@lerna-lite/core 1.3.0 → 1.5.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.
Files changed (146) hide show
  1. package/README.md +13 -12
  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 +271 -266
  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 +97 -85
  55. package/dist/package.js +320 -276
  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/make-file-finder.js.map +1 -1
  66. package/dist/project/lib/shallow-extend.d.ts +11 -11
  67. package/dist/project/lib/shallow-extend.js +24 -24
  68. package/dist/project/project.d.ts +45 -45
  69. package/dist/project/project.js +197 -195
  70. package/dist/project/project.js.map +1 -1
  71. package/dist/prompt.d.ts +23 -23
  72. package/dist/prompt.js +75 -75
  73. package/dist/utils/check-working-tree.d.ts +9 -8
  74. package/dist/utils/check-working-tree.js +41 -41
  75. package/dist/utils/check-working-tree.js.map +1 -1
  76. package/dist/utils/clean-stack.d.ts +5 -5
  77. package/dist/utils/clean-stack.js +18 -18
  78. package/dist/utils/collect-uncommitted.d.ts +17 -18
  79. package/dist/utils/collect-uncommitted.js +40 -40
  80. package/dist/utils/collect-uncommitted.js.map +1 -1
  81. package/dist/utils/collect-updates/collect-updates.d.ts +11 -11
  82. package/dist/utils/collect-updates/collect-updates.js +82 -82
  83. package/dist/utils/collect-updates/index.d.ts +2 -2
  84. package/dist/utils/collect-updates/index.js +18 -18
  85. package/dist/utils/collect-updates/lib/collect-dependents.d.ts +11 -11
  86. package/dist/utils/collect-updates/lib/collect-dependents.js +45 -45
  87. package/dist/utils/collect-updates/lib/collect-packages.d.ts +13 -13
  88. package/dist/utils/collect-updates/lib/collect-packages.js +33 -33
  89. package/dist/utils/collect-updates/lib/get-packages-for-option.d.ts +5 -5
  90. package/dist/utils/collect-updates/lib/get-packages-for-option.js +30 -30
  91. package/dist/utils/collect-updates/lib/has-tags.d.ts +5 -5
  92. package/dist/utils/collect-updates/lib/has-tags.js +26 -26
  93. package/dist/utils/collect-updates/lib/index.d.ts +5 -5
  94. package/dist/utils/collect-updates/lib/index.js +21 -21
  95. package/dist/utils/collect-updates/lib/make-diff-predicate.d.ts +7 -7
  96. package/dist/utils/collect-updates/lib/make-diff-predicate.js +64 -64
  97. package/dist/utils/conf.d.ts +25 -25
  98. package/dist/utils/conf.js +255 -255
  99. package/dist/utils/defaults.d.ts +1 -1
  100. package/dist/utils/defaults.js +182 -182
  101. package/dist/utils/defaults.js.map +1 -1
  102. package/dist/utils/describe-ref.d.ts +13 -37
  103. package/dist/utils/describe-ref.js +80 -80
  104. package/dist/utils/describe-ref.js.map +1 -1
  105. package/dist/utils/env-replace.d.ts +1 -1
  106. package/dist/utils/env-replace.js +22 -22
  107. package/dist/utils/find-prefix.d.ts +2 -2
  108. package/dist/utils/find-prefix.js +48 -48
  109. package/dist/utils/index.d.ts +21 -22
  110. package/dist/utils/index.js +38 -38
  111. package/dist/utils/index.js.map +1 -1
  112. package/dist/utils/log-package-error.d.ts +5 -5
  113. package/dist/utils/log-package-error.js +35 -35
  114. package/dist/utils/nerf-dart.d.ts +1 -1
  115. package/dist/utils/nerf-dart.js +18 -18
  116. package/dist/utils/npm-conf.d.ts +4 -4
  117. package/dist/utils/npm-conf.js +56 -55
  118. package/dist/utils/npm-conf.js.map +1 -1
  119. package/dist/utils/output.d.ts +1 -1
  120. package/dist/utils/output.js +13 -13
  121. package/dist/utils/parse-field.d.ts +1 -1
  122. package/dist/utils/parse-field.js +65 -65
  123. package/dist/utils/prerelease-id-from-version.d.ts +5 -5
  124. package/dist/utils/prerelease-id-from-version.js +15 -15
  125. package/dist/utils/pulse-till-done.d.ts +1 -1
  126. package/dist/utils/pulse-till-done.js +40 -40
  127. package/dist/utils/query-graph.d.ts +36 -36
  128. package/dist/utils/query-graph.js +77 -77
  129. package/dist/utils/query-graph.js.map +1 -1
  130. package/dist/utils/run-lifecycle.d.ts +10 -10
  131. package/dist/utils/run-lifecycle.js +131 -107
  132. package/dist/utils/run-lifecycle.js.map +1 -1
  133. package/dist/utils/run-topologically.d.ts +12 -12
  134. package/dist/utils/run-topologically.js +36 -36
  135. package/dist/utils/temp-write.d.ts +13 -0
  136. package/dist/utils/temp-write.js +50 -0
  137. package/dist/utils/temp-write.js.map +1 -0
  138. package/dist/utils/types.d.ts +131 -129
  139. package/dist/utils/types.js +138 -138
  140. package/dist/utils/warn-if-hanging.d.ts +1 -1
  141. package/dist/utils/warn-if-hanging.js +17 -17
  142. package/dist/utils/write-log-file.d.ts +1 -1
  143. package/dist/utils/write-log-file.js +32 -32
  144. package/dist/validation-error.d.ts +4 -4
  145. package/dist/validation-error.js +18 -18
  146. package/package.json +17 -12
