plgg-bundle 0.0.1
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/README.md +68 -0
- package/bin/appAliasHook.mjs +89 -0
- package/bin/hook.mjs +94 -0
- package/bin/plgg-bundle.mjs +16 -0
- package/dist/Dev/fixtures/devPoc.spec.d.ts +2 -0
- package/dist/Dev/fixtures/devPoc.spec.d.ts.map +1 -0
- package/dist/Dev/fixtures/devPoc.spec.js +145 -0
- package/dist/Dev/fixtures/devPoc.spec.js.map +1 -0
- package/dist/Dev/model/Fetch.d.ts +20 -0
- package/dist/Dev/model/Fetch.d.ts.map +1 -0
- package/dist/Dev/model/Fetch.js +8 -0
- package/dist/Dev/model/Fetch.js.map +1 -0
- package/dist/Dev/model/ModuleGraph.d.ts +27 -0
- package/dist/Dev/model/ModuleGraph.d.ts.map +1 -0
- package/dist/Dev/model/ModuleGraph.js +2 -0
- package/dist/Dev/model/ModuleGraph.js.map +1 -0
- package/dist/Dev/model/Protocol.d.ts +22 -0
- package/dist/Dev/model/Protocol.d.ts.map +1 -0
- package/dist/Dev/model/Protocol.js +31 -0
- package/dist/Dev/model/Protocol.js.map +1 -0
- package/dist/Dev/node/devServer.d.ts +21 -0
- package/dist/Dev/node/devServer.d.ts.map +1 -0
- package/dist/Dev/node/devServer.js +298 -0
- package/dist/Dev/node/devServer.js.map +1 -0
- package/dist/Dev/node/httpAdapter.d.ts +19 -0
- package/dist/Dev/node/httpAdapter.d.ts.map +1 -0
- package/dist/Dev/node/httpAdapter.js +76 -0
- package/dist/Dev/node/httpAdapter.js.map +1 -0
- package/dist/Dev/node/scanGraph.d.ts +21 -0
- package/dist/Dev/node/scanGraph.d.ts.map +1 -0
- package/dist/Dev/node/scanGraph.js +145 -0
- package/dist/Dev/node/scanGraph.js.map +1 -0
- package/dist/Dev/node/watch.d.ts +10 -0
- package/dist/Dev/node/watch.d.ts.map +1 -0
- package/dist/Dev/node/watch.js +44 -0
- package/dist/Dev/node/watch.js.map +1 -0
- package/dist/Dev/usecase/allowedHost.d.ts +16 -0
- package/dist/Dev/usecase/allowedHost.d.ts.map +1 -0
- package/dist/Dev/usecase/allowedHost.js +33 -0
- package/dist/Dev/usecase/allowedHost.js.map +1 -0
- package/dist/Dev/usecase/allowedHost.spec.d.ts +2 -0
- package/dist/Dev/usecase/allowedHost.spec.d.ts.map +1 -0
- package/dist/Dev/usecase/allowedHost.spec.js +13 -0
- package/dist/Dev/usecase/allowedHost.spec.js.map +1 -0
- package/dist/Dev/usecase/buildGraph.d.ts +12 -0
- package/dist/Dev/usecase/buildGraph.d.ts.map +1 -0
- package/dist/Dev/usecase/buildGraph.js +24 -0
- package/dist/Dev/usecase/buildGraph.js.map +1 -0
- package/dist/Dev/usecase/buildGraph.spec.d.ts +2 -0
- package/dist/Dev/usecase/buildGraph.spec.d.ts.map +1 -0
- package/dist/Dev/usecase/buildGraph.spec.js +16 -0
- package/dist/Dev/usecase/buildGraph.spec.js.map +1 -0
- package/dist/Dev/usecase/decorateDevHtml.d.ts +12 -0
- package/dist/Dev/usecase/decorateDevHtml.d.ts.map +1 -0
- package/dist/Dev/usecase/decorateDevHtml.js +15 -0
- package/dist/Dev/usecase/decorateDevHtml.js.map +1 -0
- package/dist/Dev/usecase/decorateDevHtml.spec.d.ts +2 -0
- package/dist/Dev/usecase/decorateDevHtml.spec.d.ts.map +1 -0
- package/dist/Dev/usecase/decorateDevHtml.spec.js +19 -0
- package/dist/Dev/usecase/decorateDevHtml.spec.js.map +1 -0
- package/dist/Dev/usecase/invalidate.d.ts +17 -0
- package/dist/Dev/usecase/invalidate.d.ts.map +1 -0
- package/dist/Dev/usecase/invalidate.js +57 -0
- package/dist/Dev/usecase/invalidate.js.map +1 -0
- package/dist/Dev/usecase/invalidate.spec.d.ts +2 -0
- package/dist/Dev/usecase/invalidate.spec.d.ts.map +1 -0
- package/dist/Dev/usecase/invalidate.spec.js +64 -0
- package/dist/Dev/usecase/invalidate.spec.js.map +1 -0
- package/dist/Dev/usecase/parseImports.d.ts +24 -0
- package/dist/Dev/usecase/parseImports.d.ts.map +1 -0
- package/dist/Dev/usecase/parseImports.js +40 -0
- package/dist/Dev/usecase/parseImports.js.map +1 -0
- package/dist/Dev/usecase/parseImports.spec.d.ts +2 -0
- package/dist/Dev/usecase/parseImports.spec.d.ts.map +1 -0
- package/dist/Dev/usecase/parseImports.spec.js +24 -0
- package/dist/Dev/usecase/parseImports.spec.js.map +1 -0
- package/dist/Dev/usecase/reloadDecision.d.ts +20 -0
- package/dist/Dev/usecase/reloadDecision.d.ts.map +1 -0
- package/dist/Dev/usecase/reloadDecision.js +52 -0
- package/dist/Dev/usecase/reloadDecision.js.map +1 -0
- package/dist/Dev/usecase/reloadDecision.spec.d.ts +2 -0
- package/dist/Dev/usecase/reloadDecision.spec.d.ts.map +1 -0
- package/dist/Dev/usecase/reloadDecision.spec.js +17 -0
- package/dist/Dev/usecase/reloadDecision.spec.js.map +1 -0
- package/dist/domain/model/BundleConfig.d.ts +136 -0
- package/dist/domain/model/BundleConfig.d.ts.map +1 -0
- package/dist/domain/model/BundleConfig.js +18 -0
- package/dist/domain/model/BundleConfig.js.map +1 -0
- package/dist/domain/model/BundleConfig.spec.d.ts +2 -0
- package/dist/domain/model/BundleConfig.spec.d.ts.map +1 -0
- package/dist/domain/model/BundleConfig.spec.js +8 -0
- package/dist/domain/model/BundleConfig.spec.js.map +1 -0
- package/dist/domain/usecase/asBundleConfig.d.ts +17 -0
- package/dist/domain/usecase/asBundleConfig.d.ts.map +1 -0
- package/dist/domain/usecase/asBundleConfig.js +179 -0
- package/dist/domain/usecase/asBundleConfig.js.map +1 -0
- package/dist/domain/usecase/asBundleConfig.spec.d.ts +2 -0
- package/dist/domain/usecase/asBundleConfig.spec.d.ts.map +1 -0
- package/dist/domain/usecase/asBundleConfig.spec.js +119 -0
- package/dist/domain/usecase/asBundleConfig.spec.js.map +1 -0
- package/dist/domain/usecase/build.d.ts +14 -0
- package/dist/domain/usecase/build.d.ts.map +1 -0
- package/dist/domain/usecase/build.js +177 -0
- package/dist/domain/usecase/build.js.map +1 -0
- package/dist/domain/usecase/collectModules.d.ts +53 -0
- package/dist/domain/usecase/collectModules.d.ts.map +1 -0
- package/dist/domain/usecase/collectModules.js +118 -0
- package/dist/domain/usecase/collectModules.js.map +1 -0
- package/dist/domain/usecase/deriveExternal.d.ts +25 -0
- package/dist/domain/usecase/deriveExternal.d.ts.map +1 -0
- package/dist/domain/usecase/deriveExternal.js +79 -0
- package/dist/domain/usecase/deriveExternal.js.map +1 -0
- package/dist/domain/usecase/deriveExternal.spec.d.ts +2 -0
- package/dist/domain/usecase/deriveExternal.spec.d.ts.map +1 -0
- package/dist/domain/usecase/deriveExternal.spec.js +56 -0
- package/dist/domain/usecase/deriveExternal.spec.js.map +1 -0
- package/dist/domain/usecase/discoverWorkspace.d.ts +27 -0
- package/dist/domain/usecase/discoverWorkspace.d.ts.map +1 -0
- package/dist/domain/usecase/discoverWorkspace.js +116 -0
- package/dist/domain/usecase/discoverWorkspace.js.map +1 -0
- package/dist/domain/usecase/discoverWorkspace.spec.d.ts +2 -0
- package/dist/domain/usecase/discoverWorkspace.spec.d.ts.map +1 -0
- package/dist/domain/usecase/discoverWorkspace.spec.js +23 -0
- package/dist/domain/usecase/discoverWorkspace.spec.js.map +1 -0
- package/dist/domain/usecase/emitBundle.d.ts +43 -0
- package/dist/domain/usecase/emitBundle.d.ts.map +1 -0
- package/dist/domain/usecase/emitBundle.js +157 -0
- package/dist/domain/usecase/emitBundle.js.map +1 -0
- package/dist/domain/usecase/emitBundle.spec.d.ts +2 -0
- package/dist/domain/usecase/emitBundle.spec.d.ts.map +1 -0
- package/dist/domain/usecase/emitBundle.spec.js +80 -0
- package/dist/domain/usecase/emitBundle.spec.js.map +1 -0
- package/dist/domain/usecase/emitDts.d.ts +32 -0
- package/dist/domain/usecase/emitDts.d.ts.map +1 -0
- package/dist/domain/usecase/emitDts.js +99 -0
- package/dist/domain/usecase/emitDts.js.map +1 -0
- package/dist/domain/usecase/isExternal.d.ts +12 -0
- package/dist/domain/usecase/isExternal.d.ts.map +1 -0
- package/dist/domain/usecase/isExternal.js +16 -0
- package/dist/domain/usecase/isExternal.js.map +1 -0
- package/dist/domain/usecase/isExternal.spec.d.ts +2 -0
- package/dist/domain/usecase/isExternal.spec.d.ts.map +1 -0
- package/dist/domain/usecase/isExternal.spec.js +16 -0
- package/dist/domain/usecase/isExternal.spec.js.map +1 -0
- package/dist/domain/usecase/resolveSpecifier.d.ts +35 -0
- package/dist/domain/usecase/resolveSpecifier.d.ts.map +1 -0
- package/dist/domain/usecase/resolveSpecifier.js +83 -0
- package/dist/domain/usecase/resolveSpecifier.js.map +1 -0
- package/dist/domain/usecase/resolveSpecifier.spec.d.ts +2 -0
- package/dist/domain/usecase/resolveSpecifier.spec.d.ts.map +1 -0
- package/dist/domain/usecase/resolveSpecifier.spec.js +44 -0
- package/dist/domain/usecase/resolveSpecifier.spec.js.map +1 -0
- package/dist/domain/usecase/resolveWorkspaceSpecifier.d.ts +29 -0
- package/dist/domain/usecase/resolveWorkspaceSpecifier.d.ts.map +1 -0
- package/dist/domain/usecase/resolveWorkspaceSpecifier.js +89 -0
- package/dist/domain/usecase/resolveWorkspaceSpecifier.js.map +1 -0
- package/dist/domain/usecase/resolveWorkspaceSpecifier.spec.d.ts +2 -0
- package/dist/domain/usecase/resolveWorkspaceSpecifier.spec.d.ts.map +1 -0
- package/dist/domain/usecase/resolveWorkspaceSpecifier.spec.js +27 -0
- package/dist/domain/usecase/resolveWorkspaceSpecifier.spec.js.map +1 -0
- package/dist/domain/usecase/rewriteDtsAliases.d.ts +25 -0
- package/dist/domain/usecase/rewriteDtsAliases.d.ts.map +1 -0
- package/dist/domain/usecase/rewriteDtsAliases.js +71 -0
- package/dist/domain/usecase/rewriteDtsAliases.js.map +1 -0
- package/dist/domain/usecase/rewriteDtsAliases.spec.d.ts +2 -0
- package/dist/domain/usecase/rewriteDtsAliases.spec.d.ts.map +1 -0
- package/dist/domain/usecase/rewriteDtsAliases.spec.js +35 -0
- package/dist/domain/usecase/rewriteDtsAliases.spec.js.map +1 -0
- package/dist/entrypoints/cli.d.ts +2 -0
- package/dist/entrypoints/cli.d.ts.map +1 -0
- package/dist/entrypoints/cli.js +79 -0
- package/dist/entrypoints/cli.js.map +1 -0
- package/dist/index.d.ts +21 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +28 -0
- package/dist/index.js.map +1 -0
- package/dist/vendors/runner.d.ts +20 -0
- package/dist/vendors/runner.d.ts.map +1 -0
- package/dist/vendors/runner.js +60 -0
- package/dist/vendors/runner.js.map +1 -0
- package/dist/vendors/runner.spec.d.ts +2 -0
- package/dist/vendors/runner.spec.d.ts.map +1 -0
- package/dist/vendors/runner.spec.js +20 -0
- package/dist/vendors/runner.spec.js.map +1 -0
- package/dist/vendors/transpiler.d.ts +19 -0
- package/dist/vendors/transpiler.d.ts.map +1 -0
- package/dist/vendors/transpiler.js +42 -0
- package/dist/vendors/transpiler.js.map +1 -0
- package/package.json +31 -0
- package/src/Dev/fixtures/devPoc.spec.ts +235 -0
- package/src/Dev/model/Fetch.ts +31 -0
- package/src/Dev/model/ModuleGraph.ts +30 -0
- package/src/Dev/model/Protocol.ts +35 -0
- package/src/Dev/node/devServer.ts +503 -0
- package/src/Dev/node/httpAdapter.ts +162 -0
- package/src/Dev/node/scanGraph.ts +203 -0
- package/src/Dev/node/watch.ts +54 -0
- package/src/Dev/usecase/allowedHost.spec.ts +50 -0
- package/src/Dev/usecase/allowedHost.ts +39 -0
- package/src/Dev/usecase/buildGraph.spec.ts +30 -0
- package/src/Dev/usecase/buildGraph.ts +31 -0
- package/src/Dev/usecase/decorateDevHtml.spec.ts +39 -0
- package/src/Dev/usecase/decorateDevHtml.ts +21 -0
- package/src/Dev/usecase/invalidate.spec.ts +88 -0
- package/src/Dev/usecase/invalidate.ts +67 -0
- package/src/Dev/usecase/parseImports.spec.ts +58 -0
- package/src/Dev/usecase/parseImports.ts +50 -0
- package/src/Dev/usecase/reloadDecision.spec.ts +50 -0
- package/src/Dev/usecase/reloadDecision.ts +65 -0
- package/src/domain/model/BundleConfig.spec.ts +35 -0
- package/src/domain/model/BundleConfig.ts +162 -0
- package/src/domain/usecase/asBundleConfig.spec.ts +230 -0
- package/src/domain/usecase/asBundleConfig.ts +257 -0
- package/src/domain/usecase/build.ts +259 -0
- package/src/domain/usecase/collectModules.ts +226 -0
- package/src/domain/usecase/deriveExternal.spec.ts +125 -0
- package/src/domain/usecase/deriveExternal.ts +108 -0
- package/src/domain/usecase/discoverWorkspace.spec.ts +63 -0
- package/src/domain/usecase/discoverWorkspace.ts +183 -0
- package/src/domain/usecase/emitBundle.spec.ts +162 -0
- package/src/domain/usecase/emitBundle.ts +215 -0
- package/src/domain/usecase/emitDts.ts +156 -0
- package/src/domain/usecase/isExternal.spec.ts +53 -0
- package/src/domain/usecase/isExternal.ts +20 -0
- package/src/domain/usecase/resolveSpecifier.spec.ts +112 -0
- package/src/domain/usecase/resolveSpecifier.ts +127 -0
- package/src/domain/usecase/resolveWorkspaceSpecifier.spec.ts +79 -0
- package/src/domain/usecase/resolveWorkspaceSpecifier.ts +120 -0
- package/src/domain/usecase/rewriteDtsAliases.spec.ts +123 -0
- package/src/domain/usecase/rewriteDtsAliases.ts +133 -0
- package/src/entrypoints/cli.ts +105 -0
- package/src/index.ts +28 -0
- package/src/vendors/runner.spec.ts +50 -0
- package/src/vendors/runner.ts +78 -0
- package/src/vendors/transpiler.ts +48 -0
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
import { readdirSync, readFileSync, existsSync, statSync, } from "node:fs";
|
|
2
|
+
import { join, dirname } from "node:path";
|
|
3
|
+
/**
|
|
4
|
+
* Discover every sibling package under the directory that
|
|
5
|
+
* holds `packageRoot` (the monorepo `packages/` dir) —
|
|
6
|
+
* each entry that has a `package.json` with a `name`.
|
|
7
|
+
* Sorted longest-name-first so a later prefix match picks
|
|
8
|
+
* `plgg-view` over `plgg`. Throws on a read/parse failure.
|
|
9
|
+
*/
|
|
10
|
+
export const discoverWorkspace = (packageRoot) => {
|
|
11
|
+
const siblingsDir = dirname(packageRoot);
|
|
12
|
+
return readdirSync(siblingsDir)
|
|
13
|
+
.map((name) => join(siblingsDir, name))
|
|
14
|
+
.filter(isPackageDir)
|
|
15
|
+
.map(readPackage)
|
|
16
|
+
.flatMap((p) => (p === undefined ? [] : [p]))
|
|
17
|
+
.sort((a, b) => b.name.length - a.name.length);
|
|
18
|
+
};
|
|
19
|
+
/**
|
|
20
|
+
* Whether a path is a directory holding a
|
|
21
|
+
* `package.json`.
|
|
22
|
+
*/
|
|
23
|
+
const isPackageDir = (dir) => statSync(dir).isDirectory() &&
|
|
24
|
+
existsSync(join(dir, "package.json"));
|
|
25
|
+
/**
|
|
26
|
+
* Read one package's manifest into a
|
|
27
|
+
* {@link WorkspacePackage}, or `undefined` when it
|
|
28
|
+
* declares no `name`. Throws on unreadable/invalid JSON.
|
|
29
|
+
*/
|
|
30
|
+
const readPackage = (dir) => {
|
|
31
|
+
const pkg = parseJson(join(dir, "package.json"));
|
|
32
|
+
const name = pkg["name"];
|
|
33
|
+
return typeof name === "string"
|
|
34
|
+
? { name, dir, exports: exportMap(pkg) }
|
|
35
|
+
: undefined;
|
|
36
|
+
};
|
|
37
|
+
/**
|
|
38
|
+
* Parse a `package.json`, re-throwing with context.
|
|
39
|
+
*/
|
|
40
|
+
const parseJson = (path) => {
|
|
41
|
+
try {
|
|
42
|
+
const parsed = JSON.parse(readFileSync(path, "utf8"));
|
|
43
|
+
return isRecord(parsed) ? parsed : {};
|
|
44
|
+
}
|
|
45
|
+
catch (cause) {
|
|
46
|
+
throw new Error(`WorkspaceError: cannot read ${path}: ${cause instanceof Error
|
|
47
|
+
? cause.message
|
|
48
|
+
: String(cause)}`);
|
|
49
|
+
}
|
|
50
|
+
};
|
|
51
|
+
/**
|
|
52
|
+
* Build the subpath → dist-default map from an `exports`
|
|
53
|
+
* field, tolerating both shapes used in the repo:
|
|
54
|
+
* - a subpath map (`{ ".": …, "./client": … }`), and
|
|
55
|
+
* - a bare conditions object (`{ import: …, require: … }`)
|
|
56
|
+
* which IS the `"."` export.
|
|
57
|
+
*/
|
|
58
|
+
const exportMap = (pkg) => {
|
|
59
|
+
const exports = pkg["exports"];
|
|
60
|
+
const out = new Map();
|
|
61
|
+
if (!isRecord(exports)) {
|
|
62
|
+
return out;
|
|
63
|
+
}
|
|
64
|
+
if (isSubpathMap(exports)) {
|
|
65
|
+
for (const [key, val] of Object.entries(exports)) {
|
|
66
|
+
const def = conditionDefault(val);
|
|
67
|
+
if (def !== undefined) {
|
|
68
|
+
out.set(key, def);
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
return out;
|
|
72
|
+
}
|
|
73
|
+
const def = conditionDefault(exports);
|
|
74
|
+
if (def !== undefined) {
|
|
75
|
+
out.set(".", def);
|
|
76
|
+
}
|
|
77
|
+
return out;
|
|
78
|
+
};
|
|
79
|
+
/**
|
|
80
|
+
* Whether an `exports` object is a subpath map (its keys
|
|
81
|
+
* are `.`/`./…` paths) rather than a bare conditions
|
|
82
|
+
* object (keys like `import`/`require`).
|
|
83
|
+
*/
|
|
84
|
+
const isSubpathMap = (exports) => Object.keys(exports).some((k) => k.startsWith("."));
|
|
85
|
+
/**
|
|
86
|
+
* Extract the resolved default file from a conditions
|
|
87
|
+
* object: the `import` (or `require`) branch's `default`,
|
|
88
|
+
* or a directly-stringed condition. Returns `undefined`
|
|
89
|
+
* when none is present.
|
|
90
|
+
*/
|
|
91
|
+
const conditionDefault = (conditions) => {
|
|
92
|
+
if (typeof conditions === "string") {
|
|
93
|
+
return conditions;
|
|
94
|
+
}
|
|
95
|
+
if (!isRecord(conditions)) {
|
|
96
|
+
return undefined;
|
|
97
|
+
}
|
|
98
|
+
return (branchDefault(conditions["import"]) ??
|
|
99
|
+
branchDefault(conditions["require"]) ??
|
|
100
|
+
branchDefault(conditions["default"]));
|
|
101
|
+
};
|
|
102
|
+
/**
|
|
103
|
+
* The `default` of one condition branch, where the branch
|
|
104
|
+
* is either a string or a `{ types, default }` object.
|
|
105
|
+
*/
|
|
106
|
+
const branchDefault = (branch) => typeof branch === "string"
|
|
107
|
+
? branch
|
|
108
|
+
: isRecord(branch) &&
|
|
109
|
+
typeof branch["default"] === "string"
|
|
110
|
+
? branch["default"]
|
|
111
|
+
: undefined;
|
|
112
|
+
/**
|
|
113
|
+
* Whether a value is a non-null object.
|
|
114
|
+
*/
|
|
115
|
+
const isRecord = (v) => typeof v === "object" && v !== null;
|
|
116
|
+
//# sourceMappingURL=discoverWorkspace.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"discoverWorkspace.js","sourceRoot":"","sources":["../../../src/domain/usecase/discoverWorkspace.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,WAAW,EACX,YAAY,EACZ,UAAU,EACV,QAAQ,GACT,MAAM,SAAS,CAAC;AACjB,OAAO,EAAE,IAAI,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAqB1C;;;;;;GAMG;AACH,MAAM,CAAC,MAAM,iBAAiB,GAAG,CAC/B,WAAmB,EACc,EAAE;IACnC,MAAM,WAAW,GAAG,OAAO,CAAC,WAAW,CAAC,CAAC;IACzC,OAAO,WAAW,CAAC,WAAW,CAAC;SAC5B,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,WAAW,EAAE,IAAI,CAAC,CAAC;SACtC,MAAM,CAAC,YAAY,CAAC;SACpB,GAAG,CAAC,WAAW,CAAC;SAChB,OAAO,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;SAC5C,IAAI,CACH,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC,MAAM,GAAG,CAAC,CAAC,IAAI,CAAC,MAAM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,CAAC;QACpC,aAAa,CAAC,UAAU,CAAC,SAAS,CAAC,CAAC,CACrC,CAAC;AACJ,CAAC,CAAC;AAEF;;;GAGG;AACH,MAAM,aAAa,GAAG,CACpB,MAAe,EACK,EAAE,CACtB,OAAO,MAAM,KAAK,QAAQ;IACxB,CAAC,CAAC,MAAM;IACR,CAAC,CAAC,QAAQ,CAAC,MAAM,CAAC;QACd,OAAO,MAAM,CAAC,SAAS,CAAC,KAAK,QAAQ;QACvC,CAAC,CAAC,MAAM,CAAC,SAAS,CAAC;QACnB,CAAC,CAAC,SAAS,CAAC;AAElB;;GAEG;AACH,MAAM,QAAQ,GAAG,CACf,CAAU,EACoB,EAAE,CAChC,OAAO,CAAC,KAAK,QAAQ,IAAI,CAAC,KAAK,IAAI,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"discoverWorkspace.spec.d.ts","sourceRoot":"","sources":["../../../src/domain/usecase/discoverWorkspace.spec.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { test, check, all, toBe, } from "plgg-test";
|
|
2
|
+
import { join } from "node:path";
|
|
3
|
+
import { discoverWorkspace } from "plgg-bundle/domain/usecase/discoverWorkspace";
|
|
4
|
+
// Run against the real monorepo: this package's root is
|
|
5
|
+
// `packages/plgg-bundle`, so discovery scans `packages/*`.
|
|
6
|
+
const bundleRoot = join(import.meta.dirname, "..", "..", "..");
|
|
7
|
+
const packages = discoverWorkspace(bundleRoot);
|
|
8
|
+
const byName = (name) => packages.find((p) => p.name === name);
|
|
9
|
+
test("discoverWorkspace finds sibling packages", () => all([
|
|
10
|
+
check(byName("plgg") !== undefined, toBe(true)),
|
|
11
|
+
check(byName("plgg-view") !== undefined, toBe(true)),
|
|
12
|
+
]));
|
|
13
|
+
test("discoverWorkspace reads the conditions-only '.' export (plgg)", () => check(byName("plgg")?.exports.get("."), toBe("./dist/index.es.js")));
|
|
14
|
+
test("discoverWorkspace reads a subpath export incl. the styleEntry rename", () => all([
|
|
15
|
+
check(byName("plgg-view")?.exports.get("./client"), toBe("./dist/client.es.js")),
|
|
16
|
+
check(byName("plgg-view")?.exports.get("./style"), toBe("./dist/styleEntry.es.js")),
|
|
17
|
+
]));
|
|
18
|
+
test("discoverWorkspace sorts longest-name first (so plgg-view beats plgg)", () => {
|
|
19
|
+
const iView = packages.findIndex((p) => p.name === "plgg-view");
|
|
20
|
+
const iCore = packages.findIndex((p) => p.name === "plgg");
|
|
21
|
+
return check(iView < iCore, toBe(true));
|
|
22
|
+
});
|
|
23
|
+
//# sourceMappingURL=discoverWorkspace.spec.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"discoverWorkspace.spec.js","sourceRoot":"","sources":["../../../src/domain/usecase/discoverWorkspace.spec.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,IAAI,EACJ,KAAK,EACL,GAAG,EACH,IAAI,GACL,MAAM,WAAW,CAAC;AACnB,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AACjC,OAAO,EAAE,iBAAiB,EAAE,MAAM,8CAA8C,CAAC;AAEjF,wDAAwD;AACxD,2DAA2D;AAC3D,MAAM,UAAU,GAAG,IAAI,CACrB,MAAM,CAAC,IAAI,CAAC,OAAO,EACnB,IAAI,EACJ,IAAI,EACJ,IAAI,CACL,CAAC;AAEF,MAAM,QAAQ,GAAG,iBAAiB,CAAC,UAAU,CAAC,CAAC;AAC/C,MAAM,MAAM,GAAG,CAAC,IAAY,EAAE,EAAE,CAC9B,QAAQ,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,IAAI,KAAK,IAAI,CAAC,CAAC;AAExC,IAAI,CAAC,0CAA0C,EAAE,GAAG,EAAE,CACpD,GAAG,CAAC;IACF,KAAK,CACH,MAAM,CAAC,MAAM,CAAC,KAAK,SAAS,EAC5B,IAAI,CAAC,IAAI,CAAC,CACX;IACD,KAAK,CACH,MAAM,CAAC,WAAW,CAAC,KAAK,SAAS,EACjC,IAAI,CAAC,IAAI,CAAC,CACX;CACF,CAAC,CAAC,CAAC;AAEN,IAAI,CAAC,+DAA+D,EAAE,GAAG,EAAE,CACzE,KAAK,CACH,MAAM,CAAC,MAAM,CAAC,EAAE,OAAO,CAAC,GAAG,CAAC,GAAG,CAAC,EAChC,IAAI,CAAC,oBAAoB,CAAC,CAC3B,CAAC,CAAC;AAEL,IAAI,CAAC,sEAAsE,EAAE,GAAG,EAAE,CAChF,GAAG,CAAC;IACF,KAAK,CACH,MAAM,CAAC,WAAW,CAAC,EAAE,OAAO,CAAC,GAAG,CAC9B,UAAU,CACX,EACD,IAAI,CAAC,qBAAqB,CAAC,CAC5B;IACD,KAAK,CACH,MAAM,CAAC,WAAW,CAAC,EAAE,OAAO,CAAC,GAAG,CAAC,SAAS,CAAC,EAC3C,IAAI,CAAC,yBAAyB,CAAC,CAChC;CACF,CAAC,CAAC,CAAC;AAEN,IAAI,CAAC,sEAAsE,EAAE,GAAG,EAAE;IAChF,MAAM,KAAK,GAAG,QAAQ,CAAC,SAAS,CAC9B,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,IAAI,KAAK,WAAW,CAC9B,CAAC;IACF,MAAM,KAAK,GAAG,QAAQ,CAAC,SAAS,CAC9B,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,IAAI,KAAK,MAAM,CACzB,CAAC;IACF,OAAO,KAAK,CAAC,KAAK,GAAG,KAAK,EAAE,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC;AAC1C,CAAC,CAAC,CAAC"}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { type Format } from "plgg-bundle/domain/model/BundleConfig";
|
|
2
|
+
import { type Graph } from "plgg-bundle/domain/usecase/collectModules";
|
|
3
|
+
/**
|
|
4
|
+
* Render a resolved {@link Graph} into one bundle's
|
|
5
|
+
* source text for the given {@link Format}, using an
|
|
6
|
+
* in-house module-registry runtime: every module body
|
|
7
|
+
* is wrapped in its own `(module, exports, require)`
|
|
8
|
+
* closure keyed by id, and a cached `__require` links
|
|
9
|
+
* them at runtime. This is collision-free by
|
|
10
|
+
* construction (each module keeps its own scope), so it
|
|
11
|
+
* needs none of rolldown's scope-hoisting/renaming and
|
|
12
|
+
* stays pure JS.
|
|
13
|
+
*
|
|
14
|
+
* Externals (specifiers left out of the bundle —
|
|
15
|
+
* `node:*`, sibling `plgg*` packages, …) are handled
|
|
16
|
+
* per format:
|
|
17
|
+
* - CJS: an un-rewritten `require("<external>")` in a
|
|
18
|
+
* module body falls through the registry to the host
|
|
19
|
+
* `require`.
|
|
20
|
+
* - ESM: there is no host `require`, so the bundle emits
|
|
21
|
+
* a real top-level `import * as __extN from
|
|
22
|
+
* "<external>"` for each distinct external and the
|
|
23
|
+
* registry routes `__require("<external>")` to that
|
|
24
|
+
* namespace.
|
|
25
|
+
*/
|
|
26
|
+
export declare const emitCjsBundle: (graph: Graph) => string;
|
|
27
|
+
/**
|
|
28
|
+
* ESM bundle. `exportNames` is the exact public surface
|
|
29
|
+
* (the entry's enumerable export keys), supplied by the
|
|
30
|
+
* orchestrator from the CJS bundle's runtime keys —
|
|
31
|
+
* ESM cannot declare exports dynamically. Externals are
|
|
32
|
+
* imported as namespaces at the top and resolved by the
|
|
33
|
+
* registry; an id that is neither a bundled module nor a
|
|
34
|
+
* declared external falls back to a native dynamic
|
|
35
|
+
* `import(id)` (see {@link externalFallback}).
|
|
36
|
+
*/
|
|
37
|
+
export declare const emitEsmBundle: (graph: Graph, exportNames: ReadonlyArray<string>) => string;
|
|
38
|
+
/**
|
|
39
|
+
* Dispatch on format for callers that hold the names
|
|
40
|
+
* regardless.
|
|
41
|
+
*/
|
|
42
|
+
export declare const emitBundle: (graph: Graph, format: Format, exportNames: ReadonlyArray<string>) => string;
|
|
43
|
+
//# sourceMappingURL=emitBundle.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"emitBundle.d.ts","sourceRoot":"","sources":["../../../src/domain/usecase/emitBundle.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,MAAM,EAAE,MAAM,uCAAuC,CAAC;AACpE,OAAO,EACL,KAAK,KAAK,EAEX,MAAM,2CAA2C,CAAC;AAEnD;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,eAAO,MAAM,aAAa,GACxB,OAAO,KAAK,KACX,MAOW,CAAC;AAEf;;;;;;;;;GASG;AACH,eAAO,MAAM,aAAa,GACxB,OAAO,KAAK,EACZ,aAAa,aAAa,CAAC,MAAM,CAAC,KACjC,MAYF,CAAC;AAEF;;;GAGG;AACH,eAAO,MAAM,UAAU,GACrB,OAAO,KAAK,EACZ,QAAQ,MAAM,EACd,aAAa,aAAa,CAAC,MAAM,CAAC,KACjC,MAGuB,CAAC"}
|
|
@@ -0,0 +1,157 @@
|
|
|
1
|
+
import {} from "plgg-bundle/domain/model/BundleConfig";
|
|
2
|
+
import {} from "plgg-bundle/domain/usecase/collectModules";
|
|
3
|
+
/**
|
|
4
|
+
* Render a resolved {@link Graph} into one bundle's
|
|
5
|
+
* source text for the given {@link Format}, using an
|
|
6
|
+
* in-house module-registry runtime: every module body
|
|
7
|
+
* is wrapped in its own `(module, exports, require)`
|
|
8
|
+
* closure keyed by id, and a cached `__require` links
|
|
9
|
+
* them at runtime. This is collision-free by
|
|
10
|
+
* construction (each module keeps its own scope), so it
|
|
11
|
+
* needs none of rolldown's scope-hoisting/renaming and
|
|
12
|
+
* stays pure JS.
|
|
13
|
+
*
|
|
14
|
+
* Externals (specifiers left out of the bundle —
|
|
15
|
+
* `node:*`, sibling `plgg*` packages, …) are handled
|
|
16
|
+
* per format:
|
|
17
|
+
* - CJS: an un-rewritten `require("<external>")` in a
|
|
18
|
+
* module body falls through the registry to the host
|
|
19
|
+
* `require`.
|
|
20
|
+
* - ESM: there is no host `require`, so the bundle emits
|
|
21
|
+
* a real top-level `import * as __extN from
|
|
22
|
+
* "<external>"` for each distinct external and the
|
|
23
|
+
* registry routes `__require("<external>")` to that
|
|
24
|
+
* namespace.
|
|
25
|
+
*/
|
|
26
|
+
export const emitCjsBundle = (graph) => [
|
|
27
|
+
`"use strict";`,
|
|
28
|
+
runtime(graph, `return require(id);`),
|
|
29
|
+
`module.exports = __require(${entryArg(graph)});`,
|
|
30
|
+
].join("\n");
|
|
31
|
+
/**
|
|
32
|
+
* ESM bundle. `exportNames` is the exact public surface
|
|
33
|
+
* (the entry's enumerable export keys), supplied by the
|
|
34
|
+
* orchestrator from the CJS bundle's runtime keys —
|
|
35
|
+
* ESM cannot declare exports dynamically. Externals are
|
|
36
|
+
* imported as namespaces at the top and resolved by the
|
|
37
|
+
* registry; an id that is neither a bundled module nor a
|
|
38
|
+
* declared external falls back to a native dynamic
|
|
39
|
+
* `import(id)` (see {@link externalFallback}).
|
|
40
|
+
*/
|
|
41
|
+
export const emitEsmBundle = (graph, exportNames) => {
|
|
42
|
+
const externals = collectExternals(graph);
|
|
43
|
+
return [
|
|
44
|
+
externalImports(externals),
|
|
45
|
+
externalTable(externals),
|
|
46
|
+
runtime(graph, externalFallback()),
|
|
47
|
+
`const __entry = __require(${entryArg(graph)});`,
|
|
48
|
+
`export default __entry;`,
|
|
49
|
+
namedExports(exportNames),
|
|
50
|
+
].join("\n");
|
|
51
|
+
};
|
|
52
|
+
/**
|
|
53
|
+
* Dispatch on format for callers that hold the names
|
|
54
|
+
* regardless.
|
|
55
|
+
*/
|
|
56
|
+
export const emitBundle = (graph, format, exportNames) => format === "es"
|
|
57
|
+
? emitEsmBundle(graph, exportNames)
|
|
58
|
+
: emitCjsBundle(graph);
|
|
59
|
+
/**
|
|
60
|
+
* The shared registry runtime: a module table plus a
|
|
61
|
+
* caching `__require` that runs a module body once and
|
|
62
|
+
* memoizes its `exports`. An id with no bundled module
|
|
63
|
+
* runs `unknownBody` (the format-specific external
|
|
64
|
+
* fallback).
|
|
65
|
+
*/
|
|
66
|
+
const runtime = (graph, unknownBody) => [
|
|
67
|
+
`const __modules = {`,
|
|
68
|
+
graph.modules.map(moduleEntry).join(",\n"),
|
|
69
|
+
`};`,
|
|
70
|
+
`const __cache = {};`,
|
|
71
|
+
`function __require(id) {`,
|
|
72
|
+
` if (id in __cache) return __cache[id].exports;`,
|
|
73
|
+
` const fn = __modules[id];`,
|
|
74
|
+
` if (!fn) { ${unknownBody} }`,
|
|
75
|
+
` const module = { exports: {} };`,
|
|
76
|
+
` __cache[id] = module;`,
|
|
77
|
+
` fn(module, module.exports, __require);`,
|
|
78
|
+
` return module.exports;`,
|
|
79
|
+
`}`,
|
|
80
|
+
].join("\n");
|
|
81
|
+
/**
|
|
82
|
+
* The ESM fallback body for an id with no bundled
|
|
83
|
+
* module: resolve it from the external namespace table
|
|
84
|
+
* (interop: a CJS consumer reads named members off the
|
|
85
|
+
* namespace; `default` carries the whole module), or
|
|
86
|
+
* fall back to a native dynamic `import(id)`. Static
|
|
87
|
+
* imports are always bundled or declared external, so
|
|
88
|
+
* only a transpiled dynamic `import(x)` — emitted as
|
|
89
|
+
* `Promise.resolve(x).then(s => __require(s))`, an
|
|
90
|
+
* async context where the returned Promise flattens —
|
|
91
|
+
* ever reaches the fallback; it lets bundled code load
|
|
92
|
+
* runtime files (e.g. a user's config) the registry
|
|
93
|
+
* cannot know. The CJS runtime keeps its host
|
|
94
|
+
* `require(id)` fall-through instead: its unknown-id
|
|
95
|
+
* branch is also reached by synchronous requires, where
|
|
96
|
+
* a returned Promise would corrupt the module value.
|
|
97
|
+
*/
|
|
98
|
+
const externalFallback = () => [
|
|
99
|
+
`if (id in __externals) return __externals[id];`,
|
|
100
|
+
`return import(id);`,
|
|
101
|
+
].join(" ");
|
|
102
|
+
/**
|
|
103
|
+
* Distinct external specifiers across the whole graph,
|
|
104
|
+
* sorted for deterministic output.
|
|
105
|
+
*/
|
|
106
|
+
const collectExternals = (graph) => [
|
|
107
|
+
...new Set(graph.modules.flatMap((m) => m.externals)),
|
|
108
|
+
].sort();
|
|
109
|
+
/**
|
|
110
|
+
* Top-level namespace imports, one per external, named
|
|
111
|
+
* `__ext0`, `__ext1`, … in the externals' sorted order.
|
|
112
|
+
*/
|
|
113
|
+
const externalImports = (externals) => externals
|
|
114
|
+
.map((spec, i) => `import * as ${extVar(i)} from ${JSON.stringify(spec)};`)
|
|
115
|
+
.join("\n");
|
|
116
|
+
/**
|
|
117
|
+
* The `__externals` lookup mapping each specifier to its
|
|
118
|
+
* imported namespace var.
|
|
119
|
+
*/
|
|
120
|
+
const externalTable = (externals) => [
|
|
121
|
+
`const __externals = {`,
|
|
122
|
+
externals
|
|
123
|
+
.map((spec, i) => ` ${JSON.stringify(spec)}: ${extVar(i)}`)
|
|
124
|
+
.join(",\n"),
|
|
125
|
+
`};`,
|
|
126
|
+
].join("\n");
|
|
127
|
+
/**
|
|
128
|
+
* The namespace variable name for the i-th external.
|
|
129
|
+
*/
|
|
130
|
+
const extVar = (i) => `__ext${i}`;
|
|
131
|
+
/**
|
|
132
|
+
* One module's registry entry: `"id": function (module,
|
|
133
|
+
* exports, require) { <body> }`.
|
|
134
|
+
*/
|
|
135
|
+
const moduleEntry = (m) => [
|
|
136
|
+
`${JSON.stringify(m.id)}: `,
|
|
137
|
+
`function (module, exports, require) {\n`,
|
|
138
|
+
m.code,
|
|
139
|
+
`\n}`,
|
|
140
|
+
].join("");
|
|
141
|
+
/**
|
|
142
|
+
* Static named re-exports of the entry namespace. Each
|
|
143
|
+
* name is a valid identifier (a JS export name), so the
|
|
144
|
+
* `export const` list is itself valid ESM.
|
|
145
|
+
*/
|
|
146
|
+
const namedExports = (names) => names.length === 0
|
|
147
|
+
? ``
|
|
148
|
+
: [
|
|
149
|
+
`export const {`,
|
|
150
|
+
names.map((n) => ` ${n}`).join(",\n"),
|
|
151
|
+
`} = __entry;`,
|
|
152
|
+
].join("\n");
|
|
153
|
+
/**
|
|
154
|
+
* The JSON-quoted entry id used as `__require`'s arg.
|
|
155
|
+
*/
|
|
156
|
+
const entryArg = (graph) => JSON.stringify(graph.entryId);
|
|
157
|
+
//# sourceMappingURL=emitBundle.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"emitBundle.js","sourceRoot":"","sources":["../../../src/domain/usecase/emitBundle.ts"],"names":[],"mappings":"AAAA,OAAO,EAAe,MAAM,uCAAuC,CAAC;AACpE,OAAO,EAGN,MAAM,2CAA2C,CAAC;AAEnD;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,MAAM,CAAC,MAAM,aAAa,GAAG,CAC3B,KAAY,EACJ,EAAE,CACV;IACE,eAAe;IACf,OAAO,CAAC,KAAK,EAAE,qBAAqB,CAAC;IACrC,8BAA8B,QAAQ,CACpC,KAAK,CACN,IAAI;CACN,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;AAEf;;;;;;;;;GASG;AACH,MAAM,CAAC,MAAM,aAAa,GAAG,CAC3B,KAAY,EACZ,WAAkC,EAC1B,EAAE;IACV,MAAM,SAAS,GAAG,gBAAgB,CAAC,KAAK,CAAC,CAAC;IAC1C,OAAO;QACL,eAAe,CAAC,SAAS,CAAC;QAC1B,aAAa,CAAC,SAAS,CAAC;QACxB,OAAO,CAAC,KAAK,EAAE,gBAAgB,EAAE,CAAC;QAClC,6BAA6B,QAAQ,CACnC,KAAK,CACN,IAAI;QACL,yBAAyB;QACzB,YAAY,CAAC,WAAW,CAAC;KAC1B,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;AACf,CAAC,CAAC;AAEF;;;GAGG;AACH,MAAM,CAAC,MAAM,UAAU,GAAG,CACxB,KAAY,EACZ,MAAc,EACd,WAAkC,EAC1B,EAAE,CACV,MAAM,KAAK,IAAI;IACb,CAAC,CAAC,aAAa,CAAC,KAAK,EAAE,WAAW,CAAC;IACnC,CAAC,CAAC,aAAa,CAAC,KAAK,CAAC,CAAC;AAE3B;;;;;;GAMG;AACH,MAAM,OAAO,GAAG,CACd,KAAY,EACZ,WAAmB,EACX,EAAE,CACV;IACE,qBAAqB;IACrB,KAAK,CAAC,OAAO,C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AM,GAAG,CAAC,CAAS,EAAU,EAAE,CAAC,QAAQ,CAAC,EAAE,CAAC;AAElD;;;GAGG;AACH,MAAM,WAAW,GAAG,CAAC,CAAS,EAAU,EAAE,CACxC;IACE,GAAG,IAAI,CAAC,SAAS,CAAC,CAAC,CAAC,EAAE,CAAC,IAAI;IAC3B,yCAAyC;IACzC,CAAC,CAAC,IAAI;IACN,KAAK;CACN,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;AAEb;;;;GAIG;AACH,MAAM,YAAY,GAAG,CACnB,KAA4B,EACpB,EAAE,CACV,KAAK,CAAC,MAAM,KAAK,CAAC;IAChB,CAAC,CAAC,EAAE;IACJ,CAAC,CAAC;QACE,gBAAgB;QAChB,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,KAAK,CAAC,EAAE,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC;QACtC,cAAc;KACf,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;AAEnB;;GAEG;AACH,MAAM,QAAQ,GAAG,CAAC,KAAY,EAAU,EAAE,CACxC,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"emitBundle.spec.d.ts","sourceRoot":"","sources":["../../../src/domain/usecase/emitBundle.spec.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
import { test, check, all, toBe, } from "plgg-test";
|
|
2
|
+
import { emitCjsBundle, emitEsmBundle, } from "plgg-bundle/domain/usecase/emitBundle";
|
|
3
|
+
import {} from "plgg-bundle/domain/usecase/collectModules";
|
|
4
|
+
const graph = {
|
|
5
|
+
entryId: "index.ts",
|
|
6
|
+
modules: [
|
|
7
|
+
{
|
|
8
|
+
id: "index.ts",
|
|
9
|
+
code: 'exports.x = require("dep.ts").x;',
|
|
10
|
+
externals: [],
|
|
11
|
+
},
|
|
12
|
+
{
|
|
13
|
+
id: "dep.ts",
|
|
14
|
+
code: "exports.x = 1;",
|
|
15
|
+
externals: [],
|
|
16
|
+
},
|
|
17
|
+
],
|
|
18
|
+
};
|
|
19
|
+
test("emitCjsBundle wires the registry and entry export", () => all([
|
|
20
|
+
check(emitCjsBundle(graph).includes("function __require(id)"), toBe(true)),
|
|
21
|
+
check(emitCjsBundle(graph).includes('module.exports = __require("index.ts")'), toBe(true)),
|
|
22
|
+
check(emitCjsBundle(graph).includes('"dep.ts":'), toBe(true)),
|
|
23
|
+
]));
|
|
24
|
+
test("emitEsmBundle emits static named exports", () => all([
|
|
25
|
+
check(emitEsmBundle(graph, ["x"]).includes("export default __entry;"), toBe(true)),
|
|
26
|
+
check(emitEsmBundle(graph, ["x"]).includes("} = __entry;"), toBe(true)),
|
|
27
|
+
check(emitEsmBundle(graph, ["x"]).includes(" x"), toBe(true)),
|
|
28
|
+
]));
|
|
29
|
+
test("the emitted CJS bundle actually runs", () => {
|
|
30
|
+
// Evaluate the emitted CJS in a fresh module scope
|
|
31
|
+
// and confirm the entry's export resolves through the
|
|
32
|
+
// registry runtime.
|
|
33
|
+
const code = emitCjsBundle(graph);
|
|
34
|
+
const mod = {
|
|
35
|
+
exports: {},
|
|
36
|
+
};
|
|
37
|
+
new Function("module", "exports", "require", code)(mod, mod.exports, () => ({}));
|
|
38
|
+
return check(mod.exports.x, toBe(1));
|
|
39
|
+
});
|
|
40
|
+
// A graph whose entry keeps an un-bundled external
|
|
41
|
+
// require (e.g. a node builtin).
|
|
42
|
+
const externalGraph = {
|
|
43
|
+
entryId: "index.ts",
|
|
44
|
+
modules: [
|
|
45
|
+
{
|
|
46
|
+
id: "index.ts",
|
|
47
|
+
code: 'exports.read = require("node:fs").readFileSync;',
|
|
48
|
+
externals: ["node:fs"],
|
|
49
|
+
},
|
|
50
|
+
],
|
|
51
|
+
};
|
|
52
|
+
test("emitEsmBundle imports externals and routes the registry to them", () => all([
|
|
53
|
+
check(emitEsmBundle(externalGraph, [
|
|
54
|
+
"read",
|
|
55
|
+
]).includes('import * as __ext0 from "node:fs";'), toBe(true)),
|
|
56
|
+
check(emitEsmBundle(externalGraph, [
|
|
57
|
+
"read",
|
|
58
|
+
]).includes('"node:fs": __ext0'), toBe(true)),
|
|
59
|
+
check(emitEsmBundle(externalGraph, [
|
|
60
|
+
"read",
|
|
61
|
+
]).includes("if (id in __externals) return __externals[id];"), toBe(true)),
|
|
62
|
+
]));
|
|
63
|
+
test("emitEsmBundle falls back to native dynamic import for unresolved ids", () => all([
|
|
64
|
+
// A runtime-only id (e.g. a config file path from a
|
|
65
|
+
// transpiled dynamic import) resolves natively …
|
|
66
|
+
check(emitEsmBundle(externalGraph, [
|
|
67
|
+
"read",
|
|
68
|
+
]).includes("return import(id);"), toBe(true)),
|
|
69
|
+
// … instead of throwing as a build mistake.
|
|
70
|
+
check(emitEsmBundle(externalGraph, [
|
|
71
|
+
"read",
|
|
72
|
+
]).includes("Cannot resolve external"), toBe(false)),
|
|
73
|
+
]));
|
|
74
|
+
test("emitCjsBundle leaves externals to the host require", () => all([
|
|
75
|
+
// No external import machinery in CJS …
|
|
76
|
+
check(emitCjsBundle(externalGraph).includes("__externals"), toBe(false)),
|
|
77
|
+
// … the un-rewritten require falls through to host.
|
|
78
|
+
check(emitCjsBundle(externalGraph).includes("return require(id);"), toBe(true)),
|
|
79
|
+
]));
|
|
80
|
+
//# sourceMappingURL=emitBundle.spec.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"emitBundle.spec.js","sourceRoot":"","sources":["../../../src/domain/usecase/emitBundle.spec.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,IAAI,EACJ,KAAK,EACL,GAAG,EACH,IAAI,GACL,MAAM,WAAW,CAAC;AACnB,OAAO,EACL,aAAa,EACb,aAAa,GACd,MAAM,uCAAuC,CAAC;AAC/C,OAAO,EAAc,MAAM,2CAA2C,CAAC;AAEvE,MAAM,KAAK,GAAU;IACnB,OAAO,EAAE,UAAU;IACnB,O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ACX;IACD,4CAA4C;IAC5C,KAAK,CACH,aAAa,CAAC,aAAa,EAAE;QAC3B,MAAM;KACP,CAAC,CAAC,QAAQ,CAAC,yBAAyB,CAAC,EACtC,IAAI,CAAC,KAAK,CAAC,CACZ;CACF,CAAC,CAAC,CAAC;AAEN,IAAI,CAAC,oDAAoD,EAAE,GAAG,EAAE,CAC9D,GAAG,CAAC;IACF,wCAAwC;IACxC,KAAK,CACH,aAAa,CAAC,aAAa,CAAC,CAAC,QAAQ,CACnC,aAAa,CACd,EACD,IAAI,CAAC,KAAK,CAAC,CACZ;IACD,oDAAoD;IACpD,KAAK,CACH,aAAa,CAAC,aAAa,CAAC,CAAC,QAAQ,CACnC,qBAAqB,CACtB,EACD,IAAI,CAAC,IAAI,CAAC,CACX;CACF,CAAC,CAAC,CAAC"}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Emit the per-file `.d.ts` tree for a package — the
|
|
3
|
+
* single declaration mode every package uses. Rides on
|
|
4
|
+
* the project's own `tsc` in declaration-only mode (no
|
|
5
|
+
* new dependency); a single rolled-up `index.d.ts` was
|
|
6
|
+
* a vite-plugin-dts stylistic choice, not a correctness
|
|
7
|
+
* requirement, so it is dropped (breaking-changes-OK)
|
|
8
|
+
* to keep the bundler at zero new dependencies. Throws
|
|
9
|
+
* on a tsc failure.
|
|
10
|
+
*
|
|
11
|
+
* `emitDeclarationOnly` guarantees no `.js`/`.js.map`
|
|
12
|
+
* leaks into `dist` (the reproduction trap). The
|
|
13
|
+
* synthesized config reuses the package's
|
|
14
|
+
* `tsconfig.build.json` when present, else
|
|
15
|
+
* `tsconfig.json`, and adds the two things the
|
|
16
|
+
* declaration build needs but the package config must
|
|
17
|
+
* not carry permanently:
|
|
18
|
+
* - `emitDeclarationOnly` (the package config drives
|
|
19
|
+
* `tsc --noEmit` type-checking),
|
|
20
|
+
* - exclusion of `*.spec.ts` and `dist`. Spec files are
|
|
21
|
+
* not published API and, in a clean build, would pull
|
|
22
|
+
* the package's own not-yet-built dist types through
|
|
23
|
+
* plgg-test; excluding them also avoids the TS5055
|
|
24
|
+
* "overwrite input" collision with a prior `dist`.
|
|
25
|
+
*/
|
|
26
|
+
export declare const emitDts: (args: {
|
|
27
|
+
root: string;
|
|
28
|
+
rootDir: string;
|
|
29
|
+
outDir: string;
|
|
30
|
+
aliasPrefix: string;
|
|
31
|
+
}) => void;
|
|
32
|
+
//# sourceMappingURL=emitDts.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"emitDts.d.ts","sourceRoot":"","sources":["../../../src/domain/usecase/emitDts.ts"],"names":[],"mappings":"AAeA;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AACH,eAAO,MAAM,OAAO,GAAI,MAAM;IAC5B,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,EAAE,MAAM,CAAC;IAChB,MAAM,EAAE,MAAM,CAAC;IACf,WAAW,EAAE,MAAM,CAAC;CACrB,KAAG,IA8CH,CAAC"}
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
import { spawnSync } from "node:child_process";
|
|
2
|
+
import { join, dirname, basename, relative, } from "node:path";
|
|
3
|
+
import { existsSync, writeFileSync, rmSync, } from "node:fs";
|
|
4
|
+
import { createRequire } from "node:module";
|
|
5
|
+
import { rewriteDtsAliases } from "plgg-bundle/domain/usecase/rewriteDtsAliases";
|
|
6
|
+
/**
|
|
7
|
+
* Emit the per-file `.d.ts` tree for a package — the
|
|
8
|
+
* single declaration mode every package uses. Rides on
|
|
9
|
+
* the project's own `tsc` in declaration-only mode (no
|
|
10
|
+
* new dependency); a single rolled-up `index.d.ts` was
|
|
11
|
+
* a vite-plugin-dts stylistic choice, not a correctness
|
|
12
|
+
* requirement, so it is dropped (breaking-changes-OK)
|
|
13
|
+
* to keep the bundler at zero new dependencies. Throws
|
|
14
|
+
* on a tsc failure.
|
|
15
|
+
*
|
|
16
|
+
* `emitDeclarationOnly` guarantees no `.js`/`.js.map`
|
|
17
|
+
* leaks into `dist` (the reproduction trap). The
|
|
18
|
+
* synthesized config reuses the package's
|
|
19
|
+
* `tsconfig.build.json` when present, else
|
|
20
|
+
* `tsconfig.json`, and adds the two things the
|
|
21
|
+
* declaration build needs but the package config must
|
|
22
|
+
* not carry permanently:
|
|
23
|
+
* - `emitDeclarationOnly` (the package config drives
|
|
24
|
+
* `tsc --noEmit` type-checking),
|
|
25
|
+
* - exclusion of `*.spec.ts` and `dist`. Spec files are
|
|
26
|
+
* not published API and, in a clean build, would pull
|
|
27
|
+
* the package's own not-yet-built dist types through
|
|
28
|
+
* plgg-test; excluding them also avoids the TS5055
|
|
29
|
+
* "overwrite input" collision with a prior `dist`.
|
|
30
|
+
*/
|
|
31
|
+
export const emitDts = (args) => {
|
|
32
|
+
const project = tsconfigFor(args.root);
|
|
33
|
+
const dtsConfig = join(args.root, "tsconfig.dts.json");
|
|
34
|
+
// tsc must emit into the SAME staging dir the JS bundles
|
|
35
|
+
// went to (args.outDir), overriding the `outDir: "dist"`
|
|
36
|
+
// the package config carries, so the whole `dist` is
|
|
37
|
+
// published atomically by the caller's single swap.
|
|
38
|
+
writeFileSync(dtsConfig, dtsTsconfig(basename(project), relative(args.root, args.outDir)), "utf8");
|
|
39
|
+
// tsc invocation seam: run the package's OWN pinned
|
|
40
|
+
// `tsc` directly via `node` — NOT `npx`. `npx` re-runs
|
|
41
|
+
// its own resolution each call and, on a loaded
|
|
42
|
+
// machine, can intermittently resolve/launch `tsc`
|
|
43
|
+
// differently (the non-deterministic dts-emit flake
|
|
44
|
+
// Planner caught). Resolving the local binary makes
|
|
45
|
+
// the compiler, its version, and its module resolution
|
|
46
|
+
// identical every run.
|
|
47
|
+
const r = spawnSync(process.execPath, [tscBin(args.root), "--project", dtsConfig], { cwd: args.root, encoding: "utf8" });
|
|
48
|
+
rmSync(dtsConfig, { force: true });
|
|
49
|
+
if (r.status !== 0) {
|
|
50
|
+
throw new Error(`DtsError: tsc declaration emit failed\n${r.stdout ?? ""}${r.stderr ?? ""}`);
|
|
51
|
+
}
|
|
52
|
+
// Relativize the self-alias in the declarations (tsc
|
|
53
|
+
// leaves `paths` aliases verbatim; consumers have no
|
|
54
|
+
// such alias).
|
|
55
|
+
rewriteDtsAliases(args.outDir, args.aliasPrefix);
|
|
56
|
+
};
|
|
57
|
+
/**
|
|
58
|
+
* The synthesized declaration-emit tsconfig, extending
|
|
59
|
+
* the package's base config.
|
|
60
|
+
*/
|
|
61
|
+
const dtsTsconfig = (baseName, outRel) => JSON.stringify({
|
|
62
|
+
extends: `./${baseName}`,
|
|
63
|
+
compilerOptions: {
|
|
64
|
+
noEmit: false,
|
|
65
|
+
declaration: true,
|
|
66
|
+
emitDeclarationOnly: true,
|
|
67
|
+
// Emit into the caller's staging dir, not the
|
|
68
|
+
// live `dist` (overrides the package config).
|
|
69
|
+
outDir: outRel,
|
|
70
|
+
// No incremental cache: a `.tsbuildinfo` could
|
|
71
|
+
// otherwise persist a stale module resolution
|
|
72
|
+
// across runs. Each emit is a clean resolution.
|
|
73
|
+
incremental: false,
|
|
74
|
+
composite: false,
|
|
75
|
+
},
|
|
76
|
+
exclude: [
|
|
77
|
+
"**/*.spec.ts",
|
|
78
|
+
"**/*.spec.tsx",
|
|
79
|
+
"dist",
|
|
80
|
+
`${outRel}`,
|
|
81
|
+
"node_modules",
|
|
82
|
+
],
|
|
83
|
+
}, null, 2);
|
|
84
|
+
/**
|
|
85
|
+
* Absolute path to the package's OWN pinned `tsc`
|
|
86
|
+
* launcher, resolved from its `typescript` dependency
|
|
87
|
+
* (derived from the package main so it works regardless
|
|
88
|
+
* of `typescript`'s `exports` map). Run via `node`.
|
|
89
|
+
*/
|
|
90
|
+
const tscBin = (root) => join(dirname(createRequire(join(root, "package.json")).resolve("typescript")), "..", "bin", "tsc");
|
|
91
|
+
/**
|
|
92
|
+
* Pick the tsconfig that drives declaration emit:
|
|
93
|
+
* `tsconfig.build.json` when the package carries one,
|
|
94
|
+
* otherwise `tsconfig.json`.
|
|
95
|
+
*/
|
|
96
|
+
const tsconfigFor = (root) => existsSync(join(root, "tsconfig.build.json"))
|
|
97
|
+
? join(root, "tsconfig.build.json")
|
|
98
|
+
: join(root, "tsconfig.json");
|
|
99
|
+
//# sourceMappingURL=emitDts.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"emitDts.js","sourceRoot":"","sources":["../../../src/domain/usecase/emitDts.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAC;AAC/C,OAAO,EACL,IAAI,EACJ,OAAO,EACP,QAAQ,EACR,QAAQ,GACT,MAAM,WAAW,CAAC;AACnB,OAAO,EACL,UAAU,EACV,aAAa,EACb,MAAM,GACP,MAAM,SAAS,CAAC;AACjB,OAAO,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAC5C,OAAO,EAAE,iBAAiB,EAAE,MAAM,8CAA8C,CAAC;AAEjF;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AACH,MAAM,CAAC,MAAM,OAAO,GAAG,CAAC,IAKvB,EAAQ,EAAE;IACT,MAAM,OAAO,GAAG,WAAW,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IACvC,MAAM,SAAS,GAAG,IAAI,CACpB,IAAI,CAAC,IAAI,EACT,mBAAmB,CACpB,CAAC;IACF,yDAAyD;IACzD,yDAAyD;IACzD,qDAAqD;IACrD,oDAAoD;IACpD,aAAa,CACX,SAAS,EACT,WAAW,CACT,QAAQ,CAAC,OAAO,CAAC,EACjB,QAAQ,CAAC,IAAI,CAAC,IAAI,EAAE,IAAI,CAAC,MAAM,CAAC,CACjC,EACD,MAAM,CACP,CAAC;IACF,oDAAoD;IACpD,uDAAuD;IACvD,gDAAgD;IAChD,mDAAmD;IACnD,oDAAoD;IACpD,oDAAoD;IACpD,uDAAuD;IACvD,uBAAuB;IACvB,MAAM,CAAC,GAAG,SAAS,CACjB,OAAO,CAAC,QAAQ,EAChB,CAAC,MAAM,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,EACJ,KAAK,EACL,KAAK,CACN,CAAC;AAEJ;;;;GAIG;AACH,MAAM,WAAW,GAAG,CAAC,IAAY,EAAU,EAAE,CAC3C,UAAU,CAAC,IAAI,CAAC,IAAI,EAAE,qBAAqB,CAAC,CAAC;IAC3C,CAAC,CAAC,IAAI,CAAC,IAAI,EAAE,qBAAqB,CAAC;IACnC,CAAC,CAAC,IAAI,CAAC,IAAI,EAAE,eAAe,CAAC,CAAC"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { type External } from "plgg-bundle/domain/model/BundleConfig";
|
|
2
|
+
/**
|
|
3
|
+
* Decide whether a specifier is external given the
|
|
4
|
+
* config's {@link External} declaration, dispatching on
|
|
5
|
+
* its three shapes: a string array (exact match), a
|
|
6
|
+
* `RegExp` (test), or a predicate function (call). This
|
|
7
|
+
* is the single place the three vite-config external
|
|
8
|
+
* forms — string[], `/^node:/`, and plgg-fetch's
|
|
9
|
+
* `isFrameworkDep` predicate — converge.
|
|
10
|
+
*/
|
|
11
|
+
export declare const isExternal: (external: External, specifier: string) => boolean;
|
|
12
|
+
//# sourceMappingURL=isExternal.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"isExternal.d.ts","sourceRoot":"","sources":["../../../src/domain/usecase/isExternal.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,QAAQ,EAAE,MAAM,uCAAuC,CAAC;AAEtE;;;;;;;;GAQG;AACH,eAAO,MAAM,UAAU,GACrB,UAAU,QAAQ,EAClB,WAAW,MAAM,KAChB,OAKiC,CAAC"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import {} from "plgg-bundle/domain/model/BundleConfig";
|
|
2
|
+
/**
|
|
3
|
+
* Decide whether a specifier is external given the
|
|
4
|
+
* config's {@link External} declaration, dispatching on
|
|
5
|
+
* its three shapes: a string array (exact match), a
|
|
6
|
+
* `RegExp` (test), or a predicate function (call). This
|
|
7
|
+
* is the single place the three vite-config external
|
|
8
|
+
* forms — string[], `/^node:/`, and plgg-fetch's
|
|
9
|
+
* `isFrameworkDep` predicate — converge.
|
|
10
|
+
*/
|
|
11
|
+
export const isExternal = (external, specifier) => typeof external === "function"
|
|
12
|
+
? external(specifier)
|
|
13
|
+
: external instanceof RegExp
|
|
14
|
+
? external.test(specifier)
|
|
15
|
+
: external.includes(specifier);
|
|
16
|
+
//# sourceMappingURL=isExternal.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"isExternal.js","sourceRoot":"","sources":["../../../src/domain/usecase/isExternal.ts"],"names":[],"mappings":"AAAA,OAAO,EAAiB,MAAM,uCAAuC,CAAC;AAEtE;;;;;;;;GAQG;AACH,MAAM,CAAC,MAAM,UAAU,GAAG,CACxB,QAAkB,EAClB,SAAiB,EACR,EAAE,CACX,OAAO,QAAQ,KAAK,UAAU;IAC5B,CAAC,CAAC,QAAQ,CAAC,SAAS,CAAC;IACrB,CAAC,CAAC,QAAQ,YAAY,MAAM;QAC1B,CAAC,CAAC,QAAQ,CAAC,IAAI,CAAC,SAAS,CAAC;QAC1B,CAAC,CAAC,QAAQ,CAAC,QAAQ,CAAC,SAAS,CAAC,CAAC"}
|