vis-dev-utils 4.0.45 → 5.0.1

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 (92) hide show
  1. package/babel-preset/index.cjs +102 -0
  2. package/babel-preset/index.cjs.map +1 -0
  3. package/babel-preset/{index.js → index.mjs} +58 -31
  4. package/babel-preset/index.mjs.map +1 -0
  5. package/bin/ci-utils.js +35 -41
  6. package/bin/ci-utils.js.map +1 -1
  7. package/bin/generate-examples-index.js +779 -1265
  8. package/bin/generate-examples-index.js.map +1 -1
  9. package/bin/test-e2e-interop.js +431 -3492
  10. package/bin/test-e2e-interop.js.map +1 -1
  11. package/declarations/babel-preset/index.d.ts +23 -0
  12. package/declarations/babel-preset/index.d.ts.map +1 -0
  13. package/declarations/ci-utils/index.d.ts +2 -0
  14. package/declarations/ci-utils/index.d.ts.map +1 -0
  15. package/declarations/generate-examples-index/cli.d.ts +44 -0
  16. package/declarations/generate-examples-index/cli.d.ts.map +1 -0
  17. package/declarations/generate-examples-index/content-builder/builder.d.ts +53 -0
  18. package/declarations/generate-examples-index/content-builder/builder.d.ts.map +1 -0
  19. package/declarations/generate-examples-index/content-builder/common.d.ts +47 -0
  20. package/declarations/generate-examples-index/content-builder/common.d.ts.map +1 -0
  21. package/declarations/generate-examples-index/content-builder/format.d.ts +5 -0
  22. package/declarations/generate-examples-index/content-builder/format.d.ts.map +1 -0
  23. package/declarations/generate-examples-index/content-builder/html/index.d.ts +3 -0
  24. package/declarations/generate-examples-index/content-builder/html/index.d.ts.map +1 -0
  25. package/declarations/generate-examples-index/content-builder/index.d.ts +6 -0
  26. package/declarations/generate-examples-index/content-builder/index.d.ts.map +1 -0
  27. package/declarations/generate-examples-index/content-builder/md/index.d.ts +3 -0
  28. package/declarations/generate-examples-index/content-builder/md/index.d.ts.map +1 -0
  29. package/declarations/generate-examples-index/content-builder/playground/codepen.d.ts +6 -0
  30. package/declarations/generate-examples-index/content-builder/playground/codepen.d.ts.map +1 -0
  31. package/declarations/generate-examples-index/content-builder/playground/data.d.ts +8 -0
  32. package/declarations/generate-examples-index/content-builder/playground/data.d.ts.map +1 -0
  33. package/declarations/generate-examples-index/content-builder/playground/index.d.ts +4 -0
  34. package/declarations/generate-examples-index/content-builder/playground/index.d.ts.map +1 -0
  35. package/declarations/generate-examples-index/content-builder/playground/jsfiddle.d.ts +6 -0
  36. package/declarations/generate-examples-index/content-builder/playground/jsfiddle.d.ts.map +1 -0
  37. package/declarations/generate-examples-index/content-builder/screenshots/index.d.ts +26 -0
  38. package/declarations/generate-examples-index/content-builder/screenshots/index.d.ts.map +1 -0
  39. package/declarations/generate-examples-index/index.d.ts +2 -0
  40. package/declarations/generate-examples-index/index.d.ts.map +1 -0
  41. package/declarations/generate-examples-index/paths.d.ts +16 -0
  42. package/declarations/generate-examples-index/paths.d.ts.map +1 -0
  43. package/declarations/generate-examples-index/types.d.ts +61 -0
  44. package/declarations/generate-examples-index/types.d.ts.map +1 -0
  45. package/declarations/module/constants.d.ts +2 -0
  46. package/declarations/module/constants.d.ts.map +1 -0
  47. package/declarations/{generate-rollup-configuration → module/generate-rollup-configuration}/index.d.ts +4 -3
  48. package/declarations/module/generate-rollup-configuration/index.d.ts.map +1 -0
  49. package/declarations/{header.d.ts → module/header.d.ts} +1 -3
  50. package/declarations/module/header.d.ts.map +1 -0
  51. package/declarations/module/index.d.ts.map +1 -0
  52. package/declarations/module/inspect-npm-pack.d.ts +8 -0
  53. package/declarations/module/inspect-npm-pack.d.ts.map +1 -0
  54. package/declarations/module/util.d.ts.map +1 -0
  55. package/declarations/test-e2e-interop/cli.d.ts +18 -0
  56. package/declarations/test-e2e-interop/cli.d.ts.map +1 -0
  57. package/declarations/test-e2e-interop/index.d.ts +2 -0
  58. package/declarations/test-e2e-interop/index.d.ts.map +1 -0
  59. package/declarations/test-e2e-interop/test.d.ts +23 -0
  60. package/declarations/test-e2e-interop/test.d.ts.map +1 -0
  61. package/declarations/test-e2e-interop/util.d.ts +49 -0
  62. package/declarations/test-e2e-interop/util.d.ts.map +1 -0
  63. package/dist/vis-dev-utils.cjs +871 -0
  64. package/dist/vis-dev-utils.cjs.map +1 -0
  65. package/dist/vis-dev-utils.mjs +864 -0
  66. package/dist/vis-dev-utils.mjs.map +1 -0
  67. package/package.json +85 -63
  68. package/babel-register/index.js +0 -110
  69. package/babel-register/index.js.map +0 -1
  70. package/declarations/constants.d.ts +0 -2
  71. package/declarations/constants.d.ts.map +0 -1
  72. package/declarations/generate-rollup-configuration/index.d.ts.map +0 -1
  73. package/declarations/header.d.ts.map +0 -1
  74. package/declarations/index.d.ts.map +0 -1
  75. package/declarations/inspect-npm-pack.d.ts +0 -8
  76. package/declarations/inspect-npm-pack.d.ts.map +0 -1
  77. package/declarations/util.d.ts.map +0 -1
  78. package/dist/vis-dev-utils.cjs.js +0 -777
  79. package/dist/vis-dev-utils.cjs.js.map +0 -1
  80. package/dist/vis-dev-utils.esm.js +0 -771
  81. package/dist/vis-dev-utils.esm.js.map +0 -1
  82. package/lib/header.d.ts +0 -38
  83. package/lib/header.d.ts.map +0 -1
  84. package/lib/header.js +0 -85
  85. package/lib/header.js.map +0 -1
  86. package/lib/inspect-npm-pack.d.ts +0 -8
  87. package/lib/inspect-npm-pack.d.ts.map +0 -1
  88. package/lib/inspect-npm-pack.js +0 -74
  89. package/lib/inspect-npm-pack.js.map +0 -1
  90. /package/declarations/{index.d.ts → module/index.d.ts} +0 -0
  91. /package/declarations/{util.d.ts → module/util.d.ts} +0 -0
  92. /package/eslint-shareable-config/{index.js → index.cjs} +0 -0
