From a9b409180a037be3cd95e9b625ef3f64ee9a7dbf Mon Sep 17 00:00:00 2001 From: Amin Yahyaabadi Date: Wed, 28 Apr 2021 05:27:16 -0500 Subject: [PATCH 1/6] Add node-gyp-build --- binding.js | 2 ++ package.json | 4 +++- 2 files changed, 5 insertions(+), 1 deletion(-) create mode 100644 binding.js diff --git a/binding.js b/binding.js new file mode 100644 index 0000000..3da4000 --- /dev/null +++ b/binding.js @@ -0,0 +1,2 @@ +// don't move this file. It should be next to package.json +module.exports = require('node-gyp-build')(__dirname); diff --git a/package.json b/package.json index 8d7dd79..9a2500a 100644 --- a/package.json +++ b/package.json @@ -4,6 +4,7 @@ "description": "A simple file watcher for Node", "main": "js/src/index.js", "scripts": { + "install": "node-gyp-build", "lint": "eslint js/src js/spec", "test": "yarn lint && node js/scripts/test.js" }, @@ -29,7 +30,8 @@ ], "homepage": "https://github.com/axosoft/node-simple-file-watcher", "dependencies": { - "node-addon-api": "*" + "node-addon-api": "*", + "node-gyp-build": "^4.2.3" }, "devDependencies": { "eslint": "^6.8.0", From 16470ad7d14e52ad68ff4f94a75ec53ef788ff1b Mon Sep 17 00:00:00 2001 From: Amin Yahyaabadi Date: Wed, 28 Apr 2021 05:27:58 -0500 Subject: [PATCH 2/6] Add prebuildify and prebuild script --- .gitignore | 1 + js/scripts/prebuild.js | 39 +++++++++++++++++++++++++++++++++++++++ js/src/index.js | 2 +- package.json | 9 ++++++--- 4 files changed, 47 insertions(+), 4 deletions(-) create mode 100644 js/scripts/prebuild.js diff --git a/.gitignore b/.gitignore index 32d251b..2ecb07d 100644 --- a/.gitignore +++ b/.gitignore @@ -21,6 +21,7 @@ coverage # Compiled binary addons (http://nodejs.org/api/addons.html) build/Release +prebuilds # Dependency directory # https://www.npmjs.org/doc/misc/npm-faq.html#should-i-check-my-node_modules-folder-into-git diff --git a/js/scripts/prebuild.js b/js/scripts/prebuild.js new file mode 100644 index 0000000..0a0ac86 --- /dev/null +++ b/js/scripts/prebuild.js @@ -0,0 +1,39 @@ +const {spawnSync} = require('child_process'); + +main().catch(e => { + throw e; +}); + +async function main() { + console.log('Building distribution binary...'); // eslint-disable-line no-console + + const prebuildArch = getNodearch(process.env.ARCH); + + // napi is forward compatible so we only build for two targets (Node and Electron) + let prebuildScript = `prebuildify --napi --arch=${prebuildArch} -t 12.0.0 -t electron@9.4.4 --strip`; + + if (process.platform == 'linux') { + prebuildScript = `${prebuildScript} --tag-libc`; + } + + spawnSync(prebuildScript, { + shell: true, + stdio: 'inherit', + encoding: 'utf8', + }); +} + +/** + * @param {string | undefined} arch the given architecture + * @returns {string} the Node architecture to build for + */ +function getNodearch(arch) { + if (!arch) { + return process.arch; + } + if (arch === 'x86') { + return 'ia32'; + } else { + return arch; + } +} diff --git a/js/src/index.js b/js/src/index.js index bdddb31..e44e926 100644 --- a/js/src/index.js +++ b/js/src/index.js @@ -1,7 +1,7 @@ const { promises: fs } = require('fs'); const path = require('path'); -const NSFW = require('../../build/Release/nsfw.node'); +const NSFW = require('../../binding'); function NSFWFilePoller(watchPath, eventCallback, debounceMS) { const { CREATED, DELETED, MODIFIED } = nsfw.actions; diff --git a/package.json b/package.json index 9a2500a..eaafb69 100644 --- a/package.json +++ b/package.json @@ -6,7 +6,8 @@ "scripts": { "install": "node-gyp-build", "lint": "eslint js/src js/spec", - "test": "yarn lint && node js/scripts/test.js" + "test": "yarn lint && node js/scripts/test.js", + "prebuild": "node ./js/scripts/prebuild.js" }, "repository": { "type": "git", @@ -26,7 +27,8 @@ "js/src", "src", "includes", - "binding.gyp" + "binding.gyp", + "prebuilds" ], "homepage": "https://github.com/axosoft/node-simple-file-watcher", "dependencies": { @@ -37,7 +39,8 @@ "eslint": "^6.8.0", "executive": "^1.6.3", "fs-extra": "^7.0.0", - "mocha": "^7.1.1" + "mocha": "^7.1.1", + "prebuildify": "^4.1.2" }, "keywords": [ "FileWatcher", From b06803a8417d6a0462f0b28b5bc9bf8d4e1e14d9 Mon Sep 17 00:00:00 2001 From: Amin Yahyaabadi Date: Wed, 28 Apr 2021 05:28:13 -0500 Subject: [PATCH 3/6] Add prebuild job to GitHub Actions --- .github/workflows/tests.yaml | 39 ++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) diff --git a/.github/workflows/tests.yaml b/.github/workflows/tests.yaml index 1cd06b1..c7260fb 100644 --- a/.github/workflows/tests.yaml +++ b/.github/workflows/tests.yaml @@ -27,3 +27,42 @@ jobs: - run: yarn - run: yarn test + + prebuild: + runs-on: ${{ matrix.os }} + strategy: + fail-fast: false + matrix: + os: + - ubuntu-20.04 + - macos-latest + - windows-latest + node_version: + - 14 + node_arch: + - x64 + include: + - os: windows-latest + node_version: 14 + node_arch: x86 + steps: + - uses: actions/checkout@v2 + + - name: Install Node + uses: actions/setup-node@v2 + with: + node-version: ${{ matrix.node_version }} + architecture: ${{ matrix.node_arch }} + + - name: Install Dependencies and Build + run: yarn + + - name: Prebuild + run: yarn run prebuild + env: + ARCH: ${{ matrix.node_arch }} + + - name: Upload artifacts + uses: actions/upload-artifact@v2 + with: + path: ./prebuilds From 6e745afebc272bce64d7feb02c49045b6d99e679 Mon Sep 17 00:00:00 2001 From: Amin Yahyaabadi Date: Wed, 28 Apr 2021 05:28:38 -0500 Subject: [PATCH 4/6] Add instructions for manual registration of a new npm version --- CONTRIBUTING.md | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 CONTRIBUTING.md diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md new file mode 100644 index 0000000..9e5e838 --- /dev/null +++ b/CONTRIBUTING.md @@ -0,0 +1,23 @@ +## Releasing a new npm version + +- Change the version in `package.json`, make a new git tag, and push it to GitHub. +- Wait until the GitHub Actions on the master branch pass. +- The artifacts of the latest GitHub Action run should be downloaded from the actions tab of the GitHub repository +- The artifacts.zip should be extracted and placed under the `prebuilds` folder (replacing the old folder if it exists). + + The `prebuilds` folder should look like the following. + ``` + repository-root + |-prebuilds + |_linux-x64 + |... + |_darwin-x64 + |... + |_win32-x64 + |... + ``` + +- Then: + ``` + npm publish + ``` From 09c5b356eeec022665c0883de212820267703f14 Mon Sep 17 00:00:00 2001 From: Amin Yahyaabadi Date: Wed, 28 Apr 2021 05:46:15 -0500 Subject: [PATCH 5/6] Use the prebuilds inside the test job --- .github/workflows/tests.yaml | 52 ++++++++++++++++++++++-------------- 1 file changed, 32 insertions(+), 20 deletions(-) diff --git a/.github/workflows/tests.yaml b/.github/workflows/tests.yaml index c7260fb..684e78c 100644 --- a/.github/workflows/tests.yaml +++ b/.github/workflows/tests.yaml @@ -8,27 +8,8 @@ on: name: Run Tests jobs: - - test: - name: Tests - strategy: - matrix: - node: [10, 12] - os: [windows-2016, ubuntu-16.04, ubuntu-18.04, macOS-latest] - runs-on: ${{ matrix.os }} - steps: - - uses: actions/checkout@master - - - name: Use Node.js ${{ matrix.node }} - uses: actions/setup-node@master - with: - node-version: ${{ matrix.node }} - - - run: yarn - - - run: yarn test - prebuild: + name: Prebuild runs-on: ${{ matrix.os }} strategy: fail-fast: false @@ -66,3 +47,34 @@ jobs: uses: actions/upload-artifact@v2 with: path: ./prebuilds + + test: + name: Tests + needs: prebuild + strategy: + matrix: + node: [10, 12] + os: [windows-2016, ubuntu-16.04, ubuntu-18.04, macOS-latest] + runs-on: ${{ matrix.os }} + steps: + - uses: actions/checkout@master + + - name: Use Node.js ${{ matrix.node }} + uses: actions/setup-node@master + with: + node-version: ${{ matrix.node }} + + - run: yarn + + - name: Download prebuilds + uses: actions/download-artifact@v2 + + - name: Install prebuilds + shell: bash + run: | + rm -rf build + mkdir prebuilds + mv artifact/* prebuilds/ + ls prebuilds + + - run: yarn test From 62945c453d78b5989177f22e61c907b7257b4b9f Mon Sep 17 00:00:00 2001 From: Amin Yahyaabadi Date: Wed, 28 Apr 2021 05:49:59 -0500 Subject: [PATCH 6/6] Test windows x86 in the test job --- .github/workflows/tests.yaml | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/.github/workflows/tests.yaml b/.github/workflows/tests.yaml index 684e78c..f96ee71 100644 --- a/.github/workflows/tests.yaml +++ b/.github/workflows/tests.yaml @@ -55,6 +55,12 @@ jobs: matrix: node: [10, 12] os: [windows-2016, ubuntu-16.04, ubuntu-18.04, macOS-latest] + node_arch: + - x64 + include: + - os: windows-latest + node: 14 + node_arch: x86 runs-on: ${{ matrix.os }} steps: - uses: actions/checkout@master @@ -63,8 +69,7 @@ jobs: uses: actions/setup-node@master with: node-version: ${{ matrix.node }} - - - run: yarn + architecture: ${{ matrix.node_arch }} - name: Download prebuilds uses: actions/download-artifact@v2 @@ -77,4 +82,6 @@ jobs: mv artifact/* prebuilds/ ls prebuilds + - run: yarn + - run: yarn test