From 67576a416336e34e7c3bcbf13824ab70bb083b54 Mon Sep 17 00:00:00 2001 From: Daniel Lando Date: Fri, 16 Feb 2024 14:11:17 +0100 Subject: [PATCH 1/7] fix: tests --- test/test-80-compression-node-opcua/main.js | 51 +++++++++++++------ .../package.json | 5 +- test/utils.js | 18 ++++++- 3 files changed, 56 insertions(+), 18 deletions(-) diff --git a/test/test-80-compression-node-opcua/main.js b/test/test-80-compression-node-opcua/main.js index 04bfa8610..512f8ff37 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,31 @@ 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(__dirname, 'node_modules/.bin/esbuild'), + [entryPoint, '--bundle', '--outfile=' + 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 +147,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'); }; From b3b138369cacd381ff0fe571c63973ecf81fef3e Mon Sep 17 00:00:00 2001 From: Daniel Lando Date: Fri, 16 Feb 2024 14:28:58 +0100 Subject: [PATCH 2/7] fix: missing path --- test/test-80-compression-node-opcua/main.js | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/test/test-80-compression-node-opcua/main.js b/test/test-80-compression-node-opcua/main.js index 512f8ff37..0f5a889fe 100644 --- a/test/test-80-compression-node-opcua/main.js +++ b/test/test-80-compression-node-opcua/main.js @@ -96,7 +96,12 @@ function pkgCompress(compressMode, output) { function esbuildBuild(entryPoint) { const log = utils.spawn.sync( path.join(__dirname, 'node_modules/.bin/esbuild'), - [entryPoint, '--bundle', '--outfile=' + pkgJson.main, '--platform=node'], + [ + entryPoint, + '--bundle', + '--outfile=' + path.join(buildDir, pkgJson.main), + '--platform=node', + ], { cwd: __dirname, expect: 0 }, ); From 42864aebedc9df0fa2116a611b12f2f92319ff01 Mon Sep 17 00:00:00 2001 From: Daniel Lando Date: Fri, 16 Feb 2024 15:01:01 +0100 Subject: [PATCH 3/7] fix: use npx --- test/test-80-compression-node-opcua/main.js | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/test/test-80-compression-node-opcua/main.js b/test/test-80-compression-node-opcua/main.js index 0f5a889fe..c93558611 100644 --- a/test/test-80-compression-node-opcua/main.js +++ b/test/test-80-compression-node-opcua/main.js @@ -95,8 +95,12 @@ function pkgCompress(compressMode, output) { function esbuildBuild(entryPoint) { const log = utils.spawn.sync( - path.join(__dirname, 'node_modules/.bin/esbuild'), + path.join( + path.dirname(process.argv[0]), + 'npx' + (process.platform === 'win32' ? '.cmd' : ''), + ), [ + 'esbuild', entryPoint, '--bundle', '--outfile=' + path.join(buildDir, pkgJson.main), From 9c536967e72252bbd20a08a471ee08f71f3be910 Mon Sep 17 00:00:00 2001 From: Daniel Lando Date: Fri, 16 Feb 2024 15:03:46 +0100 Subject: [PATCH 4/7] fix: try add node 20 to ci --- .github/workflows/ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index a10a95701..80566e81e 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -11,7 +11,7 @@ jobs: strategy: fail-fast: false # prevent test to stop if one fails matrix: - node-version: [16.x, 18.x] + node-version: [16.x, 18.x, 20.x] os: [ubuntu-latest, windows-latest, macos-latest] runs-on: ${{ matrix.os }} steps: From 19305b01ba5a3ace3ce01677c85a4d2ec6e721e9 Mon Sep 17 00:00:00 2001 From: Daniel Lando Date: Fri, 16 Feb 2024 15:35:15 +0100 Subject: [PATCH 5/7] fix: node 20 test --- package.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index 5704916de..b8e58fd69 100644 --- a/package.json +++ b/package.json @@ -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:20 && 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" }, From 4a01690e85cb797d1450935a75dcdc5c05896258 Mon Sep 17 00:00:00 2001 From: Daniel Lando Date: Fri, 16 Feb 2024 15:50:58 +0100 Subject: [PATCH 6/7] fix: missing npm --- test/test-79-npm/main.js | 1 + 1 file changed, 1 insertion(+) 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); From 71b83171c073d041c4aa0adee00b42e43ededfba Mon Sep 17 00:00:00 2001 From: Daniel Lando Date: Fri, 16 Feb 2024 16:18:04 +0100 Subject: [PATCH 7/7] fix: revert some node 20 changes --- .github/workflows/ci.yml | 2 +- package.json | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 80566e81e..a10a95701 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -11,7 +11,7 @@ jobs: strategy: fail-fast: false # prevent test to stop if one fails matrix: - node-version: [16.x, 18.x, 20.x] + node-version: [16.x, 18.x] os: [ubuntu-latest, windows-latest, macos-latest] runs-on: ${{ matrix.os }} steps: diff --git a/package.json b/package.json index b8e58fd69..138ffdba3 100644 --- a/package.json +++ b/package.json @@ -74,7 +74,7 @@ "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:20 && npm run test:18 && npm run test:16 && 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",