@effijs/forge 1.0.0-alpha.0 → 1.0.0-alpha.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json
CHANGED
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { readFile } from "node:fs/promises";
|
|
2
|
+
import path from "node:path";
|
|
3
|
+
import { fileURLToPath } from "node:url";
|
|
4
|
+
|
|
5
|
+
const CONFIG_FILES = new Set(["forge.config.js", ".forgerc.js"]);
|
|
6
|
+
|
|
7
|
+
function isEsmSource(source) {
|
|
8
|
+
return /(^|\n)\s*(import|export)(\s|\{)/.test(source);
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* Node warns (MODULE_TYPELESS_PACKAGE_JSON) when a `.js` file uses ESM syntax
|
|
13
|
+
* and the nearest package.json has no `"type": "module"`. React Native apps
|
|
14
|
+
* stay CommonJS because babel, metro, and jest configs are `module.exports`.
|
|
15
|
+
* Force those Forge configs to load as ESM without changing the app package.
|
|
16
|
+
*/
|
|
17
|
+
export async function load(url, context, nextLoad) {
|
|
18
|
+
if (!url.startsWith("file:")) return nextLoad(url, context);
|
|
19
|
+
|
|
20
|
+
let filePath;
|
|
21
|
+
try {
|
|
22
|
+
filePath = fileURLToPath(url);
|
|
23
|
+
} catch {
|
|
24
|
+
return nextLoad(url, context);
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
if (!CONFIG_FILES.has(path.basename(filePath))) return nextLoad(url, context);
|
|
28
|
+
|
|
29
|
+
const source = await readFile(filePath, "utf8");
|
|
30
|
+
if (!isEsmSource(source)) return nextLoad(url, context);
|
|
31
|
+
|
|
32
|
+
return {
|
|
33
|
+
format: "module",
|
|
34
|
+
source,
|
|
35
|
+
shortCircuit: true,
|
|
36
|
+
};
|
|
37
|
+
}
|
package/src/config/loadConfig.js
CHANGED
|
@@ -1,7 +1,16 @@
|
|
|
1
1
|
import fs from "fs/promises";
|
|
2
|
+
import { register } from "node:module";
|
|
2
3
|
import path from "path";
|
|
3
4
|
import { pathToFileURL } from "url";
|
|
4
5
|
|
|
6
|
+
let esmConfigLoaderReady = false;
|
|
7
|
+
|
|
8
|
+
function ensureEsmConfigLoader() {
|
|
9
|
+
if (esmConfigLoaderReady) return;
|
|
10
|
+
register(new URL("./esmConfigLoader.js", import.meta.url));
|
|
11
|
+
esmConfigLoaderReady = true;
|
|
12
|
+
}
|
|
13
|
+
|
|
5
14
|
const CONFIG_FILES = [
|
|
6
15
|
"forge.config.js",
|
|
7
16
|
"forge.config.mjs",
|
|
@@ -35,6 +44,7 @@ export async function loadLocalConfig(cwd = process.cwd()) {
|
|
|
35
44
|
};
|
|
36
45
|
}
|
|
37
46
|
|
|
47
|
+
if (configFile.endsWith(".js")) ensureEsmConfigLoader();
|
|
38
48
|
const module = await import(pathToFileURL(fullPath).href);
|
|
39
49
|
return {
|
|
40
50
|
config: module.default ?? module,
|