Skip to content

Commit

Permalink
Support rewriteTsconfig flag in tsconfig.json
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
Sam Szuflita committed Nov 11, 2015
1 parent 273a74a commit 0489c83
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 6 deletions.
8 changes: 5 additions & 3 deletions dist/main/tsconfig/tsconfig.js
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,8 @@ function getDefaultInMemoryProject(srcFile) {
formatCodeOptions: formatting.defaultFormatCodeOptions(),
compileOnSave: true,
buildOnSave: false,
scripts: {}
scripts: {},
rewriteTsconfig: true
};
return {
projectFileDirectory: dir,
Expand Down Expand Up @@ -210,7 +211,7 @@ function getProjectSync(pathOrSrcFile) {
}
if (projectSpec.filesGlob) {
var prettyJSONProjectSpec = prettyJSON(projectSpec, detectIndent(projectFileTextContent).indent);
if (prettyJSONProjectSpec !== projectFileTextContent) {
if (prettyJSONProjectSpec !== projectFileTextContent && projectSpec.rewriteTsconfig) {
fs.writeFileSync(projectFile, prettyJSONProjectSpec);
}
}
Expand Down Expand Up @@ -240,7 +241,8 @@ function getProjectSync(pathOrSrcFile) {
typings: [],
externalTranspiler: projectSpec.externalTranspiler == undefined ? undefined : projectSpec.externalTranspiler,
scripts: projectSpec.scripts || {},
buildOnSave: !!projectSpec.buildOnSave
buildOnSave: !!projectSpec.buildOnSave,
rewriteTsconfig: true
};
var validationResult = validator.validate(projectSpec.compilerOptions);
if (validationResult.errorMessage) {
Expand Down
4 changes: 4 additions & 0 deletions docs/faq.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@
## I keep getting changes to tsconfig.json
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.).

You can now disable this behavior by setting the `rewriteTsconfig` flag to `false` in your project's `tsconfig.json`.

[Further Details](https://github.com/TypeStrong/atom-typescript/blob/master/docs/tsconfig.md#rewriteTsconfig)

## For really large projects atom-typescript gets slow
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:
* Move `tsconfig.json` into a sub folder e.g. `src`
Expand Down
7 changes: 7 additions & 0 deletions docs/tsconfig.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ i.e. an empty JSON file at the *root* of your project :heart: This will be suffi
* [`compileOnSave`](https://github.com/TypeStrong/atom-typescript/blob/master/docs/tsconfig.md#compileonsave) : Should AtomTS compile on save
* [`buildOnSave`](https://github.com/TypeStrong/atom-typescript/blob/master/docs/tsconfig.md#buildonsave) : Should AtomTS build on save
* [`scripts`](https://github.com/TypeStrong/atom-typescript/blob/master/docs/tsconfig.md#scripts) : Sometimes its useful to have post build scripts
* [`rewriteTsconfig`](https://github.com/TypeStrong/atom-typescript/blob/master/docs/tsconfig.md#rewriteTsconfig) : Many
projects don't want Atom to constantly rewrite their `tsconfig.json`.


## Examples
Expand Down Expand Up @@ -115,5 +117,10 @@ Build means *compile all files*. Useful if for some reason you are using `--out`
}
```

### rewriteTsconfig
Atom-Typescript constantly resolves the `filesGlob` listed in your `tsconfig.json` to ensure that the glob is in sync
with your project. If your project doesn't require this (you are managing your `filesGlob` some other way), set this
to `false` (this defaults to `true`).

## Additional Notes
FWIW [a json schema is also available](http://json.schemastore.org/tsconfig)
10 changes: 7 additions & 3 deletions lib/main/tsconfig/tsconfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,7 @@ interface TypeScriptProjectRawSpecification {
buildOnSave?: boolean;
externalTranspiler?: string | { name: string; options?: any };
scripts?: { postbuild?: string };
rewriteTsconfig?: boolean; // optional: rewrite tsconfig to prettified version. Used by Atom.
}

/**
Expand All @@ -146,6 +147,7 @@ export interface TypeScriptProjectSpecification {
package?: UsefulFromPackageJson;
externalTranspiler?: string | { name: string; options?: any };
scripts: { postbuild?: string };
rewriteTsconfig: boolean;
}

///////// FOR USE WITH THE API /////////////
Expand Down Expand Up @@ -337,7 +339,8 @@ export function getDefaultInMemoryProject(srcFile: string): TypeScriptProjectFil
formatCodeOptions: formatting.defaultFormatCodeOptions(),
compileOnSave: true,
buildOnSave: false,
scripts: {}
scripts: {},
rewriteTsconfig: true
};

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

if (prettyJSONProjectSpec !== projectFileTextContent) {
if (prettyJSONProjectSpec !== projectFileTextContent && projectSpec.rewriteTsconfig) {
fs.writeFileSync(projectFile, prettyJSONProjectSpec);
}
}
Expand Down Expand Up @@ -421,7 +424,8 @@ export function getProjectSync(pathOrSrcFile: string): TypeScriptProjectFileDeta
typings: [],
externalTranspiler: projectSpec.externalTranspiler == undefined ? undefined : projectSpec.externalTranspiler,
scripts: projectSpec.scripts || {},
buildOnSave: !!projectSpec.buildOnSave
buildOnSave: !!projectSpec.buildOnSave,
rewriteTsconfig: true
};

// Validate the raw compiler options before converting them to TS compiler options
Expand Down

0 comments on commit 0489c83

Please sign in to comment.