@capyclaw/publisher 0.0.0-stage → 0.1.3
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/README.md +112 -2
- package/client/client.js +717 -0
- package/cordis.patch.yml +13 -0
- package/icon.svg +6 -0
- package/locale/en.json +6 -0
- package/locale/zh.json +6 -0
- package/node_modules/@capyclaw/foundation/README.md +51 -0
- package/node_modules/@capyclaw/foundation/abi/bridge.mjs +86 -0
- package/node_modules/@capyclaw/foundation/abi/errors.mjs +63 -0
- package/node_modules/@capyclaw/foundation/abi/index.mjs +35 -0
- package/node_modules/@capyclaw/foundation/abi/kinds.mjs +271 -0
- package/node_modules/@capyclaw/foundation/abi/loader.mjs +345 -0
- package/node_modules/@capyclaw/foundation/abi/schema.mjs +98 -0
- package/node_modules/@capyclaw/foundation/abi/spec.mjs +255 -0
- package/node_modules/@capyclaw/foundation/abi/validate.mjs +24 -0
- package/node_modules/@capyclaw/foundation/abi/version.mjs +82 -0
- package/node_modules/@capyclaw/foundation/cordis.patch.yml +5 -0
- package/node_modules/@capyclaw/foundation/kit/index.mjs +6 -0
- package/node_modules/@capyclaw/foundation/lib/adapters/client-panel.mjs +98 -0
- package/node_modules/@capyclaw/foundation/lib/adapters/host-event.mjs +35 -0
- package/node_modules/@capyclaw/foundation/lib/adapters/http-router.mjs +69 -0
- package/node_modules/@capyclaw/foundation/lib/adapters/lifecycle-hook.mjs +55 -0
- package/node_modules/@capyclaw/foundation/lib/adapters/own-server.mjs +113 -0
- package/node_modules/@capyclaw/foundation/lib/adapters/raw.mjs +68 -0
- package/node_modules/@capyclaw/foundation/lib/adapters/runtime-driver.mjs +113 -0
- package/node_modules/@capyclaw/foundation/lib/adapters/service-provider.mjs +77 -0
- package/node_modules/@capyclaw/foundation/lib/adapters/skill-provider.mjs +56 -0
- package/node_modules/@capyclaw/foundation/lib/adapters/tool-provider.mjs +50 -0
- package/node_modules/@capyclaw/foundation/lib/adapters/ui-panel.mjs +64 -0
- package/node_modules/@capyclaw/foundation/lib/ctx-service.mjs +42 -0
- package/node_modules/@capyclaw/foundation/lib/host/caps.mjs +34 -0
- package/node_modules/@capyclaw/foundation/lib/host/contract.mjs +85 -0
- package/node_modules/@capyclaw/foundation/lib/host/dsh.mjs +50 -0
- package/node_modules/@capyclaw/foundation/lib/host/memory.mjs +160 -0
- package/node_modules/@capyclaw/foundation/lib/host.mjs +23 -0
- package/node_modules/@capyclaw/foundation/lib/kernel.mjs +185 -0
- package/node_modules/@capyclaw/foundation/lib/skill/scan.mjs +87 -0
- package/node_modules/@capyclaw/foundation/lib/subsystems/events.mjs +60 -0
- package/node_modules/@capyclaw/foundation/lib/subsystems/log.mjs +51 -0
- package/node_modules/@capyclaw/foundation/lib/subsystems/net.mjs +188 -0
- package/node_modules/@capyclaw/foundation/package.json +53 -0
- package/node_modules/@capyclaw/foundation/runtime/index.mjs +20 -0
- package/node_modules/@capyclaw/plugin-kit/INTEGRATION.md +100 -0
- package/node_modules/@capyclaw/plugin-kit/README.md +70 -0
- package/node_modules/@capyclaw/plugin-kit/bin/sync.mjs +103 -0
- package/node_modules/@capyclaw/plugin-kit/package.json +69 -0
- package/node_modules/@capyclaw/plugin-kit/src/cli.mjs +56 -0
- package/node_modules/@capyclaw/plugin-kit/src/config.mjs +142 -0
- package/node_modules/@capyclaw/plugin-kit/src/editor/heartbeat-worker.js +129 -0
- package/node_modules/@capyclaw/plugin-kit/src/editor/lease.mjs +139 -0
- package/node_modules/@capyclaw/plugin-kit/src/editor/shadow.mjs +219 -0
- package/node_modules/@capyclaw/plugin-kit/src/editor/transport.js +13 -0
- package/node_modules/@capyclaw/plugin-kit/src/index.mjs +13 -0
- package/node_modules/@capyclaw/plugin-kit/src/pack.mjs +230 -0
- package/node_modules/@capyclaw/plugin-kit/src/runtime/context.mjs +128 -0
- package/node_modules/@capyclaw/plugin-kit/src/self-contained.mjs +307 -0
- package/node_modules/@capyclaw/plugin-kit/src/service/api.mjs +45 -0
- package/node_modules/@capyclaw/plugin-kit/src/service/http.mjs +113 -0
- package/node_modules/@capyclaw/plugin-kit/src/service/mcp-http.mjs +150 -0
- package/node_modules/@capyclaw/plugin-kit/src/service/server.mjs +131 -0
- package/node_modules/@capyclaw/plugin-kit/src/skills/provider.mjs +82 -0
- package/node_modules/@capyclaw/plugin-kit/src/store/blob-store.mjs +109 -0
- package/node_modules/@capyclaw/plugin-kit/src/store/content-store.mjs +17 -0
- package/node_modules/@capyclaw/plugin-kit/src/store/journal-store.mjs +89 -0
- package/node_modules/@capyclaw/plugin-kit/src/tools/result.mjs +57 -0
- package/node_modules/@capyclaw/plugin-kit/src/tools/validate.mjs +150 -0
- package/node_modules/@capyclaw/plugin-kit/src/tuning.mjs +82 -0
- package/node_modules/@capyclaw/plugin-kit/src/util/fs-lock.mjs +132 -0
- package/node_modules/@capyclaw/plugin-kit/src/util/http.mjs +130 -0
- package/node_modules/@capyclaw/plugin-kit/src/workspace/manager.mjs +656 -0
- package/node_modules/@capyclaw/plugin-kit/src/zip.mjs +181 -0
- package/node_modules/@capyclaw/plugin-validator/bin/cli.mjs +49 -0
- package/node_modules/@capyclaw/plugin-validator/lib/index.mjs +303 -0
- package/node_modules/@capyclaw/plugin-validator/package.json +28 -0
- package/node_modules/@capyclaw/tool-host/README.md +56 -0
- package/node_modules/@capyclaw/tool-host/cordis.patch.yml +4 -0
- package/node_modules/@capyclaw/tool-host/dsh-suite.json +30 -0
- package/node_modules/@capyclaw/tool-host/lib/host.mjs +16 -0
- package/node_modules/@capyclaw/tool-host/package.json +59 -0
- package/node_modules/@capyclaw/tool-host/src/descriptors.mjs +166 -0
- package/node_modules/@capyclaw/tool-host/src/index.mjs +416 -0
- package/node_modules/semver/LICENSE +15 -0
- package/node_modules/semver/README.md +680 -0
- package/node_modules/semver/bin/semver.js +195 -0
- package/node_modules/semver/classes/comparator.js +143 -0
- package/node_modules/semver/classes/index.js +7 -0
- package/node_modules/semver/classes/range.js +577 -0
- package/node_modules/semver/classes/semver.js +350 -0
- package/node_modules/semver/functions/clean.js +8 -0
- package/node_modules/semver/functions/cmp.js +54 -0
- package/node_modules/semver/functions/coerce.js +62 -0
- package/node_modules/semver/functions/compare-build.js +9 -0
- package/node_modules/semver/functions/compare-loose.js +5 -0
- package/node_modules/semver/functions/compare.js +7 -0
- package/node_modules/semver/functions/diff.js +60 -0
- package/node_modules/semver/functions/eq.js +5 -0
- package/node_modules/semver/functions/gt.js +5 -0
- package/node_modules/semver/functions/gte.js +5 -0
- package/node_modules/semver/functions/inc.js +21 -0
- package/node_modules/semver/functions/lt.js +5 -0
- package/node_modules/semver/functions/lte.js +5 -0
- package/node_modules/semver/functions/major.js +5 -0
- package/node_modules/semver/functions/minor.js +5 -0
- package/node_modules/semver/functions/neq.js +5 -0
- package/node_modules/semver/functions/parse.js +18 -0
- package/node_modules/semver/functions/patch.js +5 -0
- package/node_modules/semver/functions/prerelease.js +8 -0
- package/node_modules/semver/functions/rcompare.js +5 -0
- package/node_modules/semver/functions/rsort.js +5 -0
- package/node_modules/semver/functions/satisfies.js +12 -0
- package/node_modules/semver/functions/sort.js +5 -0
- package/node_modules/semver/functions/truncate.js +48 -0
- package/node_modules/semver/functions/valid.js +8 -0
- package/node_modules/semver/index.js +93 -0
- package/node_modules/semver/internal/constants.js +67 -0
- package/node_modules/semver/internal/debug.js +11 -0
- package/node_modules/semver/internal/identifiers.js +29 -0
- package/node_modules/semver/internal/lrucache.js +42 -0
- package/node_modules/semver/internal/parse-options.js +17 -0
- package/node_modules/semver/internal/re.js +223 -0
- package/node_modules/semver/internal/trim-comparator-whitespace.js +438 -0
- package/node_modules/semver/package.json +78 -0
- package/node_modules/semver/preload.js +4 -0
- package/node_modules/semver/range.bnf +17 -0
- package/node_modules/semver/ranges/gtr.js +6 -0
- package/node_modules/semver/ranges/intersects.js +9 -0
- package/node_modules/semver/ranges/ltr.js +6 -0
- package/node_modules/semver/ranges/max-satisfying.js +27 -0
- package/node_modules/semver/ranges/min-satisfying.js +26 -0
- package/node_modules/semver/ranges/min-version.js +63 -0
- package/node_modules/semver/ranges/outside.js +82 -0
- package/node_modules/semver/ranges/simplify.js +49 -0
- package/node_modules/semver/ranges/subset.js +249 -0
- package/node_modules/semver/ranges/to-comparators.js +10 -0
- package/node_modules/semver/ranges/valid.js +13 -0
- package/node_modules/yaml/LICENSE +13 -0
- package/node_modules/yaml/README.md +172 -0
- package/node_modules/yaml/bin.mjs +11 -0
- package/node_modules/yaml/browser/dist/compose/compose-collection.js +88 -0
- package/node_modules/yaml/browser/dist/compose/compose-doc.js +43 -0
- package/node_modules/yaml/browser/dist/compose/compose-node.js +109 -0
- package/node_modules/yaml/browser/dist/compose/compose-scalar.js +86 -0
- package/node_modules/yaml/browser/dist/compose/composer.js +219 -0
- package/node_modules/yaml/browser/dist/compose/resolve-block-map.js +115 -0
- package/node_modules/yaml/browser/dist/compose/resolve-block-scalar.js +198 -0
- package/node_modules/yaml/browser/dist/compose/resolve-block-seq.js +49 -0
- package/node_modules/yaml/browser/dist/compose/resolve-end.js +37 -0
- package/node_modules/yaml/browser/dist/compose/resolve-flow-collection.js +207 -0
- package/node_modules/yaml/browser/dist/compose/resolve-flow-scalar.js +226 -0
- package/node_modules/yaml/browser/dist/compose/resolve-props.js +146 -0
- package/node_modules/yaml/browser/dist/compose/util-contains-newline.js +34 -0
- package/node_modules/yaml/browser/dist/compose/util-empty-scalar-position.js +26 -0
- package/node_modules/yaml/browser/dist/compose/util-flow-indent-check.js +15 -0
- package/node_modules/yaml/browser/dist/compose/util-map-includes.js +13 -0
- package/node_modules/yaml/browser/dist/doc/Document.js +335 -0
- package/node_modules/yaml/browser/dist/doc/anchors.js +71 -0
- package/node_modules/yaml/browser/dist/doc/applyReviver.js +55 -0
- package/node_modules/yaml/browser/dist/doc/createNode.js +88 -0
- package/node_modules/yaml/browser/dist/doc/directives.js +176 -0
- package/node_modules/yaml/browser/dist/errors.js +57 -0
- package/node_modules/yaml/browser/dist/index.js +17 -0
- package/node_modules/yaml/browser/dist/log.js +11 -0
- package/node_modules/yaml/browser/dist/nodes/Alias.js +118 -0
- package/node_modules/yaml/browser/dist/nodes/Collection.js +147 -0
- package/node_modules/yaml/browser/dist/nodes/Node.js +38 -0
- package/node_modules/yaml/browser/dist/nodes/Pair.js +36 -0
- package/node_modules/yaml/browser/dist/nodes/Scalar.js +24 -0
- package/node_modules/yaml/browser/dist/nodes/YAMLMap.js +144 -0
- package/node_modules/yaml/browser/dist/nodes/YAMLSeq.js +113 -0
- package/node_modules/yaml/browser/dist/nodes/addPairToJSMap.js +63 -0
- package/node_modules/yaml/browser/dist/nodes/identity.js +36 -0
- package/node_modules/yaml/browser/dist/nodes/toJS.js +37 -0
- package/node_modules/yaml/browser/dist/parse/cst-scalar.js +214 -0
- package/node_modules/yaml/browser/dist/parse/cst-stringify.js +61 -0
- package/node_modules/yaml/browser/dist/parse/cst-visit.js +97 -0
- package/node_modules/yaml/browser/dist/parse/cst.js +98 -0
- package/node_modules/yaml/browser/dist/parse/lexer.js +721 -0
- package/node_modules/yaml/browser/dist/parse/line-counter.js +39 -0
- package/node_modules/yaml/browser/dist/parse/parser.js +975 -0
- package/node_modules/yaml/browser/dist/public-api.js +102 -0
- package/node_modules/yaml/browser/dist/schema/Schema.js +37 -0
- package/node_modules/yaml/browser/dist/schema/common/map.js +17 -0
- package/node_modules/yaml/browser/dist/schema/common/null.js +15 -0
- package/node_modules/yaml/browser/dist/schema/common/seq.js +17 -0
- package/node_modules/yaml/browser/dist/schema/common/string.js +14 -0
- package/node_modules/yaml/browser/dist/schema/core/bool.js +19 -0
- package/node_modules/yaml/browser/dist/schema/core/float.js +43 -0
- package/node_modules/yaml/browser/dist/schema/core/int.js +38 -0
- package/node_modules/yaml/browser/dist/schema/core/schema.js +23 -0
- package/node_modules/yaml/browser/dist/schema/json/schema.js +62 -0
- package/node_modules/yaml/browser/dist/schema/tags.js +96 -0
- package/node_modules/yaml/browser/dist/schema/yaml-1.1/binary.js +58 -0
- package/node_modules/yaml/browser/dist/schema/yaml-1.1/bool.js +26 -0
- package/node_modules/yaml/browser/dist/schema/yaml-1.1/float.js +46 -0
- package/node_modules/yaml/browser/dist/schema/yaml-1.1/int.js +71 -0
- package/node_modules/yaml/browser/dist/schema/yaml-1.1/merge.js +67 -0
- package/node_modules/yaml/browser/dist/schema/yaml-1.1/omap.js +74 -0
- package/node_modules/yaml/browser/dist/schema/yaml-1.1/pairs.js +78 -0
- package/node_modules/yaml/browser/dist/schema/yaml-1.1/schema.js +39 -0
- package/node_modules/yaml/browser/dist/schema/yaml-1.1/set.js +93 -0
- package/node_modules/yaml/browser/dist/schema/yaml-1.1/timestamp.js +101 -0
- package/node_modules/yaml/browser/dist/stringify/foldFlowLines.js +146 -0
- package/node_modules/yaml/browser/dist/stringify/stringify.js +129 -0
- package/node_modules/yaml/browser/dist/stringify/stringifyCollection.js +153 -0
- package/node_modules/yaml/browser/dist/stringify/stringifyComment.js +20 -0
- package/node_modules/yaml/browser/dist/stringify/stringifyDocument.js +85 -0
- package/node_modules/yaml/browser/dist/stringify/stringifyNumber.js +25 -0
- package/node_modules/yaml/browser/dist/stringify/stringifyPair.js +150 -0
- package/node_modules/yaml/browser/dist/stringify/stringifyString.js +336 -0
- package/node_modules/yaml/browser/dist/util.js +11 -0
- package/node_modules/yaml/browser/dist/visit.js +233 -0
- package/node_modules/yaml/browser/index.js +5 -0
- package/node_modules/yaml/browser/package.json +3 -0
- package/node_modules/yaml/dist/cli.d.ts +8 -0
- package/node_modules/yaml/dist/cli.mjs +201 -0
- package/node_modules/yaml/dist/compose/compose-collection.d.ts +11 -0
- package/node_modules/yaml/dist/compose/compose-collection.js +90 -0
- package/node_modules/yaml/dist/compose/compose-doc.d.ts +7 -0
- package/node_modules/yaml/dist/compose/compose-doc.js +45 -0
- package/node_modules/yaml/dist/compose/compose-node.d.ts +29 -0
- package/node_modules/yaml/dist/compose/compose-node.js +112 -0
- package/node_modules/yaml/dist/compose/compose-scalar.d.ts +5 -0
- package/node_modules/yaml/dist/compose/compose-scalar.js +88 -0
- package/node_modules/yaml/dist/compose/composer.d.ts +63 -0
- package/node_modules/yaml/dist/compose/composer.js +224 -0
- package/node_modules/yaml/dist/compose/resolve-block-map.d.ts +6 -0
- package/node_modules/yaml/dist/compose/resolve-block-map.js +117 -0
- package/node_modules/yaml/dist/compose/resolve-block-scalar.d.ts +11 -0
- package/node_modules/yaml/dist/compose/resolve-block-scalar.js +200 -0
- package/node_modules/yaml/dist/compose/resolve-block-seq.d.ts +6 -0
- package/node_modules/yaml/dist/compose/resolve-block-seq.js +51 -0
- package/node_modules/yaml/dist/compose/resolve-end.d.ts +6 -0
- package/node_modules/yaml/dist/compose/resolve-end.js +39 -0
- package/node_modules/yaml/dist/compose/resolve-flow-collection.d.ts +7 -0
- package/node_modules/yaml/dist/compose/resolve-flow-collection.js +209 -0
- package/node_modules/yaml/dist/compose/resolve-flow-scalar.d.ts +10 -0
- package/node_modules/yaml/dist/compose/resolve-flow-scalar.js +228 -0
- package/node_modules/yaml/dist/compose/resolve-props.d.ts +23 -0
- package/node_modules/yaml/dist/compose/resolve-props.js +148 -0
- package/node_modules/yaml/dist/compose/util-contains-newline.d.ts +2 -0
- package/node_modules/yaml/dist/compose/util-contains-newline.js +36 -0
- package/node_modules/yaml/dist/compose/util-empty-scalar-position.d.ts +2 -0
- package/node_modules/yaml/dist/compose/util-empty-scalar-position.js +28 -0
- package/node_modules/yaml/dist/compose/util-flow-indent-check.d.ts +3 -0
- package/node_modules/yaml/dist/compose/util-flow-indent-check.js +17 -0
- package/node_modules/yaml/dist/compose/util-map-includes.d.ts +4 -0
- package/node_modules/yaml/dist/compose/util-map-includes.js +15 -0
- package/node_modules/yaml/dist/doc/Document.d.ts +141 -0
- package/node_modules/yaml/dist/doc/Document.js +337 -0
- package/node_modules/yaml/dist/doc/anchors.d.ts +24 -0
- package/node_modules/yaml/dist/doc/anchors.js +76 -0
- package/node_modules/yaml/dist/doc/applyReviver.d.ts +9 -0
- package/node_modules/yaml/dist/doc/applyReviver.js +57 -0
- package/node_modules/yaml/dist/doc/createNode.d.ts +17 -0
- package/node_modules/yaml/dist/doc/createNode.js +90 -0
- package/node_modules/yaml/dist/doc/directives.d.ts +49 -0
- package/node_modules/yaml/dist/doc/directives.js +178 -0
- package/node_modules/yaml/dist/errors.d.ts +21 -0
- package/node_modules/yaml/dist/errors.js +62 -0
- package/node_modules/yaml/dist/index.d.ts +25 -0
- package/node_modules/yaml/dist/index.js +50 -0
- package/node_modules/yaml/dist/log.d.ts +3 -0
- package/node_modules/yaml/dist/log.js +19 -0
- package/node_modules/yaml/dist/nodes/Alias.d.ts +29 -0
- package/node_modules/yaml/dist/nodes/Alias.js +120 -0
- package/node_modules/yaml/dist/nodes/Collection.d.ts +73 -0
- package/node_modules/yaml/dist/nodes/Collection.js +151 -0
- package/node_modules/yaml/dist/nodes/Node.d.ts +53 -0
- package/node_modules/yaml/dist/nodes/Node.js +40 -0
- package/node_modules/yaml/dist/nodes/Pair.d.ts +22 -0
- package/node_modules/yaml/dist/nodes/Pair.js +39 -0
- package/node_modules/yaml/dist/nodes/Scalar.d.ts +47 -0
- package/node_modules/yaml/dist/nodes/Scalar.js +27 -0
- package/node_modules/yaml/dist/nodes/YAMLMap.d.ts +53 -0
- package/node_modules/yaml/dist/nodes/YAMLMap.js +147 -0
- package/node_modules/yaml/dist/nodes/YAMLSeq.d.ts +60 -0
- package/node_modules/yaml/dist/nodes/YAMLSeq.js +115 -0
- package/node_modules/yaml/dist/nodes/addPairToJSMap.d.ts +4 -0
- package/node_modules/yaml/dist/nodes/addPairToJSMap.js +65 -0
- package/node_modules/yaml/dist/nodes/identity.d.ts +23 -0
- package/node_modules/yaml/dist/nodes/identity.js +53 -0
- package/node_modules/yaml/dist/nodes/toJS.d.ts +29 -0
- package/node_modules/yaml/dist/nodes/toJS.js +39 -0
- package/node_modules/yaml/dist/options.d.ts +350 -0
- package/node_modules/yaml/dist/parse/cst-scalar.d.ts +64 -0
- package/node_modules/yaml/dist/parse/cst-scalar.js +218 -0
- package/node_modules/yaml/dist/parse/cst-stringify.d.ts +8 -0
- package/node_modules/yaml/dist/parse/cst-stringify.js +63 -0
- package/node_modules/yaml/dist/parse/cst-visit.d.ts +39 -0
- package/node_modules/yaml/dist/parse/cst-visit.js +99 -0
- package/node_modules/yaml/dist/parse/cst.d.ts +109 -0
- package/node_modules/yaml/dist/parse/cst.js +112 -0
- package/node_modules/yaml/dist/parse/lexer.d.ts +87 -0
- package/node_modules/yaml/dist/parse/lexer.js +723 -0
- package/node_modules/yaml/dist/parse/line-counter.d.ts +22 -0
- package/node_modules/yaml/dist/parse/line-counter.js +41 -0
- package/node_modules/yaml/dist/parse/parser.d.ts +84 -0
- package/node_modules/yaml/dist/parse/parser.js +980 -0
- package/node_modules/yaml/dist/public-api.d.ts +44 -0
- package/node_modules/yaml/dist/public-api.js +107 -0
- package/node_modules/yaml/dist/schema/Schema.d.ts +17 -0
- package/node_modules/yaml/dist/schema/Schema.js +39 -0
- package/node_modules/yaml/dist/schema/common/map.d.ts +2 -0
- package/node_modules/yaml/dist/schema/common/map.js +19 -0
- package/node_modules/yaml/dist/schema/common/null.d.ts +4 -0
- package/node_modules/yaml/dist/schema/common/null.js +17 -0
- package/node_modules/yaml/dist/schema/common/seq.d.ts +2 -0
- package/node_modules/yaml/dist/schema/common/seq.js +19 -0
- package/node_modules/yaml/dist/schema/common/string.d.ts +2 -0
- package/node_modules/yaml/dist/schema/common/string.js +16 -0
- package/node_modules/yaml/dist/schema/core/bool.d.ts +4 -0
- package/node_modules/yaml/dist/schema/core/bool.js +21 -0
- package/node_modules/yaml/dist/schema/core/float.d.ts +4 -0
- package/node_modules/yaml/dist/schema/core/float.js +47 -0
- package/node_modules/yaml/dist/schema/core/int.d.ts +4 -0
- package/node_modules/yaml/dist/schema/core/int.js +42 -0
- package/node_modules/yaml/dist/schema/core/schema.d.ts +1 -0
- package/node_modules/yaml/dist/schema/core/schema.js +25 -0
- package/node_modules/yaml/dist/schema/json/schema.d.ts +2 -0
- package/node_modules/yaml/dist/schema/json/schema.js +64 -0
- package/node_modules/yaml/dist/schema/json-schema.d.ts +69 -0
- package/node_modules/yaml/dist/schema/tags.d.ts +48 -0
- package/node_modules/yaml/dist/schema/tags.js +99 -0
- package/node_modules/yaml/dist/schema/types.d.ts +92 -0
- package/node_modules/yaml/dist/schema/yaml-1.1/binary.d.ts +2 -0
- package/node_modules/yaml/dist/schema/yaml-1.1/binary.js +70 -0
- package/node_modules/yaml/dist/schema/yaml-1.1/bool.d.ts +7 -0
- package/node_modules/yaml/dist/schema/yaml-1.1/bool.js +29 -0
- package/node_modules/yaml/dist/schema/yaml-1.1/float.d.ts +4 -0
- package/node_modules/yaml/dist/schema/yaml-1.1/float.js +50 -0
- package/node_modules/yaml/dist/schema/yaml-1.1/int.d.ts +5 -0
- package/node_modules/yaml/dist/schema/yaml-1.1/int.js +76 -0
- package/node_modules/yaml/dist/schema/yaml-1.1/merge.d.ts +9 -0
- package/node_modules/yaml/dist/schema/yaml-1.1/merge.js +71 -0
- package/node_modules/yaml/dist/schema/yaml-1.1/omap.d.ts +22 -0
- package/node_modules/yaml/dist/schema/yaml-1.1/omap.js +77 -0
- package/node_modules/yaml/dist/schema/yaml-1.1/pairs.d.ts +10 -0
- package/node_modules/yaml/dist/schema/yaml-1.1/pairs.js +82 -0
- package/node_modules/yaml/dist/schema/yaml-1.1/schema.d.ts +1 -0
- package/node_modules/yaml/dist/schema/yaml-1.1/schema.js +41 -0
- package/node_modules/yaml/dist/schema/yaml-1.1/set.d.ts +28 -0
- package/node_modules/yaml/dist/schema/yaml-1.1/set.js +96 -0
- package/node_modules/yaml/dist/schema/yaml-1.1/timestamp.d.ts +6 -0
- package/node_modules/yaml/dist/schema/yaml-1.1/timestamp.js +105 -0
- package/node_modules/yaml/dist/stringify/foldFlowLines.d.ts +34 -0
- package/node_modules/yaml/dist/stringify/foldFlowLines.js +151 -0
- package/node_modules/yaml/dist/stringify/stringify.d.ts +21 -0
- package/node_modules/yaml/dist/stringify/stringify.js +132 -0
- package/node_modules/yaml/dist/stringify/stringifyCollection.d.ts +17 -0
- package/node_modules/yaml/dist/stringify/stringifyCollection.js +155 -0
- package/node_modules/yaml/dist/stringify/stringifyComment.d.ts +10 -0
- package/node_modules/yaml/dist/stringify/stringifyComment.js +24 -0
- package/node_modules/yaml/dist/stringify/stringifyDocument.d.ts +4 -0
- package/node_modules/yaml/dist/stringify/stringifyDocument.js +87 -0
- package/node_modules/yaml/dist/stringify/stringifyNumber.d.ts +2 -0
- package/node_modules/yaml/dist/stringify/stringifyNumber.js +27 -0
- package/node_modules/yaml/dist/stringify/stringifyPair.d.ts +3 -0
- package/node_modules/yaml/dist/stringify/stringifyPair.js +152 -0
- package/node_modules/yaml/dist/stringify/stringifyString.d.ts +9 -0
- package/node_modules/yaml/dist/stringify/stringifyString.js +338 -0
- package/node_modules/yaml/dist/test-events.d.ts +4 -0
- package/node_modules/yaml/dist/test-events.js +134 -0
- package/node_modules/yaml/dist/util.d.ts +16 -0
- package/node_modules/yaml/dist/util.js +28 -0
- package/node_modules/yaml/dist/visit.d.ts +102 -0
- package/node_modules/yaml/dist/visit.js +236 -0
- package/node_modules/yaml/package.json +97 -0
- package/node_modules/yaml/util.js +2 -0
- package/package.json +78 -4
- package/plugin.mjs +113 -0
- package/server/archive.mjs +255 -0
- package/server/drop.mjs +498 -0
- package/server/impl.mjs +609 -0
- package/server/routes.mjs +339 -0
- package/server/tools.mjs +111 -0
package/server/drop.mjs
ADDED
|
@@ -0,0 +1,498 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 拖拽发布引擎:压缩包 → 解包目录 → 版本规划 → npm publish。
|
|
3
|
+
*
|
|
4
|
+
* 与 impl.mjs 的分工:impl.mjs 面向「仓库工作区」,按发现集批量发布,负责闸门/顺序/漂移;
|
|
5
|
+
* 这里面向「一个从浏览器拖进来的包」,只有一条路径:预检 → 定版本 → 发布 → 复核。
|
|
6
|
+
* 复数实现(release CLI)不重复:发布闸、密钥扫描直接复用 impl.mjs 的导出。
|
|
7
|
+
*/
|
|
8
|
+
import fs from 'node:fs'
|
|
9
|
+
import path from 'node:path'
|
|
10
|
+
import { spawn } from 'node:child_process'
|
|
11
|
+
|
|
12
|
+
import { publishGateErrors } from './impl.mjs'
|
|
13
|
+
import { inspectArchive, materialize, storeRoot, unpack } from './archive.mjs'
|
|
14
|
+
|
|
15
|
+
export const MAX_ARCHIVE_BYTES = 32 * 1024 * 1024
|
|
16
|
+
export const MAX_ENTRIES = 4096
|
|
17
|
+
|
|
18
|
+
const NPM_CLI = path.join(path.dirname(process.execPath), 'node_modules', 'npm', 'bin', 'npm-cli.js')
|
|
19
|
+
const SEMVER_RE = /^(\d+)\.(\d+)\.(\d+)(?:-([0-9A-Za-z.-]+))?(?:\+[0-9A-Za-z.-]+)?$/
|
|
20
|
+
|
|
21
|
+
/* 密钥扫描:只扫「作者自己的文件」,跳过 node_modules 与 .git。
|
|
22
|
+
* dist 产物里带着 139 个第三方包,扫它们既慢又会把别人的测试夹具当成本包泄漏。 */
|
|
23
|
+
const SECRET_PATTERNS = [
|
|
24
|
+
[/sk-[A-Za-z0-9]{20,}/, 'API key 形态(sk-…)'],
|
|
25
|
+
[/npm_[A-Za-z0-9]{20,}/, 'npm token 形态(npm_…)'],
|
|
26
|
+
[new RegExp('_auth' + 'Token', 'i'), 'npmrc 认证令牌字段'],
|
|
27
|
+
[/[A-Za-z]:\\Users\\/i, '本机绝对路径(盘符 \\Users\\)'],
|
|
28
|
+
[/\/(home|Users)\/[A-Za-z0-9._-]+\//, '本机绝对路径(/home/ 或 /Users/)'],
|
|
29
|
+
]
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* 跑一次 npm(异步);优先用当前 Node 自带的 npm-cli.js,找不到再退回 PATH 上的 npm。
|
|
33
|
+
*
|
|
34
|
+
* 必须是异步的:npm 一次调用要几百毫秒起步,网络差时能挂十几秒。用 spawnSync 会把宿主
|
|
35
|
+
* 整个事件循环钉住——插件页、聊天流、健康探活全部一起卡死。超时会杀掉子进程,返回
|
|
36
|
+
* status -2,调用方按普通失败处理。
|
|
37
|
+
*/
|
|
38
|
+
export function npmRun(args, options = {}) {
|
|
39
|
+
const { timeout = 180000, cwd, env } = options
|
|
40
|
+
const command = fs.existsSync(NPM_CLI)
|
|
41
|
+
? { file: process.execPath, args: [NPM_CLI, ...args], shell: false }
|
|
42
|
+
: { file: 'npm', args, shell: process.platform === 'win32' }
|
|
43
|
+
|
|
44
|
+
return new Promise((resolve) => {
|
|
45
|
+
let stdout = ''
|
|
46
|
+
let stderr = ''
|
|
47
|
+
let settled = false
|
|
48
|
+
let timer = null
|
|
49
|
+
let child = null
|
|
50
|
+
|
|
51
|
+
const finish = (status) => {
|
|
52
|
+
if (settled) return
|
|
53
|
+
settled = true
|
|
54
|
+
if (timer) clearTimeout(timer)
|
|
55
|
+
resolve({ status, stdout, stderr })
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
try {
|
|
59
|
+
child = spawn(command.file, command.args, {
|
|
60
|
+
cwd,
|
|
61
|
+
env: { ...process.env, ...env },
|
|
62
|
+
shell: command.shell,
|
|
63
|
+
windowsHide: true,
|
|
64
|
+
stdio: ['ignore', 'pipe', 'pipe'],
|
|
65
|
+
})
|
|
66
|
+
} catch (error) {
|
|
67
|
+
finish(-1)
|
|
68
|
+
stderr = messageOf(error)
|
|
69
|
+
return
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
child.stdout?.setEncoding('utf8')
|
|
73
|
+
child.stderr?.setEncoding('utf8')
|
|
74
|
+
child.stdout?.on('data', (chunk) => { stdout += chunk })
|
|
75
|
+
child.stderr?.on('data', (chunk) => { stderr += chunk })
|
|
76
|
+
child.on('error', (error) => {
|
|
77
|
+
stderr += messageOf(error)
|
|
78
|
+
finish(-1)
|
|
79
|
+
})
|
|
80
|
+
child.on('close', (code) => finish(typeof code === 'number' ? code : -1))
|
|
81
|
+
|
|
82
|
+
timer = setTimeout(() => {
|
|
83
|
+
stderr += `npm 调用超过 ${Math.round(timeout / 1000)}s,已终止。`
|
|
84
|
+
try { child.kill() } catch { /* 已经退出 */ }
|
|
85
|
+
finish(-2)
|
|
86
|
+
}, timeout)
|
|
87
|
+
})
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
const delay = (ms) => new Promise((resolve) => { setTimeout(resolve, ms) })
|
|
91
|
+
|
|
92
|
+
// ---------------------------------------------------------------------------
|
|
93
|
+
// 版本
|
|
94
|
+
// ---------------------------------------------------------------------------
|
|
95
|
+
|
|
96
|
+
/** 解析 x.y.z[-pre];非严格语义版本返回 null(预发布段不比较,直接按需升 patch)。 */
|
|
97
|
+
export function parseVersion(value) {
|
|
98
|
+
const match = SEMVER_RE.exec(String(value || '').trim())
|
|
99
|
+
if (!match) return null
|
|
100
|
+
return {
|
|
101
|
+
major: Number(match[1]),
|
|
102
|
+
minor: Number(match[2]),
|
|
103
|
+
patch: Number(match[3]),
|
|
104
|
+
prerelease: match[4] || '',
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
/** 只比较 x.y.z 三段;预发布段不参与(发布场景只需要「谁更新」)。 */
|
|
109
|
+
export function compareVersions(left, right) {
|
|
110
|
+
const a = parseVersion(left)
|
|
111
|
+
const b = parseVersion(right)
|
|
112
|
+
if (!a || !b) return 0
|
|
113
|
+
for (const key of ['major', 'minor', 'patch']) {
|
|
114
|
+
if (a[key] !== b[key]) return a[key] > b[key] ? 1 : -1
|
|
115
|
+
}
|
|
116
|
+
return 0
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
/** 补丁位 +1 并丢掉预发布段:0.1.1 → 0.1.2,1.0.0-rc.1 → 1.0.1。 */
|
|
120
|
+
export function bumpPatch(version) {
|
|
121
|
+
const parsed = parseVersion(version)
|
|
122
|
+
if (!parsed) throw new Error(`无法递增版本:${version} 不是 x.y.z 形态。`)
|
|
123
|
+
return `${parsed.major}.${parsed.minor}.${parsed.patch + 1}`
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
export function maxVersion(versions) {
|
|
127
|
+
let best = null
|
|
128
|
+
for (const version of versions) {
|
|
129
|
+
if (!parseVersion(version)) continue
|
|
130
|
+
if (!best || compareVersions(version, best) > 0) best = version
|
|
131
|
+
}
|
|
132
|
+
return best
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
/**
|
|
136
|
+
* 本次要发布的版本。
|
|
137
|
+
* first —— npm 上还没有这个包:按包内版本直接发
|
|
138
|
+
* ahead —— 包内版本已经比 npm 最新版更新:按包内版本发
|
|
139
|
+
* bump —— 包内版本 ≤ npm 最新版(重复发布同一版本会被 npm 拒):latest 的 patch + 1
|
|
140
|
+
*/
|
|
141
|
+
export function planVersion(manifestVersion, published) {
|
|
142
|
+
const versions = Array.isArray(published?.versions) ? published.versions : []
|
|
143
|
+
const latest = published?.latest || maxVersion(versions)
|
|
144
|
+
if (versions.length === 0) return { mode: 'first', version: manifestVersion, latest: null }
|
|
145
|
+
if (compareVersions(manifestVersion, latest) > 0) return { mode: 'ahead', version: manifestVersion, latest }
|
|
146
|
+
return { mode: 'bump', version: bumpPatch(latest), latest }
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
/**
|
|
150
|
+
* registry 版本查询缓存。
|
|
151
|
+
*
|
|
152
|
+
* 一次「拖入 → 预检 → 发布」会两次问 npm(prepare 里规划版本,publish 前重跑闸门),
|
|
153
|
+
* 每次 `npm view` 在 Windows 上要 1–3 秒。缓存 15 秒既让第二次几乎瞬回,又短到
|
|
154
|
+
* 不会把「刚发的版本」藏住;发布成功与失败都会主动失效该包。
|
|
155
|
+
*/
|
|
156
|
+
const PUBLISHED_TTL_MS = 15000
|
|
157
|
+
const publishedCache = new Map()
|
|
158
|
+
|
|
159
|
+
/** 清掉某个包(或全部)的版本缓存;发布前后各调一次。 */
|
|
160
|
+
export function forgetPublished(name) {
|
|
161
|
+
if (name) publishedCache.delete(name)
|
|
162
|
+
else publishedCache.clear()
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
/** 读 npm 上的版本集合;包不存在不算错误(第一次发布)。 */
|
|
166
|
+
export async function readPublished(name, { timeout = 60000, npm = npmRun, cacheTtlMs = PUBLISHED_TTL_MS } = {}) {
|
|
167
|
+
const cached = publishedCache.get(name)
|
|
168
|
+
if (cached && Date.now() - cached.at < cacheTtlMs) return cached.value
|
|
169
|
+
|
|
170
|
+
const value = await queryPublished(name, { timeout, npm })
|
|
171
|
+
if (value.ok) publishedCache.set(name, { at: Date.now(), value })
|
|
172
|
+
return value
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
async function queryPublished(name, { timeout, npm }) {
|
|
176
|
+
const result = await npm(['view', name, 'versions', 'dist-tags', '--json'], { timeout })
|
|
177
|
+
if (result.status === 0) {
|
|
178
|
+
try {
|
|
179
|
+
const parsed = JSON.parse(String(result.stdout || '{}'))
|
|
180
|
+
const versions = Array.isArray(parsed?.versions)
|
|
181
|
+
? parsed.versions
|
|
182
|
+
: parsed?.versions
|
|
183
|
+
? [parsed.versions]
|
|
184
|
+
: []
|
|
185
|
+
const latest = parsed?.['dist-tags']?.latest || null
|
|
186
|
+
return { ok: true, found: true, versions, latest }
|
|
187
|
+
} catch {
|
|
188
|
+
return { ok: false, found: false, versions: [], latest: null, message: 'npm view 输出不可解析。' }
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
const stderr = String(result.stderr || result.stdout || '')
|
|
192
|
+
if (/E404|404 Not Found|is not in this registry/i.test(stderr)) {
|
|
193
|
+
return { ok: true, found: false, versions: [], latest: null }
|
|
194
|
+
}
|
|
195
|
+
return { ok: false, found: false, versions: [], latest: null, message: firstLine(stderr) }
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
// ---------------------------------------------------------------------------
|
|
199
|
+
// staging
|
|
200
|
+
// ---------------------------------------------------------------------------
|
|
201
|
+
|
|
202
|
+
/** 上传字节 → 解包 → 落到本机 staging,返回包目录与事实。 */
|
|
203
|
+
export async function stageUpload(buffer, filename) {
|
|
204
|
+
const entries = unpack(buffer, filename)
|
|
205
|
+
if (entries.length === 0) throw new Error('压缩包里没有任何文件。')
|
|
206
|
+
if (entries.length > MAX_ENTRIES) {
|
|
207
|
+
throw new Error(`压缩包里的文件太多(${entries.length} 个),上限 ${MAX_ENTRIES}。`)
|
|
208
|
+
}
|
|
209
|
+
const fact = inspectArchive(entries)
|
|
210
|
+
const dir = await materialize(entries, fact.dir)
|
|
211
|
+
try {
|
|
212
|
+
/* package.json 能解析、能读出来,才算一次成功的 prepare;
|
|
213
|
+
* 读失败就地回收,否则 staging 会变成一个没人认领的目录。 */
|
|
214
|
+
return { dir, entries, manifest: readManifest(dir), name: fact.name }
|
|
215
|
+
} catch (error) {
|
|
216
|
+
cleanupStage({ dir })
|
|
217
|
+
throw error
|
|
218
|
+
}
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
export function readManifest(dir) {
|
|
222
|
+
const file = path.join(dir, 'package.json')
|
|
223
|
+
if (!fs.existsSync(file)) throw new Error('解包后找不到 package.json。')
|
|
224
|
+
return JSON.parse(fs.readFileSync(file, 'utf8'))
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
/** 读 staging 目录的事实与预检结果(不改文件)。 */
|
|
228
|
+
export async function previewStage(stage, { npm = npmRun, cacheTtlMs } = {}) {
|
|
229
|
+
const pkg = readManifest(stage.dir)
|
|
230
|
+
const published = await readPublished(pkg.name, cacheTtlMs === undefined ? { npm } : { npm, cacheTtlMs })
|
|
231
|
+
if (!published.ok) {
|
|
232
|
+
return {
|
|
233
|
+
ok: false,
|
|
234
|
+
error: 'registry-unreachable',
|
|
235
|
+
message: `读不到 npm 上 ${pkg.name} 的版本:${published.message || '未知错误'}`,
|
|
236
|
+
}
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
const plan = planVersion(String(pkg.version || ''), published)
|
|
240
|
+
const blocking = publishGateErrors(pkg, stage.dir)
|
|
241
|
+
const warnings = []
|
|
242
|
+
|
|
243
|
+
if (plan.mode === 'bump') {
|
|
244
|
+
warnings.push(`包内版本 ${pkg.version} 与 npm 最新版相同或更旧,本次按 ${plan.version} 发布(patch +1)。`)
|
|
245
|
+
}
|
|
246
|
+
if (compareVersions(plan.version, published.latest || '0.0.0') <= 0 && plan.mode !== 'first') {
|
|
247
|
+
blocking.push(`目标版本 ${plan.version} 不高于 npm 最新版 ${published.latest},npm 会拒绝重复发布。`)
|
|
248
|
+
}
|
|
249
|
+
const hasNodeModules = fs.existsSync(path.join(stage.dir, 'node_modules'))
|
|
250
|
+
if (!hasNodeModules && pkg.dependencies && Object.keys(pkg.dependencies).length > 0) {
|
|
251
|
+
warnings.push('压缩包里没有 node_modules:发布后使用方安装时会从 registry 解析依赖(不是自包含产物)。')
|
|
252
|
+
}
|
|
253
|
+
for (const hit of scanOwnFiles(stage.dir)) blocking.push(`疑似密钥/本机信息:${hit}`)
|
|
254
|
+
|
|
255
|
+
return {
|
|
256
|
+
ok: true,
|
|
257
|
+
token: stage.token,
|
|
258
|
+
name: pkg.name,
|
|
259
|
+
version: String(pkg.version || ''),
|
|
260
|
+
plan,
|
|
261
|
+
latest: published.latest || null,
|
|
262
|
+
versions: published.versions.length,
|
|
263
|
+
files: stage.entries.filter((entry) => !entry.dir).length,
|
|
264
|
+
private: pkg.private === true,
|
|
265
|
+
hasNodeModules,
|
|
266
|
+
blocking,
|
|
267
|
+
warnings,
|
|
268
|
+
description: typeof pkg.description === 'string' ? pkg.description : '',
|
|
269
|
+
stagedDir: stage.dir,
|
|
270
|
+
}
|
|
271
|
+
}
|
|
272
|
+
|
|
273
|
+
/**
|
|
274
|
+
* 落地并规划:浏览器一次拖拽 = 一次 prepare。
|
|
275
|
+
* token 是后续 publish 的唯一句柄,客户端不需要知道本机路径。
|
|
276
|
+
*/
|
|
277
|
+
export async function prepareUpload({ token, buffer, filename }, { npm = npmRun, cacheTtlMs } = {}) {
|
|
278
|
+
const stage = await stageUpload(buffer, filename)
|
|
279
|
+
stage.token = token
|
|
280
|
+
try {
|
|
281
|
+
const preview = await previewStage(stage, cacheTtlMs === undefined ? { npm } : { npm, cacheTtlMs })
|
|
282
|
+
return { stage, preview }
|
|
283
|
+
} catch (error) {
|
|
284
|
+
cleanupStage(stage)
|
|
285
|
+
throw error
|
|
286
|
+
}
|
|
287
|
+
}
|
|
288
|
+
|
|
289
|
+
/** 写回目标版本(只改 version 字段,保留其余字段与缩进风格)。 */
|
|
290
|
+
export function applyVersion(dir, version) {
|
|
291
|
+
const pkg = readManifest(dir)
|
|
292
|
+
pkg.version = version
|
|
293
|
+
fs.writeFileSync(path.join(dir, 'package.json'), `${JSON.stringify(pkg, null, 2)}\n`, 'utf8')
|
|
294
|
+
return pkg
|
|
295
|
+
}
|
|
296
|
+
|
|
297
|
+
/**
|
|
298
|
+
* 真发布:写版本 → npm publish → 回读 registry 复核。
|
|
299
|
+
* 不可撤销,所以任何一步失败都原样带回 npm 的 stderr 尾巴。
|
|
300
|
+
*/
|
|
301
|
+
export async function publishStage(stage, {
|
|
302
|
+
version, tag = 'latest', dryRun = false, npm = npmRun, verifyAttempts = 10, verifyDelayMs = 1500,
|
|
303
|
+
} = {}) {
|
|
304
|
+
const pkg = applyVersion(stage.dir, version)
|
|
305
|
+
forgetPublished(pkg.name)
|
|
306
|
+
const args = ['publish', '--tag', tag, '--json']
|
|
307
|
+
if (String(pkg.name).startsWith('@') || pkg.publishConfig?.access) args.push('--access', pkg.publishConfig?.access || 'public')
|
|
308
|
+
if (dryRun) args.push('--dry-run')
|
|
309
|
+
|
|
310
|
+
const startedAt = Date.now()
|
|
311
|
+
const result = await npm(args, { cwd: stage.dir })
|
|
312
|
+
if (result.status !== 0) {
|
|
313
|
+
const raw = String(result.stderr || result.stdout || '')
|
|
314
|
+
const friendly = friendlyNpmFailure(raw)
|
|
315
|
+
return {
|
|
316
|
+
ok: false,
|
|
317
|
+
error: dryRun ? 'dry-run-failed' : (friendly?.error || 'publish-failed'),
|
|
318
|
+
message: friendly?.message || firstLine(raw) || `npm publish 退出码 ${result.status}`,
|
|
319
|
+
detail: tailLines(raw, 12),
|
|
320
|
+
elapsedMs: Date.now() - startedAt,
|
|
321
|
+
}
|
|
322
|
+
}
|
|
323
|
+
|
|
324
|
+
if (dryRun) {
|
|
325
|
+
return {
|
|
326
|
+
ok: true,
|
|
327
|
+
dryRun: true,
|
|
328
|
+
name: pkg.name,
|
|
329
|
+
version,
|
|
330
|
+
tag,
|
|
331
|
+
elapsedMs: Date.now() - startedAt,
|
|
332
|
+
}
|
|
333
|
+
}
|
|
334
|
+
|
|
335
|
+
for (let attempt = 0; attempt < verifyAttempts; attempt += 1) {
|
|
336
|
+
const check = await npm(['view', `${pkg.name}@${version}`, 'version'], { timeout: 30000 })
|
|
337
|
+
if (check.status === 0 && String(check.stdout).trim().startsWith(version)) {
|
|
338
|
+
forgetPublished(pkg.name)
|
|
339
|
+
return {
|
|
340
|
+
ok: true,
|
|
341
|
+
name: pkg.name,
|
|
342
|
+
version,
|
|
343
|
+
tag,
|
|
344
|
+
verified: true,
|
|
345
|
+
url: `https://www.npmjs.com/package/${pkg.name}/v/${version}`,
|
|
346
|
+
elapsedMs: Date.now() - startedAt,
|
|
347
|
+
}
|
|
348
|
+
}
|
|
349
|
+
await delay(verifyDelayMs)
|
|
350
|
+
}
|
|
351
|
+
|
|
352
|
+
/*
|
|
353
|
+
* npm 退出码 0 = registry 已经收下这个 tarball。回读只是「顺手复核」,
|
|
354
|
+
* 节点同步慢时查不到并不代表发布失败——所以这里报成功 + 未核实,别吓用户。
|
|
355
|
+
*/
|
|
356
|
+
forgetPublished(pkg.name)
|
|
357
|
+
return {
|
|
358
|
+
ok: true,
|
|
359
|
+
name: pkg.name,
|
|
360
|
+
version,
|
|
361
|
+
tag,
|
|
362
|
+
verified: false,
|
|
363
|
+
url: `https://www.npmjs.com/package/${pkg.name}/v/${version}`,
|
|
364
|
+
warning: `${pkg.name}@${version} 已提交发布,但 registry 暂时还查不到(同步通常要几十秒)。稍后用 npm view 复核即可。`,
|
|
365
|
+
elapsedMs: Date.now() - startedAt,
|
|
366
|
+
}
|
|
367
|
+
}
|
|
368
|
+
|
|
369
|
+
/**
|
|
370
|
+
* 发布完成(成功或彻底失败)后回收 staging 目录。
|
|
371
|
+
*
|
|
372
|
+
* 包目录可能只是 staging 的子目录(压缩包里带一层 `pkg/` 时就是这样),
|
|
373
|
+
* 所以这里删的是「staging 根下那一次上传」而不是包目录本身,否则时间戳目录会留下来。
|
|
374
|
+
*/
|
|
375
|
+
export function cleanupStage(stage) {
|
|
376
|
+
const target = stage?.base || stageBaseOf(stage?.dir)
|
|
377
|
+
if (!target) return
|
|
378
|
+
try {
|
|
379
|
+
fs.rmSync(target, { recursive: true, force: true })
|
|
380
|
+
} catch { /* 回收失败不影响结论 */ }
|
|
381
|
+
}
|
|
382
|
+
|
|
383
|
+
/** 沿着 dir 往上找,直到父目录就是 staging 根;返回那一次上传的目录。 */
|
|
384
|
+
function stageBaseOf(dir) {
|
|
385
|
+
if (!dir) return null
|
|
386
|
+
const root = path.resolve(storeRoot())
|
|
387
|
+
let current = path.resolve(dir)
|
|
388
|
+
if (current !== root && !current.startsWith(root + path.sep)) return current
|
|
389
|
+
while (current !== root && path.dirname(current) !== root) {
|
|
390
|
+
const parent = path.dirname(current)
|
|
391
|
+
if (parent === current) break
|
|
392
|
+
current = parent
|
|
393
|
+
}
|
|
394
|
+
return current === root ? null : current
|
|
395
|
+
}
|
|
396
|
+
|
|
397
|
+
/**
|
|
398
|
+
* 回收「进程里已经没有记录」的 staging 目录。
|
|
399
|
+
*
|
|
400
|
+
* 崩溃或重启之后 stages 这张表是空的,磁盘上那些时间戳目录就再也没人认领,
|
|
401
|
+
* 会一直堆在 %LOCALAPPDATA%\capyclaw-publisher\drop 里。这里按目录 mtime 判断年龄,
|
|
402
|
+
* 只删超过 ttl 且不在 keep 列表里的。
|
|
403
|
+
*/
|
|
404
|
+
export async function sweepOrphans(keep = new Set(), ttlMs = 2 * 60 * 60 * 1000) {
|
|
405
|
+
const root = path.resolve(storeRoot())
|
|
406
|
+
const keepSet = new Set([...keep].map((item) => path.resolve(item)))
|
|
407
|
+
let names
|
|
408
|
+
try {
|
|
409
|
+
names = await fs.promises.readdir(root)
|
|
410
|
+
} catch {
|
|
411
|
+
return 0
|
|
412
|
+
}
|
|
413
|
+
const cutoff = Date.now() - ttlMs
|
|
414
|
+
let removed = 0
|
|
415
|
+
for (const name of names) {
|
|
416
|
+
const full = path.join(root, name)
|
|
417
|
+
if (keepSet.has(full)) continue
|
|
418
|
+
let stat
|
|
419
|
+
try {
|
|
420
|
+
stat = await fs.promises.stat(full)
|
|
421
|
+
} catch {
|
|
422
|
+
continue
|
|
423
|
+
}
|
|
424
|
+
if (stat.mtimeMs > cutoff) continue
|
|
425
|
+
try {
|
|
426
|
+
await fs.promises.rm(full, { recursive: true, force: true })
|
|
427
|
+
removed += 1
|
|
428
|
+
} catch { /* 删不掉就算了,下次再说 */ }
|
|
429
|
+
}
|
|
430
|
+
return removed
|
|
431
|
+
}
|
|
432
|
+
|
|
433
|
+
function scanOwnFiles(root) {
|
|
434
|
+
const hits = []
|
|
435
|
+
const skip = new Set(['node_modules', '.git'])
|
|
436
|
+
const walk = (dir, depth) => {
|
|
437
|
+
if (depth > 8) return
|
|
438
|
+
let entries = []
|
|
439
|
+
try { entries = fs.readdirSync(dir, { withFileTypes: true }) } catch { return }
|
|
440
|
+
for (const entry of entries) {
|
|
441
|
+
if (entry.isDirectory()) {
|
|
442
|
+
if (skip.has(entry.name)) continue
|
|
443
|
+
walk(path.join(dir, entry.name), depth + 1)
|
|
444
|
+
continue
|
|
445
|
+
}
|
|
446
|
+
const file = path.join(dir, entry.name)
|
|
447
|
+
let text = null
|
|
448
|
+
try { text = fs.readFileSync(file, 'utf8') } catch { continue }
|
|
449
|
+
for (const [pattern, label] of SECRET_PATTERNS) {
|
|
450
|
+
if (pattern.test(text)) hits.push(`${path.relative(root, file)}: ${label}`)
|
|
451
|
+
}
|
|
452
|
+
}
|
|
453
|
+
}
|
|
454
|
+
walk(root, 0)
|
|
455
|
+
return [...new Set(hits)]
|
|
456
|
+
}
|
|
457
|
+
|
|
458
|
+
function firstLine(text) {
|
|
459
|
+
return String(text || '').trim().split(/\r?\n/).filter(Boolean)[0] || ''
|
|
460
|
+
}
|
|
461
|
+
|
|
462
|
+
/*
|
|
463
|
+
* npm 的原始报错对用户太吵:几种最常见的失败换成能直接照做的话,
|
|
464
|
+
* 其余保持原样(stderr 首行 + detail 里的尾巴仍然给出来)。
|
|
465
|
+
*/
|
|
466
|
+
function friendlyNpmFailure(raw) {
|
|
467
|
+
const text = String(raw || '')
|
|
468
|
+
if (/cannot publish over the previously published versions|previously published version/i.test(text)) {
|
|
469
|
+
return {
|
|
470
|
+
error: 'version-exists',
|
|
471
|
+
message: '这个版本号已经在 npm 上了。把包里的 version 改高一点,或重新拖进来让发布器自动 +1。',
|
|
472
|
+
}
|
|
473
|
+
}
|
|
474
|
+
if (/one-time password|EOTP|two-factor/i.test(text)) {
|
|
475
|
+
return {
|
|
476
|
+
error: 'otp-required',
|
|
477
|
+
message: 'npm 要求两步验证码。到 npm 账号设置里开启 2FA 后,用带 OTP 的终端发布,或先关掉该包的 2FA 要求。',
|
|
478
|
+
}
|
|
479
|
+
}
|
|
480
|
+
if (/ENEEDAUTH|need auth|not authenticated/i.test(text)) {
|
|
481
|
+
return {
|
|
482
|
+
error: 'not-authenticated',
|
|
483
|
+
message: 'npm 不认当前身份。在宿主机执行 npm login,或设置 NODE_AUTH_TOKEN 后重启 DSH。',
|
|
484
|
+
}
|
|
485
|
+
}
|
|
486
|
+
if (/EPUBLISHCONFLICT/i.test(text)) {
|
|
487
|
+
return {
|
|
488
|
+
error: 'version-exists',
|
|
489
|
+
message: '这个版本号已经被占用(可能是别人刚发的)。换一个更高的版本再试。',
|
|
490
|
+
}
|
|
491
|
+
}
|
|
492
|
+
return null
|
|
493
|
+
}
|
|
494
|
+
|
|
495
|
+
function tailLines(text, count) {
|
|
496
|
+
const lines = String(text || '').trim().split(/\r?\n/).filter(Boolean)
|
|
497
|
+
return lines.slice(-count).join('\n')
|
|
498
|
+
}
|