aws / aws/jsii

jsii doesn't work with pnpm workspace

Open
#4,016 3 comments 0 reactions 0 assignees View on GitHub
feature-request p2
Dominant language
TypeScript
Stars
2.9k
Forks
267
Avg merge
1d 25m
Merged PRs (30d)
14

Description

### Describe the feature

At present, jsii supports 2 kinds of dependency version resolving:
1. General semver version like `^1.1.0`
2. File dependency like `file:../../some-local-package`

Propose jsii to support Pnpm workspace protocol version, like `workspace:*`.

```json5
// packages/pkg-a/package.json
{
"dependencies": {
"some-package": "workspace:*"
}
}
```

```
- root (with Pnpm Workspace enabled)
- packages
- package-a
- some-package
```

### Use Case

I tried to use jsii under a rush x pnpm workspace monorepo. When I ran `jsii` in a sub-package that has dependencies like `"some-package": "workspace:*"`.

Then `jsii` will throw the error `Invalid semver expression for some-package: workspace:*`. The relevant codes are located in https://github.com/aws/jsii/blob/ae16abc57bdd7fd439c4183cfcb015acadaaa3ae/packages/jsii/lib/project-info.ts#L355

The current behavior on version resolving doesn't work with pnpm workspace. This stops me from using jsii under pnpm workspace.

* https://pnpm.io/workspaces

### Proposed Solution

I tried tampering with some codes in `project-info.ts`, then jsii works for me.

1. add the workspace protocol check in `_resolveVersion`
```js
const isWorkspace = /^workspace:/.test(dep);
if (isWorkspace) {
const dependencyDir = utils_1.findDependencyDirectory(mod, searchPath);
console.log('found dependencyDir', dependencyDir);
const version = fs.readJsonSync(path.join(dependencyDir, 'package.json')).version;
return {
version: version,
}
}
```

2. ignore semver check in `resolveDependency` for `workspace:*` version

3. ignore the comparison between the actual version and declaration in `discoverDependencyTree`

After making the above changes, `jsii` will not throw errors related to dependency resolving again.

### Other Information

_No response_

### Acknowledgements

- [x] I may be able to implement this feature request
- [ ] This feature might incur a breaking change

### CDK version used

2.69.0

### Environment details (OS name and version, etc.)

os: MacOS jsii: 1.78.1

Contributor guide

Open the contributing guide

Research direction

Read packages/jsii/lib/project-info.ts, especially _resolveVersion, resolveDependency, and discoverDependencyTree. Trace how dependencies using the pnpm workspace protocol are located and validated, then verify that a workspace:* dependency resolves its local package version without invalid semver or comparison errors.

Written by the indexing model from the issue text.

Assessment

Tech stack
typescript
Domain
tooling
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.