This repository has been archived by the owner on Aug 22, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 36
Fix plugins not being found when no node_modules exists #171
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
import * as path from 'path' | ||
|
||
import {expect, fancy} from './test' | ||
import * as Plugin from '../src/plugin' | ||
import * as util from '../src/util' | ||
|
||
const root = path.resolve(__dirname, 'fixtures/typescript') | ||
const pluginName = '@oclif/plugin-help' | ||
const pluginLocation = 'some/external/directory' | ||
const pluginPjsonLocation = path.join(pluginLocation, 'package.json') | ||
|
||
const withPluginInstance = () => { | ||
return fancy | ||
.add('plugin', () => new Plugin.Plugin({ | ||
type: 'core', | ||
root, | ||
name: pluginName, | ||
ignoreManifest: true, | ||
})) | ||
.stub(util, 'exists', (checkPath: string) => checkPath === pluginPjsonLocation) | ||
.stub(util, 'resolvePackage', (id: string): Promise<string> => { | ||
if (id !== pluginName) { | ||
return Promise.reject() | ||
} | ||
return Promise.resolve(path.join(pluginLocation, 'lib', 'index.js')) | ||
}) | ||
.stub(util, 'loadJSON', (jsonPath: string) => { | ||
if (jsonPath !== pluginPjsonLocation) { | ||
return {} | ||
} | ||
return { | ||
name: pluginName, | ||
version: '1.0.0', | ||
files: [], | ||
oclif: {}, | ||
} | ||
}) | ||
} | ||
|
||
describe('Plugin', () => { | ||
withPluginInstance() | ||
.it('Should correctly instantiate a Plugin instance', ctx => { | ||
expect(ctx.plugin).to.be.instanceOf( | ||
Plugin.Plugin, | ||
'Expected instance to be an instance of Plugin!', | ||
) | ||
}) | ||
|
||
withPluginInstance() | ||
.it('Should correctly load a Plugin', async ctx => { | ||
await ctx.plugin.load() | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
I think you need to pass in
{ basedir: root }
because it may need to look outside of the current path. i.e. where user plugins are stored.With that said, the
resolve
library isn't working how I thought it would. If I add the basedir above, it will still sometimes throwMODULE_NOT_FOUND
even though it seems to be in the resolution path.For example, I modified resolvePackage to take in the same options object that resolve takes and pass that to resolve.
That package is in
/Users/t.dvornik/.local/share/sfdx/node_modules/@salesforce/plugin-evergreen-build
which should be in node module resolution but resolve isn't resolving it.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.
Thanks for looking at this - this issue flew under the radar for me for a minute, but I'll have a look to see if I can fix it sometime soon. It's not high priority for me but evidently there's a few others others also waiting on a fix.
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.
Any reason we don't just use the native
require.resolve
over theresolve
package? it doesn't appear that we really need it to resolve asynchronously for our use case.