@visulima/vis 1.0.0-alpha.4 → 1.0.0-alpha.40
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/CHANGELOG.md +1216 -78
- package/LICENSE.md +13068 -6
- package/README.md +388 -26
- package/dashboard/dist/index.html +152 -0
- package/dist/bin.js +1 -853
- package/dist/binx.js +3 -0
- package/dist/config/index.d.ts +3258 -0
- package/dist/config/index.js +1 -0
- package/dist/generate/index.d.ts +157 -0
- package/dist/generate/index.js +1 -0
- package/dist/packem_chunks/DEFAULT_CLEAN_KEEP.js +1 -0
- package/dist/packem_chunks/bin.js +1198 -0
- package/dist/packem_chunks/bloom-status.js +2 -0
- package/dist/packem_chunks/bloom-sync.js +2 -0
- package/dist/packem_chunks/cache-attestation.js +1 -0
- package/dist/packem_chunks/catalog-detector.js +1 -0
- package/dist/packem_chunks/config.js +21 -0
- package/dist/packem_chunks/detect.js +3 -0
- package/dist/packem_chunks/detect2.js +8 -0
- package/dist/packem_chunks/devtools.js +81 -0
- package/dist/packem_chunks/discord.js +4 -0
- package/dist/packem_chunks/doctor-probe.js +2 -0
- package/dist/packem_chunks/dynamic-import.js +1 -0
- package/dist/packem_chunks/extra-files.js +3 -0
- package/dist/packem_chunks/fix.js +11 -0
- package/dist/packem_chunks/git.js +3 -0
- package/dist/packem_chunks/handler.js +1 -0
- package/dist/packem_chunks/handler10.js +1 -0
- package/dist/packem_chunks/handler11.js +5 -0
- package/dist/packem_chunks/handler12.js +1 -0
- package/dist/packem_chunks/handler13.js +27 -0
- package/dist/packem_chunks/handler14.js +5 -0
- package/dist/packem_chunks/handler15.js +1 -0
- package/dist/packem_chunks/handler16.js +1 -0
- package/dist/packem_chunks/handler17.js +1 -0
- package/dist/packem_chunks/handler18.js +1 -0
- package/dist/packem_chunks/handler19.js +1 -0
- package/dist/packem_chunks/handler2.js +4 -0
- package/dist/packem_chunks/handler20.js +5 -0
- package/dist/packem_chunks/handler21.js +2 -0
- package/dist/packem_chunks/handler22.js +2 -0
- package/dist/packem_chunks/handler23.js +1 -0
- package/dist/packem_chunks/handler24.js +1 -0
- package/dist/packem_chunks/handler25.js +1 -0
- package/dist/packem_chunks/handler26.js +5 -0
- package/dist/packem_chunks/handler27.js +1 -0
- package/dist/packem_chunks/handler28.js +3 -0
- package/dist/packem_chunks/handler29.js +1 -0
- package/dist/packem_chunks/handler3.js +4 -0
- package/dist/packem_chunks/handler30.js +2 -0
- package/dist/packem_chunks/handler31.js +2 -0
- package/dist/packem_chunks/handler32.js +2 -0
- package/dist/packem_chunks/handler33.js +3 -0
- package/dist/packem_chunks/handler34.js +6 -0
- package/dist/packem_chunks/handler35.js +1 -0
- package/dist/packem_chunks/handler36.js +42 -0
- package/dist/packem_chunks/handler37.js +8 -0
- package/dist/packem_chunks/handler38.js +9 -0
- package/dist/packem_chunks/handler39.js +75 -0
- package/dist/packem_chunks/handler4.js +6 -0
- package/dist/packem_chunks/handler40.js +5 -0
- package/dist/packem_chunks/handler41.js +4 -0
- package/dist/packem_chunks/handler42.js +3 -0
- package/dist/packem_chunks/handler43.js +2 -0
- package/dist/packem_chunks/handler44.js +1 -0
- package/dist/packem_chunks/handler45.js +1 -0
- package/dist/packem_chunks/handler46.js +1 -0
- package/dist/packem_chunks/handler47.js +3 -0
- package/dist/packem_chunks/handler48.js +1 -0
- package/dist/packem_chunks/handler49.js +7 -0
- package/dist/packem_chunks/handler5.js +8 -0
- package/dist/packem_chunks/handler50.js +33 -0
- package/dist/packem_chunks/handler51.js +3 -0
- package/dist/packem_chunks/handler52.js +8 -0
- package/dist/packem_chunks/handler53.js +4 -0
- package/dist/packem_chunks/handler54.js +1 -0
- package/dist/packem_chunks/handler55.js +12 -0
- package/dist/packem_chunks/handler56.js +7 -0
- package/dist/packem_chunks/handler57.js +5 -0
- package/dist/packem_chunks/handler58.js +11 -0
- package/dist/packem_chunks/handler59.js +3 -0
- package/dist/packem_chunks/handler6.js +1 -0
- package/dist/packem_chunks/handler60.js +22 -0
- package/dist/packem_chunks/handler61.js +61 -0
- package/dist/packem_chunks/handler62.js +3 -0
- package/dist/packem_chunks/handler63.js +6 -0
- package/dist/packem_chunks/handler64.js +708 -0
- package/dist/packem_chunks/handler65.js +24 -0
- package/dist/packem_chunks/handler66.js +25 -0
- package/dist/packem_chunks/handler67.js +153 -0
- package/dist/packem_chunks/handler68.js +10 -0
- package/dist/packem_chunks/handler69.js +24 -0
- package/dist/packem_chunks/handler7.js +1 -0
- package/dist/packem_chunks/handler70.js +322 -0
- package/dist/packem_chunks/handler71.js +48 -0
- package/dist/packem_chunks/handler72.js +27 -0
- package/dist/packem_chunks/handler73.js +3 -0
- package/dist/packem_chunks/handler74.js +190 -0
- package/dist/packem_chunks/handler75.js +38 -0
- package/dist/packem_chunks/handler8.js +1 -0
- package/dist/packem_chunks/handler9.js +1 -0
- package/dist/packem_chunks/heal-accept.js +10 -0
- package/dist/packem_chunks/heal.js +14 -0
- package/dist/packem_chunks/help-command.js +31 -0
- package/dist/packem_chunks/index.js +1 -0
- package/dist/packem_chunks/index2.js +7 -0
- package/dist/packem_chunks/interface.js +2 -0
- package/dist/packem_chunks/keys-refresh.js +4 -0
- package/dist/packem_chunks/list.js +3 -0
- package/dist/packem_chunks/loader.js +4 -0
- package/dist/packem_chunks/loader2.js +1 -0
- package/dist/packem_chunks/orchestrator.js +39 -0
- package/dist/packem_chunks/pre-mode.js +2 -0
- package/dist/packem_chunks/print-config.js +2 -0
- package/dist/packem_chunks/prompts.js +7 -0
- package/dist/packem_chunks/prune.js +3 -0
- package/dist/packem_chunks/publish-guards.js +1 -0
- package/dist/packem_chunks/registry.js +48 -0
- package/dist/packem_chunks/resolveFormatter.js +9 -0
- package/dist/packem_chunks/run.js +1 -0
- package/dist/packem_chunks/security.js +1 -0
- package/dist/packem_chunks/shell-runner.js +1 -0
- package/dist/packem_chunks/slack.js +2 -0
- package/dist/packem_chunks/snapshot.js +2 -0
- package/dist/packem_chunks/stage-publisher.js +1 -0
- package/dist/packem_chunks/staged-registry.js +2 -0
- package/dist/packem_chunks/state.js +3 -0
- package/dist/packem_chunks/status.js +2 -0
- package/dist/packem_chunks/success-walk.js +8 -0
- package/dist/packem_chunks/sync.js +2 -0
- package/dist/packem_chunks/sync2.js +2 -0
- package/dist/packem_chunks/tar.js +3 -0
- package/dist/packem_chunks/tripwire.js +2 -0
- package/dist/packem_chunks/verify-lockfile.js +2 -0
- package/dist/packem_chunks/version-resolver.js +2 -0
- package/dist/packem_chunks/webhook.js +1 -0
- package/dist/packem_chunks/workflow-templates.js +167 -0
- package/dist/packem_chunks/workspace.js +2 -0
- package/dist/packem_shared/AfterAllProjectsVersioned-CAKI2nWf.js +1 -0
- package/dist/packem_shared/CONFIG_FILES-BfaR0jKT.js +1 -0
- package/dist/packem_shared/MultiSpinner-B9U0-aE3-B-gIXhFk.js +3 -0
- package/dist/packem_shared/ReleaseClient-YHzBIxYS.js +1 -0
- package/dist/packem_shared/Table-CcVkyULl-B_ef6zfS.js +35 -0
- package/dist/packem_shared/VisReleaseError-DMGRBTNO.js +1 -0
- package/dist/packem_shared/_commonjsHelpers-B5Y90VFO.js +1 -0
- package/dist/packem_shared/advisories-DLeO5KMN.js +1 -0
- package/dist/packem_shared/affected-shas-cVnX8-zs.js +1 -0
- package/dist/packem_shared/ai-analysis-BUeX2J2H.js +68 -0
- package/dist/packem_shared/ai-fix-9Vzlp6XU.js +43 -0
- package/dist/packem_shared/anolilab-text-CAM_E6uK.js +13 -0
- package/dist/packem_shared/api.d-BPftyU9r.d.ts +27 -0
- package/dist/packem_shared/build-scripts-CCCi8U66.js +1 -0
- package/dist/packem_shared/createAdapter-bU4DIP3F.js +1 -0
- package/dist/packem_shared/createVersionActions-BK43SNDH.js +1 -0
- package/dist/packem_shared/cyclonedx-kYozDyxp.js +4 -0
- package/dist/packem_shared/defineFormatter-D5dCp6Kv.js +1 -0
- package/dist/packem_shared/definePlugin-DoUcoYSy.js +1 -0
- package/dist/packem_shared/dependency-scan-DnTgYleU.js +1 -0
- package/dist/packem_shared/docker-BMLrNtWm.js +59 -0
- package/dist/packem_shared/failure-log-CEWP3bP0.js +2 -0
- package/dist/packem_shared/giget-DHY1sQZC.js +2 -0
- package/dist/packem_shared/glob-fqg4KepW-B7EjLRvw.js +1 -0
- package/dist/packem_shared/index-BDmTbWX1.js +19 -0
- package/dist/packem_shared/index-CgcF6_wo.js +1 -0
- package/dist/packem_shared/index-Du8RWawQ.js +1 -0
- package/dist/packem_shared/index-yBikBkHT.js +30 -0
- package/dist/packem_shared/interface.d-B7VK2rcH.d.ts +148 -0
- package/dist/packem_shared/interface.d-Cezzifoh.d.ts +106 -0
- package/dist/packem_shared/license-t5KnNX6v.js +1 -0
- package/dist/packem_shared/lifecycle-4z9hHE5b.js +2 -0
- package/dist/packem_shared/lockfile-C8Q1_4KK.js +1 -0
- package/dist/packem_shared/manifests-Dj3pRKBT.js +1 -0
- package/dist/packem_shared/min-release-age-D1alDE3K.js +34 -0
- package/dist/packem_shared/missing-package-json-8vNHwbqw.js +1 -0
- package/dist/packem_shared/native-config-sync-BEkJW7g3.js +21 -0
- package/dist/packem_shared/osv-bloom-B03tUWf3.js +2 -0
- package/dist/packem_shared/otelPlugin-DmKDBaPo.js +1 -0
- package/dist/packem_shared/peer-warnings-BXAzXqY3.js +1 -0
- package/dist/packem_shared/pm-runner-OGResYrA.js +1 -0
- package/dist/packem_shared/provenance-_CJjMKwu.js +1 -0
- package/dist/packem_shared/public-api-WqUCiyIe.js +131 -0
- package/dist/packem_shared/registry-keys-BfFto6vI.js +1 -0
- package/dist/packem_shared/resolve-explicit-CMDl55Nz.js +5 -0
- package/dist/packem_shared/runtime-check-Stc9AI78.js +1 -0
- package/dist/packem_shared/s1ngularity-Dhr3bPk0.js +1 -0
- package/dist/packem_shared/scan-progress-CFhc0CMj.js +2 -0
- package/dist/packem_shared/selectors-GCJIe342.js +3 -0
- package/dist/packem_shared/signatures-C730vkyK.js +2 -0
- package/dist/packem_shared/slug-DoueYuLo.js +1 -0
- package/dist/packem_shared/spinner-CV3WVJLv.js +1 -0
- package/dist/packem_shared/sticky-comment-D6_7-w8T.js +1 -0
- package/dist/packem_shared/subtree-C7bZuiSQ.js +2 -0
- package/dist/packem_shared/symbols-DPTlrJ3B.js +1 -0
- package/dist/packem_shared/tabs-BuTy5gPV.js +1 -0
- package/dist/packem_shared/toolchain-pR7AJ-tB.js +5 -0
- package/dist/packem_shared/typosquats-DN78xx1x.js +1 -0
- package/dist/packem_shared/use-measured-height-_eVGWtWt.js +1 -0
- package/dist/packem_shared/utils-Cxree603.js +1 -0
- package/dist/packem_shared/verify-6WCmFmy8.js +1 -0
- package/dist/packem_shared/vis-update-app-k3fDxech.js +1 -0
- package/dist/packem_shared/watch-BvIwLG4N.js +1 -0
- package/dist/packem_shared/watch-loop-DWkvv2tK.js +11 -0
- package/dist/release/core/changelog/index.d.ts +5 -0
- package/dist/release/core/changelog/index.js +1 -0
- package/dist/release/core/package-managers/index.d.ts +6 -0
- package/dist/release/core/package-managers/index.js +1 -0
- package/dist/release/core/version-actions/index.d.ts +14 -0
- package/dist/release/core/version-actions/index.js +1 -0
- package/dist/release/index.d.ts +196 -0
- package/dist/release/index.js +1 -0
- package/dist/release/plugin-sdk.d.ts +127 -0
- package/dist/release/plugin-sdk.js +1 -0
- package/dist/release/presets.d.ts +225 -0
- package/dist/release/presets.js +1 -0
- package/dist/release/types.d.ts +1377 -0
- package/dist/release/types.js +1 -0
- package/index.d.ts +436 -0
- package/index.js +80 -57
- package/package.json +109 -45
- package/schemas/project.schema.json +991 -0
- package/schemas/vis-config.schema.json +6377 -0
- package/schemas/vis-release-config.schema.json +1390 -0
- package/skills/vis/SKILL.md +96 -0
- package/templates/buildkite-ci/.buildkite/pipeline.yml.tera +85 -0
- package/templates/buildkite-ci/template.yml +20 -0
- package/dist/ai-analysis.d.ts +0 -40
- package/dist/ai-cache.d.ts +0 -21
- package/dist/audit-config.d.ts +0 -24
- package/dist/bin.d.ts +0 -1
- package/dist/catalog.d.ts +0 -118
- package/dist/commands/add.d.ts +0 -3
- package/dist/commands/affected.d.ts +0 -3
- package/dist/commands/ai.d.ts +0 -3
- package/dist/commands/analyze.d.ts +0 -3
- package/dist/commands/approve-builds.d.ts +0 -3
- package/dist/commands/audit.d.ts +0 -23
- package/dist/commands/check.d.ts +0 -3
- package/dist/commands/clean.d.ts +0 -3
- package/dist/commands/create/discovery.d.ts +0 -42
- package/dist/commands/create/index.d.ts +0 -13
- package/dist/commands/create/prompts.d.ts +0 -31
- package/dist/commands/create/random-name.d.ts +0 -15
- package/dist/commands/create/templates/builtin.d.ts +0 -15
- package/dist/commands/create/templates/generator.d.ts +0 -14
- package/dist/commands/create/templates/index.d.ts +0 -13
- package/dist/commands/create/templates/monorepo.d.ts +0 -16
- package/dist/commands/create/templates/remote.d.ts +0 -41
- package/dist/commands/create/templates/types.d.ts +0 -46
- package/dist/commands/create/utils.d.ts +0 -42
- package/dist/commands/dedupe.d.ts +0 -3
- package/dist/commands/devcontainer.d.ts +0 -3
- package/dist/commands/dlx.d.ts +0 -3
- package/dist/commands/doctor.d.ts +0 -15
- package/dist/commands/exec.d.ts +0 -3
- package/dist/commands/graph.d.ts +0 -3
- package/dist/commands/hook/constants.d.ts +0 -8
- package/dist/commands/hook/index.d.ts +0 -3
- package/dist/commands/hook/install.d.ts +0 -7
- package/dist/commands/hook/migrate.d.ts +0 -27
- package/dist/commands/hook/uninstall.d.ts +0 -3
- package/dist/commands/implode.d.ts +0 -3
- package/dist/commands/init.d.ts +0 -14
- package/dist/commands/install.d.ts +0 -3
- package/dist/commands/link.d.ts +0 -3
- package/dist/commands/migrate/constants.d.ts +0 -12
- package/dist/commands/migrate/deps.d.ts +0 -32
- package/dist/commands/migrate/index.d.ts +0 -3
- package/dist/commands/migrate/json.d.ts +0 -20
- package/dist/commands/migrate/lint-staged.d.ts +0 -62
- package/dist/commands/migrate/types.d.ts +0 -20
- package/dist/commands/optimize.d.ts +0 -38
- package/dist/commands/pm.d.ts +0 -3
- package/dist/commands/remove.d.ts +0 -3
- package/dist/commands/run.d.ts +0 -3
- package/dist/commands/sort-package-json.d.ts +0 -3
- package/dist/commands/staged.d.ts +0 -3
- package/dist/commands/unlink.d.ts +0 -3
- package/dist/commands/update.d.ts +0 -3
- package/dist/commands/upgrade.d.ts +0 -3
- package/dist/commands/why.d.ts +0 -3
- package/dist/config.d.ts +0 -67
- package/dist/config.js +0 -1
- package/dist/native-binding.d.ts +0 -151
- package/dist/output.d.ts +0 -40
- package/dist/overrides.d.ts +0 -82
- package/dist/package-manager.d.ts +0 -23
- package/dist/plugins/config-loader.d.ts +0 -3
- package/dist/plugins/post-command.d.ts +0 -3
- package/dist/plugins/security-enforcement.d.ts +0 -3
- package/dist/pm-runner.d.ts +0 -23
- package/dist/security.d.ts +0 -64
- package/dist/socket-security.d.ts +0 -129
- package/dist/tips.d.ts +0 -41
- package/dist/tui/components/CheckProgressApp.d.ts +0 -6
- package/dist/tui/components/CommandSummary.d.ts +0 -17
- package/dist/tui/components/Header.d.ts +0 -13
- package/dist/tui/components/OutputPanel.d.ts +0 -16
- package/dist/tui/components/QuitDialog.d.ts +0 -15
- package/dist/tui/components/TaskListPanel.d.ts +0 -19
- package/dist/tui/components/TaskRow.d.ts +0 -12
- package/dist/tui/components/TaskStore.d.ts +0 -80
- package/dist/tui/components/VisTaskRunnerApp.d.ts +0 -17
- package/dist/tui/components/devcontainer/DevcontainerStore.d.ts +0 -66
- package/dist/tui/components/devcontainer/VisDevcontainerApp.d.ts +0 -9
- package/dist/tui/components/devcontainer/catalogs/extensions.d.ts +0 -8
- package/dist/tui/components/devcontainer/catalogs/features.d.ts +0 -8
- package/dist/tui/components/devcontainer/catalogs/filters.d.ts +0 -4
- package/dist/tui/components/devcontainer/catalogs/mount-suggestions.d.ts +0 -19
- package/dist/tui/components/devcontainer/catalogs/templates.d.ts +0 -8
- package/dist/tui/components/devcontainer/devcontainer-io.d.ts +0 -14
- package/dist/tui/components/devcontainer/sections/DockerComposeSection.d.ts +0 -11
- package/dist/tui/components/devcontainer/sections/EnvironmentSection.d.ts +0 -16
- package/dist/tui/components/devcontainer/sections/ExtensionsSection.d.ts +0 -11
- package/dist/tui/components/devcontainer/sections/FeaturesSection.d.ts +0 -11
- package/dist/tui/components/devcontainer/sections/GeneralSection.d.ts +0 -12
- package/dist/tui/components/devcontainer/sections/LifecycleSection.d.ts +0 -13
- package/dist/tui/components/devcontainer/sections/MountsSection.d.ts +0 -16
- package/dist/tui/components/devcontainer/sections/PortsSection.d.ts +0 -10
- package/dist/tui/components/devcontainer/sections/PreviewPanel.d.ts +0 -11
- package/dist/tui/components/devcontainer/types.d.ts +0 -53
- package/dist/tui/components/devcontainer/validate.d.ts +0 -16
- package/dist/tui/components/graph/GraphStore.d.ts +0 -42
- package/dist/tui/components/graph/ProjectDetailPanel.d.ts +0 -10
- package/dist/tui/components/graph/ProjectListPanel.d.ts +0 -20
- package/dist/tui/components/graph/VisGraphApp.d.ts +0 -8
- package/dist/tui/components/optimize/OptimizeDetailPanel.d.ts +0 -9
- package/dist/tui/components/optimize/OptimizeListPanel.d.ts +0 -16
- package/dist/tui/components/optimize/OptimizeStore.d.ts +0 -50
- package/dist/tui/components/optimize/VisOptimizeApp.d.ts +0 -8
- package/dist/tui/components/optimize/constants.d.ts +0 -7
- package/dist/tui/components/update/PackageDetailPanel.d.ts +0 -12
- package/dist/tui/components/update/PackageListPanel.d.ts +0 -18
- package/dist/tui/components/update/UpdateStore.d.ts +0 -62
- package/dist/tui/components/update/VisUpdateApp.d.ts +0 -11
- package/dist/tui/dynamic-life-cycle.d.ts +0 -21
- package/dist/tui/formatting-utils.d.ts +0 -17
- package/dist/tui/pretty-time.d.ts +0 -8
- package/dist/tui/static-life-cycle.d.ts +0 -22
- package/dist/tui/status-utils.d.ts +0 -20
- package/dist/tui/symbols.d.ts +0 -7
- package/dist/tui/types.d.ts +0 -11
- package/dist/typosquats.d.ts +0 -70
- package/dist/upgrade-check.d.ts +0 -30
- package/dist/utils.d.ts +0 -22
- package/dist/workspace.d.ts +0 -315
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import{createRequire as te}from"node:module";import{E as f,j as g,q as y}from"../packem_shared/Table-CcVkyULl-B_ef6zfS.js";import{m as T,f as R,I as V,H as G,y as K,a as L,A as P,o as se,T as oe,B as ne}from"../packem_shared/index-BDmTbWX1.js";import{f as pe}from"../packem_shared/giget-DHY1sQZC.js";import{p as l}from"./bin.js";const re=te(import.meta.url),N=typeof globalThis<"u"&&typeof globalThis.process<"u"?globalThis.process:process,j=t=>{if(typeof N<"u"&&N.versions&&N.versions.node){const[e,r]=N.versions.node.split(".").map(Number);if(e>22||e===22&&r>=3||e===20&&r>=16)return N.getBuiltinModule(t)}return re(t)},{fileURLToPath:ie}=j("node:url"),{createInterface:ae}=j("node:readline"),{mkdtempSync:ce,rmSync:le}=j("node:fs"),{tmpdir:fe}=j("node:os"),{spawnSync:ue}=j("node:child_process"),J=[".ts",".mts",".cts",".js",".mjs",".cjs"],de="template.yml",me=[".d",".test",".spec",".config",".bench",".stories"],he=[".d.ts",".d.mts",".d.cts",".js.map",".mjs.map",".cjs.map",".ts.map"],Y=t=>{for(const e of J)if(t.endsWith(e))return t.slice(0,-e.length);return t},$e=t=>{if(he.some(r=>t.endsWith(r))||!J.some(r=>t.endsWith(r)))return!1;const e=Y(t);return!me.some(r=>e.endsWith(r))},H=(t,e)=>{const r=[];if(!R(t))return r;for(const s of V(t,{includeDirs:!1,includeSymlinks:!1,maxDepth:1})){if(!$e(s.name))continue;const n=Y(s.name);r.push({load:()=>ge(s.path),name:n,path:s.path,source:e})}return r},x=(t,e)=>{const r=[];if(!R(t))return r;for(const s of V(t,{includeFiles:!1,includeSymlinks:!1,maxDepth:1})){if(s.path===t)continue;const n=T(s.path,de);R(n)&&r.push({load:()=>ye(s.path,s.name),name:s.name,path:s.path,source:e})}return r},we=()=>{try{const t=ie(import.meta.url),e=T(G(t),"..","..","templates");return R(e)?e:void 0}catch{return}},I=t=>{const{extraDirectories:e=[],onWarning:r,workspaceRoot:s}=t,n=[...H(T(s,".vis","templates"),"native"),...x(T(s,".vis","templates"),"moon"),...x(T(s,".moon","templates"),"moon")];for(const o of e)n.push(...x(o,"config")),n.push(...H(o,"config"));const i=we();i&&n.push(...x(i,"builtin"));const a=new Map;for(const o of n){const c=a.get(o.name);if(!c){a.set(o.name,o);continue}r&&r(`Template "${o.name}" exists in multiple sources — using ${c.source} (${c.path}), ignoring ${o.source} (${o.path}).`)}return[...a.values()].sort((o,c)=>o.name.localeCompare(c.name))},ge=async t=>{const{loadNativeTemplate:e}=await import("./loader2.js");return e(t)},ye=async(t,e)=>{const{loadMoonTemplate:r}=await import("./index2.js");return r(t,e)},q=(t,e)=>new Promise(r=>{t.question(e,s=>{r(s.trim())})}),ve=async(t,e,r)=>{const s=await q(t,` ${e} ${f(r?"[Y/n]":"[y/N]")} `);return s===""?r:s.toLowerCase()==="y"||s.toLowerCase()==="yes"},be=async(t,e,r,s)=>{process.stderr.write(` ${e}
|
|
2
|
+
`);for(const[n,i]of r.entries()){const a=g(y(` ${String(n+1)}.`)),o=i===s?f(" (default)"):"";process.stderr.write(`${a} ${i}${o}
|
|
3
|
+
`)}for(;;){const n=await q(t,`
|
|
4
|
+
${f(`Enter choice (1-${String(r.length)}):`)} `);if(n===""&&s!==void 0)return s;const i=Number.parseInt(n,10);if(Number.isInteger(i)&&i>=1&&i<=r.length)return r[i-1];const a=r.find(o=>o===n);if(a)return a;process.stderr.write(` ${f("Invalid choice. Try again.")}
|
|
5
|
+
`)}},Te=async(t,e,r,s)=>{process.stderr.write(` ${e} ${f("(comma-separated numbers)")}
|
|
6
|
+
`);for(const[n,i]of r.entries()){const a=g(y(` ${String(n+1)}.`)),o=s.includes(i)?f(" (default)"):"";process.stderr.write(`${a} ${i}${o}
|
|
7
|
+
`)}for(;;){const n=await q(t,`
|
|
8
|
+
${f("Enter choices:")} `);if(n===""&&s.length>0)return s;const i=n.split(",").map(a=>Number.parseInt(a.trim(),10)).filter(a=>Number.isInteger(a)&&a>=1&&a<=r.length);if(i.length>0)return i.map(a=>r[a-1]);process.stderr.write(` ${f("Invalid choice. Try again.")}
|
|
9
|
+
`)}},Se=t=>` ${f(`${t}:`)} `,Ee=(t,e)=>e.prompt??t,Ne=t=>Object.entries(t).sort(([e,r],[s,n])=>{const i=r.order??0,a=n.order??0;return i!==a?i-a:e.localeCompare(s)}),U=(t,e)=>{switch(t.type){case"array":return e.split(",").map(r=>r.trim()).filter(Boolean);case"boolean":return e==="true"||e==="1"||e==="yes"||e==="y";case"enum":return t.multiple?e.split(",").map(r=>r.trim()).filter(Boolean):e;case"number":{const r=Number(e);if(Number.isNaN(r))throw new TypeError(`Expected a number, got "${e}"`);return r}default:return e}},W=(t,e,r)=>{if(e.type==="enum"){const s=Array.isArray(r)?r:[r];for(const n of s)if(typeof n!="string"||!e.values.includes(n))throw new Error(`Variable "${t}" must be one of: ${e.values.join(", ")} (got "${String(n)}")`)}},Re=async t=>{const{defaults:e,interactive:r,overrides:s,variables:n}=t,i={},a=r?ae({input:process.stdin,output:process.stderr}):null;try{for(const[o,c]of Ne(n)){if(Object.hasOwn(s,o)){const w=U(c,s[o]??"");W(o,c,w),i[o]=w;continue}if(e||!r||c.internal){if(c.default!==void 0){W(o,c,c.default),i[o]=c.default;continue}if(c.required)throw new Error(`Required variable "${o}" not provided. Pass --${o}=<value> or remove --defaults.`);continue}const $=Ee(o,c);let m;if(c.type==="boolean")m=await ve(a,$,!!(c.default??!1));else if(c.type==="enum")if(c.multiple){const w=Array.isArray(c.default)?c.default:[];m=await Te(a,$,c.values,w)}else{const w=typeof c.default=="string"?c.default:void 0;m=await be(a,$,c.values,w)}else{const w=c.default===void 0?"":` (${String(c.default)})`,v=await q(a,Se(`${$}${w}`));if(v===""&&c.default!==void 0)m=c.default;else if(v===""){if(c.required)throw new Error(`Variable "${o}" is required`);continue}else m=U(c,v)}W(o,c,m),i[o]=m}return i}finally{a?.close()}},je=["git://","npm://","https://","github:","gitlab:","bitbucket:","sourcehut:"],ke=t=>je.some(e=>t.startsWith(e)),_e=async(t,e={})=>{const r=e.targetDirectory===void 0,s=e.targetDirectory??ce(T(fe(),"vis-generate-")),n=()=>{if(r)try{le(s,{force:!0,recursive:!0})}catch{}};l.info(`Downloading ${t}…`);try{const i=await pe(t,{auth:e.auth||process.env.GIGET_AUTH||process.env.GITHUB_TOKEN||process.env.GH_TOKEN||void 0,dir:s,force:!0,preferOffline:e.preferOffline});return{cleanup:n,directory:i.dir}}catch(i){n();const a=i instanceof Error?i.message:String(i);throw l.warn(`Failed to download template: ${a}`),i}},Q=(t,e="")=>{const r=[];for(const[s,n]of Object.entries(t)){const i=e?`${e}/${s}`:s;typeof n=="string"||Buffer.isBuffer(n)?r.push({content:n,path:i}):n&&typeof n=="object"&&r.push(...Q(n,i))}return r},Oe=t=>t<1024?`${t} B`:t<1024*1024?`${(t/1024).toFixed(1)} KB`:`${(t/(1024*1024)).toFixed(1)} MB`,xe=(t,e)=>{if(P(e))throw new Error(`Refusing to write outside destination: template produced absolute path "${e}".`);const r=T(t,e),s=K(t,r);if(s===".."||s.startsWith(`..${se}`)||P(s))throw new Error(`Refusing to write outside destination: "${e}" resolves to "${r}" which escapes "${t}".`);return r},Ie=(t,e)=>{L(G(t)),oe(t,e)},qe=(t,e,r=!1)=>{const s=typeof t=="string"?[t]:t.commands,n=typeof t=="string"?r:t.silent??r;for(const i of s){n||l.info(`$ ${i}`);const a=ue(i,{cwd:e,shell:!0,stdio:n?"ignore":"inherit"});if(a.status!==0)return l.warn(`Script failed (exit ${String(a.status)}): ${i}`),!1}return!0},De=t=>{const e=new Map;for(const r of t){const s=typeof r=="string"?0:r.phase??0,n=e.get(s);n?n.push(r):e.set(s,[r])}return[...e.entries()].sort(([r],[s])=>r-s)},Be=async(t,e)=>{const r={builtins:{dest_dir:e.destination,dest_rel_dir:K(e.workspaceRoot,e.destination)||".",working_dir:e.cwd,workspace_root:e.workspaceRoot},options:e.options},s=await t.produce(r),n=s.files?Q(s.files):[],i=s.filesMeta??{},a=[];for(const o of n){const c=xe(e.destination,o.path);a.push({file:o,meta:i[o.path]??{},target:c})}if(e.dryRun){l.info(`${g(y("Plan"))} ${f("(dry-run, no files written)")}`);for(const o of a){const c=Buffer.isBuffer(o.file.content)?o.file.content.length:Buffer.byteLength(o.file.content,"utf8");process.stderr.write(` ${f("write")} ${o.file.path} ${f(`(${Oe(c)})`)}
|
|
10
|
+
`)}}else{L(e.destination);let o=0,c=0;for(const $ of a){const{file:m,meta:w,target:v}=$,D=R(v),b=e.force||w.force===!0;if(D&&!b){l.warn(`Skipped existing file: ${m.path} (use --force or set frontmatter force: true to overwrite)`),c+=1;continue}Ie(v,m.content),o+=1}l.success(`Wrote ${String(o)} file${o===1?"":"s"}${c>0?`, skipped ${String(c)}`:""}`)}if(!e.dryRun&&!e.skipScripts&&s.scripts&&s.scripts.length>0){const o=De(s.scripts);l.info(`Running ${String(s.scripts.length)} script${s.scripts.length===1?"":"s"} across ${String(o.length)} phase${o.length===1?"":"s"}…`);for(const[,c]of o)if((await Promise.all(c.map($=>Promise.resolve(qe($,e.destination))))).includes(!1))throw new Error("Script failed — aborting.")}if(s.suggestions&&s.suggestions.length>0){process.stderr.write(`
|
|
11
|
+
`),l.notice("Next steps:");for(const o of s.suggestions)process.stderr.write(` ${f("•")} ${o}
|
|
12
|
+
`)}},We=async t=>{let e;try{e=(await t.load()).about?.description}catch{}return{description:e,name:t.name,path:t.path,source:t.source}},Pe=(t,e)=>{const r={default:e.default,name:t,order:e.order,prompt:e.prompt,required:e.required,type:e.type};return e.type==="enum"&&(r.multiple=e.multiple,r.values=e.values),r},Ae=async t=>{const e=await t.load(),r=Object.entries(e.options??{}).sort(([s,n],[i,a])=>{const o=n.order??0,c=a.order??0;return o===c?s.localeCompare(i):o-c}).map(([s,n])=>Pe(s,n));return{description:e.about?.description??"",destination:e.destination,name:t.name,path:t.path,source:t.source,variables:r}},Ce=t=>{if(t.length===0){l.info("No templates found."),l.notice("Create one at .vis/templates/<name>.ts (programmatic) or .vis/templates/<name>/ (moon-format with template.yml).");return}l.info("Available templates:");for(const e of t){const r=f(`(${e.source})`);process.stderr.write(` ${g(y(e.name))} ${r}
|
|
13
|
+
`)}},Me=t=>{const e={},r=[];for(const s of t){if(!s.startsWith("--")){r.push(s);continue}const n=s.indexOf("=");if(n===-1){const o=s.slice(2);o.startsWith("no-")?e[o.slice(3)]="false":e[o]="true";continue}const i=s.slice(2,n),a=s.slice(n+1);e[i]=a}return{overrides:e,remaining:r}},Fe=async t=>{const{createInterface:e}=await import("node:readline"),r=e({input:process.stdin,output:process.stderr});try{process.stderr.write(` ${g(y("vis generate"))} ${f("— pick a template")}
|
|
14
|
+
|
|
15
|
+
`);for(const[s,n]of t.entries()){const i=g(y(` ${String(s+1)}.`));process.stderr.write(`${i} ${n.name} ${f(`(${n.source})`)}
|
|
16
|
+
`)}return new Promise((s,n)=>{r.question(`
|
|
17
|
+
${f(`Enter choice (1-${String(t.length)}):`)} `,i=>{const a=Number.parseInt(i.trim(),10);Number.isInteger(a)&&a>=1&&a<=t.length?s(t[a-1].name):n(new Error("Invalid choice."))})})}finally{r.close()}},Le=async({argument:t,options:e,rawUnknown:r,visConfig:s,workspaceRoot:n})=>{const i=e.cwd||n||process.cwd(),a=n??i,o=s?.generator,c=Array.isArray(t)?t:t?[t]:[];if(e.list){const u=I({extraDirectories:o?.templates??[],onWarning:p=>{l.warn(p)},workspaceRoot:a});if(e.json){const p=await Promise.all(u.map(d=>We(d)));process.stdout.write(`${JSON.stringify(p,null,2)}
|
|
18
|
+
`);return}Ce(u);return}if(e.describe){const u=c[0];if(!u)throw new Error("`--describe` requires a template name. Run `vis generate --list` to see available templates.");const p=I({extraDirectories:o?.templates??[],onWarning:h=>{l.warn(h)},workspaceRoot:a}).find(h=>h.name===u);if(!p)throw new Error(`Template "${u}" not found. Run \`vis generate --list\` to see available templates.`);const d=await Ae(p);if(e.json){process.stdout.write(`${JSON.stringify(d,null,2)}
|
|
19
|
+
`);return}if(l.info(`Template: ${g(y(d.name))} ${f(`(${d.source})`)}`),d.description&&l.info(d.description),d.destination&&l.info(`Destination: ${f(d.destination)}`),d.variables.length===0)l.info("No variables.");else{l.info("Variables:");for(const h of d.variables){const O=[h.type];h.required&&O.push("required"),h.default!==void 0&&O.push(`default=${JSON.stringify(h.default)}`),h.values&&O.push(`values=${h.values.join("|")}`),process.stderr.write(` ${g(y(h.name))} ${f(`(${O.join(", ")})`)}
|
|
20
|
+
`)}}return}let $=[...r??[]];if($.length===0){const u=process.argv.slice(2),p=u.indexOf("--");p!==-1&&($=u.slice(p+1))}const m=c.indexOf("--"),w=m===-1?[]:c.slice(m+1),v=m===-1?c:c.slice(0,m),{overrides:D}=Me([...w,...$]);let b,k,_;const E=v[0];let B;if(E&&ke(E)){const u=await _e(E,{auth:o?.auth,preferOffline:!!e.preferOffline||o?.preferOffline});B=u.cleanup;try{const p=I({extraDirectories:[u.directory],workspaceRoot:a}).find(d=>d.path.startsWith(u.directory));if(!p)throw new Error(`Downloaded template at ${u.directory} contains no template.yml or *.ts entrypoint.`);b=await p.load(),k=p.name,_=b.destination}catch(p){throw B(),p}}else{const u=I({extraDirectories:o?.templates??[],onWarning:h=>{l.warn(h)},workspaceRoot:a});if(u.length===0)throw new Error("No templates found. Create one at .vis/templates/<name>.ts or .vis/templates/<name>/template.yml.");let p;if(E)p=E;else{if(e.interactive===!1||!process.stdin.isTTY)throw new Error("No template specified. Pass a template name (see `vis generate --list`) or run interactively in a terminal.");p=await Fe(u)}const d=u.find(h=>h.name===p);if(!d)throw new Error(`Template "${p}" not found. Run 'vis generate --list' to see available templates.`);b=await d.load(),k=d.name,_=b.destination}const A=e.to,C=!!e.dryRun,X=!!e.force,M=!!e.defaults,z=!!e.skipScripts,Z=e.interactive!==!1&&!!process.stdin.isTTY&&!M;let S;A?S=A:_?S=_:S=".";const F=P(S)?S:ne(i,S);l.info(`Template: ${g(y(k))}`),l.info(`Target: ${f(F)}`),process.stderr.write(`
|
|
21
|
+
`);const ee=await Re({defaults:M,interactive:Z,overrides:D,variables:b.options??{}});try{await Be(b,{cwd:i,destination:F,dryRun:C,force:X,options:ee,skipScripts:z,workspaceRoot:a}),C||(process.stderr.write(`
|
|
22
|
+
`),l.success(`Template '${k}' applied.`))}finally{B?.()}};export{Le as default};
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import{v as F,H as P,y as S,m as b,T as I,O as U,a as T}from"../packem_shared/index-BDmTbWX1.js";import _ from"./index.js";import{aL as C,b as M,aM as J,Y as q}from"./bin.js";import{n as B}from"../packem_shared/manifests-Dj3pRKBT.js";import{s as H}from"../packem_shared/glob-fqg4KepW-B7EjLRvw.js";const K=(e,t)=>{const o=t.replace(/^\.?\//,"");return o===""||o==="."?`/${e}/`:e===""||e==="."?`/${o}`:`/${e}/${o}`},v=(e,t,o=[])=>{const s=[],n=new Set;for(const[r,i]of Object.entries(t?.globalPaths??{}))s.push({owners:i,path:r,source:"project-json"}),n.add(r);for(const[r,i]of Object.entries(e.projects)){const a=i.owners??[];for(const c of a){const f=K(i.root??r,c.path);s.push({channel:c.channel,owners:c.owners,path:f,projectId:r,source:"project-json"}),n.add(f)}}for(const r of o)n.has(r.path)||(s.push(r),n.add(r.path));return(t?.orderBy??"file-source")==="project-id"?s.sort((r,i)=>(r.projectId??"").localeCompare(i.projectId??"")||r.path.localeCompare(i.path)):s.sort((r,i)=>r.path.localeCompare(i.path)),s},Y="Update each project's project.json `owners` field and re-run the command.",z=e=>["# CODEOWNERS — generated by `vis sync codeowners`. Do not edit by hand.",e?`# Re-run with: ${e}`:`# ${Y}`,""],W=e=>{const t=[];for(const o of e){const s=o.owners.join(" "),n=o.channel?` # notify: ${o.channel}`:"";t.push(`${o.path} ${s}${n}`)}return t},Q=(e,t={})=>[...z(t.regenerationCommand),...W(e),""].join(`
|
|
2
|
+
`),O={begin:"# BEGIN vis-codeowners",end:"# END vis-codeowners"},V=(e,t=O,o={})=>{const s=o.regenerationCommand?`# Generated by vis sync codeowners — re-run with: ${o.regenerationCommand}`:"# Generated by `vis sync codeowners` — do not edit by hand.";return[t.begin,s,...W(e),t.end].join(`
|
|
3
|
+
`)},X=(e,t,o=O)=>{const s=e.indexOf(o.begin),n=e.indexOf(o.end);if(s!==-1&&n!==-1&&n>s){const i=e.slice(0,s),a=n+o.end.length,c=e.slice(a);return`${i}${t}${c}`}const r=e.replace(/\s+$/u,"");return`${r.length===0?"":`${r}
|
|
4
|
+
|
|
5
|
+
`}${t}
|
|
6
|
+
`},Z=["**/CODEOWNERS"],ee=["**/node_modules/**","**/dist/**","**/build/**","**/coverage/**","**/.git/**","**/.next/**","**/.nuxt/**"],te=e=>{const t=[];for(const o of e.split(/\r?\n/u)){const s=o.indexOf("#"),n=(s===-1?o:o.slice(0,s)).trim();if(n.length===0)continue;const r=n.split(/\s+/u);if(r.length<2)continue;const[i,...a]=r,c=a.filter(f=>f.length>0);!i||c.length===0||t.push({owners:c,path:i})}return t},oe=(e,t)=>{const o=t.replace(/^\.\/?/,"").replace(/\/$/,"");return e.startsWith("/")?o===""?e:`/${o}${e}`:o===""?`/${e}`:`/${o}/${e}`},ne=async(e,t,o)=>{const s=t&&t.length>0?[...t]:[...Z],n=[...ee];if(o){const a=o.replace(/^\.\/?/,"").replace(/^\/+/,"");a.length>0&&n.push(a)}const r=await H(s,{absolute:!0,cwd:e,ignore:n}),i=[];for(const a of r){let c;try{c=F(a)}catch{continue}const f=P(a),h=S(e,f);for(const p of te(c))i.push({owners:p.owners,path:oe(p.path,h)})}return i},re=/^(?:https?:\/\/)?(?:www\.)?github\.com\/([^/?#]+)/iu,se=e=>{if(!e)return;const t=e.match(re);if(!t?.[1])return;const o=t[1].trim();if(!(o===""||o.includes(" ")))return`@${o.replace(/^@/,"")}`},ae=(e,t)=>{const o=[];for(const[s,n]of Object.entries(e.projects)){if(n.owners&&n.owners.length>0)continue;const r=n.root??s,i=b(t,r,"package.json"),a=C(i);if(!a)continue;const c=B(a.maintainers);if(!c||c.length===0)continue;const f=[],h=new Set;for(const p of c){const $=se(p.url);$&&!h.has($)&&(h.add($),f.push($))}f.length!==0&&o.push({owners:f,path:r===""||r==="."?"/":`/${r}/`,projectId:s})}return o},ie=["author","bugs","homepage","license","repository","engines"],N=e=>typeof e=="object"&&e!==null&&!Array.isArray(e),E=(e,t)=>{if(e===t)return!0;if(typeof e!=typeof t||e===null||t===null)return!1;if(Array.isArray(e)){if(!Array.isArray(t)||e.length!==t.length)return!1;for(const[o,s]of e.entries())if(!E(s,t[o]))return!1;return!0}if(typeof e=="object"&&typeof t=="object"){const o=Object.keys(e),s=Object.keys(t);if(o.length!==s.length)return!1;for(const n of o)if(!E(e[n],t[n]))return!1;return!0}return!1},R=e=>e===void 0?e:structuredClone(e),ce=(e,t,o)=>{if(e==="repository"&&N(t)&&N(o)){const s={};for(const[n,r]of Object.entries(t))n!=="directory"&&(s[n]=R(r));return typeof o.directory=="string"&&(s.directory=o.directory),s}return R(t)},de=(e,t,o)=>{const s=[];for(const n of o.fields){if(!Object.hasOwn(e,n))continue;const r=e[n],i=t[n],a=ce(n,r,i);E(a,i)||s.push({after:a,before:i,field:n,packageJsonPath:""})}return s},fe=(e,t)=>{for(const o of t)e[o.field]=o.after},x="Generated by `vis sync codeowners --write-guard`. Do not edit by hand.",le=e=>{const t=e.replace(/^\.?\/+/u,"").replace(/\/+$/u,"");return t===""||t==="."?"**":`${t}/**`},L=e=>{const t=new Set,o=[];for(const s of[...e].sort((n,r)=>n.name.localeCompare(r.name))){const n=le(s.root);t.has(n)||(t.add(n),o.push(n))}return o},pe=e=>{const t=L(e),o=t.map(n=>` - "${n}"`).join(`
|
|
7
|
+
`),s=t.map(n=>` ${n}`).join(`
|
|
8
|
+
`);return`# ${x}
|
|
9
|
+
name: Write Guard
|
|
10
|
+
|
|
11
|
+
on:
|
|
12
|
+
pull_request:
|
|
13
|
+
paths:
|
|
14
|
+
${o}
|
|
15
|
+
|
|
16
|
+
permissions:
|
|
17
|
+
contents: read
|
|
18
|
+
pull-requests: read
|
|
19
|
+
|
|
20
|
+
jobs:
|
|
21
|
+
write-guard:
|
|
22
|
+
runs-on: ubuntu-latest
|
|
23
|
+
steps:
|
|
24
|
+
- uses: actions/checkout@v4
|
|
25
|
+
with:
|
|
26
|
+
fetch-depth: 0
|
|
27
|
+
- uses: geritol/write-guard@v1
|
|
28
|
+
with:
|
|
29
|
+
codeowners: CODEOWNERS
|
|
30
|
+
paths: |
|
|
31
|
+
${s}
|
|
32
|
+
`},ue=e=>{const t=L(e).map(o=>` - "${o}/*"`).join(`
|
|
33
|
+
`);return`# ${x}
|
|
34
|
+
#
|
|
35
|
+
# SOFT GUARD ONLY — this job does NOT block a merge by itself.
|
|
36
|
+
# It verifies the generated CODEOWNERS is in sync and flags that a
|
|
37
|
+
# restricted path changed. GitLab CI cannot portably gate a merge on
|
|
38
|
+
# code-owner *approval* from a job, so REAL ENFORCEMENT REQUIRES the
|
|
39
|
+
# native GitLab setting:
|
|
40
|
+
# Settings -> Repository -> Protected branches ->
|
|
41
|
+
# "Require approval from Code Owners" (GitLab Premium / Ultimate)
|
|
42
|
+
# https://docs.gitlab.com/ee/user/project/codeowners/
|
|
43
|
+
# Without that setting enabled, this job is advisory only.
|
|
44
|
+
write-guard:
|
|
45
|
+
stage: test
|
|
46
|
+
image: node:22-alpine
|
|
47
|
+
rules:
|
|
48
|
+
- if: '$CI_PIPELINE_SOURCE == "merge_request_event"'
|
|
49
|
+
changes:
|
|
50
|
+
${t}
|
|
51
|
+
script:
|
|
52
|
+
- corepack enable
|
|
53
|
+
- pnpm install --frozen-lockfile
|
|
54
|
+
- pnpm vis sync codeowners --check
|
|
55
|
+
- >-
|
|
56
|
+
echo "SOFT GUARD: a restricted path changed. This job does NOT enforce
|
|
57
|
+
code-owner approval. Enable 'Require approval from Code Owners' on the
|
|
58
|
+
protected branch (GitLab Premium/Ultimate) for a real merge gate:
|
|
59
|
+
https://docs.gitlab.com/ee/user/project/codeowners/"
|
|
60
|
+
`},he=e=>e.length===0?[]:[{content:pe(e),path:".github/workflows/write-guard.yml"},{content:ue(e),path:".gitlab/write-guard.gitlab-ci.yml"}],D=new Set(["nested-codeowners","package-json-maintainers","project-json"]),A=(e,t,o)=>{const s=new Set,n=[];for(const r of e??[])for(const i of r.split(",")){const a=i.trim();if(a.length===0)continue;if(o&&!o(a))throw new Error(`Unknown codeowners source: "${a}". Known: ${[...D].join(", ")}.`);const c=a;s.has(c)||(s.add(c),n.push(c))}return n.length>0?n:[...t]},ge=e=>D.has(e),G=["codeowners","package-json-fields"],me=(e,t)=>t.some(o=>_(o,e)),we=async(e,t,o,s,n)=>{const r=Object.entries(s.projects).filter(([,a])=>a.restricted===!0).map(([a,c])=>({name:a,root:c.root??a})),i=he(r);if(i.length===0){t.info("No projects flagged `restricted: true` in project.json. Skipping Write Guard.");return}if(n){let a=!1;for(const c of i){const f=b(o,c.path);let h="";try{h=await e.readFile(f,"utf8")}catch(p){if(p.code!=="ENOENT")throw p}h.trim()!==c.content.trim()&&(t.error(`${c.path} is out of date. Run \`vis sync codeowners --write-guard\` to update it.`),a=!0)}a?process.exitCode=1:t.info(`Write Guard CI is up to date (${i.length} files, ${r.length} restricted projects).`);return}for(const a of i){const c=b(o,a.path);T(P(c)),I(c,a.content),t.info(`Wrote ${a.path}`)}t.info(`Write Guard CI scoped to ${r.length} restricted project${r.length===1?"":"s"}.`)},$e=async({fs:e,logger:t,options:o,visConfig:s,workspaceRoot:n})=>{const r=n,{workspace:i}=M(r,s),a=s?.codeowners;o.writeGuard===!0&&await we(e,t,r,i,o.check===!0);const c=A(o.from,a?.sources??["project-json"],ge),f=o.regenerationCommand??a?.regenerationCommand,h=o.preserveBlock===!0||a?.preserveBlock===!0,p=a?.blockMarker??O,$=o.nestedIncludes??a?.nestedIncludes,g=o.out??"CODEOWNERS",w=[];if(c.includes("nested-codeowners")){const m=await ne(r,$,g);for(const j of m)w.push({...j,source:"nested"})}if(c.includes("package-json-maintainers")){const m=ae(i,r);for(const j of m)w.push({...j,source:"maintainers"})}const l=c.includes("project-json")?v(i,a,w):v({projects:{}},a,w);if(l.length===0){t.info("No `owners` entries found in any source. Nothing to sync.");return}const y=b(r,g);let d="";try{d=await e.readFile(y,"utf8")}catch(m){if(m.code!=="ENOENT")throw m}const u={regenerationCommand:f},k=h?X(d,V(l,p,u),p):Q(l,u);if(o.check){if(d.trim()!==k.trim()){t.error(`${y} is out of date. Run \`vis sync codeowners\` to update it.`),process.exitCode=1;return}t.info(`${y} is up to date.`);return}I(y,k),t.info(`Wrote ${l.length} entries to ${y}`)},ke=({logger:e,options:t,visConfig:o,workspaceRoot:s})=>{const n=s,r=o?.editorconfig??!0,i=C(b(n,"package.json"));if(!i){e.error("Could not read root package.json. Nothing to sync."),process.exitCode=1;return}const a=A(t.fields,ie),c=t.ignorePackageName??[],f=t.check===!0,h=(t.format??"human").toLowerCase(),p=t.quiet===!0,$=J(n).filter(d=>d!=="."),g=[];let w=0;for(const d of $){const u=b(n,d,"package.json"),k=C(u);if(!k)continue;const m=typeof k.name=="string"?k.name:void 0;if(m!==void 0&&c.length>0&&me(m,c))continue;w+=1;const j=de(i,k,{fields:a});j.length!==0&&g.push({filePath:u,packageJsonPath:S(n,u),packageName:m,pkg:k,pkgChanges:j})}if(!f)for(const d of g)fe(d.pkg,d.pkgChanges),U(d.filePath,d.pkg,{indent:q(d.filePath,{useEditorconfig:r}),overwrite:!0});const l=g.flatMap(d=>d.pkgChanges.map(u=>({after:u.after,before:u.before,field:u.field,packageJsonPath:d.packageJsonPath,packageName:d.packageName}))),y={changes:l,fields:a,kind:"package-json-fields",mode:f?"check":"write",totalChanges:l.length,totalPackages:w};if(h==="json")process.stdout.write(`${JSON.stringify(y,null,4)}
|
|
61
|
+
`);else if(l.length===0)e.info(`All ${w} package${w===1?"":"s"} in sync (fields: ${a.join(", ")}).`);else if(f){if(!p)for(const d of l)e.error(`${d.packageJsonPath}: ${d.field} drifts from root`);e.error(`Found ${l.length} field drift${l.length===1?"":"s"} across ${g.length} package${g.length===1?"":"s"}. Run \`vis sync package-json-fields\` to fix.`)}else{if(!p)for(const d of g)e.info(`${d.packageJsonPath}: synced ${d.pkgChanges.map(u=>u.field).join(", ")}`);e.info(`Synced ${l.length} field${l.length===1?"":"s"} across ${g.length} package${g.length===1?"":"s"}.`)}f&&l.length>0&&(process.exitCode=1)},Oe=async e=>{const t=e.argument[0];if(!t)throw new Error(`Missing sync kind. Usage: vis sync <kind> (known kinds: ${G.join(", ")})`);if(!e.workspaceRoot)throw new Error("Could not determine workspace root. Run inside a monorepo.");if(t==="codeowners"){await $e(e);return}if(t==="package-json-fields"){ke(e);return}throw new Error(`Unknown sync kind: "${t}". Known kinds: ${G.join(", ")}.`)};export{Oe as default};
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import{createRequire as G}from"node:module";import{I as q,j as D,E as O,V as K,s as T,q as Q}from"../packem_shared/Table-CcVkyULl-B_ef6zfS.js";import{y as B}from"../packem_shared/index-BDmTbWX1.js";import{aJ as c,aK as X}from"./bin.js";import{d as k,f as v,r as Y,a as Z,b as ee,s as ne,c as te,e as ie,u as re,h as se,i as oe,j as ae,k as le,l as ce,m as de,n as ue,v as fe,w as ge,q as pe,t as me}from"../packem_shared/watch-loop-DWkvv2tK.js";const H=G(import.meta.url),w=typeof globalThis<"u"&&typeof globalThis.process<"u"?globalThis.process:process,U=e=>{if(typeof w<"u"&&w.versions&&w.versions.node){const[n,t]=w.versions.node.split(".").map(Number);if(n>22||n===22&&t>=3||n===20&&t>=16)return w.getBuiltinModule(e)}return H(e)},{createHash:y}=U("node:crypto"),he={1:"warning",2:"error"},xe={argsCheck:(e,n)=>J(e,n,!1),argsFix:(e,n)=>J(e,n,!0),bin:()=>["pnpm","exec","eslint"],cacheKey:(e,n)=>{const t=["eslint",e.declaredVersion??"unknown",e.configFile??"no-config",n.maxWarnings===void 0?"":`mw=${n.maxWarnings}`,n.quiet?"q":"",...n.extraArgs??[]];return y("sha256").update(t.join("|")).digest("hex").slice(0,16)},detect:(e,n)=>{const t=k(n,c.eslint.packageNames[0]),i=v(e,c.eslint.configFiles);if(!(!t&&!i))return{adapter:"eslint",configFile:i,declared:!!t,declaredVersion:t,root:e}},extensions:["cjs","cts","js","jsx","mjs","mts","ts","tsx","vue"],id:"eslint",kind:"lint",parse:(e,n)=>{if(!e.stdout.trim())return[];let t;try{t=JSON.parse(e.stdout)}catch{return[{adapter:"eslint",file:n.root,fixable:!1,message:`eslint output was not valid JSON (exit ${e.exitCode})`,severity:"error"}]}const i=[];for(const r of t)for(const s of r.messages)i.push({adapter:"eslint",column:s.column,endColumn:s.endColumn,endLine:s.endLine,file:r.filePath,fixable:!!s.fix,line:s.line,message:s.message,ruleId:s.ruleId??void 0,severity:s.fatal?"error":he[s.severity]??"warning"});return i}},J=(e,n,t)=>{const i=["--format","json","--no-error-on-unmatched-pattern"];return t&&i.push("--fix"),n.quiet&&i.push("--quiet"),typeof n.maxWarnings=="number"&&i.push("--max-warnings",String(n.maxWarnings)),n.extraArgs?.length&&i.push(...n.extraArgs),i.push(...e),i},we=/^([^:]+):(\d+)(?::(\d+))?\s+([\w/-]+)\s+(.+)$/,ke=e=>{const n=we.exec(e);if(!n)return;const[,t,i,r,s,a]=n;return{column:r===void 0?void 0:Number(r),file:t,line:Number(i),message:a,ruleId:s}},ve=e=>e.startsWith("/")||/^[a-z]:[\\/]/i.test(e),ye={argsCheck:(e,n)=>V(e,n,!1),argsFix:(e,n)=>V(e,n,!0),bin:()=>["pnpm","exec","markdownlint-cli2"],cacheKey:(e,n)=>{const t=["markdownlint",e.declaredVersion??"unknown",e.configFile??"no-config",n.maxWarnings===void 0?"":`mw=${n.maxWarnings}`,n.quiet?"q":"",...n.extraArgs??[]];return y("sha256").update(t.join("|")).digest("hex").slice(0,16)},detect:(e,n)=>{const t=c.markdownlint.packageNames.map(r=>k(n,r)).find(r=>r!==void 0),i=v(e,c.markdownlint.configFiles);if(!(!t&&!i))return{adapter:"markdownlint",configFile:i,declared:!!t,declaredVersion:t,root:e}},extensions:["markdown","md"],id:"markdownlint",kind:"lint",parse:(e,n)=>{const t=(e.stderr||e.stdout||"").trim();if(!t)return[];const i=[];for(const r of t.split(/\r?\n/)){const s=ke(r.trim());s&&i.push({adapter:"markdownlint",column:s.column,file:ve(s.file)?s.file:`${n.root}/${s.file}`,fixable:!0,line:s.line,message:s.message,ruleId:s.ruleId,severity:"warning"})}return i}},V=(e,n,t)=>{const i=[];return t&&i.push("--fix"),n.extraArgs?.length&&i.push(...n.extraArgs),e.length===0?i.push("**/*.md"):i.push(...e),i},$e={advice:"info",error:"error",warning:"warning"},be={argsCheck:(e,n)=>R(e,n,!1),argsFix:(e,n)=>R(e,n,!0),bin:()=>["pnpm","exec","oxlint"],cacheKey:(e,n)=>{const t=["oxlint",e.declaredVersion??"unknown",e.configFile??"no-config",n.maxWarnings===void 0?"":`mw=${n.maxWarnings}`,n.quiet?"q":"",...n.extraArgs??[]];return y("sha256").update(t.join("|")).digest("hex").slice(0,16)},detect:(e,n)=>{const t=k(n,c.oxlint.packageNames[0]),i=v(e,c.oxlint.configFiles);if(!(!t&&!i))return{adapter:"oxlint",configFile:i,declared:!!t,declaredVersion:t,root:e}},extensions:["astro","cjs","cts","js","jsx","mjs","mts","svelte","ts","tsx","vue"],id:"oxlint",kind:"lint",parse:(e,n)=>{if(!e.stdout.trim())return[];let t;try{t=JSON.parse(e.stdout)}catch{return[{adapter:"oxlint",file:n.root,fixable:!1,message:`oxlint output was not valid JSON (exit ${e.exitCode})`,severity:"error"}]}const i=[];for(const r of t.diagnostics??[]){const s=r.labels?.[0]?.span;i.push({adapter:"oxlint",column:s?.column,file:r.filename??n.root,fixable:!1,line:s?.line,message:r.message??"",ruleId:r.code,severity:$e[r.severity??""]??"warning"})}return i}},R=(e,n,t)=>{const i=["--format","json"];return t&&i.push("--fix"),n.quiet&&i.push("--quiet"),typeof n.maxWarnings=="number"&&i.push(`--max-warnings=${String(n.maxWarnings)}`),n.extraArgs?.length&&i.push(...n.extraArgs),i.push(...e),i},Ae={error:"error",info:"info",style:"info",warning:"warning"},Fe=e=>e.startsWith("/")||/^[a-z]:[\\/]/i.test(e),je=(e,n)=>e?Fe(e)?e:`${n}/${e}`:n,Ce={argsCheck:(e,n)=>L(e,n),argsFix:(e,n)=>L(e,n),bin:()=>["shellcheck"],cacheKey:(e,n)=>{const t=["shellcheck",e.declaredVersion??"unknown",e.configFile??"no-config",n.quiet?"q":"",...n.extraArgs??[]];return y("sha256").update(t.join("|")).digest("hex").slice(0,16)},detect:(e,n)=>{const t=k(n,c.shellcheck.packageNames[0]),i=v(e,c.shellcheck.configFiles);if(!(!t&&!i))return{adapter:"shellcheck",configFile:i,declared:!!t,declaredVersion:t,root:e}},extensions:["bash","ksh","sh"],id:"shellcheck",kind:"lint",parse:(e,n)=>{if(!e.stdout.trim())return[];let t;try{t=JSON.parse(e.stdout)}catch{return[{adapter:"shellcheck",file:n.root,fixable:!1,message:`shellcheck output was not valid JSON (exit ${e.exitCode})`,severity:"error"}]}const i=[];for(const r of t.comments??[])i.push({adapter:"shellcheck",column:r.column,endColumn:r.endColumn,endLine:r.endLine,file:je(r.file,n.root),fixable:!!r.fix,line:r.line,message:r.message??"",ruleId:r.code===void 0?void 0:`SC${String(r.code)}`,severity:Ae[r.level??""]??"warning"});return i}},L=(e,n)=>{const t=["--format=json1"];return n.extraArgs?.length&&t.push(...n.extraArgs),t.push(...e),t},Se={error:"error",warning:"warning"},qe={argsCheck:(e,n)=>M(e,n,!1),argsFix:(e,n)=>M(e,n,!0),bin:()=>["pnpm","exec","stylelint"],cacheKey:(e,n)=>{const t=["stylelint",e.declaredVersion??"unknown",e.configFile??"no-config",n.maxWarnings===void 0?"":`mw=${n.maxWarnings}`,n.quiet?"q":"",...n.extraArgs??[]];return y("sha256").update(t.join("|")).digest("hex").slice(0,16)},detect:(e,n)=>{const t=k(n,c.stylelint.packageNames[0]),i=v(e,c.stylelint.configFiles);if(!(!t&&!i))return{adapter:"stylelint",configFile:i,declared:!!t,declaredVersion:t,root:e}},extensions:["astro","css","less","sass","scss","svelte","vue"],id:"stylelint",kind:"lint",parse:(e,n)=>{if(!e.stdout.trim())return[];let t;try{t=JSON.parse(e.stdout)}catch{return[{adapter:"stylelint",file:n.root,fixable:!1,message:`stylelint output was not valid JSON (exit ${e.exitCode})`,severity:"error"}]}const i=[];for(const r of t)for(const s of r.warnings??[])i.push({adapter:"stylelint",column:s.column,endColumn:s.endColumn,endLine:s.endLine,file:r.source,fixable:!1,line:s.line,message:s.text??"",ruleId:s.rule,severity:Se[s.severity??""]??"warning"});return i}},M=(e,n,t)=>{const i=["--formatter","json"];return t&&i.push("--fix"),n.quiet&&i.push("--quiet"),typeof n.maxWarnings=="number"&&i.push("--max-warnings",String(n.maxWarnings)),n.extraArgs?.length&&i.push(...n.extraArgs),i.push(...e),i},We=[be,ue,xe,qe,fe,ye,Ce,ge],Te=async({logger:e,options:n,visConfig:t,workspaceRoot:i})=>{const r=i??process.cwd(),s=t?.lint,a=Y(We,s?.order),j=Z(r,a),d=ee(j,a,"lint").filter(({adapter:l})=>s?.adapters?.[l.id]?.enabled!==!1);if(d.length===0){e.warn("vis lint: no linter detected in this workspace (looked for: oxlint, biome, eslint, stylelint, ruff, markdownlint, shellcheck, deno).");return}const C=l=>{const u=s?.adapters?.[l]?.extraArgs;return u&&u.length>0?[...u]:void 0},$={extraArgs:void 0,maxWarnings:typeof n.maxWarnings=="number"?n.maxWarnings:void 0,quiet:n.quiet??!1},b=Ne(n),P=n.fix?"fix":"check";let f;if(n.staged){if(f=ne(r),f===void 0)e.warn("vis lint: could not resolve --staged (not a git repo or git unavailable). Falling back to a workspace-wide run.");else if(f.length===0){e.info(q("✓ lint: no staged files"));return}}else if(typeof n.since=="string"&&n.since.length>0){if(f=te(r,n.since),f===void 0)e.warn(`vis lint: could not resolve --since ${n.since} (not a git repo or unknown ref). Falling back to a workspace-wide run.`);else if(f.length===0){e.info(q(`✓ lint: no files changed since ${n.since}`));return}}const W=b.length>0?b:void 0,E=X(r,void 0,void 0,!0),S=n.format??"human";S==="human"&&n.output!==void 0&&e.warn("vis lint: --output is ignored for the human format; pass --format json|minimal|sarif|junit|github to redirect findings to a file.");const N=async l=>{const u=l!==void 0&&l.length>0&&W===void 0,m=[];for(const{adapter:o,presence:x}of d){let g;if(u){if(g=re(l,o.extensions),g.length===0)continue}else g=W??l??["."];const F=C(o.id),I={adapter:o,files:g,presence:x};F&&(I.options={...$,extraArgs:F}),m.push(I)}if(m.length===0)return;const z=await se(m,$,P,{cacheRoot:E}),A=m.map((o,x)=>{const g=z[x],F=o.adapter.parse(g,o.presence);return{adapter:o.adapter,durationMs:g.durationMs,exitCode:g.exitCode,findings:F}}),h=oe(A.map(o=>({adapter:o.adapter.id,durationMs:o.durationMs,exitCode:o.exitCode,findingCount:o.findings.length,findings:o.findings}))),p=S==="human"?void 0:ae({cwd:r,target:n.output});try{switch(S){case"github":{p.write(de({runs:A.map(o=>({findings:o.findings})),workspaceRoot:r}));break}case"json":{p.write(`${JSON.stringify({findings:h.findings,runs:h.runs},null,2)}
|
|
2
|
+
`);break}case"junit":{p.write(ce({runs:A.map(o=>({adapter:o.adapter.id,durationMs:o.durationMs,findings:o.findings})),workspaceRoot:r}));break}case"minimal":{Ie(h.findings,r,p);break}case"sarif":{p.write(le({runs:A.map(o=>({adapter:o.adapter.id,findings:o.findings,presence:m.find(x=>x.adapter.id===o.adapter.id)?.presence})),workspaceRoot:r}));break}default:_e(h.findings,r,e)}}finally{p?.close()}const _=me(h);_!==0&&(process.exitCode=_)};if(n.watch){const l=[...new Set(d.flatMap(({adapter:u})=>u.extensions))];await ie({extensions:l,initialFiles:f,label:"lint",log:u=>{e.info(u)},runCycle:N,workspaceRoot:r});return}await N(f)},Ne=e=>{const n=e;return[...n._??n.args??[]]},_e=(e,n,t)=>{if(e.length===0){t.info(q("✓ lint: no findings"));return}const i=pe(e);for(const[a,j]of i){t.info(D(B(n,a)));for(const d of j){const C=Oe(d),$=Je(d.severity),b=d.ruleId?O(` ${d.ruleId}`):"";t.info(` ${O(C)} ${$} ${d.message}${b}`)}}const r=e.filter(a=>a.severity==="error").length,s=e.filter(a=>a.severity==="warning").length;t.info(""),t.info(`${K(`${String(r)} error${r===1?"":"s"}`)}, ${T(`${String(s)} warning${s===1?"":"s"}`)}`)},Ie=(e,n,t)=>{for(const i of e){const r=B(n,i.file),s=i.line??"",a=i.column??"";t.write(`${i.adapter} ${r} ${String(s)} ${String(a)} ${i.severity} ${i.ruleId??""} ${i.message}
|
|
3
|
+
`)}},Oe=e=>e.line===void 0?"":e.column===void 0?String(e.line):`${String(e.line)}:${String(e.column)}`,Je=e=>e==="error"?K("error"):e==="warning"?T("warn "):Q("info ");export{Te as default};
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import{createRequire as z}from"node:module";import{y as L,v as _,m as P,f as M,J as V,B as Y}from"../packem_shared/index-BDmTbWX1.js";import{a4 as t,a5 as a,m as c,aE as K,aF as Q,aG as U,aD as Z,s as v,ae as ee,p as k,r as re,$ as te,d as se,t as ne,aN as oe,aO as ie,aP as le,i as ce,W as N}from"./bin.js";import ae from"./index.js";import{sortPackageJsonStringWithOptions as q}from"#native";import{c as O}from"../packem_shared/utils-Cxree603.js";const Ke=z(import.meta.url),Qe=typeof globalThis<"u"&&typeof globalThis.process<"u"?globalThis.process:process;const D={error:0,rewritten:1,"would-rewrite":1,unchanged:2},de=e=>[...e].sort((r,s)=>D[r.status]-D[s.status]),ue=(e,r)=>r==="all"?e:r==="errors"?e.filter(s=>s.status==="error"):r==="rewritten"?e.filter(s=>s.status==="rewritten"||s.status==="would-rewrite"):e.filter(s=>s.status==="unchanged");class fe{#e;#r=new Set;constructor(r){this.#e={entries:de(r),filterType:"all",focusedPanel:"list",selectedIndex:0}}getSnapshot=()=>this.#e;subscribe=r=>(this.#r.add(r),()=>{this.#r.delete(r)});getFilteredEntries=()=>ue(this.#e.entries,this.#e.filterType);#t(){this.#e={...this.#e};for(const r of this.#r)r()}select(r){const s=this.getFilteredEntries();this.#e.selectedIndex=s.length===0?-1:Math.max(0,Math.min(r,s.length-1)),this.#t()}selectStep(r){this.select(this.#e.selectedIndex+r)}setFilter(r){this.#e.filterType=r,this.#e.selectedIndex=0,this.#t()}setFocusedPanel(r){this.#e.focusedPanel=r,this.#t()}}const he=({checkMode:e,entry:r,focused:s,scrollRef:l})=>{const i=s?"white":"gray";return r?t.jsxs(a,{borderColor:i,borderStyle:"single",flexDirection:"column",flexGrow:1,children:[t.jsx(a,{flexShrink:0,paddingTop:1,paddingX:2,children:t.jsx(c,{bold:!0,color:"white",children:r.relativePath})}),t.jsxs(K,{flexGrow:1,flexShrink:1,paddingX:2,ref:l,scrollbar:!0,scrollbarColor:"gray",children:[t.jsx(c,{}),t.jsxs(a,{children:[t.jsx(a,{width:10,children:t.jsx(c,{dimColor:!0,children:"Status:"})}),r.status==="error"?t.jsx(c,{bold:!0,color:"red",children:"error"}):r.status==="unchanged"?t.jsx(c,{bold:!0,color:"green",children:"already sorted"}):r.status==="rewritten"?t.jsx(c,{bold:!0,color:"yellow",children:"rewritten"}):t.jsx(c,{bold:!0,color:"yellow",children:"would rewrite (--check)"})]}),t.jsxs(a,{children:[t.jsx(a,{width:10,children:t.jsx(c,{dimColor:!0,children:"Path:"})}),t.jsx(c,{children:r.filePath})]}),r.error?t.jsxs(t.Fragment,{children:[t.jsxs(a,{flexDirection:"column",marginTop:1,children:[t.jsx(c,{dimColor:!0,children:"── "}),t.jsx(c,{bold:!0,color:"red",children:"ERROR"}),t.jsxs(a,{flexDirection:"column",marginTop:1,paddingLeft:2,children:[t.jsxs(a,{children:[t.jsx(a,{width:10,children:t.jsx(c,{dimColor:!0,children:"Step:"})}),t.jsx(c,{color:"yellow",children:r.error.step})]}),r.error.context&&t.jsxs(a,{children:[t.jsx(a,{width:10,children:t.jsx(c,{dimColor:!0,children:"Position:"})}),t.jsx(c,{children:`line ${String(r.error.context.line)}, column ${String(r.error.context.column)}`})]}),t.jsx(a,{marginTop:1,children:t.jsx(c,{color:"red",children:r.error.message})})]})]}),r.error.context&&r.error.context.snippet.length>0&&t.jsxs(a,{flexDirection:"column",marginTop:1,children:[t.jsx(c,{dimColor:!0,children:"── "}),t.jsx(c,{bold:!0,color:"white",children:"SNIPPET"}),t.jsxs(a,{flexDirection:"column",marginTop:1,paddingLeft:2,children:[r.error.context.snippet.map(n=>{const o=`${n.isErrorLine?"❯":" "} ${String(n.lineNumber).padStart(4)} `;return t.jsxs(a,{children:[t.jsx(c,{color:n.isErrorLine?"red":"gray",children:o}),t.jsx(c,{color:n.isErrorLine?"white":"gray",wrap:"truncate-end",children:n.content||" "})]},n.lineNumber)}),r.error.context.column>0&&t.jsx(a,{children:t.jsx(c,{color:"red",children:`${" ".repeat(7+r.error.context.column-1)}↑`})})]})]})]}):t.jsxs(a,{flexDirection:"column",marginTop:1,children:[t.jsx(c,{dimColor:!0,children:"── "}),t.jsx(c,{bold:!0,color:"white",children:"KEY DIFF"}),t.jsx(a,{flexDirection:"column",marginTop:1,paddingLeft:2,children:r.diff.length===0?t.jsx(c,{dimColor:!0,children:"No top-level keys moved (sub-key reorder only)."}):r.diff.map(n=>{const o=n.toIndex-n.fromIndex,d=o<0?`↑ ${String(Math.abs(o))}`:`↓ ${String(o)}`,g=o<0?"green":"yellow";return t.jsxs(a,{children:[t.jsx(a,{width:28,children:t.jsx(c,{wrap:"truncate",children:n.key})}),t.jsx(a,{width:10,children:t.jsxs(c,{dimColor:!0,children:[String(n.fromIndex)," → ",String(n.toIndex)]})}),t.jsx(c,{color:g,children:d})]},n.key)})}),e&&r.status==="would-rewrite"&&t.jsx(a,{marginTop:1,paddingLeft:2,children:t.jsx(c,{dimColor:!0,children:"--check mode: no write performed."})})]})]})]}):t.jsx(a,{alignItems:"center",borderColor:"gray",borderStyle:"single",flexDirection:"column",flexGrow:1,justifyContent:"center",children:t.jsx(c,{dimColor:!0,children:"No entry selected"})})},ge={error:"red",rewritten:"yellow",unchanged:"green","would-rewrite":"yellow"},xe={error:"ERROR",rewritten:"REWROTE",unchanged:"SORTED","would-rewrite":"REWRITE"},H={error:"errors",rewritten:"rewrites",unchanged:"sorted","would-rewrite":"rewrites"},pe={errors:"Errors",rewrites:"Rewrites",sorted:"Sorted"},me=[{count:e=>e.errors+e.rewrites+e.sorted,key:"all",label:"All",shortcut:"1"},{count:e=>e.rewrites,key:"rewritten",label:"Rewrites",shortcut:"2"},{count:e=>e.errors,key:"errors",label:"Errors",shortcut:"3"},{count:e=>e.sorted,key:"unchanged",label:"Sorted",shortcut:"4"}],X=e=>{const r={errors:0,rewrites:0,sorted:0};for(const s of e)r[H[s.status]]++;return r},we=({entry:e,isSelected:r})=>{const s=ge[e.status],l=xe[e.status];return t.jsxs(a,{flexShrink:0,height:1,children:[t.jsx(c,{children:r?">":" "}),t.jsx(c,{children:" "}),t.jsx(c,{bold:!0,color:s,children:`[${l}]`.padEnd(10)}),t.jsx(c,{children:" "}),t.jsx(a,{flexGrow:1,children:t.jsx(c,{bold:r,inverse:r,wrap:"truncate",children:e.relativePath})}),e.status!=="error"&&e.diff.length>0&&t.jsx(c,{dimColor:!0,children:` ${String(e.diff.length)} key${e.diff.length===1?"":"s"}`})]})},je=({color:e,count:r,label:s})=>t.jsx(a,{flexShrink:0,height:1,children:t.jsx(c,{bold:!0,color:e,children:`${s} (${String(r)})`})}),ye=({counts:e,entries:r,filterType:s,focused:l,selectedIndex:i,totalEntries:n,viewportHeight:o})=>{const d=l?"white":"gray",g=X(r),m=(g.errors>0?1:0)+(g.rewrites>0?1:0)+(g.sorted>0?1:0),y=s==="all"&&m>1,h=[];let w;for(const[u,p]of r.entries()){const b=H[p.status];y&&b!==w&&(w!==void 0&&h.push({kind:"spacer"}),h.push({color:b==="errors"?"red":b==="rewrites"?"yellow":"green",count:g[b],kind:"header",label:pe[b]}),w=b),h.push({entry:p,entryIndex:u,kind:"entry"})}const x=h.findIndex(u=>u.kind==="entry"&&u.entryIndex===i),S=x!==-1,j=h.length,$=Math.max(0,j-o);let f=0;S&&o>0&&(f=Math.min($,Math.max(0,x-o+1)));const E=j>o&&o>0;return t.jsxs(a,{borderColor:d,borderStyle:"single",flexDirection:"column",flexGrow:1,children:[t.jsxs(a,{flexShrink:0,gap:1,paddingX:1,children:[t.jsx(c,{bold:!0,inverse:!0,children:" VIS SORT "}),t.jsxs(c,{wrap:"truncate",children:[n," ","file",n===1?"":"s"]})]}),t.jsx(a,{flexShrink:0,gap:1,paddingX:1,paddingY:1,children:me.map(u=>{const p=s===u.key,b=u.count(e);return t.jsxs(a,{children:[t.jsx(c,{dimColor:!p,children:"["}),t.jsx(c,{bold:p,color:p?"cyan":"gray",children:u.shortcut}),t.jsx(c,{dimColor:!p,children:"]"}),t.jsxs(c,{color:p?"white":"gray",children:[" ",u.label]}),t.jsxs(c,{dimColor:!0,children:[" ","(",b,")"]})]},u.key)})}),t.jsxs(a,{flexDirection:"row",flexGrow:1,overflow:"hidden",children:[t.jsx(a,{flexDirection:"column",flexGrow:1,overflow:"hidden",paddingLeft:1,children:t.jsx(a,{flexDirection:"column",marginTop:-f,children:h.map((u,p)=>u.kind==="spacer"?t.jsx(a,{flexShrink:0,height:1},`s-${String(p)}`):u.kind==="header"?t.jsx(je,{color:u.color,count:u.count,label:u.label},`h-${u.label}`):t.jsx(we,{entry:u.entry,isSelected:u.entryIndex===i},u.entry.filePath))})}),E&&t.jsx(a,{flexShrink:0,marginLeft:1,marginRight:1,children:t.jsx(Q,{contentHeight:j,placement:"inset",scrollOffset:f,style:"block",viewportHeight:o})})]})]})},be=100,A=10,ke=6,Se=1,F={1:"all",2:"rewritten",3:"errors",4:"unchanged"},$e=({checkMode:e,store:r})=>{const{exit:s}=U(),{columns:l,rows:i}=Z(),n=v.useSyncExternalStore(r.subscribe,r.getSnapshot),o=v.useRef(null),d=r.getFilteredEntries(),g=d[n.selectedIndex]??null,m=X(n.entries),y=l>=be,h=Math.max(0,i-Se),w=y?h:Math.floor(h/2),x=Math.max(0,w-ke),S=v.useCallback(()=>{s()},[s]),j=v.useRef(0),$=v.useRef(void 0),f=v.useRef(!1),E=v.useCallback((u,p)=>{j.current+=p,$.current=u,!f.current&&(f.current=!0,queueMicrotask(()=>{f.current=!1;const b=j.current,T=$.current;j.current=0,$.current=void 0,!(b===0||T===void 0)&&(T==="list"?r.selectStep(Math.sign(b)):o.current?.scrollBy(Math.sign(b)))}))},[r]);return ee((u,p)=>{if(u==="q"||p.escape){S();return}if(F[u]){r.setFilter(F[u]);return}if(p.tab){r.setFocusedPanel(n.focusedPanel==="list"?"detail":"list");return}n.focusedPanel==="list"?p.upArrow||u==="k"?E("list",-1):(p.downArrow||u==="j")&&E("list",1):n.focusedPanel==="detail"&&(p.upArrow||u==="k"?E("detail",-1):(p.downArrow||u==="j")&&E("detail",1))}),i<A?t.jsx(a,{alignItems:"center",justifyContent:"center",children:t.jsxs(c,{color:"yellow",children:["Terminal too small. Resize to at least",A," ","rows."]})}):t.jsxs(a,{flexDirection:"column",height:i,width:l,children:[t.jsxs(a,{flexDirection:y?"row":"column",flexGrow:1,children:[t.jsx(a,{flexBasis:"50%",flexGrow:1,flexShrink:1,children:t.jsx(ye,{counts:m,entries:d,filterType:n.filterType,focused:n.focusedPanel==="list",selectedIndex:n.selectedIndex,totalEntries:n.entries.length,viewportHeight:x})}),t.jsx(a,{flexBasis:"50%",flexGrow:1,flexShrink:1,children:t.jsx(he,{checkMode:e,entry:g,focused:n.focusedPanel==="detail",scrollRef:o})})]}),t.jsx(a,{flexShrink:0,paddingX:1,children:t.jsx(c,{dimColor:!0,children:"↑/↓ or j/k:navigate | tab:switch panel | 1-4:filter | q:quit"})})]})},B=["types","node-addons","node","import","require","default"],ve=/^git\+https:\/\/github\.com\/([^/]+)\/([^/.]+(?:\.git)?)$/,Ee=/^git\+ssh:\/\/git@github\.com\/([^/]+)\/([^/.]+(?:\.git)?)$/,C=e=>typeof e=="object"&&e!==null&&!Array.isArray(e),I=e=>{if(e===null||typeof e!="object")return e;if(Array.isArray(e))return e.map(s=>I(s));const r={};for(const[s,l]of Object.entries(e))r[s]=I(l);return r},Pe=e=>{if(!C(e))return{changed:!1,value:e};const r=Object.keys(e);return r.length===1&&r[0]==="url"&&typeof e.url=="string"?{changed:!0,value:e.url}:{changed:!1,value:e}},Oe=e=>e.endsWith(".git")?e.slice(0,-4):e,Ce=e=>{if(!C(e))return{changed:!1,value:e};if(typeof e.directory=="string"&&e.directory.length>0)return{changed:!1,value:e};const{type:r}=e;if(r!==void 0&&r!=="git")return{changed:!1,value:e};const{url:s}=e;if(typeof s!="string")return{changed:!1,value:e};const l=ve.exec(s)??Ee.exec(s);if(!l)return{changed:!1,value:e};const i=l[1],n=Oe(l[2]??"");if(!i||!n)return{changed:!1,value:e};const o=new Set(["type","url"]);for(const d of Object.keys(e))if(!o.has(d))return{changed:!1,value:e};return{changed:!0,value:`${i}/${n}`}},Re=e=>{const r=Object.keys(e),s=[],l=[];for(const o of B)Object.hasOwn(e,o)&&s.push(o);for(const o of r)B.includes(o)||l.push(o);const i=[...s,...l];if(i.length===r.length&&i.every((o,d)=>o===r[d]))return{changed:!1,value:e};const n={};for(const o of i)n[o]=e[o];return{changed:!0,value:n}},W=e=>{if(!C(e))return{changed:!1,value:e};let r=!1;const s={};for(const[i,n]of Object.entries(e)){const o=W(n);s[i]=o.value,o.changed&&(r=!0)}const l=Re(s);return{changed:r||l.changed,value:l.value}},Ie=(e,r)=>{const s=I(e);let l=!1;if(r.formatBugs!==!1&&Object.hasOwn(s,"bugs")){const i=Pe(s.bugs);i.changed&&(s.bugs=i.value,l=!0)}if(r.formatRepository!==!1&&Object.hasOwn(s,"repository")){const i=Ce(s.repository);i.changed&&(s.repository=i.value,l=!0)}if(r.sortExports!==!1&&Object.hasOwn(s,"exports")&&C(s.exports)){const i=W(s.exports);i.changed&&(s.exports=i.value,l=!0)}return{changed:l,pkg:s}},Te=/at position (\d+)/,Me=/\(?line (\d+) column (\d+)\)?/,Ne=e=>{const r=new Set,s=[],l=n=>{const o=Y(n);!r.has(o)&&M(o)&&(r.add(o),s.push(o))};l(P(e,"package.json"));const i=ce(e);if(i){const n=N(e,i);for(const o of n)l(P(e,o,"package.json"))}else{const n=P(e,"package.json");if(M(n)){const o=JSON.parse(_(n)),d=Array.isArray(o.workspaces)?o.workspaces:o.workspaces?.packages;if(d){const g=N(e,d);for(const m of g)l(P(e,m,"package.json"))}}}return s},De=e=>/\n([ \t]+)/.exec(e)?.[1]??" ",Ae=e=>{if(!(e===void 0||e===""))return e==="tab"||e===String.raw`\t`?" ":/^\d+$/.test(e)?" ".repeat(Number.parseInt(e,10)):e},R=e=>e===void 0?[]:(Array.isArray(e)?e:[e]).flatMap(r=>r.split(",")).map(r=>r.trim()).filter(r=>r.length>0),Fe=e=>e.includes(`\r
|
|
2
|
+
`)?"crlf":"lf",Be=new Set(["auto","crlf","lf"]),Ge=e=>{if(e===void 0||e==="")return"auto";if(Be.has(e))return e;throw new Error(`--line-ending must be one of: auto, lf, crlf (got "${e}")`)},Je=(e,r,s)=>r.length===0?e:e.filter(l=>{const i=L(s,l),n=V(l);return!r.some(o=>{const d=o.includes("/")?i:n;return ae(o,d)})}),Le=(e,r)=>{if(r.length===0)return e;const s={},l=new Set;for(const i of r)Object.hasOwn(e,i)&&(s[i]=e[i],l.add(i));for(const i of Object.keys(e))l.has(i)||(s[i]=e[i]);return s},_e=(e,r,s)=>{if(s.length===0)return e;const l={...e};for(const i of s)Object.hasOwn(r,i)&&(l[i]=r[i]);return l},qe=(e,r)=>{let s=1,l=1;const i=Math.min(r,e.length);for(let n=0;n<i;n++)e.codePointAt(n)===10?(s++,l=1):l++;return{column:l,line:s}},G=(e,r,s=2)=>{const l=e.split(`
|
|
3
|
+
`);if(r<1||r>l.length)return[];const i=Math.max(0,r-1-s),n=Math.min(l.length,r+s),o=[];for(let d=i;d<n;d++)o.push({content:l[d]??"",isErrorLine:d+1===r,lineNumber:d+1});return o},J=(e,r)=>{if(!(e instanceof Error))return;const s=Te.exec(e.message);if(s){const{column:i,line:n}=qe(r,Number.parseInt(s[1]??"0",10));return{column:i,line:n,snippet:G(r,n)}}const l=Me.exec(e.message);if(l){const i=Number.parseInt(l[1]??"1",10);return{column:Number.parseInt(l[2]??"1",10),line:i,snippet:G(r,i)}}},He=(e,r)=>{const s=Object.keys(JSON.parse(e)),l=Object.keys(JSON.parse(r)),i=new Map(s.map((o,d)=>[o,d])),n=[];for(const[o,d]of l.entries()){const g=i.get(d);g!==void 0&&g!==o&&n.push({fromIndex:g,key:d,toIndex:o})}return n},Xe=(e,r,s)=>{const l=r.indent??s.indent??De(e),i=r.lineEnding==="auto"?s.lineEnding??Fe(e):r.lineEnding,n=q(e,{pretty:!1,sortScripts:r.sortScripts});let o=JSON.parse(n);if(r.unsorted.length>0){const y=JSON.parse(e);o=_e(o,y,r.unsorted)}o=Le(o,r.sortOrder);const d={formatBugs:r.formatBugs,formatRepository:r.formatRepository,sortExports:r.sortExports},g=Ie(o,d);let m=JSON.stringify(g.pkg,null,l);return r.finalNewline&&(m+=`
|
|
4
|
+
`),i==="crlf"&&(m=m.replaceAll(`
|
|
5
|
+
`,`\r
|
|
6
|
+
`)),m},We=(e,r)=>{const s=Ne(e),l=ne(e),i=oe({cwd:e,extraPatterns:ie(l)}),n=s.filter(d=>!i.ignores(d)),o=Je(n,r,e);return{afterGitignore:n,allFiles:s,files:o}},ze=async(e,{checkMode:r,cwd:s,fs:l,normalized:i})=>{const n=L(s,e)||e;let o;try{o=_(e)}catch(h){return{diff:[],error:{message:O(h),step:"read"},filePath:e,relativePath:n,status:"error"}}let d;try{d=q(o,{pretty:!1,sortScripts:i.sortScripts})}catch(h){const w={message:O(h),step:"native-sort"},x=J(h,o);return x&&(w.context=x),{diff:[],error:w,filePath:e,relativePath:n,status:"error"}}const g=i.editorconfig?le(e):{};let m;try{m=Xe(o,i,g)}catch(h){const w={message:O(h),step:"json-parse"},x=J(h,o);return x&&(w.context=x),{diff:[],error:w,filePath:e,relativePath:n,status:"error"}}if(o===m)return{diff:[],filePath:e,relativePath:n,status:"unchanged"};let y;try{y=He(o,d)}catch{y=[]}if(r)return{diff:y,filePath:e,relativePath:n,status:"would-rewrite"};try{await l.writeFile(e,m,"utf8")}catch(h){return{diff:y,error:{message:O(h),step:"write"},filePath:e,relativePath:n,status:"error"}}return{diff:y,filePath:e,relativePath:n,status:"rewritten"}},Ve=e=>{if(e.error&&(k.error(`${e.filePath}: ${e.error.message}`),k.info(` step: ${e.error.step}`),e.error.context)){k.info(` at line ${String(e.error.context.line)}, column ${String(e.error.context.column)}`);for(const r of e.error.context.snippet){const s=r.isErrorLine?">":" ";k.info(` ${s} ${String(r.lineNumber).padStart(4)} | ${r.content}`)}}},sr=async({fs:e,options:r,visConfig:s,workspaceRoot:l})=>{const i=l??process.cwd(),n=s?.sortPackageJson,o=r.check||!1,d={editorconfig:r.editorconfig===!1?!1:n?.editorconfig??!0,finalNewline:r.finalNewline??n?.finalNewline??!0,formatBugs:r.formatBugs===!1?!1:n?.formatBugs??!0,formatRepository:r.formatRepository===!1?!1:n?.formatRepository??!0,ignore:[...R(r.ignore),...n?.ignore??[]],indent:Ae(r.indent??n?.indent),lineEnding:Ge(r.lineEnding??n?.lineEnding),sortExports:r.sortExports===!1?!1:n?.sortExports??!0,sortOrder:[...R(r.sortOrder),...n?.sortOrder??[]],sortScripts:r.sortScripts||n?.sortScripts||!1,unsorted:[...R(r.unsorted),...n?.unsorted??[]]},g=We(i,d.ignore),{afterGitignore:m,allFiles:y,files:h}=g;if(h.length===0){y.length===0?k.info("No package.json files found."):m.length===0?k.info("All package.json files were excluded by .gitignore or workspace exclusions."):k.info("All package.json files were excluded by --ignore.");return}const w=[];for(const f of h)w.push(await ze(f,{checkMode:o,cwd:i,fs:e,normalized:d}));let x=0,S=0,j=0;for(const f of w)f.status==="error"?j++:f.status==="rewritten"||f.status==="would-rewrite"?x++:S++;const $=x>0||j>0;if(process.stdout.isTTY&&!re&&$){const f=new fe(w);await te(se.createElement($e,{checkMode:o,store:f}),{alternateScreen:!0,exitOnCtrlC:!1,interactive:!0,patchConsole:!0}).waitUntilExit()}else for(const f of w)switch(f.status){case"error":{Ve(f);break}case"rewritten":{k.success(`Sorted ${f.filePath}`);break}case"would-rewrite":{k.warn(`${f.filePath} is not sorted`);break}}if(o)x>0?(k.info(`${String(x)} file${x===1?"":"s"} not sorted, ${String(S)} already sorted`),process.exitCode=1):j===0&&k.info(`All ${String(S)} package.json file${S===1?" is":"s are"} sorted`);else{const f=[];x>0&&f.push(`sorted ${String(x)} file${x===1?"":"s"}`),S>0&&f.push(`${String(S)} already sorted`),j>0&&f.push(`${String(j)} error${j===1?"":"s"}`),f.length>0&&k.info(f.join(", "))}j>0&&(process.exitCode=1)};export{G as buildSnippet,He as computeKeyDiff,qe as computeLineColumn,sr as default,We as discoverPackageJsonFiles,J as extractParseErrorContext,ze as processFile};
|