-
-
Notifications
You must be signed in to change notification settings - Fork 932
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: recursive update with workspace alias (#7999)
close #7975
- Loading branch information
Showing
18 changed files
with
224 additions
and
13 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
"@pnpm/workspace.spec-parser": major | ||
--- | ||
|
||
Initial release. |
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,7 @@ | ||
--- | ||
"@pnpm/resolve-dependencies": patch | ||
"@pnpm/npm-resolver": patch | ||
"pnpm": patch | ||
--- | ||
|
||
`pnpm update` should not fail when there's an aliased local workspace dependency [#7975](https://github.com/pnpm/pnpm/issues/7975). |
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,14 @@ | ||
export function workspacePrefToNpm (workspacePref: string): string { | ||
const prefParts = /^workspace:([^._/][^@]*@)?(.*)$/.exec(workspacePref) | ||
import { WorkspaceSpec } from '@pnpm/workspace.spec-parser' | ||
|
||
if (prefParts == null) { | ||
export function workspacePrefToNpm (workspacePref: string): string { | ||
const parseResult = WorkspaceSpec.parse(workspacePref) | ||
if (parseResult == null) { | ||
throw new Error(`Invalid workspace spec: ${workspacePref}`) | ||
} | ||
const [workspacePkgAlias, workspaceVersion] = prefParts.slice(1) | ||
|
||
const pkgAliasPart = workspacePkgAlias != null && workspacePkgAlias | ||
? `npm:${workspacePkgAlias}` | ||
: '' | ||
const versionPart = workspaceVersion === '^' || workspaceVersion === '~' | ||
? '*' | ||
: workspaceVersion | ||
|
||
return `${pkgAliasPart}${versionPart}` | ||
const { alias, version } = parseResult | ||
const versionPart = version === '^' || version === '~' ? '*' : version | ||
return alias | ||
? `npm:${alias}@${versionPart}` | ||
: versionPart | ||
} |
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,15 @@ | ||
# @pnpm/workspace.spec-parser | ||
|
||
> Parse and stringify workspace specs | ||
[![npm version](https://img.shields.io/npm/v/@pnpm/workspace.spec-parser.svg)](https://www.npmjs.com/package/@pnpm/workspace.spec-parser) | ||
|
||
## Installation | ||
|
||
```sh | ||
pnpm add @pnpm/workspace.spec-parser | ||
``` | ||
|
||
## License | ||
|
||
MIT |
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,3 @@ | ||
const config = require('../../jest.config.js'); | ||
|
||
module.exports = 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
{ | ||
"name": "@pnpm/workspace.spec-parser", | ||
"version": "0.0.0", | ||
"description": "Parse and stringify workspace pref", | ||
"main": "lib/index.js", | ||
"types": "lib/index.d.ts", | ||
"files": [ | ||
"lib", | ||
"!*.map" | ||
], | ||
"engines": { | ||
"node": ">=18.12" | ||
}, | ||
"scripts": { | ||
"lint": "eslint \"src/**/*.ts\" \"test/**/*.ts\"", | ||
"_test": "jest", | ||
"test": "pnpm run compile && pnpm run _test", | ||
"prepublishOnly": "pnpm run compile", | ||
"compile": "tsc --build && pnpm run lint --fix" | ||
}, | ||
"repository": "https://github.com/pnpm/pnpm/blob/main/workspace/spec-parser", | ||
"keywords": [ | ||
"pnpm9", | ||
"pnpm" | ||
], | ||
"license": "MIT", | ||
"bugs": { | ||
"url": "https://github.com/pnpm/pnpm/issues" | ||
}, | ||
"homepage": "https://github.com/pnpm/pnpm/blob/main/workspace/spec-parser#readme", | ||
"funding": "https://opencollective.com/pnpm", | ||
"devDependencies": { | ||
"@pnpm/workspace.spec-parser": "workspace:*" | ||
}, | ||
"exports": { | ||
".": "./lib/index.js" | ||
} | ||
} |
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,22 @@ | ||
const WORKSPACE_PREF_REGEX = /^workspace:((?<alias>[^._/][^@]*)@)?(?<version>.*)$/ | ||
|
||
export class WorkspaceSpec { | ||
alias?: string | ||
version: string | ||
|
||
constructor (version: string, alias?: string) { | ||
this.version = version | ||
this.alias = alias | ||
} | ||
|
||
static parse (pref: string): WorkspaceSpec | null { | ||
const parts = WORKSPACE_PREF_REGEX.exec(pref) | ||
if (!parts?.groups) return null | ||
return new WorkspaceSpec(parts.groups.version, parts.groups.alias) | ||
} | ||
|
||
toString (): `workspace:${string}` { | ||
const { alias, version } = this | ||
return alias ? `workspace:${alias}@${version}` : `workspace:${version}` | ||
} | ||
} |
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,47 @@ | ||
import { WorkspaceSpec } from '../src/index' | ||
|
||
test('parse valid workspace spec', () => { | ||
expect(WorkspaceSpec.parse('workspace:*')).toStrictEqual(new WorkspaceSpec('*')) | ||
expect(WorkspaceSpec.parse('workspace:^')).toStrictEqual(new WorkspaceSpec('^')) | ||
expect(WorkspaceSpec.parse('workspace:~')).toStrictEqual(new WorkspaceSpec('~')) | ||
expect(WorkspaceSpec.parse('workspace:0.1.2')).toStrictEqual(new WorkspaceSpec('0.1.2')) | ||
expect(WorkspaceSpec.parse('workspace:foo@*')).toStrictEqual(new WorkspaceSpec('*', 'foo')) | ||
expect(WorkspaceSpec.parse('workspace:foo@^')).toStrictEqual(new WorkspaceSpec('^', 'foo')) | ||
expect(WorkspaceSpec.parse('workspace:foo@~')).toStrictEqual(new WorkspaceSpec('~', 'foo')) | ||
expect(WorkspaceSpec.parse('workspace:[email protected]')).toStrictEqual(new WorkspaceSpec('0.1.2', 'foo')) | ||
expect(WorkspaceSpec.parse('workspace:@foo/bar@*')).toStrictEqual(new WorkspaceSpec('*', '@foo/bar')) | ||
expect(WorkspaceSpec.parse('workspace:@foo/bar@^')).toStrictEqual(new WorkspaceSpec('^', '@foo/bar')) | ||
expect(WorkspaceSpec.parse('workspace:@foo/bar@~')).toStrictEqual(new WorkspaceSpec('~', '@foo/bar')) | ||
expect(WorkspaceSpec.parse('workspace:@foo/[email protected]')).toStrictEqual(new WorkspaceSpec('0.1.2', '@foo/bar')) | ||
}) | ||
|
||
test('parse invalid workspace spec', () => { | ||
expect(WorkspaceSpec.parse('npm:[email protected]')).toBe(null) | ||
expect(WorkspaceSpec.parse('*')).toBe(null) | ||
}) | ||
|
||
test('to string', () => { | ||
expect(new WorkspaceSpec('*').toString()).toBe('workspace:*') | ||
expect(new WorkspaceSpec('^').toString()).toBe('workspace:^') | ||
expect(new WorkspaceSpec('~').toString()).toBe('workspace:~') | ||
expect(new WorkspaceSpec('0.1.2').toString()).toBe('workspace:0.1.2') | ||
expect(new WorkspaceSpec('*', 'foo').toString()).toBe('workspace:foo@*') | ||
expect(new WorkspaceSpec('^', 'foo').toString()).toBe('workspace:foo@^') | ||
expect(new WorkspaceSpec('~', 'foo').toString()).toBe('workspace:foo@~') | ||
expect(new WorkspaceSpec('0.1.2', 'foo').toString()).toBe('workspace:[email protected]') | ||
expect(new WorkspaceSpec('*', '@foo/bar').toString()).toBe('workspace:@foo/bar@*') | ||
expect(new WorkspaceSpec('^', '@foo/bar').toString()).toBe('workspace:@foo/bar@^') | ||
expect(new WorkspaceSpec('~', '@foo/bar').toString()).toBe('workspace:@foo/bar@~') | ||
expect(new WorkspaceSpec('0.1.2', '@foo/bar').toString()).toBe('workspace:@foo/[email protected]') | ||
}) | ||
|
||
test('mutate alias and version', () => { | ||
const spec = WorkspaceSpec.parse('workspace:*')! | ||
expect(spec.toString()).toBe('workspace:*') | ||
spec.version = '^' | ||
expect(spec.toString()).toBe('workspace:^') | ||
spec.alias = 'foo' | ||
expect(spec.toString()).toBe('workspace:foo@^') | ||
delete spec.alias | ||
expect(spec.toString()).toBe('workspace:^') | ||
}) |
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,13 @@ | ||
{ | ||
"extends": "@pnpm/tsconfig", | ||
"compilerOptions": { | ||
"outDir": "lib", | ||
"rootDir": "src" | ||
}, | ||
"include": [ | ||
"src/**/*.ts", | ||
"../../__typings__/**/*.d.ts" | ||
], | ||
"references": [], | ||
"composite": true | ||
} |
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,8 @@ | ||
{ | ||
"extends": "./tsconfig.json", | ||
"include": [ | ||
"src/**/*.ts", | ||
"test/**/*.ts", | ||
"../../__typings__/**/*.d.ts" | ||
] | ||
} |