Skip to content

Commit 84ccaea

Browse files
committed
Use pathToFileURL so that import() works under ESM across platforms
1 parent 5ad5ad4 commit 84ccaea

File tree

1 file changed

+9
-8
lines changed

1 file changed

+9
-8
lines changed

src/cli/util/config.ts

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
*/
55

66
import path from 'node:path';
7+
import { pathToFileURL } from 'node:url';
78

89
import globToRegExp from 'glob-to-regexp';
910

@@ -35,11 +36,11 @@ export async function loadStaticPublisherRcFile(): Promise<StaticPublishRc> {
3536

3637
const configFile = './static-publish.rc.js';
3738

39+
const configFilePath = path.resolve(configFile);
3840
try {
39-
const filePath = path.resolve(configFile);
40-
configRaw = (await import(filePath)).default;
41-
} catch {
42-
//
41+
configRaw = (await import(pathToFileURL(configFilePath).href)).default;
42+
} catch (ex) {
43+
console.log('Unable to load ' + configFilePath, String(ex));
4344
}
4445

4546
if (configRaw == null) {
@@ -128,11 +129,11 @@ export async function loadPublishContentConfigFile(configFile: string): Promise<
128129

129130
let configRaw;
130131

132+
const configFilePath = path.resolve(configFile);
131133
try {
132-
const filePath = path.resolve(configFile);
133-
configRaw = (await import(filePath)).default;
134-
} catch {
135-
//
134+
configRaw = (await import(pathToFileURL(configFilePath).href)).default;
135+
} catch (ex) {
136+
console.log('Unable to load ' + configFilePath, String(ex));
136137
}
137138

138139
if (configRaw == null) {

0 commit comments

Comments
 (0)