diff --git a/README.md b/README.md index b11a961e0..365c85820 100644 --- a/README.md +++ b/README.md @@ -93,7 +93,7 @@ You can set options by passing them in before the script. ts-node --compiler ntypescript --project src --ignoreWarnings 2304 hello-world.ts ``` -* **--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`) +* **--project, -P** Path to load TypeScript configuration from (JSON file, a directory containing `tsconfig.json`, or `--no-project` to disable) (also `process.env.TS_NODE_PROJECT`/`process.env.TS_NODE_NO_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/`, `--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`) diff --git a/package.json b/package.json index c00af1be5..9fb8c6193 100644 --- a/package.json +++ b/package.json @@ -18,7 +18,7 @@ "clean": "rimraf dist", "tsc": "tsc", "build": "npm run clean && npm run tsc", - "test-spec": "mocha dist/**/*.spec.js -R spec --bail", + "test-spec": "mocha dist/**/*.spec.js -R spec", "test-cov": "istanbul cover node_modules/mocha/bin/_mocha -- \"dist/**/*.spec.js\" -R spec --bail", "test": "npm run build && npm run lint && npm run test-cov", "prepublish": "npm run build" diff --git a/src/_bin.ts b/src/_bin.ts index 29897dcb8..36a962a60 100644 --- a/src/_bin.ts +++ b/src/_bin.ts @@ -115,7 +115,7 @@ Options: -r, --require [path] Require a node module for execution -C, --compiler [name] Specify a custom TypeScript compiler -I, --ignoreWarnings [code] Ignore TypeScript warnings by diagnostic code - -P, --project [path] Path to TypeScript project (or \`false\`) + -P, --project [path] Path to TypeScript project. Defaults to CWD/tsconfig.json. --no-project to skip. -O, --compilerOptions [opts] JSON object to merge with compiler options -F, --fast Run TypeScript compilation in transpile mode --ignore [regexp], --no-ignore Set the ignore check (default: \`/node_modules/\`) diff --git a/src/index.spec.ts b/src/index.spec.ts index 567e84dc0..0f2c683d0 100644 --- a/src/index.spec.ts +++ b/src/index.spec.ts @@ -278,6 +278,15 @@ describe('ts-node', function () { return done() }) }) + + it('should ignore tsconfig.json if --no-project is passed', function (done) { + exec(`node "${EXEC_PATH}" --no-project main.ts`, { cwd: join(__dirname, '../tests/no-project') }, function (err, stdout) { + expect(err).to.equal(null) + expect(stdout).to.match(/^foobar/) + + return done() + }) + }) }) describe('register', function () { diff --git a/src/index.ts b/src/index.ts index b8d2fe8e1..fc3eff65a 100644 --- a/src/index.ts +++ b/src/index.ts @@ -95,7 +95,7 @@ const DEFAULTS = { cacheDirectory: process.env['TS_NODE_CACHE_DIRECTORY'], compiler: process.env['TS_NODE_COMPILER'], compilerOptions: parse(process.env['TS_NODE_COMPILER_OPTIONS']), - project: process.env['TS_NODE_PROJECT'], + project: process.env['TS_NODE_NO_PROJECT'] ? false : process.env['TS_NODE_PROJECT'], ignore: split(process.env['TS_NODE_IGNORE']), ignoreWarnings: split(process.env['TS_NODE_IGNORE_WARNINGS']), typeCheck: yn(process.env['TS_NODE_TYPE_CHECK']) @@ -452,7 +452,14 @@ function fixConfig (config: any, ts: TSCommon) { * Load TypeScript configuration. */ function readConfig (compilerOptions: any, project: string | boolean | undefined, cwd: string, ts: TSCommon) { - const result = loadSync(cwd, typeof project === 'string' ? project : undefined) + const result = false === project + ? { + config: { + files: [], + compilerOptions: {} + } + } + : loadSync(cwd, typeof project === 'string' ? project : undefined) // Override default configuration options. result.config.compilerOptions = Object.assign({}, result.config.compilerOptions, compilerOptions, { diff --git a/tests/no-project/main.ts b/tests/no-project/main.ts new file mode 100644 index 000000000..30647c600 --- /dev/null +++ b/tests/no-project/main.ts @@ -0,0 +1 @@ +console.log('foobar') diff --git a/tests/no-project/tsconfig.json b/tests/no-project/tsconfig.json new file mode 100644 index 000000000..23f1dee82 --- /dev/null +++ b/tests/no-project/tsconfig.json @@ -0,0 +1 @@ +this is garbage which will cause ts-node to fail if it attempts to parse it. \ No newline at end of file