@ts-dev-tools/core 1.8.8 → 1.9.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.
@@ -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,6 @@
1
+ /**
2
+ * Create a full file structure for testing ts-dev-tools packages installation
3
+ * @param projectDir path where to prepare packages
4
+ * @returns packages directory path
5
+ */
6
+ export declare function createTestPackagesDir(filename: string, useCache?: boolean): Promise<string>;
@@ -0,0 +1,95 @@
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
+ function createTestPackagesProject(projectDir) {
47
+ return __awaiter(this, void 0, void 0, function () {
48
+ var originalPackagesPath, projectDirPackages, projectDirPackagesFiles, _i, projectDirPackagesFiles_1, projectDirPackagesFile, packagePath, packageJson, content, _a, _b, packageName;
49
+ return __generator(this, function (_c) {
50
+ switch (_c.label) {
51
+ case 0:
52
+ originalPackagesPath = (0, path_1.resolve)(__dirname, "../../../..");
53
+ return [4 /*yield*/, (0, file_system_1.copyFolder)(originalPackagesPath, projectDir)];
54
+ case 1:
55
+ _c.sent();
56
+ projectDirPackages = (0, path_1.resolve)(projectDir, "packages");
57
+ projectDirPackagesFiles = (0, fs_1.readdirSync)(projectDirPackages);
58
+ for (_i = 0, projectDirPackagesFiles_1 = projectDirPackagesFiles; _i < projectDirPackagesFiles_1.length; _i++) {
59
+ projectDirPackagesFile = projectDirPackagesFiles_1[_i];
60
+ packagePath = (0, path_1.resolve)(projectDirPackages, projectDirPackagesFile);
61
+ if (!(0, fs_1.lstatSync)(packagePath).isDirectory()) {
62
+ continue;
63
+ }
64
+ packageJson = PackageJson_1.PackageJson.fromDirPath(packagePath);
65
+ content = packageJson.getContent();
66
+ if (content.dependencies) {
67
+ for (_a = 0, _b = Object.keys(content.dependencies); _a < _b.length; _a++) {
68
+ packageName = _b[_a];
69
+ if (PluginService_1.PluginService.packageNameIsPlugin(packageName)) {
70
+ content.dependencies[packageName] = "file:../".concat(PluginService_1.PluginService.getPluginShortname(packageName));
71
+ }
72
+ }
73
+ packageJson.setContent(content);
74
+ }
75
+ }
76
+ return [2 /*return*/];
77
+ }
78
+ });
79
+ });
80
+ }
81
+ /**
82
+ * Create a full file structure for testing ts-dev-tools packages installation
83
+ * @param projectDir path where to prepare packages
84
+ * @returns packages directory path
85
+ */
86
+ function createTestPackagesDir(filename_1) {
87
+ return __awaiter(this, arguments, void 0, function (filename, useCache) {
88
+ var testPackagesFileName;
89
+ if (useCache === void 0) { useCache = true; }
90
+ return __generator(this, function (_a) {
91
+ testPackagesFileName = filename.replace(".spec.ts", "-test-packages.spec.ts");
92
+ return [2 /*return*/, (0, test_project_1.createProjectForTestFile)(testPackagesFileName, useCache, createTestPackagesProject)];
93
+ });
94
+ });
95
+ }
@@ -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, "yarn init --yes")];
50
+ case 1:
51
+ _a.sent();
52
+ return [4 /*yield*/, (0, cli_1.safeExec)(projectDir, "yarn install --prefer-offline --frozen-lockfile --mutex network")];
53
+ case 2:
54
+ _a.sent();
55
+ return [4 /*yield*/, (0, cli_1.safeExec)(projectDir, "yarn add -W --dev typescript")];
56
+ case 3:
57
+ _a.sent();
58
+ return [4 /*yield*/, (0, cli_1.safeExec)(projectDir, "yarn 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, "npx lerna init --no-progress --skipInstall")];
70
+ case 6:
71
+ _a.sent();
72
+ return [4 /*yield*/, (0, cli_1.safeExec)(projectDir, "yarn install --prefer-offline --mutex network")];
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,150 @@
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 testProjectDirName = "test-" +
68
+ (0, path_1.parse)(filename)
69
+ .name.toLowerCase()
70
+ .replace(/[^a-z0-9]/g, "-");
71
+ return (0, path_1.join)(testProjectRootDirPath, testProjectDirName);
72
+ };
73
+ function defaultProjectGenerator(testProjectDirPath) {
74
+ return __awaiter(this, void 0, void 0, function () {
75
+ var corePackageRootPath, tsDevToolsDistPath;
76
+ return __generator(this, function (_a) {
77
+ switch (_a.label) {
78
+ case 0:
79
+ corePackageRootPath = (0, path_1.join)(testProjectDirPath, "node_modules/@ts-dev-tools/core");
80
+ return [4 /*yield*/, (0, file_system_1.recreateFolderRecursive)(corePackageRootPath)];
81
+ case 1:
82
+ _a.sent();
83
+ (0, fs_1.copyFileSync)((0, path_1.join)(corePackageDirPath, "package.json"), (0, path_1.join)(corePackageRootPath, "package.json"));
84
+ tsDevToolsDistPath = (0, path_1.join)(corePackageRootPath, "dist");
85
+ (0, fs_1.symlinkSync)((0, path_1.resolve)(__dirname, ".."), tsDevToolsDistPath);
86
+ (0, fs_1.copyFileSync)(defaultPackageJsonPath, (0, path_1.join)(testProjectDirPath, "package.json"));
87
+ return [2 /*return*/];
88
+ }
89
+ });
90
+ });
91
+ }
92
+ function createTestProject(packageName_1, testDirPath_1, useCache_1) {
93
+ return __awaiter(this, arguments, void 0, function (packageName, testDirPath, useCache, testProjectGenerator) {
94
+ var cacheName, testCacheDirPath, gitHooksDirPath;
95
+ if (testProjectGenerator === void 0) { testProjectGenerator = defaultProjectGenerator; }
96
+ return __generator(this, function (_a) {
97
+ switch (_a.label) {
98
+ case 0: return [4 /*yield*/, (0, file_system_1.recreateFolderRecursive)(testDirPath)];
99
+ case 1:
100
+ _a.sent();
101
+ cacheName = testProjectGenerator.name;
102
+ testCacheDirPath = (0, test_cache_1.getTestCacheDirPath)(packageName, cacheName);
103
+ if (!(useCache && (0, test_cache_1.testCacheDirExists)(packageName, cacheName))) return [3 /*break*/, 3];
104
+ return [4 /*yield*/, (0, file_system_1.copyFolder)(testCacheDirPath, testDirPath)];
105
+ case 2:
106
+ _a.sent();
107
+ return [2 /*return*/, testDirPath];
108
+ case 3: return [4 /*yield*/, testProjectGenerator(testDirPath)];
109
+ case 4:
110
+ _a.sent();
111
+ gitHooksDirPath = (0, path_1.join)(testDirPath, ".git/hooks");
112
+ return [4 /*yield*/, (0, file_system_1.recreateFolderRecursive)(gitHooksDirPath)];
113
+ case 5:
114
+ _a.sent();
115
+ if (!useCache) return [3 /*break*/, 7];
116
+ return [4 /*yield*/, (0, file_system_1.copyFolder)(testDirPath, testCacheDirPath)];
117
+ case 6:
118
+ _a.sent();
119
+ _a.label = 7;
120
+ case 7: return [2 /*return*/, testDirPath];
121
+ }
122
+ });
123
+ });
124
+ }
125
+ function createProjectForTestFile(filepath_1, useCache_1) {
126
+ return __awaiter(this, arguments, void 0, function (filepath, useCache, testProjectGenerator) {
127
+ var testDirPath, packageName;
128
+ if (testProjectGenerator === void 0) { testProjectGenerator = defaultProjectGenerator; }
129
+ return __generator(this, function (_a) {
130
+ testDirPath = getTestProjectDirPath(filepath);
131
+ packageName = (0, exports.getPackageNameFromFilepath)(filepath);
132
+ return [2 /*return*/, createTestProject(packageName, testDirPath, useCache, testProjectGenerator)];
133
+ });
134
+ });
135
+ }
136
+ function deleteTestProject(filepath) {
137
+ return __awaiter(this, void 0, void 0, function () {
138
+ var testProjectDirPath;
139
+ return __generator(this, function (_a) {
140
+ switch (_a.label) {
141
+ case 0:
142
+ testProjectDirPath = getTestProjectDirPath(filepath);
143
+ return [4 /*yield*/, (0, file_system_1.deleteFolderRecursive)(testProjectDirPath)];
144
+ case 1:
145
+ _a.sent();
146
+ return [2 /*return*/];
147
+ }
148
+ });
149
+ });
150
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ts-dev-tools/core",
3
- "version": "1.8.8",
3
+ "version": "1.9.0",
4
4
  "description": "TS dev tools Core",
5
5
  "keywords": [
6
6
  "linter",
@@ -34,7 +34,7 @@
34
34
  "jest": "jest --detectOpenHandles --forceExit",
35
35
  "test": "yarn jest --maxWorkers=50%",
36
36
  "test:unit": "yarn test --testPathPattern \".+spec\\.ts\"",
37
- "test:e2e": "yarn test --testPathPattern \".+spec\\.e2e\\.ts\"",
37
+ "test:e2e": "yarn test --testPathPattern \".+e2e\\.spec\\.ts\"",
38
38
  "test:coverage": "yarn test --coverage",
39
39
  "lint": "eslint \"src/**/*.{ts,tsx}\"",
40
40
  "prepublishOnly": "pinst --disable",
@@ -46,21 +46,21 @@
46
46
  "dependencies": {
47
47
  "@commitlint/cli": "^19.4.0",
48
48
  "@commitlint/config-conventional": "^19.0.3",
49
- "@eslint/js": "^9.9.1",
49
+ "@eslint/js": "^9.25.0",
50
50
  "@types/jest": "^29.5.2",
51
- "@types/node": "^22.5.0",
52
- "eslint": "^9.9.1",
53
- "eslint-config-prettier": "^9.1.0",
51
+ "@types/node": "^22.14.1",
52
+ "eslint": "^9.25.0",
53
+ "eslint-config-prettier": "^10.1.2",
54
54
  "eslint-plugin-jest": "^28.8.0",
55
55
  "import-sort-style-module": "^6.0.0",
56
56
  "jest": "^29.5.0",
57
- "lint-staged": "^15.2.9",
57
+ "lint-staged": "^15.5.1",
58
58
  "prettier": "^3.3.3",
59
59
  "prettier-plugin-import-sort": "^0.0.7",
60
60
  "pretty-quick": "^4.0.0",
61
61
  "ts-jest": "^29.2.5",
62
- "typescript": "^5.5.4",
63
- "typescript-eslint": "^8.3.0"
62
+ "typescript": "^5.8.3",
63
+ "typescript-eslint": "^8.30.1"
64
64
  },
65
65
  "devDependencies": {
66
66
  "pinst": "^3.0.0",
@@ -91,5 +91,5 @@
91
91
  "github-actions"
92
92
  ]
93
93
  },
94
- "gitHead": "5d74ee82aff8fd9b625ba0a6718b752ca9c40c39"
94
+ "gitHead": "81a30105d496ffa06a6d3c14140a822f9752278b"
95
95
  }
@@ -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
- }