From 359ed9698bb1263e188b53fee597baa0f7d68c94 Mon Sep 17 00:00:00 2001 From: LongYinan Date: Wed, 2 Apr 2025 17:56:37 +0800 Subject: [PATCH] chore: switch to oxnode --- .../server/src/__tests__/cache.spec.ts | 25 ++- tools/cli/bin/runner.js | 7 +- tools/cli/hooks.js | 13 -- tools/cli/package.json | 1 + tools/cli/register.js | 3 - tools/cli/src/run.ts | 11 +- yarn.lock | 188 +++++++++++++++++- 7 files changed, 207 insertions(+), 41 deletions(-) delete mode 100644 tools/cli/hooks.js delete mode 100644 tools/cli/register.js diff --git a/packages/backend/server/src/__tests__/cache.spec.ts b/packages/backend/server/src/__tests__/cache.spec.ts index 12923bf047..216a34380f 100644 --- a/packages/backend/server/src/__tests__/cache.spec.ts +++ b/packages/backend/server/src/__tests__/cache.spec.ts @@ -1,24 +1,28 @@ import { TestingModule } from '@nestjs/testing'; -import test from 'ava'; +import ava, { type TestFn } from 'ava'; import { FunctionalityModules } from '../app.module'; import { Cache } from '../base/cache'; import { createTestingModule } from './utils'; -let cache: Cache; -let module: TestingModule; -test.before(async () => { - module = await createTestingModule({ +const test = ava as TestFn<{ + cache: Cache; + module: TestingModule; +}>; + +test.before(async t => { + t.context.module = await createTestingModule({ imports: FunctionalityModules, }); - cache = module.get(Cache); + t.context.cache = t.context.module.get(Cache); }); -test.after.always(async () => { - await module.close(); +test.after.always(async t => { + await t.context.module.close(); }); test('should be able to set normal cache', async t => { + const cache = t.context.cache; t.true(await cache.set('test', 1)); t.is(await cache.get('test'), 1); @@ -31,12 +35,14 @@ test('should be able to set normal cache', async t => { }); test('should be able to set cache with non-exiting flag', async t => { + const cache = t.context.cache; t.true(await cache.setnx('test-nx', 1)); t.false(await cache.setnx('test-nx', 2)); t.is(await cache.get('test-nx'), 1); }); test('should be able to set cache with ttl', async t => { + const cache = t.context.cache; t.true(await cache.set('test-ttl', 1)); t.is(await cache.get('test-ttl'), 1); @@ -47,6 +53,7 @@ test('should be able to set cache with ttl', async t => { }); test('should be able to incr/decr number cache', async t => { + const cache = t.context.cache; t.true(await cache.set('test-incr', 1)); t.is(await cache.increase('test-incr'), 2); t.is(await cache.increase('test-incr'), 3); @@ -59,6 +66,7 @@ test('should be able to incr/decr number cache', async t => { }); test('should be able to manipulate list cache', async t => { + const cache = t.context.cache; t.is(await cache.pushBack('test-list', 1), 1); t.is(await cache.pushBack('test-list', 2, 3, 4), 4); t.is(await cache.len('test-list'), 4); @@ -73,6 +81,7 @@ test('should be able to manipulate list cache', async t => { }); test('should be able to manipulate map cache', async t => { + const cache = t.context.cache; t.is(await cache.mapSet('test-map', 'a', 1), true); t.is(await cache.mapSet('test-map', 'b', 2), true); t.is(await cache.mapLen('test-map'), 2); diff --git a/tools/cli/bin/runner.js b/tools/cli/bin/runner.js index 94f22947e3..18981c9440 100755 --- a/tools/cli/bin/runner.js +++ b/tools/cli/bin/runner.js @@ -2,12 +2,11 @@ import { spawn } from 'node:child_process'; import { existsSync } from 'node:fs'; import { join } from 'node:path'; -import { fileURLToPath, pathToFileURL } from 'node:url'; +import { fileURLToPath } from 'node:url'; const scriptsFolder = join(fileURLToPath(import.meta.url), '..', '..'); const scriptsSrcFolder = join(scriptsFolder, 'src'); const projectRoot = join(scriptsFolder, '..', '..'); -const loader = join(scriptsFolder, 'register.js'); const [node, _self, file, ...options] = process.argv; @@ -60,9 +59,7 @@ if ( scriptLocation.endsWith('.ts') || scriptLocation.startsWith(scriptsFolder) ) { - nodeOptions.unshift(`--import=${pathToFileURL(loader)}`); -} else { - nodeOptions.unshift('--experimental-specifier-resolution=node'); + nodeOptions.unshift(`--import=@oxc-node/core/register`); } spawn(node, [...nodeOptions, scriptLocation, ...options], { diff --git a/tools/cli/hooks.js b/tools/cli/hooks.js deleted file mode 100644 index afd704db6d..0000000000 --- a/tools/cli/hooks.js +++ /dev/null @@ -1,13 +0,0 @@ -import { create, createEsmHooks, register } from 'ts-node'; - -const service = create({ - experimentalSpecifierResolution: 'node', - esm: true, - transpileOnly: true, -}); - -register(service); -const hooks = createEsmHooks(service); - -export const resolve = hooks.resolve; -export const load = hooks.load; diff --git a/tools/cli/package.json b/tools/cli/package.json index 37988114f6..1754cd18a3 100644 --- a/tools/cli/package.json +++ b/tools/cli/package.json @@ -20,6 +20,7 @@ "@clack/core": "^0.4.0", "@clack/prompts": "^0.10.0", "@napi-rs/simple-git": "^0.1.19", + "@oxc-node/core": "^0.0.24", "@perfsee/webpack": "^1.13.0", "@sentry/webpack-plugin": "^3.0.0", "@swc/core": "^1.10.1", diff --git a/tools/cli/register.js b/tools/cli/register.js deleted file mode 100644 index 212f6a2b80..0000000000 --- a/tools/cli/register.js +++ /dev/null @@ -1,3 +0,0 @@ -import { register } from 'node:module'; - -register('./hooks.js', import.meta.url); diff --git a/tools/cli/src/run.ts b/tools/cli/src/run.ts index cab5bd1b84..23839083be 100644 --- a/tools/cli/src/run.ts +++ b/tools/cli/src/run.ts @@ -1,4 +1,3 @@ -import { Path } from '@affine-tools/utils/path'; import { execAsync } from '@affine-tools/utils/process'; import type { Package, PackageName } from '@affine-tools/utils/workspace'; @@ -10,8 +9,6 @@ interface RunScriptOptions { ignoreIfNotFound?: boolean; } -const currentDir = Path.dir(import.meta.url); - const ignoreLoaderScripts = [ 'vitest', 'vite', @@ -20,6 +17,7 @@ const ignoreLoaderScripts = [ 'cap', 'tsc', 'typedoc', + 'playwright', /^r$/, /electron(?!-)/, ]; @@ -162,20 +160,17 @@ export class RunCommand extends PackageCommand { const bin = args[0] === 'yarn' ? args[1] : args[0]; - const loader = currentDir.join('../register.js').toFileUrl().toString(); - // very simple test for auto ts/mjs scripts const isLoaderRequired = !ignoreLoaderScripts.some(ignore => new RegExp(ignore).test(bin)) || - process.env.NODE_OPTIONS?.includes('ts-node/esm') || - process.env.NODE_OPTIONS?.includes(loader); + process.env.NODE_OPTIONS?.includes('@oxc-node/core/register'); let NODE_OPTIONS = process.env.NODE_OPTIONS ? [process.env.NODE_OPTIONS] : []; if (isLoaderRequired) { - NODE_OPTIONS.push(`--import=${loader}`); + NODE_OPTIONS.push(`--import=@oxc-node/core/register`); } if (args[0] !== 'yarn') { diff --git a/yarn.lock b/yarn.lock index e733ea5764..09ad254d80 100644 --- a/yarn.lock +++ b/yarn.lock @@ -120,6 +120,7 @@ __metadata: "@clack/core": "npm:^0.4.0" "@clack/prompts": "npm:^0.10.0" "@napi-rs/simple-git": "npm:^0.1.19" + "@oxc-node/core": "npm:^0.0.24" "@perfsee/webpack": "npm:^1.13.0" "@sentry/webpack-plugin": "npm:^3.0.0" "@swc/core": "npm:^1.10.1" @@ -8590,14 +8591,14 @@ __metadata: languageName: node linkType: hard -"@napi-rs/wasm-runtime@npm:^0.2.4, @napi-rs/wasm-runtime@npm:^0.2.5, @napi-rs/wasm-runtime@npm:^0.2.7, @napi-rs/wasm-runtime@npm:^0.2.8": - version: 0.2.8 - resolution: "@napi-rs/wasm-runtime@npm:0.2.8" +"@napi-rs/wasm-runtime@npm:^0.2.4, @napi-rs/wasm-runtime@npm:^0.2.5, @napi-rs/wasm-runtime@npm:^0.2.7, @napi-rs/wasm-runtime@npm:^0.2.8, @napi-rs/wasm-runtime@npm:^0.2.9": + version: 0.2.9 + resolution: "@napi-rs/wasm-runtime@npm:0.2.9" dependencies: "@emnapi/core": "npm:^1.4.0" "@emnapi/runtime": "npm:^1.4.0" "@tybys/wasm-util": "npm:^0.9.0" - checksum: 10/c9f9bf0f7cd20d16f5673086310f97fd4efa2475ec91813c250be27172d0cbacc4ee16686d0dab34a6553f85615db9c0cb8c9aaeeec7e092a254396505e9e771 + checksum: 10/8ebc7d85e11e1b8d71908d5615ff24b27ef7af8287d087fb5cff5a3e545915c7545998d976a9cd6a4315dab4ba0f609439fbe6408fec3afebd288efb0dbdc135 languageName: node linkType: hard @@ -10525,6 +10526,178 @@ __metadata: languageName: node linkType: hard +"@oxc-node/core-android-arm-eabi@npm:0.0.24": + version: 0.0.24 + resolution: "@oxc-node/core-android-arm-eabi@npm:0.0.24" + conditions: os=android & cpu=arm + languageName: node + linkType: hard + +"@oxc-node/core-android-arm64@npm:0.0.24": + version: 0.0.24 + resolution: "@oxc-node/core-android-arm64@npm:0.0.24" + conditions: os=android & cpu=arm64 + languageName: node + linkType: hard + +"@oxc-node/core-darwin-arm64@npm:0.0.24": + version: 0.0.24 + resolution: "@oxc-node/core-darwin-arm64@npm:0.0.24" + conditions: os=darwin & cpu=arm64 + languageName: node + linkType: hard + +"@oxc-node/core-darwin-x64@npm:0.0.24": + version: 0.0.24 + resolution: "@oxc-node/core-darwin-x64@npm:0.0.24" + conditions: os=darwin & cpu=x64 + languageName: node + linkType: hard + +"@oxc-node/core-freebsd-x64@npm:0.0.24": + version: 0.0.24 + resolution: "@oxc-node/core-freebsd-x64@npm:0.0.24" + conditions: os=freebsd & cpu=x64 + languageName: node + linkType: hard + +"@oxc-node/core-linux-arm-gnueabihf@npm:0.0.24": + version: 0.0.24 + resolution: "@oxc-node/core-linux-arm-gnueabihf@npm:0.0.24" + conditions: os=linux & cpu=arm + languageName: node + linkType: hard + +"@oxc-node/core-linux-arm64-gnu@npm:0.0.24": + version: 0.0.24 + resolution: "@oxc-node/core-linux-arm64-gnu@npm:0.0.24" + conditions: os=linux & cpu=arm64 & libc=glibc + languageName: node + linkType: hard + +"@oxc-node/core-linux-arm64-musl@npm:0.0.24": + version: 0.0.24 + resolution: "@oxc-node/core-linux-arm64-musl@npm:0.0.24" + conditions: os=linux & cpu=arm64 & libc=musl + languageName: node + linkType: hard + +"@oxc-node/core-linux-ppc64-gnu@npm:0.0.24": + version: 0.0.24 + resolution: "@oxc-node/core-linux-ppc64-gnu@npm:0.0.24" + conditions: os=linux & cpu=ppc64 & libc=glibc + languageName: node + linkType: hard + +"@oxc-node/core-linux-s390x-gnu@npm:0.0.24": + version: 0.0.24 + resolution: "@oxc-node/core-linux-s390x-gnu@npm:0.0.24" + conditions: os=linux & cpu=s390x & libc=glibc + languageName: node + linkType: hard + +"@oxc-node/core-linux-x64-gnu@npm:0.0.24": + version: 0.0.24 + resolution: "@oxc-node/core-linux-x64-gnu@npm:0.0.24" + conditions: os=linux & cpu=x64 & libc=glibc + languageName: node + linkType: hard + +"@oxc-node/core-linux-x64-musl@npm:0.0.24": + version: 0.0.24 + resolution: "@oxc-node/core-linux-x64-musl@npm:0.0.24" + conditions: os=linux & cpu=x64 & libc=musl + languageName: node + linkType: hard + +"@oxc-node/core-wasm32-wasi@npm:0.0.24": + version: 0.0.24 + resolution: "@oxc-node/core-wasm32-wasi@npm:0.0.24" + dependencies: + "@napi-rs/wasm-runtime": "npm:^0.2.9" + conditions: cpu=wasm32 + languageName: node + linkType: hard + +"@oxc-node/core-win32-arm64-msvc@npm:0.0.24": + version: 0.0.24 + resolution: "@oxc-node/core-win32-arm64-msvc@npm:0.0.24" + conditions: os=win32 & cpu=arm64 + languageName: node + linkType: hard + +"@oxc-node/core-win32-ia32-msvc@npm:0.0.24": + version: 0.0.24 + resolution: "@oxc-node/core-win32-ia32-msvc@npm:0.0.24" + conditions: os=win32 & cpu=ia32 + languageName: node + linkType: hard + +"@oxc-node/core-win32-x64-msvc@npm:0.0.24": + version: 0.0.24 + resolution: "@oxc-node/core-win32-x64-msvc@npm:0.0.24" + conditions: os=win32 & cpu=x64 + languageName: node + linkType: hard + +"@oxc-node/core@npm:^0.0.24": + version: 0.0.24 + resolution: "@oxc-node/core@npm:0.0.24" + dependencies: + "@oxc-node/core-android-arm-eabi": "npm:0.0.24" + "@oxc-node/core-android-arm64": "npm:0.0.24" + "@oxc-node/core-darwin-arm64": "npm:0.0.24" + "@oxc-node/core-darwin-x64": "npm:0.0.24" + "@oxc-node/core-freebsd-x64": "npm:0.0.24" + "@oxc-node/core-linux-arm-gnueabihf": "npm:0.0.24" + "@oxc-node/core-linux-arm64-gnu": "npm:0.0.24" + "@oxc-node/core-linux-arm64-musl": "npm:0.0.24" + "@oxc-node/core-linux-ppc64-gnu": "npm:0.0.24" + "@oxc-node/core-linux-s390x-gnu": "npm:0.0.24" + "@oxc-node/core-linux-x64-gnu": "npm:0.0.24" + "@oxc-node/core-linux-x64-musl": "npm:0.0.24" + "@oxc-node/core-wasm32-wasi": "npm:0.0.24" + "@oxc-node/core-win32-arm64-msvc": "npm:0.0.24" + "@oxc-node/core-win32-ia32-msvc": "npm:0.0.24" + "@oxc-node/core-win32-x64-msvc": "npm:0.0.24" + pirates: "npm:^4.0.7" + dependenciesMeta: + "@oxc-node/core-android-arm-eabi": + optional: true + "@oxc-node/core-android-arm64": + optional: true + "@oxc-node/core-darwin-arm64": + optional: true + "@oxc-node/core-darwin-x64": + optional: true + "@oxc-node/core-freebsd-x64": + optional: true + "@oxc-node/core-linux-arm-gnueabihf": + optional: true + "@oxc-node/core-linux-arm64-gnu": + optional: true + "@oxc-node/core-linux-arm64-musl": + optional: true + "@oxc-node/core-linux-ppc64-gnu": + optional: true + "@oxc-node/core-linux-s390x-gnu": + optional: true + "@oxc-node/core-linux-x64-gnu": + optional: true + "@oxc-node/core-linux-x64-musl": + optional: true + "@oxc-node/core-wasm32-wasi": + optional: true + "@oxc-node/core-win32-arm64-msvc": + optional: true + "@oxc-node/core-win32-ia32-msvc": + optional: true + "@oxc-node/core-win32-x64-msvc": + optional: true + checksum: 10/62813bc609ab7843051f5fdaf63c8244836b11eb63168c03387c12c17f3ce990f81e0cf70747ea88661296eff3302c71104ec8c87da1fbabfa8d682552146cab + languageName: node + linkType: hard + "@oxlint/darwin-arm64@npm:0.16.9": version: 0.16.9 resolution: "@oxlint/darwin-arm64@npm:0.16.9" @@ -28689,6 +28862,13 @@ __metadata: languageName: node linkType: hard +"pirates@npm:^4.0.7": + version: 4.0.7 + resolution: "pirates@npm:4.0.7" + checksum: 10/2427f371366081ae42feb58214f04805d6b41d6b84d74480ebcc9e0ddbd7105a139f7c653daeaf83ad8a1a77214cf07f64178e76de048128fec501eab3305a96 + languageName: node + linkType: hard + "piscina@npm:^5.0.0-alpha.0": version: 5.0.0-alpha.2 resolution: "piscina@npm:5.0.0-alpha.2"