Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

ts-node

Package Overview
Dependencies
Maintainers
1
Versions
128
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

ts-node - npm Package Compare versions

Comparing version 2.1.2 to 3.0.0

10

dist/_bin.js

@@ -14,7 +14,6 @@ "use strict";

var strings = ['eval', 'print', 'compiler', 'project', 'ignoreWarnings', 'require', 'cacheDirectory', 'ignore'];
var booleans = ['help', 'fast', 'lazy', 'version', 'disableWarnings', 'cache'];
var booleans = ['help', 'fast', 'version', 'disableWarnings', 'cache'];
var aliases = {
help: ['h'],
fast: ['F'],
lazy: ['L'],
version: ['v'],

@@ -83,3 +82,3 @@ eval: ['e'],

if (argv.help) {
console.log("\nUsage: ts-node [options] [ -e script | script.ts ] [arguments]\n\nOptions:\n\n -e, --eval [code] Evaluate code\n -p, --print [code] Evaluate code and print result\n -r, --require [path] Require a node module for execution\n -C, --compiler [name] Specify a custom TypeScript compiler\n -I, --ignoreWarnings [code] Ignore TypeScript warnings by diagnostic code\n -D, --disableWarnings Ignore every TypeScript warning\n -P, --project [path] Path to TypeScript project (or `false`)\n -O, --compilerOptions [opts] JSON object to merge with compiler options\n -L, --lazy Lazily load TypeScript compilation on demand\n -F, --fast Run TypeScript compilation in transpile mode\n --ignore [regexp], --no-ignore Set the ignore check (default: `/node_modules/`)\n --no-cache Disable the TypeScript cache\n --cache-directory Configure the TypeScript cache directory\n");
console.log("\nUsage: ts-node [options] [ -e script | script.ts ] [arguments]\n\nOptions:\n\n -e, --eval [code] Evaluate code\n -p, --print [code] Evaluate code and print result\n -r, --require [path] Require a node module for execution\n -C, --compiler [name] Specify a custom TypeScript compiler\n -I, --ignoreWarnings [code] Ignore TypeScript warnings by diagnostic code\n -D, --disableWarnings Ignore every TypeScript warning\n -P, --project [path] Path to TypeScript project (or `false`)\n -O, --compilerOptions [opts] JSON object to merge with compiler options\n -F, --fast Run TypeScript compilation in transpile mode\n --ignore [regexp], --no-ignore Set the ignore check (default: `/node_modules/`)\n --no-cache Disable the TypeScript cache\n --cache-directory Configure the TypeScript cache directory\n");
process.exit(0);

@@ -95,3 +94,2 @@ }

fast: argv.fast,
lazy: argv.lazy,
cache: argv.cache,

@@ -169,3 +167,3 @@ cacheDirectory: argv.cacheDirectory,

try {
output = service().compile(EVAL_INSTANCE.input, EVAL_PATH, -lines);
output = service.compile(EVAL_INSTANCE.input, EVAL_PATH, -lines);
}

@@ -211,3 +209,3 @@ catch (err) {

var undo = appendEval(identifier);
var _a = service().getTypeInfo(EVAL_PATH, EVAL_INSTANCE.input.length), name = _a.name, comment = _a.comment;
var _a = service.getTypeInfo(EVAL_PATH, EVAL_INSTANCE.input.length), name = _a.name, comment = _a.comment;
undo();

@@ -214,0 +212,0 @@ repl.outputStream.write(chalk.bold(name) + "\n" + (comment ? comment + "\n" : ''));

3

dist/index.d.ts

@@ -23,3 +23,2 @@ import { BaseError } from 'make-error';

fast?: boolean | null;
lazy?: boolean | null;
cache?: boolean | null;

@@ -49,3 +48,3 @@ cacheDirectory?: string;

}
export declare function register(options?: Options): () => Register;
export declare function register(options?: Options): Register;
export declare function fileExists(fileName: string): boolean;

@@ -52,0 +51,0 @@ export declare function getDirectories(path: string): string[];

@@ -52,5 +52,3 @@ "use strict";

function getTmpDir() {
var hash = crypto.createHash('sha1')
.update(os_1.homedir(), 'utf8')
.digest('hex');
var hash = crypto.createHash('sha256').update(os_1.homedir(), 'utf8').digest('hex');
return path_1.join(os_1.tmpdir(), "ts-node-" + hash);

@@ -72,2 +70,3 @@ }

var originalJsHandler = require.extensions['.js'];
var cache = { contents: {}, versions: {}, sourceMaps: {} };
var result;

@@ -78,152 +77,141 @@ var ignore = arrify((typeof options.ignore === 'boolean' ?

['/node_modules/']).map(function (str) { return new RegExp(str); });
function load() {
var cache = { contents: {}, versions: {}, sourceMaps: {} };
sourceMapSupport.install({
environment: 'node',
retrieveSourceMap: function (fileName) {
if (cache.sourceMaps[fileName]) {
return {
url: cache.sourceMaps[fileName],
map: getFile(cache.sourceMaps[fileName])
};
}
sourceMapSupport.install({
environment: 'node',
retrieveSourceMap: function (fileName) {
if (cache.sourceMaps[fileName]) {
return {
url: cache.sourceMaps[fileName],
map: getFile(cache.sourceMaps[fileName])
};
}
});
var cwd = process.cwd();
var ts = require(compiler);
var config = readConfig(compilerOptions, project, cwd, ts);
var configDiagnostics = filterDiagnostics(config.errors, ignoreWarnings, disableWarnings);
var extensions = ['.ts', '.tsx'];
var cachedir = path_1.join(path_1.resolve(cwd, cacheDirectory), getCompilerDigest({ version: ts.version, fast: fast, ignoreWarnings: ignoreWarnings, disableWarnings: disableWarnings, config: config, compiler: compiler }));
mkdirp.sync(cachedir);
if (configDiagnostics.length) {
throw new TSError(formatDiagnostics(configDiagnostics, cwd, ts, 0));
}
if (config.options.target === undefined) {
config.options.target = ts.ScriptTarget.ES5;
});
var cwd = process.cwd();
var ts = require(compiler);
var config = readConfig(compilerOptions, project, cwd, ts);
var configDiagnostics = filterDiagnostics(config.errors, ignoreWarnings, disableWarnings);
var extensions = ['.ts', '.tsx'];
var cachedir = path_1.join(path_1.resolve(cwd, cacheDirectory), getCompilerDigest({ version: ts.version, fast: fast, ignoreWarnings: ignoreWarnings, disableWarnings: disableWarnings, config: config, compiler: compiler }));
mkdirp.sync(cachedir);
if (configDiagnostics.length) {
throw new TSError(formatDiagnostics(configDiagnostics, cwd, ts, 0));
}
if (config.options.target === undefined) {
config.options.target = ts.ScriptTarget.ES5;
}
if (config.options.module === undefined) {
config.options.module = ts.ModuleKind.CommonJS;
}
if (config.options.allowJs) {
extensions.push('.js');
}
for (var _i = 0, _a = config.fileNames; _i < _a.length; _i++) {
var fileName = _a[_i];
if (/\.d\.ts$/.test(fileName)) {
cache.versions[fileName] = 1;
}
if (config.options.module === undefined) {
config.options.module = ts.ModuleKind.CommonJS;
}
function getExtension(fileName) {
if (config.options.jsx === ts.JsxEmit.Preserve && path_1.extname(fileName) === '.tsx') {
return '.jsx';
}
if (config.options.allowJs) {
extensions.push('.js');
registerExtension('.js', ignore, service, originalJsHandler);
return '.js';
}
var getOutput = function (code, fileName, lineOffset) {
if (lineOffset === void 0) { lineOffset = 0; }
var result = ts.transpileModule(code, {
fileName: fileName,
compilerOptions: config.options,
reportDiagnostics: true
});
var diagnosticList = result.diagnostics ?
filterDiagnostics(result.diagnostics, ignoreWarnings, disableWarnings) :
[];
if (diagnosticList.length) {
throw new TSError(formatDiagnostics(diagnosticList, cwd, ts, lineOffset));
}
for (var _i = 0, _a = config.fileNames; _i < _a.length; _i++) {
var fileName = _a[_i];
if (/\.d\.ts$/.test(fileName)) {
return [result.outputText, result.sourceMapText];
};
var compile = readThrough(cachedir, shouldCache, getFile, fileExists, cache, getOutput, getExtension);
var getTypeInfo = function (fileName, position) {
throw new TypeError("No type information available under \"--fast\" mode");
};
if (!fast) {
var addVersion_1 = function (fileName) {
if (!cache.versions.hasOwnProperty(fileName)) {
cache.versions[fileName] = 1;
}
}
function getExtension(fileName) {
if (config.options.jsx === ts.JsxEmit.Preserve && path_1.extname(fileName) === '.tsx') {
return '.jsx';
}
return '.js';
}
var getOutput = function (code, fileName, lineOffset) {
};
var addCache_1 = function (code, fileName) {
cache.contents[fileName] = code;
cache.versions[fileName] += 1;
};
var serviceHost = {
getScriptFileNames: function () { return Object.keys(cache.versions); },
getScriptVersion: function (fileName) { return String(cache.versions[fileName]); },
getScriptSnapshot: function (fileName) {
if (!cache.contents.hasOwnProperty(fileName)) {
if (!fileExists(fileName)) {
return undefined;
}
cache.contents[fileName] = getFile(fileName);
}
return ts.ScriptSnapshot.fromString(cache.contents[fileName]);
},
getDirectories: getDirectories,
directoryExists: directoryExists,
getNewLine: function () { return os_1.EOL; },
getCurrentDirectory: function () { return cwd; },
getCompilationSettings: function () { return config.options; },
getDefaultLibFileName: function (options) { return ts.getDefaultLibFilePath(config.options); }
};
var service_1 = ts.createLanguageService(serviceHost);
getOutput = function (code, fileName, lineOffset) {
if (lineOffset === void 0) { lineOffset = 0; }
var result = ts.transpileModule(code, {
fileName: fileName,
compilerOptions: config.options,
reportDiagnostics: true
});
var diagnosticList = result.diagnostics ?
filterDiagnostics(result.diagnostics, ignoreWarnings, disableWarnings) :
[];
var output = service_1.getEmitOutput(fileName);
var diagnostics = service_1.getCompilerOptionsDiagnostics()
.concat(service_1.getSyntacticDiagnostics(fileName))
.concat(service_1.getSemanticDiagnostics(fileName));
var diagnosticList = filterDiagnostics(diagnostics, ignoreWarnings, disableWarnings);
if (diagnosticList.length) {
throw new TSError(formatDiagnostics(diagnosticList, cwd, ts, lineOffset));
}
return [result.outputText, result.sourceMapText];
if (output.emitSkipped) {
throw new TypeError(path_1.relative(cwd, fileName) + ": Emit skipped");
}
if (output.outputFiles.length === 0) {
throw new TypeError('Unable to require `.d.ts` file.\n' +
'This is usually the result of a faulty configuration or import. ' +
'Make sure there is a `.js`, `.json` or another executable extension and ' +
'loader (attached before `ts-node`) available alongside ' +
("`" + path_1.basename(fileName) + "`."));
}
return [output.outputFiles[1].text, output.outputFiles[0].text];
};
var compile = readThrough(cachedir, shouldCache, getFile, fileExists, cache, getOutput, getExtension);
var getTypeInfo = function (fileName, position) {
throw new TypeError("No type information available under \"--fast\" mode");
compile = readThrough(cachedir, shouldCache, getFile, fileExists, cache, function (code, fileName, lineOffset) {
addVersion_1(fileName);
addCache_1(code, fileName);
return getOutput(code, fileName, lineOffset);
}, getExtension);
getTypeInfo = function (fileName, position) {
addVersion_1(fileName);
var info = service_1.getQuickInfoAtPosition(fileName, position);
var name = ts.displayPartsToString(info ? info.displayParts : []);
var comment = ts.displayPartsToString(info ? info.documentation : []);
return { name: name, comment: comment };
};
if (!fast) {
var addVersion_1 = function (fileName) {
if (!cache.versions.hasOwnProperty(fileName)) {
cache.versions[fileName] = 1;
}
};
var addCache_1 = function (code, fileName) {
cache.contents[fileName] = code;
cache.versions[fileName] += 1;
};
var serviceHost = {
getScriptFileNames: function () { return Object.keys(cache.versions); },
getScriptVersion: function (fileName) { return String(cache.versions[fileName]); },
getScriptSnapshot: function (fileName) {
if (!cache.contents.hasOwnProperty(fileName)) {
if (!fileExists(fileName)) {
return undefined;
}
cache.contents[fileName] = getFile(fileName);
}
return ts.ScriptSnapshot.fromString(cache.contents[fileName]);
},
getDirectories: getDirectories,
directoryExists: directoryExists,
getNewLine: function () { return os_1.EOL; },
getCurrentDirectory: function () { return cwd; },
getCompilationSettings: function () { return config.options; },
getDefaultLibFileName: function (options) { return ts.getDefaultLibFilePath(config.options); }
};
var service_1 = ts.createLanguageService(serviceHost);
getOutput = function (code, fileName, lineOffset) {
if (lineOffset === void 0) { lineOffset = 0; }
var output = service_1.getEmitOutput(fileName);
var diagnostics = service_1.getCompilerOptionsDiagnostics()
.concat(service_1.getSyntacticDiagnostics(fileName))
.concat(service_1.getSemanticDiagnostics(fileName));
var diagnosticList = filterDiagnostics(diagnostics, ignoreWarnings, disableWarnings);
if (diagnosticList.length) {
throw new TSError(formatDiagnostics(diagnosticList, cwd, ts, lineOffset));
}
if (output.emitSkipped) {
throw new TypeError(path_1.relative(cwd, fileName) + ": Emit skipped");
}
if (output.outputFiles.length === 0) {
throw new TypeError('Unable to require `.d.ts` file.\n' +
'This is usually the result of a faulty configuration or import. ' +
'Make sure there is a `.js`, `.json` or another executable extension and ' +
'loader (attached before `ts-node`) available alongside ' +
("`" + path_1.basename(fileName) + "`."));
}
return [output.outputFiles[1].text, output.outputFiles[0].text];
};
compile = readThrough(cachedir, shouldCache, getFile, fileExists, cache, function (code, fileName, lineOffset) {
addVersion_1(fileName);
addCache_1(code, fileName);
return getOutput(code, fileName, lineOffset);
}, getExtension);
getTypeInfo = function (fileName, position) {
addVersion_1(fileName);
var info = service_1.getQuickInfoAtPosition(fileName, position);
var name = ts.displayPartsToString(info ? info.displayParts : []);
var comment = ts.displayPartsToString(info ? info.documentation : []);
return { name: name, comment: comment };
};
}
return { cwd: cwd, compile: compile, getTypeInfo: getTypeInfo, extensions: extensions };
}
function service() {
return result || (result = load());
}
registerExtension('.ts', ignore, service, originalJsHandler);
registerExtension('.tsx', ignore, service, originalJsHandler);
if (!options.lazy) {
service();
}
return service;
var register = { cwd: cwd, compile: compile, getTypeInfo: getTypeInfo, extensions: extensions };
extensions.forEach(function (extension) { return registerExtension(extension, ignore, register, originalJsHandler); });
return register;
}
exports.register = register;
function shouldIgnore(filename, ignore, service) {
function shouldIgnore(filename, ignore) {
var relname = normalizeSlashes(filename);
return ignore.some(function (x) { return x.test(relname); });
}
function registerExtension(ext, ignore, service, originalHandler) {
function registerExtension(ext, ignore, register, originalHandler) {
var old = require.extensions[ext] || originalHandler;
require.extensions[ext] = function (m, filename) {
if (shouldIgnore(filename, ignore, service)) {
if (shouldIgnore(filename, ignore)) {
return old(m, filename);

@@ -233,3 +221,3 @@ }

m._compile = function (code, fileName) {
return _compile.call(this, service().compile(code, fileName), fileName);
return _compile.call(this, register.compile(code, fileName), fileName);
};

@@ -306,3 +294,3 @@ return old(m, filename);

function getCacheName(sourceCode, fileName) {
return crypto.createHash('sha1')
return crypto.createHash('sha256')
.update(path_1.extname(fileName), 'utf8')

@@ -314,3 +302,3 @@ .update('\0', 'utf8')

function getCompilerDigest(opts) {
return crypto.createHash('sha1').update(JSON.stringify(opts), 'utf8').digest('hex');
return crypto.createHash('sha256').update(JSON.stringify(opts), 'utf8').digest('hex');
}

@@ -317,0 +305,0 @@ function fileExists(fileName) {

{
"name": "ts-node",
"version": "2.1.2",
"version": "3.0.0",
"preferGlobal": true,

@@ -5,0 +5,0 @@ "description": "TypeScript execution environment and REPL for node",

@@ -92,3 +92,2 @@ # TypeScript Node

* **--fast, -F** Use TypeScript's `transpileModule` mode (no type checking, but faster compilation) (also `process.env.TS_NODE_FAST`)
* **--lazy, -L** Lazily defer TypeScript initialization until first `.ts` file
* **--no-cache** Skip hitting the compiled JavaScript cache (also `process.env.TS_NODE_CACHE`)

@@ -95,0 +94,0 @@ * **--cache-directory** Configure the TypeScript cache directory (also `process.env.TS_NODE_CACHE_DIRECTORY`)

@@ -1,3 +0,1 @@

require('./').register({
lazy: true
})
require('./').register()

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc