Skip to content

Commit

Permalink
fix: use pathToFileURL when loading config
Browse files Browse the repository at this point in the history
  • Loading branch information
uhyo committed Dec 28, 2024
1 parent bfb0f89 commit 2b1976b
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 deletions.
4 changes: 2 additions & 2 deletions crates/config-file/src/node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -116,8 +116,8 @@ pub async fn run_node(code: &str) -> io::Result<String> {
pub async fn load_default_from_js_file(path: &Path) -> io::Result<String> {
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()
Expand Down
7 changes: 5 additions & 2 deletions packages/core/src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";

/**
Expand Down Expand Up @@ -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));
`);
}
Expand Down

0 comments on commit 2b1976b

Please sign in to comment.