Skip to content
This repository has been archived by the owner on Nov 19, 2021. It is now read-only.

Commit

Permalink
fix(browserslist): uses postinstall voodoo
Browse files Browse the repository at this point in the history
  • Loading branch information
edm00se committed Jan 9, 2020
1 parent 5ef4e6b commit 8900370
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 2 deletions.
8 changes: 6 additions & 2 deletions package.json
Expand Up @@ -8,7 +8,8 @@
"build": "parcel build src/index.html",
"build:ci": "parcel build src/index.html --public-url . --log-level 2",
"test": "jest",
"test:coverage": "npm run test -- --coverage"
"test:coverage": "npm run test -- --coverage",
"postinstall": "rm -rf ./.cache && node ./postinstall.js"
},
"dependencies": {},
"devDependencies": {
Expand All @@ -31,7 +32,10 @@
],
"licence": "MIT",
"browserslist": [
"last 1 chrome versions"
"> 1%",
"last 2 versions",
"ie 11",
"not ie <= 10"
],
"jest": {
"transform": {
Expand Down
33 changes: 33 additions & 0 deletions postinstall.js
@@ -0,0 +1,33 @@
// postinstall.js
const fs = require('fs');
const nodeVersion = 'node 10.11';

// Patch to node_modules/*
const patch = staticPath => {
let folderNames = fs.readdirSync(staticPath);
for (let folderName of folderNames) {
let stats = fs.statSync(staticPath + '/' + folderName);
if (!stats.isDirectory()) continue;

try {
let packageFilePath = `${staticPath}/${folderName}/package.json`;
let browserListFilePath = `${staticPath}/${folderName}/.browserslistrc`;
let packageFileData = JSON.parse(fs.readFileSync(packageFilePath));

delete packageFileData['browserslist'];
fs.writeFileSync(browserListFilePath, nodeVersion);
fs.writeFileSync(
packageFilePath,
JSON.stringify(packageFileData, null, 2)
);
// console.log(`Fixed browserlist in ${packageFilePath}`)

// Patch to node_modules/*/node_modules/*
let nestedModulePath = `${staticPath}/${folderName}/node_modules`;
if (fs.existsSync(nestedModulePath)) patch(nestedModulePath);
} catch (e) {}
}
};

patch('./node_modules');
console.log(`All browserlist has been updated.`);

0 comments on commit 8900370

Please sign in to comment.