@bettercms-ai/convert 0.23.0 → 0.24.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 +6 -0
- package/dist/cli.js +75 -6
- package/dist/cli.js.map +1 -1
- package/dist/index.d.ts +18 -2
- package/dist/index.js +84 -5
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -955,7 +955,7 @@ declare function attrsFor(path: string, kind: string, props?: AttrBinding[], sco
|
|
|
955
955
|
declare function propsAttribute(props: AttrBinding[]): string;
|
|
956
956
|
|
|
957
957
|
/** Bumped whenever the emitted source changes. `isKnownHelper` upgrades anything older. */
|
|
958
|
-
declare const HELPER_VERSION =
|
|
958
|
+
declare const HELPER_VERSION = 12;
|
|
959
959
|
/** Where each dialect's helper lives. Null = this dialect reads nothing at build time. */
|
|
960
960
|
declare const HELPER_PATH: Record<Dialect, string | null>;
|
|
961
961
|
/** The directory the snapshots live in, at the repository root. */
|
|
@@ -981,6 +981,22 @@ declare function helperSource(dialect: Dialect): string;
|
|
|
981
981
|
* treats them the same way, because it cannot tell them apart and must not overwrite either.
|
|
982
982
|
*/
|
|
983
983
|
declare function isKnownHelper(content: string, dialect: Dialect): number | null;
|
|
984
|
+
/** One committed helper a build may replace: where it lives, what replaces it, and which bytes qualify. */
|
|
985
|
+
interface HelperUpgrade {
|
|
986
|
+
path: string;
|
|
987
|
+
source: string;
|
|
988
|
+
/** sha256 of every OLDER helper this package wrote at `path`. Anything else is left alone. */
|
|
989
|
+
digests: string[];
|
|
990
|
+
}
|
|
991
|
+
/**
|
|
992
|
+
* What a BetterCMS build swaps in for a helper this package wrote at an older version.
|
|
993
|
+
*
|
|
994
|
+
* The hosting builder applies these to its own throwaway checkout — never to the repository — so a
|
|
995
|
+
* site converted before the helper read published content at request time gets that reader on its
|
|
996
|
+
* next build, with no commit and no codemod run. The rule is `isKnownHelper`'s: only bytes this
|
|
997
|
+
* package produced are replaced, so an edited or foreign module at the same path is never touched.
|
|
998
|
+
*/
|
|
999
|
+
declare function helperUpgrades(): HelperUpgrade[];
|
|
984
1000
|
|
|
985
1001
|
/**
|
|
986
1002
|
* The submit runtime, LIFTED VERBATIM from `src/lib/sites/render-page.ts` `FORM_SCRIPT`.
|
|
@@ -1949,4 +1965,4 @@ declare function convertSources(briefIn: Brief, sources: SourceFile[], options?:
|
|
|
1949
1965
|
receipt: ConversionReceipt;
|
|
1950
1966
|
}>;
|
|
1951
1967
|
|
|
1952
|
-
export { ASTRO_LANE_PENDING, type AstNode, type AttrBinding, type Brief, type BriefForm, type BriefPage, type BriefPath, COMPONENT_DIR, CONTENT_DIR, type CanvasResult, type CanvasSource, type Carried, type ComponentizeOptions, type ComponentizePlan, type ComponentizePlanComponent, type ComponentizePlanField, type ComponentizePlanPage, type ComponentizePlanSection, type ComponentizeReceipt, type ConversionReceipt, ConvertError, type ConvertErrorCode, type ConvertOptions, DIALECT_RULES, type DataMember, type DataResult, type DeclaredPath, type Dialect, type DynamicBinding, FORM_SCRIPT, type FileDeclaration, type FindSitesResult, type FixAction, FormInvariantError, type FormPendingReason, type FormsReceipt, HELPER_PATH, HELPER_VERSION, type ImageResult, type ImageTarget, type ImportedFrom, type LlmFallback, type LocatedPath, type Node, PARSE_FILE, type ParsedFile, type ParserError, type PathLocator, type PendingFix, type PendingForm, type PendingPath, type PendingReason, type PendingSection, type PlanFile, REGISTRY_MARKER, type ReceiptFile, ReceiptInvariantError, type ReceiptNote, type Rewrite, SECTIONS_LIB, SECTION_MARKER, SKIP_DIRS, SKIP_FILES, SOURCE_EXTENSIONS, SSR_DRAFT_RECIPE, STUB_CONTENT, SectionInvariantError, type SectionPendingReason, type SectionUpgradeReceipt, type SectionsReceipt, type Site, type SiteWhere, type SkippedRoot, type SourceFile, type Splice, type TargetIdentity, type UnlocatedPath, UpgradeError, type UpgradeOptions, type UpgradeRootRef, type UpgradeSkipReason, type UpgradedRoot, type ValidationCode, ValidationError, type Xray, type XrayBucket, aliasesFrom, assertForms, assertReceipt, assertSections, assetCandidates, assetImport, attrsFor, bindDataLiterals, bindImages, briefDigest, canvasBridge, carryFor, componentizeSources, convertSources, convertedHere, coverageOf, declaringElements, dialectOf, exportedFunction, extendedConfigs, findLiteral, findSites, findSitesTolerant, fixFor, flat, helperSource, importsIn, isDecorativeGlyph, isDynamicRoute, isKnownHelper, isSourceCandidate, locate, measureUnaddressable, overlapping, pageFilesFor, parseFile, propsAttribute, readBrief, readComponentizePlan, readDeclarations, readExpr, readPlan, relativeImport, resolveSpecifier, rewriteFile, routeCounts, routeOfFile, stripTags, unreadableConfigs, upgradeSections, walkAst, wireForms };
|
|
1968
|
+
export { ASTRO_LANE_PENDING, type AstNode, type AttrBinding, type Brief, type BriefForm, type BriefPage, type BriefPath, COMPONENT_DIR, CONTENT_DIR, type CanvasResult, type CanvasSource, type Carried, type ComponentizeOptions, type ComponentizePlan, type ComponentizePlanComponent, type ComponentizePlanField, type ComponentizePlanPage, type ComponentizePlanSection, type ComponentizeReceipt, type ConversionReceipt, ConvertError, type ConvertErrorCode, type ConvertOptions, DIALECT_RULES, type DataMember, type DataResult, type DeclaredPath, type Dialect, type DynamicBinding, FORM_SCRIPT, type FileDeclaration, type FindSitesResult, type FixAction, FormInvariantError, type FormPendingReason, type FormsReceipt, HELPER_PATH, HELPER_VERSION, type HelperUpgrade, type ImageResult, type ImageTarget, type ImportedFrom, type LlmFallback, type LocatedPath, type Node, PARSE_FILE, type ParsedFile, type ParserError, type PathLocator, type PendingFix, type PendingForm, type PendingPath, type PendingReason, type PendingSection, type PlanFile, REGISTRY_MARKER, type ReceiptFile, ReceiptInvariantError, type ReceiptNote, type Rewrite, SECTIONS_LIB, SECTION_MARKER, SKIP_DIRS, SKIP_FILES, SOURCE_EXTENSIONS, SSR_DRAFT_RECIPE, STUB_CONTENT, SectionInvariantError, type SectionPendingReason, type SectionUpgradeReceipt, type SectionsReceipt, type Site, type SiteWhere, type SkippedRoot, type SourceFile, type Splice, type TargetIdentity, type UnlocatedPath, UpgradeError, type UpgradeOptions, type UpgradeRootRef, type UpgradeSkipReason, type UpgradedRoot, type ValidationCode, ValidationError, type Xray, type XrayBucket, aliasesFrom, assertForms, assertReceipt, assertSections, assetCandidates, assetImport, attrsFor, bindDataLiterals, bindImages, briefDigest, canvasBridge, carryFor, componentizeSources, convertSources, convertedHere, coverageOf, declaringElements, dialectOf, exportedFunction, extendedConfigs, findLiteral, findSites, findSitesTolerant, fixFor, flat, helperSource, helperUpgrades, importsIn, isDecorativeGlyph, isDynamicRoute, isKnownHelper, isSourceCandidate, locate, measureUnaddressable, overlapping, pageFilesFor, parseFile, propsAttribute, readBrief, readComponentizePlan, readDeclarations, readExpr, readPlan, relativeImport, resolveSpecifier, rewriteFile, routeCounts, routeOfFile, stripTags, unreadableConfigs, upgradeSections, walkAst, wireForms };
|
package/dist/index.js
CHANGED
|
@@ -4187,7 +4187,7 @@ async function bindImages(ctx, targets) {
|
|
|
4187
4187
|
|
|
4188
4188
|
// src/helper.ts
|
|
4189
4189
|
import { createHash as createHash2 } from "crypto";
|
|
4190
|
-
var HELPER_VERSION =
|
|
4190
|
+
var HELPER_VERSION = 12;
|
|
4191
4191
|
var HEADER = "// @bettercms-ai/convert helper v";
|
|
4192
4192
|
var HELPER_PATH = Object.fromEntries(
|
|
4193
4193
|
Object.keys(DIALECT_RULES).map((d) => [d, DIALECT_RULES[d].helper])
|
|
@@ -4244,8 +4244,69 @@ function render(value: unknown): string | undefined {
|
|
|
4244
4244
|
return undefined;
|
|
4245
4245
|
}
|
|
4246
4246
|
|
|
4247
|
+
/**
|
|
4248
|
+
* The PUBLISHED copy, on a server BetterCMS hosts \u2014 read at request time, not at build time.
|
|
4249
|
+
*
|
|
4250
|
+
* BetterCMS keeps one file current for a running server app (\`BCMS_CONTENT_FILE\`, the same
|
|
4251
|
+
* bcms-content.json the build was given) and rewrites it on every publish, so a server-rendered
|
|
4252
|
+
* page shows a publish within seconds instead of after a rebuild. Each snapshot this module reads
|
|
4253
|
+
* resolves to its live counterpart: the shared layout by identity, a page by its \`slug\`.
|
|
4254
|
+
*
|
|
4255
|
+
* Nowhere else does anything change: with no variable (a build, \`astro dev\`, a browser, an edge
|
|
4256
|
+
* runtime) every snapshot is the one the bundle imported, exactly as before. A file that cannot be
|
|
4257
|
+
* read keeps the last good copy; it is checked at most once a second.
|
|
4258
|
+
*/
|
|
4259
|
+
type BcmsLiveContent = { stamp: number; bySlug: Map<string, unknown>; layout: unknown };
|
|
4260
|
+
let bcmsLive: BcmsLiveContent | null = null;
|
|
4261
|
+
let bcmsLiveCheckedAt = 0;
|
|
4262
|
+
|
|
4263
|
+
function liveContent(): BcmsLiveContent | null {
|
|
4264
|
+
const proc = (globalThis as {
|
|
4265
|
+
process?: { env?: Record<string, string | undefined>; getBuiltinModule?: (id: string) => unknown };
|
|
4266
|
+
}).process;
|
|
4267
|
+
const file = proc?.env?.BCMS_CONTENT_FILE;
|
|
4268
|
+
if (!file || typeof proc?.getBuiltinModule !== "function") return null;
|
|
4269
|
+
const now = Date.now();
|
|
4270
|
+
if (now - bcmsLiveCheckedAt < 1000) return bcmsLive;
|
|
4271
|
+
bcmsLiveCheckedAt = now;
|
|
4272
|
+
try {
|
|
4273
|
+
const fs = proc.getBuiltinModule("node:fs") as {
|
|
4274
|
+
statSync(path: string): { mtimeMs: number };
|
|
4275
|
+
readFileSync(path: string, encoding: "utf8"): string;
|
|
4276
|
+
};
|
|
4277
|
+
const stamp = fs.statSync(file).mtimeMs;
|
|
4278
|
+
if (bcmsLive && bcmsLive.stamp === stamp) return bcmsLive;
|
|
4279
|
+
const snapshot: unknown = JSON.parse(fs.readFileSync(file, "utf8"));
|
|
4280
|
+
const bySlug = new Map<string, unknown>();
|
|
4281
|
+
const collections = isRecord(snapshot) && isRecord(snapshot.collections) ? snapshot.collections : {};
|
|
4282
|
+
for (const rows of Object.values(collections)) {
|
|
4283
|
+
if (!Array.isArray(rows)) continue;
|
|
4284
|
+
for (const row of rows) {
|
|
4285
|
+
if (isRecord(row) && typeof row.slug === "string" && !bySlug.has(row.slug)) bySlug.set(row.slug, row);
|
|
4286
|
+
}
|
|
4287
|
+
}
|
|
4288
|
+
const pages = isRecord(snapshot) && Array.isArray(snapshot.pages) ? snapshot.pages : [];
|
|
4289
|
+
const withLayout = pages.find((page: unknown) => isRecord(page) && isRecord(page.layout));
|
|
4290
|
+
const layout = isRecord(withLayout) ? withLayout.layout : isRecord(snapshot) ? snapshot.layout : undefined;
|
|
4291
|
+
bcmsLive = { stamp, bySlug, layout };
|
|
4292
|
+
} catch {
|
|
4293
|
+
// Unreadable, or caught mid-write: keep serving the last good copy.
|
|
4294
|
+
}
|
|
4295
|
+
return bcmsLive;
|
|
4296
|
+
}
|
|
4297
|
+
|
|
4298
|
+
/** The published counterpart of a snapshot this module was handed, or the snapshot itself. */
|
|
4299
|
+
function live(page: unknown): unknown {
|
|
4300
|
+
const content = liveContent();
|
|
4301
|
+
if (!content) return page;
|
|
4302
|
+
if (page === layoutSnapshot) return isRecord(content.layout) ? content.layout : page;
|
|
4303
|
+
if (isRecord(page) && typeof page.slug === "string") return content.bySlug.get(page.slug) ?? page;
|
|
4304
|
+
return page;
|
|
4305
|
+
}
|
|
4306
|
+
|
|
4247
4307
|
/** One field of one page. \`slug\` selects the entry on a dynamic route. */
|
|
4248
4308
|
export function bcms(page: unknown, path: string, fallback: string, slug?: string): string {
|
|
4309
|
+
page = live(page);
|
|
4249
4310
|
const entries = isRecord(page) ? page.entries : undefined;
|
|
4250
4311
|
const root = slug !== undefined && isRecord(entries) ? entries[slug] : page;
|
|
4251
4312
|
return render(readPath(root, path)) ?? fallback;
|
|
@@ -4253,7 +4314,7 @@ export function bcms(page: unknown, path: string, fallback: string, slug?: strin
|
|
|
4253
4314
|
|
|
4254
4315
|
/** One field of the shared layout \u2014 the header and footer every route renders. */
|
|
4255
4316
|
export function bcmsLayout(path: string, fallback: string): string {
|
|
4256
|
-
return render(readPath(layoutSnapshot, path)) ?? fallback;
|
|
4317
|
+
return render(readPath(live(layoutSnapshot), path)) ?? fallback;
|
|
4257
4318
|
}
|
|
4258
4319
|
|
|
4259
4320
|
/**
|
|
@@ -4261,6 +4322,7 @@ export function bcmsLayout(path: string, fallback: string): string {
|
|
|
4261
4322
|
* an empty snapshot still renders the same number of cards it always did.
|
|
4262
4323
|
*/
|
|
4263
4324
|
export function bcmsRows<T>(page: unknown, path: string, fallback: T[], slug?: string): T[] {
|
|
4325
|
+
page = live(page);
|
|
4264
4326
|
const entries = isRecord(page) ? page.entries : undefined;
|
|
4265
4327
|
const root = slug !== undefined && isRecord(entries) ? entries[slug] : page;
|
|
4266
4328
|
const value = readPath(root, path);
|
|
@@ -4306,6 +4368,7 @@ export function bcmsRowsAs<T>(
|
|
|
4306
4368
|
* this out loud rather than leaving an editor to discover it.
|
|
4307
4369
|
*/
|
|
4308
4370
|
export function bcmsList(page: unknown, paths: string[], fallback: string[], slug?: string): string[] {
|
|
4371
|
+
page = live(page);
|
|
4309
4372
|
const entries = isRecord(page) ? page.entries : undefined;
|
|
4310
4373
|
const root = slug !== undefined && isRecord(entries) ? entries[slug] : page;
|
|
4311
4374
|
return paths.map((path, index) => render(readPath(root, path)) ?? fallback[index] ?? "");
|
|
@@ -4330,6 +4393,7 @@ export function bcmsTuples(page: unknown, paths: string[][], fallback: string[][
|
|
|
4330
4393
|
* no such rule and takes the CMS url directly.
|
|
4331
4394
|
*/
|
|
4332
4395
|
export function bcmsImage<T>(page: unknown, path: string, fallback: T, slug?: string): T | string {
|
|
4396
|
+
page = live(page);
|
|
4333
4397
|
if (fallback !== null && typeof fallback === "object") return fallback;
|
|
4334
4398
|
const entries = isRecord(page) ? page.entries : undefined;
|
|
4335
4399
|
const root = slug !== undefined && isRecord(entries) ? entries[slug] : page;
|
|
@@ -4358,6 +4422,7 @@ export function bcmsSection(
|
|
|
4358
4422
|
overrides?: unknown,
|
|
4359
4423
|
bindPaths?: Record<string, string>,
|
|
4360
4424
|
): Record<string, unknown> {
|
|
4425
|
+
page = live(page);
|
|
4361
4426
|
const group = bind ? readPath(page, bind) : undefined;
|
|
4362
4427
|
const base: Record<string, unknown> = isRecord(group) ? { ...group } : {};
|
|
4363
4428
|
// A locale copy on its twin's component spells its fields its own way: each prop's copy is
|
|
@@ -4429,6 +4494,7 @@ export function bcmsSectionPaths(
|
|
|
4429
4494
|
map: BcmsPathMap,
|
|
4430
4495
|
bindPaths?: Record<string, string>,
|
|
4431
4496
|
): Record<string, unknown> {
|
|
4497
|
+
page = live(page);
|
|
4432
4498
|
const out: Record<string, unknown> = isRecord(page) ? { ...page } : {};
|
|
4433
4499
|
const own = isRecord(overrides) ? overrides : {};
|
|
4434
4500
|
const separator = prefix.slice(-1);
|
|
@@ -4662,7 +4728,8 @@ var HISTORICAL = {
|
|
|
4662
4728
|
7: "f22514ef48c50230985e605bea6cf9bf41756384a7dc80603e347baba9b65d93",
|
|
4663
4729
|
8: "484e72852d2b496e016a1f2a2b1a77bb993f8a163b290781522d6114b6519bb9",
|
|
4664
4730
|
9: "d6441db2ff4578c3c5d4b7d461f3374b89247ef6ba9e0d535791e840d803e4f3",
|
|
4665
|
-
10: "ffcb59862972b15a67c5951e9f3b94ce5b8b50345e6aac2bfa5789cfc3136910"
|
|
4731
|
+
10: "ffcb59862972b15a67c5951e9f3b94ce5b8b50345e6aac2bfa5789cfc3136910",
|
|
4732
|
+
11: "ceb2a932d4c2761a5045ff35032e0b45130a0b5034547ff37579c72c9ce3594e"
|
|
4666
4733
|
},
|
|
4667
4734
|
"src/lib/bcms-content.ts": {
|
|
4668
4735
|
1: "ae72ae14d706943d481c880d70da5789b4816ba1ba319a10fbc63ded4d0b42f2",
|
|
@@ -4674,7 +4741,8 @@ var HISTORICAL = {
|
|
|
4674
4741
|
7: "ed92fb88de953d9951abbe6a1edae1d048f4050eaf6fb607ac08167f94d8bcc7",
|
|
4675
4742
|
8: "1a6f669d76d42effe77f082436e9d21c0efa6fc499e919e3d116bc3a27a7f3d5",
|
|
4676
4743
|
9: "eee9fb1635ae7d6f8f33676a1f390600ca24a62ee992775252273c73a011c494",
|
|
4677
|
-
10: "35bb7c0e30f5c41fe68e52259ec4764de6de2734064fa0e1521f3338eef0a09e"
|
|
4744
|
+
10: "35bb7c0e30f5c41fe68e52259ec4764de6de2734064fa0e1521f3338eef0a09e",
|
|
4745
|
+
11: "818784f2088150d64d91b42eac944dc9503f104d32a0e7a18c753d2982a5adc0"
|
|
4678
4746
|
},
|
|
4679
4747
|
"composables/bcms-content.ts": {
|
|
4680
4748
|
1: "c272412532efed7db64b6cf313b2bed4291f9951430412289c8a588b7f565407",
|
|
@@ -4686,7 +4754,8 @@ var HISTORICAL = {
|
|
|
4686
4754
|
7: "f22514ef48c50230985e605bea6cf9bf41756384a7dc80603e347baba9b65d93",
|
|
4687
4755
|
8: "484e72852d2b496e016a1f2a2b1a77bb993f8a163b290781522d6114b6519bb9",
|
|
4688
4756
|
9: "d6441db2ff4578c3c5d4b7d461f3374b89247ef6ba9e0d535791e840d803e4f3",
|
|
4689
|
-
10: "ffcb59862972b15a67c5951e9f3b94ce5b8b50345e6aac2bfa5789cfc3136910"
|
|
4757
|
+
10: "ffcb59862972b15a67c5951e9f3b94ce5b8b50345e6aac2bfa5789cfc3136910",
|
|
4758
|
+
11: "ceb2a932d4c2761a5045ff35032e0b45130a0b5034547ff37579c72c9ce3594e"
|
|
4690
4759
|
}
|
|
4691
4760
|
};
|
|
4692
4761
|
var sha256 = (value) => createHash2("sha256").update(value, "utf8").digest("hex");
|
|
@@ -4700,6 +4769,15 @@ function isKnownHelper(content, dialect) {
|
|
|
4700
4769
|
}
|
|
4701
4770
|
return null;
|
|
4702
4771
|
}
|
|
4772
|
+
function helperUpgrades() {
|
|
4773
|
+
const out = /* @__PURE__ */ new Map();
|
|
4774
|
+
for (const dialect of Object.keys(HELPER_PATH)) {
|
|
4775
|
+
const path = HELPER_PATH[dialect];
|
|
4776
|
+
if (!path || out.has(path)) continue;
|
|
4777
|
+
out.set(path, { path, source: helperSource(dialect), digests: Object.values(HISTORICAL[path] ?? {}) });
|
|
4778
|
+
}
|
|
4779
|
+
return [...out.values()];
|
|
4780
|
+
}
|
|
4703
4781
|
|
|
4704
4782
|
// src/locate.ts
|
|
4705
4783
|
var flat = (value) => value.replace(/\s+/g, " ").trim();
|
|
@@ -10719,6 +10797,7 @@ export {
|
|
|
10719
10797
|
fixFor,
|
|
10720
10798
|
flat,
|
|
10721
10799
|
helperSource,
|
|
10800
|
+
helperUpgrades,
|
|
10722
10801
|
importsIn,
|
|
10723
10802
|
isDecorativeGlyph,
|
|
10724
10803
|
isDynamicRoute,
|