Skip to content

Commit

Permalink
CLI: Fix ESM dynamic import issue with absolute paths on Windows
Browse files Browse the repository at this point in the history
  • Loading branch information
webketje committed Apr 27, 2023
1 parent 58217a5 commit 4469020
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions bin/metalsmith
Expand Up @@ -5,6 +5,7 @@
const exists = require('fs').existsSync
const readFileSync = require('fs').readFileSync
const Metalsmith = require('..')
const { pathToFileURL } = require('url')
const { Command } = require('commander')
const program = new Command()
const { resolve, isAbsolute, dirname, extname } = require('path')
Expand Down Expand Up @@ -68,6 +69,11 @@ async function buildCommand({ config, ...cliOptions }) {

const format = extname(path).slice(1)

// avoid ESM dynamic import error with absolute paths on Windows:
// Only URLs with a scheme in: file and data are supported by the default ESM loader. On Windows, absolute paths must be valid file:// URLs.
// cf also https://github.com/nuxt/nuxt/issues/15500#issuecomment-1451619865
path = pathToFileURL(path);

let spec
try {
if (format.match(/^[cm]*js$/)) {
Expand Down

0 comments on commit 4469020

Please sign in to comment.