@servicetitan/install 40.4.0 → 41.0.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.
Files changed (77) hide show
  1. package/dist/cli/install.d.ts +1 -1
  2. package/dist/cli/install.d.ts.map +1 -1
  3. package/dist/cli/install.js +16 -20
  4. package/dist/cli/install.js.map +1 -1
  5. package/dist/index.d.ts +1 -1
  6. package/dist/index.d.ts.map +1 -1
  7. package/dist/index.js +9 -0
  8. package/dist/index.js.map +1 -1
  9. package/dist/package-manager/npm-package-manager.d.ts +2 -0
  10. package/dist/package-manager/npm-package-manager.d.ts.map +1 -1
  11. package/dist/package-manager/npm-package-manager.js +36 -13
  12. package/dist/package-manager/npm-package-manager.js.map +1 -1
  13. package/dist/package-manager/package-manager.d.ts +8 -5
  14. package/dist/package-manager/package-manager.d.ts.map +1 -1
  15. package/dist/package-manager/package-manager.js +14 -5
  16. package/dist/package-manager/package-manager.js.map +1 -1
  17. package/dist/package-manager/pnpm-package-manager.d.ts +9 -1
  18. package/dist/package-manager/pnpm-package-manager.d.ts.map +1 -1
  19. package/dist/package-manager/pnpm-package-manager.js +80 -7
  20. package/dist/package-manager/pnpm-package-manager.js.map +1 -1
  21. package/dist/package-manager/utils/with-project-allow-scripts.js +1 -6
  22. package/dist/package-manager/utils/with-project-allow-scripts.js.map +1 -1
  23. package/dist/utils/audited-scripts.js +4 -4
  24. package/dist/utils/audited-scripts.js.map +1 -1
  25. package/dist/utils/index.d.ts +2 -0
  26. package/dist/utils/index.d.ts.map +1 -1
  27. package/dist/utils/index.js +1 -0
  28. package/dist/utils/index.js.map +1 -1
  29. package/dist/utils/npm/index.d.ts +4 -0
  30. package/dist/utils/npm/index.d.ts.map +1 -0
  31. package/dist/utils/npm/index.js +22 -0
  32. package/dist/utils/npm/index.js.map +1 -0
  33. package/dist/utils/npm/npm-config.d.ts +5 -0
  34. package/dist/utils/npm/npm-config.d.ts.map +1 -0
  35. package/dist/utils/npm/npm-config.js +112 -0
  36. package/dist/utils/npm/npm-config.js.map +1 -0
  37. package/dist/utils/npm/npm-get-local-prefix.d.ts +9 -0
  38. package/dist/utils/npm/npm-get-local-prefix.d.ts.map +1 -0
  39. package/dist/utils/npm/npm-get-local-prefix.js +65 -0
  40. package/dist/utils/npm/npm-get-local-prefix.js.map +1 -0
  41. package/dist/utils/npm/npm-who-am-i.d.ts +4 -0
  42. package/dist/utils/npm/npm-who-am-i.d.ts.map +1 -0
  43. package/dist/utils/npm/npm-who-am-i.js +37 -0
  44. package/dist/utils/npm/npm-who-am-i.js.map +1 -0
  45. package/dist/utils/os.d.ts +2 -2
  46. package/dist/utils/os.d.ts.map +1 -1
  47. package/dist/utils/os.js +22 -3
  48. package/dist/utils/os.js.map +1 -1
  49. package/dist/utils/pnpm.d.ts +5 -0
  50. package/dist/utils/pnpm.d.ts.map +1 -0
  51. package/dist/utils/pnpm.js +87 -0
  52. package/dist/utils/pnpm.js.map +1 -0
  53. package/dist/utils/setting.d.ts +6 -0
  54. package/dist/utils/setting.d.ts.map +1 -0
  55. package/dist/utils/setting.js +6 -0
  56. package/dist/utils/setting.js.map +1 -0
  57. package/package.json +2 -1
  58. package/src/cli/install.ts +12 -21
  59. package/src/index.ts +3 -0
  60. package/src/package-manager/npm-package-manager.ts +38 -19
  61. package/src/package-manager/package-manager.ts +22 -11
  62. package/src/package-manager/pnpm-package-manager.ts +96 -9
  63. package/src/package-manager/utils/with-project-allow-scripts.ts +2 -6
  64. package/src/utils/audited-scripts.ts +4 -4
  65. package/src/utils/index.ts +2 -0
  66. package/src/utils/npm/index.ts +3 -0
  67. package/src/utils/npm/npm-config.ts +83 -0
  68. package/src/utils/npm/npm-get-local-prefix.ts +63 -0
  69. package/src/utils/npm/npm-who-am-i.ts +18 -0
  70. package/src/utils/os.ts +12 -1
  71. package/src/utils/pnpm.ts +52 -0
  72. package/src/utils/setting.ts +5 -0
  73. package/dist/utils/npm.d.ts +0 -5
  74. package/dist/utils/npm.d.ts.map +0 -1
  75. package/dist/utils/npm.js +0 -77
  76. package/dist/utils/npm.js.map +0 -1
  77. package/src/utils/npm.ts +0 -44
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../src/utils/npm/npm-who-am-i.ts"],"sourcesContent":["import { debug } from '../debug';\nimport { runCommand } from '../os';\n\nexport function npmWhoAmI({ registry }: { registry?: string } = {}) {\n try {\n const result = runCommand(\n 'npm',\n ['whoami', ...(registry ? [`--registry=${registry}`] : [])],\n { stdio: ['pipe', 'pipe', 'ignore'], timeout: 10000 }\n ).trim();\n\n debug('install:whoami', { result });\n\n return result.trim();\n } catch {\n // ignore\n }\n}\n"],"names":["npmWhoAmI","registry","result","runCommand","stdio","timeout","trim","debug"],"mappings":";;;;+BAGgBA;;;eAAAA;;;uBAHM;oBACK;AAEpB,SAASA,UAAU,EAAEC,QAAQ,EAAyB,GAAG,CAAC,CAAC;IAC9D,IAAI;QACA,MAAMC,SAASC,IAAAA,cAAU,EACrB,OACA;YAAC;eAAcF,WAAW;gBAAC,CAAC,WAAW,EAAEA,UAAU;aAAC,GAAG,EAAE;SAAE,EAC3D;YAAEG,OAAO;gBAAC;gBAAQ;gBAAQ;aAAS;YAAEC,SAAS;QAAM,GACtDC,IAAI;QAENC,IAAAA,YAAK,EAAC,kBAAkB;YAAEL;QAAO;QAEjC,OAAOA,OAAOI,IAAI;IACtB,EAAE,eAAM;IACJ,SAAS;IACb;AACJ"}
@@ -1,5 +1,5 @@
1
1
  import { ExecSyncOptionsWithBufferEncoding } from 'child_process';
2
- type RunCommandOptions = ExecSyncOptionsWithBufferEncoding;
2
+ export type RunCommandOptions = ExecSyncOptionsWithBufferEncoding;
3
3
  export declare function runCommand(command: string, args: string[], options?: RunCommandOptions): string;
4
- export {};
4
+ export declare function getMissingConfigPath(): string;
5
5
  //# sourceMappingURL=os.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"os.d.ts","sourceRoot":"","sources":["../../src/utils/os.ts"],"names":[],"mappings":"AAAA,OAAO,EAAgB,iCAAiC,EAAE,MAAM,eAAe,CAAC;AAGhF,KAAK,iBAAiB,GAAG,iCAAiC,CAAC;AAE3D,wBAAgB,UAAU,CAAC,OAAO,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,EAAE,OAAO,GAAE,iBAAsB,UAG1F"}
1
+ {"version":3,"file":"os.d.ts","sourceRoot":"","sources":["../../src/utils/os.ts"],"names":[],"mappings":"AAAA,OAAO,EAAgB,iCAAiC,EAAE,MAAM,eAAe,CAAC;AAMhF,MAAM,MAAM,iBAAiB,GAAG,iCAAiC,CAAC;AAElE,wBAAgB,UAAU,CAAC,OAAO,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,EAAE,OAAO,GAAE,iBAAsB,UAG1F;AAiBD,wBAAgB,oBAAoB,WAMnC"}
package/dist/utils/os.js CHANGED
@@ -2,14 +2,30 @@
2
2
  Object.defineProperty(exports, "__esModule", {
3
3
  value: true
4
4
  });
5
- Object.defineProperty(exports, "runCommand", {
6
- enumerable: true,
7
- get: function() {
5
+ function _export(target, all) {
6
+ for(var name in all)Object.defineProperty(target, name, {
7
+ enumerable: true,
8
+ get: Object.getOwnPropertyDescriptor(all, name).get
9
+ });
10
+ }
11
+ _export(exports, {
12
+ get getMissingConfigPath () {
13
+ return getMissingConfigPath;
14
+ },
15
+ get runCommand () {
8
16
  return runCommand;
9
17
  }
10
18
  });
11
19
  const _child_process = require("child_process");
20
+ const _nodecrypto = require("node:crypto");
21
+ const _nodeos = /*#__PURE__*/ _interop_require_default(require("node:os"));
22
+ const _nodepath = /*#__PURE__*/ _interop_require_default(require("node:path"));
12
23
  const _debug = require("./debug");
24
+ function _interop_require_default(obj) {
25
+ return obj && obj.__esModule ? obj : {
26
+ default: obj
27
+ };
28
+ }
13
29
  function runCommand(command, args, options = {}) {
14
30
  var _ref;
15
31
  var _execFileSync;
@@ -40,5 +56,8 @@ function getWindowsOptions(command) {
40
56
  };
41
57
  }
42
58
  }
59
+ function getMissingConfigPath() {
60
+ return _nodepath.default.join(_nodeos.default.tmpdir(), 'servicetitan-install-missing-config', (0, _nodecrypto.randomBytes)(16).toString('hex'));
61
+ }
43
62
 
44
63
  //# sourceMappingURL=os.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/utils/os.ts"],"sourcesContent":["import { execFileSync, ExecSyncOptionsWithBufferEncoding } from 'child_process';\nimport { debug } from './debug';\n\ntype RunCommandOptions = ExecSyncOptionsWithBufferEncoding;\n\nexport function runCommand(command: string, args: string[], options: RunCommandOptions = {}) {\n debug('install:run', { command, args, options });\n return execFileSync(command, args, getOptions(command, options))?.toString() ?? '';\n}\n\nfunction getOptions(command: string, options: RunCommandOptions) {\n return {\n ...getWindowsOptions(command),\n ...options,\n ...(options.env ? { env: { ...process.env, ...options.env } } : {}),\n };\n}\n\nfunction getWindowsOptions(command: string) {\n // On Windows, npm and pnpm are command scripts (e.g., npm.CMD) that requires a shell\n if (process.platform === 'win32' && (command === 'npm' || command === 'pnpm')) {\n return { shell: true };\n }\n}\n"],"names":["runCommand","command","args","options","execFileSync","debug","getOptions","toString","getWindowsOptions","env","process","platform","shell"],"mappings":";;;;+BAKgBA;;;eAAAA;;;+BALgD;uBAC1C;AAIf,SAASA,WAAWC,OAAe,EAAEC,IAAc,EAAEC,UAA6B,CAAC,CAAC;;QAEhFC;IADPC,IAAAA,YAAK,EAAC,eAAe;QAAEJ;QAASC;QAAMC;IAAQ;IAC9C,gBAAOC,gBAAAA,IAAAA,2BAAY,EAACH,SAASC,MAAMI,WAAWL,SAASE,uBAAhDC,oCAAAA,cAA2DG,QAAQ,yCAAM;AACpF;AAEA,SAASD,WAAWL,OAAe,EAAEE,OAA0B;IAC3D,OAAO;QACH,GAAGK,kBAAkBP,QAAQ;QAC7B,GAAGE,OAAO;QACV,GAAIA,QAAQM,GAAG,GAAG;YAAEA,KAAK;gBAAE,GAAGC,QAAQD,GAAG;gBAAE,GAAGN,QAAQM,GAAG;YAAC;QAAE,IAAI,CAAC,CAAC;IACtE;AACJ;AAEA,SAASD,kBAAkBP,OAAe;IACtC,qFAAqF;IACrF,IAAIS,QAAQC,QAAQ,KAAK,WAAYV,CAAAA,YAAY,SAASA,YAAY,MAAK,GAAI;QAC3E,OAAO;YAAEW,OAAO;QAAK;IACzB;AACJ"}
1
+ {"version":3,"sources":["../../src/utils/os.ts"],"sourcesContent":["import { execFileSync, ExecSyncOptionsWithBufferEncoding } from 'child_process';\nimport { randomBytes } from 'node:crypto';\nimport os from 'node:os';\nimport path from 'node:path';\nimport { debug } from './debug';\n\nexport type RunCommandOptions = ExecSyncOptionsWithBufferEncoding;\n\nexport function runCommand(command: string, args: string[], options: RunCommandOptions = {}) {\n debug('install:run', { command, args, options });\n return execFileSync(command, args, getOptions(command, options))?.toString() ?? '';\n}\n\nfunction getOptions(command: string, options: RunCommandOptions) {\n return {\n ...getWindowsOptions(command),\n ...options,\n ...(options.env ? { env: { ...process.env, ...options.env } } : {}),\n };\n}\n\nfunction getWindowsOptions(command: string) {\n // On Windows, npm and pnpm are command scripts (e.g., npm.CMD) that requires a shell\n if (process.platform === 'win32' && (command === 'npm' || command === 'pnpm')) {\n return { shell: true };\n }\n}\n\nexport function getMissingConfigPath() {\n return path.join(\n os.tmpdir(),\n 'servicetitan-install-missing-config',\n randomBytes(16).toString('hex')\n );\n}\n"],"names":["getMissingConfigPath","runCommand","command","args","options","execFileSync","debug","getOptions","toString","getWindowsOptions","env","process","platform","shell","path","join","os","tmpdir","randomBytes"],"mappings":";;;;;;;;;;;QA4BgBA;eAAAA;;QApBAC;eAAAA;;;+BARgD;4BACpC;+DACb;iEACE;uBACK;;;;;;AAIf,SAASA,WAAWC,OAAe,EAAEC,IAAc,EAAEC,UAA6B,CAAC,CAAC;;QAEhFC;IADPC,IAAAA,YAAK,EAAC,eAAe;QAAEJ;QAASC;QAAMC;IAAQ;IAC9C,gBAAOC,gBAAAA,IAAAA,2BAAY,EAACH,SAASC,MAAMI,WAAWL,SAASE,uBAAhDC,oCAAAA,cAA2DG,QAAQ,yCAAM;AACpF;AAEA,SAASD,WAAWL,OAAe,EAAEE,OAA0B;IAC3D,OAAO;QACH,GAAGK,kBAAkBP,QAAQ;QAC7B,GAAGE,OAAO;QACV,GAAIA,QAAQM,GAAG,GAAG;YAAEA,KAAK;gBAAE,GAAGC,QAAQD,GAAG;gBAAE,GAAGN,QAAQM,GAAG;YAAC;QAAE,IAAI,CAAC,CAAC;IACtE;AACJ;AAEA,SAASD,kBAAkBP,OAAe;IACtC,qFAAqF;IACrF,IAAIS,QAAQC,QAAQ,KAAK,WAAYV,CAAAA,YAAY,SAASA,YAAY,MAAK,GAAI;QAC3E,OAAO;YAAEW,OAAO;QAAK;IACzB;AACJ;AAEO,SAASb;IACZ,OAAOc,iBAAI,CAACC,IAAI,CACZC,eAAE,CAACC,MAAM,IACT,uCACAC,IAAAA,uBAAW,EAAC,IAAIV,QAAQ,CAAC;AAEjC"}
@@ -0,0 +1,5 @@
1
+ export type PnpmConfigLocation = 'project' | 'global';
2
+ export declare function pnpmGetProjectConfig(key: string): unknown;
3
+ export declare function pnpmGetGlobalConfig(key: string): unknown;
4
+ export declare function pnpmSetConfig(location: PnpmConfigLocation, args: string[]): void;
5
+ //# sourceMappingURL=pnpm.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"pnpm.d.ts","sourceRoot":"","sources":["../../src/utils/pnpm.ts"],"names":[],"mappings":"AAIA,MAAM,MAAM,kBAAkB,GAAG,SAAS,GAAG,QAAQ,CAAC;AAEtD,wBAAgB,oBAAoB,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAYzD;AAED,wBAAgB,mBAAmB,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAGxD;AAmBD,wBAAgB,aAAa,CAAC,QAAQ,EAAE,kBAAkB,EAAE,IAAI,EAAE,MAAM,EAAE,QAKzE"}
@@ -0,0 +1,87 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", {
3
+ value: true
4
+ });
5
+ function _export(target, all) {
6
+ for(var name in all)Object.defineProperty(target, name, {
7
+ enumerable: true,
8
+ get: Object.getOwnPropertyDescriptor(all, name).get
9
+ });
10
+ }
11
+ _export(exports, {
12
+ get pnpmGetGlobalConfig () {
13
+ return pnpmGetGlobalConfig;
14
+ },
15
+ get pnpmGetProjectConfig () {
16
+ return pnpmGetProjectConfig;
17
+ },
18
+ get pnpmSetConfig () {
19
+ return pnpmSetConfig;
20
+ }
21
+ });
22
+ const _nodeos = /*#__PURE__*/ _interop_require_default(require("node:os"));
23
+ const _findworkspaceroot = require("./find-workspace-root");
24
+ const _os = require("./os");
25
+ function _interop_require_default(obj) {
26
+ return obj && obj.__esModule ? obj : {
27
+ default: obj
28
+ };
29
+ }
30
+ function pnpmGetProjectConfig(key) {
31
+ return pnpmGetConfig(key, {
32
+ cwd: getWorkspaceDir(),
33
+ env: {
34
+ // pnpm skips config paths that don't exist
35
+ /* eslint-disable @typescript-eslint/naming-convention */ XDG_CONFIG_HOME: (0, _os.getMissingConfigPath)(),
36
+ npm_config_globalconfig: (0, _os.getMissingConfigPath)(),
37
+ npm_config_userconfig: (0, _os.getMissingConfigPath)()
38
+ }
39
+ });
40
+ }
41
+ function pnpmGetGlobalConfig(key) {
42
+ // Outside the project, so the project's config doesn't affect the result
43
+ return pnpmGetConfig(key, {
44
+ cwd: _nodeos.default.homedir()
45
+ });
46
+ }
47
+ function pnpmGetConfig(key, options) {
48
+ const envKey = key.replaceAll(/[A-Z]/g, (letter)=>`_${letter.toLowerCase()}`);
49
+ const result = (0, _os.runCommand)('pnpm', [
50
+ 'config',
51
+ 'get',
52
+ '--json',
53
+ key
54
+ ], {
55
+ ...options,
56
+ env: {
57
+ ...options.env,
58
+ // Environment variables override configuration files
59
+ [`npm_config_${envKey}`]: undefined,
60
+ [`pnpm_config_${envKey}`]: undefined
61
+ },
62
+ stdio: [
63
+ 'pipe',
64
+ 'pipe',
65
+ 'ignore'
66
+ ]
67
+ }).trim();
68
+ // pnpm prints nothing for unset settings
69
+ return result ? JSON.parse(result) : undefined;
70
+ }
71
+ function pnpmSetConfig(location, args) {
72
+ (0, _os.runCommand)('pnpm', [
73
+ 'config',
74
+ 'set',
75
+ `--location=${location}`,
76
+ ...args
77
+ ], {
78
+ // In a workspace package, pnpm 11 writes project config to the package but reads it from the root
79
+ cwd: location === 'project' ? getWorkspaceDir() : undefined
80
+ });
81
+ }
82
+ function getWorkspaceDir() {
83
+ var _findWorkspaceRoot;
84
+ return (_findWorkspaceRoot = (0, _findworkspaceroot.findWorkspaceRoot)()) !== null && _findWorkspaceRoot !== void 0 ? _findWorkspaceRoot : process.cwd();
85
+ }
86
+
87
+ //# sourceMappingURL=pnpm.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/utils/pnpm.ts"],"sourcesContent":["import os from 'node:os';\nimport { findWorkspaceRoot } from './find-workspace-root';\nimport { getMissingConfigPath, runCommand } from './os';\n\nexport type PnpmConfigLocation = 'project' | 'global';\n\nexport function pnpmGetProjectConfig(key: string): unknown {\n return pnpmGetConfig(key, {\n cwd: getWorkspaceDir(),\n env: {\n // pnpm skips config paths that don't exist\n /* eslint-disable @typescript-eslint/naming-convention */\n XDG_CONFIG_HOME: getMissingConfigPath(),\n npm_config_globalconfig: getMissingConfigPath(),\n npm_config_userconfig: getMissingConfigPath(),\n /* eslint-enable @typescript-eslint/naming-convention */\n },\n });\n}\n\nexport function pnpmGetGlobalConfig(key: string): unknown {\n // Outside the project, so the project's config doesn't affect the result\n return pnpmGetConfig(key, { cwd: os.homedir() });\n}\n\nfunction pnpmGetConfig(key: string, options: NonNullable<Parameters<typeof runCommand>[2]>) {\n const envKey = key.replaceAll(/[A-Z]/g, letter => `_${letter.toLowerCase()}`);\n const result = runCommand('pnpm', ['config', 'get', '--json', key], {\n ...options,\n env: {\n ...options.env,\n // Environment variables override configuration files\n [`npm_config_${envKey}`]: undefined,\n [`pnpm_config_${envKey}`]: undefined,\n },\n stdio: ['pipe', 'pipe', 'ignore'],\n }).trim();\n\n // pnpm prints nothing for unset settings\n return result ? JSON.parse(result) : undefined;\n}\n\nexport function pnpmSetConfig(location: PnpmConfigLocation, args: string[]) {\n runCommand('pnpm', ['config', 'set', `--location=${location}`, ...args], {\n // In a workspace package, pnpm 11 writes project config to the package but reads it from the root\n cwd: location === 'project' ? getWorkspaceDir() : undefined,\n });\n}\n\nfunction getWorkspaceDir() {\n return findWorkspaceRoot() ?? process.cwd();\n}\n"],"names":["pnpmGetGlobalConfig","pnpmGetProjectConfig","pnpmSetConfig","key","pnpmGetConfig","cwd","getWorkspaceDir","env","XDG_CONFIG_HOME","getMissingConfigPath","npm_config_globalconfig","npm_config_userconfig","os","homedir","options","envKey","replaceAll","letter","toLowerCase","result","runCommand","undefined","stdio","trim","JSON","parse","location","args","findWorkspaceRoot","process"],"mappings":";;;;;;;;;;;QAoBgBA;eAAAA;;QAdAC;eAAAA;;QAoCAC;eAAAA;;;+DA1CD;mCACmB;oBACe;;;;;;AAI1C,SAASD,qBAAqBE,GAAW;IAC5C,OAAOC,cAAcD,KAAK;QACtBE,KAAKC;QACLC,KAAK;YACD,2CAA2C;YAC3C,uDAAuD,GACvDC,iBAAiBC,IAAAA,wBAAoB;YACrCC,yBAAyBD,IAAAA,wBAAoB;YAC7CE,uBAAuBF,IAAAA,wBAAoB;QAE/C;IACJ;AACJ;AAEO,SAAST,oBAAoBG,GAAW;IAC3C,yEAAyE;IACzE,OAAOC,cAAcD,KAAK;QAAEE,KAAKO,eAAE,CAACC,OAAO;IAAG;AAClD;AAEA,SAAST,cAAcD,GAAW,EAAEW,OAAsD;IACtF,MAAMC,SAASZ,IAAIa,UAAU,CAAC,UAAUC,CAAAA,SAAU,CAAC,CAAC,EAAEA,OAAOC,WAAW,IAAI;IAC5E,MAAMC,SAASC,IAAAA,cAAU,EAAC,QAAQ;QAAC;QAAU;QAAO;QAAUjB;KAAI,EAAE;QAChE,GAAGW,OAAO;QACVP,KAAK;YACD,GAAGO,QAAQP,GAAG;YACd,qDAAqD;YACrD,CAAC,CAAC,WAAW,EAAEQ,QAAQ,CAAC,EAAEM;YAC1B,CAAC,CAAC,YAAY,EAAEN,QAAQ,CAAC,EAAEM;QAC/B;QACAC,OAAO;YAAC;YAAQ;YAAQ;SAAS;IACrC,GAAGC,IAAI;IAEP,yCAAyC;IACzC,OAAOJ,SAASK,KAAKC,KAAK,CAACN,UAAUE;AACzC;AAEO,SAASnB,cAAcwB,QAA4B,EAAEC,IAAc;IACtEP,IAAAA,cAAU,EAAC,QAAQ;QAAC;QAAU;QAAO,CAAC,WAAW,EAAEM,UAAU;WAAKC;KAAK,EAAE;QACrE,kGAAkG;QAClGtB,KAAKqB,aAAa,YAAYpB,oBAAoBe;IACtD;AACJ;AAEA,SAASf;QACEsB;IAAP,QAAOA,qBAAAA,IAAAA,oCAAiB,iBAAjBA,gCAAAA,qBAAuBC,QAAQxB,GAAG;AAC7C"}
@@ -0,0 +1,6 @@
1
+ export interface Setting {
2
+ description: string;
3
+ isSet(): boolean;
4
+ set(): void;
5
+ }
6
+ //# sourceMappingURL=setting.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"setting.d.ts","sourceRoot":"","sources":["../../src/utils/setting.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,OAAO;IACpB,WAAW,EAAE,MAAM,CAAC;IACpB,KAAK,IAAI,OAAO,CAAC;IACjB,GAAG,IAAI,IAAI,CAAC;CACf"}
@@ -0,0 +1,6 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", {
3
+ value: true
4
+ });
5
+
6
+ //# sourceMappingURL=setting.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/utils/setting.ts"],"names":[],"mappings":""}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@servicetitan/install",
3
- "version": "40.4.0",
3
+ "version": "41.0.0",
4
4
  "description": "Lightweight wrapper around npm install that configures access to private packages",
5
5
  "homepage": "https://docs.st.dev/docs/frontend/uikit/install",
6
6
  "repository": {
@@ -41,6 +41,7 @@
41
41
  }
42
42
  },
43
43
  "devDependencies": {
44
+ "js-yaml": "~5.5.0",
44
45
  "ts-node": "~10.9.2"
45
46
  }
46
47
  }
@@ -1,19 +1,10 @@
1
1
  /* eslint-disable no-console */
2
- import fs from 'fs';
3
- import os from 'os';
4
- import path from 'path';
2
+ import fs from 'node:fs';
3
+ import os from 'node:os';
4
+ import path from 'node:path';
5
5
  import type { AllowScripts } from '../package-manager';
6
6
  import { getPackageManager, PackageManager } from '../package-manager';
7
- import {
8
- debug,
9
- getVersion,
10
- gitCloneRepo,
11
- isCI,
12
- npmGetUserConfig,
13
- npmWhoAmI,
14
- readJson,
15
- runCommand,
16
- } from '../utils';
7
+ import { debug, getVersion, gitCloneRepo, isCI, npmWhoAmI, readJson, runCommand } from '../utils';
17
8
 
18
9
  const REPO_NAME = 'frontend-dev-config';
19
10
  const AUTH_TOKEN_KEY = '//registry.npmjs.org/:_authToken';
