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:
Miel Truyen 2023-05-20 23:39:14 +02:00
parent ba09aaf915
commit 48dcdefee1
5 changed files with 25 additions and 17 deletions

View File

@ -1,6 +1,6 @@
{ {
"name": "rollup-plugin-html-entry2", "name": "rollup-plugin-html-entry2",
"version": "0.0.4", "version": "0.0.5",
"description": "Teaches rollup how to deal with HTML, allows to use HTML-files as entry-points.", "description": "Teaches rollup how to deal with HTML, allows to use HTML-files as entry-points.",
"license": "MIT", "license": "MIT",
"repository": { "repository": {

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 htmlModules = new Map<string, HtmlModule>();// todo clean this per new build?
let virtualSources = new Map<string, string>(); let virtualSources = new Map<string, string>();
let addedEntries = new Map<string, string>(); let addedEntries = new Map<string, string>();
let entryNames = new Map<string,string>();
const pluginName = 'html2'; const pluginName = 'html2';
return { 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 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: { resolveId: {
async handler(specifier: string, async handler(specifier: string,
importer: string | undefined, importer: string | undefined,
@ -146,12 +152,6 @@ export default function html(opts: RollupHtmlOptions = {}): Plugin {
if(source){ if(source){
virtualSources.set(sourceId, 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, { const resolved = await this.resolve(sourceId, id, {
isEntry: type==='entryChunk', isEntry: type==='entryChunk',
}); });
@ -160,8 +160,16 @@ export default function html(opts: RollupHtmlOptions = {}): Plugin {
} }
const selfInfo = this.getModuleInfo(id); 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) const importName = (source && selfInfo?.meta[pluginName].name)
? makeInlineId(selfInfo?.meta[pluginName].name, node, extname(sourceId)) ? makeInlineId(parentName, node, extname(sourceId))
: entryName; : entryName;
const htmlImport: HtmlImport = { const htmlImport: HtmlImport = {

View File

@ -39,6 +39,12 @@ Generated by [AVA](https://avajs.dev).
map: undefined, map: undefined,
source: '{"version":3,"file":"batman-c7fa228c.js","sources":["../../admin/batman.js"],"sourcesContent":["export const b = ()=>\'batman\';\\nconsole.log(b());\\n"],"names":[],"mappings":"AAAY,MAAC,CAAC,GAAG,IAAI,SAAS;AAC9B,OAAO,CAAC,GAAG,CAAC,CAAC,EAAE,CAAC;;;;"}', source: '{"version":3,"file":"batman-c7fa228c.js","sources":["../../admin/batman.js"],"sourcesContent":["export const b = ()=>\'batman\';\\nconsole.log(b());\\n"],"names":[],"mappings":"AAAY,MAAC,CAAC,GAAG,IAAI,SAAS;AAC9B,OAAO,CAAC,GAAG,CAAC,CAAC,EAAE,CAAC;;;;"}',
}, },
{
code: undefined,
fileName: 'admin/index.body.script0.js-15dfaff3.js.map',
map: undefined,
source: '{"version":3,"file":"index.body.script0.js-15dfaff3.js","sources":["../../app/admin-deps.js","../../admin/index.html.body.script0.js"],"sourcesContent":["export function adminDeps(){\\n return \\"robin!\\";\\n}\\n","\\n import {bootstrap} from \\"../app/app.js\\"\\n import {adminDeps} from \\"../app/admin-deps.js\\";\\n bootstrap(document.getElementById(\'root\'), adminDeps());\\n "],"names":[],"mappings":";;AAAO,SAAS,SAAS,EAAE;AAC3B,IAAI,OAAO,QAAQ,CAAC;AACpB;;ACCY,SAAS,CAAC,QAAQ,CAAC,cAAc,CAAC,MAAM,CAAC,EAAE,SAAS,EAAE,CAAC"}',
},
{ {
code: undefined, code: undefined,
fileName: 'admin/index.html', fileName: 'admin/index.html',
@ -54,19 +60,13 @@ Generated by [AVA](https://avajs.dev).
}␊ }␊
bootstrap(document.getElementById('root'), adminDeps());␊ bootstrap(document.getElementById('root'), adminDeps());␊
//# sourceMappingURL=index.html.body.script0.js-15dfaff3.js.map␊ //# sourceMappingURL=index.body.script0.js-15dfaff3.js.map␊
</script> </script>
<script src="batman-c7fa228c.js" type="module"></script> <script src="batman-c7fa228c.js" type="module"></script>
</body></html>`, </body></html>`,
}, },
{
code: undefined,
fileName: 'admin/index.html.body.script0.js-15dfaff3.js.map',
map: undefined,
source: '{"version":3,"file":"index.html.body.script0.js-15dfaff3.js","sources":["../../app/admin-deps.js","../../admin/index.html.body.script0.js"],"sourcesContent":["export function adminDeps(){\\n return \\"robin!\\";\\n}\\n","\\n import {bootstrap} from \\"../app/app.js\\"\\n import {adminDeps} from \\"../app/admin-deps.js\\";\\n bootstrap(document.getElementById(\'root\'), adminDeps());\\n "],"names":[],"mappings":";;AAAO,SAAS,SAAS,EAAE;AAC3B,IAAI,OAAO,QAAQ,CAAC;AACpB;;ACCY,SAAS,CAAC,QAAQ,CAAC,cAAc,CAAC,MAAM,CAAC,EAAE,SAAS,EAAE,CAAC"}',
},
{ {
code: `const bootstrap = (el,deps = [])=>{␊ code: `const bootstrap = (el,deps = [])=>{␊
el.innerHtml = \`␊ el.innerHtml = \`␊

View File

@ -1,4 +1,4 @@
import {join, dirname} from "node:path"; import {resolve, join, dirname} from "node:path";
import test from "ava"; import test from "ava";
import { rollup } from "rollup"; import { rollup } from "rollup";
@ -21,7 +21,7 @@ test.serial('multi-entry', async (t) => {
const bundle = await rollup({ const bundle = await rollup({
input: { input: {
['index']: 'index.html', ['index']: 'index.html',
['admin/index']: 'admin/index.html' ['admin/index']: resolve(__dirname,'fixtures','admin/index.html'),
}, },
plugins: [ plugins: [
html({ html({