From 5385d249cb955df648c74e40644585b61ac2482c Mon Sep 17 00:00:00 2001 From: Joe Hildebrand Date: Thu, 17 Oct 2024 15:31:29 -0600 Subject: [PATCH] Fixes #567. Use file: URLs to import ES6. --- CHANGELOG.md | 21 ++++++++------------- bin/opts.js | 6 ++++-- 2 files changed, 12 insertions(+), 15 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 0177290c..3a804da2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -14,6 +14,8 @@ Released: TBD ### Bug fixes +- [#567](https://github.com/peggyjs/peggy/issues/567) Load config files and plugins correctly on Windows by using file: URIs in import(). + ### Documentation 4.1.0 @@ -23,23 +25,16 @@ Released: 2024-10-03 ### New features -- [#477](https://github.com/peggyjs/peggy/issues/477) Option to output .d.ts - files next to .js from CLI. +- [#477](https://github.com/peggyjs/peggy/issues/477) Option to output .d.ts files next to .js from CLI. - [#530](https://github.com/peggyjs/peggy/issues/531) Allow es6 plugins from CLI -- [#532](https://github.com/peggyjs/peggy/issues/532) Allow es6 options files - from the CLI +- [#532](https://github.com/peggyjs/peggy/issues/532) Allow es6 options files from the CLI ### Bug fixes -- [#531](https://github.com/peggyjs/peggy/issues/531) Clean up rollup hacks - from CLI code. -- [#514](https://github.com/peggyjs/peggy/issues/514) Allow execution of - the `peggy` binary on Windows by handling node runtime flags manually, - executing a sub-instance of node to actually run `peggy`. -- [#538](https://github.com/peggyjs/peggy/pull/509) Fixed error in TS types - for `peg$maxFailExpected` and `peg$maxFailPos`. -- [#551](https://github.com/peggyjs/peggy/pull/551) Moved to package-extract - instead of a custom script for version file generation. +- [#531](https://github.com/peggyjs/peggy/issues/531) Clean up rollup hacks from CLI code. +- [#514](https://github.com/peggyjs/peggy/issues/514) Allow execution of the `peggy` binary on Windows by handling node runtime flags manually, executing a sub-instance of node to actually run `peggy`. +- [#538](https://github.com/peggyjs/peggy/pull/509) Fixed error in TS types for `peg$maxFailExpected` and `peg$maxFailPos`. +- [#551](https://github.com/peggyjs/peggy/pull/551) Moved to package-extract instead of a custom script for version file generation. 4.0.3 ----- diff --git a/bin/opts.js b/bin/opts.js index 99345985..fc43bd43 100644 --- a/bin/opts.js +++ b/bin/opts.js @@ -10,6 +10,7 @@ const fs = require("fs"); const path = require("path"); const { InvalidArgumentError } = require("commander"); const { isErrno, isER, replaceExt, select } = require("./utils.js"); +const { pathToFileURL } = require("url"); const MODULE_FORMATS_WITH_DEPS = ["amd", "commonjs", "es", "umd"]; const MODULE_FORMATS_WITH_GLOBAL = ["globals", "umd"]; @@ -140,7 +141,8 @@ function addExtraOptionsJSON(cmd, json, source) { async function loadConfig(cmd, val) { if (/\.[cm]?js$/.test(val)) { try { - const eOpts = await import(path.resolve(val)); + const configURL = pathToFileURL(path.resolve(val)).toString(); + const eOpts = await import(configURL); addExtraOptions(cmd, eOpts.default, "extra-options-file"); } catch (error) { isER(error); @@ -171,7 +173,7 @@ async function loadPlugin(cmd, val) { // If this is an absolute or relative path (not a module name) const id = (path.isAbsolute(val) || /^\.\.?[/\\]/.test(val)) - ? path.resolve(val) + ? pathToFileURL(path.resolve(val)).toString() : val; // Otherwise, it's an NPM module /** @type {PEG.Plugin=} */