@pagopa/dx-cli 0.7.0 → 0.8.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.
Files changed (2) hide show
  1. package/bin/index.js +88 -27
  2. package/package.json +2 -2
package/bin/index.js CHANGED
@@ -113,6 +113,11 @@ var migrateWorkflow = (sha) => (workflow, filename) => {
113
113
  )) {
114
114
  logger2.debug("Adding disable_auto_staging_deploy");
115
115
  map.addIn(["with", "disable_auto_staging_deploy"], true);
116
+ map.set("permissions", {
117
+ attestations: "write",
118
+ contents: "read",
119
+ "id-token": "write"
120
+ });
116
121
  updated = true;
117
122
  return void 0;
118
123
  }
@@ -170,6 +175,47 @@ import { $ } from "execa";
170
175
  import * as fs from "fs/promises";
171
176
  import { replaceInFile as replaceInFile3 } from "replace-in-file";
172
177
  import YAML2 from "yaml";
178
+ var NPM = class {
179
+ lockFileName = "package-lock.json";
180
+ async listWorkspaces() {
181
+ const { stdout } = await $`npm query .workspace`;
182
+ const workspaces = JSON.parse(stdout);
183
+ const workspaceNames = [];
184
+ if (Array.isArray(workspaces)) {
185
+ for (const ws of workspaces) {
186
+ if (Object.hasOwn(ws, "name")) {
187
+ workspaceNames.push(ws.name);
188
+ }
189
+ }
190
+ }
191
+ return workspaceNames;
192
+ }
193
+ };
194
+ var Yarn = class {
195
+ lockFileName = "yarn.lock";
196
+ async listWorkspaces() {
197
+ const { stdout } = await $({ lines: true })`yarn workspaces list --json`;
198
+ const workspaceNames = [];
199
+ for (const line of stdout) {
200
+ const ws = JSON.parse(line);
201
+ if (Object.hasOwn(ws, "name")) {
202
+ workspaceNames.push(ws.name);
203
+ }
204
+ }
205
+ return workspaceNames;
206
+ }
207
+ };
208
+ async function extractPackageExtensions() {
209
+ try {
210
+ const yarnrc = await fs.readFile(".yarnrc.yml", "utf-8");
211
+ const parsed = YAML2.parse(yarnrc);
212
+ if (parsed.packageExtensions) {
213
+ return parsed.packageExtensions;
214
+ }
215
+ } catch {
216
+ }
217
+ return void 0;
218
+ }
173
219
  async function preparePackageJsonForPnpm() {
174
220
  const packageJson2 = await fs.readFile("package.json", "utf-8");
175
221
  const manifest = JSON.parse(packageJson2);
@@ -196,20 +242,20 @@ async function removeFiles(...files) {
196
242
  )
197
243
  );
198
244
  }
