Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft: feat(yarn-plugin-external-workspaces): Add a yarn plugin for adding external workspace support #3504

Open
wants to merge 11 commits into
base: main
Choose a base branch
from

Conversation

JasonVMo
Copy link
Contributor

@JasonVMo JasonVMo commented Feb 3, 2025

Description

Submitting this early for feedback. This still needs lots of testing before it is ready to be merged but I'm just sharing the files early.

This creates a yarn plugin where it adds a new protocol external: with a similar syntax to workspace: such that when the package is found locally it will treat it like a workspace (by rerouting to the portal: syntax) and when it does not exist it will be treated as npm: and downloaded like a normal package.

It is configurable by a JSON file, with the ability to embed it in a key in the file. The default being package.json/external-workspaces, such that these can be defined below the workspaces key in the package.json. It can also route to a .js or .cjs file such that custom code can be invoked when necessary.

I haven't added the range parsing, as such it treats everything like it is workspace:* syntax at the moment, there are some open questions as well. I also need to check the publishing workflow to ensure it transforms the syntax correctly, one thing at a time though.

Test plan

  • I split this out from the code to add a test-repo as that adds a lot of noise. I should have a PR for that separately soon.

incubator/yarn-plugin-external-workspaces/tsconfig.json Outdated Show resolved Hide resolved
incubator/yarn-plugin-external-workspaces/src/finder.ts Outdated Show resolved Hide resolved
incubator/yarn-plugin-external-workspaces/src/finder.ts Outdated Show resolved Hide resolved
// otherwise see if it is a js file that can be loaded
if (!baseFinder) {
const extension = path.extname(configPath).toLowerCase();
if (extension === ".js" || extension === ".cjs") {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In a later iteration, it would be great if we can also add support for .mjs or ESM in general.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can discuss this more but the issue is that imports for esm are async, which has implications up the chain and the plugin resolver code expects synchronous execution.

incubator/yarn-plugin-external-workspaces/src/resolver.ts Outdated Show resolved Hide resolved
incubator/yarn-plugin-external-workspaces/src/resolver.ts Outdated Show resolved Hide resolved
* @param configPath the path to the config file
* @returns a definition finder function if successful, or null if it is not specified
*/
export function tryJsonLoad(configPath: string): DefinitionFinder | null {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's not obvious to me why this needs to return a lambda. Can't it just return a readonly map?

"directory": "incubator/yarn-plugin-external-workspaces"
},
"engines": {
"node": ">=16.17"
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(nit) NodeJs 16 is no longer supported. NodeJs 18 will go out of support in April 2025. Ideally this should be Node 20 or 22

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Imo, this is fine. This just requires the package to use Node 16 or greater. It only makes sense to put a higher requirement if we actually use features from later versions of Node.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was generated by the rnx-kit package creation code. We have some packages in the repo marked as node 16+ and others as 18+. We should probably be consistent and update the package generation with the new value.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants