Skip to content

Commit

Permalink
compile-all handles recompiling files with errors
Browse files Browse the repository at this point in the history
  • Loading branch information
azizghuloum committed Jan 5, 2025
1 parent 38b3077 commit 9123850
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 18 deletions.
13 changes: 8 additions & 5 deletions src/library-manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import stringify from "json-stringify-pretty-compact";
import { init_global_context } from "./global-module";
import { parse_dts } from "./parse-dts";

const cookie = "rewrite-ts-025";
const cookie = "rewrite-ts-026";

type module_state =
| { type: "initial" }
Expand All @@ -38,7 +38,7 @@ type module_state =
unit: CompilationUnit;
mtime: number;
}
| { type: "error"; reason: string };
| { type: "error"; reason: string; mtime: number };

abstract class Module implements imported_module {
pkg: Package;
Expand Down Expand Up @@ -177,7 +177,7 @@ abstract class Module implements imported_module {
async force_recompile() {
const state = this.state;
await this.ensureUpToDate();
assert(state.type === "fresh");
assert(state.type === "fresh" || state.type === "error");
this.state = { ...state, type: "stale" };
const dependant_modules = this.dependant_modules;
dependant_modules.forEach(
Expand All @@ -197,7 +197,8 @@ abstract class Module implements imported_module {
await this.ensureUpToDate();
const state = this.state;
switch (state.type) {
case "fresh": {
case "fresh":
case "error": {
if (t && t > state.mtime) {
await this.force_recompile();
}
Expand All @@ -223,6 +224,7 @@ abstract class Module implements imported_module {
get_mtime(): number {
switch (this.state.type) {
case "fresh":
case "error":
return this.state.mtime;
default:
throw new Error(`invalid state for '${this.path}'`);
Expand Down Expand Up @@ -409,7 +411,8 @@ class RtsModule extends Module {
this.state = { ...state, type: "fresh", ...json_content, mtime };
console.log(`up to date ${this.cuid}`);
} catch (error) {
this.state = { type: "error", reason: String(error) };
const mtime = Date.now();
this.state = { type: "error", reason: String(error), mtime };
if (error instanceof StxError) {
await print_stx_error(error, {
get_module_by_cuid: (cuid) => {
Expand Down
15 changes: 9 additions & 6 deletions test-project/.rts/main.rts.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"cid": "test-project/main.rts rewrite-ts-visualized 0.0.0",
"cookie": "rewrite-ts-025",
"cookie": "rewrite-ts-026",
"imports": [
{
"pkg": {"name": "rewrite-ts-visualized", "version": "0.0.0"},
Expand Down Expand Up @@ -50,7 +50,7 @@
["top", null]
],
{
"cuid": "dist/index.d.ts vitest 2.1.8",
"cuid": "./dist/index.d.ts vitest 2.1.8",
"name": "e.suite.@vitest/runner"
}
]
Expand All @@ -62,7 +62,7 @@
["top", null]
],
{
"cuid": "dist/index.d.ts vitest 2.1.8",
"cuid": "./dist/index.d.ts vitest 2.1.8",
"name": "e.test.@vitest/runner"
}
]
Expand All @@ -73,7 +73,10 @@
"test-project/main.rts rewrite-ts-visualized 0.0.0",
["top", null]
],
{"cuid": "dist/index.d.ts vitest 2.1.8", "name": "l.globalExpect"}
{
"cuid": "./dist/index.d.ts vitest 2.1.8",
"name": "l.globalExpect"
}
]
],
"y": [
Expand Down Expand Up @@ -121,7 +124,7 @@
["top", null]
],
{
"cuid": "dist/index.d.ts vitest 2.1.8",
"cuid": "./dist/index.d.ts vitest 2.1.8",
"name": "e.suite.@vitest/runner"
}
]
Expand All @@ -133,7 +136,7 @@
["top", null]
],
{
"cuid": "dist/index.d.ts vitest 2.1.8",
"cuid": "./dist/index.d.ts vitest 2.1.8",
"name": "e.test.@vitest/runner"
}
]
Expand Down
2 changes: 1 addition & 1 deletion test-project/.rts/mod.rts.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"cid": "test-project/mod.rts rewrite-ts-visualized 0.0.0",
"cookie": "rewrite-ts-025",
"cookie": "rewrite-ts-026",
"imports": [],
"exported_identifiers": {
"x": [
Expand Down
15 changes: 9 additions & 6 deletions test-project/.rts/sourcemap1.test.rts.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"cid": "test-project/sourcemap1.test.rts rewrite-ts-visualized 0.0.0",
"cookie": "rewrite-ts-025",
"cookie": "rewrite-ts-026",
"imports": [
{
"pkg": {"name": "vitest", "version": "2.1.8"},
Expand All @@ -25,7 +25,7 @@
["top", null]
],
{
"cuid": "dist/index.d.ts vitest 2.1.8",
"cuid": "./dist/index.d.ts vitest 2.1.8",
"name": "e.suite.@vitest/runner"
}
]
Expand All @@ -37,7 +37,7 @@
["top", null]
],
{
"cuid": "dist/index.d.ts vitest 2.1.8",
"cuid": "./dist/index.d.ts vitest 2.1.8",
"name": "e.test.@vitest/runner"
}
]
Expand All @@ -48,7 +48,10 @@
"test-project/sourcemap1.test.rts rewrite-ts-visualized 0.0.0",
["top", null]
],
{"cuid": "dist/index.d.ts vitest 2.1.8", "name": "l.globalExpect"}
{
"cuid": "./dist/index.d.ts vitest 2.1.8",
"name": "l.globalExpect"
}
]
]
},
Expand All @@ -60,7 +63,7 @@
["top", null]
],
{
"cuid": "dist/index.d.ts vitest 2.1.8",
"cuid": "./dist/index.d.ts vitest 2.1.8",
"name": "e.suite.@vitest/runner"
}
]
Expand All @@ -72,7 +75,7 @@
["top", null]
],
{
"cuid": "dist/index.d.ts vitest 2.1.8",
"cuid": "./dist/index.d.ts vitest 2.1.8",
"name": "e.test.@vitest/runner"
}
]
Expand Down

0 comments on commit 9123850

Please sign in to comment.