Skip to content

Commit

Permalink
Merge branch 'canary' into loadable_caller
Browse files Browse the repository at this point in the history
  • Loading branch information
ijjk authored May 19, 2021
2 parents 7c4b182 + c0a07aa commit 810f2b1
Show file tree
Hide file tree
Showing 9 changed files with 128 additions and 21 deletions.
6 changes: 6 additions & 0 deletions docs/basic-features/typescript.md
Original file line number Diff line number Diff line change
Expand Up @@ -127,3 +127,9 @@ export default MyApp
Next.js automatically supports the `tsconfig.json` `"paths"` and `"baseUrl"` options.
You can learn more about this feature on the [Module Path aliases documentation](/docs/advanced-features/module-path-aliases.md).
## Incremental type checking
Since `v10.2.1` Next.js supports [incremental type checking](https://www.typescriptlang.org/tsconfig#incremental) when enabled in your `tsconfig.json`, this can help speed up type checking in larger applications.
It is highly recommended to be on at least `v4.3.0-beta` of TypeScript to experience the best performance when leveraging this feature.
2 changes: 1 addition & 1 deletion packages/create-next-app/helpers/install.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ export function install(
/**
* NPM-specific command-line flags.
*/
const npmFlags: string[] = ['--logLevel', 'error']
const npmFlags: string[] = []
/**
* Yarn-specific command-line flags.
*/
Expand Down
45 changes: 43 additions & 2 deletions packages/next/build/webpack-config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -825,7 +825,7 @@ export default async function getBaseWebpackConfig(
splitChunks: isServer
? isWebpack5
? ({
filename: `${dev ? '[name]' : '[name].[contenthash]'}.js`,
filename: '[name].js',
// allow to split entrypoints
chunks: 'all',
// size of files is not so relevant for server build
Expand Down Expand Up @@ -931,7 +931,7 @@ export default async function getBaseWebpackConfig(
: 'static/webpack/[hash].hot-update.json',
// This saves chunks with the name given via `import()`
chunkFilename: isServer
? `${dev ? '[name]' : '[name].[contenthash]'}.js`
? '[name].js'
: `static/chunks/${isDevFallback ? 'fallback/' : ''}${
dev ? '[name]' : '[name].[contenthash]'
}.js`,
Expand Down Expand Up @@ -1247,6 +1247,47 @@ export default async function getBaseWebpackConfig(
// webpack 5 no longer polyfills Node.js modules:
if (webpackConfig.node) delete webpackConfig.node.setImmediate

// Due to bundling of webpack the default values can't be correctly detected
// This restores the webpack defaults
// @ts-ignore webpack 5
webpackConfig.snapshot = {}
if (process.versions.pnp === '3') {
const match = /^(.+?)[\\/]cache[\\/]jest-worker-npm-[^\\/]+\.zip[\\/]node_modules[\\/]/.exec(
require.resolve('jest-worker')
)
if (match) {
// @ts-ignore webpack 5
webpackConfig.snapshot.managedPaths = [
path.resolve(match[1], 'unplugged'),
]
}
} else {
const match = /^(.+?[\\/]node_modules)[\\/]/.exec(
require.resolve('jest-worker')
)
if (match) {
// @ts-ignore webpack 5
webpackConfig.snapshot.managedPaths = [match[1]]
}
}
if (process.versions.pnp === '1') {
const match = /^(.+?[\\/]v4)[\\/]npm-jest-worker-[^\\/]+-[\da-f]{40}[\\/]node_modules[\\/]/.exec(
require.resolve('jest-worker')
)
if (match) {
// @ts-ignore webpack 5
webpackConfig.snapshot.immutablePaths = [match[1]]
}
} else if (process.versions.pnp === '3') {
const match = /^(.+?)[\\/]jest-worker-npm-[^\\/]+\.zip[\\/]node_modules[\\/]/.exec(
require.resolve('jest-worker')
)
if (match) {
// @ts-ignore webpack 5
webpackConfig.snapshot.immutablePaths = [match[1]]
}
}

if (dev) {
if (!webpackConfig.optimization) {
webpackConfig.optimization = {}
Expand Down
2 changes: 1 addition & 1 deletion packages/next/compiled/postcss-loader/cjs.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion packages/next/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@
"ora": "4.0.4",
"path-to-regexp": "6.1.0",
"postcss-flexbugs-fixes": "5.0.2",
"postcss-loader": "4.0.3",
"postcss-loader": "4.3.0",
"postcss-preset-env": "6.7.0",
"postcss-scss": "3.0.5",
"recast": "0.18.5",
Expand Down
8 changes: 7 additions & 1 deletion packages/next/taskfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -436,7 +436,13 @@ externals['postcss-loader'] = 'next/dist/compiled/postcss-loader'
export async function ncc_postcss_loader(task, opts) {
await task
.source(opts.src || relative(__dirname, require.resolve('postcss-loader')))
.ncc({ packageName: 'postcss-loader', externals })
.ncc({
packageName: 'postcss-loader',
externals: {
...externals,
'schema-utils': 'next/dist/compiled/schema-utils3',
},
})
.target('compiled/postcss-loader')
}
// eslint-disable-next-line camelcase
Expand Down
2 changes: 1 addition & 1 deletion test/integration/build-output/test/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ describe('Build Output', () => {
expect(parseFloat(err404Size)).toBeCloseTo(gz ? 3.06 : 8.15, 1)
expect(err404Size.endsWith('kB')).toBe(true)

expect(parseFloat(err404FirstLoad)).toBeCloseTo(gz ? 66.5 : 203, 1)
expect(parseFloat(err404FirstLoad)).toBeCloseTo(gz ? 66.4 : 203, 1)
expect(err404FirstLoad.endsWith('kB')).toBe(true)

expect(parseFloat(sharedByAll)).toBeCloseTo(gz ? 63.4 : 195, 1)
Expand Down
65 changes: 62 additions & 3 deletions test/integration/create-next-app/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ async function usingTempDir(fn, options) {
const folder = path.join(os.tmpdir(), Math.random().toString(36).substring(2))
await fs.mkdirp(folder, options)
try {
return await fn(folder)
await fn(folder)
} finally {
await fs.remove(folder)
}
Expand Down Expand Up @@ -52,6 +52,9 @@ describe('create next app', () => {
expect(
fs.existsSync(path.join(cwd, projectName, 'pages/index.js'))
).toBeTruthy()
expect(
fs.existsSync(path.join(cwd, projectName, 'node_modules/next'))
).toBe(true)
})
})
}
Expand Down Expand Up @@ -88,6 +91,9 @@ describe('create next app', () => {
expect(
fs.existsSync(path.join(cwd, projectName, '.gitignore'))
).toBeTruthy()
expect(
fs.existsSync(path.join(cwd, projectName, 'node_modules/next'))
).toBe(true)
})
})

Expand Down Expand Up @@ -115,6 +121,9 @@ describe('create next app', () => {
expect(
fs.existsSync(path.join(cwd, projectName, 'next-env.d.ts'))
).toBeTruthy()
expect(
fs.existsSync(path.join(cwd, projectName, 'node_modules/next'))
).toBe(true)
// check we copied default `.gitignore`
expect(
fs.existsSync(path.join(cwd, projectName, '.gitignore'))
Expand Down Expand Up @@ -154,6 +163,9 @@ describe('create next app', () => {
expect(
fs.existsSync(path.join(cwd, projectName, '.gitignore'))
).toBeTruthy()
expect(
fs.existsSync(path.join(cwd, projectName, 'node_modules/next'))
).toBe(true)
})
})

Expand All @@ -177,6 +189,9 @@ describe('create next app', () => {
expect(
fs.existsSync(path.join(cwd, projectName, '.gitignore'))
).toBeTruthy()
expect(
fs.existsSync(path.join(cwd, projectName, 'node_modules/next'))
).toBe(true)
})
})

Expand Down Expand Up @@ -206,6 +221,9 @@ describe('create next app', () => {
expect(
fs.existsSync(path.join(cwd, projectName, '.gitignore'))
).toBeTruthy()
expect(
fs.existsSync(path.join(cwd, projectName, 'node_modules/next'))
).toBe(true)
})
})

Expand Down Expand Up @@ -248,6 +266,9 @@ describe('create next app', () => {
expect(
fs.existsSync(path.join(cwd, projectName, '.gitignore'))
).toBeTruthy()
expect(
fs.existsSync(path.join(cwd, projectName, 'node_modules/next'))
).toBe(true)
})
})

Expand Down Expand Up @@ -283,7 +304,12 @@ describe('create next app', () => {
const res = await run(['.'], { cwd })
expect(res.exitCode).toBe(0)

const files = ['package.json', 'pages/index.js', '.gitignore']
const files = [
'package.json',
'pages/index.js',
'.gitignore',
'node_modules/next',
]
files.forEach((file) =>
expect(fs.existsSync(path.join(cwd, file))).toBeTruthy()
)
Expand All @@ -296,7 +322,12 @@ describe('create next app', () => {
const res = await run([], { cwd, input: `${projectName}\n` })
expect(res.exitCode).toBe(0)

const files = ['package.json', 'pages/index.js', '.gitignore']
const files = [
'package.json',
'pages/index.js',
'.gitignore',
'node_modules/next',
]
files.forEach((file) =>
expect(fs.existsSync(path.join(cwd, projectName, file))).toBeTruthy()
)
Expand All @@ -314,6 +345,34 @@ describe('create next app', () => {
'pages/index.js',
'.gitignore',
'package-lock.json',
'node_modules/next',
]
files.forEach((file) =>
expect(fs.existsSync(path.join(cwd, projectName, file))).toBeTruthy()
)
})
})

it('should use npm as the package manager on supplying --use-npm with example', async () => {
await usingTempDir(async (cwd) => {
const projectName = 'use-npm'
const res = await run(
[
projectName,
'--use-npm',
'--example',
'https://github.com/vercel/next-learn-starter/tree/master/learn-starter',
],
{ cwd }
)
expect(res.exitCode).toBe(0)

const files = [
'package.json',
'pages/index.js',
'.gitignore',
'package-lock.json',
'node_modules/next',
]
files.forEach((file) =>
expect(fs.existsSync(path.join(cwd, projectName, file))).toBeTruthy()
Expand Down
17 changes: 6 additions & 11 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2383,11 +2383,6 @@
call-me-maybe "^1.0.1"
glob-to-regexp "^0.3.0"

"@next/eslint-plugin-next@^10.1.3":
version "10.1.3"
resolved "https://registry.yarnpkg.com/@next/eslint-plugin-next/-/eslint-plugin-next-10.1.3.tgz#739743aa33aed28d97e670b9f80b84440cf2a3c7"
integrity sha512-KrZUb6cHXt/rPhN9bSrlVLAq+9LyNOWurqbrUww3OXmrFlXBDI8W6Z0ToDkQMkIH6gTtmpGbuctxCkQ2pgeXzQ==

"@nodelib/fs.scandir@2.1.3":
version "2.1.3"
resolved "https://registry.yarnpkg.com/@nodelib/fs.scandir/-/fs.scandir-2.1.3.tgz#3a582bdb53804c6ba6d146579c46e52130cf4a3b"
Expand Down Expand Up @@ -12832,16 +12827,16 @@ postcss-loader@3.0.0:
postcss-load-config "^2.0.0"
schema-utils "^1.0.0"

postcss-loader@4.0.3:
version "4.0.3"
resolved "https://registry.yarnpkg.com/postcss-loader/-/postcss-loader-4.0.3.tgz#337f51bbdfb02269fb42f7db9fc7f0a93c1b2e3f"
integrity sha512-jHboC/AOnJLPu8/974hODCJ/rNAa2YhhJOclUeuRlAmFpKmEcBY6az8y1ejHyYc2LThzPl8qPRekh2Yz3CiRKA==
postcss-loader@4.3.0:
version "4.3.0"
resolved "https://registry.yarnpkg.com/postcss-loader/-/postcss-loader-4.3.0.tgz#2c4de9657cd4f07af5ab42bd60a673004da1b8cc"
integrity sha512-M/dSoIiNDOo8Rk0mUqoj4kpGq91gcxCfb9PoyZVdZ76/AuhxylHDYZblNE8o+EQ9AMSASeMFEKxZf5aU6wlx1Q==
dependencies:
cosmiconfig "^7.0.0"
klona "^2.0.4"
loader-utils "^2.0.0"
schema-utils "^2.7.1"
semver "^7.3.2"
schema-utils "^3.0.0"
semver "^7.3.4"

postcss-logical@^3.0.0:
version "3.0.0"
Expand Down

0 comments on commit 810f2b1

Please sign in to comment.