Skip to content

Commit

Permalink
Move next-server back into next package (#8613)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
timneutkens authored and Timer committed Sep 4, 2019
1 parent 42771f6 commit 2ba352d
Show file tree
Hide file tree
Showing 117 changed files with 255 additions and 339 deletions.
1 change: 0 additions & 1 deletion packages/next-server/amp.d.ts

This file was deleted.

2 changes: 0 additions & 2 deletions packages/next-server/amp.js

This file was deleted.

2 changes: 0 additions & 2 deletions packages/next-server/config.d.ts

This file was deleted.

1 change: 0 additions & 1 deletion packages/next-server/config.js

This file was deleted.

1 change: 0 additions & 1 deletion packages/next-server/constants.d.ts

This file was deleted.

1 change: 0 additions & 1 deletion packages/next-server/constants.js

This file was deleted.

2 changes: 0 additions & 2 deletions packages/next-server/dynamic.d.ts

This file was deleted.

1 change: 0 additions & 1 deletion packages/next-server/dynamic.js

This file was deleted.

2 changes: 0 additions & 2 deletions packages/next-server/head.d.ts

This file was deleted.

1 change: 0 additions & 1 deletion packages/next-server/head.js

This file was deleted.

2 changes: 0 additions & 2 deletions packages/next-server/index.d.ts

This file was deleted.

5 changes: 0 additions & 5 deletions packages/next-server/index.js

This file was deleted.

21 changes: 0 additions & 21 deletions packages/next-server/license.md

This file was deleted.

1 change: 0 additions & 1 deletion packages/next-server/next-config.js

This file was deleted.

77 changes: 0 additions & 77 deletions packages/next-server/package.json

This file was deleted.

41 changes: 0 additions & 41 deletions packages/next-server/taskfile.js

This file was deleted.

11 changes: 0 additions & 11 deletions packages/next-server/tsconfig.json

This file was deleted.

14 changes: 0 additions & 14 deletions packages/next-server/types/index.d.ts

This file was deleted.

4 changes: 2 additions & 2 deletions packages/next/amp.d.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
export * from 'next-server/amp'
export { default } from 'next-server/amp'
export * from './dist/next-server/lib/amp'
export { default } from './dist/next-server/lib/amp'
2 changes: 1 addition & 1 deletion packages/next/amp.js
Original file line number Diff line number Diff line change
@@ -1 +1 @@
module.exports = require('next-server/amp')
module.exports = require('./dist/next-server/lib/amp')
2 changes: 1 addition & 1 deletion packages/next/bin/next.ts
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ if (typeof React.Suspense === 'undefined') {
commands[command]().then(exec => exec(forwardedArgs))

if (command === 'dev') {
const { CONFIG_FILE } = require('next-server/constants')
const { CONFIG_FILE } = require('../next-server/lib/constants')
const { watchFile } = require('fs')
watchFile(`${process.cwd()}/${CONFIG_FILE}`, (cur: any, prev: any) => {
if (cur.size > 0 || prev.size > 0) {
Expand Down
2 changes: 1 addition & 1 deletion packages/next/build/babel/plugins/next-page-config.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { PluginObj } from '@babel/core'
import { NodePath } from '@babel/traverse'
import * as BabelTypes from '@babel/types'
import { PageConfig } from 'next-server/types'
import { PageConfig } from '../../../types'

export const dropBundleIdentifier = '__NEXT_DROP_CLIENT_FILE__'
export const sprStatus = { used: false }
Expand Down
2 changes: 1 addition & 1 deletion packages/next/build/entries.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { isTargetLikeServerless } from 'next-server/dist/server/config'
import { isTargetLikeServerless } from '../next-server/server/config'
import { join } from 'path'
import { stringify } from 'querystring'

Expand Down
4 changes: 2 additions & 2 deletions packages/next/build/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@ import {
PRERENDER_MANIFEST,
SERVER_DIRECTORY,
SERVERLESS_DIRECTORY,
} from 'next-server/constants'
} from '../next-server/lib/constants'
import loadConfig, {
isTargetLikeServerless,
} from 'next-server/dist/server/config'
} from '../next-server/server/config'
import nanoid from 'next/dist/compiled/nanoid/index.js'
import path from 'path'
import { promisify } from 'util'
Expand Down
4 changes: 2 additions & 2 deletions packages/next/build/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ export function isPageStatic(
runtimeEnvConfig: any
): { static?: boolean; prerender?: boolean; isHybridAmp?: boolean } {
try {
require('next-server/config').setConfig(runtimeEnvConfig)
require('../next-server/lib/runtime-config').setConfig(runtimeEnvConfig)
const mod = require(serverBundle)
const Comp = mod.default || mod

Expand All @@ -174,7 +174,7 @@ export function hasCustomAppGetInitialProps(
_appBundle: string,
runtimeEnvConfig: any
): boolean {
require('next-server/config').setConfig(runtimeEnvConfig)
require('../next-server/lib/runtime-config').setConfig(runtimeEnvConfig)
let mod = require(_appBundle)

if (_appBundle.endsWith('_app.js')) {
Expand Down
26 changes: 14 additions & 12 deletions packages/next/build/webpack-config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import {
REACT_LOADABLE_MANIFEST,
SERVER_DIRECTORY,
SERVERLESS_DIRECTORY,
} from 'next-server/constants'
} from '../next-server/lib/constants'
import resolve from 'next/dist/compiled/resolve/index.js'
import path from 'path'
import crypto from 'crypto'
Expand Down Expand Up @@ -144,10 +144,10 @@ export default async function getBaseWebpackConfig(
alias: {
// These aliases make sure the wrapper module is not included in the bundles
// Which makes bundles slightly smaller, but also skips parsing a module that we know will result in this alias
'next/head': 'next-server/dist/lib/head.js',
'next/head': 'next/dist/next-server/lib/head.js',
'next/router': 'next/dist/client/router.js',
'next/config': 'next-server/dist/lib/runtime-config.js',
'next/dynamic': 'next-server/dist/lib/dynamic.js',
'next/config': 'next/dist/next-server/lib/runtime-config.js',
'next/dynamic': 'next/dist/next-server/lib/dynamic.js',
next: NEXT_PROJECT_ROOT,
[PAGES_DIR_ALIAS]: path.join(dir, 'pages'),
[DOT_NEXT_ALIAS]: distDir,
Expand Down Expand Up @@ -325,9 +325,12 @@ export default async function getBaseWebpackConfig(

// Default pages have to be transpiled
if (
res.match(/next[/\\]dist[/\\]/) ||
res.match(/node_modules[/\\]@babel[/\\]runtime[/\\]/) ||
res.match(/node_modules[/\\]@babel[/\\]runtime-corejs2[/\\]/)
!res.match(/next[/\\]dist[/\\]next-server[/\\]/) &&
(res.match(/next[/\\]dist[/\\]/) ||
res.match(/node_modules[/\\]@babel[/\\]runtime[/\\]/) ||
res.match(
/node_modules[/\\]@babel[/\\]runtime-corejs2[/\\]/
))
) {
return callback()
}
Expand Down Expand Up @@ -360,9 +363,7 @@ export default async function getBaseWebpackConfig(
) {
// if it's the Next.js' require mark it as external
// since it's not used
if (
context.replace(/\\/g, '/').includes('next-server/dist/server')
) {
if (context.replace(/\\/g, '/').includes('next-server/server')) {
return callback(undefined, `commonjs ${request}`)
}
}
Expand Down Expand Up @@ -457,14 +458,14 @@ export default async function getBaseWebpackConfig(
test: /\.(tsx|ts|js|mjs|jsx)$/,
include: [
dir,
/next-server[\\/]dist[\\/]lib/,
/next[\\/]dist[\\/]next-server[\\/]lib/,
/next[\\/]dist[\\/]client/,
/next[\\/]dist[\\/]pages/,
/[\\/](strip-ansi|ansi-regex)[\\/]/,
],
exclude: (path: string) => {
if (
/next-server[\\/]dist[\\/]lib/.test(path) ||
/next[\\/]dist[\\/]next-server[\\/]lib/.test(path) ||
/next[\\/]dist[\\/]client/.test(path) ||
/next[\\/]dist[\\/]pages/.test(path) ||
/[\\/](strip-ansi|ansi-regex)[\\/]/.test(path)
Expand Down Expand Up @@ -698,6 +699,7 @@ 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 Down
2 changes: 1 addition & 1 deletion packages/next/build/webpack/loaders/next-babel-loader.js
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ module.exports = babelLoader.custom(babel => {
...(options.overrides || []),
{
test: [
/next-server[\\/]dist[\\/]lib/,
/next[\\/]dist[\\/]next-server[\\/]lib/,
/next[\\/]dist[\\/]client/,
/next[\\/]dist[\\/]pages/
],
Expand Down
19 changes: 11 additions & 8 deletions packages/next/build/webpack/loaders/next-serverless-loader.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
import { loader } from 'webpack'
import { join } from 'path'
import { parse } from 'querystring'
import { BUILD_MANIFEST, REACT_LOADABLE_MANIFEST } from 'next-server/constants'
import { isDynamicRoute } from 'next-server/dist/lib/router/utils'
import {
BUILD_MANIFEST,
REACT_LOADABLE_MANIFEST,
} from '../../../next-server/lib/constants'
import { isDynamicRoute } from '../../../next-server/lib/router/utils'
import { API_ROUTE } from '../../../lib/constants'

export type ServerlessLoaderQuery = {
Expand Down Expand Up @@ -45,13 +48,13 @@ const nextServerlessLoader: loader.Loader = function() {
${
isDynamicRoute(page)
? `
import { getRouteMatcher } from 'next-server/dist/lib/router/utils/route-matcher';
import { getRouteRegex } from 'next-server/dist/lib/router/utils/route-regex';
import { getRouteMatcher } from 'next/dist/next-server/lib/router/utils/route-matcher';
import { getRouteRegex } from 'next/dist/next-server/lib/router/utils/route-regex';
`
: ``
}
import { parse } from 'url'
import { apiResolver } from 'next-server/dist/server/api-utils'
import { apiResolver } from 'next/dist/next-server/server/api-utils'
export default (req, res) => {
const params = ${
Expand All @@ -66,11 +69,11 @@ const nextServerlessLoader: loader.Loader = function() {
} else {
return `
import {parse} from 'url'
import {renderToHTML} from 'next-server/dist/server/render';
import {sendHTML} from 'next-server/dist/server/send-html';
import {renderToHTML} from 'next/dist/next-server/server/render';
import {sendHTML} from 'next/dist/next-server/server/send-html';
${
isDynamicRoute(page)
? `import {getRouteMatcher, getRouteRegex} from 'next-server/dist/lib/router/utils';`
? `import {getRouteMatcher, getRouteRegex} from 'next/dist/next-server/lib/router/utils';`
: ''
}
import buildManifest from '${buildManifest}';
Expand Down
Loading

0 comments on commit 2ba352d

Please sign in to comment.