fimo 0.7.0-experimental.3 → 0.7.0-staging.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +2 -3
- package/assets/skills/fimo/SKILL.md +1 -1
- package/assets/skills/fimo/references/assets.md +2 -2
- package/assets/skills/fimo/references/content.md +1 -1
- package/assets/skills/fimo/references/design.md +1 -1
- package/assets/skills/fimo-cli/SKILL.md +1 -1
- package/assets/skills/fimo-cli/references/assets.md +24 -7
- package/assets/skills/fimo-cli/references/content.md +2 -2
- package/assets/skills/fimo-cli/references/domains.md +1 -1
- package/assets/skills/fimo-cli/references/media.md +142 -132
- package/assets/skills/fimo-studio/references/custom-domains.md +1 -1
- package/dist/build/vite/index.d.ts.map +1 -0
- package/dist/build/vite/plugins/content-sync.d.ts.map +1 -0
- package/dist/build/vite/plugins/content-sync.test.d.ts +2 -0
- package/dist/build/vite/plugins/content-sync.test.d.ts.map +1 -0
- package/dist/build/vite/plugins/content-sync.test.js +64 -0
- package/dist/build/vite/plugins/data-id.d.ts.map +1 -0
- package/dist/build/vite/plugins/fimo-config.d.ts.map +1 -0
- package/dist/build/vite/plugins/fimo-config.test.d.ts +2 -0
- package/dist/build/vite/plugins/fimo-config.test.d.ts.map +1 -0
- package/dist/build/vite/plugins/fimo-config.test.js +46 -0
- package/dist/build/vite/plugins/overlay.d.ts.map +1 -0
- package/dist/build/vite/plugins/robots.d.ts.map +1 -0
- package/dist/build/vite/plugins/seo.d.ts.map +1 -0
- package/dist/build/vite/plugins/server-config.d.ts.map +1 -0
- package/dist/build/vite/plugins/sitemap.d.ts.map +1 -0
- package/dist/build/vite/plugins/translations.d.ts.map +1 -0
- package/dist/build/vite/plugins/translations.test.d.ts +2 -0
- package/dist/build/vite/plugins/translations.test.d.ts.map +1 -0
- package/dist/build/vite/plugins/translations.test.js +266 -0
- package/dist/cli/bundle.json +2 -3
- package/dist/cli/index.js +110670 -1196
- package/dist/runtime/app/FimoProviders.d.ts.map +1 -0
- package/dist/runtime/app/FimoScripts.d.ts.map +1 -0
- package/dist/runtime/app/index.d.ts.map +1 -0
- package/dist/runtime/app/prefetch.d.ts.map +1 -0
- package/dist/runtime/content/DataSourcesProvider.d.ts.map +1 -0
- package/dist/runtime/content/RefreshContentProvider.d.ts.map +1 -0
- package/dist/runtime/content/RefreshContentProvider.test.d.ts +2 -0
- package/dist/runtime/content/RefreshContentProvider.test.d.ts.map +1 -0
- package/dist/runtime/content/RefreshContentProvider.test.js +33 -0
- package/dist/runtime/content/parseCollectionResponse.d.ts.map +1 -0
- package/dist/runtime/content/parseCollectionResponse.test.d.ts +2 -0
- package/dist/runtime/content/parseCollectionResponse.test.d.ts.map +1 -0
- package/dist/runtime/content/parseCollectionResponse.test.js +20 -0
- package/dist/runtime/content/utils/retrieve-data-sources.d.ts.map +1 -0
- package/dist/runtime/core/AppErrorBoundary.d.ts.map +1 -0
- package/dist/runtime/core/ViteLifecycles.d.ts.map +1 -0
- package/dist/runtime/i18n/FimoLocaleContext.d.ts.map +1 -0
- package/dist/runtime/i18n/locale.d.ts.map +1 -0
- package/dist/runtime/i18n/locale.test.d.ts +2 -0
- package/dist/runtime/i18n/locale.test.d.ts.map +1 -0
- package/dist/runtime/i18n/locale.test.js +58 -0
- package/dist/runtime/iframe/ConsoleErrorProvider.d.ts.map +1 -0
- package/dist/runtime/iframe/ScreenshotProvider.d.ts.map +1 -0
- package/dist/runtime/iframe/runtime/overlay-hmr.d.ts.map +1 -0
- package/dist/runtime/iframe/runtime/overlay-runtime.d.ts.map +1 -0
- package/dist/runtime/index.d.ts +0 -3
- package/dist/runtime/index.d.ts.map +1 -0
- package/dist/runtime/index.js +0 -2
- package/dist/runtime/paths/get-fimo-paths.d.ts.map +1 -0
- package/dist/runtime/paths/get-fimo-paths.test.d.ts +2 -0
- package/dist/runtime/paths/get-fimo-paths.test.d.ts.map +1 -0
- package/dist/runtime/paths/get-fimo-paths.test.js +69 -0
- package/dist/runtime/paths/index.d.ts.map +1 -0
- package/dist/runtime/paths/types.d.ts.map +1 -0
- package/dist/runtime/primitives/components/Boolean.d.ts.map +1 -0
- package/dist/runtime/primitives/components/Date.d.ts.map +1 -0
- package/dist/runtime/primitives/components/Image.d.ts.map +1 -0
- package/dist/runtime/primitives/components/RichText.d.ts.map +1 -0
- package/dist/runtime/primitives/components/StaticImage.d.ts.map +1 -0
- package/dist/runtime/primitives/components/Text.d.ts.map +1 -0
- package/dist/runtime/primitives/components/Video.d.ts.map +1 -0
- package/dist/runtime/primitives/components/index.d.ts.map +1 -0
- package/dist/runtime/primitives/index.d.ts.map +1 -0
- package/dist/runtime/primitives/lib/image-optimization.d.ts.map +1 -0
- package/dist/runtime/primitives/lib/index.d.ts.map +1 -0
- package/dist/runtime/primitives/lib/primitives.d.ts.map +1 -0
- package/dist/runtime/primitives/lib/query.d.ts.map +1 -0
- package/dist/runtime/primitives/lib/template.d.ts.map +1 -0
- package/dist/runtime/primitives/lib/useFimoLiveValue.d.ts.map +1 -0
- package/dist/runtime/primitives/public-surface.test.d.ts +2 -0
- package/dist/runtime/primitives/public-surface.test.d.ts.map +1 -0
- package/dist/runtime/primitives/public-surface.test.js +49 -0
- package/dist/runtime/primitives/translations.d.ts.map +1 -0
- package/dist/runtime/react-router/index.d.ts.map +1 -0
- package/dist/runtime/react-router/navigation-utils.d.ts.map +1 -0
- package/dist/runtime/react-router/navigation.d.ts.map +1 -0
- package/dist/runtime/react-router/navigation.test.d.ts +2 -0
- package/dist/runtime/react-router/navigation.test.d.ts.map +1 -0
- package/dist/runtime/react-router/navigation.test.js +35 -0
- package/dist/runtime/react-router/routes.d.ts.map +1 -0
- package/dist/runtime/react-router/routes.test.d.ts +2 -0
- package/dist/runtime/react-router/routes.test.d.ts.map +1 -0
- package/dist/runtime/react-router/routes.test.js +67 -0
- package/dist/runtime/routing/AppResetScrollOnNavigate.d.ts.map +1 -0
- package/dist/runtime/routing/AppRoutesProvider.d.ts.map +1 -0
- package/dist/runtime/seo/buildSeoForPath.d.ts.map +1 -0
- package/dist/runtime/seo/htmlProps.d.ts.map +1 -0
- package/dist/runtime/seo/index.d.ts.map +1 -0
- package/dist/runtime/seo/resolver.d.ts.map +1 -0
- package/dist/runtime/shared/fimo-config.server.d.ts.map +1 -0
- package/dist/runtime/shared/fimo-config.types.d.ts.map +1 -0
- package/dist/runtime/t/OptionalTracking.d.ts.map +1 -0
- package/dist/runtime/t/OptionalTracking.test.d.ts +2 -0
- package/dist/runtime/t/OptionalTracking.test.d.ts.map +1 -0
- package/dist/runtime/t/OptionalTracking.test.js +11 -0
- package/dist/runtime/t/Pageview.d.ts.map +1 -0
- package/dist/runtime/templates.d.ts.map +1 -0
- package/dist/scripts/generated-types.test.js +212 -0
- package/dist/scripts/lint-translation-keys.test.d.ts +1 -0
- package/dist/scripts/lint-translation-keys.test.js +16 -0
- package/dist/scripts/sync-schemas.test.d.ts +1 -0
- package/dist/scripts/sync-schemas.test.js +144 -0
- package/dist/scripts/validate-route-metadata.test.d.ts +1 -0
- package/dist/scripts/validate-route-metadata.test.js +116 -0
- package/dist/scripts/validate-schemas.test.d.ts +1 -0
- package/dist/scripts/validate-schemas.test.js +263 -0
- package/package.json +13 -31
- package/scripts/add-ext.mjs +47 -0
- package/scripts/bump-version.mjs +58 -0
- package/scripts/bundle-cli.mjs +123 -0
- package/scripts/install-cli.mjs +36 -0
- package/scripts/lib/channels.mjs +70 -0
- package/scripts/lib/dev-release-state.mjs +44 -0
- package/scripts/lib/dev-release-state.test.ts +36 -0
- package/scripts/lib/postinstall-onboarding.test.ts +82 -0
- package/scripts/lib/release-core.mjs +225 -0
- package/scripts/lib/release-core.test.ts +147 -0
- package/scripts/migration-qa-gate.test.ts +155 -0
- package/scripts/publish-npm.mjs +180 -0
- package/templates/react-router/package.json +1 -1
- package/templates/react-router/src/pages/Index.tsx +1 -1
- package/dist/runtime/content/client/createContentClient.d.ts +0 -5
- package/dist/runtime/content/client/createContentClient.js +0 -300
- package/dist/runtime/content/client/createSingletonClient.d.ts +0 -5
- package/dist/runtime/content/client/createSingletonClient.js +0 -108
- package/dist/runtime/content/client/internal.d.ts +0 -44
- package/dist/runtime/content/client/internal.js +0 -236
- package/dist/runtime/content/client/types.d.ts +0 -136
- package/dist/runtime/content/client/useQueryLocale.d.ts +0 -2
- package/dist/runtime/content/client/useQueryLocale.js +0 -6
- /package/dist/{runtime/content/client/types.js → scripts/generated-types.test.d.ts} +0 -0
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import { describe, expect, it } from 'vitest';
|
|
2
|
+
import { fimoRoutes } from './routes';
|
|
3
|
+
describe('fimoRoutes', () => {
|
|
4
|
+
const config = {
|
|
5
|
+
i18n: {
|
|
6
|
+
defaultLocale: 'en',
|
|
7
|
+
locales: ['en', 'es'],
|
|
8
|
+
routing: {
|
|
9
|
+
strategy: 'path-prefix',
|
|
10
|
+
prefixDefaultLocale: false,
|
|
11
|
+
},
|
|
12
|
+
},
|
|
13
|
+
};
|
|
14
|
+
it('adds concrete non-default locale aliases that reuse the same route modules', () => {
|
|
15
|
+
const routes = fimoRoutes([
|
|
16
|
+
{ index: true, file: './pages/Index.tsx', id: 'home' },
|
|
17
|
+
{ path: 'pricing', file: './pages/Pricing.tsx', id: 'pricing' },
|
|
18
|
+
{ path: 'blog/:slug', file: './pages/BlogPost.tsx', id: 'blog-post' },
|
|
19
|
+
], { config });
|
|
20
|
+
expect(routes).toEqual([
|
|
21
|
+
{ index: true, file: './pages/Index.tsx', id: 'home' },
|
|
22
|
+
{ path: 'pricing', file: './pages/Pricing.tsx', id: 'pricing' },
|
|
23
|
+
{ path: 'blog/:slug', file: './pages/BlogPost.tsx', id: 'blog-post' },
|
|
24
|
+
{ file: './pages/Index.tsx', id: 'fimo.es.home', path: 'es' },
|
|
25
|
+
{ path: 'es/pricing', file: './pages/Pricing.tsx', id: 'fimo.es.pricing' },
|
|
26
|
+
{ path: 'es/blog/:slug', file: './pages/BlogPost.tsx', id: 'fimo.es.blog-post' },
|
|
27
|
+
]);
|
|
28
|
+
});
|
|
29
|
+
it('can prefix the default locale when configured', () => {
|
|
30
|
+
const routes = fimoRoutes([{ index: true, file: './pages/Index.tsx', id: 'home' }], {
|
|
31
|
+
config: {
|
|
32
|
+
i18n: {
|
|
33
|
+
...config.i18n,
|
|
34
|
+
routing: {
|
|
35
|
+
strategy: 'path-prefix',
|
|
36
|
+
prefixDefaultLocale: true,
|
|
37
|
+
},
|
|
38
|
+
},
|
|
39
|
+
},
|
|
40
|
+
});
|
|
41
|
+
expect(routes).toEqual([
|
|
42
|
+
{ index: true, file: './pages/Index.tsx', id: 'home' },
|
|
43
|
+
{ file: './pages/Index.tsx', id: 'fimo.en.home', path: 'en' },
|
|
44
|
+
{ file: './pages/Index.tsx', id: 'fimo.es.home', path: 'es' },
|
|
45
|
+
]);
|
|
46
|
+
});
|
|
47
|
+
it('localizes children below a pathless layout without duplicating files', () => {
|
|
48
|
+
const routes = fimoRoutes([
|
|
49
|
+
{
|
|
50
|
+
file: './pages/Layout.tsx',
|
|
51
|
+
id: 'site-layout',
|
|
52
|
+
children: [
|
|
53
|
+
{ index: true, file: './pages/Index.tsx', id: 'home' },
|
|
54
|
+
{ path: 'pricing', file: './pages/Pricing.tsx', id: 'pricing' },
|
|
55
|
+
],
|
|
56
|
+
},
|
|
57
|
+
], { config });
|
|
58
|
+
expect(routes[1]).toMatchObject({
|
|
59
|
+
file: './pages/Layout.tsx',
|
|
60
|
+
id: 'fimo.es.site-layout',
|
|
61
|
+
children: [
|
|
62
|
+
{ file: './pages/Index.tsx', id: 'fimo.es.home', path: 'es' },
|
|
63
|
+
{ path: 'es/pricing', file: './pages/Pricing.tsx', id: 'fimo.es.pricing' },
|
|
64
|
+
],
|
|
65
|
+
});
|
|
66
|
+
});
|
|
67
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"AppResetScrollOnNavigate.d.ts","sourceRoot":"","sources":["../../../src/runtime/routing/AppResetScrollOnNavigate.tsx"],"names":[],"mappings":"AAGA,wBAAgB,wBAAwB,SAUvC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"AppRoutesProvider.d.ts","sourceRoot":"","sources":["../../../src/runtime/routing/AppRoutesProvider.tsx"],"names":[],"mappings":"AAAA,OAAO,KAA0C,MAAM,OAAO,CAAC;AAG/D,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC;AAUhD,MAAM,WAAW,QAAQ;IACvB,MAAM,EAAE,MAAM,CAAC;IACf,UAAU,EAAE,MAAM,CAAC;IACnB,YAAY,EAAE,MAAM,CAAC;CACtB;AAED,MAAM,WAAW,QAAS,SAAQ,IAAI,CAAC,WAAW,EAAE,UAAU,GAAG,SAAS,CAAC;IACzE,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,OAAO,EAAE,KAAK,CAAC,SAAS,CAAC;IACzB,KAAK,CAAC,EAAE,OAAO,CAAC;IAChB,KAAK,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,QAAQ,CAAC,CAAC;IACjC,QAAQ,CAAC,EAAE,QAAQ,EAAE,CAAC;CACvB;AAED,MAAM,WAAW,YAAa,SAAQ,IAAI,CAAC,QAAQ,EAAE,SAAS,GAAG,UAAU,GAAG,QAAQ,CAAC;IACrF,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,MAAM,CAAC;CACd;AAmBD,wBAAgB,gBAAgB,CAAC,MAAM,EAAE,QAAQ,EAAE,EAAE,QAAQ,SAAK,GAAG,YAAY,EAAE,CA4BlF;AAED,wBAAgB,iBAAiB,CAAC,EAAE,SAAS,EAAE,QAAQ,EAAE,EAAE;IAAE,SAAS,CAAC,EAAE,QAAQ,EAAE,CAAC;IAAC,QAAQ,CAAC,EAAE,KAAK,CAAC,SAAS,CAAA;CAAE,2CAoEhH"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"buildSeoForPath.d.ts","sourceRoot":"","sources":["../../../src/runtime/seo/buildSeoForPath.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAc,OAAO,EAAE,MAAM,gCAAgC,CAAC;AAK1E,wBAAgB,aAAa,CAAC,QAAQ,EAAE,MAAM,EAAE,SAAS,CAAC,EAAE,OAAO,GAAG,OAAO,GAAG,SAAS,CAExF;AA+BD,wBAAgB,gBAAgB,CAAC,QAAQ,EAAE,MAAM,EAAE,SAAS,CAAC,EAAE,OAAO;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;KAMrE;AAED,wBAAgB,aAAa,CAAC,IAAI,EAAE;IAAE,QAAQ,EAAE;QAAE,QAAQ,EAAE,MAAM,CAAA;KAAE,CAAC;IAAC,OAAO,EAAE,SAAS,OAAO,EAAE,CAAA;CAAE;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;KAclG"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"htmlProps.d.ts","sourceRoot":"","sources":["../../../src/runtime/seo/htmlProps.ts"],"names":[],"mappings":"AAQA;;;;;GAKG;AACH,wBAAgB,aAAa,CAAC,eAAe,CAAC,EAAE,MAAM,GAAG;IAAE,MAAM,CAAC,EAAE,MAAM,CAAA;CAAE,GAAG;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,GAAG,EAAE,KAAK,GAAG,KAAK,CAAA;CAAE,CAIlH"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/runtime/seo/index.ts"],"names":[],"mappings":"AAEA,cAAc,sBAAsB,CAAC;AACrC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,eAAe,CAAC;AAE9B,wBAAsB,gBAAgB,CAAC,EAAE,OAAO,EAAE,EAAE;IAAE,OAAO,EAAE,OAAO,CAAA;CAAE;;;GAIvE"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"resolver.d.ts","sourceRoot":"","sources":["../../../src/runtime/seo/resolver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CAAC,EAAE,aAAa,CAAC;IACzB,mBAAmB,CAAC,EAAE,OAAO,CAAC;CAC/B;AAED,MAAM,WAAW,cAAc;IAC7B,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,OAAO,CAAC,EAAE,MAAM,EAAE,CAAC;IACnB,OAAO,CAAC,EAAE,qBAAqB,CAAC;CACjC;AAED,MAAM,WAAW,UAAU;IACzB,GAAG,CAAC,EAAE,OAAO,CAAC;IACd,IAAI,CAAC,EAAE,cAAc,CAAC;IACtB,MAAM,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,eAAe,CAAC,CAAC;IACzC,OAAO,CAAC,EAAE,MAAM,GAAG,MAAM,CAAC;CAC3B"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"OptionalTracking.d.ts","sourceRoot":"","sources":["../../../src/runtime/t/OptionalTracking.tsx"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AAE9C,KAAK,iBAAiB,GAAG,OAAO,QAAQ,CAAC;AACzC,KAAK,cAAc,GAAG;IAAE,QAAQ,EAAE,iBAAiB,CAAA;CAAE,CAAC;AACtD,KAAK,cAAc,GAAG,MAAM,OAAO,CAAC,cAAc,CAAC,CAAC;AACpD,KAAK,YAAY,GAAG,UAAU,CAAC,iBAAiB,CAAC,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,MAAM,CAAC,CAAC;AAIvE,wBAAsB,qBAAqB,CAAC,YAAY,GAAE,cAAoC,mCAM7F;AAED,wBAAgB,gBAAgB,CAAC,EAAE,MAAM,EAAE,EAAE;IAAE,MAAM,EAAE,YAAY,EAAE,CAAA;CAAE,kDAoBtE"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"OptionalTracking.test.d.ts","sourceRoot":"","sources":["../../../src/runtime/t/OptionalTracking.test.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { describe, expect, it } from 'vitest';
|
|
2
|
+
import { loadPageviewComponent } from './OptionalTracking.js';
|
|
3
|
+
describe('loadPageviewComponent', () => {
|
|
4
|
+
it('returns the Pageview component when the tracking chunk loads', async () => {
|
|
5
|
+
const Pageview = () => null;
|
|
6
|
+
await expect(loadPageviewComponent(async () => ({ Pageview }))).resolves.toBe(Pageview);
|
|
7
|
+
});
|
|
8
|
+
it('fails closed when the tracking chunk is blocked', async () => {
|
|
9
|
+
await expect(loadPageviewComponent(async () => Promise.reject(new Error('blocked')))).resolves.toBeNull();
|
|
10
|
+
});
|
|
11
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Pageview.d.ts","sourceRoot":"","sources":["../../../src/runtime/t/Pageview.tsx"],"names":[],"mappings":"AAGA,KAAK,YAAY,GAAG;IAClB,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,MAAM,CAAC;CACd,CAAC;AA+HF,wBAAgB,QAAQ,CAAC,EAAE,MAAM,EAAE,EAAE;IAAE,MAAM,EAAE,YAAY,EAAE,CAAA;CAAE,QAkB9D"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"templates.d.ts","sourceRoot":"","sources":["../../src/runtime/templates.ts"],"names":[],"mappings":"AAiCA,eAAO,MAAM,mBAAmB,oDAAqD,CAAC;AACtF,MAAM,MAAM,iBAAiB,GAAG,CAAC,OAAO,mBAAmB,CAAC,CAAC,MAAM,CAAC,CAAC;AACrE,eAAO,MAAM,gBAAgB,EAAE,iBAAkC,CAAC;AAElE;;;;;;;;;GASG;AACH,wBAAgB,eAAe,CAAC,SAAS,GAAE,iBAAoC,GAAG,MAAM,CAEvF;AAED;;;;;;;;;;;;;;;GAeG;AACH,wBAAgB,oBAAoB,IAAI,MAAM,CAM7C;AAqBD,MAAM,WAAW,WAAW;IAC1B,MAAM,EAAE,KAAK,GAAG,KAAK,GAAG,IAAI,CAAC;CAC9B;AAED,MAAM,WAAW,iBAAiB;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AM,GAAG,IAAuB,GAAG,OAAO,CA2B/F"}
|
|
@@ -0,0 +1,212 @@
|
|
|
1
|
+
import { execFileSync } from 'node:child_process';
|
|
2
|
+
import { mkdirSync, mkdtempSync, rmSync, symlinkSync, writeFileSync } from 'node:fs';
|
|
3
|
+
import { createRequire } from 'node:module';
|
|
4
|
+
import { tmpdir } from 'node:os';
|
|
5
|
+
import { dirname, join, resolve } from 'node:path';
|
|
6
|
+
import { fileURLToPath } from 'node:url';
|
|
7
|
+
import { afterAll, describe, expect, it } from 'vitest';
|
|
8
|
+
import { syncSchemas } from './sync-schemas.js';
|
|
9
|
+
/**
|
|
10
|
+
* The generated-types gate: generate hooks + types from fixture schemas that
|
|
11
|
+
* cover every field type and reference shape, add usage code written the way
|
|
12
|
+
* an agent writes site code, and run the real TypeScript compiler over the
|
|
13
|
+
* output. A template regression fails this test — never a user project.
|
|
14
|
+
*/
|
|
15
|
+
const here = dirname(fileURLToPath(import.meta.url));
|
|
16
|
+
const requireFromHere = createRequire(import.meta.url);
|
|
17
|
+
const runtimeBarrel = resolve(here, '../runtime/index.ts');
|
|
18
|
+
const tscBin = requireFromHere.resolve('typescript/bin/tsc');
|
|
19
|
+
const fixtureRoot = mkdtempSync(join(tmpdir(), 'fimo-generated-types-'));
|
|
20
|
+
const schemasDir = join(fixtureRoot, 'src', 'schemas');
|
|
21
|
+
const SCHEMAS = {
|
|
22
|
+
Author: {
|
|
23
|
+
uid: 'Author',
|
|
24
|
+
name: 'Author',
|
|
25
|
+
i18n: { enabled: true },
|
|
26
|
+
fields: {
|
|
27
|
+
name: { type: 'string', required: true },
|
|
28
|
+
bio: { type: 'richtext' },
|
|
29
|
+
avatar: { type: 'media' },
|
|
30
|
+
active: { type: 'boolean' },
|
|
31
|
+
bornAt: { type: 'date' },
|
|
32
|
+
meta: { type: 'json' },
|
|
33
|
+
rating: { type: 'number' },
|
|
34
|
+
},
|
|
35
|
+
},
|
|
36
|
+
Video: {
|
|
37
|
+
uid: 'Video',
|
|
38
|
+
name: 'Video',
|
|
39
|
+
i18n: { enabled: false },
|
|
40
|
+
fields: {
|
|
41
|
+
title: { type: 'string', required: true },
|
|
42
|
+
clips: { type: 'media', multiple: true },
|
|
43
|
+
},
|
|
44
|
+
},
|
|
45
|
+
Post: {
|
|
46
|
+
uid: 'Post',
|
|
47
|
+
name: 'Post',
|
|
48
|
+
i18n: { enabled: true },
|
|
49
|
+
fields: {
|
|
50
|
+
title: { type: 'string', required: true },
|
|
51
|
+
author: { type: 'reference', target: 'Author' },
|
|
52
|
+
contributors: { type: 'reference', target: 'Author', many: true },
|
|
53
|
+
related: { type: 'reference', target: 'Post', many: true },
|
|
54
|
+
},
|
|
55
|
+
},
|
|
56
|
+
Page: {
|
|
57
|
+
uid: 'Page',
|
|
58
|
+
name: 'Page',
|
|
59
|
+
i18n: { enabled: true },
|
|
60
|
+
fields: {
|
|
61
|
+
title: { type: 'string' },
|
|
62
|
+
featured: { type: 'reference', targets: ['Post', 'Video'], many: true },
|
|
63
|
+
hero: { type: 'reference', targets: ['Author', 'Video'] },
|
|
64
|
+
},
|
|
65
|
+
},
|
|
66
|
+
SiteSettings: {
|
|
67
|
+
uid: 'SiteSettings',
|
|
68
|
+
name: 'SiteSettings',
|
|
69
|
+
isSingleton: true,
|
|
70
|
+
i18n: { enabled: false },
|
|
71
|
+
fields: {
|
|
72
|
+
siteName: { type: 'string', required: true },
|
|
73
|
+
},
|
|
74
|
+
},
|
|
75
|
+
};
|
|
76
|
+
const USAGE = `// Agent-style usage of the generated types — compile-time contract.
|
|
77
|
+
import type { PageResult, PageWhere } from "./Page";
|
|
78
|
+
import Post from "./Post";
|
|
79
|
+
import type { PostResult } from "./Post";
|
|
80
|
+
|
|
81
|
+
export function renderFeatured(page: PageResult<undefined, readonly ["featured", "hero"]>): string[] {
|
|
82
|
+
const out: string[] = [];
|
|
83
|
+
for (const item of page.featured) {
|
|
84
|
+
switch (item.$type) {
|
|
85
|
+
case "Post":
|
|
86
|
+
out.push(\`post \${String(item.title)} by \${item.author?.id ?? "nobody"}\`);
|
|
87
|
+
break;
|
|
88
|
+
case "Video":
|
|
89
|
+
out.push(\`video \${String(item.title)} with \${item.clips.length} clip(s)\`);
|
|
90
|
+
break;
|
|
91
|
+
default: {
|
|
92
|
+
const exhaustive: never = item;
|
|
93
|
+
return exhaustive;
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
const hero = page.hero;
|
|
98
|
+
if (hero && hero.$type === "Author") {
|
|
99
|
+
out.push(\`hero \${String(hero.name)}\`);
|
|
100
|
+
}
|
|
101
|
+
return out;
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
export function renderPost(post: PostResult<undefined, readonly ["author", "contributors"]>): string {
|
|
105
|
+
const contributors = post.contributors.map((author) => String(author.name)).join(", ");
|
|
106
|
+
return \`\${String(post.title)} — \${post.author ? String(post.author.name) : "anonymous"} (\${contributors})\`;
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
export function whereContract(): PageWhere {
|
|
110
|
+
return {
|
|
111
|
+
title: "Home",
|
|
112
|
+
// @ts-expect-error filtering on polymorphic reference fields is not supported
|
|
113
|
+
featured: "some-document-id",
|
|
114
|
+
};
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
export function paginatedPostContract(): void {
|
|
118
|
+
const legacy = Post.useGet({ limit: 3 });
|
|
119
|
+
const page = Post.useList({
|
|
120
|
+
fields: ["title", "author"] as const,
|
|
121
|
+
populate: ["author"] as const,
|
|
122
|
+
limit: 12,
|
|
123
|
+
offset: 24,
|
|
124
|
+
});
|
|
125
|
+
const infinite = Post.useInfiniteList({
|
|
126
|
+
fields: ["title", "author"] as const,
|
|
127
|
+
populate: ["author"] as const,
|
|
128
|
+
limit: 12,
|
|
129
|
+
});
|
|
130
|
+
|
|
131
|
+
const legacyPosts: PostResult[] = legacy.data ?? [];
|
|
132
|
+
const pagePosts: PostResult<readonly ["title", "author"], readonly ["author"]>[] = page.data?.items ?? [];
|
|
133
|
+
const total: number = page.data?.pageInfo.total ?? 0;
|
|
134
|
+
const nextOffset: number | null = page.data?.pageInfo.nextOffset ?? null;
|
|
135
|
+
const infinitePosts: PostResult<readonly ["title", "author"], readonly ["author"]>[] = infinite.items;
|
|
136
|
+
const firstAuthorName: string = infinitePosts[0]?.author ? String(infinitePosts[0].author.name) : "";
|
|
137
|
+
const hasMore: boolean = infinite.hasMore;
|
|
138
|
+
const isLoadingMore: boolean = infinite.isLoadingMore;
|
|
139
|
+
|
|
140
|
+
void infinite.loadMore();
|
|
141
|
+
// @ts-expect-error infinite lists own offset progression
|
|
142
|
+
Post.useInfiniteList({ offset: 12 });
|
|
143
|
+
|
|
144
|
+
void [legacyPosts, pagePosts, total, nextOffset, infinitePosts, firstAuthorName, hasMore, isLoadingMore];
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
export async function paginatedPostFetchContract(): Promise<void> {
|
|
148
|
+
const page = await Post.list({ limit: 12, offset: 24 });
|
|
149
|
+
const legacyPosts: PostResult[] = await Post.get({ limit: 3 });
|
|
150
|
+
const pagePosts: PostResult[] = page.items;
|
|
151
|
+
const hasMore: boolean = page.pageInfo.hasMore;
|
|
152
|
+
|
|
153
|
+
void [legacyPosts, pagePosts, hasMore];
|
|
154
|
+
}
|
|
155
|
+
`;
|
|
156
|
+
const SHIMS = `declare module "virtual:fimo-config" {
|
|
157
|
+
const config: Record<string, unknown>;
|
|
158
|
+
export default config;
|
|
159
|
+
}
|
|
160
|
+
declare module "virtual:translations" {
|
|
161
|
+
export const dictionaries: Record<string, Record<string, string>>;
|
|
162
|
+
export const defaultLocale: string;
|
|
163
|
+
export const signature: string;
|
|
164
|
+
export const updatedAt: string;
|
|
165
|
+
}
|
|
166
|
+
declare module "*.css" {}
|
|
167
|
+
`;
|
|
168
|
+
afterAll(() => {
|
|
169
|
+
rmSync(fixtureRoot, { recursive: true, force: true });
|
|
170
|
+
});
|
|
171
|
+
describe('generated types gate', () => {
|
|
172
|
+
it('generates hooks + types for every field shape and the output typechecks with agent-style usage', () => {
|
|
173
|
+
mkdirSync(schemasDir, { recursive: true });
|
|
174
|
+
// Real react-query types: the fixture resolves them like a real project.
|
|
175
|
+
const reactQueryDir = dirname(requireFromHere.resolve('@tanstack/react-query/package.json'));
|
|
176
|
+
mkdirSync(join(fixtureRoot, 'node_modules', '@tanstack'), { recursive: true });
|
|
177
|
+
symlinkSync(reactQueryDir, join(fixtureRoot, 'node_modules', '@tanstack', 'react-query'));
|
|
178
|
+
for (const [uid, schema] of Object.entries(SCHEMAS)) {
|
|
179
|
+
writeFileSync(join(schemasDir, `${uid}.json`), JSON.stringify(schema, null, 2));
|
|
180
|
+
}
|
|
181
|
+
const result = syncSchemas({ cwd: fixtureRoot, verbose: false });
|
|
182
|
+
expect(result.created).toBeGreaterThanOrEqual(Object.keys(SCHEMAS).length * 2);
|
|
183
|
+
writeFileSync(join(schemasDir, 'usage.ts'), USAGE);
|
|
184
|
+
writeFileSync(join(fixtureRoot, 'shims.d.ts'), SHIMS);
|
|
185
|
+
writeFileSync(join(fixtureRoot, 'tsconfig.json'), JSON.stringify({
|
|
186
|
+
compilerOptions: {
|
|
187
|
+
strict: true,
|
|
188
|
+
noEmit: true,
|
|
189
|
+
skipLibCheck: true,
|
|
190
|
+
target: 'ES2022',
|
|
191
|
+
module: 'ESNext',
|
|
192
|
+
moduleResolution: 'bundler',
|
|
193
|
+
jsx: 'react-jsx',
|
|
194
|
+
allowImportingTsExtensions: true,
|
|
195
|
+
baseUrl: '.',
|
|
196
|
+
paths: {
|
|
197
|
+
'fimo/ui': [runtimeBarrel],
|
|
198
|
+
},
|
|
199
|
+
},
|
|
200
|
+
include: ['src/**/*.ts', 'shims.d.ts'],
|
|
201
|
+
}, null, 2));
|
|
202
|
+
let output = '';
|
|
203
|
+
try {
|
|
204
|
+
output = execFileSync(process.execPath, [tscBin, '-p', fixtureRoot], { encoding: 'utf8' });
|
|
205
|
+
}
|
|
206
|
+
catch (error) {
|
|
207
|
+
const failure = error;
|
|
208
|
+
throw new Error(`generated types failed to typecheck:\n${failure.stdout ?? ''}${failure.stderr ?? ''}`);
|
|
209
|
+
}
|
|
210
|
+
expect(output.trim()).toBe('');
|
|
211
|
+
}, 120_000);
|
|
212
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { describe, expect, it } from 'vitest';
|
|
2
|
+
import { lintTranslationKeys } from './lint-translation-keys';
|
|
3
|
+
describe('lintTranslationKeys', () => {
|
|
4
|
+
it('allows literal DB-owned label keys', () => {
|
|
5
|
+
const errors = lintTranslationKeys('src/pages/Index.tsx', "const title = t('hero.title');");
|
|
6
|
+
expect(errors).toEqual([]);
|
|
7
|
+
});
|
|
8
|
+
it('rejects inline fallback values', () => {
|
|
9
|
+
const errors = lintTranslationKeys('src/pages/Index.tsx', "const title = t('hero.title', 'Welcome');");
|
|
10
|
+
expect(errors).toEqual([expect.objectContaining({ rule: 'labels/no-inline-default' })]);
|
|
11
|
+
});
|
|
12
|
+
it('rejects dynamic keys', () => {
|
|
13
|
+
const errors = lintTranslationKeys('src/pages/Index.tsx', 'const title = t(heroKey);');
|
|
14
|
+
expect(errors).toEqual([expect.objectContaining({ rule: 'translation-keys' })]);
|
|
15
|
+
});
|
|
16
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,144 @@
|
|
|
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, beforeEach, describe, expect, it } from 'vitest';
|
|
5
|
+
import { syncSchemas } from './sync-schemas.js';
|
|
6
|
+
let scratch;
|
|
7
|
+
beforeEach(() => {
|
|
8
|
+
scratch = mkdtempSync(join(tmpdir(), 'fimo-sync-schemas-'));
|
|
9
|
+
mkdirSync(join(scratch, 'src/schemas'), { recursive: true });
|
|
10
|
+
});
|
|
11
|
+
afterEach(() => {
|
|
12
|
+
rmSync(scratch, { recursive: true, force: true });
|
|
13
|
+
});
|
|
14
|
+
function writeSchema(name, schema) {
|
|
15
|
+
writeFileSync(join(scratch, 'src/schemas', `${name}.json`), JSON.stringify(schema, null, 2));
|
|
16
|
+
}
|
|
17
|
+
describe('syncSchemas', () => {
|
|
18
|
+
it('generates raw references plus typed populated helpers', () => {
|
|
19
|
+
writeSchema('Author', {
|
|
20
|
+
uid: 'Author',
|
|
21
|
+
name: 'Authors',
|
|
22
|
+
fields: {
|
|
23
|
+
name: { type: 'string' },
|
|
24
|
+
},
|
|
25
|
+
});
|
|
26
|
+
writeSchema('Post', {
|
|
27
|
+
uid: 'Post',
|
|
28
|
+
name: 'Posts',
|
|
29
|
+
fields: {
|
|
30
|
+
title: { type: 'string' },
|
|
31
|
+
author: { type: 'reference', target: 'Author' },
|
|
32
|
+
contributors: { type: 'reference', target: 'Author', many: true },
|
|
33
|
+
relatedPosts: { type: 'reference', target: 'Post', many: true },
|
|
34
|
+
},
|
|
35
|
+
});
|
|
36
|
+
expect(syncSchemas({ cwd: scratch, verbose: false })).toEqual({ created: 4, updated: 0, deleted: 0 });
|
|
37
|
+
const post = readFileSync(join(scratch, 'src/schemas/Post.ts'), 'utf-8');
|
|
38
|
+
const postTypes = readFileSync(join(scratch, 'src/schemas/Post.types.ts'), 'utf-8');
|
|
39
|
+
expect(post).toContain('import { wrapWithSource as wrapAuthorWithSource } from "./Author";');
|
|
40
|
+
expect(post).toContain('isPopulatedEntry(value) ? wrapAuthorWithSource(value) : value');
|
|
41
|
+
expect(post).toContain('function isPopulatedEntry(value: unknown): value is PopulatedEntryRecord');
|
|
42
|
+
expect(post).toContain('import type { Post, PostInput, PostPopulate, PostResult, PostFields, PostQuery } from "./Post.types";');
|
|
43
|
+
expect(post).toContain('from "./Post.types";');
|
|
44
|
+
expect(post).not.toContain('import type { Author } from "./Author";');
|
|
45
|
+
expect(post).not.toContain('export interface Post extends WithReferences<PostReferences>');
|
|
46
|
+
expect(post).not.toContain('type FimoReference');
|
|
47
|
+
expect(post).toContain('Promise<PostResult<undefined, TPopulate>>');
|
|
48
|
+
expect(post).toContain('TPopulate extends PostPopulate | undefined');
|
|
49
|
+
expect(post).toContain('wrapAuthorWithSource(value)');
|
|
50
|
+
expect(post).toContain('wrapWithSource(value)');
|
|
51
|
+
expect(post).toContain('export async function create(payload: PostInput): Promise<Post>');
|
|
52
|
+
expect(post).toContain('export async function getById');
|
|
53
|
+
expect(post).toContain('string | { id: string; locale?: string }');
|
|
54
|
+
expect(post).toContain('typeof value === "string"');
|
|
55
|
+
expect(post).toContain('/entries/Post/');
|
|
56
|
+
expect(post).not.toContain('/v2/entries');
|
|
57
|
+
expect(post).toContain('return wrapWithSource(data.data);');
|
|
58
|
+
expect(post).toContain('mutationFn : (payload) => create(withMutationLocale(payload, activeLocale))');
|
|
59
|
+
expect(post).toContain('mutationFn : ({ id, ...patch }) => update(id, withMutationLocale(patch, activeLocale))');
|
|
60
|
+
expect(post).toContain('qk.byId(vars.id, { locale: vars.locale ?? activeLocale })');
|
|
61
|
+
expect(post).toContain('{ ...value, locale: value.locale ?? activeLocale }');
|
|
62
|
+
expect(postTypes).toContain('import type { Author } from "./Author.types";');
|
|
63
|
+
expect(postTypes).toContain('export interface Post extends WithReferences<PostReferences>');
|
|
64
|
+
expect(postTypes).toContain(' id: string;');
|
|
65
|
+
expect(postTypes).toContain(' entryId: string;');
|
|
66
|
+
expect(postTypes).toContain(' documentId: string;');
|
|
67
|
+
expect(postTypes).toContain(' locale: string;');
|
|
68
|
+
expect(postTypes).toContain('type FimoReference');
|
|
69
|
+
expect(postTypes).toContain('author: FimoReference | null;');
|
|
70
|
+
expect(postTypes).toContain('contributors: FimoReference[];');
|
|
71
|
+
expect(postTypes).toContain('relatedPosts: FimoReference[];');
|
|
72
|
+
expect(postTypes).toContain('export interface PostReferences');
|
|
73
|
+
expect(postTypes).toContain('export interface PostInput');
|
|
74
|
+
expect(postTypes).toContain('author?: FimoReference | null;');
|
|
75
|
+
expect(postTypes).toContain('author: Author | null;');
|
|
76
|
+
expect(postTypes).toContain('contributors: Author[];');
|
|
77
|
+
expect(postTypes).toContain('relatedPosts: Post[];');
|
|
78
|
+
expect(postTypes).toContain('export type PostResult<');
|
|
79
|
+
expect(postTypes).not.toContain('PostPopulated');
|
|
80
|
+
});
|
|
81
|
+
it('generates effective-locale shared types and locale-sensitive populated target keys', () => {
|
|
82
|
+
writeSchema('Homepage', {
|
|
83
|
+
uid: 'Homepage',
|
|
84
|
+
name: 'Homepages',
|
|
85
|
+
fields: { title: { type: 'string' } },
|
|
86
|
+
});
|
|
87
|
+
writeSchema('Category', {
|
|
88
|
+
uid: 'Category',
|
|
89
|
+
name: 'Categories',
|
|
90
|
+
i18n: { enabled: false },
|
|
91
|
+
fields: { name: { type: 'string' } },
|
|
92
|
+
});
|
|
93
|
+
writeSchema('Settings', {
|
|
94
|
+
uid: 'Settings',
|
|
95
|
+
name: 'Settings',
|
|
96
|
+
i18n: { enabled: false },
|
|
97
|
+
fields: {
|
|
98
|
+
homepage: { type: 'reference', target: 'Homepage' },
|
|
99
|
+
category: { type: 'reference', target: 'Category' },
|
|
100
|
+
},
|
|
101
|
+
});
|
|
102
|
+
syncSchemas({ cwd: scratch, verbose: false });
|
|
103
|
+
const settings = readFileSync(join(scratch, 'src/schemas/Settings.ts'), 'utf-8');
|
|
104
|
+
const settingsTypes = readFileSync(join(scratch, 'src/schemas/Settings.types.ts'), 'utf-8');
|
|
105
|
+
const homepageTypes = readFileSync(join(scratch, 'src/schemas/Homepage.types.ts'), 'utf-8');
|
|
106
|
+
expect(settingsTypes).toContain('locale: string;');
|
|
107
|
+
expect(settingsTypes).not.toContain('locale?: string;');
|
|
108
|
+
expect(homepageTypes).toContain('locale: string;');
|
|
109
|
+
expect(settings).toContain('const LOCALIZED_CONTENT = false;');
|
|
110
|
+
expect(settings).toContain('const LOCALIZED_REFERENCE_FIELDS = new Set<string>(["homepage"]);');
|
|
111
|
+
expect(settings).toContain(' locale,');
|
|
112
|
+
expect(settings).toContain('readLocale(params, LOCALIZED_CONTENT, useQueryLocale(params.locale))');
|
|
113
|
+
expect(settings.match(/readLocale\(params, LOCALIZED_CONTENT, useQueryLocale\(params\.locale\)\)/g)?.length).toBe(4);
|
|
114
|
+
expect(settings.match(/const locale = useQueryLocale\(options\.locale\);/g)?.length).toBe(2);
|
|
115
|
+
});
|
|
116
|
+
it('generates singleton document APIs without collection mutations', () => {
|
|
117
|
+
writeSchema('Settings', {
|
|
118
|
+
uid: 'Settings',
|
|
119
|
+
name: 'Settings',
|
|
120
|
+
isSingleton: true,
|
|
121
|
+
i18n: { enabled: false },
|
|
122
|
+
fields: { siteName: { type: 'string', required: true } },
|
|
123
|
+
});
|
|
124
|
+
syncSchemas({ cwd: scratch, verbose: false });
|
|
125
|
+
const settings = readFileSync(join(scratch, 'src/schemas/Settings.ts'), 'utf-8');
|
|
126
|
+
const settingsTypes = readFileSync(join(scratch, 'src/schemas/Settings.types.ts'), 'utf-8');
|
|
127
|
+
expect(settings).toContain('fetch(`${base}${withReadOptions(`/documents/Settings`, options)}`');
|
|
128
|
+
expect(settings).toContain('`Settings.id:${id}:${encodeURIComponent(locale)}`');
|
|
129
|
+
expect(settingsTypes).toContain('id: string;');
|
|
130
|
+
expect(settingsTypes).toContain('entryId: string;');
|
|
131
|
+
expect(settingsTypes).toContain('locale?: string;');
|
|
132
|
+
expect(settings).toContain('export async function update(payload: Partial<SettingsInput>)');
|
|
133
|
+
expect(settings).toContain('mutationFn: (payload) => update(withMutationLocale(payload, activeLocale))');
|
|
134
|
+
expect(settings).toContain('export function useSuspenseGet');
|
|
135
|
+
expect(settings).not.toContain('export async function create(');
|
|
136
|
+
expect(settings).not.toContain('export async function remove(');
|
|
137
|
+
expect(settings).not.toContain('export function useCreate(');
|
|
138
|
+
expect(settings).not.toContain('export function useList(');
|
|
139
|
+
expect(settings).not.toContain('export function useInfiniteList(');
|
|
140
|
+
expect(settings).not.toContain('useInfiniteQuery');
|
|
141
|
+
expect(settingsTypes).toContain('siteName: string;');
|
|
142
|
+
expect(settingsTypes).not.toContain('documentId?: string;');
|
|
143
|
+
});
|
|
144
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
import { mkdirSync, writeFileSync } from 'node:fs';
|
|
2
|
+
import { mkdtempSync, rmSync } from 'node:fs';
|
|
3
|
+
import { tmpdir } from 'node:os';
|
|
4
|
+
import { join } from 'node:path';
|
|
5
|
+
import { afterEach, describe, expect, it } from 'vitest';
|
|
6
|
+
import { validateRouteMetadata } from './validate-route-metadata';
|
|
7
|
+
describe('validateRouteMetadata i18n checks', () => {
|
|
8
|
+
let scratch = null;
|
|
9
|
+
afterEach(() => {
|
|
10
|
+
if (scratch) {
|
|
11
|
+
rmSync(scratch, { recursive: true, force: true });
|
|
12
|
+
scratch = null;
|
|
13
|
+
}
|
|
14
|
+
});
|
|
15
|
+
it('accepts fimoRoutes() with canonical routes and multi-locale path prefixes', () => {
|
|
16
|
+
const cwd = writeProject({
|
|
17
|
+
config: {
|
|
18
|
+
i18n: {
|
|
19
|
+
defaultLocale: 'en',
|
|
20
|
+
locales: ['en', 'es'],
|
|
21
|
+
routing: { strategy: 'path-prefix' },
|
|
22
|
+
},
|
|
23
|
+
routes: {
|
|
24
|
+
home: { path: '/', label: 'Home' },
|
|
25
|
+
pricing: { path: '/pricing', label: 'Pricing' },
|
|
26
|
+
},
|
|
27
|
+
},
|
|
28
|
+
routesSource: `import type { RouteConfig } from '@react-router/dev/routes';
|
|
29
|
+
import { index, route } from '@react-router/dev/routes';
|
|
30
|
+
import { fimoRoutes } from 'fimo/react-router/routes';
|
|
31
|
+
|
|
32
|
+
const routes = [
|
|
33
|
+
index('./pages/Index.tsx', { id: 'home' }),
|
|
34
|
+
route('pricing', './pages/Pricing.tsx', { id: 'pricing' }),
|
|
35
|
+
] satisfies RouteConfig;
|
|
36
|
+
|
|
37
|
+
export default fimoRoutes(routes) satisfies RouteConfig;
|
|
38
|
+
`,
|
|
39
|
+
files: ['src/pages/Index.tsx', 'src/pages/Pricing.tsx'],
|
|
40
|
+
});
|
|
41
|
+
expect(validateRouteMetadata({ cwd }).errors).toEqual([]);
|
|
42
|
+
});
|
|
43
|
+
it('rejects invalid locale config', () => {
|
|
44
|
+
const cwd = writeProject({
|
|
45
|
+
config: {
|
|
46
|
+
i18n: {
|
|
47
|
+
defaultLocale: 'en--US',
|
|
48
|
+
locales: ['es'],
|
|
49
|
+
routing: { strategy: 'path-prefix' },
|
|
50
|
+
},
|
|
51
|
+
routes: {
|
|
52
|
+
home: { path: '/', label: 'Home' },
|
|
53
|
+
},
|
|
54
|
+
},
|
|
55
|
+
routesSource: `import { index } from '@react-router/dev/routes';
|
|
56
|
+
export default [index('./pages/Index.tsx')];
|
|
57
|
+
`,
|
|
58
|
+
files: ['src/pages/Index.tsx'],
|
|
59
|
+
});
|
|
60
|
+
const errors = validateRouteMetadata({ cwd }).errors.join('\n');
|
|
61
|
+
expect(errors).toContain('Invalid i18n.defaultLocale "en--US"');
|
|
62
|
+
expect(errors).toContain('i18n.locales must include i18n.defaultLocale');
|
|
63
|
+
});
|
|
64
|
+
it('rejects canonical routes that claim locale prefixes', () => {
|
|
65
|
+
const cwd = writeProject({
|
|
66
|
+
config: {
|
|
67
|
+
i18n: {
|
|
68
|
+
defaultLocale: 'en',
|
|
69
|
+
locales: ['en', 'es'],
|
|
70
|
+
routing: { strategy: 'path-prefix' },
|
|
71
|
+
},
|
|
72
|
+
routes: {
|
|
73
|
+
spanish: { path: '/es', label: 'Spanish' },
|
|
74
|
+
},
|
|
75
|
+
},
|
|
76
|
+
routesSource: `import { route } from '@react-router/dev/routes';
|
|
77
|
+
export default [route('es', './pages/Spanish.tsx')];
|
|
78
|
+
`,
|
|
79
|
+
files: ['src/pages/Spanish.tsx'],
|
|
80
|
+
});
|
|
81
|
+
const errors = validateRouteMetadata({ cwd }).errors.join('\n');
|
|
82
|
+
expect(errors).toContain('uses reserved locale prefix "es"');
|
|
83
|
+
});
|
|
84
|
+
it('warns as an error when top-level dynamic routes can capture locale URLs without fimoRoutes()', () => {
|
|
85
|
+
const cwd = writeProject({
|
|
86
|
+
config: {
|
|
87
|
+
i18n: {
|
|
88
|
+
defaultLocale: 'en',
|
|
89
|
+
locales: ['en', 'es'],
|
|
90
|
+
routing: { strategy: 'path-prefix' },
|
|
91
|
+
},
|
|
92
|
+
routes: {
|
|
93
|
+
page: { path: '/:slug', label: 'Page', params: { slug: { schema: 'Page', queryField: 'slug' } } },
|
|
94
|
+
},
|
|
95
|
+
},
|
|
96
|
+
routesSource: `import { route } from '@react-router/dev/routes';
|
|
97
|
+
export default [route(':slug', './pages/Page.tsx')];
|
|
98
|
+
`,
|
|
99
|
+
files: ['src/pages/Page.tsx'],
|
|
100
|
+
});
|
|
101
|
+
const errors = validateRouteMetadata({ cwd }).errors.join('\n');
|
|
102
|
+
expect(errors).toContain('top-level dynamic route');
|
|
103
|
+
expect(errors).toContain('fimoRoutes(routes)');
|
|
104
|
+
});
|
|
105
|
+
function writeProject(args) {
|
|
106
|
+
scratch = mkdtempSync(join(tmpdir(), 'fimo-route-metadata-'));
|
|
107
|
+
mkdirSync(join(scratch, 'src'), { recursive: true });
|
|
108
|
+
writeFileSync(join(scratch, 'fimo-config.json'), JSON.stringify(args.config, null, 2));
|
|
109
|
+
writeFileSync(join(scratch, 'src', 'routes.ts'), args.routesSource);
|
|
110
|
+
for (const file of args.files) {
|
|
111
|
+
mkdirSync(join(scratch, file, '..'), { recursive: true });
|
|
112
|
+
writeFileSync(join(scratch, file), 'export default function Page() { return null; }\n');
|
|
113
|
+
}
|
|
114
|
+
return scratch;
|
|
115
|
+
}
|
|
116
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|