diff --git a/package.json b/package.json index 6cffd69..f33b78f 100644 --- a/package.json +++ b/package.json @@ -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": [ diff --git a/remove_workspaces.js b/remove_workspaces.js new file mode 100644 index 0000000..dd6f089 --- /dev/null +++ b/remove_workspaces.js @@ -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`); diff --git a/restore_workspaces.js b/restore_workspaces.js new file mode 100644 index 0000000..ba74307 --- /dev/null +++ b/restore_workspaces.js @@ -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');