@lerna-lite/core 1.2.0 → 1.5.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 (144) hide show
  1. package/README.md +3 -3
  2. package/dist/child-process.d.ts +62 -62
  3. package/dist/child-process.js +165 -165
  4. package/dist/command.d.ts +37 -35
  5. package/dist/command.js +262 -262
  6. package/dist/command.js.map +1 -1
  7. package/dist/conventional-commits/constants.d.ts +4 -4
  8. package/dist/conventional-commits/constants.js +12 -12
  9. package/dist/conventional-commits/get-changelog-config.d.ts +12 -12
  10. package/dist/conventional-commits/get-changelog-config.js +98 -98
  11. package/dist/conventional-commits/index.d.ts +6 -6
  12. package/dist/conventional-commits/index.js +22 -22
  13. package/dist/conventional-commits/make-bump-only-filter.d.ts +6 -6
  14. package/dist/conventional-commits/make-bump-only-filter.js +22 -22
  15. package/dist/conventional-commits/read-existing-changelog.d.ts +7 -7
  16. package/dist/conventional-commits/read-existing-changelog.js +32 -32
  17. package/dist/conventional-commits/recommend-version.d.ts +11 -11
  18. package/dist/conventional-commits/recommend-version.js +86 -86
  19. package/dist/conventional-commits/update-changelog.d.ts +11 -11
  20. package/dist/conventional-commits/update-changelog.js +83 -83
  21. package/dist/git-clients/GitLabClient.d.ts +8 -8
  22. package/dist/git-clients/GitLabClient.js +39 -39
  23. package/dist/git-clients/github-client.d.ts +6 -6
  24. package/dist/git-clients/github-client.js +40 -40
  25. package/dist/git-clients/gitlab-client.d.ts +6 -6
  26. package/dist/git-clients/gitlab-client.js +21 -21
  27. package/dist/git-clients/index.d.ts +2 -2
  28. package/dist/git-clients/index.js +18 -18
  29. package/dist/index.d.ts +12 -12
  30. package/dist/index.js +30 -30
  31. package/dist/models/command-options.d.ts +214 -0
  32. package/dist/models/command-options.js +3 -0
  33. package/dist/models/command-options.js.map +1 -0
  34. package/dist/models/index.d.ts +2 -186
  35. package/dist/models/index.js +18 -2
  36. package/dist/models/index.js.map +1 -1
  37. package/dist/models/interfaces.d.ts +202 -0
  38. package/dist/models/interfaces.js +3 -0
  39. package/dist/models/interfaces.js.map +1 -0
  40. package/dist/otplease.d.ts +14 -14
  41. package/dist/otplease.js +108 -108
  42. package/dist/package-graph/index.d.ts +2 -2
  43. package/dist/package-graph/index.js +18 -18
  44. package/dist/package-graph/lib/cyclic-package-graph-node.d.ts +42 -42
  45. package/dist/package-graph/lib/cyclic-package-graph-node.js +97 -97
  46. package/dist/package-graph/lib/index.d.ts +3 -3
  47. package/dist/package-graph/lib/index.js +19 -19
  48. package/dist/package-graph/lib/package-graph-node.d.ts +33 -33
  49. package/dist/package-graph/lib/package-graph-node.js +58 -58
  50. package/dist/package-graph/lib/report-cycles.d.ts +1 -1
  51. package/dist/package-graph/lib/report-cycles.js +19 -19
  52. package/dist/package-graph/package-graph.d.ts +79 -79
  53. package/dist/package-graph/package-graph.js +276 -276
  54. package/dist/package.d.ts +91 -84
  55. package/dist/package.js +291 -256
  56. package/dist/package.js.map +1 -1
  57. package/dist/project/index.d.ts +2 -2
  58. package/dist/project/index.js +18 -18
  59. package/dist/project/lib/apply-extends.d.ts +10 -10
  60. package/dist/project/lib/apply-extends.js +37 -37
  61. package/dist/project/lib/index.d.ts +3 -3
  62. package/dist/project/lib/index.js +19 -19
  63. package/dist/project/lib/make-file-finder.d.ts +3 -3
  64. package/dist/project/lib/make-file-finder.js +71 -71
  65. package/dist/project/lib/shallow-extend.d.ts +11 -11
  66. package/dist/project/lib/shallow-extend.js +24 -24
  67. package/dist/project/project.d.ts +45 -45
  68. package/dist/project/project.js +195 -195
  69. package/dist/prompt.d.ts +23 -23
  70. package/dist/prompt.js +75 -75
  71. package/dist/utils/check-working-tree.d.ts +9 -8
  72. package/dist/utils/check-working-tree.js +41 -41
  73. package/dist/utils/check-working-tree.js.map +1 -1
  74. package/dist/utils/clean-stack.d.ts +5 -5
  75. package/dist/utils/clean-stack.js +18 -18
  76. package/dist/utils/collect-uncommitted.d.ts +17 -18
  77. package/dist/utils/collect-uncommitted.js +40 -40
  78. package/dist/utils/collect-uncommitted.js.map +1 -1
  79. package/dist/utils/collect-updates/collect-updates.d.ts +11 -11
  80. package/dist/utils/collect-updates/collect-updates.js +82 -82
  81. package/dist/utils/collect-updates/index.d.ts +2 -2
  82. package/dist/utils/collect-updates/index.js +18 -18
  83. package/dist/utils/collect-updates/lib/collect-dependents.d.ts +11 -11
  84. package/dist/utils/collect-updates/lib/collect-dependents.js +45 -45
  85. package/dist/utils/collect-updates/lib/collect-packages.d.ts +13 -13
  86. package/dist/utils/collect-updates/lib/collect-packages.js +33 -33
  87. package/dist/utils/collect-updates/lib/get-packages-for-option.d.ts +5 -5
  88. package/dist/utils/collect-updates/lib/get-packages-for-option.js +30 -30
  89. package/dist/utils/collect-updates/lib/has-tags.d.ts +5 -5
  90. package/dist/utils/collect-updates/lib/has-tags.js +26 -26
  91. package/dist/utils/collect-updates/lib/index.d.ts +5 -5
  92. package/dist/utils/collect-updates/lib/index.js +21 -21
  93. package/dist/utils/collect-updates/lib/make-diff-predicate.d.ts +7 -7
  94. package/dist/utils/collect-updates/lib/make-diff-predicate.js +64 -64
  95. package/dist/utils/conf.d.ts +25 -25
  96. package/dist/utils/conf.js +255 -255
  97. package/dist/utils/defaults.d.ts +1 -1
  98. package/dist/utils/defaults.js +182 -182
  99. package/dist/utils/defaults.js.map +1 -1
  100. package/dist/utils/describe-ref.d.ts +13 -37
  101. package/dist/utils/describe-ref.js +80 -80
  102. package/dist/utils/describe-ref.js.map +1 -1
  103. package/dist/utils/env-replace.d.ts +1 -1
  104. package/dist/utils/env-replace.js +22 -22
  105. package/dist/utils/find-prefix.d.ts +2 -2
  106. package/dist/utils/find-prefix.js +48 -48
  107. package/dist/utils/index.d.ts +21 -22
  108. package/dist/utils/index.js +38 -38
  109. package/dist/utils/index.js.map +1 -1
  110. package/dist/utils/log-package-error.d.ts +5 -5
  111. package/dist/utils/log-package-error.js +35 -35
  112. package/dist/utils/nerf-dart.d.ts +1 -1
  113. package/dist/utils/nerf-dart.js +18 -18
  114. package/dist/utils/npm-conf.d.ts +4 -4
  115. package/dist/utils/npm-conf.js +56 -55
  116. package/dist/utils/npm-conf.js.map +1 -1
  117. package/dist/utils/output.d.ts +1 -1
  118. package/dist/utils/output.js +13 -13
  119. package/dist/utils/parse-field.d.ts +1 -1
  120. package/dist/utils/parse-field.js +65 -65
  121. package/dist/utils/prerelease-id-from-version.d.ts +5 -5
  122. package/dist/utils/prerelease-id-from-version.js +15 -15
  123. package/dist/utils/pulse-till-done.d.ts +1 -1
  124. package/dist/utils/pulse-till-done.js +40 -40
  125. package/dist/utils/query-graph.d.ts +36 -36
  126. package/dist/utils/query-graph.js +77 -77
  127. package/dist/utils/query-graph.js.map +1 -1
  128. package/dist/utils/run-lifecycle.d.ts +10 -10
  129. package/dist/utils/run-lifecycle.js +131 -107
  130. package/dist/utils/run-lifecycle.js.map +1 -1
  131. package/dist/utils/run-topologically.d.ts +12 -12
  132. package/dist/utils/run-topologically.js +36 -36
  133. package/dist/utils/temp-write.d.ts +13 -0
  134. package/dist/utils/temp-write.js +50 -0
  135. package/dist/utils/temp-write.js.map +1 -0
  136. package/dist/utils/types.d.ts +131 -129
  137. package/dist/utils/types.js +138 -138
  138. package/dist/utils/warn-if-hanging.d.ts +1 -1
  139. package/dist/utils/warn-if-hanging.js +17 -17
  140. package/dist/utils/write-log-file.d.ts +1 -1
  141. package/dist/utils/write-log-file.js +32 -32
  142. package/dist/validation-error.d.ts +4 -4
  143. package/dist/validation-error.js +18 -18
  144. package/package.json +16 -12
