Skip to content

Commit

Permalink
✨ Autoload CLI plugin from the CWD if it has a package.json file (#878)
Browse files Browse the repository at this point in the history
  • Loading branch information
wwilsman committed Apr 11, 2022
1 parent 2893ac3 commit b29d5f1
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
1 change: 1 addition & 0 deletions packages/cli/src/commands.js
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ export async function importCommands() {
// find any current project dependencies
process.cwd()
]), async (roots, dir) => {
if (fs.existsSync(path.join(dir, 'package.json'))) roots.push(dir);
roots.push(...await findModulePackages(dir));
roots.push(...await findPnpPackages(dir));
return roots;
Expand Down
14 changes: 14 additions & 0 deletions packages/cli/test/commands.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,20 @@ describe('CLI commands', () => {
await mockfs({ $modules: true });
});

describe('from a project', () => {
it('imports the project command', async () => {
fs.writeFileSync('command.js', 'module.exports.name = "foobar"');
fs.writeFileSync('package.json', '{ "@percy/cli": { "commands": ["./command.js"] } }');

await expectAsync(importCommands()).toBeResolvedTo([
jasmine.objectContaining({ name: 'foobar' })
]);

expect(logger.stdout).toEqual([]);
expect(logger.stderr).toEqual([]);
});
});

describe('from node_modules', () => {
const mockCmds = {
'@percy/cli-exec': { name: 'exec' },
Expand Down

0 comments on commit b29d5f1

Please sign in to comment.