Skip to content

Commit

Permalink
Node 20 support
Browse files Browse the repository at this point in the history
  • Loading branch information
corrideat committed Oct 6, 2023
1 parent 975edda commit 5105950
Show file tree
Hide file tree
Showing 21 changed files with 80 additions and 47 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/npm-publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ jobs:
java-version: '11'
- uses: actions/setup-node@v3
with:
node-version: '19'
node-version: '20'
registry-url: https://registry.npmjs.org/
- run: npm ci
- run: npm publish --provenance --access public
Expand Down
4 changes: 4 additions & 0 deletions .github/workflows/pull-request.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ jobs:
- run: npm run lint
- run: npm test
- run: deno test --import-map=import_map.json test
env:
DENO_NO_PACKAGE_JSON=1

run-tests-windows:
runs-on: windows-latest
Expand All @@ -47,3 +49,5 @@ jobs:
- run: npm run lint
- run: npm test
- run: deno test --import-map=import_map.json test
env:
DENO_NO_PACKAGE_JSON=1
2 changes: 1 addition & 1 deletion .mocharc.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{
"extension": ["ts"],
"loader": "./loader.mjs"
"node-option": ["no-warnings=ExperimentalWarning", "loader=./loader.mjs"]
}
16 changes: 11 additions & 5 deletions loader.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@
*/

import module from 'node:module';
import { join } from 'node:path';
import { fileURLToPath } from 'node:url';
import { resolve as resolveTs } from 'ts-node/esm';
import importMap from './import_map.json' assert { type: 'json' };
import { fileURLToPath } from 'node:url';
import { join } from 'node:path';

export * from 'ts-node/esm';

Expand Down Expand Up @@ -47,10 +47,16 @@ module._resolveFilename = (...args) => {
export const resolve = (specifier, context, defaultResolver) => {
if (typeof specifier === 'string') {
Object.entries(importMap.imports).forEach(([k, v]) => {
if (specifier.startsWith(absoluteBaseUrl + k))
specifier = specifier.replace(k, v);
if (specifier.startsWith(k)) {
specifier = specifier.replace(k, absoluteBaseUrl + v);
}
});
}

return resolveTs(specifier, context, defaultResolver);
return resolveTs(specifier, context, defaultResolver).then((v) => {
if (v.url.endsWith('.ts')) {
v.format = 'module';
}
return v;
});
};
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@
"test:unit": "nyc mocha src/**/*.spec.ts",
"test:e2e": "mocha test/**/*.spec.ts",
"test": "npm run test:unit && npm run build && npm run test:e2e",
"prepack": "npm run build && rimraf -g -- 'dist/**/*.tsbuildinfo'",
"prepack": "npm run build",
"prepublishOnly": "npm test && npm run lint",
"preversion": "npm run lint",
"version": "npm run lint && git add -A src",
Expand Down
23 changes: 23 additions & 0 deletions src/test/lib/buildTimeSettings.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
/* Copyright © 2023 Exact Realty Limited.
*
* Permission to use, copy, modify, and distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
* copyright notice and this permission notice appear in all copies.
*
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
* REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
* AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
* INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
* LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
* OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
* PERFORMANCE OF THIS SOFTWARE.
*/

if (typeof __buildtimeSettings__ !== 'object')
Reflect.set(globalThis, '__buildtimeSettings__', {});

Reflect.set(__buildtimeSettings__, 'bidirectionalMessaging', true);
Reflect.set(__buildtimeSettings__, 'buildType', 'debug');
Reflect.set(__buildtimeSettings__, 'defaultAllowedGlobalProps', []);
Reflect.set(__buildtimeSettings__, 'hardenGlobals', true);
Reflect.set(__buildtimeSettings__, 'sandboxInitDeadlineInMs', 100);
10 changes: 10 additions & 0 deletions src/test/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"extends": "../../tsconfig.json",
"compilerOptions": {
"rootDir": ".",
"composite": true,
"lib": ["es2022"],
"outDir": "../../build/test"
},
"include": ["**/*"]
}
5 changes: 1 addition & 4 deletions src/trusted/lib/setupSandboxListeners.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,7 @@
* PERFORMANCE OF THIS SOFTWARE.
*/

