@rollup-extras/plugin-html 1.1.1 → 1.2.0

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/dist/index.cjs CHANGED
@@ -3,20 +3,34 @@
3
3
  var fs = require('fs/promises');
4
4
  var oldStyleFs = require('fs');
5
5
  var path = require('path');
6
- var logger = require('@niceties/logger');
6
+ var options = require('@rollup-extras/utils/options');
7
+ var logger = require('@rollup-extras/utils/logger');
8
+ var mutliConfigPluginBase = require('@rollup-extras/utils/mutli-config-plugin-base');
7
9
 
8
10
  function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
9
11
 
10
12
  var fs__default = /*#__PURE__*/_interopDefaultLegacy(fs);
11
13
  var oldStyleFs__default = /*#__PURE__*/_interopDefaultLegacy(oldStyleFs);
12
14
  var path__default = /*#__PURE__*/_interopDefaultLegacy(path);
15
+ var logger__default = /*#__PURE__*/_interopDefaultLegacy(logger);
13
16
 
14
17
  const defaultTemplate = '<!DOCTYPE html><html><head></head><body></body></html>';
15
18
  const headClosingElement = '</head>';
16
19
  const bodyClosingElement = '</body>';
17
20
  const cssExtention = '.css';
18
- function index (options = {}) {
19
- const { pluginName, outputFile, template, watch, emitFile, conditionalLoading, logger, useWriteBundle, logLevel, useEmittedTemplate, injectIntoHead, ignore, assetsFactory, templateFactory } = normalizeOptions(options), hasCustomTemplateFactory = 'templateFactory' in options;
21
+ const defaults = {
22
+ pluginName: '@rollup-extras/plugin-html',
23
+ outputFile: 'index.html',
24
+ watch: true,
25
+ useWriteBundle: false,
26
+ emitFile: 'auto',
27
+ injectIntoHead: (fileName) => fileName.endsWith(cssExtention),
28
+ ignore: toAssetPredicate(false),
29
+ templateFactory: ((template, assets, defaultTemplateFactory) => defaultTemplateFactory(template, assets))
30
+ };
31
+ const factories = { logger: logger__default["default"], injectIntoHead: predicateFactory, ignore: predicateFactory };
32
+ function index (options$1 = {}) {
33
+ const { pluginName, outputFile, template, watch, emitFile, conditionalLoading, logger, useWriteBundle, logLevel, useEmittedTemplate, injectIntoHead, ignore, assetsFactory, templateFactory } = options.getOptionsObject(options$1, Object.assign(Object.assign({}, defaults), { useEmittedTemplate: !('template' in options$1), logLevel: options$1.verbose ? 1 /* info */ : 0 /* verbose */ }), factories), hasCustomTemplateFactory = 'templateFactory' in options$1;
20
34
  let templateString = defaultTemplate, hasTemplateFile = false;
21
35
  if (template) {
22
36
  if (isUsableByDefaultTemplateFactory(template)) {
@@ -50,18 +64,23 @@ function index (options = {}) {
50
64
  }
51
65
  }
52
66
  }
53
- let remainingOutputsCount = 0, configsCount = 0, initialDir = '', fileNameInInitialDir, assets = freshAssets();
54
- const configs = new Set(), finalHook = useWriteBundle ? 'writeBundle' : 'generateBundle', processedFiles = new Set();
55
- const instance = {
56
- name: pluginName,
57
- renderStart: (options) => {
58
- logger('started collecting information', 0 /* verbose */);
59
- initialDir = options.dir || '';
60
- fileNameInInitialDir = path__default["default"].join(initialDir, outputFile);
61
- return renderStart();
62
- },
63
- [finalHook]: generateBundle,
64
- api: { addInstance }
67
+ let initialDir = '', fileNameInInitialDir, assets = freshAssets();
68
+ const processedFiles = new Set();
69
+ const instance = mutliConfigPluginBase.multiConfigPluginBase(useWriteBundle, pluginName, generateBundle, updateAssets);
70
+ const baseRenderStart = instance.renderStart;
71
+ const baseAddInstance = instance.api.addInstance;
72
+ instance.renderStart = function (outputOptions, inputOptions) {
73
+ logger('started collecting information', 0 /* verbose */);
74
+ initialDir = outputOptions.dir || '';
75
+ fileNameInInitialDir = path__default["default"].join(initialDir, outputFile);
76
+ return baseRenderStart.call(this, outputOptions, inputOptions);
77
+ };
78
+ instance.api.addInstance = () => {
79
+ const instance = baseAddInstance();
80
+ if (hasTemplateFile && watch) {
81
+ instance.buildStart = buildStart;
82
+ }
83
+ return instance;
65
84
  };
66
85
  if (hasTemplateFile && watch) {
67
86
  instance.buildStart = async function () {
@@ -75,6 +94,29 @@ function index (options = {}) {
75
94
  };
76
95
  }
77
96
  return instance;
97
+ async function updateAssets(options, bundle, remainingConfigsCount, remainingOutputsCount) {
98
+ await getAssets(options, bundle);
99
+ const statistics = Object.keys(assets)
100
+ .map(key => ({ key, count: assets[key].length }))
101
+ .filter(item => item.count)
102
+ .map(({ key, count }) => `${key}: ${count}`)
103
+ .join(', ');
104
+ logger(`assets collected: [${statistics}], remaining: ${remainingOutputsCount} outputs, ${remainingConfigsCount} configs`, 0 /* verbose */);
105
+ const dir = options.dir || '', fileName = path__default["default"].relative(dir, fileNameInInitialDir);
106
+ if (fileName in bundle) {
107
+ if (useEmittedTemplate) {
108
+ logger(`using exiting emitted ${fileName} as an input for out templateFactory`, 0 /* verbose */);
109
+ const source = bundle[fileName].type === 'asset' ? bundle[fileName].source.toString() : bundle[fileName].code;
110
+ useNewTemplate(source);
111
+ }
112
+ else {
113
+ logger(`removing exiting emitted ${fileName}`, 0 /* verbose */);
114
+ }
115
+ if (remainingConfigsCount === 0 && emitFile && !useWriteBundle) {
116
+ delete bundle[fileName];
117
+ }
118
+ }
119
+ }
78
120
  function freshAssets() {
79
121
  return {
80
122
  asset: [],
@@ -103,80 +145,35 @@ function index (options = {}) {
103
145
  function warnAboutUsingDefaultTemplate() {
104
146
  logger('template is unusable by default template factory, using default one', 2 /* warn */);
105
147
  }
106
- function addInstance() {
107
- const configId = ++configsCount;
108
- configs.add(configId);
109
- const instance = {
110
- name: `${pluginName}#${configId}`,
111
- renderStart: () => {
112
- configs.delete(configId);
113
- return renderStart();
114
- },
115
- [finalHook]: generateBundle
116
- };
117
- if (hasTemplateFile && watch) {
118
- instance.buildStart = buildStart;
119
- }
120
- return instance;
121
- }
122
148
  async function buildStart() {
123
149
  this.addWatchFile(template);
124
150
  }
125
- function renderStart() {
126
- ++remainingOutputsCount;
127
- }
128
- async function generateBundle(options, bundle) {
129
- --remainingOutputsCount;
130
- await getAssets(options, bundle);
131
- const statistics = Object.keys(assets)
132
- .map(key => ({ key, count: assets[key].length }))
133
- .filter(item => item.count)
134
- .map(({ key, count }) => `${key}: ${count}`)
135
- .join(', ');
136
- logger(`assets collected: [${statistics}], remaining: ${remainingOutputsCount} outputs, ${configs.size} configs`, 0 /* verbose */);
137
- const dir = options.dir || '', fileName = path__default["default"].relative(dir, fileNameInInitialDir);
138
- if (fileName in bundle) {
139
- if (useEmittedTemplate) {
140
- logger(`using exiting emitted ${fileName} as an input for out templateFactory`, 0 /* verbose */);
141
- const source = bundle[fileName].type === 'asset' ? bundle[fileName].source.toString() : bundle[fileName].code;
142
- useNewTemplate(source);
151
+ async function generateBundle(options) {
152
+ logger.start('generating html', logLevel);
153
+ try {
154
+ const dir = options.dir || '', fileName = path__default["default"].relative(dir, fileNameInInitialDir);
155
+ const depromisifiedTemplateString = await templateString, source = await templateFactory(depromisifiedTemplateString, assets, defaultTemplateFactory);
156
+ if (!emitFile || fileName.startsWith('..') || useWriteBundle) {
157
+ if (emitFile && emitFile !== 'auto') {
158
+ logger('cannot emitFile because it is outside of current output.dir, using writeFile instead', 0 /* verbose */);
159
+ }
160
+ await fs__default["default"].mkdir(path__default["default"].dirname(fileNameInInitialDir), { recursive: true });
161
+ await fs__default["default"].writeFile(fileNameInInitialDir, source);
143
162
  }
144
163
  else {
145
- logger(`removing exiting emitted ${fileName}`, 0 /* verbose */);
146
- }
147
- if (configs.size === 0 && emitFile && !useWriteBundle) {
148
- delete bundle[fileName];
164
+ this.emitFile({
165
+ type: 'asset',
166
+ fileName,
167
+ source
168
+ });
149
169
  }
170
+ // reset assets and configs for next iteration
171
+ assets = freshAssets();
172
+ processedFiles.clear();
173
+ logger.finish('html file generated');
150
174
  }
151
- if (configs.size === 0 && remainingOutputsCount === 0) {
152
- logger.start('generating html', logLevel);
153
- try {
154
- const depromisifiedTemplateString = await templateString, source = await templateFactory(depromisifiedTemplateString, assets, defaultTemplateFactory);
155
- if (!emitFile || fileName.startsWith('..') || useWriteBundle) {
156
- if (emitFile && emitFile !== 'auto') {
157
- logger('cannot emitFile because it is outside of current output.dir, using writeFile instead', 0 /* verbose */);
158
- }
159
- await fs__default["default"].mkdir(path__default["default"].dirname(fileNameInInitialDir), { recursive: true });
160
- await fs__default["default"].writeFile(fileNameInInitialDir, source);
161
- }
162
- else {
163
- this.emitFile({
164
- type: 'asset',
165
- fileName,
166
- source
167
- });
168
- }
169
- // reset assets and configs for next iteration
170
- assets = freshAssets();
171
- for (let i = configsCount; i > 0; --i) {
172
- configs.add(i);
173
- }
174
- processedFiles.clear();
175
- logger.finish('html file generated');
176
- }
177
- catch (e) {
178
- logger.finish('html generation failed', 3 /* error */, e);
179
- }
175
+ catch (e) {
176
+ logger.finish('html generation failed', 3 /* error */, e);
180
177
  }
181
178
  }
182
179
  async function getAssets(options, bundle) {
@@ -263,42 +260,17 @@ function getNonModuleScriptElement(fileName, conditionalLoading) {
263
260
  function getModuleScriptElement(fileName) {
264
261
  return `<script src="${fileName}" type="module"></script>`;
265
262
  }
266
- function normalizeOptions(userOptions) {
267
- var _a, _b, _c, _d, _e, _f, _g;
268
- const options = {
269
- pluginName: (_a = userOptions.pluginName) !== null && _a !== void 0 ? _a : '@rollup-extras/plugin-html',
270
- template: userOptions.template,
271
- outputFile: (_b = userOptions.outputFile) !== null && _b !== void 0 ? _b : 'index.html',
272
- watch: (_c = userOptions.watch) !== null && _c !== void 0 ? _c : true,
273
- useWriteBundle: (_d = userOptions.useWriteBundle) !== null && _d !== void 0 ? _d : false,
274
- useEmittedTemplate: (_e = userOptions.useEmittedTemplate) !== null && _e !== void 0 ? _e : !('template' in userOptions),
275
- emitFile: (_f = userOptions.emitFile) !== null && _f !== void 0 ? _f : 'auto',
276
- logLevel: userOptions.verbose ? 1 /* info */ : 0 /* verbose */,
277
- conditionalLoading: userOptions.conditionalLoading,
278
- injectIntoHead: (fileName) => fileName.endsWith(cssExtention),
279
- ignore: toAssetPredicate(false),
280
- assetsFactory: userOptions.assetsFactory,
281
- templateFactory: (_g = userOptions.templateFactory) !== null && _g !== void 0 ? _g : ((template, assets, defaultTemplateFactory) => defaultTemplateFactory(template, assets)),
282
- }, logger$1 = options.logger = logger.createLogger(options.pluginName), optionIgnoredText = 'option ignored because it is not a function, RegExp or boolean';
283
- if (userOptions.injectIntoHead != null) {
284
- const predicate = toAssetPredicate(userOptions.injectIntoHead);
285
- if (predicate) {
286
- options.injectIntoHead = predicate;
287
- }
288
- else {
289
- logger$1(`injectIntoHead ${optionIgnoredText}`, 2 /* warn */);
290
- }
291
- }
292
- if (userOptions.ignore != null) {
293
- const predicate = toAssetPredicate(userOptions.ignore);
263
+ function predicateFactory(options, field) {
264
+ if (options[field] != null) {
265
+ const predicate = toAssetPredicate(options[field]);
294
266
  if (predicate) {
295
- options.ignore = predicate;
267
+ return predicate;
296
268
  }
297
269
  else {
298
- logger$1(`ignore ${optionIgnoredText}`, 2 /* warn */);
270
+ options.logger && options.logger(`${field} option ignored because it is not a function, RegExp or boolean`, 2 /* warn */);
299
271
  }
300
272
  }
301
- return options;
273
+ return defaults[field];
302
274
  }
303
275
  function toAssetPredicate(sourceOption) {
304
276
  if (typeof sourceOption === 'boolean') {
package/dist/index.d.ts CHANGED
@@ -1,3 +1,7 @@
1
1
  import { PluginHooks } from 'rollup';
2
2
  import { HtmlPluginOptions } from './types';
3
- export default function (options?: HtmlPluginOptions): Partial<PluginHooks>;
3
+ export default function (options?: HtmlPluginOptions): Partial<PluginHooks> & {
4
+ api: {
5
+ addInstance(): void;
6
+ };
7
+ };
package/dist/index.mjs CHANGED
@@ -1,14 +1,27 @@
1
1
  import fs from 'fs/promises';
2
2
  import oldStyleFs from 'fs';
3
3
  import path from 'path';
4
- import { createLogger } from '@niceties/logger';
4
+ import { getOptionsObject } from '@rollup-extras/utils/options';
5
+ import logger from '@rollup-extras/utils/logger';
6
+ import { multiConfigPluginBase } from '@rollup-extras/utils/mutli-config-plugin-base';
5
7
 
6
8
  const defaultTemplate = '<!DOCTYPE html><html><head></head><body></body></html>';
7
9
  const headClosingElement = '</head>';
8
10
  const bodyClosingElement = '</body>';
9
11
  const cssExtention = '.css';
12
+ const defaults = {
13
+ pluginName: '@rollup-extras/plugin-html',
14
+ outputFile: 'index.html',
15
+ watch: true,
16
+ useWriteBundle: false,
17
+ emitFile: 'auto',
18
+ injectIntoHead: (fileName) => fileName.endsWith(cssExtention),
19
+ ignore: toAssetPredicate(false),
20
+ templateFactory: ((template, assets, defaultTemplateFactory) => defaultTemplateFactory(template, assets))
21
+ };
22
+ const factories = { logger, injectIntoHead: predicateFactory, ignore: predicateFactory };
10
23
  function index (options = {}) {
11
- const { pluginName, outputFile, template, watch, emitFile, conditionalLoading, logger, useWriteBundle, logLevel, useEmittedTemplate, injectIntoHead, ignore, assetsFactory, templateFactory } = normalizeOptions(options), hasCustomTemplateFactory = 'templateFactory' in options;
24
+ const { pluginName, outputFile, template, watch, emitFile, conditionalLoading, logger, useWriteBundle, logLevel, useEmittedTemplate, injectIntoHead, ignore, assetsFactory, templateFactory } = getOptionsObject(options, Object.assign(Object.assign({}, defaults), { useEmittedTemplate: !('template' in options), logLevel: options.verbose ? 1 /* info */ : 0 /* verbose */ }), factories), hasCustomTemplateFactory = 'templateFactory' in options;
12
25
  let templateString = defaultTemplate, hasTemplateFile = false;
13
26
  if (template) {
14
27
  if (isUsableByDefaultTemplateFactory(template)) {
@@ -42,18 +55,23 @@ function index (options = {}) {
42
55
  }
43
56
  }
44
57
  }
45
- let remainingOutputsCount = 0, configsCount = 0, initialDir = '', fileNameInInitialDir, assets = freshAssets();
46
- const configs = new Set(), finalHook = useWriteBundle ? 'writeBundle' : 'generateBundle', processedFiles = new Set();
47
- const instance = {
48
- name: pluginName,
49
- renderStart: (options) => {
50
- logger('started collecting information', 0 /* verbose */);
51
- initialDir = options.dir || '';
52
- fileNameInInitialDir = path.join(initialDir, outputFile);
53
- return renderStart();
54
- },
55
- [finalHook]: generateBundle,
56
- api: { addInstance }
58
+ let initialDir = '', fileNameInInitialDir, assets = freshAssets();
59
+ const processedFiles = new Set();
60
+ const instance = multiConfigPluginBase(useWriteBundle, pluginName, generateBundle, updateAssets);
61
+ const baseRenderStart = instance.renderStart;
62
+ const baseAddInstance = instance.api.addInstance;
63
+ instance.renderStart = function (outputOptions, inputOptions) {
64
+ logger('started collecting information', 0 /* verbose */);
65
+ initialDir = outputOptions.dir || '';
66
+ fileNameInInitialDir = path.join(initialDir, outputFile);
67
+ return baseRenderStart.call(this, outputOptions, inputOptions);
68
+ };
69
+ instance.api.addInstance = () => {
70
+ const instance = baseAddInstance();
71
+ if (hasTemplateFile && watch) {
72
+ instance.buildStart = buildStart;
73
+ }
74
+ return instance;
57
75
  };
58
76
  if (hasTemplateFile && watch) {
59
77
  instance.buildStart = async function () {
@@ -67,6 +85,29 @@ function index (options = {}) {
67
85
  };
68
86
  }
69
87
  return instance;
88
+ async function updateAssets(options, bundle, remainingConfigsCount, remainingOutputsCount) {
89
+ await getAssets(options, bundle);
90
+ const statistics = Object.keys(assets)
91
+ .map(key => ({ key, count: assets[key].length }))
92
+ .filter(item => item.count)
93
+ .map(({ key, count }) => `${key}: ${count}`)
94
+ .join(', ');
95
+ logger(`assets collected: [${statistics}], remaining: ${remainingOutputsCount} outputs, ${remainingConfigsCount} configs`, 0 /* verbose */);
96
+ const dir = options.dir || '', fileName = path.relative(dir, fileNameInInitialDir);
97
+ if (fileName in bundle) {
98
+ if (useEmittedTemplate) {
99
+ logger(`using exiting emitted ${fileName} as an input for out templateFactory`, 0 /* verbose */);
100
+ const source = bundle[fileName].type === 'asset' ? bundle[fileName].source.toString() : bundle[fileName].code;
101
+ useNewTemplate(source);
102
+ }
103
+ else {
104
+ logger(`removing exiting emitted ${fileName}`, 0 /* verbose */);
105
+ }
106
+ if (remainingConfigsCount === 0 && emitFile && !useWriteBundle) {
107
+ delete bundle[fileName];
108
+ }
109
+ }
110
+ }
70
111
  function freshAssets() {
71
112
  return {
72
113
  asset: [],
@@ -95,80 +136,35 @@ function index (options = {}) {
95
136
  function warnAboutUsingDefaultTemplate() {
96
137
  logger('template is unusable by default template factory, using default one', 2 /* warn */);
97
138
  }
98
- function addInstance() {
99
- const configId = ++configsCount;
100
- configs.add(configId);
101
- const instance = {
102
- name: `${pluginName}#${configId}`,
103
- renderStart: () => {
104
- configs.delete(configId);
105
- return renderStart();
106
- },
107
- [finalHook]: generateBundle
108
- };
109
- if (hasTemplateFile && watch) {
110
- instance.buildStart = buildStart;
111
- }
112
- return instance;
113
- }
114
139
  async function buildStart() {
115
140
  this.addWatchFile(template);
116
141
  }
117
- function renderStart() {
118
- ++remainingOutputsCount;
119
- }
120
- async function generateBundle(options, bundle) {
121
- --remainingOutputsCount;
122
- await getAssets(options, bundle);
123
- const statistics = Object.keys(assets)
124
- .map(key => ({ key, count: assets[key].length }))
125
- .filter(item => item.count)
126
- .map(({ key, count }) => `${key}: ${count}`)
127
- .join(', ');
128
- logger(`assets collected: [${statistics}], remaining: ${remainingOutputsCount} outputs, ${configs.size} configs`, 0 /* verbose */);
129
- const dir = options.dir || '', fileName = path.relative(dir, fileNameInInitialDir);
130
- if (fileName in bundle) {
131
- if (useEmittedTemplate) {
132
- logger(`using exiting emitted ${fileName} as an input for out templateFactory`, 0 /* verbose */);
133
- const source = bundle[fileName].type === 'asset' ? bundle[fileName].source.toString() : bundle[fileName].code;
134
- useNewTemplate(source);
142
+ async function generateBundle(options) {
143
+ logger.start('generating html', logLevel);
144
+ try {
145
+ const dir = options.dir || '', fileName = path.relative(dir, fileNameInInitialDir);
146
+ const depromisifiedTemplateString = await templateString, source = await templateFactory(depromisifiedTemplateString, assets, defaultTemplateFactory);
147
+ if (!emitFile || fileName.startsWith('..') || useWriteBundle) {
148
+ if (emitFile && emitFile !== 'auto') {
149
+ logger('cannot emitFile because it is outside of current output.dir, using writeFile instead', 0 /* verbose */);
150
+ }
151
+ await fs.mkdir(path.dirname(fileNameInInitialDir), { recursive: true });
152
+ await fs.writeFile(fileNameInInitialDir, source);
135
153
  }
136
154
  else {
137
- logger(`removing exiting emitted ${fileName}`, 0 /* verbose */);
138
- }
139
- if (configs.size === 0 && emitFile && !useWriteBundle) {
140
- delete bundle[fileName];
155
+ this.emitFile({
156
+ type: 'asset',
157
+ fileName,
158
+ source
159
+ });
141
160
  }
161
+ // reset assets and configs for next iteration
162
+ assets = freshAssets();
163
+ processedFiles.clear();
164
+ logger.finish('html file generated');
142
165
  }
143
- if (configs.size === 0 && remainingOutputsCount === 0) {
144
- logger.start('generating html', logLevel);
145
- try {
146
- const depromisifiedTemplateString = await templateString, source = await templateFactory(depromisifiedTemplateString, assets, defaultTemplateFactory);
147
- if (!emitFile || fileName.startsWith('..') || useWriteBundle) {
148
- if (emitFile && emitFile !== 'auto') {
149
- logger('cannot emitFile because it is outside of current output.dir, using writeFile instead', 0 /* verbose */);
150
- }
151
- await fs.mkdir(path.dirname(fileNameInInitialDir), { recursive: true });
152
- await fs.writeFile(fileNameInInitialDir, source);
153
- }
154
- else {
155
- this.emitFile({
156
- type: 'asset',
157
- fileName,
158
- source
159
- });
160
- }
161
- // reset assets and configs for next iteration
162
- assets = freshAssets();
163
- for (let i = configsCount; i > 0; --i) {
164
- configs.add(i);
165
- }
166
- processedFiles.clear();
167
- logger.finish('html file generated');
168
- }
169
- catch (e) {
170
- logger.finish('html generation failed', 3 /* error */, e);
171
- }
166
+ catch (e) {
167
+ logger.finish('html generation failed', 3 /* error */, e);
172
168
  }
173
169
  }
174
170
  async function getAssets(options, bundle) {
@@ -255,42 +251,17 @@ function getNonModuleScriptElement(fileName, conditionalLoading) {
255
251
  function getModuleScriptElement(fileName) {
256
252
  return `<script src="${fileName}" type="module"></script>`;
257
253
  }
258
- function normalizeOptions(userOptions) {
259
- var _a, _b, _c, _d, _e, _f, _g;
260
- const options = {
261
- pluginName: (_a = userOptions.pluginName) !== null && _a !== void 0 ? _a : '@rollup-extras/plugin-html',
262
- template: userOptions.template,
263
- outputFile: (_b = userOptions.outputFile) !== null && _b !== void 0 ? _b : 'index.html',
264
- watch: (_c = userOptions.watch) !== null && _c !== void 0 ? _c : true,
265
- useWriteBundle: (_d = userOptions.useWriteBundle) !== null && _d !== void 0 ? _d : false,
266
- useEmittedTemplate: (_e = userOptions.useEmittedTemplate) !== null && _e !== void 0 ? _e : !('template' in userOptions),
267
- emitFile: (_f = userOptions.emitFile) !== null && _f !== void 0 ? _f : 'auto',
268
- logLevel: userOptions.verbose ? 1 /* info */ : 0 /* verbose */,
269
- conditionalLoading: userOptions.conditionalLoading,
270
- injectIntoHead: (fileName) => fileName.endsWith(cssExtention),
271
- ignore: toAssetPredicate(false),
272
- assetsFactory: userOptions.assetsFactory,
273
- templateFactory: (_g = userOptions.templateFactory) !== null && _g !== void 0 ? _g : ((template, assets, defaultTemplateFactory) => defaultTemplateFactory(template, assets)),
274
- }, logger = options.logger = createLogger(options.pluginName), optionIgnoredText = 'option ignored because it is not a function, RegExp or boolean';
275
- if (userOptions.injectIntoHead != null) {
276
- const predicate = toAssetPredicate(userOptions.injectIntoHead);
277
- if (predicate) {
278
- options.injectIntoHead = predicate;
279
- }
280
- else {
281
- logger(`injectIntoHead ${optionIgnoredText}`, 2 /* warn */);
282
- }
283
- }
284
- if (userOptions.ignore != null) {
285
- const predicate = toAssetPredicate(userOptions.ignore);
254
+ function predicateFactory(options, field) {
255
+ if (options[field] != null) {
256
+ const predicate = toAssetPredicate(options[field]);
286
257
  if (predicate) {
287
- options.ignore = predicate;
258
+ return predicate;
288
259
  }
289
260
  else {
290
- logger(`ignore ${optionIgnoredText}`, 2 /* warn */);
261
+ options.logger && options.logger(`${field} option ignored because it is not a function, RegExp or boolean`, 2 /* warn */);
291
262
  }
292
263
  }
293
- return options;
264
+ return defaults[field];
294
265
  }
295
266
  function toAssetPredicate(sourceOption) {
296
267
  if (typeof sourceOption === 'boolean') {
package/dist/types.d.ts CHANGED
@@ -22,7 +22,7 @@ export declare type HtmlPluginOptions = {
22
22
  outputFile?: string;
23
23
  template?: string;
24
24
  watch?: boolean;
25
- emitFile?: boolean;
25
+ emitFile?: boolean | 'auto';
26
26
  verbose?: boolean;
27
27
  useWriteBundle?: boolean;
28
28
  useEmittedTemplate?: boolean;
package/package.json CHANGED
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "1.1.1",
2
+ "version": "1.2.0",
3
3
  "license": "MIT",
4
4
  "name": "@rollup-extras/plugin-html",
5
5
  "author": {
@@ -60,12 +60,13 @@
60
60
  "ts-jest": "27.1.2",
61
61
  "typescript": "4.5.x",
62
62
  "update-monorepo-package-json": "0.2.0",
63
- "pkgbld": "1.1.1"
63
+ "pkgbld": "1.1.3"
64
64
  },
65
65
  "peerDependencies": {
66
66
  "rollup": "^2.60.1"
67
67
  },
68
68
  "dependencies": {
69
- "@niceties/logger": "^1.1.0"
69
+ "@niceties/logger": "^1.1.0",
70
+ "@rollup-extras/utils": "^1.2.0"
70
71
  }
71
72
  }