Skip to content

Commit

Permalink
Merge branch 'canary' into test/ssg-data-err
Browse files Browse the repository at this point in the history
  • Loading branch information
ijjk authored Dec 13, 2019
2 parents 98b6ca9 + 32cb5e1 commit b44e55c
Show file tree
Hide file tree
Showing 34 changed files with 417 additions and 38 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@
"tailwindcss": "1.1.3",
"taskr": "1.1.0",
"tree-kill": "1.2.1",
"typescript": "3.7.2",
"typescript": "3.7.3",
"wait-port": "0.2.2",
"wd": "1.11.3",
"webpack-bundle-analyzer": "3.3.2"
Expand Down
2 changes: 1 addition & 1 deletion packages/create-next-app/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
"prompts": "2.1.0",
"rimraf": "3.0.0",
"tar": "4.4.10",
"typescript": "^3.5.3",
"typescript": "3.7.3",
"update-check": "1.5.3",
"validate-npm-package-name": "3.0.0"
}
Expand Down
18 changes: 18 additions & 0 deletions packages/next/build/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ import { verifyTypeScriptSetup } from '../lib/verifyTypeScriptSetup'
import {
BUILD_MANIFEST,
DEFAULT_REDIRECT_STATUS,
EXPORT_DETAIL,
EXPORT_MARKER,
PAGES_MANIFEST,
PHASE_PRODUCTION_BUILD,
PRERENDER_MANIFEST,
Expand Down Expand Up @@ -716,6 +718,22 @@ export default async function build(dir: string, conf = null): Promise<void> {
)
}

await fsWriteFile(
path.join(distDir, EXPORT_MARKER),
JSON.stringify({
version: 1,
hasExportPathMap: typeof config.exportPathMap === 'function',
exportTrailingSlash: config.exportTrailingSlash === true,
}),
'utf8'
)
await fsUnlink(path.join(distDir, EXPORT_DETAIL)).catch(err => {
if (err.code === 'ENOENT') {
return Promise.resolve()
}
return Promise.reject(err)
})

