Skip to content

Commit

Permalink
Add node version testing matrix and specify compatible engines
Browse files Browse the repository at this point in the history
This adds a testing matrix that covers node versions 18-21, and specifies the
minimum node engine version in `package.json` as v18.3.0. One blocker to
supporting earlier versions is that `buffer.File` was added in v18.3.0. I took
a stab at removing this, but ran into a lot of issues trying to get things to
work without it. v16 was EOLed last year though, so I don't think this is that
major of an issue. It will be easier to test against earlier versions now with
the testing matrix if we do decide we want to support them.

One notable thing is that the `--loader` vs `--import` argument depends on
versions in fairly complex ways. I think that it's roughly `--import` for
`>=18.19.0 < 19.0.0 || >=v20.6.0` and `--loader` for everything else, and I
have a commit in here with something like that working in the ava config, but
ultimately went with running ava with tsx like `tsx ./node_modules/.bin/ava`
because I'm more confident that this will work with any node version (despite
the fact that it's a bit hackier).

Closes #64
Merges #67
  • Loading branch information
sangaline authored Jan 31, 2024
1 parent 9fc84d3 commit cabbd99
Show file tree
Hide file tree
Showing 6 changed files with 190 additions and 27 deletions.
20 changes: 15 additions & 5 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ on:

jobs:
lint-and-test:
strategy:
matrix:
version: [18, 19, 20, 21]
runs-on: ubuntu-latest
steps:
- name: Checkout code
Expand All @@ -18,12 +21,12 @@ jobs:
id: setup-node
uses: actions/setup-node@v3
with:
node-version: 18.18.2
node-version: ${{ matrix.version }}
cache: yarn

- name: Install JavaScript Dependencies
run: |
yarn install --frozen-lockfile
yarn install --frozen-lockfile --ignore-engines
- name: Lint
if: success() || failure()
Expand All @@ -40,11 +43,18 @@ jobs:
run: |
yarn build
- name: Install Chrome Dependencies
if: success() || failure()
# We only run the browser tests for the development version of node because the browser environment
# is independent of the node version, so all that matters is the build we deploy works in the browser.
- name: Conditionally Install Chrome Dependencies
if: (success() || failure()) && matrix.version == 18
run: |
sudo apt-get install -y libnss3 libatk1.0-0 libatk-bridge2.0-0 libcups2 libgbm1 libasound2 libpangocairo-1.0-0 libxss1 libgtk-3-0
- name: Conditionally Remove Browser Tests
if: (success() || failure()) && matrix.version != 18
run: |
rm test/browser.test.ts
- name: Test
if: success() || failure()
run: |
Expand All @@ -61,7 +71,7 @@ jobs:
- name: Setup Node.js
uses: actions/setup-node@v3
with:
node-version: 18.18.2
node-version: 18.19.0
registry-url: "https://registry.npmjs.org"

- name: Extract Version from Tag
Expand Down
3 changes: 2 additions & 1 deletion .tool-versions
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
nodejs v18.18.2
nodejs v18.19.0
yarn 1.22.19
10 changes: 8 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM node:18.18.2-slim as development
FROM node:18.19.0-slim as development
ENV NODE_ENV=development

# Optionally convert the user to another UID/GUID to match host user file permissions.
Expand Down Expand Up @@ -50,10 +50,16 @@ WORKDIR /sindri/
# Link the `sindri-js` project.
# We need at least `package.json` and a stub for the CLI to create the symlinks,
# then we'll bind mount over this with the real project at runtime with docker compose.
# Running `npm link` requires `patch-package` to be in the PATH as a `postinstall` script,
# so we create a small stub script to satisfy this requirement and then delete it.
COPY ./package.json /sindri/package.json
RUN mkdir -p dist/cli/ && \
touch dist/cli/index.js && \
chmod u+x dist/cli/index.js && \
npm link
echo "#! /bin/sh" > patch-package && \
chmod u+x patch-package && \
export PATH="./:$PATH" && \
npm link && \
rm patch-package

CMD ["/bin/sh", "-c", "yarn install && yarn build:watch"]
1 change: 0 additions & 1 deletion ava.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ export default {
ts: "module",
},
files: ["test/**/*.test.ts"],
nodeArguments: ["--loader=tsx"],
// Increase the timeout if we expect to make live API calls.
timeout: ["dryrun", "record", "update", "wild"].includes(
process.env.NOCK_BACK_MODE ?? "lockdown",
Expand Down
29 changes: 16 additions & 13 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@
"templates/",
"tsconfig.json"
],
"engines": {
"node": ">=18.13.0"
},
"main": "dist/lib/index.js",
"module": "dist/lib/index.mjs",
"bin": {
Expand Down Expand Up @@ -54,10 +57,10 @@
"generate-api:docker": "rm -rf src/lib/api/ && openapi --client axios --input http://host.docker.internal/api/openapi.json --output src/lib/api/ --useUnionTypes && prettier --write src/lib/api/**/*",
"lint": "eslint '**/*.{js,ts}'",
"format": "prettier --write '**/*.{js,json,md,ts}'",
"test": "yarn build && ava",
"test:fast": "ava",
"test": "yarn build && yarn test:fast",
"test:fast": "tsx ./node_modules/.bin/ava",
"test:record": "NOCK_BACK_MODE=update yarn test",
"test:watch": "NODE_ENV=development NOCK_BACK_MODE=dryrun nodemon --watch src/ --watch test/ --ext js,cjs,mjs,ts,cts,mts --exec 'tsup --silent && ava'",
"test:watch": "NODE_ENV=development NOCK_BACK_MODE=dryrun nodemon --watch src/ --watch test/ --ext js,cjs,mjs,ts,cts,mts --exec 'tsup --silent && tsx ./node_modules/.bin/ava'",
"type-check": "tsc --noEmit",
"/***** Hooks *****/": "",
"postinstall": "patch-package"
Expand All @@ -74,6 +77,16 @@
"dependencies": {
"@commander-js/extra-typings": "^11.1.0",
"@inquirer/prompts": "^3.3.0",
"@tsconfig/node18": "^18.2.2",
"@types/get-port": "^4.2.0",
"@types/gzip-js": "^0.3.5",
"@types/ignore-walk": "^4.0.3",
"@types/lodash": "^4.14.202",
"@types/node": "^20.9.1",
"@types/nunjucks": "^3.2.6",
"@types/proxy": "^1.0.4",
"@types/tar": "^6.1.10",
"@types/tar-js": "^0.3.5",
"axios": "^1.6.2",
"commander": "^11.1.0",
"env-paths": "^2.2.1",
Expand All @@ -90,16 +103,6 @@
"rc": "^1.2.8",
"tar": "^6.2.0",
"tar-js": "^0.3.0",
"@tsconfig/node18": "^18.2.2",
"@types/get-port": "^4.2.0",
"@types/gzip-js": "^0.3.5",
"@types/ignore-walk": "^4.0.3",
"@types/lodash": "^4.14.202",
"@types/node": "^20.9.1",
"@types/nunjucks": "^3.2.6",
"@types/proxy": "^1.0.4",
"@types/tar": "^6.1.10",
"@types/tar-js": "^0.3.5",
"zod": "^3.22.4"
},
"devDependencies": {
Expand Down
Loading

0 comments on commit cabbd99

Please sign in to comment.