0.0.3: fix entryNames of sources files included by html in a subdir (they didnt keep their relative address...)
Some checks failed
continuous-integration/drone/push Build is failing

This commit is contained in:
2023-05-20 23:14:59 +02:00
parent a784abc1b0
commit 9bf026f0c3
5 changed files with 54 additions and 4 deletions

View File

@@ -61,8 +61,11 @@ export default function html(opts: RollupHtmlOptions = {}): Plugin {
if(publicPath){ throw new Error("TODO, do something with the public path or throw it out of the options. this is just to stop typescript complaining")}
let filter = createFilter(include, exclude, {});
// TODO, we need to clear all these properly at sme point to avoid odd bugs in watch mode
let htmlModules = new Map<string, HtmlModule>();// todo clean this per new build?
let virtualSources = new Map<string, string>();
let addedEntries = new Map<string, string>();
const pluginName = 'html2';
return {
@@ -143,6 +146,11 @@ export default function html(opts: RollupHtmlOptions = {}): Plugin {
if(source){
virtualSources.set(sourceId, source);
}
let entryName: string|undefined = undefined;
if(type==='entryChunk'){
entryName= posix.join(posix.dirname(htmlModule.name),sourceId);
entryName = entryName.slice(0,-(posix.extname(entryName).length)); // Cut off the extension (TODO, is this wise?)
}
const resolved = await this.resolve(sourceId, id, {
isEntry: type==='entryChunk',
@@ -152,7 +160,9 @@ export default function html(opts: RollupHtmlOptions = {}): Plugin {
}
const selfInfo = this.getModuleInfo(id);
const importName = (source && selfInfo?.meta[pluginName].name) ? makeInlineId(selfInfo?.meta[pluginName].name, node, extname(sourceId)) : undefined;
const importName = (source && selfInfo?.meta[pluginName].name)
? makeInlineId(selfInfo?.meta[pluginName].name, node, extname(sourceId))
: entryName;
const htmlImport: HtmlImport = {
id: <string>sourceId,
@@ -171,6 +181,9 @@ export default function html(opts: RollupHtmlOptions = {}): Plugin {
placeholder: `html-import-${crypto.randomBytes(32).toString('base64')}`,
index: htmlImports.length,
}
// if(entryName){
// addedEntries.set(resolved.id, entryName);// (we could do this using meta?)
// }
htmlImports.push(htmlImport);
return htmlImport.placeholder;
}
@@ -224,12 +237,15 @@ export default function html(opts: RollupHtmlOptions = {}): Plugin {
...options,
entryFileNames: (chunkInfo)=>{
const htmlModule = chunkInfo.facadeModuleId ? htmlModules.get(chunkInfo.facadeModuleId!) : null;
const addedEntry = chunkInfo.facadeModuleId ? addedEntries.get(chunkInfo.facadeModuleId!) : null;
const defaultOption = options.entryFileNames ?? "[name]-[hash].js";// This default is copied from the docs. TODO: don't like overwrite it this way, can we remove the need for this or fetch the true default?
if(htmlModule){
let fileName = typeof (htmlFileNames) === 'string' ? htmlFileNames : (<(chunkInfo:PreRenderedChunk)=>string>htmlFileNames)(chunkInfo);
if(fileName) {
return fileName;
}
}else if(addedEntry){
return addedEntry;
}
return typeof (defaultOption) === 'string' ? defaultOption : (<(chunkInfo:PreRenderedChunk)=>string>defaultOption)(chunkInfo);
},