Current Dev State

This commit is contained in:
Tim Lorsbach
2025-06-23 20:13:54 +02:00
parent b4f9bb277d
commit ded50edaa2
22617 changed files with 4345095 additions and 174 deletions

View File

@ -0,0 +1,18 @@
This software is released under the MIT license:
Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in
the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
the Software, and to permit persons to whom the Software is furnished to do so,
subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

View File

@ -0,0 +1,18 @@
$ git log|head -n1
commit 8b66aec6f43c5099c72ab365a93da2a9e406824e
with lexical-scope@0.0.4:
$ time module-deps bench/jquery.js | bin/cmd.js >/dev/null
real 0m7.380s
user 0m7.504s
sys 0m0.320s
with lexical-scope@0.0.5:
$ time module-deps bench/jquery.js | bin/cmd.js >/dev/null
real 0m2.441s
user 0m2.584s
sys 0m0.176s

View File

@ -0,0 +1,2 @@
#!/bin/bash
time module-deps bench/jquery.js | bin/cmd.js >/dev/null

View File

@ -0,0 +1,26 @@
#!/usr/bin/env node
var insert = require('../');
var through = require('through2');
var concat = require('concat-stream');
var JSONStream = require('JSONStream');
var basedir = process.argv[2] || process.cwd();
process.stdin
.pipe(JSONStream.parse([ true ]))
.pipe(through.obj(write))
.pipe(JSONStream.stringify())
.pipe(process.stdout)
;
function write (row, enc, next) {
var self = this;
var s = insert(row.id, { basedir: basedir });
s.pipe(concat(function (src) {
row.source = src.toString('utf8');
self.push(row);
next();
}));
s.end(row.source);
}

View File

@ -0,0 +1,6 @@
process.nextTick(function () {
console.log('in foo/index.js: ' + JSON.stringify({
__filename: __filename,
__dirname: __dirname
}));
});

View File

@ -0,0 +1,6 @@
console.log('in main.js: ' + JSON.stringify({
__filename: __filename,
__dirname: __dirname
}));
require('./foo');

View File

@ -0,0 +1,12 @@
var mdeps = require('module-deps');
var bpack = require('browser-pack');
var insert = require('../');
function inserter (file) {
return insert(file, { basedir: __dirname + '/files' });
}
var files = [ __dirname + '/files/main.js' ];
mdeps(files, { transform: inserter })
.pipe(bpack({ raw: true }))
.pipe(process.stdout)
;

View File

