-
Notifications
You must be signed in to change notification settings - Fork 70
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: pass plugin type when resolving a module path #659
Conversation
try { | ||
filePath = require.resolve(modulePath) | ||
isESM = ModuleLoader.isPathModule(filePath) | ||
} catch { | ||
filePath = Config.tsPath(config.root, modulePath) | ||
filePath = isPlugin(config) ? Config.tsPath(config.root, modulePath, config.type) : Config.tsPath(config.root, modulePath) |
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.
pass plugin.type
to Config.tsPath
if config
is a plugin.
hooks get loaded here:
https://github.com/oclif/core/blob/main/src/config/config.ts#L310
usually these are paths to compiled JS files like this one:
https://github.com/salesforcecli/plugin-info/blob/main/package.json#L93
Linked plugins are supposed to get compiled at runtime by ts-node but hooks were being skipped because the plugin.type
wasn't being passed to tsPath
:
https://github.com/oclif/core/blob/main/src/config/ts-node.ts#L101
commands from linked plugins are loaded here (see plugin.type
is being passed):
https://github.com/oclif/core/blob/main/src/config/plugin.ts#L182
@@ -136,11 +136,15 @@ export default class ModuleLoader { | |||
let isESM: boolean | |||
let filePath: string | |||
|
|||
const isPlugin = (config: IConfig|IPlugin): config is IPlugin => { |
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.
TS guard, used to pass plugin.type
when config comes from a plugin.
This issue has been linked to a new work item: W-12702335 |
This fixes a bug where linked plugins with hooks were causing a CLI to fail with the
ModuleLoadError: [MODULE_NOT_FOUND] require failed to load
.#650 introduced compilation at runtime for linked TS plugins using
ts-node
.When trying to compile hooks from linked plugins oclif isn't passing the
plugin.type
prop to the ts path resolver sotsPath
was just skipping the compilation step.Before:
After
Testing
Repro
plugin-info
(doctor hook)rm -rf lib
../sfdx-cli/bin/run plugins:link .
../sfdx-cli/bin/run
, should see theMODULE_NOT_FOUND
QA
plugin-info
(doctor hook)rm -rf lib
../sfdx-cli/bin/run plugins:link .
../sfdx-cli/bin/run
, CLI should work.