mirror of
https://github.com/nocobase/nocobase.git
synced 2026-09-21 05:44:51 +08:00
fix(runjs): resolve source exports in subprocesses
This commit is contained in:
@@ -5,3 +5,4 @@
|
||||
!/es/**
|
||||
/src/completion-catalog/generated.ts
|
||||
/src/generated/
|
||||
/register-source.cjs
|
||||
|
||||
@@ -161,6 +161,8 @@
|
||||
},
|
||||
"devDependencies": {
|
||||
"ajv": "^6.12.6",
|
||||
"cross-spawn": "^7.0.6"
|
||||
"cross-spawn": "^7.0.6",
|
||||
"tsconfig-paths": "^4.2.0",
|
||||
"tsx": "^4.19.0"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,14 @@
|
||||
const path = require('node:path');
|
||||
|
||||
require('tsx/cjs');
|
||||
|
||||
const { register } = require('tsconfig-paths');
|
||||
|
||||
register({
|
||||
baseUrl: path.resolve(__dirname, 'src'),
|
||||
paths: {
|
||||
'@nocobase/runjs': ['index.ts'],
|
||||
'@nocobase/runjs/package.json': ['../package.json'],
|
||||
'@nocobase/runjs/*': ['*'],
|
||||
},
|
||||
});
|
||||
+2
-1
@@ -137,7 +137,8 @@ function registerCompileContractTests() {
|
||||
});
|
||||
|
||||
function readCompilerBuildId(script: string): string {
|
||||
return execFileSync(process.execPath, ['--import', 'tsx', '--eval', script], {
|
||||
const runJSSourceRegisterPath = path.resolve(__dirname, '../../../../../../core/runjs/register-source.cjs');
|
||||
return execFileSync(process.execPath, ['--require', runJSSourceRegisterPath, '--import', 'tsx', '--eval', script], {
|
||||
cwd: process.cwd(),
|
||||
encoding: 'utf8',
|
||||
}).trim();
|
||||
|
||||
+3
@@ -30,10 +30,13 @@ import PluginJsTemplateServer from '../plugin';
|
||||
describe('plugin-js-template bootstrap', () => {
|
||||
it('keeps the RunJS compiler unloaded until the first compile', () => {
|
||||
const serverEntryUrl = pathToFileURL(path.resolve(__dirname, '../index.ts')).href;
|
||||
const runJSSourceRegisterPath = path.resolve(__dirname, '../../../../../../core/runjs/register-source.cjs');
|
||||
expect(() =>
|
||||
execFileSync(
|
||||
process.execPath,
|
||||
[
|
||||
'--require',
|
||||
runJSSourceRegisterPath,
|
||||
'--import',
|
||||
'tsx',
|
||||
'--input-type=module',
|
||||
|
||||
+11
-1
@@ -8,6 +8,7 @@
|
||||
*/
|
||||
|
||||
import path from 'node:path';
|
||||
import { createRequire } from 'node:module';
|
||||
import { performance } from 'node:perf_hooks';
|
||||
import { deserialize, serialize } from 'node:v8';
|
||||
import { Worker } from 'node:worker_threads';
|
||||
@@ -798,9 +799,18 @@ function assertIntegerLimit(label: string, value: number, minimum: number, maxim
|
||||
function createDefaultWorker(): JsTemplateCompileWorkerHandle {
|
||||
const isTypeScriptRuntime = __filename.endsWith('.ts');
|
||||
const workerPath = path.join(__dirname, `JsTemplateCompileWorker.${isTypeScriptRuntime ? 'ts' : 'js'}`);
|
||||
const sourceRuntimeExecArgv = isTypeScriptRuntime
|
||||
? [
|
||||
'--require',
|
||||
path.join(
|
||||
path.dirname(createRequire(__filename).resolve('@nocobase/runjs/package.json')),
|
||||
'register-source.cjs',
|
||||
),
|
||||
]
|
||||
: undefined;
|
||||
return new NodeCompileWorkerHandle(
|
||||
new Worker(workerPath, {
|
||||
execArgv: isTypeScriptRuntime ? ['--require', 'tsx/cjs'] : undefined,
|
||||
execArgv: sourceRuntimeExecArgv,
|
||||
}),
|
||||
);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user