@turbo/codemod 1.7.1-canary.1 → 1.7.1-canary.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/README.md +50 -1
- package/dist/cli.js +857 -0
- package/dist/transforms/add-package-manager.js +284 -102
- package/dist/transforms/create-turbo-config.js +262 -65
- package/dist/transforms/migrate-env-var-dependencies.js +265 -60
- package/dist/transforms/set-default-outputs.js +258 -65
- package/package.json +16 -11
- package/dist/getPackageManagerVersion.js +0 -42
- package/dist/getWorkspaceImplementation.js +0 -73
- package/dist/git.js +0 -56
- package/dist/index.js +0 -300
- package/dist/logger.js +0 -46
- package/dist/runTransform.js +0 -44
- package/dist/types.js +0 -18
@@ -23,87 +23,280 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
23
23
|
// src/transforms/set-default-outputs.ts
|
24
24
|
var set_default_outputs_exports = {};
|
25
25
|
__export(set_default_outputs_exports, {
|
26
|
-
default: () =>
|
26
|
+
default: () => set_default_outputs_default,
|
27
|
+
transformer: () => transformer
|
27
28
|
});
|
28
29
|
module.exports = __toCommonJS(set_default_outputs_exports);
|
29
|
-
var
|
30
|
-
var
|
30
|
+
var import_path2 = __toESM(require("path"));
|
31
|
+
var import_fs_extra2 = __toESM(require("fs-extra"));
|
32
|
+
|
33
|
+
// src/runner/Runner.ts
|
34
|
+
var import_chalk3 = __toESM(require("chalk"));
|
31
35
|
|
32
|
-
// src/
|
36
|
+
// src/runner/FileTransform.ts
|
33
37
|
var import_chalk = __toESM(require("chalk"));
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
38
|
+
var import_diff = require("diff");
|
39
|
+
var import_fs_extra = __toESM(require("fs-extra"));
|
40
|
+
var import_os = __toESM(require("os"));
|
41
|
+
var import_path = __toESM(require("path"));
|
42
|
+
var FileTransform = class {
|
43
|
+
constructor(args) {
|
44
|
+
this.changes = [];
|
45
|
+
this.filePath = args.filePath;
|
46
|
+
this.rootPath = args.rootPath;
|
47
|
+
this.after = args.after;
|
48
|
+
this.error = args.error;
|
49
|
+
if (args.before === void 0) {
|
50
|
+
try {
|
51
|
+
if (import_path.default.extname(args.filePath) === ".json") {
|
52
|
+
this.before = import_fs_extra.default.readJsonSync(args.filePath);
|
53
|
+
} else {
|
54
|
+
this.before = import_fs_extra.default.readFileSync(args.filePath);
|
55
|
+
}
|
56
|
+
} catch (err) {
|
57
|
+
this.before = "";
|
58
|
+
}
|
59
|
+
} else if (args.before === null) {
|
60
|
+
this.before = "";
|
61
|
+
} else {
|
62
|
+
this.before = args.before;
|
63
|
+
}
|
64
|
+
if (args.after) {
|
65
|
+
if (typeof this.before === "object" || typeof args.after === "object") {
|
66
|
+
this.changes = (0, import_diff.diffJson)(this.before, args.after);
|
67
|
+
} else {
|
68
|
+
this.changes = (0, import_diff.diffLines)(this.before, args.after);
|
69
|
+
}
|
70
|
+
} else {
|
71
|
+
this.changes = [];
|
72
|
+
}
|
73
|
+
}
|
74
|
+
fileName() {
|
75
|
+
return import_path.default.relative(this.rootPath, this.filePath);
|
76
|
+
}
|
77
|
+
write() {
|
78
|
+
if (this.after) {
|
79
|
+
if (typeof this.after === "object") {
|
80
|
+
import_fs_extra.default.writeJsonSync(this.filePath, this.after, { spaces: 2 });
|
81
|
+
} else {
|
82
|
+
import_fs_extra.default.writeFileSync(this.filePath, this.after);
|
83
|
+
}
|
84
|
+
}
|
85
|
+
}
|
86
|
+
additions() {
|
87
|
+
return this.changes.filter((c) => c.added).length;
|
88
|
+
}
|
89
|
+
deletions() {
|
90
|
+
return this.changes.filter((c) => c.removed).length;
|
91
|
+
}
|
92
|
+
hasChanges() {
|
93
|
+
return this.additions() > 0 || this.deletions() > 0;
|
94
|
+
}
|
95
|
+
log(args) {
|
96
|
+
if (args.diff) {
|
97
|
+
this.changes.forEach((part) => {
|
98
|
+
if (part.added) {
|
99
|
+
process.stdout.write(import_chalk.default.green(part.value));
|
100
|
+
} else if (part.removed) {
|
101
|
+
process.stdout.write(import_chalk.default.red(part.value));
|
102
|
+
} else {
|
103
|
+
process.stdout.write(import_chalk.default.dim(part.value));
|
104
|
+
}
|
105
|
+
});
|
106
|
+
console.log(import_os.default.EOL);
|
107
|
+
} else {
|
108
|
+
console.log(this.after);
|
109
|
+
}
|
110
|
+
}
|
111
|
+
};
|
112
|
+
|
113
|
+
// src/utils/logger.ts
|
114
|
+
var import_chalk2 = __toESM(require("chalk"));
|
115
|
+
var Logger = class {
|
116
|
+
constructor(args) {
|
117
|
+
this.transform = args.transformer;
|
118
|
+
this.dry = args.dry;
|
119
|
+
}
|
120
|
+
modified(...args) {
|
121
|
+
console.log(import_chalk2.default.green(` MODIFIED `), ...args, this.dry ? import_chalk2.default.dim(`(dry run)`) : "");
|
122
|
+
}
|
123
|
+
unchanged(...args) {
|
124
|
+
console.log(import_chalk2.default.gray(` UNCHANGED `), ...args, this.dry ? import_chalk2.default.dim(`(dry run)`) : "");
|
125
|
+
}
|
126
|
+
skipped(...args) {
|
127
|
+
console.log(import_chalk2.default.yellow(` SKIPPED `), ...args, this.dry ? import_chalk2.default.dim(`(dry run)`) : "");
|
128
|
+
}
|
129
|
+
error(...args) {
|
130
|
+
console.log(import_chalk2.default.red(` ERROR `), ...args, this.dry ? import_chalk2.default.dim(`(dry run)`) : "");
|
131
|
+
}
|
132
|
+
info(...args) {
|
133
|
+
console.log(import_chalk2.default.bold(` INFO `), ...args, this.dry ? import_chalk2.default.dim(`(dry run)`) : "");
|
134
|
+
}
|
135
|
+
};
|
136
|
+
|
137
|
+
// src/runner/Runner.ts
|
138
|
+
var Runner = class {
|
139
|
+
constructor(options) {
|
140
|
+
this.modifications = {};
|
141
|
+
this.transform = options.transformer;
|
142
|
+
this.rootPath = options.rootPath;
|
143
|
+
this.dry = options.dry;
|
144
|
+
this.print = options.print;
|
145
|
+
this.logger = new Logger(options);
|
146
|
+
}
|
147
|
+
abortTransform(args) {
|
148
|
+
this.logger.error(args.reason);
|
149
|
+
return {
|
150
|
+
fatalError: new Error(args.reason),
|
151
|
+
changes: args.changes || {}
|
152
|
+
};
|
153
|
+
}
|
154
|
+
modifyFile(args) {
|
155
|
+
this.modifications[args.filePath] = new FileTransform({
|
156
|
+
rootPath: this.rootPath,
|
157
|
+
...args
|
158
|
+
});
|
159
|
+
}
|
160
|
+
finish() {
|
161
|
+
const results = { changes: {} };
|
162
|
+
Object.keys(this.modifications).forEach((filePath) => {
|
163
|
+
const mod = this.modifications[filePath];
|
164
|
+
const result = {
|
165
|
+
action: "unchanged",
|
166
|
+
additions: mod.additions(),
|
167
|
+
deletions: mod.deletions()
|
168
|
+
};
|
169
|
+
if (mod.hasChanges()) {
|
170
|
+
if (this.dry) {
|
171
|
+
result.action = "skipped";
|
172
|
+
this.logger.skipped(import_chalk3.default.dim(mod.fileName()));
|
173
|
+
} else {
|
174
|
+
try {
|
175
|
+
mod.write();
|
176
|
+
result.action = "modified";
|
177
|
+
this.logger.modified(import_chalk3.default.bold(mod.fileName()));
|
178
|
+
} catch (err) {
|
179
|
+
let message = "Unknown error";
|
180
|
+
if (err instanceof Error) {
|
181
|
+
message = err.message;
|
182
|
+
}
|
183
|
+
result.error = new Error(message);
|
184
|
+
result.action = "error";
|
185
|
+
this.logger.error(mod.fileName(), message);
|
186
|
+
}
|
187
|
+
}
|
188
|
+
if (this.print) {
|
189
|
+
mod.log({ diff: true });
|
190
|
+
}
|
191
|
+
} else {
|
192
|
+
this.logger.unchanged(import_chalk3.default.dim(mod.fileName()));
|
193
|
+
}
|
194
|
+
results.changes[mod.fileName()] = result;
|
195
|
+
});
|
196
|
+
const encounteredError = Object.keys(results.changes).some((fileName) => {
|
197
|
+
return results.changes[fileName].action === "error";
|
198
|
+
});
|
199
|
+
if (encounteredError) {
|
200
|
+
return this.abortTransform({
|
201
|
+
reason: "Encountered an error while transforming files",
|
202
|
+
changes: results.changes
|
203
|
+
});
|
204
|
+
}
|
205
|
+
return results;
|
206
|
+
}
|
207
|
+
static logResults(results) {
|
208
|
+
const changedFiles = Object.keys(results.changes);
|
209
|
+
console.log();
|
210
|
+
if (changedFiles.length > 0) {
|
211
|
+
console.log(import_chalk3.default.bold(`Results:`));
|
212
|
+
const table = {};
|
213
|
+
changedFiles.forEach((fileName) => {
|
214
|
+
var _a;
|
215
|
+
const fileChanges = results.changes[fileName];
|
216
|
+
table[fileName] = {
|
217
|
+
action: fileChanges.action,
|
218
|
+
additions: fileChanges.additions,
|
219
|
+
deletions: fileChanges.deletions,
|
220
|
+
error: ((_a = fileChanges.error) == null ? void 0 : _a.message) || "None"
|
221
|
+
};
|
222
|
+
});
|
223
|
+
console.table(table);
|
224
|
+
console.log();
|
225
|
+
}
|
226
|
+
}
|
227
|
+
};
|
228
|
+
var Runner_default = Runner;
|
229
|
+
|
230
|
+
// src/utils/getTransformerHelpers.ts
|
231
|
+
function getTransformerHelpers({
|
232
|
+
transformer: transformer2,
|
233
|
+
rootPath,
|
234
|
+
options
|
235
|
+
}) {
|
236
|
+
const utilArgs = {
|
237
|
+
transformer: transformer2,
|
238
|
+
rootPath,
|
239
|
+
...options
|
240
|
+
};
|
241
|
+
const log = new Logger(utilArgs);
|
242
|
+
const runner = new Runner_default(utilArgs);
|
243
|
+
return { log, runner };
|
42
244
|
}
|
43
245
|
|
44
246
|
// src/transforms/set-default-outputs.ts
|
45
|
-
var import_chalk2 = __toESM(require("chalk"));
|
46
247
|
var DEFAULT_OUTPUTS = ["dist/**", "build/**"];
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
248
|
+
var TRANSFORMER = "set-default-outputs";
|
249
|
+
var DESCRIPTION = 'Add the "outputs" key with defaults where it is missing in `turbo.json`';
|
250
|
+
var INTRODUCED_IN = "1.7.0";
|
251
|
+
function transformer({
|
252
|
+
root,
|
253
|
+
options
|
254
|
+
}) {
|
255
|
+
const { log, runner } = getTransformerHelpers({
|
256
|
+
transformer: TRANSFORMER,
|
257
|
+
rootPath: root,
|
258
|
+
options
|
259
|
+
});
|
260
|
+
const packageJsonPath = import_path2.default.join(root, "package.json");
|
54
261
|
let packageJSON = {};
|
55
262
|
try {
|
56
|
-
packageJSON =
|
263
|
+
packageJSON = import_fs_extra2.default.readJSONSync(packageJsonPath);
|
57
264
|
} catch (e) {
|
58
265
|
}
|
59
266
|
if ("turbo" in packageJSON) {
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
if
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
for (const [
|
267
|
+
return runner.abortTransform({
|
268
|
+
reason: '"turbo" key detected in package.json. Run `npx @turbo/codemod transform create-turbo-config` first'
|
269
|
+
});
|
270
|
+
}
|
271
|
+
log.info(`Adding default \`outputs\` key into tasks if it doesn't exist`);
|
272
|
+
const turboConfigPath = import_path2.default.join(root, "turbo.json");
|
273
|
+
if (!import_fs_extra2.default.existsSync(turboConfigPath)) {
|
274
|
+
return runner.abortTransform({
|
275
|
+
reason: `No turbo.json found at ${root}. Is the path correct?`
|
276
|
+
});
|
277
|
+
}
|
278
|
+
const turboJson = import_fs_extra2.default.readJsonSync(turboConfigPath);
|
279
|
+
for (const [_, taskDef] of Object.entries(turboJson.pipeline)) {
|
73
280
|
if (!taskDef.outputs) {
|
74
|
-
|
75
|
-
if (flags.dry) {
|
76
|
-
skippedCount++;
|
77
|
-
} else {
|
78
|
-
taskDef.outputs = DEFAULT_OUTPUTS;
|
79
|
-
modifiedCount++;
|
80
|
-
}
|
281
|
+
taskDef.outputs = DEFAULT_OUTPUTS;
|
81
282
|
} else if (Array.isArray(taskDef.outputs) && taskDef.outputs.length === 0) {
|
82
|
-
|
83
|
-
if (flags.dry) {
|
84
|
-
skippedCount++;
|
85
|
-
} else {
|
86
|
-
delete taskDef.outputs;
|
87
|
-
modifiedCount++;
|
88
|
-
}
|
89
|
-
} else {
|
90
|
-
unmodifiedCount++;
|
91
|
-
skip(`Skipping "${taskName}", it already has an outputs key defined`);
|
283
|
+
delete taskDef.outputs;
|
92
284
|
}
|
93
285
|
}
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
});
|
100
|
-
}
|
101
|
-
console.log("All done.");
|
102
|
-
console.log("Results:");
|
103
|
-
console.log(import_chalk2.default.red(`0 errors`));
|
104
|
-
console.log(import_chalk2.default.yellow(`${skippedCount} skipped`));
|
105
|
-
console.log(import_chalk2.default.yellow(`${unmodifiedCount} unmodified`));
|
106
|
-
console.log(import_chalk2.default.green(`${modifiedCount} modified`));
|
286
|
+
runner.modifyFile({
|
287
|
+
filePath: turboConfigPath,
|
288
|
+
after: turboJson
|
289
|
+
});
|
290
|
+
return runner.finish();
|
107
291
|
}
|
292
|
+
var transformerMeta = {
|
293
|
+
name: `${TRANSFORMER}: ${DESCRIPTION}`,
|
294
|
+
value: TRANSFORMER,
|
295
|
+
introducedIn: INTRODUCED_IN,
|
296
|
+
transformer
|
297
|
+
};
|
298
|
+
var set_default_outputs_default = transformerMeta;
|
108
299
|
// Annotate the CommonJS export names for ESM import in node:
|
109
|
-
0 && (module.exports = {
|
300
|
+
0 && (module.exports = {
|
301
|
+
transformer
|
302
|
+
});
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@turbo/codemod",
|
3
|
-
"version": "1.7.1-canary.
|
3
|
+
"version": "1.7.1-canary.2",
|
4
4
|
"description": "Provides Codemod transformations to help upgrade your Turborepo codebase when a feature is deprecated.",
|
5
5
|
"homepage": "https://turbo.build/repo",
|
6
6
|
"license": "MPL-2.0",
|
@@ -17,41 +17,46 @@
|
|
17
17
|
"build": "tsup",
|
18
18
|
"test": "jest",
|
19
19
|
"lint": "eslint src/**/*.ts",
|
20
|
-
"check-types": "tsc --noEmit"
|
20
|
+
"check-types": "tsc --noEmit",
|
21
|
+
"add-transformer": "plop"
|
21
22
|
},
|
22
23
|
"dependencies": {
|
24
|
+
"axios": "0.27.2",
|
23
25
|
"chalk": "2.4.2",
|
24
|
-
"
|
26
|
+
"commander": "^9.5.0",
|
27
|
+
"diff": "^5.1.0",
|
25
28
|
"find-up": "4.1.0",
|
26
29
|
"fs-extra": "^10.0.0",
|
27
|
-
"globby": "11.1.0",
|
28
30
|
"gradient-string": "^2.0.0",
|
29
|
-
"inquirer": "^8.
|
31
|
+
"inquirer": "^8.2.4",
|
32
|
+
"inquirer-file-tree-selection-prompt": "^1.0.19",
|
30
33
|
"is-git-clean": "^1.1.0",
|
31
|
-
"meow": "^7.1.1",
|
32
34
|
"ora": "4.1.1",
|
33
|
-
"
|
34
|
-
"
|
35
|
+
"semver": "^7.3.7",
|
36
|
+
"turbo-utils": "workspace:*",
|
35
37
|
"update-check": "^1.5.4"
|
36
38
|
},
|
37
39
|
"devDependencies": {
|
38
40
|
"@types/chalk-animation": "^1.6.0",
|
41
|
+
"@types/diff": "^5.0.2",
|
39
42
|
"@types/fs-extra": "^9.0.13",
|
40
43
|
"@types/gradient-string": "^1.1.2",
|
41
|
-
"@types/inquirer": "^
|
44
|
+
"@types/inquirer": "^8.2.0",
|
42
45
|
"@types/jest": "^27.4.0",
|
43
46
|
"@types/node": "^16.11.12",
|
44
47
|
"@types/semver": "^7.3.9",
|
48
|
+
"@types/uuid": "^9.0.0",
|
45
49
|
"deepmerge": "^4.2.2",
|
46
50
|
"eslint": "^7.23.0",
|
47
51
|
"jest": "^27.4.3",
|
52
|
+
"plop": "^3.1.1",
|
48
53
|
"semver": "^7.3.5",
|
49
|
-
"strip-ansi": "^6.0.1",
|
50
54
|
"ts-jest": "^27.1.1",
|
51
55
|
"tsconfig": "workspace:*",
|
52
56
|
"tsup": "^5.10.3",
|
53
57
|
"turbo-types": "workspace:*",
|
54
|
-
"typescript": "^4.5.5"
|
58
|
+
"typescript": "^4.5.5",
|
59
|
+
"uuid": "^9.0.0"
|
55
60
|
},
|
56
61
|
"files": [
|
57
62
|
"dist"
|
@@ -1,42 +0,0 @@
|
|
1
|
-
"use strict";
|
2
|
-
var __defProp = Object.defineProperty;
|
3
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
4
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
5
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
6
|
-
var __export = (target, all) => {
|
7
|
-
for (var name in all)
|
8
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
9
|
-
};
|
10
|
-
var __copyProps = (to, from, except, desc) => {
|
11
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
12
|
-
for (let key of __getOwnPropNames(from))
|
13
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
14
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
15
|
-
}
|
16
|
-
return to;
|
17
|
-
};
|
18
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
19
|
-
|
20
|
-
// src/getPackageManagerVersion.ts
|
21
|
-
var getPackageManagerVersion_exports = {};
|
22
|
-
__export(getPackageManagerVersion_exports, {
|
23
|
-
getPackageManagerVersion: () => getPackageManagerVersion
|
24
|
-
});
|
25
|
-
module.exports = __toCommonJS(getPackageManagerVersion_exports);
|
26
|
-
var import_child_process = require("child_process");
|
27
|
-
var getPackageManagerVersion = (ws) => {
|
28
|
-
switch (ws) {
|
29
|
-
case "yarn":
|
30
|
-
return (0, import_child_process.execSync)("yarn --version").toString().trim();
|
31
|
-
case "pnpm":
|
32
|
-
return (0, import_child_process.execSync)("pnpm --version").toString().trim();
|
33
|
-
case "npm":
|
34
|
-
return (0, import_child_process.execSync)("npm --version").toString().trim();
|
35
|
-
default:
|
36
|
-
throw new Error(`${ws} is not supported`);
|
37
|
-
}
|
38
|
-
};
|
39
|
-
// Annotate the CommonJS export names for ESM import in node:
|
40
|
-
0 && (module.exports = {
|
41
|
-
getPackageManagerVersion
|
42
|
-
});
|
@@ -1,73 +0,0 @@
|
|
1
|
-
"use strict";
|
2
|
-
var __create = Object.create;
|
3
|
-
var __defProp = Object.defineProperty;
|
4
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
5
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
6
|
-
var __getProtoOf = Object.getPrototypeOf;
|
7
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
8
|
-
var __export = (target, all) => {
|
9
|
-
for (var name in all)
|
10
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
11
|
-
};
|
12
|
-
var __copyProps = (to, from, except, desc) => {
|
13
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
14
|
-
for (let key of __getOwnPropNames(from))
|
15
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
16
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
17
|
-
}
|
18
|
-
return to;
|
19
|
-
};
|
20
|
-
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target, mod));
|
21
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
22
|
-
|
23
|
-
// src/getWorkspaceImplementation.ts
|
24
|
-
var getWorkspaceImplementation_exports = {};
|
25
|
-
__export(getWorkspaceImplementation_exports, {
|
26
|
-
getWorkspaceImplementation: () => getWorkspaceImplementation,
|
27
|
-
getWorkspaceImplementationAndLockFile: () => getWorkspaceImplementationAndLockFile
|
28
|
-
});
|
29
|
-
module.exports = __toCommonJS(getWorkspaceImplementation_exports);
|
30
|
-
var import_find_up = __toESM(require("find-up"));
|
31
|
-
var import_path = __toESM(require("path"));
|
32
|
-
var cache = {};
|
33
|
-
function getWorkspaceImplementationAndLockFile(cwd) {
|
34
|
-
if (cache[cwd]) {
|
35
|
-
return cache[cwd];
|
36
|
-
}
|
37
|
-
const lockFile = import_find_up.default.sync(["yarn.lock", "pnpm-workspace.yaml", "package-lock.json"], {
|
38
|
-
cwd
|
39
|
-
});
|
40
|
-
if (!lockFile) {
|
41
|
-
return;
|
42
|
-
}
|
43
|
-
switch (import_path.default.basename(lockFile)) {
|
44
|
-
case "yarn.lock":
|
45
|
-
cache[cwd] = {
|
46
|
-
implementation: "yarn",
|
47
|
-
lockFile
|
48
|
-
};
|
49
|
-
break;
|
50
|
-
case "pnpm-workspace.yaml":
|
51
|
-
cache[cwd] = {
|
52
|
-
implementation: "pnpm",
|
53
|
-
lockFile
|
54
|
-
};
|
55
|
-
break;
|
56
|
-
case "package-lock.json":
|
57
|
-
cache[cwd] = {
|
58
|
-
implementation: "npm",
|
59
|
-
lockFile
|
60
|
-
};
|
61
|
-
break;
|
62
|
-
}
|
63
|
-
return cache[cwd];
|
64
|
-
}
|
65
|
-
function getWorkspaceImplementation(cwd) {
|
66
|
-
var _a;
|
67
|
-
return (_a = getWorkspaceImplementationAndLockFile(cwd)) == null ? void 0 : _a.implementation;
|
68
|
-
}
|
69
|
-
// Annotate the CommonJS export names for ESM import in node:
|
70
|
-
0 && (module.exports = {
|
71
|
-
getWorkspaceImplementation,
|
72
|
-
getWorkspaceImplementationAndLockFile
|
73
|
-
});
|
package/dist/git.js
DELETED
@@ -1,56 +0,0 @@
|
|
1
|
-
"use strict";
|
2
|
-
var __create = Object.create;
|
3
|
-
var __defProp = Object.defineProperty;
|
4
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
5
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
6
|
-
var __getProtoOf = Object.getPrototypeOf;
|
7
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
8
|
-
var __export = (target, all) => {
|
9
|
-
for (var name in all)
|
10
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
11
|
-
};
|
12
|
-
var __copyProps = (to, from, except, desc) => {
|
13
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
14
|
-
for (let key of __getOwnPropNames(from))
|
15
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
16
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
17
|
-
}
|
18
|
-
return to;
|
19
|
-
};
|
20
|
-
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target, mod));
|
21
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
22
|
-
|
23
|
-
// src/git.ts
|
24
|
-
var git_exports = {};
|
25
|
-
__export(git_exports, {
|
26
|
-
checkGitStatus: () => checkGitStatus
|
27
|
-
});
|
28
|
-
module.exports = __toCommonJS(git_exports);
|
29
|
-
var import_chalk = __toESM(require("chalk"));
|
30
|
-
var import_is_git_clean = __toESM(require("is-git-clean"));
|
31
|
-
function checkGitStatus(force) {
|
32
|
-
let clean = false;
|
33
|
-
let errorMessage = "Unable to determine if git directory is clean";
|
34
|
-
try {
|
35
|
-
clean = import_is_git_clean.default.sync(process.cwd());
|
36
|
-
errorMessage = "Git directory is not clean";
|
37
|
-
} catch (err) {
|
38
|
-
if (err && err.stderr && err.stderr.indexOf("not a git repository") >= 0) {
|
39
|
-
clean = true;
|
40
|
-
}
|
41
|
-
}
|
42
|
-
if (!clean) {
|
43
|
-
if (force) {
|
44
|
-
console.log(`WARNING: ${errorMessage}. Forcibly continuing...`);
|
45
|
-
} else {
|
46
|
-
console.log("Thank you for using @turbo/codemod!");
|
47
|
-
console.log(import_chalk.default.yellow("\nBut before we continue, please stash or commit your git changes."));
|
48
|
-
console.log("\nYou may use the --force flag to override this safety check.");
|
49
|
-
process.exit(1);
|
50
|
-
}
|
51
|
-
}
|
52
|
-
}
|
53
|
-
// Annotate the CommonJS export names for ESM import in node:
|
54
|
-
0 && (module.exports = {
|
55
|
-
checkGitStatus
|
56
|
-
});
|