@qubit-ltd/rollup-builder 1.8.4

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.
Files changed (49) hide show
  1. package/LICENSE +201 -0
  2. package/README.md +335 -0
  3. package/README.zh_CN.md +288 -0
  4. package/dist/rollup-builder.cjs +793 -0
  5. package/dist/rollup-builder.cjs.map +1 -0
  6. package/dist/rollup-builder.min.cjs +1 -0
  7. package/dist/rollup-builder.min.cjs.map +1 -0
  8. package/dist/rollup-builder.min.mjs +1 -0
  9. package/dist/rollup-builder.min.mjs.map +1 -0
  10. package/dist/rollup-builder.mjs +791 -0
  11. package/dist/rollup-builder.mjs.map +1 -0
  12. package/doc/api/fonts/OpenSans-Bold-webfont.eot +0 -0
  13. package/doc/api/fonts/OpenSans-Bold-webfont.svg +1838 -0
  14. package/doc/api/fonts/OpenSans-Bold-webfont.woff +0 -0
  15. package/doc/api/fonts/OpenSans-BoldItalic-webfont.eot +0 -0
  16. package/doc/api/fonts/OpenSans-BoldItalic-webfont.svg +1838 -0
  17. package/doc/api/fonts/OpenSans-BoldItalic-webfont.woff +0 -0
  18. package/doc/api/fonts/OpenSans-Italic-webfont.eot +0 -0
  19. package/doc/api/fonts/OpenSans-Italic-webfont.svg +1838 -0
  20. package/doc/api/fonts/OpenSans-Italic-webfont.woff +0 -0
  21. package/doc/api/fonts/OpenSans-Light-webfont.eot +0 -0
  22. package/doc/api/fonts/OpenSans-Light-webfont.svg +1839 -0
  23. package/doc/api/fonts/OpenSans-Light-webfont.woff +0 -0
  24. package/doc/api/fonts/OpenSans-LightItalic-webfont.eot +0 -0
  25. package/doc/api/fonts/OpenSans-LightItalic-webfont.svg +1843 -0
  26. package/doc/api/fonts/OpenSans-LightItalic-webfont.woff +0 -0
  27. package/doc/api/fonts/OpenSans-Regular-webfont.eot +0 -0
  28. package/doc/api/fonts/OpenSans-Regular-webfont.svg +1839 -0
  29. package/doc/api/fonts/OpenSans-Regular-webfont.woff +0 -0
  30. package/doc/api/fonts/OpenSans-Semibold-webfont.eot +0 -0
  31. package/doc/api/fonts/OpenSans-Semibold-webfont.svg +1838 -0
  32. package/doc/api/fonts/OpenSans-Semibold-webfont.ttf +0 -0
  33. package/doc/api/fonts/OpenSans-Semibold-webfont.woff +0 -0
  34. package/doc/api/fonts/OpenSans-SemiboldItalic-webfont.eot +0 -0
  35. package/doc/api/fonts/OpenSans-SemiboldItalic-webfont.svg +1838 -0
  36. package/doc/api/fonts/OpenSans-SemiboldItalic-webfont.ttf +0 -0
  37. package/doc/api/fonts/OpenSans-SemiboldItalic-webfont.woff +0 -0
  38. package/doc/api/global.html +2913 -0
  39. package/doc/api/index.html +418 -0
  40. package/doc/api/scripts/linenumber.js +34 -0
  41. package/doc/api/scripts/prettify/Apache-License-2.0.txt +202 -0
  42. package/doc/api/scripts/prettify/lang-css.js +2 -0
  43. package/doc/api/scripts/prettify/prettify.js +28 -0
  44. package/doc/api/styles/jsdoc-default.css +699 -0
  45. package/doc/api/styles/prettify-jsdoc.css +120 -0
  46. package/doc/api/styles/prettify-tomorrow.css +141 -0
  47. package/doc/rollup-builder.min.visualization.html +4842 -0
  48. package/doc/rollup-builder.visualization.html +4842 -0
  49. package/package.json +85 -0
