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
feat(deploy): apply publishConfig to all packages during deploy #6943
Conversation
💖 Thanks for opening this pull request! 💖 |
@@ -46,6 +59,10 @@ test('deploy', async () => { | |||
fs.writeFileSync(`${name}/index.js`, '', 'utf8') | |||
}) | |||
|
|||
await writeYamlFile('pnpm-workspace.yaml', { packages: ['*'] }) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In order to createExportableManifest
we need metadata only available after an install.
Presently, deploy
does not actually require an install previously.
This could be considered a breaking change. Although I would assume most users already have the relevant packages installed, and expected this behavior. This is inline with how commands like publish
work.
deploy
could be considered a "local" publish
.
@@ -46,6 +59,10 @@ test('deploy', async () => { | |||
fs.writeFileSync(`${name}/index.js`, '', 'utf8') | |||
}) | |||
|
|||
await writeYamlFile('pnpm-workspace.yaml', { packages: ['*'] }) | |||
crossSpawn.sync(pnpmBin, ['install', '--ignore-scripts', '--store-dir=../store', `--registry=http://localhost:${REGISTRY_MOCK_PORT}`]) | |||
fs.rmSync('pnpm-lock.yaml') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A little bit of a hack for testing purposes... an assertion below checks that this file does not exist (as a side effect of the install
called internally to deploy
) and wanted to maintain that assertion.
if (opts.makeExportableManifest) { | ||
const manifest = await readProjectManifest(newDir) | ||
const exportableManifest = await createExportableManifest( | ||
path.dirname(filenames[manifest.fileName]), | ||
manifest.manifest | ||
) | ||
await manifest.writeProjectManifest(exportableManifest) | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is going to be used only by the deploy command, so I don't see any reason to put this code to importIndexedDir. Just place it in deploy.ts
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Updated to put all createExportableManifest
logic in deploy.ts
.
Removed all changes to other packages (adding createExportableManifest
option)
4049b5c
to
6e980d0
Compare
Build is currently only failing on ubuntu+v16 on this test: https://github.com/pnpm/pnpm/blob/main/pnpm/test/filterProd.test.ts#L9 This PR does not touch filtering, install, or recursive execution, so I would be surprised if I explicitly broke something. Will defer to maintainer for guidance if there is something I can do to fix? Or perhaps just retry the test (flaky)? |
The issue with this solution is that now I suggest a different solution. Make the change in directory-fetcher. It create an index file that is passed to the linker. You can write the "exportable manifest" into |
Agreed, should only be executed on local packages. Looking into Another possible solution is to look up the list of all packages in the workspace pre-install (via something like
That sounds safe to me. Do we want to clean up the file after we are done with it?
|
No, I think we can make this the default behaviour for all local directory dependencies. No need to pass options. |
6e980d0
to
0729698
Compare
Updated, but not ready to merge.
|
type WriteProjectManifest = (manifest: ProjectManifest, force?: boolean) => Promise<void> | ||
interface WriteProjectManifestOptions { | ||
force?: boolean | ||
manifestPathOverride?: string |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The existing behavior was to re-write the file in same location it was loaded from. That is unwanted for our use case, so provided this override option.
This "breaks" existing options syntax, although I did not find any usage of the force option... so actually worked in-repo.
If this method is considered part of pnpm's public API though, I can tweak to accept a boolean or this options object for backwards compatibility.
Alternatively, I can use the writeProjectManifest
function directly in directory-fetcher
, but I did appreciate that the manifest.writeProjectManifest
came with sensible defaults
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Don't add this option. Just use a function that accepts the path to the manifest for saving the manifest.
filesIndex[fileName] = manifestPathOverride | ||
} | ||
|
||
return manifest?.manifest ?? null |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure exactly what behavior depends on it, but would it be preferable to return exportableManifest
here instead?
FWIW that did not solve my current failing tests anyways.
manifest.manifest | ||
) | ||
const manifestPathOverride = path.join(dir, 'node_modules', '.pnpm', fileName) | ||
await manifest.writeProjectManifest(exportableManifest, { manifestPathOverride }) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here is the use case of manifestPathOverride
. As mentioned in other comment, could replace this call with raw writeProjectManifest
(rather than the one built into the safeRead response)
|
||
if (manifest) { | ||
const { fileName } = manifest | ||
const exportableManifest = await createExportableManifest( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's actually check if the exportableManifest differs from the original one. If it doesn't differ, there's no. need to write it to the file system and the path to the original file may be used.
type WriteProjectManifest = (manifest: ProjectManifest, force?: boolean) => Promise<void> | ||
interface WriteProjectManifestOptions { | ||
force?: boolean | ||
manifestPathOverride?: string |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Don't add this option. Just use a function that accepts the path to the manifest for saving the manifest.
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
0729698
to
b12b3e9
Compare
Updated to use separate One (trivial) call out is that the package will not necessarily be formatted the same way as before. Which I guess wasn't ever a guarantee (e.g. multi-newline in JSON file is removed) but now we would also lose comments in a JSON5, or change the indent settings. |
Congrats on merging your first pull request! 🎉🎉🎉 |
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>
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 localworkspace:
dependencies.Issue: #6693