@rollup-extras/plugin-html 1.3.4 → 1.4.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.mjs CHANGED
@@ -4,292 +4,276 @@ import path from 'path';
4
4
  import { getOptionsObject } from '@rollup-extras/utils/options';
5
5
  import logger from '@rollup-extras/utils/logger';
6
6
  import { multiConfigPluginBase } from '@rollup-extras/utils/mutli-config-plugin-base';
7
+ import { g as getLinkElement, a as getNonModuleScriptElement, b as getModuleScriptElement, t as toAssetPredicate } from './shared.mjs';
7
8
 
8
- const defaultTemplate = '<!DOCTYPE html><html><head></head><body></body></html>';
9
- const headClosingElement = '</head>';
10
- const bodyClosingElement = '</body>';
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 };
23
- function index (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 /* LogLevel.info */ : 0 /* LogLevel.verbose */ }), factories), hasCustomTemplateFactory = 'templateFactory' in options;
25
- let templateString = defaultTemplate, hasTemplateFile = false;
26
- if (template) {
27
- if (isUsableByDefaultTemplateFactory(template)) {
28
- templateString = template;
29
- }
30
- else {
31
- if (watch) {
32
- try {
33
- // using sync fs call because we need to return plugin object immidiately
34
- useNewTemplate(oldStyleFs.readFileSync(template, { encoding: 'utf8' }));
35
- hasTemplateFile = true;
36
- }
37
- catch (e) {
38
- handleTemplateReadError(e);
39
- }
40
- }
41
- else {
42
- templateString = new Promise(resolve => {
43
- fs.readFile(template, { encoding: 'utf8' })
44
- .then((newTemplateString) => {
45
- if (!isUsableByDefaultTemplateFactory(newTemplateString) && !hasCustomTemplateFactory) {
46
- warnAboutUsingDefaultTemplate();
47
- resolve(defaultTemplate);
48
- }
49
- else {
50
- resolve(newTemplateString);
51
- }
52
- })
53
- .catch(handleTemplateReadError);
54
- });
55
- }
56
- }
57
- }
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 /* LogLevel.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;
75
- };
76
- if (hasTemplateFile && watch) {
77
- instance.buildStart = async function () {
78
- try {
79
- useNewTemplate(await fs.readFile(template, { encoding: 'utf8' }));
80
- }
81
- catch (e) {
82
- handleTemplateReadError(e);
83
- }
84
- await buildStart.apply(this);
85
- };
86
- }
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 /* LogLevel.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 /* LogLevel.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 /* LogLevel.verbose */);
105
- }
106
- if (remainingConfigsCount === 0 && emitFile && !useWriteBundle) {
107
- delete bundle[fileName];
108
- }
109
- }
110
- }
111
- function freshAssets() {
112
- return {
113
- asset: [],
114
- es: [],
115
- iife: [],
116
- umd: []
117
- };
118
- }
119
- function useNewTemplate(newTemplateString) {
120
- if (!isUsableByDefaultTemplateFactory(newTemplateString) && !hasCustomTemplateFactory) {
121
- warnAboutUsingDefaultTemplate();
122
- }
123
- else {
124
- templateString = newTemplateString;
125
- }
126
- }
127
- function handleTemplateReadError(e) {
128
- if ((e === null || e === void 0 ? void 0 : e.code) === 'ENOENT') {
129
- logger('template nor a file or string', 2 /* LogLevel.warn */, e);
130
- }
131
- else {
132
- logger('error reading template', 2 /* LogLevel.warn */, e);
133
- }
134
- }
135
- function warnAboutUsingDefaultTemplate() {
136
- logger('template is unusable by default template factory, using default one', 2 /* LogLevel.warn */);
137
- }
138
- async function buildStart() {
139
- this.addWatchFile(template);
140
- }
141
- async function generateBundle(options) {
142
- logger.start('generating html', logLevel);
143
- try {
144
- const dir = options.dir || '', fileName = path.relative(dir, fileNameInInitialDir);
145
- const depromisifiedTemplateString = await templateString, source = await templateFactory(depromisifiedTemplateString, assets, defaultTemplateFactory);
146
- if (!emitFile || fileName.startsWith('..') || useWriteBundle) {
147
- if (emitFile && emitFile !== 'auto') {
148
- logger('cannot emitFile because it is outside of current output.dir, using writeFile instead', 0 /* LogLevel.verbose */);
149
- }
150
- await fs.mkdir(path.dirname(fileNameInInitialDir), { recursive: true });
151
- await fs.writeFile(fileNameInInitialDir, source);
152
- }
153
- else {
154
- this.emitFile({
155
- type: 'asset',
156
- fileName,
157
- source
158
- });
159
- }
160
- // reset assets and configs for next iteration
161
- assets = freshAssets();
162
- processedFiles.clear();
163
- logger.finish('html file generated');
164
- }
165
- catch (e) {
166
- logger.finish('html generation failed', 3 /* LogLevel.error */, e);
167
- }
168
- }
169
- async function getAssets(options, bundle) {
170
- const dir = options.dir || '';
171
- for (const fileName of Object.keys(bundle)) {
172
- const relativeToRootAssetPath = path.join(dir, fileName);
173
- if (ignore(relativeToRootAssetPath) || processedFiles.has(relativeToRootAssetPath)) {
174
- continue;
175
- }
176
- processedFiles.add(relativeToRootAssetPath);
177
- if (bundle[fileName].type == 'asset') {
178
- if (await useAssetFactory(fileName, relativeToRootAssetPath, bundle[fileName].source, 'asset')) {
179
- continue;
180
- }
181
- if (fileName.endsWith(cssExtention)) {
182
- const assetPath = path.relative(initialDir, relativeToRootAssetPath);
183
- assets.asset.push({
184
- html: getLinkElement(assetPath),
185
- head: injectIntoHead(relativeToRootAssetPath),
186
- type: 'asset'
187
- });
188
- continue;
189
- }
190
- }
191
- else if (bundle[fileName].type == 'chunk') {
192
- const chunk = bundle[fileName];
193
- if (chunk.isEntry) {
194
- if (await useAssetFactory(fileName, relativeToRootAssetPath, chunk.code, options.format)) {
195
- continue;
196
- }
197
- if (options.format === 'es' || options.format === 'iife' || options.format === 'umd') {
198
- const assetPath = path.relative(initialDir, relativeToRootAssetPath);
199
- assets[options.format].push({
200
- html: (assets) => {
201
- let useConditionalLoading = conditionalLoading;
202
- useConditionalLoading !== null && useConditionalLoading !== void 0 ? useConditionalLoading : (useConditionalLoading = !!((assets.iife.length
203
- || assets.umd.length)
204
- && assets.es.length));
205
- return (options.format === 'iife' || options.format === 'umd') ? getNonModuleScriptElement(assetPath, !!useConditionalLoading) : getModuleScriptElement(assetPath);
206
- },
207
- head: injectIntoHead(relativeToRootAssetPath),
208
- type: 'asset'
209
- });
210
- }
211
- }
212
- }
213
- }
214
- }
215
- async function useAssetFactory(fileName, relativeToRootAssetPath, source, format) {
216
- if (assetsFactory) {
217
- try {
218
- let asset = await assetsFactory(fileName, source, format);
219
- if (asset) {
220
- if (typeof asset === 'string') {
221
- asset = {
222
- html: asset,
223
- head: injectIntoHead(relativeToRootAssetPath),
224
- type: format
225
- };
226
- }
227
- if (!assets[asset.type]) {
228
- assets[asset.type] = [];
229
- }
230
- assets[asset.type].push(asset);
231
- return true;
232
- }
233
- }
234
- catch (e) {
235
- logger('exception in assetFactory', 2 /* LogLevel.warn */, e);
236
- }
237
- }
238
- return false;
239
- }
240
- }
241
- function isUsableByDefaultTemplateFactory(template) {
242
- return template.indexOf(headClosingElement) >= 0 && template.indexOf(bodyClosingElement) >= 0;
243
- }
244
- function getLinkElement(fileName) {
245
- return `<link rel="stylesheet" href="${fileName}" type="text/css">`;
246
- }
247
- function getNonModuleScriptElement(fileName, conditionalLoading) {
248
- return `<script src="${fileName}" type="text/javascript"${conditionalLoading ? ' nomodule' : ''}></script>`;
249
- }
250
- function getModuleScriptElement(fileName) {
251
- return `<script src="${fileName}" type="module"></script>`;
252
- }
253
- function predicateFactory(options, field) {
254
- if (options[field] != null) {
255
- const predicate = toAssetPredicate(options[field]);
256
- if (predicate) {
257
- return predicate;
258
- }
259
- else {
260
- options.logger && options.logger(`${field} option ignored because it is not a function, RegExp or boolean`, 2 /* LogLevel.warn */);
261
- }
262
- }
263
- return defaults[field];
264
- }
265
- function toAssetPredicate(sourceOption) {
266
- if (typeof sourceOption === 'boolean') {
267
- return () => sourceOption;
268
- }
269
- else if (typeof sourceOption === 'function') {
270
- return sourceOption;
271
- }
272
- else if (sourceOption instanceof RegExp) {
273
- return (fileName) => sourceOption.test(fileName);
274
- }
275
- return undefined;
276
- }
277
- function defaultTemplateFactory(template, assets) {
278
- const assetsAsArray = assets.asset
279
- .concat((assets.iife.length ? assets.iife : assets.umd))
280
- .concat(assets.es)
281
- .map((asset) => {
282
- if (typeof asset.html === 'function') {
283
- asset.html = asset.html(assets);
284
- }
285
- return asset;
286
- });
287
- const headElements = assetsAsArray.filter(asset => asset.head).map(asset => asset.html);
288
- const bodyElements = assetsAsArray.filter(asset => !asset.head).map(asset => asset.html);
289
- const headIndex = template.toLowerCase().indexOf(headClosingElement);
290
- template = `${template.substring(0, headIndex)}${headElements.join('')}${template.substring(headIndex)}`;
291
- const bodyIndex = template.toLowerCase().indexOf(bodyClosingElement);
292
- return `${template.substring(0, bodyIndex)}${bodyElements.join('')}${template.substring(bodyIndex)}`;
9
+ const defaultTemplate = '<!DOCTYPE html><html><head></head><body></body></html>';
10
+ const headClosingElement = '</head>';
11
+ const bodyClosingElement = '</body>';
12
+ const cssExtention = '.css';
13
+ const defaults = {
14
+ pluginName: '@rollup-extras/plugin-html',
15
+ outputFile: 'index.html',
16
+ watch: true,
17
+ useWriteBundle: false,
18
+ emitFile: 'auto',
19
+ injectIntoHead: (fileName) => fileName.endsWith(cssExtention),
20
+ ignore: toAssetPredicate(false),
21
+ templateFactory: ((template, assets, defaultTemplateFactory) => defaultTemplateFactory(template, assets))
22
+ };
23
+ const factories = { logger, injectIntoHead: predicateFactory, ignore: predicateFactory };
24
+ function index (options = {}) {
25
+ const { pluginName, outputFile, template, watch, emitFile, conditionalLoading, logger, useWriteBundle, logLevel, useEmittedTemplate, injectIntoHead, ignore, assetsFactory, templateFactory } = getOptionsObject(options, {
26
+ ...defaults,
27
+ useEmittedTemplate: !('template' in options),
28
+ logLevel: options.verbose ? 1 /* LogLevel.info */ : 0 /* LogLevel.verbose */
29
+ }, factories), hasCustomTemplateFactory = 'templateFactory' in options;
30
+ let templateString = defaultTemplate, hasTemplateFile = false;
31
+ if (template) {
32
+ if (isUsableByDefaultTemplateFactory(template)) {
33
+ templateString = template;
34
+ }
35
+ else {
36
+ if (watch) {
37
+ try {
38
+ // using sync fs call because we need to return plugin object immidiately
39
+ useNewTemplate(oldStyleFs.readFileSync(template, { encoding: 'utf8' }));
40
+ hasTemplateFile = true;
41
+ }
42
+ catch (e) {
43
+ handleTemplateReadError(e);
44
+ }
45
+ }
46
+ else {
47
+ templateString = new Promise(resolve => {
48
+ fs.readFile(template, { encoding: 'utf8' })
49
+ .then((newTemplateString) => {
50
+ if (!isUsableByDefaultTemplateFactory(newTemplateString) && !hasCustomTemplateFactory) {
51
+ warnAboutUsingDefaultTemplate();
52
+ resolve(defaultTemplate);
53
+ }
54
+ else {
55
+ resolve(newTemplateString);
56
+ }
57
+ })
58
+ .catch(handleTemplateReadError);
59
+ });
60
+ }
61
+ }
62
+ }
63
+ let initialDir = '', fileNameInInitialDir, assets = freshAssets();
64
+ const processedFiles = new Set();
65
+ const instance = multiConfigPluginBase(useWriteBundle, pluginName, generateBundle, updateAssets);
66
+ const baseRenderStart = instance.renderStart;
67
+ const baseAddInstance = instance.api.addInstance;
68
+ instance.renderStart = function (outputOptions, inputOptions) {
69
+ logger('started collecting information', 0 /* LogLevel.verbose */);
70
+ initialDir = outputOptions.dir || '';
71
+ fileNameInInitialDir = path.join(initialDir, outputFile);
72
+ return baseRenderStart.call(this, outputOptions, inputOptions);
73
+ };
74
+ instance.api.addInstance = () => {
75
+ const instance = baseAddInstance();
76
+ if (hasTemplateFile && watch) {
77
+ instance.buildStart = buildStart;
78
+ }
79
+ return instance;
80
+ };
81
+ if (hasTemplateFile && watch) {
82
+ instance.buildStart = async function () {
83
+ try {
84
+ useNewTemplate(await fs.readFile(template, { encoding: 'utf8' }));
85
+ }
86
+ catch (e) {
87
+ handleTemplateReadError(e);
88
+ }
89
+ await buildStart.apply(this);
90
+ };
91
+ }
92
+ return instance;
93
+ async function updateAssets(options, bundle, remainingConfigsCount, remainingOutputsCount) {
94
+ await getAssets(options, bundle);
95
+ const statistics = Object.keys(assets)
96
+ .map(key => ({ key, count: assets[key].length }))
97
+ .filter(item => item.count)
98
+ .map(({ key, count }) => `${key}: ${count}`)
99
+ .join(', ');
100
+ logger(`assets collected: [${statistics}], remaining: ${remainingOutputsCount} outputs, ${remainingConfigsCount} configs`, 0 /* LogLevel.verbose */);
101
+ const dir = options.dir || '', fileName = path.relative(dir, fileNameInInitialDir);
102
+ if (fileName in bundle) {
103
+ if (useEmittedTemplate) {
104
+ logger(`using exiting emitted ${fileName} as an input for out templateFactory`, 0 /* LogLevel.verbose */);
105
+ const source = bundle[fileName].type === 'asset' ? bundle[fileName].source.toString() : bundle[fileName].code;
106
+ useNewTemplate(source);
107
+ }
108
+ else {
109
+ logger(`removing exiting emitted ${fileName}`, 0 /* LogLevel.verbose */);
110
+ }
111
+ if (remainingConfigsCount === 0 && emitFile && !useWriteBundle) {
112
+ delete bundle[fileName];
113
+ }
114
+ }
115
+ }
116
+ function freshAssets() {
117
+ return {
118
+ asset: [],
119
+ es: [],
120
+ iife: [],
121
+ umd: []
122
+ };
123
+ }
124
+ function useNewTemplate(newTemplateString) {
125
+ if (!isUsableByDefaultTemplateFactory(newTemplateString) && !hasCustomTemplateFactory) {
126
+ warnAboutUsingDefaultTemplate();
127
+ }
128
+ else {
129
+ templateString = newTemplateString;
130
+ }
131
+ }
132
+ function handleTemplateReadError(e) {
133
+ if (e?.code === 'ENOENT') {
134
+ logger('template nor a file or string', 2 /* LogLevel.warn */, e);
135
+ }
136
+ else {
137
+ logger('error reading template', 2 /* LogLevel.warn */, e);
138
+ }
139
+ }
140
+ function warnAboutUsingDefaultTemplate() {
141
+ logger('template is unusable by default template factory, using default one', 2 /* LogLevel.warn */);
142
+ }
143
+ async function buildStart() {
144
+ this.addWatchFile(template);
145
+ }
146
+ async function generateBundle(options) {
147
+ logger.start('generating html', logLevel);
148
+ try {
149
+ const dir = options.dir || '', fileName = path.relative(dir, fileNameInInitialDir);
150
+ const depromisifiedTemplateString = await templateString, source = await templateFactory(depromisifiedTemplateString, assets, defaultTemplateFactory);
151
+ if (!emitFile || fileName.startsWith('..') || useWriteBundle) {
152
+ if (emitFile && emitFile !== 'auto') {
153
+ logger('cannot emitFile because it is outside of current output.dir, using writeFile instead', 0 /* LogLevel.verbose */);
154
+ }
155
+ await fs.mkdir(path.dirname(fileNameInInitialDir), { recursive: true });
156
+ await fs.writeFile(fileNameInInitialDir, source);
157
+ }
158
+ else {
159
+ this.emitFile({
160
+ type: 'asset',
161
+ fileName,
162
+ source
163
+ });
164
+ }
165
+ // reset assets and configs for the next iteration
166
+ assets = freshAssets();
167
+ processedFiles.clear();
168
+ logger.finish('html file generated');
169
+ }
170
+ catch (e) {
171
+ logger.finish('html generation failed', 3 /* LogLevel.error */, e);
172
+ }
173
+ }
174
+ async function getAssets(options, bundle) {
175
+ const dir = options.dir || '';
176
+ for (const fileName of Object.keys(bundle)) {
177
+ const relativeToRootAssetPath = path.join(dir, fileName);
178
+ if (ignore(relativeToRootAssetPath) || processedFiles.has(relativeToRootAssetPath)) {
179
+ continue;
180
+ }
181
+ processedFiles.add(relativeToRootAssetPath);
182
+ if (bundle[fileName].type === 'asset') {
183
+ if (await useAssetFactory(fileName, relativeToRootAssetPath, bundle[fileName].source, 'asset')) {
184
+ continue;
185
+ }
186
+ if (fileName.endsWith(cssExtention)) {
187
+ const assetPath = path.relative(initialDir, relativeToRootAssetPath);
188
+ assets.asset.push({
189
+ html: getLinkElement(assetPath),
190
+ head: injectIntoHead(relativeToRootAssetPath),
191
+ type: 'asset'
192
+ });
193
+ continue;
194
+ }
195
+ }
196
+ else if (bundle[fileName].type === 'chunk') {
197
+ const chunk = bundle[fileName];
198
+ if (chunk.isEntry) {
199
+ if (await useAssetFactory(fileName, relativeToRootAssetPath, chunk.code, options.format)) {
200
+ continue;
201
+ }
202
+ if (options.format === 'es' || options.format === 'iife' || options.format === 'umd') {
203
+ const assetPath = path.relative(initialDir, relativeToRootAssetPath);
204
+ assets[options.format].push({
205
+ html: (assets) => {
206
+ let useConditionalLoading = conditionalLoading;
207
+ useConditionalLoading ??= !!((assets.iife.length
208
+ || assets.umd.length)
209
+ && assets.es.length);
210
+ return (options.format === 'iife' || options.format === 'umd') ? getNonModuleScriptElement(assetPath, !!useConditionalLoading) : getModuleScriptElement(assetPath);
211
+ },
212
+ head: injectIntoHead(relativeToRootAssetPath),
213
+ type: 'asset'
214
+ });
215
+ }
216
+ }
217
+ }
218
+ }
219
+ }
220
+ async function useAssetFactory(fileName, relativeToRootAssetPath, source, format) {
221
+ if (assetsFactory) {
222
+ try {
223
+ let asset = await assetsFactory(fileName, source, format);
224
+ if (asset) {
225
+ if (typeof asset === 'string') {
226
+ asset = {
227
+ html: asset,
228
+ head: injectIntoHead(relativeToRootAssetPath),
229
+ type: format
230
+ };
231
+ }
232
+ if (!assets[asset.type]) {
233
+ assets[asset.type] = [];
234
+ }
235
+ assets[asset.type].push(asset);
236
+ return true;
237
+ }
238
+ }
239
+ catch (e) {
240
+ logger('exception in assetFactory', 2 /* LogLevel.warn */, e);
241
+ }
242
+ }
243
+ return false;
244
+ }
245
+ }
246
+ function isUsableByDefaultTemplateFactory(template) {
247
+ return template.indexOf(headClosingElement) >= 0 && template.indexOf(bodyClosingElement) >= 0;
248
+ }
249
+ function predicateFactory(options, field) {
250
+ if (options[field] != null) {
251
+ const predicate = toAssetPredicate(options[field]);
252
+ if (predicate) {
253
+ return predicate;
254
+ }
255
+ else {
256
+ options.logger && options.logger(`${field} option ignored because it is not a function, RegExp, string or boolean`, 2 /* LogLevel.warn */);
257
+ }
258
+ }
259
+ return defaults[field];
260
+ }
261
+ function defaultTemplateFactory(template, assets) {
262
+ const assetsAsArray = assets.asset
263
+ .concat((assets.iife.length ? assets.iife : assets.umd))
264
+ .concat(assets.es)
265
+ .map((asset) => {
266
+ if (typeof asset.html === 'function') {
267
+ asset.html = asset.html(assets);
268
+ }
269
+ return asset;
270
+ });
271
+ const headElements = assetsAsArray.filter(asset => asset.head).map(asset => asset.html);
272
+ const bodyElements = assetsAsArray.filter(asset => !asset.head).map(asset => asset.html);
273
+ const headIndex = template.toLowerCase().indexOf(headClosingElement);
274
+ template = `${template.substring(0, headIndex)}${headElements.join('')}${template.substring(headIndex)}`;
275
+ const bodyIndex = template.toLowerCase().indexOf(bodyClosingElement);
276
+ return `${template.substring(0, bodyIndex)}${bodyElements.join('')}${template.substring(bodyIndex)}`;
293
277
  }
294
278
 
295
279
  export { index as default };
@@ -0,0 +1,31 @@
1
+ 'use strict';
2
+
3
+ function getLinkElement(fileName) {
4
+ return `<link rel="stylesheet" href="${fileName}" type="text/css">`;
5
+ }
6
+ function getNonModuleScriptElement(fileName, conditionalLoading) {
7
+ return `<script src="${fileName}" type="text/javascript"${conditionalLoading ? ' nomodule' : ''}></script>`;
8
+ }
9
+ function getModuleScriptElement(fileName) {
10
+ return `<script src="${fileName}" type="module"></script>`;
11
+ }
12
+ function toAssetPredicate(sourceOption) {
13
+ if (typeof sourceOption === 'boolean') {
14
+ return () => sourceOption;
15
+ }
16
+ else if (typeof sourceOption === 'function') {
17
+ return sourceOption;
18
+ }
19
+ else if (sourceOption instanceof RegExp) {
20
+ return (fileName) => sourceOption.test(fileName);
21
+ }
22
+ else if (typeof sourceOption === 'string') {
23
+ return (fileName) => fileName.endsWith(sourceOption);
24
+ }
25
+ return undefined;
26
+ }
27
+
28
+ exports.getLinkElement = getLinkElement;
29
+ exports.getModuleScriptElement = getModuleScriptElement;
30
+ exports.getNonModuleScriptElement = getNonModuleScriptElement;
31
+ exports.toAssetPredicate = toAssetPredicate;
@@ -0,0 +1,5 @@
1
+ import type { AssetPredicate, PredicateSource } from './types';
2
+ export declare function getLinkElement(fileName: string): string;
3
+ export declare function getNonModuleScriptElement(fileName: string, conditionalLoading: boolean): string;
4
+ export declare function getModuleScriptElement(fileName: string): string;
5
+ export declare function toAssetPredicate(sourceOption: PredicateSource): AssetPredicate | undefined;
@@ -0,0 +1,26 @@
1
+ function getLinkElement(fileName) {
2
+ return `<link rel="stylesheet" href="${fileName}" type="text/css">`;
3
+ }
4
+ function getNonModuleScriptElement(fileName, conditionalLoading) {
5
+ return `<script src="${fileName}" type="text/javascript"${conditionalLoading ? ' nomodule' : ''}></script>`;
6
+ }
7
+ function getModuleScriptElement(fileName) {
8
+ return `<script src="${fileName}" type="module"></script>`;
9
+ }
10
+ function toAssetPredicate(sourceOption) {
11
+ if (typeof sourceOption === 'boolean') {
12
+ return () => sourceOption;
13
+ }
14
+ else if (typeof sourceOption === 'function') {
15
+ return sourceOption;
16
+ }
17
+ else if (sourceOption instanceof RegExp) {
18
+ return (fileName) => sourceOption.test(fileName);
19
+ }
20
+ else if (typeof sourceOption === 'string') {
21
+ return (fileName) => fileName.endsWith(sourceOption);
22
+ }
23
+ return undefined;
24
+ }
25
+
26
+ export { getNonModuleScriptElement as a, getModuleScriptElement as b, getLinkElement as g, toAssetPredicate as t };