@ts-dev-tools/core 1.9.14 → 1.11.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.
- package/dist/install/command.js +4 -0
- package/dist/services/PackageManagerService.d.ts +3 -5
- package/dist/services/PackageManagerService.js +23 -208
- package/dist/services/PeerDependenciesService.d.ts +14 -0
- package/dist/services/PeerDependenciesService.js +234 -0
- package/dist/services/SymlinkDependenciesService.js +9 -4
- package/dist/services/package-manager/AbstractPackageManagerAdapter.d.ts +16 -0
- package/dist/services/package-manager/AbstractPackageManagerAdapter.js +155 -0
- package/dist/services/package-manager/NpmPackageManagerAdapter.d.ts +7 -0
- package/dist/services/package-manager/NpmPackageManagerAdapter.js +165 -0
- package/dist/services/package-manager/PackageManagerAdapter.d.ts +6 -0
- package/dist/services/package-manager/PackageManagerAdapter.js +2 -0
- package/dist/services/package-manager/PackageManagerType.d.ts +4 -0
- package/dist/services/package-manager/PackageManagerType.js +8 -0
- package/dist/services/package-manager/YarnPackageManagerAdapter.d.ts +14 -0
- package/dist/services/package-manager/YarnPackageManagerAdapter.js +321 -0
- package/package.json +2 -2
|
@@ -0,0 +1,321 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __extends = (this && this.__extends) || (function () {
|
|
3
|
+
var extendStatics = function (d, b) {
|
|
4
|
+
extendStatics = Object.setPrototypeOf ||
|
|
5
|
+
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
|
6
|
+
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
|
|
7
|
+
return extendStatics(d, b);
|
|
8
|
+
};
|
|
9
|
+
return function (d, b) {
|
|
10
|
+
if (typeof b !== "function" && b !== null)
|
|
11
|
+
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
|
|
12
|
+
extendStatics(d, b);
|
|
13
|
+
function __() { this.constructor = d; }
|
|
14
|
+
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
|
15
|
+
};
|
|
16
|
+
})();
|
|
17
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
18
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
19
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
20
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
21
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
22
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
23
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
24
|
+
});
|
|
25
|
+
};
|
|
26
|
+
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
27
|
+
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype);
|
|
28
|
+
return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
29
|
+
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
30
|
+
function step(op) {
|
|
31
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
32
|
+
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
|
33
|
+
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
34
|
+
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
35
|
+
switch (op[0]) {
|
|
36
|
+
case 0: case 1: t = op; break;
|
|
37
|
+
case 4: _.label++; return { value: op[1], done: false };
|
|
38
|
+
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
39
|
+
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
40
|
+
default:
|
|
41
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
42
|
+
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
43
|
+
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
44
|
+
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
45
|
+
if (t[2]) _.ops.pop();
|
|
46
|
+
_.trys.pop(); continue;
|
|
47
|
+
}
|
|
48
|
+
op = body.call(thisArg, _);
|
|
49
|
+
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
50
|
+
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
51
|
+
}
|
|
52
|
+
};
|
|
53
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
54
|
+
exports.YarnPackageManagerAdapter = void 0;
|
|
55
|
+
var path_1 = require("path");
|
|
56
|
+
var AbstractPackageManagerAdapter_1 = require("./AbstractPackageManagerAdapter");
|
|
57
|
+
var PackageManagerType_1 = require("./PackageManagerType");
|
|
58
|
+
var YarnPackageManagerAdapter = /** @class */ (function (_super) {
|
|
59
|
+
__extends(YarnPackageManagerAdapter, _super);
|
|
60
|
+
function YarnPackageManagerAdapter() {
|
|
61
|
+
return _super !== null && _super.apply(this, arguments) || this;
|
|
62
|
+
}
|
|
63
|
+
YarnPackageManagerAdapter.prototype.addDevPackage = function (packageName, dirPath) {
|
|
64
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
65
|
+
var isMonorepo, major, args, error_1, retryArgs;
|
|
66
|
+
return __generator(this, function (_a) {
|
|
67
|
+
switch (_a.label) {
|
|
68
|
+
case 0: return [4 /*yield*/, this.isMonorepo(dirPath)];
|
|
69
|
+
case 1:
|
|
70
|
+
isMonorepo = _a.sent();
|
|
71
|
+
return [4 /*yield*/, this.getVersion(PackageManagerType_1.PackageManagerType.yarn, dirPath)];
|
|
72
|
+
case 2:
|
|
73
|
+
major = (_a.sent()).major;
|
|
74
|
+
args = ["yarn", "add", "--dev"];
|
|
75
|
+
if (isMonorepo) {
|
|
76
|
+
args.push(major >= 2 ? "-W" : "--ignore-workspace-root-check");
|
|
77
|
+
}
|
|
78
|
+
args.push(packageName);
|
|
79
|
+
_a.label = 3;
|
|
80
|
+
case 3:
|
|
81
|
+
_a.trys.push([3, 5, , 8]);
|
|
82
|
+
return [4 /*yield*/, this.execCommand(args, dirPath, true)];
|
|
83
|
+
case 4:
|
|
84
|
+
_a.sent();
|
|
85
|
+
return [3 /*break*/, 8];
|
|
86
|
+
case 5:
|
|
87
|
+
error_1 = _a.sent();
|
|
88
|
+
if (!(isMonorepo && typeof error_1 === "string" && error_1.includes("Unsupported option name"))) return [3 /*break*/, 7];
|
|
89
|
+
retryArgs = args
|
|
90
|
+
.filter(function (arg) { return arg !== "--ignore-workspace-root-check" && arg !== "-W"; })
|
|
91
|
+
.concat(major >= 2 ? "--ignore-workspace-root-check" : "-W");
|
|
92
|
+
return [4 /*yield*/, this.execCommand(retryArgs, dirPath, true)];
|
|
93
|
+
case 6:
|
|
94
|
+
_a.sent();
|
|
95
|
+
return [2 /*return*/];
|
|
96
|
+
case 7: throw error_1;
|
|
97
|
+
case 8: return [2 /*return*/];
|
|
98
|
+
}
|
|
99
|
+
});
|
|
100
|
+
});
|
|
101
|
+
};
|
|
102
|
+
YarnPackageManagerAdapter.prototype.isMonorepo = function (dirPath) {
|
|
103
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
104
|
+
var major, primary, fallback, yarnCommands, lastOutput, hasRecognizedOutput, hasSuccessfulCommand, _i, yarnCommands_1, args, output, analysis, _a;
|
|
105
|
+
return __generator(this, function (_b) {
|
|
106
|
+
switch (_b.label) {
|
|
107
|
+
case 0: return [4 /*yield*/, this.getVersion(PackageManagerType_1.PackageManagerType.yarn, dirPath)];
|
|
108
|
+
case 1:
|
|
109
|
+
major = (_b.sent()).major;
|
|
110
|
+
primary = major >= 2 ? "list" : "info";
|
|
111
|
+
fallback = primary === "list" ? "info" : "list";
|
|
112
|
+
yarnCommands = [
|
|
113
|
+
["yarn", "workspaces", primary, "--json"],
|
|
114
|
+
["yarn", "workspaces", fallback, "--json"],
|
|
115
|
+
];
|
|
116
|
+
hasRecognizedOutput = false;
|
|
117
|
+
hasSuccessfulCommand = false;
|
|
118
|
+
_i = 0, yarnCommands_1 = yarnCommands;
|
|
119
|
+
_b.label = 2;
|
|
120
|
+
case 2:
|
|
121
|
+
if (!(_i < yarnCommands_1.length)) return [3 /*break*/, 7];
|
|
122
|
+
args = yarnCommands_1[_i];
|
|
123
|
+
_b.label = 3;
|
|
124
|
+
case 3:
|
|
125
|
+
_b.trys.push([3, 5, , 6]);
|
|
126
|
+
return [4 /*yield*/, this.execCommand(args, dirPath, true)];
|
|
127
|
+
case 4:
|
|
128
|
+
output = _b.sent();
|
|
129
|
+
hasSuccessfulCommand = true;
|
|
130
|
+
lastOutput = output;
|
|
131
|
+
analysis = this.analyzeYarnWorkspacesOutput(output);
|
|
132
|
+
if (analysis.hasEntries) {
|
|
133
|
+
return [2 /*return*/, true];
|
|
134
|
+
}
|
|
135
|
+
if (analysis.hasRecognizedData) {
|
|
136
|
+
hasRecognizedOutput = true;
|
|
137
|
+
}
|
|
138
|
+
return [3 /*break*/, 6];
|
|
139
|
+
case 5:
|
|
140
|
+
_a = _b.sent();
|
|
141
|
+
return [3 /*break*/, 6];
|
|
142
|
+
case 6:
|
|
143
|
+
_i++;
|
|
144
|
+
return [3 /*break*/, 2];
|
|
145
|
+
case 7:
|
|
146
|
+
if (hasSuccessfulCommand && !hasRecognizedOutput) {
|
|
147
|
+
throw new Error("Unexpected output from \"yarn workspaces\": ".concat(lastOutput !== null && lastOutput !== void 0 ? lastOutput : "<empty>"));
|
|
148
|
+
}
|
|
149
|
+
return [2 /*return*/, false];
|
|
150
|
+
}
|
|
151
|
+
});
|
|
152
|
+
});
|
|
153
|
+
};
|
|
154
|
+
YarnPackageManagerAdapter.prototype.isPackageInstalled = function (packageName, dirPath) {
|
|
155
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
156
|
+
var output, _a, output, _b;
|
|
157
|
+
return __generator(this, function (_c) {
|
|
158
|
+
switch (_c.label) {
|
|
159
|
+
case 0:
|
|
160
|
+
_c.trys.push([0, 2, , 3]);
|
|
161
|
+
return [4 /*yield*/, this.execCommand(["yarn", "list", "--depth=1", "--json", "--pattern", packageName], dirPath, true)];
|
|
162
|
+
case 1:
|
|
163
|
+
output = _c.sent();
|
|
164
|
+
if (this.yarnListOutputHasPackage(output, packageName)) {
|
|
165
|
+
return [2 /*return*/, true];
|
|
166
|
+
}
|
|
167
|
+
return [3 /*break*/, 3];
|
|
168
|
+
case 2:
|
|
169
|
+
_a = _c.sent();
|
|
170
|
+
return [3 /*break*/, 3];
|
|
171
|
+
case 3:
|
|
172
|
+
_c.trys.push([3, 5, , 6]);
|
|
173
|
+
return [4 /*yield*/, this.execCommand(["yarn", "why", "--json", packageName], dirPath, true)];
|
|
174
|
+
case 4:
|
|
175
|
+
output = _c.sent();
|
|
176
|
+
return [2 /*return*/, this.yarnListOutputHasPackage(output, packageName)];
|
|
177
|
+
case 5:
|
|
178
|
+
_b = _c.sent();
|
|
179
|
+
return [2 /*return*/, false];
|
|
180
|
+
case 6: return [2 /*return*/];
|
|
181
|
+
}
|
|
182
|
+
});
|
|
183
|
+
});
|
|
184
|
+
};
|
|
185
|
+
YarnPackageManagerAdapter.prototype.getNodeModulesPath = function (dirPath) {
|
|
186
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
187
|
+
return __generator(this, function (_a) {
|
|
188
|
+
return [2 /*return*/, (0, path_1.join)(dirPath, "node_modules")];
|
|
189
|
+
});
|
|
190
|
+
});
|
|
191
|
+
};
|
|
192
|
+
YarnPackageManagerAdapter.prototype.analyzeYarnWorkspacesOutput = function (output) {
|
|
193
|
+
var _a;
|
|
194
|
+
var entries = this.parseJsonLines(output);
|
|
195
|
+
if (entries.length === 0) {
|
|
196
|
+
var jsonBlock = this.extractJsonBlock(output);
|
|
197
|
+
if (jsonBlock && typeof jsonBlock === "object") {
|
|
198
|
+
entries = [jsonBlock];
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
if (entries.length === 0) {
|
|
202
|
+
return { hasEntries: false, hasRecognizedData: false };
|
|
203
|
+
}
|
|
204
|
+
var workspaceListCount = 0;
|
|
205
|
+
var hasRecognizedData = false;
|
|
206
|
+
for (var _i = 0, entries_1 = entries; _i < entries_1.length; _i++) {
|
|
207
|
+
var entry = entries_1[_i];
|
|
208
|
+
if (!entry || typeof entry !== "object") {
|
|
209
|
+
continue;
|
|
210
|
+
}
|
|
211
|
+
var type = entry.type;
|
|
212
|
+
if (type === "error" || type === "warning") {
|
|
213
|
+
continue;
|
|
214
|
+
}
|
|
215
|
+
var data = (_a = entry.data) !== null && _a !== void 0 ? _a : entry;
|
|
216
|
+
var parsedData = this.parseMaybeJsonString(data);
|
|
217
|
+
if (parsedData && typeof parsedData === "object") {
|
|
218
|
+
hasRecognizedData = true;
|
|
219
|
+
if (this.hasWorkspaceMap(parsedData)) {
|
|
220
|
+
return { hasEntries: true, hasRecognizedData: hasRecognizedData };
|
|
221
|
+
}
|
|
222
|
+
if (this.isWorkspaceInfoMap(parsedData)) {
|
|
223
|
+
return { hasEntries: true, hasRecognizedData: hasRecognizedData };
|
|
224
|
+
}
|
|
225
|
+
if (this.isWorkspaceListEntry(parsedData)) {
|
|
226
|
+
workspaceListCount += 1;
|
|
227
|
+
}
|
|
228
|
+
}
|
|
229
|
+
}
|
|
230
|
+
if (workspaceListCount > 0) {
|
|
231
|
+
return { hasEntries: true, hasRecognizedData: hasRecognizedData };
|
|
232
|
+
}
|
|
233
|
+
return { hasEntries: false, hasRecognizedData: hasRecognizedData };
|
|
234
|
+
};
|
|
235
|
+
YarnPackageManagerAdapter.prototype.parseMaybeJsonString = function (value) {
|
|
236
|
+
if (typeof value !== "string") {
|
|
237
|
+
return value;
|
|
238
|
+
}
|
|
239
|
+
try {
|
|
240
|
+
return JSON.parse(value);
|
|
241
|
+
}
|
|
242
|
+
catch (_a) {
|
|
243
|
+
return undefined;
|
|
244
|
+
}
|
|
245
|
+
};
|
|
246
|
+
YarnPackageManagerAdapter.prototype.extractJsonBlock = function (output) {
|
|
247
|
+
var start = output.indexOf("{");
|
|
248
|
+
var end = output.lastIndexOf("}");
|
|
249
|
+
if (start === -1 || end === -1 || end <= start) {
|
|
250
|
+
return undefined;
|
|
251
|
+
}
|
|
252
|
+
var candidate = output.slice(start, end + 1).trim();
|
|
253
|
+
if (candidate.length === 0) {
|
|
254
|
+
return undefined;
|
|
255
|
+
}
|
|
256
|
+
try {
|
|
257
|
+
return JSON.parse(candidate);
|
|
258
|
+
}
|
|
259
|
+
catch (_a) {
|
|
260
|
+
return undefined;
|
|
261
|
+
}
|
|
262
|
+
};
|
|
263
|
+
YarnPackageManagerAdapter.prototype.hasWorkspaceMap = function (value) {
|
|
264
|
+
if (!value || typeof value !== "object") {
|
|
265
|
+
return false;
|
|
266
|
+
}
|
|
267
|
+
var workspaces = value.workspaces;
|
|
268
|
+
return !!workspaces && Object.keys(workspaces).length > 0;
|
|
269
|
+
};
|
|
270
|
+
YarnPackageManagerAdapter.prototype.isWorkspaceListEntry = function (value) {
|
|
271
|
+
if (!value || typeof value !== "object") {
|
|
272
|
+
return false;
|
|
273
|
+
}
|
|
274
|
+
var entry = value;
|
|
275
|
+
return typeof entry.name === "string" && typeof entry.location === "string" && entry.location !== ".";
|
|
276
|
+
};
|
|
277
|
+
YarnPackageManagerAdapter.prototype.isWorkspaceInfoMap = function (value) {
|
|
278
|
+
if (!value || typeof value !== "object") {
|
|
279
|
+
return false;
|
|
280
|
+
}
|
|
281
|
+
var entries = Object.values(value);
|
|
282
|
+
if (entries.length === 0) {
|
|
283
|
+
return false;
|
|
284
|
+
}
|
|
285
|
+
return entries.some(function (entry) {
|
|
286
|
+
if (!entry || typeof entry !== "object") {
|
|
287
|
+
return false;
|
|
288
|
+
}
|
|
289
|
+
var location = entry.location;
|
|
290
|
+
return typeof location === "string" && location.length > 0 && location !== ".";
|
|
291
|
+
});
|
|
292
|
+
};
|
|
293
|
+
YarnPackageManagerAdapter.prototype.yarnListOutputHasPackage = function (output, packageName) {
|
|
294
|
+
var _a;
|
|
295
|
+
var entries = this.parseJsonLines(output);
|
|
296
|
+
for (var _i = 0, entries_2 = entries; _i < entries_2.length; _i++) {
|
|
297
|
+
var entry = entries_2[_i];
|
|
298
|
+
if (!entry || typeof entry !== "object") {
|
|
299
|
+
continue;
|
|
300
|
+
}
|
|
301
|
+
var data = entry.data;
|
|
302
|
+
var trees = (_a = data === null || data === void 0 ? void 0 : data.trees) !== null && _a !== void 0 ? _a : entry.trees;
|
|
303
|
+
if (!trees) {
|
|
304
|
+
var children = entry.children;
|
|
305
|
+
if (children) {
|
|
306
|
+
var childKeys = Object.keys(children);
|
|
307
|
+
if (childKeys.some(function (key) { return key.startsWith(packageName + "@"); })) {
|
|
308
|
+
return true;
|
|
309
|
+
}
|
|
310
|
+
}
|
|
311
|
+
continue;
|
|
312
|
+
}
|
|
313
|
+
if (trees.some(function (tree) { return tree.name.startsWith(packageName + "@"); })) {
|
|
314
|
+
return true;
|
|
315
|
+
}
|
|
316
|
+
}
|
|
317
|
+
return false;
|
|
318
|
+
};
|
|
319
|
+
return YarnPackageManagerAdapter;
|
|
320
|
+
}(AbstractPackageManagerAdapter_1.AbstractPackageManagerAdapter));
|
|
321
|
+
exports.YarnPackageManagerAdapter = YarnPackageManagerAdapter;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ts-dev-tools/core",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.11.0",
|
|
4
4
|
"description": "TS dev tools Core",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"linter",
|
|
@@ -93,5 +93,5 @@
|
|
|
93
93
|
"github-actions"
|
|
94
94
|
]
|
|
95
95
|
},
|
|
96
|
-
"gitHead": "
|
|
96
|
+
"gitHead": "9181a105b83523716cb8579991fd77f21a0e9ef6"
|
|
97
97
|
}
|