Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ export default defineNginxUiPluginConfig({ id: 'io.github.example.myplugin' })
"vue": ">=3.5.42 <4",
"vue-router": ">=5.3.1 <6",
"pinia": ">=4.0.3 <5",
"antdv-next": "~1.5",
"antdv-next": ">=1.5.4 <2",
"@vueuse/core": ">=15.0.0"
}
}
Expand Down
25 changes: 17 additions & 8 deletions src/shared-range.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,13 @@ export function parseSemver(version: string): SemverTriple | null {
}

/**
* Range strategy per shared library, matching the ranges nginx-ui's own
* webapp/vite.config.ts declares for its dependencies (see app/package.json):
* vue, vue-router and pinia allow every minor/patch up to (not including) the
* next major; antdv-next is pinned to major.minor; @vueuse/core has no
* upper bound.
* Range strategy per shared library: vue, vue-router, pinia and antdv-next
* allow every minor/patch up to (not including) the next major; @vueuse/core
* has no upper bound.
*
* antdv-next used to be pinned to major.minor. The host upgrades its minor
* regularly, and every upgrade then refused every plugin bundle built against
* the previous one, so a bundle stopped loading until its plugin was rebuilt.
*/
export function rangeForLibrary(pkg: string, version: string): string {
const parsed = parseSemver(version)
Expand All @@ -41,15 +43,22 @@ export function rangeForLibrary(pkg: string, version: string): string {
case 'vue':
case 'vue-router':
case 'pinia':
return `>=${version} <${parsed.major + 1}`
case 'antdv-next':
return `~${parsed.major}.${parsed.minor}`
return `>=${floor(parsed)} <${parsed.major + 1}`
case '@vueuse/core':
default:
return `>=${version}`
return `>=${floor(parsed)}`
}
}

/**
* The lower bound of a range: major.minor.patch without prerelease or build
* metadata, which the host's range matcher does not accept.
*/
function floor({ major, minor, patch }: SemverTriple): string {
return `${major}.${minor}.${patch}`
}

/** Builds the webapp.shared map for every library that resolved to a version. */
export function buildSharedManifest(versions: Record<string, string | null | undefined>): Record<string, string> {
const shared: Record<string, string> = {}
Expand Down
15 changes: 12 additions & 3 deletions test/shared-range.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,23 @@ describe('rangeForLibrary', () => {
expect(rangeForLibrary('pinia', '4.0.3')).toBe('>=4.0.3 <5')
})

it('pins antdv-next to major.minor', () => {
expect(rangeForLibrary('antdv-next', '1.5.4')).toBe('~1.5')
it('caps antdv-next below the next major', () => {
expect(rangeForLibrary('antdv-next', '1.5.4')).toBe('>=1.5.4 <2')
})

it('leaves @vueuse/core without an upper bound', () => {
expect(rangeForLibrary('@vueuse/core', '15.0.0')).toBe('>=15.0.0')
})

it('drops prerelease and build metadata from the lower bound', () => {
expect(rangeForLibrary('antdv-next', '1.9.0-beta.1')).toBe('>=1.9.0 <2')
expect(rangeForLibrary('@vueuse/core', '15.1.0+build.2')).toBe('>=15.1.0')
})

it('fills in a missing minor and patch', () => {
expect(rangeForLibrary('vue', '3')).toBe('>=3.0.0 <4')
})

it('passes an unparseable version through unchanged', () => {
expect(rangeForLibrary('vue', 'workspace:*')).toBe('workspace:*')
})
Expand All @@ -52,7 +61,7 @@ describe('buildSharedManifest', () => {

expect(shared).toEqual({
'vue': '>=3.5.42 <4',
'antdv-next': '~1.5',
'antdv-next': '>=1.5.4 <2',
})
})
})
Loading