@homepages/concrete 13.0.1 → 14.1.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.
Files changed (80) hide show
  1. package/CHANGELOG.md +46 -0
  2. package/README.md +4 -5
  3. package/codemods/manifest.json +11 -0
  4. package/dist/artifact/playground/client/assets/index-DZbV6Ucf.js +1338 -0
  5. package/dist/artifact/playground/client/index.html +1 -1
  6. package/dist/artifact/playground/host.mjs +22 -22
  7. package/dist/cli/build/esbuild.js +42 -3
  8. package/dist/cli/build/manifest.js +1 -1
  9. package/dist/cli/build/record.js +5 -4
  10. package/dist/cli/build/sections.js +13 -6
  11. package/dist/cli/build/template-build.js +19 -9
  12. package/dist/cli/check/load-workspace.js +3 -6
  13. package/dist/cli/commands.js +63 -15
  14. package/dist/cli/media/deriver-plugin.js +36 -5
  15. package/dist/cli/publish/artifact.js +18 -40
  16. package/dist/cli/publish/fixtures.js +1 -1
  17. package/dist/cli/publish/index.js +90 -115
  18. package/dist/cli/publish/report.js +36 -56
  19. package/dist/cli/publish/send.js +142 -0
  20. package/dist/cli/publish/target.js +33 -31
  21. package/dist/cli/publish/verdict.js +65 -0
  22. package/dist/cli/release/client.js +69 -0
  23. package/dist/cli/release/index.js +143 -0
  24. package/dist/cli/release/report.js +73 -0
  25. package/dist/cli/upgrade/fixture-modules.js +3 -5
  26. package/dist/cli.js +1 -0
  27. package/dist/css/graph.js +29 -40
  28. package/dist/css/inline.js +2 -3
  29. package/dist/fixtures/media-plugin.js +7 -25
  30. package/dist/fixtures/package-stylesheets.js +12 -48
  31. package/dist/packages/external/concrete/package.js +1 -1
  32. package/dist/packages/internal/download-files/dist/capture-origin.js +5 -5
  33. package/dist/packages/internal/media-resolution/dist/image.js +43 -4
  34. package/dist/packages/internal/media-resolution/dist/list.js +4 -4
  35. package/dist/packages/internal/media-resolution/dist/media.js +2 -2
  36. package/dist/packages/internal/media-resolution/dist/slot.js +2 -2
  37. package/dist/packages/internal/playground/dist/fixture-formats.js +5 -1
  38. package/dist/packages/internal/playground/dist/host/built.js +4 -12
  39. package/dist/packages/internal/playground/dist/host/catalog-fixture.js +0 -1
  40. package/dist/packages/internal/playground/dist/host/download.js +1 -8
  41. package/dist/packages/internal/playground/dist/host/fixture-addresses.js +3 -4
  42. package/dist/packages/internal/playground/dist/host/program.js +1 -2
  43. package/dist/packages/internal/playground/dist/host/serve.js +4 -30
  44. package/dist/packages/internal/playground/dist/host/stored-fixtures.js +2 -9
  45. package/dist/packages/internal/playground/dist/layout.js +5 -5
  46. package/dist/packages/internal/playground/dist/send-wire.js +9 -0
  47. package/dist/packages/internal/playground/dist/server/changes.js +0 -1
  48. package/dist/packages/internal/playground/dist/server/listen.js +2 -19
  49. package/dist/packages/internal/playground/dist/server/playground-server.js +2 -3
  50. package/dist/packages/internal/property-facts/dist/registry-facts.js +0 -7
  51. package/dist/packages/internal/site-files/dist/site.js +4 -6
  52. package/dist/packages/internal/static-assets-binding/dist/index.js +2 -1
  53. package/dist/packages/internal/static-assets-binding/dist/section-asset-url.js +16 -4
  54. package/dist/packages/internal/template-artifact/dist/framework-floor.js +33 -0
  55. package/dist/packages/internal/template-artifact/dist/index.js +3 -3
  56. package/dist/packages/internal/template-artifact/dist/layout.js +7 -39
  57. package/dist/packages/internal/template-artifact/dist/manifest.js +1 -1
  58. package/dist/packages/internal/template-artifact/dist/verify.js +14 -57
  59. package/dist/packages/internal/template-contracts/dist/slot-catalog.js +8 -1
  60. package/dist/packages/internal/template-contracts/dist/tour-value.d.ts +1 -1
  61. package/dist/packages/internal/template-contracts/dist/video-value.d.ts +1 -1
  62. package/dist/template/logic-build.js +38 -19
  63. package/guide/reference/cli/INDEX.md +5 -4
  64. package/guide/reference/cli/build.md +1 -1
  65. package/guide/reference/cli/check.md +1 -1
  66. package/guide/reference/cli/dev.md +1 -1
  67. package/guide/reference/cli/install.md +1 -1
  68. package/guide/reference/cli/property-add.md +1 -1
  69. package/guide/reference/cli/property-list.md +1 -1
  70. package/guide/reference/cli/publish.md +17 -16
  71. package/guide/reference/cli/release.md +57 -0
  72. package/guide/reference/cli/upgrade.md +1 -1
  73. package/guide/reference/rules/INDEX.md +1 -1
  74. package/package.json +6 -4
  75. package/dist/artifact/playground/client/assets/index-Bmvcss4B.js +0 -1338
  76. package/dist/cli/publish/captures.js +0 -61
  77. package/dist/cli/publish/client.js +0 -118
  78. package/dist/cli/publish/pack.js +0 -77
  79. package/dist/cli/publish/playground.js +0 -27
  80. package/dist/cli/publish/wire.js +0 -23
