diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index a5db575..9a6469d 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -44,9 +44,6 @@ jobs: if: steps.npm-cache.outputs.cache-hit != 'true' env: XDG_CACHE_HOME: .cache - - run: npm run postinstall - env: - XDG_CACHE_HOME: .cache - run: npm test - name: Build run: node scripts/build.js diff --git a/.github/workflows/pr.yml b/.github/workflows/pr.yml index 5829942..5bda6be 100644 --- a/.github/workflows/pr.yml +++ b/.github/workflows/pr.yml @@ -44,9 +44,6 @@ jobs: if: steps.npm-cache.outputs.cache-hit != 'true' env: XDG_CACHE_HOME: .cache - - run: npm run postinstall - env: - XDG_CACHE_HOME: .cache - run: npm test - name: Build run: node scripts/build.js diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index b95a117..aaa3021 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -76,9 +76,6 @@ jobs: if: steps.npm-cache.outputs.cache-hit != 'true' env: XDG_CACHE_HOME: .cache - - run: npm run postinstall - env: - XDG_CACHE_HOME: .cache - run: npm test - run: node scripts/build.js - run: npm publish --access public diff --git a/README.md b/README.md index 3858b5a..c5fcf98 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ A module for using [ripgrep](https://github.com/BurntSushi/ripgrep/) in a Node project. -Same as [vscode-ripgrep](https://github.com/microsoft/vscode-ripgrep), but fixes the github rate limiting error `Downloading ripgrep failed: Error: Request failed: 403` by downloading the files directly instead of also using the github rest api. +This package re-exports `rgPath` from [vscode-ripgrep](https://github.com/microsoft/vscode-ripgrep). ## Install @@ -21,13 +21,6 @@ const childProcess = spawn(rgPath, ['abc', '.'], { }) ``` -## Environment Variables - -- `RIPGREP_PREBUILT_BINARIES_MIRROR`: Specify a custom mirror URL for downloading ripgrep prebuilt binaries. This is useful for users in regions where GitHub releases are slow or inaccessible, or for organizations using internal mirrors. - - **Default**: `https://github.com/microsoft/ripgrep-prebuilt/releases/download` - - **Example**: `export RIPGREP_PREBUILT_BINARIES_MIRROR=https://your-mirror.com/ripgrep-prebuilt/releases/download` - - **Note**: The mirror URL should follow the same path structure as the official repository, with binaries available at `{mirror-url}/{version}/ripgrep-{version}-{target}` - ## Credits This project is very much based on https://github.com/microsoft/vscode-ripgrep by Microsoft. diff --git a/package-lock.json b/package-lock.json index 653f6bd..aaabcc9 100644 --- a/package-lock.json +++ b/package-lock.json @@ -7,26 +7,17 @@ "": { "name": "@lvce-editor/ripgrep", "version": "0.0.0-dev", - "hasInstallScript": true, "license": "MIT", "dependencies": { - "@lvce-editor/verror": "^1.7.0", - "@vscode/ripgrep": "^1.18.0", - "execa": "^9.6.1", - "extract-zip": "^2.0.1", - "fs-extra": "^11.3.5", - "path-exists": "^5.0.0", - "tempy": "^3.2.0", - "xdg-basedir": "^5.1.0" + "@vscode/ripgrep": "^1.18.0" }, "devDependencies": { "@lvce-editor/eslint-config": "^11.2.0", - "@types/fs-extra": "^11.0.4", "@types/jest": "^30.0.0", "@types/node": "^25.9.3", "eslint": "^10.5.0", + "execa": "^9.6.1", "jest": "^30.4.2", - "nock": "^14.0.15", "prettier": "^3.8.4", "typescript": "^6.0.3" }, @@ -2095,30 +2086,6 @@ "@eslint/json": "2.0.0" } }, - "node_modules/@lvce-editor/verror": { - "version": "1.7.0", - "resolved": "https://registry.npmjs.org/@lvce-editor/verror/-/verror-1.7.0.tgz", - "integrity": "sha512-+LGuAEIC2L7pbvkyAQVWM2Go0dAy+UWEui28g07zNtZsCBhm+gusBK8PNwLJLV5Jay+TyUYuwLIbJdjLLzqEBg==", - "license": "MIT" - }, - "node_modules/@mswjs/interceptors": { - "version": "0.41.9", - "resolved": "https://registry.npmjs.org/@mswjs/interceptors/-/interceptors-0.41.9.tgz", - "integrity": "sha512-VVPPgHyQ6ShqnrmDWuxjmUIsO9gWyOZFmuOfLd9LfBGQJwZfy0gvv9pbHSJuoFNIYC7ZDX9aoFwowjcdSC4E8w==", - "dev": true, - "license": "MIT", - "dependencies": { - "@open-draft/deferred-promise": "^2.2.0", - "@open-draft/logger": "^0.3.0", - "@open-draft/until": "^2.0.0", - "is-node-process": "^1.2.0", - "outvariant": "^1.4.3", - "strict-event-emitter": "^0.5.1" - }, - "engines": { - "node": ">=18" - } - }, "node_modules/@napi-rs/wasm-runtime": { "version": "1.1.5", "resolved": "https://registry.npmjs.org/@napi-rs/wasm-runtime/-/wasm-runtime-1.1.5.tgz", @@ -2138,31 +2105,6 @@ "@emnapi/runtime": "^1.7.1" } }, - "node_modules/@open-draft/deferred-promise": { - "version": "2.2.0", - "resolved": "https://registry.npmjs.org/@open-draft/deferred-promise/-/deferred-promise-2.2.0.tgz", - "integrity": "sha512-CecwLWx3rhxVQF6V4bAgPS5t+So2sTbPgAzafKkVizyi7tlwpcFpdFqq+wqF2OwNBmqFuu6tOyouTuxgpMfzmA==", - "dev": true, - "license": "MIT" - }, - "node_modules/@open-draft/logger": { - "version": "0.3.0", - "resolved": "https://registry.npmjs.org/@open-draft/logger/-/logger-0.3.0.tgz", - "integrity": "sha512-X2g45fzhxH238HKO4xbSr7+wBS8Fvw6ixhTDuvLd5mqh6bJJCFAPwU9mPDxbcrRtfxv4u5IHCEH77BmxvXmmxQ==", - "dev": true, - "license": "MIT", - "dependencies": { - "is-node-process": "^1.2.0", - "outvariant": "^1.4.0" - } - }, - "node_modules/@open-draft/until": { - "version": "2.1.0", - "resolved": "https://registry.npmjs.org/@open-draft/until/-/until-2.1.0.tgz", - "integrity": "sha512-U69T3ItWHvLwGg5eJ0n3I62nWuE6ilHlmz7zM0npLBRvPRd7e6NYmg54vvRtP5mZG7kZqZCFVdsTWo7BPtBujg==", - "dev": true, - "license": "MIT" - }, "node_modules/@ota-meshi/ast-token-store": { "version": "0.3.0", "resolved": "https://registry.npmjs.org/@ota-meshi/ast-token-store/-/ast-token-store-0.3.0.tgz", @@ -2204,6 +2146,7 @@ "version": "0.4.1", "resolved": "https://registry.npmjs.org/@sec-ant/readable-stream/-/readable-stream-0.4.1.tgz", "integrity": "sha512-831qok9r2t8AlxLko40y2ebgSDhenenCatLVeW/uBtnHPyhHOvG0C7TvfgecV+wHzIm5KUICgzmVpWS+IMEAeg==", + "dev": true, "license": "MIT" }, "node_modules/@sinclair/typebox": { @@ -2217,6 +2160,7 @@ "version": "4.0.0", "resolved": "https://registry.npmjs.org/@sindresorhus/merge-streams/-/merge-streams-4.0.0.tgz", "integrity": "sha512-tlqY9xq5ukxTUZBmoOp+m61cqwQD5pHJtFY3Mn8CA8ps6yghLH/Hw8UPdqg4OLmFW3IFlcXnQNmo/dh8HzXYIQ==", + "dev": true, "license": "MIT", "engines": { "node": ">=18" @@ -2325,17 +2269,6 @@ "dev": true, "license": "MIT" }, - "node_modules/@types/fs-extra": { - "version": "11.0.4", - "resolved": "https://registry.npmjs.org/@types/fs-extra/-/fs-extra-11.0.4.tgz", - "integrity": "sha512-yTbItCNreRooED33qjunPthRcSjERP1r4MqCZc7wv0u2sUkzTFp45tgUfS5+r7FrZPdmCCNflLhVSP/o+SemsQ==", - "dev": true, - "license": "MIT", - "dependencies": { - "@types/jsonfile": "*", - "@types/node": "*" - } - }, "node_modules/@types/hast": { "version": "3.0.4", "resolved": "https://registry.npmjs.org/@types/hast/-/hast-3.0.4.tgz", @@ -2391,16 +2324,6 @@ "dev": true, "license": "MIT" }, - "node_modules/@types/jsonfile": { - "version": "6.1.4", - "resolved": "https://registry.npmjs.org/@types/jsonfile/-/jsonfile-6.1.4.tgz", - "integrity": "sha512-D5qGUYwjvnNNextdU59/+fI+spnwtTFmyQP0h+PfIOSkNfpU6AOICUOkm4i0OnSk+NyjdPJrxCDro0sJsWlRpQ==", - "dev": true, - "license": "MIT", - "dependencies": { - "@types/node": "*" - } - }, "node_modules/@types/katex": { "version": "0.16.8", "resolved": "https://registry.npmjs.org/@types/katex/-/katex-0.16.8.tgz", @@ -2429,7 +2352,7 @@ "version": "25.9.3", "resolved": "https://registry.npmjs.org/@types/node/-/node-25.9.3.tgz", "integrity": "sha512-603BddQMv3pUcr4U2dhujk83N2tTDVr/34wII2B6bJy6g+8WD6yUb11jszNs0gdi4PesVWl7ABt8nYMVpnLUcg==", - "devOptional": true, + "dev": true, "license": "MIT", "dependencies": { "undici-types": ">=7.24.0 <7.24.7" @@ -2466,16 +2389,6 @@ "dev": true, "license": "MIT" }, - "node_modules/@types/yauzl": { - "version": "2.10.3", - "resolved": "https://registry.npmjs.org/@types/yauzl/-/yauzl-2.10.3.tgz", - "integrity": "sha512-oJoftv0LSuaDZE3Le4DbKX+KS9G36NzOeSap90UIK0yMA/NhKJhqlSGtNDORNRaIbQfzjXDrQa0ytJ6mNRGz/Q==", - "license": "MIT", - "optional": true, - "dependencies": { - "@types/node": "*" - } - }, "node_modules/@typescript-eslint/eslint-plugin": { "version": "8.60.1", "resolved": "https://registry.npmjs.org/@typescript-eslint/eslint-plugin/-/eslint-plugin-8.60.1.tgz", @@ -3939,15 +3852,6 @@ "node-int64": "^0.4.0" } }, - "node_modules/buffer-crc32": { - "version": "0.2.13", - "resolved": "https://registry.npmjs.org/buffer-crc32/-/buffer-crc32-0.2.13.tgz", - "integrity": "sha512-VO9Ht/+p3SN7SKWqcrgEzjGbRSJYTx+Q1pTQC0wrWqHx0vpJraQ6GtHx8tvcg1rlK1byhU5gccxgOgj7B0TDkQ==", - "license": "MIT", - "engines": { - "node": "*" - } - }, "node_modules/buffer-from": { "version": "1.1.2", "resolved": "https://registry.npmjs.org/buffer-from/-/buffer-from-1.1.2.tgz", @@ -4293,6 +4197,7 @@ "version": "7.0.6", "resolved": "https://registry.npmjs.org/cross-spawn/-/cross-spawn-7.0.6.tgz", "integrity": "sha512-uV2QOWP2nWzsy2aMp8aRibhi9dlzF5Hgh5SHaB9OiTGEyDTiJJyx0uy51QXdyWbtAHNua4XJzUKca3OzKUd3vA==", + "dev": true, "license": "MIT", "dependencies": { "path-key": "^3.1.0", @@ -4303,33 +4208,6 @@ "node": ">= 8" } }, - "node_modules/crypto-random-string": { - "version": "4.0.0", - "resolved": "https://registry.npmjs.org/crypto-random-string/-/crypto-random-string-4.0.0.tgz", - "integrity": "sha512-x8dy3RnvYdlUcPOjkEHqozhiwzKNSq7GcPuXFbnyMOCHxX8V3OgIg/pYuabl2sbUPfIJaeAQB7PMOK8DFIdoRA==", - "license": "MIT", - "dependencies": { - "type-fest": "^1.0.1" - }, - "engines": { - "node": ">=12" - }, - "funding": { - "url": "https://github.com/sponsors/sindresorhus" - } - }, - "node_modules/crypto-random-string/node_modules/type-fest": { - "version": "1.4.0", - "resolved": "https://registry.npmjs.org/type-fest/-/type-fest-1.4.0.tgz", - "integrity": "sha512-yGSza74xk0UG8k+pLh5oeoYirvIiWo5t0/o3zHHAO2tRDiZcxWP7fywNlXhqb6/r6sWvwi+RsyQMWhVLe4BVuA==", - "license": "(MIT OR CC0-1.0)", - "engines": { - "node": ">=10" - }, - "funding": { - "url": "https://github.com/sponsors/sindresorhus" - } - }, "node_modules/cspell-config-lib": { "version": "10.0.1", "resolved": "https://registry.npmjs.org/cspell-config-lib/-/cspell-config-lib-10.0.1.tgz", @@ -4460,6 +4338,7 @@ "version": "4.4.3", "resolved": "https://registry.npmjs.org/debug/-/debug-4.4.3.tgz", "integrity": "sha512-RGwwWnwQvkVfavKVt22FGLw+xYSdzARwm0ru6DhTVA3umU5hZc28V3kO4stgYryrTlLpuvgI9GiijltAjNbcqA==", + "dev": true, "license": "MIT", "dependencies": { "ms": "^2.1.3" @@ -4623,15 +4502,6 @@ "node": ">=14" } }, - "node_modules/end-of-stream": { - "version": "1.4.5", - "resolved": "https://registry.npmjs.org/end-of-stream/-/end-of-stream-1.4.5.tgz", - "integrity": "sha512-ooEGc6HP26xXq/N+GCGOT0JKCLDGrq2bQUZrQ7gyrJiZANJ/8YDTxTpQBXGMn+WbIQXNVpyWymm7KYVICQnyOg==", - "license": "MIT", - "dependencies": { - "once": "^1.4.0" - } - }, "node_modules/enhanced-resolve": { "version": "5.24.0", "resolved": "https://registry.npmjs.org/enhanced-resolve/-/enhanced-resolve-5.24.0.tgz", @@ -5200,6 +5070,7 @@ "version": "9.6.1", "resolved": "https://registry.npmjs.org/execa/-/execa-9.6.1.tgz", "integrity": "sha512-9Be3ZoN4LmYR90tUoVu2te2BsbzHfhJyfEiAVfz7N5/zv+jduIfLrV2xdQXOHbaD6KgpGdO9PRPM1Y4Q9QkPkA==", + "dev": true, "license": "MIT", "dependencies": { "@sindresorhus/merge-streams": "^4.0.0", @@ -5250,41 +5121,6 @@ "node": "^18.14.0 || ^20.0.0 || ^22.0.0 || >=24.0.0" } }, - "node_modules/extract-zip": { - "version": "2.0.1", - "resolved": "https://registry.npmjs.org/extract-zip/-/extract-zip-2.0.1.tgz", - "integrity": "sha512-GDhU9ntwuKyGXdZBUgTIe+vXnWj0fppUEtMDL0+idd5Sta8TGpHssn/eusA9mrPr9qNDym6SxAYZjNvCn/9RBg==", - "license": "BSD-2-Clause", - "dependencies": { - "debug": "^4.1.1", - "get-stream": "^5.1.0", - "yauzl": "^2.10.0" - }, - "bin": { - "extract-zip": "cli.js" - }, - "engines": { - "node": ">= 10.17.0" - }, - "optionalDependencies": { - "@types/yauzl": "^2.9.1" - } - }, - "node_modules/extract-zip/node_modules/get-stream": { - "version": "5.2.0", - "resolved": "https://registry.npmjs.org/get-stream/-/get-stream-5.2.0.tgz", - "integrity": "sha512-nBF+F1rAZVCu/p7rjzgA+Yb4lfYXrpl7a6VmJrU8wF9I1CKvP/QwPNZHnOlwbTkY6dvtFIzFMSyQXbLoTQPRpA==", - "license": "MIT", - "dependencies": { - "pump": "^3.0.0" - }, - "engines": { - "node": ">=8" - }, - "funding": { - "url": "https://github.com/sponsors/sindresorhus" - } - }, "node_modules/fast-deep-equal": { "version": "3.1.3", "resolved": "https://registry.npmjs.org/fast-deep-equal/-/fast-deep-equal-3.1.3.tgz", @@ -5340,15 +5176,6 @@ "bser": "2.1.1" } }, - "node_modules/fd-slicer": { - "version": "1.1.0", - "resolved": "https://registry.npmjs.org/fd-slicer/-/fd-slicer-1.1.0.tgz", - "integrity": "sha512-cE1qsB/VwyQozZ+q1dGxR8LBYNZeofhEdUNGSMbQD3Gw2lAzX9Zb3uIU6Ebc/Fmyjo9AWWfnn0AUCHqtevs/8g==", - "license": "MIT", - "dependencies": { - "pend": "~1.2.0" - } - }, "node_modules/fdir": { "version": "6.5.0", "resolved": "https://registry.npmjs.org/fdir/-/fdir-6.5.0.tgz", @@ -5371,6 +5198,7 @@ "version": "6.1.0", "resolved": "https://registry.npmjs.org/figures/-/figures-6.1.0.tgz", "integrity": "sha512-d+l3qxjSesT4V7v2fh+QnmFnUWv9lSpjarhShNTgBOfA0ttejbQUAlHLitbjkoRiDulW0OPoQPYIGhIC8ohejg==", + "dev": true, "license": "MIT", "dependencies": { "is-unicode-supported": "^2.0.0" @@ -5482,20 +5310,6 @@ "node": ">=0.4.x" } }, - "node_modules/fs-extra": { - "version": "11.3.5", - "resolved": "https://registry.npmjs.org/fs-extra/-/fs-extra-11.3.5.tgz", - "integrity": "sha512-eKpRKAovdpZtR1WopLHxlBWvAgPny3c4gX1G5Jhwmmw4XJj0ifSD5qB5TOo8hmA0wlRKDAOAhEE1yVPgs6Fgcg==", - "license": "MIT", - "dependencies": { - "graceful-fs": "^4.2.0", - "jsonfile": "^6.0.1", - "universalify": "^2.0.0" - }, - "engines": { - "node": ">=14.14" - } - }, "node_modules/fs.realpath": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/fs.realpath/-/fs.realpath-1.0.0.tgz", @@ -5569,6 +5383,7 @@ "version": "9.0.1", "resolved": "https://registry.npmjs.org/get-stream/-/get-stream-9.0.1.tgz", "integrity": "sha512-kVCxPF3vQM/N0B1PmoqVUqgHP+EeVjmZSQn+1oCRPxd2P21P2F19lIgbR3HBosbB1PUhOAoctJnfEn2GbN2eZA==", + "dev": true, "license": "MIT", "dependencies": { "@sec-ant/readable-stream": "^0.4.1", @@ -5719,6 +5534,7 @@ "version": "4.2.11", "resolved": "https://registry.npmjs.org/graceful-fs/-/graceful-fs-4.2.11.tgz", "integrity": "sha512-RbJ5/jmFcNNCcDV5o9eTnBLJ/HszWV0P73bc+Ff4nS/rJj+YaS6IGyiOL0VoBYX+l1Wrl3k63h/KrH+nhJ0XvQ==", + "dev": true, "license": "ISC" }, "node_modules/has-flag": { @@ -5765,6 +5581,7 @@ "version": "8.0.1", "resolved": "https://registry.npmjs.org/human-signals/-/human-signals-8.0.1.tgz", "integrity": "sha512-eKCa6bwnJhvxj14kZk5NCPc6Hb6BdsU9DZcOnmQKSnO1VKrfV0zCvtttPZUsBvjmNDn8rpcJfpwSYnHBjc95MQ==", + "dev": true, "license": "Apache-2.0", "engines": { "node": ">=18.18.0" @@ -5955,17 +5772,11 @@ "node": ">=0.10.0" } }, - "node_modules/is-node-process": { - "version": "1.2.0", - "resolved": "https://registry.npmjs.org/is-node-process/-/is-node-process-1.2.0.tgz", - "integrity": "sha512-Vg4o6/fqPxIjtxgUH5QLJhwZ7gW5diGCVlXpuUfELC62CuxM1iHcRe51f2W1FDy04Ai4KJkagKjx3XaqyfRKXw==", - "dev": true, - "license": "MIT" - }, "node_modules/is-plain-obj": { "version": "4.1.0", "resolved": "https://registry.npmjs.org/is-plain-obj/-/is-plain-obj-4.1.0.tgz", "integrity": "sha512-+Pgi+vMuUNkJyExiMBt5IlFoMyKnr5zhJ4Uspz58WOhBF5QoIZkFyNHIbBAtHwzVAgk5RtndVNsDRN61/mmDqg==", + "dev": true, "license": "MIT", "engines": { "node": ">=12" @@ -5991,6 +5802,7 @@ "version": "4.0.1", "resolved": "https://registry.npmjs.org/is-stream/-/is-stream-4.0.1.tgz", "integrity": "sha512-Dnz92NInDqYckGEUJv689RbRiTSEHCQ7wOVeALbkOz999YpqT46yMRIGtSNl2iCL1waAZSx40+h59NV/EwzV/A==", + "dev": true, "license": "MIT", "engines": { "node": ">=18" @@ -6003,6 +5815,7 @@ "version": "2.1.0", "resolved": "https://registry.npmjs.org/is-unicode-supported/-/is-unicode-supported-2.1.0.tgz", "integrity": "sha512-mE00Gnza5EEB3Ds0HfMyllZzbBrmLOX3vfWoj9A9PEnTfratQ/BcaJOuMhnkhjXvb2+FkY3VuHqtAGpTPmglFQ==", + "dev": true, "license": "MIT", "engines": { "node": ">=18" @@ -6015,6 +5828,7 @@ "version": "2.0.0", "resolved": "https://registry.npmjs.org/isexe/-/isexe-2.0.0.tgz", "integrity": "sha512-RHxMLp9lnKHGHRng9QFhRCMbYAcVpn69smSGcq3f36xjgVVWThj4qqLbTLlq7Ssj8B+fIQ1EuCEGI2lKsyQeIw==", + "dev": true, "license": "ISC" }, "node_modules/istanbul-lib-coverage": { @@ -6846,13 +6660,6 @@ "dev": true, "license": "MIT" }, - "node_modules/json-stringify-safe": { - "version": "5.0.1", - "resolved": "https://registry.npmjs.org/json-stringify-safe/-/json-stringify-safe-5.0.1.tgz", - "integrity": "sha512-ZClg6AaYvamvYEE82d3Iyd3vSSIjQ+odgjaTzRuO3s7toCdFKczob2i0zCh7JE8kWn17yvAWhUVxvqGwUalsRA==", - "dev": true, - "license": "ISC" - }, "node_modules/json5": { "version": "2.2.3", "resolved": "https://registry.npmjs.org/json5/-/json5-2.2.3.tgz", @@ -6884,18 +6691,6 @@ "url": "https://github.com/sponsors/ota-meshi" } }, - "node_modules/jsonfile": { - "version": "6.2.1", - "resolved": "https://registry.npmjs.org/jsonfile/-/jsonfile-6.2.1.tgz", - "integrity": "sha512-zwOTdL3rFQ/lRdBnntKVOX6k5cKJwEc1HdilT71BWEu7J41gXIB2MRp+vxduPSwZJPWBxEzv4yH1wYLJGUHX4Q==", - "license": "MIT", - "dependencies": { - "universalify": "^2.0.0" - }, - "optionalDependencies": { - "graceful-fs": "^4.1.6" - } - }, "node_modules/jsx-ast-utils-x": { "version": "0.1.0", "resolved": "https://registry.npmjs.org/jsx-ast-utils-x/-/jsx-ast-utils-x-0.1.0.tgz", @@ -7999,6 +7794,7 @@ "version": "2.1.3", "resolved": "https://registry.npmjs.org/ms/-/ms-2.1.3.tgz", "integrity": "sha512-6FlzubTLZG3J2a/NVCAleEhjzq5oxgHyaCU9yYXvcLsvoVaHJq/s5xXI6/XXP6tz7R9xAOtHnSO/tXtF3WRTlA==", + "dev": true, "license": "MIT" }, "node_modules/napi-postinstall": { @@ -8034,21 +7830,6 @@ "node": ">=18" } }, - "node_modules/nock": { - "version": "14.0.15", - "resolved": "https://registry.npmjs.org/nock/-/nock-14.0.15.tgz", - "integrity": "sha512-S0a47C9pLvcYx/Ugf0H30BVBEcUgMMBDk9VJIDlJ8XGrfH2QDUD4Tgdp45qDIiHttokBG+IbsOtsvIjGR/j3bg==", - "dev": true, - "license": "MIT", - "dependencies": { - "@mswjs/interceptors": "^0.41.0", - "json-stringify-safe": "^5.0.1", - "propagate": "^2.0.0" - }, - "engines": { - "node": ">=18.20.0 <20 || >=20.12.1" - } - }, "node_modules/node-int64": { "version": "0.4.0", "resolved": "https://registry.npmjs.org/node-int64/-/node-int64-0.4.0.tgz", @@ -8096,6 +7877,7 @@ "version": "6.0.0", "resolved": "https://registry.npmjs.org/npm-run-path/-/npm-run-path-6.0.0.tgz", "integrity": "sha512-9qny7Z9DsQU8Ou39ERsPU4OZQlSTP47ShQzuKZ6PRXpYLtIFgl/DEBYEXKlvcEa+9tHVcK8CF81Y2V72qaZhWA==", + "dev": true, "license": "MIT", "dependencies": { "path-key": "^4.0.0", @@ -8112,6 +7894,7 @@ "version": "4.0.0", "resolved": "https://registry.npmjs.org/path-key/-/path-key-4.0.0.tgz", "integrity": "sha512-haREypq7xkM7ErfgIyA0z+Bj4AGKlMSdlQE2jvJo6huWD1EdkKYV+G/T4nq0YEF2vgTT8kqMFKo1uHn950r4SQ==", + "dev": true, "license": "MIT", "engines": { "node": ">=12" @@ -8124,6 +7907,7 @@ "version": "1.4.0", "resolved": "https://registry.npmjs.org/once/-/once-1.4.0.tgz", "integrity": "sha512-lNaJgI+2Q5URQBkccEKHTQOPaXdUxnZZElQTZY0MFUAuaEqe1E+Nyvgdz/aIyNi6Z9MzO5dv1H8n58/GELp3+w==", + "dev": true, "license": "ISC", "dependencies": { "wrappy": "1" @@ -8163,13 +7947,6 @@ "node": ">= 0.8.0" } }, - "node_modules/outvariant": { - "version": "1.4.3", - "resolved": "https://registry.npmjs.org/outvariant/-/outvariant-1.4.3.tgz", - "integrity": "sha512-+Sl2UErvtsoajRDKCE5/dBz4DIvHXQQnAxtQTF04OJxY0+DyZXSo5P5Bb7XYWOh81syohlYL24hbDwxedPUJCA==", - "dev": true, - "license": "MIT" - }, "node_modules/p-limit": { "version": "3.1.0", "resolved": "https://registry.npmjs.org/p-limit/-/p-limit-3.1.0.tgz", @@ -8258,6 +8035,7 @@ "version": "4.0.0", "resolved": "https://registry.npmjs.org/parse-ms/-/parse-ms-4.0.0.tgz", "integrity": "sha512-TXfryirbmq34y8QBwgqCVLi+8oA3oWx2eAnSn62ITyEhEYaWRlVZ2DvMM9eZbMs/RfxPu/PK/aBLyGj4IrqMHw==", + "dev": true, "license": "MIT", "engines": { "node": ">=18" @@ -8266,15 +8044,6 @@ "url": "https://github.com/sponsors/sindresorhus" } }, - "node_modules/path-exists": { - "version": "5.0.0", - "resolved": "https://registry.npmjs.org/path-exists/-/path-exists-5.0.0.tgz", - "integrity": "sha512-RjhtfwJOxzcFmNOi6ltcbcu4Iu+FL3zEj83dk4kAS+fVpTxXLO1b38RvJgT/0QwvV/L3aY9TAnyv0EOqW4GoMQ==", - "license": "MIT", - "engines": { - "node": "^12.20.0 || ^14.13.1 || >=16.0.0" - } - }, "node_modules/path-is-absolute": { "version": "1.0.1", "resolved": "https://registry.npmjs.org/path-is-absolute/-/path-is-absolute-1.0.1.tgz", @@ -8289,6 +8058,7 @@ "version": "3.1.1", "resolved": "https://registry.npmjs.org/path-key/-/path-key-3.1.1.tgz", "integrity": "sha512-ojmeN0qd+y0jszEtoY48r0Peq5dwMEkIlCOu6Q5f41lfkswXuKtYrhgoTpLnyIcHm24Uhqx+5Tqm2InSwLhE6Q==", + "dev": true, "license": "MIT", "engines": { "node": ">=8" @@ -8318,12 +8088,6 @@ "dev": true, "license": "ISC" }, - "node_modules/pend": { - "version": "1.2.0", - "resolved": "https://registry.npmjs.org/pend/-/pend-1.2.0.tgz", - "integrity": "sha512-F3asv42UuXchdzt+xXqfW1OGlVBe+mxa2mqI0pg5yAHZPvFmY3Y6drSf/GQ1A86WgWEN9Kzh/WrgKa6iGcHXLg==", - "license": "MIT" - }, "node_modules/picocolors": { "version": "1.1.1", "resolved": "https://registry.npmjs.org/picocolors/-/picocolors-1.1.1.tgz", @@ -8502,6 +8266,7 @@ "version": "9.3.0", "resolved": "https://registry.npmjs.org/pretty-ms/-/pretty-ms-9.3.0.tgz", "integrity": "sha512-gjVS5hOP+M3wMm5nmNOucbIrqudzs9v/57bWRHQWLYklXqoXKrVfYW2W9+glfGsqtPgpiz5WwyEEB+ksXIx3gQ==", + "dev": true, "license": "MIT", "dependencies": { "parse-ms": "^4.0.0" @@ -8523,26 +8288,6 @@ "node": "^20.17.0 || >=22.9.0" } }, - "node_modules/propagate": { - "version": "2.0.1", - "resolved": "https://registry.npmjs.org/propagate/-/propagate-2.0.1.tgz", - "integrity": "sha512-vGrhOavPSTz4QVNuBNdcNXePNdNMaO1xj9yBeH1ScQPjk/rhg9sSlCXPhMkFuaNNW/syTvYqsnbIJxMBfRbbag==", - "dev": true, - "license": "MIT", - "engines": { - "node": ">= 8" - } - }, - "node_modules/pump": { - "version": "3.0.4", - "resolved": "https://registry.npmjs.org/pump/-/pump-3.0.4.tgz", - "integrity": "sha512-VS7sjc6KR7e1ukRFhQSY5LM2uBWAUPiOPa/A3mkKmiMwSmRFUITt0xuj+/lesgnCv+dPIEYlkzrcyXgquIHMcA==", - "license": "MIT", - "dependencies": { - "end-of-stream": "^1.1.0", - "once": "^1.3.1" - } - }, "node_modules/punycode": { "version": "2.3.1", "resolved": "https://registry.npmjs.org/punycode/-/punycode-2.3.1.tgz", @@ -8711,6 +8456,7 @@ "version": "2.0.0", "resolved": "https://registry.npmjs.org/shebang-command/-/shebang-command-2.0.0.tgz", "integrity": "sha512-kHxr2zZpYtdmrN1qDjrrX/Z1rR1kG8Dx+gkpK1G4eXmvXswmcE1hTWBWYUzlraYw1/yZp6YuDY77YtvbN0dmDA==", + "dev": true, "license": "MIT", "dependencies": { "shebang-regex": "^3.0.0" @@ -8723,6 +8469,7 @@ "version": "3.0.0", "resolved": "https://registry.npmjs.org/shebang-regex/-/shebang-regex-3.0.0.tgz", "integrity": "sha512-7++dFhtcx3353uBaq8DDR4NuxBetBzC7ZQOhmTQInHEd6bSrXdiEyzCvG07Z44UYdLShWUyXt5M/yhz8ekcb1A==", + "dev": true, "license": "MIT", "engines": { "node": ">=8" @@ -8732,6 +8479,7 @@ "version": "4.1.0", "resolved": "https://registry.npmjs.org/signal-exit/-/signal-exit-4.1.0.tgz", "integrity": "sha512-bzyZ1e88w9O1iNJbKnOlvYTrWPDl46O1bG0D3XInv+9tkPrxrN8jUUTiFlDkkmKWgn1M6CfIA13SuGqOa9Korw==", + "dev": true, "license": "ISC", "engines": { "node": ">=14" @@ -8889,13 +8637,6 @@ "node": ">=8" } }, - "node_modules/strict-event-emitter": { - "version": "0.5.1", - "resolved": "https://registry.npmjs.org/strict-event-emitter/-/strict-event-emitter-0.5.1.tgz", - "integrity": "sha512-vMgjE/GGEPEFnhFub6pa4FmJBRBVOLpIII2hvCZ8Kzb7K0hlHo7mQv6xYrBvCL2LtAIBwFUK8wvuJgTVSQ5MFQ==", - "dev": true, - "license": "MIT" - }, "node_modules/string-length": { "version": "4.0.2", "resolved": "https://registry.npmjs.org/string-length/-/string-length-4.0.2.tgz", @@ -9051,6 +8792,7 @@ "version": "4.0.0", "resolved": "https://registry.npmjs.org/strip-final-newline/-/strip-final-newline-4.0.0.tgz", "integrity": "sha512-aulFJcD6YK8V1G7iRB5tigAP4TsHBZZrOV8pjV++zdUwmeV8uzbY7yn6h9MswN62adStNZFuCIx4haBnRuMDaw==", + "dev": true, "license": "MIT", "engines": { "node": ">=18" @@ -9128,57 +8870,6 @@ "url": "https://opencollective.com/webpack" } }, - "node_modules/temp-dir": { - "version": "3.0.0", - "resolved": "https://registry.npmjs.org/temp-dir/-/temp-dir-3.0.0.tgz", - "integrity": "sha512-nHc6S/bwIilKHNRgK/3jlhDoIHcp45YgyiwcAk46Tr0LfEqGBVpmiAyuiuxeVE44m3mXnEeVhaipLOEWmH+Njw==", - "license": "MIT", - "engines": { - "node": ">=14.16" - } - }, - "node_modules/tempy": { - "version": "3.2.0", - "resolved": "https://registry.npmjs.org/tempy/-/tempy-3.2.0.tgz", - "integrity": "sha512-d79HhZya5Djd7am0q+W4RTsSU+D/aJzM+4Y4AGJGuGlgM2L6sx5ZvOYTmZjqPhrDrV6xJTtRSm1JCLj6V6LHLQ==", - "license": "MIT", - "dependencies": { - "is-stream": "^3.0.0", - "temp-dir": "^3.0.0", - "type-fest": "^2.12.2", - "unique-string": "^3.0.0" - }, - "engines": { - "node": ">=14.16" - }, - "funding": { - "url": "https://github.com/sponsors/sindresorhus" - } - }, - "node_modules/tempy/node_modules/is-stream": { - "version": "3.0.0", - "resolved": "https://registry.npmjs.org/is-stream/-/is-stream-3.0.0.tgz", - "integrity": "sha512-LnQR4bZ9IADDRSkvpqMGvt/tEJWclzklNgSw48V5EAaAeDd6qGvN8ei6k5p0tvxSR171VmGyHuTiAOfxAbr8kA==", - "license": "MIT", - "engines": { - "node": "^12.20.0 || ^14.13.1 || >=16.0.0" - }, - "funding": { - "url": "https://github.com/sponsors/sindresorhus" - } - }, - "node_modules/tempy/node_modules/type-fest": { - "version": "2.19.0", - "resolved": "https://registry.npmjs.org/type-fest/-/type-fest-2.19.0.tgz", - "integrity": "sha512-RAH822pAdBgcNMAfWnCBU3CFZcfZ/i1eZjwFU/dsLKumyuuP3niueg2UAukXYF0E2AAoc82ZSSf9J0WQBinzHA==", - "license": "(MIT OR CC0-1.0)", - "engines": { - "node": ">=12.20" - }, - "funding": { - "url": "https://github.com/sponsors/sindresorhus" - } - }, "node_modules/test-exclude": { "version": "6.0.0", "resolved": "https://registry.npmjs.org/test-exclude/-/test-exclude-6.0.0.tgz", @@ -9511,13 +9202,14 @@ "version": "7.24.6", "resolved": "https://registry.npmjs.org/undici-types/-/undici-types-7.24.6.tgz", "integrity": "sha512-WRNW+sJgj5OBN4/0JpHFqtqzhpbnV0GuB+OozA9gCL7a993SmU+1JBZCzLNxYsbMfIeDL+lTsphD5jN5N+n0zg==", - "devOptional": true, + "dev": true, "license": "MIT" }, "node_modules/unicorn-magic": { "version": "0.3.0", "resolved": "https://registry.npmjs.org/unicorn-magic/-/unicorn-magic-0.3.0.tgz", "integrity": "sha512-+QBBXBCvifc56fsbuxZQ6Sic3wqqc3WWaqxs58gvJrcOuN83HGTCwz3oS5phzU9LthRNE9VrJCFCLUgHeeFnfA==", + "dev": true, "license": "MIT", "engines": { "node": ">=18" @@ -9526,21 +9218,6 @@ "url": "https://github.com/sponsors/sindresorhus" } }, - "node_modules/unique-string": { - "version": "3.0.0", - "resolved": "https://registry.npmjs.org/unique-string/-/unique-string-3.0.0.tgz", - "integrity": "sha512-VGXBUVwxKMBUznyffQweQABPRRW1vHZAbadFZud4pLFAqRGvv/96vafgjWFqzourzr8YonlQiPgH0YCJfawoGQ==", - "license": "MIT", - "dependencies": { - "crypto-random-string": "^4.0.0" - }, - "engines": { - "node": ">=12" - }, - "funding": { - "url": "https://github.com/sponsors/sindresorhus" - } - }, "node_modules/unist-util-is": { "version": "6.0.1", "resolved": "https://registry.npmjs.org/unist-util-is/-/unist-util-is-6.0.1.tgz", @@ -9615,15 +9292,6 @@ "url": "https://opencollective.com/unified" } }, - "node_modules/universalify": { - "version": "2.0.1", - "resolved": "https://registry.npmjs.org/universalify/-/universalify-2.0.1.tgz", - "integrity": "sha512-gptHNQghINnc/vTGIk0SOFGFNXw7JVrlRUtConJRlvaw6DuX0wO5Jeko9sWrMBhh+PsYAZ7oXAiOnf/UKogyiw==", - "license": "MIT", - "engines": { - "node": ">= 10.0.0" - } - }, "node_modules/unrs-resolver": { "version": "1.12.2", "resolved": "https://registry.npmjs.org/unrs-resolver/-/unrs-resolver-1.12.2.tgz", @@ -9767,6 +9435,7 @@ "version": "2.0.2", "resolved": "https://registry.npmjs.org/which/-/which-2.0.2.tgz", "integrity": "sha512-BLI3Tl1TW3Pvl70l3yq3Y64i+awpwXqsGBYWkkqMtnbXgrMD+yj7rhW0kuEDxzJaYXGjEW5ogapKNMEKNMjibA==", + "dev": true, "license": "ISC", "dependencies": { "isexe": "^2.0.0" @@ -9887,6 +9556,7 @@ "version": "1.0.2", "resolved": "https://registry.npmjs.org/wrappy/-/wrappy-1.0.2.tgz", "integrity": "sha512-l4Sp/DRseor9wL6EvV2+TuQn63dMkPjZ/sp9XkghTEbV9KlPS1xUsZ3u7/IQO4wxtcFB4bgpQPRcR3QCvezPcQ==", + "dev": true, "license": "ISC" }, "node_modules/write-file-atomic": { @@ -9907,6 +9577,7 @@ "version": "5.1.0", "resolved": "https://registry.npmjs.org/xdg-basedir/-/xdg-basedir-5.1.0.tgz", "integrity": "sha512-GCPAHLvrIH13+c0SuacwvRYj2SxJXQ4kaVTT5xgL3kPrz56XxkF21IGhjSE1+W0aw7gpBWRGXLCPnPby6lSpmQ==", + "dev": true, "license": "MIT", "engines": { "node": ">=12" @@ -10039,16 +9710,6 @@ "node": ">=8" } }, - "node_modules/yauzl": { - "version": "2.10.0", - "resolved": "https://registry.npmjs.org/yauzl/-/yauzl-2.10.0.tgz", - "integrity": "sha512-p4a9I6X6nu6IhoGmBqAcbJy1mlC4j27vEPZX9F4L4/vZT3Lyq1VkFHw/V/PUcB9Buo+DG3iHkT0x3Qya58zc3g==", - "license": "MIT", - "dependencies": { - "buffer-crc32": "~0.2.3", - "fd-slicer": "~1.1.0" - } - }, "node_modules/yocto-queue": { "version": "0.1.0", "resolved": "https://registry.npmjs.org/yocto-queue/-/yocto-queue-0.1.0.tgz", @@ -10066,6 +9727,7 @@ "version": "2.1.2", "resolved": "https://registry.npmjs.org/yoctocolors/-/yoctocolors-2.1.2.tgz", "integrity": "sha512-CzhO+pFNo8ajLM2d2IW/R93ipy99LWjtwblvC1RsoSUMZgyLbYFr221TnSNT7GjGdYui6P459mw9JH/g/zW2ug==", + "dev": true, "license": "MIT", "engines": { "node": ">=18" diff --git a/package.json b/package.json index b5ee57b..e0ddf64 100644 --- a/package.json +++ b/package.json @@ -12,7 +12,6 @@ "scripts": { "build": "node scripts/build.js", "format": "prettier --write .", - "postinstall": "node ./src/postinstall.js", "test": "node --experimental-vm-modules node_modules/jest/bin/jest.js", "test:watch": "node --experimental-vm-modules node_modules/jest/bin/jest.js --watch" }, @@ -23,23 +22,15 @@ "author": "Lvce Editor", "license": "MIT", "dependencies": { - "@lvce-editor/verror": "^1.7.0", - "@vscode/ripgrep": "^1.18.0", - "execa": "^9.6.1", - "extract-zip": "^2.0.1", - "fs-extra": "^11.3.5", - "path-exists": "^5.0.0", - "tempy": "^3.2.0", - "xdg-basedir": "^5.1.0" + "@vscode/ripgrep": "^1.18.0" }, "devDependencies": { "@lvce-editor/eslint-config": "^11.2.0", - "@types/fs-extra": "^11.0.4", "@types/jest": "^30.0.0", "@types/node": "^25.9.3", "eslint": "^10.5.0", + "execa": "^9.6.1", "jest": "^30.4.2", - "nock": "^14.0.15", "prettier": "^3.8.4", "typescript": "^6.0.3" }, diff --git a/src/downloadRipGrep.js b/src/downloadRipGrep.js deleted file mode 100644 index f112133..0000000 --- a/src/downloadRipGrep.js +++ /dev/null @@ -1,144 +0,0 @@ -import { VError } from '@lvce-editor/verror' -import { execa } from 'execa' -import extractZip from 'extract-zip' -import fsExtra from 'fs-extra' -import * as os from 'node:os' -import { dirname, join } from 'node:path' -import { pipeline } from 'node:stream/promises' -import { fileURLToPath } from 'node:url' -import { pathExists } from 'path-exists' -import { temporaryFile } from 'tempy' -import { xdgCache } from 'xdg-basedir' - -const { mkdir, createWriteStream, move } = fsExtra - -const __dirname = dirname(fileURLToPath(import.meta.url)) - -const REPOSITORY = `microsoft/ripgrep-prebuilt` -const VERSION = process.env.RIPGREP_VERSION || 'v15.0.1' -const BIN_PATH = join(__dirname, '../bin') - -const getTarget = () => { - const arch = process.env.npm_config_arch || os.arch() - const platform = process.env.platform || os.platform() - switch (platform) { - case 'darwin': - switch (arch) { - case 'arm64': - return 'aarch64-apple-darwin.tar.gz' - default: - return 'x86_64-apple-darwin.tar.gz' - } - case 'win32': - switch (arch) { - case 'x64': - return 'x86_64-pc-windows-msvc.zip' - case 'arm': - return 'aarch64-pc-windows-msvc.zip' - default: - return 'i686-pc-windows-msvc.zip' - } - case 'linux': - switch (arch) { - case 'x64': - return 'x86_64-unknown-linux-musl.tar.gz' - case 'arm': - case 'armv7l': - return 'arm-unknown-linux-gnueabihf.tar.gz' - case 'arm64': - return 'aarch64-unknown-linux-gnu.tar.gz' - case 'ppc64': - return 'powerpc64le-unknown-linux-gnu.tar.gz' - case 's390x': - return 's390x-unknown-linux-gnu.tar.gz' - default: - return 'i686-unknown-linux-musl.tar.gz' - } - default: - throw new VError('Unknown platform: ' + platform) - } -} - -export const downloadFile = async (url, outFile) => { - try { - const tmpFile = temporaryFile() - const response = await fetch(url) - if (!response.ok) { - throw new Error(`HTTP ${response.status}: ${response.statusText}`) - } - await pipeline(response.body, createWriteStream(tmpFile)) - await mkdir(dirname(outFile), { recursive: true }) - await move(tmpFile, outFile) - } catch (error) { - throw new VError(error, `Failed to download "${url}"`) - } -} - -/** - * @param {string} inFile - * @param {string} outDir - */ -const unzip = async (inFile, outDir) => { - try { - await mkdir(outDir, { recursive: true }) - await extractZip(inFile, { dir: outDir }) - } catch (error) { - throw new VError(error, `Failed to unzip "${inFile}"`) - } -} - -/** - * @param {string} inFile - * @param {string} outDir - */ -const untarGz = async (inFile, outDir) => { - try { - await mkdir(outDir, { recursive: true }) - await execa('tar', ['xvf', inFile, '-C', outDir]) - } catch (error) { - throw new VError(error, `Failed to extract "${inFile}"`) - } -} - -const downloadRipGrepAndroid = async (platform) => { - if (platform === 'android') { - try { - await execa('pkg', ['install', 'ripgrep', '-y']) - return true - } catch (error) { - console.info( - 'Could not install ripgrep via pkg. Falling back to download.', - ) - return false - } - } -} - -export const downloadRipGrep = async (overrideBinPath) => { - const platform = process.env.platform || os.platform() - if (platform === 'android') { - const didInstall = await downloadRipGrepAndroid(platform) - if (didInstall) { - return - } - } - const target = getTarget() - const baseUrl = - process.env.RIPGREP_PREBUILT_BINARIES_MIRROR || - `https://github.com/${REPOSITORY}/releases/download` - const url = `${baseUrl}/${VERSION}/ripgrep-${VERSION}-${target}` - const downloadPath = `${xdgCache}/vscode-ripgrep/ripgrep-${VERSION}-${target}` - const binPath = overrideBinPath ?? BIN_PATH - if (!(await pathExists(downloadPath))) { - await downloadFile(url, downloadPath) - } else { - console.info(`File ${downloadPath} has been cached`) - } - if (downloadPath.endsWith('.tar.gz')) { - await untarGz(downloadPath, binPath) - } else if (downloadPath.endsWith('.zip')) { - await unzip(downloadPath, binPath) - } else { - throw new VError(`Invalid downloadPath ${downloadPath}`) - } -} diff --git a/src/index.d.ts b/src/index.d.ts index 24a19e7..70bf589 100644 --- a/src/index.d.ts +++ b/src/index.d.ts @@ -1,2 +1 @@ -export declare const rgPath: string -export declare const downloadRipGrep: (overrideBinPath?: string) => Promise +export { rgPath } from '@vscode/ripgrep' diff --git a/src/index.js b/src/index.js index d8af93e..70bf589 100644 --- a/src/index.js +++ b/src/index.js @@ -1,13 +1 @@ -import { dirname, join } from 'node:path' -import { fileURLToPath } from 'node:url' - -export { downloadRipGrep } from './downloadRipGrep.js' - -const __dirname = dirname(fileURLToPath(import.meta.url)) - -export const rgPath = join( - __dirname, - '..', - 'bin', - `rg${process.platform === 'win32' ? '.exe' : ''}`, -) +export { rgPath } from '@vscode/ripgrep' diff --git a/src/postinstall.js b/src/postinstall.js deleted file mode 100644 index cae35ae..0000000 --- a/src/postinstall.js +++ /dev/null @@ -1,3 +0,0 @@ -import { downloadRipGrep } from './downloadRipGrep.js' - -downloadRipGrep() diff --git a/test/downloadRipGrep.test.js b/test/downloadRipGrep.test.js deleted file mode 100644 index 6a70824..0000000 --- a/test/downloadRipGrep.test.js +++ /dev/null @@ -1,140 +0,0 @@ -import { - test, - expect, - beforeAll, - afterAll, - beforeEach, - jest, -} from '@jest/globals' -import nock from 'nock' - -// Use a real filesystem temp cache and mock only what must not run (tar) -const { mkdtempSync, mkdirSync, writeFileSync } = await import('node:fs') -const { join } = await import('node:path') -const { tmpdir } = await import('node:os') - -const tempCacheDir = mkdtempSync(join(tmpdir(), 'ripgrep-test-')) -const tempBinDir = mkdtempSync(join(tmpdir(), 'ripgrep-bin-')) -const testVersion = 'v15.0.0' -const linuxTarget = 'x86_64-unknown-linux-musl.tar.gz' - -// Force predictable platform/arch for URL/target without mocking core 'os' -const originalEnv = { ...process.env } -process.env.platform = 'linux' -process.env.npm_config_arch = 'x64' -process.env.RIPGREP_VERSION = testVersion - -// Provide cache location used by the implementation -jest.unstable_mockModule('xdg-basedir', () => ({ - xdgCache: tempCacheDir, -})) - -// Mock only tar execution -/** @type {any} */ -const mockExeca = jest.fn() -jest.unstable_mockModule('execa', () => ({ - execa: mockExeca, -})) - -// Import after mocks -const { downloadRipGrep, downloadFile } = - await import('../src/downloadRipGrep.js') - -beforeAll(() => { - nock.disableNetConnect() -}) - -afterAll(() => { - nock.enableNetConnect() - process.env = originalEnv -}) - -beforeEach(() => { - jest.clearAllMocks() - nock.cleanAll() -}) - -test('downloadRipGrep should handle network error', async () => { - // Simulate a network failure so pipeline rejects - nock('https://github.com') - .get( - `/microsoft/ripgrep-prebuilt/releases/download/${testVersion}/ripgrep-${testVersion}-${linuxTarget}`, - ) - .replyWithError('simulated error') - - await expect(downloadRipGrep(tempBinDir)).rejects.toThrow( - 'Failed to download', - ) -}) - -test('downloadRipGrep should successfully download and extract file', async () => { - // Intercept the GitHub asset request with a simple 200 body - const scope = nock('https://github.com') - .get( - `/microsoft/ripgrep-prebuilt/releases/download/${testVersion}/ripgrep-${testVersion}-${linuxTarget}`, - ) - .reply(200, 'mock-tar-gz-content', { - 'Content-Type': 'application/gzip', - }) - - mockExeca.mockResolvedValue(/** @type {any} */ ({ stdout: '', stderr: '' })) - - await downloadRipGrep(tempBinDir) - - expect(scope.isDone()).toBe(true) - expect(mockExeca).toHaveBeenCalled() - const tarArgs = /** @type {any[]} */ (mockExeca.mock.calls[0])[1] - const normalize = (p) => String(p).replace(/\\/g, '/') - expect(tarArgs[0]).toBe('xvf') - expect(normalize(tarArgs[1])).toContain( - normalize( - `${tempCacheDir}/vscode-ripgrep/ripgrep-${testVersion}-${linuxTarget}`, - ), - ) - expect(tarArgs[2]).toBe('-C') - expect(normalize(tarArgs[3])).toBe(normalize(tempBinDir)) -}) - -test('downloadRipGrep should use cached file when it exists', async () => { - // Prepare a cached file on disk - const cachedDir = join(tempCacheDir, 'vscode-ripgrep') - mkdirSync(cachedDir, { recursive: true }) - const cachedFile = join(cachedDir, `ripgrep-${testVersion}-${linuxTarget}`) - writeFileSync(cachedFile, 'already-downloaded') - - mockExeca.mockResolvedValue(/** @type {any} */ ({ stdout: '', stderr: '' })) - const infoSpy = jest.spyOn(console, 'info').mockImplementation(() => {}) - - await downloadRipGrep(tempBinDir) - - expect(infoSpy).toHaveBeenCalledWith( - expect.stringContaining('has been cached'), - ) - expect(mockExeca).toHaveBeenCalled() - const tarArgs = /** @type {any[]} */ (mockExeca.mock.calls[0])[1] - const normalize = (p) => String(p).replace(/\\/g, '/') - expect(tarArgs[0]).toBe('xvf') - expect(normalize(tarArgs[1])).toBe(normalize(cachedFile)) - expect(tarArgs[2]).toBe('-C') - expect(normalize(tarArgs[3])).toBe(normalize(tempBinDir)) - - infoSpy.mockRestore() -}) - -test('downloadFile should handle download errors', async () => { - // Make the stream fail to ensure pipeline rejects - nock('https://github.com') - .get( - `/microsoft/ripgrep-prebuilt/releases/download/${testVersion}/ripgrep-${testVersion}-${linuxTarget}`, - ) - .replyWithError('simulated error') - - await expect( - downloadFile( - `https://github.com/microsoft/ripgrep-prebuilt/releases/download/${testVersion}/ripgrep-${testVersion}-${linuxTarget}`, - join(tmpdir(), 'test.tar.gz'), - ), - ).rejects.toThrow( - `Failed to download \"https://github.com/microsoft/ripgrep-prebuilt/releases/download/${testVersion}/ripgrep-${testVersion}-${linuxTarget}\": simulated error`, - ) -}) diff --git a/test/test.js b/test/test.js index 692e242..e22ed9e 100644 --- a/test/test.js +++ b/test/test.js @@ -2,7 +2,7 @@ import { execa } from 'execa' import { mkdtemp, writeFile } from 'fs/promises' import { tmpdir, platform } from 'os' import { join } from 'path' -import { rgPath } from '../src/index.js' +import * as ripgrep from '../src/index.js' const getTmpDir = () => { return mkdtemp(join(tmpdir(), 'foo-')) @@ -11,7 +11,11 @@ const getTmpDir = () => { test('rgPath', async () => { const tmpDir = await getTmpDir() await writeFile(`${tmpDir}/sample-file.txt`, 'sample text') - const command = platform() === 'android' ? 'rg' : rgPath + const command = platform() === 'android' ? 'rg' : ripgrep.rgPath const { stdout } = await execa(command, ['sample', '.'], { cwd: tmpDir }) expect(stdout).toContain('sample-file.txt:sample text') }) + +test('exports only rgPath', () => { + expect(Object.keys(ripgrep)).toEqual(['rgPath']) +})