199
- async function replaceYarnOccurrences() {
245
+ async function replacePMOccurrences() {
200
246
  const logger2 = getLogger4(["dx-cli", "codemod"]);
201
- logger2.info("Replacing yarn occurrences in files...");
247
+ logger2.info("Replacing yarn and npm occurrences in files...");
202
248
  const results = await replaceInFile3({
203
249
  allowEmptyPaths: true,
204
250
  files: ["**/*.json", "**/*.md", "**/Dockerfile", "**/docker-compose.yml"],
205
251
  from: [
206
252
  "https://yarnpkg.com/",
207
253
  "https://classic.yarnpkg.com/",
208
- /yarn workspace (\S+)/g,
209
- /yarn workspace/g,
210
- /yarn install --immutable/g,
211
- /yarn -q dlx/g,
212
- /Yarn/gi
254
+ /\b(yarn workspace|npm -(\b-workspace\b|\bw\b)) (\S+)\b/g,
255
+ /\b(yarn workspace|npm -(\b-workspace\b|\bw\b)) /g,
256
+ /\b(yarn install --immutable|npm ci)\b/g,
257
+ /\b(yarn -q dlx|npx)\b/g,
258
+ /\b(Yarn|npm)\b/gi
213
259
  ],
214
260
  ignore: ["**/node_modules/**", "**/dist/**", "**/build/**"],
215
261
  to: [
@@ -240,8 +286,9 @@ async function updateDXWorkflows() {
240
286
  processor: migrateWorkflow(sha)
241
287
  });
242
288
  }
243
- async function writePnpmWorkspaceFile(workspaces) {
289
+ async function writePnpmWorkspaceFile(workspaces, packageExtensions) {
244
290
  const pnpmWorkspace = {
291
+ packageExtensions,
245
292
  packages: workspaces.length > 0 ? workspaces : ["apps/*", "packages/*"]
246
293
  };
247
294
  const yamlContent = YAML2.stringify(pnpmWorkspace);
@@ -251,15 +298,30 @@ var apply = async (info) => {
251
298
  if (info.packageManager === "pnpm") {
252
299
  throw new Error("Project is already using pnpm");
253
300
  }
301
+ const pm = info.packageManager === "yarn" ? new Yarn() : new NPM();
254
302
  const logger2 = getLogger4(["dx-cli", "codemod"]);
303
+ const localWorkspaces = await pm.listWorkspaces();
304
+ logger2.info("Using the {protocol} protocol for local dependencies", {
305
+ protocol: "workspace:"
306
+ });
307
+ if (localWorkspaces.length > 0) {
308
+ await replaceInFile3({
309
+ allowEmptyPaths: true,
310
+ files: ["**/package.json"],
311
+ from: localWorkspaces.map((ws) => new RegExp(`"${ws}": ".*?"`, "g")),
312
+ to: localWorkspaces.map((ws) => `"${ws}": "workspace:^"`)
313
+ });
314
+ }
255
315
  logger2.info("Remove unused fields from {file}", {
256
316
  file: "package.json"
257
317
  });
258
318
  const workspaces = await preparePackageJsonForPnpm();
319
+ const packageExtensions = info.packageManager === "yarn" ? await extractPackageExtensions() : void 0;
259
320
  logger2.info("Create {file}", {
260
321
  file: "pnpm-workspace.yaml"
261
322
  });
262
- await writePnpmWorkspaceFile(workspaces);
323
+ await writePnpmWorkspaceFile(workspaces, packageExtensions);
324
+ await $`corepack pnpm@latest add --config pnpm-plugin-pagopa`;
263
325
  logger2.info("Remove node_modules and yarn files");
264
326
  await removeFiles(
265
327
  ".yarnrc",
@@ -270,26 +332,27 @@ var apply = async (info) => {
270
332
  ".pnp.loader.cjs",
271
333
  "node_modules"
272
334
  );
273
- logger2.info("Importing {source} to {target}", {
274
- source: "yarn.lock",
275
- target: "pnpm-lock.yaml"
276
- });
277
- try {
278
- await fs.access("yarn.lock");
279
- await $`corepack pnpm@latest import yarn.lock`;
280
- await removeFiles("yarn.lock");
281
- } catch {
282
- logger2.info("No yarn.lock file found, skipping import.");
335
+ const stat2 = await fs.stat(pm.lockFileName);
336
+ if (stat2.isFile()) {
337
+ logger2.info("Importing {source} to {target}", {
338
+ source: pm.lockFileName,
339
+ target: "pnpm-lock.yaml"
340
+ });
341
+ await $`corepack pnpm@latest import ${pm.lockFileName}`;
342
+ await removeFiles(pm.lockFileName);
343
+ } else {
344
+ logger2.info("No {source} file found, skipping import.", {
345
+ source: pm.lockFileName
346
+ });
283
347
  }
284
- await $`corepack pnpm@latest add --config pnpm-plugin-pagopa`;
285
- await replaceYarnOccurrences();
348
+ await replacePMOccurrences();
286
349
  await updateDXWorkflows();
287
350
  logger2.info("Setting pnpm as the package manager...");
288
351
  await $`corepack use pnpm@latest`;
289
352
  };
290
353
  var use_pnpm_default = {
291
354
  apply,
292
- description: "A codemod that switches the project to use pnpm",
355
+ description: "Migrate the project to use pnpm as the package manager",
293
356
  id: "use-pnpm"
294
357
  };
295
358
 
@@ -665,7 +728,7 @@ import { Command as Command5 } from "commander";
665
728
  import { getLogger as getLogger7 } from "@logtape/logtape";
666
729
  function printVersion() {
667
730
  const logger2 = getLogger7(["dx-cli", "version"]);
668
- logger2.info(`dx CLI version: ${"0.7.0"}`);
731
+ logger2.info(`dx CLI version: ${"0.8.0"}`);
669
732
  }
670
733
 
671
734
  // src/adapters/commander/commands/version.ts
@@ -674,11 +737,9 @@ var makeVersionCommand = () => new Command5().name("version").alias("v").action(
674
737
  // src/adapters/commander/index.ts
675
738
  var makeCli = (deps2, config2, cliDeps) => {
676
739
  const program2 = new Command6();
677
- program2.name("dx").description("The CLI for DX-Platform").version("0.7.0");
740
+ program2.name("dx").description("The CLI for DX-Platform").version("0.8.0");
678
741
  program2.addCommand(makeDoctorCommand(deps2, config2));
679
- if (process.env.ENABLE_CODEMODS) {
680
- program2.addCommand(makeCodemodCommand(cliDeps));
681
- }
742
+ program2.addCommand(makeCodemodCommand(cliDeps));
682
743
  if (process.env.ENABLE_INIT_COMMAND) {
683
744
  program2.addCommand(makeInitCommand());
684
745
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pagopa/dx-cli",
3
- "version": "0.7.0",
3
+ "version": "0.8.0",
4
4
  "type": "module",
5
5
  "description": "A CLI useful to manage DX tools.",
6
6
  "repository": {
@@ -31,7 +31,7 @@
31
31
  "semver": "^7.7.2",
32
32
  "yaml": "^2.8.0",
33
33
  "zod": "^3.25.28",
34
- "@pagopa/monorepo-generator": "^0.6.0"
34
+ "@pagopa/monorepo-generator": "^0.8.0"
35
35
  },
36
36
  "devDependencies": {
37
37
  "@tsconfig/node22": "22.0.2",