@homepages/concrete 5.0.0 → 6.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +342 -0
- package/README.md +28 -17
- package/codemods/fill-is-a-source.mjs +533 -0
- package/codemods/manifest.json +16 -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 -16
- 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 +21 -35
- 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 +1 -9
- 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 +66 -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.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 +25 -12
- 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/section-nav.js +0 -15
- 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
|
@@ -2,7 +2,7 @@ import { stampCollectionBounds } from "../../packages/internal/template-contract
|
|
|
2
2
|
import { isTemplate } from "../../template/define-template.js";
|
|
3
3
|
import { compileTemplateCss } from "../../css/compile.js";
|
|
4
4
|
import { renderInstanceSlots } from "../../fixtures/media.js";
|
|
5
|
-
import { materializeTemplate
|
|
5
|
+
import { materializeTemplate } from "../../template/materialize.js";
|
|
6
6
|
import { loadFixtures } from "../../fixtures/load.js";
|
|
7
7
|
import { resolveFixture } from "../../fixtures/resolve.js";
|
|
8
8
|
import { materializeSection } from "../../section/materialize.js";
|
|
@@ -17,23 +17,6 @@ const TEMPLATE_FILE = "template.ts";
|
|
|
17
17
|
function violationText(violations) {
|
|
18
18
|
return violations.map((v) => ` ${v.file}: ${v.message} (${v.rule})`).join("\n");
|
|
19
19
|
}
|
|
20
|
-
/** Concrete's reconcile rules address sections by key; the resolver's runner addresses instances. */
|
|
21
|
-
function bakeReconcileRules(template, instanceBySection) {
|
|
22
|
-
return template.reconcile.map((rule) => ({
|
|
23
|
-
description: rule.description,
|
|
24
|
-
reads: rule.reads.flatMap((ref) => {
|
|
25
|
-
const instanceId = instanceBySection[ref.section];
|
|
26
|
-
return instanceId === void 0 ? [] : [{
|
|
27
|
-
instanceId,
|
|
28
|
-
slot: ref.slot
|
|
29
|
-
}];
|
|
30
|
-
}),
|
|
31
|
-
fn: (ctx) => rule.fn({
|
|
32
|
-
site: ctx.site,
|
|
33
|
-
facts: ctx.facts
|
|
34
|
-
}).map((edit) => resolveEdit(edit, instanceBySection))
|
|
35
|
-
}));
|
|
36
|
-
}
|
|
37
20
|
function schemaWire(section, states) {
|
|
38
21
|
const materialized = materializeSection(section, states);
|
|
39
22
|
const slots = materialized.slots;
|
|
@@ -45,7 +28,6 @@ function schemaWire(section, states) {
|
|
|
45
28
|
...groups === void 0 ? {} : { groups }
|
|
46
29
|
};
|
|
47
30
|
}
|
|
48
|
-
/** What the section declares about its display: a required section, and its variant's cases and lock. */
|
|
49
31
|
function displayOf(section) {
|
|
50
32
|
const variant = section.schema.meta.display?.variant;
|
|
51
33
|
return {
|
|
@@ -56,7 +38,6 @@ function displayOf(section) {
|
|
|
56
38
|
}
|
|
57
39
|
};
|
|
58
40
|
}
|
|
59
|
-
/** A resolved fixture as the host reads it: plain records, each media entry with its file's size when the loader knows it. */
|
|
60
41
|
function hostFixture(fixture, sizeOf) {
|
|
61
42
|
const media = {};
|
|
62
43
|
for (const [id, entry] of fixture.media) {
|
|
@@ -91,17 +72,14 @@ var DevWorkspace = class {
|
|
|
91
72
|
get root() {
|
|
92
73
|
return this.options.root;
|
|
93
74
|
}
|
|
94
|
-
/** A module changed: everything derived from source is stale. */
|
|
95
75
|
invalidateSource() {
|
|
96
76
|
this.composition = null;
|
|
97
77
|
this.fixtureSet = null;
|
|
98
78
|
this.stylesheet = null;
|
|
99
79
|
}
|
|
100
|
-
/** A fixture module changed. */
|
|
101
80
|
invalidateFixtures() {
|
|
102
81
|
this.fixtureSet = null;
|
|
103
82
|
}
|
|
104
|
-
/** A stylesheet changed. */
|
|
105
83
|
invalidateStylesheet() {
|
|
106
84
|
this.stylesheet = null;
|
|
107
85
|
}
|
|
@@ -128,16 +106,12 @@ var DevWorkspace = class {
|
|
|
128
106
|
}
|
|
129
107
|
loadFixtureSet() {
|
|
130
108
|
this.fixtureSet ??= (async () => {
|
|
131
|
-
const {
|
|
109
|
+
const { materialized } = await this.loadComposition();
|
|
132
110
|
const loaded = await loadFixtures({ root: this.root });
|
|
133
|
-
const reconcile = bakeReconcileRules(template, materialized.instanceBySection);
|
|
134
111
|
const resolved = /* @__PURE__ */ new Map();
|
|
135
112
|
const violations = [...loaded.violations];
|
|
136
113
|
for (const fixture of loaded.fixtures) {
|
|
137
|
-
const result = resolveFixture(fixture, {
|
|
138
|
-
placements: materialized.placements,
|
|
139
|
-
reconcile
|
|
140
|
-
});
|
|
114
|
+
const result = resolveFixture(fixture, { placements: materialized.placements });
|
|
141
115
|
violations.push(...result.violations);
|
|
142
116
|
if (result.resolved !== null) resolved.set(fixture.id, result.resolved);
|
|
143
117
|
}
|
|
@@ -214,7 +188,6 @@ var DevWorkspace = class {
|
|
|
214
188
|
}
|
|
215
189
|
});
|
|
216
190
|
}
|
|
217
|
-
/** React over the composition's own section values: the renderer the host is handed in `dev`. */
|
|
218
191
|
renderer() {
|
|
219
192
|
return {
|
|
220
193
|
section: async (key) => {
|
|
@@ -226,11 +199,9 @@ var DevWorkspace = class {
|
|
|
226
199
|
renderToString: (element, options) => renderToString(element, options)
|
|
227
200
|
};
|
|
228
201
|
}
|
|
229
|
-
/** A media file the fixture loader or the template's own modules minted a URL for. */
|
|
230
202
|
async fixtureAsset(url) {
|
|
231
203
|
return (await this.loadComposition()).assets.get(url) ?? (await this.loadFixtureSet()).loaded.assets.get(url);
|
|
232
204
|
}
|
|
233
|
-
/** The template stylesheet. A graph that does not compile answers with the reason as a CSS comment. */
|
|
234
205
|
async templateCss() {
|
|
235
206
|
this.stylesheet ??= (async () => {
|
|
236
207
|
const { template } = await this.loadComposition();
|
|
@@ -260,11 +231,10 @@ var DevWorkspace = class {
|
|
|
260
231
|
violations: result.violations
|
|
261
232
|
};
|
|
262
233
|
}
|
|
263
|
-
/** An asset the template stylesheet references, by its content-hashed filename. */
|
|
264
234
|
sectionAsset(filename) {
|
|
265
235
|
return this.sectionAssets.get(filename);
|
|
266
236
|
}
|
|
267
237
|
};
|
|
268
238
|
|
|
269
239
|
//#endregion
|
|
270
|
-
export { DevWorkspace, TEMPLATE_FILE
|
|
240
|
+
export { DevWorkspace, TEMPLATE_FILE };
|
package/dist/cli/media/cache.js
CHANGED
|
@@ -1,31 +1,15 @@
|
|
|
1
|
+
import { writeFileReplacing } from "../../platform/fs.js";
|
|
1
2
|
import { LADDER_POLICY_FINGERPRINT } from "../../packages/internal/image-ladder/dist/policy.js";
|
|
2
3
|
import { basename, join } from "node:path";
|
|
3
|
-
import { mkdir, readFile, readdir,
|
|
4
|
+
import { mkdir, readFile, readdir, stat, utimes } from "node:fs/promises";
|
|
4
5
|
import { createHash } from "node:crypto";
|
|
5
6
|
|
|
6
7
|
//#region src/cli/media/cache.ts
|
|
7
8
|
const POLICY_VERSION = "1";
|
|
8
9
|
const MANIFEST = "manifest.json";
|
|
9
|
-
/**
|
|
10
|
-
* Where a workspace keeps its derived ladders: a `media/` subdirectory of the
|
|
11
|
-
* workspace's `.concrete/` directory, which the scaffold gitignores.
|
|
12
|
-
*/
|
|
13
10
|
function mediaCacheDir(workspaceRoot) {
|
|
14
11
|
return join(workspaceRoot, ".concrete", "cache", "media");
|
|
15
12
|
}
|
|
16
|
-
/**
|
|
17
|
-
* Cache key for one master, namespaced by the derivation version AND the ladder
|
|
18
|
-
* policy's own fingerprint. Without the fingerprint term, changing the encoder settings
|
|
19
|
-
* and forgetting to bump `POLICY_VERSION` would leave this cache returning the OLD
|
|
20
|
-
* encodes indefinitely — a wrong preview and a wrong asset-budget number, with every
|
|
21
|
-
* gate still green.
|
|
22
|
-
*
|
|
23
|
-
* `masterKey` is `<stem>|<hash>`: the stem is part of it so two identically-byted
|
|
24
|
-
* masters with different names never inherit each other's derivative filenames.
|
|
25
|
-
*
|
|
26
|
-
* `policyFingerprint` defaults to the real policy's; a test overrides it to prove two
|
|
27
|
-
* policies produce two keys without touching the policy itself.
|
|
28
|
-
*/
|
|
29
13
|
function cacheKey(masterKey, policyFingerprint = LADDER_POLICY_FINGERPRINT) {
|
|
30
14
|
return createHash("sha256").update(`${POLICY_VERSION}|${policyFingerprint}|${masterKey}`).digest("hex").slice(0, 24);
|
|
31
15
|
}
|
|
@@ -49,15 +33,6 @@ function referencesBaseRung(image, derivatives) {
|
|
|
49
33
|
const base = basename(image.url);
|
|
50
34
|
return derivatives.some((d) => d.filename === base);
|
|
51
35
|
}
|
|
52
|
-
/**
|
|
53
|
-
* The cached derivation for `key`, or null on any miss — absent, truncated, malformed,
|
|
54
|
-
* or missing one of its byte files. A partially-written entry MUST read as a miss: a
|
|
55
|
-
* half-populated ladder that looked like a hit would ship a broken srcset.
|
|
56
|
-
*
|
|
57
|
-
* SIDE EFFECT: a hit touches the entry's manifest mtime, which is what
|
|
58
|
-
* `pruneMediaCache` orders by. Eviction is therefore least-recently-USED, not
|
|
59
|
-
* least-recently-written. The touch is best-effort and never fails a read.
|
|
60
|
-
*/
|
|
61
36
|
async function readCached(key, dir) {
|
|
62
37
|
const entry = join(dir, key);
|
|
63
38
|
try {
|
|
@@ -83,31 +58,11 @@ async function readCached(key, dir) {
|
|
|
83
58
|
return null;
|
|
84
59
|
}
|
|
85
60
|
}
|
|
86
|
-
/**
|
|
87
|
-
* Persist one derivation. The manifest is written LAST and via rename, so a crash
|
|
88
|
-
* mid-write leaves an entry `readCached` rejects rather than a hit pointing at bytes
|
|
89
|
-
* that were never flushed. Rejects on an unusable directory — the caller decides
|
|
90
|
-
* whether that is fatal (it is not).
|
|
91
|
-
*
|
|
92
|
-
* Every byte file is also written to a process-unique temp name and renamed into
|
|
93
|
-
* place, never written in place — that guards a REWRITE of an existing key, not just
|
|
94
|
-
* the first write. A `check` and a `dev` server sharing one workspace can both miss
|
|
95
|
-
* the same cold key and both write it; and a single process can re-derive a key whose
|
|
96
|
-
* manifest is still intact but a byte file vanished (`readCached`'s own miss path).
|
|
97
|
-
* Either way, a second writer starts overwriting filenames the OLD, still-valid
|
|
98
|
-
* manifest still names — in place, a reader in that window would see a truncated
|
|
99
|
-
* file under a manifest that vouches for it. Renaming keeps every reader seeing
|
|
100
|
-
* either the fully-old or fully-new file, never a partial one, on either name.
|
|
101
|
-
*/
|
|
102
61
|
async function writeCached(key, value, dir) {
|
|
103
62
|
const entry = join(dir, key);
|
|
104
63
|
await mkdir(entry, { recursive: true });
|
|
105
64
|
const tag = `${process.pid}-${Math.random().toString(36).slice(2)}`;
|
|
106
|
-
for (const d of value.derivatives) {
|
|
107
|
-
const tmp = join(entry, `${d.filename}.${tag}.tmp`);
|
|
108
|
-
await writeFile(tmp, d.bytes);
|
|
109
|
-
await rename(tmp, join(entry, d.filename));
|
|
110
|
-
}
|
|
65
|
+
for (const d of value.derivatives) await writeFileReplacing(join(entry, `${d.filename}.${tag}.tmp`), join(entry, d.filename), d.bytes);
|
|
111
66
|
const manifest = {
|
|
112
67
|
image: value.image,
|
|
113
68
|
derivatives: value.derivatives.map(({ filename, contentType }) => ({
|
|
@@ -115,9 +70,7 @@ async function writeCached(key, value, dir) {
|
|
|
115
70
|
contentType
|
|
116
71
|
}))
|
|
117
72
|
};
|
|
118
|
-
|
|
119
|
-
await writeFile(tmpPath, JSON.stringify(manifest));
|
|
120
|
-
await rename(tmpPath, join(entry, MANIFEST));
|
|
73
|
+
await writeFileReplacing(join(entry, `${MANIFEST}.${tag}.tmp`), join(entry, MANIFEST), JSON.stringify(manifest));
|
|
121
74
|
}
|
|
122
75
|
const GARBAGE_RANK = Number.MIN_SAFE_INTEGER;
|
|
123
76
|
|
package/dist/cli/media/derive.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { URL_SAFE_NAME } from "../../platform/names.js";
|
|
1
2
|
import { cacheKey, readCached, writeCached } from "./cache.js";
|
|
2
3
|
import { basename, extname } from "node:path";
|
|
3
4
|
import { createHash } from "node:crypto";
|
|
@@ -6,8 +7,6 @@ import { createHash } from "node:crypto";
|
|
|
6
7
|
function loadImageLadder() {
|
|
7
8
|
return import("../../packages/internal/image-ladder/dist/index.js");
|
|
8
9
|
}
|
|
9
|
-
/** The extensions a JS import derives. `.svg`/`.gif`/`.ico` are deliberately absent:
|
|
10
|
-
* rasterising line art is a regression, and a ladder cannot express an animation. */
|
|
11
10
|
const DERIVABLE_EXTENSIONS = /* @__PURE__ */ new Set([
|
|
12
11
|
".jpg",
|
|
13
12
|
".jpeg",
|
|
@@ -15,32 +14,11 @@ const DERIVABLE_EXTENSIONS = /* @__PURE__ */ new Set([
|
|
|
15
14
|
".webp",
|
|
16
15
|
".avif"
|
|
17
16
|
]);
|
|
18
|
-
/**
|
|
19
|
-
* The rungs of `rungs` a rendered frame can ever select, for a master `width` wide whose
|
|
20
|
-
* long edge is `longEdge`: every rung at least `floor` px wide, plus the top rung.
|
|
21
|
-
*
|
|
22
|
-
* A rendered template's page is a frame document whose window is exactly the format's
|
|
23
|
-
* box — the canvas scales the iframe, it never narrows it — so an unsized `<Image>`
|
|
24
|
-
* (`sizes` defaults to `100vw`) asks for the frame width times the device pixel ratio,
|
|
25
|
-
* and a candidate narrower than the frame is never the one a DPR >= 1 screen picks. The
|
|
26
|
-
* top rung stays whatever its width: it is what a frame wider than the master picks.
|
|
27
|
-
*
|
|
28
|
-
* Dropping a candidate can never degrade a render, whatever `sizes` an author wrote or
|
|
29
|
-
* whatever DPR a browser has: every rung kept is wider than every rung dropped, so a
|
|
30
|
-
* browser choosing from the kept set lands on the rung it chose before or a wider one.
|
|
31
|
-
* Measured on a `deck16x9` canvas at DPR 1, 2 and 3: every image fetched exactly one
|
|
32
|
-
* candidate, and never one narrower than the frame unless it was the master's top rung.
|
|
33
|
-
*
|
|
34
|
-
* `width` is estimated per rung the way `encodeRung` resizes (`fit: inside` on the long
|
|
35
|
-
* edge), before encoding, so a dropped rung costs no encode. An off-by-one at the floor
|
|
36
|
-
* only decides whether one more candidate ships, never what a frame shows.
|
|
37
|
-
*/
|
|
38
17
|
function frameReachableRungs(rungs, width, longEdge, floor) {
|
|
39
18
|
if (floor === void 0 || floor <= 0 || longEdge <= 0 || rungs.length === 0) return [...rungs];
|
|
40
19
|
const top = rungs[rungs.length - 1];
|
|
41
20
|
return rungs.filter((edge) => edge === top || Math.round(width * Math.min(edge, longEdge) / longEdge) >= floor);
|
|
42
21
|
}
|
|
43
|
-
/** 8 hex chars of sha256 over the master's bytes — the shared stem of every derivative. */
|
|
44
22
|
function masterHash(bytes) {
|
|
45
23
|
return createHash("sha256").update(bytes).digest("hex").slice(0, 8);
|
|
46
24
|
}
|
|
@@ -59,58 +37,7 @@ const PASSTHROUGH_CONTENT_TYPES = {
|
|
|
59
37
|
".webp": "image/webp",
|
|
60
38
|
".avif": "image/avif"
|
|
61
39
|
};
|
|
62
|
-
/** The characters a derivative filename may contain — it is interpolated verbatim
|
|
63
|
-
* into a public URL and a space-delimited srcset candidate list. */
|
|
64
|
-
const SAFE_STEM = /^[A-Za-z0-9._-]+$/;
|
|
65
|
-
/**
|
|
66
|
-
* How many of a master's rung x format encodes run at once.
|
|
67
|
-
*
|
|
68
|
-
* MEASURED, not a core count. `sharp` is already multi-threaded per call — libvips
|
|
69
|
-
* sizes its own pool to the CPU count — so N concurrent encodes ask for roughly
|
|
70
|
-
* N x cores threads and hold N decoded copies of a large master resident at the same
|
|
71
|
-
* time. Past a point that buys nothing and costs RSS, on a machine already running
|
|
72
|
-
* the rest of a dev stack.
|
|
73
|
-
*
|
|
74
|
-
* Cold derivation of a 2560px photographic master — 9 rungs x 3 formats, 27 encodes
|
|
75
|
-
* — on a 4-core dev box, best of three interleaved rounds, peak process RSS:
|
|
76
|
-
*
|
|
77
|
-
* limit 1 (the serial loop this replaced) 17.2 s 483 MB
|
|
78
|
-
* limit 2 9.9 s 645 MB
|
|
79
|
-
* limit 3 8.0 s 742 MB
|
|
80
|
-
* limit 4 7.6 s 841 MB
|
|
81
|
-
* limit 6 8.0 s 814 MB
|
|
82
|
-
* limit 8 9.2 s 856 MB
|
|
83
|
-
*
|
|
84
|
-
* 4 is the bottom of the curve and it turns back up past it: the extra encodes only
|
|
85
|
-
* queue for the same cores while each one still pins its own decoded buffers. The
|
|
86
|
-
* cost of choosing it over 3 is ~100 MB for ~5% — take 3 if a dev box is the tighter
|
|
87
|
-
* constraint. Held at a constant rather than `availableParallelism()` deliberately:
|
|
88
|
-
* the quantity being bounded is how many large rasters may be decoded at once, and a
|
|
89
|
-
* 64-core CI box has the same answer to that as a laptop.
|
|
90
|
-
*
|
|
91
|
-
* End to end, the same change over a cold two-master section render (48 encodes)
|
|
92
|
-
* through the dev server's `/api/render`, three interleaved rounds, best of each:
|
|
93
|
-
* 64.0 s -> 31.3 s, peak server RSS 531 MB -> 945 MB. That ceiling is set by the pool
|
|
94
|
-
* and not by the corpus — masters are derived one at a time, and the three parallel
|
|
95
|
-
* rounds peaked within 4 MB of each other, so a 21-master workspace peaks where a
|
|
96
|
-
* two-master one does.
|
|
97
|
-
*/
|
|
98
40
|
const ENCODE_CONCURRENCY = 4;
|
|
99
|
-
/**
|
|
100
|
-
* Run `task` over `items` with at most `limit` in flight, returning results in
|
|
101
|
-
* INPUT order — the ladder is positional (see the call site), so a completion-ordered
|
|
102
|
-
* result array would silently reshuffle every srcset it feeds.
|
|
103
|
-
*
|
|
104
|
-
* A rejection stops the pool from claiming further items and propagates, so one bad
|
|
105
|
-
* encode does not leave the rest of the ladder churning behind an already-failed call.
|
|
106
|
-
*
|
|
107
|
-
* EXPORTED FOR ITS TEST, and the test has to be here rather than over a real
|
|
108
|
-
* derivation: the ladder's own encodes get MORE expensive per rung and are fed in
|
|
109
|
-
* rung order, so they finish in very nearly input order anyway and a
|
|
110
|
-
* completion-ordered bug passes a byte-comparison against the serial run (verified —
|
|
111
|
-
* that mutant survives). Only a task whose completion order is deliberately inverted
|
|
112
|
-
* grades this.
|
|
113
|
-
*/
|
|
114
41
|
async function mapConcurrent(items, limit, task) {
|
|
115
42
|
const results = new Array(items.length);
|
|
116
43
|
let next = 0;
|
|
@@ -133,12 +60,6 @@ var UnsafeStemError = class extends Error {
|
|
|
133
60
|
}
|
|
134
61
|
};
|
|
135
62
|
const derivationCache = /* @__PURE__ */ new Map();
|
|
136
|
-
/**
|
|
137
|
-
* The master as an emitted file. Pure over (stem, hash, extension, bytes), so it is
|
|
138
|
-
* built OUTSIDE both cache tiers and attached on every path — an entry written
|
|
139
|
-
* before masters existed still serves one, and no cache holds a second copy of
|
|
140
|
-
* bytes the caller already has in hand.
|
|
141
|
-
*/
|
|
142
63
|
function masterAsset(absPath, hash, bytes) {
|
|
143
64
|
const ext = extname(absPath).toLowerCase();
|
|
144
65
|
const key = `${basename(absPath, extname(absPath))}-${hash}`;
|
|
@@ -159,24 +80,11 @@ function toDerivation(cached, master, masterByteLength, passthrough) {
|
|
|
159
80
|
passthrough
|
|
160
81
|
};
|
|
161
82
|
}
|
|
162
|
-
/**
|
|
163
|
-
* Derive `bytes` into a ladder and the `AuthorImage` that references it.
|
|
164
|
-
*
|
|
165
|
-
* `absPath` supplies only the derivative stem (its basename); nothing is read
|
|
166
|
-
* from disk here — the caller already has the bytes, and keeping this a pure
|
|
167
|
-
* function of them is what makes the in-process memoization sound.
|
|
168
|
-
*
|
|
169
|
-
* Without `sharp`, returns the master verbatim with `responsive: null` and
|
|
170
|
-
* `width`/`height` of 0 — unless a cached derivation for these exact bytes already
|
|
171
|
-
* exists, which is served regardless. `<Image>` reads dimensions only off
|
|
172
|
-
* `responsive`, so a zero is inert at render; it is reported by `check` rather than
|
|
173
|
-
* hidden.
|
|
174
|
-
*/
|
|
175
83
|
async function deriveAuthorImage(absPath, bytes, opts = {}) {
|
|
176
84
|
const encodeConcurrency = opts.encodeConcurrency ?? ENCODE_CONCURRENCY;
|
|
177
85
|
const hash = masterHash(bytes);
|
|
178
86
|
const stem = basename(absPath, extname(absPath));
|
|
179
|
-
if (!
|
|
87
|
+
if (!URL_SAFE_NAME.test(stem)) throw new UnsafeStemError(absPath, stem);
|
|
180
88
|
const floor = opts.minRungWidth !== void 0 && opts.minRungWidth > 0 ? opts.minRungWidth : void 0;
|
|
181
89
|
const masterKey = floor === void 0 ? `${stem}|${hash}` : `${stem}|${hash}|frame${String(floor)}`;
|
|
182
90
|
const memoKey = `${opts.cacheDir ?? ""}|${masterKey}`;
|
|
@@ -6,8 +6,6 @@ import { readFile } from "node:fs/promises";
|
|
|
6
6
|
const NAMESPACE = "media-deriver";
|
|
7
7
|
const RESOLVING = Symbol("media-deriver:resolving");
|
|
8
8
|
const RASTER_FILTER = /\.(?:[jJ][pP][eE]?[gG]|[pP][nN][gG]|[wW][eE][bB][pP]|[aA][vV][iI][fF])$/;
|
|
9
|
-
/** A fresh deriver per esbuild pass; `cacheDir` opts it into the on-disk ladder cache, and
|
|
10
|
-
* `minRungWidth` (a rendered template's frame width) drops the rungs no frame selects. */
|
|
11
9
|
function createMediaDeriver(opts = {}) {
|
|
12
10
|
const derived = /* @__PURE__ */ new Map();
|
|
13
11
|
const masters = /* @__PURE__ */ new Map();
|
|
@@ -2,12 +2,6 @@ import { captureViewport } from "../../packages/internal/format-geometry/dist/ca
|
|
|
2
2
|
import "../../packages/internal/format-geometry/dist/index.js";
|
|
3
3
|
|
|
4
4
|
//#region src/cli/media/frame-rung-floor.ts
|
|
5
|
-
/**
|
|
6
|
-
* The frame width, in CSS px at DPR 1, of the template's narrowest declared format —
|
|
7
|
-
* undefined for a website, whose pages are served at any viewport and keep the full
|
|
8
|
-
* ladder. The narrowest, so a multi-format template keeps every rung any of its frames
|
|
9
|
-
* can select.
|
|
10
|
-
*/
|
|
11
5
|
function frameRungFloor(template) {
|
|
12
6
|
if (template.output === "website") return void 0;
|
|
13
7
|
const widths = template.formats.filter((format) => format.width !== void 0).map((format) => captureViewport(format).width);
|
|
@@ -55,11 +55,9 @@ const COUNT_NOUNS = [
|
|
|
55
55
|
"documents"
|
|
56
56
|
]
|
|
57
57
|
];
|
|
58
|
-
/** `pearl-street` → `pearlStreet`: the name a library property module exports its property under. */
|
|
59
58
|
function exportNameFor(slug) {
|
|
60
59
|
return slug.replace(/-([a-z0-9])/g, (_, c) => c.toUpperCase());
|
|
61
60
|
}
|
|
62
|
-
/** One line per property: its slug, its description, then its type, intent and non-zero counts. */
|
|
63
61
|
function listingLines(index) {
|
|
64
62
|
const width = Math.max(0, ...index.properties.map((p) => p.slug.length));
|
|
65
63
|
return index.properties.map((property) => {
|
|
@@ -74,7 +72,6 @@ function listingLines(index) {
|
|
|
74
72
|
function say(stream, text) {
|
|
75
73
|
stream.write(text.endsWith("\n") ? text : `${text}\n`);
|
|
76
74
|
}
|
|
77
|
-
/** Says, on stderr, when an earlier copy stood in for a registry that could not be read. */
|
|
78
75
|
function reportSource(io, prefix, library) {
|
|
79
76
|
if (library.source === "cache") say(io.stderr, `${prefix}: the registry could not be read, so this is ${LIBRARY_PACKAGE} ${library.version}, cached earlier.`);
|
|
80
77
|
}
|
|
@@ -165,7 +162,6 @@ async function runAdd(argv, io, environment) {
|
|
|
165
162
|
].join("\n"));
|
|
166
163
|
return 0;
|
|
167
164
|
}
|
|
168
|
-
/** The group's entry point, with its environment injected. */
|
|
169
165
|
function createPropertyCommand(environment = {}) {
|
|
170
166
|
return async (argv, io) => {
|
|
171
167
|
const [subcommand, ...rest] = argv;
|
|
@@ -1,18 +1,15 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { cacheRoot, removeTree, renameSettled } from "../../platform/fs.js";
|
|
2
2
|
import { compareVersions, parseVersion } from "../currency/version-order.js";
|
|
3
3
|
import { readPublishedDist, resolveLatest } from "../currency/resolve-latest.js";
|
|
4
4
|
import { readTarball } from "../tar.js";
|
|
5
5
|
import { dirname, join } from "node:path";
|
|
6
|
-
import { mkdir, readdir,
|
|
6
|
+
import { mkdir, readdir, stat, writeFile } from "node:fs/promises";
|
|
7
7
|
import { createHash } from "node:crypto";
|
|
8
8
|
|
|
9
9
|
//#region src/cli/property/library.ts
|
|
10
10
|
const LIBRARY_PACKAGE = "@homepages/sample-properties";
|
|
11
|
-
/** Below the cache root, beside the currency cache's file. */
|
|
12
11
|
const LIBRARY_CACHE_RELATIVE = join("homepages", "sample-properties");
|
|
13
|
-
/** Each registry read. Longer than the preamble's two seconds: a person asked for this one. */
|
|
14
12
|
const REGISTRY_TIMEOUT_MS = 1e4;
|
|
15
|
-
/** The tarball download, which carries every property's media. */
|
|
16
13
|
const DOWNLOAD_TIMEOUT_MS = 6e4;
|
|
17
14
|
async function isDirectory(path) {
|
|
18
15
|
try {
|
|
@@ -21,7 +18,6 @@ async function isDirectory(path) {
|
|
|
21
18
|
return false;
|
|
22
19
|
}
|
|
23
20
|
}
|
|
24
|
-
/** The newest version already unpacked under `root`, or `null`. A half-written staging directory is not a version. */
|
|
25
21
|
async function newestCached(root) {
|
|
26
22
|
let names;
|
|
27
23
|
try {
|
|
@@ -52,25 +48,16 @@ async function download(url, doFetch) {
|
|
|
52
48
|
return null;
|
|
53
49
|
}
|
|
54
50
|
}
|
|
55
|
-
/**
|
|
56
|
-
* Whether the bytes are the ones the registry published. The sha512 integrity string when
|
|
57
|
-
* there is one — it may list several digests, and one sha512 decides — else the sha1
|
|
58
|
-
* every registry still carries. A version with neither cannot be checked, so it fails.
|
|
59
|
-
*/
|
|
60
51
|
function matchesDigest(bytes, dist) {
|
|
61
52
|
for (const token of (dist.integrity ?? "").split(/\s+/)) if (token.startsWith("sha512-")) return createHash("sha512").update(bytes).digest("base64") === token.slice(7);
|
|
62
53
|
if (dist.shasum !== null) return createHash("sha1").update(bytes).digest("hex") === dist.shasum.toLowerCase();
|
|
63
54
|
return false;
|
|
64
55
|
}
|
|
65
|
-
/** Unpacks into a staging directory and renames it into place, so a version directory is always whole. */
|
|
66
56
|
async function unpack(bytes, dir, version) {
|
|
67
57
|
const files = readTarball(bytes);
|
|
68
58
|
if (!files.some((file) => file.path === "index.json")) throw new Error(`${LIBRARY_PACKAGE}@${version} carries no index.json, so it is not a library this command can read`);
|
|
69
59
|
const staging = `${dir}.${String(process.pid)}.tmp`;
|
|
70
|
-
await
|
|
71
|
-
recursive: true,
|
|
72
|
-
force: true
|
|
73
|
-
});
|
|
60
|
+
await removeTree(staging);
|
|
74
61
|
try {
|
|
75
62
|
for (const file of files) {
|
|
76
63
|
const target = join(staging, ...file.path.split("/"));
|
|
@@ -78,18 +65,14 @@ async function unpack(bytes, dir, version) {
|
|
|
78
65
|
await writeFile(target, file.body);
|
|
79
66
|
}
|
|
80
67
|
try {
|
|
81
|
-
await
|
|
68
|
+
await renameSettled(staging, dir);
|
|
82
69
|
} catch (cause) {
|
|
83
70
|
if (!await isDirectory(dir)) throw cause;
|
|
84
71
|
}
|
|
85
72
|
} finally {
|
|
86
|
-
await
|
|
87
|
-
recursive: true,
|
|
88
|
-
force: true
|
|
89
|
-
});
|
|
73
|
+
await removeTree(staging);
|
|
90
74
|
}
|
|
91
75
|
}
|
|
92
|
-
/** The published version unpacked, or `null` when the registry could not be read at some step. */
|
|
93
76
|
async function fromRegistry(root, registry, doFetch) {
|
|
94
77
|
const latest = await resolveLatest(registry);
|
|
95
78
|
if (latest === null || parseVersion(latest) === null) return null;
|
|
@@ -111,9 +94,8 @@ async function fromRegistry(root, registry, doFetch) {
|
|
|
111
94
|
source: "registry"
|
|
112
95
|
};
|
|
113
96
|
}
|
|
114
|
-
/** The library to read: the published latest, else the newest cached copy. Throws when there is neither. */
|
|
115
97
|
async function openLibrary(options) {
|
|
116
|
-
const root = join(
|
|
98
|
+
const root = join(cacheRoot(options.env), LIBRARY_CACHE_RELATIVE);
|
|
117
99
|
const doFetch = options.fetchImpl ?? fetch;
|
|
118
100
|
const published = await fromRegistry(root, {
|
|
119
101
|
packageName: LIBRARY_PACKAGE,
|
|
@@ -4,7 +4,6 @@ import { request } from "node:http";
|
|
|
4
4
|
import { request as request$1 } from "node:https";
|
|
5
5
|
|
|
6
6
|
//#region src/cli/publish/client.ts
|
|
7
|
-
/** A socket that goes quiet this long is a dead endpoint, not a slow one. */
|
|
8
7
|
const IDLE_TIMEOUT_MS = 6e4;
|
|
9
8
|
function send(url, method, headers, body) {
|
|
10
9
|
const request$2 = url.protocol === "https:" ? request$1 : request;
|
|
@@ -8,7 +8,6 @@ import { join } from "node:path";
|
|
|
8
8
|
import { readFile, stat } from "node:fs/promises";
|
|
9
9
|
|
|
10
10
|
//#region src/cli/publish/freshness.ts
|
|
11
|
-
/** The artifact's manifest and when it was written; `missing` without one, `unreadable` when it does not parse. */
|
|
12
11
|
async function readManifest(out) {
|
|
13
12
|
let text;
|
|
14
13
|
let builtAt;
|
|
@@ -32,7 +31,6 @@ async function readManifest(out) {
|
|
|
32
31
|
builtAt
|
|
33
32
|
} : "unreadable";
|
|
34
33
|
}
|
|
35
|
-
/** Decide whether the artifact at `out` can be published as it is. */
|
|
36
34
|
async function assessFreshness(options) {
|
|
37
35
|
const read = await readManifest(options.out);
|
|
38
36
|
const previous = typeof read === "string" ? null : read.manifest;
|
package/dist/cli/publish/git.js
CHANGED
|
@@ -1,21 +1,15 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { promisify } from "node:util";
|
|
1
|
+
import { execGit } from "../../platform/process.js";
|
|
3
2
|
|
|
4
3
|
//#region src/cli/publish/git.ts
|
|
5
|
-
const run = promisify(execFile);
|
|
6
4
|
async function git(root, args) {
|
|
7
5
|
try {
|
|
8
|
-
const { stdout } = await
|
|
6
|
+
const { stdout } = await execGit(args, { cwd: root });
|
|
9
7
|
const value = stdout.trim();
|
|
10
8
|
return value === "" ? null : value;
|
|
11
9
|
} catch {
|
|
12
10
|
return null;
|
|
13
11
|
}
|
|
14
12
|
}
|
|
15
|
-
/**
|
|
16
|
-
* A remote URL with any credentials removed: an https remote can carry a token in its
|
|
17
|
-
* userinfo, and the record is read by people other than the one who published.
|
|
18
|
-
*/
|
|
19
13
|
function withoutCredentials(remote) {
|
|
20
14
|
try {
|
|
21
15
|
const url = new URL(remote);
|
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
import { DEFAULT_BUILD_DIR, booleanFlag, parseSpec } from "../commands.js";
|
|
2
|
-
import { formatHuman } from "../check/report.js";
|
|
1
|
+
import { DEFAULT_BUILD_DIR, booleanFlag, parseSpec, stringFlag } from "../commands.js";
|
|
3
2
|
import { findWorkspaceRoot } from "../workspace.js";
|
|
3
|
+
import { removeTree } from "../../platform/fs.js";
|
|
4
|
+
import { formatHuman } from "../check/report.js";
|
|
4
5
|
import { TERMINAL_STATES } from "./wire.js";
|
|
5
6
|
import { publicationClient } from "./client.js";
|
|
6
7
|
import { assessFreshness } from "./freshness.js";
|
|
@@ -9,17 +10,15 @@ import { packArtifact } from "./pack.js";
|
|
|
9
10
|
import { API_URL_VARIABLE, TOKEN_VARIABLE, TargetError, maskToken, resolveTarget } from "./target.js";
|
|
10
11
|
import { adoptText, builtText, freshnessText, refusalText, stageLine, summaryText, targetText, uploadText, writeText } from "./report.js";
|
|
11
12
|
import { join, resolve } from "node:path";
|
|
12
|
-
import { mkdtemp,
|
|
13
|
-
import { parseArgs } from "node:util";
|
|
13
|
+
import { mkdtemp, stat } from "node:fs/promises";
|
|
14
14
|
import { tmpdir } from "node:os";
|
|
15
|
+
import { parseArgs } from "node:util";
|
|
15
16
|
|
|
16
17
|
//#region src/cli/publish/index.ts
|
|
17
18
|
const EXIT_OK = 0;
|
|
18
19
|
const EXIT_REFUSED = 1;
|
|
19
20
|
const EXIT_USAGE = 2;
|
|
20
|
-
/** The record is read this often while a publication runs. */
|
|
21
21
|
const POLL_INTERVAL_MS = 2e3;
|
|
22
|
-
/** Consecutive unanswered polls before the endpoint counts as lost: a minute at the default interval. */
|
|
23
22
|
const POLL_FAILURES_TOLERATED = 30;
|
|
24
23
|
const DEFAULT_DEPS = {
|
|
25
24
|
build: async (options) => (await import("../build/artifact.js")).buildArtifact(options),
|
|
@@ -29,7 +28,6 @@ const DEFAULT_DEPS = {
|
|
|
29
28
|
now: () => /* @__PURE__ */ new Date(),
|
|
30
29
|
pollIntervalMs: POLL_INTERVAL_MS
|
|
31
30
|
};
|
|
32
|
-
/** A run that ends here: the exit code, and the sentence (with its newline) to print first. */
|
|
33
31
|
var Ending = class extends Error {
|
|
34
32
|
code;
|
|
35
33
|
sentence;
|
|
@@ -40,7 +38,6 @@ var Ending = class extends Error {
|
|
|
40
38
|
}
|
|
41
39
|
};
|
|
42
40
|
const say = (sentence) => `concrete publish: ${sentence}\n`;
|
|
43
|
-
/** The ending an answer that is not `ok` calls for. */
|
|
44
41
|
function endingFor(answer, target, doing) {
|
|
45
42
|
switch (answer.kind) {
|
|
46
43
|
case "unreachable": return new Ending(EXIT_USAGE, say(`could not reach ${target.endpoint} while ${doing} (${answer.reason}); check the connection${target.overridden ? ` and ${API_URL_VARIABLE}` : ""}, then run again.`));
|
|
@@ -57,7 +54,6 @@ function unwrap(answer, target, doing) {
|
|
|
57
54
|
if (answer.kind === "ok") return answer.value;
|
|
58
55
|
throw endingFor(answer, target, doing);
|
|
59
56
|
}
|
|
60
|
-
/** The artifact to publish: the one on disk when the tree still matches it, else a fresh build. */
|
|
61
57
|
async function ensureArtifact(run, root, out, rebuild) {
|
|
62
58
|
const { io, deps } = run;
|
|
63
59
|
const freshness = await assessFreshness({
|
|
@@ -83,7 +79,6 @@ async function ensureArtifact(run, root, out, rebuild) {
|
|
|
83
79
|
io.stderr.write(stageLine("build", builtText(outcome.manifest)));
|
|
84
80
|
return outcome.manifest;
|
|
85
81
|
}
|
|
86
|
-
/** Follow the record to a terminal state, printing each stage as it settles. */
|
|
87
82
|
async function follow(run, client, target, first) {
|
|
88
83
|
const { io, deps } = run;
|
|
89
84
|
const printed = /* @__PURE__ */ new Set();
|
|
@@ -156,10 +151,7 @@ async function publishWorkspace(run, root, target, rebuild) {
|
|
|
156
151
|
io.stderr.write(`${summaryText(settled)}\n`);
|
|
157
152
|
return EXIT_OK;
|
|
158
153
|
} finally {
|
|
159
|
-
await
|
|
160
|
-
recursive: true,
|
|
161
|
-
force: true
|
|
162
|
-
});
|
|
154
|
+
await removeTree(scratch);
|
|
163
155
|
}
|
|
164
156
|
}
|
|
165
157
|
async function publish(argv, io, deps) {
|
|
@@ -182,7 +174,8 @@ async function publish(argv, io, deps) {
|
|
|
182
174
|
}
|
|
183
175
|
let target;
|
|
184
176
|
try {
|
|
185
|
-
|
|
177
|
+
const envFile = stringFlag(values, "env-file");
|
|
178
|
+
target = await resolveTarget(root, io.env, envFile === null ? void 0 : resolve(io.cwd, envFile));
|
|
186
179
|
} catch (cause) {
|
|
187
180
|
if (cause instanceof TargetError) throw new Ending(EXIT_USAGE, say(cause.message));
|
|
188
181
|
throw cause;
|
package/dist/cli/publish/pack.js
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
|
+
import { byCodeUnit } from "../../platform/order.js";
|
|
2
|
+
import { listDir } from "../../platform/fs.js";
|
|
1
3
|
import { createWriteStream } from "node:fs";
|
|
2
4
|
import { join } from "node:path";
|
|
3
|
-
import { lstat, readFile
|
|
5
|
+
import { lstat, readFile } from "node:fs/promises";
|
|
4
6
|
import { createGzip } from "node:zlib";
|
|
5
7
|
import { Readable } from "node:stream";
|
|
6
8
|
import { pipeline } from "node:stream/promises";
|
|
@@ -11,8 +13,7 @@ const NAME_FIELD = 100;
|
|
|
11
13
|
async function listFiles(dir) {
|
|
12
14
|
const out = [];
|
|
13
15
|
const visit = async (relative) => {
|
|
14
|
-
const
|
|
15
|
-
for (const entry of entries) {
|
|
16
|
+
for (const entry of await listDir(join(dir, relative))) {
|
|
16
17
|
const path = relative === "" ? entry.name : `${relative}/${entry.name}`;
|
|
17
18
|
if (entry.isDirectory()) await visit(path);
|
|
18
19
|
else if (entry.isFile()) out.push(path);
|
|
@@ -21,7 +22,7 @@ async function listFiles(dir) {
|
|
|
21
22
|
};
|
|
22
23
|
if (!(await lstat(dir)).isDirectory()) throw new Error(`${dir} is not a directory.`);
|
|
23
24
|
await visit("");
|
|
24
|
-
return out.sort();
|
|
25
|
+
return out.sort(byCodeUnit);
|
|
25
26
|
}
|
|
26
27
|
function octal(value, width) {
|
|
27
28
|
return `${value.toString(8).padStart(width - 1, "0")}\0`;
|
|
@@ -44,7 +45,6 @@ function header(name, size, type) {
|
|
|
44
45
|
return block;
|
|
45
46
|
}
|
|
46
47
|
const padding = (size) => Buffer.alloc((BLOCK - size % BLOCK) % BLOCK);
|
|
47
|
-
/** One pax record, `<length> path=<value>\n`, whose length counts its own digits. */
|
|
48
48
|
function paxRecord(path) {
|
|
49
49
|
const body = ` path=${path}\n`;
|
|
50
50
|
const bodyBytes = Buffer.byteLength(body, "utf8");
|
|
@@ -67,7 +67,6 @@ async function* entries(dir, paths) {
|
|
|
67
67
|
}
|
|
68
68
|
yield Buffer.alloc(BLOCK * 2);
|
|
69
69
|
}
|
|
70
|
-
/** Pack `dir` into a gzipped tar at `file`. */
|
|
71
70
|
async function packArtifact(dir, file) {
|
|
72
71
|
const paths = await listFiles(dir);
|
|
73
72
|
await pipeline(Readable.from(entries(dir, paths)), createGzip(), createWriteStream(file));
|