Commit graph

36 commits

Author SHA1 Message Date
OJ Kwon
fc61428db1
feat(next/swc): support experimental swc plugins (#36790)
* build(cargo): build swc with plugin support

* feat(next): expose experimental swcplugins config

* docs(compiler): add description

* build(cargo): resolve feature conflicts

* build(cargo): resolve build conflict

* Update docs/advanced-features/compiler.md

Co-authored-by: Maia Teegarden <dev@padmaia.rocks>

Co-authored-by: Maia Teegarden <dev@padmaia.rocks>
2022-05-26 15:16:26 -07:00
Damien Simonin Feugas
bf089562c7
feat(middleware)!: forbids middleware response body (#36835)
_Hello Next.js team! First PR here, I hope I've followed the right practices._

### What's in there?

It has been decided to only support the following uses cases in Next.js' middleware:
- rewrite the URL (`x-middleware-rewrite` response header)
- redirect to another URL (`Location` response header)
- pass on to the next piece in the request pipeline (`x-middleware-next` response header)

1. during development, a warning on console tells developers when they are returning a response (either with `Response` or `NextResponse`).
2. at build time, this warning becomes an error.
3. at run time, returning a response body will trigger a 500 HTTP error with a JSON payload containing the detailed error.

All returned/thrown errors contain a link to the documentation.

This is a breaking feature compared to the _beta_ middleware implementation, and also removes `NextResponse.json()` which makes no sense any more.

### How to try it?
- runtime behavior: `HEADLESS=true yarn jest test/integration/middleware/core`
- build behavior : `yarn jest test/integration/middleware/build-errors`
- development behavior: `HEADLESS=true yarn jest test/development/middleware-warnings`

### Notes to reviewers

The limitation happens in next's web adapter. ~The initial implementation was to check `response.body` existence, but it turns out [`Response.redirect()`](https://github.com/vercel/next.js/blob/canary/packages/next/server/web/spec-compliant/response.ts#L42-L53) may set the response body (https://github.com/vercel/next.js/pull/31886). Hence why the proposed implementation specifically looks at response headers.~
`Response.redirect()` and `NextResponse.redirect()` do not need to include the final location in their body: it is handled by next server https://github.com/vercel/next.js/blob/canary/packages/next/server/next-server.ts#L1142

Because this is a breaking change, I had to adjust several tests cases, previously returning JSON/stream/text bodies. When relevant, these middlewares are returning data using response headers.

About DevEx: relying on AST analysis to detect forbidden use cases is not as good as running the code.
Such cases are easy to detect:
```js
new Response('a text value')
new Response(JSON.stringify({ /* whatever */ })
```
But these are false-positive cases:
```js
function returnNull() { return null }
new Response(returnNull())

function doesNothing() {}
new Response(doesNothing())
```
However, I see no good reasons to let users ship middleware such as the one above, hence why the build will fail, even if _technically speaking_, they are not setting the response body. 



## Feature

- [x] Implements an existing feature request or RFC. Make sure the feature request has been accepted for implementation before opening a PR.
- [ ] Related issues linked using `fixes #number`
- [x] Integration tests added
- [x] Documentation added
- [ ] Telemetry added. In case of a feature if it's used or not.
- [x] Errors have helpful link attached, see `contributing.md`

## Documentation / Examples

- [x] Make sure the linting passes by running `yarn lint`
2022-05-19 22:02:20 +00:00
Tim Neutkens
92b397f2b7
Lazy-load postcss (#31762)
Co-authored-by: Tobias Koppers <1365881+sokra@users.noreply.github.com>
Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com>
Co-authored-by: Tobias Koppers <tobias.koppers@googlemail.com>
2021-11-25 18:41:20 +01:00
Tobias Koppers
c03e28425b
make sure "webpack" exists in the repo for typings (#30371)
fixes "yarn types" needed before "yarn dev"
use incremental typescript for next package
2021-10-29 17:57:55 +00:00
JJ Kasper
38ac55dd20
Update output tracing resolving (#29473) 2021-09-29 12:38:21 -05:00
Maia Teegarden
4172a4c0a6
Add initial next swc package with first transform (#27355)
* Set up next-swc package with no custom transforms

* Add hook_optimizer transform

* Fix lint

* Build next-swc on CI

* Add toolchain in rust action

* Build binaries in manual workflow

* Commit from GitHub Actions (Build next-swc native binaries)

* Update dependencies

* Update swc and use stable rust

* Build next-swc binaries

* Test compiled code

* Dedupe @node-rs/helper

* Add workflow to check next-swc binaries

* Fix check native

* PR feedback

* PR feedback

* Pr feedback

* Build next-swc binaries

* Combine native workflows

* Add docs for contributors on less common platforms

* PR feedback

* Compare JsWord instead of converting to string

* Fix workflow formatting

* Add docs for building binaries for CI

* Build next-swc binaries

* Fix workflow if syntax

* Add license info to copied code

Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com>
2021-07-27 17:07:28 +02:00
Luke Fender
f2f9090a50
Ignore emacs lockfiles (#20497)
Fixes: https://github.com/vercel/next.js/issues/15278

> Bug report

> When using next dev with emacs, as you develop, emacs creates symbolic link files starting with .# as lock files. Next.js seems to attempt to load these but fails, spewing out errors constantly.

Prevents dev server from crashing when emacs creates lockfiles

tested with:

- GNU Emacs 27.1
- OSX 11.1
- Node v15.4.0
2020-12-29 16:12:36 +00:00
JJ Kasper
3cece4d2ad
Update Azure config (#18931) 2020-11-09 00:56:39 -05:00
Kristoffer K
2e6bc8eba4
ci: add pnp test (#16255) 2020-08-17 13:39:57 -04:00
Luis Alvarez D
48c8440016
Add .vercel to gitignore (#13595)
Also added `.now`, this should make sure that if the Vercel CLI is used inside the examples to deploy a project, the project folder is not added to the list of changes.
2020-05-31 20:53:08 +00:00
JJ Kasper
da5a05dc87
Migrate PR stats action into Next.js repo (#13177)
* Migrate PR stats into Next.js repo

* Update running prettier in local mode
2020-05-21 14:07:27 +02:00
Luis Alvarez D
a6a8ee53ba
Added path (#13075) 2020-05-19 11:11:14 +02:00
Luis Fernando Alvarez D
b94123ccc9 Improve exported router types (#7853)
* Added the RouteUrl type and improved router types

* Added more tests for router types

* Add build test for typescript types

* Add next-env.d.ts to the typescript test

* Removed next-env.d.ts

* Added next-env.d.ts to gitignore

* Remove route url re-exports

* renamed PublicRouterInstance to be NextRouter

* export the Url type

* Replaced BaseRouter with NextRouter in server/utils

* Don't export the Url type

* Update tsconfig.json
2019-07-11 13:35:39 -04:00
JJ Kasper
533018f7d0 Update tests for BrowserStack (#6810)
Update tests to setup webdriver stuff in `jest-environment` and re-use one browser session instead of spawning one for each webdriver call to prevent creating too many BrowserStack sessions.
2019-03-29 16:05:53 +01:00
Corbin Crutchley
9504a389c0 Update dependencies of various examples (#6731)
Minor changes to examples. Updating major semver updates with only `package.json` changes. 
I've done my best to make sure that these packages.json files all have `latest` for the `nextjs` package, `cross-env` for those with `server.js` files, etc.
I also added a `package.json` to `with-dynamic-app-layout` (it was missing one previously)

Made sure to test all of these packages post-upgrade to ensure maintained functionality
2019-03-27 01:42:49 +01:00
Tim Neutkens
620b426903
Remove baseurl/paths option (#5878)
For some reason the canary branch is failing on Typescript while the PR was not.
2018-12-13 16:56:48 +01:00
Adam Lane
e8f7847645 ingore intelij editor files (#5645) 2018-11-13 11:05:58 +01:00
Tim Neutkens
f9cd204c99 Remove yarn.lock 2018-09-02 15:17:37 +02:00
Evan Tahler
a39e54c675 custom-server-actionhero (#3905) 2018-02-27 13:16:17 +01:00
Arunoda Susiripala
4b143fc232 Make sure dynamic imports works on Windows (#3641)
* Make sure dynamic imports works on Windows

* Fix an issue with the load test firmware.

* Fix symlink creation on Unix
2018-01-31 08:35:10 +01:00
Tim Neutkens
06d42b99ec Ignore package-lock.json (#2623) 2017-07-23 19:51:12 +02:00
Arunoda Susiripala
e613882010 Update tests for the recent changes. 2017-05-15 09:31:02 +05:30
Arunoda Susiripala
7b193f1aa7 Add basic test setup 2017-05-09 16:24:34 -07:00
Arunoda Susiripala
e8ff53f519 Added the test app for static export. 2017-05-09 14:03:20 -07:00
alex newman
9347c8bdd0 Specify a different build directory for #1513 (#1599)
* Update references to `.next`

* Remove console logs and extraneous semi colons

* Remove lint errors

* Update references to .next and update docs

* Update options from nested to flat with `distDir`

* Add integration tests, and update `.gitignore`

* Rename integration folder to dist-dir to match standards
2017-04-06 15:39:26 +05:30
Leo Lamprecht
73f493cba5
is part of the build output 2017-02-16 23:55:28 +01:00
Naoyuki Kanezawa
141ab99888 build on tmp dir (#1150) 2017-02-15 10:03:33 -03:00
Naoyuki Kanezawa
f3145ab1d1 remove editors section from .gitignore (#1148) 2017-02-15 11:50:29 +01:00
Thomas Lindstrøm
acc1983f80 Don't delete .next folder before a replacement is built (#1139) 2017-02-14 20:14:30 -03:00
Lukas Strassel
4a73ccbb00 add react and react dom as peer (#1024)
- tackles #997
- add ./idea to gitignore for webstorm users
- update all the examples
2017-02-08 10:11:38 +05:30
Leo Lamprecht
7ee6b0f4b0
Yarn's lockfile should be part of the repo
https://yarnpkg.com/en/docs/yarn-lock
2016-12-06 21:57:21 +01:00
Benjamin Coe
c56fde89c3
chore: add test coverage 2016-11-22 10:11:23 -08:00
Leo Lamprecht
9ad5414ce3
Commented on ignored files and dirs 2016-10-25 20:44:56 +02:00
Dan Zajdband
7f89c39045 Set test command and added more tests 2016-10-12 19:15:58 -04:00
nkzawa
3647ed14ac add a test 2016-10-10 13:25:08 +09:00
nkzawa
9b06a22f31 initial source 2016-10-06 08:52:50 +09:00