Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: support windows absolute extends #3062

Merged

Conversation

sheerlox
Copy link
Member

@sheerlox sheerlox commented Nov 16, 2023

Description

Restore support for Windows absolute path in the extends configuration option by using import-from-esm to load the referenced module.

Context

Following the changes in #3037, a user encountered an ERR_UNSUPPORTED_ESM_URL_SCHEME error because using resolve-from does not return an URL, and import then considers C:/ to be an URL scheme (like file://) and returns the encountered error.

How has this been tested

Since there are no Windows-specific tests on this repository and the test pipeline doesn't run on Windows, we can rely on import-from-esm solid test suite to guarantee this works:

Related issues

Copy link
Member

@travi travi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

just one thought wondering if we could clean things up furhter. i havent dug in to better understand if that is a reasonable follow up or not, but i'm going to move this forward and we can do that as a separate PR if it does make sense.

thanks for sticking with this @sheerlox!

import { fileURLToPath } from "node:url";

import { castArray, isNil, isPlainObject, isString, pickBy } from "lodash-es";
import { readPackageUp } from "read-pkg-up";
import { cosmiconfig } from "cosmiconfig";
import resolveFrom from "resolve-from";
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is resolve-from still used elsewhere in the project? would it be possible to remove it as a dependency?

Copy link
Member Author

@sheerlox sheerlox Nov 17, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes it is still being used in the loadPlugin function, and we can't replace it with import-from-esm it because doesn't support ESM named exports (it only returns the whole module if the default export does not exist).
At least this part of the code is not subject to the Windows absolute path issue since the import statement explicitly specifies the file:// protocol.

export async function loadPlugin({ cwd }, name, pluginsPath) {
const basePath = pluginsPath[name]
? dirname(resolveFrom.silent(__dirname, pluginsPath[name]) || resolveFrom(cwd, pluginsPath[name]))
: __dirname;
if (isFunction(name)) {
return name;
}
const file = resolveFrom.silent(basePath, name) || resolveFrom(cwd, name);
const { default: cjsExport, ...esmNamedExports } = await import(`file://${file}`);
if (cjsExport) {
return cjsExport;
}
return esmNamedExports;
}

@travi travi merged commit 0d06f62 into semantic-release:master Nov 17, 2023
6 checks passed
Copy link

🎉 This PR is included in version 22.0.8 🎉

The release is available on:

Your semantic-release bot 📦🚀

@sheerlox sheerlox deleted the fix/support-windows-absolute-extends branch November 17, 2023 06:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants