refactor(Cypress): add nodemodules

This commit is contained in:
2021-09-02 17:18:41 +02:00
parent 1aa57bbd0a
commit bc6e1bc12e
4238 changed files with 340975 additions and 8 deletions

5
node_modules/insert-module-globals/.travis.yml generated vendored Normal file
View File

@@ -0,0 +1,5 @@
language: node_js
node_js:
- "0.10"
- "0.12"
- node

6
node_modules/insert-module-globals/CHANGELOG.md generated vendored Normal file
View File

@@ -0,0 +1,6 @@
# insert-module-globals Change Log
All notable changes to this project will be documented in this file.
This project adheres to [Semantic Versioning](http://semver.org/).
## 7.2.1
* Fix incorrect output when source contains a top-level `const` declaration with the same name as an inserted global. ([d86999f](https://github.com/browserify/insert-module-globals/commit/d86999f0180e09dd272666f5aff8db04183b3ea2))

18
node_modules/insert-module-globals/LICENSE generated vendored Normal file
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.

18
node_modules/insert-module-globals/appveyor.yml generated vendored Normal file
View File

@@ -0,0 +1,18 @@
version: "{build}"
environment:
matrix:
- nodejs_version: "" # lastest
- nodejs_version: "0.12"
- nodejs_version: "0.10"
install:
- ps: Install-Product node $env:nodejs_version
- npm install
build: off
test_script:
- node --version
- npm --version
- npm test

View File

@@ -0,0 +1 @@
jquery-3.3.1.js -diff

15
node_modules/insert-module-globals/bench/index.js generated vendored Normal file
View File

@@ -0,0 +1,15 @@
var bench = require('nanobench');
var path = require('path');
var fs = require('fs');
var insert = require('../');
bench('jquery', function (b) {
var source = fs.readFileSync(path.join(__dirname, 'jquery-3.3.1.js'));
b.start();
var stream = insert();
stream.on('data', function() {});
stream.on('end', function () {
b.end();
});
stream.end(source);
});

26
node_modules/insert-module-globals/bin/cmd.js generated vendored Executable file
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');

12
node_modules/insert-module-globals/example/insert.js generated vendored Normal file
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)
;

197
node_modules/insert-module-globals/index.js generated vendored Normal file
View File

@@ -0,0 +1,197 @@
var undeclaredIdentifiers = require('undeclared-identifiers');
var through = require('through2');
var merge = require('xtend');
var parse = require('acorn-node').parse;
var path = require('path');
var isAbsolute = path.isAbsolute || require('path-is-absolute');
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 or a subdirectory of fromPath,
// relpath will result in something like "index.js", "src/abc.js".
// require() needs "./" prepended to these paths.
if (!/^\./.test(relpath) && !isAbsolute(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';
},
setImmediate: function () {
return 'require("timers").setImmediate';
},
clearImmediate: function () {
return 'require("timers").clearImmediate';
},
__filename: function (file, basedir) {
var relpath = path.relative(basedir, file);
// standardize path separators, use slash in Windows too
if ( path.sep === '\\' ) {
relpath = relpath.replace(/\\/g, '/');
}
var filename = '/' + relpath;
return JSON.stringify(filename);
},
__dirname: function (file, basedir) {
var relpath = path.relative(basedir, file);
// standardize path separators, use slash in Windows too
if ( path.sep === '\\' ) {
relpath = relpath.replace(/\\/g, '/');
}
var dir = path.dirname('/' + relpath );
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 undeclared = opts.always
? { identifiers: varNames, properties: [] }
: undeclaredIdentifiers(parse(source), { wildcard: true })
;
}
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 = undeclared.properties.indexOf(name)
if (prop === -1 || countprops(undeclared.properties, parts[0]) > 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 (undeclared.identifiers.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] });
// we double-wrap the source in IIFEs to prevent code like
// (function(Buffer){ const Buffer = null }())
// which causes a parse error.
var wrappedSource = '(function (){\n' + src + '\n}).call(this)';
if (keys.length <= 3) {
wrappedSource = '(function (' + keys.join(',') + '){'
+ wrappedSource + '}).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(',') + '){'
+ wrappedSource + '}).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();
}
function countprops (props, name) {
return props.filter(function (prop) {
return prop.slice(0, name.length + 1) === name + '.';
}).length;
}

81
node_modules/insert-module-globals/package.json generated vendored Normal file
View File

@@ -0,0 +1,81 @@
{
"_from": "insert-module-globals@^7.0.0",
"_id": "insert-module-globals@7.2.1",
"_inBundle": false,
"_integrity": "sha512-ufS5Qq9RZN+Bu899eA9QCAYThY+gGW7oRkmb0vC93Vlyu/CFGcH0OYPEjVkDXA5FEbTt1+VWzdoOD3Ny9N+8tg==",
"_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.2.1.tgz",
"_shasum": "d5e33185181a4e1f33b15f7bf100ee91890d5cb3",
"_spec": "insert-module-globals@^7.0.0",
"_where": "/home/simon/Documents/lifen-autotest/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/browserify/insert-module-globals/issues"
},
"bundleDependencies": false,
"dependencies": {
"JSONStream": "^1.0.3",
"acorn-node": "^1.5.2",
"combine-source-map": "^0.8.0",
"concat-stream": "^1.6.1",
"is-buffer": "^1.1.0",
"path-is-absolute": "^1.0.1",
"process": "~0.11.0",
"through2": "^2.0.0",
"undeclared-identifiers": "^1.1.2",
"xtend": "^4.0.0"
},
"deprecated": false,
"description": "insert implicit module globals into a module-deps stream",
"devDependencies": {
"browser-pack": "^6.0.0",
"buffer": "^4.9.1",
"convert-source-map": "~1.1.0",
"module-deps": "^4.0.2",
"nanobench": "^2.1.1",
"tape": "^4.2.0",
"timers-browserify": "^1.4.2"
},
"homepage": "https://github.com/browserify/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/browserify/insert-module-globals.git"
},
"scripts": {
"test": "tape test/*.js"
},
"version": "7.2.1"
}

