From 54f3493b1bc4cadfa99da70eeafcca1f528344ee Mon Sep 17 00:00:00 2001 From: Erin Date: Fri, 28 Jul 2023 07:59:40 -0400 Subject: [PATCH] clean up complicated path logic shit --- build/index.js | 15 ++++++--------- index.ts | 16 ++++++---------- 2 files changed, 12 insertions(+), 19 deletions(-) diff --git a/build/index.js b/build/index.js index c54e73f..443a567 100644 --- a/build/index.js +++ b/build/index.js @@ -97,8 +97,10 @@ function buildConfig({ manifest: manifestPathRelative, outDir, scriptPlugins = [ catch (error) { throw new Error('Failed to load manifest'); } - const uniqueFileNameSegmentCache = new Map(); - function uniqueFileNameSegment(filepath, ext = extname(filepath).slice(1)) { + // reserve manifest.json at the root of the build output - needs to be the + // actual manifest file we generate + const uniqueFileNameSegmentCache = new Map([['\0', 'manifest.json']]); + function ensureUniquePath(filepath, ext = extname(filepath).slice(1)) { // console.log('getting segment for', filepath); const cached = uniqueFileNameSegmentCache.get(filepath); if (cached) { @@ -115,18 +117,13 @@ function buildConfig({ manifest: manifestPathRelative, outDir, scriptPlugins = [ uniqueFileNameSegmentCache.set(filepath, finalName); return finalName; } - function getOutputFilename(entryPath, ext) { - // return join(dirname(entryPath), uniqueFileNameSegment(entryPath, - // ext)); - return uniqueFileNameSegment(entryPath, ext); - } const scripts = getScriptEntrypoints(manifestContent); const assets = getAssetEntrypoints(manifestContent); return [ // Process each script entrypoint independently ...scripts.map(({ path, replacePath }) => { // Figure out where this bundle will live in the output - const outPath = getOutputFilename(path, 'js'); + const outPath = ensureUniquePath(path, 'js'); // Rewrite the manifest with that path replacePath(outPath); // Build the bundle @@ -153,7 +150,7 @@ function buildConfig({ manifest: manifestPathRelative, outDir, scriptPlugins = [ buildStart() { assets.forEach(({ path, replacePath }) => { // Figure out where the asset will live in output - const outPath = getOutputFilename(path); + const outPath = ensureUniquePath(path); // Rewrite the manifest with that path replacePath(outPath); // Emit the asset as part of the build step diff --git a/index.ts b/index.ts index 43556a1..fc6d518 100644 --- a/index.ts +++ b/index.ts @@ -29,8 +29,10 @@ export function buildConfig ({ throw new Error('Failed to load manifest'); } - const uniqueFileNameSegmentCache = new Map(); - function uniqueFileNameSegment (filepath: string, ext = extname(filepath).slice(1)) { + // reserve manifest.json at the root of the build output - needs to be the + // actual manifest file we generate + const uniqueFileNameSegmentCache = new Map([['\0', 'manifest.json']]); + function ensureUniquePath (filepath: string, ext = extname(filepath).slice(1)) { // console.log('getting segment for', filepath); const cached = uniqueFileNameSegmentCache.get(filepath); if (cached) { @@ -51,12 +53,6 @@ export function buildConfig ({ return finalName; } - function getOutputFilename (entryPath: string, ext?: string) { - // return join(dirname(entryPath), uniqueFileNameSegment(entryPath, - // ext)); - return uniqueFileNameSegment(entryPath, ext); - } - const scripts = getScriptEntrypoints(manifestContent); const assets = getAssetEntrypoints(manifestContent); @@ -64,7 +60,7 @@ export function buildConfig ({ // Process each script entrypoint independently ...scripts.map(({path, replacePath}) => { // Figure out where this bundle will live in the output - const outPath = getOutputFilename(path, 'js'); + const outPath = ensureUniquePath(path, 'js'); // Rewrite the manifest with that path replacePath(outPath); @@ -94,7 +90,7 @@ export function buildConfig ({ buildStart () { assets.forEach(({path, replacePath}) => { // Figure out where the asset will live in output - const outPath = getOutputFilename(path); + const outPath = ensureUniquePath(path); // Rewrite the manifest with that path replacePath(outPath);