Skip to content

Commit d78206d

Browse files
committed
Use URLs instead of paths to import plugins and migrations
- plain absolute paths don't work on Windows so they need to be converted to file URLs
1 parent f80ba7f commit d78206d

File tree

2 files changed

+7
-4
lines changed

2 files changed

+7
-4
lines changed

src/modules/migrations/utils/migrationUtils.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
1+
import * as fs from "node:fs";
2+
import path from "node:path";
3+
import { pathToFileURL } from "node:url";
4+
15
import { ManagementClient } from "@kontent-ai/management-sdk";
26
import chalk from "chalk";
3-
import * as fs from "fs";
4-
import path from "path";
57
import { match, P } from "ts-pattern";
68

79
import { logError, logInfo, LogOptions } from "../../../log.js";
@@ -92,7 +94,7 @@ export const loadMigrationFiles = async (folderPath: string): Promise<WithErr<Mi
9294
.filter(file => file.isFile() && file.name.endsWith("js"))
9395
.map(async file => {
9496
const migrationPath = path.join(folderPath, file.name);
95-
const module = (await import(migrationPath)).default;
97+
const module = (await import(pathToFileURL(migrationPath).href)).default;
9698

9799
if (isMigrationModule(module)) {
98100
return { name: file.name, module };

src/modules/migrations/utils/statusUtils.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import * as fs from "node:fs";
22
import * as path from "node:path";
3+
import { pathToFileURL } from "node:url";
34

45
import {
56
MigrationOperation,
@@ -43,7 +44,7 @@ export const loadStatusPlugin = async (pluginsPath: string): Promise<WithErr<Sta
4344
return { err: `Provided plugins path ${pluginsPath} does not exist.` };
4445
}
4546

46-
const pluginModule = await import(pluginsPath);
47+
const pluginModule = await import(pathToFileURL(pluginsPath).href);
4748

4849
return { value: statusPluginSchema.parse(pluginModule) };
4950
};

0 commit comments

Comments
 (0)