From e267beed7c90bda28556814e46ce17a94921f590 Mon Sep 17 00:00:00 2001 From: David Kellner <52860029+kellnerd@users.noreply.github.com> Date: Tue, 23 Jul 2024 21:19:05 +0200 Subject: [PATCH] build: Fix dynamic import of metadata modules on Windows (again) I already did this in #34, but it was reverted when we switched from ESM to CJS in #147. Now that a2e7fc7 reintroduced ESM with `tsx`, we need this patch again. --- build/plugin-userscript.ts | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/build/plugin-userscript.ts b/build/plugin-userscript.ts index 86e0bae2..b9309d3c 100644 --- a/build/plugin-userscript.ts +++ b/build/plugin-userscript.ts @@ -1,7 +1,7 @@ import fs from 'node:fs'; import path from 'node:path'; // https://github.com/DefinitelyTyped/DefinitelyTyped/issues/34960 -import { URL } from 'node:url'; +import { pathToFileURL, URL } from 'node:url'; import type { Plugin } from 'rollup'; import type { PackageJson } from 'type-fest'; @@ -162,7 +162,8 @@ export class MetadataGenerator { * @return {Promise} The userscript's metadata. */ public async loadMetadata(): Promise { - const metadataFile = path.resolve('./src', this.options.userscriptName, 'meta.ts'); + // Use file URLs for compatibility with Windows, otherwise drive letters are recognized as an invalid protocol. + const metadataFile = pathToFileURL(path.resolve('./src', this.options.userscriptName, 'meta.ts')).href; // eslint-disable-next-line no-unsanitized/method -- Fine. const specificMetadata = (await import(metadataFile) as { default: UserscriptMetadata }).default; return this.insertDefaultMetadata(specificMetadata);