fimo 0.7.0-experimental.1 → 0.7.0-experimental.10
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/assets/content-templates/hooks-template.eta +27 -73
- package/assets/content-templates/types-template.eta +1 -4
- package/assets/skills/fimo/SKILL.md +2 -2
- package/assets/skills/fimo/references/content.md +42 -46
- package/assets/skills/fimo/references/locales.md +0 -8
- package/assets/skills/fimo/references/setup-react-router.md +2 -2
- package/assets/skills/fimo/references/ui.md +1 -1
- package/assets/skills/fimo-cli/references/content.md +14 -17
- package/assets/skills/fimo-cli/references/locales.md +0 -6
- package/assets/skills/fimo-migration/SKILL.md +22 -2
- package/assets/skills/fimo-migration/references/content.md +8 -0
- package/assets/skills/fimo-migration/references/manifest.md +35 -0
- package/assets/skills/fimo-migration/references/qa.md +24 -2
- package/assets/skills/fimo-migration/references/workflow.md +12 -1
- package/assets/skills/fimo-migration/references/wrap.md +617 -0
- package/assets/skills/fimo-studio/references/visual-editing.md +5 -3
- package/dist/build/vite/plugins/translations.d.ts +2 -8
- package/dist/build/vite/plugins/translations.d.ts.map +1 -1
- package/dist/build/vite/plugins/translations.js +3 -121
- package/dist/cli/bundle.json +1 -1
- package/dist/cli/index.js +20655 -12551
- package/dist/runtime/app/FimoProviders.d.ts +1 -11
- package/dist/runtime/app/FimoProviders.d.ts.map +1 -1
- package/dist/runtime/app/FimoProviders.js +2 -23
- package/dist/runtime/astro/index.d.ts +2 -0
- package/dist/runtime/astro/index.d.ts.map +1 -0
- package/dist/runtime/astro/index.js +3 -0
- package/dist/runtime/astro/server.d.ts +3 -0
- package/dist/runtime/astro/server.d.ts.map +1 -0
- package/dist/runtime/astro/server.js +6 -0
- package/dist/runtime/content/utils/retrieve-data-sources.d.ts +0 -1
- package/dist/runtime/content/utils/retrieve-data-sources.d.ts.map +1 -1
- package/dist/runtime/content/utils/retrieve-data-sources.js +4 -27
- package/dist/runtime/i18n/FimoLocaleContext.d.ts.map +1 -1
- package/dist/runtime/i18n/FimoLocaleContext.js +1 -0
- package/dist/runtime/next/FimoNextProviders.d.ts +24 -0
- package/dist/runtime/next/FimoNextProviders.d.ts.map +1 -0
- package/dist/runtime/next/FimoNextProviders.js +20 -0
- package/dist/runtime/next/FimoNextScripts.d.ts +10 -0
- package/dist/runtime/next/FimoNextScripts.d.ts.map +1 -0
- package/dist/runtime/next/FimoNextScripts.js +19 -0
- package/dist/runtime/next/index.d.ts +14 -0
- package/dist/runtime/next/index.d.ts.map +1 -0
- package/dist/runtime/next/index.js +14 -0
- package/dist/runtime/next/server.d.ts +2 -0
- package/dist/runtime/next/server.d.ts.map +1 -0
- package/dist/runtime/next/server.js +4 -0
- package/dist/runtime/nuxt/composables.d.ts +9 -0
- package/dist/runtime/nuxt/composables.d.ts.map +1 -0
- package/dist/runtime/nuxt/composables.js +57 -0
- package/dist/runtime/nuxt/index.d.ts +3 -0
- package/dist/runtime/nuxt/index.d.ts.map +1 -0
- package/dist/runtime/nuxt/index.js +6 -0
- package/dist/runtime/nuxt/server.d.ts +3 -0
- package/dist/runtime/nuxt/server.d.ts.map +1 -0
- package/dist/runtime/nuxt/server.js +6 -0
- package/dist/runtime/paths/get-fimo-paths.d.ts.map +1 -1
- package/dist/runtime/paths/get-fimo-paths.js +5 -15
- package/dist/runtime/primitives/labels-hook.d.ts +33 -0
- package/dist/runtime/primitives/labels-hook.d.ts.map +1 -0
- package/dist/runtime/primitives/labels-hook.js +41 -0
- package/dist/runtime/primitives/labels-store.d.ts +12 -0
- package/dist/runtime/primitives/labels-store.d.ts.map +1 -0
- package/dist/runtime/primitives/labels-store.js +60 -0
- package/dist/runtime/primitives/labels-store.test.d.ts +2 -0
- package/dist/runtime/primitives/labels-store.test.d.ts.map +1 -0
- package/dist/runtime/primitives/labels-store.test.js +66 -0
- package/dist/runtime/primitives/lib/primitives.d.ts +2 -2
- package/dist/runtime/primitives/lib/primitives.d.ts.map +1 -1
- package/dist/runtime/primitives/lib/query.d.ts +3 -5
- package/dist/runtime/primitives/lib/query.d.ts.map +1 -1
- package/dist/runtime/primitives/lib/useFimoLiveValue.d.ts +5 -3
- package/dist/runtime/primitives/lib/useFimoLiveValue.d.ts.map +1 -1
- package/dist/runtime/primitives/lib/useFimoLiveValue.js +11 -4
- package/dist/runtime/primitives/public-surface.test.js +5 -9
- package/dist/runtime/primitives/translations.d.ts +1 -27
- package/dist/runtime/primitives/translations.d.ts.map +1 -1
- package/dist/runtime/primitives/translations.js +7 -85
- package/dist/runtime/react/FimoSpaProviders.d.ts +36 -0
- package/dist/runtime/react/FimoSpaProviders.d.ts.map +1 -0
- package/dist/runtime/react/FimoSpaProviders.js +63 -0
- package/dist/runtime/react/index.d.ts +33 -0
- package/dist/runtime/react/index.d.ts.map +1 -0
- package/dist/runtime/react/index.js +39 -0
- package/dist/runtime/remix/FimoRemixProviders.d.ts +16 -0
- package/dist/runtime/remix/FimoRemixProviders.d.ts.map +1 -0
- package/dist/runtime/remix/FimoRemixProviders.js +12 -0
- package/dist/runtime/remix/FimoRemixScripts.d.ts +10 -0
- package/dist/runtime/remix/FimoRemixScripts.d.ts.map +1 -0
- package/dist/runtime/remix/FimoRemixScripts.js +19 -0
- package/dist/runtime/remix/index.d.ts +12 -0
- package/dist/runtime/remix/index.d.ts.map +1 -0
- package/dist/runtime/remix/index.js +11 -0
- package/dist/runtime/remix/server.d.ts +2 -0
- package/dist/runtime/remix/server.d.ts.map +1 -0
- package/dist/runtime/remix/server.js +2 -0
- package/dist/runtime/seo/buildSeoForPath.d.ts +3 -1
- package/dist/runtime/seo/buildSeoForPath.d.ts.map +1 -1
- package/dist/runtime/seo/buildSeoForPath.js +1 -4
- package/dist/runtime/shared/display-routes.d.ts +14 -0
- package/dist/runtime/shared/display-routes.d.ts.map +1 -0
- package/dist/runtime/shared/display-routes.js +25 -0
- package/dist/runtime/shared/fimo-config.server.d.ts.map +1 -1
- package/dist/runtime/shared/fimo-config.server.js +1 -0
- package/dist/runtime/shared/fimo-config.types.d.ts +2 -0
- package/dist/runtime/shared/fimo-config.types.d.ts.map +1 -1
- package/dist/runtime/shared/i18n-messages.d.ts +29 -0
- package/dist/runtime/shared/i18n-messages.d.ts.map +1 -0
- package/dist/runtime/shared/i18n-messages.js +79 -0
- package/dist/runtime/shared/i18n-messages.test.d.ts +2 -0
- package/dist/runtime/shared/i18n-messages.test.d.ts.map +1 -0
- package/dist/runtime/shared/i18n-messages.test.js +39 -0
- package/dist/runtime/shared/labels-fetch.pure.d.ts +17 -0
- package/dist/runtime/shared/labels-fetch.pure.d.ts.map +1 -0
- package/dist/runtime/shared/labels-fetch.pure.js +71 -0
- package/dist/runtime/shared/labels-fetch.server.d.ts +7 -0
- package/dist/runtime/shared/labels-fetch.server.d.ts.map +1 -0
- package/dist/runtime/shared/labels-fetch.server.js +97 -0
- package/dist/runtime/shared/labels-t.pure.d.ts +2 -0
- package/dist/runtime/shared/labels-t.pure.d.ts.map +1 -0
- package/dist/runtime/shared/labels-t.pure.js +10 -0
- package/dist/runtime/strapi/client.d.ts +26 -0
- package/dist/runtime/strapi/client.d.ts.map +1 -0
- package/dist/runtime/strapi/client.js +88 -0
- package/dist/runtime/strapi/client.test.d.ts +2 -0
- package/dist/runtime/strapi/client.test.d.ts.map +1 -0
- package/dist/runtime/strapi/client.test.js +64 -0
- package/dist/runtime/strapi/index.d.ts +5 -0
- package/dist/runtime/strapi/index.d.ts.map +1 -0
- package/dist/runtime/strapi/index.js +6 -0
- package/dist/runtime/strapi/reshape.d.ts +28 -0
- package/dist/runtime/strapi/reshape.d.ts.map +1 -0
- package/dist/runtime/strapi/reshape.js +79 -0
- package/dist/runtime/strapi/reshape.test.d.ts +2 -0
- package/dist/runtime/strapi/reshape.test.d.ts.map +1 -0
- package/dist/runtime/strapi/reshape.test.js +33 -0
- package/dist/runtime/svelte/index.d.ts +3 -0
- package/dist/runtime/svelte/index.d.ts.map +1 -0
- package/dist/runtime/svelte/index.js +7 -0
- package/dist/runtime/svelte/server.d.ts +3 -0
- package/dist/runtime/svelte/server.d.ts.map +1 -0
- package/dist/runtime/svelte/server.js +6 -0
- package/dist/runtime/vue/index.d.ts +3 -0
- package/dist/runtime/vue/index.d.ts.map +1 -0
- package/dist/runtime/vue/index.js +5 -0
- package/dist/runtime/vue/server.d.ts +3 -0
- package/dist/runtime/vue/server.d.ts.map +1 -0
- package/dist/runtime/vue/server.js +6 -0
- package/dist/runtime/wrapped/FimoFileLink.d.ts +17 -0
- package/dist/runtime/wrapped/FimoFileLink.d.ts.map +1 -0
- package/dist/runtime/wrapped/FimoFileLink.js +19 -0
- package/dist/runtime/wrapped/FimoMediaImage.d.ts +14 -0
- package/dist/runtime/wrapped/FimoMediaImage.d.ts.map +1 -0
- package/dist/runtime/wrapped/FimoMediaImage.js +20 -0
- package/dist/runtime/wrapped/FimoMediaVideo.d.ts +14 -0
- package/dist/runtime/wrapped/FimoMediaVideo.d.ts.map +1 -0
- package/dist/runtime/wrapped/FimoMediaVideo.js +20 -0
- package/dist/runtime/wrapped/FimoRichTextBlock.d.ts +23 -0
- package/dist/runtime/wrapped/FimoRichTextBlock.d.ts.map +1 -0
- package/dist/runtime/wrapped/FimoRichTextBlock.js +22 -0
- package/dist/runtime/wrapped/FimoText.d.ts +22 -0
- package/dist/runtime/wrapped/FimoText.d.ts.map +1 -0
- package/dist/runtime/wrapped/FimoText.js +20 -0
- package/dist/runtime/wrapped/WrappedContentContext.d.ts +28 -0
- package/dist/runtime/wrapped/WrappedContentContext.d.ts.map +1 -0
- package/dist/runtime/wrapped/WrappedContentContext.js +30 -0
- package/dist/runtime/wrapped/WrappedProviders.d.ts +33 -0
- package/dist/runtime/wrapped/WrappedProviders.d.ts.map +1 -0
- package/dist/runtime/wrapped/WrappedProviders.js +101 -0
- package/dist/runtime/wrapped/dom.d.ts +4 -0
- package/dist/runtime/wrapped/dom.d.ts.map +1 -0
- package/dist/runtime/wrapped/dom.js +23 -0
- package/dist/runtime/wrapped/dom.test.d.ts +2 -0
- package/dist/runtime/wrapped/dom.test.d.ts.map +1 -0
- package/dist/runtime/wrapped/dom.test.js +16 -0
- package/dist/runtime/wrapped/server.d.ts +77 -0
- package/dist/runtime/wrapped/server.d.ts.map +1 -0
- package/dist/runtime/wrapped/server.js +237 -0
- package/dist/runtime/wrapped/server.test.d.ts +2 -0
- package/dist/runtime/wrapped/server.test.d.ts.map +1 -0
- package/dist/runtime/wrapped/server.test.js +91 -0
- package/dist/scripts/apply-wrap-templates.d.ts +61 -0
- package/dist/scripts/apply-wrap-templates.js +132 -0
- package/dist/scripts/apply-wrap-templates.test.d.ts +1 -0
- package/dist/scripts/apply-wrap-templates.test.js +199 -0
- package/dist/scripts/apply-wrap.d.ts +46 -0
- package/dist/scripts/apply-wrap.js +278 -0
- package/dist/scripts/apply-wrap.test.d.ts +1 -0
- package/dist/scripts/apply-wrap.test.js +226 -0
- package/dist/scripts/cms/discover.d.ts +2 -0
- package/dist/scripts/cms/discover.js +17 -0
- package/dist/scripts/cms/example-content.d.ts +32 -0
- package/dist/scripts/cms/example-content.js +108 -0
- package/dist/scripts/cms/example-content.test.d.ts +1 -0
- package/dist/scripts/cms/example-content.test.js +66 -0
- package/dist/scripts/cms/strapi/detect.d.ts +2 -0
- package/dist/scripts/cms/strapi/detect.js +186 -0
- package/dist/scripts/cms/strapi/detect.test.d.ts +1 -0
- package/dist/scripts/cms/strapi/detect.test.js +56 -0
- package/dist/scripts/cms/strapi/index.d.ts +3 -0
- package/dist/scripts/cms/strapi/index.js +25 -0
- package/dist/scripts/cms/strapi/list-source.d.ts +17 -0
- package/dist/scripts/cms/strapi/list-source.js +90 -0
- package/dist/scripts/cms/strapi/list-source.test.d.ts +1 -0
- package/dist/scripts/cms/strapi/list-source.test.js +33 -0
- package/dist/scripts/cms/strapi/schema-map.d.ts +9 -0
- package/dist/scripts/cms/strapi/schema-map.js +149 -0
- package/dist/scripts/cms/strapi/schema-map.test.d.ts +1 -0
- package/dist/scripts/cms/strapi/schema-map.test.js +91 -0
- package/dist/scripts/cms/strapi/touchpoints.d.ts +31 -0
- package/dist/scripts/cms/strapi/touchpoints.js +145 -0
- package/dist/scripts/cms/strapi/touchpoints.test.d.ts +1 -0
- package/dist/scripts/cms/strapi/touchpoints.test.js +62 -0
- package/dist/scripts/cms/strapi/wire-client.d.ts +15 -0
- package/dist/scripts/cms/strapi/wire-client.js +107 -0
- package/dist/scripts/cms/strapi/wire-client.test.d.ts +1 -0
- package/dist/scripts/cms/strapi/wire-client.test.js +51 -0
- package/dist/scripts/cms/strapi/wiring.d.ts +17 -0
- package/dist/scripts/cms/strapi/wiring.js +36 -0
- package/dist/scripts/cms/strapi/wiring.test.d.ts +1 -0
- package/dist/scripts/cms/strapi/wiring.test.js +27 -0
- package/dist/scripts/cms/types.d.ts +117 -0
- package/dist/scripts/cms/types.js +11 -0
- package/dist/scripts/detect-framework.d.ts +39 -0
- package/dist/scripts/detect-framework.js +133 -0
- package/dist/scripts/detect-framework.test.d.ts +1 -0
- package/dist/scripts/detect-framework.test.js +122 -0
- package/dist/scripts/draft-rows.d.ts +19 -0
- package/dist/scripts/draft-rows.js +135 -0
- package/dist/scripts/draft-rows.test.d.ts +1 -0
- package/dist/scripts/draft-rows.test.js +113 -0
- package/dist/scripts/draft-schemas.d.ts +27 -0
- package/dist/scripts/draft-schemas.js +188 -0
- package/dist/scripts/draft-schemas.test.d.ts +1 -0
- package/dist/scripts/draft-schemas.test.js +152 -0
- package/dist/scripts/extract-translations.js +16 -11
- package/dist/scripts/extract-translations.test.d.ts +1 -0
- package/dist/scripts/extract-translations.test.js +66 -0
- package/dist/scripts/frameworks/astro/routes.d.ts +3 -0
- package/dist/scripts/frameworks/astro/routes.js +55 -0
- package/dist/scripts/frameworks/astro/template-style.d.ts +7 -0
- package/dist/scripts/frameworks/astro/template-style.js +19 -0
- package/dist/scripts/frameworks/discover.d.ts +70 -0
- package/dist/scripts/frameworks/discover.js +178 -0
- package/dist/scripts/frameworks/next/rewire.d.ts +30 -0
- package/dist/scripts/frameworks/next/rewire.js +258 -0
- package/dist/scripts/frameworks/next/rewire.test.d.ts +1 -0
- package/dist/scripts/frameworks/next/rewire.test.js +134 -0
- package/dist/scripts/frameworks/next/routes.d.ts +17 -0
- package/dist/scripts/frameworks/next/routes.js +134 -0
- package/dist/scripts/frameworks/next/routes.test.d.ts +1 -0
- package/dist/scripts/frameworks/next/routes.test.js +64 -0
- package/dist/scripts/frameworks/next/wiring.d.ts +33 -0
- package/dist/scripts/frameworks/next/wiring.js +186 -0
- package/dist/scripts/frameworks/next/wiring.test.d.ts +1 -0
- package/dist/scripts/frameworks/next/wiring.test.js +174 -0
- package/dist/scripts/frameworks/nuxt/routes.d.ts +3 -0
- package/dist/scripts/frameworks/nuxt/routes.js +54 -0
- package/dist/scripts/frameworks/nuxt/template-style.d.ts +9 -0
- package/dist/scripts/frameworks/nuxt/template-style.js +27 -0
- package/dist/scripts/frameworks/remix/routes.d.ts +3 -0
- package/dist/scripts/frameworks/remix/routes.js +50 -0
- package/dist/scripts/frameworks/support.d.ts +75 -0
- package/dist/scripts/frameworks/support.js +165 -0
- package/dist/scripts/frameworks/support.test.d.ts +1 -0
- package/dist/scripts/frameworks/support.test.js +87 -0
- package/dist/scripts/frameworks/sveltekit/routes.d.ts +3 -0
- package/dist/scripts/frameworks/sveltekit/routes.js +50 -0
- package/dist/scripts/frameworks/sveltekit/template-style.d.ts +9 -0
- package/dist/scripts/frameworks/sveltekit/template-style.js +54 -0
- package/dist/scripts/frameworks/vite/routes.d.ts +15 -0
- package/dist/scripts/frameworks/vite/routes.js +93 -0
- package/dist/scripts/frameworks/vite/routes.test.d.ts +1 -0
- package/dist/scripts/frameworks/vite/routes.test.js +73 -0
- package/dist/scripts/frameworks/vite/wiring.d.ts +10 -0
- package/dist/scripts/frameworks/vite/wiring.js +99 -0
- package/dist/scripts/frameworks/vite/wiring.test.d.ts +1 -0
- package/dist/scripts/frameworks/vite/wiring.test.js +88 -0
- package/dist/scripts/generated-types.test.js +1 -1
- package/dist/scripts/i18n-namespace.d.ts +25 -0
- package/dist/scripts/i18n-namespace.js +53 -0
- package/dist/scripts/lib/validation-report.d.ts +1 -0
- package/dist/scripts/lib/validation-report.js +3 -0
- package/dist/scripts/render-parity/capture.d.ts +56 -0
- package/dist/scripts/render-parity/capture.js +366 -0
- package/dist/scripts/render-parity/capture.test.d.ts +1 -0
- package/dist/scripts/render-parity/capture.test.js +306 -0
- package/dist/scripts/render-parity/compare.d.ts +59 -0
- package/dist/scripts/render-parity/compare.js +0 -0
- package/dist/scripts/render-parity/compare.test.d.ts +1 -0
- package/dist/scripts/render-parity/compare.test.js +98 -0
- package/dist/scripts/render-parity/normalize-html.d.ts +13 -0
- package/dist/scripts/render-parity/normalize-html.js +223 -0
- package/dist/scripts/render-parity/normalize-html.test.d.ts +1 -0
- package/dist/scripts/render-parity/normalize-html.test.js +58 -0
- package/dist/scripts/render-parity/types.d.ts +41 -0
- package/dist/scripts/render-parity/types.js +1 -0
- package/dist/scripts/resolve-routes.js +1 -1
- package/dist/scripts/scan-wrappable.d.ts +196 -0
- package/dist/scripts/scan-wrappable.js +1227 -0
- package/dist/scripts/scan-wrappable.test.d.ts +1 -0
- package/dist/scripts/scan-wrappable.test.js +521 -0
- package/dist/scripts/sync-schemas.test.js +4 -24
- package/dist/scripts/validate-route-metadata.js +11 -0
- package/dist/scripts/validate-schemas.test.js +2 -2
- package/package.json +92 -5
- package/templates/react-router/package.json +7 -10
- package/dist/runtime/paths/get-fimo-paths.test.d.ts +0 -2
- package/dist/runtime/paths/get-fimo-paths.test.d.ts.map +0 -1
- package/dist/runtime/paths/get-fimo-paths.test.js +0 -69
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
import { mkdirSync, mkdtempSync, readFileSync, rmSync, writeFileSync } from 'node:fs';
|
|
2
|
+
import { tmpdir } from 'node:os';
|
|
3
|
+
import { join } from 'node:path';
|
|
4
|
+
import { afterEach, describe, expect, it } from 'vitest';
|
|
5
|
+
import { writeSchemaDrafts } from '../../draft-schemas.js';
|
|
6
|
+
import { scanWrappable } from '../../scan-wrappable.js';
|
|
7
|
+
import { rewireNextCollectionPages } from './rewire.js';
|
|
8
|
+
let dir;
|
|
9
|
+
const project = (files) => {
|
|
10
|
+
dir = mkdtempSync(join(tmpdir(), 'next-rewire-'));
|
|
11
|
+
for (const [rel, content] of Object.entries(files)) {
|
|
12
|
+
const full = join(dir, rel);
|
|
13
|
+
mkdirSync(join(full, '..'), { recursive: true });
|
|
14
|
+
writeFileSync(full, content);
|
|
15
|
+
}
|
|
16
|
+
return dir;
|
|
17
|
+
};
|
|
18
|
+
afterEach(() => {
|
|
19
|
+
if (dir) {
|
|
20
|
+
rmSync(dir, { recursive: true, force: true });
|
|
21
|
+
}
|
|
22
|
+
});
|
|
23
|
+
const run = (root) => {
|
|
24
|
+
const scan = scanWrappable(root, { keepInternal: true });
|
|
25
|
+
const drafts = writeSchemaDrafts(root, scan);
|
|
26
|
+
return rewireNextCollectionPages(root, { appDir: 'app' }, scan, drafts);
|
|
27
|
+
};
|
|
28
|
+
const DATA_PAGE = `import posts from '../../src/data/posts.json';
|
|
29
|
+
|
|
30
|
+
export default function PostsPage() {
|
|
31
|
+
return (
|
|
32
|
+
<main>
|
|
33
|
+
<h1>Posts</h1>
|
|
34
|
+
<ul>
|
|
35
|
+
{posts.slice(0, 24).map((item: any, idx: number) => (
|
|
36
|
+
<li key={idx}><span>{item.title}</span> <span>{item.excerpt}</span></li>
|
|
37
|
+
))}
|
|
38
|
+
</ul>
|
|
39
|
+
</main>
|
|
40
|
+
);
|
|
41
|
+
}
|
|
42
|
+
`;
|
|
43
|
+
const POSTS_JSON = JSON.stringify([
|
|
44
|
+
{ slug: 'post-1', title: 'Charting the bay', excerpt: 'First excerpt of the harbor.' },
|
|
45
|
+
{ slug: 'post-2', title: 'Berth songs', excerpt: 'Second excerpt of the crew.' },
|
|
46
|
+
{ slug: 'post-3', title: 'Lantern census', excerpt: 'Third excerpt of the reef.' },
|
|
47
|
+
]);
|
|
48
|
+
const INCODE_PAGE = `const clients = [
|
|
49
|
+
{ "name": "Quay anchor Co", "slug": "client-0", "since": "2018-03-20" },
|
|
50
|
+
{ "name": "Gull harbor Co", "slug": "client-1", "since": "2015-08-17" },
|
|
51
|
+
{ "name": "Crane skiff Co", "slug": "client-2", "since": "2017-07-07" }
|
|
52
|
+
];
|
|
53
|
+
|
|
54
|
+
export default function ClientsPage() {
|
|
55
|
+
return (
|
|
56
|
+
<main>
|
|
57
|
+
<h1>Clients</h1>
|
|
58
|
+
<ul>
|
|
59
|
+
{clients.map((item, idx) => (
|
|
60
|
+
<li key={idx}><span>{item.name}</span> <span>{item.since}</span></li>
|
|
61
|
+
))}
|
|
62
|
+
</ul>
|
|
63
|
+
</main>
|
|
64
|
+
);
|
|
65
|
+
}
|
|
66
|
+
`;
|
|
67
|
+
describe('rewireNextCollectionPages', () => {
|
|
68
|
+
it('wires a data-file import page through wrapCollection', () => {
|
|
69
|
+
const root = project({
|
|
70
|
+
'src/data/posts.json': POSTS_JSON,
|
|
71
|
+
'app/posts/page.tsx': DATA_PAGE,
|
|
72
|
+
});
|
|
73
|
+
const result = run(root);
|
|
74
|
+
expect(result.rewired).toBe(1);
|
|
75
|
+
const page = readFileSync(join(root, 'app/posts/page.tsx'), 'utf8');
|
|
76
|
+
expect(page).toContain("import postsSource from '../../src/data/posts.json'");
|
|
77
|
+
expect(page).toContain('export default async function PostsPage()');
|
|
78
|
+
expect(page).toContain("const posts = await wrapCollection('Post', postsSource);");
|
|
79
|
+
expect(page).toContain('import { wrapCollection } from "fimo/next/server"');
|
|
80
|
+
});
|
|
81
|
+
it('extracts an in-code array to src/data and wires the page', () => {
|
|
82
|
+
const root = project({
|
|
83
|
+
'app/clients/page.tsx': INCODE_PAGE,
|
|
84
|
+
});
|
|
85
|
+
const result = run(root);
|
|
86
|
+
expect(result.rewired).toBe(1);
|
|
87
|
+
const extracted = JSON.parse(readFileSync(join(root, 'src/data/clients.json'), 'utf8'));
|
|
88
|
+
expect(extracted).toHaveLength(3);
|
|
89
|
+
expect(extracted[0]).toEqual({ name: 'Quay anchor Co', slug: 'client-0', since: '2018-03-20' });
|
|
90
|
+
const page = readFileSync(join(root, 'app/clients/page.tsx'), 'utf8');
|
|
91
|
+
expect(page).toContain("import clientsSource from '../../src/data/clients.json'");
|
|
92
|
+
expect(page).toContain('export default async function ClientsPage()');
|
|
93
|
+
expect(page).toContain("const clients = await wrapCollection('Client', clientsSource);");
|
|
94
|
+
expect(page).not.toContain('"Quay anchor Co"');
|
|
95
|
+
});
|
|
96
|
+
it('extracts an `as const` in-code array (the generator/create-next-app shape)', () => {
|
|
97
|
+
const root = project({
|
|
98
|
+
'app/clients/page.tsx': INCODE_PAGE.replace('\n];', '\n] as const;'),
|
|
99
|
+
});
|
|
100
|
+
const result = run(root);
|
|
101
|
+
expect(result.rewired).toBe(1);
|
|
102
|
+
const page = readFileSync(join(root, 'app/clients/page.tsx'), 'utf8');
|
|
103
|
+
expect(page).toContain("const clients = await wrapCollection('Client', clientsSource);");
|
|
104
|
+
expect(page).not.toContain('as const');
|
|
105
|
+
});
|
|
106
|
+
it('bails on client components with a reason', () => {
|
|
107
|
+
const root = project({
|
|
108
|
+
'src/data/posts.json': POSTS_JSON,
|
|
109
|
+
'app/posts/page.tsx': `'use client';\n${DATA_PAGE}`,
|
|
110
|
+
});
|
|
111
|
+
const result = run(root);
|
|
112
|
+
expect(result.rewired).toBe(0);
|
|
113
|
+
expect(result.warnings.some((warning) => warning.includes('client component'))).toBe(true);
|
|
114
|
+
});
|
|
115
|
+
it('bails when the collection is referenced outside the page component', () => {
|
|
116
|
+
const root = project({
|
|
117
|
+
'app/clients/page.tsx': `${INCODE_PAGE}\nexport const clientCount = clients.length;\n`,
|
|
118
|
+
});
|
|
119
|
+
const result = run(root);
|
|
120
|
+
expect(result.rewired).toBe(0);
|
|
121
|
+
expect(result.warnings.some((warning) => warning.includes('referenced outside'))).toBe(true);
|
|
122
|
+
});
|
|
123
|
+
it('is idempotent: an already-wired page is left untouched', () => {
|
|
124
|
+
const root = project({
|
|
125
|
+
'src/data/posts.json': POSTS_JSON,
|
|
126
|
+
'app/posts/page.tsx': DATA_PAGE,
|
|
127
|
+
});
|
|
128
|
+
run(root);
|
|
129
|
+
const once = readFileSync(join(root, 'app/posts/page.tsx'), 'utf8');
|
|
130
|
+
const again = run(root);
|
|
131
|
+
expect(readFileSync(join(root, 'app/posts/page.tsx'), 'utf8')).toBe(once);
|
|
132
|
+
expect(again.warnings.filter((warning) => warning.includes('app/posts'))).toHaveLength(0);
|
|
133
|
+
});
|
|
134
|
+
});
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
export interface DiscoveredRoute {
|
|
2
|
+
id: string;
|
|
3
|
+
path: string;
|
|
4
|
+
label: string;
|
|
5
|
+
}
|
|
6
|
+
/**
|
|
7
|
+
* Discover page routes of a Next.js app-router directory (`app/` or
|
|
8
|
+
* `src/app/`). Returns display routes for `fimo-config.json#routes` so the
|
|
9
|
+
* Studio page switcher can enumerate a wrapped site's pages.
|
|
10
|
+
*/
|
|
11
|
+
export declare function discoverNextRoutes(appDir: string): DiscoveredRoute[];
|
|
12
|
+
/**
|
|
13
|
+
* Pages-router discovery (`pages/` or `src/pages/`): every module is a route
|
|
14
|
+
* except `_app`/`_document`/`_error` and `api/`. `[param]` segments map to
|
|
15
|
+
* `:param` (the parity capture skips dynamic routes, same as app router).
|
|
16
|
+
*/
|
|
17
|
+
export declare function discoverNextPagesRoutes(pagesDir: string): DiscoveredRoute[];
|
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
import { readdirSync, statSync } from 'node:fs';
|
|
2
|
+
import { join } from 'node:path';
|
|
3
|
+
const PAGE_FILES = new Set(['page.tsx', 'page.jsx', 'page.ts', 'page.js', 'page.mdx']);
|
|
4
|
+
const titleCase = (seg) => seg
|
|
5
|
+
.replace(/[_\-]+/g, ' ')
|
|
6
|
+
.replace(/([a-z])([A-Z])/g, '$1 $2')
|
|
7
|
+
.split(/\s+/)
|
|
8
|
+
.filter(Boolean)
|
|
9
|
+
.map((w) => w.charAt(0).toUpperCase() + w.slice(1).toLowerCase())
|
|
10
|
+
.join(' ');
|
|
11
|
+
function segmentToPath(segment) {
|
|
12
|
+
// Route groups `(marketing)` don't contribute URL segments. Parallel-route
|
|
13
|
+
// slots `@modal` and private folders `_lib` are not standalone pages.
|
|
14
|
+
if (segment.startsWith('(')) {
|
|
15
|
+
return '';
|
|
16
|
+
}
|
|
17
|
+
if (segment.startsWith('@') || segment.startsWith('_')) {
|
|
18
|
+
return null;
|
|
19
|
+
}
|
|
20
|
+
const catchAll = segment.match(/^\[\.\.\.(.+)\]$/) ?? segment.match(/^\[\[\.\.\.(.+)\]\]$/);
|
|
21
|
+
if (catchAll) {
|
|
22
|
+
return `:${catchAll[1]}*`;
|
|
23
|
+
}
|
|
24
|
+
const param = segment.match(/^\[(.+)\]$/);
|
|
25
|
+
if (param) {
|
|
26
|
+
return `:${param[1]}`;
|
|
27
|
+
}
|
|
28
|
+
return segment;
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Discover page routes of a Next.js app-router directory (`app/` or
|
|
32
|
+
* `src/app/`). Returns display routes for `fimo-config.json#routes` so the
|
|
33
|
+
* Studio page switcher can enumerate a wrapped site's pages.
|
|
34
|
+
*/
|
|
35
|
+
export function discoverNextRoutes(appDir) {
|
|
36
|
+
const routes = [];
|
|
37
|
+
const walk = (dir, segments) => {
|
|
38
|
+
let entries;
|
|
39
|
+
try {
|
|
40
|
+
entries = readdirSync(dir);
|
|
41
|
+
}
|
|
42
|
+
catch {
|
|
43
|
+
return;
|
|
44
|
+
}
|
|
45
|
+
if (entries.some((entry) => PAGE_FILES.has(entry))) {
|
|
46
|
+
const parts = segments.filter((s) => s.length > 0);
|
|
47
|
+
const routePath = `/${parts.join('/')}`.replace(/\/+/g, '/');
|
|
48
|
+
const lastStatic = [...parts].reverse().find((p) => !p.startsWith(':'));
|
|
49
|
+
routes.push({
|
|
50
|
+
id: routePath === '/' ? 'home' : parts.map((p) => p.replace(/^:/, '')).join('-'),
|
|
51
|
+
path: routePath,
|
|
52
|
+
label: routePath === '/' ? 'Home' : titleCase(lastStatic ?? parts[parts.length - 1] ?? routePath),
|
|
53
|
+
});
|
|
54
|
+
}
|
|
55
|
+
for (const entry of entries) {
|
|
56
|
+
const full = join(dir, entry);
|
|
57
|
+
let isDir = false;
|
|
58
|
+
try {
|
|
59
|
+
isDir = statSync(full).isDirectory();
|
|
60
|
+
}
|
|
61
|
+
catch {
|
|
62
|
+
continue;
|
|
63
|
+
}
|
|
64
|
+
if (!isDir) {
|
|
65
|
+
continue;
|
|
66
|
+
}
|
|
67
|
+
const mapped = segmentToPath(entry);
|
|
68
|
+
if (mapped === null) {
|
|
69
|
+
continue;
|
|
70
|
+
}
|
|
71
|
+
walk(full, [...segments, mapped]);
|
|
72
|
+
}
|
|
73
|
+
};
|
|
74
|
+
walk(appDir, []);
|
|
75
|
+
return routes.sort((a, b) => a.path.localeCompare(b.path));
|
|
76
|
+
}
|
|
77
|
+
const PAGES_EXTENSIONS = /\.(tsx|jsx|ts|js)$/;
|
|
78
|
+
const PAGES_SKIP = new Set(['api']);
|
|
79
|
+
/**
|
|
80
|
+
* Pages-router discovery (`pages/` or `src/pages/`): every module is a route
|
|
81
|
+
* except `_app`/`_document`/`_error` and `api/`. `[param]` segments map to
|
|
82
|
+
* `:param` (the parity capture skips dynamic routes, same as app router).
|
|
83
|
+
*/
|
|
84
|
+
export function discoverNextPagesRoutes(pagesDir) {
|
|
85
|
+
const routes = [];
|
|
86
|
+
const toSegment = (name) => name
|
|
87
|
+
.replace(/^\[\.\.\.(.+)\]$/, ':$1')
|
|
88
|
+
.replace(/^\[\[\.\.\.(.+)\]\]$/, ':$1')
|
|
89
|
+
.replace(/^\[(.+)\]$/, ':$1');
|
|
90
|
+
const walk = (dir, segments) => {
|
|
91
|
+
let entries;
|
|
92
|
+
try {
|
|
93
|
+
entries = readdirSync(dir);
|
|
94
|
+
}
|
|
95
|
+
catch {
|
|
96
|
+
return;
|
|
97
|
+
}
|
|
98
|
+
for (const entry of entries) {
|
|
99
|
+
const full = join(dir, entry);
|
|
100
|
+
let isDir = false;
|
|
101
|
+
try {
|
|
102
|
+
isDir = statSync(full).isDirectory();
|
|
103
|
+
}
|
|
104
|
+
catch {
|
|
105
|
+
continue;
|
|
106
|
+
}
|
|
107
|
+
if (isDir) {
|
|
108
|
+
// api/ is only special at the pages root.
|
|
109
|
+
if (!(segments.length === 0 && PAGES_SKIP.has(entry))) {
|
|
110
|
+
walk(full, [...segments, toSegment(entry)]);
|
|
111
|
+
}
|
|
112
|
+
continue;
|
|
113
|
+
}
|
|
114
|
+
if (!PAGES_EXTENSIONS.test(entry)) {
|
|
115
|
+
continue;
|
|
116
|
+
}
|
|
117
|
+
const base = entry.replace(PAGES_EXTENSIONS, '');
|
|
118
|
+
if (base.startsWith('_')) {
|
|
119
|
+
continue;
|
|
120
|
+
}
|
|
121
|
+
const parts = base === 'index' ? segments : [...segments, toSegment(base)];
|
|
122
|
+
const routePath = `/${parts.join('/')}`.replace(/\/+/g, '/');
|
|
123
|
+
const lastStatic = [...parts].reverse().find((part) => !part.startsWith(':'));
|
|
124
|
+
routes.push({
|
|
125
|
+
id: routePath === '/' ? 'home' : parts.map((part) => part.replace(/^:/, '')).join('-'),
|
|
126
|
+
path: routePath,
|
|
127
|
+
label: routePath === '/' ? 'Home' : titleCase(lastStatic ?? parts[parts.length - 1] ?? routePath),
|
|
128
|
+
});
|
|
129
|
+
}
|
|
130
|
+
};
|
|
131
|
+
walk(pagesDir, []);
|
|
132
|
+
routes.sort((a, b) => a.path.localeCompare(b.path));
|
|
133
|
+
return routes;
|
|
134
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import { mkdirSync, mkdtempSync, rmSync, writeFileSync } from 'node:fs';
|
|
2
|
+
import { tmpdir } from 'node:os';
|
|
3
|
+
import { join } from 'node:path';
|
|
4
|
+
import { afterEach, describe, expect, it } from 'vitest';
|
|
5
|
+
import { discoverNextRoutes } from './routes.js';
|
|
6
|
+
let dir;
|
|
7
|
+
const app = (pages) => {
|
|
8
|
+
dir = mkdtempSync(join(tmpdir(), 'next-routes-'));
|
|
9
|
+
for (const page of pages) {
|
|
10
|
+
const full = join(dir, page);
|
|
11
|
+
mkdirSync(join(full, '..'), { recursive: true });
|
|
12
|
+
writeFileSync(full, 'export default function Page() { return null }');
|
|
13
|
+
}
|
|
14
|
+
return dir;
|
|
15
|
+
};
|
|
16
|
+
afterEach(() => {
|
|
17
|
+
if (dir) {
|
|
18
|
+
rmSync(dir, { recursive: true, force: true });
|
|
19
|
+
}
|
|
20
|
+
});
|
|
21
|
+
describe('discoverNextRoutes', () => {
|
|
22
|
+
it('discovers static routes', () => {
|
|
23
|
+
const routes = discoverNextRoutes(app(['page.tsx', 'about/page.tsx', 'pricing/page.tsx']));
|
|
24
|
+
expect(routes.map((r) => r.path)).toEqual(['/', '/about', '/pricing']);
|
|
25
|
+
expect(routes[0]).toEqual({ id: 'home', path: '/', label: 'Home' });
|
|
26
|
+
expect(routes[1]).toEqual({ id: 'about', path: '/about', label: 'About' });
|
|
27
|
+
});
|
|
28
|
+
it('maps dynamic and catch-all segments', () => {
|
|
29
|
+
const routes = discoverNextRoutes(app(['blog/[slug]/page.tsx', 'docs/[...path]/page.tsx']));
|
|
30
|
+
expect(routes.map((r) => r.path)).toEqual(['/blog/:slug', '/docs/:path*']);
|
|
31
|
+
expect(routes[0].label).toBe('Blog');
|
|
32
|
+
});
|
|
33
|
+
it('collapses route groups and skips private and parallel segments', () => {
|
|
34
|
+
const routes = discoverNextRoutes(app(['(marketing)/features/page.tsx', '_internal/secret/page.tsx', '@modal/photo/page.tsx']));
|
|
35
|
+
expect(routes.map((r) => r.path)).toEqual(['/features']);
|
|
36
|
+
});
|
|
37
|
+
it('returns [] for a missing directory', () => {
|
|
38
|
+
expect(discoverNextRoutes(join(tmpdir(), 'does-not-exist'))).toEqual([]);
|
|
39
|
+
});
|
|
40
|
+
});
|
|
41
|
+
describe('discoverNextPagesRoutes', () => {
|
|
42
|
+
it('maps pages-router modules to routes, skipping api and _ files', async () => {
|
|
43
|
+
const { mkdtempSync, mkdirSync, writeFileSync, rmSync } = await import('node:fs');
|
|
44
|
+
const { tmpdir } = await import('node:os');
|
|
45
|
+
const { join } = await import('node:path');
|
|
46
|
+
const dir = mkdtempSync(join(tmpdir(), 'pages-'));
|
|
47
|
+
try {
|
|
48
|
+
mkdirSync(join(dir, 'blog'), { recursive: true });
|
|
49
|
+
mkdirSync(join(dir, 'api'), { recursive: true });
|
|
50
|
+
writeFileSync(join(dir, 'index.tsx'), '');
|
|
51
|
+
writeFileSync(join(dir, 'about.tsx'), '');
|
|
52
|
+
writeFileSync(join(dir, '_app.tsx'), '');
|
|
53
|
+
writeFileSync(join(dir, '_document.tsx'), '');
|
|
54
|
+
writeFileSync(join(dir, 'api/hello.ts'), '');
|
|
55
|
+
writeFileSync(join(dir, 'blog/index.tsx'), '');
|
|
56
|
+
writeFileSync(join(dir, 'blog/[slug].tsx'), '');
|
|
57
|
+
const { discoverNextPagesRoutes } = await import('./routes.js');
|
|
58
|
+
expect(discoverNextPagesRoutes(dir).map((route) => route.path)).toEqual(['/', '/about', '/blog', '/blog/:slug']);
|
|
59
|
+
}
|
|
60
|
+
finally {
|
|
61
|
+
rmSync(dir, { recursive: true, force: true });
|
|
62
|
+
}
|
|
63
|
+
});
|
|
64
|
+
});
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import type { FrameworkDetection } from '../../detect-framework.js';
|
|
2
|
+
/**
|
|
3
|
+
* Next.js-side wrap wiring: everything the wrap migration must touch that is
|
|
4
|
+
* specific to this framework lives HERE, not in the generic flow. Mirror this
|
|
5
|
+
* module when adding a framework (see the fimo-framework-adapter skill).
|
|
6
|
+
*/
|
|
7
|
+
export declare function ensureNextWiring(cwd: string): {
|
|
8
|
+
changes: string[];
|
|
9
|
+
warnings: string[];
|
|
10
|
+
};
|
|
11
|
+
export interface RootWiringResult {
|
|
12
|
+
changes: string[];
|
|
13
|
+
warnings: string[];
|
|
14
|
+
/** True when the root wiring is in place (pre-existing or just applied). */
|
|
15
|
+
wired: boolean;
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Candidate app-router root-layout files: the direct `<appDir>/layout.*` plus,
|
|
19
|
+
* for i18n apps that place the `<html>` layout under a dynamic segment
|
|
20
|
+
* (next-intl's `app/[locale]/layout.tsx`), any `<appDir>/[segment]/layout.*`.
|
|
21
|
+
* Existing files only, in resolution order.
|
|
22
|
+
*/
|
|
23
|
+
export declare function nextRootLayoutFiles(cwd: string, appDir: string): string[];
|
|
24
|
+
/**
|
|
25
|
+
* Wire the app-router root layout deterministically: imports, async default
|
|
26
|
+
* export, loader calls, `<FimoNextScripts />` in head, and `{children}`
|
|
27
|
+
* wrapped in `<FimoNextProviders>`. Only the provably safe shape is touched —
|
|
28
|
+
* one default-exported function whose JSX returns `<html>…<body>` with a
|
|
29
|
+
* `{children}` expression somewhere inside body (create-next-app and its
|
|
30
|
+
* variants). Anything else bails with the reason, and the agent prompt keeps
|
|
31
|
+
* the manual recipe.
|
|
32
|
+
*/
|
|
33
|
+
export declare function ensureNextLayoutWiring(cwd: string, detection: Pick<FrameworkDetection, 'appDir'>): RootWiringResult;
|
|
@@ -0,0 +1,186 @@
|
|
|
1
|
+
import fs from 'node:fs';
|
|
2
|
+
import path from 'node:path';
|
|
3
|
+
import { parseSync } from 'oxc-parser';
|
|
4
|
+
import { ensureFimoImport } from '../../apply-wrap.js';
|
|
5
|
+
/**
|
|
6
|
+
* Next.js-side wrap wiring: everything the wrap migration must touch that is
|
|
7
|
+
* specific to this framework lives HERE, not in the generic flow. Mirror this
|
|
8
|
+
* module when adding a framework (see the fimo-framework-adapter skill).
|
|
9
|
+
*/
|
|
10
|
+
export function ensureNextWiring(cwd) {
|
|
11
|
+
const changes = [];
|
|
12
|
+
const warnings = [];
|
|
13
|
+
const configFile = ['next.config.ts', 'next.config.mjs', 'next.config.js', 'next.config.cjs']
|
|
14
|
+
.map((candidate) => path.join(cwd, candidate))
|
|
15
|
+
.find((candidate) => fs.existsSync(candidate));
|
|
16
|
+
if (configFile) {
|
|
17
|
+
const source = fs.readFileSync(configFile, 'utf8');
|
|
18
|
+
if (!source.includes('allowedDevOrigins')) {
|
|
19
|
+
// The three mainstream config shapes: a named object binding, a direct
|
|
20
|
+
// `export default {` literal, and CJS `module.exports = {`.
|
|
21
|
+
let patched = source.replace(/(const\s+nextConfig[^=]*=\s*\{)/, `$1\n allowedDevOrigins: ['*.preview.fimo.ai'],`);
|
|
22
|
+
if (patched === source) {
|
|
23
|
+
patched = source.replace(/((?:export\s+default|module\.exports\s*=)\s*\{)/, `$1\n allowedDevOrigins: ['*.preview.fimo.ai'],\n`);
|
|
24
|
+
}
|
|
25
|
+
if (patched !== source) {
|
|
26
|
+
fs.writeFileSync(configFile, patched);
|
|
27
|
+
changes.push(`added allowedDevOrigins to ${path.basename(configFile)}`);
|
|
28
|
+
}
|
|
29
|
+
else {
|
|
30
|
+
warnings.push(`Could not patch ${path.basename(configFile)} automatically — add: allowedDevOrigins: ['*.preview.fimo.ai']`);
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
else {
|
|
35
|
+
warnings.push("No next.config found — create one with: allowedDevOrigins: ['*.preview.fimo.ai']");
|
|
36
|
+
}
|
|
37
|
+
return { changes, warnings };
|
|
38
|
+
}
|
|
39
|
+
function findFirst(node, predicate) {
|
|
40
|
+
if (!node || typeof node !== 'object') {
|
|
41
|
+
return null;
|
|
42
|
+
}
|
|
43
|
+
if (predicate(node)) {
|
|
44
|
+
return node;
|
|
45
|
+
}
|
|
46
|
+
for (const value of Object.values(node)) {
|
|
47
|
+
if (Array.isArray(value)) {
|
|
48
|
+
for (const entry of value) {
|
|
49
|
+
const found = findFirst(entry, predicate);
|
|
50
|
+
if (found) {
|
|
51
|
+
return found;
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
else if (value && typeof value === 'object') {
|
|
56
|
+
const found = findFirst(value, predicate);
|
|
57
|
+
if (found) {
|
|
58
|
+
return found;
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
return null;
|
|
63
|
+
}
|
|
64
|
+
const jsxName = (element) => element?.openingElement?.name?.name;
|
|
65
|
+
/**
|
|
66
|
+
* Candidate app-router root-layout files: the direct `<appDir>/layout.*` plus,
|
|
67
|
+
* for i18n apps that place the `<html>` layout under a dynamic segment
|
|
68
|
+
* (next-intl's `app/[locale]/layout.tsx`), any `<appDir>/[segment]/layout.*`.
|
|
69
|
+
* Existing files only, in resolution order.
|
|
70
|
+
*/
|
|
71
|
+
export function nextRootLayoutFiles(cwd, appDir) {
|
|
72
|
+
const names = ['layout.tsx', 'layout.jsx', 'layout.js'];
|
|
73
|
+
const dirs = [path.join(cwd, appDir)];
|
|
74
|
+
try {
|
|
75
|
+
for (const entry of fs.readdirSync(path.join(cwd, appDir), { withFileTypes: true })) {
|
|
76
|
+
if (entry.isDirectory() && entry.name.startsWith('[') && entry.name.endsWith(']')) {
|
|
77
|
+
dirs.push(path.join(cwd, appDir, entry.name));
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
catch {
|
|
82
|
+
// appDir missing — no candidates
|
|
83
|
+
}
|
|
84
|
+
return dirs.flatMap((dir) => names.map((name) => path.join(dir, name))).filter((file) => fs.existsSync(file));
|
|
85
|
+
}
|
|
86
|
+
/**
|
|
87
|
+
* Wire the app-router root layout deterministically: imports, async default
|
|
88
|
+
* export, loader calls, `<FimoNextScripts />` in head, and `{children}`
|
|
89
|
+
* wrapped in `<FimoNextProviders>`. Only the provably safe shape is touched —
|
|
90
|
+
* one default-exported function whose JSX returns `<html>…<body>` with a
|
|
91
|
+
* `{children}` expression somewhere inside body (create-next-app and its
|
|
92
|
+
* variants). Anything else bails with the reason, and the agent prompt keeps
|
|
93
|
+
* the manual recipe.
|
|
94
|
+
*/
|
|
95
|
+
export function ensureNextLayoutWiring(cwd, detection) {
|
|
96
|
+
if (!detection.appDir) {
|
|
97
|
+
return {
|
|
98
|
+
changes: [],
|
|
99
|
+
warnings: ['Root wiring not applied: pages-router project (no app directory) — wire pages/_app manually.'],
|
|
100
|
+
wired: false,
|
|
101
|
+
};
|
|
102
|
+
}
|
|
103
|
+
const candidates = nextRootLayoutFiles(cwd, detection.appDir);
|
|
104
|
+
// Already wired anywhere — an agent may have mounted the [locale] layout by hand.
|
|
105
|
+
if (candidates.some((file) => fs.readFileSync(file, 'utf8').includes('FimoNextProviders'))) {
|
|
106
|
+
return { changes: [], warnings: [], wired: true };
|
|
107
|
+
}
|
|
108
|
+
// The real root layout is the one that returns <html> (next-intl puts it under
|
|
109
|
+
// app/[locale]/); fall back to the first candidate for the bail message.
|
|
110
|
+
const layoutFile = candidates.find((file) => fs.readFileSync(file, 'utf8').includes('<html')) ?? candidates[0];
|
|
111
|
+
const rel = layoutFile ? path.relative(cwd, layoutFile) : `${detection.appDir}/layout.tsx`;
|
|
112
|
+
const bail = (reason) => ({
|
|
113
|
+
changes: [],
|
|
114
|
+
warnings: [`Root wiring not applied: ${reason} — follow the layout recipe in the agent prompt (${rel}).`],
|
|
115
|
+
wired: false,
|
|
116
|
+
});
|
|
117
|
+
if (!layoutFile) {
|
|
118
|
+
return bail('no root layout file found');
|
|
119
|
+
}
|
|
120
|
+
const code = fs.readFileSync(layoutFile, 'utf8');
|
|
121
|
+
let program;
|
|
122
|
+
try {
|
|
123
|
+
program = parseSync(layoutFile, code).program;
|
|
124
|
+
}
|
|
125
|
+
catch {
|
|
126
|
+
return bail('root layout could not be parsed');
|
|
127
|
+
}
|
|
128
|
+
const exportDefault = (program.body ?? []).find((node) => node.type === 'ExportDefaultDeclaration');
|
|
129
|
+
if (!exportDefault || exportDefault.declaration?.type !== 'FunctionDeclaration') {
|
|
130
|
+
return bail('the default export is not a plain function declaration');
|
|
131
|
+
}
|
|
132
|
+
const layoutFn = exportDefault.declaration;
|
|
133
|
+
const body = layoutFn.body;
|
|
134
|
+
if (!body || (body.type !== 'FunctionBody' && body.type !== 'BlockStatement')) {
|
|
135
|
+
return bail('the layout function has no block body');
|
|
136
|
+
}
|
|
137
|
+
const html = findFirst(body, (node) => node?.type === 'JSXElement' && jsxName(node) === 'html');
|
|
138
|
+
if (!html) {
|
|
139
|
+
return bail('the layout does not return an <html> element');
|
|
140
|
+
}
|
|
141
|
+
const htmlBody = (html.children ?? []).find((child) => child?.type === 'JSXElement' && jsxName(child) === 'body');
|
|
142
|
+
if (!htmlBody) {
|
|
143
|
+
return bail('no <body> element found under <html>');
|
|
144
|
+
}
|
|
145
|
+
const childrenExpr = findFirst(htmlBody, (node) => node?.type === 'JSXExpressionContainer' &&
|
|
146
|
+
node.expression?.type === 'Identifier' &&
|
|
147
|
+
node.expression?.name === 'children');
|
|
148
|
+
if (!childrenExpr) {
|
|
149
|
+
return bail('no {children} expression found inside <body>');
|
|
150
|
+
}
|
|
151
|
+
const edits = [];
|
|
152
|
+
if (!layoutFn.async) {
|
|
153
|
+
edits.push({ start: layoutFn.start, end: layoutFn.start, replacement: 'async ' });
|
|
154
|
+
}
|
|
155
|
+
edits.push({
|
|
156
|
+
start: body.start + 1,
|
|
157
|
+
end: body.start + 1,
|
|
158
|
+
replacement: '\n const config = loadFimoConfig();\n const labels = await loadFimoLabels();\n',
|
|
159
|
+
});
|
|
160
|
+
edits.push({
|
|
161
|
+
start: childrenExpr.start,
|
|
162
|
+
end: childrenExpr.end,
|
|
163
|
+
replacement: `<FimoNextProviders config={config} labels={labels}>${code.slice(childrenExpr.start, childrenExpr.end)}</FimoNextProviders>`,
|
|
164
|
+
});
|
|
165
|
+
const head = (html.children ?? []).find((child) => child?.type === 'JSXElement' && jsxName(child) === 'head');
|
|
166
|
+
if (head) {
|
|
167
|
+
const at = head.openingElement.end;
|
|
168
|
+
edits.push({ start: at, end: at, replacement: '<FimoNextScripts />' });
|
|
169
|
+
}
|
|
170
|
+
else {
|
|
171
|
+
const at = html.openingElement.end;
|
|
172
|
+
edits.push({
|
|
173
|
+
start: at,
|
|
174
|
+
end: at,
|
|
175
|
+
replacement: '\n <head>\n <FimoNextScripts />\n </head>',
|
|
176
|
+
});
|
|
177
|
+
}
|
|
178
|
+
let next = code;
|
|
179
|
+
for (const edit of edits.sort((a, b) => b.start - a.start)) {
|
|
180
|
+
next = next.slice(0, edit.start) + edit.replacement + next.slice(edit.end);
|
|
181
|
+
}
|
|
182
|
+
next = ensureFimoImport(next, ['FimoNextProviders', 'FimoNextScripts'], 'fimo/next');
|
|
183
|
+
next = ensureFimoImport(next, ['loadFimoConfig', 'loadFimoLabels'], 'fimo/next/server');
|
|
184
|
+
fs.writeFileSync(layoutFile, next);
|
|
185
|
+
return { changes: [`wired Fimo providers into ${rel}`], warnings: [], wired: true };
|
|
186
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|