Commit graph

639 commits

Author SHA1 Message Date
Joe Haddad
cbf8e0b2c4
Bump Babel Cache Key (#9655) 2019-12-06 23:30:58 -05:00
Joe Haddad
bbc62a07be
Only Remove Server-Side Imports (#9653)
* Only Remove Server-Side Imports

* Cleanup imports
2019-12-06 22:57:14 -05:00
Joe Haddad
b4db0421ff
Rewrite SSG Transform for Recursive Cleanup (#9652) 2019-12-06 22:03:55 -05:00
Joe Haddad
cb4c08c02b
Fix SSG Named Export Transform (#9649) 2019-12-06 11:50:50 -05:00
Joe Haddad
10b2eb5b31
Fix Import Shaking for Namespaces (#9650) 2019-12-06 11:46:00 -05:00
Joe Haddad
e76fc18675
Remove Scope Bindings for SSG (#9642) 2019-12-05 18:05:50 -05:00
Joe Haddad
7a51b888c5 Add SSG Support for VariableDeclarations (#9641) 2019-12-05 16:43:18 -06:00
Joe Haddad
a718df5f56
Rewrite SSG Transform (#9640)
* Rewrite SSG Transform

* Add Named Declaration Support

* more adjustments

* Re-crawl scope
2019-12-05 17:22:41 -05:00
Joe Haddad
b4d0740c62
Separate SSG Transform from Config (#9639)
* Separate SSG Transform from Config

* update fn name

* fix
2019-12-05 16:43:11 -05:00
Joe Haddad
30ff9a339f Remove Extraneous Imports in Pages (#9627)
* Remove Extraneous Imports in Pages

* Add test

* bump cache key
2019-12-05 11:04:00 -06:00
Joe Haddad
21e1db7bc1
Aggressively Replace Constants (#9610)
* Aggressively Replace Constants

* Test both windows

* add other switch
2019-12-03 16:08:49 -05:00
Joe Haddad
063e174076
Add Support for Event Flushing (#9606)
* Add Support for Event Flushing

* Update packages/next/export/index.ts

Co-Authored-By: JJ Kasper <jj@jjsweb.site>
2019-12-03 11:18:58 -05:00
JJ Kasper
bf1d872f89 Fix extra prerender error for invalid getStaticProps usage (#9593)
* Fix extra prerender error for invalid getStaticProps usage

* Add error for getStaticProps usage in _error

* Revert erroring for SSG in _error
2019-12-02 17:12:10 -05:00
Joe Haddad
69b7538dce
Simplify getRouteRegex Callsites (#9597) 2019-12-02 16:43:30 -05:00
Joe Haddad
dd1f610f8d
Add SSG Tests with Catch All Routing (#9594)
* Add SSG Tests with Catch All Routing

* fix node version compat

* Remove unneeded query
2019-12-02 16:04:25 -05:00
JJ Kasper
89b22d2994 Fix missing getStaticProps error in serverless mode (#9532)
* Make sure to show missing getStaticProps error in serverless mode

* Update test
2019-11-27 23:23:32 -05:00
Joe Haddad
ca3f881a42 s/getStaticParams/getStaticPaths/ (#9565)
* WIP: rename get static paths

* Adjust logic

* Add warning

* rename constant

* Check for error when using old method

* Add friendly error message

* Test for message of invalid keys

* replace index with dots
2019-11-27 21:46:16 -06:00
Joe Haddad
a6656a0b84
Upgrade path-to-regexp (#9553)
* Upgrade `path-to-regexp`

* Correct import

* Update delimiter

* Fix path match

* Fix hot loader

* Fix params.path usage and pathToRegexp import

* Revert changes for params.path

* Fix lint

* Simplify path match function

* Delimiter should always be `/`

* Fix passed in params

* Add new regex wrapping

* Wrap another route

* Fix error message match
2019-11-27 16:48:28 -05:00
Kristoffer K
63886b36a2 fix: resolve preset-modules (#9538)
* fix: require preset-modules

* Update packages/next/build/webpack/plugins/next-esm-plugin.ts

Co-Authored-By: Joe Haddad <timer150@gmail.com>

* fix formatting
2019-11-26 14:56:08 -05:00
Jason Miller
1f15746176 [modern] preset-modules & fix custom babelrc (#9489)
* Modernize additional common Babel configurations.

* Add @babel/preset-modules dependency

* code quality

* Use modern terser ecma mode for .module.js bundles.
2019-11-26 11:27:26 +01:00
JJ Kasper
cd8e72d5e3 Add custom routes to build output (#9517)
* Add custom routes to build output

* De-dupe code a bit
2019-11-26 10:33:47 +01:00
Janicklas Ralph
04a7f1e85d Replace url polyfill with self.URL (#9200)
* Adding native-url package

* Bumping native-url version

* Upgrading native-url

* Logging stats object for debugging

* Logging stats object for debugging

* Adding try catch to the error lines

* Experimenting with regex

* Experimenting with regex

* Experimenting with regex

* Testing regex changes

* Fixing defer-script test case to not include polyfill.js

* Meging changes with existing polyfill work

* Bumping version

* adjust webpack config

* Reduce size in size test

* Remove 1kb from legacy
2019-11-25 23:10:02 -05:00
Joe Haddad
4656f52d15
CSS Support Customization (#9502)
* CSS Support Customization

* Sort imports

* Correct PostCSS plugin loading

* Add css customization test

* Test "bad" css configuration

* Add load config test

* adjust spacing

* adjust spacing 2x

* Only allow config through JSON

* Support excluding false plugins

* Test tailwind css behavior

* Test plugin exclusion

* Fix unit test

* Fix config file

* Remove more variants

* Update test cases
2019-11-25 16:52:29 -05:00
Joe Haddad
caa5347873
Remove Legacy Code (#9515)
The `sprStatus` module state is no longer used (and shouldn't be!). We can safely remove this code.

I also renamed the drop bundle identifier while I was here.
2019-11-25 14:32:25 -05:00
Joe Haddad
0a86b149fa
Purge Babel Cache (#9514)
* Bust Babel Cache

* Increase e
2019-11-25 14:16:04 -05:00
Joe Haddad
b80d4d6893
Drop Re-Exported iSSG Imports (#9512)
* Drop Re-Exported iSSG Imports
This pull request adds loader support for the following export form:
```js
export { getStaticParams as unstable_getStaticParams } from '../../lib/docs/page';
export { getStaticProps as unstable_getStaticProps } from '../../lib/docs/page';
```

This will now result in correct detection and removal.

* Add unit tests for next page config behavior

* Test extra function is not dropped
2019-11-25 11:44:24 -05:00
Joe Haddad
61f4e70135
Upgrade Babel Dependencies (#9478)
* Upgrade Babel Dependencies

* Update test for new size
2019-11-20 21:53:12 -05:00
JJ Kasper
09cab2df5e Fix typo in serverless loader (#9431)
* Fix typo in serverless loader

* Add test for top level error in API route

* Fix type error
2019-11-15 18:00:24 -08:00
Joe Haddad
ba5e6943fa
[Experimental] Catch-all Route Support (#9416)
* Catch-all Route Support

* Add SSR tests

* Add additional test

* Add unit tests

* Put the feature behind a flag

* Apply suggestions from code review

Co-Authored-By: JJ Kasper <jj@jjsweb.site>

* Fix test
2019-11-14 23:19:41 -08:00
Janicklas Ralph
332852bf01 Integration test case for fetch alias (#9391)
* Polyfilling fetch and object-assign

* Polyfilling corejs object-assign

* Adding object-assign in polyfills.js. IE11 does not support Object.assign

* Fixing failing test

* Updating object.assign polyfill to fix aliasing

* Updating test case value to match new build stats

* Increasing the size of default build to 225kb

* Fixing defer-script test case to not include polyfill.js

* Revert README.md

* Re-design the polyfill approach based on PR feedback

* Adding comment and fixing test case

* Rename polyfills chunk

* Extract aliases into helper

* Remove extra new line

* Fix TypeScript typings

* Adding _internal_fetch alias

* Adjust build manifest plugin

* Build manifest plugin changes - adding a separate entry for polyfills

* Rename polyfills entry in build-manifest.json

* Remove old comment

* Fix TS

* Set key

* Polyfills already added

* Filtring polyfill.module.js

* Fix test

* Add __internal_fetch to alias rule

* Adjust name

* bump size

* ignore polyfills

* sigh

* Aliasing Object.assign

* Mergin latest changes

* Integration test for polyfilling fetch

* Remove comment

* Fix prettier error

* Fix review comments

* Fix review comments

* Update fetch.js

* Fix tests
2019-11-14 22:47:08 -08:00
Joe Haddad
7bb7d70650
Polyfill Object.assign by Default (#9369)
* Polyfill `Object.assign` by Default

* fix formatting
2019-11-10 20:48:11 -08:00
Mathieu Triay
be86ab00e1 Update webpack config to also take next-stylus into account (#9277) 2019-11-10 19:56:29 -08:00
Joe Haddad
18a9c7e371
Improve linting rules to catch more errors (#9374)
* Update `packages/`

* Update examples

* Update tests

* Update bench

* Update top level files

* Fix build

* trigger
2019-11-10 19:24:53 -08:00
Joe Haddad
8107533b21
Bind fetch to self instead of window (#9368) 2019-11-10 12:54:29 -08:00
Joe Haddad
8dcec04bd1
Fix window.fetch Polyfill (#9364) 2019-11-09 21:25:32 -08:00
JJ Kasper
4e3b5ae20c
Update routes-manifest and add tests (#9361)
* Test custom-routes serverless

* Make sure we add default statusCode to routes-manifest

* Update routes-manifest

* Add DEFAULT_REDIRECT_STATUS constant
2019-11-09 20:00:54 -08:00
JJ Kasper
d19e825daa Implement custom routes RFC (#9157)
* add initial custom-routes handling

* Add tests for custom-routes

* Handle chained redirects, separate dev custom
routes reading, and add version to routes manifest

* Handle no routes manifest

* Swap build custom routes calling

* Add flatten-routes

* Add flattening of custom routes

* Re-work implementation to follow routes top-down

* Add regex field to routes-manifest

* Fix path-to-regexp match breaking after upgrade

* Fix duplicate const from merge

* Add some changes from review

* Don't make path-match strict

* add default custom route values

* Update routes-manifest

* Update options for path-match

* Remove todo

* Add test for rewrite with params

* Only use strict mode for custom routes

* Update dynamic-routing test

* Move getCustomRoutes to prepare

* Remove extra change

* Update handling for error-in-error test

* Apply suggestions from code review

Co-Authored-By: Joe Haddad <joe.haddad@zeit.co>

* Apply suggestions from review

* Update slice change

* Apply suggestions from code review

Co-Authored-By: Joe Haddad <joe.haddad@zeit.co>

* Apply suggestions from review

* Fix TypeScript error

* Fix getCustomRoutes in dev mode

* Apply suggestions from code review

* Update slice

* Apply suggestions from code review

Co-Authored-By: Joe Haddad <joe.haddad@zeit.co>

* Delete un-used test page

* Add test for param overwriting

* Apply suggestions from code review

Co-Authored-By: Joe Haddad <joe.haddad@zeit.co>

* Add extra check to param test
2019-11-09 14:34:52 -08:00
JJ Kasper
820a9790ba Add a routes manifest with the dynamic routes (#9347)
* Add a routes manifest with the dynamic routes

* Update to use pageKeys for windows compat

* Update routes-manifest test
2019-11-08 16:51:19 -08:00
Tim Neutkens
0499316650 Add check for now.json and custom server (#9346)
* Check if the user has a now.json

* Check for now.json

* Add check for custom server
2019-11-08 09:03:50 -08:00
Joe Haddad
dee2888404
Allow TypeScript Namespaces (#9308) 2019-11-04 15:26:31 -05:00
Joe Haddad
8e62c9b688
Enforce the framework Chunk (#9250) 2019-11-04 11:25:14 -05:00
Joe Haddad
bbf705f262
Simplify Build Output (#9281)
* Simplify Build Output

* Remove noop tests

* Drop 

* Remove bolding
2019-11-04 11:14:04 -05:00
JJ Kasper
739322d06b Handle backslashes for plugins (#9282) 2019-11-01 23:06:34 -04:00
Janicklas Ralph
ff2d3fd87d Polyfill window.fetch by Default (#9168)
* Polyfilling fetch and object-assign

* Polyfilling corejs object-assign

* Adding object-assign in polyfills.js. IE11 does not support Object.assign

* Fixing failing test

* Updating object.assign polyfill to fix aliasing

* Updating test case value to match new build stats

* Increasing the size of default build to 225kb

* Fixing defer-script test case to not include polyfill.js

* Revert README.md

* Re-design the polyfill approach based on PR feedback

* Adding comment and fixing test case

* Rename polyfills chunk

* Extract aliases into helper

* Remove extra new line

* Fix TypeScript typings

* Adding _internal_fetch alias

* Adjust build manifest plugin

* Build manifest plugin changes - adding a separate entry for polyfills

* Rename polyfills entry in build-manifest.json

* Remove old comment

* Fix TS

* Set key

* Polyfills already added

* Filtring polyfill.module.js

* Fix test

* Add __internal_fetch to alias rule

* Adjust name

* bump size

* ignore polyfills

* sigh
2019-11-01 21:00:56 -04:00
Tim Neutkens
7c80febcf7 Initial plugins implementation (#9139)
* Add initial bit for plugins

* Add checks for needed metadata values

* Add test

* Initial plugins changes

* Add handling for _app middleware

* Add loading of _document middleware and
handling of multiple default export syntaxes

* Fix insert order for middleware member expression

* Remove early return from middleware plugin from testing

* Add tests for current plugin middlewares

* Update test plugin package.json

* Update handling for class default export

* Update to use webpack loader instead of babel
plugin, remove redundant middleware naming, and add field for required env for plugins

* Add middleware to support material-ui use case
and example material-ui plugin

* Update tests and remove tests stuff from google analytics plugin

* Remove old plugin suite

* Add init-server middleware

* Exit hard without stack trace when error in collecting plugins

* Add on-error-client and on-error-server and update
to run init-server with next-start in serverless mode

* Update init-client for google analytics plugin

* Add example Sentry plugin and update with-sentry-simple

* Remove middleware field/folder and use src dir for plugins

* Add post-hydration middleware and update
material-ui plugin

* Put plugins code behind flag

* Update chromedriver

* Revert "Update chromedriver"

This reverts commit 1461e978e677f7da05e29e0415ec614a04bf65f9.

* Update lock file

* Remove un-needed _app for sentry example

* Add auto loading of scoped packages, add plugins
config for manually listing plugins, and update
to only collect plugins once

* Update example plugins

* Expose plugins' config

* Rename plugin lifecycles and add babel-preset-build

* Rename other methods with unstable

* Update log when plugin config overrides auto-detecting
2019-11-01 14:13:13 -05:00
JJ Kasper
aafbd53cbf Remove dead code elimination for when iSSG isn't used (#9267)
* Don't rely on page-config plugin to detect iSSG usage

* Make sure to only update sprStatus if page file

* Remove dead-code elimination for iSSG code

* Revert next-page-config.ts

* Update index.js

* Update index.test.js
2019-10-31 16:07:35 -04:00
JJ Kasper
fa5fb97ce8 Make sure to pipe output from staticCheckWorkers (#9256) 2019-10-31 12:38:09 +01:00
Jason Miller
c966900768 Bugfix/Performance: Start the modern child compiler earlier (#9257)
* Start the modern Child Compiler earlier during builds

* fix child compiler errors not bubbling
2019-10-31 12:37:07 +01:00
Gerald Monaco
f632567bcf Add experimental config for React Mode (#9207)
* Add experimental config for React Mode

* Use latest types

* Use latest types
2019-10-30 09:39:58 -04:00
Joe Haddad
6b54e9ed66 Fix Prettier Commit Hook (#9245)
* Apply format to webpack config

* hit all files
2019-10-30 12:35:51 +01:00
Jan Karres
3b3d20f729 Check if 'formatAmpMessages' returns a none empty string in Next.js build process (#8924) 2019-10-29 23:49:40 -04:00
Jason Miller
5f203b8342 Improve serverless build performance (#9155)
* Improve serverless build performance

Next's serverless build uses a custom resolver, injected the via Webpack's `externals` option that delegates out to `resolve-request` to more aggressively pull node modules into the serverless bundles.

When profiling a large Next.js application, I noticed an excessive number of filesystem calls near the end of the build. I narrowed this down to the serverless compiler pass, and eventually the custom resolver function that is the subject of this PR.  As it turns out, around half of the calls to the `externals` custom resolver function are for a `request` path that is a relative import. Next doesn't have any specific logic to apply to relative imports - it only needs to special-case bare module resolution.

Adding a simple bypass for relative module resolution reduces the number of blocking filesystem-bound `resolveRequest()` calls by 50% on a certain well-known Next.js website. This also results in a 30% reduction in production build times for incremental builds.

* Explain more in the comment
2019-10-29 23:36:22 -04:00
Janicklas Ralph
d3293f7cd6 Dynamic granular chunking (#9090)
* Enable granular chunks config for all chunk types

Adding comment

Bug fix

* Update index.test.js

* Update index.test.js

* Fix test cases. Adding next/link to not trigger a different bug

* Removing obsolete comment
2019-10-29 21:27:41 -04:00
Christoph Tavan
14ed867537 Disable worker_threads by default for firebase compatibility (#9199)
* Pass config.experimental.cpus to export during build

Currently, there is no way of specifying the number of worker threads of
`next export` when run as part of `next build`.

I suggest a sane default should be to just use the same amount of
workers that were used during the build process which currently seems to
be configured through `config.experimental.cpus`.

This setting is already respected in the two other places where
jest-workers are in use: The TerserPlugin and the staticCheckWorkers in
`next build`.

* Only enable worker threads if there is more than 1 worker

Multiple worker threads can cause problems when certain dependencies are
being used, see e.g. https://github.com/zeit/next.js/issues/7894

This patch allows disabling of worker threads by setting
`config.experimental.cpus = 1`.

The benefit of spawning 1 worker thread, if there is any at all, should
very limited anyways, so the workload can just as well be processed in
the main thread.

* Disable parallel build for firebase authentication example

* Add integration test to cover #7894

* Rename test suite and add worker_threads config

* Disable worker_threads by default

* Update index.test.js

* Use workerThreads config for TerserPlugin

* Update to use workerThreads config in
TerserPlugin for consistency

* Disable node 12 specific test
2019-10-28 20:01:24 -04:00
Alexander Kachkaev
ad2a3d65fd Add configuration flags to disable integrated type checker (#9138)
* Add a configuration flag to disable integrated type checker

* Add tests for typescript-transpileonly

* Restore removed argument

* Make output more coherent

* Split transpileOnly into ignoreDevErrors and ignoreBuildErrors

* Minor stylistic change
2019-10-28 11:02:03 -07:00
htbvo
211c84e1c9 allow NextScript to optionally defer javascript (#8980)
* allow NextScript to optionally defer javascript

* move defer options to experimental feature

* combine defer flags into a single option

* Update deferScripts to work with serverless target

* Add test for defer and async property

* Read the async property

* Check versions of chrome and chromedriver

* Update to chromedriver 76

* Fix test
2019-10-26 19:27:22 +02:00
Gerald Monaco
4421448f03 Add StrictMode toggle (#9161)
* Add StrictMode toggle

* Rename option to reactStrictMode

* Default to false initially
2019-10-26 00:20:38 +02:00
JJ Kasper
d38da874cf Record src directory usage with version (#9023)
* Add tracking src dir usage to telemetry

* Move isSrcDir back to eventVersion

* Move spinner back

* Add test for isSrcDir telemetry

* Add test for dev mode
2019-10-22 22:42:16 -04:00
Alex Castle
a82b5aed9b Update granular chunks to produce up to 25 chunks per entrypoint on high-complexity apps (#9129) 2019-10-18 13:36:03 -04:00
Joe Haddad
4d3cca3382
Warn on No Cache in CI (#9116)
* Warn on No Cache in CI

* Bold the note lead

* Add custom clarification for netlify

* Reorder

* Add tests

* Fix detection
2019-10-18 12:40:47 -04:00
Gerald Monaco
d28e46ac15 Support Concurrent Mode in Loadable (#9026) 2019-10-18 17:23:06 +02:00
JJ Kasper
499808fa2b
Make sure to update scope for page export declaration (#9115)
* Register page export declaration to scope

* Update to not need to traverse to update scope
2019-10-18 09:37:09 -05:00
JJ Kasper
a3eb73240c Update to return JSON if data request (#9106)
* Update to return json if data request

* Update sending data

* Add test using serverless bundle directly

* Don't early return if fromExport
2019-10-16 17:24:28 -04:00
Joe Haddad
393af8e6b3
Fix SPR header name (#9104) 2019-10-16 14:54:07 -04:00
Alex Castle
0886a1234d Optimize script tags (#9048)
* Update _document.tsx to optimize script loading

* Update maxInitialChunks to 15

* Undo change chunk count

* Adjust impl a bit

* Add CSS preload test

* Ensure build manifest not preloaded

* Correct file name

* break comment
2019-10-16 00:01:10 -04:00
Joe Haddad
0208356f67
Temporary: SPR: Use Group Index Mapping (#9089)
This pull request is a temporary addition that uses the `x-now-route-params` header in serverless.

This header returns the regex groups with indexes, not their named variants.
As a result, we must use the getRouteMatcher utility to reverse this into Next.js' expected names.

Since this got complex, I've added a test for it. We should probably remove this behavior sooner than later.
2019-10-15 16:30:10 -04:00
Joe Haddad
c77338bd31
Temporary: Add Support for Now Platform Headers (#9085) 2019-10-15 14:44:50 -04:00
Alex Castle
3263af513e Update framework chunk test regex to not select nested dependencies (#9012)
* Update framework chunk test regex to not select nested dependencies

* Update webpack-config.ts
2019-10-14 14:02:11 -04:00
Joe Haddad
58cc1d3be4
Remove static optimization from message (#9045)
* Remove static optimization from message
This check does not pertain to automatic static optimization.

Closes https://github.com/zeit/next.js/issues/9042

* Update help message
2019-10-11 10:39:38 -04:00
Joe Haddad
de670b3834
Do Not Rely on Module State (#8968)
* Do Not Rely on Module State

* Update storage.ts
2019-10-10 13:18:07 -04:00
JJ Kasper
ac42beae86 Add buildId to SPR data routes (#8929)
* Add buildId to SPR data routes

* Update buildId replace in serverless loader

* Use new RegExp and add comment

* Apply suggestions from code review

Co-Authored-By: Joe Haddad <joe.haddad@zeit.co>

* Test to ensure client transition and handle / data route
2019-10-10 13:07:50 -04:00
JJ Kasper
e5202ffb24
Add CSS fixture for src dir (#9001)
* Add CSS fixture for src dir

* Revert relative customAppFile dir and update tests
2019-10-09 10:41:49 -05:00
Yamagishi Kazutoshi
32633c83dd Add src directory support for global CSS (#8999) 2019-10-08 18:48:09 -05:00
Joe Haddad
afaff59f96
Monkeypatch @zeit/next-css@0.2.1-canary.4 (#8996) 2019-10-08 14:28:15 -04:00
JJ Kasper
5cd0b0c40f
Update resetting log for spinners (#8995) 2019-10-08 11:33:51 -05:00
Joe Haddad
023863d975
Revert "Remove config export (#8895)" (#8982)
This reverts commit 67f7cf5627.
2019-10-07 13:22:47 -04:00
JJ Kasper
e2d713f93e De-experimentalize the public/ folder (#8661)
* Remove experimental.publicDirectory config

* Error when public is set as an output dir

* Remove experimental.publicDirectory checks

* Update publicFiles checking in next build
2019-10-06 13:44:03 +02:00
Joe Haddad
e2ca0ac0e8
Fix Legacy CSS Modules on the Server (#8970)
CSS Modules run their loader on the server, so we need to patch both variants of the webpack configuration.
2019-10-04 22:53:14 -04:00
Joe Haddad
c9d9ff6a8b
Informative Error for Invalid Global CSS (#8958)
* Informative Error for Invalid Global CSS
This adds a helpful error message with a (basic) err.sh link for invalid Global CSS usage.

We'll want to expand on this topic more and offer alternatives when CSS Modules support lands.

* Update expected error message
2019-10-04 11:55:18 -04:00
Joe Haddad
d299811bfa
Convert Export to TypeScript (#8965)
This pull request converts Next.js' export CLI command to use TypeScript. This is useful for upcoming changes.
2019-10-04 11:26:44 -04:00
Joe Haddad
3f51f0ed80
Add support for CSS Module patching (#8957) 2019-10-03 20:01:40 -04:00
Joe Haddad
89cf68dd1c
Also patch standalone usage of @zeit/next-css (#8950) 2019-10-03 13:10:42 -04:00
Joe Haddad
50bd10f5f8
Use Better Telemetry Directory (#8942)
* Use Better Telemetry Directory
So, as it turns out, storing in `node_modules` is a bad idea.

Both npm and Yarn will remove additional files when you run `npm install` or `yarn install`.

Instead, we'll store this inside of Next.js' `distDir`. This should also be cached by users, if it's not, it probably won't be any worse as compared to `node_modules`.

* Fix directory name

* Fix build setup

* Record when export session is started

* Move more into branch
2019-10-03 10:21:15 -04:00
Joe Haddad
955ea42288
Monkey patch next-sass and next-less (#8944)
* Monkey patch `next-sass` and `next-less`
These two Next.js plugins use poor webpack practices: they define plugins without resolving themselves.

As a result, the resolution root is unknown by webpack and you get into package hoisting bugs.

To fix this, we emulate the logic these packages should've performed themselves on a best-effort basis.

* Add comments explaining the monkey patch

* Fix comment

* Update packages/next/build/webpack-config.ts

Co-Authored-By: Tim Neutkens <tim@timneutkens.nl>
2019-10-03 10:08:49 -04:00
Joe Haddad
40b0b9b958
Reduce Timeframe That FOUC Styles Are Active (#8937)
* Show content as soon as <style> tags are added

* Add fallback removal

* Add test for when unused

* Ensure the function is ES5 compatible

* IE support

* Test it works on broken pages
2019-10-02 19:08:19 -04:00
Joe Haddad
67f7cf5627
Remove config export (#8895)
* Remove `config` export
This removes the `config` export instead of all exports.

Reverts #8889 (but with fixed behavior)

* Add test to ensure config object is dropped from client-bundle
2019-10-02 18:49:56 -04:00
Joe Haddad
29c1b93c89
s/Automatic Prerendering/Automatic Static Optimization/ (#8940)
* s/Automatic Prerendering/Automatic Static Optimization/

* Update more links
2019-10-02 18:03:00 -04:00
Joe Haddad
294f835592
Add srcRoute attribute to SPRv2 Manifest (#8928)
* Add new `srcRoute` attribute to SprRoute

* Update prerender manfiest test snapshot

* Fix types
2019-10-02 09:28:38 -04:00
Joe Haddad
afa73ae46b
Update Prerender Manifest (#8918)
* Update Prerender Manifest

* Fix typescript
2019-09-30 22:08:01 -04:00
JJ Kasper
6312a49e77 Don't remove path in page-config plugin (#8889) 2019-09-28 14:14:43 +02:00
Joe Haddad
296cfacd12
Add SPR Dynamic Routes to Manifest (#8885)
* Add SPR Dynamic Routes to Manifest
This adds dynamic routes for SPR pages to the prerender manifest so we can configure the Now Builder to handle these routes as SPR routes. Otherwise, they're treated like normal `getInitialProps` pages.

* Fix types
2019-09-27 16:34:37 -04:00
JJ Kasper
2ae475e07c SPR follow ups (#8846)
* Add revalidate header and error when invalid
object from getStaticProps

* Make sprCache no-op in dev mode

* Update packages/next/next-server/server/next-server.ts

* Update tests for fixes

* Update getStaticProps error and add test

* Update manifest test

* Add validating revalidate value

* Apply suggestions from code review

Co-Authored-By: Joe Haddad <joe.haddad@zeit.co>

* Change from error to warning high revalidate value
2019-09-25 11:29:21 -04:00
JJ Kasper
fd50e51e2a
Remove extra build logs (#8839) 2019-09-24 11:37:03 -05:00
JJ Kasper
a8e3b02236 Add src directory support (#8735)
* Add find-pages-dir

* Add support for src directory

* Add test for pages dir preference

* Update comment
2019-09-24 17:15:14 +02:00
Maël Nison
62fce6f572 TS / PnP compatibility (#8744)
* Fixes PnP + TS support

* Uses import on the resolved TS path (since it's not a dep)

* Fixes TS
2019-09-24 14:54:52 +02:00
JJ Kasper
85e720a092 Add experimental SPR support (#8832)
* initial commit for SPRv2

* Add initial SPR cache handling

* update SPR handling

* Implement SPR handling in render

* Update tests, handle caching with serverless next
start, add TODOs, and update manifest generating

* Handle no prerender-manifest from not being used

* Fix url.parse error

* Apply suggestions from code review

Co-Authored-By: Joe Haddad <joe.haddad@zeit.co>

* Replace set with constants in next-page-config

* simplify sprStatus.used

* Add error if getStaticProps is used with getInitialProps

* Remove stale TODO

* Update revalidate values in SPR cache for non-seeded routes

* Apply suggestions from code review

* Remove concurrency type

* Rename variable for clarity

* Add copying prerender files during export

* Add comment for clarity

* Fix exporting

* Update comment

* Add additional note

* Rename variable

* Update to not re-export SPR pages from build

* Hard navigate when fetching data fails

* Remove default extension

* Add brackets

* Add checking output files to prerender tests

* Adjust export move logic

* Clarify behavior of export aggregation

* Update variable names for clarity

* Update tests

* Add comment

* s/an oxymoron/contradictory/

* rename

* Extract error case

* Add tests for exporting SPR pages and update
/_next/data endpoint to end with .json

* Relocate variable

* Adjust route building

* Rename to unstable

* Rename unstable_getStaticParams

* Fix linting

* Only add this when a data request

* Update prerender data tests

* s/isServerless/isLikeServerless/

* Don't rely on query for `next start` in serverless mode

* Rename var

* Update renderedDuringBuild check

* Add test for dynamic param with bracket

* Fix serverless next start handling

* remove todo

* Adjust comment

* Update calculateRevalidate

* Remove cache logic from render.tsx

* Remove extra imports

* Move SPR cache logic to next-server

* Remove old isDynamic prop

* Add calling App getInitialProps for SPR pages

* Update revalidate logic

* Add isStale to SprCacheValue

* Update headers for SPR

* add awaiting pendingRevalidation

* Dont return null for revalidation render

* Adjust logic

* Be sure to remove coalesced render

* Fix data for serverless

* Create a method coalescing utility

* Remove TODO

* Extract send payload helper

* Wrap in-line

* Move around some code

* Add tests for de-duping and revalidating

* Update prerender manifest test
2019-09-24 10:50:04 +02:00
Joe Haddad
8d765b0209
Enable Experimental CSS Source Maps (#8805)
Source maps should be enabled in development so that original styles can be inspected.
This is in-line with other Next.js behavior (source maps in dev).
2019-09-19 14:38:12 -04:00
Janicklas Ralph
deeaa9230f Update page sizes displayed on build (#8777)
* Fixing page sizes displayed during build

* Adding comments

* Update variable name

* Fixed support for modern mode

* Remove braces

* Memoize fs.stat result

* Memoize fs.stat result
2019-09-19 11:16:51 -05:00
Joe Haddad
db7d7c7dfa
Add Experimental CSS Before Anchor (#8803)
This simplifies the CSS insert function and fixes its edge cases around nextSibling by inserting before the anchor instead of after it.
2019-09-19 11:37:47 -04:00
Luc
9b0c641b25 Insert <style> tags after anchor element (#8795)
* insert css *after* noscript tag in dev mode

* use arrow function
2019-09-19 10:53:32 -04:00
Joe Haddad
ed84bee503
Fix Experimental CSS Ordering (#8790)
* Fix CSS Ordering
This fixes CSS ordering between development and production.

Before this change, globally imported CSS would come _after_ `<style jsx global>` in development, but _before_ in production.

After this change, it'll always be applied before.

* Move to correct element

* Add tests

* Fix obnoxious indents

* Update test/integration/css/fixtures/with-styled-jsx/pages/index.js

Co-Authored-By: JJ Kasper <jj@jjsweb.site>
2019-09-18 20:18:41 -04:00
Joe Haddad
b4d349e6c1
Reduce Install Size (#8788)
* Reduce Install Size
This should shave a decent amount off our install size.

* Fix CSS source map emitting

* Fix generation

* Enable source maps for testing purposes

* Disable double comment

* Fix test regex
2019-09-18 13:59:46 -04:00
Joe Haddad
2612b48e3f
Update webpack typings (#8783)
This is in preparation of a new plugin.
2019-09-18 11:24:37 -04:00
Joe Haddad
65358b7a33
Global CSS Support (#8710)
* Global CSS Support

* Fix webpack configuration

* oneOf rule isn't necessary yet

* Adjust CSS chunk naming

* Begin testing CSS behavior

* Add another test TODO

* Replace null-loader with ignore-loader

* Turn on chunks for new CSS feature

* Fix multi test suite

* Test CSS import order

* Test style HMR

* Test CSS compilation

* Test compilation and prefixing together

* Verify CSS styling works for Development and Production

* Add missing TODO

* Remove unnecessary test

* Adjust TODO message

* Hide page until React hydrates

* Revert "Hide page until React hydrates"

This reverts commit 898d4e0ee547b003d5790e2b11476740d645b907.

* Hide FOUC during development

* Test CSS imports

* Update tests TODO

* Add fixture for url() test

* Test `file-loader` support in CSS files

* Use a simple variant of cssnano

* Self-import

* Undo bundling

* Implement suggestion
2019-09-17 16:05:20 -04:00
JJ Kasper
b210133907 Show dots for non-TTY (#8771) 2019-09-17 13:22:51 -04:00
JJ Kasper
129e32f8ad
Fix windows paths mismatching for type errors (#8766) 2019-09-16 21:30:09 -05:00
JJ Kasper
4e9e51035e Match public files priority in dev (#8641)
* Match public files priority in dev

* Remove un-needed old public file handling

* Run public file priority test for non-dev also

* Make sure to enable publicDirectory

* Add checking for conflicting pages in dev and during build

* Add error for public dir middleware conflict

* Add err.sh for _next conflict

* Move up public dir conflict checking

* Only run _next conflict check in dev when path contains it
2019-09-16 23:06:30 +02:00
JJ Kasper
204028d6ab Update build feedback with dots indicating activity (#8382)
* Add progress for analyzing and auto-prerendering

* Add typing for tty-aware-progress and use stdout

* Add fancier spinners

* Update spinner and add handling for logs while spinning

* Remove un-needed types package

* Remove progress and combine analyzing/prerendering messages
2019-09-16 17:37:00 +02:00
JJ Kasper
fe7c7342c7 Add link to docs for prerender indicator and allow disabling (#8610)
* Add link to docs for prerender indicator and allow disabling

* Fix lint error from example

* Disable by default when electron is detected

* Add button to dismiss indicator for session

* Update disabling indicator in electron
2019-09-15 23:18:11 +02:00
Joe Haddad
d031cf64df
Ensure requests are resolved as directories (#8742)
* Ensure requests are resolved as directories
`resolveRequest` will strip down to baseDir if there's no trailing slash as it assumes you passed a file.

* Disable telemetry for PR Stats
2019-09-14 17:41:05 -04:00
Joe Haddad
cbd427bf3c
Document the intended behavior of our externals (#8741)
This fully annotates our externals code to explain how it should be functioning. This will be useful as tests cases are made to ensure this is working correctly.
2019-09-14 16:58:45 -04:00
Maël Nison
9770d192f2 Prevents externalizing non-hoisted packages (#8739) 2019-09-14 16:12:25 -04:00
Joe Haddad
fb83462713
Externalize experimental package (#8731)
* Add missing dependency

* Ignore prepass for Next.js internal

* Revert "Add missing dependency"

This reverts commit 9ef0030b56255577364ff7cab46f513216a290ae.
2019-09-13 12:38:25 -04:00
Joe Haddad
eb8c11bbda
Organize webpack configuration imports (#8711)
This PR simply organizes the webpack config imports.
2019-09-11 16:41:29 -04:00
Joe Haddad
55369051f5
Warn build on duplicate pages (#8646)
* Fail build on duplicate pages
This will fail the `next build` command when a duplicate page is found.
In development, we'll emit a warning instead of crashing the dev server.

* Add test for warning in development

* Only issue a warning

* Fix production test

* Fix development test

* Remove useless arg

* Warn in development, too
2019-09-11 14:26:10 -04:00
JJ Kasper
5a0dcbc95b Update pages-loader to return one value (#8629)
* Update pages-loader to return one value

* de-dupe page mod update also
2019-09-11 13:21:10 -04:00
Joe Haddad
fcadad9960
TypeScript report on active pages only (#8703)
* TypeScript report on active pages only
The TypeScript integration needs to report on active pages only.
When inactive pages are reported, they block the compilation and prevent the user from fixing the error (because the file isn't watched).

We cannot add the file to the webpack watcher because the compilation has already been sealed.

* Remove TODO message

* Test that inactive pages are not type checked
2019-09-11 13:06:48 -04:00
Maël Nison
9fa8baa03a Uses the PnP API when available (#8668)
* Uses the PnP API when available

* Moves the resolution into an helper

* Update packages/next/lib/resolve-request.ts

Co-Authored-By: Joe Haddad <joe.haddad@zeit.co>

* Apply Prettier
2019-09-09 11:47:42 -04:00
Joe Haddad
93d6a670fe
Resolve externals using webpack's context (#8669) 2019-09-08 13:53:33 -04:00
Maël Nison
d3c1731c09 Adds the PnP plugin by default (#8653)
* Adds the PnP plugin by default

* Covers loaders

* Fixes linting
2019-09-06 09:49:38 -04:00
Joe Haddad
6e77c071c7
Update Next.js Telemetry Event Shapes (#8628)
* Update Next.js Telemetry Event Shapes

* Force value as-is
2019-09-04 20:31:35 -04:00
Tim Neutkens
2ba352da39 Move next-server back into next package (#8613)
* Initial move

* Make emitting work

* Update paths

* Remove leftover files

* Add correct externals configuration

* Import correct path

* Update path to work with ts-server test

* Update lib directory

* Compile next-server/lib
2019-09-04 10:00:54 -04:00
JJ Kasper
fbf784d76f Add data-ampdevmode attribute for AMP scripts (#8524)
* Add data-ampdevmode attribute

* Apply suggestions from code review

Co-Authored-By: Joe Haddad <joe.haddad@zeit.co>
2019-09-03 11:11:22 -04:00
Joe Haddad
ffc205ba8c
Use URL-friendly chunk names (#8609)
* Use URL-friendly chunk names

* Fix example linting
2019-09-03 10:55:48 -04:00
Joe Haddad
67e7753c85
Fix serverless chunking (#8569)
* Fix Serverless Chunking

* Remove old test & environment variable

* Update serverless trace test case
2019-08-30 07:26:30 -04:00
Joe Haddad
1f4e34ca00
Anonymous Telemetry (#8529)
* Add anonymous telemetry

* Fix types

* Remove semver package

* Rename build time variable

* Track CSS-in-JS solutions

* Single retry and 5s timeout
2019-08-29 12:43:06 -04:00
Jason Miller
1b6e455807 Add modern-preset Babel option (#8521)
* Add `modern-preset` Babel option

* fix test failure

* prefix configuration option with "experimental-"

* fix issues noted by @janicklas-ralph
2019-08-27 17:20:07 -04:00
Sebastian Silbermann
bb0ccd9a4d Specify loader paths for PnP support (#8531)
* fix(next): Loader not found using yarn v2

* Use Object.fromKeys pattern instead
2019-08-27 16:37:47 -04:00
JJ Kasper
f81b6d56e0 Replace worker-farm with jest-worker (#8496)
* Replace worker-farm with jest-worker

* Apply suggestions from code review

Co-Authored-By: Joe Haddad <joe.haddad@zeit.co>

* Remove semaphores on top of jest-worker, unwind
terser worker, and remove extra error log
2019-08-24 14:55:42 -04:00
JJ Kasper
674ba17211
Update prerender-manifest structure (#8497) 2019-08-23 16:17:40 -05:00
Alex Castle
3970a26b92 Tweaks and test for library chunks fixes (#8482)
* Adjust lib chunk naming algorithm and prevent duplicate react-dom

* Remove alias for react-dom and update separator replacement logic

* Add comment to webpack-config

* Add integration test for react-dom duplication

* Switch to using hash for lib chunk names

* remove extra file from PR

* Remove another extraneous change

* Remove test based on lib chunk name

* Update index.test.js
2019-08-23 10:28:48 -04:00
JJ Kasper
56a134409c Debug TypeScript test suite (#8476)
* Tweak typescript test suite

* Revert "Tweak typescript test suite"

This reverts commit 9e0108da7c70e7ae45b412b60c07162383de65f3.

* Make sure HMR connection isn't being closed
while testing

* Update to not re-use NODE_ENV

* Break up/rework TypeScript test suite

* bump
2019-08-22 16:34:24 -04:00
Sojin Park
7c0ac82264 Fix bug in hook destructuring optimization when ignoring array elements (#8455)
* Fix bug in hook destructuring optimization when ignoring array elements

* Add test cases
2019-08-22 11:21:34 -04:00
Alex Castle
3896cbe712 Adjust lib chunk naming algorithm and prevent duplicate react-dom (#8450)
* Adjust lib chunk naming algorithm and prevent duplicate react-dom

* Remove alias for react-dom and update separator replacement logic

* Add comment to webpack-config
2019-08-22 10:46:11 -04:00
Ran Yitzhaki
c3b18fdeaa Fix a broken link in webpack config (#8456)
* Fix a broken link in webpack config

* Update test
2019-08-21 11:58:31 -04:00
JJ Kasper
9c8aaf9d4b Fix build-manifest not removing _app files for modern (#8447) 2019-08-20 15:32:03 -04:00
Jason Miller
8bd2e433de Initial optimizeLibraries experimental flag (#8345)
* Add experimental optimizeLibraries flag, currently prunes Moment.js locales

* expose moment for use in assertion

* try with the same setup as the production integration test

* Apply optimiztaions in dev and on server so they're consistent.

* fix build (oh dear)

* Update index.test.js

* Rename flag to future.excludeDefaultMomentLocales

* Adjust impl
2019-08-20 15:19:45 -04:00
Joe Haddad
5ad0ea8e5b
Remove __NEXT_REPLACE__BUILD_ID__ workaround (#8445)
We no longer need this because we don't run terser on serverless bundles.

---

Closes https://github.com/zeit/next.js/issues/8436
2019-08-20 12:38:14 -04:00
Joe Haddad
847e892d71
Remove Flying Shuttle experiment (#8433)
* Remove Flying Shuttle experiment

* Remove more old tests

* Remove minify loader
2019-08-20 11:07:57 -04:00
Joe Haddad
df4f600291
🗜 Optimize client-side routing manifest (#8429)
* Optimize client-side routing manifest

* Turn on granularChunks for tests

* Add row for build manifest

* Hack it
2019-08-20 02:28:09 -04:00
Maël Nison
a8aa15af11 Adds basic support for PnP (#8427)
* Adds basic support for PnP

* Update preset.ts

* Update next-babel-loader.js
2019-08-19 23:39:07 -04:00
William
ec95927e14 Fix dynamic APIs with query params (#8386)
* Fix dynamic APIs with query params

If you define a dynamic API such as

```
pages/
  api/
    [id].js
```

This api becomes available at `/api/[id]`. If you send a request with
a query parameter the value of `req.query.id` will include the query
string as well as the path parameter.

E.g. the request to `/api/2?test=123` will result in `req.query`
being

```javascript
{
  id: "2?test=123",
  test: "123",
}
```

instead of

```javascript
{
  id: "2",
  test: "123",
}
```

* Fix url parse in serverless loader

* Add serverless test
2019-08-19 13:19:39 -04:00
Tim Neutkens
46c4f20cd3
Add custom profiler / tracer (#8378)
* Add custom profiler / tracer

This captures both client/production builds and everything before and after is cpu profiled, which makes sure that the whole process instead of just webpack is included in the final report.

* Update tests

* Update profiling-plugin.js

* Rename profiling-plugin.js to profiling-plugin.ts

* Update profiling-plugin.ts

* Update and rename profiling-plugin.ts to profiling-plugin.js

* Update webpack-config.ts

* Update profiling-plugin.js

* Add types

* Add missing type

* Add back TypeScript linting

* Remove tracing-js
2019-08-18 21:45:39 +02:00
Jason Miller
d8fe224951 Hook destructuring optimization (#8381)
* Add hook destructuring optimization

* oops, accidentally included loose mode

* inline hook destructuring optimization plugin

* fix test nesting

* fix lockfile

* allow any react hook

* Add page to stats-app with hooks
2019-08-15 18:08:06 -04:00
Jason Miller
cfd6080435 Feature: Add transparent JSX optimization (#8350)
* 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.
2019-08-15 17:07:34 -04:00
Joe Haddad
3c611822ab
Create a unique instance of transform-define (#8371) 2019-08-14 14:10:55 -04:00
Joe Haddad
5a8ed815fc
Define typeof window for application code only (#8355) 2019-08-13 22:02:53 -04:00
JJ Kasper
d9abbaded1 Remove experimental async-to-promises code (#8353) 2019-08-13 16:04:17 -04:00
Lukáš Huvar
7e1d54cc09 Add warning for disabled minification during build (#8337)
* Add warning for disabled minification

* Adding err.sh

* Apply suggestions from code review

Co-Authored-By: Joe Haddad <timer150@gmail.com>

* Remove example

* Update packages/next/build/index.ts

Co-Authored-By: Joe Haddad <timer150@gmail.com>

* Update index.test.js
2019-08-12 23:13:12 -04:00
Alex Castle
3b31f957a1 Use 'initial' setting for SplitChunksPlugin (#8293)
* Use 'initial' setting for SplitChunksPlugin

* Initial chunking integration test shell

* Create integration tests for granular chunks build output
2019-08-12 20:35:33 -04:00
Joe Haddad
6b516f6c84
Remove accidental support for invalid JavaScript (#8077)
* Remove accidental support for invalid JavaScript
Next.js inadvertently supported users mixing ES Modules and CommonJS due to a Babel bug that was fixed in v7.
This removes the hack in favor of the new Babel `sourceType` feature.

**This will result in broken code for users who relied on this non-standard conforming behavior.**

* Fix comment

* Toggle feature behind modern flag
2019-08-12 00:10:12 -04:00
JJ Kasper
77c5e36ba7 Escape output names for modern bundles to prevent replacing (#8232)
* Escape output names for modern bundles

* Update escaping for modern bundle
2019-08-11 23:32:18 -04:00
JJ Kasper
fc7e235f2c Followup optimizations for new experimentalPrerender (#8287)
* Add checking for hybrid AMP during static check

* Update to always hit server for prerender data

* Add removing of SPR code when not used

* Add checking for hybrid AMP during static check

* Update to always hit server for prerender data

* Add removing of SPR code when not used

* Update dead code elimination
2019-08-11 21:56:57 -04:00
Tim Neutkens
2b62c33f25
Only add flying-shuttle code when enabled (#8330)
Follow-up of #7536, small optimization / code removal when the feature is not enabled.
2019-08-12 00:03:11 +02:00
Steven Sinatra
5b1150352f Add info about removing @zeit/next-typescript on .babelrc (#8321) 2019-08-11 13:09:01 +02:00
JJ Kasper
1db69188ed Remove cache clearing from static-checker (#8290) 2019-08-08 21:52:24 -04:00
Alex Castle
3e8b36e879 Experimental: Granular build chunking (#7696)
* Refactor SplitChunksPlugin configs and add experimental chunking strategy

* Use typeDefs for SplitChunksConfig

* Modify build manifest plugin to create runtime build manifest

* Add support for granular chunks to page-loader

* Ensure normal behavior if experimental granularChunks flag is false

* Update client build manifest to remove iife & implicit global

* Factor out '/_next/' prepending into getDependencies

* Update packages/next/build/webpack-config.ts filepath regex

Co-Authored-By: Jason Miller <developit@users.noreply.github.com>

* Simplify dependency load ordering in page-loader.js

* Use SHA1 hash to shorten filenames for dependency modules

* Add scheduler to framework cacheGroup in webpack-config

* Update page loader to not duplicate script tags with query parameters

* Ensure no slashes end up in the file hashes

* Add prop-types to framework chunk

* Fix issue with mis-attributed events

* Increase modern build size budget--possibly decrement after consulting with @janicklasralph

* Use module.rawRequest for lib chunks

Co-Authored-By: Daniel Stockman <daniel.stockman@gmail.com>

* Dasherize lib chunk names

Co-Authored-By: Daniel Stockman <daniel.stockman@gmail.com>

* Fix typescript errors, reorganize lib name logic

* Dasherize rawRequest, short circuit name logic when rawRequest found

* Add `scheduler` package to test regex

* Fix a nit

* Adjust build manifest plugin

* Shorten key name

* Extract createPreloadLink helper

* Extract getDependencies helper

* Move method

* Minimize diff

* Minimize diff x2

* Fix Array.from polyfill

* Simplify page loader code

* Remove async=false for script tags

* Code golf `getDependencies` implementation

* Require lib chunks be in node_modules

* Update packages/next/build/webpack-config.ts

Co-Authored-By: Joe Haddad <timer150@gmail.com>

* Replace remaining missed windows compat regex

* Trim client manifest

* Prevent duplicate link preload tags

* Revert size test changes

* Squash manifest size even further

* Add comment for clarity

* Code golfing 🏌️‍♂️

* Correctly select modern dependencies

* Ship separate modern client manifest when module/module enabled

* Update packages/next/build/webpack/plugins/build-manifest-plugin.ts

Co-Authored-By: Joe Haddad <timer150@gmail.com>

* Remove unneccessary filter from page-loader

* Add lookbehind to file extension regex in page-loader

* v9.0.3

* Update examples for Apollo with AppTree (#8180)

* Update examples for Apollo with AppTree

* Fix apolloClient being overwritten when rendering AppTree

* Golf page-loader (#8190)

* Remove lookbehind for module replacement

* Wait for build manifest promise before page load or prefetch

* Updating modern-only chunks inside the right entry point

* Fixing ts errors

* Rename variable

* Revert "Wait for build manifest promise before page load or prefetch"

This reverts commit c370528c6888ba7fa71162a0854534ed280224ef.

* Use proper typedef for webpack chunk

* Re-enable promisified client build manifest

* Fix bug in getDependencies map

* Insert check for granularChunks in page-loader

* Increase size limit temporarily for granular chunks

* Add 50ms delay to flaky test

* Set env.__NEXT_GRANULAR_CHUNKS in webpack config

* Reset size limit to 187

* Set process.env.__NEXT_GRANULAR_CHUNKS to false if selectivePageBuilding

* Update test/integration/production/test/index.test.js

Co-Authored-By: Joe Haddad <timer150@gmail.com>

* Do not create promise if not using chunking PR
2019-08-08 13:14:33 -04:00
Jason Miller
fa5be4971a Bugfix: Babel targets value can be a String (#8268)
* Fix modern SSR build when Babel configuration uses a String value for "targets". Fixes #8255.

* Add custom babelrc integration tests
2019-08-08 15:38:51 +02:00
JJ Kasper
61d151ccd7 Handle backslashes in exportedFiles (#8277) 2019-08-07 11:27:01 -04:00
Sebastian Benz
91629a8e72 Migrate amp-toolbox-optimizer to @ampproject/toolbox-optimizer (#8275)
* migrate amp-toolbox-optimizer to @ampproject/toolbox-optimizer

* Add updated yarn.lock
2019-08-07 10:47:46 -04:00
JJ Kasper
ca13752e24
Implement experimentalPrerender option (#7983)
* Revert "Remove Old Prerender Implementation (#8218)"

This reverts commit 2ab300dd81.

* Add contentHandler for page config

* Rename config from contentHandler to re-use
experimentalPrerender

* Remove un-needed changes

* Replace backslashes for manifest

* Update manifest output format

* Make prerender: true enable SPR behavior and update
to merge prerender-manifest for flying-shuttle

* Fix output path for / prerender file

* Add dynamic routes to test suite

* Add generating and previewing of skeletons
for prerendered dynamic routes

* remove inline prerender option

* update to not replace getInitialProps which allows
nested getInitialProps and add query when fetching prerender

* Apply suggestions from code review

Co-Authored-By: Joe Haddad <timer150@gmail.com>

* Remove legacy prerender option

* Apply suggestions from review

* Apply more suggestions from review

* Apply suggestions from code review

Co-Authored-By: Joe Haddad <timer150@gmail.com>

* Add handling of error when parsing json

* Update handling of moving exported pages

* Rename nextPreviewSkeleton to _nextPreviewSkeleton

* bump
2019-08-06 15:26:01 -05:00
Joe Haddad
b31c296730
Experimental: Serverless Trace target (#8246)
* Experimental: Serverless Trace target
The Serverless Trace target produces Serverless-handler wrapped entrypoints, but does not bundle all of `node_modules`.

This behavior increases bundling performance to be more akin to `target: 'server'`.

This mode is expected to be used with smart platforms (like [ZEIT Now](https://zeit.co/now) that can trace a program to its minimum dependencies.

* Use more generic variables

* Add asset relocator for production mode of serverless trace

* Verify Firebase compatiblity

* Revert "Add asset relocator for production mode of serverless trace"

This reverts commit 8404f1dcf28b60edab41a56c94b38dcd3fddec20.

* Add serverless trace tests

* Add _isLikeServerless helper

* Make constants

* Fix export

* Update packages/next-server/server/config.ts

Co-Authored-By: JJ Kasper <jj@jjsweb.site>

* Use a global helper for is like serverless

* Update import for isTargetLikeServerless

* Update packages/next/build/index.ts

Co-Authored-By: JJ Kasper <jj@jjsweb.site>
2019-08-05 18:26:20 -04:00
Joe Haddad
2ab300dd81
Remove Old Prerender Implementation (#8218)
* Remove Prerender Implementation

* Fix PageConfig

* Fix next server

* Fix two more files

* Fix render

* Fix render

* Try to fix up page config

* Correct build file

* Switch back static checker

* Turn stuff back

* Add missing newline

* Revert changes

* Add missing newline

* Fix types
2019-08-02 10:28:03 -04:00
Joe Haddad
c61f6c1200
Test environment code should target Node (#8181) 2019-07-30 16:28:48 -04:00
Lukáš Huvar
3e03fee278 Fix build only server-side /api/index.js (#8167)
* Build error for index API routes

* Fix server build
2019-07-30 13:52:43 +01:00
Joe Haddad
df213f7aab
Include scheduler in React bundle (#8164) 2019-07-29 13:42:57 -04:00
Joe Haddad
91f60cdadf
refactor(webpack): extract splitChunksConfig (#8161) 2019-07-29 12:19:31 -04:00
Piotr Tomasik
78775954f2 fix regex to not match any string with double underscore (#8153)
* fix regex to not match any string with double underscore

* add test for __ in env name and make existing test more descriptive.
2019-07-29 08:17:10 +01:00
Lukáš Huvar
bbcb448e87 Fix index.js for API routes (#8112)
This fixes the problem with `/pages/api/index.js` not creating serverless function. Fixes #8111
2019-07-25 17:39:29 +00:00
Janicklas Ralph
f4e6149d1c Experimental module/nomodule support (#7704)
* Module/nomodule implementation based on RFC 7563

* Remove comment

* Fixing issue with building amp pages

* Fixing test cases for serverless mode

* Adding safari 10 nomodule fix. Preloading modern js by default

* Fixing size-limit integration test

* Bug fix

* Adding testcase for modern build

* Trigger rebuild

* Setting default crossOrigin value

* Moving modern config option inside experimental flag

* Adding nomodule attribute to safari-fix script

* Changing safari10NomoduleFix default value to true

* Removing safari-fix flag

* Changing .es6 to .module

* Disable modern default

* Removing default crossOrigin value. Setting modern flag to false by default. Fixed test cases

* Remove confusing defaults and mark required instead

* Adjust blacklist

* Move behavior of page marking

* Fixing childCompiler errors not being captured

* Tweak names

* Revert

* whoops

* Fixing bug with page-loader.js

* Changing modern babel cache name

* Rename helper

* Iterate over both bundles

* Correctly clamp bundle sizes

* Revert test

* Add modern mode tests

* Fix test

* test

* test2
2019-07-24 22:16:32 -04:00
Joe Haddad
aac5121466
Apply missing formatting (#8079)
* Reapply missing formatting

* Fix lint
2019-07-23 14:33:49 -04:00
Jason Miller
ab57978d18 Modern JS for SSR Bundles (#7961)
* Compile for the current version of Node.js by default when producing server builds.

* Update packages/next/build/babel/preset.ts

Co-Authored-By: Joe Haddad <timer150@gmail.com>

* Include server variation in Babel cacheKey
2019-07-22 14:36:55 -04:00
JJ Kasper
3c1355686a Handle windows backslashes when checking ssr-prepass (#8016) 2019-07-17 20:21:24 +02:00
Xinzi Zhou
9609fe453d Replace fs.exists with fs.access (#7742)
* Replace deprecated fs.exists with fs.access.

* Update packages/next/lib/file-exists.ts

Co-Authored-By: Joe Haddad <timer150@gmail.com>

* Update packages/next/lib/file-exists.ts

Co-Authored-By: Joe Haddad <timer150@gmail.com>
2019-07-16 23:01:21 -07:00
Dmitry Vasilev
4347fa4d56 Add babel option to use styled-jsx/babel-test in the preset (#7747)
* Add babel option to use styled-jsx/babel-test in the preset

* Fix the types
2019-07-16 14:23:19 +02:00
Lukáš Huvar
718a36e127 Fix build for API routes conflict pages (#7992)
* Fixes #7991

* Fix tests
2019-07-16 12:59:09 +02:00
JJ Kasper
86b6a4b6fe
Add handling for invalid page config (#7921) 2019-07-15 13:54:35 -07:00
Natalie Marleny
e68a5a793a fix: Ensure ergonomic handling of non-page in ./pages/ (#7955)
* Update autoExport wording to automatic static optimization

* Add sufficiently informative error message

- Update other Next error message for consistency

* Implement feedback - add missing character

Co-Authored-By: Lukáš Huvar <lukas@huvar.cz>

* Fix TypeScript errors

* Update test from autoExport to automatic static optimization

- Also reflect new wording of error message for readability

* Add test for handle non-page in pages

- When target: severless
2019-07-15 17:16:35 +02:00
JJ Kasper
fad4ec3958 Don't externalize ssr-prepass if added by user (#7966) 2019-07-15 16:41:53 +02:00
JJ Kasper
10614e8465 Replace windows backslashes with forward (#7942)
slashes for better handling
2019-07-13 22:24:44 +02:00
Joe Haddad
13cf664898
Add support for legacy server npm modules (#7898)
Notably, this PR fixes `faunadb` which relies on `formidable`.

n.b. `formidable` is an unmaintained legacy npm package that uses practices not compatible with the modern ecosystem.
2019-07-11 13:02:43 -04:00
JJ Kasper
41cb3b3bc0 Stop PageConfig plugin from running on non-pages (#7884)
* Add test for PageConfig

* Make sure PageConfig plugin is only run for pages
2019-07-10 15:27:11 -04:00
JJ Kasper
268ac93685 Fix placeholder values being added when exporting from serverless (#7883)
* Add testing serverless in dynamic routes suite

* Fix placeholder dynamic values being added
when exporting from serverless
2019-07-10 15:23:28 -04:00
JJ Kasper
bf7af1d16b Add default values for runtime config (#7847)
* Add default values for runtime config

* Add test to ensure default values are set
for runtime config

* Only add runtimeConfig if it's not empty

* Only add runtimeConfig if it's not empty

* Simplify default value adding

* Reduce bundle size

* remove comment changes

* Fix typos

* Add test for runtimeConfig in __NEXT_DATA__
2019-07-10 10:43:04 -04:00
Barry
1d8fa3a943 fix terminal links (cmd-click) on VSCode (#7849) 2019-07-09 19:34:20 -05:00
Joe Haddad
ab0b2cf3da
Add a test for module.exports from a page (#7842)
Closes https://github.com/zeit/next.js/issues/7835
2019-07-09 13:23:38 -04:00
JJ Kasper
30da9e075e Update to always require next/config when setting config (#7822) 2019-07-09 13:23:51 +02:00
JJ Kasper
e56573008b Fix package count being zero in some cases (#7812)
contains ignored package name
2019-07-08 20:49:51 -04:00
Lukáš Huvar
f204935251 Fix serverless loader for API routes (#7767)
* Fix serverless loader for API routes

* Only use params with dynamic routes
2019-07-07 17:45:40 -04:00
Joe Haddad
6fa17b3f15
Improve automatic prerendering warning (#7759) 2019-07-05 11:57:16 -04:00
Joe Haddad
b2a9670ca4
Make exportTrailingSlash stable (#7746) 2019-07-03 13:25:44 -04:00
Joe Haddad
7439a773b0 Nit: Change Pre-render to Prerender (#7733) 2019-07-02 22:51:12 +02:00
JJ Kasper
0ca8087565
Add prerender PageConfig option (#7699)
* Add prerender PageConfig option

* Update PageConfig type

* Add inlining of data when pre-render is set and add tests

* Update types import

* Add check for props

* Rename prerender to experimentalPrerender for now
2019-07-01 14:13:52 -07:00
Joe Haddad
5493f2e8b3
Remove Next.js debug mode (#7719) 2019-07-01 13:13:06 -04:00
Lukáš Huvar
4ad934c148 Serverless build for API routes (#7649)
* Fixes serverless target in development

* Fix serverless build

* Fix serverless build

* Add manifest test

* Better output

* Fix manifest test

* Update snapshot

* Remove snapshots
2019-07-01 12:47:11 -04:00
JJ Kasper
564eac4746
Fix styled-jsx not rendering when used in node_modules (#7697)
* Don't transpile styled-jsx in server mode

* Add test fo styled-jsx-module

* Add styled-jsx as dependency of next-server
2019-06-29 15:42:07 -07:00
JJ Kasper
356636c80f Add updated de-duping logic for next/dynamic (#7705) 2019-06-28 20:48:28 -04:00
Joe Haddad
39761e5ce7 Remove withAmp and do not expose isInAmpMode (#7690)
* Remove `withAmp` and do not expose `isInAmpMode`
This pull request removes the `withAmp` higher-order component in favor of the exported configuration object.
Retaining this backwards compatibility isn't worth the extra maintenance burden, given it hasn't been released for very long and the migration is ultra-simple.

I'm 👎 on retaining backwards compatibility just for the sake of it.

Migration example follows. I'm willing to write a codemod if reviewers feel it's necessary.

*Before*
```js
import { withAmp } from 'next/amp'

function Home() {
  return <h1>My AMP Page</h1>
}

export default withAmp(Home)
// or
export default withAmp(Home, { hybrid: true })
```

*After*
```js
export default function Home() {
  return <h1>My AMP Page</h1>
}

export const config = {
  amp: true,
  // or
  amp: 'hybrid',
}
```

* Fix { amp: 'hybrid' }

Co-Authored-By: JJ Kasper <jj@jjsweb.site>
2019-06-28 15:04:24 -07:00
Joe Haddad
3aed76fad8
Unflag Automatic Prerendering (#7666)
* Unflag Dynamic Routing

* Unflag Automatic Prerendering

* Ensure pages are lambdas for test

* Fix file check

* Fix tests

* oof

* Use lambda for document middleware test
2019-06-28 16:01:11 -04:00
JJ Kasper
7c30bf97f6
Re-add require cache clearing (#7674) 2019-06-26 12:16:54 -07:00