Skip to content

Commit

Permalink
fix: file path for asset factories
Browse files Browse the repository at this point in the history
  • Loading branch information
kshutkin committed Jun 18, 2023
1 parent bfd87eb commit fd0e5e0
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 8 deletions.
5 changes: 5 additions & 0 deletions .changeset/green-bags-brush.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@rollup-extras/plugin-html": patch
---

fixed correct path to file when using multiple dist folders and asset factories
15 changes: 7 additions & 8 deletions plugin-html/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ export default function(options: HtmlPluginOptions = {}) {

instance.renderStart = function (this: PluginContext, outputOptions: NormalizedOutputOptions, inputOptions: NormalizedInputOptions) {
logger('started collecting information', LogLevel.verbose);
initialDir = outputOptions.dir || '';
initialDir = outputOptions.dir ?? '';
fileNameInInitialDir = path.join(initialDir, outputFile);
return (baseRenderStart as (this: PluginContext, outputOptions: NormalizedOutputOptions, inputOptions: NormalizedInputOptions) => void | Promise<void>).call(this, outputOptions, inputOptions);
};
Expand Down Expand Up @@ -119,7 +119,7 @@ export default function(options: HtmlPluginOptions = {}) {
.map(({ key, count }) => `${key}: ${count}`)
.join(', ');
logger(`assets collected: [${statistics}], remaining: ${remainingOutputsCount} outputs, ${remainingConfigsCount} configs`, LogLevel.verbose);
const dir = options.dir || '', fileName = path.relative(dir, fileNameInInitialDir);
const dir = options.dir ?? '', fileName = path.relative(dir, fileNameInInitialDir);
if (fileName in bundle) {
if (useEmittedTemplate) {
logger(`using exiting emitted ${fileName} as an input for out templateFactory`, LogLevel.verbose);
Expand Down Expand Up @@ -170,7 +170,7 @@ export default function(options: HtmlPluginOptions = {}) {
async function generateBundle(this: PluginContext, options: NormalizedOutputOptions) {
logger.start('generating html', logLevel);
try {
const dir = options.dir || '', fileName = path.relative(dir, fileNameInInitialDir);
const dir = options.dir ?? '', fileName = path.relative(dir, fileNameInInitialDir);
const depromisifiedTemplateString = await templateString,
source = await templateFactory(depromisifiedTemplateString, assets, defaultTemplateFactory);

Expand All @@ -197,19 +197,19 @@ export default function(options: HtmlPluginOptions = {}) {
}

async function getAssets(options: NormalizedOutputOptions, bundle: OutputBundle) {
const dir = options.dir || '';
const dir = options.dir ?? '';
for (const fileName of Object.keys(bundle)) {
const relativeToRootAssetPath = path.join(dir, fileName);
const assetPath = path.relative(initialDir, relativeToRootAssetPath);
if (ignore(relativeToRootAssetPath) || processedFiles.has(relativeToRootAssetPath)) {
continue;
}
processedFiles.add(relativeToRootAssetPath);
if ((bundle[fileName] as OutputAsset | OutputChunk).type === 'asset') {
if (await useAssetFactory(fileName, relativeToRootAssetPath, (bundle[fileName] as OutputAsset).source, 'asset')) {
if (await useAssetFactory(assetPath, relativeToRootAssetPath, (bundle[fileName] as OutputAsset).source, 'asset')) {
continue;
}
if (fileName.endsWith(cssExtention)) {
const assetPath = path.relative(initialDir, relativeToRootAssetPath);
(assets.asset as AssetDescriptor[]).push({
html: getLinkElement(assetPath),
head: injectIntoHead(relativeToRootAssetPath),
Expand All @@ -220,11 +220,10 @@ export default function(options: HtmlPluginOptions = {}) {
} else if ((bundle[fileName] as OutputAsset | OutputChunk).type === 'chunk') {
const chunk = bundle[fileName] as OutputChunk;
if (chunk.isEntry) {
if (await useAssetFactory(fileName, relativeToRootAssetPath, chunk.code, options.format)) {
if (await useAssetFactory(assetPath, relativeToRootAssetPath, chunk.code, options.format)) {
continue;
}
if (options.format === 'es' || options.format === 'iife' || options.format === 'umd') {
const assetPath = path.relative(initialDir, relativeToRootAssetPath);
(assets[options.format] as AssetDescriptor[]).push({
html: (assets: Assets) => {
let useConditionalLoading = conditionalLoading;
Expand Down

0 comments on commit fd0e5e0

Please sign in to comment.