-
Notifications
You must be signed in to change notification settings - Fork 170
Update yarn to the latest stable version and add dynamic-extensions plugin #3924
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
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
6240747
update yarn to 4.9.2
JasonVMo 7f90c0d
Merge remote-tracking branch 'origin/main' into user/jasonvmo/bump-yarn
JasonVMo b3adac5
add dynamic-extensions plugin
JasonVMo 13bd2e0
add some basic dynamic extension configuration
JasonVMo 96563b7
update tester deps to match current yarn version
JasonVMo File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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,96 @@ | ||
| // @ts-check | ||
|
|
||
| /** | ||
| * @import { Configuration, Hooks, Manifest, PackageExtensionData, Plugin } from "@yarnpkg/core"; | ||
| * @import { PortablePath } from "@yarnpkg/fslib"; | ||
| * @typedef {{ cwd: string; manifest: Manifest["raw"]; }} Workspace; | ||
| */ | ||
|
|
||
| const DYNAMIC_PACKAGE_EXTENSIONS_KEY = "dynamicPackageExtensions"; | ||
|
|
||
| // This module *must* be CommonJS because `actions/setup-node` (and probably | ||
| // other GitHub actions) does not support ESM. Yarn itself does. | ||
| exports.name = "@rnx-kit/yarn-plugin-dynamic-extensions"; | ||
|
|
||
| /** @type {(require: NodeJS.Require) => Plugin<Hooks>} */ | ||
| exports.factory = (require) => { | ||
| const { Project, SettingsType, structUtils } = require("@yarnpkg/core"); | ||
| const { npath } = require("@yarnpkg/fslib"); | ||
|
|
||
| /** | ||
| * @param {Configuration} configuration | ||
| * @param {PortablePath} projectRoot | ||
| * @returns {Promise<((ws: Workspace) => PackageExtensionData | undefined) | void>} | ||
| */ | ||
| async function loadUserExtensions(configuration, projectRoot) { | ||
| const packageExtensions = configuration.get(DYNAMIC_PACKAGE_EXTENSIONS_KEY); | ||
| if (typeof packageExtensions !== "string") { | ||
| return; | ||
| } | ||
|
|
||
| const path = require("node:path"); | ||
| const { pathToFileURL } = require("node:url"); | ||
|
|
||
| // Make sure we resolve user extensions relative to the source config | ||
| const source = configuration.sources.get(DYNAMIC_PACKAGE_EXTENSIONS_KEY); | ||
| const sourceDir = source ? npath.dirname(source) : projectRoot; | ||
|
|
||
| // On Windows, import paths must include the `file:` protocol. | ||
| const root = npath.fromPortablePath(sourceDir); | ||
| const url = pathToFileURL(path.resolve(root, packageExtensions)); | ||
| const external = await import(url.toString()); | ||
| return external?.default ?? external; | ||
| } | ||
|
|
||
| /** @type {Plugin<Hooks>["configuration"] & Record<string, unknown>} */ | ||
| const configuration = {}; | ||
| configuration[DYNAMIC_PACKAGE_EXTENSIONS_KEY] = { | ||
| description: "Path to module providing package extensions", | ||
| type: SettingsType.STRING, | ||
| }; | ||
|
|
||
| return { | ||
| configuration, | ||
| hooks: { | ||
| registerPackageExtensions: async ( | ||
| configuration, | ||
| registerPackageExtension | ||
| ) => { | ||
| const { projectCwd } = configuration; | ||
| if (!projectCwd) { | ||
| return; | ||
| } | ||
|
|
||
| const getUserExtensions = await loadUserExtensions( | ||
| configuration, | ||
| projectCwd | ||
| ); | ||
| if (!getUserExtensions) { | ||
| return; | ||
| } | ||
|
|
||
| const { workspace } = await Project.find(configuration, projectCwd); | ||
| if (!workspace) { | ||
| return; | ||
| } | ||
|
|
||
| workspace.project.workspacesByCwd.forEach(({ cwd, manifest }) => { | ||
| const { name, version, raw } = manifest; | ||
| if (!name || !version) { | ||
| return; | ||
| } | ||
|
|
||
| /** @type {Workspace} */ | ||
| const workspace = { cwd: npath.fromPortablePath(cwd), manifest: raw }; | ||
| const data = getUserExtensions(workspace); | ||
| if (!data) { | ||
| return; | ||
| } | ||
|
|
||
| const descriptor = structUtils.makeDescriptor(name, version); | ||
| registerPackageExtension(descriptor, data); | ||
| }); | ||
| }, | ||
| }, | ||
| }; | ||
| }; | ||
This file was deleted.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains hidden or 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,5 +1,12 @@ | ||
| dynamicPackageExtensions: ./scripts/dynamic.extensions.mjs | ||
|
|
||
| enableGlobalCache: false | ||
|
|
||
| nodeLinker: node-modules | ||
|
|
||
| yarnPath: .yarn/releases/yarn-4.6.0.cjs | ||
| plugins: | ||
| - checksum: 672e525b81762c6162366bd3ffec5e86ab8fac2655ef0267047e86a0f32e79a4bde0f170bc30479663f40aa3f006d91f8dc3289f679dd4dc5ae5a5d12ba3ad0b | ||
| path: .yarn/plugins/@rnx-kit/yarn-plugin-dynamic-extensions.cjs | ||
| spec: "https://raw.githubusercontent.com/microsoft/rnx-kit/main/incubator/yarn-plugin-dynamic-extensions/index.js" | ||
|
|
||
| yarnPath: .yarn/releases/yarn-4.9.2.cjs |
This file contains hidden or 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 |
|---|---|---|
|
|
@@ -100,5 +100,5 @@ | |
| ] | ||
| } | ||
| }, | ||
| "packageManager": "yarn@4.6.0" | ||
| "packageManager": "yarn@4.9.2" | ||
| } | ||
This file contains hidden or 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,46 @@ | ||
| import fs from 'fs'; | ||
| import path from 'path'; | ||
| import { fileURLToPath } from 'url'; | ||
|
|
||
| /** | ||
| * @param {Object} workspace The package currently being processed | ||
| * @param {string} workspace.cwd Path of the current package | ||
| * @param {Object} workspace.manifest The content of `package.json` | ||
| * @returns {{ | ||
| * dependencies?: Record<string, string>; | ||
| * peerDependencies?: Record<string, string>; | ||
| * peerDependenciesMeta?: Record<string, { optional?: boolean }>; | ||
| * }} | ||
| */ | ||
|
|
||
| /** | ||
| * These are the dependencies we want to ensure exist in each folder. They will not override | ||
| * the dependencies in the package.json if already present. | ||
| */ | ||
| const scriptDependencies = getScriptFolderDependencies(['typescript', 'eslint', 'just-scripts']); | ||
|
|
||
| /** | ||
| * Get the dependencies for the script folder, both `devDependencies` and `dependencies` | ||
| * @param {string[]} keys - The keys of the dependencies to include | ||
| * @returns {Record<string, string>} A map of dependencies for the script folder | ||
| */ | ||
| function getScriptFolderDependencies(keys) { | ||
| const pkgJsonName = path.join(path.dirname(fileURLToPath(import.meta.url)), './package.json'); | ||
| const pkgJson = JSON.parse(fs.readFileSync(pkgJsonName, 'utf-8')); | ||
| const mergedDeps = { ...pkgJson.devDependencies, ...pkgJson.dependencies }; | ||
| return Object.fromEntries(Object.entries(mergedDeps).filter(([key]) => keys.includes(key))); | ||
| } | ||
|
|
||
| export default function ({ cwd, manifest }) { | ||
| const dependenciesToAdd = {}; | ||
| Object.keys(scriptDependencies).forEach((key) => { | ||
| if ((manifest?.dependencies && manifest.dependencies[key]) || (manifest?.devDependencies && manifest.devDependencies[key])) { | ||
| // If the dependency already exists in the package.json, skip it | ||
| return; | ||
| } | ||
| dependenciesToAdd[key] = scriptDependencies[key]; | ||
| }); | ||
| return { | ||
| dependencies: dependenciesToAdd, | ||
| }; | ||
| } |
This file contains hidden or 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 +1 @@ | ||
| yarnPath: ../.yarn/releases/yarn-4.6.0.cjs | ||
| yarnPath: ../.yarn/releases/yarn-4.9.2.cjs |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.