diff --git a/.gitignore b/.gitignore index c2658d7d..ff2c5856 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,2 @@ node_modules/ +*.tsbuildinfo diff --git a/package.json b/package.json index 78d6fb48..1c71ed9e 100644 --- a/package.json +++ b/package.json @@ -5,6 +5,7 @@ "packages/*" ], "scripts": { + "build": "tsc --build packages/format packages/pointers", "bundle": "tsx ./bin/bundle-schema.ts", "test": "vitest", "start": "./bin/start", diff --git a/packages/format/bin/generate-schema-yamls.js b/packages/format/bin/generate-schema-yamls.js index 5f42c890..3671935f 100644 --- a/packages/format/bin/generate-schema-yamls.js +++ b/packages/format/bin/generate-schema-yamls.js @@ -33,7 +33,7 @@ const rawSchemas = Object.entries(schemaYamls) .map(([id, yaml]) => ({ [id]: YAML.parse(yaml) })) .reduce((a, b) => ({ ...a, ...b }), {}); -console.log(`// THIS FILE GETS AUTO-GENERATED AS PART OF THIS PACKAGE'S BUILD PROCESS +const output = `// THIS FILE GETS AUTO-GENERATED AS PART OF THIS PACKAGE'S BUILD PROCESS // Please do not modify it directly or allow it to get checked into source control. export type SchemaYamlsById = { @@ -50,4 +50,11 @@ const rawSchemas = ${JSON.stringify(rawSchemas, undefined, 2)} as const; export type Schema = (typeof rawSchemas)[Id]; -`); +`; + +const outputPath = path.resolve(__dirname, "../src/schemas/yamls.ts"); +const tempPath = outputPath + ".tmp"; + +// Write to temp file, then rename atomically to avoid race conditions +fs.writeFileSync(tempPath, output); +fs.renameSync(tempPath, outputPath); diff --git a/packages/format/package.json b/packages/format/package.json index 2defc53b..4a653469 100644 --- a/packages/format/package.json +++ b/packages/format/package.json @@ -9,13 +9,13 @@ "dist" ], "scripts": { - "prepare:yamls": "node ./bin/generate-schema-yamls.js > src/schemas/yamls.ts", + "prepare:yamls": "node ./bin/generate-schema-yamls.js", "prepare": "yarn prepare:yamls && tsc", "clean": "rm -rf dist && rm src/schemas/yamls.ts", "test": "vitest", "watch:typescript": "tsc --watch", "watch:schemas": "nodemon --watch ../../schemas -e 'yaml' --exec 'yarn prepare:yamls'", - "watch": "concurrently --names=tsc,schemas \"yarn watch:typescript\" \"yarn watch:schemas\"" + "watch": "yarn prepare && concurrently --names=tsc,schemas \"yarn watch:typescript\" \"yarn watch:schemas\"" }, "dependencies": { "json-schema-typed": "^8.0.1", diff --git a/packages/format/test/guards.ts b/packages/format/test/guards.ts index 470a3cef..f0385664 100644 --- a/packages/format/test/guards.ts +++ b/packages/format/test/guards.ts @@ -8,7 +8,7 @@ export interface SchemaGuard extends DescribeSchemaOptions { export const testSchemaGuards = ( namespace: string, - schemaGuards: SchemaGuard[], + schemaGuards: readonly SchemaGuard[], ) => { describe(`type guards for ${namespace} schemas`, () => { for (const { guard, ...describeSchemaOptions } of schemaGuards) { diff --git a/packages/format/tsconfig.json b/packages/format/tsconfig.json index ec599801..1ff58c75 100644 --- a/packages/format/tsconfig.json +++ b/packages/format/tsconfig.json @@ -8,5 +8,5 @@ "rootDir": "./", "outDir": "./dist/" }, - "include": ["./src/**/*.ts", "vitest.d.ts", "yamls.ts"] + "include": ["./src/**/*.ts", "./test/**/*.ts", "./*.ts"] } diff --git a/packages/pointers/package.json b/packages/pointers/package.json index 157242b6..d74eb683 100644 --- a/packages/pointers/package.json +++ b/packages/pointers/package.json @@ -7,8 +7,8 @@ "license": "MIT", "scripts": { "run-example": "node ./dist/bin/run-example.js", - "prepare": "tsc", - "watch": "yarn prepare --watch", + "prepare": "tsc --build", + "watch": "tsc --build --watch", "test": "vitest" }, "devDependencies": { diff --git a/packages/pointers/tsconfig.json b/packages/pointers/tsconfig.json index 86950c29..2e1ab2b9 100644 --- a/packages/pointers/tsconfig.json +++ b/packages/pointers/tsconfig.json @@ -3,5 +3,6 @@ "compilerOptions": { "rootDir": "./", "outDir": "./dist/" - } + }, + "references": [{ "path": "../format" }] } diff --git a/tsconfig.base.json b/tsconfig.base.json index b9f77881..f702e095 100644 --- a/tsconfig.base.json +++ b/tsconfig.base.json @@ -3,8 +3,8 @@ /* Visit https://aka.ms/tsconfig to read more about this file */ /* Projects */ - // "incremental": true, /* Save .tsbuildinfo files to allow for incremental compilation of projects. */ - // "composite": true, /* Enable constraints that allow a TypeScript project to be used with project references. */ + "incremental": true /* Save .tsbuildinfo files to allow for incremental compilation of projects. */, + "composite": true /* Enable constraints that allow a TypeScript project to be used with project references. */, // "tsBuildInfoFile": "./.tsbuildinfo", /* Specify the path to .tsbuildinfo incremental compilation file. */ // "disableSourceOfProjectReferenceRedirect": true, /* Disable preferring source files instead of declaration files when referencing composite projects. */ // "disableSolutionSearching": true, /* Opt a project out of multi-project reference checking when editing. */