@ng-native/migrate 0.18.0 → 0.18.1
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/migrations.cjs +8 -0
- package/package.json +1 -1
- package/vitest-tsconfig-paths.cjs +51 -0
package/migrations.cjs
CHANGED
|
@@ -26,6 +26,7 @@ const { splitStoreAndPlayer } = require('./split-store-and-player.cjs');
|
|
|
26
26
|
const { stopWatchingConditions } = require('./stop-watching-conditions.cjs');
|
|
27
27
|
const { syncAppVersions } = require('./sync-app-versions.cjs');
|
|
28
28
|
const { trackingAvailableGetter } = require('./tracking-available-getter.cjs');
|
|
29
|
+
const { vitestTsconfigPaths } = require('./vitest-tsconfig-paths.cjs');
|
|
29
30
|
const { version } = require('./package.json');
|
|
30
31
|
|
|
31
32
|
/** @type {Migration[]} */
|
|
@@ -89,6 +90,13 @@ const migrations = [
|
|
|
89
90
|
"Keep what watchConditions returns in each app's entry point and stop it as the app is destroyed.",
|
|
90
91
|
run: stopWatchingConditions,
|
|
91
92
|
},
|
|
93
|
+
{
|
|
94
|
+
name: 'vitest-tsconfig-paths',
|
|
95
|
+
version: '0.18.1',
|
|
96
|
+
description:
|
|
97
|
+
"Resolve the workspace's path aliases in Nx Vitest configs with vite-tsconfig-paths, as nxViteTsPaths does nothing from Nx 24.",
|
|
98
|
+
run: vitestTsconfigPaths,
|
|
99
|
+
},
|
|
92
100
|
];
|
|
93
101
|
|
|
94
102
|
module.exports = { migrations };
|
package/package.json
CHANGED
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `@ng-native/nx` wrote `nxViteTsPaths()` from `@nx/vite` into the Vitest config of an app or
|
|
3
|
+
* library in a workspace with tsconfig path aliases. From Nx 24 that export is an inert stub, so a
|
|
4
|
+
* test importing one of the workspace's libraries failed with "Cannot find package '@org/ui'". The
|
|
5
|
+
* generators now write `vite-tsconfig-paths`, as Nx 24 does in its own Vite configs.
|
|
6
|
+
*
|
|
7
|
+
* Each `vitest.config.mts` that runs `ngNative()` and imports `nxViteTsPaths` from `@nx/vite`
|
|
8
|
+
* imports `tsconfigPaths` from `vite-tsconfig-paths` in its place, and the root `package.json`
|
|
9
|
+
* gains `vite-tsconfig-paths` when it lists neither. A config the generator did not write is left
|
|
10
|
+
* as it is.
|
|
11
|
+
*/
|
|
12
|
+
const { files } = require('./host.cjs');
|
|
13
|
+
const { formatted } = require('./sync-app-versions.cjs');
|
|
14
|
+
|
|
15
|
+
// Either quote, as the workspace's Prettier formats it.
|
|
16
|
+
const FROM =
|
|
17
|
+
/import \{ nxViteTsPaths \} from (['"])@nx\/vite\/plugins\/nx-tsconfig-paths\.plugin\1;/;
|
|
18
|
+
const TO = 'import tsconfigPaths from $1vite-tsconfig-paths$1;';
|
|
19
|
+
const DEPENDENCY = { name: 'vite-tsconfig-paths', range: '^5.1.4' };
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* Rewrites each config the generators wrote, and answers whether there was one.
|
|
23
|
+
*
|
|
24
|
+
* @param {import('./host.cjs').Host} host
|
|
25
|
+
*/
|
|
26
|
+
function rewriteConfigs(host) {
|
|
27
|
+
let changed = false;
|
|
28
|
+
for (const file of files(host)) {
|
|
29
|
+
if (file !== 'vitest.config.mts' && !file.endsWith('/vitest.config.mts')) continue;
|
|
30
|
+
const text = host.read(file) ?? '';
|
|
31
|
+
if (!FROM.test(text) || !text.includes('@ng-native/testing/vitest')) continue;
|
|
32
|
+
host.write(file, text.replace(FROM, TO).replace(/\bnxViteTsPaths\(\)/g, 'tsconfigPaths()'));
|
|
33
|
+
changed = true;
|
|
34
|
+
}
|
|
35
|
+
return changed;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
/** @param {import('./host.cjs').Host} host */
|
|
39
|
+
function vitestTsconfigPaths(host) {
|
|
40
|
+
const original = rewriteConfigs(host) ? host.read('package.json') : null;
|
|
41
|
+
if (original === null) return [];
|
|
42
|
+
const manifest = JSON.parse(original);
|
|
43
|
+
if (manifest.dependencies?.[DEPENDENCY.name] || manifest.devDependencies?.[DEPENDENCY.name]) {
|
|
44
|
+
return [];
|
|
45
|
+
}
|
|
46
|
+
manifest.devDependencies = { ...manifest.devDependencies, [DEPENDENCY.name]: DEPENDENCY.range };
|
|
47
|
+
host.write('package.json', formatted(manifest, original));
|
|
48
|
+
return ['Install vite-tsconfig-paths, which the root package.json now lists.'];
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
module.exports = { vitestTsconfigPaths };
|