staticPages.forEach(pg => allStaticPages.add(pg))
pageInfos.forEach((info: PageInfo, key: string) => {
allPageInfos.set(key, info)
Expand Down
61 changes: 60 additions & 1 deletion packages/next/build/webpack-config.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import crypto from 'crypto'
import ForkTsCheckerWebpackPlugin from 'fork-ts-checker-webpack-plugin'
import MiniCssExtractPlugin from 'mini-css-extract-plugin'
import path from 'path'
// @ts-ignore: Currently missing types
import PnpWebpackPlugin from 'pnp-webpack-plugin'
Expand Down Expand Up @@ -35,6 +34,7 @@ import BuildManifestPlugin from './webpack/plugins/build-manifest-plugin'
import ChunkNamesPlugin from './webpack/plugins/chunk-names-plugin'
import { CssMinimizerPlugin } from './webpack/plugins/css-minimizer-plugin'
import { importAutoDllPlugin } from './webpack/plugins/dll-import'
import MiniCssExtractPlugin from './webpack/plugins/mini-css-extract-plugin'
import { DropClientPage } from './webpack/plugins/next-drop-client-page-plugin'
import NextEsmPlugin from './webpack/plugins/next-esm-plugin'
import NextJsSsrImportPlugin from './webpack/plugins/nextjs-ssr-import'
Expand Down Expand Up @@ -864,6 +864,65 @@ export default async function getBaseWebpackConfig(
}
}

function canMatchCss(rule: webpack.RuleSetCondition | undefined): boolean {
if (!rule) {
return false
}

const fileName = '/tmp/test.css'

if (rule instanceof RegExp && rule.test(fileName)) {
return true
}

if (typeof rule === 'function') {
try {
if (rule(fileName)) {
return true
}
} catch (_) {}
}

if (Array.isArray(rule) && rule.some(canMatchCss)) {
return true
}

return false
}

if (config.experimental.css) {
const hasUserCssConfig =
webpackConfig.module &&
webpackConfig.module.rules.some(
rule => canMatchCss(rule.test) || canMatchCss(rule.include)
)

if (hasUserCssConfig) {
if (webpackConfig.module?.rules.length) {
// Remove default CSS Loader
webpackConfig.module.rules = webpackConfig.module.rules.filter(
r =>
!(
typeof r.oneOf?.[0]?.options === 'object' &&
r.oneOf[0].options.__next_css_remove === true
)
)
}
if (webpackConfig.plugins?.length) {
// Disable CSS Extraction Plugin
webpackConfig.plugins = webpackConfig.plugins.filter(
p => (p as any).__next_css_remove !== true
)
}
if (webpackConfig.optimization?.minimizer?.length) {
// Disable CSS Minifier
webpackConfig.optimization.minimizer = webpackConfig.optimization.minimizer.filter(
e => (e as any).__next_css_remove !== true
)
}
}
}

// check if using @zeit/next-typescript and show warning
if (
isServer &&
Expand Down
15 changes: 13 additions & 2 deletions packages/next/build/webpack/config/blocks/css/index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import curry from 'lodash.curry'
import MiniCssExtractPlugin from 'mini-css-extract-plugin'
import path from 'path'
import webpack, { Configuration } from 'webpack'
import MiniCssExtractPlugin from '../../../plugins/mini-css-extract-plugin'
import { loader } from '../../helpers'
import { ConfigurationContext, ConfigurationFn, pipe } from '../../utils'
import { getCssModuleLocalIdent } from './getCssModuleLocalIdent'
Expand Down Expand Up @@ -71,7 +71,18 @@ export const css = curry(async function css(
return config
}

const fns: ConfigurationFn[] = []
const fns: ConfigurationFn[] = [
loader({
oneOf: [
{
// Impossible regex expression
test: /a^/,
loader: 'noop-loader',
options: { __next_css_remove: true },
},
],
}),
]

const postCssPlugins = await getPostCssPlugins(ctx.rootDirectory)
// CSS Modules support must be enabled on the server and client so the class
Expand Down
2 changes: 2 additions & 0 deletions packages/next/build/webpack/plugins/css-minimizer-plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ type CssMinimizerPluginOptions = {
}

export class CssMinimizerPlugin {
__next_css_remove = true

private options: CssMinimizerPluginOptions

constructor(options: CssMinimizerPluginOptions) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import MiniCssExtractPlugin from 'mini-css-extract-plugin'

export default class NextMiniCssExtractPlugin extends MiniCssExtractPlugin {
__next_css_remove = true
}
32 changes: 29 additions & 3 deletions packages/next/export/index.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,16 @@
import chalk from 'chalk'
import { copyFile as copyFileOrig, existsSync, readFileSync } from 'fs'
import findUp from 'find-up'
import {
copyFile as copyFileOrig,
existsSync,
readFileSync,
writeFileSync,
} from 'fs'
import Worker from 'jest-worker'
import mkdirpModule from 'mkdirp'
import { cpus } from 'os'
import { dirname, join, resolve, sep } from 'path'
import { promisify } from 'util'
import findUp from 'find-up'
import { AmpPageStatus, formatAmpMessages } from '../build/output/index'
import createSpinner from '../build/spinner'
import { API_ROUTE } from '../lib/constants'
Expand All @@ -16,11 +21,12 @@ import {
CLIENT_PUBLIC_FILES_PATH,
CLIENT_STATIC_FILES_PATH,
CONFIG_FILE,
EXPORT_DETAIL,
PAGES_MANIFEST,
PHASE_EXPORT,
PRERENDER_MANIFEST,
SERVER_DIRECTORY,
SERVERLESS_DIRECTORY,
SERVER_DIRECTORY,
} from '../next-server/lib/constants'
import loadConfig, {
isTargetLikeServerless,
Expand Down Expand Up @@ -180,6 +186,16 @@ export default async function(
await recursiveDelete(join(outDir))
await mkdirp(join(outDir, '_next', buildId))

writeFileSync(
join(distDir, EXPORT_DETAIL),
JSON.stringify({
version: 1,
outDirectory: outDir,
success: false,
}),
'utf8'
)

// Copy static directory
if (!options.buildExport && existsSync(join(dir, 'static'))) {
log(' copying "static" directory')
Expand Down Expand Up @@ -372,6 +388,16 @@ export default async function(
// Add an empty line to the console for the better readability.
log('')

writeFileSync(
join(distDir, EXPORT_DETAIL),
JSON.stringify({
version: 1,
outDirectory: outDir,
success: true,
}),
'utf8'
)

if (telemetry) {
await telemetry.flush()
}
Expand Down
2 changes: 2 additions & 0 deletions packages/next/next-server/lib/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ export const PHASE_PRODUCTION_SERVER = 'phase-production-server'
export const PHASE_DEVELOPMENT_SERVER = 'phase-development-server'
export const PAGES_MANIFEST = 'pages-manifest.json'
export const BUILD_MANIFEST = 'build-manifest.json'
export const EXPORT_MARKER = 'export-marker.json'
export const EXPORT_DETAIL = 'export-detail.json'
export const PRERENDER_MANIFEST = 'prerender-manifest.json'
export const ROUTES_MANIFEST = 'routes-manifest.json'
export const REACT_LOADABLE_MANIFEST = 'react-loadable-manifest.json'
Expand Down
9 changes: 5 additions & 4 deletions packages/next/next-server/server/next-server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -774,9 +774,8 @@ export default class Server {

// Toggle whether or not this is an SPR Data request
const isSprData = isSpr && query._nextSprData
if (isSprData) {
delete query._nextSprData
}
delete query._nextSprData

// Compute the SPR cache key
const sprCacheKey = parseUrl(req.url || '').pathname!

Expand Down Expand Up @@ -890,7 +889,9 @@ export default class Server {
req,
res,
pathname,
query,
result.unstable_getStaticProps
? { _nextSprData: query._nextSprData }
: query,
result,
{ ...this.renderOpts, amphtml, hasAmp, dataOnly }
)
Expand Down
2 changes: 1 addition & 1 deletion packages/next/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@
"resolve": "1.11.0",
"taskr": "1.1.0",
"text-table": "0.2.0",
"typescript": "3.5.1",
"typescript": "3.7.3",
"unistore": "3.4.1"
},
"engines": {
Expand Down
7 changes: 1 addition & 6 deletions packages/next/server/next-dev-server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -414,13 +414,8 @@ export default class DevServer extends Server {
continue
}

// eslint-disable-next-line no-loop-func
return this.hotReloader!.ensurePage(dynamicRoute.page).then(() => {
pathname = dynamicRoute.page
query = Object.assign({}, query, params)
})
return this.hotReloader!.ensurePage(dynamicRoute.page)
}

throw err
})
} catch (err) {
Expand Down
1 change: 1 addition & 0 deletions packages/next/taskfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ const babelServerOpts = {
],
],
plugins: [
'@babel/plugin-proposal-optional-chaining',
'babel-plugin-dynamic-import-node',
['@babel/plugin-proposal-class-properties', { loose: true }],
],
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/out
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
const A = () => {
throw new Error('fail da export')
}
A.getInitialProps = () => {}
export default A
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/out
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
module.exports = {
exportPathMap() {
return { '/': { page: '/' } }
},
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export default () => <div>Hello Export</div>
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/lel
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module.exports = {
exportTrailingSlash: true,
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export default () => <div>Hello Export</div>
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/out
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export default () => <div>Hello Export</div>
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/out
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export default () => <div>Hello Export</div>
Loading

0 comments on commit b44e55c

Please sign in to comment.