@arcgis/components-build-utils 5.1.0-next.98 → 5.2.0-next.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -8,5 +8,5 @@ It is not intended to be used directly, but rather used as a dependency by other
8
8
 
9
9
  ## License
10
10
 
11
- This package is licensed under the terms described in the `LICENSE.md` file, located in the root of the package, and at https://js.arcgis.com/5.0/LICENSE.txt.
12
- For third party notices, see https://js.arcgis.com/5.0/third-party-notices.txt.
11
+ This package is licensed under the terms described in the `LICENSE.md` file, located in the root of the package, and at https://js.arcgis.com/5.1/LICENSE.txt.
12
+ For third party notices, see https://js.arcgis.com/5.1/third-party-notices.txt.
package/dist/index.cjs CHANGED
@@ -44,13 +44,20 @@ function sh(command, options = {}) {
44
44
  }
45
45
  }
46
46
  function sp(command, args, options = {}) {
47
- try {
48
- const normalizedOptions = { encoding: "utf8", ...options };
49
- const result = node_child_process.spawnSync(command, args, normalizedOptions);
50
- return `${result.stdout ?? ""}${result.stderr ?? ""}`.trim();
51
- } catch (error) {
52
- throw error;
47
+ const normalizedOptions = { encoding: "utf8", ...options };
48
+ const result = node_child_process.spawnSync(command, args, normalizedOptions);
49
+ if (result.error) {
50
+ throw result.error;
51
+ }
52
+ const output = `${result.stdout ?? ""}${result.stderr ?? ""}`.trim();
53
+ const exitCode = result.status ?? 0;
54
+ if (exitCode !== 0) {
55
+ throw new Error(
56
+ `Command failed with exit code ${String(exitCode)}: ${command} ${args.join(" ")}
57
+ ${output}`.trim()
58
+ );
53
59
  }
60
+ return output;
54
61
  }
55
62
  async function asyncSh(command, options = {}) {
56
63
  const normalizedOptions = { encoding: "utf8", ...options };
@@ -250,7 +257,8 @@ function detectPackageManager(cwd = process.cwd()) {
250
257
  function vitePresetPlugin({
251
258
  dtsOptions = {},
252
259
  externalize,
253
- bundleIn
260
+ bundleIn,
261
+ isApplication
254
262
  } = {
255
263
  externalize: [],
256
264
  dtsOptions: {}
@@ -281,7 +289,8 @@ function vitePresetPlugin({
281
289
  },
282
290
  externalizeDependencies({
283
291
  externalize,
284
- bundleIn
292
+ bundleIn,
293
+ isApplication
285
294
  }),
286
295
  // This dependency pulls in many others. Since components-build-utils has a
287
296
  // single entry point, we load a large module tree needlessly. To avoid,
@@ -340,24 +349,33 @@ function shouldSkip(id) {
340
349
  return id.includes("__test") || id.includes(".e2e.") || id.includes(".spec.") || id.includes(".test.") || id.includes(".stories.");
341
350
  }
342
351
  function externalizeDependencies(options) {
343
- const packageJson = retrievePackageJson();
352
+ return externalizeDependenciesImplementation(options, retrievePackageJson());
353
+ }
354
+ function externalizeDependenciesImplementation(options, packageJson) {
344
355
  const externalDependencies = Object.keys({
345
356
  ...packageJson.dependencies,
346
357
  ...packageJson.peerDependencies,
347
358
  ...packageJson.optionalDependencies
348
359
  });
360
+ const isStrictBundling = toPosixPathSeparators(void 0).includes(
361
+ "support-packages/components-build-utils"
362
+ );
349
363
  const bundleIn = options.bundleIn?.map(stringToStartsWithGlob);
364
+ const explicitExternalize = options.externalize?.map(stringToStartsWithGlob) ?? [];
350
365
  const externalize = [
351
- ...options.externalize?.map(stringToStartsWithGlob) ?? [],
366
+ ...explicitExternalize,
367
+ // BUG: we shouldn't silently externalize node in browser packages.
368
+ // Consider erroring instead
352
369
  /^node:/u,
353
370
  new RegExp(
354
- `^(?:${externalDependencies.join("|")}${externalDependencies.length === 0 ? "" : "|"}${node_module.builtinModules.join("|")})(?:/.+)?$`,
371
+ `^(?:${externalDependencies.join("|")}${externalDependencies.length === 0 ? "" : "|"}${node_module.builtinModules.join("|")})(?:/|$)`,
355
372
  "u"
356
373
  )
357
374
  ];
358
375
  const plugin = {
359
- name: "@arcgis/components-build-utils:externalize-dependencies",
376
+ name: pluginName,
360
377
  apply: "build",
378
+ // Externalize before Vite's default resolution runs
361
379
  enforce: "pre",
362
380
  // Rolldown also has "external" option, which can be provided regexes.
363
381
  // Theoretically that would be more efficient due to less communication
@@ -367,21 +385,62 @@ function externalizeDependencies(options) {
367
385
  resolveId: {
368
386
  filter: {
369
387
  id: {
370
- include: externalize,
388
+ include: [
389
+ // In most cases, we want all dependencies in library packages to be
390
+ // externalized. Thus, this regex matches all non-relative imports.
391
+ nonRelativeSpecifierPattern,
392
+ // Also include explicitExternalize because those may target relative
393
+ // paths (e.g. ./draconvert.js in mock-services).
394
+ ...explicitExternalize
395
+ ],
371
396
  exclude: bundleIn
372
397
  }
373
398
  },
374
- handler() {
375
- return false;
399
+ handler(id, importer, resolveOptions) {
400
+ if (matchesAny(id, externalize)) {
401
+ return false;
402
+ }
403
+ if (
404
+ // Entrypoints look like src/components/button/button.tsx, so are
405
+ // matched by the nonRelativeSpecifierPattern
406
+ resolveOptions.isEntry || // Virtual specifiers are handled by plugins
407
+ id.startsWith("\0") || // data: node: virtual:
408
+ id.includes(":") || // ?raw ?url ?worker - resolved by other plugins
409
+ id.includes("?") || // Applications can bundle in anything
410
+ options.isApplication === true
411
+ ) {
412
+ return;
413
+ }
414
+ const error = `[${pluginName}] Vite tried to bundle in "${id}" (imported by ${importer}).
415
+ This is likely undesirable. To externalize it, declare this dependency as a "dependency", "peerDependency" or "optionalDependency" in package.json.
416
+ If this is intentional, add it to the build.dependencies.bundleIn option in useLumina() or bundleIn option in the vitePresetPlugin().
417
+ If this is an application rather than a library, pass isApplication:true in vitePresetPlugin().`;
418
+ if (isStrictBundling) {
419
+ throw Error(error);
420
+ } else {
421
+ console.error(node_util.styleText("red", `${error}
422
+ This will be an error in future version.`));
423
+ return;
424
+ }
376
425
  }
377
426
  }
378
427
  };
379
428
  return plugin;
380
429
  }
430
+ const pluginName = "@arcgis/components-build-utils:externalize-dependencies";
381
431
  const stringToStartsWithGlob = (option) => typeof option === "string" ? new RegExp(
382
432
  `^${option.replace(/[.*+?^${}()|[\]\\]/gu, "\\$&")}${option.endsWith("/") ? "(?:.+)?" : "(?:/.+)?"}$`,
383
433
  "u"
384
434
  ) : option;
435
+ const nonRelativeSpecifierPattern = /^[^\.\/]/u;
436
+ function matchesAny(id, patterns) {
437
+ for (let index = 0; index < patterns.length; ++index) {
438
+ if (patterns[index].test(id)) {
439
+ return true;
440
+ }
441
+ }
442
+ return false;
443
+ }
385
444
  exports.asyncFindPath = asyncFindPath;
386
445
  exports.asyncRetrievePackageJson = asyncRetrievePackageJson;
387
446
  exports.asyncSh = asyncSh;
package/dist/index.js CHANGED
@@ -20,13 +20,20 @@ function sh(command, options = {}) {
20
20
  }
21
21
  }
22
22
  function sp(command, args, options = {}) {
23
- try {
24
- const normalizedOptions = { encoding: "utf8", ...options };
25
- const result = spawnSync(command, args, normalizedOptions);
26
- return `${result.stdout ?? ""}${result.stderr ?? ""}`.trim();
27
- } catch (error) {
28
- throw error;
23
+ const normalizedOptions = { encoding: "utf8", ...options };
24
+ const result = spawnSync(command, args, normalizedOptions);
25
+ if (result.error) {
26
+ throw result.error;
27
+ }
28
+ const output = `${result.stdout ?? ""}${result.stderr ?? ""}`.trim();
29
+ const exitCode = result.status ?? 0;
30
+ if (exitCode !== 0) {
31
+ throw new Error(
32
+ `Command failed with exit code ${String(exitCode)}: ${command} ${args.join(" ")}
33
+ ${output}`.trim()
34
+ );
29
35
  }
36
+ return output;
30
37
  }
31
38
  async function asyncSh(command, options = {}) {
32
39
  const normalizedOptions = { encoding: "utf8", ...options };
@@ -226,7 +233,8 @@ function detectPackageManager(cwd = process.cwd()) {
226
233
  function vitePresetPlugin({
227
234
  dtsOptions = {},
228
235
  externalize,
229
- bundleIn
236
+ bundleIn,
237
+ isApplication
230
238
  } = {
231
239
  externalize: [],
232
240
  dtsOptions: {}
@@ -257,7 +265,8 @@ function vitePresetPlugin({
257
265
  },
258
266
  externalizeDependencies({
259
267
  externalize,
260
- bundleIn
268
+ bundleIn,
269
+ isApplication
261
270
  }),
262
271
  // This dependency pulls in many others. Since components-build-utils has a
263
272
  // single entry point, we load a large module tree needlessly. To avoid,
@@ -316,24 +325,33 @@ function shouldSkip(id) {
316
325
  return id.includes("__test") || id.includes(".e2e.") || id.includes(".spec.") || id.includes(".test.") || id.includes(".stories.");
317
326
  }
318
327
  function externalizeDependencies(options) {
319
- const packageJson = retrievePackageJson();
328
+ return externalizeDependenciesImplementation(options, retrievePackageJson());
329
+ }
330
+ function externalizeDependenciesImplementation(options, packageJson) {
320
331
  const externalDependencies = Object.keys({
321
332
  ...packageJson.dependencies,
322
333
  ...packageJson.peerDependencies,
323
334
  ...packageJson.optionalDependencies
324
335
  });
336
+ const isStrictBundling = toPosixPathSeparators(import.meta.dirname).includes(
337
+ "support-packages/components-build-utils"
338
+ );
325
339
  const bundleIn = options.bundleIn?.map(stringToStartsWithGlob);
340
+ const explicitExternalize = options.externalize?.map(stringToStartsWithGlob) ?? [];
326
341
  const externalize = [
327
- ...options.externalize?.map(stringToStartsWithGlob) ?? [],
342
+ ...explicitExternalize,
343
+ // BUG: we shouldn't silently externalize node in browser packages.
344
+ // Consider erroring instead
328
345
  /^node:/u,
329
346
  new RegExp(
330
- `^(?:${externalDependencies.join("|")}${externalDependencies.length === 0 ? "" : "|"}${builtinModules.join("|")})(?:/.+)?$`,
347
+ `^(?:${externalDependencies.join("|")}${externalDependencies.length === 0 ? "" : "|"}${builtinModules.join("|")})(?:/|$)`,
331
348
  "u"
332
349
  )
333
350
  ];
334
351
  const plugin = {
335
- name: "@arcgis/components-build-utils:externalize-dependencies",
352
+ name: pluginName,
336
353
  apply: "build",
354
+ // Externalize before Vite's default resolution runs
337
355
  enforce: "pre",
338
356
  // Rolldown also has "external" option, which can be provided regexes.
339
357
  // Theoretically that would be more efficient due to less communication
@@ -343,21 +361,62 @@ function externalizeDependencies(options) {
343
361
  resolveId: {
344
362
  filter: {
345
363
  id: {
346
- include: externalize,
364
+ include: [
365
+ // In most cases, we want all dependencies in library packages to be
366
+ // externalized. Thus, this regex matches all non-relative imports.
367
+ nonRelativeSpecifierPattern,
368
+ // Also include explicitExternalize because those may target relative
369
+ // paths (e.g. ./draconvert.js in mock-services).
370
+ ...explicitExternalize
371
+ ],
347
372
  exclude: bundleIn
348
373
  }
349
374
  },
350
- handler() {
351
- return false;
375
+ handler(id, importer, resolveOptions) {
376
+ if (matchesAny(id, externalize)) {
377
+ return false;
378
+ }
379
+ if (
380
+ // Entrypoints look like src/components/button/button.tsx, so are
381
+ // matched by the nonRelativeSpecifierPattern
382
+ resolveOptions.isEntry || // Virtual specifiers are handled by plugins
383
+ id.startsWith("\0") || // data: node: virtual:
384
+ id.includes(":") || // ?raw ?url ?worker - resolved by other plugins
385
+ id.includes("?") || // Applications can bundle in anything
386
+ options.isApplication === true
387
+ ) {
388
+ return;
389
+ }
390
+ const error = `[${pluginName}] Vite tried to bundle in "${id}" (imported by ${importer}).
391
+ This is likely undesirable. To externalize it, declare this dependency as a "dependency", "peerDependency" or "optionalDependency" in package.json.
392
+ If this is intentional, add it to the build.dependencies.bundleIn option in useLumina() or bundleIn option in the vitePresetPlugin().
393
+ If this is an application rather than a library, pass isApplication:true in vitePresetPlugin().`;
394
+ if (isStrictBundling) {
395
+ throw Error(error);
396
+ } else {
397
+ console.error(styleText("red", `${error}
398
+ This will be an error in future version.`));
399
+ return;
400
+ }
352
401
  }
353
402
  }
354
403
  };
355
404
  return plugin;
356
405
  }
406
+ const pluginName = "@arcgis/components-build-utils:externalize-dependencies";
357
407
  const stringToStartsWithGlob = (option) => typeof option === "string" ? new RegExp(
358
408
  `^${option.replace(/[.*+?^${}()|[\]\\]/gu, "\\$&")}${option.endsWith("/") ? "(?:.+)?" : "(?:/.+)?"}$`,
359
409
  "u"
360
410
  ) : option;
411
+ const nonRelativeSpecifierPattern = /^[^\.\/]/u;
412
+ function matchesAny(id, patterns) {
413
+ for (let index = 0; index < patterns.length; ++index) {
414
+ if (patterns[index].test(id)) {
415
+ return true;
416
+ }
417
+ }
418
+ return false;
419
+ }
361
420
  export {
362
421
  asyncFindPath,
363
422
  asyncRetrievePackageJson,
@@ -13,6 +13,8 @@ export type PackageJson = {
13
13
  "module"?: string;
14
14
  "types"?: string;
15
15
  "files"?: string[];
16
+ "bin"?: Record<string, string> | string;
17
+ "man"?: string[] | string;
16
18
  "dependencies"?: Record<string, string>;
17
19
  "devDependencies"?: Record<string, string>;
18
20
  "peerDependencies"?: Record<string, string>;
@@ -13,6 +13,8 @@ export type PackageJson = {
13
13
  "module"?: string;
14
14
  "types"?: string;
15
15
  "files"?: string[];
16
+ "bin"?: Record<string, string> | string;
17
+ "man"?: string[] | string;
16
18
  "dependencies"?: Record<string, string>;
17
19
  "devDependencies"?: Record<string, string>;
18
20
  "peerDependencies"?: Record<string, string>;
package/dist/vite.d.cts CHANGED
@@ -1,11 +1,12 @@
1
1
  import { Plugin } from 'vite';
2
2
  import { default as dts } from 'vite-plugin-dts';
3
+ import { PackageJson } from './packageJson.ts';
3
4
  /**
4
5
  * Vite preset for all our support packages:
5
6
  * - externalizes all non-dev-dependencies
6
7
  * - generates type declarations (using `vite-plugin-dts`)
7
8
  */
8
- export declare function vitePresetPlugin({ dtsOptions, externalize, bundleIn, }?: DependencyManagementOptions & {
9
+ export declare function vitePresetPlugin({ dtsOptions, externalize, bundleIn, isApplication, }?: DependencyManagementOptions & {
9
10
  /** Additional options for `vite-plugin-dts` */
10
11
  dtsOptions?: Parameters<typeof dts>[0] | false;
11
12
  }): [Plugin, Plugin, Promise<Plugin> | undefined];
@@ -40,6 +41,14 @@ export type DependencyManagementOptions = {
40
41
  * technical reasons.
41
42
  */
42
43
  readonly externalize?: (RegExp | string)[];
44
+ /**
45
+ * By default, this plugin errors if any devDependency is used in runtime code
46
+ * to avoid bundling in dependencies in a library. In application packages,
47
+ * bundling in everything is desirable, so enable this option.
48
+ *
49
+ * @default false
50
+ */
51
+ readonly isApplication?: boolean;
43
52
  };
44
53
  /**
45
54
  * By default, Rollup will bundle-in all dependencies.
@@ -69,6 +78,24 @@ export type DependencyManagementOptions = {
69
78
  * be externalized (because all peerDependencies are externalized).
70
79
  */
71
80
  export declare function externalizeDependencies(options: DependencyManagementOptions): Plugin;
81
+ interface PluginShape extends Plugin {
82
+ resolveId: {
83
+ filter: {
84
+ id: {
85
+ include: RegExp[];
86
+ exclude: RegExp[] | undefined;
87
+ };
88
+ };
89
+ handler: (id: string, importer: string | undefined, options: {
90
+ isEntry: boolean;
91
+ }) => false | undefined;
92
+ };
93
+ }
94
+ declare function externalizeDependenciesImplementation(options: DependencyManagementOptions, packageJson: PackageJson): PluginShape;
95
+ declare function matchesAny(id: string, patterns: readonly RegExp[]): boolean;
72
96
  export declare const exportsForTests: {
73
97
  stringToStartsWithGlob: (option: RegExp | string) => RegExp;
98
+ externalizeDependenciesImplementation: typeof externalizeDependenciesImplementation;
99
+ matchesAny: typeof matchesAny;
74
100
  };
101
+ export {};
package/dist/vite.d.ts CHANGED
@@ -1,11 +1,12 @@
1
1
  import { Plugin } from 'vite';
2
2
  import { default as dts } from 'vite-plugin-dts';
3
+ import { PackageJson } from './packageJson.ts';
3
4
  /**
4
5
  * Vite preset for all our support packages:
5
6
  * - externalizes all non-dev-dependencies
6
7
  * - generates type declarations (using `vite-plugin-dts`)
7
8
  */
8
- export declare function vitePresetPlugin({ dtsOptions, externalize, bundleIn, }?: DependencyManagementOptions & {
9
+ export declare function vitePresetPlugin({ dtsOptions, externalize, bundleIn, isApplication, }?: DependencyManagementOptions & {
9
10
  /** Additional options for `vite-plugin-dts` */
10
11
  dtsOptions?: Parameters<typeof dts>[0] | false;
11
12
  }): [Plugin, Plugin, Promise<Plugin> | undefined];
@@ -40,6 +41,14 @@ export type DependencyManagementOptions = {
40
41
  * technical reasons.
41
42
  */
42
43
  readonly externalize?: (RegExp | string)[];
44
+ /**
45
+ * By default, this plugin errors if any devDependency is used in runtime code
46
+ * to avoid bundling in dependencies in a library. In application packages,
47
+ * bundling in everything is desirable, so enable this option.
48
+ *
49
+ * @default false
50
+ */
51
+ readonly isApplication?: boolean;
43
52
  };
44
53
  /**
45
54
  * By default, Rollup will bundle-in all dependencies.
@@ -69,6 +78,24 @@ export type DependencyManagementOptions = {
69
78
  * be externalized (because all peerDependencies are externalized).
70
79
  */
71
80
  export declare function externalizeDependencies(options: DependencyManagementOptions): Plugin;
81
+ interface PluginShape extends Plugin {
82
+ resolveId: {
83
+ filter: {
84
+ id: {
85
+ include: RegExp[];
86
+ exclude: RegExp[] | undefined;
87
+ };
88
+ };
89
+ handler: (id: string, importer: string | undefined, options: {
90
+ isEntry: boolean;
91
+ }) => false | undefined;
92
+ };
93
+ }
94
+ declare function externalizeDependenciesImplementation(options: DependencyManagementOptions, packageJson: PackageJson): PluginShape;
95
+ declare function matchesAny(id: string, patterns: readonly RegExp[]): boolean;
72
96
  export declare const exportsForTests: {
73
97
  stringToStartsWithGlob: (option: RegExp | string) => RegExp;
98
+ externalizeDependenciesImplementation: typeof externalizeDependenciesImplementation;
99
+ matchesAny: typeof matchesAny;
74
100
  };
101
+ export {};
package/package.json CHANGED
@@ -1,25 +1,25 @@
1
1
  {
2
2
  "name": "@arcgis/components-build-utils",
3
- "version": "5.1.0-next.98",
3
+ "version": "5.2.0-next.0",
4
4
  "description": "Collection of common internal build-time patterns and utilities for ArcGIS Maps SDK for JavaScript components.",
5
5
  "homepage": "https://developers.arcgis.com/javascript/latest/",
6
6
  "type": "module",
7
- "main": "dist/index.cjs",
8
- "module": "dist/index.js",
9
- "types": "dist/index.d.ts",
7
+ "main": "./dist/index.cjs",
8
+ "module": "./dist/index.js",
9
+ "types": "./dist/index.d.ts",
10
10
  "exports": {
11
11
  ".": {
12
12
  "types": "./dist/index.d.ts",
13
13
  "import": "./dist/index.js",
14
14
  "require": "./dist/index.cjs"
15
- },
16
- "./ts": "./src/index.ts"
15
+ }
17
16
  },
18
17
  "files": [
19
18
  "dist/"
20
19
  ],
21
20
  "license": "SEE LICENSE IN LICENSE.md",
22
21
  "dependencies": {
22
+ "@types/node": "^24.10.0",
23
23
  "tslib": "^2.8.1",
24
24
  "vite": "^7.3.2",
25
25
  "vite-plugin-dts": "^4.5.4"