@lerna-lite/core 1.1.0 → 1.4.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 (147) 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 -10
  18. package/dist/conventional-commits/recommend-version.js +86 -86
  19. package/dist/conventional-commits/recommend-version.js.map +1 -1
  20. package/dist/conventional-commits/update-changelog.d.ts +11 -11
  21. package/dist/conventional-commits/update-changelog.js +83 -83
  22. package/dist/git-clients/GitLabClient.d.ts +8 -8
  23. package/dist/git-clients/GitLabClient.js +39 -39
  24. package/dist/git-clients/github-client.d.ts +6 -6
  25. package/dist/git-clients/github-client.js +40 -40
  26. package/dist/git-clients/gitlab-client.d.ts +6 -6
  27. package/dist/git-clients/gitlab-client.js +21 -21
  28. package/dist/git-clients/index.d.ts +2 -2
  29. package/dist/git-clients/index.js +18 -18
  30. package/dist/index.d.ts +12 -12
  31. package/dist/index.js +30 -30
  32. package/dist/models/command-options.d.ts +206 -0
  33. package/dist/models/command-options.js +3 -0
  34. package/dist/models/command-options.js.map +1 -0
  35. package/dist/models/index.d.ts +2 -148
  36. package/dist/models/index.js +18 -2
  37. package/dist/models/index.js.map +1 -1
  38. package/dist/models/interfaces.d.ts +201 -0
  39. package/dist/models/interfaces.js +3 -0
  40. package/dist/models/interfaces.js.map +1 -0
  41. package/dist/otplease.d.ts +14 -13
  42. package/dist/otplease.js +108 -112
  43. package/dist/otplease.js.map +1 -1
  44. package/dist/package-graph/index.d.ts +2 -2
  45. package/dist/package-graph/index.js +18 -18
  46. package/dist/package-graph/lib/cyclic-package-graph-node.d.ts +42 -42
  47. package/dist/package-graph/lib/cyclic-package-graph-node.js +97 -97
  48. package/dist/package-graph/lib/index.d.ts +3 -3
  49. package/dist/package-graph/lib/index.js +19 -19
  50. package/dist/package-graph/lib/package-graph-node.d.ts +33 -33
  51. package/dist/package-graph/lib/package-graph-node.js +58 -58
  52. package/dist/package-graph/lib/report-cycles.d.ts +1 -1
  53. package/dist/package-graph/lib/report-cycles.js +19 -19
  54. package/dist/package-graph/package-graph.d.ts +79 -79
  55. package/dist/package-graph/package-graph.js +276 -248
  56. package/dist/package-graph/package-graph.js.map +1 -1
  57. package/dist/package.d.ts +91 -96
  58. package/dist/package.js +282 -260
  59. package/dist/package.js.map +1 -1
  60. package/dist/project/index.d.ts +2 -2
  61. package/dist/project/index.js +18 -18
  62. package/dist/project/lib/apply-extends.d.ts +10 -6
  63. package/dist/project/lib/apply-extends.js +37 -37
  64. package/dist/project/lib/apply-extends.js.map +1 -1
  65. package/dist/project/lib/index.d.ts +3 -3
  66. package/dist/project/lib/index.js +19 -19
  67. package/dist/project/lib/make-file-finder.d.ts +3 -3
  68. package/dist/project/lib/make-file-finder.js +71 -71
  69. package/dist/project/lib/shallow-extend.d.ts +11 -5
  70. package/dist/project/lib/shallow-extend.js +24 -24
  71. package/dist/project/lib/shallow-extend.js.map +1 -1
  72. package/dist/project/project.d.ts +45 -51
  73. package/dist/project/project.js +198 -197
  74. package/dist/project/project.js.map +1 -1
  75. package/dist/prompt.d.ts +23 -23
  76. package/dist/prompt.js +75 -75
  77. package/dist/utils/check-working-tree.d.ts +8 -8
  78. package/dist/utils/check-working-tree.js +41 -41
  79. package/dist/utils/clean-stack.d.ts +5 -5
  80. package/dist/utils/clean-stack.js +18 -18
  81. package/dist/utils/collect-uncommitted.d.ts +18 -19
  82. package/dist/utils/collect-uncommitted.js +40 -45
  83. package/dist/utils/collect-uncommitted.js.map +1 -1
  84. package/dist/utils/collect-updates/collect-updates.d.ts +11 -11
  85. package/dist/utils/collect-updates/collect-updates.js +82 -82
  86. package/dist/utils/collect-updates/index.d.ts +2 -2
  87. package/dist/utils/collect-updates/index.js +18 -18
  88. package/dist/utils/collect-updates/lib/collect-dependents.d.ts +11 -11
  89. package/dist/utils/collect-updates/lib/collect-dependents.js +45 -45
  90. package/dist/utils/collect-updates/lib/collect-packages.d.ts +13 -13
  91. package/dist/utils/collect-updates/lib/collect-packages.js +33 -33
  92. package/dist/utils/collect-updates/lib/get-packages-for-option.d.ts +5 -5
  93. package/dist/utils/collect-updates/lib/get-packages-for-option.js +30 -30
  94. package/dist/utils/collect-updates/lib/has-tags.d.ts +5 -5
  95. package/dist/utils/collect-updates/lib/has-tags.js +26 -26
  96. package/dist/utils/collect-updates/lib/index.d.ts +5 -5
  97. package/dist/utils/collect-updates/lib/index.js +21 -21
  98. package/dist/utils/collect-updates/lib/make-diff-predicate.d.ts +7 -7
  99. package/dist/utils/collect-updates/lib/make-diff-predicate.js +64 -64
  100. package/dist/utils/conf.d.ts +25 -25
  101. package/dist/utils/conf.js +255 -255
  102. package/dist/utils/defaults.d.ts +1 -1
  103. package/dist/utils/defaults.js +182 -182
  104. package/dist/utils/defaults.js.map +1 -1
  105. package/dist/utils/describe-ref.d.ts +37 -37
  106. package/dist/utils/describe-ref.js +80 -80
  107. package/dist/utils/env-replace.d.ts +1 -1
  108. package/dist/utils/env-replace.js +22 -22
  109. package/dist/utils/find-prefix.d.ts +2 -2
  110. package/dist/utils/find-prefix.js +48 -48
  111. package/dist/utils/index.d.ts +23 -22
  112. package/dist/utils/index.js +39 -38
  113. package/dist/utils/index.js.map +1 -1
  114. package/dist/utils/log-package-error.d.ts +5 -5
  115. package/dist/utils/log-package-error.js +35 -35
  116. package/dist/utils/nerf-dart.d.ts +1 -1
  117. package/dist/utils/nerf-dart.js +18 -18
  118. package/dist/utils/npm-conf.d.ts +4 -4
  119. package/dist/utils/npm-conf.js +55 -55
  120. package/dist/utils/output.d.ts +1 -1
  121. package/dist/utils/output.js +13 -13
  122. package/dist/utils/parse-field.d.ts +1 -1
  123. package/dist/utils/parse-field.js +65 -65
  124. package/dist/utils/prerelease-id-from-version.d.ts +5 -5
  125. package/dist/utils/prerelease-id-from-version.js +15 -15
  126. package/dist/utils/pulse-till-done.d.ts +1 -1
  127. package/dist/utils/pulse-till-done.js +40 -40
  128. package/dist/utils/query-graph.d.ts +36 -36
  129. package/dist/utils/query-graph.js +77 -77
  130. package/dist/utils/query-graph.js.map +1 -1
  131. package/dist/utils/run-lifecycle.d.ts +10 -10
  132. package/dist/utils/run-lifecycle.js +131 -107
  133. package/dist/utils/run-lifecycle.js.map +1 -1
  134. package/dist/utils/run-topologically.d.ts +12 -12
  135. package/dist/utils/run-topologically.js +36 -36
  136. package/dist/utils/temp-write.d.ts +13 -0
  137. package/dist/utils/temp-write.js +50 -0
  138. package/dist/utils/temp-write.js.map +1 -0
  139. package/dist/utils/types.d.ts +131 -129
  140. package/dist/utils/types.js +138 -138
  141. package/dist/utils/warn-if-hanging.d.ts +1 -1
  142. package/dist/utils/warn-if-hanging.js +17 -17
  143. package/dist/utils/write-log-file.d.ts +1 -1
  144. package/dist/utils/write-log-file.js +32 -32
  145. package/dist/validation-error.d.ts +4 -4
  146. package/dist/validation-error.js +18 -18
  147. package/package.json +14 -10
