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
Some checks failed
continuous-integration/drone/push Build is failing
This commit is contained in:
parent
a784abc1b0
commit
9bf026f0c3
18
src/index.ts
18
src/index.ts
@ -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);
|
||||
},
|
||||
|
||||
2
test/multi-entry/fixtures/admin/batman.js
Normal file
2
test/multi-entry/fixtures/admin/batman.js
Normal file
@ -0,0 +1,2 @@
|
||||
export const b = ()=>'batman';
|
||||
console.log(b());
|
||||
@ -8,5 +8,6 @@
|
||||
import {adminDeps} from "../app/admin-deps.js";
|
||||
bootstrap(document.getElementById('root'), adminDeps());
|
||||
</script>
|
||||
<script src="./batman.js" type="module"></script>
|
||||
</body>
|
||||
</html>
|
||||
|
||||
@ -9,6 +9,36 @@ Generated by [AVA](https://avajs.dev).
|
||||
> Snapshot 1
|
||||
|
||||
[
|
||||
{
|
||||
code: `const b = ()=>'batman';␊
|
||||
console.log(b());␊
|
||||
␊
|
||||
export { b };␊
|
||||
//# sourceMappingURL=batman-c7fa228c.js.map␊
|
||||
`,
|
||||
fileName: 'admin/batman-c7fa228c.js',
|
||||
map: SourceMap {
|
||||
file: 'batman-c7fa228c.js',
|
||||
mappings: 'AAAY,MAAC,CAAC,GAAG,IAAI,SAAS;AAC9B,OAAO,CAAC,GAAG,CAAC,CAAC,EAAE,CAAC;;;;',
|
||||
names: [],
|
||||
sources: [
|
||||
'../../admin/batman.js',
|
||||
],
|
||||
sourcesContent: [
|
||||
`export const b = ()=>'batman';␊
|
||||
console.log(b());␊
|
||||
`,
|
||||
],
|
||||
version: 3,
|
||||
},
|
||||
source: undefined,
|
||||
},
|
||||
{
|
||||
code: undefined,
|
||||
fileName: 'admin/batman-c7fa228c.js.map',
|
||||
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;;;;"}',
|
||||
},
|
||||
{
|
||||
code: undefined,
|
||||
fileName: 'admin/index.html',
|
||||
@ -24,17 +54,18 @@ Generated by [AVA](https://avajs.dev).
|
||||
}␊
|
||||
␊
|
||||
bootstrap(document.getElementById('root'), adminDeps());␊
|
||||
//# sourceMappingURL=index.html.body.script.js-15dfaff3.js.map␊
|
||||
//# sourceMappingURL=index.html.body.script0.js-15dfaff3.js.map␊
|
||||
</script>␊
|
||||
<script src="batman-c7fa228c.js" type="module"></script>␊
|
||||
␊
|
||||
␊
|
||||
</body></html>`,
|
||||
},
|
||||
{
|
||||
code: undefined,
|
||||
fileName: 'admin/index.html.body.script.js-15dfaff3.js.map',
|
||||
fileName: 'admin/index.html.body.script0.js-15dfaff3.js.map',
|
||||
map: undefined,
|
||||
source: '{"version":3,"file":"index.html.body.script.js-15dfaff3.js","sources":["../../app/admin-deps.js","../../admin/index.html.body.script.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"}',
|
||||
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 = [])=>{␊
|
||||
|
||||
Binary file not shown.
Loading…
x
Reference in New Issue
Block a user