Skip to content

Commit

Permalink
Bump to Node v20.17.0 (stateful#1696)
Browse files Browse the repository at this point in the history
* Bump to NodeJS v20.17.0

* Node modules cleanup

* Code cleanup
  • Loading branch information
pastuxso authored Oct 1, 2024
1 parent ab9d3ef commit 557ffff
Show file tree
Hide file tree
Showing 14 changed files with 125 additions and 22 deletions.
3 changes: 3 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ jobs:
DO_NOT_TRACK: 1
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: "20.17.0"
- name: Install xvfb
run: sudo apt-get update -y && sudo apt-get install xvfb
- name: 👷 Install Dependencies
Expand Down
2 changes: 1 addition & 1 deletion .nvmrc
Original file line number Diff line number Diff line change
@@ -1 +1 @@
v18.19.0
v20.17.0
2 changes: 1 addition & 1 deletion .tool-versions
Original file line number Diff line number Diff line change
@@ -1 +1 @@
nodejs 18.20.2
nodejs 20.17.0
6 changes: 3 additions & 3 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@
"smartStep": true,
"console": "integratedTerminal",
"env": {
"NODE_OPTIONS": "--experimental-specifier-resolution=node"
"NODE_OPTIONS": "--import=./specifier-register.mjs"
},
},
{
Expand All @@ -86,8 +86,8 @@
"<node_internals>/**/*.js"
],
"env": {
"NODE_OPTIONS": "--experimental-specifier-resolution=node"
"NODE_OPTIONS": "--import=./specifier-register.mjs"
},
}
]
}
}
20 changes: 11 additions & 9 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -144,14 +144,14 @@ To run the extension in a new Extension Development Host window of VS Code open
To compile all extension files, run:

```sh {"id":"01HF7VQMH8ESX1EFV4PDNTDPTS","name":"build","promptEnv":"no"}
export NODE_OPTIONS="--experimental-specifier-resolution=node --max-old-space-size=8192"
export NODE_OPTIONS="--import=./specifier-register.mjs --max-old-space-size=8192"
npm run build
```

And then package the extension into a .vsix file:

```sh {"id":"01J04FQ8WSEVTDVS05VPZMKAYJ","name":"bundle","promptEnv":"no"}
export NODE_OPTIONS="--experimental-specifier-resolution=node --max-old-space-size=8192"
export NODE_OPTIONS="--import=./specifier-register.mjs --max-old-space-size=8192"
npm run bundle
```

Expand All @@ -160,19 +160,19 @@ npm run bundle
The Runme project has several test stages that you can run individually or as a whole:

```sh {"id":"01HF7VQMH8ESX1EFV4PFZ87Q58","name":"test","promptEnv":"no"}
export NODE_OPTIONS="--experimental-specifier-resolution=node --max-old-space-size=8192"
export NODE_OPTIONS="--import=./specifier-register.mjs --max-old-space-size=8192"
npx runme run test:format test:lint test:unit test:e2e
```

```sh {"id":"01J5VPD3TXY1EAZDCXNHN60S77","promptEnv":"no"}
export NODE_OPTIONS="--experimental-specifier-resolution=node --max-old-space-size=8192"
```sh {"id":"01J5VPD3TXY1EAZDCXNHN60S77"}
export NODE_OPTIONS="--import=./specifier-register.mjs --max-old-space-size=8192"
npx runme run test:format test:lint test:unit
```

When testing in CI environment, run:

```sh {"id":"01HF7VQMH8ESX1EFV4PGJBDGG0","name":"test:ci","promptEnv":"no"}
export NODE_OPTIONS="--experimental-specifier-resolution=node --max-old-space-size=8192"
export NODE_OPTIONS="--import=./specifier-register.mjs --max-old-space-size=8192"
npx runme run test:format test:lint test:unit test:e2e:ci
```

Expand Down Expand Up @@ -211,7 +211,7 @@ We use [Vitest](https://vitest.dev/) for running unit tests via:
In case you experience a "Cannot find module '@buf/stateful'" error, it's probably caused because of a nvm cache issue, you can try clearing removing node_modules and reinstalling the dependencies. In case the issue persists, do a fresh clone of the repository. The issue is probably caused by nvm caching the wrong version of the package.

```sh {"id":"01HF7VQMH8ESX1EFV4PT2KN303","name":"test:unit","promptEnv":"no"}
export NODE_OPTIONS="--experimental-specifier-resolution=node --max-old-space-size=8192"
export NODE_OPTIONS="--import=./specifier-register.mjs --max-old-space-size=8192"
npx vitest -c ./vitest.conf.ts --run
```

Expand All @@ -226,6 +226,7 @@ open coverage/lcov-report/index.html
We use WebdriverIO to run e2e tests on the VS Code extension:

```sh {"id":"01HF7VQMH8ESX1EFV4PX19FXW0","name":"test:e2e"}
export NODE_OPTIONS="--import=./specifier-register.mjs --max-old-space-size=8192"
npx wdio run ./tests/e2e/wdio.conf.ts
```

Expand All @@ -236,6 +237,7 @@ The process for testing in CI is a bit more complicated as we try to test closer
Therefore to test in a closer production environment, run:

```sh {"id":"01HF7VQMH8ESX1EFV4PYWC0M3X","name":"test:e2e:ci"}
export NODE_OPTIONS="--import=./specifier-register.mjs --max-old-space-size=8192"
# run reconcile command when previous commands pass or fail
npx runme run test:e2e:ci:setup test:e2e:ci:run; npx runme run test:e2e:ci:reconcile
```
Expand All @@ -249,7 +251,7 @@ mv ./node_modules/ ./.node_modules
mv ./package.json ./.package.json
mv ./package-lock.json ./.package-lock.json
# then install runme again
RUNME_DOWNLOAD_ON_INSTALL=1 npm i runme
RUNME_DOWNLOAD_ON_INSTALL=1 NODE_OPTIONS='' npm i runme || true
# restore package.json to allow testing the extension
mv ./.package.json ./package.json
```
Expand All @@ -260,7 +262,7 @@ Then we can run the e2e tests via:

