Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/canary' into add/rewrite-proxying
Browse files Browse the repository at this point in the history
  • Loading branch information
ijjk committed Jan 10, 2020
2 parents 2144afa + 3dc4a68 commit 45801a3
Show file tree
Hide file tree
Showing 15 changed files with 82 additions and 20 deletions.
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.1.8-canary.11"
"version": "9.1.8-canary.12"
}
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.1.8-canary.11",
"version": "9.1.8-canary.12",
"keywords": [
"react",
"next",
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.1.8-canary.11",
"version": "9.1.8-canary.12",
"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.1.8-canary.11",
"version": "9.1.8-canary.12",
"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.1.8-canary.11",
"version": "9.1.8-canary.12",
"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.1.8-canary.11",
"version": "9.1.8-canary.12",
"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.1.8-canary.11",
"version": "9.1.8-canary.12",
"nextjs": {
"name": "Sentry",
"required-env": [
Expand Down
34 changes: 23 additions & 11 deletions packages/next/build/webpack-config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -865,18 +865,31 @@ export default async function getBaseWebpackConfig(
return false
}

const fileName = '/tmp/test.css'

if (rule instanceof RegExp && rule.test(fileName)) {
const fileNames = [
'/tmp/test.css',
'/tmp/test.scss',
'/tmp/test.sass',
'/tmp/test.less',
'/tmp/test.styl',
]

if (rule instanceof RegExp && fileNames.some(input => rule.test(input))) {
return true
}

if (typeof rule === 'function') {
try {
if (rule(fileName)) {
return true
}
} catch (_) {}
if (
fileNames.some(input => {
try {
if (rule(input)) {
return true
}
} catch (_) {}
return false
})
) {
return true
}
}

if (Array.isArray(rule) && rule.some(canMatchCss)) {
Expand All @@ -888,10 +901,9 @@ export default async function getBaseWebpackConfig(

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

if (hasUserCssConfig) {
if (webpackConfig.module?.rules.length) {
Expand Down
9 changes: 8 additions & 1 deletion packages/next/next-server/server/next-server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -496,6 +496,13 @@ export default class Server {
res.setHeader('Location', updatedDestination)
res.statusCode =
(route as Redirect).statusCode || DEFAULT_REDIRECT_STATUS

// Since IE11 doesn't support the 308 header add backwards
// compatibility using refresh header
if (res.statusCode === 308) {
res.setHeader('Refresh', `0;url=${updatedDestination}`)
}

res.end()
return {
finished: true,
Expand All @@ -510,7 +517,7 @@ export default class Server {
})
proxy.web(req, res)

proxy.on('error', err => {
proxy.on('error', (err: Error) => {
console.error(
`Error occurred proxying ${updatedDestination}`,
err
Expand Down
2 changes: 1 addition & 1 deletion packages/next/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "next",
"version": "9.1.8-canary.11",
"version": "9.1.8-canary.12",
"description": "The React Framework",
"main": "./dist/server/next.js",
"license": "MIT",
Expand Down
8 changes: 8 additions & 0 deletions test/integration/custom-routes/test/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,14 @@ const runTests = (isDev = false) => {
expect(await res.text()).toContain('ZEIT, Inc')
})

it('should add refresh header for 308 redirect', async () => {
const res = await fetchViaHTTP(appPort, '/redirect4', undefined, {
redirect: 'manual',
})
expect(res.status).toBe(308)
expect(res.headers.get('refresh')).toBe(`0;url=/`)
})

if (!isDev) {
it('should output routes-manifest successfully', async () => {
const manifest = await fs.readJSON(
Expand Down
2 changes: 2 additions & 0 deletions test/integration/legacy-sass/next.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
const withSass = require('@zeit/next-sass')
module.exports = withSass({})
3 changes: 3 additions & 0 deletions test/integration/legacy-sass/pages/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import '../styles/style.scss'

export default () => <div className="example">Hello World!</div>
4 changes: 4 additions & 0 deletions test/integration/legacy-sass/styles/style.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
$color: #2ecc71;
.example {
background-color: $color;
}
26 changes: 26 additions & 0 deletions test/integration/legacy-sass/test/index.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
/* eslint-env jest */
/* global jasmine */
import { remove } from 'fs-extra'
import { nextBuild } from 'next-test-utils'
import { recursiveReadDir } from 'next/dist/lib/recursive-readdir'
import { join } from 'path'

jasmine.DEFAULT_TIMEOUT_INTERVAL = 1000 * 60 * 1

const appDir = join(__dirname, '../')

describe('Legacy Sass Support Should Disable New CSS', () => {
beforeAll(async () => {
await remove(join(appDir, '.next'))
await nextBuild(appDir)
})

it(`should've emitted a single CSS file`, async () => {
const cssFiles = await recursiveReadDir(
join(appDir, '.next', 'static'),
/\.css$/
)

expect(cssFiles.length).toBe(1)
})
})

0 comments on commit 45801a3

Please sign in to comment.