Skip to content

Commit bf64f33

Browse files
committed
Use pathToFileURL so that import() works under ESM across platforms
1 parent 7f1edde commit bf64f33

File tree

1 file changed

+19
-10
lines changed

1 file changed

+19
-10
lines changed

src/cli/util/config.ts

Lines changed: 19 additions & 10 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

@@ -46,16 +47,20 @@ export async function loadStaticPublisherRcFile(): Promise<StaticPublishRc> {
4647

4748
const configFile = './static-publish.rc.js';
4849

50+
const configFilePath = path.resolve(configFile);
4951
try {
50-
const filePath = path.resolve(configFile);
51-
configRaw = (await import(filePath)).default;
52-
} catch {
53-
//
52+
configRaw = (await import(pathToFileURL(configFilePath).href)).default;
53+
} catch (ex) {
54+
throw new LoadConfigError(configFile, [
55+
`Unable to load ${configFilePath}`,
56+
String(ex),
57+
]);
5458
}
5559

5660
if (configRaw == null) {
5761
throw new LoadConfigError(configFile, [
58-
'Unable to load ' + configFile,
62+
`Unable to load ${configFilePath}`,
63+
`default export does not exist or is null.`
5964
]);
6065
}
6166

@@ -143,16 +148,20 @@ export async function loadPublishContentConfigFile(configFile: string): Promise<
143148

144149
let configRaw;
145150

151+
const configFilePath = path.resolve(configFile);
146152
try {
147-
const filePath = path.resolve(configFile);
148-
configRaw = (await import(filePath)).default;
149-
} catch {
150-
//
153+
configRaw = (await import(pathToFileURL(configFilePath).href)).default;
154+
} catch (ex) {
155+
throw new LoadConfigError(configFile, [
156+
`Unable to load ${configFilePath}`,
157+
String(ex),
158+
]);
151159
}
152160

153161
if (configRaw == null) {
154162
throw new LoadConfigError(configFile, [
155-
'Unable to load ' + configFile,
163+
`Unable to load ${configFilePath}`,
164+
`default export does not exist or is null.`
156165
]);
157166
}
158167

0 commit comments

Comments
 (0)