Skip to content

Commit

Permalink
fix(cli): Fix plugin loading with rewrite of loading logic (#9171)
Browse files Browse the repository at this point in the history
**Problem**
Although the cli plugin loading behaviour was functional for our
storybook and data-migrate needs, some flaws where highlighted when it
came to integrate third party packages. The loading logic was somewhat
scatterbrained and had no tests.

**Changes**
1. Reworks the plugin loading logic and, hopefully, makes the logic
easier to follow.
2. Adds tests for the loading logic. This will help catch unintentional
changes in behaviour in future updates.
3. I removed the `version` option from the toml config for experimental
cli plugins. If users wish to enforce a specific version they should
install such a version in the standard way they would for any third
party package - using the package.json and yarn.

**Notes**
1. This is still considered an "experimental" feature so we can
potentially be more loose - which is why I felt a larger rewrite was
advantageous in this case.
  • Loading branch information
Josh-Walker-GM authored Sep 15, 2023
1 parent dc86db5 commit d8dc89a
Show file tree
Hide file tree
Showing 7 changed files with 2,429 additions and 309 deletions.
8 changes: 0 additions & 8 deletions packages/cli-helpers/src/lib/__tests__/version.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -261,14 +261,6 @@ describe('version compatibility detection', () => {
)
})

test('throws if no redwoodjs engine is found', async () => {
await expect(
getCompatibilityData('@scope/package-name', '0.0.1')
).rejects.toThrowErrorMatchingInlineSnapshot(
`"The package '@scope/package-name' does not specify a RedwoodJS compatibility version/range"`
)
})

test('throws if no latest version could be found', async () => {
jest.spyOn(global, 'fetch').mockImplementation(() => {
return {
Expand Down
13 changes: 5 additions & 8 deletions packages/cli-helpers/src/lib/version.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,18 +67,15 @@ export async function getCompatibilityData(
? packument['dist-tags'][preferredVersionOrTag]
: preferredVersionOrTag

// Does that version of the package support the current version of RedwoodJS?
// Extract the package's redwoodjs engine specification for the preferred version
const packageRedwoodSpecification =
packument.versions[preferredVersion].engines?.redwoodjs

if (packageRedwoodSpecification === undefined) {
throw new Error(
`The package '${packageName}' does not specify a RedwoodJS compatibility version/range`
)
}

// We have to use the semver.intersects function because the package's redwoodjs engine could be a range
if (semver.intersects(projectRedwoodVersion, packageRedwoodSpecification)) {
if (
packageRedwoodSpecification !== undefined &&
semver.intersects(projectRedwoodVersion, packageRedwoodSpecification)
) {
const tag = getCorrespondingTag(preferredVersion, packument['dist-tags'])
return {
preferred: {
Expand Down
Loading

0 comments on commit d8dc89a

Please sign in to comment.