-
Notifications
You must be signed in to change notification settings - Fork 73
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(taskr): use createRequire to perform relative requires and add missing optional peer dependency @taskr/esnext #317
base: master
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you, but I think just defining peerDep is all that's needed. Installers will preserve access to the taskr/esnext
Do you mean just making |
No, still optional. You already have it listed as a peerDependency. That's enough to have |
Do you want me to remove the |
Can you please include or list steps for a simple reproduction? |
Sure, here is a sh file that will reproduce the issue mkdir taskr-repro
cd taskr-repro
printf "exports.lint = function * (task) {
yield task.source('src/**/*.js').prettier({
semi: false,
useTabs: true,
trailingComma: 'es5'
}).target('dist/js');
}" > taskfile.js
mkdir src
printf "console.log('foo'); // bar" > src/index.js
yarn init -y2p
yarn config set pnpFallbackMode none
yarn add taskr @taskr/prettier
PNP_DEBUG_LEVEL=1 yarn taskr lint The issue is that The solution is to perform the require relative to the users project which declares the plugins. |
695899b
to
ae06ae0
Compare
@lukeed Anything else you'd like me to do to move this forward? |
Hey, sorry for the delay on this! Never got around to setting up yarn@2 (don't want to alter my environment) Should't something like this work too? I have something like this in other places: function req(name, base) {
try {
return require( require.resolve(name, { paths: [base] }) );
} catch (e) {
$.alert(e.message);
}
} |
No worries :)
Yarn@2 is installed on a per project basis so you would only alter a single project, the repro I provided does just that in the init command.
Most likely yes, it's only in some rare cases where it doesn't quite work. However, since taskr is set to target 1: taskr/packages/taskr/package.json Line 52 in 82d0bef
2: https://nodejs.org/api/modules.html#modules_require_resolve_request_options |
@lukeed Sorry to ping again but would be nice to get this merged |
What's the problem this PR addresses?
taskr
makes assumptions about thenode_modules
layout and tries to require files directly from it instead of usingcreateRequire
,taskr
also has an optional peer dependency on@taskr/esnext
that it doesn't declare making it rely heavily on hoisting to place it in an accesible location.Read https://yarnpkg.com/advanced/rulebook for more in depth information
How did you fix it?
createRequire
to perform the require relative to thebase
https://nodejs.org/api/module.html#module_module_createrequire_filename@taskr/esnext
as a optional peer dependencycc @lukeed @arcanis