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 1.2.3 to 1.3.0

15

dist/_bin.js

@@ -13,3 +13,3 @@ "use strict";

var index_1 = require('./index');
var strings = ['eval', 'print', 'compiler', 'project', 'ignoreWarnings', 'cacheDirectory'];
var strings = ['eval', 'print', 'compiler', 'project', 'ignoreWarnings', 'require', 'cacheDirectory'];
var booleans = ['help', 'fast', 'lazy', 'version', 'disableWarnings', 'cache'];

@@ -25,2 +25,3 @@ var aliases = {

compiler: ['C'],
require: ['r'],
cacheDirectory: ['cache-directory'],

@@ -83,3 +84,3 @@ ignoreWarnings: ['I', 'ignore-warnings'],

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 -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 compiler options to merge with compilation\n -L, --lazy Lazily load TypeScript compilation\n -F, --fast Run TypeScript compilation in transpile mode\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 compiler options to merge with compilation\n -L, --lazy Lazily load TypeScript compilation\n -F, --fast Run TypeScript compilation in transpile mode\n --no-cache Disable the TypeScript cache\n --cache-directory Configure the TypeScript cache directory\n");
process.exit(0);

@@ -101,3 +102,2 @@ }

getFile: isEval ? getFileEval : index_1.getFile,
getVersion: isEval ? getVersionEval : index_1.getVersion,
fileExists: isEval ? fileExistsEval : index_1.fileExists,

@@ -109,2 +109,6 @@ ignoreWarnings: arrify(argv.ignoreWarnings)

