Skip to content

Commit 756d510

Browse files
authored
fix(vite-plugin-angular): skip rolldown dep optimizer transform in test mode and close transformer (#2373)
1 parent 744b684 commit 756d510

3 files changed

Lines changed: 64 additions & 11 deletions

File tree

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
import { describe, expect, it } from 'vitest';
2+
import { createRolldownCompilerPlugin } from './compiler-plugin.js';
3+
4+
const pluginOptions = {
5+
tsconfig: 'tsconfig.spec.json',
6+
sourcemap: false,
7+
incremental: false,
8+
};
9+
10+
describe('createRolldownCompilerPlugin', () => {
11+
it('skips the dependency transform in test mode', () => {
12+
const plugin = createRolldownCompilerPlugin(pluginOptions, true, true);
13+
14+
expect(plugin.load).toBeUndefined();
15+
});
16+
17+
it('keeps the dependency transform outside test mode', () => {
18+
const plugin = createRolldownCompilerPlugin(pluginOptions, false, true);
19+
20+
expect(plugin.load).toBeDefined();
21+
});
22+
23+
it('closes the JavaScript transformer when the build ends', async () => {
24+
const plugin = createRolldownCompilerPlugin(pluginOptions, false, true);
25+
26+
expect(plugin.buildEnd).toBeDefined();
27+
await expect(
28+
(plugin.buildEnd as unknown as () => Promise<void>)(),
29+
).resolves.toBeUndefined();
30+
});
31+
32+
it('keeps the transformer open when closeTransformer is false', () => {
33+
const plugin = createRolldownCompilerPlugin(pluginOptions, false, false);
34+
35+
expect(plugin.buildEnd).toBeUndefined();
36+
});
37+
});

‎packages/vite-plugin-angular/src/lib/compiler-plugin.ts‎

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -50,14 +50,20 @@ export function createCompilerPlugin(
5050

5151
export function createRolldownCompilerPlugin(
5252
pluginOptions: CompilerPluginOptions,
53+
isTest: boolean,
54+
closeTransformer: boolean,
5355
): Rolldown.Plugin {
5456
const javascriptTransformer = new JavaScriptTransformer(
5557
{ ...pluginOptions, jit: true },
5658
1,
5759
);
58-
return {
60+
61+
const plugin: Rolldown.Plugin = {
5962
name: 'analogjs-rolldown-deps-optimizer-plugin',
60-
load: {
63+
};
64+
65+
if (!isTest) {
66+
plugin.load = {
6167
filter: {
6268
id: /\.[cm]?js$/,
6369
},
@@ -69,6 +75,12 @@ export function createRolldownCompilerPlugin(
6975
loader: 'js',
7076
} as any;
7177
},
72-
},
73-
};
78+
};
79+
}
80+
81+
if (closeTransformer) {
82+
plugin.buildEnd = () => javascriptTransformer.close();
83+
}
84+
85+
return plugin;
7486
}

‎packages/vite-plugin-angular/src/lib/utils/plugin-config.ts‎

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -100,13 +100,17 @@ export function createDepOptimizerConfig(opts: DepOptimizerOptions) {
100100

101101
const rolldownOptions: vite.DepOptimizationOptions['rolldownOptions'] = {
102102
plugins: [
103-
createRolldownCompilerPlugin({
104-
tsconfig: opts.tsconfig,
105-
sourcemap: !opts.isProd,
106-
advancedOptimizations: opts.isProd,
107-
jit: opts.jit,
108-
incremental: opts.watchMode,
109-
}),
103+
createRolldownCompilerPlugin(
104+
{
105+
tsconfig: opts.tsconfig,
106+
sourcemap: !opts.isProd,
107+
advancedOptimizations: opts.isProd,
108+
jit: opts.jit,
109+
incremental: opts.watchMode,
110+
},
111+
opts.isTest,
112+
!opts.isAstroIntegration,
113+
),
110114
],
111115
};
112116

0 commit comments

Comments
 (0)