@jasonshimmy/vite-plugin-cer-app 0.23.2 → 0.24.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cli/checks/lighthouse.d.ts +26 -0
- package/dist/cli/checks/lighthouse.d.ts.map +1 -0
- package/dist/cli/checks/lighthouse.js +121 -0
- package/dist/cli/checks/lighthouse.js.map +1 -0
- package/dist/cli/checks/links.d.ts +12 -0
- package/dist/cli/checks/links.d.ts.map +1 -0
- package/dist/cli/checks/links.js +89 -0
- package/dist/cli/checks/links.js.map +1 -0
- package/dist/cli/checks/performance.d.ts +17 -0
- package/dist/cli/checks/performance.d.ts.map +1 -0
- package/dist/cli/checks/performance.js +61 -0
- package/dist/cli/checks/performance.js.map +1 -0
- package/dist/cli/commands/check.d.ts +3 -0
- package/dist/cli/commands/check.d.ts.map +1 -0
- package/dist/cli/commands/check.js +85 -0
- package/dist/cli/commands/check.js.map +1 -0
- package/dist/cli/create/index.d.ts +11 -1
- package/dist/cli/create/index.d.ts.map +1 -1
- package/dist/cli/create/index.js +135 -65
- package/dist/cli/create/index.js.map +1 -1
- package/dist/cli/create/templates/spa/package.json.tpl +5 -3
- package/dist/cli/create/templates/ssg/cer.config.ts.tpl +2 -0
- package/dist/cli/create/templates/ssg/package.json.tpl +5 -3
- package/dist/cli/create/templates/ssr/package.json.tpl +5 -3
- package/dist/cli/index.js +2 -0
- package/dist/cli/index.js.map +1 -1
- package/dist/index.d.ts +3 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/plugin/build-ssg.d.ts +22 -6
- package/dist/plugin/build-ssg.d.ts.map +1 -1
- package/dist/plugin/build-ssg.js +227 -17
- package/dist/plugin/build-ssg.js.map +1 -1
- package/dist/plugin/content/parser.d.ts.map +1 -1
- package/dist/plugin/content/parser.js +54 -10
- package/dist/plugin/content/parser.js.map +1 -1
- package/dist/plugin/dev-server.d.ts +4 -1
- package/dist/plugin/dev-server.d.ts.map +1 -1
- package/dist/plugin/dev-server.js.map +1 -1
- package/dist/plugin/dts-generator.d.ts.map +1 -1
- package/dist/plugin/dts-generator.js +50 -8
- package/dist/plugin/dts-generator.js.map +1 -1
- package/dist/plugin/generated-dir.d.ts +2 -0
- package/dist/plugin/generated-dir.d.ts.map +1 -1
- package/dist/plugin/generated-dir.js +17 -6
- package/dist/plugin/generated-dir.js.map +1 -1
- package/dist/plugin/html-post-process.d.ts +6 -0
- package/dist/plugin/html-post-process.d.ts.map +1 -1
- package/dist/plugin/html-post-process.js +24 -0
- package/dist/plugin/html-post-process.js.map +1 -1
- package/dist/plugin/index.d.ts.map +1 -1
- package/dist/plugin/index.js +60 -13
- package/dist/plugin/index.js.map +1 -1
- package/dist/plugin/transforms/auto-import.d.ts.map +1 -1
- package/dist/plugin/transforms/auto-import.js +7 -0
- package/dist/plugin/transforms/auto-import.js.map +1 -1
- package/dist/plugin/transforms/prune-runtime-css.d.ts +8 -0
- package/dist/plugin/transforms/prune-runtime-css.d.ts.map +1 -0
- package/dist/plugin/transforms/prune-runtime-css.js +40 -0
- package/dist/plugin/transforms/prune-runtime-css.js.map +1 -0
- package/dist/runtime/app-template.d.ts +1 -1
- package/dist/runtime/app-template.d.ts.map +1 -1
- package/dist/runtime/app-template.js +206 -36
- package/dist/runtime/app-template.js.map +1 -1
- package/dist/runtime/composables/index.d.ts +4 -0
- package/dist/runtime/composables/index.d.ts.map +1 -1
- package/dist/runtime/composables/index.js +2 -0
- package/dist/runtime/composables/index.js.map +1 -1
- package/dist/runtime/composables/use-active-headings.d.ts +24 -0
- package/dist/runtime/composables/use-active-headings.d.ts.map +1 -0
- package/dist/runtime/composables/use-active-headings.js +112 -0
- package/dist/runtime/composables/use-active-headings.js.map +1 -0
- package/dist/runtime/composables/use-content-page.d.ts +45 -0
- package/dist/runtime/composables/use-content-page.d.ts.map +1 -0
- package/dist/runtime/composables/use-content-page.js +179 -0
- package/dist/runtime/composables/use-content-page.js.map +1 -0
- package/dist/runtime/composables/use-content-search.d.ts.map +1 -1
- package/dist/runtime/composables/use-content-search.js +1 -5
- package/dist/runtime/composables/use-content-search.js.map +1 -1
- package/dist/runtime/composables/use-fetch.d.ts +2 -1
- package/dist/runtime/composables/use-fetch.d.ts.map +1 -1
- package/dist/runtime/composables/use-fetch.js +112 -43
- package/dist/runtime/composables/use-fetch.js.map +1 -1
- package/dist/runtime/composables/use-route.d.ts.map +1 -1
- package/dist/runtime/composables/use-route.js +39 -11
- package/dist/runtime/composables/use-route.js.map +1 -1
- package/dist/runtime/content/client.js +2 -2
- package/dist/runtime/content/client.js.map +1 -1
- package/dist/runtime/entry-server-template.d.ts +16 -1
- package/dist/runtime/entry-server-template.d.ts.map +1 -1
- package/dist/runtime/entry-server-template.js +120 -13
- package/dist/runtime/entry-server-template.js.map +1 -1
- package/dist/types/config.d.ts +45 -4
- package/dist/types/config.d.ts.map +1 -1
- package/dist/types/config.js.map +1 -1
- package/dist/types/middleware.d.ts +2 -2
- package/dist/types/middleware.d.ts.map +1 -1
- package/package.json +22 -19
- package/.github/copilot-instructions.md +0 -169
- package/.github/workflows/publish.yml +0 -257
- package/.nvmrc +0 -1
- package/CHANGELOG.md +0 -236
- package/CLAUDE.md +0 -113
- package/commits.txt +0 -1
- package/cypress.config.ts +0 -16
- package/docs/authentication.md +0 -285
- package/docs/cli.md +0 -324
- package/docs/components.md +0 -237
- package/docs/composables.md +0 -907
- package/docs/configuration.md +0 -696
- package/docs/content.md +0 -570
- package/docs/data-loading.md +0 -336
- package/docs/getting-started.md +0 -237
- package/docs/head-management.md +0 -212
- package/docs/i18n.md +0 -159
- package/docs/layouts.md +0 -224
- package/docs/middleware.md +0 -234
- package/docs/plugins.md +0 -170
- package/docs/rendering-modes.md +0 -377
- package/docs/routing.md +0 -485
- package/docs/server-api.md +0 -253
- package/docs/testing.md +0 -455
- package/docs/use-fetch.md +0 -183
- package/e2e/cypress/e2e/api.cy.ts +0 -123
- package/e2e/cypress/e2e/async-component.cy.ts +0 -27
- package/e2e/cypress/e2e/component-splitting.cy.ts +0 -50
- package/e2e/cypress/e2e/content.cy.ts +0 -425
- package/e2e/cypress/e2e/cookie.cy.ts +0 -85
- package/e2e/cypress/e2e/data.cy.ts +0 -158
- package/e2e/cypress/e2e/error-boundary.cy.ts +0 -88
- package/e2e/cypress/e2e/fouc.cy.ts +0 -254
- package/e2e/cypress/e2e/group-meta.cy.ts +0 -36
- package/e2e/cypress/e2e/head.cy.ts +0 -89
- package/e2e/cypress/e2e/i18n.cy.ts +0 -79
- package/e2e/cypress/e2e/interactive.cy.ts +0 -137
- package/e2e/cypress/e2e/isr-nested-runtime.cy.ts +0 -102
- package/e2e/cypress/e2e/jit-css-custom-colors.cy.ts +0 -43
- package/e2e/cypress/e2e/middleware-chain.cy.ts +0 -89
- package/e2e/cypress/e2e/middleware-status.cy.ts +0 -30
- package/e2e/cypress/e2e/middleware.cy.ts +0 -45
- package/e2e/cypress/e2e/navigate.cy.ts +0 -39
- package/e2e/cypress/e2e/observability.cy.ts +0 -77
- package/e2e/cypress/e2e/per-route-error.cy.ts +0 -42
- package/e2e/cypress/e2e/per-route-render.cy.ts +0 -70
- package/e2e/cypress/e2e/preview-hardening.cy.ts +0 -88
- package/e2e/cypress/e2e/routes.cy.ts +0 -128
- package/e2e/cypress/e2e/seo-meta.cy.ts +0 -108
- package/e2e/cypress/e2e/server-middleware.cy.ts +0 -46
- package/e2e/cypress/e2e/session-rotation.cy.ts +0 -25
- package/e2e/cypress/e2e/session.cy.ts +0 -73
- package/e2e/cypress/e2e/ssr-render-error.cy.ts +0 -68
- package/e2e/cypress/e2e/synthetic-404.cy.ts +0 -45
- package/e2e/cypress/e2e/use-page-data.cy.ts +0 -122
- package/e2e/cypress/e2e/use-state.cy.ts +0 -138
- package/e2e/cypress/support/commands.ts +0 -120
- package/e2e/cypress/support/e2e.ts +0 -10
- package/e2e/cypress/tsconfig.json +0 -14
- package/e2e/kitchen-sink/app/components/ks-badge.ts +0 -8
- package/e2e/kitchen-sink/app/composables/useKsCounter.ts +0 -9
- package/e2e/kitchen-sink/app/error.ts +0 -18
- package/e2e/kitchen-sink/app/layouts/admin.ts +0 -13
- package/e2e/kitchen-sink/app/layouts/default.ts +0 -25
- package/e2e/kitchen-sink/app/layouts/group.ts +0 -9
- package/e2e/kitchen-sink/app/layouts/minimal.ts +0 -7
- package/e2e/kitchen-sink/app/loading.ts +0 -9
- package/e2e/kitchen-sink/app/middleware/auth.ts +0 -9
- package/e2e/kitchen-sink/app/middleware/custom-log.ts +0 -4
- package/e2e/kitchen-sink/app/middleware/group-auth.ts +0 -7
- package/e2e/kitchen-sink/app/middleware/logger.ts +0 -14
- package/e2e/kitchen-sink/app/pages/(auth)/login.ts +0 -13
- package/e2e/kitchen-sink/app/pages/(auth)/protected.ts +0 -16
- package/e2e/kitchen-sink/app/pages/404.ts +0 -9
- package/e2e/kitchen-sink/app/pages/about.ts +0 -17
- package/e2e/kitchen-sink/app/pages/admin/_layout.ts +0 -1
- package/e2e/kitchen-sink/app/pages/admin/dashboard.ts +0 -11
- package/e2e/kitchen-sink/app/pages/async-component-error-test.ts +0 -18
- package/e2e/kitchen-sink/app/pages/async-component-test.ts +0 -18
- package/e2e/kitchen-sink/app/pages/blog/[slug].ts +0 -59
- package/e2e/kitchen-sink/app/pages/blog/index.ts +0 -51
- package/e2e/kitchen-sink/app/pages/content-blog.ts +0 -37
- package/e2e/kitchen-sink/app/pages/content-doc.ts +0 -42
- package/e2e/kitchen-sink/app/pages/content-fallback.ts +0 -36
- package/e2e/kitchen-sink/app/pages/content-guides.ts +0 -35
- package/e2e/kitchen-sink/app/pages/content-index.ts +0 -39
- package/e2e/kitchen-sink/app/pages/content-search.ts +0 -36
- package/e2e/kitchen-sink/app/pages/cookie-test.ts +0 -22
- package/e2e/kitchen-sink/app/pages/counter.ts +0 -17
- package/e2e/kitchen-sink/app/pages/group-auth-blocked.ts +0 -9
- package/e2e/kitchen-sink/app/pages/group-meta-test/_layout.ts +0 -6
- package/e2e/kitchen-sink/app/pages/group-meta-test/custom-mw.ts +0 -14
- package/e2e/kitchen-sink/app/pages/group-meta-test/page.ts +0 -9
- package/e2e/kitchen-sink/app/pages/group-meta-test/protected.ts +0 -8
- package/e2e/kitchen-sink/app/pages/head.ts +0 -20
- package/e2e/kitchen-sink/app/pages/i18n-test.ts +0 -14
- package/e2e/kitchen-sink/app/pages/index.ts +0 -27
- package/e2e/kitchen-sink/app/pages/isr-test.ts +0 -17
- package/e2e/kitchen-sink/app/pages/items/[id].ts +0 -20
- package/e2e/kitchen-sink/app/pages/jit-css-custom-colors-test.ts +0 -14
- package/e2e/kitchen-sink/app/pages/loader-error-test.ts +0 -13
- package/e2e/kitchen-sink/app/pages/loader-props-test.ts +0 -19
- package/e2e/kitchen-sink/app/pages/loader-response-error-test.ts +0 -13
- package/e2e/kitchen-sink/app/pages/middleware-chain-test.ts +0 -12
- package/e2e/kitchen-sink/app/pages/middleware-status-test.ts +0 -9
- package/e2e/kitchen-sink/app/pages/navigate-test.ts +0 -16
- package/e2e/kitchen-sink/app/pages/observability-test.ts +0 -25
- package/e2e/kitchen-sink/app/pages/per-route-error-test.error.ts +0 -13
- package/e2e/kitchen-sink/app/pages/per-route-error-test.ts +0 -15
- package/e2e/kitchen-sink/app/pages/plugin-dsd-test.ts +0 -10
- package/e2e/kitchen-sink/app/pages/render-error-test.ts +0 -12
- package/e2e/kitchen-sink/app/pages/render-server-test.ts +0 -12
- package/e2e/kitchen-sink/app/pages/render-spa-test.ts +0 -12
- package/e2e/kitchen-sink/app/pages/route-info.ts +0 -14
- package/e2e/kitchen-sink/app/pages/seo-test.ts +0 -23
- package/e2e/kitchen-sink/app/pages/session-rotation-test.ts +0 -25
- package/e2e/kitchen-sink/app/pages/use-state-test.ts +0 -37
- package/e2e/kitchen-sink/app/plugins/01.setup.ts +0 -7
- package/e2e/kitchen-sink/app/plugins/02.ks-plugin-components.ts +0 -27
- package/e2e/kitchen-sink/cer-auto-imports.d.ts +0 -51
- package/e2e/kitchen-sink/cer-env.d.ts +0 -35
- package/e2e/kitchen-sink/cer-tsconfig.json +0 -30
- package/e2e/kitchen-sink/cer.config.ts +0 -43
- package/e2e/kitchen-sink/content/01.guides/01.index.md +0 -8
- package/e2e/kitchen-sink/content/01.guides/02.intro.md +0 -8
- package/e2e/kitchen-sink/content/01.guides/10.advanced.md +0 -8
- package/e2e/kitchen-sink/content/blog/2026-04-01-hello.md +0 -26
- package/e2e/kitchen-sink/content/blog/2026-04-02-draft.md +0 -10
- package/e2e/kitchen-sink/content/blog/index.md +0 -8
- package/e2e/kitchen-sink/content/blog/no-frontmatter.md +0 -7
- package/e2e/kitchen-sink/content/docs/getting-started.md +0 -48
- package/e2e/kitchen-sink/content/index.md +0 -16
- package/e2e/kitchen-sink/server/api/echo.ts +0 -12
- package/e2e/kitchen-sink/server/api/health.ts +0 -3
- package/e2e/kitchen-sink/server/api/posts/[slug].ts +0 -11
- package/e2e/kitchen-sink/server/api/posts/index.ts +0 -5
- package/e2e/kitchen-sink/server/api/session.ts +0 -23
- package/e2e/kitchen-sink/server/data/posts.ts +0 -21
- package/e2e/kitchen-sink/server/middleware/01-headers.ts +0 -6
- package/e2e/kitchen-sink/server/middleware/02-status-test.ts +0 -10
- package/e2e/kitchen-sink/tsconfig.json +0 -3
- package/e2e/scripts/clean.mjs +0 -14
- package/eslint.config.ts +0 -22
- package/src/__tests__/cli/adapters/cloudflare-worker.integration.test.ts +0 -132
- package/src/__tests__/cli/adapters/cloudflare.test.ts +0 -332
- package/src/__tests__/cli/adapters/netlify-bridge.integration.test.ts +0 -139
- package/src/__tests__/cli/adapters/netlify.test.ts +0 -286
- package/src/__tests__/cli/adapters/vercel-launcher.integration.test.ts +0 -129
- package/src/__tests__/cli/adapters/vercel.test.ts +0 -263
- package/src/__tests__/cli/preview-hardening.test.ts +0 -265
- package/src/__tests__/cli/preview-isr.test.ts +0 -320
- package/src/__tests__/index.test.ts +0 -21
- package/src/__tests__/plugin/app-template.test.ts +0 -166
- package/src/__tests__/plugin/build-ssg-render.test.ts +0 -155
- package/src/__tests__/plugin/build-ssg.test.ts +0 -598
- package/src/__tests__/plugin/build-ssr.test.ts +0 -192
- package/src/__tests__/plugin/cer-app-plugin.test.ts +0 -552
- package/src/__tests__/plugin/content/emitter.test.ts +0 -117
- package/src/__tests__/plugin/content/loader.test.ts +0 -154
- package/src/__tests__/plugin/content/parser.test.ts +0 -381
- package/src/__tests__/plugin/content/path-utils.test.ts +0 -69
- package/src/__tests__/plugin/content/search.test.ts +0 -119
- package/src/__tests__/plugin/dev-server.test.ts +0 -813
- package/src/__tests__/plugin/dts-generator.test.ts +0 -394
- package/src/__tests__/plugin/entry-server-template.test.ts +0 -385
- package/src/__tests__/plugin/generated-dir.test.ts +0 -144
- package/src/__tests__/plugin/html-post-process.test.ts +0 -146
- package/src/__tests__/plugin/path-utils.test.ts +0 -411
- package/src/__tests__/plugin/resolve-config.test.ts +0 -233
- package/src/__tests__/plugin/scanner.test.ts +0 -186
- package/src/__tests__/plugin/transforms/auto-import.test.ts +0 -510
- package/src/__tests__/plugin/transforms/head-inject.test.ts +0 -178
- package/src/__tests__/plugin/virtual/composables.test.ts +0 -57
- package/src/__tests__/plugin/virtual/content-components.test.ts +0 -66
- package/src/__tests__/plugin/virtual/error.test.ts +0 -71
- package/src/__tests__/plugin/virtual/layouts.test.ts +0 -70
- package/src/__tests__/plugin/virtual/loading.test.ts +0 -72
- package/src/__tests__/plugin/virtual/middleware.test.ts +0 -83
- package/src/__tests__/plugin/virtual/plugins.test.ts +0 -129
- package/src/__tests__/plugin/virtual/routes.test.ts +0 -884
- package/src/__tests__/plugin/virtual/server-api.test.ts +0 -164
- package/src/__tests__/plugin/virtual/server-middleware.test.ts +0 -102
- package/src/__tests__/runtime/app-template.test.ts +0 -208
- package/src/__tests__/runtime/define-middleware.test.ts +0 -64
- package/src/__tests__/runtime/define-server-middleware.test.ts +0 -54
- package/src/__tests__/runtime/entry-client-template.test.ts +0 -61
- package/src/__tests__/runtime/isr-handler.test.ts +0 -338
- package/src/__tests__/runtime/oauth/handler.test.ts +0 -358
- package/src/__tests__/runtime/oauth/providers.test.ts +0 -47
- package/src/__tests__/runtime/oauth-index.test.ts +0 -43
- package/src/__tests__/runtime/use-auth.test.ts +0 -169
- package/src/__tests__/runtime/use-content-search-composable.test.ts +0 -405
- package/src/__tests__/runtime/use-content-search.test.ts +0 -163
- package/src/__tests__/runtime/use-content.test.ts +0 -226
- package/src/__tests__/runtime/use-cookie.test.ts +0 -277
- package/src/__tests__/runtime/use-fetch-component.test.ts +0 -214
- package/src/__tests__/runtime/use-fetch.test.ts +0 -377
- package/src/__tests__/runtime/use-head.test.ts +0 -311
- package/src/__tests__/runtime/use-inject-client.test.ts +0 -67
- package/src/__tests__/runtime/use-inject.test.ts +0 -66
- package/src/__tests__/runtime/use-locale.test.ts +0 -152
- package/src/__tests__/runtime/use-navigate.test.ts +0 -121
- package/src/__tests__/runtime/use-page-data.test.ts +0 -298
- package/src/__tests__/runtime/use-route.test.ts +0 -156
- package/src/__tests__/runtime/use-runtime-config.test.ts +0 -182
- package/src/__tests__/runtime/use-seo-meta.test.ts +0 -109
- package/src/__tests__/runtime/use-session.test.ts +0 -320
- package/src/__tests__/runtime/use-state.test.ts +0 -340
- package/src/__tests__/types/config.test.ts +0 -18
- package/src/cli/adapters/cloudflare.ts +0 -335
- package/src/cli/adapters/netlify.ts +0 -326
- package/src/cli/adapters/vercel.ts +0 -311
- package/src/cli/commands/adapt.ts +0 -84
- package/src/cli/commands/build.ts +0 -165
- package/src/cli/commands/dev.ts +0 -125
- package/src/cli/commands/generate.ts +0 -91
- package/src/cli/commands/preview-isr.ts +0 -172
- package/src/cli/commands/preview.ts +0 -523
- package/src/cli/create/index.ts +0 -275
- package/src/cli/create/templates/shared/.gitignore.tpl +0 -25
- package/src/cli/create/templates/shared/app/layouts/default.ts.tpl +0 -15
- package/src/cli/create/templates/shared/app/pages/index.ts.tpl +0 -8
- package/src/cli/create/templates/shared/index.html.tpl +0 -12
- package/src/cli/create/templates/shared/tsconfig.json.tpl +0 -6
- package/src/cli/create/templates/spa/cer.config.ts.tpl +0 -6
- package/src/cli/create/templates/spa/package.json.tpl +0 -18
- package/src/cli/create/templates/ssg/cer.config.ts.tpl +0 -10
- package/src/cli/create/templates/ssg/package.json.tpl +0 -19
- package/src/cli/create/templates/ssr/cer.config.ts.tpl +0 -6
- package/src/cli/create/templates/ssr/package.json.tpl +0 -18
- package/src/cli/index.ts +0 -22
- package/src/index.ts +0 -20
- package/src/plugin/build-ssg.ts +0 -403
- package/src/plugin/build-ssr.ts +0 -134
- package/src/plugin/content/emitter.ts +0 -50
- package/src/plugin/content/index.ts +0 -233
- package/src/plugin/content/parser.ts +0 -259
- package/src/plugin/content/path-utils.ts +0 -55
- package/src/plugin/content/scanner.ts +0 -26
- package/src/plugin/content/search.ts +0 -28
- package/src/plugin/dev-server.ts +0 -379
- package/src/plugin/dts-generator.ts +0 -273
- package/src/plugin/generated-dir.ts +0 -121
- package/src/plugin/html-post-process.ts +0 -96
- package/src/plugin/index.ts +0 -584
- package/src/plugin/path-utils.ts +0 -186
- package/src/plugin/scanner.ts +0 -65
- package/src/plugin/transforms/auto-import.ts +0 -206
- package/src/plugin/transforms/head-inject.ts +0 -161
- package/src/plugin/virtual/composables.ts +0 -28
- package/src/plugin/virtual/content-components.ts +0 -83
- package/src/plugin/virtual/error.ts +0 -34
- package/src/plugin/virtual/layouts.ts +0 -41
- package/src/plugin/virtual/loading.ts +0 -32
- package/src/plugin/virtual/middleware.ts +0 -45
- package/src/plugin/virtual/plugins.ts +0 -46
- package/src/plugin/virtual/routes.ts +0 -514
- package/src/plugin/virtual/server-api.ts +0 -85
- package/src/plugin/virtual/server-middleware.ts +0 -44
- package/src/runtime/app-template.ts +0 -377
- package/src/runtime/composables/define-middleware.ts +0 -17
- package/src/runtime/composables/define-server-middleware.ts +0 -18
- package/src/runtime/composables/index.ts +0 -27
- package/src/runtime/composables/use-auth.ts +0 -125
- package/src/runtime/composables/use-content-search.ts +0 -205
- package/src/runtime/composables/use-content.ts +0 -146
- package/src/runtime/composables/use-cookie.ts +0 -135
- package/src/runtime/composables/use-fetch.ts +0 -438
- package/src/runtime/composables/use-head.ts +0 -234
- package/src/runtime/composables/use-inject.ts +0 -49
- package/src/runtime/composables/use-locale.ts +0 -109
- package/src/runtime/composables/use-navigate.ts +0 -58
- package/src/runtime/composables/use-page-data.ts +0 -93
- package/src/runtime/composables/use-route.ts +0 -71
- package/src/runtime/composables/use-runtime-config.ts +0 -123
- package/src/runtime/composables/use-seo-meta.ts +0 -80
- package/src/runtime/composables/use-session.ts +0 -186
- package/src/runtime/composables/use-state.ts +0 -92
- package/src/runtime/content/client.ts +0 -168
- package/src/runtime/entry-client-template.ts +0 -39
- package/src/runtime/entry-server-template.ts +0 -493
- package/src/runtime/isr-handler.ts +0 -184
- package/src/runtime/oauth/handler.ts +0 -407
- package/src/runtime/oauth/index.ts +0 -49
- package/src/runtime/oauth/providers.ts +0 -38
- package/src/types/api.ts +0 -40
- package/src/types/config.ts +0 -379
- package/src/types/content.ts +0 -66
- package/src/types/index.ts +0 -7
- package/src/types/middleware.ts +0 -63
- package/src/types/page.ts +0 -117
- package/src/types/plugin.ts +0 -34
- package/tsconfig.build.json +0 -10
- package/tsconfig.json +0 -19
- package/vitest.config.ts +0 -33
|
@@ -1,514 +0,0 @@
|
|
|
1
|
-
import { existsSync } from 'node:fs'
|
|
2
|
-
import { basename, dirname, join, relative } from 'node:path'
|
|
3
|
-
import { readFile } from 'node:fs/promises'
|
|
4
|
-
import { scanDirectory } from '../scanner.js'
|
|
5
|
-
import { buildRouteEntry, sortRoutes } from '../path-utils.js'
|
|
6
|
-
|
|
7
|
-
/**
|
|
8
|
-
* Extracts the middleware array from a page file's source code without
|
|
9
|
-
* importing the module. Handles both single-quoted and double-quoted strings.
|
|
10
|
-
*
|
|
11
|
-
* Matches patterns like:
|
|
12
|
-
* middleware: ['auth', 'admin']
|
|
13
|
-
* middleware: ["auth"]
|
|
14
|
-
*/
|
|
15
|
-
function extractMiddleware(source: string): string[] {
|
|
16
|
-
const match = source.match(/middleware\s*:\s*\[([^\]]*)\]/)
|
|
17
|
-
if (!match) return []
|
|
18
|
-
const inner = match[1]
|
|
19
|
-
const names = inner.match(/['"]([^'"]+)['"]/g)
|
|
20
|
-
if (!names) return []
|
|
21
|
-
return names.map((s) => s.replace(/['"]/g, ''))
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
/**
|
|
25
|
-
* Extracts the layout name from a page file's source code without importing
|
|
26
|
-
* the module. Returns null when no layout is declared (caller defaults to
|
|
27
|
-
* 'default').
|
|
28
|
-
*
|
|
29
|
-
* Matches patterns like:
|
|
30
|
-
* layout: 'minimal'
|
|
31
|
-
* layout: "admin"
|
|
32
|
-
*/
|
|
33
|
-
function extractLayout(source: string): string | null {
|
|
34
|
-
const match = source.match(/layout\s*:\s*['"]([^'"]+)['"]/)
|
|
35
|
-
return match ? match[1] : null
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
/**
|
|
39
|
-
* Extracts the `ssg.revalidate` number from a page file's source.
|
|
40
|
-
* Returns null when not declared.
|
|
41
|
-
*
|
|
42
|
-
* Matches patterns like:
|
|
43
|
-
* revalidate: 60
|
|
44
|
-
* revalidate: 3600
|
|
45
|
-
*/
|
|
46
|
-
function extractRevalidate(source: string): number | null {
|
|
47
|
-
const match = source.match(/revalidate\s*:\s*(\d+)/)
|
|
48
|
-
return match ? parseInt(match[1], 10) : null
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
/**
|
|
52
|
-
* Extracts the `transition` value from a page file's source.
|
|
53
|
-
* Returns the transition name string, true (boolean), or null if absent.
|
|
54
|
-
*
|
|
55
|
-
* Matches patterns like:
|
|
56
|
-
* transition: 'fade'
|
|
57
|
-
* transition: true
|
|
58
|
-
*/
|
|
59
|
-
function extractTransition(source: string): string | boolean | null {
|
|
60
|
-
const strMatch = source.match(/transition\s*:\s*['"]([^'"]+)['"]/)
|
|
61
|
-
if (strMatch) return strMatch[1]
|
|
62
|
-
const boolMatch = source.match(/transition\s*:\s*(true|false)/)
|
|
63
|
-
if (boolMatch) return boolMatch[1] === 'true'
|
|
64
|
-
return null
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
/**
|
|
68
|
-
* Extracts the per-route `hydrate` strategy from a page file's source.
|
|
69
|
-
* Returns 'load', 'idle', 'visible', 'none', or null if absent.
|
|
70
|
-
* 'load' is the default — callers skip emitting it to keep the bundle lean.
|
|
71
|
-
*
|
|
72
|
-
* Matches patterns like:
|
|
73
|
-
* hydrate: 'idle'
|
|
74
|
-
* hydrate: 'visible'
|
|
75
|
-
* hydrate: 'none'
|
|
76
|
-
*/
|
|
77
|
-
function extractHydrate(source: string): 'load' | 'idle' | 'visible' | 'none' | null {
|
|
78
|
-
const match = source.match(/hydrate\s*:\s*['"]([^'"]+)['"]/)
|
|
79
|
-
if (!match) return null
|
|
80
|
-
const val = match[1]
|
|
81
|
-
if (val === 'load' || val === 'idle' || val === 'visible' || val === 'none') return val
|
|
82
|
-
return null
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
/**
|
|
86
|
-
* Extracts the per-route `render` strategy from a page file's source.
|
|
87
|
-
* Returns 'static', 'server', 'spa', or null if absent.
|
|
88
|
-
*
|
|
89
|
-
* Matches patterns like:
|
|
90
|
-
* render: 'server'
|
|
91
|
-
* render: 'spa'
|
|
92
|
-
* render: 'static'
|
|
93
|
-
*/
|
|
94
|
-
function extractRender(source: string): 'static' | 'server' | 'spa' | null {
|
|
95
|
-
const match = source.match(/render\s*:\s*['"]([^'"]+)['"]/)
|
|
96
|
-
if (!match) return null
|
|
97
|
-
const val = match[1]
|
|
98
|
-
if (val === 'static' || val === 'server' || val === 'spa') return val
|
|
99
|
-
return null
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
/**
|
|
103
|
-
* Extracts the `title` string from a page file's `meta` export.
|
|
104
|
-
* Returns null when not declared.
|
|
105
|
-
*
|
|
106
|
-
* Matches patterns like:
|
|
107
|
-
* title: 'My Page Title'
|
|
108
|
-
* title: "My Page Title"
|
|
109
|
-
*/
|
|
110
|
-
function extractTitle(source: string): string | null {
|
|
111
|
-
const match = source.match(/title\s*:\s*['"]([^'"]+)['"]/)
|
|
112
|
-
return match ? match[1] : null
|
|
113
|
-
}
|
|
114
|
-
|
|
115
|
-
/**
|
|
116
|
-
* Reads a `_layout.ts` file and returns the group-level meta it exports.
|
|
117
|
-
* Group meta applies to all pages in the same directory and subdirectories.
|
|
118
|
-
*
|
|
119
|
-
* Reads:
|
|
120
|
-
* - `export const meta = { middleware: ['auth', 'admin'] }` → group middleware
|
|
121
|
-
* - `export const meta = { layout: 'minimal' }` → group layout override
|
|
122
|
-
* - `export default 'minimal'` → group layout (legacy form, still supported)
|
|
123
|
-
*
|
|
124
|
-
* Page-level meta takes precedence over group meta (group provides defaults only).
|
|
125
|
-
*/
|
|
126
|
-
async function readGroupMeta(layoutFile: string): Promise<{ middleware: string[]; layout: string | null; layoutChainExtra: string | null }> {
|
|
127
|
-
try {
|
|
128
|
-
const src = await readFile(layoutFile, 'utf-8')
|
|
129
|
-
// Legacy: export default 'layoutName'
|
|
130
|
-
const defaultMatch = src.match(/export\s+default\s+['"]([^'"]+)['"]/)
|
|
131
|
-
const layoutChainExtra = defaultMatch ? defaultMatch[1] : null
|
|
132
|
-
// meta.middleware
|
|
133
|
-
const mwMatch = src.match(/middleware\s*:\s*\[([^\]]*)\]/)
|
|
134
|
-
let middleware: string[] = []
|
|
135
|
-
if (mwMatch) {
|
|
136
|
-
const names = mwMatch[1].match(/['"]([^'"]+)['"]/g)
|
|
137
|
-
if (names) middleware = names.map((s) => s.replace(/['"]/g, ''))
|
|
138
|
-
}
|
|
139
|
-
// meta.layout (explicit override in meta object)
|
|
140
|
-
const layoutMatch = src.match(/layout\s*:\s*['"]([^'"]+)['"]/)
|
|
141
|
-
const layout = layoutMatch ? layoutMatch[1] : null
|
|
142
|
-
return { middleware, layout, layoutChainExtra }
|
|
143
|
-
} catch {
|
|
144
|
-
return { middleware: [], layout: null, layoutChainExtra: null }
|
|
145
|
-
}
|
|
146
|
-
}
|
|
147
|
-
|
|
148
|
-
/**
|
|
149
|
-
* Resolves the layout chain for a page by walking its ancestor directories
|
|
150
|
-
* inside pagesDir looking for `_layout.ts` files. Each `_layout.ts` must
|
|
151
|
-
* export a default string naming a layout in `app/layouts/`.
|
|
152
|
-
*
|
|
153
|
-
* Returns null when no nested layouts are found (single-layout path is used).
|
|
154
|
-
*
|
|
155
|
-
* Example:
|
|
156
|
-
* app/pages/admin/_layout.ts → export default 'minimal'
|
|
157
|
-
* app/pages/admin/users.ts → meta.layout: 'default' (or omitted)
|
|
158
|
-
* → layoutChain = ['default', 'minimal']
|
|
159
|
-
*/
|
|
160
|
-
async function resolveLayoutChain(
|
|
161
|
-
filePath: string,
|
|
162
|
-
pagesDir: string,
|
|
163
|
-
outerLayout: string | null,
|
|
164
|
-
): Promise<string[] | null> {
|
|
165
|
-
const rel = relative(pagesDir, filePath)
|
|
166
|
-
const parts = rel.split('/').slice(0, -1) // directory segments only
|
|
167
|
-
|
|
168
|
-
if (parts.length === 0) return null
|
|
169
|
-
|
|
170
|
-
const extras: string[] = []
|
|
171
|
-
let currentDir = pagesDir
|
|
172
|
-
for (const part of parts) {
|
|
173
|
-
currentDir = join(currentDir, part)
|
|
174
|
-
const layoutFile = join(currentDir, '_layout.ts')
|
|
175
|
-
if (existsSync(layoutFile)) {
|
|
176
|
-
const { layoutChainExtra } = await readGroupMeta(layoutFile)
|
|
177
|
-
if (layoutChainExtra) extras.push(layoutChainExtra)
|
|
178
|
-
}
|
|
179
|
-
}
|
|
180
|
-
|
|
181
|
-
if (extras.length === 0) return null
|
|
182
|
-
return [outerLayout ?? 'default', ...extras]
|
|
183
|
-
}
|
|
184
|
-
|
|
185
|
-
/**
|
|
186
|
-
* Resolves group-level meta (middleware + layout) from ancestor `_layout.ts` files.
|
|
187
|
-
* The deepest (most-specific) `_layout.ts` wins when multiple levels define the same field.
|
|
188
|
-
* Page-level meta always takes precedence over group meta.
|
|
189
|
-
*/
|
|
190
|
-
async function resolveGroupMeta(
|
|
191
|
-
filePath: string,
|
|
192
|
-
pagesDir: string,
|
|
193
|
-
): Promise<{ middleware: string[]; layout: string | null }> {
|
|
194
|
-
const rel = relative(pagesDir, filePath)
|
|
195
|
-
const parts = rel.split('/').slice(0, -1)
|
|
196
|
-
|
|
197
|
-
let groupMiddleware: string[] = []
|
|
198
|
-
let groupLayout: string | null = null
|
|
199
|
-
|
|
200
|
-
let currentDir = pagesDir
|
|
201
|
-
for (const part of parts) {
|
|
202
|
-
currentDir = join(currentDir, part)
|
|
203
|
-
const layoutFile = join(currentDir, '_layout.ts')
|
|
204
|
-
if (existsSync(layoutFile)) {
|
|
205
|
-
const { middleware, layout } = await readGroupMeta(layoutFile)
|
|
206
|
-
// Deeper _layout.ts wins: overwrite (more-specific takes precedence)
|
|
207
|
-
if (middleware.length > 0) groupMiddleware = middleware
|
|
208
|
-
if (layout !== null) groupLayout = layout
|
|
209
|
-
}
|
|
210
|
-
}
|
|
211
|
-
|
|
212
|
-
return { middleware: groupMiddleware, layout: groupLayout }
|
|
213
|
-
}
|
|
214
|
-
|
|
215
|
-
/**
|
|
216
|
-
* Resolves the per-route error tag by checking for:
|
|
217
|
-
* 1. Co-located `<page>.error.ts` alongside the page file
|
|
218
|
-
* 2. Directory-level `_error.ts` in the same directory as the page
|
|
219
|
-
*
|
|
220
|
-
* Returns { errorTag, errorFilePath } when found, null otherwise.
|
|
221
|
-
*/
|
|
222
|
-
function resolveRouteErrorTag(
|
|
223
|
-
filePath: string,
|
|
224
|
-
pagesDir: string,
|
|
225
|
-
pageTagName: string,
|
|
226
|
-
): { errorTag: string; errorFilePath: string } | null {
|
|
227
|
-
// 1. Co-located: foo.ts → foo.error.ts
|
|
228
|
-
const colocated = filePath.replace(/\.ts$/, '.error.ts')
|
|
229
|
-
if (existsSync(colocated)) {
|
|
230
|
-
return { errorTag: pageTagName + '-error', errorFilePath: colocated }
|
|
231
|
-
}
|
|
232
|
-
// 2. Directory-level: _error.ts in the same dir
|
|
233
|
-
const dirError = join(dirname(filePath), '_error.ts')
|
|
234
|
-
if (existsSync(dirError)) {
|
|
235
|
-
// Tag: based on directory relative to pagesDir
|
|
236
|
-
const relDir = relative(pagesDir, dirname(filePath))
|
|
237
|
-
const dirParts = relDir.split('/').filter(Boolean)
|
|
238
|
-
const tag = dirParts.length > 0 ? `page-${dirParts.join('-')}-error` : 'page-error'
|
|
239
|
-
return { errorTag: tag.toLowerCase().replace(/-+/g, '-').replace(/^-|-$/g, ''), errorFilePath: dirError }
|
|
240
|
-
}
|
|
241
|
-
return null
|
|
242
|
-
}
|
|
243
|
-
|
|
244
|
-
export interface I18nRouteConfig {
|
|
245
|
-
locales: string[]
|
|
246
|
-
defaultLocale: string
|
|
247
|
-
strategy: 'prefix' | 'prefix_except_default' | 'no_prefix'
|
|
248
|
-
}
|
|
249
|
-
|
|
250
|
-
/**
|
|
251
|
-
* Generates the virtual:cer-routes module code.
|
|
252
|
-
*
|
|
253
|
-
* Each page module is loaded lazily via a `load()` function — a dynamic
|
|
254
|
-
* import that both registers the custom element (side-effect of component())
|
|
255
|
-
* and returns the tag name as `default`. This lets Vite split each page into
|
|
256
|
-
* its own chunk so only the routes the user actually visits are downloaded.
|
|
257
|
-
*
|
|
258
|
-
* Middleware names and layout names are extracted at build time with a
|
|
259
|
-
* lightweight regex so no eager import is needed.
|
|
260
|
-
*
|
|
261
|
-
* Special conventions:
|
|
262
|
-
* app/pages/404.ts → path "/:all*" (catch-all not-found page)
|
|
263
|
-
*
|
|
264
|
-
* When `i18n` is provided, non-catch-all routes are duplicated for each locale:
|
|
265
|
-
* strategy 'prefix' → `/en/about`, `/fr/about`
|
|
266
|
-
* strategy 'prefix_except_default' → `/about`, `/fr/about`
|
|
267
|
-
* strategy 'no_prefix' → routes are unchanged
|
|
268
|
-
*/
|
|
269
|
-
export async function generateRoutesCode(pagesDir: string, i18n?: I18nRouteConfig | null): Promise<string> {
|
|
270
|
-
if (!existsSync(pagesDir)) {
|
|
271
|
-
return `// AUTO-GENERATED by @jasonshimmy/vite-plugin-cer-app\nconst routes = []\nexport default routes\n`
|
|
272
|
-
}
|
|
273
|
-
|
|
274
|
-
const allFiles = await scanDirectory('**/*.ts', pagesDir)
|
|
275
|
-
// Exclude _layout.ts and _error.ts files — they are directory-level config, not pages.
|
|
276
|
-
const files = allFiles.filter((f) => basename(f) !== '_layout.ts' && basename(f) !== '_error.ts' && !basename(f).endsWith('.error.ts'))
|
|
277
|
-
|
|
278
|
-
if (files.length === 0) {
|
|
279
|
-
return `// AUTO-GENERATED by @jasonshimmy/vite-plugin-cer-app\nconst routes = []\nexport default routes\n`
|
|
280
|
-
}
|
|
281
|
-
|
|
282
|
-
const rawEntries = files.map((f) => {
|
|
283
|
-
const entry = buildRouteEntry(f, pagesDir)
|
|
284
|
-
// 404.ts convention: treat as catch-all not-found route
|
|
285
|
-
if (basename(f) === '404.ts') {
|
|
286
|
-
return { ...entry, routePath: '/:all*', tagName: 'page-404', isDynamic: true, isCatchAll: true }
|
|
287
|
-
}
|
|
288
|
-
return entry
|
|
289
|
-
})
|
|
290
|
-
|
|
291
|
-
// Deduplicate by routePath — keep the first occurrence after sorting to
|
|
292
|
-
// avoid "Duplicate route path detected" warnings (e.g. when both 404.ts
|
|
293
|
-
// and [...all].ts resolve to the same /:all* catch-all route).
|
|
294
|
-
const seen = new Set<string>()
|
|
295
|
-
const entries = rawEntries.filter((e) => {
|
|
296
|
-
if (seen.has(e.routePath)) return false
|
|
297
|
-
seen.add(e.routePath)
|
|
298
|
-
return true
|
|
299
|
-
})
|
|
300
|
-
|
|
301
|
-
const sorted = sortRoutes(entries)
|
|
302
|
-
|
|
303
|
-
// Read each file's source once to extract static metadata without eagerly
|
|
304
|
-
// importing the module, then resolve any nested layout chains.
|
|
305
|
-
const metaPerEntry: Array<{
|
|
306
|
-
middleware: string[]
|
|
307
|
-
layout: string | null
|
|
308
|
-
layoutChain: string[] | null
|
|
309
|
-
revalidate: number | null
|
|
310
|
-
transition: string | boolean | null
|
|
311
|
-
render: 'static' | 'server' | 'spa' | null
|
|
312
|
-
hydrate: 'load' | 'idle' | 'visible' | 'none' | null
|
|
313
|
-
title: string | null
|
|
314
|
-
routeErrorTag: string | null
|
|
315
|
-
routeErrorFilePath: string | null
|
|
316
|
-
}> = await Promise.all(
|
|
317
|
-
sorted.map(async (entry) => {
|
|
318
|
-
try {
|
|
319
|
-
const src = await readFile(entry.filePath, 'utf-8')
|
|
320
|
-
const pageLayout = extractLayout(src)
|
|
321
|
-
const pageMiddleware = extractMiddleware(src)
|
|
322
|
-
|
|
323
|
-
// P2-1: Resolve group meta from ancestor _layout.ts files.
|
|
324
|
-
// Page-level declarations take precedence over group-level defaults.
|
|
325
|
-
const groupMeta = await resolveGroupMeta(entry.filePath, pagesDir)
|
|
326
|
-
const layout = pageLayout ?? groupMeta.layout
|
|
327
|
-
const middleware = pageMiddleware.length > 0 ? pageMiddleware : groupMeta.middleware
|
|
328
|
-
|
|
329
|
-
const layoutChain = await resolveLayoutChain(entry.filePath, pagesDir, layout)
|
|
330
|
-
|
|
331
|
-
// P2-2: Resolve per-route error tag from co-located or directory _error.ts.
|
|
332
|
-
const routeError = resolveRouteErrorTag(entry.filePath, pagesDir, entry.tagName)
|
|
333
|
-
|
|
334
|
-
return {
|
|
335
|
-
middleware,
|
|
336
|
-
layout,
|
|
337
|
-
layoutChain,
|
|
338
|
-
revalidate: extractRevalidate(src),
|
|
339
|
-
transition: extractTransition(src),
|
|
340
|
-
render: extractRender(src),
|
|
341
|
-
hydrate: extractHydrate(src),
|
|
342
|
-
title: extractTitle(src),
|
|
343
|
-
routeErrorTag: routeError?.errorTag ?? null,
|
|
344
|
-
routeErrorFilePath: routeError?.errorFilePath ?? null,
|
|
345
|
-
}
|
|
346
|
-
} catch {
|
|
347
|
-
return { middleware: [], layout: null, layoutChain: null, revalidate: null, transition: null, render: null, hydrate: null, title: null, routeErrorTag: null, routeErrorFilePath: null }
|
|
348
|
-
}
|
|
349
|
-
}),
|
|
350
|
-
)
|
|
351
|
-
|
|
352
|
-
const lines: string[] = ['// AUTO-GENERATED by @jasonshimmy/vite-plugin-cer-app', '']
|
|
353
|
-
|
|
354
|
-
// When i18n is active, expand each non-catch-all route into locale-prefixed variants.
|
|
355
|
-
// Catch-all routes (/:all*) are never prefixed — they match anything including locale paths.
|
|
356
|
-
function buildLocaleRouteItems(routePath: string, loadFn: string, metaStr: string, mwChainBody: string, isCatchAll: boolean): string[] {
|
|
357
|
-
if (!i18n || i18n.strategy === 'no_prefix' || isCatchAll) {
|
|
358
|
-
return [buildRouteItem(routePath, loadFn, metaStr, mwChainBody)]
|
|
359
|
-
}
|
|
360
|
-
const items: string[] = []
|
|
361
|
-
for (const locale of i18n.locales) {
|
|
362
|
-
const isDefault = locale === i18n.defaultLocale
|
|
363
|
-
const skip = isDefault && i18n.strategy === 'prefix_except_default'
|
|
364
|
-
const prefixedPath = skip ? routePath : JSON.stringify(`/${locale}${JSON.parse(routePath)}`)
|
|
365
|
-
const localeMeta = ` meta: { ...${metaStr.trim() ? metaStr.replace(/^\s*meta: \{/, '{').replace(/\},\s*$/, '}') : '{}'}, locale: ${JSON.stringify(locale)} },\n`
|
|
366
|
-
items.push(buildRouteItem(prefixedPath, loadFn, localeMeta, mwChainBody))
|
|
367
|
-
}
|
|
368
|
-
return items
|
|
369
|
-
}
|
|
370
|
-
|
|
371
|
-
function buildRouteItem(routePath: string, loadFn: string, metaStr: string, mwChainBody: string): string {
|
|
372
|
-
if (!mwChainBody) {
|
|
373
|
-
return (
|
|
374
|
-
` {\n` +
|
|
375
|
-
` path: ${routePath},\n` +
|
|
376
|
-
` load: ${loadFn},\n` +
|
|
377
|
-
metaStr +
|
|
378
|
-
` }`
|
|
379
|
-
)
|
|
380
|
-
}
|
|
381
|
-
return (
|
|
382
|
-
` {\n` +
|
|
383
|
-
` path: ${routePath},\n` +
|
|
384
|
-
` load: ${loadFn},\n` +
|
|
385
|
-
metaStr +
|
|
386
|
-
mwChainBody +
|
|
387
|
-
` }`
|
|
388
|
-
)
|
|
389
|
-
}
|
|
390
|
-
|
|
391
|
-
// Track whether any user-defined catch-all route exists.
|
|
392
|
-
const hasCatchAll = sorted.some((e) => e.isCatchAll)
|
|
393
|
-
|
|
394
|
-
// Build routes array with lazy load() functions for code splitting.
|
|
395
|
-
const routeItems = sorted.map((entry, i) => {
|
|
396
|
-
const { middleware: mw, layout, layoutChain, revalidate, transition, render, hydrate, title, routeErrorTag, routeErrorFilePath } = metaPerEntry[i]
|
|
397
|
-
const filePath = JSON.stringify(entry.filePath)
|
|
398
|
-
const tagName = JSON.stringify(entry.tagName)
|
|
399
|
-
const routePath = JSON.stringify(entry.routePath)
|
|
400
|
-
const isNotFoundPage = basename(entry.filePath) === '404.ts'
|
|
401
|
-
|
|
402
|
-
// The load() function dynamically imports the page module which:
|
|
403
|
-
// 1. Runs component() as a side effect, registering the custom element
|
|
404
|
-
// 2. Returns the tag name string as `default` so the router knows what to render
|
|
405
|
-
// 3. Forwards the optional `loader` export for SSR data hydration
|
|
406
|
-
// 4. (P2-2) If a co-located or directory _error.ts exists, imports it as a side-effect
|
|
407
|
-
// and returns its tag name as `errorTag` for per-route error boundaries.
|
|
408
|
-
let loadFn: string
|
|
409
|
-
if (routeErrorFilePath) {
|
|
410
|
-
const errorPath = JSON.stringify(routeErrorFilePath)
|
|
411
|
-
const errorTagLiteral = JSON.stringify(routeErrorTag)
|
|
412
|
-
loadFn = `() => Promise.all([import(${filePath}), import(${errorPath})]).then(([mod]) => ({ default: ${tagName}, loader: mod.loader ?? null, errorTag: ${errorTagLiteral} }))`
|
|
413
|
-
} else {
|
|
414
|
-
loadFn = `() => import(${filePath}).then(mod => ({ default: ${tagName}, loader: mod.loader ?? null }))`
|
|
415
|
-
}
|
|
416
|
-
|
|
417
|
-
// Build meta object — only emit fields that are set
|
|
418
|
-
const metaFields: string[] = []
|
|
419
|
-
if (layoutChain !== null) {
|
|
420
|
-
metaFields.push(`layoutChain: ${JSON.stringify(layoutChain)}`)
|
|
421
|
-
} else if (layout !== null) {
|
|
422
|
-
metaFields.push(`layout: ${JSON.stringify(layout)}`)
|
|
423
|
-
}
|
|
424
|
-
if (revalidate !== null) {
|
|
425
|
-
metaFields.push(`ssg: { revalidate: ${revalidate} }`)
|
|
426
|
-
}
|
|
427
|
-
if (transition !== null) {
|
|
428
|
-
metaFields.push(`transition: ${JSON.stringify(transition)}`)
|
|
429
|
-
}
|
|
430
|
-
if (render !== null) {
|
|
431
|
-
metaFields.push(`render: ${JSON.stringify(render)}`)
|
|
432
|
-
}
|
|
433
|
-
// 'load' is the default — only emit non-default values to keep bundle lean.
|
|
434
|
-
if (hydrate !== null && hydrate !== 'load') {
|
|
435
|
-
metaFields.push(`hydrate: ${JSON.stringify(hydrate)}`)
|
|
436
|
-
}
|
|
437
|
-
if (title !== null) {
|
|
438
|
-
metaFields.push(`title: ${JSON.stringify(title)}`)
|
|
439
|
-
}
|
|
440
|
-
if (isNotFoundPage) {
|
|
441
|
-
metaFields.push(`_cerNotFound: true`)
|
|
442
|
-
}
|
|
443
|
-
// P2-2: Per-route error tag stored in meta for SSR error boundary resolution.
|
|
444
|
-
if (routeErrorTag !== null) {
|
|
445
|
-
metaFields.push(`errorTag: ${JSON.stringify(routeErrorTag)}`)
|
|
446
|
-
}
|
|
447
|
-
const metaStr = metaFields.length > 0 ? ` meta: { ${metaFields.join(', ')} },\n` : ''
|
|
448
|
-
|
|
449
|
-
let mwChainBody = ''
|
|
450
|
-
if (mw.length > 0) {
|
|
451
|
-
// Inline the middleware names as a literal array (extracted at build time)
|
|
452
|
-
// so we never need to eagerly import the page module just to read meta.
|
|
453
|
-
const mwLiteral = JSON.stringify(mw)
|
|
454
|
-
mwChainBody = (
|
|
455
|
-
` beforeEnter: async (to, from) => {\n` +
|
|
456
|
-
` const _hydrationEntry = (globalThis).__CER_HYDRATION_ENTRY__\n` +
|
|
457
|
-
` if (\n` +
|
|
458
|
-
` _hydrationEntry &&\n` +
|
|
459
|
-
` from.path === to.path &&\n` +
|
|
460
|
-
` JSON.stringify(from.params ?? {}) === JSON.stringify(to.params ?? {}) &&\n` +
|
|
461
|
-
` _hydrationEntry.path === to.path &&\n` +
|
|
462
|
-
` JSON.stringify(_hydrationEntry.query ?? {}) === JSON.stringify(to.query ?? {})\n` +
|
|
463
|
-
` ) {\n` +
|
|
464
|
-
` delete (globalThis).__CER_HYDRATION_ENTRY__\n` +
|
|
465
|
-
` return true\n` +
|
|
466
|
-
` }\n` +
|
|
467
|
-
` const { middleware } = await import('virtual:cer-middleware')\n` +
|
|
468
|
-
` const _names = ${mwLiteral}\n` +
|
|
469
|
-
` let _idx = 0\n` +
|
|
470
|
-
` let _guardResult = true\n` +
|
|
471
|
-
` const _runNext = async () => {\n` +
|
|
472
|
-
` if (_idx >= _names.length) return\n` +
|
|
473
|
-
` const name = _names[_idx++]\n` +
|
|
474
|
-
` const handler = middleware[name]\n` +
|
|
475
|
-
` if (typeof handler !== 'function') { await _runNext(); return }\n` +
|
|
476
|
-
` let _calledNext = false\n` +
|
|
477
|
-
` const next = async () => { _calledNext = true; await _runNext() }\n` +
|
|
478
|
-
` let result\n` +
|
|
479
|
-
` try {\n` +
|
|
480
|
-
` result = await handler(to, from, next)\n` +
|
|
481
|
-
` } catch (err) {\n` +
|
|
482
|
-
` console.error('[cer-app] Middleware "' + name + '" threw an error:', err)\n` +
|
|
483
|
-
` _guardResult = false; return\n` +
|
|
484
|
-
` }\n` +
|
|
485
|
-
` if (!_calledNext) {\n` +
|
|
486
|
-
` if (typeof result === 'string') { _guardResult = result; return }\n` +
|
|
487
|
-
` if (result === false) { _guardResult = false; return }\n` +
|
|
488
|
-
` }\n` +
|
|
489
|
-
` }\n` +
|
|
490
|
-
` await _runNext()\n` +
|
|
491
|
-
` return _guardResult\n` +
|
|
492
|
-
` },\n`
|
|
493
|
-
)
|
|
494
|
-
}
|
|
495
|
-
|
|
496
|
-
return buildLocaleRouteItems(routePath, loadFn, metaStr, mwChainBody, entry.isCatchAll)
|
|
497
|
-
})
|
|
498
|
-
|
|
499
|
-
// P1-1: If no user-defined catch-all exists, synthesize a 404 fallback route.
|
|
500
|
-
// The null default tag causes _prepareRequest to return status 404.
|
|
501
|
-
const allRouteItems = routeItems.flat()
|
|
502
|
-
if (!hasCatchAll) {
|
|
503
|
-
allRouteItems.push(` {\n path: '/:all*',\n load: () => Promise.resolve({ default: null, loader: null }),\n meta: { _cerNotFound: true },\n }`)
|
|
504
|
-
}
|
|
505
|
-
|
|
506
|
-
lines.push('const routes = [')
|
|
507
|
-
lines.push(allRouteItems.join(',\n'))
|
|
508
|
-
lines.push(']')
|
|
509
|
-
lines.push('')
|
|
510
|
-
lines.push('export default routes')
|
|
511
|
-
lines.push('')
|
|
512
|
-
|
|
513
|
-
return lines.join('\n')
|
|
514
|
-
}
|
|
@@ -1,85 +0,0 @@
|
|
|
1
|
-
import { existsSync } from 'node:fs'
|
|
2
|
-
import { scanDirectory } from '../scanner.js'
|
|
3
|
-
import { fileToRoutePath } from '../path-utils.js'
|
|
4
|
-
import type { AuthConfig } from '../../types/config.js'
|
|
5
|
-
|
|
6
|
-
/**
|
|
7
|
-
* Generates the virtual:cer-server-api module code.
|
|
8
|
-
* Scans server/api/ and produces an apiRoutes array with path and handlers.
|
|
9
|
-
* When `authConfig` is provided, prepends OAuth initiate / callback / logout routes.
|
|
10
|
-
*/
|
|
11
|
-
export async function generateServerApiCode(serverApiDir: string, authConfig?: AuthConfig | null): Promise<string> {
|
|
12
|
-
const hasOAuth = !!(authConfig?.providers && Object.keys(authConfig.providers).length > 0)
|
|
13
|
-
const files = existsSync(serverApiDir) ? await scanDirectory('**/*.ts', serverApiDir) : []
|
|
14
|
-
|
|
15
|
-
const lines: string[] = ['// AUTO-GENERATED by @jasonshimmy/vite-plugin-cer-app', '']
|
|
16
|
-
|
|
17
|
-
// ── OAuth routes ────────────────────────────────────────────────────────────
|
|
18
|
-
// Injected ahead of user routes so auth paths are never shadowed.
|
|
19
|
-
if (hasOAuth) {
|
|
20
|
-
// Serialise only the fields the handler needs at runtime.
|
|
21
|
-
// clientSecret is server-only (this module is never in the client bundle).
|
|
22
|
-
const serialisedCfg = JSON.stringify({
|
|
23
|
-
providers: Object.fromEntries(
|
|
24
|
-
Object.entries(authConfig!.providers!).map(([name, cfg]) => [
|
|
25
|
-
name,
|
|
26
|
-
cfg
|
|
27
|
-
? {
|
|
28
|
-
clientId: cfg.clientId,
|
|
29
|
-
clientSecret: cfg.clientSecret,
|
|
30
|
-
scope: cfg.scope,
|
|
31
|
-
authorizationUrl: cfg.authorizationUrl,
|
|
32
|
-
tokenUrl: cfg.tokenUrl,
|
|
33
|
-
userInfoUrl: cfg.userInfoUrl,
|
|
34
|
-
}
|
|
35
|
-
: undefined,
|
|
36
|
-
]),
|
|
37
|
-
),
|
|
38
|
-
redirectAfterLogin: authConfig!.redirectAfterLogin ?? '/',
|
|
39
|
-
redirectAfterLogout: authConfig!.redirectAfterLogout ?? '/',
|
|
40
|
-
sessionKey: authConfig!.sessionKey ?? 'auth',
|
|
41
|
-
})
|
|
42
|
-
|
|
43
|
-
lines.push(`import { handleOAuthInitiate, handleOAuthCallback, handleOAuthLogout } from '@jasonshimmy/vite-plugin-cer-app/oauth'`)
|
|
44
|
-
lines.push(`const _authCfg = ${serialisedCfg}`)
|
|
45
|
-
lines.push('')
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
// ── User API routes ─────────────────────────────────────────────────────────
|
|
49
|
-
const entries: Array<{ alias: string; apiPath: string }> = []
|
|
50
|
-
|
|
51
|
-
for (const file of files) {
|
|
52
|
-
const routeSuffix = fileToRoutePath(file, serverApiDir)
|
|
53
|
-
const apiPath = '/api' + (routeSuffix === '/' ? '' : routeSuffix)
|
|
54
|
-
|
|
55
|
-
const safeAlias = '_route' + apiPath
|
|
56
|
-
.replace(/[^a-zA-Z0-9]/g, '_')
|
|
57
|
-
.replace(/_+/g, '_')
|
|
58
|
-
.replace(/^_|_$/g, '')
|
|
59
|
-
const alias = `_route_${safeAlias.replace(/^_route_/, '')}`
|
|
60
|
-
|
|
61
|
-
entries.push({ alias, apiPath })
|
|
62
|
-
lines.push(`import * as ${alias} from ${JSON.stringify(file)}`)
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
if (entries.length > 0) lines.push('')
|
|
66
|
-
|
|
67
|
-
lines.push('export const apiRoutes = [')
|
|
68
|
-
|
|
69
|
-
// OAuth routes come first
|
|
70
|
-
if (hasOAuth) {
|
|
71
|
-
lines.push(` { path: '/api/auth/:provider', handlers: { get: (req, res) => handleOAuthInitiate(req, res, req.params?.provider ?? '', _authCfg) } },`)
|
|
72
|
-
lines.push(` { path: '/api/auth/callback/:provider', handlers: { get: (req, res) => handleOAuthCallback(req, res, req.params?.provider ?? '', _authCfg) } },`)
|
|
73
|
-
lines.push(` { path: '/api/auth/logout', handlers: { get: (req, res) => handleOAuthLogout(req, res, _authCfg) } },`)
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
for (const { alias, apiPath } of entries) {
|
|
77
|
-
lines.push(` { path: ${JSON.stringify(apiPath)}, handlers: ${alias} },`)
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
lines.push(']')
|
|
81
|
-
lines.push('export default apiRoutes')
|
|
82
|
-
lines.push('')
|
|
83
|
-
|
|
84
|
-
return lines.join('\n')
|
|
85
|
-
}
|
|
@@ -1,44 +0,0 @@
|
|
|
1
|
-
import { existsSync } from 'node:fs'
|
|
2
|
-
import { basename } from 'pathe'
|
|
3
|
-
import { scanDirectory } from '../scanner.js'
|
|
4
|
-
|
|
5
|
-
/**
|
|
6
|
-
* Generates the virtual:cer-server-middleware module code.
|
|
7
|
-
* Scans server/middleware/ and produces an array of server middleware handlers.
|
|
8
|
-
*/
|
|
9
|
-
export async function generateServerMiddlewareCode(serverMiddlewareDir: string): Promise<string> {
|
|
10
|
-
if (!existsSync(serverMiddlewareDir)) {
|
|
11
|
-
return `// AUTO-GENERATED by @jasonshimmy/vite-plugin-cer-app\nexport const serverMiddleware = []\nexport default serverMiddleware\n`
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
const files = await scanDirectory('**/*.ts', serverMiddlewareDir)
|
|
15
|
-
|
|
16
|
-
if (files.length === 0) {
|
|
17
|
-
return `// AUTO-GENERATED by @jasonshimmy/vite-plugin-cer-app\nexport const serverMiddleware = []\nexport default serverMiddleware\n`
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
// Sort alphabetically so middleware runs in a deterministic order
|
|
21
|
-
const sorted = [...files].sort()
|
|
22
|
-
|
|
23
|
-
const lines: string[] = ['// AUTO-GENERATED by @jasonshimmy/vite-plugin-cer-app', '']
|
|
24
|
-
|
|
25
|
-
const entries: Array<{ alias: string; name: string }> = []
|
|
26
|
-
|
|
27
|
-
for (const file of sorted) {
|
|
28
|
-
const name = basename(file).replace(/\.[jt]s$/, '')
|
|
29
|
-
const alias = `_sm_${name.replace(/[^a-zA-Z0-9_]/g, '_').replace(/^(\d)/, '_$1')}`
|
|
30
|
-
entries.push({ alias, name })
|
|
31
|
-
lines.push(`import ${alias} from ${JSON.stringify(file)}`)
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
lines.push('')
|
|
35
|
-
lines.push('export const serverMiddleware = [')
|
|
36
|
-
for (const { alias, name } of entries) {
|
|
37
|
-
lines.push(` { name: ${JSON.stringify(name)}, handler: ${alias}?.default ?? ${alias} },`)
|
|
38
|
-
}
|
|
39
|
-
lines.push(']')
|
|
40
|
-
lines.push('export default serverMiddleware')
|
|
41
|
-
lines.push('')
|
|
42
|
-
|
|
43
|
-
return lines.join('\n')
|
|
44
|
-
}
|