create-curb 1.19.0-preview.4 → 1.20.0-preview.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.
package/RELEASE_NOTES.md CHANGED
@@ -1,12 +1,5 @@
1
1
 
2
- ### Added
3
-
4
- - Curb voices lists the voices, and curb check fails on a voice id it does not have (#85)
5
-
6
-
7
2
  ### Fixed
8
3
 
9
- - Pin every published runtime dependency to an exact version (#92)
10
- - Harden the dev server, static serving and diagnostics parsing (#83)
11
- - Validate local server origins and request targets (#81)
4
+ - Skip onnxruntime-node's extra downloads on install and hint the fix (#96)
12
5
 
@@ -20,6 +20,7 @@ import { fileURLToPath } from "node:url";
20
20
  import pc from "picocolors";
21
21
  import { blockedInstallScripts, installScriptsFix } from "./install-scripts.js";
22
22
  import { exitOnUnsupportedNode } from "./node-version.js";
23
+ import { installEnv, installFailureHint, readNpmConfig } from "./install-env.js";
23
24
  import { npmCommand } from "./npm-command.js";
24
25
  import { scaffoldArgs } from "./scaffold-args.js";
25
26
 
@@ -418,6 +419,9 @@ function gitInit() {
418
419
  }
419
420
  }
420
421
 
422
+ /** The environment npm install runs in: onnxruntime-node downloads skipped unless the project or user chose. */
423
+ const projectInstallEnv = () => installEnv(process.env, (key) => readNpmConfig(key, targetDir));
424
+
421
425
  /**
422
426
  * Animated install progress: spinner + what npm is fetching right now + an
423
427
  * elapsed-seconds counter, so a long install is never a silent wait.
@@ -425,6 +429,7 @@ function gitInit() {
425
429
  * instead and the current package name lifted from the fetch URLs.
426
430
  */
427
431
  function installWithSpinner() {
432
+ const env = projectInstallEnv(); // before the spinner, so its one-line note is not overwritten
428
433
  const frames = ["⠋", "⠙", "⠹", "⠸", "⠼", "⠴", "⠦", "⠧", "⠇", "⠏"];
429
434
  let at = 0;
430
435
  const started = Date.now();
@@ -449,7 +454,7 @@ function installWithSpinner() {
449
454
  resolveInstall(ok);
450
455
  };
451
456
  const npm = npmCommand("npm", ["install", "--loglevel=http", "--no-fund", "--no-audit"]);
452
- const child = spawn(npm.file, npm.args, { cwd: targetDir, shell: npm.shell });
457
+ const child = spawn(npm.file, npm.args, { cwd: targetDir, shell: npm.shell, env });
453
458
  const stderrLines = [];
454
459
  child.stderr.on("data", (chunk) => {
455
460
  const text = chunk.toString();
@@ -480,7 +485,7 @@ function installWithSpinner() {
480
485
  finish(
481
486
  false,
482
487
  `${pc.red("✖")} npm install failed ${pc.dim(`after ${elapsed()}s`)}`,
483
- `${tail}\nRun "npm install" inside ${targetArg} to see the full output.`,
488
+ `${tail}\nRun "npm install" inside ${targetArg} to see the full output.\n${installFailureHint(targetArg)}`,
484
489
  );
485
490
  });
486
491
  });
@@ -492,11 +497,11 @@ function installPlain() {
492
497
  try {
493
498
  // Warnings and errors only: no progress chatter, funding or audit summary.
494
499
  const npm = npmCommand("npm", ["install", "--loglevel=warn", "--no-fund", "--no-audit"]);
495
- execFileSync(npm.file, npm.args, { cwd: targetDir, stdio: "inherit", shell: npm.shell });
500
+ execFileSync(npm.file, npm.args, { cwd: targetDir, stdio: "inherit", shell: npm.shell, env: projectInstallEnv() });
496
501
  return true;
497
502
  } catch (error) {
498
503
  // npm printed its errors above; this names what failed and where to retry.
499
- console.error(`${pc.red("✖")} npm install failed (${error.message.split("\n")[0]}). Run "npm install" inside ${targetArg}.`);
504
+ console.error(`${pc.red("✖")} npm install failed (${error.message.split("\n")[0]}). Run "npm install" inside ${targetArg}.\n${installFailureHint(targetArg)}`);
500
505
  return false;
501
506
  }
502
507
  }
@@ -0,0 +1,63 @@
1
+ // onnxruntime-node's postinstall downloads extra binaries (GPU builds) from a host other than
2
+ // the npm registry. The agent does not need them, and on a network that allows only the
3
+ // registry the download fails and takes the whole npm install down with it. npm 10 runs the
4
+ // script even when package.json's allowScripts denies it, so the install skips the download
5
+ // through the package's own switches, unless the user already chose one.
6
+ import { execFileSync } from "node:child_process";
7
+ import { npmCommand } from "./npm-command.js";
8
+
9
+ /** The npm config keys onnxruntime-node's postinstall reads (as npm_config_<key>, dashes as
10
+ * underscores); the same two are read from the environment as ONNXRUNTIME_NODE_INSTALL[_CUDA]. */
11
+ export const INSTALL_PREFERENCE_KEYS = ["onnxruntime-node-install", "onnxruntime-node-install-cuda"];
12
+
13
+ const hasPreference = (env) =>
14
+ Object.entries(env).some(
15
+ ([name, value]) =>
16
+ value && /^(?:ONNXRUNTIME_NODE_INSTALL(?:_CUDA)?|npm_config_onnxruntime_node_install(?:_cuda)?)$/i.test(name),
17
+ );
18
+
19
+ /** The value npm resolves for a config key (environment, project and user .npmrc), or undefined
20
+ * when it is unset. Throws when npm cannot answer, for example inside an npm 10 workspace
21
+ * (ENOWORKSPACES). The workspace flags are no way round that: they answer "undefined" for a
22
+ * key the workspace root's .npmrc sets. */
23
+ export function readNpmConfig(key, cwd) {
24
+ const command = npmCommand("npm", ["config", "get", key]);
25
+ const value = execFileSync(command.file, command.args, {
26
+ cwd,
27
+ encoding: "utf8",
28
+ shell: command.shell,
29
+ stdio: ["ignore", "pipe", "ignore"],
30
+ }).trim();
31
+ return value && value !== "undefined" && value !== "null" ? value : undefined;
32
+ }
33
+
34
+ const LOOKUP_FAILED_NOTE =
35
+ "Could not read npm config, so the install keeps your onnxruntime-node settings as they are and may download extra binaries.";
36
+
37
+ /** The environment for `npm install`: the downloads are skipped, unless the user set a
38
+ * preference for them in the environment or in npm's config, which is then left alone. When
39
+ * npm's config cannot be read the preference is unknown, so nothing is injected and `note`
40
+ * gets one line saying so. */
41
+ export function installEnv(base = process.env, npmConfig = readNpmConfig, note = console.error) {
42
+ if (hasPreference(base)) return { ...base };
43
+ try {
44
+ if (INSTALL_PREFERENCE_KEYS.some((key) => npmConfig(key))) return { ...base };
45
+ } catch {
46
+ note(LOOKUP_FAILED_NOTE);
47
+ return { ...base };
48
+ }
49
+ return { ...base, ONNXRUNTIME_NODE_INSTALL: "skip", ONNXRUNTIME_NODE_INSTALL_CUDA: "skip" };
50
+ }
51
+
52
+ /** The lines printed after a failed install: the fix in the form of the user's shell. */
53
+ export function installFailureHint(targetArg, platform = process.platform) {
54
+ const head = `If a download was blocked by your network, run inside ${targetArg}:`;
55
+ if (platform === "win32") {
56
+ return [
57
+ head,
58
+ " Command Prompt: set ONNXRUNTIME_NODE_INSTALL=skip&& set ONNXRUNTIME_NODE_INSTALL_CUDA=skip&& npm install",
59
+ " PowerShell: $env:ONNXRUNTIME_NODE_INSTALL='skip'; $env:ONNXRUNTIME_NODE_INSTALL_CUDA='skip'; npm install",
60
+ ].join("\n");
61
+ }
62
+ return `${head} ONNXRUNTIME_NODE_INSTALL=skip ONNXRUNTIME_NODE_INSTALL_CUDA=skip npm install`;
63
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "create-curb",
3
- "version": "1.19.0-preview.4",
3
+ "version": "1.20.0-preview.1",
4
4
  "description": "Create a Curb voice agent with one command. The framework for production voice agents.",
5
5
  "keywords": [
6
6
  "curb",