Skip to content

Commit 453de96

Browse files
author
Sam Szuflita
committed
Support rewriteTsconfig flag in tsconfig.json
The rewriteTsconfig flag enables users to prevent Atom-Typescript from rewriting their tsconfig.json. The flag defaults to true, so users who upgrade won't observe any different behavior. The FAQ and tsconfig docs have been modified to reflect rewriteTsconfig. This resolves TypeStrong#703.
1 parent 273a74a commit 453de96

File tree

4 files changed

+36
-6
lines changed

4 files changed

+36
-6
lines changed

dist/main/tsconfig/tsconfig.js

+5-3
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,8 @@ function getDefaultInMemoryProject(srcFile) {
174174
formatCodeOptions: formatting.defaultFormatCodeOptions(),
175175
compileOnSave: true,
176176
buildOnSave: false,
177-
scripts: {}
177+
scripts: {},
178+
atom: { rewriteTsconfig: true },
178179
};
179180
return {
180181
projectFileDirectory: dir,
@@ -210,7 +211,7 @@ function getProjectSync(pathOrSrcFile) {
210211
}
211212
if (projectSpec.filesGlob) {
212213
var prettyJSONProjectSpec = prettyJSON(projectSpec, detectIndent(projectFileTextContent).indent);
213-
if (prettyJSONProjectSpec !== projectFileTextContent) {
214+
if (prettyJSONProjectSpec !== projectFileTextContent && projectSpec.atom.rewriteTsconfig) {
214215
fs.writeFileSync(projectFile, prettyJSONProjectSpec);
215216
}
216217
}
@@ -240,7 +241,8 @@ function getProjectSync(pathOrSrcFile) {
240241
typings: [],
241242
externalTranspiler: projectSpec.externalTranspiler == undefined ? undefined : projectSpec.externalTranspiler,
242243
scripts: projectSpec.scripts || {},
243-
buildOnSave: !!projectSpec.buildOnSave
244+
buildOnSave: !!projectSpec.buildOnSave,
245+
atom: { rewriteTsconfig: true }
244246
};
245247
var validationResult = validator.validate(projectSpec.compilerOptions);
246248
if (validationResult.errorMessage) {

docs/faq.md

+4
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,10 @@
33
## I keep getting changes to tsconfig.json
44
This is probably because of us keeping `files` updated with the `filesGlob` option. The reason why we do this is because the official `tsconfig.json` spec does not support `filesGlob`. Therefore we keep `files` in sync with the `filesGlob` so that your team mates can use whatever editor they prefer (sublime text, visual studio etc.).
55

6+
You can now disable this behavior by setting the `rewriteTsconfig` flag to `false` in your project's `tsconfig.json` under the `atom` key.
7+
8+
[Further Details](https://github.com/TypeStrong/atom-typescript/blob/master/docs/tsconfig.md#atom)
9+
610
## For really large projects atom-typescript gets slow
711
If you have `tsconfig.json` in a folder that contains `node_modules`, atom-typescript might become slow (due to extensive file listing). Two possible fixes:
812
* Move `tsconfig.json` into a sub folder e.g. `src`

docs/tsconfig.md

+20
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ i.e. an empty JSON file at the *root* of your project :heart: This will be suffi
2020
* [`compileOnSave`](https://github.com/TypeStrong/atom-typescript/blob/master/docs/tsconfig.md#compileonsave) : Should AtomTS compile on save
2121
* [`buildOnSave`](https://github.com/TypeStrong/atom-typescript/blob/master/docs/tsconfig.md#buildonsave) : Should AtomTS build on save
2222
* [`scripts`](https://github.com/TypeStrong/atom-typescript/blob/master/docs/tsconfig.md#scripts) : Sometimes its useful to have post build scripts
23+
* [`atom`](https://github.com/TypeStrong/atom-typescript/blob/master/docs/tsconfig.md#rewriteTsconfig) : Configuration specific to Atom. Currently
24+
only contains `rewriteTsconfig` which prevents Atom from rewriting a project's `tsconfig.json`.
2325

2426

2527
## Examples
@@ -115,5 +117,23 @@ Build means *compile all files*. Useful if for some reason you are using `--out`
115117
}
116118
```
117119

120+
### atom
121+
Configuration options specific to Atom.
122+
123+
124+
**rewriteTsconfig**
125+
126+
Atom-Typescript constantly resolves the `filesGlob` listed in your `tsconfig.json` to ensure that the glob is in sync
127+
with your project. If your project doesn't require this (you are managing your `filesGlob` some other way), set this
128+
to `false` (this defaults to `true`).
129+
130+
```json
131+
{
132+
"atom": {
133+
"rewriteTsconfig": true
134+
}
135+
}
136+
```
137+
118138
## Additional Notes
119139
FWIW [a json schema is also available](http://json.schemastore.org/tsconfig)

lib/main/tsconfig/tsconfig.ts

+7-3
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,7 @@ interface TypeScriptProjectRawSpecification {
129129
buildOnSave?: boolean;
130130
externalTranspiler?: string | { name: string; options?: any };
131131
scripts?: { postbuild?: string };
132+
atom?: { rewriteTsconfig?: boolean };
132133
}
133134

134135
/**
@@ -146,6 +147,7 @@ export interface TypeScriptProjectSpecification {
146147
package?: UsefulFromPackageJson;
147148
externalTranspiler?: string | { name: string; options?: any };
148149
scripts: { postbuild?: string };
150+
atom: { rewriteTsconfig: boolean };
149151
}
150152

151153
///////// FOR USE WITH THE API /////////////
@@ -337,7 +339,8 @@ export function getDefaultInMemoryProject(srcFile: string): TypeScriptProjectFil
337339
formatCodeOptions: formatting.defaultFormatCodeOptions(),
338340
compileOnSave: true,
339341
buildOnSave: false,
340-
scripts: {}
342+
scripts: {},
343+
atom: { rewriteTsconfig: true },
341344
};
342345

343346
return {
@@ -388,7 +391,7 @@ export function getProjectSync(pathOrSrcFile: string): TypeScriptProjectFileDeta
388391
if (projectSpec.filesGlob) { // for filesGlob we keep the files in sync
389392
var prettyJSONProjectSpec = prettyJSON(projectSpec, detectIndent(projectFileTextContent).indent);
390393

391-
if (prettyJSONProjectSpec !== projectFileTextContent) {
394+
if (prettyJSONProjectSpec !== projectFileTextContent && projectSpec.atom.rewriteTsconfig) {
392395
fs.writeFileSync(projectFile, prettyJSONProjectSpec);
393396
}
394397
}
@@ -421,7 +424,8 @@ export function getProjectSync(pathOrSrcFile: string): TypeScriptProjectFileDeta
421424
typings: [],
422425
externalTranspiler: projectSpec.externalTranspiler == undefined ? undefined : projectSpec.externalTranspiler,
423426
scripts: projectSpec.scripts || {},
424-
buildOnSave: !!projectSpec.buildOnSave
427+
buildOnSave: !!projectSpec.buildOnSave,
428+
atom: { rewriteTsconfig: true }
425429
};
426430

427431
// Validate the raw compiler options before converting them to TS compiler options

0 commit comments

Comments
 (0)