Compare commits

...

5 Commits

Author SHA1 Message Date
LongYinan
2bfc7e33f1 Fix 2025-05-05 15:51:28 +08:00
LongYinan
e320240f24 Update run.ts 2025-05-05 15:51:28 +08:00
LongYinan
93d93abd8a Fix cycle require yarn.js 2025-05-05 15:51:28 +08:00
LongYinan
7fbe5173c3 reduce server tests sharding 2025-05-05 15:51:28 +08:00
LongYinan
359ed9698b chore: switch to oxnode 2025-05-05 15:51:27 +08:00
8 changed files with 217 additions and 49 deletions

View File

@@ -542,8 +542,8 @@ jobs:
strategy:
fail-fast: false
matrix:
node_index: [0, 1, 2, 3, 4, 5, 6, 7]
total_nodes: [8]
node_index: [0, 1, 2, 3]
total_nodes: [4]
env:
NODE_ENV: test
DATABASE_URL: postgresql://affine:affine@localhost:5432/affine

View File

@@ -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<number>('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);

View File

@@ -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], {

View File

@@ -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;

View File

@@ -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",

View File

@@ -1,3 +0,0 @@
import { register } from 'node:module';
register('./hooks.js', import.meta.url);

View File

@@ -1,4 +1,5 @@
import { Path } from '@affine-tools/utils/path';
import path from 'node:path';
import { execAsync } from '@affine-tools/utils/process';
import type { Package, PackageName } from '@affine-tools/utils/workspace';
@@ -10,8 +11,6 @@ interface RunScriptOptions {
ignoreIfNotFound?: boolean;
}
const currentDir = Path.dir(import.meta.url);
const ignoreLoaderScripts = [
'vitest',
'vite',
@@ -20,6 +19,7 @@ const ignoreLoaderScripts = [
'cap',
'tsc',
'typedoc',
'playwright',
/^r$/,
/electron(?!-)/,
];
@@ -162,25 +162,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);
!ignoreLoaderScripts.some(ignore => new RegExp(ignore).test(bin)) &&
!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}`);
}
if (args[0] !== 'yarn') {
// add 'yarn' to the command so we can bypass bin execution to it
args.unshift('yarn');
NODE_OPTIONS.push(`--import=@oxc-node/core/register`);
}
await execAsync(pkg.name, args, {
@@ -188,6 +180,11 @@ export class RunCommand extends PackageCommand {
env: {
...envs,
NODE_OPTIONS: NODE_OPTIONS.join(' '),
PATH: `${path.join(pkg.nodeModulesPath.value, '.bin')}${path.delimiter}${path.join(
this.workspace.path.value,
'node_modules',
'.bin'
)}${path.delimiter}${process.env.PATH}`,
},
});
}

188
yarn.lock
View File

@@ -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"