Skip to content

Commit 1d417ce

Browse files
committed
fix(qwikVite): input handling
1 parent 02d046d commit 1d417ce

File tree

5 files changed

+56
-16
lines changed

5 files changed

+56
-16
lines changed

packages/qwik/src/optimizer/src/plugins/plugin.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -384,7 +384,13 @@ export function createQwikPlugin(optimizerOptions: OptimizerOptions = {}) {
384384
}
385385
}
386386

387-
return { ...opts };
387+
const out = { ...opts };
388+
// Make sure to know what the actual input is
389+
opts.input ||= updatedOpts.input as string[];
390+
if (opts.input && typeof opts.input === 'string') {
391+
opts.input = [opts.input];
392+
}
393+
return out;
388394
};
389395

390396
let hasValidatedSource = false;

packages/qwik/src/optimizer/src/plugins/rollup.ts

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -66,11 +66,10 @@ export function qwikRollup(qwikRollupOpts: QwikRollupPluginOptions = {}): any {
6666
experimental: qwikRollupOpts.experimental,
6767
};
6868

69-
const opts = await qwikPlugin.normalizeOptions(pluginOpts);
70-
71-
if (opts.input) {
72-
inputOpts.input = opts.input;
73-
}
69+
await qwikPlugin.normalizeOptions(pluginOpts);
70+
// Override the input with the normalized input
71+
const { input } = qwikPlugin.getOptions();
72+
inputOpts.input = input;
7473

7574
return inputOpts;
7675
},

packages/qwik/src/optimizer/src/plugins/rollup.unit.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,14 +54,15 @@ test('rollup default set input options, ssr', async () => {
5454
target: 'ssr',
5555
} as any;
5656
const plugin = qwikRollup(initOpts);
57+
const input = normalizePath(resolve(cwd, 'src', 'my.ssr.tsx'));
5758
const rollupInputOpts: Rollup.InputOptions = await plugin.options!({
58-
input: normalizePath(resolve(cwd, 'src', 'my.ssr.tsx')),
59+
input,
5960
});
6061
const opts: NormalizedQwikPluginOptions = plugin.api.getOptions();
6162
assert.deepEqual(typeof rollupInputOpts.onwarn, 'function');
6263
assert.deepEqual(rollupInputOpts.treeshake, undefined);
63-
assert.deepEqual(rollupInputOpts.input, normalizePath(resolve(cwd, 'src', 'my.ssr.tsx')));
64-
assert.deepEqual(opts.input, undefined);
64+
assert.deepEqual(rollupInputOpts.input, [input]);
65+
assert.deepEqual(opts.input, [input]);
6566
});
6667

6768
test('rollup default output options, client', async () => {

packages/qwik/src/optimizer/src/plugins/vite.ts

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,11 @@ export function qwikVite(qwikViteOpts: QwikVitePluginOptions = {}): any {
144144
? viteConfig.build.ssr
145145
: qwikViteOpts.ssr?.input
146146
: undefined;
147+
const clientInput = target === 'client' ? qwikViteOpts.client?.input : undefined;
148+
let input = viteConfig.build?.rollupOptions?.input || clientInput || ssrInput;
149+
if (input && typeof input === 'string') {
150+
input = [input];
151+
}
147152
const shouldFindVendors =
148153
!qwikViteOpts.disableVendorScan && (target !== 'lib' || viteCommand === 'serve');
149154
viteAssetsDir = viteConfig.build?.assetsDir;
@@ -170,16 +175,13 @@ export function qwikVite(qwikViteOpts: QwikVitePluginOptions = {}): any {
170175
sourcemap: !!viteConfig.build?.sourcemap,
171176
lint: qwikViteOpts.lint,
172177
experimental: qwikViteOpts.experimental,
173-
input: viteConfig.build?.rollupOptions?.input || ssrInput,
178+
input,
174179
manifestInput: qwikViteOpts.ssr?.manifestInput,
175180
manifestOutput: qwikViteOpts.client?.manifestOutput,
176181
};
177182

178183
const opts = await qwikPlugin.normalizeOptions(pluginOpts);
179-
if (ssrInput) {
180-
// make sure vite uses the ssr input
181-
opts.input ||= [ssrInput];
182-
}
184+
input ||= opts.input;
183185

184186
manifestInput = opts.manifestInput;
185187
srcDir = opts.srcDir;
@@ -282,7 +284,7 @@ export function qwikVite(qwikViteOpts: QwikVitePluginOptions = {}): any {
282284
*/
283285
maxParallelFileOps: 1,
284286
// This will amend the existing input
285-
input: opts.input,
287+
input,
286288
output: {
287289
manualChunks: qwikPlugin.manualChunks,
288290
},

packages/qwik/src/optimizer/src/plugins/vite.unit.ts

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import path, { resolve } from 'node:path';
22
import type { Rollup } from 'vite';
3-
import { assert, test } from 'vitest';
3+
import { assert, describe, test } from 'vitest';
44
import { normalizePath } from '../../../testing/util';
55
import type { OptimizerOptions } from '../types';
66
import { qwikVite, type QwikVitePlugin, type QwikVitePluginOptions } from './vite';
@@ -523,3 +523,35 @@ test('command: build, --mode lib with multiple outputs', async () => {
523523
assert.deepEqual(build.emptyOutDir, undefined);
524524
assert.deepEqual(opts.resolveQwikBuild, true);
525525
});
526+
527+
describe('input config', () => {
528+
const initOpts = {
529+
optimizerOptions: mockOptimizerOptions(),
530+
client: {
531+
input: './src/widget/counter.tsx',
532+
outDir: './dist/client',
533+
},
534+
ssr: {
535+
input: './src/widget/ssr.tsx',
536+
outDir: './dist/server',
537+
},
538+
} as QwikVitePluginOptions;
539+
test('should handle client target', async () => {
540+
const plugin = getPlugin(initOpts);
541+
const c: any = (await plugin.config.call(
542+
configHookPluginContext,
543+
{},
544+
{ command: 'build', mode: 'development' }
545+
))!;
546+
assert.deepEqual(c.build.rollupOptions.input, ['./src/widget/counter.tsx']);
547+
});
548+
test('should handle ssr target', async () => {
549+
const plugin = getPlugin(initOpts);
550+
const c: any = (await plugin.config.call(
551+
configHookPluginContext,
552+
{},
553+
{ command: 'build', mode: 'ssr' }
554+
))!;
555+
assert.deepEqual(c.build.rollupOptions.input, ['./src/widget/ssr.tsx']);
556+
});
557+
});

0 commit comments

Comments
 (0)