package/dist/package.js CHANGED
@@ -1,277 +1,321 @@
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.Package = void 0;
7
- const npm_package_arg_1 = __importDefault(require("npm-package-arg"));
8
- const path_1 = __importDefault(require("path"));
9
- const load_json_file_1 = __importDefault(require("load-json-file"));
10
- const write_pkg_1 = __importDefault(require("write-pkg"));
11
- // symbol used to 'hide' internal state
12
- const PKG = Symbol('pkg');
13
- // private fields
14
- const _location = Symbol('location');
15
- const _resolved = Symbol('resolved');
16
- const _rootPath = Symbol('rootPath');
17
- const _scripts = Symbol('scripts');
18
- const _contents = Symbol('contents');
19
- /**
20
- * @param {import('npm-package-arg').Result} result
21
- */
22
- function binSafeName({ name, scope }) {
23
- return scope ? name.substring(scope.length + 1) : name;
24
- }
25
- // package.json files are not that complicated, so this is intentionally naïve
26
- function shallowCopy(json) {
27
- return Object.keys(json).reduce((obj, key) => {
28
- const val = json[key];
29
- /* istanbul ignore if */
30
- if (Array.isArray(val)) {
31
- obj[key] = val.slice();
32
- }
33
- else if (val && typeof val === 'object') {
34
- obj[key] = Object.assign({}, val);
35
- }
36
- else {
37
- obj[key] = val;
38
- }
39
- return obj;
40
- }, {});
41
- }
42
- /**
43
- * Lerna's internal representation of a local package, with
44
- * many values resolved directly from the original JSON.
45
- */
46
- class Package {
47
- /**
48
- * @param {RawManifest} pkg
49
- * @param {string} location
50
- * @param {string} [rootPath]
51
- */
52
- constructor(pkg, location, rootPath = location) {
53
- var _a, _b;
54
- this._id = '';
55
- this.licensePath = '';
56
- this.localDependencies = new Map();
57
- // npa will throw an error if the name is invalid
58
- const resolved = npm_package_arg_1.default.resolve((_a = pkg === null || pkg === void 0 ? void 0 : pkg.name) !== null && _a !== void 0 ? _a : '', `file:${path_1.default.relative(rootPath, location)}`, rootPath);
59
- this.name = (_b = pkg === null || pkg === void 0 ? void 0 : pkg.name) !== null && _b !== void 0 ? _b : '';
60
- this[PKG] = pkg;
61
- // omit raw pkg from default util.inspect() output, but preserve internal mutability
62
- Object.defineProperty(this, PKG, { enumerable: false, writable: true });
63
- this[_location] = location;
64
- this[_resolved] = resolved;
65
- this[_rootPath] = rootPath;
66
- this[_scripts] = { ...pkg.scripts };
67
- }
68
- /**
69
- * Create a Package instance from parameters, possibly reusing existing instance.
70
- * @param {string|Package|RawManifest} ref A path to a package.json file, Package instance, or JSON object
71
- * @param {string} [dir] If `ref` is a JSON object, this is the location of the manifest
72
- * @returns {Package}
73
- */
74
- static lazy(ref, dir = '.') {
75
- if (typeof ref === 'string') {
76
- const location = path_1.default.resolve(path_1.default.basename(ref) === 'package.json' ? path_1.default.dirname(ref) : ref);
77
- const manifest = load_json_file_1.default.sync(path_1.default.join(location, 'package.json'));
78
- return new Package(manifest, location);
79
- }
80
- // don't use instanceof because it fails across nested module boundaries
81
- if ('__isLernaPackage' in ref) {
82
- return ref;
83
- }
84
- // assume ref is a json object
85
- return new Package(ref, dir);
86
- }
87
- // readonly getters
88
- get location() {
89
- return this[_location];
90
- }
91
- get private() {
92
- return Boolean(this[PKG].private);
93
- }
94
- get resolved() {
95
- return this[_resolved];
96
- }
97
- get rootPath() {
98
- return this[_rootPath];
99
- }
100
- get scripts() {
101
- return this[_scripts];
102
- }
103
- get bin() {
104
- const pkg = this[PKG];
105
- return typeof pkg.bin === 'string'
106
- ? { [binSafeName(this.resolved)]: pkg.bin, }
107
- : Object.assign({}, pkg.bin);
108
- }
109
- get binLocation() {
110
- return path_1.default.join(this.location, 'node_modules', '.bin');
111
- }
112
- get manifestLocation() {
113
- return path_1.default.join(this.location, 'package.json');
114
- }
115
- get nodeModulesLocation() {
116
- return path_1.default.join(this.location, 'node_modules');
117
- }
118
- // eslint-disable-next-line class-methods-use-this
119
- get __isLernaPackage() {
120
- // safer than instanceof across module boundaries
121
- return true;
122
- }
123
- // accessors
124
- get version() {
125
- return this[PKG].version;
126
- }
127
- set version(version) {
128
- this[PKG].version = version;
129
- }
130
- get contents() {
131
- // if modified with setter, use that value
132
- if (this[_contents]) {
133
- return this[_contents];
134
- }
135
- // if provided by pkg.publishConfig.directory value
136
- if (this[PKG].publishConfig && this[PKG].publishConfig.directory) {
137
- return path_1.default.join(this.location, this[PKG].publishConfig.directory);
138
- }
139
- // default to package root
140
- return this.location;
141
- }
142
- set contents(subDirectory) {
143
- this[_contents] = path_1.default.join(this.location, subDirectory);
144
- }
145
- // 'live' collections
146
- get dependencies() {
147
- return this[PKG].dependencies;
148
- }
149
- get devDependencies() {
150
- return this[PKG].devDependencies;
151
- }
152
- get optionalDependencies() {
153
- return this[PKG].optionalDependencies;
154
- }
155
- get peerDependencies() {
156
- return this[PKG].peerDependencies;
157
- }
158
- get pkg() {
159
- return this[PKG];
160
- }
161
- /**
162
- * Map-like retrieval of arbitrary values
163
- * @template {keyof RawManifest} K
164
- * @param {K} key field name to retrieve value
165
- * @returns {RawManifest[K]} value stored under key, if present
166
- */
167
- get(key) {
168
- return this[PKG][key];
169
- }
170
- /**
171
- * Map-like storage of arbitrary values
172
- * @template {keyof RawManifest} K
173
- * @param {T} key field name to store value
174
- * @param {RawManifest[K]} val value to store
175
- * @returns {Package} instance for chaining
176
- */
177
- set(key, val) {
178
- this[PKG][key] = val;
179
- return this;
180
- }
181
- /**
182
- * Provide shallow copy for munging elsewhere
183
- * @returns {Object}
184
- */
185
- toJSON() {
186
- return shallowCopy(this[PKG]);
187
- }
188
- /**
189
- * Refresh internal state from disk (e.g., changed by external lifecycles)
190
- */
191
- refresh() {
192
- return (0, load_json_file_1.default)(this.manifestLocation).then((pkg) => {
193
- this[PKG] = pkg;
194
- return this;
195
- });
196
- }
197
- /**
198
- * Write manifest changes to disk
199
- * @returns {Promise} resolves when write finished
200
- */
201
- serialize() {
202
- return (0, write_pkg_1.default)(this.manifestLocation, this[PKG]).then(() => this);
203
- }
204
- /**
205
- * Mutate local dependency spec according to type
206
- * @param {Object} resolved npa metadata
207
- * @param {String} depVersion semver
208
- * @param {String} savePrefix npm_config_save_prefix
209
- * @param {Boolean} workspaceStrictMatch - are we using strict match with `workspace:` protocol
210
- * @param {String} updatedByCommand - which command called this update?
211
- */
212
- updateLocalDependency(resolved, depVersion, savePrefix, workspaceStrictMatch = true, updatedByCommand) {
213
- var _a;
214
- const depName = resolved.name;
215
- // first, try runtime dependencies
216
- let depCollection = this.dependencies;
217
- // try optionalDependencies if that didn't work
218
- if (!depCollection || !depCollection[depName]) {
219
- depCollection = this.optionalDependencies;
220
- }
221
- // fall back to devDependencies
222
- if (!depCollection || !depCollection[depName]) {
223
- depCollection = this.devDependencies;
224
- }
225
- if (depCollection && (resolved.registry || resolved.type === 'directory')) {
226
- // a version (1.2.3) OR range (^1.2.3) OR directory (file:../foo-pkg)
227
- depCollection[depName] = `${savePrefix}${depVersion}`;
228
- // when using explicit `workspace:` protocol
229
- if (resolved.explicitWorkspace) {
230
- const workspaceTarget = (_a = resolved === null || resolved === void 0 ? void 0 : resolved.workspaceTarget) !== null && _a !== void 0 ? _a : '';
231
- if (updatedByCommand === 'publish') {
232
- // when publishing, workspace protocol will be transformed to semver range
233
- // e.g.: considering version is `1.2.3` and we have `workspace:*` it will be converted to "^1.2.3" or to "1.2.3" with strict match range enabled
234
- if (workspaceStrictMatch) {
235
- if (workspaceTarget === 'workspace:*') {
236
- depCollection[depName] = depVersion; // (*) exact range, "1.5.0"
237
- }
238
- else if (workspaceTarget === 'workspace:~') {
239
- depCollection[depName] = `~${depVersion}`; // (~) patch range, "~1.5.0"
240
- }
241
- else if (workspaceTarget === 'workspace:^') {
242
- depCollection[depName] = `^${depVersion}`; // (^) minor range, "^1.5.0"
243
- }
244
- }
245
- // anything else will fall under what Lerna previously found to be the version,
246
- // typically by this line: depCollection[depName] = `${savePrefix}${depVersion}`;
247
- }
248
- else {
249
- // when versioning we'll only bump workspace protocol that have semver range like `workspace:^1.2.3`
250
- // any other workspace will remain the same in `package.json` file, for example `workspace:^`
251
- // keep target workspace or bump when it's a workspace semver range (like `workspace:^1.2.3`)
252
- depCollection[depName] = /^workspace:[*|^|~]{1}$/.test(workspaceTarget)
253
- ? resolved.workspaceTarget // target like `workspace:^` => `workspace:^` (remains untouched in package.json)
254
- : `workspace:${depCollection[depName]}`; // range like `workspace:^1.2.3` => `workspace:^1.3.3` (bump minor example)
255
- }
256
- }
257
- }
258
- else if (resolved.gitCommittish) {
259
- // a git url with matching committish (#v1.2.3 or #1.2.3)
260
- const [tagPrefix] = /^\D*/.exec(resolved.gitCommittish);
261
- // update committish
262
- const { hosted } = resolved; // take that, lint!
263
- hosted.committish = `${tagPrefix}${depVersion}`;
264
- // always serialize the full url (identical to previous resolved.saveSpec)
265
- depCollection[depName] = hosted.toString({ noGitPlus: false, noCommittish: false });
266
- }
267
- else if (resolved.gitRange) {
268
- // a git url with matching gitRange (#semver:^1.2.3)
269
- const { hosted } = resolved; // take that, lint!
270
- hosted.committish = `semver:${savePrefix}${depVersion}`;
271
- // always serialize the full url (identical to previous resolved.saveSpec)
272
- depCollection[depName] = hosted.toString({ noGitPlus: false, noCommittish: false });
273
- }
274
- }
275
- }
276
- exports.Package = Package;
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.Package = void 0;
7
+ const load_json_file_1 = __importDefault(require("load-json-file"));
8
+ const npm_package_arg_1 = __importDefault(require("npm-package-arg"));
9
+ const npmlog_1 = __importDefault(require("npmlog"));
10
+ const path_1 = __importDefault(require("path"));
11
+ const write_pkg_1 = __importDefault(require("write-pkg"));
12
+ // symbol used to 'hide' internal state
13
+ const PKG = Symbol('pkg');
14
+ // private fields
15
+ const _location = Symbol('location');
16
+ const _resolved = Symbol('resolved');
17
+ const _rootPath = Symbol('rootPath');
18
+ const _scripts = Symbol('scripts');
19
+ const _contents = Symbol('contents');
20
+ /**
21
+ * @param {import('npm-package-arg').Result} result
22
+ */
23
+ function binSafeName({ name, scope }) {
24
+ return scope ? name.substring(scope.length + 1) : name;
25
+ }
26
+ // package.json files are not that complicated, so this is intentionally naïve
27
+ function shallowCopy(json) {
28
+ return Object.keys(json).reduce((obj, key) => {
29
+ const val = json[key];
30
+ /* istanbul ignore if */
31
+ if (Array.isArray(val)) {
32
+ obj[key] = val.slice();
33
+ }
34
+ else if (val && typeof val === 'object') {
35
+ obj[key] = Object.assign({}, val);
36
+ }
37
+ else {
38
+ obj[key] = val;
39
+ }
40
+ return obj;
41
+ }, {});
42
+ }
43
+ /**
44
+ * Lerna's internal representation of a local package, with
45
+ * many values resolved directly from the original JSON.
46
+ */
47
+ class Package {
48
+ /**
49
+ * @param {RawManifest} pkg
50
+ * @param {string} location
51
+ * @param {string} [rootPath]
52
+ */
53
+ constructor(pkg, location, rootPath = location) {
54
+ var _a, _b;
55
+ this._id = '';
56
+ this.licensePath = '';
57
+ this.localDependencies = new Map();
58
+ // npa will throw an error if the name is invalid
59
+ const resolved = npm_package_arg_1.default.resolve((_a = pkg === null || pkg === void 0 ? void 0 : pkg.name) !== null && _a !== void 0 ? _a : '', `file:${path_1.default.relative(rootPath, location)}`, rootPath);
60
+ this.name = (_b = pkg === null || pkg === void 0 ? void 0 : pkg.name) !== null && _b !== void 0 ? _b : '';
61
+ this[PKG] = pkg;
62
+ // omit raw pkg from default util.inspect() output, but preserve internal mutability
63
+ Object.defineProperty(this, PKG, { enumerable: false, writable: true });
64
+ this[_location] = location;
65
+ this[_resolved] = resolved;
66
+ this[_rootPath] = rootPath;
67
+ this[_scripts] = { ...pkg.scripts };
68
+ }
69
+ /**
70
+ * Create a Package instance from parameters, possibly reusing existing instance.
71
+ * @param {string|Package|RawManifest} ref A path to a package.json file, Package instance, or JSON object
72
+ * @param {string} [dir] If `ref` is a JSON object, this is the location of the manifest
73
+ * @returns {Package}
74
+ */
75
+ static lazy(ref, dir = '.') {
76
+ if (typeof ref === 'string') {
77
+ const location = path_1.default.resolve(path_1.default.basename(ref) === 'package.json' ? path_1.default.dirname(ref) : ref);
78
+ const manifest = load_json_file_1.default.sync(path_1.default.join(location, 'package.json'));
79
+ return new Package(manifest, location);
80
+ }
81
+ // don't use instanceof because it fails across nested module boundaries
82
+ if ('__isLernaPackage' in ref) {
83
+ return ref;
84
+ }
85
+ // assume ref is a json object
86
+ return new Package(ref, dir);
87
+ }
88
+ // readonly getters
89
+ get location() {
90
+ return this[_location];
91
+ }
92
+ get private() {
93
+ return Boolean(this[PKG].private);
94
+ }
95
+ get resolved() {
96
+ return this[_resolved];
97
+ }
98
+ get rootPath() {
99
+ return this[_rootPath];
100
+ }
101
+ get scripts() {
102
+ return this[_scripts];
103
+ }
104
+ get bin() {
105
+ const pkg = this[PKG];
106
+ return typeof pkg.bin === 'string'
107
+ ? { [binSafeName(this.resolved)]: pkg.bin }
108
+ : Object.assign({}, pkg.bin);
109
+ }
110
+ get binLocation() {
111
+ return path_1.default.join(this.location, 'node_modules', '.bin');
112
+ }
113
+ get manifestLocation() {
114
+ return path_1.default.join(this.location, 'package.json');
115
+ }
116
+ get nodeModulesLocation() {
117
+ return path_1.default.join(this.location, 'node_modules');
118
+ }
119
+ // eslint-disable-next-line class-methods-use-this
120
+ get __isLernaPackage() {
121
+ // safer than instanceof across module boundaries
122
+ return true;
123
+ }
124
+ // accessors
125
+ get version() {
126
+ return this[PKG].version;
127
+ }
128
+ set version(version) {
129
+ this[PKG].version = version;
130
+ }
131
+ get workspaces() {
132
+ return this[PKG].workspaces;
133
+ }
134
+ set workspaces(workspaces) {
135
+ this[PKG].workspaces = workspaces;
136
+ }
137
+ get contents() {
138
+ // if modified with setter, use that value
139
+ if (this[_contents]) {
140
+ return this[_contents];
141
+ }
142
+ // if provided by pkg.publishConfig.directory value
143
+ if (this[PKG].publishConfig && this[PKG].publishConfig.directory) {
144
+ return path_1.default.join(this.location, this[PKG].publishConfig.directory);
145
+ }
146
+ // default to package root
147
+ return this.location;
148
+ }
149
+ set contents(subDirectory) {
150
+ this[_contents] = path_1.default.join(this.location, subDirectory);
151
+ }
152
+ // 'live' collections
153
+ get dependencies() {
154
+ return this[PKG].dependencies;
155
+ }
156
+ get devDependencies() {
157
+ return this[PKG].devDependencies;
158
+ }
159
+ get optionalDependencies() {
160
+ return this[PKG].optionalDependencies;
161
+ }
162
+ get peerDependencies() {
163
+ return this[PKG].peerDependencies;
164
+ }
165
+ get pkg() {
166
+ return this[PKG];
167
+ }
168
+ /**
169
+ * Map-like retrieval of arbitrary values
170
+ * @template {keyof RawManifest} K
171
+ * @param {K} key field name to retrieve value
172
+ * @returns {RawManifest[K]} value stored under key, if present
173
+ */
174
+ get(key) {
175
+ return this[PKG][key];
176
+ }
177
+ /**
178
+ * Map-like storage of arbitrary values
179
+ * @template {keyof RawManifest} K
180
+ * @param {T} key field name to store value
181
+ * @param {RawManifest[K]} val value to store
182
+ * @returns {Package} instance for chaining
183
+ */
184
+ set(key, val) {
185
+ this[PKG][key] = val;
186
+ return this;
187
+ }
188
+ /**
189
+ * Provide shallow copy for munging elsewhere
190
+ * @returns {Object}
191
+ */
192
+ toJSON() {
193
+ return shallowCopy(this[PKG]);
194
+ }
195
+ /**
196
+ * Refresh internal state from disk (e.g., changed by external lifecycles)
197
+ */
198
+ refresh() {
199
+ return (0, load_json_file_1.default)(this.manifestLocation).then((pkg) => {
200
+ this[PKG] = pkg;
201
+ return this;
202
+ });
203
+ }
204
+ /**
205
+ * Write manifest changes to disk
206
+ * @returns {Promise} resolves when write finished
207
+ */
208
+ serialize() {
209
+ return (0, write_pkg_1.default)(this.manifestLocation, this[PKG]).then(() => this);
210
+ }
211
+ /**
212
+ * Mutate given dependency (could be local/external) spec according to type
213
+ * @param {Object} resolved npa metadata
214
+ */
215
+ removeDependencyWorkspaceProtocolPrefix(pkgName, resolved) {
216
+ var _a;
217
+ const depName = resolved.name;
218
+ const depCollection = this.retrievePackageDependencies(depName);
219
+ const workspaceTarget = (_a = resolved === null || resolved === void 0 ? void 0 : resolved.workspaceTarget) !== null && _a !== void 0 ? _a : '';
220
+ if (depCollection &&
221
+ (resolved.registry || resolved.type === 'directory') &&
222
+ /^(workspace:)+(.*)$/.test(workspaceTarget)) {
223
+ if (workspaceTarget) {
224
+ if (resolved.fetchSpec === 'latest') {
225
+ npmlog_1.default.error(`publish`, [
226
+ `Your package named "${pkgName}" has external dependencies not handled by Lerna-Lite and without workspace version suffix, `,
227
+ `we recommend using defined versions with workspace protocol. `,
228
+ `Your dependency is currently being published with "${depName}": "${resolved.fetchSpec}".`,
229
+ ].join(''));
230
+ }
231
+ depCollection[depName] = resolved.fetchSpec;
232
+ }
233
+ }
234
+ }
235
+ /**
236
+ * Mutate local dependency spec according to type
237
+ * @param {Object} resolved npa metadata
238
+ * @param {String} depVersion semver
239
+ * @param {String} savePrefix npm_config_save_prefix
240
+ * @param {Boolean} [workspaceStrictMatch] - are we using `workspace:` protocol strict match?
241
+ * @param {String} [updatedByCommand] - which command called this update?
242
+ */
243
+ updateLocalDependency(resolved, depVersion, savePrefix, workspaceStrictMatch = true, updatedByCommand) {
244
+ var _a;
245
+ const depName = resolved.name;
246
+ const depCollection = this.retrievePackageDependencies(depName);
247
+ if (depCollection && (resolved.registry || resolved.type === 'directory')) {
248
+ // a version (1.2.3) OR range (^1.2.3) OR directory (file:../foo-pkg)
249
+ depCollection[depName] = `${savePrefix}${depVersion}`;
250
+ // when using explicit `workspace:` protocol
251
+ if (resolved.explicitWorkspace) {
252
+ const workspaceTarget = (_a = resolved === null || resolved === void 0 ? void 0 : resolved.workspaceTarget) !== null && _a !== void 0 ? _a : '';
253
+ const [_, _wsTxt, operatorPrefix, rangePrefix] = workspaceTarget.match(/^(workspace:)?([<>=]{0,2})?([*^~])?(.*)$/);
254
+ if (operatorPrefix) {
255
+ // with workspace it might include an operator, if so use it like "workspace:>=1.2.3"
256
+ depCollection[depName] = `${operatorPrefix}${depVersion}`;
257
+ }
258
+ else if (workspaceStrictMatch) {
259
+ // with workspace in strict mode we might have empty range prefix like "workspace:1.2.3"
260
+ depCollection[depName] = `${rangePrefix || ''}${depVersion}`;
261
+ }
262
+ if (updatedByCommand === 'publish') {
263
+ // when publishing, workspace protocol will be transformed to semver range
264
+ // e.g.: considering version is `1.2.3` and we have `workspace:*` it will be converted to "^1.2.3" or to "1.2.3" with strict match range enabled
265
+ if (workspaceStrictMatch) {
266
+ if (workspaceTarget === 'workspace:*') {
267
+ depCollection[depName] = depVersion; // (*) exact range, "1.5.0"
268
+ }
269
+ else if (workspaceTarget === 'workspace:~') {
270
+ depCollection[depName] = `~${depVersion}`; // (~) patch range, "~1.5.0"
271
+ }
272
+ else if (workspaceTarget === 'workspace:^') {
273
+ depCollection[depName] = `^${depVersion}`; // (^) minor range, "^1.5.0"
274
+ }
275
+ }
276
+ // anything else will fall under what Lerna previously found to be the version,
277
+ // typically by this line: depCollection[depName] = `${savePrefix}${depVersion}`;
278
+ }
279
+ else {
280
+ // when versioning we'll only bump workspace protocol that have semver range like `workspace:^1.2.3`
281
+ // any other workspace will remain the same in `package.json` file, for example `workspace:^`
282
+ // keep target workspace or bump when it's a workspace semver range (like `workspace:^1.2.3`)
283
+ depCollection[depName] = /^workspace:[*^~]{1}$/.test(workspaceTarget)
284
+ ? resolved.workspaceTarget // target like `workspace:^` => `workspace:^` (remains untouched in package.json)
285
+ : `workspace:${depCollection[depName]}`; // range like `workspace:^1.2.3` => `workspace:^1.3.3` (bump minor example)
286
+ }
287
+ }
288
+ }
289
+ else if (resolved.gitCommittish) {
290
+ // a git url with matching committish (#v1.2.3 or #1.2.3)
291
+ const [tagPrefix] = /^\D*/.exec(resolved.gitCommittish);
292
+ // update committish
293
+ const { hosted } = resolved; // take that, lint!
294
+ hosted.committish = `${tagPrefix}${depVersion}`;
295
+ // always serialize the full url (identical to previous resolved.saveSpec)
296
+ depCollection[depName] = hosted.toString({ noGitPlus: false, noCommittish: false });
297
+ }
298
+ else if (resolved.gitRange) {
299
+ // a git url with matching gitRange (#semver:^1.2.3)
300
+ const { hosted } = resolved; // take that, lint!
301
+ hosted.committish = `semver:${savePrefix}${depVersion}`;
302
+ // always serialize the full url (identical to previous resolved.saveSpec)
303
+ depCollection[depName] = hosted.toString({ noGitPlus: false, noCommittish: false });
304
+ }
305
+ }
306
+ retrievePackageDependencies(depName) {
307
+ // first, try runtime dependencies
308
+ let depCollection = this.dependencies;
309
+ // try optionalDependencies if that didn't work
310
+ if (!depCollection || !depCollection[depName]) {
311
+ depCollection = this.optionalDependencies;
312
+ }
313
+ // fall back to devDependencies
314
+ if (!depCollection || !depCollection[depName]) {
315
+ depCollection = this.devDependencies;
316
+ }
317
+ return depCollection;
318
+ }
319
+ }
320
+ exports.Package = Package;
277
321
  //# sourceMappingURL=package.js.map