@pagopa/dx-cli 0.14.2 → 0.14.4
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/bin/index.js +46 -35
- package/package.json +3 -3
package/bin/index.js
CHANGED
|
@@ -201,7 +201,8 @@ var useAzureAppsvc = {
|
|
|
201
201
|
// src/adapters/codemods/use-pnpm.ts
|
|
202
202
|
import { getLogger as getLogger4 } from "@logtape/logtape";
|
|
203
203
|
import { $ } from "execa";
|
|
204
|
-
import
|
|
204
|
+
import assert from "assert/strict";
|
|
205
|
+
import fs from "fs/promises";
|
|
205
206
|
import { replaceInFile as replaceInFile3 } from "replace-in-file";
|
|
206
207
|
import semver from "semver";
|
|
207
208
|
import YAML4 from "yaml";
|
|
@@ -262,6 +263,17 @@ async function preparePackageJsonForPnpm() {
|
|
|
262
263
|
await fs.writeFile("package.json", JSON.stringify(manifest, null, 2));
|
|
263
264
|
return workspaces;
|
|
264
265
|
}
|
|
266
|
+
async function writePnpmWorkspaceFile(workspaces, packageExtensions) {
|
|
267
|
+
const pnpmWorkspace = {
|
|
268
|
+
cleanupUnusedCatalogs: true,
|
|
269
|
+
linkWorkspacePackages: true,
|
|
270
|
+
packageExtensions,
|
|
271
|
+
packageImportMethod: "clone-or-copy",
|
|
272
|
+
packages: workspaces.length > 0 ? workspaces : ["apps/*", "packages/*"]
|
|
273
|
+
};
|
|
274
|
+
const yamlContent = YAML4.stringify(pnpmWorkspace);
|
|
275
|
+
await fs.writeFile("pnpm-workspace.yaml", yamlContent, "utf-8");
|
|
276
|
+
}
|
|
265
277
|
async function removeFiles(...files) {
|
|
266
278
|
await Promise.all(
|
|
267
279
|
files.map(
|
|
@@ -285,7 +297,7 @@ async function replacePMOccurrences() {
|
|
|
285
297
|
/\b(yarn workspace|npm -(\b-workspace\b|\bw\b))\b/g,
|
|
286
298
|
/\b(yarn install --immutable|npm ci)\b/g,
|
|
287
299
|
/\b(yarn -q dlx|npx)\b/g,
|
|
288
|
-
|
|
300
|
+
/(^|\s)(Yarn|npm)(?!\S)/gi
|
|
289
301
|
],
|
|
290
302
|
ignore: ["**/node_modules/**", "**/dist/**", "**/build/**"],
|
|
291
303
|
to: [
|
|
@@ -321,33 +333,20 @@ async function updateDXWorkflows() {
|
|
|
321
333
|
processor: migrateWorkflow(sha)
|
|
322
334
|
});
|
|
323
335
|
}
|
|
324
|
-
async
|
|
325
|
-
const pnpmWorkspace = {
|
|
326
|
-
packageExtensions,
|
|
327
|
-
packages: workspaces.length > 0 ? workspaces : ["apps/*", "packages/*"]
|
|
328
|
-
};
|
|
329
|
-
const yamlContent = YAML4.stringify(pnpmWorkspace);
|
|
330
|
-
await fs.writeFile("pnpm-workspace.yaml", yamlContent, "utf-8");
|
|
331
|
-
}
|
|
332
|
-
var apply = async (info) => {
|
|
336
|
+
var usePnpm = async (packageManager, currentNodeVersion) => {
|
|
333
337
|
const minNodeVersion = "20.19.5";
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
process.exit(1);
|
|
340
|
-
}
|
|
341
|
-
if (info.packageManager === "pnpm") {
|
|
342
|
-
throw new Error("Project is already using pnpm");
|
|
343
|
-
}
|
|
344
|
-
const pm = info.packageManager === "yarn" ? new Yarn() : new NPM();
|
|
338
|
+
assert.notEqual(packageManager, "pnpm", "Project is already using pnpm");
|
|
339
|
+
assert.ok(
|
|
340
|
+
semver.gte(currentNodeVersion, minNodeVersion),
|
|
341
|
+
`his codemod requires Node.js >= ${minNodeVersion}. Current version: ${currentNodeVersion}`
|
|
342
|
+
);
|
|
345
343
|
const logger = getLogger4(["dx-cli", "codemod"]);
|
|
344
|
+
const pm = packageManager === "yarn" ? new Yarn() : new NPM();
|
|
346
345
|
const localWorkspaces = await pm.listWorkspaces();
|
|
347
|
-
logger.info("Using the {protocol} protocol for local dependencies", {
|
|
348
|
-
protocol: "workspace:"
|
|
349
|
-
});
|
|
350
346
|
if (localWorkspaces.length > 0) {
|
|
347
|
+
logger.info("Using the {protocol} protocol for local dependencies", {
|
|
348
|
+
protocol: "workspace:"
|
|
349
|
+
});
|
|
351
350
|
await replaceInFile3({
|
|
352
351
|
allowEmptyPaths: true,
|
|
353
352
|
files: ["**/package.json"],
|
|
@@ -359,12 +358,11 @@ var apply = async (info) => {
|
|
|
359
358
|
file: "package.json"
|
|
360
359
|
});
|
|
361
360
|
const workspaces = await preparePackageJsonForPnpm();
|
|
362
|
-
const packageExtensions =
|
|
361
|
+
const packageExtensions = packageManager === "yarn" ? await extractPackageExtensions() : void 0;
|
|
363
362
|
logger.info("Create {file}", {
|
|
364
363
|
file: "pnpm-workspace.yaml"
|
|
365
364
|
});
|
|
366
365
|
await writePnpmWorkspaceFile(workspaces, packageExtensions);
|
|
367
|
-
await $`corepack pnpm@latest add --config pnpm-plugin-pagopa`;
|
|
368
366
|
logger.info("Remove node_modules and yarn files");
|
|
369
367
|
await removeFiles(
|
|
370
368
|
".yarnrc",
|
|
@@ -375,8 +373,8 @@ var apply = async (info) => {
|
|
|
375
373
|
".pnp.loader.cjs",
|
|
376
374
|
"node_modules"
|
|
377
375
|
);
|
|
378
|
-
const
|
|
379
|
-
if (
|
|
376
|
+
const stat = await fs.stat(pm.lockFileName);
|
|
377
|
+
if (stat.isFile()) {
|
|
380
378
|
logger.info("Importing {source} to {target}", {
|
|
381
379
|
source: pm.lockFileName,
|
|
382
380
|
target: "pnpm-lock.yaml"
|
|
@@ -395,6 +393,16 @@ var apply = async (info) => {
|
|
|
395
393
|
logger.info("Setting pnpm as the package manager...");
|
|
396
394
|
await $`corepack use pnpm@latest`;
|
|
397
395
|
};
|
|
396
|
+
var apply = async (info) => {
|
|
397
|
+
const logger = getLogger4(["dx-cli", "codemod"]);
|
|
398
|
+
try {
|
|
399
|
+
await usePnpm(info.packageManager, process.versions.node);
|
|
400
|
+
} catch (error) {
|
|
401
|
+
if (error instanceof Error) {
|
|
402
|
+
logger.error(error.message);
|
|
403
|
+
}
|
|
404
|
+
}
|
|
405
|
+
};
|
|
398
406
|
var use_pnpm_default = {
|
|
399
407
|
apply,
|
|
400
408
|
description: "Migrate the project to use pnpm as the package manager",
|
|
@@ -814,7 +822,10 @@ var withSpinner = (text, successText, failText, promise) => ResultAsync6.fromPro
|
|
|
814
822
|
successText,
|
|
815
823
|
text
|
|
816
824
|
}),
|
|
817
|
-
(cause) =>
|
|
825
|
+
(cause) => {
|
|
826
|
+
console.error(`Something went wrong: ${JSON.stringify(cause, null, 2)}`);
|
|
827
|
+
return new Error(failText, { cause });
|
|
828
|
+
}
|
|
818
829
|
);
|
|
819
830
|
var validateAnswers = (answers) => okAsync2(answers);
|
|
820
831
|
var runGeneratorActions = (generator) => (answers) => withSpinner(
|
|
@@ -993,7 +1004,7 @@ var makeSavemoneyCommand = () => new Command5("savemoney").description(
|
|
|
993
1004
|
// src/adapters/commander/index.ts
|
|
994
1005
|
var makeCli = (deps2, config2, cliDeps) => {
|
|
995
1006
|
const program2 = new Command6();
|
|
996
|
-
program2.name("dx").description("The CLI for DX-Platform").version("0.14.
|
|
1007
|
+
program2.name("dx").description("The CLI for DX-Platform").version("0.14.4");
|
|
997
1008
|
program2.addCommand(makeDoctorCommand(deps2, config2));
|
|
998
1009
|
program2.addCommand(makeCodemodCommand(cliDeps));
|
|
999
1010
|
program2.addCommand(makeInitCommand(deps2));
|
|
@@ -1036,11 +1047,11 @@ var parseJson = Result2.fromThrowable(
|
|
|
1036
1047
|
);
|
|
1037
1048
|
|
|
1038
1049
|
// src/adapters/node/fs/file-reader.ts
|
|
1039
|
-
var
|
|
1050
|
+
var readFile = (filePath) => ResultAsync7.fromPromise(
|
|
1040
1051
|
fs3.readFile(filePath, "utf-8"),
|
|
1041
1052
|
(cause) => new Error(`Failed to read file: ${filePath}`, { cause })
|
|
1042
1053
|
);
|
|
1043
|
-
var readFileAndDecode = (filePath, schema) =>
|
|
1054
|
+
var readFileAndDecode = (filePath, schema) => readFile(filePath).andThen(parseJson).andThen(decode(schema));
|
|
1044
1055
|
var fileExists = (path3) => ResultAsync7.fromPromise(
|
|
1045
1056
|
fs3.stat(path3),
|
|
1046
1057
|
() => new Error(`${path3} not found.`)
|
|
@@ -1106,7 +1117,7 @@ var resolveWorkspacePattern = (repoRoot, pattern) => ResultAsync8.fromPromise(
|
|
|
1106
1117
|
subDirectories.map((directory) => path2.join(repoRoot, directory))
|
|
1107
1118
|
)
|
|
1108
1119
|
);
|
|
1109
|
-
var getWorkspaces = (repoRoot) =>
|
|
1120
|
+
var getWorkspaces = (repoRoot) => readFile(path2.join(repoRoot, "pnpm-workspace.yaml")).andThen(parseYaml).andThen(
|
|
1110
1121
|
(obj) => (
|
|
1111
1122
|
// If no packages are defined, go on with an empty array
|
|
1112
1123
|
decode(z3.object({ packages: z3.array(z3.string()) }))(obj).orElse(
|
|
@@ -1138,7 +1149,7 @@ var makeRepositoryReader = () => ({
|
|
|
1138
1149
|
fileExists,
|
|
1139
1150
|
findRepositoryRoot,
|
|
1140
1151
|
getWorkspaces,
|
|
1141
|
-
readFile
|
|
1152
|
+
readFile
|
|
1142
1153
|
});
|
|
1143
1154
|
|
|
1144
1155
|
// src/config.ts
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@pagopa/dx-cli",
|
|
3
|
-
"version": "0.14.
|
|
3
|
+
"version": "0.14.4",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "A CLI useful to manage DX tools.",
|
|
6
6
|
"repository": {
|
|
@@ -33,8 +33,8 @@
|
|
|
33
33
|
"semver": "^7.7.2",
|
|
34
34
|
"yaml": "^2.8.2",
|
|
35
35
|
"zod": "^4.2.1",
|
|
36
|
-
"@pagopa/
|
|
37
|
-
"@pagopa/
|
|
36
|
+
"@pagopa/monorepo-generator": "^0.14.1",
|
|
37
|
+
"@pagopa/dx-savemoney": "^0.1.4"
|
|
38
38
|
},
|
|
39
39
|
"devDependencies": {
|
|
40
40
|
"@tsconfig/node22": "22.0.2",
|