Skip to content
This repository has been archived by the owner on Apr 6, 2023. It is now read-only.

fix(nuxi): ensure nuxi upgrade runs in rootDir #6707

Merged
merged 4 commits into from
Aug 17, 2022
Merged

fix(nuxi): ensure nuxi upgrade runs in rootDir #6707

merged 4 commits into from
Aug 17, 2022

Conversation

harlan-zw
Copy link
Collaborator

@harlan-zw harlan-zw commented Aug 17, 2022

πŸ”— Linked issue

❓ Type of change

  • πŸ“– Documentation (updates to the documentation or readme)
  • 🐞 Bug fix (a non-breaking change that fixes an issue)
  • πŸ‘Œ Enhancement (improving an existing functionality like performance)
  • ✨ New feature (a non-breaking change that adds functionality)
  • ⚠️ Breaking change (fix or feature that would cause existing functionality to change)

πŸ“š Description

When using nuxi update command with a custom path, it won't honour that path when running the package manager install, instead, it will always run in the cwd.

This is apparent in a monorepo or sub-path nuxt installs.

For example, run in this repo yarn nuxi upgrade ../some-nuxt-app --force and you'll see it modifies the frameworks package.json and lock.

In providing the proper path, a new issue appears where the getNuxtVersion fails. It seems like a cache issue where it's resolving to the old version path, leading to a failure to read the file, as it didn't exist.

Exception

 ERROR  ENOENT: no such file or directory, open '/home/harlan/forks/nuxt-app/node_modules/.pnpm/nuxt@3.0.0-rc.6/node_modules/nuxt/package.json'                                                 19:49:21

Logs

➜  nuxt3-fork git:(main) βœ— yarn nuxi upgrade ../nuxt-app --force
Nuxt CLI v3.0.0-rc.8                                                                                                                                                                                                                                                                                                                              19:54:50
β„Ή Package Manager: pnpm 7.9.0                                                                                                                                                                   19:54:50
β„Ή Current nuxt version: 3.0.0-rc.6                                                                                                                                                              19:54:50
β„Ή Removing lock-file and node_modules...                                                                                                                                                        19:54:50
β„Ή Installing latest Nuxt 3 RC...                                                                                                                                                                19:54:51
 WARN  deprecated stable@0.1.8: Modern JS already guarantees Array#sort() is a stable sort, so this library is deprecated. See the compatibility table on MDN: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/sort#browser_compatibility
Packages: +579
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Packages are hard linked from the content-addressable store to the virtual store.
  Content-addressable store is at: /home/harlan/.local/share/pnpm/store/v3
  Virtual store is at:             node_modules/.pnpm
Progress: resolved 612, reused 571, downloaded 0, added 579, done

devDependencies:
+ nuxt 3.0.0-rc.8
β„Ή Cleaning up generated nuxt files and caches...                                                                                                                                                19:55:07
β„Ή Upgraded nuxt version: [unknown]                                                                                                                                                              19:55:07
βœ” Successfully upgraded nuxt from 3.0.0-rc.6 to [unknown]                                                                                                                                       19:55:07
β„Ή Changelog: https://github.com/nuxt/framework/compare/v3.0.0-rc.6...v[unknown]  

As a work-around I've set it up to read from the package.json's dependency, which should be fairly safe.

πŸ“ Checklist

  • I have linked an issue or discussion.
  • I have updated the documentation accordingly.

@netlify
Copy link

netlify bot commented Aug 17, 2022

βœ… Deploy Preview for nuxt3-docs canceled.

Name Link
πŸ”¨ Latest commit 4854d9b
πŸ” Latest deploy log https://app.netlify.com/sites/nuxt3-docs/deploys/62fcc932cdb2260007f0bf15

@harlan-zw
Copy link
Collaborator Author

harlan-zw commented Aug 17, 2022

The second getNuxtVersion is definitely using some sort of cache, here's another example running in the root of a directory. The only reason this one didn't show [unknown] is pnpm didn't delete the old package.

So in fact my fix to use the package.json lookup as a fallback should be its own PR

➜  nuxt-app nuxi upgrade
Nuxt CLI v3.0.0-rc.6-27668034.5232c1b                                                                                                                                                           20:32:25
β„Ή Package Manager: pnpm 7.9.0                                                                                                                                                                   20:32:25
β„Ή Current nuxt version: 3.0.0-rc.6-27668034.5232c1b                                                                                                                                             20:32:25
β„Ή Cleaning up generated nuxt files and caches...                                                                                                                                                20:32:25
β„Ή Upgrading nuxt...                                                                                                                                                                             20:32:25
 WARN  deprecated stable@0.1.8: Modern JS already guarantees Array#sort() is a stable sort, so this library is deprecated. See the compatibility table on MDN: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/sort#browser_compatibility
Packages: +10 -9
++++++++++---------
Progress: resolved 612, reused 571, downloaded 0, added 10, done

devDependencies:
- nuxt 3.0.0-rc.6-27668034.5232c1b
+ nuxt 3.0.0-rc.8
β„Ή Upgraded nuxt version: 3.0.0-rc.6-27668034.5232c1b                                                                                                                                            20:32:38
βœ” You're already using the latest version of nuxt.

@pi0
Copy link
Member

pi0 commented Aug 17, 2022

It is because of CJS requires cache (

try { return requireModule(id + '/package.json', paths) } catch { }
). Do you mind to migrate command to pkg-types.readPackageJSON to see if it solves?

@harlan-zw
Copy link
Collaborator Author

It is because of CJS requires cache (

try { return requireModule(id + '/package.json', paths) } catch { }

). Do you mind to migrate command to pkg-types.readPackageJSON to see if it solves?

Nice, that worked a treat as far as I can tell

➜  nuxt3-fork git:(fix/nuxi-update-non-cwd) βœ— yarn nuxi upgrade ../nuxt-app
Nuxt CLI v3.0.0-rc.8                                                                                                                                                                            20:51:42
β„Ή Package Manager: pnpm 7.9.0                                                                                                                                                                   20:51:42
β„Ή Current nuxt version: 3.0.0-rc.6                                                                                                                                                              20:51:42
β„Ή Installing latest Nuxt 3 RC...                                                                                                                                                                20:51:42
 WARN  deprecated stable@0.1.8: Modern JS already guarantees Array#sort() is a stable sort, so this library is deprecated. See the compatibility table on MDN: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/sort#browser_compatibility
Packages: +2 -4
++----
Progress: resolved 612, reused 571, downloaded 0, added 0, done

devDependencies:
- nuxt 3.0.0-rc.6
+ nuxt 3.0.0-rc.8
β„Ή Cleaning up generated nuxt files and caches...                                                                                                                                                20:51:55
β„Ή Upgraded nuxt version: 3.0.0-rc.8                                                                                                                                                             20:51:55
βœ” Successfully upgraded nuxt from 3.0.0-rc.6 to 3.0.0-rc.8                                                                                                                                      20:51:55
β„Ή Changelog: https://github.com/nuxt/framework/compare/6...8 

Copy link
Member

@pi0 pi0 left a comment

Choose a reason for hiding this comment

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

Thanks!

@pi0 pi0 changed the title fix(nuxi): ensure update dependency install uses provided path fix(nuxi): ensure nuxi upgrade runs in rootDir Aug 17, 2022
@pi0 pi0 merged commit e93f88c into nuxt:main Aug 17, 2022
@pi0 pi0 mentioned this pull request Aug 26, 2022
@danielroe danielroe added the 3.x label Jan 19, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants