From 2b1976bf3bd3d33f75e1db03a40d77ec7696cd83 Mon Sep 17 00:00:00 2001 From: uhyo Date: Sat, 28 Dec 2024 18:15:31 +0900 Subject: [PATCH] fix: use pathToFileURL when loading config --- crates/config-file/src/node.rs | 4 ++-- packages/core/src/config.ts | 7 +++++-- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/crates/config-file/src/node.rs b/crates/config-file/src/node.rs index 7dbc361..0041c9b 100644 --- a/crates/config-file/src/node.rs +++ b/crates/config-file/src/node.rs @@ -116,8 +116,8 @@ pub async fn run_node(code: &str) -> io::Result { pub async fn load_default_from_js_file(path: &Path) -> io::Result { run_node(&format!( r#" -import config from "{}"; -import {{ stdout }} from "process"; +import {{ pathToFileURL }} from "url"; +const config = (await import(pathToFileURL("{}").toString())).default; export default config?.default ?? config; "#, path.to_string_lossy().escape_default() diff --git a/packages/core/src/config.ts b/packages/core/src/config.ts index 909ae24..b024704 100644 --- a/packages/core/src/config.ts +++ b/packages/core/src/config.ts @@ -2,8 +2,9 @@ * @file `nitrogql_helper/config` namespace. */ +import { pathToFileURL } from "node:url"; import { execFileSync } from "node:child_process"; -import { getMemory, readString, utf8Len, writeString } from "./memory.js"; +import { readString, utf8Len, writeString } from "./memory.js"; import { getCommandClient } from "./command/commandClient.js"; /** @@ -55,8 +56,10 @@ export function executeNodeSync(code: string): string { */ export function executeConfigFileSync(configFilePath: string): string { return executeNodeSync(` -import config from ${JSON.stringify(configFilePath)}; import { stdout } from "process"; +const config = (await import(${JSON.stringify( + pathToFileURL(configFilePath).toString() + )})).default; stdout.write(JSON.stringify(config.default ?? config)); `); }