From 5a1b9516ea8b3dfb89e378ba98e226221f19dbfe Mon Sep 17 00:00:00 2001 From: Jiri Lojda Date: Thu, 31 Oct 2024 09:34:18 +0100 Subject: [PATCH] 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 --- src/modules/migrations/utils/migrationUtils.ts | 8 +++++--- src/modules/migrations/utils/statusUtils.ts | 3 ++- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/src/modules/migrations/utils/migrationUtils.ts b/src/modules/migrations/utils/migrationUtils.ts index fcb52e1c..96479b0d 100644 --- a/src/modules/migrations/utils/migrationUtils.ts +++ b/src/modules/migrations/utils/migrationUtils.ts @@ -1,7 +1,9 @@ +import * as fs from "node:fs"; +import path from "node:path"; +import { pathToFileURL } from "node:url"; + import { ManagementClient } from "@kontent-ai/management-sdk"; import chalk from "chalk"; -import * as fs from "fs"; -import path from "path"; import { match, P } from "ts-pattern"; import { logError, logInfo, LogOptions } from "../../../log.js"; @@ -92,7 +94,7 @@ export const loadMigrationFiles = async (folderPath: string): Promise file.isFile() && file.name.endsWith("js")) .map(async file => { const migrationPath = path.join(folderPath, file.name); - const module = (await import(migrationPath)).default; + const module = (await import(pathToFileURL(migrationPath).href)).default; if (isMigrationModule(module)) { return { name: file.name, module }; diff --git a/src/modules/migrations/utils/statusUtils.ts b/src/modules/migrations/utils/statusUtils.ts index e198d4f0..c0d47e97 100644 --- a/src/modules/migrations/utils/statusUtils.ts +++ b/src/modules/migrations/utils/statusUtils.ts @@ -1,5 +1,6 @@ import * as fs from "node:fs"; import * as path from "node:path"; +import { pathToFileURL } from "node:url"; import { MigrationOperation, @@ -43,7 +44,7 @@ export const loadStatusPlugin = async (pluginsPath: string): Promise