@ -0,0 +1,170 @@
var parseScope = require('lexical-scope');
var through = require('through2');
var merge = require('xtend');
var path = require('path');
var processPath = require.resolve('process/browser.js');
var isbufferPath = require.resolve('is-buffer')
var combineSourceMap = require('combine-source-map');
function getRelativeRequirePath(fullPath, fromPath) {
var relpath = path.relative(path.dirname(fromPath), fullPath);
// If fullPath is in the same directory as fromPath, relpath will
// result in something like "index.js". require() needs "./" prepended
// to these paths.
if (path.dirname(relpath) === '.') {
relpath = "./" + relpath;
}
// On Windows: Convert path separators to what require() expects
if (path.sep === '\\') {
relpath = relpath.replace(/\\/g, '/');
}
return relpath;
}
var defaultVars = {
process: function (file) {
var relpath = getRelativeRequirePath(processPath, file);
return 'require(' + JSON.stringify(relpath) + ')';
},
global: function () {
return 'typeof global !== "undefined" ? global : '
+ 'typeof self !== "undefined" ? self : '
+ 'typeof window !== "undefined" ? window : {}'
;
},
'Buffer.isBuffer': function (file) {
var relpath = getRelativeRequirePath(isbufferPath, file);
return 'require(' + JSON.stringify(relpath) + ')';
},
Buffer: function () {
return 'require("buffer").Buffer';
},
__filename: function (file, basedir) {
var filename = '/' + path.relative(basedir, file);
return JSON.stringify(filename);
},
__dirname: function (file, basedir) {
var dir = path.dirname('/' + path.relative(basedir, file));
return JSON.stringify(dir);
}
};
module.exports = function (file, opts) {
if (/\.json$/i.test(file)) return through();
if (!opts) opts = {};
var basedir = opts.basedir || '/';
var vars = merge(defaultVars, opts.vars);
var varNames = Object.keys(vars).filter(function(name) {
return typeof vars[name] === 'function';
});
var quick = RegExp(varNames.map(function (name) {
return '\\b' + name + '\\b';
}).join('|'));
var chunks = [];
return through(write, end);
function write (chunk, enc, next) { chunks.push(chunk); next() }
function end () {
var self = this;
var source = Buffer.isBuffer(chunks[0])
? Buffer.concat(chunks).toString('utf8')
: chunks.join('')
;
source = source
.replace(/^\ufeff/, '')
.replace(/^#![^\n]*\n/, '\n');
if (opts.always !== true && !quick.test(source)) {
this.push(source);
this.push(null);
return;
}
try {
var scope = opts.always
? { globals: { implicit: varNames } }
: parseScope('(function(){\n' + source + '\n})()')
;
}
catch (err) {
var e = new SyntaxError(
(err.message || err) + ' while parsing ' + file
);
e.type = 'syntax';
e.filename = file;
return this.emit('error', e);
}
var globals = {};
varNames.forEach(function (name) {
if (!/\./.test(name)) return;
var parts = name.split('.')
var prop = (scope.globals.implicitProperties || {})[parts[0]]
if (!prop || prop.length !== 1 || prop[0] !== parts[1]) return;
var value = vars[name](file, basedir);
if (!value) return;
globals[parts[0]] = '{'
+ JSON.stringify(parts[1]) + ':' + value + '}';
self.emit('global', name);
});
varNames.forEach(function (name) {
if (/\./.test(name)) return;
if (globals[name]) return;
if (scope.globals.implicit.indexOf(name) < 0) return;
var value = vars[name](file, basedir);
if (!value) return;
globals[name] = value;
self.emit('global', name);
});
this.push(closeOver(globals, source, file, opts));
this.push(null);
}
};
module.exports.vars = defaultVars;
function closeOver (globals, src, file, opts) {
var keys = Object.keys(globals);
if (keys.length === 0) return src;
var values = keys.map(function (key) { return globals[key] });
var wrappedSource;
if (keys.length <= 3) {
wrappedSource = '(function (' + keys.join(',') + '){\n'
+ src + '\n}).call(this,' + values.join(',') + ')'
;
}
else {
// necessary to make arguments[3..6] still work for workerify etc
// a,b,c,arguments[3..6],d,e,f...
var extra = [ '__argument0', '__argument1', '__argument2', '__argument3' ];
var names = keys.slice(0,3).concat(extra).concat(keys.slice(3));
values.splice(3, 0,
'arguments[3]','arguments[4]',
'arguments[5]','arguments[6]'
);
wrappedSource = '(function (' + names.join(',') + '){\n'
+ src + '\n}).call(this,' + values.join(',') + ')';
}
// Generate source maps if wanted. Including the right offset for
// the wrapped source.
if (!opts.debug) {
return wrappedSource;
}
var sourceFile = path.relative(opts.basedir, file)
.replace(/\\/g, '/');
var sourceMap = combineSourceMap.create().addFile(
{ sourceFile: sourceFile, source: src},
{ line: 1 });
return combineSourceMap.removeComments(wrappedSource) + "\n"
+ sourceMap.comment();
}

View File

@ -0,0 +1,77 @@
{
"_from": "insert-module-globals@^7.0.0",
"_id": "insert-module-globals@7.0.1",
"_inBundle": false,
"_integrity": "sha1-wDv04BywhtW15azorQr+eInWOMM=",
"_location": "/insert-module-globals",
"_phantomChildren": {},
"_requested": {
"type": "range",
"registry": true,
"raw": "insert-module-globals@^7.0.0",
"name": "insert-module-globals",
"escapedName": "insert-module-globals",
"rawSpec": "^7.0.0",
"saveSpec": null,
"fetchSpec": "^7.0.0"
},
"_requiredBy": [
"/browserify"
],
"_resolved": "https://registry.npmjs.org/insert-module-globals/-/insert-module-globals-7.0.1.tgz",
"_shasum": "c03bf4e01cb086d5b5e5ace8ad0afe7889d638c3",
"_spec": "insert-module-globals@^7.0.0",
"_where": "/home/manfred/enviPath/ketcher2/ketcher/node_modules/browserify",
"author": {
"name": "James Halliday",
"email": "mail@substack.net",
"url": "http://substack.net"
},
"bin": {
"insert-module-globals": "bin/cmd.js"
},
"bugs": {
"url": "https://github.com/substack/insert-module-globals/issues"
},
"bundleDependencies": false,
"dependencies": {
"JSONStream": "^1.0.3",
"combine-source-map": "~0.7.1",
"concat-stream": "~1.5.1",
"is-buffer": "^1.1.0",
"lexical-scope": "^1.2.0",
"process": "~0.11.0",
"through2": "^2.0.0",
"xtend": "^4.0.0"
},
"deprecated": false,
"description": "insert implicit module globals into a module-deps stream",
"devDependencies": {
"browser-pack": "^6.0.0",
"buffer": "^3.0.0",
"convert-source-map": "~1.1.0",
"module-deps": "^4.0.2",
"tape": "^4.2.0"
},
"homepage": "https://github.com/substack/insert-module-globals",
"keywords": [
"__filename",
"__dirname",
"global",
"process",
"module-deps",
"browser-pack",
"browserify"
],
"license": "MIT",
"main": "index.js",
"name": "insert-module-globals",
"repository": {
"type": "git",
"url": "git://github.com/substack/insert-module-globals.git"
},
"scripts": {
"test": "tape test/*.js"
},
"version": "7.0.1"
}

View File

@ -0,0 +1,146 @@
# insert-module-globals
insert implicit module globals
(`__filename`, `__dirname`, `process`, `global`, and `Buffer`)
as a browserify-style transform
[![build status](https://secure.travis-ci.org/substack/insert-module-globals.png)](http://travis-ci.org/substack/insert-module-globals)
# example
``` js
var mdeps = require('module-deps');
var bpack = require('browser-pack');
var insert = require('insert-module-globals');
function inserter (file) {
return insert(file, { basedir: __dirname + '/files' });
}
var files = [ __dirname + '/files/main.js' ];
mdeps(files, { transform: inserter })
.pipe(bpack({ raw: true }))
.pipe(process.stdout)
;
```
```
$ node example/insert.js | node
in main.js: {"__filename":"/main.js","__dirname":"/"}
in foo/index.js: {"__filename":"/foo/index.js","__dirname":"/foo"}
```
or use the command-line scripts:
```
$ module-deps main.js | insert-module-globals | browser-pack | node
in main.js: {"__filename":"/main.js","__dirname":"/"}
in foo/index.js: {"__filename":"/foo/index.js","__dirname":"/foo"}
```
or use insert-module-globals as a transform:
```
$ module-deps main.js --transform insert-module-globals | browser-pack | node
in main.js: {"__filename":"/main.js","__dirname":"/"}
in foo/index.js: {"__filename":"/foo/index.js","__dirname":"/foo"}
```
# methods
``` js
var insertGlobals = require('insert-module-globals')
```
## var inserter = insertGlobals(file, opts)
Return a transform stream `inserter` for the filename `file` that will accept a
javascript file as input and will output the file with a closure around the
contents as necessary to define extra builtins.
When `opts.always` is true, wrap every file with all the global variables
without parsing. This is handy because parsing the scope can take a long time,
so you can prioritize fast builds over saving bytes in the final output. When
`opts.always` is truthy but not true, avoid parsing but perform a quick test to
determine if wrapping should be skipped.
Use `opts.vars` to override the default inserted variables, or set
`opts.vars[name]` to `undefined` to not insert a variable which would otherwise
be inserted.
`opts.vars` properties with a `.` in their name will be executed instead of the
parent object if ONLY that property is used. For example, `"Buffer.isBuffer"`
will mask `"Buffer"` only when there is a `Buffer.isBuffer()` call in a file and
no other references to `Buffer`.
If `opts.debug` is true, an inline source map will be generated to compensate
for the extra lines.
# events
## inserter.on('global', function (name) {})
When a global is detected, the inserter stream emits a `'global'` event.
# usage
```
usage: insert-module-globals {basedir}
```
# install
With [npm](https://npmjs.org), to get the library do:
```
npm install insert-module-globals
```
and to get the bin script do:
```
npm install -g insert-module-globals
```
# insert custom globals.
`insert-module-globals` can also insert arbitary globals into files.
Pass in an object of functions as the `vars` option.
``` js
var vars = {
process: function (file, basedir) {
return {
id: "path/to/custom_process.js",
source: customProcessContent
}
},
Buffer: function (file, basedir) {
return {
id: 'path/to/custom_buffer.js',
source: customProcessContent,
//suffix is optional
//it's used to extract the value from the module.
//it becomes: require(...).Buffer in this case.
suffix: '.Buffer'
}
},
Math: function () {
//if you return a string,
//it's simply set as the value.
return '{}'
//^ any attempt to use Math[x] will throw!
}
}
function inserter (file) {
return insert(file, { vars: vars });
}
mdeps(files, { transform: inserter })
.pipe(bpack({ raw: true }))
.pipe(process.stdout)
```
# license
MIT

View File

@ -0,0 +1,105 @@
var test = require('tape')
var mdeps = require('module-deps');
var bpack = require('browser-pack');
var insert = require('../');
var concat = require('concat-stream');
var vm = require('vm');
test('always true insert', function (t) {
t.plan(10);
var s = mdeps({
modules: {
buffer: require.resolve('buffer/')
}
});
s.pipe(bpack({ raw: true })).pipe(concat(function (src) {
var c = {
t: t,
process: 'sandbox process',
Buffer: 'sandbox Buffer',
__filename: 'sandbox __filename',
__dirname: 'sandbox __dirname',
custom: 'sandbox custom',
self: { xyz: 555 }
};
vm.runInNewContext(src, c);
}));
s.write({ transform: inserter({ always: true }), global: true });
s.end(__dirname + '/always/main.js');
});
test('always true insert custom globals without defaults', function (t) {
t.plan(7);
var s = mdeps({
modules: {
buffer: require.resolve('buffer/')
}
});
s.pipe(bpack({ raw: true })).pipe(concat(function (src) {
var c = {
t: t,
process: 'sandbox process',
Buffer: 'sandbox Buffer',
__filename: 'sandbox __filename',
__dirname: 'sandbox __dirname',
custom: 'sandbox custom',
self: { xyz: 555 }
};
vm.runInNewContext(src, c);
}));
s.write({
transform: inserter({ always: true, vars: {
global: {},
process: undefined,
Buffer: undefined,
__filename: undefined,
__dirname: undefined,
custom: function() { return '"inserted custom"' }
}}),
global: true
});
s.end(__dirname + '/always/custom_globals_without_defaults.js');
});
test('always truthy-but-not-true insert hidden from quick test is not really inserted; true is', function (t) {
t.plan(2);
var testit = function(always, expected) {
var s = mdeps({
modules: {
buffer: require.resolve('buffer/')
}
});
s.pipe(bpack({ raw: true })).pipe(concat(function (src) {
var c = {
t: t,
process: 'sandbox process',
Buffer: 'sandbox Buffer',
__filename: 'sandbox __filename',
__dirname: 'sandbox __dirname',
custom: 'sandbox custom',
expected: expected,
self: { xyz: 555 }
};
vm.runInNewContext(src, c);
}));
s.write({
transform: inserter({ always: always, vars: {
custom: function() { return '"inserted custom"' }
}}),
global: true
})
s.end(__dirname + '/always/hidden_from_quick_test.js');
};
var always = 'truthy', expected = 'sandbox custom';
testit(always, expected);
always = true; expected = 'inserted custom';
testit(always, expected);
});
function inserter (opts) {
return function (file) {
return insert(file, opts);
};
}

View File

@ -0,0 +1,7 @@
t.equal(eval('process'), 'sandbox process');
t.equal(eval('typeof global'), 'undefined');
t.equal(eval('self.xyz'), 555);
t.equal(eval('Buffer'), 'sandbox Buffer');
t.equal(eval('__filename'), 'sandbox __filename');
t.equal(eval('__dirname'), 'sandbox __dirname');
t.equal(eval('custom'), 'inserted custom');

View File

@ -0,0 +1 @@
t.equal(eval('cust' + 'om'), eval('expected'));

View File

@ -0,0 +1,10 @@
t.equal(eval('typeof process'), 'object');
t.equal(eval('typeof process.nextTick'), 'function');
t.equal(eval('typeof global'), 'object');
t.equal(eval('global.xyz'), 555);
t.equal(eval('typeof Buffer'), 'function');
t.equal(eval('typeof __filename'), 'string');
t.notEqual(eval('__filename'), 'sandbox __filename');
t.equal(eval('typeof __dirname'), 'string');
t.notEqual(eval('__dirname'), 'sandbox __dirname');
t.equal(eval('custom'), 'sandbox custom');

View File

@ -0,0 +1,63 @@
var test = require('tape');
var vm = require('vm');
var concat = require('concat-stream');
var insert = require('../');
var bpack = require('browser-pack');
var mdeps = require('module-deps');
test('insert globals', function (t) {
var expected = [ 'global' ];
t.plan(2 + expected.length);
var deps = mdeps()
var pack = bpack({ raw: true });
deps.pipe(pack);
pack.pipe(concat(function (src) {
var c = {
t : t,
a : 555,
};
c.self = c;
vm.runInNewContext(src, c);
}));
deps.write({
transform: function (file) {
var tr = inserter(file)
tr.on('global', function (name) {
t.equal(name, expected.shift());
});
return tr;
},
global: true
});
deps.end(__dirname + '/global/main.js');
});
test('__filename and __dirname', function (t) {
t.plan(2);
var file = __dirname + '/global/filename.js';
var deps = mdeps()
var pack = bpack({ raw: true });
deps.pipe(pack);
pack.pipe(concat(function (src) {
var c = {};
vm.runInNewContext('require=' + src, c);
var x = c.require(file);
t.equal(x.filename, '/filename.js');
t.equal(x.dirname, '/');
}));
deps.write({ transform: inserter, global: true });
deps.end(file);
});
function inserter (file) {
return insert(file, { basedir: __dirname + '/global' });
}

View File

@ -0,0 +1,2 @@
exports.filename = __filename;
exports.dirname = __dirname;

View File

@ -0,0 +1,2 @@
t.equal(a, 555);
t.equal(a, global.a);

View File

@ -0,0 +1,46 @@
var test = require('tape');
var mdeps = require('module-deps');
var bpack = require('browser-pack');
var insert = require('../');
var concat = require('concat-stream');
var vm = require('vm');
test('process.nextTick inserts', function (t) {
t.plan(4);
var s = mdeps()
s.pipe(bpack({ raw: true })).pipe(concat(function (src) {
var c = {
t: t,
setTimeout: setTimeout,
clearTimeout: clearTimeout
};
vm.runInNewContext(src, c);
}));
s.write({ transform: inserter, global: true })
s.end(__dirname + '/insert/main.js');
});
test('buffer inserts', function (t) {
t.plan(2);
var s = mdeps({
modules: { buffer: require.resolve('buffer/') }
});
s.pipe(bpack({ raw: true })).pipe(concat(function (src) {
var c = {
t: t,
setTimeout: setTimeout,
clearTimeout: clearTimeout,
Uint8Array: Uint8Array,
DataView: DataView
};
vm.runInNewContext(src, c);
}));
s.write({ transform: inserter, global: true })
s.end(__dirname + '/insert/buffer.js');
});
function inserter (file) {
return insert(file, {
basedir: __dirname + '/insert'
});
}

View File

@ -0,0 +1 @@
require('./foo/buf');

View File

@ -0,0 +1,4 @@
process.nextTick(function () {
t.equal(Buffer('abc').toString('base64'), 'YWJj');
t.equal(Buffer([98,99,100]).toString(), 'bcd');
});

View File

@ -0,0 +1,4 @@
process.nextTick(function () {
t.equal(__filename, '/foo/index.js');
t.equal(__dirname, '/foo');
});

View File

@ -0,0 +1,4 @@
t.equal(__filename, '/main.js');
t.equal(__dirname, '/');
require('./foo');

View File

@ -0,0 +1,27 @@
var test = require('tape');
var mdeps = require('module-deps');
var bpack = require('browser-pack');
var insert = require('../');
var concat = require('concat-stream');
var vm = require('vm');
test('isbuffer', function (t) {
t.plan(5);
var deps = mdeps()
var pack = bpack({ raw: true, hasExports: true });
deps.pipe(pack).pipe(concat(function (src) {
var c = { global: {} };
vm.runInNewContext(src, c);
t.equal(c.require('main')(Buffer('wow')), true, 'is a buffer');
t.equal(c.require('main')('wow'), false, 'not a buffer (string)');
t.equal(c.require('main')({}), false, 'not a buffer (object)');
t.notOk(/require("buffer")/.test(src), 'buffer not required in source')
t.notOk(/require\("\//.test(src), 'absolute path not required in source')
}));
deps.write({ transform: inserter, global: true });
deps.end({ id: 'main', file: __dirname + '/isbuffer/main.js' });
});
function inserter (file) {
return insert(file, { basedir: __dirname + '/isbuffer' });
}

View File

@ -0,0 +1,3 @@
module.exports = function (buf) {
return Buffer.isBuffer(buf);
};

View File

@ -0,0 +1,27 @@
var test = require('tape');
var mdeps = require('module-deps');
var bpack = require('browser-pack');
var insert = require('../');
var concat = require('concat-stream');
var vm = require('vm');
test('early return', function (t) {
t.plan(4);
var s = mdeps()
s.pipe(bpack({ raw: true })).pipe(concat(function (src) {
var c = {
t: t,
setTimeout: setTimeout,
clearTimeout: clearTimeout
};
vm.runInNewContext(src, c);
}));
s.write({ transform: inserter, global: true });
s.end(__dirname + '/return/main.js');
});
function inserter (file) {
return insert(file, {
basedir: __dirname + '/return'
});
}

View File

@ -0,0 +1,4 @@
process.nextTick(function () {
t.equal(__filename, '/foo/index.js');
t.equal(__dirname, '/foo');
});

View File

@ -0,0 +1,6 @@
t.equal(__filename, '/main.js');
t.equal(__dirname, '/');
require('./foo');
return;

View File

@ -0,0 +1,40 @@
var test = require('tape');
var convert = require('convert-source-map');
var insert = require('../');
var mdeps = require('module-deps');
var vm = require('vm');
test('sourcemap', function (t) {
t.plan(6);
var file = __dirname + '/sourcemap/main.js';
var deps = mdeps()
deps.on('data', function(row) {
var src = row.source;
var sm = convert.fromSource(src).toObject();
t.deepEqual(sm.sources, [ 'test/sourcemap/main_es6.js' ]);
t.deepEqual(sm.sourcesContent, [ 'console.log(`${__dirname}`, `${__filename}`);\n' ]);
t.deepEqual(sm.mappings, ';AAAA,OAAO,CAAC,GAAG,MAAI,SAAS,OAAO,UAAU,CAAG,CAAC');
t.equal(src.match(convert.commentRegex).length, 1);
var c = {
console: {
log: function(dirname, filename) {
t.equal(dirname, '/');
t.equal(filename, '/main.js');
}
},
};
vm.runInNewContext(src, c);
});
deps.write({ transform: inserter, global: true });
deps.end(file);
});
function inserter (file) {
return insert(file, { debug: true, basedir: __dirname + '/sourcemap' });
}

View File

@ -0,0 +1,3 @@
console.log("" + __dirname, "" + __filename);
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbInRlc3Qvc291cmNlbWFwL21haW5fZXM2LmpzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiJBQUFBLE9BQU8sQ0FBQyxHQUFHLE1BQUksU0FBUyxPQUFPLFVBQVUsQ0FBRyxDQUFDIiwiZmlsZSI6InVuZGVmaW5lZCIsInNvdXJjZXNDb250ZW50IjpbImNvbnNvbGUubG9nKGAke19fZGlybmFtZX1gLCBgJHtfX2ZpbGVuYW1lfWApO1xuIl19

View File

@ -0,0 +1 @@
console.log(`${__dirname}`, `${__filename}`);

View File

@ -0,0 +1,33 @@
var test = require('tape');
var vm = require('vm');
var concat = require('concat-stream');
var insert = require('../');
var bpack = require('browser-pack');
var mdeps = require('module-deps');
test('unprefix - remove shebang and bom', function (t) {
t.plan(3);
var file = __dirname + '/unprefix/main.js';
var deps = mdeps();
var pack = bpack({ raw: true });
deps.pipe(pack);
pack.pipe(concat(function (src) {
var c = {};
vm.runInNewContext('require=' + src, c);
var x = c.require(file);
t.equal(x.filename, '/hello.js');
t.equal(x.dirname, '/');
t.notOk(/\ufeff/.test(src.toString()));
}));
deps.write({ transform: inserter, global: true });
deps.end(file);
});
function inserter (file) {
return insert(file, { basedir: __dirname + '/unprefix' });
}

View File

@ -0,0 +1,2 @@
exports.filename = __filename;
exports.dirname = __dirname;

View File

@ -0,0 +1,3 @@
#!/usr/bin/env node
module.exports = require('./hello');