Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Completely ignore tsconfig.json if project === false. #523

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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`)
Expand Down
2 changes: 1 addition & 1 deletion src/_bin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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/\`)
Expand Down
9 changes: 9 additions & 0 deletions src/index.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 () {
Expand Down
11 changes: 9 additions & 2 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'],
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use yn like the rest of the options.

ignore: split(process.env['TS_NODE_IGNORE']),
ignoreWarnings: split(process.env['TS_NODE_IGNORE_WARNINGS']),
typeCheck: yn(process.env['TS_NODE_TYPE_CHECK'])
Expand Down Expand Up @@ -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, {
Expand Down
1 change: 1 addition & 0 deletions tests/no-project/main.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
console.log('foobar')
1 change: 1 addition & 0 deletions tests/no-project/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
this is garbage which will cause ts-node to fail if it attempts to parse it.