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: env suffix for plugins/middlewares/tasks #2922

Draft
wants to merge 4 commits into
base: v2
Choose a base branch
from

Conversation

sandros94
Copy link
Contributor

@sandros94 sandros94 commented Dec 5, 2024

πŸ”— Linked issue

Resolves #2866

❓ Type of change

  • πŸ“– Documentation (updates to the documentation, readme, or JSdoc annotations)
  • 🐞 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)
  • 🧹 Chore (updates to the build process or auxiliary tools and libraries)
  • ⚠️ Breaking change (fix or feature that would cause existing functionality to change)

πŸ“š Description

As discussed in the linked issue this will make the env suffix (.dev.ts, .prod.ts and .prerender.ts) also available to plugins, middlewares and tasks.

TODO

  • move the regex matching to scanDir
  • update the related scan* functions to return an object with env
    • scanAndSyncOptions
    • scanHandlers (untouched)
    • scanMiddleware
    • scanServerRoutes
    • scanPlugins
    • scanTasks
    • scanModules
  • make the builder filter them

πŸ“ Checklist

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

@sandros94
Copy link
Contributor Author

@pi0 sorry if this took me so long before start working on it πŸ™ but I also need your assistance since I'm unable to run tests (and didn't want to continue without checking).

I'm on WSL2, [email protected] and [email protected], but if I run pnpm run test I get:

 RUN  v2.1.6 /home/sandros94/github/sandros94/nitro

 ❯ test/presets/aws-lambda.test.ts (0)
 ❯ test/presets/azure.test.ts (0)
 ❯ test/presets/bun.test.ts (0)
 ❯ test/presets/cloudflare-module-legacy.test.ts (0)
 ❯ test/presets/cloudflare-module.test.ts (0)
 ❯ test/presets/cloudflare-pages.test.ts (0)
 ❯ test/presets/cloudflare-worker.test.ts (0)
 ❯ test/presets/deno-server.test.ts (0)
 ❯ test/presets/netlify-legacy.test.ts (0)
 ❯ test/presets/netlify.test.ts (0)
 ❯ test/presets/nitro-dev.test.ts (0)
 ❯ test/presets/node.test.ts (0)
 ❯ test/presets/static.test.ts (0)
 ❯ test/presets/vercel-edge.test.ts (0)
 ❯ test/presets/vercel.test.ts (0)
 ❯ test/presets/winterjs.test.ts (0)
 βœ“ test/unit/azure.utils.test.ts (8)
 ❯ test/unit/externals.test.ts (0)
 βœ“ test/unit/utils.env.test.ts (7)

⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯ Failed Suites 17 ⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯

 FAIL  test/presets/aws-lambda.test.ts [ test/presets/aws-lambda.test.ts ]
Error: Failed to load url nitropack/core (resolved id: nitropack/core) in /home/sandros94/github/sandros94/nitro/test/tests.ts. Does the file exist?
 ❯ loadAndTransform node_modules/.pnpm/[email protected]_@[email protected][email protected][email protected][email protected]/node_modules/vite/dist/node/chunks/dep-BcnkIxro.js:40838:17

⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯[1/17]⎯

 FAIL  test/presets/azure.test.ts [ test/presets/azure.test.ts ]
 FAIL  test/presets/bun.test.ts [ test/presets/bun.test.ts ]
 FAIL  test/presets/cloudflare-module-legacy.test.ts [ test/presets/cloudflare-module-legacy.test.ts ]
 FAIL  test/presets/cloudflare-module.test.ts [ test/presets/cloudflare-module.test.ts ]
 FAIL  test/presets/cloudflare-pages.test.ts [ test/presets/cloudflare-pages.test.ts ]
 FAIL  test/presets/cloudflare-worker.test.ts [ test/presets/cloudflare-worker.test.ts ]
 FAIL  test/presets/deno-server.test.ts [ test/presets/deno-server.test.ts ]
 FAIL  test/presets/netlify.test.ts [ test/presets/netlify.test.ts ]
 FAIL  test/presets/nitro-dev.test.ts [ test/presets/nitro-dev.test.ts ]
 FAIL  test/presets/node.test.ts [ test/presets/node.test.ts ]
 FAIL  test/presets/static.test.ts [ test/presets/static.test.ts ]
 FAIL  test/presets/vercel-edge.test.ts [ test/presets/vercel-edge.test.ts ]
 FAIL  test/presets/winterjs.test.ts [ test/presets/winterjs.test.ts ]
Error: Failed to load url nitropack/core (resolved id: nitropack/core) in /home/sandros94/github/sandros94/nitro/test/tests.ts. Does the file exist?
 ❯ loadAndTransform node_modules/.pnpm/[email protected]_@[email protected][email protected][email protected][email protected]/node_modules/vite/dist/node/chunks/dep-BcnkIxro.js:40838:17

⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯[2/17]⎯

 FAIL  test/presets/netlify-legacy.test.ts [ test/presets/netlify-legacy.test.ts ]
 FAIL  test/presets/vercel.test.ts [ test/presets/vercel.test.ts ]
Error: Failed to load url nitropack/core (resolved id: nitropack/core) in /home/sandros94/github/sandros94/nitro/test/tests.ts. Does the file exist?
 ❯ loadAndTransform node_modules/.pnpm/[email protected]_@[email protected][email protected][email protected][email protected]/node_modules/vite/dist/node/chunks/dep-BcnkIxro.js:40838:17

⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯[3/17]⎯

 FAIL  test/unit/externals.test.ts [ test/unit/externals.test.ts ]
Error: Failed to load url nitropack/kit (resolved id: nitropack/kit) in /home/sandros94/github/sandros94/nitro/src/rollup/plugins/externals.ts. Does the file exist?
 ❯ loadAndTransform node_modules/.pnpm/[email protected]_@[email protected][email protected][email protected][email protected]/node_modules/vite/dist/node/chunks/dep-BcnkIxro.js:40838:17

⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯[4/17]⎯

 Test Files  17 failed | 2 passed (19)
      Tests  15 passed (15)
   Start at  15:52:17
   Duration  967ms (transform 637ms, setup 0ms, collect 297ms, tests 14ms, environment 4ms, prepare 1.57s)

 ELIFECYCLE  Test failed. See above for more details.

Even if I do pnpm run gen-presets (although I'm not sure if this is necessary)

@pi0
Copy link
Member

pi0 commented Dec 5, 2024

Thanks @sandros94. I will review ASAP.

If you run minimal tests like this also fails?

pnpm build --sutb && pnpm vitest test/presets/node.test.ts

src/core/scan.ts Outdated Show resolved Hide resolved
@sandros94
Copy link
Contributor Author

This extractSuffix should also eliminate the small overhead caused by parsing for method, WDYT?

About scanPlugins and scanModules: do I need to take care of something in particular inside scanAndSyncOptions? Do nitro.options.plugins/modules only need to be populated in specific env?

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.

feat: env suffix for plugins/middlewares/tasks
2 participants