@@ -1,256 +1,256 @@
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.Conf = void 0;
7
- const assert_1 = __importDefault(require("assert"));
8
- const fs_1 = __importDefault(require("fs"));
9
- const path_1 = __importDefault(require("path"));
10
- // @ts-ignore
11
- const config_chain_1 = require("config-chain");
12
- const env_replace_1 = require("./env-replace");
13
- const find_prefix_1 = require("./find-prefix");
14
- const parse_field_1 = require("./parse-field");
15
- const nerf_dart_1 = require("./nerf-dart");
16
- class Conf extends config_chain_1.ConfigChain {
17
- // https://github.com/npm/npm/blob/latest/lib/config/core.js#L208-L222
18
- constructor(base) {
19
- super(base);
20
- this.globalPrefix = '';
21
- this.localPrefix = '';
22
- this.root = base;
23
- }
24
- // https://github.com/npm/npm/blob/latest/lib/config/core.js#L332-L342
25
- add(data, marker) {
26
- try {
27
- /* eslint-disable no-param-reassign */
28
- for (const x of Object.keys(data)) {
29
- // https://github.com/npm/npm/commit/f0e998d
30
- const newKey = (0, env_replace_1.envReplace)(x);
31
- const newField = (0, parse_field_1.parseField)(data[x], newKey);
32
- delete data[x];
33
- data[newKey] = newField;
34
- }
35
- /* eslint-enable no-param-reassign */
36
- }
37
- catch (err) {
38
- throw err;
39
- }
40
- return super.add(data, marker);
41
- }
42
- // https://github.com/npm/npm/blob/latest/lib/config/core.js#L312-L325
43
- addFile(file, name = file) {
44
- const marker = { __source__: name };
45
- this.sources[name] = { path: file, type: 'ini' };
46
- this.push(marker);
47
- this._await();
48
- try {
49
- const contents = fs_1.default.readFileSync(file, 'utf8');
50
- this.addString(contents, file, 'ini', marker);
51
- }
52
- catch (err) {
53
- this.add({}, marker);
54
- }
55
- return this;
56
- }
57
- // https://github.com/npm/npm/blob/latest/lib/config/core.js#L344-L360
58
- addEnv(env = process.env) {
59
- const conf = {};
60
- Object.keys(env)
61
- .filter((x) => /^npm_config_/i.test(x))
62
- .forEach((x) => {
63
- if (!env[x]) {
64
- return;
65
- }
66
- // leave first char untouched, even if it is a '_'
67
- // convert all other '_' to '-'
68
- const p = x
69
- .toLowerCase()
70
- .replace(/^npm_config_/, '')
71
- .replace(/(?!^)_/g, '-');
72
- conf[p] = env[x];
73
- });
74
- return super.addEnv('', conf, 'env');
75
- }
76
- // https://github.com/npm/npm/blob/latest/lib/config/load-prefix.js
77
- loadPrefix() {
78
- const cli = this.list[0];
79
- Object.defineProperty(this, 'prefix', {
80
- enumerable: true,
81
- set: (prefix) => {
82
- const g = this.get('global');
83
- this[g ? 'globalPrefix' : 'localPrefix'] = prefix;
84
- },
85
- get: () => {
86
- const g = this.get('global');
87
- return g ? this.globalPrefix : this.localPrefix;
88
- },
89
- });
90
- Object.defineProperty(this, 'globalPrefix', {
91
- enumerable: true,
92
- set: (prefix) => {
93
- this.set('prefix', prefix);
94
- },
95
- get: () => path_1.default.resolve(this.get('prefix')),
96
- });
97
- let p;
98
- Object.defineProperty(this, 'localPrefix', {
99
- enumerable: true,
100
- set: (prefix) => {
101
- p = prefix;
102
- },
103
- get: () => p,
104
- });
105
- if (Object.prototype.hasOwnProperty.call(cli, 'prefix')) {
106
- p = path_1.default.resolve(cli.prefix);
107
- }
108
- else {
109
- try {
110
- p = (0, find_prefix_1.findPrefix)(process.cwd());
111
- }
112
- catch (err) {
113
- throw err;
114
- }
115
- }
116
- return p;
117
- }
118
- // https://github.com/npm/npm/blob/latest/lib/config/load-cafile.js
119
- loadCAFile(file) {
120
- if (!file) {
121
- return;
122
- }
123
- try {
124
- const contents = fs_1.default.readFileSync(file, 'utf8');
125
- const delim = '-----END CERTIFICATE-----';
126
- const output = contents
127
- .split(delim)
128
- .filter((x) => Boolean(x.trim()))
129
- .map((x) => x.trimLeft() + delim);
130
- this.set('ca', output);
131
- }
132
- catch (err) {
133
- if (err.code === 'ENOENT') {
134
- return;
135
- }
136
- throw err;
137
- }
138
- }
139
- // https://github.com/npm/npm/blob/latest/lib/config/set-user.js
140
- loadUser() {
141
- const defConf = this.root;
142
- if (this.get('global')) {
143
- return;
144
- }
145
- if (process.env.SUDO_UID) {
146
- defConf.user = Number(process.env.SUDO_UID);
147
- return;
148
- }
149
- const prefix = path_1.default.resolve(this.get('prefix'));
150
- try {
151
- const stats = fs_1.default.statSync(prefix);
152
- defConf.user = stats.uid;
153
- }
154
- catch (err) {
155
- if (err.code === 'ENOENT') {
156
- return;
157
- }
158
- throw err;
159
- }
160
- }
161
- // https://github.com/npm/npm/blob/24ec9f2/lib/config/get-credentials-by-uri.js
162
- getCredentialsByURI(uri) {
163
- (0, assert_1.default)(uri && typeof uri === 'string', 'registry URL is required');
164
- const nerfed = (0, nerf_dart_1.toNerfDart)(uri);
165
- const defnerf = (0, nerf_dart_1.toNerfDart)(this.get('registry'));
166
- // hidden class micro-optimization
167
- const c = {
168
- scope: nerfed,
169
- token: undefined,
170
- password: undefined,
171
- username: undefined,
172
- email: undefined,
173
- auth: undefined,
174
- alwaysAuth: undefined,
175
- };
176
- // used to override scope matching for tokens as well as legacy auth
177
- if (this.get(`${nerfed}:always-auth`) !== undefined) {
178
- const val = this.get(`${nerfed}:always-auth`);
179
- c.alwaysAuth = val === 'false' ? false : !!val;
180
- }
181
- else if (this.get('always-auth') !== undefined) {
182
- c.alwaysAuth = this.get('always-auth');
183
- }
184
- if (this.get(`${nerfed}:_authToken`)) {
185
- c.token = this.get(`${nerfed}:_authToken`);
186
- // the bearer token is enough, don't confuse things
187
- return c;
188
- }
189
- // Handle the old-style _auth=<base64> style for the default registry, if set.
190
- let authDef = this.get('_auth');
191
- let userDef = this.get('username');
192
- let passDef = this.get('_password');
193
- if (authDef && !(userDef && passDef)) {
194
- authDef = Buffer.from(authDef, 'base64').toString();
195
- authDef = authDef.split(':');
196
- userDef = authDef.shift();
197
- passDef = authDef.join(':');
198
- }
199
- if (this.get(`${nerfed}:_password`)) {
200
- c.password = Buffer.from(this.get(`${nerfed}:_password`), 'base64').toString('utf8');
201
- }
202
- else if (nerfed === defnerf && passDef) {
203
- c.password = passDef;
204
- }
205
- if (this.get(`${nerfed}:username`)) {
206
- c.username = this.get(`${nerfed}:username`);
207
- }
208
- else if (nerfed === defnerf && userDef) {
209
- c.username = userDef;
210
- }
211
- if (this.get(`${nerfed}:email`)) {
212
- c.email = this.get(`${nerfed}:email`);
213
- }
214
- else if (this.get('email')) {
215
- c.email = this.get('email');
216
- }
217
- if (c.username && c.password) {
218
- c.auth = Buffer.from(`${c.username}:${c.password}`).toString('base64');
219
- }
220
- return c;
221
- }
222
- // https://github.com/npm/npm/blob/24ec9f2/lib/config/set-credentials-by-uri.js
223
- setCredentialsByURI(uri, c) {
224
- (0, assert_1.default)(uri && typeof uri === 'string', 'registry URL is required');
225
- (0, assert_1.default)(c && typeof c === 'object', 'credentials are required');
226
- const nerfed = (0, nerf_dart_1.toNerfDart)(uri);
227
- if (c.token) {
228
- this.set(`${nerfed}:_authToken`, c.token, 'user');
229
- this.del(`${nerfed}:_password`, 'user');
230
- this.del(`${nerfed}:username`, 'user');
231
- this.del(`${nerfed}:email`, 'user');
232
- this.del(`${nerfed}:always-auth`, 'user');
233
- }
234
- else if (c.username || c.password || c.email) {
235
- (0, assert_1.default)(c.username, 'must include username');
236
- (0, assert_1.default)(c.password, 'must include password');
237
- (0, assert_1.default)(c.email, 'must include email address');
238
- this.del(`${nerfed}:_authToken`, 'user');
239
- const encoded = Buffer.from(c.password, 'utf8').toString('base64');
240
- this.set(`${nerfed}:_password`, encoded, 'user');
241
- this.set(`${nerfed}:username`, c.username, 'user');
242
- this.set(`${nerfed}:email`, c.email, 'user');
243
- if (c.alwaysAuth !== undefined) {
244
- this.set(`${nerfed}:always-auth`, c.alwaysAuth, 'user');
245
- }
246
- else {
247
- this.del(`${nerfed}:always-auth`, 'user');
248
- }
249
- }
250
- else {
251
- throw new Error('No credentials to set.');
252
- }
253
- }
254
- }
255
- exports.Conf = Conf;
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.Conf = void 0;
7
+ const assert_1 = __importDefault(require("assert"));
8
+ const fs_1 = __importDefault(require("fs"));
9
+ const path_1 = __importDefault(require("path"));
10
+ // @ts-ignore
11
+ const config_chain_1 = require("config-chain");
12
+ const env_replace_1 = require("./env-replace");
13
+ const find_prefix_1 = require("./find-prefix");
14
+ const parse_field_1 = require("./parse-field");
15
+ const nerf_dart_1 = require("./nerf-dart");
16
+ class Conf extends config_chain_1.ConfigChain {
17
+ // https://github.com/npm/npm/blob/latest/lib/config/core.js#L208-L222
18
+ constructor(base) {
19
+ super(base);
20
+ this.globalPrefix = '';
21
+ this.localPrefix = '';
22
+ this.root = base;
23
+ }
24
+ // https://github.com/npm/npm/blob/latest/lib/config/core.js#L332-L342
25
+ add(data, marker) {
26
+ try {
27
+ /* eslint-disable no-param-reassign */
28
+ for (const x of Object.keys(data)) {
29
+ // https://github.com/npm/npm/commit/f0e998d
30
+ const newKey = (0, env_replace_1.envReplace)(x);
31
+ const newField = (0, parse_field_1.parseField)(data[x], newKey);
32
+ delete data[x];
33
+ data[newKey] = newField;
34
+ }
35
+ /* eslint-enable no-param-reassign */
36
+ }
37
+ catch (err) {
38
+ throw err;
39
+ }
40
+ return super.add(data, marker);
41
+ }
42
+ // https://github.com/npm/npm/blob/latest/lib/config/core.js#L312-L325
43
+ addFile(file, name = file) {
44
+ const marker = { __source__: name };
45
+ this.sources[name] = { path: file, type: 'ini' };
46
+ this.push(marker);
47
+ this._await();
48
+ try {
49
+ const contents = fs_1.default.readFileSync(file, 'utf8');
50
+ this.addString(contents, file, 'ini', marker);
51
+ }
52
+ catch (err) {
53
+ this.add({}, marker);
54
+ }
55
+ return this;
56
+ }
57
+ // https://github.com/npm/npm/blob/latest/lib/config/core.js#L344-L360
58
+ addEnv(env = process.env) {
59
+ const conf = {};
60
+ Object.keys(env)
61
+ .filter((x) => /^npm_config_/i.test(x))
62
+ .forEach((x) => {
63
+ if (!env[x]) {
64
+ return;
65
+ }
66
+ // leave first char untouched, even if it is a '_'
67
+ // convert all other '_' to '-'
68
+ const p = x
69
+ .toLowerCase()
70
+ .replace(/^npm_config_/, '')
71
+ .replace(/(?!^)_/g, '-');
72
+ conf[p] = env[x];
73
+ });
74
+ return super.addEnv('', conf, 'env');
75
+ }
76
+ // https://github.com/npm/npm/blob/latest/lib/config/load-prefix.js
77
+ loadPrefix() {
78
+ const cli = this.list[0];
79
+ Object.defineProperty(this, 'prefix', {
80
+ enumerable: true,
81
+ set: (prefix) => {
82
+ const g = this.get('global');
83
+ this[g ? 'globalPrefix' : 'localPrefix'] = prefix;
84
+ },
85
+ get: () => {
86
+ const g = this.get('global');
87
+ return g ? this.globalPrefix : this.localPrefix;
88
+ },
89
+ });
90
+ Object.defineProperty(this, 'globalPrefix', {
91
+ enumerable: true,
92
+ set: (prefix) => {
93
+ this.set('prefix', prefix);
94
+ },
95
+ get: () => path_1.default.resolve(this.get('prefix')),
96
+ });
97
+ let p;
98
+ Object.defineProperty(this, 'localPrefix', {
99
+ enumerable: true,
100
+ set: (prefix) => {
101
+ p = prefix;
102
+ },
103
+ get: () => p,
104
+ });
105
+ if (Object.prototype.hasOwnProperty.call(cli, 'prefix')) {
106
+ p = path_1.default.resolve(cli.prefix);
107
+ }
108
+ else {
109
+ try {
110
+ p = (0, find_prefix_1.findPrefix)(process.cwd());
111
+ }
112
+ catch (err) {
113
+ throw err;
114
+ }
115
+ }
116
+ return p;
117
+ }
118
+ // https://github.com/npm/npm/blob/latest/lib/config/load-cafile.js
119
+ loadCAFile(file) {
120
+ if (!file) {
121
+ return;
122
+ }
123
+ try {
124
+ const contents = fs_1.default.readFileSync(file, 'utf8');
125
+ const delim = '-----END CERTIFICATE-----';
126
+ const output = contents
127
+ .split(delim)
128
+ .filter((x) => Boolean(x.trim()))
129
+ .map((x) => x.trimLeft() + delim);
130
+ this.set('ca', output);
131
+ }
132
+ catch (err) {
133
+ if (err.code === 'ENOENT') {
134
+ return;
135
+ }
136
+ throw err;
137
+ }
138
+ }
139
+ // https://github.com/npm/npm/blob/latest/lib/config/set-user.js
140
+ loadUser() {
141
+ const defConf = this.root;
142
+ if (this.get('global')) {
143
+ return;
144
+ }
145
+ if (process.env.SUDO_UID) {
146
+ defConf.user = Number(process.env.SUDO_UID);
147
+ return;
148
+ }
149
+ const prefix = path_1.default.resolve(this.get('prefix'));
150
+ try {
151
+ const stats = fs_1.default.statSync(prefix);
152
+ defConf.user = stats.uid;
153
+ }
154
+ catch (err) {
155
+ if (err.code === 'ENOENT') {
156
+ return;
157
+ }
158
+ throw err;
159
+ }
160
+ }
161
+ // https://github.com/npm/npm/blob/24ec9f2/lib/config/get-credentials-by-uri.js
162
+ getCredentialsByURI(uri) {
163
+ (0, assert_1.default)(uri && typeof uri === 'string', 'registry URL is required');
164
+ const nerfed = (0, nerf_dart_1.toNerfDart)(uri);
165
+ const defnerf = (0, nerf_dart_1.toNerfDart)(this.get('registry'));
166
+ // hidden class micro-optimization
167
+ const c = {
168
+ scope: nerfed,
169
+ token: undefined,
170
+ password: undefined,
171
+ username: undefined,
172
+ email: undefined,
173
+ auth: undefined,
174
+ alwaysAuth: undefined,
175
+ };
176
+ // used to override scope matching for tokens as well as legacy auth
177
+ if (this.get(`${nerfed}:always-auth`) !== undefined) {
178
+ const val = this.get(`${nerfed}:always-auth`);
179
+ c.alwaysAuth = val === 'false' ? false : !!val;
180
+ }
181
+ else if (this.get('always-auth') !== undefined) {
182
+ c.alwaysAuth = this.get('always-auth');
183
+ }
184
+ if (this.get(`${nerfed}:_authToken`)) {
185
+ c.token = this.get(`${nerfed}:_authToken`);
186
+ // the bearer token is enough, don't confuse things
187
+ return c;
188
+ }
189
+ // Handle the old-style _auth=<base64> style for the default registry, if set.
190
+ let authDef = this.get('_auth');
191
+ let userDef = this.get('username');
192
+ let passDef = this.get('_password');
193
+ if (authDef && !(userDef && passDef)) {
194
+ authDef = Buffer.from(authDef, 'base64').toString();
195
+ authDef = authDef.split(':');
196
+ userDef = authDef.shift();
197
+ passDef = authDef.join(':');
198
+ }
199
+ if (this.get(`${nerfed}:_password`)) {
200
+ c.password = Buffer.from(this.get(`${nerfed}:_password`), 'base64').toString('utf8');
201
+ }
202
+ else if (nerfed === defnerf && passDef) {
203
+ c.password = passDef;
204
+ }
205
+ if (this.get(`${nerfed}:username`)) {
206
+ c.username = this.get(`${nerfed}:username`);
207
+ }
208
+ else if (nerfed === defnerf && userDef) {
209
+ c.username = userDef;
210
+ }
211
+ if (this.get(`${nerfed}:email`)) {
212
+ c.email = this.get(`${nerfed}:email`);
213
+ }
214
+ else if (this.get('email')) {
215
+ c.email = this.get('email');
216
+ }
217
+ if (c.username && c.password) {
218
+ c.auth = Buffer.from(`${c.username}:${c.password}`).toString('base64');
219
+ }
220
+ return c;
221
+ }
222
+ // https://github.com/npm/npm/blob/24ec9f2/lib/config/set-credentials-by-uri.js
223
+ setCredentialsByURI(uri, c) {
224
+ (0, assert_1.default)(uri && typeof uri === 'string', 'registry URL is required');
225
+ (0, assert_1.default)(c && typeof c === 'object', 'credentials are required');
226
+ const nerfed = (0, nerf_dart_1.toNerfDart)(uri);
227
+ if (c.token) {
228
+ this.set(`${nerfed}:_authToken`, c.token, 'user');
229
+ this.del(`${nerfed}:_password`, 'user');
230
+ this.del(`${nerfed}:username`, 'user');
231
+ this.del(`${nerfed}:email`, 'user');
232
+ this.del(`${nerfed}:always-auth`, 'user');
233
+ }
234
+ else if (c.username || c.password || c.email) {
235
+ (0, assert_1.default)(c.username, 'must include username');
236
+ (0, assert_1.default)(c.password, 'must include password');
237
+ (0, assert_1.default)(c.email, 'must include email address');
238
+ this.del(`${nerfed}:_authToken`, 'user');
239
+ const encoded = Buffer.from(c.password, 'utf8').toString('base64');
240
+ this.set(`${nerfed}:_password`, encoded, 'user');
241
+ this.set(`${nerfed}:username`, c.username, 'user');
242
+ this.set(`${nerfed}:email`, c.email, 'user');
243
+ if (c.alwaysAuth !== undefined) {
244
+ this.set(`${nerfed}:always-auth`, c.alwaysAuth, 'user');
245
+ }
246
+ else {
247
+ this.del(`${nerfed}:always-auth`, 'user');
248
+ }
249
+ }
250
+ else {
251
+ throw new Error('No credentials to set.');
252
+ }
253
+ }
254
+ }
255
+ exports.Conf = Conf;
256
256
  //# sourceMappingURL=conf.js.map
@@ -1 +1 @@
1
- export {};
1
+ export {};