diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml new file mode 100644 index 000000000..87d4022f0 --- /dev/null +++ b/.github/workflows/publish.yml @@ -0,0 +1,83 @@ +on: + push: + tags: + - v* + workflow_dispatch: + +jobs: + build: + # TODO: should we run the tests, or can we assume that a v* tag ought to + # get published? + name: build + strategy: + matrix: + node: [20] + os: + - name: darwin + architecture: arm64 + host: macos-13 + + - name: linux + architecture: x86-64 + host: ubuntu-20.04 + env: + CC: clang + CXX: clang++ + npm_config_clang: 1 + GYP_DEFINES: use_obsolete_asm=true + runs-on: ${{ matrix.os.host }} + steps: + - uses: actions/checkout@v4 + with: + submodules: true + - uses: actions/setup-node@v4 + with: + node-version: 20 + check-latest: true + - name: Prebuildify + run: | + [[ $(uname -o) == *Linux ]] && \ + sudo apt-get update && \ + sudo apt-get install -y software-properties-common git build-essential clang libssl-dev libkrb5-dev libc++-dev wget python3 + npm ci + npx prebuildify --napi --strip -t "$(node --version | tr -d 'v')" + - uses: actions/upload-artifact@v4 + with: + name: prebuild-${{ runner.os }}-${{ runner.arch }} + path: prebuilds + retention-days: 14 + + # https://docs.npmjs.com/generating-provenance-statements#publishing-packages-with-provenance-via-github-actions + publish: + runs-on: ubuntu-latest + needs: [build] + permissions: + id-token: write + steps: + - uses: actions/checkout@v4 + with: + submodules: true + - uses: actions/setup-node@v4 + with: + node-version: 20 + check-latest: true + registry-url: "https://registry.npmjs.org" + scope: "readme" + - name: download built libraries + id: download + uses: actions/download-artifact@v4 + with: + path: prebuilds + - name: copy libs + run: | + set -x + find ${{ steps.download.outputs.download-path }} + mv ${{ steps.download.outputs.download-path }}/*/* ./prebuilds + find ./prebuilds + - name: npm install + run: npm ci + - name: publish + run: | + (cat "$NPM_CONFIG_USERCONFIG" || true) && echo "token: ${NODE_AUTH_TOKEN:0:10}" && npm publish --provenance --access public + env: + NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 6d5114d6a..357caebcd 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -7,207 +7,79 @@ on: - v*.*.* pull_request: -name: Testing - jobs: - linux-tests: - name: "Linux Tests" - strategy: - matrix: - node: [16] # 18+ requires GLIBC 2.28+ - runs-on: ubuntu-latest - container: ubuntu:16.04 + linux-test: + name: "test on linux" + env: + CC: clang + CXX: clang++ + npm_config_clang: 1 + GYP_DEFINES: use_obsolete_asm=true + DEBIAN_FRONTEND: "noninteractive" + runs-on: ubuntu-20.04 + container: ubuntu:20.04 steps: - - name: Install Dependencies for Ubuntu - # git >= 2.18 required for actions/checkout git support - run: apt-get update && apt-get install -y software-properties-common && add-apt-repository -y ppa:git-core/ppa && apt-get update && apt-get install -y git build-essential clang libssl-dev libkrb5-dev libc++-dev wget - env: - ACTIONS_ALLOW_UNSECURE_COMMANDS: true - - - name: Setup python 3.6 - env: - CC: clang - CXX: clang++ + - name: prerequisites run: | - mkdir ~/python - cd ~/python - wget https://www.python.org/ftp/python/3.6.15/Python-3.6.15.tgz - tar -xvf Python-3.6.15.tgz - cd Python-3.6.15 - ./configure - make - make install - - - name: Setup Environment + apt-get update + apt-get install -y software-properties-common git build-essential clang libssl-dev libkrb5-dev libc++-dev wget python3 + - uses: actions/checkout@v4 + with: + submodules: true + - uses: actions/setup-node@v4 + with: + node-version: 20 + check-latest: true + - name: Test run: | + set -xe mkdir ~/.ssh_tests chmod 700 ~/.ssh_tests printf "%b" "Host *\n\tStrictHostKeyChecking no\n" > ~/.ssh_tests/config printf "%b" "ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDBkHMoNRRkHYNE7EnQLdFxMgVcqGgNPYDhrWiLMlYuzpmEcUnhwW3zNaIa4J2JlGkRNgYZVia1Ic1V3koJPE3YO2+exAfJBIPeb6O1qDADc2hFFHzd28wmHKUkO61yzo2ZjDQfaEVtjN39Yiy19AbddN3bzNrgvuQT574fa6Rghl2RfecKYO77iHA1RGXIFc8heXVIUuUV/jHjb56Wqo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SN1LWHxIITVUj3BmcWqUCgYEAwZ45\nWdaHfK7G6GjI7liDQT4ZlslA8dmLv2Jl2ExBBMoY3m3Sre428z2ZFa4O/nsBYP0a\nDxgYmX20fQGcbPugKdCYHc7HkKbMU1GwiVCGpDYZCm2gJKTvam3dYNaiAfq5DyhP\nzDCZNJ5rrSMprXsuRv2O4c5u8qtJ5ByaOJBjOr0CgYBMlkAxzkpUssS5CaaZDiLv\nLbfEr3HRLjYdc5KpzLBQ8NpJzhmfiIJsK1Wf8B0qb2J1XJg2Oy0KwFOgPbWIoryY\nSg19Pq98Cdn1UWCOrSabr8ZIaKe55WTgGcc8/O3k6BsNfaO9PJZfSssNUlCCtml1\n18u+uo9RJPhPDBd7Gj7r8QKBgFraxWy7t24xkZMDgK4fiM/3tQhFvhz/CY2wPbxG\n5Ae8UfkmLcOCUfTIReqfd9fAnsAFZNIKa5izHRu/wsh9NwYIJSlvm8PsEVtTrPRy\nfgvWet+i24/2eYZGsag8b19gaLCNKQzXDT1czYg8RNVsRSX427BoLzXeXNkW9uNu\nFbI9AoGAV2kxcdcKS4BtNHKPeGgV87dM0DWhQaAtEXEIcQquFtba0lAXioGHg8U4\nzeiugl4Qzchwk5qd3wnZ4SOhx0s16/5gQDlnkbjFR6EREUnvLRwV92zBXUTOGIkh\nZ7Z4rcgUKlVAaHT3OHN/lTyqJG/ib+K4wZhbztl/ox+JUFsvD98=\n-----END RSA PRIVATE KEY-----\n" > ~/.ssh_tests/id_rsa + ls ~/.ssh_tests chmod 600 ~/.ssh_tests/id_rsa* git config --global user.name "John Doe" git config --global user.email johndoe@example.com - # v4 requires node 20, which won't run due to GLIBC 2.28+ requirement - - uses: actions/checkout@v3 + eval "$(ssh-agent -s)" + ssh-add ~/.ssh_tests/id_rsa - - name: Use Node.js - # v4 requires node 20, which won't run due to GLIBC 2.28+ requirement - uses: actions/setup-node@v3 - env: - ACTIONS_ALLOW_UNSECURE_COMMANDS: true + npm install + npm test + + mac-test: + name: "macOS tests" + env: + CC: clang + CXX: clang++ + npm_config_clang: 1 + GYP_DEFINES: use_obsolete_asm=true + runs-on: macos-13 + steps: + - uses: actions/checkout@v4 + with: + submodules: true + - uses: actions/setup-node@v4 with: - node-version: ${{ matrix.node }} + node-version: 20 check-latest: true - - - name: Install - env: - CC: clang - CXX: clang++ - npm_config_clang: 1 - GYP_DEFINES: use_obsolete_asm=true - # There is a race condition in node/generate that needs to be fixed - # Node 16 changed the logic it uses to select it's UID which means to make node run as root and not 1001, we need to chwon the current directory. More Details: - # https://stackoverflow.com/questions/70298238/getting-eaccess-when-running-npm-8-as-root - run: | - chown root.root -R . - npm set unsafe-perm true - node utils/retry npm install - - name: Test run: | - set -e - eval `ssh-agent -s` - ssh-add ~/.ssh_tests/id_rsa - node utils/retry npm test - - - name: Deploy - if: startsWith(github.ref, 'refs/tags/v') - env: - node_pre_gyp_bucket: ${{ secrets.node_pre_gyp_bucket }} - AWS_ACCESS_KEY_ID: ${{ secrets.node_pre_gyp_accessKeyId }} - AWS_SECRET_ACCESS_KEY: ${{ secrets.node_pre_gyp_secretAccessKey }} - run: | - npm install -g @mapbox/node-pre-gyp aws-sdk - node lifecycleScripts/clean - node-pre-gyp package - node-pre-gyp publish - - macos-tests: - name: "macOS Tests" - strategy: - matrix: - node: [16, 18, 20] - runs-on: macOS-12 - # This is mostly the same as the Linux steps, waiting for anchor support - # https://github.com/actions/runner/issues/1182 - steps: - - name: Setup Environment - run: | + set -xe mkdir ~/.ssh_tests chmod 700 ~/.ssh_tests printf "%b" "Host *\n\tStrictHostKeyChecking no\n" > ~/.ssh_tests/config printf "%b" "ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDBkHMoNRRkHYNE7EnQLdFxMgVcqGgNPYDhrWiLMlYuzpmEcUnhwW3zNaIa4J2JlGkRNgYZVia1Ic1V3koJPE3YO2+exAfJBIPeb6O1qDADc2hFFHzd28wmHKUkO61yzo2ZjDQfaEVtjN39Yiy19AbddN3bzNrgvuQT574fa6Rghl2Rfec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vg\nHg6cafE1is7d+l669bfjitlx+3muF2CYnylSN1LWHxIITVUj3BmcWqUCgYEAwZ45\nWdaHfK7G6GjI7liDQT4ZlslA8dmLv2Jl2ExBBMoY3m3Sre428z2ZFa4O/nsBYP0a\nDxgYmX20fQGcbPugKdCYHc7HkKbMU1GwiVCGpDYZCm2gJKTvam3dYNaiAfq5DyhP\nzDCZNJ5rrSMprXsuRv2O4c5u8qtJ5ByaOJBjOr0CgYBMlkAxzkpUssS5CaaZDiLv\nLbfEr3HRLjYdc5KpzLBQ8NpJzhmfiIJsK1Wf8B0qb2J1XJg2Oy0KwFOgPbWIoryY\nSg19Pq98Cdn1UWCOrSabr8ZIaKe55WTgGcc8/O3k6BsNfaO9PJZfSssNUlCCtml1\n18u+uo9RJPhPDBd7Gj7r8QKBgFraxWy7t24xkZMDgK4fiM/3tQhFvhz/CY2wPbxG\n5Ae8UfkmLcOCUfTIReqfd9fAnsAFZNIKa5izHRu/wsh9NwYIJSlvm8PsEVtTrPRy\nfgvWet+i24/2eYZGsag8b19gaLCNKQzXDT1czYg8RNVsRSX427BoLzXeXNkW9uNu\nFbI9AoGAV2kxcdcKS4BtNHKPeGgV87dM0DWhQaAtEXEIcQquFtba0lAXioGHg8U4\nzeiugl4Qzchwk5qd3wnZ4SOhx0s16/5gQDlnkbjFR6EREUnvLRwV92zBXUTOGIkh\nZ7Z4rcgUKlVAaHT3OHN/lTyqJG/ib+K4wZhbztl/ox+JUFsvD98=\n-----END RSA PRIVATE KEY-----\n" > ~/.ssh_tests/id_rsa + ls ~/.ssh_tests chmod 600 ~/.ssh_tests/id_rsa* git config --global user.name "John Doe" git config --global user.email johndoe@example.com - - uses: actions/checkout@v4 - - - name: Use Node.js - uses: actions/setup-node@v4 - env: - ACTIONS_ALLOW_UNSECURE_COMMANDS: true - with: - node-version: ${{ matrix.node }} - check-latest: true - - - name: Install - env: - CC: clang - CXX: clang++ - npm_config_clang: 1 - GYP_DEFINES: use_obsolete_asm=true - # There is a race condition in node/generate that needs to be fixed - run: node utils/retry npm install - - - name: Test - run: | - set -e - eval `ssh-agent -s` + eval "$(ssh-agent -s)" ssh-add ~/.ssh_tests/id_rsa - node utils/retry npm test - - - name: Deploy - if: startsWith(github.ref, 'refs/tags/v') - env: - node_pre_gyp_bucket: ${{ secrets.node_pre_gyp_bucket }} - AWS_ACCESS_KEY_ID: ${{ secrets.node_pre_gyp_accessKeyId }} - AWS_SECRET_ACCESS_KEY: ${{ secrets.node_pre_gyp_secretAccessKey }} - run: | - npm install -g @mapbox/node-pre-gyp aws-sdk - node lifecycleScripts/clean - node-pre-gyp package - node-pre-gyp publish - - windows-tests: - name: Windows Tests - strategy: - matrix: - node: [16, 18, 20] - arch: [x86, x64] - runs-on: windows-2019 - steps: - - name: Setup Environment - run: | - git config --file C:\ProgramData\Git\config core.autocrlf input - git config --system core.autocrlf input - git config --global core.autocrlf input - git config --global user.name "John Doe" - git config --global user.email johndoe@example.com - - - uses: actions/checkout@v4 - - - name: Use Node.js - uses: actions/setup-node@v4 - env: - ACTIONS_ALLOW_UNSECURE_COMMANDS: true - with: - node-version: ${{ matrix.node }} - check-latest: true - architecture: ${{ matrix.arch }} - - - name: Install - run: npm install - - - name: Test - env: - GIT_SSH: ${{ github.workspace }}\vendor\plink.exe - run: | - powershell -command "Start-Process ${{ github.workspace }}\vendor\pageant.exe ${{ github.workspace }}\vendor\private.ppk" - node utils/retry npm test - - # You're probably wondering why this isn't a single `run: |` step, it certainly is for *nix, - # but it's not, because the CI runner for windows doesn't wait for each step as listed here - # and it treats each additional step past the first as an orphaned process. - - name: Deploy (Dependencies) - if: startsWith(github.ref, 'refs/tags/v') - run: npm install -g @mapbox/node-pre-gyp aws-sdk - - - name: Deploy (Clean) - if: startsWith(github.ref, 'refs/tags/v') - run: node lifecycleScripts\clean - - - name: Deploy (Package) - if: startsWith(github.ref, 'refs/tags/v') - run: node-pre-gyp package - - name: Deploy (Publish) - if: startsWith(github.ref, 'refs/tags/v') - env: - node_pre_gyp_bucket: ${{ secrets.node_pre_gyp_bucket }} - AWS_ACCESS_KEY_ID: ${{ secrets.node_pre_gyp_accessKeyId }} - AWS_SECRET_ACCESS_KEY: ${{ secrets.node_pre_gyp_secretAccessKey }} - run: node-pre-gyp publish + npm install + npm test diff --git a/.gitignore b/.gitignore index 99a83fc4a..6c58abbb9 100644 --- a/.gitignore +++ b/.gitignore @@ -47,3 +47,6 @@ jsconfig.json test/id_rsa test/nodegit-test-rsa + +gibberish +prebuilds diff --git a/.npmignore b/.npmignore index 046bdf56a..1a87c3d5f 100644 --- a/.npmignore +++ b/.npmignore @@ -3,12 +3,15 @@ /examples/ /generate/ /guides/ -/lib/ /test/ -/vendor/Release/ -!/include -!/src +# we never want npm installs to build from source. Exclude these 10k+ files from the package. +/include/ +/src/ +/vendor/ + +# we do need the libgit2.gyp file though, so node-gyp can run +!/vendor/libgit2.gyp .astylerc .editorconfig diff --git a/README.md b/README.md index 72442d791..4354c2f83 100644 --- a/README.md +++ b/README.md @@ -6,15 +6,16 @@ **Stable (libgit2@v0.28.3): 0.28.3** -## Have a problem? Come chat with us! ## +## Have a problem? Come chat with us! Visit [slack.libgit2.org](http://slack.libgit2.org/) to sign up, then join us in #nodegit. -## Maintained by ## -Tyler Ang-Wanek [@twwanek](http://twitter.com/twwanek) with help from tons of -[awesome contributors](https://github.com/nodegit/nodegit/contributors)! +## Maintained by + +Readme + +### Alumni Maintainers -### Alumni Maintainers ### Tim Branyen [@tbranyen](http://twitter.com/tbranyen), John Haley [@johnhaley81](http://twitter.com/johnhaley81), Max Korp [@maxkorp](http://twitter.com/MaximilianoKorp), @@ -22,16 +23,16 @@ Steve Smith [@orderedlist](https://twitter.com/orderedlist), Michael Robinson [@codeofinterest](http://twitter.com/codeofinterest), and Nick Kallen [@nk](http://twitter.com/nk) -## API Documentation. ## +## API Documentation. [http://www.nodegit.org/](http://www.nodegit.org/) -## Getting started. ## +## Getting started. NodeGit will work on most systems out-of-the-box without any native dependencies. -``` bash +```bash npm install nodegit ``` @@ -41,7 +42,7 @@ libstdc++-4.9. In Ubuntu: -``` sh +```sh sudo add-apt-repository ppa:ubuntu-toolchain-r/test sudo apt-get update sudo apt-get install libstdc++-4.9-dev @@ -49,7 +50,7 @@ sudo apt-get install libstdc++-4.9-dev In Travis: -``` yaml +```yaml addons: apt: sources: @@ -60,64 +61,66 @@ addons: In CircleCI: -``` yaml - dependencies: - pre: - - sudo add-apt-repository -y ppa:ubuntu-toolchain-r/test - - sudo apt-get update - - sudo apt-get install -y libstdc++-4.9-dev +```yaml +dependencies: + pre: + - sudo add-apt-repository -y ppa:ubuntu-toolchain-r/test + - sudo apt-get update + - sudo apt-get install -y libstdc++-4.9-dev ``` -If you receive errors about *lifecycleScripts* preinstall/install you probably miss *libssl-dev* +If you receive errors about _lifecycleScripts_ preinstall/install you probably miss _libssl-dev_ In Ubuntu: + ``` sudo apt-get install libssl-dev ``` You will need the following libraries installed on your linux machine: - - libpcre - - libpcreposix - - libkrb5 - - libk5crypto - - libcom_err + +- libpcre +- libpcreposix +- libkrb5 +- libk5crypto +- libcom_err When building locally, you will also need development packages for kerberos and pcre, so both of these utilities must be present on your machine: - - pcre-config - - krb5-config +- pcre-config +- krb5-config If you are still encountering problems while installing, you should try the [Building from source](http://www.nodegit.org/guides/install/from-source/) instructions. -## API examples. ## +## API examples. -### Cloning a repository and reading a file: ### +### Cloning a repository and reading a file: -``` javascript +```javascript var Git = require("nodegit"); // Clone a given repository into the `./tmp` folder. Git.Clone("https://github.com/nodegit/nodegit", "./tmp") // Look up this known commit. - .then(function(repo) { + .then(function (repo) { // Use a known commit sha from this repository. return repo.getCommit("59b20b8d5c6ff8d09518454d4dd8b7b30f095ab5"); }) // Look up a specific file within that commit. - .then(function(commit) { + .then(function (commit) { return commit.getEntry("README.md"); }) // Get the blob contents from the file. - .then(function(entry) { + .then(function (entry) { // Patch the blob to contain a reference to the entry. - return entry.getBlob().then(function(blob) { + return entry.getBlob().then(function (blob) { blob.entry = entry; return blob; }); }) // Display information about the blob. - .then(function(blob) { + .then(function (blob) { // Show the path, sha, and filesize in bytes. console.log(blob.entry.path() + blob.entry.sha() + blob.rawsize() + "b"); @@ -127,23 +130,24 @@ Git.Clone("https://github.com/nodegit/nodegit", "./tmp") // Show the entire file. console.log(String(blob)); }) - .catch(function(err) { console.log(err); }); - + .catch(function (err) { + console.log(err); + }); ``` -### Emulating git log: ### +### Emulating git log: -``` javascript +```javascript var Git = require("nodegit"); // Open the repository directory. Git.Repository.open("tmp") // Open the master branch. - .then(function(repo) { + .then(function (repo) { return repo.getMasterCommit(); }) // Display information about commits on master. - .then(function(firstCommitOnMaster) { + .then(function (firstCommitOnMaster) { // Create a new history event emitter. var history = firstCommitOnMaster.history(); @@ -151,7 +155,7 @@ Git.Repository.open("tmp") var count = 0; // Listen for commit events from the history. - history.on("commit", function(commit) { + history.on("commit", function (commit) { // Disregard commits past 9. if (++count >= 9) { return; @@ -180,10 +184,10 @@ Git.Repository.open("tmp") For more examples, check the `examples/` folder. -## Unit tests. ## +## Unit tests. -You will need to build locally before running the tests. See above. +You will need to build locally before running the tests. See above. -``` bash +```bash npm test ``` diff --git a/generate/templates/templates/nodegit.js b/generate/templates/templates/nodegit.js index 43e7d9de0..c5fd769eb 100644 --- a/generate/templates/templates/nodegit.js +++ b/generate/templates/templates/nodegit.js @@ -1,26 +1,13 @@ var _ = require("lodash"); var util = require("util"); +var path = require("path"); var worker; try { worker = require("worker_threads"); } catch (e) {} -var rawApi; - -// Attempt to load the production release first, if it fails fall back to the -// debug release. -try { - rawApi = require("../build/Release/nodegit.node"); -} -catch (ex) { - /* istanbul ignore next */ - if (ex.code !== "MODULE_NOT_FOUND") { - throw ex; - } - - rawApi = require("../build/Debug/nodegit.node"); -} +var rawApi = require("node-gyp-build")(path.join(__dirname, "..")); var promisify = fn => fn && util.promisify(fn); // jshint ignore:line diff --git a/lifecycleScripts/install.js b/lifecycleScripts/install.js index ddbb90e9c..313cedec6 100755 --- a/lifecycleScripts/install.js +++ b/lifecycleScripts/install.js @@ -1,21 +1,13 @@ var buildFlags = require("../utils/buildFlags"); -var spawn = require("child_process").spawn; -var path = require("path"); -module.exports = function install() { +module.exports = async function install() { console.log("[nodegit] Running install script"); - var nodePreGyp = "node-pre-gyp"; - - if (process.platform === "win32") { - nodePreGyp += ".cmd"; - } - var args = ["install"]; if (buildFlags.mustBuild) { console.info( - "[nodegit] Pre-built download disabled, building from source." + "[nodegit] Pre-built download disabled, building from source.", ); args.push("--build-from-source"); @@ -23,48 +15,18 @@ module.exports = function install() { console.info("[nodegit] Building debug version."); args.push("--debug"); } - } - else { + } else { args.push("--fallback-to-build"); } - return new Promise(function(resolve, reject) { - const gypPath = path.join(__dirname, "..", "node_modules", "node-gyp", "bin", "node-gyp.js"); - var spawnedNodePreGyp = spawn(nodePreGyp, args, { - env: { - ...process.env, - npm_config_node_gyp: gypPath - }, - shell: process.platform === "win32" - }); - - spawnedNodePreGyp.stdout.on("data", function(data) { - console.info(data.toString().trim()); - }); - - spawnedNodePreGyp.stderr.on("data", function(data) { - console.error(data.toString().trim()); - }); - - spawnedNodePreGyp.on("close", function(code) { - if (!code) { - resolve(); - } else { - reject(code); - } - }); - }) - .then(function() { - console.info("[nodegit] Completed installation successfully."); - }); + return; }; // Called on the command line if (require.main === module) { - module.exports() - .catch(function(e) { - console.error("[nodegit] ERROR - Could not finish install"); - console.error("[nodegit] ERROR - finished with error code: " + e); - process.exit(e); - }); + module.exports().catch(function (e) { + console.error("[nodegit] ERROR - Could not finish install"); + console.error("[nodegit] ERROR - finished with error code: " + e); + process.exit(e); + }); } diff --git a/lifecycleScripts/submodules/getStatus.js b/lifecycleScripts/submodules/getStatus.js index 2fcc42d37..c53835c6a 100644 --- a/lifecycleScripts/submodules/getStatus.js +++ b/lifecycleScripts/submodules/getStatus.js @@ -3,8 +3,8 @@ var rootDir = path.join(__dirname, "../.."); var exec = require(path.join(rootDir, "./utils/execPromise")); module.exports = function getStatus() { - return exec("git submodule status", { cwd: rootDir}) - .then(function(stdout) { + return exec("git submodule status", { cwd: rootDir }) + .then(function (stdout) { if (!stdout) { // In the case where we pull from npm they pre-init the submodules for // us and `git submodule status` returns empty-string. In that case @@ -19,8 +19,8 @@ module.exports = function getStatus() { var commitOid = lineSections[0].replace("+", "").replace("-", ""); var name = lineSections[1]; - return exec("git status", { cwd: path.join(rootDir, name)}) - .then(function(workDirStatus) { + return exec("git status", { cwd: path.join(rootDir, name) }).then( + function (workDirStatus) { return { commitOid: commitOid, onNewCommit: onNewCommit, @@ -30,18 +30,18 @@ module.exports = function getStatus() { .trim() .split("\n") .pop() - .indexOf("nothing to commit") + .indexOf("nothing to commit"), }; - }); + }, + ); } - return Promise.all(stdout - .trim() - .split("\n") - .map(getStatusPromiseFromLine) + return Promise.all( + stdout.trim().split("\n").map(getStatusPromiseFromLine), ); }) - .catch(function() { + .catch(function (err) { + console.error("[readme] failure to get submodule status:", err); // In the case that NodeGit is required from another project via npm we // won't be able to run submodule commands but that's ok since the // correct version of libgit2 is published with nodegit. diff --git a/lifecycleScripts/submodules/index.js b/lifecycleScripts/submodules/index.js index 2d13d3c89..ab8a34f6b 100644 --- a/lifecycleScripts/submodules/index.js +++ b/lifecycleScripts/submodules/index.js @@ -2,7 +2,7 @@ var path = require("path"); var rootDir = path.join(__dirname, "../.."); var gitExecutableLocation = require( - path.join(rootDir, "./utils/gitExecutableLocation") + path.join(rootDir, "./utils/gitExecutableLocation"), ); var submoduleStatus = require("./getStatus"); @@ -10,73 +10,75 @@ var exec = require(path.join(rootDir, "./utils/execPromise")); module.exports = function submodules() { return gitExecutableLocation() - .catch(function() { - console.error("[nodegit] ERROR - Compilation of NodeGit requires git " + - "CLI to be installed and on the path"); + .catch(function () { + console.error( + "[nodegit] ERROR - Compilation of NodeGit requires git " + + "CLI to be installed and on the path", + ); throw new Error("git CLI is not installed or not on the path"); }) - .then(function() { + .then(function () { console.log("[nodegit] Checking submodule status"); return submoduleStatus(); }) - .then(function(statuses) { + .then(function (statuses) { + console.log("[readme] submodule status: ", statuses); function printSubmodule(submoduleName) { console.log("\t" + submoduleName); } var dirtySubmodules = statuses - .filter(function(status) { - return status.workDirDirty && !status.needsInitialization; - }) - .map(function(dirtySubmodule) { - return dirtySubmodule.name; - }); + .filter(function (status) { + return status.workDirDirty && !status.needsInitialization; + }) + .map(function (dirtySubmodule) { + return dirtySubmodule.name; + }); if (dirtySubmodules.length) { console.error( - "[nodegit] ERROR - Some submodules have uncommited changes:" + "[nodegit] ERROR - Some submodules have uncommited changes:", ); dirtySubmodules.forEach(printSubmodule); console.error( - "\nThey must either be committed or discarded before we build" + "\nThey must either be committed or discarded before we build", ); throw new Error("Dirty Submodules: " + dirtySubmodules.join(" ")); } var outOfSyncSubmodules = statuses - .filter(function(status) { + .filter(function (status) { return status.onNewCommit && !status.needsInitialization; }) - .map(function(outOfSyncSubmodule) { + .map(function (outOfSyncSubmodule) { return outOfSyncSubmodule.name; }); if (outOfSyncSubmodules.length) { console.warn( - "[nodegit] WARNING - Some submodules are pointing to an new commit:" + "[nodegit] WARNING - Some submodules are pointing to an new commit:", ); outOfSyncSubmodules.forEach(printSubmodule); console.warn("\nThey will not be updated."); } return statuses - .filter(function(status) { + .filter(function (status) { return !status.onNewCommit; }) - .reduce(function(chainPromise, submoduleToUpdate) { - return chainPromise - .then(function() { - console.log( - "[nodegit] Initializing submodule", - submoduleToUpdate.name - ); - return exec( - "git submodule update --init --recursive " + - submoduleToUpdate.name - ); - }); + .reduce(function (chainPromise, submoduleToUpdate) { + return chainPromise.then(function () { + console.log( + "[nodegit] Initializing submodule", + submoduleToUpdate.name, + ); + return exec( + "git submodule update --init --recursive " + + submoduleToUpdate.name, + ); + }); }, Promise.resolve()); }); }; diff --git a/package-lock.json b/package-lock.json index 799afbdea..fcdc740ef 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "nodegit", - "version": "0.28.0-alpha.26", + "version": "1.0.0-alpha.2", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "nodegit", - "version": "0.28.0-alpha.26", + "version": "1.0.0-alpha.2", "hasInstallScript": true, "license": "MIT", "dependencies": { @@ -17,6 +17,7 @@ "json5": "^2.1.0", "lodash": "^4.17.14", "node-gyp": "^10.0.1", + "node-gyp-build": "^4.8.1", "ramda": "^0.25.0", "tar-fs": "^2.1.1" }, @@ -3231,6 +3232,16 @@ "node": "^16.14.0 || >=18.0.0" } }, + "node_modules/node-gyp-build": { + "version": "4.8.1", + "resolved": "https://registry.npmjs.org/node-gyp-build/-/node-gyp-build-4.8.1.tgz", + "integrity": "sha512-OSs33Z9yWr148JZcbZd5WiAXhh/n9z8TxQcdMhIOlpN9AhWpLfvVFO73+m77bBABQMaY9XSvIa+qk0jlI7Gcaw==", + "bin": { + "node-gyp-build": "bin.js", + "node-gyp-build-optional": "optional.js", + "node-gyp-build-test": "build-test.js" + } + }, "node_modules/node-gyp/node_modules/abbrev": { "version": "2.0.0", "resolved": "https://registry.npmjs.org/abbrev/-/abbrev-2.0.0.tgz", @@ -7389,6 +7400,11 @@ } } }, + "node-gyp-build": { + "version": "4.8.1", + "resolved": "https://registry.npmjs.org/node-gyp-build/-/node-gyp-build-4.8.1.tgz", + "integrity": "sha512-OSs33Z9yWr148JZcbZd5WiAXhh/n9z8TxQcdMhIOlpN9AhWpLfvVFO73+m77bBABQMaY9XSvIa+qk0jlI7Gcaw==" + }, "nopt": { "version": "5.0.0", "resolved": "https://registry.npmjs.org/nopt/-/nopt-5.0.0.tgz", diff --git a/package.json b/package.json index e5f85e8f0..bb5fc6289 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { - "name": "nodegit", + "name": "@readme/nodegit", "description": "Node.js libgit2 asynchronous native bindings", - "version": "0.28.0-alpha.26", + "version": "1.0.0-alpha.2", "homepage": "http://nodegit.org", "keywords": [ "libgit2", @@ -26,10 +26,7 @@ } ], "main": "lib/nodegit.js", - "repository": { - "type": "git", - "url": "git://github.com/nodegit/nodegit.git" - }, + "repository": "github:readmeio/nodegit", "directories": { "build": "./build", "lib": "./lib" @@ -45,6 +42,7 @@ "json5": "^2.1.0", "lodash": "^4.17.14", "node-gyp": "^10.0.1", + "node-gyp-build": "^4.8.1", "ramda": "^0.25.0", "tar-fs": "^2.1.1" }, @@ -61,11 +59,6 @@ "mocha": "^5.2.0", "walk": "^2.3.9" }, - "binary": { - "module_name": "nodegit", - "module_path": "./build/Release/", - "host": "https://axonodegit.s3.amazonaws.com/nodegit/nodegit/" - }, "scripts": { "cov": "npm run cppcov && npm run filtercov && npm run mergecov", "coveralls": "cat ./test/coverage/merged.lcov | coveralls", @@ -74,7 +67,7 @@ "generateJson": "node generate/scripts/generateJson", "generateMissingTests": "node generate/scripts/generateMissingTests", "generateNativeCode": "node generate/scripts/generateNativeCode", - "install": "node lifecycleScripts/preinstall && node lifecycleScripts/install", + "install": "node lifecycleScripts/preinstall.js && node-gyp-build", "installDebug": "BUILD_DEBUG=true npm install", "lint": "jshint lib test/tests test/utils lifecycleScripts", "mergecov": "lcov-result-merger 'test/**/*.info' 'test/coverage/merged.lcov' && ./lcov-1.10/bin/genhtml test/coverage/merged.lcov --output-directory test/coverage/report", diff --git a/test/index.js b/test/index.js index 4891a0dba..544ac3dc4 100644 --- a/test/index.js +++ b/test/index.js @@ -3,7 +3,7 @@ var path = require("path"); var fs = require('fs'); var bin = "./node_modules/.bin/istanbul"; -var cov = "cover --report=lcov --dir=test/coverage/js _mocha --".split(" "); +var cov = "cover --report=lcov --dir=test/coverage/js node_modules/.bin/_mocha --".split(" "); if (process.platform === 'win32') { bin = "./node_modules/mocha/bin/mocha";