146
node_modules/insert-module-globals/readme.markdown generated vendored Normal file
View File

@@ -0,0 +1,146 @@
# insert-module-globals
insert implicit module globals
(`__filename`, `__dirname`, `process`, `global`, `setImmediate`, `clearImmediate` and `Buffer`)
as a browserify-style transform
[![build status](https://secure.travis-ci.org/browserify/insert-module-globals.png)](http://travis-ci.org/browserify/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

136
node_modules/insert-module-globals/test/always.js generated vendored Normal file
View File

@@ -0,0 +1,136 @@
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/'),
timers: require.resolve('timers-browserify')
}
});
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/'),
timers: require.resolve('timers-browserify')
}
});
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/'),
timers: require.resolve('timers-browserify')
}
});
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);
});
test('inserted names do not cause const name collisions', function (t) {
t.plan(1);
var s = mdeps({
modules: {
buffer: require.resolve('buffer/'),
timers: require.resolve('timers-browserify')
}
});
s.on('error', t.fail);
s.pipe(bpack({ raw: true })).pipe(concat(function (src) {
var c = {
t: t,
Buffer: 'sandbox Buffer'
};
vm.runInNewContext(src, c);
}));
s.write({
transform: inserter({
always: true,
vars: {
Buffer: function() { return '"sandbox Buffer"' }
}
}),
global: true
});
s.end(__dirname + '/always/collision.js');
});
function inserter (opts) {
return function (file) {
return insert(file, opts);
};
}

View File

@@ -0,0 +1,2 @@
const Buffer = null;
t.equal(Buffer, null);

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'));

10
node_modules/insert-module-globals/test/always/main.js generated vendored Normal file
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');

64
node_modules/insert-module-globals/test/global.js generated vendored Normal file
View File

@@ -0,0 +1,64 @@
var test = require('tape');
var vm = require('vm');
var concat = require('concat-stream');
var path = require('path');
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 = path.join(__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);

30
node_modules/insert-module-globals/test/immediate.js generated vendored Normal file
View File

