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