forked from rainbow-me/rainbowkit
-
Notifications
You must be signed in to change notification settings - Fork 0
/
.pnpmfile.cjs
52 lines (46 loc) · 1.77 KB
/
.pnpmfile.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
function readPackage(pkg) {
// Filter dependencies in app templates that are present in the root package.json.
// This allows us to provide complete package.json files for all app templates.
if (
/-app$/.test(pkg.name) || // create-rainbowkit templates (e.g. next-app)
/^with-/.test(pkg.name) // example apps (e.g. with-next)
) {
pkg.dependencies = omitRootDependencies(pkg.name, pkg.dependencies);
pkg.devDependencies = omitRootDependencies(pkg.name, pkg.devDependencies);
}
return pkg;
}
module.exports = {
hooks: {
readPackage,
},
};
function omitRootDependencies(packageName, dependencies) {
const packageJson = require('./package.json');
const rootDependencies = {
...packageJson.dependencies,
...packageJson.devDependencies,
};
const filteredDependencies = {};
const allowedDuplicatePackages = [
// None for now
];
Object.keys(dependencies).forEach((dep) => {
if (!rootDependencies[dep] || allowedDuplicatePackages.includes(dep)) {
// Keep the dependency in the app template's package.json since it's not in the
// root package.json (or in the list of allowed duplicate packages).
filteredDependencies[dep] = dependencies[dep];
} else if (rootDependencies[dep] !== dependencies[dep]) {
throw new Error(
[
`Dependency ${dep} has different version in root package.json. Root: ${rootDependencies[dep]}, ${packageName}: ${dependencies[dep]}`,
packageName === 'generated-test-app' &&
'You might have stale files left over from a past create-rainbowkit run. Try running "pnpm test:cli:clean" and then "pnpm test:cli:dev" after install to regenerate test app.',
]
.filter(Boolean)
.join('\n'),
);
}
});
return filteredDependencies;
}