Skip to content

Commit

Permalink
Merge branch 'canary' into cli-create-from-example
Browse files Browse the repository at this point in the history
  • Loading branch information
merelinguist authored Feb 18, 2020
2 parents 5952dfa + b5c70e8 commit 83d19e9
Show file tree
Hide file tree
Showing 43 changed files with 205 additions and 179 deletions.
6 changes: 5 additions & 1 deletion .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,11 @@
}
},
{
"files": ["test/**/*", "examples/**/*"],
"files": [
"test/**/*",
"examples/**/*",
"packages/create-next-app/templates/**/*"
],
"rules": { "react/react-in-jsx-scope": "off" }
}
],
Expand Down
2 changes: 1 addition & 1 deletion examples/with-graphql-faunadb/scripts/setup.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ readline.question(`Please provide the FaunaDB admin key\n`, adminKey => {
privileges: [
{
resource: q.Collection('GuestbookEntry'),
actions: { read: true, write: true },
actions: { read: true, write: true, create: true },
},
{
resource: q.Index('entries'),
Expand Down
2 changes: 1 addition & 1 deletion lerna.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,5 @@
"registry": "https://registry.npmjs.org/"
}
},
"version": "9.2.2-canary.21"
"version": "9.2.3-canary.0"
}
2 changes: 1 addition & 1 deletion packages/create-next-app/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "create-next-app",
"version": "9.2.2-canary.21",
"version": "9.2.3-canary.0",
"keywords": [
"react",
"next",
Expand Down
1 change: 0 additions & 1 deletion packages/create-next-app/templates/default/pages/index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import React from 'react'
import Head from 'next/head'

const Home = () => (
Expand Down
2 changes: 1 addition & 1 deletion packages/next-bundle-analyzer/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@next/bundle-analyzer",
"version": "9.2.2-canary.21",
"version": "9.2.3-canary.0",
"main": "index.js",
"license": "MIT",
"repository": {
Expand Down
2 changes: 1 addition & 1 deletion packages/next-mdx/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@next/mdx",
"version": "9.2.2-canary.21",
"version": "9.2.3-canary.0",
"main": "index.js",
"license": "MIT",
"repository": {
Expand Down
2 changes: 1 addition & 1 deletion packages/next-plugin-google-analytics/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@next/plugin-google-analytics",
"version": "9.2.2-canary.21",
"version": "9.2.3-canary.0",
"nextjs": {
"name": "Google Analytics",
"required-env": [
Expand Down
2 changes: 1 addition & 1 deletion packages/next-plugin-material-ui/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@next/plugin-material-ui",
"version": "9.2.2-canary.21",
"version": "9.2.3-canary.0",
"nextjs": {
"name": "Material UI",
"required-env": []
Expand Down
2 changes: 1 addition & 1 deletion packages/next-plugin-sentry/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@next/plugin-sentry",
"version": "9.2.2-canary.21",
"version": "9.2.3-canary.0",
"nextjs": {
"name": "Sentry",
"required-env": [
Expand Down
2 changes: 1 addition & 1 deletion packages/next-polyfill-nomodule/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@next/polyfill-nomodule",
"version": "9.2.2-canary.21",
"version": "9.2.3-canary.0",
"description": "A polyfill for non-dead, nomodule browsers.",
"main": "dist/polyfill-nomodule.js",
"license": "MIT",
Expand Down
2 changes: 0 additions & 2 deletions packages/next/build/babel/plugins/react-loadable-plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,6 @@ export default function({ types: t }: { types: typeof BabelTypes }): PluginObj {
callExpression.node.arguments.push(t.objectExpression([]))
}
// This is needed as the code is modified above
// TODO: remove ignore statement
// @ts-ignore
args = callExpression.get('arguments')
loader = args[0]
options = args[1]
Expand Down
6 changes: 2 additions & 4 deletions packages/next/build/babel/preset.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,7 @@ module.exports = (
const supportsESM = api.caller(supportsStaticESM)
const isServer = api.caller((caller: any) => !!caller && caller.isServer)
const isModern = api.caller((caller: any) => !!caller && caller.isModern)
const isPolyfillsOptimization = api.caller(
(caller: any) => !!caller && caller.polyfillsOptimization
)

const isLaxModern =
isModern ||
(options['preset-env']?.targets &&
Expand Down Expand Up @@ -155,7 +153,7 @@ module.exports = (
!isServer && [
require('@babel/plugin-transform-runtime'),
{
corejs: isPolyfillsOptimization ? false : 2,
corejs: false,
helpers: true,
regenerator: true,
useESModules: supportsESM && presetEnvConfig.modules !== 'commonjs',
Expand Down
1 change: 0 additions & 1 deletion packages/next/build/compiler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ export function runCompiler(
config: webpack.Configuration | webpack.Configuration[]
): Promise<CompilerResult> {
return new Promise(async (resolve, reject) => {
// @ts-ignore webpack allows both a single config or array of configs
const compiler = webpack(config)
compiler.run((err: Error, statsOrMultiStats: any) => {
if (err) {
Expand Down
65 changes: 15 additions & 50 deletions packages/next/build/webpack-config.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import crypto from 'crypto'
import ForkTsCheckerWebpackPlugin from 'fork-ts-checker-webpack-plugin'
import path from 'path'
// @ts-ignore: Currently missing types
import PnpWebpackPlugin from 'pnp-webpack-plugin'
import webpack from 'webpack'
import {
Expand Down Expand Up @@ -29,7 +28,6 @@ import {
} from './plugins/collect-plugins'
import { build as buildConfiguration } from './webpack/config'
import { __overrideCssConfiguration } from './webpack/config/blocks/css/overrideCssConfiguration'
// @ts-ignore: JS file
import { pluginLoaderOptions } from './webpack/loaders/next-plugin-loader'
import BuildManifestPlugin from './webpack/plugins/build-manifest-plugin'
import ChunkNamesPlugin from './webpack/plugins/chunk-names-plugin'
Expand All @@ -56,10 +54,7 @@ const escapePathVariables = (value: any) => {
: value
}

function getOptimizedAliases(
isServer: boolean,
polyfillsOptimization: boolean
): { [pkg: string]: string } {
function getOptimizedAliases(isServer: boolean): { [pkg: string]: string } {
if (isServer) {
return {}
}
Expand All @@ -70,12 +65,6 @@ function getOptimizedAliases(
const shimAssign = path.join(__dirname, 'polyfills', 'object.assign')
return Object.assign(
{},
// Polyfill: Window#fetch
polyfillsOptimization
? undefined
: {
__next_polyfill__fetch: require.resolve('whatwg-fetch'),
},
{
unfetch$: stubWindowFetch,
'isomorphic-unfetch$': stubWindowFetch,
Expand All @@ -86,13 +75,6 @@ function getOptimizedAliases(
'whatwg-fetch.js'
),
},
polyfillsOptimization
? undefined
: {
// Polyfill: Object.assign
__next_polyfill__object_assign: require.resolve('object-assign'),
'@babel/runtime-corejs2/core-js/object/assign': stubObjectAssign,
},
{
'object-assign$': stubObjectAssign,

Expand All @@ -113,6 +95,12 @@ function getOptimizedAliases(
)
}

type ClientEntries = {
'main.js': string[]
} & {
[key: string]: string
}

export default async function getBaseWebpackConfig(
dir: string,
{
Expand Down Expand Up @@ -164,7 +152,6 @@ export default async function getBaseWebpackConfig(
babelPresetPlugins,
hasModern: !!config.experimental.modern,
development: dev,
polyfillsOptimization: !!config.experimental.polyfillsOptimization,
},
},
// Backwards compat
Expand Down Expand Up @@ -197,7 +184,7 @@ export default async function getBaseWebpackConfig(
const outputPath = path.join(distDir, isServer ? outputDir : '')
const totalPages = Object.keys(entrypoints).length
const clientEntries = !isServer
? {
? ({
// Backwards compatibility
'main.js': [],
[CLIENT_STATIC_FILES_RUNTIME_MAIN]:
Expand All @@ -211,11 +198,9 @@ export default async function getBaseWebpackConfig(
),
[CLIENT_STATIC_FILES_RUNTIME_POLYFILLS]: path.join(
NEXT_PROJECT_ROOT_DIST_CLIENT,
config.experimental.polyfillsOptimization
? 'polyfills-nomodule.js'
: 'polyfills.js'
'polyfills.js'
),
}
} as ClientEntries)
: undefined

let typeScriptPath
Expand Down Expand Up @@ -263,17 +248,7 @@ export default async function getBaseWebpackConfig(
next: NEXT_PROJECT_ROOT,
[PAGES_DIR_ALIAS]: pagesDir,
[DOT_NEXT_ALIAS]: distDir,
...getOptimizedAliases(
isServer,
!!config.experimental.polyfillsOptimization
),

// Temporary to allow runtime-corejs2 to be stubbed in experimental polyfillsOptimization
...(config.experimental.polyfillsOptimization
? {
'@babel/runtime-corejs2': '@babel/runtime',
}
: undefined),
...getOptimizedAliases(isServer),
},
mainFields: isServer ? ['main', 'module'] : ['browser', 'module', 'main'],
plugins: [PnpWebpackPlugin],
Expand Down Expand Up @@ -524,11 +499,7 @@ export default async function getBaseWebpackConfig(
!res.match(/next[/\\]dist[/\\]next-server[/\\]/) &&
(res.match(/[/\\]next[/\\]dist[/\\]/) ||
// This is the @babel/plugin-transform-runtime "helpers: true" option
res.match(/node_modules[/\\]@babel[/\\]runtime[/\\]/) ||
(!config.experimental.polyfillsOptimization &&
res.match(
/node_modules[/\\]@babel[/\\]runtime-corejs2[/\\]/
)))
res.match(/node_modules[/\\]@babel[/\\]runtime[/\\]/))
) {
return callback()
}
Expand Down Expand Up @@ -652,7 +623,6 @@ export default async function getBaseWebpackConfig(
],
plugins: [PnpWebpackPlugin],
},
// @ts-ignore this is filtered
module: {
rules: [
{
Expand Down Expand Up @@ -725,9 +695,6 @@ export default async function getBaseWebpackConfig(
'process.env.__NEXT_MODERN_BUILD': JSON.stringify(
config.experimental.modern && !dev
),
'process.env.__NEXT_POLYFILLS_OPTIMIZATION': JSON.stringify(
!!config.experimental.polyfillsOptimization
),
'process.env.__NEXT_GRANULAR_CHUNKS': JSON.stringify(
config.experimental.granularChunks && !dev
),
Expand Down Expand Up @@ -902,8 +869,7 @@ export default async function getBaseWebpackConfig(
webpack,
})

// @ts-ignore: Property 'then' does not exist on type 'Configuration'
if (typeof webpackConfig.then === 'function') {
if (typeof (webpackConfig as any).then === 'function') {
console.warn(
'> Promise returned in next config. https://err.sh/zeit/next.js/promise-in-next-config'
)
Expand Down Expand Up @@ -1109,7 +1075,6 @@ export default async function getBaseWebpackConfig(
// Server compilation doesn't have main.js
if (clientEntries && entry['main.js'] && entry['main.js'].length > 0) {
const originalFile = clientEntries[CLIENT_STATIC_FILES_RUNTIME_MAIN]
// @ts-ignore TODO: investigate type error
entry[CLIENT_STATIC_FILES_RUNTIME_MAIN] = [
...entry['main.js'],
originalFile,
Expand All @@ -1122,8 +1087,8 @@ export default async function getBaseWebpackConfig(
}

if (!dev) {
// @ts-ignore entry is always a function
webpackConfig.entry = await webpackConfig.entry()
// entry is always a function
webpackConfig.entry = await (webpackConfig.entry as webpack.EntryFunc)()
}

return webpackConfig
Expand Down
6 changes: 1 addition & 5 deletions packages/next/build/webpack/loaders/next-babel-loader.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,6 @@ module.exports = babelLoader.custom(babel => {
hasModern: opts.hasModern,
babelPresetPlugins: opts.babelPresetPlugins,
development: opts.development,
polyfillsOptimization: opts.polyfillsOptimization,
}
const filename = join(opts.cwd, 'noop.js')
const loader = Object.assign(
Expand All @@ -72,7 +71,7 @@ module.exports = babelLoader.custom(babel => {
(opts.isServer ? '-server' : '') +
(opts.isModern ? '-modern' : '') +
(opts.hasModern ? '-has-modern' : '') +
(opts.polyfillsOptimization ? '-new-polyfills' : '') +
'-new-polyfills' +
(opts.development ? '-development' : '-production') +
JSON.stringify(
babel.loadPartialConfig({
Expand All @@ -95,7 +94,6 @@ module.exports = babelLoader.custom(babel => {
delete loader.hasModern
delete loader.pagesDir
delete loader.babelPresetPlugins
delete loader.polyfillsOptimization
delete loader.development
return { loader, custom }
},
Expand All @@ -110,7 +108,6 @@ module.exports = babelLoader.custom(babel => {
pagesDir,
babelPresetPlugins,
development,
polyfillsOptimization,
},
}
) {
Expand All @@ -134,7 +131,6 @@ module.exports = babelLoader.custom(babel => {

options.caller.isServer = isServer
options.caller.isModern = isModern
options.caller.polyfillsOptimization = polyfillsOptimization
options.caller.isDev = development

options.plugins = options.plugins || []
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,16 +88,17 @@ export default class WebpackConformancePlugin {
private parserHandler = (factory: compilation.NormalModuleFactory): void => {
const JS_TYPES = ['auto', 'esm', 'dynamic']
const collectedVisitors: Map<string, [NodeInspector?]> = new Map()
// Collect all intereseted visitors from all tests.
// Collect all interested visitors from all tests.
this.tests.forEach(test => {
if (test.getAstNode) {
const getAstNodeCallbacks: IGetAstNodeResult[] = test.getAstNode()
getAstNodeCallbacks.forEach(result => {
if (!collectedVisitors.has(result.visitor)) {
collectedVisitors.set(result.visitor, [])
}
// @ts-ignore
collectedVisitors.get(result.visitor).push(result.inspectNode)
;(collectedVisitors.get(result.visitor) as NodeInspector[]).push(
result.inspectNode
)
})
}
})
Expand Down
17 changes: 3 additions & 14 deletions packages/next/client/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,20 +14,9 @@ import { isDynamicRoute } from '../next-server/lib/router/utils/is-dynamic'

/// <reference types="react-dom/experimental" />

if (process.env.__NEXT_POLYFILLS_OPTIMIZATION) {
if (!('finally' in Promise.prototype)) {
// eslint-disable-next-line no-extend-native
Promise.prototype.finally = require('finally-polyfill')
}
} else {
// Polyfill Promise globally
// This is needed because Webpack's dynamic loading(common chunks) code
// depends on Promise.
// So, we need to polyfill it.
// See: https://webpack.js.org/guides/code-splitting/#dynamic-imports
if (!self.Promise) {
self.Promise = require('@babel/runtime-corejs2/core-js/promise')
}
if (!('finally' in Promise.prototype)) {
// eslint-disable-next-line no-extend-native
Promise.prototype.finally = require('finally-polyfill')
}

const data = JSON.parse(document.getElementById('__NEXT_DATA__').textContent)
Expand Down
Loading

0 comments on commit 83d19e9

Please sign in to comment.