forked from tldraw/tldraw
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathyarn.config.cjs
More file actions
59 lines (49 loc) · 1.72 KB
/
Copy pathyarn.config.cjs
File metadata and controls
59 lines (49 loc) · 1.72 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
/** @type {import('@yarnpkg/types')} */
const { defineConfig } = require(`@yarnpkg/types`)
/**
* @param {Context} context
*/
function enforceConsistentDependenciesAcrossTheProject({ Yarn }) {
// check non-peer deps:
for (const dependency of Yarn.dependencies()) {
if (dependency.type === 'peerDependencies') continue
for (const otherDependency of Yarn.dependencies({ ident: dependency.ident })) {
if (otherDependency.type === 'peerDependencies') continue
dependency.update(otherDependency.range)
}
}
// check peer deps:
for (const dependency of Yarn.dependencies()) {
if (dependency.type !== 'peerDependencies') continue
for (const otherDependency of Yarn.dependencies({ ident: dependency.ident })) {
if (otherDependency.type !== 'peerDependencies') continue
dependency.update(otherDependency.range)
}
}
for (const workspace of Yarn.workspaces()) {
if (workspace.cwd === '.') continue
workspace.set('packageManager', undefined)
}
}
/**
* Require a Node version where `require()` of an ES module works natively, so
* published packages can depend on ESM-only modules without breaking CommonJS
* consumers. Node 20 is EOL, so we require Node 22.12+, where `require(esm)` is
* unflagged; earlier versions throw `ERR_REQUIRE_ESM`.
*
* @param {Context} context
*/
function enforceNodeEngineOnPackages({ Yarn }) {
const nodeEngine = '>=22.12.0'
for (const workspace of Yarn.workspaces()) {
// only the published library packages under packages/*
if (!workspace.cwd.startsWith('packages/')) continue
workspace.set(['engines', 'node'], nodeEngine)
}
}
module.exports = defineConfig({
constraints: async (ctx) => {
enforceConsistentDependenciesAcrossTheProject(ctx)
enforceNodeEngineOnPackages(ctx)
},
})