clean up complicated path logic shit
This commit is contained in:
parent
0dbd89f21d
commit
54f3493b1b
|
@ -97,8 +97,10 @@ function buildConfig({ manifest: manifestPathRelative, outDir, scriptPlugins = [
|
||||||
catch (error) {
|
catch (error) {
|
||||||
throw new Error('Failed to load manifest');
|
throw new Error('Failed to load manifest');
|
||||||
}
|
}
|
||||||
const uniqueFileNameSegmentCache = new Map();
|
// reserve manifest.json at the root of the build output - needs to be the
|
||||||
function uniqueFileNameSegment(filepath, ext = extname(filepath).slice(1)) {
|
// 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);
|
// console.log('getting segment for', filepath);
|
||||||
const cached = uniqueFileNameSegmentCache.get(filepath);
|
const cached = uniqueFileNameSegmentCache.get(filepath);
|
||||||
if (cached) {
|
if (cached) {
|
||||||
|
@ -115,18 +117,13 @@ function buildConfig({ manifest: manifestPathRelative, outDir, scriptPlugins = [
|
||||||
uniqueFileNameSegmentCache.set(filepath, finalName);
|
uniqueFileNameSegmentCache.set(filepath, finalName);
|
||||||
return finalName;
|
return finalName;
|
||||||
}
|
}
|
||||||
function getOutputFilename(entryPath, ext) {
|
|
||||||
// return join(dirname(entryPath), uniqueFileNameSegment(entryPath,
|
|
||||||
// ext));
|
|
||||||
return uniqueFileNameSegment(entryPath, ext);
|
|
||||||
}
|
|
||||||
const scripts = getScriptEntrypoints(manifestContent);
|
const scripts = getScriptEntrypoints(manifestContent);
|
||||||
const assets = getAssetEntrypoints(manifestContent);
|
const assets = getAssetEntrypoints(manifestContent);
|
||||||
return [
|
return [
|
||||||
// Process each script entrypoint independently
|
// Process each script entrypoint independently
|
||||||
...scripts.map(({ path, replacePath }) => {
|
...scripts.map(({ path, replacePath }) => {
|
||||||
// Figure out where this bundle will live in the output
|
// 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
|
// Rewrite the manifest with that path
|
||||||
replacePath(outPath);
|
replacePath(outPath);
|
||||||
// Build the bundle
|
// Build the bundle
|
||||||
|
@ -153,7 +150,7 @@ function buildConfig({ manifest: manifestPathRelative, outDir, scriptPlugins = [
|
||||||
buildStart() {
|
buildStart() {
|
||||||
assets.forEach(({ path, replacePath }) => {
|
assets.forEach(({ path, replacePath }) => {
|
||||||
// Figure out where the asset will live in output
|
// Figure out where the asset will live in output
|
||||||
const outPath = getOutputFilename(path);
|
const outPath = ensureUniquePath(path);
|
||||||
// Rewrite the manifest with that path
|
// Rewrite the manifest with that path
|
||||||
replacePath(outPath);
|
replacePath(outPath);
|
||||||
// Emit the asset as part of the build step
|
// Emit the asset as part of the build step
|
||||||
|
|
16
index.ts
16
index.ts
|
@ -29,8 +29,10 @@ export function buildConfig ({
|
||||||
throw new Error('Failed to load manifest');
|
throw new Error('Failed to load manifest');
|
||||||
}
|
}
|
||||||
|
|
||||||
const uniqueFileNameSegmentCache = new Map();
|
// reserve manifest.json at the root of the build output - needs to be the
|
||||||
function uniqueFileNameSegment (filepath: string, ext = extname(filepath).slice(1)) {
|
// 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);
|
// console.log('getting segment for', filepath);
|
||||||
const cached = uniqueFileNameSegmentCache.get(filepath);
|
const cached = uniqueFileNameSegmentCache.get(filepath);
|
||||||
if (cached) {
|
if (cached) {
|
||||||
|
@ -51,12 +53,6 @@ export function buildConfig ({
|
||||||
return finalName;
|
return finalName;
|
||||||
}
|
}
|
||||||
|
|
||||||
function getOutputFilename (entryPath: string, ext?: string) {
|
|
||||||
// return join(dirname(entryPath), uniqueFileNameSegment(entryPath,
|
|
||||||
// ext));
|
|
||||||
return uniqueFileNameSegment(entryPath, ext);
|
|
||||||
}
|
|
||||||
|
|
||||||
const scripts = getScriptEntrypoints(manifestContent);
|
const scripts = getScriptEntrypoints(manifestContent);
|
||||||
const assets = getAssetEntrypoints(manifestContent);
|
const assets = getAssetEntrypoints(manifestContent);
|
||||||
|
|
||||||
|
@ -64,7 +60,7 @@ export function buildConfig ({
|
||||||
// Process each script entrypoint independently
|
// Process each script entrypoint independently
|
||||||
...scripts.map(({path, replacePath}) => {
|
...scripts.map(({path, replacePath}) => {
|
||||||
// Figure out where this bundle will live in the output
|
// 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
|
// Rewrite the manifest with that path
|
||||||
replacePath(outPath);
|
replacePath(outPath);
|
||||||
|
@ -94,7 +90,7 @@ export function buildConfig ({
|
||||||
buildStart () {
|
buildStart () {
|
||||||
assets.forEach(({path, replacePath}) => {
|
assets.forEach(({path, replacePath}) => {
|
||||||
// Figure out where the asset will live in output
|
// Figure out where the asset will live in output
|
||||||
const outPath = getOutputFilename(path);
|
const outPath = ensureUniquePath(path);
|
||||||
|
|
||||||
// Rewrite the manifest with that path
|
// Rewrite the manifest with that path
|
||||||
replacePath(outPath);
|
replacePath(outPath);
|
||||||
|
|
Loading…
Reference in a new issue