@ts-dev-tools/core 1.9.7 → 1.9.8

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.
@@ -115,24 +115,47 @@ var PackageManagerService = /** @class */ (function () {
115
115
  };
116
116
  PackageManagerService.isPackageInstalled = function (packageName, dirPath) {
117
117
  return __awaiter(this, void 0, void 0, function () {
118
- var packageManager, args, output, installedPackages;
118
+ var packageManager, args, output, error_1, installedPackages;
119
119
  var _a, _b;
120
120
  return __generator(this, function (_c) {
121
121
  switch (_c.label) {
122
122
  case 0:
123
123
  packageManager = PackageManagerService.detectPackageManager(dirPath);
124
- args = [
125
- packageManager,
126
- "list",
127
- "--depth=1",
128
- "--json",
129
- "--no-progress",
130
- "--pattern=\"".concat(packageName, "\""),
131
- "--non-interactive",
132
- ];
133
- return [4 /*yield*/, PackageManagerService.execCommand(args, dirPath, true)];
124
+ args = [packageManager, "list", "--depth=1", "--json"];
125
+ switch (packageManager) {
126
+ case PackageManagerType.yarn:
127
+ args.push("--pattern=".concat(packageName));
128
+ break;
129
+ case PackageManagerType.npm:
130
+ args.push("--no-progress", "--non-interactive", packageName);
131
+ break;
132
+ }
133
+ _c.label = 1;
134
134
  case 1:
135
+ _c.trys.push([1, 3, , 4]);
136
+ return [4 /*yield*/, PackageManagerService.execCommand(args, dirPath, true)];
137
+ case 2:
135
138
  output = _c.sent();
139
+ return [3 /*break*/, 4];
140
+ case 3:
141
+ error_1 = _c.sent();
142
+ // npm returns non-zero exit code when package is not found, but still outputs valid JSON
143
+ if (typeof error_1 === "string") {
144
+ try {
145
+ // Try to parse as JSON - if successful, use it as output
146
+ JSON.parse(error_1.trim());
147
+ output = error_1;
148
+ }
149
+ catch (_d) {
150
+ // If it's not valid JSON, the package is not installed
151
+ return [2 /*return*/, false];
152
+ }
153
+ }
154
+ else {
155
+ return [2 /*return*/, false];
156
+ }
157
+ return [3 /*break*/, 4];
158
+ case 4:
136
159
  installedPackages = JSON.parse(output);
137
160
  switch (packageManager) {
138
161
  case PackageManagerType.yarn:
@@ -180,26 +203,53 @@ var PackageManagerService = /** @class */ (function () {
180
203
  };
181
204
  PackageManagerService.execCommand = function (args_1, cwd_1) {
182
205
  return __awaiter(this, arguments, void 0, function (args, cwd, silent) {
183
- var cmd;
206
+ var cmd, cmdArgs, useShell, SHELL_OPERATORS_1, hasShellSyntax;
184
207
  if (silent === void 0) { silent = false; }
185
208
  return __generator(this, function (_a) {
186
- if (!args.length) {
209
+ // Handle empty args check for both string and array
210
+ if (Array.isArray(args) && args.length === 0) {
211
+ throw new Error("Command args must not be empty");
212
+ }
213
+ if (typeof args === "string" && args.trim().length === 0) {
187
214
  throw new Error("Command args must not be empty");
188
215
  }
189
216
  if (cwd && !(0, fs_1.existsSync)(cwd)) {
190
217
  throw new Error("Directory \"".concat(cwd, "\" does not exist"));
191
218
  }
219
+ useShell = false;
192
220
  if (Array.isArray(args)) {
193
- cmd = args.shift() || "";
221
+ SHELL_OPERATORS_1 = [">", "|", "&&", "||", ";", "<", ">>", "2>", "&", "$("];
222
+ hasShellSyntax = args.some(function (arg) {
223
+ var trimmedArg = arg.trim();
224
+ return SHELL_OPERATORS_1.some(function (op) {
225
+ return trimmedArg.startsWith(op) ||
226
+ trimmedArg.endsWith(op) ||
227
+ trimmedArg.includes(" ".concat(op, " ")) ||
228
+ trimmedArg.includes(" ".concat(op)) ||
229
+ trimmedArg.includes("".concat(op, " "));
230
+ });
231
+ });
232
+ if (hasShellSyntax) {
233
+ // Use shell mode for commands with shell syntax
234
+ cmd = args.join(" ").trim();
235
+ cmdArgs = [];
236
+ useShell = true;
237
+ }
238
+ else {
239
+ // Use array mode for normal commands
240
+ cmd = args[0];
241
+ cmdArgs = args.slice(1);
242
+ }
194
243
  }
195
244
  else {
196
245
  cmd = args;
197
- args = [];
246
+ cmdArgs = [];
247
+ useShell = true;
198
248
  }
199
249
  return [2 /*return*/, new Promise(function (resolve, reject) {
200
- var child = (0, child_process_1.spawn)(cmd, args, {
250
+ var child = (0, child_process_1.spawn)(cmd, cmdArgs, {
201
251
  stdio: silent ? "pipe" : "inherit",
202
- shell: true,
252
+ shell: useShell,
203
253
  windowsVerbatimArguments: true,
204
254
  cwd: cwd,
205
255
  });
@@ -207,7 +257,9 @@ var PackageManagerService = /** @class */ (function () {
207
257
  var error = "";
208
258
  child.on("exit", function (code) {
209
259
  if (code) {
210
- return reject(error);
260
+ // For commands that output to stdout even on error (like npm list),
261
+ // reject with the output so caller can handle it
262
+ return reject(output.length > 0 ? output : error);
211
263
  }
212
264
  resolve(output);
213
265
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ts-dev-tools/core",
3
- "version": "1.9.7",
3
+ "version": "1.9.8",
4
4
  "description": "TS dev tools Core",
5
5
  "keywords": [
6
6
  "linter",
@@ -36,7 +36,8 @@
36
36
  "test:unit": "npm run test -- --testPathPattern \".+spec\\.ts\"",
37
37
  "test:e2e": "npm run test -- --testPathPattern \".+e2e\\.spec\\.ts\"",
38
38
  "test:coverage": "npm run test -- --coverage",
39
- "lint": "eslint \"src/**/*.{ts,tsx}\""
39
+ "lint": "eslint \"src/**/*.{ts,tsx}\"",
40
+ "lint:ci": "npm run lint -- --output-file eslint-report.json --format json"
40
41
  },
41
42
  "bugs": {
42
43
  "url": "https://github.com/escemi-tech/ts-dev-tools/issues"
@@ -45,7 +46,7 @@
45
46
  "@commitlint/cli": "^20.0.0",
46
47
  "@commitlint/config-conventional": "^20.0.0",
47
48
  "@eslint/js": "^9.25.0",
48
- "@prettier/plugin-oxc": "^0.0.4",
49
+ "@prettier/plugin-oxc": "^0.0.5",
49
50
  "@types/jest": "^30.0.0",
50
51
  "@types/node": "^24.0.1",
51
52
  "eslint": "^9.25.0",
@@ -92,5 +93,5 @@
92
93
  "github-actions"
93
94
  ]
94
95
  },
95
- "gitHead": "017cf83fb5426195d1feb11bcb97f2a173850f06"
96
+ "gitHead": "e49f690ba0ee84ba44a86c0631b4a2004bb77073"
96
97
  }