@@ -0,0 +1,864 @@
1
+ /**
2
+ * vis-dev-utils
3
+ * http://visjs.org/
4
+ *
5
+ * Development utilities for the Vis family projects.
6
+ *
7
+ * @version 5.0.1
8
+ * @date 2025-07-13T10:18:37.410Z
9
+ *
10
+ * @copyright (c) 2011-2017 Almende B.V, http://almende.com
11
+ * @copyright (c) 2017-2019 visjs contributors, https://github.com/visjs
12
+ *
13
+ * @license
14
+ * vis.js is dual licensed under both
15
+ *
16
+ * 1. The Apache 2.0 License
17
+ * http://www.apache.org/licenses/LICENSE-2.0
18
+ *
19
+ * and
20
+ *
21
+ * 2. The MIT License
22
+ * http://opensource.org/licenses/MIT
23
+ *
24
+ * vis.js may be distributed under either license.
25
+ */
26
+
27
+ import fs, { readFile } from 'node:fs/promises';
28
+ import { fileURLToPath, URL } from 'node:url';
29
+ import analyzerPlugin from 'rollup-plugin-analyzer';
30
+ import babelPlugin from '@rollup/plugin-babel';
31
+ import commonjsPlugin from '@rollup/plugin-commonjs';
32
+ import copyPlugin from 'rollup-plugin-copy';
33
+ import jsonPlugin from '@rollup/plugin-json';
34
+ import nodeResolvePlugin from '@rollup/plugin-node-resolve';
35
+ import postcssAssetsPlugin from 'postcss-assets';
36
+ import postcssPlugin from 'rollup-plugin-postcss';
37
+ import stripCodePlugin from 'rollup-plugin-strip-code';
38
+ import terserPlugin from '@rollup/plugin-terser';
39
+ import typescriptPlugin from '@rollup/plugin-typescript';
40
+ import { resolve, sep, join, dirname } from 'node:path';
41
+ import { string } from 'rollup-plugin-string';
42
+ import { config, expect } from 'chai';
43
+ import { execSync } from 'node:child_process';
44
+ import { readFileSync } from 'node:fs';
45
+ import { setGracefulCleanup, fileSync } from 'tmp-promise';
46
+
47
+ const BABEL_IGNORE_RE = /[\\/]node_modules[\\/](?!.*[\\/]esnext[\\/])/;
48
+
49
+ function textToComment(string) {
50
+ if (string.includes("*/")) {
51
+ throw new Error(
52
+ "Don't include comments in the input string. It will be converted automatically."
53
+ );
54
+ }
55
+ return "/**\n" + string.replace(/^[\n\r]*/, "").replace(/[\n\r\s]*$/, "").split("\n").map((line) => " * " + line).map((line) => line.replace(/[^\S\r\n]*$/, "")).join("\n") + "\n */\n";
56
+ }
57
+ const buildHeader = ({
58
+ customText,
59
+ date,
60
+ description,
61
+ homepage,
62
+ name,
63
+ version
64
+ }) => textToComment(`
65
+ ${name}
66
+ ${homepage}
67
+
68
+ ${description}
69
+
70
+ @version ${version}
71
+ @date ${date}
72
+
73
+ @copyright (c) 2011-2017 Almende B.V, http://almende.com
74
+ @copyright (c) 2017-2019 visjs contributors, https://github.com/visjs
75
+
76
+ @license
77
+ vis.js is dual licensed under both
78
+
79
+ 1. The Apache 2.0 License
80
+ http://www.apache.org/licenses/LICENSE-2.0
81
+
82
+ and
83
+
84
+ 2. The MIT License
85
+ http://opensource.org/licenses/MIT
86
+
87
+ vis.js may be distributed under either license.
88
+
89
+ ${customText}
90
+ `);
91
+ const defaultDate = (/* @__PURE__ */ new Date()).toISOString();
92
+ async function generateHeader(options) {
93
+ const packageJSON = JSON.parse(
94
+ await readFile(
95
+ (await import('find-up')).findUpSync("package.json"),
96
+ "utf8"
97
+ )
98
+ );
99
+ const defaultDescription = packageJSON.description;
100
+ const defaultHomepage = packageJSON.homepage;
101
+ const defaultName = packageJSON.name;
102
+ const defaultVersion = packageJSON.version;
103
+ const {
104
+ customText = "",
105
+ date = defaultDate,
106
+ description = defaultDescription,
107
+ homepage = defaultHomepage,
108
+ name = defaultName,
109
+ version = defaultVersion
110
+ } = options || {};
111
+ return buildHeader({
112
+ customText,
113
+ date,
114
+ description,
115
+ homepage,
116
+ name,
117
+ version
118
+ });
119
+ }
120
+
121
+ const rawGlobby = import('globby');
122
+ config.truncateThreshold = Number.MAX_SAFE_INTEGER;
123
+ const VIS_DEBUG = ["1", "true", "y", "yes"].includes(
124
+ process.env["VIS_DEBUG"] || "false"
125
+ );
126
+ const VIS_TEST = ["1", "true", "y", "yes"].includes(
127
+ process.env["VIS_TEST"] || "false"
128
+ );
129
+ async function glob(pattern) {
130
+ return (await rawGlobby).globby(
131
+ sep === "\\" ? pattern.replace(/\\/g, "/") : pattern
132
+ );
133
+ }
134
+ const dependenciesWithVisExportStructure = [
135
+ "vis-data",
136
+ "vis-graph3d",
137
+ "vis-network",
138
+ "vis-timeline",
139
+ "vis-util",
140
+ "vis-uuid"
141
+ ];
142
+ function processDependencies(deps) {
143
+ const depNames = Array.isArray(deps) ? deps : Object.keys(deps);
144
+ return depNames.flatMap(
145
+ (key) => dependenciesWithVisExportStructure.includes(key) ? [key + "/esnext"] : [key]
146
+ );
147
+ }
148
+ function processGlobals(globals) {
149
+ return Object.entries(globals).reduce(
150
+ (acc, [key, value]) => {
151
+ acc[dependenciesWithVisExportStructure.includes(key) ? key + "/esnext" : key] = value;
152
+ return acc;
153
+ },
154
+ /* @__PURE__ */ Object.create(null)
155
+ );
156
+ }
157
+ function isTS(path) {
158
+ return path.endsWith(".ts");
159
+ }
160
+ const validate = VIS_DEBUG ? async (callback) => {
161
+ try {
162
+ await callback(expect);
163
+ } catch (error) {
164
+ console.error(error);
165
+ }
166
+ } : async (callback) => {
167
+ await callback(expect);
168
+ };
169
+ function getPaths(buildVariant, moduleFormat) {
170
+ function getPath(lib) {
171
+ return {
172
+ [`vis-${lib}/esnext`]: `vis-${lib}/${buildVariant}/${moduleFormat}/vis-${lib}.js`
173
+ };
174
+ }
175
+ return {
176
+ ...getPath("charts"),
177
+ ...getPath("data"),
178
+ ...getPath("graph3d"),
179
+ ...getPath("network"),
180
+ ...getPath("timeline"),
181
+ ...getPath("util"),
182
+ ...getPath("uuid")
183
+ };
184
+ }
185
+ function scopeCopyTarget(...dirs) {
186
+ return function(target) {
187
+ const dest = Array.isArray(target.dest) ? target.dest : [target.dest];
188
+ const bundleDest = dest.flatMap(
189
+ (path) => dirs.map((dir) => join(dir, path))
190
+ );
191
+ return {
192
+ ...target,
193
+ dest: bundleDest
194
+ };
195
+ };
196
+ }
197
+ const injectCSS = true;
198
+ const minimize = true;
199
+ const transpile = true;
200
+ const generateRollupPluginArray = (libraryFilename, assets, copyTargetsBundle, copyTargetsVariant, tsconfig, mode, bundleType, {
201
+ injectCSS: injectCSS2 = false,
202
+ minimize: minimize2 = false,
203
+ strip = mode === "production",
204
+ transpile: transpile2 = false,
205
+ typescript = false
206
+ } = {}) => {
207
+ const fullLibraryFilename = `${libraryFilename}${minimize2 ? ".min" : ""}`;
208
+ const bundleDir = bundleType;
209
+ const bundleVariantDirs = ["esm", "umd"].map(
210
+ (variant) => join(bundleDir, variant)
211
+ );
212
+ return [
213
+ ...strip ? [
214
+ // This should be first because it removes code from source files.
215
+ // It's much easier to follow if the removal happens before any
216
+ // transformations.
217
+ stripCodePlugin({
218
+ start_comment: "develblock:start",
219
+ end_comment: "develblock:end"
220
+ })
221
+ ] : [
222
+ // Remove the comments marking devel blocks as they can cause problems
223
+ // later on because transpilation shuffles things around which may
224
+ // lead to all kinds of issues including syntax errors.
225
+ stripCodePlugin({
226
+ pattern: /[\t ]*\/\* ?develblock:(start|end) ?\*\//g
227
+ })
228
+ ],
229
+ analyzerPlugin(VIS_DEBUG ? void 0 : { limit: 10, summaryOnly: true }),
230
+ copyPlugin({
231
+ verbose: VIS_DEBUG,
232
+ targets: [
233
+ // JavaScript
234
+ {
235
+ src: resolve(
236
+ dirname(fileURLToPath(new URL(import.meta.url))),
237
+ "assets/bundle-root.js"
238
+ ),
239
+ dest: bundleDir,
240
+ rename: "index.js"
241
+ },
242
+ {
243
+ src: resolve(
244
+ dirname(fileURLToPath(new URL(import.meta.url))),
245
+ "assets/bundle-index.js"
246
+ ),
247
+ dest: bundleVariantDirs,
248
+ rename: "index.js",
249
+ transform: (content) => content.toString().replace("{{filename}}", libraryFilename)
250
+ },
251
+ // TypeScript
252
+ {
253
+ src: resolve(
254
+ dirname(fileURLToPath(new URL(import.meta.url))),
255
+ "assets/bundle-root.d.ts"
256
+ ),
257
+ dest: bundleDir,
258
+ rename: "index.d.ts"
259
+ },
260
+ {
261
+ src: resolve(
262
+ dirname(fileURLToPath(new URL(import.meta.url))),
263
+ "assets/bundle-index.d.ts"
264
+ ),
265
+ dest: bundleVariantDirs,
266
+ rename: "index.d.ts",
267
+ transform: (content) => content.toString().replace("{{filename}}", libraryFilename)
268
+ },
269
+ {
270
+ src: resolve(
271
+ dirname(fileURLToPath(new URL(import.meta.url))),
272
+ "assets/bundle-file.d.ts"
273
+ ),
274
+ dest: bundleVariantDirs,
275
+ rename: `${fullLibraryFilename}.d.ts`,
276
+ transform: (content) => content.toString().replace("{{bundle-type}}", bundleType)
277
+ },
278
+ // Custom
279
+ ...copyTargetsBundle.map(scopeCopyTarget(bundleDir)),
280
+ ...copyTargetsVariant.map(scopeCopyTarget(...bundleVariantDirs))
281
+ ]
282
+ }),
283
+ nodeResolvePlugin({
284
+ browser: true,
285
+ extensions: [".js", ".json", ".ts"],
286
+ mainFields: ["jsnext", "module", "main"],
287
+ preferBuiltins: false
288
+ }),
289
+ ...typescript ? [
290
+ typescriptPlugin({
291
+ tsconfig
292
+ })
293
+ ] : [],
294
+ commonjsPlugin(),
295
+ postcssPlugin({
296
+ extract: !injectCSS2 && `styles/${fullLibraryFilename}.css`,
297
+ inject: injectCSS2,
298
+ minimize: minimize2,
299
+ // Prevent the sourcemaps from being injected into JS files.
300
+ sourceMap: !injectCSS2,
301
+ plugins: [
302
+ postcssAssetsPlugin({
303
+ loadPaths: [assets]
304
+ })
305
+ ]
306
+ }),
307
+ jsonPlugin(),
308
+ string({
309
+ include: "**/*.txt"
310
+ }),
311
+ ...transpile2 ? [
312
+ babelPlugin({
313
+ babelHelpers: "runtime",
314
+ babelrc: false,
315
+ configFile: false,
316
+ exclude: BABEL_IGNORE_RE,
317
+ extensions: [".js", ".ts"],
318
+ presets: [["vis-dev-utils/babel-preset", { ts: true }]]
319
+ })
320
+ ] : [],
321
+ ...minimize2 ? [
322
+ terserPlugin({
323
+ format: {
324
+ comments: "some"
325
+ }
326
+ })
327
+ ] : []
328
+ ];
329
+ };
330
+ async function generateRollupConfiguration(options, mode = VIS_TEST ? "test" : VIS_DEBUG ? "development" : "production") {
331
+ const {
332
+ assets = ".",
333
+ copyTargets: {
334
+ bundle: copyTargetsBundle = [],
335
+ variant: copyTargetsVariant = []
336
+ } = {},
337
+ externalForPeerBuild = [],
338
+ globals = {},
339
+ header = { name: "Unknown Library" },
340
+ libraryFilename = "unknown-library",
341
+ packageJSON: {
342
+ dependencies = {},
343
+ devDependencies = {},
344
+ peerDependencies = {},
345
+ ...packageJSONRest
346
+ } = {},
347
+ entryPoints: entryPoint = "./src",
348
+ tsconfig = "tsconfig.json"
349
+ } = options || {};
350
+ validate((expect) => {
351
+ if (Object.keys(peerDependencies).length > 0) {
352
+ expect(
353
+ Object.keys(dependencies),
354
+ "The dependencies and peer dependencies have to be disjoint sets"
355
+ ).to.be.an("array").that.does.not.include.any.members(Object.keys(peerDependencies));
356
+ }
357
+ });
358
+ validate((expect) => {
359
+ expect(
360
+ Object.keys(devDependencies),
361
+ "For convenience all peer dependencies also have to be dev dependencies"
362
+ ).to.be.an("array").that.includes.all.members(Object.keys(peerDependencies));
363
+ });
364
+ validate((expect) => {
365
+ expect(
366
+ Object.keys(peerDependencies),
367
+ "Peer build externals have to be a subset of peer dependencies"
368
+ ).to.be.an("array").that.includes.all.members(externalForPeerBuild);
369
+ });
370
+ validate((expect) => {
371
+ expect(
372
+ [...Object.keys(dependencies), ...Object.keys(peerDependencies)].sort(),
373
+ "Globals have to be provided for all runtime and peer dependencies but nothing else"
374
+ ).to.be.an("array").that.deep.equals(Object.keys(globals).sort());
375
+ });
376
+ validate(async (expect) => {
377
+ expect(resolve(assets), "Assets have to be a directory").to.be.a("string");
378
+ const stats = await fs.stat(resolve(assets));
379
+ expect(stats.isDirectory(), "Assets have to be a directory").to.be.true;
380
+ });
381
+ validate(async (expect) => {
382
+ expect(entryPoint, "The entry point has to be directory").to.be.a("string");
383
+ const stats = await fs.stat(entryPoint);
384
+ expect(stats.isDirectory(), "The entry point has to be directory").to.be.true;
385
+ });
386
+ const [esnextEntry, peerEntry, standaloneEntry] = await Promise.all(
387
+ ["ESNext", "peer", "standalone"].map(async (name) => {
388
+ const filenameGlob = `entry-${name.toLowerCase()}.{js,ts}`;
389
+ const files = await glob(resolve(entryPoint, filenameGlob));
390
+ validate(async (expect) => {
391
+ expect(
392
+ files,
393
+ `There has to be a single entry file (${filenameGlob}) for the ${name} build`
394
+ ).to.have.lengthOf(1).and.to.have.ownProperty("0");
395
+ const stats = await fs.stat(resolve(files[0]));
396
+ expect(
397
+ stats.isFile(),
398
+ `The entry file (${filenameGlob}) for the ${name} build has to be a file`
399
+ ).to.be.true;
400
+ });
401
+ return files[0];
402
+ })
403
+ );
404
+ validate(async (expect) => {
405
+ expect(
406
+ resolve("./declarations"),
407
+ "There has to be a directory with TypeScript declarations"
408
+ ).to.be.a("string");
409
+ const stats = await fs.stat(resolve("./declarations"));
410
+ expect(
411
+ stats.isDirectory(),
412
+ "There has to be a directory with TypeScript declarations"
413
+ ).to.be.true;
414
+ });
415
+ validate((expect) => {
416
+ expect(
417
+ packageJSONRest,
418
+ "The directories with built files have to be included in the package"
419
+ ).to.have.ownProperty("files").that.is.an("array").and.includes.all.members([
420
+ "declarations",
421
+ "esnext",
422
+ "peer",
423
+ "standalone"
424
+ ]);
425
+ });
426
+ const expectedExports = Object.fromEntries([
427
+ [
428
+ ".",
429
+ {
430
+ import: `./peer/esm/${libraryFilename}.mjs`,
431
+ require: `./peer/umd/${libraryFilename}.cjs`,
432
+ types: "./declarations/index.d.ts"
433
+ }
434
+ ],
435
+ ["./package.json", "./package.json"],
436
+ [
437
+ "./declarations/index.d.ts",
438
+ {
439
+ types: "./declarations/index.d.ts"
440
+ }
441
+ ],
442
+ ...["standalone", "peer", "esnext"].flatMap(
443
+ (variant) => [
444
+ [
445
+ `./${variant}`,
446
+ {
447
+ import: `./${variant}/esm/${libraryFilename}.mjs`,
448
+ require: `./${variant}/umd/${libraryFilename}.cjs`,
449
+ types: "./declarations/index.d.ts"
450
+ }
451
+ ],
452
+ [
453
+ `./${variant}/esm/${libraryFilename}.js`,
454
+ {
455
+ import: `./${variant}/esm/${libraryFilename}.mjs`,
456
+ types: "./declarations/index.d.ts"
457
+ }
458
+ ],
459
+ [
460
+ `./${variant}/esm/${libraryFilename}.mjs`,
461
+ {
462
+ import: `./${variant}/esm/${libraryFilename}.mjs`,
463
+ types: "./declarations/index.d.ts"
464
+ }
465
+ ],
466
+ [
467
+ `./${variant}/esm/${libraryFilename}.min.js`,
468
+ {
469
+ import: `./${variant}/esm/${libraryFilename}.min.mjs`,
470
+ types: "./declarations/index.d.ts"
471
+ }
472
+ ],
473
+ [
474
+ `./${variant}/esm/${libraryFilename}.min.mjs`,
475
+ {
476
+ import: `./${variant}/esm/${libraryFilename}.min.mjs`,
477
+ types: "./declarations/index.d.ts"
478
+ }
479
+ ],
480
+ [
481
+ `./${variant}/umd/${libraryFilename}.js`,
482
+ {
483
+ require: `./${variant}/umd/${libraryFilename}.cjs`,
484
+ types: "./declarations/index.d.ts"
485
+ }
486
+ ],
487
+ [
488
+ `./${variant}/umd/${libraryFilename}.cjs`,
489
+ {
490
+ require: `./${variant}/umd/${libraryFilename}.cjs`,
491
+ types: "./declarations/index.d.ts"
492
+ }
493
+ ],
494
+ [
495
+ `./${variant}/umd/${libraryFilename}.min.js`,
496
+ {
497
+ require: `./${variant}/umd/${libraryFilename}.min.cjs`,
498
+ types: "./declarations/index.d.ts"
499
+ }
500
+ ],
501
+ [
502
+ `./${variant}/umd/${libraryFilename}.min.cjs`,
503
+ {
504
+ require: `./${variant}/umd/${libraryFilename}.min.cjs`,
505
+ types: "./declarations/index.d.ts"
506
+ }
507
+ ]
508
+ ]
509
+ )
510
+ ]);
511
+ validate((expect) => {
512
+ expect(
513
+ packageJSONRest,
514
+ "Package JSON's type property has to point to the declarations"
515
+ ).to.have.ownProperty("types").that.is.a("string").and.equals("./declarations/index.d.ts").and.is.oneOf(Object.keys(expectedExports));
516
+ });
517
+ validate((expect) => {
518
+ expect(
519
+ packageJSONRest,
520
+ "Package JSON's browser property has to point to the minifed UMD build"
521
+ ).to.have.ownProperty("browser").that.is.a("string").and.equals(`./peer/umd/${libraryFilename}.min.cjs`).and.is.oneOf(Object.keys(expectedExports));
522
+ });
523
+ validate((expect) => {
524
+ expect(
525
+ packageJSONRest,
526
+ "Package JSON's main property has to point to the UMD build"
527
+ ).to.have.ownProperty("main").that.is.a("string").and.equals(`./peer/umd/${libraryFilename}.cjs`).and.is.oneOf(Object.keys(expectedExports));
528
+ });
529
+ validate((expect) => {
530
+ expect(
531
+ packageJSONRest,
532
+ "Package JSON's modul property has to point to the ESM build"
533
+ ).to.have.ownProperty("module").that.is.a("string").and.equals(`./peer/esm/${libraryFilename}.mjs`).and.is.oneOf(Object.keys(expectedExports));
534
+ });
535
+ validate((expect) => {
536
+ expect(
537
+ packageJSONRest,
538
+ "Package JSON's jsnext has to point to the ESNext build"
539
+ ).to.have.ownProperty("jsnext").that.is.a("string").and.equals(`./esnext/esm/${libraryFilename}.mjs`).and.is.oneOf(Object.keys(expectedExports));
540
+ });
541
+ validate((expect) => {
542
+ expect(
543
+ Object.fromEntries(
544
+ Object.entries(packageJSONRest.exports ?? {}).filter(
545
+ ([key]) => Object.keys(expectedExports).includes(key)
546
+ )
547
+ ),
548
+ "Package JSON's exports have to contain common entries"
549
+ ).to.deep.equal(expectedExports);
550
+ });
551
+ validate(async (expect) => {
552
+ const [{ status }] = await Promise.allSettled([
553
+ fs.access(resolve("./.babelrc"))
554
+ ]);
555
+ expect(
556
+ status,
557
+ "Babelrc is ignored. Use babel.config.js config file instead."
558
+ ).to.equal("rejected");
559
+ });
560
+ validate(async (expect) => {
561
+ const [{ status }] = await Promise.allSettled([
562
+ fs.access(resolve("./babel.config.js"))
563
+ ]);
564
+ expect(status, "There has to be a babel.config.js config file.").to.equal(
565
+ "fulfilled"
566
+ );
567
+ });
568
+ const banner = await generateHeader(header);
569
+ const external = {
570
+ // No dependencies are bundled.
571
+ esnext: processDependencies([
572
+ ...Object.keys(dependencies),
573
+ ...Object.keys(peerDependencies),
574
+ // This will show a warning if any of them is used. The idea behind
575
+ // it is that if someone accidentaly imports a dev dependency they
576
+ // won't accidentaly add it to globals and Rollup will warn them
577
+ // about their error.
578
+ ...Object.keys(devDependencies)
579
+ ]),
580
+ // Only dependencies that cause compatibility issues are not bundled.
581
+ peer: processDependencies(externalForPeerBuild),
582
+ // No runtime dependencies, everything's bundled.
583
+ standalone: []
584
+ };
585
+ const commonOutput = {
586
+ banner,
587
+ dir: ".",
588
+ globals: processGlobals(globals),
589
+ sourcemap: VIS_TEST ? "inline" : true
590
+ };
591
+ const commonOutputESM = {
592
+ ...commonOutput,
593
+ format: "esm"
594
+ };
595
+ const commonOutputUMD = {
596
+ ...commonOutput,
597
+ exports: "named",
598
+ extend: true,
599
+ format: "umd",
600
+ name: "vis",
601
+ strict: false
602
+ // Regenerator runtime causes issues with CSP in strict mode.
603
+ };
604
+ const getPlugins = generateRollupPluginArray.bind(null, libraryFilename).bind(null, assets).bind(null, copyTargetsBundle).bind(null, copyTargetsVariant).bind(null, tsconfig).bind(null, mode);
605
+ return [
606
+ {
607
+ external: external.standalone,
608
+ input: standaloneEntry,
609
+ output: [
610
+ {
611
+ ...commonOutputESM,
612
+ entryFileNames: `standalone/esm/${libraryFilename}.js`
613
+ },
614
+ {
615
+ ...commonOutputESM,
616
+ entryFileNames: `standalone/esm/${libraryFilename}.mjs`
617
+ },
618
+ {
619
+ ...commonOutputUMD,
620
+ entryFileNames: `standalone/umd/${libraryFilename}.js`
621
+ },
622
+ {
623
+ ...commonOutputUMD,
624
+ entryFileNames: `standalone/umd/${libraryFilename}.cjs`
625
+ }
626
+ ],
627
+ plugins: getPlugins("standalone", {
628
+ injectCSS,
629
+ transpile,
630
+ typescript: isTS(standaloneEntry)
631
+ })
632
+ },
633
+ {
634
+ external: external.standalone,
635
+ input: standaloneEntry,
636
+ output: [
637
+ {
638
+ ...commonOutputESM,
639
+ entryFileNames: `standalone/esm/${libraryFilename}.min.js`
640
+ },
641
+ {
642
+ ...commonOutputESM,
643
+ entryFileNames: `standalone/esm/${libraryFilename}.min.mjs`
644
+ },
645
+ {
646
+ ...commonOutputUMD,
647
+ entryFileNames: `standalone/umd/${libraryFilename}.min.js`
648
+ },
649
+ {
650
+ ...commonOutputUMD,
651
+ entryFileNames: `standalone/umd/${libraryFilename}.min.cjs`
652
+ }
653
+ ],
654
+ plugins: getPlugins("standalone", {
655
+ injectCSS,
656
+ minimize,
657
+ transpile,
658
+ typescript: isTS(standaloneEntry)
659
+ })
660
+ },
661
+ {
662
+ external: external.peer,
663
+ input: peerEntry,
664
+ output: [
665
+ {
666
+ ...commonOutputESM,
667
+ entryFileNames: `peer/esm/${libraryFilename}.js`,
668
+ paths: getPaths("peer", "esm")
669
+ },
670
+ {
671
+ ...commonOutputESM,
672
+ entryFileNames: `peer/esm/${libraryFilename}.mjs`,
673
+ paths: getPaths("peer", "esm")
674
+ },
675
+ {
676
+ ...commonOutputUMD,
677
+ entryFileNames: `peer/umd/${libraryFilename}.js`,
678
+ paths: getPaths("peer", "umd")
679
+ },
680
+ {
681
+ ...commonOutputUMD,
682
+ entryFileNames: `peer/umd/${libraryFilename}.cjs`,
683
+ paths: getPaths("peer", "umd")
684
+ }
685
+ ],
686
+ plugins: getPlugins("peer", {
687
+ transpile,
688
+ typescript: isTS(peerEntry)
689
+ })
690
+ },
691
+ {
692
+ external: external.peer,
693
+ input: peerEntry,
694
+ output: [
695
+ {
696
+ ...commonOutputESM,
697
+ entryFileNames: `peer/esm/${libraryFilename}.min.js`,
698
+ paths: getPaths("peer", "esm")
699
+ },
700
+ {
701
+ ...commonOutputESM,
702
+ entryFileNames: `peer/esm/${libraryFilename}.min.mjs`,
703
+ paths: getPaths("peer", "esm")
704
+ },
705
+ {
706
+ ...commonOutputUMD,
707
+ entryFileNames: `peer/umd/${libraryFilename}.min.js`,
708
+ paths: getPaths("peer", "umd")
709
+ },
710
+ {
711
+ ...commonOutputUMD,
712
+ entryFileNames: `peer/umd/${libraryFilename}.min.cjs`,
713
+ paths: getPaths("peer", "umd")
714
+ }
715
+ ],
716
+ plugins: getPlugins("peer", {
717
+ minimize,
718
+ transpile,
719
+ typescript: isTS(peerEntry)
720
+ })
721
+ },
722
+ {
723
+ external: external.esnext,
724
+ input: esnextEntry,
725
+ output: [
726
+ {
727
+ ...commonOutputESM,
728
+ entryFileNames: `esnext/esm/${libraryFilename}.js`,
729
+ paths: getPaths("esnext", "esm")
730
+ },
731
+ {
732
+ ...commonOutputESM,
733
+ entryFileNames: `esnext/esm/${libraryFilename}.mjs`,
734
+ paths: getPaths("esnext", "esm")
735
+ },
736
+ {
737
+ ...commonOutputESM,
738
+ entryFileNames: `esnext/umd/${libraryFilename}.js`,
739
+ paths: getPaths("esnext", "umd")
740
+ },
741
+ {
742
+ ...commonOutputESM,
743
+ entryFileNames: `esnext/umd/${libraryFilename}.cjs`,
744
+ paths: getPaths("esnext", "umd")
745
+ }
746
+ ],
747
+ plugins: getPlugins("esnext", {
748
+ typescript: isTS(esnextEntry)
749
+ })
750
+ },
751
+ {
752
+ external: external.esnext,
753
+ input: esnextEntry,
754
+ output: [
755
+ {
756
+ ...commonOutputESM,
757
+ entryFileNames: `esnext/esm/${libraryFilename}.min.js`,
758
+ paths: getPaths("esnext", "esm")
759
+ },
760
+ {
761
+ ...commonOutputESM,
762
+ entryFileNames: `esnext/esm/${libraryFilename}.min.mjs`,
763
+ paths: getPaths("esnext", "esm")
764
+ },
765
+ {
766
+ ...commonOutputUMD,
767
+ entryFileNames: `esnext/umd/${libraryFilename}.min.js`,
768
+ paths: getPaths("esnext", "umd")
769
+ },
770
+ {
771
+ ...commonOutputUMD,
772
+ entryFileNames: `esnext/umd/${libraryFilename}.min.cjs`,
773
+ paths: getPaths("esnext", "umd")
774
+ }
775
+ ],
776
+ plugins: getPlugins("esnext", {
777
+ minimize,
778
+ typescript: isTS(esnextEntry)
779
+ })
780
+ }
781
+ ];
782
+ }
783
+
784
+ setGracefulCleanup();
785
+ const PACK_CMD = [
786
+ "npm",
787
+ "pack",
788
+ // Don't create any package, we just need to see what would be packed.
789
+ "--dry-run",
790
+ // Prevents things like Husky from outputting to stdout, we don't need them
791
+ // here anyway.
792
+ "--ignore-scripts",
793
+ // JSON is easier to parse and more stable between npm versions.
794
+ "--json"
795
+ ];
796
+ function logStderr(textOrLines, message) {
797
+ console.group('"npm pack" output');
798
+ console.error(textOrLines);
799
+ console.groupEnd();
800
+ throw new Error(message);
801
+ }
802
+ function runNpmPack() {
803
+ const tmpFile = fileSync().name;
804
+ execSync(`${PACK_CMD.join(" ")} > ${tmpFile}`, {
805
+ encoding: "utf-8",
806
+ env: {
807
+ ...process.env,
808
+ LC_ALL: "C",
809
+ NODE_ENV: "production"
810
+ }
811
+ });
812
+ const stdout = readFileSync(tmpFile, "utf-8").replace(/^([^[]*)\[\n/, "[");
813
+ try {
814
+ return JSON.parse(stdout);
815
+ } catch (error) {
816
+ logStderr({ error, stdout }, 'Failed to parse "npm pack" JSON output.');
817
+ }
818
+ }
819
+ function extractFiles(packageInfo) {
820
+ const files = packageInfo.files.map(
821
+ ({ path, size }) => [
822
+ path,
823
+ { empty: size === 0 }
824
+ ]
825
+ );
826
+ if (files.length === 0) {
827
+ logStderr(packageInfo, 'No files found in "npm pack" output.');
828
+ }
829
+ return Object.fromEntries(files);
830
+ }
831
+ function extractName(packageInfo) {
832
+ const name = packageInfo.name;
833
+ if (name == null) {
834
+ logStderr(
835
+ packageInfo,
836
+ `Can't find the name of the package in "npm pack" output.`
837
+ );
838
+ }
839
+ return name.replace(/^npm notice name: */, "");
840
+ }
841
+ function inspectNpmPack() {
842
+ const [packageInfo, ...unexpectedExtras] = runNpmPack();
843
+ if (packageInfo == null) {
844
+ logStderr(
845
+ [packageInfo, ...unexpectedExtras],
846
+ 'There was no output from "npm pack".'
847
+ );
848
+ }
849
+ if (unexpectedExtras.length !== 0) {
850
+ logStderr(
851
+ [packageInfo, ...unexpectedExtras],
852
+ `Can't process the output of "npm pack" if there are multiple packages.`
853
+ );
854
+ }
855
+ const files = extractFiles(packageInfo);
856
+ const name = extractName(packageInfo);
857
+ return {
858
+ name,
859
+ files
860
+ };
861
+ }
862
+
863
+ export { BABEL_IGNORE_RE, generateHeader, generateRollupConfiguration, inspectNpmPack, textToComment };
864
+ //# sourceMappingURL=vis-dev-utils.mjs.map