Skip to content

Commit ab17552

Browse files
authored
Merge pull request #614 from eemeli/engines-compat
Re-introduce compatibility with Node.js 14.6
2 parents a141bc0 + b27c124 commit ab17552

File tree

7 files changed

+99
-32
lines changed

7 files changed

+99
-32
lines changed

.github/workflows/nodejs.yml

Lines changed: 58 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,17 +10,14 @@ on:
1010
jobs:
1111
test:
1212
runs-on: ${{ matrix.os }}
13-
1413
strategy:
1514
matrix:
1615
os: [ubuntu-latest, windows-latest, macos-latest]
1716
node-version: [18, 20, latest]
18-
1917
steps:
2018
- uses: actions/checkout@v4
2119
with: { submodules: true }
22-
- name: Use Node.js ${{ matrix.node-version }}
23-
uses: actions/setup-node@v4
20+
- uses: actions/setup-node@v4
2421
with:
2522
node-version: ${{ matrix.node-version }}
2623
- run: npm ci
@@ -37,3 +34,60 @@ jobs:
3734
with: { node-version: 20 }
3835
- run: npm ci
3936
- run: npm run lint
37+
38+
node-16:
39+
runs-on: ubuntu-latest
40+
strategy:
41+
matrix:
42+
node-version: ['16.0.0', '16']
43+
steps:
44+
- uses: actions/checkout@v4
45+
with: { submodules: true }
46+
- uses: actions/setup-node@v4
47+
with:
48+
node-version: ${{ matrix.node-version }}
49+
- run: npm ci
50+
- run: npm install --no-save rollup@3
51+
- run: npm test
52+
- run: npm run test:dist
53+
54+
node-14-build:
55+
runs-on: ubuntu-latest
56+
strategy:
57+
matrix:
58+
node-version: ['14.18.0']
59+
steps:
60+
- uses: actions/checkout@v4
61+
with: { submodules: true }
62+
- uses: actions/setup-node@v4
63+
with:
64+
node-version: ${{ matrix.node-version }}
65+
- run: npm install --global npm@7
66+
- run: npm ci
67+
- run: npm install --no-save rollup@2
68+
- run: npm run test:dist
69+
- uses: actions/upload-artifact@v4
70+
with:
71+
name: yaml-node14
72+
path: dist/
73+
node-14-run:
74+
needs: node-14-build
75+
runs-on: ubuntu-latest
76+
strategy:
77+
matrix:
78+
node-version: ['14.6.0', '14', '15.0.0']
79+
steps:
80+
- uses: actions/checkout@v4
81+
with: { submodules: true }
82+
- uses: actions/setup-node@v4
83+
with:
84+
node-version: ${{ matrix.node-version }}
85+
- run: npm install --global npm@7
86+
- run: npm ci
87+
- uses: actions/download-artifact@v4
88+
with:
89+
name: yaml-node14
90+
path: dist/
91+
- run: npx jest --config config/jest.config.js
92+
env:
93+
TEST: dist

config/jest.config.js

Lines changed: 21 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -19,28 +19,27 @@ const transform = {
1919
'[/\\\\]tests[/\\\\].*\\.(m?js|ts)$': babel
2020
}
2121

22-
// The npm script name is significant.
23-
switch (process.env.npm_lifecycle_event) {
24-
case 'test:dist':
25-
console.log('Testing build output from dist/')
26-
moduleNameMapper = {
27-
'^yaml$': '<rootDir>/dist/index.js',
28-
'^yaml/cli$': '<rootDir>/dist/cli.mjs',
29-
'^yaml/util$': '<rootDir>/dist/util.js',
30-
'^../src/test-events.ts$': '<rootDir>/dist/test-events.js'
31-
}
32-
transform['[/\\\\]dist[/\\\\].*\\.mjs$'] = babel
33-
break
34-
35-
case 'test':
36-
default:
37-
process.env.TRACE_LEVEL = 'log'
38-
moduleNameMapper = {
39-
'^yaml$': '<rootDir>/src/index.ts',
40-
'^yaml/cli$': '<rootDir>/src/cli.ts',
41-
'^yaml/util$': '<rootDir>/src/util.ts'
42-
}
43-
transform['[/\\\\]src[/\\\\].*\\.ts$'] = babel
22+
// npm_lifecycle_event is the npm script name.
23+
if (
24+
process.env.TEST === 'dist' ||
25+
process.env.npm_lifecycle_event === 'test:dist'
26+
) {
27+
console.log('Testing build output from dist/')
28+
moduleNameMapper = {
29+
'^yaml$': '<rootDir>/dist/index.js',
30+
'^yaml/cli$': '<rootDir>/dist/cli.mjs',
31+
'^yaml/util$': '<rootDir>/dist/util.js',
32+
'^../src/test-events.ts$': '<rootDir>/dist/test-events.js'
33+
}
34+
transform['[/\\\\]dist[/\\\\].*\\.mjs$'] = babel
35+
} else {
36+
process.env.TRACE_LEVEL = 'log'
37+
moduleNameMapper = {
38+
'^yaml$': '<rootDir>/src/index.ts',
39+
'^yaml/cli$': '<rootDir>/src/cli.ts',
40+
'^yaml/util$': '<rootDir>/src/util.ts'
41+
}
42+
transform['[/\\\\]src[/\\\\].*\\.ts$'] = babel
4443
}
4544

4645
module.exports = {

config/rollup.node-config.mjs

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,14 @@ function fixDynamicImportRewrite(context) {
4949
}
5050
}
5151

52+
/**
53+
* Leave out `node:` prefix as unsupported in Node.js < 14.18
54+
*
55+
* @param {string} id
56+
*/
57+
const fixNodePaths = id =>
58+
id.startsWith('node:') ? id.substring(5) : undefined
59+
5260
export default [
5361
{
5462
input: {
@@ -60,7 +68,8 @@ export default [
6068
dir: 'dist',
6169
format: 'cjs',
6270
esModule: false,
63-
preserveModules: true
71+
preserveModules: true,
72+
paths: fixNodePaths
6473
},
6574
external: ['node:buffer', 'node:process'],
6675
plugins: [
@@ -72,7 +81,7 @@ export default [
7281
},
7382
{
7483
input: 'src/cli.ts',
75-
output: { file: 'dist/cli.mjs' },
84+
output: { file: 'dist/cli.mjs', paths: fixNodePaths },
7685
external: () => true,
7786
plugins: [
7887
typescript({

package-lock.json

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,6 @@
9191
"typescript-eslint": "^8.4.0"
9292
},
9393
"engines": {
94-
"node": ">= 14"
94+
"node": ">= 14.6"
9595
}
9696
}

tests/cli.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Readable } from 'node:stream'
1+
import { Readable } from 'stream'
22
import { cli } from 'yaml/cli'
33

44
const [major] = process.versions.node.split('.')

tests/doc/anchors.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -239,7 +239,12 @@ describe('merge <<', () => {
239239
for (let i = 5; i < res.length - 1; ++i) {
240240
expect(res[i]).toHaveProperty('<<')
241241
}
242-
expect(res.at(-1)).toMatchObject({ x: 1, y: 2, r: 10, label: 'center/big' })
242+
expect(res[res.length - 1]).toMatchObject({
243+
x: 1,
244+
y: 2,
245+
r: 10,
246+
label: 'center/big'
247+
})
243248
})
244249

245250
test('YAML.parseDocument', () => {

0 commit comments

Comments
 (0)