@@ -39,26 +30,26 @@ export class Install {
39
30
  execute() {
40
31
  this.log(`install cli v${getVersion()}`);
41
32
 
42
- this.configureNpx();
33
+ this.configureSettings();
43
34
  const env = this.configureNpmToken();
44
35
  this.installPackages(env);
45
36
  }
46
37
 
47
- private configureNpx() {
38
+ private configureSettings() {
48
39
  if (isCI() || this.args.fix) {
49
40
  return;
50
41
  }
51
42
 
52
43
  try {
53
- if (npmGetUserConfig('yes') !== undefined) {
54
- return;
44
+ for (const setting of this.packageManager.getRecommendedSettings(this.args)) {
45
+ if (!setting.isSet()) {
46
+ this.log(`Setting ${setting.description} ...`);
47
+ setting.set();
48
+ }
55
49
  }
56
-
57
- this.log('Configuring npx to require confirmation ...');
58
- runCommand('npm', ['config', 'set', 'yes=false', '--location=user']);
59
50
  } catch (e) {
60
51
  console.warn(String(e));
61
- console.warn('Failed to configure npx to require confirmation');
52
+ console.warn('Failed to configure recommended package manager settings');
62
53
  }
63
54
  }
64
55
 
package/src/index.ts CHANGED
@@ -5,7 +5,10 @@ export {
5
5
  gitCloneRepo,
6
6
  gitIsReachable,
7
7
  isCI,
8
+ npmGetLocalPrefix,
9
+ npmGetProjectConfig,
8
10
  npmWhoAmI,
11
+ pnpmGetProjectConfig,
9
12
  versionCompare,
10
13
  } from './utils';
11
14
  export type { AuditedScript } from './utils';
@@ -1,10 +1,11 @@
1
1
  /* eslint-disable no-console */
2
- import fs from 'fs';
2
+ import fs from 'node:fs';
3
3
  import {
4
4
  AUDITED_SCRIPTS,
5
5
  getPackagesWithInstallScripts,
6
6
  isCI,
7
7
  runCommand,
8
+ toNpmConfigSettings,
8
9
  versionCompare,
9
10
  warnUntrustedInstallScripts,
10
11
  } from '../utils';
@@ -21,7 +22,11 @@ import {
21
22
  withProjectAllowScripts,
22
23
  } from './utils';
23
24
 
24
- const MIN_NPM_VERSION_FOR_RELEASE_AGE = '11.10.0';
25
+ /*
26
+ * npm added `min-release-age-exclude` in 11.17.0. Earlier versions reject it
27
+ * through `npm config set` and ignore manually configured values.
28
+ */
29
+ const MIN_NPM_VERSION_FOR_RELEASE_AGE = '11.17.0';
25
30
 
26
31
  interface NpmLockFileEntry {
27
32
  version?: string;
@@ -52,6 +57,10 @@ export class NpmPackageManager extends PackageManager<NpmLockFile> {
52
57
  return entry?.dependencies?.[dependency] ?? entry?.peerDependencies?.[dependency];
53
58
  }
54
59
 
60
+ getRecommendedSettings(args: InstallArgs) {
61
+ return toNpmConfigSettings(['yes=false', ...this.getMinReleaseAgeSettings(args)]);
62
+ }
63
+
55
64
  getResolvedVersion({ workspacePackage, dependency }: ResolvedVersionQuery): string | undefined {
56
65
  return this.findEntry({ workspacePackage, package: dependency })?.version;
57
66
  }
@@ -160,9 +169,12 @@ export class NpmPackageManager extends PackageManager<NpmLockFile> {
160
169
  workspacePackage,
161
170
  package: packageName,
162
171
  }: {
163
- workspacePackage: string;
172
+ workspacePackage: string | undefined;
164
173
  package: string;
165
174
  }): NpmLockFileEntry | undefined {
175
+ if (workspacePackage === undefined) {
176
+ return undefined;
177
+ }
166
178
  const packages = this.getLockFile()?.packages;
167
179
  const entry =
168
180
  packages?.[`${workspacePackage}/node_modules/${packageName}`] ??
@@ -198,35 +210,42 @@ export class NpmPackageManager extends PackageManager<NpmLockFile> {
198
210
  const version = runCommand(this.command, ['--version']).trim();
199
211
  if (versionCompare(version, MIN_NPM_VERSION_FOR_RELEASE_AGE) < 0) {
200
212
  console.warn(
201
- `WARNING: npm ${version} does not support minimum release age protection. Installing without it.`
213
+ `WARNING: npm ${version} does not support minimum release age exclusions. Installing without minimum release age protection.`
202
214
  );
203
215
  return [];
204
216
  }
205
217
 
218
+ const excludeFlags = resolved.exclude.map(
219
+ pattern => `--min-release-age-exclude=${pattern}`
220
+ );
206
221
  if (this.hasConfiguredMinReleaseAge()) {
207
222
  return [];
208
223
  }
209
224
 
210
- return [
211
- `--min-release-age=${resolved.days}`,
212
- ...resolved.exclude.map(pattern => `--min-release-age-exclude=${pattern}`),
213
- ];
225
+ return [`--min-release-age=${resolved.days}`, ...excludeFlags];
226
+ }
227
+
228
+ private getMinReleaseAgeSettings(args: InstallArgs): string[] {
229
+ const resolved = resolveMinReleaseAge(args.minReleaseAge);
230
+ if (!resolved) {
231
+ return [];
232
+ }
233
+
234
+ const version = runCommand(this.command, ['--version']).trim();
235
+ if (versionCompare(version, MIN_NPM_VERSION_FOR_RELEASE_AGE) < 0) {
236
+ return [];
237
+ }
238
+
239
+ const excludeSettings = resolved.exclude.map(
240
+ pattern => `min-release-age-exclude=${pattern}`
241
+ );
242
+ return [`min-release-age=${resolved.days}`, ...excludeSettings];
214
243
  }
215
244
 
216
245
  private hasConfiguredMinReleaseAge(): boolean {
217
246
  try {
218
247
  const config = JSON.parse(runCommand(this.command, ['config', 'list', '--json']));
219
- if (Number(config['min-release-age']) > 0) {
220
- return true;
221
- }
222
- /*
223
- * On npm >=11.10.0 <11.14.0, min-release-age is flattened into an
224
- * absolute `before` cutoff date and removed from the config, so
225
- * fall back to checking that cutoff instead.
226
- */
227
- return (
228
- typeof config.before === 'string' && new Date(config.before).getTime() < Date.now()
229
- );
248
+ return Number(config['min-release-age']) > 0;
230
249
  } catch {
231
250
  return false;
232
251
  }
@@ -1,6 +1,6 @@
1
- import fs from 'fs';
1
+ import fs from 'node:fs';
2
2
  import path from 'node:path';
3
- import { findUp, runCommand } from '../utils';
3
+ import { findUp, runCommand, Setting } from '../utils';
4
4
 
5
5
  export type AllowScripts = true | false | string[];
6
6
 
@@ -12,13 +12,13 @@ export interface InstallArgs {
12
12
  }
13
13
 
14
14
  export interface DeclaredVersionQuery {
15
- workspacePackage: string;
15
+ workspacePackage: string | undefined;
16
16
  declaredBy: string;
17
17
  dependency: string;
18
18
  }
19
19
 
20
20
  export interface ResolvedVersionQuery {
21
- workspacePackage: string;
21
+ workspacePackage: string | undefined;
22
22
  dependency: string;
23
23
  }
24
24
 
@@ -49,18 +49,29 @@ export abstract class PackageManager<LockFile = unknown> {
49
49
  /**
50
50
  * Returns the lockfile key for a package given its absolute or
51
51
  * cwd-relative directory. Both npm and pnpm key their lockfile entries
52
- * by the package's path relative to the workspace root.
52
+ * by the package's path relative to the workspace root. Returns undefined
53
+ * for a directory outside the lockfile's directory, which the lockfile
54
+ * doesn't describe.
53
55
  */
54
- getWorkspacePackage(packageDir = process.cwd()): string {
56
+ getWorkspacePackage(packageDir = process.cwd()): string | undefined {
55
57
  const lockFilePath = this.getLockFilePath();
56
58
  if (!lockFilePath) {
57
59
  return this.rootWorkspacePackage;
58
60
  }
59
- const relative = path
60
- .relative(path.dirname(lockFilePath), path.resolve(packageDir))
61
- .split(path.sep)
62
- .join('/');
63
- return relative === '' ? this.rootWorkspacePackage : relative;
61
+ const relative = path.relative(path.dirname(lockFilePath), path.resolve(packageDir));
62
+ if (
63
+ relative === '..' ||
64
+ relative.startsWith(`..${path.sep}`) ||
65
+ // path.relative returns an absolute path for a directory on another Windows drive
66
+ path.isAbsolute(relative)
67
+ ) {
68
+ return undefined;
69
+ }
70
+ return relative === '' ? this.rootWorkspacePackage : relative.split(path.sep).join('/');
71
+ }
72
+
73
+ getRecommendedSettings(_args: InstallArgs): Setting[] {
74
+ return [];
64
75
  }
65
76
 
66
77
  protected getLockFile(): LockFile | undefined {
@@ -1,11 +1,22 @@
1
1
  /* eslint-disable no-console */
2
- import fs from 'fs';
3
- import { isCI, runCommand, versionCompare } from '../utils';
2
+ import type * as Yaml from 'js-yaml';
3
+ import fs from 'node:fs';
4
+ import {
5
+ isCI,
6
+ pnpmGetGlobalConfig,
7
+ pnpmGetProjectConfig,
8
+ pnpmSetConfig,
9
+ runCommand,
10
+ Setting,
11
+ toNpmConfigSettings,
12
+ versionCompare,
13
+ } from '../utils';
4
14
  import type { DeclaredVersionQuery, InstallArgs, ResolvedVersionQuery } from './package-manager';
5
15
  import { PackageManager } from './package-manager';
6
16
  import { resolveMinReleaseAge } from './utils';
7
17
 
8
18
  const MIN_PNPM_VERSION_FOR_RELEASE_AGE = '10.16.0';
19
+ const MINUTES_PER_DAY = 24 * 60;
9
20
 
10
21
  interface PnpmImporterEntry {
11
22
  specifier: string;
@@ -53,6 +64,11 @@ export class PnpmPackageManager extends PackageManager<PnpmLockFile> {
53
64
  return snapshot?.dependencies?.[dependency] ?? snapshot?.peerDependencies?.[dependency];
54
65
  }
55
66
 
67
+ getRecommendedSettings(args: InstallArgs) {
68
+ // npx is part of npm, so it reads npm's config even in pnpm projects
69
+ return [...toNpmConfigSettings(['yes=false']), ...this.getMinReleaseAgeSettings(args)];
70
+ }
71
+
56
72
  getResolvedVersion({ workspacePackage, dependency }: ResolvedVersionQuery): string | undefined {
57
73
  return this.resolveVersion(workspacePackage, dependency);
58
74
  }
@@ -84,20 +100,72 @@ export class PnpmPackageManager extends PackageManager<PnpmLockFile> {
84
100
  * js-yaml is an optional peer; let MODULE_NOT_FOUND surface so a caller
85
101
  * missing the dep gets a clear error instead of silent `undefined`.
86
102
  */
87
- const yaml = require('js-yaml');
103
+ const yaml: typeof Yaml = require('js-yaml');
88
104
  try {
89
- return yaml.load(fs.readFileSync(lockFilePath, 'utf-8'));
105
+ return yaml.load(fs.readFileSync(lockFilePath, 'utf-8')) as PnpmLockFile;
90
106
  } catch {
91
107
  return undefined;
92
108
  }
93
109
  }
94
110
 
95
- private resolveVersion(workspacePackage: string, dependency: string): string | undefined {
96
- const importer = this.getLockFile()?.importers?.[workspacePackage];
111
+ private getMinReleaseAgeSettings(args: InstallArgs): Setting[] {
112
+ const resolved = resolveMinReleaseAge(args.minReleaseAge);
113
+ if (!resolved) {
114
+ return [];
115
+ }
116
+
117
+ const version = runCommand(this.command, ['--version']).trim();
118
+ if (versionCompare(version, MIN_PNPM_VERSION_FOR_RELEASE_AGE) < 0) {
119
+ return [];
120
+ }
121
+
122
+ return (['project', 'global'] as const).flatMap(location => {
123
+ const getConfig = location === 'project' ? pnpmGetProjectConfig : pnpmGetGlobalConfig;
124
+ return [
125
+ {
126
+ description: `minimumReleaseAge in pnpm ${location} config`,
127
+ isSet: () => getConfig('minimumReleaseAge') !== undefined,
128
+ set: () =>
129
+ pnpmSetConfig(location, [
130
+ 'minimumReleaseAge',
131
+ String(resolved.days * MINUTES_PER_DAY),
132
+ ]),
133
+ },
134
+ {
135
+ description: `minimumReleaseAgeExclude in pnpm ${location} config`,
136
+ isSet: () => getConfig('minimumReleaseAgeExclude') !== undefined,
137
+ set: () =>
138
+ pnpmSetConfig(location, [
139
+ '--json',
140
+ 'minimumReleaseAgeExclude',
141
+ toJsonArg(resolved.exclude),
142
+ ]),
143
+ },
144
+ ];
145
+ });
146
+ }
147
+
148
+ /**
149
+ * Returns the version of a dependency that a workspace package resolves to. When the package
150
+ * doesn't declare the dependency itself, it resolves through the root's node_modules, so this
151
+ * falls back to the root workspace's dependencies. Packages outside the workspace get no
152
+ * fallback.
153
+ */
154
+ private resolveVersion(
155
+ workspacePackage: string | undefined,
156
+ dependency: string
157
+ ): string | undefined {
158
+ if (workspacePackage === undefined) {
159
+ return undefined;
160
+ }
161
+ const importers = this.getLockFile()?.importers;
162
+ const importer = importers?.[workspacePackage];
163
+ if (!importer) {
164
+ return undefined;
165
+ }
97
166
  const entry =
98
- importer?.dependencies?.[dependency] ??
99
- importer?.devDependencies?.[dependency] ??
100
- importer?.optionalDependencies?.[dependency];
167
+ findImporterEntry(importer, dependency) ??
168
+ findImporterEntry(importers[this.rootWorkspacePackage], dependency);
101
169
  return entry ? stripPeerDependencySuffix(entry.version) : undefined;
102
170
  }
103
171
 
@@ -142,6 +210,25 @@ export class PnpmPackageManager extends PackageManager<PnpmLockFile> {
142
210
  }
143
211
  }
144
212
 
213
+ function findImporterEntry(importer: PnpmImporter | undefined, dependency: string) {
214
+ return (
215
+ importer?.dependencies?.[dependency] ??
216
+ importer?.devDependencies?.[dependency] ??
217
+ importer?.optionalDependencies?.[dependency]
218
+ );
219
+ }
220
+
221
+ function toJsonArg(value: unknown) {
222
+ const json = JSON.stringify(value);
223
+ if (process.platform !== 'win32') {
224
+ return json;
225
+ }
226
+
227
+ // On Windows, pnpm runs through a shell that strips unescaped double quotes
228
+ const escapedJson = json.replaceAll('"', String.raw`\"`);
229
+ return `"${escapedJson}"`;
230
+ }
231
+
145
232
  function stripPeerDependencySuffix(version: string): string {
146
233
  // e.g., "1.2.3(react@18.2.0)(react-dom@18.2.0)" → "1.2.3"
147
234
  return version.split('(')[0];
@@ -1,6 +1,6 @@
1
1
  import fs from 'fs';
2
2
  import path from 'path';
3
- import { runCommand } from '../../utils';
3
+ import { npmGetLocalPrefix, runCommand } from '../../utils';
4
4
 
5
5
  const NPM = 'npm';
6
6
 
@@ -9,7 +9,7 @@ export function withProjectAllowScripts<T>(scripts: string[], fn: () => T): T {
9
9
  return fn();
10
10
  }
11
11
 
12
- const packageJsonPath = path.join(getNpmPrefix(), 'package.json');
12
+ const packageJsonPath = path.join(npmGetLocalPrefix(), 'package.json');
13
13
  const backupPath = `${packageJsonPath}.bak`;
14
14
  const original = fs.readFileSync(packageJsonPath, 'utf-8');
15
15
  fs.copyFileSync(packageJsonPath, backupPath);
@@ -27,10 +27,6 @@ function getNpmVersion(): string {
27
27
  return runCommand(NPM, ['--version']).trim();
28
28
  }
29
29
 
30
- function getNpmPrefix(): string {
31
- return runCommand(NPM, ['prefix']).trim();
32
- }
33
-
34
30
  function buildPackageJsonWithAllowScripts(original: string, scripts: string[]): string {
35
31
  const packageJson = JSON.parse(original);
36
32
  const allowed = Object.fromEntries(scripts.map(name => [name, true]));
@@ -14,18 +14,18 @@ export const AUDITED_SCRIPTS: AuditedScript[] = [
14
14
  },
15
15
  {
16
16
  name: 'cypress',
17
- maximumVersion: '16.3.0',
17
+ maximumVersion: '16.4.0',
18
18
  note: "Downloads Cypress's platform-specific test runner binary",
19
19
  },
20
20
  {
21
21
  name: 'msw',
22
- maximumVersion: '3.0.5',
22
+ maximumVersion: '3.0.8',
23
23
  note: 'No install script at all since 3.0.0; worker regeneration moved to the manual `msw init` CLI command instead of running automatically on install. Ceiling bumped anyway to prevent audit workflow from flagging old version',
24
24
  },
25
25
  {
26
26
  name: 'nx',
27
- maximumVersion: '24.0.6',
28
- note: 'Verifies native platform support and updates the Nx Cloud client if the workspace uses Nx Cloud',
27
+ maximumVersion: '24.1.0',
28
+ note: 'Verifies native platform and workspace trust, and updates the Nx Cloud client if the workspace uses Nx Cloud',
29
29
  },
30
30
  {
31
31
  name: 'tree-sitter',