Unverified Commit 9b098f54 authored by Tim Neutkens's avatar Tim Neutkens Committed by GitHub

Add sourcemaps to Next.js core compilation (#13049)

* Generate sourcemaps for core files that pass through Babel

* Run files through Babel instead of tsc

* Get rid of wildcard helper

* Get rid of wildcard helper

* Remove unused file

* Update wildcard imports

* Add exclude

* Get rid of object-assign helper

* Use Object.assign as it gives better output
Co-authored-by: 's avatarJoe Haddad <joe.haddad@zeit.co>
parent 53a2cebd
import * as React from 'react'
import React from 'react'
export const AmpStateContext: React.Context<any> = React.createContext({})
......
import * as React from 'react'
import React from 'react'
import { DocumentProps } from './utils'
type DocumentContext = {
......
import * as React from 'react'
import React from 'react'
export const HeadManagerContext: React.Context<any> = React.createContext(null)
......
import * as React from 'react'
import React from 'react'
type CaptureFn = (moduleName: string) => void
......
import * as React from 'react'
export const RequestContext: React.Context<any> = React.createContext(null)
if (process.env.NODE_ENV !== 'production') {
RequestContext.displayName = 'RequestContext'
}
import * as React from 'react'
import React from 'react'
import { NextRouter } from './router/router'
export const RouterContext = React.createContext<NextRouter>(null as any)
......
......@@ -310,12 +310,11 @@ export default class Router implements BaseRouter {
throw new Error(`Cannot update unavailable route: ${route}`)
}
const newData = {
...data,
const newData = Object.assign({}, data, {
Component,
__N_SSG: mod.__N_SSG,
__N_SSP: mod.__N_SSP,
}
})
this.components[route] = newData
// pages/_app.js updated
......
......@@ -62,10 +62,8 @@ export function getRouteRegex(
return {
re: new RegExp('^' + parameterizedRoute + '(?:/)?$', 'i'),
groups,
...(namedParameterizedRoute
? {
namedRegex: `^${namedParameterizedRoute}(?:/)?$`,
}
: {}),
namedRegex: namedParameterizedRoute
? `^${namedParameterizedRoute}(?:/)?$`
: undefined,
}
}
......@@ -32,6 +32,12 @@ const babelClientOpts = {
'@babel/plugin-syntax-dynamic-impor' + 't',
['@babel/plugin-proposal-class-properties', { loose: true }],
],
overrides: [
{
test: /\.tsx?$/,
plugins: [require('@babel/plugin-proposal-numeric-separator').default],
},
],
}
const babelServerOpts = {
......@@ -46,7 +52,12 @@ const babelServerOpts = {
node: '8.3',
},
loose: true,
exclude: ['transform-typeof-symbol'],
// This is handled by the Next.js webpack config that will run next/babel over the same code.
exclude: [
'transform-typeof-symbol',
'transform-async-to-generator',
'transform-spread',
],
},
],
],
......@@ -56,6 +67,12 @@ const babelServerOpts = {
'babel-plugin-dynamic-import-node',
['@babel/plugin-proposal-class-properties', { loose: true }],
],
overrides: [
{
test: /\.tsx?$/,
plugins: [require('@babel/plugin-proposal-numeric-separator').default],
},
],
}
module.exports = function (task) {
......@@ -92,6 +109,7 @@ module.exports = function (task) {
babelrc: false,
configFile: false,
filename: file.base,
sourceMaps: true,
}
const output = transform(file.data, options)
const ext = extname(file.base)
......@@ -111,6 +129,17 @@ module.exports = function (task) {
)
}
if (output.map) {
const map = `${file.base}.map`
// add sourcemap to `files` array
this._.files.push({
base: map,
dir: file.dir,
data: Buffer.from(JSON.stringify(output.map)),
})
}
file.data = Buffer.from(setNextVersion(output.code))
})
}
......
......@@ -715,7 +715,7 @@ export default async function (task) {
export async function nextserverlib(task, opts) {
await task
.source(opts.src || 'next-server/lib/**/*.+(js|ts|tsx)')
.typescript({ module: 'commonjs' })
.babel('server')
.target('dist/next-server/lib')
notify('Compiled lib files')
}
......@@ -723,7 +723,7 @@ export async function nextserverlib(task, opts) {
export async function nextserverserver(task, opts) {
await task
.source(opts.src || 'next-server/server/**/*.+(js|ts|tsx)')
.typescript({ module: 'commonjs' })
.babel('server')
.target('dist/next-server/server')
notify('Compiled server files')
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment