Skip to content

Commit 63c0b63

Browse files
committed
test: refactor for chunkFileNames and entryFileNames as functions
1 parent 7bf156d commit 63c0b63

File tree

2 files changed

+17
-17
lines changed

2 files changed

+17
-17
lines changed

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

Lines changed: 8 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -230,7 +230,14 @@ export function normalizeRollupOutputOptionsObject(
230230
return 'build/qwik-city.js';
231231
}
232232

233-
const sanitizedPath = sanitizePath(optimizer, chunkInfo.name);
233+
// Sanitize The path to use dashes instead of slashes, to keep the same folder strucutre as without debug:true.
234+
// Besides, Rollup doesn't accept absolute or relative paths as inputs for the [name] placeholder for the same reason.
235+
const path = optimizer.sys.path;
236+
const relativePath = path.relative(optimizer.sys.cwd(), chunkInfo.name);
237+
const sanitizedPath = relativePath
238+
.replace(/^(\.\.\/)+/, '')
239+
.replace(/^\/+/, '')
240+
.replace(/\//g, '-');
234241
chunkInfo.name = sanitizedPath;
235242
return `build/[name].js`;
236243
};
@@ -277,20 +284,6 @@ export function normalizeRollupOutputOptionsObject(
277284
return outputOpts;
278285
}
279286

280-
/**
281-
* @private Sanitize The path to use dashes instead of slashes, to keep the same folder strucutre as
282-
* without debug:true. Besides, Rollup doesn't accept absolute or relative paths as inputs for the
283-
* [name] placeholder for the same reason.
284-
*/
285-
export function sanitizePath(optimizer: Optimizer, pathToSanitize: string) {
286-
const path = optimizer.sys.path;
287-
const relativePath = path.relative(optimizer.sys.cwd(), pathToSanitize);
288-
return relativePath
289-
.replace(/^(\.\.\/)+/, '')
290-
.replace(/^\/+/, '')
291-
.replace(/\//g, '-');
292-
}
293-
294287
export function createRollupError(id: string, diagnostic: Diagnostic) {
295288
const loc = diagnostic.highlights[0] ?? {};
296289
const err: Rollup.RollupError = Object.assign(new Error(diagnostic.message), {

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

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,13 @@ test('command: serve, mode: development', async () => {
6161
const build = c.build!;
6262
const rollupOptions = build!.rollupOptions!;
6363
const outputOptions = rollupOptions.output as Rollup.OutputOptions;
64+
const chunkFileNames = outputOptions.chunkFileNames as (
65+
chunkInfo: Rollup.PreRenderedChunk
66+
) => string;
67+
const entryFileNames = outputOptions.entryFileNames as (
68+
chunkInfo: Rollup.PreRenderedChunk
69+
) => string;
70+
const fakeChunkInfo = { name: 'chunk.tsx' } as Rollup.PreRenderedChunk;
6471

6572
assert.deepEqual(opts.target, 'client');
6673
assert.deepEqual(opts.buildMode, 'development');
@@ -71,8 +78,8 @@ test('command: serve, mode: development', async () => {
7178
assert.deepEqual(rollupOptions.input, normalizePath(resolve(cwd, 'src', 'entry.dev')));
7279

7380
assert.deepEqual(outputOptions.assetFileNames, 'assets/[hash]-[name].[ext]');
74-
assert.deepEqual(outputOptions.chunkFileNames, 'build/[name].js');
75-
assert.deepEqual(outputOptions.entryFileNames, 'build/[name].js');
81+
assert.deepEqual(chunkFileNames(fakeChunkInfo), 'build/[name].js');
82+
assert.deepEqual(entryFileNames(fakeChunkInfo), 'build/[name].js');
7683
assert.deepEqual(outputOptions.format, 'es');
7784

7885
assert.deepEqual(build.dynamicImportVarsOptions?.exclude, [/./]);

0 commit comments

Comments
 (0)