@homepages/concrete 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +59 -0
- package/README.md +174 -0
- package/codemods/manifest.json +9 -0
- package/dist/artifact/playground/client/assets/index-BSA1yutg.css +1 -0
- package/dist/artifact/playground/client/assets/index-JloQyj8h.js +1101 -0
- package/dist/artifact/playground/client/index.html +13 -0
- package/dist/artifact/playground/client/island-canvas-host.mjs +1 -0
- package/dist/artifact/playground/host.mjs +127 -0
- package/dist/asset-modules.d.ts +99 -0
- package/dist/base.css +220 -0
- package/dist/browser/site-config.d.ts +18 -0
- package/dist/browser/site-config.js +56 -0
- package/dist/browser/submit-lead.d.ts +98 -0
- package/dist/browser/submit-lead.js +188 -0
- package/dist/browser.d.ts +3 -0
- package/dist/browser.js +4 -0
- package/dist/cli/build/artifact.js +225 -0
- package/dist/cli/build/captures.js +67 -0
- package/dist/cli/build/esbuild.js +127 -0
- package/dist/cli/build/fixtures.js +96 -0
- package/dist/cli/build/icons.js +76 -0
- package/dist/cli/build/index.js +38 -0
- package/dist/cli/build/playground.js +31 -0
- package/dist/cli/build/sections.js +236 -0
- package/dist/cli/build/source.js +62 -0
- package/dist/cli/build/static.js +156 -0
- package/dist/cli/capture/bundle.js +37 -0
- package/dist/cli/capture/capture-browser.js +51 -0
- package/dist/cli/capture/capture.js +121 -0
- package/dist/cli/check/analyze.js +95 -0
- package/dist/cli/check/index.js +19 -0
- package/dist/cli/check/load-workspace.js +119 -0
- package/dist/cli/check/messages.js +16 -0
- package/dist/cli/check/render/class-conflicts.js +39 -0
- package/dist/cli/check/render/html.js +86 -0
- package/dist/cli/check/render/inputs.js +53 -0
- package/dist/cli/check/render/invariants.js +58 -0
- package/dist/cli/check/render/island-frames.js +72 -0
- package/dist/cli/check/render/marker-coverage.js +102 -0
- package/dist/cli/check/render/nav.js +64 -0
- package/dist/cli/check/report.js +73 -0
- package/dist/cli/check/stages/bundles.js +129 -0
- package/dist/cli/check/stages/composition.js +67 -0
- package/dist/cli/check/stages/contracts.js +22 -0
- package/dist/cli/check/stages/dependencies.js +261 -0
- package/dist/cli/check/stages/fixtures.js +74 -0
- package/dist/cli/check/stages/lint.js +41 -0
- package/dist/cli/check/stages/logic.js +63 -0
- package/dist/cli/check/stages/render.js +144 -0
- package/dist/cli/check/stages/sections.js +83 -0
- package/dist/cli/check/stages/stylesheet.js +31 -0
- package/dist/cli/check/stages/typecheck.js +68 -0
- package/dist/cli/check/stages/workspace.js +26 -0
- package/dist/cli/commands.js +342 -0
- package/dist/cli/currency/cache.js +89 -0
- package/dist/cli/currency/decide.js +65 -0
- package/dist/cli/currency/opt-out.js +16 -0
- package/dist/cli/currency/preamble.js +183 -0
- package/dist/cli/currency/prompt.js +28 -0
- package/dist/cli/currency/refresh.js +44 -0
- package/dist/cli/currency/resolve-latest.js +185 -0
- package/dist/cli/currency/version-order.js +38 -0
- package/dist/cli/dev/crop.js +22 -0
- package/dist/cli/dev/hmr.js +26 -0
- package/dist/cli/dev/http.js +129 -0
- package/dist/cli/dev/index.js +70 -0
- package/dist/cli/dev/islands.js +390 -0
- package/dist/cli/dev/load-template.js +46 -0
- package/dist/cli/dev/request-error.js +22 -0
- package/dist/cli/dev/server.js +307 -0
- package/dist/cli/dev/tsconfig-paths.js +95 -0
- package/dist/cli/dev/vite.js +85 -0
- package/dist/cli/dev/workspace-reader.js +274 -0
- package/dist/cli/io.d.ts +14 -0
- package/dist/cli/media/cache.js +125 -0
- package/dist/cli/media/derive.js +252 -0
- package/dist/cli/media/deriver-plugin.js +71 -0
- package/dist/cli/property/index.js +180 -0
- package/dist/cli/property/library.js +137 -0
- package/dist/cli/publish/client.js +119 -0
- package/dist/cli/publish/freshness.js +66 -0
- package/dist/cli/publish/git.js +43 -0
- package/dist/cli/publish/index.js +207 -0
- package/dist/cli/publish/pack.js +78 -0
- package/dist/cli/publish/report.js +98 -0
- package/dist/cli/publish/target.js +87 -0
- package/dist/cli/publish/wire.js +29 -0
- package/dist/cli/tar.js +87 -0
- package/dist/cli/upgrade/codemod.js +56 -0
- package/dist/cli/upgrade/index.js +263 -0
- package/dist/cli/upgrade/manifest.js +72 -0
- package/dist/cli/upgrade/plan.js +68 -0
- package/dist/cli/upgrade/stage.js +71 -0
- package/dist/cli/version.d.ts +12 -0
- package/dist/cli/version.js +15 -0
- package/dist/cli/workspace.js +108 -0
- package/dist/cli.d.ts +6 -0
- package/dist/cli.js +94 -0
- package/dist/css/compile.js +77 -0
- package/dist/css/graph.js +109 -0
- package/dist/css/inline.js +132 -0
- package/dist/css/rules.js +65 -0
- package/dist/design-system/format-variants.js +127 -0
- package/dist/eslint/authoring.js +46 -0
- package/dist/eslint/correctness.js +42 -0
- package/dist/eslint/rules/editor-declaration.js +103 -0
- package/dist/eslint/rules/editor-reason.js +135 -0
- package/dist/eslint/rules/island-imports.js +20 -0
- package/dist/eslint/rules/jsx-visitor.js +20 -0
- package/dist/eslint/rules/no-client-runtime.js +88 -0
- package/dist/eslint/rules/no-editor-globals.js +60 -0
- package/dist/eslint/rules/no-hard-coded-color.js +183 -0
- package/dist/eslint/rules/no-inline-style.js +24 -0
- package/dist/eslint/rules/no-marker-literal.js +37 -0
- package/dist/eslint/rules/no-nondeterminism.js +44 -0
- package/dist/eslint/rules/no-px-breakpoint.js +44 -0
- package/dist/eslint/rules/no-raw-values.js +45 -0
- package/dist/eslint/rules/serializable-props.js +95 -0
- package/dist/eslint.d.ts +6 -0
- package/dist/eslint.js +26 -0
- package/dist/fixtures/brand.d.ts +4 -0
- package/dist/fixtures/brand.js +9 -0
- package/dist/fixtures/bundle-rule.js +67 -0
- package/dist/fixtures/canonical.d.ts +149 -0
- package/dist/fixtures/image-dimensions.js +59 -0
- package/dist/fixtures/load.js +154 -0
- package/dist/fixtures/media-plugin.js +141 -0
- package/dist/fixtures/media.js +165 -0
- package/dist/fixtures/property.js +210 -0
- package/dist/fixtures/resolve.js +202 -0
- package/dist/fixtures/rows.js +108 -0
- package/dist/fixtures/synthesize-empties.js +42 -0
- package/dist/fixtures.d.ts +213 -0
- package/dist/fixtures.js +37 -0
- package/dist/index.d.ts +53 -0
- package/dist/index.js +37 -0
- package/dist/islands/client-module.js +97 -0
- package/dist/islands/marker.d.ts +43 -0
- package/dist/islands/marker.js +44 -0
- package/dist/node_modules/.pnpm/fflate@0.8.3/node_modules/fflate/esm/browser.js +687 -0
- package/dist/packages/external/concrete/package.js +5 -0
- package/dist/packages/internal/fact-interpolation/dist/index.js +22 -0
- package/dist/packages/internal/fill-bake/dist/bake-property-ref.js +111 -0
- package/dist/packages/internal/fill-bake/dist/display.js +9 -0
- package/dist/packages/internal/fill-bake/dist/index.js +6 -0
- package/dist/packages/internal/fill-bake/dist/reconcile-cross-section.js +170 -0
- package/dist/packages/internal/fill-vocabulary/dist/facts.d.ts +32 -0
- package/dist/packages/internal/fill-vocabulary/dist/facts.js +131 -0
- package/dist/packages/internal/fill-vocabulary/dist/row-planners.js +73 -0
- package/dist/packages/internal/format-geometry/dist/capture.js +404 -0
- package/dist/packages/internal/format-geometry/dist/format.d.ts +41 -0
- package/dist/packages/internal/format-geometry/dist/geometry.js +58 -0
- package/dist/packages/internal/format-geometry/dist/index.js +4 -0
- package/dist/packages/internal/image-descriptor/dist/index.d.ts +35 -0
- package/dist/packages/internal/image-ladder/dist/crop.js +82 -0
- package/dist/packages/internal/image-ladder/dist/encode.js +23 -0
- package/dist/packages/internal/image-ladder/dist/index.js +4 -0
- package/dist/packages/internal/image-ladder/dist/policy.js +102 -0
- package/dist/packages/internal/island-runtime/dist/capture-holds.d.ts +13 -0
- package/dist/packages/internal/island-runtime/dist/capture-holds.js +45 -0
- package/dist/packages/internal/island-runtime/dist/contract.d.ts +176 -0
- package/dist/packages/internal/island-runtime/dist/contract.js +94 -0
- package/dist/packages/internal/island-runtime/dist/editor-instance-context.js +15 -0
- package/dist/packages/internal/island-runtime/dist/index.d.ts +103 -0
- package/dist/packages/internal/island-runtime/dist/index.js +163 -0
- package/dist/packages/internal/island-runtime/dist/use-capture-ready.d.ts +19 -0
- package/dist/packages/internal/island-runtime/dist/use-capture-ready.js +39 -0
- package/dist/packages/internal/island-runtime/dist/use-editor.d.ts +22 -0
- package/dist/packages/internal/island-runtime/dist/use-editor.js +54 -0
- package/dist/packages/internal/island-runtime/dist/viewport-schedule.js +105 -0
- package/dist/packages/internal/property-facts/dist/derive-facts-view.js +25 -0
- package/dist/packages/internal/property-facts/dist/index.js +3 -0
- package/dist/packages/internal/property-facts/dist/property-facts-CSdkSuD7.js +181 -0
- package/dist/packages/internal/section-contracts/dist/cap-contract.js +59 -0
- package/dist/packages/internal/section-contracts/dist/catalog.js +102 -0
- package/dist/packages/internal/section-contracts/dist/choose-select-contract.js +24 -0
- package/dist/packages/internal/section-contracts/dist/count-bounds-contract.js +48 -0
- package/dist/packages/internal/section-contracts/dist/display-contract.js +30 -0
- package/dist/packages/internal/section-contracts/dist/display-evidence-contract.js +17 -0
- package/dist/packages/internal/section-contracts/dist/group-contract.js +21 -0
- package/dist/packages/internal/section-contracts/dist/index.js +26 -0
- package/dist/packages/internal/section-contracts/dist/interpolation-contract.js +48 -0
- package/dist/packages/internal/section-contracts/dist/list-fill-contract.js +53 -0
- package/dist/packages/internal/section-contracts/dist/list-scalar-contract.js +70 -0
- package/dist/packages/internal/section-contracts/dist/name-title-contract.js +27 -0
- package/dist/packages/internal/section-contracts/dist/nested-slot-contract.js +12 -0
- package/dist/packages/internal/section-contracts/dist/option-source-contract.js +22 -0
- package/dist/packages/internal/section-contracts/dist/poi-curation-contract.js +18 -0
- package/dist/packages/internal/section-contracts/dist/pooling-field-contract.js +30 -0
- package/dist/packages/internal/section-contracts/dist/record-collection-contract.js +24 -0
- package/dist/packages/internal/section-contracts/dist/row-contract.js +37 -0
- package/dist/packages/internal/section-contracts/dist/row-fill-contract.js +38 -0
- package/dist/packages/internal/section-contracts/dist/runners.js +181 -0
- package/dist/packages/internal/section-contracts/dist/select-contract.js +28 -0
- package/dist/packages/internal/section-contracts/dist/source-contract.js +48 -0
- package/dist/packages/internal/section-contracts/dist/source-filter-contract.js +15 -0
- package/dist/packages/internal/section-contracts/dist/sources-contract.js +28 -0
- package/dist/packages/internal/section-contracts/dist/url-contract.js +20 -0
- package/dist/packages/internal/source-resolution/dist/index.js +222 -0
- package/dist/packages/internal/template-artifact/dist/hash.js +50 -0
- package/dist/packages/internal/template-artifact/dist/index.js +7 -0
- package/dist/packages/internal/template-artifact/dist/layout.js +165 -0
- package/dist/packages/internal/template-artifact/dist/manifest.js +73 -0
- package/dist/packages/internal/template-artifact/dist/sha256.js +138 -0
- package/dist/packages/internal/template-artifact/dist/verify.js +275 -0
- package/dist/packages/internal/template-contracts/dist/collection-editing.js +38 -0
- package/dist/packages/internal/template-contracts/dist/content-categories.d.ts +10 -0
- package/dist/packages/internal/template-contracts/dist/content-categories.js +17 -0
- package/dist/packages/internal/template-contracts/dist/document-value.d.ts +33 -0
- package/dist/packages/internal/template-contracts/dist/facts-view.d.ts +81 -0
- package/dist/packages/internal/template-contracts/dist/facts-view.js +136 -0
- package/dist/packages/internal/template-contracts/dist/layout.js +17 -0
- package/dist/packages/internal/template-contracts/dist/markers.d.ts +40 -0
- package/dist/packages/internal/template-contracts/dist/markers.js +41 -0
- package/dist/packages/internal/template-contracts/dist/poi-row.d.ts +63 -0
- package/dist/packages/internal/template-contracts/dist/select-key.js +13 -0
- package/dist/packages/internal/template-contracts/dist/slot-catalog.d.ts +1112 -0
- package/dist/packages/internal/template-contracts/dist/slot-catalog.js +1109 -0
- package/dist/packages/internal/template-contracts/dist/slot-overrides.js +11 -0
- package/dist/packages/internal/template-contracts/dist/tour-value.d.ts +45 -0
- package/dist/packages/internal/template-contracts/dist/video-value.d.ts +63 -0
- package/dist/playground/host/page-state.js +12 -0
- package/dist/playground/host/paths.js +9 -0
- package/dist/playground/layout.js +24 -0
- package/dist/playground/wire.js +36 -0
- package/dist/playground-island-runtime.d.ts +3 -0
- package/dist/playground-island-runtime.js +4 -0
- package/dist/primitives/FrameShell.d.ts +29 -0
- package/dist/primitives/FrameShell.js +34 -0
- package/dist/primitives/Image.d.ts +119 -0
- package/dist/primitives/Image.js +173 -0
- package/dist/primitives/Section.d.ts +22 -0
- package/dist/primitives/Section.js +26 -0
- package/dist/primitives/Tour.d.ts +43 -0
- package/dist/primitives/Tour.js +72 -0
- package/dist/primitives/Video.d.ts +57 -0
- package/dist/primitives/Video.js +116 -0
- package/dist/primitives/embed-playback.js +50 -0
- package/dist/primitives/index.d.ts +11 -0
- package/dist/primitives/marker-attrs.js +44 -0
- package/dist/primitives/object-fit.js +11 -0
- package/dist/primitives/picture-sources.d.ts +24 -0
- package/dist/primitives/picture-sources.js +52 -0
- package/dist/primitives/probe-context.js +24 -0
- package/dist/primitives/slot-bindings.d.ts +96 -0
- package/dist/primitives/slot-bindings.js +226 -0
- package/dist/primitives/slot-document.d.ts +35 -0
- package/dist/primitives/slot-document.js +37 -0
- package/dist/primitives/slot-group.d.ts +40 -0
- package/dist/primitives/slot-group.js +45 -0
- package/dist/primitives/slot-list.d.ts +21 -0
- package/dist/primitives/slot-list.js +23 -0
- package/dist/primitives/slot-media.d.ts +71 -0
- package/dist/primitives/slot-media.js +98 -0
- package/dist/primitives/slot-scalar.d.ts +53 -0
- package/dist/primitives/slot-scalar.js +98 -0
- package/dist/primitives/slot.d.ts +26 -0
- package/dist/primitives/slot.js +28 -0
- package/dist/rules/registry.js +479 -0
- package/dist/schema/compute.d.ts +22 -0
- package/dist/schema/compute.js +30 -0
- package/dist/schema/define-schema.d.ts +27 -0
- package/dist/schema/define-schema.js +73 -0
- package/dist/schema/extract-fill-spec.js +246 -0
- package/dist/schema/extract-used-facts.js +176 -0
- package/dist/schema/fact.d.ts +65 -0
- package/dist/schema/fact.js +33 -0
- package/dist/schema/fill-builders.d.ts +387 -0
- package/dist/schema/fill-builders.js +263 -0
- package/dist/schema/fill-declaration.d.ts +76 -0
- package/dist/schema/fill-declaration.js +43 -0
- package/dist/schema/fill-spec.d.ts +18 -0
- package/dist/schema/fill-spec.js +170 -0
- package/dist/schema/format-presets.d.ts +27 -0
- package/dist/schema/format-presets.js +76 -0
- package/dist/schema/format.d.ts +22 -0
- package/dist/schema/format.js +40 -0
- package/dist/schema/formats.d.ts +6 -0
- package/dist/schema/formats.js +7 -0
- package/dist/schema/layout.d.ts +32 -0
- package/dist/schema/layout.js +30 -0
- package/dist/schema/manifest.js +300 -0
- package/dist/schema/property-facts.d.ts +83 -0
- package/dist/schema/runtime-values.d.ts +88 -0
- package/dist/schema/section-nav.d.ts +38 -0
- package/dist/schema/section-nav.js +29 -0
- package/dist/schema/section-props.d.ts +98 -0
- package/dist/schema/section-schema.d.ts +53 -0
- package/dist/schema/section-schema.js +54 -0
- package/dist/schema/slot-builders.d.ts +497 -0
- package/dist/schema/slot-builders.js +331 -0
- package/dist/schema/slot-types.d.ts +110 -0
- package/dist/schema/slot-types.js +187 -0
- package/dist/section/declare.d.ts +44 -0
- package/dist/section/declare.js +27 -0
- package/dist/section/discovery.js +76 -0
- package/dist/section/groups.js +74 -0
- package/dist/section/materialize.js +28 -0
- package/dist/section/placements.js +28 -0
- package/dist/section/section.d.ts +69 -0
- package/dist/section/section.js +101 -0
- package/dist/site-analytics.d.ts +1 -0
- package/dist/site-analytics.js +15 -0
- package/dist/site-runtime/analytics.js +97 -0
- package/dist/site-runtime/site-integrations.js +97 -0
- package/dist/styles.css +60 -0
- package/dist/template/define-template.d.ts +139 -0
- package/dist/template/define-template.js +98 -0
- package/dist/template/logic-build.js +191 -0
- package/dist/template/logic-shim.d.ts +43 -0
- package/dist/template/logic-shim.js +52 -0
- package/dist/template/logic-transform.js +92 -0
- package/dist/template/materialize.js +107 -0
- package/dist/template/reconcile.d.ts +67 -0
- package/dist/template/reconcile.js +25 -0
- package/dist/template/running-copy.js +58 -0
- package/guide/reference/cli/INDEX.md +79 -0
- package/guide/reference/cli/build.md +48 -0
- package/guide/reference/cli/check.md +49 -0
- package/guide/reference/cli/dev.md +46 -0
- package/guide/reference/cli/property-add.md +53 -0
- package/guide/reference/cli/property-list.md +46 -0
- package/guide/reference/cli/publish.md +54 -0
- package/guide/reference/cli/upgrade.md +48 -0
- package/guide/reference/rules/INDEX.md +190 -0
- package/package.json +137 -0
- package/tsconfig.base.json +16 -0
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import { compareVersions, parseVersion } from "./version-order.js";
|
|
2
|
+
|
|
3
|
+
//#region src/cli/currency/decide.ts
|
|
4
|
+
/**
|
|
5
|
+
* The rules that need no registry, cheapest first, each short-circuiting.
|
|
6
|
+
*
|
|
7
|
+
* The order is the point: opting out has to be the first rule or it is not an opt-out,
|
|
8
|
+
* and neither rule needs anything the workspace does not already hold.
|
|
9
|
+
*/
|
|
10
|
+
function decideLocally(signals) {
|
|
11
|
+
if (signals.optedOut) return {
|
|
12
|
+
state: "inert",
|
|
13
|
+
reason: "opted-out"
|
|
14
|
+
};
|
|
15
|
+
if (!signals.registryRange) return {
|
|
16
|
+
state: "inert",
|
|
17
|
+
reason: "not-a-registry-range"
|
|
18
|
+
};
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Whether the registry has to be read at all.
|
|
22
|
+
*
|
|
23
|
+
* Defined by the same chain `decideCurrency` short-circuits on, rather than restated,
|
|
24
|
+
* so the two can never drift into a caller that reads the network for a workspace
|
|
25
|
+
* already decided without it.
|
|
26
|
+
*/
|
|
27
|
+
function registryNeeded(signals) {
|
|
28
|
+
return decideLocally(signals) === void 0;
|
|
29
|
+
}
|
|
30
|
+
function blockedReason(signals, latest, crossesMajor) {
|
|
31
|
+
if (!signals.tty) return "not-a-tty";
|
|
32
|
+
if (!signals.lockfile) return "lockfile-missing";
|
|
33
|
+
if (crossesMajor && signals.declinedVersions.includes(latest)) return "declined";
|
|
34
|
+
return null;
|
|
35
|
+
}
|
|
36
|
+
/** Total: every signals object maps to exactly one decision, and nothing throws. */
|
|
37
|
+
function decideCurrency(signals) {
|
|
38
|
+
const local = decideLocally(signals);
|
|
39
|
+
if (local !== void 0) return local;
|
|
40
|
+
if (signals.latest === null) return {
|
|
41
|
+
state: "inert",
|
|
42
|
+
reason: "registry-unknown"
|
|
43
|
+
};
|
|
44
|
+
const installed = parseVersion(signals.installed);
|
|
45
|
+
const latest = parseVersion(signals.latest);
|
|
46
|
+
if (installed === null || latest === null) return {
|
|
47
|
+
state: "inert",
|
|
48
|
+
reason: "unreadable-version"
|
|
49
|
+
};
|
|
50
|
+
if (compareVersions(installed, latest) >= 0) return {
|
|
51
|
+
state: "current",
|
|
52
|
+
installed: signals.installed,
|
|
53
|
+
latest: signals.latest
|
|
54
|
+
};
|
|
55
|
+
const crossesMajor = latest.major > installed.major;
|
|
56
|
+
return {
|
|
57
|
+
state: crossesMajor ? "new-major" : "behind-within-major",
|
|
58
|
+
installed: signals.installed,
|
|
59
|
+
latest: signals.latest,
|
|
60
|
+
blocked: blockedReason(signals, signals.latest, crossesMajor)
|
|
61
|
+
};
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
//#endregion
|
|
65
|
+
export { decideCurrency, registryNeeded };
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
//#region src/cli/currency/opt-out.ts
|
|
2
|
+
const NO_AUTO_UPDATE_ENV = "HOMEPAGES_NO_AUTO_UPDATE";
|
|
3
|
+
/**
|
|
4
|
+
* Whether the author turned the whole feature off.
|
|
5
|
+
*
|
|
6
|
+
* Documented as `=1`, but any value other than `0` counts: an author who exports it as
|
|
7
|
+
* `true` in a shell profile means the same thing, and silently ignoring that spelling
|
|
8
|
+
* would install over them.
|
|
9
|
+
*/
|
|
10
|
+
function optedOut(env) {
|
|
11
|
+
const value = env[NO_AUTO_UPDATE_ENV];
|
|
12
|
+
return value !== void 0 && value !== "" && value !== "0";
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
//#endregion
|
|
16
|
+
export { NO_AUTO_UPDATE_ENV, optedOut };
|
|
@@ -0,0 +1,183 @@
|
|
|
1
|
+
import { findCommand, flagName, hasNoAutoUpdateFlag } from "../commands.js";
|
|
2
|
+
import { findWorkspaceRoot, isRegistryRange, readDeclaredRange, resolveInstalledVersion } from "../workspace.js";
|
|
3
|
+
import { defaultCacheRoot, openCurrencyCache } from "./cache.js";
|
|
4
|
+
import { decideCurrency, registryNeeded } from "./decide.js";
|
|
5
|
+
import { optedOut } from "./opt-out.js";
|
|
6
|
+
import { askYesNo } from "./prompt.js";
|
|
7
|
+
import { REFRESH_COMMAND, npmUpdate } from "./refresh.js";
|
|
8
|
+
import { resolveLatest } from "./resolve-latest.js";
|
|
9
|
+
import { join } from "node:path";
|
|
10
|
+
import { stat } from "node:fs/promises";
|
|
11
|
+
|
|
12
|
+
//#region src/cli/currency/preamble.ts
|
|
13
|
+
const NOTHING_HAPPENED = {
|
|
14
|
+
decision: null,
|
|
15
|
+
refresh: "not-attempted"
|
|
16
|
+
};
|
|
17
|
+
async function isFile(path) {
|
|
18
|
+
try {
|
|
19
|
+
return (await stat(path)).isFile();
|
|
20
|
+
} catch {
|
|
21
|
+
return false;
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
async function gatherLocalSignals(root, options, env) {
|
|
25
|
+
return {
|
|
26
|
+
installed: await resolveInstalledVersion(root) ?? options.cliVersion,
|
|
27
|
+
optedOut: optedOut(env) || hasNoAutoUpdateFlag(options.argv),
|
|
28
|
+
registryRange: isRegistryRange(await readDeclaredRange(root) ?? "*"),
|
|
29
|
+
tty: options.tty ?? process.stdout.isTTY === true,
|
|
30
|
+
lockfile: await isFile(join(root, "package-lock.json"))
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
/** The registry's answer for this workspace, through the user-scoped time cache. */
|
|
34
|
+
async function latestVersion(cache, root, options, env) {
|
|
35
|
+
const declinedVersions = await cache.declinedVersions();
|
|
36
|
+
const cached = await cache.readLatest();
|
|
37
|
+
if (cached !== void 0) return {
|
|
38
|
+
latest: cached.value,
|
|
39
|
+
declinedVersions
|
|
40
|
+
};
|
|
41
|
+
const latest = await (options.resolveLatestImpl ?? resolveLatest)({
|
|
42
|
+
cwd: root,
|
|
43
|
+
env
|
|
44
|
+
});
|
|
45
|
+
await cache.writeLatest(latest);
|
|
46
|
+
return {
|
|
47
|
+
latest,
|
|
48
|
+
declinedVersions
|
|
49
|
+
};
|
|
50
|
+
}
|
|
51
|
+
function say(sink, lines) {
|
|
52
|
+
sink.write(`${lines.join("\n")}\n`);
|
|
53
|
+
}
|
|
54
|
+
const gap = (installed, latest) => `concrete: ${latest} is published; this workspace is on ${installed}.`;
|
|
55
|
+
/**
|
|
56
|
+
* Reports a real gap the preamble may not act on. Each reason is a different thing for
|
|
57
|
+
* the author to do, so none of them share a line — a message that only said "not
|
|
58
|
+
* refreshing" would leave the author with nothing to fix.
|
|
59
|
+
*/
|
|
60
|
+
function reportBlocked(sink, installed, latest, reason) {
|
|
61
|
+
say(sink, [reason === "not-a-tty" ? `${gap(installed, latest)} Not refreshing outside a terminal — run \`npm update\` at the workspace root to catch up.` : `${gap(installed, latest)} There is no package-lock.json to refresh — run \`npm install\` at the workspace root first.`]);
|
|
62
|
+
}
|
|
63
|
+
async function refreshWorkspace(root, installed, latest, options, env, sink) {
|
|
64
|
+
say(sink, [`${gap(installed, latest)} Refreshing — \`--no-auto-update\` skips this.`, ` npm ${REFRESH_COMMAND.join(" ")}`]);
|
|
65
|
+
if (!await (options.refreshImpl ?? npmUpdate)({
|
|
66
|
+
root,
|
|
67
|
+
env,
|
|
68
|
+
sink
|
|
69
|
+
})) {
|
|
70
|
+
say(sink, [`concrete: the refresh did not complete. Continuing on ${installed} — run \`npm update\` when you can.`]);
|
|
71
|
+
return "failed";
|
|
72
|
+
}
|
|
73
|
+
say(sink, [`concrete: now on ${await resolveInstalledVersion(root) ?? latest}.`]);
|
|
74
|
+
return "succeeded";
|
|
75
|
+
}
|
|
76
|
+
/** `upgrade`'s own routine, imported only when an author has actually said yes. */
|
|
77
|
+
const runUpgradeCommand = async ({ root, target, env, sink }) => {
|
|
78
|
+
const { runUpgrade } = await import("../upgrade/index.js");
|
|
79
|
+
return runUpgrade([flagName(findCommand("upgrade"), "to"), target], {
|
|
80
|
+
cwd: root,
|
|
81
|
+
env,
|
|
82
|
+
stdout: sink,
|
|
83
|
+
stderr: sink,
|
|
84
|
+
tty: true
|
|
85
|
+
});
|
|
86
|
+
};
|
|
87
|
+
/**
|
|
88
|
+
* The one branch that asks a question.
|
|
89
|
+
*
|
|
90
|
+
* Crossing a major is a manifest rewrite plus its codemods, so it is never automatic —
|
|
91
|
+
* but a notice the author can only act on later leaves the gap open indefinitely, which
|
|
92
|
+
* is what the question closes. Whichever way it is answered, the command the author
|
|
93
|
+
* actually typed runs afterwards; nothing here returns a code, and nothing here throws.
|
|
94
|
+
*/
|
|
95
|
+
async function crossMajor(root, decision, cache, options, env, sink) {
|
|
96
|
+
if (decision.blocked !== null) {
|
|
97
|
+
say(sink, [`${gap(decision.installed, decision.latest)} That crosses a major, which is never automatic — continuing on ${decision.installed}.`, ` Run \`concrete upgrade\` when you are ready to move.`]);
|
|
98
|
+
return "not-attempted";
|
|
99
|
+
}
|
|
100
|
+
say(sink, [`${gap(decision.installed, decision.latest)} That crosses a major, so nothing moves without you.`]);
|
|
101
|
+
if (!await (options.askImpl ?? askYesNo)({
|
|
102
|
+
question: ` Move this workspace to ${decision.latest} now? [Y/n] `,
|
|
103
|
+
sink
|
|
104
|
+
})) {
|
|
105
|
+
await cache.decline(decision.latest);
|
|
106
|
+
say(sink, [`concrete: staying on ${decision.installed}. Run \`concrete upgrade\` when you are ready to move —`, ` this will not ask about ${decision.latest} again.`]);
|
|
107
|
+
return "not-attempted";
|
|
108
|
+
}
|
|
109
|
+
let code;
|
|
110
|
+
try {
|
|
111
|
+
code = await (options.upgradeImpl ?? runUpgradeCommand)({
|
|
112
|
+
root,
|
|
113
|
+
target: decision.latest,
|
|
114
|
+
env,
|
|
115
|
+
sink
|
|
116
|
+
});
|
|
117
|
+
} catch (cause) {
|
|
118
|
+
code = 1;
|
|
119
|
+
say(sink, [`concrete: the upgrade could not run (${cause instanceof Error ? cause.message : String(cause)}).`]);
|
|
120
|
+
}
|
|
121
|
+
if (code !== 0) {
|
|
122
|
+
say(sink, [`concrete: continuing on ${decision.installed}.`]);
|
|
123
|
+
return "failed";
|
|
124
|
+
}
|
|
125
|
+
say(sink, [`concrete: this command is still running ${decision.installed} — the next one you run will be ${decision.latest}.`]);
|
|
126
|
+
return "succeeded";
|
|
127
|
+
}
|
|
128
|
+
/**
|
|
129
|
+
* Bring the workspace up to the published release before the command runs, or say why
|
|
130
|
+
* that did not happen.
|
|
131
|
+
*
|
|
132
|
+
* Never throws and never writes to stdout. Returns what it decided so a caller — in
|
|
133
|
+
* practice a test — can see the whole behaviour table without reading bytes.
|
|
134
|
+
*/
|
|
135
|
+
async function enforceCurrency(options) {
|
|
136
|
+
const env = options.env ?? process.env;
|
|
137
|
+
const sink = options.sink ?? process.stderr;
|
|
138
|
+
let root;
|
|
139
|
+
try {
|
|
140
|
+
root = await findWorkspaceRoot(options.cwd);
|
|
141
|
+
} catch {
|
|
142
|
+
return NOTHING_HAPPENED;
|
|
143
|
+
}
|
|
144
|
+
const local = await gatherLocalSignals(root, options, env);
|
|
145
|
+
const cache = openCurrencyCache({
|
|
146
|
+
root: options.cacheRoot ?? defaultCacheRoot(env),
|
|
147
|
+
now: options.now ?? Date.now
|
|
148
|
+
});
|
|
149
|
+
const registry = registryNeeded(local) ? await latestVersion(cache, root, options, env) : {
|
|
150
|
+
latest: null,
|
|
151
|
+
declinedVersions: []
|
|
152
|
+
};
|
|
153
|
+
const decision = decideCurrency({
|
|
154
|
+
...local,
|
|
155
|
+
...registry
|
|
156
|
+
});
|
|
157
|
+
switch (decision.state) {
|
|
158
|
+
case "inert":
|
|
159
|
+
case "current": return {
|
|
160
|
+
decision,
|
|
161
|
+
refresh: "not-attempted"
|
|
162
|
+
};
|
|
163
|
+
case "new-major": return {
|
|
164
|
+
decision,
|
|
165
|
+
refresh: await crossMajor(root, decision, cache, options, env, sink)
|
|
166
|
+
};
|
|
167
|
+
case "behind-within-major":
|
|
168
|
+
if (decision.blocked === "not-a-tty" || decision.blocked === "lockfile-missing") {
|
|
169
|
+
reportBlocked(sink, decision.installed, decision.latest, decision.blocked);
|
|
170
|
+
return {
|
|
171
|
+
decision,
|
|
172
|
+
refresh: "not-attempted"
|
|
173
|
+
};
|
|
174
|
+
}
|
|
175
|
+
return {
|
|
176
|
+
decision,
|
|
177
|
+
refresh: await refreshWorkspace(root, decision.installed, decision.latest, options, env, sink)
|
|
178
|
+
};
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
//#endregion
|
|
183
|
+
export { enforceCurrency };
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { createInterface } from "node:readline";
|
|
2
|
+
|
|
3
|
+
//#region src/cli/currency/prompt.ts
|
|
4
|
+
/** Only a whole word: a path or a sentence typed at the prompt is not a decline. */
|
|
5
|
+
const NO = /^n(o)?$/i;
|
|
6
|
+
const askYesNo = async ({ question, sink, input = process.stdin }) => {
|
|
7
|
+
const reader = createInterface({
|
|
8
|
+
input,
|
|
9
|
+
output: sink
|
|
10
|
+
});
|
|
11
|
+
try {
|
|
12
|
+
const answer = await new Promise((resolve) => {
|
|
13
|
+
reader.once("close", () => {
|
|
14
|
+
resolve(null);
|
|
15
|
+
});
|
|
16
|
+
reader.question(question, resolve);
|
|
17
|
+
});
|
|
18
|
+
return answer === null || !NO.test(answer.trim());
|
|
19
|
+
} catch {
|
|
20
|
+
return true;
|
|
21
|
+
} finally {
|
|
22
|
+
reader.close();
|
|
23
|
+
input.pause();
|
|
24
|
+
}
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
//#endregion
|
|
28
|
+
export { askYesNo };
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { CONCRETE_PACKAGE } from "../workspace.js";
|
|
2
|
+
import { spawn } from "node:child_process";
|
|
3
|
+
|
|
4
|
+
//#region src/cli/currency/refresh.ts
|
|
5
|
+
/** The exact invocation, so the notice that names it and the run that makes it agree. */
|
|
6
|
+
const REFRESH_COMMAND = ["update", CONCRETE_PACKAGE];
|
|
7
|
+
/**
|
|
8
|
+
* One npm subcommand at the workspace root, streamed. `null` on success, the failure
|
|
9
|
+
* text otherwise. Never throws. Shared with `upgrade`'s install, so the two surfaces that
|
|
10
|
+
* run npm on an author's behalf stream it, and fail, the same way.
|
|
11
|
+
*/
|
|
12
|
+
function runNpm(args, { root, env, sink }) {
|
|
13
|
+
return new Promise((resolve) => {
|
|
14
|
+
let child;
|
|
15
|
+
try {
|
|
16
|
+
child = spawn("npm", [...args], {
|
|
17
|
+
cwd: root,
|
|
18
|
+
env: { ...env },
|
|
19
|
+
stdio: [
|
|
20
|
+
"ignore",
|
|
21
|
+
"pipe",
|
|
22
|
+
"pipe"
|
|
23
|
+
],
|
|
24
|
+
shell: process.platform === "win32"
|
|
25
|
+
});
|
|
26
|
+
} catch (cause) {
|
|
27
|
+
resolve(cause instanceof Error ? cause.message : String(cause));
|
|
28
|
+
return;
|
|
29
|
+
}
|
|
30
|
+
child.stdout.pipe(sink, { end: false });
|
|
31
|
+
child.stderr.pipe(sink, { end: false });
|
|
32
|
+
child.once("error", (cause) => {
|
|
33
|
+
resolve(cause.message);
|
|
34
|
+
});
|
|
35
|
+
child.once("close", (code, signal) => {
|
|
36
|
+
if (code === 0) resolve(null);
|
|
37
|
+
else resolve(signal === null ? `npm ${args[0] ?? ""} exited ${String(code)}` : `npm ${args[0] ?? ""} was killed by ${signal}`);
|
|
38
|
+
});
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
const npmUpdate = async (request) => await runNpm(REFRESH_COMMAND, request) === null;
|
|
42
|
+
|
|
43
|
+
//#endregion
|
|
44
|
+
export { REFRESH_COMMAND, npmUpdate, runNpm };
|
|
@@ -0,0 +1,185 @@
|
|
|
1
|
+
import { CONCRETE_PACKAGE } from "../workspace.js";
|
|
2
|
+
import { z } from "zod";
|
|
3
|
+
import { execFile } from "node:child_process";
|
|
4
|
+
import { promisify } from "node:util";
|
|
5
|
+
|
|
6
|
+
//#region src/cli/currency/resolve-latest.ts
|
|
7
|
+
const execFileAsync = promisify(execFile);
|
|
8
|
+
/** The package whose `latest` decides currency. */
|
|
9
|
+
const CURRENCY_PACKAGE = CONCRETE_PACKAGE;
|
|
10
|
+
/**
|
|
11
|
+
* The whole budget, config read included.
|
|
12
|
+
*
|
|
13
|
+
* Not incidental: without a deadline a hung registry connection turns every author
|
|
14
|
+
* command into a hang, which is the one failure that would make an author reach for the
|
|
15
|
+
* kill switch permanently. Two seconds is what the read may cost a command that runs
|
|
16
|
+
* in front of every other one.
|
|
17
|
+
*/
|
|
18
|
+
const DEFAULT_TIMEOUT_MS = 2e3;
|
|
19
|
+
const PUBLIC_REGISTRY = "https://registry.npmjs.org/";
|
|
20
|
+
/** npm prints this, literally, for a key that is not set. */
|
|
21
|
+
const NPM_UNSET = "undefined";
|
|
22
|
+
const VERSION_DIST_SCHEMA = z.object({ dist: z.object({
|
|
23
|
+
tarball: z.string(),
|
|
24
|
+
integrity: z.string().optional(),
|
|
25
|
+
shasum: z.string().optional()
|
|
26
|
+
}) });
|
|
27
|
+
const DIST_TAGS_SCHEMA = z.object({ latest: z.string().optional() });
|
|
28
|
+
/**
|
|
29
|
+
* `npm config get <keys…>`, as npm resolves them — every `.npmrc` layer, env vars and
|
|
30
|
+
* builtin defaults included. Hand-parsing those files would honour a different subset
|
|
31
|
+
* than the install this feature's recommendation is about.
|
|
32
|
+
*
|
|
33
|
+
* Reading config touches no network and no package cache.
|
|
34
|
+
*/
|
|
35
|
+
function npmConfigReader(cwd, env, timeoutMs) {
|
|
36
|
+
return async (keys) => {
|
|
37
|
+
const { stdout } = await execFileAsync("npm", [
|
|
38
|
+
"config",
|
|
39
|
+
"get",
|
|
40
|
+
...keys
|
|
41
|
+
], {
|
|
42
|
+
cwd,
|
|
43
|
+
env: { ...env },
|
|
44
|
+
encoding: "utf8",
|
|
45
|
+
timeout: timeoutMs,
|
|
46
|
+
shell: process.platform === "win32"
|
|
47
|
+
});
|
|
48
|
+
const only = keys.length === 1 ? keys[0] : void 0;
|
|
49
|
+
if (only !== void 0) return { [only]: stdout.trim() };
|
|
50
|
+
const values = {};
|
|
51
|
+
for (const line of stdout.split("\n")) {
|
|
52
|
+
const separator = line.indexOf("=");
|
|
53
|
+
if (separator === -1) continue;
|
|
54
|
+
values[line.slice(0, separator).trim()] = line.slice(separator + 1).trim();
|
|
55
|
+
}
|
|
56
|
+
return values;
|
|
57
|
+
};
|
|
58
|
+
}
|
|
59
|
+
function usable(value) {
|
|
60
|
+
return value === void 0 || value === "" || value === NPM_UNSET ? void 0 : value;
|
|
61
|
+
}
|
|
62
|
+
/** The scope's own registry wins over the default one, exactly as an install resolves it. */
|
|
63
|
+
async function registryBase(packageName, read) {
|
|
64
|
+
const slash = packageName.indexOf("/");
|
|
65
|
+
const scope = packageName.startsWith("@") && slash > 0 ? packageName.slice(0, slash) : void 0;
|
|
66
|
+
const keys = scope === void 0 ? ["registry"] : [`${scope}:registry`, "registry"];
|
|
67
|
+
let values;
|
|
68
|
+
try {
|
|
69
|
+
values = await read(keys);
|
|
70
|
+
} catch {
|
|
71
|
+
return PUBLIC_REGISTRY;
|
|
72
|
+
}
|
|
73
|
+
const base = usable(scope === void 0 ? void 0 : values[`${scope}:registry`]) ?? usable(values.registry) ?? PUBLIC_REGISTRY;
|
|
74
|
+
return base.endsWith("/") ? base : `${base}/`;
|
|
75
|
+
}
|
|
76
|
+
/** The escaping npm's own registry clients use: the scope separator, and only it. */
|
|
77
|
+
function packagePath(packageName) {
|
|
78
|
+
return packageName.replace("/", "%2f");
|
|
79
|
+
}
|
|
80
|
+
/**
|
|
81
|
+
* Everything a request needs, or `null` when the budget is already gone.
|
|
82
|
+
*
|
|
83
|
+
* By default ONE deadline across both steps, so a wedged `npm config get` cannot spend
|
|
84
|
+
* the budget and then let the request spend it again. With `configTimeoutMs` the config
|
|
85
|
+
* read is bounded by that instead and the request gets all of `timeoutMs`.
|
|
86
|
+
*
|
|
87
|
+
* Either way a config read that outlasts its deadline is unknown, never the public
|
|
88
|
+
* registry: npm killed mid-read is not npm answering "unset", and asking the public
|
|
89
|
+
* registry about a version only a mirror carries would answer `absent`.
|
|
90
|
+
*/
|
|
91
|
+
async function prepare(options) {
|
|
92
|
+
const packageName = options.packageName ?? CURRENCY_PACKAGE;
|
|
93
|
+
const timeoutMs = options.timeoutMs ?? 2e3;
|
|
94
|
+
const configTimeoutMs = options.configTimeoutMs ?? timeoutMs;
|
|
95
|
+
const env = options.env ?? process.env;
|
|
96
|
+
const doFetch = options.fetchImpl ?? fetch;
|
|
97
|
+
const read = options.readNpmConfig ?? npmConfigReader(options.cwd ?? process.cwd(), env, configTimeoutMs);
|
|
98
|
+
const startedAt = Date.now();
|
|
99
|
+
const base = await registryBase(packageName, read);
|
|
100
|
+
const spent = Date.now() - startedAt;
|
|
101
|
+
if (spent >= configTimeoutMs) return null;
|
|
102
|
+
const remaining = options.configTimeoutMs === void 0 ? timeoutMs - spent : timeoutMs;
|
|
103
|
+
return remaining <= 0 ? null : {
|
|
104
|
+
base,
|
|
105
|
+
remaining,
|
|
106
|
+
doFetch,
|
|
107
|
+
packageName
|
|
108
|
+
};
|
|
109
|
+
}
|
|
110
|
+
/**
|
|
111
|
+
* One GET inside what is left of the deadline. `null` is unreachable, aborted, or a
|
|
112
|
+
* transport that threw — never a status, which the caller reads for itself.
|
|
113
|
+
*
|
|
114
|
+
* A private mirror demanding credentials answers 401 rather than `null`: reading a
|
|
115
|
+
* token out of npm's config is a larger question than this feature answers, and every
|
|
116
|
+
* caller here treats a status it did not expect as unknown anyway.
|
|
117
|
+
*/
|
|
118
|
+
async function get(call, url) {
|
|
119
|
+
try {
|
|
120
|
+
return await call.doFetch(url, {
|
|
121
|
+
signal: AbortSignal.timeout(call.remaining),
|
|
122
|
+
headers: { accept: "application/json" }
|
|
123
|
+
});
|
|
124
|
+
} catch {
|
|
125
|
+
return null;
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
/**
|
|
129
|
+
* The `latest` dist-tag for the package, or `null` when it cannot be read.
|
|
130
|
+
*
|
|
131
|
+
* Never throws — a preamble that runs before every author command may not be able to
|
|
132
|
+
* fail one.
|
|
133
|
+
*/
|
|
134
|
+
async function resolveLatest(options = {}) {
|
|
135
|
+
const call = await prepare(options);
|
|
136
|
+
if (call === null) return null;
|
|
137
|
+
const response = await get(call, `${call.base}-/package/${packagePath(call.packageName)}/dist-tags`);
|
|
138
|
+
if (response === null || !response.ok) return null;
|
|
139
|
+
try {
|
|
140
|
+
const body = await response.json();
|
|
141
|
+
return DIST_TAGS_SCHEMA.parse(body).latest ?? null;
|
|
142
|
+
} catch {
|
|
143
|
+
return null;
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
/**
|
|
147
|
+
* Whether the registry carries an exact version.
|
|
148
|
+
*
|
|
149
|
+
* Three answers, not two, and the third is the point: `unknown` covers an unreachable
|
|
150
|
+
* registry, a timeout and any status that is neither the version document nor a plain
|
|
151
|
+
* 404. A caller must not read it as `absent` — refusing a version because the network
|
|
152
|
+
* was down would turn an offline moment into "that release does not exist".
|
|
153
|
+
*/
|
|
154
|
+
async function versionExists(version, options = {}) {
|
|
155
|
+
const call = await prepare(options);
|
|
156
|
+
if (call === null) return "unknown";
|
|
157
|
+
const response = await get(call, `${call.base}${packagePath(call.packageName)}/${encodeURIComponent(version)}`);
|
|
158
|
+
if (response === null) return "unknown";
|
|
159
|
+
if (response.ok) return "present";
|
|
160
|
+
return response.status === 404 ? "absent" : "unknown";
|
|
161
|
+
}
|
|
162
|
+
/**
|
|
163
|
+
* The `dist` block of one exact version's document, or `null` when it cannot be read.
|
|
164
|
+
* Never throws. A 404 is `null` too: the caller asks only about a version `resolveLatest`
|
|
165
|
+
* has just named, so there is no absent-versus-unknown decision to make here.
|
|
166
|
+
*/
|
|
167
|
+
async function readPublishedDist(version, options = {}) {
|
|
168
|
+
const call = await prepare(options);
|
|
169
|
+
if (call === null) return null;
|
|
170
|
+
const response = await get(call, `${call.base}${packagePath(call.packageName)}/${encodeURIComponent(version)}`);
|
|
171
|
+
if (response === null || !response.ok) return null;
|
|
172
|
+
try {
|
|
173
|
+
const { dist } = VERSION_DIST_SCHEMA.parse(await response.json());
|
|
174
|
+
return {
|
|
175
|
+
tarball: dist.tarball,
|
|
176
|
+
integrity: dist.integrity ?? null,
|
|
177
|
+
shasum: dist.shasum ?? null
|
|
178
|
+
};
|
|
179
|
+
} catch {
|
|
180
|
+
return null;
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
//#endregion
|
|
185
|
+
export { CURRENCY_PACKAGE, DEFAULT_TIMEOUT_MS, readPublishedDist, resolveLatest, versionExists };
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
//#region src/cli/currency/version-order.ts
|
|
2
|
+
const VERSION_PATTERN = /^(\d+)\.(\d+)\.(\d+)(?:-([0-9A-Za-z.-]+))?(?:\+[0-9A-Za-z.-]+)?$/;
|
|
3
|
+
/** `null` for anything this cannot read — the caller must treat that as unknown. */
|
|
4
|
+
function parseVersion(raw) {
|
|
5
|
+
const matched = VERSION_PATTERN.exec(raw.trim());
|
|
6
|
+
if (matched === null) return null;
|
|
7
|
+
return {
|
|
8
|
+
major: Number(matched[1]),
|
|
9
|
+
minor: Number(matched[2]),
|
|
10
|
+
patch: Number(matched[3]),
|
|
11
|
+
prerelease: matched[4] ?? ""
|
|
12
|
+
};
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* `-1`, `0` or `1`, ordering `a` against `b`.
|
|
16
|
+
*
|
|
17
|
+
* Prereleases are ordered exactly one step past the release triple: at equal triples a
|
|
18
|
+
* prerelease sorts BELOW the release, so `4.1.0-rc.1` is behind `4.1.0`. Two
|
|
19
|
+
* prereleases at the same triple compare EQUAL rather than being ranked against each
|
|
20
|
+
* other — the identifier precedence rules that would rank them are the fiddliest part
|
|
21
|
+
* of the spec, and the only input that could reach them is an author's own local build
|
|
22
|
+
* against a registry `latest`, which is never a prerelease. Ranking them by string
|
|
23
|
+
* comparison would order `rc.10` below `rc.9`, which is worse than declining to answer.
|
|
24
|
+
*/
|
|
25
|
+
function compareVersions(a, b) {
|
|
26
|
+
for (const part of [
|
|
27
|
+
"major",
|
|
28
|
+
"minor",
|
|
29
|
+
"patch"
|
|
30
|
+
]) if (a[part] !== b[part]) return a[part] < b[part] ? -1 : 1;
|
|
31
|
+
if (a.prerelease === b.prerelease) return 0;
|
|
32
|
+
if (a.prerelease === "") return 1;
|
|
33
|
+
if (b.prerelease === "") return -1;
|
|
34
|
+
return 0;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
//#endregion
|
|
38
|
+
export { compareVersions, parseVersion };
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { CROP_PARAM, croppedUrl, cutRegion as cutRegion$1, parseCropParam } from "../../packages/internal/image-ladder/dist/crop.js";
|
|
2
|
+
|
|
3
|
+
//#region src/cli/dev/crop.ts
|
|
4
|
+
/** A fixture media URL serving only `rect` of the image. */
|
|
5
|
+
function croppedMediaUrl(url, rect) {
|
|
6
|
+
return croppedUrl(url, rect);
|
|
7
|
+
}
|
|
8
|
+
async function defaultLoadSharp() {
|
|
9
|
+
try {
|
|
10
|
+
return (await import("sharp")).default;
|
|
11
|
+
} catch {
|
|
12
|
+
return null;
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
/** `rect` of an image's bytes, in its own format. Null when sharp is unavailable. */
|
|
16
|
+
async function cutRegion(master, rect, loadSharp = defaultLoadSharp) {
|
|
17
|
+
const sharp = await loadSharp();
|
|
18
|
+
return sharp === null ? null : cutRegion$1(sharp, master, rect);
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
//#endregion
|
|
22
|
+
export { CROP_PARAM, croppedMediaUrl, cutRegion, parseCropParam };
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
//#region src/cli/dev/hmr.ts
|
|
2
|
+
function createHmrBus() {
|
|
3
|
+
const clients = /* @__PURE__ */ new Set();
|
|
4
|
+
return {
|
|
5
|
+
attach(res) {
|
|
6
|
+
res.writeHead(200, {
|
|
7
|
+
"content-type": "text/event-stream",
|
|
8
|
+
"cache-control": "no-cache",
|
|
9
|
+
connection: "keep-alive"
|
|
10
|
+
});
|
|
11
|
+
res.write(": hello\n\n");
|
|
12
|
+
clients.add(res);
|
|
13
|
+
res.on("close", () => clients.delete(res));
|
|
14
|
+
},
|
|
15
|
+
broadcast(event) {
|
|
16
|
+
for (const res of clients) res.write(`event: ${event}\ndata: {}\n\n`);
|
|
17
|
+
},
|
|
18
|
+
closeAll() {
|
|
19
|
+
for (const res of clients) res.end();
|
|
20
|
+
clients.clear();
|
|
21
|
+
}
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
//#endregion
|
|
26
|
+
export { createHmrBus };
|