@rollup-extras/plugin-html 2.1.0 → 2.1.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -1,3 +1,5 @@
1
+ ![Coverage](https://raw.githubusercontent.com/kshutkin/rollup-extras/refs/heads/coverage/plugin-html/badge.svg)
2
+
1
3
  # Plugin Html
2
4
 
3
5
  Rollup plugin to inject assets names into html template.
@@ -35,10 +35,15 @@ export function simpleModuleScript(predicateSource) {
35
35
 
36
36
  export function combineAssetFactories(...factories) {
37
37
  return (fileName, content, type) => {
38
- for (const factory of factories) {
39
- const result = factory(fileName, content, type);
40
- if (result) {
41
- return result;
38
+ return next(0);
39
+
40
+ function next(start) {
41
+ for (let index = start; index < factories.length; index++) {
42
+ const result = factories[index](fileName, content, type);
43
+ if (result instanceof Promise) {
44
+ return result.then(asset => asset || next(index + 1));
45
+ }
46
+ if (result) return result;
42
47
  }
43
48
  }
44
49
  };
package/index.js CHANGED
@@ -79,18 +79,18 @@ export default function (options = {}) {
79
79
  handleTemplateReadError(e);
80
80
  }
81
81
  } else {
82
- templateString = new Promise(resolve => {
83
- readFile(template, { encoding: 'utf8' })
84
- .then(newTemplateString => {
85
- if (!isUsableByDefaultTemplateFactory(newTemplateString) && !hasCustomTemplateFactory) {
86
- warnAboutUsingDefaultTemplate();
87
- resolve(defaultTemplate);
88
- } else {
89
- resolve(newTemplateString);
90
- }
91
- })
92
- .catch(handleTemplateReadError);
93
- });
82
+ templateString = readFile(template, { encoding: 'utf8' })
83
+ .then(newTemplateString => {
84
+ if (!isUsableByDefaultTemplateFactory(newTemplateString) && !hasCustomTemplateFactory) {
85
+ warnAboutUsingDefaultTemplate();
86
+ return defaultTemplate;
87
+ }
88
+ return newTemplateString;
89
+ })
90
+ .catch(e => {
91
+ handleTemplateReadError(e);
92
+ return defaultTemplate;
93
+ });
94
94
  }
95
95
  }
96
96
  }
@@ -245,7 +245,7 @@ export default function (options = {}) {
245
245
  const dir = options.dir ?? '';
246
246
  for (const fileName of Object.keys(bundle)) {
247
247
  const relativeToRootAssetPath = join(dir, fileName);
248
- const assetPath = relative(initialDir, relativeToRootAssetPath);
248
+ const assetPath = getAssetPath(relativeToRootAssetPath);
249
249
  if (ignore(relativeToRootAssetPath) || processedFiles.has(relativeToRootAssetPath)) {
250
250
  continue;
251
251
  }
@@ -285,7 +285,7 @@ export default function (options = {}) {
285
285
  if (modulepreload && options.format === 'es') {
286
286
  const transitiveImports = collectTransitiveImports(bundle, fileName);
287
287
  for (const importFileName of transitiveImports) {
288
- const importAssetPath = relative(initialDir, join(dir, importFileName));
288
+ const importAssetPath = getAssetPath(join(dir, importFileName));
289
289
  (assets.asset).push({
290
290
  html: getModulePreloadElement(importAssetPath),
291
291
  head: true,
@@ -298,6 +298,10 @@ export default function (options = {}) {
298
298
  }
299
299
  }
300
300
 
301
+ function getAssetPath(fileName) {
302
+ return relative(dirname(fileNameInInitialDir), fileName).replaceAll('\\', '/');
303
+ }
304
+
301
305
  async function useAssetFactory(fileName, relativeToRootAssetPath, source, format) {
302
306
  if (assetsFactory) {
303
307
  try {
package/package.json CHANGED
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "2.1.0",
2
+ "version": "2.1.2",
3
3
  "license": "MIT",
4
4
  "name": "@rollup-extras/plugin-html",
5
5
  "author": "Konstantin Shutkin",