```sh {"id":"01HF7VQMH8ESX1EFV4Q3XXMMX7","name":"test:e2e:ci:run"}
cd ./tests/e2e/
npm ci
NODE_OPTIONS='' npm ci
npx wdio run ./wdio.conf.ts
```

Expand Down
3 changes: 3 additions & 0 deletions package-lock.json

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

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@
},
"private": true,
"engines": {
"vscode": "^1.78.0"
"vscode": "^1.78.0",
"node": ">=20.17.0"
},
"galleryBanner": {
"color": "#0D003D",
Expand Down
78 changes: 78 additions & 0 deletions specifier-node.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
import {dirname, isAbsolute, join, extname} from 'node:path'
import {cwd} from 'node:process'
import {readFile} from 'node:fs/promises'


let warn = (field, desc) => console.warn('⚠️ \x1b[33m%s\x1b[0m',
`Warning: The package.json field 'extensionless.${field}' must be ${desc}! Using the default value instead...`)

let getPkgJson = async dirPath => {
do {
let path = join(dirPath, 'package.json')

try {
return {body: JSON.parse(await readFile(path, 'utf8')), path}
} catch (e) {
if (!['ENOTDIR', 'ENOENT', 'EISDIR'].includes(e.code)) {
throw new Error('Cannot retrieve package.json', {cause: e})
}
}
} while (dirPath !== (dirPath = dirname(dirPath)))
}

export async function getConfig({argv1 = ''} = {}) {
let defaults = {
lookFor: ['js']
}, dirPath = isAbsolute(argv1) ? argv1 : cwd(), {
lookFor
} = {...defaults, ...(await getPkgJson(dirPath))?.body.extensionless}

Array.isArray(lookFor) && lookFor.length && lookFor.every(a => typeof a === 'string' && /^[a-z]\w*$/i.test(a)) || (
lookFor = defaults.lookFor, warn('lookFor', 'an array of alphanumeric strings')
)

return {lookFor}
}


let initPromise
export function globalPreload({port}) {
port.onmessage = e => initPromise = initialize({argv1: e.data})

return 'port.postMessage(process.argv[1])'
}

let indexFiles, candidates
export async function initialize(data) {
let {lookFor} = await getConfig(data)

indexFiles = [lookFor.map(e => `index.${e}`), ['index.json']]
candidates = indexFiles.map(i => i.map(f => extname(f)).concat(i.map(f => `/${f}`)))
}

let winAbsPath = /^[/\\]?[a-z]:[/\\]/i, relSpecs = ['.', '..']
let specStarts = ['./', '../', '/', 'file://', 'https://', '.\\', '..\\', '\\']
let knownExts = ['.js', '.cjs', '.mjs', '.json', '.node', '.wasm'], empty = [[], []]

export async function resolve(specifier, context, nextResolve) {
let error, prefix = winAbsPath.test(specifier) ? 'file://' : ''

if (!prefix && !relSpecs.includes(specifier) && !specStarts.some(s => specifier.startsWith(s))) {
try {return await nextResolve(specifier)} catch (e) {error = e}
}

let {type} = context.importAttributes ?? context.importAssertions
let trySpec = error ? specifier : new URL(prefix + specifier, context.parentURL).href
let postfixes = (await initPromise, trySpec.endsWith('/') ?
indexFiles : knownExts.includes(extname(trySpec)) ? empty : candidates)

for (let postfix of postfixes[+(type === 'json')]) {
try {return await nextResolve(trySpec + postfix)} catch {}
}

if (error) {
throw error
}

return await nextResolve(trySpec)
}
4 changes: 4 additions & 0 deletions specifier-register.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import {register} from 'node:module'
import {argv} from 'node:process'

register('./specifier-node.mjs', import.meta.url, {data: {argv1: argv[1]}})
7 changes: 4 additions & 3 deletions tests/e2e/package-lock.json

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

1 change: 1 addition & 0 deletions tests/e2e/specifier-node.mjs
1 change: 1 addition & 0 deletions tests/e2e/specifier-register.mjs
6 changes: 5 additions & 1 deletion tests/e2e/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@
],
"target": "es2022"
},
"include": ["specs", "./wdio.conf.ts", "pageobjects"],
"include": [
"specs",
"./wdio.conf.ts",
"pageobjects"
],
"exclude": []
}
11 changes: 8 additions & 3 deletions tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,11 @@
"module": "commonjs",
"outDir": "out",
"rootDir": "src",
"target": "ES2021",
"lib": ["ES2021", "DOM"],
"target": "es2021",
"lib": [
"es2021",
"DOM"
],
"moduleResolution": "node",
"esModuleInterop": true,
"experimentalDecorators": true,
Expand All @@ -15,6 +18,8 @@
"vscode"
]
},
"include": ["src/"],
"include": [
"src/"
],
"exclude": []
}

0 comments on commit 557ffff

Please sign in to comment.