-
Notifications
You must be signed in to change notification settings - Fork 99
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
206 additions
and
2 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 @@ | ||
--- | ||
"@rnx-kit/yarn-plugin-align-deps": minor | ||
--- | ||
|
||
Added experimental Yarn plugin to simplify dependency alignment |
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,33 @@ | ||
# @rnx-kit/yarn-plugin-align-deps | ||
|
||
[](https://github.com/microsoft/rnx-kit/actions/workflows/build.yml) | ||
[](https://www.npmjs.com/package/@rnx-kit/yarn-plugin-align-deps) | ||
|
||
🚧🚧🚧🚧🚧🚧🚧🚧🚧🚧🚧 | ||
|
||
### THIS TOOL IS EXPERIMENTAL — USE WITH CAUTION | ||
|
||
🚧🚧🚧🚧🚧🚧🚧🚧🚧🚧🚧 | ||
|
||
This is a sample folder to use as base for generating new packages for | ||
`rnx-kit`. | ||
|
||
## Motivation | ||
|
||
We want new packages to follow an existing set of patterns and guidelines; via | ||
this package, we can enforce easily allow new folders to stick to at least a | ||
common starting point. | ||
|
||
## Installation | ||
|
||
```sh | ||
yarn add @rnx-kit/yarn-plugin-align-deps --dev | ||
``` | ||
|
||
or if you're using npm | ||
|
||
```sh | ||
npm add --save-dev @rnx-kit/yarn-plugin-align-deps | ||
``` | ||
|
||
## Usage |
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,4 @@ | ||
import config from "@rnx-kit/eslint-config"; | ||
|
||
// eslint-disable-next-line no-restricted-exports | ||
export default 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,108 @@ | ||
// @ts-check | ||
|
||
/** | ||
* @import { Hooks, Manifest, PackageExtensionData, Plugin } from "@yarnpkg/core"; | ||
*/ | ||
|
||
const PLUGIN_NAME = "@rnx-kit/yarn-plugin-align-deps"; | ||
|
||
/** | ||
* @param {Record<string, unknown>} config | ||
* @param {string} projectRoot | ||
* @param {NodeJS.Require} require | ||
* @returns {Promise<((manifest: Manifest["raw"]) => PackageExtensionData) | undefined>} | ||
*/ | ||
async function loadUserProfiles( | ||
{ "rnx-kit": rnxconfig }, | ||
projectRoot, | ||
require | ||
) { | ||
if ( | ||
typeof rnxconfig !== "object" || | ||
!rnxconfig || | ||
!("profiles" in rnxconfig) | ||
) { | ||
return; | ||
} | ||
|
||
const { profiles } = rnxconfig; | ||
if (!profiles) { | ||
return; | ||
} | ||
|
||
switch (typeof profiles) { | ||
case "object": | ||
return ({ "rnx-kit": rnxconfig }) => { | ||
if (!rnxconfig || !("profile" in rnxconfig)) { | ||
return; | ||
} | ||
|
||
return profiles[rnxconfig.profile]; | ||
}; | ||
|
||
case "string": { | ||
const path = require("node:path"); | ||
|
||
const profilesPath = path.resolve(projectRoot, profiles); | ||
const external = await import(profilesPath); | ||
return external?.default ?? external; | ||
} | ||
|
||
default: | ||
console.warn( | ||
`${PLUGIN_NAME}: invalid configuration: 'profiles' must be an object or a string` | ||
); | ||
break; | ||
} | ||
} | ||
|
||
// TODO: This module *must* be CommonJS because `actions/setup-node` does not | ||
// support ESM. Yarn itself does. | ||
exports.name = PLUGIN_NAME; | ||
|
||
/** @type {(require: NodeJS.Require) => Plugin<Hooks>} */ | ||
exports.factory = (require) => ({ | ||
hooks: { | ||
registerPackageExtensions: async ( | ||
configuration, | ||
registerPackageExtension | ||
) => { | ||
const { projectCwd } = configuration; | ||
if (!projectCwd) { | ||
return; | ||
} | ||
|
||
const { Project, structUtils } = require("@yarnpkg/core"); | ||
|
||
const { workspace } = await Project.find(configuration, projectCwd); | ||
if (!workspace) { | ||
return; | ||
} | ||
|
||
const { manifest, project } = workspace; | ||
const getUserProfile = await loadUserProfiles( | ||
manifest.raw, | ||
projectCwd, | ||
require | ||
); | ||
if (!getUserProfile) { | ||
return; | ||
} | ||
|
||
project.workspacesByCwd.forEach(({ manifest }) => { | ||
const { name, version, raw } = manifest; | ||
if (!name || !version) { | ||
return; | ||
} | ||
|
||
const profile = getUserProfile(raw); | ||
if (!profile) { | ||
return; | ||
} | ||
|
||
const descriptor = structUtils.makeDescriptor(name, version); | ||
registerPackageExtension(descriptor, profile); | ||
}); | ||
}, | ||
}, | ||
}); |
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,41 @@ | ||
{ | ||
"private": true, | ||
"name": "@rnx-kit/yarn-plugin-align-deps", | ||
"version": "0.0.1", | ||
"description": "EXPERIMENTAL - USE WITH CAUTION - yarn-plugin-align-deps", | ||
"homepage": "https://github.com/microsoft/rnx-kit/tree/main/incubator/yarn-plugin-align-deps#readme", | ||
"license": "MIT", | ||
"author": { | ||
"name": "Microsoft Open Source", | ||
"email": "[email protected]" | ||
}, | ||
"files": [ | ||
"index.js" | ||
], | ||
"main": "index.js", | ||
"exports": { | ||
".": "./index.js" | ||
}, | ||
"repository": { | ||
"type": "git", | ||
"url": "https://github.com/microsoft/rnx-kit", | ||
"directory": "incubator/yarn-plugin-align-deps" | ||
}, | ||
"engines": { | ||
"node": ">=18.12" | ||
}, | ||
"scripts": { | ||
"format": "rnx-kit-scripts format", | ||
"lint": "rnx-kit-scripts lint", | ||
"test": "rnx-kit-scripts test" | ||
}, | ||
"devDependencies": { | ||
"@rnx-kit/eslint-config": "*", | ||
"@rnx-kit/scripts": "*", | ||
"@rnx-kit/tsconfig": "*", | ||
"@yarnpkg/core": "^4.0.0", | ||
"eslint": "^9.0.0", | ||
"prettier": "^3.0.0" | ||
}, | ||
"experimental": 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
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