@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,90 +1,43 @@
|
|
|
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.GitService = void 0;
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
4
|
+
const fs_1 = require("fs");
|
|
5
|
+
const path_1 = require("path");
|
|
6
|
+
const constants_1 = require("../constants");
|
|
7
|
+
const CmdService_1 = require("./CmdService");
|
|
8
|
+
class GitService {
|
|
9
|
+
static async isGitRepository(absoluteProjectDir) {
|
|
10
|
+
return await CmdService_1.CmdService.execCmd("git rev-parse", absoluteProjectDir, true)
|
|
11
|
+
.then(() => true)
|
|
12
|
+
.catch(() => false);
|
|
46
13
|
}
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
gitHookDirPath = (0, path_1.join)(absoluteProjectDir, ".git/hooks");
|
|
64
|
-
gitHookFilePath = (0, path_1.join)(gitHookDirPath, gitHookName);
|
|
65
|
-
if ((0, fs_1.existsSync)(gitHookFilePath)) {
|
|
66
|
-
mode = GitService.getFilePermissions(gitHookFilePath);
|
|
67
|
-
if (mode !== GitService.GIT_HOOK_MODE) {
|
|
68
|
-
(0, fs_1.chmodSync)(gitHookFilePath, GitService.GIT_HOOK_MODE);
|
|
69
|
-
}
|
|
70
|
-
return [2 /*return*/];
|
|
71
|
-
}
|
|
72
|
-
return [2 /*return*/, new Promise(function (resolve, reject) {
|
|
73
|
-
var stream = (0, fs_1.createWriteStream)(gitHookFilePath, { mode: GitService.GIT_HOOK_MODE });
|
|
74
|
-
stream.on("close", function () { return resolve(undefined); });
|
|
75
|
-
stream.on("error", function (error) { return reject(error); });
|
|
76
|
-
stream.write(GitService.GIT_HOOK_TEMPLATE.replace("%gitHookCommand%", gitHookCommand));
|
|
77
|
-
stream.end();
|
|
78
|
-
})];
|
|
79
|
-
});
|
|
14
|
+
static async addGitHook(absoluteProjectDir, gitHookName, gitHookCommand) {
|
|
15
|
+
const gitHookDirPath = (0, path_1.join)(absoluteProjectDir, ".git/hooks");
|
|
16
|
+
const gitHookFilePath = (0, path_1.join)(gitHookDirPath, gitHookName);
|
|
17
|
+
if ((0, fs_1.existsSync)(gitHookFilePath)) {
|
|
18
|
+
const mode = GitService.getFilePermissions(gitHookFilePath);
|
|
19
|
+
if (mode !== GitService.GIT_HOOK_MODE) {
|
|
20
|
+
(0, fs_1.chmodSync)(gitHookFilePath, GitService.GIT_HOOK_MODE);
|
|
21
|
+
}
|
|
22
|
+
return;
|
|
23
|
+
}
|
|
24
|
+
return new Promise((resolve, reject) => {
|
|
25
|
+
const stream = (0, fs_1.createWriteStream)(gitHookFilePath, { mode: GitService.GIT_HOOK_MODE });
|
|
26
|
+
stream.on("close", () => resolve(undefined));
|
|
27
|
+
stream.on("error", (error) => reject(error));
|
|
28
|
+
stream.write(GitService.GIT_HOOK_TEMPLATE.replace("%gitHookCommand%", gitHookCommand));
|
|
29
|
+
stream.end();
|
|
80
30
|
});
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
|
|
31
|
+
}
|
|
32
|
+
static getFilePermissions(filePath) {
|
|
33
|
+
const { mode } = (0, fs_1.statSync)(filePath);
|
|
84
34
|
return mode & parseInt("777", 8);
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
GitService.GIT_HOOK_TEMPLATE = "#!/bin/sh\n\n# Created by ".concat(constants_1.PROJECT_NAME, " (").concat(constants_1.PROJECT_URL, ")\n\n%gitHookCommand%");
|
|
88
|
-
return GitService;
|
|
89
|
-
}());
|
|
35
|
+
}
|
|
36
|
+
}
|
|
90
37
|
exports.GitService = GitService;
|
|
38
|
+
GitService.GIT_HOOK_MODE = 0o755;
|
|
39
|
+
GitService.GIT_HOOK_TEMPLATE = `#!/bin/sh
|
|
40
|
+
|
|
41
|
+
# Created by ${constants_1.PROJECT_NAME} (${constants_1.PROJECT_URL})
|
|
42
|
+
|
|
43
|
+
%gitHookCommand%`;
|
|
@@ -32,144 +32,75 @@ var __importStar = (this && this.__importStar) || (function () {
|
|
|
32
32
|
return result;
|
|
33
33
|
};
|
|
34
34
|
})();
|
|
35
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
36
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
37
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
38
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
39
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
40
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
41
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
42
|
-
});
|
|
43
|
-
};
|
|
44
|
-
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
45
|
-
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);
|
|
46
|
-
return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
47
|
-
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
48
|
-
function step(op) {
|
|
49
|
-
if (f) throw new TypeError("Generator is already executing.");
|
|
50
|
-
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
|
51
|
-
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;
|
|
52
|
-
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
53
|
-
switch (op[0]) {
|
|
54
|
-
case 0: case 1: t = op; break;
|
|
55
|
-
case 4: _.label++; return { value: op[1], done: false };
|
|
56
|
-
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
57
|
-
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
58
|
-
default:
|
|
59
|
-
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
60
|
-
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
61
|
-
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
62
|
-
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
63
|
-
if (t[2]) _.ops.pop();
|
|
64
|
-
_.trys.pop(); continue;
|
|
65
|
-
}
|
|
66
|
-
op = body.call(thisArg, _);
|
|
67
|
-
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
68
|
-
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
69
|
-
}
|
|
70
|
-
};
|
|
71
35
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
72
36
|
exports.MigrationsService = void 0;
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
37
|
+
const fs_1 = require("fs");
|
|
38
|
+
const path_1 = require("path");
|
|
39
|
+
const PackageJson_1 = require("../services/PackageJson");
|
|
40
|
+
const PluginService_1 = require("./PluginService");
|
|
41
|
+
class MigrationsService {
|
|
42
|
+
static async executeMigrations(absoluteProjectDir, currentVersion) {
|
|
43
|
+
const migrations = MigrationsService.getAvailableMigrations(absoluteProjectDir, currentVersion);
|
|
44
|
+
const packageJson = PackageJson_1.PackageJson.fromDirPath(absoluteProjectDir);
|
|
45
|
+
const packageJsonBackupPath = packageJson.backup();
|
|
46
|
+
try {
|
|
47
|
+
for (const migration of migrations) {
|
|
48
|
+
console.info(`Applying migration "${migration.fullname}"...`);
|
|
49
|
+
const { up } = await Promise.resolve(`${migration.path}`).then(s => __importStar(require(s)));
|
|
50
|
+
// Apply migration
|
|
51
|
+
await up(absoluteProjectDir);
|
|
52
|
+
// Upgrade current version
|
|
53
|
+
PackageJson_1.PackageJson.fromDirPath(absoluteProjectDir).merge({
|
|
54
|
+
tsDevTools: { version: migration.shortname },
|
|
55
|
+
});
|
|
56
|
+
console.info(`Migration "${migration.fullname}" applied!`);
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
catch (error) {
|
|
60
|
+
// Rollback package.json
|
|
61
|
+
packageJson.restore(packageJsonBackupPath);
|
|
62
|
+
throw error;
|
|
63
|
+
}
|
|
64
|
+
if ((0, fs_1.existsSync)(packageJsonBackupPath)) {
|
|
65
|
+
(0, fs_1.unlinkSync)(packageJsonBackupPath);
|
|
66
|
+
}
|
|
79
67
|
}
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
case 0:
|
|
86
|
-
migrations = MigrationsService.getAvailableMigrations(absoluteProjectDir, currentVersion);
|
|
87
|
-
packageJson = PackageJson_1.PackageJson.fromDirPath(absoluteProjectDir);
|
|
88
|
-
packageJsonBackupPath = packageJson.backup();
|
|
89
|
-
_a.label = 1;
|
|
90
|
-
case 1:
|
|
91
|
-
_a.trys.push([1, 7, , 8]);
|
|
92
|
-
_i = 0, migrations_1 = migrations;
|
|
93
|
-
_a.label = 2;
|
|
94
|
-
case 2:
|
|
95
|
-
if (!(_i < migrations_1.length)) return [3 /*break*/, 6];
|
|
96
|
-
migration = migrations_1[_i];
|
|
97
|
-
console.info("Applying migration \"".concat(migration.fullname, "\"..."));
|
|
98
|
-
return [4 /*yield*/, Promise.resolve("".concat(migration.path)).then(function (s) { return __importStar(require(s)); })];
|
|
99
|
-
case 3:
|
|
100
|
-
up = (_a.sent()).up;
|
|
101
|
-
// Apply migration
|
|
102
|
-
return [4 /*yield*/, up(absoluteProjectDir)];
|
|
103
|
-
case 4:
|
|
104
|
-
// Apply migration
|
|
105
|
-
_a.sent();
|
|
106
|
-
// Upgrade current version
|
|
107
|
-
PackageJson_1.PackageJson.fromDirPath(absoluteProjectDir).merge({
|
|
108
|
-
tsDevTools: { version: migration.shortname },
|
|
109
|
-
});
|
|
110
|
-
console.info("Migration \"".concat(migration.fullname, "\" applied!"));
|
|
111
|
-
_a.label = 5;
|
|
112
|
-
case 5:
|
|
113
|
-
_i++;
|
|
114
|
-
return [3 /*break*/, 2];
|
|
115
|
-
case 6: return [3 /*break*/, 8];
|
|
116
|
-
case 7:
|
|
117
|
-
error_1 = _a.sent();
|
|
118
|
-
// Rollback package.json
|
|
119
|
-
packageJson.restore(packageJsonBackupPath);
|
|
120
|
-
throw error_1;
|
|
121
|
-
case 8:
|
|
122
|
-
if ((0, fs_1.existsSync)(packageJsonBackupPath)) {
|
|
123
|
-
(0, fs_1.unlinkSync)(packageJsonBackupPath);
|
|
124
|
-
}
|
|
125
|
-
return [2 /*return*/];
|
|
126
|
-
}
|
|
127
|
-
});
|
|
128
|
-
});
|
|
129
|
-
};
|
|
130
|
-
MigrationsService.getAvailableMigrations = function (absoluteProjectDir, currentVersion) {
|
|
131
|
-
var installedPlugins = PluginService_1.PluginService.getInstalledPlugins(absoluteProjectDir);
|
|
132
|
-
var migrationFiles = [];
|
|
133
|
-
for (var _i = 0, installedPlugins_1 = installedPlugins; _i < installedPlugins_1.length; _i++) {
|
|
134
|
-
var installedPlugin = installedPlugins_1[_i];
|
|
135
|
-
migrationFiles.push.apply(migrationFiles, MigrationsService.getPluginMigrations(installedPlugin, currentVersion));
|
|
68
|
+
static getAvailableMigrations(absoluteProjectDir, currentVersion) {
|
|
69
|
+
const installedPlugins = PluginService_1.PluginService.getInstalledPlugins(absoluteProjectDir);
|
|
70
|
+
const migrationFiles = [];
|
|
71
|
+
for (const installedPlugin of installedPlugins) {
|
|
72
|
+
migrationFiles.push(...MigrationsService.getPluginMigrations(installedPlugin, currentVersion));
|
|
136
73
|
}
|
|
137
|
-
migrationFiles.sort(
|
|
138
|
-
var nameA = _a.shortname;
|
|
139
|
-
var nameB = _b.shortname;
|
|
140
|
-
return nameA.localeCompare(nameB);
|
|
141
|
-
});
|
|
74
|
+
migrationFiles.sort(({ shortname: nameA }, { shortname: nameB }) => nameA.localeCompare(nameB));
|
|
142
75
|
return Array.from(new Set(migrationFiles));
|
|
143
|
-
}
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
for (
|
|
148
|
-
var migrationFile = _a[_i];
|
|
76
|
+
}
|
|
77
|
+
static getPluginMigrations(plugin, currentVersion) {
|
|
78
|
+
const migrationFiles = [];
|
|
79
|
+
const pluginMigrationsDirPath = (0, path_1.resolve)(plugin.path, MigrationsService.MIGRATION_BUILT_PATH);
|
|
80
|
+
for (const migrationFile of (0, fs_1.readdirSync)(pluginMigrationsDirPath)) {
|
|
149
81
|
if (!migrationFile.match(/^[0-9]{14}-[-a-z]+\.(js|ts)$/)) {
|
|
150
82
|
continue;
|
|
151
83
|
}
|
|
152
|
-
|
|
153
|
-
|
|
84
|
+
const migrationName = MigrationsService.getMigrationNameFromFile(migrationFile);
|
|
85
|
+
const shouldApplyMigration = MigrationsService.migrationIsAfterCurrentVersion(migrationName, currentVersion);
|
|
154
86
|
if (!shouldApplyMigration) {
|
|
155
87
|
continue;
|
|
156
88
|
}
|
|
157
89
|
migrationFiles.push({
|
|
158
90
|
shortname: migrationName,
|
|
159
|
-
fullname:
|
|
91
|
+
fullname: `${plugin.shortname} - ${migrationName}`,
|
|
160
92
|
path: (0, path_1.resolve)(pluginMigrationsDirPath, migrationFile),
|
|
161
93
|
});
|
|
162
94
|
}
|
|
163
95
|
return migrationFiles;
|
|
164
|
-
}
|
|
165
|
-
|
|
166
|
-
|
|
96
|
+
}
|
|
97
|
+
static getMigrationNameFromFile(migrationFile) {
|
|
98
|
+
const migrationName = migrationFile.split(".").slice(0, -1).join(".");
|
|
167
99
|
return migrationName;
|
|
168
|
-
}
|
|
169
|
-
|
|
100
|
+
}
|
|
101
|
+
static migrationIsAfterCurrentVersion(migrationName, currentVersion) {
|
|
170
102
|
return !currentVersion || currentVersion.localeCompare(migrationName) < 0;
|
|
171
|
-
}
|
|
172
|
-
|
|
173
|
-
return MigrationsService;
|
|
174
|
-
}());
|
|
103
|
+
}
|
|
104
|
+
}
|
|
175
105
|
exports.MigrationsService = MigrationsService;
|
|
106
|
+
MigrationsService.MIGRATION_BUILT_PATH = "dist/install/migrations";
|
|
@@ -1,88 +1,78 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
|
|
3
|
-
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
|
|
4
|
-
if (ar || !(i in from)) {
|
|
5
|
-
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
|
|
6
|
-
ar[i] = from[i];
|
|
7
|
-
}
|
|
8
|
-
}
|
|
9
|
-
return to.concat(ar || Array.prototype.slice.call(from));
|
|
10
|
-
};
|
|
11
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
3
|
exports.PackageJson = void 0;
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
4
|
+
const PackageJsonMerge_1 = require("./PackageJsonMerge");
|
|
5
|
+
const FileService_1 = require("./FileService");
|
|
6
|
+
const path_1 = require("path");
|
|
7
|
+
class PackageJson {
|
|
8
|
+
constructor(path) {
|
|
18
9
|
this.path = path;
|
|
19
10
|
this.content = undefined;
|
|
20
11
|
if (!FileService_1.FileService.fileExists(this.path)) {
|
|
21
|
-
throw new Error(
|
|
12
|
+
throw new Error(`Package.json "${this.path}" does not exist`);
|
|
22
13
|
}
|
|
23
14
|
}
|
|
24
|
-
|
|
15
|
+
getPath() {
|
|
25
16
|
return this.path;
|
|
26
|
-
}
|
|
27
|
-
|
|
17
|
+
}
|
|
18
|
+
getContent() {
|
|
28
19
|
if (this.content) {
|
|
29
20
|
return this.content;
|
|
30
21
|
}
|
|
31
22
|
return (this.content = JSON.parse(FileService_1.FileService.getFileContent(this.path)));
|
|
32
|
-
}
|
|
33
|
-
|
|
23
|
+
}
|
|
24
|
+
setContent(content) {
|
|
34
25
|
this.content = content;
|
|
35
26
|
this.write();
|
|
36
|
-
}
|
|
37
|
-
|
|
27
|
+
}
|
|
28
|
+
getPackageName() {
|
|
38
29
|
return this.getContent().name;
|
|
39
|
-
}
|
|
40
|
-
|
|
30
|
+
}
|
|
31
|
+
getPackageVersion() {
|
|
41
32
|
return this.getContent().version;
|
|
42
|
-
}
|
|
43
|
-
|
|
33
|
+
}
|
|
34
|
+
isPrivate() {
|
|
44
35
|
return this.getContent().private === true;
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
36
|
+
}
|
|
37
|
+
getTsDevToolsVersion() {
|
|
38
|
+
const tsDevToolsConfig = this.getContent().tsDevTools;
|
|
39
|
+
const version = tsDevToolsConfig?.version;
|
|
49
40
|
return version;
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
|
|
41
|
+
}
|
|
42
|
+
getDependenciesPackageNames() {
|
|
43
|
+
const dependencies = this.getContent().dependencies;
|
|
53
44
|
return dependencies ? Object.keys(dependencies) : [];
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
|
|
45
|
+
}
|
|
46
|
+
getDevDependenciesPackageNames() {
|
|
47
|
+
const devDependencies = this.getContent().devDependencies;
|
|
57
48
|
return devDependencies ? Object.keys(devDependencies) : [];
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
return Array.from(new Set(
|
|
61
|
-
}
|
|
62
|
-
|
|
49
|
+
}
|
|
50
|
+
getAllDependenciesPackageNames() {
|
|
51
|
+
return Array.from(new Set([...this.getDependenciesPackageNames(), ...this.getDevDependenciesPackageNames()]));
|
|
52
|
+
}
|
|
53
|
+
hasDependency(packageName) {
|
|
63
54
|
return this.getAllDependenciesPackageNames().includes(packageName);
|
|
64
|
-
}
|
|
65
|
-
|
|
55
|
+
}
|
|
56
|
+
merge(update) {
|
|
66
57
|
this.content = PackageJsonMerge_1.PackageJsonMerge.merge(this.getContent(), update);
|
|
67
58
|
this.write();
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
|
|
59
|
+
}
|
|
60
|
+
backup() {
|
|
61
|
+
const backupPath = this.path + ".backup";
|
|
71
62
|
FileService_1.FileService.copyFile(this.path, backupPath);
|
|
72
63
|
return backupPath;
|
|
73
|
-
}
|
|
74
|
-
|
|
64
|
+
}
|
|
65
|
+
restore(backupPath) {
|
|
75
66
|
FileService_1.FileService.copyFile(backupPath, this.path);
|
|
76
67
|
this.content = undefined;
|
|
77
|
-
}
|
|
78
|
-
|
|
68
|
+
}
|
|
69
|
+
write() {
|
|
79
70
|
FileService_1.FileService.putFileContent(this.path, JSON.stringify(this.content, null, 2));
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
|
|
71
|
+
}
|
|
72
|
+
static fromDirPath(dirPath) {
|
|
73
|
+
const packageJsonPath = (0, path_1.join)(dirPath, PackageJson.PACKAGE_JSON_FILE_NAME);
|
|
83
74
|
return new PackageJson(packageJsonPath);
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
return PackageJson;
|
|
87
|
-
}());
|
|
75
|
+
}
|
|
76
|
+
}
|
|
88
77
|
exports.PackageJson = PackageJson;
|
|
78
|
+
PackageJson.PACKAGE_JSON_FILE_NAME = "package.json";
|
|
@@ -1,18 +1,16 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.PackageJsonMerge = void 0;
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
}
|
|
7
|
-
PackageJsonMerge.merge = function (source, update) {
|
|
4
|
+
class PackageJsonMerge {
|
|
5
|
+
static merge(source, update) {
|
|
8
6
|
return PackageJsonMerge.mergeObjects(source, update);
|
|
9
|
-
}
|
|
10
|
-
|
|
7
|
+
}
|
|
8
|
+
static mergeValues(source, update) {
|
|
11
9
|
if (source === undefined) {
|
|
12
10
|
return update;
|
|
13
11
|
}
|
|
14
12
|
if (!PackageJsonMerge.typesEqual(source, update)) {
|
|
15
|
-
throw new Error(
|
|
13
|
+
throw new Error(`Unable to merge package json value because types are different`);
|
|
16
14
|
}
|
|
17
15
|
// Deal with arrays
|
|
18
16
|
if (Array.isArray(update)) {
|
|
@@ -23,35 +21,33 @@ var PackageJsonMerge = /** @class */ (function () {
|
|
|
23
21
|
return PackageJsonMerge.mergeObjects(source, update);
|
|
24
22
|
}
|
|
25
23
|
return update;
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
for (
|
|
24
|
+
}
|
|
25
|
+
static mergeObjects(source, update) {
|
|
26
|
+
for (const updateKey in update) {
|
|
29
27
|
if (!Object.prototype.hasOwnProperty.call(update, updateKey)) {
|
|
30
28
|
continue;
|
|
31
29
|
}
|
|
32
|
-
|
|
33
|
-
|
|
30
|
+
const updateValue = update[updateKey];
|
|
31
|
+
const sourceValue = Object.prototype.hasOwnProperty.call(source, updateKey)
|
|
34
32
|
? source[updateKey]
|
|
35
33
|
: undefined;
|
|
36
34
|
source[updateKey] = PackageJsonMerge.mergeValues(sourceValue, updateValue);
|
|
37
35
|
}
|
|
38
36
|
return source;
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
for (
|
|
42
|
-
var item = update_1[_i];
|
|
37
|
+
}
|
|
38
|
+
static mergeArrays(source, update) {
|
|
39
|
+
for (const item of update) {
|
|
43
40
|
if (!source.includes(item)) {
|
|
44
41
|
source.push(item);
|
|
45
42
|
}
|
|
46
43
|
}
|
|
47
44
|
return source;
|
|
48
|
-
}
|
|
49
|
-
|
|
45
|
+
}
|
|
46
|
+
static typesEqual(sourceValue, updateValue) {
|
|
50
47
|
if (Array.isArray(sourceValue) && !Array.isArray(updateValue)) {
|
|
51
48
|
return false;
|
|
52
49
|
}
|
|
53
50
|
return typeof sourceValue === typeof updateValue;
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
}());
|
|
51
|
+
}
|
|
52
|
+
}
|
|
57
53
|
exports.PackageJsonMerge = PackageJsonMerge;
|