Skip to content

Commit

Permalink
chore(precompile): re-add watchpack to the precompile (#60309)
Browse files Browse the repository at this point in the history
Per @styfle suggestion, #58038 has been split into multiple PRs for
easier review.

- Re-add precompile `watchpack`
- Next.js has stopped bundling the `watchpack` since
#50792. Currently, `watchpack` is
a direct dependency of Next.js. The PR adds the pre-compile back.

Co-authored-by: Steven <steven@ceriously.com>
  • Loading branch information
SukkaW and styfle authored Jan 8, 2024
1 parent 817a240 commit 3894bad
Show file tree
Hide file tree
Showing 8 changed files with 17 additions and 14 deletions.
3 changes: 1 addition & 2 deletions packages/next/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -98,8 +98,7 @@
"caniuse-lite": "^1.0.30001406",
"graceful-fs": "^4.2.11",
"postcss": "8.4.31",
"styled-jsx": "5.1.1",
"watchpack": "2.4.0"
"styled-jsx": "5.1.1"
},
"peerDependencies": {
"@opentelemetry/api": "^1.1.0",
Expand Down
1 change: 1 addition & 0 deletions packages/next/src/compiled/watchpack/watchpack.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion packages/next/src/compiled/webpack/bundle5.js

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ import fs from 'fs'
import url from 'url'
import path from 'path'
import qs from 'querystring'
import Watchpack from 'watchpack'
import Watchpack from 'next/dist/compiled/watchpack'
import { loadEnvConfig } from '@next/env'
import isError from '../../../lib/is-error'
import findUp from 'next/dist/compiled/find-up'
Expand Down Expand Up @@ -1870,7 +1870,7 @@ async function startWatcher(opts: SetupOpts) {
const watchTimeChange =
watchTime === undefined ||
(watchTime && watchTime !== meta?.timestamp)
fileWatchTimes.set(fileName, meta.timestamp)
fileWatchTimes.set(fileName, meta?.timestamp)

if (envFiles.includes(fileName)) {
if (watchTimeChange) {
Expand Down
2 changes: 1 addition & 1 deletion packages/next/src/server/lib/start-server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import path from 'path'
import http from 'http'
import https from 'https'
import os from 'os'
import Watchpack from 'watchpack'
import Watchpack from 'next/dist/compiled/watchpack'
import * as Log from '../../build/output/log'
import setupDebug from 'next/dist/compiled/debug'
import { RESTART_EXIT_CODE, checkNodeDebugType, getDebugPort } from './utils'
Expand Down
9 changes: 8 additions & 1 deletion packages/next/taskfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -569,7 +569,13 @@ export async function ncc_next_font(task, opts) {
}

// eslint-disable-next-line camelcase
externals['watchpack'] = 'watchpack'
externals['watchpack'] = 'next/dist/compiled/watchpack'
export async function ncc_watchpack(task, opts) {
await task
.source(relative(__dirname, require.resolve('watchpack')))
.ncc({ packageName: 'watchpack', externals })
.target('src/compiled/watchpack')
}

// eslint-disable-next-line camelcase
externals['jest-worker'] = 'next/dist/compiled/jest-worker'
Expand Down Expand Up @@ -2312,6 +2318,7 @@ export async function ncc(task, opts) {
'ncc_terser',
'ncc_text_table',
'ncc_unistore',
'ncc_watchpack',
'ncc_web_vitals',
'ncc_web_vitals_attribution',
'ncc_webpack_bundle5',
Expand Down
4 changes: 0 additions & 4 deletions packages/next/types/misc.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -174,10 +174,6 @@ declare module 'next/dist/compiled/babel/preset-env' {
const anyType: any
export default anyType
}
declare module 'watchpack' {
const anyType: any
export default anyType
}
declare module 'next/dist/compiled/babel/core' {
export * from '@babel/core'
}
Expand Down
6 changes: 3 additions & 3 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 3894bad

Please sign in to comment.