@nx/vite 19.0.6 → 19.0.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nx/vite",
3
- "version": "19.0.6",
3
+ "version": "19.0.8",
4
4
  "private": false,
5
5
  "description": "The Nx Plugin for building and testing applications using Vite",
6
6
  "repository": {
@@ -12,7 +12,8 @@
12
12
  "Monorepo",
13
13
  "Vite",
14
14
  "Web",
15
- "CLI"
15
+ "CLI",
16
+ "Front-end"
16
17
  ],
17
18
  "main": "./index",
18
19
  "typings": "./index.d.ts",
@@ -29,13 +30,13 @@
29
30
  "migrations": "./migrations.json"
30
31
  },
31
32
  "dependencies": {
32
- "@nx/devkit": "19.0.6",
33
+ "@nx/devkit": "19.0.8",
33
34
  "@phenomnomnominal/tsquery": "~5.0.1",
34
35
  "@swc/helpers": "~0.5.0",
35
36
  "enquirer": "~2.3.6",
36
- "@nx/js": "19.0.6",
37
+ "@nx/js": "19.0.8",
37
38
  "tsconfig-paths": "^4.1.2",
38
- "@nrwl/vite": "19.0.6"
39
+ "@nrwl/vite": "19.0.8"
39
40
  },
40
41
  "peerDependencies": {
41
42
  "vite": "^5.0.0",
@@ -13,6 +13,7 @@ _export(exports, {
13
13
  return createNodes;
14
14
  }
15
15
  });
16
+ const _extends = require("@swc/helpers/_/_extends");
16
17
  const _devkit = require("@nx/devkit");
17
18
  const _path = require("path");
18
19
  const _getnamedinputs = require("@nx/devkit/src/utils/get-named-inputs");
@@ -22,21 +23,22 @@ const _cachedirectory = require("nx/src/utils/cache-directory");
22
23
  const _js = require("@nx/js");
23
24
  const _executorutils = require("../utils/executor-utils");
24
25
  const cachePath = (0, _path.join)(_cachedirectory.projectGraphCacheDirectory, 'vite.hash');
25
- const targetsCache = (0, _fs.existsSync)(cachePath) ? readTargetsCache() : {};
26
- const calculatedTargets = {};
26
+ const targetsCache = readTargetsCache();
27
27
  function readTargetsCache() {
28
- return (0, _devkit.readJsonFile)(cachePath);
28
+ return (0, _fs.existsSync)(cachePath) ? (0, _devkit.readJsonFile)(cachePath) : {};
29
29
  }
30
- function writeTargetsToCache(targets) {
31
- (0, _devkit.writeJsonFile)(cachePath, targets);
30
+ function writeTargetsToCache() {
31
+ const oldCache = readTargetsCache();
32
+ (0, _devkit.writeJsonFile)(cachePath, _extends._({}, oldCache, targetsCache));
32
33
  }
33
34
  const createDependencies = ()=>{
34
- writeTargetsToCache(calculatedTargets);
35
+ writeTargetsToCache();
35
36
  return [];
36
37
  };
37
38
  const createNodes = [
38
39
  '**/{vite,vitest}.config.{js,ts,mjs,mts,cjs,cts}',
39
40
  async (configFilePath, options, context)=>{
41
+ var _targetsCache, _hash;
40
42
  const projectRoot = (0, _path.dirname)(configFilePath);
41
43
  // Do not create a project if package.json and project.json isn't there.
42
44
  const siblingFiles = (0, _fs.readdirSync)((0, _path.join)(context.workspaceRoot, projectRoot));
@@ -49,13 +51,13 @@ const createNodes = [
49
51
  const hash = (0, _calculatehashforcreatenodes.calculateHashForCreateNodes)(projectRoot, options, context, [
50
52
  (0, _js.getLockFileName)((0, _devkit.detectPackageManager)(context.workspaceRoot))
51
53
  ]) + configFilePath;
52
- const targets = targetsCache[hash] ? targetsCache[hash] : await buildViteTargets(configFilePath, projectRoot, options, context);
53
- calculatedTargets[hash] = targets;
54
+ var _;
55
+ (_ = (_targetsCache = targetsCache)[_hash = hash]) != null ? _ : _targetsCache[_hash] = await buildViteTargets(configFilePath, projectRoot, options, context);
54
56
  return {
55
57
  projects: {
56
58
  [projectRoot]: {
57
59
  root: projectRoot,
58
- targets
60
+ targets: targetsCache[hash]
59
61
  }
60
62
  }
61
63
  };
@@ -142,8 +144,7 @@ async function testTarget(namedInputs, outputs, projectRoot) {
142
144
  return {
143
145
  command: `vitest`,
144
146
  options: {
145
- cwd: (0, _devkit.joinPathFragments)(projectRoot),
146
- watch: false
147
+ cwd: (0, _devkit.joinPathFragments)(projectRoot)
147
148
  },
148
149
  cache: true,
149
150
  inputs: [
@@ -158,6 +159,9 @@ async function testTarget(namedInputs, outputs, projectRoot) {
158
159
  externalDependencies: [
159
160
  'vitest'
160
161
  ]
162
+ },
163
+ {
164
+ env: 'CI'
161
165
  }
162
166
  ],
163
167
  outputs
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../../packages/vite/src/plugins/plugin.ts"],"sourcesContent":["import {\n CreateDependencies,\n CreateNodes,\n CreateNodesContext,\n detectPackageManager,\n joinPathFragments,\n readJsonFile,\n TargetConfiguration,\n workspaceRoot,\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 { projectGraphCacheDirectory } from 'nx/src/utils/cache-directory';\nimport { getLockFileName } from '@nx/js';\nimport { loadViteDynamicImport } from '../utils/executor-utils';\n\nexport interface VitePluginOptions {\n buildTargetName?: string;\n testTargetName?: string;\n serveTargetName?: string;\n previewTargetName?: string;\n serveStaticTargetName?: string;\n}\n\nconst cachePath = join(projectGraphCacheDirectory, 'vite.hash');\nconst targetsCache = existsSync(cachePath) ? readTargetsCache() : {};\n\nconst calculatedTargets: Record<\n string,\n Record<string, TargetConfiguration>\n> = {};\n\nfunction readTargetsCache(): Record<\n string,\n Record<string, TargetConfiguration>\n> {\n return readJsonFile(cachePath);\n}\n\nfunction writeTargetsToCache(\n targets: Record<string, Record<string, TargetConfiguration>>\n) {\n writeJsonFile(cachePath, targets);\n}\n\nexport const createDependencies: CreateDependencies = () => {\n writeTargetsToCache(calculatedTargets);\n return [];\n};\n\nexport const createNodes: CreateNodes<VitePluginOptions> = [\n '**/{vite,vitest}.config.{js,ts,mjs,mts,cjs,cts}',\n async (configFilePath, options, context) => {\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 options = 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 calculateHashForCreateNodes(projectRoot, options, context, [\n getLockFileName(detectPackageManager(context.workspaceRoot)),\n ]) + configFilePath;\n const targets = targetsCache[hash]\n ? targetsCache[hash]\n : await buildViteTargets(configFilePath, projectRoot, options, context);\n\n calculatedTargets[hash] = targets;\n\n return {\n projects: {\n [projectRoot]: {\n root: projectRoot,\n targets,\n },\n },\n };\n },\n];\n\nasync function buildViteTargets(\n configFilePath: string,\n projectRoot: string,\n options: VitePluginOptions,\n context: CreateNodesContext\n) {\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 );\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 return targets;\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), watch: false },\n cache: true,\n inputs: [\n ...('production' in namedInputs\n ? ['default', '^production']\n : ['default', '^default']),\n {\n externalDependencies: ['vitest'],\n },\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): {\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 '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 '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 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","cachePath","join","projectGraphCacheDirectory","targetsCache","existsSync","readTargetsCache","calculatedTargets","readJsonFile","writeTargetsToCache","targets","writeJsonFile","configFilePath","options","context","projectRoot","dirname","siblingFiles","readdirSync","workspaceRoot","includes","normalizeOptions","hash","calculateHashForCreateNodes","getLockFileName","detectPackageManager","buildViteTargets","projects","root","absoluteConfigFilePath","joinPathFragments","importEsbuild","Function","resolveConfig","loadViteDynamicImport","viteConfig","configFile","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","watch","executor","spa","build","test","buildOutputPath","normalizeOutputPath","outDir","lib","rollupOptions","reportsDirectoryPath","coverage","reportsDirectory","outputPath","path","isAbsolute","relative","startsWith"],"mappings":";;;;;;;;IAgDaA,kBAAkB;eAAlBA;;IAKAC,WAAW;eAAXA;;;wBA3CN;sBAC6C;gCACrB;oBACS;6CACI;gCACD;oBACX;+BACM;AAUtC,MAAMC,YAAYC,IAAAA,UAAI,EAACC,0CAA0B,EAAE;AACnD,MAAMC,eAAeC,IAAAA,cAAU,EAACJ,aAAaK,qBAAqB,CAAC;AAEnE,MAAMC,oBAGF,CAAC;AAEL,SAASD;IAIP,OAAOE,IAAAA,oBAAY,EAACP;AACtB;AAEA,SAASQ,oBACPC,OAA4D;IAE5DC,IAAAA,qBAAa,EAACV,WAAWS;AAC3B;AAEO,MAAMX,qBAAyC;IACpDU,oBAAoBF;IACpB,OAAO,EAAE;AACX;AAEO,MAAMP,cAA8C;IACzD;IACA,OAAOY,gBAAgBC,SAASC;QAC9B,MAAMC,cAAcC,IAAAA,aAAO,EAACJ;QAC5B,wEAAwE;QACxE,MAAMK,eAAeC,IAAAA,eAAW,EAAChB,IAAAA,UAAI,EAACY,QAAQK,aAAa,EAAEJ;QAC7D,IACE,CAACE,aAAaG,QAAQ,CAAC,mBACvB,CAACH,aAAaG,QAAQ,CAAC,iBACvB;YACA,OAAO,CAAC;QACV;QAEAP,UAAUQ,iBAAiBR;QAE3B,oGAAoG;QACpG,iFAAiF;QACjF,MAAMS,OACJC,IAAAA,wDAA2B,EAACR,aAAaF,SAASC,SAAS;YACzDU,IAAAA,mBAAe,EAACC,IAAAA,4BAAoB,EAACX,QAAQK,aAAa;SAC3D,IAAIP;QACP,MAAMF,UAAUN,YAAY,CAACkB,KAAK,GAC9BlB,YAAY,CAACkB,KAAK,GAClB,MAAMI,iBAAiBd,gBAAgBG,aAAaF,SAASC;QAEjEP,iBAAiB,CAACe,KAAK,GA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AAS5D,iBAAiBR,OAA0B;QAElDA,UACAA,WACAA,WACAA,WACAA;IALAA,kBAAAA,UAAAA,UAAY,CAAC;;IACbA,qBAAAA,WAAAA,SAAQqC,8CAARrC,SAAQqC,kBAAoB;;IAC5BrC,qBAAAA,YAAAA,SAAQuC,8CAARvC,UAAQuC,kBAAoB;;IAC5BvC,uBAAAA,YAAAA,SAAQyC,kDAARzC,UAAQyC,oBAAsB;;IAC9BzC,oBAAAA,YAAAA,SAAQ6C,4CAAR7C,UAAQ6C,iBAAmB;;IAC3B7C,2BAAAA,YAAAA,SAAQ2C,0DAAR3C,UAAQ2C,wBAA0B;IAClC,OAAO3C;AACT"}
1
+ {"version":3,"sources":["../../../../../packages/vite/src/plugins/plugin.ts"],"sourcesContent":["import {\n CreateDependencies,\n CreateNodes,\n CreateNodesContext,\n detectPackageManager,\n joinPathFragments,\n readJsonFile,\n TargetConfiguration,\n workspaceRoot,\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 { projectGraphCacheDirectory } from 'nx/src/utils/cache-directory';\nimport { getLockFileName } from '@nx/js';\nimport { loadViteDynamicImport } from '../utils/executor-utils';\n\nexport interface VitePluginOptions {\n buildTargetName?: string;\n testTargetName?: string;\n serveTargetName?: string;\n previewTargetName?: string;\n serveStaticTargetName?: string;\n}\n\nconst cachePath = join(projectGraphCacheDirectory, 'vite.hash');\nconst targetsCache = readTargetsCache();\n\nfunction readTargetsCache(): Record<\n string,\n Record<string, TargetConfiguration>\n> {\n return existsSync(cachePath) ? readJsonFile(cachePath) : {};\n}\n\nfunction writeTargetsToCache() {\n const oldCache = readTargetsCache();\n writeJsonFile(cachePath, {\n ...oldCache,\n ...targetsCache,\n });\n}\n\nexport const createDependencies: CreateDependencies = () => {\n writeTargetsToCache();\n return [];\n};\n\nexport const createNodes: CreateNodes<VitePluginOptions> = [\n '**/{vite,vitest}.config.{js,ts,mjs,mts,cjs,cts}',\n async (configFilePath, options, context) => {\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 options = 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 calculateHashForCreateNodes(projectRoot, options, context, [\n getLockFileName(detectPackageManager(context.workspaceRoot)),\n ]) + configFilePath;\n\n targetsCache[hash] ??= await buildViteTargets(\n configFilePath,\n projectRoot,\n options,\n context\n );\n\n return {\n projects: {\n [projectRoot]: {\n root: projectRoot,\n targets: targetsCache[hash],\n },\n },\n };\n },\n];\n\nasync function buildViteTargets(\n configFilePath: string,\n projectRoot: string,\n options: VitePluginOptions,\n context: CreateNodesContext\n) {\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 );\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 return targets;\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): {\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 '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 '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 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","cachePath","join","projectGraphCacheDirectory","targetsCache","readTargetsCache","existsSync","readJsonFile","writeTargetsToCache","oldCache","writeJsonFile","configFilePath","options","context","hash","projectRoot","dirname","siblingFiles","readdirSync","workspaceRoot","includes","normalizeOptions","calculateHashForCreateNodes","getLockFileName","detectPackageManager","buildViteTargets","projects","root","targets","absoluteConfigFilePath","joinPathFragments","importEsbuild","Function","resolveConfig","loadViteDynamicImport","viteConfig","configFile","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"],"mappings":";;;;;;;;IA6CaA,kBAAkB;eAAlBA;;IAKAC,WAAW;eAAXA;;;;wBAxCN;sBAC6C;gCACrB;oBACS;6CACI;gCACD;oBACX;+BACM;AAUtC,MAAMC,YAAYC,IAAAA,UAAI,EAACC,0CAA0B,EAAE;AACnD,MAAMC,eAAeC;AAErB,SAASA;IAIP,OAAOC,IAAAA,cAAU,EAACL,aAAaM,IAAAA,oBAAY,EAACN,aAAa,CAAC;AAC5D;AAEA,SAASO;IACP,MAAMC,WAAWJ;IACjBK,IAAAA,qBAAa,EAACT,WAAW,eACpBQ,UACAL;AAEP;AAEO,MAAML,qBAAyC;IACpDS;IACA,OAAO,EAAE;AACX;AAEO,MAAMR,cAA8C;IACzD;IACA,OAAOW,gBAAgBC,SAASC;YAoB9BT,eAAaU;QAnBb,MAAMC,cAAcC,IAAAA,aAAO,EAACL;QAC5B,wEAAwE;QACxE,MAAMM,eAAeC,IAAAA,eAAW,EAAChB,IAAAA,UAAI,EAACW,QAAQM,aAAa,EAAEJ;QAC7D,IACE,CAACE,aAAaG,QAAQ,CAAC,mBACvB,CAACH,aAAaG,QAAQ,CAAC,iBACvB;YACA,OAAO,CAAC;QACV;QAEAR,UAAUS,iBAAiBT;QAE3B,oGAAoG;QACpG,iFAAiF;QACjF,MAAME,OACJQ,IAAAA,wDAA2B,EAACP,aAAaH,SAASC,SAAS;YACzDU,IAAAA,mBAAe,EAACC,IAAAA,4BAAoB,EAACX,QAAQM,aAAa;SAC3D,IAAIR;;QAEPP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