@homepages/concrete 4.0.0 → 6.0.0
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 +359 -0
- package/README.md +28 -17
- package/codemods/fill-is-a-source.mjs +533 -0
- package/codemods/manifest.json +18 -0
- package/codemods/reads-replace-reconcile.mjs +285 -0
- package/dist/artifact/playground/client/assets/{index-D1fwOGVK.js → index-u3T7DiSN.js} +96 -96
- package/dist/artifact/playground/client/index.html +1 -1
- package/dist/artifact/playground/host.mjs +23 -23
- package/dist/base.css +3 -8
- package/dist/browser/site-config.js +1 -16
- package/dist/browser/submit-lead.js +0 -31
- package/dist/cli/build/artifact.js +16 -23
- package/dist/cli/build/captures.js +0 -6
- package/dist/cli/build/esbuild.js +0 -17
- package/dist/cli/build/fixtures.js +15 -30
- package/dist/cli/build/icons.js +0 -3
- package/dist/cli/build/index.js +1 -1
- package/dist/cli/build/playground.js +4 -8
- package/dist/cli/build/sections.js +9 -30
- package/dist/cli/build/source.js +52 -27
- package/dist/cli/build/static.js +4 -25
- package/dist/cli/capture/bundle.js +0 -9
- package/dist/cli/capture/capture-browser.js +0 -14
- package/dist/cli/capture/capture.js +1 -8
- package/dist/cli/check/analyze.js +2 -5
- package/dist/cli/check/index.js +1 -1
- package/dist/cli/check/line-endings.js +52 -0
- package/dist/cli/check/load-workspace.js +3 -8
- package/dist/cli/check/portable-names.js +48 -0
- package/dist/cli/check/render/class-conflicts.js +0 -5
- package/dist/cli/check/render/html.js +0 -1
- package/dist/cli/check/render/invariants.js +0 -5
- package/dist/cli/check/render/island-frames.js +0 -25
- package/dist/cli/check/render/marker-coverage.js +0 -20
- package/dist/cli/check/render/nav.js +0 -33
- package/dist/cli/check/report.js +0 -3
- package/dist/cli/check/stages/bundles.js +1 -9
- package/dist/cli/check/stages/composition.js +3 -2
- package/dist/cli/check/stages/dependencies.js +7 -38
- package/dist/cli/check/stages/fixtures.js +3 -31
- package/dist/cli/check/stages/lint.js +2 -2
- package/dist/cli/check/stages/logic.js +3 -34
- package/dist/cli/check/stages/relations.js +46 -0
- package/dist/cli/check/stages/render.js +0 -1
- package/dist/cli/check/stages/sections.js +3 -3
- package/dist/cli/check/stages/stylesheet.js +1 -1
- package/dist/cli/check/stages/typecheck.js +5 -11
- package/dist/cli/check/stages/workspace.js +36 -14
- package/dist/cli/commands.js +9 -56
- package/dist/cli/currency/cache.js +4 -17
- package/dist/cli/currency/decide.js +0 -14
- package/dist/cli/currency/opt-out.js +0 -7
- package/dist/cli/currency/preamble.js +3 -24
- package/dist/cli/currency/prompt.js +0 -1
- package/dist/cli/currency/refresh.js +5 -12
- package/dist/cli/currency/resolve-latest.js +3 -64
- package/dist/cli/currency/version-order.js +0 -12
- package/dist/cli/dev/crop.js +0 -2
- package/dist/cli/dev/http.js +0 -13
- package/dist/cli/dev/index.js +3 -4
- package/dist/cli/dev/islands.js +25 -70
- package/dist/cli/dev/listen.js +26 -0
- package/dist/cli/dev/load-template.js +0 -1
- package/dist/cli/dev/request-error.js +0 -4
- package/dist/cli/dev/server.js +46 -52
- package/dist/cli/dev/tsconfig-paths.js +0 -13
- package/dist/cli/dev/vite.js +9 -38
- package/dist/cli/dev/workspace-reader.js +4 -34
- package/dist/cli/media/cache.js +4 -51
- package/dist/cli/media/derive.js +2 -94
- package/dist/cli/media/deriver-plugin.js +0 -2
- package/dist/cli/media/frame-rung-floor.js +0 -6
- package/dist/cli/property/index.js +0 -4
- package/dist/cli/property/library.js +6 -24
- package/dist/cli/publish/client.js +0 -1
- package/dist/cli/publish/freshness.js +0 -2
- package/dist/cli/publish/git.js +2 -8
- package/dist/cli/publish/index.js +8 -15
- package/dist/cli/publish/pack.js +5 -6
- package/dist/cli/publish/report.js +0 -6
- package/dist/cli/publish/target.js +16 -13
- package/dist/cli/publish/wire.js +0 -6
- package/dist/cli/tar.js +2 -9
- package/dist/cli/upgrade/codemod.js +0 -8
- package/dist/cli/upgrade/index.js +0 -24
- package/dist/cli/upgrade/manifest.js +0 -12
- package/dist/cli/upgrade/plan.js +0 -17
- package/dist/cli/upgrade/stage.js +12 -15
- package/dist/cli/version.js +0 -8
- package/dist/cli/workspace.js +2 -34
- package/dist/cli.js +4 -21
- package/dist/css/compile.js +25 -28
- package/dist/css/graph.js +3 -10
- package/dist/css/inline.js +3 -13
- package/dist/css/rules.js +6 -43
- package/dist/design-system/format-variants.js +0 -22
- package/dist/eslint/authoring.js +0 -2
- package/dist/eslint/correctness.js +0 -7
- package/dist/eslint/rules/editor-reason.js +0 -11
- package/dist/eslint/rules/island-ids.js +0 -1
- package/dist/eslint/rules/jsx-visitor.js +0 -13
- package/dist/eslint/rules/no-editor-globals.js +0 -2
- package/dist/eslint/rules/no-raw-values.js +0 -1
- package/dist/fixtures/brand.js +0 -1
- package/dist/fixtures/bundle-rule.js +4 -9
- package/dist/fixtures/canonical.d.ts +20 -0
- package/dist/fixtures/image-dimensions.js +0 -1
- package/dist/fixtures/load.js +8 -17
- package/dist/fixtures/media-plugin.js +4 -31
- package/dist/fixtures/media.js +0 -21
- package/dist/fixtures/package-stylesheets.js +0 -6
- package/dist/fixtures/property.js +16 -15
- package/dist/fixtures/resolve.js +102 -29
- package/dist/fixtures/rows.js +12 -11
- package/dist/fixtures/synthesize-empties.js +0 -4
- package/dist/fixtures.d.ts +19 -4
- package/dist/fixtures.js +0 -18
- package/dist/index.d.ts +8 -9
- package/dist/index.js +2 -11
- package/dist/islands/client-module.js +0 -11
- package/dist/islands/marker.js +0 -33
- package/dist/node_modules/.pnpm/fflate@0.8.3/node_modules/fflate/esm/browser.js +0 -20
- package/dist/packages/external/concrete/package.js +1 -1
- package/dist/packages/internal/fill-bake/dist/bake-property-ref.js +22 -36
- package/dist/packages/internal/fill-bake/dist/compute-reads.js +4 -0
- package/dist/packages/internal/fill-bake/dist/derive-source.js +40 -0
- package/dist/packages/internal/fill-bake/dist/display.js +0 -1
- package/dist/packages/internal/fill-bake/dist/index.js +4 -4
- package/dist/packages/internal/fill-vocabulary/dist/origination.js +106 -0
- package/dist/packages/internal/fill-vocabulary/dist/row-planners.js +1 -49
- package/dist/packages/internal/format-geometry/dist/capture.js +10 -240
- package/dist/packages/internal/format-geometry/dist/geometry.js +0 -6
- package/dist/packages/internal/image-ladder/dist/crop.js +0 -12
- package/dist/packages/internal/image-ladder/dist/policy.js +0 -14
- package/dist/packages/internal/island-runtime/dist/capture-holds.js +0 -13
- package/dist/packages/internal/island-runtime/dist/contract.js +0 -34
- package/dist/packages/internal/island-runtime/dist/editor-instance-context.js +0 -1
- package/dist/packages/internal/island-runtime/dist/index.js +0 -34
- package/dist/packages/internal/island-runtime/dist/island-id-context.js +0 -1
- package/dist/packages/internal/island-runtime/dist/use-capture-ready.js +0 -15
- package/dist/packages/internal/island-runtime/dist/use-editor.js +0 -10
- package/dist/packages/internal/island-runtime/dist/use-island-id.js +0 -32
- package/dist/packages/internal/property-facts/dist/derive-facts-view.js +2 -17
- package/dist/packages/internal/property-facts/dist/index.js +1 -1
- package/dist/packages/internal/property-facts/dist/{property-facts-CSdkSuD7.js → property-facts-5pxZnlkh.js} +13 -2
- package/dist/packages/internal/section-contracts/dist/cap-contract.js +1 -18
- package/dist/packages/internal/section-contracts/dist/catalog.js +16 -8
- package/dist/packages/internal/section-contracts/dist/choose-select-contract.js +12 -16
- package/dist/packages/internal/section-contracts/dist/count-bounds-contract.js +5 -11
- package/dist/packages/internal/section-contracts/dist/display-contract.js +2 -0
- package/dist/packages/internal/section-contracts/dist/display-evidence-contract.js +2 -8
- package/dist/packages/internal/section-contracts/dist/fill-spec-view.js +13 -0
- package/dist/packages/internal/section-contracts/dist/index.js +2 -1
- package/dist/packages/internal/section-contracts/dist/interpolation-contract.js +16 -42
- package/dist/packages/internal/section-contracts/dist/list-fill-contract.js +24 -43
- package/dist/packages/internal/section-contracts/dist/name-title-contract.js +11 -18
- package/dist/packages/internal/section-contracts/dist/poi-curation-contract.js +10 -12
- package/dist/packages/internal/section-contracts/dist/pooling-field-contract.js +3 -13
- package/dist/packages/internal/section-contracts/dist/row-fill-contract.js +6 -18
- package/dist/packages/internal/section-contracts/dist/runners.js +21 -13
- package/dist/packages/internal/section-contracts/dist/source-contract.js +13 -2
- package/dist/packages/internal/section-contracts/dist/writer-reads-fact-contract.js +31 -0
- package/dist/packages/internal/source-resolution/dist/index.js +5 -30
- package/dist/packages/internal/template-artifact/dist/hash.js +0 -8
- package/dist/packages/internal/template-artifact/dist/index.js +1 -1
- package/dist/packages/internal/template-artifact/dist/layout.js +0 -39
- package/dist/packages/internal/template-artifact/dist/manifest.js +1 -9
- package/dist/packages/internal/template-artifact/dist/sha256.js +0 -1
- package/dist/packages/internal/template-artifact/dist/verify.js +2 -4
- package/dist/packages/internal/template-contracts/dist/collection-editing.js +0 -16
- package/dist/packages/internal/template-contracts/dist/content-categories.js +0 -4
- package/dist/packages/internal/template-contracts/dist/facts-view.d.ts +16 -10
- package/dist/packages/internal/template-contracts/dist/facts-view.js +15 -28
- package/dist/packages/internal/template-contracts/dist/layout.js +0 -7
- package/dist/packages/internal/template-contracts/dist/markers.js +0 -29
- package/dist/packages/internal/template-contracts/dist/select-key.js +0 -6
- package/dist/packages/internal/template-contracts/dist/slot-catalog.d.ts +56 -34
- package/dist/packages/internal/template-contracts/dist/slot-catalog.js +22 -389
- package/dist/platform/file-url.js +8 -0
- package/dist/platform/fs.js +73 -0
- package/dist/platform/names.js +63 -0
- package/dist/platform/order.js +7 -0
- package/dist/platform/paths.js +62 -0
- package/dist/platform/process.js +97 -0
- package/dist/playground/host/page-state.js +0 -2
- package/dist/playground/host/paths.js +0 -1
- package/dist/playground/layout.js +0 -7
- package/dist/playground/wire.js +0 -8
- package/dist/primitives/FrameShell.js +0 -18
- package/dist/primitives/Image.d.ts +5 -1
- package/dist/primitives/Image.js +2 -68
- package/dist/primitives/Section.js +0 -13
- package/dist/primitives/Tour.js +0 -26
- package/dist/primitives/Video.js +0 -32
- package/dist/primitives/embed-playback.js +0 -1
- package/dist/primitives/marker-attrs.js +0 -17
- package/dist/primitives/picture-sources.js +6 -1
- package/dist/primitives/probe-context.js +0 -7
- package/dist/primitives/slot-bindings.d.ts +3 -2
- package/dist/primitives/slot-bindings.js +0 -46
- package/dist/primitives/slot-document.js +0 -11
- package/dist/primitives/slot-group.js +0 -9
- package/dist/primitives/slot-media.js +0 -27
- package/dist/primitives/slot-scalar.js +0 -4
- package/dist/primitives/slot.js +0 -6
- package/dist/rules/registry.js +42 -24
- package/dist/schema/compute.d.ts +46 -8
- package/dist/schema/compute.js +21 -15
- package/dist/schema/define-schema.d.ts +1 -1
- package/dist/schema/define-schema.js +37 -17
- package/dist/schema/extract-fill-spec.js +93 -180
- package/dist/schema/extract-used-facts.js +16 -158
- package/dist/schema/fact.d.ts +33 -18
- package/dist/schema/fact.js +7 -11
- package/dist/schema/fill-builders.d.ts +91 -366
- package/dist/schema/fill-builders.js +21 -259
- package/dist/schema/fill-declaration.d.ts +7 -69
- package/dist/schema/fill-declaration.js +5 -34
- package/dist/schema/fill-spec.js +59 -148
- package/dist/schema/format-presets.js +0 -12
- package/dist/schema/format.js +0 -7
- package/dist/schema/layout.js +0 -10
- package/dist/schema/manifest.js +0 -39
- package/dist/schema/property-facts.d.ts +20 -0
- package/dist/schema/runtime-values.d.ts +6 -18
- package/dist/schema/section-nav.js +0 -15
- package/dist/schema/section-props.d.ts +7 -9
- package/dist/schema/section-schema.d.ts +0 -1
- package/dist/schema/section-schema.js +4 -20
- package/dist/schema/slot-builders.d.ts +128 -117
- package/dist/schema/slot-builders.js +18 -201
- package/dist/schema/slot-ref.d.ts +63 -0
- package/dist/schema/slot-ref.js +33 -0
- package/dist/schema/slot-types.d.ts +3 -2
- package/dist/schema/slot-types.js +11 -20
- package/dist/section/declare.d.ts +14 -10
- package/dist/section/declare.js +13 -2
- package/dist/section/discovery.js +6 -21
- package/dist/section/groups.js +0 -6
- package/dist/section/materialize.js +0 -5
- package/dist/section/placements.js +0 -4
- package/dist/section/section.d.ts +8 -5
- package/dist/section/section.js +7 -29
- package/dist/styles.css +5 -0
- package/dist/template/define-template.d.ts +0 -4
- package/dist/template/define-template.js +1 -15
- package/dist/template/logic-build.js +8 -35
- package/dist/template/logic-shim.d.ts +4 -5
- package/dist/template/logic-shim.js +2 -6
- package/dist/template/logic-transform.js +0 -6
- package/dist/template/materialize.js +52 -43
- package/dist/template/mirror-types.js +43 -0
- package/dist/template/running-copy.js +5 -20
- package/dist/template/section-reads.js +83 -0
- package/guide/reference/cli/INDEX.md +12 -6
- package/guide/reference/cli/build.md +1 -1
- package/guide/reference/cli/check.md +1 -1
- package/guide/reference/cli/dev.md +3 -3
- package/guide/reference/cli/property-add.md +1 -1
- package/guide/reference/cli/property-list.md +1 -1
- package/guide/reference/cli/publish.md +4 -2
- package/guide/reference/cli/upgrade.md +1 -1
- package/guide/reference/rules/INDEX.md +26 -13
- package/package.json +4 -2
- package/dist/packages/internal/fact-interpolation/dist/index.js +0 -22
- package/dist/packages/internal/fill-bake/dist/reconcile-cross-section.js +0 -170
- package/dist/packages/internal/fill-vocabulary/dist/facts.d.ts +0 -32
- package/dist/packages/internal/fill-vocabulary/dist/facts.js +0 -131
- package/dist/packages/internal/template-contracts/dist/slot-overrides.js +0 -11
- package/dist/schema/fill-spec.d.ts +0 -18
- package/dist/template/reconcile.d.ts +0 -67
- package/dist/template/reconcile.js +0 -25
package/dist/cli/dev/index.js
CHANGED
|
@@ -1,22 +1,21 @@
|
|
|
1
|
+
import { onShutdown } from "../../platform/process.js";
|
|
1
2
|
import { findCommand, flagDefault, parseSpec, stringFlag } from "../commands.js";
|
|
3
|
+
import { findWorkspaceRoot } from "../workspace.js";
|
|
2
4
|
import { TEMPLATE_FILE } from "./workspace-reader.js";
|
|
3
5
|
import { startDevServer } from "./server.js";
|
|
4
|
-
import { findWorkspaceRoot } from "../workspace.js";
|
|
5
6
|
import { existsSync } from "node:fs";
|
|
6
7
|
import { join } from "node:path";
|
|
7
8
|
import { parseArgs } from "node:util";
|
|
8
9
|
|
|
9
10
|
//#region src/cli/dev/index.ts
|
|
10
11
|
const DEFAULT_PORT = Number(flagDefault(findCommand("dev"), "port"));
|
|
11
|
-
/** The port a `--port` value names: a positive integer, else the default. */
|
|
12
12
|
function parsePort(raw) {
|
|
13
13
|
if (raw === null) return DEFAULT_PORT;
|
|
14
14
|
const port = Number(raw);
|
|
15
15
|
return Number.isInteger(port) && port > 0 ? port : DEFAULT_PORT;
|
|
16
16
|
}
|
|
17
17
|
const processSignals = () => new Promise((resolveStop) => {
|
|
18
|
-
|
|
19
|
-
process.once("SIGTERM", () => resolveStop());
|
|
18
|
+
onShutdown(resolveStop);
|
|
20
19
|
});
|
|
21
20
|
function createDevRunner(deps) {
|
|
22
21
|
return async (argv, io) => {
|
package/dist/cli/dev/islands.js
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import { CAPTURE_ISLANDS_READY_GLOBAL } from "../../packages/internal/format-geometry/dist/capture.js";
|
|
2
2
|
import "../../packages/internal/format-geometry/dist/index.js";
|
|
3
3
|
import { hasClientDirective } from "../../islands/client-module.js";
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
4
|
+
import { isWorkspaceFile, packageFile, toPosix } from "../../platform/paths.js";
|
|
5
|
+
import { listDirSync } from "../../platform/fs.js";
|
|
6
|
+
import { readFileSync } from "node:fs";
|
|
7
|
+
import nodePath, { dirname, extname, join, relative } from "node:path";
|
|
7
8
|
import { mkdir, readFile, writeFile } from "node:fs/promises";
|
|
8
9
|
import { createHash } from "node:crypto";
|
|
9
10
|
|
|
@@ -14,12 +15,7 @@ const SKIPPED_DIRS = /* @__PURE__ */ new Set([
|
|
|
14
15
|
"dist",
|
|
15
16
|
".concrete"
|
|
16
17
|
]);
|
|
17
|
-
/** Forward slashes: Vite module ids use them on every platform, `node:path` does not. */
|
|
18
|
-
function toPosixPath(path) {
|
|
19
|
-
return sep === "\\" ? path.replaceAll("\\", "/") : path;
|
|
20
|
-
}
|
|
21
18
|
const SERVER_FRAME = /^[ \t]*export[ \t]+const[ \t]+serverFrame[ \t]*(?::[^=]*)?=[ \t]*(.*)$/m;
|
|
22
|
-
/** Whether a client module declares the literal `serverFrame = false`: no server-rendered first frame. */
|
|
23
19
|
function declaresNoServerFrame(text) {
|
|
24
20
|
const declaration = SERVER_FRAME.exec(text);
|
|
25
21
|
if (!declaration) return false;
|
|
@@ -30,29 +26,29 @@ function declaresNoServerFrame(text) {
|
|
|
30
26
|
if (rest !== "" && !/^(?:satisfies|as)\b/.test(rest)) return false;
|
|
31
27
|
return literal[1] === "false";
|
|
32
28
|
}
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
29
|
+
function islandKeyFor(root, file, paths = nodePath) {
|
|
30
|
+
const rel = toPosix(paths.relative(root, file), paths);
|
|
31
|
+
const slash = rel.lastIndexOf("/");
|
|
32
|
+
const name = rel.slice(slash + 1);
|
|
33
|
+
const dot = name.lastIndexOf(".");
|
|
34
|
+
return `${rel.slice(0, Math.max(slash, 0))}:${dot > 0 ? name.slice(0, dot) : name}`;
|
|
35
|
+
}
|
|
36
|
+
function workspaceComponentFile(root, id, paths = nodePath) {
|
|
37
|
+
const file = id.split("?")[0] ?? id;
|
|
38
|
+
return COMPONENT_EXTS.has(paths.extname(file)) && isWorkspaceFile(root, file, paths) ? file : null;
|
|
42
39
|
}
|
|
43
|
-
/** Every island module in the workspace, sorted: a `.tsx`/`.jsx` file whose prologue says `"use client"`. */
|
|
44
40
|
function findWorkspaceIslands(root) {
|
|
45
41
|
const out = [];
|
|
46
42
|
const walk = (dir, depth) => {
|
|
47
43
|
let entries;
|
|
48
44
|
try {
|
|
49
|
-
entries =
|
|
45
|
+
entries = listDirSync(dir);
|
|
50
46
|
} catch {
|
|
51
47
|
return;
|
|
52
48
|
}
|
|
53
|
-
for (const entry of entries
|
|
49
|
+
for (const entry of entries) {
|
|
54
50
|
if (entry.name.startsWith(".")) continue;
|
|
55
|
-
const path =
|
|
51
|
+
const path = entry.path;
|
|
56
52
|
if (entry.isDirectory()) {
|
|
57
53
|
if (SKIPPED_DIRS.has(entry.name) || depth === 0 && entry.name === "fixtures") continue;
|
|
58
54
|
walk(path, depth + 1);
|
|
@@ -70,10 +66,9 @@ function findWorkspaceIslands(root) {
|
|
|
70
66
|
walk(root, 0);
|
|
71
67
|
return out;
|
|
72
68
|
}
|
|
73
|
-
/** island key → the root-relative URL Vite serves the module at. */
|
|
74
69
|
function islandMapOf(root, files) {
|
|
75
70
|
const map = {};
|
|
76
|
-
for (const file of files) map[islandKeyFor(root, file)] = `/${
|
|
71
|
+
for (const file of files) map[islandKeyFor(root, file)] = `/${toPosix(relative(root, file))}`;
|
|
77
72
|
return map;
|
|
78
73
|
}
|
|
79
74
|
function markerModule(islandKey, markerSpecifier, children) {
|
|
@@ -91,38 +86,21 @@ export default function __trIslandWrapper(__trProps) {
|
|
|
91
86
|
`;
|
|
92
87
|
}
|
|
93
88
|
const DEFAULT_EXPORT = /export\s+default\s+/;
|
|
94
|
-
/**
|
|
95
|
-
* A client module rewritten so its default export renders through the island marker. The
|
|
96
|
-
* original is rebound to `__trIslandReal` and re-exported under that name: a top-level
|
|
97
|
-
* marker must hydrate the RAW component (the marker's children are its own output),
|
|
98
|
-
* while a nested usage must render the wrapper so its marker is emitted, and one shared
|
|
99
|
-
* Vite module graph serves both. `null` for a non-client module or one with no default.
|
|
100
|
-
*/
|
|
101
89
|
function wrapClientModule(code, islandKey, markerSpecifier) {
|
|
102
90
|
if (!hasClientDirective(code) || !DEFAULT_EXPORT.test(code)) return null;
|
|
103
91
|
return code.replace(DEFAULT_EXPORT, "const __trIslandReal = ") + markerModule(islandKey, markerSpecifier, "\n __trCreateElement(__trIslandReal, __trProps),") + "export { __trIslandReal };\n";
|
|
104
92
|
}
|
|
105
|
-
/** The marker-only module the SERVER graph gets for an island declaring `serverFrame = false`. */
|
|
106
93
|
function stubClientModule(code, islandKey, markerSpecifier) {
|
|
107
94
|
if (!hasClientDirective(code) || !DEFAULT_EXPORT.test(code) || !declaresNoServerFrame(code)) return null;
|
|
108
95
|
return markerModule(islandKey, markerSpecifier, "");
|
|
109
96
|
}
|
|
110
|
-
/**
|
|
111
|
-
* The Vite transform that makes an island of every workspace client module, in both
|
|
112
|
-
* graphs. The browser graph needs the wrap too: a NESTED island is marked in the server
|
|
113
|
-
* HTML, so its parent's client render must emit that marker, or React discards the
|
|
114
|
-
* parent's server tree. The server graph alone stubs an island with no server frame.
|
|
115
|
-
*
|
|
116
|
-
* It must run before the React plugin, which consumes the directive otherwise.
|
|
117
|
-
*/
|
|
118
97
|
function islandTransformPlugin(options) {
|
|
119
|
-
const inside = options.root.endsWith(sep) ? options.root : options.root + sep;
|
|
120
98
|
return {
|
|
121
99
|
name: "concrete-dev:islands",
|
|
122
100
|
enforce: "pre",
|
|
123
101
|
transform(code, id, transformOptions) {
|
|
124
|
-
const file =
|
|
125
|
-
if (
|
|
102
|
+
const file = workspaceComponentFile(options.root, id);
|
|
103
|
+
if (file === null) return null;
|
|
126
104
|
const key = islandKeyFor(options.root, file);
|
|
127
105
|
if (transformOptions?.ssr === true) {
|
|
128
106
|
const stub = stubClientModule(code, key, options.markerSpecifier);
|
|
@@ -139,18 +117,12 @@ function islandTransformPlugin(options) {
|
|
|
139
117
|
}
|
|
140
118
|
};
|
|
141
119
|
}
|
|
142
|
-
/**
|
|
143
|
-
* The same transform for the server graph `concrete dev` renders from, which esbuild
|
|
144
|
-
* bundles (./load-template.ts): a workspace client module is stubbed when it declares no
|
|
145
|
-
* server frame and wrapped otherwise, exactly as the browser graph's Vite plugin does.
|
|
146
|
-
*/
|
|
147
120
|
function islandEsbuildPlugin(options) {
|
|
148
|
-
const inside = options.root.endsWith(sep) ? options.root : options.root + sep;
|
|
149
121
|
return {
|
|
150
122
|
name: "concrete-dev:islands",
|
|
151
123
|
setup(build) {
|
|
152
124
|
build.onLoad({ filter: /\.[jt]sx$/ }, async (args) => {
|
|
153
|
-
if (
|
|
125
|
+
if (workspaceComponentFile(options.root, args.path) === null) return void 0;
|
|
154
126
|
const code = await readFile(args.path, "utf8");
|
|
155
127
|
const key = islandKeyFor(options.root, args.path);
|
|
156
128
|
const contents = stubClientModule(code, key, options.markerSpecifier) ?? wrapClientModule(code, key, options.markerSpecifier);
|
|
@@ -164,21 +136,15 @@ function islandEsbuildPlugin(options) {
|
|
|
164
136
|
}
|
|
165
137
|
};
|
|
166
138
|
}
|
|
167
|
-
/**
|
|
168
|
-
* The island runtime module the host scripts import, by absolute path: the built entry
|
|
169
|
-
* beside this module in dist, or the source module when running from source.
|
|
170
|
-
*/
|
|
171
139
|
function islandRuntimeFile() {
|
|
172
|
-
|
|
173
|
-
return extname(here) === ".ts" ? join(dirname(here), "island-runtime.ts") : join(dirname(here), "..", "..", "playground-island-runtime.js");
|
|
140
|
+
return packageFile("cli/dev/island-runtime.ts", "playground-island-runtime.js");
|
|
174
141
|
}
|
|
175
|
-
/** The `/@fs/` URL Vite serves an absolute file at. */
|
|
176
142
|
function fsUrl(file) {
|
|
177
|
-
return `/@fs/${
|
|
143
|
+
return `/@fs/${toPosix(file).replace(/^\/+/, "")}`;
|
|
178
144
|
}
|
|
179
145
|
function importers(root, files) {
|
|
180
146
|
return `const modules = {\n${files.map((file) => {
|
|
181
|
-
const url = `/${
|
|
147
|
+
const url = `/${toPosix(relative(root, file))}`;
|
|
182
148
|
return ` ${JSON.stringify(url)}: () => import(${JSON.stringify(url)}),`;
|
|
183
149
|
}).join("\n")}\n};`;
|
|
184
150
|
}
|
|
@@ -227,12 +193,6 @@ window.${CAPTURE_ISLANDS_READY_GLOBAL} = ready;
|
|
|
227
193
|
ready.catch(() => {});
|
|
228
194
|
`;
|
|
229
195
|
}
|
|
230
|
-
/**
|
|
231
|
-
* The canvas island host, over whatever reaches the island modules: `concrete dev`'s Vite
|
|
232
|
-
* importers, or a published build's hashed bundles (`bundledCanvasHostSource`). One body,
|
|
233
|
-
* so the gate, the shields and the commit signal a hosted canvas runs are the ones a
|
|
234
|
-
* developer saw in `dev`.
|
|
235
|
-
*/
|
|
236
196
|
function canvasHostCore(runtimeSpecifier, modules) {
|
|
237
197
|
return `${modules.head}
|
|
238
198
|
import { hydrateIslands, unmountIslands } from ${JSON.stringify(runtimeSpecifier)};
|
|
@@ -365,11 +325,6 @@ function importIsland(key) {
|
|
|
365
325
|
label: "concrete dev"
|
|
366
326
|
});
|
|
367
327
|
}
|
|
368
|
-
/**
|
|
369
|
-
* Write both host scripts under the workspace's `.concrete/dev/` and return the URLs Vite
|
|
370
|
-
* serves them at. Each URL carries a hash of its contents, so a changed island set is a
|
|
371
|
-
* new module to Vite rather than a cached one.
|
|
372
|
-
*/
|
|
373
328
|
async function writeIslandHostScripts(root, files) {
|
|
374
329
|
const dir = join(root, ".concrete", "dev");
|
|
375
330
|
await mkdir(dir, { recursive: true });
|
|
@@ -387,4 +342,4 @@ async function writeIslandHostScripts(root, files) {
|
|
|
387
342
|
}
|
|
388
343
|
|
|
389
344
|
//#endregion
|
|
390
|
-
export { declaresNoServerFrame, findWorkspaceIslands, fsUrl, hasClientDirective, islandEsbuildPlugin, islandKeyFor, islandMapOf, islandRuntimeFile, islandTransformPlugin, stubClientModule,
|
|
345
|
+
export { declaresNoServerFrame, findWorkspaceIslands, fsUrl, hasClientDirective, islandEsbuildPlugin, islandKeyFor, islandMapOf, islandRuntimeFile, islandTransformPlugin, stubClientModule, workspaceComponentFile, wrapClientModule, writeIslandHostScripts };
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
//#region src/cli/dev/listen.ts
|
|
2
|
+
const HMR_PORT_OFFSET = 100;
|
|
3
|
+
const MAX_PORT = 65535;
|
|
4
|
+
const MAX_DEV_PORT = MAX_PORT - 100;
|
|
5
|
+
function hmrPortFor(port) {
|
|
6
|
+
if (port > 65435) throw new Error(`port ${String(port)} leaves no room for the editor's module-reload socket at port + ${String(100)} — pick one no higher than ${String(MAX_DEV_PORT)} with --port <n>`);
|
|
7
|
+
return port + 100;
|
|
8
|
+
}
|
|
9
|
+
function listenRefusal(err, what) {
|
|
10
|
+
if (err.code === "EADDRINUSE") return /* @__PURE__ */ new Error(`${what} is already in use — pick another with --port <n>`);
|
|
11
|
+
if (err.code === "EACCES") return /* @__PURE__ */ new Error(`${what} is reserved or not permitted on this machine — pick another with --port <n>`);
|
|
12
|
+
return err;
|
|
13
|
+
}
|
|
14
|
+
function listenOn(server, port, what) {
|
|
15
|
+
return new Promise((resolveListen, reject) => {
|
|
16
|
+
const refuse = (err) => reject(listenRefusal(err, what));
|
|
17
|
+
server.once("error", refuse);
|
|
18
|
+
server.listen(port, () => {
|
|
19
|
+
server.off("error", refuse);
|
|
20
|
+
resolveListen();
|
|
21
|
+
});
|
|
22
|
+
});
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
//#endregion
|
|
26
|
+
export { MAX_DEV_PORT, hmrPortFor, listenOn, listenRefusal };
|
|
@@ -7,7 +7,6 @@ import { build } from "esbuild";
|
|
|
7
7
|
|
|
8
8
|
//#region src/cli/dev/load-template.ts
|
|
9
9
|
let serial = 0;
|
|
10
|
-
/** Bundle `<root>/template.ts` into the workspace's `.concrete/` cache and import the output. */
|
|
11
10
|
async function loadTemplateModule(options) {
|
|
12
11
|
const { root } = options;
|
|
13
12
|
const media = createFixtureMediaPlugin(root);
|
|
@@ -1,8 +1,4 @@
|
|
|
1
1
|
//#region src/cli/dev/request-error.ts
|
|
2
|
-
/**
|
|
3
|
-
* Answer a rejected request handler. Safe to call at any point in a response's
|
|
4
|
-
* life: it never writes headers twice, and it never throws.
|
|
5
|
-
*/
|
|
6
2
|
function respondToHandlerError(err, req, res, fixStacktrace) {
|
|
7
3
|
const error = err instanceof Error ? err : new Error(String(err));
|
|
8
4
|
fixStacktrace?.(error);
|
package/dist/cli/dev/server.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
|
+
import { RUNNING_FROM_SOURCE, isInsideRoot, packageFile, packageRoot, toPosix } from "../../platform/paths.js";
|
|
1
2
|
import { ASSET_PUBLIC_PATH } from "../../css/inline.js";
|
|
2
|
-
import { findWorkspaceIslands, islandMapOf, writeIslandHostScripts } from "./islands.js";
|
|
3
|
+
import { findWorkspaceIslands, fsUrl, islandMapOf, writeIslandHostScripts } from "./islands.js";
|
|
3
4
|
import { FIXTURE_MEDIA_PATH } from "../../fixtures/media-plugin.js";
|
|
4
5
|
import { HMR_EVENTS, ROUTES } from "../../playground/wire.js";
|
|
5
6
|
import { STYLESHEET_PATHS } from "../../playground/host/paths.js";
|
|
@@ -10,46 +11,28 @@ import { croppedMediaUrl, cutRegion } from "./crop.js";
|
|
|
10
11
|
import { createHmrBus } from "./hmr.js";
|
|
11
12
|
import { RequestError, contentTypeFor, readBody, sendBytes, sendFile, sendHtml, sendText } from "./http.js";
|
|
12
13
|
import { respondToHandlerError } from "./request-error.js";
|
|
14
|
+
import { hmrPortFor, listenOn } from "./listen.js";
|
|
13
15
|
import { createDevVite, settleBrowserDependencies } from "./vite.js";
|
|
14
16
|
import { DevWorkspace } from "./workspace-reader.js";
|
|
15
17
|
import { existsSync, statSync } from "node:fs";
|
|
16
|
-
import {
|
|
17
|
-
import {
|
|
18
|
+
import { extname, join, relative, resolve } from "node:path";
|
|
19
|
+
import { pathToFileURL } from "node:url";
|
|
18
20
|
import { readFile } from "node:fs/promises";
|
|
19
21
|
import { createServer } from "node:http";
|
|
20
22
|
|
|
21
23
|
//#region src/cli/dev/server.ts
|
|
22
|
-
/** The host module bounds a render request at the same size. */
|
|
23
24
|
const MAX_BODY_BYTES = 1024 * 1024;
|
|
24
|
-
/** How many cut crops the server keeps in memory: a session draws a handful, and a re-render asks for the same ones again. */
|
|
25
25
|
const MAX_CACHED_CROPS = 64;
|
|
26
|
-
/** The canvas kernel rewrites a stylesheet asset's `/section-assets/` URL to this mount under the frame's base. */
|
|
27
26
|
const CANVAS_SECTION_ASSET_PATH = "/runtime/section-asset";
|
|
28
|
-
/** The package root: the nearest ancestor of this module with a package.json. */
|
|
29
|
-
function findPackageRoot(fromFile) {
|
|
30
|
-
let dir = dirname(fromFile);
|
|
31
|
-
for (;;) {
|
|
32
|
-
if (existsSync(join(dir, "package.json"))) return dir;
|
|
33
|
-
const parent = dirname(dir);
|
|
34
|
-
if (parent === dir) throw new Error("concrete dev: could not locate the package root");
|
|
35
|
-
dir = parent;
|
|
36
|
-
}
|
|
37
|
-
}
|
|
38
|
-
const THIS_FILE = fileURLToPath(import.meta.url);
|
|
39
|
-
/** Running from source (a test, a checkout) rather than the built package. */
|
|
40
|
-
const FROM_SOURCE = extname(THIS_FILE) === ".ts";
|
|
41
|
-
/** The client shell with the base stamped: every route the client builds resolves against it. */
|
|
42
27
|
function stampBase(html, base) {
|
|
43
28
|
const tag = `<base href="${base}">`;
|
|
44
29
|
return /<head[^>]*>/i.test(html) ? html.replace(/<head[^>]*>/i, (head) => `${head}\n ${tag}`) : `${tag}${html}`;
|
|
45
30
|
}
|
|
46
|
-
/** The canvas routes the client's shell answers: the base itself and `fixtures/<fixture>/canvas[/<canvas-id>]`. */
|
|
47
31
|
function isCanvasPath(path) {
|
|
48
32
|
if (path === "/") return true;
|
|
49
33
|
const [head, fixture, view, ...rest] = path.split("/").filter(Boolean);
|
|
50
34
|
return head === "fixtures" && fixture !== void 0 && view === "canvas" && rest.length <= 1;
|
|
51
35
|
}
|
|
52
|
-
/** The host module an artifact carries, as the package built it. */
|
|
53
36
|
async function loadHostModule(packageRoot) {
|
|
54
37
|
const file = playgroundHostFile(packageRoot);
|
|
55
38
|
if (!existsSync(file)) throw new Error(`the playground host module is not built (${file}) — run the package's build.`);
|
|
@@ -59,23 +42,36 @@ async function loadHostModule(packageRoot) {
|
|
|
59
42
|
}
|
|
60
43
|
async function startDevServer(options) {
|
|
61
44
|
const { root, port, log } = options;
|
|
62
|
-
const
|
|
63
|
-
const
|
|
45
|
+
const hmrPort = hmrPortFor(port);
|
|
46
|
+
const packageRoot$1 = packageRoot();
|
|
47
|
+
const clientDir = playgroundClientOutDir(packageRoot$1);
|
|
64
48
|
if (!existsSync(join(clientDir, "index.html"))) log.write(`concrete dev: the playground client is not built (${clientDir}) — run the package's build.\n`);
|
|
65
|
-
const createHost = await loadHostModule(packageRoot);
|
|
66
|
-
const sourceMarker = join(packageRoot, "src", "islands", "marker.tsx");
|
|
67
|
-
const browserMarker =
|
|
68
|
-
const serverMarker =
|
|
69
|
-
const islandEntries = findWorkspaceIslands(root).map((file) => relative(root, file));
|
|
49
|
+
const createHost = await loadHostModule(packageRoot$1);
|
|
50
|
+
const sourceMarker = join(packageRoot$1, "src", "islands", "marker.tsx");
|
|
51
|
+
const browserMarker = RUNNING_FROM_SOURCE ? fsUrl(sourceMarker) : "@homepages/concrete";
|
|
52
|
+
const serverMarker = RUNNING_FROM_SOURCE ? sourceMarker : "@homepages/concrete";
|
|
53
|
+
const islandEntries = findWorkspaceIslands(root).map((file) => toPosix(relative(root, file)));
|
|
70
54
|
const browserAssets = /* @__PURE__ */ new Map();
|
|
71
|
-
const
|
|
72
|
-
|
|
73
|
-
packageRoot,
|
|
74
|
-
markerSpecifier: browserMarker,
|
|
75
|
-
hmrPort: port + 100,
|
|
76
|
-
islandEntries,
|
|
77
|
-
assets: browserAssets
|
|
55
|
+
const hmrServer = createServer((_req, res) => {
|
|
56
|
+
res.writeHead(426).end("Upgrade Required");
|
|
78
57
|
});
|
|
58
|
+
await listenOn(hmrServer, hmrPort, `port ${String(hmrPort)} (the editor's module-reload socket, --port + ${String(100)})`);
|
|
59
|
+
const closeHmrServer = () => new Promise((done) => hmrServer.close(() => done()));
|
|
60
|
+
let vite;
|
|
61
|
+
try {
|
|
62
|
+
vite = await createDevVite({
|
|
63
|
+
root,
|
|
64
|
+
packageRoot: packageRoot$1,
|
|
65
|
+
markerSpecifier: browserMarker,
|
|
66
|
+
hmrServer,
|
|
67
|
+
hmrPort,
|
|
68
|
+
islandEntries,
|
|
69
|
+
assets: browserAssets
|
|
70
|
+
});
|
|
71
|
+
} catch (err) {
|
|
72
|
+
await closeHmrServer();
|
|
73
|
+
throw err;
|
|
74
|
+
}
|
|
79
75
|
let islands = {
|
|
80
76
|
map: {},
|
|
81
77
|
canvasHost: null,
|
|
@@ -102,7 +98,7 @@ async function startDevServer(options) {
|
|
|
102
98
|
await refreshIslands();
|
|
103
99
|
const capturer = options.capturer ?? createCapturer({
|
|
104
100
|
root,
|
|
105
|
-
packageRoot
|
|
101
|
+
packageRoot: packageRoot$1
|
|
106
102
|
});
|
|
107
103
|
const origin = `http://localhost:${port}/`;
|
|
108
104
|
let browserGraphSettled = null;
|
|
@@ -137,16 +133,16 @@ async function startDevServer(options) {
|
|
|
137
133
|
host,
|
|
138
134
|
hmr,
|
|
139
135
|
clientDir,
|
|
140
|
-
baseCss:
|
|
136
|
+
baseCss: packageFile("css/base.css", "base.css"),
|
|
141
137
|
log,
|
|
142
138
|
browserAssets,
|
|
143
139
|
crops: /* @__PURE__ */ new Map()
|
|
144
140
|
};
|
|
145
|
-
const fixturesDir = join(root, "fixtures")
|
|
141
|
+
const fixturesDir = join(root, "fixtures");
|
|
146
142
|
const onChange = (path) => {
|
|
147
143
|
vite.moduleGraph.invalidateAll();
|
|
148
144
|
browserGraphSettled = null;
|
|
149
|
-
if (
|
|
145
|
+
if (isInsideRoot(fixturesDir, path)) {
|
|
150
146
|
workspace.invalidateFixtures();
|
|
151
147
|
hmr.broadcast(HMR_EVENTS.fixtures);
|
|
152
148
|
return;
|
|
@@ -174,14 +170,13 @@ async function startDevServer(options) {
|
|
|
174
170
|
respondToHandlerError(err, req, res, (error) => vite.ssrFixStacktrace(error));
|
|
175
171
|
});
|
|
176
172
|
});
|
|
177
|
-
|
|
178
|
-
server
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
});
|
|
173
|
+
try {
|
|
174
|
+
await listenOn(server, port, `port ${String(port)}`);
|
|
175
|
+
} catch (err) {
|
|
176
|
+
await vite.close();
|
|
177
|
+
await closeHmrServer();
|
|
178
|
+
throw err;
|
|
179
|
+
}
|
|
185
180
|
return {
|
|
186
181
|
url: origin,
|
|
187
182
|
port,
|
|
@@ -191,10 +186,10 @@ async function startDevServer(options) {
|
|
|
191
186
|
await new Promise((done) => server.close(() => done()));
|
|
192
187
|
await capturer.close();
|
|
193
188
|
await vite.close();
|
|
189
|
+
await closeHmrServer();
|
|
194
190
|
}
|
|
195
191
|
};
|
|
196
192
|
}
|
|
197
|
-
/** A Node request as the fetch-style request the host module takes. Only a request with a method that carries one reads its body. */
|
|
198
193
|
async function toFetchRequest(req, url) {
|
|
199
194
|
const method = req.method ?? "GET";
|
|
200
195
|
const headers = new Headers();
|
|
@@ -237,10 +232,9 @@ async function sendClientShell(ctx, res) {
|
|
|
237
232
|
}
|
|
238
233
|
sendHtml(res, stampBase(html, "/"));
|
|
239
234
|
}
|
|
240
|
-
/** A file the client build emitted, by its path under the base. `false` when there is none. */
|
|
241
235
|
async function sendClientAsset(ctx, path, res) {
|
|
242
236
|
const file = resolve(ctx.clientDir, `.${decodeURIComponent(path)}`);
|
|
243
|
-
if (!
|
|
237
|
+
if (!isInsideRoot(ctx.clientDir, file)) return false;
|
|
244
238
|
try {
|
|
245
239
|
if (!statSync(file).isFile()) return false;
|
|
246
240
|
} catch {
|
|
@@ -312,4 +306,4 @@ async function sendFixtureMedia(ctx, req, url, res) {
|
|
|
312
306
|
}
|
|
313
307
|
|
|
314
308
|
//#endregion
|
|
315
|
-
export {
|
|
309
|
+
export { isCanvasPath, stampBase, startDevServer };
|
|
@@ -22,7 +22,6 @@ function toPattern(key, targets, baseUrl) {
|
|
|
22
22
|
targets: targets.map((target) => isAbsolute(target) ? target : join(baseUrl, target))
|
|
23
23
|
};
|
|
24
24
|
}
|
|
25
|
-
/** The wildcard capture for a match, `""` for an exact match, or `undefined` when `specifier` doesn't match. */
|
|
26
25
|
function matchPattern(pattern, specifier) {
|
|
27
26
|
if (!pattern.hasWildcard) return specifier === pattern.prefix ? "" : void 0;
|
|
28
27
|
if (!specifier.startsWith(pattern.prefix) || !specifier.endsWith(pattern.suffix)) return void 0;
|
|
@@ -35,7 +34,6 @@ function isFile(path) {
|
|
|
35
34
|
return false;
|
|
36
35
|
}
|
|
37
36
|
}
|
|
38
|
-
/** `candidate` resolved as tsc would: itself, itself with an extension, or a directory index. */
|
|
39
37
|
function resolveCandidate(candidate) {
|
|
40
38
|
for (const ext of RESOLVE_EXTENSIONS) if (isFile(candidate + ext)) return candidate + ext;
|
|
41
39
|
for (const ext of RESOLVE_EXTENSIONS.slice(1)) {
|
|
@@ -43,12 +41,6 @@ function resolveCandidate(candidate) {
|
|
|
43
41
|
if (isFile(indexFile)) return indexFile;
|
|
44
42
|
}
|
|
45
43
|
}
|
|
46
|
-
/**
|
|
47
|
-
* The resolver for `root`'s tsconfig `paths`, or `null` when the workspace declares none
|
|
48
|
-
* or its tsconfig cannot be read. Synchronous, and handed the compiler rather than
|
|
49
|
-
* importing it, so the lint preset's rules (which cannot await) resolve an import exactly
|
|
50
|
-
* as `dev` does. Relative, absolute and unmapped specifiers resolve to `undefined`.
|
|
51
|
-
*/
|
|
52
44
|
function createPathsResolver(ts, root) {
|
|
53
45
|
try {
|
|
54
46
|
const configFile = ts.readConfigFile(join(root, "tsconfig.json"), (file) => ts.sys.readFile(file));
|
|
@@ -73,11 +65,6 @@ function createPathsResolver(ts, root) {
|
|
|
73
65
|
return null;
|
|
74
66
|
}
|
|
75
67
|
}
|
|
76
|
-
/**
|
|
77
|
-
* A Vite `resolveId` plugin from `root`'s tsconfig `paths`, or `null` when the workspace
|
|
78
|
-
* declares none or its tsconfig cannot be read — `check` owns reporting a broken tsconfig,
|
|
79
|
-
* so `dev` degrades rather than refusing to start over it.
|
|
80
|
-
*/
|
|
81
68
|
async function createTsconfigPathsPlugin(root) {
|
|
82
69
|
const ts = (await import("typescript")).default;
|
|
83
70
|
const resolvePath = createPathsResolver(ts, root);
|
package/dist/cli/dev/vite.js
CHANGED
|
@@ -1,17 +1,14 @@
|
|
|
1
1
|
import { createTsconfigPathsPlugin } from "./tsconfig-paths.js";
|
|
2
|
-
import {
|
|
2
|
+
import { isInsideRoot, toPosix } from "../../platform/paths.js";
|
|
3
|
+
import { islandTransformPlugin } from "./islands.js";
|
|
3
4
|
import { imageDimensions } from "../../fixtures/image-dimensions.js";
|
|
4
5
|
import { MEDIA_EXTENSIONS, fixtureMediaModule } from "../../fixtures/media-plugin.js";
|
|
5
|
-
import { extname
|
|
6
|
+
import { extname } from "node:path";
|
|
6
7
|
import { readFile } from "node:fs/promises";
|
|
7
8
|
import react from "@vitejs/plugin-react";
|
|
8
9
|
import { createServer } from "vite";
|
|
9
10
|
|
|
10
11
|
//#region src/cli/dev/vite.ts
|
|
11
|
-
function isInside(dir, file) {
|
|
12
|
-
const rel = relative(dir, file);
|
|
13
|
-
return rel !== "" && !rel.startsWith("..") && !isAbsolute(rel);
|
|
14
|
-
}
|
|
15
12
|
const RASTER_EXTENSIONS = /* @__PURE__ */ new Set([
|
|
16
13
|
".png",
|
|
17
14
|
".jpg",
|
|
@@ -19,24 +16,6 @@ const RASTER_EXTENSIONS = /* @__PURE__ */ new Set([
|
|
|
19
16
|
".webp",
|
|
20
17
|
".avif"
|
|
21
18
|
]);
|
|
22
|
-
/**
|
|
23
|
-
* Every asset import in the BROWSER graph, resolved exactly as the server graph resolves
|
|
24
|
-
* it (../../fixtures/media-plugin.ts): a raster yields the `AuthorImage` object the
|
|
25
|
-
* authoring contract promises, everything else its served `/fixture-media/` URL string.
|
|
26
|
-
*
|
|
27
|
-
* Left to itself Vite answers differently on both counts — it inlines a file under
|
|
28
|
-
* `assetsInlineLimit` as a `data:` URI and names the rest by their workspace path — and an
|
|
29
|
-
* island is in BOTH graphs, so a divergence is an attribute mismatch React reports on the
|
|
30
|
-
* island's own element at hydration. `build` has no such split (both its graphs are
|
|
31
|
-
* esbuild's), so this is the dev server's alone to close.
|
|
32
|
-
*
|
|
33
|
-
* What it mints is recorded in `assets`, which the server's `/fixture-media/` route reads
|
|
34
|
-
* alongside the server graph's index: an island declaring `serverFrame = false` is stubbed
|
|
35
|
-
* out of that graph, so its assets are minted only here.
|
|
36
|
-
*
|
|
37
|
-
* A query suffix (`?url`, `?raw`) is the author asking Vite for a form of their own on
|
|
38
|
-
* purpose, and is left to Vite.
|
|
39
|
-
*/
|
|
40
19
|
function fixtureMediaVitePlugin(root, assets) {
|
|
41
20
|
return {
|
|
42
21
|
name: "concrete-dev:fixture-media",
|
|
@@ -44,7 +23,7 @@ function fixtureMediaVitePlugin(root, assets) {
|
|
|
44
23
|
async load(id) {
|
|
45
24
|
if (id.includes("?")) return null;
|
|
46
25
|
const ext = extname(id).toLowerCase();
|
|
47
|
-
if (!
|
|
26
|
+
if (!isInsideRoot(root, id)) return rasterFromPackage(id, ext);
|
|
48
27
|
if (!MEDIA_EXTENSIONS.has(ext)) return null;
|
|
49
28
|
const { asset, value } = fixtureMediaModule(id, await readFile(id));
|
|
50
29
|
assets.set(asset.url, asset);
|
|
@@ -58,7 +37,7 @@ async function rasterFromPackage(id, ext) {
|
|
|
58
37
|
width: 0,
|
|
59
38
|
height: 0
|
|
60
39
|
};
|
|
61
|
-
const url = `/@fs/${
|
|
40
|
+
const url = `/@fs/${toPosix(id).replace(/^\/+/, "")}`;
|
|
62
41
|
return `export default ${JSON.stringify({
|
|
63
42
|
url,
|
|
64
43
|
responsive: null,
|
|
@@ -87,7 +66,10 @@ async function createDevVite(options) {
|
|
|
87
66
|
middlewareMode: true,
|
|
88
67
|
fs: { allow: [root, packageRoot] },
|
|
89
68
|
watch: { ignored: ["**/.concrete/**", "**/node_modules/**"] },
|
|
90
|
-
hmr: {
|
|
69
|
+
hmr: {
|
|
70
|
+
server: options.hmrServer,
|
|
71
|
+
port: options.hmrPort
|
|
72
|
+
}
|
|
91
73
|
},
|
|
92
74
|
resolve: { dedupe: ["react", "react-dom"] },
|
|
93
75
|
optimizeDeps: {
|
|
@@ -100,17 +82,6 @@ async function createDevVite(options) {
|
|
|
100
82
|
}
|
|
101
83
|
});
|
|
102
84
|
}
|
|
103
|
-
/**
|
|
104
|
-
* Resolves once the browser graph reachable from `entryUrls` has been transformed and the
|
|
105
|
-
* dependency optimizer has committed every package that graph imports. Never rejects: a
|
|
106
|
-
* module that fails to transform is left for the page to report.
|
|
107
|
-
*
|
|
108
|
-
* A capture awaits this before Chromium opens a page. A package import Vite first meets
|
|
109
|
-
* mid-page — one the dependency scan missed, or one added after the cache under
|
|
110
|
-
* `node_modules/.vite` was written — re-optimizes, and when that moves an optimized file
|
|
111
|
-
* Vite FULL-RELOADS every open page, destroying the one a capture is settling. Met here,
|
|
112
|
-
* with no page open, the reload lands on nobody.
|
|
113
|
-
*/
|
|
114
85
|
async function settleBrowserDependencies(vite, entryUrls) {
|
|
115
86
|
const client = vite.environments.client;
|
|
116
87
|
const optimizer = client.depsOptimizer;
|