torenware / ddev-viteserve

An add-on to run the Vite dev server from inside the DDEV environment.
Apache License 2.0
34 stars 9 forks source link

[feat] Make the add-on "Laravel-aware" #5

Open torenware opened 2 years ago

torenware commented 2 years ago

I'm experimenting with making the add-on change its behavior when used in projects of type: laravel. Changes would include at least:

  1. Changing the javascript directory to ".", which seems to be the laravel default.
  2. Making the choice of the package manager more intelligent. New behavior will be:
    • Check for a setting in .ddev/.env
    • Otherwise: see if npm, yarn or pnpm has installed its lock-file and node_modules/ exists.
    • Otherwise: ask the user which of these package managers to use.

This issue is the tracking issue for the PRs relevant to this issue.

rfay commented 2 years ago

You should be able to compare $DDEV_PROJECT_TYPE to laravel. That gets the Laravel users that use the project type. But there are others that use project type 'php'

torenware commented 2 years ago

You should be able to compare $DDEV_PROJECT_TYPE to laravel. That gets the Laravel users that use the project type. But there are others that use project type 'php'

OK, easier than munging config.yaml myself. I'll try this to see if it works where I'm doing that.

torenware commented 2 years ago

For folks like @tyler36 to try to make sure this does what it needs to do:

Here's what the UI looks like when you do not set a package manager and do not do npm install or its yarn/pnpm equivalent:

  1. Get the current code by doing ddev get https://github.com/torenware/ddev-viteserve/tarball/laravel-aware-5
  2. ddev restart
  3. If you now call ddev vite-serve on a completely fresh project, without modifying the generated .ddev/.env file, you'll see something like this:
    $ ddev vite-serve
    1) npm
    2) yarn
    3) pnpm
    Choose the package manager to use: 
  4. Start by choosing "1" for npm. vite-serve will run npm install for you, and start vite for you.
    
    Choose the package manager to use: 1
    'npm'
    Using package manager npm

added 26 packages, and audited 27 packages in 18s

6 packages are looking for funding run npm fund for details

found 0 vulnerabilities npm notice npm notice New minor version of npm available! 8.11.0 -> 8.19.2 npm notice Changelog: https://github.com/npm/cli/releases/tag/v8.19.2 npm notice Run npm install -g npm@8.19.2 to update! npm notice Vite now serving .

5. To see the "already installed state", run `ddev vite-serve stop`, and then run `ddev vite-serve` again:

$ ddev vite-serve stop stopping vite $ ddev vite-serve 'npm' Using package manager npm

up to date, audited 27 packages in 1s

6 packages are looking for funding run npm fund for details

found 0 vulnerabilities Vite now serving .


6. Note that vite-serve auto-detected the previous npm install, but reran `npm install` to make sure things haven't changed in your package.json and lock file.
7. Delete node_modules/ and the lock file, and you'll be able to see the selection menu come up again when you restart vite-serve.
8. Try this with yarn or pnpm to see this also works.
9. Then, on a clean install of the stock Laravel project, use the procedure in the current CMS Quickstart Guide, to confirm that I haven't broken that path either.
torenware commented 2 years ago

You should be able to compare $DDEV_PROJECT_TYPE to laravel. That gets the Laravel users that use the project type. But there are others that use project type 'php'

This works fine, and the code is refactored accordingly. For the php type, it probably does not make sense to do this; in my own use of it, I still tend to put the vite project in a sub-directory, and there's no reason to suppose that people would mix the php and js code as has become Laravel's preference. For everybody else, laissez les bons temps rouler, non?