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 3.3.0 to 4.0.0

48

dist/_bin.js

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

var minimist = require("minimist");
var chalk = require("chalk");
var chalk_1 = require("chalk");
var diff_1 = require("diff");

@@ -15,6 +15,5 @@ var vm_1 = require("vm");

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

@@ -26,5 +25,5 @@ eval: ['e'],

require: ['r'],
typeCheck: ['type-check'],
cacheDirectory: ['cache-directory'],
ignoreWarnings: ['I', 'ignore-warnings'],
disableWarnings: ['D', 'disable-warnings'],
compilerOptions: ['O', 'compiler-options']

@@ -76,17 +75,16 @@ };

cache: null,
fast: null,
disableWarnings: null
typeCheck: null
}
});
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 -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 -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);
}
var cwd = process.cwd();
var code = argv.eval == null ? argv.print : argv.eval;
var code = argv.eval === undefined ? argv.print : argv.eval;
var isEvalScript = typeof argv.eval === 'string' || !!argv.print;
var isEval = isEvalScript || stop === process.argv.length;
var isPrinted = argv.print != null;
var isPrinted = argv.print !== undefined;
var service = index_1.register({
fast: argv.fast,
typeCheck: argv.typeCheck,
cache: argv.cache,

@@ -98,3 +96,2 @@ cacheDirectory: argv.cacheDirectory,

ignoreWarnings: argv.ignoreWarnings,
disableWarnings: argv.disableWarnings,
compilerOptions: index_1.parse(argv.compilerOptions),

@@ -160,3 +157,2 @@ getFile: isEval ? getFileEval : index_1.getFile,

}
process.exit(0);
}

