-
Notifications
You must be signed in to change notification settings - Fork 77
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Improvements for dynamic plugins with commands (#1016)
* chore: move prepare to separate file * fix: split configure and prepare steps * fix: support dynamic local plugin imports * fix: invoke prepare lifecycle for dynamically imported plugins * feat: trace indicate deduped init, config, and prepare lifecycle * test: command plugin changes * test: prepare plugin changes * docs: commands configurations * docs: fixes * chore: npm dedupe * docs: changelogs * fix: types improvements
- Loading branch information
1 parent
d429aec
commit 2749b90
Showing
19 changed files
with
535 additions
and
323 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
Large diffs are not rendered by default.
Oops, something went wrong.
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
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,18 @@ | ||
/* eslint-disable no-sync */ | ||
import { gasketBin } from './cli.js'; | ||
import { processCommand } from './utils/process-command.js'; | ||
|
||
/** @type {import('@gasket/core').HookHandler<'prepare'>} */ | ||
export default function prepare(gasket, config) { | ||
if (!config.command) return config; | ||
|
||
/** @type {import('@gasket/plugin-command').GasketCommandDefinition[]} */ | ||
const cmdDefs = gasket.execSync('commands'); | ||
|
||
cmdDefs.forEach((cmdDef) => { | ||
const { command, hidden, isDefault } = processCommand(cmdDef); | ||
gasketBin.addCommand(command, { hidden, isDefault }); | ||
}); | ||
|
||
return config; | ||
} |
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,62 @@ | ||
/* eslint-disable no-sync */ | ||
import { jest } from '@jest/globals'; | ||
|
||
const mockAddCommand = jest.fn(); | ||
const mockParse = jest.fn(); | ||
const mockProcessCommand = jest.fn(); | ||
|
||
jest.unstable_mockModule('../lib/cli.js', () => { | ||
return { | ||
gasketBin: { | ||
addCommand: mockAddCommand, | ||
parse: mockParse | ||
} | ||
}; | ||
}); | ||
|
||
jest.unstable_mockModule('../lib/utils/process-command.js', () => { | ||
return { | ||
processCommand: mockProcessCommand.mockReturnValue({ command: 'test', hidden: false, isDefault: false }) | ||
}; | ||
}); | ||
|
||
const prepare = ((await import('../lib/prepare.js')).default); | ||
|
||
describe('prepare', () => { | ||
let mockGasket, mockConfig; | ||
|
||
beforeEach(() => { | ||
jest.clearAllMocks(); | ||
mockGasket = { | ||
execSync: jest.fn().mockReturnValue([{ id: 'test', description: 'test', action: jest.fn() }]), | ||
config: { | ||
env: 'development' | ||
} | ||
}; | ||
mockConfig = { | ||
command: 'test' | ||
}; | ||
}); | ||
|
||
it('should be function', () => { | ||
expect(prepare).toEqual(expect.any(Function)); | ||
}); | ||
|
||
it('should not exec commands if no gasket command detected', async () => { | ||
delete mockConfig.command; | ||
await prepare(mockGasket, mockConfig); | ||
expect(mockGasket.execSync).not.toHaveBeenCalled(); | ||
}); | ||
|
||
it('should execute command lifecycle', async () => { | ||
process.argv = ['node', '/path/to/gasket.js']; | ||
await prepare(mockGasket, mockConfig); | ||
expect(mockGasket.execSync).toHaveBeenCalledWith('commands'); | ||
}); | ||
|
||
it('should add commands to gasketBin', async () => { | ||
process.argv = ['node', '/path/to/gasket.js', 'bogus']; | ||
await prepare(mockGasket, mockConfig); | ||
expect(mockAddCommand).toHaveBeenCalledWith('test', expect.any(Object)); | ||
}); | ||
}); |
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
Oops, something went wrong.