Socket
Socket
Sign inDemoInstall

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 7.0.1 to 8.0.0

138

dist/bin.js
#!/usr/bin/env node
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var _a;
var path_1 = require("path");
var repl_1 = require("repl");
var util_1 = require("util");
var arrify = require("arrify");
var Module = require("module");
var minimist = require("minimist");
var arg = require("arg");
var diff_1 = require("diff");

@@ -14,74 +14,76 @@ var vm_1 = require("vm");

var index_1 = require("./index");
var argv = minimist(process.argv.slice(2), {
stopEarly: true,
string: ['eval', 'print', 'compiler', 'project', 'ignoreDiagnostics', 'require', 'cacheDirectory', 'ignore'],
boolean: ['help', 'transpileOnly', 'typeCheck', 'version', 'files', 'cache', 'pretty', 'skipProject', 'skipIgnore'],
alias: {
eval: ['e'],
print: ['p'],
require: ['r'],
help: ['h'],
version: ['v'],
typeCheck: ['type-check'],
transpileOnly: ['T', 'transpile-only'],
cacheDirectory: ['cache-directory'],
ignore: ['I'],
project: ['P'],
skipIgnore: ['skip-ignore'],
skipProject: ['skip-project'],
compiler: ['C'],
ignoreDiagnostics: ['D', 'ignore-diagnostics'],
compilerOptions: ['O', 'compiler-options']
},
default: {
cache: index_1.DEFAULTS.cache,
files: index_1.DEFAULTS.files,
pretty: index_1.DEFAULTS.pretty,
typeCheck: index_1.DEFAULTS.typeCheck,
transpileOnly: index_1.DEFAULTS.transpileOnly,
cacheDirectory: index_1.DEFAULTS.cacheDirectory,
ignore: index_1.DEFAULTS.ignore,
project: index_1.DEFAULTS.project,
skipIgnore: index_1.DEFAULTS.skipIgnore,
skipProject: index_1.DEFAULTS.skipProject,
compiler: index_1.DEFAULTS.compiler,
ignoreDiagnostics: index_1.DEFAULTS.ignoreDiagnostics
}
var args = arg({
// Node.js-like options.
'--eval': String,
'--print': Boolean,
'--require': [String],
// CLI options.
'--files': Boolean,
'--help': Boolean,
'--version': arg.COUNT,
// Project options.
'--compiler': String,
'--compiler-options': index_1.parse,
'--project': String,
'--ignore-diagnostics': [String],
'--ignore': [String],
'--transpile-only': Boolean,
'--type-check': Boolean,
'--pretty': Boolean,
'--skip-project': Boolean,
'--skip-ignore': Boolean,
// Aliases.
'-e': '--eval',
'-p': '--print',
'-r': '--require',
'-h': '--help',
'-v': '--version',
'-T': '--transpile-only',
'-I': '--ignore',
'-P': '--project',
'-C': '--compiler',
'-D': '--ignore-diagnostics',
'-O': '--compiler-options'
}, {
stopAtPositional: true
});
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 before execution\n\n -h, --help Print CLI usage\n -v, --version Print module version information\n\n -T, --transpile-only Use TypeScript's faster `transpileModule`\n --cache-directory Configure the output file cache directory\n -I, --ignore [pattern] Override the path patterns to skip compilation\n -P, --project [path] Path to TypeScript JSON project file\n -C, --compiler [name] Specify a custom TypeScript compiler\n -D, --ignoreDiagnostics [code] Ignore TypeScript warnings by diagnostic code\n -O, --compilerOptions [opts] JSON object to merge with compiler options\n\n --files Load files from `tsconfig.json` on startup\n --pretty Use pretty diagnostic formatter\n --no-cache Disable the local TypeScript Node cache\n --skip-project Skip reading `tsconfig.json`\n --skip-ignore Skip `--ignore` checks\n");
var _b = args["--help"], help = _b === void 0 ? false : _b, _c = args["--version"], version = _c === void 0 ? 0 : _c, _d = args["--files"], files = _d === void 0 ? index_1.DEFAULTS.files : _d, _e = args["--compiler"], compiler = _e === void 0 ? index_1.DEFAULTS.compiler : _e, _f = args["--compiler-options"], compilerOptions = _f === void 0 ? index_1.DEFAULTS.compilerOptions : _f, _g = args["--project"], project = _g === void 0 ? index_1.DEFAULTS.project : _g, _h = args["--ignore-diagnostics"], ignoreDiagnostics = _h === void 0 ? index_1.DEFAULTS.ignoreDiagnostics : _h, _j = args["--ignore"], ignore = _j === void 0 ? index_1.DEFAULTS.ignore : _j, _k = args["--transpile-only"], transpileOnly = _k === void 0 ? index_1.DEFAULTS.transpileOnly : _k, _l = args["--type-check"], typeCheck = _l === void 0 ? index_1.DEFAULTS.typeCheck : _l, _m = args["--pretty"], pretty = _m === void 0 ? index_1.DEFAULTS.pretty : _m, _o = args["--skip-project"], skipProject = _o === void 0 ? index_1.DEFAULTS.skipProject : _o, _p = args["--skip-ignore"], skipIgnore = _p === void 0 ? index_1.DEFAULTS.skipIgnore : _p;
if (help) {
console.log("\nUsage: ts-node [options] [ -e script | script.ts ] [arguments]\n\nOptions:\n\n -e, --eval [code] Evaluate code\n -p, --print Print result of `--eval`\n -r, --require [path] Require a node module before execution\n\n -h, --help Print CLI usage\n -v, --version Print module version information\n\n -T, --transpile-only Use TypeScript's faster `transpileModule`\n -I, --ignore [pattern] Override the path patterns to skip compilation\n -P, --project [path] Path to TypeScript JSON project file\n -C, --compiler [name] Specify a custom TypeScript compiler\n -D, --ignore-diagnostics [code] Ignore TypeScript warnings by diagnostic code\n -O, --compiler-options [opts] JSON object to merge with compiler options\n\n --files Load files from `tsconfig.json` on startup\n --pretty Use pretty diagnostic formatter\n --skip-project Skip reading `tsconfig.json`\n --skip-ignore Skip `--ignore` checks\n");
process.exit(0);
}
// Output project information.
if (version === 1) {
console.log("v" + index_1.VERSION);
process.exit(0);
}
var cwd = process.cwd();
var code = argv.eval === undefined ? argv.print : argv.eval;
var isEval = typeof argv.eval === 'string' || !!argv.print; // Minimist struggles with empty strings.
var isPrinted = argv.print !== undefined;
var code = args['--eval'];
var isPrinted = args['--print'] !== undefined;
// Register the TypeScript compiler instance.
var service = index_1.register({
files: argv.files,
pretty: argv.pretty,
typeCheck: argv.typeCheck,
transpileOnly: argv.transpileOnly,
cache: argv.cache,
cacheDirectory: argv.cacheDirectory,
ignore: argv.ignore,
project: argv.project,
skipIgnore: argv.skipIgnore,
skipProject: argv.skipProject,
compiler: argv.compiler,
ignoreDiagnostics: argv.ignoreDiagnostics,
compilerOptions: index_1.parse(argv.compilerOptions) || index_1.DEFAULTS.compilerOptions,
readFile: isEval ? readFileEval : undefined,
fileExists: isEval ? fileExistsEval : undefined
files: files,
pretty: pretty,
typeCheck: typeCheck,
transpileOnly: transpileOnly,
ignore: ignore,
project: project,
skipIgnore: skipIgnore,
skipProject: skipProject,
compiler: compiler,
ignoreDiagnostics: ignoreDiagnostics,
compilerOptions: compilerOptions,
readFile: code ? readFileEval : undefined,
fileExists: code ? fileExistsEval : undefined
});
// Output project information.
if (argv.version) {
if (version >= 2) {
console.log("ts-node v" + index_1.VERSION);
console.log("node " + process.version);
console.log("typescript v" + service.ts.version);
console.log("cache " + JSON.stringify(service.cachedir));
console.log("compiler v" + service.ts.version);
process.exit(0);
}
// Require specified modules before start-up.
Module._preloadModules(arrify(argv.require));
if (args['--require'])
Module._preloadModules(args['--require']);
/**

@@ -93,10 +95,11 @@ * Eval helpers.

var EVAL_INSTANCE = { input: '', output: '', version: 0, lines: 0 };
// Prepend `ts-node` arguments to CLI for child processes.
(_a = process.execArgv).unshift.apply(_a, [__filename].concat(process.argv.slice(2, process.argv.length - args._.length)));
process.argv = [process.argv[1]].concat(args._.length ? path_1.resolve(cwd, args._[0]) : []).concat(args._.slice(1));
// Execute the main contents (either eval, script or piped).
if (isEval) {
if (code) {
evalAndExit(code, isPrinted);
}
else {
if (argv._.length) {
process.argv = ['node'].concat(path_1.resolve(cwd, argv._[0])).concat(argv._.slice(1));
process.execArgv.unshift(__filename);
if (args._.length) {
Module.runMain();

@@ -217,7 +220,7 @@ }

function replEval(code, _context, _filename, callback) {
var err;
var err = null;
var result;
// TODO: Figure out how to handle completion here.
if (code === '.scope') {
callback();
callback(err);
return;

@@ -236,3 +239,2 @@ }

console.error(error.diagnosticText);
err = undefined;
}

@@ -239,0 +241,0 @@ }

@@ -40,6 +40,4 @@ import { BaseError } from 'make-error';

files?: boolean | null;
cache?: boolean | null;
cacheDirectory?: string;
compiler?: string;
ignore?: string | string[];
ignore?: string[];
project?: string;

@@ -49,3 +47,3 @@ skipIgnore?: boolean | null;

compilerOptions?: object;
ignoreDiagnostics?: number | string | Array<number | string>;
ignoreDiagnostics?: Array<number | string>;
readFile?: (path: string) => string | undefined;

@@ -93,3 +91,2 @@ fileExists?: (path: string) => boolean;

extensions: string[];
cachedir: string;
ts: TSCommon;

@@ -96,0 +93,0 @@ compile(code: string, fileName: string, lineOffset?: number): string;

"use strict";
var __extends = (this && this.__extends) || (function () {
var extendStatics = Object.setPrototypeOf ||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
var extendStatics = function (d, b) {
extendStatics = Object.setPrototypeOf ||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
return extendStatics(d, b);
};
return function (d, b) {

@@ -14,10 +17,6 @@ extendStatics(d, b);

var path_1 = require("path");
var fs_1 = require("fs");
var os_1 = require("os");
var sourceMapSupport = require("source-map-support");
var mkdirp = require("mkdirp");
var crypto = require("crypto");
var yn = require("yn");
var arrify = require("arrify");
var bufferFrom = require("buffer-from");
var make_error_1 = require("make-error");

@@ -51,5 +50,3 @@ var util = require("util");

files: yn(process.env['TS_NODE_FILES']),
cache: yn(process.env['TS_NODE_CACHE'], { default: true }),
pretty: yn(process.env['TS_NODE_PRETTY']),
cacheDirectory: process.env['TS_NODE_CACHE_DIRECTORY'],
compiler: process.env['TS_NODE_COMPILER'],

@@ -68,3 +65,3 @@ compilerOptions: parse(process.env['TS_NODE_COMPILER_OPTIONS']),

*/
var DEFAULT_COMPILER_OPTIONS = {
var TS_NODE_COMPILER_OPTIONS = {
sourceMap: true,

@@ -120,9 +117,2 @@ inlineSourceMap: false,

/**
* Return a default temp directory based on home directory of user.
*/
function getTmpDir() {
var hash = crypto.createHash('sha256').update(os_1.homedir(), 'utf8').digest('hex');
return path_1.join(os_1.tmpdir(), "ts-node-" + hash);
}
/**
* Register TypeScript compiler.

@@ -133,9 +123,8 @@ */

var options = Object.assign({}, exports.DEFAULTS, opts);
var cacheDirectory = options.cacheDirectory || getTmpDir();
var originalJsHandler = require.extensions['.js'];
var ignoreDiagnostics = arrify(options.ignoreDiagnostics).concat([
var ignoreDiagnostics = [
6059,
18002,
18003 // "No inputs were found in config file."
]).map(Number);
18003
].concat((options.ignoreDiagnostics || [])).map(Number);
var memoryCache = {

@@ -156,5 +145,5 @@ contents: Object.create(null),

var cwd = process.cwd();
var compilerOptions = options.compilerOptions, project = options.project, skipProject = options.skipProject;
var compiler = options.compiler || 'typescript';
var compilerOptions = options.compilerOptions, project = options.project, skipProject = options.skipProject, files = options.files;
var typeCheck = options.typeCheck === true || options.transpileOnly !== true;
var compiler = require.resolve(options.compiler || 'typescript', { paths: [cwd] });
var ts = require(compiler);

@@ -164,14 +153,5 @@ var transformers = options.transformers || undefined;

var fileExists = options.fileExists || ts.sys.fileExists;
var config = readConfig(cwd, ts, fileExists, readFile, compilerOptions, project, skipProject);
var config = readConfig(cwd, ts, fileExists, readFile, compilerOptions, project, skipProject, files);
var configDiagnosticList = filterDiagnostics(config.errors, ignoreDiagnostics);
var extensions = ['.ts', '.tsx'];
var fileNames = options.files ? config.fileNames : [];
var cachedir = path_1.join(path_1.resolve(cwd, cacheDirectory), getCompilerDigest({
version: ts.version,
options: config.options,
fileNames: fileNames,
typeCheck: typeCheck,
ignoreDiagnostics: ignoreDiagnostics,
compiler: compiler
}));
var diagnosticHost = {

@@ -199,4 +179,4 @@ getNewLine: function () { return os_1.EOL; },

// Initialize files from TypeScript into project.
for (var _i = 0, fileNames_1 = fileNames; _i < fileNames_1.length; _i++) {
var path = fileNames_1[_i];
for (var _i = 0, _a = config.fileNames; _i < _a.length; _i++) {
var path = _a[_i];
memoryCache.versions[path] = 1;

@@ -307,4 +287,10 @@ }

}
var compile = readThrough(cachedir, options.cache === true, memoryCache, getOutput, getExtension);
var register = { cwd: cwd, compile: compile, getTypeInfo: getTypeInfo, extensions: extensions, cachedir: cachedir, ts: ts };
// Create a simple TypeScript compiler proxy.
function compile(code, fileName, lineOffset) {
var _a = getOutput(code, fileName, lineOffset), value = _a[0], sourceMap = _a[1];
var output = updateOutput(value, fileName, sourceMap, getExtension);
memoryCache.outputs[fileName] = output;
return output;
}
var register = { cwd: cwd, compile: compile, getTypeInfo: getTypeInfo, extensions: extensions, ts: ts };
// Register the extensions.

@@ -365,3 +351,3 @@ extensions.forEach(function (extension) {

*/
function readConfig(cwd, ts, fileExists, readFile, compilerOptions, project, noProject) {
function readConfig(cwd, ts, fileExists, readFile, compilerOptions, project, skipProject, includeFiles) {
var config = { compilerOptions: {} };

@@ -371,3 +357,3 @@ var basePath = normalizeSlashes(cwd);

// Read project configuration when available.
if (!noProject) {
if (!skipProject) {
configFileName = project

@@ -386,46 +372,16 @@ ? normalizeSlashes(path_1.resolve(cwd, project))

}
// Remove resolution of "files".
if (!includeFiles) {
config.files = [];
config.includes = [];
}
// Override default configuration options `ts-node` requires.
config.compilerOptions = Object.assign({}, config.compilerOptions, compilerOptions, DEFAULT_COMPILER_OPTIONS);
config.compilerOptions = Object.assign({}, config.compilerOptions, compilerOptions, TS_NODE_COMPILER_OPTIONS);
return fixConfig(ts, ts.parseJsonConfigFileContent(config, ts.sys, basePath, undefined, configFileName));
}
/**
* Wrap the function with caching.
*/
function readThrough(cachedir, shouldCache, memoryCache, compile, getExtension) {
if (shouldCache === false) {
return function (code, fileName, lineOffset) {
debug('readThrough', fileName);
var _a = compile(code, fileName, lineOffset), value = _a[0], sourceMap = _a[1];
var output = updateOutput(value, fileName, sourceMap, getExtension);
memoryCache.outputs[fileName] = output;
return output;
};
}
// Make sure the cache directory exists before continuing.
mkdirp.sync(cachedir);
return function (code, fileName, lineOffset) {
debug('readThrough', fileName);
var cachePath = path_1.join(cachedir, getCacheName(code, fileName));
var extension = getExtension(fileName);
var outputPath = "" + cachePath + extension;
try {
var output_1 = fs_1.readFileSync(outputPath, 'utf8');
if (isValidCacheContent(output_1)) {
memoryCache.outputs[fileName] = output_1;
return output_1;
}
}
catch (err) { /* Ignore. */ }
var _a = compile(code, fileName, lineOffset), value = _a[0], sourceMap = _a[1];
var output = updateOutput(value, fileName, sourceMap, getExtension);
memoryCache.outputs[fileName] = output;
fs_1.writeFileSync(outputPath, output);
return output;
};
}
/**
* Update the output remapping the source map.
*/
function updateOutput(outputText, fileName, sourceMap, getExtension) {
var base64Map = bufferFrom(updateSourceMap(sourceMap, fileName), 'utf8').toString('base64');
var base64Map = Buffer.from(updateSourceMap(sourceMap, fileName), 'utf8').toString('base64');
var sourceMapContent = "data:application/json;charset=utf-8;base64," + base64Map;

@@ -446,25 +402,2 @@ var sourceMapLength = (path_1.basename(fileName) + ".map").length + (getExtension(fileName).length - path_1.extname(fileName).length);

/**
* Get the file name for the cache entry.
*/
function getCacheName(sourceCode, fileName) {
return crypto.createHash('sha256')
.update(path_1.extname(fileName), 'utf8')
.update('\x00', 'utf8')
.update(sourceCode, 'utf8')
.digest('hex');
}
/**
* Ensure the given cached content is valid by sniffing for a base64 encoded '}'
* at the end of the content, which should exist if there is a valid sourceMap present.
*/
function isValidCacheContent(contents) {
return /(?:9|0=|Q==)$/.test(contents.slice(-3));
}
/**
* Create a hash of the current configuration.
*/
function getCompilerDigest(obj) {
return crypto.createHash('sha256').update(JSON.stringify(obj), 'utf8').digest('hex');
}
/**
* Filter diagnostics.

@@ -471,0 +404,0 @@ */

@@ -10,5 +10,6 @@ "use strict";

var index_1 = require("./index");
var testDir = path_1.join(__dirname, '../tests');
var TEST_DIR = path_1.join(__dirname, '../tests');
var EXEC_PATH = path_1.join(__dirname, '../dist/bin');
var BIN_EXEC = "node \"" + EXEC_PATH + "\" --project \"" + testDir + "/tsconfig.json\"";
var PROJECT = path_1.join(TEST_DIR, semver.gte(ts.version, '2.5.0') ? 'tsconfig.json5' : 'tsconfig.json');
var BIN_EXEC = "node \"" + EXEC_PATH + "\" --project \"" + PROJECT + "\"";
var SOURCE_MAP_REGEXP = /\/\/# sourceMappingURL=data:application\/json;charset=utf\-8;base64,[\w\+]+=*$/;

@@ -31,3 +32,3 @@ describe('ts-node', function () {

child_process_1.exec("node -r ../register hello-world.ts", {
cwd: testDir
cwd: TEST_DIR
}, function (err, stdout) {

@@ -40,3 +41,3 @@ chai_1.expect(err).to.equal(null);

it('should execute cli with absolute path', function (done) {
child_process_1.exec(BIN_EXEC + " \"" + path_1.join(testDir, 'hello-world') + "\"", function (err, stdout) {
child_process_1.exec(BIN_EXEC + " \"" + path_1.join(TEST_DIR, 'hello-world') + "\"", function (err, stdout) {
chai_1.expect(err).to.equal(null);

@@ -48,3 +49,3 @@ chai_1.expect(stdout).to.equal('Hello, world!\n');

it('should print scripts', function (done) {
child_process_1.exec(BIN_EXEC + " -p \"import { example } from './tests/complex/index';example()\"", function (err, stdout) {
child_process_1.exec(BIN_EXEC + " -pe \"import { example } from './tests/complex/index';example()\"", function (err, stdout) {
chai_1.expect(err).to.equal(null);

@@ -60,3 +61,3 @@ chai_1.expect(stdout).to.equal('example\n');

'-O "{\\\"allowJs\\\":true}"',
'-p "import { main } from \'./tests/allow-js/run\';main()"'
'-pe "import { main } from \'./tests/allow-js/run\';main()"'
].join(' '), function (err, stdout) {

@@ -72,3 +73,3 @@ chai_1.expect(err).to.equal(null);

'-O "{\\\"allowJs\\\":true}"',
'-p "import { Foo2 } from \'./tests/allow-js/with-jsx\'; Foo2.sayHi()"'
'-pe "import { Foo2 } from \'./tests/allow-js/with-jsx\'; Foo2.sayHi()"'
].join(' '), function (err, stdout) {

@@ -106,3 +107,3 @@ chai_1.expect(err).to.equal(null);

it('should be able to ignore diagnostic', function (done) {
child_process_1.exec(BIN_EXEC + " --ignoreDiagnostics 2345 -e \"import * as m from './tests/module';console.log(m.example(123))\"", function (err) {
child_process_1.exec(BIN_EXEC + " --ignore-diagnostics 2345 -e \"import * as m from './tests/module';console.log(m.example(123))\"", function (err) {
if (err === null) {

@@ -130,3 +131,3 @@ return done('Command was expected to fail, but it succeeded.');

it.skip('eval should work with source maps', function (done) {
child_process_1.exec(BIN_EXEC + " -p \"import './tests/throw'\"", function (err) {
child_process_1.exec(BIN_EXEC + " -pe \"import './tests/throw'\"", function (err) {
if (err === null) {

@@ -144,3 +145,3 @@ return done('Command was expected to fail, but it succeeded.');

it('should support transpile only mode', function (done) {
child_process_1.exec(BIN_EXEC + " --transpileOnly -p \"x\"", function (err) {
child_process_1.exec(BIN_EXEC + " --transpile-only -pe \"x\"", function (err) {
if (err === null) {

@@ -170,3 +171,3 @@ return done('Command was expected to fail, but it succeeded.');

it('should pipe into an eval script', function (done) {
var cp = child_process_1.exec(BIN_EXEC + " --fast -p 'process.stdin.isTTY'", function (err, stdout) {
var cp = child_process_1.exec(BIN_EXEC + " --transpile-only -pe 'process.stdin.isTTY'", function (err, stdout) {
chai_1.expect(err).to.equal(null);

@@ -179,3 +180,3 @@ chai_1.expect(stdout).to.equal('undefined\n');

it('should support require flags', function (done) {
child_process_1.exec(BIN_EXEC + " -r ./tests/hello-world -p \"console.log('success')\"", function (err, stdout) {
child_process_1.exec(BIN_EXEC + " -r ./tests/hello-world -pe \"console.log('success')\"", function (err, stdout) {
chai_1.expect(err).to.equal(null);

@@ -206,6 +207,13 @@ chai_1.expect(stdout).to.equal('Hello, world!\nsuccess\nundefined\n');

});
it('should preserve `ts-node` context with child process', function (done) {
child_process_1.exec(BIN_EXEC + " tests/child-process", function (err, stdout) {
chai_1.expect(err).to.equal(null);
chai_1.expect(stdout).to.equal('Hello, world!\n');
return done();
});
});
});
describe('register', function () {
index_1.register({
project: path_1.join(testDir, 'tsconfig.json'),
project: PROJECT,
compilerOptions: {

@@ -212,0 +220,0 @@ jsx: 'preserve'

{
"name": "ts-node",
"version": "7.0.1",
"version": "8.0.0",
"description": "TypeScript execution environment and REPL for node.js, with source map support",

@@ -52,7 +52,5 @@ "main": "dist/index.js",

"@types/arrify": "^1.0.1",
"@types/buffer-from": "^1.1.0",
"@types/chai": "^4.0.4",
"@types/diff": "^3.2.1",
"@types/minimist": "^1.2.0",
"@types/mkdirp": "^0.5.0",
"@types/mocha": "^5.0.0",

@@ -65,2 +63,3 @@ "@types/node": "^10.0.3",

"@types/yn": "types/npm-yn#ca75f6c82940fae6a06fb41d2d37a6aa9b4ea8e9",
"arg": "^4.1.0",
"chai": "^4.0.1",

@@ -74,13 +73,13 @@ "istanbul": "^0.4.0",

"semver": "^5.1.0",
"tslint": "^5.0.0",
"tslint-config-standard": "^7.0.0",
"typescript": "^2.8.3"
"tslint": "^5.11.0",
"tslint-config-standard": "^8.0.1",
"typescript": "^3.1.5"
},
"peerDependencies": {
"typescript": ">=2.0"
},
"dependencies": {
"arrify": "^1.0.0",
"buffer-from": "^1.1.0",
"diff": "^3.1.0",
"make-error": "^1.1.1",
"minimist": "^1.2.0",
"mkdirp": "^0.5.1",
"source-map-support": "^0.5.6",

@@ -87,0 +86,0 @@ "yn": "^2.0.0"

@@ -37,3 +37,3 @@ # ![TypeScript Node](logo.svg)

# Execute, and print, code with TypeScript.
ts-node -p '"Hello, world!"'
ts-node -p -e '"Hello, world!"'

@@ -104,3 +104,3 @@ # Pipe scripts to execute with TypeScript.

**Typescript Node** loads `tsconfig.json` automatically. Use `--skip-project` to the loading `tsconfig.json`.
**Typescript Node** loads `tsconfig.json` automatically. Use `--skip-project` to skip loading the `tsconfig.json`.

@@ -128,3 +128,3 @@ **Tip**: You can use `ts-node` together with [tsconfig-paths](https://www.npmjs.com/package/tsconfig-paths) to load modules according to the `paths` section in `tsconfig.json`.

* `-T, --transpileOnly` Use TypeScript's faster `transpileModule` (`TS_NODE_TRANSPILE_ONLY`, default: `false`)
* `-T, --transpile-only` Use TypeScript's faster `transpileModule` (`TS_NODE_TRANSPILE_ONLY`, default: `false`)
* `--cacheDirectory` Configure the output file cache directory (`TS_NODE_CACHE_DIRECTORY`)

@@ -134,4 +134,4 @@ * `-I, --ignore [pattern]` Override the path patterns to skip compilation (`TS_NODE_IGNORE`, default: `/node_modules/`)

* `-C, --compiler [name]` Specify a custom TypeScript compiler (`TS_NODE_COMPILER`, default: `typescript`)
* `-D, --ignoreDiagnostics [code]` Ignore TypeScript warnings by diagnostic code (`TS_NODE_IGNORE_DIAGNOSTICS`)
* `-O, --compilerOptions [opts]` JSON object to merge with compiler options (`TS_NODE_COMPILER_OPTIONS`)
* `-D, --ignore-diagnostics [code]` Ignore TypeScript warnings by diagnostic code (`TS_NODE_IGNORE_DIAGNOSTICS`)
* `-O, --compiler-options [opts]` JSON object to merge with compiler options (`TS_NODE_COMPILER_OPTIONS`)
* `--files` Load files from `tsconfig.json` on startup (`TS_NODE_FILES`, default: `false`)

@@ -153,5 +153,7 @@ * `--pretty` Use pretty diagnostic formatter (`TS_NODE_PRETTY`, default: `false`)

For global definitions, you can use [`typeRoots`](https://www.typescriptlang.org/docs/handbook/tsconfig-json.html#types-typeroots-and-types):
For global definitions, you can use the `typeRoots` compiler option. This requires that your type definitions be structured as type packages (not loose TypeScript definition files). More details on how this works can be found in the [TypeScript Handbook](https://www.typescriptlang.org/docs/handbook/tsconfig-json.html#types-typeroots-and-types).
```json
Example `tsconfig.json`:
```
{

@@ -164,5 +166,20 @@ "compilerOptions": {

> A types package is a folder with a file called `index.d.ts` or a folder with a `package.json` that has a types field.
> -- <cite>[TypeScript Handbook](https://www.typescriptlang.org/docs/handbook/tsconfig-json.html#types-typeroots-and-types)</cite>
Example project structure:
```
<project_root>/
-- tsconfig.json
-- typings/
-- <module_name>/
-- index.d.ts
```
Example module declaration file:
```
declare module '<module_name>' {
// module definitions go here
}
```
For module definitions, you can use [`paths`](https://www.typescriptlang.org/docs/handbook/module-resolution.html#path-mapping):

@@ -169,0 +186,0 @@

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