-
Notifications
You must be signed in to change notification settings - Fork 187
/
prepare-built-package.js
77 lines (64 loc) · 2.14 KB
/
prepare-built-package.js
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
74
75
76
77
/*
* https://youtrack.jetbrains.com/issue/RG-2304/Publish-built-version-as-a-separate-package-jetbrains-ring-ui-built
* Removes "devDependencies" from package.json file, and keeps only whitelisted "dependencies"
*/
/* eslint-disable no-console */
const fs = require('fs');
const sourcePackageJSON = require('./package.json');
const BUILT_PACKAGE_NAME = '@jetbrains/ring-ui-built';
// There should be all dependencies, that are actually used in runtime. All build-time dependencies should be removed
const WHITE_LIST = [
'@jetbrains/icons',
'@jetbrains/logos',
'change-case',
'classnames',
'combokeys',
'date-fns',
'dequal',
'element-resize-detector',
'es6-error',
'fastdom',
'focus-trap',
'highlight.js',
'just-debounce-it',
'memoize-one',
'react-movable',
'react-virtualized',
'react-waypoint',
'scrollbar-width',
'simply-uuid',
'sniffr',
'util-deprecate',
];
function clearAndRenamePackage() {
const filterDependencies = (packageData, whitelist) => {
const dependencies = packageData.dependencies;
const filteredDependencies = {};
// Only keep runtime dependencies and the ones in the whitelist
for (const depName in dependencies) {
if (whitelist.includes(depName)) {
filteredDependencies[depName] = dependencies[depName];
}
}
return {
...packageData,
dependencies: filteredDependencies,
devDependencies: {},
};
};
const updatePackageJSON = (filename, packageData) => {
// eslint-disable-next-line no-magic-numbers
fs.writeFileSync(filename, JSON.stringify(packageData, null, 2));
};
// Rename package.name
sourcePackageJSON.name = BUILT_PACKAGE_NAME;
// Remove "webpack" from peer dependencies
delete sourcePackageJSON.peerDependencies.webpack;
delete sourcePackageJSON.peerDependenciesMeta.webpack;
// Remove build-time files from files to be published
sourcePackageJSON.files = ['components', 'typings.d.ts'];
const filteredData = filterDependencies(sourcePackageJSON, WHITE_LIST);
updatePackageJSON('./package.json', filteredData);
console.log('package.json updated. DevDependencies removed.');
}
clearAndRenamePackage();