Skip to content

Commit c4088aa

Browse files
committed
refactor: extract sanitizePath
1 parent f8853c2 commit c4088aa

File tree

1 file changed

+15
-7
lines changed
  • packages/qwik/src/optimizer/src/plugins

1 file changed

+15
-7
lines changed

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

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

233-
// some chunk names are absolute paths and rollup doesn't accept that so we must sanitize those instead of simply returning `build/[name].js`.
234-
const path = optimizer.sys.path;
235-
const relativePath = path.relative(optimizer.sys.cwd(), chunkInfo.name);
236-
const sanitizedPath = relativePath
237-
.replace(/^(\.\.\/)+/, '')
238-
.replace(/^\/+/, '')
239-
.replace(/\//g, '-');
233+
const sanitizedPath = sanitizePath(optimizer, chunkInfo.name);
240234

241235
return `build/${sanitizedPath}.js`;
242236
};
@@ -283,6 +277,20 @@ export function normalizeRollupOutputOptionsObject(
283277
return outputOpts;
284278
}
285279

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+
286294
export function createRollupError(id: string, diagnostic: Diagnostic) {
287295
const loc = diagnostic.highlights[0] ?? {};
288296
const err: Rollup.RollupError = Object.assign(new Error(diagnostic.message), {

0 commit comments

Comments
 (0)