Skip to content

Support rewriteTsconfig flag in tsconfig.json #715

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

Merged
merged 3 commits into from
Nov 16, 2015
Merged
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
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: {},
atom: { 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.atom.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,
atom: { 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` under the `atom` key.

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

## 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
21 changes: 20 additions & 1 deletion docs/tsconfig.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +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

* [`atom`](https://github.com/TypeStrong/atom-typescript/blob/master/docs/tsconfig.md#rewriteTsconfig) : Configuration specific to Atom. Currently
only contains `rewriteTsconfig` which prevents Atom from rewriting a project's `tsconfig.json`.

## Examples

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

### atom
Configuration options specific to Atom.


**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`).

```json
{
"atom": {
"rewriteTsconfig": 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 };
atom?: { rewriteTsconfig?: boolean };
}

/**
Expand All @@ -146,6 +147,7 @@ export interface TypeScriptProjectSpecification {
package?: UsefulFromPackageJson;
externalTranspiler?: string | { name: string; options?: any };
scripts: { postbuild?: string };
atom: { 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: {},
atom: { 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.atom.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,
atom: { rewriteTsconfig: true }
};

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