@ts-dev-tools/core 1.8.9 → 1.9.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.
package/README.md CHANGED
@@ -68,7 +68,7 @@
68
68
  ### _1_. Install
69
69
 
70
70
  ```sh
71
- npm install --include=dev @ts-dev-tools/core
71
+ npm install --save-dev @ts-dev-tools/core
72
72
  ```
73
73
 
74
74
  Or
@@ -77,10 +77,16 @@ Or
77
77
  yarn add --dev @ts-dev-tools/core
78
78
  ```
79
79
 
80
+ Or
81
+
82
+ ```sh
83
+ pnpm add -D @ts-dev-tools/core
84
+ ```
85
+
80
86
  ### _2_. Enable ts-dev-tools
81
87
 
82
88
  ```sh
83
- npx ts-dev-tools install
89
+ npm exec ts-dev-tools install
84
90
  ```
85
91
 
86
92
  Or
@@ -89,4 +95,10 @@ Or
89
95
  yarn ts-dev-tools install
90
96
  ```
91
97
 
92
- ⚠️ If your package is not private and you're publishing it on a registry like npmjs.com, you need to disable postinstall script using [pinst](https://github.com/typicode/pinst). Otherwise, postinstall will run when someone installs your package and result in an error.
98
+ Or
99
+
100
+ ```sh
101
+ pnpm ts-dev-tools install
102
+ ```
103
+
104
+ ⚠️ If your package is using yarn, is not private and you're publishing it on a registry like npmjs.com, you need to disable postinstall script using [pinst](https://github.com/typicode/pinst). Otherwise, postinstall will run when someone installs your package and result in an error.
@@ -68,7 +68,9 @@ function install(_a) {
68
68
  return [4 /*yield*/, MigrationsService_1.MigrationsService.executeMigrations(absoluteProjectDir, currentVersion)];
69
69
  case 1:
70
70
  _d.sent();
71
- SymlinkDependenciesService_1.SymlinkDependenciesService.executeSymlinking(absoluteProjectDir);
71
+ return [4 /*yield*/, SymlinkDependenciesService_1.SymlinkDependenciesService.executeSymlinking(absoluteProjectDir)];
72
+ case 2:
73
+ _d.sent();
72
74
  DuplicateDependenciesService_1.DuplicateDependenciesService.executeDeduplication(absoluteProjectDir);
73
75
  console.info("Installation done!");
74
76
  return [2 /*return*/];
@@ -41,12 +41,17 @@ var DuplicateDependenciesService = /** @class */ (function () {
41
41
  }
42
42
  };
43
43
  DuplicateDependenciesService.printDuplicatedDependencies = function (duplicateDependencies) {
44
+ var hasDuplicates = false;
44
45
  duplicateDependencies.forEach(function (pluginDuplicateDependencies, plugin) {
45
46
  if (pluginDuplicateDependencies.size) {
46
47
  var pluginDuplicateDependenciesValue = Array.from(pluginDuplicateDependencies);
48
+ hasDuplicates = true;
47
49
  console.info("Some dev dependencies are unnecessarily installed as their are already required by \"".concat(plugin, "\":\n - ").concat(pluginDuplicateDependenciesValue.join("\n - "), "\n"));
48
50
  }
49
51
  });
52
+ if (!hasDuplicates) {
53
+ console.info("No duplicate dev dependencies found.");
54
+ }
50
55
  };
51
56
  return DuplicateDependenciesService;
52
57
  }());
@@ -7,5 +7,6 @@ export declare class PackageManagerService {
7
7
  static addDevPackage(packageName: string, dirPath: string): Promise<void>;
8
8
  static isMonorepo(dirPath: string): Promise<boolean>;
9
9
  static isPackageInstalled(packageName: string, dirPath: string): Promise<boolean>;
10
+ static getNodeModulesPath(dirPath: string): Promise<string>;
10
11
  private static execCommand;
11
12
  }
@@ -149,6 +149,35 @@ var PackageManagerService = /** @class */ (function () {
149
149
  });
150
150
  });
151
151
  };
152
+ PackageManagerService.getNodeModulesPath = function (dirPath) {
153
+ return __awaiter(this, void 0, void 0, function () {
154
+ var packageManager, nodeModulesPath, _a;
155
+ return __generator(this, function (_b) {
156
+ switch (_b.label) {
157
+ case 0:
158
+ packageManager = PackageManagerService.detectPackageManager(dirPath);
159
+ _a = packageManager;
160
+ switch (_a) {
161
+ case PackageManagerType.yarn: return [3 /*break*/, 1];
162
+ case PackageManagerType.npm: return [3 /*break*/, 2];
163
+ }
164
+ return [3 /*break*/, 4];
165
+ case 1:
166
+ nodeModulesPath = (0, path_1.join)(dirPath, "node_modules");
167
+ return [3 /*break*/, 4];
168
+ case 2: return [4 /*yield*/, PackageManagerService.execCommand([packageManager, "root", "--no-progress", "--non-interactive"], dirPath, true)];
169
+ case 3:
170
+ nodeModulesPath = (_b.sent()).trim();
171
+ return [3 /*break*/, 4];
172
+ case 4:
173
+ if (nodeModulesPath) {
174
+ return [2 /*return*/, nodeModulesPath];
175
+ }
176
+ throw new Error("Node modules path not found for package manager ".concat(packageManager));
177
+ }
178
+ });
179
+ });
180
+ };
152
181
  PackageManagerService.execCommand = function (args_1, cwd_1) {
153
182
  return __awaiter(this, arguments, void 0, function (args, cwd, silent) {
154
183
  var cmd;
@@ -1,7 +1,8 @@
1
1
  export declare class SymlinkDependenciesService {
2
2
  static DEPENDENCIES_FOLDER: string;
3
- static executeSymlinking(absoluteProjectDir: string): void;
3
+ static executeSymlinking(absoluteProjectDir: string): Promise<void>;
4
4
  private static symlinkPluginDependencies;
5
5
  private static getPluginDependencies;
6
+ private static getPluginDependenciesPath;
6
7
  private static symlinkDependency;
7
8
  }
@@ -1,47 +1,130 @@
1
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
+ };
2
38
  Object.defineProperty(exports, "__esModule", { value: true });
3
39
  exports.SymlinkDependenciesService = void 0;
4
40
  var fs_1 = require("fs");
5
41
  var path_1 = require("path");
6
42
  var PackageJson_1 = require("./PackageJson");
7
43
  var PluginService_1 = require("./PluginService");
44
+ var PackageManagerService_1 = require("./PackageManagerService");
8
45
  var SymlinkDependenciesService = /** @class */ (function () {
9
46
  function SymlinkDependenciesService() {
10
47
  }
11
48
  SymlinkDependenciesService.executeSymlinking = function (absoluteProjectDir) {
12
- console.info("Symlinking dev dependencies...");
13
- var installedPlugins = PluginService_1.PluginService.getInstalledPlugins(absoluteProjectDir);
14
- for (var _i = 0, installedPlugins_1 = installedPlugins; _i < installedPlugins_1.length; _i++) {
15
- var plugin = installedPlugins_1[_i];
16
- SymlinkDependenciesService.symlinkPluginDependencies(absoluteProjectDir, plugin);
17
- }
18
- console.info("Symlinking dev dependencies done!");
49
+ return __awaiter(this, void 0, void 0, function () {
50
+ var installedPlugins, _i, installedPlugins_1, plugin;
51
+ return __generator(this, function (_a) {
52
+ switch (_a.label) {
53
+ case 0:
54
+ console.info("Symlinking dev dependencies...");
55
+ installedPlugins = PluginService_1.PluginService.getInstalledPlugins(absoluteProjectDir);
56
+ _i = 0, installedPlugins_1 = installedPlugins;
57
+ _a.label = 1;
58
+ case 1:
59
+ if (!(_i < installedPlugins_1.length)) return [3 /*break*/, 4];
60
+ plugin = installedPlugins_1[_i];
61
+ return [4 /*yield*/, SymlinkDependenciesService.symlinkPluginDependencies(absoluteProjectDir, plugin)];
62
+ case 2:
63
+ _a.sent();
64
+ _a.label = 3;
65
+ case 3:
66
+ _i++;
67
+ return [3 /*break*/, 1];
68
+ case 4:
69
+ console.info("Symlinking dev dependencies done!");
70
+ return [2 /*return*/];
71
+ }
72
+ });
73
+ });
19
74
  };
20
75
  SymlinkDependenciesService.symlinkPluginDependencies = function (absoluteProjectDir, plugin) {
21
- var pluginDependencies = SymlinkDependenciesService.getPluginDependencies(plugin);
22
- var pluginDependenciesPath = (0, path_1.join)(plugin.path, SymlinkDependenciesService.DEPENDENCIES_FOLDER);
23
- if (!(0, fs_1.existsSync)(pluginDependenciesPath)) {
24
- throw new Error("Plugin dependencies folder not found: ".concat(pluginDependenciesPath));
25
- }
26
- for (var _i = 0, pluginDependencies_1 = pluginDependencies; _i < pluginDependencies_1.length; _i++) {
27
- var pluginDependency = pluginDependencies_1[_i];
28
- var pluginDependencyPath = (0, path_1.join)(pluginDependenciesPath, pluginDependency);
29
- if (!(0, fs_1.existsSync)(pluginDependencyPath)) {
30
- continue;
31
- }
32
- var projectDependencyPath = (0, path_1.join)(absoluteProjectDir, SymlinkDependenciesService.DEPENDENCIES_FOLDER);
33
- var projectPluginDependencyPath = (0, path_1.join)(projectDependencyPath, pluginDependency);
34
- if ((0, fs_1.existsSync)(projectPluginDependencyPath)) {
35
- continue;
36
- }
37
- console.info("- Symlinking ".concat(pluginDependency));
38
- SymlinkDependenciesService.symlinkDependency(pluginDependencyPath, projectPluginDependencyPath);
39
- }
76
+ return __awaiter(this, void 0, void 0, function () {
77
+ var pluginDependencies, projectDependencyPath, pluginDependenciesPath, _i, pluginDependencies_1, pluginDependency, pluginDependencyPath, projectPluginDependencyPath;
78
+ return __generator(this, function (_a) {
79
+ switch (_a.label) {
80
+ case 0:
81
+ pluginDependencies = SymlinkDependenciesService.getPluginDependencies(plugin);
82
+ projectDependencyPath = (0, path_1.join)(absoluteProjectDir, SymlinkDependenciesService.DEPENDENCIES_FOLDER);
83
+ return [4 /*yield*/, SymlinkDependenciesService.getPluginDependenciesPath(absoluteProjectDir, plugin)];
84
+ case 1:
85
+ pluginDependenciesPath = _a.sent();
86
+ if (projectDependencyPath === pluginDependenciesPath) {
87
+ console.info("- Skipping symlinking ".concat(plugin.shortname, " dependencies, already in node_modules"));
88
+ return [2 /*return*/];
89
+ }
90
+ for (_i = 0, pluginDependencies_1 = pluginDependencies; _i < pluginDependencies_1.length; _i++) {
91
+ pluginDependency = pluginDependencies_1[_i];
92
+ pluginDependencyPath = (0, path_1.join)(pluginDependenciesPath, pluginDependency);
93
+ if (!(0, fs_1.existsSync)(pluginDependencyPath)) {
94
+ continue;
95
+ }
96
+ projectPluginDependencyPath = (0, path_1.join)(projectDependencyPath, pluginDependency);
97
+ if ((0, fs_1.existsSync)(projectPluginDependencyPath)) {
98
+ continue;
99
+ }
100
+ console.info("- Symlinking ".concat(pluginDependency));
101
+ SymlinkDependenciesService.symlinkDependency(pluginDependencyPath, projectPluginDependencyPath);
102
+ }
103
+ return [2 /*return*/];
104
+ }
105
+ });
106
+ });
40
107
  };
41
108
  SymlinkDependenciesService.getPluginDependencies = function (plugin) {
42
109
  var pluginPackageJson = PackageJson_1.PackageJson.fromDirPath(plugin.path);
43
110
  return pluginPackageJson.getDependenciesPackageNames();
44
111
  };
112
+ SymlinkDependenciesService.getPluginDependenciesPath = function (absoluteProjectDir, plugin) {
113
+ return __awaiter(this, void 0, void 0, function () {
114
+ var pluginDependenciesPath;
115
+ return __generator(this, function (_a) {
116
+ switch (_a.label) {
117
+ case 0:
118
+ pluginDependenciesPath = (0, path_1.join)(plugin.path, SymlinkDependenciesService.DEPENDENCIES_FOLDER);
119
+ if ((0, fs_1.existsSync)(pluginDependenciesPath)) {
120
+ return [2 /*return*/, pluginDependenciesPath];
121
+ }
122
+ return [4 /*yield*/, PackageManagerService_1.PackageManagerService.getNodeModulesPath(absoluteProjectDir)];
123
+ case 1: return [2 /*return*/, _a.sent()];
124
+ }
125
+ });
126
+ });
127
+ };
45
128
  SymlinkDependenciesService.symlinkDependency = function (pluginDependencyPath, projectPluginDependencyPath) {
46
129
  var pluginDependencyParentFolder = (0, path_1.join)(projectPluginDependencyPath, "..");
47
130
  if (!(0, fs_1.existsSync)(pluginDependencyParentFolder)) {
@@ -1,3 +1,4 @@
1
1
  export declare function mockConsoleInfo(): void;
2
2
  export declare function resetMockedConsoleInfo(): void;
3
3
  export declare function getConsoleInfoContent(): string;
4
+ export declare function stripAnsi(input: string): string;
@@ -3,6 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.mockConsoleInfo = mockConsoleInfo;
4
4
  exports.resetMockedConsoleInfo = resetMockedConsoleInfo;
5
5
  exports.getConsoleInfoContent = getConsoleInfoContent;
6
+ exports.stripAnsi = stripAnsi;
6
7
  var info = console.info;
7
8
  function mockConsoleInfo() {
8
9
  console.info = jest.fn();
@@ -15,3 +16,12 @@ function getConsoleInfoContent() {
15
16
  var calls = (_a = console.info) === null || _a === void 0 ? void 0 : _a.mock.calls;
16
17
  return calls.flat().join("\n");
17
18
  }
19
+ function stripAnsi(input) {
20
+ // Valid string terminator sequences are BEL, ESC\, and 0x9c
21
+ var ST = "(?:\\u0007|\\u001B\\u005C|\\u009C)";
22
+ var pattern = [
23
+ "[\\u001B\\u009B][[\\]()#;?]*(?:(?:(?:(?:;[-a-zA-Z\\d\\/#&.:=?%@~_]+)*|[a-zA-Z\\d]+(?:;[-a-zA-Z\\d\\/#&.:=?%@~_]*)*)?".concat(ST, ")"),
24
+ "(?:(?:\\d{1,4}(?:;\\d{0,4})*)?[\\dA-PR-TZcf-nq-uy=><~]))",
25
+ ].join("|");
26
+ return input.replace(new RegExp(pattern, "g"), "");
27
+ }
@@ -1,2 +1,3 @@
1
- export declare function deleteFolderRecursive(path: string): void;
2
- export declare function copyFolderSync(from: string, to: string): void;
1
+ export declare function recreateFolderRecursive(path: string): Promise<void>;
2
+ export declare function deleteFolderRecursive(path: string): Promise<void>;
3
+ export declare function copyFolder(src: string, dest: string): Promise<void>;
@@ -1,35 +1,100 @@
1
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
+ };
2
38
  Object.defineProperty(exports, "__esModule", { value: true });
39
+ exports.recreateFolderRecursive = recreateFolderRecursive;
3
40
  exports.deleteFolderRecursive = deleteFolderRecursive;
4
- exports.copyFolderSync = copyFolderSync;
41
+ exports.copyFolder = copyFolder;
5
42
  var fs_1 = require("fs");
6
- var path_1 = require("path");
7
- function deleteFolderRecursive(path) {
8
- if ((0, fs_1.existsSync)(path)) {
9
- (0, fs_1.readdirSync)(path).forEach(function (file) {
10
- var curPath = (0, path_1.join)(path, file);
11
- if ((0, fs_1.lstatSync)(curPath).isDirectory()) {
12
- // recurse
13
- deleteFolderRecursive(curPath);
43
+ var cli_1 = require("./cli");
44
+ function recreateFolderRecursive(path) {
45
+ return __awaiter(this, void 0, void 0, function () {
46
+ return __generator(this, function (_a) {
47
+ switch (_a.label) {
48
+ case 0:
49
+ if (!(0, fs_1.existsSync)(path)) return [3 /*break*/, 2];
50
+ return [4 /*yield*/, deleteFolderRecursive(path)];
51
+ case 1:
52
+ _a.sent();
53
+ _a.label = 2;
54
+ case 2:
55
+ (0, fs_1.mkdirSync)(path, { recursive: true });
56
+ return [2 /*return*/];
14
57
  }
15
- else {
16
- // delete file
17
- (0, fs_1.unlinkSync)(curPath);
58
+ });
59
+ });
60
+ }
61
+ function deleteFolderRecursive(path) {
62
+ return __awaiter(this, void 0, void 0, function () {
63
+ return __generator(this, function (_a) {
64
+ switch (_a.label) {
65
+ case 0:
66
+ if (!(0, fs_1.existsSync)(path)) return [3 /*break*/, 2];
67
+ return [4 /*yield*/, (0, cli_1.safeExec)(path, "rm -rf ".concat(path))];
68
+ case 1:
69
+ _a.sent();
70
+ _a.label = 2;
71
+ case 2: return [2 /*return*/];
18
72
  }
19
73
  });
20
- (0, fs_1.rmdirSync)(path);
21
- }
74
+ });
22
75
  }
23
- function copyFolderSync(from, to) {
24
- if (!(0, fs_1.existsSync)(to)) {
25
- (0, fs_1.mkdirSync)(to);
26
- }
27
- (0, fs_1.readdirSync)(from).forEach(function (element) {
28
- if ((0, fs_1.lstatSync)((0, path_1.join)(from, element)).isFile()) {
29
- (0, fs_1.copyFileSync)((0, path_1.join)(from, element), (0, path_1.join)(to, element));
30
- }
31
- else {
32
- copyFolderSync((0, path_1.join)(from, element), (0, path_1.join)(to, element));
33
- }
76
+ function copyFolder(src, dest) {
77
+ return __awaiter(this, void 0, void 0, function () {
78
+ var command;
79
+ return __generator(this, function (_a) {
80
+ switch (_a.label) {
81
+ case 0: return [4 /*yield*/, recreateFolderRecursive(dest)];
82
+ case 1:
83
+ _a.sent();
84
+ command = [
85
+ "rsync -a",
86
+ "--include='/.git/'",
87
+ "--include='/.git/hooks/'",
88
+ "--include='/.git/hooks/**'",
89
+ "--exclude='/.git/**'",
90
+ "\"".concat(src, "/\""),
91
+ "\"".concat(dest, "/\""),
92
+ ].join(" ");
93
+ return [4 /*yield*/, (0, cli_1.safeExec)(src, command)];
94
+ case 2:
95
+ _a.sent();
96
+ return [2 /*return*/];
97
+ }
98
+ });
34
99
  });
35
100
  }
@@ -0,0 +1,2 @@
1
+ export declare function getTestCacheDirPath(packageName: string, cacheName: string): string;
2
+ export declare function testCacheDirExists(packageName: string, cacheName: string): boolean;
@@ -0,0 +1,21 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getTestCacheDirPath = getTestCacheDirPath;
4
+ exports.testCacheDirExists = testCacheDirExists;
5
+ var fs_1 = require("fs");
6
+ var path_1 = require("path");
7
+ var rootDirPath = (0, path_1.resolve)(__dirname, "../../../..");
8
+ function getTestCacheDirPath(packageName, cacheName) {
9
+ if (!packageName) {
10
+ throw new Error("Package name must be provided");
11
+ }
12
+ if (!cacheName) {
13
+ throw new Error("Cache name must be provided");
14
+ }
15
+ var cacheDirPath = (0, path_1.resolve)((0, path_1.join)(rootDirPath, "node_modules/.cache/ts-dev-tools", packageName), cacheName.toLowerCase().replace(/[^a-z0-9]/g, "-"));
16
+ return cacheDirPath;
17
+ }
18
+ function testCacheDirExists(packageName, cacheName) {
19
+ var cacheDirPath = getTestCacheDirPath(packageName, cacheName);
20
+ return (0, fs_1.existsSync)(cacheDirPath);
21
+ }
@@ -0,0 +1,7 @@
1
+ /**
2
+ * Create a full file structure for testing ts-dev-tools packages installation
3
+ * This function is not using cache to prevents drift between current code and test code
4
+ * @param projectDir path where to prepare packages
5
+ * @returns packages directory path
6
+ */
7
+ export declare function createTestPackagesDir(filename: string): Promise<string>;
@@ -0,0 +1,107 @@
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.createTestPackagesDir = createTestPackagesDir;
40
+ var fs_1 = require("fs");
41
+ var path_1 = require("path");
42
+ var PackageJson_1 = require("../services/PackageJson");
43
+ var PluginService_1 = require("../services/PluginService");
44
+ var test_project_1 = require("./test-project");
45
+ var file_system_1 = require("./file-system");
46
+ var cli_1 = require("./cli");
47
+ function createTestPackagesProject(projectDir) {
48
+ return __awaiter(this, void 0, void 0, function () {
49
+ var originalPackagesPath, projectDirPackages, projectDirPackagesFiles, _i, projectDirPackagesFiles_1, projectDirPackagesFile, packagePath, packageJson, content, _a, _b, packageName, pluginShortName, dependencyPath;
50
+ return __generator(this, function (_c) {
51
+ switch (_c.label) {
52
+ case 0:
53
+ originalPackagesPath = (0, path_1.resolve)(__dirname, "../../..");
54
+ projectDirPackages = (0, path_1.resolve)(projectDir, "packages");
55
+ return [4 /*yield*/, (0, file_system_1.copyFolder)(originalPackagesPath, projectDirPackages)];
56
+ case 1:
57
+ _c.sent();
58
+ projectDirPackagesFiles = (0, fs_1.readdirSync)(projectDirPackages);
59
+ _i = 0, projectDirPackagesFiles_1 = projectDirPackagesFiles;
60
+ _c.label = 2;
61
+ case 2:
62
+ if (!(_i < projectDirPackagesFiles_1.length)) return [3 /*break*/, 5];
63
+ projectDirPackagesFile = projectDirPackagesFiles_1[_i];
64
+ packagePath = (0, path_1.resolve)(projectDirPackages, projectDirPackagesFile);
65
+ if (!(0, fs_1.lstatSync)(packagePath).isDirectory()) {
66
+ return [3 /*break*/, 4];
67
+ }
68
+ packageJson = PackageJson_1.PackageJson.fromDirPath(packagePath);
69
+ content = packageJson.getContent();
70
+ if (content.dependencies) {
71
+ for (_a = 0, _b = Object.keys(content.dependencies); _a < _b.length; _a++) {
72
+ packageName = _b[_a];
73
+ if (PluginService_1.PluginService.packageNameIsPlugin(packageName)) {
74
+ pluginShortName = PluginService_1.PluginService.getPluginShortname(packageName);
75
+ dependencyPath = (0, path_1.resolve)((0, path_1.join)(packagePath, "..", pluginShortName));
76
+ content.dependencies[packageName] = "file://".concat(dependencyPath);
77
+ }
78
+ }
79
+ packageJson.setContent(content);
80
+ }
81
+ return [4 /*yield*/, (0, cli_1.safeExec)(packagePath, "npm install")];
82
+ case 3:
83
+ _c.sent();
84
+ _c.label = 4;
85
+ case 4:
86
+ _i++;
87
+ return [3 /*break*/, 2];
88
+ case 5: return [2 /*return*/];
89
+ }
90
+ });
91
+ });
92
+ }
93
+ /**
94
+ * Create a full file structure for testing ts-dev-tools packages installation
95
+ * This function is not using cache to prevents drift between current code and test code
96
+ * @param projectDir path where to prepare packages
97
+ * @returns packages directory path
98
+ */
99
+ function createTestPackagesDir(filename) {
100
+ return __awaiter(this, void 0, void 0, function () {
101
+ var testPackagesFileName;
102
+ return __generator(this, function (_a) {
103
+ testPackagesFileName = filename.replace(".spec.ts", "-test-packages.spec.ts");
104
+ return [2 /*return*/, (0, test_project_1.createProjectForTestFile)(testPackagesFileName, false, createTestPackagesProject)];
105
+ });
106
+ });
107
+ }
@@ -0,0 +1,2 @@
1
+ import { TestProjectGenerator } from "./test-project";
2
+ export declare const createTestMonorepoProject: (filepath: string, useCache: boolean, testProjectGenerator: TestProjectGenerator) => Promise<string>;
@@ -0,0 +1,97 @@
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.createTestMonorepoProject = void 0;
40
+ var path_1 = require("path");
41
+ var PackageJson_1 = require("../services/PackageJson");
42
+ var cli_1 = require("./cli");
43
+ var test_project_1 = require("./test-project");
44
+ function generateProjectInMonorepoProject(packageName, projectDir, useCache, testProjectGenerator) {
45
+ return __awaiter(this, void 0, void 0, function () {
46
+ var packageDir;
47
+ return __generator(this, function (_a) {
48
+ switch (_a.label) {
49
+ case 0: return [4 /*yield*/, (0, cli_1.safeExec)(projectDir, "npm init --yes")];
50
+ case 1:
51
+ _a.sent();
52
+ return [4 /*yield*/, (0, cli_1.safeExec)(projectDir, "npm install")];
53
+ case 2:
54
+ _a.sent();
55
+ return [4 /*yield*/, (0, cli_1.safeExec)(projectDir, "npm install --save-dev -W typescript")];
56
+ case 3:
57
+ _a.sent();
58
+ return [4 /*yield*/, (0, cli_1.safeExec)(projectDir, "npm exec tsc -- --init")];
59
+ case 4:
60
+ _a.sent();
61
+ PackageJson_1.PackageJson.fromDirPath(projectDir).merge({
62
+ private: true,
63
+ workspaces: ["packages/*"],
64
+ });
65
+ packageDir = (0, path_1.join)(projectDir, "packages/test-package");
66
+ return [4 /*yield*/, (0, test_project_1.createTestProject)(packageName, packageDir, useCache, testProjectGenerator)];
67
+ case 5:
68
+ _a.sent();
69
+ return [4 /*yield*/, (0, cli_1.safeExec)(projectDir, "npm exec lerna -- init --no-progress --skipInstall")];
70
+ case 6:
71
+ _a.sent();
72
+ return [4 /*yield*/, (0, cli_1.safeExec)(projectDir, "npm install")];
73
+ case 7:
74
+ _a.sent();
75
+ return [2 /*return*/];
76
+ }
77
+ });
78
+ });
79
+ }
80
+ function generateMonorepoProject(packageName, useCache, testProjectGenerator) {
81
+ var projectGenerator = function (projectDir) {
82
+ return generateProjectInMonorepoProject(packageName, projectDir, useCache, testProjectGenerator);
83
+ };
84
+ Object.defineProperty(projectGenerator, "name", {
85
+ value: "monorepo-project-generator-".concat(testProjectGenerator.name),
86
+ configurable: true,
87
+ });
88
+ return projectGenerator;
89
+ }
90
+ var createTestMonorepoProject = function (filepath, useCache, testProjectGenerator) { return __awaiter(void 0, void 0, void 0, function () {
91
+ var packageName;
92
+ return __generator(this, function (_a) {
93
+ packageName = (0, test_project_1.getPackageNameFromFilepath)(filepath);
94
+ return [2 /*return*/, (0, test_project_1.createProjectForTestFile)(filepath, useCache, generateMonorepoProject(packageName, useCache, testProjectGenerator))];
95
+ });
96
+ }); };
97
+ exports.createTestMonorepoProject = createTestMonorepoProject;
@@ -0,0 +1,5 @@
1
+ export declare const getPackageNameFromFilepath: (filepath: string) => string;
2
+ export type TestProjectGenerator = (testProjectDir: string) => Promise<void>;
3
+ export declare function createTestProject(packageName: string, testDirPath: string, useCache: boolean, testProjectGenerator?: TestProjectGenerator): Promise<string>;
4
+ export declare function createProjectForTestFile(filepath: string, useCache: boolean, testProjectGenerator?: TestProjectGenerator): Promise<string>;
5
+ export declare function deleteTestProject(filepath: string): Promise<void>;
@@ -0,0 +1,148 @@
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.getPackageNameFromFilepath = void 0;
40
+ exports.createTestProject = createTestProject;
41
+ exports.createProjectForTestFile = createProjectForTestFile;
42
+ exports.deleteTestProject = deleteTestProject;
43
+ var fs_1 = require("fs");
44
+ var path_1 = require("path");
45
+ var test_cache_1 = require("./test-cache");
46
+ var file_system_1 = require("./file-system");
47
+ var os_1 = require("os");
48
+ var rootDirPath = (0, path_1.resolve)(__dirname, "../../../..");
49
+ var corePackageDirPath = (0, path_1.resolve)(__dirname, "..", "..");
50
+ var testProjectDir = (0, path_1.resolve)("__tests__/test-project");
51
+ var defaultPackageJsonPath = (0, path_1.join)(testProjectDir, "package.json");
52
+ var getPackageNameFromFilepath = function (filepath) {
53
+ var relativeFilepath = (0, path_1.relative)(rootDirPath, filepath);
54
+ var parts = relativeFilepath.split("/");
55
+ if (parts.length < 2) {
56
+ throw new Error("Invalid filepath: " + filepath);
57
+ }
58
+ var packageName = parts[1];
59
+ if (!packageName) {
60
+ throw new Error("Package name could not be determined from the filepath: " + filepath);
61
+ }
62
+ return packageName;
63
+ };
64
+ exports.getPackageNameFromFilepath = getPackageNameFromFilepath;
65
+ var getTestProjectDirPath = function (filename) {
66
+ var testProjectRootDirPath = (0, path_1.join)((0, os_1.tmpdir)(), "ts-dev-tools");
67
+ var relativeFilepath = (0, path_1.relative)(rootDirPath, filename);
68
+ var testProjectDirName = "test-" + relativeFilepath.toLowerCase().replace(/[^a-z0-9]/g, "-");
69
+ return (0, path_1.join)(testProjectRootDirPath, testProjectDirName);
70
+ };
71
+ function defaultProjectGenerator(testProjectDirPath) {
72
+ return __awaiter(this, void 0, void 0, function () {
73
+ var corePackageRootPath, tsDevToolsDistPath;
74
+ return __generator(this, function (_a) {
75
+ switch (_a.label) {
76
+ case 0:
77
+ corePackageRootPath = (0, path_1.join)(testProjectDirPath, "node_modules/@ts-dev-tools/core");
78
+ return [4 /*yield*/, (0, file_system_1.recreateFolderRecursive)(corePackageRootPath)];
79
+ case 1:
80
+ _a.sent();
81
+ (0, fs_1.copyFileSync)((0, path_1.join)(corePackageDirPath, "package.json"), (0, path_1.join)(corePackageRootPath, "package.json"));
82
+ tsDevToolsDistPath = (0, path_1.join)(corePackageRootPath, "dist");
83
+ (0, fs_1.symlinkSync)((0, path_1.resolve)(__dirname, ".."), tsDevToolsDistPath);
84
+ (0, fs_1.copyFileSync)(defaultPackageJsonPath, (0, path_1.join)(testProjectDirPath, "package.json"));
85
+ return [2 /*return*/];
86
+ }
87
+ });
88
+ });
89
+ }
90
+ function createTestProject(packageName_1, testDirPath_1, useCache_1) {
91
+ return __awaiter(this, arguments, void 0, function (packageName, testDirPath, useCache, testProjectGenerator) {
92
+ var cacheName, testCacheDirPath, gitHooksDirPath;
93
+ if (testProjectGenerator === void 0) { testProjectGenerator = defaultProjectGenerator; }
94
+ return __generator(this, function (_a) {
95
+ switch (_a.label) {
96
+ case 0: return [4 /*yield*/, (0, file_system_1.recreateFolderRecursive)(testDirPath)];
97
+ case 1:
98
+ _a.sent();
99
+ cacheName = testProjectGenerator.name;
100
+ testCacheDirPath = (0, test_cache_1.getTestCacheDirPath)(packageName, cacheName);
101
+ if (!(useCache && (0, test_cache_1.testCacheDirExists)(packageName, cacheName))) return [3 /*break*/, 3];
102
+ return [4 /*yield*/, (0, file_system_1.copyFolder)(testCacheDirPath, testDirPath)];
103
+ case 2:
104
+ _a.sent();
105
+ return [2 /*return*/, testDirPath];
106
+ case 3: return [4 /*yield*/, testProjectGenerator(testDirPath)];
107
+ case 4:
108
+ _a.sent();
109
+ gitHooksDirPath = (0, path_1.join)(testDirPath, ".git/hooks");
110
+ return [4 /*yield*/, (0, file_system_1.recreateFolderRecursive)(gitHooksDirPath)];
111
+ case 5:
112
+ _a.sent();
113
+ if (!useCache) return [3 /*break*/, 7];
114
+ return [4 /*yield*/, (0, file_system_1.copyFolder)(testDirPath, testCacheDirPath)];
115
+ case 6:
116
+ _a.sent();
117
+ _a.label = 7;
118
+ case 7: return [2 /*return*/, testDirPath];
119
+ }
120
+ });
121
+ });
122
+ }
123
+ function createProjectForTestFile(filepath_1, useCache_1) {
124
+ return __awaiter(this, arguments, void 0, function (filepath, useCache, testProjectGenerator) {
125
+ var testDirPath, packageName;
126
+ if (testProjectGenerator === void 0) { testProjectGenerator = defaultProjectGenerator; }
127
+ return __generator(this, function (_a) {
128
+ testDirPath = getTestProjectDirPath(filepath);
129
+ packageName = (0, exports.getPackageNameFromFilepath)(filepath);
130
+ return [2 /*return*/, createTestProject(packageName, testDirPath, useCache, testProjectGenerator)];
131
+ });
132
+ });
133
+ }
134
+ function deleteTestProject(filepath) {
135
+ return __awaiter(this, void 0, void 0, function () {
136
+ var testProjectDirPath;
137
+ return __generator(this, function (_a) {
138
+ switch (_a.label) {
139
+ case 0:
140
+ testProjectDirPath = getTestProjectDirPath(filepath);
141
+ return [4 /*yield*/, (0, file_system_1.deleteFolderRecursive)(testProjectDirPath)];
142
+ case 1:
143
+ _a.sent();
144
+ return [2 /*return*/];
145
+ }
146
+ });
147
+ });
148
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ts-dev-tools/core",
3
- "version": "1.8.9",
3
+ "version": "1.9.1",
4
4
  "description": "TS dev tools Core",
5
5
  "keywords": [
6
6
  "linter",
@@ -28,17 +28,15 @@
28
28
  "url": "git+https://github.com/escemi-tech/ts-dev-tools.git"
29
29
  },
30
30
  "scripts": {
31
- "start": "yarn link && tsc -w",
32
- "stop": "yarn unlink",
31
+ "start": "npm link && tsc -w",
32
+ "stop": "npm unlink",
33
33
  "build": "rimraf dist && tsc",
34
34
  "jest": "jest --detectOpenHandles --forceExit",
35
- "test": "yarn jest --maxWorkers=50%",
36
- "test:unit": "yarn test --testPathPattern \".+spec\\.ts\"",
37
- "test:e2e": "yarn test --testPathPattern \".+spec\\.e2e\\.ts\"",
38
- "test:coverage": "yarn test --coverage",
39
- "lint": "eslint \"src/**/*.{ts,tsx}\"",
40
- "prepublishOnly": "pinst --disable",
41
- "postpublish": "pinst --enable"
35
+ "test": "npm run jest -- --maxWorkers=50%",
36
+ "test:unit": "npm run test -- --testPathPattern \".+spec\\.ts\"",
37
+ "test:e2e": "npm run test -- --testPathPattern \".+e2e\\.spec\\.ts\"",
38
+ "test:coverage": "npm run test -- --coverage",
39
+ "lint": "eslint \"src/**/*.{ts,tsx}\""
42
40
  },
43
41
  "bugs": {
44
42
  "url": "https://github.com/escemi-tech/ts-dev-tools/issues"
@@ -46,24 +44,23 @@
46
44
  "dependencies": {
47
45
  "@commitlint/cli": "^19.4.0",
48
46
  "@commitlint/config-conventional": "^19.0.3",
49
- "@eslint/js": "^9.9.1",
47
+ "@eslint/js": "^9.25.0",
50
48
  "@types/jest": "^29.5.2",
51
- "@types/node": "^22.5.0",
52
- "eslint": "^9.9.1",
53
- "eslint-config-prettier": "^10.0.1",
49
+ "@types/node": "^22.14.1",
50
+ "eslint": "^9.25.0",
51
+ "eslint-config-prettier": "^10.1.2",
54
52
  "eslint-plugin-jest": "^28.8.0",
55
53
  "import-sort-style-module": "^6.0.0",
56
54
  "jest": "^29.5.0",
57
- "lint-staged": "^15.2.9",
55
+ "lint-staged": "^15.5.1",
58
56
  "prettier": "^3.3.3",
59
57
  "prettier-plugin-import-sort": "^0.0.7",
60
58
  "pretty-quick": "^4.0.0",
61
59
  "ts-jest": "^29.2.5",
62
- "typescript": "^5.5.4",
63
- "typescript-eslint": "^8.3.0"
60
+ "typescript": "^5.8.3",
61
+ "typescript-eslint": "^8.30.1"
64
62
  },
65
63
  "devDependencies": {
66
- "pinst": "^3.0.0",
67
64
  "ts-node": "^10.9.1"
68
65
  },
69
66
  "prettier": {
@@ -91,5 +88,5 @@
91
88
  "github-actions"
92
89
  ]
93
90
  },
94
- "gitHead": "1b6d5858642b90c7125e80b3cf37fa190d469bcf"
91
+ "gitHead": "cec0352615e50a8aa5716e057abbd970bccbddd7"
95
92
  }
@@ -1,13 +0,0 @@
1
- export declare const testProjectDir: string;
2
- export declare function createTestProjectDir(filename: string): string;
3
- export declare function createTestProjectDirWithFixtures(filename: string): string;
4
- export declare function getCorePackageRootPath(filename: string): string;
5
- export declare function restorePackageJson(filename: string): void;
6
- export declare function removeTestProjectDir(filename: string): void;
7
- export declare const createTestMonorepoProjectDir: (projectDir: string, createProject: (projectDir: string) => Promise<void>) => Promise<void>;
8
- /**
9
- * Create a full file structure for testing ts-dev-tools packages installation
10
- * @param projectDir path where to prepare packages
11
- * @returns packages directory path
12
- */
13
- export declare const createTestPackagesDir: (projectDir: string) => Promise<string>;
@@ -1,159 +0,0 @@
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.createTestPackagesDir = exports.createTestMonorepoProjectDir = exports.testProjectDir = void 0;
40
- exports.createTestProjectDir = createTestProjectDir;
41
- exports.createTestProjectDirWithFixtures = createTestProjectDirWithFixtures;
42
- exports.getCorePackageRootPath = getCorePackageRootPath;
43
- exports.restorePackageJson = restorePackageJson;
44
- exports.removeTestProjectDir = removeTestProjectDir;
45
- var fs_1 = require("fs");
46
- var path_1 = require("path");
47
- var PackageJson_1 = require("../services/PackageJson");
48
- var PluginService_1 = require("../services/PluginService");
49
- var cli_1 = require("./cli");
50
- var test_dir_1 = require("./test-dir");
51
- exports.testProjectDir = (0, path_1.resolve)("__tests__/test-project");
52
- var defaultPackageJsonPath = (0, path_1.join)(exports.testProjectDir, "package.json");
53
- var getTestProjectDirPath = function (filename) { return (0, test_dir_1.getTestDirPath)("test", filename); };
54
- function createTestProjectDir(filename) {
55
- var testDirPath = getTestProjectDirPath(filename);
56
- return (0, test_dir_1.createTestDir)(testDirPath, true);
57
- }
58
- function createTestProjectDirWithFixtures(filename) {
59
- var testProjectDirPath = createTestProjectDir(filename);
60
- (0, fs_1.mkdirSync)((0, path_1.join)(testProjectDirPath, ".git/hooks"), { recursive: true });
61
- // Fake node_modules
62
- var corePackageRootPath = getCorePackageRootPath(filename);
63
- (0, fs_1.mkdirSync)(corePackageRootPath, { recursive: true });
64
- (0, fs_1.copyFileSync)((0, path_1.resolve)(__dirname, "../../package.json"), (0, path_1.join)(corePackageRootPath, "package.json"));
65
- // Fake migrations
66
- var tsDevToolsDistPath = (0, path_1.join)(corePackageRootPath, "dist");
67
- (0, fs_1.symlinkSync)((0, path_1.resolve)(__dirname, ".."), tsDevToolsDistPath);
68
- restorePackageJson(filename);
69
- return testProjectDirPath;
70
- }
71
- function getCorePackageRootPath(filename) {
72
- var testProjectDirPath = getTestProjectDirPath(filename);
73
- if (!(0, fs_1.existsSync)(testProjectDirPath)) {
74
- throw new Error("Test project dir \"".concat(testProjectDirPath, "\" does not exist"));
75
- }
76
- return (0, path_1.join)(testProjectDirPath, "node_modules/@ts-dev-tools/core");
77
- }
78
- function restorePackageJson(filename) {
79
- var testProjectDirPath = getTestProjectDirPath(filename);
80
- if (!(0, fs_1.existsSync)(testProjectDirPath)) {
81
- throw new Error("Test project dir \"".concat(testProjectDirPath, "\" does not exist"));
82
- }
83
- (0, fs_1.copyFileSync)(defaultPackageJsonPath, (0, path_1.join)(testProjectDirPath, "package.json"));
84
- }
85
- function removeTestProjectDir(filename) {
86
- var testProjectDirPath = getTestProjectDirPath(filename);
87
- (0, test_dir_1.removeTestDir)(testProjectDirPath);
88
- }
89
- var createTestMonorepoProjectDir = function (projectDir, createProject) { return __awaiter(void 0, void 0, void 0, function () {
90
- var packageDir;
91
- return __generator(this, function (_a) {
92
- switch (_a.label) {
93
- case 0: return [4 /*yield*/, (0, cli_1.safeExec)(projectDir, "yarn init --yes")];
94
- case 1:
95
- _a.sent();
96
- return [4 /*yield*/, (0, cli_1.safeExec)(projectDir, "yarn install")];
97
- case 2:
98
- _a.sent();
99
- return [4 /*yield*/, (0, cli_1.safeExec)(projectDir, "yarn add -W --dev typescript")];
100
- case 3:
101
- _a.sent();
102
- return [4 /*yield*/, (0, cli_1.safeExec)(projectDir, "yarn tsc --init")];
103
- case 4:
104
- _a.sent();
105
- PackageJson_1.PackageJson.fromDirPath(projectDir).merge({
106
- private: true,
107
- workspaces: ["packages/*"],
108
- });
109
- packageDir = (0, path_1.join)(projectDir, "packages/test-package");
110
- (0, fs_1.mkdirSync)(packageDir, { recursive: true });
111
- return [4 /*yield*/, createProject(packageDir)];
112
- case 5:
113
- _a.sent();
114
- return [2 /*return*/];
115
- }
116
- });
117
- }); };
118
- exports.createTestMonorepoProjectDir = createTestMonorepoProjectDir;
119
- /**
120
- * Create a full file structure for testing ts-dev-tools packages installation
121
- * @param projectDir path where to prepare packages
122
- * @returns packages directory path
123
- */
124
- var createTestPackagesDir = function (projectDir) { return __awaiter(void 0, void 0, void 0, function () {
125
- var originalPackagesPath, projectDirPackages, projectDirPackagesFiles, _i, projectDirPackagesFiles_1, projectDirPackagesFile, packagePath, packageJson, content, _a, _b, packageName;
126
- return __generator(this, function (_c) {
127
- switch (_c.label) {
128
- case 0:
129
- originalPackagesPath = (0, path_1.resolve)(__dirname, "../../..");
130
- projectDirPackages = (0, path_1.join)(projectDir, "tmp-packages");
131
- (0, fs_1.mkdirSync)(projectDirPackages);
132
- return [4 /*yield*/, (0, cli_1.safeExec)(projectDir, "cp -R ".concat(originalPackagesPath, " ").concat(projectDirPackages, "/"))];
133
- case 1:
134
- _c.sent();
135
- projectDirPackages = (0, path_1.resolve)(projectDirPackages, "packages");
136
- projectDirPackagesFiles = (0, fs_1.readdirSync)(projectDirPackages);
137
- for (_i = 0, projectDirPackagesFiles_1 = projectDirPackagesFiles; _i < projectDirPackagesFiles_1.length; _i++) {
138
- projectDirPackagesFile = projectDirPackagesFiles_1[_i];
139
- packagePath = (0, path_1.resolve)(projectDirPackages, projectDirPackagesFile);
140
- if (!(0, fs_1.lstatSync)(packagePath).isDirectory()) {
141
- continue;
142
- }
143
- packageJson = PackageJson_1.PackageJson.fromDirPath(packagePath);
144
- content = packageJson.getContent();
145
- if (content.dependencies) {
146
- for (_a = 0, _b = Object.keys(content.dependencies); _a < _b.length; _a++) {
147
- packageName = _b[_a];
148
- if (PluginService_1.PluginService.packageNameIsPlugin(packageName)) {
149
- content.dependencies[packageName] = "file:../".concat(PluginService_1.PluginService.getPluginShortname(packageName));
150
- }
151
- }
152
- packageJson.setContent(content);
153
- }
154
- }
155
- return [2 /*return*/, projectDirPackages];
156
- }
157
- });
158
- }); };
159
- exports.createTestPackagesDir = createTestPackagesDir;
@@ -1,3 +0,0 @@
1
- export declare const getTestDirPath: (dirName: string, filename: string) => string;
2
- export declare function createTestDir(testDirPath: string, removeIfExists?: boolean): string;
3
- export declare function removeTestDir(testDirPath: string): void;
@@ -1,30 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getTestDirPath = void 0;
4
- exports.createTestDir = createTestDir;
5
- exports.removeTestDir = removeTestDir;
6
- var fs_1 = require("fs");
7
- var os_1 = require("os");
8
- var path_1 = require("path");
9
- var file_system_1 = require("./file-system");
10
- var getTestDirPath = function (dirName, filename) {
11
- return (0, path_1.join)((0, os_1.tmpdir)(), dirName + "-" + (0, path_1.basename)(filename).split(".")[0]);
12
- };
13
- exports.getTestDirPath = getTestDirPath;
14
- function createTestDir(testDirPath, removeIfExists) {
15
- if (removeIfExists === void 0) { removeIfExists = false; }
16
- if ((0, fs_1.existsSync)(testDirPath)) {
17
- if (!removeIfExists) {
18
- return testDirPath;
19
- }
20
- (0, file_system_1.deleteFolderRecursive)(testDirPath);
21
- }
22
- (0, fs_1.mkdirSync)(testDirPath);
23
- return testDirPath;
24
- }
25
- function removeTestDir(testDirPath) {
26
- if (!(0, fs_1.existsSync)(testDirPath)) {
27
- throw new Error("Test project dir \"".concat(testDirPath, "\" does not exist"));
28
- }
29
- (0, file_system_1.deleteFolderRecursive)(testDirPath);
30
- }