-
Notifications
You must be signed in to change notification settings - Fork 0
/
.pnpmfile.cjs
54 lines (48 loc) · 1.89 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
53
54
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-kryptogokit 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 = [
// We're on an older version of eslint due to eslint-config-kryptogo
// so we need to allow multiple versions for now.
'eslint',
];
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-kryptogokit 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;
}