@farmfe/runtime
Advanced tools
Comparing version 0.3.3 to 0.3.4
# @farmfe/runtime | ||
## 0.3.4 | ||
### Patch Changes | ||
- Auto external node native module when reading farm.config.ts | ||
## 0.3.3 | ||
@@ -4,0 +10,0 @@ |
{ | ||
"name": "@farmfe/runtime", | ||
"version": "0.3.3", | ||
"version": "0.3.4", | ||
"description": "Runtime of Farm", | ||
@@ -5,0 +5,0 @@ "author": { |
import { Module } from './module'; | ||
import { FarmRuntimePlugin, FarmRuntimePluginContainer } from './plugin'; | ||
import { Resource, ResourceLoader } from './resource-loader'; | ||
import { Resource, ResourceLoader, targetEnv } from './resource-loader'; | ||
@@ -52,2 +52,19 @@ /* eslint-disable @typescript-eslint/no-explicit-any */ | ||
// if running on node, using native require to load node built-in modules | ||
if (targetEnv === 'node') { | ||
const { __farmNodeRequire, __farmNodeBuiltinModules } = | ||
// TODO: polyfill globalThis | ||
globalThis as unknown as { | ||
__farmNodeRequire: (id: string) => any; | ||
__farmNodeBuiltinModules: string[]; | ||
}; | ||
if (moduleId.startsWith('node:')) { | ||
const nodeModuleId = moduleId.slice(5); | ||
return __farmNodeRequire(nodeModuleId); | ||
} else if (__farmNodeBuiltinModules.includes(moduleId)) { | ||
return __farmNodeRequire(moduleId); | ||
} | ||
} | ||
const initializer = this.modules[moduleId]; | ||
@@ -54,0 +71,0 @@ |
@@ -8,5 +8,6 @@ // using native ability to load resources if target env is node. | ||
// eslint-disable-next-line @typescript-eslint/ban-ts-comment | ||
// @ts-ignore do not check type here | ||
const targetEnv = (globalThis || global || window || self).__FARM_TARGET_ENV__; | ||
export const targetEnv = | ||
// eslint-disable-next-line @typescript-eslint/ban-ts-comment | ||
// @ts-ignore do not check type here | ||
(globalThis || global || window || self).__FARM_TARGET_ENV__ || 'node'; | ||
@@ -13,0 +14,0 @@ /** |
15664
419