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

Apply publishConfig for workspace packages on deployment #6693

Open
1 task
vteivans opened this issue Jun 20, 2023 · 5 comments · May be fixed by #7647
Open
1 task

Apply publishConfig for workspace packages on deployment #6693

vteivans opened this issue Jun 20, 2023 · 5 comments · May be fixed by #7647

Comments

@vteivans
Copy link

Describe the user story

When I run pnpm --filter=<deployed project name> deploy <target directory> command on an application in workspace it copies related packages from the workspace to <target directory>/node_modules as they are. This means that the package.json files in workspace packages must be in "publishable" state (e.g. "main": "dist/index.js"). This makes the packages harder to use in development mode as they must be rebuilt on any change for the dist to represent the actual state.

I would like the package.json to be transformed from "development" state to "publishing" state for any packages that get copied over by pnpm deploy command.

Describe the solution you'd like

As far as I understand pnpm already has a solution for this. When pnpm pack (or publish) is ran, publishConfig from package.json is applied. This allows for easy switching from "development" to "publishing" state. I suggest applying the same logic on pnpm deploy - if the package that is being copied has publishConfig apply it during pnpm deploy.

Describe the drawbacks of your solution

Not sure how it could break as this would be the normal package state when it's installed from a repository.

@logan70
Copy link

logan70 commented Jul 28, 2023

I got the same problem, is there any solution?

@vteivans
Copy link
Author

The solution we've landed on so far is to have a POST install script, that looks something like this:

const writeFileSync = require('fs').writeFileSync;

const pkgJsonPath = './package.json';

const json = require(pkgJsonPath);

if (
  !json.hasOwnProperty('publishConfig') ||
  !json.publishConfig ||
  typeof json.publishConfig !== 'object'
) {
  return;
}

for (const prop of ['main', 'typings']) {
  if (json.publishConfig.hasOwnProperty(prop)) {
    json[prop] = json.publishConfig[prop];
  }
}

writeFileSync(pkgJsonPath, JSON.stringify(json, null, 2));

Keep in mind that it needs to be adjusted for when should the script be run (probably not on every package install, but only for deployment). Also the location of package.json might change if this code should be made in to a package.

JacobLey added a commit to JacobLey/pnpm that referenced this issue Aug 15, 2023
When deploying packages, the package.json of the deployed package
(as well as any other locally defined dependencies)
should be treated as if it published, and mutate the package.json
according to `publishConfig` and local `workspace:` dependencies.

Issue: pnpm#6693
@JacobLey
Copy link
Contributor

Took an attempt at implementing this: https://github.com/pnpm/pnpm/pull/6943/files

Alongside the publishConfig application, will also transform workspace: dependencies into the literal version.

Potentially this is a breaking change because it now requires install to run prior to deploy, but I believe that it is a reasonable assumption users are already doing that, especially considering these packages are assumed to have been "built" prior to deploy as well.

Agreed with @vteivans that the application of publishConfig itself should not be considered a breaking change. It could be, but that would generally mean the config is incorrectly setup.

JacobLey added a commit to JacobLey/pnpm that referenced this issue Aug 16, 2023
When deploying packages, the package.json of the deployed package
(as well as any other locally defined dependencies)
should be treated as if it published, and mutate the package.json
according to `publishConfig` and local `workspace:` dependencies.

Issue: pnpm#6693
JacobLey added a commit to JacobLey/pnpm that referenced this issue Aug 17, 2023
When deploying packages, the package.json of the deployed package
(as well as any other locally defined dependencies)
should be treated as if it published, and mutate the package.json
according to `publishConfig` and local `workspace:` dependencies.

Issue: pnpm#6693
JacobLey added a commit to JacobLey/pnpm that referenced this issue Aug 18, 2023
When deploying packages, the package.json of the deployed package
(as well as any other locally defined dependencies)
should be treated as if it published, and mutate the package.json
according to `publishConfig` and local `workspace:` dependencies.

Issue: pnpm#6693
@vteivans
Copy link
Author

Thank you very much @jakebailey!

zkochan added a commit that referenced this issue Feb 13, 2024
When deploying packages, the package.json of the deployed package
(as well as any other locally defined dependencies)
should be treated as if it published, and mutate the package.json
according to `publishConfig` and local `workspace:` dependencies.

close #6693

---------

Co-authored-by: Zoltan Kochan <z@kochan.io>
@zkochan zkochan linked a pull request Feb 13, 2024 that will close this issue
1 task
@zkochan
Copy link
Member

zkochan commented Feb 13, 2024

I don't remember how hard it was to fix all the issues that were caused by the change. But I will try to get it to v9. Created a PR again #7647

@zkochan zkochan reopened this Feb 13, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants