diff --git a/.github/workflows/update-dep.yml b/.github/workflows/update-dep.yml new file mode 100644 index 000000000..6cd2fd7cf --- /dev/null +++ b/.github/workflows/update-dep.yml @@ -0,0 +1,71 @@ +# Update a dependency On-Demand + +name: Update dependency On-Demand + +on: + workflow_dispatch: + inputs: + dep: + description: 'Dependency' + required: true + default: '@yao-pkg/pkg-fetch' + version: + description: 'Version' + required: false + default: '' + +jobs: + build: + runs-on: ubuntu-latest + permissions: + contents: write + pull-requests: write + + steps: + - uses: actions/checkout@v3 + + - name: Use Node.js 20 + uses: actions/setup-node@v3.6.0 + with: + node-version: 20.x + cache: 'yarn' + + - name: Update dependency + run: | + yarn add ${{github.event.inputs.dep}}@${{github.event.inputs.version || 'latest'}} + - name: Check for changes + id: check + run: | + git diff --name-only || true + if ! git diff --quiet ; then + echo "Has changes" + echo "changed=true" >> $GITHUB_OUTPUT + VERSION=$(npm info ${{github.event.inputs.dep}} version) + echo "version=$VERSION" >> $GITHUB_OUTPUT + else + echo "No changes detected. Dependency already up to date" + echo "changed=false" >> $GITHUB_OUTPUT + fi + - name: Create Pull Request + if: ${{ steps.check.outputs.changed == 'true' }} + id: cpr + uses: peter-evans/create-pull-request@v4 + with: + token: ${{ secrets.GITHUB_TOKEN }} + commit-message: "feat: bump ${{github.event.inputs.dep}}@${{ steps.check.outputs.version }}" + branch: "${{github.event.inputs.dep}}@${{ steps.check.outputs.version }}" + delete-branch: true + title: "feat: bump ${{github.event.inputs.dep}}@${{ steps.check.outputs.version }}" + body: | + Update ${{github.event.inputs.dep}} to version ${{ steps.check.outputs.version }} + labels: | + dependencies + workflow-bump + base: main + draft: false + + - name: Check outputs + if: ${{ steps.check.outputs.changed == 'true' }} + run: | + echo "Pull Request Number - ${{ steps.cpr.outputs.pull-request-number }}" + echo "Pull Request URL - ${{ steps.cpr.outputs.pull-request-url }}" diff --git a/CHANGELOG.md b/CHANGELOG.md index 893d2b64c..a37211423 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,13 @@ +## [5.11.4](https://github.com/yao-pkg/pkg/compare/v5.11.3...v5.11.4) (2024-02-16) + +### Features + +- pkg-fetch@3.5.9 with nodejs 18.19.1 and 20.11.1 ([d6485df](https://github.com/yao-pkg/pkg/commit/d6485df9a0b065be450600785d3a5d52108fddb6)) + +### Bug Fixes + +- tests ([#34](https://github.com/yao-pkg/pkg/issues/34)) ([7472af7](https://github.com/yao-pkg/pkg/commit/7472af714d1766f6a4f62cfdfe038d3291b5cd72)) + ## [5.11.3](https://github.com/yao-pkg/pkg/compare/v5.11.2...v5.11.3) (2024-02-12) ### Bug Fixes diff --git a/package.json b/package.json index 7790505be..ec8628647 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@yao-pkg/pkg", - "version": "5.11.3", + "version": "5.11.4", "description": "Package your Node.js project into an executable", "main": "lib-es5/index.js", "license": "MIT", @@ -25,7 +25,7 @@ "@babel/generator": "7.23.0", "@babel/parser": "7.23.0", "@babel/types": "7.23.0", - "@yao-pkg/pkg-fetch": "3.5.8", + "@yao-pkg/pkg-fetch": "3.5.9", "chalk": "^4.1.2", "fs-extra": "^9.1.0", "globby": "^11.1.0", @@ -74,10 +74,10 @@ "fix": "npm run lint:style -- -w && npm run lint:code -- --fix", "prepare": "npm run build", "prepublishOnly": "npm run lint", - "test": "npm run build && npm run test:18 && npm run test:16 && npm run test:14 && npm run test:host", + "test": "npm run build && npm run test:18 && npm run test:16 && npm run test:host", + "test:20": "node test/test.js node20 no-npm", "test:18": "node test/test.js node18 no-npm", "test:16": "node test/test.js node16 no-npm", - "test:14": "node test/test.js node14 no-npm", "test:host": "node test/test.js host only-npm", "release": "read -p 'GITHUB_TOKEN: ' GITHUB_TOKEN && export GITHUB_TOKEN=$GITHUB_TOKEN && release-it" }, diff --git a/test/test-79-npm/main.js b/test/test-79-npm/main.js index 65372754d..06f875976 100644 --- a/test/test-79-npm/main.js +++ b/test/test-79-npm/main.js @@ -28,6 +28,7 @@ const npm = { 14: 6, 16: 7, 18: 8, + 20: 10, }[hostVersion]; assert(npm !== undefined); diff --git a/test/test-80-compression-node-opcua/main.js b/test/test-80-compression-node-opcua/main.js index 04bfa8610..c93558611 100644 --- a/test/test-80-compression-node-opcua/main.js +++ b/test/test-80-compression-node-opcua/main.js @@ -12,6 +12,9 @@ const fs = require('fs'); const path = require('path'); const assert = require('assert'); const utils = require('../utils.js'); +const pkgJson = require('./package.json'); + +const buildDir = 'build'; assert(!module.parent); assert(__dirname === process.cwd()); @@ -20,9 +23,14 @@ if (utils.shouldSkipPnpm()) { return; } +function clean() { + utils.vacuum.sync(buildDir); + utils.vacuum.sync('node_modules'); + utils.vacuum.sync('./pnpm-lock.yaml'); +} + // remove any possible left-over -utils.vacuum.sync('./node_modules'); -utils.vacuum.sync('./pnpm-lock.yaml'); +clean(); // launch `pnpm install` const pnpmlog = utils.spawn.sync( @@ -47,11 +55,11 @@ assert( const input = 'package.json'; const target = process.argv[2] || 'host'; const ext = process.platform === 'win32' ? '.exe' : ''; -const outputRef = 'test-output-empty' + ext; -const outputNone = 'test-output-None' + ext; -const outputGZip = 'test-output-GZip' + ext; -const outputBrotli = 'test-output-Brotli' + ext; -const outputBrotliDebug = 'test-output-Brotli-debug' + ext; +const outputRef = path.join(buildDir, 'test-output-empty' + ext); +const outputNone = path.join(buildDir, 'test-output-None' + ext); +const outputGZip = path.join(buildDir, 'test-output-GZip' + ext); +const outputBrotli = path.join(buildDir, 'test-output-Brotli' + ext); +const outputBrotliDebug = path.join(buildDir, 'test-output-Brotli-debug' + ext); const inspect = ['ignore', 'ignore', 'pipe']; @@ -78,13 +86,40 @@ function pkgCompress(compressMode, output) { ); // check that produced executable is running and produce the expected output. const log = utils.spawn.sync(path.join(__dirname, output), [], { - cwd: __dirname, + cwd: path.join(__dirname, buildDir), expect: 0, }); assert(log === '42\n'); return fs.statSync(output).size; } +function esbuildBuild(entryPoint) { + const log = utils.spawn.sync( + path.join( + path.dirname(process.argv[0]), + 'npx' + (process.platform === 'win32' ? '.cmd' : ''), + ), + [ + 'esbuild', + entryPoint, + '--bundle', + '--outfile=' + path.join(buildDir, pkgJson.main), + '--platform=node', + ], + { cwd: __dirname, expect: 0 }, + ); + + console.log(log); + + // copy folder 'node_modules/node-opcua-nodesets' to build folder + utils.copyRecursiveSync( + 'node_modules/node-opcua-nodesets/nodesets', + path.join(buildDir, 'nodesets'), + ); +} + +esbuildBuild(pkgJson.main); + const sizeNoneFull = pkgCompress('None', outputNone); const sizeGZipFull = pkgCompress('GZip', outputGZip); const sizeBrotliFull = pkgCompress('Brotli', outputBrotli); @@ -121,15 +156,8 @@ const logPkg5 = utils.pkg.sync( { expect: 2 }, ); -// xx console.log(logPkg4); assert(logPkg5.match(/Invalid compression algorithm/g)); -utils.vacuum.sync(outputRef); -utils.vacuum.sync(outputNone); -utils.vacuum.sync(outputBrotli); -utils.vacuum.sync(outputGZip); -utils.vacuum.sync(outputBrotliDebug); -utils.vacuum.sync('node_modules'); -utils.vacuum.sync('./pnpm-lock.yaml'); +clean(); console.log('OK'); diff --git a/test/test-80-compression-node-opcua/package.json b/test/test-80-compression-node-opcua/package.json index fa88fb8f1..6a60ac5fb 100644 --- a/test/test-80-compression-node-opcua/package.json +++ b/test/test-80-compression-node-opcua/package.json @@ -2,6 +2,7 @@ "name": "test-12-compression", "version": "1.0.0", "description": "", + "bin": "build/test-x.js", "main": "test-x.js", "scripts": { "preinstall": "npx only-allow pnpm", @@ -15,7 +16,9 @@ "node-opcua-crypto": "^1.7.1", "node-opcua-nodesets": "^2.36.0" }, - "bin": "test-x.js", + "devDependencies": { + "esbuild": "^0.20.0" + }, "pkg": { "assets": [ "./node_modules/node-opcua-nodesets/nodesets/*.xml" diff --git a/test/utils.js b/test/utils.js index e699afac4..ec586fe11 100644 --- a/test/utils.js +++ b/test/utils.js @@ -7,7 +7,7 @@ const rimraf = require('rimraf'); const globby = require('globby'); const { execSync } = require('child_process'); const { spawnSync } = require('child_process'); -const { existsSync } = require('fs'); +const { existsSync, statSync, copyFileSync, readdirSync } = require('fs'); const stableStringify = require('json-stable-stringify'); module.exports.mkdirp = mkdirp; @@ -20,6 +20,22 @@ module.exports.pause = function (seconds) { ]); }; +module.exports.copyRecursiveSync = function (origin, dest) { + const stats = statSync(origin); + if (stats.isDirectory()) { + mkdirp.sync(dest); + const files = readdirSync(origin); + for (const file of files) { + module.exports.copyRecursiveSync( + path.join(origin, file), + path.join(dest, file), + ); + } + } else { + copyFileSync(origin, dest); + } +}; + module.exports.vacuum = function () { throw new Error('Async vacuum not implemented'); }; diff --git a/yarn.lock b/yarn.lock index 5aea7dd2e..01055f87b 100644 --- a/yarn.lock +++ b/yarn.lock @@ -640,10 +640,10 @@ "@typescript-eslint/types" "6.7.4" eslint-visitor-keys "^3.4.1" -"@yao-pkg/pkg-fetch@3.5.8": - version "3.5.8" - resolved "https://registry.yarnpkg.com/@yao-pkg/pkg-fetch/-/pkg-fetch-3.5.8.tgz#2601026f8ad8fbdaa0650db2a957d594b84bcb1e" - integrity sha512-WlM4+eRmF1p9M/wqBaYKnVkBwf60wurvMOU38HSx5xfkPg7e4XmBuTv8g/TAZPjSZaQPlz4+/03pUibK4gY55g== +"@yao-pkg/pkg-fetch@3.5.9": + version "3.5.9" + resolved "https://registry.yarnpkg.com/@yao-pkg/pkg-fetch/-/pkg-fetch-3.5.9.tgz#dbdb12f683183cba568b620ace660903222fae5a" + integrity sha512-usMwwqFCd2B7k+V87u6kiTesyDSlw+3LpiuYBWe+UgryvSOk/NXjx3XVCub8hQoi0bCREbdQ6NDBqminyHJJrg== dependencies: chalk "^4.1.2" fs-extra "^9.1.0"