@akanjs/devkit 3.0.0-alpha.8 → 3.0.0-alpha.81
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 +15 -0
- package/README.ko.md +1 -1
- package/README.md +1 -1
- package/agentsIndex.test.ts +10 -0
- package/agentsIndex.ts +47 -1
- package/aiEditor.ts +1 -1
- package/akanApp/BackendImportGraph.test.ts +120 -0
- package/akanApp/BackendImportGraph.ts +167 -0
- package/akanApp/akanApp.host.test.ts +16 -678
- package/akanApp/akanApp.host.ts +65 -562
- package/akanApp/devHostPolicy.test.ts +542 -0
- package/akanApp/devHostPolicy.ts +412 -0
- package/akanApp/index.ts +2 -0
- package/akanConfig/akanConfig.test.ts +182 -14
- package/akanConfig/akanConfig.ts +132 -47
- package/akanConfig/types.ts +8 -0
- package/akanContext.ts +70 -14
- package/akanMcpContract.ts +25 -4
- package/applicationBuildRunner.test.ts +1 -1
- package/applicationBuildRunner.ts +45 -21
- package/artifact/implicitRootLayout.test.ts +67 -0
- package/artifact/implicitRootLayout.ts +27 -7
- package/artifact/routeSeedIndex.test.ts +1 -0
- package/biome.base.json +340 -0
- package/biomeBase.ts +9 -0
- package/capacitorApp.ts +10 -0
- package/cloud/globalConfig.ts +9 -2
- package/commandDecorators/command.ts +30 -6
- package/commandDecorators/commandBuilder.ts +20 -5
- package/commandDecorators/commandDecorators.test.ts +115 -3
- package/dependencyScanner.test.ts +99 -0
- package/dependencyScanner.ts +27 -24
- package/devkitUtils.test.ts +0 -104
- package/executors.test.ts +132 -5
- package/executors.ts +89 -14
- package/fileEditor.ts +19 -19
- package/formSetterScanner.test.ts +80 -0
- package/formSetterScanner.ts +92 -0
- package/frontendBuild/autoImportSync.test.ts +58 -0
- package/frontendBuild/autoImportSync.ts +4 -0
- package/frontendBuild/buildRouteClient.test.ts +47 -24
- package/frontendBuild/clientBuildTypes.ts +4 -0
- package/frontendBuild/clientEntriesBundler.ts +4 -1
- package/frontendBuild/clientEntryDiscovery.ts +2 -2
- package/frontendBuild/csrArtifactBuilder.ts +116 -84
- package/frontendBuild/cssCompiler.ts +123 -12
- package/frontendBuild/cssImportResolver.ts +8 -7
- package/frontendBuild/fontOptimizer.ts +37 -18
- package/frontendBuild/fontPruner.test.ts +220 -0
- package/frontendBuild/fontPruner.ts +206 -0
- package/frontendBuild/frontendBuild.test.ts +178 -10
- package/frontendBuild/hmrWatcher.ts +1 -1
- package/frontendBuild/index.ts +1 -1
- package/frontendBuild/pagesBundleBuilder.ts +3 -3
- package/frontendBuild/pagesEntrySourceGenerator.ts +11 -88
- package/frontendBuild/routeClientBuilder.ts +12 -5
- package/frontendBuild/ssrBaseArtifactBuilder.ts +21 -4
- package/frontendBuild/styleContract.ts +14 -20
- package/frontendBuild/themeValidator.ts +22 -17
- package/frontendBuild/vendorSpecifiers.ts +1 -0
- package/incrementalBuilder/devWatchBatch.test.ts +18 -20
- package/incrementalBuilder/devWatchBatch.ts +6 -2
- package/incrementalBuilder/incrementalBuilder.host.ts +1 -1
- package/incrementalBuilder/incrementalBuilder.proc.ts +8 -4
- package/index.ts +0 -5
- package/integration/devStabilityHarness.ts +2 -10
- package/libSource.test.ts +109 -0
- package/libSource.ts +126 -0
- package/lint/__fixtures__/README.md +40 -0
- package/lint/__fixtures__/no-arbitrary-color/bad.tsx +3 -0
- package/lint/__fixtures__/no-arbitrary-color/good.tsx +4 -0
- package/lint/__fixtures__/no-async-component-in-ui/bad.tsx +4 -0
- package/lint/__fixtures__/no-async-component-in-ui/good.tsx +4 -0
- package/lint/__fixtures__/no-bang-comment-in-client/bad.tsx +4 -0
- package/lint/__fixtures__/no-bang-comment-in-client/fixture.json +1 -0
- package/lint/__fixtures__/no-bang-comment-in-client/good.tsx +3 -0
- package/lint/__fixtures__/no-daisyui-legacy-class/bad.tsx +7 -0
- package/lint/__fixtures__/no-daisyui-legacy-class/good.tsx +5 -0
- package/lint/__fixtures__/no-deep-internal-import/bad.tsx +3 -0
- package/lint/__fixtures__/no-deep-internal-import/fixture.json +1 -0
- package/lint/__fixtures__/no-deep-internal-import/good.tsx +3 -0
- package/lint/__fixtures__/no-deprecated-log-level/bad.tsx +4 -0
- package/lint/__fixtures__/no-deprecated-log-level/good.tsx +4 -0
- package/lint/__fixtures__/no-import-client-functions/bad.tsx +2 -0
- package/lint/__fixtures__/no-import-client-functions/good.tsx +4 -0
- package/lint/__fixtures__/no-import-client-in-server/bad.tsx +6 -0
- package/lint/__fixtures__/no-import-client-in-server/good.tsx +5 -0
- package/lint/__fixtures__/no-import-external-library/bad.tsx +4 -0
- package/lint/__fixtures__/no-import-external-library/good.tsx +5 -0
- package/lint/__fixtures__/no-import-server-in-client/bad.tsx +6 -0
- package/lint/__fixtures__/no-import-server-in-client/good.tsx +4 -0
- package/lint/__fixtures__/no-init-fetch-in-client/store-file/bad.ts +1 -0
- package/lint/__fixtures__/no-init-fetch-in-client/store-file/fixture.json +1 -0
- package/lint/__fixtures__/no-init-fetch-in-client/store-file/good.ts +1 -0
- package/lint/__fixtures__/no-init-fetch-in-client/use-client/bad.tsx +4 -0
- package/lint/__fixtures__/no-init-fetch-in-client/use-client/good.tsx +5 -0
- package/lint/__fixtures__/no-inline-color/bad.tsx +3 -0
- package/lint/__fixtures__/no-inline-color/good.tsx +3 -0
- package/lint/__fixtures__/no-interpolated-arbitrary-class/bad.tsx +3 -0
- package/lint/__fixtures__/no-interpolated-arbitrary-class/good.tsx +3 -0
- package/lint/__fixtures__/no-js-private-class-method/bad.tsx +3 -0
- package/lint/__fixtures__/no-js-private-class-method/good.tsx +3 -0
- package/lint/__fixtures__/no-model-type-in-util-zone/bad.tsx +3 -0
- package/lint/__fixtures__/no-model-type-in-util-zone/good.tsx +6 -0
- package/lint/__fixtures__/no-raw-palette-class/bad.tsx +6 -0
- package/lint/__fixtures__/no-raw-palette-class/good.tsx +8 -0
- package/lint/__fixtures__/no-redeclare-predefined-endpoint/bad.ts +10 -0
- package/lint/__fixtures__/no-redeclare-predefined-endpoint/fixture.json +1 -0
- package/lint/__fixtures__/no-redeclare-predefined-endpoint/good.ts +6 -0
- package/lint/__fixtures__/no-return-in-store-action/bad.tsx +2 -0
- package/lint/__fixtures__/no-return-in-store-action/good.tsx +6 -0
- package/lint/__fixtures__/no-throw-raw-error/bad.tsx +4 -0
- package/lint/__fixtures__/no-throw-raw-error/good.tsx +4 -0
- package/lint/__fixtures__/no-unpublished-form-setter/bad.tsx +3 -0
- package/lint/__fixtures__/no-unpublished-form-setter/good.tsx +5 -0
- package/lint/__fixtures__/no-use-client-in-server/bad.tsx +3 -0
- package/lint/__fixtures__/no-use-client-in-server/good.tsx +2 -0
- package/lint/__fixtures__/non-scalar-props-restricted/bad.tsx +5 -0
- package/lint/__fixtures__/non-scalar-props-restricted/good.tsx +4 -0
- package/lint/gritRules.test.ts +178 -0
- package/lint/no-arbitrary-color.grit +1 -1
- package/lint/no-async-component-in-ui.grit +35 -0
- package/lint/no-bang-comment-in-client.grit +23 -10
- package/lint/no-daisyui-legacy-class.grit +26 -9
- package/lint/no-deprecated-log-level.grit +17 -0
- package/lint/no-import-client-in-server.grit +48 -0
- package/lint/no-import-server-in-client.grit +45 -0
- package/lint/no-init-fetch-in-client.grit +47 -0
- package/lint/no-inline-color.grit +10 -8
- package/lint/no-interpolated-arbitrary-class.grit +3 -3
- package/lint/no-model-type-in-util-zone.grit +58 -0
- package/lint/no-raw-palette-class.grit +3 -3
- package/lint/no-unpublished-form-setter.grit +41 -0
- package/lint/non-scalar-props-restricted.grit +16 -7
- package/linter.test.ts +80 -0
- package/linter.ts +99 -25
- package/package.json +6 -6
- package/prompter.ts +9 -4
- package/qualityScanner.test.ts +116 -0
- package/qualityScanner.ts +89 -21
- package/recipeScanner.ts +4 -1
- package/repoIdentity.ts +42 -0
- package/scanInfo.ts +32 -26
- package/semver.test.ts +26 -0
- package/semver.ts +31 -0
- package/slicePlanner.test.ts +182 -0
- package/slicePlanner.ts +235 -0
- package/ssrScanner.test.ts +301 -0
- package/subspace.test.ts +418 -0
- package/subspace.ts +723 -0
- package/subspaceConfig.ts +76 -0
- package/transforms/asyncDefaultExportDetector.ts +103 -0
- package/transforms/barrelImportsPlugin.ts +1 -1
- package/transforms/externalizeFrameworkPlugin.ts +0 -1
- package/transforms/transforms.test.ts +5 -5
- package/transforms/tsconfigPackageResolver.test.ts +230 -0
- package/tsconfig.json +6 -2
- package/typeChecker.ts +1 -1
- package/types.ts +1 -0
- package/ui/ScrollList.tsx +6 -8
- package/uploadRelease.ts +2 -2
- package/workflow/executor.test.ts +146 -0
- package/workspaceLayout.test.ts +56 -4
- package/workspaceLayout.ts +49 -4
- package/builder.ts +0 -164
- package/extractDeps.ts +0 -86
- package/frontendBuild/styleGuard.test.ts +0 -165
- package/frontendBuild/styleGuard.ts +0 -322
- package/getCredentials.ts +0 -19
- package/getModelFileData.ts +0 -62
- package/src/capacitorApp.ts +0 -282
- package/streamAi.ts +0 -45
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
import ts from "typescript";
|
|
2
|
+
import type { QualityWarning, SourceFileInfo } from "./qualityScanner";
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* The inventory of model fields a screen writes but does not publish.
|
|
6
|
+
*
|
|
7
|
+
* A control handed `onChange={st.do.setTitleOnTask}` **by reference** names the field it writes, so it emits
|
|
8
|
+
* `data-akan-action` and `useFieldTool` publishes the field to the in-page agent. Any wrapper around that setter is
|
|
9
|
+
* an anonymous closure carrying neither, and the field goes quiet — for the agent, for an E2E selector, and for the
|
|
10
|
+
* accessibility tree.
|
|
11
|
+
*
|
|
12
|
+
* `no-unpublished-form-setter.grit` is the per-line enforcement, and it fires only on a pure forwarding wrapper,
|
|
13
|
+
* because every other shape has a legitimate reading and a lint error would be wrong. This is the other half: the
|
|
14
|
+
* per-file count of fields that ended up unreachable whatever the reason, which is the number worth watching. A
|
|
15
|
+
* warning rather than an error for the same reason — the remedy depends on why the wrapper is there.
|
|
16
|
+
*
|
|
17
|
+
* Only a handler that takes a parameter is counted. A zero-parameter handler (`onClick={() => st.do.setStatusOnUser
|
|
18
|
+
* ("active")}`) is a button setting a constant, not a form control, and its remedy is an `st.tool` beside it.
|
|
19
|
+
*/
|
|
20
|
+
export class FormSetterScanner {
|
|
21
|
+
static #fieldSetter = /^set[A-Za-z0-9_$]*On[A-Za-z0-9_$]*$/;
|
|
22
|
+
|
|
23
|
+
scan(sourceFiles: SourceFileInfo[]): QualityWarning[] {
|
|
24
|
+
return sourceFiles.filter((sourceFile) => sourceFile.file.endsWith(".tsx")).flatMap((f) => this.#scanFile(f));
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
#scanFile({ file, sourceFile }: SourceFileInfo): QualityWarning[] {
|
|
28
|
+
const wrapped: { setter: string; line: number }[] = [];
|
|
29
|
+
const visit = (node: ts.Node) => {
|
|
30
|
+
if (ts.isJsxAttribute(node)) {
|
|
31
|
+
const setter = FormSetterScanner.#wrappedSetterOf(node);
|
|
32
|
+
if (setter) wrapped.push({ setter, line: FormSetterScanner.#lineOf(sourceFile, node) });
|
|
33
|
+
}
|
|
34
|
+
ts.forEachChild(node, visit);
|
|
35
|
+
};
|
|
36
|
+
visit(sourceFile);
|
|
37
|
+
if (!wrapped.length) return [];
|
|
38
|
+
const setters = [...new Set(wrapped.map((entry) => entry.setter))].sort();
|
|
39
|
+
return [
|
|
40
|
+
{
|
|
41
|
+
rule: "akan.agent.unpublished-form-setter",
|
|
42
|
+
scope: "agent",
|
|
43
|
+
severity: "warning",
|
|
44
|
+
message:
|
|
45
|
+
setters.length === 1
|
|
46
|
+
? `${setters[0]} is reached through a wrapper, so that field publishes no agent tool and carries no data-akan-action.`
|
|
47
|
+
: `${setters.length} field setters are reached through a wrapper, so those fields publish no agent tool and carry no data-akan-action: ${setters.join(", ")}.`,
|
|
48
|
+
file,
|
|
49
|
+
line: wrapped[0]?.line,
|
|
50
|
+
locations: wrapped.map(({ line }) => ({ file, line })),
|
|
51
|
+
},
|
|
52
|
+
];
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
/** The setter a handler prop writes behind a wrapper, or null when it is passed by reference or absent. */
|
|
56
|
+
static #wrappedSetterOf(attribute: ts.JsxAttribute): string | null {
|
|
57
|
+
if (!ts.isIdentifier(attribute.name) || !/^on[A-Z]/.test(attribute.name.text)) return null;
|
|
58
|
+
const initializer = attribute.initializer;
|
|
59
|
+
if (!initializer || !ts.isJsxExpression(initializer) || !initializer.expression) return null;
|
|
60
|
+
const handler = initializer.expression;
|
|
61
|
+
if (!ts.isArrowFunction(handler) && !ts.isFunctionExpression(handler)) return null;
|
|
62
|
+
if (!handler.parameters.length) return null;
|
|
63
|
+
return FormSetterScanner.#setterCallIn(handler.body);
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
static #setterCallIn(node: ts.Node): string | null {
|
|
67
|
+
let found: string | null = null;
|
|
68
|
+
const visit = (current: ts.Node) => {
|
|
69
|
+
if (found) return;
|
|
70
|
+
if (ts.isCallExpression(current) && ts.isPropertyAccessExpression(current.expression)) {
|
|
71
|
+
const { expression, name } = current.expression;
|
|
72
|
+
if (
|
|
73
|
+
ts.isPropertyAccessExpression(expression) &&
|
|
74
|
+
ts.isIdentifier(expression.expression) &&
|
|
75
|
+
expression.expression.text === "st" &&
|
|
76
|
+
expression.name.text === "do" &&
|
|
77
|
+
FormSetterScanner.#fieldSetter.test(name.text)
|
|
78
|
+
) {
|
|
79
|
+
found = name.text;
|
|
80
|
+
return;
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
ts.forEachChild(current, visit);
|
|
84
|
+
};
|
|
85
|
+
visit(node);
|
|
86
|
+
return found;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
static #lineOf(sourceFile: ts.SourceFile, node: ts.Node) {
|
|
90
|
+
return sourceFile.getLineAndCharacterOfPosition(node.getStart(sourceFile)).line + 1;
|
|
91
|
+
}
|
|
92
|
+
}
|
|
@@ -355,3 +355,61 @@ describe("AutoImportSync.syncForBatch", () => {
|
|
|
355
355
|
expect(await readFile(indexFile, "utf8")).not.toContain("@libs/shared/client");
|
|
356
356
|
});
|
|
357
357
|
});
|
|
358
|
+
|
|
359
|
+
describe("AutoImportSync — scope", () => {
|
|
360
|
+
const writeAt = async (root: string, rel: string, source: string) => {
|
|
361
|
+
const abs = path.join(root, rel);
|
|
362
|
+
await mkdir(path.dirname(abs), { recursive: true });
|
|
363
|
+
await writeFile(abs, source);
|
|
364
|
+
return abs;
|
|
365
|
+
};
|
|
366
|
+
|
|
367
|
+
// `lib/__lib/` is generated and gitignored: `akan sync` rewrites it, which is also what makes the
|
|
368
|
+
// watcher hand it to the syncer, so an edit there is churn that the next sync discards.
|
|
369
|
+
test("leaves the generated lib/__lib stubs alone and still syncs lib/__scalar", async () => {
|
|
370
|
+
const root = await makeTempRoot();
|
|
371
|
+
const needsImport = "export class A {\n count = field(Int);\n}\n";
|
|
372
|
+
const generated = await writeAt(root, "libs/shared/lib/__lib/lib.constant.ts", needsImport);
|
|
373
|
+
const scalar = await writeAt(root, "libs/shared/lib/__scalar/money/money.constant.ts", needsImport);
|
|
374
|
+
|
|
375
|
+
const result = await new AutoImportSync({ workspaceRoot: root }).syncForBatch([generated, scalar]);
|
|
376
|
+
|
|
377
|
+
expect(result.errors).toEqual([]);
|
|
378
|
+
expect(result.changedFiles).toEqual([scalar]);
|
|
379
|
+
expect(await readFile(generated, "utf8")).toBe(needsImport);
|
|
380
|
+
expect(await readFile(scalar, "utf8")).toContain('import { Int } from "akanjs/base";');
|
|
381
|
+
});
|
|
382
|
+
|
|
383
|
+
// The transform is pure and the write is conditional on a difference, so a second pass over its own
|
|
384
|
+
// output writes nothing — without that the watcher would re-fire on the syncer's own edit.
|
|
385
|
+
test("a second pass over its own output changes nothing", async () => {
|
|
386
|
+
const root = await makeTempRoot();
|
|
387
|
+
const file = await writeAt(
|
|
388
|
+
root,
|
|
389
|
+
"libs/shared/lib/task/task.constant.ts",
|
|
390
|
+
"export class A {\n count = field(Int);\n}\n",
|
|
391
|
+
);
|
|
392
|
+
const sync = new AutoImportSync({ workspaceRoot: root });
|
|
393
|
+
|
|
394
|
+
expect((await sync.syncForBatch([file])).changedFiles).toEqual([file]);
|
|
395
|
+
const afterFirst = await readFile(file, "utf8");
|
|
396
|
+
expect((await sync.syncForBatch([file])).changedFiles).toEqual([]);
|
|
397
|
+
expect(await readFile(file, "utf8")).toBe(afterFirst);
|
|
398
|
+
});
|
|
399
|
+
|
|
400
|
+
// One try/catch per file: a file that cannot be read is reported and the rest of the batch still runs.
|
|
401
|
+
test("a failing file is reported without abandoning the batch", async () => {
|
|
402
|
+
const root = await makeTempRoot();
|
|
403
|
+
const missing = path.join(root, "libs/shared/lib/task/gone.constant.ts");
|
|
404
|
+
const good = await writeAt(
|
|
405
|
+
root,
|
|
406
|
+
"libs/shared/lib/task/task.constant.ts",
|
|
407
|
+
"export class A {\n count = field(Int);\n}\n",
|
|
408
|
+
);
|
|
409
|
+
|
|
410
|
+
const result = await new AutoImportSync({ workspaceRoot: root }).syncForBatch([missing, good]);
|
|
411
|
+
|
|
412
|
+
expect(result.changedFiles).toEqual([good]);
|
|
413
|
+
expect(result.errors).toEqual([]);
|
|
414
|
+
});
|
|
415
|
+
});
|
|
@@ -250,6 +250,10 @@ export class AutoImportSync {
|
|
|
250
250
|
const parts = rel.split(path.sep).filter(Boolean);
|
|
251
251
|
const [scope, project, facet] = parts;
|
|
252
252
|
if ((scope !== "apps" && scope !== "libs") || !project || !facet) return null;
|
|
253
|
+
//* `lib/__lib/` holds the generated per-lib re-export stubs — gitignored, and rewritten by every
|
|
254
|
+
//* `akan sync`, which is also what makes the watcher report them. An edit there is churn at best and
|
|
255
|
+
//* silently discarded at worst. `lib/__scalar/` is real source and stays in scope.
|
|
256
|
+
if (facet === "lib" && parts[3] === "__lib") return null;
|
|
253
257
|
const role = roleFor(facet, base);
|
|
254
258
|
if (!role) return null;
|
|
255
259
|
|
|
@@ -82,16 +82,42 @@ describe("route client store bootstrap", () => {
|
|
|
82
82
|
});
|
|
83
83
|
|
|
84
84
|
test("bundles akan fetch into production SSR client chunks", () => {
|
|
85
|
-
expect(RouteClientBuilder.
|
|
85
|
+
expect(RouteClientBuilder.resolveSsrClientBundleOptions("start")).toMatchObject({
|
|
86
86
|
external: expect.arrayContaining(["akanjs/fetch"]),
|
|
87
87
|
externalSubpaths: ["akanjs/fetch"],
|
|
88
88
|
});
|
|
89
89
|
|
|
90
|
-
expect(RouteClientBuilder.
|
|
90
|
+
expect(RouteClientBuilder.resolveSsrClientBundleOptions("build")).toEqual({
|
|
91
|
+
target: "bun",
|
|
91
92
|
external: ["react", "react-dom", "react-dom/client", "react/jsx-runtime", "react/jsx-dev-runtime"],
|
|
92
93
|
});
|
|
93
94
|
});
|
|
94
95
|
|
|
96
|
+
test("targets the server so SSR client chunks never resolve a browser export condition", async () => {
|
|
97
|
+
const root = await makeTempRoot();
|
|
98
|
+
const pkgDir = path.join(root, "node_modules/dom-conditioned-pkg");
|
|
99
|
+
await write(
|
|
100
|
+
path.join(pkgDir, "package.json"),
|
|
101
|
+
JSON.stringify({
|
|
102
|
+
name: "dom-conditioned-pkg",
|
|
103
|
+
type: "module",
|
|
104
|
+
exports: { ".": { browser: "./index.dom.js", default: "./index.js" } },
|
|
105
|
+
}),
|
|
106
|
+
);
|
|
107
|
+
await write(path.join(pkgDir, "index.dom.js"), 'export const element = document.createElement("i");\n');
|
|
108
|
+
await write(path.join(pkgDir, "index.js"), "export const element = null;\n");
|
|
109
|
+
const entry = path.join(root, "entry.ts");
|
|
110
|
+
await write(entry, 'export { element } from "dom-conditioned-pkg";\n');
|
|
111
|
+
|
|
112
|
+
for (const command of ["start", "build"] as const) {
|
|
113
|
+
const { target } = RouteClientBuilder.resolveSsrClientBundleOptions(command);
|
|
114
|
+
const built = await Bun.build({ entrypoints: [entry], target, format: "esm" });
|
|
115
|
+
|
|
116
|
+
expect(built.success).toBe(true);
|
|
117
|
+
expect(await built.outputs[0].text()).not.toContain("document.createElement");
|
|
118
|
+
}
|
|
119
|
+
});
|
|
120
|
+
|
|
95
121
|
test("rewrites SSR external imports to runtime aliases", () => {
|
|
96
122
|
const source = [
|
|
97
123
|
'import React, { useState } from "react";',
|
|
@@ -133,28 +159,25 @@ describe("route client store bootstrap", () => {
|
|
|
133
159
|
await write(uiEntry, 'export { ClientPathWrapper } from "./System/Client";\n');
|
|
134
160
|
await write(clientEntry, '"use client";\nexport const ClientPathWrapper = () => null;\n');
|
|
135
161
|
|
|
136
|
-
const discovery = new GraphClientEntryDiscovery(
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
return null;
|
|
156
|
-
},
|
|
157
|
-
);
|
|
162
|
+
const discovery = new GraphClientEntryDiscovery({ barrelImports: ["akanjs/ui"] }, async (specifier) => {
|
|
163
|
+
if (specifier === "akanjs/ui") {
|
|
164
|
+
return {
|
|
165
|
+
pkgName: "akanjs/ui",
|
|
166
|
+
entryFile: uiEntry,
|
|
167
|
+
pkgDir: path.dirname(uiEntry),
|
|
168
|
+
preserveFilePath: true,
|
|
169
|
+
};
|
|
170
|
+
}
|
|
171
|
+
if (specifier === "akanjs/ui/System/Client.tsx") {
|
|
172
|
+
return {
|
|
173
|
+
pkgName: "akanjs/ui/System/Client.tsx",
|
|
174
|
+
entryFile: clientEntry,
|
|
175
|
+
pkgDir: path.dirname(clientEntry),
|
|
176
|
+
preserveFilePath: true,
|
|
177
|
+
};
|
|
178
|
+
}
|
|
179
|
+
return null;
|
|
180
|
+
});
|
|
158
181
|
|
|
159
182
|
expect(await discovery.discover([seed])).toEqual([clientEntry]);
|
|
160
183
|
});
|
|
@@ -55,6 +55,8 @@ export interface BuildClientResult {
|
|
|
55
55
|
rscClientUrl: string;
|
|
56
56
|
}
|
|
57
57
|
|
|
58
|
+
export type ClientBundleTarget = "browser" | "bun";
|
|
59
|
+
|
|
58
60
|
export const CLIENT_BUNDLE_NAMING = {
|
|
59
61
|
entry: "[name]-[hash].[ext]",
|
|
60
62
|
chunk: "chunks/[hash].[ext]",
|
|
@@ -79,6 +81,8 @@ export interface BundleClientEntriesOptions {
|
|
|
79
81
|
}
|
|
80
82
|
|
|
81
83
|
export interface BundleClientEntriesInternalOptions extends BundleClientEntriesOptions {
|
|
84
|
+
/** Module-resolution target. `"bun"` for the server-executed `client-ssr` bundle, `"browser"` otherwise. */
|
|
85
|
+
target?: ClientBundleTarget;
|
|
82
86
|
external?: readonly string[];
|
|
83
87
|
externalSubpaths?: readonly string[];
|
|
84
88
|
externalAliases?: Partial<Record<string, string>>;
|
|
@@ -7,6 +7,7 @@ import {
|
|
|
7
7
|
type BundleClientEntriesInternalOptions,
|
|
8
8
|
type BundleClientEntriesResult,
|
|
9
9
|
CLIENT_BUNDLE_NAMING,
|
|
10
|
+
type ClientBundleTarget,
|
|
10
11
|
type ClientManifest,
|
|
11
12
|
type MetafileOutput,
|
|
12
13
|
type OpaqueEntryAliases,
|
|
@@ -25,6 +26,7 @@ export class ClientEntriesBundler {
|
|
|
25
26
|
#externalSubpaths: readonly string[];
|
|
26
27
|
#externalAliases: Partial<Record<string, string>>;
|
|
27
28
|
#command: "build" | "start";
|
|
29
|
+
#target: ClientBundleTarget;
|
|
28
30
|
#outputSubdir: string;
|
|
29
31
|
#reactFastRefresh: boolean;
|
|
30
32
|
#artifactDir: string;
|
|
@@ -47,6 +49,7 @@ export class ClientEntriesBundler {
|
|
|
47
49
|
this.#externalSubpaths = options.externalSubpaths ?? [];
|
|
48
50
|
this.#externalAliases = options.externalAliases ?? {};
|
|
49
51
|
this.#command = options.command ?? "start";
|
|
52
|
+
this.#target = options.target ?? "browser";
|
|
50
53
|
this.#outputSubdir = options.outputSubdir ?? "client";
|
|
51
54
|
this.#reactFastRefresh = options.reactFastRefresh ?? false;
|
|
52
55
|
this.#artifactDir = `${this.#command === "build" ? this.#app.dist.cwdPath : this.#app.cwdPath}/.akan/artifact`;
|
|
@@ -61,7 +64,7 @@ export class ClientEntriesBundler {
|
|
|
61
64
|
entrypoints: this.#opaqueEntries.entries,
|
|
62
65
|
outdir: this.#outdir,
|
|
63
66
|
splitting: true,
|
|
64
|
-
target:
|
|
67
|
+
target: this.#target,
|
|
65
68
|
format: "esm",
|
|
66
69
|
naming: CLIENT_BUNDLE_NAMING,
|
|
67
70
|
metafile: true,
|
|
@@ -34,7 +34,7 @@ const shouldSkipNodeModule = (absPath: string) => NODE_MODULES_RE.test(absPath)
|
|
|
34
34
|
* the traversal matches the module graph the bundler will actually see.
|
|
35
35
|
*/
|
|
36
36
|
export class GraphClientEntryDiscovery implements ClientEntryDiscovery {
|
|
37
|
-
#akanConfig: AkanConfig
|
|
37
|
+
#akanConfig: Pick<AkanConfig, "barrelImports">;
|
|
38
38
|
#resolvePackage: PackageResolver;
|
|
39
39
|
#analyzer: BarrelAnalyzer;
|
|
40
40
|
#tsTranspiler = new Bun.Transpiler({ loader: "tsx" });
|
|
@@ -57,7 +57,7 @@ export class GraphClientEntryDiscovery implements ClientEntryDiscovery {
|
|
|
57
57
|
#unresolvedPaths = new Set<string>();
|
|
58
58
|
#unresolvedSpecifiers = new Set<string>();
|
|
59
59
|
|
|
60
|
-
constructor(akanConfig: AkanConfig, resolvePackage: PackageResolver) {
|
|
60
|
+
constructor(akanConfig: Pick<AkanConfig, "barrelImports">, resolvePackage: PackageResolver) {
|
|
61
61
|
this.#akanConfig = akanConfig;
|
|
62
62
|
this.#resolvePackage = resolvePackage;
|
|
63
63
|
this.#analyzer = new BarrelAnalyzer({ resolvePackage });
|
|
@@ -1,14 +1,18 @@
|
|
|
1
1
|
import { mkdir, rm, unlink } from "node:fs/promises";
|
|
2
2
|
import path from "node:path";
|
|
3
3
|
import type { BaseBuildArtifact } from "akanjs/server";
|
|
4
|
-
import { resolveSsrPageEntriesForApp } from "../artifact/implicitRootLayout";
|
|
4
|
+
import { type PageEntry, resolveSsrPageEntriesForApp } from "../artifact/implicitRootLayout";
|
|
5
5
|
import type { App } from "../commandDecorators";
|
|
6
|
+
import { getPageKeyBasePath } from "./cssCompiler";
|
|
7
|
+
import { PagesBundleBuilder } from "./pagesBundleBuilder";
|
|
6
8
|
import { PagesEntrySourceGenerator } from "./pagesEntrySourceGenerator";
|
|
7
9
|
|
|
8
10
|
export interface BuildCsrArtifactResult {
|
|
9
11
|
outputDir: string;
|
|
10
12
|
}
|
|
11
13
|
|
|
14
|
+
type CssAsset = NonNullable<BaseBuildArtifact["cssAssets"]>[string];
|
|
15
|
+
|
|
12
16
|
export class CsrArtifactBuilder {
|
|
13
17
|
#app: App;
|
|
14
18
|
#command: "build" | "start";
|
|
@@ -29,31 +33,39 @@ export class CsrArtifactBuilder {
|
|
|
29
33
|
|
|
30
34
|
const pageEntries = await resolveSsrPageEntriesForApp(this.#app, pageKeys);
|
|
31
35
|
const akanConfig = await this.#app.getConfig();
|
|
32
|
-
const
|
|
33
|
-
const
|
|
34
|
-
const
|
|
36
|
+
const cssAssets = await this.#loadCssAssets();
|
|
37
|
+
const basePaths = [...akanConfig.basePaths];
|
|
38
|
+
const htmlBasePaths = basePaths.length > 0 ? basePaths : [""];
|
|
35
39
|
await rm(this.#outputDir, { recursive: true, force: true });
|
|
36
|
-
await mkdir(
|
|
37
|
-
const
|
|
40
|
+
await mkdir(this.#generatedDir, { recursive: true });
|
|
41
|
+
const generatedFiles = Object.fromEntries(
|
|
42
|
+
(
|
|
43
|
+
await Promise.all(
|
|
44
|
+
htmlBasePaths.map(async (basePath) => [
|
|
45
|
+
this.#createHtmlFile(basePath),
|
|
46
|
+
await this.#createEntryFile(
|
|
47
|
+
basePath,
|
|
48
|
+
CsrArtifactBuilder.pageEntriesForBasePath(pageEntries, basePath, basePaths),
|
|
49
|
+
),
|
|
50
|
+
]),
|
|
51
|
+
)
|
|
52
|
+
).flat(),
|
|
53
|
+
);
|
|
38
54
|
|
|
39
55
|
const result = await Bun.build({
|
|
40
56
|
target: "browser",
|
|
41
|
-
entrypoints:
|
|
42
|
-
files:
|
|
43
|
-
|
|
44
|
-
[`${this.#app.cwdPath}/.akan/generated/csr/csr.tsx`]: `
|
|
45
|
-
import { bootCsr } from "akanjs/webkit";
|
|
46
|
-
${PagesEntrySourceGenerator.generateStatic(pageEntries)}
|
|
47
|
-
void bootCsr(pages);
|
|
48
|
-
`,
|
|
49
|
-
},
|
|
50
|
-
root: `${this.#app.cwdPath}/.akan/generated/csr`,
|
|
57
|
+
entrypoints: htmlBasePaths.map((basePath) => this.#generatedPath(CsrArtifactBuilder.htmlFilename(basePath))),
|
|
58
|
+
files: generatedFiles,
|
|
59
|
+
root: this.#generatedDir,
|
|
51
60
|
outdir: this.#outputDir,
|
|
52
61
|
splitting: false,
|
|
53
62
|
minify: true,
|
|
54
63
|
env: "AKAN_PUBLIC_*",
|
|
55
64
|
define: this.#define(),
|
|
56
65
|
optimizeImports: akanConfig.optimizeImports,
|
|
66
|
+
// The base artifact's compiled sheet is the only stylesheet, as it is for SSR: a raw `.css` reached through
|
|
67
|
+
// the route graph is Tailwind source, and every root layout stylesheet in the graph would land in every HTML.
|
|
68
|
+
plugins: [PagesBundleBuilder.createCssStubPlugin()],
|
|
57
69
|
});
|
|
58
70
|
|
|
59
71
|
if (!result.success) {
|
|
@@ -61,11 +73,32 @@ void bootCsr(pages);
|
|
|
61
73
|
throw new Error(`[csr-build] failed${logs ? `\n${logs}` : ""}`);
|
|
62
74
|
}
|
|
63
75
|
|
|
64
|
-
await this.#inlineCsrArtifacts(
|
|
76
|
+
await this.#inlineCsrArtifacts(cssAssets);
|
|
65
77
|
this.#app.verbose(`[csr-build] output -> ${this.#outputDir}`);
|
|
66
78
|
return { outputDir: this.#outputDir };
|
|
67
79
|
}
|
|
68
80
|
|
|
81
|
+
/** The routes one basePath's HTML boots: its own plus every route outside any basePath, matching `bootCsr`. */
|
|
82
|
+
static pageEntriesForBasePath(pageEntries: PageEntry[], basePath: string, basePaths: string[]): PageEntry[] {
|
|
83
|
+
return pageEntries.filter((entry) => {
|
|
84
|
+
const entryBasePath = getPageKeyBasePath(entry.key, basePaths);
|
|
85
|
+
return entryBasePath === null || entryBasePath === basePath;
|
|
86
|
+
});
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
static htmlFilename(basePath: string): string {
|
|
90
|
+
return `${basePath || "index"}.html`;
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
static entryFilename(basePath: string): string {
|
|
94
|
+
return `${basePath || "index"}.csr.tsx`;
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
static basePathOfHtml(htmlPath: string): string {
|
|
98
|
+
const name = path.basename(htmlPath, ".html");
|
|
99
|
+
return name === "index" ? "" : name;
|
|
100
|
+
}
|
|
101
|
+
|
|
69
102
|
get #outputDir(): string {
|
|
70
103
|
return path.join(
|
|
71
104
|
this.#command === "build" ? this.#app.dist.cwdPath : this.#app.cwdPath,
|
|
@@ -73,6 +106,18 @@ void bootCsr(pages);
|
|
|
73
106
|
);
|
|
74
107
|
}
|
|
75
108
|
|
|
109
|
+
get #generatedDir(): string {
|
|
110
|
+
return path.join(this.#app.cwdPath, ".akan/generated/csr");
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
get #artifactDir(): string {
|
|
114
|
+
return path.join(this.#command === "build" ? this.#app.dist.cwdPath : this.#app.cwdPath, ".akan/artifact");
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
#generatedPath(filename: string): string {
|
|
118
|
+
return path.join(this.#generatedDir, filename);
|
|
119
|
+
}
|
|
120
|
+
|
|
76
121
|
#define(): Record<string, string> {
|
|
77
122
|
const nodeEnv = this.#command === "build" ? "production" : (process.env.NODE_ENV ?? "development");
|
|
78
123
|
return {
|
|
@@ -84,10 +129,19 @@ void bootCsr(pages);
|
|
|
84
129
|
};
|
|
85
130
|
}
|
|
86
131
|
|
|
132
|
+
async #createEntryFile(basePath: string, pageEntries: PageEntry[]): Promise<readonly [string, string]> {
|
|
133
|
+
return [
|
|
134
|
+
this.#generatedPath(CsrArtifactBuilder.entryFilename(basePath)),
|
|
135
|
+
`import { bootCsr } from "akanjs/webkit";
|
|
136
|
+
${await PagesEntrySourceGenerator.generateStatic(pageEntries)}
|
|
137
|
+
void bootCsr(pages);
|
|
138
|
+
`,
|
|
139
|
+
] as const;
|
|
140
|
+
}
|
|
141
|
+
|
|
87
142
|
#createHtmlFile(basePath: string): readonly [string, string] {
|
|
88
|
-
const filename = `${basePath}.html`;
|
|
89
143
|
return [
|
|
90
|
-
|
|
144
|
+
this.#generatedPath(CsrArtifactBuilder.htmlFilename(basePath)),
|
|
91
145
|
`<!doctype html>
|
|
92
146
|
<html lang="${this.#lang}">
|
|
93
147
|
<head>
|
|
@@ -98,41 +152,40 @@ void bootCsr(pages);
|
|
|
98
152
|
</head>
|
|
99
153
|
<body>
|
|
100
154
|
<div id="root"></div>
|
|
101
|
-
<script type="module" src="
|
|
155
|
+
<script type="module" src="./${CsrArtifactBuilder.entryFilename(basePath)}"></script>
|
|
102
156
|
</body>
|
|
103
157
|
</html>
|
|
104
158
|
`,
|
|
105
159
|
] as const;
|
|
106
160
|
}
|
|
107
161
|
|
|
108
|
-
async #
|
|
109
|
-
const
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
const artifactFile = Bun.file(path.join(artifactDir, "base-artifact.json"));
|
|
114
|
-
if (!(await artifactFile.exists())) return { cssAssets: {} };
|
|
115
|
-
const artifact = (await artifactFile.json()) as Pick<BaseBuildArtifact, "cssAssets">;
|
|
116
|
-
return { cssAssets: artifact.cssAssets ?? {} };
|
|
162
|
+
async #loadCssAssets(): Promise<Record<string, CssAsset>> {
|
|
163
|
+
const artifactFile = Bun.file(path.join(this.#artifactDir, "base-artifact.json"));
|
|
164
|
+
if (!(await artifactFile.exists())) return {};
|
|
165
|
+
const artifact = (await artifactFile.json()) as Partial<Pick<BaseBuildArtifact, "cssAssets">>;
|
|
166
|
+
return artifact.cssAssets ?? {};
|
|
117
167
|
}
|
|
118
168
|
|
|
119
|
-
async #inlineCsrArtifacts(cssAssets: Record<string,
|
|
169
|
+
async #inlineCsrArtifacts(cssAssets: Record<string, CssAsset>): Promise<void> {
|
|
120
170
|
const jsFiles = new Set<string>();
|
|
121
|
-
const cssFiles = new Set<string>();
|
|
122
171
|
for (const htmlPath of await this.#htmlOutputPaths()) {
|
|
123
172
|
const htmlFile = Bun.file(htmlPath);
|
|
124
173
|
if (!(await htmlFile.exists())) continue;
|
|
125
|
-
const basePath =
|
|
126
|
-
const
|
|
174
|
+
const basePath = CsrArtifactBuilder.basePathOfHtml(htmlPath);
|
|
175
|
+
const cssAsset = cssAssets[basePath];
|
|
176
|
+
if (!cssAsset) {
|
|
177
|
+
this.#app.logger.warn(
|
|
178
|
+
`[csr-build] base-artifact.json has no compiled stylesheet for ${basePath || "root"}; ${path.basename(htmlPath)} ships without CSS`,
|
|
179
|
+
);
|
|
180
|
+
}
|
|
181
|
+
const inlined = await this.#inlineHtmlAssets(await htmlFile.text(), htmlPath, cssAsset);
|
|
127
182
|
for (const filePath of inlined.jsFiles) jsFiles.add(filePath);
|
|
128
|
-
for (const filePath of inlined.cssFiles) cssFiles.add(filePath);
|
|
129
183
|
await Bun.write(htmlPath, inlined.html);
|
|
130
184
|
}
|
|
131
185
|
for (const filePath of jsFiles) await unlink(filePath).catch(() => undefined);
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
const remainingAssets = [...remainingJs, ...remainingCss];
|
|
186
|
+
const remainingAssets = await this.#listOutputFiles(
|
|
187
|
+
(filePath) => filePath.endsWith(".js") || filePath.endsWith(".css"),
|
|
188
|
+
);
|
|
136
189
|
if (remainingAssets.length > 0) {
|
|
137
190
|
throw new Error(`[csr-build] expected single-file HTML, but CSR assets remain:\n${remainingAssets.join("\n")}`);
|
|
138
191
|
}
|
|
@@ -141,44 +194,20 @@ void bootCsr(pages);
|
|
|
141
194
|
async #inlineHtmlAssets(
|
|
142
195
|
html: string,
|
|
143
196
|
htmlPath: string,
|
|
144
|
-
cssAsset?:
|
|
145
|
-
): Promise<{ html: string; jsFiles: string[]
|
|
197
|
+
cssAsset?: CssAsset,
|
|
198
|
+
): Promise<{ html: string; jsFiles: string[] }> {
|
|
199
|
+
let next = html;
|
|
200
|
+
if (cssAsset) {
|
|
201
|
+
const css = await Bun.file(path.join(this.#artifactDir, cssAsset.cssRelPath)).text();
|
|
202
|
+
next = CsrArtifactBuilder.injectBeforeHeadEnd(next, CsrArtifactBuilder.createInlineStyle(css));
|
|
203
|
+
}
|
|
146
204
|
const jsFiles: string[] = [];
|
|
147
|
-
const cssFiles = CsrArtifactBuilder.collectStylesheetHrefs(html).map((href) =>
|
|
148
|
-
CsrArtifactBuilder.resolveHtmlAssetPath(htmlPath, href),
|
|
149
|
-
);
|
|
150
|
-
let next = CsrArtifactBuilder.stripBundledStylesheetLinks(html);
|
|
151
205
|
next = await CsrArtifactBuilder.replaceModuleScriptSrc(next, async (src) => {
|
|
152
206
|
const jsPath = CsrArtifactBuilder.resolveHtmlAssetPath(htmlPath, src);
|
|
153
207
|
jsFiles.push(jsPath);
|
|
154
208
|
return await Bun.file(jsPath).text();
|
|
155
209
|
});
|
|
156
|
-
|
|
157
|
-
await Promise.all(
|
|
158
|
-
cssFiles.map((cssFile) =>
|
|
159
|
-
Bun.file(cssFile)
|
|
160
|
-
.text()
|
|
161
|
-
.catch(() => ""),
|
|
162
|
-
),
|
|
163
|
-
)
|
|
164
|
-
)
|
|
165
|
-
.filter(Boolean)
|
|
166
|
-
.join("\n");
|
|
167
|
-
if (bundledCss) {
|
|
168
|
-
const style = CsrArtifactBuilder.createInlineStyle(bundledCss);
|
|
169
|
-
if (!next.includes(style)) next = CsrArtifactBuilder.injectBeforeHeadEnd(next, style);
|
|
170
|
-
}
|
|
171
|
-
if (cssAsset) {
|
|
172
|
-
const cssPath = path.join(
|
|
173
|
-
this.#command === "build" ? this.#app.dist.cwdPath : this.#app.cwdPath,
|
|
174
|
-
".akan/artifact",
|
|
175
|
-
cssAsset.cssRelPath,
|
|
176
|
-
);
|
|
177
|
-
const css = await Bun.file(cssPath).text();
|
|
178
|
-
const style = CsrArtifactBuilder.createInlineStyle(css);
|
|
179
|
-
if (!next.includes(style)) next = CsrArtifactBuilder.injectBeforeHeadEnd(next, style);
|
|
180
|
-
}
|
|
181
|
-
return { html: next, jsFiles, cssFiles };
|
|
210
|
+
return { html: next, jsFiles };
|
|
182
211
|
}
|
|
183
212
|
|
|
184
213
|
async #htmlOutputPaths(): Promise<string[]> {
|
|
@@ -194,23 +223,26 @@ void bootCsr(pages);
|
|
|
194
223
|
return files.sort();
|
|
195
224
|
}
|
|
196
225
|
|
|
226
|
+
/**
|
|
227
|
+
* Bun's HTML bundler hoists the module script into `<head>`, so once that script is inline its source is part
|
|
228
|
+
* of the text being searched — and a React bundle contains `<body` and `</head>` as strings. Positions are
|
|
229
|
+
* taken on a copy with script, style and comment bodies blanked, and the snippet always lands after whatever
|
|
230
|
+
* was injected before it: prepending would reverse the cascade order the caller chose.
|
|
231
|
+
*/
|
|
197
232
|
static injectBeforeHeadEnd(html: string, snippet: string): string {
|
|
198
|
-
const
|
|
199
|
-
const
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
return `${html.slice(0, headEnd.index)}${snippet}\n${html.slice(headEnd.index)}`;
|
|
205
|
-
}
|
|
206
|
-
|
|
207
|
-
static stripBundledStylesheetLinks(html: string): string {
|
|
208
|
-
return html.replace(/<link\b(?=[^>]*\brel=["']stylesheet["'])[^>]*>\s*/gi, "");
|
|
233
|
+
const scannable = CsrArtifactBuilder.blankEmbeddedContent(html);
|
|
234
|
+
const headEnd = scannable.search(/<\/head\s*>/i);
|
|
235
|
+
if (headEnd !== -1) return `${html.slice(0, headEnd)}${snippet}\n${html.slice(headEnd)}`;
|
|
236
|
+
const bodyStart = scannable.search(/<body(?:\s|>)/i);
|
|
237
|
+
if (bodyStart !== -1) return `${html.slice(0, bodyStart)}${snippet}\n${html.slice(bodyStart)}`;
|
|
238
|
+
return `${html}\n${snippet}`;
|
|
209
239
|
}
|
|
210
240
|
|
|
211
|
-
static
|
|
212
|
-
|
|
213
|
-
|
|
241
|
+
static blankEmbeddedContent(html: string): string {
|
|
242
|
+
return html.replace(
|
|
243
|
+
/<script\b[^>]*>[\s\S]*?<\/script\s*>|<style\b[^>]*>[\s\S]*?<\/style\s*>|<!--[\s\S]*?-->/gi,
|
|
244
|
+
(match) => " ".repeat(match.length),
|
|
245
|
+
);
|
|
214
246
|
}
|
|
215
247
|
|
|
216
248
|
static createInlineStyle(css: string): string {
|