@nx/vite 19.4.0-beta.0 → 19.4.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/generators.json +5 -0
- package/package.json +4 -4
- package/plugins/nx-tsconfig-paths.plugin.js +3 -3
- package/plugins/nx-tsconfig-paths.plugin.js.map +1 -1
- package/src/generators/convert-to-inferred/convert-to-inferred.d.ts +7 -0
- package/src/generators/convert-to-inferred/convert-to-inferred.js +83 -0
- package/src/generators/convert-to-inferred/convert-to-inferred.js.map +1 -0
- package/src/generators/convert-to-inferred/lib/build-post-target-transformer.d.ts +6 -0
- package/src/generators/convert-to-inferred/lib/build-post-target-transformer.js +160 -0
- package/src/generators/convert-to-inferred/lib/build-post-target-transformer.js.map +1 -0
- package/src/generators/convert-to-inferred/lib/preview-post-target-transformer.d.ts +6 -0
- package/src/generators/convert-to-inferred/lib/preview-post-target-transformer.js +50 -0
- package/src/generators/convert-to-inferred/lib/preview-post-target-transformer.js.map +1 -0
- package/src/generators/convert-to-inferred/lib/serve-post-target-transformer.d.ts +6 -0
- package/src/generators/convert-to-inferred/lib/serve-post-target-transformer.js +58 -0
- package/src/generators/convert-to-inferred/lib/serve-post-target-transformer.js.map +1 -0
- package/src/generators/convert-to-inferred/lib/test-post-target-transformer.d.ts +5 -0
- package/src/generators/convert-to-inferred/lib/test-post-target-transformer.js +63 -0
- package/src/generators/convert-to-inferred/lib/test-post-target-transformer.js.map +1 -0
- package/src/generators/convert-to-inferred/lib/utils.d.ts +4 -0
- package/src/generators/convert-to-inferred/lib/utils.js +69 -0
- package/src/generators/convert-to-inferred/lib/utils.js.map +1 -0
- package/src/generators/convert-to-inferred/schema.json +19 -0
- package/src/generators/init/init.js +1 -1
- package/src/generators/init/init.js.map +1 -1
- package/src/generators/setup-paths-plugin/setup-paths-plugin.js +3 -0
- package/src/generators/setup-paths-plugin/setup-paths-plugin.js.map +1 -1
- package/src/plugins/plugin.js +18 -8
- package/src/plugins/plugin.js.map +1 -1
package/generators.json
CHANGED
|
@@ -21,6 +21,11 @@
|
|
|
21
21
|
"schema": "./src/generators/setup-paths-plugin/schema.json",
|
|
22
22
|
"description": "Sets up the nxViteTsPaths plugin to enable support for workspace libraries."
|
|
23
23
|
},
|
|
24
|
+
"convert-to-inferred": {
|
|
25
|
+
"factory": "./src/generators/convert-to-inferred/convert-to-inferred",
|
|
26
|
+
"schema": "./src/generators/convert-to-inferred/schema.json",
|
|
27
|
+
"description": "Convert existing Vite project(s) using `@nx/vite:*` executors to use `@nx/vite/plugin`. Defaults to migrating all projects. Pass '--project' to migrate only one target."
|
|
28
|
+
},
|
|
24
29
|
"vitest": {
|
|
25
30
|
"factory": "./src/generators/vitest/vitest-generator#vitestGeneratorInternal",
|
|
26
31
|
"schema": "./src/generators/vitest/schema.json",
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nx/vite",
|
|
3
|
-
"version": "19.4.0-beta.
|
|
3
|
+
"version": "19.4.0-beta.2",
|
|
4
4
|
"private": false,
|
|
5
5
|
"description": "The Nx Plugin for building and testing applications using Vite",
|
|
6
6
|
"repository": {
|
|
@@ -30,13 +30,13 @@
|
|
|
30
30
|
"migrations": "./migrations.json"
|
|
31
31
|
},
|
|
32
32
|
"dependencies": {
|
|
33
|
-
"@nx/devkit": "19.4.0-beta.
|
|
33
|
+
"@nx/devkit": "19.4.0-beta.2",
|
|
34
34
|
"@phenomnomnominal/tsquery": "~5.0.1",
|
|
35
35
|
"@swc/helpers": "~0.5.0",
|
|
36
36
|
"enquirer": "~2.3.6",
|
|
37
|
-
"@nx/js": "19.4.0-beta.
|
|
37
|
+
"@nx/js": "19.4.0-beta.2",
|
|
38
38
|
"tsconfig-paths": "^4.1.2",
|
|
39
|
-
"@nrwl/vite": "19.4.0-beta.
|
|
39
|
+
"@nrwl/vite": "19.4.0-beta.2"
|
|
40
40
|
},
|
|
41
41
|
"peerDependencies": {
|
|
42
42
|
"vite": "^5.0.0",
|
|
@@ -51,7 +51,7 @@ function nxViteTsPaths(options = {}) {
|
|
|
51
51
|
throw new Error((0, _devkit.stripIndents)`Unable to find a tsconfig in the workspace!
|
|
52
52
|
There should at least be a tsconfig.base.json or tsconfig.json in the root of the workspace ${_devkit.workspaceRoot}`);
|
|
53
53
|
}
|
|
54
|
-
if (!options.buildLibsFromSource && !global.NX_GRAPH_CREATION) {
|
|
54
|
+
if (!options.buildLibsFromSource && !global.NX_GRAPH_CREATION && config.mode !== 'test') {
|
|
55
55
|
const projectGraph = await (0, _devkit.createProjectGraphAsync)({
|
|
56
56
|
exitOnError: false,
|
|
57
57
|
resetDaemonClient: true
|
|
@@ -61,7 +61,7 @@ There should at least be a tsconfig.base.json or tsconfig.json in the root of th
|
|
|
61
61
|
process.env.NX_TASK_TARGET_TARGET === 'serve' ? 'build' : process.env.NX_TASK_TARGET_TARGET, process.env.NX_TASK_TARGET_CONFIGURATION);
|
|
62
62
|
// This tsconfig is used via the Vite ts paths plugin.
|
|
63
63
|
// It can be also used by other user-defined Vite plugins (e.g. for creating type declaration files).
|
|
64
|
-
foundTsConfigPath = (0, _buildablelibsutils.createTmpTsConfig)(foundTsConfigPath, _devkit.workspaceRoot, (0, _nodepath.relative)(_devkit.workspaceRoot, projectRoot), dependencies);
|
|
64
|
+
foundTsConfigPath = (0, _buildablelibsutils.createTmpTsConfig)(foundTsConfigPath, _devkit.workspaceRoot, (0, _nodepath.relative)(_devkit.workspaceRoot, projectRoot), dependencies, true);
|
|
65
65
|
if (config.command === 'serve') {
|
|
66
66
|
const buildableLibraryDependencies = dependencies.filter((dep)=>dep.node.type === 'lib').map((dep)=>dep.node.name).join(',');
|
|
67
67
|
const buildCommand = `npx nx run-many --target=${process.env.NX_TASK_TARGET_TARGET} --projects=${buildableLibraryDependencies}`;
|
|
@@ -73,7 +73,7 @@ There should at least be a tsconfig.base.json or tsconfig.json in the root of th
|
|
|
73
73
|
const parsed = (0, _tsconfigpaths.loadConfig)(foundTsConfigPath);
|
|
74
74
|
logIt('first parsed tsconfig: ', parsed);
|
|
75
75
|
if (parsed.resultType === 'failed') {
|
|
76
|
-
throw new Error(`Failed loading
|
|
76
|
+
throw new Error(`Failed loading tsconfig at ${foundTsConfigPath}`);
|
|
77
77
|
}
|
|
78
78
|
tsConfigPathsEsm = parsed;
|
|
79
79
|
matchTsPathEsm = (0, _tsconfigpaths.createMatchPath)(parsed.absoluteBaseUrl, parsed.paths, options.mainFields);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../packages/vite/plugins/nx-tsconfig-paths.plugin.ts"],"sourcesContent":["import {\n createProjectGraphAsync,\n joinPathFragments,\n stripIndents,\n workspaceRoot,\n} from '@nx/devkit';\nimport { copyFileSync, existsSync } from 'node:fs';\nimport { relative, join, resolve } from 'node:path';\nimport {\n loadConfig,\n createMatchPath,\n MatchPath,\n ConfigLoaderSuccessResult,\n} from 'tsconfig-paths';\nimport {\n calculateProjectBuildableDependencies,\n createTmpTsConfig,\n} from '@nx/js/src/utils/buildable-libs-utils';\nimport { Plugin } from 'vite';\nimport { nxViteBuildCoordinationPlugin } from './nx-vite-build-coordination.plugin';\n\nexport interface nxViteTsPathsOptions {\n /**\n * Enable debug logging\n * @default false\n **/\n debug?: boolean;\n /**\n * export fields in package.json to use for resolving\n * @default [['exports', '.', 'import'], 'module', 'main']\n *\n * fallback resolution will use ['main', 'module']\n **/\n mainFields?: (string | string[])[];\n /**\n * extensions to check when resolving files when package.json resolution fails\n * @default ['.ts', '.tsx', '.js', '.jsx', '.json', '.mjs', '.cjs']\n **/\n extensions?: string[];\n /**\n * Inform Nx whether to use the raw source or to use the built output for buildable dependencies.\n * Set to `false` to use incremental builds.\n * @default true\n */\n buildLibsFromSource?: boolean;\n}\n\nexport function nxViteTsPaths(options: nxViteTsPathsOptions = {}) {\n let matchTsPathEsm: MatchPath;\n let matchTsPathFallback: MatchPath | undefined;\n let tsConfigPathsEsm: ConfigLoaderSuccessResult;\n let tsConfigPathsFallback: ConfigLoaderSuccessResult;\n\n options.extensions ??= [\n '.ts',\n '.tsx',\n '.js',\n '.jsx',\n '.json',\n '.mjs',\n '.cjs',\n ];\n options.mainFields ??= [['exports', '.', 'import'], 'module', 'main'];\n options.buildLibsFromSource ??= true;\n let projectRoot = '';\n\n return {\n name: 'nx-vite-ts-paths',\n async configResolved(config: any) {\n projectRoot = config.root;\n const projectRootFromWorkspaceRoot = relative(workspaceRoot, projectRoot);\n let foundTsConfigPath = getTsConfig(\n join(\n workspaceRoot,\n 'tmp',\n projectRootFromWorkspaceRoot,\n process.env.NX_TASK_TARGET_TARGET ?? 'build',\n 'tsconfig.generated.json'\n )\n );\n if (!foundTsConfigPath) {\n throw new Error(stripIndents`Unable to find a tsconfig in the workspace! \nThere should at least be a tsconfig.base.json or tsconfig.json in the root of the workspace ${workspaceRoot}`);\n }\n\n if (!options.buildLibsFromSource && !global.NX_GRAPH_CREATION) {\n const projectGraph = await createProjectGraphAsync({\n exitOnError: false,\n resetDaemonClient: true,\n });\n const { dependencies } = calculateProjectBuildableDependencies(\n undefined,\n projectGraph,\n workspaceRoot,\n process.env.NX_TASK_TARGET_PROJECT,\n // When using incremental building and the serve target is called\n // we need to get the deps for the 'build' target instead.\n process.env.NX_TASK_TARGET_TARGET === 'serve'\n ? 'build'\n : process.env.NX_TASK_TARGET_TARGET,\n process.env.NX_TASK_TARGET_CONFIGURATION\n );\n // This tsconfig is used via the Vite ts paths plugin.\n // It can be also used by other user-defined Vite plugins (e.g. for creating type declaration files).\n foundTsConfigPath = createTmpTsConfig(\n foundTsConfigPath,\n workspaceRoot,\n relative(workspaceRoot, projectRoot),\n dependencies\n );\n\n if (config.command === 'serve') {\n const buildableLibraryDependencies = dependencies\n .filter((dep) => dep.node.type === 'lib')\n .map((dep) => dep.node.name)\n .join(',');\n const buildCommand = `npx nx run-many --target=${process.env.NX_TASK_TARGET_TARGET} --projects=${buildableLibraryDependencies}`;\n config.plugins.push(nxViteBuildCoordinationPlugin({ buildCommand }));\n }\n }\n\n const parsed = loadConfig(foundTsConfigPath);\n\n logIt('first parsed tsconfig: ', parsed);\n if (parsed.resultType === 'failed') {\n throw new Error(`Failed loading tsonfig at ${foundTsConfigPath}`);\n }\n tsConfigPathsEsm = parsed;\n\n matchTsPathEsm = createMatchPath(\n parsed.absoluteBaseUrl,\n parsed.paths,\n options.mainFields\n );\n\n const rootLevelTsConfig = getTsConfig(\n join(workspaceRoot, 'tsconfig.base.json')\n );\n const rootLevelParsed = loadConfig(rootLevelTsConfig);\n logIt('fallback parsed tsconfig: ', rootLevelParsed);\n if (rootLevelParsed.resultType === 'success') {\n tsConfigPathsFallback = rootLevelParsed;\n matchTsPathFallback = createMatchPath(\n rootLevelParsed.absoluteBaseUrl,\n rootLevelParsed.paths,\n ['main', 'module']\n );\n }\n },\n resolveId(importPath: string) {\n let resolvedFile: string;\n try {\n resolvedFile = matchTsPathEsm(importPath);\n } catch (e) {\n logIt('Using fallback path matching.');\n resolvedFile = matchTsPathFallback?.(importPath);\n }\n\n if (!resolvedFile) {\n if (tsConfigPathsEsm || tsConfigPathsFallback) {\n logIt(\n `Unable to resolve ${importPath} with tsconfig paths. Using fallback file matching.`\n );\n resolvedFile =\n loadFileFromPaths(tsConfigPathsEsm, importPath) ||\n loadFileFromPaths(tsConfigPathsFallback, importPath);\n } else {\n logIt(`Unable to resolve ${importPath} with tsconfig paths`);\n }\n }\n\n logIt(`Resolved ${importPath} to ${resolvedFile}`);\n // Returning null defers to other resolveId functions and eventually the default resolution behavior\n // https://rollupjs.org/plugin-development/#resolveid\n return resolvedFile || null;\n },\n async writeBundle(options) {\n const outDir = options.dir || 'dist';\n const src = resolve(projectRoot, 'package.json');\n if (existsSync(src)) {\n const dest = join(outDir, 'package.json');\n\n try {\n copyFileSync(src, dest);\n } catch (err) {\n console.error('Error copying package.json:', err);\n }\n }\n },\n } as Plugin;\n\n function getTsConfig(preferredTsConfigPath: string): string {\n return [\n resolve(preferredTsConfigPath),\n resolve(join(workspaceRoot, 'tsconfig.base.json')),\n resolve(join(workspaceRoot, 'tsconfig.json')),\n ].find((tsPath) => {\n if (existsSync(tsPath)) {\n logIt('Found tsconfig at', tsPath);\n return tsPath;\n }\n });\n }\n\n function logIt(...msg: any[]) {\n if (process.env.NX_VERBOSE_LOGGING === 'true' || options?.debug) {\n console.debug('\\n[Nx Vite TsPaths]', ...msg);\n }\n }\n\n function loadFileFromPaths(\n tsconfig: ConfigLoaderSuccessResult,\n importPath: string\n ) {\n logIt(\n `Trying to resolve file from config in ${tsconfig.configFileAbsolutePath}`\n );\n let resolvedFile: string;\n for (const alias in tsconfig.paths) {\n const paths = tsconfig.paths[alias];\n\n const normalizedImport = alias.replace(/\\/\\*$/, '');\n\n if (importPath.startsWith(normalizedImport)) {\n const joinedPath = joinPathFragments(\n tsconfig.absoluteBaseUrl,\n paths[0].replace(/\\/\\*$/, '')\n );\n\n resolvedFile = findFile(\n importPath.replace(normalizedImport, joinedPath)\n );\n }\n }\n\n return resolvedFile;\n }\n\n function findFile(path: string): string {\n for (const ext of options.extensions) {\n const resolvedPath = resolve(path + ext);\n if (existsSync(resolvedPath)) {\n return resolvedPath;\n }\n\n const resolvedIndexPath = resolve(path, `index${ext}`);\n if (existsSync(resolvedIndexPath)) {\n return resolvedIndexPath;\n }\n }\n }\n}\n"],"names":["nxViteTsPaths","options","matchTsPathEsm","matchTsPathFallback","tsConfigPathsEsm","tsConfigPathsFallback","extensions","mainFields","buildLibsFromSource","projectRoot","name","configResolved","config","root","projectRootFromWorkspaceRoot","relative","workspaceRoot","process","foundTsConfigPath","getTsConfig","join","env","NX_TASK_TARGET_TARGET","Error","stripIndents","global","NX_GRAPH_CREATION","projectGraph","createProjectGraphAsync","exitOnError","resetDaemonClient","dependencies","calculateProjectBuildableDependencies","undefined","NX_TASK_TARGET_PROJECT","NX_TASK_TARGET_CONFIGURATION","createTmpTsConfig","command","buildableLibraryDependencies","filter","dep","node","type","map","buildCommand","plugins","push","nxViteBuildCoordinationPlugin","parsed","loadConfig","logIt","resultType","createMatchPath","absoluteBaseUrl","paths","rootLevelTsConfig","rootLevelParsed","resolveId","importPath","resolvedFile","e","loadFileFromPaths","writeBundle","outDir","dir","src","resolve","existsSync","dest","copyFileSync","err","console","error","preferredTsConfigPath","find","tsPath","msg","NX_VERBOSE_LOGGING","debug","tsconfig","configFileAbsolutePath","alias","normalizedImport","replace","startsWith","joinedPath","joinPathFragments","findFile","path","ext","resolvedPath","resolvedIndexPath"],"rangeMappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;","mappings":";+BA+CgBA;;;eAAAA;;;wBA1CT;wBACkC;0BACD;+BAMjC;oCAIA;+CAEuC;AA4BvC,SAASA,cAAcC,UAAgC,CAAC,CAAC;QAM9DA,UASAA,WACAA;IAfA,IAAIC;IACJ,IAAIC;IACJ,IAAIC;IACJ,IAAIC;;IAEJJ,gBAAAA,WAAAA,SAAQK,oCAARL,SAAQK,aAAe;QACrB;QACA;QACA;QACA;QACA;QACA;QACA;KACD;;IACDL,gBAAAA,YAAAA,SAAQM,oCAARN,UAAQM,aAAe;QAAC;YAAC;YAAW;YAAK;SAAS;QAAE;QAAU;KAAO;;IACrEN,yBAAAA,YAAAA,SAAQO,sDAARP,UAAQO,sBAAwB;IAChC,IAAIC,cAAc;IAElB,OAAO;QACLC,MAAM;QACN,MAAMC,gBAAeC,MAAW;YAC9BH,cAAcG,OAAOC,IAAI;YACzB,MAAMC,+BAA+BC,IAAAA,kBAAQ,EAACC,qBAAa,EAAEP;gBAMzDQ;YALJ,IAAIC,oBAAoBC,YACtBC,IAAAA,cAAI,EACFJ,qBAAa,EACb,OACAF,8BACAG,CAAAA,qCAAAA,QAAQI,GAAG,CAACC,q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E;YACpC,MAAMoF,eAAexB,IAAAA,iBAAO,EAACsB,OAAOC;YACpC,IAAItB,IAAAA,kBAAU,EAACuB,eAAe;gBAC5B,OAAOA;YACT;YAEA,MAAMC,oBAAoBzB,IAAAA,iBAAO,EAACsB,MAAM,CAAC,KAAK,EAAEC,IAAI,CAAC;YACrD,IAAItB,IAAAA,kBAAU,EAACwB,oBAAoB;gBACjC,OAAOA;YACT;QACF;IACF;AACF"}
|
|
1
|
+
{"version":3,"sources":["../../../../packages/vite/plugins/nx-tsconfig-paths.plugin.ts"],"sourcesContent":["import {\n createProjectGraphAsync,\n joinPathFragments,\n stripIndents,\n workspaceRoot,\n} from '@nx/devkit';\nimport { copyFileSync, existsSync } from 'node:fs';\nimport { relative, join, resolve } from 'node:path';\nimport {\n loadConfig,\n createMatchPath,\n MatchPath,\n ConfigLoaderSuccessResult,\n} from 'tsconfig-paths';\nimport {\n calculateProjectBuildableDependencies,\n createTmpTsConfig,\n} from '@nx/js/src/utils/buildable-libs-utils';\nimport { Plugin } from 'vite';\nimport { nxViteBuildCoordinationPlugin } from './nx-vite-build-coordination.plugin';\n\nexport interface nxViteTsPathsOptions {\n /**\n * Enable debug logging\n * @default false\n **/\n debug?: boolean;\n /**\n * export fields in package.json to use for resolving\n * @default [['exports', '.', 'import'], 'module', 'main']\n *\n * fallback resolution will use ['main', 'module']\n **/\n mainFields?: (string | string[])[];\n /**\n * extensions to check when resolving files when package.json resolution fails\n * @default ['.ts', '.tsx', '.js', '.jsx', '.json', '.mjs', '.cjs']\n **/\n extensions?: string[];\n /**\n * Inform Nx whether to use the raw source or to use the built output for buildable dependencies.\n * Set to `false` to use incremental builds.\n * @default true\n */\n buildLibsFromSource?: boolean;\n}\n\nexport function nxViteTsPaths(options: nxViteTsPathsOptions = {}) {\n let matchTsPathEsm: MatchPath;\n let matchTsPathFallback: MatchPath | undefined;\n let tsConfigPathsEsm: ConfigLoaderSuccessResult;\n let tsConfigPathsFallback: ConfigLoaderSuccessResult;\n\n options.extensions ??= [\n '.ts',\n '.tsx',\n '.js',\n '.jsx',\n '.json',\n '.mjs',\n '.cjs',\n ];\n options.mainFields ??= [['exports', '.', 'import'], 'module', 'main'];\n options.buildLibsFromSource ??= true;\n let projectRoot = '';\n\n return {\n name: 'nx-vite-ts-paths',\n async configResolved(config: any) {\n projectRoot = config.root;\n const projectRootFromWorkspaceRoot = relative(workspaceRoot, projectRoot);\n let foundTsConfigPath = getTsConfig(\n join(\n workspaceRoot,\n 'tmp',\n projectRootFromWorkspaceRoot,\n process.env.NX_TASK_TARGET_TARGET ?? 'build',\n 'tsconfig.generated.json'\n )\n );\n if (!foundTsConfigPath) {\n throw new Error(stripIndents`Unable to find a tsconfig in the workspace! \nThere should at least be a tsconfig.base.json or tsconfig.json in the root of the workspace ${workspaceRoot}`);\n }\n\n if (\n !options.buildLibsFromSource &&\n !global.NX_GRAPH_CREATION &&\n config.mode !== 'test'\n ) {\n const projectGraph = await createProjectGraphAsync({\n exitOnError: false,\n resetDaemonClient: true,\n });\n const { dependencies } = calculateProjectBuildableDependencies(\n undefined,\n projectGraph,\n workspaceRoot,\n process.env.NX_TASK_TARGET_PROJECT,\n // When using incremental building and the serve target is called\n // we need to get the deps for the 'build' target instead.\n process.env.NX_TASK_TARGET_TARGET === 'serve'\n ? 'build'\n : process.env.NX_TASK_TARGET_TARGET,\n process.env.NX_TASK_TARGET_CONFIGURATION\n );\n // This tsconfig is used via the Vite ts paths plugin.\n // It can be also used by other user-defined Vite plugins (e.g. for creating type declaration files).\n foundTsConfigPath = createTmpTsConfig(\n foundTsConfigPath,\n workspaceRoot,\n relative(workspaceRoot, projectRoot),\n dependencies,\n true\n );\n\n if (config.command === 'serve') {\n const buildableLibraryDependencies = dependencies\n .filter((dep) => dep.node.type === 'lib')\n .map((dep) => dep.node.name)\n .join(',');\n const buildCommand = `npx nx run-many --target=${process.env.NX_TASK_TARGET_TARGET} --projects=${buildableLibraryDependencies}`;\n config.plugins.push(nxViteBuildCoordinationPlugin({ buildCommand }));\n }\n }\n\n const parsed = loadConfig(foundTsConfigPath);\n\n logIt('first parsed tsconfig: ', parsed);\n if (parsed.resultType === 'failed') {\n throw new Error(`Failed loading tsconfig at ${foundTsConfigPath}`);\n }\n tsConfigPathsEsm = parsed;\n\n matchTsPathEsm = createMatchPath(\n parsed.absoluteBaseUrl,\n parsed.paths,\n options.mainFields\n );\n\n const rootLevelTsConfig = getTsConfig(\n join(workspaceRoot, 'tsconfig.base.json')\n );\n const rootLevelParsed = loadConfig(rootLevelTsConfig);\n logIt('fallback parsed tsconfig: ', rootLevelParsed);\n if (rootLevelParsed.resultType === 'success') {\n tsConfigPathsFallback = rootLevelParsed;\n matchTsPathFallback = createMatchPath(\n rootLevelParsed.absoluteBaseUrl,\n rootLevelParsed.paths,\n ['main', 'module']\n );\n }\n },\n resolveId(importPath: string) {\n let resolvedFile: string;\n try {\n resolvedFile = matchTsPathEsm(importPath);\n } catch (e) {\n logIt('Using fallback path matching.');\n resolvedFile = matchTsPathFallback?.(importPath);\n }\n\n if (!resolvedFile) {\n if (tsConfigPathsEsm || tsConfigPathsFallback) {\n logIt(\n `Unable to resolve ${importPath} with tsconfig paths. Using fallback file matching.`\n );\n resolvedFile =\n loadFileFromPaths(tsConfigPathsEsm, importPath) ||\n loadFileFromPaths(tsConfigPathsFallback, importPath);\n } else {\n logIt(`Unable to resolve ${importPath} with tsconfig paths`);\n }\n }\n\n logIt(`Resolved ${importPath} to ${resolvedFile}`);\n // Returning null defers to other resolveId functions and eventually the default resolution behavior\n // https://rollupjs.org/plugin-development/#resolveid\n return resolvedFile || null;\n },\n async writeBundle(options) {\n const outDir = options.dir || 'dist';\n const src = resolve(projectRoot, 'package.json');\n if (existsSync(src)) {\n const dest = join(outDir, 'package.json');\n\n try {\n copyFileSync(src, dest);\n } catch (err) {\n console.error('Error copying package.json:', err);\n }\n }\n },\n } as Plugin;\n\n function getTsConfig(preferredTsConfigPath: string): string {\n return [\n resolve(preferredTsConfigPath),\n resolve(join(workspaceRoot, 'tsconfig.base.json')),\n resolve(join(workspaceRoot, 'tsconfig.json')),\n ].find((tsPath) => {\n if (existsSync(tsPath)) {\n logIt('Found tsconfig at', tsPath);\n return tsPath;\n }\n });\n }\n\n function logIt(...msg: any[]) {\n if (process.env.NX_VERBOSE_LOGGING === 'true' || options?.debug) {\n console.debug('\\n[Nx Vite TsPaths]', ...msg);\n }\n }\n\n function loadFileFromPaths(\n tsconfig: ConfigLoaderSuccessResult,\n importPath: string\n ) {\n logIt(\n `Trying to resolve file from config in ${tsconfig.configFileAbsolutePath}`\n );\n let resolvedFile: string;\n for (const alias in tsconfig.paths) {\n const paths = tsconfig.paths[alias];\n\n const normalizedImport = alias.replace(/\\/\\*$/, '');\n\n if (importPath.startsWith(normalizedImport)) {\n const joinedPath = joinPathFragments(\n tsconfig.absoluteBaseUrl,\n paths[0].replace(/\\/\\*$/, '')\n );\n\n resolvedFile = findFile(\n importPath.replace(normalizedImport, joinedPath)\n );\n }\n }\n\n return resolvedFile;\n }\n\n function findFile(path: string): string {\n for (const ext of options.extensions) {\n const resolvedPath = resolve(path + ext);\n if (existsSync(resolvedPath)) {\n return resolvedPath;\n }\n\n const resolvedIndexPath = resolve(path, `index${ext}`);\n if (existsSync(resolvedIndexPath)) {\n return resolvedIndexPath;\n }\n }\n }\n}\n"],"names":["nxViteTsPaths","options","matchTsPathEsm","matchTsPathFallback","tsConfigPathsEsm","tsConfigPathsFallback","extensions","mainFields","buildLibsFromSource","projectRoot","name","configResolved","config","root","projectRootFromWorkspaceRoot","relative","workspaceRoot","process","foundTsConfigPath","getTsConfig","join","env","NX_TASK_TARGET_TARGET","Error","stripIndents","global","NX_GRAPH_CREATION","mode","projectGraph","createProjectGraphAsync","exitOnError","resetDaemonClient","dependencies","calculateProjectBuildableDependencies","undefined","NX_TASK_TARGET_PROJECT","NX_TASK_TARGET_CONFIGURATION","createTmpTsConfig","command","buildableLibraryDependencies","filter","dep","node","type","map","buildCommand","plugins","push","nxViteBuildCoordinationPlugin","parsed","loadConfig","logIt","resultType","createMatchPath","absoluteBaseUrl","paths","rootLevelTsConfig","rootLevelParsed","resolveId","importPath","resolvedFile","e","loadFileFromPaths","writeBundle","outDir","dir","src","resolve","existsSync","dest","copyFileSync","err","console","error","preferredTsConfigPath","find","tsPath","msg","NX_VERBOSE_LOGGING","debug","tsconfig","configFileAbsolutePath","alias","normalizedImport","replace","startsWith","joinedPath","joinPathFragments","findFile","path","ext","resolvedPath","resolvedIndexPath"],"rangeMappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;","mappings":";+BA+CgBA;;;eAAAA;;;wBA1CT;wBACkC;0BACD;+BAMjC;oCAIA;+CAEuC;AA4BvC,SAASA,cAAcC,UAAgC,CAAC,CAAC;QAM9DA,UASAA,WACAA;IAfA,IAAIC;IACJ,IAAIC;IACJ,IAAIC;IACJ,IAAIC;;IAEJJ,gBAAAA,WAAAA,SAAQK,oCAARL,SAAQK,aAAe;QACrB;QACA;QACA;QACA;QACA;QACA;QACA;KACD;;IACDL,gBAAAA,YAAAA,SAAQM,oCAARN,UAAQM,aAAe;QAAC;YAAC;YAAW;YAAK;SAAS;QAAE;QAAU;KAAO;;IACrEN,yBAAAA,YAAAA,SAAQO,sDAARP,UAAQO,sBAAwB;IAChC,IAAIC,cAAc;IAElB,OAAO;QACLC,MAAM;QACN,MAAMC,gBAAeC,MAAW;YAC9BH,cAAcG,OAAOC,IAAI;YACzB,MAAMC,+BAA+BC,IAAAA,kBAAQ,EAACC,qBAAa,EAAEP;gBAMzDQ;YALJ,IAAIC,oBAAoBC,YACtBC,IAAAA,cAAI,EACFJ,qBAAa,EACb,OACAF,8BACAG,CAAAA,qCAAAA,QAAQI,GAAG,CAACC,qBAAqB,YA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AOzF,QAAQK,UAAU,CAAE;YACpC,MAAMqF,eAAexB,IAAAA,iBAAO,EAACsB,OAAOC;YACpC,IAAItB,IAAAA,kBAAU,EAACuB,eAAe;gBAC5B,OAAOA;YACT;YAEA,MAAMC,oBAAoBzB,IAAAA,iBAAO,EAACsB,MAAM,CAAC,KAAK,EAAEC,IAAI,CAAC;YACrD,IAAItB,IAAAA,kBAAU,EAACwB,oBAAoB;gBACjC,OAAOA;YACT;QACF;IACF;AACF"}
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
function _export(target, all) {
|
|
3
|
+
for(var name in all)Object.defineProperty(target, name, {
|
|
4
|
+
enumerable: true,
|
|
5
|
+
get: all[name]
|
|
6
|
+
});
|
|
7
|
+
}
|
|
8
|
+
_export(exports, {
|
|
9
|
+
convertToInferred: function() {
|
|
10
|
+
return convertToInferred;
|
|
11
|
+
},
|
|
12
|
+
default: function() {
|
|
13
|
+
return _default;
|
|
14
|
+
}
|
|
15
|
+
});
|
|
16
|
+
const _devkit = require("@nx/devkit");
|
|
17
|
+
const _executortopluginmigrator = require("@nx/devkit/src/generators/plugin-migrations/executor-to-plugin-migrator");
|
|
18
|
+
const _plugin = require("../../plugins/plugin");
|
|
19
|
+
const _buildposttargettransformer = require("./lib/build-post-target-transformer");
|
|
20
|
+
const _serveposttargettransformer = require("./lib/serve-post-target-transformer");
|
|
21
|
+
const _previewposttargettransformer = require("./lib/preview-post-target-transformer");
|
|
22
|
+
const _testposttargettransformer = require("./lib/test-post-target-transformer");
|
|
23
|
+
const _aggregatelogutil = require("@nx/devkit/src/generators/plugin-migrations/aggregate-log-util");
|
|
24
|
+
async function convertToInferred(tree, options) {
|
|
25
|
+
const projectGraph = await (0, _devkit.createProjectGraphAsync)();
|
|
26
|
+
const migrationLogs = new _aggregatelogutil.AggregatedLog();
|
|
27
|
+
const migratedProjects = await (0, _executortopluginmigrator.migrateProjectExecutorsToPlugin)(tree, projectGraph, '@nx/vite/plugin', _plugin.createNodesV2, {
|
|
28
|
+
buildTargetName: 'build',
|
|
29
|
+
serveTargetName: 'serve',
|
|
30
|
+
previewTargetName: 'preview',
|
|
31
|
+
testTargetName: 'test',
|
|
32
|
+
serveStaticTargetName: 'serve-static'
|
|
33
|
+
}, [
|
|
34
|
+
{
|
|
35
|
+
executors: [
|
|
36
|
+
'@nx/vite:build'
|
|
37
|
+
],
|
|
38
|
+
postTargetTransformer: _buildposttargettransformer.buildPostTargetTransformer,
|
|
39
|
+
targetPluginOptionMapper: (target)=>({
|
|
40
|
+
buildTargetName: target
|
|
41
|
+
})
|
|
42
|
+
},
|
|
43
|
+
{
|
|
44
|
+
executors: [
|
|
45
|
+
'@nx/vite:dev-server'
|
|
46
|
+
],
|
|
47
|
+
postTargetTransformer: (0, _serveposttargettransformer.servePostTargetTransformer)(migrationLogs),
|
|
48
|
+
targetPluginOptionMapper: (target)=>({
|
|
49
|
+
serveTargetName: target
|
|
50
|
+
})
|
|
51
|
+
},
|
|
52
|
+
{
|
|
53
|
+
executors: [
|
|
54
|
+
'@nx/vite:preview-server'
|
|
55
|
+
],
|
|
56
|
+
postTargetTransformer: (0, _previewposttargettransformer.previewPostTargetTransformer)(migrationLogs),
|
|
57
|
+
targetPluginOptionMapper: (target)=>({
|
|
58
|
+
previewTargetName: target
|
|
59
|
+
})
|
|
60
|
+
},
|
|
61
|
+
{
|
|
62
|
+
executors: [
|
|
63
|
+
'@nx/vite:test'
|
|
64
|
+
],
|
|
65
|
+
postTargetTransformer: _testposttargettransformer.testPostTargetTransformer,
|
|
66
|
+
targetPluginOptionMapper: (target)=>({
|
|
67
|
+
testTargetName: target
|
|
68
|
+
})
|
|
69
|
+
}
|
|
70
|
+
], options.project);
|
|
71
|
+
if (migratedProjects.size === 0) {
|
|
72
|
+
throw new Error('Could not find any targets to migrate.');
|
|
73
|
+
}
|
|
74
|
+
if (!options.skipFormat) {
|
|
75
|
+
await (0, _devkit.formatFiles)(tree);
|
|
76
|
+
}
|
|
77
|
+
return ()=>{
|
|
78
|
+
migrationLogs.flushLogs();
|
|
79
|
+
};
|
|
80
|
+
}
|
|
81
|
+
const _default = convertToInferred;
|
|
82
|
+
|
|
83
|
+
//# sourceMappingURL=convert-to-inferred.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../../../packages/vite/src/generators/convert-to-inferred/convert-to-inferred.ts"],"sourcesContent":["import { createProjectGraphAsync, formatFiles, type Tree } from '@nx/devkit';\nimport { migrateProjectExecutorsToPlugin } from '@nx/devkit/src/generators/plugin-migrations/executor-to-plugin-migrator';\nimport { createNodesV2, VitePluginOptions } from '../../plugins/plugin';\nimport { buildPostTargetTransformer } from './lib/build-post-target-transformer';\nimport { servePostTargetTransformer } from './lib/serve-post-target-transformer';\nimport { previewPostTargetTransformer } from './lib/preview-post-target-transformer';\nimport { testPostTargetTransformer } from './lib/test-post-target-transformer';\nimport { AggregatedLog } from '@nx/devkit/src/generators/plugin-migrations/aggregate-log-util';\n\ninterface Schema {\n project?: string;\n skipFormat?: boolean;\n}\n\nexport async function convertToInferred(tree: Tree, options: Schema) {\n const projectGraph = await createProjectGraphAsync();\n const migrationLogs = new AggregatedLog();\n\n const migratedProjects =\n await migrateProjectExecutorsToPlugin<VitePluginOptions>(\n tree,\n projectGraph,\n '@nx/vite/plugin',\n createNodesV2,\n {\n buildTargetName: 'build',\n serveTargetName: 'serve',\n previewTargetName: 'preview',\n testTargetName: 'test',\n serveStaticTargetName: 'serve-static',\n },\n [\n {\n executors: ['@nx/vite:build'],\n postTargetTransformer: buildPostTargetTransformer,\n targetPluginOptionMapper: (target) => ({ buildTargetName: target }),\n },\n {\n executors: ['@nx/vite:dev-server'],\n postTargetTransformer: servePostTargetTransformer(migrationLogs),\n targetPluginOptionMapper: (target) => ({ serveTargetName: target }),\n },\n {\n executors: ['@nx/vite:preview-server'],\n postTargetTransformer: previewPostTargetTransformer(migrationLogs),\n targetPluginOptionMapper: (target) => ({ previewTargetName: target }),\n },\n {\n executors: ['@nx/vite:test'],\n postTargetTransformer: testPostTargetTransformer,\n targetPluginOptionMapper: (target) => ({ testTargetName: target }),\n },\n ],\n options.project\n );\n\n if (migratedProjects.size === 0) {\n throw new Error('Could not find any targets to migrate.');\n }\n\n if (!options.skipFormat) {\n await formatFiles(tree);\n }\n\n return () => {\n migrationLogs.flushLogs();\n };\n}\n\nexport default convertToInferred;\n"],"names":["convertToInferred","tree","options","projectGraph","createProjectGraphAsync","migrationLogs","AggregatedLog","migratedProjects","migrateProjectExecutorsToPlugin","createNodesV2","buildTargetName","serveTargetName","previewTargetName","testTargetName","serveStaticTargetName","executors","postTargetTransformer","buildPostTargetTransformer","targetPluginOptionMapper","target","servePostTargetTransformer","previewPostTargetTransformer","testPostTargetTransformer","project","size","Error","skipFormat","formatFiles","flushLogs"],"rangeMappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;","mappings":";;;;;;;;IAcsBA,iBAAiB;eAAjBA;;IAuDtB,OAAiC;eAAjC;;;wBArEgE;0CAChB;wBACC;4CACN;4CACA;8CACE;2CACH;kCACZ;AAOvB,eAAeA,kBAAkBC,IAAU,EAAEC,OAAe;IACjE,MAAMC,eAAe,MAAMC,IAAAA,+BAAuB;IAClD,MAAMC,gBAAgB,IAAIC,+BAAa;IAEvC,MAAMC,mBACJ,MAAMC,IAAAA,yDAA+B,EACnCP,MACAE,cACA,mBACAM,qBAAa,EACb;QACEC,iBAAiB;QACjBC,iBAAiB;QACjBC,mBAAmB;QACnBC,gBAAgB;QAChBC,uBAAuB;IACzB,GACA;QACE;YACEC,WAAW;gBAAC;aAAiB;YAC7BC,uBAAuBC,sDAA0B;YACjDC,0BAA0B,CAACC,SAAY,CAAA;oBAAET,iBAAiBS;gBAAO,CAAA;QACnE;QACA;YACEJ,WAAW;gBAAC;aAAsB;YAClCC,uBAAuBI,IAAAA,sDAA0B,EAACf;YAClDa,0BAA0B,CAACC,SAAY,CAAA;oBAAER,iBAAiBQ;gBAAO,CAAA;QACnE;QACA;YACEJ,WAAW;gBAAC;aAA0B;YACtCC,uBAAuBK,IAAAA,0DAA4B,EAAChB;YACpDa,0BAA0B,CAACC,SAAY,CAAA;oBAAEP,mBAAmBO;gBAAO,CAAA;QACrE;QACA;YACEJ,WAAW;gBAAC;aAAgB;YAC5BC,uBAAuBM,oDAAyB;YAChDJ,0BAA0B,CAACC,SAAY,CAAA;oBAAEN,gBAAgBM;gBAAO,CAAA;QAClE;KACD,EACDjB,QAAQqB,OAAO;IAGnB,IAAIhB,iBAAiBiB,IAAI,KAAK,GAAG;QAC/B,MAAM,IAAIC,MAAM;IAClB;IAEA,IAAI,CAACvB,QAAQwB,UAAU,EAAE;QACvB,MAAMC,IAAAA,mBAAW,EAAC1B;IACpB;IAEA,OAAO;QACLI,cAAcuB,SAAS;IACzB;AACF;MAEA,WAAe5B"}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { type TargetConfiguration, type Tree } from '@nx/devkit';
|
|
2
|
+
export declare function buildPostTargetTransformer(target: TargetConfiguration, tree: Tree, projectDetails: {
|
|
3
|
+
projectName: string;
|
|
4
|
+
root: string;
|
|
5
|
+
}, inferredTargetConfiguration: TargetConfiguration): TargetConfiguration<any>;
|
|
6
|
+
export declare function moveBuildLibsFromSourceToViteConfig(tree: Tree, configPath: string): void;
|
|
@@ -0,0 +1,160 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
function _export(target, all) {
|
|
3
|
+
for(var name in all)Object.defineProperty(target, name, {
|
|
4
|
+
enumerable: true,
|
|
5
|
+
get: all[name]
|
|
6
|
+
});
|
|
7
|
+
}
|
|
8
|
+
_export(exports, {
|
|
9
|
+
buildPostTargetTransformer: function() {
|
|
10
|
+
return buildPostTargetTransformer;
|
|
11
|
+
},
|
|
12
|
+
moveBuildLibsFromSourceToViteConfig: function() {
|
|
13
|
+
return moveBuildLibsFromSourceToViteConfig;
|
|
14
|
+
}
|
|
15
|
+
});
|
|
16
|
+
const _devkit = require("@nx/devkit");
|
|
17
|
+
const _tsquery = require("@phenomnomnominal/tsquery");
|
|
18
|
+
const _posix = require("path/posix");
|
|
19
|
+
const _utils = require("./utils");
|
|
20
|
+
const _pluginmigrationutils = require("@nx/devkit/src/generators/plugin-migrations/plugin-migration-utils");
|
|
21
|
+
function buildPostTargetTransformer(target, tree, projectDetails, inferredTargetConfiguration) {
|
|
22
|
+
let viteConfigPath = (0, _utils.getViteConfigPath)(tree, projectDetails.root);
|
|
23
|
+
const configValues = {
|
|
24
|
+
default: {}
|
|
25
|
+
};
|
|
26
|
+
if (target.configurations) {
|
|
27
|
+
for(const configurationName in target.configurations){
|
|
28
|
+
const configuration = target.configurations[configurationName];
|
|
29
|
+
configValues[configurationName] = {};
|
|
30
|
+
let configurationConfigFile = viteConfigPath;
|
|
31
|
+
if (configuration.configFile) {
|
|
32
|
+
if ('buildLibsFromSource' in target.options) {
|
|
33
|
+
configuration.buildLibsFromSource = target.options.buildLibsFromSource;
|
|
34
|
+
}
|
|
35
|
+
configurationConfigFile = configuration.configFile;
|
|
36
|
+
}
|
|
37
|
+
removePropertiesFromTargetOptions(tree, configuration, configurationConfigFile, projectDetails.root, configValues[configurationName], configuration.configFile && configuration.configFile !== viteConfigPath);
|
|
38
|
+
}
|
|
39
|
+
for(const configurationName in target.configurations){
|
|
40
|
+
const configuration = target.configurations[configurationName];
|
|
41
|
+
if (configuration.config && configuration.config !== (0, _utils.toProjectRelativePath)(viteConfigPath, projectDetails.root)) {
|
|
42
|
+
const configFilePath = (0, _devkit.joinPathFragments)(projectDetails.root, configuration.config);
|
|
43
|
+
(0, _utils.addConfigValuesToViteConfig)(tree, configFilePath, configValues);
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
if (Object.keys(target.configurations).length === 0) {
|
|
47
|
+
if ('defaultConfiguration' in target) {
|
|
48
|
+
delete target.defaultConfiguration;
|
|
49
|
+
}
|
|
50
|
+
delete target.configurations;
|
|
51
|
+
}
|
|
52
|
+
if ('defaultConfiguration' in target && !target.configurations[target.defaultConfiguration]) {
|
|
53
|
+
delete target.defaultConfiguration;
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
if (target.options) {
|
|
57
|
+
if (target.options.configFile) {
|
|
58
|
+
viteConfigPath = target.options.configFile;
|
|
59
|
+
}
|
|
60
|
+
removePropertiesFromTargetOptions(tree, target.options, viteConfigPath, projectDetails.root, configValues['default'], true);
|
|
61
|
+
}
|
|
62
|
+
if (target.outputs) {
|
|
63
|
+
(0, _pluginmigrationutils.processTargetOutputs)(target, [
|
|
64
|
+
{
|
|
65
|
+
newName: 'outDir',
|
|
66
|
+
oldName: 'outputPath'
|
|
67
|
+
}
|
|
68
|
+
], inferredTargetConfiguration, {
|
|
69
|
+
projectName: projectDetails.projectName,
|
|
70
|
+
projectRoot: projectDetails.root
|
|
71
|
+
});
|
|
72
|
+
}
|
|
73
|
+
if (target.inputs && target.inputs.every((i)=>i === 'production' || i === '^production')) {
|
|
74
|
+
delete target.inputs;
|
|
75
|
+
}
|
|
76
|
+
(0, _utils.addConfigValuesToViteConfig)(tree, viteConfigPath, configValues);
|
|
77
|
+
return target;
|
|
78
|
+
}
|
|
79
|
+
function removePropertiesFromTargetOptions(tree, targetOptions, viteConfigPath, projectRoot, configValues, needsAstTransform = false) {
|
|
80
|
+
if ('configFile' in targetOptions) {
|
|
81
|
+
targetOptions.config = (0, _utils.toProjectRelativePath)(targetOptions.configFile, projectRoot);
|
|
82
|
+
delete targetOptions.configFile;
|
|
83
|
+
}
|
|
84
|
+
if (targetOptions.outputPath) {
|
|
85
|
+
targetOptions.outDir = (0, _utils.toProjectRelativePath)(targetOptions.outputPath, projectRoot);
|
|
86
|
+
delete targetOptions.outputPath;
|
|
87
|
+
}
|
|
88
|
+
if ('buildLibsFromSource' in targetOptions) {
|
|
89
|
+
configValues['buildLibsFromSource'] = targetOptions.buildLibsFromSource;
|
|
90
|
+
if (needsAstTransform) {
|
|
91
|
+
moveBuildLibsFromSourceToViteConfig(tree, viteConfigPath);
|
|
92
|
+
}
|
|
93
|
+
delete targetOptions.buildLibsFromSource;
|
|
94
|
+
}
|
|
95
|
+
if ('skipTypeCheck' in targetOptions) {
|
|
96
|
+
delete targetOptions.skipTypeCheck;
|
|
97
|
+
}
|
|
98
|
+
if ('generatePackageJson' in targetOptions) {
|
|
99
|
+
delete targetOptions.generatePackageJson;
|
|
100
|
+
}
|
|
101
|
+
if ('includeDevDependenciesInPackageJson' in targetOptions) {
|
|
102
|
+
delete targetOptions.includeDevDependenciesInPackageJson;
|
|
103
|
+
}
|
|
104
|
+
if ('tsConfig' in targetOptions) {
|
|
105
|
+
delete targetOptions.tsConfig;
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
function moveBuildLibsFromSourceToViteConfig(tree, configPath) {
|
|
109
|
+
const PLUGINS_PROPERTY_SELECTOR = 'PropertyAssignment:has(Identifier[name=plugins])';
|
|
110
|
+
const PLUGINS_NX_VITE_TS_PATHS_SELECTOR = 'PropertyAssignment:has(Identifier[name=plugins]) CallExpression:has(Identifier[name=nxViteTsPaths])';
|
|
111
|
+
const BUILD_LIBS_FROM_SOURCE_SELECTOR = 'PropertyAssignment:has(Identifier[name=plugins]) CallExpression:has(Identifier[name=nxViteTsPaths]) ObjectLiteralExpression > PropertyAssignment:has(Identifier[name=buildLibsFromSource])';
|
|
112
|
+
const nxViteTsPathsImport = (0, _posix.extname)(configPath) === 'js' ? 'const {nxViteTsPaths} = require("@nx/vite/plugins/nx-tsconfig-paths.plugin");' : 'import { nxViteTsPaths } from "@nx/vite/plugins/nx-tsconfig-paths.plugin";';
|
|
113
|
+
const plugin = `nxViteTsPaths({ buildLibsFromSource: options.buildLibsFromSource }),`;
|
|
114
|
+
const viteConfigContents = tree.read(configPath, 'utf-8');
|
|
115
|
+
let newViteConfigContents = viteConfigContents;
|
|
116
|
+
const ast = _tsquery.tsquery.ast(viteConfigContents);
|
|
117
|
+
const buildLibsFromSourceNodes = (0, _tsquery.tsquery)(ast, BUILD_LIBS_FROM_SOURCE_SELECTOR, {
|
|
118
|
+
visitAllChildren: true
|
|
119
|
+
});
|
|
120
|
+
if (buildLibsFromSourceNodes.length > 0) {
|
|
121
|
+
return;
|
|
122
|
+
}
|
|
123
|
+
const nxViteTsPathsNodes = (0, _tsquery.tsquery)(ast, PLUGINS_NX_VITE_TS_PATHS_SELECTOR, {
|
|
124
|
+
visitAllChildren: true
|
|
125
|
+
});
|
|
126
|
+
if (nxViteTsPathsNodes.length === 0) {
|
|
127
|
+
const pluginsNodes = (0, _tsquery.tsquery)(ast, PLUGINS_PROPERTY_SELECTOR, {
|
|
128
|
+
visitAllChildren: true
|
|
129
|
+
});
|
|
130
|
+
if (pluginsNodes.length === 0) {
|
|
131
|
+
// Add plugin property
|
|
132
|
+
const configNodes = (0, _tsquery.tsquery)(ast, 'CallExpression:has(Identifier[name=defineConfig]) > ObjectLiteralExpression', {
|
|
133
|
+
visitAllChildren: true
|
|
134
|
+
});
|
|
135
|
+
if (configNodes.length === 0) {
|
|
136
|
+
return;
|
|
137
|
+
}
|
|
138
|
+
newViteConfigContents = `${nxViteTsPathsImport}\n${viteConfigContents.slice(0, configNodes[0].getStart() + 1)}plugins: [${plugin}],${viteConfigContents.slice(configNodes[0].getStart() + 1)}`;
|
|
139
|
+
} else {
|
|
140
|
+
// Add nxViteTsPaths plugin
|
|
141
|
+
const pluginsArrayNodes = (0, _tsquery.tsquery)(pluginsNodes[0], 'ArrayLiteralExpression');
|
|
142
|
+
if (pluginsArrayNodes.length === 0) {
|
|
143
|
+
return;
|
|
144
|
+
}
|
|
145
|
+
newViteConfigContents = `${nxViteTsPathsImport}\n${viteConfigContents.slice(0, pluginsArrayNodes[0].getStart() + 1)}${plugin}${viteConfigContents.slice(pluginsArrayNodes[0].getStart() + 1)}`;
|
|
146
|
+
}
|
|
147
|
+
} else {
|
|
148
|
+
const pluginOptionsNodes = (0, _tsquery.tsquery)(nxViteTsPathsNodes[0], 'ObjectLiteralExpression');
|
|
149
|
+
if (pluginOptionsNodes.length === 0) {
|
|
150
|
+
// Add the options
|
|
151
|
+
newViteConfigContents = `${viteConfigContents.slice(0, nxViteTsPathsNodes[0].getStart())}${plugin}${viteConfigContents.slice(nxViteTsPathsNodes[0].getEnd())}`;
|
|
152
|
+
} else {
|
|
153
|
+
// update the object
|
|
154
|
+
newViteConfigContents = `${viteConfigContents.slice(0, pluginOptionsNodes[0].getStart() + 1)}buildLibsFromSource: options.buildLibsFromSource, ${viteConfigContents.slice(pluginOptionsNodes[0].getStart() + 1)}`;
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
tree.write(configPath, newViteConfigContents);
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
//# sourceMappingURL=build-post-target-transformer.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../../../../packages/vite/src/generators/convert-to-inferred/lib/build-post-target-transformer.ts"],"sourcesContent":["import {\n joinPathFragments,\n type TargetConfiguration,\n type Tree,\n} from '@nx/devkit';\nimport { tsquery } from '@phenomnomnominal/tsquery';\nimport { extname } from 'path/posix';\nimport {\n addConfigValuesToViteConfig,\n getViteConfigPath,\n toProjectRelativePath,\n} from './utils';\nimport { processTargetOutputs } from '@nx/devkit/src/generators/plugin-migrations/plugin-migration-utils';\n\nexport function buildPostTargetTransformer(\n target: TargetConfiguration,\n tree: Tree,\n projectDetails: { projectName: string; root: string },\n inferredTargetConfiguration: TargetConfiguration\n) {\n let viteConfigPath = getViteConfigPath(tree, projectDetails.root);\n\n const configValues: Record<string, Record<string, unknown>> = {\n default: {},\n };\n\n if (target.configurations) {\n for (const configurationName in target.configurations) {\n const configuration = target.configurations[configurationName];\n configValues[configurationName] = {};\n let configurationConfigFile = viteConfigPath;\n if (configuration.configFile) {\n if ('buildLibsFromSource' in target.options) {\n configuration.buildLibsFromSource =\n target.options.buildLibsFromSource;\n }\n\n configurationConfigFile = configuration.configFile;\n }\n\n removePropertiesFromTargetOptions(\n tree,\n configuration,\n configurationConfigFile,\n projectDetails.root,\n configValues[configurationName],\n configuration.configFile && configuration.configFile !== viteConfigPath\n );\n }\n\n for (const configurationName in target.configurations) {\n const configuration = target.configurations[configurationName];\n if (\n configuration.config &&\n configuration.config !==\n toProjectRelativePath(viteConfigPath, projectDetails.root)\n ) {\n const configFilePath = joinPathFragments(\n projectDetails.root,\n configuration.config\n );\n addConfigValuesToViteConfig(tree, configFilePath, configValues);\n }\n }\n\n if (Object.keys(target.configurations).length === 0) {\n if ('defaultConfiguration' in target) {\n delete target.defaultConfiguration;\n }\n delete target.configurations;\n }\n\n if (\n 'defaultConfiguration' in target &&\n !target.configurations[target.defaultConfiguration]\n ) {\n delete target.defaultConfiguration;\n }\n }\n\n if (target.options) {\n if (target.options.configFile) {\n viteConfigPath = target.options.configFile;\n }\n\n removePropertiesFromTargetOptions(\n tree,\n target.options,\n viteConfigPath,\n projectDetails.root,\n configValues['default'],\n true\n );\n }\n\n if (target.outputs) {\n processTargetOutputs(\n target,\n [{ newName: 'outDir', oldName: 'outputPath' }],\n inferredTargetConfiguration,\n {\n projectName: projectDetails.projectName,\n projectRoot: projectDetails.root,\n }\n );\n }\n\n if (\n target.inputs &&\n target.inputs.every((i) => i === 'production' || i === '^production')\n ) {\n delete target.inputs;\n }\n\n addConfigValuesToViteConfig(tree, viteConfigPath, configValues);\n\n return target;\n}\n\nfunction removePropertiesFromTargetOptions(\n tree: Tree,\n targetOptions: any,\n viteConfigPath: string,\n projectRoot: string,\n configValues: Record<string, unknown>,\n needsAstTransform = false\n) {\n if ('configFile' in targetOptions) {\n targetOptions.config = toProjectRelativePath(\n targetOptions.configFile,\n projectRoot\n );\n delete targetOptions.configFile;\n }\n if (targetOptions.outputPath) {\n targetOptions.outDir = toProjectRelativePath(\n targetOptions.outputPath,\n projectRoot\n );\n\n delete targetOptions.outputPath;\n }\n if ('buildLibsFromSource' in targetOptions) {\n configValues['buildLibsFromSource'] = targetOptions.buildLibsFromSource;\n\n if (needsAstTransform) {\n moveBuildLibsFromSourceToViteConfig(tree, viteConfigPath);\n }\n delete targetOptions.buildLibsFromSource;\n }\n if ('skipTypeCheck' in targetOptions) {\n delete targetOptions.skipTypeCheck;\n }\n if ('generatePackageJson' in targetOptions) {\n delete targetOptions.generatePackageJson;\n }\n if ('includeDevDependenciesInPackageJson' in targetOptions) {\n delete targetOptions.includeDevDependenciesInPackageJson;\n }\n if ('tsConfig' in targetOptions) {\n delete targetOptions.tsConfig;\n }\n}\n\nexport function moveBuildLibsFromSourceToViteConfig(\n tree: Tree,\n configPath: string\n) {\n const PLUGINS_PROPERTY_SELECTOR =\n 'PropertyAssignment:has(Identifier[name=plugins])';\n const PLUGINS_NX_VITE_TS_PATHS_SELECTOR =\n 'PropertyAssignment:has(Identifier[name=plugins]) CallExpression:has(Identifier[name=nxViteTsPaths])';\n const BUILD_LIBS_FROM_SOURCE_SELECTOR =\n 'PropertyAssignment:has(Identifier[name=plugins]) CallExpression:has(Identifier[name=nxViteTsPaths]) ObjectLiteralExpression > PropertyAssignment:has(Identifier[name=buildLibsFromSource])';\n\n const nxViteTsPathsImport =\n extname(configPath) === 'js'\n ? 'const {nxViteTsPaths} = require(\"@nx/vite/plugins/nx-tsconfig-paths.plugin\");'\n : 'import { nxViteTsPaths } from \"@nx/vite/plugins/nx-tsconfig-paths.plugin\";';\n const plugin = `nxViteTsPaths({ buildLibsFromSource: options.buildLibsFromSource }),`;\n\n const viteConfigContents = tree.read(configPath, 'utf-8');\n let newViteConfigContents = viteConfigContents;\n\n const ast = tsquery.ast(viteConfigContents);\n const buildLibsFromSourceNodes = tsquery(\n ast,\n BUILD_LIBS_FROM_SOURCE_SELECTOR,\n { visitAllChildren: true }\n );\n if (buildLibsFromSourceNodes.length > 0) {\n return;\n }\n\n const nxViteTsPathsNodes = tsquery(ast, PLUGINS_NX_VITE_TS_PATHS_SELECTOR, {\n visitAllChildren: true,\n });\n if (nxViteTsPathsNodes.length === 0) {\n const pluginsNodes = tsquery(ast, PLUGINS_PROPERTY_SELECTOR, {\n visitAllChildren: true,\n });\n if (pluginsNodes.length === 0) {\n // Add plugin property\n const configNodes = tsquery(\n ast,\n 'CallExpression:has(Identifier[name=defineConfig]) > ObjectLiteralExpression',\n { visitAllChildren: true }\n );\n if (configNodes.length === 0) {\n return;\n }\n\n newViteConfigContents = `${nxViteTsPathsImport}\\n${viteConfigContents.slice(\n 0,\n configNodes[0].getStart() + 1\n )}plugins: [${plugin}],${viteConfigContents.slice(\n configNodes[0].getStart() + 1\n )}`;\n } else {\n // Add nxViteTsPaths plugin\n\n const pluginsArrayNodes = tsquery(\n pluginsNodes[0],\n 'ArrayLiteralExpression'\n );\n if (pluginsArrayNodes.length === 0) {\n return;\n }\n\n newViteConfigContents = `${nxViteTsPathsImport}\\n${viteConfigContents.slice(\n 0,\n pluginsArrayNodes[0].getStart() + 1\n )}${plugin}${viteConfigContents.slice(\n pluginsArrayNodes[0].getStart() + 1\n )}`;\n }\n } else {\n const pluginOptionsNodes = tsquery(\n nxViteTsPathsNodes[0],\n 'ObjectLiteralExpression'\n );\n if (pluginOptionsNodes.length === 0) {\n // Add the options\n newViteConfigContents = `${viteConfigContents.slice(\n 0,\n nxViteTsPathsNodes[0].getStart()\n )}${plugin}${viteConfigContents.slice(nxViteTsPathsNodes[0].getEnd())}`;\n } else {\n // update the object\n newViteConfigContents = `${viteConfigContents.slice(\n 0,\n pluginOptionsNodes[0].getStart() + 1\n )}buildLibsFromSource: options.buildLibsFromSource, ${viteConfigContents.slice(\n pluginOptionsNodes[0].getStart() + 1\n )}`;\n }\n }\n\n tree.write(configPath, newViteConfigContents);\n}\n"],"names":["buildPostTargetTransformer","moveBuildLibsFromSourceToViteConfig","target","tree","projectDetails","inferredTargetConfiguration","viteConfigPath","getViteConfigPath","root","configValues","default","configurations","configurationName","configuration","configurationConfigFile","configFile","options","buildLibsFromSource","removePropertiesFromTargetOptions","config","toProjectRelativePath","configFilePath","joinPathFragments","addConfigValuesToViteConfig","Object","keys","length","defaultConfiguration","outputs","processTargetOutputs","newName","oldName","projectName","projectRoot","inputs","every","i","targetOptions","needsAstTransform","outputPath","outDir","skipTypeCheck","generatePackageJson","includeDevDependenciesInPackageJson","tsConfig","configPath","PLUGINS_PROPERTY_SELECTOR","PLUGINS_NX_VITE_TS_PATHS_SELECTOR","BUILD_LIBS_FROM_SOURCE_SELECTOR","nxViteTsPathsImport","extname","plugin","viteConfigContents","read","newViteConfigContents","ast","tsquery","buildLibsFromSourceNodes","visitAllChildren","nxViteTsPathsNodes","pluginsNodes","configNodes","slice","getStart","pluginsArrayNodes","pluginOptionsNodes","getEnd","write"],"rangeMappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;","mappings":";;;;;;;;IAcgBA,0BAA0B;eAA1BA;;IAsJAC,mCAAmC;eAAnCA;;;wBAhKT;yBACiB;uBACA;uBAKjB;sCAC8B;AAE9B,SAASD,2BACdE,MAA2B,EAC3BC,IAAU,EACVC,cAAqD,EACrDC,2BAAgD;IAEhD,IAAIC,iBAAiBC,IAAAA,wBAAiB,EAACJ,MAAMC,eAAeI,IAAI;IAEhE,MAAMC,eAAwD;QAC5DC,SAAS,CAAC;IACZ;IAEA,IAAIR,OAAOS,cAAc,EAAE;QACzB,IAAK,MAAMC,qBAAqBV,OAAOS,cAAc,CAAE;YACrD,MAAME,gBAAgBX,OAAOS,cAAc,CAACC,kBAAkB;YAC9DH,YAAY,CAACG,kBAAkB,GAAG,CAAC;YACnC,IAAIE,0BAA0BR;YAC9B,IAAIO,cAAcE,UAAU,EAAE;gBAC5B,IAAI,yBAAyBb,OAAOc,OAAO,EAAE;oBAC3CH,cAAcI,mBAAmB,GAC/Bf,OAAOc,OAAO,CAACC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QAAQ,KAAK,GAClC,CAAC;QACL;IACF,OAAO;QACL,MAAME,qBAAqBT,IAAAA,gBAAO,EAChCG,kBAAkB,CAAC,EAAE,EACrB;QAEF,IAAIM,mBAAmBvC,MAAM,KAAK,GAAG;YACnC,kBAAkB;YAClB4B,wBAAwB,CAAC,EAAEF,mBAAmBU,KAAK,CACjD,GACAH,kBAAkB,CAAC,EAAE,CAACI,QAAQ,IAC9B,EAAEZ,OAAO,EAAEC,mBAAmBU,KAAK,CAACH,kBAAkB,CAAC,EAAE,CAACO,MAAM,IAAI,CAAC;QACzE,OAAO;YACL,oBAAoB;YACpBZ,wBAAwB,CAAC,EAAEF,mBAAmBU,KAAK,CACjD,GACAG,kBAAkB,CAAC,EAAE,CAACF,QAAQ,KAAK,GACnC,kDAAkD,EAAEX,mBAAmBU,KAAK,CAC5EG,kBAAkB,CAAC,EAAE,CAACF,QAAQ,KAAK,GACnC,CAAC;QACL;IACF;IAEA5D,KAAKgE,KAAK,CAACtB,YAAYS;AACzB"}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { type TargetConfiguration, type Tree } from '@nx/devkit';
|
|
2
|
+
import { AggregatedLog } from '@nx/devkit/src/generators/plugin-migrations/aggregate-log-util';
|
|
3
|
+
export declare function previewPostTargetTransformer(migrationLogs: AggregatedLog): (target: TargetConfiguration, tree: Tree, projectDetails: {
|
|
4
|
+
projectName: string;
|
|
5
|
+
root: string;
|
|
6
|
+
}, inferredTargetConfiguration: TargetConfiguration) => TargetConfiguration<any>;
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "previewPostTargetTransformer", {
|
|
3
|
+
enumerable: true,
|
|
4
|
+
get: function() {
|
|
5
|
+
return previewPostTargetTransformer;
|
|
6
|
+
}
|
|
7
|
+
});
|
|
8
|
+
const _utils = require("./utils");
|
|
9
|
+
function previewPostTargetTransformer(migrationLogs) {
|
|
10
|
+
return (target, tree, projectDetails, inferredTargetConfiguration)=>{
|
|
11
|
+
const viteConfigPath = (0, _utils.getViteConfigPath)(tree, projectDetails.root);
|
|
12
|
+
if (target.options) {
|
|
13
|
+
removePropertiesFromTargetOptions(target.options, projectDetails.projectName, migrationLogs);
|
|
14
|
+
}
|
|
15
|
+
if (target.configurations) {
|
|
16
|
+
for(const configurationName in target.configurations){
|
|
17
|
+
const configuration = target.configurations[configurationName];
|
|
18
|
+
removePropertiesFromTargetOptions(configuration, projectDetails.projectName, migrationLogs);
|
|
19
|
+
}
|
|
20
|
+
if (Object.keys(target.configurations).length === 0) {
|
|
21
|
+
if ('defaultConfiguration' in target) {
|
|
22
|
+
delete target.defaultConfiguration;
|
|
23
|
+
}
|
|
24
|
+
delete target.configurations;
|
|
25
|
+
}
|
|
26
|
+
if ('defaultConfiguration' in target && !target.configurations[target.defaultConfiguration]) {
|
|
27
|
+
delete target.defaultConfiguration;
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
return target;
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
function removePropertiesFromTargetOptions(targetOptions, projectName, migrationLogs) {
|
|
34
|
+
if ('buildTarget' in targetOptions) {
|
|
35
|
+
delete targetOptions.buildTarget;
|
|
36
|
+
}
|
|
37
|
+
if ('staticFilePath' in targetOptions) {
|
|
38
|
+
delete targetOptions.staticFilePath;
|
|
39
|
+
}
|
|
40
|
+
if ('proxyConfig' in targetOptions) {
|
|
41
|
+
migrationLogs.addLog({
|
|
42
|
+
executorName: '@nx/vite:preview-server',
|
|
43
|
+
project: projectName,
|
|
44
|
+
log: `Encountered 'proxyConfig' in project.json. You will need to copy the contents of this file to the 'server.proxy' property in your Vite config file.`
|
|
45
|
+
});
|
|
46
|
+
delete targetOptions.proxyConfig;
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
//# sourceMappingURL=preview-post-target-transformer.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../../../../packages/vite/src/generators/convert-to-inferred/lib/preview-post-target-transformer.ts"],"sourcesContent":["import { type TargetConfiguration, type Tree } from '@nx/devkit';\nimport { getViteConfigPath } from './utils';\nimport { AggregatedLog } from '@nx/devkit/src/generators/plugin-migrations/aggregate-log-util';\n\nexport function previewPostTargetTransformer(migrationLogs: AggregatedLog) {\n return (\n target: TargetConfiguration,\n tree: Tree,\n projectDetails: { projectName: string; root: string },\n inferredTargetConfiguration: TargetConfiguration\n ) => {\n const viteConfigPath = getViteConfigPath(tree, projectDetails.root);\n\n if (target.options) {\n removePropertiesFromTargetOptions(\n target.options,\n projectDetails.projectName,\n migrationLogs\n );\n }\n\n if (target.configurations) {\n for (const configurationName in target.configurations) {\n const configuration = target.configurations[configurationName];\n removePropertiesFromTargetOptions(\n configuration,\n projectDetails.projectName,\n migrationLogs\n );\n }\n\n if (Object.keys(target.configurations).length === 0) {\n if ('defaultConfiguration' in target) {\n delete target.defaultConfiguration;\n }\n delete target.configurations;\n }\n\n if (\n 'defaultConfiguration' in target &&\n !target.configurations[target.defaultConfiguration]\n ) {\n delete target.defaultConfiguration;\n }\n }\n\n return target;\n };\n}\n\nfunction removePropertiesFromTargetOptions(\n targetOptions: any,\n projectName: string,\n migrationLogs: AggregatedLog\n) {\n if ('buildTarget' in targetOptions) {\n delete targetOptions.buildTarget;\n }\n\n if ('staticFilePath' in targetOptions) {\n delete targetOptions.staticFilePath;\n }\n\n if ('proxyConfig' in targetOptions) {\n migrationLogs.addLog({\n executorName: '@nx/vite:preview-server',\n project: projectName,\n log: `Encountered 'proxyConfig' in project.json. You will need to copy the contents of this file to the 'server.proxy' property in your Vite config file.`,\n });\n delete targetOptions.proxyConfig;\n }\n}\n"],"names":["previewPostTargetTransformer","migrationLogs","target","tree","projectDetails","inferredTargetConfiguration","viteConfigPath","getViteConfigPath","root","options","removePropertiesFromTargetOptions","projectName","configurations","configurationName","configuration","Object","keys","length","defaultConfiguration","targetOptions","buildTarget","staticFilePath","addLog","executorName","project","log","proxyConfig"],"r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} from '@nx/devkit';
|
|
2
|
+
import { AggregatedLog } from '@nx/devkit/src/generators/plugin-migrations/aggregate-log-util';
|
|
3
|
+
export declare function servePostTargetTransformer(migrationLogs: AggregatedLog): (target: TargetConfiguration, tree: Tree, projectDetails: {
|
|
4
|
+
projectName: string;
|
|
5
|
+
root: string;
|
|
6
|
+
}, inferredTargetConfiguration: TargetConfiguration) => TargetConfiguration<any>;
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "servePostTargetTransformer", {
|
|
3
|
+
enumerable: true,
|
|
4
|
+
get: function() {
|
|
5
|
+
return servePostTargetTransformer;
|
|
6
|
+
}
|
|
7
|
+
});
|
|
8
|
+
const _utils = require("./utils");
|
|
9
|
+
function servePostTargetTransformer(migrationLogs) {
|
|
10
|
+
return (target, tree, projectDetails, inferredTargetConfiguration)=>{
|
|
11
|
+
const viteConfigPath = (0, _utils.getViteConfigPath)(tree, projectDetails.root);
|
|
12
|
+
if (target.options) {
|
|
13
|
+
removePropertiesFromTargetOptions(tree, target.options, viteConfigPath, projectDetails.root, projectDetails.projectName, migrationLogs, true);
|
|
14
|
+
}
|
|
15
|
+
if (target.configurations) {
|
|
16
|
+
for(const configurationName in target.configurations){
|
|
17
|
+
const configuration = target.configurations[configurationName];
|
|
18
|
+
removePropertiesFromTargetOptions(tree, configuration, viteConfigPath, projectDetails.root, projectDetails.projectName, migrationLogs);
|
|
19
|
+
}
|
|
20
|
+
if (Object.keys(target.configurations).length === 0) {
|
|
21
|
+
if ('defaultConfiguration' in target) {
|
|
22
|
+
delete target.defaultConfiguration;
|
|
23
|
+
}
|
|
24
|
+
delete target.configurations;
|
|
25
|
+
}
|
|
26
|
+
if ('defaultConfiguration' in target && !target.configurations[target.defaultConfiguration]) {
|
|
27
|
+
delete target.defaultConfiguration;
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
return target;
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
function removePropertiesFromTargetOptions(tree, targetOptions, viteConfigPath, projectRoot, projectName, migrationLogs, defaultOptions = false) {
|
|
34
|
+
if ('buildTarget' in targetOptions) {
|
|
35
|
+
delete targetOptions.buildTarget;
|
|
36
|
+
}
|
|
37
|
+
if ('buildLibsFromSource' in targetOptions) {
|
|
38
|
+
migrationLogs.addLog({
|
|
39
|
+
executorName: '@nx/vite:dev-server',
|
|
40
|
+
project: projectName,
|
|
41
|
+
log: `Encountered 'buildLibsFromSource' in project.json. This property will be added to your Vite config file via the '@nx/vite:build' executor migration.`
|
|
42
|
+
});
|
|
43
|
+
delete targetOptions.buildLibsFromSource;
|
|
44
|
+
}
|
|
45
|
+
if ('hmr' in targetOptions) {
|
|
46
|
+
delete targetOptions.hmr;
|
|
47
|
+
}
|
|
48
|
+
if ('proxyConfig' in targetOptions) {
|
|
49
|
+
migrationLogs.addLog({
|
|
50
|
+
executorName: '@nx/vite:dev-server',
|
|
51
|
+
project: projectName,
|
|
52
|
+
log: `Encountered 'proxyConfig' in project.json. You will need to copy the contents of this file to the 'server.proxy' property in your Vite config file.`
|
|
53
|
+
});
|
|
54
|
+
delete targetOptions.proxyConfig;
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
//# sourceMappingURL=serve-post-target-transformer.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../../../../packages/vite/src/generators/convert-to-inferred/lib/serve-post-target-transformer.ts"],"sourcesContent":["import { type TargetConfiguration, type Tree } from '@nx/devkit';\nimport { getViteConfigPath } from './utils';\nimport { AggregatedLog } from '@nx/devkit/src/generators/plugin-migrations/aggregate-log-util';\n\nexport function servePostTargetTransformer(migrationLogs: AggregatedLog) {\n return (\n target: TargetConfiguration,\n tree: Tree,\n projectDetails: { projectName: string; root: string },\n inferredTargetConfiguration: TargetConfiguration\n ) => {\n const viteConfigPath = getViteConfigPath(tree, projectDetails.root);\n\n if (target.options) {\n removePropertiesFromTargetOptions(\n tree,\n target.options,\n viteConfigPath,\n projectDetails.root,\n projectDetails.projectName,\n migrationLogs,\n true\n );\n }\n\n if (target.configurations) {\n for (const configurationName in target.configurations) {\n const configuration = target.configurations[configurationName];\n removePropertiesFromTargetOptions(\n tree,\n configuration,\n viteConfigPath,\n projectDetails.root,\n projectDetails.projectName,\n migrationLogs\n );\n }\n\n if (Object.keys(target.configurations).length === 0) {\n if ('defaultConfiguration' in target) {\n delete target.defaultConfiguration;\n }\n delete target.configurations;\n }\n\n if (\n 'defaultConfiguration' in target &&\n !target.configurations[target.defaultConfiguration]\n ) {\n delete target.defaultConfiguration;\n }\n }\n\n return target;\n };\n}\n\nfunction removePropertiesFromTargetOptions(\n tree: Tree,\n targetOptions: any,\n viteConfigPath: string,\n projectRoot: string,\n projectName: string,\n migrationLogs: AggregatedLog,\n defaultOptions = false\n) {\n if ('buildTarget' in targetOptions) {\n delete targetOptions.buildTarget;\n }\n\n if ('buildLibsFromSource' in targetOptions) {\n migrationLogs.addLog({\n executorName: '@nx/vite:dev-server',\n project: projectName,\n log: `Encountered 'buildLibsFromSource' in project.json. This property will be added to your Vite config file via the '@nx/vite:build' executor migration.`,\n });\n delete targetOptions.buildLibsFromSource;\n }\n\n if ('hmr' in targetOptions) {\n delete targetOptions.hmr;\n }\n\n if ('proxyConfig' in targetOptions) {\n migrationLogs.addLog({\n executorName: '@nx/vite:dev-server',\n project: projectName,\n log: `Encountered 'proxyConfig' in project.json. You will need to copy the contents of this file to the 'server.proxy' property in your Vite config file.`,\n });\n delete targetOptions.proxyConfig;\n }\n}\n"],"names":["servePostTargetTransformer","migrationLogs","target","tree","projectDetails","inferredTargetConfiguration","viteConfigPath","getViteConfigPath","root","options","removePropertiesFromTargetOptions","projectName","configurations","configurationName","configuration","Object","keys","length","defaultConfiguration","targetOptions","projectRoot","defaultOptions","buildTarget","addLog","executorName","project","log","buildLibsFromSource","hmr","proxyConfig"],"rangeMappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;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R,eAAe;QAC1B,OAAOA,cAAcS,GAAG;IAC1B;IAEA,IAAI,iBAAiBT,eAAe;QAClClB,cAAcsB,MAAM,CAAC;YACnBC,cAAc;YACdC,SAASd;YACTe,KAAK,CAAC,mJAAmJ,CAAC;QAC5J;QACA,OAAOP,cAAcU,WAAW;IAClC;AACF"}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { type TargetConfiguration, type Tree } from '@nx/devkit';
|
|
2
|
+
export declare function testPostTargetTransformer(target: TargetConfiguration, tree: Tree, projectDetails: {
|
|
3
|
+
projectName: string;
|
|
4
|
+
root: string;
|
|
5
|
+
}, inferredTargetConfiguration: TargetConfiguration): TargetConfiguration<any>;
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "testPostTargetTransformer", {
|
|
3
|
+
enumerable: true,
|
|
4
|
+
get: function() {
|
|
5
|
+
return testPostTargetTransformer;
|
|
6
|
+
}
|
|
7
|
+
});
|
|
8
|
+
const _utils = require("./utils");
|
|
9
|
+
const _pluginmigrationutils = require("@nx/devkit/src/generators/plugin-migrations/plugin-migration-utils");
|
|
10
|
+
function testPostTargetTransformer(target, tree, projectDetails, inferredTargetConfiguration) {
|
|
11
|
+
if (target.options) {
|
|
12
|
+
removePropertiesFromTargetOptions(target.options, projectDetails.root);
|
|
13
|
+
}
|
|
14
|
+
if (target.configurations) {
|
|
15
|
+
for(const configurationName in target.configurations){
|
|
16
|
+
const configuration = target.configurations[configurationName];
|
|
17
|
+
removePropertiesFromTargetOptions(configuration, projectDetails.root);
|
|
18
|
+
}
|
|
19
|
+
if (Object.keys(target.configurations).length === 0) {
|
|
20
|
+
if ('defaultConfiguration' in target) {
|
|
21
|
+
delete target.defaultConfiguration;
|
|
22
|
+
}
|
|
23
|
+
delete target.configurations;
|
|
24
|
+
}
|
|
25
|
+
if ('defaultConfiguration' in target && !target.configurations[target.defaultConfiguration]) {
|
|
26
|
+
delete target.defaultConfiguration;
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
if (target.outputs) {
|
|
30
|
+
(0, _pluginmigrationutils.processTargetOutputs)(target, [
|
|
31
|
+
{
|
|
32
|
+
newName: 'coverage.reportsDirectory',
|
|
33
|
+
oldName: 'reportsDirectory'
|
|
34
|
+
}
|
|
35
|
+
], inferredTargetConfiguration, {
|
|
36
|
+
projectName: projectDetails.projectName,
|
|
37
|
+
projectRoot: projectDetails.root
|
|
38
|
+
});
|
|
39
|
+
}
|
|
40
|
+
if (target.inputs && target.inputs.every((i)=>i === 'default' || i === '^production')) {
|
|
41
|
+
delete target.inputs;
|
|
42
|
+
}
|
|
43
|
+
return target;
|
|
44
|
+
}
|
|
45
|
+
function removePropertiesFromTargetOptions(targetOptions, projectRoot) {
|
|
46
|
+
if ('configFile' in targetOptions) {
|
|
47
|
+
targetOptions.config = (0, _utils.toProjectRelativePath)(targetOptions.configFile, projectRoot);
|
|
48
|
+
delete targetOptions.configFile;
|
|
49
|
+
}
|
|
50
|
+
if ('reportsDirectory' in targetOptions) {
|
|
51
|
+
if (targetOptions.reportsDirectory.startsWith('../')) {
|
|
52
|
+
targetOptions.reportsDirectory = targetOptions.reportsDirectory.replace(/(\.\.\/)+/, '');
|
|
53
|
+
}
|
|
54
|
+
targetOptions['coverage.reportsDirectory'] = (0, _utils.toProjectRelativePath)(targetOptions.reportsDirectory, projectRoot);
|
|
55
|
+
delete targetOptions.reportsDirectory;
|
|
56
|
+
}
|
|
57
|
+
if ('testFiles' in targetOptions) {
|
|
58
|
+
targetOptions.testNamePattern = `"/(${targetOptions.testFiles.map((f)=>f.replace('.', '\\.')).join('|')})/"`;
|
|
59
|
+
delete targetOptions.testFiles;
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
//# sourceMappingURL=test-post-target-transformer.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../../../../packages/vite/src/generators/convert-to-inferred/lib/test-post-target-transformer.ts"],"sourcesContent":["import { type TargetConfiguration, type Tree } from '@nx/devkit';\nimport { toProjectRelativePath } from './utils';\nimport { processTargetOutputs } from '@nx/devkit/src/generators/plugin-migrations/plugin-migration-utils';\n\nexport function testPostTargetTransformer(\n target: TargetConfiguration,\n tree: Tree,\n projectDetails: { projectName: string; root: string },\n inferredTargetConfiguration: TargetConfiguration\n) {\n if (target.options) {\n removePropertiesFromTargetOptions(target.options, projectDetails.root);\n }\n\n if (target.configurations) {\n for (const configurationName in target.configurations) {\n const configuration = target.configurations[configurationName];\n removePropertiesFromTargetOptions(configuration, projectDetails.root);\n }\n\n if (Object.keys(target.configurations).length === 0) {\n if ('defaultConfiguration' in target) {\n delete target.defaultConfiguration;\n }\n delete target.configurations;\n }\n\n if (\n 'defaultConfiguration' in target &&\n !target.configurations[target.defaultConfiguration]\n ) {\n delete target.defaultConfiguration;\n }\n }\n\n if (target.outputs) {\n processTargetOutputs(\n target,\n [{ newName: 'coverage.reportsDirectory', oldName: 'reportsDirectory' }],\n inferredTargetConfiguration,\n {\n projectName: projectDetails.projectName,\n projectRoot: projectDetails.root,\n }\n );\n }\n\n if (\n target.inputs &&\n target.inputs.every((i) => i === 'default' || i === '^production')\n ) {\n delete target.inputs;\n }\n\n return target;\n}\n\nfunction removePropertiesFromTargetOptions(\n targetOptions: any,\n projectRoot: string\n) {\n if ('configFile' in targetOptions) {\n targetOptions.config = toProjectRelativePath(\n targetOptions.configFile,\n projectRoot\n );\n delete targetOptions.configFile;\n }\n\n if ('reportsDirectory' in targetOptions) {\n if (targetOptions.reportsDirectory.startsWith('../')) {\n targetOptions.reportsDirectory = targetOptions.reportsDirectory.replace(\n /(\\.\\.\\/)+/,\n ''\n );\n }\n targetOptions['coverage.reportsDirectory'] = toProjectRelativePath(\n targetOptions.reportsDirectory,\n projectRoot\n );\n delete targetOptions.reportsDirectory;\n }\n\n if ('testFiles' in targetOptions) {\n targetOptions.testNamePattern = `\"/(${targetOptions.testFiles\n .map((f) => f.replace('.', '\\\\.'))\n .join('|')})/\"`;\n delete targetOptions.testFiles;\n }\n}\n"],"names":["testPostTargetTransformer","target","tree","projectDetails","inferredTargetConfiguration","options","removePropertiesFromTargetOptions","root","configurations","configurationName","configuration","Object","keys","length","defaultConfiguration","outputs","processTargetOutputs","newName","oldName","projectName","projectRoot","inputs","every","i","targetOptions","config","toProjectRelativePath","configFile","reportsDirectory","startsWith","replace","testNamePattern","testFiles","map","f","join"],"rangeMappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;","mappings":";+BAIgBA;;;eAAAA;;;uBAHsB;sCACD;AAE9B,SAASA,0BACdC,MAA2B,EAC3BC,IAAU,EACVC,cAAqD,EACrDC,2BAAgD;IAEhD,IAAIH,OAAOI,OAAO,EAAE;QAClBC,kCAAkCL,OAAOI,OAAO,EAAEF,eAAeI,IAAI;IACvE;IAEA,IAAIN,OAAOO,cAAc,EAAE;QACzB,IAAK,MAAMC,qBAAqBR,OAAOO,cAAc,CAAE;YACrD,MAAME,gBAAgBT,OAAOO,cAAc,CAACC,kBAAkB;YAC9DH,kCAAkCI,eAAeP,eAAeI,IAAI;QACtE;QAEA,IAAII,OAAOC,IAAI,CAACX,OAAOO,cAAc,EAAEK,MAAM,KAAK,GAAG;YACnD,IAAI,0BAA0BZ,QAAQ;gBACpC,OAAOA,OAAOa,oBAAoB;YACpC;YACA,OAAOb,OAAOO,cAAc;QAC9B;QAEA,IACE,0BAA0BP,UAC1B,CAACA,OAAOO,cAAc,CAACP,OAAOa,oBAAoB,CAAC,EACnD;YACA,OAAOb,OAAOa,oBAAoB;QACpC;IACF;IAEA,IAAIb,OAAOc,OAAO,EAAE;QAClBC,IAAAA,0CAAoB,EAClBf,QACA;YAAC;gBAAEgB,SAAS;gBAA6BC,SAAS;YAAmB;SAAE,EACvEd,6BACA;YACEe,aAAahB,eAAegB,WAAW;YACvCC,aAAajB,eAAeI,IAAI;QAClC;IAEJ;IAEA,IACEN,OAAOoB,MAAM,IACbpB,OAAOoB,MAAM,CAACC,KAAK,CAAC,CAACC,IAAMA,MAAM,aAAaA,MAAM,gBACpD;QACA,OAAOtB,OAAOoB,MAAM;IACtB;IAEA,OAAOpB;AACT;AAEA,SAASK,kCACPkB,aAAkB,EAClBJ,WAAmB;IAEnB,IAAI,gBAAgBI,eAAe;QACjCA,cAAcC,MAAM,GAAGC,IAAAA,4BAAqB,EAC1CF,cAAcG,UAAU,EACxBP;QAEF,OAAOI,cAAcG,UAAU;IACjC;IAEA,IAAI,sBAAsBH,eAAe;QACvC,IAAIA,cAAcI,gBAAgB,CAACC,UAAU,CAAC,QAAQ;YACpDL,cAAcI,gBAAgB,GAAGJ,cAAcI,gBAAgB,CAACE,OAAO,CACrE,aACA;QAEJ;QACAN,aAAa,CAAC,4BAA4B,GAAGE,IAAAA,4BAAqB,EAChEF,cAAcI,gBAAgB,EAC9BR;QAEF,OAAOI,cAAcI,gBAAgB;IACvC;IAEA,IAAI,eAAeJ,eAAe;QAChCA,cAAcO,eAAe,GAAG,CAAC,GAAG,EAAEP,cAAcQ,SAAS,CAC1DC,GAAG,CAAC,CAACC,IAAMA,EAAEJ,OAAO,CAAC,KAAK,QAC1BK,IAAI,CAAC,KAAK,GAAG,CAAC;QACjB,OAAOX,cAAcQ,SAAS;IAChC;AACF"}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import { type Tree } from '@nx/devkit';
|
|
2
|
+
export declare function toProjectRelativePath(path: string, projectRoot: string): string;
|
|
3
|
+
export declare function getViteConfigPath(tree: Tree, root: string): string;
|
|
4
|
+
export declare function addConfigValuesToViteConfig(tree: Tree, configFile: string, configValues: Record<string, Record<string, unknown>>): void;
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
function _export(target, all) {
|
|
3
|
+
for(var name in all)Object.defineProperty(target, name, {
|
|
4
|
+
enumerable: true,
|
|
5
|
+
get: all[name]
|
|
6
|
+
});
|
|
7
|
+
}
|
|
8
|
+
_export(exports, {
|
|
9
|
+
addConfigValuesToViteConfig: function() {
|
|
10
|
+
return addConfigValuesToViteConfig;
|
|
11
|
+
},
|
|
12
|
+
getViteConfigPath: function() {
|
|
13
|
+
return getViteConfigPath;
|
|
14
|
+
},
|
|
15
|
+
toProjectRelativePath: function() {
|
|
16
|
+
return toProjectRelativePath;
|
|
17
|
+
}
|
|
18
|
+
});
|
|
19
|
+
const _posix = require("path/posix");
|
|
20
|
+
const _devkit = require("@nx/devkit");
|
|
21
|
+
const _tsquery = require("@phenomnomnominal/tsquery");
|
|
22
|
+
function toProjectRelativePath(path, projectRoot) {
|
|
23
|
+
if (projectRoot === '.') {
|
|
24
|
+
// workspace and project root are the same, we normalize it to ensure it
|
|
25
|
+
// works with Jest since some paths only work when they start with `./`
|
|
26
|
+
return path.startsWith('.') ? path : `./${path}`;
|
|
27
|
+
}
|
|
28
|
+
const relativePath = (0, _posix.relative)((0, _posix.resolve)(_devkit.workspaceRoot, projectRoot), (0, _posix.resolve)(_devkit.workspaceRoot, path));
|
|
29
|
+
return relativePath.startsWith('.') ? relativePath : `./${relativePath}`;
|
|
30
|
+
}
|
|
31
|
+
function getViteConfigPath(tree, root) {
|
|
32
|
+
return [
|
|
33
|
+
(0, _devkit.joinPathFragments)(root, `vite.config.ts`),
|
|
34
|
+
(0, _devkit.joinPathFragments)(root, `vite.config.cts`),
|
|
35
|
+
(0, _devkit.joinPathFragments)(root, `vite.config.mts`),
|
|
36
|
+
(0, _devkit.joinPathFragments)(root, `vite.config.js`),
|
|
37
|
+
(0, _devkit.joinPathFragments)(root, `vite.config.cjs`),
|
|
38
|
+
(0, _devkit.joinPathFragments)(root, `vite.config.mjs`)
|
|
39
|
+
].find((f)=>tree.exists(f));
|
|
40
|
+
}
|
|
41
|
+
function addConfigValuesToViteConfig(tree, configFile, configValues) {
|
|
42
|
+
const IMPORT_PROPERTY_SELECTOR = 'ImportDeclaration';
|
|
43
|
+
const viteConfigContents = tree.read(configFile, 'utf-8');
|
|
44
|
+
const ast = _tsquery.tsquery.ast(viteConfigContents);
|
|
45
|
+
// AST TO GET SECTION TO APPEND TO
|
|
46
|
+
const importNodes = (0, _tsquery.tsquery)(ast, IMPORT_PROPERTY_SELECTOR, {
|
|
47
|
+
visitAllChildren: true
|
|
48
|
+
});
|
|
49
|
+
if (importNodes.length === 0) {
|
|
50
|
+
return;
|
|
51
|
+
}
|
|
52
|
+
const lastImportNode = importNodes[importNodes.length - 1];
|
|
53
|
+
const configValuesString = `
|
|
54
|
+
// These options were migrated by @nx/vite:convert-to-inferred from the project.json file.
|
|
55
|
+
const configValues = ${JSON.stringify(configValues)};
|
|
56
|
+
|
|
57
|
+
// Determine the correct configValue to use based on the configuration
|
|
58
|
+
const nxConfiguration = process.env.NX_TASK_TARGET_CONFIGURATION ?? 'default';
|
|
59
|
+
|
|
60
|
+
const options = {
|
|
61
|
+
...configValues.default,
|
|
62
|
+
...(configValues[nxConfiguration] ?? {})
|
|
63
|
+
}`;
|
|
64
|
+
tree.write(configFile, `${viteConfigContents.slice(0, lastImportNode.getEnd())}
|
|
65
|
+
${configValuesString}
|
|
66
|
+
${viteConfigContents.slice(lastImportNode.getEnd())}`);
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
//# sourceMappingURL=utils.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../../../../packages/vite/src/generators/convert-to-inferred/lib/utils.ts"],"sourcesContent":["import { relative, resolve } from 'path/posix';\nimport { workspaceRoot, type Tree, joinPathFragments } from '@nx/devkit';\nimport { tsquery } from '@phenomnomnominal/tsquery';\n\nexport function toProjectRelativePath(\n path: string,\n projectRoot: string\n): string {\n if (projectRoot === '.') {\n // workspace and project root are the same, we normalize it to ensure it\n // works with Jest since some paths only work when they start with `./`\n return path.startsWith('.') ? path : `./${path}`;\n }\n\n const relativePath = relative(\n resolve(workspaceRoot, projectRoot),\n resolve(workspaceRoot, path)\n );\n\n return relativePath.startsWith('.') ? relativePath : `./${relativePath}`;\n}\n\nexport function getViteConfigPath(tree: Tree, root: string) {\n return [\n joinPathFragments(root, `vite.config.ts`),\n joinPathFragments(root, `vite.config.cts`),\n joinPathFragments(root, `vite.config.mts`),\n joinPathFragments(root, `vite.config.js`),\n joinPathFragments(root, `vite.config.cjs`),\n joinPathFragments(root, `vite.config.mjs`),\n ].find((f) => tree.exists(f));\n}\n\nexport function addConfigValuesToViteConfig(\n tree: Tree,\n configFile: string,\n configValues: Record<string, Record<string, unknown>>\n) {\n const IMPORT_PROPERTY_SELECTOR = 'ImportDeclaration';\n const viteConfigContents = tree.read(configFile, 'utf-8');\n\n const ast = tsquery.ast(viteConfigContents);\n // AST TO GET SECTION TO APPEND TO\n const importNodes = tsquery(ast, IMPORT_PROPERTY_SELECTOR, {\n visitAllChildren: true,\n });\n if (importNodes.length === 0) {\n return;\n }\n const lastImportNode = importNodes[importNodes.length - 1];\n\n const configValuesString = `\n // These options were migrated by @nx/vite:convert-to-inferred from the project.json file.\n const configValues = ${JSON.stringify(configValues)};\n \n // Determine the correct configValue to use based on the configuration\n const nxConfiguration = process.env.NX_TASK_TARGET_CONFIGURATION ?? 'default';\n \n const options = {\n ...configValues.default,\n ...(configValues[nxConfiguration] ?? {})\n }`;\n\n tree.write(\n configFile,\n `${viteConfigContents.slice(0, lastImportNode.getEnd())}\n ${configValuesString}\n ${viteConfigContents.slice(lastImportNode.getEnd())}`\n );\n}\n"],"names":["addConfigValuesToViteConfig","getViteConfigPath","toProjectRelativePath","path","projectRoot","startsWith","relativePath","relative","resolve","workspaceRoot","tree","root","joinPathFragments","find","f","exists","configFile","configValues","IMPORT_PROPERTY_SELECTOR","viteConfigContents","read","ast","tsquery","importNodes","visitAllChildren","length","lastImportNode","configValuesString","JSON","stringify","write","slice","getEnd"],"rangeMappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;","mappings":";;;;;;;;IAiCgBA,2BAA2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BAAiBH,WAAW,CAACA,YAAYE,MAAM,GAAG,EAAE;IAE1D,MAAME,qBAAqB,CAAC;;uBAEP,EAAEC,KAAKC,SAAS,CAACZ,cAAc;;;;;;;;GAQnD,CAAC;IAEFP,KAAKoB,KAAK,CACRd,YACA,CAAC,EAAEG,mBAAmBY,KAAK,CAAC,GAAGL,eAAeM,MAAM,IAAI;EAC1D,EAAEL,mBAAmB;EACrB,EAAER,mBAAmBY,KAAK,CAACL,eAAeM,MAAM,IAAI,CAAC;AAEvD"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
{
|
|
2
|
+
"$schema": "https://json-schema.org/schema",
|
|
3
|
+
"$id": "NxViteConvertToInferred",
|
|
4
|
+
"description": "Convert existing Vite project(s) using `@nx/vite:*` executors to use `@nx/vite/plugin`. Defaults to migrating all projects. Pass '--project' to migrate only one target.",
|
|
5
|
+
"title": "Convert Vite project from executor to plugin",
|
|
6
|
+
"type": "object",
|
|
7
|
+
"properties": {
|
|
8
|
+
"project": {
|
|
9
|
+
"type": "string",
|
|
10
|
+
"description": "The project to convert from using the `@nx/vite:*` executors to use `@nx/vite/plugin`.",
|
|
11
|
+
"x-priority": "important"
|
|
12
|
+
},
|
|
13
|
+
"skipFormat": {
|
|
14
|
+
"type": "boolean",
|
|
15
|
+
"description": "Whether to format files at the end of the migration.",
|
|
16
|
+
"default": false
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
}
|
|
@@ -62,7 +62,7 @@ async function initGeneratorInternal(tree, schema) {
|
|
|
62
62
|
var _addPlugin;
|
|
63
63
|
(_addPlugin = (_schema = schema).addPlugin) != null ? _addPlugin : _schema.addPlugin = addPluginDefault;
|
|
64
64
|
if (schema.addPlugin) {
|
|
65
|
-
await (0, _addplugin.
|
|
65
|
+
await (0, _addplugin.addPlugin)(tree, await (0, _devkit.createProjectGraphAsync)(), '@nx/vite/plugin', _plugin.createNodesV2, {
|
|
66
66
|
buildTargetName: [
|
|
67
67
|
'build',
|
|
68
68
|
'vite:build',
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../../../packages/vite/src/generators/init/init.ts"],"sourcesContent":["import {\n createProjectGraphAsync,\n formatFiles,\n GeneratorCallback,\n readNxJson,\n runTasksInSerial,\n Tree,\n updateNxJson,\n} from '@nx/devkit';\nimport {
|
|
1
|
+
{"version":3,"sources":["../../../../../../packages/vite/src/generators/init/init.ts"],"sourcesContent":["import {\n createProjectGraphAsync,\n formatFiles,\n GeneratorCallback,\n readNxJson,\n runTasksInSerial,\n Tree,\n updateNxJson,\n} from '@nx/devkit';\nimport { addPlugin } from '@nx/devkit/src/utils/add-plugin';\n\nimport { setupPathsPlugin } from '../setup-paths-plugin/setup-paths-plugin';\nimport { createNodesV2 } from '../../plugins/plugin';\nimport { InitGeneratorSchema } from './schema';\nimport { checkDependenciesInstalled, moveToDevDependencies } from './lib/utils';\n\nexport function updateNxJsonSettings(tree: Tree) {\n const nxJson = readNxJson(tree);\n\n const productionFileSet = nxJson.namedInputs?.production;\n if (productionFileSet) {\n productionFileSet.push(\n '!{projectRoot}/**/?(*.)+(spec|test).[jt]s?(x)?(.snap)',\n '!{projectRoot}/tsconfig.spec.json'\n );\n\n nxJson.namedInputs.production = Array.from(new Set(productionFileSet));\n }\n\n const hasPlugin = nxJson.plugins?.some((p) =>\n typeof p === 'string'\n ? p === '@nx/vite/plugin'\n : p.plugin === '@nx/vite/plugin'\n );\n\n if (!hasPlugin) {\n nxJson.targetDefaults ??= {};\n nxJson.targetDefaults['@nx/vite:test'] ??= {};\n nxJson.targetDefaults['@nx/vite:test'].cache ??= true;\n nxJson.targetDefaults['@nx/vite:test'].inputs ??= [\n 'default',\n productionFileSet ? '^production' : '^default',\n ];\n }\n\n updateNxJson(tree, nxJson);\n}\n\nexport function initGenerator(tree: Tree, schema: InitGeneratorSchema) {\n return initGeneratorInternal(tree, { addPlugin: false, ...schema });\n}\n\nexport async function initGeneratorInternal(\n tree: Tree,\n schema: InitGeneratorSchema\n) {\n const nxJson = readNxJson(tree);\n const addPluginDefault =\n process.env.NX_ADD_PLUGINS !== 'false' &&\n nxJson.useInferencePlugins !== false;\n schema.addPlugin ??= addPluginDefault;\n\n if (schema.addPlugin) {\n await addPlugin(\n tree,\n await createProjectGraphAsync(),\n '@nx/vite/plugin',\n createNodesV2,\n {\n buildTargetName: ['build', 'vite:build', 'vite-build'],\n testTargetName: ['test', 'vite:test', 'vite-test'],\n serveTargetName: ['serve', 'vite:serve', 'vite-serve'],\n previewTargetName: ['preview', 'vite:preview', 'vite-preview'],\n serveStaticTargetName: [\n 'serve-static',\n 'vite:serve-static',\n 'vite-serve-static',\n ],\n },\n schema.updatePackageScripts\n );\n }\n\n updateNxJsonSettings(tree);\n\n if (schema.setupPathsPlugin) {\n await setupPathsPlugin(tree, { skipFormat: true });\n }\n\n const tasks: GeneratorCallback[] = [];\n if (!schema.skipPackageJson) {\n tasks.push(moveToDevDependencies(tree));\n tasks.push(checkDependenciesInstalled(tree, schema));\n }\n\n if (!schema.skipFormat) {\n await formatFiles(tree);\n }\n\n return runTasksInSerial(...tasks);\n}\n\nexport default initGenerator;\n"],"names":["initGenerator","initGeneratorInternal","updateNxJsonSettings","tree","nxJson","readNxJson","productionFileSet","namedInputs","production","push","Array","from","Set","hasPlugin","plugins","some","p","plugin","targetDefaults","cache","inputs","updateNxJson","schema","addPlugin","addPluginDefault","process","env","NX_ADD_PLUGINS","useInferencePlugins","createProjectGraphAsync","createNodesV2","buildTargetName","testTargetName","serveTargetName","previewTargetName","serveStaticTargetName","updatePackageScripts","setupPathsPlugin","skipFormat","tasks","skipPackageJson","moveToDevDependencies","checkDependenciesInstalled","formatFiles","runTasksInSerial"],"rangeMappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;","mappings":";;;;;;;;IAsGA,OAA6B;eAA7B;;IAtDgBA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,GAAG,CAACC,cAAc,KAAK,WAC/BvB,OAAOwB,mBAAmB,KAAK;;IACjCN,eAAAA,UAAAA,QAAOC,kCAAPD,QAAOC,YAAcC;IAErB,IAAIF,OAAOC,SAAS,EAAE;QACpB,MAAMA,IAAAA,oBAAS,EACbpB,MACA,MAAM0B,IAAAA,+BAAuB,KAC7B,mBACAC,qBAAa,EACb;YACEC,iBAAiB;gBAAC;gBAAS;gBAAc;aAAa;YACtDC,gBAAgB;gBAAC;gBAAQ;gBAAa;aAAY;YAClDC,iBAAiB;gBAAC;gBAAS;gBAAc;aAAa;YACtDC,mBAAmB;gBAAC;gBAAW;gBAAgB;aAAe;YAC9DC,uBAAuB;gBACrB;gBACA;gBACA;aACD;QACH,GACAb,OAAOc,oBAAoB;IAE/B;IAEAlC,qBAAqBC;IAErB,IAAImB,OAAOe,gBAAgB,EAAE;QAC3B,MAAMA,IAAAA,kCAAgB,EAAClC,MAAM;YAAEmC,YAAY;QAAK;IAClD;IAEA,MAAMC,QAA6B,EAAE;IACrC,IAAI,CAACjB,OAAOkB,eAAe,EAAE;QAC3BD,MAAM9B,IAAI,CAACgC,IAAAA,4BAAqB,EAACtC;QACjCoC,MAAM9B,IAAI,CAACiC,IAAAA,iCAA0B,EAACvC,MAAMmB;IAC9C;IAEA,IAAI,CAACA,OAAOgB,UAAU,EAAE;QACtB,MAAMK,IAAAA,mBAAW,EAACxC;IACpB;IAEA,OAAOyC,IAAAA,wBAAgB,KAAIL;AAC7B;MAEA,WAAevC"}
|
|
@@ -31,6 +31,9 @@ function ensureImportExists(tree, file) {
|
|
|
31
31
|
let content = tree.read(file, 'utf-8');
|
|
32
32
|
const ast = tsquery.ast(content);
|
|
33
33
|
const allImports = tsquery.query(ast, 'ImportDeclaration');
|
|
34
|
+
if (content.includes('@nx/vite/plugins/nx-tsconfig-paths.plugin')) {
|
|
35
|
+
return;
|
|
36
|
+
}
|
|
34
37
|
if (allImports.length) {
|
|
35
38
|
const lastImport = allImports[allImports.length - 1];
|
|
36
39
|
tree.write(file, (0, _devkit.applyChangesToString)(content, [
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../../../packages/vite/src/generators/setup-paths-plugin/setup-paths-plugin.ts"],"sourcesContent":["import {\n applyChangesToString,\n ChangeType,\n formatFiles,\n globAsync,\n Tree,\n} from '@nx/devkit';\nimport type { ArrayLiteralExpression, Node } from 'typescript';\n\nexport async function setupPathsPlugin(\n tree: Tree,\n schema: { skipFormat?: boolean }\n) {\n const files = await globAsync(tree, [\n '**/vite.config.{js,ts,mjs,mts,cjs,cts}',\n ]);\n\n for (const file of files) {\n ensureImportExists(tree, file);\n ensurePluginAdded(tree, file);\n }\n\n if (!schema.skipFormat) {\n await formatFiles(tree);\n }\n}\n\nfunction ensureImportExists(tree, file) {\n const { tsquery } = require('@phenomnomnominal/tsquery');\n let content = tree.read(file, 'utf-8');\n const ast = tsquery.ast(content);\n const allImports = tsquery.query(ast, 'ImportDeclaration');\n if (allImports.length) {\n const lastImport = allImports[allImports.length - 1];\n tree.write(\n file,\n applyChangesToString(content, [\n {\n type: ChangeType.Insert,\n index: lastImport.end + 1,\n text: `import { nxViteTsPaths } from '@nx/vite/plugins/nx-tsconfig-paths.plugin';\\n`,\n },\n ])\n );\n } else {\n if (file.endsWith('.cts') || file.endsWith('.cjs')) {\n tree.write(\n file,\n applyChangesToString(content, [\n {\n type: ChangeType.Insert,\n index: 0,\n text: `const { nxViteTsPaths } = require('@nx/vite/plugins/nx-tsconfig-paths.plugin');\\n`,\n },\n ])\n );\n } else {\n tree.write(\n file,\n applyChangesToString(content, [\n {\n type: ChangeType.Insert,\n index: 0,\n text: `import { nxViteTsPaths } from '@nx/vite/plugins/nx-tsconfig-paths.plugin';\\n`,\n },\n ])\n );\n }\n }\n}\n\nfunction ensurePluginAdded(tree, file) {\n const { tsquery } = require('@phenomnomnominal/tsquery');\n const content = tree.read(file, 'utf-8');\n const ast = tsquery.ast(content);\n const foundDefineConfig = tsquery.query(\n ast,\n 'CallExpression:has(Identifier[name=\"defineConfig\"])'\n );\n if (!foundDefineConfig.length) return content;\n\n // Do not update defineConfig if it has an arrow function since it can be tricky and error-prone.\n const defineUsingArrowFunction = tsquery.query(\n foundDefineConfig[0],\n 'ArrowFunction'\n );\n if (defineUsingArrowFunction.length) return content;\n\n const propertyAssignments = tsquery.query(\n foundDefineConfig[0],\n 'PropertyAssignment'\n );\n\n if (propertyAssignments.length) {\n const pluginsNode = tsquery.query(\n foundDefineConfig[0],\n 'PropertyAssignment:has(Identifier[name=\"plugins\"])'\n );\n\n if (pluginsNode.length) {\n const updated = tsquery.replace(\n content,\n 'PropertyAssignment:has(Identifier[name=\"plugins\"])',\n (node: Node) => {\n const found = tsquery.query(\n node,\n 'ArrayLiteralExpression'\n ) as ArrayLiteralExpression[];\n let updatedPluginsString = '';\n\n const existingPluginNodes = found?.[0].elements ?? [];\n\n for (const plugin of existingPluginNodes) {\n updatedPluginsString += `${plugin.getText()},`;\n }\n\n if (\n !existingPluginNodes?.some((node: Node) =>\n node.getText().includes('nxViteTsPaths')\n )\n ) {\n updatedPluginsString += ` nxViteTsPaths(),`;\n }\n\n return `plugins: [${updatedPluginsString}]`;\n }\n );\n tree.write(file, updated);\n } else {\n tree.write(\n file,\n applyChangesToString(content, [\n {\n type: ChangeType.Insert,\n index: propertyAssignments[0].getStart(),\n text: `plugins: [nxViteTsPaths()],\n `,\n },\n ])\n );\n }\n } else {\n tree.write(\n file,\n applyChangesToString(content, [\n {\n type: ChangeType.Insert,\n index: foundDefineConfig[0].getStart() + 14, // length of \"defineConfig(\" + 1\n text: `plugins: [nxViteTsPaths()],`,\n },\n ])\n );\n }\n}\n\nexport default setupPathsPlugin;\n"],"names":["setupPathsPlugin","tree","schema","files","globAsync","file","ensureImportExists","ensurePluginAdded","skipFormat","formatFiles","tsquery","require","content","read","ast","allImports","query","length","lastImport","write","applyChangesToString","type","ChangeType","Insert","index","end","text","endsWith","foundDefineConfig","defineUsingArrowFunction","propertyAssignments","pluginsNode","updated","replace","node","found","updatedPluginsString","existingPluginNodes","elements","plugin","getText","some","
|
|
1
|
+
{"version":3,"sources":["../../../../../../packages/vite/src/generators/setup-paths-plugin/setup-paths-plugin.ts"],"sourcesContent":["import {\n applyChangesToString,\n ChangeType,\n formatFiles,\n globAsync,\n Tree,\n} from '@nx/devkit';\nimport type { ArrayLiteralExpression, Node } from 'typescript';\n\nexport async function setupPathsPlugin(\n tree: Tree,\n schema: { skipFormat?: boolean }\n) {\n const files = await globAsync(tree, [\n '**/vite.config.{js,ts,mjs,mts,cjs,cts}',\n ]);\n\n for (const file of files) {\n ensureImportExists(tree, file);\n ensurePluginAdded(tree, file);\n }\n\n if (!schema.skipFormat) {\n await formatFiles(tree);\n }\n}\n\nfunction ensureImportExists(tree: Tree, file: string) {\n const { tsquery } = require('@phenomnomnominal/tsquery');\n let content = tree.read(file, 'utf-8');\n const ast = tsquery.ast(content);\n const allImports = tsquery.query(ast, 'ImportDeclaration');\n if (content.includes('@nx/vite/plugins/nx-tsconfig-paths.plugin')) {\n return;\n }\n if (allImports.length) {\n const lastImport = allImports[allImports.length - 1];\n tree.write(\n file,\n applyChangesToString(content, [\n {\n type: ChangeType.Insert,\n index: lastImport.end + 1,\n text: `import { nxViteTsPaths } from '@nx/vite/plugins/nx-tsconfig-paths.plugin';\\n`,\n },\n ])\n );\n } else {\n if (file.endsWith('.cts') || file.endsWith('.cjs')) {\n tree.write(\n file,\n applyChangesToString(content, [\n {\n type: ChangeType.Insert,\n index: 0,\n text: `const { nxViteTsPaths } = require('@nx/vite/plugins/nx-tsconfig-paths.plugin');\\n`,\n },\n ])\n );\n } else {\n tree.write(\n file,\n applyChangesToString(content, [\n {\n type: ChangeType.Insert,\n index: 0,\n text: `import { nxViteTsPaths } from '@nx/vite/plugins/nx-tsconfig-paths.plugin';\\n`,\n },\n ])\n );\n }\n }\n}\n\nfunction ensurePluginAdded(tree, file) {\n const { tsquery } = require('@phenomnomnominal/tsquery');\n const content = tree.read(file, 'utf-8');\n const ast = tsquery.ast(content);\n const foundDefineConfig = tsquery.query(\n ast,\n 'CallExpression:has(Identifier[name=\"defineConfig\"])'\n );\n if (!foundDefineConfig.length) return content;\n\n // Do not update defineConfig if it has an arrow function since it can be tricky and error-prone.\n const defineUsingArrowFunction = tsquery.query(\n foundDefineConfig[0],\n 'ArrowFunction'\n );\n if (defineUsingArrowFunction.length) return content;\n\n const propertyAssignments = tsquery.query(\n foundDefineConfig[0],\n 'PropertyAssignment'\n );\n\n if (propertyAssignments.length) {\n const pluginsNode = tsquery.query(\n foundDefineConfig[0],\n 'PropertyAssignment:has(Identifier[name=\"plugins\"])'\n );\n\n if (pluginsNode.length) {\n const updated = tsquery.replace(\n content,\n 'PropertyAssignment:has(Identifier[name=\"plugins\"])',\n (node: Node) => {\n const found = tsquery.query(\n node,\n 'ArrayLiteralExpression'\n ) as ArrayLiteralExpression[];\n let updatedPluginsString = '';\n\n const existingPluginNodes = found?.[0].elements ?? [];\n\n for (const plugin of existingPluginNodes) {\n updatedPluginsString += `${plugin.getText()},`;\n }\n\n if (\n !existingPluginNodes?.some((node: Node) =>\n node.getText().includes('nxViteTsPaths')\n )\n ) {\n updatedPluginsString += ` nxViteTsPaths(),`;\n }\n\n return `plugins: [${updatedPluginsString}]`;\n }\n );\n tree.write(file, updated);\n } else {\n tree.write(\n file,\n applyChangesToString(content, [\n {\n type: ChangeType.Insert,\n index: propertyAssignments[0].getStart(),\n text: `plugins: [nxViteTsPaths()],\n `,\n },\n ])\n );\n }\n } else {\n tree.write(\n file,\n applyChangesToString(content, [\n {\n type: ChangeType.Insert,\n index: foundDefineConfig[0].getStart() + 14, // length of \"defineConfig(\" + 1\n text: `plugins: [nxViteTsPaths()],`,\n },\n ])\n );\n }\n}\n\nexport default setupPathsPlugin;\n"],"names":["setupPathsPlugin","tree","schema","files","globAsync","file","ensureImportExists","ensurePluginAdded","skipFormat","formatFiles","tsquery","require","content","read","ast","allImports","query","includes","length","lastImport","write","applyChangesToString","type","ChangeType","Insert","index","end","text","endsWith","foundDefineConfig","defineUsingArrowFunction","propertyAssignments","pluginsNode","updated","replace","node","found","updatedPluginsString","existingPluginNodes","elements","plugin","getText","some","getStart"],"rangeMappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;","mappings":";;;;;;;;IA8JA,OAAgC;eAAhC;;IArJsBA,gBAAgB;eAAhBA;;;wBAHf;AAGA,eAAeA,iBACpBC,IAAU,EACVC,MAAgC;IAEhC,MAAMC,QAAQ,MAAMC,IAAAA,iBAAS,EAACH,MAAM;QAClC;KACD;IAED,KAAK,MAAMI,QAAQF,MAAO;QACxBG,mBAAmBL,MAAMI;QACzBE,kBAAkBN,MAAMI;IAC1B;IAEA,IAAI,CAACH,OAAOM,UAAU,EAAE;QACtB,MAAMC,IAAAA,mBAAW,EAACR;IACpB;AACF;AAEA,SAASK,mBAAmBL,IAAU,EAAEI,IAAY;IAClD,MAAM,EAAEK,OAAO,EAAE,GAAGC,QAAQ;IAC5B,IAAIC,UAAUX,KAAKY,IAAI,CAACR,MAAM;IAC9B,MAAMS,MAAMJ,QAAQI,GAAG,CAACF;IACxB,MAAMG,aAAaL,QAAQM,KAAK,CAACF,KAAK;IACtC,IAAIF,QAAQK,QAAQ,CAAC,8CAA8C;QACjE;IACF;IACA,IAAIF,WAAWG,MAAM,EAAE;QACrB,MAAMC,aAAaJ,UAAU,CAACA,WAAWG,MAAM,GAAG,EAAE;QACpDjB,KAAKmB,KAAK,CACRf,MACAgB,IAAAA,4BAAoB,EAACT,SAAS;YAC5B;gBACEU,MAAMC,kBAAU,CAACC,MAAM;gBACvBC,OAAON,WAAWO,GAAG,GAAG;gBACxBC,MAAM,CAAC,4EAA4E,CAAC;YACtF;SACD;IAEL,OAAO;QACL,IAAItB,KAAKuB,QAAQ,CAAC,WAAWvB,KAAKuB,QAA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AE;gBAErD,KAAK,MAAMI,UAAUF,oBAAqB;oBACxCD,wBAAwB,CAAC,EAAEG,OAAOC,OAAO,GAAG,CAAC,CAAC;gBAChD;gBAEA,IACE,EAACH,uCAAAA,oBAAqBI,IAAI,CAAC,CAACP,OAC1BA,KAAKM,OAAO,GAAGxB,QAAQ,CAAC,oBAE1B;oBACAoB,wBAAwB,CAAC,iBAAiB,CAAC;gBAC7C;gBAEA,OAAO,CAAC,UAAU,EAAEA,qBAAqB,CAAC,CAAC;YAC7C;YAEFpC,KAAKmB,KAAK,CAACf,MAAM4B;QACnB,OAAO;YACLhC,KAAKmB,KAAK,CACRf,MACAgB,IAAAA,4BAAoB,EAACT,SAAS;gBAC5B;oBACEU,MAAMC,kBAAU,CAACC,MAAM;oBACvBC,OAAOM,mBAAmB,CAAC,EAAE,CAACY,QAAQ;oBACtChB,MAAM,CAAC;YACP,CAAC;gBACH;aACD;QAEL;IACF,OAAO;QACL1B,KAAKmB,KAAK,CACRf,MACAgB,IAAAA,4BAAoB,EAACT,SAAS;YAC5B;gBACEU,MAAMC,kBAAU,CAACC,MAAM;gBACvBC,OAAOI,iBAAiB,CAAC,EAAE,CAACc,QAAQ,KAAK;gBACzChB,MAAM,CAAC,2BAA2B,CAAC;YACrC;SACD;IAEL;AACF;MAEA,WAAe3B"}
|
package/src/plugins/plugin.js
CHANGED
|
@@ -72,13 +72,19 @@ async function createNodesInternal(configFilePath, options, context, targetsCach
|
|
|
72
72
|
var _;
|
|
73
73
|
(_ = (_targetsCache = targetsCache)[_hash = hash]) != null ? _ : _targetsCache[_hash] = await buildViteTargets(configFilePath, projectRoot, normalizedOptions, context);
|
|
74
74
|
const { targets, metadata } = targetsCache[hash];
|
|
75
|
+
const project = {
|
|
76
|
+
root: projectRoot,
|
|
77
|
+
targets,
|
|
78
|
+
metadata
|
|
79
|
+
};
|
|
80
|
+
// If project is buildable, then the project type.
|
|
81
|
+
// If it is not buildable, then leave it to other plugins/project.json to set the project type.
|
|
82
|
+
if (project.targets[options.buildTargetName]) {
|
|
83
|
+
project.projectType = project.targets[options.serveTargetName] ? 'application' : 'library';
|
|
84
|
+
}
|
|
75
85
|
return {
|
|
76
86
|
projects: {
|
|
77
|
-
[projectRoot]:
|
|
78
|
-
root: projectRoot,
|
|
79
|
-
targets,
|
|
80
|
-
metadata
|
|
81
|
-
}
|
|
87
|
+
[projectRoot]: project
|
|
82
88
|
}
|
|
83
89
|
};
|
|
84
90
|
}
|
|
@@ -103,10 +109,14 @@ async function buildViteTargets(configFilePath, projectRoot, options, context) {
|
|
|
103
109
|
// If file is not vitest.config and buildable, create targets for build, serve, preview and serve-static
|
|
104
110
|
const hasRemixPlugin = viteConfig.plugins && viteConfig.plugins.some((p)=>p.name === 'remix');
|
|
105
111
|
if (!configFilePath.includes('vitest.config') && !hasRemixPlugin && isBuildable) {
|
|
112
|
+
var _viteConfig_build;
|
|
106
113
|
targets[options.buildTargetName] = await buildTarget(options.buildTargetName, namedInputs, buildOutputs, projectRoot);
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
114
|
+
// If running in library mode, then there is nothing to serve.
|
|
115
|
+
if (!((_viteConfig_build = viteConfig.build) == null ? void 0 : _viteConfig_build.lib)) {
|
|
116
|
+
targets[options.serveTargetName] = serveTarget(projectRoot);
|
|
117
|
+
targets[options.previewTargetName] = previewTarget(projectRoot);
|
|
118
|
+
targets[options.serveStaticTargetName] = serveStaticTarget(options);
|
|
119
|
+
}
|
|
110
120
|
}
|
|
111
121
|
// if file is vitest.config or vite.config has definition for test, create target for test
|
|
112
122
|
if (configFilePath.includes('vitest.config') || hasTest) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../../packages/vite/src/plugins/plugin.ts"],"sourcesContent":["import {\n CreateDependencies,\n CreateNodes,\n CreateNodesContext,\n createNodesFromFiles,\n CreateNodesV2,\n detectPackageManager,\n joinPathFragments,\n logger,\n ProjectConfiguration,\n readJsonFile,\n TargetConfiguration,\n writeJsonFile,\n} from '@nx/devkit';\nimport { dirname, isAbsolute, join, relative } from 'path';\nimport { getNamedInputs } from '@nx/devkit/src/utils/get-named-inputs';\nimport { existsSync, readdirSync } from 'fs';\nimport { calculateHashForCreateNodes } from '@nx/devkit/src/utils/calculate-hash-for-create-nodes';\nimport { workspaceDataDirectory } from 'nx/src/utils/cache-directory';\nimport { getLockFileName } from '@nx/js';\nimport { loadViteDynamicImport } from '../utils/executor-utils';\nimport { hashObject } from 'nx/src/hasher/file-hasher';\n\nexport interface VitePluginOptions {\n buildTargetName?: string;\n testTargetName?: string;\n serveTargetName?: string;\n previewTargetName?: string;\n serveStaticTargetName?: string;\n}\ntype ViteTargets = Pick<ProjectConfiguration, 'targets' | 'metadata'>;\n\nfunction readTargetsCache(cachePath: string): Record<string, ViteTargets> {\n return existsSync(cachePath) ? readJsonFile(cachePath) : {};\n}\n\nfunction writeTargetsToCache(cachePath, results?: Record<string, ViteTargets>) {\n writeJsonFile(cachePath, results);\n}\n\n/**\n * @deprecated The 'createDependencies' function is now a no-op. This functionality is included in 'createNodesV2'.\n */\nexport const createDependencies: CreateDependencies = () => {\n return [];\n};\n\nconst viteVitestConfigGlob = '**/{vite,vitest}.config.{js,ts,mjs,mts,cjs,cts}';\n\nexport const createNodesV2: CreateNodesV2<VitePluginOptions> = [\n viteVitestConfigGlob,\n async (configFilePaths, options, context) => {\n const optionsHash = hashObject(options);\n const cachePath = join(workspaceDataDirectory, `vite-${optionsHash}.hash`);\n const targetsCache = readTargetsCache(cachePath);\n try {\n return await createNodesFromFiles(\n (configFile, options, context) =>\n createNodesInternal(configFile, options, context, targetsCache),\n configFilePaths,\n options,\n context\n );\n } finally {\n writeTargetsToCache(cachePath, targetsCache);\n }\n },\n];\n\nexport const createNodes: CreateNodes<VitePluginOptions> = [\n viteVitestConfigGlob,\n async (configFilePath, options, context) => {\n logger.warn(\n '`createNodes` is deprecated. Update your plugin to utilize createNodesV2 instead. In Nx 20, this will change to the createNodesV2 API.'\n );\n return createNodesInternal(configFilePath, options, context, {});\n },\n];\n\nasync function createNodesInternal(\n configFilePath: string,\n options: VitePluginOptions,\n context: CreateNodesContext,\n targetsCache: Record<string, ViteTargets>\n) {\n const projectRoot = dirname(configFilePath);\n // Do not create a project if package.json and project.json isn't there.\n const siblingFiles = readdirSync(join(context.workspaceRoot, projectRoot));\n if (\n !siblingFiles.includes('package.json') &&\n !siblingFiles.includes('project.json')\n ) {\n return {};\n }\n\n const normalizedOptions = normalizeOptions(options);\n\n // We do not want to alter how the hash is calculated, so appending the config file path to the hash\n // to prevent vite/vitest files overwriting the target cache created by the other\n const hash =\n (await calculateHashForCreateNodes(\n projectRoot,\n normalizedOptions,\n context,\n [getLockFileName(detectPackageManager(context.workspaceRoot))]\n )) + configFilePath;\n\n targetsCache[hash] ??= await buildViteTargets(\n configFilePath,\n projectRoot,\n normalizedOptions,\n context\n );\n\n const { targets, metadata } = targetsCache[hash];\n\n return {\n projects: {\n [projectRoot]: {\n root: projectRoot,\n targets,\n metadata,\n },\n },\n };\n}\n\nasync function buildViteTargets(\n configFilePath: string,\n projectRoot: string,\n options: VitePluginOptions,\n context: CreateNodesContext\n): Promise<ViteTargets> {\n const absoluteConfigFilePath = joinPathFragments(\n context.workspaceRoot,\n configFilePath\n );\n\n // Workaround for the `build$3 is not a function` error that we sometimes see in agents.\n // This should be removed later once we address the issue properly\n try {\n const importEsbuild = () => new Function('return import(\"esbuild\")')();\n await importEsbuild();\n } catch {\n // do nothing\n }\n const { resolveConfig } = await loadViteDynamicImport();\n const viteConfig = await resolveConfig(\n {\n configFile: absoluteConfigFilePath,\n mode: 'development',\n },\n 'build'\n );\n\n const { buildOutputs, testOutputs, hasTest, isBuildable } = getOutputs(\n viteConfig,\n projectRoot,\n context.workspaceRoot\n );\n\n const namedInputs = getNamedInputs(projectRoot, context);\n\n const targets: Record<string, TargetConfiguration> = {};\n\n // If file is not vitest.config and buildable, create targets for build, serve, preview and serve-static\n const hasRemixPlugin =\n viteConfig.plugins && viteConfig.plugins.some((p) => p.name === 'remix');\n if (\n !configFilePath.includes('vitest.config') &&\n !hasRemixPlugin &&\n isBuildable\n ) {\n targets[options.buildTargetName] = await buildTarget(\n options.buildTargetName,\n namedInputs,\n buildOutputs,\n projectRoot\n );\n\n targets[options.serveTargetName] = serveTarget(projectRoot);\n\n targets[options.previewTargetName] = previewTarget(projectRoot);\n\n targets[options.serveStaticTargetName] = serveStaticTarget(options) as {};\n }\n\n // if file is vitest.config or vite.config has definition for test, create target for test\n if (configFilePath.includes('vitest.config') || hasTest) {\n targets[options.testTargetName] = await testTarget(\n namedInputs,\n testOutputs,\n projectRoot\n );\n }\n\n const metadata = {};\n return { targets, metadata };\n}\n\nasync function buildTarget(\n buildTargetName: string,\n namedInputs: {\n [inputName: string]: any[];\n },\n outputs: string[],\n projectRoot: string\n) {\n return {\n command: `vite build`,\n options: { cwd: joinPathFragments(projectRoot) },\n cache: true,\n dependsOn: [`^${buildTargetName}`],\n inputs: [\n ...('production' in namedInputs\n ? ['production', '^production']\n : ['default', '^default']),\n {\n externalDependencies: ['vite'],\n },\n ],\n outputs,\n };\n}\n\nfunction serveTarget(projectRoot: string) {\n const targetConfig: TargetConfiguration = {\n command: `vite serve`,\n options: {\n cwd: joinPathFragments(projectRoot),\n },\n };\n\n return targetConfig;\n}\n\nfunction previewTarget(projectRoot: string) {\n const targetConfig: TargetConfiguration = {\n command: `vite preview`,\n options: {\n cwd: joinPathFragments(projectRoot),\n },\n };\n\n return targetConfig;\n}\n\nasync function testTarget(\n namedInputs: {\n [inputName: string]: any[];\n },\n outputs: string[],\n projectRoot: string\n) {\n return {\n command: `vitest`,\n options: { cwd: joinPathFragments(projectRoot) },\n cache: true,\n inputs: [\n ...('production' in namedInputs\n ? ['default', '^production']\n : ['default', '^default']),\n {\n externalDependencies: ['vitest'],\n },\n { env: 'CI' },\n ],\n outputs,\n };\n}\n\nfunction serveStaticTarget(options: VitePluginOptions) {\n const targetConfig: TargetConfiguration = {\n executor: '@nx/web:file-server',\n options: {\n buildTarget: `${options.buildTargetName}`,\n spa: true,\n },\n };\n\n return targetConfig;\n}\n\nfunction getOutputs(\n viteConfig: Record<string, any> | undefined,\n projectRoot: string,\n workspaceRoot: string\n): {\n buildOutputs: string[];\n testOutputs: string[];\n hasTest: boolean;\n isBuildable: boolean;\n} {\n const { build, test } = viteConfig;\n\n const buildOutputPath = normalizeOutputPath(\n build?.outDir,\n projectRoot,\n workspaceRoot,\n 'dist'\n );\n\n const isBuildable =\n build?.lib ||\n build?.rollupOptions?.inputs ||\n existsSync(join(workspaceRoot, projectRoot, 'index.html'));\n\n const reportsDirectoryPath = normalizeOutputPath(\n test?.coverage?.reportsDirectory,\n projectRoot,\n workspaceRoot,\n 'coverage'\n );\n\n return {\n buildOutputs: [buildOutputPath],\n testOutputs: [reportsDirectoryPath],\n hasTest: !!test,\n isBuildable,\n };\n}\n\nfunction normalizeOutputPath(\n outputPath: string | undefined,\n projectRoot: string,\n workspaceRoot: string,\n path: 'coverage' | 'dist'\n): string | undefined {\n if (!outputPath) {\n if (projectRoot === '.') {\n return `{projectRoot}/${path}`;\n } else {\n return `{workspaceRoot}/${path}/{projectRoot}`;\n }\n } else {\n if (isAbsolute(outputPath)) {\n return `{workspaceRoot}/${relative(workspaceRoot, outputPath)}`;\n } else {\n if (outputPath.startsWith('..')) {\n return join('{workspaceRoot}', join(projectRoot, outputPath));\n } else {\n return join('{projectRoot}', outputPath);\n }\n }\n }\n}\n\nfunction normalizeOptions(options: VitePluginOptions): VitePluginOptions {\n options ??= {};\n options.buildTargetName ??= 'build';\n options.serveTargetName ??= 'serve';\n options.previewTargetName ??= 'preview';\n options.testTargetName ??= 'test';\n options.serveStaticTargetName ??= 'serve-static';\n return options;\n}\n"],"names":["createDependencies","createNodes","createNodesV2","readTargetsCache","cachePath","existsSync","readJsonFile","writeTargetsToCache","results","writeJsonFile","viteVitestConfigGlob","configFilePaths","options","context","optionsHash","hashObject","join","workspaceDataDirectory","targetsCache","createNodesFromFiles","configFile","createNodesInternal","configFilePath","logger","warn","hash","projectRoot","dirname","siblingFiles","readdirSync","workspaceRoot","includes","normalizedOptions","normalizeOptions","calculateHashForCreateNodes","getLockFileName","detectPackageManager","buildViteTargets","targets","metadata","projects","root","absoluteConfigFilePath","joinPathFragments","importEsbuild","Function","resolveConfig","loadViteDynamicImport","viteConfig","mode","buildOutputs","testOutputs","hasTest","isBuildable","getOutputs","namedInputs","getNamedInputs","hasRemixPlugin","plugins","some","p","name","buildTargetName","buildTarget","serveTargetName","serveTarget","previewTargetName","previewTarget","serveStaticTargetName","serveStaticTarget","testTargetName","testTarget","outputs","command","cwd","cache","dependsOn","inputs","externalDependencies","targetConfig","env","executor","spa","build","test","buildOutputPath","normalizeOutputPath","outDir","lib","rollupOptions","reportsDirectoryPath","coverage","reportsDirectory","outputPath","path","isAbsolute","relative","startsWith"],"rangeMappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;","mappings":";;;;;;;;IA2CaA,kBAAkB;eAAlBA;;IA0BAC,WAAW;eAAXA;;IApBAC,aAAa;eAAbA;;;wBApCN;sBAC6C;gCACrB;oBACS;6CACI;gCACL;oBACP;+BACM;4BACX;AAW3B,SAASC,iBAAiBC,SAAiB;IACzC,OAAOC,IAAAA,cAAU,EAACD,aAAaE,IAAAA,oBAAY,EAACF,aAAa,CAAC;AAC5D;AAEA,SAASG,oBAAoBH,SAAS,EAAEI,OAAqC;IAC3EC,IAAAA,qBAAa,EAACL,WAAWI;AAC3B;AAKO,MAAMR,qBAAyC;IACpD,OAAO,EAAE;AACX;AAEA,MA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AAIA,WAAWI,UAAU,CAAC,OAAO;gBAC/B,OAAOjF,IAAAA,UAAI,EAAC,mBAAmBA,IAAAA,UAAI,EAACU,aAAamE;YACnD,OAAO;gBACL,OAAO7E,IAAAA,UAAI,EAAC,iBAAiB6E;YAC/B;QACF;IACF;AACF;AAEA,SAAS5D,iBAAiBrB,OAA0B;QAElDA,UACAA,WACAA,WACAA,WACAA;IALAA,kBAAAA,UAAAA,UAAY,CAAC;;IACbA,qBAAAA,WAAAA,SAAQkD,8CAARlD,SAAQkD,kBAAoB;;IAC5BlD,qBAAAA,YAAAA,SAAQoD,8CAARpD,UAAQoD,kBAAoB;;IAC5BpD,uBAAAA,YAAAA,SAAQsD,kDAARtD,UAAQsD,oBAAsB;;IAC9BtD,oBAAAA,YAAAA,SAAQ0D,4CAAR1D,UAAQ0D,iBAAmB;;IAC3B1D,2BAAAA,YAAAA,SAAQwD,0DAARxD,UAAQwD,wBAA0B;IAClC,OAAOxD;AACT"}
|
|
1
|
+
{"version":3,"sources":["../../../../../packages/vite/src/plugins/plugin.ts"],"sourcesContent":["import {\n CreateDependencies,\n CreateNodes,\n CreateNodesContext,\n createNodesFromFiles,\n CreateNodesV2,\n detectPackageManager,\n joinPathFragments,\n logger,\n ProjectConfiguration,\n readJsonFile,\n TargetConfiguration,\n writeJsonFile,\n} from '@nx/devkit';\nimport { dirname, isAbsolute, join, relative } from 'path';\nimport { getNamedInputs } from '@nx/devkit/src/utils/get-named-inputs';\nimport { existsSync, readdirSync } from 'fs';\nimport { calculateHashForCreateNodes } from '@nx/devkit/src/utils/calculate-hash-for-create-nodes';\nimport { workspaceDataDirectory } from 'nx/src/utils/cache-directory';\nimport { getLockFileName } from '@nx/js';\nimport { loadViteDynamicImport } from '../utils/executor-utils';\nimport { hashObject } from 'nx/src/hasher/file-hasher';\n\nexport interface VitePluginOptions {\n buildTargetName?: string;\n testTargetName?: string;\n serveTargetName?: string;\n previewTargetName?: string;\n serveStaticTargetName?: string;\n}\ntype ViteTargets = Pick<ProjectConfiguration, 'targets' | 'metadata'>;\n\nfunction readTargetsCache(cachePath: string): Record<string, ViteTargets> {\n return existsSync(cachePath) ? readJsonFile(cachePath) : {};\n}\n\nfunction writeTargetsToCache(cachePath, results?: Record<string, ViteTargets>) {\n writeJsonFile(cachePath, results);\n}\n\n/**\n * @deprecated The 'createDependencies' function is now a no-op. This functionality is included in 'createNodesV2'.\n */\nexport const createDependencies: CreateDependencies = () => {\n return [];\n};\n\nconst viteVitestConfigGlob = '**/{vite,vitest}.config.{js,ts,mjs,mts,cjs,cts}';\n\nexport const createNodesV2: CreateNodesV2<VitePluginOptions> = [\n viteVitestConfigGlob,\n async (configFilePaths, options, context) => {\n const optionsHash = hashObject(options);\n const cachePath = join(workspaceDataDirectory, `vite-${optionsHash}.hash`);\n const targetsCache = readTargetsCache(cachePath);\n try {\n return await createNodesFromFiles(\n (configFile, options, context) =>\n createNodesInternal(configFile, options, context, targetsCache),\n configFilePaths,\n options,\n context\n );\n } finally {\n writeTargetsToCache(cachePath, targetsCache);\n }\n },\n];\n\nexport const createNodes: CreateNodes<VitePluginOptions> = [\n viteVitestConfigGlob,\n async (configFilePath, options, context) => {\n logger.warn(\n '`createNodes` is deprecated. Update your plugin to utilize createNodesV2 instead. In Nx 20, this will change to the createNodesV2 API.'\n );\n return createNodesInternal(configFilePath, options, context, {});\n },\n];\n\nasync function createNodesInternal(\n configFilePath: string,\n options: VitePluginOptions,\n context: CreateNodesContext,\n targetsCache: Record<string, ViteTargets>\n) {\n const projectRoot = dirname(configFilePath);\n // Do not create a project if package.json and project.json isn't there.\n const siblingFiles = readdirSync(join(context.workspaceRoot, projectRoot));\n if (\n !siblingFiles.includes('package.json') &&\n !siblingFiles.includes('project.json')\n ) {\n return {};\n }\n\n const normalizedOptions = normalizeOptions(options);\n\n // We do not want to alter how the hash is calculated, so appending the config file path to the hash\n // to prevent vite/vitest files overwriting the target cache created by the other\n const hash =\n (await calculateHashForCreateNodes(\n projectRoot,\n normalizedOptions,\n context,\n [getLockFileName(detectPackageManager(context.workspaceRoot))]\n )) + configFilePath;\n\n targetsCache[hash] ??= await buildViteTargets(\n configFilePath,\n projectRoot,\n normalizedOptions,\n context\n );\n\n const { targets, metadata } = targetsCache[hash];\n const project: ProjectConfiguration = {\n root: projectRoot,\n targets,\n metadata,\n };\n\n // If project is buildable, then the project type.\n // If it is not buildable, then leave it to other plugins/project.json to set the project type.\n if (project.targets[options.buildTargetName]) {\n project.projectType = project.targets[options.serveTargetName]\n ? 'application'\n : 'library';\n }\n\n return {\n projects: {\n [projectRoot]: project,\n },\n };\n}\n\nasync function buildViteTargets(\n configFilePath: string,\n projectRoot: string,\n options: VitePluginOptions,\n context: CreateNodesContext\n): Promise<ViteTargets> {\n const absoluteConfigFilePath = joinPathFragments(\n context.workspaceRoot,\n configFilePath\n );\n // Workaround for the `build$3 is not a function` error that we sometimes see in agents.\n // This should be removed later once we address the issue properly\n try {\n const importEsbuild = () => new Function('return import(\"esbuild\")')();\n await importEsbuild();\n } catch {\n // do nothing\n }\n const { resolveConfig } = await loadViteDynamicImport();\n const viteConfig = await resolveConfig(\n {\n configFile: absoluteConfigFilePath,\n mode: 'development',\n },\n 'build'\n );\n\n const { buildOutputs, testOutputs, hasTest, isBuildable } = getOutputs(\n viteConfig,\n projectRoot,\n context.workspaceRoot\n );\n\n const namedInputs = getNamedInputs(projectRoot, context);\n\n const targets: Record<string, TargetConfiguration> = {};\n\n // If file is not vitest.config and buildable, create targets for build, serve, preview and serve-static\n const hasRemixPlugin =\n viteConfig.plugins && viteConfig.plugins.some((p) => p.name === 'remix');\n if (\n !configFilePath.includes('vitest.config') &&\n !hasRemixPlugin &&\n isBuildable\n ) {\n targets[options.buildTargetName] = await buildTarget(\n options.buildTargetName,\n namedInputs,\n buildOutputs,\n projectRoot\n );\n\n // If running in library mode, then there is nothing to serve.\n if (!viteConfig.build?.lib) {\n targets[options.serveTargetName] = serveTarget(projectRoot);\n targets[options.previewTargetName] = previewTarget(projectRoot);\n targets[options.serveStaticTargetName] = serveStaticTarget(options) as {};\n }\n }\n\n // if file is vitest.config or vite.config has definition for test, create target for test\n if (configFilePath.includes('vitest.config') || hasTest) {\n targets[options.testTargetName] = await testTarget(\n namedInputs,\n testOutputs,\n projectRoot\n );\n }\n\n const metadata = {};\n return { targets, metadata };\n}\n\nasync function buildTarget(\n buildTargetName: string,\n namedInputs: {\n [inputName: string]: any[];\n },\n outputs: string[],\n projectRoot: string\n) {\n return {\n command: `vite build`,\n options: { cwd: joinPathFragments(projectRoot) },\n cache: true,\n dependsOn: [`^${buildTargetName}`],\n inputs: [\n ...('production' in namedInputs\n ? ['production', '^production']\n : ['default', '^default']),\n {\n externalDependencies: ['vite'],\n },\n ],\n outputs,\n };\n}\n\nfunction serveTarget(projectRoot: string) {\n const targetConfig: TargetConfiguration = {\n command: `vite serve`,\n options: {\n cwd: joinPathFragments(projectRoot),\n },\n };\n\n return targetConfig;\n}\n\nfunction previewTarget(projectRoot: string) {\n const targetConfig: TargetConfiguration = {\n command: `vite preview`,\n options: {\n cwd: joinPathFragments(projectRoot),\n },\n };\n\n return targetConfig;\n}\n\nasync function testTarget(\n namedInputs: {\n [inputName: string]: any[];\n },\n outputs: string[],\n projectRoot: string\n) {\n return {\n command: `vitest`,\n options: { cwd: joinPathFragments(projectRoot) },\n cache: true,\n inputs: [\n ...('production' in namedInputs\n ? ['default', '^production']\n : ['default', '^default']),\n {\n externalDependencies: ['vitest'],\n },\n { env: 'CI' },\n ],\n outputs,\n };\n}\n\nfunction serveStaticTarget(options: VitePluginOptions) {\n const targetConfig: TargetConfiguration = {\n executor: '@nx/web:file-server',\n options: {\n buildTarget: `${options.buildTargetName}`,\n spa: true,\n },\n };\n\n return targetConfig;\n}\n\nfunction getOutputs(\n viteConfig: Record<string, any> | undefined,\n projectRoot: string,\n workspaceRoot: string\n): {\n buildOutputs: string[];\n testOutputs: string[];\n hasTest: boolean;\n isBuildable: boolean;\n} {\n const { build, test } = viteConfig;\n\n const buildOutputPath = normalizeOutputPath(\n build?.outDir,\n projectRoot,\n workspaceRoot,\n 'dist'\n );\n\n const isBuildable =\n build?.lib ||\n build?.rollupOptions?.inputs ||\n existsSync(join(workspaceRoot, projectRoot, 'index.html'));\n\n const reportsDirectoryPath = normalizeOutputPath(\n test?.coverage?.reportsDirectory,\n projectRoot,\n workspaceRoot,\n 'coverage'\n );\n\n return {\n buildOutputs: [buildOutputPath],\n testOutputs: [reportsDirectoryPath],\n hasTest: !!test,\n isBuildable,\n };\n}\n\nfunction normalizeOutputPath(\n outputPath: string | undefined,\n projectRoot: string,\n workspaceRoot: string,\n path: 'coverage' | 'dist'\n): string | undefined {\n if (!outputPath) {\n if (projectRoot === '.') {\n return `{projectRoot}/${path}`;\n } else {\n return `{workspaceRoot}/${path}/{projectRoot}`;\n }\n } else {\n if (isAbsolute(outputPath)) {\n return `{workspaceRoot}/${relative(workspaceRoot, outputPath)}`;\n } else {\n if (outputPath.startsWith('..')) {\n return join('{workspaceRoot}', join(projectRoot, outputPath));\n } else {\n return join('{projectRoot}', outputPath);\n }\n }\n }\n}\n\nfunction normalizeOptions(options: VitePluginOptions): VitePluginOptions {\n options ??= {};\n options.buildTargetName ??= 'build';\n options.serveTargetName ??= 'serve';\n options.previewTargetName ??= 'preview';\n options.testTargetName ??= 'test';\n options.serveStaticTargetName ??= 'serve-static';\n return options;\n}\n"],"names":["createDependencies","createNodes","createNodesV2","readTargetsCache","cachePath","existsSync","readJsonFile","writeTargetsToCache","results","writeJsonFile","viteVitestConfigGlob","configFilePaths","options","context","optionsHash","hashObject","join","workspaceDataDirectory","targetsCache","createNodesFromFiles","configFile","createNodesInternal","configFilePath","logger","warn","hash","projectRoot","dirname","siblingFiles","readdirSync","workspaceRoot","includes","normalizedOptions","normalizeOptions","calculateHashForCreateNodes","getLockFileName","detectPackageManager","buildViteTargets","targets","metadata","project","root","buildTargetName","projectType","serveTargetName","projects","absoluteConfigFilePath","joinPathFragments","importEsbuild","Function","resolveConfig","loadViteDynamicImport","viteConfig","mode","buildOutputs","testOutputs","hasTest","isBuildable","getOutputs","namedInputs","getNamedInputs","hasRemixPlugin","plugins","some","p","name","buildTarget","build","lib","serveTarget","previewTargetName","previewTarget","serveStaticTargetName","serveStaticTarget","testTargetName","testTarget","outputs","command","cwd","cache","dependsOn","inputs","externalDependencies","targetConfig","env","executor","spa","test","buildOutputPath","normalizeOutputPath","outDir","rollupOptions","reportsDirectoryPath","coverage","reportsDirectory","outputPath","path","isAbsolute","relative","startsWith"],"rangeMappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;","mappings":";;;;;;;;IA2CaA,kBAAkB;eAAlBA;;IA0BAC,WAAW;eAAXA;;IApBAC,aAAa;eAAbA;;;wBApCN;sBAC6C;gCACrB;oBACS;6CACI;gCACL;oBACP;+BACM;4BACX;AAW3B,SAASC,iBAAiBC,SAAiB;IACzC,OAAOC,IAAAA,cAAU,EAACD,aAAaE,IAAAA,oBAAY,EAACF,aAAa,CAAC;AAC5D;AAEA,SAASG,oBAAoBH,SAAS,EAAEI,OAAqC;IAC3EC,IAAAA,qBAAa,EAACL,WAAWI;AAC3B;AAKO,MAAMR,qBAAyC;IACpD,OAAO,EAAE;AACX;AAEA,MAAMU,uBAAuB;AAEtB,MAAMR,gBAAkD;IAC7DQ;IACA,OAAOC,iBAAiBC,SAASC;QAC/B,MAAMC,cAAcC,IAAAA,sBAAU,EAACH;QAC/B,MAAMR,YAAYY,IAAAA,UAAI,EAACC,sCAAsB,EAAE,CAAC,KAAK,EAAEH,YAAY,KAAK,CAAC;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