@xylabs/toolchain 7.10.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.
- package/dist/actions/analyze.mjs +140 -0
- package/dist/actions/analyze.mjs.map +1 -0
- package/dist/actions/build.mjs +173 -0
- package/dist/actions/build.mjs.map +1 -0
- package/dist/actions/claude-check.mjs +199 -0
- package/dist/actions/claude-check.mjs.map +1 -0
- package/dist/actions/claude-clean.mjs +70 -0
- package/dist/actions/claude-clean.mjs.map +1 -0
- package/dist/actions/claude-commands.mjs +126 -0
- package/dist/actions/claude-commands.mjs.map +1 -0
- package/dist/actions/claude-rules.mjs +151 -0
- package/dist/actions/claude-rules.mjs.map +1 -0
- package/dist/actions/claude-settings.mjs +99 -0
- package/dist/actions/claude-settings.mjs.map +1 -0
- package/dist/actions/claude-skills.mjs +131 -0
- package/dist/actions/claude-skills.mjs.map +1 -0
- package/dist/actions/clean-docs.mjs +66 -0
- package/dist/actions/clean-docs.mjs.map +1 -0
- package/dist/actions/clean-eslint.mjs +47 -0
- package/dist/actions/clean-eslint.mjs.map +1 -0
- package/dist/actions/clean.mjs +166 -0
- package/dist/actions/clean.mjs.map +1 -0
- package/dist/actions/compile.mjs +184 -0
- package/dist/actions/compile.mjs.map +1 -0
- package/dist/actions/copy-assets.mjs +81 -0
- package/dist/actions/copy-assets.mjs.map +1 -0
- package/dist/actions/cycle.mjs +275 -0
- package/dist/actions/cycle.mjs.map +1 -0
- package/dist/actions/dead.mjs +119 -0
- package/dist/actions/dead.mjs.map +1 -0
- package/dist/actions/deplint/checkPackage/checkPackage.mjs +1556 -0
- package/dist/actions/deplint/checkPackage/checkPackage.mjs.map +1 -0
- package/dist/actions/deplint/checkPackage/checkPackageTypes.mjs +1 -0
- package/dist/actions/deplint/checkPackage/checkPackageTypes.mjs.map +1 -0
- package/dist/actions/deplint/checkPackage/getMismatchedPeerDevVersions.mjs +77 -0
- package/dist/actions/deplint/checkPackage/getMismatchedPeerDevVersions.mjs.map +1 -0
- package/dist/actions/deplint/checkPackage/getUnlistedDependencies.mjs +158 -0
- package/dist/actions/deplint/checkPackage/getUnlistedDependencies.mjs.map +1 -0
- package/dist/actions/deplint/checkPackage/getUnlistedDevDependencies.mjs +125 -0
- package/dist/actions/deplint/checkPackage/getUnlistedDevDependencies.mjs.map +1 -0
- package/dist/actions/deplint/checkPackage/getUnnecessaryPeerDependencies.mjs +207 -0
- package/dist/actions/deplint/checkPackage/getUnnecessaryPeerDependencies.mjs.map +1 -0
- package/dist/actions/deplint/checkPackage/getUnsatisfiedPeerDependencies.mjs +318 -0
- package/dist/actions/deplint/checkPackage/getUnsatisfiedPeerDependencies.mjs.map +1 -0
- package/dist/actions/deplint/checkPackage/getUnusedDependencies.mjs +163 -0
- package/dist/actions/deplint/checkPackage/getUnusedDependencies.mjs.map +1 -0
- package/dist/actions/deplint/checkPackage/getUnusedDevDependencies.mjs +408 -0
- package/dist/actions/deplint/checkPackage/getUnusedDevDependencies.mjs.map +1 -0
- package/dist/actions/deplint/checkPackage/getUnusedPeerDependencies.mjs +75 -0
- package/dist/actions/deplint/checkPackage/getUnusedPeerDependencies.mjs.map +1 -0
- package/dist/actions/deplint/checkPackage/getWorkspaceVersionProblems.mjs +128 -0
- package/dist/actions/deplint/checkPackage/getWorkspaceVersionProblems.mjs.map +1 -0
- package/dist/actions/deplint/checkPackage/index.mjs +1609 -0
- package/dist/actions/deplint/checkPackage/index.mjs.map +1 -0
- package/dist/actions/deplint/deplint.mjs +1840 -0
- package/dist/actions/deplint/deplint.mjs.map +1 -0
- package/dist/actions/deplint/engine.mjs +1736 -0
- package/dist/actions/deplint/engine.mjs.map +1 -0
- package/dist/actions/deplint/findFiles.mjs +39 -0
- package/dist/actions/deplint/findFiles.mjs.map +1 -0
- package/dist/actions/deplint/findFilesByGlob.mjs +14 -0
- package/dist/actions/deplint/findFilesByGlob.mjs.map +1 -0
- package/dist/actions/deplint/fixer.mjs +103 -0
- package/dist/actions/deplint/fixer.mjs.map +1 -0
- package/dist/actions/deplint/getBasePackageName.mjs +13 -0
- package/dist/actions/deplint/getBasePackageName.mjs.map +1 -0
- package/dist/actions/deplint/getCliReferencedPackagesFromFiles.mjs +140 -0
- package/dist/actions/deplint/getCliReferencedPackagesFromFiles.mjs.map +1 -0
- package/dist/actions/deplint/getDependenciesFromPackageJson.mjs +29 -0
- package/dist/actions/deplint/getDependenciesFromPackageJson.mjs.map +1 -0
- package/dist/actions/deplint/getExtendsFromTsconfigs.mjs +68 -0
- package/dist/actions/deplint/getExtendsFromTsconfigs.mjs.map +1 -0
- package/dist/actions/deplint/getExternalImportsFromFiles.mjs +143 -0
- package/dist/actions/deplint/getExternalImportsFromFiles.mjs.map +1 -0
- package/dist/actions/deplint/getImportsFromFile.mjs +85 -0
- package/dist/actions/deplint/getImportsFromFile.mjs.map +1 -0
- package/dist/actions/deplint/getRequiredPeerDependencies.mjs +37 -0
- package/dist/actions/deplint/getRequiredPeerDependencies.mjs.map +1 -0
- package/dist/actions/deplint/getScriptReferencedPackages.mjs +83 -0
- package/dist/actions/deplint/getScriptReferencedPackages.mjs.map +1 -0
- package/dist/actions/deplint/implicitDevDependencies.mjs +116 -0
- package/dist/actions/deplint/implicitDevDependencies.mjs.map +1 -0
- package/dist/actions/deplint/index.mjs +1848 -0
- package/dist/actions/deplint/index.mjs.map +1 -0
- package/dist/actions/deplint/packageEditor.mjs +82 -0
- package/dist/actions/deplint/packageEditor.mjs.map +1 -0
- package/dist/actions/deplint/packageJsonEditor.mjs +101 -0
- package/dist/actions/deplint/packageJsonEditor.mjs.map +1 -0
- package/dist/actions/deplint/reporters.mjs +36 -0
- package/dist/actions/deplint/reporters.mjs.map +1 -0
- package/dist/actions/deplint/rules.mjs +1223 -0
- package/dist/actions/deplint/rules.mjs.map +1 -0
- package/dist/actions/deplint/snapshot.mjs +372 -0
- package/dist/actions/deplint/snapshot.mjs.map +1 -0
- package/dist/actions/deplint/tsScriptsAliases.mjs +20 -0
- package/dist/actions/deplint/tsScriptsAliases.mjs.map +1 -0
- package/dist/actions/deplint/types.mjs +1 -0
- package/dist/actions/deplint/types.mjs.map +1 -0
- package/dist/actions/deploy.mjs +194 -0
- package/dist/actions/deploy.mjs.map +1 -0
- package/dist/actions/dupdeps.mjs +226 -0
- package/dist/actions/dupdeps.mjs.map +1 -0
- package/dist/actions/eject.mjs +142 -0
- package/dist/actions/eject.mjs.map +1 -0
- package/dist/actions/fix.mjs +359 -0
- package/dist/actions/fix.mjs.map +1 -0
- package/dist/actions/gen-docs.mjs +155 -0
- package/dist/actions/gen-docs.mjs.map +1 -0
- package/dist/actions/gitignore.mjs +159 -0
- package/dist/actions/gitignore.mjs.map +1 -0
- package/dist/actions/gitlint-fix.mjs +27 -0
- package/dist/actions/gitlint-fix.mjs.map +1 -0
- package/dist/actions/gitlint.mjs +48 -0
- package/dist/actions/gitlint.mjs.map +1 -0
- package/dist/actions/index.mjs +8259 -0
- package/dist/actions/index.mjs.map +1 -0
- package/dist/actions/knip.mjs +119 -0
- package/dist/actions/knip.mjs.map +1 -0
- package/dist/actions/license.mjs +92 -0
- package/dist/actions/license.mjs.map +1 -0
- package/dist/actions/lint-init.mjs +275 -0
- package/dist/actions/lint-init.mjs.map +1 -0
- package/dist/actions/lint.mjs +356 -0
- package/dist/actions/lint.mjs.map +1 -0
- package/dist/actions/lintNext.mjs +209 -0
- package/dist/actions/lintNext.mjs.map +1 -0
- package/dist/actions/lintlint.mjs +341 -0
- package/dist/actions/lintlint.mjs.map +1 -0
- package/dist/actions/npmignore-gen.mjs +90 -0
- package/dist/actions/npmignore-gen.mjs.map +1 -0
- package/dist/actions/orphan.mjs +110 -0
- package/dist/actions/orphan.mjs.map +1 -0
- package/dist/actions/package/clean-outputs.mjs +50 -0
- package/dist/actions/package/clean-outputs.mjs.map +1 -0
- package/dist/actions/package/clean-typescript.mjs +50 -0
- package/dist/actions/package/clean-typescript.mjs.map +1 -0
- package/dist/actions/package/clean.mjs +69 -0
- package/dist/actions/package/clean.mjs.map +1 -0
- package/dist/actions/package/compile/XyConfig.mjs +32 -0
- package/dist/actions/package/compile/XyConfig.mjs.map +1 -0
- package/dist/actions/package/compile/buildEntries.mjs +53 -0
- package/dist/actions/package/compile/buildEntries.mjs.map +1 -0
- package/dist/actions/package/compile/compile.mjs +439 -0
- package/dist/actions/package/compile/compile.mjs.map +1 -0
- package/dist/actions/package/compile/copyTypeFiles.mjs +34 -0
- package/dist/actions/package/compile/copyTypeFiles.mjs.map +1 -0
- package/dist/actions/package/compile/deepMerge.mjs +27 -0
- package/dist/actions/package/compile/deepMerge.mjs.map +1 -0
- package/dist/actions/package/compile/getCompilerOptions.mjs +12 -0
- package/dist/actions/package/compile/getCompilerOptions.mjs.map +1 -0
- package/dist/actions/package/compile/index.mjs +472 -0
- package/dist/actions/package/compile/index.mjs.map +1 -0
- package/dist/actions/package/compile/inputs.mjs +22 -0
- package/dist/actions/package/compile/inputs.mjs.map +1 -0
- package/dist/actions/package/compile/packageCompileTsc.mjs +93 -0
- package/dist/actions/package/compile/packageCompileTsc.mjs.map +1 -0
- package/dist/actions/package/compile/packageCompileTscTypes.mjs +92 -0
- package/dist/actions/package/compile/packageCompileTscTypes.mjs.map +1 -0
- package/dist/actions/package/compile/packageCompileTsup.mjs +402 -0
- package/dist/actions/package/compile/packageCompileTsup.mjs.map +1 -0
- package/dist/actions/package/copy-assets.mjs +69 -0
- package/dist/actions/package/copy-assets.mjs.map +1 -0
- package/dist/actions/package/cycle.mjs +62 -0
- package/dist/actions/package/cycle.mjs.map +1 -0
- package/dist/actions/package/gen-docs.mjs +137 -0
- package/dist/actions/package/gen-docs.mjs.map +1 -0
- package/dist/actions/package/index.mjs +1131 -0
- package/dist/actions/package/index.mjs.map +1 -0
- package/dist/actions/package/lint.mjs +87 -0
- package/dist/actions/package/lint.mjs.map +1 -0
- package/dist/actions/package/publint.mjs +336 -0
- package/dist/actions/package/publint.mjs.map +1 -0
- package/dist/actions/package/recompile.mjs +510 -0
- package/dist/actions/package/recompile.mjs.map +1 -0
- package/dist/actions/package-lint-deps.mjs +348 -0
- package/dist/actions/package-lint-deps.mjs.map +1 -0
- package/dist/actions/package-lint.mjs +774 -0
- package/dist/actions/package-lint.mjs.map +1 -0
- package/dist/actions/packman/clean.mjs +144 -0
- package/dist/actions/packman/clean.mjs.map +1 -0
- package/dist/actions/packman/convert.mjs +1331 -0
- package/dist/actions/packman/convert.mjs.map +1 -0
- package/dist/actions/packman/convertToPnpm.mjs +295 -0
- package/dist/actions/packman/convertToPnpm.mjs.map +1 -0
- package/dist/actions/packman/convertToYarn.mjs +307 -0
- package/dist/actions/packman/convertToYarn.mjs.map +1 -0
- package/dist/actions/packman/index.mjs +1493 -0
- package/dist/actions/packman/index.mjs.map +1 -0
- package/dist/actions/packman/lint.mjs +109 -0
- package/dist/actions/packman/lint.mjs.map +1 -0
- package/dist/actions/packman/rewriteScripts.mjs +52 -0
- package/dist/actions/packman/rewriteScripts.mjs.map +1 -0
- package/dist/actions/packman/rewriteSourceImports.mjs +60 -0
- package/dist/actions/packman/rewriteSourceImports.mjs.map +1 -0
- package/dist/actions/packman/swapTsScriptsDependency.mjs +57 -0
- package/dist/actions/packman/swapTsScriptsDependency.mjs.map +1 -0
- package/dist/actions/publint.mjs +748 -0
- package/dist/actions/publint.mjs.map +1 -0
- package/dist/actions/publish.mjs +208 -0
- package/dist/actions/publish.mjs.map +1 -0
- package/dist/actions/reactTest.mjs +142 -0
- package/dist/actions/reactTest.mjs.map +1 -0
- package/dist/actions/readme-gen.mjs +362 -0
- package/dist/actions/readme-gen.mjs.map +1 -0
- package/dist/actions/readme-init.mjs +89 -0
- package/dist/actions/readme-init.mjs.map +1 -0
- package/dist/actions/readme-lint.mjs +147 -0
- package/dist/actions/readme-lint.mjs.map +1 -0
- package/dist/actions/rebuild.mjs +143 -0
- package/dist/actions/rebuild.mjs.map +1 -0
- package/dist/actions/recompile.mjs +196 -0
- package/dist/actions/recompile.mjs.map +1 -0
- package/dist/actions/reinstall.mjs +283 -0
- package/dist/actions/reinstall.mjs.map +1 -0
- package/dist/actions/relint.mjs +355 -0
- package/dist/actions/relint.mjs.map +1 -0
- package/dist/actions/repo-init.mjs +217 -0
- package/dist/actions/repo-init.mjs.map +1 -0
- package/dist/actions/retest.mjs +150 -0
- package/dist/actions/retest.mjs.map +1 -0
- package/dist/actions/sitemap.mjs +121 -0
- package/dist/actions/sitemap.mjs.map +1 -0
- package/dist/actions/sonar.mjs +119 -0
- package/dist/actions/sonar.mjs.map +1 -0
- package/dist/actions/start.mjs +142 -0
- package/dist/actions/start.mjs.map +1 -0
- package/dist/actions/statics.mjs +225 -0
- package/dist/actions/statics.mjs.map +1 -0
- package/dist/actions/test.mjs +144 -0
- package/dist/actions/test.mjs.map +1 -0
- package/dist/actions/up.mjs +140 -0
- package/dist/actions/up.mjs.map +1 -0
- package/dist/actions/updo.mjs +533 -0
- package/dist/actions/updo.mjs.map +1 -0
- package/dist/actions/upplug.mjs +124 -0
- package/dist/actions/upplug.mjs.map +1 -0
- package/dist/actions/upyarn.mjs +119 -0
- package/dist/actions/upyarn.mjs.map +1 -0
- package/dist/actions/yarn3only.mjs +60 -0
- package/dist/actions/yarn3only.mjs.map +1 -0
- package/dist/bin/package/build-only.mjs +451 -0
- package/dist/bin/package/build-only.mjs.map +1 -0
- package/dist/bin/package/build.mjs +451 -0
- package/dist/bin/package/build.mjs.map +1 -0
- package/dist/bin/package/clean-outputs.mjs +50 -0
- package/dist/bin/package/clean-outputs.mjs.map +1 -0
- package/dist/bin/package/clean-typescript.mjs +50 -0
- package/dist/bin/package/clean-typescript.mjs.map +1 -0
- package/dist/bin/package/clean.mjs +75 -0
- package/dist/bin/package/clean.mjs.map +1 -0
- package/dist/bin/package/compile-only.mjs +447 -0
- package/dist/bin/package/compile-only.mjs.map +1 -0
- package/dist/bin/package/compile-tsup.mjs +409 -0
- package/dist/bin/package/compile-tsup.mjs.map +1 -0
- package/dist/bin/package/compile.mjs +451 -0
- package/dist/bin/package/compile.mjs.map +1 -0
- package/dist/bin/package/copy-assets-cjs.mjs +75 -0
- package/dist/bin/package/copy-assets-cjs.mjs.map +1 -0
- package/dist/bin/package/copy-assets-esm.mjs +75 -0
- package/dist/bin/package/copy-assets-esm.mjs.map +1 -0
- package/dist/bin/package/cycle.mjs +72 -0
- package/dist/bin/package/cycle.mjs.map +1 -0
- package/dist/bin/package/fix.mjs +97 -0
- package/dist/bin/package/fix.mjs.map +1 -0
- package/dist/bin/package/gen-docs.mjs +142 -0
- package/dist/bin/package/gen-docs.mjs.map +1 -0
- package/dist/bin/package/lint-verbose.mjs +97 -0
- package/dist/bin/package/lint-verbose.mjs.map +1 -0
- package/dist/bin/package/lint.mjs +97 -0
- package/dist/bin/package/lint.mjs.map +1 -0
- package/dist/bin/package/publint.mjs +423 -0
- package/dist/bin/package/publint.mjs.map +1 -0
- package/dist/bin/package/recompile.mjs +516 -0
- package/dist/bin/package/recompile.mjs.map +1 -0
- package/dist/bin/package/relint.mjs +97 -0
- package/dist/bin/package/relint.mjs.map +1 -0
- package/dist/bin/run-or-exec.mjs +20 -0
- package/dist/bin/run-or-exec.mjs.map +1 -0
- package/dist/bin/xy.mjs +8885 -0
- package/dist/bin/xy.mjs.map +1 -0
- package/dist/index.d.ts +1102 -0
- package/dist/index.mjs +9986 -0
- package/dist/index.mjs.map +1 -0
- package/dist/lib/checkResult.mjs +16 -0
- package/dist/lib/checkResult.mjs.map +1 -0
- package/dist/lib/claudeMdTemplate.mjs +69 -0
- package/dist/lib/claudeMdTemplate.mjs.map +1 -0
- package/dist/lib/concurrency.mjs +38 -0
- package/dist/lib/concurrency.mjs.map +1 -0
- package/dist/lib/createBuildConfig.mjs +55 -0
- package/dist/lib/createBuildConfig.mjs.map +1 -0
- package/dist/lib/defaultBuildConfig.mjs +23 -0
- package/dist/lib/defaultBuildConfig.mjs.map +1 -0
- package/dist/lib/deleteGlob.mjs +13 -0
- package/dist/lib/deleteGlob.mjs.map +1 -0
- package/dist/lib/dependencies/DuplicateDetector.mjs +99 -0
- package/dist/lib/dependencies/DuplicateDetector.mjs.map +1 -0
- package/dist/lib/dependencies/detectDuplicateDependencies.mjs +203 -0
- package/dist/lib/dependencies/detectDuplicateDependencies.mjs.map +1 -0
- package/dist/lib/dependencies/index.mjs +281 -0
- package/dist/lib/dependencies/index.mjs.map +1 -0
- package/dist/lib/dependencies/workspaceCycles.mjs +79 -0
- package/dist/lib/dependencies/workspaceCycles.mjs.map +1 -0
- package/dist/lib/file/ReadFileSyncOptions.mjs +6 -0
- package/dist/lib/file/ReadFileSyncOptions.mjs.map +1 -0
- package/dist/lib/file/constants.mjs +8 -0
- package/dist/lib/file/constants.mjs.map +1 -0
- package/dist/lib/file/fileLines.mjs +32 -0
- package/dist/lib/file/fileLines.mjs.map +1 -0
- package/dist/lib/file/index.mjs +42 -0
- package/dist/lib/file/index.mjs.map +1 -0
- package/dist/lib/file/tryReadFileSync.mjs +14 -0
- package/dist/lib/file/tryReadFileSync.mjs.map +1 -0
- package/dist/lib/fillTemplate.mjs +8 -0
- package/dist/lib/fillTemplate.mjs.map +1 -0
- package/dist/lib/generateIgnoreFiles.mjs +86 -0
- package/dist/lib/generateIgnoreFiles.mjs.map +1 -0
- package/dist/lib/generateReadmeFiles.mjs +323 -0
- package/dist/lib/generateReadmeFiles.mjs.map +1 -0
- package/dist/lib/gitignoreTemplate.mjs +12 -0
- package/dist/lib/gitignoreTemplate.mjs.map +1 -0
- package/dist/lib/index.mjs +1627 -0
- package/dist/lib/index.mjs.map +1 -0
- package/dist/lib/initCwd.mjs +8 -0
- package/dist/lib/initCwd.mjs.map +1 -0
- package/dist/lib/jsonFormatters.mjs +11 -0
- package/dist/lib/jsonFormatters.mjs.map +1 -0
- package/dist/lib/latestVersions.mjs +12 -0
- package/dist/lib/latestVersions.mjs.map +1 -0
- package/dist/lib/loadConfig.mjs +72 -0
- package/dist/lib/loadConfig.mjs.map +1 -0
- package/dist/lib/packageName.mjs +26 -0
- package/dist/lib/packageName.mjs.map +1 -0
- package/dist/lib/parsedPackageJSON.mjs +11 -0
- package/dist/lib/parsedPackageJSON.mjs.map +1 -0
- package/dist/lib/processEx.mjs +36 -0
- package/dist/lib/processEx.mjs.map +1 -0
- package/dist/lib/repoTemplates.mjs +34 -0
- package/dist/lib/repoTemplates.mjs.map +1 -0
- package/dist/lib/runInstall.mjs +30 -0
- package/dist/lib/runInstall.mjs.map +1 -0
- package/dist/lib/runSteps.mjs +118 -0
- package/dist/lib/runSteps.mjs.map +1 -0
- package/dist/lib/runStepsAsync.mjs +136 -0
- package/dist/lib/runStepsAsync.mjs.map +1 -0
- package/dist/lib/runXy.mjs +147 -0
- package/dist/lib/runXy.mjs.map +1 -0
- package/dist/lib/runXyWithWarning.mjs +36 -0
- package/dist/lib/runXyWithWarning.mjs.map +1 -0
- package/dist/lib/safeExit.mjs +61 -0
- package/dist/lib/safeExit.mjs.map +1 -0
- package/dist/lib/string/empty.mjs +8 -0
- package/dist/lib/string/empty.mjs.map +1 -0
- package/dist/lib/string/index.mjs +12 -0
- package/dist/lib/string/index.mjs.map +1 -0
- package/dist/lib/string/union.mjs +6 -0
- package/dist/lib/string/union.mjs.map +1 -0
- package/dist/lib/tryRunLocalScript.mjs +57 -0
- package/dist/lib/tryRunLocalScript.mjs.map +1 -0
- package/dist/lib/updo/applyUpdates.mjs +44 -0
- package/dist/lib/updo/applyUpdates.mjs.map +1 -0
- package/dist/lib/updo/collectWorkspaceDeps.mjs +48 -0
- package/dist/lib/updo/collectWorkspaceDeps.mjs.map +1 -0
- package/dist/lib/updo/fetchRegistryInfo.mjs +53 -0
- package/dist/lib/updo/fetchRegistryInfo.mjs.map +1 -0
- package/dist/lib/updo/index.mjs +594 -0
- package/dist/lib/updo/index.mjs.map +1 -0
- package/dist/lib/updo/interactiveSelect.mjs +185 -0
- package/dist/lib/updo/interactiveSelect.mjs.map +1 -0
- package/dist/lib/updo/interfaces.mjs +1 -0
- package/dist/lib/updo/interfaces.mjs.map +1 -0
- package/dist/lib/updo/renderTable.mjs +79 -0
- package/dist/lib/updo/renderTable.mjs.map +1 -0
- package/dist/lib/updo/resolveVersions.mjs +49 -0
- package/dist/lib/updo/resolveVersions.mjs.map +1 -0
- package/dist/lib/updo/runUpdo.mjs +511 -0
- package/dist/lib/updo/runUpdo.mjs.map +1 -0
- package/dist/lib/withErrnoException.mjs +13 -0
- package/dist/lib/withErrnoException.mjs.map +1 -0
- package/dist/lib/withError.mjs +8 -0
- package/dist/lib/withError.mjs.map +1 -0
- package/dist/lib/yarn/index.mjs +39 -0
- package/dist/lib/yarn/index.mjs.map +1 -0
- package/dist/lib/yarn/isYarnVersionOrGreater.mjs +18 -0
- package/dist/lib/yarn/isYarnVersionOrGreater.mjs.map +1 -0
- package/dist/lib/yarn/workspace/Workspace.mjs +1 -0
- package/dist/lib/yarn/workspace/Workspace.mjs.map +1 -0
- package/dist/lib/yarn/workspace/index.mjs +23 -0
- package/dist/lib/yarn/workspace/index.mjs.map +1 -0
- package/dist/lib/yarn/workspace/yarnWorkspace.mjs +22 -0
- package/dist/lib/yarn/workspace/yarnWorkspace.mjs.map +1 -0
- package/dist/lib/yarn/workspace/yarnWorkspaces.mjs +15 -0
- package/dist/lib/yarn/workspace/yarnWorkspaces.mjs.map +1 -0
- package/dist/lib/yarn/yarnInitCwd.mjs +8 -0
- package/dist/lib/yarn/yarnInitCwd.mjs.map +1 -0
- package/dist/loadPackageConfig.mjs +18 -0
- package/dist/loadPackageConfig.mjs.map +1 -0
- package/dist/pm/PackageManager.mjs +1 -0
- package/dist/pm/PackageManager.mjs.map +1 -0
- package/dist/pm/detectPackageManager.mjs +10 -0
- package/dist/pm/detectPackageManager.mjs.map +1 -0
- package/dist/pm/detectReact.mjs +52 -0
- package/dist/pm/detectReact.mjs.map +1 -0
- package/dist/pm/index.mjs +263 -0
- package/dist/pm/index.mjs.map +1 -0
- package/dist/pm/pnpmPackageManager.mjs +97 -0
- package/dist/pm/pnpmPackageManager.mjs.map +1 -0
- package/dist/pm/registry.mjs +27 -0
- package/dist/pm/registry.mjs.map +1 -0
- package/dist/pm/yarnPackageManager.mjs +112 -0
- package/dist/pm/yarnPackageManager.mjs.map +1 -0
- package/dist/types.d.mjs +1 -0
- package/dist/types.d.mjs.map +1 -0
- package/dist/xy/build/buildCommand.mjs +194 -0
- package/dist/xy/build/buildCommand.mjs.map +1 -0
- package/dist/xy/build/compileCommand.mjs +203 -0
- package/dist/xy/build/compileCommand.mjs.map +1 -0
- package/dist/xy/build/compileOnlyCommand.mjs +204 -0
- package/dist/xy/build/compileOnlyCommand.mjs.map +1 -0
- package/dist/xy/build/copyAssetsCommand.mjs +92 -0
- package/dist/xy/build/copyAssetsCommand.mjs.map +1 -0
- package/dist/xy/build/index.mjs +487 -0
- package/dist/xy/build/index.mjs.map +1 -0
- package/dist/xy/build/rebuildCommand.mjs +156 -0
- package/dist/xy/build/rebuildCommand.mjs.map +1 -0
- package/dist/xy/build/recompileCommand.mjs +215 -0
- package/dist/xy/build/recompileCommand.mjs.map +1 -0
- package/dist/xy/common/checkCommand.mjs +1909 -0
- package/dist/xy/common/checkCommand.mjs.map +1 -0
- package/dist/xy/common/claude/checkCommand.mjs +207 -0
- package/dist/xy/common/claude/checkCommand.mjs.map +1 -0
- package/dist/xy/common/claude/cleanCommand.mjs +78 -0
- package/dist/xy/common/claude/cleanCommand.mjs.map +1 -0
- package/dist/xy/common/claude/commandsCommand.mjs +134 -0
- package/dist/xy/common/claude/commandsCommand.mjs.map +1 -0
- package/dist/xy/common/claude/index.mjs +734 -0
- package/dist/xy/common/claude/index.mjs.map +1 -0
- package/dist/xy/common/claude/initCommand.mjs +458 -0
- package/dist/xy/common/claude/initCommand.mjs.map +1 -0
- package/dist/xy/common/claude/rulesCommand.mjs +167 -0
- package/dist/xy/common/claude/rulesCommand.mjs.map +1 -0
- package/dist/xy/common/claude/settingsCommand.mjs +115 -0
- package/dist/xy/common/claude/settingsCommand.mjs.map +1 -0
- package/dist/xy/common/claude/skillsCommand.mjs +140 -0
- package/dist/xy/common/claude/skillsCommand.mjs.map +1 -0
- package/dist/xy/common/cleanDocsCommand.mjs +74 -0
- package/dist/xy/common/cleanDocsCommand.mjs.map +1 -0
- package/dist/xy/common/deadCommand.mjs +137 -0
- package/dist/xy/common/deadCommand.mjs.map +1 -0
- package/dist/xy/common/genDocsCommand.mjs +175 -0
- package/dist/xy/common/genDocsCommand.mjs.map +1 -0
- package/dist/xy/common/gitignoreCommand.mjs +165 -0
- package/dist/xy/common/gitignoreCommand.mjs.map +1 -0
- package/dist/xy/common/gitlintCommand.mjs +89 -0
- package/dist/xy/common/gitlintCommand.mjs.map +1 -0
- package/dist/xy/common/index.mjs +4654 -0
- package/dist/xy/common/index.mjs.map +1 -0
- package/dist/xy/common/licenseCommand.mjs +108 -0
- package/dist/xy/common/licenseCommand.mjs.map +1 -0
- package/dist/xy/common/npmignoreGenCommand.mjs +100 -0
- package/dist/xy/common/npmignoreGenCommand.mjs.map +1 -0
- package/dist/xy/common/orphan/cleanCommand.mjs +102 -0
- package/dist/xy/common/orphan/cleanCommand.mjs.map +1 -0
- package/dist/xy/common/orphan/index.mjs +138 -0
- package/dist/xy/common/orphan/index.mjs.map +1 -0
- package/dist/xy/common/orphan/listCommand.mjs +100 -0
- package/dist/xy/common/orphan/listCommand.mjs.map +1 -0
- package/dist/xy/common/packmanCommand.mjs +1538 -0
- package/dist/xy/common/packmanCommand.mjs.map +1 -0
- package/dist/xy/common/readme/genCommand.mjs +395 -0
- package/dist/xy/common/readme/genCommand.mjs.map +1 -0
- package/dist/xy/common/readme/index.mjs +538 -0
- package/dist/xy/common/readme/index.mjs.map +1 -0
- package/dist/xy/common/readme/initCommand.mjs +109 -0
- package/dist/xy/common/readme/initCommand.mjs.map +1 -0
- package/dist/xy/common/readme/lintCommand.mjs +181 -0
- package/dist/xy/common/readme/lintCommand.mjs.map +1 -0
- package/dist/xy/common/repo/index.mjs +1070 -0
- package/dist/xy/common/repo/index.mjs.map +1 -0
- package/dist/xy/common/repo/initCommand.mjs +273 -0
- package/dist/xy/common/repo/initCommand.mjs.map +1 -0
- package/dist/xy/common/repo/lintCommand.mjs +789 -0
- package/dist/xy/common/repo/lintCommand.mjs.map +1 -0
- package/dist/xy/common/retestCommand.mjs +163 -0
- package/dist/xy/common/retestCommand.mjs.map +1 -0
- package/dist/xy/common/testCommand.mjs +157 -0
- package/dist/xy/common/testCommand.mjs.map +1 -0
- package/dist/xy/deploy/deployCommand.mjs +214 -0
- package/dist/xy/deploy/deployCommand.mjs.map +1 -0
- package/dist/xy/deploy/index.mjs +289 -0
- package/dist/xy/deploy/index.mjs.map +1 -0
- package/dist/xy/deploy/publishCommand.mjs +218 -0
- package/dist/xy/deploy/publishCommand.mjs.map +1 -0
- package/dist/xy/index.mjs +8887 -0
- package/dist/xy/index.mjs.map +1 -0
- package/dist/xy/install/cleanCommand.mjs +182 -0
- package/dist/xy/install/cleanCommand.mjs.map +1 -0
- package/dist/xy/install/dupdepsCommand.mjs +234 -0
- package/dist/xy/install/dupdepsCommand.mjs.map +1 -0
- package/dist/xy/install/index.mjs +1006 -0
- package/dist/xy/install/index.mjs.map +1 -0
- package/dist/xy/install/reinstallCommand.mjs +292 -0
- package/dist/xy/install/reinstallCommand.mjs.map +1 -0
- package/dist/xy/install/staticsCommand.mjs +233 -0
- package/dist/xy/install/staticsCommand.mjs.map +1 -0
- package/dist/xy/install/upCommand.mjs +150 -0
- package/dist/xy/install/upCommand.mjs.map +1 -0
- package/dist/xy/install/updoCommand.mjs +550 -0
- package/dist/xy/install/updoCommand.mjs.map +1 -0
- package/dist/xy/lint/cycleCommand.mjs +289 -0
- package/dist/xy/lint/cycleCommand.mjs.map +1 -0
- package/dist/xy/lint/deplintCommand.mjs +1897 -0
- package/dist/xy/lint/deplintCommand.mjs.map +1 -0
- package/dist/xy/lint/fixCommand.mjs +398 -0
- package/dist/xy/lint/fixCommand.mjs.map +1 -0
- package/dist/xy/lint/index.mjs +3759 -0
- package/dist/xy/lint/index.mjs.map +1 -0
- package/dist/xy/lint/knipCommand.mjs +142 -0
- package/dist/xy/lint/knipCommand.mjs.map +1 -0
- package/dist/xy/lint/lint/index.mjs +695 -0
- package/dist/xy/lint/lint/index.mjs.map +1 -0
- package/dist/xy/lint/lint/initCommand.mjs +282 -0
- package/dist/xy/lint/lint/initCommand.mjs.map +1 -0
- package/dist/xy/lint/lint/runCommand.mjs +405 -0
- package/dist/xy/lint/lint/runCommand.mjs.map +1 -0
- package/dist/xy/lint/lintCommand.mjs +695 -0
- package/dist/xy/lint/lintCommand.mjs.map +1 -0
- package/dist/xy/lint/lintlintCommand.mjs +359 -0
- package/dist/xy/lint/lintlintCommand.mjs.map +1 -0
- package/dist/xy/lint/publintCommand.mjs +778 -0
- package/dist/xy/lint/publintCommand.mjs.map +1 -0
- package/dist/xy/lint/relintCommand.mjs +381 -0
- package/dist/xy/lint/relintCommand.mjs.map +1 -0
- package/dist/xy/lint/sonarCommand.mjs +137 -0
- package/dist/xy/lint/sonarCommand.mjs.map +1 -0
- package/dist/xy/param.mjs +8 -0
- package/dist/xy/param.mjs.map +1 -0
- package/dist/xy/react/analyzeCommand.mjs +150 -0
- package/dist/xy/react/analyzeCommand.mjs.map +1 -0
- package/dist/xy/react/ejectCommand.mjs +150 -0
- package/dist/xy/react/ejectCommand.mjs.map +1 -0
- package/dist/xy/react/index.mjs +202 -0
- package/dist/xy/react/index.mjs.map +1 -0
- package/dist/xy/react/sitemapCommand.mjs +129 -0
- package/dist/xy/react/sitemapCommand.mjs.map +1 -0
- package/dist/xy/react/startCommand.mjs +150 -0
- package/dist/xy/react/startCommand.mjs.map +1 -0
- package/dist/xy/xy.mjs +8879 -0
- package/dist/xy/xy.mjs.map +1 -0
- package/dist/xy/xyParseOptions.mjs +117 -0
- package/dist/xy/xyParseOptions.mjs.map +1 -0
- package/dist/xy/yarn/index.mjs +188 -0
- package/dist/xy/yarn/index.mjs.map +1 -0
- package/dist/xy/yarn/upplugCommand.mjs +134 -0
- package/dist/xy/yarn/upplugCommand.mjs.map +1 -0
- package/dist/xy/yarn/upyarnCommand.mjs +129 -0
- package/dist/xy/yarn/upyarnCommand.mjs.map +1 -0
- package/dist/xy/yarn/yarn3OnlyCommand.mjs +70 -0
- package/dist/xy/yarn/yarn3OnlyCommand.mjs.map +1 -0
- package/package.json +119 -0
- package/templates/claude/CLAUDE-local.md +4 -0
- package/templates/claude/CLAUDE-project.md +4 -0
- package/templates/claude/commands/xy-build.md +7 -0
- package/templates/claude/commands/xy-clean.md +7 -0
- package/templates/claude/commands/xy-compile.md +7 -0
- package/templates/claude/commands/xy-cycle.md +7 -0
- package/templates/claude/commands/xy-dead.md +7 -0
- package/templates/claude/commands/xy-deplint.md +7 -0
- package/templates/claude/commands/xy-deps.md +24 -0
- package/templates/claude/commands/xy-dupdeps.md +7 -0
- package/templates/claude/commands/xy-fix.md +7 -0
- package/templates/claude/commands/xy-gen-docs.md +7 -0
- package/templates/claude/commands/xy-gitignore.md +7 -0
- package/templates/claude/commands/xy-gitlint.md +7 -0
- package/templates/claude/commands/xy-knip.md +7 -0
- package/templates/claude/commands/xy-license.md +7 -0
- package/templates/claude/commands/xy-lint-rules.md +44 -0
- package/templates/claude/commands/xy-lint.md +7 -0
- package/templates/claude/commands/xy-publint.md +7 -0
- package/templates/claude/commands/xy-rebuild.md +7 -0
- package/templates/claude/commands/xy-recompile.md +7 -0
- package/templates/claude/commands/xy-reinstall.md +7 -0
- package/templates/claude/commands/xy-relint.md +7 -0
- package/templates/claude/commands/xy-retest.md +7 -0
- package/templates/claude/commands/xy-sonar.md +7 -0
- package/templates/claude/commands/xy-test.md +7 -0
- package/templates/claude/commands/xy-up.md +9 -0
- package/templates/claude/rules/xylabs-architecture.md +8 -0
- package/templates/claude/rules/xylabs-git-workflow.md +7 -0
- package/templates/claude/rules/xylabs-naming.md +7 -0
- package/templates/claude/rules/xylabs-style.md +17 -0
- package/templates/claude/skills/xylabs-e2e-setup/SKILL.md +223 -0
- package/templates/claude/skills/xylabs-xy-cli/SKILL.md +236 -0
- package/templates/claude/skills/xylabs-xy-deplint-fix/SKILL.md +122 -0
- package/templates/gitignore/gitignore/template.gitignore +51 -0
- package/templates/gitignore/template.gitignore +51 -0
- package/templates/readme/README.body.md +25 -0
- package/templates/readme/README.template.md +22 -0
- package/templates/repo/cli/package/package.json.tmpl +63 -0
- package/templates/repo/cli/package/src/__packageName__.ts.tmpl +21 -0
- package/templates/repo/cli/package/src/actions/index.ts +1 -0
- package/templates/repo/cli/package/src/actions/printVersion.ts.tmpl +8 -0
- package/templates/repo/cli/package/src/bin/__packageName__.ts.tmpl +12 -0
- package/templates/repo/cli/package/src/commands/index.ts +1 -0
- package/templates/repo/cli/package/src/commands/versionCommand.ts.tmpl +11 -0
- package/templates/repo/cli/package/src/index.ts.tmpl +1 -0
- package/templates/repo/cli/package/tsconfig.build.json +25 -0
- package/templates/repo/cli/package/tsconfig.json +4 -0
- package/templates/repo/cli/package/tsup.config.ts +15 -0
- package/templates/repo/cli/package/xy.config.ts +3 -0
- package/templates/repo/cli/root/CLAUDE.md.tmpl +38 -0
- package/templates/repo/cli/root/cspell.json.tmpl +13 -0
- package/templates/repo/cli/root/eslint.config.ts +28 -0
- package/templates/repo/cli/root/github/workflows/build-pnpm.yml.tmpl +34 -0
- package/templates/repo/cli/root/github/workflows/build-yarn.yml.tmpl +32 -0
- package/templates/repo/cli/root/gitignore.tmpl +47 -0
- package/templates/repo/cli/root/knip.config.ts +16 -0
- package/templates/repo/cli/root/package.json.tmpl +54 -0
- package/templates/repo/cli/root/pnpm-workspace.yaml +2 -0
- package/templates/repo/cli/root/tsconfig.json +4 -0
- package/templates/repo/cli/root/vitest.config.ts +31 -0
- package/templates/repo/cli/root/xy.config.ts.tmpl +5 -0
|
@@ -0,0 +1,1493 @@
|
|
|
1
|
+
// src/actions/packman/clean.ts
|
|
2
|
+
import {
|
|
3
|
+
existsSync as existsSync8,
|
|
4
|
+
rmSync as rmSync3,
|
|
5
|
+
writeFileSync as writeFileSync7
|
|
6
|
+
} from "fs";
|
|
7
|
+
import PATH7 from "path";
|
|
8
|
+
import chalk9 from "chalk";
|
|
9
|
+
|
|
10
|
+
// src/actions/packman/convert.ts
|
|
11
|
+
import {
|
|
12
|
+
existsSync as existsSync7,
|
|
13
|
+
readdirSync,
|
|
14
|
+
readFileSync as readFileSync7,
|
|
15
|
+
statSync
|
|
16
|
+
} from "fs";
|
|
17
|
+
import PATH6 from "path";
|
|
18
|
+
import chalk8 from "chalk";
|
|
19
|
+
|
|
20
|
+
// src/actions/package-lint.ts
|
|
21
|
+
import {
|
|
22
|
+
existsSync as existsSync2,
|
|
23
|
+
readFileSync as readFileSync2,
|
|
24
|
+
writeFileSync as writeFileSync2
|
|
25
|
+
} from "fs";
|
|
26
|
+
import PATH2 from "path";
|
|
27
|
+
import chalk3 from "chalk";
|
|
28
|
+
import picomatch from "picomatch";
|
|
29
|
+
import semver2 from "semver";
|
|
30
|
+
|
|
31
|
+
// src/pm/detectPackageManager.ts
|
|
32
|
+
import { existsSync } from "fs";
|
|
33
|
+
function detectPackageManager() {
|
|
34
|
+
if (existsSync("pnpm-lock.yaml") || existsSync("pnpm-workspace.yaml")) return "pnpm";
|
|
35
|
+
return "yarn";
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
// src/pm/registry.ts
|
|
39
|
+
var implementations = /* @__PURE__ */ new Map();
|
|
40
|
+
function getPackageManager(name) {
|
|
41
|
+
const pmName = name ?? detectPackageManager();
|
|
42
|
+
const pm = implementations.get(pmName);
|
|
43
|
+
if (!pm) {
|
|
44
|
+
throw new Error(
|
|
45
|
+
`No package manager implementation registered for "${pmName}". Ensure registerPackageManager() has been called before getPackageManager().`
|
|
46
|
+
);
|
|
47
|
+
}
|
|
48
|
+
return pm;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
// src/lib/initCwd.ts
|
|
52
|
+
function INIT_CWD() {
|
|
53
|
+
return process.env.INIT_CWD ?? process.cwd();
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
// src/lib/latestVersions.ts
|
|
57
|
+
var latestVersions = {
|
|
58
|
+
node: "24.14.1",
|
|
59
|
+
nodeLtsCodename: "Krypton",
|
|
60
|
+
npm: "11.11.0",
|
|
61
|
+
pnpm: "10.33.0",
|
|
62
|
+
yarn: "4.13.0"
|
|
63
|
+
};
|
|
64
|
+
|
|
65
|
+
// src/lib/runInstall.ts
|
|
66
|
+
import { spawnSync } from "child_process";
|
|
67
|
+
import chalk from "chalk";
|
|
68
|
+
function runInstall(cwd) {
|
|
69
|
+
const pm = detectPackageManager();
|
|
70
|
+
console.log(chalk.gray(`Running ${pm} install...`));
|
|
71
|
+
const result = spawnSync(pm, ["install"], {
|
|
72
|
+
cwd,
|
|
73
|
+
stdio: "inherit"
|
|
74
|
+
});
|
|
75
|
+
if (result.status !== 0) {
|
|
76
|
+
console.warn(chalk.yellow(`${pm} install failed`));
|
|
77
|
+
return false;
|
|
78
|
+
}
|
|
79
|
+
console.log(chalk.green("Dependencies installed"));
|
|
80
|
+
return true;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
// src/actions/package-lint-deps.ts
|
|
84
|
+
import { readFileSync, writeFileSync } from "fs";
|
|
85
|
+
import PATH from "path";
|
|
86
|
+
import chalk2 from "chalk";
|
|
87
|
+
import semver from "semver";
|
|
88
|
+
function readWorkspacePackageJson(cwd, location) {
|
|
89
|
+
const pkgPath = PATH.resolve(cwd, location, "package.json");
|
|
90
|
+
try {
|
|
91
|
+
return JSON.parse(readFileSync(pkgPath, "utf8"));
|
|
92
|
+
} catch {
|
|
93
|
+
return void 0;
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
function writeWorkspacePackageJson(cwd, location, pkg) {
|
|
97
|
+
const pkgPath = PATH.resolve(cwd, location, "package.json");
|
|
98
|
+
writeFileSync(pkgPath, `${JSON.stringify(pkg, null, 2)}
|
|
99
|
+
`, "utf8");
|
|
100
|
+
}
|
|
101
|
+
function buildWorkspaceVersionMap(cwd, workspaces) {
|
|
102
|
+
const map = /* @__PURE__ */ new Map();
|
|
103
|
+
for (const { location, name } of workspaces) {
|
|
104
|
+
if (location === ".") continue;
|
|
105
|
+
const pkg = readWorkspacePackageJson(cwd, location);
|
|
106
|
+
if (!pkg) continue;
|
|
107
|
+
const version = pkg.version;
|
|
108
|
+
if (version) map.set(name, version);
|
|
109
|
+
}
|
|
110
|
+
return map;
|
|
111
|
+
}
|
|
112
|
+
function expectedPeerRange(devDepVersion, targetVersion) {
|
|
113
|
+
const parsed = semver.parse(targetVersion);
|
|
114
|
+
if (!parsed) return `~${targetVersion}`;
|
|
115
|
+
if (devDepVersion === "workspace:^") {
|
|
116
|
+
return `^${parsed.major}`;
|
|
117
|
+
}
|
|
118
|
+
return `~${parsed.major}.${parsed.minor}`;
|
|
119
|
+
}
|
|
120
|
+
function checkVersionConsistency(cwd, rootPkg, workspaces) {
|
|
121
|
+
const result = {
|
|
122
|
+
errors: [],
|
|
123
|
+
fixable: [],
|
|
124
|
+
warnings: []
|
|
125
|
+
};
|
|
126
|
+
if (rootPkg.version !== void 0) {
|
|
127
|
+
result.fixable.push('Root package.json should not have a "version" field in a monorepo');
|
|
128
|
+
}
|
|
129
|
+
const versions = /* @__PURE__ */ new Map();
|
|
130
|
+
for (const { location, name } of workspaces) {
|
|
131
|
+
if (location === ".") continue;
|
|
132
|
+
const pkg = readWorkspacePackageJson(cwd, location);
|
|
133
|
+
if (!pkg) continue;
|
|
134
|
+
const version = pkg.version;
|
|
135
|
+
if (version) {
|
|
136
|
+
versions.set(name, version);
|
|
137
|
+
} else {
|
|
138
|
+
result.errors.push(`${name} (${location}) is missing a "version" field`);
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
const uniqueVersions = new Set(versions.values());
|
|
142
|
+
if (uniqueVersions.size > 1) {
|
|
143
|
+
const versionList = [...uniqueVersions].toSorted(semver.rcompare);
|
|
144
|
+
for (const [name, version] of versions) {
|
|
145
|
+
if (version !== versionList[0]) {
|
|
146
|
+
result.fixable.push(`${name} has version ${version} (expected ${versionList[0]})`);
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
return result;
|
|
151
|
+
}
|
|
152
|
+
function fixVersionConsistency(cwd, rootPkg, writeRootPackageJson2, workspaces) {
|
|
153
|
+
if (rootPkg.version !== void 0) {
|
|
154
|
+
delete rootPkg.version;
|
|
155
|
+
writeRootPackageJson2(cwd, rootPkg);
|
|
156
|
+
console.log(chalk2.green(' \u2714 Fixed: removed "version" from root package.json'));
|
|
157
|
+
}
|
|
158
|
+
const versions = [];
|
|
159
|
+
for (const { location } of workspaces) {
|
|
160
|
+
if (location === ".") continue;
|
|
161
|
+
const pkg = readWorkspacePackageJson(cwd, location);
|
|
162
|
+
if (!pkg) continue;
|
|
163
|
+
const version = pkg.version;
|
|
164
|
+
if (version && semver.valid(version)) {
|
|
165
|
+
versions.push(version);
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
if (versions.length === 0) return;
|
|
169
|
+
const highest = versions.toSorted(semver.rcompare)[0];
|
|
170
|
+
for (const { location, name } of workspaces) {
|
|
171
|
+
if (location === ".") continue;
|
|
172
|
+
const pkg = readWorkspacePackageJson(cwd, location);
|
|
173
|
+
if (!pkg) continue;
|
|
174
|
+
if (pkg.version !== highest) {
|
|
175
|
+
pkg.version = highest;
|
|
176
|
+
writeWorkspacePackageJson(cwd, location, pkg);
|
|
177
|
+
console.log(chalk2.green(` \u2714 Fixed: set version to ${highest} in ${name} (${location})`));
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
function expectedDepVersion(targetVersion) {
|
|
182
|
+
const parsed = semver.parse(targetVersion);
|
|
183
|
+
if (!parsed) return `~${targetVersion}`;
|
|
184
|
+
return `~${targetVersion}`;
|
|
185
|
+
}
|
|
186
|
+
function checkInternalDepVersions(cwd, workspaces) {
|
|
187
|
+
const result = {
|
|
188
|
+
errors: [],
|
|
189
|
+
fixable: [],
|
|
190
|
+
warnings: []
|
|
191
|
+
};
|
|
192
|
+
const workspaceVersions = buildWorkspaceVersionMap(cwd, workspaces);
|
|
193
|
+
for (const { location, name } of workspaces) {
|
|
194
|
+
const pkg = readWorkspacePackageJson(cwd, location);
|
|
195
|
+
if (!pkg) continue;
|
|
196
|
+
for (const depField of ["dependencies", "devDependencies"]) {
|
|
197
|
+
const deps = pkg[depField];
|
|
198
|
+
if (!deps) continue;
|
|
199
|
+
for (const [dep, version] of Object.entries(deps)) {
|
|
200
|
+
const targetVersion = workspaceVersions.get(dep);
|
|
201
|
+
if (!targetVersion) continue;
|
|
202
|
+
const expected = expectedDepVersion(targetVersion);
|
|
203
|
+
if (version.startsWith("workspace:")) {
|
|
204
|
+
result.fixable.push(
|
|
205
|
+
`${name} (${location}) ${depField}.${dep} is "${version}" \u2014 should be "${expected}" (not workspace: protocol)`
|
|
206
|
+
);
|
|
207
|
+
} else if (version !== expected) {
|
|
208
|
+
result.fixable.push(
|
|
209
|
+
`${name} (${location}) ${depField}.${dep} is "${version}" \u2014 should be "${expected}"`
|
|
210
|
+
);
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
}
|
|
215
|
+
return result;
|
|
216
|
+
}
|
|
217
|
+
function fixInternalDepVersions(cwd, workspaces) {
|
|
218
|
+
const workspaceVersions = buildWorkspaceVersionMap(cwd, workspaces);
|
|
219
|
+
for (const { location, name } of workspaces) {
|
|
220
|
+
const pkg = readWorkspacePackageJson(cwd, location);
|
|
221
|
+
if (!pkg) continue;
|
|
222
|
+
let modified = false;
|
|
223
|
+
for (const depField of ["dependencies", "devDependencies"]) {
|
|
224
|
+
const deps = pkg[depField];
|
|
225
|
+
if (!deps) continue;
|
|
226
|
+
for (const [dep, version] of Object.entries(deps)) {
|
|
227
|
+
const targetVersion = workspaceVersions.get(dep);
|
|
228
|
+
if (!targetVersion) continue;
|
|
229
|
+
const expected = expectedDepVersion(targetVersion);
|
|
230
|
+
if (version !== expected) {
|
|
231
|
+
deps[dep] = expected;
|
|
232
|
+
console.log(chalk2.green(` \u2714 Fixed: set ${depField}.${dep} to "${expected}" in ${name} (${location})`));
|
|
233
|
+
modified = true;
|
|
234
|
+
}
|
|
235
|
+
}
|
|
236
|
+
}
|
|
237
|
+
if (modified) {
|
|
238
|
+
writeWorkspacePackageJson(cwd, location, pkg);
|
|
239
|
+
}
|
|
240
|
+
}
|
|
241
|
+
}
|
|
242
|
+
function checkWorkspaceProtocol(cwd, workspaces) {
|
|
243
|
+
const result = {
|
|
244
|
+
errors: [],
|
|
245
|
+
fixable: [],
|
|
246
|
+
warnings: []
|
|
247
|
+
};
|
|
248
|
+
const workspaceNames = new Set(workspaces.map((w) => w.name));
|
|
249
|
+
for (const { location, name } of workspaces) {
|
|
250
|
+
const pkg = readWorkspacePackageJson(cwd, location);
|
|
251
|
+
if (!pkg) continue;
|
|
252
|
+
for (const depField of ["dependencies", "devDependencies"]) {
|
|
253
|
+
const deps = pkg[depField];
|
|
254
|
+
if (!deps) continue;
|
|
255
|
+
for (const [dep, version] of Object.entries(deps)) {
|
|
256
|
+
if (!workspaceNames.has(dep)) continue;
|
|
257
|
+
if (!version.startsWith("workspace:")) {
|
|
258
|
+
result.fixable.push(
|
|
259
|
+
`${name} (${location}) ${depField}.${dep} is "${version}" \u2014 should use workspace: protocol`
|
|
260
|
+
);
|
|
261
|
+
}
|
|
262
|
+
}
|
|
263
|
+
}
|
|
264
|
+
}
|
|
265
|
+
return result;
|
|
266
|
+
}
|
|
267
|
+
function fixWorkspaceProtocol(cwd, workspaces) {
|
|
268
|
+
const workspaceNames = new Set(workspaces.map((w) => w.name));
|
|
269
|
+
for (const { location, name } of workspaces) {
|
|
270
|
+
const pkg = readWorkspacePackageJson(cwd, location);
|
|
271
|
+
if (!pkg) continue;
|
|
272
|
+
let modified = false;
|
|
273
|
+
for (const depField of ["dependencies", "devDependencies"]) {
|
|
274
|
+
const deps = pkg[depField];
|
|
275
|
+
if (!deps) continue;
|
|
276
|
+
for (const [dep, version] of Object.entries(deps)) {
|
|
277
|
+
if (!workspaceNames.has(dep)) continue;
|
|
278
|
+
if (!version.startsWith("workspace:")) {
|
|
279
|
+
deps[dep] = "workspace:~";
|
|
280
|
+
console.log(chalk2.green(` \u2714 Fixed: set ${depField}.${dep} to "workspace:~" in ${name} (${location})`));
|
|
281
|
+
modified = true;
|
|
282
|
+
}
|
|
283
|
+
}
|
|
284
|
+
}
|
|
285
|
+
if (modified) {
|
|
286
|
+
writeWorkspacePackageJson(cwd, location, pkg);
|
|
287
|
+
}
|
|
288
|
+
}
|
|
289
|
+
}
|
|
290
|
+
function checkInternalPeerVersions(cwd, workspaces) {
|
|
291
|
+
const result = {
|
|
292
|
+
errors: [],
|
|
293
|
+
fixable: [],
|
|
294
|
+
warnings: []
|
|
295
|
+
};
|
|
296
|
+
const workspaceVersions = buildWorkspaceVersionMap(cwd, workspaces);
|
|
297
|
+
for (const { location, name } of workspaces) {
|
|
298
|
+
const pkg = readWorkspacePackageJson(cwd, location);
|
|
299
|
+
if (!pkg) continue;
|
|
300
|
+
const peerDeps = pkg.peerDependencies;
|
|
301
|
+
if (!peerDeps) continue;
|
|
302
|
+
const devDeps = pkg.devDependencies;
|
|
303
|
+
for (const [dep, version] of Object.entries(peerDeps)) {
|
|
304
|
+
const targetVersion = workspaceVersions.get(dep);
|
|
305
|
+
if (!targetVersion) continue;
|
|
306
|
+
if (version.startsWith("workspace:")) {
|
|
307
|
+
const expected2 = expectedPeerRange(devDeps?.[dep], targetVersion);
|
|
308
|
+
result.fixable.push(
|
|
309
|
+
`${name} (${location}) peerDependencies.${dep} uses workspace: protocol \u2014 should be "${expected2}"`
|
|
310
|
+
);
|
|
311
|
+
continue;
|
|
312
|
+
}
|
|
313
|
+
const expected = expectedPeerRange(devDeps?.[dep], targetVersion);
|
|
314
|
+
if (version !== expected && !semver.satisfies(targetVersion, version)) {
|
|
315
|
+
result.fixable.push(
|
|
316
|
+
`${name} (${location}) peerDependencies.${dep} is "${version}" \u2014 current version ${targetVersion} is not satisfied; expected "${expected}"`
|
|
317
|
+
);
|
|
318
|
+
}
|
|
319
|
+
}
|
|
320
|
+
}
|
|
321
|
+
return result;
|
|
322
|
+
}
|
|
323
|
+
function fixInternalPeerVersions(cwd, workspaces) {
|
|
324
|
+
const workspaceVersions = buildWorkspaceVersionMap(cwd, workspaces);
|
|
325
|
+
for (const { location, name } of workspaces) {
|
|
326
|
+
const pkg = readWorkspacePackageJson(cwd, location);
|
|
327
|
+
if (!pkg) continue;
|
|
328
|
+
const peerDeps = pkg.peerDependencies;
|
|
329
|
+
if (!peerDeps) continue;
|
|
330
|
+
const devDeps = pkg.devDependencies;
|
|
331
|
+
let modified = false;
|
|
332
|
+
for (const [dep, version] of Object.entries(peerDeps)) {
|
|
333
|
+
const targetVersion = workspaceVersions.get(dep);
|
|
334
|
+
if (!targetVersion) continue;
|
|
335
|
+
const expected = expectedPeerRange(devDeps?.[dep], targetVersion);
|
|
336
|
+
if (version !== expected) {
|
|
337
|
+
peerDeps[dep] = expected;
|
|
338
|
+
console.log(chalk2.green(` \u2714 Fixed: set peerDependencies.${dep} to "${expected}" in ${name} (${location})`));
|
|
339
|
+
modified = true;
|
|
340
|
+
}
|
|
341
|
+
}
|
|
342
|
+
if (modified) {
|
|
343
|
+
writeWorkspacePackageJson(cwd, location, pkg);
|
|
344
|
+
}
|
|
345
|
+
}
|
|
346
|
+
}
|
|
347
|
+
|
|
348
|
+
// src/actions/package-lint.ts
|
|
349
|
+
function emptyResult() {
|
|
350
|
+
return {
|
|
351
|
+
errors: [],
|
|
352
|
+
fixable: [],
|
|
353
|
+
warnings: []
|
|
354
|
+
};
|
|
355
|
+
}
|
|
356
|
+
function readRootPackageJson(cwd) {
|
|
357
|
+
const raw = readFileSync2(PATH2.resolve(cwd, "package.json"), "utf8");
|
|
358
|
+
return JSON.parse(raw);
|
|
359
|
+
}
|
|
360
|
+
function writeRootPackageJson(cwd, pkg) {
|
|
361
|
+
const path = PATH2.resolve(cwd, "package.json");
|
|
362
|
+
writeFileSync2(path, `${JSON.stringify(pkg, null, 2)}
|
|
363
|
+
`, "utf8");
|
|
364
|
+
}
|
|
365
|
+
function readPnpmWorkspaceGlobs(cwd) {
|
|
366
|
+
const wsPath = PATH2.resolve(cwd, "pnpm-workspace.yaml");
|
|
367
|
+
if (!existsSync2(wsPath)) return void 0;
|
|
368
|
+
const raw = readFileSync2(wsPath, "utf8");
|
|
369
|
+
const globs = [];
|
|
370
|
+
let inPackages = false;
|
|
371
|
+
for (const line of raw.split("\n")) {
|
|
372
|
+
if (/^packages\s*:/.test(line)) {
|
|
373
|
+
inPackages = true;
|
|
374
|
+
continue;
|
|
375
|
+
}
|
|
376
|
+
if (inPackages) {
|
|
377
|
+
const match = /^\s+-\s+['"]?([^'"]+)['"]?\s*$/.exec(line);
|
|
378
|
+
if (match) {
|
|
379
|
+
globs.push(match[1]);
|
|
380
|
+
} else if (/^\S/.test(line) && line.trim() !== "") {
|
|
381
|
+
break;
|
|
382
|
+
}
|
|
383
|
+
}
|
|
384
|
+
}
|
|
385
|
+
return globs.length > 0 ? globs : void 0;
|
|
386
|
+
}
|
|
387
|
+
function isMonorepo(pkg, cwd) {
|
|
388
|
+
const workspaces = pkg.workspaces;
|
|
389
|
+
if (Array.isArray(workspaces) && workspaces.length > 0) return true;
|
|
390
|
+
return readPnpmWorkspaceGlobs(cwd) !== void 0;
|
|
391
|
+
}
|
|
392
|
+
function checkPackagesFolder(workspaces) {
|
|
393
|
+
const result = emptyResult();
|
|
394
|
+
for (const { location, name } of workspaces) {
|
|
395
|
+
if (location === ".") continue;
|
|
396
|
+
if (!location.startsWith("packages/") && !location.startsWith("packages\\")) {
|
|
397
|
+
result.errors.push(`${name} (${location}) is not inside a packages/ folder`);
|
|
398
|
+
}
|
|
399
|
+
}
|
|
400
|
+
return result;
|
|
401
|
+
}
|
|
402
|
+
function checkRootPrivate(pkg) {
|
|
403
|
+
const result = emptyResult();
|
|
404
|
+
if (!pkg.private) {
|
|
405
|
+
result.fixable.push("Root package.json must be private to prevent accidental publishing");
|
|
406
|
+
}
|
|
407
|
+
return result;
|
|
408
|
+
}
|
|
409
|
+
function fixRootPrivate(cwd, pkg) {
|
|
410
|
+
pkg.private = true;
|
|
411
|
+
writeRootPackageJson(cwd, pkg);
|
|
412
|
+
console.log(chalk3.green(' \u2714 Fixed: set "private": true in root package.json'));
|
|
413
|
+
}
|
|
414
|
+
function checkNoPublishConfigOnPrivate(pkg) {
|
|
415
|
+
const result = emptyResult();
|
|
416
|
+
if (pkg.private && pkg.publishConfig) {
|
|
417
|
+
result.fixable.push("Root package.json has publishConfig but is private \u2014 publishConfig is unnecessary");
|
|
418
|
+
}
|
|
419
|
+
return result;
|
|
420
|
+
}
|
|
421
|
+
function fixNoPublishConfigOnPrivate(cwd, pkg) {
|
|
422
|
+
delete pkg.publishConfig;
|
|
423
|
+
writeRootPackageJson(cwd, pkg);
|
|
424
|
+
console.log(chalk3.green(" \u2714 Fixed: removed publishConfig from private root package.json"));
|
|
425
|
+
}
|
|
426
|
+
function checkNoPackageManagerInWorkspaces(cwd, workspaces) {
|
|
427
|
+
const result = emptyResult();
|
|
428
|
+
for (const { location, name } of workspaces) {
|
|
429
|
+
if (location === ".") continue;
|
|
430
|
+
const pkgPath = PATH2.resolve(cwd, location, "package.json");
|
|
431
|
+
try {
|
|
432
|
+
const raw = readFileSync2(pkgPath, "utf8");
|
|
433
|
+
const pkg = JSON.parse(raw);
|
|
434
|
+
if (pkg.packageManager) {
|
|
435
|
+
result.fixable.push(`${name} (${location}) has a packageManager field \u2014 only the root should define this`);
|
|
436
|
+
}
|
|
437
|
+
} catch {
|
|
438
|
+
}
|
|
439
|
+
}
|
|
440
|
+
return result;
|
|
441
|
+
}
|
|
442
|
+
function fixNoPackageManagerInWorkspaces(cwd, _pkg, workspaces) {
|
|
443
|
+
for (const { location } of workspaces) {
|
|
444
|
+
if (location === ".") continue;
|
|
445
|
+
const pkgPath = PATH2.resolve(cwd, location, "package.json");
|
|
446
|
+
try {
|
|
447
|
+
const raw = readFileSync2(pkgPath, "utf8");
|
|
448
|
+
const pkg = JSON.parse(raw);
|
|
449
|
+
if (pkg.packageManager) {
|
|
450
|
+
delete pkg.packageManager;
|
|
451
|
+
writeFileSync2(pkgPath, `${JSON.stringify(pkg, null, 2)}
|
|
452
|
+
`, "utf8");
|
|
453
|
+
console.log(chalk3.green(` \u2714 Fixed: removed packageManager from ${location}/package.json`));
|
|
454
|
+
}
|
|
455
|
+
} catch {
|
|
456
|
+
}
|
|
457
|
+
}
|
|
458
|
+
}
|
|
459
|
+
function checkWorkspacesFieldPlacement(cwd, pm, workspaces) {
|
|
460
|
+
const result = emptyResult();
|
|
461
|
+
for (const { location, name } of workspaces) {
|
|
462
|
+
if (pm === "pnpm" ? true : location !== ".") {
|
|
463
|
+
const pkgPath = PATH2.resolve(cwd, location, "package.json");
|
|
464
|
+
try {
|
|
465
|
+
const pkg = JSON.parse(readFileSync2(pkgPath, "utf8"));
|
|
466
|
+
if (pkg.workspaces) {
|
|
467
|
+
const label = location === "." ? "Root" : `${name} (${location})`;
|
|
468
|
+
const reason = pm === "pnpm" ? "pnpm uses pnpm-workspace.yaml instead" : "only the root should define workspaces";
|
|
469
|
+
result.fixable.push(`${label} has a workspaces field \u2014 ${reason}`);
|
|
470
|
+
}
|
|
471
|
+
} catch {
|
|
472
|
+
}
|
|
473
|
+
}
|
|
474
|
+
}
|
|
475
|
+
return result;
|
|
476
|
+
}
|
|
477
|
+
function fixWorkspacesFieldPlacement(cwd, pm, workspaces) {
|
|
478
|
+
for (const { location } of workspaces) {
|
|
479
|
+
if (pm === "pnpm" ? true : location !== ".") {
|
|
480
|
+
const pkgPath = PATH2.resolve(cwd, location, "package.json");
|
|
481
|
+
try {
|
|
482
|
+
const pkg = JSON.parse(readFileSync2(pkgPath, "utf8"));
|
|
483
|
+
if (pkg.workspaces) {
|
|
484
|
+
delete pkg.workspaces;
|
|
485
|
+
writeFileSync2(pkgPath, `${JSON.stringify(pkg, null, 2)}
|
|
486
|
+
`, "utf8");
|
|
487
|
+
const label = location === "." ? "root" : location;
|
|
488
|
+
console.log(chalk3.green(` \u2714 Fixed: removed workspaces from ${label}/package.json`));
|
|
489
|
+
}
|
|
490
|
+
} catch {
|
|
491
|
+
}
|
|
492
|
+
}
|
|
493
|
+
}
|
|
494
|
+
}
|
|
495
|
+
function checkWorkspaceGlobCoverage(pkg, cwd, pm, workspaces) {
|
|
496
|
+
const result = emptyResult();
|
|
497
|
+
const globs = pm === "pnpm" ? readPnpmWorkspaceGlobs(cwd) ?? [] : Array.isArray(pkg.workspaces) ? pkg.workspaces : [];
|
|
498
|
+
if (globs.length === 0) {
|
|
499
|
+
const source = pm === "pnpm" ? "pnpm-workspace.yaml" : "root package.json workspaces";
|
|
500
|
+
result.errors.push(`No workspace globs found in ${source}`);
|
|
501
|
+
return result;
|
|
502
|
+
}
|
|
503
|
+
const matchers = globs.map((glob) => picomatch(glob));
|
|
504
|
+
const isMatch = (location) => matchers.some((m) => m(location));
|
|
505
|
+
for (const { location, name } of workspaces) {
|
|
506
|
+
if (location === ".") continue;
|
|
507
|
+
if (!isMatch(location)) {
|
|
508
|
+
const source = pm === "pnpm" ? "pnpm-workspace.yaml" : "root package.json workspaces";
|
|
509
|
+
result.errors.push(`${name} (${location}) is not matched by any glob in ${source}`);
|
|
510
|
+
}
|
|
511
|
+
}
|
|
512
|
+
return result;
|
|
513
|
+
}
|
|
514
|
+
function logResults(label, result, fix) {
|
|
515
|
+
let errors = 0;
|
|
516
|
+
let fixed = 0;
|
|
517
|
+
for (const error of result.errors) {
|
|
518
|
+
console.log(chalk3.red(` \u2717 ${error}`));
|
|
519
|
+
errors++;
|
|
520
|
+
}
|
|
521
|
+
for (const fixable of result.fixable) {
|
|
522
|
+
if (fix) {
|
|
523
|
+
fixed++;
|
|
524
|
+
} else {
|
|
525
|
+
console.log(chalk3.red(` \u2717 ${fixable} (fixable)`));
|
|
526
|
+
errors++;
|
|
527
|
+
}
|
|
528
|
+
}
|
|
529
|
+
for (const warning of result.warnings) {
|
|
530
|
+
console.log(chalk3.yellow(` \u26A0 ${warning}`));
|
|
531
|
+
}
|
|
532
|
+
if (errors === 0 && fixed === 0 && result.warnings.length === 0) {
|
|
533
|
+
console.log(chalk3.green(` \u2713 ${label}`));
|
|
534
|
+
}
|
|
535
|
+
return { errors, fixed };
|
|
536
|
+
}
|
|
537
|
+
function runChecks(entries, cwd, pkg, fix) {
|
|
538
|
+
let totalErrors = 0;
|
|
539
|
+
let totalFixed = 0;
|
|
540
|
+
for (const entry of entries) {
|
|
541
|
+
const result = entry.check();
|
|
542
|
+
const log = logResults(entry.label, result, fix);
|
|
543
|
+
if (fix && entry.fix && result.fixable.length > 0) {
|
|
544
|
+
entry.fix(cwd, pkg);
|
|
545
|
+
}
|
|
546
|
+
totalErrors += log.errors;
|
|
547
|
+
totalFixed += log.fixed;
|
|
548
|
+
}
|
|
549
|
+
return { errors: totalErrors, fixed: totalFixed };
|
|
550
|
+
}
|
|
551
|
+
function checkVoltaOnlyInRoot(cwd, workspaces) {
|
|
552
|
+
const result = emptyResult();
|
|
553
|
+
for (const { location, name } of workspaces) {
|
|
554
|
+
if (location === ".") continue;
|
|
555
|
+
const pkgPath = PATH2.resolve(cwd, location, "package.json");
|
|
556
|
+
try {
|
|
557
|
+
const pkg = JSON.parse(readFileSync2(pkgPath, "utf8"));
|
|
558
|
+
if (pkg.volta) {
|
|
559
|
+
result.fixable.push(`${name} (${location}) has a volta field \u2014 only the root should define this`);
|
|
560
|
+
}
|
|
561
|
+
} catch {
|
|
562
|
+
}
|
|
563
|
+
}
|
|
564
|
+
return result;
|
|
565
|
+
}
|
|
566
|
+
function fixVoltaOnlyInRoot(cwd, _pkg, workspaces) {
|
|
567
|
+
for (const { location } of workspaces) {
|
|
568
|
+
if (location === ".") continue;
|
|
569
|
+
const pkgPath = PATH2.resolve(cwd, location, "package.json");
|
|
570
|
+
try {
|
|
571
|
+
const raw = readFileSync2(pkgPath, "utf8");
|
|
572
|
+
const pkg = JSON.parse(raw);
|
|
573
|
+
if (pkg.volta) {
|
|
574
|
+
delete pkg.volta;
|
|
575
|
+
writeFileSync2(pkgPath, `${JSON.stringify(pkg, null, 2)}
|
|
576
|
+
`, "utf8");
|
|
577
|
+
console.log(chalk3.green(` \u2714 Fixed: removed volta from ${location}/package.json`));
|
|
578
|
+
}
|
|
579
|
+
} catch {
|
|
580
|
+
}
|
|
581
|
+
}
|
|
582
|
+
}
|
|
583
|
+
function isTerminalPackage(pkg) {
|
|
584
|
+
return pkg.private === true;
|
|
585
|
+
}
|
|
586
|
+
function checkEnginesOnlyInNonTerminal(cwd, workspaces) {
|
|
587
|
+
const result = emptyResult();
|
|
588
|
+
const rootPkg = JSON.parse(readFileSync2(PATH2.resolve(cwd, "package.json"), "utf8"));
|
|
589
|
+
if (rootPkg.engines) {
|
|
590
|
+
result.fixable.push("Root package.json has engines \u2014 terminal packages should not declare engines (use volta instead)");
|
|
591
|
+
}
|
|
592
|
+
for (const { location, name } of workspaces) {
|
|
593
|
+
if (location === ".") continue;
|
|
594
|
+
const pkgPath = PATH2.resolve(cwd, location, "package.json");
|
|
595
|
+
try {
|
|
596
|
+
const pkg = JSON.parse(readFileSync2(pkgPath, "utf8"));
|
|
597
|
+
if (isTerminalPackage(pkg) && pkg.engines) {
|
|
598
|
+
result.fixable.push(`${name} (${location}) is terminal (private) but has engines \u2014 terminal packages should not declare engines`);
|
|
599
|
+
}
|
|
600
|
+
if (!isTerminalPackage(pkg) && !pkg.engines) {
|
|
601
|
+
result.fixable.push(`${name} (${location}) is a library but has no engines field`);
|
|
602
|
+
}
|
|
603
|
+
} catch {
|
|
604
|
+
}
|
|
605
|
+
}
|
|
606
|
+
return result;
|
|
607
|
+
}
|
|
608
|
+
function fixEnginesOnlyInNonTerminal(cwd, _pkg, workspaces) {
|
|
609
|
+
const rootPath = PATH2.resolve(cwd, "package.json");
|
|
610
|
+
const rootRaw = readFileSync2(rootPath, "utf8");
|
|
611
|
+
const rootPkg = JSON.parse(rootRaw);
|
|
612
|
+
if (rootPkg.engines) {
|
|
613
|
+
delete rootPkg.engines;
|
|
614
|
+
writeFileSync2(rootPath, `${JSON.stringify(rootPkg, null, 2)}
|
|
615
|
+
`, "utf8");
|
|
616
|
+
console.log(chalk3.green(" \u2714 Fixed: removed engines from root package.json"));
|
|
617
|
+
}
|
|
618
|
+
const enginesTemplate = resolveEnginesTemplate(cwd, workspaces);
|
|
619
|
+
for (const { location } of workspaces) {
|
|
620
|
+
if (location === ".") continue;
|
|
621
|
+
const pkgPath = PATH2.resolve(cwd, location, "package.json");
|
|
622
|
+
try {
|
|
623
|
+
const raw = readFileSync2(pkgPath, "utf8");
|
|
624
|
+
const pkg = JSON.parse(raw);
|
|
625
|
+
if (isTerminalPackage(pkg) && pkg.engines) {
|
|
626
|
+
delete pkg.engines;
|
|
627
|
+
writeFileSync2(pkgPath, `${JSON.stringify(pkg, null, 2)}
|
|
628
|
+
`, "utf8");
|
|
629
|
+
console.log(chalk3.green(` \u2714 Fixed: removed engines from ${location}/package.json`));
|
|
630
|
+
}
|
|
631
|
+
if (!isTerminalPackage(pkg) && !pkg.engines && enginesTemplate) {
|
|
632
|
+
pkg.engines = enginesTemplate;
|
|
633
|
+
writeFileSync2(pkgPath, `${JSON.stringify(pkg, null, 2)}
|
|
634
|
+
`, "utf8");
|
|
635
|
+
console.log(chalk3.green(` \u2714 Fixed: added engines to ${location}/package.json`));
|
|
636
|
+
}
|
|
637
|
+
} catch {
|
|
638
|
+
}
|
|
639
|
+
}
|
|
640
|
+
}
|
|
641
|
+
function resolveEnginesTemplate(cwd, workspaces) {
|
|
642
|
+
for (const { location } of workspaces) {
|
|
643
|
+
if (location === ".") continue;
|
|
644
|
+
try {
|
|
645
|
+
const pkg = JSON.parse(readFileSync2(PATH2.resolve(cwd, location, "package.json"), "utf8"));
|
|
646
|
+
if (!isTerminalPackage(pkg) && pkg.engines) {
|
|
647
|
+
return pkg.engines;
|
|
648
|
+
}
|
|
649
|
+
} catch {
|
|
650
|
+
}
|
|
651
|
+
}
|
|
652
|
+
return void 0;
|
|
653
|
+
}
|
|
654
|
+
function checkVersionsIncludeLts(cwd, workspaces) {
|
|
655
|
+
const result = emptyResult();
|
|
656
|
+
const toolVersions = {
|
|
657
|
+
node: latestVersions.node,
|
|
658
|
+
npm: latestVersions.npm,
|
|
659
|
+
pnpm: latestVersions.pnpm,
|
|
660
|
+
yarn: latestVersions.yarn
|
|
661
|
+
};
|
|
662
|
+
for (const { location, name } of workspaces) {
|
|
663
|
+
const pkgPath = location === "." ? PATH2.resolve(cwd, "package.json") : PATH2.resolve(cwd, location, "package.json");
|
|
664
|
+
try {
|
|
665
|
+
const pkg = JSON.parse(readFileSync2(pkgPath, "utf8"));
|
|
666
|
+
const label = location === "." ? "root" : `${name} (${location})`;
|
|
667
|
+
const engines = pkg.engines;
|
|
668
|
+
if (engines) {
|
|
669
|
+
for (const [tool, range] of Object.entries(engines)) {
|
|
670
|
+
const latest = toolVersions[tool];
|
|
671
|
+
if (latest && !semver2.satisfies(latest, range)) {
|
|
672
|
+
result.errors.push(
|
|
673
|
+
`${label} engines.${tool} "${range}" does not include latest ${tool === "node" ? "LTS " : ""}version ${latest}`
|
|
674
|
+
);
|
|
675
|
+
}
|
|
676
|
+
}
|
|
677
|
+
}
|
|
678
|
+
const volta = pkg.volta;
|
|
679
|
+
if (volta) {
|
|
680
|
+
for (const [tool, pinnedVersion] of Object.entries(volta)) {
|
|
681
|
+
const latest = toolVersions[tool];
|
|
682
|
+
if (latest && semver2.lt(pinnedVersion, latest)) {
|
|
683
|
+
result.warnings.push(
|
|
684
|
+
`${label} volta.${tool} "${pinnedVersion}" is older than latest ${tool === "node" ? "LTS " : ""}version ${latest}`
|
|
685
|
+
);
|
|
686
|
+
}
|
|
687
|
+
}
|
|
688
|
+
}
|
|
689
|
+
} catch {
|
|
690
|
+
}
|
|
691
|
+
}
|
|
692
|
+
return result;
|
|
693
|
+
}
|
|
694
|
+
function logSummary(errors, fixed) {
|
|
695
|
+
if (fixed > 0) {
|
|
696
|
+
console.log(chalk3.green(`
|
|
697
|
+
Fixed ${fixed} issue(s)`));
|
|
698
|
+
}
|
|
699
|
+
if (errors > 0) {
|
|
700
|
+
console.log(chalk3.red(`
|
|
701
|
+
${errors} error(s) found`));
|
|
702
|
+
} else if (fixed === 0) {
|
|
703
|
+
console.log(chalk3.green("\n All checks passed"));
|
|
704
|
+
}
|
|
705
|
+
}
|
|
706
|
+
function packageLintMonorepo(fix = false) {
|
|
707
|
+
const cwd = INIT_CWD();
|
|
708
|
+
let pkg;
|
|
709
|
+
try {
|
|
710
|
+
pkg = readRootPackageJson(cwd);
|
|
711
|
+
} catch {
|
|
712
|
+
console.error(chalk3.red("Could not read package.json"));
|
|
713
|
+
return 1;
|
|
714
|
+
}
|
|
715
|
+
if (!isMonorepo(pkg, cwd)) {
|
|
716
|
+
console.log(chalk3.gray("Not a monorepo \u2014 skipping repo lint checks"));
|
|
717
|
+
return 0;
|
|
718
|
+
}
|
|
719
|
+
console.log(chalk3.green("Repo Lint"));
|
|
720
|
+
const pm = detectPackageManager();
|
|
721
|
+
const workspaces = getPackageManager().listWorkspaces();
|
|
722
|
+
const internalDepCheck = pm === "pnpm" ? {
|
|
723
|
+
check: () => checkWorkspaceProtocol(cwd, workspaces),
|
|
724
|
+
fix: () => fixWorkspaceProtocol(cwd, workspaces),
|
|
725
|
+
label: "Internal deps/devDeps use workspace: protocol"
|
|
726
|
+
} : {
|
|
727
|
+
check: () => checkInternalDepVersions(cwd, workspaces),
|
|
728
|
+
fix: () => fixInternalDepVersions(cwd, workspaces),
|
|
729
|
+
label: "Internal deps/devDeps use correct version ranges"
|
|
730
|
+
};
|
|
731
|
+
const checks2 = [
|
|
732
|
+
{
|
|
733
|
+
check: () => checkRootPrivate(pkg),
|
|
734
|
+
fix: fixRootPrivate,
|
|
735
|
+
label: "Root package is private"
|
|
736
|
+
},
|
|
737
|
+
{
|
|
738
|
+
check: () => checkNoPublishConfigOnPrivate(pkg),
|
|
739
|
+
fix: fixNoPublishConfigOnPrivate,
|
|
740
|
+
label: "No publishConfig on private root"
|
|
741
|
+
},
|
|
742
|
+
{ check: () => checkPackagesFolder(workspaces), label: "All packages are in packages/ folder" },
|
|
743
|
+
{
|
|
744
|
+
check: () => checkWorkspacesFieldPlacement(cwd, pm, workspaces),
|
|
745
|
+
fix: () => fixWorkspacesFieldPlacement(cwd, pm, workspaces),
|
|
746
|
+
label: pm === "pnpm" ? "No workspaces field in package.json (use pnpm-workspace.yaml)" : "Workspaces field only in root package.json"
|
|
747
|
+
},
|
|
748
|
+
{
|
|
749
|
+
check: () => checkWorkspaceGlobCoverage(pkg, cwd, pm, workspaces),
|
|
750
|
+
label: "Workspace globs cover all packages"
|
|
751
|
+
},
|
|
752
|
+
{
|
|
753
|
+
check: () => checkNoPackageManagerInWorkspaces(cwd, workspaces),
|
|
754
|
+
fix: () => fixNoPackageManagerInWorkspaces(cwd, pkg, workspaces),
|
|
755
|
+
label: "No packageManager in workspace packages"
|
|
756
|
+
},
|
|
757
|
+
{
|
|
758
|
+
check: () => checkVoltaOnlyInRoot(cwd, workspaces),
|
|
759
|
+
fix: () => fixVoltaOnlyInRoot(cwd, pkg, workspaces),
|
|
760
|
+
label: "Volta only in root package.json"
|
|
761
|
+
},
|
|
762
|
+
{
|
|
763
|
+
check: () => checkEnginesOnlyInNonTerminal(cwd, workspaces),
|
|
764
|
+
fix: () => fixEnginesOnlyInNonTerminal(cwd, pkg, workspaces),
|
|
765
|
+
label: "Engines only in non-terminal (library) packages"
|
|
766
|
+
},
|
|
767
|
+
{
|
|
768
|
+
check: () => checkVersionsIncludeLts(cwd, workspaces),
|
|
769
|
+
label: "Engine/volta versions include latest LTS"
|
|
770
|
+
},
|
|
771
|
+
{
|
|
772
|
+
check: () => checkVersionConsistency(cwd, pkg, workspaces),
|
|
773
|
+
fix: () => fixVersionConsistency(cwd, pkg, writeRootPackageJson, workspaces),
|
|
774
|
+
label: "Consistent versions across packages"
|
|
775
|
+
},
|
|
776
|
+
internalDepCheck,
|
|
777
|
+
{
|
|
778
|
+
check: () => checkInternalPeerVersions(cwd, workspaces),
|
|
779
|
+
fix: () => fixInternalPeerVersions(cwd, workspaces),
|
|
780
|
+
label: "Internal peerDeps use semver ranges (not workspace: protocol)"
|
|
781
|
+
}
|
|
782
|
+
];
|
|
783
|
+
const { errors, fixed } = runChecks(checks2, cwd, pkg, fix);
|
|
784
|
+
logSummary(errors, fixed);
|
|
785
|
+
if (fix && fixed > 0) {
|
|
786
|
+
runInstall();
|
|
787
|
+
}
|
|
788
|
+
return errors > 0 ? 1 : 0;
|
|
789
|
+
}
|
|
790
|
+
|
|
791
|
+
// src/actions/packman/convertToPnpm.ts
|
|
792
|
+
import { spawnSync as spawnSync2 } from "child_process";
|
|
793
|
+
import {
|
|
794
|
+
existsSync as existsSync5,
|
|
795
|
+
mkdirSync,
|
|
796
|
+
readFileSync as readFileSync5,
|
|
797
|
+
rmSync,
|
|
798
|
+
writeFileSync as writeFileSync5
|
|
799
|
+
} from "fs";
|
|
800
|
+
import PATH4 from "path";
|
|
801
|
+
import chalk6 from "chalk";
|
|
802
|
+
|
|
803
|
+
// src/actions/packman/rewriteScripts.ts
|
|
804
|
+
function rewriteYarnToPnpm(script) {
|
|
805
|
+
let result = script;
|
|
806
|
+
result = result.replaceAll(/\byarn workspace (\S+) run /g, "pnpm --filter $1 run ");
|
|
807
|
+
result = result.replaceAll(/\byarn workspace (\S+) (package-\S+)/g, "pnpm --filter $1 run $2");
|
|
808
|
+
result = result.replaceAll(/\byarn workspaces foreach\s+(?:[^\s]*\s+)*run /g, "pnpm -r run ");
|
|
809
|
+
result = result.replaceAll(/\byarn workspaces foreach --all version (\S+) --deferred/g, "pnpm -r exec npm version $1 --no-git-tag-version");
|
|
810
|
+
result = result.replaceAll(/\byarn version apply --all/g, 'echo "versions applied"');
|
|
811
|
+
result = result.replaceAll(/\byarn xy\b/g, "pnpm xy");
|
|
812
|
+
result = result.replaceAll(/\byarn add\b/g, "pnpm add");
|
|
813
|
+
result = result.replaceAll(/\byarn remove\b/g, "pnpm remove");
|
|
814
|
+
result = result.replaceAll(/\byarn install\b/g, "pnpm install");
|
|
815
|
+
result = result.replaceAll(/\byarn dedupe\b/g, "pnpm dedupe");
|
|
816
|
+
result = result.replaceAll(/\byarn outdated\b/g, "pnpm outdated");
|
|
817
|
+
result = result.replaceAll(/\byarn run\b/g, "pnpm run");
|
|
818
|
+
result = result.replaceAll(/\byarn rimraf\b/g, "rimraf");
|
|
819
|
+
result = result.replaceAll(/\byarn npm\b/g, "npm");
|
|
820
|
+
result = result.replaceAll(/\byarn\b(?![@/.])/g, "pnpm");
|
|
821
|
+
return result;
|
|
822
|
+
}
|
|
823
|
+
function rewritePnpmToYarn(script) {
|
|
824
|
+
let result = script;
|
|
825
|
+
result = result.replaceAll(/\bpnpm --filter (\S+) run /g, "yarn workspace $1 run ");
|
|
826
|
+
result = result.replaceAll(/\bpnpm -r run /g, "yarn workspaces foreach -Apt run ");
|
|
827
|
+
result = result.replaceAll(/\bpnpm -r exec npm version (\S+) --no-git-tag-version/g, "yarn workspaces foreach --all version $1 --deferred");
|
|
828
|
+
result = result.replaceAll(/\bpnpm xy\b/g, "yarn xy");
|
|
829
|
+
result = result.replaceAll(/\bpnpm add\b/g, "yarn add");
|
|
830
|
+
result = result.replaceAll(/\bpnpm remove\b/g, "yarn remove");
|
|
831
|
+
result = result.replaceAll(/\bpnpm install\b/g, "yarn install");
|
|
832
|
+
result = result.replaceAll(/\bpnpm dedupe\b/g, "yarn dedupe");
|
|
833
|
+
result = result.replaceAll(/\bpnpm outdated\b/g, "yarn outdated");
|
|
834
|
+
result = result.replaceAll(/\bpnpm run\b/g, "yarn run");
|
|
835
|
+
result = result.replaceAll(/\bpnpm\b(?![@/.])/g, "yarn");
|
|
836
|
+
return result;
|
|
837
|
+
}
|
|
838
|
+
function rewriteScript(script, direction) {
|
|
839
|
+
return direction === "yarn-to-pnpm" ? rewriteYarnToPnpm(script) : rewritePnpmToYarn(script);
|
|
840
|
+
}
|
|
841
|
+
function rewriteScriptsInPackageJson(pkg, direction) {
|
|
842
|
+
const scripts = pkg.scripts;
|
|
843
|
+
if (!scripts) return pkg;
|
|
844
|
+
const rewritten = {};
|
|
845
|
+
for (const [name, script] of Object.entries(scripts)) {
|
|
846
|
+
rewritten[name] = rewriteScript(script, direction);
|
|
847
|
+
}
|
|
848
|
+
return { ...pkg, scripts: rewritten };
|
|
849
|
+
}
|
|
850
|
+
|
|
851
|
+
// src/actions/packman/rewriteSourceImports.ts
|
|
852
|
+
import {
|
|
853
|
+
existsSync as existsSync3,
|
|
854
|
+
readFileSync as readFileSync3,
|
|
855
|
+
writeFileSync as writeFileSync3
|
|
856
|
+
} from "fs";
|
|
857
|
+
import chalk4 from "chalk";
|
|
858
|
+
import { globSync } from "glob";
|
|
859
|
+
var IMPORT_SWAP_MAP = {
|
|
860
|
+
"yarn-to-pnpm": [
|
|
861
|
+
["@xylabs/ts-scripts-yarn3", "@xylabs/ts-scripts-pnpm"],
|
|
862
|
+
["@xylabs/ts-scripts-react-yarn3", "@xylabs/ts-scripts-react-pnpm"]
|
|
863
|
+
],
|
|
864
|
+
"pnpm-to-yarn": [
|
|
865
|
+
["@xylabs/ts-scripts-pnpm", "@xylabs/ts-scripts-yarn3"],
|
|
866
|
+
["@xylabs/ts-scripts-react-pnpm", "@xylabs/ts-scripts-react-yarn3"]
|
|
867
|
+
]
|
|
868
|
+
};
|
|
869
|
+
var SOURCE_GLOBS = [
|
|
870
|
+
"**/*.ts",
|
|
871
|
+
"**/*.tsx",
|
|
872
|
+
"**/*.mts",
|
|
873
|
+
"**/*.cts",
|
|
874
|
+
"**/*.js",
|
|
875
|
+
"**/*.mjs"
|
|
876
|
+
];
|
|
877
|
+
var IGNORE_PATTERNS = [
|
|
878
|
+
"**/node_modules/**",
|
|
879
|
+
"**/dist/**",
|
|
880
|
+
"**/build/**",
|
|
881
|
+
"**/.yarn/**"
|
|
882
|
+
];
|
|
883
|
+
function rewriteSourceImports(cwd, direction) {
|
|
884
|
+
const swaps = IMPORT_SWAP_MAP[direction];
|
|
885
|
+
const files = globSync(SOURCE_GLOBS, {
|
|
886
|
+
cwd,
|
|
887
|
+
absolute: true,
|
|
888
|
+
ignore: IGNORE_PATTERNS
|
|
889
|
+
});
|
|
890
|
+
let count = 0;
|
|
891
|
+
for (const file of files) {
|
|
892
|
+
if (!existsSync3(file)) continue;
|
|
893
|
+
const original = readFileSync3(file, "utf8");
|
|
894
|
+
let content = original;
|
|
895
|
+
for (const [from, to] of swaps) {
|
|
896
|
+
content = content.replaceAll(from, to);
|
|
897
|
+
}
|
|
898
|
+
if (content !== original) {
|
|
899
|
+
writeFileSync3(file, content, "utf8");
|
|
900
|
+
count++;
|
|
901
|
+
}
|
|
902
|
+
}
|
|
903
|
+
if (count > 0) {
|
|
904
|
+
console.log(chalk4.green(` Rewrote ts-scripts imports in ${count} source file(s)`));
|
|
905
|
+
}
|
|
906
|
+
}
|
|
907
|
+
|
|
908
|
+
// src/actions/packman/swapTsScriptsDependency.ts
|
|
909
|
+
import {
|
|
910
|
+
existsSync as existsSync4,
|
|
911
|
+
readFileSync as readFileSync4,
|
|
912
|
+
writeFileSync as writeFileSync4
|
|
913
|
+
} from "fs";
|
|
914
|
+
import PATH3 from "path";
|
|
915
|
+
import chalk5 from "chalk";
|
|
916
|
+
var SWAP_MAP = {
|
|
917
|
+
"yarn-to-pnpm": [
|
|
918
|
+
["@xylabs/ts-scripts-yarn3", "@xylabs/ts-scripts-pnpm"]
|
|
919
|
+
],
|
|
920
|
+
"pnpm-to-yarn": [
|
|
921
|
+
["@xylabs/ts-scripts-pnpm", "@xylabs/ts-scripts-yarn3"]
|
|
922
|
+
]
|
|
923
|
+
};
|
|
924
|
+
function swapInPackageJson(pkgPath, direction) {
|
|
925
|
+
if (!existsSync4(pkgPath)) return false;
|
|
926
|
+
const raw = readFileSync4(pkgPath, "utf8");
|
|
927
|
+
const pkg = JSON.parse(raw);
|
|
928
|
+
let changed = false;
|
|
929
|
+
for (const depField of ["dependencies", "devDependencies"]) {
|
|
930
|
+
const deps = pkg[depField];
|
|
931
|
+
if (!deps) continue;
|
|
932
|
+
for (const [from, to] of SWAP_MAP[direction]) {
|
|
933
|
+
if (deps[from]) {
|
|
934
|
+
deps[to] = deps[from];
|
|
935
|
+
delete deps[from];
|
|
936
|
+
changed = true;
|
|
937
|
+
}
|
|
938
|
+
}
|
|
939
|
+
}
|
|
940
|
+
if (changed) {
|
|
941
|
+
writeFileSync4(pkgPath, JSON.stringify(pkg, null, 2) + "\n", "utf8");
|
|
942
|
+
}
|
|
943
|
+
return changed;
|
|
944
|
+
}
|
|
945
|
+
function swapTsScriptsDependency(cwd, workspacePackageJsonPaths, direction) {
|
|
946
|
+
let count = 0;
|
|
947
|
+
if (swapInPackageJson(PATH3.join(cwd, "package.json"), direction)) {
|
|
948
|
+
count++;
|
|
949
|
+
}
|
|
950
|
+
for (const pkgPath of workspacePackageJsonPaths) {
|
|
951
|
+
const fullPath = PATH3.resolve(cwd, pkgPath, "package.json");
|
|
952
|
+
if (swapInPackageJson(fullPath, direction)) {
|
|
953
|
+
count++;
|
|
954
|
+
}
|
|
955
|
+
}
|
|
956
|
+
if (count > 0) {
|
|
957
|
+
const target = direction === "yarn-to-pnpm" ? "@xylabs/ts-scripts-pnpm" : "@xylabs/ts-scripts-yarn3";
|
|
958
|
+
console.log(chalk5.green(` Swapped ts-scripts dependency to ${target} in ${count} package(s)`));
|
|
959
|
+
}
|
|
960
|
+
}
|
|
961
|
+
|
|
962
|
+
// src/actions/packman/convertToPnpm.ts
|
|
963
|
+
var PNPM_VERSION = "10.12.1";
|
|
964
|
+
function createPnpmWorkspaceYaml(cwd, workspacePatterns) {
|
|
965
|
+
const lines = ["packages:"];
|
|
966
|
+
for (const pattern of workspacePatterns) {
|
|
967
|
+
lines.push(` - '${pattern}'`);
|
|
968
|
+
}
|
|
969
|
+
writeFileSync5(PATH4.join(cwd, "pnpm-workspace.yaml"), lines.join("\n") + "\n", "utf8");
|
|
970
|
+
console.log(chalk6.green(" Created pnpm-workspace.yaml"));
|
|
971
|
+
}
|
|
972
|
+
function readPnpmWorkspacePatterns(cwd) {
|
|
973
|
+
const wsPath = PATH4.join(cwd, "pnpm-workspace.yaml");
|
|
974
|
+
if (!existsSync5(wsPath)) return [];
|
|
975
|
+
const content = readFileSync5(wsPath, "utf8");
|
|
976
|
+
const patterns = [];
|
|
977
|
+
const lines = content.split("\n");
|
|
978
|
+
let inPackages = false;
|
|
979
|
+
for (const line of lines) {
|
|
980
|
+
if (line.trim() === "packages:") {
|
|
981
|
+
inPackages = true;
|
|
982
|
+
continue;
|
|
983
|
+
}
|
|
984
|
+
if (inPackages && /^\s+-\s+/.test(line)) {
|
|
985
|
+
const pattern = line.replace(/^\s+-\s+/, "").replaceAll(/['"]/g, "").trim();
|
|
986
|
+
if (pattern) patterns.push(pattern);
|
|
987
|
+
} else if (inPackages && !/^\s/.test(line) && line.trim()) {
|
|
988
|
+
inPackages = false;
|
|
989
|
+
}
|
|
990
|
+
}
|
|
991
|
+
return patterns;
|
|
992
|
+
}
|
|
993
|
+
function updateRootPackageJson(cwd) {
|
|
994
|
+
const pkgPath = PATH4.join(cwd, "package.json");
|
|
995
|
+
const pkg = JSON.parse(readFileSync5(pkgPath, "utf8"));
|
|
996
|
+
const workspacePatterns = pkg.workspaces ?? readPnpmWorkspacePatterns(cwd);
|
|
997
|
+
delete pkg.workspaces;
|
|
998
|
+
pkg.packageManager = `pnpm@${PNPM_VERSION}`;
|
|
999
|
+
const updated = rewriteScriptsInPackageJson(pkg, "yarn-to-pnpm");
|
|
1000
|
+
writeFileSync5(pkgPath, JSON.stringify(updated, null, 2) + "\n", "utf8");
|
|
1001
|
+
console.log(chalk6.green(" Updated root package.json"));
|
|
1002
|
+
return workspacePatterns;
|
|
1003
|
+
}
|
|
1004
|
+
function updateGitignore(cwd) {
|
|
1005
|
+
const gitignorePath = PATH4.join(cwd, ".gitignore");
|
|
1006
|
+
if (!existsSync5(gitignorePath)) return;
|
|
1007
|
+
let content = readFileSync5(gitignorePath, "utf8");
|
|
1008
|
+
const yarnLines = [
|
|
1009
|
+
".pnp.*",
|
|
1010
|
+
".pnp",
|
|
1011
|
+
".yarn/*",
|
|
1012
|
+
"!.yarn/patches",
|
|
1013
|
+
"!.yarn/plugins",
|
|
1014
|
+
"!.yarn/releases",
|
|
1015
|
+
"!.yarn/sdks",
|
|
1016
|
+
"!.yarn/versions"
|
|
1017
|
+
];
|
|
1018
|
+
for (const line of yarnLines) {
|
|
1019
|
+
content = content.replaceAll(new RegExp(String.raw`^${line.replaceAll(".", String.raw`\.`).replaceAll("*", String.raw`\*`).replaceAll("!", String.raw`\!`)}\s*$`, "gm"), "");
|
|
1020
|
+
}
|
|
1021
|
+
content = content.replaceAll(/\n{3,}/g, "\n\n");
|
|
1022
|
+
writeFileSync5(gitignorePath, content, "utf8");
|
|
1023
|
+
console.log(chalk6.green(" Updated .gitignore"));
|
|
1024
|
+
}
|
|
1025
|
+
function deleteYarnArtifacts(cwd) {
|
|
1026
|
+
const yarnLock = PATH4.join(cwd, "yarn.lock");
|
|
1027
|
+
const yarnrc = PATH4.join(cwd, ".yarnrc.yml");
|
|
1028
|
+
const yarnDir = PATH4.join(cwd, ".yarn");
|
|
1029
|
+
if (existsSync5(yarnLock)) {
|
|
1030
|
+
rmSync(yarnLock);
|
|
1031
|
+
console.log(chalk6.gray(" Deleted yarn.lock"));
|
|
1032
|
+
}
|
|
1033
|
+
if (existsSync5(yarnrc)) {
|
|
1034
|
+
rmSync(yarnrc);
|
|
1035
|
+
console.log(chalk6.gray(" Deleted .yarnrc.yml"));
|
|
1036
|
+
}
|
|
1037
|
+
if (existsSync5(yarnDir)) {
|
|
1038
|
+
rmSync(yarnDir, { force: true, recursive: true });
|
|
1039
|
+
console.log(chalk6.gray(" Deleted .yarn/"));
|
|
1040
|
+
}
|
|
1041
|
+
}
|
|
1042
|
+
function createNpmrc(cwd) {
|
|
1043
|
+
const npmrcPath = PATH4.join(cwd, ".npmrc");
|
|
1044
|
+
if (existsSync5(npmrcPath)) return;
|
|
1045
|
+
mkdirSync(PATH4.dirname(npmrcPath), { recursive: true });
|
|
1046
|
+
writeFileSync5(npmrcPath, "", "utf8");
|
|
1047
|
+
console.log(chalk6.green(" Created .npmrc"));
|
|
1048
|
+
}
|
|
1049
|
+
function convertToPnpm(cwd, workspacePackageJsonPaths) {
|
|
1050
|
+
console.log(chalk6.blue("\nConverting to pnpm...\n"));
|
|
1051
|
+
const workspacePatterns = updateRootPackageJson(cwd);
|
|
1052
|
+
createPnpmWorkspaceYaml(cwd, workspacePatterns);
|
|
1053
|
+
for (const pkgPath of workspacePackageJsonPaths) {
|
|
1054
|
+
const fullPath = PATH4.resolve(cwd, pkgPath, "package.json");
|
|
1055
|
+
if (!existsSync5(fullPath)) continue;
|
|
1056
|
+
const pkg = JSON.parse(readFileSync5(fullPath, "utf8"));
|
|
1057
|
+
const updated = rewriteScriptsInPackageJson(pkg, "yarn-to-pnpm");
|
|
1058
|
+
if (JSON.stringify(pkg) !== JSON.stringify(updated)) {
|
|
1059
|
+
writeFileSync5(fullPath, JSON.stringify(updated, null, 2) + "\n", "utf8");
|
|
1060
|
+
}
|
|
1061
|
+
}
|
|
1062
|
+
console.log(chalk6.green(` Rewrote scripts in ${workspacePackageJsonPaths.length} workspace package(s)`));
|
|
1063
|
+
updateGitignore(cwd);
|
|
1064
|
+
createNpmrc(cwd);
|
|
1065
|
+
swapTsScriptsDependency(cwd, workspacePackageJsonPaths, "yarn-to-pnpm");
|
|
1066
|
+
rewriteSourceImports(cwd, "yarn-to-pnpm");
|
|
1067
|
+
deleteYarnArtifacts(cwd);
|
|
1068
|
+
console.log(chalk6.blue("\nRunning pnpm install..."));
|
|
1069
|
+
const install = spawnSync2("pnpm", ["install"], {
|
|
1070
|
+
cwd,
|
|
1071
|
+
encoding: "utf8",
|
|
1072
|
+
shell: true,
|
|
1073
|
+
stdio: "inherit"
|
|
1074
|
+
});
|
|
1075
|
+
if (install.status !== 0) {
|
|
1076
|
+
console.error(chalk6.red("pnpm install failed"));
|
|
1077
|
+
return 1;
|
|
1078
|
+
}
|
|
1079
|
+
console.log(chalk6.blue("\nConversion complete.\n"));
|
|
1080
|
+
return 0;
|
|
1081
|
+
}
|
|
1082
|
+
|
|
1083
|
+
// src/actions/packman/convertToYarn.ts
|
|
1084
|
+
import { spawnSync as spawnSync3 } from "child_process";
|
|
1085
|
+
import {
|
|
1086
|
+
existsSync as existsSync6,
|
|
1087
|
+
readFileSync as readFileSync6,
|
|
1088
|
+
rmSync as rmSync2,
|
|
1089
|
+
writeFileSync as writeFileSync6
|
|
1090
|
+
} from "fs";
|
|
1091
|
+
import PATH5 from "path";
|
|
1092
|
+
import chalk7 from "chalk";
|
|
1093
|
+
var YARN_VERSION = "4.13.0";
|
|
1094
|
+
var YARNRC_TEMPLATE = `compressionLevel: mixed
|
|
1095
|
+
|
|
1096
|
+
enableGlobalCache: true
|
|
1097
|
+
|
|
1098
|
+
enableInlineBuilds: true
|
|
1099
|
+
|
|
1100
|
+
nmHoistingLimits: none
|
|
1101
|
+
|
|
1102
|
+
nodeLinker: node-modules
|
|
1103
|
+
`;
|
|
1104
|
+
var YARN_GITIGNORE_ENTRIES = `
|
|
1105
|
+
.pnp.*
|
|
1106
|
+
.yarn/*
|
|
1107
|
+
!.yarn/patches
|
|
1108
|
+
!.yarn/plugins
|
|
1109
|
+
!.yarn/releases
|
|
1110
|
+
!.yarn/sdks
|
|
1111
|
+
!.yarn/versions
|
|
1112
|
+
`;
|
|
1113
|
+
function readPnpmWorkspacePatterns2(cwd) {
|
|
1114
|
+
const wsPath = PATH5.join(cwd, "pnpm-workspace.yaml");
|
|
1115
|
+
if (!existsSync6(wsPath)) return [];
|
|
1116
|
+
const content = readFileSync6(wsPath, "utf8");
|
|
1117
|
+
const patterns = [];
|
|
1118
|
+
const lines = content.split("\n");
|
|
1119
|
+
let inPackages = false;
|
|
1120
|
+
for (const line of lines) {
|
|
1121
|
+
if (line.trim() === "packages:") {
|
|
1122
|
+
inPackages = true;
|
|
1123
|
+
continue;
|
|
1124
|
+
}
|
|
1125
|
+
if (inPackages && /^\s+-\s+/.test(line)) {
|
|
1126
|
+
const pattern = line.replace(/^\s+-\s+/, "").replaceAll(/['"]/g, "").trim();
|
|
1127
|
+
if (pattern) patterns.push(pattern);
|
|
1128
|
+
} else if (inPackages && !/^\s/.test(line) && line.trim()) {
|
|
1129
|
+
inPackages = false;
|
|
1130
|
+
}
|
|
1131
|
+
}
|
|
1132
|
+
return patterns;
|
|
1133
|
+
}
|
|
1134
|
+
function updateRootPackageJson2(cwd, workspacePatterns) {
|
|
1135
|
+
const pkgPath = PATH5.join(cwd, "package.json");
|
|
1136
|
+
const pkg = JSON.parse(readFileSync6(pkgPath, "utf8"));
|
|
1137
|
+
pkg.workspaces = workspacePatterns;
|
|
1138
|
+
pkg.packageManager = `yarn@${YARN_VERSION}`;
|
|
1139
|
+
const updated = rewriteScriptsInPackageJson(pkg, "pnpm-to-yarn");
|
|
1140
|
+
writeFileSync6(pkgPath, JSON.stringify(updated, null, 2) + "\n", "utf8");
|
|
1141
|
+
console.log(chalk7.green(" Updated root package.json"));
|
|
1142
|
+
}
|
|
1143
|
+
function updateGitignore2(cwd) {
|
|
1144
|
+
const gitignorePath = PATH5.join(cwd, ".gitignore");
|
|
1145
|
+
let content = existsSync6(gitignorePath) ? readFileSync6(gitignorePath, "utf8") : "";
|
|
1146
|
+
if (!content.includes(".yarn/*")) {
|
|
1147
|
+
content = content.trimEnd() + "\n" + YARN_GITIGNORE_ENTRIES;
|
|
1148
|
+
}
|
|
1149
|
+
writeFileSync6(gitignorePath, content, "utf8");
|
|
1150
|
+
console.log(chalk7.green(" Updated .gitignore"));
|
|
1151
|
+
}
|
|
1152
|
+
function deletePnpmArtifacts(cwd) {
|
|
1153
|
+
const lockfile = PATH5.join(cwd, "pnpm-lock.yaml");
|
|
1154
|
+
const workspaceYaml = PATH5.join(cwd, "pnpm-workspace.yaml");
|
|
1155
|
+
const npmrc = PATH5.join(cwd, ".npmrc");
|
|
1156
|
+
if (existsSync6(lockfile)) {
|
|
1157
|
+
rmSync2(lockfile);
|
|
1158
|
+
console.log(chalk7.gray(" Deleted pnpm-lock.yaml"));
|
|
1159
|
+
}
|
|
1160
|
+
if (existsSync6(workspaceYaml)) {
|
|
1161
|
+
rmSync2(workspaceYaml);
|
|
1162
|
+
console.log(chalk7.gray(" Deleted pnpm-workspace.yaml"));
|
|
1163
|
+
}
|
|
1164
|
+
if (existsSync6(npmrc)) {
|
|
1165
|
+
const content = readFileSync6(npmrc, "utf8");
|
|
1166
|
+
if (content.trim() === "" || content.includes("shamefully-hoist") || content.includes("node-linker")) {
|
|
1167
|
+
rmSync2(npmrc);
|
|
1168
|
+
console.log(chalk7.gray(" Deleted .npmrc"));
|
|
1169
|
+
}
|
|
1170
|
+
}
|
|
1171
|
+
}
|
|
1172
|
+
function createYarnrc(cwd) {
|
|
1173
|
+
const yarnrcPath = PATH5.join(cwd, ".yarnrc.yml");
|
|
1174
|
+
if (existsSync6(yarnrcPath)) return;
|
|
1175
|
+
writeFileSync6(yarnrcPath, YARNRC_TEMPLATE, "utf8");
|
|
1176
|
+
console.log(chalk7.green(" Created .yarnrc.yml"));
|
|
1177
|
+
}
|
|
1178
|
+
function readWorkspacePatternsFromPackageJson(cwd) {
|
|
1179
|
+
const pkgPath = PATH5.join(cwd, "package.json");
|
|
1180
|
+
if (!existsSync6(pkgPath)) return [];
|
|
1181
|
+
const pkg = JSON.parse(readFileSync6(pkgPath, "utf8"));
|
|
1182
|
+
return pkg.workspaces ?? [];
|
|
1183
|
+
}
|
|
1184
|
+
function convertToYarn(cwd, workspacePackageJsonPaths) {
|
|
1185
|
+
console.log(chalk7.blue("\nConverting to yarn...\n"));
|
|
1186
|
+
const workspacePatterns = readPnpmWorkspacePatterns2(cwd);
|
|
1187
|
+
if (workspacePatterns.length === 0) {
|
|
1188
|
+
const fromPkg = readWorkspacePatternsFromPackageJson(cwd);
|
|
1189
|
+
if (fromPkg.length > 0) {
|
|
1190
|
+
workspacePatterns.push(...fromPkg);
|
|
1191
|
+
} else {
|
|
1192
|
+
console.warn(chalk7.yellow(" No workspace patterns found"));
|
|
1193
|
+
}
|
|
1194
|
+
}
|
|
1195
|
+
updateRootPackageJson2(cwd, workspacePatterns);
|
|
1196
|
+
for (const pkgPath of workspacePackageJsonPaths) {
|
|
1197
|
+
const fullPath = PATH5.resolve(cwd, pkgPath, "package.json");
|
|
1198
|
+
if (!existsSync6(fullPath)) continue;
|
|
1199
|
+
const pkg = JSON.parse(readFileSync6(fullPath, "utf8"));
|
|
1200
|
+
const updated = rewriteScriptsInPackageJson(pkg, "pnpm-to-yarn");
|
|
1201
|
+
if (JSON.stringify(pkg) !== JSON.stringify(updated)) {
|
|
1202
|
+
writeFileSync6(fullPath, JSON.stringify(updated, null, 2) + "\n", "utf8");
|
|
1203
|
+
}
|
|
1204
|
+
}
|
|
1205
|
+
console.log(chalk7.green(` Rewrote scripts in ${workspacePackageJsonPaths.length} workspace package(s)`));
|
|
1206
|
+
updateGitignore2(cwd);
|
|
1207
|
+
createYarnrc(cwd);
|
|
1208
|
+
swapTsScriptsDependency(cwd, workspacePackageJsonPaths, "pnpm-to-yarn");
|
|
1209
|
+
rewriteSourceImports(cwd, "pnpm-to-yarn");
|
|
1210
|
+
deletePnpmArtifacts(cwd);
|
|
1211
|
+
console.log(chalk7.blue("\nRunning yarn install..."));
|
|
1212
|
+
const install = spawnSync3("yarn", ["install"], {
|
|
1213
|
+
cwd,
|
|
1214
|
+
encoding: "utf8",
|
|
1215
|
+
shell: true,
|
|
1216
|
+
stdio: "inherit"
|
|
1217
|
+
});
|
|
1218
|
+
if (install.status !== 0) {
|
|
1219
|
+
console.error(chalk7.red("yarn install failed"));
|
|
1220
|
+
return 1;
|
|
1221
|
+
}
|
|
1222
|
+
console.log(chalk7.blue("\nConversion complete.\n"));
|
|
1223
|
+
return 0;
|
|
1224
|
+
}
|
|
1225
|
+
|
|
1226
|
+
// src/actions/packman/convert.ts
|
|
1227
|
+
function detectCurrentPM(cwd) {
|
|
1228
|
+
if (existsSync7(PATH6.join(cwd, "pnpm-lock.yaml")) || existsSync7(PATH6.join(cwd, "pnpm-workspace.yaml"))) {
|
|
1229
|
+
return "pnpm";
|
|
1230
|
+
}
|
|
1231
|
+
if (existsSync7(PATH6.join(cwd, "yarn.lock")) || existsSync7(PATH6.join(cwd, ".yarnrc.yml"))) {
|
|
1232
|
+
return "yarn";
|
|
1233
|
+
}
|
|
1234
|
+
return "unknown";
|
|
1235
|
+
}
|
|
1236
|
+
function findWorkspacePackagePaths(cwd) {
|
|
1237
|
+
const pkgPath = PATH6.join(cwd, "package.json");
|
|
1238
|
+
const pkg = JSON.parse(readFileSync7(pkgPath, "utf8"));
|
|
1239
|
+
const patterns = pkg.workspaces ?? [];
|
|
1240
|
+
if (patterns.length === 0) {
|
|
1241
|
+
const wsPath = PATH6.join(cwd, "pnpm-workspace.yaml");
|
|
1242
|
+
if (existsSync7(wsPath)) {
|
|
1243
|
+
const content = readFileSync7(wsPath, "utf8");
|
|
1244
|
+
const lines = content.split("\n");
|
|
1245
|
+
let inPackages = false;
|
|
1246
|
+
for (const line of lines) {
|
|
1247
|
+
if (line.trim() === "packages:") {
|
|
1248
|
+
inPackages = true;
|
|
1249
|
+
continue;
|
|
1250
|
+
}
|
|
1251
|
+
if (inPackages && /^\s+-\s+/.test(line)) {
|
|
1252
|
+
const pattern = line.replace(/^\s+-\s+/, "").replaceAll(/['"]/g, "").trim();
|
|
1253
|
+
if (pattern) patterns.push(pattern);
|
|
1254
|
+
} else if (inPackages && !/^\s/.test(line) && line.trim()) {
|
|
1255
|
+
inPackages = false;
|
|
1256
|
+
}
|
|
1257
|
+
}
|
|
1258
|
+
}
|
|
1259
|
+
}
|
|
1260
|
+
const dirs = [];
|
|
1261
|
+
for (const pattern of patterns) {
|
|
1262
|
+
const resolved = resolveWorkspaceGlob(cwd, pattern);
|
|
1263
|
+
dirs.push(...resolved);
|
|
1264
|
+
}
|
|
1265
|
+
return dirs;
|
|
1266
|
+
}
|
|
1267
|
+
function resolveWorkspaceGlob(cwd, pattern) {
|
|
1268
|
+
const parts = pattern.split("/");
|
|
1269
|
+
return walkGlob(cwd, parts, "");
|
|
1270
|
+
}
|
|
1271
|
+
function walkGlob(basePath, parts, currentPath) {
|
|
1272
|
+
if (parts.length === 0) {
|
|
1273
|
+
const fullPath = PATH6.join(basePath, currentPath);
|
|
1274
|
+
if (existsSync7(PATH6.join(fullPath, "package.json"))) {
|
|
1275
|
+
return [currentPath];
|
|
1276
|
+
}
|
|
1277
|
+
return [];
|
|
1278
|
+
}
|
|
1279
|
+
const [part, ...rest] = parts;
|
|
1280
|
+
const dirPath = PATH6.join(basePath, currentPath);
|
|
1281
|
+
if (!existsSync7(dirPath) || !statSync(dirPath).isDirectory()) {
|
|
1282
|
+
return [];
|
|
1283
|
+
}
|
|
1284
|
+
if (part === "*" || part === "**") {
|
|
1285
|
+
const entries = readdirSync(dirPath, { withFileTypes: true }).filter((e) => e.isDirectory() && !e.name.startsWith(".") && e.name !== "node_modules" && e.name !== "dist");
|
|
1286
|
+
const results = [];
|
|
1287
|
+
if (part === "**") {
|
|
1288
|
+
results.push(...walkGlob(basePath, rest, currentPath));
|
|
1289
|
+
}
|
|
1290
|
+
for (const entry of entries) {
|
|
1291
|
+
const subPath2 = currentPath ? `${currentPath}/${entry.name}` : entry.name;
|
|
1292
|
+
if (part === "**") {
|
|
1293
|
+
results.push(
|
|
1294
|
+
...walkGlob(basePath, rest, subPath2),
|
|
1295
|
+
...walkGlob(basePath, parts, subPath2)
|
|
1296
|
+
);
|
|
1297
|
+
} else {
|
|
1298
|
+
results.push(...walkGlob(basePath, rest, subPath2));
|
|
1299
|
+
}
|
|
1300
|
+
}
|
|
1301
|
+
return results;
|
|
1302
|
+
}
|
|
1303
|
+
const subPath = currentPath ? `${currentPath}/${part}` : part;
|
|
1304
|
+
return walkGlob(basePath, rest, subPath);
|
|
1305
|
+
}
|
|
1306
|
+
function convert({ target, verbose }) {
|
|
1307
|
+
const validTargets = ["pnpm", "yarn"];
|
|
1308
|
+
if (!validTargets.includes(target)) {
|
|
1309
|
+
console.error(chalk8.red(`Invalid target "${target}". Must be one of: ${validTargets.join(", ")}`));
|
|
1310
|
+
return 1;
|
|
1311
|
+
}
|
|
1312
|
+
const cwd = process.cwd();
|
|
1313
|
+
const currentPM = detectCurrentPM(cwd);
|
|
1314
|
+
if (verbose) {
|
|
1315
|
+
console.log(chalk8.gray(`Current package manager: ${currentPM}`));
|
|
1316
|
+
console.log(chalk8.gray(`Target package manager: ${target}`));
|
|
1317
|
+
}
|
|
1318
|
+
if (currentPM === target) {
|
|
1319
|
+
console.log(chalk8.yellow(`Already using ${target}. Re-applying conversion to fix any incomplete steps...`));
|
|
1320
|
+
}
|
|
1321
|
+
if (currentPM === "unknown") {
|
|
1322
|
+
console.error(chalk8.red("Could not detect current package manager. No yarn.lock or pnpm-lock.yaml found."));
|
|
1323
|
+
return 1;
|
|
1324
|
+
}
|
|
1325
|
+
const workspacePaths = findWorkspacePackagePaths(cwd);
|
|
1326
|
+
if (verbose) {
|
|
1327
|
+
console.log(chalk8.gray(`Found ${workspacePaths.length} workspace packages`));
|
|
1328
|
+
}
|
|
1329
|
+
const result = target === "pnpm" ? convertToPnpm(cwd, workspacePaths) : convertToYarn(cwd, workspacePaths);
|
|
1330
|
+
if (result !== 0) return result;
|
|
1331
|
+
console.log(chalk8.green("\nRunning repo lint --fix..."));
|
|
1332
|
+
packageLintMonorepo(true);
|
|
1333
|
+
return result;
|
|
1334
|
+
}
|
|
1335
|
+
|
|
1336
|
+
// src/actions/packman/clean.ts
|
|
1337
|
+
function removeNodeModules(dir, verbose) {
|
|
1338
|
+
const nmPath = PATH7.join(dir, "node_modules");
|
|
1339
|
+
if (existsSync8(nmPath)) {
|
|
1340
|
+
if (verbose) console.log(chalk9.gray(`Removing ${nmPath}`));
|
|
1341
|
+
rmSync3(nmPath, { force: true, recursive: true });
|
|
1342
|
+
return true;
|
|
1343
|
+
}
|
|
1344
|
+
return false;
|
|
1345
|
+
}
|
|
1346
|
+
function packmanClean({ verbose }) {
|
|
1347
|
+
const cwd = process.cwd();
|
|
1348
|
+
const pm = detectCurrentPM(cwd);
|
|
1349
|
+
if (pm === "unknown") {
|
|
1350
|
+
console.error(chalk9.red("Could not detect current package manager. No yarn.lock or pnpm-lock.yaml found."));
|
|
1351
|
+
return 1;
|
|
1352
|
+
}
|
|
1353
|
+
console.log(chalk9.blue(`Detected package manager: ${pm}`));
|
|
1354
|
+
let removedCount = 0;
|
|
1355
|
+
if (removeNodeModules(cwd, verbose)) removedCount++;
|
|
1356
|
+
const workspacePaths = findWorkspacePackagePaths(cwd);
|
|
1357
|
+
for (const wsPath of workspacePaths) {
|
|
1358
|
+
const fullPath = PATH7.join(cwd, wsPath);
|
|
1359
|
+
if (removeNodeModules(fullPath, verbose)) removedCount++;
|
|
1360
|
+
}
|
|
1361
|
+
console.log(chalk9.green(`Removed ${removedCount} node_modules folder${removedCount === 1 ? "" : "s"}`));
|
|
1362
|
+
if (pm === "yarn") {
|
|
1363
|
+
const lockPath = PATH7.join(cwd, "yarn.lock");
|
|
1364
|
+
if (existsSync8(lockPath)) {
|
|
1365
|
+
writeFileSync7(lockPath, "");
|
|
1366
|
+
console.log(chalk9.green("Truncated yarn.lock"));
|
|
1367
|
+
}
|
|
1368
|
+
} else if (pm === "pnpm") {
|
|
1369
|
+
const lockPath = PATH7.join(cwd, "pnpm-lock.yaml");
|
|
1370
|
+
if (existsSync8(lockPath)) {
|
|
1371
|
+
rmSync3(lockPath);
|
|
1372
|
+
console.log(chalk9.green("Deleted pnpm-lock.yaml"));
|
|
1373
|
+
}
|
|
1374
|
+
}
|
|
1375
|
+
console.log(chalk9.green("Ready for a clean install"));
|
|
1376
|
+
return 0;
|
|
1377
|
+
}
|
|
1378
|
+
|
|
1379
|
+
// src/actions/packman/lint.ts
|
|
1380
|
+
import {
|
|
1381
|
+
existsSync as existsSync9,
|
|
1382
|
+
readFileSync as readFileSync8,
|
|
1383
|
+
writeFileSync as writeFileSync8
|
|
1384
|
+
} from "fs";
|
|
1385
|
+
import PATH8 from "path";
|
|
1386
|
+
import chalk10 from "chalk";
|
|
1387
|
+
function checkEnableScripts(cwd, verbose, silent) {
|
|
1388
|
+
const yarnrcPath = PATH8.join(cwd, ".yarnrc.yml");
|
|
1389
|
+
if (!existsSync9(yarnrcPath)) {
|
|
1390
|
+
if (verbose) console.log(chalk10.gray(" No .yarnrc.yml found, skipping enableScripts check"));
|
|
1391
|
+
return true;
|
|
1392
|
+
}
|
|
1393
|
+
const content = readFileSync8(yarnrcPath, "utf8");
|
|
1394
|
+
const lines = content.split("\n");
|
|
1395
|
+
for (const line of lines) {
|
|
1396
|
+
const trimmed = line.trim();
|
|
1397
|
+
if (/^enableScripts\s*:/.test(trimmed)) {
|
|
1398
|
+
const value = trimmed.replace(/^enableScripts\s*:\s*/, "").trim();
|
|
1399
|
+
if (value === "false") {
|
|
1400
|
+
if (verbose) console.log(chalk10.green(" enableScripts is correctly set to false"));
|
|
1401
|
+
return true;
|
|
1402
|
+
}
|
|
1403
|
+
if (!silent) console.log(chalk10.red(" enableScripts is set to", value, "(expected false)"));
|
|
1404
|
+
return false;
|
|
1405
|
+
}
|
|
1406
|
+
}
|
|
1407
|
+
if (!silent) console.log(chalk10.red(" enableScripts is not set in .yarnrc.yml (expected false)"));
|
|
1408
|
+
return false;
|
|
1409
|
+
}
|
|
1410
|
+
function fixEnableScripts(cwd, verbose) {
|
|
1411
|
+
const yarnrcPath = PATH8.join(cwd, ".yarnrc.yml");
|
|
1412
|
+
if (!existsSync9(yarnrcPath)) {
|
|
1413
|
+
if (verbose) console.log(chalk10.gray(" No .yarnrc.yml found, skipping enableScripts fix"));
|
|
1414
|
+
return true;
|
|
1415
|
+
}
|
|
1416
|
+
const content = readFileSync8(yarnrcPath, "utf8");
|
|
1417
|
+
const lines = content.split("\n");
|
|
1418
|
+
let found = false;
|
|
1419
|
+
const newLines = lines.map((line) => {
|
|
1420
|
+
if (/^\s*enableScripts\s*:/.test(line)) {
|
|
1421
|
+
found = true;
|
|
1422
|
+
return "enableScripts: false";
|
|
1423
|
+
}
|
|
1424
|
+
return line;
|
|
1425
|
+
});
|
|
1426
|
+
if (!found) {
|
|
1427
|
+
let inserted = false;
|
|
1428
|
+
for (let i = 0; i < newLines.length; i++) {
|
|
1429
|
+
const trimmed = newLines[i].trim();
|
|
1430
|
+
if (trimmed && !trimmed.startsWith("#") && trimmed > "enableScripts:") {
|
|
1431
|
+
newLines.splice(i, 0, "enableScripts: false", "");
|
|
1432
|
+
inserted = true;
|
|
1433
|
+
break;
|
|
1434
|
+
}
|
|
1435
|
+
}
|
|
1436
|
+
if (!inserted) {
|
|
1437
|
+
const lastLine = newLines.at(-1);
|
|
1438
|
+
if (lastLine === "") {
|
|
1439
|
+
newLines.splice(-1, 0, "enableScripts: false", "");
|
|
1440
|
+
} else {
|
|
1441
|
+
newLines.push("", "enableScripts: false");
|
|
1442
|
+
}
|
|
1443
|
+
}
|
|
1444
|
+
}
|
|
1445
|
+
writeFileSync8(yarnrcPath, newLines.join("\n"), "utf8");
|
|
1446
|
+
console.log(chalk10.green(" Fixed: enableScripts set to false"));
|
|
1447
|
+
return true;
|
|
1448
|
+
}
|
|
1449
|
+
var checks = [
|
|
1450
|
+
{
|
|
1451
|
+
name: "enableScripts should be false in .yarnrc.yml",
|
|
1452
|
+
check: checkEnableScripts,
|
|
1453
|
+
fix: fixEnableScripts
|
|
1454
|
+
}
|
|
1455
|
+
];
|
|
1456
|
+
function packmanLint({ fix, verbose } = {}) {
|
|
1457
|
+
const cwd = process.cwd();
|
|
1458
|
+
let failures = 0;
|
|
1459
|
+
for (const check of checks) {
|
|
1460
|
+
if (verbose) console.log(chalk10.gray(`Checking: ${check.name}`));
|
|
1461
|
+
const passed = check.check(cwd, verbose, fix);
|
|
1462
|
+
if (!passed) {
|
|
1463
|
+
if (fix) {
|
|
1464
|
+
const fixed = check.fix(cwd, verbose);
|
|
1465
|
+
if (!fixed) {
|
|
1466
|
+
failures++;
|
|
1467
|
+
}
|
|
1468
|
+
} else {
|
|
1469
|
+
failures++;
|
|
1470
|
+
}
|
|
1471
|
+
}
|
|
1472
|
+
}
|
|
1473
|
+
if (failures > 0) {
|
|
1474
|
+
console.log(chalk10.red(`
|
|
1475
|
+
packman lint: ${failures} check(s) failed`));
|
|
1476
|
+
if (!fix) {
|
|
1477
|
+
console.log(chalk10.yellow("Run with --fix to auto-fix issues"));
|
|
1478
|
+
}
|
|
1479
|
+
} else {
|
|
1480
|
+
console.log(chalk10.green("\npackman lint: all checks passed"));
|
|
1481
|
+
}
|
|
1482
|
+
return failures > 0 ? 1 : 0;
|
|
1483
|
+
}
|
|
1484
|
+
export {
|
|
1485
|
+
convert,
|
|
1486
|
+
detectCurrentPM,
|
|
1487
|
+
findWorkspacePackagePaths,
|
|
1488
|
+
packmanClean,
|
|
1489
|
+
packmanLint,
|
|
1490
|
+
rewriteScript,
|
|
1491
|
+
rewriteScriptsInPackageJson
|
|
1492
|
+
};
|
|
1493
|
+
//# sourceMappingURL=index.mjs.map
|