if (typeof __buildtimeSettings__ !== 'object')
Reflect.set(globalThis, '__buildtimeSettings__', {});

Reflect.set(__buildtimeSettings__, 'sandboxInitDeadlineInMs', 100);
import '~/test/lib/buildTimeSettings.js';

import setupSandboxListeners from './setupSandboxListeners.js';

Expand Down
3 changes: 2 additions & 1 deletion src/trusted/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@
"compilerOptions": {
"rootDir": ".",
"outDir": "../../dist/trusted",
"tsBuildInfoFile": "../../build/trusted.tsbuildinfo",
"composite": true
},
"references": [{ "path": "../types" }, { "path": "../untrusted" }],
"references": [{ "path": "../types" }, { "path": "../untrusted" }, { "path": "../test" }],
"include": ["**/*", "**/*.json"]
}
1 change: 1 addition & 0 deletions src/types/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
"compilerOptions": {
"rootDir": ".",
"outDir": "../../dist/types",
"tsBuildInfoFile": "../../build/types.tsbuildinfo",
"composite": true
},
"include": ["**/*", "**/*.json"]
Expand Down
6 changes: 1 addition & 5 deletions src/untrusted/lib/createContext.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,7 @@
* PERFORMANCE OF THIS SOFTWARE.
*/

if (typeof __buildtimeSettings__ !== 'object')
Reflect.set(globalThis, '__buildtimeSettings__', {});

Reflect.set(__buildtimeSettings__, 'bidirectionalMessaging', true);
Reflect.set(__buildtimeSettings__, 'defaultAllowedGlobalProps', []);
import '~/test/lib/buildTimeSettings.js';

import assert from 'node:assert/strict';
import createContext, { setupExternalMethods } from './createContext.js';
Expand Down
5 changes: 1 addition & 4 deletions src/untrusted/lib/hardenGlobals.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,7 @@
* PERFORMANCE OF THIS SOFTWARE.
*/

if (typeof __buildtimeSettings__ !== 'object')
Reflect.set(globalThis, '__buildtimeSettings__', {});

Reflect.set(__buildtimeSettings__, 'hardenGlobals', true);
import '~/test/lib/buildTimeSettings.js';

import assert from 'node:assert/strict';
import hardenGlobals, { disableURLStaticMethods } from './hardenGlobals.js';
Expand Down
5 changes: 1 addition & 4 deletions src/untrusted/lib/performTaskFactory.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,7 @@
* PERFORMANCE OF THIS SOFTWARE.
*/

if (typeof __buildtimeSettings__ !== 'object')
Reflect.set(globalThis, '__buildtimeSettings__', {});

Reflect.set(__buildtimeSettings__, 'buildType', 'debug');
import '~/test/lib/buildTimeSettings.js';

import assert from 'node:assert/strict';
import performTaskFactory from './performTaskFactory.js';
Expand Down
5 changes: 1 addition & 4 deletions src/untrusted/lib/requestHandler.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,7 @@
* PERFORMANCE OF THIS SOFTWARE.
*/

if (typeof __buildtimeSettings__ !== 'object')
Reflect.set(globalThis, '__buildtimeSettings__', {});

Reflect.set(__buildtimeSettings__, 'buildType', 'debug');
import '~/test/lib/buildTimeSettings.js';

import assert from 'node:assert/strict';
import { reconstructErrorInformation } from './errorModem.js';
Expand Down
3 changes: 2 additions & 1 deletion src/untrusted/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@
"compilerOptions": {
"rootDir": ".",
"outDir": "../../dist/untrusted",
"tsBuildInfoFile": "../../build/untrusted.tsbuildinfo",
"composite": true
},
"references": [{ "path": "../types" }],
"references": [{ "path": "../types" }, { "path": "../test" }],
"include": ["**/*", "**/*.json"]
}
11 changes: 4 additions & 7 deletions test/e2e/bare/bareSandbox.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