@@ -0,0 +1,793 @@
1
+ 'use strict';
2
+
3
+ var _defineProperty = require('@babel/runtime/helpers/defineProperty');
4
+ var _toConsumableArray = require('@babel/runtime/helpers/toConsumableArray');
5
+ var node_module = require('node:module');
6
+ var json = require('@rollup/plugin-json');
7
+ var node_url = require('node:url');
8
+ var alias = require('@rollup/plugin-alias');
9
+ var nodeResolve = require('@rollup/plugin-node-resolve');
10
+ var commonjs = require('@rollup/plugin-commonjs');
11
+ var babel = require('@rollup/plugin-babel');
12
+ var terser = require('@rollup/plugin-terser');
13
+ var analyzer = require('rollup-plugin-analyzer');
14
+ var rollupPluginVisualizer = require('rollup-plugin-visualizer');
15
+
16
+ function _createForOfIteratorHelper$1(r, e) { var t = "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (!t) { if (Array.isArray(r) || (t = _unsupportedIterableToArray$1(r)) || e) { t && (r = t); var _n = 0, F = function F() {}; return { s: F, n: function n() { return _n >= r.length ? { done: !0 } : { done: !1, value: r[_n++] }; }, e: function e(r) { throw r; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var o, a = !0, u = !1; return { s: function s() { t = t.call(r); }, n: function n() { var r = t.next(); return a = r.done, r; }, e: function e(r) { u = !0, o = r; }, f: function f() { try { a || null == t["return"] || t["return"](); } finally { if (u) throw o; } } }; }
17
+ function _unsupportedIterableToArray$1(r, a) { if (r) { if ("string" == typeof r) return _arrayLikeToArray$1(r, a); var t = {}.toString.call(r).slice(8, -1); return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray$1(r, a) : void 0; } }
18
+ function _arrayLikeToArray$1(r, a) { (null == a || a > r.length) && (a = r.length); for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e]; return n; }
19
+
20
+ /**
21
+ * Gets Rollup `external` configuration.
22
+ *
23
+ * @param {string} importMetaUrl
24
+ * The URL of the `import.meta` of the caller module.
25
+ * @param {object} options
26
+ * The additional options for building the library.
27
+ * @returns {function}
28
+ * The predicate used as the Rollup `external` configuration for the library.
29
+ * @author Haixing Hu
30
+ */
31
+ function getRollupExternal(importMetaUrl, options) {
32
+ var _options$externals;
33
+ if (!importMetaUrl) {
34
+ throw new Error('importMetaUrl is required');
35
+ }
36
+ if (!options) {
37
+ throw new Error('options is required');
38
+ }
39
+ // gets all peerDependencies packages from 'package.json' of the caller module
40
+ var require = node_module.createRequire(importMetaUrl);
41
+ var pkg = require('./package.json');
42
+ var peers = _toConsumableArray(Object.keys(pkg.peerDependencies || {}));
43
+ if (!Array.isArray(peers)) {
44
+ throw new Error('peerDependencies should be an array');
45
+ }
46
+ if (peers.length === 0) {
47
+ return [];
48
+ }
49
+ var peerPattern = peers ? new RegExp("^(".concat(peers.join('|'), ")($|/)")) : null;
50
+ // gets the additional external packages from the user passed options
51
+ var additions = (_options$externals = options.externals) !== null && _options$externals !== void 0 ? _options$externals : [];
52
+ // save some configuration to the options object
53
+ options.peers = peers;
54
+ options.peerPattern = peerPattern;
55
+ return function (id) {
56
+ if (peerPattern && peerPattern.test(id)) {
57
+ return true;
58
+ }
59
+ var _iterator = _createForOfIteratorHelper$1(additions),
60
+ _step;
61
+ try {
62
+ for (_iterator.s(); !(_step = _iterator.n()).done;) {
63
+ var pattern = _step.value;
64
+ if (pattern instanceof RegExp && pattern.test(id)) {
65
+ return true;
66
+ }
67
+ if ((typeof pattern === 'string' || pattern instanceof String) && pattern === id) {
68
+ return true;
69
+ }
70
+ }
71
+ } catch (err) {
72
+ _iterator.e(err);
73
+ } finally {
74
+ _iterator.f();
75
+ }
76
+ return false;
77
+ };
78
+ }
79
+
80
+ ////////////////////////////////////////////////////////////////////////////////
81
+ //
82
+ // Copyright (c) 2022 - 2023.
83
+ // Haixing Hu, Qubit Co. Ltd.
84
+ //
85
+ // All rights reserved.
86
+ //
87
+ ////////////////////////////////////////////////////////////////////////////////
88
+
89
+ /**
90
+ * Gets the Rollup `output` configuration.
91
+ *
92
+ * @param {string} format
93
+ * The format of the library.
94
+ * @param {string} libraryName
95
+ * The name of the library.
96
+ * @param {object} options
97
+ * The additional options for building the library.
98
+ * @returns {object}
99
+ * The Rollup output configuration for the library.
100
+ * @author Haixing Hu
101
+ */
102
+ function getRollupOutput(format, libraryName, options) {
103
+ var _options$exports, _options$nodeEnv, _options$minify, _options$filenamePref, _options$outputDir, _options$sourcemap;
104
+ var filenameExt = '';
105
+ var footer = '';
106
+ var exports = (_options$exports = options.exports) !== null && _options$exports !== void 0 ? _options$exports : 'auto';
107
+ switch (format) {
108
+ case 'cjs': // drop down
109
+ case 'umd':
110
+ // drop down
111
+ filenameExt = format === 'cjs' ? '.cjs' : ".".concat(format, ".js");
112
+ // The following workaround is to solve the following issue: If an ESM
113
+ // module has both default export and named exports, the rollup cannot
114
+ // handle it correctly. For example, the following is a source ESM module:
115
+ // ```js
116
+ // export { Foo, Bar };
117
+ // export default Foo;
118
+ // ```
119
+ // The rollup will translate it into the following codes:
120
+ // ```js
121
+ // exports.Foo = Foo;
122
+ // exports.Bar = Bar;
123
+ // exports.default = Foo;
124
+ // ```
125
+ // However, a common-js consumer will use the module as follows:
126
+ // ```js
127
+ // const Foo = require('my-module');
128
+ // ```
129
+ // which will cause an error. The correct usage should be
130
+ // ```js
131
+ // const Foo = require('my-module').default
132
+ // ```
133
+ // But unfortunately, the rollup will translate the ESM default import as
134
+ // follows:
135
+ // ```js
136
+ // import Foo from 'my-module';
137
+ // ```
138
+ // will be translated by rollup to
139
+ // ```js
140
+ // const Foo = require('my-module');
141
+ // ```
142
+ // Note that the above translation has no `.default` suffix, which will
143
+ // cause an error.
144
+ //
145
+ // The workaround is copied from the source code of the official rollup
146
+ // plugins:
147
+ // https://github.com/rollup/plugins/blob/master/shared/rollup.config.mjs
148
+ //
149
+ // It adds a simple footer statements to each `CJS` format bundle:
150
+ // ```js
151
+ // module.exports = Object.assign(exports.default, exports);
152
+ // ```
153
+ //
154
+ // See:
155
+ // [1] https://rollupjs.org/configuration-options/#output-exports
156
+ // [2] https://github.com/rollup/rollup/issues/1961
157
+ // [3] https://stackoverflow.com/questions/58246998/mixing-default-and-named-exports-with-rollup
158
+ // [4] https://github.com/avisek/rollup-patch-seamless-default-export
159
+ // [5] https://github.com/rollup/plugins/blob/master/shared/rollup.config.mjs
160
+ //
161
+ if (exports === 'mixed') {
162
+ exports = 'named';
163
+ footer = 'module.exports = Object.assign(exports.default, exports);';
164
+ }
165
+ break;
166
+ case 'amd': // drop down
167
+ case 'iife':
168
+ filenameExt = ".".concat(format, ".js");
169
+ if (exports === 'mixed') {
170
+ exports = 'auto';
171
+ }
172
+ break;
173
+ case 'es': // drop down
174
+ case 'esm': // drop down
175
+ case 'module':
176
+ format = 'es';
177
+ filenameExt = '.mjs';
178
+ // fix the exports, because the ESM format does not support the 'mixed' exports mode
179
+ if (exports === 'mixed') {
180
+ exports = 'auto';
181
+ }
182
+ break;
183
+ default:
184
+ throw new Error("Unsupported library format: ".concat(format));
185
+ }
186
+ var nodeEnv = (_options$nodeEnv = options.nodeEnv) !== null && _options$nodeEnv !== void 0 ? _options$nodeEnv : process.env.NODE_ENV;
187
+ var minify = (_options$minify = options.minify) !== null && _options$minify !== void 0 ? _options$minify : nodeEnv === 'production';
188
+ var camelCaseToDashCase = function camelCaseToDashCase(s) {
189
+ return s.replace(/([a-z])([A-Z])/g, '$1-$2').toLowerCase();
190
+ };
191
+ var filenamePrefix = (_options$filenamePref = options.filenamePrefix) !== null && _options$filenamePref !== void 0 ? _options$filenamePref : camelCaseToDashCase(libraryName);
192
+ var filenameBase = "".concat(filenamePrefix).concat(minify ? '.min' : '');
193
+ var filename = "".concat(filenameBase).concat(filenameExt);
194
+ var outputDir = (_options$outputDir = options.outputDir) !== null && _options$outputDir !== void 0 ? _options$outputDir : 'dist';
195
+ var sourcemap = (_options$sourcemap = options.sourcemap) !== null && _options$sourcemap !== void 0 ? _options$sourcemap : true;
196
+ // save some configuration to the options object
197
+ options.format = format;
198
+ options.name = libraryName;
199
+ options.minify = minify;
200
+ options.filenamePrefix = filenamePrefix;
201
+ options.filenameBase = filenameBase;
202
+ options.filenameExt = filenameExt;
203
+ options.filename = filename;
204
+ options.exports = exports;
205
+ options.sourcemap = sourcemap;
206
+ options.outputDir = outputDir;
207
+ return {
208
+ name: libraryName,
209
+ file: "".concat(outputDir, "/").concat(filename),
210
+ format: format,
211
+ exports: exports,
212
+ footer: footer,
213
+ sourcemap: sourcemap,
214
+ compact: minify
215
+ };
216
+ }
217
+
218
+ ////////////////////////////////////////////////////////////////////////////////
219
+ //
220
+ // Copyright (c) 2022 - 2023.
221
+ // Haixing Hu, Qubit Co. Ltd.
222
+ //
223
+ // All rights reserved.
224
+ //
225
+ ////////////////////////////////////////////////////////////////////////////////
226
+
227
+ /**
228
+ * Configures the `@rollup/plugin-alias` plugin.
229
+ *
230
+ * @param {string} format
231
+ * The format of the library.
232
+ * @param {string} importMetaUrl
233
+ * The URL of the `import.meta` of the caller module.
234
+ * @param {object} options
235
+ * The additional options for building the library.
236
+ * @param {Array<Object>} plugins
237
+ * The Rollup plugins array.
238
+ * @returns {Array<Object>}
239
+ * The modified Rollup plugins array.
240
+ * @author Haixing Hu
241
+ * @see https://www.npmjs.com/package/@rollup/plugin-alias
242
+ */
243
+ function configAliasPlugin(format, importMetaUrl, options, plugins) {
244
+ var _options$useAliasPlug;
245
+ if ((_options$useAliasPlug = options.useAliasPlugin) !== null && _options$useAliasPlug !== void 0 ? _options$useAliasPlug : true) {
246
+ var _options$aliasPluginO;
247
+ // The @rollup/plugin-alias enables us to use absolute import paths for
248
+ // "src" (or any other path you want to configure).
249
+ var pluginOptions = (_options$aliasPluginO = options.aliasPluginOptions) !== null && _options$aliasPluginO !== void 0 ? _options$aliasPluginO : {
250
+ entries: {
251
+ 'src': node_url.fileURLToPath(new URL('src', importMetaUrl))
252
+ }
253
+ };
254
+ if (options.debug === true) {
255
+ console.debug('[DEBUG] The @rollup/plugin-alias plugin options are:');
256
+ console.dir(pluginOptions, {
257
+ depth: null
258
+ });
259
+ }
260
+ plugins.push(alias(pluginOptions));
261
+ }
262
+ return plugins;
263
+ }
264
+
265
+ ////////////////////////////////////////////////////////////////////////////////
266
+ //
267
+ // Copyright (c) 2022 - 2023.
268
+ // Haixing Hu, Qubit Co. Ltd.
269
+ //
270
+ // All rights reserved.
271
+ //
272
+ ////////////////////////////////////////////////////////////////////////////////
273
+
274
+ /**
275
+ * Configures the `@rollup/plugin-node-resolve` plugin.
276
+ *
277
+ * @param {string} format
278
+ * The format of the library.
279
+ * @param {string} importMetaUrl
280
+ * The URL of the `import.meta` of the caller module.
281
+ * @param {object} options
282
+ * The additional options for building the library.
283
+ * @param {Array<Object>} plugins
284
+ * The Rollup plugins array.
285
+ * @returns {Array<Object>}
286
+ * The modified Rollup plugins array.
287
+ * @author Haixing Hu
288
+ * @see https://www.npmjs.com/package/@rollup/plugin-node-resolve
289
+ */
290
+ function configNodeResolvePlugin(format, importMetaUrl, options, plugins) {
291
+ var _options$useNodeResol;
292
+ if ((_options$useNodeResol = options.useNodeResolvePlugin) !== null && _options$useNodeResol !== void 0 ? _options$useNodeResol : true) {
293
+ var _options$nodeResolveP;
294
+ // The @rollup/plugin-node-resolve allows Rollup to resolve external
295
+ // modules from node_modules:
296
+ var pluginOptions = (_options$nodeResolveP = options.nodeResolvePluginOptions) !== null && _options$nodeResolveP !== void 0 ? _options$nodeResolveP : {};
297
+ if (options.debug === true) {
298
+ console.debug('[DEBUG] The @rollup/plugin-node-resolve plugin options are:');
299
+ console.dir(pluginOptions, {
300
+ depth: null
301
+ });
302
+ }
303
+ plugins.push(nodeResolve(pluginOptions));
304
+ }
305
+ return plugins;
306
+ }
307
+
308
+ ////////////////////////////////////////////////////////////////////////////////
309
+ //
310
+ // Copyright (c) 2022 - 2023.
311
+ // Haixing Hu, Qubit Co. Ltd.
312
+ //
313
+ // All rights reserved.
314
+ //
315
+ ////////////////////////////////////////////////////////////////////////////////
316
+
317
+ /**
318
+ * Configures the `@rollup/plugin-commonjs` plugin.
319
+ *
320
+ * @param {string} format
321
+ * The format of the library.
322
+ * @param {string} importMetaUrl
323
+ * The URL of the `import.meta` of the caller module.
324
+ * @param {object} options
325
+ * The additional options for building the library.
326
+ * @param {Array<Object>} plugins
327
+ * The Rollup plugins array.
328
+ * @returns {Array<Object>}
329
+ * The modified Rollup plugins array.
330
+ * @author Haixing Hu
331
+ * @see https://www.npmjs.com/package/@rollup/plugin-commonjs
332
+ */
333
+ function configCommonJsPlugin(format, importMetaUrl, options, plugins) {
334
+ var _options$useCommonjsP;
335
+ if ((_options$useCommonjsP = options.useCommonjsPlugin) !== null && _options$useCommonjsP !== void 0 ? _options$useCommonjsP : true) {
336
+ var _options$commonjsPlug;
337
+ // The @rollup/plugin-commonjs plugin converts 3rd-party CommonJS modules
338
+ // into ES6 code, so that they can be included in our Rollup bundle.
339
+ // When using @rollup/plugin-babel with @rollup/plugin-commonjs in the
340
+ // same Rollup configuration, it's important to note that
341
+ // @rollup/plugin-commonjs must be placed before this plugin in the
342
+ // plugins array for the two to work together properly.
343
+ var pluginOptions = (_options$commonjsPlug = options.commonjsPluginOptions) !== null && _options$commonjsPlug !== void 0 ? _options$commonjsPlug : {
344
+ include: ['node_modules/**']
345
+ };
346
+ if (options.debug === true) {
347
+ console.debug('[DEBUG] The @rollup/plugin-commonjs plugin options are:');
348
+ console.dir(pluginOptions, {
349
+ depth: null
350
+ });
351
+ }
352
+ plugins.push(commonjs(pluginOptions));
353
+ }
354
+ return plugins;
355
+ }
356
+
357
+ ////////////////////////////////////////////////////////////////////////////////
358
+ //
359
+ // Copyright (c) 2022 - 2023.
360
+ // Haixing Hu, Qubit Co. Ltd.
361
+ //
362
+ // All rights reserved.
363
+ //
364
+ ////////////////////////////////////////////////////////////////////////////////
365
+
366
+ /**
367
+ * Configures the `@rollup/plugin-babel` plugin.
368
+ *
369
+ * @param {string} format
370
+ * The format of the library.
371
+ * @param {string} importMetaUrl
372
+ * The URL of the `import.meta` of the caller module.
373
+ * @param {object} options
374
+ * The additional options for building the library.
375
+ * @param {Array} plugins
376
+ * The array of Rollup plugins.
377
+ * @returns {Array<Object>}
378
+ * The modified Rollup plugins array.
379
+ * @author Haixing Hu
380
+ * @see https://www.npmjs.com/package/@rollup/plugin-babel
381
+ */
382
+ function configBabelPlugin(format, importMetaUrl, options, plugins) {
383
+ var _options$useBabelPlug;
384
+ if ((_options$useBabelPlug = options.useBabelPlugin) !== null && _options$useBabelPlug !== void 0 ? _options$useBabelPlug : true) {
385
+ var _options$babelPluginO;
386
+ var pluginOptions = (_options$babelPluginO = options.babelPluginOptions) !== null && _options$babelPluginO !== void 0 ? _options$babelPluginO : {
387
+ babelHelpers: 'runtime',
388
+ exclude: ['node_modules/**'],
389
+ presets: [
390
+ // The @babel/preset-env preset enables Babel to transpile ES6+ code
391
+ // and the rollup requires that Babel keeps ES6 module syntax intact.
392
+ ['@babel/preset-env', {
393
+ modules: false
394
+ }]],
395
+ plugins: ['@babel/plugin-transform-runtime']
396
+ };
397
+ if (options.debug === true) {
398
+ console.debug('[DEBUG] The @rollup/plugin-babel plugin options are:');
399
+ console.dir(pluginOptions, {
400
+ depth: null
401
+ });
402
+ }
403
+ plugins.push(babel(pluginOptions));
404
+ }
405
+ return plugins;
406
+ }
407
+
408
+ ////////////////////////////////////////////////////////////////////////////////
409
+ //
410
+ // Copyright (c) 2022 - 2023.
411
+ // Haixing Hu, Qubit Co. Ltd.
412
+ //
413
+ // All rights reserved.
414
+ //
415
+ ////////////////////////////////////////////////////////////////////////////////
416
+
417
+ /**
418
+ * Configures the `@rollup/plugin-terser` plugin.
419
+ *
420
+ * @param {string} format
421
+ * The format of the library.
422
+ * @param {string} importMetaUrl
423
+ * The URL of the `import.meta` of the caller module.
424
+ * @param {object} options
425
+ * The additional options for building the library.
426
+ * @param {Array} plugins
427
+ * The array of Rollup plugins.
428
+ * @returns {Array<Object>}
429
+ * The modified Rollup plugins array.
430
+ * @author Haixing Hu
431
+ * @see https://www.npmjs.com/package/@rollup/plugin-terser
432
+ */
433
+ function configTerserPlugin(format, importMetaUrl, options, plugins) {
434
+ var _options$nodeEnv, _options$minify;
435
+ var nodeEnv = (_options$nodeEnv = options.nodeEnv) !== null && _options$nodeEnv !== void 0 ? _options$nodeEnv : process.env.NODE_ENV;
436
+ var minify = (_options$minify = options.minify) !== null && _options$minify !== void 0 ? _options$minify : nodeEnv === 'production';
437
+ if (minify) {
438
+ var _options$terserPlugin;
439
+ // The @rollup/plugin-terser uses terser under the hood to minify the code.
440
+ var pluginOptions = (_options$terserPlugin = options.terserPluginOptions) !== null && _options$terserPlugin !== void 0 ? _options$terserPlugin : {
441
+ output: {
442
+ comments: false // default to remove all comments
443
+ },
444
+ keep_classnames: true,
445
+ // keep the class names
446
+ keep_fnames: true // keep the function names
447
+ };
448
+ if (options.debug === true) {
449
+ console.debug('[DEBUG] The @rollup/plugin-terser plugin options are:');
450
+ console.dir(pluginOptions, {
451
+ depth: null
452
+ });
453
+ }
454
+ plugins.push(terser(pluginOptions));
455
+ }
456
+ return plugins;
457
+ }
458
+
459
+ ////////////////////////////////////////////////////////////////////////////////
460
+ //
461
+ // Copyright (c) 2022 - 2023.
462
+ // Haixing Hu, Qubit Co. Ltd.
463
+ //
464
+ // All rights reserved.
465
+ //
466
+ ////////////////////////////////////////////////////////////////////////////////
467
+
468
+ /**
469
+ * Configures the `rollup-plugin-analyzer` plugin.
470
+ *
471
+ * @param {string} format
472
+ * The format of the library.
473
+ * @param {string} importMetaUrl
474
+ * The URL of the `import.meta` of the caller module.
475
+ * @param {object} options
476
+ * The additional options for building the library.
477
+ * @param {Array} plugins
478
+ * The array of Rollup plugins.
479
+ * @returns {Array<Object>}
480
+ * The modified Rollup plugins array.
481
+ * @author Haixing Hu
482
+ * @see https://www.npmjs.com/package/rollup-plugin-analyzer
483
+ */
484
+ function configAnalyzerPlugin(format, importMetaUrl, options, plugins) {
485
+ var _options$useAnalyzerP;
486
+ if ((_options$useAnalyzerP = options.useAnalyzerPlugin) !== null && _options$useAnalyzerP !== void 0 ? _options$useAnalyzerP : true) {
487
+ var _options$analyzerPlug;
488
+ // The rollup-plugin-analyzer will print out some useful info about our
489
+ // generated bundle upon successful builds.
490
+ var pluginOptions = (_options$analyzerPlug = options.analyzerPluginOptions) !== null && _options$analyzerPlug !== void 0 ? _options$analyzerPlug : {
491
+ hideDeps: true,
492
+ limit: 0,
493
+ summaryOnly: true
494
+ };
495
+ if (options.debug === true) {
496
+ console.debug('[DEBUG] The rollup-plugin-analyzer plugin options are:');
497
+ console.dir(pluginOptions, {
498
+ depth: null
499
+ });
500
+ }
501
+ plugins.push(analyzer(pluginOptions));
502
+ }
503
+ return plugins;
504
+ }
505
+
506
+ ////////////////////////////////////////////////////////////////////////////////
507
+ //
508
+ // Copyright (c) 2022 - 2023.
509
+ // Haixing Hu, Qubit Co. Ltd.
510
+ //
511
+ // All rights reserved.
512
+ //
513
+ ////////////////////////////////////////////////////////////////////////////////
514
+
515
+ /**
516
+ * Configures the `rollup-plugin-visualizer` plugin.
517
+ *
518
+ * The `rollup-plugin-visualizer` will visualize and analyze your Rollup
519
+ * bundle to see which modules are taking up space.
520
+ *
521
+ * @param {string} format
522
+ * The format of the library.
523
+ * @param {string} importMetaUrl
524
+ * The URL of the `import.meta` of the caller module.
525
+ * @param {object} options
526
+ * The additional options for building the library.
527
+ * @param {Array} plugins
528
+ * The array of Rollup plugins.
529
+ * @returns {Array<Object>}
530
+ * The modified Rollup plugins array.
531
+ * @author Haixing Hu
532
+ * @see https://www.npmjs.com/package/rollup-plugin-visualizer
533
+ */
534
+ function configVisualizerPlugin(format, importMetaUrl, options, plugins) {
535
+ var _options$useVisualize;
536
+ if ((_options$useVisualize = options.useVisualizerPlugin) !== null && _options$useVisualize !== void 0 ? _options$useVisualize : true) {
537
+ var _options$visualizerPl;
538
+ // The rollup-plugin-visualizer will visualize and analyze your Rollup
539
+ // bundle to see which modules are taking up space.
540
+ var pluginOptions = (_options$visualizerPl = options.visualizerPluginOptions) !== null && _options$visualizerPl !== void 0 ? _options$visualizerPl : {
541
+ filename: "./doc/".concat(options.filenameBase, ".visualization.html"),
542
+ gzipSize: true,
543
+ brotliSize: true
544
+ };
545
+ if (options.debug === true) {
546
+ console.debug('[DEBUG] The rollup-plugin-visualizer plugin options are:');
547
+ console.dir(pluginOptions, {
548
+ depth: null
549
+ });
550
+ }
551
+ plugins.push(rollupPluginVisualizer.visualizer(pluginOptions));
552
+ }
553
+ return plugins;
554
+ }
555
+
556
+ /**
557
+ * Gets Rollup `plugins` configuration.
558
+ *
559
+ * @param {string} format
560
+ * The format of the library.
561
+ * @param {string} importMetaUrl
562
+ * The URL of the `import.meta` of the caller module.
563
+ * @param {object} options
564
+ * The additional options for building the library.
565
+ * @returns {Array<Object>}
566
+ * The Rollup plugins array.
567
+ * @author Haixing Hu
568
+ */
569
+ function getRollupPlugins(format, importMetaUrl, options) {
570
+ var plugins = [];
571
+ plugins.push(json());
572
+ configAliasPlugin(format, importMetaUrl, options, plugins);
573
+ configNodeResolvePlugin(format, importMetaUrl, options, plugins);
574
+ configCommonJsPlugin(format, importMetaUrl, options, plugins);
575
+ configBabelPlugin(format, importMetaUrl, options, plugins);
576
+ configTerserPlugin(format, importMetaUrl, options, plugins);
577
+ configAnalyzerPlugin(format, importMetaUrl, options, plugins);
578
+ configVisualizerPlugin(format, importMetaUrl, options, plugins);
579
+ // The user can specify additional plugins.
580
+ if (options.plugins) {
581
+ plugins.push.apply(plugins, _toConsumableArray(options.plugins));
582
+ }
583
+ return plugins;
584
+ }
585
+
586
+ ////////////////////////////////////////////////////////////////////////////////
587
+ //
588
+ // Copyright (c) 2022 - 2024.
589
+ // Haixing Hu, Qubit Co. Ltd.
590
+ //
591
+ // All rights reserved.
592
+ //
593
+ ////////////////////////////////////////////////////////////////////////////////
594
+
595
+ function getRollupOnWarn() {
596
+ return function onWarn(warning, warn) {
597
+ // skip certain warnings
598
+ if (warning.code === 'INVALID_ANNOTATION' && warning.message.includes('#__PURE__') && warning.message.includes('terser')) {
599
+ return;
600
+ }
601
+ if (warning.code === 'CIRCULAR_DEPENDENCY' && warning.message.includes('node_modules')) {
602
+ return;
603
+ }
604
+ // Use default for everything else
605
+ warn(warning);
606
+ };
607
+ }
608
+
609
+ function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
610
+ function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
611
+ function _createForOfIteratorHelper(r, e) { var t = "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (!t) { if (Array.isArray(r) || (t = _unsupportedIterableToArray(r)) || e) { t && (r = t); var _n = 0, F = function F() {}; return { s: F, n: function n() { return _n >= r.length ? { done: !0 } : { done: !1, value: r[_n++] }; }, e: function e(r) { throw r; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var o, a = !0, u = !1; return { s: function s() { t = t.call(r); }, n: function n() { var r = t.next(); return a = r.done, r; }, e: function e(r) { u = !0, o = r; }, f: function f() { try { a || null == t["return"] || t["return"](); } finally { if (u) throw o; } } }; }
612
+ function _unsupportedIterableToArray(r, a) { if (r) { if ("string" == typeof r) return _arrayLikeToArray(r, a); var t = {}.toString.call(r).slice(8, -1); return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray(r, a) : void 0; } }
613
+ function _arrayLikeToArray(r, a) { (null == a || a > r.length) && (a = r.length); for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e]; return n; }
614
+
615
+ /**
616
+ * Builds the Rollup configuration for a library.
617
+ *
618
+ * The function could be provided with an additional options for building the
619
+ * library. It can have the following fields:
620
+ *
621
+ * - `debug: boolean`: whether to print the debug information. If this field is
622
+ * not specified, the default value is `false`.
623
+ * - `formats: [string]`: the array of formats of the library. It can be an
624
+ * array of the following values:
625
+ * - `'cjs'`: the CommonJS format.
626
+ * - `'umd'`: the UMD format.
627
+ * - `'esm'`: the ES module format.
628
+ *
629
+ * If this field is not specified, the default value is `['cjs', 'esm']`.
630
+ * - `exports: string`: the export mode to use. It can be one of the following
631
+ * values:
632
+ * - `'auto'`: automatically guesses your intentions based on what the input
633
+ * module exports.
634
+ * - `'default'`: if you are only exporting one thing using `export default ...`;
635
+ * note that this can cause issues when generating CommonJS output that is
636
+ * meant to be interchangeable with ESM output.
637
+ * - `'named'`: if you are using named exports.
638
+ * - `'none'`: if you are not exporting anything (e.g. you are building an
639
+ * app, not a library)
640
+ * - `'mixed'`: if you are using named exports mixed with a default export.
641
+ * Note that this is not a standard exports mode officially supported by
642
+ * the `rollup`, instead, it is an additional mode add by this library.
643
+ *
644
+ * See [output.exports](https://rollupjs.org/configuration-options/#output-exports)
645
+ * for more details. If this field is not specified, the default value is
646
+ * `'auto'`.
647
+ * - `nodeEnv: string`: the value of the `NODE_ENV` environment variable. If
648
+ * this field is not specified, the default value is `process.env.NODE_ENV`.
649
+ * - `minify: boolean`: whether to minify the code. If this field is not
650
+ * specified, and the `nodeEnv` is `production`, the default value is `true`;
651
+ * otherwise the default value is `false`.
652
+ * - `sourcemap: boolean`: whether to generate the source map. If this field is
653
+ * not specified, the default value is `true`.
654
+ * - `input: string`: the input file of the library. If this field is not
655
+ * specified, the default value is `src/index.js`.
656
+ * - `outputDir: string`: the output directory of the library. If this field is
657
+ * not specified, the default value is `dist`.
658
+ * - `filenamePrefix: string`: the prefix of the output filename. If this field
659
+ * is not specified, the default value is the dash case of the library name.
660
+ * For example, if the library name is `MyLibrary`, the default value of this
661
+ * field is `my-library`.
662
+ * - `externals: [string]`: the array of additional external packages, each can
663
+ * be specified with either a string or a regular expression. If this field is
664
+ * not specified, the default value is an empty array.
665
+ * - `useAliasPlugin: boolean`: whether to use the `@rollup/plugin-alias` plugin.
666
+ * If this field is not specified, the default value is `true`.
667
+ * - `aliasPluginOptions: object`: the options for the `@rollup/plugin-alias`
668
+ * plugin. If this field is not specified, the default value is:
669
+ * ```js
670
+ * {
671
+ * entries: {
672
+ * 'src': fileURLToPath(new URL('src', importMetaUrl)),
673
+ * },
674
+ * }
675
+ * ```
676
+ * - `useNodeResolvePlugin: boolean`: whether to use the `@rollup/plugin-node-resolve`
677
+ * plugin. If this field is not specified, the default value is `true`.
678
+ * - `nodeResolvePluginOptions: object`: the options for the `@rollup/plugin-node-resolve`
679
+ * plugin. If this field is not specified, the default value is: `{}`.
680
+ * - `useCommonjsPlugin: boolean`: whether to use the `@rollup/plugin-commonjs`
681
+ * plugin. If this field is not specified, the default value is `true`.
682
+ * - `commonjsPluginOptions: object`: the options for the `@rollup/plugin-commonjs`
683
+ * plugin. If this field is not specified, the default value is:
684
+ * ```js
685
+ * {
686
+ * include: ['node_modules/**'],
687
+ * }
688
+ * ```
689
+ * - `useBabelPlugin: boolean`: whether to use the `@rollup/plugin-babel` plugin.
690
+ * If this field is not specified, the default value is `true`.
691
+ * - `babelPluginOptions: object`: the options for the `@rollup/plugin-babel`
692
+ * plugin. If this field is not specified, the default value is:
693
+ * ```js
694
+ * {
695
+ * babelHelpers: 'runtime',
696
+ * exclude: ['node_modules/**'],
697
+ * presets: [
698
+ * '@babel/preset-env',
699
+ * ],
700
+ * plugins: [
701
+ * '@babel/plugin-transform-runtime',
702
+ * ],
703
+ * }
704
+ * ```
705
+ * Note that when using the `@rollup/plugin-babel` plugin, you can also specify
706
+ * the configuration of Babel in the standard Babel configuration files,
707
+ * such as `babel.config.js`, `.babelrc`, etc.
708
+ * - `terserOptions: object`: the options for the `@rollup/plugin-terser` plugin.
709
+ * If this field is not specified, the default value is: `{}`. Whether to use
710
+ * the `@rollup/plugin-terser` plugin depends on the `minify` field of the
711
+ * options or the `NODE_ENV` environment variable.
712
+ * - `useAnalyzerPlugin: boolean`: whether to use the `rollup-plugin-analyzer`
713
+ * plugin. If this field is not specified, the default value is `true`.
714
+ * - `analyzerOptions: object`: the options for the `rollup-plugin-analyzer`
715
+ * plugin. If this field is not specified, the default value is:
716
+ * ```js
717
+ * {
718
+ * hideDeps: true,
719
+ * limit: 0,
720
+ * summaryOnly: true,
721
+ * }
722
+ * ```
723
+ * - `plugins: [object]`: the array of configuration of additional Rollup
724
+ * plugins. If this field is not specified, the default value is an empty
725
+ * array.
726
+ *
727
+ * @param {string} libraryName
728
+ * The name of the library, which will be used as the name of the global
729
+ * variable in the UMD format. It should in the camel case.
730
+ * @param {string} importMetaUrl
731
+ * The URL of the `import.meta` of the caller module. It **MUST** be passed
732
+ * with the `import.meta.url` of the caller module.
733
+ * @param {object} options
734
+ * The additional options for building the library, as described above.
735
+ * @returns {Array<object>}
736
+ * the array of Rollup configurations for the library.
737
+ */
738
+ function rollupBuilder(libraryName, importMetaUrl) {
739
+ var _options$formats, _options$input;
740
+ var options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
741
+ var formats = (_options$formats = options.formats) !== null && _options$formats !== void 0 ? _options$formats : ['cjs', 'esm'];
742
+ var result = [];
743
+ var input = (_options$input = options.input) !== null && _options$input !== void 0 ? _options$input : 'src/index.js';
744
+ var _iterator = _createForOfIteratorHelper(formats),
745
+ _step;
746
+ try {
747
+ for (_iterator.s(); !(_step = _iterator.n()).done;) {
748
+ var format = _step.value;
749
+ var clonedOptions = _objectSpread({}, options);
750
+ var output = getRollupOutput(format, libraryName, clonedOptions);
751
+ var external = getRollupExternal(importMetaUrl, clonedOptions);
752
+ var plugins = getRollupPlugins(format, importMetaUrl, clonedOptions);
753
+ var onwarn = getRollupOnWarn();
754
+ var config = {
755
+ input: input,
756
+ output: output,
757
+ external: external,
758
+ plugins: plugins,
759
+ onwarn: onwarn
760
+ };
761
+ result.push(config);
762
+ if (options.debug === true) {
763
+ console.debug("[DEBUG] The options for the format ".concat(format, " is:"));
764
+ console.dir(clonedOptions, {
765
+ depth: null
766
+ });
767
+ }
768
+ }
769
+ } catch (err) {
770
+ _iterator.e(err);
771
+ } finally {
772
+ _iterator.f();
773
+ }
774
+ if (options.debug === true) {
775
+ console.debug('[DEBUG] The generated rollup configurations are:');
776
+ console.dir(result, {
777
+ depth: null
778
+ });
779
+ }
780
+ return result;
781
+ }
782
+
783
+ ////////////////////////////////////////////////////////////////////////////////
784
+ //
785
+ // Copyright (c) 2022 - 2023.
786
+ // Haixing Hu, Qubit Co. Ltd.
787
+ //
788
+ // All rights reserved.
789
+ //
790
+ ////////////////////////////////////////////////////////////////////////////////
791
+
792
+ module.exports = rollupBuilder;
793
+ //# sourceMappingURL=rollup-builder.cjs.map