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

feat(optimizer): support patch-package #10286

Merged
merged 1 commit into from Nov 25, 2022
Merged

feat(optimizer): support patch-package #10286

merged 1 commit into from Nov 25, 2022

Conversation

ArnaudBarre
Copy link
Member

@ArnaudBarre ArnaudBarre commented Sep 29, 2022

Description

patch-package is a widely used tool to quickly fix node modules. And I would love Vite to invalidate dependencies pre-bundling when I add/update a patch to the project.

What is the purpose of this pull request?

  • Bug fix
  • New Feature
  • Documentation update
  • Other

Before submitting the PR, please make sure you do the following

  • Read the Contributing Guidelines.
  • Read the Pull Request Guidelines and follow the Commit Convention.
  • Check that there isn't already a PR that solves the problem the same way to avoid creating a duplicate.
  • Provide a description in this PR that addresses what the PR is solving, or reference the issue that it solves (e.g. fixes #123).
  • Ideally, include relevant tests that fail without this PR but pass with it.

@@ -1076,6 +1083,20 @@ export function getDepHash(config: ResolvedConfig, ssr: boolean): string {
return getHash(content)
}

function getPatchesLastModificationTime(dir: string): string | undefined {
const fullPath = path.join(dir, 'patches')
Copy link
Member

@antfu antfu Sep 29, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I feel we better not make this convention hard-coded, as this is customizable with --patch-dir option of patch-package. Maybe we could have a better way to detect it?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't see anything a part from YAO or a (maybe expensive) grep for searching files ending with .patch

@antfu
Copy link
Member

antfu commented Sep 29, 2022

I think this would be a good addition.

For reference, a side from patch-package, these tools also supports patching

@ArnaudBarre
Copy link
Member Author

Thanks for the pointers. I updated the PR to take this into account and limit the number of fs calls for lockfile != yarn.

@ArnaudBarre ArnaudBarre changed the title feat(optimizer): Support patch-package feat(optimizer): support patch-package Nov 24, 2022
@patak-dev
Copy link
Member

This looks really useful! Thanks a lot, @ArnaudBarre. Let's merge it so we can test it during the alpha.

@patak-dev patak-dev merged commit 4fb7ad0 into vitejs:main Nov 25, 2022
@ArnaudBarre ArnaudBarre deleted the patches-hash branch November 25, 2022 19:30
'pnpm-lock.yaml',
'bun.lockb'
{ name: 'package-lock.json', patchesDirs: ['patches'] }, // Default of https://github.com/ds300/patch-package
{ name: 'yarn.lock', patchesDirs: ['patches', '.yarn/patches'] }, // .yarn/patches for v2+
Copy link
Contributor

@merceyz merceyz Nov 27, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This can be changed by the user but either way it's part of the lockfile.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the report, I didn't notice while I was testing. I will send a PR to fix this before the release

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants