@nx/vite 23.3.0-beta.5 → 23.3.0-beta.6

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.
@@ -21,6 +21,7 @@ const nx_vite_build_coordination_plugin_1 = require("./nx-vite-build-coordinatio
21
21
  function nxViteTsPaths(options = {}) {
22
22
  (0, deprecation_1.warnNxViteTsPathsDeprecation)();
23
23
  let foundTsConfigPath;
24
+ let tsConfigPathsLoaded = false;
24
25
  let matchTsPathEsm;
25
26
  let matchTsPathEsmExact;
26
27
  let matchTsPathFallback;
@@ -55,6 +56,7 @@ function nxViteTsPaths(options = {}) {
55
56
  async configResolved(config) {
56
57
  projectRoot = config.root;
57
58
  projectRootFromWorkspaceRoot = (0, node_path_1.relative)(devkit_1.workspaceRoot, projectRoot);
59
+ tsConfigPathsLoaded = false;
58
60
  foundTsConfigPath = getTsConfig(process.env.NX_TSCONFIG_PATH ??
59
61
  (0, node_path_1.join)(devkit_1.workspaceRoot, 'tmp', projectRootFromWorkspaceRoot, process.env.NX_TASK_TARGET_TARGET ?? 'build', 'tsconfig.generated.json'));
60
62
  if (!foundTsConfigPath)
@@ -91,34 +93,10 @@ function nxViteTsPaths(options = {}) {
91
93
  }
92
94
  }
93
95
  }
94
- const parsed = (0, tsconfig_paths_1.loadConfig)(foundTsConfigPath);
95
- logIt('first parsed tsconfig: ', parsed);
96
- if (parsed.resultType === 'failed') {
97
- throw new Error(`Failed loading tsconfig at ${foundTsConfigPath}`);
98
- }
99
- // `loadConfig` derives `absoluteBaseUrl` from the leaf tsconfig, but
100
- // `paths` resolve against the config that declared them.
101
- const pathsBaseUrl = (0, js_1.resolvePathsBaseUrl)(foundTsConfigPath);
102
- tsConfigPathsEsm = { ...parsed, absoluteBaseUrl: pathsBaseUrl };
103
- matchTsPathEsm = (0, tsconfig_paths_1.createMatchPath)(pathsBaseUrl, parsed.paths, options.mainFields);
104
- matchTsPathEsmExact = createExactMatchPath(pathsBaseUrl, parsed.paths, options.mainFields);
105
- const rootLevelTsConfig = getTsConfig((0, node_path_1.join)(devkit_1.workspaceRoot, 'tsconfig.base.json'));
106
- // A workspace may have no root-level tsconfig at all. Passing no path to
107
- // `loadConfig` makes it search upwards from the cwd instead, which finds
108
- // an unrelated tsconfig whose directory is not this workspace.
109
- if (rootLevelTsConfig) {
110
- const rootLevelParsed = (0, tsconfig_paths_1.loadConfig)(rootLevelTsConfig);
111
- logIt('fallback parsed tsconfig: ', rootLevelParsed);
112
- if (rootLevelParsed.resultType === 'success') {
113
- const rootLevelPathsBaseUrl = (0, js_1.resolvePathsBaseUrl)(rootLevelTsConfig);
114
- tsConfigPathsFallback = {
115
- ...rootLevelParsed,
116
- absoluteBaseUrl: rootLevelPathsBaseUrl,
117
- };
118
- matchTsPathFallback = (0, tsconfig_paths_1.createMatchPath)(rootLevelPathsBaseUrl, rootLevelParsed.paths, ['main', 'module']);
119
- matchTsPathFallbackExact = createExactMatchPath(rootLevelPathsBaseUrl, rootLevelParsed.paths, ['main', 'module']);
120
- }
121
- }
96
+ // Graph construction resolves every config and never a module, so the
97
+ // parsing waits for the first `resolveId` there.
98
+ if (!global.NX_GRAPH_CREATION)
99
+ loadTsConfigPaths();
122
100
  },
123
101
  resolveId(importPath) {
124
102
  // Let other resolvers handle this path.
@@ -130,6 +108,8 @@ function nxViteTsPaths(options = {}) {
130
108
  // by tsconfig path mapping (which would incorrectly use baseUrl).
131
109
  if (importPath.startsWith('/'))
132
110
  return null;
111
+ if (!tsConfigPathsLoaded)
112
+ loadTsConfigPaths();
133
113
  let resolvedFile;
134
114
  try {
135
115
  resolvedFile =
@@ -179,6 +159,37 @@ function nxViteTsPaths(options = {}) {
179
159
  }
180
160
  },
181
161
  };
162
+ function loadTsConfigPaths() {
163
+ const parsed = (0, tsconfig_paths_1.loadConfig)(foundTsConfigPath);
164
+ logIt('first parsed tsconfig: ', parsed);
165
+ if (parsed.resultType === 'failed') {
166
+ throw new Error(`Failed loading tsconfig at ${foundTsConfigPath}`);
167
+ }
168
+ // `loadConfig` derives `absoluteBaseUrl` from the leaf tsconfig, but
169
+ // `paths` resolve against the config that declared them.
170
+ const pathsBaseUrl = (0, js_1.resolvePathsBaseUrl)(foundTsConfigPath);
171
+ tsConfigPathsEsm = { ...parsed, absoluteBaseUrl: pathsBaseUrl };
172
+ matchTsPathEsm = (0, tsconfig_paths_1.createMatchPath)(pathsBaseUrl, parsed.paths, options.mainFields);
173
+ matchTsPathEsmExact = createExactMatchPath(pathsBaseUrl, parsed.paths, options.mainFields);
174
+ const rootLevelTsConfig = getTsConfig((0, node_path_1.join)(devkit_1.workspaceRoot, 'tsconfig.base.json'));
175
+ // A workspace may have no root-level tsconfig at all. Passing no path to
176
+ // `loadConfig` makes it search upwards from the cwd instead, which finds
177
+ // an unrelated tsconfig whose directory is not this workspace.
178
+ if (rootLevelTsConfig) {
179
+ const rootLevelParsed = (0, tsconfig_paths_1.loadConfig)(rootLevelTsConfig);
180
+ logIt('fallback parsed tsconfig: ', rootLevelParsed);
181
+ if (rootLevelParsed.resultType === 'success') {
182
+ const rootLevelPathsBaseUrl = (0, js_1.resolvePathsBaseUrl)(rootLevelTsConfig);
183
+ tsConfigPathsFallback = {
184
+ ...rootLevelParsed,
185
+ absoluteBaseUrl: rootLevelPathsBaseUrl,
186
+ };
187
+ matchTsPathFallback = (0, tsconfig_paths_1.createMatchPath)(rootLevelPathsBaseUrl, rootLevelParsed.paths, ['main', 'module']);
188
+ matchTsPathFallbackExact = createExactMatchPath(rootLevelPathsBaseUrl, rootLevelParsed.paths, ['main', 'module']);
189
+ }
190
+ }
191
+ tsConfigPathsLoaded = true;
192
+ }
182
193
  function getTsConfig(preferredTsConfigPath) {
183
194
  const projectTsConfigPath = (0, options_utils_1.getProjectTsConfigPath)(projectRootFromWorkspaceRoot);
184
195
  return [
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nx/vite",
3
- "version": "23.3.0-beta.5",
3
+ "version": "23.3.0-beta.6",
4
4
  "private": false,
5
5
  "type": "commonjs",
6
6
  "files": [
@@ -94,10 +94,10 @@
94
94
  "supportsOptionalMigrations": true
95
95
  },
96
96
  "dependencies": {
97
- "@nx/devkit": "23.3.0-beta.5",
97
+ "@nx/devkit": "23.3.0-beta.6",
98
98
  "@phenomnomnominal/tsquery": "~6.2.0",
99
- "@nx/js": "23.3.0-beta.5",
100
- "@nx/vitest": "23.3.0-beta.5",
99
+ "@nx/js": "23.3.0-beta.6",
100
+ "@nx/vitest": "23.3.0-beta.6",
101
101
  "picomatch": "4.0.4",
102
102
  "tsconfig-paths": "^4.1.2",
103
103
  "semver": "^7.6.3",
@@ -105,8 +105,8 @@
105
105
  "ajv": "^8.0.0"
106
106
  },
107
107
  "devDependencies": {
108
- "@nx/eslint": "23.3.0-beta.5",
109
- "nx": "23.3.0-beta.5"
108
+ "@nx/eslint": "23.3.0-beta.6",
109
+ "nx": "23.3.0-beta.6"
110
110
  },
111
111
  "peerDependencies": {
112
112
  "vite": "^5.0.0 || ^6.0.0 || ^7.0.0 || ^8.0.0"