@analogjs/platform 3.0.0-beta.6 → 3.0.0-beta.60
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/migrations/migrate-setup-testbed-browser-mode/migrate-setup-testbed-browser-mode.js +1 -2
- package/migrations/migrate-to-separated-plugins/migrate-to-separated-plugins.js +3 -3
- package/migrations/migrate-to-separated-plugins/migrate-to-separated-plugins.js.map +1 -1
- package/migrations/migrate-vitest-builder-aliases/migrate-vitest-builder-aliases.js +3 -3
- package/migrations/migrate-vitest-builder-aliases/migrate-vitest-builder-aliases.js.map +1 -1
- package/migrations/utils/source-edits.js +1 -2
- package/package.json +14 -11
- package/src/index.js +2 -3
- package/src/lib/analog-integration-plugin.js +1 -2
- package/src/lib/clear-client-page-endpoint.js +2 -3
- package/src/lib/content/marked/index.js +1 -2
- package/src/lib/content/marked/marked-content-highlighter.js +1 -2
- package/src/lib/content/marked/marked-setup.service.js +1 -2
- package/src/lib/content/prism/angular.js +1 -2
- package/src/lib/content/prism/index.js +1 -2
- package/src/lib/content/prism/prism-highlighter.js +1 -2
- package/src/lib/content/shiki/index.js +1 -2
- package/src/lib/content/shiki/shiki-highlighter.js +2 -3
- package/src/lib/content/utils/escape-html.js +1 -2
- package/src/lib/content-plugin.js +13 -5
- package/src/lib/content-plugin.js.map +1 -1
- package/src/lib/deps-plugin.d.ts +1 -1
- package/src/lib/deps-plugin.js +13 -10
- package/src/lib/deps-plugin.js.map +1 -1
- package/src/lib/discover-library-routes.d.ts +3 -3
- package/src/lib/discover-library-routes.js +5 -6
- package/src/lib/discover-library-routes.js.map +1 -1
- package/src/lib/get-page-endpoints.d.ts +25 -0
- package/src/lib/get-page-endpoints.js +28 -0
- package/src/lib/get-page-endpoints.js.map +1 -0
- package/src/lib/inject-server-fn-ids.js +1 -2
- package/src/lib/nitro/analog-nitro-plugin.d.ts +6 -6
- package/src/lib/nitro/analog-nitro-plugin.js +119 -51
- package/src/lib/nitro/analog-nitro-plugin.js.map +1 -1
- package/src/lib/nitro/angular-linker-plugin.d.ts +4 -2
- package/src/lib/nitro/angular-linker-plugin.js +25 -40
- package/src/lib/nitro/angular-linker-plugin.js.map +1 -1
- package/src/lib/nitro/build-sitemap.js +3 -4
- package/src/lib/nitro/build-sitemap.js.map +1 -1
- package/src/lib/nitro/debug.js +1 -2
- package/src/lib/nitro/get-content-files.js +1 -2
- package/src/lib/nitro/get-page-handlers.d.ts +4 -19
- package/src/lib/nitro/get-page-handlers.js +10 -28
- package/src/lib/nitro/get-page-handlers.js.map +1 -1
- package/src/lib/nitro/get-server-fn-handlers.js +1 -2
- package/src/lib/nitro/i18n-prerender.d.ts +2 -1
- package/src/lib/nitro/i18n-prerender.js +11 -9
- package/src/lib/nitro/i18n-prerender.js.map +1 -1
- package/src/lib/nitro/page-endpoints-plugin.js +1 -2
- package/src/lib/nitro/post-rendering-hook.js +1 -2
- package/src/lib/nitro/renderers.js +1 -2
- package/src/lib/nitro/server-fn-endpoints.d.ts +3 -1
- package/src/lib/nitro/server-fn-endpoints.js +15 -7
- package/src/lib/nitro/server-fn-endpoints.js.map +1 -1
- package/src/lib/nx-plugin/_virtual/_rolldown/runtime.js +1 -2
- package/src/lib/nx-plugin/executors.json +0 -7
- package/src/lib/nx-plugin/node_modules/.pnpm/es-toolkit@1.45.1/node_modules/es-toolkit/dist/string/camelCase.js +1 -2
- package/src/lib/nx-plugin/node_modules/.pnpm/es-toolkit@1.45.1/node_modules/es-toolkit/dist/string/camelCase.js.map +1 -1
- package/src/lib/nx-plugin/node_modules/.pnpm/es-toolkit@1.45.1/node_modules/es-toolkit/dist/string/capitalize.js +1 -2
- package/src/lib/nx-plugin/node_modules/.pnpm/es-toolkit@1.45.1/node_modules/es-toolkit/dist/string/capitalize.js.map +1 -1
- package/src/lib/nx-plugin/node_modules/.pnpm/es-toolkit@1.45.1/node_modules/es-toolkit/dist/string/words.js +1 -2
- package/src/lib/nx-plugin/node_modules/.pnpm/es-toolkit@1.45.1/node_modules/es-toolkit/dist/string/words.js.map +1 -1
- package/src/lib/nx-plugin/src/builders/vite/vite-build.js +1 -2
- package/src/lib/nx-plugin/src/builders/vite/vite-build.js.map +1 -1
- package/src/lib/nx-plugin/src/builders/vite-dev-server/dev-server.js +1 -2
- package/src/lib/nx-plugin/src/builders/vite-dev-server/dev-server.js.map +1 -1
- package/src/lib/nx-plugin/src/generators/app/compat.d.ts +2 -1
- package/src/lib/nx-plugin/src/generators/app/compat.js +5 -3
- package/src/lib/nx-plugin/src/generators/app/compat.js.map +1 -1
- package/src/lib/nx-plugin/src/generators/app/generator.js +8 -4
- package/src/lib/nx-plugin/src/generators/app/generator.js.map +1 -1
- package/src/lib/nx-plugin/src/generators/app/lib/add-agent-context.js +1 -2
- package/src/lib/nx-plugin/src/generators/app/lib/add-agent-context.js.map +1 -1
- package/src/lib/nx-plugin/src/generators/app/lib/add-analog-project-config.js +1 -2
- package/src/lib/nx-plugin/src/generators/app/lib/add-analog-project-config.js.map +1 -1
- package/src/lib/nx-plugin/src/generators/app/lib/add-angular-app.js +13 -3
- package/src/lib/nx-plugin/src/generators/app/lib/add-angular-app.js.map +1 -1
- package/src/lib/nx-plugin/src/generators/app/lib/add-files.js +1 -2
- package/src/lib/nx-plugin/src/generators/app/lib/add-files.js.map +1 -1
- package/src/lib/nx-plugin/src/generators/app/lib/add-home-page.js +1 -2
- package/src/lib/nx-plugin/src/generators/app/lib/add-home-page.js.map +1 -1
- package/src/lib/nx-plugin/src/generators/app/lib/add-tailwind-config.js +1 -2
- package/src/lib/nx-plugin/src/generators/app/lib/add-tailwind-config.js.map +1 -1
- package/src/lib/nx-plugin/src/generators/app/lib/add-tailwind-helpers.js +3 -4
- package/src/lib/nx-plugin/src/generators/app/lib/add-tailwind-helpers.js.map +1 -1
- package/src/lib/nx-plugin/src/generators/app/lib/cleanup-files.js +1 -2
- package/src/lib/nx-plugin/src/generators/app/lib/update-index-html.js +1 -2
- package/src/lib/nx-plugin/src/generators/app/lib/update-index-html.js.map +1 -1
- package/src/lib/nx-plugin/src/generators/app/versions/minimum-supported-versions.d.ts +3 -1
- package/src/lib/nx-plugin/src/generators/app/versions/minimum-supported-versions.js +6 -3
- package/src/lib/nx-plugin/src/generators/app/versions/minimum-supported-versions.js.map +1 -1
- package/src/lib/nx-plugin/src/generators/app/versions/tailwind-dependencies.js +1 -2
- package/src/lib/nx-plugin/src/generators/app/versions/tailwind-dependencies.js.map +1 -1
- package/src/lib/nx-plugin/src/generators/app/versions/versions.js +1 -2
- package/src/lib/nx-plugin/src/generators/init/compat.d.ts +2 -1
- package/src/lib/nx-plugin/src/generators/init/compat.js +5 -3
- package/src/lib/nx-plugin/src/generators/init/compat.js.map +1 -1
- package/src/lib/nx-plugin/src/generators/init/files/src/server/routes/api/v1/hello.ts__template__ +2 -2
- package/src/lib/nx-plugin/src/generators/init/files/vite.config.ts__template__ +5 -1
- package/src/lib/nx-plugin/src/generators/init/generator.js +1 -2
- package/src/lib/nx-plugin/src/generators/init/generator.js.map +1 -1
- package/src/lib/nx-plugin/src/generators/init/lib/add-analog-dependencies.js +3 -4
- package/src/lib/nx-plugin/src/generators/init/lib/add-analog-dependencies.js.map +1 -1
- package/src/lib/nx-plugin/src/generators/init/lib/update-app-tsconfig.js +1 -2
- package/src/lib/nx-plugin/src/generators/init/lib/update-app-tsconfig.js.map +1 -1
- package/src/lib/nx-plugin/src/generators/init/lib/update-build-target.js +1 -2
- package/src/lib/nx-plugin/src/generators/init/lib/update-build-target.js.map +1 -1
- package/src/lib/nx-plugin/src/generators/init/lib/update-git-ignore.js +1 -2
- package/src/lib/nx-plugin/src/generators/init/lib/update-index-html.js +1 -2
- package/src/lib/nx-plugin/src/generators/init/lib/update-index-html.js.map +1 -1
- package/src/lib/nx-plugin/src/generators/init/lib/update-main.js +1 -2
- package/src/lib/nx-plugin/src/generators/init/lib/update-main.js.map +1 -1
- package/src/lib/nx-plugin/src/generators/init/lib/update-package-json.js +1 -2
- package/src/lib/nx-plugin/src/generators/init/lib/update-package-json.js.map +1 -1
- package/src/lib/nx-plugin/src/generators/init/lib/update-serve-target.js +1 -2
- package/src/lib/nx-plugin/src/generators/init/lib/update-serve-target.js.map +1 -1
- package/src/lib/nx-plugin/src/generators/init/lib/update-test-target.js +1 -2
- package/src/lib/nx-plugin/src/generators/init/lib/update-test-target.js.map +1 -1
- package/src/lib/nx-plugin/src/generators/init/lib/update-test-tsconfig.js +1 -2
- package/src/lib/nx-plugin/src/generators/init/lib/update-test-tsconfig.js.map +1 -1
- package/src/lib/nx-plugin/src/generators/page/compat.d.ts +2 -1
- package/src/lib/nx-plugin/src/generators/page/compat.js +5 -3
- package/src/lib/nx-plugin/src/generators/page/compat.js.map +1 -1
- package/src/lib/nx-plugin/src/generators/page/generator.js +1 -2
- package/src/lib/nx-plugin/src/generators/page/generator.js.map +1 -1
- package/src/lib/nx-plugin/src/generators/preset/__snapshots__/generator.spec.ts.snap +4 -0
- package/src/lib/nx-plugin/src/generators/preset/generator.js +6 -4
- package/src/lib/nx-plugin/src/generators/preset/generator.js.map +1 -1
- package/src/lib/nx-plugin/src/utils/version-utils.js +1 -2
- package/src/lib/nx-plugin/src/utils/version-utils.js.map +1 -1
- package/src/lib/nx-plugin/src/utils/versions/dependencies.d.ts +1 -1
- package/src/lib/nx-plugin/src/utils/versions/dependencies.js +2 -2
- package/src/lib/nx-plugin/src/utils/versions/dependencies.js.map +1 -1
- package/src/lib/nx-plugin/src/utils/versions/dev-dependencies.d.ts +2 -2
- package/src/lib/nx-plugin/src/utils/versions/dev-dependencies.js +9 -5
- package/src/lib/nx-plugin/src/utils/versions/dev-dependencies.js.map +1 -1
- package/src/lib/nx-plugin/src/utils/versions/versions.d.ts +9 -6
- package/src/lib/nx-plugin/src/utils/versions/versions.js +14 -9
- package/src/lib/nx-plugin/src/utils/versions/versions.js.map +1 -1
- package/src/lib/options.d.ts +16 -0
- package/src/lib/platform-plugin.js +3 -2
- package/src/lib/platform-plugin.js.map +1 -1
- package/src/lib/route-file-discovery.js +9 -6
- package/src/lib/route-file-discovery.js.map +1 -1
- package/src/lib/route-idiom-diagnostics.js +24 -10
- package/src/lib/route-idiom-diagnostics.js.map +1 -1
- package/src/lib/route-manifest.d.ts +1 -1
- package/src/lib/route-manifest.js +7 -8
- package/src/lib/route-manifest.js.map +1 -1
- package/src/lib/router-plugin.js +8 -5
- package/src/lib/router-plugin.js.map +1 -1
- package/src/lib/server-fn-client-transform.js +1 -2
- package/src/lib/server-fn-id.js +1 -2
- package/src/lib/server-plugin.d.ts +9 -0
- package/src/lib/server-plugin.js +169 -0
- package/src/lib/server-plugin.js.map +1 -0
- package/src/lib/ssr/defer-streaming-plugin.js +0 -1
- package/src/lib/ssr/inject-html-plugin.js +1 -2
- package/src/lib/ssr/ssr-build-plugin.js +1 -2
- package/src/lib/typed-routes-plugin.js +7 -7
- package/src/lib/typed-routes-plugin.js.map +1 -1
- package/src/lib/utils/debug-harness.js +1 -2
- package/src/lib/utils/debug-log-file.js +1 -2
- package/src/lib/utils/debug.js +1 -2
- package/src/lib/utils/rolldown.js +1 -2
- package/src/server-mode-plugin.js +2 -2
- package/src/server-mode-plugin.js.map +1 -1
- package/src/lib/nx-plugin/src/executors/vite-dev-server/compat.d.ts +0 -3
- package/src/lib/nx-plugin/src/executors/vite-dev-server/compat.js +0 -7
- package/src/lib/nx-plugin/src/executors/vite-dev-server/compat.js.map +0 -1
- package/src/lib/nx-plugin/src/executors/vite-dev-server/schema.d.ts +0 -1
- package/src/lib/nx-plugin/src/executors/vite-dev-server/schema.json +0 -101
- package/src/lib/nx-plugin/src/executors/vite-dev-server/vite-dev-server.impl.d.ts +0 -2
- package/src/lib/nx-plugin/src/executors/vite-dev-server/vite-dev-server.impl.js +0 -6
- package/src/lib/nx-plugin/src/executors/vite-dev-server/vite-dev-server.impl.js.map +0 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"platform-plugin.js","names":[],"sources":["../../../src/lib/platform-plugin.ts"],"sourcesContent":["import { createRequire } from 'node:module';\nimport { join } from 'node:path';\nimport { Plugin } from 'vite';\n\nimport { Options } from './options.js';\nimport {\n activateDeferredDebug,\n applyDebugOption,\n debugPlatform,\n} from './utils/debug.js';\nimport { routerPlugin } from './router-plugin.js';\nimport { analogIntegrationPlugin } from './analog-integration-plugin.js';\nimport {\n i18nDefRegistryPlugin,\n ssrBuildPlugin,\n} from './ssr/ssr-build-plugin.js';\nimport { contentPlugin } from './content-plugin.js';\nimport { clearClientPageEndpointsPlugin } from './clear-client-page-endpoint.js';\nimport { depsPlugin } from './deps-plugin.js';\nimport { injectHTMLPlugin } from './ssr/inject-html-plugin.js';\nimport {\n deferStreamingPlugin,\n MIN_STREAMING_ANGULAR_MAJOR,\n streamingSupportedOnAngular,\n} from './ssr/defer-streaming-plugin.js';\nimport { serverModePlugin } from '../server-mode-plugin.js';\nimport { typedRoutes } from './typed-routes-plugin.js';\nimport { analogNitroPlugin } from './nitro/analog-nitro-plugin.js';\n\n/**\n * The installed `@angular/core` major version, resolved from the workspace root\n * (where the app's Angular is installed). Returns `null` when it cannot be\n * detected, in which case streaming is not blocked and the build-time\n * anchor-drift detection is relied on instead.\n */\nfunction getAngularCoreMajor(workspaceRoot: string): number | null {\n try {\n const req = createRequire(join(workspaceRoot, 'noop.js'));\n const { version } = req('@angular/core/package.json') as {\n version: string;\n };\n const major = Number.parseInt(version.split('.')[0], 10);\n return Number.isNaN(major) ? null : major;\n } catch {\n return null;\n }\n}\n\nexport function platformPlugin(opts: Options = {}): Plugin[] {\n applyDebugOption(opts.debug, opts.workspaceRoot);\n\n const isTest = process.env['NODE_ENV'] === 'test' || !!process.env['VITEST'];\n const { ...platformOptions } = {\n ssr: true,\n ...opts,\n };\n\n // Streaming patches the compiled @angular/core, which needs a supported\n // Angular version. Turn it off otherwise so the renderer stays buffered.\n if (platformOptions.ssr && platformOptions.experimental?.streaming) {\n const major = getAngularCoreMajor(\n platformOptions.workspaceRoot ?? process.cwd(),\n );\n if (!streamingSupportedOnAngular(major)) {\n console.warn(\n `[@analogjs/platform] experimental.streaming requires Angular ` +\n `${MIN_STREAMING_ANGULAR_MAJOR}+ (detected v${major}); streaming is ` +\n `disabled and rendering falls back to buffered SSR.`,\n );\n platformOptions.experimental = {\n ...platformOptions.experimental,\n streaming: false,\n };\n }\n }\n\n debugPlatform('experimental options resolved', {\n typedRouting: platformOptions.experimental?.typedRouting,\n });\n\n return [\n ...(platformOptions.experimental?.typedRouting\n ? [\n typedRoutes({\n ...(typeof platformOptions.experimental.typedRouting === 'object'\n ? platformOptions.experimental.typedRouting\n : {}),\n workspaceRoot: platformOptions.workspaceRoot,\n additionalPagesDirs: platformOptions.additionalPagesDirs,\n additionalContentDirs: platformOptions.additionalContentDirs,\n }),\n ]\n : []),\n {\n name: 'analogjs-debug-activate',\n config(_, { command }) {\n activateDeferredDebug(command);\n },\n },\n // `nitro()` from `@analogjs/vite-plugin-nitro` reads these as its defaults.\n {\n name: '@analogjs/platform-options',\n api: { analogOptions: platformOptions },\n },\n ...(!isTest ? [analogNitroPlugin(platformOptions)] : []),\n ...(platformOptions.ssr\n ? [...ssrBuildPlugin(), ...injectHTMLPlugin()]\n : []),\n ...(platformOptions.ssr && platformOptions.experimental?.streaming\n ? [deferStreamingPlugin()]\n : []),\n ...(!isTest ? depsPlugin(platformOptions) : []),\n ...routerPlugin(platformOptions),\n analogIntegrationPlugin(platformOptions),\n ...contentPlugin(platformOptions?.content, platformOptions),\n ...(platformOptions.i18n ? [i18nDefRegistryPlugin()] : []),\n ...serverModePlugin(platformOptions.entryServer),\n clearClientPageEndpointsPlugin(),\n ];\n}\n"],"mappings":"
|
|
1
|
+
{"version":3,"file":"platform-plugin.js","names":[],"sources":["../../../src/lib/platform-plugin.ts"],"sourcesContent":["import { createRequire } from 'node:module';\nimport { join } from 'node:path';\nimport { Plugin } from 'vite';\n\nimport { Options } from './options.js';\nimport {\n activateDeferredDebug,\n applyDebugOption,\n debugPlatform,\n} from './utils/debug.js';\nimport { routerPlugin } from './router-plugin.js';\nimport { analogIntegrationPlugin } from './analog-integration-plugin.js';\nimport {\n i18nDefRegistryPlugin,\n ssrBuildPlugin,\n} from './ssr/ssr-build-plugin.js';\nimport { contentPlugin } from './content-plugin.js';\nimport { clearClientPageEndpointsPlugin } from './clear-client-page-endpoint.js';\nimport { depsPlugin } from './deps-plugin.js';\nimport { injectHTMLPlugin } from './ssr/inject-html-plugin.js';\nimport {\n deferStreamingPlugin,\n MIN_STREAMING_ANGULAR_MAJOR,\n streamingSupportedOnAngular,\n} from './ssr/defer-streaming-plugin.js';\nimport { serverModePlugin } from '../server-mode-plugin.js';\nimport { typedRoutes } from './typed-routes-plugin.js';\nimport { analogNitroPlugin } from './nitro/analog-nitro-plugin.js';\nimport { serverPlugin } from './server-plugin.js';\n\n/**\n * The installed `@angular/core` major version, resolved from the workspace root\n * (where the app's Angular is installed). Returns `null` when it cannot be\n * detected, in which case streaming is not blocked and the build-time\n * anchor-drift detection is relied on instead.\n */\nfunction getAngularCoreMajor(workspaceRoot: string): number | null {\n try {\n const req = createRequire(join(workspaceRoot, 'noop.js'));\n const { version } = req('@angular/core/package.json') as {\n version: string;\n };\n const major = Number.parseInt(version.split('.')[0], 10);\n return Number.isNaN(major) ? null : major;\n } catch {\n return null;\n }\n}\n\nexport function platformPlugin(opts: Options = {}): Plugin[] {\n applyDebugOption(opts.debug, opts.workspaceRoot);\n\n const isTest = process.env['NODE_ENV'] === 'test' || !!process.env['VITEST'];\n const { ...platformOptions } = {\n ssr: true,\n ...opts,\n };\n\n // Streaming patches the compiled @angular/core, which needs a supported\n // Angular version. Turn it off otherwise so the renderer stays buffered.\n if (platformOptions.ssr && platformOptions.experimental?.streaming) {\n const major = getAngularCoreMajor(\n platformOptions.workspaceRoot ?? process.cwd(),\n );\n if (!streamingSupportedOnAngular(major)) {\n console.warn(\n `[@analogjs/platform] experimental.streaming requires Angular ` +\n `${MIN_STREAMING_ANGULAR_MAJOR}+ (detected v${major}); streaming is ` +\n `disabled and rendering falls back to buffered SSR.`,\n );\n platformOptions.experimental = {\n ...platformOptions.experimental,\n streaming: false,\n };\n }\n }\n\n debugPlatform('experimental options resolved', {\n typedRouting: platformOptions.experimental?.typedRouting,\n });\n\n return [\n ...(platformOptions.experimental?.typedRouting\n ? [\n typedRoutes({\n ...(typeof platformOptions.experimental.typedRouting === 'object'\n ? platformOptions.experimental.typedRouting\n : {}),\n workspaceRoot: platformOptions.workspaceRoot,\n additionalPagesDirs: platformOptions.additionalPagesDirs,\n additionalContentDirs: platformOptions.additionalContentDirs,\n }),\n ]\n : []),\n {\n name: 'analogjs-debug-activate',\n config(_, { command }) {\n activateDeferredDebug(command);\n },\n },\n // `nitro()` from `@analogjs/vite-plugin-nitro` reads these as its defaults.\n {\n name: '@analogjs/platform-options',\n api: { analogOptions: platformOptions },\n },\n ...(!isTest ? [analogNitroPlugin(platformOptions)] : []),\n ...(platformOptions.server && !isTest\n ? [serverPlugin(platformOptions.server, platformOptions)]\n : []),\n ...(platformOptions.ssr\n ? [...ssrBuildPlugin(), ...injectHTMLPlugin()]\n : []),\n ...(platformOptions.ssr && platformOptions.experimental?.streaming\n ? [deferStreamingPlugin()]\n : []),\n ...(!isTest ? depsPlugin(platformOptions) : []),\n ...routerPlugin(platformOptions),\n analogIntegrationPlugin(platformOptions),\n ...contentPlugin(platformOptions?.content, platformOptions),\n ...(platformOptions.i18n ? [i18nDefRegistryPlugin()] : []),\n ...serverModePlugin(platformOptions.entryServer),\n clearClientPageEndpointsPlugin(),\n ];\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;AAoCA,SAAS,oBAAoB,eAAsC;CACjE,IAAI;EAEF,MAAM,EAAE,YADI,cAAc,KAAK,eAAe,SAAS,CACnC,CAAA,CAAI,4BAA4B;EAGpD,MAAM,QAAQ,OAAO,SAAS,QAAQ,MAAM,GAAG,CAAC,CAAC,IAAI,EAAE;EACvD,OAAO,OAAO,MAAM,KAAK,IAAI,OAAO;CACtC,QAAQ;EACN,OAAO;CACT;AACF;AAEA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;EAC7C,GAAG,aAAa,eAAe;EAC/B,wBAAwB,eAAe;EACvC,GAAG,cAAc,iBAAiB,SAAS,eAAe;EAC1D,GAAI,gBAAgB,OAAO,CAAC,sBAAsB,CAAC,IAAI,CAAC;EACxD,GAAG,iBAAiB,gBAAgB,WAAW;EAC/C,+BAA+B;CACjC;AACF"}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { resolve } from "node:path";
|
|
2
2
|
import { normalizePath } from "vite";
|
|
3
3
|
import { globSync } from "tinyglobby";
|
|
4
|
-
|
|
4
|
+
// packages/platform/src/lib/route-file-discovery.ts
|
|
5
5
|
function createRouteFileDiscovery(options) {
|
|
6
6
|
const { root, workspaceRoot, additionalPagesDirs, additionalContentDirs } = options;
|
|
7
7
|
let routeFilesCache = /* @__PURE__ */ new Set();
|
|
@@ -20,9 +20,13 @@ function createRouteFileDiscovery(options) {
|
|
|
20
20
|
function isWithinDir(path, dir) {
|
|
21
21
|
return path === dir || path.startsWith(`${dir}/`);
|
|
22
22
|
}
|
|
23
|
+
/** Page route files: `.page.ts`, or `.page.tsrx` for TSRX components. */
|
|
24
|
+
function isPageFile(path) {
|
|
25
|
+
return path.endsWith(".page.ts") || path.endsWith(".page.tsrx");
|
|
26
|
+
}
|
|
23
27
|
function getAppLocalFileKind(path) {
|
|
24
28
|
if (path.endsWith(".md") && ["src/app/pages", "src/content"].some((dir) => isWithinDir(path, `${root}/${dir}`))) return "content";
|
|
25
|
-
if (path
|
|
29
|
+
if (isPageFile(path) && isWithinDir(path, `${root}/src/app/pages`)) return "route";
|
|
26
30
|
return null;
|
|
27
31
|
}
|
|
28
32
|
function getDiscoveredFileKind(path) {
|
|
@@ -30,13 +34,13 @@ function createRouteFileDiscovery(options) {
|
|
|
30
34
|
const localKind = getAppLocalFileKind(normalized);
|
|
31
35
|
if (localKind) return localKind;
|
|
32
36
|
if (normalized.endsWith(".md") && additionalContentRoots.some((dir) => isWithinDir(normalized, dir))) return "content";
|
|
33
|
-
if (normalized
|
|
37
|
+
if (isPageFile(normalized) && additionalPagesRoots.some((dir) => isWithinDir(normalized, dir))) return "route";
|
|
34
38
|
if (normalized.endsWith(".server.ts") && [`${root}/src/app/pages`, ...additionalPagesRoots].some((dir) => isWithinDir(normalized, dir))) return "server";
|
|
35
39
|
return null;
|
|
36
40
|
}
|
|
37
41
|
function scanRouteFiles() {
|
|
38
|
-
const appLocalGlobs = [`${root}/src/app/pages/**/*.page.ts`];
|
|
39
|
-
const additionalGlobs = additionalPagesDirs.
|
|
42
|
+
const appLocalGlobs = [`${root}/src/app/pages/**/*.page.ts`, `${root}/src/app/pages/**/*.page.tsrx`];
|
|
43
|
+
const additionalGlobs = additionalPagesDirs.flatMap((dir) => [`${joinDir(dir)}/**/*.page.ts`, `${joinDir(dir)}/**/*.page.tsrx`]);
|
|
40
44
|
const appLocal = globSync(appLocalGlobs, {
|
|
41
45
|
dot: true,
|
|
42
46
|
absolute: true
|
|
@@ -107,7 +111,6 @@ function createRouteFileDiscovery(options) {
|
|
|
107
111
|
}
|
|
108
112
|
};
|
|
109
113
|
}
|
|
110
|
-
//#endregion
|
|
111
114
|
export { createRouteFileDiscovery };
|
|
112
115
|
|
|
113
116
|
//# sourceMappingURL=route-file-discovery.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"route-file-discovery.js","names":[],"sources":["../../../src/lib/route-file-discovery.ts"],"sourcesContent":["import { normalizePath } from 'vite';\nimport { resolve } from 'node:path';\nimport { globSync } from 'tinyglobby';\n\nexport interface RouteFileDiscoveryOptions {\n root: string;\n workspaceRoot: string;\n additionalPagesDirs: string[];\n additionalContentDirs: string[];\n}\n\nexport type RouteFileKind = 'route' | 'content' | 'server';\n\nexport interface RouteFileDiscovery {\n getRouteFiles(): string[];\n getContentFiles(): string[];\n /** `server` marks page `.server.ts` files, which affect `load` types only. */\n getDiscoveredFileKind(path: string): RouteFileKind | null;\n updateDiscoveredFile(path: string, event: 'add' | 'change' | 'unlink'): void;\n /**\n * Returns true if the normalized filename was discovered from an app-local\n * glob (under the configured root) rather than from an additional directory.\n *\n * Used by collision priority to prefer app-local routes over shared/external\n * routes based on actual configured roots instead of hard-coded path\n * substrings.\n */\n isAppLocal(normalizedFilename: string): boolean;\n reset(): void;\n}\n\nexport function createRouteFileDiscovery(\n options: RouteFileDiscoveryOptions,\n): RouteFileDiscovery {\n const { root, workspaceRoot, additionalPagesDirs, additionalContentDirs } =\n options;\n\n let routeFilesCache = new Set<string>();\n let contentFilesCache = new Set<string>();\n let appLocalFilesCache = new Set<string>();\n let initialized = false;\n const joinDir = (dir: string) =>\n isWithinDir(dir, workspaceRoot)\n ? normalizePath(dir)\n : dir.startsWith('/')\n ? normalizePath(`${workspaceRoot}${dir}`)\n : normalizePath(resolve(workspaceRoot, dir));\n const additionalPagesRoots = additionalPagesDirs.map(joinDir);\n const additionalContentRoots = additionalContentDirs.map(joinDir);\n\n function normalizePath_(absolutePath: string): string {\n const normalized = normalizePath(absolutePath);\n if (isWithinDir(normalized, root)) {\n return normalized.slice(root.length);\n }\n if (isWithinDir(normalized, workspaceRoot)) {\n return normalized.slice(workspaceRoot.length);\n }\n return normalized;\n }\n\n function isWithinDir(path: string, dir: string): boolean {\n return path === dir || path.startsWith(`${dir}/`);\n }\n\n function getAppLocalFileKind(path: string): 'route' | 'content' | null {\n if (\n path.endsWith('.md') &&\n ['src/app/pages', 'src/content'].some((dir) =>\n isWithinDir(path, `${root}/${dir}`),\n )\n )\n return 'content';\n if (path
|
|
1
|
+
{"version":3,"file":"route-file-discovery.js","names":[],"sources":["../../../src/lib/route-file-discovery.ts"],"sourcesContent":["import { normalizePath } from 'vite';\nimport { resolve } from 'node:path';\nimport { globSync } from 'tinyglobby';\n\nexport interface RouteFileDiscoveryOptions {\n root: string;\n workspaceRoot: string;\n additionalPagesDirs: string[];\n additionalContentDirs: string[];\n}\n\nexport type RouteFileKind = 'route' | 'content' | 'server';\n\nexport interface RouteFileDiscovery {\n getRouteFiles(): string[];\n getContentFiles(): string[];\n /** `server` marks page `.server.ts` files, which affect `load` types only. */\n getDiscoveredFileKind(path: string): RouteFileKind | null;\n updateDiscoveredFile(path: string, event: 'add' | 'change' | 'unlink'): void;\n /**\n * Returns true if the normalized filename was discovered from an app-local\n * glob (under the configured root) rather than from an additional directory.\n *\n * Used by collision priority to prefer app-local routes over shared/external\n * routes based on actual configured roots instead of hard-coded path\n * substrings.\n */\n isAppLocal(normalizedFilename: string): boolean;\n reset(): void;\n}\n\nexport function createRouteFileDiscovery(\n options: RouteFileDiscoveryOptions,\n): RouteFileDiscovery {\n const { root, workspaceRoot, additionalPagesDirs, additionalContentDirs } =\n options;\n\n let routeFilesCache = new Set<string>();\n let contentFilesCache = new Set<string>();\n let appLocalFilesCache = new Set<string>();\n let initialized = false;\n const joinDir = (dir: string) =>\n isWithinDir(dir, workspaceRoot)\n ? normalizePath(dir)\n : dir.startsWith('/')\n ? normalizePath(`${workspaceRoot}${dir}`)\n : normalizePath(resolve(workspaceRoot, dir));\n const additionalPagesRoots = additionalPagesDirs.map(joinDir);\n const additionalContentRoots = additionalContentDirs.map(joinDir);\n\n function normalizePath_(absolutePath: string): string {\n const normalized = normalizePath(absolutePath);\n if (isWithinDir(normalized, root)) {\n return normalized.slice(root.length);\n }\n if (isWithinDir(normalized, workspaceRoot)) {\n return normalized.slice(workspaceRoot.length);\n }\n return normalized;\n }\n\n function isWithinDir(path: string, dir: string): boolean {\n return path === dir || path.startsWith(`${dir}/`);\n }\n\n /** Page route files: `.page.ts`, or `.page.tsrx` for TSRX components. */\n function isPageFile(path: string): boolean {\n return path.endsWith('.page.ts') || path.endsWith('.page.tsrx');\n }\n\n function getAppLocalFileKind(path: string): 'route' | 'content' | null {\n if (\n path.endsWith('.md') &&\n ['src/app/pages', 'src/content'].some((dir) =>\n isWithinDir(path, `${root}/${dir}`),\n )\n )\n return 'content';\n if (isPageFile(path) && isWithinDir(path, `${root}/src/app/pages`))\n return 'route';\n return null;\n }\n\n function getDiscoveredFileKind(path: string): RouteFileKind | null {\n const normalized = normalizePath(path);\n const localKind = getAppLocalFileKind(normalized);\n if (localKind) return localKind;\n if (\n normalized.endsWith('.md') &&\n additionalContentRoots.some((dir) => isWithinDir(normalized, dir))\n ) {\n return 'content';\n }\n if (\n isPageFile(normalized) &&\n additionalPagesRoots.some((dir) => isWithinDir(normalized, dir))\n ) {\n return 'route';\n }\n if (\n normalized.endsWith('.server.ts') &&\n [`${root}/src/app/pages`, ...additionalPagesRoots].some((dir) =>\n isWithinDir(normalized, dir),\n )\n ) {\n return 'server';\n }\n return null;\n }\n\n function scanRouteFiles(): string[] {\n const appLocalGlobs = [\n `${root}/src/app/pages/**/*.page.ts`,\n `${root}/src/app/pages/**/*.page.tsrx`,\n ];\n const additionalGlobs = additionalPagesDirs.flatMap((dir) => [\n `${joinDir(dir)}/**/*.page.ts`,\n `${joinDir(dir)}/**/*.page.tsrx`,\n ]);\n\n const appLocal = globSync(appLocalGlobs, {\n dot: true,\n absolute: true,\n }).map(normalizePath_);\n\n const additional = globSync(additionalGlobs, {\n dot: true,\n absolute: true,\n }).map(normalizePath_);\n\n for (const f of appLocal) {\n appLocalFilesCache.add(f);\n }\n\n return [...appLocal, ...additional];\n }\n\n function scanContentFiles(): string[] {\n const appLocalGlobs = [\n `${root}/src/app/pages/**/*.md`,\n `${root}/src/content/**/*.md`,\n ];\n const additionalGlobs = additionalContentDirs.map(\n (dir) => `${joinDir(dir)}/**/*.md`,\n );\n\n const appLocal = globSync(appLocalGlobs, {\n dot: true,\n absolute: true,\n }).map(normalizePath_);\n\n const additional = globSync(additionalGlobs, {\n dot: true,\n absolute: true,\n }).map(normalizePath_);\n\n for (const f of appLocal) {\n appLocalFilesCache.add(f);\n }\n\n return [...appLocal, ...additional];\n }\n\n function isAppLocalByPath(absolutePath: string): boolean {\n const normalized = normalizePath(absolutePath);\n return getAppLocalFileKind(normalized) !== null;\n }\n\n function ensureInitialized(): void {\n if (initialized) {\n return;\n }\n\n routeFilesCache = new Set(scanRouteFiles());\n contentFilesCache = new Set(scanContentFiles());\n initialized = true;\n }\n\n return {\n getRouteFiles(): string[] {\n ensureInitialized();\n return [...routeFilesCache].sort();\n },\n\n getContentFiles(): string[] {\n ensureInitialized();\n return [...contentFilesCache].sort();\n },\n\n getDiscoveredFileKind(path: string): RouteFileKind | null {\n return getDiscoveredFileKind(path);\n },\n\n updateDiscoveredFile(\n path: string,\n event: 'add' | 'change' | 'unlink',\n ): void {\n ensureInitialized();\n const kind = getDiscoveredFileKind(path);\n if (!kind || kind === 'server') {\n return;\n }\n\n const normalizedPath = normalizePath_(path);\n const targetCache =\n kind === 'content' ? contentFilesCache : routeFilesCache;\n\n if (event === 'unlink') {\n targetCache.delete(normalizedPath);\n appLocalFilesCache.delete(normalizedPath);\n return;\n }\n\n targetCache.add(normalizedPath);\n if (isAppLocalByPath(path)) {\n appLocalFilesCache.add(normalizedPath);\n }\n },\n\n isAppLocal(normalizedFilename: string): boolean {\n ensureInitialized();\n return appLocalFilesCache.has(normalizedFilename);\n },\n\n reset(): void {\n initialized = false;\n appLocalFilesCache = new Set<string>();\n },\n };\n}\n"],"mappings":";;;;AA+BA,SAAgB,yBACd,SACoB;CACpB,MAAM,EAAE,MAAM,eAAe,qBAAqB,0BAChD;CAEF,IAAI,kCAAkB,IAAI,IAAY;CACtC,IAAI,oCAAoB,IAAI,IAAY;CACxC,IAAI,qCAAqB,IAAI,IAAY;CACzC,IAAI,cAAc;CAClB,MAAM,WAAW,QACf,YAAY,KAAK,aAAa,IAC1B,cAAc,GAAG,IACjB,IAAI,WAAW,GAAG,IAChB,cAAc,GAAG,gBAAgB,KAAK,IACtC,cAAc,QAAQ,eAAe,GAAG,CAAC;CACjD,MAAM,uBAAuB,oBAAoB,IAAI,OAAO;CAC5D,MAAM,yBAAyB,sBAAsB,IAAI,OAAO;CAEhE,SAAS,eAAe,cAA8B;EACpD,MAAM,aAAa,cAAc,YAAY;EAC7C,IAAI,YAAY,YAAY,IAAI,GAC9B,OAAO,WAAW,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AiB,eAAe,IAAI;GAC1C,MAAM,cACJ,SAAS,YAAY,oBAAoB;GAE3C,IAAI,UAAU,UAAU;IACtB,YAAY,OAAO,cAAc;IACjC,mBAAmB,OAAO,cAAc;IACxC;GACF;GAEA,YAAY,IAAI,cAAc;GAC9B,IAAI,iBAAiB,IAAI,GACvB,mBAAmB,IAAI,cAAc;EAEzC;EAEA,WAAW,oBAAqC;GAC9C,kBAAkB;GAClB,OAAO,mBAAmB,IAAI,kBAAkB;EAClD;EAEA,QAAc;GACZ,cAAc;GACd,qCAAqB,IAAI,IAAY;EACvC;CACF;AACF"}
|
|
@@ -1,9 +1,15 @@
|
|
|
1
1
|
import { relative } from "node:path";
|
|
2
2
|
import { normalizePath } from "vite";
|
|
3
3
|
import { parseSync } from "oxc-parser";
|
|
4
|
-
|
|
4
|
+
// packages/platform/src/lib/route-idiom-diagnostics.ts
|
|
5
5
|
var PAGE_FILE_RE = /\.page\.ts$/;
|
|
6
6
|
var ROUTER_OUTLET_RE = /\bRouterOutlet\b|<router-outlet(?:\s|>)/;
|
|
7
|
+
var WRAPPER_EXPRESSIONS = /* @__PURE__ */ new Set([
|
|
8
|
+
"ParenthesizedExpression",
|
|
9
|
+
"TSAsExpression",
|
|
10
|
+
"TSSatisfiesExpression",
|
|
11
|
+
"TSTypeAssertion"
|
|
12
|
+
]);
|
|
7
13
|
function analyzeAnalogRouteFile(options) {
|
|
8
14
|
const { filename, code, routeFiles = [] } = options;
|
|
9
15
|
const parseResult = parseSync(filename, code, {
|
|
@@ -31,7 +37,7 @@ function analyzeAnalogRouteFile(options) {
|
|
|
31
37
|
message: "Redirect routes should not also export a page component.",
|
|
32
38
|
details: "Analog ignores the default export when `routeMeta.redirectTo` is present. Remove the component export or remove the redirect."
|
|
33
39
|
});
|
|
34
|
-
if (routeMetaInfo?.
|
|
40
|
+
if (routeMetaInfo?.redirectTarget && !routeMetaInfo.redirectTarget.startsWith("/")) diagnostics.push({
|
|
35
41
|
code: "relative-redirect",
|
|
36
42
|
severity: "warning",
|
|
37
43
|
message: "`routeMeta.redirectTo` should use an absolute path.",
|
|
@@ -73,17 +79,19 @@ function isLikelyLayoutRoute(filename, routeFiles) {
|
|
|
73
79
|
return routeFiles.some((routeFile) => routeFile !== filename && routeFile.startsWith(`${routeStem}/`));
|
|
74
80
|
}
|
|
75
81
|
function getRouteMetaInfo(program, bindingName) {
|
|
76
|
-
const routeMetaNode = getExportedBindingInitializer(program, bindingName);
|
|
82
|
+
const routeMetaNode = unwrapExpression(getExportedBindingInitializer(program, bindingName));
|
|
77
83
|
if (routeMetaNode?.type !== "ObjectExpression") return null;
|
|
78
84
|
let redirectTo;
|
|
79
85
|
for (const property of routeMetaNode.properties ?? []) {
|
|
80
86
|
if (property?.type !== "Property") continue;
|
|
81
87
|
if (getPropertyName(property.key) !== "redirectTo") continue;
|
|
82
|
-
redirectTo =
|
|
88
|
+
redirectTo = property.value;
|
|
83
89
|
}
|
|
90
|
+
const value = unwrapExpression(redirectTo);
|
|
91
|
+
if (!value || isNullish(value)) return { hasRedirect: false };
|
|
84
92
|
return {
|
|
85
|
-
hasRedirect:
|
|
86
|
-
|
|
93
|
+
hasRedirect: true,
|
|
94
|
+
redirectTarget: getStaticRedirectTarget(value)
|
|
87
95
|
};
|
|
88
96
|
}
|
|
89
97
|
function getExportedBindingInitializer(program, bindingName) {
|
|
@@ -131,11 +139,17 @@ function getPropertyName(node) {
|
|
|
131
139
|
if (node?.type === "Identifier") return node.name;
|
|
132
140
|
if ((node?.type === "Literal" || node?.type === "StringLiteral") && typeof node.value === "string") return node.value;
|
|
133
141
|
}
|
|
134
|
-
function
|
|
135
|
-
if ((node
|
|
136
|
-
if (node
|
|
142
|
+
function getStaticRedirectTarget(node) {
|
|
143
|
+
if ((node.type === "Literal" || node.type === "StringLiteral") && typeof node.value === "string") return node.value;
|
|
144
|
+
if (node.type === "TemplateLiteral") return (node.quasis?.[0]?.value.cooked ?? node.quasis?.[0]?.value.raw) || void 0;
|
|
145
|
+
}
|
|
146
|
+
function isNullish(node) {
|
|
147
|
+
return node.type === "Literal" && node.value === null || node.type === "Identifier" && node.name === "undefined" || node.type === "UnaryExpression" && node.operator === "void";
|
|
148
|
+
}
|
|
149
|
+
function unwrapExpression(node) {
|
|
150
|
+
while (node && WRAPPER_EXPRESSIONS.has(node.type)) node = node.expression;
|
|
151
|
+
return node;
|
|
137
152
|
}
|
|
138
|
-
//#endregion
|
|
139
153
|
export { analyzeAnalogRouteFile, formatAnalogRouteIdiomDiagnostic };
|
|
140
154
|
|
|
141
155
|
//# sourceMappingURL=route-idiom-diagnostics.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"route-idiom-diagnostics.js","names":[],"sources":["../../../src/lib/route-idiom-diagnostics.ts"],"sourcesContent":["import { parseSync, type OxcError, type Severity } from 'oxc-parser';\nimport { relative } from 'node:path';\nimport { normalizePath } from 'vite';\n\nexport interface AnalogRouteIdiomDiagnostic {\n code: string;\n severity: 'error' | 'warning';\n message: string;\n details?: string;\n}\n\nexport interface AnalyzeAnalogRouteFileOptions {\n filename: string;\n code: string;\n routeFiles?: string[];\n}\n\nconst PAGE_FILE_RE = /\\.page\\.ts$/;\nconst ROUTER_OUTLET_RE = /\\bRouterOutlet\\b|<router-outlet(?:\\s|>)/;\n\nexport function analyzeAnalogRouteFile(\n options: AnalyzeAnalogRouteFileOptions,\n): AnalogRouteIdiomDiagnostic[] {\n const { filename, code, routeFiles = [] } = options;\n const parseResult = parseSync(filename, code, {\n lang: 'ts',\n sourceType: 'module',\n range: true,\n showSemanticErrors: true,\n });\n\n const parseDiagnostics = parseResult.errors.map((error) =>\n toParseDiagnostic(error),\n );\n\n if (parseDiagnostics.some((diagnostic) => diagnostic.severity === 'error')) {\n return parseDiagnostics;\n }\n\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n const program: any = parseResult.program;\n const exportedBindings = collectExportedBindings(program);\n const routeMetaBindingName = exportedBindings.routeMeta;\n const diagnostics = [...parseDiagnostics];\n\n const routeMetaInfo = routeMetaBindingName\n ? getRouteMetaInfo(program, routeMetaBindingName)\n : null;\n\n if (!exportedBindings.hasDefaultExport && !routeMetaInfo?.hasRedirect) {\n diagnostics.push({\n code: 'missing-default-export',\n severity: 'warning',\n message:\n 'Route files should default-export the page component, unless they are redirect-only routes.',\n details:\n 'Add `export default class ...` or define `routeMeta.redirectTo` for a redirect route.',\n });\n }\n\n if (exportedBindings.hasDefaultExport && routeMetaInfo?.hasRedirect) {\n diagnostics.push({\n code: 'redirect-with-component',\n severity: 'warning',\n message: 'Redirect routes should not also export a page component.',\n details:\n 'Analog ignores the default export when `routeMeta.redirectTo` is present. Remove the component export or remove the redirect.',\n });\n }\n\n if (\n routeMetaInfo?.hasRedirect &&\n routeMetaInfo.redirectTo &&\n !routeMetaInfo.redirectTo.startsWith('/')\n ) {\n diagnostics.push({\n code: 'relative-redirect',\n severity: 'warning',\n message: '`routeMeta.redirectTo` should use an absolute path.',\n details:\n 'Nested redirects are documented to use absolute targets such as `/cities/new-york`.',\n });\n }\n\n if (\n isLikelyLayoutRoute(filename, routeFiles) &&\n !ROUTER_OUTLET_RE.test(code)\n ) {\n diagnostics.push({\n code: 'layout-without-router-outlet',\n severity: 'warning',\n message:\n 'This route file looks like a layout shell, but it does not reference `RouterOutlet` or `<router-outlet>`.',\n details:\n 'Parent layout pages usually import `RouterOutlet` and render an outlet so child routes have somewhere to mount.',\n });\n }\n\n return diagnostics;\n}\n\nexport function formatAnalogRouteIdiomDiagnostic(\n diagnostic: AnalogRouteIdiomDiagnostic,\n filename: string,\n workspaceRoot: string,\n): string {\n const displayName = toDisplayPath(filename, workspaceRoot);\n const header = `[Analog] ${displayName} (${diagnostic.code})`;\n const severity = diagnostic.severity.toUpperCase();\n\n if (diagnostic.details) {\n return `${header}\\n${severity}: ${diagnostic.message}\\n${diagnostic.details}`;\n }\n\n return `${header}\\n${severity}: ${diagnostic.message}`;\n}\n\nfunction toDisplayPath(filename: string, workspaceRoot: string): string {\n const normalizedFilename = normalizePath(filename);\n const normalizedRoot = normalizePath(workspaceRoot);\n const relativePath = normalizePath(\n relative(normalizedRoot, normalizedFilename),\n );\n\n if (relativePath && !relativePath.startsWith('..')) {\n return `/${relativePath}`;\n }\n\n return normalizedFilename;\n}\n\nfunction toParseDiagnostic(error: OxcError): AnalogRouteIdiomDiagnostic {\n return {\n code: 'oxc-parse',\n severity: error.severity === severityError ? 'error' : 'warning',\n message: error.message,\n details: error.codeframe ?? error.helpMessage ?? undefined,\n };\n}\n\nconst severityError: Severity = 'Error';\n\nfunction isLikelyLayoutRoute(filename: string, routeFiles: string[]): boolean {\n if (!PAGE_FILE_RE.test(filename)) {\n return false;\n }\n\n const routeStem = filename.replace(PAGE_FILE_RE, '');\n return routeFiles.some(\n (routeFile) =>\n routeFile !== filename && routeFile.startsWith(`${routeStem}/`),\n );\n}\n\nfunction getRouteMetaInfo(\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n program: any,\n bindingName: string,\n): {\n hasRedirect: boolean;\n redirectTo?: string;\n} | null {\n const routeMetaNode = getExportedBindingInitializer(program, bindingName);\n\n if (routeMetaNode?.type !== 'ObjectExpression') {\n return null;\n }\n\n let redirectTo: string | undefined;\n\n for (const property of routeMetaNode.properties ?? []) {\n if (property?.type !== 'Property') {\n continue;\n }\n\n const keyName = getPropertyName(property.key);\n if (keyName !== 'redirectTo') {\n continue;\n }\n\n redirectTo = getStringValue(property.value);\n }\n\n return {\n hasRedirect: typeof redirectTo === 'string' && redirectTo.length > 0,\n redirectTo,\n };\n}\n\nfunction getExportedBindingInitializer(\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n program: any,\n bindingName: string,\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n): any | undefined {\n for (const statement of program.body ?? []) {\n if (statement?.type === 'VariableDeclaration') {\n const initializer = getVariableInitializer(statement, bindingName);\n if (initializer) {\n return initializer;\n }\n continue;\n }\n\n if (\n statement?.type === 'ExportNamedDeclaration' &&\n statement.declaration?.type === 'VariableDeclaration'\n ) {\n const initializer = getVariableInitializer(\n statement.declaration,\n bindingName,\n );\n if (initializer) {\n return initializer;\n }\n }\n }\n\n return undefined;\n}\n\nfunction getVariableInitializer(\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n declaration: any,\n bindingName: string,\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n): any | undefined {\n for (const declarator of declaration.declarations ?? []) {\n if (\n declarator.id?.type === 'Identifier' &&\n declarator.id.name === bindingName\n ) {\n return declarator.init;\n }\n }\n\n return undefined;\n}\n\nfunction collectExportedBindings(\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n program: any,\n): {\n hasDefaultExport: boolean;\n routeMeta?: string;\n} {\n let hasDefaultExport = false;\n let routeMeta: string | undefined;\n\n for (const statement of program.body ?? []) {\n if (statement?.type === 'ExportDefaultDeclaration') {\n hasDefaultExport = true;\n continue;\n }\n\n if (statement?.type !== 'ExportNamedDeclaration') {\n continue;\n }\n\n const declaration = statement.declaration;\n if (declaration?.type === 'VariableDeclaration') {\n for (const declarator of declaration.declarations ?? []) {\n if (declarator.id?.type !== 'Identifier') {\n continue;\n }\n\n if (declarator.id.name === 'routeMeta') {\n routeMeta = 'routeMeta';\n }\n }\n }\n\n for (const specifier of statement.specifiers ?? []) {\n if (\n specifier?.type !== 'ExportSpecifier' ||\n specifier.local?.type !== 'Identifier'\n ) {\n continue;\n }\n\n if (specifier.exported?.type !== 'Identifier') {\n continue;\n }\n\n if (specifier.exported.name === 'routeMeta') {\n routeMeta = specifier.local.name;\n }\n }\n }\n\n return {\n hasDefaultExport,\n routeMeta,\n };\n}\n\nfunction getPropertyName(\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n node: any,\n): string | undefined {\n if (node?.type === 'Identifier') {\n return node.name;\n }\n\n if (\n (node?.type === 'Literal' || node?.type === 'StringLiteral') &&\n typeof node.value === 'string'\n ) {\n return node.value;\n }\n\n return undefined;\n}\n\nfunction getStringValue(\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n node: any,\n): string | undefined {\n if (\n (node?.type === 'Literal' || node?.type === 'StringLiteral') &&\n typeof node.value === 'string'\n ) {\n return node.value;\n }\n\n if (\n node?.type === 'TemplateLiteral' &&\n node.expressions?.length === 0 &&\n node.quasis?.length === 1\n ) {\n return node.quasis[0].value.cooked ?? node.quasis[0].value.raw;\n }\n\n return undefined;\n}\n"],"mappings":";;;;AAiBA,IAAM,eAAe;AACrB,IAAM,mBAAmB;AAEzB,SAAgB,uBACd,SAC8B;CAC9B,MAAM,EAAE,UAAU,MAAM,aAAa,CAAC,MAAM;CAC5C,MAAM,cAAc,UAAU,UAAU,MAAM;EAC5C,MAAM;EACN,YAAY;EACZ,OAAO;EACP,oBAAoB;CACtB,CAAC;CAED,MAAM,mBAAmB,YAAY,OAAO,KAAK,UAC/C,kBAAkB,KAAK,CACzB;CAEA,IAAI,iBAAiB,MAAM,eAAe,WAAW,aAAa,OAAO,GACvE,OAAO;CAIT,MAAM,UAAe,YAAY;CACjC,MAAM,mBAAmB,wBAAwB,OAAO;CACxD,MAAM,uBAAuB,iBAAiB;CAC9C,MAAM,cAAc,CAAC,GAAG,gBAAgB;CAExC,MAAM,gBAAgB,uBAClB,iBAAiB,SAAS,oBAAoB,IAC9C;CAEJ,IAAI,CAAC,iBAAiB,oBAAoB,CAAC,eAAe,aACxD,YAAY,KAAK;EACf,MAAM;EACN,UAAU;EACV,SACE;EACF,SACE;CACJ,CAAC;CAGH,IAAI,iBAAiB,oBAAoB,eAAe,aACtD,YAAY,KAAK;EACf,MAAM;EACN,UAAU;EACV,SAAS;EACT,SACE;CACJ,CAAC;CAGH,IACE,eAAe,eACf,cAAc,cACd,CAAC,cAAc,WAAW,WAAW,GAAG,GAExC,YAAY,KAAK;EACf,MAAM;EACN,UAAU;EACV,SAAS;EACT,SACE;CACJ,CAAC;CAGH,IACE,oBAAoB,UAAU,UAAU,KACxC,CAAC,iBAAiB,KAAK,IAAI,GAE3B,YAAY,KAAK;EACf,MAAM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ACjB,OAAO,KAAK;CAGd,KACG,MAAM,SAAS,aAAa,MAAM,SAAS,oBAC5C,OAAO,KAAK,UAAU,UAEtB,OAAO,KAAK;AAIhB;AAEA,SAAS,eAEP,MACoB;CACpB,KACG,MAAM,SAAS,aAAa,MAAM,SAAS,oBAC5C,OAAO,KAAK,UAAU,UAEtB,OAAO,KAAK;CAGd,IACE,MAAM,SAAS,qBACf,KAAK,aAAa,WAAW,KAC7B,KAAK,QAAQ,WAAW,GAExB,OAAO,KAAK,OAAO,EAAE,CAAC,MAAM,UAAU,KAAK,OAAO,EAAE,CAAC,MAAM;AAI/D"}
|
|
1
|
+
{"version":3,"file":"route-idiom-diagnostics.js","names":[],"sources":["../../../src/lib/route-idiom-diagnostics.ts"],"sourcesContent":["import { parseSync, type OxcError, type Severity } from 'oxc-parser';\nimport { relative } from 'node:path';\nimport { normalizePath } from 'vite';\n\nexport interface AnalogRouteIdiomDiagnostic {\n code: string;\n severity: 'error' | 'warning';\n message: string;\n details?: string;\n}\n\nexport interface AnalyzeAnalogRouteFileOptions {\n filename: string;\n code: string;\n routeFiles?: string[];\n}\n\nconst PAGE_FILE_RE = /\\.page\\.ts$/;\nconst ROUTER_OUTLET_RE = /\\bRouterOutlet\\b|<router-outlet(?:\\s|>)/;\n\n// Valid AST node types: grouping parentheses, as, satisfies, angle-bracket type assertion\nconst WRAPPER_EXPRESSIONS = new Set([\n 'ParenthesizedExpression',\n 'TSAsExpression',\n 'TSSatisfiesExpression',\n 'TSTypeAssertion',\n]);\n\nexport function analyzeAnalogRouteFile(\n options: AnalyzeAnalogRouteFileOptions,\n): AnalogRouteIdiomDiagnostic[] {\n const { filename, code, routeFiles = [] } = options;\n const parseResult = parseSync(filename, code, {\n lang: 'ts',\n sourceType: 'module',\n range: true,\n showSemanticErrors: true,\n });\n\n const parseDiagnostics = parseResult.errors.map((error) =>\n toParseDiagnostic(error),\n );\n\n if (parseDiagnostics.some((diagnostic) => diagnostic.severity === 'error')) {\n return parseDiagnostics;\n }\n\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n const program: any = parseResult.program;\n const exportedBindings = collectExportedBindings(program);\n const routeMetaBindingName = exportedBindings.routeMeta;\n const diagnostics = [...parseDiagnostics];\n\n const routeMetaInfo = routeMetaBindingName\n ? getRouteMetaInfo(program, routeMetaBindingName)\n : null;\n\n if (!exportedBindings.hasDefaultExport && !routeMetaInfo?.hasRedirect) {\n diagnostics.push({\n code: 'missing-default-export',\n severity: 'warning',\n message:\n 'Route files should default-export the page component, unless they are redirect-only routes.',\n details:\n 'Add `export default class ...` or define `routeMeta.redirectTo` for a redirect route.',\n });\n }\n\n if (exportedBindings.hasDefaultExport && routeMetaInfo?.hasRedirect) {\n diagnostics.push({\n code: 'redirect-with-component',\n severity: 'warning',\n message: 'Redirect routes should not also export a page component.',\n details:\n 'Analog ignores the default export when `routeMeta.redirectTo` is present. Remove the component export or remove the redirect.',\n });\n }\n\n if (\n routeMetaInfo?.redirectTarget &&\n !routeMetaInfo.redirectTarget.startsWith('/')\n ) {\n diagnostics.push({\n code: 'relative-redirect',\n severity: 'warning',\n message: '`routeMeta.redirectTo` should use an absolute path.',\n details:\n 'Nested redirects are documented to use absolute targets such as `/cities/new-york`.',\n });\n }\n\n if (\n isLikelyLayoutRoute(filename, routeFiles) &&\n !ROUTER_OUTLET_RE.test(code)\n ) {\n diagnostics.push({\n code: 'layout-without-router-outlet',\n severity: 'warning',\n message:\n 'This route file looks like a layout shell, but it does not reference `RouterOutlet` or `<router-outlet>`.',\n details:\n 'Parent layout pages usually import `RouterOutlet` and render an outlet so child routes have somewhere to mount.',\n });\n }\n\n return diagnostics;\n}\n\nexport function formatAnalogRouteIdiomDiagnostic(\n diagnostic: AnalogRouteIdiomDiagnostic,\n filename: string,\n workspaceRoot: string,\n): string {\n const displayName = toDisplayPath(filename, workspaceRoot);\n const header = `[Analog] ${displayName} (${diagnostic.code})`;\n const severity = diagnostic.severity.toUpperCase();\n\n if (diagnostic.details) {\n return `${header}\\n${severity}: ${diagnostic.message}\\n${diagnostic.details}`;\n }\n\n return `${header}\\n${severity}: ${diagnostic.message}`;\n}\n\nfunction toDisplayPath(filename: string, workspaceRoot: string): string {\n const normalizedFilename = normalizePath(filename);\n const normalizedRoot = normalizePath(workspaceRoot);\n const relativePath = normalizePath(\n relative(normalizedRoot, normalizedFilename),\n );\n\n if (relativePath && !relativePath.startsWith('..')) {\n return `/${relativePath}`;\n }\n\n return normalizedFilename;\n}\n\nfunction toParseDiagnostic(error: OxcError): AnalogRouteIdiomDiagnostic {\n return {\n code: 'oxc-parse',\n severity: error.severity === severityError ? 'error' : 'warning',\n message: error.message,\n details: error.codeframe ?? error.helpMessage ?? undefined,\n };\n}\n\nconst severityError: Severity = 'Error';\n\nfunction isLikelyLayoutRoute(filename: string, routeFiles: string[]): boolean {\n if (!PAGE_FILE_RE.test(filename)) {\n return false;\n }\n\n const routeStem = filename.replace(PAGE_FILE_RE, '');\n return routeFiles.some(\n (routeFile) =>\n routeFile !== filename && routeFile.startsWith(`${routeStem}/`),\n );\n}\n\nfunction getRouteMetaInfo(\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n program: any,\n bindingName: string,\n): {\n hasRedirect: boolean;\n redirectTarget?: string;\n} | null {\n const routeMetaNode = unwrapExpression(\n getExportedBindingInitializer(program, bindingName),\n );\n\n if (routeMetaNode?.type !== 'ObjectExpression') {\n return null;\n }\n\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n let redirectTo: any;\n\n for (const property of routeMetaNode.properties ?? []) {\n if (property?.type !== 'Property') {\n continue;\n }\n\n const keyName = getPropertyName(property.key);\n\n if (keyName !== 'redirectTo') {\n continue;\n }\n\n redirectTo = property.value;\n }\n\n const value = unwrapExpression(redirectTo);\n\n if (!value || isNullish(value)) {\n return { hasRedirect: false };\n }\n\n return {\n hasRedirect: true,\n redirectTarget: getStaticRedirectTarget(value),\n };\n}\n\nfunction getExportedBindingInitializer(\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n program: any,\n bindingName: string,\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n): any | undefined {\n for (const statement of program.body ?? []) {\n if (statement?.type === 'VariableDeclaration') {\n const initializer = getVariableInitializer(statement, bindingName);\n if (initializer) {\n return initializer;\n }\n continue;\n }\n\n if (\n statement?.type === 'ExportNamedDeclaration' &&\n statement.declaration?.type === 'VariableDeclaration'\n ) {\n const initializer = getVariableInitializer(\n statement.declaration,\n bindingName,\n );\n if (initializer) {\n return initializer;\n }\n }\n }\n\n return undefined;\n}\n\nfunction getVariableInitializer(\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n declaration: any,\n bindingName: string,\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n): any | undefined {\n for (const declarator of declaration.declarations ?? []) {\n if (\n declarator.id?.type === 'Identifier' &&\n declarator.id.name === bindingName\n ) {\n return declarator.init;\n }\n }\n\n return undefined;\n}\n\nfunction collectExportedBindings(\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n program: any,\n): {\n hasDefaultExport: boolean;\n routeMeta?: string;\n} {\n let hasDefaultExport = false;\n let routeMeta: string | undefined;\n\n for (const statement of program.body ?? []) {\n if (statement?.type === 'ExportDefaultDeclaration') {\n hasDefaultExport = true;\n continue;\n }\n\n if (statement?.type !== 'ExportNamedDeclaration') {\n continue;\n }\n\n const declaration = statement.declaration;\n if (declaration?.type === 'VariableDeclaration') {\n for (const declarator of declaration.declarations ?? []) {\n if (declarator.id?.type !== 'Identifier') {\n continue;\n }\n\n if (declarator.id.name === 'routeMeta') {\n routeMeta = 'routeMeta';\n }\n }\n }\n\n for (const specifier of statement.specifiers ?? []) {\n if (\n specifier?.type !== 'ExportSpecifier' ||\n specifier.local?.type !== 'Identifier'\n ) {\n continue;\n }\n\n if (specifier.exported?.type !== 'Identifier') {\n continue;\n }\n\n if (specifier.exported.name === 'routeMeta') {\n routeMeta = specifier.local.name;\n }\n }\n }\n\n return {\n hasDefaultExport,\n routeMeta,\n };\n}\n\nfunction getPropertyName(\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n node: any,\n): string | undefined {\n if (node?.type === 'Identifier') {\n return node.name;\n }\n\n if (\n (node?.type === 'Literal' || node?.type === 'StringLiteral') &&\n typeof node.value === 'string'\n ) {\n return node.value;\n }\n\n return undefined;\n}\n\nfunction getStaticRedirectTarget(\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n node: any,\n): string | undefined {\n if (\n (node.type === 'Literal' || node.type === 'StringLiteral') &&\n typeof node.value === 'string'\n ) {\n return node.value;\n }\n\n if (node.type === 'TemplateLiteral') {\n const lead = node.quasis?.[0]?.value.cooked ?? node.quasis?.[0]?.value.raw;\n return lead || undefined;\n }\n\n return undefined;\n}\n\nfunction isNullish(\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n node: any,\n): boolean {\n return (\n (node.type === 'Literal' && node.value === null) ||\n (node.type === 'Identifier' && node.name === 'undefined') ||\n (node.type === 'UnaryExpression' && node.operator === 'void')\n );\n}\n\nfunction unwrapExpression(\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n node: any,\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n): any | undefined {\n while (node && WRAPPER_EXPRESSIONS.has(node.type)) {\n node = node.expression;\n }\n\n return node;\n}\n"],"mappings":";;;;AAiBA,IAAM,eAAe;AACrB,IAAM,mBAAmB;AAGzB,IAAM,sCAAsB,IAAI,IAAI;CAClC;CACA;CACA;CACA;AACF,CAAC;AAED,SAAgB,uBACd,SAC8B;CAC9B,MAAM,EAAE,UAAU,MAAM,aAAa,CAAC,MAAM;CAC5C,MAAM,cAAc,UAAU,UAAU,MAAM;EAC5C,MAAM;EACN,YAAY;EACZ,OAAO;EACP,oBAAoB;CACtB,CAAC;CAED,MAAM,mBAAmB,YAAY,OAAO,KAAK,UAC/C,kBAAkB,KAAK,CACzB;CAEA,IAAI,iBAAiB,MAAM,eAAe,WAAW,aAAa,OAAO,GACvE,OAAO;CAIT,MAAM,UAAe,YAAY;CACjC,MAAM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,oBAAoB,IAAI,KAAK,IAAI,GAC9C,OAAO,KAAK;CAGd,OAAO;AACT"}
|
|
@@ -65,7 +65,7 @@ export interface RouteManifest {
|
|
|
65
65
|
* (`/libs/shared/feature/src/content/`) uniformly.
|
|
66
66
|
* 2. `[\\/](?:app[\\/]pages|src[\\/]content)[\\/]` — non-anchored
|
|
67
67
|
* fallback for paths where the directory marker appears mid-string.
|
|
68
|
-
* 3. `\.page\.(js|ts)$` — strips page file extensions.
|
|
68
|
+
* 3. `\.page\.(js|ts|tsrx)$` — strips page file extensions.
|
|
69
69
|
* 4. `\.(ts|md)$` — strips remaining file extensions.
|
|
70
70
|
*
|
|
71
71
|
* Examples:
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
|
|
1
|
+
// packages/platform/src/lib/route-manifest.ts
|
|
2
2
|
/**
|
|
3
3
|
* Converts a discovered filename to a route path pattern.
|
|
4
4
|
*
|
|
@@ -13,7 +13,7 @@
|
|
|
13
13
|
* (`/libs/shared/feature/src/content/`) uniformly.
|
|
14
14
|
* 2. `[\\/](?:app[\\/]pages|src[\\/]content)[\\/]` — non-anchored
|
|
15
15
|
* fallback for paths where the directory marker appears mid-string.
|
|
16
|
-
* 3. `\.page\.(js|ts)$` — strips page file extensions.
|
|
16
|
+
* 3. `\.page\.(js|ts|tsrx)$` — strips page file extensions.
|
|
17
17
|
* 4. `\.(ts|md)$` — strips remaining file extensions.
|
|
18
18
|
*
|
|
19
19
|
* Examples:
|
|
@@ -27,7 +27,7 @@
|
|
|
27
27
|
* - '/libs/shared/feature/src/content/test.md' -> '/test'
|
|
28
28
|
*/
|
|
29
29
|
function filenameToRoutePath(filename) {
|
|
30
|
-
let path = filename.replace(/^(?:[a-zA-Z]:[\\/])?(.*?)[\\/](?:routes|pages|content)[\\/]|(?:[\\/](?:app[\\/]pages|src[\\/]content)[\\/])|(\.page\.(js|ts)$)|(\.(ts|md)$)/g, "");
|
|
30
|
+
let path = filename.replace(/^(?:[a-zA-Z]:[\\/])?(.*?)[\\/](?:routes|pages|content)[\\/]|(?:[\\/](?:app[\\/]pages|src[\\/]content)[\\/])|(\.page\.(js|ts|tsrx)$)|(\.(ts|md)$)/g, "");
|
|
31
31
|
const brackets = [];
|
|
32
32
|
path = path.replace(/\[\[?\.{0,3}[^\]]*\]?\]/g, (match) => {
|
|
33
33
|
brackets.push(match);
|
|
@@ -48,7 +48,7 @@ function filenameToRoutePath(filename) {
|
|
|
48
48
|
* changes to the regex must be kept in sync between both functions.
|
|
49
49
|
*/
|
|
50
50
|
function filenameToRouteId(filename) {
|
|
51
|
-
let path = filename.replace(/^(?:[a-zA-Z]:[\\/])?(.*?)[\\/](?:routes|pages|content)[\\/]|(?:[\\/](?:app[\\/]pages|src[\\/]content)[\\/])|(\.page\.(js|ts)$)|(\.(ts|md)$)/g, "");
|
|
51
|
+
let path = filename.replace(/^(?:[a-zA-Z]:[\\/])?(.*?)[\\/](?:routes|pages|content)[\\/]|(?:[\\/](?:app[\\/]pages|src[\\/]content)[\\/])|(\.page\.(js|ts|tsrx)$)|(\.(ts|md)$)/g, "");
|
|
52
52
|
const brackets = [];
|
|
53
53
|
path = path.replace(/\(.*?\)|\[\[?\.{0,3}[^\]]*\]?\]/g, (match) => {
|
|
54
54
|
brackets.push(match);
|
|
@@ -114,8 +114,8 @@ function generateRouteManifest(filenames, collisionPriority) {
|
|
|
114
114
|
const winner = seenByFullPath.get(collisionKey);
|
|
115
115
|
if (winner.filename === filename) continue;
|
|
116
116
|
const isLayoutIndexPair = (a, b) => {
|
|
117
|
-
const indexRe = /\/index\.(page\.)?(ts|js|md)$/;
|
|
118
|
-
const layoutRe = /\.(page\.)?(ts|js)$/;
|
|
117
|
+
const indexRe = /\/index\.(page\.)?(ts|tsrx|js|md)$/;
|
|
118
|
+
const layoutRe = /\.(page\.)?(ts|tsrx|js)$/;
|
|
119
119
|
if (indexRe.test(a) && layoutRe.test(b)) return a.replace(indexRe, "") === b.replace(layoutRe, "");
|
|
120
120
|
return false;
|
|
121
121
|
};
|
|
@@ -199,7 +199,7 @@ function canonicalRoutesByFullPath(routes) {
|
|
|
199
199
|
}
|
|
200
200
|
/** A route file's path within its pages directory, e.g. `users/[id]`. */
|
|
201
201
|
function toRouteFileKey(filename) {
|
|
202
|
-
return filename.replace(/^.*?[\\/](?:routes|pages|content)[\\/]|\.page\.(?:js|ts)$|\.(?:ts|md)$/g, "");
|
|
202
|
+
return filename.replace(/^.*?[\\/](?:routes|pages|content)[\\/]|\.page\.(?:js|ts|tsrx)$|\.(?:ts|md)$/g, "");
|
|
203
203
|
}
|
|
204
204
|
function isPathlessLayoutId(id) {
|
|
205
205
|
const segments = id.split("/").filter(Boolean);
|
|
@@ -294,7 +294,6 @@ function computeLocalPath(fullPath, parentFullPath) {
|
|
|
294
294
|
if (!parentFullPath) return fullPath.slice(1);
|
|
295
295
|
return fullPath.slice(parentFullPath.length).replace(/^\/+/, "") || "/";
|
|
296
296
|
}
|
|
297
|
-
//#endregion
|
|
298
297
|
export { extractRouteParams, filenameToRouteId, filenameToRoutePath, generateRouteManifest, generateRouteTableDeclaration };
|
|
299
298
|
|
|
300
299
|
//# sourceMappingURL=route-manifest.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"route-manifest.js","names":[],"sources":["../../../src/lib/route-manifest.ts"],"sourcesContent":["/**\n * Route-manifest engine for typed file routes.\n *\n * Pure functions (no Angular dependencies) for converting discovered\n * filenames into typed route manifests and generated declarations.\n */\n\nexport interface RouteParamInfo {\n name: string;\n type: 'dynamic' | 'catchAll' | 'optionalCatchAll';\n}\n\nexport interface RouteEntry {\n /** Stable structural route id derived from the source filename */\n id: string;\n /** The route path segment relative to the nearest existing parent route */\n path: string;\n /** The fully resolved navigation path pattern (e.g., '/users/[id]') */\n fullPath: string;\n /** Extracted parameter information */\n params: RouteParamInfo[];\n /** Original filename that produced this route */\n filename: string;\n /** Type of source that produced this route */\n kind: 'page' | 'content';\n /** Parent route id, or null for top-level routes */\n parentId: string | null;\n /** Child route ids */\n children: string[];\n /** Whether the source filename represents an index route */\n isIndex: boolean;\n /** Whether the source filename includes route-group/pathless segments */\n isGroup: boolean;\n /** Whether the route contains a required catch-all parameter */\n isCatchAll: boolean;\n /** Whether the route contains an optional catch-all parameter */\n isOptionalCatchAll: boolean;\n /** Layout files that wrap this route, outermost first */\n layouts: string[];\n}\n\nexport interface RouteCollision {\n fullPath: string;\n keptFile: string;\n droppedFile: string;\n /** True when both files have the same collision priority (hard error). */\n samePriority: boolean;\n}\n\nexport interface RouteManifest {\n routes: RouteEntry[];\n collisions: RouteCollision[];\n /** Canonical route per fullPath — precomputed once to avoid redundant work. */\n canonicalByFullPath: Map<string, RouteEntry>;\n /** Full paths defined by more than one file, such as a layout and its index page. */\n sharedFullPaths: Set<string>;\n}\n\n/**\n * Converts a discovered filename to a route path pattern.\n *\n * Uses the same stripping rules as the existing route system\n * but preserves bracket param syntax instead of converting to\n * Angular's `:param` syntax.\n *\n * The regex applies four alternations (left to right, all replaced with ''):\n * 1. `^(.*?)[\\\\/](?:routes|pages|content)[\\\\/]` — anchored, strips everything\n * up to and including the first /routes/, /pages/, or /content/ segment.\n * Handles app-local paths (`/src/app/pages/`) AND additional dirs\n * (`/libs/shared/feature/src/content/`) uniformly.\n * 2. `[\\\\/](?:app[\\\\/]pages|src[\\\\/]content)[\\\\/]` — non-anchored\n * fallback for paths where the directory marker appears mid-string.\n * 3. `\\.page\\.(js|ts)$` — strips page file extensions.\n * 4. `\\.(ts|md)$` — strips remaining file extensions.\n *\n * Examples:\n * - '/src/app/pages/index.page.ts' -> '/'\n * - '/src/app/pages/about.page.ts' -> '/about'\n * - '/src/app/pages/users/[id].page.ts' -> '/users/[id]'\n * - '/src/app/pages/blog.[slug].page.ts' -> '/blog/[slug]'\n * - '/src/app/pages/(auth)/login.page.ts' -> '/login'\n * - '/src/app/pages/docs/[...slug].page.ts' -> '/docs/[...slug]'\n * - '/src/app/pages/shop/[[...category]].page.ts' -> '/shop/[[...category]]'\n * - '/libs/shared/feature/src/content/test.md' -> '/test'\n */\nexport function filenameToRoutePath(filename: string): string {\n let path = filename.replace(\n /^(?:[a-zA-Z]:[\\\\/])?(.*?)[\\\\/](?:routes|pages|content)[\\\\/]|(?:[\\\\/](?:app[\\\\/]pages|src[\\\\/]content)[\\\\/])|(\\.page\\.(js|ts)$)|(\\.(ts|md)$)/g,\n '',\n );\n\n const brackets: string[] = [];\n path = path.replace(/\\[\\[?\\.{0,3}[^\\]]*\\]?\\]/g, (match) => {\n brackets.push(match);\n // eslint-disable-next-line no-control-regex\n return `\\0B${brackets.length - 1}\\0`;\n });\n // Match the runtime router: strip index segments and groups before dots.\n path = path\n .replace(/\\(.*?\\)/g, '')\n .replace(/(^|[./])index(?=[./]|$)/g, '$1')\n .replace(/\\./g, '/');\n // eslint-disable-next-line no-control-regex\n path = path.replace(/\\0B(\\d+)\\0/g, (_, idx) => brackets[Number(idx)]);\n return '/' + path.split('/').filter(Boolean).join('/');\n}\n\n/**\n * Converts a discovered filename to a stable structural route id.\n *\n * Unlike `filenameToRoutePath`, this preserves route groups and `index`\n * segments so that multiple files resolving to the same URL shape can still\n * have distinct structural identities in the generated route tree metadata.\n *\n * Uses the same directory-stripping regex as `filenameToRoutePath` —\n * changes to the regex must be kept in sync between both functions.\n */\nexport function filenameToRouteId(filename: string): string {\n let path = filename.replace(\n /^(?:[a-zA-Z]:[\\\\/])?(.*?)[\\\\/](?:routes|pages|content)[\\\\/]|(?:[\\\\/](?:app[\\\\/]pages|src[\\\\/]content)[\\\\/])|(\\.page\\.(js|ts)$)|(\\.(ts|md)$)/g,\n '',\n );\n\n const brackets: string[] = [];\n path = path.replace(/\\(.*?\\)|\\[\\[?\\.{0,3}[^\\]]*\\]?\\]/g, (match) => {\n brackets.push(match);\n // eslint-disable-next-line no-control-regex\n return `\\0B${brackets.length - 1}\\0`;\n });\n path = path.replace(/\\./g, '/');\n // eslint-disable-next-line no-control-regex\n path = path.replace(/\\0B(\\d+)\\0/g, (_, idx) => brackets[Number(idx)]);\n\n const segments = path.split('/').filter(Boolean);\n\n return '/' + segments.join('/');\n}\n\n/**\n * Extracts parameter information from a route path pattern.\n */\nexport function extractRouteParams(routePath: string): RouteParamInfo[] {\n const params: RouteParamInfo[] = [];\n\n for (const match of routePath.matchAll(/\\[\\[\\.\\.\\.([^\\]]+)\\]\\]/g)) {\n params.push({ name: match[1], type: 'optionalCatchAll' });\n }\n for (const match of routePath.matchAll(/(?<!\\[)\\[\\.\\.\\.([^\\]]+)\\](?!\\])/g)) {\n params.push({ name: match[1], type: 'catchAll' });\n }\n for (const match of routePath.matchAll(/(?<!\\[)\\[(?!\\.)([^\\]]+)\\](?!\\])/g)) {\n params.push({ name: match[1], type: 'dynamic' });\n }\n\n return params;\n}\n\n/**\n * Generates a route manifest from a list of discovered filenames.\n *\n * @param collisionPriority - Optional callback that returns a numeric priority\n * for each filename (lower wins). When provided, this replaces the default\n * hard-coded path-substring heuristic with config-derived precedence.\n */\nexport function generateRouteManifest(\n filenames: string[],\n collisionPriority?: (filename: string) => number,\n): RouteManifest {\n const routes: RouteEntry[] = [];\n const collisions: RouteCollision[] = [];\n const sharedFullPaths = new Set<string>();\n const seenByFullPath = new Map<\n string,\n { filename: string; priority: number }\n >();\n const getPriority = collisionPriority ?? getCollisionPriority;\n\n // Prefer app-local route files over shared/external sources when two files\n // resolve to the same URL. This keeps `additionalPagesDirs` additive instead\n // of unexpectedly overriding the route that lives inside the app itself.\n const prioritizedFilenames = [...filenames].sort((a, b) => {\n const aPriority = getPriority(a);\n const bPriority = getPriority(b);\n if (aPriority !== bPriority) {\n return aPriority - bPriority;\n }\n return a.localeCompare(b);\n });\n\n // Layout routes are a file and a folder with the same name, so users.page.ts\n // wraps users/[id].page.ts but not users.[id].page.ts. Folders from all\n // pages dirs share one tree.\n const layoutByKey = new Map<string, string>();\n for (const filename of prioritizedFilenames) {\n const key = toRouteFileKey(filename);\n if (!filename.endsWith('.md') && !layoutByKey.has(key)) {\n layoutByKey.set(key, filename);\n }\n }\n\n for (const filename of prioritizedFilenames) {\n const fullPath = filenameToRoutePath(filename);\n const params = extractRouteParams(fullPath);\n const id = filenameToRouteId(filename);\n const isPathlessLayout = isPathlessLayoutId(id);\n // Different pathless branches can select the same URL with canMatch guards.\n const groupScope = id.slice(0, id.lastIndexOf(')') + 1);\n const collisionKey = JSON.stringify([fullPath, groupScope]);\n\n const currentPriority = getPriority(filename);\n\n // Pathless layouts (e.g. (auth).page.ts) are structural wrappers that\n // render a <router-outlet> — they coexist with index.page.ts at the same\n // fullPath without collision. The Angular router handles them as nested\n // layout routes, not competing page components.\n if (!isPathlessLayout) {\n if (seenByFullPath.has(collisionKey)) {\n const winner = seenByFullPath.get(collisionKey)!;\n if (winner.filename === filename) {\n continue;\n }\n // A layout file (e.g., docs.page.ts) and its index child\n // (e.g., docs/index.page.ts) intentionally share the same route\n // path — the layout wraps the index as a parent-child pair.\n const isLayoutIndexPair = (a: string, b: string) => {\n const indexRe = /\\/index\\.(page\\.)?(ts|js|md)$/;\n const layoutRe = /\\.(page\\.)?(ts|js)$/;\n if (indexRe.test(a) && layoutRe.test(b)) {\n const dir = a.replace(indexRe, '');\n const layout = b.replace(layoutRe, '');\n return dir === layout;\n }\n return false;\n };\n if (\n isLayoutIndexPair(winner.filename, filename) ||\n isLayoutIndexPair(filename, winner.filename)\n ) {\n sharedFullPaths.add(fullPath);\n continue;\n }\n collisions.push({\n fullPath,\n keptFile: winner.filename,\n droppedFile: filename,\n samePriority: winner.priority === currentPriority,\n });\n console.warn(\n `[Analog] Route collision: '${fullPath}' is defined by both ` +\n `'${winner.filename}' and '${filename}'. ` +\n `Keeping '${winner.filename}' based on route source precedence and skipping duplicate.`,\n );\n continue;\n }\n seenByFullPath.set(collisionKey, { filename, priority: currentPriority });\n }\n\n const segments = toRouteFileKey(filename).split('/');\n const layouts: string[] = [];\n for (let i = 1; i < segments.length; i++) {\n const layout = layoutByKey.get(segments.slice(0, i).join('/'));\n if (layout) layouts.push(layout);\n }\n\n routes.push({\n id,\n path: fullPath,\n fullPath,\n params,\n filename,\n kind: filename.endsWith('.md') ? 'content' : 'page',\n parentId: null,\n children: [],\n isIndex: id === '/index' || id.endsWith('/index'),\n isGroup: isPathlessLayout,\n isCatchAll: params.some((param) => param.type === 'catchAll'),\n isOptionalCatchAll: params.some(\n (param) => param.type === 'optionalCatchAll',\n ),\n layouts,\n });\n }\n\n routes.sort((a, b) => {\n const aW = getRouteWeight(a.fullPath);\n const bW = getRouteWeight(b.fullPath);\n if (aW !== bW) return aW - bW;\n return a.fullPath.localeCompare(b.fullPath);\n });\n\n const routeByFullPath = canonicalRoutesByFullPath(routes);\n\n const routeById = new Map(routes.map((route) => [route.id, route]));\n\n for (const route of routes) {\n // Use structural id-based parent lookup for any route whose id\n // contains a group segment — this wires group children (e.g.\n // /(auth)/sign-up) to their pathless layout parent (/(auth)).\n // This also correctly handles nested groups like\n // /dashboard/(settings)/profile: findNearestParentById walks up\n // id segments and finds /(settings) if it exists, otherwise falls\n // through to fullPathParent which resolves to /dashboard.\n // Non-group routes always use the canonical fullPath-based lookup.\n const hasGroupSegment = route.id.includes('/(');\n const structuralParent = hasGroupSegment\n ? findNearestParentById(route.id, routeById)\n : undefined;\n const fullPathParent = findNearestParentRoute(\n route.fullPath,\n routeByFullPath,\n );\n const parent = structuralParent ?? fullPathParent;\n route.parentId = parent?.id ?? null;\n route.path = computeLocalPath(route.fullPath, parent?.fullPath ?? null);\n }\n\n for (const route of routes) {\n if (route.parentId) {\n routeById.get(route.parentId)?.children.push(route.id);\n }\n if (routeByFullPath.get(route.fullPath) !== route) {\n sharedFullPaths.add(route.fullPath);\n }\n }\n\n return {\n routes,\n collisions,\n canonicalByFullPath: routeByFullPath,\n sharedFullPaths,\n };\n}\n\nfunction canonicalRoutesByFullPath(\n routes: RouteEntry[],\n): Map<string, RouteEntry> {\n const map = new Map<string, RouteEntry>();\n for (const route of routes) {\n const existing = map.get(route.fullPath);\n if (!existing) {\n map.set(route.fullPath, route);\n } else if (existing.isGroup && !route.isGroup) {\n // Non-group routes always take precedence over group layouts.\n map.set(route.fullPath, route);\n } else if (existing.isGroup && route.isGroup) {\n // Both are group layouts — tiebreak by id to ensure stable selection\n // regardless of filesystem or glob ordering across platforms.\n if (route.id.localeCompare(existing.id) < 0) {\n map.set(route.fullPath, route);\n }\n }\n }\n return map;\n}\n\n/** A route file's path within its pages directory, e.g. `users/[id]`. */\nfunction toRouteFileKey(filename: string): string {\n return filename.replace(\n /^.*?[\\\\/](?:routes|pages|content)[\\\\/]|\\.page\\.(?:js|ts)$|\\.(?:ts|md)$/g,\n '',\n );\n}\n\nfunction isPathlessLayoutId(id: string): boolean {\n const segments = id.split('/').filter(Boolean);\n if (segments.length === 0) return false;\n return /^\\([^)]*\\)$/.test(segments[segments.length - 1]);\n}\n\nfunction getRouteWeight(path: string): number {\n if (path.includes('[[...')) return 3;\n if (path.includes('[...')) return 2;\n if (path.includes('[')) return 1;\n return 0;\n}\n\nfunction getCollisionPriority(filename: string): number {\n if (\n filename.includes('/src/app/pages/') ||\n filename.includes('/app/pages/') ||\n filename.includes('/src/content/')\n ) {\n return 0;\n }\n\n return 1;\n}\n\n/** Import specifiers for a page module's typed exports. */\nexport interface RouteModuleImports {\n routeMeta?: string;\n load?: string;\n}\n\n/**\n * Generates the route-table section for the combined generated route module.\n *\n * `resolveModuleImports` adds `routeMeta` and `load` types for pages whose\n * URL is defined by a single file, along with the `routeMeta` of the layouts\n * that wrap them. URLs shared by several files, such as a layout and its\n * index page, are ambiguous and only get params and query types.\n */\nexport function generateRouteTableDeclaration(\n manifest: RouteManifest,\n resolveModuleImports?: (filename: string) => RouteModuleImports | undefined,\n): string {\n const lines: string[] = [];\n lines.push('/** @noprettier */');\n lines.push('// This file is auto-generated by @analogjs/platform');\n lines.push(\"import type {} from '@analogjs/router';\");\n lines.push(\"declare module '@analogjs/router' {\");\n lines.push(' interface AnalogRouteTable {');\n\n const importType = (specifier: string, name: string) =>\n `typeof import(${JSON.stringify(specifier)}).${name}`;\n\n for (const route of manifest.canonicalByFullPath.values()) {\n const paramsType = generateParamsType(route.params);\n const queryType = 'Record<string, string | string[] | undefined>';\n\n lines.push(` ${JSON.stringify(route.fullPath)}: {`);\n lines.push(` params: ${paramsType};`);\n lines.push(` query: ${queryType};`);\n if (\n resolveModuleImports &&\n route.kind === 'page' &&\n !manifest.sharedFullPaths.has(route.fullPath)\n ) {\n const layoutRouteMeta = route.layouts.flatMap((layout) => {\n const specifier = resolveModuleImports(layout)?.routeMeta;\n return specifier ? [importType(specifier, 'routeMeta')] : [];\n });\n const imports = resolveModuleImports(route.filename);\n if (layoutRouteMeta.length) {\n lines.push(` layoutRouteMeta: [${layoutRouteMeta.join(', ')}];`);\n }\n if (imports?.routeMeta) {\n lines.push(\n ` routeMeta: ${importType(imports.routeMeta, 'routeMeta')};`,\n );\n }\n if (imports?.load) {\n lines.push(` load: ${importType(imports.load, 'load')};`);\n }\n }\n lines.push(` };`);\n }\n\n lines.push(' }');\n lines.push('}');\n lines.push('');\n lines.push('export {};');\n lines.push('');\n\n return lines.join('\\n');\n}\n\nfunction generateParamsType(params: RouteParamInfo[]): string {\n if (params.length === 0) return 'Record<string, never>';\n\n const entries = params.map((p) => {\n const key = isValidIdentifier(p.name) ? p.name : JSON.stringify(p.name);\n switch (p.type) {\n case 'dynamic':\n return `${key}: string`;\n case 'catchAll':\n return `${key}: string[]`;\n case 'optionalCatchAll':\n return `${key}?: string[]`;\n }\n });\n\n return `{ ${entries.join('; ')} }`;\n}\n\nfunction isValidIdentifier(name: string): boolean {\n return /^[a-zA-Z_$][a-zA-Z0-9_$]*$/.test(name);\n}\n\nfunction findNearestParentById(\n id: string,\n routesById: Map<string, RouteEntry>,\n): RouteEntry | undefined {\n if (id === '/') {\n return undefined;\n }\n\n const segments = id.split('/').filter(Boolean);\n for (let index = segments.length - 1; index > 0; index--) {\n const candidate = '/' + segments.slice(0, index).join('/');\n const route = routesById.get(candidate);\n if (route) {\n return route;\n }\n }\n\n return undefined;\n}\n\nfunction findNearestParentRoute(\n fullPath: string,\n routesByFullPath: Map<string, RouteEntry>,\n): RouteEntry | undefined {\n if (fullPath === '/') {\n return undefined;\n }\n\n const segments = fullPath.slice(1).split('/');\n for (let index = segments.length - 1; index > 0; index--) {\n const candidate = '/' + segments.slice(0, index).join('/');\n const route = routesByFullPath.get(candidate);\n if (route) {\n return route;\n }\n }\n\n return undefined;\n}\n\nfunction computeLocalPath(\n fullPath: string,\n parentFullPath: string | null,\n): string {\n if (fullPath === '/') {\n return '/';\n }\n\n if (!parentFullPath) {\n return fullPath.slice(1);\n }\n\n const suffix = fullPath.slice(parentFullPath.length).replace(/^\\/+/, '');\n return suffix || '/';\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAqFA,SAAgB,oBAAoB,UAA0B;CAC5D,IAAI,OAAO,SAAS,QAClB,gJACA,EACF;CAEA,MAAM,WAAqB,CAAC;CAC5B,OAAO,KAAK,QAAQ,6BAA6B,UAAU;EACzD,SAAS,KAAK,KAAK;EAEnB,OAAO,MAAM,SAAS,SAAS,EAAE;CACnC,CAAC;CAED,OAAO,KACJ,QAAQ,YAAY,EAAE,CAAC,CACvB,QAAQ,4BAA4B,IAAI,CAAC,CACzC,QAAQ,OAAO,GAAG;CAErB,OAAO,KAAK,QAAQ,gBAAgB,GAAG,QAAQ,SAAS,OAAO,GAAG,EAAE;CACpE,OAAO,MAAM,KAAK,MAAM,GAAG,CAAC,CAAC,OAAO,OAAO,CAAC,CAAC,KAAK,GAAG;AACvD;;;;;;;;;;;AAYA,SAAgB,kBAAkB,UAA0B;CAC1D,IAAI,OAAO,SAAS,QAClB,gJACA,EACF;CAEA,MAAM,WAAqB,CAAC;CAC5B,OAAO,KAAK,QAAQ,qCAAqC,UAAU;EACjE,SAAS,KAAK,KAAK;EAEnB,OAAO,MAAM,SAAS,SAAS,EAAE;CACnC,CAAC;CACD,OAAO,KAAK,QAAQ,OAAO,GAAG;CAE9B,OAAO,KAAK,QAAQ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uB;CAChD,OAAO,6BAA6B,KAAK,IAAI;AAC/C;AAEA,SAAS,sBACP,IACA,YACwB;CACxB,IAAI,OAAO,KACT;CAGF,MAAM,WAAW,GAAG,MAAM,GAAG,CAAC,CAAC,OAAO,OAAO;CAC7C,KAAK,IAAI,QAAQ,SAAS,SAAS,GAAG,QAAQ,GAAG,SAAS;EACxD,MAAM,YAAY,MAAM,SAAS,MAAM,GAAG,KAAK,CAAC,CAAC,KAAK,GAAG;EACzD,MAAM,QAAQ,WAAW,IAAI,SAAS;EACtC,IAAI,OACF,OAAO;CAEX;AAGF;AAEA,SAAS,uBACP,UACA,kBACwB;CACxB,IAAI,aAAa,KACf;CAGF,MAAM,WAAW,SAAS,MAAM,CAAC,CAAC,CAAC,MAAM,GAAG;CAC5C,KAAK,IAAI,QAAQ,SAAS,SAAS,GAAG,QAAQ,GAAG,SAAS;EACxD,MAAM,YAAY,MAAM,SAAS,MAAM,GAAG,KAAK,CAAC,CAAC,KAAK,GAAG;EACzD,MAAM,QAAQ,iBAAiB,IAAI,SAAS;EAC5C,IAAI,OACF,OAAO;CAEX;AAGF;AAEA,SAAS,iBACP,UACA,gBACQ;CACR,IAAI,aAAa,KACf,OAAO;CAGT,IAAI,CAAC,gBACH,OAAO,SAAS,MAAM,CAAC;CAIzB,OADe,SAAS,MAAM,eAAe,MAAM,CAAC,CAAC,QAAQ,QAAQ,EAC9D,KAAU;AACnB"}
|
|
1
|
+
{"version":3,"file":"route-manifest.js","names":[],"sources":["../../../src/lib/route-manifest.ts"],"sourcesContent":["/**\n * Route-manifest engine for typed file routes.\n *\n * Pure functions (no Angular dependencies) for converting discovered\n * filenames into typed route manifests and generated declarations.\n */\n\nexport interface RouteParamInfo {\n name: string;\n type: 'dynamic' | 'catchAll' | 'optionalCatchAll';\n}\n\nexport interface RouteEntry {\n /** Stable structural route id derived from the source filename */\n id: string;\n /** The route path segment relative to the nearest existing parent route */\n path: string;\n /** The fully resolved navigation path pattern (e.g., '/users/[id]') */\n fullPath: string;\n /** Extracted parameter information */\n params: RouteParamInfo[];\n /** Original filename that produced this route */\n filename: string;\n /** Type of source that produced this route */\n kind: 'page' | 'content';\n /** Parent route id, or null for top-level routes */\n parentId: string | null;\n /** Child route ids */\n children: string[];\n /** Whether the source filename represents an index route */\n isIndex: boolean;\n /** Whether the source filename includes route-group/pathless segments */\n isGroup: boolean;\n /** Whether the route contains a required catch-all parameter */\n isCatchAll: boolean;\n /** Whether the route contains an optional catch-all parameter */\n isOptionalCatchAll: boolean;\n /** Layout files that wrap this route, outermost first */\n layouts: string[];\n}\n\nexport interface RouteCollision {\n fullPath: string;\n keptFile: string;\n droppedFile: string;\n /** True when both files have the same collision priority (hard error). */\n samePriority: boolean;\n}\n\nexport interface RouteManifest {\n routes: RouteEntry[];\n collisions: RouteCollision[];\n /** Canonical route per fullPath — precomputed once to avoid redundant work. */\n canonicalByFullPath: Map<string, RouteEntry>;\n /** Full paths defined by more than one file, such as a layout and its index page. */\n sharedFullPaths: Set<string>;\n}\n\n/**\n * Converts a discovered filename to a route path pattern.\n *\n * Uses the same stripping rules as the existing route system\n * but preserves bracket param syntax instead of converting to\n * Angular's `:param` syntax.\n *\n * The regex applies four alternations (left to right, all replaced with ''):\n * 1. `^(.*?)[\\\\/](?:routes|pages|content)[\\\\/]` — anchored, strips everything\n * up to and including the first /routes/, /pages/, or /content/ segment.\n * Handles app-local paths (`/src/app/pages/`) AND additional dirs\n * (`/libs/shared/feature/src/content/`) uniformly.\n * 2. `[\\\\/](?:app[\\\\/]pages|src[\\\\/]content)[\\\\/]` — non-anchored\n * fallback for paths where the directory marker appears mid-string.\n * 3. `\\.page\\.(js|ts|tsrx)$` — strips page file extensions.\n * 4. `\\.(ts|md)$` — strips remaining file extensions.\n *\n * Examples:\n * - '/src/app/pages/index.page.ts' -> '/'\n * - '/src/app/pages/about.page.ts' -> '/about'\n * - '/src/app/pages/users/[id].page.ts' -> '/users/[id]'\n * - '/src/app/pages/blog.[slug].page.ts' -> '/blog/[slug]'\n * - '/src/app/pages/(auth)/login.page.ts' -> '/login'\n * - '/src/app/pages/docs/[...slug].page.ts' -> '/docs/[...slug]'\n * - '/src/app/pages/shop/[[...category]].page.ts' -> '/shop/[[...category]]'\n * - '/libs/shared/feature/src/content/test.md' -> '/test'\n */\nexport function filenameToRoutePath(filename: string): string {\n let path = filename.replace(\n /^(?:[a-zA-Z]:[\\\\/])?(.*?)[\\\\/](?:routes|pages|content)[\\\\/]|(?:[\\\\/](?:app[\\\\/]pages|src[\\\\/]content)[\\\\/])|(\\.page\\.(js|ts|tsrx)$)|(\\.(ts|md)$)/g,\n '',\n );\n\n const brackets: string[] = [];\n path = path.replace(/\\[\\[?\\.{0,3}[^\\]]*\\]?\\]/g, (match) => {\n brackets.push(match);\n // eslint-disable-next-line no-control-regex\n return `\\0B${brackets.length - 1}\\0`;\n });\n // Match the runtime router: strip index segments and groups before dots.\n path = path\n .replace(/\\(.*?\\)/g, '')\n .replace(/(^|[./])index(?=[./]|$)/g, '$1')\n .replace(/\\./g, '/');\n // eslint-disable-next-line no-control-regex\n path = path.replace(/\\0B(\\d+)\\0/g, (_, idx) => brackets[Number(idx)]);\n return '/' + path.split('/').filter(Boolean).join('/');\n}\n\n/**\n * Converts a discovered filename to a stable structural route id.\n *\n * Unlike `filenameToRoutePath`, this preserves route groups and `index`\n * segments so that multiple files resolving to the same URL shape can still\n * have distinct structural identities in the generated route tree metadata.\n *\n * Uses the same directory-stripping regex as `filenameToRoutePath` —\n * changes to the regex must be kept in sync between both functions.\n */\nexport function filenameToRouteId(filename: string): string {\n let path = filename.replace(\n /^(?:[a-zA-Z]:[\\\\/])?(.*?)[\\\\/](?:routes|pages|content)[\\\\/]|(?:[\\\\/](?:app[\\\\/]pages|src[\\\\/]content)[\\\\/])|(\\.page\\.(js|ts|tsrx)$)|(\\.(ts|md)$)/g,\n '',\n );\n\n const brackets: string[] = [];\n path = path.replace(/\\(.*?\\)|\\[\\[?\\.{0,3}[^\\]]*\\]?\\]/g, (match) => {\n brackets.push(match);\n // eslint-disable-next-line no-control-regex\n return `\\0B${brackets.length - 1}\\0`;\n });\n path = path.replace(/\\./g, '/');\n // eslint-disable-next-line no-control-regex\n path = path.replace(/\\0B(\\d+)\\0/g, (_, idx) => brackets[Number(idx)]);\n\n const segments = path.split('/').filter(Boolean);\n\n return '/' + segments.join('/');\n}\n\n/**\n * Extracts parameter information from a route path pattern.\n */\nexport function extractRouteParams(routePath: string): RouteParamInfo[] {\n const params: RouteParamInfo[] = [];\n\n for (const match of routePath.matchAll(/\\[\\[\\.\\.\\.([^\\]]+)\\]\\]/g)) {\n params.push({ name: match[1], type: 'optionalCatchAll' });\n }\n for (const match of routePath.matchAll(/(?<!\\[)\\[\\.\\.\\.([^\\]]+)\\](?!\\])/g)) {\n params.push({ name: match[1], type: 'catchAll' });\n }\n for (const match of routePath.matchAll(/(?<!\\[)\\[(?!\\.)([^\\]]+)\\](?!\\])/g)) {\n params.push({ name: match[1], type: 'dynamic' });\n }\n\n return params;\n}\n\n/**\n * Generates a route manifest from a list of discovered filenames.\n *\n * @param collisionPriority - Optional callback that returns a numeric priority\n * for each filename (lower wins). When provided, this replaces the default\n * hard-coded path-substring heuristic with config-derived precedence.\n */\nexport function generateRouteManifest(\n filenames: string[],\n collisionPriority?: (filename: string) => number,\n): RouteManifest {\n const routes: RouteEntry[] = [];\n const collisions: RouteCollision[] = [];\n const sharedFullPaths = new Set<string>();\n const seenByFullPath = new Map<\n string,\n { filename: string; priority: number }\n >();\n const getPriority = collisionPriority ?? getCollisionPriority;\n\n // Prefer app-local route files over shared/external sources when two files\n // resolve to the same URL. This keeps `additionalPagesDirs` additive instead\n // of unexpectedly overriding the route that lives inside the app itself.\n const prioritizedFilenames = [...filenames].sort((a, b) => {\n const aPriority = getPriority(a);\n const bPriority = getPriority(b);\n if (aPriority !== bPriority) {\n return aPriority - bPriority;\n }\n return a.localeCompare(b);\n });\n\n // Layout routes are a file and a folder with the same name, so users.page.ts\n // wraps users/[id].page.ts but not users.[id].page.ts. Folders from all\n // pages dirs share one tree.\n const layoutByKey = new Map<string, string>();\n for (const filename of prioritizedFilenames) {\n const key = toRouteFileKey(filename);\n if (!filename.endsWith('.md') && !layoutByKey.has(key)) {\n layoutByKey.set(key, filename);\n }\n }\n\n for (const filename of prioritizedFilenames) {\n const fullPath = filenameToRoutePath(filename);\n const params = extractRouteParams(fullPath);\n const id = filenameToRouteId(filename);\n const isPathlessLayout = isPathlessLayoutId(id);\n // Different pathless branches can select the same URL with canMatch guards.\n const groupScope = id.slice(0, id.lastIndexOf(')') + 1);\n const collisionKey = JSON.stringify([fullPath, groupScope]);\n\n const currentPriority = getPriority(filename);\n\n // Pathless layouts (e.g. (auth).page.ts) are structural wrappers that\n // render a <router-outlet> — they coexist with index.page.ts at the same\n // fullPath without collision. The Angular router handles them as nested\n // layout routes, not competing page components.\n if (!isPathlessLayout) {\n if (seenByFullPath.has(collisionKey)) {\n const winner = seenByFullPath.get(collisionKey)!;\n if (winner.filename === filename) {\n continue;\n }\n // A layout file (e.g., docs.page.ts) and its index child\n // (e.g., docs/index.page.ts) intentionally share the same route\n // path — the layout wraps the index as a parent-child pair.\n const isLayoutIndexPair = (a: string, b: string) => {\n const indexRe = /\\/index\\.(page\\.)?(ts|tsrx|js|md)$/;\n const layoutRe = /\\.(page\\.)?(ts|tsrx|js)$/;\n if (indexRe.test(a) && layoutRe.test(b)) {\n const dir = a.replace(indexRe, '');\n const layout = b.replace(layoutRe, '');\n return dir === layout;\n }\n return false;\n };\n if (\n isLayoutIndexPair(winner.filename, filename) ||\n isLayoutIndexPair(filename, winner.filename)\n ) {\n sharedFullPaths.add(fullPath);\n continue;\n }\n collisions.push({\n fullPath,\n keptFile: winner.filename,\n droppedFile: filename,\n samePriority: winner.priority === currentPriority,\n });\n console.warn(\n `[Analog] Route collision: '${fullPath}' is defined by both ` +\n `'${winner.filename}' and '${filename}'. ` +\n `Keeping '${winner.filename}' based on route source precedence and skipping duplicate.`,\n );\n continue;\n }\n seenByFullPath.set(collisionKey, { filename, priority: currentPriority });\n }\n\n const segments = toRouteFileKey(filename).split('/');\n const layouts: string[] = [];\n for (let i = 1; i < segments.length; i++) {\n const layout = layoutByKey.get(segments.slice(0, i).join('/'));\n if (layout) layouts.push(layout);\n }\n\n routes.push({\n id,\n path: fullPath,\n fullPath,\n params,\n filename,\n kind: filename.endsWith('.md') ? 'content' : 'page',\n parentId: null,\n children: [],\n isIndex: id === '/index' || id.endsWith('/index'),\n isGroup: isPathlessLayout,\n isCatchAll: params.some((param) => param.type === 'catchAll'),\n isOptionalCatchAll: params.some(\n (param) => param.type === 'optionalCatchAll',\n ),\n layouts,\n });\n }\n\n routes.sort((a, b) => {\n const aW = getRouteWeight(a.fullPath);\n const bW = getRouteWeight(b.fullPath);\n if (aW !== bW) return aW - bW;\n return a.fullPath.localeCompare(b.fullPath);\n });\n\n const routeByFullPath = canonicalRoutesByFullPath(routes);\n\n const routeById = new Map(routes.map((route) => [route.id, route]));\n\n for (const route of routes) {\n // Use structural id-based parent lookup for any route whose id\n // contains a group segment — this wires group children (e.g.\n // /(auth)/sign-up) to their pathless layout parent (/(auth)).\n // This also correctly handles nested groups like\n // /dashboard/(settings)/profile: findNearestParentById walks up\n // id segments and finds /(settings) if it exists, otherwise falls\n // through to fullPathParent which resolves to /dashboard.\n // Non-group routes always use the canonical fullPath-based lookup.\n const hasGroupSegment = route.id.includes('/(');\n const structuralParent = hasGroupSegment\n ? findNearestParentById(route.id, routeById)\n : undefined;\n const fullPathParent = findNearestParentRoute(\n route.fullPath,\n routeByFullPath,\n );\n const parent = structuralParent ?? fullPathParent;\n route.parentId = parent?.id ?? null;\n route.path = computeLocalPath(route.fullPath, parent?.fullPath ?? null);\n }\n\n for (const route of routes) {\n if (route.parentId) {\n routeById.get(route.parentId)?.children.push(route.id);\n }\n if (routeByFullPath.get(route.fullPath) !== route) {\n sharedFullPaths.add(route.fullPath);\n }\n }\n\n return {\n routes,\n collisions,\n canonicalByFullPath: routeByFullPath,\n sharedFullPaths,\n };\n}\n\nfunction canonicalRoutesByFullPath(\n routes: RouteEntry[],\n): Map<string, RouteEntry> {\n const map = new Map<string, RouteEntry>();\n for (const route of routes) {\n const existing = map.get(route.fullPath);\n if (!existing) {\n map.set(route.fullPath, route);\n } else if (existing.isGroup && !route.isGroup) {\n // Non-group routes always take precedence over group layouts.\n map.set(route.fullPath, route);\n } else if (existing.isGroup && route.isGroup) {\n // Both are group layouts — tiebreak by id to ensure stable selection\n // regardless of filesystem or glob ordering across platforms.\n if (route.id.localeCompare(existing.id) < 0) {\n map.set(route.fullPath, route);\n }\n }\n }\n return map;\n}\n\n/** A route file's path within its pages directory, e.g. `users/[id]`. */\nfunction toRouteFileKey(filename: string): string {\n return filename.replace(\n /^.*?[\\\\/](?:routes|pages|content)[\\\\/]|\\.page\\.(?:js|ts|tsrx)$|\\.(?:ts|md)$/g,\n '',\n );\n}\n\nfunction isPathlessLayoutId(id: string): boolean {\n const segments = id.split('/').filter(Boolean);\n if (segments.length === 0) return false;\n return /^\\([^)]*\\)$/.test(segments[segments.length - 1]);\n}\n\nfunction getRouteWeight(path: string): number {\n if (path.includes('[[...')) return 3;\n if (path.includes('[...')) return 2;\n if (path.includes('[')) return 1;\n return 0;\n}\n\nfunction getCollisionPriority(filename: string): number {\n if (\n filename.includes('/src/app/pages/') ||\n filename.includes('/app/pages/') ||\n filename.includes('/src/content/')\n ) {\n return 0;\n }\n\n return 1;\n}\n\n/** Import specifiers for a page module's typed exports. */\nexport interface RouteModuleImports {\n routeMeta?: string;\n load?: string;\n}\n\n/**\n * Generates the route-table section for the combined generated route module.\n *\n * `resolveModuleImports` adds `routeMeta` and `load` types for pages whose\n * URL is defined by a single file, along with the `routeMeta` of the layouts\n * that wrap them. URLs shared by several files, such as a layout and its\n * index page, are ambiguous and only get params and query types.\n */\nexport function generateRouteTableDeclaration(\n manifest: RouteManifest,\n resolveModuleImports?: (filename: string) => RouteModuleImports | undefined,\n): string {\n const lines: string[] = [];\n lines.push('/** @noprettier */');\n lines.push('// This file is auto-generated by @analogjs/platform');\n lines.push(\"import type {} from '@analogjs/router';\");\n lines.push(\"declare module '@analogjs/router' {\");\n lines.push(' interface AnalogRouteTable {');\n\n const importType = (specifier: string, name: string) =>\n `typeof import(${JSON.stringify(specifier)}).${name}`;\n\n for (const route of manifest.canonicalByFullPath.values()) {\n const paramsType = generateParamsType(route.params);\n const queryType = 'Record<string, string | string[] | undefined>';\n\n lines.push(` ${JSON.stringify(route.fullPath)}: {`);\n lines.push(` params: ${paramsType};`);\n lines.push(` query: ${queryType};`);\n if (\n resolveModuleImports &&\n route.kind === 'page' &&\n !manifest.sharedFullPaths.has(route.fullPath)\n ) {\n const layoutRouteMeta = route.layouts.flatMap((layout) => {\n const specifier = resolveModuleImports(layout)?.routeMeta;\n return specifier ? [importType(specifier, 'routeMeta')] : [];\n });\n const imports = resolveModuleImports(route.filename);\n if (layoutRouteMeta.length) {\n lines.push(` layoutRouteMeta: [${layoutRouteMeta.join(', ')}];`);\n }\n if (imports?.routeMeta) {\n lines.push(\n ` routeMeta: ${importType(imports.routeMeta, 'routeMeta')};`,\n );\n }\n if (imports?.load) {\n lines.push(` load: ${importType(imports.load, 'load')};`);\n }\n }\n lines.push(` };`);\n }\n\n lines.push(' }');\n lines.push('}');\n lines.push('');\n lines.push('export {};');\n lines.push('');\n\n return lines.join('\\n');\n}\n\nfunction generateParamsType(params: RouteParamInfo[]): string {\n if (params.length === 0) return 'Record<string, never>';\n\n const entries = params.map((p) => {\n const key = isValidIdentifier(p.name) ? p.name : JSON.stringify(p.name);\n switch (p.type) {\n case 'dynamic':\n return `${key}: string`;\n case 'catchAll':\n return `${key}: string[]`;\n case 'optionalCatchAll':\n return `${key}?: string[]`;\n }\n });\n\n return `{ ${entries.join('; ')} }`;\n}\n\nfunction isValidIdentifier(name: string): boolean {\n return /^[a-zA-Z_$][a-zA-Z0-9_$]*$/.test(name);\n}\n\nfunction findNearestParentById(\n id: string,\n routesById: Map<string, RouteEntry>,\n): RouteEntry | undefined {\n if (id === '/') {\n return undefined;\n }\n\n const segments = id.split('/').filter(Boolean);\n for (let index = segments.length - 1; index > 0; index--) {\n const candidate = '/' + segments.slice(0, index).join('/');\n const route = routesById.get(candidate);\n if (route) {\n return route;\n }\n }\n\n return undefined;\n}\n\nfunction findNearestParentRoute(\n fullPath: string,\n routesByFullPath: Map<string, RouteEntry>,\n): RouteEntry | undefined {\n if (fullPath === '/') {\n return undefined;\n }\n\n const segments = fullPath.slice(1).split('/');\n for (let index = segments.length - 1; index > 0; index--) {\n const candidate = '/' + segments.slice(0, index).join('/');\n const route = routesByFullPath.get(candidate);\n if (route) {\n return route;\n }\n }\n\n return undefined;\n}\n\nfunction computeLocalPath(\n fullPath: string,\n parentFullPath: string | null,\n): string {\n if (fullPath === '/') {\n return '/';\n }\n\n if (!parentFullPath) {\n return fullPath.slice(1);\n }\n\n const suffix = fullPath.slice(parentFullPath.length).replace(/^\\/+/, '');\n return suffix || '/';\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAqFA,SAAgB,oBAAoB,UAA0B;CAC5D,IAAI,OAAO,SAAS,QAClB,qJACA,EACF;CAEA,MAAM,WAAqB,CAAC;CAC5B,OAAO,KAAK,QAAQ,6BAA6B,UAAU;EACzD,SAAS,KAAK,KAAK;EAEnB,OAAO,MAAM,SAAS,SAAS,EAAE;CACnC,CAAC;CAED,OAAO,KACJ,QAAQ,YAAY,EAAE,CAAC,CACvB,QAAQ,4BAA4B,IAAI,CAAC,CACzC,QAAQ,OAAO,GAAG;CAErB,OAAO,KAAK,QAAQ,gBAAgB,GAAG,QAAQ,SAAS,OAAO,GAAG,EAAE;CACpE,OAAO,MAAM,KAAK,MAAM,GAAG,CAAC,CAAC,OAAO,OAAO,CAAC,CAAC,KAAK,GAAG;AACvD;;;;;;;;;;;AAYA,SAAgB,kBAAkB,UAA0B;CAC1D,IAAI,OAAO,SAAS,QAClB,qJACA,EACF;CAEA,MAAM,WAAqB,CAAC;CAC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ACH,OAAO,GAAG,IAAI;GAChB,KAAK,YACH,OAAO,GAAG,IAAI;GAChB,KAAK,oBACH,OAAO,GAAG,IAAI;EAClB;CACF,CAEY,CAAA,CAAQ,KAAK,IAAI,EAAE;AACjC;AAEA,SAAS,kBAAkB,MAAuB;CAChD,OAAO,6BAA6B,KAAK,IAAI;AAC/C;AAEA,SAAS,sBACP,IACA,YACwB;CACxB,IAAI,OAAO,KACT;CAGF,MAAM,WAAW,GAAG,MAAM,GAAG,CAAC,CAAC,OAAO,OAAO;CAC7C,KAAK,IAAI,QAAQ,SAAS,SAAS,GAAG,QAAQ,GAAG,SAAS;EACxD,MAAM,YAAY,MAAM,SAAS,MAAM,GAAG,KAAK,CAAC,CAAC,KAAK,GAAG;EACzD,MAAM,QAAQ,WAAW,IAAI,SAAS;EACtC,IAAI,OACF,OAAO;CAEX;AAGF;AAEA,SAAS,uBACP,UACA,kBACwB;CACxB,IAAI,aAAa,KACf;CAGF,MAAM,WAAW,SAAS,MAAM,CAAC,CAAC,CAAC,MAAM,GAAG;CAC5C,KAAK,IAAI,QAAQ,SAAS,SAAS,GAAG,QAAQ,GAAG,SAAS;EACxD,MAAM,YAAY,MAAM,SAAS,MAAM,GAAG,KAAK,CAAC,CAAC,KAAK,GAAG;EACzD,MAAM,QAAQ,iBAAiB,IAAI,SAAS;EAC5C,IAAI,OACF,OAAO;CAEX;AAGF;AAEA,SAAS,iBACP,UACA,gBACQ;CACR,IAAI,aAAa,KACf,OAAO;CAGT,IAAI,CAAC,gBACH,OAAO,SAAS,MAAM,CAAC;CAIzB,OADe,SAAS,MAAM,eAAe,MAAM,CAAC,CAAC,QAAQ,QAAQ,EAC9D,KAAU;AACnB"}
|
package/src/lib/router-plugin.js
CHANGED
|
@@ -3,7 +3,7 @@ import { isAbsolute, relative, resolve } from "node:path";
|
|
|
3
3
|
import { readFileSync } from "node:fs";
|
|
4
4
|
import { normalizePath } from "vite";
|
|
5
5
|
import { globSync } from "tinyglobby";
|
|
6
|
-
|
|
6
|
+
// packages/platform/src/lib/router-plugin.ts
|
|
7
7
|
/**
|
|
8
8
|
* Router plugin that handles route file discovery and hot module replacement.
|
|
9
9
|
*
|
|
@@ -49,7 +49,11 @@ function routerPlugin(options) {
|
|
|
49
49
|
return getRouteLikeDirs().some((dir) => normalizedPath === dir || normalizedPath.startsWith(`${dir}/`));
|
|
50
50
|
};
|
|
51
51
|
const discoverRouteFiles = () => {
|
|
52
|
-
routeFilesCache ??= globSync([
|
|
52
|
+
routeFilesCache ??= globSync([
|
|
53
|
+
`${root}/src/app/pages/**/*.page.ts`,
|
|
54
|
+
`${root}/src/app/pages/**/*.page.tsrx`,
|
|
55
|
+
...additionalPagesDirs.flatMap((dir) => [`${dir}/**/*.page.ts`, `${dir}/**/*.page.tsrx`])
|
|
56
|
+
], {
|
|
53
57
|
dot: true,
|
|
54
58
|
absolute: true
|
|
55
59
|
});
|
|
@@ -74,7 +78,7 @@ function routerPlugin(options) {
|
|
|
74
78
|
return endpointFilesCache;
|
|
75
79
|
};
|
|
76
80
|
const discoverPageRouteFiles = () => {
|
|
77
|
-
pageRouteFilesCache ??= discoverRouteFiles().filter((file) => file.endsWith(".page.ts"));
|
|
81
|
+
pageRouteFilesCache ??= discoverRouteFiles().filter((file) => file.endsWith(".page.ts") || file.endsWith(".page.tsrx"));
|
|
78
82
|
return pageRouteFilesCache;
|
|
79
83
|
};
|
|
80
84
|
const invalidateDiscoveryCaches = () => {
|
|
@@ -192,7 +196,7 @@ function routerPlugin(options) {
|
|
|
192
196
|
`);
|
|
193
197
|
result = result.replace("ANALOG_CONTENT_ROUTE_FILES = {};", `
|
|
194
198
|
ANALOG_CONTENT_ROUTE_FILES = {${contentRouteFiles.map((module) => {
|
|
195
|
-
return `"${getModuleKey(module)}": () => import('${module}?analog-content-file=true')
|
|
199
|
+
return `"${getModuleKey(module)}": () => import('${module}?analog-content-file=true')`;
|
|
196
200
|
})}};
|
|
197
201
|
`);
|
|
198
202
|
result = result.replace("ANALOG_CONTENT_FILE_COUNT = 0", `ANALOG_CONTENT_FILE_COUNT = ${contentRouteFiles.length}`);
|
|
@@ -233,7 +237,6 @@ function routerPlugin(options) {
|
|
|
233
237
|
}
|
|
234
238
|
];
|
|
235
239
|
}
|
|
236
|
-
//#endregion
|
|
237
240
|
export { routerPlugin };
|
|
238
241
|
|
|
239
242
|
//# sourceMappingURL=router-plugin.js.map
|