@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.
@@ -0,0 +1,155 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ var __generator = (this && this.__generator) || function (thisArg, body) {
12
+ 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);
13
+ return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
14
+ function verb(n) { return function (v) { return step([n, v]); }; }
15
+ function step(op) {
16
+ if (f) throw new TypeError("Generator is already executing.");
17
+ while (g && (g = 0, op[0] && (_ = 0)), _) try {
18
+ 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;
19
+ if (y = 0, t) op = [op[0] & 2, t.value];
20
+ switch (op[0]) {
21
+ case 0: case 1: t = op; break;
22
+ case 4: _.label++; return { value: op[1], done: false };
23
+ case 5: _.label++; y = op[1]; op = [0]; continue;
24
+ case 7: op = _.ops.pop(); _.trys.pop(); continue;
25
+ default:
26
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
27
+ if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
28
+ if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
29
+ if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
30
+ if (t[2]) _.ops.pop();
31
+ _.trys.pop(); continue;
32
+ }
33
+ op = body.call(thisArg, _);
34
+ } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
35
+ if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
36
+ }
37
+ };
38
+ Object.defineProperty(exports, "__esModule", { value: true });
39
+ exports.AbstractPackageManagerAdapter = void 0;
40
+ var child_process_1 = require("child_process");
41
+ var fs_1 = require("fs");
42
+ var AbstractPackageManagerAdapter = /** @class */ (function () {
43
+ function AbstractPackageManagerAdapter() {
44
+ }
45
+ AbstractPackageManagerAdapter.prototype.getVersion = function (packageManager, dirPath) {
46
+ return __awaiter(this, void 0, void 0, function () {
47
+ var raw, match;
48
+ return __generator(this, function (_a) {
49
+ switch (_a.label) {
50
+ case 0: return [4 /*yield*/, this.execCommand([packageManager, "--version"], dirPath, true)];
51
+ case 1:
52
+ raw = (_a.sent()).trim();
53
+ match = raw.match(/(\d+)\.(\d+)\.(\d+)/);
54
+ if (!match) {
55
+ return [2 /*return*/, { raw: raw, major: 0, minor: 0, patch: 0 }];
56
+ }
57
+ return [2 /*return*/, {
58
+ raw: raw,
59
+ major: Number(match[1]),
60
+ minor: Number(match[2]),
61
+ patch: Number(match[3]),
62
+ }];
63
+ }
64
+ });
65
+ });
66
+ };
67
+ AbstractPackageManagerAdapter.prototype.execCommand = function (args_1, cwd_1) {
68
+ return __awaiter(this, arguments, void 0, function (args, cwd, silent) {
69
+ var cmd, cmdArgs, useShell, shellOperators_1, hasShellSyntax;
70
+ if (silent === void 0) { silent = false; }
71
+ return __generator(this, function (_a) {
72
+ if (Array.isArray(args) && args.length === 0) {
73
+ throw new Error("Command args must not be empty");
74
+ }
75
+ if (typeof args === "string" && args.trim().length === 0) {
76
+ throw new Error("Command args must not be empty");
77
+ }
78
+ if (cwd && !(0, fs_1.existsSync)(cwd)) {
79
+ throw new Error("Directory \"".concat(cwd, "\" does not exist"));
80
+ }
81
+ useShell = false;
82
+ if (Array.isArray(args)) {
83
+ shellOperators_1 = [">", "|", "&&", "||", ";", "<", ">>", "2>", "&", "$("];
84
+ hasShellSyntax = args.some(function (arg) {
85
+ var trimmedArg = arg.trim();
86
+ return shellOperators_1.some(function (op) {
87
+ return trimmedArg.startsWith(op) ||
88
+ trimmedArg.endsWith(op) ||
89
+ trimmedArg.includes(" ".concat(op, " ")) ||
90
+ trimmedArg.includes(" ".concat(op)) ||
91
+ trimmedArg.includes("".concat(op, " "));
92
+ });
93
+ });
94
+ if (hasShellSyntax) {
95
+ cmd = args.join(" ").trim();
96
+ cmdArgs = [];
97
+ useShell = true;
98
+ }
99
+ else {
100
+ cmd = args[0];
101
+ cmdArgs = args.slice(1);
102
+ }
103
+ }
104
+ else {
105
+ cmd = args;
106
+ cmdArgs = [];
107
+ useShell = true;
108
+ }
109
+ return [2 /*return*/, new Promise(function (resolve, reject) {
110
+ var child = (0, child_process_1.spawn)(cmd, cmdArgs, {
111
+ stdio: silent ? "pipe" : "inherit",
112
+ shell: useShell,
113
+ windowsVerbatimArguments: true,
114
+ cwd: cwd,
115
+ });
116
+ var output = "";
117
+ var error = "";
118
+ child.on("exit", function (code) {
119
+ if (code) {
120
+ return reject(output.length > 0 ? output : error);
121
+ }
122
+ resolve(output);
123
+ });
124
+ if (child.stdout) {
125
+ child.stdout.on("data", function (data) {
126
+ output += "\n".concat(data);
127
+ });
128
+ }
129
+ if (child.stderr) {
130
+ child.stderr.on("data", function (data) {
131
+ error += "\n".concat(data);
132
+ });
133
+ }
134
+ })];
135
+ });
136
+ });
137
+ };
138
+ AbstractPackageManagerAdapter.prototype.parseJsonLines = function (output) {
139
+ return output
140
+ .split(/\r?\n/)
141
+ .map(function (line) { return line.trim(); })
142
+ .filter(function (line) { return line.length > 0; })
143
+ .map(function (line) {
144
+ try {
145
+ return JSON.parse(line);
146
+ }
147
+ catch (_a) {
148
+ return undefined;
149
+ }
150
+ })
151
+ .filter(function (entry) { return entry !== undefined; });
152
+ };
153
+ return AbstractPackageManagerAdapter;
154
+ }());
155
+ exports.AbstractPackageManagerAdapter = AbstractPackageManagerAdapter;
@@ -0,0 +1,7 @@
1
+ import { AbstractPackageManagerAdapter } from "./AbstractPackageManagerAdapter";
2
+ export declare class NpmPackageManagerAdapter extends AbstractPackageManagerAdapter {
3
+ addDevPackage(packageName: string, dirPath: string): Promise<void>;
4
+ isMonorepo(dirPath: string): Promise<boolean>;
5
+ isPackageInstalled(packageName: string, dirPath: string): Promise<boolean>;
6
+ getNodeModulesPath(dirPath: string): Promise<string>;
7
+ }
@@ -0,0 +1,165 @@
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.NpmPackageManagerAdapter = void 0;
55
+ var AbstractPackageManagerAdapter_1 = require("./AbstractPackageManagerAdapter");
56
+ var NpmPackageManagerAdapter = /** @class */ (function (_super) {
57
+ __extends(NpmPackageManagerAdapter, _super);
58
+ function NpmPackageManagerAdapter() {
59
+ return _super !== null && _super.apply(this, arguments) || this;
60
+ }
61
+ NpmPackageManagerAdapter.prototype.addDevPackage = function (packageName, dirPath) {
62
+ return __awaiter(this, void 0, void 0, function () {
63
+ var isMonorepo, args;
64
+ return __generator(this, function (_a) {
65
+ switch (_a.label) {
66
+ case 0: return [4 /*yield*/, this.isMonorepo(dirPath)];
67
+ case 1:
68
+ isMonorepo = _a.sent();
69
+ args = ["npm", "install", "--save-dev"];
70
+ if (isMonorepo) {
71
+ args.push("--no-workspaces");
72
+ }
73
+ args.push(packageName);
74
+ return [4 /*yield*/, this.execCommand(args, dirPath, true)];
75
+ case 2:
76
+ _a.sent();
77
+ return [2 /*return*/];
78
+ }
79
+ });
80
+ });
81
+ };
82
+ NpmPackageManagerAdapter.prototype.isMonorepo = function (dirPath) {
83
+ return __awaiter(this, void 0, void 0, function () {
84
+ var _a;
85
+ return __generator(this, function (_b) {
86
+ switch (_b.label) {
87
+ case 0:
88
+ _b.trys.push([0, 2, , 3]);
89
+ return [4 /*yield*/, this.execCommand(["npm", "--workspaces", "list", "--json"], dirPath, true)];
90
+ case 1:
91
+ _b.sent();
92
+ return [2 /*return*/, true];
93
+ case 2:
94
+ _a = _b.sent();
95
+ return [2 /*return*/, false];
96
+ case 3: return [2 /*return*/];
97
+ }
98
+ });
99
+ });
100
+ };
101
+ NpmPackageManagerAdapter.prototype.isPackageInstalled = function (packageName, dirPath) {
102
+ return __awaiter(this, void 0, void 0, function () {
103
+ var args, output, error_1, installedPackages;
104
+ return __generator(this, function (_a) {
105
+ switch (_a.label) {
106
+ case 0:
107
+ args = [
108
+ "npm",
109
+ "list",
110
+ "--depth=1",
111
+ "--json",
112
+ "--no-progress",
113
+ "--non-interactive",
114
+ packageName,
115
+ ];
116
+ _a.label = 1;
117
+ case 1:
118
+ _a.trys.push([1, 3, , 4]);
119
+ return [4 /*yield*/, this.execCommand(args, dirPath, true)];
120
+ case 2:
121
+ output = _a.sent();
122
+ return [3 /*break*/, 4];
123
+ case 3:
124
+ error_1 = _a.sent();
125
+ if (typeof error_1 === "string") {
126
+ try {
127
+ JSON.parse(error_1.trim());
128
+ output = error_1;
129
+ }
130
+ catch (_b) {
131
+ return [2 /*return*/, false];
132
+ }
133
+ }
134
+ else {
135
+ return [2 /*return*/, false];
136
+ }
137
+ return [3 /*break*/, 4];
138
+ case 4:
139
+ installedPackages = JSON.parse(output);
140
+ return [2 /*return*/, installedPackages.dependencies
141
+ ? Object.prototype.hasOwnProperty.call(installedPackages.dependencies, packageName)
142
+ : false];
143
+ }
144
+ });
145
+ });
146
+ };
147
+ NpmPackageManagerAdapter.prototype.getNodeModulesPath = function (dirPath) {
148
+ return __awaiter(this, void 0, void 0, function () {
149
+ var nodeModulesPath;
150
+ return __generator(this, function (_a) {
151
+ switch (_a.label) {
152
+ case 0: return [4 /*yield*/, this.execCommand(["npm", "root", "--no-progress", "--non-interactive"], dirPath, true)];
153
+ case 1:
154
+ nodeModulesPath = (_a.sent()).trim();
155
+ if (nodeModulesPath) {
156
+ return [2 /*return*/, nodeModulesPath];
157
+ }
158
+ throw new Error("Node modules path not found for package manager npm");
159
+ }
160
+ });
161
+ });
162
+ };
163
+ return NpmPackageManagerAdapter;
164
+ }(AbstractPackageManagerAdapter_1.AbstractPackageManagerAdapter));
165
+ exports.NpmPackageManagerAdapter = NpmPackageManagerAdapter;
@@ -0,0 +1,6 @@
1
+ export interface PackageManagerAdapter {
2
+ addDevPackage(packageName: string, dirPath: string): Promise<void>;
3
+ isMonorepo(dirPath: string): Promise<boolean>;
4
+ isPackageInstalled(packageName: string, dirPath: string): Promise<boolean>;
5
+ getNodeModulesPath(dirPath: string): Promise<string>;
6
+ }
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,4 @@
1
+ export declare enum PackageManagerType {
2
+ yarn = "yarn",
3
+ npm = "npm"
4
+ }
@@ -0,0 +1,8 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.PackageManagerType = void 0;
4
+ var PackageManagerType;
5
+ (function (PackageManagerType) {
6
+ PackageManagerType["yarn"] = "yarn";
7
+ PackageManagerType["npm"] = "npm";
8
+ })(PackageManagerType || (exports.PackageManagerType = PackageManagerType = {}));
@@ -0,0 +1,14 @@
1
+ import { AbstractPackageManagerAdapter } from "./AbstractPackageManagerAdapter";
2
+ export declare class YarnPackageManagerAdapter extends AbstractPackageManagerAdapter {
3
+ addDevPackage(packageName: string, dirPath: string): Promise<void>;
4
+ isMonorepo(dirPath: string): Promise<boolean>;
5
+ isPackageInstalled(packageName: string, dirPath: string): Promise<boolean>;
6
+ getNodeModulesPath(dirPath: string): Promise<string>;
7
+ private analyzeYarnWorkspacesOutput;
8
+ private parseMaybeJsonString;
9
+ private extractJsonBlock;
10
+ private hasWorkspaceMap;
11
+ private isWorkspaceListEntry;
12
+ private isWorkspaceInfoMap;
13
+ private yarnListOutputHasPackage;
14
+ }