Skip to content
This repository has been archived by the owner on Apr 18, 2023. It is now read-only.

Commit

Permalink
Remove workspaces key from package.json for publishing
Browse files Browse the repository at this point in the history
Closes #26
  • Loading branch information
wojtekmaj committed Oct 21, 2021
1 parent 851a5f4 commit e3cadb1
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 1 deletion.
5 changes: 4 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,10 @@
"build": "babel --source-maps=both src -d build",
"clean": "rimraf build",
"lint": "eslint src/ --ext .jsx,.js",
"prepack": "yarn clean && yarn build",
"postpack": "yarn restore-workspaces",
"prepack": "yarn clean && yarn build && yarn remove-workspaces",
"remove-workspaces": "node remove_workspaces.js",
"restore-workspaces": "node restore_workspaces.js",
"test": "yarn lint"
},
"keywords": [
Expand Down
16 changes: 16 additions & 0 deletions remove_workspaces.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
/**
* Removes workspaces key from package.json to avoid issue with Yarn v1
* See: https://github.com/wojtekmaj/enzyme-adapter-react-17/issues/26
*/
const fs = require('fs');

fs.copyFileSync('./package.json', './package.json.bak');

const packageJson = JSON.parse(fs.readFileSync('package.json', 'utf8'));

const {
workspaces,
...packageJsonWithoutWorkspaces
} = packageJson;

fs.writeFileSync('package.json', `${JSON.stringify(packageJsonWithoutWorkspaces, null, 2)}\n`);
8 changes: 8 additions & 0 deletions restore_workspaces.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
/**
* Restores original package.json file
*/
const fs = require('fs');

fs.copyFileSync('./package.json.bak', './package.json');

fs.unlinkSync('./package.json.bak');

0 comments on commit e3cadb1

Please sign in to comment.