Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bug?]: package.json that gets packed doesn't contain changes from after prepack #3609

Closed
1 task
wojtekmaj opened this issue Oct 21, 2021 · 2 comments
Closed
1 task
Labels
bug Something isn't working

Comments

@wojtekmaj
Copy link
Contributor

wojtekmaj commented Oct 21, 2021

Self-service

  • I'd be willing to implement a fix

Describe the bug

package.json that gets packed is a version from before prepack or from after postpack. I think this is confusing - I was under impression that after prepack and before postpack is a window of time when all files are collected and packaged.

To reproduce

  • In prepack script, add a script that modifies package.json
  • in postpack script, add a script that restores package.json
  • Call yarn pack
  • Explore package.tgz

Environment

System:
    OS: macOS 12.0
    CPU: (8) x64 Intel(R) Core(TM) i5-8259U CPU @ 2.30GHz
  Binaries:
    Node: 16.5.0 - /private/var/folders/h7/yd7dwy6x5fqgw_gkv2gb_vw80000gp/T/xfs-23c51887/node
    Yarn: 3.0.0 - /private/var/folders/h7/yd7dwy6x5fqgw_gkv2gb_vw80000gp/T/xfs-23c51887/yarn
    npm: 7.19.1 - /usr/local/bin/npm

Additional context

Reproducible at https://github.com/wojtekmaj/enzyme-adapter-react-17/tree/502e1346f871418919275955b9ca267be0c3d6bd

@wojtekmaj wojtekmaj added the bug Something isn't working label Oct 21, 2021
@merceyz
Copy link
Member

merceyz commented Oct 21, 2021

Duplicate of #3145

@merceyz
Copy link
Member

merceyz commented Oct 21, 2021

This was fixed in #3146 which is currently in a canary release

yarn set version canary

I see that you made a script in wojtekmaj/enzyme-adapter-react-17@e3cadb1 to remove and restore the workspaces key but you can use a plugin for this which doesn't mutate the file on disk.

module.exports = {
	name: `plugin-remove-workspaces-field`,
	factory: () => ({
		hooks: {
			beforeWorkspacePacking(workspace, rawManifest) {
				delete rawManifest.workspaces;
			},
		},
	}),
};

wojtekmaj added a commit to wojtekmaj/enzyme-adapter-react-17 that referenced this issue Nov 1, 2021
wojtekmaj added a commit to wojtekmaj/enzyme-adapter-react-17 that referenced this issue Nov 1, 2021
wojtekmaj added a commit to wojtekmaj/enzyme-adapter-react-17 that referenced this issue Nov 1, 2021
* Revert "Remove remove-workspaces and restore-workspaces from lifecycle scripts"

This reverts commit 2235914.

* Replace prepack and postpack scripts with custom Yarn plugin

As suggested in yarnpkg/berry#3609 (comment)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants