Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: provide support for node14 #8

Merged
merged 4 commits into from
Apr 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
65 changes: 43 additions & 22 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,30 @@
name: CI
on: [push, pull_request]
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Use Node.js 20.x
uses: actions/setup-node@v4
with:
node-version: 20.x
cache: 'npm'
- run: npm ci
- run: npm run build
- uses: actions/upload-artifact@v4
with:
name: build
path: |
target
package.json
retention-days: 1

push:
name: Push ${{ github.ref }}
needs: build
if: github.event_name == 'push'
runs-on: ubuntu-22.04
runs-on: ubuntu-latest
permissions:
checks: read
statuses: write
Expand All @@ -18,19 +38,16 @@ jobs:
uses: actions/checkout@v4
with:
fetch-depth: ${{ github.ref == 'refs/heads/main' && '0' || '1' }}

- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: 20
cache: 'npm'

- uses: actions/download-artifact@v4
with:
name: build
- name: Fetch deps
run: npm ci

- name: Build
run: npm run build

- name: Run tests
run: npm run test

Expand Down Expand Up @@ -58,34 +75,38 @@ jobs:

pr:
if: github.event_name == 'pull_request'
needs: build
name: PR (Node v${{ matrix.node-version }}, OS ${{ matrix.os }})
strategy:
matrix:
os: [ ubuntu-22.04, windows-latest ]
node-version: [ 20 ]
os: [ ubuntu-latest, windows-latest ]
# v22 awaits https://github.com/nodejs/node/issues/52682
node-version: [ 14, 20 ]

runs-on: ${{ matrix.os }}
steps:
- name: Checkout
uses: actions/checkout@v4

- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: ${{ matrix.node-version }}
cache: 'npm'

- name: Fetch deps
run: npm ci

- name: Build
run: npm run build
- uses: actions/download-artifact@v4
with:
name: build

- name: Run all tests
if: matrix.os == 'ubuntu-22.04'
run: npm run test

- name: Run win32 tests
if: matrix.os == 'windows-latest'
run: node --loader ts-node/esm --experimental-specifier-resolution=node ./src/test/ts/spawn.test.ts
if: matrix.os == 'ubuntu-latest' && matrix.node-version == 20
run: |
npm ci
npm run test
- name: Run spawn tests (win32)
if: matrix.os == 'windows-latest' && matrix.node-version == 20
run: |
npm ci
node --loader ts-node/esm --experimental-specifier-resolution=node ./src/test/ts/spawn.test.ts
timeout-minutes: 5

- name: Run smoke tests
run: npm run test:smoke
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

<sup>
– cute sounds but never friendly. <br/>
eat all kinds of materials.
eats all kinds of materials.
</sup>

# 🔬🧫
Expand Down
40 changes: 20 additions & 20 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 5 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
"test": "concurrently 'npm:test:*'",
"test:lint": "eslint -c src/test/lint/.eslintrc.json src",
"test:unit": "c8 -r lcov -r text -o target/coverage -x src/scripts -x src/test -x target node --loader ts-node/esm --experimental-specifier-resolution=node src/scripts/test.mjs",
"test:smoke": "node ./src/test/smoke/invoke.test.mjs && node src/test/smoke/invoke.test.cjs",
"publish:draft": "npm run build && npm publish --no-git-tag-version"
},
"repository": {
Expand All @@ -60,18 +61,18 @@
"homepage": "https://github.com/webpod/zurk#readme",
"dependencies": {},
"devDependencies": {
"@types/node": "^20.11.28",
"@types/node": "^20.12.7",
"c8": "^9.1.0",
"concurrently": "^8.2.2",
"esbuild": "^0.20.2",
"esbuild-node-externals": "^1.13.0",
"esbuild-plugin-entry-chunks": "^0.1.11",
"esbuild-plugin-entry-chunks": "^0.1.12",
"eslint": "^8.57.0",
"eslint-config-qiwi": "^2.1.3",
"fast-glob": "^3.3.2",
"minimist": "^1.2.8",
"ts-node": "^10.9.2",
"typedoc": "^0.25.12",
"typescript": "^5.4.2"
"typedoc": "^0.25.13",
"typescript": "^5.4.5"
}
}
2 changes: 1 addition & 1 deletion src/main/ts/spawn.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ export const normalizeCtx = (...ctxs: TSpawnCtx[]): TSpawnCtxNormalized => assig
input: null,
env: process.env,
ee: new EventEmitter(),
ac: AbortController && new AbortController(),
ac: global.AbortController && new AbortController(),
get signal() { return this.ac?.signal },
on: {},
detached: process.platform !== 'win32',
Expand Down
2 changes: 1 addition & 1 deletion src/main/ts/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ export const isStringLiteral = (pieces: any) => pieces?.every?.((p: any) => type
export const assign = <T, E>(target: T, ...extras: E[]): T =>
Object.defineProperties(target, extras.reduce<Record<string, any>>((m: any, extra) =>
({...m, ...Object.fromEntries(Object.entries(Object.getOwnPropertyDescriptors(extra))
.filter(([,v]) => !Object.hasOwn(v, 'value') || v.value !== undefined))}), {}))
.filter(([,v]) => !Object.prototype.hasOwnProperty.call(v, 'value') || v.value !== undefined))}), {}))

export const quote = (arg: string) => {
if (/^[\w./:=@-]+$/i.test(arg) || arg === '') {
Expand Down
2 changes: 1 addition & 1 deletion src/scripts/test.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@ import { pathToFileURL } from 'node:url'
import process from 'node:process'

const focused = process.argv.slice(2)
const suites = focused.length ? focused : await glob('src/test/**/*.test.{ts,cjs,mjs}', {cwd: process.cwd(), absolute: true, onlyFiles: true})
const suites = focused.length ? focused : await glob('src/test/**/*.test.{ts,cjs,mjs,js}', {cwd: process.cwd(), absolute: true, onlyFiles: true})

await Promise.all(suites.map(suite => import(pathToFileURL(suite))))
8 changes: 8 additions & 0 deletions src/test/smoke/invoke.test.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
const assert = require('assert')
const { zurk } = require('zurk')

const result = zurk({ sync: true, cmd: 'echo', args: ['foo'] })
assert.match(result.stdout, /foo/)
assert.equal(result.status, 0)

console.log('smoke cjs: ok')
8 changes: 8 additions & 0 deletions src/test/smoke/invoke.test.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import assert from 'assert'
import { zurk } from 'zurk'

const result = zurk({ sync: true, cmd: 'echo', args: ['foo'] })
assert.match(result.stdout, /foo/)
assert.equal(result.status, 0)

console.log('smoke mjs: ok')