Skip to content

Commit 94f6ae5

Browse files
authored
Merge pull request #160 from ethdebug/increments
Enable incremental TypeScript compilation with project references
2 parents f01c38b + 10cac45 commit 94f6ae5

File tree

9 files changed

+21
-11
lines changed

9 files changed

+21
-11
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
11
node_modules/
2+
*.tsbuildinfo

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
"packages/*"
66
],
77
"scripts": {
8+
"build": "tsc --build packages/format packages/pointers",
89
"bundle": "tsx ./bin/bundle-schema.ts",
910
"test": "vitest",
1011
"start": "./bin/start",

packages/format/bin/generate-schema-yamls.js

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ const rawSchemas = Object.entries(schemaYamls)
3333
.map(([id, yaml]) => ({ [id]: YAML.parse(yaml) }))
3434
.reduce((a, b) => ({ ...a, ...b }), {});
3535

36-
console.log(`// THIS FILE GETS AUTO-GENERATED AS PART OF THIS PACKAGE'S BUILD PROCESS
36+
const output = `// THIS FILE GETS AUTO-GENERATED AS PART OF THIS PACKAGE'S BUILD PROCESS
3737
// Please do not modify it directly or allow it to get checked into source control.
3838
3939
export type SchemaYamlsById = {
@@ -50,4 +50,11 @@ const rawSchemas = ${JSON.stringify(rawSchemas, undefined, 2)} as const;
5050
5151
export type Schema<Id extends keyof typeof rawSchemas> =
5252
(typeof rawSchemas)[Id];
53-
`);
53+
`;
54+
55+
const outputPath = path.resolve(__dirname, "../src/schemas/yamls.ts");
56+
const tempPath = outputPath + ".tmp";
57+
58+
// Write to temp file, then rename atomically to avoid race conditions
59+
fs.writeFileSync(tempPath, output);
60+
fs.renameSync(tempPath, outputPath);

packages/format/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,13 @@
99
"dist"
1010
],
1111
"scripts": {
12-
"prepare:yamls": "node ./bin/generate-schema-yamls.js > src/schemas/yamls.ts",
12+
"prepare:yamls": "node ./bin/generate-schema-yamls.js",
1313
"prepare": "yarn prepare:yamls && tsc",
1414
"clean": "rm -rf dist && rm src/schemas/yamls.ts",
1515
"test": "vitest",
1616
"watch:typescript": "tsc --watch",
1717
"watch:schemas": "nodemon --watch ../../schemas -e 'yaml' --exec 'yarn prepare:yamls'",
18-
"watch": "concurrently --names=tsc,schemas \"yarn watch:typescript\" \"yarn watch:schemas\""
18+
"watch": "yarn prepare && concurrently --names=tsc,schemas \"yarn watch:typescript\" \"yarn watch:schemas\""
1919
},
2020
"dependencies": {
2121
"json-schema-typed": "^8.0.1",

packages/format/test/guards.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ export interface SchemaGuard extends DescribeSchemaOptions {
88

99
export const testSchemaGuards = (
1010
namespace: string,
11-
schemaGuards: SchemaGuard[],
11+
schemaGuards: readonly SchemaGuard[],
1212
) => {
1313
describe(`type guards for ${namespace} schemas`, () => {
1414
for (const { guard, ...describeSchemaOptions } of schemaGuards) {

packages/format/tsconfig.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,5 +8,5 @@
88
"rootDir": "./",
99
"outDir": "./dist/"
1010
},
11-
"include": ["./src/**/*.ts", "vitest.d.ts", "yamls.ts"]
11+
"include": ["./src/**/*.ts", "./test/**/*.ts", "./*.ts"]
1212
}

packages/pointers/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@
77
"license": "MIT",
88
"scripts": {
99
"run-example": "node ./dist/bin/run-example.js",
10-
"prepare": "tsc",
11-
"watch": "yarn prepare --watch",
10+
"prepare": "tsc --build",
11+
"watch": "tsc --build --watch",
1212
"test": "vitest"
1313
},
1414
"devDependencies": {

packages/pointers/tsconfig.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,6 @@
33
"compilerOptions": {
44
"rootDir": "./",
55
"outDir": "./dist/"
6-
}
6+
},
7+
"references": [{ "path": "../format" }]
78
}

tsconfig.base.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33
/* Visit https://aka.ms/tsconfig to read more about this file */
44

55
/* Projects */
6-
// "incremental": true, /* Save .tsbuildinfo files to allow for incremental compilation of projects. */
7-
// "composite": true, /* Enable constraints that allow a TypeScript project to be used with project references. */
6+
"incremental": true /* Save .tsbuildinfo files to allow for incremental compilation of projects. */,
7+
"composite": true /* Enable constraints that allow a TypeScript project to be used with project references. */,
88
// "tsBuildInfoFile": "./.tsbuildinfo", /* Specify the path to .tsbuildinfo incremental compilation file. */
99
// "disableSourceOfProjectReferenceRedirect": true, /* Disable preferring source files instead of declaration files when referencing composite projects. */
1010
// "disableSolutionSearching": true, /* Opt a project out of multi-project reference checking when editing. */

0 commit comments

Comments
 (0)