@decocms/blocks 8.10.0 → 8.11.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/dist/v8/cli/index.d.ts +1 -0
- package/dist/v8/cli/index.d.ts.map +1 -1
- package/dist/v8/cli/index.js +1 -0
- package/dist/v8/cli/index.js.map +1 -1
- package/dist/v8/cli/run.d.ts +2 -0
- package/dist/v8/cli/run.d.ts.map +1 -1
- package/dist/v8/cli/run.js +30 -1
- package/dist/v8/cli/run.js.map +1 -1
- package/dist/v8/cli/skills.d.ts +25 -0
- package/dist/v8/cli/skills.d.ts.map +1 -0
- package/dist/v8/cli/skills.js +70 -0
- package/dist/v8/cli/skills.js.map +1 -0
- package/package.json +3 -2
- package/skills/deco-apps/SKILL.md +82 -0
- package/skills/deco-apps/references/algolia.md +51 -0
- package/skills/deco-apps/references/commerce-types.md +132 -0
- package/skills/deco-apps/references/instrumented-fetch.md +144 -0
- package/skills/deco-apps/references/magento.md +55 -0
- package/skills/deco-apps/references/messaging.md +76 -0
- package/skills/deco-apps/references/shopify.md +69 -0
- package/skills/deco-apps/references/vendored-loaders.md +135 -0
- package/skills/deco-apps/references/vtex-cookies-auth.md +146 -0
- package/skills/deco-apps/references/vtex.md +150 -0
- package/skills/deco-apps/references/wake.md +75 -0
- package/skills/deco-cms-schema/SKILL.md +80 -0
- package/skills/deco-cms-schema/references/annotations.md +147 -0
- package/skills/deco-cms-schema/references/content-hygiene.md +91 -0
- package/skills/deco-cms-schema/references/formats-and-widgets.md +112 -0
- package/skills/deco-cms-schema/references/shapes-that-break-the-form.md +165 -0
- package/skills/deco-cms-schema/references/types-to-fields.md +112 -0
- package/skills/deco-go-live/SKILL.md +127 -0
- package/skills/deco-go-live/references/content-releases.md +90 -0
- package/skills/deco-go-live/references/process.md +106 -0
- package/skills/deco-go-live/references/proxy-headers-checkout.md +139 -0
- package/skills/deco-go-live/references/qa-checklist-template.md +150 -0
- package/skills/deco-go-live/references/qa-inventory.md +120 -0
- package/skills/deco-go-live/references/react-spa.md +183 -0
- package/skills/deco-go-live/references/seo-analytics.md +114 -0
- package/skills/deco-go-live/references/traffic-ramp.md +87 -0
- package/skills/deco-go-live/references/worker-runtime.md +93 -0
- package/skills/deco-go-live/scripts/preflight.sh +221 -0
- package/skills/deco-images-media/SKILL.md +64 -0
- package/skills/deco-images-media/references/asset-upload.md +191 -0
- package/skills/deco-images-media/references/components-per-binding.md +167 -0
- package/skills/deco-images-media/references/providers-and-cdn.md +145 -0
- package/skills/deco-images-media/references/quality-and-lcp.md +93 -0
- package/skills/deco-images-media/references/troubleshooting.md +147 -0
- package/skills/deco-images-media/references/video.md +122 -0
- package/skills/deco-make-editable/SKILL.md +94 -0
- package/skills/deco-make-editable/references/a11y-and-e2e.md +104 -0
- package/skills/deco-make-editable/references/content-shapes.md +198 -0
- package/skills/deco-make-editable/references/from-figma.md +110 -0
- package/skills/deco-make-editable/references/i18n-fields.md +112 -0
- package/skills/deco-make-editable/references/inventory.md +79 -0
- package/skills/deco-make-editable/references/pixel-parity.md +175 -0
- package/skills/deco-make-editable/references/seeding-content.md +119 -0
- package/skills/deco-nextjs-site/SKILL.md +74 -0
- package/skills/deco-nextjs-site/references/caching.md +116 -0
- package/skills/deco-nextjs-site/references/metadata-seo.md +100 -0
- package/skills/deco-nextjs-site/references/proxy-and-drafts.md +177 -0
- package/skills/deco-nextjs-site/references/rendering.md +171 -0
- package/skills/deco-nextjs-site/references/setup.md +190 -0
- package/skills/deco-nextjs-site/references/studio-bridge.md +130 -0
- package/skills/deco-site-authoring/SKILL.md +75 -0
- package/skills/deco-site-authoring/references/lazy-blocks.md +155 -0
- package/skills/deco-site-authoring/references/loaders.md +192 -0
- package/skills/deco-site-authoring/references/pages.md +156 -0
- package/skills/deco-site-authoring/references/review-before-publish.md +95 -0
- package/skills/deco-site-authoring/references/sections.md +158 -0
- package/skills/deco-site-authoring/references/seo.md +116 -0
- package/skills/deco-site-workflow/SKILL.md +92 -0
- package/skills/deco-site-workflow/references/check.md +116 -0
- package/skills/deco-site-workflow/references/cli-reference.md +104 -0
- package/skills/deco-site-workflow/references/content-layout.md +93 -0
- package/skills/deco-site-workflow/references/content-sync.md +146 -0
- package/skills/deco-site-workflow/references/delivery.md +51 -0
- package/skills/deco-site-workflow/references/deploy.md +87 -0
- package/skills/deco-site-workflow/references/schema.md +173 -0
- package/skills/deco-site-workflow/references/serve-and-studio.md +138 -0
- package/skills/deco-storefront-caching/SKILL.md +67 -0
- package/skills/deco-storefront-caching/references/cache-keys.md +129 -0
- package/skills/deco-storefront-caching/references/case-study.md +82 -0
- package/skills/deco-storefront-caching/references/egress-traps.md +153 -0
- package/skills/deco-storefront-caching/references/nextjs.md +60 -0
- package/skills/deco-storefront-caching/references/perf-guardrails-e2e.md +123 -0
- package/skills/deco-storefront-caching/references/verification.md +136 -0
- package/skills/deco-storefront-caching/references/worker-page-cache.md +160 -0
- package/skills/deco-storefront-caching/scripts/html-anatomy.mjs +97 -0
- package/skills/deco-storefront-performance/SKILL.md +81 -0
- package/skills/deco-storefront-performance/references/cls-third-party.md +90 -0
- package/skills/deco-storefront-performance/references/hydration.md +116 -0
- package/skills/deco-storefront-performance/references/loaders-n-plus-1.md +107 -0
- package/skills/deco-storefront-performance/references/navigation-ux.md +130 -0
- package/skills/deco-storefront-performance/references/payload-trim.md +163 -0
- package/skills/deco-storefront-performance/references/render-location.md +152 -0
- package/skills/deco-storefront-performance/references/request-dedupe.md +147 -0
- package/skills/deco-storefront-performance/references/trace-reading.md +79 -0
- package/skills/deco-storefront-performance/references/worker-memory.md +176 -0
- package/skills/deco-tanstack-site/SKILL.md +68 -0
- package/skills/deco-tanstack-site/references/document-and-security.md +155 -0
- package/skills/deco-tanstack-site/references/router-and-navigation.md +137 -0
- package/skills/deco-tanstack-site/references/routes-and-pages.md +183 -0
- package/skills/deco-tanstack-site/references/server-functions.md +123 -0
- package/skills/deco-tanstack-site/references/setup.md +153 -0
- package/skills/deco-tanstack-site/references/worker-entry.md +152 -0
- package/skills/deco-v7-to-v8-migration/SKILL.md +122 -0
- package/skills/deco-v7-to-v8-migration/references/caching-and-privacy.md +10 -0
- package/skills/deco-v7-to-v8-migration/references/content.md +25 -0
- package/skills/deco-v7-to-v8-migration/references/editor-forms.md +27 -0
- package/skills/deco-v7-to-v8-migration/references/faststore.md +40 -0
- package/skills/deco-v7-to-v8-migration/references/framework-code.md +53 -0
- package/skills/deco-v7-to-v8-migration/references/hosted-releases.md +16 -0
- package/skills/deco-v7-to-v8-migration/references/import-map.md +81 -0
- package/skills/deco-v7-to-v8-migration/references/legacy-names.md +33 -0
- package/skills/deco-v7-to-v8-migration/references/manual-steps.md +10 -0
- package/skills/deco-v7-to-v8-migration/references/native-apps.md +43 -0
- package/skills/deco-v7-to-v8-migration/references/nextjs.md +19 -0
- package/skills/deco-v7-to-v8-migration/references/parity.md +66 -0
- package/skills/deco-v7-to-v8-migration/references/rendering.md +13 -0
- package/skills/deco-v7-to-v8-migration/references/running-the-script.md +29 -0
- package/skills/deco-v7-to-v8-migration/references/script-steps.md +13 -0
- package/skills/deco-v7-to-v8-migration/references/server-functions.md +15 -0
- package/skills/deco-v7-to-v8-migration/references/sibling-port.md +11 -0
- package/skills/deco-v7-to-v8-migration/references/site-code.md +15 -0
- package/skills/deco-v7-to-v8-migration/references/telemetry.md +10 -0
- package/skills/deco-v7-to-v8-migration/references/verify.md +20 -0
- package/skills/deco-v7-to-v8-migration/scripts/apps.ts +297 -0
- package/skills/deco-v7-to-v8-migration/scripts/asyncRendering.ts +73 -0
- package/skills/deco-v7-to-v8-migration/scripts/blockMap.ts +584 -0
- package/skills/deco-v7-to-v8-migration/scripts/ciSchemaCheck.ts +145 -0
- package/skills/deco-v7-to-v8-migration/scripts/compat.ts +357 -0
- package/skills/deco-v7-to-v8-migration/scripts/content.ts +121 -0
- package/skills/deco-v7-to-v8-migration/scripts/experiments.ts +81 -0
- package/skills/deco-v7-to-v8-migration/scripts/framework.ts +61 -0
- package/skills/deco-v7-to-v8-migration/scripts/imageCopy.ts +276 -0
- package/skills/deco-v7-to-v8-migration/scripts/imageModule.ts +285 -0
- package/skills/deco-v7-to-v8-migration/scripts/imports.ts +942 -0
- package/skills/deco-v7-to-v8-migration/scripts/invoke.ts +624 -0
- package/skills/deco-v7-to-v8-migration/scripts/legacyNames.ts +45 -0
- package/skills/deco-v7-to-v8-migration/scripts/main.ts +59 -0
- package/skills/deco-v7-to-v8-migration/scripts/matchers.ts +41 -0
- package/skills/deco-v7-to-v8-migration/scripts/migrate.ts +176 -0
- package/skills/deco-v7-to-v8-migration/scripts/redirects.ts +455 -0
- package/skills/deco-v7-to-v8-migration/scripts/report.ts +50 -0
- package/skills/deco-v7-to-v8-migration/scripts/scaffold.ts +1119 -0
- package/skills/deco-v7-to-v8-migration/scripts/secrets.ts +35 -0
- package/skills/deco-v7-to-v8-migration/scripts/sectionLoaders.ts +216 -0
- package/skills/deco-v7-to-v8-migration/scripts/siteSettings.ts +261 -0
- package/skills/deco-v7-to-v8-migration/scripts/stubs.ts +388 -0
- package/skills/deco-v7-to-v8-migration/scripts/tsconfig.json +7 -0
- package/skills/deco-v7-to-v8-migration/scripts/vendor.ts +249 -0
- package/skills/deco-v7-to-v8-migration/scripts/vtexInvoke.ts +240 -0
- package/skills/deco-v7-to-v8-migration/scripts/walk.ts +30 -0
- package/skills/deco-variants/SKILL.md +57 -0
- package/skills/deco-variants/references/caching-variants.md +63 -0
- package/skills/deco-variants/references/custom-matchers.md +83 -0
- package/skills/deco-variants/references/draft-preview.md +59 -0
- package/skills/deco-variants/references/experiments-and-campaigns.md +104 -0
- package/skills/deco-variants/references/multivariate.md +85 -0
- package/skills/deco-variants/references/v7-matchers.md +71 -0
- package/src/v8/cli/index.ts +1 -0
- package/src/v8/cli/run.ts +35 -1
- package/src/v8/cli/skills.ts +91 -0
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
/** The migration's command line: `bun scripts/main.ts` (or `npx tsx scripts/main.ts`). */
|
|
2
|
+
import { parseArgs } from "node:util";
|
|
3
|
+
import { migrate } from "./migrate";
|
|
4
|
+
import { formatReport } from "./report";
|
|
5
|
+
import { VTEX_INVOKE_MODES, VtexInvokeChoiceNeeded, type VtexInvokeMode } from "./vtexInvoke";
|
|
6
|
+
|
|
7
|
+
const USAGE = `Usage: bun scripts/main.ts [--root <dir>] [--decofile <file>] [--vtex-invoke keep|v8]
|
|
8
|
+
|
|
9
|
+
Migrates a v7 Deco site to the next major, in place, and prints what is left
|
|
10
|
+
to do. Run it on a clean working tree (see /next/renames-and-migrations).
|
|
11
|
+
|
|
12
|
+
--root <dir> the app root, with the site's package.json (default: .)
|
|
13
|
+
--decofile <file> content to split into .deco/blocks when the site has none
|
|
14
|
+
(the JSON served at <site>/.decofile)
|
|
15
|
+
--vtex-invoke <mode> the VTEX invoke keys v7's VTEX app answered from its own
|
|
16
|
+
invoke map (invoke.vtex.actions.checkout.addItemsToCart);
|
|
17
|
+
needed only when the site calls them, and it has no default:
|
|
18
|
+
keep vendor v7's handler, so the call works as it did
|
|
19
|
+
v8 no v7 code: @decocms/apps-vtex's client where it has the
|
|
20
|
+
operation, else a stub that rejects and a report line`;
|
|
21
|
+
|
|
22
|
+
async function main(argv: string[]): Promise<number> {
|
|
23
|
+
const { values } = parseArgs({
|
|
24
|
+
args: argv,
|
|
25
|
+
options: {
|
|
26
|
+
root: { type: "string", default: "." },
|
|
27
|
+
decofile: { type: "string" },
|
|
28
|
+
"vtex-invoke": { type: "string" },
|
|
29
|
+
help: { type: "boolean", short: "h" },
|
|
30
|
+
},
|
|
31
|
+
});
|
|
32
|
+
if (values.help) {
|
|
33
|
+
console.log(USAGE);
|
|
34
|
+
return 0;
|
|
35
|
+
}
|
|
36
|
+
const vtexInvoke = values["vtex-invoke"];
|
|
37
|
+
if (vtexInvoke !== undefined && !VTEX_INVOKE_MODES.includes(vtexInvoke as VtexInvokeMode)) {
|
|
38
|
+
throw new Error(`--vtex-invoke takes keep or v8, not "${vtexInvoke}"`);
|
|
39
|
+
}
|
|
40
|
+
const report = await migrate({
|
|
41
|
+
root: values.root!,
|
|
42
|
+
decofile: values.decofile,
|
|
43
|
+
vtexInvoke: vtexInvoke as VtexInvokeMode | undefined,
|
|
44
|
+
});
|
|
45
|
+
console.log(formatReport(report));
|
|
46
|
+
return 0;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
main(process.argv.slice(2)).then(
|
|
50
|
+
(code) => {
|
|
51
|
+
process.exitCode = code;
|
|
52
|
+
},
|
|
53
|
+
(error) => {
|
|
54
|
+
console.error(error instanceof Error ? error.message : error);
|
|
55
|
+
// A choice the migration needs explains itself; the usage is for a wrong command line.
|
|
56
|
+
if (!(error instanceof VtexInvokeChoiceNeeded)) console.error(USAGE);
|
|
57
|
+
process.exitCode = 1;
|
|
58
|
+
},
|
|
59
|
+
);
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* v7's website matchers in the block map. `@decocms/compat-v7/matchers` has
|
|
3
|
+
* each one with v7's results, taking the request explicitly; the binding's
|
|
4
|
+
* compat subpath gives that request (`matcherContext()`, with one A/B
|
|
5
|
+
* decision list per request). The block map registers each matcher the
|
|
6
|
+
* content uses under its v7 name. v7's random matcher isn't one of them, so
|
|
7
|
+
* the binding is the only writer of the visitor's `deco_segment`: its tests
|
|
8
|
+
* move by hand into the saved block `experiments`, as do date windows into
|
|
9
|
+
* `campaigns` (the content step reports both, ./experiments.ts).
|
|
10
|
+
*/
|
|
11
|
+
import type { Framework } from "./framework";
|
|
12
|
+
|
|
13
|
+
/** The matchers @decocms/compat-v7/matchers ports, with their props type; `request: false` reads none. */
|
|
14
|
+
const MATCHERS: Record<string, { props: string; request: boolean }> = {
|
|
15
|
+
cookie: { props: "CookieProps", request: true },
|
|
16
|
+
device: { props: "DeviceProps", request: true },
|
|
17
|
+
environment: { props: "never", request: false },
|
|
18
|
+
host: { props: "HostProps", request: true },
|
|
19
|
+
location: { props: "LocationProps", request: true },
|
|
20
|
+
multi: { props: "MultiProps", request: false },
|
|
21
|
+
pathname: { props: "PathnameProps", request: true },
|
|
22
|
+
queryString: { props: "QueryStringProps", request: true },
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
/** The matcher a v7 type name (`website/matchers/device.ts`, with or without `.ts`) names, if ported. */
|
|
26
|
+
export function v7Matcher(type: string): string | undefined {
|
|
27
|
+
const name = /^website\/matchers\/([A-Za-z]+)(?:\.ts)?$/.exec(type)?.[1];
|
|
28
|
+
return name && Object.hasOwn(MATCHERS, name) ? name : undefined;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
/** The block map's function for one matcher. */
|
|
32
|
+
export function matcherEntry(matcher: string, framework: Framework): string {
|
|
33
|
+
const { props, request } = MATCHERS[matcher];
|
|
34
|
+
if (!request) return `(props: matchers.${props}) => matchers.${matcher}(props)`;
|
|
35
|
+
return framework === "tanstack"
|
|
36
|
+
? `(props: matchers.${props}) => matchers.${matcher}(props, matcherInput())`
|
|
37
|
+
: `async (props: matchers.${props}) => matchers.${matcher}(props, await matcherContext())`;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
export const V7_MATCHER_HINT =
|
|
41
|
+
"a v7 matcher: @decocms/compat-v7/matchers has v7's (device, cookie, host, pathname, queryString, location, multi), taking the request; the script registers them on a TanStack Start or Next.js site, through matcherContext() from @decocms/compat-v7/tanstack/server or /nextjs/server. Elsewhere register it under this name with the request your framework gives (/next/matchers-and-variants#matchers); v7's environment matcher read the process environment, which v8 never does: write one in the site that knows where it runs. A random matcher belongs in the saved block experiments (type split-traffic), under its saved-block name, read by the experiment rule ({ name }) (/next/matchers-and-variants#run-an-a-b-test)";
|
|
@@ -0,0 +1,176 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `migrate`: moves a v7 site to the next major in one pass (spec:
|
|
3
|
+
* renames-and-migrations › Migrating from v7). The steps, in order:
|
|
4
|
+
*
|
|
5
|
+
* 1. content: saved blocks in `.deco/blocks`, v7 generated files removed,
|
|
6
|
+
* v7 async-rendering wrappers (Lazy, Deferred) unwrapped to their sections,
|
|
7
|
+
* legacy type names outside the alias table renamed, v7's random
|
|
8
|
+
* matchers and date rules holding their own dates reported (moved by
|
|
9
|
+
* hand into the saved blocks `experiments` and `campaigns`), every v7
|
|
10
|
+
* redirect block folded into the `Redirects` block (type `redirects`);
|
|
11
|
+
* then site settings folded into the `CMS` block (`.deco/blocks/CMS.json`);
|
|
12
|
+
* 2. secrets: each v7 secret listed, to move to the deploy platform's
|
|
13
|
+
* secrets (content holds none);
|
|
14
|
+
* 3. block map: the site's v7 section-loader registration turned into an
|
|
15
|
+
* export, then `.deco/index.ts` with aliases under the v7 names (v7's
|
|
16
|
+
* matchers from `@decocms/compat-v7/matchers`, `loadSections` running the
|
|
17
|
+
* section loaders), after vendoring the app loaders and actions the
|
|
18
|
+
* content calls, and the view registry `src/views.ts`;
|
|
19
|
+
* 4. invoke: each `/deco/invoke` key the site calls → one server function
|
|
20
|
+
* (`src/server/invoke.functions.ts` or `invoke.actions.ts`), imported at
|
|
21
|
+
* each call site; `ctx.invoke`, app state and `useSection` → the stubs in
|
|
22
|
+
* `src/migration-stubs.ts`;
|
|
23
|
+
* 5. scaffold: `src/cms.ts`, the page loader and the catch-all route for the
|
|
24
|
+
* binding, replacing v7's page routes; on TanStack Start, a report line
|
|
25
|
+
* pointing at the example worker entry to copy, with what v7's
|
|
26
|
+
* `createDecoWorkerEntry` configured (the script writes no worker entry);
|
|
27
|
+
* 6. imports: the codemod over `src/` (v7 helpers to `@decocms/compat-v7`,
|
|
28
|
+
* `ctx.device` from the loader's request, `src/imageUrl.ts` on TanStack);
|
|
29
|
+
* 7. scripts: `deco schema && deco content` before dev and build, and
|
|
30
|
+
* `deco schema --check` in the site's CI after the install step.
|
|
31
|
+
*
|
|
32
|
+
* Before the block map, v7's app blocks (`deco-vtex`, …) become the client
|
|
33
|
+
* code that configures each platform's client (`src/clients/<app>.ts`).
|
|
34
|
+
*
|
|
35
|
+
* It changes files in place, so run it on a clean working tree and review the
|
|
36
|
+
* diff. What it can't do is returned in the report.
|
|
37
|
+
*/
|
|
38
|
+
import fs from "node:fs";
|
|
39
|
+
import path from "node:path";
|
|
40
|
+
import { writeAppClients } from "./apps";
|
|
41
|
+
import { unwrapAsyncRendering } from "./asyncRendering";
|
|
42
|
+
import { writeBlockMap } from "./blockMap";
|
|
43
|
+
import { addSchemaCheck } from "./ciSchemaCheck";
|
|
44
|
+
import { listSources, rewriteDeviceReads } from "./compat";
|
|
45
|
+
import { moveContent } from "./content";
|
|
46
|
+
import { reportTestsAndDates } from "./experiments";
|
|
47
|
+
import { siteFramework, V8_RANGE } from "./framework";
|
|
48
|
+
import { rewriteImports } from "./imports";
|
|
49
|
+
import { rewriteInvokes, vtexInvokeMapKeysUsed } from "./invoke";
|
|
50
|
+
import { renameLegacyTypes } from "./legacyNames";
|
|
51
|
+
import { foldRedirects } from "./redirects";
|
|
52
|
+
import { createReport, type Report } from "./report";
|
|
53
|
+
import { reportWorkerEntry, writeScaffold } from "./scaffold";
|
|
54
|
+
import { listSecrets } from "./secrets";
|
|
55
|
+
import { wireSectionLoaders } from "./sectionLoaders";
|
|
56
|
+
import { foldSiteSettings } from "./siteSettings";
|
|
57
|
+
import { rewriteLoaderContext, rewritePartialImports, writeStubs } from "./stubs";
|
|
58
|
+
import { VtexInvokeChoiceNeeded, type VtexInvokeMode } from "./vtexInvoke";
|
|
59
|
+
|
|
60
|
+
interface MigrateOptions {
|
|
61
|
+
/** The app root: the folder with the site's package.json. */
|
|
62
|
+
root: string;
|
|
63
|
+
/** A decofile to split into `.deco/blocks` when the site has none, relative to the root. */
|
|
64
|
+
decofile?: string;
|
|
65
|
+
/**
|
|
66
|
+
* What the VTEX invoke keys v7's VTEX app answered from its own invoke map
|
|
67
|
+
* become: `"keep"` vendors v7's handler, `"v8"` moves them to
|
|
68
|
+
* `@decocms/apps-vtex`'s client with no v7 code (./vtexInvoke.ts). No
|
|
69
|
+
* default: a site that calls such keys without a choice gets
|
|
70
|
+
* `VtexInvokeChoiceNeeded` before anything is written.
|
|
71
|
+
*/
|
|
72
|
+
vtexInvoke?: VtexInvokeMode;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
/** The scripts /next/cli#run-it-before-dev-and-build asks for. */
|
|
76
|
+
const SCRIPTS: Record<string, string> = {
|
|
77
|
+
predev: "deco schema && deco content",
|
|
78
|
+
prebuild: "deco schema && deco content && deco check",
|
|
79
|
+
};
|
|
80
|
+
|
|
81
|
+
function addScripts(root: string, report: Report): void {
|
|
82
|
+
const file = path.join(root, "package.json");
|
|
83
|
+
const manifest = JSON.parse(fs.readFileSync(file, "utf8"));
|
|
84
|
+
manifest.scripts ??= {};
|
|
85
|
+
const added: string[] = [];
|
|
86
|
+
for (const [name, command] of Object.entries(SCRIPTS)) {
|
|
87
|
+
const current = manifest.scripts[name];
|
|
88
|
+
if (current === undefined) {
|
|
89
|
+
manifest.scripts[name] = command;
|
|
90
|
+
added.push(name);
|
|
91
|
+
} else if (!current.includes(command)) {
|
|
92
|
+
report.manual.push({
|
|
93
|
+
step: "scripts",
|
|
94
|
+
subject: `package.json ${name}`,
|
|
95
|
+
message: `run ${command} in it (/next/cli#run-it-before-dev-and-build)`,
|
|
96
|
+
});
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
if (added.length > 0) {
|
|
100
|
+
fs.writeFileSync(file, `${JSON.stringify(manifest, null, 2)}\n`);
|
|
101
|
+
report.done.push({
|
|
102
|
+
step: "scripts",
|
|
103
|
+
subject: "package.json",
|
|
104
|
+
message: `added ${added.join(" and ")}`,
|
|
105
|
+
});
|
|
106
|
+
}
|
|
107
|
+
const framework = siteFramework(root);
|
|
108
|
+
const packages = [`@decocms/blocks ${V8_RANGE}`];
|
|
109
|
+
if (framework) {
|
|
110
|
+
packages.push(
|
|
111
|
+
`@decocms/${framework} ${V8_RANGE} (the v8 binding, released with blocks at one version)`,
|
|
112
|
+
);
|
|
113
|
+
}
|
|
114
|
+
const written = siteImports(root);
|
|
115
|
+
if (written.has("@decocms/compat-v7")) {
|
|
116
|
+
packages.push(`@decocms/compat-v7 ${V8_RANGE} (v7's helpers, released with them)`);
|
|
117
|
+
}
|
|
118
|
+
for (const client of ["@decocms/apps-vtex", "@decocms/apps-shopify"]) {
|
|
119
|
+
if (written.has(client)) packages.push(`${client} ${V8_RANGE}`);
|
|
120
|
+
}
|
|
121
|
+
report.manual.push({
|
|
122
|
+
step: "scripts",
|
|
123
|
+
subject: "package.json",
|
|
124
|
+
message: `depend on ${packages.join(", ")}; drop the v7 codegen from build, and @decocms/apps-commerce, @decocms/blocks-admin and @decocms/blocks-cli once nothing imports them`,
|
|
125
|
+
});
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
/** The `@decocms/*` packages the site's code and block map import after the migration. */
|
|
129
|
+
function siteImports(root: string): Set<string> {
|
|
130
|
+
const found = new Set<string>();
|
|
131
|
+
const files = [...listSources(path.join(root, "src")), path.join(root, ".deco", "index.ts")];
|
|
132
|
+
for (const file of files) {
|
|
133
|
+
if (!fs.existsSync(file)) continue;
|
|
134
|
+
for (const [, name] of fs.readFileSync(file, "utf8").matchAll(/["'](@decocms\/[^/"']+)/g)) {
|
|
135
|
+
found.add(name);
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
return found;
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
export async function migrate(options: MigrateOptions): Promise<Report> {
|
|
142
|
+
const root = path.resolve(options.root);
|
|
143
|
+
if (!fs.existsSync(path.join(root, "package.json"))) {
|
|
144
|
+
throw new Error(`no package.json in ${root}; pass the app root with --root`);
|
|
145
|
+
}
|
|
146
|
+
if (!options.vtexInvoke) {
|
|
147
|
+
const keys = vtexInvokeMapKeysUsed(root);
|
|
148
|
+
if (keys.length > 0) throw new VtexInvokeChoiceNeeded(keys);
|
|
149
|
+
}
|
|
150
|
+
const report = createReport();
|
|
151
|
+
moveContent(root, report, { decofile: options.decofile });
|
|
152
|
+
unwrapAsyncRendering(root, report);
|
|
153
|
+
renameLegacyTypes(root, report);
|
|
154
|
+
foldRedirects(root, report);
|
|
155
|
+
reportTestsAndDates(root, report);
|
|
156
|
+
const apps = writeAppClients(root, report);
|
|
157
|
+
foldSiteSettings(root, report);
|
|
158
|
+
listSecrets(root, report);
|
|
159
|
+
const wiring = wireSectionLoaders(root, report);
|
|
160
|
+
const { vendored } = writeBlockMap(root, report, wiring, apps);
|
|
161
|
+
const stubs = new Set([
|
|
162
|
+
...rewriteInvokes(root, report, vendored, { vtexInvoke: options.vtexInvoke }),
|
|
163
|
+
...rewriteLoaderContext(root, report),
|
|
164
|
+
...rewritePartialImports(root, report),
|
|
165
|
+
]);
|
|
166
|
+
writeStubs(root, stubs, report);
|
|
167
|
+
rewriteDeviceReads(root, report);
|
|
168
|
+
writeScaffold(root, report);
|
|
169
|
+
if (siteFramework(root) === "tanstack") {
|
|
170
|
+
reportWorkerEntry(root, report);
|
|
171
|
+
}
|
|
172
|
+
rewriteImports(root, report, vendored);
|
|
173
|
+
addScripts(root, report);
|
|
174
|
+
addSchemaCheck(root, report);
|
|
175
|
+
return report;
|
|
176
|
+
}
|