@gaganref/confect-cli 10.3.1-fork.96 → 10.6.0-fork.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +78 -0
- package/dist/Ansi.mjs +1 -2
- package/dist/BuildError.mjs +5 -5
- package/dist/BuildError.mjs.map +1 -1
- package/dist/Bundler.mjs +103 -76
- package/dist/Bundler.mjs.map +1 -1
- package/dist/CodeBlockWriter.mjs +1 -2
- package/dist/CodegenError.mjs +27 -17
- package/dist/CodegenError.mjs.map +1 -1
- package/dist/ConfectDirectory.mjs +8 -3
- package/dist/ConfectDirectory.mjs.map +1 -1
- package/dist/ConvexConfig.mjs +23 -15
- package/dist/ConvexConfig.mjs.map +1 -1
- package/dist/ConvexDirectory.mjs +6 -4
- package/dist/ConvexDirectory.mjs.map +1 -1
- package/dist/Declaration.mjs +92 -56
- package/dist/Declaration.mjs.map +1 -1
- package/dist/DirectoryOptions.mjs +13 -8
- package/dist/DirectoryOptions.mjs.map +1 -1
- package/dist/DocName.mjs +1 -2
- package/dist/EntryPoint.mjs +17 -15
- package/dist/EntryPoint.mjs.map +1 -1
- package/dist/Evaluation.mjs +24 -13
- package/dist/Evaluation.mjs.map +1 -1
- package/dist/EvaluationWorker.mjs +5 -6
- package/dist/EvaluationWorker.mjs.map +1 -1
- package/dist/FunctionModule.mjs +85 -47
- package/dist/FunctionModule.mjs.map +1 -1
- package/dist/FunctionPath.mjs +1 -2
- package/dist/FunctionPath.mjs.map +1 -1
- package/dist/FunctionPaths.mjs +2 -3
- package/dist/GenerationSnapshot.mjs +30 -22
- package/dist/GenerationSnapshot.mjs.map +1 -1
- package/dist/GroupPath.mjs +6 -3
- package/dist/GroupPath.mjs.map +1 -1
- package/dist/GroupPaths.mjs +1 -2
- package/dist/ImplModulePath.mjs +1 -2
- package/dist/Json.mjs +13 -0
- package/dist/Json.mjs.map +1 -0
- package/dist/LeafModule.mjs +121 -41
- package/dist/LeafModule.mjs.map +1 -1
- package/dist/ManifestSections.mjs +23 -19
- package/dist/ManifestSections.mjs.map +1 -1
- package/dist/PackageSelfReference.mjs +32 -0
- package/dist/PackageSelfReference.mjs.map +1 -0
- package/dist/ProjectRoot.mjs +11 -3
- package/dist/ProjectRoot.mjs.map +1 -1
- package/dist/RelativeModulePath.mjs +1 -2
- package/dist/Remove.mjs +2 -3
- package/dist/Remove.mjs.map +1 -1
- package/dist/RestoreWatcher.mjs +1 -2
- package/dist/Rollback.mjs +7 -6
- package/dist/Rollback.mjs.map +1 -1
- package/dist/SectionFiles.mjs +77 -48
- package/dist/SectionFiles.mjs.map +1 -1
- package/dist/SnapshotError.mjs +3 -3
- package/dist/SnapshotError.mjs.map +1 -1
- package/dist/SpecAssemblyNode.mjs +1 -2
- package/dist/SpecModulePath.mjs +4 -4
- package/dist/SpecModulePath.mjs.map +1 -1
- package/dist/SyncState.mjs +3 -4
- package/dist/SyncState.mjs.map +1 -1
- package/dist/TableModule.mjs +18 -10
- package/dist/TableModule.mjs.map +1 -1
- package/dist/TableModulePath.mjs +3 -3
- package/dist/TableModulePath.mjs.map +1 -1
- package/dist/TypeScriptConfig.mjs +135 -0
- package/dist/TypeScriptConfig.mjs.map +1 -0
- package/dist/WatchBuild.mjs +107 -32
- package/dist/WatchBuild.mjs.map +1 -1
- package/dist/WatchGraph.mjs +4 -4
- package/dist/WatchGraph.mjs.map +1 -1
- package/dist/WatchTopology.mjs +5 -4
- package/dist/WatchTopology.mjs.map +1 -1
- package/dist/Watcher.mjs +179 -108
- package/dist/Watcher.mjs.map +1 -1
- package/dist/cliApp.mjs +5 -3
- package/dist/cliApp.mjs.map +1 -1
- package/dist/confect/codegen.mjs +95 -53
- package/dist/confect/codegen.mjs.map +1 -1
- package/dist/confect/declaration.mjs +76 -42
- package/dist/confect/declaration.mjs.map +1 -1
- package/dist/confect/dev.mjs +18 -12
- package/dist/confect/dev.mjs.map +1 -1
- package/dist/confect.mjs +4 -2
- package/dist/confect.mjs.map +1 -1
- package/dist/index.mjs +1 -2
- package/dist/log.mjs +13 -5
- package/dist/log.mjs.map +1 -1
- package/dist/package.json.mjs +5 -0
- package/dist/package.json.mjs.map +1 -0
- package/dist/templates.mjs +34 -22
- package/dist/templates.mjs.map +1 -1
- package/dist/utils.mjs +36 -5
- package/dist/utils.mjs.map +1 -1
- package/package.json +10 -10
- package/dist/package.mjs +0 -6
- package/dist/package.mjs.map +0 -1
package/dist/TableModule.mjs
CHANGED
|
@@ -9,14 +9,19 @@ import * as FileSystem from "effect/FileSystem";
|
|
|
9
9
|
import * as Path from "effect/Path";
|
|
10
10
|
import * as Array from "effect/Array";
|
|
11
11
|
import { pipe } from "effect/Function";
|
|
12
|
+
import * as Record from "effect/Record";
|
|
13
|
+
import * as String from "effect/String";
|
|
12
14
|
import * as Order from "effect/Order";
|
|
13
15
|
import * as Table from "@confect/core/Table";
|
|
14
|
-
|
|
16
|
+
// src/TableModule.ts
|
|
15
17
|
const TABLES_DIRNAME = "tables";
|
|
16
18
|
const tableNameFromRelativePath = Effect.fnUntraced(function* (relativePath) {
|
|
17
19
|
const { name } = (yield* Path.Path).parse(relativePath);
|
|
18
20
|
return name;
|
|
19
21
|
});
|
|
22
|
+
/**
|
|
23
|
+
* @internal
|
|
24
|
+
*/
|
|
20
25
|
const discoverTableFiles = Effect.gen(function* () {
|
|
21
26
|
const fs = yield* FileSystem.FileSystem;
|
|
22
27
|
const path = yield* Path.Path;
|
|
@@ -24,7 +29,7 @@ const discoverTableFiles = Effect.gen(function* () {
|
|
|
24
29
|
const tablesDirectory = path.join(confectDirectory, TABLES_DIRNAME);
|
|
25
30
|
if (!(yield* fs.exists(tablesDirectory))) return [];
|
|
26
31
|
const allPaths = yield* readDirectorySorted(tablesDirectory);
|
|
27
|
-
return pipe(allPaths, Array.filter((p) =>
|
|
32
|
+
return pipe(allPaths, Array.filter((p) => String.endsWith(".ts")(p) && !String.endsWith(".test.ts")(p)), Array.map((p) => path.join(TABLES_DIRNAME, p)));
|
|
28
33
|
});
|
|
29
34
|
const byTableName = Order.mapInput(Order.String, (tableModule) => tableModule.tableName);
|
|
30
35
|
/**
|
|
@@ -46,6 +51,8 @@ const byTableName = Order.mapInput(Order.String, (tableModule) => tableModule.ta
|
|
|
46
51
|
* the same table name (the directory is scanned recursively but names are
|
|
47
52
|
* derived from the basename alone, so `tables/a/notes.ts` and
|
|
48
53
|
* `tables/b/notes.ts` would collide).
|
|
54
|
+
*
|
|
55
|
+
* @internal
|
|
49
56
|
*/
|
|
50
57
|
const discover = Effect.gen(function* () {
|
|
51
58
|
const relativePaths = yield* discoverTableFiles;
|
|
@@ -53,9 +60,9 @@ const discover = Effect.gen(function* () {
|
|
|
53
60
|
const tableName = yield* tableNameFromRelativePath(relativePath);
|
|
54
61
|
yield* Effect.try({
|
|
55
62
|
try: () => Identifier.validateConfectTableIdentifier(tableName),
|
|
56
|
-
catch: (e) =>
|
|
63
|
+
catch: (e) => InvalidTableFilenameError.make({
|
|
57
64
|
tablePath: relativePath,
|
|
58
|
-
reason: e instanceof Error ? e.message : String(e)
|
|
65
|
+
reason: e instanceof Error ? e.message : globalThis.String(e)
|
|
59
66
|
})
|
|
60
67
|
});
|
|
61
68
|
return {
|
|
@@ -64,11 +71,11 @@ const discover = Effect.gen(function* () {
|
|
|
64
71
|
};
|
|
65
72
|
}), { concurrency: "unbounded" });
|
|
66
73
|
const sorted = pipe(tableModules, Array.sortBy(byTableName));
|
|
67
|
-
const collisions =
|
|
74
|
+
const collisions = Array.map(Array.filter(Record.toEntries(Array.groupBy(sorted, (tableModule) => tableModule.tableName)), ([, group]) => group.length > 1), ([tableName, group]) => ({
|
|
68
75
|
tableName,
|
|
69
76
|
tablePaths: Array.map(group, (tableModule) => tableModule.relativePath)
|
|
70
77
|
}));
|
|
71
|
-
if (collisions.length > 0) return yield*
|
|
78
|
+
if (collisions.length > 0) return yield* DuplicateTableNameError.make({ collisions });
|
|
72
79
|
return sorted;
|
|
73
80
|
});
|
|
74
81
|
/**
|
|
@@ -80,6 +87,8 @@ const discover = Effect.gen(function* () {
|
|
|
80
87
|
* Must run _after_ `_generated/id.ts` has been emitted, because user-authored
|
|
81
88
|
* table modules typically `import { Id } from "../_generated/id"` for
|
|
82
89
|
* cross-table references.
|
|
90
|
+
*
|
|
91
|
+
* @internal
|
|
83
92
|
*/
|
|
84
93
|
const validate = Effect.fnUntraced(function* (tableModules) {
|
|
85
94
|
const path = yield* Path.Path;
|
|
@@ -87,12 +96,11 @@ const validate = Effect.fnUntraced(function* (tableModules) {
|
|
|
87
96
|
const validateRelativePath = Effect.fnUntraced(function* (relativePath) {
|
|
88
97
|
const absolutePath = path.resolve(confectDirectory, relativePath);
|
|
89
98
|
const { module } = yield* bundle(absolutePath).pipe(Effect.mapError((error) => fromBundlerError(relativePath, error)));
|
|
90
|
-
if (!Table.isUnnamedTable(module.default)) return yield*
|
|
99
|
+
if (!Table.isUnnamedTable(module.default)) return yield* InvalidTableDefaultExportError.make({ tablePath: relativePath });
|
|
91
100
|
});
|
|
92
|
-
const relativePaths =
|
|
93
|
-
yield* withBatch(
|
|
101
|
+
const relativePaths = Array.map(tableModules, ({ relativePath }) => relativePath);
|
|
102
|
+
yield* withBatch(Array.map(relativePaths, (relativePath) => path.resolve(confectDirectory, relativePath)), Effect.forEach(relativePaths, validateRelativePath, { concurrency: 4 }));
|
|
94
103
|
});
|
|
95
|
-
//#endregion
|
|
96
104
|
export { TABLES_DIRNAME, discover, discoverTableFiles, validate };
|
|
97
105
|
|
|
98
106
|
//# sourceMappingURL=TableModule.mjs.map
|
package/dist/TableModule.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"TableModule.mjs","names":["Bundler.bundle","Bundler.withBatch"],"sources":["../src/TableModule.ts"],"sourcesContent":["import { Identifier } from \"@confect/core\";\nimport * as Table from \"@confect/core/Table\";\nimport * as FileSystem from \"effect/FileSystem\";\nimport * as Path from \"effect/Path\";\nimport { pipe } from \"effect/Function\";\nimport * as Array from \"effect/Array\";\nimport * as Effect from \"effect/Effect\";\nimport * as Order from \"effect/Order\";\nimport { fromBundlerError } from \"./BuildError.js\";\nimport * as Bundler from \"./Bundler.js\";\nimport {\n DuplicateTableNameError,\n InvalidTableDefaultExportError,\n InvalidTableFilenameError,\n} from \"./CodegenError.js\";\nimport { ConfectDirectory } from \"./ConfectDirectory.js\";\nimport { readDirectorySorted } from \"./utils.js\";\n\nexport const TABLES_DIRNAME = \"tables\";\n\n/**\n * Discovered metadata for a single user-authored table module under\n * `confect/tables/`.\n *\n * - `relativePath`—path from `confect/` to the file (e.g. `tables/notes.ts`).\n * - `tableName`—the file basename (e.g. `notes`). This is also the import binding\n * used in generated files, and the table name surfaced to Convex.\n */\nexport interface TableModule {\n readonly relativePath: string;\n readonly tableName: string;\n}\n\nconst tableNameFromRelativePath = Effect.fnUntraced(function* (\n relativePath: string,\n) {\n const path = yield* Path.Path;\n const { name } = path.parse(relativePath);\n return name;\n});\n\nexport const discoverTableFiles = Effect.gen(function* () {\n const fs = yield* FileSystem.FileSystem;\n const path = yield* Path.Path;\n const confectDirectory = yield* ConfectDirectory.get;\n const tablesDirectory = path.join(confectDirectory, TABLES_DIRNAME);\n\n if (!(yield* fs.exists(tablesDirectory))) {\n return [] as ReadonlyArray<string>;\n }\n\n const allPaths = yield* readDirectorySorted(tablesDirectory);\n\n return pipe(\n allPaths,\n Array.filter((p) =>
|
|
1
|
+
{"version":3,"file":"TableModule.mjs","names":["Bundler.bundle","Bundler.withBatch"],"sources":["../src/TableModule.ts"],"sourcesContent":["import * as String from \"effect/String\";\nimport * as Record from \"effect/Record\";\nimport { Identifier } from \"@confect/core\";\nimport * as Table from \"@confect/core/Table\";\nimport * as FileSystem from \"effect/FileSystem\";\nimport * as Path from \"effect/Path\";\nimport { pipe } from \"effect/Function\";\nimport * as Array from \"effect/Array\";\nimport * as Effect from \"effect/Effect\";\nimport * as Order from \"effect/Order\";\nimport { fromBundlerError } from \"./BuildError.js\";\nimport * as Bundler from \"./Bundler.js\";\nimport {\n DuplicateTableNameError,\n InvalidTableDefaultExportError,\n InvalidTableFilenameError,\n} from \"./CodegenError.js\";\nimport { ConfectDirectory } from \"./ConfectDirectory.js\";\nimport { readDirectorySorted } from \"./utils.js\";\n\nexport const TABLES_DIRNAME = \"tables\";\n\n/**\n * Discovered metadata for a single user-authored table module under\n * `confect/tables/`.\n *\n * - `relativePath`—path from `confect/` to the file (e.g. `tables/notes.ts`).\n * - `tableName`—the file basename (e.g. `notes`). This is also the import binding\n * used in generated files, and the table name surfaced to Convex.\n */\nexport interface TableModule {\n readonly relativePath: string;\n readonly tableName: string;\n}\n\nconst tableNameFromRelativePath = Effect.fnUntraced(function* (\n relativePath: string,\n) {\n const path = yield* Path.Path;\n const { name } = path.parse(relativePath);\n return name;\n});\n\n/**\n * @internal\n */\nexport const discoverTableFiles = Effect.gen(function* () {\n const fs = yield* FileSystem.FileSystem;\n const path = yield* Path.Path;\n const confectDirectory = yield* ConfectDirectory.get;\n const tablesDirectory = path.join(confectDirectory, TABLES_DIRNAME);\n\n if (!(yield* fs.exists(tablesDirectory))) {\n return [] as ReadonlyArray<string>;\n }\n\n const allPaths = yield* readDirectorySorted(tablesDirectory);\n\n return pipe(\n allPaths,\n Array.filter(\n (p) => String.endsWith(\".ts\")(p) && !String.endsWith(\".test.ts\")(p),\n ),\n Array.map((p) => path.join(TABLES_DIRNAME, p)),\n );\n});\n\nconst byTableName = Order.mapInput(\n Order.String,\n (tableModule: TableModule) => tableModule.tableName,\n);\n\n/**\n * Discover every `confect/tables/**\\/*.ts` module by listing the directory.\n * Validates that each filename is a legal table identifier—the table name is\n * derived from the file basename, so the filename must be a valid JavaScript\n * identifier with no leading underscore (Convex reserves `_<name>` for system\n * tables).\n *\n * This step does _not_ bundle the table modules. It runs early in the codegen\n * pipeline so the `_generated/id.ts` constructor can be emitted _before_ any\n * user-authored table is bundled (those modules import from `_generated/id.ts`\n * for cross-table refs).\n *\n * A missing `confect/tables/` directory is allowed and produces an empty list.\n *\n * Fails with {@link InvalidTableFilenameError} if any filename is not a valid\n * table identifier, or {@link DuplicateTableNameError} if two files resolve to\n * the same table name (the directory is scanned recursively but names are\n * derived from the basename alone, so `tables/a/notes.ts` and\n * `tables/b/notes.ts` would collide).\n *\n * @internal\n */\nexport const discover = Effect.gen(function* () {\n const relativePaths = yield* discoverTableFiles;\n\n const tableModules = yield* Effect.forEach(\n relativePaths,\n Effect.fnUntraced(function* (relativePath: string) {\n const tableName = yield* tableNameFromRelativePath(relativePath);\n yield* Effect.try({\n try: () => Identifier.validateConfectTableIdentifier(tableName),\n catch: (e) =>\n InvalidTableFilenameError.make({\n tablePath: relativePath,\n reason: e instanceof Error ? e.message : globalThis.String(e),\n }),\n });\n return { relativePath, tableName } satisfies TableModule;\n }),\n { concurrency: \"unbounded\" },\n );\n\n const sorted = pipe(tableModules, Array.sortBy(byTableName));\n\n const collisions = Array.map(\n Array.filter(\n Record.toEntries(\n Array.groupBy(sorted, (tableModule) => tableModule.tableName),\n ),\n ([, group]) => group.length > 1,\n ),\n ([tableName, group]) => ({\n tableName,\n tablePaths: Array.map(group, (tableModule) => tableModule.relativePath),\n }),\n );\n\n if (collisions.length > 0) {\n return yield* DuplicateTableNameError.make({ collisions });\n }\n\n return sorted;\n});\n\n/**\n * Bundle every discovered table module and verify that its default export is an\n * {@link Table.UnnamedTable} (the result of `Table.make(...)` before a name has\n * been bound). Fails with {@link InvalidTableDefaultExportError} if any\n * module's default export is missing or has the wrong shape.\n *\n * Must run _after_ `_generated/id.ts` has been emitted, because user-authored\n * table modules typically `import { Id } from \"../_generated/id\"` for\n * cross-table references.\n *\n * @internal\n */\nexport const validate = Effect.fnUntraced(function* (\n tableModules: ReadonlyArray<TableModule>,\n) {\n const path = yield* Path.Path;\n const confectDirectory = yield* ConfectDirectory.get;\n\n const validateRelativePath = Effect.fnUntraced(function* (\n relativePath: string,\n ) {\n const absolutePath = path.resolve(confectDirectory, relativePath);\n const { module } = yield* Bundler.bundle(absolutePath).pipe(\n Effect.mapError((error) => fromBundlerError(relativePath, error)),\n );\n\n if (!Table.isUnnamedTable(module.default)) {\n return yield* InvalidTableDefaultExportError.make({\n tablePath: relativePath,\n });\n }\n });\n\n const relativePaths = Array.map(\n tableModules,\n ({ relativePath }) => relativePath,\n );\n yield* Bundler.withBatch(\n Array.map(relativePaths, (relativePath) =>\n path.resolve(confectDirectory, relativePath),\n ),\n Effect.forEach(relativePaths, validateRelativePath, { concurrency: 4 }),\n );\n});\n"],"mappings":";;;;;;;;;;;;;;;;AAoBA,MAAa,iBAAiB;AAe9B,MAAM,4BAA4B,OAAO,WAAW,WAClD,cACA;CAEA,MAAM,EAAE,UAAS,OADG,KAAK,KAAA,CACH,MAAM,YAAY;CACxC,OAAO;AACT,CAAC;;;;AAKD,MAAa,qBAAqB,OAAO,IAAI,aAAa;CACxD,MAAM,KAAK,OAAO,WAAW;CAC7B,MAAM,OAAO,OAAO,KAAK;CACzB,MAAM,mBAAmB,OAAO,iBAAiB;CACjD,MAAM,kBAAkB,KAAK,KAAK,kBAAkB,cAAc;CAElE,IAAI,EAAE,OAAO,GAAG,OAAO,eAAe,IACpC,OAAO,CAAC;CAGV,MAAM,WAAW,OAAO,oBAAoB,eAAe;CAE3D,OAAO,KACL,UACA,MAAM,QACH,MAAM,OAAO,SAAS,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,SAAS,UAAU,CAAC,CAAC,CAAC,CACpE,GACA,MAAM,KAAK,MAAM,KAAK,KAAK,gBAAgB,CAAC,CAAC,CAC/C;AACF,CAAC;AAED,MAAM,cAAc,MAAM,SACxB,MAAM,SACL,gBAA6B,YAAY,SAC5C;;;;;;;;;;;;;;;;;;;;;;;AAwBA,MAAa,WAAW,OAAO,IAAI,aAAa;CAC9C,MAAM,gBAAgB,OAAO;CAE7B,MAAM,eAAe,OAAO,OAAO,QACjC,eACA,OAAO,WAAW,WAAW,cAAsB;EACjD,MAAM,YAAY,OAAO,0BAA0B,YAAY;EAC/D,OAAO,OA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AAE,CAAC,CACxE;AACF,CAAC"}
|
package/dist/TableModulePath.mjs
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { withSuffix } from "./RelativeModulePath.mjs";
|
|
2
2
|
import * as Schema from "effect/Schema";
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
3
|
+
import * as String from "effect/String";
|
|
4
|
+
// src/TableModulePath.ts
|
|
5
|
+
const TableModulePath = withSuffix(".ts").check(Schema.makeFilter((value) => String.split(/[/\\]/)(value)[0] === "tables")).pipe(Schema.brand("@confect/cli/TableModulePath"));
|
|
6
6
|
export { TableModulePath };
|
|
7
7
|
|
|
8
8
|
//# sourceMappingURL=TableModulePath.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"TableModulePath.mjs","names":["RelativeModulePath.withSuffix"],"sources":["../src/TableModulePath.ts"],"sourcesContent":["import * as Schema from \"effect/Schema\";\nimport * as RelativeModulePath from \"./RelativeModulePath.js\";\n\nexport const TableModulePath = RelativeModulePath.withSuffix(\".ts\")\n .check(Schema.makeFilter((value) =>
|
|
1
|
+
{"version":3,"file":"TableModulePath.mjs","names":["RelativeModulePath.withSuffix"],"sources":["../src/TableModulePath.ts"],"sourcesContent":["import * as String from \"effect/String\";\nimport * as Schema from \"effect/Schema\";\nimport * as RelativeModulePath from \"./RelativeModulePath.js\";\n\nexport const TableModulePath = RelativeModulePath.withSuffix(\".ts\")\n .check(\n Schema.makeFilter((value) => String.split(/[/\\\\]/)(value)[0] === \"tables\"),\n )\n .pipe(Schema.brand(\"@confect/cli/TableModulePath\"));\n\nexport type TableModulePath = typeof TableModulePath.Type;\n"],"mappings":";;;;AAIA,MAAa,kBAAkBA,WAA8B,KAAK,CAAC,CAChE,MACC,OAAO,YAAY,UAAU,OAAO,MAAM,OAAO,CAAC,CAAC,KAAK,CAAC,CAAC,OAAO,QAAQ,CAC3E,CAAC,CACA,KAAK,OAAO,MAAM,8BAA8B,CAAC"}
|
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
import { BundlerError } from "./BuildError.mjs";
|
|
2
|
+
import * as NodeModule from "node:module";
|
|
3
|
+
import * as Effect from "effect/Effect";
|
|
4
|
+
import * as FileSystem from "effect/FileSystem";
|
|
5
|
+
import * as Path from "effect/Path";
|
|
6
|
+
import * as Array from "effect/Array";
|
|
7
|
+
import * as HashSet from "effect/HashSet";
|
|
8
|
+
import * as Match from "effect/Match";
|
|
9
|
+
import * as Option from "effect/Option";
|
|
10
|
+
import * as Exsolve from "exsolve";
|
|
11
|
+
import * as Schema from "effect/Schema";
|
|
12
|
+
import * as String from "effect/String";
|
|
13
|
+
import * as RegExp from "effect/RegExp";
|
|
14
|
+
import * as Jsonc from "jsonc-parser";
|
|
15
|
+
Schema.Struct({
|
|
16
|
+
path: Schema.String,
|
|
17
|
+
aliases: Schema.Array(Schema.String)
|
|
18
|
+
});
|
|
19
|
+
var DiscoveryRejected = class extends Schema.TaggedError()("TypeScriptConfigDiscoveryRejected", {
|
|
20
|
+
path: Schema.String,
|
|
21
|
+
reason: Schema.Literals(["ForbiddenFile", "NotRegularFile"])
|
|
22
|
+
}) {};
|
|
23
|
+
const NotDirectory = Schema.Struct({ code: Schema.Literal("ENOTDIR") });
|
|
24
|
+
const property = (node, key) => Match.value(node).pipe(Match.when({ type: "object" }, (object) => Array.findFirst(object.children ?? [], (entry) => Option.exists(Array.head(entry.children ?? []), (name) => name.value === key)).pipe(Option.flatMap((entry) => Array.get(entry.children ?? [], 1)), Option.getOrUndefined)), Match.orElse(() => void 0));
|
|
25
|
+
const string = (node) => Match.value(node).pipe(Match.when({ type: "string" }, (text) => Schema.decodeUnknownOption(Schema.String)(text.value)), Match.orElse(() => Option.none()));
|
|
26
|
+
const parents = (path, directory) => Array.unfold(Option.some(path.resolve(directory)), (current) => Option.map(current, (value) => [value, path.dirname(value) === value ? Option.none() : Option.some(path.dirname(value))]));
|
|
27
|
+
/**
|
|
28
|
+
* @internal
|
|
29
|
+
*/
|
|
30
|
+
const discover = Effect.fnUntraced(function* (directory) {
|
|
31
|
+
const fs = yield* FileSystem.FileSystem;
|
|
32
|
+
const path = yield* Path.Path;
|
|
33
|
+
const root = path.parse(path.resolve(directory)).root;
|
|
34
|
+
const selected = yield* Effect.findFirst(Array.filter(parents(path, directory), (candidate) => candidate !== root), (candidate) => fs.exists(path.join(candidate, "tsconfig.json"))).pipe(Effect.mapError((cause) => BundlerError.make({ cause })));
|
|
35
|
+
if (Option.isNone(selected)) return Option.none();
|
|
36
|
+
const read = Effect.fnUntraced(function* (file) {
|
|
37
|
+
const stat = yield* fs.stat(file);
|
|
38
|
+
return yield* Match.value(stat).pipe(Match.when({ type: "File" }, () => Effect.gen(function* () {
|
|
39
|
+
const real = yield* fs.realPath(file);
|
|
40
|
+
if (path.basename(file) === ".env.local" || path.basename(real) === ".env.local") return yield* DiscoveryRejected.make({
|
|
41
|
+
path: file,
|
|
42
|
+
reason: "ForbiddenFile"
|
|
43
|
+
});
|
|
44
|
+
const contents = yield* fs.readFileString(real);
|
|
45
|
+
return Option.some({
|
|
46
|
+
path: real,
|
|
47
|
+
tree: Jsonc.parseTree(contents, void 0, { allowTrailingComma: true })
|
|
48
|
+
});
|
|
49
|
+
})), Match.orElse(() => Effect.succeed(Option.none())));
|
|
50
|
+
}, Effect.catch((cause) => {
|
|
51
|
+
const fail = () => Effect.fail(BundlerError.make({ cause }));
|
|
52
|
+
return Match.value(cause).pipe(Match.tag("PlatformError", ({ reason }) => Match.value(reason).pipe(Match.when({ _tag: "NotFound" }, () => Effect.succeedNone), Match.when({ _tag: "BadResource" }, ({ cause: platformCause }) => Schema.decodeUnknownOption(NotDirectory)(platformCause).pipe(Option.match({
|
|
53
|
+
onNone: fail,
|
|
54
|
+
onSome: () => Effect.succeedNone
|
|
55
|
+
}))), Match.orElse(fail))), Match.tag("TypeScriptConfigDiscoveryRejected", fail), Match.exhaustive);
|
|
56
|
+
}));
|
|
57
|
+
const visit = (file, ancestors) => Effect.gen(function* () {
|
|
58
|
+
const source = yield* read(file);
|
|
59
|
+
if (Option.isNone(source)) return Option.none();
|
|
60
|
+
if (HashSet.has(ancestors, source.value.path)) return Option.some({ aliases: Option.none() });
|
|
61
|
+
const lineage = HashSet.add(ancestors, source.value.path);
|
|
62
|
+
const extension = property(source.value.tree, "extends");
|
|
63
|
+
const inherited = yield* Effect.forEach(Array.getSomes(Array.map(Match.value(extension).pipe(Match.when({ type: "array" }, (array) => array.children ?? []), Match.orElse((node) => [node])), string)), (value) => extend(path.dirname(source.value.path), value, lineage));
|
|
64
|
+
const paths = property(property(source.value.tree, "compilerOptions"), "paths");
|
|
65
|
+
const aliases = Match.value(paths).pipe(Match.when({ type: "object" }, (object) => Option.some(Array.getSomes(Array.map(object.children ?? [], (entry) => Option.flatMap(Array.head(entry.children ?? []), string))))), Match.orElse(() => Array.reduce(inherited, Option.none(), (previous, base) => Option.orElse(Option.flatMap(base, (config) => config.aliases), () => previous))));
|
|
66
|
+
return Option.some({ aliases });
|
|
67
|
+
});
|
|
68
|
+
const extend = (from, value, ancestors) => Effect.gen(function* () {
|
|
69
|
+
if (String.isEmpty(value)) return Option.none();
|
|
70
|
+
if (path.isAbsolute(value) || /^(?:\.{1,2}(?:[\\/]|$))/.test(value)) {
|
|
71
|
+
const file = path.resolve(from, value === "." || value === ".." ? `${value}/tsconfig.json` : value);
|
|
72
|
+
const found = yield* visit(file, ancestors);
|
|
73
|
+
return Option.isSome(found) || String.endsWith(".json")(file) ? found : yield* visit(`${file}.json`, ancestors);
|
|
74
|
+
}
|
|
75
|
+
const parts = String.split(value, "/");
|
|
76
|
+
const packageName = Array.join(Array.take(parts, String.startsWith("@")(value) ? 2 : 1), "/");
|
|
77
|
+
for (const current of parents(path, from)) {
|
|
78
|
+
if (path.basename(current) === "node_modules") continue;
|
|
79
|
+
const packageDirectory = path.join(current, "node_modules", packageName);
|
|
80
|
+
const manifestPath = path.join(packageDirectory, "package.json");
|
|
81
|
+
const manifest = yield* read(manifestPath);
|
|
82
|
+
if (Option.isSome(manifest)) {
|
|
83
|
+
const exports = property(manifest.value.tree, "exports");
|
|
84
|
+
const target = Match.value(exports).pipe(Match.whenOr({ type: "string" }, { type: "array" }, { type: "object" }, () => Option.liftThrowable(() => Exsolve.resolveModulePath(value, {
|
|
85
|
+
from: manifestPath,
|
|
86
|
+
conditions: [
|
|
87
|
+
"node",
|
|
88
|
+
"require",
|
|
89
|
+
"module"
|
|
90
|
+
],
|
|
91
|
+
cache: false
|
|
92
|
+
}))()), Match.orElse(() => Option.none()));
|
|
93
|
+
if (Option.isSome(target)) {
|
|
94
|
+
const found = yield* visit(target.value, ancestors);
|
|
95
|
+
if (Option.isSome(found)) return found;
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
const base = Option.flatMap(manifest, ({ tree }) => string(property(tree, "tsconfig"))).pipe(Option.filter(String.isNonEmpty), Option.match({
|
|
99
|
+
onNone: () => path.join(current, "node_modules", value),
|
|
100
|
+
onSome: (configPath) => path.resolve(packageDirectory, configPath)
|
|
101
|
+
}));
|
|
102
|
+
for (const file of [
|
|
103
|
+
path.join(base, "tsconfig.json"),
|
|
104
|
+
base,
|
|
105
|
+
`${base}.json`
|
|
106
|
+
]) {
|
|
107
|
+
const found = yield* visit(file, ancestors);
|
|
108
|
+
if (Option.isSome(found)) return found;
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
const legacy = Option.liftThrowable(() => NodeModule.createRequire(path.join(from, "tsconfig.json")).resolve(value))();
|
|
112
|
+
return Option.isSome(legacy) ? yield* visit(legacy.value, ancestors) : Option.none();
|
|
113
|
+
});
|
|
114
|
+
const file = path.join(selected.value, "tsconfig.json");
|
|
115
|
+
const config = yield* visit(file, HashSet.empty());
|
|
116
|
+
if (Option.isNone(config)) return yield* BundlerError.make({ cause: DiscoveryRejected.make({
|
|
117
|
+
path: file,
|
|
118
|
+
reason: "NotRegularFile"
|
|
119
|
+
}) });
|
|
120
|
+
return Option.some({
|
|
121
|
+
path: file,
|
|
122
|
+
aliases: Option.getOrElse(config.value.aliases, () => [])
|
|
123
|
+
});
|
|
124
|
+
});
|
|
125
|
+
const buildOptions = (self) => Option.match(self, {
|
|
126
|
+
onNone: () => ({ tsconfigRaw: {} }),
|
|
127
|
+
onSome: ({ path }) => ({ tsconfig: path })
|
|
128
|
+
});
|
|
129
|
+
const aliasPatterns = (self) => Array.map(Option.match(self, {
|
|
130
|
+
onNone: () => [],
|
|
131
|
+
onSome: ({ aliases }) => aliases
|
|
132
|
+
}), (alias) => new globalThis.RegExp(`^${Array.join(Array.map(String.split(alias, "*"), RegExp.escape), ".*")}$`));
|
|
133
|
+
export { aliasPatterns, buildOptions, discover };
|
|
134
|
+
|
|
135
|
+
//# sourceMappingURL=TypeScriptConfig.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"TypeScriptConfig.mjs","names":[],"sources":["../src/TypeScriptConfig.ts"],"sourcesContent":["import * as NodeModule from \"node:module\";\nimport * as Array from \"effect/Array\";\nimport * as Effect from \"effect/Effect\";\nimport * as FileSystem from \"effect/FileSystem\";\nimport * as HashSet from \"effect/HashSet\";\nimport * as Match from \"effect/Match\";\nimport * as Option from \"effect/Option\";\nimport * as Path from \"effect/Path\";\nimport type * as PlatformError from \"effect/PlatformError\";\nimport * as RegExp from \"effect/RegExp\";\nimport * as Schema from \"effect/Schema\";\nimport * as String from \"effect/String\";\nimport * as Jsonc from \"jsonc-parser\";\nimport * as Exsolve from \"exsolve\";\nimport type * as esbuild from \"esbuild\";\nimport * as BuildError from \"./BuildError.js\";\n\nexport const TypeScriptConfig = Schema.Struct({\n path: Schema.String,\n aliases: Schema.Array(Schema.String),\n});\nexport type TypeScriptConfig = typeof TypeScriptConfig.Type;\n\nclass DiscoveryRejected extends Schema.TaggedError<\n DiscoveryRejected,\n { readonly brand: unique symbol }\n>()(\"TypeScriptConfigDiscoveryRejected\", {\n path: Schema.String,\n reason: Schema.Literals([\"ForbiddenFile\", \"NotRegularFile\"]),\n}) {}\n\ninterface InheritedConfig {\n readonly aliases: Option.Option<ReadonlyArray<string>>;\n}\n\ninterface ConfigSource {\n readonly path: string;\n readonly tree: Jsonc.Node | undefined;\n}\n\nconst NotDirectory = Schema.Struct({ code: Schema.Literal(\"ENOTDIR\") });\n\nconst property = (\n node: Jsonc.Node | undefined,\n key: string,\n): Jsonc.Node | undefined =>\n Match.value(node).pipe(\n Match.when({ type: \"object\" }, (object) =>\n Array.findFirst(object.children ?? [], (entry) =>\n Option.exists(\n Array.head(entry.children ?? []),\n (name) => name.value === key,\n ),\n ).pipe(\n Option.flatMap((entry) => Array.get(entry.children ?? [], 1)),\n Option.getOrUndefined,\n ),\n ),\n Match.orElse(() => undefined),\n );\n\nconst string = (node: Jsonc.Node | undefined): Option.Option<string> =>\n Match.value(node).pipe(\n Match.when({ type: \"string\" }, (text) =>\n Schema.decodeUnknownOption(Schema.String)(text.value),\n ),\n Match.orElse(() => Option.none()),\n );\n\nconst parents = (path: Path.Path, directory: string): ReadonlyArray<string> =>\n Array.unfold(Option.some(path.resolve(directory)), (current) =>\n Option.map(\n current,\n (value) =>\n [\n value,\n path.dirname(value) === value\n ? Option.none()\n : Option.some(path.dirname(value)),\n ] as const,\n ),\n );\n\n/**\n * @internal\n */\nexport const discover = Effect.fnUntraced(function* (directory: string) {\n const fs = yield* FileSystem.FileSystem;\n const path = yield* Path.Path;\n const root = path.parse(path.resolve(directory)).root;\n const selected = yield* Effect.findFirst(\n Array.filter(parents(path, directory), (candidate) => candidate !== root),\n (candidate) => fs.exists(path.join(candidate, \"tsconfig.json\")),\n ).pipe(Effect.mapError((cause) => BuildError.BundlerError.make({ cause })));\n if (Option.isNone(selected)) return Option.none<TypeScriptConfig>();\n\n const read = Effect.fnUntraced(\n function* (file: string) {\n const stat = yield* fs.stat(file);\n return yield* Match.value(stat).pipe(\n Match.when({ type: \"File\" }, () =>\n Effect.gen(function* () {\n const real = yield* fs.realPath(file);\n if (\n path.basename(file) === \".env.local\" ||\n path.basename(real) === \".env.local\"\n )\n return yield* DiscoveryRejected.make({\n path: file,\n reason: \"ForbiddenFile\",\n });\n const contents = yield* fs.readFileString(real);\n return Option.some({\n path: real,\n tree: Jsonc.parseTree(contents, undefined, {\n allowTrailingComma: true,\n }),\n });\n }),\n ),\n Match.orElse(() => Effect.succeed(Option.none<ConfigSource>())),\n );\n },\n Effect.catch((cause: PlatformError.PlatformError | DiscoveryRejected) => {\n const fail = () => Effect.fail(BuildError.BundlerError.make({ cause }));\n return Match.value(cause).pipe(\n Match.tag(\"PlatformError\", ({ reason }) =>\n Match.value(reason).pipe(\n Match.when({ _tag: \"NotFound\" }, () => Effect.succeedNone),\n Match.when({ _tag: \"BadResource\" }, ({ cause: platformCause }) =>\n Schema.decodeUnknownOption(NotDirectory)(platformCause).pipe(\n Option.match({\n onNone: fail,\n onSome: () => Effect.succeedNone,\n }),\n ),\n ),\n Match.orElse(fail),\n ),\n ),\n Match.tag(\"TypeScriptConfigDiscoveryRejected\", fail),\n Match.exhaustive,\n );\n }),\n );\n\n const visit = (\n file: string,\n ancestors: HashSet.HashSet<string>,\n ): Effect.Effect<Option.Option<InheritedConfig>, BuildError.BundlerError> =>\n Effect.gen(function* () {\n const source = yield* read(file);\n if (Option.isNone(source)) return Option.none();\n if (HashSet.has(ancestors, source.value.path))\n return Option.some({ aliases: Option.none() });\n const lineage = HashSet.add(ancestors, source.value.path);\n const extension = property(source.value.tree, \"extends\");\n const inherited = yield* Effect.forEach(\n Array.getSomes(\n Array.map(\n Match.value(extension).pipe(\n Match.when({ type: \"array\" }, (array) => array.children ?? []),\n Match.orElse((node) => [node]),\n ),\n string,\n ),\n ),\n (value) => extend(path.dirname(source.value.path), value, lineage),\n );\n const paths = property(\n property(source.value.tree, \"compilerOptions\"),\n \"paths\",\n );\n const aliases = Match.value(paths).pipe(\n Match.when({ type: \"object\" }, (object) =>\n Option.some(\n Array.getSomes(\n Array.map(object.children ?? [], (entry) =>\n Option.flatMap(Array.head(entry.children ?? []), string),\n ),\n ),\n ),\n ),\n Match.orElse(() =>\n Array.reduce(\n inherited,\n Option.none<ReadonlyArray<string>>(),\n (previous, base) =>\n Option.orElse(\n Option.flatMap(base, (config) => config.aliases),\n () => previous,\n ),\n ),\n ),\n );\n return Option.some({ aliases });\n });\n\n const extend = (\n from: string,\n value: string,\n ancestors: HashSet.HashSet<string>,\n ): Effect.Effect<Option.Option<InheritedConfig>, BuildError.BundlerError> =>\n Effect.gen(function* () {\n if (String.isEmpty(value)) return Option.none();\n if (path.isAbsolute(value) || /^(?:\\.{1,2}(?:[\\\\/]|$))/.test(value)) {\n const file = path.resolve(\n from,\n value === \".\" || value === \"..\" ? `${value}/tsconfig.json` : value,\n );\n const found = yield* visit(file, ancestors);\n return Option.isSome(found) || String.endsWith(\".json\")(file)\n ? found\n : yield* visit(`${file}.json`, ancestors);\n }\n const parts = String.split(value, \"/\");\n const packageName = Array.join(\n Array.take(parts, String.startsWith(\"@\")(value) ? 2 : 1),\n \"/\",\n );\n for (const current of parents(path, from)) {\n if (path.basename(current) === \"node_modules\") continue;\n const packageDirectory = path.join(\n current,\n \"node_modules\",\n packageName,\n );\n const manifestPath = path.join(packageDirectory, \"package.json\");\n const manifest = yield* read(manifestPath);\n if (Option.isSome(manifest)) {\n const exports = property(manifest.value.tree, \"exports\");\n const target = Match.value(exports).pipe(\n Match.whenOr(\n { type: \"string\" },\n { type: \"array\" },\n { type: \"object\" },\n () =>\n Option.liftThrowable(() =>\n Exsolve.resolveModulePath(value, {\n from: manifestPath,\n conditions: [\"node\", \"require\", \"module\"],\n cache: false,\n }),\n )(),\n ),\n Match.orElse(() => Option.none()),\n );\n if (Option.isSome(target)) {\n const found = yield* visit(target.value, ancestors);\n if (Option.isSome(found)) return found;\n }\n }\n const base = Option.flatMap(manifest, ({ tree }) =>\n string(property(tree, \"tsconfig\")),\n ).pipe(\n Option.filter(String.isNonEmpty),\n Option.match({\n onNone: () => path.join(current, \"node_modules\", value),\n onSome: (configPath) => path.resolve(packageDirectory, configPath),\n }),\n );\n for (const file of [\n path.join(base, \"tsconfig.json\"),\n base,\n `${base}.json`,\n ]) {\n const found = yield* visit(file, ancestors);\n if (Option.isSome(found)) return found;\n }\n }\n const legacy = Option.liftThrowable(() =>\n NodeModule.createRequire(path.join(from, \"tsconfig.json\")).resolve(\n value,\n ),\n )();\n return Option.isSome(legacy)\n ? yield* visit(legacy.value, ancestors)\n : Option.none();\n });\n\n const file = path.join(selected.value, \"tsconfig.json\");\n const config = yield* visit(file, HashSet.empty());\n if (Option.isNone(config))\n return yield* BuildError.BundlerError.make({\n cause: DiscoveryRejected.make({ path: file, reason: \"NotRegularFile\" }),\n });\n return Option.some({\n path: file,\n aliases: Option.getOrElse(config.value.aliases, () => []),\n });\n});\n\nexport const buildOptions = (\n self: Option.Option<TypeScriptConfig>,\n): Pick<esbuild.BuildOptions, \"tsconfig\" | \"tsconfigRaw\"> =>\n Option.match(self, {\n onNone: () => ({ tsconfigRaw: {} }),\n onSome: ({ path }) => ({ tsconfig: path }),\n });\n\nexport const aliasPatterns = (\n self: Option.Option<TypeScriptConfig>,\n): ReadonlyArray<globalThis.RegExp> =>\n Array.map(\n Option.match(self, { onNone: () => [], onSome: ({ aliases }) => aliases }),\n (alias) =>\n new globalThis.RegExp(\n `^${Array.join(Array.map(String.split(alias, \"*\"), RegExp.escape), \".*\")}$`,\n ),\n );\n"],"mappings":";;;;;;;;;;;;;;AAiBgC,OAAO,OAAO;CAC5C,MAAM,OAAO;CACb,SAAS,OAAO,MAAM,OAAO,MAAM;AACrC,CAAC;AAGD,IAAM,oBAAN,cAAgC,OAAO,YAGrC,CAAC,CAAC,qCAAqC;CACvC,MAAM,OAAO;CACb,QAAQ,OAAO,SAAS,CAAC,iBAAiB,gBAAgB,CAAC;AAC7D,CAAC,CAAC,CAAC,CAAC;AAWJ,MAAM,eAAe,OAAO,OAAO,EAAE,MAAM,OAAO,QAAQ,SAAS,EAAE,CAAC;AAEtE,MAAM,YACJ,MACA,QAEA,MAAM,MAAM,IAA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IAAI,OAAO,MAAM,OAAO,GAAG,GAAG,OAAO,MAAM,GAAG,IAAI,EAAE,EAC3E,CACJ"}
|
package/dist/WatchBuild.mjs
CHANGED
|
@@ -1,22 +1,71 @@
|
|
|
1
1
|
import { affected, make } from "./WatchGraph.mjs";
|
|
2
2
|
import * as Effect from "effect/Effect";
|
|
3
3
|
import * as Array from "effect/Array";
|
|
4
|
-
import * as Result from "effect/Result";
|
|
5
4
|
import * as HashSet from "effect/HashSet";
|
|
6
5
|
import * as Match from "effect/Match";
|
|
7
6
|
import * as Option from "effect/Option";
|
|
8
7
|
import * as HashMap from "effect/HashMap";
|
|
8
|
+
import * as String from "effect/String";
|
|
9
9
|
import * as Brand from "effect/Brand";
|
|
10
10
|
import * as Data from "effect/Data";
|
|
11
11
|
import * as Equal from "effect/Equal";
|
|
12
|
+
import * as Digest from "effect/crypto/Digest";
|
|
12
13
|
import * as Hex from "effect/encoding/Hex";
|
|
13
|
-
|
|
14
|
+
// src/WatchBuild.ts
|
|
15
|
+
/**
|
|
16
|
+
* @internal
|
|
17
|
+
*/
|
|
14
18
|
const Failure = Data.taggedEnum();
|
|
19
|
+
/**
|
|
20
|
+
* @internal
|
|
21
|
+
*/
|
|
15
22
|
const emptyCapture = {
|
|
16
23
|
fingerprints: HashMap.empty(),
|
|
17
24
|
failures: HashMap.empty()
|
|
18
25
|
};
|
|
26
|
+
/**
|
|
27
|
+
* @internal
|
|
28
|
+
*/
|
|
19
29
|
const Outcome = Data.taggedEnum();
|
|
30
|
+
/**
|
|
31
|
+
* @internal
|
|
32
|
+
*/
|
|
33
|
+
const combine = (outcomes) => {
|
|
34
|
+
if (outcomes.length === 1) return Array.headNonEmpty(outcomes);
|
|
35
|
+
const combined = Array.reduce(outcomes, {
|
|
36
|
+
fingerprints: HashMap.empty(),
|
|
37
|
+
graph: HashMap.empty(),
|
|
38
|
+
hashes: [],
|
|
39
|
+
failures: [],
|
|
40
|
+
warnings: []
|
|
41
|
+
}, (state, outcome) => Outcome.$match(outcome, {
|
|
42
|
+
Failed: ({ fingerprints, failures, warnings }) => ({
|
|
43
|
+
...state,
|
|
44
|
+
fingerprints: HashMap.union(state.fingerprints, fingerprints),
|
|
45
|
+
failures: [...state.failures, ...failures],
|
|
46
|
+
warnings: [...state.warnings, ...warnings]
|
|
47
|
+
}),
|
|
48
|
+
Succeeded: ({ snapshot, warnings }) => ({
|
|
49
|
+
...state,
|
|
50
|
+
fingerprints: HashMap.union(state.fingerprints, snapshot.fingerprints),
|
|
51
|
+
graph: Array.reduce(snapshot.graph, state.graph, (graph, [file, importers]) => HashMap.set(graph, file, HashSet.union(Option.getOrElse(HashMap.get(graph, file), () => HashSet.empty()), importers))),
|
|
52
|
+
hashes: [...state.hashes, snapshot.outputHash],
|
|
53
|
+
warnings: [...state.warnings, ...warnings]
|
|
54
|
+
})
|
|
55
|
+
}));
|
|
56
|
+
return Array.isReadonlyArrayNonEmpty(combined.failures) ? Outcome.Failed({
|
|
57
|
+
fingerprints: combined.fingerprints,
|
|
58
|
+
failures: combined.failures,
|
|
59
|
+
warnings: combined.warnings
|
|
60
|
+
}) : Outcome.Succeeded({
|
|
61
|
+
snapshot: {
|
|
62
|
+
fingerprints: combined.fingerprints,
|
|
63
|
+
graph: combined.graph,
|
|
64
|
+
outputHash: Array.join(combined.hashes, ":")
|
|
65
|
+
},
|
|
66
|
+
warnings: combined.warnings
|
|
67
|
+
});
|
|
68
|
+
};
|
|
20
69
|
const Generation = Brand.nominal();
|
|
21
70
|
const Barrier = Brand.nominal();
|
|
22
71
|
const RequestId = Brand.nominal();
|
|
@@ -58,19 +107,34 @@ const endRequest = (progress) => ({
|
|
|
58
107
|
request: Request.Idle()
|
|
59
108
|
});
|
|
60
109
|
const isFresh = (barrier, completion) => completion.generation > barrier;
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
110
|
+
/**
|
|
111
|
+
* @internal
|
|
112
|
+
*/
|
|
113
|
+
const verifyInputs = Effect.fn("WatchBuild.verifyInputs")(function* (snapshot, fs, digest) {
|
|
114
|
+
const matches = yield* Effect.forEach(snapshot.fingerprints, ([file, expected]) => fs.readFile(file).pipe(Effect.flatMap((contents) => digest.digest(Digest.sha256, contents)), Effect.mapBoth({
|
|
115
|
+
onSuccess: (hash) => Hex.encode(hash) === expected,
|
|
116
|
+
onFailure: (cause) => Failure.InputCaptureFailed({
|
|
117
|
+
file,
|
|
118
|
+
cause
|
|
119
|
+
})
|
|
120
|
+
})), { concurrency: 8 });
|
|
66
121
|
return Array.every(matches, (matchesInput) => matchesInput);
|
|
67
122
|
});
|
|
123
|
+
/**
|
|
124
|
+
* @internal
|
|
125
|
+
*/
|
|
68
126
|
const State = Data.taggedEnum();
|
|
127
|
+
/**
|
|
128
|
+
* @internal
|
|
129
|
+
*/
|
|
69
130
|
const lastSuccessful = (state) => State.$match(state, {
|
|
70
131
|
Initial: () => Option.none(),
|
|
71
132
|
Succeeded: ({ snapshot }) => Option.some(snapshot),
|
|
72
133
|
Failed: ({ lastSuccessful: snapshot }) => snapshot
|
|
73
134
|
});
|
|
135
|
+
/**
|
|
136
|
+
* @internal
|
|
137
|
+
*/
|
|
74
138
|
const observe = (previous, outcome) => Outcome.$match(outcome, {
|
|
75
139
|
Succeeded: ({ snapshot, warnings }) => State.Succeeded({
|
|
76
140
|
snapshot,
|
|
@@ -79,32 +143,41 @@ const observe = (previous, outcome) => Outcome.$match(outcome, {
|
|
|
79
143
|
Failed: (observation) => State.Failed({
|
|
80
144
|
observation,
|
|
81
145
|
lastSuccessful: lastSuccessful(previous),
|
|
82
|
-
discovered: State.$is("Initial")(previous) ? HashSet.empty() : HashSet.union(State.$is("Failed")(previous) ? previous.discovered : HashSet.empty(), HashSet.difference(
|
|
146
|
+
discovered: State.$is("Initial")(previous) ? HashSet.empty() : HashSet.union(State.$is("Failed")(previous) ? previous.discovered : HashSet.empty(), HashSet.difference(observation.fingerprints.pipe(HashMap.keys, HashSet.fromIterable), fingerprints(previous).pipe(HashMap.keys, HashSet.fromIterable)))
|
|
83
147
|
})
|
|
84
148
|
});
|
|
149
|
+
/**
|
|
150
|
+
* @internal
|
|
151
|
+
*/
|
|
85
152
|
const fingerprints = (state) => State.$match(state, {
|
|
86
153
|
Initial: () => HashMap.empty(),
|
|
87
154
|
Succeeded: ({ snapshot }) => snapshot.fingerprints,
|
|
88
155
|
Failed: ({ observation }) => observation.fingerprints
|
|
89
156
|
});
|
|
157
|
+
/**
|
|
158
|
+
* @internal
|
|
159
|
+
*/
|
|
90
160
|
const outputHash = (state) => State.$match(state, {
|
|
91
161
|
Initial: () => Option.none(),
|
|
92
162
|
Succeeded: ({ snapshot }) => Option.some(snapshot.outputHash),
|
|
93
163
|
Failed: () => Option.none()
|
|
94
164
|
});
|
|
95
165
|
const Change = Data.taggedEnum();
|
|
166
|
+
/**
|
|
167
|
+
* @internal
|
|
168
|
+
*/
|
|
96
169
|
const diff = (previous, current, generatedDirectoryPrefix) => {
|
|
97
170
|
const previousFingerprints = fingerprints(previous);
|
|
98
171
|
const currentFingerprints = fingerprints(current);
|
|
99
|
-
const files = HashSet.union(
|
|
100
|
-
const changed = Array.fromIterable(files)
|
|
101
|
-
const sources =
|
|
172
|
+
const files = HashSet.union(previousFingerprints.pipe(HashMap.keys, HashSet.fromIterable), currentFingerprints.pipe(HashMap.keys, HashSet.fromIterable));
|
|
173
|
+
const changed = Array.filter(Array.fromIterable(files), (file) => !Equal.equals(HashMap.get(previousFingerprints, file), HashMap.get(currentFingerprints, file)));
|
|
174
|
+
const sources = Array.filter(changed, (file) => !String.startsWith(generatedDirectoryPrefix)(file));
|
|
102
175
|
const recovered = State.$is("Failed")(previous) && State.$is("Succeeded")(current);
|
|
103
176
|
const untrackedOutput = recovered ? Option.match(lastSuccessful(previous), {
|
|
104
177
|
onNone: () => false,
|
|
105
178
|
onSome: (baseline) => Equal.equals(baseline.fingerprints, currentFingerprints) && !Equal.equals(Option.some(baseline.outputHash), outputHash(current))
|
|
106
179
|
}) : changed.length === 0 && !Equal.equals(outputHash(previous), outputHash(current));
|
|
107
|
-
if (State.$is("Initial")(previous) ||
|
|
180
|
+
if (State.$is("Initial")(previous) || Array.some(sources, (file) => HashMap.has(previousFingerprints, file)) && State.$is("Failed")(current) || untrackedOutput) return Change.Full();
|
|
108
181
|
const graph = Option.match(lastSuccessful(current), {
|
|
109
182
|
onNone: () => HashMap.empty(),
|
|
110
183
|
onSome: (snapshot) => snapshot.graph
|
|
@@ -113,55 +186,55 @@ const diff = (previous, current, generatedDirectoryPrefix) => {
|
|
|
113
186
|
onNone: () => HashMap.empty(),
|
|
114
187
|
onSome: (snapshot) => snapshot.graph
|
|
115
188
|
});
|
|
116
|
-
const affectedSources = recovered && State.$is("Failed")(previous) ? Array.fromIterable(HashSet.union(HashSet.fromIterable(sources), HashSet.filter(previous.discovered, (file) => !
|
|
189
|
+
const affectedSources = recovered && State.$is("Failed")(previous) ? Array.fromIterable(HashSet.union(HashSet.fromIterable(sources), HashSet.filter(previous.discovered, (file) => !String.startsWith(generatedDirectoryPrefix)(file)))) : sources;
|
|
117
190
|
const paths = HashSet.union(affected(graph, affectedSources), affected(previousGraph, affectedSources));
|
|
118
191
|
return recovered ? Change.Recovered({ paths }) : Change.Affected({ paths });
|
|
119
192
|
};
|
|
120
|
-
|
|
121
|
-
|
|
193
|
+
/**
|
|
194
|
+
* @internal
|
|
195
|
+
*/
|
|
196
|
+
const parse = Effect.fn("WatchBuild.parse")(function* (result, capture, resolve, digest) {
|
|
197
|
+
const failures = capture.failures.pipe(HashMap.values, Array.fromIterable);
|
|
122
198
|
if (Array.isReadonlyArrayNonEmpty(result.errors)) failures.push(Failure.BuildFailed({ errors: result.errors }));
|
|
123
199
|
if (Array.isReadonlyArrayNonEmpty(failures)) return Outcome.Failed({
|
|
124
200
|
fingerprints: capture.fingerprints,
|
|
125
201
|
failures,
|
|
126
202
|
warnings: result.warnings
|
|
127
203
|
});
|
|
128
|
-
if (
|
|
204
|
+
if (result.metafile === void 0) return Outcome.Failed({
|
|
129
205
|
fingerprints: capture.fingerprints,
|
|
130
206
|
failures: [Failure.InvalidBuildResult({ missing: "metafile" })],
|
|
131
207
|
warnings: result.warnings
|
|
132
208
|
});
|
|
133
|
-
if (
|
|
209
|
+
if (result.outputFiles === void 0 || !Array.isReadonlyArrayNonEmpty(result.outputFiles)) return Outcome.Failed({
|
|
134
210
|
fingerprints: capture.fingerprints,
|
|
135
211
|
failures: [Failure.InvalidBuildResult({ missing: "outputFiles" })],
|
|
136
212
|
warnings: result.warnings
|
|
137
213
|
});
|
|
138
|
-
const hashes = yield* Effect.forEach(result.outputFiles, (file) =>
|
|
139
|
-
file: file.path,
|
|
140
|
-
cause
|
|
141
|
-
})))).pipe(Effect.result);
|
|
142
|
-
if (Result.isFailure(hashes)) return Outcome.Failed({
|
|
143
|
-
fingerprints: capture.fingerprints,
|
|
144
|
-
failures: [hashes.failure],
|
|
145
|
-
warnings: result.warnings
|
|
146
|
-
});
|
|
214
|
+
const hashes = yield* Effect.forEach(result.outputFiles, (file) => digest.digest(Digest.sha256, file.contents).pipe(Effect.map(Hex.encode)));
|
|
147
215
|
return Outcome.Succeeded({
|
|
148
216
|
snapshot: {
|
|
149
217
|
fingerprints: capture.fingerprints,
|
|
150
218
|
graph: make(result.metafile, resolve),
|
|
151
|
-
outputHash:
|
|
219
|
+
outputHash: Array.join(hashes, ":")
|
|
152
220
|
},
|
|
153
221
|
warnings: result.warnings
|
|
154
222
|
});
|
|
155
223
|
});
|
|
224
|
+
/**
|
|
225
|
+
* @internal
|
|
226
|
+
*/
|
|
156
227
|
const failureMessage = (failure) => Failure.$match(failure, {
|
|
157
|
-
BuildFailed: ({ errors }) =>
|
|
228
|
+
BuildFailed: ({ errors }) => Array.join(Array.map(errors, (error) => error.text), "\n"),
|
|
158
229
|
InputCaptureFailed: ({ file, cause }) => `Could not fingerprint input ${file}: ${cause.message}`,
|
|
159
|
-
OutputCaptureFailed: ({ file, cause }) => `Could not fingerprint output ${file}: ${cause.message}`,
|
|
160
230
|
InvalidBuildResult: ({ missing }) => `esbuild completed without ${missing}`
|
|
161
231
|
});
|
|
232
|
+
/**
|
|
233
|
+
* @internal
|
|
234
|
+
*/
|
|
162
235
|
const messages = (outcome) => Outcome.$match(outcome, {
|
|
163
236
|
Succeeded: () => [],
|
|
164
|
-
Failed: ({ failures }) =>
|
|
237
|
+
Failed: ({ failures }) => Array.flatMap(failures, (failure) => Match.value(failure).pipe(Match.tag("BuildFailed", ({ errors }) => errors), Match.tag("InputCaptureFailed", "InvalidBuildResult", (captureFailure) => [{
|
|
165
238
|
id: "confect-watch",
|
|
166
239
|
pluginName: "confect",
|
|
167
240
|
text: failureMessage(captureFailure),
|
|
@@ -170,6 +243,9 @@ const messages = (outcome) => Outcome.$match(outcome, {
|
|
|
170
243
|
detail: captureFailure
|
|
171
244
|
}]), Match.exhaustive))
|
|
172
245
|
});
|
|
246
|
+
/**
|
|
247
|
+
* @internal
|
|
248
|
+
*/
|
|
173
249
|
const diagnostics = (state) => State.$match(state, {
|
|
174
250
|
Initial: () => ({
|
|
175
251
|
errors: [],
|
|
@@ -184,7 +260,6 @@ const diagnostics = (state) => State.$match(state, {
|
|
|
184
260
|
warnings: observation.warnings
|
|
185
261
|
})
|
|
186
262
|
});
|
|
187
|
-
|
|
188
|
-
export { Change, Failure, Outcome, State, captureBarrier, complete, diagnostics, diff, emptyCapture, endRequest, failureMessage, fingerprints, getCompletion, initialProgress, isFresh, joinedWithoutCompletion, lastSuccessful, makeRequestId, messages, observe, outputHash, parse, request, start, verifyInputs };
|
|
263
|
+
export { Change, Failure, Outcome, State, captureBarrier, combine, complete, diagnostics, diff, emptyCapture, endRequest, failureMessage, fingerprints, getCompletion, initialProgress, isFresh, joinedWithoutCompletion, lastSuccessful, makeRequestId, messages, observe, outputHash, parse, request, start, verifyInputs };
|
|
189
264
|
|
|
190
265
|
//# sourceMappingURL=WatchBuild.mjs.map
|