@@ -0,0 +1,65 @@
1
+ import { CONSOLE_KEY_HEADER, VERDICT_ROUTE } from "../../packages/internal/playground/dist/send-wire.js";
2
+
3
+ //#region src/cli/publish/verdict.ts
4
+ const isObject = (value) => typeof value === "object" && value !== null;
5
+ function reasonOf(cause) {
6
+ if (cause instanceof Error) {
7
+ const code = cause.cause?.code;
8
+ return typeof code === "string" ? `${code}: ${cause.message}` : cause.message;
9
+ }
10
+ return String(cause);
11
+ }
12
+ async function askVerdict(origin, key, ask, fetchFn = fetch) {
13
+ let response;
14
+ try {
15
+ response = await fetchFn(`${origin.replace(/\/+$/, "")}${VERDICT_ROUTE}`, {
16
+ method: "POST",
17
+ headers: {
18
+ [CONSOLE_KEY_HEADER]: key,
19
+ accept: "application/json",
20
+ "content-type": "application/json"
21
+ },
22
+ body: JSON.stringify(ask)
23
+ });
24
+ } catch (cause) {
25
+ return {
26
+ kind: "unreachable",
27
+ reason: reasonOf(cause)
28
+ };
29
+ }
30
+ const text = await response.text();
31
+ let value;
32
+ try {
33
+ value = JSON.parse(text);
34
+ } catch {
35
+ return {
36
+ kind: "unexpected",
37
+ status: response.status,
38
+ reason: "the answer is not JSON"
39
+ };
40
+ }
41
+ if (response.status === 200 && isObject(value) && typeof value["passed"] === "boolean" && Array.isArray(value["problems"])) return {
42
+ kind: "given",
43
+ verdict: value
44
+ };
45
+ if (response.status === 202 && isObject(value) && isObject(value["job"])) return {
46
+ kind: "pending",
47
+ pending: value
48
+ };
49
+ if (response.status >= 400) {
50
+ const refusal = isObject(value) && typeof value["code"] === "string" && typeof value["detail"] === "string" ? value : null;
51
+ return {
52
+ kind: "refused",
53
+ status: response.status,
54
+ refusal
55
+ };
56
+ }
57
+ return {
58
+ kind: "unexpected",
59
+ status: response.status,
60
+ reason: "the answer is not the verdict's"
61
+ };
62
+ }
63
+
64
+ //#endregion
65
+ export { askVerdict };
@@ -0,0 +1,69 @@
1
+ import { CONSOLE_KEY_HEADER, RELEASE_ROUTE } from "../../packages/internal/playground/dist/send-wire.js";
2
+
3
+ //#region src/cli/release/client.ts
4
+ const OUTCOMES = /* @__PURE__ */ new Set([
5
+ "released",
6
+ "would_release",
7
+ "refused",
8
+ "ask_again",
9
+ "not_taken"
10
+ ]);
11
+ const isObject = (value) => typeof value === "object" && value !== null;
12
+ function reasonOf(cause) {
13
+ if (cause instanceof Error) {
14
+ const code = cause.cause?.code;
15
+ return typeof code === "string" ? `${code}: ${cause.message}` : cause.message;
16
+ }
17
+ return String(cause);
18
+ }
19
+ async function askRelease(origin, key, ask, fetchFn = fetch) {
20
+ let response;
21
+ try {
22
+ response = await fetchFn(`${origin.replace(/\/+$/, "")}${RELEASE_ROUTE}`, {
23
+ method: "POST",
24
+ headers: {
25
+ [CONSOLE_KEY_HEADER]: key,
26
+ accept: "application/json",
27
+ "content-type": "application/json"
28
+ },
29
+ body: JSON.stringify(ask)
30
+ });
31
+ } catch (cause) {
32
+ return {
33
+ kind: "unreachable",
34
+ reason: reasonOf(cause)
35
+ };
36
+ }
37
+ const text = await response.text();
38
+ let value;
39
+ try {
40
+ value = JSON.parse(text);
41
+ } catch {
42
+ return {
43
+ kind: "unexpected",
44
+ status: response.status,
45
+ reason: "the answer is not JSON"
46
+ };
47
+ }
48
+ if (isObject(value) && typeof value["outcome"] === "string" && OUTCOMES.has(value["outcome"])) return {
49
+ kind: "outcome",
50
+ status: response.status,
51
+ outcome: value
52
+ };
53
+ if (response.status >= 400) {
54
+ const refusal = isObject(value) && typeof value["code"] === "string" && typeof value["detail"] === "string" ? value : null;
55
+ return {
56
+ kind: "refused",
57
+ status: response.status,
58
+ refusal
59
+ };
60
+ }
61
+ return {
62
+ kind: "unexpected",
63
+ status: response.status,
64
+ reason: "the answer is not the release's"
65
+ };
66
+ }
67
+
68
+ //#endregion
69
+ export { askRelease };
@@ -0,0 +1,143 @@
1
+ import { booleanFlag, parseSpec, stringFlag } from "../commands.js";
2
+ import { findWorkspaceRoot } from "../workspace.js";
3
+ import { CONSOLE_KEY_VARIABLE, CONSOLE_URL_VARIABLE, TargetError, maskToken, resolveConsoleTarget } from "../publish/target.js";
4
+ import { askRelease } from "./client.js";
5
+ import { endingLines, subjectText } from "./report.js";
6
+ import { resolve } from "node:path";
7
+ import { parseArgs } from "node:util";
8
+
9
+ //#region src/cli/release/index.ts
10
+ const EXIT_OK = 0;
11
+ const EXIT_REFUSED = 1;
12
+ const EXIT_FAILED = 2;
13
+ const ASKS_TOLERATED = 60;
14
+ const DEFAULT_DEPS = {
15
+ templateKey: async (root) => {
16
+ const { loadWorkspace, TEMPLATE_FILE } = await import("../check/load-workspace.js");
17
+ const workspace = await loadWorkspace(root);
18
+ if (workspace.template !== null) return { key: workspace.template.key };
19
+ const first = workspace.violations[0];
20
+ return { problem: `${TEMPLATE_FILE} did not load${first === void 0 ? "" : ` (${first.file}: ${first.message})`}; run \`concrete check\`.` };
21
+ },
22
+ ask: (target, ask) => askRelease(target.console, target.key, ask),
23
+ now: () => /* @__PURE__ */ new Date()
24
+ };
25
+ const say = (sentence) => `concrete release: ${sentence}\n`;
26
+ function failureOf(answer, target) {
27
+ const where = target.console;
28
+ switch (answer.kind) {
29
+ case "unreachable": return {
30
+ code: EXIT_FAILED,
31
+ sentence: say(`could not reach ${where} (${answer.reason}); check the connection${target.overridden ? ` and ${CONSOLE_URL_VARIABLE}` : ""}, then run again.`)
32
+ };
33
+ case "unexpected": return {
34
+ code: EXIT_FAILED,
35
+ sentence: say(`${where} did not answer as a console (${answer.reason}); ${target.overridden ? `check that ${CONSOLE_URL_VARIABLE} names the console` : "run again, and report it if it repeats"}.`)
36
+ };
37
+ case "refused": {
38
+ const detail = answer.refusal?.detail ?? `${where} refused the release (HTTP ${String(answer.status)}).`;
39
+ if (answer.status === 401) return {
40
+ code: EXIT_FAILED,
41
+ sentence: say(`${where} did not accept ${CONSOLE_KEY_VARIABLE} (${maskToken(target.key)}): ${detail}`)
42
+ };
43
+ if (answer.status === 409 || answer.status >= 500) return {
44
+ code: EXIT_FAILED,
45
+ sentence: say(`${detail} Nothing changed in the app; run \`concrete release\` again.`)
46
+ };
47
+ return {
48
+ code: EXIT_REFUSED,
49
+ sentence: say(detail)
50
+ };
51
+ }
52
+ }
53
+ }
54
+ async function releaseTemplate(run, first) {
55
+ const { io, deps, target } = run;
56
+ let ask = first;
57
+ let named = false;
58
+ for (let asks = 1;; asks++) {
59
+ const answer = await deps.ask(target, ask);
60
+ if (answer.kind !== "outcome") {
61
+ const failure = failureOf(answer, target);
62
+ if (run.json && answer.kind === "refused" && answer.refusal !== null) io.stdout.write(`${JSON.stringify(answer.refusal, null, 2)}\n`);
63
+ io.stderr.write(failure.sentence);
64
+ return failure.code;
65
+ }
66
+ const outcome = answer.outcome;
67
+ if (!named) {
68
+ io.stderr.write(`${subjectText(outcome, deps.now())}\n`);
69
+ named = true;
70
+ }
71
+ for (const line of endingLines(outcome)) io.stderr.write(`${line}\n`);
72
+ if (outcome.outcome === "ask_again") {
73
+ if (asks < 60) {
74
+ ask = {
75
+ ...ask,
76
+ version: outcome.version
77
+ };
78
+ continue;
79
+ }
80
+ if (run.json) io.stdout.write(`${JSON.stringify(outcome, null, 2)}\n`);
81
+ io.stderr.write(say(`the release has not ended after ${String(asks)} asks; run \`concrete release --version ${outcome.version}\` again to pick it up.`));
82
+ return EXIT_FAILED;
83
+ }
84
+ if (run.json) io.stdout.write(`${JSON.stringify(outcome, null, 2)}\n`);
85
+ switch (outcome.outcome) {
86
+ case "released":
87
+ case "would_release": return EXIT_OK;
88
+ case "refused": return EXIT_REFUSED;
89
+ case "not_taken": return EXIT_FAILED;
90
+ }
91
+ }
92
+ }
93
+ async function release(argv, io, deps) {
94
+ let values;
95
+ try {
96
+ ({values} = parseArgs({
97
+ args: [...argv],
98
+ ...parseSpec("release")
99
+ }));
100
+ } catch (cause) {
101
+ io.stderr.write(say(`${cause instanceof Error ? cause.message : String(cause)}; run \`concrete --help\` for the flags release takes.`));
102
+ return EXIT_FAILED;
103
+ }
104
+ const version = stringFlag(values, "version");
105
+ let root;
106
+ try {
107
+ root = await findWorkspaceRoot(io.cwd);
108
+ } catch (cause) {
109
+ io.stderr.write(say(cause instanceof Error ? cause.message : String(cause)));
110
+ return EXIT_FAILED;
111
+ }
112
+ let target;
113
+ try {
114
+ const envFile = stringFlag(values, "env-file");
115
+ target = await resolveConsoleTarget(root, io.env, envFile === null ? void 0 : resolve(io.cwd, envFile));
116
+ } catch (cause) {
117
+ if (cause instanceof TargetError) {
118
+ io.stderr.write(say(cause.message));
119
+ return EXIT_FAILED;
120
+ }
121
+ throw cause;
122
+ }
123
+ const template = await deps.templateKey(root);
124
+ if ("problem" in template) {
125
+ io.stderr.write(say(template.problem));
126
+ return EXIT_FAILED;
127
+ }
128
+ const ask = {
129
+ template: template.key,
130
+ ...version === null ? {} : { version },
131
+ ...booleanFlag(values, "dry-run") ? { dry_run: true } : {}
132
+ };
133
+ return releaseTemplate({
134
+ io,
135
+ deps,
136
+ target,
137
+ json: booleanFlag(values, "json")
138
+ }, ask);
139
+ }
140
+ const runRelease = (argv, io) => release(argv, io, DEFAULT_DEPS);
141
+
142
+ //#endregion
143
+ export { DEFAULT_DEPS, release, runRelease };
@@ -0,0 +1,73 @@
1
+ import { problemLines } from "../publish/report.js";
2
+
3
+ //#region src/cli/release/report.ts
4
+ const plural = (count, one, many) => `${String(count)} ${count === 1 ? one : many}`;
5
+ function agoText(at, now) {
6
+ const seconds = Math.max(0, Math.floor((now.getTime() - Date.parse(at)) / 1e3));
7
+ if (Number.isNaN(seconds)) return `at ${at}`;
8
+ if (seconds < 60) return "just now";
9
+ for (const [size, unit] of [
10
+ [86400, "day"],
11
+ [3600, "hour"],
12
+ [60, "minute"]
13
+ ]) if (seconds >= size) return `${plural(Math.floor(seconds / size), unit, `${unit}s`)} ago`;
14
+ return "just now";
15
+ }
16
+ function subjectText(subject, now) {
17
+ const head = `${subject.dry_run ? "Dry run: releasing" : "Releasing"} ${subject.template} · version ${subject.version}`;
18
+ const sent = subject.sent;
19
+ if (sent === null) return head;
20
+ return `${head}, sent ${agoText(sent.at, now)}${sent.key === null ? "" : ` with key "${sent.key}"`}`;
21
+ }
22
+ function audienceText(audience) {
23
+ return `Audience: ${audience === "global" ? "every org" : plural(audience.orgs.length, "org", "orgs")}`;
24
+ }
25
+ function reportLines(report, dryRun) {
26
+ const count = (status) => report.sections.filter((section) => section.status === status).length;
27
+ const nothing = report.template.status === "unchanged" && count("new") === 0 && count("changed") === 0;
28
+ const head = dryRun ? "Would release" : "Released";
29
+ const lines = [];
30
+ if (nothing) lines.push(`${head} · the app already holds this build; nothing changes`);
31
+ else {
32
+ const sections = [
33
+ count("new") > 0 ? `${String(count("new"))} new` : null,
34
+ `${String(count("changed"))} changed`,
35
+ `${String(count("unchanged"))} unchanged`
36
+ ].filter((part) => part !== null).join(", ");
37
+ lines.push(`${head} · template ${report.template.status} · sections: ${sections}`);
38
+ }
39
+ if (report.granted.length > 0 || report.revoked.length > 0) lines.push(`${dryRun ? "Would grant" : "Granted"} ${plural(report.granted.length, "org", "orgs")} · ${dryRun ? "would revoke" : "revoked"} ${plural(report.revoked.length, "org", "orgs")}`);
40
+ const adopting = plural(report.adopting, "deliverable", "deliverables");
41
+ lines.push(dryRun ? `${adopting} would adopt this build` : `${adopting} adopting this build`);
42
+ return lines;
43
+ }
44
+ function unfinishedText(unfinished) {
45
+ switch (unfinished.code) {
46
+ case "verifying": return "the console is verifying the build; asking again";
47
+ case "more_to_deliver": return `delivered ${plural(unfinished.delivered, "content", "contents")} to the app, ${String(unfinished.missing)} still to go; asking again`;
48
+ }
49
+ }
50
+ function refusalLines(refusal) {
51
+ switch (refusal.code) {
52
+ case "verdict_failed": return [`refused: platform ${refusal.platform} did not load the build:`, ...problemLines(refusal.problems)];
53
+ case "audience_not_allowed": {
54
+ const lines = ["refused: the build's audience is outside your team's:"];
55
+ if (refusal.every_org) lines.push(" the build is offered to every org, and your team may not release to every org");
56
+ for (const org of refusal.orgs) lines.push(` your team may not release to org ${org}`);
57
+ return lines;
58
+ }
59
+ case "format_in_use": return ["refused: the build drops formats deliverables of this template still hold:", ...refusal.formats.map((format) => ` ${format.format}: ${plural(format.deliverables, "deliverable", "deliverables")}`)];
60
+ }
61
+ }
62
+ function endingLines(outcome) {
63
+ switch (outcome.outcome) {
64
+ case "released":
65
+ case "would_release": return [audienceText(outcome.audience), ...reportLines(outcome.report, outcome.outcome === "would_release")];
66
+ case "refused": return [audienceText(outcome.audience), ...refusalLines(outcome.refusal)];
67
+ case "not_taken": return [`The app could not take the release (${outcome.reason.code}: ${outcome.reason.detail}). Nothing says the build is unfit; run \`concrete release --version ${outcome.version}\` again.`];
68
+ case "ask_again": return [unfinishedText(outcome.unfinished)];
69
+ }
70
+ }
71
+
72
+ //#endregion
73
+ export { agoText, audienceText, endingLines, refusalLines, reportLines, subjectText, unfinishedText };
@@ -1,7 +1,7 @@
1
1
  import { externalFile, packageFile, workspacePath } from "../../platform/paths.js";
2
2
  import { FIXTURE_MEDIA_PATH, MEDIA_LOADERS, createFixtureMediaPlugin, externalOutsideWorkspace } from "../../fixtures/media-plugin.js";
3
3
  import { listDirSync, removeTree } from "../../platform/fs.js";
4
- import { createPackageStylesheetsPlugin } from "../../fixtures/package-stylesheets.js";
4
+ import { emptyPackageStylesheets } from "../../fixtures/package-stylesheets.js";
5
5
  import { runningCopyPlugin } from "../../template/running-copy.js";
6
6
  import { basename, join } from "node:path";
7
7
  import { pathToFileURL } from "node:url";
@@ -58,7 +58,7 @@ async function evaluateFixtureModules(root, files) {
58
58
  await mkdir(cache, { recursive: true });
59
59
  const outdir = await mkdtemp(join(cache, `${importSerial++}-`));
60
60
  const media = createFixtureMediaPlugin(root, urlOfPath);
61
- const stylesheets = await createPackageStylesheetsPlugin(root);
61
+ emptyPackageStylesheets();
62
62
  try {
63
63
  let result;
64
64
  try {
@@ -83,8 +83,7 @@ async function evaluateFixtureModules(root, files) {
83
83
  retiredSubpathPlugin(),
84
84
  runningCopyPlugin(),
85
85
  externalOutsideWorkspace(root),
86
- media.plugin,
87
- stylesheets.plugin
86
+ media.plugin
88
87
  ],
89
88
  metafile: true,
90
89
  write: true,
@@ -116,7 +115,6 @@ async function evaluateFixtureModules(root, files) {
116
115
  problems: []
117
116
  };
118
117
  } finally {
119
- await stylesheets.dispose();
120
118
  await removeTree(outdir);
121
119
  }
122
120
  }
package/dist/cli.js CHANGED
@@ -62,6 +62,7 @@ async function main(argv, io) {
62
62
  if (cmd === "upgrade") return dispatch(cmd, async () => (await import("./cli/upgrade/index.js")).runUpgrade, args, io);
63
63
  if (cmd === "install") return dispatch(cmd, async () => (await import("./cli/install/index.js")).runInstall, args, io);
64
64
  if (cmd === "publish") return dispatch(cmd, async () => (await import("./cli/publish/index.js")).runPublish, args, io);
65
+ if (cmd === "release") return dispatch(cmd, async () => (await import("./cli/release/index.js")).runRelease, args, io);
65
66
  if (cmd === "property") return dispatch(command.name, async () => (await import("./cli/property/index.js")).runProperty, args, io);
66
67
  io.stderr.write(`concrete: '${cmd}' is declared but has no dispatch branch.\n`);
67
68
  return 1;
package/dist/css/graph.js CHANGED
@@ -3,7 +3,6 @@ import { relative } from "node:path";
3
3
  import { build } from "esbuild";
4
4
 
5
5
  //#region src/css/graph.ts
6
- const CSS_NAMESPACE = "concrete-css-graph";
7
6
  const UNFOLLOWED_RE = /^(?:react|react-dom)(?:\/.*)?$|^@homepages\/concrete(?:\/(?!.*\.css$).*)?$/;
8
7
  const EMPTY_LOADERS = Object.fromEntries([
9
8
  ".svg",
@@ -27,49 +26,40 @@ const EMPTY_LOADERS = Object.fromEntries([
27
26
  ".pdf",
28
27
  ".zip"
29
28
  ].map((ext) => [ext, "empty"]));
30
- const INTERCEPTED_FILTER = /^[^./]|\.css$/;
31
- function isOwnResolve(pluginData) {
32
- return typeof pluginData === "object" && pluginData !== null && pluginData.concreteCssGraph === true;
33
- }
34
- function graphPlugin() {
29
+ const BARE_FILTER = /^[^./]/;
30
+ const CSS_FILTER = /\.css$/;
31
+ function graphPlugin(root) {
32
+ const stylesheets = /* @__PURE__ */ new Map();
35
33
  return {
36
- name: "concrete-css-graph",
37
- setup(api) {
38
- api.onResolve({ filter: INTERCEPTED_FILTER }, async (args) => {
39
- if (args.kind === "entry-point" || isOwnResolve(args.pluginData)) return void 0;
40
- if (UNFOLLOWED_RE.test(args.path)) return externalSpecifier(args.path);
41
- const resolved = await api.resolve(args.path, {
42
- kind: args.kind,
43
- importer: args.importer,
44
- resolveDir: args.resolveDir,
45
- pluginData: { concreteCssGraph: true }
34
+ plugin: {
35
+ name: "concrete-css-graph",
36
+ setup(api) {
37
+ api.onResolve({ filter: BARE_FILTER }, (args) => args.kind !== "entry-point" && UNFOLLOWED_RE.test(args.path) ? externalSpecifier(args.path) : void 0);
38
+ api.onLoad({ filter: CSS_FILTER }, (args) => {
39
+ if (args.namespace !== "file") return void 0;
40
+ stylesheets.set(metafileKey(root, args.path), args.path);
41
+ return {
42
+ contents: "",
43
+ loader: "js"
44
+ };
46
45
  });
47
- if (resolved.errors.length > 0 || resolved.external) return void 0;
48
- if (resolved.path.endsWith(".css")) return {
49
- path: resolved.path,
50
- namespace: CSS_NAMESPACE,
51
- sideEffects: true
52
- };
53
- });
54
- api.onLoad({
55
- filter: /.*/,
56
- namespace: CSS_NAMESPACE
57
- }, () => ({
58
- contents: "",
59
- loader: "js"
60
- }));
61
- }
46
+ }
47
+ },
48
+ stylesheets
62
49
  };
63
50
  }
64
- function stylesheetsInImportOrder(metafile, entryKey) {
51
+ function metafileKey(root, file) {
52
+ return toPosix(relative(root, file));
53
+ }
54
+ function stylesheetsInImportOrder(metafile, entryKey, stylesheets) {
65
55
  const order = [];
66
56
  const seen = /* @__PURE__ */ new Set();
67
- const prefix = `${CSS_NAMESPACE}:`;
68
57
  const visit = (key) => {
69
58
  if (seen.has(key)) return;
70
59
  seen.add(key);
71
- if (key.startsWith(prefix)) {
72
- order.push(key.slice(prefix.length));
60
+ const stylesheet = stylesheets.get(key);
61
+ if (stylesheet !== void 0) {
62
+ order.push(stylesheet);
73
63
  return;
74
64
  }
75
65
  for (const record of metafile.inputs[key]?.imports ?? []) {
@@ -81,7 +71,8 @@ function stylesheetsInImportOrder(metafile, entryKey) {
81
71
  return order;
82
72
  }
83
73
  async function collectCssGraph(input) {
84
- const result = await build({
74
+ const graph = graphPlugin(input.root);
75
+ return stylesheetsInImportOrder((await build({
85
76
  entryPoints: [input.templateFile],
86
77
  absWorkingDir: input.root,
87
78
  bundle: true,
@@ -92,11 +83,9 @@ async function collectCssGraph(input) {
92
83
  jsx: "automatic",
93
84
  outdir: "out",
94
85
  loader: EMPTY_LOADERS,
95
- plugins: [graphPlugin()],
86
+ plugins: [graph.plugin],
96
87
  logLevel: "silent"
97
- });
98
- const entryKey = toPosix(relative(input.root, input.templateFile));
99
- return stylesheetsInImportOrder(result.metafile, entryKey);
88
+ })).metafile, metafileKey(input.root, input.templateFile), graph.stylesheets);
100
89
  }
101
90
 
102
91
  //#endregion
@@ -4,7 +4,6 @@ import { basename, extname, join } from "node:path";
4
4
  import { build } from "esbuild";
5
5
 
6
6
  //#region src/css/inline.ts
7
- const ASSET_PUBLIC_PATH = "/section-assets";
8
7
  const ASSET_NAMES = "[name]-[hash]";
9
8
  function importRulePlugin() {
10
9
  return {
@@ -66,7 +65,7 @@ async function inlineCssGraph(root, files) {
66
65
  metafile: true,
67
66
  outdir: "out",
68
67
  loader: Object.fromEntries(Object.keys(ASSET_MIME).map((ext) => [ext, "file"])),
69
- publicPath: ASSET_PUBLIC_PATH,
68
+ publicPath: "",
70
69
  assetNames: ASSET_NAMES,
71
70
  legalComments: "none",
72
71
  plugins: [importRulePlugin()],
@@ -95,4 +94,4 @@ async function inlineCssGraph(root, files) {
95
94
  }
96
95
 
97
96
  //#endregion
98
- export { ASSET_PUBLIC_PATH, inlineCssGraph };
97
+ export { inlineCssGraph };
@@ -1,12 +1,12 @@
1
1
  import { externalFile, isInsideRoot } from "../platform/paths.js";
2
2
  import { fixtureMediaUrl as fixtureMediaUrl$1, importedFileValue } from "../packages/internal/playground/dist/host/property-derive.js";
3
- import { basename } from "node:path";
3
+ import { basename, resolve } from "node:path";
4
4
  import { readFile } from "node:fs/promises";
5
5
  import { createHash } from "node:crypto";
6
6
 
7
7
  //#region src/fixtures/media-plugin.ts
8
- const NAMESPACE = "concrete-fixture-media";
9
- const RESOLVING = Symbol("concrete-fixture-media:resolving");
8
+ const NAME = "concrete-fixture-media";
9
+ const RESOLVING = Symbol("concrete-external-outside-workspace:resolving");
10
10
  const FIXTURE_MEDIA_PATH = "/fixture-media";
11
11
  const MEDIA_FILTER = /\.(?:[pP][nN][gG]|[jJ][pP][eE]?[gG]|[wW][eE][bB][pP]|[aA][vV][iI][fF]|[sS][vV][gG]|[gG][iI][fF]|[iI][cC][oO]|[wW][oO][fF][fF]2?|[tT][tT][fF]|[oO][tT][fF]|[eE][oO][tT]|[mM][pP]4|[wW][eE][bB][mM]|[mM][oO][vV]|[mM][pP]3|[wW][aA][vV]|[pP][dD][fF]|[zZ][iI][pP])$/;
12
12
  const MEDIA_LOADERS = Object.fromEntries([
@@ -37,6 +37,7 @@ function externalOutsideWorkspace(root) {
37
37
  setup(build) {
38
38
  build.onResolve({ filter: /^\.\.?\// }, async (args) => {
39
39
  if (args.pluginData === RESOLVING) return null;
40
+ if (isInsideRoot(root, resolve(args.resolveDir, args.path))) return null;
40
41
  const resolved = await build.resolve(args.path, {
41
42
  importer: args.importer,
42
43
  namespace: args.namespace,
@@ -71,29 +72,10 @@ function createFixtureMediaPlugin(root, urlOf) {
71
72
  const assets = /* @__PURE__ */ new Map();
72
73
  return {
73
74
  plugin: {
74
- name: NAMESPACE,
75
+ name: NAME,
75
76
  setup(build) {
76
- build.onResolve({ filter: MEDIA_FILTER }, async (args) => {
77
- if (args.pluginData === RESOLVING) return null;
78
- if (args.kind !== "import-statement" && args.kind !== "dynamic-import") return null;
79
- const resolved = await build.resolve(args.path, {
80
- importer: args.importer,
81
- namespace: args.namespace,
82
- resolveDir: args.resolveDir,
83
- kind: args.kind,
84
- pluginData: RESOLVING
85
- });
86
- if (resolved.errors.length > 0 || resolved.path === "") return null;
87
- if (!isInsideRoot(root, resolved.path)) return null;
88
- return {
89
- path: resolved.path,
90
- namespace: NAMESPACE
91
- };
92
- });
93
- build.onLoad({
94
- filter: /.*/,
95
- namespace: NAMESPACE
96
- }, async (args) => {
77
+ build.onLoad({ filter: MEDIA_FILTER }, async (args) => {
78
+ if (args.namespace !== "file" || !isInsideRoot(root, args.path)) return void 0;
97
79
  const bytes = await readFile(args.path);
98
80
  const { asset, value } = await fixtureMediaModule(args.path, bytes, urlOf?.(args.path, bytes));
99
81
  assets.set(asset.url, asset);
@@ -1,53 +1,17 @@
1
- import { context } from "esbuild";
1
+ import { register } from "node:module";
2
2
 
3
3
  //#region src/fixtures/package-stylesheets.ts
4
- const NAMESPACE = "concrete-package-stylesheet";
5
- async function createPackageStylesheetsPlugin(root) {
6
- let resolve;
7
- const resolver = await context({
8
- absWorkingDir: root,
9
- platform: "node",
10
- logLevel: "silent",
11
- plugins: [{
12
- name: `${NAMESPACE}-resolver`,
13
- setup: (api) => void (resolve = (path, options) => api.resolve(path, options))
14
- }]
15
- });
16
- const stylesheets = /* @__PURE__ */ new Map();
17
- return {
18
- plugin: {
19
- name: NAMESPACE,
20
- setup(api) {
21
- api.onResolve({ filter: /^[^./]/ }, async (args) => {
22
- if (args.kind === "entry-point" || args.path.startsWith("node:") || resolve === void 0) return null;
23
- const key = `${args.kind}\0${args.resolveDir}\0${args.path}`;
24
- let stylesheet = stylesheets.get(key);
25
- if (stylesheet === void 0) {
26
- stylesheet = resolve(args.path, {
27
- kind: args.kind,
28
- importer: args.importer,
29
- resolveDir: args.resolveDir
30
- }).then((resolved) => resolved.errors.length === 0 && !resolved.external && resolved.path.endsWith(".css") ? resolved.path : null);
31
- stylesheets.set(key, stylesheet);
32
- }
33
- const path = await stylesheet;
34
- return path === null ? null : {
35
- path,
36
- namespace: NAMESPACE
37
- };
38
- });
39
- api.onLoad({
40
- filter: /.*/,
41
- namespace: NAMESPACE
42
- }, () => ({
43
- contents: "",
44
- loader: "empty"
45
- }));
46
- }
47
- },
48
- dispose: () => resolver.dispose()
49
- };
4
+ const HOOKS = `export async function load(url, context, nextLoad) {
5
+ if (url.startsWith("file:") && new URL(url).pathname.endsWith(".css")) return { format: "module", source: "", shortCircuit: true };
6
+ return nextLoad(url, context);
7
+ }
8
+ `;
9
+ let registered = false;
10
+ function emptyPackageStylesheets() {
11
+ if (registered) return;
12
+ register(`data:text/javascript,${encodeURIComponent(HOOKS)}`);
13
+ registered = true;
50
14
  }
51
15
 
52
16
  //#endregion
53
- export { createPackageStylesheetsPlugin };
17
+ export { emptyPackageStylesheets };
@@ -1,5 +1,5 @@
1
1
  //#region package.json
2
- var version = "13.0.1";
2
+ var version = "14.1.0";
3
3
 
4
4
  //#endregion
5
5
  export { version };