0.0.5: fix, try to resolve sensible entrynames even if files were imported with an absolute path
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
2023-05-20 23:39:14 +02:00
parent ba09aaf915
commit 48dcdefee1
5 changed files with 25 additions and 17 deletions

View File

@@ -66,11 +66,17 @@ export default function html(opts: RollupHtmlOptions = {}): Plugin {
let htmlModules = new Map<string, HtmlModule>();// todo clean this per new build?
let virtualSources = new Map<string, string>();
let addedEntries = new Map<string, string>();
let entryNames = new Map<string,string>();
const pluginName = 'html2';
return {
name: pluginName,// TODO: Need a better name, original plugin was just named `html` and might still make sense to use in conjunction with this one
buildStart(options){
entryNames = new Map(Object.entries(typeof(options.input)==='object'?options.input:{[options.input]:[options.input]})
.map(([k,v])=>[v,k])
);
},
resolveId: {
async handler(specifier: string,
importer: string | undefined,
@@ -146,12 +152,6 @@ 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',
});
@@ -160,8 +160,16 @@ export default function html(opts: RollupHtmlOptions = {}): Plugin {
}
const selfInfo = this.getModuleInfo(id);
let entryName: string|undefined = undefined;
const parentName = entryNames.get(id)??selfInfo?.meta[pluginName].name;
if(type==='entryChunk'){
entryName= posix.join(posix.dirname(parentName),sourceId);
entryName = entryName.slice(0,-(posix.extname(entryName).length)); // Cut off the extension (TODO, is this wise?)
}
const importName = (source && selfInfo?.meta[pluginName].name)
? makeInlineId(selfInfo?.meta[pluginName].name, node, extname(sourceId))
? makeInlineId(parentName, node, extname(sourceId))
: entryName;
const htmlImport: HtmlImport = {