Skip to content

Commit b7ce5fc

Browse files
committed
fix(migrate): resolve constant external matchers
1 parent 3cc7b06 commit b7ce5fc

10 files changed

Lines changed: 335 additions & 65 deletions

File tree

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
const externalOptions = ['foo'];
2+
3+
export default {
4+
pack: [
5+
{
6+
external: externalOptions,
7+
skipNodeModulesBundle: true,
8+
inputOptions(options) { return { external: options.external }; },
9+
bundle: false,
10+
dts: { tsgo: true },
11+
},
12+
{
13+
external: externalOptions,
14+
deps: { skipNodeModulesBundle: true, dts: { neverBundle: ['types'] } },
15+
bundle: false,
16+
},
17+
],
18+
};

crates/vp_cli_snapshots/tests/cli_snapshots/fixtures/migration_pack_tsdown_023/manual.config.txt renamed to crates/vp_cli_snapshots/tests/cli_snapshots/fixtures/migration_pack_tsdown_023/external-constants.config.txt

File renamed without changes.

crates/vp_cli_snapshots/tests/cli_snapshots/fixtures/migration_pack_tsdown_023/external.config.txt

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
const externalOptions = ['foo', './external.js'];
2+
const externalAlias = externalOptions;
3+
14
export default {
25
pack: [
36
{
@@ -14,5 +17,19 @@ export default {
1417
external: ['foo', './external.js'],
1518
deps: { skipNodeModulesBundle: true },
1619
},
20+
{
21+
entry: 'src/index.ts',
22+
outDir: 'dist/constant',
23+
dts: false,
24+
external: externalOptions,
25+
skipNodeModulesBundle: true,
26+
},
27+
{
28+
entry: 'src/index.ts',
29+
outDir: 'dist/alias',
30+
dts: false,
31+
external: externalAlias,
32+
deps: { skipNodeModulesBundle: true },
33+
},
1734
],
1835
};

crates/vp_cli_snapshots/tests/cli_snapshots/fixtures/migration_pack_tsdown_023/snapshots.toml

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@ steps = [
3535
{ argv = ["vp", "pack"], snapshot = false },
3636
{ argv = ["vpt", "print-file", "dist/top/index.mjs"] },
3737
{ argv = ["vpt", "print-file", "dist/nested/index.mjs"] },
38+
{ argv = ["vpt", "print-file", "dist/constant/index.mjs"] },
39+
{ argv = ["vpt", "print-file", "dist/alias/index.mjs"] },
3840
{ argv = ["vp", "migrate", "--no-interactive"] },
3941
]
4042

@@ -58,13 +60,23 @@ steps = [
5860
]
5961

6062
[[case]]
61-
name = "migration_pack_tsdown_023_manual"
63+
name = "migration_pack_tsdown_023_external_constants"
6264
vp = "global"
63-
comment = "Report unsupported external matchers without changing the pack options."
65+
comment = "Migrate constant external references with both skip forms without a manual-migration warning."
6466
steps = [
65-
{ argv = ["vpt", "cp", "manual.config.txt", "vite.config.ts"], snapshot = false },
67+
{ argv = ["vpt", "cp", "external-constants.config.txt", "vite.config.ts"], snapshot = false },
6668
{ argv = ["vp", "migrate", "--no-interactive"] },
6769
{ argv = ["vpt", "print-file", "vite.config.ts"] },
6870
{ argv = ["vp", "migrate", "--no-interactive"] },
6971
{ argv = ["vpt", "print-file", "vite.config.ts"] },
7072
]
73+
74+
[[case]]
75+
name = "migration_pack_tsdown_023_external_conflicts"
76+
vp = "global"
77+
comment = "Report conflicting dependency rules while preserving the pack options."
78+
steps = [
79+
{ argv = ["vpt", "cp", "external-conflicts.config.txt", "vite.config.ts"], snapshot = false },
80+
{ argv = ["vp", "migrate", "--no-interactive"] },
81+
{ argv = ["vpt", "print-file", "vite.config.ts"] },
82+
]

crates/vp_cli_snapshots/tests/cli_snapshots/fixtures/migration_pack_tsdown_023/snapshots/migration_pack_tsdown_023_external.md

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,9 @@ VITE+ - The Unified Toolchain for the Web
2525
## `vpt print-file vite.config.ts`
2626

2727
```
28+
const externalOptions = ['foo', './external.js'];
29+
const externalAlias = externalOptions;
30+
2831
export default {
2932
pack: [
3033
{
@@ -41,6 +44,20 @@ export default {
4144
inputOptions: { external: ['foo', './external.js'] },
4245
deps: { resolveDepSubpath: true, neverBundle: true },
4346
},
47+
{
48+
entry: 'src/index.ts',
49+
outDir: 'dist/constant',
50+
dts: false,
51+
inputOptions: { external: externalOptions },
52+
deps: { neverBundle: true, resolveDepSubpath: true },
53+
},
54+
{
55+
entry: 'src/index.ts',
56+
outDir: 'dist/alias',
57+
dts: false,
58+
inputOptions: { external: externalAlias },
59+
deps: { resolveDepSubpath: true, neverBundle: true },
60+
},
4461
],
4562
};
4663
```
@@ -64,6 +81,22 @@ import { externalValue } from "./external.js";
6481
export { externalValue, foo };
6582
```
6683

84+
## `vpt print-file dist/constant/index.mjs`
85+
86+
```
87+
import { foo } from "foo";
88+
import { externalValue } from "./external.js";
89+
export { externalValue, foo };
90+
```
91+
92+
## `vpt print-file dist/alias/index.mjs`
93+
94+
```
95+
import { foo } from "foo";
96+
import { externalValue } from "./external.js";
97+
export { externalValue, foo };
98+
```
99+
67100
## `vp migrate --no-interactive`
68101

69102
```
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
# migration_pack_tsdown_023_external_conflicts
2+
3+
Report conflicting dependency rules while preserving the pack options.
4+
5+
## `vpt cp external-conflicts.config.txt vite.config.ts`
6+
7+
8+
## `vp migrate --no-interactive`
9+
10+
```
11+
VITE+ - The Unified Toolchain for the Web
12+
13+
◇ Updated . to Vite+ <version>
14+
• Node <version> npm <version>
15+
• Dependencies:
16+
vite-plus 0.2.0 → <version>
17+
vite → <version>
18+
• Package manager settings configured
19+
! Warnings:
20+
- vite.config.ts: Cannot safely combine external with skipNodeModulesBundle. Migrate this pack config manually; its options were left unchanged. See https://tsdown.dev/options/dependencies#migration-from-deprecated-options
21+
```
22+
23+
## `vpt print-file vite.config.ts`
24+
25+
```
26+
const externalOptions = ['foo'];
27+
28+
export default {
29+
pack: [
30+
{
31+
external: externalOptions,
32+
skipNodeModulesBundle: true,
33+
inputOptions(options) { return { external: options.external }; },
34+
bundle: false,
35+
dts: { tsgo: true },
36+
},
37+
{
38+
external: externalOptions,
39+
deps: { skipNodeModulesBundle: true, dts: { neverBundle: ['types'] } },
40+
bundle: false,
41+
},
42+
],
43+
};
44+
```
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
# migration_pack_tsdown_023_external_constants
2+
3+
Migrate constant external references with both skip forms without a manual-migration warning.
4+
5+
## `vpt cp external-constants.config.txt vite.config.ts`
6+
7+
8+
## `vp migrate --no-interactive`
9+
10+
```
11+
VITE+ - The Unified Toolchain for the Web
12+
13+
◇ Updated . to Vite+ <version>
14+
• Node <version> npm <version>
15+
• Dependencies:
16+
vite-plus 0.2.0 → <version>
17+
vite → <version>
18+
• 1 file had imports rewritten
19+
• Package manager settings configured
20+
```
21+
22+
## `vpt print-file vite.config.ts`
23+
24+
```
25+
const externalOptions = ['foo'];
26+
27+
export default {
28+
pack: [
29+
{ inputOptions: { external: externalOptions }, deps: { neverBundle: true, resolveDepSubpath: true }, unbundle: true, dts: { generator: 'tsgo' } },
30+
{ inputOptions: { external: externalOptions }, deps: { resolveDepSubpath: true, neverBundle: true }, unbundle: true },
31+
],
32+
};
33+
```
34+
35+
## `vp migrate --no-interactive`
36+
37+
```
38+
VITE+ - The Unified Toolchain for the Web
39+
40+
This project is already using Vite+! Happy coding!
41+
```
42+
43+
## `vpt print-file vite.config.ts`
44+
45+
```
46+
const externalOptions = ['foo'];
47+
48+
export default {
49+
pack: [
50+
{ inputOptions: { external: externalOptions }, deps: { neverBundle: true, resolveDepSubpath: true }, unbundle: true, dts: { generator: 'tsgo' } },
51+
{ inputOptions: { external: externalOptions }, deps: { resolveDepSubpath: true, neverBundle: true }, unbundle: true },
52+
],
53+
};
54+
```

crates/vp_cli_snapshots/tests/cli_snapshots/fixtures/migration_pack_tsdown_023/snapshots/migration_pack_tsdown_023_manual.md

Lines changed: 0 additions & 60 deletions
This file was deleted.

0 commit comments

Comments
 (0)