forked from ag-grid/ag-grid
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcustomise.js
More file actions
74 lines (58 loc) · 2.49 KB
/
customise.js
File metadata and controls
74 lines (58 loc) · 2.49 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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
/**
* There are some issues which we have had to resolve by editing plugins as it was the only way to achieve what we
* needed to. This script applies these customisations by replacing content inside the node_modules after they've been
* installed; perhaps we should fork the plugins properly and point to those instead.
*/
const fs = require('fs-extra');
const applyCustomisation = (packageName, expectedVersion, customisation, providedPath = null, optional = false) => {
const packagePath = providedPath ? providedPath : `./node_modules/${packageName}/package.json`;
if (!fs.existsSync(packagePath) && optional) {
console.log(`${packagePath} doesn't exist but is optional - skipping`);
return true;
}
const version = require(packagePath).version;
const versionMatches = version === expectedVersion;
if (versionMatches) {
customisation.apply();
console.log(`✓ ${customisation.name}`);
} else {
console.error(`✗ ${customisation.name}`);
console.error(`Customisation failed: Expected version ${expectedVersion} of ${packageName} but found ${version}. You should test the customisation with the new version and update the expected version number if it works.`);
}
return versionMatches;
};
const updateFileContents = (filename, existingContent, newContent) => {
const contents = fs.readFileSync(filename, 'utf8');
const newContents = contents.replace(existingContent, newContent);
if (newContents !== contents) {
fs.writeFileSync(filename, newContents);
}
};
const forceEs5ForCjsBundles = () => {
return applyCustomisation('@rollup/plugin-node-resolve', '13.3.0', {
name: `Force ES5 for CJS bundles`,
apply: () => updateFileContents(
'./node_modules/@rollup/plugin-node-resolve/dist/cjs/index.js',
` const pkgRoot = path.dirname(pkgPath);
const packageInfo = {`,
` const pkgRoot = path.dirname(pkgPath);
if(pkg.name === 'ag-charts-community') {
pkg['module'] = "./dist/esm/es5/main.js";
}
const packageInfo = {
`
)
});
};
console.log(`--------------------------------------------------------------------------------`);
console.log(`Applying customisations...`);
const success = [
forceEs5ForCjsBundles(),
].every(x => x);
if (success) {
console.log(`Finished!`);
} else {
console.error('Failed.');
process.exitCode = 1;
}
console.log(`--------------------------------------------------------------------------------`);