@@ -182,12 +178,10 @@ function _eval(input, context) {

}
var result;
for (var _i = 0, changes_1 = changes; _i < changes_1.length; _i++) {
var change = changes_1[_i];
if (change.added) {
var script = new vm_1.Script(change.value, EVAL_FILENAME);
result = script.runInNewContext(context);
}
}
return result;
return changes.reduce(function (result, change) {
return change.added ? exec(change.value, EVAL_FILENAME, context) : result;
}, undefined);
}
function exec(code, filename, context) {
var script = new vm_1.Script(code, { filename: filename });
return script.runInNewContext(context);
}
function startRepl() {

@@ -201,4 +195,8 @@ var repl = repl_1.start({

});
appendEval('exports = module.exports\n');
var reset = appendEval('');
var resetEval = appendEval('');
function reset() {
resetEval();
exec('exports = module.exports', EVAL_FILENAME, repl.context);
}
reset();
repl.on('reset', reset);

@@ -215,3 +213,3 @@ repl.defineCommand('type', {

undo();
repl.outputStream.write(chalk.bold(name) + "\n" + (comment ? comment + "\n" : ''));
repl.outputStream.write(chalk_1.default.bold(name) + "\n" + (comment ? comment + "\n" : ''));
repl.displayPrompt();

@@ -233,3 +231,3 @@ }

if (error instanceof index_1.TSError) {
if (typeof repl_1.Recoverable === 'function' && isRecoverable(error)) {
if (repl_1.Recoverable && isRecoverable(error)) {
err = new repl_1.Recoverable(error);

@@ -236,0 +234,0 @@ }

@@ -8,2 +8,3 @@ #!/usr/bin/env node

var argv = process.argv.slice(2);
var signals = ['SIGINT', 'SIGTERM', 'SIGWINCH'];
v8flags(function (err, v8flags) {

@@ -19,2 +20,3 @@ if (err) {

'debug',
'inspect',
'--debug',

@@ -31,3 +33,5 @@ '--debug-brk',

'--perf-basic-prof',
'--preserve-symlinks'
'--preserve-symlinks',
'--expose-gc',
'--expose-http2'
]);

@@ -37,9 +41,3 @@ for (var i = 0; i < argv.length; i++) {

var flag = arg.split('=', 1)[0];
if (flag === '-d') {
nodeArgs.push('--debug');
}
else if (flag === '-gc') {
nodeArgs.push('--expose-gc');
}
else if (knownFlags.indexOf(flag) > -1) {
if (knownFlags.indexOf(flag) > -1) {
nodeArgs.push(arg);

@@ -55,14 +53,17 @@ }

}
var proc = child_process_1.spawn(process.execPath, nodeArgs.concat(path_1.join(__dirname, '_bin.js'), scriptArgs), { stdio: 'inherit' });
proc.on('exit', function (code, signal) {
process.on('exit', function () {
if (signal) {
process.kill(process.pid, signal);
}
else {
process.exit(code);
}
});
var proc = child_process_1.spawn(process.execPath, nodeArgs.concat(path_1.join(__dirname, '_bin.js'), scriptArgs), {
detached: true,
stdio: 'inherit'
});
signals.forEach(function (signal) { return process.on(signal, function () { return proc.kill(signal); }); });
proc.on('close', function (code, signal) {
if (signal) {
process.kill(process.pid, signal);
}
else {
process.exit(code);
}
});
process.on('exit', function () { return proc.kill(); });
});
//# sourceMappingURL=bin.js.map

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

export interface Options {
fast?: boolean | null;
cache?: boolean | null;
typeCheck?: boolean;
cache?: boolean;
cacheDirectory?: string;

@@ -30,6 +30,6 @@ compiler?: string;

ignoreWarnings?: number | string | Array<number | string>;
disableWarnings?: boolean | null;
getFile?: (path: string) => string;
fileExists?: (path: string) => boolean;
compilerOptions?: any;
transformers?: TS.CustomTransformers;
}

@@ -43,2 +43,7 @@ export interface TypeInfo {

export declare function normalizeSlashes(value: string): string;
export declare class TSError extends BaseError {
diagnostics: TSDiagnostic[];
name: string;
constructor(diagnostics: TSDiagnostic[]);
}
export interface Register {

@@ -61,7 +66,2 @@ cwd: string;

export declare function formatDiagnostic(diagnostic: TS.Diagnostic, cwd: string, ts: TSCommon, lineOffset: number): TSDiagnostic;
export declare class TSError extends BaseError {
diagnostics: TSDiagnostic[];
name: string;
constructor(diagnostics: TSDiagnostic[]);
}
export declare function printError(error: TSError): string;

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

var sourceMapSupport = require("source-map-support");
var chalk = require("chalk");
var chalk_1 = require("chalk");
var mkdirp = require("mkdirp");

@@ -42,3 +42,2 @@ var crypto = require("crypto");

cacheDirectory: process.env['TS_NODE_CACHE_DIRECTORY'],
disableWarnings: yn(process.env['TS_NODE_DISABLE_WARNINGS']),
compiler: process.env['TS_NODE_COMPILER'],

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

ignoreWarnings: split(process.env['TS_NODE_IGNORE_WARNINGS']),
fast: yn(process.env['TS_NODE_FAST'])
typeCheck: yn(process.env['TS_NODE_TYPE_CHECK'])
};

@@ -64,2 +63,13 @@ function split(value) {

exports.normalizeSlashes = normalizeSlashes;
var TSError = (function (_super) {
__extends(TSError, _super);
function TSError(diagnostics) {
var _this = _super.call(this, "\u2A2F Unable to compile TypeScript\n" + diagnostics.map(function (x) { return x.message; }).join('\n')) || this;
_this.diagnostics = diagnostics;
_this.name = 'TSError';
return _this;
}
return TSError;
}(make_error_1.BaseError));
exports.TSError = TSError;
function getTmpDir() {

@@ -74,8 +84,7 @@ var hash = crypto.createHash('sha256').update(os_1.homedir(), 'utf8').digest('hex');

var ignoreWarnings = arrify(options.ignoreWarnings || DEFAULTS.ignoreWarnings || []).concat(emptyFileListWarnings).map(Number);
var disableWarnings = !!(options.disableWarnings == null ? DEFAULTS.disableWarnings : options.disableWarnings);
var getFile = options.getFile || DEFAULTS.getFile;
var fileExists = options.fileExists || DEFAULTS.fileExists;
var shouldCache = !!(options.cache == null ? DEFAULTS.cache : options.cache);
var fast = !!(options.fast == null ? DEFAULTS.fast : options.fast);
var project = options.project || DEFAULTS.project;
var shouldCache = !!(options.cache === undefined ? DEFAULTS.cache : options.cache);
var typeCheck = !!(options.typeCheck === undefined ? DEFAULTS.typeCheck : options.typeCheck);
var project = options.project === undefined ? DEFAULTS.project : options.project;
var cacheDirectory = options.cacheDirectory || DEFAULTS.cacheDirectory || getTmpDir();

@@ -102,5 +111,5 @@ var compilerOptions = Object.assign({}, DEFAULTS.compilerOptions, options.compilerOptions);

var config = readConfig(compilerOptions, project, cwd, ts);
var configDiagnostics = filterDiagnostics(config.errors, ignoreWarnings, disableWarnings);
var configDiagnostics = filterDiagnostics(config.errors, ignoreWarnings);
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 }));
var cachedir = path_1.join(path_1.resolve(cwd, cacheDirectory), getCompilerDigest({ version: ts.version, typeCheck: typeCheck, ignoreWarnings: ignoreWarnings, config: config, compiler: compiler }));
if (configDiagnostics.length) {

@@ -111,11 +120,11 @@ throw new TSError(formatDiagnostics(configDiagnostics, cwd, ts, 0));

extensions.push('.js');
extensions.push('.jsx');
}
for (var _i = 0, _a = config.fileNames; _i < _a.length; _i++) {
var fileName = _a[_i];
if (/\.d\.ts$/.test(fileName)) {
cache.versions[fileName] = 1;
}
cache.versions[fileName] = 1;
}
function getExtension(fileName) {
if (config.options.jsx === ts.JsxEmit.Preserve && path_1.extname(fileName) === '.tsx') {
var ext = path_1.extname(fileName);
if (config.options.jsx === ts.JsxEmit.Preserve && (ext === '.tsx' || ext === '.jsx')) {
return '.jsx';

@@ -130,6 +139,7 @@ }

compilerOptions: config.options,
reportDiagnostics: true
reportDiagnostics: true,
transformers: options.transformers
});
var diagnosticList = result.diagnostics ?
filterDiagnostics(result.diagnostics, ignoreWarnings, disableWarnings) :
filterDiagnostics(result.diagnostics, ignoreWarnings) :
[];

@@ -143,12 +153,17 @@ if (diagnosticList.length) {

var getTypeInfo = function (_code, _fileName, _position) {
throw new TypeError("No type information available under \"--fast\" mode");
throw new TypeError("Type information is unavailable without \"--type-check\"");
};
if (!fast) {
if (typeCheck) {
var setCache_1 = function (code, fileName) {
cache.contents[fileName] = code;
cache.versions[fileName] = (cache.versions[fileName] + 1) || 1;
if (cache.contents[fileName] !== code) {
cache.contents[fileName] = code;
cache.versions[fileName] = (cache.versions[fileName] || 0) + 1;
}
};
var serviceHost = {
getScriptFileNames: function () { return Object.keys(cache.versions); },
getScriptVersion: function (fileName) { return String(cache.versions[fileName]); },
getScriptVersion: function (fileName) {
var version = cache.versions[fileName];
return version === undefined ? undefined : String(version);
},
getScriptSnapshot: function (fileName) {

@@ -171,3 +186,4 @@ if (!cache.contents[fileName]) {

getCompilationSettings: function () { return config.options; },
getDefaultLibFileName: function () { return ts.getDefaultLibFilePath(config.options); }
getDefaultLibFileName: function () { return ts.getDefaultLibFilePath(config.options); },
getCustomTransformers: function () { return options.transformers; }
};

@@ -181,3 +197,3 @@ var service_1 = ts.createLanguageService(serviceHost);

.concat(service_1.getSemanticDiagnostics(fileName));
var diagnosticList = filterDiagnostics(diagnostics, ignoreWarnings, disableWarnings);
var diagnosticList = filterDiagnostics(diagnostics, ignoreWarnings);
if (diagnosticList.length) {

@@ -338,6 +354,3 @@ throw new TSError(formatDiagnostics(diagnosticList, cwd, ts, lineOffset));

exports.getFile = getFile;
function filterDiagnostics(diagnostics, ignore, disable) {
if (disable) {
return [];
}
function filterDiagnostics(diagnostics, ignore) {
return diagnostics.filter(function (x) { return ignore.indexOf(x.code) === -1; });

@@ -364,18 +377,7 @@ }

exports.formatDiagnostic = formatDiagnostic;
var TSError = (function (_super) {
__extends(TSError, _super);
function TSError(diagnostics) {
var _this = _super.call(this, "\u2A2F Unable to compile TypeScript\n" + diagnostics.map(function (x) { return x.message; }).join('\n')) || this;
_this.diagnostics = diagnostics;
_this.name = 'TSError';
return _this;
}
return TSError;
}(make_error_1.BaseError));
exports.TSError = TSError;
function printError(error) {
var title = chalk.red('⨯') + " Unable to compile TypeScript";
return chalk.bold(title) + "\n" + error.diagnostics.map(function (x) { return x.message; }).join('\n');
var title = chalk_1.default.red('⨯') + " Unable to compile TypeScript";
return chalk_1.default.bold(title) + "\n" + error.diagnostics.map(function (x) { return x.message; }).join('\n');
}
exports.printError = printError;
//# sourceMappingURL=index.js.map

@@ -20,2 +20,25 @@ "use strict";

describe('cli', function () {
this.slow(1000);
it('should forward signals to the child process', function (done) {
this.slow(5000);
var proc = child_process_1.spawn('node', [
EXEC_PATH,
'--project',
testDir,
'tests/signals'
], {
shell: '/bin/bash'
});
var stdout = '';
proc.stdout.on('data', function (data) { return stdout += data.toString(); });
var stderr = '';
proc.stderr.on('data', function (data) { return stderr += data.toString(); });
proc.on('exit', function (code) {
chai_1.expect(stderr).to.equal('');
chai_1.expect(stdout).to.equal('exited fine');
chai_1.expect(code).to.equal(0);
return done();
});
setTimeout(function () { return proc.kill('SIGINT'); }, 2000);
});
it('should execute cli', function (done) {

@@ -28,2 +51,11 @@ child_process_1.exec(BIN_EXEC + " tests/hello-world", function (err, stdout) {

});
it('should register via cli', function (done) {
child_process_1.exec("node -r ../register hello-world.ts", {
cwd: testDir
}, function (err, stdout) {
chai_1.expect(err).to.equal(null);
chai_1.expect(stdout).to.equal('Hello, world!\n');
return done();
});
});
it('should execute cli with absolute path', function (done) {

@@ -55,2 +87,13 @@ child_process_1.exec(BIN_EXEC + " \"" + path_1.join(testDir, 'hello-world') + "\"", function (err, stdout) {

});
it('should include jsx when `allow-js` true', function (done) {
child_process_1.exec([
BIN_EXEC,
'-O "{\\\"allowJs\\\":true}"',
'-p "import { Foo2 } from \'./tests/allow-js/with-jsx\'; Foo2.sayHi()"'
].join(' '), function (err, stdout) {
chai_1.expect(err).to.equal(null);
chai_1.expect(stdout).to.equal('hello world\n');
return done();
});
});
}

@@ -65,3 +108,6 @@ it('should eval code', function (done) {

it('should throw errors', function (done) {
child_process_1.exec(BIN_EXEC + " -e \"import * as m from './tests/module';console.log(m.example(123))\"", function (err) {
child_process_1.exec(BIN_EXEC + " --type-check -e \"import * as m from './tests/module';console.log(m.example(123))\"", function (err) {
if (err === null) {
return done('Command was expected to fail, but it succeeded.');
}
chai_1.expect(err.message).to.match(new RegExp('\\[eval\\]\\.ts \\(1,59\\): Argument of type \'(?:number|123)\' ' +

@@ -73,3 +119,6 @@ 'is not assignable to parameter of type \'string\'\\. \\(2345\\)'));

it('should be able to ignore errors', function (done) {
child_process_1.exec(BIN_EXEC + " --ignoreWarnings 2345 -e \"import * as m from './tests/module';console.log(m.example(123))\"", function (err) {
child_process_1.exec(BIN_EXEC + " --type-check --ignoreWarnings 2345 -e \"import * as m from './tests/module';console.log(m.example(123))\"", function (err) {
if (err === null) {
return done('Command was expected to fail, but it succeeded.');
}
chai_1.expect(err.message).to.match(/TypeError: (?:(?:undefined|foo\.toUpperCase) is not a function|.*has no method \'toUpperCase\')/);

@@ -79,16 +128,7 @@ return done();

});
it('should be able to disable warnings from environment', function (done) {
child_process_1.exec(BIN_EXEC + " tests/compiler-error", {
env: {
PATH: process.env.PATH,
HOME: process.env.HOME,
TS_NODE_DISABLE_WARNINGS: true
it('should work with source maps', function (done) {
child_process_1.exec(BIN_EXEC + " --type-check tests/throw", function (err) {
if (err === null) {
return done('Command was expected to fail, but it succeeded.');
}
}, function (err) {
chai_1.expect(err.message).to.match(/TypeError: (?:(?:undefined|str\.toUpperCase) is not a function|.*has no method \'toUpperCase\')/);
return done();
});
});
it('should work with source maps', function (done) {
child_process_1.exec(BIN_EXEC + " tests/throw", function (err) {
chai_1.expect(err.message).to.contain([

@@ -103,9 +143,11 @@ path_1.join(__dirname, '../tests/throw.ts') + ":3",

});
it('eval should work with source maps', function (done) {
child_process_1.exec(BIN_EXEC + " -p \"import './tests/throw'\"", function (err) {
it.skip('eval should work with source maps', function (done) {
child_process_1.exec(BIN_EXEC + " --type-check -p \"import './tests/throw'\"", function (err) {
if (err === null) {
return done('Command was expected to fail, but it succeeded.');
}
chai_1.expect(err.message).to.contain([
path_1.join(__dirname, '../tests/throw.ts') + ":3",
' bar () { throw new Error(\'this is a demo\') }',
' ^',
'Error: this is a demo'
' ^'
].join('\n'));

@@ -115,4 +157,7 @@ return done();

});
it('should ignore all warnings', function (done) {
child_process_1.exec(BIN_EXEC + " -D -p \"x\"", function (err) {
it('should use transpile mode by default', function (done) {
child_process_1.exec(BIN_EXEC + " -p \"x\"", function (err) {
if (err === null) {
return done('Command was expected to fail, but it succeeded.');
}
chai_1.expect(err.message).to.contain('ReferenceError: x is not defined');

@@ -119,0 +164,0 @@ return done();

{
"name": "ts-node",
"version": "3.3.0",
"version": "4.0.0",
"description": "TypeScript execution environment and REPL for node",
"main": "dist/index.js",
"types": "dist/index.d.ts",
"bin": {

@@ -12,3 +13,2 @@ "ts-node": "dist/bin.js",

"dist/",
"typings.js",
"register.js",

@@ -18,3 +18,3 @@ "LICENSE"

"scripts": {
"lint": "tslint \"src/**/*.ts\"",
"lint": "tslint \"src/**/*.ts\" --project tsconfig.json --type-check",
"clean": "rimraf dist",

@@ -26,3 +26,3 @@ "tsc": "tsc",

"test": "npm run build && npm run lint && npm run test-cov",
"prepublish": "typings install && npm run build"
"prepublish": "npm run build"
},

@@ -55,19 +55,30 @@ "engines": {

"devDependencies": {
"@types/react": "^15.0.38",
"@types/chai": "^4.0.4",
"@types/mocha": "^2.2.42",
"@types/proxyquire": "^1.3.28",
"@types/react": "^16.0.2",
"@types/semver": "^5.3.34",
"chai": "^4.0.1",
"istanbul": "^0.4.0",
"mocha": "^3.0.0",
"mocha": "^4.0.0",
"ntypescript": "^1.201507091536.1",
"proxyquire": "^1.7.2",
"react": "^15.6.1",
"react": "^16.0.0",
"rimraf": "^2.5.4",
"semver": "^5.1.0",
"tslint": "^5.0.0",
"tslint-config-standard": "^6.0.1",
"typescript": "^2.4.1",
"typings": "^2.0.0"
"tslint-config-standard": "^7.0.0",
"typescript": "^2.4.1"
},
"dependencies": {
"@types/arrify": "^1.0.1",
"@types/diff": "^3.2.1",
"@types/minimist": "^1.2.0",
"@types/mkdirp": "^0.5.0",
"@types/node": "^8.0.27",
"@types/source-map-support": "^0.4.0",
"@types/v8flags": "types/npm-v8flags#de224ae1cd5fd7dbb4e7158a6cc7a29e5315930d",
"@types/yn": "types/npm-yn#ca75f6c82940fae6a06fb41d2d37a6aa9b4ea8e9",
"arrify": "^1.0.0",
"chalk": "^2.0.0",
"chalk": "^2.3.0",
"diff": "^3.1.0",

@@ -77,4 +88,4 @@ "make-error": "^1.1.1",

"mkdirp": "^0.5.1",
"source-map-support": "^0.4.0",
"tsconfig": "^6.0.0",
"source-map-support": "^0.5.0",
"tsconfig": "^7.0.0",
"v8flags": "^3.0.0",

@@ -81,0 +92,0 @@ "yn": "^2.0.0"

@@ -49,8 +49,14 @@ # TypeScript Node

### Programmatic
You can require `ts-node` and register the loader for future requires by using `require('ts-node').register({ /* options */ })`. You can also use the shortcut files `node -r ts-node/register` or `node -r ts-node/register/type-check` depending on your preferences.
### Mocha
```sh
mocha --compilers ts:ts-node/register,tsx:ts-node/register [...args]
mocha --require ts-node/register --watch-extensions ts,tsx "test/**/*.{ts,tsx}" [...args]
```
**Note:** `--watch-extensions` is only used in `--watch` mode.
### Tape

@@ -77,3 +83,3 @@

**Typescript Node** uses `tsconfig.json` automatically, use `-n` to skip loading `tsconfig.json`.
**Typescript Node** uses `tsconfig.json` automatically, use `--no-project` to skip loading `tsconfig.json`.

@@ -92,28 +98,13 @@ **NOTE**: 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`.

* **--project, -P** Path to load TypeScript configuration from (JSON file, a directory containing `tsconfig.json`, or `false` to disable) (also `process.env.TS_NODE_PROJECT`)
* **--project, -P** Path to load TypeScript configuration from (JSON file, a directory containing `tsconfig.json`, or `--no-project`/`false` to disable) (also `process.env.TS_NODE_PROJECT`)
* **--compiler, -C** Use a custom, require-able TypeScript compiler compatible with `typescript@>=1.5.0-alpha` (also `process.env.TS_NODE_COMPILER`)
* **--ignore** Specify an array of regular expression strings for `ts-node` to skip compiling as TypeScript (defaults to `/node_modules/`, `false` to disable) (also `process.env.TS_NODE_IGNORE`)
* **--ignore** Specify an array of regular expression strings for `ts-node` to skip compiling as TypeScript (defaults to `/node_modules/`, `--no-ignore`/`false` to disable) (also `process.env.TS_NODE_IGNORE`)
* **--ignoreWarnings, -I** Set an array of TypeScript diagnostic codes to ignore (also `process.env.TS_NODE_IGNORE_WARNINGS`)
* **--disableWarnings, -D** Ignore all TypeScript errors (also `process.env.TS_NODE_DISABLE_WARNINGS`)
* **--compilerOptions, -O** Set compiler options using JSON (E.g. `--compilerOptions '{"target":"es6"}'`) (also `process.env.TS_NODE_COMPILER_OPTIONS`)
* **--fast, -F** Use TypeScript's `transpileModule` mode (no type checking, but faster compilation) (also `process.env.TS_NODE_FAST`)
* **--type-check** Use TypeScript with type checking (also `process.env.TS_NODE_TYPE_CHECK`)
* **--no-cache** Skip hitting the compiled JavaScript cache (also `process.env.TS_NODE_CACHE`)
* **--cache-directory** Configure the TypeScript cache directory (also `process.env.TS_NODE_CACHE_DIRECTORY`)
## Programmatic Usage
Additionally, the `transformers` option may be provided when programmatically registering `ts-node` to specify custom TypeScript transformers.
```js
require('ts-node').register({ /* options */ })
// Or using the shortcut file.
require('ts-node/register')
```
This will register the TypeScript compiler for "on the fly" compilation support of `.ts` and `.tsx` files during the run
of the script. From here you can use `require` to bring in modules from TypeScript files:
```js
var someModule = require('path_to_a_typescript_file');
```
## License

@@ -120,0 +111,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

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