package/README.md CHANGED
@@ -1,13 +1,13 @@
1
1
  [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
2
- [![TypeScript](https://img.shields.io/badge/%3C%2F%3E-TypeScript-%230074c1.svg)](http://www.typescriptlang.org/)
3
- [![npm](https://img.shields.io/npm/v/@lerna-lite/core.svg?color=forest)](https://www.npmjs.com/package/@lerna-lite/core)
4
2
  [![npm](https://img.shields.io/npm/dy/@lerna-lite/core?color=forest)](https://www.npmjs.com/package/@lerna-lite/core)
5
- [![Actions Status](https://github.com/ghiscoding/lerna-lite/workflows/CI%20Build/badge.svg)](https://github.com/ghiscoding/lerna-lite/actions)
3
+ [![npm](https://img.shields.io/npm/v/@lerna-lite/core.svg?logo=npm&logoColor=fff&label=npm)](https://www.npmjs.com/package/@lerna-lite/core)
6
4
 
7
5
  ## Lerna-Lite Core
6
+
8
7
  #### @lerna-lite/core
9
8
 
10
9
  The Lerna-Lite core & utils, basically the shared code used by all commands.
11
10
 
12
11
  ### Installation
12
+
13
13
  Follow the instruction provided in the main [README](https://github.com/ghiscoding/lerna-lite#installation) page.
@@ -1,62 +1,62 @@
1
- import execa from 'execa';
2
- import { Package } from './package';
3
- /**
4
- * Execute a command asynchronously, piping stdio by default.
5
- * @param {string} command
6
- * @param {string[]} args
7
- * @param {import("execa").Options} [opts]
8
- */
9
- export declare function exec(command: string, args: string[], opts?: execa.Options & {
10
- pkg?: Package;
11
- }, cmdDryRun?: boolean): Promise<any>;
12
- /**
13
- * Execute a command synchronously.
14
- * @param {string} command
15
- * @param {string[]} args
16
- * @param {import("execa").SyncOptions} [opts]
17
- */
18
- export declare function execSync(command: string, args?: string[], opts?: execa.SyncOptions<string>, cmdDryRun?: boolean): string;
19
- /**
20
- * Spawn a command asynchronously, _always_ inheriting stdio.
21
- * @param {string} command
22
- * @param {string[]} args
23
- * @param {import("execa").Options} [opts]
24
- */
25
- export declare function spawn(command: string, args: string[], opts?: execa.Options & {
26
- pkg?: Package;
27
- }, cmdDryRun?: boolean): Promise<any>;
28
- /**
29
- * Spawn a command asynchronously, streaming stdio with optional prefix.
30
- * @param {string} command
31
- * @param {string[]} args
32
- * @param {import("execa").Options} [opts]
33
- * @param {string} [prefix]
34
- */
35
- export declare function spawnStreaming(command: string, args: string[], opts?: execa.Options & {
36
- pkg?: Package;
37
- }, prefix?: string | boolean, cmdDryRun?: boolean): Promise<any>;
38
- export declare function getChildProcessCount(): number;
39
- export declare function getExitCode(result: any): any;
40
- /**
41
- * @param {string} command
42
- * @param {string[]} args
43
- * @param {import("execa").Options} opts
44
- */
45
- export declare function spawnProcess(command: string, args: string[], opts: execa.Options & {
46
- pkg?: Package;
47
- }, cmdDryRun?: boolean): any;
48
- /**
49
- * Spawn a command asynchronously, _always_ inheriting stdio.
50
- * @param {string} command
51
- * @param {string[]} args
52
- * @param {import("execa").Options} [opts]
53
- */
54
- export declare function wrapError(spawned: execa.ExecaChildProcess & {
55
- pkg?: Package;
56
- }): Promise<execa.ExecaReturnValue<string>>;
57
- /**
58
- * Log the child-process command and its arguments as dry-run (without executing the process)
59
- * @param {string} command
60
- * @param {string[]} args
61
- */
62
- export declare function logExecCommand(command: string, args?: string[]): string;
1
+ import execa from 'execa';
2
+ import { Package } from './package';
3
+ /**
4
+ * Execute a command asynchronously, piping stdio by default.
5
+ * @param {string} command
6
+ * @param {string[]} args
7
+ * @param {import("execa").Options} [opts]
8
+ */
9
+ export declare function exec(command: string, args: string[], opts?: execa.Options & {
10
+ pkg?: Package;
11
+ }, cmdDryRun?: boolean): Promise<any>;
12
+ /**
13
+ * Execute a command synchronously.
14
+ * @param {string} command
15
+ * @param {string[]} args
16
+ * @param {import("execa").SyncOptions} [opts]
17
+ */
18
+ export declare function execSync(command: string, args?: string[], opts?: execa.SyncOptions<string>, cmdDryRun?: boolean): string;
19
+ /**
20
+ * Spawn a command asynchronously, _always_ inheriting stdio.
21
+ * @param {string} command
22
+ * @param {string[]} args
23
+ * @param {import("execa").Options} [opts]
24
+ */
25
+ export declare function spawn(command: string, args: string[], opts?: execa.Options & {
26
+ pkg?: Package;
27
+ }, cmdDryRun?: boolean): Promise<any>;
28
+ /**
29
+ * Spawn a command asynchronously, streaming stdio with optional prefix.
30
+ * @param {string} command
31
+ * @param {string[]} args
32
+ * @param {import("execa").Options} [opts]
33
+ * @param {string} [prefix]
34
+ */
35
+ export declare function spawnStreaming(command: string, args: string[], opts?: execa.Options & {
36
+ pkg?: Package;
37
+ }, prefix?: string | boolean, cmdDryRun?: boolean): Promise<any>;
38
+ export declare function getChildProcessCount(): number;
39
+ export declare function getExitCode(result: any): any;
40
+ /**
41
+ * @param {string} command
42
+ * @param {string[]} args
43
+ * @param {import("execa").Options} opts
44
+ */
45
+ export declare function spawnProcess(command: string, args: string[], opts: execa.Options & {
46
+ pkg?: Package;
47
+ }, cmdDryRun?: boolean): any;
48
+ /**
49
+ * Spawn a command asynchronously, _always_ inheriting stdio.
50
+ * @param {string} command
51
+ * @param {string[]} args
52
+ * @param {import("execa").Options} [opts]
53
+ */
54
+ export declare function wrapError(spawned: execa.ExecaChildProcess & {
55
+ pkg?: Package;
56
+ }): Promise<execa.ExecaReturnValue<string>>;
57
+ /**
58
+ * Log the child-process command and its arguments as dry-run (without executing the process)
59
+ * @param {string} command
60
+ * @param {string[]} args
61
+ */
62
+ export declare function logExecCommand(command: string, args?: string[]): string;
@@ -1,166 +1,166 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.logExecCommand = exports.wrapError = exports.spawnProcess = exports.getExitCode = exports.getChildProcessCount = exports.spawnStreaming = exports.spawn = exports.execSync = exports.exec = void 0;
7
- const chalk_1 = __importDefault(require("chalk"));
8
- const execa_1 = __importDefault(require("execa"));
9
- const npmlog_1 = __importDefault(require("npmlog"));
10
- const os_1 = __importDefault(require("os"));
11
- const strong_log_transformer_1 = __importDefault(require("strong-log-transformer"));
12
- // bookkeeping for spawned processes
13
- const children = new Set();
14
- // when streaming processes are spawned, use this color for prefix
15
- const colorWheel = ['cyan', 'magenta', 'blue', 'yellow', 'green', 'red'];
16
- const NUM_COLORS = colorWheel.length;
17
- // ever-increasing index ensures colors are always sequential
18
- let currentColor = 0;
19
- /**
20
- * Execute a command asynchronously, piping stdio by default.
21
- * @param {string} command
22
- * @param {string[]} args
23
- * @param {import("execa").Options} [opts]
24
- */
25
- function exec(command, args, opts, cmdDryRun = false) {
26
- const options = Object.assign({ stdio: 'pipe' }, opts);
27
- const spawned = spawnProcess(command, args, options, cmdDryRun);
28
- return cmdDryRun ? Promise.resolve() : wrapError(spawned);
29
- }
30
- exports.exec = exec;
31
- /**
32
- * Execute a command synchronously.
33
- * @param {string} command
34
- * @param {string[]} args
35
- * @param {import("execa").SyncOptions} [opts]
36
- */
37
- function execSync(command, args, opts, cmdDryRun = false) {
38
- return cmdDryRun
39
- ? logExecCommand(command, args)
40
- : execa_1.default.sync(command, args, opts).stdout;
41
- }
42
- exports.execSync = execSync;
43
- /**
44
- * Spawn a command asynchronously, _always_ inheriting stdio.
45
- * @param {string} command
46
- * @param {string[]} args
47
- * @param {import("execa").Options} [opts]
48
- */
49
- function spawn(command, args, opts, cmdDryRun = false) {
50
- const options = Object.assign({}, opts, { stdio: 'inherit' });
51
- const spawned = spawnProcess(command, args, options, cmdDryRun);
52
- return wrapError(spawned);
53
- }
54
- exports.spawn = spawn;
55
- /**
56
- * Spawn a command asynchronously, streaming stdio with optional prefix.
57
- * @param {string} command
58
- * @param {string[]} args
59
- * @param {import("execa").Options} [opts]
60
- * @param {string} [prefix]
61
- */
62
- // istanbul ignore next
63
- function spawnStreaming(command, args, opts, prefix, cmdDryRun = false) {
64
- const options = Object.assign({}, opts);
65
- options.stdio = ['ignore', 'pipe', 'pipe'];
66
- const spawned = spawnProcess(command, args, options, cmdDryRun);
67
- const stdoutOpts = {};
68
- const stderrOpts = {}; // mergeMultiline causes escaped newlines :P
69
- if (prefix) {
70
- const colorName = colorWheel[currentColor % NUM_COLORS];
71
- const color = chalk_1.default[colorName];
72
- currentColor += 1;
73
- stdoutOpts.tag = `${color.bold(prefix)}:`;
74
- stderrOpts.tag = `${color(prefix)}:`;
75
- }
76
- // Avoid 'Possible EventEmitter memory leak detected' warning due to piped stdio
77
- if (children.size > process.stdout.listenerCount('close')) {
78
- process.stdout.setMaxListeners(children.size);
79
- process.stderr.setMaxListeners(children.size);
80
- }
81
- spawned.stdout.pipe((0, strong_log_transformer_1.default)(stdoutOpts)).pipe(process.stdout);
82
- spawned.stderr.pipe((0, strong_log_transformer_1.default)(stderrOpts)).pipe(process.stderr);
83
- return wrapError(spawned);
84
- }
85
- exports.spawnStreaming = spawnStreaming;
86
- function getChildProcessCount() {
87
- return children.size;
88
- }
89
- exports.getChildProcessCount = getChildProcessCount;
90
- function getExitCode(result) {
91
- var _a, _b, _c;
92
- // https://nodejs.org/docs/latest-v6.x/api/child_process.html#child_process_event_close
93
- if (typeof result.code === 'number' || typeof result.exitCode === 'number') {
94
- return (_a = result.code) !== null && _a !== void 0 ? _a : result.exitCode;
95
- }
96
- // https://nodejs.org/docs/latest-v6.x/api/errors.html#errors_error_code
97
- // istanbul ignore else
98
- if (typeof result.code === 'string' || typeof result.exitCode === 'string') {
99
- return os_1.default.constants.errno[(_b = result.code) !== null && _b !== void 0 ? _b : result.exitCode];
100
- }
101
- // istanbul ignore next: extremely weird
102
- throw new TypeError(`Received unexpected exit code value ${JSON.stringify((_c = result.code) !== null && _c !== void 0 ? _c : result.exitCode)}`);
103
- }
104
- exports.getExitCode = getExitCode;
105
- /**
106
- * @param {string} command
107
- * @param {string[]} args
108
- * @param {import("execa").Options} opts
109
- */
110
- function spawnProcess(command, args, opts, cmdDryRun = false) {
111
- if (cmdDryRun) {
112
- return logExecCommand(command, args);
113
- }
114
- const child = (0, execa_1.default)(command, args, opts);
115
- const drain = (_code, signal) => {
116
- children.delete(child);
117
- // don't run repeatedly if this is the error event
118
- if (signal === undefined) {
119
- child.removeListener('exit', drain);
120
- }
121
- };
122
- child.once('exit', drain);
123
- child.once('error', drain);
124
- if (opts.pkg) {
125
- child.pkg = opts.pkg;
126
- }
127
- children.add(child);
128
- return child;
129
- }
130
- exports.spawnProcess = spawnProcess;
131
- /**
132
- * Spawn a command asynchronously, _always_ inheriting stdio.
133
- * @param {string} command
134
- * @param {string[]} args
135
- * @param {import("execa").Options} [opts]
136
- */
137
- function wrapError(spawned) {
138
- if (spawned.pkg) {
139
- return spawned.catch((err) => {
140
- // ensure exit code is always a number
141
- err.exitCode = getExitCode(err);
142
- // log non-lerna error cleanly
143
- err.pkg = spawned.pkg;
144
- throw err;
145
- });
146
- }
147
- return spawned;
148
- }
149
- exports.wrapError = wrapError;
150
- /**
151
- * Log the child-process command and its arguments as dry-run (without executing the process)
152
- * @param {string} command
153
- * @param {string[]} args
154
- */
155
- function logExecCommand(command, args) {
156
- var _a;
157
- const argStr = (_a = (Array.isArray(args) ? args.join(' ') : args)) !== null && _a !== void 0 ? _a : '';
158
- const cmdList = [];
159
- for (const c of [command, argStr]) {
160
- cmdList.push((Array.isArray(c) ? c.join(' ') : c));
161
- }
162
- npmlog_1.default.info('dry-run>', cmdList.join(' '));
163
- return '';
164
- }
165
- exports.logExecCommand = logExecCommand;
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.logExecCommand = exports.wrapError = exports.spawnProcess = exports.getExitCode = exports.getChildProcessCount = exports.spawnStreaming = exports.spawn = exports.execSync = exports.exec = void 0;
7
+ const chalk_1 = __importDefault(require("chalk"));
8
+ const execa_1 = __importDefault(require("execa"));
9
+ const npmlog_1 = __importDefault(require("npmlog"));
10
+ const os_1 = __importDefault(require("os"));
11
+ const strong_log_transformer_1 = __importDefault(require("strong-log-transformer"));
12
+ // bookkeeping for spawned processes
13
+ const children = new Set();
14
+ // when streaming processes are spawned, use this color for prefix
15
+ const colorWheel = ['cyan', 'magenta', 'blue', 'yellow', 'green', 'red'];
16
+ const NUM_COLORS = colorWheel.length;
17
+ // ever-increasing index ensures colors are always sequential
18
+ let currentColor = 0;
19
+ /**
20
+ * Execute a command asynchronously, piping stdio by default.
21
+ * @param {string} command
22
+ * @param {string[]} args
23
+ * @param {import("execa").Options} [opts]
24
+ */
25
+ function exec(command, args, opts, cmdDryRun = false) {
26
+ const options = Object.assign({ stdio: 'pipe' }, opts);
27
+ const spawned = spawnProcess(command, args, options, cmdDryRun);
28
+ return cmdDryRun ? Promise.resolve() : wrapError(spawned);
29
+ }
30
+ exports.exec = exec;
31
+ /**
32
+ * Execute a command synchronously.
33
+ * @param {string} command
34
+ * @param {string[]} args
35
+ * @param {import("execa").SyncOptions} [opts]
36
+ */
37
+ function execSync(command, args, opts, cmdDryRun = false) {
38
+ return cmdDryRun
39
+ ? logExecCommand(command, args)
40
+ : execa_1.default.sync(command, args, opts).stdout;
41
+ }
42
+ exports.execSync = execSync;
43
+ /**
44
+ * Spawn a command asynchronously, _always_ inheriting stdio.
45
+ * @param {string} command
46
+ * @param {string[]} args
47
+ * @param {import("execa").Options} [opts]
48
+ */
49
+ function spawn(command, args, opts, cmdDryRun = false) {
50
+ const options = Object.assign({}, opts, { stdio: 'inherit' });
51
+ const spawned = spawnProcess(command, args, options, cmdDryRun);
52
+ return wrapError(spawned);
53
+ }
54
+ exports.spawn = spawn;
55
+ /**
56
+ * Spawn a command asynchronously, streaming stdio with optional prefix.
57
+ * @param {string} command
58
+ * @param {string[]} args
59
+ * @param {import("execa").Options} [opts]
60
+ * @param {string} [prefix]
61
+ */
62
+ // istanbul ignore next
63
+ function spawnStreaming(command, args, opts, prefix, cmdDryRun = false) {
64
+ const options = Object.assign({}, opts);
65
+ options.stdio = ['ignore', 'pipe', 'pipe'];
66
+ const spawned = spawnProcess(command, args, options, cmdDryRun);
67
+ const stdoutOpts = {};
68
+ const stderrOpts = {}; // mergeMultiline causes escaped newlines :P
69
+ if (prefix) {
70
+ const colorName = colorWheel[currentColor % NUM_COLORS];
71
+ const color = chalk_1.default[colorName];
72
+ currentColor += 1;
73
+ stdoutOpts.tag = `${color.bold(prefix)}:`;
74
+ stderrOpts.tag = `${color(prefix)}:`;
75
+ }
76
+ // Avoid 'Possible EventEmitter memory leak detected' warning due to piped stdio
77
+ if (children.size > process.stdout.listenerCount('close')) {
78
+ process.stdout.setMaxListeners(children.size);
79
+ process.stderr.setMaxListeners(children.size);
80
+ }
81
+ spawned.stdout.pipe((0, strong_log_transformer_1.default)(stdoutOpts)).pipe(process.stdout);
82
+ spawned.stderr.pipe((0, strong_log_transformer_1.default)(stderrOpts)).pipe(process.stderr);
83
+ return wrapError(spawned);
84
+ }
85
+ exports.spawnStreaming = spawnStreaming;
86
+ function getChildProcessCount() {
87
+ return children.size;
88
+ }
89
+ exports.getChildProcessCount = getChildProcessCount;
90
+ function getExitCode(result) {
91
+ var _a, _b, _c;
92
+ // https://nodejs.org/docs/latest-v6.x/api/child_process.html#child_process_event_close
93
+ if (typeof result.code === 'number' || typeof result.exitCode === 'number') {
94
+ return (_a = result.code) !== null && _a !== void 0 ? _a : result.exitCode;
95
+ }
96
+ // https://nodejs.org/docs/latest-v6.x/api/errors.html#errors_error_code
97
+ // istanbul ignore else
98
+ if (typeof result.code === 'string' || typeof result.exitCode === 'string') {
99
+ return os_1.default.constants.errno[(_b = result.code) !== null && _b !== void 0 ? _b : result.exitCode];
100
+ }
101
+ // istanbul ignore next: extremely weird
102
+ throw new TypeError(`Received unexpected exit code value ${JSON.stringify((_c = result.code) !== null && _c !== void 0 ? _c : result.exitCode)}`);
103
+ }
104
+ exports.getExitCode = getExitCode;
105
+ /**
106
+ * @param {string} command
107
+ * @param {string[]} args
108
+ * @param {import("execa").Options} opts
109
+ */
110
+ function spawnProcess(command, args, opts, cmdDryRun = false) {
111
+ if (cmdDryRun) {
112
+ return logExecCommand(command, args);
113
+ }
114
+ const child = (0, execa_1.default)(command, args, opts);
115
+ const drain = (_code, signal) => {
116
+ children.delete(child);
117
+ // don't run repeatedly if this is the error event
118
+ if (signal === undefined) {
119
+ child.removeListener('exit', drain);
120
+ }
121
+ };
122
+ child.once('exit', drain);
123
+ child.once('error', drain);
124
+ if (opts.pkg) {
125
+ child.pkg = opts.pkg;
126
+ }
127
+ children.add(child);
128
+ return child;
129
+ }
130
+ exports.spawnProcess = spawnProcess;
131
+ /**
132
+ * Spawn a command asynchronously, _always_ inheriting stdio.
133
+ * @param {string} command
134
+ * @param {string[]} args
135
+ * @param {import("execa").Options} [opts]
136
+ */
137
+ function wrapError(spawned) {
138
+ if (spawned.pkg) {
139
+ return spawned.catch((err) => {
140
+ // ensure exit code is always a number
141
+ err.exitCode = getExitCode(err);
142
+ // log non-lerna error cleanly
143
+ err.pkg = spawned.pkg;
144
+ throw err;
145
+ });
146
+ }
147
+ return spawned;
148
+ }
149
+ exports.wrapError = wrapError;
150
+ /**
151
+ * Log the child-process command and its arguments as dry-run (without executing the process)
152
+ * @param {string} command
153
+ * @param {string[]} args
154
+ */
155
+ function logExecCommand(command, args) {
156
+ var _a;
157
+ const argStr = (_a = (Array.isArray(args) ? args.join(' ') : args)) !== null && _a !== void 0 ? _a : '';
158
+ const cmdList = [];
159
+ for (const c of [command, argStr]) {
160
+ cmdList.push((Array.isArray(c) ? c.join(' ') : c));
161
+ }
162
+ npmlog_1.default.info('dry-run>', cmdList.join(' '));
163
+ return '';
164
+ }
165
+ exports.logExecCommand = logExecCommand;
166
166
  //# sourceMappingURL=child-process.js.map
package/dist/command.d.ts CHANGED
@@ -1,35 +1,37 @@
1
- import { Logger } from 'npmlog';
2
- import { Project } from './project/project';
3
- import { CommandType, ExecOpts } from './models';
4
- import { PackageGraph } from './package-graph/package-graph';
5
- export declare class Command {
6
- argv: any;
7
- concurrency: number;
8
- envDefaults: any;
9
- sort: any;
10
- toposort?: number;
11
- execOpts: ExecOpts;
12
- commandName: CommandType;
13
- composed: any;
14
- logger: Logger;
15
- options: any;
16
- project: Project;
17
- packageGraph: PackageGraph;
18
- runner?: Promise<any>;
19
- constructor(_argv: any);
20
- then(onResolved: typeof Promise.resolve, onRejected: typeof Promise.reject): Promise<unknown> | undefined;
21
- catch(onRejected: typeof Promise.reject): Promise<any> | undefined;
22
- get requiresGit(): boolean;
23
- get otherCommandConfigs(): string[];
24
- configureEnvironment(): void;
25
- configureOptions(): void;
26
- configureProperties(): void;
27
- configureLogging(): void;
28
- enableProgressBar(): void;
29
- gitInitialized(): boolean;
30
- runValidations(): void;
31
- runPreparations(): Promise<any>;
32
- runCommand(): Promise<any>;
33
- initialize(): any | Promise<any>;
34
- execute(): any | Promise<any>;
35
- }
1
+ import { Logger } from 'npmlog';
2
+ import { Project } from './project/project';
3
+ import { CommandType, ExecCommandOption, ExecOpts, InitCommandOption, ListCommandOption, ProjectConfig, PublishCommandOption, VersionCommandOption } from './models';
4
+ import { PackageGraph } from './package-graph/package-graph';
5
+ declare type AvailableCommandOption = ExecCommandOption | InitCommandOption | ListCommandOption | PublishCommandOption | VersionCommandOption;
6
+ export declare class Command<T extends AvailableCommandOption> {
7
+ argv: any;
8
+ concurrency: number;
9
+ envDefaults: any;
10
+ sort: any;
11
+ toposort?: number;
12
+ execOpts: ExecOpts;
13
+ commandName: CommandType;
14
+ composed: any;
15
+ logger: Logger;
16
+ options: T & ExecOpts & ProjectConfig;
17
+ project: Project;
18
+ packageGraph: PackageGraph;
19
+ runner?: Promise<any>;
20
+ constructor(_argv: AvailableCommandOption);
21
+ then(onResolved: typeof Promise.resolve, onRejected: typeof Promise.reject): Promise<unknown> | undefined;
22
+ catch(onRejected: typeof Promise.reject): Promise<any> | undefined;
23
+ get requiresGit(): boolean;
24
+ get otherCommandConfigs(): string[];
25
+ configureEnvironment(): void;
26
+ configureOptions(): void;
27
+ configureProperties(): void;
28
+ configureLogging(): void;
29
+ enableProgressBar(): void;
30
+ gitInitialized(): boolean;
31
+ runValidations(): void;
32
+ runPreparations(): Promise<any> | void;
33
+ runCommand(): Promise<any>;
34
+ initialize(): any | Promise<any>;
35
+ execute(): any | Promise<any>;
36
+ }
37
+ export {};