-
Notifications
You must be signed in to change notification settings - Fork 105
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
Upgrade to Yarn v4 (Berry) #3095
base: livekit
Are you sure you want to change the base?
Changes from all commits
fee9841
95b37ea
31fb916
0b26dc2
d633ec5
cb14b72
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
/* | ||
Copyright 2025 New Vector Ltd. | ||
|
||
SPDX-License-Identifier: AGPL-3.0-only OR LicenseRef-Element-Commercial | ||
Please see LICENSE in the repository root for full details. | ||
*/ | ||
|
||
module.exports = { | ||
name: "linker", | ||
factory: (require) => ({ | ||
hooks: { | ||
registerPackageExtensions: async (config, registerPackageExtension) => { | ||
const { structUtils } = require("@yarnpkg/core"); | ||
const { parseSyml } = require("@yarnpkg/parsers"); | ||
const path = require("path"); | ||
const fs = require("fs"); | ||
const process = require("process"); | ||
|
||
// Create a descriptor that we can use to target our direct dependencies | ||
const projectPath = config.projectCwd | ||
.replace(/\\/g, "/") | ||
.replace("/C:/", "C:/"); | ||
const manifestPath = path.join(projectPath, "package.json"); | ||
const manifest = JSON.parse(fs.readFileSync(manifestPath, "utf8")); | ||
const selfDescriptor = structUtils.parseDescriptor( | ||
`${manifest.name}@*`, | ||
true, | ||
); | ||
|
||
// Load the list of linked packages | ||
const linksPath = path.join(projectPath, ".links.yaml"); | ||
let linksFile; | ||
try { | ||
linksFile = fs.readFileSync(linksPath, "utf8"); | ||
} catch (e) { | ||
return; // File doesn't exist, there's nothing to link | ||
} | ||
let links; | ||
try { | ||
links = parseSyml(linksFile); | ||
} catch (e) { | ||
console.error(".links.yaml has invalid syntax", e); | ||
process.exit(1); | ||
} | ||
|
||
// Resolve paths and turn them into a Yarn package extension | ||
const overrides = Object.fromEntries( | ||
Object.entries(links).map(([name, link]) => [ | ||
name, | ||
`portal:${path.resolve(config.projectCwd, link)}`, | ||
]), | ||
); | ||
const overrideIdentHashes = new Set(); | ||
for (const name of Object.keys(overrides)) | ||
overrideIdentHashes.add( | ||
structUtils.parseDescriptor(`${name}@*`, true).identHash, | ||
); | ||
|
||
registerPackageExtension(selfDescriptor, { dependencies: overrides }); | ||
|
||
// Filter out the original dependencies from the package spec so Yarn | ||
// knows to override them | ||
const filterDependencies = (original) => { | ||
const pkg = structUtils.copyPackage(original); | ||
pkg.dependencies = new Map( | ||
Array.from(pkg.dependencies.entries()).filter( | ||
([, value]) => !overrideIdentHashes.has(value.identHash), | ||
), | ||
); | ||
return pkg; | ||
}; | ||
|
||
// Patch Yarn's own normalizePackage method with the above filter | ||
const originalNormalizePackage = config.normalizePackage; | ||
config.normalizePackage = function (pkg, extensions) { | ||
return originalNormalizePackage.call( | ||
this, | ||
pkg.identHash === selfDescriptor.identHash | ||
? filterDependencies(pkg) | ||
: pkg, | ||
extensions, | ||
); | ||
}; | ||
}, | ||
}, | ||
}), | ||
}; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
nodeLinker: node-modules | ||
plugins: | ||
- .yarn/plugins/linker.cjs |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,9 @@ | ||
## Element Call Docs | ||
|
||
This folder contains documentation for Element Call setup and usage. | ||
This folder contains documentation for setup, usage, and development of Element Call. | ||
|
||
- [Embedded vs standalone mode](./embedded-standalone.md) | ||
- [Url format and parameters](./url-params.md) | ||
- [Global JS controls](./controls.md) | ||
- [Self-Hosting](./self-hosting.md) | ||
- [Developing with linked packages](./linking.md) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
# Developing with linked packages | ||
|
||
If you want to make changes to a package that Element Call depends on and see those changes applied in real time, you can create a link to a local copy of the package. Yarn has a command for this (`yarn link`), but it's not recommended to use it as it ends up modifying package.json with details specific to your development environment. | ||
|
||
Instead, you can use our little 'linker' plugin. Create a file named `.links.yaml` in the Element Call project directory, listing the names and paths of any dependencies you want to link. For example: | ||
|
||
```yaml | ||
matrix-js-sdk: ../path/to/matrix-js-sdk | ||
"@vector-im/compound-web": /home/alice/path/to/compound-web | ||
``` | ||
|
||
Then run `yarn install`. |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -130,5 +130,6 @@ | |
"resolutions": { | ||
"@livekit/components-core/rxjs": "^7.8.1", | ||
"matrix-widget-api": "1.11.0" | ||
} | ||
}, | ||
"packageManager": "[email protected]" | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,5 +4,6 @@ set -ex | |
|
||
export VITE_APP_VERSION=$(git describe --tags --abbrev=0) | ||
|
||
corepack enable | ||
yarn install | ||
yarn run build |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,7 +12,6 @@ import posthog, { | |
} from "posthog-js"; | ||
import { logger } from "matrix-js-sdk/src/logger"; | ||
import { type MatrixClient } from "matrix-js-sdk/src/matrix"; | ||
import { Buffer } from "buffer"; | ||
|
||
import { widget } from "../widget"; | ||
import { | ||
|
@@ -297,7 +296,7 @@ export class PosthogAnalytics { | |
const posthogIdMaterial = "ec" + accountAnalyticsId + client.getUserId(); | ||
const bufferForPosthogId = await crypto.subtle.digest( | ||
"sha-256", | ||
Buffer.from(posthogIdMaterial, "utf-8"), | ||
new TextEncoder().encode(posthogIdMaterial), | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. is this needed for the yarn berry switch or just randomly here? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I was trying out Yarn's plug-n-play mode, and it needed this change. I reverted to the normal node_modules linker so I don't think it's strictly necessary. Would you prefer I exclude it? |
||
); | ||
const view = new Int32Array(bufferForPosthogId); | ||
return Array.from(view) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am loving this.
Do I understand it correctly, that it just allows us to put this part of the package.json into its own file, so that we can git-ignore it?
pnpm has the same behaviour and I was wondering how this could be elegantly solved.
This is great!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, though I just realized that this method will still modify yarn.lock, sigh. I don't know of a better solution right now.