import runNodejsTests from '@test/lib/runNodejsTests.js';

import * as bare from '@dist/exports/bare';
import * as bare from '@dist/exports/bare.js';

// TODO: Import from '@dist/exports/bare'
import { hardenGlobals, freezePrototypes } from '@dist/index.js';
Expand All @@ -28,13 +28,10 @@ if (process.version) {
.slice(1)
.split('.', 2)
.map((n) => parseInt(n));
if (
(major === 18 && minor >= 18) ||
(major === 20 && minor >= 6) ||
major > 20
) {
if ((major === 20 && minor >= 6) || major > 20) {
freezePrototypes();
}
}

runNodejsTests('Bare', bare.default);
// Due to Node's CJS-from-ESM implementation, the import is bare.default.default
runNodejsTests('Bare', (bare.default as unknown as typeof bare).default);
2 changes: 1 addition & 1 deletion test/e2e/nodejs/nodejsSandbox.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,6 @@

import runNodejsTests from '@test/lib/runNodejsTests.js';

import { nodejsSandbox as m } from '@dist/index';
import { nodejsSandbox as m } from '@dist/index.js';

runNodejsTests('Node.js', m);
3 changes: 3 additions & 0 deletions test/lib/runBrowserTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,12 @@
* PERFORMANCE OF THIS SOFTWARE.
*/

import { fileURLToPath } from 'node:url';
import getCodeHelper from './getCodeHelper.js';
import { enabledBrowsers, webdriverTestSuites } from './webdriverTestSuites.js';

const __dirname = fileURLToPath(new URL('.', import.meta.url));

const runBrowserTest = (m: string, commonBundle?: boolean) => {
const code = commonBundle
? getCodeHelper(__dirname, '../../dist/index.mjs', m)
Expand Down
2 changes: 1 addition & 1 deletion test/lib/runNodejsTests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
import '~untrusted/lib/nodejsLoadWebcrypto.js'; // MUST BE AT THE TOP

import assertRejectsWithFactory from '@test/lib/assertRejectsWithFactory.js';
import baseTests from '@test/lib/baseTests.json';
import baseTests from '@test/lib/baseTests.json' assert { type: 'json' };
import wrapper from '@test/lib/wrapper.js';
import assert from 'node:assert/strict';
import type { ISandbox } from '~/types/index.js';
Expand Down
10 changes: 5 additions & 5 deletions test/lib/webdriverTestSuites.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@

import assert from 'node:assert/strict';
import webdriver from 'selenium-webdriver';
import { Options as ChromeOptions } from 'selenium-webdriver/chrome';
import { Options as EdgeOptions } from 'selenium-webdriver/edge';
import { Options as FirefoxOptions } from 'selenium-webdriver/firefox';
import { Options as SafariOptions } from 'selenium-webdriver/safari';
import baseTests from './baseTests.json';
import { Options as ChromeOptions } from 'selenium-webdriver/chrome.js';
import { Options as EdgeOptions } from 'selenium-webdriver/edge.js';
import { Options as FirefoxOptions } from 'selenium-webdriver/firefox.js';
import { Options as SafariOptions } from 'selenium-webdriver/safari.js';
import baseTests from './baseTests.json' assert { type: 'json' };

export const enabledBrowsers = () => {
const webdriverBrowsers = new Set(
Expand Down
7 changes: 5 additions & 2 deletions tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"compilerOptions": {
"target": "es6",
"composite": true,
"module": "commonjs",
"module": "esnext",
"moduleResolution": "node",
"outDir": "dist",
"rootDir": "src",
Expand Down Expand Up @@ -35,7 +35,10 @@
"checkJs": false
},
"ts-node": {
"experimentalResolver": true
"experimentalResolver": true,
"compilerOptions": {
"module": "esnext"
}
},
"references": [
{ "path": "src/trusted" },
Expand Down

0 comments on commit 5105950

Please sign in to comment.