@xylabs/ts-scripts-yarn3 7.4.28 → 7.5.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/actions/deploy-major.mjs +1 -90
- package/dist/actions/deploy-major.mjs.map +1 -1
- package/dist/actions/deploy-minor.mjs +1 -90
- package/dist/actions/deploy-minor.mjs.map +1 -1
- package/dist/actions/deploy-next.mjs +1 -90
- package/dist/actions/deploy-next.mjs.map +1 -1
- package/dist/actions/deploy.mjs +1 -90
- package/dist/actions/deploy.mjs.map +1 -1
- package/dist/actions/index.mjs +128 -3840
- package/dist/actions/index.mjs.map +1 -1
- package/dist/actions/publish.mjs +1 -90
- package/dist/actions/publish.mjs.map +1 -1
- package/dist/actions/reinstall.mjs +1 -90
- package/dist/actions/reinstall.mjs.map +1 -1
- package/dist/actions/up.mjs +1 -90
- package/dist/actions/up.mjs.map +1 -1
- package/dist/actions/updo.mjs +1 -90
- package/dist/actions/updo.mjs.map +1 -1
- package/dist/actions/upplug.mjs +1 -90
- package/dist/actions/upplug.mjs.map +1 -1
- package/dist/actions/upyarn.mjs +1 -90
- package/dist/actions/upyarn.mjs.map +1 -1
- package/dist/actions/yarn3only.mjs +2 -32
- package/dist/actions/yarn3only.mjs.map +1 -1
- package/dist/bin/xy.mjs +222 -3684
- package/dist/bin/xy.mjs.map +1 -1
- package/dist/index.d.ts +24 -502
- package/dist/index.mjs +224 -4659
- package/dist/index.mjs.map +1 -1
- package/dist/lib/index.mjs +0 -804
- package/dist/lib/index.mjs.map +1 -1
- package/dist/lib/yarn/index.mjs +0 -7
- package/dist/lib/yarn/index.mjs.map +1 -1
- package/dist/pm/index.mjs +82 -0
- package/dist/pm/index.mjs.map +1 -0
- package/dist/pm/yarnPackageManager.mjs +82 -0
- package/dist/pm/yarnPackageManager.mjs.map +1 -0
- package/dist/xy/common/index.mjs +7 -1459
- package/dist/xy/common/index.mjs.map +1 -1
- package/dist/xy/common/upplugCommand.mjs +1 -90
- package/dist/xy/common/upplugCommand.mjs.map +1 -1
- package/dist/xy/common/upyarnCommand.mjs +1 -90
- package/dist/xy/common/upyarnCommand.mjs.map +1 -1
- package/dist/xy/common/yarn3OnlyCommand.mjs +1 -33
- package/dist/xy/common/yarn3OnlyCommand.mjs.map +1 -1
- package/dist/xy/deploy/deployCommand.mjs +3 -90
- package/dist/xy/deploy/deployCommand.mjs.map +1 -1
- package/dist/xy/deploy/deployMajorCommand.mjs +1 -90
- package/dist/xy/deploy/deployMajorCommand.mjs.map +1 -1
- package/dist/xy/deploy/deployMinorCommand.mjs +1 -90
- package/dist/xy/deploy/deployMinorCommand.mjs.map +1 -1
- package/dist/xy/deploy/deployNextCommand.mjs +1 -90
- package/dist/xy/deploy/deployNextCommand.mjs.map +1 -1
- package/dist/xy/deploy/index.mjs +11 -94
- package/dist/xy/deploy/index.mjs.map +1 -1
- package/dist/xy/deploy/publishCommand.mjs +1 -90
- package/dist/xy/deploy/publishCommand.mjs.map +1 -1
- package/dist/xy/index.mjs +183 -3717
- package/dist/xy/index.mjs.map +1 -1
- package/dist/xy/install/cleanCommand.mjs +6 -118
- package/dist/xy/install/cleanCommand.mjs.map +1 -1
- package/dist/xy/install/dupdepsCommand.mjs +6 -178
- package/dist/xy/install/dupdepsCommand.mjs.map +1 -1
- package/dist/xy/install/index.mjs +12 -305
- package/dist/xy/install/index.mjs.map +1 -1
- package/dist/xy/install/reinstallCommand.mjs +1 -90
- package/dist/xy/install/reinstallCommand.mjs.map +1 -1
- package/dist/xy/install/staticsCommand.mjs +6 -177
- package/dist/xy/install/staticsCommand.mjs.map +1 -1
- package/dist/xy/install/upCommand.mjs +1 -90
- package/dist/xy/install/upCommand.mjs.map +1 -1
- package/dist/xy/install/updoCommand.mjs +1 -90
- package/dist/xy/install/updoCommand.mjs.map +1 -1
- package/dist/xy/xy.mjs +64 -3595
- package/dist/xy/xy.mjs.map +1 -1
- package/dist/xy/yarnCommands.mjs +80 -0
- package/dist/xy/yarnCommands.mjs.map +1 -0
- package/package.json +5 -47
- package/dist/actions/build.mjs +0 -140
- package/dist/actions/build.mjs.map +0 -1
- package/dist/actions/claude-clean.mjs +0 -71
- package/dist/actions/claude-clean.mjs.map +0 -1
- package/dist/actions/claude-commands.mjs +0 -112
- package/dist/actions/claude-commands.mjs.map +0 -1
- package/dist/actions/claude-rules.mjs +0 -137
- package/dist/actions/claude-rules.mjs.map +0 -1
- package/dist/actions/claude-settings.mjs +0 -85
- package/dist/actions/claude-settings.mjs.map +0 -1
- package/dist/actions/claude-skills.mjs +0 -120
- package/dist/actions/claude-skills.mjs.map +0 -1
- package/dist/actions/clean-docs.mjs +0 -37
- package/dist/actions/clean-docs.mjs.map +0 -1
- package/dist/actions/clean-eslint.mjs +0 -26
- package/dist/actions/clean-eslint.mjs.map +0 -1
- package/dist/actions/clean.mjs +0 -124
- package/dist/actions/clean.mjs.map +0 -1
- package/dist/actions/compile.mjs +0 -157
- package/dist/actions/compile.mjs.map +0 -1
- package/dist/actions/copy-assets.mjs +0 -73
- package/dist/actions/copy-assets.mjs.map +0 -1
- package/dist/actions/cycle.mjs +0 -144
- package/dist/actions/cycle.mjs.map +0 -1
- package/dist/actions/dead.mjs +0 -98
- package/dist/actions/dead.mjs.map +0 -1
- package/dist/actions/deplint/checkPackage/checkPackage.mjs +0 -672
- package/dist/actions/deplint/checkPackage/checkPackage.mjs.map +0 -1
- package/dist/actions/deplint/checkPackage/checkPackageTypes.mjs +0 -1
- package/dist/actions/deplint/checkPackage/checkPackageTypes.mjs.map +0 -1
- package/dist/actions/deplint/checkPackage/getUnlistedDependencies.mjs +0 -48
- package/dist/actions/deplint/checkPackage/getUnlistedDependencies.mjs.map +0 -1
- package/dist/actions/deplint/checkPackage/getUnlistedDevDependencies.mjs +0 -33
- package/dist/actions/deplint/checkPackage/getUnlistedDevDependencies.mjs.map +0 -1
- package/dist/actions/deplint/checkPackage/getUnusedDependencies.mjs +0 -30
- package/dist/actions/deplint/checkPackage/getUnusedDependencies.mjs.map +0 -1
- package/dist/actions/deplint/checkPackage/getUnusedDevDependencies.mjs +0 -309
- package/dist/actions/deplint/checkPackage/getUnusedDevDependencies.mjs.map +0 -1
- package/dist/actions/deplint/checkPackage/getUnusedPeerDependencies.mjs +0 -26
- package/dist/actions/deplint/checkPackage/getUnusedPeerDependencies.mjs.map +0 -1
- package/dist/actions/deplint/checkPackage/index.mjs +0 -672
- package/dist/actions/deplint/checkPackage/index.mjs.map +0 -1
- package/dist/actions/deplint/deplint.mjs +0 -764
- package/dist/actions/deplint/deplint.mjs.map +0 -1
- package/dist/actions/deplint/findFiles.mjs +0 -39
- package/dist/actions/deplint/findFiles.mjs.map +0 -1
- package/dist/actions/deplint/findFilesByGlob.mjs +0 -14
- package/dist/actions/deplint/findFilesByGlob.mjs.map +0 -1
- package/dist/actions/deplint/getBasePackageName.mjs +0 -13
- package/dist/actions/deplint/getBasePackageName.mjs.map +0 -1
- package/dist/actions/deplint/getCliReferencedPackagesFromFiles.mjs +0 -140
- package/dist/actions/deplint/getCliReferencedPackagesFromFiles.mjs.map +0 -1
- package/dist/actions/deplint/getDependenciesFromPackageJson.mjs +0 -20
- package/dist/actions/deplint/getDependenciesFromPackageJson.mjs.map +0 -1
- package/dist/actions/deplint/getExtendsFromTsconfigs.mjs +0 -44
- package/dist/actions/deplint/getExtendsFromTsconfigs.mjs.map +0 -1
- package/dist/actions/deplint/getExternalImportsFromFiles.mjs +0 -122
- package/dist/actions/deplint/getExternalImportsFromFiles.mjs.map +0 -1
- package/dist/actions/deplint/getImportsFromFile.mjs +0 -85
- package/dist/actions/deplint/getImportsFromFile.mjs.map +0 -1
- package/dist/actions/deplint/getRequiredPeerDependencies.mjs +0 -36
- package/dist/actions/deplint/getRequiredPeerDependencies.mjs.map +0 -1
- package/dist/actions/deplint/getScriptReferencedPackages.mjs +0 -83
- package/dist/actions/deplint/getScriptReferencedPackages.mjs.map +0 -1
- package/dist/actions/deplint/implicitDevDependencies.mjs +0 -80
- package/dist/actions/deplint/implicitDevDependencies.mjs.map +0 -1
- package/dist/actions/deplint/index.mjs +0 -764
- package/dist/actions/deplint/index.mjs.map +0 -1
- package/dist/actions/dupdeps.mjs +0 -184
- package/dist/actions/dupdeps.mjs.map +0 -1
- package/dist/actions/fix.mjs +0 -147
- package/dist/actions/fix.mjs.map +0 -1
- package/dist/actions/gen-docs.mjs +0 -109
- package/dist/actions/gen-docs.mjs.map +0 -1
- package/dist/actions/gitignore.mjs +0 -152
- package/dist/actions/gitignore.mjs.map +0 -1
- package/dist/actions/gitlint-fix.mjs +0 -27
- package/dist/actions/gitlint-fix.mjs.map +0 -1
- package/dist/actions/gitlint.mjs +0 -48
- package/dist/actions/gitlint.mjs.map +0 -1
- package/dist/actions/knip.mjs +0 -98
- package/dist/actions/knip.mjs.map +0 -1
- package/dist/actions/license.mjs +0 -84
- package/dist/actions/license.mjs.map +0 -1
- package/dist/actions/lint.mjs +0 -144
- package/dist/actions/lint.mjs.map +0 -1
- package/dist/actions/lintlint.mjs +0 -230
- package/dist/actions/lintlint.mjs.map +0 -1
- package/dist/actions/npmignore-gen.mjs +0 -88
- package/dist/actions/npmignore-gen.mjs.map +0 -1
- package/dist/actions/package/clean-outputs.mjs +0 -29
- package/dist/actions/package/clean-outputs.mjs.map +0 -1
- package/dist/actions/package/clean-typescript.mjs +0 -29
- package/dist/actions/package/clean-typescript.mjs.map +0 -1
- package/dist/actions/package/clean.mjs +0 -48
- package/dist/actions/package/clean.mjs.map +0 -1
- package/dist/actions/package/compile/XyConfig.mjs +0 -1
- package/dist/actions/package/compile/XyConfig.mjs.map +0 -1
- package/dist/actions/package/compile/buildEntries.mjs +0 -53
- package/dist/actions/package/compile/buildEntries.mjs.map +0 -1
- package/dist/actions/package/compile/compile.mjs +0 -433
- package/dist/actions/package/compile/compile.mjs.map +0 -1
- package/dist/actions/package/compile/copyTypeFiles.mjs +0 -34
- package/dist/actions/package/compile/copyTypeFiles.mjs.map +0 -1
- package/dist/actions/package/compile/deepMerge.mjs +0 -26
- package/dist/actions/package/compile/deepMerge.mjs.map +0 -1
- package/dist/actions/package/compile/getCompilerOptions.mjs +0 -12
- package/dist/actions/package/compile/getCompilerOptions.mjs.map +0 -1
- package/dist/actions/package/compile/index.mjs +0 -436
- package/dist/actions/package/compile/index.mjs.map +0 -1
- package/dist/actions/package/compile/inputs.mjs +0 -22
- package/dist/actions/package/compile/inputs.mjs.map +0 -1
- package/dist/actions/package/compile/packageCompileTsc.mjs +0 -94
- package/dist/actions/package/compile/packageCompileTsc.mjs.map +0 -1
- package/dist/actions/package/compile/packageCompileTscTypes.mjs +0 -92
- package/dist/actions/package/compile/packageCompileTscTypes.mjs.map +0 -1
- package/dist/actions/package/compile/packageCompileTsup.mjs +0 -402
- package/dist/actions/package/compile/packageCompileTsup.mjs.map +0 -1
- package/dist/actions/package/copy-assets.mjs +0 -46
- package/dist/actions/package/copy-assets.mjs.map +0 -1
- package/dist/actions/package/cycle.mjs +0 -39
- package/dist/actions/package/cycle.mjs.map +0 -1
- package/dist/actions/package/gen-docs.mjs +0 -114
- package/dist/actions/package/gen-docs.mjs.map +0 -1
- package/dist/actions/package/index.mjs +0 -825
- package/dist/actions/package/index.mjs.map +0 -1
- package/dist/actions/package/lint.mjs +0 -80
- package/dist/actions/package/lint.mjs.map +0 -1
- package/dist/actions/package/publint.mjs +0 -66
- package/dist/actions/package/publint.mjs.map +0 -1
- package/dist/actions/package/recompile.mjs +0 -483
- package/dist/actions/package/recompile.mjs.map +0 -1
- package/dist/actions/package-lint.mjs +0 -178
- package/dist/actions/package-lint.mjs.map +0 -1
- package/dist/actions/publint.mjs +0 -166
- package/dist/actions/publint.mjs.map +0 -1
- package/dist/actions/readme-gen.mjs +0 -289
- package/dist/actions/readme-gen.mjs.map +0 -1
- package/dist/actions/readme-init.mjs +0 -83
- package/dist/actions/readme-init.mjs.map +0 -1
- package/dist/actions/rebuild.mjs +0 -101
- package/dist/actions/rebuild.mjs.map +0 -1
- package/dist/actions/recompile.mjs +0 -187
- package/dist/actions/recompile.mjs.map +0 -1
- package/dist/actions/relint.mjs +0 -144
- package/dist/actions/relint.mjs.map +0 -1
- package/dist/actions/retest.mjs +0 -123
- package/dist/actions/retest.mjs.map +0 -1
- package/dist/actions/sonar.mjs +0 -98
- package/dist/actions/sonar.mjs.map +0 -1
- package/dist/actions/statics.mjs +0 -183
- package/dist/actions/statics.mjs.map +0 -1
- package/dist/actions/test.mjs +0 -117
- package/dist/actions/test.mjs.map +0 -1
- package/dist/bin/package/build-only.mjs +0 -445
- package/dist/bin/package/build-only.mjs.map +0 -1
- package/dist/bin/package/build.mjs +0 -445
- package/dist/bin/package/build.mjs.map +0 -1
- package/dist/bin/package/clean-outputs.mjs +0 -29
- package/dist/bin/package/clean-outputs.mjs.map +0 -1
- package/dist/bin/package/clean-typescript.mjs +0 -29
- package/dist/bin/package/clean-typescript.mjs.map +0 -1
- package/dist/bin/package/clean.mjs +0 -53
- package/dist/bin/package/clean.mjs.map +0 -1
- package/dist/bin/package/compile-only.mjs +0 -441
- package/dist/bin/package/compile-only.mjs.map +0 -1
- package/dist/bin/package/compile-tsup.mjs +0 -409
- package/dist/bin/package/compile-tsup.mjs.map +0 -1
- package/dist/bin/package/compile.mjs +0 -445
- package/dist/bin/package/compile.mjs.map +0 -1
- package/dist/bin/package/copy-assets-cjs.mjs +0 -54
- package/dist/bin/package/copy-assets-cjs.mjs.map +0 -1
- package/dist/bin/package/copy-assets-esm.mjs +0 -54
- package/dist/bin/package/copy-assets-esm.mjs.map +0 -1
- package/dist/bin/package/cycle.mjs +0 -51
- package/dist/bin/package/cycle.mjs.map +0 -1
- package/dist/bin/package/fix.mjs +0 -92
- package/dist/bin/package/fix.mjs.map +0 -1
- package/dist/bin/package/gen-docs.mjs +0 -121
- package/dist/bin/package/gen-docs.mjs.map +0 -1
- package/dist/bin/package/lint-verbose.mjs +0 -92
- package/dist/bin/package/lint-verbose.mjs.map +0 -1
- package/dist/bin/package/lint.mjs +0 -92
- package/dist/bin/package/lint.mjs.map +0 -1
- package/dist/bin/package/publint.mjs +0 -75
- package/dist/bin/package/publint.mjs.map +0 -1
- package/dist/bin/package/recompile.mjs +0 -489
- package/dist/bin/package/recompile.mjs.map +0 -1
- package/dist/bin/package/relint.mjs +0 -92
- package/dist/bin/package/relint.mjs.map +0 -1
- package/dist/lib/checkResult.mjs +0 -16
- package/dist/lib/checkResult.mjs.map +0 -1
- package/dist/lib/claudeMdTemplate.mjs +0 -65
- package/dist/lib/claudeMdTemplate.mjs.map +0 -1
- package/dist/lib/createBuildConfig.mjs +0 -55
- package/dist/lib/createBuildConfig.mjs.map +0 -1
- package/dist/lib/defaultBuildConfig.mjs +0 -23
- package/dist/lib/defaultBuildConfig.mjs.map +0 -1
- package/dist/lib/deleteGlob.mjs +0 -13
- package/dist/lib/deleteGlob.mjs.map +0 -1
- package/dist/lib/dependencies/DuplicateDetector.mjs +0 -81
- package/dist/lib/dependencies/DuplicateDetector.mjs.map +0 -1
- package/dist/lib/dependencies/detectDuplicateDependencies.mjs +0 -164
- package/dist/lib/dependencies/detectDuplicateDependencies.mjs.map +0 -1
- package/dist/lib/dependencies/index.mjs +0 -165
- package/dist/lib/dependencies/index.mjs.map +0 -1
- package/dist/lib/file/ReadFileSyncOptions.mjs +0 -6
- package/dist/lib/file/ReadFileSyncOptions.mjs.map +0 -1
- package/dist/lib/file/constants.mjs +0 -8
- package/dist/lib/file/constants.mjs.map +0 -1
- package/dist/lib/file/fileLines.mjs +0 -32
- package/dist/lib/file/fileLines.mjs.map +0 -1
- package/dist/lib/file/index.mjs +0 -42
- package/dist/lib/file/index.mjs.map +0 -1
- package/dist/lib/file/tryReadFileSync.mjs +0 -14
- package/dist/lib/file/tryReadFileSync.mjs.map +0 -1
- package/dist/lib/generateIgnoreFiles.mjs +0 -84
- package/dist/lib/generateIgnoreFiles.mjs.map +0 -1
- package/dist/lib/generateReadmeFiles.mjs +0 -257
- package/dist/lib/generateReadmeFiles.mjs.map +0 -1
- package/dist/lib/gitignoreTemplate.mjs +0 -12
- package/dist/lib/gitignoreTemplate.mjs.map +0 -1
- package/dist/lib/jsonFormatters.mjs +0 -11
- package/dist/lib/jsonFormatters.mjs.map +0 -1
- package/dist/lib/loadConfig.mjs +0 -24
- package/dist/lib/loadConfig.mjs.map +0 -1
- package/dist/lib/parsedPackageJSON.mjs +0 -11
- package/dist/lib/parsedPackageJSON.mjs.map +0 -1
- package/dist/lib/processEx.mjs +0 -36
- package/dist/lib/processEx.mjs.map +0 -1
- package/dist/lib/runSteps.mjs +0 -95
- package/dist/lib/runSteps.mjs.map +0 -1
- package/dist/lib/runStepsAsync.mjs +0 -113
- package/dist/lib/runStepsAsync.mjs.map +0 -1
- package/dist/lib/runXy.mjs +0 -103
- package/dist/lib/runXy.mjs.map +0 -1
- package/dist/lib/runXyWithWarning.mjs +0 -13
- package/dist/lib/runXyWithWarning.mjs.map +0 -1
- package/dist/lib/safeExit.mjs +0 -61
- package/dist/lib/safeExit.mjs.map +0 -1
- package/dist/lib/string/empty.mjs +0 -8
- package/dist/lib/string/empty.mjs.map +0 -1
- package/dist/lib/string/index.mjs +0 -12
- package/dist/lib/string/index.mjs.map +0 -1
- package/dist/lib/string/union.mjs +0 -6
- package/dist/lib/string/union.mjs.map +0 -1
- package/dist/lib/tryRunLocalScript.mjs +0 -33
- package/dist/lib/tryRunLocalScript.mjs.map +0 -1
- package/dist/lib/withErrnoException.mjs +0 -13
- package/dist/lib/withErrnoException.mjs.map +0 -1
- package/dist/lib/withError.mjs +0 -8
- package/dist/lib/withError.mjs.map +0 -1
- package/dist/loadPackageConfig.mjs +0 -11
- package/dist/loadPackageConfig.mjs.map +0 -1
- package/dist/types.d.mjs +0 -1
- package/dist/types.d.mjs.map +0 -1
- package/dist/xy/build/buildCommand.mjs +0 -161
- package/dist/xy/build/buildCommand.mjs.map +0 -1
- package/dist/xy/build/compileCommand.mjs +0 -174
- package/dist/xy/build/compileCommand.mjs.map +0 -1
- package/dist/xy/build/compileOnlyCommand.mjs +0 -175
- package/dist/xy/build/compileOnlyCommand.mjs.map +0 -1
- package/dist/xy/build/copyAssetsCommand.mjs +0 -84
- package/dist/xy/build/copyAssetsCommand.mjs.map +0 -1
- package/dist/xy/build/index.mjs +0 -507
- package/dist/xy/build/index.mjs.map +0 -1
- package/dist/xy/build/rebuildCommand.mjs +0 -114
- package/dist/xy/build/rebuildCommand.mjs.map +0 -1
- package/dist/xy/build/recompileCommand.mjs +0 -204
- package/dist/xy/build/recompileCommand.mjs.map +0 -1
- package/dist/xy/common/claude/cleanCommand.mjs +0 -79
- package/dist/xy/common/claude/cleanCommand.mjs.map +0 -1
- package/dist/xy/common/claude/commandsCommand.mjs +0 -120
- package/dist/xy/common/claude/commandsCommand.mjs.map +0 -1
- package/dist/xy/common/claude/index.mjs +0 -546
- package/dist/xy/common/claude/index.mjs.map +0 -1
- package/dist/xy/common/claude/initCommand.mjs +0 -319
- package/dist/xy/common/claude/initCommand.mjs.map +0 -1
- package/dist/xy/common/claude/rulesCommand.mjs +0 -153
- package/dist/xy/common/claude/rulesCommand.mjs.map +0 -1
- package/dist/xy/common/claude/settingsCommand.mjs +0 -93
- package/dist/xy/common/claude/settingsCommand.mjs.map +0 -1
- package/dist/xy/common/claude/skillsCommand.mjs +0 -129
- package/dist/xy/common/claude/skillsCommand.mjs.map +0 -1
- package/dist/xy/common/cleanDocsCommand.mjs +0 -45
- package/dist/xy/common/cleanDocsCommand.mjs.map +0 -1
- package/dist/xy/common/deadCommand.mjs +0 -116
- package/dist/xy/common/deadCommand.mjs.map +0 -1
- package/dist/xy/common/genDocsCommand.mjs +0 -125
- package/dist/xy/common/genDocsCommand.mjs.map +0 -1
- package/dist/xy/common/gitignoreCommand.mjs +0 -158
- package/dist/xy/common/gitignoreCommand.mjs.map +0 -1
- package/dist/xy/common/gitlintCommand.mjs +0 -82
- package/dist/xy/common/gitlintCommand.mjs.map +0 -1
- package/dist/xy/common/licenseCommand.mjs +0 -100
- package/dist/xy/common/licenseCommand.mjs.map +0 -1
- package/dist/xy/common/npmignoreGenCommand.mjs +0 -98
- package/dist/xy/common/npmignoreGenCommand.mjs.map +0 -1
- package/dist/xy/common/readme/genCommand.mjs +0 -321
- package/dist/xy/common/readme/genCommand.mjs.map +0 -1
- package/dist/xy/common/readme/index.mjs +0 -361
- package/dist/xy/common/readme/index.mjs.map +0 -1
- package/dist/xy/common/readme/initCommand.mjs +0 -103
- package/dist/xy/common/readme/initCommand.mjs.map +0 -1
- package/dist/xy/common/retestCommand.mjs +0 -136
- package/dist/xy/common/retestCommand.mjs.map +0 -1
- package/dist/xy/common/testCommand.mjs +0 -130
- package/dist/xy/common/testCommand.mjs.map +0 -1
- package/dist/xy/lint/cycleCommand.mjs +0 -163
- package/dist/xy/lint/cycleCommand.mjs.map +0 -1
- package/dist/xy/lint/deplintCommand.mjs +0 -814
- package/dist/xy/lint/deplintCommand.mjs.map +0 -1
- package/dist/xy/lint/fixCommand.mjs +0 -168
- package/dist/xy/lint/fixCommand.mjs.map +0 -1
- package/dist/xy/lint/index.mjs +0 -1691
- package/dist/xy/lint/index.mjs.map +0 -1
- package/dist/xy/lint/knipCommand.mjs +0 -121
- package/dist/xy/lint/knipCommand.mjs.map +0 -1
- package/dist/xy/lint/lintCommand.mjs +0 -186
- package/dist/xy/lint/lintCommand.mjs.map +0 -1
- package/dist/xy/lint/lintlintCommand.mjs +0 -250
- package/dist/xy/lint/lintlintCommand.mjs.map +0 -1
- package/dist/xy/lint/packageLintCommand.mjs +0 -193
- package/dist/xy/lint/packageLintCommand.mjs.map +0 -1
- package/dist/xy/lint/publintCommand.mjs +0 -187
- package/dist/xy/lint/publintCommand.mjs.map +0 -1
- package/dist/xy/lint/relintCommand.mjs +0 -163
- package/dist/xy/lint/relintCommand.mjs.map +0 -1
- package/dist/xy/lint/sonarCommand.mjs +0 -121
- package/dist/xy/lint/sonarCommand.mjs.map +0 -1
- package/dist/xy/param.mjs +0 -8
- package/dist/xy/param.mjs.map +0 -1
- package/dist/xy/xyParseOptions.mjs +0 -70
- package/dist/xy/xyParseOptions.mjs.map +0 -1
package/dist/actions/index.mjs
CHANGED
|
@@ -1,3716 +1,145 @@
|
|
|
1
|
-
// src/actions/
|
|
2
|
-
import
|
|
3
|
-
|
|
4
|
-
// src/lib/checkResult.ts
|
|
5
|
-
import chalk from "chalk";
|
|
6
|
-
var checkResult = (name, result, level = "error", exitOnFail = false) => {
|
|
7
|
-
if (result) {
|
|
8
|
-
const exiting = exitOnFail ? "[Exiting Process]" : "[Continuing]";
|
|
9
|
-
const chalkFunc = level === "error" ? chalk.red : chalk.yellow;
|
|
10
|
-
console[level](chalkFunc(`${name} had ${result} failures ${exiting}`));
|
|
11
|
-
if (exitOnFail) {
|
|
12
|
-
process.exit(result);
|
|
13
|
-
}
|
|
14
|
-
}
|
|
15
|
-
};
|
|
16
|
-
|
|
17
|
-
// src/lib/claudeMdTemplate.ts
|
|
18
|
-
import {
|
|
19
|
-
readdirSync,
|
|
20
|
-
readFileSync,
|
|
21
|
-
statSync
|
|
22
|
-
} from "fs";
|
|
23
|
-
import { createRequire } from "module";
|
|
24
|
-
import PATH from "path";
|
|
25
|
-
var require2 = createRequire(import.meta.url);
|
|
26
|
-
var packageRoot = PATH.dirname(require2.resolve("@xylabs/ts-scripts-yarn3/package.json"));
|
|
27
|
-
var templatesDir = PATH.resolve(packageRoot, "templates", "claude");
|
|
28
|
-
var XYLABS_RULES_PREFIX = "xylabs-";
|
|
29
|
-
var XYLABS_COMMANDS_PREFIX = "xy-";
|
|
30
|
-
var LEGACY_COMMANDS_PREFIX = "xylabs-";
|
|
31
|
-
var XYLABS_SKILLS_PREFIX = "xylabs-";
|
|
32
|
-
var claudeMdRuleTemplates = () => {
|
|
33
|
-
const rulesDir = PATH.resolve(templatesDir, "rules");
|
|
34
|
-
const files = readdirSync(rulesDir).filter((f) => f.startsWith(XYLABS_RULES_PREFIX) && f.endsWith(".md"));
|
|
35
|
-
const result = {};
|
|
36
|
-
for (const file of files) {
|
|
37
|
-
result[file] = readFileSync(PATH.resolve(rulesDir, file), "utf8");
|
|
38
|
-
}
|
|
39
|
-
return result;
|
|
40
|
-
};
|
|
41
|
-
var claudeCommandTemplates = () => {
|
|
42
|
-
const commandsDir = PATH.resolve(templatesDir, "commands");
|
|
43
|
-
const files = readdirSync(commandsDir).filter((f) => f.startsWith(XYLABS_COMMANDS_PREFIX) && f.endsWith(".md"));
|
|
44
|
-
const result = {};
|
|
45
|
-
for (const file of files) {
|
|
46
|
-
result[file] = readFileSync(PATH.resolve(commandsDir, file), "utf8");
|
|
47
|
-
}
|
|
48
|
-
return result;
|
|
49
|
-
};
|
|
50
|
-
var claudeSkillTemplates = () => {
|
|
51
|
-
const skillsDir = PATH.resolve(templatesDir, "skills");
|
|
52
|
-
const dirs = readdirSync(skillsDir).filter(
|
|
53
|
-
(f) => f.startsWith(XYLABS_SKILLS_PREFIX) && statSync(PATH.resolve(skillsDir, f)).isDirectory()
|
|
54
|
-
);
|
|
55
|
-
const result = {};
|
|
56
|
-
for (const dir of dirs) {
|
|
57
|
-
const dirPath = PATH.resolve(skillsDir, dir);
|
|
58
|
-
const files = readdirSync(dirPath, { recursive: true, encoding: "utf8" });
|
|
59
|
-
result[dir] = {};
|
|
60
|
-
for (const file of files) {
|
|
61
|
-
if (statSync(PATH.resolve(dirPath, file)).isFile()) {
|
|
62
|
-
result[dir][file] = readFileSync(PATH.resolve(dirPath, file), "utf8");
|
|
63
|
-
}
|
|
64
|
-
}
|
|
65
|
-
}
|
|
66
|
-
return result;
|
|
67
|
-
};
|
|
68
|
-
var claudeMdLocalTemplate = () => readFileSync(PATH.resolve(templatesDir, "CLAUDE-local.md"), "utf8");
|
|
69
|
-
|
|
70
|
-
// src/lib/deleteGlob.ts
|
|
71
|
-
import fs from "fs";
|
|
72
|
-
import { glob } from "glob";
|
|
73
|
-
var deleteGlob = (globPath) => {
|
|
74
|
-
const files = glob.sync(globPath);
|
|
75
|
-
for (const file of files) {
|
|
76
|
-
fs.rmSync(file, { recursive: true, force: true });
|
|
77
|
-
}
|
|
78
|
-
};
|
|
79
|
-
|
|
80
|
-
// src/lib/dependencies/detectDuplicateDependencies.ts
|
|
81
|
-
import { execSync } from "child_process";
|
|
82
|
-
|
|
83
|
-
// src/lib/processEx.ts
|
|
84
|
-
import chalk2 from "chalk";
|
|
85
|
-
|
|
86
|
-
// src/lib/withError.ts
|
|
87
|
-
var withError = (ex, closure, predicate = (ex2) => !!ex2.name && !!ex2.message) => {
|
|
88
|
-
return predicate(ex) ? closure(ex) : void 0;
|
|
89
|
-
};
|
|
90
|
-
|
|
91
|
-
// src/lib/withErrnoException.ts
|
|
92
|
-
var withErrnoException = (ex, closure) => {
|
|
93
|
-
return withError(ex, closure, (ex2) => ex2.errno !== void 0);
|
|
94
|
-
};
|
|
95
|
-
|
|
96
|
-
// src/lib/processEx.ts
|
|
97
|
-
var processEx = (ex) => {
|
|
98
|
-
const error = typeof ex === "string" ? new Error(ex) : ex;
|
|
99
|
-
const exitCode = withErrnoException(error, (error2) => {
|
|
100
|
-
if (error2.code === "ENOENT") {
|
|
101
|
-
console.error(chalk2.red(`'${error2.path}' not found.`));
|
|
102
|
-
} else {
|
|
103
|
-
console.error(chalk2.red(`Errno: ${error2.code}`));
|
|
104
|
-
}
|
|
105
|
-
return error2.errno ?? -1;
|
|
106
|
-
}) ?? withError(error, (error2) => {
|
|
107
|
-
console.error(chalk2.red(`${error2.name}: ${error2.message}`));
|
|
108
|
-
return -1;
|
|
109
|
-
}) ?? (() => {
|
|
110
|
-
console.error(chalk2.red(`Unexpected Error: ${JSON.stringify(ex, null, 2)}`));
|
|
111
|
-
return -1;
|
|
112
|
-
})();
|
|
113
|
-
process.exit(process.exitCode ?? exitCode);
|
|
114
|
-
};
|
|
115
|
-
|
|
116
|
-
// src/lib/safeExit.ts
|
|
117
|
-
var safeExit = (func, exitOnFail = true) => {
|
|
118
|
-
try {
|
|
119
|
-
const result = func();
|
|
120
|
-
if (result && exitOnFail) {
|
|
121
|
-
process.exit(result);
|
|
122
|
-
}
|
|
123
|
-
return result;
|
|
124
|
-
} catch (ex) {
|
|
125
|
-
return processEx(ex);
|
|
126
|
-
}
|
|
127
|
-
};
|
|
128
|
-
var safeExitAsync = async (func, exitOnFail = true) => {
|
|
129
|
-
try {
|
|
130
|
-
const result = await func();
|
|
131
|
-
if (result && exitOnFail) {
|
|
132
|
-
process.exit(result);
|
|
133
|
-
}
|
|
134
|
-
return result;
|
|
135
|
-
} catch (ex) {
|
|
136
|
-
return processEx(ex);
|
|
137
|
-
}
|
|
138
|
-
};
|
|
139
|
-
|
|
140
|
-
// src/lib/dependencies/DuplicateDetector.ts
|
|
141
|
-
import { EOL } from "os";
|
|
142
|
-
import chalk3 from "chalk";
|
|
143
|
-
|
|
144
|
-
// src/lib/jsonFormatters.ts
|
|
145
|
-
var multiLineToJSONArray = (output) => {
|
|
146
|
-
const withCommas = output.replaceAll("\r\n", "").replaceAll("\n", ",");
|
|
147
|
-
const cleanCollection = withCommas.slice(0, Math.max(0, withCommas.length - 1));
|
|
148
|
-
const collection = `[${cleanCollection}]`;
|
|
149
|
-
return JSON.parse(collection);
|
|
150
|
-
};
|
|
151
|
-
|
|
152
|
-
// src/lib/dependencies/DuplicateDetector.ts
|
|
153
|
-
var trimVirtualMeta = (value) => {
|
|
154
|
-
const virtualParts = value.split("virtual:");
|
|
155
|
-
if (virtualParts.length > 1) {
|
|
156
|
-
const hashParts = virtualParts[1].split("#");
|
|
157
|
-
return virtualParts[0] + hashParts[1];
|
|
158
|
-
} else {
|
|
159
|
-
return value;
|
|
160
|
-
}
|
|
161
|
-
};
|
|
162
|
-
var trimObjectDependencyVirtualMeta = (obj) => {
|
|
163
|
-
const resultObj = {};
|
|
164
|
-
for (const [key, value] of Object.entries(obj)) {
|
|
165
|
-
resultObj[trimVirtualMeta(key)] = {
|
|
166
|
-
descriptor: trimVirtualMeta(value.descriptor),
|
|
167
|
-
locator: trimVirtualMeta(value.locator)
|
|
168
|
-
};
|
|
169
|
-
}
|
|
170
|
-
return resultObj;
|
|
171
|
-
};
|
|
172
|
-
var trimDependencyVirtualMeta = (dependencies) => {
|
|
173
|
-
return dependencies.map((dependency) => {
|
|
174
|
-
return { children: trimObjectDependencyVirtualMeta(dependency.children), value: trimVirtualMeta(dependency.value) };
|
|
175
|
-
});
|
|
176
|
-
};
|
|
177
|
-
var DuplicateDetector = class {
|
|
178
|
-
dependency;
|
|
179
|
-
dependencyEntries;
|
|
180
|
-
constructor(output, dependency) {
|
|
181
|
-
this.dependency = dependency;
|
|
182
|
-
this.dependencyEntries = trimDependencyVirtualMeta(multiLineToJSONArray(output));
|
|
183
|
-
}
|
|
184
|
-
detect() {
|
|
185
|
-
const result = this.dependencyEntries.reduce(this.detectReducer, this.resultsFactory(this.dependency));
|
|
186
|
-
if (result.duplicateVersions.length > 0) {
|
|
187
|
-
console.log(chalk3.yellow(`${EOL}Duplicates found for: ${this.dependency}`));
|
|
188
|
-
const duplicateVersions = result.duplicateVersions.toString().replaceAll(",", `${EOL} `);
|
|
189
|
-
console.log(chalk3.grey(` ${duplicateVersions}`, EOL));
|
|
190
|
-
return 1;
|
|
191
|
-
} else {
|
|
192
|
-
console.log(`${this.dependency} - OK`);
|
|
193
|
-
return 0;
|
|
194
|
-
}
|
|
195
|
-
}
|
|
196
|
-
detectReducer(acc, entry) {
|
|
197
|
-
const version = Object.entries(entry.children).map(([k]) => k)[0];
|
|
198
|
-
if (!acc.currentVersion) {
|
|
199
|
-
acc.currentVersion = version;
|
|
200
|
-
return acc;
|
|
201
|
-
}
|
|
202
|
-
if (acc.currentVersion && acc.currentVersion !== version && !version.includes("@virtual:")) {
|
|
203
|
-
if (acc.duplicateVersions.length === 0) {
|
|
204
|
-
acc.duplicateVersions.push(acc.currentVersion);
|
|
205
|
-
}
|
|
206
|
-
acc.duplicateVersions.push(version);
|
|
207
|
-
acc.duplicateVersions = [...new Set(acc.duplicateVersions)];
|
|
208
|
-
}
|
|
209
|
-
return acc;
|
|
210
|
-
}
|
|
211
|
-
resultsFactory = (dependency) => ({
|
|
212
|
-
currentVersion: void 0,
|
|
213
|
-
dependency,
|
|
214
|
-
duplicateVersions: []
|
|
215
|
-
});
|
|
216
|
-
};
|
|
217
|
-
|
|
218
|
-
// src/lib/dependencies/detectDuplicateDependencies.ts
|
|
219
|
-
var detectDuplicateDependencies = (depsFromPackageJSON, DefaultDependencies2) => {
|
|
220
|
-
let exitCode = 0;
|
|
221
|
-
const dependencies = depsFromPackageJSON?.length ? depsFromPackageJSON : DefaultDependencies2;
|
|
222
|
-
return safeExit(() => {
|
|
223
|
-
if (dependencies) {
|
|
224
|
-
for (const dependency of dependencies) {
|
|
225
|
-
let output;
|
|
226
|
-
try {
|
|
227
|
-
const cmd = `yarn why ${dependency} --json`;
|
|
228
|
-
output = execSync(cmd).toString();
|
|
229
|
-
} catch (e) {
|
|
230
|
-
console.error(`Error running yarn why: ${e}`);
|
|
231
|
-
exitCode = 1;
|
|
232
|
-
continue;
|
|
233
|
-
}
|
|
234
|
-
if (output) {
|
|
235
|
-
exitCode = new DuplicateDetector(output, dependency).detect();
|
|
236
|
-
} else {
|
|
237
|
-
console.log(`${dependency} - N/A`);
|
|
238
|
-
if (depsFromPackageJSON) {
|
|
239
|
-
exitCode = 1;
|
|
240
|
-
console.log(`\u{1F6A8} Library ${dependency} was requested in package.json but not found`);
|
|
241
|
-
}
|
|
242
|
-
}
|
|
243
|
-
}
|
|
244
|
-
return exitCode;
|
|
245
|
-
} else {
|
|
246
|
-
console.log("\u{1F6A8} No dependencies where passed");
|
|
247
|
-
return exitCode;
|
|
248
|
-
}
|
|
249
|
-
});
|
|
250
|
-
};
|
|
251
|
-
|
|
252
|
-
// src/lib/file/constants.ts
|
|
253
|
-
var WINDOWS_NEWLINE_REGEX = /\r\n/g;
|
|
254
|
-
var CROSS_PLATFORM_NEWLINE = "\n";
|
|
255
|
-
|
|
256
|
-
// src/lib/file/fileLines.ts
|
|
257
|
-
import {
|
|
258
|
-
existsSync,
|
|
259
|
-
readFileSync as readFileSync2,
|
|
260
|
-
writeFileSync
|
|
261
|
-
} from "fs";
|
|
262
|
-
|
|
263
|
-
// src/lib/string/empty.ts
|
|
264
|
-
var empty = (value) => value?.trim().length === 0;
|
|
265
|
-
var notEmpty = (value) => !empty(value);
|
|
266
|
-
|
|
267
|
-
// src/lib/string/union.ts
|
|
268
|
-
var union = (a, b) => /* @__PURE__ */ new Set([...new Set(a), ...new Set(b)]);
|
|
269
|
-
|
|
270
|
-
// src/lib/file/ReadFileSyncOptions.ts
|
|
271
|
-
var defaultReadFileSyncOptions = { encoding: "utf8" };
|
|
272
|
-
|
|
273
|
-
// src/lib/file/fileLines.ts
|
|
274
|
-
var readLines = (uri, options = defaultReadFileSyncOptions) => existsSync(uri) ? readFileSync2(uri, options).replace(WINDOWS_NEWLINE_REGEX, CROSS_PLATFORM_NEWLINE).split(CROSS_PLATFORM_NEWLINE) : [];
|
|
275
|
-
var readNonEmptyLines = (uri, options = defaultReadFileSyncOptions) => readLines(uri, options).filter(notEmpty);
|
|
276
|
-
var writeLines = (uri, lines, options = defaultReadFileSyncOptions) => {
|
|
277
|
-
const existing = existsSync(uri) ? readFileSync2(uri, options) : void 0;
|
|
278
|
-
const desired = lines.join(CROSS_PLATFORM_NEWLINE);
|
|
279
|
-
if (existing !== desired) writeFileSync(uri, desired, options);
|
|
280
|
-
};
|
|
281
|
-
|
|
282
|
-
// src/lib/generateIgnoreFiles.ts
|
|
283
|
-
import chalk4 from "chalk";
|
|
284
|
-
|
|
285
|
-
// src/lib/yarn/isYarnVersionOrGreater.ts
|
|
286
|
-
import { spawnSync } from "child_process";
|
|
287
|
-
var isYarnVersionOrGreater = (major, minor, patch) => {
|
|
288
|
-
const result = spawnSync("yarn", ["-v"], { encoding: "utf8", shell: true });
|
|
289
|
-
const version = result.stdout.toString().replaceAll("\n", "");
|
|
290
|
-
const versionNumbers = version.split(".").map((ver) => Number.parseInt(ver));
|
|
291
|
-
const majorDelta = versionNumbers[0] - major;
|
|
292
|
-
const minorDelta = versionNumbers[1] - (minor ?? versionNumbers[1]);
|
|
293
|
-
const patchDelta = versionNumbers[2] - (patch ?? versionNumbers[2]);
|
|
294
|
-
const majorOk = majorDelta >= 0;
|
|
295
|
-
const minorOk = majorDelta > 0 || minorDelta >= 0;
|
|
296
|
-
const patchOk = majorDelta > 0 || minorDelta > 0 || patchDelta >= 0;
|
|
297
|
-
return [majorOk && minorOk && patchOk, version];
|
|
298
|
-
};
|
|
299
|
-
|
|
300
|
-
// src/lib/yarn/workspace/yarnWorkspaces.ts
|
|
301
|
-
import { spawnSync as spawnSync2 } from "child_process";
|
|
302
|
-
var yarnWorkspaces = () => {
|
|
303
|
-
const result = spawnSync2("yarn", ["workspaces", "list", "--json", "--recursive"], { encoding: "utf8", shell: true });
|
|
304
|
-
if (result.error) {
|
|
305
|
-
throw result.error;
|
|
306
|
-
}
|
|
307
|
-
return result.stdout.toString().split("\n").slice(0, -1).map((item) => {
|
|
308
|
-
return JSON.parse(item);
|
|
309
|
-
});
|
|
310
|
-
};
|
|
311
|
-
|
|
312
|
-
// src/lib/yarn/workspace/yarnWorkspace.ts
|
|
313
|
-
var yarnWorkspace = (pkg) => {
|
|
314
|
-
const workspace = yarnWorkspaces().find(({ name }) => name === pkg);
|
|
315
|
-
if (!workspace) throw new Error(`Workspace ${pkg} not found`);
|
|
316
|
-
return workspace;
|
|
317
|
-
};
|
|
318
|
-
|
|
319
|
-
// src/lib/yarn/yarnInitCwd.ts
|
|
320
|
-
var INIT_CWD = () => {
|
|
321
|
-
if (!process.env.INIT_CWD) console.error("Missing INIT_CWD");
|
|
322
|
-
return process.env.INIT_CWD;
|
|
323
|
-
};
|
|
324
|
-
|
|
325
|
-
// src/lib/generateIgnoreFiles.ts
|
|
326
|
-
var localeCompare = (a, b) => a.localeCompare(b);
|
|
327
|
-
var mergeEntries = (a, b) => [...union(a, b)].toSorted(localeCompare);
|
|
328
|
-
var generateIgnoreFiles = (filename2, pkg) => {
|
|
329
|
-
console.log(chalk4.green(`Generate ${filename2} Files`));
|
|
330
|
-
const cwd5 = INIT_CWD() ?? ".";
|
|
331
|
-
const workspaces = pkg ? [yarnWorkspace(pkg)] : yarnWorkspaces();
|
|
332
|
-
const readEntries = (location) => readNonEmptyLines(`${location}/${filename2}`);
|
|
333
|
-
const writeEntries = (location, entries) => writeLines(`${location}/${filename2}`, entries);
|
|
334
|
-
const results = workspaces.map(({ location, name }) => {
|
|
335
|
-
try {
|
|
336
|
-
writeEntries(location, mergeEntries(readEntries(cwd5), readEntries(location)));
|
|
337
|
-
return 0;
|
|
338
|
-
} catch (ex) {
|
|
339
|
-
const error = ex;
|
|
340
|
-
console.error(`Generate ${filename2} Files [${name}] [${error.message}]`);
|
|
341
|
-
return 1;
|
|
342
|
-
}
|
|
343
|
-
});
|
|
344
|
-
const succeeded = results.every((result) => result === 0);
|
|
345
|
-
return succeeded ? 0 : 1;
|
|
346
|
-
};
|
|
347
|
-
|
|
348
|
-
// src/lib/generateReadmeFiles.ts
|
|
349
|
-
import { execSync as execSync2 } from "child_process";
|
|
350
|
-
import FS, { readFileSync as readFileSync3 } from "fs";
|
|
351
|
-
import {
|
|
352
|
-
mkdir,
|
|
353
|
-
readFile,
|
|
354
|
-
writeFile
|
|
355
|
-
} from "fs/promises";
|
|
356
|
-
import { createRequire as createRequire2 } from "module";
|
|
357
|
-
import PATH2 from "path";
|
|
358
|
-
import { createInterface } from "readline";
|
|
359
|
-
import chalk5 from "chalk";
|
|
360
|
-
var require3 = createRequire2(import.meta.url);
|
|
361
|
-
var packageRoot2 = PATH2.dirname(require3.resolve("@xylabs/ts-scripts-yarn3/package.json"));
|
|
362
|
-
var readmeTemplatesDir = PATH2.resolve(packageRoot2, "templates", "readme");
|
|
363
|
-
function fillTemplate(template, data) {
|
|
364
|
-
const additionalData = { ...data, safeName: data.name.replaceAll("/", "__").replaceAll("@", "") };
|
|
365
|
-
return template.replaceAll(/\{\{(.*?)\}\}/g, (_, key) => additionalData[key.trim()] ?? "");
|
|
366
|
-
}
|
|
367
|
-
function generateTypedoc(packageLocation, entryPoints) {
|
|
368
|
-
const tempDir = PATH2.join(packageLocation, ".temp-typedoc");
|
|
369
|
-
try {
|
|
370
|
-
if (!FS.existsSync(tempDir)) {
|
|
371
|
-
FS.mkdirSync(tempDir, { recursive: true });
|
|
372
|
-
}
|
|
373
|
-
const typedocConfig = {
|
|
374
|
-
disableSources: true,
|
|
375
|
-
entryPointStrategy: "expand",
|
|
376
|
-
entryPoints: entryPoints.map((ep) => PATH2.resolve(packageLocation, ep)),
|
|
377
|
-
excludeExternals: true,
|
|
378
|
-
excludeInternal: true,
|
|
379
|
-
excludePrivate: true,
|
|
380
|
-
githubPages: false,
|
|
381
|
-
hideBreadcrumbs: true,
|
|
382
|
-
hideGenerator: true,
|
|
383
|
-
hidePageTitle: true,
|
|
384
|
-
out: tempDir,
|
|
385
|
-
plugin: ["typedoc-plugin-markdown"],
|
|
386
|
-
readme: "none",
|
|
387
|
-
skipErrorChecking: true,
|
|
388
|
-
sort: ["source-order"],
|
|
389
|
-
theme: "markdown",
|
|
390
|
-
useCodeBlocks: true
|
|
391
|
-
};
|
|
392
|
-
const typedocJsonPath = PATH2.join(tempDir, "typedoc.json");
|
|
393
|
-
FS.writeFileSync(typedocJsonPath, JSON.stringify(typedocConfig, null, 2));
|
|
394
|
-
try {
|
|
395
|
-
execSync2(`npx typedoc --options ${typedocJsonPath}`, {
|
|
396
|
-
cwd: process.cwd(),
|
|
397
|
-
stdio: ["ignore", "pipe", "pipe"]
|
|
398
|
-
});
|
|
399
|
-
} catch {
|
|
400
|
-
return "";
|
|
401
|
-
}
|
|
402
|
-
return consolidateMarkdown(tempDir);
|
|
403
|
-
} catch {
|
|
404
|
-
return "";
|
|
405
|
-
} finally {
|
|
406
|
-
try {
|
|
407
|
-
FS.rmSync(tempDir, { force: true, recursive: true });
|
|
408
|
-
} catch {
|
|
409
|
-
}
|
|
410
|
-
}
|
|
411
|
-
}
|
|
412
|
-
function consolidateMarkdown(tempDir) {
|
|
413
|
-
let consolidated = "## Reference\n\n";
|
|
414
|
-
const mainReadmePath = PATH2.join(tempDir, "README.md");
|
|
415
|
-
if (FS.existsSync(mainReadmePath)) {
|
|
416
|
-
const mainContent = FS.readFileSync(mainReadmePath, "utf8").replace(/^---(.|\n)*?---\n/, "").replace(/^# .+\n/, "").replaceAll(/\]\((.+?)\.md\)/g, "](#$1)");
|
|
417
|
-
consolidated += mainContent + "\n\n";
|
|
418
|
-
}
|
|
419
|
-
consolidated += processDirectory(tempDir);
|
|
420
|
-
return consolidated.replaceAll(/\n\n\n+/g, "\n\n").replaceAll(/^#### /gm, "### ").replaceAll(/^##### /gm, "#### ").replaceAll(/^###### /gm, "##### ");
|
|
421
|
-
}
|
|
422
|
-
function processDirectory(dir, level = 0) {
|
|
423
|
-
const indent = " ".repeat(level);
|
|
424
|
-
let content = "";
|
|
425
|
-
try {
|
|
426
|
-
const items = FS.readdirSync(dir, { withFileTypes: true });
|
|
427
|
-
for (const item of items) {
|
|
428
|
-
if (item.isDirectory()) continue;
|
|
429
|
-
if (item.name === "README.md" || !item.name.endsWith(".md")) continue;
|
|
430
|
-
const fileContent = FS.readFileSync(PATH2.join(dir, item.name), "utf8").replace(/^---(.|\n)*?---\n/, "");
|
|
431
|
-
const moduleName = item.name.replace(".md", "");
|
|
432
|
-
content += `
|
|
433
|
-
|
|
434
|
-
${indent}### <a id="${moduleName}"></a>${moduleName}
|
|
435
|
-
|
|
436
|
-
`;
|
|
437
|
-
content += fileContent.replace(/^# .+\n/, "").replaceAll(/\]\((.+?)\.md\)/g, "](#$1)");
|
|
438
|
-
}
|
|
439
|
-
for (const item of items) {
|
|
440
|
-
if (!item.isDirectory()) continue;
|
|
441
|
-
if (item.name === "spec" || item.name.includes(".spec")) continue;
|
|
442
|
-
content += `
|
|
443
|
-
|
|
444
|
-
${indent}### ${item.name}
|
|
445
|
-
`;
|
|
446
|
-
content += processDirectory(PATH2.join(dir, item.name), level + 1);
|
|
447
|
-
}
|
|
448
|
-
} catch {
|
|
449
|
-
}
|
|
450
|
-
return content;
|
|
451
|
-
}
|
|
452
|
-
function askConfirmation(question) {
|
|
453
|
-
const rl = createInterface({ input: process.stdin, output: process.stdout });
|
|
454
|
-
return new Promise((resolve) => {
|
|
455
|
-
rl.question(question, (answer) => {
|
|
456
|
-
rl.close();
|
|
457
|
-
resolve(answer.toLowerCase() === "y" || answer.toLowerCase() === "yes");
|
|
458
|
-
});
|
|
459
|
-
});
|
|
460
|
-
}
|
|
461
|
-
var DEFAULT_README_TEMPLATE = readFileSync3(PATH2.resolve(readmeTemplatesDir, "README.template.md"), "utf8");
|
|
462
|
-
var DEFAULT_README_BODY = readFileSync3(PATH2.resolve(readmeTemplatesDir, "README.body.md"), "utf8");
|
|
463
|
-
function applyLogoConfig(template, logoUrl, logoLinkUrl) {
|
|
464
|
-
let result = template;
|
|
465
|
-
if (logoUrl) {
|
|
466
|
-
result = result.replace(/\[logo]: .+/, `[logo]: ${logoUrl}`);
|
|
467
|
-
if (logoLinkUrl) {
|
|
468
|
-
result = result.replace(/\[!\[logo]\[]][^)]*\)/, `[![logo][]](${logoLinkUrl})`);
|
|
469
|
-
}
|
|
470
|
-
} else {
|
|
471
|
-
result = result.replace(/\[!\[logo]\[]][^\n]*\n*/, "");
|
|
472
|
-
result = result.replace(/\[logo]: [^\n]*\n?/, "");
|
|
473
|
-
}
|
|
474
|
-
return result;
|
|
475
|
-
}
|
|
476
|
-
function resolveTemplatePath(templatePath) {
|
|
477
|
-
const cwd5 = INIT_CWD() ?? ".";
|
|
478
|
-
return templatePath ?? PATH2.join(cwd5, ".xy", "README.template.md");
|
|
479
|
-
}
|
|
480
|
-
async function loadOrCreateTemplate(resolvedTemplatePath) {
|
|
481
|
-
try {
|
|
482
|
-
const template = await readFile(resolvedTemplatePath, "utf8");
|
|
483
|
-
return { created: false, template };
|
|
484
|
-
} catch {
|
|
485
|
-
console.log(chalk5.yellow(`Template not found: ${resolvedTemplatePath}`));
|
|
486
|
-
const shouldCreate = await askConfirmation("Would you like to create a stock template? (y/N) ");
|
|
487
|
-
if (!shouldCreate) {
|
|
488
|
-
throw new Error("Template creation declined");
|
|
489
|
-
}
|
|
490
|
-
const template = DEFAULT_README_TEMPLATE;
|
|
491
|
-
await scaffoldTemplate(resolvedTemplatePath, template);
|
|
492
|
-
return { created: true, template };
|
|
493
|
-
}
|
|
494
|
-
}
|
|
495
|
-
async function scaffoldTemplate(resolvedTemplatePath, template) {
|
|
496
|
-
const xyDir = PATH2.dirname(resolvedTemplatePath);
|
|
497
|
-
await mkdir(xyDir, { recursive: true });
|
|
498
|
-
await writeFile(resolvedTemplatePath, template);
|
|
499
|
-
console.log(chalk5.green(`Created template: ${resolvedTemplatePath}`));
|
|
500
|
-
const bodyPath = PATH2.join(xyDir, "README.body.md");
|
|
501
|
-
await writeFile(bodyPath, DEFAULT_README_BODY);
|
|
502
|
-
console.log(chalk5.green(`Created body template: ${bodyPath}`));
|
|
503
|
-
}
|
|
504
|
-
async function resolveBody(location, defaultBody) {
|
|
505
|
-
const localBodyPath = PATH2.join(location, "README.body.md");
|
|
506
|
-
try {
|
|
507
|
-
return await readFile(localBodyPath, "utf8");
|
|
508
|
-
} catch {
|
|
509
|
-
return defaultBody;
|
|
510
|
-
}
|
|
511
|
-
}
|
|
512
|
-
async function generateReadmeForWorkspace(location, name, template, defaultBody, typedoc, verbose) {
|
|
513
|
-
try {
|
|
514
|
-
const pkgJsonPath = PATH2.join(location, "package.json");
|
|
515
|
-
const pkgJson = JSON.parse(await readFile(pkgJsonPath, "utf8"));
|
|
516
|
-
const body = await resolveBody(location, defaultBody);
|
|
517
|
-
const typedocContent = typedoc ? generateTypedoc(location, ["src/index*.ts"]) : "";
|
|
518
|
-
const readmeContent = fillTemplate(template, {
|
|
519
|
-
...pkgJson,
|
|
520
|
-
body,
|
|
521
|
-
typedoc: typedocContent
|
|
522
|
-
});
|
|
523
|
-
await writeFile(PATH2.join(location, "README.md"), readmeContent);
|
|
524
|
-
if (verbose) console.log(chalk5.green(` ${name}`));
|
|
525
|
-
return true;
|
|
526
|
-
} catch (ex) {
|
|
527
|
-
const error = ex;
|
|
528
|
-
console.warn(chalk5.yellow(` Skipped ${location}: ${error.message}`));
|
|
529
|
-
return false;
|
|
530
|
-
}
|
|
531
|
-
}
|
|
532
|
-
async function generateReadmeFiles({
|
|
533
|
-
logoLinkUrl,
|
|
534
|
-
logoUrl,
|
|
535
|
-
pkg,
|
|
536
|
-
templatePath,
|
|
537
|
-
typedoc = false,
|
|
538
|
-
verbose = false
|
|
539
|
-
}) {
|
|
540
|
-
console.log(chalk5.green("Generate README Files"));
|
|
541
|
-
const resolvedTemplatePath = resolveTemplatePath(templatePath);
|
|
542
|
-
let template;
|
|
543
|
-
let templateCreated;
|
|
544
|
-
try {
|
|
545
|
-
({ template, created: templateCreated } = await loadOrCreateTemplate(resolvedTemplatePath));
|
|
546
|
-
} catch {
|
|
547
|
-
return 1;
|
|
548
|
-
}
|
|
549
|
-
template = applyLogoConfig(template, logoUrl, logoLinkUrl);
|
|
550
|
-
if (templateCreated) {
|
|
551
|
-
console.log(chalk5.green("Generating README files for all packages..."));
|
|
552
|
-
}
|
|
553
|
-
const xyDir = PATH2.dirname(resolvedTemplatePath);
|
|
554
|
-
const xyBodyPath = PATH2.join(xyDir, "README.body.md");
|
|
555
|
-
let defaultBody;
|
|
556
|
-
try {
|
|
557
|
-
defaultBody = await readFile(xyBodyPath, "utf8");
|
|
558
|
-
} catch {
|
|
559
|
-
defaultBody = DEFAULT_README_BODY;
|
|
560
|
-
}
|
|
561
|
-
const workspaces = pkg && !templateCreated ? [yarnWorkspace(pkg)] : yarnWorkspaces();
|
|
562
|
-
let failed = false;
|
|
563
|
-
for (const { location, name } of workspaces) {
|
|
564
|
-
const success = await generateReadmeForWorkspace(location, name, template, defaultBody, typedoc, verbose);
|
|
565
|
-
if (!success) failed = true;
|
|
566
|
-
}
|
|
567
|
-
return failed ? 1 : 0;
|
|
568
|
-
}
|
|
569
|
-
|
|
570
|
-
// src/lib/gitignoreTemplate.ts
|
|
571
|
-
import { readFileSync as readFileSync4 } from "fs";
|
|
572
|
-
import { createRequire as createRequire3 } from "module";
|
|
573
|
-
import PATH3 from "path";
|
|
574
|
-
var require4 = createRequire3(import.meta.url);
|
|
575
|
-
var packageRoot3 = PATH3.dirname(require4.resolve("@xylabs/ts-scripts-yarn3/package.json"));
|
|
576
|
-
var templatesDir2 = PATH3.resolve(packageRoot3, "templates", "gitignore");
|
|
577
|
-
var gitignoreTemplate = () => readFileSync4(PATH3.resolve(templatesDir2, "template.gitignore"), "utf8");
|
|
578
|
-
|
|
579
|
-
// src/lib/loadConfig.ts
|
|
580
|
-
import chalk6 from "chalk";
|
|
581
|
-
import { cosmiconfig } from "cosmiconfig";
|
|
582
|
-
import { TypeScriptLoader } from "cosmiconfig-typescript-loader";
|
|
583
|
-
import deepmerge from "deepmerge";
|
|
584
|
-
var config;
|
|
585
|
-
var loadConfig = async (params) => {
|
|
586
|
-
if (config === void 0) {
|
|
587
|
-
const cosmicConfigResult = await cosmiconfig("xy", { cache: true, loaders: { ".ts": TypeScriptLoader() } }).search();
|
|
588
|
-
config = cosmicConfigResult?.config;
|
|
589
|
-
const configFilePath = cosmicConfigResult?.filepath;
|
|
590
|
-
if (configFilePath !== void 0) {
|
|
591
|
-
console.log(chalk6.green(`Loaded config from ${configFilePath}`));
|
|
592
|
-
if (config.verbose) {
|
|
593
|
-
console.log(chalk6.gray(`${JSON.stringify(config, null, 2)}`));
|
|
594
|
-
}
|
|
595
|
-
}
|
|
596
|
-
}
|
|
597
|
-
return deepmerge(config, params ?? {});
|
|
598
|
-
};
|
|
599
|
-
|
|
600
|
-
// src/lib/parsedPackageJSON.ts
|
|
601
|
-
import { readFileSync as readFileSync5 } from "fs";
|
|
602
|
-
var parsedPackageJSON = (path14) => {
|
|
603
|
-
const pathToPackageJSON = path14 ?? process.env.npm_package_json ?? "";
|
|
604
|
-
const packageJSON = readFileSync5(pathToPackageJSON).toString();
|
|
605
|
-
return JSON.parse(packageJSON);
|
|
606
|
-
};
|
|
607
|
-
|
|
608
|
-
// src/lib/runSteps.ts
|
|
609
|
-
import { spawnSync as spawnSync3 } from "child_process";
|
|
610
|
-
import { existsSync as existsSync2 } from "fs";
|
|
611
|
-
import chalk7 from "chalk";
|
|
612
|
-
var runSteps = (name, steps, exitOnFail = true, messages) => {
|
|
613
|
-
return safeExit(() => {
|
|
614
|
-
const pkgName = process.env.npm_package_name;
|
|
615
|
-
console.log(chalk7.green(`${name} [${pkgName}]`));
|
|
616
|
-
let totalStatus = 0;
|
|
617
|
-
for (const [i, [command, args, config2]] of steps.entries()) {
|
|
618
|
-
if (messages?.[i]) {
|
|
619
|
-
console.log(chalk7.gray(messages?.[i]));
|
|
620
|
-
}
|
|
621
|
-
const argList = Array.isArray(args) ? args : args.split(" ");
|
|
622
|
-
if (command === "node" && !existsSync2(argList[0])) {
|
|
623
|
-
throw new Error(`File not found [${argList[0]}]`);
|
|
624
|
-
}
|
|
625
|
-
const status = spawnSync3(command, Array.isArray(args) ? args : args.split(" "), {
|
|
626
|
-
...config2,
|
|
627
|
-
encoding: "utf8",
|
|
628
|
-
env: { FORCE_COLOR: "3", ...process.env },
|
|
629
|
-
shell: true,
|
|
630
|
-
stdio: "inherit"
|
|
631
|
-
}).status ?? 0;
|
|
632
|
-
checkResult(name, status, "error", exitOnFail);
|
|
633
|
-
totalStatus += status ?? 0;
|
|
634
|
-
}
|
|
635
|
-
return totalStatus;
|
|
636
|
-
}, !!exitOnFail);
|
|
637
|
-
};
|
|
638
|
-
|
|
639
|
-
// src/lib/runStepsAsync.ts
|
|
640
|
-
import { spawn } from "child_process";
|
|
641
|
-
import { existsSync as existsSync3 } from "fs";
|
|
642
|
-
import chalk8 from "chalk";
|
|
643
|
-
var runStepAsync = (name, step, exitOnFail = true, message) => {
|
|
644
|
-
return new Promise((resolve) => {
|
|
645
|
-
const [command, args, config2] = step;
|
|
646
|
-
if (message) {
|
|
647
|
-
console.log(chalk8.gray(message));
|
|
648
|
-
}
|
|
649
|
-
const argList = Array.isArray(args) ? args : args.split(" ");
|
|
650
|
-
if (command === "node" && !existsSync3(argList[0])) {
|
|
651
|
-
throw new Error(`File not found [${argList[0]}]`);
|
|
652
|
-
}
|
|
653
|
-
spawn(command, Array.isArray(args) ? args : args.split(" "), {
|
|
654
|
-
...config2,
|
|
655
|
-
env: { FORCE_COLOR: "3", ...process.env },
|
|
656
|
-
shell: true,
|
|
657
|
-
stdio: "inherit"
|
|
658
|
-
}).on("close", (code) => {
|
|
659
|
-
if (code) {
|
|
660
|
-
console.error(
|
|
661
|
-
chalk8.red(
|
|
662
|
-
`Command Exited With Non-Zero Result [${chalk8.gray(code)}] | ${chalk8.yellow(command)} ${chalk8.white(
|
|
663
|
-
Array.isArray(args) ? args.join(" ") : args
|
|
664
|
-
)}`
|
|
665
|
-
)
|
|
666
|
-
);
|
|
667
|
-
checkResult(name, code, "error", exitOnFail);
|
|
668
|
-
resolve(code);
|
|
669
|
-
} else {
|
|
670
|
-
resolve(0);
|
|
671
|
-
}
|
|
672
|
-
});
|
|
673
|
-
});
|
|
674
|
-
};
|
|
675
|
-
var runStepsAsync = async (name, steps, exitOnFail = true, messages) => {
|
|
676
|
-
return await safeExitAsync(async () => {
|
|
677
|
-
const pkgName = process.env.npm_package_name;
|
|
678
|
-
console.log(chalk8.green(`${name} [${pkgName}]`));
|
|
679
|
-
let result = 0;
|
|
680
|
-
for (const [i, step] of steps.entries()) {
|
|
681
|
-
result += await runStepAsync(name, step, exitOnFail, messages?.[i]);
|
|
682
|
-
}
|
|
683
|
-
return result;
|
|
684
|
-
});
|
|
685
|
-
};
|
|
686
|
-
|
|
687
|
-
// src/actions/build.ts
|
|
688
|
-
var build = async ({
|
|
689
|
-
incremental,
|
|
690
|
-
jobs,
|
|
691
|
-
target,
|
|
692
|
-
verbose,
|
|
693
|
-
pkg
|
|
694
|
-
}) => {
|
|
695
|
-
const start = Date.now();
|
|
696
|
-
const pkgOptions = pkg === void 0 ? [] : [pkg];
|
|
697
|
-
const incrementalOptions = incremental ? ["-i"] : [];
|
|
698
|
-
const verboseOptions = verbose ? ["-v"] : [];
|
|
699
|
-
const targetOptions = target === void 0 ? [] : ["-t", target];
|
|
700
|
-
const jobsOptions = jobs === void 0 ? [] : ["-j", `${jobs}`];
|
|
701
|
-
if (jobs !== void 0) {
|
|
702
|
-
console.log(chalk9.blue(`Jobs set to [${jobs}]`));
|
|
703
|
-
}
|
|
704
|
-
const result = await runStepsAsync(`Build${incremental ? "-Incremental" : ""} [${pkg ?? "All"}]`, [
|
|
705
|
-
["yarn", ["xy", "compile", ...pkgOptions, ...targetOptions, ...verboseOptions, ...jobsOptions, ...incrementalOptions, "--types", "tsup"]],
|
|
706
|
-
["yarn", ["xy", "publint", ...pkgOptions, ...verboseOptions, ...jobsOptions, ...incrementalOptions]],
|
|
707
|
-
["yarn", ["xy", "deplint", ...pkgOptions, ...verboseOptions, ...jobsOptions, ...incrementalOptions]],
|
|
708
|
-
["yarn", ["xy", "lint", ...pkgOptions, ...verboseOptions, ...incrementalOptions]]
|
|
709
|
-
]);
|
|
710
|
-
console.log(`${chalk9.gray("Built in")} [${chalk9.magenta(((Date.now() - start) / 1e3).toFixed(2))}] ${chalk9.gray("seconds")}`);
|
|
711
|
-
return result;
|
|
712
|
-
};
|
|
713
|
-
|
|
714
|
-
// src/actions/claude-clean.ts
|
|
715
|
-
import {
|
|
716
|
-
existsSync as existsSync4,
|
|
717
|
-
readdirSync as readdirSync2,
|
|
718
|
-
rmSync,
|
|
719
|
-
unlinkSync
|
|
720
|
-
} from "fs";
|
|
721
|
-
import PATH4 from "path";
|
|
722
|
-
import chalk10 from "chalk";
|
|
723
|
-
function removeFile(filePath, label) {
|
|
724
|
-
if (existsSync4(filePath)) {
|
|
725
|
-
unlinkSync(filePath);
|
|
726
|
-
console.log(chalk10.yellow(` Removed ${label}`));
|
|
727
|
-
return true;
|
|
728
|
-
}
|
|
729
|
-
return false;
|
|
730
|
-
}
|
|
731
|
-
function removeDir(dirPath, label) {
|
|
732
|
-
if (existsSync4(dirPath)) {
|
|
733
|
-
rmSync(dirPath, { recursive: true });
|
|
734
|
-
console.log(chalk10.yellow(` Removed ${label}`));
|
|
735
|
-
return true;
|
|
736
|
-
}
|
|
737
|
-
return false;
|
|
738
|
-
}
|
|
739
|
-
function claudeClean() {
|
|
740
|
-
console.log(chalk10.green("Clean Claude configuration"));
|
|
741
|
-
const cwd5 = INIT_CWD() ?? process.cwd();
|
|
742
|
-
let removed = 0;
|
|
743
|
-
const rootFiles = ["CLAUDE.md", "CLAUDE.local.md"];
|
|
744
|
-
for (const file of rootFiles) {
|
|
745
|
-
if (removeFile(PATH4.resolve(cwd5, file), file)) removed++;
|
|
746
|
-
}
|
|
747
|
-
if (removeDir(PATH4.resolve(cwd5, ".claude"), ".claude/")) removed++;
|
|
748
|
-
const packagesDir = PATH4.resolve(cwd5, "packages");
|
|
749
|
-
if (existsSync4(packagesDir)) {
|
|
750
|
-
const findClaudeFiles = (dir, prefix) => {
|
|
751
|
-
const entries = readdirSync2(dir, { withFileTypes: true });
|
|
752
|
-
for (const entry of entries) {
|
|
753
|
-
const fullPath = PATH4.resolve(dir, entry.name);
|
|
754
|
-
const label = `${prefix}${entry.name}`;
|
|
755
|
-
if (entry.isFile() && (entry.name === "CLAUDE.md" || entry.name === "CLAUDE.local.md")) {
|
|
756
|
-
if (removeFile(fullPath, label)) removed++;
|
|
757
|
-
} else if (entry.isDirectory() && entry.name === ".claude") {
|
|
758
|
-
if (removeDir(fullPath, `${label}/`)) removed++;
|
|
759
|
-
} else if (entry.isDirectory() && entry.name !== "node_modules" && entry.name !== "dist") {
|
|
760
|
-
findClaudeFiles(fullPath, `${label}/`);
|
|
761
|
-
}
|
|
762
|
-
}
|
|
763
|
-
};
|
|
764
|
-
findClaudeFiles(packagesDir, "packages/");
|
|
765
|
-
}
|
|
766
|
-
if (removed > 0) {
|
|
767
|
-
console.log(chalk10.green(` Removed ${removed} item(s)`));
|
|
768
|
-
} else {
|
|
769
|
-
console.log(chalk10.gray(" Nothing to clean"));
|
|
770
|
-
}
|
|
771
|
-
return 0;
|
|
772
|
-
}
|
|
773
|
-
|
|
774
|
-
// src/actions/claude-commands.ts
|
|
775
|
-
import {
|
|
776
|
-
existsSync as existsSync5,
|
|
777
|
-
mkdirSync,
|
|
778
|
-
readdirSync as readdirSync3,
|
|
779
|
-
readFileSync as readFileSync6,
|
|
780
|
-
unlinkSync as unlinkSync2,
|
|
781
|
-
writeFileSync as writeFileSync2
|
|
782
|
-
} from "fs";
|
|
783
|
-
import PATH5 from "path";
|
|
784
|
-
import chalk11 from "chalk";
|
|
785
|
-
var syncCommandFiles = (commandsDir) => {
|
|
786
|
-
const templates = claudeCommandTemplates();
|
|
787
|
-
const templateNames = new Set(Object.keys(templates));
|
|
788
|
-
let updated = 0;
|
|
789
|
-
let created = 0;
|
|
790
|
-
for (const [filename2, content] of Object.entries(templates)) {
|
|
791
|
-
const targetPath = PATH5.resolve(commandsDir, filename2);
|
|
792
|
-
const existing = existsSync5(targetPath) ? readFileSync6(targetPath, "utf8") : void 0;
|
|
793
|
-
if (existing === content) continue;
|
|
794
|
-
writeFileSync2(targetPath, content, "utf8");
|
|
795
|
-
if (existing) {
|
|
796
|
-
updated++;
|
|
797
|
-
} else {
|
|
798
|
-
created++;
|
|
799
|
-
}
|
|
800
|
-
}
|
|
801
|
-
return {
|
|
802
|
-
created,
|
|
803
|
-
templateNames,
|
|
804
|
-
updated
|
|
805
|
-
};
|
|
806
|
-
};
|
|
807
|
-
var removeStaleCommands = (commandsDir, templateNames) => {
|
|
808
|
-
const existingCommands = readdirSync3(commandsDir).filter((f) => f.startsWith(XYLABS_COMMANDS_PREFIX) && f.endsWith(".md"));
|
|
809
|
-
let removed = 0;
|
|
810
|
-
for (const file of existingCommands) {
|
|
811
|
-
if (!templateNames.has(file)) {
|
|
812
|
-
unlinkSync2(PATH5.resolve(commandsDir, file));
|
|
813
|
-
removed++;
|
|
814
|
-
}
|
|
815
|
-
}
|
|
816
|
-
return removed;
|
|
817
|
-
};
|
|
818
|
-
var removeLegacyCommands = (commandsDir) => {
|
|
819
|
-
const legacyFiles = readdirSync3(commandsDir).filter((f) => f.startsWith(LEGACY_COMMANDS_PREFIX) && f.endsWith(".md"));
|
|
820
|
-
for (const file of legacyFiles) {
|
|
821
|
-
unlinkSync2(PATH5.resolve(commandsDir, file));
|
|
822
|
-
}
|
|
823
|
-
return legacyFiles.length;
|
|
824
|
-
};
|
|
825
|
-
var logCommandsResult = (created, updated, removed) => {
|
|
826
|
-
if (created || updated || removed) {
|
|
827
|
-
const parts = [
|
|
828
|
-
created ? `${created} created` : "",
|
|
829
|
-
updated ? `${updated} updated` : "",
|
|
830
|
-
removed ? `${removed} removed` : ""
|
|
831
|
-
].filter(Boolean);
|
|
832
|
-
console.log(chalk11.green(`.claude/commands/${XYLABS_COMMANDS_PREFIX}*.md: ${parts.join(", ")}`));
|
|
833
|
-
} else {
|
|
834
|
-
console.log(chalk11.gray(`.claude/commands/${XYLABS_COMMANDS_PREFIX}*.md: already up to date`));
|
|
835
|
-
}
|
|
836
|
-
};
|
|
837
|
-
var claudeCommands = () => {
|
|
838
|
-
const cwd5 = INIT_CWD() ?? process.cwd();
|
|
839
|
-
const commandsDir = PATH5.resolve(cwd5, ".claude", "commands");
|
|
840
|
-
mkdirSync(commandsDir, { recursive: true });
|
|
841
|
-
const legacy = removeLegacyCommands(commandsDir);
|
|
842
|
-
const {
|
|
843
|
-
created,
|
|
844
|
-
templateNames,
|
|
845
|
-
updated
|
|
846
|
-
} = syncCommandFiles(commandsDir);
|
|
847
|
-
const removed = removeStaleCommands(commandsDir, templateNames);
|
|
848
|
-
logCommandsResult(created, updated, removed + legacy);
|
|
849
|
-
return 0;
|
|
850
|
-
};
|
|
851
|
-
|
|
852
|
-
// src/actions/claude-rules.ts
|
|
853
|
-
import { spawnSync as spawnSync4 } from "child_process";
|
|
854
|
-
import {
|
|
855
|
-
existsSync as existsSync6,
|
|
856
|
-
mkdirSync as mkdirSync2,
|
|
857
|
-
readdirSync as readdirSync4,
|
|
858
|
-
readFileSync as readFileSync7,
|
|
859
|
-
unlinkSync as unlinkSync3,
|
|
860
|
-
writeFileSync as writeFileSync3
|
|
861
|
-
} from "fs";
|
|
862
|
-
import PATH6 from "path";
|
|
863
|
-
import chalk12 from "chalk";
|
|
864
|
-
var syncRuleFiles = (rulesDir) => {
|
|
865
|
-
const templates = claudeMdRuleTemplates();
|
|
866
|
-
const templateNames = new Set(Object.keys(templates));
|
|
867
|
-
let updated = 0;
|
|
868
|
-
let created = 0;
|
|
869
|
-
for (const [filename2, content] of Object.entries(templates)) {
|
|
870
|
-
const targetPath = PATH6.resolve(rulesDir, filename2);
|
|
871
|
-
const existing = existsSync6(targetPath) ? readFileSync7(targetPath, "utf8") : void 0;
|
|
872
|
-
if (existing === content) continue;
|
|
873
|
-
writeFileSync3(targetPath, content, "utf8");
|
|
874
|
-
if (existing) {
|
|
875
|
-
updated++;
|
|
876
|
-
} else {
|
|
877
|
-
created++;
|
|
878
|
-
}
|
|
879
|
-
}
|
|
880
|
-
return {
|
|
881
|
-
created,
|
|
882
|
-
templateNames,
|
|
883
|
-
updated
|
|
884
|
-
};
|
|
885
|
-
};
|
|
886
|
-
var removeStaleRules = (rulesDir, templateNames) => {
|
|
887
|
-
const existingRules = readdirSync4(rulesDir).filter((f) => f.startsWith(XYLABS_RULES_PREFIX) && f.endsWith(".md"));
|
|
888
|
-
let removed = 0;
|
|
889
|
-
for (const file of existingRules) {
|
|
890
|
-
if (!templateNames.has(file)) {
|
|
891
|
-
unlinkSync3(PATH6.resolve(rulesDir, file));
|
|
892
|
-
removed++;
|
|
893
|
-
}
|
|
894
|
-
}
|
|
895
|
-
return removed;
|
|
896
|
-
};
|
|
897
|
-
var logRulesResult = (created, updated, removed) => {
|
|
898
|
-
if (created || updated || removed) {
|
|
899
|
-
const parts = [
|
|
900
|
-
created ? `${created} created` : "",
|
|
901
|
-
updated ? `${updated} updated` : "",
|
|
902
|
-
removed ? `${removed} removed` : ""
|
|
903
|
-
].filter(Boolean);
|
|
904
|
-
console.log(chalk12.green(`.claude/rules/${XYLABS_RULES_PREFIX}*.md: ${parts.join(", ")}`));
|
|
905
|
-
} else {
|
|
906
|
-
console.log(chalk12.gray(`.claude/rules/${XYLABS_RULES_PREFIX}*.md: already up to date`));
|
|
907
|
-
}
|
|
908
|
-
};
|
|
909
|
-
var ensureProjectClaudeMd = (cwd5, force) => {
|
|
910
|
-
const projectPath = PATH6.resolve(cwd5, "CLAUDE.md");
|
|
911
|
-
if (!existsSync6(projectPath) || force) {
|
|
912
|
-
if (force && existsSync6(projectPath)) {
|
|
913
|
-
console.log(chalk12.yellow("Regenerating CLAUDE.md"));
|
|
914
|
-
}
|
|
915
|
-
console.log(chalk12.green("Generating CLAUDE.md via claude /init..."));
|
|
916
|
-
const result = spawnSync4("claude", ["-p", "/init", "--allowedTools", "Read", "Write", "Glob", "Grep"], {
|
|
917
|
-
cwd: cwd5,
|
|
918
|
-
shell: true,
|
|
919
|
-
stdio: "inherit"
|
|
920
|
-
});
|
|
921
|
-
if (result.status !== 0) {
|
|
922
|
-
console.error(chalk12.red("claude /init failed \u2014 is Claude Code installed?"));
|
|
923
|
-
return 1;
|
|
924
|
-
}
|
|
925
|
-
} else {
|
|
926
|
-
console.log(chalk12.gray("CLAUDE.md already exists (skipped, use --force to regenerate)"));
|
|
927
|
-
}
|
|
928
|
-
return 0;
|
|
929
|
-
};
|
|
930
|
-
var ensureLocalClaudeMd = (cwd5) => {
|
|
931
|
-
const localPath = PATH6.resolve(cwd5, "CLAUDE.local.md");
|
|
932
|
-
if (existsSync6(localPath)) {
|
|
933
|
-
console.log(chalk12.gray("CLAUDE.local.md already exists (skipped)"));
|
|
934
|
-
} else {
|
|
935
|
-
writeFileSync3(localPath, claudeMdLocalTemplate(), "utf8");
|
|
936
|
-
console.log(chalk12.green("Generated CLAUDE.local.md"));
|
|
937
|
-
}
|
|
938
|
-
};
|
|
939
|
-
var claudeRules = ({ force } = {}) => {
|
|
940
|
-
const cwd5 = INIT_CWD() ?? process.cwd();
|
|
941
|
-
const rulesDir = PATH6.resolve(cwd5, ".claude", "rules");
|
|
942
|
-
mkdirSync2(rulesDir, { recursive: true });
|
|
943
|
-
const {
|
|
944
|
-
created,
|
|
945
|
-
templateNames,
|
|
946
|
-
updated
|
|
947
|
-
} = syncRuleFiles(rulesDir);
|
|
948
|
-
const removed = removeStaleRules(rulesDir, templateNames);
|
|
949
|
-
logRulesResult(created, updated, removed);
|
|
950
|
-
const claudeMdResult = ensureProjectClaudeMd(cwd5, force);
|
|
951
|
-
ensureLocalClaudeMd(cwd5);
|
|
952
|
-
return claudeMdResult ?? 0;
|
|
953
|
-
};
|
|
954
|
-
|
|
955
|
-
// src/actions/claude-settings.ts
|
|
956
|
-
import {
|
|
957
|
-
existsSync as existsSync7,
|
|
958
|
-
mkdirSync as mkdirSync3,
|
|
959
|
-
writeFileSync as writeFileSync4
|
|
960
|
-
} from "fs";
|
|
961
|
-
import PATH7 from "path";
|
|
962
|
-
import { createInterface as createInterface2 } from "readline";
|
|
963
|
-
import chalk13 from "chalk";
|
|
964
|
-
var DEFAULT_SETTINGS = {
|
|
965
|
-
permissions: {
|
|
966
|
-
allow: [
|
|
967
|
-
"Bash(git *)",
|
|
968
|
-
"Bash(yarn *)",
|
|
969
|
-
"Bash(npx *)",
|
|
970
|
-
"Bash(node *)",
|
|
971
|
-
"Bash(ls *)",
|
|
972
|
-
"Bash(mkdir *)",
|
|
973
|
-
"Bash(cp *)",
|
|
974
|
-
"Bash(mv *)",
|
|
975
|
-
"Bash(rm *)",
|
|
976
|
-
"Bash(cat *)",
|
|
977
|
-
"Bash(head *)",
|
|
978
|
-
"Bash(tail *)",
|
|
979
|
-
"Bash(echo *)",
|
|
980
|
-
"Bash(pwd)",
|
|
981
|
-
"Bash(which *)",
|
|
982
|
-
"Bash(grep *)",
|
|
983
|
-
"Bash(find *)",
|
|
984
|
-
"Bash(npm view *)",
|
|
985
|
-
"Bash(gh *)",
|
|
986
|
-
"Read",
|
|
987
|
-
"Edit",
|
|
988
|
-
"Write",
|
|
989
|
-
"Glob",
|
|
990
|
-
"Grep",
|
|
991
|
-
"Skill"
|
|
992
|
-
],
|
|
993
|
-
deny: [
|
|
994
|
-
"Bash(git push --force *)",
|
|
995
|
-
"Bash(git reset --hard *)",
|
|
996
|
-
"Bash(rm -rf /*)"
|
|
997
|
-
]
|
|
998
|
-
}
|
|
999
|
-
};
|
|
1000
|
-
function askConfirmation2(question) {
|
|
1001
|
-
const rl = createInterface2({ input: process.stdin, output: process.stdout });
|
|
1002
|
-
return new Promise((resolve) => {
|
|
1003
|
-
rl.question(question, (answer) => {
|
|
1004
|
-
rl.close();
|
|
1005
|
-
resolve(answer.toLowerCase() === "y" || answer.toLowerCase() === "yes");
|
|
1006
|
-
});
|
|
1007
|
-
});
|
|
1008
|
-
}
|
|
1009
|
-
async function claudeSettings() {
|
|
1010
|
-
const cwd5 = INIT_CWD() ?? process.cwd();
|
|
1011
|
-
const claudeDir = PATH7.resolve(cwd5, ".claude");
|
|
1012
|
-
const settingsPath = PATH7.resolve(claudeDir, "settings.local.json");
|
|
1013
|
-
mkdirSync3(claudeDir, { recursive: true });
|
|
1014
|
-
if (existsSync7(settingsPath)) {
|
|
1015
|
-
const confirmed = await askConfirmation2(
|
|
1016
|
-
chalk13.yellow(`${settingsPath} already exists. Replace it? (y/N) `)
|
|
1017
|
-
);
|
|
1018
|
-
if (!confirmed) {
|
|
1019
|
-
console.log(chalk13.gray("Skipped \u2014 existing settings.local.json preserved"));
|
|
1020
|
-
return 0;
|
|
1021
|
-
}
|
|
1022
|
-
}
|
|
1023
|
-
writeFileSync4(settingsPath, `${JSON.stringify(DEFAULT_SETTINGS, null, 2)}
|
|
1024
|
-
`, "utf8");
|
|
1025
|
-
console.log(chalk13.green("Generated .claude/settings.local.json"));
|
|
1026
|
-
return 0;
|
|
1027
|
-
}
|
|
1028
|
-
|
|
1029
|
-
// src/actions/claude-skills.ts
|
|
1030
|
-
import {
|
|
1031
|
-
existsSync as existsSync8,
|
|
1032
|
-
mkdirSync as mkdirSync4,
|
|
1033
|
-
readdirSync as readdirSync5,
|
|
1034
|
-
readFileSync as readFileSync8,
|
|
1035
|
-
rmSync as rmSync2,
|
|
1036
|
-
statSync as statSync2,
|
|
1037
|
-
writeFileSync as writeFileSync5
|
|
1038
|
-
} from "fs";
|
|
1039
|
-
import PATH8 from "path";
|
|
1040
|
-
import chalk14 from "chalk";
|
|
1041
|
-
var syncSkillFiles = (skillsDir) => {
|
|
1042
|
-
const templates = claudeSkillTemplates();
|
|
1043
|
-
const templateNames = new Set(Object.keys(templates));
|
|
1044
|
-
let updated = 0;
|
|
1045
|
-
let created = 0;
|
|
1046
|
-
for (const [skillName, files] of Object.entries(templates)) {
|
|
1047
|
-
const skillDir = PATH8.resolve(skillsDir, skillName);
|
|
1048
|
-
mkdirSync4(skillDir, { recursive: true });
|
|
1049
|
-
for (const [filename2, content] of Object.entries(files)) {
|
|
1050
|
-
const targetPath = PATH8.resolve(skillDir, filename2);
|
|
1051
|
-
mkdirSync4(PATH8.dirname(targetPath), { recursive: true });
|
|
1052
|
-
const existing = existsSync8(targetPath) ? readFileSync8(targetPath, "utf8") : void 0;
|
|
1053
|
-
if (existing === content) continue;
|
|
1054
|
-
writeFileSync5(targetPath, content, "utf8");
|
|
1055
|
-
if (existing) {
|
|
1056
|
-
updated++;
|
|
1057
|
-
} else {
|
|
1058
|
-
created++;
|
|
1059
|
-
}
|
|
1060
|
-
}
|
|
1061
|
-
}
|
|
1062
|
-
return {
|
|
1063
|
-
created,
|
|
1064
|
-
templateNames,
|
|
1065
|
-
updated
|
|
1066
|
-
};
|
|
1067
|
-
};
|
|
1068
|
-
var removeStaleSkills = (skillsDir, templateNames) => {
|
|
1069
|
-
const existingSkills = readdirSync5(skillsDir).filter(
|
|
1070
|
-
(f) => f.startsWith(XYLABS_SKILLS_PREFIX) && statSync2(PATH8.resolve(skillsDir, f)).isDirectory()
|
|
1071
|
-
);
|
|
1072
|
-
let removed = 0;
|
|
1073
|
-
for (const dir of existingSkills) {
|
|
1074
|
-
if (!templateNames.has(dir)) {
|
|
1075
|
-
rmSync2(PATH8.resolve(skillsDir, dir), { recursive: true });
|
|
1076
|
-
removed++;
|
|
1077
|
-
}
|
|
1078
|
-
}
|
|
1079
|
-
return removed;
|
|
1080
|
-
};
|
|
1081
|
-
var logSkillsResult = (created, updated, removed) => {
|
|
1082
|
-
if (created || updated || removed) {
|
|
1083
|
-
const parts = [
|
|
1084
|
-
created ? `${created} created` : "",
|
|
1085
|
-
updated ? `${updated} updated` : "",
|
|
1086
|
-
removed ? `${removed} removed` : ""
|
|
1087
|
-
].filter(Boolean);
|
|
1088
|
-
console.log(chalk14.green(`.claude/skills/${XYLABS_SKILLS_PREFIX}*/: ${parts.join(", ")}`));
|
|
1089
|
-
} else {
|
|
1090
|
-
console.log(chalk14.gray(`.claude/skills/${XYLABS_SKILLS_PREFIX}*/: already up to date`));
|
|
1091
|
-
}
|
|
1092
|
-
};
|
|
1093
|
-
var claudeSkills = () => {
|
|
1094
|
-
const cwd5 = INIT_CWD() ?? process.cwd();
|
|
1095
|
-
const skillsDir = PATH8.resolve(cwd5, ".claude", "skills");
|
|
1096
|
-
mkdirSync4(skillsDir, { recursive: true });
|
|
1097
|
-
const {
|
|
1098
|
-
created,
|
|
1099
|
-
templateNames,
|
|
1100
|
-
updated
|
|
1101
|
-
} = syncSkillFiles(skillsDir);
|
|
1102
|
-
const removed = removeStaleSkills(skillsDir, templateNames);
|
|
1103
|
-
logSkillsResult(created, updated, removed);
|
|
1104
|
-
return 0;
|
|
1105
|
-
};
|
|
1106
|
-
|
|
1107
|
-
// src/actions/clean.ts
|
|
1108
|
-
var clean = async ({ verbose, pkg }) => {
|
|
1109
|
-
return pkg ? await cleanPackage({ pkg, verbose }) : cleanAll({ verbose });
|
|
1110
|
-
};
|
|
1111
|
-
var cleanPackage = ({ pkg }) => {
|
|
1112
|
-
return runStepsAsync(`Clean [${pkg}]`, [["yarn", ["workspace", pkg, "run", "package-clean"]]]);
|
|
1113
|
-
};
|
|
1114
|
-
var cleanAll = ({ verbose }) => {
|
|
1115
|
-
const verboseOptions = verbose ? ["--verbose"] : ["--no-verbose"];
|
|
1116
|
-
return runStepsAsync("Clean", [["yarn", ["workspaces foreach", "-pA", "--jobs 64", ...verboseOptions, "run", "package-clean"]]]);
|
|
1117
|
-
};
|
|
1118
|
-
|
|
1119
|
-
// src/actions/clean-docs.ts
|
|
1120
|
-
import path from "path";
|
|
1121
|
-
import chalk15 from "chalk";
|
|
1122
|
-
var cleanDocs = () => {
|
|
1123
|
-
const pkgName = process.env.npm_package_name;
|
|
1124
|
-
console.log(chalk15.green(`Cleaning Docs [${pkgName}]`));
|
|
1125
|
-
for (const { location } of yarnWorkspaces()) deleteGlob(path.join(location, "docs"));
|
|
1126
|
-
return 0;
|
|
1127
|
-
};
|
|
1128
|
-
|
|
1129
|
-
// src/actions/compile.ts
|
|
1130
|
-
import chalk16 from "chalk";
|
|
1131
|
-
var compile = ({
|
|
1132
|
-
verbose,
|
|
1133
|
-
target,
|
|
1134
|
-
pkg,
|
|
1135
|
-
incremental,
|
|
1136
|
-
publint: publint2,
|
|
1137
|
-
jobs
|
|
1138
|
-
}) => {
|
|
1139
|
-
return pkg ? compilePackage({
|
|
1140
|
-
pkg,
|
|
1141
|
-
publint: publint2,
|
|
1142
|
-
target,
|
|
1143
|
-
verbose
|
|
1144
|
-
}) : compileAll({
|
|
1145
|
-
incremental,
|
|
1146
|
-
publint: publint2,
|
|
1147
|
-
target,
|
|
1148
|
-
verbose,
|
|
1149
|
-
jobs
|
|
1150
|
-
});
|
|
1151
|
-
};
|
|
1152
|
-
var compilePackage = ({ target, pkg }) => {
|
|
1153
|
-
const targetOptions = target ? ["-t", target] : [];
|
|
1154
|
-
return runSteps(
|
|
1155
|
-
`Compile [${pkg}]`,
|
|
1156
|
-
[["yarn", ["workspace", pkg, "run", "package-compile", ...targetOptions]]]
|
|
1157
|
-
);
|
|
1158
|
-
};
|
|
1159
|
-
var compileAll = ({
|
|
1160
|
-
jobs,
|
|
1161
|
-
verbose,
|
|
1162
|
-
target,
|
|
1163
|
-
incremental
|
|
1164
|
-
}) => {
|
|
1165
|
-
const start = Date.now();
|
|
1166
|
-
const verboseOptions = verbose ? ["--verbose"] : ["--no-verbose"];
|
|
1167
|
-
const targetOptions = target ? ["-t", target] : [];
|
|
1168
|
-
const incrementalOptions = incremental ? ["--since", "-Ap", "--topological-dev"] : ["--parallel", "-Ap", "--topological-dev"];
|
|
1169
|
-
const jobsOptions = jobs ? ["-j", `${jobs}`] : [];
|
|
1170
|
-
if (jobs) {
|
|
1171
|
-
console.log(chalk16.blue(`Jobs set to [${jobs}]`));
|
|
1172
|
-
}
|
|
1173
|
-
const result = runSteps(`Compile${incremental ? "-Incremental" : ""} [All]`, [
|
|
1174
|
-
["yarn", [
|
|
1175
|
-
"workspaces",
|
|
1176
|
-
"foreach",
|
|
1177
|
-
...incrementalOptions,
|
|
1178
|
-
...jobsOptions,
|
|
1179
|
-
...verboseOptions,
|
|
1180
|
-
"run",
|
|
1181
|
-
"package-compile",
|
|
1182
|
-
...targetOptions
|
|
1183
|
-
]]
|
|
1184
|
-
]);
|
|
1185
|
-
console.log(`${chalk16.gray("Compiled in")} [${chalk16.magenta(((Date.now() - start) / 1e3).toFixed(2))}] ${chalk16.gray("seconds")}`);
|
|
1186
|
-
return result;
|
|
1187
|
-
};
|
|
1188
|
-
|
|
1189
|
-
// src/actions/copy-assets.ts
|
|
1190
|
-
import path2 from "path/posix";
|
|
1191
|
-
import chalk17 from "chalk";
|
|
1192
|
-
import cpy from "cpy";
|
|
1193
|
-
var copyPackageTargetAssets = async (target, name, location) => {
|
|
1194
|
-
try {
|
|
1195
|
-
const values = await cpy(
|
|
1196
|
-
["**/*.jpg", "**/*.png", "**/*.gif", "**/*.svg", "**/*.webp", "**/*.sass", "**/*.scss", "**/*.gif", "**/*.css"],
|
|
1197
|
-
`../dist/${target}`,
|
|
1198
|
-
{
|
|
1199
|
-
cwd: path2.join(process.cwd(), location, "src"),
|
|
1200
|
-
flat: false
|
|
1201
|
-
}
|
|
1202
|
-
);
|
|
1203
|
-
for (const value of values) {
|
|
1204
|
-
console.log(`${value.split("/").pop()} => ./dist/${target}`);
|
|
1205
|
-
}
|
|
1206
|
-
return 0;
|
|
1207
|
-
} catch (reason) {
|
|
1208
|
-
console.log(`Copy Failed: ${name}: ${reason}`);
|
|
1209
|
-
return 1;
|
|
1210
|
-
}
|
|
1211
|
-
};
|
|
1212
|
-
var copyTargetAssets = async (target, pkg) => {
|
|
1213
|
-
const workspaces = yarnWorkspaces();
|
|
1214
|
-
console.log(chalk17.green(`Copying Assets [${target.toUpperCase()}]`));
|
|
1215
|
-
const workspaceList = workspaces.filter(({ name }) => {
|
|
1216
|
-
return pkg === void 0 || name === pkg;
|
|
1217
|
-
});
|
|
1218
|
-
if (workspaceList.length === 0) {
|
|
1219
|
-
console.error(`Package not found [${pkg}]`);
|
|
1220
|
-
} else {
|
|
1221
|
-
const results = await Promise.all(
|
|
1222
|
-
workspaceList.map(async (workspace) => {
|
|
1223
|
-
const { location, name } = workspace;
|
|
1224
|
-
return await copyPackageTargetAssets(target, name, location);
|
|
1225
|
-
})
|
|
1226
|
-
);
|
|
1227
|
-
return results.reduce((prev, result) => prev || result, 0);
|
|
1228
|
-
}
|
|
1229
|
-
return 0;
|
|
1230
|
-
};
|
|
1231
|
-
var copyAssets = async ({ target, pkg }) => {
|
|
1232
|
-
switch (target) {
|
|
1233
|
-
case "esm": {
|
|
1234
|
-
return await copyTargetAssets("esm", pkg);
|
|
1235
|
-
}
|
|
1236
|
-
case "cjs": {
|
|
1237
|
-
return await copyTargetAssets("cjs", pkg);
|
|
1238
|
-
}
|
|
1239
|
-
default: {
|
|
1240
|
-
return await copyTargetAssets("esm", pkg) || await copyTargetAssets("cjs", pkg);
|
|
1241
|
-
}
|
|
1242
|
-
}
|
|
1243
|
-
};
|
|
1244
|
-
|
|
1245
|
-
// src/actions/cycle.ts
|
|
1246
|
-
import { cruise } from "dependency-cruiser";
|
|
1247
|
-
var cycle = async ({ verbose, pkg } = {}) => {
|
|
1248
|
-
return pkg ? cyclePackage({ pkg, verbose }) : await cycleAll({ verbose });
|
|
1249
|
-
};
|
|
1250
|
-
var cyclePackage = ({ pkg, verbose }) => {
|
|
1251
|
-
const verboseOptions = verbose ? ["--verbose"] : ["--no-verbose"];
|
|
1252
|
-
return runSteps(
|
|
1253
|
-
`Cycle [${pkg}]`,
|
|
1254
|
-
[["yarn", ["workspace", pkg, "run", "package-cycle", ...verboseOptions]]]
|
|
1255
|
-
);
|
|
1256
|
-
};
|
|
1257
|
-
var cycleAll = async ({ verbose = false }) => {
|
|
1258
|
-
const pkgName = process.env.npm_package_name;
|
|
1259
|
-
const cruiseOptions = {
|
|
1260
|
-
ruleSet: {
|
|
1261
|
-
forbidden: [
|
|
1262
|
-
{
|
|
1263
|
-
name: "no-circular",
|
|
1264
|
-
severity: "error",
|
|
1265
|
-
comment: "This dependency creates a circular reference",
|
|
1266
|
-
from: {},
|
|
1267
|
-
to: { circular: true }
|
|
1268
|
-
}
|
|
1269
|
-
]
|
|
1270
|
-
},
|
|
1271
|
-
exclude: "node_modules|packages/.*/packages",
|
|
1272
|
-
validate: true,
|
|
1273
|
-
doNotFollow: { path: "node_modules|packages/.*/packages" },
|
|
1274
|
-
tsPreCompilationDeps: false,
|
|
1275
|
-
combinedDependencies: true,
|
|
1276
|
-
outputType: verbose ? "text" : "err"
|
|
1277
|
-
};
|
|
1278
|
-
const target = "**/packages/*/src";
|
|
1279
|
-
console.log(`Checking for circular dependencies in ${target}...`);
|
|
1280
|
-
const result = await cruise([target], cruiseOptions);
|
|
1281
|
-
if (result.output) {
|
|
1282
|
-
console.log(result.output);
|
|
1283
|
-
}
|
|
1284
|
-
if (result.exitCode === 0) {
|
|
1285
|
-
console.log(`${pkgName} \u2705 No dependency violations`);
|
|
1286
|
-
} else {
|
|
1287
|
-
console.error(`${pkgName} \u274C Dependency violations found`);
|
|
1288
|
-
}
|
|
1289
|
-
return result.exitCode;
|
|
1290
|
-
};
|
|
1291
|
-
|
|
1292
|
-
// src/actions/dead.ts
|
|
1293
|
-
var dead = () => {
|
|
1294
|
-
return runSteps("Dead", [["yarn", ["ts-prune", "-p", "tsconfig.json"]]]);
|
|
1295
|
-
};
|
|
1296
|
-
|
|
1297
|
-
// src/actions/deplint/deplint.ts
|
|
1298
|
-
import chalk23 from "chalk";
|
|
1299
|
-
|
|
1300
|
-
// src/actions/deplint/findFiles.ts
|
|
1301
|
-
import fs2 from "fs";
|
|
1302
|
-
|
|
1303
|
-
// src/actions/deplint/findFilesByGlob.ts
|
|
1304
|
-
import { globSync } from "glob";
|
|
1305
|
-
function findFilesByGlob(cwd5, pattern, ignore) {
|
|
1306
|
-
return globSync(pattern, {
|
|
1307
|
-
cwd: cwd5,
|
|
1308
|
-
absolute: true,
|
|
1309
|
-
ignore,
|
|
1310
|
-
nodir: true
|
|
1311
|
-
});
|
|
1312
|
-
}
|
|
1313
|
-
|
|
1314
|
-
// src/actions/deplint/findFiles.ts
|
|
1315
|
-
var codeExtensions = "*.{ts,tsx,mts,cts,js,mjs,cjs}";
|
|
1316
|
-
function getWorkspaceIgnores(location) {
|
|
1317
|
-
try {
|
|
1318
|
-
const raw = fs2.readFileSync(`${location}/package.json`, "utf8");
|
|
1319
|
-
const pkg = JSON.parse(raw);
|
|
1320
|
-
return pkg.workspaces ?? [];
|
|
1321
|
-
} catch {
|
|
1322
|
-
return [];
|
|
1323
|
-
}
|
|
1324
|
-
}
|
|
1325
|
-
function findFiles(location) {
|
|
1326
|
-
const workspaceIgnores = getWorkspaceIgnores(location).map((w) => `${w}/**`);
|
|
1327
|
-
const ignore = ["**/node_modules/**", "dist/**", ...workspaceIgnores];
|
|
1328
|
-
const allFiles = findFilesByGlob(location, `./**/${codeExtensions}`, ignore);
|
|
1329
|
-
const distFiles = [
|
|
1330
|
-
...findFilesByGlob(location, "./dist/**/*.d.ts"),
|
|
1331
|
-
...findFilesByGlob(location, `./dist/**/${codeExtensions}`)
|
|
1332
|
-
];
|
|
1333
|
-
return { allFiles, distFiles };
|
|
1334
|
-
}
|
|
1335
|
-
|
|
1336
|
-
// src/actions/deplint/getDependenciesFromPackageJson.ts
|
|
1337
|
-
import fs3 from "fs";
|
|
1338
|
-
import path3 from "path";
|
|
1339
|
-
function getDependenciesFromPackageJson(packageJsonPath) {
|
|
1340
|
-
const packageJsonFullPath = path3.resolve(packageJsonPath);
|
|
1341
|
-
const rawContent = fs3.readFileSync(packageJsonFullPath, "utf8");
|
|
1342
|
-
const packageJson = JSON.parse(rawContent);
|
|
1343
|
-
const dependencies = packageJson.dependencies ? Object.keys(packageJson.dependencies) : [];
|
|
1344
|
-
const devDependencies = packageJson.devDependencies ? Object.keys(packageJson.devDependencies) : [];
|
|
1345
|
-
const peerDependencies = packageJson.peerDependencies ? Object.keys(packageJson.peerDependencies) : [];
|
|
1346
|
-
return {
|
|
1347
|
-
dependencies,
|
|
1348
|
-
devDependencies,
|
|
1349
|
-
peerDependencies
|
|
1350
|
-
};
|
|
1351
|
-
}
|
|
1352
|
-
|
|
1353
|
-
// src/actions/deplint/getExtendsFromTsconfigs.ts
|
|
1354
|
-
import fs4 from "fs";
|
|
1355
|
-
import { globSync as globSync2 } from "glob";
|
|
1356
|
-
|
|
1357
|
-
// src/actions/deplint/getBasePackageName.ts
|
|
1358
|
-
function getBasePackageName(importName) {
|
|
1359
|
-
const importNameScrubbed = importName.replaceAll('"', "").trim();
|
|
1360
|
-
if (importNameScrubbed.startsWith("@")) {
|
|
1361
|
-
const parts = importNameScrubbed.split("/");
|
|
1362
|
-
return parts.length >= 2 ? `${parts[0]}/${parts[1]}` : importNameScrubbed;
|
|
1363
|
-
}
|
|
1364
|
-
return importNameScrubbed.split("/")[0];
|
|
1365
|
-
}
|
|
1366
|
-
|
|
1367
|
-
// src/actions/deplint/getExtendsFromTsconfigs.ts
|
|
1368
|
-
var isExternalReference = (ref) => !ref.startsWith(".") && !ref.startsWith("/");
|
|
1369
|
-
function parseExtendsField(value) {
|
|
1370
|
-
if (typeof value === "string") return [value];
|
|
1371
|
-
if (Array.isArray(value)) return value.filter((v) => typeof v === "string");
|
|
1372
|
-
return [];
|
|
1373
|
-
}
|
|
1374
|
-
function getExtendsFromTsconfigs(location) {
|
|
1375
|
-
const tsconfigFiles = globSync2("./tsconfig*.json", { cwd: location, absolute: true });
|
|
1376
|
-
const packages = /* @__PURE__ */ new Set();
|
|
1377
|
-
for (const file of tsconfigFiles) {
|
|
1378
|
-
try {
|
|
1379
|
-
const content = fs4.readFileSync(file, "utf8");
|
|
1380
|
-
const cleaned = content.replaceAll(/\/\/.*/g, "").replaceAll(/,\s*([}\]])/g, "$1");
|
|
1381
|
-
const parsed = JSON.parse(cleaned);
|
|
1382
|
-
const refs = parseExtendsField(parsed.extends);
|
|
1383
|
-
for (const ref of refs) {
|
|
1384
|
-
if (isExternalReference(ref)) {
|
|
1385
|
-
packages.add(getBasePackageName(ref));
|
|
1386
|
-
}
|
|
1387
|
-
}
|
|
1388
|
-
} catch {
|
|
1389
|
-
}
|
|
1390
|
-
}
|
|
1391
|
-
return [...packages];
|
|
1392
|
-
}
|
|
1393
|
-
|
|
1394
|
-
// src/actions/deplint/getImportsFromFile.ts
|
|
1395
|
-
import fs5 from "fs";
|
|
1396
|
-
import path4 from "path";
|
|
1397
|
-
import ts from "typescript";
|
|
1398
|
-
function isTypeOnlyImportClause(clause) {
|
|
1399
|
-
if (clause === void 0) {
|
|
1400
|
-
return false;
|
|
1401
|
-
}
|
|
1402
|
-
if ("phaseModifier" in clause) {
|
|
1403
|
-
const mod = clause.phaseModifier;
|
|
1404
|
-
const kind = typeof mod === "number" ? mod : mod?.kind;
|
|
1405
|
-
return kind === ts.SyntaxKind.TypeKeyword;
|
|
1406
|
-
}
|
|
1407
|
-
return clause.isTypeOnly;
|
|
1408
|
-
}
|
|
1409
|
-
function getImportsFromFile(filePath, importPaths, typeImportPaths) {
|
|
1410
|
-
const sourceCode = fs5.readFileSync(filePath, "utf8");
|
|
1411
|
-
const isMjsFile = filePath.endsWith(".mjs");
|
|
1412
|
-
const sourceFile = ts.createSourceFile(
|
|
1413
|
-
path4.basename(filePath),
|
|
1414
|
-
sourceCode,
|
|
1415
|
-
ts.ScriptTarget.Latest,
|
|
1416
|
-
true,
|
|
1417
|
-
isMjsFile ? ts.ScriptKind.JS : void 0
|
|
1418
|
-
);
|
|
1419
|
-
const imports = [];
|
|
1420
|
-
const typeImports = [];
|
|
1421
|
-
const isDeclarationFile2 = filePath.endsWith(".d.ts");
|
|
1422
|
-
function visit(node) {
|
|
1423
|
-
if (ts.isImportDeclaration(node) || ts.isExportDeclaration(node)) {
|
|
1424
|
-
const moduleSpecifier = node.moduleSpecifier?.getFullText();
|
|
1425
|
-
const isTypeImport = ts.isImportDeclaration(node) ? isTypeOnlyImportClause(node.importClause) : false;
|
|
1426
|
-
if (typeof moduleSpecifier === "string") {
|
|
1427
|
-
const trimmed = moduleSpecifier.replaceAll("'", "").replaceAll('"', "").trim();
|
|
1428
|
-
if (isTypeImport || isDeclarationFile2) {
|
|
1429
|
-
typeImports.push(trimmed);
|
|
1430
|
-
} else {
|
|
1431
|
-
imports.push(trimmed);
|
|
1432
|
-
}
|
|
1433
|
-
}
|
|
1434
|
-
} else if (ts.isCallExpression(node) && node.expression.kind === ts.SyntaxKind.ImportKeyword) {
|
|
1435
|
-
const [arg] = node.arguments;
|
|
1436
|
-
if (ts.isStringLiteral(arg)) {
|
|
1437
|
-
imports.push(arg.text);
|
|
1438
|
-
}
|
|
1439
|
-
} else if (ts.isCallExpression(node) && ts.isIdentifier(node.expression) && node.expression.text === "require" && node.arguments.length > 0 && ts.isStringLiteral(node.arguments[0])) {
|
|
1440
|
-
imports.push(node.arguments[0].text);
|
|
1441
|
-
}
|
|
1442
|
-
ts.forEachChild(node, visit);
|
|
1443
|
-
}
|
|
1444
|
-
visit(sourceFile);
|
|
1445
|
-
for (const ref of sourceFile.typeReferenceDirectives) {
|
|
1446
|
-
typeImports.push(ref.fileName);
|
|
1447
|
-
}
|
|
1448
|
-
const importsStartsWithExcludes = [".", "#", "node:"];
|
|
1449
|
-
const isValidImport = (imp) => !importsStartsWithExcludes.some((exc) => imp.startsWith(exc)) && !imp.includes("*") && !imp.includes("!");
|
|
1450
|
-
const cleanedImports = imports.filter(isValidImport).map(getBasePackageName);
|
|
1451
|
-
const cleanedTypeImports = typeImports.filter(isValidImport).map(getBasePackageName);
|
|
1452
|
-
for (const imp of cleanedImports) {
|
|
1453
|
-
importPaths[imp] = importPaths[imp] ?? [];
|
|
1454
|
-
importPaths[imp].push(filePath);
|
|
1455
|
-
}
|
|
1456
|
-
for (const imp of cleanedTypeImports) {
|
|
1457
|
-
typeImportPaths[imp] = typeImportPaths[imp] ?? [];
|
|
1458
|
-
typeImportPaths[imp].push(filePath);
|
|
1459
|
-
}
|
|
1460
|
-
return [cleanedImports, cleanedTypeImports];
|
|
1461
|
-
}
|
|
1462
|
-
|
|
1463
|
-
// src/actions/deplint/getExternalImportsFromFiles.ts
|
|
1464
|
-
var internalImportPrefixes = [".", "#", "node:"];
|
|
1465
|
-
var removeInternalImports = (imports) => {
|
|
1466
|
-
return imports.filter((imp) => !internalImportPrefixes.some((prefix) => imp.startsWith(prefix)));
|
|
1467
|
-
};
|
|
1468
|
-
var isDeclarationFile = (file) => file.endsWith(".d.ts") || file.endsWith(".d.cts") || file.endsWith(".d.mts");
|
|
1469
|
-
function getExternalImportsFromFiles({
|
|
1470
|
-
allFiles,
|
|
1471
|
-
distFiles,
|
|
1472
|
-
tsconfigExtends = []
|
|
1473
|
-
}) {
|
|
1474
|
-
const allImportPaths = {};
|
|
1475
|
-
const distImportPaths = {};
|
|
1476
|
-
const distTypeImportPaths = {};
|
|
1477
|
-
for (const path14 of allFiles) getImportsFromFile(path14, allImportPaths, allImportPaths).flat();
|
|
1478
|
-
const distTypeFiles = distFiles.filter(isDeclarationFile);
|
|
1479
|
-
const distCodeFiles = distFiles.filter((file) => !isDeclarationFile(file));
|
|
1480
|
-
for (const path14 of distCodeFiles) getImportsFromFile(path14, distImportPaths, distImportPaths).flat();
|
|
1481
|
-
for (const path14 of distTypeFiles) getImportsFromFile(path14, distTypeImportPaths, distTypeImportPaths).flat();
|
|
1482
|
-
const allImports = Object.keys(allImportPaths);
|
|
1483
|
-
const distImports = Object.keys(distImportPaths);
|
|
1484
|
-
const externalAllImports = removeInternalImports(allImports);
|
|
1485
|
-
const externalDistImports = removeInternalImports(distImports);
|
|
1486
|
-
const externalDistTypeImports = removeInternalImports(Object.keys(distTypeImportPaths));
|
|
1487
|
-
for (const ext of tsconfigExtends) {
|
|
1488
|
-
if (!externalAllImports.includes(ext)) externalAllImports.push(ext);
|
|
1489
|
-
}
|
|
1490
|
-
return {
|
|
1491
|
-
allImportPaths,
|
|
1492
|
-
allImports,
|
|
1493
|
-
distImportPaths,
|
|
1494
|
-
distImports,
|
|
1495
|
-
externalAllImports,
|
|
1496
|
-
externalDistImports,
|
|
1497
|
-
externalDistTypeImports
|
|
1498
|
-
};
|
|
1499
|
-
}
|
|
1500
|
-
|
|
1501
|
-
// src/actions/deplint/checkPackage/getUnlistedDependencies.ts
|
|
1502
|
-
import { builtinModules } from "module";
|
|
1503
|
-
import chalk18 from "chalk";
|
|
1504
|
-
function isRuntimeImportListed(imp, name, dependencies, peerDependencies) {
|
|
1505
|
-
return dependencies.includes(imp) || imp === name || peerDependencies.includes(imp) || builtinModules.includes(imp);
|
|
1506
|
-
}
|
|
1507
|
-
function isTypeImportListed(imp, name, dependencies, devDependencies, peerDependencies) {
|
|
1508
|
-
return dependencies.includes(imp) || imp === name || dependencies.includes(`@types/${imp}`) || peerDependencies.includes(imp) || peerDependencies.includes(`@types/${imp}`) || devDependencies.includes(`@types/${imp}`) || builtinModules.includes(imp);
|
|
1509
|
-
}
|
|
1510
|
-
function logMissing(name, imp, importPaths) {
|
|
1511
|
-
console.log(`[${chalk18.blue(name)}] Missing dependency in package.json: ${chalk18.red(imp)}`);
|
|
1512
|
-
if (importPaths[imp]) {
|
|
1513
|
-
console.log(` ${importPaths[imp].join("\n ")}`);
|
|
1514
|
-
}
|
|
1515
|
-
}
|
|
1516
|
-
function getUnlistedDependencies({ name, location }, {
|
|
1517
|
-
dependencies,
|
|
1518
|
-
devDependencies,
|
|
1519
|
-
peerDependencies
|
|
1520
|
-
}, {
|
|
1521
|
-
externalDistImports,
|
|
1522
|
-
externalDistTypeImports,
|
|
1523
|
-
distImportPaths
|
|
1524
|
-
}) {
|
|
1525
|
-
let unlistedDependencies = 0;
|
|
1526
|
-
for (const imp of externalDistImports) {
|
|
1527
|
-
if (!isRuntimeImportListed(imp, name, dependencies, peerDependencies)) {
|
|
1528
|
-
unlistedDependencies++;
|
|
1529
|
-
logMissing(name, imp, distImportPaths);
|
|
1530
|
-
}
|
|
1531
|
-
}
|
|
1532
|
-
for (const imp of externalDistTypeImports) {
|
|
1533
|
-
if (!isTypeImportListed(imp, name, dependencies, devDependencies, peerDependencies)) {
|
|
1534
|
-
unlistedDependencies++;
|
|
1535
|
-
logMissing(name, imp, distImportPaths);
|
|
1536
|
-
}
|
|
1537
|
-
}
|
|
1538
|
-
if (unlistedDependencies > 0) {
|
|
1539
|
-
const packageLocation = `${location}/package.json`;
|
|
1540
|
-
console.log(` ${chalk18.yellow(packageLocation)}
|
|
1541
|
-
`);
|
|
1542
|
-
}
|
|
1543
|
-
return unlistedDependencies;
|
|
1544
|
-
}
|
|
1545
|
-
|
|
1546
|
-
// src/actions/deplint/checkPackage/getUnlistedDevDependencies.ts
|
|
1547
|
-
import { builtinModules as builtinModules2 } from "module";
|
|
1548
|
-
import chalk19 from "chalk";
|
|
1549
|
-
function getUnlistedDevDependencies({ name, location }, {
|
|
1550
|
-
devDependencies,
|
|
1551
|
-
dependencies,
|
|
1552
|
-
peerDependencies
|
|
1553
|
-
}, {
|
|
1554
|
-
allImportPaths,
|
|
1555
|
-
externalAllImports,
|
|
1556
|
-
distImports
|
|
1557
|
-
}) {
|
|
1558
|
-
let unlistedDevDependencies = 0;
|
|
1559
|
-
for (const imp of externalAllImports) {
|
|
1560
|
-
if (!distImports.includes(imp) && imp !== name && !dependencies.includes(imp) && !dependencies.includes(`@types/${imp}`) && !peerDependencies.includes(imp) && !peerDependencies.includes(`@types/${imp}`) && !devDependencies.includes(imp) && !devDependencies.includes(`@types/${imp}`) && !builtinModules2.includes(imp)) {
|
|
1561
|
-
unlistedDevDependencies++;
|
|
1562
|
-
console.log(`[${chalk19.blue(name)}] Missing devDependency in package.json: ${chalk19.red(imp)}`);
|
|
1563
|
-
if (allImportPaths[imp]) {
|
|
1564
|
-
console.log(` ${allImportPaths[imp].join("\n ")}`);
|
|
1565
|
-
}
|
|
1566
|
-
}
|
|
1567
|
-
}
|
|
1568
|
-
if (unlistedDevDependencies > 0) {
|
|
1569
|
-
const packageLocation = `${location}/package.json`;
|
|
1570
|
-
console.log(` ${chalk19.yellow(packageLocation)}
|
|
1571
|
-
`);
|
|
1572
|
-
}
|
|
1573
|
-
return unlistedDevDependencies;
|
|
1574
|
-
}
|
|
1575
|
-
|
|
1576
|
-
// src/actions/deplint/checkPackage/getUnusedDependencies.ts
|
|
1577
|
-
import chalk20 from "chalk";
|
|
1578
|
-
function getUnusedDependencies({ name, location }, { dependencies }, {
|
|
1579
|
-
externalDistImports,
|
|
1580
|
-
externalDistTypeImports,
|
|
1581
|
-
externalAllImports
|
|
1582
|
-
}, exclude) {
|
|
1583
|
-
let unusedDependencies = 0;
|
|
1584
|
-
for (const dep of dependencies) {
|
|
1585
|
-
if (exclude?.has(dep)) continue;
|
|
1586
|
-
if (!externalDistImports.includes(dep) && !externalDistImports.includes(dep.replace(/^@types\//, "")) && !externalDistTypeImports.includes(dep) && !externalDistTypeImports.includes(dep.replace(/^@types\//, ""))) {
|
|
1587
|
-
unusedDependencies++;
|
|
1588
|
-
if (externalAllImports.includes(dep)) {
|
|
1589
|
-
console.log(`[${chalk20.blue(name)}] dependency should be devDependency in package.json: ${chalk20.red(dep)}`);
|
|
1590
|
-
} else {
|
|
1591
|
-
console.log(`[${chalk20.blue(name)}] Unused dependency in package.json: ${chalk20.red(dep)}`);
|
|
1592
|
-
}
|
|
1593
|
-
}
|
|
1594
|
-
}
|
|
1595
|
-
if (unusedDependencies > 0) {
|
|
1596
|
-
const packageLocation = `${location}/package.json`;
|
|
1597
|
-
console.log(` ${chalk20.yellow(packageLocation)}
|
|
1598
|
-
`);
|
|
1599
|
-
}
|
|
1600
|
-
return unusedDependencies;
|
|
1601
|
-
}
|
|
1602
|
-
|
|
1603
|
-
// src/actions/deplint/checkPackage/getUnusedDevDependencies.ts
|
|
1604
|
-
import chalk21 from "chalk";
|
|
1605
|
-
|
|
1606
|
-
// src/actions/deplint/getCliReferencedPackagesFromFiles.ts
|
|
1607
|
-
import fs8 from "fs";
|
|
1608
|
-
import path7 from "path";
|
|
1609
|
-
import ts2 from "typescript";
|
|
1610
|
-
|
|
1611
|
-
// src/actions/deplint/getScriptReferencedPackages.ts
|
|
1612
|
-
import fs7 from "fs";
|
|
1613
|
-
import path6 from "path";
|
|
1614
|
-
|
|
1615
|
-
// src/actions/deplint/getRequiredPeerDependencies.ts
|
|
1616
|
-
import fs6 from "fs";
|
|
1617
|
-
import path5 from "path";
|
|
1618
|
-
function findDepPackageJson(location, dep) {
|
|
1619
|
-
let dir = location;
|
|
1620
|
-
while (true) {
|
|
1621
|
-
const candidate = path5.join(dir, "node_modules", dep, "package.json");
|
|
1622
|
-
if (fs6.existsSync(candidate)) return candidate;
|
|
1623
|
-
const parent = path5.dirname(dir);
|
|
1624
|
-
if (parent === dir) return void 0;
|
|
1625
|
-
dir = parent;
|
|
1626
|
-
}
|
|
1627
|
-
}
|
|
1628
|
-
function getRequiredPeerDependencies(location, allDeps) {
|
|
1629
|
-
const required = /* @__PURE__ */ new Set();
|
|
1630
|
-
for (const dep of allDeps) {
|
|
1631
|
-
const depPkgPath = findDepPackageJson(location, dep);
|
|
1632
|
-
if (!depPkgPath) continue;
|
|
1633
|
-
try {
|
|
1634
|
-
const raw = fs6.readFileSync(depPkgPath, "utf8");
|
|
1635
|
-
const pkg = JSON.parse(raw);
|
|
1636
|
-
if (pkg.peerDependencies) {
|
|
1637
|
-
for (const peer of Object.keys(pkg.peerDependencies)) {
|
|
1638
|
-
required.add(peer);
|
|
1639
|
-
}
|
|
1640
|
-
}
|
|
1641
|
-
} catch {
|
|
1642
|
-
}
|
|
1643
|
-
}
|
|
1644
|
-
return required;
|
|
1645
|
-
}
|
|
1646
|
-
|
|
1647
|
-
// src/actions/deplint/getScriptReferencedPackages.ts
|
|
1648
|
-
function getBinNames(location, dep) {
|
|
1649
|
-
const depPkgPath = findDepPackageJson(location, dep);
|
|
1650
|
-
if (!depPkgPath) return [];
|
|
1651
|
-
try {
|
|
1652
|
-
const raw = fs7.readFileSync(depPkgPath, "utf8");
|
|
1653
|
-
const pkg = JSON.parse(raw);
|
|
1654
|
-
if (!pkg.bin) return [];
|
|
1655
|
-
if (typeof pkg.bin === "string") return [pkg.name?.split("/").pop() ?? dep];
|
|
1656
|
-
return Object.keys(pkg.bin);
|
|
1657
|
-
} catch {
|
|
1658
|
-
return [];
|
|
1659
|
-
}
|
|
1660
|
-
}
|
|
1661
|
-
function tokenizeScript(script) {
|
|
1662
|
-
return script.split(/[&|;$()"`\s]+/).map((t) => t.trim()).filter(Boolean);
|
|
1663
|
-
}
|
|
1664
|
-
function getScriptReferencedPackages(location, allDeps) {
|
|
1665
|
-
const pkgPath = path6.join(location, "package.json");
|
|
1666
|
-
let scripts = {};
|
|
1667
|
-
try {
|
|
1668
|
-
const raw = fs7.readFileSync(pkgPath, "utf8");
|
|
1669
|
-
const pkg = JSON.parse(raw);
|
|
1670
|
-
scripts = pkg.scripts ?? {};
|
|
1671
|
-
} catch {
|
|
1672
|
-
return /* @__PURE__ */ new Set();
|
|
1673
|
-
}
|
|
1674
|
-
const scriptText = Object.values(scripts).join(" ");
|
|
1675
|
-
const tokens = new Set(tokenizeScript(scriptText));
|
|
1676
|
-
const binToPackage = /* @__PURE__ */ new Map();
|
|
1677
|
-
for (const dep of allDeps) {
|
|
1678
|
-
const bins = getBinNames(location, dep);
|
|
1679
|
-
for (const bin of bins) {
|
|
1680
|
-
binToPackage.set(bin, dep);
|
|
1681
|
-
}
|
|
1682
|
-
}
|
|
1683
|
-
const referenced = /* @__PURE__ */ new Set();
|
|
1684
|
-
for (const token of tokens) {
|
|
1685
|
-
const baseName = getBasePackageName(token);
|
|
1686
|
-
if (allDeps.includes(baseName)) {
|
|
1687
|
-
referenced.add(baseName);
|
|
1688
|
-
}
|
|
1689
|
-
const pkg = binToPackage.get(token);
|
|
1690
|
-
if (pkg) {
|
|
1691
|
-
referenced.add(pkg);
|
|
1692
|
-
}
|
|
1693
|
-
}
|
|
1694
|
-
return referenced;
|
|
1695
|
-
}
|
|
1696
|
-
|
|
1697
|
-
// src/actions/deplint/getCliReferencedPackagesFromFiles.ts
|
|
1698
|
-
var shellCommandFunctions = /* @__PURE__ */ new Set(["execSync", "exec"]);
|
|
1699
|
-
var directExecFunctions = /* @__PURE__ */ new Set(["spawn", "spawnSync", "execFile", "execFileSync"]);
|
|
1700
|
-
var allExecFunctions = /* @__PURE__ */ new Set([...shellCommandFunctions, ...directExecFunctions]);
|
|
1701
|
-
function getCommandTokensFromFile(filePath) {
|
|
1702
|
-
const tokens = /* @__PURE__ */ new Set();
|
|
1703
|
-
let sourceCode;
|
|
1704
|
-
try {
|
|
1705
|
-
sourceCode = fs8.readFileSync(filePath, "utf8");
|
|
1706
|
-
} catch {
|
|
1707
|
-
return tokens;
|
|
1708
|
-
}
|
|
1709
|
-
const isMjsFile = filePath.endsWith(".mjs");
|
|
1710
|
-
const sourceFile = ts2.createSourceFile(
|
|
1711
|
-
path7.basename(filePath),
|
|
1712
|
-
sourceCode,
|
|
1713
|
-
ts2.ScriptTarget.Latest,
|
|
1714
|
-
true,
|
|
1715
|
-
isMjsFile ? ts2.ScriptKind.JS : void 0
|
|
1716
|
-
);
|
|
1717
|
-
function visit(node) {
|
|
1718
|
-
if (ts2.isCallExpression(node) && node.arguments.length > 0) {
|
|
1719
|
-
const fnName = getFunctionName(node.expression);
|
|
1720
|
-
if (fnName && allExecFunctions.has(fnName)) {
|
|
1721
|
-
const firstArg = node.arguments[0];
|
|
1722
|
-
if (ts2.isStringLiteral(firstArg) || ts2.isNoSubstitutionTemplateLiteral(firstArg)) {
|
|
1723
|
-
const value = firstArg.text;
|
|
1724
|
-
if (shellCommandFunctions.has(fnName)) {
|
|
1725
|
-
for (const token of tokenizeScript(value)) {
|
|
1726
|
-
tokens.add(token);
|
|
1727
|
-
}
|
|
1728
|
-
} else {
|
|
1729
|
-
tokens.add(value);
|
|
1730
|
-
}
|
|
1731
|
-
} else if (ts2.isTemplateExpression(firstArg)) {
|
|
1732
|
-
const head = firstArg.head.text;
|
|
1733
|
-
if (head) {
|
|
1734
|
-
for (const token of tokenizeScript(head)) {
|
|
1735
|
-
tokens.add(token);
|
|
1736
|
-
}
|
|
1737
|
-
}
|
|
1738
|
-
}
|
|
1739
|
-
}
|
|
1740
|
-
}
|
|
1741
|
-
ts2.forEachChild(node, visit);
|
|
1742
|
-
}
|
|
1743
|
-
visit(sourceFile);
|
|
1744
|
-
return tokens;
|
|
1745
|
-
}
|
|
1746
|
-
function getFunctionName(expr) {
|
|
1747
|
-
if (ts2.isIdentifier(expr)) {
|
|
1748
|
-
return expr.text;
|
|
1749
|
-
}
|
|
1750
|
-
if (ts2.isPropertyAccessExpression(expr) && ts2.isIdentifier(expr.name)) {
|
|
1751
|
-
return expr.name.text;
|
|
1752
|
-
}
|
|
1753
|
-
return void 0;
|
|
1754
|
-
}
|
|
1755
|
-
function getCliReferencedPackagesFromFiles(allFiles, location, allDeps) {
|
|
1756
|
-
const allTokens = /* @__PURE__ */ new Set();
|
|
1757
|
-
for (const file of allFiles) {
|
|
1758
|
-
for (const token of getCommandTokensFromFile(file)) {
|
|
1759
|
-
allTokens.add(token);
|
|
1760
|
-
}
|
|
1761
|
-
}
|
|
1762
|
-
if (allTokens.size === 0) return /* @__PURE__ */ new Set();
|
|
1763
|
-
const binToPackage = /* @__PURE__ */ new Map();
|
|
1764
|
-
for (const dep of allDeps) {
|
|
1765
|
-
for (const bin of getBinNames(location, dep)) {
|
|
1766
|
-
binToPackage.set(bin, dep);
|
|
1767
|
-
}
|
|
1768
|
-
}
|
|
1769
|
-
const referenced = /* @__PURE__ */ new Set();
|
|
1770
|
-
for (const token of allTokens) {
|
|
1771
|
-
const baseName = getBasePackageName(token);
|
|
1772
|
-
if (allDeps.includes(baseName)) {
|
|
1773
|
-
referenced.add(baseName);
|
|
1774
|
-
}
|
|
1775
|
-
const pkg = binToPackage.get(token);
|
|
1776
|
-
if (pkg) {
|
|
1777
|
-
referenced.add(pkg);
|
|
1778
|
-
}
|
|
1779
|
-
}
|
|
1780
|
-
return referenced;
|
|
1781
|
-
}
|
|
1782
|
-
|
|
1783
|
-
// src/actions/deplint/implicitDevDependencies.ts
|
|
1784
|
-
import fs9 from "fs";
|
|
1785
|
-
var hasFileWithExtension = (files, extensions) => files.some((f) => extensions.some((ext) => f.endsWith(ext)));
|
|
1786
|
-
var tsExtensions = [".ts", ".tsx", ".mts", ".cts"];
|
|
1787
|
-
var hasTypescriptFiles = ({ allFiles }) => hasFileWithExtension(allFiles, tsExtensions);
|
|
1788
|
-
var decoratorPattern = /^\s*@[a-zA-Z]\w*/m;
|
|
1789
|
-
var hasDecorators = ({ allFiles }) => allFiles.filter((f) => tsExtensions.some((ext) => f.endsWith(ext))).some((file) => {
|
|
1790
|
-
try {
|
|
1791
|
-
const content = fs9.readFileSync(file, "utf8");
|
|
1792
|
-
return decoratorPattern.test(content);
|
|
1793
|
-
} catch {
|
|
1794
|
-
return false;
|
|
1795
|
-
}
|
|
1796
|
-
});
|
|
1797
|
-
var importPlugins = /* @__PURE__ */ new Set(["eslint-plugin-import-x", "eslint-plugin-import"]);
|
|
1798
|
-
function hasImportPlugin({ location, allDependencies }) {
|
|
1799
|
-
if (allDependencies.some((d) => importPlugins.has(d))) return true;
|
|
1800
|
-
for (const dep of allDependencies) {
|
|
1801
|
-
const pkgPath = findDepPackageJson(location, dep);
|
|
1802
|
-
if (!pkgPath) continue;
|
|
1803
|
-
try {
|
|
1804
|
-
const pkg = JSON.parse(fs9.readFileSync(pkgPath, "utf8"));
|
|
1805
|
-
const transitiveDeps = [
|
|
1806
|
-
...Object.keys(pkg.dependencies ?? {}),
|
|
1807
|
-
...Object.keys(pkg.peerDependencies ?? {})
|
|
1808
|
-
];
|
|
1809
|
-
if (transitiveDeps.some((d) => importPlugins.has(d))) return true;
|
|
1810
|
-
} catch {
|
|
1811
|
-
}
|
|
1812
|
-
}
|
|
1813
|
-
return false;
|
|
1814
|
-
}
|
|
1815
|
-
var hasVitest = ({ allDependencies }) => allDependencies.includes("vitest");
|
|
1816
|
-
var rules = [
|
|
1817
|
-
{
|
|
1818
|
-
package: "typescript",
|
|
1819
|
-
isNeeded: hasTypescriptFiles
|
|
1820
|
-
},
|
|
1821
|
-
{
|
|
1822
|
-
package: "eslint-import-resolver-typescript",
|
|
1823
|
-
isNeeded: (context) => hasTypescriptFiles(context) && context.allDependencies.includes("eslint") && hasImportPlugin(context)
|
|
1824
|
-
},
|
|
1825
|
-
{
|
|
1826
|
-
package: "tslib",
|
|
1827
|
-
isNeeded: hasDecorators
|
|
1828
|
-
},
|
|
1829
|
-
{
|
|
1830
|
-
package: "@vitest/coverage-v8",
|
|
1831
|
-
isNeeded: hasVitest
|
|
1832
|
-
}
|
|
1833
|
-
];
|
|
1834
|
-
function getImplicitDevDependencies(context) {
|
|
1835
|
-
const implicit = /* @__PURE__ */ new Set();
|
|
1836
|
-
for (const rule of rules) {
|
|
1837
|
-
if (rule.isNeeded(context)) {
|
|
1838
|
-
implicit.add(rule.package);
|
|
1839
|
-
}
|
|
1840
|
-
}
|
|
1841
|
-
return implicit;
|
|
1842
|
-
}
|
|
1843
|
-
|
|
1844
|
-
// src/actions/deplint/checkPackage/getUnusedDevDependencies.ts
|
|
1845
|
-
var allExternalImports = ({
|
|
1846
|
-
externalAllImports,
|
|
1847
|
-
externalDistImports,
|
|
1848
|
-
externalDistTypeImports
|
|
1849
|
-
}) => {
|
|
1850
|
-
return /* @__PURE__ */ new Set([
|
|
1851
|
-
...externalAllImports,
|
|
1852
|
-
...externalDistImports,
|
|
1853
|
-
...externalDistTypeImports
|
|
1854
|
-
]);
|
|
1855
|
-
};
|
|
1856
|
-
function isDevDepUsed(dep, allImports, implicitDeps, requiredPeers, scriptRefs, cliRefs) {
|
|
1857
|
-
if (implicitDeps.has(dep)) return true;
|
|
1858
|
-
if (requiredPeers.has(dep)) return true;
|
|
1859
|
-
if (scriptRefs.has(dep)) return true;
|
|
1860
|
-
if (cliRefs.has(dep)) return true;
|
|
1861
|
-
if (dep.startsWith("@types/")) {
|
|
1862
|
-
const baseName = dep.replace(/^@types\//, "");
|
|
1863
|
-
return allImports.has(baseName) || allImports.has(dep) || implicitDeps.has(baseName);
|
|
1864
|
-
}
|
|
1865
|
-
return allImports.has(dep);
|
|
1866
|
-
}
|
|
1867
|
-
function getUnusedDevDependencies({ name, location }, {
|
|
1868
|
-
devDependencies,
|
|
1869
|
-
dependencies,
|
|
1870
|
-
peerDependencies
|
|
1871
|
-
}, sourceParams, fileContext, exclude) {
|
|
1872
|
-
const allImports = allExternalImports(sourceParams);
|
|
1873
|
-
const allDeps = [...dependencies, ...devDependencies, ...peerDependencies];
|
|
1874
|
-
const implicitDeps = getImplicitDevDependencies({
|
|
1875
|
-
...fileContext,
|
|
1876
|
-
allDependencies: allDeps,
|
|
1877
|
-
location
|
|
1878
|
-
});
|
|
1879
|
-
const requiredPeers = getRequiredPeerDependencies(location, allDeps);
|
|
1880
|
-
const scriptRefs = getScriptReferencedPackages(location, allDeps);
|
|
1881
|
-
const cliRefs = getCliReferencedPackagesFromFiles(fileContext.allFiles, location, allDeps);
|
|
1882
|
-
let unusedDevDependencies = 0;
|
|
1883
|
-
for (const dep of devDependencies) {
|
|
1884
|
-
if (exclude?.has(dep)) continue;
|
|
1885
|
-
if (dependencies.includes(dep) || peerDependencies.includes(dep)) continue;
|
|
1886
|
-
if (!isDevDepUsed(dep, allImports, implicitDeps, requiredPeers, scriptRefs, cliRefs)) {
|
|
1887
|
-
unusedDevDependencies++;
|
|
1888
|
-
console.log(`[${chalk21.blue(name)}] Unused devDependency in package.json: ${chalk21.red(dep)}`);
|
|
1889
|
-
}
|
|
1890
|
-
}
|
|
1891
|
-
if (unusedDevDependencies > 0) {
|
|
1892
|
-
const packageLocation = `${location}/package.json`;
|
|
1893
|
-
console.log(` ${chalk21.yellow(packageLocation)}
|
|
1894
|
-
`);
|
|
1895
|
-
}
|
|
1896
|
-
return unusedDevDependencies;
|
|
1897
|
-
}
|
|
1898
|
-
|
|
1899
|
-
// src/actions/deplint/checkPackage/getUnusedPeerDependencies.ts
|
|
1900
|
-
import chalk22 from "chalk";
|
|
1901
|
-
function getUnusedPeerDependencies({ name, location }, { peerDependencies, dependencies }, { externalDistImports, externalDistTypeImports }, exclude) {
|
|
1902
|
-
let unusedDependencies = 0;
|
|
1903
|
-
for (const dep of peerDependencies) {
|
|
1904
|
-
if (exclude?.has(dep)) continue;
|
|
1905
|
-
if (!externalDistImports.includes(dep) && !externalDistImports.includes(dep.replace(/^@types\//, "")) && !externalDistTypeImports.includes(dep) && !externalDistTypeImports.includes(dep.replace(/^@types\//, ""))) {
|
|
1906
|
-
unusedDependencies++;
|
|
1907
|
-
if (dependencies.includes(dep)) {
|
|
1908
|
-
console.log(`[${chalk22.blue(name)}] Unused peerDependency [already a dependency] in package.json: ${chalk22.red(dep)}`);
|
|
1909
|
-
} else {
|
|
1910
|
-
console.log(`[${chalk22.blue(name)}] Unused peerDependency in package.json: ${chalk22.red(dep)}`);
|
|
1911
|
-
}
|
|
1912
|
-
}
|
|
1913
|
-
}
|
|
1914
|
-
if (unusedDependencies > 0) {
|
|
1915
|
-
const packageLocation = `${location}/package.json`;
|
|
1916
|
-
console.log(` ${chalk22.yellow(packageLocation)}
|
|
1917
|
-
`);
|
|
1918
|
-
}
|
|
1919
|
-
return unusedDependencies;
|
|
1920
|
-
}
|
|
1921
|
-
|
|
1922
|
-
// src/actions/deplint/checkPackage/checkPackage.ts
|
|
1923
|
-
function logVerbose(name, location, allFiles, distFiles, tsconfigExtends) {
|
|
1924
|
-
console.info(`Checking package: ${name} at ${location}`);
|
|
1925
|
-
console.info(`All files: ${allFiles.length}, Distribution files: ${distFiles.length}`);
|
|
1926
|
-
for (const file of allFiles) {
|
|
1927
|
-
console.info(`File: ${file}`);
|
|
1928
|
-
}
|
|
1929
|
-
for (const file of distFiles) {
|
|
1930
|
-
console.info(`Distribution file: ${file}`);
|
|
1931
|
-
}
|
|
1932
|
-
for (const ext of tsconfigExtends) {
|
|
1933
|
-
console.info(`Tsconfig extends: ${ext}`);
|
|
1934
|
-
}
|
|
1935
|
-
}
|
|
1936
|
-
function checkPackage({
|
|
1937
|
-
name,
|
|
1938
|
-
location,
|
|
1939
|
-
deps = false,
|
|
1940
|
-
devDeps = false,
|
|
1941
|
-
exclude,
|
|
1942
|
-
peerDeps = false,
|
|
1943
|
-
verbose = false
|
|
1944
|
-
}) {
|
|
1945
|
-
const { allFiles, distFiles } = findFiles(location);
|
|
1946
|
-
const tsconfigExtends = getExtendsFromTsconfigs(location);
|
|
1947
|
-
if (verbose) {
|
|
1948
|
-
logVerbose(name, location, allFiles, distFiles, tsconfigExtends);
|
|
1949
|
-
}
|
|
1950
|
-
const checkDeps = deps || !(deps || devDeps || peerDeps);
|
|
1951
|
-
const checkDevDeps = devDeps || !(deps || devDeps || peerDeps);
|
|
1952
|
-
const checkPeerDeps = peerDeps;
|
|
1953
|
-
const sourceParams = getExternalImportsFromFiles({
|
|
1954
|
-
allFiles,
|
|
1955
|
-
distFiles,
|
|
1956
|
-
tsconfigExtends
|
|
1957
|
-
});
|
|
1958
|
-
const packageParams = getDependenciesFromPackageJson(`${location}/package.json`);
|
|
1959
|
-
const unlistedDependencies = checkDeps ? getUnlistedDependencies({ name, location }, packageParams, sourceParams) : 0;
|
|
1960
|
-
const unusedDependencies = checkDeps ? getUnusedDependencies({ name, location }, packageParams, sourceParams, exclude) : 0;
|
|
1961
|
-
const unlistedDevDependencies = checkDevDeps ? getUnlistedDevDependencies({ name, location }, packageParams, sourceParams) : 0;
|
|
1962
|
-
const fileContext = { allFiles, distFiles };
|
|
1963
|
-
const unusedDevDependencies = checkDevDeps ? getUnusedDevDependencies({ name, location }, packageParams, sourceParams, fileContext, exclude) : 0;
|
|
1964
|
-
const unusedPeerDependencies = checkPeerDeps ? getUnusedPeerDependencies({ name, location }, packageParams, sourceParams, exclude) : 0;
|
|
1965
|
-
const totalErrors = unlistedDependencies + unlistedDevDependencies + unusedDependencies + unusedDevDependencies + unusedPeerDependencies;
|
|
1966
|
-
return totalErrors;
|
|
1967
|
-
}
|
|
1968
|
-
|
|
1969
|
-
// src/actions/deplint/deplint.ts
|
|
1970
|
-
var deplint = async ({
|
|
1971
|
-
pkg,
|
|
1972
|
-
deps,
|
|
1973
|
-
devDeps,
|
|
1974
|
-
peerDeps,
|
|
1975
|
-
verbose,
|
|
1976
|
-
cliExclude
|
|
1977
|
-
}) => {
|
|
1978
|
-
const config2 = await loadConfig();
|
|
1979
|
-
const exclude = /* @__PURE__ */ new Set([
|
|
1980
|
-
...config2.deplint?.exclude ?? [],
|
|
1981
|
-
...cliExclude ?? []
|
|
1982
|
-
]);
|
|
1983
|
-
let totalErrors = 0;
|
|
1984
|
-
if (pkg === void 0) {
|
|
1985
|
-
const workspaces = yarnWorkspaces();
|
|
1986
|
-
console.info("Deplint Started...");
|
|
1987
|
-
for (const workspace of workspaces) {
|
|
1988
|
-
totalErrors += checkPackage({
|
|
1989
|
-
...workspace,
|
|
1990
|
-
deps,
|
|
1991
|
-
devDeps,
|
|
1992
|
-
exclude,
|
|
1993
|
-
peerDeps,
|
|
1994
|
-
verbose
|
|
1995
|
-
});
|
|
1996
|
-
}
|
|
1997
|
-
} else {
|
|
1998
|
-
const { location, name } = yarnWorkspace(pkg);
|
|
1999
|
-
console.info(`Running Deplint for ${name}`);
|
|
2000
|
-
totalErrors += checkPackage({
|
|
2001
|
-
name,
|
|
2002
|
-
location,
|
|
2003
|
-
devDeps,
|
|
2004
|
-
deps,
|
|
2005
|
-
exclude,
|
|
2006
|
-
peerDeps,
|
|
2007
|
-
verbose
|
|
2008
|
-
});
|
|
2009
|
-
}
|
|
2010
|
-
if (totalErrors > 0) {
|
|
2011
|
-
console.warn(`Deplint: Found ${chalk23.red(totalErrors)} dependency problems. ${chalk23.red("\u2716")}`);
|
|
2012
|
-
} else {
|
|
2013
|
-
console.info(`Deplint: Found no dependency problems. ${chalk23.green("\u2714")}`);
|
|
2014
|
-
}
|
|
2015
|
-
return 0;
|
|
2016
|
-
};
|
|
2017
|
-
|
|
2018
|
-
// src/actions/deploy.ts
|
|
2019
|
-
import { readFileSync as readFileSync9 } from "fs";
|
|
2020
|
-
var privatePackageExcludeList = () => {
|
|
2021
|
-
const possibleDeployablePackages = yarnWorkspaces().map((workspace) => [
|
|
2022
|
-
workspace,
|
|
2023
|
-
JSON.parse(readFileSync9(`${workspace.location}/package.json`, { encoding: "utf8" }))
|
|
2024
|
-
]);
|
|
2025
|
-
const privatePackages = possibleDeployablePackages.filter(([_, pkg]) => pkg.private).map(([workspace]) => workspace);
|
|
2026
|
-
const excludeList = privatePackages.map((workspace) => `--exclude ${workspace.name}`);
|
|
2027
|
-
return excludeList;
|
|
2028
|
-
};
|
|
2029
|
-
var deploy = () => {
|
|
2030
|
-
const excludeList = privatePackageExcludeList();
|
|
2031
|
-
if (excludeList.length > 0) {
|
|
2032
|
-
console.log("Excluding private packages from deployment:", excludeList);
|
|
2033
|
-
}
|
|
2034
|
-
return runSteps("Deploy [Patch]", [
|
|
2035
|
-
["yarn", "workspaces foreach --all version patch --deferred"],
|
|
2036
|
-
["yarn", "xy clean"],
|
|
2037
|
-
["yarn", "xy build"],
|
|
2038
|
-
["yarn", "version apply --all"]
|
|
2039
|
-
]);
|
|
2040
|
-
};
|
|
2041
|
-
|
|
2042
|
-
// src/actions/deploy-major.ts
|
|
2043
|
-
import { readFileSync as readFileSync10 } from "fs";
|
|
2044
|
-
var privatePackageExcludeList2 = () => {
|
|
2045
|
-
const possibleDeployablePackages = yarnWorkspaces().map((workspace) => [
|
|
2046
|
-
workspace,
|
|
2047
|
-
JSON.parse(readFileSync10(`${workspace.location}/package.json`, { encoding: "utf8" }))
|
|
2048
|
-
]);
|
|
2049
|
-
const privatePackages = possibleDeployablePackages.filter(([_, pkg]) => pkg.private).map(([workspace]) => workspace);
|
|
2050
|
-
const excludeList = privatePackages.map((workspace) => `--exclude ${workspace.name}`);
|
|
2051
|
-
return excludeList;
|
|
2052
|
-
};
|
|
2053
|
-
var deployMajor = () => {
|
|
2054
|
-
const excludeList = privatePackageExcludeList2();
|
|
2055
|
-
if (excludeList.length > 0) {
|
|
2056
|
-
console.log("Excluding private packages from deployment:", excludeList);
|
|
2057
|
-
}
|
|
2058
|
-
return runSteps("Deploy [Major]", [
|
|
2059
|
-
["yarn", "workspaces foreach --all version major --deferred"],
|
|
2060
|
-
["yarn", "xy clean"],
|
|
2061
|
-
["yarn", "xy build"],
|
|
2062
|
-
["yarn", "version apply --all"]
|
|
2063
|
-
]);
|
|
2064
|
-
};
|
|
2065
|
-
|
|
2066
|
-
// src/actions/deploy-minor.ts
|
|
2067
|
-
import { readFileSync as readFileSync11 } from "fs";
|
|
2068
|
-
var privatePackageExcludeList3 = () => {
|
|
2069
|
-
const possibleDeployablePackages = yarnWorkspaces().map((workspace) => [
|
|
2070
|
-
workspace,
|
|
2071
|
-
JSON.parse(readFileSync11(`${workspace.location}/package.json`, { encoding: "utf8" }))
|
|
2072
|
-
]);
|
|
2073
|
-
const privatePackages = possibleDeployablePackages.filter(([_, pkg]) => pkg.private).map(([workspace]) => workspace);
|
|
2074
|
-
const excludeList = privatePackages.map((workspace) => `--exclude ${workspace.name}`);
|
|
2075
|
-
return excludeList;
|
|
2076
|
-
};
|
|
2077
|
-
var deployMinor = () => {
|
|
2078
|
-
const excludeList = privatePackageExcludeList3();
|
|
2079
|
-
if (excludeList.length > 0) {
|
|
2080
|
-
console.log("Excluding private packages from deployment:", excludeList);
|
|
2081
|
-
}
|
|
2082
|
-
return runSteps("Deploy [Minor]", [
|
|
2083
|
-
["yarn", "workspaces foreach --all version minor --deferred"],
|
|
2084
|
-
["yarn", "xy clean"],
|
|
2085
|
-
["yarn", "xy build"],
|
|
2086
|
-
["yarn", "version apply --all"]
|
|
2087
|
-
]);
|
|
2088
|
-
};
|
|
2089
|
-
|
|
2090
|
-
// src/actions/deploy-next.ts
|
|
2091
|
-
import { readFileSync as readFileSync12 } from "fs";
|
|
2092
|
-
var privatePackageExcludeList4 = () => {
|
|
2093
|
-
const possibleDeployablePackages = yarnWorkspaces().map((workspace) => [
|
|
2094
|
-
workspace,
|
|
2095
|
-
JSON.parse(readFileSync12(`${workspace.location}/package.json`, { encoding: "utf8" }))
|
|
2096
|
-
]);
|
|
2097
|
-
const privatePackages = possibleDeployablePackages.filter(([_, pkg]) => pkg.private).map(([workspace]) => workspace);
|
|
2098
|
-
const excludeList = privatePackages.map((workspace) => `--exclude ${workspace.name}`);
|
|
2099
|
-
return excludeList;
|
|
2100
|
-
};
|
|
2101
|
-
var deployNext = () => {
|
|
2102
|
-
const excludeList = privatePackageExcludeList4();
|
|
2103
|
-
if (excludeList.length > 0) {
|
|
2104
|
-
console.log("Excluding private packages from deployment:", excludeList);
|
|
2105
|
-
}
|
|
2106
|
-
return runSteps("Deploy [Next]", [
|
|
2107
|
-
["yarn", "workspaces foreach --all version minor --deferred"],
|
|
2108
|
-
["yarn", "xy clean"],
|
|
2109
|
-
["yarn", "xy build"],
|
|
2110
|
-
["yarn", "version apply --all --prerelease"]
|
|
2111
|
-
]);
|
|
2112
|
-
};
|
|
2113
|
-
|
|
2114
|
-
// src/actions/dupdeps.ts
|
|
2115
|
-
import chalk24 from "chalk";
|
|
2116
|
-
var dupdeps = () => {
|
|
2117
|
-
console.log(chalk24.green("Checking all Dependencies for Duplicates"));
|
|
2118
|
-
const pkg = parsedPackageJSON();
|
|
2119
|
-
const allDependencies = { ...pkg?.dependencies, ...pkg?.devDependencies };
|
|
2120
|
-
const dependencies = Object.keys(allDependencies);
|
|
2121
|
-
return detectDuplicateDependencies(dependencies);
|
|
2122
|
-
};
|
|
2123
|
-
|
|
2124
|
-
// src/actions/lint.ts
|
|
2125
|
-
import chalk25 from "chalk";
|
|
2126
|
-
var lintPackage = ({
|
|
2127
|
-
pkg,
|
|
2128
|
-
fix: fix2,
|
|
2129
|
-
verbose
|
|
2130
|
-
}) => {
|
|
2131
|
-
console.log(chalk25.gray(`${fix2 ? "Fix" : "Lint"} [${pkg}]`));
|
|
2132
|
-
const start = Date.now();
|
|
2133
|
-
const result = runSteps(`${fix2 ? "Fix" : "Lint"} [${pkg}]`, [
|
|
2134
|
-
["yarn", [
|
|
2135
|
-
"workspace",
|
|
2136
|
-
pkg,
|
|
2137
|
-
"run",
|
|
2138
|
-
fix2 ? "package-fix" : verbose ? "package-lint-verbose" : "package-lint"
|
|
2139
|
-
]]
|
|
2140
|
-
]);
|
|
2141
|
-
console.log(chalk25.gray(`${fix2 ? "Fixed in" : "Linted in"} [${chalk25.magenta(((Date.now() - start) / 1e3).toFixed(2))}] ${chalk25.gray("seconds")}`));
|
|
2142
|
-
return result;
|
|
2143
|
-
};
|
|
2144
|
-
var lint = ({
|
|
2145
|
-
pkg,
|
|
2146
|
-
verbose,
|
|
2147
|
-
incremental,
|
|
2148
|
-
fix: fix2
|
|
2149
|
-
} = {}) => {
|
|
2150
|
-
return pkg === void 0 ? lintAllPackages({
|
|
2151
|
-
verbose,
|
|
2152
|
-
incremental,
|
|
2153
|
-
fix: fix2
|
|
2154
|
-
}) : lintPackage({
|
|
2155
|
-
pkg,
|
|
2156
|
-
fix: fix2,
|
|
2157
|
-
verbose
|
|
2158
|
-
});
|
|
2159
|
-
};
|
|
2160
|
-
var lintAllPackages = ({ fix: fix2 = false } = {}) => {
|
|
2161
|
-
console.log(chalk25.gray(`${fix2 ? "Fix" : "Lint"} [All-Packages]`));
|
|
2162
|
-
const start = Date.now();
|
|
2163
|
-
const fixOptions = fix2 ? ["--fix"] : [];
|
|
2164
|
-
const result = runSteps(`${fix2 ? "Fix" : "Lint"} [All-Packages]`, [
|
|
2165
|
-
["yarn", ["eslint", "--cache", "--cache-location", ".eslintcache", "--cache-strategy", "content", ...fixOptions]]
|
|
2166
|
-
]);
|
|
2167
|
-
console.log(chalk25.gray(`${fix2 ? "Fixed in" : "Linted in"} [${chalk25.magenta(((Date.now() - start) / 1e3).toFixed(2))}] ${chalk25.gray("seconds")}`));
|
|
2168
|
-
return result;
|
|
2169
|
-
};
|
|
2170
|
-
|
|
2171
|
-
// src/actions/fix.ts
|
|
2172
|
-
var fix = (params) => {
|
|
2173
|
-
return lint({ ...params, fix: true });
|
|
2174
|
-
};
|
|
2175
|
-
|
|
2176
|
-
// src/actions/gen-docs.ts
|
|
2177
|
-
var genDocs = ({ pkg, incremental }) => {
|
|
2178
|
-
return pkg ? genDocsPackage({ pkg }) : genDocsAll({ incremental });
|
|
2179
|
-
};
|
|
2180
|
-
var genDocsPackage = ({ pkg }) => {
|
|
2181
|
-
const steps = [["yarn", ["workspace", pkg, "run", "package-gen-docs"]]];
|
|
2182
|
-
return runSteps(`GenDocs [${pkg}]`, [...steps]);
|
|
2183
|
-
};
|
|
2184
|
-
var genDocsAll = ({ incremental }) => {
|
|
2185
|
-
const incrementalOptions = incremental ? ["--since", "-pA"] : ["-pA"];
|
|
2186
|
-
const steps = [["yarn", ["workspaces", "foreach", ...incrementalOptions, "run", "package-gen-docs"]]];
|
|
2187
|
-
return runSteps(`GenDocs [All${incremental ? "-Incremental" : ""}]`, [...steps]);
|
|
2188
|
-
};
|
|
2189
|
-
|
|
2190
|
-
// src/actions/gitignore.ts
|
|
2191
|
-
import { unlinkSync as unlinkSync4 } from "fs";
|
|
2192
|
-
import chalk26 from "chalk";
|
|
2193
|
-
var COMMENT_PREFIX = "#";
|
|
2194
|
-
var isComment = (line) => line.startsWith(COMMENT_PREFIX);
|
|
2195
|
-
var isNegation = (line) => line.startsWith("!");
|
|
2196
|
-
function parseTemplateSections(lines) {
|
|
2197
|
-
const sections = [];
|
|
2198
|
-
let current = [];
|
|
2199
|
-
for (const line of lines) {
|
|
2200
|
-
if (isComment(line)) {
|
|
2201
|
-
if (current.length > 0) {
|
|
2202
|
-
sections.push(current);
|
|
2203
|
-
}
|
|
2204
|
-
current = [line];
|
|
2205
|
-
} else {
|
|
2206
|
-
current.push(line);
|
|
2207
|
-
}
|
|
2208
|
-
}
|
|
2209
|
-
if (current.length > 0) {
|
|
2210
|
-
sections.push(current);
|
|
2211
|
-
}
|
|
2212
|
-
return sections;
|
|
2213
|
-
}
|
|
2214
|
-
function mergeWithTemplate(existing, templateContent) {
|
|
2215
|
-
const templateLines = templateContent.split("\n").filter((line) => line.trim().length > 0);
|
|
2216
|
-
const sections = parseTemplateSections(templateLines);
|
|
2217
|
-
const existingEntries = new Set(existing.filter((line) => !isComment(line)));
|
|
2218
|
-
const templateEntries = new Set(templateLines.filter((line) => !isComment(line)));
|
|
2219
|
-
const customEntries = [...existingEntries].filter((entry) => !templateEntries.has(entry));
|
|
2220
|
-
const result = [];
|
|
2221
|
-
for (const section of sections) {
|
|
2222
|
-
for (const line of section) {
|
|
2223
|
-
result.push(line);
|
|
2224
|
-
}
|
|
2225
|
-
result.push("");
|
|
2226
|
-
}
|
|
2227
|
-
if (customEntries.length > 0) {
|
|
2228
|
-
result.push("# Custom");
|
|
2229
|
-
const sorted = [...union(customEntries, [])].toSorted((a, b) => {
|
|
2230
|
-
if (isNegation(a) && !isNegation(b)) return 1;
|
|
2231
|
-
if (!isNegation(a) && isNegation(b)) return -1;
|
|
2232
|
-
return a.localeCompare(b);
|
|
2233
|
-
});
|
|
2234
|
-
for (const entry of sorted) {
|
|
2235
|
-
result.push(entry);
|
|
2236
|
-
}
|
|
2237
|
-
result.push("");
|
|
2238
|
-
}
|
|
2239
|
-
return result;
|
|
2240
|
-
}
|
|
2241
|
-
function removePackageGitignores(cwd5) {
|
|
2242
|
-
let removed = 0;
|
|
2243
|
-
const workspaces = yarnWorkspaces();
|
|
2244
|
-
for (const { location } of workspaces) {
|
|
2245
|
-
if (location === ".") continue;
|
|
2246
|
-
const filePath = `${cwd5}/${location}/.gitignore`;
|
|
2247
|
-
try {
|
|
2248
|
-
unlinkSync4(filePath);
|
|
2249
|
-
console.log(chalk26.yellow(` Removed ${location}/.gitignore`));
|
|
2250
|
-
removed++;
|
|
2251
|
-
} catch {
|
|
2252
|
-
}
|
|
2253
|
-
}
|
|
2254
|
-
return removed;
|
|
2255
|
-
}
|
|
2256
|
-
var gitignoreGen = gitignore;
|
|
2257
|
-
function gitignore() {
|
|
2258
|
-
console.log(chalk26.green("Generate .gitignore"));
|
|
2259
|
-
const cwd5 = INIT_CWD() ?? ".";
|
|
2260
|
-
const gitignorePath = `${cwd5}/.gitignore`;
|
|
2261
|
-
try {
|
|
2262
|
-
const templateContent = gitignoreTemplate();
|
|
2263
|
-
const existing = readNonEmptyLines(gitignorePath);
|
|
2264
|
-
const merged = mergeWithTemplate(existing, templateContent);
|
|
2265
|
-
writeLines(gitignorePath, merged);
|
|
2266
|
-
console.log(chalk26.green(" Root .gitignore updated"));
|
|
2267
|
-
const removed = removePackageGitignores(cwd5);
|
|
2268
|
-
if (removed > 0) {
|
|
2269
|
-
console.log(chalk26.green(` Removed ${removed} package .gitignore file(s)`));
|
|
2270
|
-
}
|
|
2271
|
-
return 0;
|
|
2272
|
-
} catch (ex) {
|
|
2273
|
-
const error = ex;
|
|
2274
|
-
console.error(chalk26.red(`Generate .gitignore failed: ${error.message}`));
|
|
2275
|
-
return 1;
|
|
2276
|
-
}
|
|
2277
|
-
}
|
|
2278
|
-
|
|
2279
|
-
// src/actions/gitlint.ts
|
|
2280
|
-
import chalk27 from "chalk";
|
|
2281
|
-
import ParseGitConfig from "parse-git-config";
|
|
2282
|
-
var gitlint = () => {
|
|
2283
|
-
console.log(`
|
|
2284
|
-
Gitlint Start [${process.cwd()}]
|
|
2285
|
-
`);
|
|
2286
|
-
let valid = 0;
|
|
2287
|
-
let warnings = 0;
|
|
2288
|
-
const errors = 0;
|
|
2289
|
-
const gitConfig = ParseGitConfig.sync();
|
|
2290
|
-
const warn = (message) => {
|
|
2291
|
-
console.warn(chalk27.yellow(`Warning: ${message}`));
|
|
2292
|
-
warnings++;
|
|
2293
|
-
};
|
|
2294
|
-
if (gitConfig.core.ignorecase) {
|
|
2295
|
-
warn("Please set core.ignorecase to FALSE in .git/config file [run yarn gitlint-fix]");
|
|
2296
|
-
} else {
|
|
2297
|
-
valid++;
|
|
2298
|
-
}
|
|
2299
|
-
if (gitConfig.core.autocrlf === false) {
|
|
2300
|
-
valid++;
|
|
2301
|
-
} else {
|
|
2302
|
-
warn("Please set core.autocrlf to FALSE in .git/config file [run yarn gitlint-fix]");
|
|
2303
|
-
}
|
|
2304
|
-
if (gitConfig.core.eol === "lf") {
|
|
2305
|
-
valid++;
|
|
2306
|
-
} else {
|
|
2307
|
-
warn('Please set core.eol to "lf" in .git/config file [run yarn gitlint-fix]');
|
|
2308
|
-
}
|
|
2309
|
-
const resultMessages = [];
|
|
2310
|
-
if (valid > 0) {
|
|
2311
|
-
resultMessages.push(chalk27.green(`Passed: ${valid}`));
|
|
2312
|
-
}
|
|
2313
|
-
if (warnings > 0) {
|
|
2314
|
-
resultMessages.push(chalk27.yellow(`Warnings: ${warnings}`));
|
|
2315
|
-
}
|
|
2316
|
-
if (errors > 0) {
|
|
2317
|
-
resultMessages.push(chalk27.red(` Errors: ${errors}`));
|
|
2318
|
-
}
|
|
2319
|
-
console.warn(`Gitlint Finish [ ${resultMessages.join(" | ")} ]
|
|
2320
|
-
`);
|
|
2321
|
-
return warnings + errors === 0 ? 1 : 0;
|
|
2322
|
-
};
|
|
2323
|
-
|
|
2324
|
-
// src/actions/gitlint-fix.ts
|
|
2325
|
-
import { execSync as execSync3 } from "child_process";
|
|
2326
|
-
import chalk28 from "chalk";
|
|
2327
|
-
import ParseGitConfig2 from "parse-git-config";
|
|
2328
|
-
var gitlintFix = () => {
|
|
2329
|
-
console.log(`
|
|
2330
|
-
Gitlint Fix Start [${process.cwd()}]
|
|
2331
|
-
`);
|
|
2332
|
-
const gitConfig = ParseGitConfig2.sync();
|
|
2333
|
-
if (gitConfig.core.ignorecase) {
|
|
2334
|
-
execSync3("git config core.ignorecase false", { stdio: "inherit" });
|
|
2335
|
-
console.warn(chalk28.yellow("\nGitlint Fix: Updated core.ignorecase to be false\n"));
|
|
2336
|
-
}
|
|
2337
|
-
if (gitConfig.core.autocrlf !== false) {
|
|
2338
|
-
execSync3("git config core.autocrlf false", { stdio: "inherit" });
|
|
2339
|
-
console.warn(chalk28.yellow("\nGitlint Fix: Updated core.autocrlf to be false\n"));
|
|
2340
|
-
}
|
|
2341
|
-
if (gitConfig.core.eol !== "lf") {
|
|
2342
|
-
execSync3("git config core.eol lf", { stdio: "inherit" });
|
|
2343
|
-
console.warn(chalk28.yellow('\nGitlint Fix: Updated core.eol to be "lf"\n'));
|
|
2344
|
-
}
|
|
2345
|
-
return 1;
|
|
2346
|
-
};
|
|
2347
|
-
|
|
2348
|
-
// src/actions/knip.ts
|
|
2349
|
-
var knip = () => {
|
|
2350
|
-
return runSteps("Knip", [["yarn", ["knip", "--dependencies", "--no-exit-code"]]]);
|
|
2351
|
-
};
|
|
2352
|
-
|
|
2353
|
-
// src/actions/license.ts
|
|
2354
|
-
import chalk29 from "chalk";
|
|
2355
|
-
import { init } from "license-checker";
|
|
2356
|
-
var license = async (pkg) => {
|
|
2357
|
-
const workspaces = yarnWorkspaces();
|
|
2358
|
-
const workspaceList = workspaces.filter(({ name }) => {
|
|
2359
|
-
return pkg === void 0 || name === pkg;
|
|
2360
|
-
});
|
|
2361
|
-
const exclude = /* @__PURE__ */ new Set([
|
|
2362
|
-
"MIT",
|
|
2363
|
-
"MIT*",
|
|
2364
|
-
"ISC",
|
|
2365
|
-
"Apache-2.0",
|
|
2366
|
-
"BSD",
|
|
2367
|
-
"BSD*",
|
|
2368
|
-
"BSD-2-Clause",
|
|
2369
|
-
"BSD-3-Clause",
|
|
2370
|
-
"CC-BY-4.0",
|
|
2371
|
-
"Unlicense",
|
|
2372
|
-
"CC-BY-3.0",
|
|
2373
|
-
"CC0-1.0",
|
|
2374
|
-
"LGPL-3.0-only",
|
|
2375
|
-
"LGPL-3.0",
|
|
2376
|
-
"LGPL-3.0-or-later",
|
|
2377
|
-
"Python-2.0"
|
|
2378
|
-
]);
|
|
2379
|
-
console.log(chalk29.green("License Checker"));
|
|
2380
|
-
return (await Promise.all(
|
|
2381
|
-
workspaceList.map(({ location, name }) => {
|
|
2382
|
-
return new Promise((resolve) => {
|
|
2383
|
-
init({ production: true, start: location }, (error, packages) => {
|
|
2384
|
-
if (error) {
|
|
2385
|
-
console.error(chalk29.red(`License Checker [${name}] Error`));
|
|
2386
|
-
console.error(chalk29.gray(error));
|
|
2387
|
-
console.log("\n");
|
|
2388
|
-
resolve(1);
|
|
2389
|
-
} else {
|
|
2390
|
-
console.log(chalk29.green(`License Checker [${name}]`));
|
|
2391
|
-
let count = 0;
|
|
2392
|
-
for (const [name2, info] of Object.entries(packages)) {
|
|
2393
|
-
const licenses = Array.isArray(info.licenses) ? info.licenses : [info.licenses];
|
|
2394
|
-
for (let license2 of licenses) {
|
|
2395
|
-
if (license2) {
|
|
2396
|
-
const processedLicense = license2[0] === "(" && license2.at(-1) === ")" ? license2.slice(1, -2) : license2;
|
|
2397
|
-
const orLicenses = processedLicense.split(" OR ");
|
|
2398
|
-
let orLicenseFound = false;
|
|
2399
|
-
for (const orLicense of orLicenses) {
|
|
2400
|
-
if (exclude.has(orLicense)) {
|
|
2401
|
-
orLicenseFound = true;
|
|
2402
|
-
}
|
|
2403
|
-
}
|
|
2404
|
-
if (!orLicenseFound) {
|
|
2405
|
-
count++;
|
|
2406
|
-
console.warn(chalk29.yellow(`${name2}: Package License not allowed [${license2}]`));
|
|
2407
|
-
}
|
|
2408
|
-
}
|
|
2409
|
-
}
|
|
2410
|
-
}
|
|
2411
|
-
console.log("\n");
|
|
2412
|
-
resolve(count);
|
|
2413
|
-
}
|
|
2414
|
-
});
|
|
2415
|
-
});
|
|
2416
|
-
})
|
|
2417
|
-
)).reduce((prev, value) => prev || value, 0);
|
|
2418
|
-
};
|
|
2419
|
-
|
|
2420
|
-
// src/actions/lintlint.ts
|
|
2421
|
-
import { readFileSync as readFileSync13, writeFileSync as writeFileSync6 } from "fs";
|
|
2422
|
-
import PATH9 from "path";
|
|
2423
|
-
import chalk30 from "chalk";
|
|
2424
|
-
import { findUp } from "find-up";
|
|
2425
|
-
function parseRuleValue(value) {
|
|
2426
|
-
if (typeof value === "string") {
|
|
2427
|
-
return { level: value };
|
|
2428
|
-
}
|
|
2429
|
-
if (typeof value === "number") {
|
|
2430
|
-
return { level: String(value) };
|
|
2431
|
-
}
|
|
2432
|
-
if (Array.isArray(value) && value.length > 0) {
|
|
2433
|
-
return {
|
|
2434
|
-
level: String(value[0]),
|
|
2435
|
-
options: value.length > 1 ? value.slice(1) : void 0
|
|
2436
|
-
};
|
|
2437
|
-
}
|
|
2438
|
-
return void 0;
|
|
2439
|
-
}
|
|
2440
|
-
function normalizeLevel(level) {
|
|
2441
|
-
if (level === "0" || level === "off") return "off";
|
|
2442
|
-
if (level === "1" || level === "warn") return "warn";
|
|
2443
|
-
if (level === "2" || level === "error") return "error";
|
|
2444
|
-
return level;
|
|
2445
|
-
}
|
|
2446
|
-
function rulesMatch(a, b) {
|
|
2447
|
-
if (normalizeLevel(a.level) !== normalizeLevel(b.level)) return false;
|
|
2448
|
-
return JSON.stringify(a.options) === JSON.stringify(b.options);
|
|
2449
|
-
}
|
|
2450
|
-
function formatRule(entry) {
|
|
2451
|
-
if (entry.options) {
|
|
2452
|
-
return JSON.stringify([entry.level, ...entry.options]);
|
|
2453
|
-
}
|
|
2454
|
-
return JSON.stringify([entry.level]);
|
|
2455
|
-
}
|
|
2456
|
-
function mergeRulesFromBlocks(blocks) {
|
|
2457
|
-
const merged = /* @__PURE__ */ new Map();
|
|
2458
|
-
for (const block of blocks) {
|
|
2459
|
-
if (!block.rules) continue;
|
|
2460
|
-
for (const [name, value] of Object.entries(block.rules)) {
|
|
2461
|
-
const parsed = parseRuleValue(value);
|
|
2462
|
-
if (parsed) merged.set(name, parsed);
|
|
2463
|
-
}
|
|
2464
|
-
}
|
|
2465
|
-
return merged;
|
|
2466
|
-
}
|
|
2467
|
-
function detectSharedPackage(source) {
|
|
2468
|
-
if (source.includes("@xylabs/eslint-config-react-flat")) return "@xylabs/eslint-config-react-flat";
|
|
2469
|
-
if (source.includes("@xylabs/eslint-config-flat")) return "@xylabs/eslint-config-flat";
|
|
2470
|
-
return void 0;
|
|
2471
|
-
}
|
|
2472
|
-
function extractLocalRuleBlocks(source) {
|
|
2473
|
-
const blocks = [];
|
|
2474
|
-
const ruleBlockRegex = /\{\s*(?:files\s*:\s*\[.*?\]\s*,\s*)?rules\s*:\s*\{([^}]*(?:\{[^}]*\}[^}]*)*)\}/g;
|
|
2475
|
-
let match;
|
|
2476
|
-
while ((match = ruleBlockRegex.exec(source)) !== null) {
|
|
2477
|
-
blocks.push(match[1]);
|
|
2478
|
-
}
|
|
2479
|
-
return blocks;
|
|
2480
|
-
}
|
|
2481
|
-
function extractRulesFromSourceBlocks(blocks) {
|
|
2482
|
-
const rules2 = /* @__PURE__ */ new Map();
|
|
2483
|
-
for (const block of blocks) {
|
|
2484
|
-
const ruleRegex = /['"]([^'"]+)['"]\s*:\s*(\[[\s\S]*?\](?=\s*,|\s*$))/gm;
|
|
2485
|
-
let match;
|
|
2486
|
-
while ((match = ruleRegex.exec(block)) !== null) {
|
|
2487
|
-
rules2.set(match[1], match[2]);
|
|
2488
|
-
}
|
|
2489
|
-
}
|
|
2490
|
-
return rules2;
|
|
2491
|
-
}
|
|
2492
|
-
async function resolveSharedConfig(configDir, sharedPkg) {
|
|
2493
|
-
try {
|
|
2494
|
-
const sharedModule = await import(sharedPkg);
|
|
2495
|
-
const config2 = sharedModule.config ?? sharedModule.default;
|
|
2496
|
-
if (Array.isArray(config2)) return config2;
|
|
2497
|
-
return [];
|
|
2498
|
-
} catch {
|
|
2499
|
-
const distPath = PATH9.resolve(configDir, "node_modules", sharedPkg, "dist", "node", "index.mjs");
|
|
2500
|
-
try {
|
|
2501
|
-
const sharedModule = await import(distPath);
|
|
2502
|
-
const config2 = sharedModule.config ?? sharedModule.default;
|
|
2503
|
-
if (Array.isArray(config2)) return config2;
|
|
2504
|
-
} catch {
|
|
2505
|
-
const neutralPath = PATH9.resolve(configDir, "node_modules", sharedPkg, "dist", "neutral", "index.mjs");
|
|
2506
|
-
const sharedModule = await import(neutralPath);
|
|
2507
|
-
const config2 = sharedModule.config ?? sharedModule.default;
|
|
2508
|
-
if (Array.isArray(config2)) return config2;
|
|
2509
|
-
}
|
|
2510
|
-
return [];
|
|
2511
|
-
}
|
|
2512
|
-
}
|
|
2513
|
-
async function loadSharedRules(configDir, sharedPkg, verbose) {
|
|
2514
|
-
const sharedBlocks = await resolveSharedConfig(configDir, sharedPkg);
|
|
2515
|
-
const sharedRules = mergeRulesFromBlocks(sharedBlocks);
|
|
2516
|
-
if (verbose) {
|
|
2517
|
-
console.log(chalk30.gray(`Shared config defines ${sharedRules.size} rules`));
|
|
2518
|
-
}
|
|
2519
|
-
if (sharedRules.size === 0) {
|
|
2520
|
-
console.error(chalk30.red("Could not load rules from shared config. Is it installed and built?"));
|
|
2521
|
-
return void 0;
|
|
2522
|
-
}
|
|
2523
|
-
return sharedRules;
|
|
2524
|
-
}
|
|
2525
|
-
async function loadLocalRules(eslintConfigPath, source, verbose) {
|
|
2526
|
-
const localModule = await import(eslintConfigPath);
|
|
2527
|
-
const localConfig = localModule.default ?? localModule;
|
|
2528
|
-
const localBlocks = Array.isArray(localConfig) ? localConfig : [localConfig];
|
|
2529
|
-
const resolved = mergeRulesFromBlocks(localBlocks);
|
|
2530
|
-
const localRuleBlocks = extractLocalRuleBlocks(source);
|
|
2531
|
-
const explicit = extractRulesFromSourceBlocks(localRuleBlocks);
|
|
2532
|
-
if (verbose) {
|
|
2533
|
-
console.log(chalk30.gray(`Local config has ${explicit.size} explicit rule setting(s)`));
|
|
2534
|
-
}
|
|
2535
|
-
return { explicit, resolved };
|
|
2536
|
-
}
|
|
2537
|
-
function compareRules(explicitRuleNames, allResolvedRules, sharedRules) {
|
|
2538
|
-
const redundant = [];
|
|
2539
|
-
const overrides = [];
|
|
2540
|
-
const additions = [];
|
|
2541
|
-
for (const ruleName of explicitRuleNames.keys()) {
|
|
2542
|
-
const resolvedEntry = allResolvedRules.get(ruleName);
|
|
2543
|
-
const sharedEntry = sharedRules.get(ruleName);
|
|
2544
|
-
if (!resolvedEntry) continue;
|
|
2545
|
-
if (!sharedEntry) {
|
|
2546
|
-
additions.push({ local: resolvedEntry, rule: ruleName });
|
|
2547
|
-
} else if (rulesMatch(resolvedEntry, sharedEntry)) {
|
|
2548
|
-
redundant.push({
|
|
2549
|
-
local: resolvedEntry,
|
|
2550
|
-
rule: ruleName,
|
|
2551
|
-
shared: sharedEntry
|
|
2552
|
-
});
|
|
2553
|
-
} else {
|
|
2554
|
-
overrides.push({
|
|
2555
|
-
local: resolvedEntry,
|
|
2556
|
-
rule: ruleName,
|
|
2557
|
-
shared: sharedEntry
|
|
2558
|
-
});
|
|
2559
|
-
}
|
|
2560
|
-
}
|
|
2561
|
-
return {
|
|
2562
|
-
additions,
|
|
2563
|
-
overrides,
|
|
2564
|
-
redundant
|
|
2565
|
-
};
|
|
2566
|
-
}
|
|
2567
|
-
function reportResults({
|
|
2568
|
-
additions,
|
|
2569
|
-
overrides,
|
|
2570
|
-
redundant
|
|
2571
|
-
}, verbose) {
|
|
2572
|
-
if (redundant.length > 0) {
|
|
2573
|
-
console.log(chalk30.yellow(`
|
|
2574
|
-
${redundant.length} redundant rule(s) (same as shared config \u2014 can be removed):`));
|
|
2575
|
-
for (const { rule, local } of redundant) {
|
|
2576
|
-
console.log(chalk30.yellow(` ${rule}: ${formatRule(local)}`));
|
|
2577
|
-
}
|
|
2578
|
-
}
|
|
2579
|
-
if (overrides.length > 0) {
|
|
2580
|
-
console.log(chalk30.cyan(`
|
|
2581
|
-
${overrides.length} rule override(s) (different from shared config):`));
|
|
2582
|
-
for (const {
|
|
2583
|
-
rule,
|
|
2584
|
-
local,
|
|
2585
|
-
shared
|
|
2586
|
-
} of overrides) {
|
|
2587
|
-
console.log(chalk30.cyan(` ${rule}:`));
|
|
2588
|
-
console.log(chalk30.gray(` shared: ${formatRule(shared)}`));
|
|
2589
|
-
console.log(chalk30.white(` local: ${formatRule(local)}`));
|
|
2590
|
-
}
|
|
2591
|
-
}
|
|
2592
|
-
if (additions.length > 0 && verbose) {
|
|
2593
|
-
console.log(chalk30.gray(`
|
|
2594
|
-
${additions.length} local addition(s) (not in shared config):`));
|
|
2595
|
-
for (const { rule, local } of additions) {
|
|
2596
|
-
console.log(chalk30.gray(` ${rule}: ${formatRule(local)}`));
|
|
2597
|
-
}
|
|
2598
|
-
}
|
|
2599
|
-
if (redundant.length === 0 && overrides.length === 0) {
|
|
2600
|
-
console.log(chalk30.green("No redundant or overridden rules found"));
|
|
2601
|
-
}
|
|
2602
|
-
}
|
|
2603
|
-
function fixRedundantRules(eslintConfigPath, source, redundant) {
|
|
2604
|
-
let updated = source;
|
|
2605
|
-
for (const { rule } of redundant) {
|
|
2606
|
-
const escaped = rule.replaceAll("/", String.raw`\/`);
|
|
2607
|
-
const pattern = new RegExp(String.raw`[ \t]*['"]${escaped}['"]\s*:\s*\[[^\]]*\],?[ \t]*\n?`, "g");
|
|
2608
|
-
updated = updated.replace(pattern, "");
|
|
2609
|
-
}
|
|
2610
|
-
updated = updated.replaceAll(/\n{3,}/g, "\n\n");
|
|
2611
|
-
if (updated !== source) {
|
|
2612
|
-
writeFileSync6(eslintConfigPath, updated, "utf8");
|
|
2613
|
-
console.log(chalk30.green(`
|
|
2614
|
-
Fixed: removed ${redundant.length} redundant rule(s)`));
|
|
2615
|
-
}
|
|
2616
|
-
}
|
|
2617
|
-
async function lintlint({ fix: fix2, verbose } = {}) {
|
|
2618
|
-
const eslintConfigPath = await findUp("eslint.config.mjs");
|
|
2619
|
-
if (!eslintConfigPath) {
|
|
2620
|
-
console.error(chalk30.red("No eslint.config.mjs found"));
|
|
2621
|
-
return 1;
|
|
2622
|
-
}
|
|
2623
|
-
const configDir = PATH9.dirname(eslintConfigPath);
|
|
2624
|
-
if (verbose) {
|
|
2625
|
-
console.log(chalk30.gray(`Found config: ${eslintConfigPath}`));
|
|
2626
|
-
}
|
|
2627
|
-
const source = readFileSync13(eslintConfigPath, "utf8");
|
|
2628
|
-
const sharedPkg = detectSharedPackage(source);
|
|
2629
|
-
if (!sharedPkg) {
|
|
2630
|
-
console.log(chalk30.yellow("No @xylabs/eslint-config-flat or @xylabs/eslint-config-react-flat imports found"));
|
|
2631
|
-
return 0;
|
|
2632
|
-
}
|
|
2633
|
-
if (verbose) {
|
|
2634
|
-
console.log(chalk30.gray(`Shared package: ${sharedPkg}`));
|
|
2635
|
-
}
|
|
2636
|
-
const sharedRules = await loadSharedRules(configDir, sharedPkg, !!verbose);
|
|
2637
|
-
if (!sharedRules) return 1;
|
|
2638
|
-
const { explicit, resolved } = await loadLocalRules(eslintConfigPath, source, !!verbose);
|
|
2639
|
-
const results = compareRules(explicit, resolved, sharedRules);
|
|
2640
|
-
reportResults(results, !!verbose);
|
|
2641
|
-
if (results.redundant.length > 0 && fix2) {
|
|
2642
|
-
fixRedundantRules(eslintConfigPath, source, results.redundant);
|
|
2643
|
-
}
|
|
2644
|
-
return results.redundant.length > 0 && !fix2 ? 1 : 0;
|
|
2645
|
-
}
|
|
2646
|
-
|
|
2647
|
-
// src/actions/npmignore-gen.ts
|
|
2648
|
-
var filename = ".npmignore";
|
|
2649
|
-
var npmignoreGen = (pkg) => generateIgnoreFiles(filename, pkg);
|
|
2650
|
-
|
|
2651
|
-
// src/actions/package/clean-outputs.ts
|
|
2652
|
-
import path8 from "path";
|
|
2653
|
-
import chalk31 from "chalk";
|
|
2654
|
-
var packageCleanOutputs = () => {
|
|
2655
|
-
const pkg = process.env.INIT_CWD ?? ".";
|
|
2656
|
-
const pkgName = process.env.npm_package_name;
|
|
2657
|
-
const folders = [path8.join(pkg, "dist"), path8.join(pkg, "build"), path8.join(pkg, "docs")];
|
|
2658
|
-
console.log(chalk31.green(`Cleaning Outputs [${pkgName}]`));
|
|
2659
|
-
for (let folder of folders) {
|
|
2660
|
-
deleteGlob(folder);
|
|
2661
|
-
}
|
|
2662
|
-
return 0;
|
|
2663
|
-
};
|
|
2664
|
-
|
|
2665
|
-
// src/actions/package/clean-typescript.ts
|
|
2666
|
-
import path9 from "path";
|
|
2667
|
-
import chalk32 from "chalk";
|
|
2668
|
-
var packageCleanTypescript = () => {
|
|
2669
|
-
const pkg = process.env.INIT_CWD ?? ".";
|
|
2670
|
-
const pkgName = process.env.npm_package_name;
|
|
2671
|
-
console.log(chalk32.green(`Cleaning Typescript [${pkgName}]`));
|
|
2672
|
-
const files = [path9.join(pkg, "*.tsbuildinfo"), path9.join(pkg, ".tsconfig.*"), path9.join(pkg, ".eslintcache")];
|
|
2673
|
-
for (let file of files) {
|
|
2674
|
-
deleteGlob(file);
|
|
2675
|
-
}
|
|
2676
|
-
return 0;
|
|
2677
|
-
};
|
|
2678
|
-
|
|
2679
|
-
// src/actions/package/clean.ts
|
|
2680
|
-
var packageClean = async () => {
|
|
2681
|
-
return (await Promise.all([packageCleanOutputs(), packageCleanTypescript()])).reduce((prev, value) => prev + value, 0);
|
|
2682
|
-
};
|
|
2683
|
-
|
|
2684
|
-
// src/actions/package/compile/compile.ts
|
|
2685
|
-
import chalk37 from "chalk";
|
|
2686
|
-
|
|
2687
|
-
// src/actions/package/compile/packageCompileTsup.ts
|
|
2688
|
-
import chalk36 from "chalk";
|
|
2689
|
-
import { build as build2, defineConfig } from "tsup";
|
|
2690
|
-
|
|
2691
|
-
// src/actions/package/compile/inputs.ts
|
|
2692
|
-
import chalk33 from "chalk";
|
|
2693
|
-
import { glob as glob2 } from "glob";
|
|
2694
|
-
var getAllInputs = (srcDir, verbose = false) => {
|
|
2695
|
-
return [...glob2.sync(`${srcDir}/**/*.ts`, { posix: true }).map((file) => {
|
|
2696
|
-
const result = file.slice(Math.max(0, srcDir.length + 1));
|
|
2697
|
-
if (verbose) {
|
|
2698
|
-
console.log(chalk33.gray(`getAllInputs: ${JSON.stringify(result, null, 2)}`));
|
|
2699
|
-
}
|
|
2700
|
-
return result;
|
|
2701
|
-
}), ...glob2.sync(`${srcDir}/**/*.tsx`, { posix: true }).map((file) => {
|
|
2702
|
-
const result = file.slice(Math.max(0, srcDir.length + 1));
|
|
2703
|
-
if (verbose) {
|
|
2704
|
-
console.log(chalk33.gray(`getAllInputs: ${JSON.stringify(result, null, 2)}`));
|
|
2705
|
-
}
|
|
2706
|
-
return result;
|
|
2707
|
-
})];
|
|
2708
|
-
};
|
|
2709
|
-
|
|
2710
|
-
// src/actions/package/compile/buildEntries.ts
|
|
2711
|
-
var isSpecOrStory = (entry) => {
|
|
2712
|
-
return entry.includes(".spec.") || entry.includes(".stories.") || entry.startsWith("spec/") || entry.includes("/spec/") || entry.startsWith("stories/") || entry.includes("/stories/") || entry === "spec.ts" || entry.endsWith("/spec.ts") || entry === "stories.ts" || entry.endsWith("/stories.ts");
|
|
2713
|
-
};
|
|
2714
|
-
var buildEntries = (srcDir, entryMode = "single", options, excludeSpecAndStories = true, verbose = false) => {
|
|
2715
|
-
let entries = [];
|
|
2716
|
-
switch (entryMode) {
|
|
2717
|
-
case "platform": {
|
|
2718
|
-
entries = ["index-node.ts", "index-browser.ts"];
|
|
2719
|
-
break;
|
|
2720
|
-
}
|
|
2721
|
-
case "all": {
|
|
2722
|
-
entries = (excludeSpecAndStories ? getAllInputs(srcDir).filter((entry) => !isSpecOrStory(entry)) : getAllInputs(srcDir)).filter((entry) => !entry.endsWith(".d.ts"));
|
|
2723
|
-
break;
|
|
2724
|
-
}
|
|
2725
|
-
case "custom": {
|
|
2726
|
-
entries = [];
|
|
2727
|
-
break;
|
|
2728
|
-
}
|
|
2729
|
-
default: {
|
|
2730
|
-
entries = ["index.ts"];
|
|
2731
|
-
break;
|
|
2732
|
-
}
|
|
2733
|
-
}
|
|
2734
|
-
if (typeof options !== "boolean" && Array.isArray(options?.entry)) {
|
|
2735
|
-
entries.push(...options.entry);
|
|
2736
|
-
}
|
|
2737
|
-
if (verbose) console.log(`buildEntries [${entryMode}] ${entries.length}`);
|
|
2738
|
-
return entries;
|
|
2739
|
-
};
|
|
2740
|
-
|
|
2741
|
-
// src/actions/package/compile/deepMerge.ts
|
|
2742
|
-
function deepMerge(target, source) {
|
|
2743
|
-
if (!source || typeof source !== "object") return target;
|
|
2744
|
-
for (const key of Object.keys(source)) {
|
|
2745
|
-
if (typeof source[key] === "object" && source[key] !== null && !Array.isArray(source[key])) {
|
|
2746
|
-
if (!target[key] || typeof target[key] !== "object") {
|
|
2747
|
-
target[key] = {};
|
|
2748
|
-
}
|
|
2749
|
-
deepMerge(target[key], source[key]);
|
|
2750
|
-
} else {
|
|
2751
|
-
target[key] = source[key];
|
|
2752
|
-
}
|
|
2753
|
-
}
|
|
2754
|
-
return target;
|
|
2755
|
-
}
|
|
2756
|
-
function deepMergeObjects(objects) {
|
|
2757
|
-
const result = {};
|
|
2758
|
-
for (const obj of objects) {
|
|
2759
|
-
deepMerge(result, obj);
|
|
2760
|
-
}
|
|
2761
|
-
return result;
|
|
2762
|
-
}
|
|
2763
|
-
|
|
2764
|
-
// src/actions/package/compile/packageCompileTsc.ts
|
|
2765
|
-
import { cwd as cwd2 } from "process";
|
|
2766
|
-
import chalk34 from "chalk";
|
|
2767
|
-
import { createProgramFromConfig } from "tsc-prog";
|
|
2768
|
-
import ts3, {
|
|
2769
|
-
DiagnosticCategory,
|
|
2770
|
-
formatDiagnosticsWithColorAndContext,
|
|
2771
|
-
getPreEmitDiagnostics,
|
|
2772
|
-
sys
|
|
2773
|
-
} from "typescript";
|
|
2774
|
-
|
|
2775
|
-
// src/actions/package/compile/getCompilerOptions.ts
|
|
2776
|
-
import { cwd } from "process";
|
|
2777
|
-
import deepmerge2 from "deepmerge";
|
|
2778
|
-
import { getTsconfig } from "get-tsconfig";
|
|
2779
|
-
var getCompilerOptions = (options = {}, fileName = "tsconfig.json") => {
|
|
2780
|
-
const resolvedTsConfigCompilerOptions = getTsconfig(cwd(), fileName)?.config?.compilerOptions ?? {};
|
|
2781
|
-
return deepmerge2(resolvedTsConfigCompilerOptions, options);
|
|
2782
|
-
};
|
|
1
|
+
// src/actions/deploy.ts
|
|
2
|
+
import { readFileSync } from "fs";
|
|
3
|
+
import { runSteps } from "@xylabs/ts-scripts-common";
|
|
2783
4
|
|
|
2784
|
-
// src/
|
|
2785
|
-
|
|
2786
|
-
|
|
2787
|
-
|
|
2788
|
-
|
|
2789
|
-
|
|
2790
|
-
const
|
|
2791
|
-
|
|
2792
|
-
|
|
2793
|
-
|
|
2794
|
-
|
|
2795
|
-
|
|
2796
|
-
|
|
2797
|
-
throw new Error("Could not find tsconfig.json");
|
|
2798
|
-
}
|
|
2799
|
-
const compilerOptions = {
|
|
2800
|
-
...getCompilerOptions({
|
|
2801
|
-
removeComments: false,
|
|
2802
|
-
skipDefaultLibCheck: true,
|
|
2803
|
-
skipLibCheck: true,
|
|
2804
|
-
sourceMap: false
|
|
2805
|
-
}),
|
|
2806
|
-
...compilerOptionsParam,
|
|
2807
|
-
outDir: `${outDir}/${platform}`,
|
|
2808
|
-
emitDeclarationOnly: true,
|
|
2809
|
-
noEmit: false
|
|
2810
|
-
};
|
|
2811
|
-
console.log(chalk34.cyan(`Validating Files: ${entries.length}`));
|
|
2812
|
-
if (verbose) {
|
|
2813
|
-
for (const entry of entries) {
|
|
2814
|
-
console.log(chalk34.grey(`Validating: ${entry}`));
|
|
2815
|
-
}
|
|
2816
|
-
}
|
|
2817
|
-
try {
|
|
2818
|
-
if (entries.length > 0) {
|
|
2819
|
-
const program = createProgramFromConfig({
|
|
2820
|
-
configFilePath,
|
|
2821
|
-
basePath: pkg ?? cwd2(),
|
|
2822
|
-
compilerOptions,
|
|
2823
|
-
files: entries.map((entry) => `${srcDir}/${entry}`),
|
|
2824
|
-
include: [`${srcDir}/**/*.*`]
|
|
2825
|
-
});
|
|
2826
|
-
const diagnostics = getPreEmitDiagnostics(program);
|
|
2827
|
-
if (diagnostics.length > 0) {
|
|
2828
|
-
const formattedDiagnostics = formatDiagnosticsWithColorAndContext(
|
|
2829
|
-
diagnostics,
|
|
2830
|
-
{
|
|
2831
|
-
getCanonicalFileName: (fileName) => fileName,
|
|
2832
|
-
getCurrentDirectory: () => srcDir,
|
|
2833
|
-
getNewLine: () => sys.newLine
|
|
2834
|
-
}
|
|
2835
|
-
);
|
|
2836
|
-
console.error(formattedDiagnostics);
|
|
2837
|
-
}
|
|
2838
|
-
const nonEmitPatterns = [".stories.", "/stories/", "/stories.", ".spec.", "/spec/", "/spec.", ".example."];
|
|
2839
|
-
program.emit(void 0, (fileName, text, writeByteOrderMark) => {
|
|
2840
|
-
if (nonEmitPatterns.some((pattern) => fileName.includes(pattern))) {
|
|
2841
|
-
return;
|
|
2842
|
-
}
|
|
2843
|
-
ts3.sys.writeFile(fileName, text, writeByteOrderMark);
|
|
2844
|
-
});
|
|
2845
|
-
return diagnostics.reduce((acc, diag) => acc + (diag.category === DiagnosticCategory.Error ? 1 : 0), 0);
|
|
2846
|
-
}
|
|
2847
|
-
return 0;
|
|
2848
|
-
} finally {
|
|
2849
|
-
if (verbose) {
|
|
2850
|
-
console.log(chalk34.cyan(`Validating code FINISH: ${entries.length} files to ${outDir} from ${srcDir}`));
|
|
2851
|
-
}
|
|
2852
|
-
}
|
|
5
|
+
// src/lib/yarn/isYarnVersionOrGreater.ts
|
|
6
|
+
import { spawnSync } from "child_process";
|
|
7
|
+
var isYarnVersionOrGreater = (major, minor, patch) => {
|
|
8
|
+
const result = spawnSync("yarn", ["-v"], { encoding: "utf8", shell: true });
|
|
9
|
+
const version = result.stdout.toString().replaceAll("\n", "");
|
|
10
|
+
const versionNumbers = version.split(".").map((ver) => Number.parseInt(ver));
|
|
11
|
+
const majorDelta = versionNumbers[0] - major;
|
|
12
|
+
const minorDelta = versionNumbers[1] - (minor ?? versionNumbers[1]);
|
|
13
|
+
const patchDelta = versionNumbers[2] - (patch ?? versionNumbers[2]);
|
|
14
|
+
const majorOk = majorDelta >= 0;
|
|
15
|
+
const minorOk = majorDelta > 0 || minorDelta >= 0;
|
|
16
|
+
const patchOk = majorDelta > 0 || minorDelta > 0 || patchDelta >= 0;
|
|
17
|
+
return [majorOk && minorOk && patchOk, version];
|
|
2853
18
|
};
|
|
2854
19
|
|
|
2855
|
-
// src/
|
|
2856
|
-
import
|
|
2857
|
-
|
|
2858
|
-
|
|
2859
|
-
|
|
2860
|
-
|
|
2861
|
-
import nodeExternals from "rollup-plugin-node-externals";
|
|
2862
|
-
var ignoredWarningCodes = /* @__PURE__ */ new Set(["EMPTY_BUNDLE", "UNRESOLVED_IMPORT"]);
|
|
2863
|
-
async function bundleDts(inputPath, outputPath, platform, options, verbose = false) {
|
|
2864
|
-
const pkg = process.env.INIT_CWD ?? cwd3();
|
|
2865
|
-
const tsconfigPath = path10.resolve(pkg, "tsconfig.json");
|
|
2866
|
-
const nodePlugIns = platform === "node" ? [nodeExternals()] : [];
|
|
2867
|
-
try {
|
|
2868
|
-
const bundle = await rollup({
|
|
2869
|
-
input: inputPath,
|
|
2870
|
-
plugins: [dts({
|
|
2871
|
-
...options,
|
|
2872
|
-
tsconfig: tsconfigPath,
|
|
2873
|
-
compilerOptions: {
|
|
2874
|
-
emitDeclarationOnly: true,
|
|
2875
|
-
noEmit: false,
|
|
2876
|
-
declarationMap: true
|
|
2877
|
-
}
|
|
2878
|
-
}), ...nodePlugIns],
|
|
2879
|
-
onwarn(warning, warn) {
|
|
2880
|
-
if (ignoredWarningCodes.has(warning.code ?? "")) {
|
|
2881
|
-
return;
|
|
2882
|
-
}
|
|
2883
|
-
console.warn(chalk35.yellow(`[${warning.code}] ${warning.message}`));
|
|
2884
|
-
console.warn(chalk35.gray(inputPath));
|
|
2885
|
-
warn(warning);
|
|
2886
|
-
}
|
|
2887
|
-
});
|
|
2888
|
-
await bundle.write({
|
|
2889
|
-
file: outputPath,
|
|
2890
|
-
format: "es"
|
|
2891
|
-
});
|
|
2892
|
-
} catch (ex) {
|
|
2893
|
-
const error = ex;
|
|
2894
|
-
console.warn(chalk35.red(error));
|
|
2895
|
-
console.warn(chalk35.gray(inputPath));
|
|
2896
|
-
}
|
|
2897
|
-
if (verbose) {
|
|
2898
|
-
console.log(`Bundled declarations written to ${outputPath}`);
|
|
2899
|
-
}
|
|
2900
|
-
}
|
|
2901
|
-
var packageCompileTscTypes = async (entries, outDir, platform, srcDir = "build", verbose = false) => {
|
|
2902
|
-
if (verbose) {
|
|
2903
|
-
console.log(chalk35.cyan(`Compiling Types START [${platform}]: ${entries.length} files to ${outDir} from ${srcDir}`));
|
|
2904
|
-
console.log(`Entries: ${entries.join(", ")}`);
|
|
20
|
+
// src/lib/yarn/workspace/yarnWorkspaces.ts
|
|
21
|
+
import { spawnSync as spawnSync2 } from "child_process";
|
|
22
|
+
var yarnWorkspaces = () => {
|
|
23
|
+
const result = spawnSync2("yarn", ["workspaces", "list", "--json", "--recursive"], { encoding: "utf8", shell: true });
|
|
24
|
+
if (result.error) {
|
|
25
|
+
throw result.error;
|
|
2905
26
|
}
|
|
2906
|
-
|
|
2907
|
-
|
|
2908
|
-
const entryNameToTypeName = (entry) => {
|
|
2909
|
-
const splitEntryName = entry.split(".");
|
|
2910
|
-
const newEntryExtension = "d." + splitEntryName.at(-1);
|
|
2911
|
-
return [...splitEntryName.slice(0, -1), newEntryExtension].join(".");
|
|
2912
|
-
};
|
|
2913
|
-
const compilerOptions = getCompilerOptions({
|
|
2914
|
-
removeComments: false,
|
|
2915
|
-
skipDefaultLibCheck: true,
|
|
2916
|
-
skipLibCheck: true,
|
|
2917
|
-
declarationMap: true,
|
|
2918
|
-
emitDeclarationOnly: true,
|
|
2919
|
-
noEmit: true
|
|
27
|
+
return result.stdout.toString().split("\n").slice(0, -1).map((item) => {
|
|
28
|
+
return JSON.parse(item);
|
|
2920
29
|
});
|
|
2921
|
-
const entryNames = entries.map((entry) => entry.split(`${srcDir}/`).at(-1) ?? entry);
|
|
2922
|
-
await Promise.all(entryNames.map(async (entryName) => {
|
|
2923
|
-
const entryTypeName = entryNameToTypeName(entryName);
|
|
2924
|
-
await bundleDts(`${srcRoot}/${entryTypeName}`, `${outDir}/${entryTypeName}`, platform, { compilerOptions }, verbose);
|
|
2925
|
-
}));
|
|
2926
|
-
if (verbose) {
|
|
2927
|
-
console.log(chalk35.cyan(`Compiling Types FINISH: ${entries.length} files to ${outDir} from ${srcDir}`));
|
|
2928
|
-
}
|
|
2929
|
-
return 0;
|
|
2930
|
-
};
|
|
2931
|
-
|
|
2932
|
-
// src/actions/package/compile/packageCompileTsup.ts
|
|
2933
|
-
var compileFolder = async (srcDir, entries, buildDir, options, bundleTypes = false, verbose) => {
|
|
2934
|
-
const outDir = options?.outDir ?? "dist";
|
|
2935
|
-
if (verbose) {
|
|
2936
|
-
console.log(`compileFolder [${srcDir}, ${options?.outDir}]`);
|
|
2937
|
-
}
|
|
2938
|
-
if (entries.length === 0) {
|
|
2939
|
-
console.warn(chalk36.yellow(`No entries found in ${srcDir} to compile`));
|
|
2940
|
-
return 0;
|
|
2941
|
-
}
|
|
2942
|
-
if (verbose) {
|
|
2943
|
-
console.log(chalk36.gray(`buildDir [${buildDir}]`));
|
|
2944
|
-
}
|
|
2945
|
-
const validationResult = packageCompileTsc(options?.platform ?? "neutral", entries, srcDir, buildDir, void 0, verbose);
|
|
2946
|
-
if (validationResult !== 0) {
|
|
2947
|
-
console.error(chalk36.red(`Compile:Validation had ${validationResult} errors`));
|
|
2948
|
-
return validationResult;
|
|
2949
|
-
}
|
|
2950
|
-
const optionsParams = tsupOptions([{
|
|
2951
|
-
bundle: true,
|
|
2952
|
-
cjsInterop: true,
|
|
2953
|
-
clean: false,
|
|
2954
|
-
dts: false,
|
|
2955
|
-
format: ["esm"],
|
|
2956
|
-
outDir,
|
|
2957
|
-
silent: true,
|
|
2958
|
-
sourcemap: true,
|
|
2959
|
-
splitting: false,
|
|
2960
|
-
tsconfig: "tsconfig.json",
|
|
2961
|
-
...options,
|
|
2962
|
-
entry: entries.map((entry) => `${srcDir}/${entry}`)
|
|
2963
|
-
}]);
|
|
2964
|
-
const optionsResult = defineConfig(optionsParams);
|
|
2965
|
-
const optionsList = (await Promise.all(
|
|
2966
|
-
(Array.isArray(optionsResult) ? optionsResult : [optionsResult]).flatMap(async (options2) => {
|
|
2967
|
-
const result = typeof options2 === "function" ? await options2({}) : [options2];
|
|
2968
|
-
return Array.isArray(result) ? result : [result];
|
|
2969
|
-
})
|
|
2970
|
-
)).flat();
|
|
2971
|
-
if (verbose) {
|
|
2972
|
-
console.log(chalk36.cyan(`TSUP:build:start [${srcDir}]`));
|
|
2973
|
-
console.log(chalk36.gray(`TSUP:build:options [${JSON.stringify(optionsList, null, 2)}]`));
|
|
2974
|
-
}
|
|
2975
|
-
await Promise.all(optionsList.map((options2) => build2(options2)));
|
|
2976
|
-
if (verbose) {
|
|
2977
|
-
console.log(chalk36.cyan(`TSUP:build:stop [${srcDir}]`));
|
|
2978
|
-
}
|
|
2979
|
-
if (bundleTypes) {
|
|
2980
|
-
await packageCompileTscTypes(entries, outDir, options?.platform ?? "neutral", buildDir, verbose);
|
|
2981
|
-
}
|
|
2982
|
-
return 0;
|
|
2983
|
-
};
|
|
2984
|
-
var tsupOptions = (options = []) => {
|
|
2985
|
-
const standardLoaders = {
|
|
2986
|
-
".gif": "copy",
|
|
2987
|
-
".html": "copy",
|
|
2988
|
-
".jpg": "copy",
|
|
2989
|
-
".json": "json",
|
|
2990
|
-
".png": "copy",
|
|
2991
|
-
".svg": "text",
|
|
2992
|
-
".webp": "copy"
|
|
2993
|
-
};
|
|
2994
|
-
const standardOptions = {
|
|
2995
|
-
bundle: true,
|
|
2996
|
-
format: ["esm"],
|
|
2997
|
-
loader: standardLoaders,
|
|
2998
|
-
outExtension: ({ format }) => format === "esm" ? { js: ".mjs" } : { js: ".cjs" },
|
|
2999
|
-
skipNodeModulesBundle: true,
|
|
3000
|
-
sourcemap: true,
|
|
3001
|
-
target: "esnext"
|
|
3002
|
-
};
|
|
3003
|
-
return deepMergeObjects([standardOptions, ...options]);
|
|
3004
|
-
};
|
|
3005
|
-
var packageCompileTsup = async (config2) => {
|
|
3006
|
-
const compile2 = config2?.compile;
|
|
3007
|
-
const verbose = config2?.verbose ?? false;
|
|
3008
|
-
const outDirAsBuildDir = compile2?.outDirAsBuildDir ?? true;
|
|
3009
|
-
const bundleTypes = compile2?.bundleTypes ?? false;
|
|
3010
|
-
if (verbose) {
|
|
3011
|
-
console.log("Compiling with TSUP");
|
|
3012
|
-
}
|
|
3013
|
-
const compileForNode = compile2?.node ?? { src: {} };
|
|
3014
|
-
const compileForBrowser = compile2?.browser ?? { src: {} };
|
|
3015
|
-
const compileForNeutral = compile2?.neutral ?? { src: {} };
|
|
3016
|
-
return (await Promise.all(
|
|
3017
|
-
Object.entries(compileForNode).map(async ([srcDir, options]) => {
|
|
3018
|
-
const optionsObject = typeof options === "object" ? options : {};
|
|
3019
|
-
const inEsBuildOptions = typeof compile2?.node?.esbuildOptions === "object" ? compile2?.node?.esbuildOptions : {};
|
|
3020
|
-
const entry = buildEntries(srcDir, compile2?.entryMode, options, true, verbose);
|
|
3021
|
-
const platform = "node";
|
|
3022
|
-
const rootOutDir = optionsObject.outDir ?? "dist";
|
|
3023
|
-
const outDir = rootOutDir + "/" + platform;
|
|
3024
|
-
return typeof srcDir === "string" ? await compileFolder(
|
|
3025
|
-
srcDir,
|
|
3026
|
-
entry,
|
|
3027
|
-
outDirAsBuildDir ? rootOutDir : "build",
|
|
3028
|
-
tsupOptions([
|
|
3029
|
-
inEsBuildOptions,
|
|
3030
|
-
compile2?.tsup?.options ?? {},
|
|
3031
|
-
typeof options === "object" ? options : {},
|
|
3032
|
-
{ platform: "node", outDir }
|
|
3033
|
-
]),
|
|
3034
|
-
bundleTypes,
|
|
3035
|
-
verbose
|
|
3036
|
-
) : 0;
|
|
3037
|
-
})
|
|
3038
|
-
)).reduce((prev, value) => prev + value, 0) + (await Promise.all(
|
|
3039
|
-
Object.entries(compileForBrowser).map(async ([srcDir, options]) => {
|
|
3040
|
-
const optionsObject = typeof options === "object" ? options : {};
|
|
3041
|
-
const inEsBuildOptions = typeof compile2?.browser?.esbuildOptions === "object" ? compile2?.browser?.esbuildOptions : {};
|
|
3042
|
-
const entry = buildEntries(srcDir, compile2?.entryMode, options, true, verbose);
|
|
3043
|
-
const platform = "browser";
|
|
3044
|
-
const rootOutDir = optionsObject.outDir ?? "dist";
|
|
3045
|
-
const outDir = rootOutDir + "/" + platform;
|
|
3046
|
-
return typeof srcDir === "string" ? await compileFolder(
|
|
3047
|
-
srcDir,
|
|
3048
|
-
entry,
|
|
3049
|
-
outDirAsBuildDir ? rootOutDir : "build",
|
|
3050
|
-
tsupOptions([
|
|
3051
|
-
inEsBuildOptions,
|
|
3052
|
-
compile2?.tsup?.options ?? {},
|
|
3053
|
-
typeof options === "object" ? options : {},
|
|
3054
|
-
{ platform: "browser", outDir }
|
|
3055
|
-
]),
|
|
3056
|
-
bundleTypes,
|
|
3057
|
-
verbose
|
|
3058
|
-
) : 0;
|
|
3059
|
-
})
|
|
3060
|
-
)).reduce((prev, value) => prev + value, 0) + (await Promise.all(
|
|
3061
|
-
Object.entries(compileForNeutral).map(async ([srcDir, options]) => {
|
|
3062
|
-
const optionsObject = typeof options === "object" ? options : {};
|
|
3063
|
-
const inEsBuildOptions = typeof compile2?.neutral?.esbuildOptions === "object" ? compile2?.neutral?.esbuildOptions : {};
|
|
3064
|
-
const entry = buildEntries(srcDir, compile2?.entryMode, options, true, verbose);
|
|
3065
|
-
const platform = "neutral";
|
|
3066
|
-
const rootOutDir = optionsObject.outDir ?? "dist";
|
|
3067
|
-
const outDir = rootOutDir + "/" + platform;
|
|
3068
|
-
return typeof srcDir === "string" ? await compileFolder(
|
|
3069
|
-
srcDir,
|
|
3070
|
-
entry,
|
|
3071
|
-
outDirAsBuildDir ? rootOutDir : "build",
|
|
3072
|
-
tsupOptions([
|
|
3073
|
-
inEsBuildOptions,
|
|
3074
|
-
compile2?.tsup?.options ?? {},
|
|
3075
|
-
typeof options === "object" ? options : {},
|
|
3076
|
-
{ platform: "neutral", outDir }
|
|
3077
|
-
]),
|
|
3078
|
-
bundleTypes,
|
|
3079
|
-
verbose
|
|
3080
|
-
) : 0;
|
|
3081
|
-
})
|
|
3082
|
-
)).reduce((prev, value) => prev + value, 0) + 0;
|
|
3083
30
|
};
|
|
3084
31
|
|
|
3085
|
-
// src/actions/
|
|
3086
|
-
var
|
|
3087
|
-
const
|
|
3088
|
-
|
|
3089
|
-
|
|
3090
|
-
|
|
3091
|
-
|
|
3092
|
-
|
|
3093
|
-
|
|
3094
|
-
import path11 from "path/posix";
|
|
3095
|
-
import chalk38 from "chalk";
|
|
3096
|
-
import cpy2 from "cpy";
|
|
3097
|
-
var copyTargetAssets2 = async (target, name, location) => {
|
|
3098
|
-
try {
|
|
3099
|
-
const values = await cpy2(
|
|
3100
|
-
["**/*.jpg", "**/*.png", "**/*.gif", "**/*.svg", "**/*.webp", "**/*.sass", "**/*.scss", "**/*.gif", "**/*.css"],
|
|
3101
|
-
`../dist/${target}`,
|
|
3102
|
-
{
|
|
3103
|
-
cwd: path11.join(location, "src"),
|
|
3104
|
-
flat: false
|
|
3105
|
-
}
|
|
3106
|
-
);
|
|
3107
|
-
if (values.length > 0) {
|
|
3108
|
-
console.log(chalk38.green(`Copying Assets [${target.toUpperCase()}] - ${name} - ${location}`));
|
|
3109
|
-
}
|
|
3110
|
-
for (const value of values) {
|
|
3111
|
-
console.log(`${value.split("/").pop()} => ./dist/${target}`);
|
|
3112
|
-
}
|
|
3113
|
-
return 0;
|
|
3114
|
-
} catch (ex) {
|
|
3115
|
-
const error = ex;
|
|
3116
|
-
console.log(`Copy Assets Failed: ${name}: ${error.message}`);
|
|
3117
|
-
return 1;
|
|
3118
|
-
}
|
|
3119
|
-
};
|
|
3120
|
-
var packageCopyAssets = async ({ target }) => {
|
|
3121
|
-
const pkg = process.env.INIT_CWD ?? "./";
|
|
3122
|
-
const pkgName = process.env.npm_package_name ?? "Unknown";
|
|
3123
|
-
switch (target) {
|
|
3124
|
-
case "esm": {
|
|
3125
|
-
return await copyTargetAssets2("esm", pkgName, pkg);
|
|
3126
|
-
}
|
|
3127
|
-
case "cjs": {
|
|
3128
|
-
return await copyTargetAssets2("cjs", pkgName, pkg);
|
|
3129
|
-
}
|
|
3130
|
-
default: {
|
|
3131
|
-
return await copyTargetAssets2("esm", pkgName, pkg) || await copyTargetAssets2("cjs", pkgName, pkg);
|
|
3132
|
-
}
|
|
3133
|
-
}
|
|
3134
|
-
};
|
|
3135
|
-
|
|
3136
|
-
// src/actions/package/cycle.ts
|
|
3137
|
-
import { cruise as cruise2 } from "dependency-cruiser";
|
|
3138
|
-
var packageCycle = async () => {
|
|
3139
|
-
const pkg = process.env.INIT_CWD;
|
|
3140
|
-
const pkgName = process.env.npm_package_name;
|
|
3141
|
-
const cruiseOptions = {
|
|
3142
|
-
ruleSet: {
|
|
3143
|
-
forbidden: [
|
|
3144
|
-
{
|
|
3145
|
-
name: "no-circular",
|
|
3146
|
-
severity: "error",
|
|
3147
|
-
comment: "This dependency creates a circular reference",
|
|
3148
|
-
from: {},
|
|
3149
|
-
to: { circular: true }
|
|
3150
|
-
}
|
|
3151
|
-
]
|
|
3152
|
-
},
|
|
3153
|
-
exclude: "node_modules|packages/.*/packages",
|
|
3154
|
-
validate: true,
|
|
3155
|
-
doNotFollow: { path: "node_modules|packages/.*/packages" },
|
|
3156
|
-
tsPreCompilationDeps: false,
|
|
3157
|
-
combinedDependencies: true,
|
|
3158
|
-
outputType: "err"
|
|
3159
|
-
};
|
|
3160
|
-
const target = `${pkg}/src`;
|
|
3161
|
-
console.log(`Checking for circular dependencies in ${target}...`);
|
|
3162
|
-
const result = await cruise2([target], cruiseOptions);
|
|
3163
|
-
console.log(result.output);
|
|
3164
|
-
if (result.exitCode === 0) {
|
|
3165
|
-
console.log(`${pkgName} \u2705 No dependency violations`);
|
|
3166
|
-
} else {
|
|
3167
|
-
console.error(`${pkgName} \u274C Dependency violations found`);
|
|
3168
|
-
}
|
|
3169
|
-
return result.exitCode;
|
|
3170
|
-
};
|
|
3171
|
-
|
|
3172
|
-
// src/actions/package/gen-docs.ts
|
|
3173
|
-
import { existsSync as existsSync9 } from "fs";
|
|
3174
|
-
import path12 from "path";
|
|
3175
|
-
import chalk39 from "chalk";
|
|
3176
|
-
import {
|
|
3177
|
-
Application,
|
|
3178
|
-
ArgumentsReader,
|
|
3179
|
-
TSConfigReader,
|
|
3180
|
-
TypeDocReader
|
|
3181
|
-
} from "typedoc";
|
|
3182
|
-
var ExitCodes = {
|
|
3183
|
-
CompileError: 3,
|
|
3184
|
-
ExceptionThrown: 6,
|
|
3185
|
-
NoEntryPoints: 2,
|
|
3186
|
-
Ok: 0,
|
|
3187
|
-
OptionError: 1,
|
|
3188
|
-
OutputError: 5,
|
|
3189
|
-
ValidationError: 4
|
|
3190
|
-
};
|
|
3191
|
-
var packageGenDocs = async () => {
|
|
3192
|
-
const pkg = process.env.INIT_CWD;
|
|
3193
|
-
if (pkg !== void 0 && !existsSync9(path12.join(pkg, "typedoc.json"))) {
|
|
3194
|
-
return;
|
|
3195
|
-
}
|
|
3196
|
-
const app = await Application.bootstrap({
|
|
3197
|
-
entryPointStrategy: "merge",
|
|
3198
|
-
entryPoints: [`${pkg}/src/**/*.ts`, `${pkg}/packages/*/dist/docs.json`],
|
|
3199
|
-
excludeExternals: true,
|
|
3200
|
-
json: `${pkg}/dist/docs.json`,
|
|
3201
|
-
logLevel: "Error",
|
|
3202
|
-
tsconfig: `${pkg}/tsconfig.json`
|
|
3203
|
-
});
|
|
3204
|
-
app.options.addReader(new ArgumentsReader(0));
|
|
3205
|
-
app.options.addReader(new TypeDocReader());
|
|
3206
|
-
app.options.addReader(new TSConfigReader());
|
|
3207
|
-
app.options.addReader(new ArgumentsReader(300));
|
|
3208
|
-
return await runTypeDoc(app);
|
|
32
|
+
// src/actions/deploy.ts
|
|
33
|
+
var privatePackageExcludeList = () => {
|
|
34
|
+
const possibleDeployablePackages = yarnWorkspaces().map((workspace) => [
|
|
35
|
+
workspace,
|
|
36
|
+
JSON.parse(readFileSync(`${workspace.location}/package.json`, { encoding: "utf8" }))
|
|
37
|
+
]);
|
|
38
|
+
const privatePackages = possibleDeployablePackages.filter(([_, pkg]) => pkg.private).map(([workspace]) => workspace);
|
|
39
|
+
const excludeList = privatePackages.map((workspace) => `--exclude ${workspace.name}`);
|
|
40
|
+
return excludeList;
|
|
3209
41
|
};
|
|
3210
|
-
var
|
|
3211
|
-
const
|
|
3212
|
-
if (
|
|
3213
|
-
console.log(
|
|
3214
|
-
return ExitCodes.Ok;
|
|
3215
|
-
}
|
|
3216
|
-
if (app.options.getValue("showConfig")) {
|
|
3217
|
-
console.log(app.options.getRawValues());
|
|
3218
|
-
return ExitCodes.Ok;
|
|
3219
|
-
}
|
|
3220
|
-
if (app.logger.hasErrors()) {
|
|
3221
|
-
return ExitCodes.OptionError;
|
|
3222
|
-
}
|
|
3223
|
-
if (app.options.getValue("treatWarningsAsErrors") && app.logger.hasWarnings()) {
|
|
3224
|
-
return ExitCodes.OptionError;
|
|
3225
|
-
}
|
|
3226
|
-
if (app.options.getValue("entryPoints").length === 0) {
|
|
3227
|
-
app.logger.error("No entry points provided");
|
|
3228
|
-
return ExitCodes.NoEntryPoints;
|
|
3229
|
-
}
|
|
3230
|
-
if (app.options.getValue("watch")) {
|
|
3231
|
-
await app.convertAndWatch(async (project2) => {
|
|
3232
|
-
const out = app.options.getValue("out");
|
|
3233
|
-
if (out) {
|
|
3234
|
-
await app.generateDocs(project2, out);
|
|
3235
|
-
}
|
|
3236
|
-
const json = app.options.getValue("json");
|
|
3237
|
-
if (json) {
|
|
3238
|
-
await app.generateJson(project2, json);
|
|
3239
|
-
}
|
|
3240
|
-
if (!out && !json) {
|
|
3241
|
-
await app.generateDocs(project2, "./docs");
|
|
3242
|
-
}
|
|
3243
|
-
});
|
|
3244
|
-
return ExitCodes.Ok;
|
|
3245
|
-
}
|
|
3246
|
-
const project = await app.convert();
|
|
3247
|
-
if (!project) {
|
|
3248
|
-
return ExitCodes.CompileError;
|
|
3249
|
-
}
|
|
3250
|
-
if (app.options.getValue("treatWarningsAsErrors") && app.logger.hasWarnings()) {
|
|
3251
|
-
return ExitCodes.CompileError;
|
|
3252
|
-
}
|
|
3253
|
-
app.validate(project);
|
|
3254
|
-
if (app.logger.hasErrors()) {
|
|
3255
|
-
return ExitCodes.ValidationError;
|
|
3256
|
-
}
|
|
3257
|
-
if (app.options.getValue("treatWarningsAsErrors") && app.logger.hasWarnings()) {
|
|
3258
|
-
return ExitCodes.ValidationError;
|
|
3259
|
-
}
|
|
3260
|
-
if (app.options.getValue("emit") !== "none") {
|
|
3261
|
-
const out = app.options.getValue("out");
|
|
3262
|
-
if (out) {
|
|
3263
|
-
await app.generateDocs(project, out);
|
|
3264
|
-
}
|
|
3265
|
-
const json = app.options.getValue("json");
|
|
3266
|
-
if (json) {
|
|
3267
|
-
await app.generateJson(project, json);
|
|
3268
|
-
}
|
|
3269
|
-
if (!out && !json) {
|
|
3270
|
-
await app.generateDocs(project, "./docs");
|
|
3271
|
-
}
|
|
3272
|
-
if (app.logger.hasErrors()) {
|
|
3273
|
-
return ExitCodes.OutputError;
|
|
3274
|
-
}
|
|
3275
|
-
if (app.options.getValue("treatWarningsAsErrors") && app.logger.hasWarnings()) {
|
|
3276
|
-
return ExitCodes.OutputError;
|
|
3277
|
-
}
|
|
42
|
+
var deploy = () => {
|
|
43
|
+
const excludeList = privatePackageExcludeList();
|
|
44
|
+
if (excludeList.length > 0) {
|
|
45
|
+
console.log("Excluding private packages from deployment:", excludeList);
|
|
3278
46
|
}
|
|
3279
|
-
|
|
3280
|
-
|
|
47
|
+
return runSteps("Deploy [Patch]", [
|
|
48
|
+
["yarn", "workspaces foreach --all version patch --deferred"],
|
|
49
|
+
["yarn", "xy clean"],
|
|
50
|
+
["yarn", "xy build"],
|
|
51
|
+
["yarn", "version apply --all"]
|
|
52
|
+
]);
|
|
3281
53
|
};
|
|
3282
54
|
|
|
3283
|
-
// src/actions/
|
|
3284
|
-
import {
|
|
3285
|
-
import
|
|
3286
|
-
|
|
3287
|
-
|
|
3288
|
-
|
|
3289
|
-
|
|
3290
|
-
|
|
3291
|
-
|
|
3292
|
-
|
|
3293
|
-
|
|
3294
|
-
const severity = ["none", "warning", "error"];
|
|
3295
|
-
for (const lintResult of lintResults) {
|
|
3296
|
-
if (lintResult.messages.length > 0) {
|
|
3297
|
-
console.log(chalk40.gray(`
|
|
3298
|
-
${lintResult.filePath}`));
|
|
3299
|
-
for (const message of lintResult.messages) {
|
|
3300
|
-
console.log(
|
|
3301
|
-
chalk40.gray(` ${message.line}:${message.column}`),
|
|
3302
|
-
chalk40[colors[message.severity]](` ${severity[message.severity]}`),
|
|
3303
|
-
chalk40.white(` ${message.message}`),
|
|
3304
|
-
chalk40.gray(` ${message.ruleId}`)
|
|
3305
|
-
);
|
|
3306
|
-
}
|
|
3307
|
-
}
|
|
3308
|
-
}
|
|
55
|
+
// src/actions/deploy-major.ts
|
|
56
|
+
import { readFileSync as readFileSync2 } from "fs";
|
|
57
|
+
import { runSteps as runSteps2 } from "@xylabs/ts-scripts-common";
|
|
58
|
+
var privatePackageExcludeList2 = () => {
|
|
59
|
+
const possibleDeployablePackages = yarnWorkspaces().map((workspace) => [
|
|
60
|
+
workspace,
|
|
61
|
+
JSON.parse(readFileSync2(`${workspace.location}/package.json`, { encoding: "utf8" }))
|
|
62
|
+
]);
|
|
63
|
+
const privatePackages = possibleDeployablePackages.filter(([_, pkg]) => pkg.private).map(([workspace]) => workspace);
|
|
64
|
+
const excludeList = privatePackages.map((workspace) => `--exclude ${workspace.name}`);
|
|
65
|
+
return excludeList;
|
|
3309
66
|
};
|
|
3310
|
-
|
|
3311
|
-
const
|
|
3312
|
-
if (
|
|
3313
|
-
|
|
3314
|
-
}
|
|
3315
|
-
return pathToFileURL(configPath);
|
|
3316
|
-
}
|
|
3317
|
-
function getFiles(dir, ignoreFolders) {
|
|
3318
|
-
const currentDirectory = cwd4();
|
|
3319
|
-
const subDirectory = dir.split(currentDirectory)[1]?.split("/")[1];
|
|
3320
|
-
if (ignoreFolders.includes(subDirectory)) return [];
|
|
3321
|
-
return readdirSync6(dir, { withFileTypes: true }).flatMap((dirent) => {
|
|
3322
|
-
const res = path13.resolve(dir, dirent.name);
|
|
3323
|
-
const relativePath = subDirectory === void 0 ? dirent.name : `${subDirectory}/${dirent.name}`;
|
|
3324
|
-
const ignoreMatchers = ignoreFolders.map((pattern) => picomatch(pattern));
|
|
3325
|
-
if (ignoreMatchers.some((isMatch) => isMatch(relativePath))) return [];
|
|
3326
|
-
return dirent.isDirectory() ? getFiles(res, ignoreFolders) : [res];
|
|
3327
|
-
});
|
|
3328
|
-
}
|
|
3329
|
-
var packageLint = async (fix2 = false, verbose = false, cache = true) => {
|
|
3330
|
-
const pkg = process.env.INIT_CWD;
|
|
3331
|
-
const configPath = await getRootESLintConfig();
|
|
3332
|
-
const { default: eslintConfig } = await import(configPath.href);
|
|
3333
|
-
const start = Date.now();
|
|
3334
|
-
const ignoreFolders = ["node_modules", "dist", "packages", ".git", "build", ".yarn", ".vscode", ".github"];
|
|
3335
|
-
const engine = new ESLint({
|
|
3336
|
-
baseConfig: [...eslintConfig],
|
|
3337
|
-
fix: fix2,
|
|
3338
|
-
warnIgnored: false,
|
|
3339
|
-
cache
|
|
3340
|
-
});
|
|
3341
|
-
const files = getFiles(cwd4(), ignoreFolders);
|
|
3342
|
-
console.log(chalk40.green(`Linting ${pkg} [files = ${files.length}]`));
|
|
3343
|
-
if (verbose) {
|
|
3344
|
-
for (const file of files) {
|
|
3345
|
-
console.log(chalk40.gray(` ${file}`));
|
|
3346
|
-
}
|
|
3347
|
-
}
|
|
3348
|
-
const lintResults = await engine.lintFiles(files);
|
|
3349
|
-
dumpMessages(lintResults);
|
|
3350
|
-
if (fix2) {
|
|
3351
|
-
await ESLint.outputFixes(lintResults);
|
|
67
|
+
var deployMajor = () => {
|
|
68
|
+
const excludeList = privatePackageExcludeList2();
|
|
69
|
+
if (excludeList.length > 0) {
|
|
70
|
+
console.log("Excluding private packages from deployment:", excludeList);
|
|
3352
71
|
}
|
|
3353
|
-
|
|
3354
|
-
|
|
3355
|
-
|
|
3356
|
-
|
|
3357
|
-
|
|
72
|
+
return runSteps2("Deploy [Major]", [
|
|
73
|
+
["yarn", "workspaces foreach --all version major --deferred"],
|
|
74
|
+
["yarn", "xy clean"],
|
|
75
|
+
["yarn", "xy build"],
|
|
76
|
+
["yarn", "version apply --all"]
|
|
77
|
+
]);
|
|
3358
78
|
};
|
|
3359
79
|
|
|
3360
|
-
// src/actions/
|
|
3361
|
-
import {
|
|
3362
|
-
import
|
|
3363
|
-
|
|
3364
|
-
|
|
3365
|
-
|
|
3366
|
-
|
|
3367
|
-
|
|
3368
|
-
|
|
3369
|
-
|
|
3370
|
-
|
|
3371
|
-
if (pkg.main !== void 0) {
|
|
3372
|
-
console.warn(chalk41.yellow('Publint [custom]: "main" field is deprecated, use "exports" instead'));
|
|
3373
|
-
warningCount++;
|
|
3374
|
-
}
|
|
3375
|
-
if (pkg.sideEffects !== false) {
|
|
3376
|
-
console.warn(chalk41.yellow('Publint [custom]: "sideEffects" field should be set to false'));
|
|
3377
|
-
warningCount++;
|
|
3378
|
-
}
|
|
3379
|
-
if (pkg.resolutions !== void 0) {
|
|
3380
|
-
console.warn(chalk41.yellow('Publint [custom]: "resolutions" in use'));
|
|
3381
|
-
console.warn(chalk41.gray(JSON.stringify(pkg.resolutions, null, 2)));
|
|
3382
|
-
warningCount++;
|
|
3383
|
-
}
|
|
3384
|
-
return [errorCount, warningCount];
|
|
80
|
+
// src/actions/deploy-minor.ts
|
|
81
|
+
import { readFileSync as readFileSync3 } from "fs";
|
|
82
|
+
import { runSteps as runSteps3 } from "@xylabs/ts-scripts-common";
|
|
83
|
+
var privatePackageExcludeList3 = () => {
|
|
84
|
+
const possibleDeployablePackages = yarnWorkspaces().map((workspace) => [
|
|
85
|
+
workspace,
|
|
86
|
+
JSON.parse(readFileSync3(`${workspace.location}/package.json`, { encoding: "utf8" }))
|
|
87
|
+
]);
|
|
88
|
+
const privatePackages = possibleDeployablePackages.filter(([_, pkg]) => pkg.private).map(([workspace]) => workspace);
|
|
89
|
+
const excludeList = privatePackages.map((workspace) => `--exclude ${workspace.name}`);
|
|
90
|
+
return excludeList;
|
|
3385
91
|
};
|
|
3386
|
-
var
|
|
3387
|
-
const
|
|
3388
|
-
|
|
3389
|
-
|
|
3390
|
-
const pkg = JSON.parse(await fs10.readFile(`${pkgDir}/package.json`, "utf8"));
|
|
3391
|
-
console.log(chalk41.green(`Publint: ${pkg.name}`));
|
|
3392
|
-
console.log(chalk41.gray(pkgDir));
|
|
3393
|
-
const { publint: publint2 } = await import("publint");
|
|
3394
|
-
const { messages } = await publint2({
|
|
3395
|
-
level: "suggestion",
|
|
3396
|
-
pkgDir,
|
|
3397
|
-
strict
|
|
3398
|
-
});
|
|
3399
|
-
const { formatMessage } = await import("publint/utils");
|
|
3400
|
-
for (const message of messages) {
|
|
3401
|
-
switch (message.type) {
|
|
3402
|
-
case "error": {
|
|
3403
|
-
console.error(chalk41.red(`[${message.code}] ${formatMessage(message, pkg)}`));
|
|
3404
|
-
break;
|
|
3405
|
-
}
|
|
3406
|
-
case "warning": {
|
|
3407
|
-
console.warn(chalk41.yellow(`[${message.code}] ${formatMessage(message, pkg)}`));
|
|
3408
|
-
break;
|
|
3409
|
-
}
|
|
3410
|
-
default: {
|
|
3411
|
-
console.log(chalk41.white(`[${message.code}] ${formatMessage(message, pkg)}`));
|
|
3412
|
-
break;
|
|
3413
|
-
}
|
|
3414
|
-
}
|
|
3415
|
-
}
|
|
3416
|
-
const [errorCount, warningCount] = customPubLint(pkg);
|
|
3417
|
-
if (verbose) {
|
|
3418
|
-
console.log(chalk41.gray(`Publint [Finish]: ${pkgDir} [${messages.length + errorCount + warningCount} messages]`));
|
|
92
|
+
var deployMinor = () => {
|
|
93
|
+
const excludeList = privatePackageExcludeList3();
|
|
94
|
+
if (excludeList.length > 0) {
|
|
95
|
+
console.log("Excluding private packages from deployment:", excludeList);
|
|
3419
96
|
}
|
|
3420
|
-
return
|
|
97
|
+
return runSteps3("Deploy [Minor]", [
|
|
98
|
+
["yarn", "workspaces foreach --all version minor --deferred"],
|
|
99
|
+
["yarn", "xy clean"],
|
|
100
|
+
["yarn", "xy build"],
|
|
101
|
+
["yarn", "version apply --all"]
|
|
102
|
+
]);
|
|
3421
103
|
};
|
|
3422
104
|
|
|
3423
|
-
// src/actions/
|
|
3424
|
-
|
|
3425
|
-
|
|
105
|
+
// src/actions/deploy-next.ts
|
|
106
|
+
import { readFileSync as readFileSync4 } from "fs";
|
|
107
|
+
import { runSteps as runSteps4 } from "@xylabs/ts-scripts-common";
|
|
108
|
+
var privatePackageExcludeList4 = () => {
|
|
109
|
+
const possibleDeployablePackages = yarnWorkspaces().map((workspace) => [
|
|
110
|
+
workspace,
|
|
111
|
+
JSON.parse(readFileSync4(`${workspace.location}/package.json`, { encoding: "utf8" }))
|
|
112
|
+
]);
|
|
113
|
+
const privatePackages = possibleDeployablePackages.filter(([_, pkg]) => pkg.private).map(([workspace]) => workspace);
|
|
114
|
+
const excludeList = privatePackages.map((workspace) => `--exclude ${workspace.name}`);
|
|
115
|
+
return excludeList;
|
|
3426
116
|
};
|
|
3427
|
-
|
|
3428
|
-
|
|
3429
|
-
|
|
3430
|
-
|
|
3431
|
-
import chalk42 from "chalk";
|
|
3432
|
-
import picomatch2 from "picomatch";
|
|
3433
|
-
function emptyResult() {
|
|
3434
|
-
return {
|
|
3435
|
-
errors: [],
|
|
3436
|
-
fixable: [],
|
|
3437
|
-
warnings: []
|
|
3438
|
-
};
|
|
3439
|
-
}
|
|
3440
|
-
function readRootPackageJson(cwd5) {
|
|
3441
|
-
const raw = readFileSync14(PATH10.resolve(cwd5, "package.json"), "utf8");
|
|
3442
|
-
return JSON.parse(raw);
|
|
3443
|
-
}
|
|
3444
|
-
function writeRootPackageJson(cwd5, pkg) {
|
|
3445
|
-
const path14 = PATH10.resolve(cwd5, "package.json");
|
|
3446
|
-
writeFileSync7(path14, `${JSON.stringify(pkg, null, 2)}
|
|
3447
|
-
`, "utf8");
|
|
3448
|
-
}
|
|
3449
|
-
function isMonorepo(pkg) {
|
|
3450
|
-
const workspaces = pkg.workspaces;
|
|
3451
|
-
return Array.isArray(workspaces) && workspaces.length > 0;
|
|
3452
|
-
}
|
|
3453
|
-
function checkPackagesFolder(workspaces) {
|
|
3454
|
-
const result = emptyResult();
|
|
3455
|
-
for (const { location, name } of workspaces) {
|
|
3456
|
-
if (location === ".") continue;
|
|
3457
|
-
if (!location.startsWith("packages/") && !location.startsWith("packages\\")) {
|
|
3458
|
-
result.errors.push(`${name} (${location}) is not inside a packages/ folder`);
|
|
3459
|
-
}
|
|
3460
|
-
}
|
|
3461
|
-
return result;
|
|
3462
|
-
}
|
|
3463
|
-
function checkRootPrivate(pkg) {
|
|
3464
|
-
const result = emptyResult();
|
|
3465
|
-
if (!pkg.private) {
|
|
3466
|
-
result.fixable.push("Root package.json must be private to prevent accidental publishing");
|
|
3467
|
-
}
|
|
3468
|
-
return result;
|
|
3469
|
-
}
|
|
3470
|
-
function fixRootPrivate(cwd5, pkg) {
|
|
3471
|
-
pkg.private = true;
|
|
3472
|
-
writeRootPackageJson(cwd5, pkg);
|
|
3473
|
-
console.log(chalk42.green(' \u2714 Fixed: set "private": true in root package.json'));
|
|
3474
|
-
}
|
|
3475
|
-
function checkNoPublishConfigOnPrivate(pkg) {
|
|
3476
|
-
const result = emptyResult();
|
|
3477
|
-
if (pkg.private && pkg.publishConfig) {
|
|
3478
|
-
result.fixable.push("Root package.json has publishConfig but is private \u2014 publishConfig is unnecessary");
|
|
3479
|
-
}
|
|
3480
|
-
return result;
|
|
3481
|
-
}
|
|
3482
|
-
function fixNoPublishConfigOnPrivate(cwd5, pkg) {
|
|
3483
|
-
delete pkg.publishConfig;
|
|
3484
|
-
writeRootPackageJson(cwd5, pkg);
|
|
3485
|
-
console.log(chalk42.green(" \u2714 Fixed: removed publishConfig from private root package.json"));
|
|
3486
|
-
}
|
|
3487
|
-
function checkDiscoverable(pkg, workspaces) {
|
|
3488
|
-
const result = emptyResult();
|
|
3489
|
-
const globs = pkg.workspaces;
|
|
3490
|
-
const matchers = globs.map((glob3) => picomatch2(glob3));
|
|
3491
|
-
const isMatch = (location) => matchers.some((m) => m(location));
|
|
3492
|
-
for (const { location, name } of workspaces) {
|
|
3493
|
-
if (location === ".") continue;
|
|
3494
|
-
if (!isMatch(location)) {
|
|
3495
|
-
result.errors.push(`${name} (${location}) is not matched by any workspace glob in package.json`);
|
|
3496
|
-
}
|
|
3497
|
-
}
|
|
3498
|
-
return result;
|
|
3499
|
-
}
|
|
3500
|
-
function logResults(label, result, fix2) {
|
|
3501
|
-
let errors = 0;
|
|
3502
|
-
let fixed = 0;
|
|
3503
|
-
for (const error of result.errors) {
|
|
3504
|
-
console.log(chalk42.red(` \u2717 ${error}`));
|
|
3505
|
-
errors++;
|
|
3506
|
-
}
|
|
3507
|
-
for (const fixable of result.fixable) {
|
|
3508
|
-
if (fix2) {
|
|
3509
|
-
fixed++;
|
|
3510
|
-
} else {
|
|
3511
|
-
console.log(chalk42.red(` \u2717 ${fixable} (fixable)`));
|
|
3512
|
-
errors++;
|
|
3513
|
-
}
|
|
3514
|
-
}
|
|
3515
|
-
for (const warning of result.warnings) {
|
|
3516
|
-
console.log(chalk42.yellow(` \u26A0 ${warning}`));
|
|
3517
|
-
}
|
|
3518
|
-
if (errors === 0 && fixed === 0 && result.warnings.length === 0) {
|
|
3519
|
-
console.log(chalk42.green(` \u2713 ${label}`));
|
|
3520
|
-
}
|
|
3521
|
-
return { errors, fixed };
|
|
3522
|
-
}
|
|
3523
|
-
function runChecks(entries, cwd5, pkg, fix2) {
|
|
3524
|
-
let totalErrors = 0;
|
|
3525
|
-
let totalFixed = 0;
|
|
3526
|
-
for (const entry of entries) {
|
|
3527
|
-
const result = entry.check();
|
|
3528
|
-
const log = logResults(entry.label, result, fix2);
|
|
3529
|
-
if (fix2 && entry.fix && result.fixable.length > 0) {
|
|
3530
|
-
entry.fix(cwd5, pkg);
|
|
3531
|
-
}
|
|
3532
|
-
totalErrors += log.errors;
|
|
3533
|
-
totalFixed += log.fixed;
|
|
3534
|
-
}
|
|
3535
|
-
return { errors: totalErrors, fixed: totalFixed };
|
|
3536
|
-
}
|
|
3537
|
-
function logSummary(errors, fixed) {
|
|
3538
|
-
if (fixed > 0) {
|
|
3539
|
-
console.log(chalk42.green(`
|
|
3540
|
-
Fixed ${fixed} issue(s)`));
|
|
3541
|
-
}
|
|
3542
|
-
if (errors > 0) {
|
|
3543
|
-
console.log(chalk42.red(`
|
|
3544
|
-
${errors} error(s) found`));
|
|
3545
|
-
} else if (fixed === 0) {
|
|
3546
|
-
console.log(chalk42.green("\n All checks passed"));
|
|
3547
|
-
}
|
|
3548
|
-
}
|
|
3549
|
-
function packageLintMonorepo(fix2 = false) {
|
|
3550
|
-
const cwd5 = INIT_CWD() ?? process.cwd();
|
|
3551
|
-
let pkg;
|
|
3552
|
-
try {
|
|
3553
|
-
pkg = readRootPackageJson(cwd5);
|
|
3554
|
-
} catch {
|
|
3555
|
-
console.error(chalk42.red("Could not read package.json"));
|
|
3556
|
-
return 1;
|
|
3557
|
-
}
|
|
3558
|
-
if (!isMonorepo(pkg)) {
|
|
3559
|
-
console.log(chalk42.gray("Not a monorepo \u2014 skipping package-lint checks"));
|
|
3560
|
-
return 0;
|
|
117
|
+
var deployNext = () => {
|
|
118
|
+
const excludeList = privatePackageExcludeList4();
|
|
119
|
+
if (excludeList.length > 0) {
|
|
120
|
+
console.log("Excluding private packages from deployment:", excludeList);
|
|
3561
121
|
}
|
|
3562
|
-
|
|
3563
|
-
|
|
3564
|
-
const checks = [
|
|
3565
|
-
{
|
|
3566
|
-
check: () => checkRootPrivate(pkg),
|
|
3567
|
-
fix: fixRootPrivate,
|
|
3568
|
-
label: "Root package is private"
|
|
3569
|
-
},
|
|
3570
|
-
{
|
|
3571
|
-
check: () => checkNoPublishConfigOnPrivate(pkg),
|
|
3572
|
-
fix: fixNoPublishConfigOnPrivate,
|
|
3573
|
-
label: "No publishConfig on private root"
|
|
3574
|
-
},
|
|
3575
|
-
{ check: () => checkPackagesFolder(workspaces), label: "All packages are in packages/ folder" },
|
|
3576
|
-
{ check: () => checkDiscoverable(pkg, workspaces), label: "All packages are discoverable from workspace globs" }
|
|
3577
|
-
];
|
|
3578
|
-
const { errors, fixed } = runChecks(checks, cwd5, pkg, fix2);
|
|
3579
|
-
logSummary(errors, fixed);
|
|
3580
|
-
return errors > 0 ? 1 : 0;
|
|
3581
|
-
}
|
|
3582
|
-
|
|
3583
|
-
// src/actions/publint.ts
|
|
3584
|
-
var publint = async ({ verbose, pkg }) => {
|
|
3585
|
-
return pkg === void 0 ? publintAll({ verbose }) : await publintPackage({ pkg, verbose });
|
|
3586
|
-
};
|
|
3587
|
-
var publintPackage = ({ pkg }) => {
|
|
3588
|
-
return runStepsAsync(`Publint [${pkg}]`, [["yarn", ["workspace", pkg, "run", "package-publint"]]]);
|
|
3589
|
-
};
|
|
3590
|
-
var publintAll = ({ verbose }) => {
|
|
3591
|
-
const verboseOptions = verbose ? ["--verbose"] : ["--no-verbose"];
|
|
3592
|
-
return runSteps("Publint", [["yarn", ["workspaces", "foreach", "-pA", ...verboseOptions, "run", "package-publint"]]]);
|
|
3593
|
-
};
|
|
3594
|
-
|
|
3595
|
-
// src/actions/publish.ts
|
|
3596
|
-
var publish = () => {
|
|
3597
|
-
return runSteps("Publish", [["npm", ["publish", "--workspaces"]]]);
|
|
3598
|
-
};
|
|
3599
|
-
|
|
3600
|
-
// src/actions/readme-gen.ts
|
|
3601
|
-
async function readmeGen({
|
|
3602
|
-
pkg,
|
|
3603
|
-
templatePath,
|
|
3604
|
-
typedoc,
|
|
3605
|
-
verbose
|
|
3606
|
-
}) {
|
|
3607
|
-
const config2 = await loadConfig();
|
|
3608
|
-
return await generateReadmeFiles({
|
|
3609
|
-
logoLinkUrl: config2.readme?.logoLinkUrl,
|
|
3610
|
-
logoUrl: config2.readme?.logoUrl,
|
|
3611
|
-
pkg,
|
|
3612
|
-
templatePath,
|
|
3613
|
-
typedoc,
|
|
3614
|
-
verbose
|
|
3615
|
-
});
|
|
3616
|
-
}
|
|
3617
|
-
|
|
3618
|
-
// src/actions/readme-init.ts
|
|
3619
|
-
async function readmeInit({ templatePath }) {
|
|
3620
|
-
const config2 = await loadConfig();
|
|
3621
|
-
const template = applyLogoConfig(DEFAULT_README_TEMPLATE, config2.readme?.logoUrl, config2.readme?.logoLinkUrl);
|
|
3622
|
-
const resolvedTemplatePath = resolveTemplatePath(templatePath);
|
|
3623
|
-
await scaffoldTemplate(resolvedTemplatePath, template);
|
|
3624
|
-
return 0;
|
|
3625
|
-
}
|
|
3626
|
-
|
|
3627
|
-
// src/actions/rebuild.ts
|
|
3628
|
-
var rebuild = ({ target }) => {
|
|
3629
|
-
return runSteps("Rebuild", [
|
|
122
|
+
return runSteps4("Deploy [Next]", [
|
|
123
|
+
["yarn", "workspaces foreach --all version minor --deferred"],
|
|
3630
124
|
["yarn", "xy clean"],
|
|
3631
|
-
["yarn",
|
|
125
|
+
["yarn", "xy build"],
|
|
126
|
+
["yarn", "version apply --all --prerelease"]
|
|
3632
127
|
]);
|
|
3633
128
|
};
|
|
3634
129
|
|
|
3635
|
-
// src/actions/
|
|
3636
|
-
import
|
|
3637
|
-
var
|
|
3638
|
-
|
|
3639
|
-
target,
|
|
3640
|
-
pkg,
|
|
3641
|
-
incremental
|
|
3642
|
-
}) => {
|
|
3643
|
-
return pkg ? await recompilePackage({
|
|
3644
|
-
pkg,
|
|
3645
|
-
target,
|
|
3646
|
-
verbose
|
|
3647
|
-
}) : await recompileAll({
|
|
3648
|
-
incremental,
|
|
3649
|
-
target,
|
|
3650
|
-
verbose
|
|
3651
|
-
});
|
|
3652
|
-
};
|
|
3653
|
-
var recompilePackage = ({ target, pkg }) => {
|
|
3654
|
-
const targetOptions = target ? ["-t", target] : [];
|
|
3655
|
-
return runStepsAsync(
|
|
3656
|
-
`Recompile [${pkg}]`,
|
|
3657
|
-
[["yarn", ["workspace", pkg, "run", "package-recompile", ...targetOptions]]]
|
|
3658
|
-
);
|
|
3659
|
-
};
|
|
3660
|
-
var recompileAll = async ({
|
|
3661
|
-
jobs,
|
|
3662
|
-
verbose,
|
|
3663
|
-
target,
|
|
3664
|
-
incremental
|
|
3665
|
-
}) => {
|
|
3666
|
-
const start = Date.now();
|
|
3667
|
-
const verboseOptions = verbose ? ["--verbose"] : ["--no-verbose"];
|
|
3668
|
-
const targetOptions = target ? ["-t", target] : [];
|
|
3669
|
-
const incrementalOptions = incremental ? ["--since", "-Apt", "--topological-dev"] : ["--parallel", "-Apt", "--topological-dev"];
|
|
3670
|
-
const jobsOptions = jobs ? ["-j", `${jobs}`] : [];
|
|
3671
|
-
if (jobs) {
|
|
3672
|
-
console.log(chalk43.blue(`Jobs set to [${jobs}]`));
|
|
3673
|
-
}
|
|
3674
|
-
const result = await runStepsAsync(`Recompile${incremental ? "-Incremental" : ""} [All]`, [
|
|
3675
|
-
[
|
|
3676
|
-
"yarn",
|
|
3677
|
-
[
|
|
3678
|
-
"workspaces",
|
|
3679
|
-
"foreach",
|
|
3680
|
-
...incrementalOptions,
|
|
3681
|
-
...jobsOptions,
|
|
3682
|
-
...verboseOptions,
|
|
3683
|
-
"run",
|
|
3684
|
-
"package-clean",
|
|
3685
|
-
...targetOptions
|
|
3686
|
-
]
|
|
3687
|
-
],
|
|
3688
|
-
[
|
|
3689
|
-
"yarn",
|
|
3690
|
-
[
|
|
3691
|
-
"workspaces",
|
|
3692
|
-
"foreach",
|
|
3693
|
-
...incrementalOptions,
|
|
3694
|
-
...jobsOptions,
|
|
3695
|
-
...verboseOptions,
|
|
3696
|
-
"run",
|
|
3697
|
-
"package-compile",
|
|
3698
|
-
...targetOptions
|
|
3699
|
-
]
|
|
3700
|
-
]
|
|
3701
|
-
]);
|
|
3702
|
-
console.log(
|
|
3703
|
-
`${chalk43.gray("Recompiled in")} [${chalk43.magenta(((Date.now() - start) / 1e3).toFixed(2))}] ${chalk43.gray("seconds")}`
|
|
3704
|
-
);
|
|
3705
|
-
return result;
|
|
130
|
+
// src/actions/publish.ts
|
|
131
|
+
import { runSteps as runSteps5 } from "@xylabs/ts-scripts-common";
|
|
132
|
+
var publish = () => {
|
|
133
|
+
return runSteps5("Publish", [["npm", ["publish", "--workspaces"]]]);
|
|
3706
134
|
};
|
|
3707
135
|
|
|
3708
136
|
// src/actions/reinstall.ts
|
|
3709
137
|
import {
|
|
3710
138
|
closeSync,
|
|
3711
139
|
openSync,
|
|
3712
|
-
rmSync
|
|
140
|
+
rmSync
|
|
3713
141
|
} from "fs";
|
|
142
|
+
import { runSteps as runSteps6 } from "@xylabs/ts-scripts-common";
|
|
3714
143
|
var reinstall = () => {
|
|
3715
144
|
console.log("Reinstall [Clear Lock File]");
|
|
3716
145
|
closeSync(openSync("./yarn.lock", "w"));
|
|
@@ -3719,7 +148,7 @@ var reinstall = () => {
|
|
|
3719
148
|
const result = workspaces.map(({ location, name }) => {
|
|
3720
149
|
const dist = `${location}/node_modules`;
|
|
3721
150
|
try {
|
|
3722
|
-
|
|
151
|
+
rmSync(dist, { force: true, recursive: true });
|
|
3723
152
|
return 0;
|
|
3724
153
|
} catch (ex) {
|
|
3725
154
|
const error = ex;
|
|
@@ -3727,108 +156,19 @@ var reinstall = () => {
|
|
|
3727
156
|
return 1;
|
|
3728
157
|
}
|
|
3729
158
|
}).reduce((prev, result2) => prev || result2, 0);
|
|
3730
|
-
return result ||
|
|
3731
|
-
};
|
|
3732
|
-
|
|
3733
|
-
// src/actions/relint.ts
|
|
3734
|
-
import chalk44 from "chalk";
|
|
3735
|
-
var relintPackage = ({
|
|
3736
|
-
pkg,
|
|
3737
|
-
fix: fix2,
|
|
3738
|
-
verbose
|
|
3739
|
-
}) => {
|
|
3740
|
-
console.log(chalk44.gray(`${fix2 ? "Fix" : "Lint"} [${pkg}]`));
|
|
3741
|
-
const start = Date.now();
|
|
3742
|
-
const result = runSteps(`${fix2 ? "Fix" : "Lint"} [${pkg}]`, [
|
|
3743
|
-
["yarn", [
|
|
3744
|
-
"workspace",
|
|
3745
|
-
pkg,
|
|
3746
|
-
"run",
|
|
3747
|
-
fix2 ? "package-fix" : verbose ? "package-lint-verbose" : "package-lint"
|
|
3748
|
-
]]
|
|
3749
|
-
]);
|
|
3750
|
-
console.log(chalk44.gray(`${fix2 ? "Fixed in" : "Linted in"} [${chalk44.magenta(((Date.now() - start) / 1e3).toFixed(2))}] ${chalk44.gray("seconds")}`));
|
|
3751
|
-
return result;
|
|
3752
|
-
};
|
|
3753
|
-
var relint = ({
|
|
3754
|
-
pkg,
|
|
3755
|
-
verbose,
|
|
3756
|
-
incremental,
|
|
3757
|
-
fix: fix2
|
|
3758
|
-
} = {}) => {
|
|
3759
|
-
return pkg === void 0 ? relintAllPackages({
|
|
3760
|
-
verbose,
|
|
3761
|
-
incremental,
|
|
3762
|
-
fix: fix2
|
|
3763
|
-
}) : relintPackage({
|
|
3764
|
-
pkg,
|
|
3765
|
-
fix: fix2,
|
|
3766
|
-
verbose
|
|
3767
|
-
});
|
|
3768
|
-
};
|
|
3769
|
-
var relintAllPackages = ({ fix: fix2 = false } = {}) => {
|
|
3770
|
-
console.log(chalk44.gray(`${fix2 ? "Fix" : "Lint"} [All-Packages]`));
|
|
3771
|
-
const start = Date.now();
|
|
3772
|
-
const fixOptions = fix2 ? ["--fix"] : [];
|
|
3773
|
-
const result = runSteps(`${fix2 ? "Fix" : "Lint"} [All-Packages]`, [
|
|
3774
|
-
["yarn", ["eslint", ...fixOptions]]
|
|
3775
|
-
]);
|
|
3776
|
-
console.log(chalk44.gray(`${fix2 ? "Fixed in" : "Linted in"} [${chalk44.magenta(((Date.now() - start) / 1e3).toFixed(2))}] ${chalk44.gray("seconds")}`));
|
|
3777
|
-
return result;
|
|
3778
|
-
};
|
|
3779
|
-
|
|
3780
|
-
// src/actions/retest.ts
|
|
3781
|
-
function isWorkspace(target) {
|
|
3782
|
-
return yarnWorkspaces().some((ws) => ws.name === target);
|
|
3783
|
-
}
|
|
3784
|
-
var retest = ({ target } = {}) => {
|
|
3785
|
-
if (target && isWorkspace(target)) {
|
|
3786
|
-
return runSteps(`Re-Test [${target}]`, [
|
|
3787
|
-
["yarn", ["workspace", target, "run", "vitest", "--clearCache"]],
|
|
3788
|
-
["yarn", ["workspace", target, "run", "vitest", "."]]
|
|
3789
|
-
]);
|
|
3790
|
-
}
|
|
3791
|
-
const path14 = target ?? ".";
|
|
3792
|
-
return runSteps("Re-Test", [
|
|
3793
|
-
["yarn", ["vitest", "--clearCache"]],
|
|
3794
|
-
["yarn", ["vitest", path14]]
|
|
3795
|
-
]);
|
|
3796
|
-
};
|
|
3797
|
-
|
|
3798
|
-
// src/actions/sonar.ts
|
|
3799
|
-
var sonar = () => {
|
|
3800
|
-
return runSteps("Sonar", [["yarn", ["eslint", "-c", "sonar.eslintrc", "."]]]);
|
|
3801
|
-
};
|
|
3802
|
-
|
|
3803
|
-
// src/actions/statics.ts
|
|
3804
|
-
import chalk45 from "chalk";
|
|
3805
|
-
var DefaultDependencies = ["axios", "@xylabs/pixel", "react", "graphql", "react-router", "@mui/material", "@mui/system"];
|
|
3806
|
-
var statics = () => {
|
|
3807
|
-
console.log(chalk45.green("Check Required Static Dependencies"));
|
|
3808
|
-
const statics2 = parsedPackageJSON()?.xy?.deps?.statics;
|
|
3809
|
-
return detectDuplicateDependencies(statics2, DefaultDependencies);
|
|
3810
|
-
};
|
|
3811
|
-
|
|
3812
|
-
// src/actions/test.ts
|
|
3813
|
-
function isWorkspace2(target) {
|
|
3814
|
-
return yarnWorkspaces().some((ws) => ws.name === target);
|
|
3815
|
-
}
|
|
3816
|
-
var test = ({ target } = {}) => {
|
|
3817
|
-
if (target && isWorkspace2(target)) {
|
|
3818
|
-
return runSteps(`Test [${target}]`, [["yarn", ["workspace", target, "run", "vitest", "."]]]);
|
|
3819
|
-
}
|
|
3820
|
-
const path14 = target ?? ".";
|
|
3821
|
-
return runSteps("Test", [["yarn", ["vitest", path14]]]);
|
|
159
|
+
return result || runSteps6("Reinstall", [["yarn", "install --network-timeout 10000"]]);
|
|
3822
160
|
};
|
|
3823
161
|
|
|
3824
162
|
// src/actions/up.ts
|
|
163
|
+
import { runSteps as runSteps7 } from "@xylabs/ts-scripts-common";
|
|
3825
164
|
var up = () => {
|
|
3826
|
-
return
|
|
165
|
+
return runSteps7("Up", [["yarn", "outdated"]]);
|
|
3827
166
|
};
|
|
3828
167
|
|
|
3829
168
|
// src/actions/updo.ts
|
|
169
|
+
import { runSteps as runSteps8 } from "@xylabs/ts-scripts-common";
|
|
3830
170
|
var updo = () => {
|
|
3831
|
-
return
|
|
171
|
+
return runSteps8("Updo", [
|
|
3832
172
|
["yarn", "install"],
|
|
3833
173
|
["yarn", "upgrade-interactive"],
|
|
3834
174
|
["yarn", "dedupe"]
|
|
@@ -3836,8 +176,9 @@ var updo = () => {
|
|
|
3836
176
|
};
|
|
3837
177
|
|
|
3838
178
|
// src/actions/upplug.ts
|
|
179
|
+
import { runSteps as runSteps9 } from "@xylabs/ts-scripts-common";
|
|
3839
180
|
var updateYarnPlugins = () => {
|
|
3840
|
-
return
|
|
181
|
+
return runSteps9("Update Yarn Plugins", [
|
|
3841
182
|
["yarn", ["plugin", "import", "https://mskelton.dev/yarn-outdated/v3"]],
|
|
3842
183
|
["yarn", ["plugin", "import", "version"]],
|
|
3843
184
|
["yarn", ["plugin", "import", "interactive-tools"]],
|
|
@@ -3846,11 +187,13 @@ var updateYarnPlugins = () => {
|
|
|
3846
187
|
};
|
|
3847
188
|
|
|
3848
189
|
// src/actions/upyarn.ts
|
|
190
|
+
import { runSteps as runSteps10 } from "@xylabs/ts-scripts-common";
|
|
3849
191
|
var updateYarnVersion = () => {
|
|
3850
|
-
return
|
|
192
|
+
return runSteps10("Update Yarn Version", [["yarn", ["set", "version", "latest"]]]);
|
|
3851
193
|
};
|
|
3852
194
|
|
|
3853
195
|
// src/actions/yarn3only.ts
|
|
196
|
+
import { processEx } from "@xylabs/ts-scripts-common";
|
|
3854
197
|
var yarn3Only = () => {
|
|
3855
198
|
const [valid, version] = isYarnVersionOrGreater(3);
|
|
3856
199
|
if (!valid) {
|
|
@@ -3858,78 +201,23 @@ var yarn3Only = () => {
|
|
|
3858
201
|
}
|
|
3859
202
|
return 0;
|
|
3860
203
|
};
|
|
204
|
+
|
|
205
|
+
// src/actions/index.ts
|
|
206
|
+
import {
|
|
207
|
+
clean,
|
|
208
|
+
dupdeps,
|
|
209
|
+
statics
|
|
210
|
+
} from "@xylabs/ts-scripts-common";
|
|
3861
211
|
export {
|
|
3862
|
-
build,
|
|
3863
|
-
claudeClean,
|
|
3864
|
-
claudeCommands,
|
|
3865
|
-
claudeRules,
|
|
3866
|
-
claudeSettings,
|
|
3867
|
-
claudeSkills,
|
|
3868
212
|
clean,
|
|
3869
|
-
cleanAll,
|
|
3870
|
-
cleanDocs,
|
|
3871
|
-
cleanPackage,
|
|
3872
|
-
compile,
|
|
3873
|
-
compileAll,
|
|
3874
|
-
compilePackage,
|
|
3875
|
-
copyAssets,
|
|
3876
|
-
cycle,
|
|
3877
|
-
cycleAll,
|
|
3878
|
-
cyclePackage,
|
|
3879
|
-
dead,
|
|
3880
|
-
deplint,
|
|
3881
213
|
deploy,
|
|
3882
214
|
deployMajor,
|
|
3883
215
|
deployMinor,
|
|
3884
216
|
deployNext,
|
|
3885
217
|
dupdeps,
|
|
3886
|
-
fix,
|
|
3887
|
-
genDocs,
|
|
3888
|
-
genDocsAll,
|
|
3889
|
-
genDocsPackage,
|
|
3890
|
-
gitignore,
|
|
3891
|
-
gitignoreGen,
|
|
3892
|
-
gitlint,
|
|
3893
|
-
gitlintFix,
|
|
3894
|
-
knip,
|
|
3895
|
-
license,
|
|
3896
|
-
lint,
|
|
3897
|
-
lintAllPackages,
|
|
3898
|
-
lintPackage,
|
|
3899
|
-
lintlint,
|
|
3900
|
-
npmignoreGen,
|
|
3901
|
-
packageClean,
|
|
3902
|
-
packageCleanOutputs,
|
|
3903
|
-
packageCleanTypescript,
|
|
3904
|
-
packageCompile,
|
|
3905
|
-
packageCompileTsc,
|
|
3906
|
-
packageCompileTsup,
|
|
3907
|
-
packageCopyAssets,
|
|
3908
|
-
packageCycle,
|
|
3909
|
-
packageGenDocs,
|
|
3910
|
-
packageLint,
|
|
3911
|
-
packageLintMonorepo,
|
|
3912
|
-
packagePublint,
|
|
3913
|
-
packageRecompile,
|
|
3914
|
-
publint,
|
|
3915
|
-
publintAll,
|
|
3916
|
-
publintPackage,
|
|
3917
218
|
publish,
|
|
3918
|
-
readmeGen,
|
|
3919
|
-
readmeInit,
|
|
3920
|
-
rebuild,
|
|
3921
|
-
recompile,
|
|
3922
|
-
recompileAll,
|
|
3923
|
-
recompilePackage,
|
|
3924
219
|
reinstall,
|
|
3925
|
-
relint,
|
|
3926
|
-
relintAllPackages,
|
|
3927
|
-
relintPackage,
|
|
3928
|
-
retest,
|
|
3929
|
-
sonar,
|
|
3930
220
|
statics,
|
|
3931
|
-
test,
|
|
3932
|
-
tsupOptions,
|
|
3933
221
|
up,
|
|
3934
222
|
updateYarnPlugins,
|
|
3935
223
|
updateYarnVersion,
|