@lomray/vite-ssr-boost 8.0.0-beta.1 → 8.0.0-beta.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +2 -1
- package/adapters/body.d.ts +1 -1
- package/adapters/body.js +1 -1
- package/adapters/body.js.map +1 -1
- package/adapters/compression.d.ts +5 -5
- package/adapters/compression.js +1 -1
- package/adapters/compression.js.map +1 -1
- package/adapters/edge.d.ts +5 -5
- package/adapters/edge.js.map +1 -1
- package/adapters/express/create-request.d.ts +2 -2
- package/adapters/express/create-request.js.map +1 -1
- package/adapters/express/entry.d.ts +17 -19
- package/adapters/express/entry.js.map +1 -1
- package/adapters/express/prepare-server.d.ts +7 -25
- package/adapters/express/prepare-server.js +1 -1
- package/adapters/express/prepare-server.js.map +1 -1
- package/adapters/express/render.d.ts +14 -15
- package/adapters/express/render.js +1 -1
- package/adapters/express/render.js.map +1 -1
- package/adapters/express/server.d.ts +5 -6
- package/adapters/express/server.js +1 -1
- package/adapters/express/server.js.map +1 -1
- package/adapters/express.d.ts +5 -5
- package/adapters/express.js.map +1 -1
- package/adapters/fastify.d.ts +5 -5
- package/adapters/fastify.js +1 -1
- package/adapters/fastify.js.map +1 -1
- package/adapters/hono.d.ts +2 -2
- package/adapters/hono.js.map +1 -1
- package/adapters/node.d.ts +6 -5
- package/adapters/node.js.map +1 -1
- package/browser/entry.d.ts +9 -9
- package/browser/entry.js +1 -1
- package/browser/entry.js.map +1 -1
- package/cli/build.d.ts +2 -2
- package/cli/build.js.map +1 -1
- package/cli/helpers/keyboard-input.d.ts +1 -1
- package/cli/helpers/keyboard-input.js +1 -1
- package/cli/helpers/keyboard-input.js.map +1 -1
- package/cli/helpers/vite-reset-cache.d.ts +1 -1
- package/cli/helpers/vite-reset-cache.js.map +1 -1
- package/cli/interfaces/actions.d.ts +8 -9
- package/cli/run-amplify-build.d.ts +1 -1
- package/cli/run-amplify-build.js.map +1 -1
- package/cli/run-dev.d.ts +3 -4
- package/cli/run-dev.js.map +1 -1
- package/cli/run-docker-build.d.ts +2 -2
- package/cli/run-docker-build.js.map +1 -1
- package/cli/run-prod.d.ts +4 -5
- package/cli/run-prod.js.map +1 -1
- package/cli/run-serverless.d.ts +2 -2
- package/cli/run-serverless.js.map +1 -1
- package/cli/run-vercel-build.d.ts +1 -1
- package/cli/run-vercel-build.js.map +1 -1
- package/cli.js +1 -1
- package/cli.js.map +1 -1
- package/components/navigate.d.ts +3 -3
- package/components/navigate.js.map +1 -1
- package/components/only-client.d.ts +2 -2
- package/components/only-client.js +1 -1
- package/components/only-client.js.map +1 -1
- package/components/render-client.d.ts +4 -4
- package/components/render-client.js +1 -1
- package/components/render-client.js.map +1 -1
- package/components/response-status.d.ts +2 -2
- package/components/response-status.js.map +1 -1
- package/components/scroll-to-top.d.ts +2 -2
- package/components/scroll-to-top.js +1 -1
- package/components/scroll-to-top.js.map +1 -1
- package/components/with-suspense.d.ts +3 -3
- package/components/with-suspense.js.map +1 -1
- package/constants/cli-actions.d.ts +1 -1
- package/constants/cli-actions.js.map +1 -1
- package/constants/cli-context.d.ts +4 -5
- package/constants/cli-context.js.map +1 -1
- package/constants/cli-name.d.ts +1 -1
- package/constants/cli-name.js.map +1 -1
- package/constants/cli-shortcuts.d.ts +2 -2
- package/constants/cli-shortcuts.js +1 -1
- package/constants/cli-shortcuts.js.map +1 -1
- package/constants/common.js.map +1 -1
- package/constants/plugin-name.d.ts +1 -1
- package/constants/plugin-name.js.map +1 -1
- package/constants/stream-error.d.ts +1 -1
- package/constants/stream-error.js.map +1 -1
- package/context/server.d.ts +3 -4
- package/context/server.js.map +1 -1
- package/core/compose-html.d.ts +2 -2
- package/core/compose-html.js.map +1 -1
- package/core/early-hints.d.ts +2 -2
- package/core/early-hints.js.map +1 -1
- package/core/handler.d.ts +3 -3
- package/core/handler.js.map +1 -1
- package/core/head-response.d.ts +1 -1
- package/core/head-response.js.map +1 -1
- package/core/headers.d.ts +3 -4
- package/core/headers.js +1 -1
- package/core/headers.js.map +1 -1
- package/core/render.d.ts +13 -13
- package/core/render.js +1 -1
- package/core/render.js.map +1 -1
- package/core/transform-html.d.ts +1 -1
- package/core/transform-html.js.map +1 -1
- package/core/types.d.ts +2 -3
- package/edge/render-to-stream.d.ts +2 -2
- package/edge/render-to-stream.js +1 -1
- package/edge/render-to-stream.js.map +1 -1
- package/helpers/build-custom-state.d.ts +1 -1
- package/helpers/build-custom-state.js +1 -1
- package/helpers/build-custom-state.js.map +1 -1
- package/helpers/build-router-state.d.ts +2 -2
- package/helpers/build-router-state.js.map +1 -1
- package/helpers/create-focus-only.d.ts +3 -3
- package/helpers/create-focus-only.js.map +1 -1
- package/helpers/dev-marker.d.ts +1 -1
- package/helpers/dev-marker.js.map +1 -1
- package/helpers/get-server-state.d.ts +1 -1
- package/helpers/get-server-state.js.map +1 -1
- package/helpers/html-escape.d.ts +1 -1
- package/helpers/html-escape.js +1 -1
- package/helpers/html-escape.js.map +1 -1
- package/helpers/import-route.d.ts +7 -7
- package/helpers/import-route.js +1 -1
- package/helpers/import-route.js.map +1 -1
- package/helpers/is-route-file.d.ts +1 -1
- package/helpers/is-route-file.js.map +1 -1
- package/helpers/obtain-stream-error.d.ts +3 -3
- package/helpers/obtain-stream-error.js.map +1 -1
- package/helpers/plugin-config.d.ts +5 -5
- package/helpers/plugin-config.js +1 -1
- package/helpers/plugin-config.js.map +1 -1
- package/helpers/print-server-info.d.ts +3 -4
- package/helpers/print-server-info.js +1 -1
- package/helpers/print-server-info.js.map +1 -1
- package/helpers/print-server-urls.d.ts +2 -2
- package/helpers/print-server-urls.js +1 -1
- package/helpers/print-server-urls.js.map +1 -1
- package/helpers/process-stop.d.ts +1 -1
- package/helpers/process-stop.js.map +1 -1
- package/helpers/resolve-server-urls.d.ts +3 -4
- package/helpers/resolve-server-urls.js +1 -1
- package/helpers/resolve-server-urls.js.map +1 -1
- package/helpers/serialize-errors.d.ts +2 -2
- package/helpers/serialize-errors.js.map +1 -1
- package/helpers/vite-aliases.d.ts +2 -2
- package/helpers/vite-aliases.js +1 -1
- package/helpers/vite-aliases.js.map +1 -1
- package/interfaces/fc-route.d.ts +4 -4
- package/interfaces/fc-route.js.map +1 -1
- package/interfaces/fc.d.ts +3 -4
- package/interfaces/route-object.d.ts +6 -6
- package/node/compress-response.d.ts +2 -2
- package/node/compress-response.js +1 -1
- package/node/compress-response.js.map +1 -1
- package/node/create-headers.d.ts +1 -1
- package/node/create-headers.js.map +1 -1
- package/node/create-request.d.ts +2 -2
- package/node/create-request.js.map +1 -1
- package/node/http.d.ts +4 -6
- package/node/render-to-stream.d.ts +2 -2
- package/node/render-to-stream.js +1 -1
- package/node/render-to-stream.js.map +1 -1
- package/node/request-signal.d.ts +2 -2
- package/node/request-signal.js.map +1 -1
- package/node/split-link-header.d.ts +1 -1
- package/node/split-link-header.js.map +1 -1
- package/node/write-early-hints.d.ts +2 -2
- package/node/write-early-hints.js.map +1 -1
- package/node/write-fetch-response.d.ts +3 -2
- package/node/write-fetch-response.js +1 -1
- package/node/write-fetch-response.js.map +1 -1
- package/package.json +52 -32
- package/plugin.d.ts +7 -7
- package/plugin.js.map +1 -1
- package/plugins/create-spa-index.d.ts +3 -3
- package/plugins/create-spa-index.js.map +1 -1
- package/plugins/handle-custom-entrypoint.d.ts +4 -4
- package/plugins/handle-custom-entrypoint.js +1 -1
- package/plugins/handle-custom-entrypoint.js.map +1 -1
- package/plugins/make-aliases.d.ts +3 -3
- package/plugins/make-aliases.js +1 -1
- package/plugins/make-aliases.js.map +1 -1
- package/plugins/normalize-route.d.ts +3 -3
- package/plugins/normalize-route.js.map +1 -1
- package/services/build.d.ts +5 -51
- package/services/build.js +1 -1
- package/services/build.js.map +1 -1
- package/services/logger.d.ts +2 -30
- package/services/logger.js.map +1 -1
- package/services/parse-routes.d.ts +5 -42
- package/services/parse-routes.js +1 -1
- package/services/parse-routes.js.map +1 -1
- package/services/path-normalize.d.ts +3 -18
- package/services/path-normalize.js +1 -1
- package/services/path-normalize.js.map +1 -1
- package/services/server-api.d.ts +1 -7
- package/services/server-api.js.map +1 -1
- package/services/server-config.d.ts +4 -48
- package/services/server-config.js +1 -1
- package/services/server-config.js.map +1 -1
- package/services/ssr-manifest.d.ts +6 -63
- package/services/ssr-manifest.js +1 -1
- package/services/ssr-manifest.js.map +1 -1
- package/workflow/Dockerfile +1 -1
package/services/build.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"build.js","sources":["../../src/services/build.ts"],"sourcesContent":["import childProcess from 'node:child_process';\nimport fs from 'node:fs';\nimport path from 'node:path';\nimport chalk from 'chalk';\nimport type { ResolvedConfig } from 'vite';\nimport { resolveConfig } from 'vite';\nimport viteResetCache from '@cli/helpers/vite-reset-cache';\nimport createFocusOnly from '@helpers/create-focus-only';\nimport { createDevMarker } from '@helpers/dev-marker';\nimport type { IPluginConfig } from '@helpers/plugin-config';\nimport getPluginConfig from '@helpers/plugin-config';\nimport processStop from '@helpers/process-stop';\nimport ServerConfig from '@services/server-config';\nimport SsrManifest from '@services/ssr-manifest';\n\nexport interface IBuildParams {\n mode: string;\n onFinish?: () => void;\n clientOptions?: string;\n serverOptions?: string;\n focusOnly?: 'all' | 'app' | 'client' | 'server' | 'entrypoint';\n isWatch?: boolean;\n isUnlockRobots?: boolean;\n isEject?: boolean;\n isServerless?: boolean;\n isNoWarnings?: boolean;\n}\n\ninterface IBuildProcess {\n promise: Promise<number | null | string>;\n command: childProcess.ChildProcess;\n}\n\ninterface ISpawnBuildParams {\n shouldWait?: boolean;\n focusOnly?: IBuildParams['focusOnly'];\n env?: Record<string, string>;\n}\n\nexport interface IBuildEntrypoint {\n // entrypoint name\n name: string;\n type: 'spa' | 'ssr';\n // custom index file, default: indexFile from plugin config\n indexFile?: string;\n // custom entry file for replace in indexFile, default: undefined (do nothing)\n clientFile?: string;\n // custom server file, indexFile and clientFile will be ignored\n serverFile?: string;\n // additional options for vite build command\n buildOptions?: string;\n}\n\n/**\n * Build service\n */\nclass Build {\n /**\n * Is production build\n */\n protected isProd: boolean;\n\n /**\n * Node environment\n */\n protected nodeEnv: string;\n\n /**\n * Build folder\n */\n protected buildDir: string;\n\n /**\n * Vite config\n */\n protected viteConfig: ResolvedConfig;\n\n /**\n * Plugin config\n */\n protected pluginConfig: IPluginConfig;\n\n /**\n * Build params\n */\n protected params: IBuildParams = {\n mode: '',\n clientOptions: '',\n serverOptions: '',\n focusOnly: 'app',\n isWatch: false,\n isUnlockRobots: false,\n isEject: false,\n isServerless: false,\n isNoWarnings: false,\n };\n\n /**\n * Abort controller for builds\n */\n protected abortController: AbortController | null = null;\n\n /**\n * Running builds\n */\n protected runningBuild: { name: string; buildProcess: IBuildProcess }[] = [];\n\n /**\n * Listener for preview has attached\n */\n protected hasPreviewModeExitListener = false;\n\n /**\n * @constructor\n */\n public constructor(params: IBuildParams) {\n this.params = { ...this.params, ...params };\n }\n\n /**\n * Make config\n */\n protected async makeConfig(): Promise<void> {\n const { mode } = this.params;\n\n this.viteConfig = await resolveConfig({}, 'build', mode, 'production');\n this.pluginConfig = getPluginConfig(this.viteConfig);\n this.buildDir = path.resolve(this.viteConfig.root, this.viteConfig.build.outDir);\n this.nodeEnv = process.env.NODE_ENV || 'production';\n this.isProd = this.nodeEnv === 'production';\n }\n\n /**\n * Clear build folder\n */\n public clearBuildFolder(): void {\n // clear build folder\n if (fs.existsSync(this.buildDir)) {\n fs.rmSync(this.buildDir, { recursive: true });\n }\n }\n\n /**\n * Return is prod indicator value\n */\n public getIsProd(): boolean {\n return this.isProd;\n }\n\n /**\n * Return node env value\n */\n public getNodeEnv(): string {\n return this.nodeEnv;\n }\n\n /**\n * Return build names\n */\n public getRunningBuildNames(): string[] {\n return this.runningBuild.map(({ name }) => name);\n }\n\n /**\n * Promisify spawn process\n */\n protected promisifyProcess(\n command: childProcess.ChildProcess,\n isRejectWarnings = false,\n ): IBuildProcess {\n const promise = new Promise<number | null | string>((resolve, reject): void => {\n command.on('exit', (code) => {\n resolve(code);\n });\n\n command.on('close', (code: number): void => {\n resolve(code);\n });\n\n command.on('error', (message: string): void => {\n reject(message);\n });\n\n if (isRejectWarnings) {\n command.stderr?.on('data', (buff: Uint8Array): void => {\n const msg = Buffer.from(buff).toString();\n\n if (msg.includes('warning') || msg.includes('WARNING')) {\n resolve(1);\n }\n });\n }\n });\n\n command.stdout?.pipe(process.stdout);\n command.stderr?.pipe(process.stderr);\n\n return { promise, command };\n }\n\n /**\n * Build assets manifest file\n */\n protected buildManifest(): void {\n console.info(chalk.blue('Building routes manifest file'));\n\n const serverConfig = ServerConfig.init(\n { isProd: this.isProd, mode: this.params.mode },\n { root: this.viteConfig.root, clientFile: this.pluginConfig.clientFile },\n );\n\n SsrManifest.get(serverConfig, {\n buildDir: this.viteConfig.build.outDir,\n viteAliases: this.viteConfig.resolve.alias,\n basename: this.viteConfig.base,\n renderBuiltUrl: this.viteConfig?.experimental?.renderBuiltUrl,\n }).buildRoutesManifest();\n }\n\n /**\n * Change general directive Disallow to Allow in robots.txt.\n */\n protected unlockRobots(): void {\n const robotsFile = `${this.buildDir}/client/robots.txt`;\n\n if (!fs.existsSync(robotsFile)) {\n console.warn(`Failed to unlock robots.txt, file not exist: ${robotsFile}`);\n\n return;\n }\n\n const data = fs\n .readFileSync(robotsFile, { encoding: 'utf-8' })\n .replace(/Disallow: \\/$/m, 'Allow: /');\n\n fs.writeFileSync(robotsFile, data, { encoding: 'utf-8' });\n\n console.info(chalk.blue('\\nrobots.txt unlocked.'));\n }\n\n /**\n * Eject cli to run app via node\n */\n protected eject(): void {\n const entrypoint = `${this.buildDir}/server/start.js`;\n const script =\n \"import runProd from '@lomray/vite-ssr-boost/cli/run-prod.js';\\n\\n\" +\n 'const VERSION = process.env.VERSION || \"1.0.0\";\\n' +\n 'const PORT = process.env.PORT || 3000;\\n' +\n 'const IS_HOST = process.env.IS_HOST || \"0\";\\n' +\n 'const ONLY_CLIENT = process.env.ONLY_CLIENT || \"0\";\\n\\n' +\n `await runProd({\n version: VERSION,\n isHost: IS_HOST === '1',\n isPrintInfo: true,\n port: PORT,\n onlyClient: ONLY_CLIENT === '1',\n });\\n`;\n\n fs.writeFileSync(entrypoint, script, {\n encoding: 'utf-8',\n });\n }\n\n /**\n * Create serverless entrypoint\n */\n protected createServerless(): void {\n const entrypoint = `${this.buildDir}/server/serverless.js`;\n const script =\n \"import runServerless from '@lomray/vite-ssr-boost/cli/run-serverless.js';\\n\\n\" +\n `export default await runServerless({ version: process.env.VERSION || \"1.0.0\" });\\n`;\n\n fs.writeFileSync(entrypoint, script, {\n encoding: 'utf-8',\n });\n }\n\n /**\n * Build specified entrypoint\n */\n protected async spawnBuild(\n name: string,\n buildOptions: string,\n params: ISpawnBuildParams = {},\n ): Promise<void> {\n const { mode, isNoWarnings } = this.params;\n const { focusOnly = this.params.focusOnly, shouldWait = false, env = {} } = params;\n const modeOpt = mode && !buildOptions.includes('--mode') ? `--mode ${mode}` : '';\n\n const buildProcess = this.promisifyProcess(\n childProcess.spawn(`vite build ${buildOptions} ${modeOpt} --emptyOutDir`, {\n signal: this.abortController!.signal,\n stdio: [process.stdin, 'pipe', 'pipe'],\n shell: true,\n env: {\n ...process.env,\n ...env,\n FORCE_COLOR: '2',\n SSR_BOOST_IS_SSR: createFocusOnly(focusOnly).isOnlyClient() ? '0' : '1',\n SSR_BOOST_ACTION: global.viteBoostAction,\n },\n }),\n isNoWarnings,\n );\n\n this.runningBuild.push({ name, buildProcess });\n\n if (!shouldWait) {\n return;\n }\n\n await this.waitLastBuild();\n }\n\n /**\n * Wait latest build and stop process in case error\n */\n protected async waitLastBuild(): Promise<void> {\n const latestProcess = this.runningBuild.at(-1);\n\n if (!latestProcess) {\n return;\n }\n\n const exitCode = await latestProcess.buildProcess.promise;\n\n processStop(exitCode, true);\n }\n\n /**\n * Run preview mode\n */\n protected runPreviewMode(): void {\n if (!this.hasPreviewModeExitListener) {\n process.on('exit', () => {\n this.abortController!.abort();\n });\n\n this.hasPreviewModeExitListener = true;\n }\n\n const { onFinish } = this.params;\n let buildCount = this.runningBuild.length;\n\n /**\n * Detect finished builds for process\n */\n const listener = (buff: Uint8Array): void => {\n const msg = Buffer.from(buff).toString();\n\n if (msg.includes('built in')) {\n buildCount -= 1;\n\n if (!buildCount) {\n this.runningBuild.forEach(({ buildProcess }) => {\n buildProcess.command.stdout?.removeListener('data', listener);\n });\n createDevMarker(this.isProd, this.viteConfig);\n onFinish?.();\n }\n }\n };\n\n /**\n * Listen output for call onFinish\n */\n this.runningBuild.forEach(({ buildProcess }) => {\n buildProcess.command.stdout?.on('data', listener);\n });\n }\n\n /**\n * Run app build\n */\n public async build(): Promise<void> {\n await this.makeConfig();\n // this is required step - build with different env may cause problems\n await viteResetCache();\n this.clearBuildFolder();\n\n const {\n clientOptions,\n serverOptions,\n onFinish,\n isWatch,\n focusOnly,\n isEject,\n isServerless,\n isUnlockRobots,\n } = this.params;\n const { outDir } = this.viteConfig.build;\n const focus = createFocusOnly(focusOnly);\n\n this.abortController = new AbortController();\n this.runningBuild = [];\n\n if (focus.isClient()) {\n /**\n * Build client\n */\n await this.spawnBuild('client', `${clientOptions} --outDir ${outDir}/client`, {\n shouldWait: !isWatch,\n });\n }\n\n /**\n * Build server\n */\n if (focus.isServer()) {\n await this.spawnBuild(\n 'server',\n `${serverOptions} --outDir ${outDir}/server --ssr ${this.pluginConfig.serverFile}`,\n {\n shouldWait: !isWatch,\n },\n );\n\n if (!isWatch) {\n this.buildManifest();\n\n if (isEject) {\n this.eject();\n }\n\n if (isServerless) {\n this.createServerless();\n }\n }\n }\n\n /**\n * Build additional entrypoint\n */\n const { entrypoint } = this.pluginConfig;\n\n if (entrypoint?.length && focus.isEntrypoint()) {\n for (const { name, type, serverFile, buildOptions = '' } of entrypoint) {\n const cliOptions = serverFile && type === 'ssr' ? `--ssr ${serverFile}` : '';\n\n await this.spawnBuild(name, `${buildOptions} ${cliOptions} --outDir ${outDir}/${name}`, {\n shouldWait: !isWatch,\n focusOnly: type === 'ssr' ? 'server' : 'client',\n env: {\n SSR_BOOST_CUSTOM_ENTRYPOINT_BUILD_NAME: name,\n },\n });\n }\n }\n\n /**\n * Preview mode\n */\n if (isWatch) {\n this.runPreviewMode();\n\n return;\n }\n\n if (isUnlockRobots) {\n this.unlockRobots();\n }\n\n createDevMarker(this.isProd, this.viteConfig);\n onFinish?.();\n }\n}\n\nexport default Build;\n"],"names":["Build","isProd","nodeEnv","buildDir","viteConfig","pluginConfig","params","mode","clientOptions","serverOptions","focusOnly","isWatch","isUnlockRobots","isEject","isServerless","isNoWarnings","abortController","runningBuild","hasPreviewModeExitListener","constructor","this","async","resolveConfig","getPluginConfig","path","resolve","root","build","outDir","process","env","NODE_ENV","clearBuildFolder","fs","existsSync","rmSync","recursive","getIsProd","getNodeEnv","getRunningBuildNames","map","name","promisifyProcess","command","isRejectWarnings","promise","Promise","reject","on","code","message","stderr","buff","msg","Buffer","from","toString","includes","stdout","pipe","buildManifest","console","info","chalk","blue","serverConfig","ServerConfig","init","clientFile","SsrManifest","get","viteAliases","alias","basename","base","renderBuiltUrl","experimental","buildRoutesManifest","unlockRobots","robotsFile","warn","data","readFileSync","encoding","replace","writeFileSync","eject","entrypoint","createServerless","buildOptions","shouldWait","modeOpt","buildProcess","childProcess","spawn","signal","stdio","stdin","shell","FORCE_COLOR","SSR_BOOST_IS_SSR","createFocusOnly","isOnlyClient","SSR_BOOST_ACTION","global","viteBoostAction","push","waitLastBuild","latestProcess","at","exitCode","processStop","runPreviewMode","abort","onFinish","buildCount","length","listener","forEach","removeListener","createDevMarker","makeConfig","viteResetCache","focus","AbortController","isClient","spawnBuild","isServer","serverFile","isEntrypoint","type","cliOptions","SSR_BOOST_CUSTOM_ENTRYPOINT_BUILD_NAME"],"mappings":"gcAwDA,MAAMA,EAIMC,OAKAC,QAKAC,SAKAC,WAKAC,aAKAC,OAAuB,CAC/BC,KAAM,GACNC,cAAe,GACfC,cAAe,GACfC,UAAW,MACXC,SAAS,EACTC,gBAAgB,EAChBC,SAAS,EACTC,cA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AAGtH,cAA0BoB,WAAiB,CAC5E8D,YAAa/E,IAObgH,EAAMI,mBACF3G,KAAK0G,WACT,SACA,GAAGrH,cAA0BmB,kBAAuBR,KAAKf,aAAa2H,aACtE,CACEtC,YAAa/E,IAIZA,IACHS,KAAKwC,gBAED/C,GACFO,KAAKkE,QAGHxE,GACFM,KAAKoE,qBAQX,MAAMD,WAAEA,GAAenE,KAAKf,aAE5B,GAAIkF,GAAY6B,QAAUO,EAAMM,eAC9B,IAAK,MAAMxF,KAAEA,EAAIyF,KAAEA,EAAIF,WAAEA,EAAUvC,aAAEA,EAAe,MAAQF,EAAY,CACtE,MAAM4C,EAAaH,GAAuB,QAATE,EAAiB,SAASF,IAAe,SAEpE5G,KAAK0G,WAAWrF,EAAM,GAAGgD,KAAgB0C,cAAuBvG,KAAUa,IAAQ,CACtFiD,YAAa/E,EACbD,UAAoB,QAATwH,EAAiB,SAAW,SACvCpG,IAAK,CACHsG,uCAAwC3F,IAG9C,CAME9B,EACFS,KAAK4F,kBAKHpG,GACFQ,KAAK0D,eAGP0C,EAAgBpG,KAAKnB,OAAQmB,KAAKhB,YAClC8G,MACF"}
|
|
1
|
+
{"version":3,"file":"build.js","sources":["../../src/services/build.ts"],"sourcesContent":[null],"names":["Build","isProd","nodeEnv","buildDir","viteConfig","pluginConfig","params","mode","clientOptions","serverOptions","focusOnly","isWatch","isUnlockRobots","isEject","isServerless","isNoWarnings","abortController","runningBuild","hasPreviewModeExitListener","constructor","this","makeConfig","resolveConfig","getPluginConfig","path","resolve","root","build","outDir","process","env","NODE_ENV","clearBuildFolder","fs","existsSync","rmSync","recursive","getIsProd","getNodeEnv","getRunningBuildNames","map","name","promisifyProcess","command","isRejectWarnings","promise","Promise","reject","on","code","message","stderr","buff","msg","Buffer","from","toString","includes","stdout","pipe","buildManifest","console","info","chalk","blue","serverConfig","ServerConfig","init","clientFile","SsrManifest","get","viteAliases","alias","basename","base","renderBuiltUrl","experimental","buildRoutesManifest","unlockRobots","robotsFile","warn","data","readFileSync","encoding","replace","writeFileSync","eject","entrypoint","createServerless","spawnBuild","buildOptions","shouldWait","modeOpt","buildProcess","childProcess","spawn","signal","stdio","stdin","shell","FORCE_COLOR","SSR_BOOST_IS_SSR","createFocusOnly","isOnlyClient","SSR_BOOST_ACTION","global","viteBoostAction","push","waitLastBuild","latestProcess","at","exitCode","processStop","runPreviewMode","abort","onFinish","buildCount","length","listener","forEach","removeListener","createDevMarker","viteResetCache","focus","AbortController","isClient","isServer","serverFile","isEntrypoint","type","cliOptions","SSR_BOOST_CUSTOM_ENTRYPOINT_BUILD_NAME"],"mappings":"gcAwDA,MAAMA,EAIMC,OAKAC,QAKAC,SAKAC,WAKAC,aAKAC,OAAuB,CAC/BC,KAAM,GACNC,cAAe,GACfC,cAAe,GACfC,UAAW,MACXC,SAAS,EACTC,gBAAgB,EAChBC,SAAS,EACTC,cAAc,EACdC,cAAc,GAMNC,gBAA0C,KAK1CC,aAAgE,GAKhEC,4BAA6B,EAKvC,WAAAC,CAAmBb,GACjBc,KAAKd,OAAS,IAAKc,KAAKd,UAAWA,EACrC,CAKU,gBAAMe,GACd,MAAMd,KAAEA,GAASa,KAAKd,OAEtBc,KAAKhB,iBAAmBkB,EAAc,CAAA,EAAI,QAASf,EAAM,cACzDa,KAAKf,aAAekB,EAAgBH,KAAKhB,YACzCgB,KAAKjB,SAAWqB,EAAKC,QAAQL,KAAKhB,WAAWsB,KAAMN,KAAKhB,WAAWuB,MAAMC,QACzER,KAAKlB,QAAU2B,QAAQC,IAAIC,UAAY,aACvCX,KAAKnB,OAA0B,eAAjBmB,KAAKlB,OACrB,CAKO,gBAAA8B,GAEDC,EAAGC,WAAWd,KAAKjB,WACrB8B,EAAGE,OAAOf,KAAKjB,SAAU,CAAEiC,WAAW,GAE1C,CAKO,SAAAC,GACL,OAAOjB,KAAKnB,MACd,CAKO,UAAAqC,GACL,OAAOlB,KAAKlB,OACd,CAKO,oBAAAqC,GACL,OAAOnB,KAAKH,aAAauB,IAAI,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AKnB,OAAQmB,KAAKhB,YAClC+G,MACF"}
|
package/services/logger.d.ts
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import { LogErrorOptions, LogOptions } from 'vite';
|
|
2
|
-
import { Logger as ViteLogger } from "vite";
|
|
1
|
+
import type { LogErrorOptions, Logger as ViteLogger, LogOptions } from 'vite';
|
|
3
2
|
declare const LogLevels: {
|
|
4
3
|
error: number;
|
|
5
4
|
warn: number;
|
|
@@ -31,68 +30,41 @@ declare class Logger implements ViteLogger {
|
|
|
31
30
|
* Return 'true' to skip output
|
|
32
31
|
*/
|
|
33
32
|
logFilter: ILoggerOptions['logFilter'] | undefined;
|
|
34
|
-
/**
|
|
35
|
-
* @constructor
|
|
36
|
-
*/
|
|
37
33
|
/**
|
|
38
34
|
* @constructor
|
|
39
35
|
*/
|
|
40
36
|
constructor({ logFilter, logLevel }?: ILoggerOptions);
|
|
41
|
-
/**
|
|
42
|
-
* @inheritDoc
|
|
43
|
-
*/
|
|
44
37
|
/**
|
|
45
38
|
* @inheritDoc
|
|
46
39
|
*/
|
|
47
40
|
clearScreen(): void;
|
|
48
|
-
/**
|
|
49
|
-
* Should we skip current log depends on current log level
|
|
50
|
-
*/
|
|
51
41
|
/**
|
|
52
42
|
* Should we skip current log depends on current log level
|
|
53
43
|
*/
|
|
54
44
|
protected shouldSkipLog(level: number): boolean;
|
|
55
|
-
/**
|
|
56
|
-
* Common log
|
|
57
|
-
*/
|
|
58
45
|
/**
|
|
59
46
|
* Common log
|
|
60
47
|
*/
|
|
61
48
|
protected log(params: ILogParams): void;
|
|
62
|
-
/**
|
|
63
|
-
* @inheritDoc
|
|
64
|
-
*/
|
|
65
49
|
/**
|
|
66
50
|
* @inheritDoc
|
|
67
51
|
*/
|
|
68
52
|
error(msg: string, options?: LogErrorOptions): void;
|
|
69
|
-
/**
|
|
70
|
-
* @inheritDoc
|
|
71
|
-
*/
|
|
72
53
|
/**
|
|
73
54
|
* @inheritDoc
|
|
74
55
|
*/
|
|
75
56
|
hasErrorLogged(): boolean;
|
|
76
|
-
/**
|
|
77
|
-
* @inheritDoc
|
|
78
|
-
*/
|
|
79
57
|
/**
|
|
80
58
|
* @inheritDoc
|
|
81
59
|
*/
|
|
82
60
|
info(msg: string, options: LogOptions): void;
|
|
83
|
-
/**
|
|
84
|
-
* @inheritDoc
|
|
85
|
-
*/
|
|
86
61
|
/**
|
|
87
62
|
* @inheritDoc
|
|
88
63
|
*/
|
|
89
64
|
warn(msg: string, options: LogOptions): void;
|
|
90
|
-
/**
|
|
91
|
-
* @inheritDoc
|
|
92
|
-
*/
|
|
93
65
|
/**
|
|
94
66
|
* @inheritDoc
|
|
95
67
|
*/
|
|
96
68
|
warnOnce(msg: string, options: LogOptions): void;
|
|
97
69
|
}
|
|
98
|
-
export
|
|
70
|
+
export default Logger;
|
package/services/logger.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"logger.js","sources":["../../src/services/logger.ts"],"sourcesContent":[
|
|
1
|
+
{"version":3,"file":"logger.js","sources":["../../src/services/logger.ts"],"sourcesContent":[null],"names":["LogLevels","error","warn","info","Logger","hasWarned","loglevel","logFilter","constructor","logLevel","this","clearScreen","shouldSkipLog","level","log","params","msg","options","args","filter","Boolean","console","hasErrorLogged","warnOnce"],"mappings":"AAEA,MAAMA,EAAY,CAChBC,MAAO,EACPC,KAAM,EACNC,KAAM,GAiBR,MAAMC,EAIGC,UAKAC,SAMAC,UAKP,WAAAC,EAAmBD,UAAEA,EAASE,SAAEA,EAAW,GAAsB,CAAA,GAC/DC,KAAKJ,SAAWG,EAChBC,KAAKH,UAAYA,CACnB,CAKO,WAAAI,GAEP,CAKU,aAAAC,CAAcC,GACtB,OAAOA,EAAQH,KAAKJ,QACtB,CAKU,GAAAQ,CAAIC,GACZ,MAAMF,MAAEA,EAAKG,IAAEA,EAAGC,QAAEA,GAAYF,EAEhC,GAAIL,KAAKE,cAAcZ,EAAUa,KAAWH,KAAKH,YAAYQ,GAC3D,OAGF,MAAMG,EAAO,CAACF,EAAKC,GAAShB,OAAOkB,OAAOC,SAE1CC,QAAQR,MAAUK,EACpB,CAKO,KAAAjB,CAAMe,EAAaC,GACxBP,KAAKI,IAAI,CAAEE,MAAKC,UAASJ,MAAO,SAClC,CAKO,cAAAS,GACL,OAAO,CACT,CAKO,IAAAnB,CAAKa,EAAaC,GACvBP,KAAKI,IAAI,CAAEE,MAAKC,UAASJ,MAAO,QAClC,CAKO,IAAAX,CAAKc,EAAaC,GACvBP,KAAKI,IAAI,CAAEE,MAAKC,UAASJ,MAAO,QAClC,CAKO,QAAAU,CAASP,EAAaC,GAC3BP,KAAKR,KAAKc,EAAKC,EACjB"}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { Alias } from 'vite';
|
|
2
|
-
import PathNormalize from
|
|
3
|
-
import ServerConfig from
|
|
4
|
-
type TRoutesTree = {
|
|
1
|
+
import type { Alias } from 'vite';
|
|
2
|
+
import PathNormalize from './path-normalize.js';
|
|
3
|
+
import type ServerConfig from './server-config.js';
|
|
4
|
+
export type TRoutesTree = {
|
|
5
5
|
index: number;
|
|
6
6
|
import: string;
|
|
7
7
|
children: TRoutesTree[];
|
|
@@ -18,91 +18,54 @@ declare class ParseRoutes {
|
|
|
18
18
|
* Server config
|
|
19
19
|
*/
|
|
20
20
|
protected readonly config: ServerConfig;
|
|
21
|
-
/**
|
|
22
|
-
* @constructor
|
|
23
|
-
*/
|
|
24
21
|
/**
|
|
25
22
|
* @constructor
|
|
26
23
|
*/
|
|
27
24
|
constructor(config: ServerConfig, viteAliases?: Alias[]);
|
|
28
|
-
/**
|
|
29
|
-
* Parse routes
|
|
30
|
-
*/
|
|
31
25
|
/**
|
|
32
26
|
* Parse routes
|
|
33
27
|
*/
|
|
34
28
|
parse(): TRoutesTree[];
|
|
35
|
-
/**
|
|
36
|
-
* Parse file and return ast
|
|
37
|
-
*/
|
|
38
29
|
/**
|
|
39
30
|
* Parse file and return ast
|
|
40
31
|
*/
|
|
41
32
|
private parseFile;
|
|
42
|
-
/**
|
|
43
|
-
* Find route import filepath
|
|
44
|
-
*/
|
|
45
33
|
/**
|
|
46
34
|
* Find route import filepath
|
|
47
35
|
*/
|
|
48
36
|
private getImportPath;
|
|
49
|
-
/**
|
|
50
|
-
* Find routes array inside code
|
|
51
|
-
*/
|
|
52
37
|
/**
|
|
53
38
|
* Find routes array inside code
|
|
54
39
|
*/
|
|
55
40
|
private findRoutesDefinition;
|
|
56
|
-
/**
|
|
57
|
-
* Entrypoint routes file
|
|
58
|
-
*/
|
|
59
41
|
/**
|
|
60
42
|
* Entrypoint routes file
|
|
61
43
|
*/
|
|
62
44
|
private findRoutesEntrypoint;
|
|
63
|
-
/**
|
|
64
|
-
* Resolve route filename import
|
|
65
|
-
*/
|
|
66
45
|
/**
|
|
67
46
|
* Resolve route filename import
|
|
68
47
|
*/
|
|
69
48
|
private resolveFilename;
|
|
70
|
-
/**
|
|
71
|
-
* Parse ast array routes objects
|
|
72
|
-
*/
|
|
73
49
|
/**
|
|
74
50
|
* Parse ast array routes objects
|
|
75
51
|
*/
|
|
76
52
|
private parseRoutesArray;
|
|
77
|
-
/**
|
|
78
|
-
* Parse imports map from ast
|
|
79
|
-
*/
|
|
80
53
|
/**
|
|
81
54
|
* Parse imports map from ast
|
|
82
55
|
*/
|
|
83
56
|
private static parseImportsMap;
|
|
84
|
-
/**
|
|
85
|
-
* Recursive build routes tree with dynamic imports
|
|
86
|
-
*/
|
|
87
57
|
/**
|
|
88
58
|
* Recursive build routes tree with dynamic imports
|
|
89
59
|
*/
|
|
90
60
|
private recursiveBuildRoutesTree;
|
|
91
|
-
/**
|
|
92
|
-
* Add pathId to static routes
|
|
93
|
-
*/
|
|
94
61
|
/**
|
|
95
62
|
* Add pathId to static routes
|
|
96
63
|
*/
|
|
97
64
|
private static processRouteFileCode;
|
|
98
|
-
/**
|
|
99
|
-
* Inject pathId to sync/async routes
|
|
100
|
-
* Add async wrapper (see import-routes)
|
|
101
|
-
*/
|
|
102
65
|
/**
|
|
103
66
|
* Inject pathId to sync/async routes
|
|
104
67
|
* Add async wrapper (see import-routes)
|
|
105
68
|
*/
|
|
106
69
|
static handleRoutes(code: string, shouldAddPathId: boolean): string;
|
|
107
70
|
}
|
|
108
|
-
export
|
|
71
|
+
export default ParseRoutes;
|
package/services/parse-routes.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import e from"fs";import{resolve as t}from"node:path";import r from"path";import n from"@babel/generator";import*as
|
|
1
|
+
import e from"fs";import{resolve as t}from"node:path";import r from"path";import n from"@babel/generator";import*as o from"@babel/parser";import a from"@babel/traverse";import{isObjectProperty as i,isIdentifier as s,isBooleanLiteral as l,isJSXElement as p,isFunction as u,isArrayExpression as c,objectProperty as m,identifier as f,stringLiteral as d,isJSXIdentifier as h,isObjectExpression as y}from"@babel/types";import v from"../constants/plugin-name.js";import E from"./path-normalize.js";const g=n.default??n,x=a.default??a;class I{pathNormalize;config;constructor(e,t){this.config=e,this.pathNormalize=new E(e,t)}parse(){const{clientFile:e,root:r}=this.config.getParams(),n=t(r,e),o=this.findRoutesEntrypoint(n);if(!o?.routesPath)throw new Error(`Unable to find routes file import in ${e}`);const{routesPath:a,exportName:i}=o,s=this.resolveFilename(a,n);return this.recursiveBuildRoutesTree(s,i)}parseFile(t){try{const r=e.readFileSync(t,"utf-8");return o.parse(r,{sourceType:"module",createImportExpressions:!0,plugins:["typescript","jsx"]})}catch{return null}}getImportPath(e,t){let r=null,n=null;return x(e,{ImportDeclaration(e){const o=e.node;o.specifiers.forEach(e=>{e.local.name===t&&(n="ImportDefaultSpecifier"===e.type?null:t,r=o.source.value)})}}),{routesPath:r,exportName:n}}findRoutesDefinition(e,t){let r=t;if(x(e,{ExportNamedDeclaration({node:e}){!e.declaration&&e.specifiers.length>0&&e.specifiers.forEach(e=>{const n=e.exported.name;null===t&&"ExportSpecifier"===e.type?"default"===e.local.name&&(r=n):n===t&&(r=e.local.name)})},ExportDefaultDeclaration({node:e}){null===t&&("Identifier"===e.declaration.type?r=e.declaration.name:"VariableDeclaration"===e.declaration.type&&(r=e.declaration.declarations[0].id.name))}}),r){let t=null;return x(e,{VariableDeclaration({node:e}){e.declarations.forEach(n=>{n.id.name===r&&(t=e)})}}),t}return null}findRoutesEntrypoint(e){const t=this.parseFile(e);let r=null;return t?(x(t,{CallExpression({node:e}){"entryClient"===e.callee.name&&e.arguments.length>=2&&"Identifier"===e.arguments[1].type&&(r=e.arguments[1].name)}}),this.getImportPath(t,r)):r}resolveFilename(e,t){let n=e;(e.startsWith("./")||e.startsWith("../"))&&t&&(n=r.resolve(r.dirname(t),e));const o=this.pathNormalize.getAppPath(n,!0);return this.pathNormalize.findAppFile(o)}parseRoutesArray(e,t,r){const n=[];return e.forEach((e,o)=>{if("ObjectExpression"===e.type){const a={index:o,import:"",children:[]};e.properties.forEach(e=>{const n=e;if("children"===n.key.name&&"ArrayExpression"===n.value.type&&(a.children=this.parseRoutesArray(n.value.elements,t,r)),"lazy"===n.key.name&&"ArrowFunctionExpression"===n.value.type){const e=n.value.body;if("ImportExpression"===e.type){const t=e.source;"StringLiteral"===t.type&&(a.import=t.value)}}if("Component"===n.key.name&&"Identifier"===n.value.type){const e=n.value.name,{path:r}=t[e]??{};r&&(a.import=r)}if("element"===n.key.name&&"JSXElement"===n.value.type){const e=n.value?.openingElement?.name?.name,{path:r}=t[e]??{};r&&(a.import=r)}if("children"===n.key.name&&"Identifier"===n.value.type){const e=n.value.name,{path:o,isDefault:i}=t[e]??{};if(o){const t=this.resolveFilename(o,r);t&&(a.children=this.recursiveBuildRoutesTree(t,i?null:e))}}}),(a.import||a.children.length>0)&&n.push(a)}}),n}static parseImportsMap(e){const t={};return x(e,{ImportDeclaration(e){const r=e.node;r.specifiers.forEach(e=>{t[e.local.name]={path:r.source.value,isDefault:"ImportDefaultSpecifier"===e.type}})}}),t}recursiveBuildRoutesTree(e,t=null){if(!e)return[];const r=this.parseFile(e);if(!r)return[];const n=this.findRoutesDefinition(r,t),o=[];if(!n)return o;const a=I.parseImportsMap(r),i=n.declarations[0].init?.elements;return o.push(...this.parseRoutesArray(i,a,e)),o}static processRouteFileCode(e,t,r,n){e.node.properties.forEach(o=>{if(i(o)&&s(o.key)){if("lazy"===o.key.name&&"ArrowFunctionExpression"===o.value.type){const t=o.value.body,a=e.node.properties.find(e=>i(e)&&s(e.key)&&"onlyClient"===e.key.name);if(o.value={type:"CallExpression",callee:{type:"Identifier",name:"n"},arguments:i(a)&&(l(a.value)||p(a.value)||u(a.value)||s(a.value))?[o.value,a.value]:[o.value]},a&&(e.node.properties=e.node.properties.filter(e=>e!==a)),n(),"ImportExpression"===t.type){const n=t.source,a=e.findParent?.(e=>c(e.node));if(a&&"StringLiteral"===n.type&&n.value&&r){const t=m(f("pathId"),d(n.value));e.node.properties.splice(e.node.properties.indexOf(o)+1,0,t)}}}if("element"===o.key.name||"Component"===o.key.name){let n="";p(o.value)&&h(o.value.openingElement.name)?n=o.value.openingElement.name.name:s(o.value)&&(n=o.value.name);const a=e.findParent?.(e=>c(e.node)),i=t[n]?.path;if(a&&i&&r){const t=m(f("pathId"),d(i));e.node.properties.splice(e.node.properties.indexOf(o)+1,0,t)}}"children"===o.key.name&&c(o.value)&&o.value.elements.forEach(e=>{y(e)&&I.processRouteFileCode({node:e},t,r,n)})}})}static handleRoutes(e,t){if(!e)return e;const r=o.parse(e,{sourceType:"module",createImportExpressions:!0,plugins:["typescript","jsx"]});if(!r)return e;const n=I.parseImportsMap(r);let a=!1;return x(r,{ObjectExpression(e){I.processRouteFileCode(e,n,t,()=>{a=!0})}}),a&&r.program.body.unshift({type:"ImportDeclaration",specifiers:[{type:"ImportDefaultSpecifier",local:{type:"Identifier",name:"n"}}],source:{type:"StringLiteral",value:`${v}/helpers/import-route`}}),g(r,{retainLines:!0}).code}}export{I as default};
|
|
2
2
|
//# sourceMappingURL=parse-routes.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"parse-routes.js","sources":["../../src/services/parse-routes.ts"],"sourcesContent":["import fs from 'fs';\nimport { resolve } from 'node:path';\nimport path from 'path';\nimport babelGenerate from '@babel/generator';\nimport type * as GenerateTypes from '@babel/generator';\nimport * as parser from '@babel/parser';\nimport type { ParseResult } from '@babel/parser';\nimport babelTraverse from '@babel/traverse';\nimport type * as TraverseTypes from '@babel/traverse';\nimport type {\n CallExpression,\n File as BabelFile,\n VariableDeclaration,\n ObjectExpression,\n} from '@babel/types';\nimport {\n isObjectProperty,\n isIdentifier,\n identifier,\n isBooleanLiteral,\n stringLiteral,\n isFunction,\n objectProperty,\n isArrayExpression,\n isJSXElement,\n isJSXIdentifier,\n isObjectExpression,\n} from '@babel/types';\nimport type { Alias } from 'vite';\nimport PLUGIN_NAME from '@constants/plugin-name';\nimport PathNormalize from '@services/path-normalize';\nimport type ServerConfig from '@services/server-config';\n//\n// @ts-expect-error known import problem\nconst generate = (babelGenerate.default ?? babelGenerate) as (typeof GenerateTypes)['default'];\n// @ts-expect-error known import problem\nconst traverse = (babelTraverse.default ?? babelTraverse) as (typeof TraverseTypes)['default'];\n\ninterface IPathImport {\n routesPath: string | null;\n exportName: string | null;\n}\n\ninterface IMapImports {\n [name: string]: {\n path: string;\n isDefault: boolean; // is default import?\n };\n}\n\nexport type TRoutesTree = {\n index: number;\n import: string;\n children: TRoutesTree[];\n};\n\n/**\n * Parse react router routes array\n */\nclass ParseRoutes {\n /**\n * Path normalize service\n */\n protected readonly pathNormalize: PathNormalize;\n\n /**\n * Server config\n */\n protected readonly config: ServerConfig;\n\n /**\n * @constructor\n */\n constructor(config: ServerConfig, viteAliases?: Alias[]) {\n this.config = config;\n this.pathNormalize = new PathNormalize(config, viteAliases);\n }\n\n /**\n * Parse routes\n */\n public parse(): TRoutesTree[] {\n const { clientFile, root } = this.config.getParams();\n\n const clientEntrypoint = resolve(root, clientFile);\n const routesEntrypoint = this.findRoutesEntrypoint(clientEntrypoint);\n\n if (!routesEntrypoint?.routesPath) {\n throw new Error(`Unable to find routes file import in ${clientFile}`);\n }\n\n const { routesPath, exportName } = routesEntrypoint;\n const routeFilepath = this.resolveFilename(routesPath, clientEntrypoint);\n\n return this.recursiveBuildRoutesTree(routeFilepath, exportName);\n }\n\n /**\n * Parse file and return ast\n */\n private parseFile(filename: string): ParseResult<BabelFile> | null {\n try {\n const code = fs.readFileSync(filename, 'utf-8');\n\n return parser.parse(code, {\n sourceType: 'module',\n plugins: ['typescript', 'jsx'],\n });\n } catch {\n return null;\n }\n }\n\n /**\n * Find route import filepath\n */\n private getImportPath(\n ast: ParseResult<BabelFile>,\n importName: string | null,\n ): IPathImport | null {\n let routesPath: string | null = null;\n let exportName: string | null = null;\n\n traverse(ast, {\n ImportDeclaration(nodePath) {\n const importNode = nodePath.node;\n\n importNode.specifiers.forEach((specifier) => {\n if (specifier.local.name === importName) {\n exportName = specifier.type === 'ImportDefaultSpecifier' ? null : importName;\n routesPath = importNode.source.value;\n }\n });\n },\n });\n\n return {\n routesPath,\n exportName,\n };\n }\n\n /**\n * Find routes array inside code\n */\n private findRoutesDefinition(\n ast: ParseResult<BabelFile>,\n exportName: string | null,\n ): null | VariableDeclaration {\n let exportNameResolved = exportName;\n\n // noinspection JSUnusedGlobalSymbols\n traverse(ast, {\n ExportNamedDeclaration({ node }) {\n if (!node.declaration && node.specifiers.length > 0) {\n node.specifiers.forEach((specifier) => {\n // @ts-expect-error missing in types\n const exportedName = specifier.exported.name as string;\n\n if (exportName === null && specifier.type === 'ExportSpecifier') {\n if (specifier.local.name === 'default') {\n exportNameResolved = exportedName;\n }\n } else if (exportedName === exportName) {\n // @ts-expect-error missing in types\n // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access\n exportNameResolved = specifier.local.name as string;\n }\n });\n }\n },\n ExportDefaultDeclaration({ node }) {\n if (exportName === null) {\n if (node.declaration.type === 'Identifier') {\n exportNameResolved = node.declaration.name;\n // @ts-expect-error missing in types\n } else if (node.declaration.type === 'VariableDeclaration') {\n // @ts-expect-error missing in types\n // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access\n exportNameResolved = node.declaration.declarations[0].id.name as string;\n }\n }\n },\n });\n\n if (exportNameResolved) {\n let variableNode: VariableDeclaration | null = null;\n\n traverse(ast, {\n VariableDeclaration({ node }) {\n node.declarations.forEach((declaration) => {\n // @ts-expect-error missing in types\n if (declaration.id.name === exportNameResolved) {\n variableNode = node;\n }\n });\n },\n });\n\n return variableNode;\n }\n\n return null;\n }\n\n /**\n * Entrypoint routes file\n */\n private findRoutesEntrypoint(clientEntrypoint: string): IPathImport | null {\n const ast = this.parseFile(clientEntrypoint);\n\n let routesVariable: string | null = null;\n\n if (!ast) {\n return routesVariable;\n }\n\n traverse(ast, {\n CallExpression({ node }) {\n if (\n // @ts-expect-error missing in types\n node.callee.name === 'entryClient' &&\n node.arguments.length >= 2 &&\n node.arguments[1].type === 'Identifier'\n ) {\n routesVariable = node.arguments[1].name;\n }\n },\n });\n\n return this.getImportPath(ast, routesVariable);\n }\n\n /**\n * Resolve route filename import\n */\n private resolveFilename(filename: string, relativeFile?: string): string | null {\n let resolvedFilename = filename;\n\n if ((filename.startsWith('./') || filename.startsWith('../')) && relativeFile) {\n resolvedFilename = path.resolve(path.dirname(relativeFile), filename);\n }\n\n const filepath = this.pathNormalize.getAppPath(resolvedFilename, true);\n\n return this.pathNormalize.findAppFile(filepath!);\n }\n\n /**\n * Parse ast array routes objects\n */\n private parseRoutesArray(\n elements: TraverseTypes.Node[],\n importsMap: IMapImports,\n relativeFile: string,\n ): TRoutesTree[] {\n const results: TRoutesTree[] = [];\n\n elements.forEach((node, index) => {\n if (node.type === 'ObjectExpression') {\n const routeInfo: TRoutesTree = { index, import: '', children: [] };\n\n node.properties.forEach((prop) => {\n const objectProp = prop as {\n key: { name: string };\n value: { type: string; elements: TraverseTypes.Node[] };\n };\n\n if (objectProp.key.name === 'children' && objectProp.value.type === 'ArrayExpression') {\n routeInfo.children = this.parseRoutesArray(\n objectProp.value.elements,\n importsMap,\n relativeFile,\n );\n }\n\n // async routes\n if (\n objectProp.key.name === 'lazy' &&\n objectProp.value.type === 'ArrowFunctionExpression'\n ) {\n // @ts-expect-error incorrect types\n const importCall = objectProp.value.body as CallExpression;\n\n if (importCall.type === 'CallExpression' && importCall.callee.type === 'Import') {\n const [importArg] = importCall.arguments;\n\n if (importArg.type === 'StringLiteral') {\n routeInfo.import = importArg.value;\n }\n }\n }\n\n // static routes: Component\n if (objectProp.key.name === 'Component' && objectProp.value.type === 'Identifier') {\n // @ts-expect-error incorrect types\n const importName = objectProp.value.name as string;\n const { path: importPath } = importsMap[importName] ?? {};\n\n if (importPath) {\n routeInfo.import = importPath;\n }\n }\n\n // static routes: element\n if (objectProp.key.name === 'element' && objectProp.value.type === 'JSXElement') {\n // @ts-expect-error incorrect types\n // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access\n const importName = objectProp.value?.openingElement?.name?.name as string;\n const { path: importPath } = importsMap[importName] ?? {};\n\n if (importPath) {\n routeInfo.import = importPath;\n }\n }\n\n if (objectProp.key.name === 'children' && objectProp.value.type === 'Identifier') {\n // @ts-expect-error incorrect types\n const importName = objectProp.value.name as string;\n const { path: importPath, isDefault } = importsMap[importName] ?? {};\n\n if (importPath) {\n const childrenFilePath = this.resolveFilename(importPath, relativeFile);\n\n if (childrenFilePath) {\n routeInfo.children = this.recursiveBuildRoutesTree(\n childrenFilePath,\n isDefault ? null : importName,\n );\n }\n }\n }\n });\n\n if (routeInfo.import || routeInfo.children.length > 0) {\n results.push(routeInfo);\n }\n }\n });\n\n return results;\n }\n\n /**\n * Parse imports map from ast\n */\n private static parseImportsMap(ast: ParseResult<BabelFile>): IMapImports {\n const importsMap: IMapImports = {};\n\n traverse(ast, {\n ImportDeclaration(nodePath) {\n const importNode = nodePath.node;\n\n importNode.specifiers.forEach((specifier) => {\n importsMap[specifier.local.name] = {\n path: importNode.source.value,\n isDefault: specifier.type === 'ImportDefaultSpecifier',\n };\n });\n },\n });\n\n return importsMap;\n }\n\n /**\n * Recursive build routes tree with dynamic imports\n */\n private recursiveBuildRoutesTree(\n filename: string | null,\n exportName: string | null = null,\n ): TRoutesTree[] {\n if (!filename) {\n return [];\n }\n\n const ast = this.parseFile(filename);\n\n if (!ast) {\n return [];\n }\n\n const routesNode = this.findRoutesDefinition(ast, exportName);\n const results: TRoutesTree[] = [];\n\n if (!routesNode) {\n return results;\n }\n\n const importsMap = ParseRoutes.parseImportsMap(ast);\n\n // @ts-expect-error missing types\n const elements = routesNode.declarations[0].init?.elements as TraverseTypes.Node[];\n\n results.push(...this.parseRoutesArray(elements, importsMap, filename));\n\n return results;\n }\n\n /**\n * Add pathId to static routes\n */\n private static processRouteFileCode(\n nodePath: TraverseTypes.NodePath<ObjectExpression>,\n importsMap: IMapImports,\n shouldAddPathId: boolean,\n addImportRouteWrapper: () => void,\n ): void {\n nodePath.node.properties.forEach((property) => {\n if (isObjectProperty(property) && isIdentifier(property.key)) {\n // async routes\n if (property.key.name === 'lazy' && property.value.type === 'ArrowFunctionExpression') {\n const importCall = property.value.body as CallExpression;\n const onlyClientProp = nodePath.node.properties.find(\n (p) => isObjectProperty(p) && isIdentifier(p.key) && p.key.name === 'onlyClient',\n );\n\n /**\n * Wrap lazy import with:\n * @see importRoute\n */\n property.value = {\n type: 'CallExpression',\n callee: {\n type: 'Identifier',\n name: 'n',\n },\n arguments:\n isObjectProperty(onlyClientProp) &&\n (isBooleanLiteral(onlyClientProp.value) ||\n isJSXElement(onlyClientProp.value) ||\n isFunction(onlyClientProp.value) ||\n isIdentifier(onlyClientProp.value))\n ? [property.value, onlyClientProp.value]\n : [property.value],\n };\n\n if (onlyClientProp) {\n nodePath.node.properties = nodePath.node.properties.filter((p) => p !== onlyClientProp);\n }\n\n addImportRouteWrapper();\n\n if (importCall.type === 'CallExpression' && importCall.callee.type === 'Import') {\n const [importArg] = importCall.arguments;\n // current object has part of array (inside array)\n const parent = nodePath.findParent?.((p) => isArrayExpression(p.node));\n\n if (\n parent &&\n importArg.type === 'StringLiteral' &&\n importArg.value &&\n shouldAddPathId\n ) {\n const pathIdProperty = objectProperty(\n identifier('pathId'),\n stringLiteral(importArg.value),\n );\n\n // Insert the pathId property right after the element property\n nodePath.node.properties.splice(\n nodePath.node.properties.indexOf(property) + 1,\n 0,\n pathIdProperty,\n );\n }\n }\n }\n\n if (property.key.name === 'element' || property.key.name === 'Component') {\n let componentName = '';\n\n if (isJSXElement(property.value) && isJSXIdentifier(property.value.openingElement.name)) {\n componentName = property.value.openingElement.name.name;\n } else if (isIdentifier(property.value)) {\n componentName = property.value.name;\n }\n\n // current object has part of array (inside array)\n const parent = nodePath.findParent?.((p) => isArrayExpression(p.node));\n const importName = importsMap[componentName]?.path;\n\n if (parent && importName && shouldAddPathId) {\n const pathIdProperty = objectProperty(identifier('pathId'), stringLiteral(importName));\n\n // Insert the pathId property right after the element property\n nodePath.node.properties.splice(\n nodePath.node.properties.indexOf(property) + 1,\n 0,\n pathIdProperty,\n );\n }\n }\n\n if (property.key.name === 'children' && isArrayExpression(property.value)) {\n // Process each object in the children array recursively\n property.value.elements.forEach((element) => {\n if (isObjectExpression(element)) {\n ParseRoutes.processRouteFileCode(\n { node: element } as TraverseTypes.NodePath<ObjectExpression>,\n importsMap,\n shouldAddPathId,\n addImportRouteWrapper,\n );\n }\n });\n }\n }\n });\n }\n\n /**\n * Inject pathId to sync/async routes\n * Add async wrapper (see import-routes)\n */\n public static handleRoutes(code: string, shouldAddPathId: boolean): string {\n if (!code) {\n return code;\n }\n\n const ast = parser.parse(code, {\n sourceType: 'module',\n plugins: ['typescript', 'jsx'],\n });\n\n if (!ast) {\n return code;\n }\n\n const importsMap = ParseRoutes.parseImportsMap(ast);\n let shouldAddRoutesImport = false;\n\n traverse(ast, {\n ObjectExpression(nodePath): void {\n ParseRoutes.processRouteFileCode(nodePath, importsMap, shouldAddPathId, () => {\n shouldAddRoutesImport = true;\n });\n },\n });\n\n if (shouldAddRoutesImport) {\n ast.program.body.unshift({\n type: 'ImportDeclaration',\n specifiers: [\n {\n type: 'ImportDefaultSpecifier',\n local: {\n type: 'Identifier',\n name: 'n',\n },\n },\n ],\n source: {\n type: 'StringLiteral',\n value: `${PLUGIN_NAME}/helpers/import-route`,\n },\n });\n }\n\n return generate(ast, {\n retainLines: true,\n }).code;\n }\n}\n\nexport default ParseRoutes;\n"],"names":["generate","babelGenerate","default","traverse","babelTraverse","ParseRoutes","pathNormalize","config","constructor","viteAliases","this","PathNormalize","parse","clientFile","root","getParams","clientEntrypoint","resolve","routesEntrypoint","findRoutesEntrypoint","routesPath","Error","exportName","routeFilepath","resolveFilename","recursiveBuildRoutesTree","parseFile","filename","code","fs","readFileSync","parser","sourceType","plugins","getImportPath","ast","importName","ImportDeclaration","nodePath","importNode","node","specifiers","forEach","specifier","local","name","type","source","value","findRoutesDefinition","exportNameResolved","ExportNamedDeclaration","declaration","length","exportedName","exported","ExportDefaultDeclaration","declarations","id","variableNode","VariableDeclaration","routesVariable","CallExpression","callee","arguments","relativeFile","resolvedFilename","startsWith","path","dirname","filepath","getAppPath","findAppFile","parseRoutesArray","elements","importsMap","results","index","routeInfo","import","children","properties","prop","objectProp","key","importCall","body","importArg","importPath","openingElement","isDefault","childrenFilePath","push","static","routesNode","parseImportsMap","init","shouldAddPathId","addImportRouteWrapper","property","isObjectProperty","isIdentifier","onlyClientProp","find","p","isBooleanLiteral","isJSXElement","isFunction","filter","parent","findParent","isArrayExpression","pathIdProperty","objectProperty","identifier","stringLiteral","splice","indexOf","componentName","isJSXIdentifier","element","isObjectExpression","processRouteFileCode","shouldAddRoutesImport","ObjectExpression","program","unshift","PLUGIN_NAME","retainLines"],"mappings":"4eAkCA,MAAMA,EAAYC,EAAcC,SAAWD,EAErCE,EAAYC,EAAcF,SAAWE,EAuB3C,MAAMC,EAIeC,cAKAC,OAKnBC,YAAYD,EAAsBE,GAChCC,KAAKH,OAASA,EACdG,KAAKJ,cAAgB,IAAIK,EAAcJ,EAAQE,EACjD,CAKOG,QACL,MAAMC,WAAEA,EAAUC,KAAEA,GAAS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EAAM,CAC7BI,WAAY,SACZC,QAAS,CAAC,aAAc,SAG1B,IAAKE,EACH,OAAOP,EAGT,MAAM+C,EAAatE,EAAY0F,gBAAgB5D,GAC/C,IAAIwF,GAAwB,EA6B5B,OA3BAxH,EAASgC,EAAK,CACZyF,iBAAiBtF,GACfjC,EAAYqH,qBAAqBpF,EAAUqC,EAAYsB,GAAiB,KACtE0B,GAAwB,CAAI,GAEhC,IAGEA,GACFxF,EAAI0F,QAAQvC,KAAKwC,QAAQ,CACvBhF,KAAM,oBACNL,WAAY,CACV,CACEK,KAAM,yBACNF,MAAO,CACLE,KAAM,aACND,KAAM,OAIZE,OAAQ,CACND,KAAM,gBACNE,MAAO,GAAG+E,4BAKT/H,EAASmC,EAAK,CACnB6F,aAAa,IACZpG,IACL"}
|
|
1
|
+
{"version":3,"file":"parse-routes.js","sources":["../../src/services/parse-routes.ts"],"sourcesContent":[null],"names":["generate","babelGenerate","default","traverse","babelTraverse","ParseRoutes","pathNormalize","config","constructor","viteAliases","this","PathNormalize","parse","clientFile","root","getParams","clientEntrypoint","resolve","routesEntrypoint","findRoutesEntrypoint","routesPath","Error","exportName","routeFilepath","resolveFilename","recursiveBuildRoutesTree","parseFile","filename","code","fs","readFileSync","parser","sourceType","createImportExpressions","plugins","getImportPath","ast","importName","ImportDeclaration","nodePath","importNode","node","specifiers","forEach","specifier","local","name","type","source","value","findRoutesDefinition","exportNameResolved","ExportNamedDeclaration","declaration","length","exportedName","exported","ExportDefaultDeclaration","declarations","id","variableNode","VariableDeclaration","routesVariable","CallExpression","callee","arguments","relativeFile","resolvedFilename","startsWith","path","dirname","filepath","getAppPath","findAppFile","parseRoutesArray","elements","importsMap","results","index","routeInfo","import","children","properties","prop","objectProp","key","importCall","body","importArg","importPath","openingElement","isDefault","childrenFilePath","push","parseImportsMap","routesNode","init","processRouteFileCode","shouldAddPathId","addImportRouteWrapper","property","isObjectProperty","isIdentifier","onlyClientProp","find","p","isBooleanLiteral","isJSXElement","isFunction","filter","parent","findParent","isArrayExpression","pathIdProperty","objectProperty","identifier","stringLiteral","splice","indexOf","componentName","isJSXIdentifier","element","isObjectExpression","handleRoutes","shouldAddRoutesImport","ObjectExpression","program","unshift","PLUGIN_NAME","retainLines"],"mappings":"4eAmCA,MAAMA,EAAYC,EAAcC,SAAWD,EAErCE,EAAYC,EAAcF,SAAWE,EAuB3C,MAAMC,EAIeC,cAKAC,OAKnB,WAAAC,CAAYD,EAAsBE,GAChCC,KAAKH,OAASA,EACdG,KAAKJ,cAAgB,IAAIK,EAAcJ,EAAQE,EACjD,CAKO,KAAAG,GACL,MAAMC,WAAEA,EAAUC,KAAEA,GAASJ,KAAKH,OAAOQ,YAEnCC,EAAmBC,EAAQH,EAAMD,GACjCK,EAAmBR,KAAKS,qBAAqBH,GAEnD,IAAKE,GAAkBE,WACrB,MAAM,IAAIC,MAAM,wCAAwCR,KAG1D,MAAMO,WAAEA,EAAUE,WAAEA,GAAeJ,EAC7BK,EAAgBb,KAAKc,gBAAgBJ,EAAYJ,GAEvD,OAAON,KAAKe,yBAAyBF,EAAeD,EACtD,CAKQ,SAAAI,CAAUC,GAChB,IACE,MAAMC,EAAOC,EAAGC,aAAaH,EAAU,SAEvC,OAAOI,EAAOnB,MAAMgB,EAAM,CACxBI,WAAY,SACZC,yBAAyB,EACzBC,QAAS,CAAC,aAAc,QAE5B,CAAE,MACA,OAAO,IACT,CACF,CAKQ,aAAAC,CACNC,EACAC,GAEA,IAAIjB,EAA4B,KAC5BE,EAA4B,KAehC,OAbAnB,EAASiC,EAAK,CACZ,iBAAAE,CAAkBC,GAChB,MAAMC,EAAaD,EAASE,KAE5BD,EAAWE,WAAWC,QAASC,IACzBA,EAAUC,MAAMC,OAAST,IAC3Bf,EAAgC,2BAAnBsB,EAAUG,KAAoC,KAAOV,EAClEjB,EAAaoB,EAAWQ,OAAOC,QAGrC,IAGK,CACL7B,aACAE,aAEJ,CAKQ,oBAAA4B,CACNd,EACAd,GAEA,IAAI6B,EAAqB7B,E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,MAAMe,EAAiBC,EAAeC,EAAW,UAAWC,EAAc/E,IAG1EE,EAASE,KAAKyC,WAAWmC,OACvB9E,EAASE,KAAKyC,WAAWoC,QAAQlB,GAAY,EAC7C,EACAa,EAEJ,CACF,CAE0B,aAAtBb,EAASf,IAAIvC,MAAuBkE,EAAkBZ,EAASnD,QAEjEmD,EAASnD,MAAM0B,SAAShC,QAAS8E,IAC3BC,EAAmBD,IACrBpH,EAAY4F,qBACV,CAAExD,KAAMgF,GACR7C,EACAsB,EACAC,IAKV,GAEJ,CAMO,mBAAOwB,CAAa/F,EAAcsE,GACvC,IAAKtE,EACH,OAAOA,EAGT,MAAMQ,EAAML,EAAOnB,MAAMgB,EAAM,CAC7BI,WAAY,SACZC,yBAAyB,EACzBC,QAAS,CAAC,aAAc,SAG1B,IAAKE,EACH,OAAOR,EAGT,MAAMgD,EAAavE,EAAYyF,gBAAgB1D,GAC/C,IAAIwF,GAAwB,EA6B5B,OA3BAzH,EAASiC,EAAK,CACZ,gBAAAyF,CAAiBtF,GACflC,EAAY4F,qBAAqB1D,EAAUqC,EAAYsB,EAAiB,KACtE0B,GAAwB,GAE5B,IAGEA,GACFxF,EAAI0F,QAAQvC,KAAKwC,QAAQ,CACvBhF,KAAM,oBACNL,WAAY,CACV,CACEK,KAAM,yBACNF,MAAO,CACLE,KAAM,aACND,KAAM,OAIZE,OAAQ,CACND,KAAM,gBACNE,MAAO,GAAG+E,4BAKThI,EAASoC,EAAK,CACnB6F,aAAa,IACZrG,IACL"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { Alias } from 'vite';
|
|
2
|
-
import ServerConfig from
|
|
1
|
+
import type { Alias } from 'vite';
|
|
2
|
+
import type ServerConfig from './server-config.js';
|
|
3
3
|
/**
|
|
4
4
|
* Service for work with path and aliases
|
|
5
5
|
*/
|
|
@@ -12,40 +12,25 @@ declare class PathNormalize {
|
|
|
12
12
|
* Server config
|
|
13
13
|
*/
|
|
14
14
|
protected readonly config: ServerConfig;
|
|
15
|
-
/**
|
|
16
|
-
* @constructor
|
|
17
|
-
*/
|
|
18
15
|
/**
|
|
19
16
|
* @constructor
|
|
20
17
|
*/
|
|
21
18
|
constructor(config: ServerConfig, viteAliases?: Alias[]);
|
|
22
|
-
/**
|
|
23
|
-
* Get vite aliases
|
|
24
|
-
*/
|
|
25
19
|
/**
|
|
26
20
|
* Get vite aliases
|
|
27
21
|
*/
|
|
28
22
|
getAliases(): Record<string, string>;
|
|
29
|
-
/**
|
|
30
|
-
* Return filename postfix
|
|
31
|
-
*/
|
|
32
23
|
/**
|
|
33
24
|
* Return filename postfix
|
|
34
25
|
*/
|
|
35
26
|
getImportPostfix(): string[];
|
|
36
|
-
/**
|
|
37
|
-
* Resolve app path
|
|
38
|
-
*/
|
|
39
27
|
/**
|
|
40
28
|
* Resolve app path
|
|
41
29
|
*/
|
|
42
30
|
getAppPath(appPath?: string, withRoot?: boolean): string | undefined;
|
|
43
|
-
/**
|
|
44
|
-
* Find app filepath
|
|
45
|
-
*/
|
|
46
31
|
/**
|
|
47
32
|
* Find app filepath
|
|
48
33
|
*/
|
|
49
34
|
findAppFile(basePath: string): string | null;
|
|
50
35
|
}
|
|
51
|
-
export
|
|
36
|
+
export default PathNormalize;
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import t from"node:fs";import s from"path";class e{viteAliases;config;constructor(t,s){this.config=t,this.viteAliases=s??t.getVite()?.config?.resolve.alias}getAliases(){const t={};return this.viteAliases?.forEach((
|
|
1
|
+
import t from"node:fs";import s from"path";class e{viteAliases;config;constructor(t,s){this.config=t,this.viteAliases=s??t.getVite()?.config?.resolve.alias}getAliases(){const t={};return this.viteAliases?.forEach(({find:s,replacement:e})=>{"string"==typeof s&&(t[s]=e)}),t}getImportPostfix(){return["","/index"].map(t=>["",".js",".ts",".tsx"].map(s=>`${t}${s}`)).flat()}getAppPath(t,e=!1){if(!t)return;const{root:i}=this.config.getParams();let r=t;if(t.startsWith("./")||t.startsWith("../"))r=s.resolve(i,t);else{const s=this.getAliases(),[e]=t.split("/");s[e]&&(r=t.replace(e,s[e]))}return r=r.split(s.win32.sep).join(s.posix.sep),e?r:r.replace(i,"").replace(/^(\/)|(\/)$/g,"")}findAppFile(s){const e=this.getImportPostfix();for(const i of e){const e=`${s}${i}`;if(t.existsSync(e)&&t.statSync(e).isFile())return e}return null}}export{e as default};
|
|
2
2
|
//# sourceMappingURL=path-normalize.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"path-normalize.js","sources":["../../src/services/path-normalize.ts"],"sourcesContent":[
|
|
1
|
+
{"version":3,"file":"path-normalize.js","sources":["../../src/services/path-normalize.ts"],"sourcesContent":[null],"names":["PathNormalize","viteAliases","config","constructor","this","getVite","resolve","alias","getAliases","aliases","forEach","find","replacement","getImportPostfix","map","prefix","ext","flat","getAppPath","appPath","withRoot","root","getParams","fullPath","startsWith","path","routeAlias","split","replace","win32","sep","join","posix","findAppFile","basePath","postfixes","postfix","filepath","fs","existsSync","statSync","isFile"],"mappings":"2CAQA,MAAMA,EAIeC,YAKAC,OAKnB,WAAAC,CAAYD,EAAsBD,GAChCG,KAAKF,OAASA,EACdE,KAAKH,YAAcA,GAAeC,EAAOG,WAAWH,QAAQI,QAAQC,KACtE,CAKO,UAAAC,GACL,MAAMC,EAAkC,CAAA,EAUxC,OARAL,KAAKH,aAAaS,QAAQ,EAAGC,OAAMC,kBACb,iBAATD,IAIXF,EAAQE,GAAQC,KAGXH,CACT,CAKO,gBAAAI,GACL,MAAO,CAAC,GAAI,UACTC,IAAKC,GAAW,CAAC,GAAI,MAAO,MAAO,QAAQD,IAAKE,GAAQ,GAAGD,IAASC,MACpEC,MACL,CAKO,UAAAC,CAAWC,EAAkBC,GAAW,GAC7C,IAAKD,EACH,OAGF,MAAME,KAAEA,GAASjB,KAAKF,OAAOoB,YAC7B,IAAIC,EAAWJ,EAGf,GAAIA,EAAQK,WAAW,OAASL,EAAQK,WAAW,OACjDD,EAAWE,EAAKnB,QAAQe,EAAMF,OACzB,CAEL,MAAMV,EAAUL,KAAKI,cAEdkB,GAAcP,EAAQQ,MAAM,KAE/BlB,EAAQiB,KACVH,EAAWJ,EAAQS,QAAQF,EAAYjB,EAAQiB,IAEnD,CAKA,OAFAH,EAAWA,EAASI,MAAMF,EAAKI,MAAMC,KAAKC,KAAKN,EAAKO,MAAMF,KAEtDV,EACKG,EAGFA,EAASK,QAAQP,EAAM,IAAIO,QAAQ,eAAgB,GAC5D,CAKO,WAAAK,CAAYC,GACjB,MAAMC,EAAY/B,KAAKS,mBAEvB,IAAK,MAAMuB,KAAWD,EAAW,CAC/B,MAAME,EAAW,GAAGH,IAAWE,IAE/B,GAAIE,EAAGC,WAAWF,IAAaC,EAAGE,SAASH,GAAUI,SACnD,OAAOJ,CAEX,CAEA,OAAO,IACT"}
|
package/services/server-api.d.ts
CHANGED
|
@@ -6,19 +6,13 @@ declare class ServerApi {
|
|
|
6
6
|
* Block access to index.html
|
|
7
7
|
*/
|
|
8
8
|
protected isAllowIndexHtml: boolean;
|
|
9
|
-
/**
|
|
10
|
-
* Server can return index.html
|
|
11
|
-
*/
|
|
12
9
|
/**
|
|
13
10
|
* Server can return index.html
|
|
14
11
|
*/
|
|
15
12
|
hasAccessIndexHtml(): boolean;
|
|
16
|
-
/**
|
|
17
|
-
* Allow/disallow return index.html on request
|
|
18
|
-
*/
|
|
19
13
|
/**
|
|
20
14
|
* Allow/disallow return index.html on request
|
|
21
15
|
*/
|
|
22
16
|
changeAccessIndexHtml(isAllowed: boolean): void;
|
|
23
17
|
}
|
|
24
|
-
export
|
|
18
|
+
export default ServerApi;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"server-api.js","sources":["../../src/services/server-api.ts"],"sourcesContent":[
|
|
1
|
+
{"version":3,"file":"server-api.js","sources":["../../src/services/server-api.ts"],"sourcesContent":[null],"names":["ServerApi","isAllowIndexHtml","hasAccessIndexHtml","this","changeAccessIndexHtml","isAllowed"],"mappings":"AAGA,MAAMA,EAIMC,kBAAmB,EAKtB,kBAAAC,GACL,OAAOC,KAAKF,gBACd,CAKO,qBAAAG,CAAsBC,GAC3BF,KAAKF,iBAAmBI,CAC1B"}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { Logger, ViteDevServer } from 'vite';
|
|
2
|
-
import { IPluginConfig } from
|
|
3
|
-
import { IBuildEntrypoint } from
|
|
1
|
+
import type { Logger, ViteDevServer } from 'vite';
|
|
2
|
+
import type { IPluginConfig } from '../helpers/plugin-config.js';
|
|
3
|
+
import type { IBuildEntrypoint } from './build.js';
|
|
4
4
|
interface IConfigOptions {
|
|
5
5
|
isProd?: boolean;
|
|
6
6
|
isHost?: boolean;
|
|
@@ -69,107 +69,63 @@ declare class ServerConfig {
|
|
|
69
69
|
* Default root dir
|
|
70
70
|
*/
|
|
71
71
|
protected defaultBuildRoots: string[];
|
|
72
|
-
/**
|
|
73
|
-
* @constructor
|
|
74
|
-
*/
|
|
75
72
|
/**
|
|
76
73
|
* @constructor
|
|
77
74
|
*/
|
|
78
75
|
protected constructor({ entrypointName, isProd, isHost, isOnlyClient, isModulePreload, mode, }: IConfigOptions, prodParams: Partial<IConfigParams>);
|
|
79
|
-
/**
|
|
80
|
-
* Initialize service
|
|
81
|
-
*/
|
|
82
76
|
/**
|
|
83
77
|
* Initialize service
|
|
84
78
|
*/
|
|
85
79
|
static init(options?: IConfigOptions, prodOptions?: Partial<IConfigParams>): ServerConfig;
|
|
86
|
-
/**
|
|
87
|
-
* Lookup build folder
|
|
88
|
-
*/
|
|
89
80
|
/**
|
|
90
81
|
* Lookup build folder
|
|
91
82
|
*/
|
|
92
83
|
protected getBuildDir(root?: string): string;
|
|
93
|
-
/**
|
|
94
|
-
* Make config params
|
|
95
|
-
*/
|
|
96
84
|
/**
|
|
97
85
|
* Make config params
|
|
98
86
|
*/
|
|
99
87
|
protected makeParams(): void;
|
|
100
|
-
/**
|
|
101
|
-
* Set vite server
|
|
102
|
-
*/
|
|
103
88
|
/**
|
|
104
89
|
* Set vite server
|
|
105
90
|
*/
|
|
106
91
|
setVite(vite: ViteDevServer): void;
|
|
107
|
-
/**
|
|
108
|
-
* Set express server
|
|
109
|
-
*/
|
|
110
92
|
/**
|
|
111
93
|
* Set express server
|
|
112
94
|
*/
|
|
113
95
|
setApp<T>(app: T): void;
|
|
114
|
-
/**
|
|
115
|
-
* Return vite dev server
|
|
116
|
-
* NOTE: only on development mode
|
|
117
|
-
*/
|
|
118
96
|
/**
|
|
119
97
|
* Return vite dev server
|
|
120
98
|
* NOTE: only on development mode
|
|
121
99
|
*/
|
|
122
100
|
getVite(): ViteDevServer | undefined;
|
|
123
|
-
/**
|
|
124
|
-
* Return express server
|
|
125
|
-
*/
|
|
126
101
|
/**
|
|
127
102
|
* Return express server
|
|
128
103
|
*/
|
|
129
104
|
getApp<T = unknown>(): T | undefined;
|
|
130
|
-
/**
|
|
131
|
-
* Return plugin config
|
|
132
|
-
* NOTE: only on development mode
|
|
133
|
-
*/
|
|
134
105
|
/**
|
|
135
106
|
* Return plugin config
|
|
136
107
|
* NOTE: only on development mode
|
|
137
108
|
*/
|
|
138
109
|
getPluginConfig(): IPluginConfig | undefined;
|
|
139
|
-
/**
|
|
140
|
-
* Return config params
|
|
141
|
-
*/
|
|
142
110
|
/**
|
|
143
111
|
* Return config params
|
|
144
112
|
*/
|
|
145
113
|
getParams(): IConfigParams;
|
|
146
|
-
/**
|
|
147
|
-
* Get server logger
|
|
148
|
-
*/
|
|
149
114
|
/**
|
|
150
115
|
* Get server logger
|
|
151
116
|
*/
|
|
152
117
|
getLogger(): Logger;
|
|
153
|
-
/**
|
|
154
|
-
* Set custom logger
|
|
155
|
-
*/
|
|
156
118
|
/**
|
|
157
119
|
* Set custom logger
|
|
158
120
|
*/
|
|
159
121
|
setLogger(logger: Logger): void;
|
|
160
|
-
/**
|
|
161
|
-
* Apply config to specified entrypoint
|
|
162
|
-
*/
|
|
163
122
|
/**
|
|
164
123
|
* Apply config to specified entrypoint
|
|
165
124
|
*/
|
|
166
125
|
protected applyEntrypointConfig(): void;
|
|
167
|
-
/**
|
|
168
|
-
* Get current entrypoint
|
|
169
|
-
*/
|
|
170
126
|
/**
|
|
171
127
|
* Get current entrypoint
|
|
172
128
|
*/
|
|
173
129
|
protected getEntrypoint(): IBuildEntrypoint | undefined;
|
|
174
130
|
}
|
|
175
|
-
export
|
|
131
|
+
export default ServerConfig;
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import t from"node:fs";import i from"node:path";import e from"../helpers/plugin-config.js";import r from"./logger.js";class s{isProd;isHost;isModulePreload;mode;entrypointName;vite;app;params;defaultParams;logger;defaultBuildRoots=["./build","./dist"];constructor({entrypointName:t,isProd:i=!1,isHost:e=!1,isOnlyClient:r=!1,isModulePreload:s=!1,mode:o="production"},n){this.isProd=i,this.isHost=e,this.isModulePreload=s,this.mode=o,this.entrypointName=t,this.defaultParams={publicDir:"/client",indexFile:"/client/index.html",serverFile:"/server/server.js",host:"127.0.0.1",isSPA:r,...n},this.makeParams()}static init(t={},i={}){return new s(t,i)}getBuildDir(i){for(const e of[i,...this.defaultBuildRoots])if(e&&t.existsSync(e))return e;return i??this.defaultBuildRoots[0]}makeParams(){this.applyEntrypointConfig();const t=this.getPluginConfig()??{},{config:e}=this.vite??{},{root:s,publicDir:o,indexFile:n,clientFile:l,serverFile:a,host:p,isSPA:h}=this.defaultParams,g=new URL(import.meta.url),d=t.pluginPath??i.resolve(i.dirname(g.pathname),"../"),u=this.getEntrypoint(),m="boolean"==typeof e?.server.host||this.isHost?"0.0.0.0":e?.server.host??p,f=Number(e?.env.VITE_PORT??e?.server.port??this.defaultParams.port);this.params={root:e?.root??this.getBuildDir(s),publicDir:e?.publicDir??o,indexFile:t.indexFile??n,clientFile:t.clientFile??l,serverFile:t.serverFile??a,pluginPath:d,host:m,port:f,isSPA:u?"spa"===u.type:h,isProd:this.isProd},this.logger=this.vite?.config.logger??new r}setVite(t){this.vite=t,this.makeParams()}setApp(t){this.app=t}getVite(){return this.vite}getApp(){return this.app}getPluginConfig(){return this.vite?e(this.vite.config):void 0}getParams(){return this.params}getLogger(){return this.logger}setLogger(t){this.logger=t}applyEntrypointConfig(){const t=this.getPluginConfig();if(!this.vite||!t||!this.entrypointName)return;const i=this.getEntrypoint();i&&["indexFile","clientFile","serverFile"].forEach(
|
|
1
|
+
import t from"node:fs";import i from"node:path";import e from"../helpers/plugin-config.js";import r from"./logger.js";class s{isProd;isHost;isModulePreload;mode;entrypointName;vite;app;params;defaultParams;logger;defaultBuildRoots=["./build","./dist"];constructor({entrypointName:t,isProd:i=!1,isHost:e=!1,isOnlyClient:r=!1,isModulePreload:s=!1,mode:o="production"},n){this.isProd=i,this.isHost=e,this.isModulePreload=s,this.mode=o,this.entrypointName=t,this.defaultParams={publicDir:"/client",indexFile:"/client/index.html",serverFile:"/server/server.js",host:"127.0.0.1",isSPA:r,...n},this.makeParams()}static init(t={},i={}){return new s(t,i)}getBuildDir(i){for(const e of[i,...this.defaultBuildRoots])if(e&&t.existsSync(e))return e;return i??this.defaultBuildRoots[0]}makeParams(){this.applyEntrypointConfig();const t=this.getPluginConfig()??{},{config:e}=this.vite??{},{root:s,publicDir:o,indexFile:n,clientFile:l,serverFile:a,host:p,isSPA:h}=this.defaultParams,g=new URL(import.meta.url),d=t.pluginPath??i.resolve(i.dirname(g.pathname),"../"),u=this.getEntrypoint(),m="boolean"==typeof e?.server.host||this.isHost?"0.0.0.0":e?.server.host??p,f=Number(e?.env.VITE_PORT??e?.server.port??this.defaultParams.port);this.params={root:e?.root??this.getBuildDir(s),publicDir:e?.publicDir??o,indexFile:t.indexFile??n,clientFile:t.clientFile??l,serverFile:t.serverFile??a,pluginPath:d,host:m,port:f,isSPA:u?"spa"===u.type:h,isProd:this.isProd},this.logger=this.vite?.config.logger??new r}setVite(t){this.vite=t,this.makeParams()}setApp(t){this.app=t}getVite(){return this.vite}getApp(){return this.app}getPluginConfig(){return this.vite?e(this.vite.config):void 0}getParams(){return this.params}getLogger(){return this.logger}setLogger(t){this.logger=t}applyEntrypointConfig(){const t=this.getPluginConfig();if(!this.vite||!t||!this.entrypointName)return;const i=this.getEntrypoint();i&&["indexFile","clientFile","serverFile"].forEach(e=>{i[e]&&(t[e]=i[e])})}getEntrypoint(){const t=this.vite?e(this.vite.config):void 0;return t?.entrypoint?.find(({name:t})=>t===this.entrypointName)}}export{s as default};
|
|
2
2
|
//# sourceMappingURL=server-config.js.map
|