@@ -0,0 +1,30 @@
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('immediate', function (t) {
t.plan(3);
var deps = mdeps({
modules: { timers: require.resolve('timers-browserify') }
});
var pack = bpack({ raw: true, hasExports: true });
deps.pipe(pack).pipe(concat(function (src) {
var c = {
setTimeout: setTimeout,
clearTimeout: clearTimeout,
T: t
};
t.ok(/require\("timers"\)/.test(src), 'timers required in source');
t.notOk(/require\("\//.test(src), 'absolute path not required in source');
vm.runInNewContext(src, c);
}));
deps.write({ transform: inserter, global: true });
deps.end({ id: 'main', file: __dirname + '/immediate/main.js' });
});
function inserter (file) {
return insert(file, { basedir: __dirname + '/immediate' });
}

View File

@@ -0,0 +1,8 @@
var immediate = setImmediate(function () {
T.fail('should have been cleared')
})
setImmediate(function () {
T.pass('should call setImmediate')
})
clearImmediate(immediate)

46
node_modules/insert-module-globals/test/insert.js generated vendored Normal file
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');

64
node_modules/insert-module-globals/test/isbuffer.js generated vendored Normal file
View File

@@ -0,0 +1,64 @@
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');
// use is-buffer instead of builtin Buffer.isBuffer. The builtin
// does `instanceof` which does not work on the browserified version
var isBuffer = require('is-buffer');
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' });
});
test('isbuffer (and Buffer.from)', 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')(c.require('main').a()), true, 'is a buffer');
t.equal(c.require('main')('wow'), false, 'is not a buffer');
t.equal(isBuffer(c.require('main').a()), true, 'is a buffer');
t.ok(/require\("buffer"\)/.test(src), 'buffer required in source')
t.equal(c.require('main').a().toString('hex'), 'abcd', 'is a buffer');
}));
deps.write({ transform: inserter, global: true });
deps.end({ id: 'main', file: __dirname + '/isbuffer/both.js' });
});
test('isbuffer (and new Buffer)', 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')(c.require('main').a()), true, 'is a buffer');
t.equal(c.require('main')('wow'), false, 'is not a buffer');
t.equal(isBuffer(c.require('main').a()), true, 'is a buffer');
t.ok(/require\("buffer"\)/.test(src), 'buffer required in source')
t.equal(c.require('main').a().toString('utf8'), 'abcd', 'is a buffer');
}));
deps.write({ transform: inserter, global: true });
deps.end({ id: 'main', file: __dirname + '/isbuffer/new.js' });
});
function inserter (file) {
return insert(file, { basedir: __dirname + '/isbuffer' });
}

View File

@@ -0,0 +1,6 @@
module.exports = function (buf) {
return Buffer.isBuffer(buf);
};
module.exports.a = function () {
return Buffer.from('abcd', 'hex');
};

View File

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

View File

@@ -0,0 +1,6 @@
module.exports = function (buf) {
return Buffer.isBuffer(buf);
};
module.exports.a = function () {
return new Buffer('abcd');
};

27
node_modules/insert-module-globals/test/return.js generated vendored Normal file
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;

35
node_modules/insert-module-globals/test/roots.js generated vendored Normal file
View File

@@ -0,0 +1,35 @@
var test = require('tape');
var mdeps = require('module-deps');
var bpack = require('browser-pack');
var insert = require('../');
var concat = require('concat-stream');
var path = require('path');
var fs = require('fs');
var vm = require('vm');
test('windows partitions', { skip: process.platform !== 'win32' }, function (t) {
t.plan(1);
var deps = mdeps()
var pack = bpack({ raw: true, hasExports: true });
deps.pipe(pack).pipe(concat(function (src) {
var c = {
console: { log: log }
};
vm.runInNewContext(src, c);
function log (value) {
t.equal(typeof value, 'function');
}
}));
deps.write({ transform: inserter, global: true });
deps.end({
id: 'main',
file: 'D:\\test.js',
source: fs.readFileSync(__dirname + '/roots/main.js')
});
});
function inserter (file) {
return insert(file, {
basedir: path.join(__dirname, '..')
});
}

View File

@@ -0,0 +1 @@
console.log(Buffer.isBuffer)

41
node_modules/insert-module-globals/test/sourcemap.js generated vendored Normal file
View File

@@ -0,0 +1,41 @@
var test = require('tape');
var convert = require('convert-source-map');
var insert = require('../');
var mdeps = require('module-deps');
var vm = require('vm');
var path = require('path');
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}`);

37
node_modules/insert-module-globals/test/subdir.js generated vendored Normal file
View File

@@ -0,0 +1,37 @@
var test = require('tape');
var mdeps = require('module-deps');
var bpack = require('browser-pack');
var insert = require('../');
var concat = require('concat-stream');
var path = require('path');
var fs = require('fs');
var vm = require('vm');
test('subdir', function (t) {
t.plan(1);
var deps = mdeps()
var pack = bpack({ raw: true, hasExports: true });
deps.pipe(pack).pipe(concat(function (src) {
var c = {
console: { log: log }
};
vm.runInNewContext(src, c);
function log (value) {
t.equal(value, false);
}
}));
deps.write({ transform: inserter, global: true });
deps.end({
id: 'main',
// Fake the file path so that the relative path to is-buffer becomes
// "node_modules/is-buffer/index.js"
file: path.join(__dirname, '../subdir_test.js'),
source: fs.readFileSync(__dirname + '/subdir/main.js')
});
});
function inserter (file) {
return insert(file, {
basedir: path.join(__dirname, '..')
});
}

View File

@@ -0,0 +1 @@
console.log(Buffer.isBuffer("test"))

34
node_modules/insert-module-globals/test/unprefix.js generated vendored Normal file
View File

@@ -0,0 +1,34 @@
var test = require('tape');
var vm = require('vm');
var concat = require('concat-stream');
var path = require('path');
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 = path.join(__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');