Skip to content

Commit

Permalink
Merge branch 'main' into async-resolve
Browse files Browse the repository at this point in the history
  • Loading branch information
robertsLando authored Feb 19, 2024
2 parents fe2f955 + c279732 commit d55ac11
Show file tree
Hide file tree
Showing 8 changed files with 155 additions and 26 deletions.
71 changes: 71 additions & 0 deletions .github/workflows/update-dep.yml
Original file line number Diff line number Diff line change
@@ -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/[email protected]
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 }}"
10 changes: 10 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,13 @@
## [5.11.4](https://github.com/yao-pkg/pkg/compare/v5.11.3...v5.11.4) (2024-02-16)

### Features

- [email protected] 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
Expand Down
8 changes: 4 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand All @@ -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",
Expand Down Expand Up @@ -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"
},
Expand Down
1 change: 1 addition & 0 deletions test/test-79-npm/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ const npm = {
14: 6,
16: 7,
18: 8,
20: 10,
}[hostVersion];

assert(npm !== undefined);
Expand Down
60 changes: 44 additions & 16 deletions test/test-80-compression-node-opcua/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand All @@ -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(
Expand All @@ -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'];

Expand All @@ -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);
Expand Down Expand Up @@ -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');
5 changes: 4 additions & 1 deletion test/test-80-compression-node-opcua/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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"
Expand Down
18 changes: 17 additions & 1 deletion test/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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');
};
Expand Down
8 changes: 4 additions & 4 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -640,10 +640,10 @@
"@typescript-eslint/types" "6.7.4"
eslint-visitor-keys "^3.4.1"

"@yao-pkg/[email protected].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/[email protected].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"
Expand Down

0 comments on commit d55ac11

Please sign in to comment.