initial commit
This commit is contained in:
136
node_modules/ts-node-dev/lib/bin.js
generated
vendored
Executable file
136
node_modules/ts-node-dev/lib/bin.js
generated
vendored
Executable file
@ -0,0 +1,136 @@
|
||||
#!/usr/bin/env node
|
||||
"use strict";
|
||||
var __assign = (this && this.__assign) || function () {
|
||||
__assign = Object.assign || function(t) {
|
||||
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
||||
s = arguments[i];
|
||||
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
||||
t[p] = s[p];
|
||||
}
|
||||
return t;
|
||||
};
|
||||
return __assign.apply(this, arguments);
|
||||
};
|
||||
var __spreadArrays = (this && this.__spreadArrays) || function () {
|
||||
for (var s = 0, i = 0, il = arguments.length; i < il; i++) s += arguments[i].length;
|
||||
for (var r = Array(s), k = 0, i = 0; i < il; i++)
|
||||
for (var a = arguments[i], j = 0, jl = a.length; j < jl; j++, k++)
|
||||
r[k] = a[j];
|
||||
return r;
|
||||
};
|
||||
var __importDefault = (this && this.__importDefault) || function (mod) {
|
||||
return (mod && mod.__esModule) ? mod : { "default": mod };
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
var _1 = require(".");
|
||||
var minimist_1 = __importDefault(require("minimist"));
|
||||
var nodeArgs = [];
|
||||
var unknown = [];
|
||||
var devArgs = process.argv.slice(2, 100);
|
||||
var tsNodeFlags = {
|
||||
boolean: [
|
||||
'scope',
|
||||
'emit',
|
||||
'files',
|
||||
'pretty',
|
||||
'transpile-only',
|
||||
'prefer-ts-exts',
|
||||
'prefer-ts',
|
||||
'log-error',
|
||||
'skip-project',
|
||||
'skip-ignore',
|
||||
'compiler-host',
|
||||
'script-mode',
|
||||
],
|
||||
string: [
|
||||
'compiler',
|
||||
'project',
|
||||
'ignore',
|
||||
'ignore-diagnostics',
|
||||
'compiler-options',
|
||||
'scopeDir',
|
||||
'transpiler'
|
||||
],
|
||||
};
|
||||
var tsNodeAlias = {
|
||||
'transpile-only': 'T',
|
||||
'compiler-host': 'H',
|
||||
ignore: 'I',
|
||||
'ignore-diagnostics': 'D',
|
||||
'compiler-options': 'O',
|
||||
compiler: 'C',
|
||||
project: 'P',
|
||||
'script-mode': 's',
|
||||
};
|
||||
var devFlags = {
|
||||
boolean: [
|
||||
'deps',
|
||||
'all-deps',
|
||||
'dedupe',
|
||||
'fork',
|
||||
'exec-check',
|
||||
'debug',
|
||||
'poll',
|
||||
'respawn',
|
||||
'notify',
|
||||
'tree-kill',
|
||||
'clear',
|
||||
'cls',
|
||||
'exit-child',
|
||||
'error-recompile',
|
||||
'quiet',
|
||||
'rs',
|
||||
],
|
||||
string: [
|
||||
'dir',
|
||||
'deps-level',
|
||||
'compile-timeout',
|
||||
'ignore-watch',
|
||||
'interval',
|
||||
'debounce',
|
||||
'watch',
|
||||
'cache-directory',
|
||||
],
|
||||
};
|
||||
var opts = minimist_1.default(devArgs, {
|
||||
stopEarly: true,
|
||||
boolean: __spreadArrays(devFlags.boolean, tsNodeFlags.boolean),
|
||||
string: __spreadArrays(devFlags.string, tsNodeFlags.string),
|
||||
alias: __assign(__assign({}, tsNodeAlias), { 'prefer-ts-exts': 'prefer-ts' }),
|
||||
default: {
|
||||
fork: true,
|
||||
},
|
||||
unknown: function (arg) {
|
||||
unknown.push(arg);
|
||||
return true;
|
||||
},
|
||||
});
|
||||
var script = opts._[0];
|
||||
var scriptArgs = opts._.slice(1);
|
||||
opts.priorNodeArgs = [];
|
||||
unknown.forEach(function (arg) {
|
||||
if (arg === script || nodeArgs.indexOf(arg) >= 0)
|
||||
return;
|
||||
var argName = arg.replace(/^-+/, '');
|
||||
// fix this
|
||||
var argOpts = opts[argName];
|
||||
var argValues = Array.isArray(argOpts) ? argOpts : [argOpts];
|
||||
argValues.forEach(function (argValue) {
|
||||
if ((arg === '-r' || arg === '--require') && argValue === 'esm') {
|
||||
opts.priorNodeArgs.push(arg, argValue);
|
||||
return false;
|
||||
}
|
||||
nodeArgs.push(arg);
|
||||
if (typeof argValue === 'string') {
|
||||
nodeArgs.push(argValue);
|
||||
}
|
||||
});
|
||||
});
|
||||
if (!script) {
|
||||
// eslint-disable-next-line no-console
|
||||
console.log('ts-node-dev: no script to run provided');
|
||||
// eslint-disable-next-line no-console
|
||||
console.log('Usage: ts-node-dev [options] script [arguments]\n');
|
||||
process.exit(1);
|
||||
}
|
||||
_1.runDev(script, scriptArgs, nodeArgs, opts);
|
59
node_modules/ts-node-dev/lib/cfg.js
generated
vendored
Normal file
59
node_modules/ts-node-dev/lib/cfg.js
generated
vendored
Normal file
@ -0,0 +1,59 @@
|
||||
"use strict";
|
||||
var __importDefault = (this && this.__importDefault) || function (mod) {
|
||||
return (mod && mod.__esModule) ? mod : { "default": mod };
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.makeCfg = void 0;
|
||||
var fs_1 = __importDefault(require("fs"));
|
||||
var path_1 = __importDefault(require("path"));
|
||||
function read(dir) {
|
||||
var f = path_1.default.resolve(dir, '.node-dev.json');
|
||||
return fs_1.default.existsSync(f) ? JSON.parse(fs_1.default.readFileSync(f, 'utf-8')) : null;
|
||||
}
|
||||
function resolvePath(unresolvedPath) {
|
||||
return path_1.default.resolve(process.cwd(), unresolvedPath);
|
||||
}
|
||||
exports.makeCfg = function (main, opts) {
|
||||
var dir = main ? path_1.default.dirname(main) : '.';
|
||||
var userDir = process.env.HOME || process.env.USERPROFILE;
|
||||
var c = read(dir) || read(process.cwd()) || (userDir && read(userDir)) || {};
|
||||
c.deps = parseInt(opts['deps-level'] || '') || 0;
|
||||
if (typeof c.depsLevel === 'number')
|
||||
c.deps = c.depsLevel;
|
||||
if (opts) {
|
||||
// Overwrite with CLI opts ...
|
||||
if (opts['deps'] || opts['all-deps'])
|
||||
c.deps = -1;
|
||||
if (opts.dedupe)
|
||||
c.dedupe = true;
|
||||
if (opts.respawn)
|
||||
c.respawn = true;
|
||||
if (opts.notify === false)
|
||||
c.notify = false;
|
||||
if (opts.clear || opts.cls)
|
||||
c.clear = true;
|
||||
c.fork = opts.fork;
|
||||
}
|
||||
var ignoreWatchItems = opts['ignore-watch']
|
||||
? []
|
||||
.concat(opts['ignore-watch'])
|
||||
.map(function (_) { return _.trim(); })
|
||||
: [];
|
||||
var ignoreWatch = ignoreWatchItems.concat(c.ignore || []);
|
||||
opts.debug && console.log('Ignore watch:', ignoreWatch);
|
||||
var ignore = ignoreWatch.concat(ignoreWatch.map(resolvePath));
|
||||
return {
|
||||
vm: c.vm !== false,
|
||||
fork: c.fork !== false,
|
||||
notify: c.notify !== false,
|
||||
deps: c.deps,
|
||||
timestamp: c.timestamp || (c.timestamp !== false && 'HH:MM:ss'),
|
||||
clear: !!c.clear,
|
||||
dedupe: !!c.dedupe,
|
||||
ignore: ignore,
|
||||
respawn: c.respawn || false,
|
||||
debug: !!opts.debug,
|
||||
quiet: !!opts.quiet,
|
||||
extensions: c.extensions,
|
||||
};
|
||||
};
|
16
node_modules/ts-node-dev/lib/check-file-exists.js
generated
vendored
Normal file
16
node_modules/ts-node-dev/lib/check-file-exists.js
generated
vendored
Normal file
@ -0,0 +1,16 @@
|
||||
"use strict";
|
||||
var __importDefault = (this && this.__importDefault) || function (mod) {
|
||||
return (mod && mod.__esModule) ? mod : { "default": mod };
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
var fs_1 = __importDefault(require("fs"));
|
||||
var filePath = process.argv[2];
|
||||
var handler = function (stat) {
|
||||
if (stat && stat.birthtime.getTime() > 0) {
|
||||
process.exit(0);
|
||||
}
|
||||
};
|
||||
fs_1.default.watchFile(filePath, { interval: 100 }, handler);
|
||||
fs_1.default.stat(filePath, function (err, stat) {
|
||||
handler(stat);
|
||||
});
|
140
node_modules/ts-node-dev/lib/child-require-hook.js
generated
vendored
Normal file
140
node_modules/ts-node-dev/lib/child-require-hook.js
generated
vendored
Normal file
@ -0,0 +1,140 @@
|
||||
"use strict";
|
||||
var fs = require('fs');
|
||||
var getCompiledPath = require('./get-compiled-path').getCompiledPath;
|
||||
var sep = require('path').sep;
|
||||
var join = require('path').join;
|
||||
var extname = require('path').extname;
|
||||
var execSync = require('child_process').execSync;
|
||||
var Module = require('module');
|
||||
var compilationId = '';
|
||||
var timeThreshold = 0;
|
||||
var allowJs = false;
|
||||
var compiledDir = '';
|
||||
var preferTs = false;
|
||||
var ignore = [/node_modules/];
|
||||
var readyFile = '';
|
||||
var execCheck = false;
|
||||
var exitChild = false;
|
||||
var sourceMapSupportPath = '';
|
||||
var libPath = '';
|
||||
var checkFileScript = join(__dirname, 'check-file-exists.js');
|
||||
var waitForFile = function (fileName) {
|
||||
var start = new Date().getTime();
|
||||
while (true) {
|
||||
var exists = execCheck
|
||||
? execSync(['node', checkFileScript, '"' + fileName + '"'].join(' '), {
|
||||
stdio: 'inherit',
|
||||
}) || true
|
||||
: fs.existsSync(fileName);
|
||||
if (exists) {
|
||||
return;
|
||||
}
|
||||
var passed = new Date().getTime() - start;
|
||||
if (timeThreshold && passed > timeThreshold) {
|
||||
throw new Error('Could not require ' + fileName);
|
||||
}
|
||||
}
|
||||
};
|
||||
var sendFsCompileRequest = function (fileName, compiledPath) {
|
||||
var compileRequestFile = [compiledDir, compilationId + '.req'].join(sep);
|
||||
fs.writeFileSync(compileRequestFile, [fileName, compiledPath].join('\n'));
|
||||
};
|
||||
var compile = function (code, fileName) {
|
||||
var compiledPath = getCompiledPath(code, fileName, compiledDir);
|
||||
if (process.send) {
|
||||
try {
|
||||
process.send({
|
||||
compile: fileName,
|
||||
compiledPath: compiledPath,
|
||||
});
|
||||
}
|
||||
catch (e) {
|
||||
console.warn('Error while sending compile request via process.send');
|
||||
sendFsCompileRequest(fileName, compiledPath);
|
||||
}
|
||||
}
|
||||
else {
|
||||
sendFsCompileRequest(fileName, compiledPath);
|
||||
}
|
||||
waitForFile(compiledPath + '.done');
|
||||
var compiled = fs.readFileSync(compiledPath, 'utf-8');
|
||||
return compiled;
|
||||
};
|
||||
function registerExtensions(extensions) {
|
||||
extensions.forEach(function (ext) {
|
||||
var old = require.extensions[ext] || require.extensions['.js'];
|
||||
require.extensions[ext] = function (m, fileName) {
|
||||
var _compile = m._compile;
|
||||
m._compile = function (code, fileName) {
|
||||
return _compile.call(this, compile(code, fileName), fileName);
|
||||
};
|
||||
return old(m, fileName);
|
||||
};
|
||||
});
|
||||
if (preferTs) {
|
||||
var reorderRequireExtension_1 = function (ext) {
|
||||
var old = require.extensions[ext];
|
||||
delete require.extensions[ext];
|
||||
require.extensions[ext] = old;
|
||||
};
|
||||
var order = ['.ts', '.tsx'].concat(Object.keys(require.extensions).filter(function (_) { return _ !== '.ts' && _ !== '.tsx'; }));
|
||||
order.forEach(function (ext) {
|
||||
reorderRequireExtension_1(ext);
|
||||
});
|
||||
}
|
||||
}
|
||||
function isFileInNodeModules(fileName) {
|
||||
return fileName.indexOf(sep + 'node_modules' + sep) >= 0;
|
||||
}
|
||||
function registerJsExtension() {
|
||||
var old = require.extensions['.js'];
|
||||
// handling preferTs probably redundant after reordering
|
||||
if (allowJs) {
|
||||
require.extensions['.jsx'] = require.extensions['.js'] = function (m, fileName) {
|
||||
if (fileName.indexOf(libPath) === 0) {
|
||||
return old(m, fileName);
|
||||
}
|
||||
var tsCode = undefined;
|
||||
var tsFileName = '';
|
||||
var _compile = m._compile;
|
||||
var isIgnored = ignore &&
|
||||
ignore.reduce(function (res, ignore) {
|
||||
return res || ignore.test(fileName);
|
||||
}, false);
|
||||
var ext = extname(fileName);
|
||||
if (tsCode !== undefined || (allowJs && !isIgnored && ext == '.js')) {
|
||||
m._compile = function (code, fileName) {
|
||||
if (tsCode !== undefined) {
|
||||
code = tsCode;
|
||||
fileName = tsFileName;
|
||||
}
|
||||
return _compile.call(this, compile(code, fileName), fileName);
|
||||
};
|
||||
}
|
||||
return old(m, fileName);
|
||||
};
|
||||
}
|
||||
}
|
||||
var sourceMapRequire = Module.createRequire
|
||||
? Module.createRequire(sourceMapSupportPath)
|
||||
: require;
|
||||
sourceMapRequire(sourceMapSupportPath).install({
|
||||
hookRequire: true,
|
||||
});
|
||||
registerJsExtension();
|
||||
registerExtensions(['.ts', '.tsx']);
|
||||
if (readyFile) {
|
||||
var time = new Date().getTime();
|
||||
while (!fs.existsSync(readyFile)) {
|
||||
if (new Date().getTime() - time > 5000) {
|
||||
throw new Error('Waiting ts-node-dev ready file failed');
|
||||
}
|
||||
}
|
||||
}
|
||||
if (exitChild) {
|
||||
process.on('SIGTERM', function () {
|
||||
console.log('Child got SIGTERM, exiting.');
|
||||
process.exit();
|
||||
});
|
||||
}
|
||||
module.exports.registerExtensions = registerExtensions;
|
290
node_modules/ts-node-dev/lib/compiler.js
generated
vendored
Normal file
290
node_modules/ts-node-dev/lib/compiler.js
generated
vendored
Normal file
@ -0,0 +1,290 @@
|
||||
"use strict";
|
||||
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
||||
if (k2 === undefined) k2 = k;
|
||||
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
|
||||
}) : (function(o, m, k, k2) {
|
||||
if (k2 === undefined) k2 = k;
|
||||
o[k2] = m[k];
|
||||
}));
|
||||
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
||||
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
||||
}) : function(o, v) {
|
||||
o["default"] = v;
|
||||
});
|
||||
var __importStar = (this && this.__importStar) || function (mod) {
|
||||
if (mod && mod.__esModule) return mod;
|
||||
var result = {};
|
||||
if (mod != null) for (var k in mod) if (k !== "default" && Object.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
||||
__setModuleDefault(result, mod);
|
||||
return result;
|
||||
};
|
||||
var __importDefault = (this && this.__importDefault) || function (mod) {
|
||||
return (mod && mod.__esModule) ? mod : { "default": mod };
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.makeCompiler = void 0;
|
||||
var tsNode = __importStar(require("ts-node"));
|
||||
var fs_1 = __importDefault(require("fs"));
|
||||
var path_1 = __importDefault(require("path"));
|
||||
var os_1 = __importDefault(require("os"));
|
||||
var mkdirp_1 = __importDefault(require("mkdirp"));
|
||||
var rimraf_1 = __importDefault(require("rimraf"));
|
||||
var tsconfig_1 = require("tsconfig");
|
||||
var get_compiled_path_1 = require("./get-compiled-path");
|
||||
var get_cwd_1 = require("./get-cwd");
|
||||
var fixPath = function (p) { return p.replace(/\\/g, '/').replace(/\$/g, '$$$$'); };
|
||||
var sourceMapSupportPath = require.resolve('source-map-support');
|
||||
var compileExtensions = ['.ts', '.tsx'];
|
||||
var cwd = process.cwd();
|
||||
var compilationInstanceStamp = Math.random().toString().slice(2);
|
||||
var originalJsHandler = require.extensions['.js'];
|
||||
var parse = function (value) {
|
||||
return typeof value === 'string' ? JSON.parse(value) : undefined;
|
||||
};
|
||||
function split(value) {
|
||||
return typeof value === 'string'
|
||||
? value.split(/ *, */g).filter(function (v) { return v !== ''; })
|
||||
: undefined;
|
||||
}
|
||||
exports.makeCompiler = function (options, _a) {
|
||||
var log = _a.log, restart = _a.restart;
|
||||
var _errorCompileTimeout;
|
||||
var allowJs = false;
|
||||
var project = options['project'];
|
||||
var tsConfigPath = tsconfig_1.resolveSync(cwd, typeof project === 'string' ? project : undefined) || '';
|
||||
var compiledPathsHash = {};
|
||||
var tmpDir = options['cache-directory']
|
||||
? path_1.default.resolve(options['cache-directory'])
|
||||
: fs_1.default.mkdtempSync(path_1.default.join(os_1.default.tmpdir(), '.ts-node'));
|
||||
var writeChildHookFile = function (options) {
|
||||
var compileTimeout = parseInt(options['compile-timeout']);
|
||||
var getIgnoreVal = function (ignore) {
|
||||
var ignoreVal = !ignore || ignore === 'false'
|
||||
? 'false'
|
||||
: '[' +
|
||||
ignore
|
||||
.split(/,/)
|
||||
.map(function (i) { return i.trim(); })
|
||||
.map(function (ignore) { return 'new RegExp("' + ignore + '")'; })
|
||||
.join(', ') +
|
||||
']';
|
||||
return ignoreVal;
|
||||
};
|
||||
var varDecl = function (name, value) { return "var " + name + " = '" + value + "'"; };
|
||||
var replacements = [
|
||||
compileTimeout ? ['10000', compileTimeout.toString()] : null,
|
||||
allowJs ? ['allowJs = false', 'allowJs = true'] : null,
|
||||
options['prefer-ts-exts']
|
||||
? ['preferTs = false', 'preferTs = true']
|
||||
: null,
|
||||
options['exec-check'] ? ['execCheck = false', 'execCheck = true'] : null,
|
||||
options['exit-child'] ? ['exitChild = false', 'exitChild = true'] : null,
|
||||
options['ignore'] !== undefined
|
||||
? [
|
||||
'var ignore = [/node_modules/]',
|
||||
'var ignore = ' + getIgnoreVal(options['ignore']),
|
||||
]
|
||||
: null,
|
||||
[
|
||||
varDecl('compilationId', ''),
|
||||
varDecl('compilationId', getCompilationId()),
|
||||
],
|
||||
[varDecl('compiledDir', ''), varDecl('compiledDir', getCompiledDir())],
|
||||
[
|
||||
'./get-compiled-path',
|
||||
fixPath(path_1.default.join(__dirname, 'get-compiled-path')),
|
||||
],
|
||||
[
|
||||
varDecl('readyFile', ''),
|
||||
varDecl('readyFile', getCompilerReadyFilePath()),
|
||||
],
|
||||
[
|
||||
varDecl('sourceMapSupportPath', ''),
|
||||
varDecl('sourceMapSupportPath', fixPath(sourceMapSupportPath)),
|
||||
],
|
||||
[
|
||||
varDecl('libPath', ''),
|
||||
varDecl('libPath', __dirname.replace(/\\/g, '\\\\')),
|
||||
],
|
||||
['__dirname', '"' + fixPath(__dirname) + '"'],
|
||||
]
|
||||
.filter(function (_) { return !!_; })
|
||||
.map(function (_) { return _; });
|
||||
var fileText = fs_1.default.readFileSync(path_1.default.join(__dirname, 'child-require-hook.js'), 'utf-8');
|
||||
var fileData = replacements.reduce(function (text, _a) {
|
||||
var what = _a[0], to = _a[1];
|
||||
return text.replace(what, to);
|
||||
}, fileText);
|
||||
fs_1.default.writeFileSync(getChildHookPath(), fileData);
|
||||
};
|
||||
var init = function () {
|
||||
registerTsNode();
|
||||
/* clean up compiled on each new init*/
|
||||
rimraf_1.default.sync(getCompiledDir());
|
||||
createCompiledDir();
|
||||
// check if `allowJs` compiler option enable
|
||||
// (.js handler was changed while ts-node registration)
|
||||
allowJs = require.extensions['.js'] !== originalJsHandler;
|
||||
if (allowJs) {
|
||||
compileExtensions.push('.js', '.jsx');
|
||||
}
|
||||
writeChildHookFile(options);
|
||||
};
|
||||
var getCompilationId = function () {
|
||||
return compilationInstanceStamp;
|
||||
};
|
||||
var createCompiledDir = function () {
|
||||
var compiledDir = getCompiledDir();
|
||||
if (!fs_1.default.existsSync(compiledDir)) {
|
||||
mkdirp_1.default.sync(getCompiledDir());
|
||||
}
|
||||
};
|
||||
var getCompiledDir = function () {
|
||||
return path_1.default.join(tmpDir, 'compiled').replace(/\\/g, '/');
|
||||
};
|
||||
var getCompileReqFilePath = function () {
|
||||
return path_1.default.join(getCompiledDir(), getCompilationId() + '.req');
|
||||
};
|
||||
var getCompilerReadyFilePath = function () {
|
||||
return path_1.default
|
||||
.join(os_1.default.tmpdir(), 'ts-node-dev-ready-' + compilationInstanceStamp)
|
||||
.replace(/\\/g, '/');
|
||||
};
|
||||
var getChildHookPath = function () {
|
||||
return path_1.default
|
||||
.join(os_1.default.tmpdir(), 'ts-node-dev-hook-' + compilationInstanceStamp + '.js')
|
||||
.replace(/\\/g, '/');
|
||||
};
|
||||
var writeReadyFile = function () {
|
||||
fs_1.default.writeFileSync(getCompilerReadyFilePath(), '');
|
||||
};
|
||||
var clearErrorCompile = function () {
|
||||
clearTimeout(_errorCompileTimeout);
|
||||
};
|
||||
var registerTsNode = function () {
|
||||
Object.keys(compiledPathsHash).forEach(function (key) {
|
||||
delete compiledPathsHash[key];
|
||||
});
|
||||
['.js', '.jsx', '.ts', '.tsx'].forEach(function (ext) {
|
||||
require.extensions[ext] = originalJsHandler;
|
||||
});
|
||||
var scriptPath = options._.length
|
||||
? path_1.default.resolve(cwd, options._[0])
|
||||
: undefined;
|
||||
tsNode.register({
|
||||
// --dir does not work (it gives a boolean only) so we only check for script-mode
|
||||
dir: get_cwd_1.getCwd(options['dir'], options['script-mode'], scriptPath),
|
||||
scope: options['scope'],
|
||||
scopeDir: options['scopeDir'],
|
||||
emit: options['emit'],
|
||||
files: options['files'],
|
||||
pretty: options['pretty'],
|
||||
transpileOnly: options['transpile-only'],
|
||||
ignore: options['ignore'] ? split(options['ignore']) : undefined,
|
||||
preferTsExts: options['prefer-ts-exts'],
|
||||
logError: options['log-error'],
|
||||
project: options['project'],
|
||||
skipProject: options['skip-project'],
|
||||
transpiler: options['transpiler'],
|
||||
skipIgnore: options['skip-ignore'],
|
||||
compiler: options['compiler'],
|
||||
compilerHost: options['compiler-host'],
|
||||
ignoreDiagnostics: options['ignore-diagnostics']
|
||||
? split(options['ignore-diagnostics'])
|
||||
: undefined,
|
||||
compilerOptions: parse(options['compiler-options']),
|
||||
});
|
||||
};
|
||||
var compiler = {
|
||||
tsConfigPath: tsConfigPath,
|
||||
init: init,
|
||||
getCompileReqFilePath: getCompileReqFilePath,
|
||||
getChildHookPath: getChildHookPath,
|
||||
writeReadyFile: writeReadyFile,
|
||||
clearErrorCompile: clearErrorCompile,
|
||||
compileChanged: function (fileName) {
|
||||
var ext = path_1.default.extname(fileName);
|
||||
if (compileExtensions.indexOf(ext) < 0)
|
||||
return;
|
||||
try {
|
||||
var code = fs_1.default.readFileSync(fileName, 'utf-8');
|
||||
compiler.compile({
|
||||
code: code,
|
||||
compile: fileName,
|
||||
compiledPath: get_compiled_path_1.getCompiledPath(code, fileName, getCompiledDir()),
|
||||
});
|
||||
}
|
||||
catch (e) {
|
||||
console.error(e);
|
||||
}
|
||||
},
|
||||
compile: function (params) {
|
||||
var fileName = params.compile;
|
||||
var code = fs_1.default.readFileSync(fileName, 'utf-8');
|
||||
var compiledPath = params.compiledPath;
|
||||
// Prevent occasional duplicate compilation requests
|
||||
if (compiledPathsHash[compiledPath]) {
|
||||
return;
|
||||
}
|
||||
compiledPathsHash[compiledPath] = true;
|
||||
function writeCompiled(code, fileName) {
|
||||
fs_1.default.writeFile(compiledPath, code, function (err) {
|
||||
err && log.error(err);
|
||||
fs_1.default.writeFile(compiledPath + '.done', '', function (err) {
|
||||
err && log.error(err);
|
||||
});
|
||||
});
|
||||
}
|
||||
if (fs_1.default.existsSync(compiledPath)) {
|
||||
return;
|
||||
}
|
||||
var starTime = new Date().getTime();
|
||||
var m = {
|
||||
_compile: writeCompiled,
|
||||
};
|
||||
var _compile = function () {
|
||||
var ext = path_1.default.extname(fileName);
|
||||
var extHandler = require.extensions[ext];
|
||||
extHandler(m, fileName);
|
||||
log.debug(fileName, 'compiled in', new Date().getTime() - starTime, 'ms');
|
||||
};
|
||||
try {
|
||||
_compile();
|
||||
}
|
||||
catch (e) {
|
||||
console.error('Compilation error in', fileName);
|
||||
var errorCode = 'throw ' +
|
||||
'new Error(' +
|
||||
JSON.stringify(e.message) +
|
||||
')' +
|
||||
';';
|
||||
writeCompiled(errorCode);
|
||||
// reinitialize ts-node compilation to clean up state after error
|
||||
// without timeout in causes cases error not be printed out
|
||||
setTimeout(function () {
|
||||
registerTsNode();
|
||||
}, 0);
|
||||
if (!options['error-recompile']) {
|
||||
return;
|
||||
}
|
||||
var timeoutMs_1 = parseInt(process.env.TS_NODE_DEV_ERROR_RECOMPILE_TIMEOUT || '0') ||
|
||||
5000;
|
||||
var errorHandler_1 = function () {
|
||||
clearTimeout(_errorCompileTimeout);
|
||||
_errorCompileTimeout = setTimeout(function () {
|
||||
try {
|
||||
_compile();
|
||||
restart(fileName);
|
||||
}
|
||||
catch (e) {
|
||||
registerTsNode();
|
||||
errorHandler_1();
|
||||
}
|
||||
}, timeoutMs_1);
|
||||
};
|
||||
errorHandler_1();
|
||||
}
|
||||
},
|
||||
};
|
||||
return compiler;
|
||||
};
|
2
node_modules/ts-node-dev/lib/dedupe.js
generated
vendored
Normal file
2
node_modules/ts-node-dev/lib/dedupe.js
generated
vendored
Normal file
@ -0,0 +1,2 @@
|
||||
"use strict";
|
||||
require('dynamic-dedupe').activate();
|
18
node_modules/ts-node-dev/lib/get-compiled-path.js
generated
vendored
Normal file
18
node_modules/ts-node-dev/lib/get-compiled-path.js
generated
vendored
Normal file
@ -0,0 +1,18 @@
|
||||
"use strict";
|
||||
var __importDefault = (this && this.__importDefault) || function (mod) {
|
||||
return (mod && mod.__esModule) ? mod : { "default": mod };
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.getCompiledPath = void 0;
|
||||
var crypto_1 = __importDefault(require("crypto"));
|
||||
var path_1 = __importDefault(require("path"));
|
||||
var cwd = process.cwd();
|
||||
exports.getCompiledPath = function (code, fileName, compiledDir) {
|
||||
var hash = crypto_1.default
|
||||
.createHash('sha256')
|
||||
.update(fileName + code, 'utf8')
|
||||
.digest('hex');
|
||||
fileName = path_1.default.relative(cwd, fileName);
|
||||
var hashed = fileName.replace(/[^\w]/g, '_') + '_' + hash + '.js';
|
||||
return path_1.default.join(compiledDir, hashed);
|
||||
};
|
49
node_modules/ts-node-dev/lib/get-cwd.js
generated
vendored
Normal file
49
node_modules/ts-node-dev/lib/get-cwd.js
generated
vendored
Normal file
@ -0,0 +1,49 @@
|
||||
"use strict";
|
||||
var __importDefault = (this && this.__importDefault) || function (mod) {
|
||||
return (mod && mod.__esModule) ? mod : { "default": mod };
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.getCwd = void 0;
|
||||
var path_1 = __importDefault(require("path"));
|
||||
var hasOwnProperty = function (object, property) {
|
||||
return Object.prototype.hasOwnProperty.call(object, property);
|
||||
};
|
||||
exports.getCwd = function (dir, scriptMode, scriptPath) {
|
||||
if (scriptMode) {
|
||||
if (!scriptPath) {
|
||||
console.error('Script mode must be used with a script name, e.g. `ts-node-dev -s <script.ts>`');
|
||||
process.exit();
|
||||
}
|
||||
if (dir) {
|
||||
console.error('Script mode cannot be combined with `--dir`');
|
||||
process.exit();
|
||||
}
|
||||
// Use node's own resolution behavior to ensure we follow symlinks.
|
||||
// scriptPath may omit file extension or point to a directory with or without package.json.
|
||||
// This happens before we are registered, so we tell node's resolver to consider ts, tsx, and jsx files.
|
||||
// In extremely rare cases, is is technically possible to resolve the wrong directory,
|
||||
// because we do not yet know preferTsExts, jsx, nor allowJs.
|
||||
// See also, justification why this will not happen in real-world situations:
|
||||
// https://github.com/TypeStrong/ts-node/pull/1009#issuecomment-613017081
|
||||
var exts = ['.js', '.jsx', '.ts', '.tsx'];
|
||||
var extsTemporarilyInstalled = [];
|
||||
for (var _i = 0, exts_1 = exts; _i < exts_1.length; _i++) {
|
||||
var ext = exts_1[_i];
|
||||
if (!hasOwnProperty(require.extensions, ext)) {
|
||||
// tslint:disable-line
|
||||
extsTemporarilyInstalled.push(ext);
|
||||
require.extensions[ext] = function () { }; // tslint:disable-line
|
||||
}
|
||||
}
|
||||
try {
|
||||
return path_1.default.dirname(require.resolve(scriptPath));
|
||||
}
|
||||
finally {
|
||||
for (var _a = 0, extsTemporarilyInstalled_1 = extsTemporarilyInstalled; _a < extsTemporarilyInstalled_1.length; _a++) {
|
||||
var ext = extsTemporarilyInstalled_1[_a];
|
||||
delete require.extensions[ext]; // tslint:disable-line
|
||||
}
|
||||
}
|
||||
}
|
||||
return dir;
|
||||
};
|
68
node_modules/ts-node-dev/lib/hook.js
generated
vendored
Normal file
68
node_modules/ts-node-dev/lib/hook.js
generated
vendored
Normal file
@ -0,0 +1,68 @@
|
||||
"use strict";
|
||||
var __importDefault = (this && this.__importDefault) || function (mod) {
|
||||
return (mod && mod.__esModule) ? mod : { "default": mod };
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.makeHook = void 0;
|
||||
var vm_1 = __importDefault(require("vm"));
|
||||
exports.makeHook = function (cfg, wrapper, callback) {
|
||||
// Hook into Node's `require(...)`
|
||||
updateHooks();
|
||||
// Patch the vm module to watch files executed via one of these methods:
|
||||
if (cfg.vm) {
|
||||
patch(vm_1.default, 'createScript', 1);
|
||||
patch(vm_1.default, 'runInThisContext', 1);
|
||||
patch(vm_1.default, 'runInNewContext', 2);
|
||||
patch(vm_1.default, 'runInContext', 2);
|
||||
}
|
||||
/**
|
||||
* Patch the specified method to watch the file at the given argument
|
||||
* index.
|
||||
*/
|
||||
function patch(obj, method, optionsArgIndex) {
|
||||
var orig = obj[method];
|
||||
if (!orig)
|
||||
return;
|
||||
obj[method] = function () {
|
||||
var opts = arguments[optionsArgIndex];
|
||||
var file = null;
|
||||
if (opts) {
|
||||
file = typeof opts == 'string' ? opts : opts.filename;
|
||||
}
|
||||
if (file)
|
||||
callback(file);
|
||||
return orig.apply(this, arguments);
|
||||
};
|
||||
}
|
||||
/**
|
||||
* (Re-)install hooks for all registered file extensions.
|
||||
*/
|
||||
function updateHooks() {
|
||||
Object.keys(require.extensions).forEach(function (ext) {
|
||||
var fn = require.extensions[ext];
|
||||
if (typeof fn === 'function' && fn.name !== 'nodeDevHook') {
|
||||
require.extensions[ext] = createHook(fn);
|
||||
}
|
||||
});
|
||||
}
|
||||
/**
|
||||
* Returns a function that can be put into `require.extensions` in order to
|
||||
* invoke the callback when a module is required for the first time.
|
||||
*/
|
||||
function createHook(handler) {
|
||||
return function nodeDevHook(module, filename) {
|
||||
if (module.parent === wrapper) {
|
||||
// If the main module is required conceal the wrapper
|
||||
module.id = '.';
|
||||
module.parent = null;
|
||||
process.mainModule = module;
|
||||
}
|
||||
if (!module.loaded)
|
||||
callback(module.filename);
|
||||
// Invoke the original handler
|
||||
handler(module, filename);
|
||||
// Make sure the module did not hijack the handler
|
||||
updateHooks();
|
||||
};
|
||||
}
|
||||
};
|
286
node_modules/ts-node-dev/lib/index.js
generated
vendored
Normal file
286
node_modules/ts-node-dev/lib/index.js
generated
vendored
Normal file
@ -0,0 +1,286 @@
|
||||
"use strict";
|
||||
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
||||
if (k2 === undefined) k2 = k;
|
||||
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
|
||||
}) : (function(o, m, k, k2) {
|
||||
if (k2 === undefined) k2 = k;
|
||||
o[k2] = m[k];
|
||||
}));
|
||||
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
||||
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
||||
}) : function(o, v) {
|
||||
o["default"] = v;
|
||||
});
|
||||
var __importStar = (this && this.__importStar) || function (mod) {
|
||||
if (mod && mod.__esModule) return mod;
|
||||
var result = {};
|
||||
if (mod != null) for (var k in mod) if (k !== "default" && Object.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
||||
__setModuleDefault(result, mod);
|
||||
return result;
|
||||
};
|
||||
var __importDefault = (this && this.__importDefault) || function (mod) {
|
||||
return (mod && mod.__esModule) ? mod : { "default": mod };
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.runDev = void 0;
|
||||
var child_process_1 = require("child_process");
|
||||
var chokidar_1 = __importDefault(require("chokidar"));
|
||||
var fs_1 = __importDefault(require("fs"));
|
||||
var readline_1 = __importDefault(require("readline"));
|
||||
var kill = require('tree-kill');
|
||||
var ipc = __importStar(require("./ipc"));
|
||||
var resolveMain_1 = require("./resolveMain");
|
||||
var compiler_1 = require("./compiler");
|
||||
var cfg_1 = require("./cfg");
|
||||
var notify_1 = require("./notify");
|
||||
var log_1 = require("./log");
|
||||
var version = require('../package.json').version;
|
||||
var tsNodeVersion = require('ts-node').VERSION;
|
||||
var tsVersion = require('typescript').version;
|
||||
exports.runDev = function (script, scriptArgs, nodeArgs, opts) {
|
||||
if (typeof script !== 'string' || script.length === 0) {
|
||||
throw new TypeError('`script` must be a string');
|
||||
}
|
||||
if (!Array.isArray(scriptArgs)) {
|
||||
throw new TypeError('`scriptArgs` must be an array');
|
||||
}
|
||||
if (!Array.isArray(nodeArgs)) {
|
||||
throw new TypeError('`nodeArgs` must be an array');
|
||||
}
|
||||
// The child_process
|
||||
var child;
|
||||
var wrapper = resolveMain_1.resolveMain(__dirname + '/wrap.js');
|
||||
var main = resolveMain_1.resolveMain(script);
|
||||
var cfg = cfg_1.makeCfg(main, opts);
|
||||
var log = log_1.makeLog(cfg);
|
||||
var notify = notify_1.makeNotify(cfg, log);
|
||||
// Run ./dedupe.js as preload script
|
||||
if (cfg.dedupe)
|
||||
process.env.NODE_DEV_PRELOAD = __dirname + '/dedupe';
|
||||
function initWatcher() {
|
||||
var watcher = chokidar_1.default.watch([], {
|
||||
usePolling: opts.poll,
|
||||
interval: parseInt(opts.interval) || undefined,
|
||||
});
|
||||
watcher.on('change', restart);
|
||||
watcher.on('fallback', function (limit) {
|
||||
log.warn('node-dev ran out of file handles after watching %s files.', limit);
|
||||
log.warn('Falling back to polling which uses more CPU.');
|
||||
log.info('Run ulimit -n 10000 to increase the file descriptor limit.');
|
||||
if (cfg.deps)
|
||||
log.info('... or add `--no-deps` to use less file handles.');
|
||||
});
|
||||
return watcher;
|
||||
}
|
||||
var watcher = initWatcher();
|
||||
var starting = false;
|
||||
// Read for "rs" from command line
|
||||
if (opts.rs !== false) {
|
||||
var rl = readline_1.default.createInterface({
|
||||
input: process.stdin,
|
||||
output: process.stdout,
|
||||
terminal: false,
|
||||
});
|
||||
rl.on('line', function (line) {
|
||||
if (line.trim() === 'rs') {
|
||||
restart('', true);
|
||||
}
|
||||
});
|
||||
}
|
||||
log.info('ts-node-dev ver. ' +
|
||||
version +
|
||||
' (using ts-node ver. ' +
|
||||
tsNodeVersion +
|
||||
', typescript ver. ' +
|
||||
tsVersion +
|
||||
')');
|
||||
/**
|
||||
* Run the wrapped script.
|
||||
*/
|
||||
var compileReqWatcher;
|
||||
function start() {
|
||||
if (cfg.clear)
|
||||
process.stdout.write('\u001bc');
|
||||
for (var _i = 0, _a = (opts.watch || '').split(','); _i < _a.length; _i++) {
|
||||
var watched = _a[_i];
|
||||
if (watched)
|
||||
watcher.add(watched);
|
||||
}
|
||||
var cmd = nodeArgs.concat(wrapper, script, scriptArgs);
|
||||
var childHookPath = compiler.getChildHookPath();
|
||||
cmd = (opts.priorNodeArgs || []).concat(['-r', childHookPath]).concat(cmd);
|
||||
log.debug('Starting child process %s', cmd.join(' '));
|
||||
child = child_process_1.fork(cmd[0], cmd.slice(1), {
|
||||
cwd: process.cwd(),
|
||||
env: process.env,
|
||||
});
|
||||
starting = false;
|
||||
if (compileReqWatcher) {
|
||||
compileReqWatcher.close();
|
||||
}
|
||||
compileReqWatcher = chokidar_1.default.watch([], {
|
||||
usePolling: opts.poll,
|
||||
interval: parseInt(opts.interval) || undefined,
|
||||
});
|
||||
var currentCompilePath;
|
||||
fs_1.default.writeFileSync(compiler.getCompileReqFilePath(), '');
|
||||
compileReqWatcher.add(compiler.getCompileReqFilePath());
|
||||
compileReqWatcher.on('change', function (file) {
|
||||
fs_1.default.readFile(file, 'utf-8', function (err, data) {
|
||||
if (err) {
|
||||
log.error('Error reading compile request file', err);
|
||||
return;
|
||||
}
|
||||
var split = data.split('\n');
|
||||
var compile = split[0];
|
||||
var compiledPath = split[1];
|
||||
if (currentCompilePath == compiledPath)
|
||||
return;
|
||||
currentCompilePath = compiledPath;
|
||||
if (compiledPath) {
|
||||
compiler.compile({
|
||||
compile: compile,
|
||||
compiledPath: compiledPath,
|
||||
});
|
||||
}
|
||||
});
|
||||
});
|
||||
child.on('message', function (message) {
|
||||
if (!message.compiledPath ||
|
||||
currentCompilePath === message.compiledPath) {
|
||||
return;
|
||||
}
|
||||
currentCompilePath = message.compiledPath;
|
||||
compiler.compile(message);
|
||||
});
|
||||
child.on('exit', function (code) {
|
||||
log.debug('Child exited with code %s', code);
|
||||
if (!child)
|
||||
return;
|
||||
if (!child.respawn)
|
||||
process.exit(code || 0);
|
||||
child = undefined;
|
||||
});
|
||||
if (cfg.respawn) {
|
||||
child.respawn = true;
|
||||
}
|
||||
if (compiler.tsConfigPath) {
|
||||
watcher.add(compiler.tsConfigPath);
|
||||
}
|
||||
// Listen for `required` messages and watch the required file.
|
||||
ipc.on(child, 'required', function (m) {
|
||||
var required = m.required;
|
||||
var isIgnored = cfg.ignore.some(isPrefixOf(required)) ||
|
||||
cfg.ignore.some(isRegExpMatch(required));
|
||||
if (!isIgnored && (cfg.deps === -1 || getLevel(required) <= cfg.deps)) {
|
||||
log.debug(required, 'added to watcher');
|
||||
watcher.add(required);
|
||||
}
|
||||
});
|
||||
// Upon errors, display a notification and tell the child to exit.
|
||||
ipc.on(child, 'error', function (m) {
|
||||
log.debug('Child error');
|
||||
notify(m.error, m.message, 'error');
|
||||
stop(m.willTerminate);
|
||||
});
|
||||
compiler.writeReadyFile();
|
||||
}
|
||||
var killChild = function () {
|
||||
if (!child)
|
||||
return;
|
||||
log.debug('Sending SIGTERM kill to child pid', child.pid);
|
||||
if (opts['tree-kill']) {
|
||||
log.debug('Using tree-kill');
|
||||
kill(child.pid);
|
||||
}
|
||||
else {
|
||||
child.kill('SIGTERM');
|
||||
}
|
||||
};
|
||||
function stop(willTerminate) {
|
||||
if (!child || child.stopping) {
|
||||
return;
|
||||
}
|
||||
child.stopping = true;
|
||||
child.respawn = true;
|
||||
if (child.connected === undefined || child.connected === true) {
|
||||
log.debug('Disconnecting from child');
|
||||
child.disconnect();
|
||||
if (!willTerminate) {
|
||||
killChild();
|
||||
}
|
||||
}
|
||||
}
|
||||
function restart(file, isManualRestart) {
|
||||
if (file === compiler.tsConfigPath) {
|
||||
notify('Reinitializing TS compilation', '');
|
||||
compiler.init();
|
||||
}
|
||||
compiler.clearErrorCompile();
|
||||
if (isManualRestart === true) {
|
||||
notify('Restarting', 'manual restart from user');
|
||||
}
|
||||
else {
|
||||
notify('Restarting', file + ' has been modified');
|
||||
}
|
||||
compiler.compileChanged(file);
|
||||
if (starting) {
|
||||
log.debug('Already starting');
|
||||
return;
|
||||
}
|
||||
log.debug('Removing all watchers from files');
|
||||
//watcher.removeAll()ya
|
||||
watcher.close();
|
||||
watcher = initWatcher();
|
||||
starting = true;
|
||||
if (child) {
|
||||
log.debug('Child is still running, restart upon exit');
|
||||
child.on('exit', start);
|
||||
stop();
|
||||
}
|
||||
else {
|
||||
log.debug('Child is already stopped, probably due to a previous error');
|
||||
start();
|
||||
}
|
||||
}
|
||||
// Relay SIGTERM
|
||||
process.on('SIGTERM', function () {
|
||||
log.debug('Process got SIGTERM');
|
||||
killChild();
|
||||
process.exit(0);
|
||||
});
|
||||
var compiler = compiler_1.makeCompiler(opts, {
|
||||
restart: restart,
|
||||
log: log,
|
||||
});
|
||||
compiler.init();
|
||||
start();
|
||||
};
|
||||
/**
|
||||
* Returns the nesting-level of the given module.
|
||||
* Will return 0 for modules from the main package or linked modules,
|
||||
* a positive integer otherwise.
|
||||
*/
|
||||
function getLevel(mod) {
|
||||
var p = getPrefix(mod);
|
||||
return p.split('node_modules').length - 1;
|
||||
}
|
||||
/**
|
||||
* Returns the path up to the last occurence of `node_modules` or an
|
||||
* empty string if the path does not contain a node_modules dir.
|
||||
*/
|
||||
function getPrefix(mod) {
|
||||
var n = 'node_modules';
|
||||
var i = mod.lastIndexOf(n);
|
||||
return ~i ? mod.slice(0, i + n.length) : '';
|
||||
}
|
||||
function isPrefixOf(value) {
|
||||
return function (prefix) {
|
||||
return value.indexOf(prefix) === 0;
|
||||
};
|
||||
}
|
||||
function isRegExpMatch(value) {
|
||||
return function (regExp) {
|
||||
return new RegExp(regExp).test(value);
|
||||
};
|
||||
}
|
35
node_modules/ts-node-dev/lib/ipc.js
generated
vendored
Normal file
35
node_modules/ts-node-dev/lib/ipc.js
generated
vendored
Normal file
@ -0,0 +1,35 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.relay = exports.on = exports.send = void 0;
|
||||
/**
|
||||
* Checks if the given message is an internal node-dev message.
|
||||
*/
|
||||
function isNodeDevMessage(m) {
|
||||
return m.cmd === 'NODE_DEV';
|
||||
}
|
||||
/**
|
||||
* Sends a message to the given process.
|
||||
*/
|
||||
exports.send = function (m, dest) {
|
||||
if (dest === void 0) { dest = process; }
|
||||
m.cmd = 'NODE_DEV';
|
||||
if (dest.send)
|
||||
dest.send(m);
|
||||
};
|
||||
exports.on = function (proc, type, cb) {
|
||||
function handleMessage(m) {
|
||||
if (isNodeDevMessage(m) && type in m)
|
||||
cb(m);
|
||||
}
|
||||
proc.on('internalMessage', handleMessage);
|
||||
proc.on('message', handleMessage);
|
||||
};
|
||||
exports.relay = function (src, dest) {
|
||||
if (dest === void 0) { dest = process; }
|
||||
function relayMessage(m) {
|
||||
if (isNodeDevMessage(m))
|
||||
dest.send(m);
|
||||
}
|
||||
src.on('internalMessage', relayMessage);
|
||||
src.on('message', relayMessage);
|
||||
};
|
50
node_modules/ts-node-dev/lib/log.js
generated
vendored
Normal file
50
node_modules/ts-node-dev/lib/log.js
generated
vendored
Normal file
@ -0,0 +1,50 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.makeLog = void 0;
|
||||
var util = require('util');
|
||||
var colors = {
|
||||
info: '36',
|
||||
error: '31;1',
|
||||
warn: '33',
|
||||
debug: '90',
|
||||
};
|
||||
var formatDate = function (date) {
|
||||
return [date.getHours(), date.getMinutes(), date.getSeconds()]
|
||||
.map(function (n) { return n.toString().padStart(2, '0'); })
|
||||
.join(':');
|
||||
};
|
||||
/**
|
||||
* Logs a message to the console. The level is displayed in ANSI colors,
|
||||
* either bright red in case of an error or green otherwise.
|
||||
*/
|
||||
exports.makeLog = function (cfg) {
|
||||
function log(msg, level) {
|
||||
if (cfg.quiet && level === 'info')
|
||||
return;
|
||||
if (cfg.timestamp)
|
||||
msg = color(formatDate(new Date()), '30;1') + ' ' + msg;
|
||||
var c = colors[level.toLowerCase()] || '32';
|
||||
console.log('[' + color(level.toUpperCase(), c) + '] ' + msg);
|
||||
}
|
||||
function color(s, c) {
|
||||
if (process.stdout.isTTY) {
|
||||
return '\x1B[' + c + 'm' + s + '\x1B[0m';
|
||||
}
|
||||
return s;
|
||||
}
|
||||
log.debug = function () {
|
||||
if (!cfg.debug)
|
||||
return;
|
||||
log(util.format.apply(util, arguments), 'debug');
|
||||
};
|
||||
log.info = function () {
|
||||
log(util.format.apply(util, arguments), 'info');
|
||||
};
|
||||
log.warn = function () {
|
||||
log(util.format.apply(util, arguments), 'warn');
|
||||
};
|
||||
log.error = function () {
|
||||
log(util.format.apply(util, arguments), 'error');
|
||||
};
|
||||
return log;
|
||||
};
|
33
node_modules/ts-node-dev/lib/notify.js
generated
vendored
Normal file
33
node_modules/ts-node-dev/lib/notify.js
generated
vendored
Normal file
@ -0,0 +1,33 @@
|
||||
"use strict";
|
||||
var __importDefault = (this && this.__importDefault) || function (mod) {
|
||||
return (mod && mod.__esModule) ? mod : { "default": mod };
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.makeNotify = void 0;
|
||||
var path_1 = __importDefault(require("path"));
|
||||
var notifier = null;
|
||||
try {
|
||||
notifier = require('node-notifier');
|
||||
}
|
||||
catch (error) {
|
||||
notifier = null;
|
||||
}
|
||||
function icon(level) {
|
||||
return path_1.default.resolve(__dirname, '../icons/node_' + level + '.png');
|
||||
}
|
||||
/**
|
||||
* Displays a desktop notification and writes a message to the console.
|
||||
*/
|
||||
exports.makeNotify = function (cfg, log) {
|
||||
return function (title, msg, level) {
|
||||
level = level || 'info';
|
||||
log([title, msg].filter(function (_) { return _; }).join(': '), level);
|
||||
if (notifier !== null && cfg.notify) {
|
||||
notifier.notify({
|
||||
title: title || 'node.js',
|
||||
icon: icon(level),
|
||||
message: msg,
|
||||
});
|
||||
}
|
||||
};
|
||||
};
|
33
node_modules/ts-node-dev/lib/resolveMain.js
generated
vendored
Normal file
33
node_modules/ts-node-dev/lib/resolveMain.js
generated
vendored
Normal file
@ -0,0 +1,33 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.resolveMain = void 0;
|
||||
var resolve = require('resolve');
|
||||
function resolveRequest(req) {
|
||||
// The `resolve` package is prebuilt through ncc, which prevents
|
||||
// PnP from being able to inject itself into it. To circumvent
|
||||
// this, we simply use PnP directly when available.
|
||||
if (process.versions.pnp) {
|
||||
var resolveRequest_1 = require("pnpapi").resolveRequest;
|
||||
return resolveRequest_1(req, process.cwd() + '/');
|
||||
}
|
||||
else {
|
||||
var opts = {
|
||||
basedir: process.cwd(),
|
||||
paths: [process.cwd()],
|
||||
};
|
||||
return resolve.sync(req, opts);
|
||||
}
|
||||
}
|
||||
exports.resolveMain = function (main) {
|
||||
try {
|
||||
return resolveRequest(main + '.ts');
|
||||
}
|
||||
catch (e) {
|
||||
try {
|
||||
return resolveRequest(main + '/index.ts');
|
||||
}
|
||||
catch (e) {
|
||||
return resolveRequest(main);
|
||||
}
|
||||
}
|
||||
};
|
104
node_modules/ts-node-dev/lib/wrap.js
generated
vendored
Normal file
104
node_modules/ts-node-dev/lib/wrap.js
generated
vendored
Normal file
@ -0,0 +1,104 @@
|
||||
"use strict";
|
||||
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
||||
if (k2 === undefined) k2 = k;
|
||||
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
|
||||
}) : (function(o, m, k, k2) {
|
||||
if (k2 === undefined) k2 = k;
|
||||
o[k2] = m[k];
|
||||
}));
|
||||
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
||||
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
||||
}) : function(o, v) {
|
||||
o["default"] = v;
|
||||
});
|
||||
var __importStar = (this && this.__importStar) || function (mod) {
|
||||
if (mod && mod.__esModule) return mod;
|
||||
var result = {};
|
||||
if (mod != null) for (var k in mod) if (k !== "default" && Object.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
||||
__setModuleDefault(result, mod);
|
||||
return result;
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
var childProcess = require('child_process');
|
||||
var child_process_1 = require("child_process");
|
||||
var resolve = require('resolve').sync;
|
||||
var hook_1 = require("./hook");
|
||||
var ipc = __importStar(require("./ipc"));
|
||||
var resolveMain_1 = require("./resolveMain");
|
||||
var cfg_1 = require("./cfg");
|
||||
// const Module = require('module')
|
||||
// Remove wrap.js from the argv array
|
||||
process.argv.splice(1, 1);
|
||||
// Resolve the location of the main script relative to cwd
|
||||
var main = resolveMain_1.resolveMain(process.argv[1]);
|
||||
var cfg = cfg_1.makeCfg(main, {});
|
||||
if (process.env.TS_NODE_DEV === undefined) {
|
||||
process.env.TS_NODE_DEV = 'true';
|
||||
}
|
||||
if (process.env.NODE_DEV_PRELOAD) {
|
||||
require(process.env.NODE_DEV_PRELOAD);
|
||||
}
|
||||
// Listen SIGTERM and exit unless there is another listener
|
||||
process.on('SIGTERM', function () {
|
||||
if (process.listeners('SIGTERM').length === 1)
|
||||
process.exit(0);
|
||||
});
|
||||
if (cfg.fork) {
|
||||
var oldFork_1 = child_process_1.fork;
|
||||
// Overwrite child_process.fork() so that we can hook into forked processes
|
||||
// too. We also need to relay messages about required files to the parent.
|
||||
var newFork = function (modulePath, args, options) {
|
||||
var child = oldFork_1(__filename, [modulePath].concat(args), options);
|
||||
ipc.relay(child);
|
||||
return child;
|
||||
};
|
||||
childProcess.fork = newFork;
|
||||
}
|
||||
// const lastRequired = null
|
||||
// const origRequire = Module.prototype.require
|
||||
// Module.prototype.require = function (requirePath) {
|
||||
// lastRequired = { path: requirePath, filename: this.filename }
|
||||
// return origRequire.apply(this, arguments)
|
||||
// }
|
||||
// Error handler that displays a notification and logs the stack to stderr:
|
||||
var caught = false;
|
||||
process.on('uncaughtException', function (err) {
|
||||
// NB: err can be null
|
||||
// Handle exception only once
|
||||
if (caught)
|
||||
return;
|
||||
caught = true;
|
||||
// If there's a custom uncaughtException handler expect it to terminate
|
||||
// the process.
|
||||
var hasCustomHandler = process.listeners('uncaughtException').length > 1;
|
||||
var isTsError = err && err.message && /TypeScript/.test(err.message);
|
||||
if (!hasCustomHandler && !isTsError) {
|
||||
console.error((err && err.stack) || err);
|
||||
}
|
||||
ipc.send({
|
||||
error: isTsError ? '' : (err && err.name) || 'Error',
|
||||
// lastRequired: lastRequired,
|
||||
message: err ? err.message : '',
|
||||
code: err && err.code,
|
||||
willTerminate: hasCustomHandler,
|
||||
});
|
||||
});
|
||||
// Hook into require() and notify the parent process about required files
|
||||
hook_1.makeHook(cfg, module, function (file) {
|
||||
ipc.send({ required: file });
|
||||
});
|
||||
// Check if a module is registered for this extension
|
||||
// const ext = path.extname(main).slice(1)
|
||||
// const mod = cfg.extensions[ext]
|
||||
// // Support extensions where 'require' returns a function that accepts options
|
||||
// if (typeof mod == 'object' && mod.name) {
|
||||
// const fn = require(resolve(mod.name, { basedir: path.dirname(main) }))
|
||||
// if (typeof fn == 'function' && mod.options) {
|
||||
// // require returned a function, call it with options
|
||||
// fn(mod.options)
|
||||
// }
|
||||
// } else if (typeof mod == 'string') {
|
||||
// require(resolve(mod, { basedir: path.dirname(main) }))
|
||||
// }
|
||||
// Execute the wrapped script
|
||||
require(main);
|
Reference in New Issue
Block a user