From 91b5de24d00f836a2adf900128b0e472d6d0bef3 Mon Sep 17 00:00:00 2001 From: Wojciech Maj Date: Thu, 21 Oct 2021 14:26:49 +0200 Subject: [PATCH 1/2] Revert "Remove remove-workspaces and restore-workspaces from lifecycle scripts" This reverts commit 22359142363e6a4cff41638c29893483631b5a1e. --- package.json | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/package.json b/package.json index 03f5272..e49af46 100644 --- a/package.json +++ b/package.json @@ -11,7 +11,8 @@ "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" From 487f79b6571c61cab9a3b8dc21285afc6ab7ffd4 Mon Sep 17 00:00:00 2001 From: Wojciech Maj Date: Mon, 1 Nov 2021 17:16:52 +0100 Subject: [PATCH 2/2] Replace prepack and postpac scripts with custom Yarn plugin As suggested in https://github.com/yarnpkg/berry/issues/3609#issuecomment-948562289 --- .yarn/plugins/plugin-remove-workspaces-field.cjs | 10 ++++++++++ .yarnrc.yml | 1 + package.json | 5 +---- remove_workspaces.js | 16 ---------------- restore_workspaces.js | 8 -------- 5 files changed, 12 insertions(+), 28 deletions(-) create mode 100644 .yarn/plugins/plugin-remove-workspaces-field.cjs delete mode 100644 remove_workspaces.js delete mode 100644 restore_workspaces.js diff --git a/.yarn/plugins/plugin-remove-workspaces-field.cjs b/.yarn/plugins/plugin-remove-workspaces-field.cjs new file mode 100644 index 0000000..7b08819 --- /dev/null +++ b/.yarn/plugins/plugin-remove-workspaces-field.cjs @@ -0,0 +1,10 @@ +module.exports = { + name: `plugin-remove-workspaces-field`, + factory: () => ({ + hooks: { + beforeWorkspacePacking(workspace, rawManifest) { + delete rawManifest.workspaces; + }, + }, + }), +}; diff --git a/.yarnrc.yml b/.yarnrc.yml index cafa477..cbe06f8 100644 --- a/.yarnrc.yml +++ b/.yarnrc.yml @@ -1,6 +1,7 @@ nodeLinker: node-modules plugins: + - path: .yarn/plugins/plugin-remove-workspaces-field.cjs - path: .yarn/plugins/@yarnpkg/plugin-interactive-tools.cjs spec: "@yarnpkg/plugin-interactive-tools" diff --git a/package.json b/package.json index e49af46..cfced26 100644 --- a/package.json +++ b/package.json @@ -11,10 +11,7 @@ "build": "babel --source-maps=both src -d build", "clean": "rimraf build", "lint": "eslint src/ --ext .jsx,.js", - "postpack": "yarn restore-workspaces", - "prepack": "yarn clean && yarn build && yarn remove-workspaces", - "remove-workspaces": "node remove_workspaces.js", - "restore-workspaces": "node restore_workspaces.js", + "prepack": "yarn clean && yarn build", "test": "yarn lint" }, "keywords": [ diff --git a/remove_workspaces.js b/remove_workspaces.js deleted file mode 100644 index dd6f089..0000000 --- a/remove_workspaces.js +++ /dev/null @@ -1,16 +0,0 @@ -/** - * 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 deleted file mode 100644 index ba74307..0000000 --- a/restore_workspaces.js +++ /dev/null @@ -1,8 +0,0 @@ -/** - * Restores original package.json file - */ -const fs = require('fs'); - -fs.copyFileSync('./package.json.bak', './package.json'); - -fs.unlinkSync('./package.json.bak');