@arcgis/node-toolkit 5.2.0-next.79 → 5.2.0-next.85

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/shell.d.ts CHANGED
@@ -1,6 +1,9 @@
1
- import { ExecSyncOptionsWithStringEncoding, SpawnSyncOptionsWithStringEncoding, SpawnOptions } from 'node:child_process';
1
+ import { ExecOptionsWithStringEncoding, ExecSyncOptionsWithStringEncoding, SpawnSyncOptionsWithStringEncoding, SpawnOptions } from 'node:child_process';
2
2
  type SyncProcessOptions = Omit<SpawnSyncOptionsWithStringEncoding, "stdio">;
3
- type AsyncProcessOptions = Omit<SpawnOptions, "stdio"> & {
3
+ type CollectOutputSyncOptions = SyncProcessOptions & {
4
+ stderr?: "ignore" | "inherit";
5
+ };
6
+ type AsyncProcessOptions = SpawnOptions & {
4
7
  input?: NonNullable<SpawnSyncOptionsWithStringEncoding["input"]>;
5
8
  };
6
9
  /**
@@ -30,7 +33,7 @@ export declare function sh(command: string, options?: Partial<ExecSyncOptionsWit
30
33
  * Example (shell features required):
31
34
  * `await asyncSh("pnpm list | grep @arcgis/core")`
32
35
  */
33
- export declare function asyncSh(command: string, options?: Partial<ExecSyncOptionsWithStringEncoding>): Promise<string>;
36
+ export declare function asyncSh(command: string, options?: Partial<ExecOptionsWithStringEncoding>): Promise<string>;
34
37
  /**
35
38
  * Synchronously execute a command without shell interpolation and return the output.
36
39
  *
@@ -67,7 +70,7 @@ export declare function runCommand(command: string, args: string[], options?: Pa
67
70
  * Synchronously execute a command and collect stdout while streaming stderr.
68
71
  * Note that `pnpm` command will be automatically invoked with `shell: process.platform === "win32"`.
69
72
  */
70
- export declare function collectOutputSync(command: string, args: string[], options?: Partial<SyncProcessOptions>): string;
73
+ export declare function collectOutputSync(command: string, args: string[], options?: Partial<CollectOutputSyncOptions>): string;
71
74
  /**
72
75
  * Asynchronously execute a command and collect stdout while streaming stderr.
73
76
  * Note that `pnpm` command will be automatically invoked with `shell: process.platform === "win32"`.
package/dist/shell.js CHANGED
@@ -67,14 +67,14 @@ function runCommandSync(command, args, options = {}) {
67
67
  const fixedOptions = fixPnpmUsage(command, options);
68
68
  const { input } = fixedOptions;
69
69
  const stdio = input === void 0 ? "inherit" : ["pipe", "inherit", "inherit"];
70
- const result = spawnSync(command, args, { ...fixedOptions, stdio });
70
+ const result = spawnSync(command, args, { stdio, ...fixedOptions });
71
71
  assertSyncResultSuccess(command, args, result);
72
72
  }
73
73
  async function runCommand(command, args, options = {}) {
74
74
  const fixedOptions = fixPnpmUsage(command, options);
75
75
  const { input } = fixedOptions;
76
76
  const stdio = input === void 0 ? "inherit" : ["pipe", "inherit", "inherit"];
77
- const child = spawn(command, args, { ...fixedOptions, stdio });
77
+ const child = spawn(command, args, { stdio, ...fixedOptions });
78
78
  if (input !== void 0) {
79
79
  child.stdin?.end(input);
80
80
  }
@@ -91,11 +91,12 @@ async function runCommand(command, args, options = {}) {
91
91
  }
92
92
  function collectOutputSync(command, args, options = {}) {
93
93
  const fixedOptions = fixPnpmUsage(command, options);
94
- const { input } = fixedOptions;
94
+ const { input, stderr = "inherit", ...spawnOptions } = fixedOptions;
95
95
  const result = spawnSync(command, args, {
96
96
  encoding: "utf8",
97
- ...fixedOptions,
98
- stdio: [input === void 0 ? "ignore" : "pipe", "pipe", "inherit"]
97
+ stdio: [input === void 0 ? "ignore" : "pipe", "pipe", stderr],
98
+ ...spawnOptions,
99
+ ...input === void 0 ? {} : { input }
99
100
  });
100
101
  assertSyncResultSuccess(command, args, result);
101
102
  return (result.stdout ?? "").trim();
@@ -104,8 +105,8 @@ async function collectOutput(command, args, options = {}) {
104
105
  const fixedOptions = fixPnpmUsage(command, options);
105
106
  const { input } = fixedOptions;
106
107
  const child = spawn(command, args, {
107
- ...fixedOptions,
108
- stdio: [input === void 0 ? "ignore" : "pipe", "pipe", "inherit"]
108
+ stdio: [input === void 0 ? "ignore" : "pipe", "pipe", "inherit"],
109
+ ...fixedOptions
109
110
  });
110
111
  if (input !== void 0) {
111
112
  child.stdin?.end(input);
@@ -0,0 +1,3 @@
1
+ import { Plugin } from 'vite';
2
+ /** @public */
3
+ export declare function installPlaywright(): Plugin;
@@ -0,0 +1,87 @@
1
+ import { mkdir, rm, stat } from "node:fs/promises";
2
+ import { homedir } from "node:os";
3
+ import { join } from "node:path";
4
+ import { findPath, existsAsync } from "../file.js";
5
+ import { runCommand } from "../shell.js";
6
+ import { pathToFileURL } from "node:url";
7
+ let installPromise;
8
+ function installPlaywright() {
9
+ return {
10
+ name: "install-playwright",
11
+ apply() {
12
+ if (process.env.VITEST === "true") {
13
+ installPromise ??= ensureInstalled();
14
+ return true;
15
+ }
16
+ return false;
17
+ },
18
+ async configResolved() {
19
+ await installPromise;
20
+ }
21
+ };
22
+ }
23
+ async function ensureInstalled() {
24
+ const playwrightCwd = findPath("node_modules/playwright");
25
+ if (playwrightCwd === void 0) {
26
+ throw new Error("Playwright not found in node_modules. Please install it first.");
27
+ }
28
+ const { chromium } = await import(pathToFileURL(join(playwrightCwd, "index.mjs")).href);
29
+ if (await existsAsync(chromium.executablePath())) {
30
+ return;
31
+ }
32
+ const home = homedir();
33
+ const { env, platform } = process;
34
+ const stateDir = env.XDG_STATE_HOME ?? env.XDG_CACHE_HOME ?? (platform === "win32" ? env.LOCALAPPDATA ?? join(home, "AppData", "Local", "webgis-sdk") : platform === "darwin" ? join(home, "Library", "Caches", "webgis-sdk") : join(home, ".local", "state", "webgis-sdk"));
35
+ const lockPath = join(stateDir, "playwright-install.lock");
36
+ await mkdir(stateDir, { recursive: true });
37
+ const releaseLock = await acquireLock(lockPath);
38
+ try {
39
+ if (await existsAsync(chromium.executablePath())) {
40
+ return;
41
+ }
42
+ const installArgs = [
43
+ join(playwrightCwd, "cli.js"),
44
+ "install",
45
+ ...process.platform === "linux" ? ["--with-deps"] : [],
46
+ "chromium",
47
+ "chromium-headless-shell"
48
+ ];
49
+ await runCommand(process.execPath, installArgs, { stdio: ["ignore", "ignore", "inherit"] });
50
+ } finally {
51
+ await releaseLock();
52
+ }
53
+ }
54
+ const lockPoll = 500;
55
+ async function acquireLock(lockDir) {
56
+ const startTime = Date.now();
57
+ while (true) {
58
+ try {
59
+ await mkdir(lockDir);
60
+ return async () => {
61
+ await rm(lockDir, { recursive: true, force: true }).catch(() => {
62
+ });
63
+ };
64
+ } catch (err) {
65
+ if (err?.code !== "EEXIST") {
66
+ throw err;
67
+ }
68
+ const lockTimeout = 10 * 60 * 1e3;
69
+ try {
70
+ const stats = await stat(lockDir);
71
+ if (Date.now() - stats.mtimeMs > lockTimeout) {
72
+ await rm(lockDir, { recursive: true, force: true }).catch(() => {
73
+ });
74
+ continue;
75
+ }
76
+ } catch {
77
+ }
78
+ if (Date.now() - startTime > lockTimeout) {
79
+ throw new Error(`Timed out waiting for Playwright install lock: ${lockDir}`);
80
+ }
81
+ await new Promise((resolve) => setTimeout(resolve, lockPoll));
82
+ }
83
+ }
84
+ }
85
+ export {
86
+ installPlaywright
87
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@arcgis/node-toolkit",
3
- "version": "5.2.0-next.79",
3
+ "version": "5.2.0-next.85",
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",
@@ -12,6 +12,7 @@
12
12
  "./packageJson": "./dist/packageJson.js",
13
13
  "./vite/presetPlugin": "./dist/vite/presetPlugin.js",
14
14
  "./vite/externalizeDependenciesPlugin": "./dist/vite/externalizeDependenciesPlugin.js",
15
+ "./vite/installPlaywright": "./dist/vite/installPlaywright.js",
15
16
  "./workspace": "./dist/workspace.js",
16
17
  "./package.json": "./package.json"
17
18
  },