fix(taskr): use createRequire to perform relative requires and add missing optional peer dependency @taskr/esnext#317
Conversation
lukeed
left a comment
There was a problem hiding this comment.
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 lintThe 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?
taskrmakes assumptions about thenode_moduleslayout and tries to require files directly from it instead of usingcreateRequire,taskralso has an optional peer dependency on@taskr/esnextthat 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?
createRequireto perform the require relative to thebasehttps://nodejs.org/api/module.html#module_module_createrequire_filename@taskr/esnextas a optional peer dependencycc @lukeed @arcanis