@ts-dev-tools/core 1.12.1 → 1.12.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/bin.js +26 -76
- package/dist/constants.js +2 -2
- package/dist/eslint-plugin-ts-dev-tools/index.js +18 -30
- package/dist/install/command.js +30 -80
- package/dist/install/migrations/20201024173398-init.js +89 -141
- package/dist/install/migrations/20220617100200-prettier-cache.js +9 -49
- package/dist/install/migrations/20240329200200-eslint-ignore.js +9 -49
- package/dist/install/migrations/20240412185500-eslint-config.js +16 -53
- package/dist/install/migrations/20240617094000-config-nx-scopes.js +22 -67
- package/dist/install/migrations/20250623095500-add-prettier-oxc.js +9 -49
- package/dist/install/migrations/20250623095600-remove-prettier-oxc.js +15 -55
- package/dist/services/CmdService.js +17 -21
- package/dist/services/CorePackageService.js +8 -11
- package/dist/services/DuplicateDependenciesService.js +28 -33
- package/dist/services/FileService.js +11 -14
- package/dist/services/GitService.js +36 -83
- package/dist/services/MigrationsService.js +52 -121
- package/dist/services/PackageJson.js +47 -57
- package/dist/services/PackageJsonMerge.js +17 -21
- package/dist/services/PackageManagerService.js +25 -80
- package/dist/services/PeerDependenciesService.js +92 -157
- package/dist/services/PluginService.js +32 -39
- package/dist/services/SymlinkDependenciesService.js +52 -133
- package/dist/services/package-manager/AbstractPackageManagerAdapter.js +84 -138
- package/dist/services/package-manager/NpmPackageManagerAdapter.js +58 -158
- package/dist/services/package-manager/YarnPackageManagerAdapter.js +122 -235
- package/dist/tests/cli.js +12 -57
- package/dist/tests/console.js +5 -6
- package/dist/tests/file-system.js +23 -92
- package/dist/tests/test-cache.js +5 -5
- package/dist/tests/test-packages.js +33 -95
- package/dist/tests/test-project-monorepo.js +22 -85
- package/dist/tests/test-project.js +49 -127
- package/package.json +12 -12
|
@@ -1,100 +1,31 @@
|
|
|
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
|
-
};
|
|
38
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
3
|
exports.recreateFolderRecursive = recreateFolderRecursive;
|
|
40
4
|
exports.deleteFolderRecursive = deleteFolderRecursive;
|
|
41
5
|
exports.copyFolder = copyFolder;
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
function recreateFolderRecursive(path) {
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
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*/];
|
|
57
|
-
}
|
|
58
|
-
});
|
|
59
|
-
});
|
|
6
|
+
const fs_1 = require("fs");
|
|
7
|
+
const cli_1 = require("./cli");
|
|
8
|
+
async function recreateFolderRecursive(path) {
|
|
9
|
+
if ((0, fs_1.existsSync)(path)) {
|
|
10
|
+
await deleteFolderRecursive(path);
|
|
11
|
+
}
|
|
12
|
+
(0, fs_1.mkdirSync)(path, { recursive: true });
|
|
60
13
|
}
|
|
61
|
-
function deleteFolderRecursive(path) {
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
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*/];
|
|
72
|
-
}
|
|
73
|
-
});
|
|
74
|
-
});
|
|
14
|
+
async function deleteFolderRecursive(path) {
|
|
15
|
+
if ((0, fs_1.existsSync)(path)) {
|
|
16
|
+
await (0, cli_1.safeExec)(path, `rm -rf ${path}`);
|
|
17
|
+
}
|
|
75
18
|
}
|
|
76
|
-
function copyFolder(src, dest) {
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
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
|
-
});
|
|
99
|
-
});
|
|
19
|
+
async function copyFolder(src, dest) {
|
|
20
|
+
await recreateFolderRecursive(dest);
|
|
21
|
+
const command = [
|
|
22
|
+
"rsync -a",
|
|
23
|
+
"--include='/.git/'",
|
|
24
|
+
"--include='/.git/hooks/'",
|
|
25
|
+
"--include='/.git/hooks/**'",
|
|
26
|
+
"--exclude='/.git/**'",
|
|
27
|
+
`"${src}/"`,
|
|
28
|
+
`"${dest}/"`,
|
|
29
|
+
].join(" ");
|
|
30
|
+
await (0, cli_1.safeExec)(src, command);
|
|
100
31
|
}
|
package/dist/tests/test-cache.js
CHANGED
|
@@ -2,9 +2,9 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.getTestCacheDirPath = getTestCacheDirPath;
|
|
4
4
|
exports.testCacheDirExists = testCacheDirExists;
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
5
|
+
const fs_1 = require("fs");
|
|
6
|
+
const path_1 = require("path");
|
|
7
|
+
const rootDirPath = (0, path_1.resolve)(__dirname, "../../../..");
|
|
8
8
|
function getTestCacheDirPath(packageName, cacheName) {
|
|
9
9
|
if (!packageName) {
|
|
10
10
|
throw new Error("Package name must be provided");
|
|
@@ -12,10 +12,10 @@ function getTestCacheDirPath(packageName, cacheName) {
|
|
|
12
12
|
if (!cacheName) {
|
|
13
13
|
throw new Error("Cache name must be provided");
|
|
14
14
|
}
|
|
15
|
-
|
|
15
|
+
const 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
16
|
return cacheDirPath;
|
|
17
17
|
}
|
|
18
18
|
function testCacheDirExists(packageName, cacheName) {
|
|
19
|
-
|
|
19
|
+
const cacheDirPath = getTestCacheDirPath(packageName, cacheName);
|
|
20
20
|
return (0, fs_1.existsSync)(cacheDirPath);
|
|
21
21
|
}
|
|
@@ -1,94 +1,37 @@
|
|
|
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
|
-
};
|
|
38
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
3
|
exports.createTestPackagesDir = createTestPackagesDir;
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
function createTestPackagesProject(projectDir) {
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
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*/];
|
|
4
|
+
const fs_1 = require("fs");
|
|
5
|
+
const path_1 = require("path");
|
|
6
|
+
const PackageJson_1 = require("../services/PackageJson");
|
|
7
|
+
const PluginService_1 = require("../services/PluginService");
|
|
8
|
+
const test_project_1 = require("./test-project");
|
|
9
|
+
const file_system_1 = require("./file-system");
|
|
10
|
+
const cli_1 = require("./cli");
|
|
11
|
+
async function createTestPackagesProject(projectDir) {
|
|
12
|
+
const originalPackagesPath = (0, path_1.resolve)(__dirname, "../../..");
|
|
13
|
+
const projectDirPackages = (0, path_1.resolve)(projectDir, "packages");
|
|
14
|
+
await (0, file_system_1.copyFolder)(originalPackagesPath, projectDirPackages);
|
|
15
|
+
const projectDirPackagesFiles = (0, fs_1.readdirSync)(projectDirPackages);
|
|
16
|
+
for (const projectDirPackagesFile of projectDirPackagesFiles) {
|
|
17
|
+
const packagePath = (0, path_1.resolve)(projectDirPackages, projectDirPackagesFile);
|
|
18
|
+
if (!(0, fs_1.lstatSync)(packagePath).isDirectory()) {
|
|
19
|
+
continue;
|
|
20
|
+
}
|
|
21
|
+
const packageJson = PackageJson_1.PackageJson.fromDirPath(packagePath);
|
|
22
|
+
const content = packageJson.getContent();
|
|
23
|
+
if (content.dependencies) {
|
|
24
|
+
for (const packageName of Object.keys(content.dependencies)) {
|
|
25
|
+
if (PluginService_1.PluginService.packageNameIsPlugin(packageName)) {
|
|
26
|
+
const pluginShortName = PluginService_1.PluginService.getPluginShortname(packageName);
|
|
27
|
+
const dependencyPath = (0, path_1.resolve)((0, path_1.join)(packagePath, "..", pluginShortName));
|
|
28
|
+
content.dependencies[packageName] = `file://${dependencyPath}`;
|
|
29
|
+
}
|
|
89
30
|
}
|
|
90
|
-
|
|
91
|
-
|
|
31
|
+
packageJson.setContent(content);
|
|
32
|
+
}
|
|
33
|
+
await (0, cli_1.safeExec)(packagePath, "npm install");
|
|
34
|
+
}
|
|
92
35
|
}
|
|
93
36
|
/**
|
|
94
37
|
* Create a full file structure for testing ts-dev-tools packages installation
|
|
@@ -96,12 +39,7 @@ function createTestPackagesProject(projectDir) {
|
|
|
96
39
|
* @param projectDir path where to prepare packages
|
|
97
40
|
* @returns packages directory path
|
|
98
41
|
*/
|
|
99
|
-
function createTestPackagesDir(filename) {
|
|
100
|
-
|
|
101
|
-
|
|
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
|
-
});
|
|
42
|
+
async function createTestPackagesDir(filename) {
|
|
43
|
+
const testPackagesFileName = filename.replace(".spec.ts", `-test-packages.spec.ts`);
|
|
44
|
+
return (0, test_project_1.createProjectForTestFile)(testPackagesFileName, false, createTestPackagesProject);
|
|
107
45
|
}
|
|
@@ -1,97 +1,34 @@
|
|
|
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
|
-
};
|
|
38
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
3
|
exports.createTestMonorepoProject = void 0;
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
function generateProjectInMonorepoProject(packageName, projectDir, useCache, testProjectGenerator) {
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
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
|
-
});
|
|
4
|
+
const path_1 = require("path");
|
|
5
|
+
const PackageJson_1 = require("../services/PackageJson");
|
|
6
|
+
const cli_1 = require("./cli");
|
|
7
|
+
const test_project_1 = require("./test-project");
|
|
8
|
+
async function generateProjectInMonorepoProject(packageName, projectDir, useCache, testProjectGenerator) {
|
|
9
|
+
await (0, cli_1.safeExec)(projectDir, "npm init --yes");
|
|
10
|
+
await (0, cli_1.safeExec)(projectDir, "npm install");
|
|
11
|
+
await (0, cli_1.safeExec)(projectDir, "npm install --save-dev -W typescript");
|
|
12
|
+
await (0, cli_1.safeExec)(projectDir, "npm exec tsc -- --init");
|
|
13
|
+
PackageJson_1.PackageJson.fromDirPath(projectDir).merge({
|
|
14
|
+
private: true,
|
|
15
|
+
workspaces: ["packages/*"],
|
|
78
16
|
});
|
|
17
|
+
const packageDir = (0, path_1.join)(projectDir, "packages/test-package");
|
|
18
|
+
await (0, test_project_1.createTestProject)(packageName, packageDir, useCache, testProjectGenerator);
|
|
19
|
+
await (0, cli_1.safeExec)(projectDir, `npm exec lerna -- init --no-progress --skipInstall`);
|
|
20
|
+
await (0, cli_1.safeExec)(projectDir, "npm install");
|
|
79
21
|
}
|
|
80
22
|
function generateMonorepoProject(packageName, useCache, testProjectGenerator) {
|
|
81
|
-
|
|
82
|
-
return generateProjectInMonorepoProject(packageName, projectDir, useCache, testProjectGenerator);
|
|
83
|
-
};
|
|
23
|
+
const projectGenerator = (projectDir) => generateProjectInMonorepoProject(packageName, projectDir, useCache, testProjectGenerator);
|
|
84
24
|
Object.defineProperty(projectGenerator, "name", {
|
|
85
|
-
value:
|
|
25
|
+
value: `monorepo-project-generator-${testProjectGenerator.name}`,
|
|
86
26
|
configurable: true,
|
|
87
27
|
});
|
|
88
28
|
return projectGenerator;
|
|
89
29
|
}
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
return
|
|
93
|
-
|
|
94
|
-
return [2 /*return*/, (0, test_project_1.createProjectForTestFile)(filepath, useCache, generateMonorepoProject(packageName, useCache, testProjectGenerator))];
|
|
95
|
-
});
|
|
96
|
-
}); };
|
|
30
|
+
const createTestMonorepoProject = async (filepath, useCache, testProjectGenerator) => {
|
|
31
|
+
const packageName = (0, test_project_1.getPackageNameFromFilepath)(filepath);
|
|
32
|
+
return (0, test_project_1.createProjectForTestFile)(filepath, useCache, generateMonorepoProject(packageName, useCache, testProjectGenerator));
|
|
33
|
+
};
|
|
97
34
|
exports.createTestMonorepoProject = createTestMonorepoProject;
|
|
@@ -1,148 +1,70 @@
|
|
|
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
|
-
};
|
|
38
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
3
|
exports.getPackageNameFromFilepath = void 0;
|
|
40
4
|
exports.createTestProject = createTestProject;
|
|
41
5
|
exports.createProjectForTestFile = createProjectForTestFile;
|
|
42
6
|
exports.deleteTestProject = deleteTestProject;
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
7
|
+
const fs_1 = require("fs");
|
|
8
|
+
const path_1 = require("path");
|
|
9
|
+
const test_cache_1 = require("./test-cache");
|
|
10
|
+
const file_system_1 = require("./file-system");
|
|
11
|
+
const os_1 = require("os");
|
|
12
|
+
const rootDirPath = (0, path_1.resolve)(__dirname, "../../../..");
|
|
13
|
+
const corePackageDirPath = (0, path_1.resolve)(__dirname, "..", "..");
|
|
14
|
+
const testProjectDir = (0, path_1.resolve)("__tests__/test-project");
|
|
15
|
+
const defaultPackageJsonPath = (0, path_1.join)(testProjectDir, "package.json");
|
|
16
|
+
const getPackageNameFromFilepath = (filepath) => {
|
|
17
|
+
const relativeFilepath = (0, path_1.relative)(rootDirPath, filepath);
|
|
18
|
+
const parts = relativeFilepath.split("/");
|
|
55
19
|
if (parts.length < 2) {
|
|
56
20
|
throw new Error("Invalid filepath: " + filepath);
|
|
57
21
|
}
|
|
58
|
-
|
|
22
|
+
const packageName = parts[1];
|
|
59
23
|
if (!packageName) {
|
|
60
24
|
throw new Error("Package name could not be determined from the filepath: " + filepath);
|
|
61
25
|
}
|
|
62
26
|
return packageName;
|
|
63
27
|
};
|
|
64
28
|
exports.getPackageNameFromFilepath = getPackageNameFromFilepath;
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
29
|
+
const getTestProjectDirPath = (filename) => {
|
|
30
|
+
const testProjectRootDirPath = (0, path_1.join)((0, os_1.tmpdir)(), "ts-dev-tools");
|
|
31
|
+
const relativeFilepath = (0, path_1.relative)(rootDirPath, filename);
|
|
32
|
+
const testProjectDirName = "test-" + relativeFilepath.toLowerCase().replace(/[^a-z0-9]/g, "-");
|
|
69
33
|
return (0, path_1.join)(testProjectRootDirPath, testProjectDirName);
|
|
70
34
|
};
|
|
71
|
-
function defaultProjectGenerator(testProjectDirPath) {
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
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
|
-
});
|
|
35
|
+
async function defaultProjectGenerator(testProjectDirPath) {
|
|
36
|
+
// Fake node_modules
|
|
37
|
+
const corePackageRootPath = (0, path_1.join)(testProjectDirPath, "node_modules/@ts-dev-tools/core");
|
|
38
|
+
await (0, file_system_1.recreateFolderRecursive)(corePackageRootPath);
|
|
39
|
+
(0, fs_1.copyFileSync)((0, path_1.join)(corePackageDirPath, "package.json"), (0, path_1.join)(corePackageRootPath, "package.json"));
|
|
40
|
+
// Fake migrations
|
|
41
|
+
const tsDevToolsDistPath = (0, path_1.join)(corePackageRootPath, "dist");
|
|
42
|
+
(0, fs_1.symlinkSync)((0, path_1.resolve)(__dirname, ".."), tsDevToolsDistPath);
|
|
43
|
+
(0, fs_1.copyFileSync)(defaultPackageJsonPath, (0, path_1.join)(testProjectDirPath, "package.json"));
|
|
89
44
|
}
|
|
90
|
-
function createTestProject(
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
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
|
-
});
|
|
45
|
+
async function createTestProject(packageName, testDirPath, useCache, testProjectGenerator = defaultProjectGenerator) {
|
|
46
|
+
await (0, file_system_1.recreateFolderRecursive)(testDirPath);
|
|
47
|
+
const cacheName = testProjectGenerator.name;
|
|
48
|
+
const testCacheDirPath = (0, test_cache_1.getTestCacheDirPath)(packageName, cacheName);
|
|
49
|
+
if (useCache && (0, test_cache_1.testCacheDirExists)(packageName, cacheName)) {
|
|
50
|
+
await (0, file_system_1.copyFolder)(testCacheDirPath, testDirPath);
|
|
51
|
+
return testDirPath;
|
|
52
|
+
}
|
|
53
|
+
await testProjectGenerator(testDirPath);
|
|
54
|
+
// Add mandatory project fixtures
|
|
55
|
+
const gitHooksDirPath = (0, path_1.join)(testDirPath, ".git/hooks");
|
|
56
|
+
await (0, file_system_1.recreateFolderRecursive)(gitHooksDirPath);
|
|
57
|
+
if (useCache) {
|
|
58
|
+
await (0, file_system_1.copyFolder)(testDirPath, testCacheDirPath);
|
|
59
|
+
}
|
|
60
|
+
return testDirPath;
|
|
122
61
|
}
|
|
123
|
-
function createProjectForTestFile(
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
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
|
-
});
|
|
62
|
+
async function createProjectForTestFile(filepath, useCache, testProjectGenerator = defaultProjectGenerator) {
|
|
63
|
+
const testDirPath = getTestProjectDirPath(filepath);
|
|
64
|
+
const packageName = (0, exports.getPackageNameFromFilepath)(filepath);
|
|
65
|
+
return createTestProject(packageName, testDirPath, useCache, testProjectGenerator);
|
|
133
66
|
}
|
|
134
|
-
function deleteTestProject(filepath) {
|
|
135
|
-
|
|
136
|
-
|
|
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
|
-
});
|
|
67
|
+
async function deleteTestProject(filepath) {
|
|
68
|
+
const testProjectDirPath = getTestProjectDirPath(filepath);
|
|
69
|
+
await (0, file_system_1.deleteFolderRecursive)(testProjectDirPath);
|
|
148
70
|
}
|