mirror of
https://github.com/nocobase/nocobase.git
synced 2026-09-24 16:02:20 +08:00
Merge branch 'next' into develop
This commit is contained in:
@@ -0,0 +1,52 @@
|
||||
import { defineConfig } from '@nocobase/build';
|
||||
import fs from 'fs/promises';
|
||||
import path from 'path';
|
||||
|
||||
function getPackageRoot(packageName: string) {
|
||||
let resolved = '';
|
||||
try {
|
||||
resolved = require.resolve(`${packageName}/package.json`, { paths: [__dirname] });
|
||||
} catch (_error) {
|
||||
resolved = require.resolve(packageName, { paths: [__dirname] });
|
||||
}
|
||||
|
||||
const marker = `${path.sep}node_modules${path.sep}${packageName.split('/').join(path.sep)}${path.sep}`;
|
||||
const markerIndex = resolved.lastIndexOf(marker);
|
||||
if (markerIndex < 0) {
|
||||
throw new Error(`Cannot resolve package root for ${packageName} from ${resolved}`);
|
||||
}
|
||||
|
||||
return resolved.slice(0, markerIndex + marker.length - 1);
|
||||
}
|
||||
|
||||
async function copyRuntimePackage(packageName: string, copied: Set<string>, log: (msg: string) => void) {
|
||||
if (copied.has(packageName)) {
|
||||
return;
|
||||
}
|
||||
|
||||
copied.add(packageName);
|
||||
|
||||
const source = getPackageRoot(packageName);
|
||||
const packageJson = require(path.join(source, 'package.json'));
|
||||
const target = path.resolve(__dirname, 'dist/node_modules', packageName);
|
||||
|
||||
log(`copying ${packageName} to dist/node_modules`);
|
||||
await fs.mkdir(path.dirname(target), { recursive: true });
|
||||
await fs.cp(source, target, {
|
||||
recursive: true,
|
||||
force: true,
|
||||
dereference: false,
|
||||
verbatimSymlinks: true,
|
||||
});
|
||||
|
||||
const dependencies = Object.keys(packageJson.dependencies || {});
|
||||
for (const dependency of dependencies) {
|
||||
await copyRuntimePackage(dependency, copied, log);
|
||||
}
|
||||
}
|
||||
|
||||
export default defineConfig({
|
||||
afterBuild: async (log) => {
|
||||
await copyRuntimePackage('quickjs-emscripten', new Set<string>(), log);
|
||||
},
|
||||
});
|
||||
@@ -8,7 +8,19 @@
|
||||
*/
|
||||
|
||||
const { parentPort, workerData } = require('node:worker_threads');
|
||||
const { getQuickJS } = require('quickjs-emscripten');
|
||||
const path = require('node:path');
|
||||
|
||||
function loadQuickJS() {
|
||||
const bundledPath = path.join(__dirname, '..', 'node_modules', 'quickjs-emscripten');
|
||||
try {
|
||||
return require(bundledPath);
|
||||
} catch (error) {
|
||||
const packageName = 'quickjs-emscripten';
|
||||
return require(packageName);
|
||||
}
|
||||
}
|
||||
|
||||
const { getQuickJS } = loadQuickJS();
|
||||
|
||||
const MEMORY_LIMIT_BYTES = 128 * 1024 * 1024;
|
||||
const MAX_STACK_SIZE_BYTES = 1024 * 1024;
|
||||
|
||||
Reference in New Issue
Block a user