var evalFile = { input: '', output: '', version: 0 };
for (var _i = 0, _a = arrify(argv.require); _i < _a.length; _i++) {
var id = _a[_i];
Module._load(id);
}
if (isEvalScript) {

@@ -170,3 +174,3 @@ evalAndExit(code, isPrinted);

try {
output = service().compile(EVAL_PATH);
output = service().compile(evalFile.input, EVAL_PATH);
}

@@ -248,5 +252,2 @@ catch (error) {

}
function getVersionEval(fileName) {
return fileName === EVAL_PATH ? String(evalFile.version) : index_1.getVersion(fileName);
}
function fileExistsEval(fileName) {

@@ -253,0 +254,0 @@ return fileName === EVAL_PATH ? true : index_1.fileExists(fileName);

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

getFile?: (fileName: string) => string;
getVersion?: (fileName: string) => string;
fileExists?: (fileName: string) => boolean;

@@ -43,7 +42,6 @@ compilerOptions?: any;

cwd: string;
compile(fileName: string): string;
compile(code: string, fileName: string): string;
getTypeInfo(fileName: string, position: number): TypeInfo;
}
export declare function register(opts?: Options): () => Register;
export declare function getVersion(fileName: string): string;
export declare function fileExists(fileName: string): boolean;

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

@@ -18,7 +18,5 @@ "use strict";

var pkg = require('../package.json');
var oldHandlers = {};
exports.VERSION = pkg.version;
var DEFAULT_OPTIONS = {
getFile: getFile,
getVersion: getVersion,
fileExists: fileExists,

@@ -43,10 +41,10 @@ cache: process.env.TS_NODE_CACHE,

function load() {
var project = { version: 0, files: {}, versions: {}, maps: {} };
var project = { cache: {}, versions: {}, sourceMaps: {} };
sourceMapSupport.install({
environment: 'node',
retrieveSourceMap: function (fileName) {
if (project.maps[fileName]) {
if (project.sourceMaps[fileName]) {
return {
url: project.maps[fileName],
map: options.getFile(project.maps[fileName])
url: project.sourceMaps[fileName],
map: options.getFile(project.sourceMaps[fileName])
};

@@ -70,6 +68,8 @@ }

var fileName = _a[_i];
project.files[fileName] = true;
if (/\.d\.ts$/.test(fileName)) {
project.versions[fileName] = 1;
}
}
var getOutput = function (fileName, contents) {
var result = ts.transpileModule(contents, {
var getOutput = function (code, fileName) {
var result = ts.transpileModule(code, {
fileName: fileName,

@@ -92,11 +92,22 @@ compilerOptions: config.options,

if (!options.fast) {
var addVersion_1 = function (fileName) {
if (!project.versions.hasOwnProperty(fileName)) {
project.versions[fileName] = 1;
}
};
var addCache_1 = function (code, fileName) {
project.cache[fileName] = code;
project.versions[fileName] += 1;
};
var serviceHost = {
getScriptFileNames: function () { return Object.keys(project.files); },
getProjectVersion: function () { return String(project.version); },
getScriptVersion: function (fileName) { return versionFile_1(fileName); },
getScriptFileNames: function () { return Object.keys(project.versions); },
getScriptVersion: function (fileName) { return String(project.versions[fileName]); },
getScriptSnapshot: function (fileName) {
if (!options.fileExists(fileName)) {
return undefined;
if (!project.cache.hasOwnProperty(fileName)) {
if (!options.fileExists(fileName)) {
return undefined;
}
project.cache[fileName] = options.getFile(fileName);
}
return ts.ScriptSnapshot.fromString(options.getFile(fileName));
return ts.ScriptSnapshot.fromString(project.cache[fileName]);
},

@@ -111,17 +122,3 @@ getDirectories: getDirectories,

var service_1 = ts.createLanguageService(serviceHost);
var addAndVersionFile_1 = function (fileName) {
project.files[fileName] = true;
var currentVersion = project.versions[fileName];
var newVersion = versionFile_1(fileName);
if (currentVersion !== newVersion) {
project.version++;
}
return newVersion;
};
var versionFile_1 = function (fileName) {
var version = options.getVersion(fileName);
project.versions[fileName] = version;
return version;
};
getOutput = function (fileName) {
getOutput = function (code, fileName) {
var output = service_1.getEmitOutput(fileName);

@@ -140,8 +137,9 @@ var diagnostics = service_1.getCompilerOptionsDiagnostics()

};
compile = readThrough(cachedir, options, project, function (fileName, contents) {
addAndVersionFile_1(fileName);
return getOutput(fileName, contents);
compile = readThrough(cachedir, options, project, function (code, fileName) {
addVersion_1(fileName);
addCache_1(code, fileName);
return getOutput(code, fileName);
});
getTypeInfo = function (fileName, position) {
addAndVersionFile_1(fileName);
addVersion_1(fileName);
var info = service_1.getQuickInfoAtPosition(fileName, position);

@@ -158,5 +156,2 @@ var name = ts.displayPartsToString(info ? info.displayParts : []);

}
function loader(m, fileName) {
return m._compile(service().compile(fileName), fileName);
}
function shouldIgnore(filename) {

@@ -166,4 +161,3 @@ return path_1.relative(service().cwd, filename).split(path_1.sep).indexOf('node_modules') > -1;

function registerExtension(ext) {
var old = oldHandlers[ext] || oldHandlers['.js'] || require.extensions['.js'];
oldHandlers[ext] = require.extensions[ext];
var old = require.extensions[ext] || require.extensions['.js'];
require.extensions[ext] = function (m, filename) {

@@ -173,3 +167,7 @@ if (shouldIgnore(filename)) {

}
return loader(m, filename);
var _compile = m._compile;
m._compile = function (code, fileName) {
return _compile.call(this, service().compile(code, fileName), fileName);
};
return old(m, filename);
};

@@ -209,8 +207,7 @@ }

if (options.cache === false) {
return function (fileName) {
var contents = options.getFile(fileName);
var cachePath = path_1.join(cachedir, getCacheName(contents, fileName));
return function (code, fileName) {
var cachePath = path_1.join(cachedir, getCacheName(code, fileName));
var sourceMapPath = cachePath + ".js.map";
var out = compile(fileName, contents);
project.maps[fileName] = sourceMapPath;
var out = compile(code, fileName);
project.sourceMaps[fileName] = sourceMapPath;
var output = updateOutput(out[0], fileName, sourceMapPath);

@@ -222,12 +219,11 @@ var sourceMap = updateSourceMap(out[1], fileName);

}
return function (fileName) {
var contents = options.getFile(fileName);
var cachePath = path_1.join(cachedir, getCacheName(contents, fileName));
return function (code, fileName) {
var cachePath = path_1.join(cachedir, getCacheName(code, fileName));
var outputPath = cachePath + ".js";
var sourceMapPath = cachePath + ".js.map";
project.maps[fileName] = sourceMapPath;
project.sourceMaps[fileName] = sourceMapPath;
if (options.fileExists(outputPath)) {
return options.getFile(outputPath);
}
var out = compile(fileName, contents);
var out = compile(code, fileName);
var output = updateOutput(out[0], fileName, sourceMapPath);

@@ -268,6 +264,2 @@ var sourceMap = updateSourceMap(out[1], fileName);

}
function getVersion(fileName) {
return String(fs_1.statSync(fileName).mtime.getTime());
}
exports.getVersion = getVersion;
function fileExists(fileName) {

@@ -274,0 +266,0 @@ try {

@@ -120,2 +120,9 @@ "use strict";

});
it('should support require flags', function (done) {
child_process_1.exec(BIN_EXEC + " -r ./tests/hello-world -p \"console.log('success')\"", function (err, stdout) {
chai_1.expect(err).to.not.exist;
chai_1.expect(stdout).to.equal('Hello, world!\nsuccess\nundefined\n');
return done();
});
});
});

@@ -122,0 +129,0 @@ describe('register', function () {

{
"name": "ts-node",
"version": "1.2.3",
"version": "1.3.0",
"preferGlobal": true,

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

Sorry, the diff of this file is not supported yet

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