Skip to content

Commit

Permalink
Use URLs instead of paths to import plugins and migrations
Browse files Browse the repository at this point in the history
- plain absolute paths don't work on Windows so they need to be converted to file URLs
  • Loading branch information
JiriLojda committed Oct 31, 2024
1 parent 2ce9dd4 commit 5a1b951
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 deletions.
8 changes: 5 additions & 3 deletions src/modules/migrations/utils/migrationUtils.ts
Original file line number Diff line number Diff line change
@@ -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";
Expand Down Expand Up @@ -92,7 +94,7 @@ export const loadMigrationFiles = async (folderPath: string): Promise<WithErr<Mi
.filter(file => 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 };
Expand Down
3 changes: 2 additions & 1 deletion src/modules/migrations/utils/statusUtils.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import * as fs from "node:fs";
import * as path from "node:path";
import { pathToFileURL } from "node:url";

import {
MigrationOperation,
Expand Down Expand Up @@ -43,7 +44,7 @@ export const loadStatusPlugin = async (pluginsPath: string): Promise<WithErr<Sta
return { err: `Provided plugins path ${pluginsPath} does not exists` };
}

const pluginModule = await import(pluginsPath);
const pluginModule = await import(pathToFileURL(pluginsPath).href);

return { value: statusPluginSchema.parse(pluginModule) };
};
Expand Down

0 comments on commit 5a1b951

Please sign in to comment.