-
Notifications
You must be signed in to change notification settings - Fork 2.5k
nxViteTsPaths overwrites generated package.json #30312
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
Comments
The nxViteTsPaths plugin added a rollup writeBundle hook in 19.1.0 that copies over the package.json file from the projectRoot without a configuration option to not copy the file. This adds an option to prevent overwriting of a generated package.json Closes nrwl#30312
FYI, I met some of you at NX Enterprise in NYC. I went through the legal loopholes at my company to get approval to contribute for this issue. I started work on adding an option to the plugin to disable copying of the |
The nxViteTsPaths plugin added a rollup writeBundle hook in 19.1.0 that copies over the package.json file from the projectRoot without a configuration option to not copy the file. This adds an option to prevent overwriting of a generated package.json Closes nrwl#30312
The nxViteTsPaths plugin added a rollup writeBundle hook in 19.1.0 that copies over the package.json file from the projectRoot without a configuration option to not copy the file. This adds an option to prevent overwriting of a generated package.json Closes nrwl#30312
The nxViteTsPaths plugin added a rollup writeBundle hook in 19.1.0 that copies over the package.json file from the projectRoot without a configuration option to not copy the file. This adds an option to prevent overwriting of a generated package.json Closes nrwl#30312
The nxViteTsPaths plugin added a rollup writeBundle hook in 19.1.0 that copies over the package.json file from the projectRoot without a configuration option to not copy the file. This adds an option to prevent overwriting of a generated package.json Closes nrwl#30312
…ckage.json file if it already exists in dest The nxViteTsPaths plugin currently always copys the package.json file at the end of the build and does not check if the file was generated from the build process. This adds logic to check if the package.json file already exists in the dist path before copying to prevent overwriting generated files. Closes nrwl#30312
The nxViteTsPaths plugin currently always copys the package.json file at the end of the build and does not check if the file was generated from the build process. This adds logic to check if the package.json file already exists in the dist path before copying to prevent overwriting generated files. Closes nrwl#30312
I decided to take another route, and do this more as a fix instead of a feature enhancement. This prevents overwriting of a generated package.json during build. Let me know your thoughts on direction @Coly010 |
The nxViteTsPaths plugin currently always copys the package.json file at the end of the build and does not check if the file was generated from the build process. This adds logic to check if the package.json file already exists in the dist path before copying to prevent overwriting generated files. Closes nrwl#30312
The nxViteTsPaths plugin currently always copys the package.json file at the end of the build and does not check if the file was generated from the build process. This adds logic to check if the package.json file already exists in the dist path before copying to prevent overwriting generated files. Closes nrwl#30312
Current Behavior
When using nxViteTsPaths as a vite plugin for bundling a library and also using rollup-plugin-generate-pacakge-json (or any other plugin to create/modify/generate a
package.json
) the project directory'spackage.json
gets copied to the outputDir during thewriteBundle
lifecycle hook of Rollup resulting in the generatedpackage.json
file getting overwritten.Expected Behavior
Several things:
nxViteTsPaths
ignores thegeneratePackageJson
configuration from@nx/vite:build
.nxViteTsPaths
has no options related to copying apackage.json
file. Earlier versions ofnxViteTsPaths
do not copy/modify files at all. The copying ofpackage.json
is undocumented and the side-effect of overwriting apackage.json
that's generated during build is unexpected.The documentation:
https://nx.dev/nx-api/vite/documents/overview#installation
https://nx.dev/recipes/vite/configure-vite#typescript-paths
nxViteTsPaths
is a 'pre' enforced plugin, yet it uses thewriteBundle
hook, which is the last hook in rollup runs. Consider usinggenerateBundle
hook instead so other plugins can run after.IMO the functionality of copying the
package.json
file at the end of the build should be a completely separate plugin as it doesn't align with the documented use case fornxViteTsPaths
. This functionality was added for the inference feature and was added to an existing plugin instead of creating a new one.Steps to Reproduce
See reproduction: https://stackblitz.com/edit/vitejs-vite-6smqcoqr?file=package.json
npm run build:with
builds with nxViteTsPaths pluginnpm run build:without
builds without nxViteTsPaths pluginNotice difference in dist/libs/mylib/package.json#exports.
Nx Report
Additional Information
The issue is at https://github.com/nrwl/nx/blob/20.5.0/packages/vite/plugins/nx-tsconfig-paths.plugin.ts#L196-L210
@Coly010 added the
writeBundle
function as part of support for the inference plugin.This was introduced in
@nx/[email protected]
.The text was updated successfully, but these errors were encountered: