@homepages/concrete 1.0.1 → 1.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +7 -0
- package/codemods/manifest.json +4 -0
- package/dist/cli/build/artifact.js +2 -1
- package/dist/cli/check/load-workspace.js +1 -1
- package/dist/cli/check/stages/bundles.js +2 -1
- package/dist/cli/check/stages/logic.js +2 -1
- package/dist/cli/check/stages/sections.js +2 -1
- package/dist/packages/external/concrete/package.js +1 -1
- package/dist/section/discovery.js +27 -4
- package/dist/template/logic-build.js +54 -9
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,12 @@
|
|
|
1
1
|
# @homepages/concrete
|
|
2
2
|
|
|
3
|
+
## 1.0.2
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- 14ad198: A section module can declare a markup helper beside its section again. A top-level `function Detail() { return <div>…</div> }` that only the render function calls no longer fails `concrete check`'s logic stage with "React reached the logic bundle through … (react/jsx-runtime)", and neither does a render-only helper that calls a `react` import such as `useId`: both drop from the logic bundle with the render. A compute closure or top-level call that really uses React still fails the stage, naming the module.
|
|
8
|
+
- 56321ef: A section that is also re-exported from a barrel (`sections/index.ts` exporting each section, for `import { Hero } from "./sections"`) now bundles from the module that declares it. Before, `concrete check` and `concrete build` used whichever export site they found first. Any section whose folder sorted after the barrel was bundled through the barrel, so its renderer carried every sibling section's islands and assets, and check findings named `sections/index.ts` instead of the section's own file. Barrels are safe to keep: per-section renderer sizes are the same with or without one.
|
|
9
|
+
|
|
3
10
|
## 1.0.1
|
|
4
11
|
|
|
5
12
|
### Patch Changes
|
package/codemods/manifest.json
CHANGED
|
@@ -9,6 +9,7 @@ import "../../packages/internal/template-artifact/dist/index.js";
|
|
|
9
9
|
import { compileTemplateCss } from "../../css/compile.js";
|
|
10
10
|
import { mediaCacheDir } from "../media/cache.js";
|
|
11
11
|
import { usedFactsFromSchema } from "../../schema/extract-used-facts.js";
|
|
12
|
+
import { exportSite } from "../../section/discovery.js";
|
|
12
13
|
import { buildSection } from "./sections.js";
|
|
13
14
|
import { TEMPLATE_FILE } from "../check/load-workspace.js";
|
|
14
15
|
import { analyzeWorkspace } from "../check/analyze.js";
|
|
@@ -74,7 +75,7 @@ async function buildArtifact(options) {
|
|
|
74
75
|
const key = publishedKey(local);
|
|
75
76
|
if (!isSectionKey(key)) throw new Error(`Section key "${local}" cannot name an artifact directory: a key is one path segment of letters, digits, ".", "_" and "-".`);
|
|
76
77
|
const entry = entryByKey.get(local);
|
|
77
|
-
const site = discovered
|
|
78
|
+
const site = exportSite(discovered, section);
|
|
78
79
|
const sectionLogic = logic.sections.get(local);
|
|
79
80
|
if (entry === void 0 || site === void 0 || sectionLogic === void 0) throw new Error(`build: check passed without materializing, discovering or bundling the logic of section "${local}".`);
|
|
80
81
|
const module = join(root, site.module);
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { isTemplate } from "../../template/define-template.js";
|
|
2
|
+
import { listModules } from "../../section/discovery.js";
|
|
2
3
|
import { MEDIA_LOADERS, createFixtureMediaPlugin, externalOutsideWorkspace } from "../../fixtures/media-plugin.js";
|
|
3
4
|
import { runningCopyPlugin } from "../../template/running-copy.js";
|
|
4
|
-
import { listModules } from "../../section/discovery.js";
|
|
5
5
|
import { existsSync } from "node:fs";
|
|
6
6
|
import { join, relative, sep } from "node:path";
|
|
7
7
|
import { pathToFileURL } from "node:url";
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { publishedSectionKey } from "../../../packages/internal/template-artifact/dist/layout.js";
|
|
2
2
|
import "../../../packages/internal/template-artifact/dist/index.js";
|
|
3
|
+
import { exportSite } from "../../../section/discovery.js";
|
|
3
4
|
import { buildFramedRenderer, buildSection, framedRendererPath } from "../../build/sections.js";
|
|
4
5
|
import { workspacePath } from "../load-workspace.js";
|
|
5
6
|
import { describeError } from "../messages.js";
|
|
@@ -32,7 +33,7 @@ async function bundlesStage(ctx) {
|
|
|
32
33
|
const weights = [];
|
|
33
34
|
const built = /* @__PURE__ */ new Map();
|
|
34
35
|
for (const entry of [...sections].sort((a, b) => a.key < b.key ? -1 : a.key > b.key ? 1 : 0)) {
|
|
35
|
-
const site = discovered
|
|
36
|
+
const site = exportSite(discovered, entry.section);
|
|
36
37
|
if (site === void 0) continue;
|
|
37
38
|
const input = {
|
|
38
39
|
root: ctx.root,
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { exportSite } from "../../../section/discovery.js";
|
|
1
2
|
import { TEMPLATE_FILE } from "../load-workspace.js";
|
|
2
3
|
import { describeError } from "../messages.js";
|
|
3
4
|
import { buildSectionLogic, buildTemplateLogic } from "../../../template/logic-build.js";
|
|
@@ -16,7 +17,7 @@ async function logicStage(ctx) {
|
|
|
16
17
|
const violations = [];
|
|
17
18
|
const sections = /* @__PURE__ */ new Map();
|
|
18
19
|
for (const [key, section] of composition.sections) {
|
|
19
|
-
const site = discovered
|
|
20
|
+
const site = exportSite(discovered, section);
|
|
20
21
|
if (site === void 0) continue;
|
|
21
22
|
try {
|
|
22
23
|
sections.set(key, await buildSectionLogic({
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { declaringModule } from "../../../section/section.js";
|
|
2
2
|
import { fillSpecFromSchema } from "../../../schema/extract-fill-spec.js";
|
|
3
|
+
import { exportSite } from "../../../section/discovery.js";
|
|
3
4
|
import { TEMPLATE_FILE, workspacePath } from "../load-workspace.js";
|
|
4
5
|
import { describeError } from "../messages.js";
|
|
5
6
|
import { renderInstanceSlots } from "../../../fixtures/media.js";
|
|
@@ -30,7 +31,7 @@ function sectionsStage(ctx) {
|
|
|
30
31
|
if (workspace === void 0 || discovered === void 0 || composition === void 0) return Promise.resolve({ skipped: "the composition stage could not derive the placed sections" });
|
|
31
32
|
const corpus = ctx.corpus ?? [];
|
|
32
33
|
const fileOf = (section) => {
|
|
33
|
-
const exported = discovered
|
|
34
|
+
const exported = exportSite(discovered, section);
|
|
34
35
|
if (exported !== void 0) return exported.module;
|
|
35
36
|
const at = declaringModule(section);
|
|
36
37
|
return at !== void 0 && isAbsolute(at) && at.startsWith(workspace.root) ? workspacePath(workspace.root, at) : TEMPLATE_FILE;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { isSection } from "./section.js";
|
|
2
|
-
import { readdirSync } from "node:fs";
|
|
1
|
+
import { declaringModule, isSection } from "./section.js";
|
|
2
|
+
import { readdirSync, realpathSync } from "node:fs";
|
|
3
3
|
import { join, relative, sep } from "node:path";
|
|
4
4
|
import { pathToFileURL } from "node:url";
|
|
5
5
|
|
|
@@ -61,7 +61,8 @@ async function discoverSections(options) {
|
|
|
61
61
|
const entry = {
|
|
62
62
|
section: value,
|
|
63
63
|
module,
|
|
64
|
-
exportName
|
|
64
|
+
exportName,
|
|
65
|
+
declares: isDeclaringModule(value, file)
|
|
65
66
|
};
|
|
66
67
|
found.push(entry);
|
|
67
68
|
const prior = byKey.get(value.key);
|
|
@@ -71,6 +72,28 @@ async function discoverSections(options) {
|
|
|
71
72
|
}
|
|
72
73
|
return found;
|
|
73
74
|
}
|
|
75
|
+
function isDeclaringModule(section, file) {
|
|
76
|
+
const at = declaringModule(section);
|
|
77
|
+
if (at === void 0) return false;
|
|
78
|
+
if (at === file) return true;
|
|
79
|
+
try {
|
|
80
|
+
return realpathSync(at) === realpathSync(file);
|
|
81
|
+
} catch {
|
|
82
|
+
return false;
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
/**
|
|
86
|
+
* The export site check and build bundle a section from — the one rule for choosing
|
|
87
|
+
* among a section's several export sites. The module that declares the section wins
|
|
88
|
+
* over any module re-exporting it: an entry through a barrel drags every sibling the
|
|
89
|
+
* barrel lists, their islands and assets, into this section's bundles, and names the
|
|
90
|
+
* barrel in every finding. When the runtime recorded no declaring module among the
|
|
91
|
+
* sites, the first site in discovery order stands.
|
|
92
|
+
*/
|
|
93
|
+
function exportSite(discovered, section) {
|
|
94
|
+
const sites = discovered.filter((candidate) => candidate.section === section);
|
|
95
|
+
return sites.find((site) => site.declares) ?? sites[0];
|
|
96
|
+
}
|
|
74
97
|
|
|
75
98
|
//#endregion
|
|
76
|
-
export { DuplicateSectionKeyError, discoverSections, listModules };
|
|
99
|
+
export { DuplicateSectionKeyError, discoverSections, exportSite, listModules };
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { stripRendersForLogic } from "./logic-transform.js";
|
|
2
2
|
import { existsSync } from "node:fs";
|
|
3
3
|
import { dirname, extname } from "node:path";
|
|
4
|
+
import ts from "typescript";
|
|
4
5
|
import { fileURLToPath } from "node:url";
|
|
5
6
|
import { readFile } from "node:fs/promises";
|
|
6
7
|
import { build } from "esbuild";
|
|
@@ -30,7 +31,39 @@ function shimPath() {
|
|
|
30
31
|
if (existsSync(source)) return source;
|
|
31
32
|
throw new Error(`@homepages/concrete: the logic shim is missing beside ${import.meta.url}`);
|
|
32
33
|
}
|
|
33
|
-
const
|
|
34
|
+
const REACT_STUB_SEPARATOR = "?from=";
|
|
35
|
+
const JSX_RUNTIME_NAMES = [
|
|
36
|
+
"jsx",
|
|
37
|
+
"jsxs",
|
|
38
|
+
"jsxDEV",
|
|
39
|
+
"Fragment"
|
|
40
|
+
];
|
|
41
|
+
function reactStub(names) {
|
|
42
|
+
const lines = [
|
|
43
|
+
`const marker = "@homepages/concrete logic build: a render-time primitive reached the bundle";`,
|
|
44
|
+
`const stub = (name) => () => { throw new Error(marker + " (react." + name + ")"); };`,
|
|
45
|
+
`export default /* @__PURE__ */ stub("default");`
|
|
46
|
+
];
|
|
47
|
+
[...names].forEach((name, index) => {
|
|
48
|
+
lines.push(`const s${String(index)} = /* @__PURE__ */ stub(${JSON.stringify(name)});`, `export { s${String(index)} as ${JSON.stringify(name)} };`);
|
|
49
|
+
});
|
|
50
|
+
return lines.join("\n");
|
|
51
|
+
}
|
|
52
|
+
function importedNames(source, importer, specifier) {
|
|
53
|
+
const names = new Set(/\/jsx-(?:dev-)?runtime$/.test(specifier) ? JSX_RUNTIME_NAMES : []);
|
|
54
|
+
const kind = /\.[jt]sx$/.test(importer) ? ts.ScriptKind.TSX : /\.[cm]?js$/.test(importer) ? ts.ScriptKind.JS : ts.ScriptKind.TS;
|
|
55
|
+
const sourceFile = ts.createSourceFile(importer, source, ts.ScriptTarget.ES2022, false, kind);
|
|
56
|
+
const fromSpecifier = (from) => from !== void 0 && ts.isStringLiteral(from) && from.text === specifier;
|
|
57
|
+
for (const statement of sourceFile.statements) {
|
|
58
|
+
let bindings;
|
|
59
|
+
if (ts.isImportDeclaration(statement) && fromSpecifier(statement.moduleSpecifier)) bindings = statement.importClause?.namedBindings;
|
|
60
|
+
else if (ts.isExportDeclaration(statement) && fromSpecifier(statement.moduleSpecifier)) bindings = statement.exportClause;
|
|
61
|
+
if (bindings === void 0 || !(ts.isNamedImports(bindings) || ts.isNamedExports(bindings))) continue;
|
|
62
|
+
for (const element of bindings.elements) names.add((element.propertyName ?? element.name).text);
|
|
63
|
+
}
|
|
64
|
+
names.delete("default");
|
|
65
|
+
return names;
|
|
66
|
+
}
|
|
34
67
|
function logicPlugin() {
|
|
35
68
|
return {
|
|
36
69
|
name: "concrete-logic",
|
|
@@ -48,17 +81,25 @@ function logicPlugin() {
|
|
|
48
81
|
resolveDir: dirname(args.path)
|
|
49
82
|
}));
|
|
50
83
|
api.onResolve({ filter: /^react(?:-dom)?(?:\/.*)?$/ }, (args) => ({
|
|
51
|
-
path: args.path
|
|
84
|
+
path: `${args.path}${REACT_STUB_SEPARATOR}${args.importer}`,
|
|
52
85
|
namespace: REACT_NAMESPACE,
|
|
53
|
-
sideEffects: false
|
|
86
|
+
sideEffects: false,
|
|
87
|
+
pluginData: {
|
|
88
|
+
specifier: args.path,
|
|
89
|
+
importer: args.importer,
|
|
90
|
+
readable: args.namespace === "file"
|
|
91
|
+
}
|
|
54
92
|
}));
|
|
55
93
|
api.onLoad({
|
|
56
94
|
filter: /.*/,
|
|
57
95
|
namespace: REACT_NAMESPACE
|
|
58
|
-
}, () =>
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
96
|
+
}, async (args) => {
|
|
97
|
+
const { specifier, importer, readable } = args.pluginData;
|
|
98
|
+
return {
|
|
99
|
+
contents: reactStub(importedNames(readable ? await readFile(importer, "utf8") : "", importer, specifier)),
|
|
100
|
+
loader: "js"
|
|
101
|
+
};
|
|
102
|
+
});
|
|
62
103
|
api.onResolve({ filter: STYLESHEET_RE }, (args) => ({
|
|
63
104
|
path: args.path,
|
|
64
105
|
namespace: EMPTY_NAMESPACE,
|
|
@@ -114,7 +155,11 @@ function reachedThrough(metafile) {
|
|
|
114
155
|
const importers = [];
|
|
115
156
|
for (const [input, entry] of Object.entries(metafile.inputs)) {
|
|
116
157
|
if (input.startsWith(`${REACT_NAMESPACE}:`) || !(input in output.inputs)) continue;
|
|
117
|
-
for (const imported of entry.imports)
|
|
158
|
+
for (const imported of entry.imports) {
|
|
159
|
+
if (!survivors.has(imported.path)) continue;
|
|
160
|
+
const stub = imported.path.slice(21);
|
|
161
|
+
importers.push(`${input} (${stub.slice(0, stub.indexOf(REACT_STUB_SEPARATOR))})`);
|
|
162
|
+
}
|
|
118
163
|
}
|
|
119
164
|
return importers;
|
|
120
165
|
}
|
|
@@ -142,7 +187,7 @@ async function bundleLogic(what, contents, resolveDir) {
|
|
|
142
187
|
}
|
|
143
188
|
});
|
|
144
189
|
const importers = reachedThrough(result.metafile);
|
|
145
|
-
if (importers.length > 0) throw new Error(`${what}: React reached the logic bundle through ${importers.join(", ")}. A logic bundle carries only declarations and compute closures;
|
|
190
|
+
if (importers.length > 0) throw new Error(`${what}: React reached the logic bundle through ${importers.join(", ")}. A logic bundle carries only declarations and compute closures; take the React call out of whatever these modules keep live (a compute closure, or a top-level call), or hand-list the logic entry. Markup only the render uses is never live.`);
|
|
146
191
|
const js = result.outputFiles?.[0];
|
|
147
192
|
if (js === void 0) throw new Error(`${what}: esbuild produced no logic-bundle output`);
|
|
148
193
|
return js.text;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@homepages/concrete",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.2",
|
|
4
4
|
"description": "Concrete, the HomePages template framework: the authoring API, the contract primitives, the styles, the lint preset and the `concrete` command in one package that owns its whole toolchain.",
|
|
5
5
|
"license": "UNLICENSED",
|
|
6
6
|
"type": "module",
|