-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathyarn.config.cjs
73 lines (70 loc) · 2.83 KB
/
yarn.config.cjs
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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
// /** @type {import('@yarnpkg/types')} */
// const { defineConfig } = require('@yarnpkg/types');
const defineConfig = config => config;
module.exports = defineConfig({
async constraints({ Yarn }) {
const root = Yarn.workspace({ cwd: '.' });
for (const workspace of Yarn.workspaces()) {
const depsToWorkspace = Yarn.dependencies({ ident: workspace.ident });
if (!workspace.cwd.startsWith('packages/')) {
// workspace is not a published package (example or root)
// ...it should be private
workspace.set('private', true);
// ...there should be no dependencies to it
for (const dep of depsToWorkspace) {
dep.delete();
}
// done with this workspace
continue;
}
// workspace is a published package
// make sure all deps to this workspace use the correct version
for (const dep of depsToWorkspace) {
if (dep.workspace.cwd.startsWith('examples/')) {
// example apps should always use the workspace version
dep.update('workspace:*');
} else if (dep.type === 'peerDependencies') {
// peer dependencies should use a caret range
if (!dep.range.startsWith('^')) {
dep.error(`Expected peer dependency to use a caret (^) range.`);
}
// peer dependencies should also have a dev dependency to the workspace
dep.workspace.set(['devDependencies', dep.ident], 'workspace:*');
} else if (dep.type === 'devDependencies') {
dep.update('workspace:*');
} else if (dep.type === 'dependencies') {
// there should be no regular deps between packages.
dep.delete();
}
}
// package.json invariants
workspace.set('main', 'dist/index.cjs.js');
workspace.set('module', 'dist/index.esm.js');
workspace.unset('type');
workspace.set('types', 'build/types/index.d.ts');
workspace.set('files', ['dist/index.*']);
workspace.set('scripts.build', 'tsc -b');
workspace.set('scripts.bundle', 'rollup -c && api-extractor run');
workspace.set('scripts.prepack', 'yarn build && yarn bundle');
workspace.unset('exports');
workspace.set('publishConfig', {
registry: 'https://registry.npmjs.org/',
access: 'public',
types: 'dist/index.d.ts',
main: 'dist/index.cjs.js',
module: 'dist/index.esm.js',
});
// dev deps that should all share the same version (from root package.json)
for (const id of ['@microsoft/api-extractor', 'rollup']) {
workspace.set(['devDependencies', id], getRootVersion(id));
}
}
function getRootVersion(id) {
const version = root.pkg.dependencies.get(id)?.version;
if (!version) {
root.error(`Expected dependency on ${id}.`);
}
return version;
}
},
});