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
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Re: Fix plugins not being found when no node_modules exists (#289)
* Implement test for plugin load This test should pass when it has been updated to use resolve * Update findRoot to use resolve function * Fix findRoot not working due to incorrect assumptions Assume resolve returns an entry file not a directory * use `require.resolve` instead of `resolve` package * remove `resolve` types * return directory instead of resolved file * undo previous commit * adds root to one of the starting resolution paths * fallback to legacy dependency resolution if not found * grammar Co-authored-by: Ryan Paroz <[email protected]>
- Loading branch information
1 parent
47a4711
commit 208b2d7
Showing
3 changed files
with
92 additions
and
12 deletions.
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
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): string => { | ||
if (id !== pluginName) { | ||
throw new Error(`resolvePackage: expected ${pluginName} but got ${id}`) | ||
} | ||
return 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() | ||
}) | ||
}) |