@analogjs/platform 3.0.0-beta.2 → 3.0.0-beta.20
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/package.json +8 -5
- package/src/lib/content-plugin.js +12 -3
- package/src/lib/content-plugin.js.map +1 -1
- package/src/lib/deps-plugin.d.ts +1 -1
- package/src/lib/deps-plugin.js +10 -6
- package/src/lib/deps-plugin.js.map +1 -1
- package/src/lib/get-page-endpoints.d.ts +25 -0
- package/src/lib/get-page-endpoints.js +29 -0
- package/src/lib/get-page-endpoints.js.map +1 -0
- package/src/lib/nitro/get-page-handlers.d.ts +4 -19
- package/src/lib/nitro/get-page-handlers.js +9 -26
- package/src/lib/nitro/get-page-handlers.js.map +1 -1
- package/src/lib/nx-plugin/executors.json +0 -7
- package/src/lib/nx-plugin/src/generators/app/compat.d.ts +2 -1
- package/src/lib/nx-plugin/src/generators/app/compat.js +4 -1
- package/src/lib/nx-plugin/src/generators/app/compat.js.map +1 -1
- package/src/lib/nx-plugin/src/generators/app/generator.js +7 -2
- package/src/lib/nx-plugin/src/generators/app/generator.js.map +1 -1
- package/src/lib/nx-plugin/src/generators/app/lib/add-tailwind-helpers.js +2 -2
- package/src/lib/nx-plugin/src/generators/app/lib/add-tailwind-helpers.js.map +1 -1
- package/src/lib/nx-plugin/src/generators/app/versions/minimum-supported-versions.d.ts +3 -1
- package/src/lib/nx-plugin/src/generators/app/versions/minimum-supported-versions.js +5 -1
- package/src/lib/nx-plugin/src/generators/app/versions/minimum-supported-versions.js.map +1 -1
- package/src/lib/nx-plugin/src/generators/init/compat.d.ts +2 -1
- package/src/lib/nx-plugin/src/generators/init/compat.js +4 -1
- package/src/lib/nx-plugin/src/generators/init/compat.js.map +1 -1
- package/src/lib/nx-plugin/src/generators/init/lib/add-analog-dependencies.js +2 -2
- package/src/lib/nx-plugin/src/generators/init/lib/add-analog-dependencies.js.map +1 -1
- package/src/lib/nx-plugin/src/generators/page/compat.d.ts +2 -1
- package/src/lib/nx-plugin/src/generators/page/compat.js +4 -1
- package/src/lib/nx-plugin/src/generators/page/compat.js.map +1 -1
- package/src/lib/nx-plugin/src/generators/preset/__snapshots__/generator.spec.ts.snap +4 -0
- package/src/lib/nx-plugin/src/generators/preset/generator.js +5 -2
- package/src/lib/nx-plugin/src/generators/preset/generator.js.map +1 -1
- package/src/lib/nx-plugin/src/utils/versions/dev-dependencies.d.ts +2 -2
- package/src/lib/nx-plugin/src/utils/versions/dev-dependencies.js +7 -3
- package/src/lib/nx-plugin/src/utils/versions/dev-dependencies.js.map +1 -1
- package/src/lib/nx-plugin/src/utils/versions/versions.d.ts +9 -6
- package/src/lib/nx-plugin/src/utils/versions/versions.js +13 -7
- package/src/lib/nx-plugin/src/utils/versions/versions.js.map +1 -1
- package/src/lib/options.d.ts +16 -0
- package/src/lib/platform-plugin.js +2 -0
- package/src/lib/platform-plugin.js.map +1 -1
- package/src/lib/router-plugin.js +1 -1
- package/src/lib/router-plugin.js.map +1 -1
- package/src/lib/server-plugin.d.ts +9 -0
- package/src/lib/server-plugin.js +154 -0
- package/src/lib/server-plugin.js.map +1 -0
- package/src/lib/typed-routes-plugin.js +1 -1
- package/src/lib/typed-routes-plugin.js.map +1 -1
- package/src/lib/nx-plugin/src/executors/vite-dev-server/compat.d.ts +0 -3
- package/src/lib/nx-plugin/src/executors/vite-dev-server/compat.js +0 -7
- package/src/lib/nx-plugin/src/executors/vite-dev-server/compat.js.map +0 -1
- package/src/lib/nx-plugin/src/executors/vite-dev-server/schema.d.ts +0 -1
- package/src/lib/nx-plugin/src/executors/vite-dev-server/schema.json +0 -101
- package/src/lib/nx-plugin/src/executors/vite-dev-server/vite-dev-server.impl.d.ts +0 -2
- package/src/lib/nx-plugin/src/executors/vite-dev-server/vite-dev-server.impl.js +0 -6
- package/src/lib/nx-plugin/src/executors/vite-dev-server/vite-dev-server.impl.js.map +0 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@analogjs/platform",
|
|
3
|
-
"version": "3.0.0-beta.
|
|
3
|
+
"version": "3.0.0-beta.20",
|
|
4
4
|
"description": "The fullstack meta-framework for Angular",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"author": "Brandon Roberts <robertsbt@gmail.com>",
|
|
@@ -31,7 +31,7 @@
|
|
|
31
31
|
"url": "https://github.com/sponsors/brandonroberts"
|
|
32
32
|
},
|
|
33
33
|
"dependencies": {
|
|
34
|
-
"@analogjs/vite-plugin-angular": "3.0.0-beta.
|
|
34
|
+
"@analogjs/vite-plugin-angular": "3.0.0-beta.20",
|
|
35
35
|
"es-toolkit": "^1.45.1",
|
|
36
36
|
"front-matter": "^4.0.2",
|
|
37
37
|
"magic-string": "^0.30.21",
|
|
@@ -45,13 +45,16 @@
|
|
|
45
45
|
},
|
|
46
46
|
"devDependencies": {
|
|
47
47
|
"@babel/core": "^8.0.0",
|
|
48
|
+
"@nx/angular": "24.0.0",
|
|
49
|
+
"@nx/devkit": "24.0.0",
|
|
50
|
+
"@nx/vite": "24.0.0",
|
|
48
51
|
"h3": "^2.0.1-rc.31",
|
|
49
52
|
"nitro": "3.0.260903-beta"
|
|
50
53
|
},
|
|
51
54
|
"peerDependencies": {
|
|
52
|
-
"@nx/angular": "^
|
|
53
|
-
"@nx/devkit": "^
|
|
54
|
-
"@nx/vite": "^
|
|
55
|
+
"@nx/angular": "^21.2.0 || ^22.0.0 || ^23.0.0 || ^24.0.0",
|
|
56
|
+
"@nx/devkit": "^21.2.0 || ^22.0.0 || ^23.0.0 || ^24.0.0",
|
|
57
|
+
"@nx/vite": "^21.2.0 || ^22.0.0 || ^23.0.0 || ^24.0.0",
|
|
55
58
|
"marked": "^18.0.0",
|
|
56
59
|
"marked-gfm-heading-id": "^4.1.3",
|
|
57
60
|
"marked-highlight": "^2.2.3",
|
|
@@ -4,6 +4,12 @@ import { readFileSync } from "node:fs";
|
|
|
4
4
|
import * as vite from "vite";
|
|
5
5
|
import { globSync } from "tinyglobby";
|
|
6
6
|
//#region packages/platform/src/lib/content-plugin.ts
|
|
7
|
+
function toModuleValue(value) {
|
|
8
|
+
if (value instanceof Date) return `new Date(${JSON.stringify(value.toISOString())})`;
|
|
9
|
+
if (Array.isArray(value)) return `[${value.map(toModuleValue).join(",")}]`;
|
|
10
|
+
if (value && typeof value === "object") return `{${Object.entries(value).map(([key, entry]) => `${JSON.stringify(key)}:${toModuleValue(entry)}`).join(",")}}`;
|
|
11
|
+
return JSON.stringify(value) ?? "undefined";
|
|
12
|
+
}
|
|
7
13
|
/**
|
|
8
14
|
* Content plugin that provides markdown and content file processing for Analog.
|
|
9
15
|
*
|
|
@@ -30,7 +36,10 @@ function contentPlugin({ highlighter, markedOptions, shikiOptions, prismOptions
|
|
|
30
36
|
contentRootDirs = [vite.normalizePath(`${root}/src/content`), ...(options?.additionalContentDirs || []).map(normalizeContentDir)];
|
|
31
37
|
};
|
|
32
38
|
const discoverContentFilesList = () => {
|
|
33
|
-
contentFilesListCache ??= globSync(contentRootDirs.map((dir) => `${dir}/**/*.md`), {
|
|
39
|
+
contentFilesListCache ??= globSync(contentRootDirs.map((dir) => `${dir}/**/*.md`), {
|
|
40
|
+
dot: true,
|
|
41
|
+
cwd: workspaceRoot
|
|
42
|
+
});
|
|
34
43
|
return contentFilesListCache;
|
|
35
44
|
};
|
|
36
45
|
const resolveContentModulePath = (module) => vite.normalizePath(module.startsWith("/") ? module : `${workspaceRoot}/${module}`);
|
|
@@ -167,13 +176,13 @@ function contentPlugin({ highlighter, markedOptions, shikiOptions, prismOptions
|
|
|
167
176
|
}
|
|
168
177
|
}
|
|
169
178
|
const fm = await import("front-matter");
|
|
170
|
-
const { body,
|
|
179
|
+
const { body, attributes } = (fm.default || fm)(readFileSync(id.split("?")[0], "utf8"));
|
|
171
180
|
const { getMarkedSetup } = await import("./content/marked/index.js");
|
|
172
181
|
const mdContent = await getMarkedSetup({
|
|
173
182
|
mangle: true,
|
|
174
183
|
...markedOptions || {}
|
|
175
184
|
}, markedHighlighter).getMarkedInstance().parse(body);
|
|
176
|
-
return `export default ${JSON.stringify(
|
|
185
|
+
return `export default ${JSON.stringify(mdContent)};\nexport const metadata = ${toModuleValue(attributes)};`;
|
|
177
186
|
}
|
|
178
187
|
},
|
|
179
188
|
...contentDiscoveryPlugins
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"content-plugin.js","names":[],"sources":["../../../src/lib/content-plugin.ts"],"sourcesContent":["import * as vite from 'vite';\nimport { readFileSync } from 'node:fs';\nimport { relative, resolve } from 'node:path';\nimport { globSync } from 'tinyglobby';\n\nimport type { WithShikiHighlighterOptions } from './content/shiki/options.js';\nimport type { MarkedContentHighlighter } from './content/marked/marked-content-highlighter.js';\nimport type { WithPrismHighlighterOptions } from './content/prism/options.js';\nimport type { WithMarkedOptions } from './content/marked/index.js';\nimport type { Options } from './options.js';\nimport { getBundleOptionsKey } from './utils/rolldown.js';\n\ninterface Content {\n code: string;\n attributes: string;\n}\n\nexport type ContentPluginOptions = {\n highlighter?: 'shiki' | 'prism';\n markedOptions?: WithMarkedOptions;\n shikiOptions?: WithShikiHighlighterOptions;\n prismOptions?: WithPrismHighlighterOptions;\n};\n\n/**\n * Content plugin that provides markdown and content file processing for Analog.\n *\n * IMPORTANT: This plugin uses tinyglobby for file discovery.\n * Key pitfall with { dot: true }:\n * - Returns relative paths from cwd (e.g., \"apps/blog-app/src/content/...\")\n * - These paths CANNOT be used directly in ES module imports\n * - Relative paths without ./ or ../ are treated as package names\n * - Must convert to absolute paths for imports to work correctly\n */\nexport function contentPlugin(\n {\n highlighter,\n markedOptions,\n shikiOptions,\n prismOptions,\n }: ContentPluginOptions = {},\n options?: Options,\n): vite.Plugin[] {\n const cache = new Map<string, Content>();\n // The content list placeholder can be transformed several times during serve.\n // Caching the discovered markdown paths keeps those repeat passes cheap.\n let contentFilesListCache: string[] | undefined;\n\n let markedHighlighter: MarkedContentHighlighter;\n const workspaceRoot = vite.normalizePath(\n options?.workspaceRoot ?? process.env['NX_WORKSPACE_ROOT'] ?? process.cwd(),\n );\n let config: vite.UserConfig;\n let root: string;\n // Keep discovery and invalidation aligned by deriving both from the same\n // normalized content roots. That way external content dirs participate in\n // cache busting exactly the same way they participate in glob discovery.\n // Initialized once in the `config` hook after `root` is resolved — all\n // inputs (`root`, `workspaceRoot`, `options`) are stable after that point.\n let contentRootDirs: string[];\n const normalizeContentDir = (dir: string) => {\n const normalized = vite.normalizePath(\n dir.startsWith('/')\n ? `${workspaceRoot}${dir}`\n : resolve(workspaceRoot, dir),\n );\n return normalized.endsWith('/') ? normalized.slice(0, -1) : normalized;\n };\n const initContentRootDirs = () => {\n contentRootDirs = [\n vite.normalizePath(`${root}/src/content`),\n ...(options?.additionalContentDirs || []).map(normalizeContentDir),\n ];\n };\n const discoverContentFilesList = () => {\n contentFilesListCache ??= globSync(\n contentRootDirs.map((dir) => `${dir}/**/*.md`),\n { dot: true },\n );\n\n return contentFilesListCache;\n };\n const resolveContentModulePath = (module: string) =>\n vite.normalizePath(\n module.startsWith('/') ? module : `${workspaceRoot}/${module}`,\n );\n const getContentModuleKey = (module: string) => {\n const absolutePath = resolveContentModulePath(module);\n const relativeToRoot = vite.normalizePath(relative(root, absolutePath));\n // `startsWith(root)` is not safe here because sibling directories such as\n // `/apps/my-app-tools` also start with `/apps/my-app`. A relative path only\n // represents in-app content when it stays within `root`.\n const isInApp =\n !relativeToRoot.startsWith('..') && !relativeToRoot.startsWith('/');\n\n // Both branches prepend `/` so generated keys are always absolute-\n // looking (`/src/content/...` for in-app, `/libs/shared/...` for\n // workspace-external). Downstream consumers like content-files-token\n // rely on the leading `/` for slug extraction regexes.\n return isInApp\n ? `/${relativeToRoot}`\n : `/${vite.normalizePath(relative(workspaceRoot, absolutePath))}`;\n };\n\n const contentDiscoveryPlugins: vite.Plugin[] = [\n {\n name: 'analog-content-glob-routes',\n config(_config) {\n config = _config;\n root = vite.normalizePath(\n resolve(workspaceRoot, config.root || '.') || '.',\n );\n initContentRootDirs();\n },\n // Vite 8 / Rolldown \"filtered transform\" — the `filter.code` string\n // tells the bundler to skip this handler entirely for modules whose\n // source does not contain the substring, avoiding unnecessary JS→Rust\n // round-trips. The inner `code.includes()` guard is kept for Vite 7\n // compat where filters are not evaluated by the bundler.\n transform: {\n filter: {\n code: 'ANALOG_CONTENT_FILE_LIST',\n },\n handler(code) {\n if (code.includes('ANALOG_CONTENT_FILE_LIST')) {\n const contentFilesList = discoverContentFilesList();\n\n const eagerImports: string[] = [];\n\n contentFilesList.forEach((module, index) => {\n // CRITICAL: tinyglobby returns relative paths like \"apps/blog-app/src/content/file.md\"\n // These MUST be converted to absolute paths for ES module imports\n // Otherwise Node.js treats \"apps\" as a package name and throws \"Cannot find package 'apps'\"\n const absolutePath = resolveContentModulePath(module);\n eagerImports.push(\n `import { default as analog_module_${index} } from \"${absolutePath}?analog-content-list=true\";`,\n );\n });\n\n // Match just the assignment (not the declaration) so the rewrite\n // works whether the source uses `const`, `let`, `var`, or\n // `export const` — including the post-Rolldown `var X = {};`\n // form — without destroying the declaration that keeps the\n // module binding exported.\n let result = code.replace(\n /ANALOG_CONTENT_FILE_LIST\\s*=\\s*\\{\\s*\\}/,\n `ANALOG_CONTENT_FILE_LIST = {${contentFilesList.map(\n (module, index) =>\n `\"${getContentModuleKey(module)}\": analog_module_${index}`,\n )}}`,\n );\n\n if (!code.includes('analog_module_')) {\n result = `${eagerImports.join('\\n')}\\n${result}`;\n }\n\n return {\n code: result,\n map: { mappings: '' },\n };\n }\n\n return;\n },\n },\n },\n {\n name: 'analogjs-invalidate-content-dirs',\n configureServer(server) {\n function invalidateContent(path: string) {\n const normalizedPath = vite.normalizePath(path);\n const isContentPath = contentRootDirs.some(\n (dir) =>\n normalizedPath === dir || normalizedPath.startsWith(`${dir}/`),\n );\n\n if (isContentPath) {\n // The file set only changes on add/remove because this watcher is\n // intentionally scoped to those events. Clear the list cache so the\n // next transform sees the updated directory contents.\n contentFilesListCache = undefined;\n server.moduleGraph.fileToModulesMap.forEach((mods) => {\n mods.forEach((mod) => {\n if (\n mod.id?.includes('analogjs') &&\n mod.id?.includes('content')\n ) {\n server.moduleGraph.invalidateModule(mod);\n\n mod.importers.forEach((imp) => {\n server.moduleGraph.invalidateModule(imp);\n });\n }\n });\n });\n\n server.ws.send('analog:debug-full-reload', {\n plugin: 'platform:content-plugin',\n reason: 'content-file-set-changed',\n path: normalizedPath,\n });\n server.ws.send({\n type: 'full-reload',\n });\n }\n }\n\n server.watcher.on('add', invalidateContent);\n server.watcher.on('unlink', invalidateContent);\n },\n },\n ];\n\n if (!highlighter) {\n return [\n {\n name: 'analogjs-external-content',\n config() {\n const bundleOptionsKey = getBundleOptionsKey();\n return {\n build: {\n [bundleOptionsKey]: {\n external: ['@analogjs/content'],\n },\n },\n };\n },\n },\n {\n name: 'analogjs-exclude-content-import',\n transform: {\n filter: {\n code: '@analogjs/content',\n },\n handler(code) {\n /**\n * Remove the package so it doesn't get\n * referenced when building for serverless\n * functions.\n */\n if (code.includes(`import('@analogjs/content')`)) {\n return {\n code: code.replace(\n `import('@analogjs/content')`,\n 'Promise.resolve({})',\n ),\n };\n }\n\n return;\n },\n },\n },\n ...contentDiscoveryPlugins,\n ];\n }\n\n return [\n {\n name: 'analogjs-content-frontmatter',\n // Filter by module ID so only `?analog-content-list=true` virtual\n // imports enter the handler. Returns `moduleSideEffects: false` so\n // Rolldown can tree-shake unused content list entries.\n transform: {\n filter: {\n id: /analog-content-list=true/,\n },\n async handler(code, id) {\n const cachedContent = cache.get(id);\n // There's no reason to run `readFileSync` and frontmatter parsing if the\n // `transform` hook is called with the same code. In such cases, we can simply\n // return the cached attributes, which is faster than repeatedly reading files\n // synchronously during the build process.\n if (cachedContent?.code === code) {\n return {\n code: `export default ${cachedContent.attributes}`,\n moduleSideEffects: false,\n };\n }\n\n const fm: any = await import('front-matter');\n // The `default` property will be available in CommonJS environment, for instance,\n // when running unit tests. It's safe to retrieve `default` first, since we still\n // fallback to the original implementation.\n const frontmatter = fm.default || fm;\n const fileContents = readFileSync(id.split('?')[0], 'utf8');\n const { attributes } = frontmatter(fileContents);\n const content = {\n code,\n attributes: JSON.stringify(attributes),\n };\n cache.set(id, content);\n\n return {\n code: `export default ${content.attributes}`,\n moduleSideEffects: false,\n };\n },\n },\n },\n {\n name: 'analogjs-content-file',\n enforce: 'post',\n async load(id) {\n if (!id.includes('analog-content-file=true')) {\n return;\n }\n\n if (!markedHighlighter) {\n if (highlighter === 'shiki') {\n const { getShikiHighlighter } =\n await import('./content/shiki/index.js');\n markedHighlighter = getShikiHighlighter(shikiOptions);\n } else {\n const { getPrismHighlighter } =\n await import('./content/prism/index.js');\n markedHighlighter = getPrismHighlighter();\n\n const langs = [\n 'bash',\n 'css',\n 'javascript',\n 'json',\n 'markup',\n 'typescript',\n ];\n\n if (\n Array.isArray(prismOptions?.additionalLangs) &&\n prismOptions?.additionalLangs?.length > 0\n ) {\n langs.push(...prismOptions.additionalLangs);\n }\n\n const loadLanguages = await import('prismjs/components/index.js');\n\n (\n loadLanguages as unknown as { default: (...args: any[]) => any }\n ).default(langs);\n }\n }\n\n const fm: any = await import('front-matter');\n // The `default` property will be available in CommonJS environment, for instance,\n // when running unit tests. It's safe to retrieve `default` first, since we still\n // fallback to the original implementation.\n const frontmatterFn = fm.default || fm;\n const fileContents = readFileSync(id.split('?')[0], 'utf8');\n const { body, frontmatter } = frontmatterFn(fileContents);\n\n // parse markdown and highlight\n const { getMarkedSetup } = await import('./content/marked/index.js');\n const markedSetupService = getMarkedSetup(\n { mangle: true, ...(markedOptions || {}) },\n markedHighlighter,\n );\n const mdContent = (await markedSetupService\n .getMarkedInstance()\n .parse(body)) as unknown as string;\n\n return `export default ${JSON.stringify(\n `---\\n${frontmatter}\\n---\\n\\n${mdContent}`,\n )}`;\n },\n },\n ...contentDiscoveryPlugins,\n ];\n}\n"],"mappings":";;;;;;;;;;;;;;;;AAkCA,SAAgB,cACd,EACE,aACA,eACA,cACA,iBACwB,CAAC,GAC3B,SACe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,GAExC,MAAM,KAAK,GAAG,aAAa,eAAe;MAK5C,CAAA,MAF4B,OAAO,+BAAA,CAIjC,QAAQ,KAAK;KACjB;IACF;IAEA,MAAM,KAAU,MAAM,OAAO;IAM7B,MAAM,EAAE,MAAM,iBAFQ,GAAG,WAAW,GAAA,CACf,aAAa,GAAG,MAAM,GAAG,CAAC,CAAC,IAAI,MACR,CAAY;IAGxD,MAAM,EAAE,mBAAmB,MAAM,OAAO;IAKxC,MAAM,YAAa,MAJQ,eACzB;KAAE,QAAQ;KAAM,GAAI,iBAAiB,CAAC;IAAG,GACzC,iBAEuB,CAAA,CACtB,kBAAkB,CAAC,CACnB,MAAM,IAAI;IAEb,OAAO,kBAAkB,KAAK,UAC5B,QAAQ,YAAY,WAAW,WACjC;GACF;EACF;EACA,GAAG;CACL;AACF"}
|
|
1
|
+
{"version":3,"file":"content-plugin.js","names":[],"sources":["../../../src/lib/content-plugin.ts"],"sourcesContent":["import * as vite from 'vite';\nimport { readFileSync } from 'node:fs';\nimport { relative, resolve } from 'node:path';\nimport { globSync } from 'tinyglobby';\n\nimport type { WithShikiHighlighterOptions } from './content/shiki/options.js';\nimport type { MarkedContentHighlighter } from './content/marked/marked-content-highlighter.js';\nimport type { WithPrismHighlighterOptions } from './content/prism/options.js';\nimport type { WithMarkedOptions } from './content/marked/index.js';\nimport type { Options } from './options.js';\nimport { getBundleOptionsKey } from './utils/rolldown.js';\n\ninterface Content {\n code: string;\n attributes: string;\n}\n\n// Serializes parsed frontmatter as a JS expression, keeping YAML timestamps as Dates.\nfunction toModuleValue(value: unknown): string {\n if (value instanceof Date) {\n return `new Date(${JSON.stringify(value.toISOString())})`;\n }\n if (Array.isArray(value)) {\n return `[${value.map(toModuleValue).join(',')}]`;\n }\n if (value && typeof value === 'object') {\n return `{${Object.entries(value)\n .map(([key, entry]) => `${JSON.stringify(key)}:${toModuleValue(entry)}`)\n .join(',')}}`;\n }\n return JSON.stringify(value) ?? 'undefined';\n}\n\nexport type ContentPluginOptions = {\n highlighter?: 'shiki' | 'prism';\n markedOptions?: WithMarkedOptions;\n shikiOptions?: WithShikiHighlighterOptions;\n prismOptions?: WithPrismHighlighterOptions;\n};\n\n/**\n * Content plugin that provides markdown and content file processing for Analog.\n *\n * IMPORTANT: This plugin uses tinyglobby for file discovery.\n * Key pitfall with { dot: true }:\n * - Returns relative paths from cwd (e.g., \"apps/blog-app/src/content/...\")\n * - These paths CANNOT be used directly in ES module imports\n * - Relative paths without ./ or ../ are treated as package names\n * - Must convert to absolute paths for imports to work correctly\n */\nexport function contentPlugin(\n {\n highlighter,\n markedOptions,\n shikiOptions,\n prismOptions,\n }: ContentPluginOptions = {},\n options?: Options,\n): vite.Plugin[] {\n const cache = new Map<string, Content>();\n // The content list placeholder can be transformed several times during serve.\n // Caching the discovered markdown paths keeps those repeat passes cheap.\n let contentFilesListCache: string[] | undefined;\n\n let markedHighlighter: MarkedContentHighlighter;\n const workspaceRoot = vite.normalizePath(\n options?.workspaceRoot ?? process.env['NX_WORKSPACE_ROOT'] ?? process.cwd(),\n );\n let config: vite.UserConfig;\n let root: string;\n // Keep discovery and invalidation aligned by deriving both from the same\n // normalized content roots. That way external content dirs participate in\n // cache busting exactly the same way they participate in glob discovery.\n // Initialized once in the `config` hook after `root` is resolved — all\n // inputs (`root`, `workspaceRoot`, `options`) are stable after that point.\n let contentRootDirs: string[];\n const normalizeContentDir = (dir: string) => {\n const normalized = vite.normalizePath(\n dir.startsWith('/')\n ? `${workspaceRoot}${dir}`\n : resolve(workspaceRoot, dir),\n );\n return normalized.endsWith('/') ? normalized.slice(0, -1) : normalized;\n };\n const initContentRootDirs = () => {\n contentRootDirs = [\n vite.normalizePath(`${root}/src/content`),\n ...(options?.additionalContentDirs || []).map(normalizeContentDir),\n ];\n };\n const discoverContentFilesList = () => {\n contentFilesListCache ??= globSync(\n contentRootDirs.map((dir) => `${dir}/**/*.md`),\n { dot: true, cwd: workspaceRoot },\n );\n\n return contentFilesListCache;\n };\n const resolveContentModulePath = (module: string) =>\n vite.normalizePath(\n module.startsWith('/') ? module : `${workspaceRoot}/${module}`,\n );\n const getContentModuleKey = (module: string) => {\n const absolutePath = resolveContentModulePath(module);\n const relativeToRoot = vite.normalizePath(relative(root, absolutePath));\n // `startsWith(root)` is not safe here because sibling directories such as\n // `/apps/my-app-tools` also start with `/apps/my-app`. A relative path only\n // represents in-app content when it stays within `root`.\n const isInApp =\n !relativeToRoot.startsWith('..') && !relativeToRoot.startsWith('/');\n\n // Both branches prepend `/` so generated keys are always absolute-\n // looking (`/src/content/...` for in-app, `/libs/shared/...` for\n // workspace-external). Downstream consumers like content-files-token\n // rely on the leading `/` for slug extraction regexes.\n return isInApp\n ? `/${relativeToRoot}`\n : `/${vite.normalizePath(relative(workspaceRoot, absolutePath))}`;\n };\n\n const contentDiscoveryPlugins: vite.Plugin[] = [\n {\n name: 'analog-content-glob-routes',\n config(_config) {\n config = _config;\n root = vite.normalizePath(\n resolve(workspaceRoot, config.root || '.') || '.',\n );\n initContentRootDirs();\n },\n // Vite 8 / Rolldown \"filtered transform\" — the `filter.code` string\n // tells the bundler to skip this handler entirely for modules whose\n // source does not contain the substring, avoiding unnecessary JS→Rust\n // round-trips. The inner `code.includes()` guard is kept for Vite 7\n // compat where filters are not evaluated by the bundler.\n transform: {\n filter: {\n code: 'ANALOG_CONTENT_FILE_LIST',\n },\n handler(code) {\n if (code.includes('ANALOG_CONTENT_FILE_LIST')) {\n const contentFilesList = discoverContentFilesList();\n\n const eagerImports: string[] = [];\n\n contentFilesList.forEach((module, index) => {\n // CRITICAL: tinyglobby returns relative paths like \"apps/blog-app/src/content/file.md\"\n // These MUST be converted to absolute paths for ES module imports\n // Otherwise Node.js treats \"apps\" as a package name and throws \"Cannot find package 'apps'\"\n const absolutePath = resolveContentModulePath(module);\n eagerImports.push(\n `import { default as analog_module_${index} } from \"${absolutePath}?analog-content-list=true\";`,\n );\n });\n\n // Match just the assignment (not the declaration) so the rewrite\n // works whether the source uses `const`, `let`, `var`, or\n // `export const` — including the post-Rolldown `var X = {};`\n // form — without destroying the declaration that keeps the\n // module binding exported.\n let result = code.replace(\n /ANALOG_CONTENT_FILE_LIST\\s*=\\s*\\{\\s*\\}/,\n `ANALOG_CONTENT_FILE_LIST = {${contentFilesList.map(\n (module, index) =>\n `\"${getContentModuleKey(module)}\": analog_module_${index}`,\n )}}`,\n );\n\n if (!code.includes('analog_module_')) {\n result = `${eagerImports.join('\\n')}\\n${result}`;\n }\n\n return {\n code: result,\n map: { mappings: '' },\n };\n }\n\n return;\n },\n },\n },\n {\n name: 'analogjs-invalidate-content-dirs',\n configureServer(server) {\n function invalidateContent(path: string) {\n const normalizedPath = vite.normalizePath(path);\n const isContentPath = contentRootDirs.some(\n (dir) =>\n normalizedPath === dir || normalizedPath.startsWith(`${dir}/`),\n );\n\n if (isContentPath) {\n // The file set only changes on add/remove because this watcher is\n // intentionally scoped to those events. Clear the list cache so the\n // next transform sees the updated directory contents.\n contentFilesListCache = undefined;\n server.moduleGraph.fileToModulesMap.forEach((mods) => {\n mods.forEach((mod) => {\n if (\n mod.id?.includes('analogjs') &&\n mod.id?.includes('content')\n ) {\n server.moduleGraph.invalidateModule(mod);\n\n mod.importers.forEach((imp) => {\n server.moduleGraph.invalidateModule(imp);\n });\n }\n });\n });\n\n server.ws.send('analog:debug-full-reload', {\n plugin: 'platform:content-plugin',\n reason: 'content-file-set-changed',\n path: normalizedPath,\n });\n server.ws.send({\n type: 'full-reload',\n });\n }\n }\n\n server.watcher.on('add', invalidateContent);\n server.watcher.on('unlink', invalidateContent);\n },\n },\n ];\n\n if (!highlighter) {\n return [\n {\n name: 'analogjs-external-content',\n config() {\n const bundleOptionsKey = getBundleOptionsKey();\n return {\n build: {\n [bundleOptionsKey]: {\n external: ['@analogjs/content'],\n },\n },\n };\n },\n },\n {\n name: 'analogjs-exclude-content-import',\n transform: {\n filter: {\n code: '@analogjs/content',\n },\n handler(code) {\n /**\n * Remove the package so it doesn't get\n * referenced when building for serverless\n * functions.\n */\n if (code.includes(`import('@analogjs/content')`)) {\n return {\n code: code.replace(\n `import('@analogjs/content')`,\n 'Promise.resolve({})',\n ),\n };\n }\n\n return;\n },\n },\n },\n ...contentDiscoveryPlugins,\n ];\n }\n\n return [\n {\n name: 'analogjs-content-frontmatter',\n // Filter by module ID so only `?analog-content-list=true` virtual\n // imports enter the handler. Returns `moduleSideEffects: false` so\n // Rolldown can tree-shake unused content list entries.\n transform: {\n filter: {\n id: /analog-content-list=true/,\n },\n async handler(code, id) {\n const cachedContent = cache.get(id);\n // There's no reason to run `readFileSync` and frontmatter parsing if the\n // `transform` hook is called with the same code. In such cases, we can simply\n // return the cached attributes, which is faster than repeatedly reading files\n // synchronously during the build process.\n if (cachedContent?.code === code) {\n return {\n code: `export default ${cachedContent.attributes}`,\n moduleSideEffects: false,\n };\n }\n\n const fm: any = await import('front-matter');\n // The `default` property will be available in CommonJS environment, for instance,\n // when running unit tests. It's safe to retrieve `default` first, since we still\n // fallback to the original implementation.\n const frontmatter = fm.default || fm;\n const fileContents = readFileSync(id.split('?')[0], 'utf8');\n const { attributes } = frontmatter(fileContents);\n const content = {\n code,\n attributes: JSON.stringify(attributes),\n };\n cache.set(id, content);\n\n return {\n code: `export default ${content.attributes}`,\n moduleSideEffects: false,\n };\n },\n },\n },\n {\n name: 'analogjs-content-file',\n enforce: 'post',\n async load(id) {\n if (!id.includes('analog-content-file=true')) {\n return;\n }\n\n if (!markedHighlighter) {\n if (highlighter === 'shiki') {\n const { getShikiHighlighter } =\n await import('./content/shiki/index.js');\n markedHighlighter = getShikiHighlighter(shikiOptions);\n } else {\n const { getPrismHighlighter } =\n await import('./content/prism/index.js');\n markedHighlighter = getPrismHighlighter();\n\n const langs = [\n 'bash',\n 'css',\n 'javascript',\n 'json',\n 'markup',\n 'typescript',\n ];\n\n if (\n Array.isArray(prismOptions?.additionalLangs) &&\n prismOptions?.additionalLangs?.length > 0\n ) {\n langs.push(...prismOptions.additionalLangs);\n }\n\n const loadLanguages = await import('prismjs/components/index.js');\n\n (\n loadLanguages as unknown as { default: (...args: any[]) => any }\n ).default(langs);\n }\n }\n\n const fm: any = await import('front-matter');\n // The `default` property will be available in CommonJS environment, for instance,\n // when running unit tests. It's safe to retrieve `default` first, since we still\n // fallback to the original implementation.\n const frontmatterFn = fm.default || fm;\n const fileContents = readFileSync(id.split('?')[0], 'utf8');\n const { body, attributes } = frontmatterFn(fileContents);\n\n // parse markdown and highlight\n const { getMarkedSetup } = await import('./content/marked/index.js');\n const markedSetupService = getMarkedSetup(\n { mangle: true, ...(markedOptions || {}) },\n markedHighlighter,\n );\n const mdContent = (await markedSetupService\n .getMarkedInstance()\n .parse(body)) as unknown as string;\n\n return `export default ${JSON.stringify(mdContent)};\\nexport const metadata = ${toModuleValue(attributes)};`;\n },\n },\n ...contentDiscoveryPlugins,\n ];\n}\n"],"mappings":";;;;;;AAkBA,SAAS,cAAc,OAAwB;CAC7C,IAAI,iBAAiB,MACnB,OAAO,YAAY,KAAK,UAAU,MAAM,YAAY,CAAC,EAAE;CAEzD,IAAI,MAAM,QAAQ,KAAK,GACrB,OAAO,IAAI,MAAM,IAAI,aAAa,CAAC,CAAC,KAAK,GAAG,EAAE;CAEhD,IAAI,SAAS,OAAO,UAAU,UAC5B,OAAO,IAAI,OAAO,QAAQ,KAAK,CAAC,CAC7B,KAAK,CAAC,KAAK,WAAW,GAAG,KAAK,UAAU,GAAG,EAAE,GAAG,cAAc,KAAK,GAAG,CAAC,CACvE,KAAK,GAAG,EAAE;CAEf,OAAO,KAAK,UAAU,KAAK,KAAK;AAClC;;;;;;;;;;;AAmBA,SAAgB,cACd,EACE,aACA,eACA,cACA,iBACwB,CAAC,GAC3B,SACe;CACf,MAAM,wBAAQ,IAAI,IAAqB;CAGvC,IAAI;CAEJ,IAAI;CACJ,MAAM,gBAAgB,KAAK,cACzB,SAAS,iBAAiB,QAAQ,IAAI,wBAAwB,QAAQ,IAAI,CAC5E;CACA,IAAI;CACJ,IAAI;CAMJ,IAAI;CACJ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,GAAA,CACf,aAAa,GAAG,MAAM,GAAG,CAAC,CAAC,IAAI,MACT,CAAY;IAGvD,MAAM,EAAE,mBAAmB,MAAM,OAAO;IAKxC,MAAM,YAAa,MAJQ,eACzB;KAAE,QAAQ;KAAM,GAAI,iBAAiB,CAAC;IAAG,GACzC,iBAEuB,CAAA,CACtB,kBAAkB,CAAC,CACnB,MAAM,IAAI;IAEb,OAAO,kBAAkB,KAAK,UAAU,SAAS,EAAE,6BAA6B,cAAc,UAAU,EAAE;GAC5G;EACF;EACA,GAAG;CACL;AACF"}
|
package/src/lib/deps-plugin.d.ts
CHANGED
package/src/lib/deps-plugin.js
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import { debugPlatform } from "./utils/debug.js";
|
|
2
2
|
import { getJsTransformConfigKey, isRolldown } from "./utils/rolldown.js";
|
|
3
3
|
import { angularLinkerPlugin } from "./nitro/angular-linker-plugin.js";
|
|
4
|
+
import { dirname, resolve } from "node:path";
|
|
5
|
+
import { normalizePath } from "vite";
|
|
4
6
|
import { crawlFrameworkPkgs } from "vitefu";
|
|
5
7
|
//#region packages/platform/src/lib/deps-plugin.ts
|
|
6
8
|
var ANGULAR_LINKED_SSR_DEPS = [
|
|
@@ -13,14 +15,16 @@ function depsPlugin(options) {
|
|
|
13
15
|
const workspaceRoot = options?.workspaceRoot ?? process.env["NX_WORKSPACE_ROOT"] ?? process.cwd();
|
|
14
16
|
return [{
|
|
15
17
|
name: "analogjs-deps-plugin",
|
|
16
|
-
config() {
|
|
17
|
-
const
|
|
18
|
+
config(userConfig) {
|
|
19
|
+
const jsTransformKey = getJsTransformConfigKey();
|
|
20
|
+
const userTransform = userConfig?.[jsTransformKey] !== void 0 || jsTransformKey === "oxc" && !!userConfig?.esbuild;
|
|
21
|
+
const transform = options?.server ? { include: [`${normalizePath(resolve(userConfig?.root ?? process.cwd(), dirname(options.server.entry)))}/**/*.ts`] } : { exclude: ["**/*.ts", "**/*.js"] };
|
|
18
22
|
debugPlatform("deps transform config", {
|
|
19
|
-
jsTransformKey
|
|
20
|
-
|
|
23
|
+
jsTransformKey,
|
|
24
|
+
transform: userTransform ? "user" : transform
|
|
21
25
|
});
|
|
22
26
|
return {
|
|
23
|
-
[
|
|
27
|
+
...userTransform ? {} : { [jsTransformKey]: transform },
|
|
24
28
|
ssr: {
|
|
25
29
|
noExternal: [
|
|
26
30
|
"@analogjs/**",
|
|
@@ -30,7 +34,7 @@ function depsPlugin(options) {
|
|
|
30
34
|
"rxfire",
|
|
31
35
|
"@ng-web-apis/**",
|
|
32
36
|
"@taiga-ui/**",
|
|
33
|
-
|
|
37
|
+
/^@tanstack\/angular-/
|
|
34
38
|
],
|
|
35
39
|
optimizeDeps: {
|
|
36
40
|
include: [
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"deps-plugin.js","names":[],"sources":["../../../src/lib/deps-plugin.ts"],"sourcesContent":["import
|
|
1
|
+
{"version":3,"file":"deps-plugin.js","names":[],"sources":["../../../src/lib/deps-plugin.ts"],"sourcesContent":["import { dirname, resolve } from 'node:path';\nimport { normalizePath, type Plugin } from 'vite';\nimport { crawlFrameworkPkgs } from 'vitefu';\n\nimport { angularLinkerPlugin } from './nitro/angular-linker-plugin.js';\nimport { Options } from './options.js';\nimport { debugPlatform } from './utils/debug.js';\nimport { getJsTransformConfigKey, isRolldown } from './utils/rolldown.js';\n\nconst ANGULAR_LINKED_SSR_DEPS = [\n '@angular/compiler',\n '@angular/core',\n '@angular/platform-browser',\n '@angular/platform-server',\n];\n\nexport function depsPlugin(options?: Options): Plugin[] {\n const workspaceRoot =\n options?.workspaceRoot ?? process.env['NX_WORKSPACE_ROOT'] ?? process.cwd();\n\n return [\n {\n name: 'analogjs-deps-plugin',\n config(userConfig) {\n // Skip Vite's built-in ts/js transform so `@analogjs/vite-plugin-angular`\n // (when the user includes it) owns Angular file compilation. Users who\n // run an alternative compiler, or compile non-Angular server code with\n // Vite, set the transform in their own Vite config. Theirs is kept\n // as-is: merging would concatenate these excludes into it, and an\n // exclude wins over any include they set.\n const jsTransformKey = getJsTransformConfigKey();\n // Vite 8 still converts a user's `esbuild` object to `oxc` (unless\n // `oxc` is set), but `esbuild: false` no longer has any effect there.\n const userTransform =\n userConfig?.[jsTransformKey] !== undefined ||\n (jsTransformKey === 'oxc' && !!userConfig?.esbuild);\n // With `server`, Vite compiles the server entry's directory instead,\n // which the Angular compiler leaves alone.\n const transform = options?.server\n ? {\n include: [\n `${normalizePath(\n resolve(\n userConfig?.root ?? process.cwd(),\n dirname(options.server.entry),\n ),\n )}/**/*.ts`,\n ],\n }\n : { exclude: ['**/*.ts', '**/*.js'] };\n debugPlatform('deps transform config', {\n jsTransformKey,\n transform: userTransform ? 'user' : transform,\n });\n\n return {\n ...(userTransform ? {} : { [jsTransformKey]: transform }),\n ssr: {\n noExternal: [\n '@analogjs/**',\n 'es-toolkit',\n 'firebase/**',\n 'firebase-admin/**',\n 'rxfire',\n '@ng-web-apis/**',\n '@taiga-ui/**',\n /^@tanstack\\/angular-/,\n ],\n // The server pre-bundle is resolved separately from the client\n // one, so a secondary entry point left out of it loads its own\n // copy of `@angular/core`. `inject()` then runs against a runtime\n // with no active injection context and SSR fails with NG0203.\n // With Rolldown, the rest of Angular is pre-bundled too and the\n // partial-compilation packages are linked, so the server needs no JIT.\n optimizeDeps: {\n include: [\n ...(isRolldown() ? ANGULAR_LINKED_SSR_DEPS : []),\n '@angular/common',\n '@angular/common/http',\n '@angular/core/rxjs-interop',\n ],\n ...(isRolldown()\n ? { rolldownOptions: { plugins: [angularLinkerPlugin()] } }\n : {}),\n },\n },\n optimizeDeps: {\n include: [\n '@angular/common',\n '@angular/common/http',\n '@angular/core/rxjs-interop',\n 'front-matter',\n ],\n exclude: [\n '@angular/platform-server',\n '@analogjs/content',\n '@analogjs/router',\n '@nx/angular',\n '@nx/vite',\n '@nx/devkit',\n '@nx/js',\n '@nx/devkit',\n '@nx/cypress',\n '@nx/jest',\n '@nx/js',\n '@nx/eslint',\n '@nx/webpack',\n '@nx/web',\n '@nx/workspace',\n '@nx/eslint',\n '@nx/module-federation',\n '@nx/rspack',\n 'webpack',\n 'fsevents',\n 'nx',\n ],\n },\n };\n },\n },\n {\n name: 'analogjs-auto-discover-deps',\n async config(config, { command }) {\n const pkgConfig = await crawlFrameworkPkgs({\n root: workspaceRoot,\n isBuild: command === 'build',\n viteUserConfig: config,\n isSemiFrameworkPkgByJson(pkgJson) {\n return pkgJson['module'] && pkgJson['module'].includes('fesm');\n },\n });\n return pkgConfig;\n },\n },\n ];\n}\n"],"mappings":";;;;;;;AASA,IAAM,0BAA0B;CAC9B;CACA;CACA;CACA;AACF;AAEA,SAAgB,WAAW,SAA6B;CACtD,MAAM,gBACJ,SAAS,iBAAiB,QAAQ,IAAI,wBAAwB,QAAQ,IAAI;CAE5E,OAAO,CACL;EACE,MAAM;EACN,OAAO,YAAY;GAOjB,MAAM,iBAAiB,wBAAwB;GAG/C,MAAM,gBACJ,aAAa,oBAAoB,KAAA,KAChC,mBAAmB,SAAS,CAAC,CAAC,YAAY;GAG7C,MAAM,YAAY,SAAS,SACvB,EACE,SAAS,CACP,GAAG,cACD,QACE,YAAY,QAAQ,QAAQ,IAAI,GAChC,QAAQ,QAAQ,OAAO,KAAK,CAC9B,CACF,EAAE,SACJ,EACF,IACA,EAAE,SAAS,CAAC,WAAW,SAAS,EAAE;GACtC,cAAc,yBAAyB;IACrC;IACA,WAAW,gBAAgB,SAAS;GACtC,CAAC;GAED,OAAO;IACL,GAAI,gBAAgB,CAAC,IAAI,GAAG,iBAAiB,UAAU;IACvD,KAAK;KACH,YAAY;MACV;MACA;MACA;MACA;MACA;MACA;MACA;MACA;KACF;KAOA,cAAc;MACZ,SAAS;OACP,GAAI,WAAW,IAAI,0BAA0B,CAAC;OAC9C;OACA;OACA;MACF;MACA,GAAI,WAAW,IACX,EAAE,iBAAiB,EAAE,SAAS,CAAC,oBAAoB,CAAC,EAAE,EAAE,IACxD,CAAC;KACP;IACF;IACA,cAAc;KACZ,SAAS;MACP;MACA;MACA;MACA;KACF;KACA,SAAS;MACP;MACA;MACA;MACA;MACA;MACA;MACA;MACA;MACA;MACA;MACA;MACA;MACA;MACA;MACA;MACA;MACA;MACA;MACA;MACA;MACA;KACF;IACF;GACF;EACF;CACF,GACA;EACE,MAAM;EACN,MAAM,OAAO,QAAQ,EAAE,WAAW;GAShC,OAAO,MARiB,mBAAmB;IACzC,MAAM;IACN,SAAS,YAAY;IACrB,gBAAgB;IAChB,yBAAyB,SAAS;KAChC,OAAO,QAAQ,aAAa,QAAQ,SAAS,CAAC,SAAS,MAAM;IAC/D;GACF,CAAC;EAEH;CACF,CACF;AACF"}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
type GetPageEndpointsArgs = {
|
|
2
|
+
workspaceRoot: string;
|
|
3
|
+
sourceRoot: string;
|
|
4
|
+
rootDir: string;
|
|
5
|
+
additionalPagesDirs?: string[];
|
|
6
|
+
};
|
|
7
|
+
export type PageEndpoint = {
|
|
8
|
+
/** Absolute path to the page's `.server.ts` file. */
|
|
9
|
+
file: string;
|
|
10
|
+
/** Route relative to the endpoint root, e.g. `/pages/users/:id`. */
|
|
11
|
+
route: string;
|
|
12
|
+
};
|
|
13
|
+
/**
|
|
14
|
+
* Discovers server-side page endpoints: every `.server.ts` file under
|
|
15
|
+
* `app/pages/**` and any additional pages directories, mapped to a route
|
|
16
|
+
* pattern. Servers mount them under their own prefix.
|
|
17
|
+
*
|
|
18
|
+
* Route transformation examples:
|
|
19
|
+
* - index.server.ts → /pages/index
|
|
20
|
+
* - users/[id].server.ts → /pages/users/:id
|
|
21
|
+
* - products/[...slug].server.ts → /pages/products/**:slug
|
|
22
|
+
* - (auth)/login.server.ts → /pages/-auth-/login
|
|
23
|
+
*/
|
|
24
|
+
export declare function getPageEndpoints({ workspaceRoot, sourceRoot, rootDir, additionalPagesDirs }: GetPageEndpointsArgs): PageEndpoint[];
|
|
25
|
+
export {};
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { resolve } from "node:path";
|
|
2
|
+
import { normalizePath } from "vite";
|
|
3
|
+
import { globSync } from "tinyglobby";
|
|
4
|
+
//#region packages/platform/src/lib/get-page-endpoints.ts
|
|
5
|
+
/**
|
|
6
|
+
* Discovers server-side page endpoints: every `.server.ts` file under
|
|
7
|
+
* `app/pages/**` and any additional pages directories, mapped to a route
|
|
8
|
+
* pattern. Servers mount them under their own prefix.
|
|
9
|
+
*
|
|
10
|
+
* Route transformation examples:
|
|
11
|
+
* - index.server.ts → /pages/index
|
|
12
|
+
* - users/[id].server.ts → /pages/users/:id
|
|
13
|
+
* - products/[...slug].server.ts → /pages/products/**:slug
|
|
14
|
+
* - (auth)/login.server.ts → /pages/-auth-/login
|
|
15
|
+
*/
|
|
16
|
+
function getPageEndpoints({ workspaceRoot, sourceRoot, rootDir, additionalPagesDirs }) {
|
|
17
|
+
const root = normalizePath(resolve(workspaceRoot, rootDir));
|
|
18
|
+
return globSync([`${root}/${sourceRoot}/app/pages/**/*.server.ts`, ...(additionalPagesDirs || []).map((dir) => `${workspaceRoot}${dir}/**/*.server.ts`)], {
|
|
19
|
+
dot: true,
|
|
20
|
+
absolute: true
|
|
21
|
+
}).map((file) => ({
|
|
22
|
+
file,
|
|
23
|
+
route: normalizePath(file).replace(/^(.*?)\/pages/, "/pages").replace(/\.server\.ts$/, "").replace(/\[\.{3}(.+)\]/g, "**:$1").replace(/\[\.{3}(\w+)\]/g, "**:$1").replace(/\/\(([^/]+)\)/g, "/-$1-").replace(/\[(\w+)\]/g, ":$1").replace(/\./g, "/")
|
|
24
|
+
}));
|
|
25
|
+
}
|
|
26
|
+
//#endregion
|
|
27
|
+
export { getPageEndpoints };
|
|
28
|
+
|
|
29
|
+
//# sourceMappingURL=get-page-endpoints.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"get-page-endpoints.js","names":[],"sources":["../../../src/lib/get-page-endpoints.ts"],"sourcesContent":["import { resolve } from 'node:path';\nimport { globSync } from 'tinyglobby';\nimport { normalizePath } from 'vite';\n\ntype GetPageEndpointsArgs = {\n workspaceRoot: string;\n sourceRoot: string;\n rootDir: string;\n additionalPagesDirs?: string[];\n};\n\nexport type PageEndpoint = {\n /** Absolute path to the page's `.server.ts` file. */\n file: string;\n /** Route relative to the endpoint root, e.g. `/pages/users/:id`. */\n route: string;\n};\n\n/**\n * Discovers server-side page endpoints: every `.server.ts` file under\n * `app/pages/**` and any additional pages directories, mapped to a route\n * pattern. Servers mount them under their own prefix.\n *\n * Route transformation examples:\n * - index.server.ts → /pages/index\n * - users/[id].server.ts → /pages/users/:id\n * - products/[...slug].server.ts → /pages/products/**:slug\n * - (auth)/login.server.ts → /pages/-auth-/login\n */\nexport function getPageEndpoints({\n workspaceRoot,\n sourceRoot,\n rootDir,\n additionalPagesDirs,\n}: GetPageEndpointsArgs): PageEndpoint[] {\n const root = normalizePath(resolve(workspaceRoot, rootDir));\n\n const endpointFiles: string[] = globSync(\n [\n `${root}/${sourceRoot}/app/pages/**/*.server.ts`,\n ...(additionalPagesDirs || []).map(\n (dir) => `${workspaceRoot}${dir}/**/*.server.ts`,\n ),\n ],\n { dot: true, absolute: true },\n );\n\n return endpointFiles.map((file) => ({\n file,\n route: normalizePath(file)\n .replace(/^(.*?)\\/pages/, '/pages')\n .replace(/\\.server\\.ts$/, '')\n .replace(/\\[\\.{3}(.+)\\]/g, '**:$1')\n .replace(/\\[\\.{3}(\\w+)\\]/g, '**:$1')\n // Strip Angular Router group syntax `(group)` from any segment, not\n // just trailing ones. Routes like `(auth)/login.server.ts` need to\n // become `/-auth-/login`, otherwise the literal parens leak through\n // and the endpoint is mounted under an invalid path.\n .replace(/\\/\\(([^/]+)\\)/g, '/-$1-')\n .replace(/\\[(\\w+)\\]/g, ':$1')\n .replace(/\\./g, '/'),\n }));\n}\n"],"mappings":";;;;;;;;;;;;;;;AA6BA,SAAgB,iBAAiB,EAC/B,eACA,YACA,SACA,uBACuC;CACvC,MAAM,OAAO,cAAc,QAAQ,eAAe,OAAO,CAAC;CAY1D,OAVgC,SAC9B,CACE,GAAG,KAAK,GAAG,WAAW,4BACtB,IAAI,uBAAuB,CAAC,EAAA,CAAG,KAC5B,QAAQ,GAAG,gBAAgB,IAAI,gBAClC,CACF,GACA;EAAE,KAAK;EAAM,UAAU;CAAK,CAGvB,CAAA,CAAc,KAAK,UAAU;EAClC;EACA,OAAO,cAAc,IAAI,CAAC,CACvB,QAAQ,iBAAiB,QAAQ,CAAC,CAClC,QAAQ,iBAAiB,EAAE,CAAC,CAC5B,QAAQ,kBAAkB,OAAO,CAAC,CAClC,QAAQ,mBAAmB,OAAO,CAAC,CAKnC,QAAQ,kBAAkB,OAAO,CAAC,CAClC,QAAQ,cAAc,KAAK,CAAC,CAC5B,QAAQ,OAAO,GAAG;CACvB,EAAE;AACJ"}
|
|
@@ -1,22 +1,7 @@
|
|
|
1
1
|
import type { NitroEventHandler } from "nitro/types";
|
|
2
|
-
|
|
3
|
-
workspaceRoot: string;
|
|
4
|
-
sourceRoot: string;
|
|
5
|
-
rootDir: string;
|
|
6
|
-
additionalPagesDirs?: string[];
|
|
7
|
-
};
|
|
2
|
+
import { getPageEndpoints } from "../get-page-endpoints.js";
|
|
8
3
|
/**
|
|
9
|
-
*
|
|
10
|
-
*
|
|
11
|
-
* Discovers all `.server.ts` files under `app/pages/**` and any additional
|
|
12
|
-
* pages directories, then maps each file to a Nitro route pattern under
|
|
13
|
-
* `/api/_analog/pages/...`.
|
|
14
|
-
*
|
|
15
|
-
* Route transformation examples:
|
|
16
|
-
* - index.server.ts → /api/_analog/pages/index
|
|
17
|
-
* - users/[id].server.ts → /api/_analog/pages/users/:id
|
|
18
|
-
* - products/[...slug].server.ts → /api/_analog/pages/products/**:slug
|
|
19
|
-
* - (auth)/login.server.ts → /api/_analog/pages/-auth-/login
|
|
4
|
+
* Nitro event handlers for server-side page routes: each discovered page
|
|
5
|
+
* endpoint, mounted under `/api/_analog`.
|
|
20
6
|
*/
|
|
21
|
-
export declare function getPageHandlers(
|
|
22
|
-
export {};
|
|
7
|
+
export declare function getPageHandlers(args: Parameters<typeof getPageEndpoints>[0]): NitroEventHandler[];
|
|
@@ -1,32 +1,15 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { normalizePath } from "vite";
|
|
3
|
-
import { globSync } from "tinyglobby";
|
|
1
|
+
import { getPageEndpoints } from "../get-page-endpoints.js";
|
|
4
2
|
//#region packages/platform/src/lib/nitro/get-page-handlers.ts
|
|
5
3
|
/**
|
|
6
|
-
*
|
|
7
|
-
*
|
|
8
|
-
* Discovers all `.server.ts` files under `app/pages/**` and any additional
|
|
9
|
-
* pages directories, then maps each file to a Nitro route pattern under
|
|
10
|
-
* `/api/_analog/pages/...`.
|
|
11
|
-
*
|
|
12
|
-
* Route transformation examples:
|
|
13
|
-
* - index.server.ts → /api/_analog/pages/index
|
|
14
|
-
* - users/[id].server.ts → /api/_analog/pages/users/:id
|
|
15
|
-
* - products/[...slug].server.ts → /api/_analog/pages/products/**:slug
|
|
16
|
-
* - (auth)/login.server.ts → /api/_analog/pages/-auth-/login
|
|
4
|
+
* Nitro event handlers for server-side page routes: each discovered page
|
|
5
|
+
* endpoint, mounted under `/api/_analog`.
|
|
17
6
|
*/
|
|
18
|
-
function getPageHandlers(
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
})
|
|
24
|
-
return {
|
|
25
|
-
handler: endpointFile,
|
|
26
|
-
route: `/api/_analog${normalizePath(endpointFile).replace(/^(.*?)\/pages/, "/pages").replace(/\.server\.ts$/, "").replace(/\[\.{3}(.+)\]/g, "**:$1").replace(/\[\.{3}(\w+)\]/g, "**:$1").replace(/\/\(([^/]+)\)/g, "/-$1-").replace(/\[(\w+)\]/g, ":$1").replace(/\./g, "/")}`,
|
|
27
|
-
lazy: true
|
|
28
|
-
};
|
|
29
|
-
});
|
|
7
|
+
function getPageHandlers(args) {
|
|
8
|
+
return getPageEndpoints(args).map(({ file, route }) => ({
|
|
9
|
+
handler: file,
|
|
10
|
+
route: `/api/_analog${route}`,
|
|
11
|
+
lazy: true
|
|
12
|
+
}));
|
|
30
13
|
}
|
|
31
14
|
//#endregion
|
|
32
15
|
export { getPageHandlers };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"get-page-handlers.js","names":[],"sources":["../../../../src/lib/nitro/get-page-handlers.ts"],"sourcesContent":["import
|
|
1
|
+
{"version":3,"file":"get-page-handlers.js","names":[],"sources":["../../../../src/lib/nitro/get-page-handlers.ts"],"sourcesContent":["import type { NitroEventHandler } from 'nitro/types';\n\nimport { getPageEndpoints } from '../get-page-endpoints.js';\n\n/**\n * Nitro event handlers for server-side page routes: each discovered page\n * endpoint, mounted under `/api/_analog`.\n */\nexport function getPageHandlers(\n args: Parameters<typeof getPageEndpoints>[0],\n): NitroEventHandler[] {\n return getPageEndpoints(args).map(({ file, route }) => ({\n handler: file,\n route: `/api/_analog${route}`,\n lazy: true,\n }));\n}\n"],"mappings":";;;;;;AAQA,SAAgB,gBACd,MACqB;CACrB,OAAO,iBAAiB,IAAI,CAAC,CAAC,KAAK,EAAE,MAAM,aAAa;EACtD,SAAS;EACT,OAAO,eAAe;EACtB,MAAM;CACR,EAAE;AACJ"}
|
|
@@ -10,12 +10,5 @@
|
|
|
10
10
|
"schema": "./src/builders/vite/schema.json",
|
|
11
11
|
"description": "Build with Vite."
|
|
12
12
|
}
|
|
13
|
-
},
|
|
14
|
-
"executors": {
|
|
15
|
-
"vite-dev-server": {
|
|
16
|
-
"implementation": "./src/executors/vite-dev-server/vite-dev-server.impl",
|
|
17
|
-
"schema": "./src/executors/vite-dev-server/schema.json",
|
|
18
|
-
"description": "Vite dev server."
|
|
19
|
-
}
|
|
20
13
|
}
|
|
21
14
|
}
|
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import { convertNxGenerator } from "@nx/devkit";
|
|
2
|
+
import generator from "./generator";
|
|
2
3
|
/**
|
|
3
4
|
* Angular CLI schematic wrapper for the Analog application generator.
|
|
4
5
|
* Referenced by `generators.json#schematics.application.factory` so that
|
|
5
6
|
* `ng generate @analogjs/platform:application` resolves through the
|
|
6
7
|
* Angular schematics engine (which uses named exports, not default).
|
|
7
8
|
*/
|
|
8
|
-
export declare
|
|
9
|
+
export declare function applicationSchematic(options: Parameters<typeof generator>[1]): ReturnType<ReturnType<typeof convertNxGenerator>>;
|
|
9
10
|
export default applicationSchematic;
|
|
@@ -3,6 +3,7 @@ Object.defineProperties(exports, {
|
|
|
3
3
|
[Symbol.toStringTag]: { value: "Module" }
|
|
4
4
|
});
|
|
5
5
|
const require_src_generators_app_generator = require("./generator.js");
|
|
6
|
+
let _nx_devkit = require("@nx/devkit");
|
|
6
7
|
//#region packages/nx-plugin/src/generators/app/compat.ts
|
|
7
8
|
/**
|
|
8
9
|
* Angular CLI schematic wrapper for the Analog application generator.
|
|
@@ -10,7 +11,9 @@ const require_src_generators_app_generator = require("./generator.js");
|
|
|
10
11
|
* `ng generate @analogjs/platform:application` resolves through the
|
|
11
12
|
* Angular schematics engine (which uses named exports, not default).
|
|
12
13
|
*/
|
|
13
|
-
|
|
14
|
+
function applicationSchematic(options) {
|
|
15
|
+
return (0, _nx_devkit.convertNxGenerator)(require_src_generators_app_generator)(options);
|
|
16
|
+
}
|
|
14
17
|
//#endregion
|
|
15
18
|
exports.applicationSchematic = applicationSchematic;
|
|
16
19
|
exports.default = applicationSchematic;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"compat.js","names":[],"sources":["../../../../../../../../nx-plugin/src/generators/app/compat.ts"],"sourcesContent":["import { convertNxGenerator } from '@nx/devkit';\nimport generator from './generator';\n\n/**\n * Angular CLI schematic wrapper for the Analog application generator.\n * Referenced by `generators.json#schematics.application.factory` so that\n * `ng generate @analogjs/platform:application` resolves through the\n * Angular schematics engine (which uses named exports, not default).\n */\nexport
|
|
1
|
+
{"version":3,"file":"compat.js","names":[],"sources":["../../../../../../../../nx-plugin/src/generators/app/compat.ts"],"sourcesContent":["import { convertNxGenerator } from '@nx/devkit';\nimport generator from './generator';\n\n/**\n * Angular CLI schematic wrapper for the Analog application generator.\n * Referenced by `generators.json#schematics.application.factory` so that\n * `ng generate @analogjs/platform:application` resolves through the\n * Angular schematics engine (which uses named exports, not default).\n */\nexport function applicationSchematic(\n options: Parameters<typeof generator>[1],\n): ReturnType<ReturnType<typeof convertNxGenerator>> {\n return convertNxGenerator(generator)(options);\n}\nexport default applicationSchematic;\n"],"mappings":";;;;;;;;;;;;;AASA,SAAgB,qBACd,SACmD;CACnD,QAAA,GAAO,WAAA,mBAAA,CAAmB,oCAAS,CAAC,CAAC,OAAO;AAC9C"}
|
|
@@ -2,6 +2,7 @@ const require_version_utils = require("../../utils/version-utils.js");
|
|
|
2
2
|
const require_add_home_page = require("./lib/add-home-page.js");
|
|
3
3
|
const require_minimum_supported_versions = require("./versions/minimum-supported-versions.js");
|
|
4
4
|
const require_add_angular_app = require("./lib/add-angular-app.js");
|
|
5
|
+
const require_versions = require("../../utils/versions/versions.js");
|
|
5
6
|
const require_src_generators_init_generator = require("../init/generator.js");
|
|
6
7
|
const require_add_files = require("./lib/add-files.js");
|
|
7
8
|
const require_add_agent_context = require("./lib/add-agent-context.js");
|
|
@@ -41,7 +42,10 @@ function normalizeOptions(tree, options) {
|
|
|
41
42
|
async function appGenerator(tree, options) {
|
|
42
43
|
const nxVersion = require_version_utils.getInstalledPackageVersion(tree, "nx");
|
|
43
44
|
if (nxVersion && require_minimum_supported_versions.belowMinimumSupportedNxVersion(nxVersion)) throw new Error(_nx_devkit.stripIndents`Nx v${require_minimum_supported_versions.MINIMUM_SUPPORTED_NX_VERSION} or newer is required to install Analog`);
|
|
44
|
-
if (options.linter === "oxlint"
|
|
45
|
+
if (options.linter === "oxlint") {
|
|
46
|
+
if (!nxVersion) throw new Error(_nx_devkit.stripIndents`The oxlint linter is only supported in Nx workspaces`);
|
|
47
|
+
if (require_minimum_supported_versions.belowMinimumSupportedOxlintNxVersion(nxVersion)) throw new Error(_nx_devkit.stripIndents`Nx v${require_minimum_supported_versions.MINIMUM_SUPPORTED_OXLINT_NX_VERSION} or newer is required to use the oxlint linter`);
|
|
48
|
+
}
|
|
45
49
|
const normalizedOptions = normalizeOptions(tree, options);
|
|
46
50
|
if (nxVersion) await require_add_angular_app.addAngularApp(tree, normalizedOptions);
|
|
47
51
|
else {
|
|
@@ -62,10 +66,11 @@ async function appGenerator(tree, options) {
|
|
|
62
66
|
require_add_files.addFiles(tree, normalizedOptions, majorAngularVersion);
|
|
63
67
|
(0, _nx_devkit.addDependenciesToPackageJson)(tree, {
|
|
64
68
|
"front-matter": "^4.0.2",
|
|
69
|
+
h3: require_versions.H3,
|
|
65
70
|
marked: "^18.0.0",
|
|
66
71
|
mermaid: "^10.2.4",
|
|
67
72
|
prismjs: "^1.29.0"
|
|
68
|
-
}, {});
|
|
73
|
+
}, { "@analogjs/vite-plugin-nitro": require_versions.ANALOG_JS_VITE_PLUGIN_NITRO });
|
|
69
74
|
(0, _nx_devkit.updateJson)(tree, "/package.json", (json) => {
|
|
70
75
|
json.dependencies["@angular/platform-server"] = `~${angularVersion}`;
|
|
71
76
|
json.overrides = {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"generator.js","names":[],"sources":["../../../../../../../../nx-plugin/src/generators/app/generator.ts"],"sourcesContent":["import {\n formatFiles,\n getWorkspaceLayout,\n installPackagesTask,\n names,\n offsetFromRoot as determineOffsetFromRoot,\n stripIndents,\n Tree,\n addDependenciesToPackageJson,\n updateJson,\n} from '@nx/devkit';\nimport { wrapAngularDevkitSchematic } from '@nx/devkit/ngcli-adapter';\nimport { AnalogNxApplicationGeneratorOptions } from './schema';\nimport { major, coerce } from 'semver';\nimport { getInstalledPackageVersion } from '../../utils/version-utils';\nimport { addHomePage } from './lib/add-home-page';\nimport {\n belowMinimumSupportedNxVersion,\n MINIMUM_SUPPORTED_NX_VERSION,\n} from './versions/minimum-supported-versions';\nimport { addAngularApp } from './lib/add-angular-app';\nimport setupAnalogGenerator from '../init/generator';\nimport { addFiles } from './lib/add-files';\nimport { addAgentContext } from './lib/add-agent-context';\nimport { addTailwindConfig } from './lib/add-tailwind-config';\nimport { cleanupFiles } from './lib/cleanup-files';\nimport { addAnalogProjectConfig } from './lib/add-analog-project-config';\nimport { updateIndex } from './lib/update-index-html';\n\nexport interface NormalizedOptions\n extends AnalogNxApplicationGeneratorOptions, ReturnType<typeof names> {\n projectName: string;\n projectRoot: string;\n projectDirectory: string;\n parsedTags: string[];\n offsetFromRoot: string;\n appsDir: string;\n nxPackageNamespace: string;\n isNx: boolean;\n}\n\nfunction normalizeOptions(\n tree: Tree,\n options: AnalogNxApplicationGeneratorOptions,\n): NormalizedOptions {\n const isNx = tree.exists('/nx.json');\n const appsDir = isNx ? getWorkspaceLayout(tree).appsDir : 'projects';\n const allNames = names(options.analogAppName);\n const projectDirectory = allNames.fileName;\n const projectName = projectDirectory.replace(new RegExp('/', 'g'), '-');\n const projectRoot = `${appsDir}/${projectDirectory}`;\n const parsedTags = options.tags\n ? options.tags.split(',').map((s) => s.trim())\n : [];\n const offsetFromRoot = determineOffsetFromRoot(projectRoot);\n const nxPackageNamespace = '@nx';\n const addTailwind = options.addTailwind ?? true;\n\n return {\n ...options,\n ...allNames,\n projectName,\n projectRoot,\n projectDirectory,\n parsedTags,\n offsetFromRoot,\n appsDir,\n nxPackageNamespace,\n addTailwind,\n isNx,\n };\n}\n\nasync function appGenerator(\n tree: Tree,\n options: AnalogNxApplicationGeneratorOptions,\n): Promise<() => void> {\n const nxVersion = getInstalledPackageVersion(tree, 'nx');\n\n if (nxVersion && belowMinimumSupportedNxVersion(nxVersion)) {\n throw new Error(\n stripIndents`Nx v${MINIMUM_SUPPORTED_NX_VERSION} or newer is required to install Analog`,\n );\n }\n\n if (options.linter === 'oxlint'
|
|
1
|
+
{"version":3,"file":"generator.js","names":[],"sources":["../../../../../../../../nx-plugin/src/generators/app/generator.ts"],"sourcesContent":["import {\n formatFiles,\n getWorkspaceLayout,\n installPackagesTask,\n names,\n offsetFromRoot as determineOffsetFromRoot,\n stripIndents,\n Tree,\n addDependenciesToPackageJson,\n updateJson,\n} from '@nx/devkit';\nimport { wrapAngularDevkitSchematic } from '@nx/devkit/ngcli-adapter';\nimport { AnalogNxApplicationGeneratorOptions } from './schema';\nimport { major, coerce } from 'semver';\nimport { getInstalledPackageVersion } from '../../utils/version-utils';\nimport { addHomePage } from './lib/add-home-page';\nimport {\n belowMinimumSupportedNxVersion,\n belowMinimumSupportedOxlintNxVersion,\n MINIMUM_SUPPORTED_NX_VERSION,\n MINIMUM_SUPPORTED_OXLINT_NX_VERSION,\n} from './versions/minimum-supported-versions';\nimport { addAngularApp } from './lib/add-angular-app';\nimport setupAnalogGenerator from '../init/generator';\nimport { addFiles } from './lib/add-files';\nimport { addAgentContext } from './lib/add-agent-context';\nimport { addTailwindConfig } from './lib/add-tailwind-config';\nimport { cleanupFiles } from './lib/cleanup-files';\nimport { addAnalogProjectConfig } from './lib/add-analog-project-config';\nimport { updateIndex } from './lib/update-index-html';\nimport { ANALOG_JS_VITE_PLUGIN_NITRO, H3 } from '../../utils/versions/versions';\n\nexport interface NormalizedOptions\n extends AnalogNxApplicationGeneratorOptions, ReturnType<typeof names> {\n projectName: string;\n projectRoot: string;\n projectDirectory: string;\n parsedTags: string[];\n offsetFromRoot: string;\n appsDir: string;\n nxPackageNamespace: string;\n isNx: boolean;\n}\n\nfunction normalizeOptions(\n tree: Tree,\n options: AnalogNxApplicationGeneratorOptions,\n): NormalizedOptions {\n const isNx = tree.exists('/nx.json');\n const appsDir = isNx ? getWorkspaceLayout(tree).appsDir : 'projects';\n const allNames = names(options.analogAppName);\n const projectDirectory = allNames.fileName;\n const projectName = projectDirectory.replace(new RegExp('/', 'g'), '-');\n const projectRoot = `${appsDir}/${projectDirectory}`;\n const parsedTags = options.tags\n ? options.tags.split(',').map((s) => s.trim())\n : [];\n const offsetFromRoot = determineOffsetFromRoot(projectRoot);\n const nxPackageNamespace = '@nx';\n const addTailwind = options.addTailwind ?? true;\n\n return {\n ...options,\n ...allNames,\n projectName,\n projectRoot,\n projectDirectory,\n parsedTags,\n offsetFromRoot,\n appsDir,\n nxPackageNamespace,\n addTailwind,\n isNx,\n };\n}\n\nasync function appGenerator(\n tree: Tree,\n options: AnalogNxApplicationGeneratorOptions,\n): Promise<() => void> {\n const nxVersion = getInstalledPackageVersion(tree, 'nx');\n\n if (nxVersion && belowMinimumSupportedNxVersion(nxVersion)) {\n throw new Error(\n stripIndents`Nx v${MINIMUM_SUPPORTED_NX_VERSION} or newer is required to install Analog`,\n );\n }\n\n if (options.linter === 'oxlint') {\n if (!nxVersion) {\n throw new Error(\n stripIndents`The oxlint linter is only supported in Nx workspaces`,\n );\n }\n if (belowMinimumSupportedOxlintNxVersion(nxVersion)) {\n throw new Error(\n stripIndents`Nx v${MINIMUM_SUPPORTED_OXLINT_NX_VERSION} or newer is required to use the oxlint linter`,\n );\n }\n }\n\n const normalizedOptions = normalizeOptions(tree, options);\n\n if (nxVersion) {\n await addAngularApp(tree, normalizedOptions);\n } else {\n const angularAppSchematic = wrapAngularDevkitSchematic(\n '@schematics/angular',\n 'application',\n );\n await angularAppSchematic(tree, {\n projectRoot: normalizedOptions.projectRoot,\n name: normalizedOptions.analogAppName,\n });\n addAnalogProjectConfig(\n tree,\n normalizedOptions.projectRoot,\n normalizedOptions.projectName,\n normalizedOptions.parsedTags,\n normalizedOptions.name,\n normalizedOptions.appsDir,\n normalizedOptions.nxPackageNamespace,\n );\n }\n\n await setupAnalogGenerator(tree, {\n project: normalizedOptions.analogAppName,\n vitest: true,\n });\n\n const angularVersion = getInstalledPackageVersion(tree, '@angular/core');\n const coercedAngularVersion = coerce(angularVersion ?? '');\n if (!coercedAngularVersion) {\n throw new Error('Could not determine installed Angular version.');\n }\n const majorAngularVersion = major(coercedAngularVersion);\n addFiles(tree, normalizedOptions, majorAngularVersion);\n addDependenciesToPackageJson(\n tree,\n {\n 'front-matter': '^4.0.2',\n h3: H3,\n marked: '^18.0.0',\n mermaid: '^10.2.4',\n prismjs: '^1.29.0',\n },\n { '@analogjs/vite-plugin-nitro': ANALOG_JS_VITE_PLUGIN_NITRO },\n );\n\n updateJson<{\n dependencies: Record<string, string>;\n overrides?: Record<string, unknown>;\n }>(tree, '/package.json', (json) => {\n json.dependencies['@angular/platform-server'] = `~${angularVersion}`;\n json.overrides = {\n ...json.overrides,\n vite: '$vite',\n vitest: '$vitest',\n };\n\n return json;\n });\n\n updateIndex(tree, normalizedOptions.analogAppName);\n\n if (normalizedOptions.addTailwind) {\n await addTailwindConfig(tree, normalizedOptions.projectName);\n }\n\n addHomePage(tree, normalizedOptions, majorAngularVersion);\n\n if (!normalizedOptions.skipAgentContext) {\n addAgentContext(tree, normalizedOptions.projectRoot);\n }\n\n cleanupFiles(tree, normalizedOptions);\n\n if (!normalizedOptions.skipFormat) {\n await formatFiles(tree);\n }\n\n return () => {\n installPackagesTask(tree);\n };\n}\n\nexport default appGenerator;\n"],"mappings":";;;;;;;;;;;;;;;;AA4CA,SAAS,iBACP,MACA,SACmB;CACnB,MAAM,OAAO,KAAK,OAAO,UAAU;CACnC,MAAM,UAAU,QAAA,GAAO,WAAA,mBAAA,CAAmB,IAAI,CAAC,CAAC,UAAU;CAC1D,MAAM,YAAA,GAAW,WAAA,MAAA,CAAM,QAAQ,aAAa;CAC5C,MAAM,mBAAmB,SAAS;CAClC,MAAM,cAAc,iBAAiB,wBAAQ,IAAI,OAAO,KAAK,GAAG,GAAG,GAAG;CACtE,MAAM,cAAc,GAAG,QAAQ,GAAG;CAClC,MAAM,aAAa,QAAQ,OACvB,QAAQ,KAAK,MAAM,GAAG,CAAC,CAAC,KAAK,MAAM,EAAE,KAAK,CAAC,IAC3C,CAAC;CACL,MAAM,kBAAA,GAAiB,WAAA,eAAA,CAAwB,WAAW;CAC1D,MAAM,qBAAqB;CAC3B,MAAM,cAAc,QAAQ,eAAe;CAE3C,OAAO;EACL,GAAG;EACH,GAAG;E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4BAA4B,CAC/D;CAEA,CAAA,GAAA,WAAA,WAAA,CAGG,MAAM,kBAAkB,SAAS;EAClC,KAAK,aAAa,8BAA8B,IAAI;EACpD,KAAK,YAAY;GACf,GAAG,KAAK;GACR,MAAM;GACN,QAAQ;EACV;EAEA,OAAO;CACT,CAAC;CAED,0BAAA,YAAY,MAAM,kBAAkB,aAAa;CAEjD,IAAI,kBAAkB,aACpB,MAAM,4BAAA,kBAAkB,MAAM,kBAAkB,WAAW;CAG7D,sBAAA,YAAY,MAAM,mBAAmB,mBAAmB;CAExD,IAAI,CAAC,kBAAkB,kBACrB,0BAAA,gBAAgB,MAAM,kBAAkB,WAAW;CAGrD,sBAAA,aAAa,MAAM,iBAAiB;CAEpC,IAAI,CAAC,kBAAkB,YACrB,OAAA,GAAM,WAAA,YAAA,CAAY,IAAI;CAGxB,aAAa;EACX,CAAA,GAAA,WAAA,oBAAA,CAAoB,IAAI;CAC1B;AACF"}
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
const require_tailwind_dependencies = require("../versions/tailwind-dependencies.js");
|
|
2
2
|
let _nx_devkit = require("@nx/devkit");
|
|
3
3
|
let semver = require("semver");
|
|
4
|
-
let _nx_devkit_internal = require("@nx/devkit/internal");
|
|
5
4
|
//#region packages/nx-plugin/src/generators/app/lib/add-tailwind-helpers.ts
|
|
6
5
|
function normalizeOptions(options) {
|
|
7
6
|
return {
|
|
@@ -13,7 +12,8 @@ function detectTailwindInstalledVersion(tree) {
|
|
|
13
12
|
const { dependencies, devDependencies } = (0, _nx_devkit.readJson)(tree, "package.json");
|
|
14
13
|
const tailwindVersion = dependencies?.tailwindcss ?? devDependencies?.tailwindcss;
|
|
15
14
|
if (!tailwindVersion) return;
|
|
16
|
-
const version = (0,
|
|
15
|
+
const version = (0, semver.coerce)(tailwindVersion);
|
|
16
|
+
if (!version) throw new Error(`The Tailwind CSS version "${tailwindVersion}" is not a valid version.`);
|
|
17
17
|
if ((0, semver.lt)(version, "4.0.0")) throw new Error(`The Tailwind CSS version "${tailwindVersion}" is not supported. Please upgrade to v4.0.0 or higher.`);
|
|
18
18
|
return (0, semver.lt)(version, "5.0.0") ? "4" : "5";
|
|
19
19
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"add-tailwind-helpers.js","names":[],"sources":["../../../../../../../../../nx-plugin/src/generators/app/lib/add-tailwind-helpers.ts"],"sourcesContent":["import {
|
|
1
|
+
{"version":3,"file":"add-tailwind-helpers.js","names":[],"sources":["../../../../../../../../../nx-plugin/src/generators/app/lib/add-tailwind-helpers.ts"],"sourcesContent":["import { getTailwindDependencies } from '../versions/tailwind-dependencies';\nimport { coerce, lt } from 'semver';\nimport {\n Tree,\n readJson,\n addDependenciesToPackageJson,\n GeneratorCallback,\n ProjectConfiguration,\n joinPathFragments,\n stripIndents,\n} from '@nx/devkit';\nimport {\n GeneratorOptions,\n NormalizedGeneratorOptions,\n} from './add-tailwind-config';\n\nexport function normalizeOptions(\n options: GeneratorOptions,\n): NormalizedGeneratorOptions {\n return {\n ...options,\n buildTarget: options.buildTarget || 'build',\n };\n}\n\nexport function detectTailwindInstalledVersion(\n tree: Tree,\n): '4' | '5' | undefined {\n const { dependencies, devDependencies } = readJson(tree, 'package.json');\n const tailwindVersion =\n dependencies?.tailwindcss ?? devDependencies?.tailwindcss;\n\n if (!tailwindVersion) {\n return undefined;\n }\n\n const version = coerce(tailwindVersion);\n if (!version) {\n throw new Error(\n `The Tailwind CSS version \"${tailwindVersion}\" is not a valid version.`,\n );\n }\n if (lt(version, '4.0.0')) {\n throw new Error(\n `The Tailwind CSS version \"${tailwindVersion}\" is not supported. Please upgrade to v4.0.0 or higher.`,\n );\n }\n return lt(version, '5.0.0') ? '4' : '5';\n}\n\nexport function addTailwindRequiredPackages(tree: Tree): GeneratorCallback {\n const pkgVersions = getTailwindDependencies();\n return addDependenciesToPackageJson(\n tree,\n {\n postcss: pkgVersions.postcss,\n tailwindcss: pkgVersions.tailwindcss,\n '@tailwindcss/postcss': pkgVersions['@tailwindcss/postcss'],\n '@tailwindcss/vite': pkgVersions['@tailwindcss/vite'],\n },\n {},\n );\n}\n\nexport function writeTailwindPostcssConfig(\n tree: Tree,\n project: ProjectConfiguration,\n): void {\n const postcssConfigPath = joinPathFragments(\n project.root,\n 'postcss.config.mjs',\n );\n\n if (tree.exists(postcssConfigPath)) {\n return;\n }\n\n tree.write(\n postcssConfigPath,\n `export default {\n plugins: {\n '@tailwindcss/postcss': {},\n },\n};\n`,\n );\n}\n\nexport function updateApplicationStyles(\n tree: Tree,\n options: NormalizedGeneratorOptions,\n project: ProjectConfiguration,\n): void {\n let stylesEntryPoint = options.stylesEntryPoint;\n\n if (stylesEntryPoint && !tree.exists(stylesEntryPoint)) {\n throw new Error(\n `The provided styles entry point \"${stylesEntryPoint}\" could not be found.`,\n );\n }\n\n if (!stylesEntryPoint) {\n stylesEntryPoint = findStylesEntryPoint(tree, options, project);\n\n if (!stylesEntryPoint) {\n throw new Error(\n stripIndents`Could not find a styles entry point for project \"${options.project}\".\n Please specify a styles entry point using the \"--stylesEntryPoint\" option.`,\n );\n }\n }\n\n if (!stylesEntryPoint.endsWith('.css')) {\n throw new Error(\n `Tailwind CSS v4 is not compatible with any css preprocessors like sass or less. Please use a css file as the styles entry point.`,\n );\n }\n\n const stylesEntryPointContent = tree.read(stylesEntryPoint, 'utf-8');\n\n tree.write(\n stylesEntryPoint,\n stripIndents`@import \"tailwindcss\";\n\n\n ${stylesEntryPointContent}`,\n );\n}\n\nfunction findStylesEntryPoint(\n tree: Tree,\n options: NormalizedGeneratorOptions,\n project: ProjectConfiguration,\n): string | undefined {\n // first check for common names\n const possibleStylesEntryPoints = [\n joinPathFragments(project.sourceRoot ?? project.root, 'styles.css'),\n joinPathFragments(project.sourceRoot ?? project.root, 'styles.scss'),\n joinPathFragments(project.sourceRoot ?? project.root, 'styles.sass'),\n joinPathFragments(project.sourceRoot ?? project.root, 'styles.less'),\n ];\n\n const stylesEntryPoint = possibleStylesEntryPoints.find((s) =>\n tree.exists(s),\n );\n if (stylesEntryPoint) {\n return stylesEntryPoint;\n }\n\n // then check for the specified styles in the build configuration if it exists\n const styles: Array<string | { input: string; inject: boolean }> =\n project.targets?.[options.buildTarget].options?.styles;\n\n if (!styles) {\n return undefined;\n }\n\n // find the first style that belongs to the project source\n const style = styles.find((s) =>\n typeof s === 'string'\n ? s.startsWith(project.root) && tree.exists(s)\n : s.input.startsWith(project.root) &&\n s.inject !== false &&\n tree.exists(s.input),\n );\n\n if (!style) {\n return undefined;\n }\n\n return typeof style === 'string' ? style : style.input;\n}\n"],"mappings":";;;;AAgBA,SAAgB,iBACd,SAC4B;CAC5B,OAAO;EACL,GAAG;EACH,aAAa,QAAQ,eAAe;CACtC;AACF;AAEA,SAAgB,+BACd,MACuB;CACvB,MAAM,EAAE,cAAc,qBAAA,GAAoB,WAAA,SAAA,CAAS,MAAM,cAAc;CACvE,MAAM,kBACJ,cAAc,eAAe,iBAAiB;CAEhD,IAAI,CAAC,iBACH;CAGF,MAAM,WAAA,GAAU,OAAA,OAAA,CAAO,eAAe;CACtC,IAAI,CAAC,SACH,MAAM,IAAI,MACR,6BAA6B,gBAAgB,0BAC/C;CAEF,KAAA,GAAI,OAAA,GAAA,CAAG,SAAS,OAAO,GACrB,MAAM,IAAI,MACR,6BAA6B,gBAAgB,wDAC/C;CAEF,QAAA,GAAO,OAAA,GAAA,CAAG,SAAS,OAAO,IAAI,MAAM;AACtC;AAEA,SAAgB,4BAA4B,MAA+B;CACzE,MAAM,cAAc,8BAAA,wBAAwB;CAC5C,QAAA,GAAO,WAAA,6BAAA,CACL,MACA;EACE,SAAS,YAAY;EACrB,aAAa,YAAY;EACzB,wBAAwB,YAAY;EACpC,qBAAqB,YAAY;CACnC,GACA,CAAC,CACH;AACF;AAEA,SAAgB,2BACd,MACA,SACM;CACN,MAAM,qBAAA,GAAoB,WAAA,kBAAA,CACxB,QAAQ,MACR,oBACF;CAEA,IAAI,KAAK,OAAO,iBAAiB,GA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AAO,UAAU,WAAW,QAAQ,MAAM;AACnD"}
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
-
export declare const MINIMUM_SUPPORTED_NX_VERSION = "
|
|
1
|
+
export declare const MINIMUM_SUPPORTED_NX_VERSION = "21.2.0";
|
|
2
|
+
export declare const MINIMUM_SUPPORTED_OXLINT_NX_VERSION = "23.2.0";
|
|
2
3
|
export declare const MINIMUM_SUPPORTED_ANGULAR_VERSION = "20.0.0";
|
|
3
4
|
export declare const belowMinimumSupportedNxVersion: (nxVersion: string) => boolean;
|
|
5
|
+
export declare const belowMinimumSupportedOxlintNxVersion: (nxVersion: string) => boolean;
|