* Add transparent JSX optimization.
* fix duplicate React import
* fix React not being imported when only a single Fragment node is present in a source module
* remove babel-plugin-react-require
* Fix JSX optimization for CommonJS source files.
* Add error message for duplicate slug name within a dynamic path
* Update based on feedback
Co-authored-by: Tim Neutkens <tim@timneutkens.nl>
* WIP - committed with no-verify - progress
Co-authored-by: Tim Neutkens <tim@timneutkens.nl>
* Remove old test placeholder
* Add test for re-used names
* Dynamic Routes: Change impl from $param to [param]
* Update expected test snapshot
* Update test to use new syntax
* Update test file
* Test more behavior
* Update route sorter for new param syntax
* Update dynamic routing tests
* Update danging test file
* Tweak test
* Fix dev and update tests
* replace recursive-copy with own implementation
* update yarn.lock
* do not filter out not directories
* do not fail if folder already exists
* replace `\` by `/` when sending pathes to filter
* use fs-extra only in tests
* investigate and test recursive-copy npm module
* improve test by creating fixtures programmatically
* remove recursive-copy npm module test
* add recursive-copy to bench
* add bench:recursive-copy script
* fix Sema import in recursive-copy.ts
* small improvements
* Revise dynamic route generation
This implements a new tree-based route sorting algorithm that uses a Depth-First-Traversal approach to correctly sort the routes.
This provides better clarity over a `.sort()` based approach and will scale well as we add new features in the future.
* Update import
* Moved server/lib/utils.js to Typescript
* moved _app.js to Typescript
* Moved _error.js to Typescript
* Added argument for custom props in _app and _error
* Moved _document.js to Typescript
* updated one test
* Updated types and added a validation for _document props
* Improved types
* Fixed some types
* Updated AppType
* Fixed some tests
* Added missing import
* Removed a not very useful type
* Fix missing type
* Move @types/styled-jsx
* Fix typescript errors
* Remove CLI and negative page building
* Remove select all tests
* Update test of getSpecifiedPages
* Prune old tests from snapshot
* Remove old flying shuttle tests
* Add checking of react versions to make sure it
meets the minimum set in peerDependencies
* Simplify react check
* Update error wording
Co-Authored-By: timneutkens <tim@timneutkens.nl>
* Add err.sh
* Update test-production circleci job name
* Add react error message to next-dev-server
* Update test for new wording
- Removed `fetchRoute` as it was only used once (internal method, non-breaking)
- Convert files to TypeScript
- Don't extend `ServerRouter` from `Router` as it introduces unneeded overhead, we only have to provide `pathname` `asPath` and `query` for `withRouter`. Also added `events` even though it shouldn't be called on SSR, just making sure we don't break things.
* make router UrlIsNew comparing method work as expected
* Remove shallow-equals from router and update urlIsNew check
* Remove shallow-equals test since it is no longer used
* Add integration test for asPath query
We don't use a lot of the features of `glob`, so let's remove it in favor of a leaner approach using regex.
It's failing on windows and I have no idea why and don't own a windows machine 🤦🏼♂️
(Ignore some of the commits in here, I forgot to create the new branch before I started working)
* Implement circular JSON err.sh link
* Add test for getInitialProps returning circular json
* Make test warn less
* Fix tests
* Add reference to original tests
This PR aims at replacing next-server/lib/event-emitter.js by mitt.
Fix https://github.com/zeit/next.js/issues/4908
event-emitter.js is ~400 bytes gzipped vs mitt is 200 bytes
- Replaces taskr-babel with taskr-typescript for the `next` package
- Makes sure Node 8+ is used, no unneeded transpilation
- Compile Next.js client side files through babel the same way pages are
- Compile Next.js client side files to esmodules, not commonjs, so that tree shaking works.
- Move error-debug.js out of next-server as it's only used/require in development
- Drop ansi-html as dependency from next-server
- Make next/link esmodule (for tree-shaking)
- Make next/router esmodule (for tree-shaking)
- add typescript compilation to next-server
- Remove last remains of Flow
- Move hoist-non-react-statics to next, out of next-server
- Move htmlescape to next, out of next-server
- Remove runtime-corejs2 from next-server
- [x] Add unit test
- [x] Allow to get the display name of a native component (e.g.: `div`) without throwing
- [ ] Remove displayName in production mode
* Throw error if getInitialProps is defined as as instance method
Omitting the static keyword happens pretty often. Therefore we should trigger a warning in devmode.
Closes: #4782
* Document getInitialProps error
* Add unit tests for loadGetInitialProps
The prepares for next-server.
I also took this as an opportunity to get all build directory paths from a single location, as they were previously scattered across webpack/babel plugins and loaders.
Fixes#4603.
Tests explain it the best:
```js
describe('development mode (no chunkhash)', () => {
it('should strip the extension from the filename', () => {
const filename = 'foo_bar_0123456789abcdef.js'
expect(getChunkNameFromFilename(filename, true)).toBe('foo_bar_0123456789abcdef')
})
it('should only strip the extension even if there\'s a hyphen in the name', () => {
const filename = 'foo-bar-0123456789abcdef.js'
expect(getChunkNameFromFilename(filename, true)).toBe('foo-bar-0123456789abcdef')
})
})
describe('production mode (with chunkhash)', () => {
it('should strip the hash from the filename', () => {
const filename = 'foo_bar_0123456789abcdef-0123456789abcdef.js'
expect(getChunkNameFromFilename(filename, false)).toBe('foo_bar_0123456789abcdef')
})
it('should only strip the part after the last hyphen in the filename', () => {
const filename = 'foo-bar-0123456789abcdef-0123456789abcdef.js'
expect(getChunkNameFromFilename(filename, false)).toBe('foo-bar-0123456789abcdef')
})
})
```
This fixes a missed bug introduced in #4510.
Because the regexp was `/-[^-]*/` and not `/-[^-]*$/`, a wrong part of the filename was being removed:
```
bad:
'foo-bar-0123456789abcdef-0123456789abcdef.js' -> 'foo-0123456789abcdef-0123456789abcdef.js'
good:
'foo-bar-0123456789abcdef-0123456789abcdef.js' -> 'foo-bar-0123456789abcdef'
```
By a stroke of luck this didn't affect the existing dynamically generated chunks. To prevent regression I've added unit tests for the function that generates the name.
Btw. in the original issue (#4433) I used the right regexp, I just used the wrong regexp in #4510.
cc @timneutkens
* Always use the same name for the same dynamic import.
* Add unit tests for the modulePath generation.
* Allow tests to run correctly on Windows.
* Make the chunk name a bit pretty.
* Fix tests to run on Windows.