pnpm-settings-migrator 0.6.0 → 0.6.1

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/cli.mjs CHANGED
@@ -1,6 +1,6 @@
1
1
  import process from "node:process";
2
2
  import { cac } from "cac";
3
- import consola, { consola as consola$1 } from "consola";
3
+ import consola$1, { consola } from "consola";
4
4
  import { isPlainObject, isUndefined, pick } from "@ntnyq/utils";
5
5
  import { defu } from "defu";
6
6
  import detectIndent from "detect-indent";
@@ -13,7 +13,7 @@ import { readIniFile } from "read-ini-file";
13
13
  import { kebabCase } from "uncase";
14
14
  //#region package.json
15
15
  var name = "pnpm-settings-migrator";
16
- var version = "0.6.0";
16
+ var version = "0.6.1";
17
17
  //#endregion
18
18
  //#region src/constants.ts
19
19
  const NPMRC = ".npmrc";
@@ -309,7 +309,7 @@ function mergeWithArrayDedupe(existing, incoming) {
309
309
  for (const [key, incomingValue] of Object.entries(incoming)) {
310
310
  const existingValue = result[key];
311
311
  if (isUndefined(existingValue)) result[key] = incomingValue;
312
- else if (Array.isArray(existingValue) && Array.isArray(incomingValue)) result[key] = Array.from(new Set([...existingValue, ...incomingValue]));
312
+ else if (Array.isArray(existingValue) && Array.isArray(incomingValue)) result[key] = Array.from(/* @__PURE__ */ new Set([...existingValue, ...incomingValue]));
313
313
  else if (isPlainObject(existingValue) && isPlainObject(incomingValue)) result[key] = mergeWithArrayDedupe(existingValue, incomingValue);
314
314
  }
315
315
  return result;
@@ -477,10 +477,10 @@ async function migratePnpmSettings(rawOptions = {}) {
477
477
  fsExists(packageJsonPath),
478
478
  fsExists(pnpmWorkspaceYamlPath)
479
479
  ]);
480
- if (!npmrcExists) consola.info(`${dim(NPMRC)} not found`);
481
- if (!packageJsonExists) consola.info(`${dim(PACKAGE_JSON)} not found`);
480
+ if (!npmrcExists) consola$1.info(`${dim(NPMRC)} not found`);
481
+ if (!packageJsonExists) consola$1.info(`${dim(PACKAGE_JSON)} not found`);
482
482
  if (!npmrcExists && !packageJsonExists) {
483
- consola.warn("No pnpm settings files to migrate");
483
+ consola$1.warn("No pnpm settings files to migrate");
484
484
  return;
485
485
  }
486
486
  let packageJsonIndent = 2;
@@ -494,8 +494,8 @@ async function migratePnpmSettings(rawOptions = {}) {
494
494
  }
495
495
  if (pnpmWorkspaceExists) {
496
496
  const content = await fsReadFile(pnpmWorkspaceYamlPath);
497
- pnpmWorkspaceYamlIndent = detectIndent(content).amount;
498
- pnpmWorkspaceYamlObject = parse(content);
497
+ pnpmWorkspaceYamlIndent = resolveYamlIndent(content);
498
+ pnpmWorkspaceYamlObject = parse(content) ?? {};
499
499
  }
500
500
  const compatibility = resolveCompatibilityTarget(options.compatibility, packageJsonObject.packageManager);
501
501
  const npmrcMigratable = npmrcExists ? compatibility === "v10" ? {
@@ -510,7 +510,7 @@ async function migratePnpmSettings(rawOptions = {}) {
510
510
  const hasResolutions = options.yarnResolutions && !!packageJsonObject.resolutions;
511
511
  const hasNpmrcSettings = Object.keys(pnpmSettingsInNpmrc).length > 0;
512
512
  if (!hasPnpmInPackageJson && !hasResolutions && !hasNpmrcSettings) {
513
- consola.warn("No pnpm settings fields to migrate");
513
+ consola$1.warn("No pnpm settings fields to migrate");
514
514
  return;
515
515
  }
516
516
  const pnpmSettingsInPackageJson = options.yarnResolutions && packageJsonObject.resolutions ? {
@@ -540,7 +540,7 @@ async function migratePnpmSettings(rawOptions = {}) {
540
540
  await fsWriteFile(packageJsonPath, JSON.stringify(packageJsonObject, null, packageJsonIndent));
541
541
  }
542
542
  } catch (err) {
543
- consola.error("Failed to migrate pnpm settings:", err);
543
+ consola$1.error("Failed to migrate pnpm settings:", err);
544
544
  throw err;
545
545
  }
546
546
  }
@@ -575,19 +575,23 @@ function resolveCompatibilityTarget(compatibility, packageManager) {
575
575
  const [, major] = (packageManager || "").match(/^pnpm@(\d+)(?:\.|$)/) || [];
576
576
  return Number(major) >= 11 ? "v11" : "v10";
577
577
  }
578
+ function resolveYamlIndent(content) {
579
+ const detectedIndent = detectIndent(content).amount;
580
+ return detectedIndent > 0 ? detectedIndent : 2;
581
+ }
578
582
  //#endregion
579
583
  //#region src/cli.ts
580
584
  const cli = cac(name);
581
585
  cli.version(version).option("--cwd [cwd]", "Current working directory").option("--sort-keys", "Sort keys when write pnpm-workspace.yaml").option("--compatibility <compatibility>", "Compatibility target (auto, v10, v11)").option("--replace-deprecated", "Replace deprecated pnpm settings with new ones and remove old keys").option("--strategy <strategy>", "Strategy to handle conflicts (discard, merge, overwrite)").option("--no-yarn-resolutions", "Disable migrating resolutions field in package.json").option("--no-newline-between", "Disable adding newlines between each root keys").option("--no-clean-npmrc", "Disable removing pnpm settings in .npmrc file").option("--no-clean-package-json", "Disable removing pnpm fields in package.json").help();
582
586
  cli.command("").action(async (options) => {
583
587
  try {
584
- consola$1.log(`\n${bold(magenta(name))} ${dim(`v${version}`)}`);
585
- consola$1.log(dim("\n--------------\n"));
588
+ consola.log(`\n${bold(magenta(name))} ${dim(`v${version}`)}`);
589
+ consola.log(dim("\n--------------\n"));
586
590
  await migratePnpmSettings(options);
587
- consola$1.success(green("pnpm settings migrate has finished"));
591
+ consola.success(green("pnpm settings migrate has finished"));
588
592
  } catch (err) {
589
- consola$1.fail(red(String(err)));
590
- if (err instanceof Error && err.stack) consola$1.fail(dim(err.stack?.split("\n").slice(1).join("\n")));
593
+ consola.fail(red(String(err)));
594
+ if (err instanceof Error && err.stack) consola.fail(dim(err.stack?.split("\n").slice(1).join("\n")));
591
595
  process.exit(1);
592
596
  }
593
597
  });
package/dist/index.mjs CHANGED
@@ -304,7 +304,7 @@ function mergeWithArrayDedupe(existing, incoming) {
304
304
  for (const [key, incomingValue] of Object.entries(incoming)) {
305
305
  const existingValue = result[key];
306
306
  if (isUndefined(existingValue)) result[key] = incomingValue;
307
- else if (Array.isArray(existingValue) && Array.isArray(incomingValue)) result[key] = Array.from(new Set([...existingValue, ...incomingValue]));
307
+ else if (Array.isArray(existingValue) && Array.isArray(incomingValue)) result[key] = Array.from(/* @__PURE__ */ new Set([...existingValue, ...incomingValue]));
308
308
  else if (isPlainObject(existingValue) && isPlainObject(incomingValue)) result[key] = mergeWithArrayDedupe(existingValue, incomingValue);
309
309
  }
310
310
  return result;
@@ -489,8 +489,8 @@ async function migratePnpmSettings(rawOptions = {}) {
489
489
  }
490
490
  if (pnpmWorkspaceExists) {
491
491
  const content = await fsReadFile(pnpmWorkspaceYamlPath);
492
- pnpmWorkspaceYamlIndent = detectIndent(content).amount;
493
- pnpmWorkspaceYamlObject = parse(content);
492
+ pnpmWorkspaceYamlIndent = resolveYamlIndent(content);
493
+ pnpmWorkspaceYamlObject = parse(content) ?? {};
494
494
  }
495
495
  const compatibility = resolveCompatibilityTarget(options.compatibility, packageJsonObject.packageManager);
496
496
  const npmrcMigratable = npmrcExists ? compatibility === "v10" ? {
@@ -570,5 +570,9 @@ function resolveCompatibilityTarget(compatibility, packageManager) {
570
570
  const [, major] = (packageManager || "").match(/^pnpm@(\d+)(?:\.|$)/) || [];
571
571
  return Number(major) >= 11 ? "v11" : "v10";
572
572
  }
573
+ function resolveYamlIndent(content) {
574
+ const detectedIndent = detectIndent(content).amount;
575
+ return detectedIndent > 0 ? detectedIndent : 2;
576
+ }
573
577
  //#endregion
574
578
  export { migratePnpmSettings, resolveOptions };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "pnpm-settings-migrator",
3
3
  "type": "module",
4
- "version": "0.6.0",
4
+ "version": "0.6.1",
5
5
  "description": "Move pnpm settings from `pnpm` field in `package.json` and `.npmrc` file to `pnpm-workspace.yaml`",
6
6
  "keywords": [
7
7
  "migrator",
@@ -40,7 +40,7 @@
40
40
  "sideEffects": false,
41
41
  "dependencies": {
42
42
  "@ntnyq/utils": "^0.15.0",
43
- "@pnpm/types": "^1101.3.0",
43
+ "@pnpm/types": "^1101.3.2",
44
44
  "cac": "^7.0.0",
45
45
  "camelcase-keys": "^10.0.2",
46
46
  "consola": "^3.4.2",
@@ -53,16 +53,16 @@
53
53
  },
54
54
  "devDependencies": {
55
55
  "@ntnyq/eslint-config": "^6.1.5",
56
- "@types/node": "^25.9.2",
57
- "@typescript/native-preview": "^7.0.0-dev.20260607.1",
56
+ "@types/node": "^26.0.0",
57
+ "@typescript/native-preview": "^7.0.0-dev.20260620.1",
58
58
  "bumpp": "^11.1.0",
59
- "eslint": "^10.4.1",
59
+ "eslint": "^10.5.0",
60
60
  "husky": "^9.1.7",
61
61
  "nano-staged": "^1.0.2",
62
- "npm-run-all2": "^9.0.1",
63
- "oxfmt": "^0.53.0",
64
- "tsdown": "^0.22.2",
65
- "vitest": "^4.1.8"
62
+ "npm-run-all2": "^9.0.2",
63
+ "oxfmt": "^0.55.0",
64
+ "tsdown": "^0.22.3",
65
+ "vitest": "^4.1.9"
66
66
  },
67
67
  "nano-staged": {
68
68
  "*.{js,ts,mjs,tsx,md,yml,yaml,toml,json}": "eslint --fix",