mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-07-20 03:26:47 +08:00
chore: switch to oxnode
This commit is contained in:
@@ -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], {
|
||||
|
||||
@@ -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;
|
||||
@@ -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",
|
||||
|
||||
@@ -1,3 +0,0 @@
|
||||
import { register } from 'node:module';
|
||||
|
||||
register('./hooks.js', import.meta.url);
|
||||
@@ -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') {
|
||||
|
||||
Reference in New Issue
Block a user