2021-10-28 11:07:13 +02:00
|
|
|
const { relative, basename, resolve, join, dirname } = require('path')
|
2021-12-21 16:13:45 +01:00
|
|
|
// eslint-disable-next-line import/no-extraneous-dependencies
|
|
|
|
const glob = require('glob')
|
2022-01-17 16:17:22 +01:00
|
|
|
// eslint-disable-next-line import/no-extraneous-dependencies
|
2023-10-06 00:01:45 +02:00
|
|
|
const fs = require('fs/promises')
|
2022-06-06 21:36:29 +02:00
|
|
|
// eslint-disable-next-line import/no-extraneous-dependencies
|
2022-07-21 20:29:19 +02:00
|
|
|
const resolveFrom = require('resolve-from')
|
2023-09-20 20:19:43 +02:00
|
|
|
const execa = require('execa')
|
2021-01-14 02:59:08 +01:00
|
|
|
|
2020-03-29 18:56:34 +02:00
|
|
|
export async function next__polyfill_nomodule(task, opts) {
|
|
|
|
await task
|
2023-01-03 10:05:50 +01:00
|
|
|
.source(relative(__dirname, require.resolve('@next/polyfill-nomodule')))
|
2020-03-29 18:56:34 +02:00
|
|
|
.target('dist/build/polyfills')
|
|
|
|
}
|
|
|
|
|
2021-12-21 16:13:45 +01:00
|
|
|
export async function next__polyfill_module(task, opts) {
|
|
|
|
await task
|
2023-01-03 10:05:50 +01:00
|
|
|
.source(relative(__dirname, require.resolve('@next/polyfill-module')))
|
2021-12-21 16:13:45 +01:00
|
|
|
.target('dist/build/polyfills')
|
|
|
|
}
|
|
|
|
|
2021-02-03 18:02:44 +01:00
|
|
|
export async function browser_polyfills(task, opts) {
|
2021-12-21 16:13:45 +01:00
|
|
|
await task.parallel(
|
|
|
|
['next__polyfill_nomodule', 'next__polyfill_module'],
|
|
|
|
opts
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
// eslint-disable-next-line camelcase
|
|
|
|
export async function copy_regenerator_runtime(task, opts) {
|
|
|
|
await task
|
|
|
|
.source(join(dirname(require.resolve('regenerator-runtime')), '**/*'))
|
2023-01-03 10:05:50 +01:00
|
|
|
.target('src/compiled/regenerator-runtime')
|
2020-03-29 18:56:34 +02:00
|
|
|
}
|
|
|
|
|
2022-06-22 14:09:22 +02:00
|
|
|
// eslint-disable-next-line camelcase
|
2022-08-09 03:27:42 +02:00
|
|
|
export async function copy_styled_jsx_assets(task, opts) {
|
2022-08-12 19:08:38 +02:00
|
|
|
// we copy the styled-jsx types so that we can reference them
|
2022-06-22 14:09:22 +02:00
|
|
|
// in the next-env.d.ts file so it doesn't matter if the styled-jsx
|
|
|
|
// package is hoisted out of Next.js' node_modules or not
|
|
|
|
const styledJsxPath = dirname(require.resolve('styled-jsx/package.json'))
|
|
|
|
const typeFiles = glob.sync('*.d.ts', { cwd: styledJsxPath })
|
2022-08-09 03:27:42 +02:00
|
|
|
const outputDir = join(__dirname, 'dist/styled-jsx')
|
2022-08-09 19:10:33 +02:00
|
|
|
// Separate type files into different folders to avoid conflicts between
|
|
|
|
// dev dep `styled-jsx` and `next/dist/styled-jsx` for duplicated declare modules
|
|
|
|
const typesDir = join(outputDir, 'types')
|
2023-10-06 00:01:45 +02:00
|
|
|
await fs.mkdir(typesDir, { recursive: true })
|
2022-06-22 14:09:22 +02:00
|
|
|
|
|
|
|
for (const file of typeFiles) {
|
2022-08-11 17:13:26 +02:00
|
|
|
const content = await fs.readFile(join(styledJsxPath, file), 'utf8')
|
2022-08-09 19:10:33 +02:00
|
|
|
await fs.writeFile(join(typesDir, file), content)
|
2022-06-22 14:09:22 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-03-29 18:16:32 +02:00
|
|
|
const externals = {
|
2021-12-08 17:41:35 +01:00
|
|
|
// don't bundle caniuse-lite data so users can
|
|
|
|
// update it manually
|
|
|
|
'caniuse-lite': 'caniuse-lite',
|
|
|
|
'/caniuse-lite(/.*)/': 'caniuse-lite$1',
|
2020-03-30 03:25:10 +02:00
|
|
|
|
2020-11-06 03:33:14 +01:00
|
|
|
'node-fetch': 'node-fetch',
|
2021-09-02 08:45:35 +02:00
|
|
|
postcss: 'postcss',
|
|
|
|
// Ensure latest version is used
|
|
|
|
'postcss-safe-parser': 'next/dist/compiled/postcss-safe-parser',
|
2020-11-06 03:33:14 +01:00
|
|
|
|
2021-01-14 02:59:08 +01:00
|
|
|
// sass-loader
|
|
|
|
// (also responsible for these dependencies in package.json)
|
|
|
|
'node-sass': 'node-sass',
|
|
|
|
sass: 'sass',
|
|
|
|
fibers: 'fibers',
|
|
|
|
|
2020-03-30 03:25:10 +02:00
|
|
|
chokidar: 'chokidar',
|
2020-04-15 20:20:25 +02:00
|
|
|
'jest-worker': 'jest-worker',
|
2021-09-21 16:22:57 +02:00
|
|
|
|
|
|
|
'terser-webpack-plugin':
|
2024-02-20 01:17:13 +01:00
|
|
|
'next/dist/build/webpack/plugins/terser-webpack-plugin/src',
|
2022-07-26 21:23:19 +02:00
|
|
|
|
|
|
|
// TODO: Add @swc/helpers to externals once @vercel/ncc switch to swc-loader
|
2020-03-29 05:41:35 +02:00
|
|
|
}
|
2021-12-21 16:13:45 +01:00
|
|
|
// eslint-disable-next-line camelcase
|
|
|
|
externals['node-html-parser'] = 'next/dist/compiled/node-html-parser'
|
|
|
|
export async function ncc_node_html_parser(task, opts) {
|
|
|
|
await task
|
2023-01-03 10:05:50 +01:00
|
|
|
.source(relative(__dirname, require.resolve('node-html-parser')))
|
2023-07-10 17:40:06 +02:00
|
|
|
.ncc({
|
|
|
|
packageName: 'node-html-parser',
|
|
|
|
externals,
|
|
|
|
target: 'es5',
|
|
|
|
})
|
2023-01-03 10:05:50 +01:00
|
|
|
.target('src/compiled/node-html-parser')
|
2021-12-21 16:13:45 +01:00
|
|
|
}
|
|
|
|
|
2023-08-15 04:31:00 +02:00
|
|
|
// eslint-disable-next-line camelcase
|
|
|
|
externals['@mswjs/interceptors/ClientRequest'] =
|
|
|
|
'next/dist/compiled/@mswjs/interceptors/ClientRequest'
|
|
|
|
export async function ncc_mswjs_interceptors(task, opts) {
|
|
|
|
await task
|
|
|
|
.source(
|
|
|
|
relative(__dirname, require.resolve('@mswjs/interceptors/ClientRequest'))
|
|
|
|
)
|
|
|
|
.ncc({
|
|
|
|
packageName: '@mswjs/interceptors/ClientRequest',
|
|
|
|
externals,
|
|
|
|
target: 'es5',
|
|
|
|
})
|
|
|
|
.target('src/compiled/@mswjs/interceptors/ClientRequest')
|
|
|
|
}
|
|
|
|
|
2023-03-27 05:29:28 +02:00
|
|
|
export async function capsize_metrics() {
|
|
|
|
const {
|
|
|
|
entireMetricsCollection,
|
|
|
|
// eslint-disable-next-line import/no-extraneous-dependencies
|
|
|
|
} = require('@capsizecss/metrics/entireMetricsCollection')
|
|
|
|
const outputPathDist = join(
|
|
|
|
__dirname,
|
|
|
|
'dist/server/capsize-font-metrics.json'
|
|
|
|
)
|
|
|
|
|
2023-10-06 00:01:45 +02:00
|
|
|
await writeJson(outputPathDist, entireMetricsCollection, { spaces: 2 })
|
2023-03-27 05:29:28 +02:00
|
|
|
}
|
|
|
|
|
2021-12-21 16:13:45 +01:00
|
|
|
// eslint-disable-next-line camelcase
|
|
|
|
externals['@babel/runtime'] = 'next/dist/compiled/@babel/runtime'
|
|
|
|
export async function copy_babel_runtime(task, opts) {
|
|
|
|
const runtimeDir = dirname(require.resolve('@babel/runtime/package.json'))
|
2023-01-03 10:05:50 +01:00
|
|
|
const outputDir = join(__dirname, 'src/compiled/@babel/runtime')
|
2021-12-21 16:13:45 +01:00
|
|
|
const runtimeFiles = glob.sync('**/*', {
|
|
|
|
cwd: runtimeDir,
|
|
|
|
ignore: ['node_modules/**/*'],
|
|
|
|
})
|
|
|
|
|
|
|
|
for (const file of runtimeFiles) {
|
|
|
|
const inputPath = join(runtimeDir, file)
|
|
|
|
const outputPath = join(outputDir, file)
|
|
|
|
|
2023-10-06 00:01:45 +02:00
|
|
|
if (!(await fs.stat(inputPath)).isFile()) {
|
2021-12-21 16:13:45 +01:00
|
|
|
continue
|
|
|
|
}
|
2023-10-06 00:01:45 +02:00
|
|
|
let contents = await fs.readFile(inputPath, 'utf8')
|
2021-12-21 16:13:45 +01:00
|
|
|
|
|
|
|
if (inputPath.endsWith('.js')) {
|
|
|
|
contents = contents
|
|
|
|
.replace(
|
|
|
|
'regenerator-runtime',
|
|
|
|
'next/dist/compiled/regenerator-runtime'
|
|
|
|
)
|
|
|
|
.replace('@babel/runtime', 'next/dist/compiled/@babel/runtime')
|
|
|
|
}
|
|
|
|
|
|
|
|
if (inputPath.endsWith('package.json')) {
|
|
|
|
contents = JSON.stringify({
|
|
|
|
...JSON.parse(contents),
|
|
|
|
dependencies: {},
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2023-10-06 00:01:45 +02:00
|
|
|
await fs.mkdir(dirname(outputPath), { recursive: true })
|
|
|
|
await fs.writeFile(outputPath, contents)
|
2021-12-21 16:13:45 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-03-31 04:29:10 +02:00
|
|
|
externals['@vercel/og'] = 'next/dist/compiled/@vercel/og'
|
|
|
|
export async function copy_vercel_og(task, opts) {
|
2023-12-21 14:50:57 +01:00
|
|
|
function copy_og_asset(globPattern) {
|
|
|
|
return task
|
|
|
|
.source(
|
|
|
|
join(
|
|
|
|
relative(
|
|
|
|
__dirname,
|
|
|
|
dirname(require.resolve('@vercel/og/package.json'))
|
|
|
|
),
|
|
|
|
globPattern
|
|
|
|
)
|
2023-07-19 23:04:27 +02:00
|
|
|
)
|
2023-12-21 14:50:57 +01:00
|
|
|
.target('src/compiled/@vercel/og')
|
|
|
|
}
|
2023-07-19 23:04:27 +02:00
|
|
|
|
2023-12-21 14:50:57 +01:00
|
|
|
await copy_og_asset('./dist/*.ttf')
|
|
|
|
await copy_og_asset('./dist/*.wasm')
|
|
|
|
await copy_og_asset('LICENSE')
|
|
|
|
await copy_og_asset('./dist/index.*.js')
|
2023-03-31 04:29:10 +02:00
|
|
|
|
|
|
|
// Types are not bundled, include satori types here
|
|
|
|
await task
|
|
|
|
.source(
|
|
|
|
join(dirname(require.resolve('satori/package.json')), 'dist/index.d.ts')
|
|
|
|
)
|
|
|
|
// eslint-disable-next-line require-yield
|
|
|
|
.run({ every: true }, function* (file) {
|
|
|
|
const source = file.data.toString()
|
|
|
|
// Ignore yoga-wasm-web types
|
|
|
|
file.data = source.replace(
|
|
|
|
/import { Yoga } from ['"]yoga-wasm-web['"]/g,
|
|
|
|
'type Yoga = any'
|
|
|
|
)
|
|
|
|
})
|
|
|
|
.target('src/compiled/@vercel/og/satori')
|
|
|
|
await task
|
|
|
|
.source(join(dirname(require.resolve('satori/package.json')), 'LICENSE'))
|
|
|
|
.target('src/compiled/@vercel/og/satori')
|
|
|
|
|
|
|
|
await task
|
|
|
|
.source(
|
|
|
|
join(
|
|
|
|
dirname(require.resolve('@vercel/og/package.json')),
|
|
|
|
'dist/**/*.d.ts'
|
|
|
|
)
|
|
|
|
)
|
|
|
|
// eslint-disable-next-line require-yield
|
|
|
|
.run({ every: true }, function* (file) {
|
|
|
|
const source = file.data.toString()
|
|
|
|
// Refers to copied satori types
|
|
|
|
file.data = source.replace(
|
|
|
|
/['"]satori['"]/g,
|
|
|
|
'"next/dist/compiled/@vercel/og/satori"'
|
|
|
|
)
|
|
|
|
})
|
|
|
|
.target('src/compiled/@vercel/og')
|
|
|
|
|
2023-10-06 00:01:45 +02:00
|
|
|
await writeJson(
|
2023-03-31 04:29:10 +02:00
|
|
|
join(__dirname, 'src/compiled/@vercel/og/package.json'),
|
2023-10-06 00:01:45 +02:00
|
|
|
{
|
|
|
|
name: '@vercel/og',
|
2023-10-19 16:26:48 +02:00
|
|
|
version: require('@vercel/og/package.json').version,
|
2023-10-06 00:01:45 +02:00
|
|
|
LICENSE: 'MLP-2.0',
|
|
|
|
type: 'module',
|
|
|
|
main: './index.node.js',
|
|
|
|
exports: {
|
|
|
|
'.': {
|
|
|
|
'edge-light': './index.edge.js',
|
|
|
|
import: './index.node.js',
|
|
|
|
node: './index.node.js',
|
|
|
|
default: './index.node.js',
|
2023-03-31 04:29:10 +02:00
|
|
|
},
|
2023-10-19 16:26:48 +02:00
|
|
|
'./package.json': './package.json',
|
2023-03-31 04:29:10 +02:00
|
|
|
},
|
2023-10-06 00:01:45 +02:00
|
|
|
},
|
|
|
|
{ spaces: 2 }
|
2023-03-31 04:29:10 +02:00
|
|
|
)
|
|
|
|
}
|
|
|
|
|
2022-01-17 16:17:22 +01:00
|
|
|
// eslint-disable-next-line camelcase
|
|
|
|
externals['node-fetch'] = 'next/dist/compiled/node-fetch'
|
|
|
|
export async function ncc_node_fetch(task, opts) {
|
|
|
|
await task
|
2023-01-03 10:05:50 +01:00
|
|
|
.source(relative(__dirname, require.resolve('node-fetch')))
|
2022-01-17 16:17:22 +01:00
|
|
|
.ncc({ packageName: 'node-fetch', externals })
|
2023-01-03 10:05:50 +01:00
|
|
|
.target('src/compiled/node-fetch')
|
2022-01-17 16:17:22 +01:00
|
|
|
}
|
|
|
|
|
2022-10-11 16:11:57 +02:00
|
|
|
externals['anser'] = 'next/dist/compiled/anser'
|
2024-01-22 13:53:42 +01:00
|
|
|
externals['next/dist/compiled/anser'] = 'next/dist/compiled/anser'
|
2022-10-11 16:11:57 +02:00
|
|
|
export async function ncc_node_anser(task, opts) {
|
|
|
|
await task
|
2023-01-03 10:05:50 +01:00
|
|
|
.source(relative(__dirname, require.resolve('anser')))
|
2022-10-11 16:11:57 +02:00
|
|
|
.ncc({ packageName: 'anser', externals })
|
2023-01-03 10:05:50 +01:00
|
|
|
.target('src/compiled/anser')
|
2022-10-11 16:11:57 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
externals['stacktrace-parser'] = 'next/dist/compiled/stacktrace-parser'
|
2024-01-22 13:53:42 +01:00
|
|
|
externals['next/dist/compiled/stacktrace-parser'] =
|
|
|
|
'next/dist/compiled/stacktrace-parser'
|
2022-10-11 16:11:57 +02:00
|
|
|
export async function ncc_node_stacktrace_parser(task, opts) {
|
|
|
|
await task
|
2023-01-03 10:05:50 +01:00
|
|
|
.source(relative(__dirname, require.resolve('stacktrace-parser')))
|
2022-10-11 16:11:57 +02:00
|
|
|
.ncc({ packageName: 'stacktrace-parser', externals })
|
2023-01-03 10:05:50 +01:00
|
|
|
.target('src/compiled/stacktrace-parser')
|
2022-10-11 16:11:57 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
externals['data-uri-to-buffer'] = 'next/dist/compiled/data-uri-to-buffer'
|
2024-01-22 13:53:42 +01:00
|
|
|
externals['next/dist/compiled/data-uri-to-buffer'] =
|
|
|
|
'next/dist/compiled/data-uri-to-buffer'
|
2022-10-11 16:11:57 +02:00
|
|
|
export async function ncc_node_data_uri_to_buffer(task, opts) {
|
|
|
|
await task
|
2023-01-03 10:05:50 +01:00
|
|
|
.source(relative(__dirname, require.resolve('data-uri-to-buffer')))
|
2022-10-11 16:11:57 +02:00
|
|
|
.ncc({ packageName: 'data-uri-to-buffer', externals })
|
2023-01-03 10:05:50 +01:00
|
|
|
.target('src/compiled/data-uri-to-buffer')
|
2022-10-11 16:11:57 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
externals['css.escape'] = 'next/dist/compiled/css.escape'
|
2024-01-22 13:53:42 +01:00
|
|
|
externals['next/dist/compiled/css.escape'] = 'next/dist/compiled/css.escape'
|
2022-10-11 16:11:57 +02:00
|
|
|
export async function ncc_node_cssescape(task, opts) {
|
|
|
|
await task
|
2023-01-03 10:05:50 +01:00
|
|
|
.source(relative(__dirname, require.resolve('css.escape')))
|
2022-10-11 16:11:57 +02:00
|
|
|
.ncc({ packageName: 'css.escape', externals })
|
2023-01-03 10:05:50 +01:00
|
|
|
.target('src/compiled/css.escape')
|
2022-10-11 16:11:57 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
externals['shell-quote'] = 'next/dist/compiled/shell-quote'
|
2024-01-22 13:53:42 +01:00
|
|
|
externals['next/dist/compiled/shell-quote'] = 'next/dist/compiled/shell-quote'
|
2022-10-11 16:11:57 +02:00
|
|
|
export async function ncc_node_shell_quote(task, opts) {
|
|
|
|
await task
|
2023-01-03 10:05:50 +01:00
|
|
|
.source(relative(__dirname, require.resolve('shell-quote')))
|
2022-10-11 16:11:57 +02:00
|
|
|
.ncc({ packageName: 'shell-quote', externals })
|
2023-01-03 10:05:50 +01:00
|
|
|
.target('src/compiled/shell-quote')
|
2022-10-11 16:11:57 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
externals['platform'] = 'next/dist/compiled/platform'
|
2024-01-22 13:53:42 +01:00
|
|
|
externals['next/dist/compiled/platform'] = 'next/dist/compiled/platform'
|
2022-10-11 16:11:57 +02:00
|
|
|
export async function ncc_node_platform(task, opts) {
|
|
|
|
await task
|
2023-01-03 10:05:50 +01:00
|
|
|
.source(relative(__dirname, require.resolve('platform')))
|
2022-10-11 16:11:57 +02:00
|
|
|
.ncc({ packageName: 'platform', externals })
|
2023-01-03 10:05:50 +01:00
|
|
|
.target('src/compiled/platform')
|
2022-10-11 16:11:57 +02:00
|
|
|
|
2023-01-03 10:05:50 +01:00
|
|
|
const clientFile = join(__dirname, 'src/compiled/platform/platform.js')
|
2023-10-06 00:01:45 +02:00
|
|
|
const content = await fs.readFile(clientFile, 'utf8')
|
2022-10-11 16:11:57 +02:00
|
|
|
// remove AMD define branch as this forces the module to not
|
2023-03-25 10:21:27 +01:00
|
|
|
// be treated as commonjs
|
2023-10-06 00:01:45 +02:00
|
|
|
await fs.writeFile(
|
2022-10-11 16:11:57 +02:00
|
|
|
clientFile,
|
|
|
|
content.replace(
|
|
|
|
new RegExp(
|
|
|
|
'if(typeof define=="function"&&typeof define.amd=="object"&&define.amd){r.platform=d;define((function(){return d}))}else '.replace(
|
|
|
|
/[|\\{}()[\]^$+*?.-]/g,
|
|
|
|
'\\$&'
|
|
|
|
),
|
|
|
|
'g'
|
|
|
|
),
|
|
|
|
''
|
|
|
|
)
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
2021-12-20 14:01:35 +01:00
|
|
|
// eslint-disable-next-line camelcase
|
|
|
|
externals['acorn'] = 'next/dist/compiled/acorn'
|
|
|
|
export async function ncc_acorn(task, opts) {
|
|
|
|
await task
|
2023-01-03 10:05:50 +01:00
|
|
|
.source(relative(__dirname, require.resolve('acorn')))
|
2021-12-20 14:01:35 +01:00
|
|
|
.ncc({ packageName: 'acorn', externals })
|
2023-01-03 10:05:50 +01:00
|
|
|
.target('src/compiled/acorn')
|
2021-12-20 14:01:35 +01:00
|
|
|
}
|
|
|
|
|
2023-02-17 15:10:09 +01:00
|
|
|
// eslint-disable-next-line camelcase
|
|
|
|
externals['@edge-runtime/cookies'] = 'next/dist/compiled/@edge-runtime/cookies'
|
|
|
|
|
|
|
|
export async function ncc_edge_runtime_cookies() {
|
|
|
|
// `@edge-runtime/cookies` is precompiled and pre-bundled
|
|
|
|
// so we vendor the package as it is.
|
|
|
|
const dest = 'src/compiled/@edge-runtime/cookies'
|
2023-10-06 00:01:45 +02:00
|
|
|
const pkg = await readJson(
|
2023-02-17 15:10:09 +01:00
|
|
|
require.resolve('@edge-runtime/cookies/package.json')
|
|
|
|
)
|
2023-10-06 00:01:45 +02:00
|
|
|
await rmrf(dest)
|
|
|
|
await fs.mkdir(dest, { recursive: true })
|
2023-02-17 15:10:09 +01:00
|
|
|
|
2023-10-06 00:01:45 +02:00
|
|
|
await writeJson(join(dest, 'package.json'), {
|
2023-02-17 15:10:09 +01:00
|
|
|
name: '@edge-runtime/cookies',
|
|
|
|
version: pkg.version,
|
|
|
|
main: './index.js',
|
|
|
|
license: pkg.license,
|
|
|
|
})
|
|
|
|
|
2023-10-06 00:01:45 +02:00
|
|
|
await fs.cp(
|
2023-02-17 15:10:09 +01:00
|
|
|
require.resolve('@edge-runtime/cookies/dist/index.js'),
|
|
|
|
join(dest, 'index.js')
|
|
|
|
)
|
2023-10-06 00:01:45 +02:00
|
|
|
await fs.cp(
|
2023-02-17 15:10:09 +01:00
|
|
|
require.resolve('@edge-runtime/cookies/dist/index.d.ts'),
|
|
|
|
join(dest, 'index.d.ts')
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
2022-05-30 14:01:36 +02:00
|
|
|
// eslint-disable-next-line camelcase
|
|
|
|
externals['@edge-runtime/primitives'] =
|
|
|
|
'next/dist/compiled/@edge-runtime/primitives'
|
|
|
|
|
|
|
|
export async function ncc_edge_runtime_primitives() {
|
|
|
|
// `@edge-runtime/primitives` is precompiled and pre-bundled
|
|
|
|
// so we vendor the package as it is.
|
2023-01-03 10:05:50 +01:00
|
|
|
const dest = 'src/compiled/@edge-runtime/primitives'
|
2023-10-06 00:01:45 +02:00
|
|
|
await fs.mkdir(dest, { recursive: true })
|
2023-05-31 10:03:20 +02:00
|
|
|
const primitivesPath = dirname(
|
|
|
|
require.resolve('@edge-runtime/primitives/package.json')
|
|
|
|
)
|
2023-10-06 00:01:45 +02:00
|
|
|
const pkg = await readJson(
|
2022-05-30 14:01:36 +02:00
|
|
|
require.resolve('@edge-runtime/primitives/package.json')
|
|
|
|
)
|
2023-10-06 00:01:45 +02:00
|
|
|
await rmrf(dest)
|
2022-07-21 20:29:19 +02:00
|
|
|
|
2023-05-31 10:03:20 +02:00
|
|
|
for (const file of await fs.readdir(join(primitivesPath, 'types'))) {
|
2023-10-06 00:01:45 +02:00
|
|
|
await fs.cp(join(primitivesPath, 'types', file), join(dest, file))
|
2023-05-31 10:03:20 +02:00
|
|
|
}
|
2022-07-21 20:29:19 +02:00
|
|
|
|
2023-05-31 10:03:20 +02:00
|
|
|
for (const file of await fs.readdir(join(primitivesPath, 'dist'))) {
|
2023-10-06 00:01:45 +02:00
|
|
|
await fs.cp(join(primitivesPath, 'dist', file), join(dest, file))
|
2022-07-21 20:29:19 +02:00
|
|
|
}
|
|
|
|
|
2023-10-06 00:01:45 +02:00
|
|
|
await writeJson(join(dest, 'package.json'), {
|
2022-05-30 14:01:36 +02:00
|
|
|
name: '@edge-runtime/primitives',
|
|
|
|
version: pkg.version,
|
|
|
|
main: './index.js',
|
|
|
|
license: pkg.license,
|
|
|
|
})
|
2023-10-06 00:01:45 +02:00
|
|
|
await fs.cp(
|
2022-05-30 14:01:36 +02:00
|
|
|
require.resolve('@edge-runtime/primitives'),
|
|
|
|
join(dest, 'index.js')
|
|
|
|
)
|
2023-10-06 00:01:45 +02:00
|
|
|
await fs.cp(
|
2023-05-31 10:03:20 +02:00
|
|
|
require.resolve('@edge-runtime/primitives/types/index.d.ts'),
|
|
|
|
join(dest, 'index.d.ts')
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
// eslint-disable-next-line camelcase
|
|
|
|
externals['@edge-runtime/ponyfill'] =
|
|
|
|
'next/dist/compiled/@edge-runtime/ponyfill'
|
|
|
|
export async function ncc_edge_runtime_ponyfill(task, opts) {
|
|
|
|
const indexFile = await fs.readFile(
|
|
|
|
require.resolve('@edge-runtime/ponyfill/src/index.js'),
|
|
|
|
'utf8'
|
|
|
|
)
|
2023-10-06 00:01:45 +02:00
|
|
|
const dest = 'src/compiled/@edge-runtime/ponyfill'
|
|
|
|
await fs.mkdir(dest, { recursive: true })
|
|
|
|
await fs.writeFile(
|
|
|
|
join(dest, 'index.js'),
|
2023-05-31 10:03:20 +02:00
|
|
|
indexFile.replace(
|
|
|
|
`require('@edge-runtime/primitives')`,
|
|
|
|
`require(${JSON.stringify(externals['@edge-runtime/primitives'])})`
|
|
|
|
)
|
|
|
|
)
|
2023-10-06 00:01:45 +02:00
|
|
|
await fs.cp(
|
2023-05-31 10:03:20 +02:00
|
|
|
require.resolve('@edge-runtime/ponyfill/src/index.d.ts'),
|
2023-10-06 00:01:45 +02:00
|
|
|
join(dest, 'index.d.ts')
|
2023-05-31 10:03:20 +02:00
|
|
|
)
|
|
|
|
|
2023-10-06 00:01:45 +02:00
|
|
|
const pkg = await readJson(
|
2023-05-31 10:03:20 +02:00
|
|
|
require.resolve('@edge-runtime/ponyfill/package.json')
|
|
|
|
)
|
|
|
|
|
2023-10-06 00:01:45 +02:00
|
|
|
await writeJson(join(dest, 'package.json'), {
|
2023-05-31 10:03:20 +02:00
|
|
|
name: '@edge-runtime/ponyfill',
|
|
|
|
version: pkg.version,
|
|
|
|
main: './index.js',
|
|
|
|
types: './index.d.ts',
|
|
|
|
license: pkg.license,
|
|
|
|
})
|
2022-05-30 14:01:36 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// eslint-disable-next-line camelcase
|
|
|
|
externals['edge-runtime'] = 'next/dist/compiled/edge-runtime'
|
|
|
|
export async function ncc_edge_runtime(task, opts) {
|
2022-07-21 20:29:19 +02:00
|
|
|
const vmPath = resolveFrom(
|
|
|
|
dirname(require.resolve('edge-runtime')),
|
|
|
|
'@edge-runtime/vm/dist/edge-vm'
|
|
|
|
)
|
|
|
|
|
|
|
|
const content = await fs.readFile(vmPath, 'utf8')
|
|
|
|
|
|
|
|
// ensure ncc doesn't attempt to bundle dynamic requires
|
|
|
|
// so that they work at runtime correctly
|
|
|
|
await fs.writeFile(
|
|
|
|
vmPath,
|
|
|
|
content.replace(
|
|
|
|
/require\.resolve\('@edge-runtime\/primitives/g,
|
|
|
|
`__non_webpack_require__.resolve('next/dist/compiled/@edge-runtime/primitives`
|
|
|
|
)
|
|
|
|
)
|
|
|
|
|
2022-05-30 14:01:36 +02:00
|
|
|
await task
|
2023-01-03 10:05:50 +01:00
|
|
|
.source(relative(__dirname, require.resolve('edge-runtime')))
|
2022-05-30 14:01:36 +02:00
|
|
|
.ncc({ packageName: 'edge-runtime', externals })
|
2023-01-03 10:05:50 +01:00
|
|
|
.target('src/compiled/edge-runtime')
|
2022-07-26 17:47:34 +02:00
|
|
|
|
2023-01-03 10:05:50 +01:00
|
|
|
const outputFile = join(__dirname, 'src/compiled/edge-runtime/index.js')
|
2022-07-26 17:47:34 +02:00
|
|
|
|
|
|
|
await fs.writeFile(
|
|
|
|
outputFile,
|
|
|
|
(
|
|
|
|
await fs.readFile(outputFile, 'utf8')
|
|
|
|
).replace(/eval\("require"\)/g, 'require')
|
|
|
|
)
|
2022-05-30 14:01:36 +02:00
|
|
|
}
|
|
|
|
|
2023-02-16 15:33:39 +01:00
|
|
|
// eslint-disable-next-line camelcase
|
|
|
|
export async function ncc_next_font(task, opts) {
|
|
|
|
// `@next/font` can be copied as is, its only dependency is already NCCed
|
|
|
|
const destDir = join(__dirname, 'dist/compiled/@next/font')
|
|
|
|
const pkgPath = require.resolve('@next/font/package.json')
|
2023-10-06 00:01:45 +02:00
|
|
|
const pkg = await readJson(pkgPath)
|
2023-02-16 15:33:39 +01:00
|
|
|
const srcDir = dirname(pkgPath)
|
2023-10-06 00:01:45 +02:00
|
|
|
await rmrf(destDir)
|
|
|
|
await fs.mkdir(destDir, { recursive: true })
|
2023-02-16 15:33:39 +01:00
|
|
|
|
|
|
|
const files = glob.sync('{dist,google,local}/**/*.{js,json,d.ts}', {
|
|
|
|
cwd: srcDir,
|
|
|
|
})
|
|
|
|
|
|
|
|
for (const file of files) {
|
|
|
|
const outputFile = join(destDir, file)
|
2023-10-06 00:01:45 +02:00
|
|
|
await fs.mkdir(dirname(outputFile), { recursive: true })
|
|
|
|
await fs.cp(join(srcDir, file), outputFile)
|
2023-02-16 15:33:39 +01:00
|
|
|
}
|
|
|
|
|
2023-10-06 00:01:45 +02:00
|
|
|
await writeJson(join(destDir, 'package.json'), {
|
2023-02-16 15:33:39 +01:00
|
|
|
name: '@next/font',
|
|
|
|
license: pkg.license,
|
|
|
|
types: pkg.types,
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2021-12-21 16:13:45 +01:00
|
|
|
// eslint-disable-next-line camelcase
|
2024-01-08 19:45:19 +01:00
|
|
|
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')
|
|
|
|
}
|
2021-12-21 16:13:45 +01:00
|
|
|
|
2022-01-17 16:17:22 +01:00
|
|
|
// eslint-disable-next-line camelcase
|
|
|
|
externals['jest-worker'] = 'next/dist/compiled/jest-worker'
|
|
|
|
export async function ncc_jest_worker(task, opts) {
|
2023-10-06 00:01:45 +02:00
|
|
|
await rmrf(join(__dirname, 'src/compiled/jest-worker'))
|
|
|
|
await fs.mkdir(join(__dirname, 'src/compiled/jest-worker/workers'), {
|
|
|
|
recursive: true,
|
|
|
|
})
|
2022-01-17 16:17:22 +01:00
|
|
|
|
|
|
|
const workers = ['processChild.js', 'threadChild.js']
|
|
|
|
|
|
|
|
await task
|
2023-01-03 10:05:50 +01:00
|
|
|
.source(relative(__dirname, require.resolve('jest-worker')))
|
2022-01-17 16:17:22 +01:00
|
|
|
.ncc({ packageName: 'jest-worker', externals })
|
2023-01-03 10:05:50 +01:00
|
|
|
.target('src/compiled/jest-worker')
|
2022-01-17 16:17:22 +01:00
|
|
|
|
|
|
|
for (const worker of workers) {
|
|
|
|
const content = await fs.readFile(
|
|
|
|
join(
|
|
|
|
dirname(require.resolve('jest-worker/package.json')),
|
|
|
|
'build/workers',
|
|
|
|
worker
|
|
|
|
),
|
|
|
|
'utf8'
|
|
|
|
)
|
|
|
|
await fs.writeFile(
|
|
|
|
join(
|
|
|
|
dirname(require.resolve('jest-worker/package.json')),
|
|
|
|
'build/workers',
|
|
|
|
worker + '.tmp.js'
|
|
|
|
),
|
|
|
|
content.replace(/require\(file\)/g, '__non_webpack_require__(file)')
|
|
|
|
)
|
|
|
|
await task
|
|
|
|
.source(
|
2023-01-03 10:05:50 +01:00
|
|
|
relative(
|
|
|
|
__dirname,
|
|
|
|
join(
|
|
|
|
dirname(require.resolve('jest-worker/package.json')),
|
|
|
|
'build/workers',
|
|
|
|
worker + '.tmp.js'
|
2022-01-17 16:17:22 +01:00
|
|
|
)
|
2023-01-03 10:05:50 +01:00
|
|
|
)
|
2022-01-17 16:17:22 +01:00
|
|
|
)
|
2022-01-19 17:11:14 +01:00
|
|
|
.ncc({ externals })
|
2023-01-03 10:05:50 +01:00
|
|
|
.target('src/compiled/jest-worker/out')
|
2022-01-17 16:17:22 +01:00
|
|
|
|
2023-10-06 00:01:45 +02:00
|
|
|
await fs.rename(
|
2023-01-03 10:05:50 +01:00
|
|
|
join(__dirname, 'src/compiled/jest-worker/out', worker + '.tmp.js'),
|
2023-10-06 00:01:45 +02:00
|
|
|
join(__dirname, 'src/compiled/jest-worker', worker)
|
2022-01-17 16:17:22 +01:00
|
|
|
)
|
|
|
|
}
|
2023-10-06 00:01:45 +02:00
|
|
|
await rmrf(join(__dirname, 'src/compiled/jest-worker/workers'))
|
|
|
|
await rmrf(join(__dirname, 'src/compiled/jest-worker/out'))
|
2022-01-17 16:17:22 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// eslint-disable-next-line camelcase
|
|
|
|
export async function ncc_react_refresh_utils(task, opts) {
|
2023-10-06 00:01:45 +02:00
|
|
|
await rmrf(join(__dirname, 'dist/compiled/react-refresh'))
|
|
|
|
await fs.cp(
|
2022-01-17 16:17:22 +01:00
|
|
|
dirname(require.resolve('react-refresh/package.json')),
|
2023-10-06 00:01:45 +02:00
|
|
|
join(__dirname, 'dist/compiled/react-refresh'),
|
|
|
|
{ recursive: true, force: true }
|
2022-01-17 16:17:22 +01:00
|
|
|
)
|
|
|
|
|
2022-05-31 02:05:27 +02:00
|
|
|
const srcDir = join(
|
|
|
|
dirname(require.resolve('@next/react-refresh-utils/package.json')),
|
|
|
|
'dist'
|
|
|
|
)
|
|
|
|
const destDir = join(
|
|
|
|
__dirname,
|
|
|
|
'dist/compiled/@next/react-refresh-utils/dist'
|
2022-01-17 16:17:22 +01:00
|
|
|
)
|
2023-10-06 00:01:45 +02:00
|
|
|
await rmrf(destDir)
|
|
|
|
await fs.mkdir(destDir, { recursive: true })
|
2022-01-17 16:17:22 +01:00
|
|
|
|
|
|
|
const files = glob.sync('**/*.{js,json}', { cwd: srcDir })
|
|
|
|
|
|
|
|
for (const file of files) {
|
|
|
|
if (file === 'tsconfig.json') continue
|
|
|
|
|
|
|
|
const content = await fs.readFile(join(srcDir, file), 'utf8')
|
|
|
|
const outputFile = join(destDir, file)
|
|
|
|
|
2023-10-06 00:01:45 +02:00
|
|
|
await fs.mkdir(dirname(outputFile), { recursive: true })
|
2022-01-17 16:17:22 +01:00
|
|
|
await fs.writeFile(
|
|
|
|
outputFile,
|
|
|
|
content.replace(
|
|
|
|
/react-refresh\/runtime/g,
|
|
|
|
'next/dist/compiled/react-refresh/runtime'
|
|
|
|
)
|
|
|
|
)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-12-21 16:13:45 +01:00
|
|
|
// eslint-disable-next-line camelcase
|
|
|
|
externals['browserslist'] = 'next/dist/compiled/browserslist'
|
|
|
|
export async function ncc_browserslist(task, opts) {
|
2022-02-02 20:23:51 +01:00
|
|
|
const browserslistModule = require.resolve('browserslist')
|
|
|
|
const nodeFile = join(dirname(browserslistModule), 'node.js')
|
|
|
|
|
|
|
|
const content = await fs.readFile(nodeFile, 'utf8')
|
|
|
|
// ensure ncc doesn't attempt to bundle dynamic requires
|
|
|
|
// so that they work at runtime correctly
|
|
|
|
await fs.writeFile(
|
|
|
|
nodeFile,
|
|
|
|
content.replace(
|
|
|
|
/require\(require\.resolve\(/g,
|
|
|
|
`__non_webpack_require__(__non_webpack_require__.resolve(`
|
|
|
|
)
|
|
|
|
)
|
|
|
|
|
2021-12-21 16:13:45 +01:00
|
|
|
await task
|
2023-01-03 10:05:50 +01:00
|
|
|
.source(relative(__dirname, require.resolve('browserslist')))
|
2021-12-21 16:13:45 +01:00
|
|
|
.ncc({ packageName: 'browserslist', externals })
|
2023-01-03 10:05:50 +01:00
|
|
|
.target('src/compiled/browserslist')
|
2022-02-02 20:23:51 +01:00
|
|
|
|
|
|
|
await fs.writeFile(nodeFile, content)
|
2021-12-21 16:13:45 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// eslint-disable-next-line camelcase
|
|
|
|
externals['@napi-rs/triples'] = 'next/dist/compiled/@napi-rs/triples'
|
|
|
|
export async function ncc_napirs_triples(task, opts) {
|
|
|
|
await task
|
2023-01-03 10:05:50 +01:00
|
|
|
.source(relative(__dirname, require.resolve('@napi-rs/triples')))
|
2021-12-21 16:13:45 +01:00
|
|
|
.ncc({ packageName: '@napi-rs/triples', externals })
|
2023-01-03 10:05:50 +01:00
|
|
|
.target('src/compiled/@napi-rs/triples')
|
2021-12-21 16:13:45 +01:00
|
|
|
}
|
|
|
|
|
2021-12-20 14:01:35 +01:00
|
|
|
// eslint-disable-next-line camelcase
|
|
|
|
externals['p-limit'] = 'next/dist/compiled/p-limit'
|
|
|
|
export async function ncc_p_limit(task, opts) {
|
|
|
|
await task
|
2023-01-03 10:05:50 +01:00
|
|
|
.source(relative(__dirname, require.resolve('p-limit')))
|
2021-12-20 14:01:35 +01:00
|
|
|
.ncc({ packageName: 'p-limit', externals })
|
2023-01-03 10:05:50 +01:00
|
|
|
.target('src/compiled/p-limit')
|
2021-12-20 14:01:35 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// eslint-disable-next-line camelcase
|
|
|
|
externals['raw-body'] = 'next/dist/compiled/raw-body'
|
|
|
|
export async function ncc_raw_body(task, opts) {
|
|
|
|
await task
|
2023-01-03 10:05:50 +01:00
|
|
|
.source(relative(__dirname, require.resolve('raw-body')))
|
2021-12-20 14:01:35 +01:00
|
|
|
.ncc({ packageName: 'raw-body', externals })
|
2023-01-03 10:05:50 +01:00
|
|
|
.target('src/compiled/raw-body')
|
2021-12-20 14:01:35 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// eslint-disable-next-line camelcase
|
|
|
|
externals['image-size'] = 'next/dist/compiled/image-size'
|
|
|
|
export async function ncc_image_size(task, opts) {
|
|
|
|
await task
|
2023-01-03 10:05:50 +01:00
|
|
|
.source(relative(__dirname, require.resolve('image-size')))
|
2021-12-20 14:01:35 +01:00
|
|
|
.ncc({ packageName: 'image-size', externals })
|
2023-01-03 10:05:50 +01:00
|
|
|
.target('src/compiled/image-size')
|
2021-12-20 14:01:35 +01:00
|
|
|
}
|
|
|
|
|
2024-02-08 12:00:34 +01:00
|
|
|
// eslint-disable-next-line camelcase
|
|
|
|
externals['get-orientation'] = 'next/dist/compiled/get-orientation'
|
|
|
|
export async function ncc_get_orientation(task, opts) {
|
|
|
|
await task
|
|
|
|
.source(relative(__dirname, require.resolve('get-orientation')))
|
|
|
|
.ncc({ packageName: 'get-orientation', externals })
|
|
|
|
.target('src/compiled/get-orientation')
|
|
|
|
}
|
|
|
|
|
2021-12-20 14:01:35 +01:00
|
|
|
// eslint-disable-next-line camelcase
|
|
|
|
externals['@hapi/accept'] = 'next/dist/compiled/@hapi/accept'
|
|
|
|
export async function ncc_hapi_accept(task, opts) {
|
|
|
|
await task
|
2023-01-03 10:05:50 +01:00
|
|
|
.source(relative(__dirname, require.resolve('@hapi/accept')))
|
2021-12-20 14:01:35 +01:00
|
|
|
.ncc({ packageName: '@hapi/accept', externals })
|
2023-01-03 10:05:50 +01:00
|
|
|
.target('src/compiled/@hapi/accept')
|
2021-12-20 14:01:35 +01:00
|
|
|
}
|
|
|
|
|
2020-03-29 00:31:06 +01:00
|
|
|
// eslint-disable-next-line camelcase
|
2020-03-30 00:41:15 +02:00
|
|
|
externals['amphtml-validator'] = 'next/dist/compiled/amphtml-validator'
|
2020-03-29 00:31:06 +01:00
|
|
|
export async function ncc_amphtml_validator(task, opts) {
|
|
|
|
await task
|
2023-01-03 10:05:50 +01:00
|
|
|
.source(relative(__dirname, require.resolve('amphtml-validator')))
|
2020-03-29 18:16:32 +02:00
|
|
|
.ncc({ packageName: 'amphtml-validator', externals })
|
2023-01-03 10:05:50 +01:00
|
|
|
.target('src/compiled/amphtml-validator')
|
2020-03-29 00:31:06 +01:00
|
|
|
}
|
2021-12-20 14:01:35 +01:00
|
|
|
|
|
|
|
// eslint-disable-next-line camelcase
|
|
|
|
export async function ncc_assert(task, opts) {
|
|
|
|
await task
|
2023-01-03 10:05:50 +01:00
|
|
|
.source(relative(__dirname, require.resolve('assert/')))
|
2021-12-20 14:01:35 +01:00
|
|
|
.ncc({
|
|
|
|
packageName: 'assert',
|
|
|
|
externals,
|
|
|
|
mainFields: ['browser', 'main'],
|
|
|
|
target: 'es5',
|
|
|
|
})
|
2023-01-03 10:05:50 +01:00
|
|
|
.target('src/compiled/assert')
|
2021-12-20 14:01:35 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// eslint-disable-next-line camelcase
|
|
|
|
export async function ncc_browser_zlib(task, opts) {
|
|
|
|
await task
|
2023-01-03 10:05:50 +01:00
|
|
|
.source(relative(__dirname, require.resolve('browserify-zlib/')))
|
2021-12-20 14:01:35 +01:00
|
|
|
.ncc({
|
|
|
|
packageName: 'browserify-zlib',
|
|
|
|
externals,
|
|
|
|
mainFields: ['browser', 'main'],
|
|
|
|
target: 'es5',
|
|
|
|
})
|
2023-01-03 10:05:50 +01:00
|
|
|
.target('src/compiled/browserify-zlib')
|
2021-12-20 14:01:35 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// eslint-disable-next-line camelcase
|
|
|
|
export async function ncc_buffer(task, opts) {
|
|
|
|
await task
|
2023-01-03 10:05:50 +01:00
|
|
|
.source(relative(__dirname, require.resolve('buffer/')))
|
2021-12-20 14:01:35 +01:00
|
|
|
.ncc({
|
|
|
|
packageName: 'buffer',
|
|
|
|
externals,
|
|
|
|
mainFields: ['browser', 'main'],
|
|
|
|
target: 'es5',
|
|
|
|
})
|
2023-01-03 10:05:50 +01:00
|
|
|
.target('src/compiled/buffer')
|
2021-12-20 14:01:35 +01:00
|
|
|
}
|
|
|
|
|
2022-01-17 16:17:22 +01:00
|
|
|
// eslint-disable-next-line camelcase
|
|
|
|
export async function copy_react_is(task, opts) {
|
|
|
|
await task
|
|
|
|
.source(join(dirname(require.resolve('react-is/package.json')), '**/*'))
|
2023-01-03 10:05:50 +01:00
|
|
|
.target('src/compiled/react-is')
|
2022-01-17 16:17:22 +01:00
|
|
|
}
|
|
|
|
|
2021-12-20 14:01:35 +01:00
|
|
|
// eslint-disable-next-line camelcase
|
|
|
|
export async function copy_constants_browserify(task, opts) {
|
2023-01-03 10:05:50 +01:00
|
|
|
await fs.mkdir(join(__dirname, 'src/compiled/constants-browserify'), {
|
2021-12-20 14:01:35 +01:00
|
|
|
recursive: true,
|
|
|
|
})
|
2023-10-06 00:01:45 +02:00
|
|
|
await writeJson(
|
2023-01-03 10:05:50 +01:00
|
|
|
join(__dirname, 'src/compiled/constants-browserify/package.json'),
|
2023-10-06 00:01:45 +02:00
|
|
|
{ name: 'constants-browserify', main: './constants.json' }
|
2021-12-20 14:01:35 +01:00
|
|
|
)
|
|
|
|
await task
|
|
|
|
.source(require.resolve('constants-browserify'))
|
2023-01-03 10:05:50 +01:00
|
|
|
.target('src/compiled/constants-browserify')
|
2021-12-20 14:01:35 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// eslint-disable-next-line camelcase
|
|
|
|
export async function ncc_crypto_browserify(task, opts) {
|
|
|
|
await task
|
2023-01-03 10:05:50 +01:00
|
|
|
.source(relative(__dirname, require.resolve('crypto-browserify/')))
|
2021-12-20 14:01:35 +01:00
|
|
|
.ncc({
|
|
|
|
packageName: 'crypto-browserify',
|
|
|
|
externals,
|
|
|
|
mainFields: ['browser', 'main'],
|
|
|
|
target: 'es5',
|
|
|
|
})
|
2023-01-03 10:05:50 +01:00
|
|
|
.target('src/compiled/crypto-browserify')
|
2021-12-20 14:01:35 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// eslint-disable-next-line camelcase
|
|
|
|
export async function ncc_domain_browser(task, opts) {
|
|
|
|
await task
|
2023-01-03 10:05:50 +01:00
|
|
|
.source(relative(__dirname, require.resolve('domain-browser/')))
|
2021-12-20 14:01:35 +01:00
|
|
|
.ncc({
|
|
|
|
packageName: 'domain-browser',
|
|
|
|
externals,
|
|
|
|
mainFields: ['browser', 'main'],
|
|
|
|
target: 'es5',
|
|
|
|
})
|
2023-01-03 10:05:50 +01:00
|
|
|
.target('src/compiled/domain-browser')
|
2021-12-20 14:01:35 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// eslint-disable-next-line camelcase
|
|
|
|
export async function ncc_events(task, opts) {
|
|
|
|
await task
|
2023-01-03 10:05:50 +01:00
|
|
|
.source(relative(__dirname, require.resolve('events/')))
|
2021-12-20 14:01:35 +01:00
|
|
|
.ncc({
|
|
|
|
packageName: 'events',
|
|
|
|
externals,
|
|
|
|
mainFields: ['browser', 'main'],
|
|
|
|
target: 'es5',
|
|
|
|
})
|
2023-01-03 10:05:50 +01:00
|
|
|
.target('src/compiled/events')
|
2021-12-20 14:01:35 +01:00
|
|
|
}
|
|
|
|
|
2022-01-17 16:17:22 +01:00
|
|
|
// eslint-disable-next-line camelcase
|
|
|
|
export async function ncc_stream_browserify(task, opts) {
|
|
|
|
await task
|
2023-01-03 10:05:50 +01:00
|
|
|
.source(relative(__dirname, require.resolve('stream-browserify/')))
|
2022-01-17 16:17:22 +01:00
|
|
|
.ncc({
|
|
|
|
packageName: 'stream-browserify',
|
|
|
|
mainFields: ['browser', 'main'],
|
|
|
|
target: 'es5',
|
|
|
|
})
|
2023-01-03 10:05:50 +01:00
|
|
|
.target('src/compiled/stream-browserify')
|
2022-01-17 16:17:22 +01:00
|
|
|
|
|
|
|
// while ncc'ing readable-stream the browser mapping does not replace the
|
|
|
|
// require('stream') with require('events').EventEmitter correctly so we
|
|
|
|
// patch this manually as leaving require('stream') causes a circular
|
|
|
|
// reference breaking the browser polyfill
|
2023-01-03 10:05:50 +01:00
|
|
|
const outputFile = join(__dirname, 'src/compiled/stream-browserify/index.js')
|
2022-01-17 16:17:22 +01:00
|
|
|
|
2023-10-06 00:01:45 +02:00
|
|
|
await fs.writeFile(
|
2022-01-17 16:17:22 +01:00
|
|
|
outputFile,
|
2023-10-06 00:01:45 +02:00
|
|
|
(
|
|
|
|
await fs.readFile(outputFile, 'utf8')
|
|
|
|
).replace(`require("stream")`, `require("events").EventEmitter`)
|
2022-01-17 16:17:22 +01:00
|
|
|
)
|
|
|
|
}
|
|
|
|
|
2021-12-20 14:01:35 +01:00
|
|
|
// eslint-disable-next-line camelcase
|
|
|
|
export async function ncc_stream_http(task, opts) {
|
|
|
|
await task
|
2023-01-03 10:05:50 +01:00
|
|
|
.source(relative(__dirname, require.resolve('stream-http/')))
|
2021-12-20 14:01:35 +01:00
|
|
|
.ncc({
|
|
|
|
packageName: 'stream-http',
|
|
|
|
externals,
|
|
|
|
mainFields: ['browser', 'main'],
|
|
|
|
target: 'es5',
|
|
|
|
})
|
2023-01-03 10:05:50 +01:00
|
|
|
.target('src/compiled/stream-http')
|
2021-12-20 14:01:35 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// eslint-disable-next-line camelcase
|
|
|
|
export async function ncc_https_browserify(task, opts) {
|
|
|
|
await task
|
2023-01-03 10:05:50 +01:00
|
|
|
.source(relative(__dirname, require.resolve('https-browserify/')))
|
2021-12-20 14:01:35 +01:00
|
|
|
.ncc({
|
|
|
|
packageName: 'https-browserify',
|
|
|
|
externals,
|
|
|
|
mainFields: ['browser', 'main'],
|
|
|
|
target: 'es5',
|
|
|
|
})
|
2023-01-03 10:05:50 +01:00
|
|
|
.target('src/compiled/https-browserify')
|
2021-12-20 14:01:35 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// eslint-disable-next-line camelcase
|
|
|
|
export async function ncc_os_browserify(task, opts) {
|
|
|
|
await task
|
2023-01-03 10:05:50 +01:00
|
|
|
.source(relative(__dirname, require.resolve('os-browserify/browser')))
|
2021-12-20 14:01:35 +01:00
|
|
|
.ncc({
|
|
|
|
packageName: 'os-browserify',
|
|
|
|
externals,
|
|
|
|
mainFields: ['browser', 'main'],
|
|
|
|
target: 'es5',
|
|
|
|
})
|
2023-01-03 10:05:50 +01:00
|
|
|
.target('src/compiled/os-browserify')
|
2021-12-20 14:01:35 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// eslint-disable-next-line camelcase
|
|
|
|
export async function ncc_path_browserify(task, opts) {
|
|
|
|
await task
|
2023-01-03 10:05:50 +01:00
|
|
|
.source(relative(__dirname, require.resolve('path-browserify/')))
|
2021-12-20 14:01:35 +01:00
|
|
|
.ncc({
|
|
|
|
packageName: 'path-browserify',
|
|
|
|
externals,
|
|
|
|
mainFields: ['browser', 'main'],
|
|
|
|
target: 'es5',
|
|
|
|
})
|
2023-01-03 10:05:50 +01:00
|
|
|
.target('src/compiled/path-browserify')
|
2022-05-23 19:56:00 +02:00
|
|
|
|
2023-01-03 10:05:50 +01:00
|
|
|
const filePath = join(__dirname, 'src/compiled/path-browserify/index.js')
|
2023-10-06 00:01:45 +02:00
|
|
|
const content = await fs.readFile(filePath, 'utf8')
|
2022-05-23 19:56:00 +02:00
|
|
|
|
|
|
|
// Remove process usage from path-browserify polyfill for edge-runtime
|
|
|
|
await fs.writeFile(filePath, content.replace(/process\.cwd\(\)/g, '""'))
|
2021-12-20 14:01:35 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// eslint-disable-next-line camelcase
|
|
|
|
export async function ncc_process(task, opts) {
|
|
|
|
await task
|
2023-01-03 10:05:50 +01:00
|
|
|
.source(relative(__dirname, require.resolve('process/browser')))
|
2021-12-20 14:01:35 +01:00
|
|
|
.ncc({
|
|
|
|
packageName: 'process',
|
|
|
|
externals,
|
|
|
|
mainFields: ['browser', 'main'],
|
|
|
|
target: 'es5',
|
|
|
|
})
|
2023-01-03 10:05:50 +01:00
|
|
|
.target('src/compiled/process')
|
2021-12-20 14:01:35 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// eslint-disable-next-line camelcase
|
|
|
|
export async function ncc_querystring_es3(task, opts) {
|
|
|
|
await task
|
2023-01-03 10:05:50 +01:00
|
|
|
.source(relative(__dirname, require.resolve('querystring-es3/')))
|
2021-12-20 14:01:35 +01:00
|
|
|
.ncc({
|
|
|
|
packageName: 'querystring-es3',
|
|
|
|
externals,
|
|
|
|
mainFields: ['browser', 'main'],
|
|
|
|
target: 'es5',
|
|
|
|
})
|
2023-01-03 10:05:50 +01:00
|
|
|
.target('src/compiled/querystring-es3')
|
2021-12-20 14:01:35 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// eslint-disable-next-line camelcase
|
|
|
|
export async function ncc_string_decoder(task, opts) {
|
|
|
|
await task
|
2023-01-03 10:05:50 +01:00
|
|
|
.source(relative(__dirname, require.resolve('string_decoder/')))
|
2021-12-20 14:01:35 +01:00
|
|
|
.ncc({
|
|
|
|
packageName: 'string_decoder',
|
|
|
|
externals,
|
|
|
|
mainFields: ['browser', 'main'],
|
|
|
|
target: 'es5',
|
|
|
|
})
|
2023-01-03 10:05:50 +01:00
|
|
|
.target('src/compiled/string_decoder')
|
2021-12-20 14:01:35 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// eslint-disable-next-line camelcase
|
|
|
|
export async function ncc_util(task, opts) {
|
|
|
|
await task
|
2023-01-03 10:05:50 +01:00
|
|
|
.source(relative(__dirname, require.resolve('util/')))
|
2021-12-20 14:01:35 +01:00
|
|
|
.ncc({
|
|
|
|
packageName: 'util',
|
|
|
|
externals,
|
|
|
|
mainFields: ['browser', 'main'],
|
|
|
|
target: 'es5',
|
|
|
|
})
|
2023-01-03 10:05:50 +01:00
|
|
|
.target('src/compiled/util')
|
2021-12-20 14:01:35 +01:00
|
|
|
}
|
|
|
|
|
2022-01-03 20:31:23 +01:00
|
|
|
// eslint-disable-next-line camelcase
|
|
|
|
export async function ncc_punycode(task, opts) {
|
|
|
|
await task
|
2023-01-03 10:05:50 +01:00
|
|
|
.source(relative(__dirname, require.resolve('punycode/')))
|
2022-01-03 20:31:23 +01:00
|
|
|
.ncc({
|
|
|
|
packageName: 'punycode',
|
|
|
|
externals,
|
|
|
|
mainFields: ['browser', 'main'],
|
|
|
|
target: 'es5',
|
|
|
|
})
|
2023-01-03 10:05:50 +01:00
|
|
|
.target('src/compiled/punycode')
|
2022-01-03 20:31:23 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// eslint-disable-next-line camelcase
|
|
|
|
export async function ncc_set_immediate(task, opts) {
|
|
|
|
await task
|
2023-01-03 10:05:50 +01:00
|
|
|
.source(relative(__dirname, require.resolve('setimmediate/')))
|
2022-01-03 20:31:23 +01:00
|
|
|
.ncc({
|
|
|
|
packageName: 'setimmediate',
|
|
|
|
externals,
|
|
|
|
mainFields: ['browser', 'main'],
|
|
|
|
target: 'es5',
|
|
|
|
})
|
2023-01-03 10:05:50 +01:00
|
|
|
.target('src/compiled/setimmediate')
|
2022-01-03 20:31:23 +01:00
|
|
|
}
|
|
|
|
|
2021-12-20 14:01:35 +01:00
|
|
|
// eslint-disable-next-line camelcase
|
|
|
|
export async function ncc_timers_browserify(task, opts) {
|
|
|
|
await task
|
2023-01-03 10:05:50 +01:00
|
|
|
.source(relative(__dirname, require.resolve('timers-browserify/')))
|
2021-12-20 14:01:35 +01:00
|
|
|
.ncc({
|
|
|
|
packageName: 'timers-browserify',
|
2022-01-03 20:31:23 +01:00
|
|
|
externals: {
|
|
|
|
...externals,
|
|
|
|
setimmediate: 'next/dist/compiled/setimmediate',
|
|
|
|
},
|
2021-12-20 14:01:35 +01:00
|
|
|
mainFields: ['browser', 'main'],
|
|
|
|
target: 'es5',
|
|
|
|
})
|
2023-01-03 10:05:50 +01:00
|
|
|
.target('src/compiled/timers-browserify')
|
2021-12-20 14:01:35 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// eslint-disable-next-line camelcase
|
|
|
|
export async function ncc_tty_browserify(task, opts) {
|
|
|
|
await task
|
2023-01-03 10:05:50 +01:00
|
|
|
.source(relative(__dirname, require.resolve('tty-browserify/')))
|
2021-12-20 14:01:35 +01:00
|
|
|
.ncc({
|
|
|
|
packageName: 'tty-browserify',
|
|
|
|
externals,
|
|
|
|
mainFields: ['browser', 'main'],
|
|
|
|
target: 'es5',
|
|
|
|
})
|
2023-01-03 10:05:50 +01:00
|
|
|
.target('src/compiled/tty-browserify')
|
2021-12-20 14:01:35 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// eslint-disable-next-line camelcase
|
|
|
|
export async function ncc_vm_browserify(task, opts) {
|
|
|
|
await task
|
2023-01-03 10:05:50 +01:00
|
|
|
.source(relative(__dirname, require.resolve('vm-browserify/')))
|
2021-12-20 14:01:35 +01:00
|
|
|
.ncc({
|
|
|
|
packageName: 'vm-browserify',
|
|
|
|
externals,
|
|
|
|
mainFields: ['browser', 'main'],
|
|
|
|
target: 'es5',
|
|
|
|
})
|
2023-01-03 10:05:50 +01:00
|
|
|
.target('src/compiled/vm-browserify')
|
2021-12-20 14:01:35 +01:00
|
|
|
}
|
|
|
|
|
2019-03-24 23:38:03 +01:00
|
|
|
// eslint-disable-next-line camelcase
|
2021-02-11 10:55:56 +01:00
|
|
|
externals['@ampproject/toolbox-optimizer'] =
|
|
|
|
'next/dist/compiled/@ampproject/toolbox-optimizer'
|
|
|
|
export async function ncc_amp_optimizer(task, opts) {
|
|
|
|
await task
|
|
|
|
.source(
|
2023-01-03 10:05:50 +01:00
|
|
|
relative(__dirname, require.resolve('@ampproject/toolbox-optimizer'))
|
2021-02-11 10:55:56 +01:00
|
|
|
)
|
|
|
|
.ncc({
|
|
|
|
externals,
|
|
|
|
precompiled: false,
|
|
|
|
packageName: '@ampproject/toolbox-optimizer',
|
|
|
|
})
|
|
|
|
.target('dist/compiled/@ampproject/toolbox-optimizer')
|
|
|
|
}
|
|
|
|
// eslint-disable-next-line camelcase
|
2020-03-30 00:41:15 +02:00
|
|
|
externals['async-retry'] = 'next/dist/compiled/async-retry'
|
2020-03-29 00:27:09 +01:00
|
|
|
export async function ncc_async_retry(task, opts) {
|
|
|
|
await task
|
2023-01-03 10:05:50 +01:00
|
|
|
.source(relative(__dirname, require.resolve('async-retry')))
|
2020-03-29 01:53:00 +01:00
|
|
|
.ncc({
|
|
|
|
packageName: 'async-retry',
|
2020-03-29 18:16:32 +02:00
|
|
|
externals,
|
2020-03-29 01:53:00 +01:00
|
|
|
})
|
2023-01-03 10:05:50 +01:00
|
|
|
.target('src/compiled/async-retry')
|
2020-03-29 00:27:09 +01:00
|
|
|
}
|
|
|
|
// eslint-disable-next-line camelcase
|
2020-03-30 00:41:15 +02:00
|
|
|
externals['async-sema'] = 'next/dist/compiled/async-sema'
|
2020-03-29 00:27:09 +01:00
|
|
|
export async function ncc_async_sema(task, opts) {
|
|
|
|
await task
|
2023-01-03 10:05:50 +01:00
|
|
|
.source(relative(__dirname, require.resolve('async-sema')))
|
2020-03-29 18:16:32 +02:00
|
|
|
.ncc({ packageName: 'async-sema', externals })
|
2023-01-03 10:05:50 +01:00
|
|
|
.target('src/compiled/async-sema')
|
2020-03-29 00:27:09 +01:00
|
|
|
}
|
2020-06-02 21:20:37 +02:00
|
|
|
|
2023-02-24 19:05:21 +01:00
|
|
|
externals['postcss-plugin-stub-for-cssnano-simple'] =
|
|
|
|
'next/dist/compiled/postcss-plugin-stub-for-cssnano-simple'
|
|
|
|
// eslint-disable-next-line camelcase
|
|
|
|
export async function ncc_postcss_plugin_stub_for_cssnano_simple(task, opts) {
|
|
|
|
await task
|
|
|
|
.source('src/bundles/postcss-plugin-stub/index.js')
|
|
|
|
.ncc({
|
|
|
|
externals,
|
|
|
|
})
|
|
|
|
.target('src/compiled/postcss-plugin-stub-for-cssnano-simple')
|
|
|
|
}
|
|
|
|
|
2021-08-22 21:06:58 +02:00
|
|
|
const babelCorePackages = {
|
2020-11-06 03:33:14 +01:00
|
|
|
'code-frame': 'next/dist/compiled/babel/code-frame',
|
2021-04-08 14:03:02 +02:00
|
|
|
'@babel/generator': 'next/dist/compiled/babel/generator',
|
|
|
|
'@babel/traverse': 'next/dist/compiled/babel/traverse',
|
2021-09-01 19:46:50 +02:00
|
|
|
'@babel/types': 'next/dist/compiled/babel/types',
|
2020-11-06 03:33:14 +01:00
|
|
|
'@babel/core': 'next/dist/compiled/babel/core',
|
2022-03-06 21:41:22 +01:00
|
|
|
'@babel/parser': 'next/dist/compiled/babel/parser',
|
2021-04-08 14:03:02 +02:00
|
|
|
'@babel/core/lib/config': 'next/dist/compiled/babel/core-lib-config',
|
|
|
|
'@babel/core/lib/transformation/normalize-file':
|
|
|
|
'next/dist/compiled/babel/core-lib-normalize-config',
|
|
|
|
'@babel/core/lib/transformation/normalize-opts':
|
|
|
|
'next/dist/compiled/babel/core-lib-normalize-opts',
|
|
|
|
'@babel/core/lib/transformation/block-hoist-plugin':
|
|
|
|
'next/dist/compiled/babel/core-lib-block-hoisting-plugin',
|
|
|
|
'@babel/core/lib/transformation/plugin-pass':
|
|
|
|
'next/dist/compiled/babel/core-lib-plugin-pass',
|
2020-11-06 03:33:14 +01:00
|
|
|
}
|
2024-01-22 13:53:42 +01:00
|
|
|
externals['next/dist/compiled/babel/code-frame'] =
|
|
|
|
'next/dist/compiled/babel/code-frame'
|
2020-11-06 03:33:14 +01:00
|
|
|
|
2021-08-22 21:06:58 +02:00
|
|
|
Object.assign(externals, babelCorePackages)
|
2020-11-06 03:33:14 +01:00
|
|
|
|
2021-08-22 21:06:58 +02:00
|
|
|
// eslint-disable-next-line camelcase
|
|
|
|
export async function ncc_babel_bundle(task, opts) {
|
|
|
|
const bundleExternals = {
|
|
|
|
...externals,
|
|
|
|
'next/dist/compiled/babel-packages': 'next/dist/compiled/babel-packages',
|
|
|
|
}
|
|
|
|
for (const pkg of Object.keys(babelCorePackages)) {
|
|
|
|
delete bundleExternals[pkg]
|
|
|
|
}
|
|
|
|
await task
|
2023-02-06 21:49:23 +01:00
|
|
|
.source('src/bundles/babel/bundle.js')
|
2021-08-22 21:06:58 +02:00
|
|
|
.ncc({
|
|
|
|
packageName: '@babel/core',
|
|
|
|
bundleName: 'babel',
|
|
|
|
externals: bundleExternals,
|
|
|
|
})
|
2023-01-03 10:05:50 +01:00
|
|
|
.target('src/compiled/babel')
|
2021-08-22 21:06:58 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// eslint-disable-next-line camelcase
|
2020-11-06 03:33:14 +01:00
|
|
|
export async function ncc_babel_bundle_packages(task, opts) {
|
2022-03-06 21:41:22 +01:00
|
|
|
const eslintParseFile = join(
|
|
|
|
dirname(require.resolve('@babel/eslint-parser')),
|
|
|
|
'./parse.cjs'
|
|
|
|
)
|
2023-10-06 00:01:45 +02:00
|
|
|
const content = await fs.readFile(eslintParseFile, 'utf-8')
|
2022-03-06 21:41:22 +01:00
|
|
|
// Let parser.cjs require @babel/parser directly
|
|
|
|
const replacedContent = content
|
|
|
|
.replace(
|
|
|
|
`const babelParser = require((`,
|
|
|
|
`function noop(){};\nconst babelParser = require('@babel/parser');noop((`
|
|
|
|
)
|
|
|
|
.replace(/require.resolve/g, 'noop')
|
|
|
|
await fs.writeFile(eslintParseFile, replacedContent)
|
|
|
|
|
2021-08-22 21:06:58 +02:00
|
|
|
await task
|
2023-02-06 21:49:23 +01:00
|
|
|
.source('src/bundles/babel/packages-bundle.js')
|
2021-08-22 21:06:58 +02:00
|
|
|
.ncc({
|
|
|
|
externals: externals,
|
|
|
|
})
|
2023-01-03 10:05:50 +01:00
|
|
|
.target(`src/compiled/babel-packages`)
|
2021-08-22 21:06:58 +02:00
|
|
|
|
2023-10-06 00:01:45 +02:00
|
|
|
await writeJson(join(__dirname, 'src/compiled/babel-packages/package.json'), {
|
|
|
|
name: 'babel-packages',
|
|
|
|
main: './packages-bundle.js',
|
|
|
|
})
|
2021-09-01 21:29:35 +02:00
|
|
|
|
2023-02-06 21:49:23 +01:00
|
|
|
await task.source('src/bundles/babel/packages/*').target('src/compiled/babel')
|
2020-11-06 03:33:14 +01:00
|
|
|
}
|
|
|
|
|
2023-02-24 19:05:21 +01:00
|
|
|
externals['cssnano-simple'] = 'next/dist/compiled/cssnano-simple'
|
|
|
|
// eslint-disable-next-line camelcase
|
|
|
|
export async function ncc_cssnano_simple_bundle(task, opts) {
|
|
|
|
const bundleExternals = {
|
|
|
|
...externals,
|
|
|
|
'postcss-svgo': 'next/dist/compiled/postcss-plugin-stub-for-cssnano-simple',
|
|
|
|
}
|
|
|
|
|
|
|
|
await task
|
|
|
|
.source('src/bundles/cssnano-simple/index.js')
|
|
|
|
.ncc({
|
|
|
|
externals: bundleExternals,
|
|
|
|
})
|
|
|
|
.target('src/compiled/cssnano-simple')
|
|
|
|
}
|
|
|
|
|
2022-02-25 03:04:02 +01:00
|
|
|
// eslint-disable-next-line camelcase
|
|
|
|
externals['bytes'] = 'next/dist/compiled/bytes'
|
|
|
|
export async function ncc_bytes(task, opts) {
|
|
|
|
await task
|
2023-01-03 10:05:50 +01:00
|
|
|
.source(relative(__dirname, require.resolve('bytes')))
|
2022-02-25 03:04:02 +01:00
|
|
|
.ncc({ packageName: 'bytes', externals })
|
2023-01-03 10:05:50 +01:00
|
|
|
.target('src/compiled/bytes')
|
2022-02-25 03:04:02 +01:00
|
|
|
}
|
2020-11-04 22:52:49 +01:00
|
|
|
// eslint-disable-next-line camelcase
|
2020-03-30 00:41:15 +02:00
|
|
|
externals['ci-info'] = 'next/dist/compiled/ci-info'
|
2020-03-29 00:43:52 +01:00
|
|
|
export async function ncc_ci_info(task, opts) {
|
|
|
|
await task
|
2023-01-03 10:05:50 +01:00
|
|
|
.source(relative(__dirname, require.resolve('ci-info')))
|
2020-03-29 18:16:32 +02:00
|
|
|
.ncc({ packageName: 'ci-info', externals })
|
2023-01-03 10:05:50 +01:00
|
|
|
.target('src/compiled/ci-info')
|
2020-03-29 00:43:52 +01:00
|
|
|
}
|
2021-08-04 23:53:15 +02:00
|
|
|
// eslint-disable-next-line camelcase
|
|
|
|
externals['cli-select'] = 'next/dist/compiled/cli-select'
|
|
|
|
export async function ncc_cli_select(task, opts) {
|
|
|
|
await task
|
2023-01-03 10:05:50 +01:00
|
|
|
.source(relative(__dirname, require.resolve('cli-select')))
|
2021-08-04 23:53:15 +02:00
|
|
|
.ncc({ packageName: 'cli-select', externals })
|
2023-01-03 10:05:50 +01:00
|
|
|
.target('src/compiled/cli-select')
|
2021-08-04 23:53:15 +02:00
|
|
|
}
|
2024-03-02 00:12:47 +01:00
|
|
|
externals['commmander'] = 'next/dist/compiled/commander'
|
|
|
|
export async function ncc_commander(task, opts) {
|
|
|
|
await task
|
|
|
|
.source(relative(__dirname, require.resolve('commander')))
|
|
|
|
.ncc({ packageName: 'commander', externals })
|
|
|
|
.target('src/compiled/commander')
|
|
|
|
}
|
2021-01-14 02:59:08 +01:00
|
|
|
externals['comment-json'] = 'next/dist/compiled/comment-json'
|
|
|
|
export async function ncc_comment_json(task, opts) {
|
|
|
|
await task
|
2023-01-03 10:05:50 +01:00
|
|
|
.source(relative(__dirname, require.resolve('comment-json')))
|
2021-01-14 02:59:08 +01:00
|
|
|
.ncc({ packageName: 'comment-json', externals })
|
2023-01-03 10:05:50 +01:00
|
|
|
.target('src/compiled/comment-json')
|
2021-01-14 02:59:08 +01:00
|
|
|
}
|
2020-03-29 00:43:52 +01:00
|
|
|
// eslint-disable-next-line camelcase
|
2020-03-30 00:41:15 +02:00
|
|
|
externals['compression'] = 'next/dist/compiled/compression'
|
2020-03-29 00:56:38 +01:00
|
|
|
export async function ncc_compression(task, opts) {
|
|
|
|
await task
|
2023-01-03 10:05:50 +01:00
|
|
|
.source(relative(__dirname, require.resolve('compression')))
|
2020-03-29 18:16:32 +02:00
|
|
|
.ncc({ packageName: 'compression', externals })
|
2023-01-03 10:05:50 +01:00
|
|
|
.target('src/compiled/compression')
|
2020-03-29 00:56:38 +01:00
|
|
|
}
|
|
|
|
// eslint-disable-next-line camelcase
|
2020-03-30 00:41:15 +02:00
|
|
|
externals['conf'] = 'next/dist/compiled/conf'
|
2020-03-29 17:46:33 +02:00
|
|
|
export async function ncc_conf(task, opts) {
|
|
|
|
await task
|
2023-01-03 10:05:50 +01:00
|
|
|
.source(relative(__dirname, require.resolve('conf')))
|
2020-03-29 18:16:32 +02:00
|
|
|
.ncc({ packageName: 'conf', externals })
|
2023-01-03 10:05:50 +01:00
|
|
|
.target('src/compiled/conf')
|
2020-03-29 17:46:33 +02:00
|
|
|
}
|
|
|
|
// eslint-disable-next-line camelcase
|
2021-11-02 00:23:24 +01:00
|
|
|
externals['content-disposition'] = 'next/dist/compiled/content-disposition'
|
|
|
|
export async function ncc_content_disposition(task, opts) {
|
|
|
|
await task
|
2023-01-03 10:05:50 +01:00
|
|
|
.source(relative(__dirname, require.resolve('content-disposition')))
|
2021-11-02 00:23:24 +01:00
|
|
|
.ncc({ packageName: 'content-disposition', externals })
|
2023-01-03 10:05:50 +01:00
|
|
|
.target('src/compiled/content-disposition')
|
2021-11-02 00:23:24 +01:00
|
|
|
}
|
|
|
|
// eslint-disable-next-line camelcase
|
2020-03-30 00:41:15 +02:00
|
|
|
externals['content-type'] = 'next/dist/compiled/content-type'
|
2020-03-29 00:56:38 +01:00
|
|
|
export async function ncc_content_type(task, opts) {
|
|
|
|
await task
|
2023-01-03 10:05:50 +01:00
|
|
|
.source(relative(__dirname, require.resolve('content-type')))
|
2020-03-29 18:16:32 +02:00
|
|
|
.ncc({ packageName: 'content-type', externals })
|
2023-01-03 10:05:50 +01:00
|
|
|
.target('src/compiled/content-type')
|
2020-03-29 00:56:38 +01:00
|
|
|
}
|
|
|
|
// eslint-disable-next-line camelcase
|
2020-03-30 00:41:15 +02:00
|
|
|
externals['cookie'] = 'next/dist/compiled/cookie'
|
2020-03-29 01:02:03 +01:00
|
|
|
export async function ncc_cookie(task, opts) {
|
|
|
|
await task
|
2023-01-03 10:05:50 +01:00
|
|
|
.source(relative(__dirname, require.resolve('cookie')))
|
2020-03-29 18:16:32 +02:00
|
|
|
.ncc({ packageName: 'cookie', externals })
|
2023-01-03 10:05:50 +01:00
|
|
|
.target('src/compiled/cookie')
|
2020-03-29 01:02:03 +01:00
|
|
|
}
|
|
|
|
// eslint-disable-next-line camelcase
|
2021-08-04 23:53:15 +02:00
|
|
|
externals['cross-spawn'] = 'next/dist/compiled/cross-spawn'
|
|
|
|
export async function ncc_cross_spawn(task, opts) {
|
|
|
|
await task
|
2023-01-03 10:05:50 +01:00
|
|
|
.source(relative(__dirname, require.resolve('cross-spawn')))
|
2021-08-04 23:53:15 +02:00
|
|
|
.ncc({ packageName: 'cross-spawn', externals })
|
2023-01-03 10:05:50 +01:00
|
|
|
.target('src/compiled/cross-spawn')
|
2021-08-04 23:53:15 +02:00
|
|
|
}
|
|
|
|
// eslint-disable-next-line camelcase
|
2020-04-29 17:04:42 +02:00
|
|
|
externals['debug'] = 'next/dist/compiled/debug'
|
|
|
|
export async function ncc_debug(task, opts) {
|
|
|
|
await task
|
2023-01-03 10:05:50 +01:00
|
|
|
.source(relative(__dirname, require.resolve('debug')))
|
2020-04-29 17:04:42 +02:00
|
|
|
.ncc({ packageName: 'debug', externals })
|
2023-01-03 10:05:50 +01:00
|
|
|
.target('src/compiled/debug')
|
2020-04-29 17:04:42 +02:00
|
|
|
}
|
|
|
|
// eslint-disable-next-line camelcase
|
2020-03-30 00:41:15 +02:00
|
|
|
externals['devalue'] = 'next/dist/compiled/devalue'
|
2020-03-29 01:18:22 +01:00
|
|
|
export async function ncc_devalue(task, opts) {
|
|
|
|
await task
|
2023-01-03 10:05:50 +01:00
|
|
|
.source(relative(__dirname, require.resolve('devalue')))
|
2020-03-29 18:16:32 +02:00
|
|
|
.ncc({ packageName: 'devalue', externals })
|
2023-01-03 10:05:50 +01:00
|
|
|
.target('src/compiled/devalue')
|
2020-03-29 01:18:22 +01:00
|
|
|
}
|
2021-10-25 01:54:16 +02:00
|
|
|
|
2020-11-04 22:52:49 +01:00
|
|
|
// eslint-disable-next-line camelcase
|
2020-03-30 00:41:15 +02:00
|
|
|
externals['find-up'] = 'next/dist/compiled/find-up'
|
2020-03-29 18:21:53 +02:00
|
|
|
export async function ncc_find_up(task, opts) {
|
|
|
|
await task
|
2023-01-03 10:05:50 +01:00
|
|
|
.source(relative(__dirname, require.resolve('find-up')))
|
2020-03-29 18:21:53 +02:00
|
|
|
.ncc({ packageName: 'find-up', externals })
|
2023-01-03 10:05:50 +01:00
|
|
|
.target('src/compiled/find-up')
|
2020-03-29 18:21:53 +02:00
|
|
|
}
|
|
|
|
// eslint-disable-next-line camelcase
|
2020-03-30 00:41:15 +02:00
|
|
|
externals['fresh'] = 'next/dist/compiled/fresh'
|
2020-03-29 01:27:13 +01:00
|
|
|
export async function ncc_fresh(task, opts) {
|
|
|
|
await task
|
2023-01-03 10:05:50 +01:00
|
|
|
.source(relative(__dirname, require.resolve('fresh')))
|
2020-03-29 18:16:32 +02:00
|
|
|
.ncc({ packageName: 'fresh', externals })
|
2023-01-03 10:05:50 +01:00
|
|
|
.target('src/compiled/fresh')
|
2020-03-29 01:27:13 +01:00
|
|
|
}
|
|
|
|
// eslint-disable-next-line camelcase
|
2021-08-16 21:29:11 +02:00
|
|
|
externals['glob'] = 'next/dist/compiled/glob'
|
|
|
|
export async function ncc_glob(task, opts) {
|
|
|
|
await task
|
2023-01-03 10:05:50 +01:00
|
|
|
.source(relative(__dirname, require.resolve('glob')))
|
2021-08-16 21:29:11 +02:00
|
|
|
.ncc({ packageName: 'glob', externals })
|
2023-01-03 10:05:50 +01:00
|
|
|
.target('src/compiled/glob')
|
2021-08-16 21:29:11 +02:00
|
|
|
}
|
|
|
|
// eslint-disable-next-line camelcase
|
2020-03-30 00:41:15 +02:00
|
|
|
externals['gzip-size'] = 'next/dist/compiled/gzip-size'
|
2020-03-29 01:29:14 +01:00
|
|
|
export async function ncc_gzip_size(task, opts) {
|
|
|
|
await task
|
2023-01-03 10:05:50 +01:00
|
|
|
.source(relative(__dirname, require.resolve('gzip-size')))
|
2020-03-29 18:16:32 +02:00
|
|
|
.ncc({ packageName: 'gzip-size', externals })
|
2023-01-03 10:05:50 +01:00
|
|
|
.target('src/compiled/gzip-size')
|
2020-03-29 01:29:14 +01:00
|
|
|
}
|
|
|
|
// eslint-disable-next-line camelcase
|
2020-03-30 00:41:15 +02:00
|
|
|
externals['http-proxy'] = 'next/dist/compiled/http-proxy'
|
2020-03-29 01:30:34 +01:00
|
|
|
export async function ncc_http_proxy(task, opts) {
|
|
|
|
await task
|
2023-01-03 10:05:50 +01:00
|
|
|
.source(relative(__dirname, require.resolve('http-proxy')))
|
2020-03-29 18:16:32 +02:00
|
|
|
.ncc({ packageName: 'http-proxy', externals })
|
2023-01-03 10:05:50 +01:00
|
|
|
.target('src/compiled/http-proxy')
|
2020-03-29 01:30:34 +01:00
|
|
|
}
|
|
|
|
// eslint-disable-next-line camelcase
|
2020-03-30 03:37:41 +02:00
|
|
|
externals['ignore-loader'] = 'next/dist/compiled/ignore-loader'
|
|
|
|
export async function ncc_ignore_loader(task, opts) {
|
|
|
|
await task
|
2023-01-03 10:05:50 +01:00
|
|
|
.source(relative(__dirname, require.resolve('ignore-loader')))
|
2020-03-30 03:37:41 +02:00
|
|
|
.ncc({ packageName: 'ignore-loader', externals })
|
2023-01-03 10:05:50 +01:00
|
|
|
.target('src/compiled/ignore-loader')
|
2020-03-30 03:37:41 +02:00
|
|
|
}
|
|
|
|
// eslint-disable-next-line camelcase
|
2020-10-17 21:22:10 +02:00
|
|
|
externals['is-animated'] = 'next/dist/compiled/is-animated'
|
|
|
|
export async function ncc_is_animated(task, opts) {
|
|
|
|
await task
|
2023-01-03 10:05:50 +01:00
|
|
|
.source(relative(__dirname, require.resolve('is-animated')))
|
2020-10-17 21:22:10 +02:00
|
|
|
.ncc({ packageName: 'is-animated', externals })
|
2023-01-03 10:05:50 +01:00
|
|
|
.target('src/compiled/is-animated')
|
2020-10-17 21:22:10 +02:00
|
|
|
}
|
|
|
|
// eslint-disable-next-line camelcase
|
2020-03-30 00:41:15 +02:00
|
|
|
externals['is-docker'] = 'next/dist/compiled/is-docker'
|
2020-03-29 01:33:35 +01:00
|
|
|
export async function ncc_is_docker(task, opts) {
|
|
|
|
await task
|
2023-01-03 10:05:50 +01:00
|
|
|
.source(relative(__dirname, require.resolve('is-docker')))
|
2020-03-29 18:16:32 +02:00
|
|
|
.ncc({ packageName: 'is-docker', externals })
|
2023-01-03 10:05:50 +01:00
|
|
|
.target('src/compiled/is-docker')
|
2020-03-29 01:33:35 +01:00
|
|
|
}
|
|
|
|
// eslint-disable-next-line camelcase
|
2020-03-30 00:41:15 +02:00
|
|
|
externals['is-wsl'] = 'next/dist/compiled/is-wsl'
|
2020-03-29 01:33:35 +01:00
|
|
|
export async function ncc_is_wsl(task, opts) {
|
|
|
|
await task
|
2023-01-03 10:05:50 +01:00
|
|
|
.source(relative(__dirname, require.resolve('is-wsl')))
|
2020-03-29 18:16:32 +02:00
|
|
|
.ncc({ packageName: 'is-wsl', externals })
|
2023-01-03 10:05:50 +01:00
|
|
|
.target('src/compiled/is-wsl')
|
2020-03-29 01:33:35 +01:00
|
|
|
}
|
|
|
|
// eslint-disable-next-line camelcase
|
2020-03-30 00:41:15 +02:00
|
|
|
externals['json5'] = 'next/dist/compiled/json5'
|
2020-03-29 01:36:15 +01:00
|
|
|
export async function ncc_json5(task, opts) {
|
|
|
|
await task
|
2023-01-03 10:05:50 +01:00
|
|
|
.source(relative(__dirname, require.resolve('json5')))
|
2020-03-29 18:16:32 +02:00
|
|
|
.ncc({ packageName: 'json5', externals })
|
2023-01-03 10:05:50 +01:00
|
|
|
.target('src/compiled/json5')
|
2020-03-29 01:36:15 +01:00
|
|
|
}
|
|
|
|
// eslint-disable-next-line camelcase
|
2020-03-30 00:41:15 +02:00
|
|
|
externals['jsonwebtoken'] = 'next/dist/compiled/jsonwebtoken'
|
2020-03-29 01:37:45 +01:00
|
|
|
export async function ncc_jsonwebtoken(task, opts) {
|
|
|
|
await task
|
2023-01-03 10:05:50 +01:00
|
|
|
.source(relative(__dirname, require.resolve('jsonwebtoken')))
|
2023-10-24 20:05:56 +02:00
|
|
|
.ncc({
|
|
|
|
packageName: 'jsonwebtoken',
|
|
|
|
externals: {
|
|
|
|
...externals,
|
|
|
|
semver: 'next/dist/lib/semver-noop',
|
|
|
|
},
|
|
|
|
})
|
2023-01-03 10:05:50 +01:00
|
|
|
.target('src/compiled/jsonwebtoken')
|
2020-03-29 01:37:45 +01:00
|
|
|
}
|
|
|
|
// eslint-disable-next-line camelcase
|
2023-02-18 07:24:40 +01:00
|
|
|
externals['loader-runner'] = 'next/dist/compiled/loader-runner'
|
|
|
|
export async function ncc_loader_runner(task, opts) {
|
|
|
|
await task
|
|
|
|
.source(relative(__dirname, require.resolve('loader-runner')))
|
|
|
|
.ncc({ packageName: 'loader-runner', externals })
|
|
|
|
.target('src/compiled/loader-runner')
|
|
|
|
}
|
|
|
|
// eslint-disable-next-line camelcase
|
2021-11-08 19:37:25 +01:00
|
|
|
externals['loader-utils'] = 'error loader-utils version not specified'
|
|
|
|
externals['loader-utils2'] = 'next/dist/compiled/loader-utils2'
|
|
|
|
export async function ncc_loader_utils2(task, opts) {
|
2021-01-15 02:51:45 +01:00
|
|
|
await task
|
2023-01-03 10:05:50 +01:00
|
|
|
.source(relative(__dirname, require.resolve('loader-utils2')))
|
2021-11-08 19:37:25 +01:00
|
|
|
.ncc({ packageName: 'loader-utils2', externals })
|
2023-01-03 10:05:50 +01:00
|
|
|
.target('src/compiled/loader-utils2')
|
2021-11-08 19:37:25 +01:00
|
|
|
}
|
|
|
|
// eslint-disable-next-line camelcase
|
|
|
|
externals['loader-utils3'] = 'next/dist/compiled/loader-utils3'
|
|
|
|
export async function ncc_loader_utils3(task, opts) {
|
|
|
|
await task
|
2023-01-03 10:05:50 +01:00
|
|
|
.source(relative(__dirname, require.resolve('loader-utils3')))
|
2021-11-08 19:37:25 +01:00
|
|
|
.ncc({ packageName: 'loader-utils3', externals })
|
2023-01-03 10:05:50 +01:00
|
|
|
.target('src/compiled/loader-utils3')
|
2021-01-15 02:51:45 +01:00
|
|
|
}
|
|
|
|
// eslint-disable-next-line camelcase
|
2020-03-30 00:41:15 +02:00
|
|
|
externals['lodash.curry'] = 'next/dist/compiled/lodash.curry'
|
2020-03-29 01:43:59 +01:00
|
|
|
export async function ncc_lodash_curry(task, opts) {
|
|
|
|
await task
|
2023-01-03 10:05:50 +01:00
|
|
|
.source(relative(__dirname, require.resolve('lodash.curry')))
|
2020-03-29 18:16:32 +02:00
|
|
|
.ncc({ packageName: 'lodash.curry', externals })
|
2023-01-03 10:05:50 +01:00
|
|
|
.target('src/compiled/lodash.curry')
|
2020-03-29 01:43:59 +01:00
|
|
|
}
|
|
|
|
// eslint-disable-next-line camelcase
|
2020-03-30 00:41:15 +02:00
|
|
|
externals['lru-cache'] = 'next/dist/compiled/lru-cache'
|
2020-03-29 01:46:22 +01:00
|
|
|
export async function ncc_lru_cache(task, opts) {
|
|
|
|
await task
|
2023-01-03 10:05:50 +01:00
|
|
|
.source(relative(__dirname, require.resolve('lru-cache')))
|
2020-03-29 18:16:32 +02:00
|
|
|
.ncc({ packageName: 'lru-cache', externals })
|
2023-01-03 10:05:50 +01:00
|
|
|
.target('src/compiled/lru-cache')
|
2020-03-29 01:46:22 +01:00
|
|
|
}
|
|
|
|
// eslint-disable-next-line camelcase
|
2020-03-30 00:41:15 +02:00
|
|
|
externals['nanoid'] = 'next/dist/compiled/nanoid'
|
2020-03-28 20:42:35 +01:00
|
|
|
export async function ncc_nanoid(task, opts) {
|
|
|
|
await task
|
2023-01-03 10:05:50 +01:00
|
|
|
.source(relative(__dirname, require.resolve('nanoid')))
|
2020-03-29 18:16:32 +02:00
|
|
|
.ncc({ packageName: 'nanoid', externals })
|
2023-01-03 10:05:50 +01:00
|
|
|
.target('src/compiled/nanoid')
|
2020-03-28 20:42:35 +01:00
|
|
|
}
|
|
|
|
// eslint-disable-next-line camelcase
|
2021-10-18 17:46:39 +02:00
|
|
|
externals['native-url'] = 'next/dist/compiled/native-url'
|
|
|
|
export async function ncc_native_url(task, opts) {
|
|
|
|
await task
|
2023-01-03 10:05:50 +01:00
|
|
|
.source(relative(__dirname, require.resolve('native-url')))
|
2023-02-06 20:33:38 +01:00
|
|
|
.ncc({
|
|
|
|
packageName: 'native-url',
|
|
|
|
externals: {
|
|
|
|
...externals,
|
|
|
|
querystring: 'next/dist/compiled/querystring-es3',
|
|
|
|
},
|
|
|
|
target: 'es5',
|
|
|
|
})
|
2023-01-03 10:05:50 +01:00
|
|
|
.target('src/compiled/native-url')
|
2021-10-18 17:46:39 +02:00
|
|
|
}
|
|
|
|
// eslint-disable-next-line camelcase
|
2020-11-04 22:52:49 +01:00
|
|
|
externals['neo-async'] = 'next/dist/compiled/neo-async'
|
|
|
|
export async function ncc_neo_async(task, opts) {
|
|
|
|
await task
|
2023-01-03 10:05:50 +01:00
|
|
|
.source(relative(__dirname, require.resolve('neo-async')))
|
2020-11-04 22:52:49 +01:00
|
|
|
.ncc({ packageName: 'neo-async', externals })
|
2023-01-03 10:05:50 +01:00
|
|
|
.target('src/compiled/neo-async')
|
2020-11-04 22:52:49 +01:00
|
|
|
}
|
2021-12-20 14:01:35 +01:00
|
|
|
|
2021-10-18 17:46:39 +02:00
|
|
|
// eslint-disable-next-line camelcase
|
2020-03-30 00:41:15 +02:00
|
|
|
externals['ora'] = 'next/dist/compiled/ora'
|
2020-03-29 01:53:00 +01:00
|
|
|
export async function ncc_ora(task, opts) {
|
|
|
|
await task
|
2023-01-03 10:05:50 +01:00
|
|
|
.source(relative(__dirname, require.resolve('ora')))
|
2020-03-29 18:16:32 +02:00
|
|
|
.ncc({ packageName: 'ora', externals })
|
2023-01-03 10:05:50 +01:00
|
|
|
.target('src/compiled/ora')
|
2020-03-29 01:53:00 +01:00
|
|
|
}
|
|
|
|
// eslint-disable-next-line camelcase
|
2020-03-30 04:01:30 +02:00
|
|
|
externals['postcss-flexbugs-fixes'] =
|
|
|
|
'next/dist/compiled/postcss-flexbugs-fixes'
|
|
|
|
export async function ncc_postcss_flexbugs_fixes(task, opts) {
|
|
|
|
await task
|
2023-01-03 10:05:50 +01:00
|
|
|
.source(relative(__dirname, require.resolve('postcss-flexbugs-fixes')))
|
2020-03-30 04:01:30 +02:00
|
|
|
.ncc({ packageName: 'postcss-flexbugs-fixes', externals })
|
2023-01-03 10:05:50 +01:00
|
|
|
.target('src/compiled/postcss-flexbugs-fixes')
|
2020-03-30 04:01:30 +02:00
|
|
|
}
|
|
|
|
// eslint-disable-next-line camelcase
|
2021-09-02 08:45:35 +02:00
|
|
|
export async function ncc_postcss_safe_parser(task, opts) {
|
2020-03-30 04:01:30 +02:00
|
|
|
await task
|
2023-01-03 10:05:50 +01:00
|
|
|
.source(relative(__dirname, require.resolve('postcss-safe-parser')))
|
2021-09-02 08:45:35 +02:00
|
|
|
.ncc({ packageName: 'postcss-safe-parser', externals })
|
2023-01-03 10:05:50 +01:00
|
|
|
.target('src/compiled/postcss-safe-parser')
|
2020-03-30 04:01:30 +02:00
|
|
|
}
|
|
|
|
// eslint-disable-next-line camelcase
|
|
|
|
externals['postcss-preset-env'] = 'next/dist/compiled/postcss-preset-env'
|
|
|
|
export async function ncc_postcss_preset_env(task, opts) {
|
|
|
|
await task
|
2023-01-03 10:05:50 +01:00
|
|
|
.source(relative(__dirname, require.resolve('postcss-preset-env')))
|
2020-03-30 04:01:30 +02:00
|
|
|
.ncc({ packageName: 'postcss-preset-env', externals })
|
2023-01-03 10:05:50 +01:00
|
|
|
.target('src/compiled/postcss-preset-env')
|
2020-03-30 04:01:30 +02:00
|
|
|
}
|
|
|
|
// eslint-disable-next-line camelcase
|
2020-11-14 16:03:04 +01:00
|
|
|
externals['postcss-scss'] = 'next/dist/compiled/postcss-scss'
|
|
|
|
export async function ncc_postcss_scss(task, opts) {
|
|
|
|
await task
|
2023-01-03 10:05:50 +01:00
|
|
|
.source(relative(__dirname, require.resolve('postcss-scss')))
|
2020-11-14 16:03:04 +01:00
|
|
|
.ncc({
|
|
|
|
packageName: 'postcss-scss',
|
|
|
|
externals: {
|
|
|
|
'postcss/lib/parser': 'postcss/lib/parser',
|
|
|
|
...externals,
|
|
|
|
},
|
|
|
|
})
|
2023-01-03 10:05:50 +01:00
|
|
|
.target('src/compiled/postcss-scss')
|
2020-11-14 16:03:04 +01:00
|
|
|
}
|
|
|
|
// eslint-disable-next-line camelcase
|
2021-09-02 08:45:35 +02:00
|
|
|
externals['postcss-modules-extract-imports'] =
|
|
|
|
'next/dist/compiled/postcss-modules-extract-imports'
|
|
|
|
export async function ncc_postcss_modules_extract_imports(task, opts) {
|
|
|
|
await task
|
|
|
|
.source(
|
2023-01-03 10:05:50 +01:00
|
|
|
relative(__dirname, require.resolve('postcss-modules-extract-imports'))
|
2021-09-02 08:45:35 +02:00
|
|
|
)
|
|
|
|
.ncc({
|
|
|
|
packageName: 'postcss-modules-extract-imports',
|
|
|
|
externals: {
|
|
|
|
'postcss/lib/parser': 'postcss/lib/parser',
|
|
|
|
...externals,
|
|
|
|
},
|
|
|
|
})
|
2023-01-03 10:05:50 +01:00
|
|
|
.target('src/compiled/postcss-modules-extract-imports')
|
2021-09-02 08:45:35 +02:00
|
|
|
}
|
|
|
|
// eslint-disable-next-line camelcase
|
|
|
|
externals['postcss-modules-local-by-default'] =
|
|
|
|
'next/dist/compiled/postcss-modules-local-by-default'
|
|
|
|
export async function ncc_postcss_modules_local_by_default(task, opts) {
|
|
|
|
await task
|
|
|
|
.source(
|
2023-01-03 10:05:50 +01:00
|
|
|
relative(__dirname, require.resolve('postcss-modules-local-by-default'))
|
2021-09-02 08:45:35 +02:00
|
|
|
)
|
|
|
|
.ncc({
|
|
|
|
packageName: 'postcss-modules-local-by-default',
|
|
|
|
externals: {
|
|
|
|
'postcss/lib/parser': 'postcss/lib/parser',
|
|
|
|
...externals,
|
|
|
|
},
|
|
|
|
})
|
2023-01-03 10:05:50 +01:00
|
|
|
.target('src/compiled/postcss-modules-local-by-default')
|
2021-09-02 08:45:35 +02:00
|
|
|
}
|
|
|
|
// eslint-disable-next-line camelcase
|
|
|
|
externals['postcss-modules-scope'] = 'next/dist/compiled/postcss-modules-scope'
|
|
|
|
export async function ncc_postcss_modules_scope(task, opts) {
|
|
|
|
await task
|
2023-01-03 10:05:50 +01:00
|
|
|
.source(relative(__dirname, require.resolve('postcss-modules-scope')))
|
2021-09-02 08:45:35 +02:00
|
|
|
.ncc({
|
|
|
|
packageName: 'postcss-modules-scope',
|
|
|
|
externals: {
|
|
|
|
'postcss/lib/parser': 'postcss/lib/parser',
|
|
|
|
...externals,
|
|
|
|
},
|
|
|
|
})
|
2023-01-03 10:05:50 +01:00
|
|
|
.target('src/compiled/postcss-modules-scope')
|
2021-09-02 08:45:35 +02:00
|
|
|
}
|
|
|
|
// eslint-disable-next-line camelcase
|
|
|
|
externals['postcss-modules-values'] =
|
|
|
|
'next/dist/compiled/postcss-modules-values'
|
|
|
|
export async function ncc_postcss_modules_values(task, opts) {
|
|
|
|
await task
|
2023-01-03 10:05:50 +01:00
|
|
|
.source(relative(__dirname, require.resolve('postcss-modules-values')))
|
2021-09-02 08:45:35 +02:00
|
|
|
.ncc({
|
|
|
|
packageName: 'postcss-modules-values',
|
|
|
|
externals: {
|
|
|
|
'postcss/lib/parser': 'postcss/lib/parser',
|
|
|
|
...externals,
|
|
|
|
},
|
|
|
|
})
|
2023-01-03 10:05:50 +01:00
|
|
|
.target('src/compiled/postcss-modules-values')
|
2021-09-02 08:45:35 +02:00
|
|
|
}
|
|
|
|
// eslint-disable-next-line camelcase
|
|
|
|
externals['postcss-value-parser'] = 'next/dist/compiled/postcss-value-parser'
|
|
|
|
export async function ncc_postcss_value_parser(task, opts) {
|
|
|
|
await task
|
2023-01-03 10:05:50 +01:00
|
|
|
.source(relative(__dirname, require.resolve('postcss-value-parser')))
|
2021-09-02 08:45:35 +02:00
|
|
|
.ncc({
|
|
|
|
packageName: 'postcss-value-parser',
|
|
|
|
externals: {
|
|
|
|
'postcss/lib/parser': 'postcss/lib/parser',
|
|
|
|
...externals,
|
|
|
|
},
|
|
|
|
})
|
2023-01-03 10:05:50 +01:00
|
|
|
.target('src/compiled/postcss-value-parser')
|
2021-09-02 08:45:35 +02:00
|
|
|
}
|
|
|
|
// eslint-disable-next-line camelcase
|
|
|
|
externals['icss-utils'] = 'next/dist/compiled/icss-utils'
|
|
|
|
export async function ncc_icss_utils(task, opts) {
|
|
|
|
await task
|
2023-01-03 10:05:50 +01:00
|
|
|
.source(relative(__dirname, require.resolve('icss-utils')))
|
2021-09-02 08:45:35 +02:00
|
|
|
.ncc({
|
|
|
|
packageName: 'icss-utils',
|
|
|
|
externals: {
|
|
|
|
'postcss/lib/parser': 'postcss/lib/parser',
|
|
|
|
...externals,
|
|
|
|
},
|
|
|
|
})
|
2023-01-03 10:05:50 +01:00
|
|
|
.target('src/compiled/icss-utils')
|
2021-09-02 08:45:35 +02:00
|
|
|
}
|
2022-10-19 01:32:23 +02:00
|
|
|
|
2023-08-06 22:00:12 +02:00
|
|
|
externals['scheduler'] = 'next/dist/compiled/scheduler-experimental'
|
|
|
|
externals['scheduler'] = 'next/dist/compiled/scheduler'
|
|
|
|
export async function copy_vendor_react(task_) {
|
|
|
|
function* copy_vendor_react_impl(task, opts) {
|
|
|
|
const channel = opts.experimental ? `experimental-builtin` : `builtin`
|
|
|
|
const packageSuffix = opts.experimental ? `-experimental` : ``
|
2023-04-25 16:29:02 +02:00
|
|
|
|
|
|
|
// Override the `react`, `react-dom` and `scheduler`'s package names to avoid
|
|
|
|
// "The name `react` was looked up in the Haste module map" warnings.
|
|
|
|
// TODO-APP: remove unused fields from package.json and unused files
|
2023-08-06 22:00:12 +02:00
|
|
|
function overridePackageName(source) {
|
2023-04-25 16:29:02 +02:00
|
|
|
const json = JSON.parse(source)
|
2023-08-06 22:00:12 +02:00
|
|
|
json.name = json.name + '-' + channel
|
2023-04-25 16:29:02 +02:00
|
|
|
return JSON.stringify(
|
|
|
|
{
|
|
|
|
name: json.name,
|
|
|
|
main: json.main,
|
|
|
|
exports: json.exports,
|
|
|
|
dependencies: json.dependencies,
|
2023-08-06 22:00:12 +02:00
|
|
|
peerDependencies: json.peerDependencies,
|
2023-04-25 16:29:02 +02:00
|
|
|
browser: json.browser,
|
|
|
|
},
|
|
|
|
null,
|
|
|
|
2
|
2023-04-22 00:19:51 +02:00
|
|
|
)
|
2023-04-25 16:29:02 +02:00
|
|
|
}
|
2023-04-08 17:16:24 +02:00
|
|
|
|
2023-04-25 16:29:02 +02:00
|
|
|
const schedulerDir = dirname(
|
2023-08-06 22:00:12 +02:00
|
|
|
relative(__dirname, require.resolve(`scheduler-${channel}/package.json`))
|
2023-04-25 16:29:02 +02:00
|
|
|
)
|
|
|
|
yield task
|
|
|
|
.source(join(schedulerDir, '*.{json,js}'))
|
|
|
|
// eslint-disable-next-line require-yield
|
|
|
|
.run({ every: true }, function* (file) {
|
|
|
|
if (file.base === 'package.json') {
|
2023-08-06 22:00:12 +02:00
|
|
|
file.data = overridePackageName(file.data.toString())
|
2023-04-25 16:29:02 +02:00
|
|
|
}
|
|
|
|
})
|
2023-08-06 22:00:12 +02:00
|
|
|
.target(`src/compiled/scheduler${packageSuffix}`)
|
2023-04-25 16:29:02 +02:00
|
|
|
yield task
|
|
|
|
.source(join(schedulerDir, 'cjs/**/*.js'))
|
2023-08-06 22:00:12 +02:00
|
|
|
.target(`src/compiled/scheduler${packageSuffix}/cjs`)
|
2023-04-25 16:29:02 +02:00
|
|
|
yield task
|
|
|
|
.source(join(schedulerDir, 'LICENSE'))
|
2023-08-06 22:00:12 +02:00
|
|
|
.target(`src/compiled/scheduler${packageSuffix}`)
|
2023-04-25 16:29:02 +02:00
|
|
|
|
|
|
|
const reactDir = dirname(
|
2023-08-06 22:00:12 +02:00
|
|
|
relative(__dirname, require.resolve(`react-${channel}/package.json`))
|
2023-04-25 16:29:02 +02:00
|
|
|
)
|
|
|
|
const reactDomDir = dirname(
|
2023-08-06 22:00:12 +02:00
|
|
|
relative(__dirname, require.resolve(`react-dom-${channel}/package.json`))
|
2023-04-25 16:29:02 +02:00
|
|
|
)
|
|
|
|
|
|
|
|
yield task
|
|
|
|
.source(join(reactDir, '*.{json,js}'))
|
|
|
|
// eslint-disable-next-line require-yield
|
|
|
|
.run({ every: true }, function* (file) {
|
|
|
|
if (file.base === 'package.json') {
|
2023-08-06 22:00:12 +02:00
|
|
|
file.data = overridePackageName(file.data.toString())
|
2023-04-25 16:29:02 +02:00
|
|
|
}
|
|
|
|
})
|
2023-08-06 22:00:12 +02:00
|
|
|
.target(`src/compiled/react${packageSuffix}`)
|
2023-04-25 16:29:02 +02:00
|
|
|
yield task
|
|
|
|
.source(join(reactDir, 'LICENSE'))
|
2023-08-06 22:00:12 +02:00
|
|
|
.target(`src/compiled/react${packageSuffix}`)
|
2023-04-25 16:29:02 +02:00
|
|
|
yield task
|
|
|
|
.source(join(reactDir, 'cjs/**/*.js'))
|
2023-08-06 22:00:12 +02:00
|
|
|
// eslint-disable-next-line require-yield
|
|
|
|
.run({ every: true }, function* (file) {
|
|
|
|
const source = file.data.toString()
|
|
|
|
// We replace the module/chunk loading code with our own implementation in Next.js.
|
|
|
|
file.data = source.replace(
|
|
|
|
/require\(["']react["']\)/g,
|
|
|
|
`require("next/dist/compiled/react${packageSuffix}")`
|
|
|
|
)
|
|
|
|
})
|
|
|
|
.target(`src/compiled/react${packageSuffix}/cjs`)
|
2023-04-25 16:29:02 +02:00
|
|
|
|
|
|
|
yield task
|
|
|
|
.source(join(reactDomDir, '*.{json,js}'))
|
|
|
|
// eslint-disable-next-line require-yield
|
|
|
|
.run({ every: true }, function* (file) {
|
|
|
|
if (file.base === 'package.json') {
|
2023-08-06 22:00:12 +02:00
|
|
|
file.data = overridePackageName(file.data.toString())
|
2023-04-25 16:29:02 +02:00
|
|
|
}
|
|
|
|
})
|
2023-08-06 22:00:12 +02:00
|
|
|
.target(`src/compiled/react-dom${packageSuffix}`)
|
2023-04-25 16:29:02 +02:00
|
|
|
yield task
|
|
|
|
.source(join(reactDomDir, 'LICENSE'))
|
2023-08-06 22:00:12 +02:00
|
|
|
.target(`src/compiled/react-dom${packageSuffix}`)
|
2023-04-25 16:29:02 +02:00
|
|
|
yield task
|
|
|
|
.source(join(reactDomDir, 'cjs/**/*.js'))
|
2023-08-06 22:00:12 +02:00
|
|
|
// eslint-disable-next-line require-yield
|
|
|
|
.run({ every: true }, function* (file) {
|
|
|
|
const source = file.data.toString()
|
|
|
|
// We replace the module/chunk loading code with our own implementation in Next.js.
|
|
|
|
file.data = source
|
|
|
|
.replace(
|
|
|
|
/require\(["']scheduler["']\)/g,
|
|
|
|
`require("next/dist/compiled/scheduler${packageSuffix}")`
|
|
|
|
)
|
|
|
|
.replace(
|
|
|
|
/require\(["']react["']\)/g,
|
|
|
|
`require("next/dist/compiled/react${packageSuffix}")`
|
|
|
|
)
|
|
|
|
|
|
|
|
// Note that we don't replace `react-dom` with `next/dist/compiled/react-dom`
|
|
|
|
// as it mighe be aliased to the server rendering stub.
|
|
|
|
})
|
|
|
|
.target(`src/compiled/react-dom${packageSuffix}/cjs`)
|
2023-04-17 15:00:02 +02:00
|
|
|
|
2023-04-25 16:29:02 +02:00
|
|
|
// Remove unused files
|
|
|
|
const reactDomCompiledDir = join(
|
2023-04-17 15:00:02 +02:00
|
|
|
__dirname,
|
2023-08-06 22:00:12 +02:00
|
|
|
`src/compiled/react-dom${packageSuffix}`
|
2023-04-17 15:00:02 +02:00
|
|
|
)
|
2023-04-25 16:29:02 +02:00
|
|
|
const itemsToRemove = [
|
|
|
|
'static.js',
|
|
|
|
'static.node.js',
|
|
|
|
'static.browser.js',
|
|
|
|
'unstable_testing.js',
|
|
|
|
'test-utils.js',
|
|
|
|
'server.bun.js',
|
|
|
|
'cjs/react-dom-server.bun.development.js',
|
|
|
|
'cjs/react-dom-server.bun.production.min.js',
|
|
|
|
'cjs/react-dom-test-utils.development.js',
|
|
|
|
'cjs/react-dom-test-utils.production.min.js',
|
|
|
|
'unstable_server-external-runtime.js',
|
|
|
|
]
|
|
|
|
for (const item of itemsToRemove) {
|
2023-10-06 00:01:45 +02:00
|
|
|
yield rmrf(join(reactDomCompiledDir, item))
|
2023-04-25 16:29:02 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// react-server-dom-webpack
|
|
|
|
// Currently, this `next` and `experimental` channels are always in sync so
|
|
|
|
// we can use the same version for both.
|
2023-10-03 23:40:25 +02:00
|
|
|
const reactServerDomWebpackDir = dirname(
|
2023-04-25 16:29:02 +02:00
|
|
|
relative(
|
|
|
|
__dirname,
|
2023-08-06 22:00:12 +02:00
|
|
|
require.resolve(`react-server-dom-webpack${packageSuffix}/package.json`)
|
2023-04-25 16:29:02 +02:00
|
|
|
)
|
|
|
|
)
|
|
|
|
yield task
|
2023-10-03 23:40:25 +02:00
|
|
|
.source(join(reactServerDomWebpackDir, 'LICENSE'))
|
2023-08-06 22:00:12 +02:00
|
|
|
.target(`src/compiled/react-server-dom-webpack${packageSuffix}`)
|
2023-04-25 16:29:02 +02:00
|
|
|
yield task
|
2023-10-03 23:40:25 +02:00
|
|
|
.source(join(reactServerDomWebpackDir, '{package.json,*.js,cjs/**/*.js}'))
|
2023-04-25 16:29:02 +02:00
|
|
|
// eslint-disable-next-line require-yield
|
|
|
|
.run({ every: true }, function* (file) {
|
|
|
|
// We replace the module/chunk loading code with our own implementation in Next.js.
|
2023-10-03 23:40:25 +02:00
|
|
|
// NOTE: We only replace module/chunk loading for server builds because the server
|
|
|
|
// bundles have unique constraints like a runtime bundle. For browser builds this
|
|
|
|
// package will be bundled alongside user code and we don't need to introduce the extra
|
|
|
|
// indirection
|
|
|
|
if (
|
|
|
|
(file.base.startsWith('react-server-dom-webpack-client') &&
|
|
|
|
!file.base.startsWith('react-server-dom-webpack-client.browser')) ||
|
|
|
|
(file.base.startsWith('react-server-dom-webpack-server') &&
|
|
|
|
!file.base.startsWith('react-server-dom-webpack-server.browser'))
|
|
|
|
) {
|
|
|
|
const source = file.data.toString()
|
|
|
|
file.data = source.replace(
|
|
|
|
/__webpack_require__/g,
|
|
|
|
'globalThis.__next_require__'
|
|
|
|
)
|
|
|
|
} else if (file.base === 'package.json') {
|
2023-08-06 22:00:12 +02:00
|
|
|
file.data = overridePackageName(file.data)
|
2023-05-01 15:49:10 +02:00
|
|
|
}
|
2023-04-25 16:29:02 +02:00
|
|
|
})
|
2023-08-06 22:00:12 +02:00
|
|
|
.target(`src/compiled/react-server-dom-webpack${packageSuffix}`)
|
2023-10-03 23:40:25 +02:00
|
|
|
|
|
|
|
// react-server-dom-turbopack
|
|
|
|
// Currently, this `next` and `experimental` channels are always in sync so
|
|
|
|
// we can use the same version for both.
|
|
|
|
const reactServerDomTurbopackDir = dirname(
|
|
|
|
relative(
|
|
|
|
__dirname,
|
|
|
|
require.resolve(
|
|
|
|
`react-server-dom-turbopack${packageSuffix}/package.json`
|
|
|
|
)
|
|
|
|
)
|
|
|
|
)
|
|
|
|
yield task
|
|
|
|
.source(join(reactServerDomTurbopackDir, 'LICENSE'))
|
|
|
|
.target(`src/compiled/react-server-dom-turbopack${packageSuffix}`)
|
|
|
|
yield task
|
|
|
|
.source(
|
|
|
|
join(reactServerDomTurbopackDir, '{package.json,*.js,cjs/**/*.js}')
|
|
|
|
)
|
|
|
|
// eslint-disable-next-line require-yield
|
|
|
|
.run({ every: true }, function* (file) {
|
|
|
|
// We replace the module loading code with our own implementation in Next.js.
|
|
|
|
// NOTE: We only replace module loading for server builds because the server
|
|
|
|
// bundles have unique constraints like a runtime bundle. For browser builds this
|
|
|
|
// package will be bundled alongside user code and we don't need to introduce the extra
|
|
|
|
// indirection
|
|
|
|
if (
|
|
|
|
(file.base.startsWith('react-server-dom-turbopack-client') &&
|
|
|
|
!file.base.startsWith(
|
|
|
|
'react-server-dom-turbopack-client.browser'
|
|
|
|
)) ||
|
|
|
|
(file.base.startsWith('react-server-dom-turbopack-server') &&
|
|
|
|
!file.base.startsWith('react-server-dom-turbopack-server.browser'))
|
|
|
|
) {
|
|
|
|
const source = file.data.toString()
|
|
|
|
file.data = source
|
|
|
|
.replace(/__turbopack_load__/g, 'globalThis.__next_chunk_load__')
|
|
|
|
.replace(/__turbopack_require__/g, 'globalThis.__next_require__')
|
|
|
|
} else if (file.base === 'package.json') {
|
|
|
|
file.data = overridePackageName(file.data)
|
|
|
|
}
|
|
|
|
})
|
|
|
|
.target(`src/compiled/react-server-dom-turbopack${packageSuffix}`)
|
2023-04-25 16:29:02 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// As taskr transpiles async functions into generators, to reuse the same logic
|
|
|
|
// we need to directly write this iteration logic here.
|
2023-08-06 22:00:12 +02:00
|
|
|
for (const res of copy_vendor_react_impl(task_, { experimental: false })) {
|
2023-04-25 16:29:02 +02:00
|
|
|
await res
|
|
|
|
}
|
2023-08-06 22:00:12 +02:00
|
|
|
for (const res of copy_vendor_react_impl(task_, { experimental: true })) {
|
2023-04-25 16:29:02 +02:00
|
|
|
await res
|
|
|
|
}
|
2021-10-28 11:07:13 +02:00
|
|
|
}
|
|
|
|
|
2023-03-30 19:40:13 +02:00
|
|
|
// eslint-disable-next-line camelcase
|
2023-08-06 22:00:12 +02:00
|
|
|
export async function ncc_rsc_poison_packages(task, opts) {
|
2023-03-30 19:40:13 +02:00
|
|
|
await task
|
|
|
|
.source(join(dirname(require.resolve('server-only')), '*'))
|
2023-08-06 22:00:12 +02:00
|
|
|
.target('src/compiled/server-only')
|
2023-03-30 19:40:13 +02:00
|
|
|
await task
|
|
|
|
.source(join(dirname(require.resolve('client-only')), '*'))
|
2023-08-06 22:00:12 +02:00
|
|
|
.target('src/compiled/client-only')
|
2023-03-30 19:40:13 +02:00
|
|
|
}
|
|
|
|
|
2021-01-14 02:59:08 +01:00
|
|
|
externals['sass-loader'] = 'next/dist/compiled/sass-loader'
|
2022-10-19 01:32:23 +02:00
|
|
|
// eslint-disable-next-line camelcase
|
2021-01-14 02:59:08 +01:00
|
|
|
export async function ncc_sass_loader(task, opts) {
|
2022-07-27 06:12:54 +02:00
|
|
|
const sassLoaderPath = require.resolve('sass-loader')
|
|
|
|
const utilsPath = join(dirname(sassLoaderPath), 'utils.js')
|
|
|
|
const originalContent = await fs.readFile(utilsPath, 'utf8')
|
|
|
|
|
|
|
|
await fs.writeFile(
|
|
|
|
utilsPath,
|
|
|
|
originalContent.replace(
|
|
|
|
/require\.resolve\(["'](sass|node-sass)["']\)/g,
|
|
|
|
'eval("require").resolve("$1")'
|
|
|
|
)
|
|
|
|
)
|
|
|
|
|
2021-01-14 02:59:08 +01:00
|
|
|
await task
|
2023-01-03 10:05:50 +01:00
|
|
|
.source(relative(__dirname, sassLoaderPath))
|
2021-01-14 02:59:08 +01:00
|
|
|
.ncc({
|
|
|
|
packageName: 'sass-loader',
|
|
|
|
externals: {
|
|
|
|
...externals,
|
2021-09-21 19:17:16 +02:00
|
|
|
'schema-utils': externals['schema-utils3'],
|
2021-11-08 19:37:25 +01:00
|
|
|
'loader-utils': externals['loader-utils2'],
|
2021-01-14 02:59:08 +01:00
|
|
|
},
|
2021-01-15 02:51:45 +01:00
|
|
|
target: 'es5',
|
2021-01-14 02:59:08 +01:00
|
|
|
})
|
2023-01-03 10:05:50 +01:00
|
|
|
.target('src/compiled/sass-loader')
|
2021-01-14 02:59:08 +01:00
|
|
|
}
|
|
|
|
// eslint-disable-next-line camelcase
|
2021-09-21 19:17:16 +02:00
|
|
|
externals['schema-utils'] = 'MISSING_VERSION schema-utils version not specified'
|
|
|
|
externals['schema-utils2'] = 'next/dist/compiled/schema-utils2'
|
|
|
|
export async function ncc_schema_utils2(task, opts) {
|
2020-11-04 22:52:49 +01:00
|
|
|
await task
|
2023-01-03 10:05:50 +01:00
|
|
|
.source(relative(__dirname, require.resolve('schema-utils2')))
|
2020-11-04 22:52:49 +01:00
|
|
|
.ncc({
|
|
|
|
packageName: 'schema-utils',
|
2021-09-21 19:17:16 +02:00
|
|
|
bundleName: 'schema-utils2',
|
2020-11-04 22:52:49 +01:00
|
|
|
externals,
|
|
|
|
})
|
2023-01-03 10:05:50 +01:00
|
|
|
.target('src/compiled/schema-utils2')
|
2020-11-04 22:52:49 +01:00
|
|
|
}
|
|
|
|
// eslint-disable-next-line camelcase
|
2021-01-14 02:59:08 +01:00
|
|
|
externals['schema-utils3'] = 'next/dist/compiled/schema-utils3'
|
|
|
|
export async function ncc_schema_utils3(task, opts) {
|
|
|
|
await task
|
2023-01-03 10:05:50 +01:00
|
|
|
.source(relative(__dirname, require.resolve('schema-utils3')))
|
2021-01-14 02:59:08 +01:00
|
|
|
.ncc({
|
2021-09-21 19:17:16 +02:00
|
|
|
packageName: 'schema-utils',
|
|
|
|
bundleName: 'schema-utils3',
|
2021-01-14 02:59:08 +01:00
|
|
|
externals,
|
|
|
|
})
|
2023-01-03 10:05:50 +01:00
|
|
|
.target('src/compiled/schema-utils3')
|
2021-01-14 02:59:08 +01:00
|
|
|
}
|
|
|
|
externals['semver'] = 'next/dist/compiled/semver'
|
|
|
|
export async function ncc_semver(task, opts) {
|
|
|
|
await task
|
2023-01-03 10:05:50 +01:00
|
|
|
.source(relative(__dirname, require.resolve('semver')))
|
2021-01-14 02:59:08 +01:00
|
|
|
.ncc({ packageName: 'semver', externals })
|
2023-01-03 10:05:50 +01:00
|
|
|
.target('src/compiled/semver')
|
2021-01-14 02:59:08 +01:00
|
|
|
}
|
|
|
|
// eslint-disable-next-line camelcase
|
2020-03-30 00:41:15 +02:00
|
|
|
externals['send'] = 'next/dist/compiled/send'
|
2020-03-29 03:40:29 +02:00
|
|
|
export async function ncc_send(task, opts) {
|
|
|
|
await task
|
2023-01-03 10:05:50 +01:00
|
|
|
.source(relative(__dirname, require.resolve('send')))
|
2020-03-29 18:16:32 +02:00
|
|
|
.ncc({ packageName: 'send', externals })
|
2023-01-03 10:05:50 +01:00
|
|
|
.target('src/compiled/send')
|
2020-03-29 03:40:29 +02:00
|
|
|
}
|
|
|
|
// eslint-disable-next-line camelcase
|
2020-05-09 17:21:53 +02:00
|
|
|
// NB: Used by other dependencies, but Vercel version is a duplicate
|
2020-03-29 21:07:55 +02:00
|
|
|
// version so can be inlined anyway (although may change in future)
|
2020-03-30 00:41:15 +02:00
|
|
|
externals['source-map'] = 'next/dist/compiled/source-map'
|
2020-03-29 05:41:35 +02:00
|
|
|
export async function ncc_source_map(task, opts) {
|
|
|
|
await task
|
2023-01-03 10:05:50 +01:00
|
|
|
.source(relative(__dirname, require.resolve('source-map')))
|
2020-03-29 18:16:32 +02:00
|
|
|
.ncc({ packageName: 'source-map', externals })
|
2023-01-03 10:05:50 +01:00
|
|
|
.target('src/compiled/source-map')
|
2020-03-29 05:41:35 +02:00
|
|
|
}
|
|
|
|
// eslint-disable-next-line camelcase
|
2024-01-22 10:04:34 +01:00
|
|
|
// NB: Used by other dependencies, but Vercel version is a duplicate
|
|
|
|
// version so can be inlined anyway (although may change in future)
|
|
|
|
externals['source-map08'] = 'next/dist/compiled/source-map08'
|
|
|
|
externals['next/dist/compiled/source-map08'] = 'next/dist/compiled/source-map08'
|
|
|
|
export async function ncc_source_map08(task, opts) {
|
|
|
|
await task
|
|
|
|
.source(relative(__dirname, require.resolve('source-map08')))
|
|
|
|
.ncc({
|
|
|
|
packageName: 'source-map08',
|
|
|
|
packageJsonName: 'source-map08',
|
|
|
|
externals,
|
|
|
|
minify: false,
|
|
|
|
})
|
|
|
|
.target('src/compiled/source-map08')
|
|
|
|
}
|
|
|
|
// eslint-disable-next-line camelcase
|
2020-03-30 00:41:15 +02:00
|
|
|
externals['string-hash'] = 'next/dist/compiled/string-hash'
|
2020-03-29 05:05:26 +02:00
|
|
|
export async function ncc_string_hash(task, opts) {
|
|
|
|
await task
|
2023-01-03 10:05:50 +01:00
|
|
|
.source(relative(__dirname, require.resolve('string-hash')))
|
2020-03-29 18:16:32 +02:00
|
|
|
.ncc({ packageName: 'string-hash', externals })
|
2023-01-03 10:05:50 +01:00
|
|
|
.target('src/compiled/string-hash')
|
2020-03-29 05:05:26 +02:00
|
|
|
}
|
|
|
|
// eslint-disable-next-line camelcase
|
2020-03-30 00:41:15 +02:00
|
|
|
externals['strip-ansi'] = 'next/dist/compiled/strip-ansi'
|
2024-01-22 13:53:42 +01:00
|
|
|
externals['next/dist/compiled/strip-ansi'] = 'next/dist/compiled/strip-ansi'
|
2020-03-29 05:05:26 +02:00
|
|
|
export async function ncc_strip_ansi(task, opts) {
|
|
|
|
await task
|
2023-01-03 10:05:50 +01:00
|
|
|
.source(relative(__dirname, require.resolve('strip-ansi')))
|
2020-03-29 18:16:32 +02:00
|
|
|
.ncc({ packageName: 'strip-ansi', externals })
|
2023-01-03 10:05:50 +01:00
|
|
|
.target('src/compiled/strip-ansi')
|
2020-03-29 05:05:26 +02:00
|
|
|
}
|
|
|
|
// eslint-disable-next-line camelcase
|
2021-08-16 21:29:11 +02:00
|
|
|
externals['@vercel/nft'] = 'next/dist/compiled/@vercel/nft'
|
|
|
|
export async function ncc_nft(task, opts) {
|
|
|
|
await task
|
2023-01-03 10:05:50 +01:00
|
|
|
.source(relative(__dirname, require.resolve('@vercel/nft')))
|
2021-08-16 21:29:11 +02:00
|
|
|
.ncc({ packageName: '@vercel/nft', externals })
|
2023-01-03 10:05:50 +01:00
|
|
|
.target('src/compiled/@vercel/nft')
|
2021-08-16 21:29:11 +02:00
|
|
|
}
|
2022-05-02 23:11:45 +02:00
|
|
|
|
|
|
|
// eslint-disable-next-line camelcase
|
|
|
|
externals['tar'] = 'next/dist/compiled/tar'
|
|
|
|
export async function ncc_tar(task, opts) {
|
|
|
|
await task
|
2023-01-03 10:05:50 +01:00
|
|
|
.source(relative(__dirname, require.resolve('tar')))
|
2022-05-02 23:11:45 +02:00
|
|
|
.ncc({ packageName: 'tar', externals })
|
2023-01-03 10:05:50 +01:00
|
|
|
.target('src/compiled/tar')
|
2022-05-02 23:11:45 +02:00
|
|
|
}
|
|
|
|
|
2021-08-16 21:29:11 +02:00
|
|
|
// eslint-disable-next-line camelcase
|
2020-03-30 00:41:15 +02:00
|
|
|
externals['terser'] = 'next/dist/compiled/terser'
|
2020-03-29 05:52:40 +02:00
|
|
|
export async function ncc_terser(task, opts) {
|
|
|
|
await task
|
2023-01-03 10:05:50 +01:00
|
|
|
.source(relative(__dirname, require.resolve('terser')))
|
2020-03-29 18:16:32 +02:00
|
|
|
.ncc({ packageName: 'terser', externals })
|
2023-01-03 10:05:50 +01:00
|
|
|
.target('src/compiled/terser')
|
2020-03-29 05:52:40 +02:00
|
|
|
}
|
|
|
|
// eslint-disable-next-line camelcase
|
2020-03-30 00:41:15 +02:00
|
|
|
externals['text-table'] = 'next/dist/compiled/text-table'
|
2020-03-28 20:42:35 +01:00
|
|
|
export async function ncc_text_table(task, opts) {
|
|
|
|
await task
|
2023-01-03 10:05:50 +01:00
|
|
|
.source(relative(__dirname, require.resolve('text-table')))
|
2020-03-29 18:16:32 +02:00
|
|
|
.ncc({ packageName: 'text-table', externals })
|
2023-01-03 10:05:50 +01:00
|
|
|
.target('src/compiled/text-table')
|
2020-03-28 20:42:35 +01:00
|
|
|
}
|
|
|
|
// eslint-disable-next-line camelcase
|
2020-03-30 00:41:15 +02:00
|
|
|
externals['unistore'] = 'next/dist/compiled/unistore'
|
2020-03-28 20:42:35 +01:00
|
|
|
export async function ncc_unistore(task, opts) {
|
|
|
|
await task
|
2023-01-03 10:05:50 +01:00
|
|
|
.source(relative(__dirname, require.resolve('unistore')))
|
2020-03-29 18:16:32 +02:00
|
|
|
.ncc({ packageName: 'unistore', externals })
|
2023-01-03 10:05:50 +01:00
|
|
|
.target('src/compiled/unistore')
|
2020-03-28 20:42:35 +01:00
|
|
|
}
|
2023-09-28 11:05:36 +02:00
|
|
|
|
|
|
|
// eslint-disable-next-line camelcase
|
refactor: rewrite config schema in zod (#56383)
The PR supersedes the https://github.com/vercel/next.js/pull/53150, which is way too outdated, has way too many conflicts, and also heavily relies on GitHub Copilot (which makes the progress slow and tedious).
The PR uses [`json-schema-to-zod`](https://github.com/StefanTerdell/json-schema-to-zod) (instead of the GitHub Copilot) to generate the zod schema, and manually replaces all generated `z.customRefine` with my hand-written zod schema.
TODO:
- [x] Convert schema
- [x] Reduce `z.any()` usage
- [x] Create human-readable errors from the `ZodError`
- [x] Update test cases to reflect the latest error message
-----
The benefit of using zod over ajv:
- Easier maintenance: zod schema is straightforward to compose.
- Better typescript support: config schema now strictly reflects the `NextConfig` type.
- Smaller installation size: by replacing `ajv` and `@segment/ajv-human-errors` w/ `zod`, I am able to reduce installation size by 114 KiB.
- Better Extension: the zod error message is easy to customize.
-----
In the previous PR https://github.com/vercel/next.js/pull/56083, @feedthejim replaces `zod` w/ `superstruct`. `superstruct` is lightweight and fast, which makes it perfect for creating simple schemas for RSC payload. But, this also means `superstruct` has its limitations compared to `zod`:
- `superstruct`'s syntax is different, and some utilities's usage is counter-intuitive:
- `z.array(z.string()).gt(1)` vs `s.size(s.array(s.string()), 1)`
- `z.numer().gt(1)` vs `s.size(s.number(), 1)`, `s.min(s.number(), 1)`
- `z.boolean().optional().nullable()` vs `s.nullable(s.optional(z.boolean()))`
- `superstruct` has weaker TypeScript support and worse DX compared to `zod` when composing huge schema:
- `zod.ZodType + z.object()` can provide a more detailed type mismatch message on which specific property is the culprit, while `Describe + s.object()` provides almost no information at all.
- `zod`'s schema is more powerful
- `z.function()` supports `z.args()` and `z.returns()`, while `superstruct` only has `s.func()`
- zod also has Promise type `z.promise()` and intersection type `z.and()`
- `superstruct`'s error is harder to parse compared to `zod`'s `ZodError`
So in the PR, I re-introduced `zod` for `next.config.js` validation.
2023-10-05 17:46:53 +02:00
|
|
|
externals['superstruct'] = 'next/dist/compiled/superstruct'
|
2023-09-28 11:05:36 +02:00
|
|
|
export async function ncc_superstruct(task, opts) {
|
|
|
|
await task
|
|
|
|
.source(relative(__dirname, require.resolve('superstruct')))
|
|
|
|
.ncc({ packageName: 'superstruct', externals })
|
|
|
|
.target('src/compiled/superstruct')
|
|
|
|
}
|
|
|
|
|
refactor: rewrite config schema in zod (#56383)
The PR supersedes the https://github.com/vercel/next.js/pull/53150, which is way too outdated, has way too many conflicts, and also heavily relies on GitHub Copilot (which makes the progress slow and tedious).
The PR uses [`json-schema-to-zod`](https://github.com/StefanTerdell/json-schema-to-zod) (instead of the GitHub Copilot) to generate the zod schema, and manually replaces all generated `z.customRefine` with my hand-written zod schema.
TODO:
- [x] Convert schema
- [x] Reduce `z.any()` usage
- [x] Create human-readable errors from the `ZodError`
- [x] Update test cases to reflect the latest error message
-----
The benefit of using zod over ajv:
- Easier maintenance: zod schema is straightforward to compose.
- Better typescript support: config schema now strictly reflects the `NextConfig` type.
- Smaller installation size: by replacing `ajv` and `@segment/ajv-human-errors` w/ `zod`, I am able to reduce installation size by 114 KiB.
- Better Extension: the zod error message is easy to customize.
-----
In the previous PR https://github.com/vercel/next.js/pull/56083, @feedthejim replaces `zod` w/ `superstruct`. `superstruct` is lightweight and fast, which makes it perfect for creating simple schemas for RSC payload. But, this also means `superstruct` has its limitations compared to `zod`:
- `superstruct`'s syntax is different, and some utilities's usage is counter-intuitive:
- `z.array(z.string()).gt(1)` vs `s.size(s.array(s.string()), 1)`
- `z.numer().gt(1)` vs `s.size(s.number(), 1)`, `s.min(s.number(), 1)`
- `z.boolean().optional().nullable()` vs `s.nullable(s.optional(z.boolean()))`
- `superstruct` has weaker TypeScript support and worse DX compared to `zod` when composing huge schema:
- `zod.ZodType + z.object()` can provide a more detailed type mismatch message on which specific property is the culprit, while `Describe + s.object()` provides almost no information at all.
- `zod`'s schema is more powerful
- `z.function()` supports `z.args()` and `z.returns()`, while `superstruct` only has `s.func()`
- zod also has Promise type `z.promise()` and intersection type `z.and()`
- `superstruct`'s error is harder to parse compared to `zod`'s `ZodError`
So in the PR, I re-introduced `zod` for `next.config.js` validation.
2023-10-05 17:46:53 +02:00
|
|
|
externals['zod'] = 'next/dist/compiled/zod'
|
|
|
|
export async function ncc_zod(task, opts) {
|
|
|
|
await task
|
|
|
|
.source(relative(__dirname, require.resolve('zod')))
|
|
|
|
.ncc({ packageName: 'zod', externals })
|
|
|
|
.target('src/compiled/zod')
|
|
|
|
}
|
|
|
|
|
2020-11-04 22:52:49 +01:00
|
|
|
// eslint-disable-next-line camelcase
|
|
|
|
externals['web-vitals'] = 'next/dist/compiled/web-vitals'
|
|
|
|
export async function ncc_web_vitals(task, opts) {
|
|
|
|
await task
|
2022-08-29 18:56:02 +02:00
|
|
|
.source(
|
2023-01-03 10:05:50 +01:00
|
|
|
relative(
|
|
|
|
__dirname,
|
|
|
|
resolve(resolveFrom(__dirname, 'web-vitals'), '../web-vitals.js')
|
|
|
|
)
|
2022-08-29 18:56:02 +02:00
|
|
|
)
|
|
|
|
// web-vitals@3.0.0 is pure ESM, compile to CJS for pre-compiled
|
|
|
|
.ncc({ packageName: 'web-vitals', externals, target: 'es5', esm: false })
|
2023-01-03 10:05:50 +01:00
|
|
|
.target('src/compiled/web-vitals')
|
2020-11-04 22:52:49 +01:00
|
|
|
}
|
2021-01-14 02:59:08 +01:00
|
|
|
// eslint-disable-next-line camelcase
|
add attribution to web vitals (#39368)
This commit implements the main proposal presented in
https://github.com/vercel/next.js/issues/39241
to add attribution to web vitals.
Attribution adds more specific debugging info to web vitals,
for example in the case of Cumulative Layout Shift (CLS),
we might want to know
> What's the first element that shifted when the single largest layout shift occurred?
on in the case of Largest Contentful Paint (LCP),
> What's the element corresponding to the LCP for the page?
> If it is an image, what's the URL of the image resource?
Attribution is *disabled* by default because it could potentially
generate a lot data and overwhelm the RUM backend.
It is enabled *per metric* (LCP, FCP, CLS, etc)
As part of this change, `web-vitals` has been upgraded to v3.0.0
This version contains minor bug fixes, please see changelog at
https://github.com/GoogleChrome/web-vitals/commit/9fe3cc02c875cb70ac0f1803f5e11b428e7a4014
Fixes #39241
## Bug
- [ ] Related issues linked using `fixes #number`
- [ ] Integration tests added
- [ ] Errors have helpful link attached, see `contributing.md`
## Feature
- [x] Implements an existing feature request or RFC. Make sure the feature request has been accepted for implementation before opening a PR.
- [x] Related issues linked using `fixes #number`
- [x] Integration tests added
- [x] Documentation added
- [ ] Telemetry added. In case of a feature if it's used or not.
- [ ] Errors have helpful link attached, see `contributing.md`
## Documentation / Examples
- [ ] Make sure the linting passes by running `pnpm lint`
- [x] The examples guidelines are followed from [our contributing doc](https://github.com/vercel/next.js/blob/canary/contributing.md#adding-examples)
Co-authored-by: JJ Kasper <22380829+ijjk@users.noreply.github.com>
2022-10-04 02:17:30 +02:00
|
|
|
externals['web-vitals-attribution'] =
|
|
|
|
'next/dist/compiled/web-vitals-attribution'
|
|
|
|
export async function ncc_web_vitals_attribution(task, opts) {
|
|
|
|
await task
|
|
|
|
.source(
|
2023-01-03 10:05:50 +01:00
|
|
|
relative(
|
|
|
|
__dirname,
|
|
|
|
resolve(require.resolve('web-vitals'), '../web-vitals.attribution.js')
|
|
|
|
)
|
add attribution to web vitals (#39368)
This commit implements the main proposal presented in
https://github.com/vercel/next.js/issues/39241
to add attribution to web vitals.
Attribution adds more specific debugging info to web vitals,
for example in the case of Cumulative Layout Shift (CLS),
we might want to know
> What's the first element that shifted when the single largest layout shift occurred?
on in the case of Largest Contentful Paint (LCP),
> What's the element corresponding to the LCP for the page?
> If it is an image, what's the URL of the image resource?
Attribution is *disabled* by default because it could potentially
generate a lot data and overwhelm the RUM backend.
It is enabled *per metric* (LCP, FCP, CLS, etc)
As part of this change, `web-vitals` has been upgraded to v3.0.0
This version contains minor bug fixes, please see changelog at
https://github.com/GoogleChrome/web-vitals/commit/9fe3cc02c875cb70ac0f1803f5e11b428e7a4014
Fixes #39241
## Bug
- [ ] Related issues linked using `fixes #number`
- [ ] Integration tests added
- [ ] Errors have helpful link attached, see `contributing.md`
## Feature
- [x] Implements an existing feature request or RFC. Make sure the feature request has been accepted for implementation before opening a PR.
- [x] Related issues linked using `fixes #number`
- [x] Integration tests added
- [x] Documentation added
- [ ] Telemetry added. In case of a feature if it's used or not.
- [ ] Errors have helpful link attached, see `contributing.md`
## Documentation / Examples
- [ ] Make sure the linting passes by running `pnpm lint`
- [x] The examples guidelines are followed from [our contributing doc](https://github.com/vercel/next.js/blob/canary/contributing.md#adding-examples)
Co-authored-by: JJ Kasper <22380829+ijjk@users.noreply.github.com>
2022-10-04 02:17:30 +02:00
|
|
|
)
|
|
|
|
.ncc({
|
|
|
|
packageName: 'web-vitals',
|
|
|
|
bundleName: 'web-vitals-attribution',
|
|
|
|
externals,
|
|
|
|
target: 'es5',
|
|
|
|
esm: false,
|
|
|
|
})
|
2023-01-03 10:05:50 +01:00
|
|
|
.target('src/compiled/web-vitals-attribution')
|
add attribution to web vitals (#39368)
This commit implements the main proposal presented in
https://github.com/vercel/next.js/issues/39241
to add attribution to web vitals.
Attribution adds more specific debugging info to web vitals,
for example in the case of Cumulative Layout Shift (CLS),
we might want to know
> What's the first element that shifted when the single largest layout shift occurred?
on in the case of Largest Contentful Paint (LCP),
> What's the element corresponding to the LCP for the page?
> If it is an image, what's the URL of the image resource?
Attribution is *disabled* by default because it could potentially
generate a lot data and overwhelm the RUM backend.
It is enabled *per metric* (LCP, FCP, CLS, etc)
As part of this change, `web-vitals` has been upgraded to v3.0.0
This version contains minor bug fixes, please see changelog at
https://github.com/GoogleChrome/web-vitals/commit/9fe3cc02c875cb70ac0f1803f5e11b428e7a4014
Fixes #39241
## Bug
- [ ] Related issues linked using `fixes #number`
- [ ] Integration tests added
- [ ] Errors have helpful link attached, see `contributing.md`
## Feature
- [x] Implements an existing feature request or RFC. Make sure the feature request has been accepted for implementation before opening a PR.
- [x] Related issues linked using `fixes #number`
- [x] Integration tests added
- [x] Documentation added
- [ ] Telemetry added. In case of a feature if it's used or not.
- [ ] Errors have helpful link attached, see `contributing.md`
## Documentation / Examples
- [ ] Make sure the linting passes by running `pnpm lint`
- [x] The examples guidelines are followed from [our contributing doc](https://github.com/vercel/next.js/blob/canary/contributing.md#adding-examples)
Co-authored-by: JJ Kasper <22380829+ijjk@users.noreply.github.com>
2022-10-04 02:17:30 +02:00
|
|
|
}
|
|
|
|
// eslint-disable-next-line camelcase
|
2021-09-21 19:17:16 +02:00
|
|
|
externals['webpack-sources'] = 'error webpack-sources version not specified'
|
|
|
|
externals['webpack-sources1'] = 'next/dist/compiled/webpack-sources1'
|
|
|
|
export async function ncc_webpack_sources1(task, opts) {
|
2021-01-14 02:59:08 +01:00
|
|
|
await task
|
2023-01-03 10:05:50 +01:00
|
|
|
.source(relative(__dirname, require.resolve('webpack-sources1')))
|
2021-09-21 19:17:16 +02:00
|
|
|
.ncc({ packageName: 'webpack-sources1', externals, target: 'es5' })
|
2023-01-03 10:05:50 +01:00
|
|
|
.target('src/compiled/webpack-sources1')
|
2021-01-14 02:59:08 +01:00
|
|
|
}
|
|
|
|
// eslint-disable-next-line camelcase
|
2021-07-29 18:10:51 +02:00
|
|
|
externals['webpack-sources3'] = 'next/dist/compiled/webpack-sources3'
|
|
|
|
export async function ncc_webpack_sources3(task, opts) {
|
2021-01-14 02:59:08 +01:00
|
|
|
await task
|
2023-01-03 10:05:50 +01:00
|
|
|
.source(relative(__dirname, require.resolve('webpack-sources3')))
|
2021-07-29 18:10:51 +02:00
|
|
|
.ncc({ packageName: 'webpack-sources3', externals, target: 'es5' })
|
2023-01-03 10:05:50 +01:00
|
|
|
.target('src/compiled/webpack-sources3')
|
2021-01-14 02:59:08 +01:00
|
|
|
}
|
2021-10-22 20:55:45 +02:00
|
|
|
|
|
|
|
// eslint-disable-next-line camelcase
|
2024-01-19 20:56:16 +01:00
|
|
|
externals['picomatch'] = 'next/dist/compiled/picomatch'
|
2021-10-22 20:55:45 +02:00
|
|
|
export async function ncc_minimatch(task, opts) {
|
|
|
|
await task
|
2024-01-19 20:56:16 +01:00
|
|
|
.source(relative(__dirname, require.resolve('picomatch')))
|
|
|
|
.ncc({ packageName: 'picomatch', externals })
|
|
|
|
.target('src/compiled/picomatch')
|
2021-10-22 20:55:45 +02:00
|
|
|
}
|
|
|
|
|
2021-05-12 18:04:01 +02:00
|
|
|
// eslint-disable-next-line camelcase
|
|
|
|
externals['mini-css-extract-plugin'] =
|
|
|
|
'next/dist/compiled/mini-css-extract-plugin'
|
2022-05-23 02:16:50 +02:00
|
|
|
|
2021-05-12 18:04:01 +02:00
|
|
|
export async function ncc_mini_css_extract_plugin(task, opts) {
|
|
|
|
await task
|
|
|
|
.source(
|
|
|
|
relative(
|
|
|
|
__dirname,
|
|
|
|
resolve(require.resolve('mini-css-extract-plugin'), '../index.js')
|
|
|
|
)
|
|
|
|
)
|
|
|
|
.ncc({
|
|
|
|
externals: {
|
|
|
|
...externals,
|
|
|
|
'./index': './index.js',
|
2021-09-23 23:22:14 +02:00
|
|
|
'schema-utils': externals['schema-utils3'],
|
2021-09-21 19:17:16 +02:00
|
|
|
'webpack-sources': externals['webpack-sources1'],
|
2021-05-12 18:04:01 +02:00
|
|
|
},
|
|
|
|
})
|
2023-01-03 10:05:50 +01:00
|
|
|
.target('src/compiled/mini-css-extract-plugin')
|
2022-05-23 02:16:50 +02:00
|
|
|
await task
|
|
|
|
.source(
|
|
|
|
relative(
|
|
|
|
__dirname,
|
|
|
|
resolve(
|
|
|
|
require.resolve('mini-css-extract-plugin'),
|
|
|
|
'../hmr/hotModuleReplacement.js'
|
|
|
|
)
|
|
|
|
)
|
|
|
|
)
|
|
|
|
.ncc({
|
|
|
|
externals: {
|
|
|
|
...externals,
|
|
|
|
'./hmr': './hmr',
|
|
|
|
'schema-utils': 'next/dist/compiled/schema-utils3',
|
|
|
|
},
|
|
|
|
})
|
2023-01-03 10:05:50 +01:00
|
|
|
.target('src/compiled/mini-css-extract-plugin/hmr')
|
2021-05-12 18:04:01 +02:00
|
|
|
await task
|
2023-01-03 10:05:50 +01:00
|
|
|
.source(relative(__dirname, require.resolve('mini-css-extract-plugin')))
|
2021-05-12 18:04:01 +02:00
|
|
|
.ncc({
|
|
|
|
packageName: 'mini-css-extract-plugin',
|
|
|
|
externals: {
|
|
|
|
...externals,
|
|
|
|
'./index': './index.js',
|
2021-09-21 19:17:16 +02:00
|
|
|
'schema-utils': externals['schema-utils3'],
|
2021-05-12 18:04:01 +02:00
|
|
|
},
|
|
|
|
})
|
2023-01-03 10:05:50 +01:00
|
|
|
.target('src/compiled/mini-css-extract-plugin')
|
2021-05-12 18:04:01 +02:00
|
|
|
}
|
2022-10-07 15:25:22 +02:00
|
|
|
|
2021-10-20 19:52:11 +02:00
|
|
|
// eslint-disable-next-line camelcase
|
|
|
|
externals['ua-parser-js'] = 'next/dist/compiled/ua-parser-js'
|
|
|
|
export async function ncc_ua_parser_js(task, opts) {
|
|
|
|
await task
|
2023-01-03 10:05:50 +01:00
|
|
|
.source(relative(__dirname, require.resolve('ua-parser-js')))
|
2021-10-20 19:52:11 +02:00
|
|
|
.ncc({ packageName: 'ua-parser-js', externals })
|
2023-01-03 10:05:50 +01:00
|
|
|
.target('src/compiled/ua-parser-js')
|
2021-10-20 19:52:11 +02:00
|
|
|
}
|
2021-01-14 02:59:08 +01:00
|
|
|
// eslint-disable-next-line camelcase
|
|
|
|
export async function ncc_webpack_bundle5(task, opts) {
|
2021-09-17 19:27:03 +02:00
|
|
|
const bundleExternals = {
|
|
|
|
...externals,
|
2021-09-21 19:17:16 +02:00
|
|
|
'schema-utils': externals['schema-utils3'],
|
|
|
|
'webpack-sources': externals['webpack-sources3'],
|
2021-09-17 19:27:03 +02:00
|
|
|
}
|
|
|
|
for (const pkg of Object.keys(webpackBundlePackages)) {
|
|
|
|
delete bundleExternals[pkg]
|
|
|
|
}
|
2020-08-06 16:41:11 +02:00
|
|
|
await task
|
2023-02-06 21:49:23 +01:00
|
|
|
.source('src/bundles/webpack/bundle5.js')
|
2021-01-14 02:59:08 +01:00
|
|
|
.ncc({
|
2022-08-16 11:55:37 +02:00
|
|
|
packageName: 'webpack',
|
2021-01-14 02:59:08 +01:00
|
|
|
bundleName: 'webpack',
|
|
|
|
customEmit(path) {
|
|
|
|
if (path.endsWith('.runtime.js')) return `'./${basename(path)}'`
|
|
|
|
},
|
2021-09-21 19:17:16 +02:00
|
|
|
externals: bundleExternals,
|
2021-01-14 02:59:08 +01:00
|
|
|
target: 'es5',
|
|
|
|
})
|
2023-01-03 10:05:50 +01:00
|
|
|
.target('src/compiled/webpack')
|
2021-01-14 02:59:08 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
const webpackBundlePackages = {
|
2021-05-23 13:15:58 +02:00
|
|
|
webpack: 'next/dist/compiled/webpack/webpack-lib',
|
2021-09-06 10:53:06 +02:00
|
|
|
'webpack/lib/NormalModule': 'next/dist/compiled/webpack/NormalModule',
|
2021-09-21 19:17:16 +02:00
|
|
|
'webpack/lib/node/NodeTargetPlugin':
|
|
|
|
'next/dist/compiled/webpack/NodeTargetPlugin',
|
2021-01-14 02:59:08 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
Object.assign(externals, webpackBundlePackages)
|
|
|
|
|
|
|
|
export async function ncc_webpack_bundle_packages(task, opts) {
|
|
|
|
await task
|
2023-02-06 21:49:23 +01:00
|
|
|
.source('src/bundles/webpack/packages/*')
|
2023-01-03 10:05:50 +01:00
|
|
|
.target('src/compiled/webpack/')
|
2020-08-06 16:41:11 +02:00
|
|
|
}
|
|
|
|
|
2021-10-15 09:09:54 +02:00
|
|
|
// eslint-disable-next-line camelcase
|
|
|
|
externals['ws'] = 'next/dist/compiled/ws'
|
|
|
|
export async function ncc_ws(task, opts) {
|
|
|
|
await task
|
2023-01-03 10:05:50 +01:00
|
|
|
.source(relative(__dirname, require.resolve('ws')))
|
2021-10-15 09:09:54 +02:00
|
|
|
.ncc({ packageName: 'ws', externals })
|
2023-01-03 10:05:50 +01:00
|
|
|
.target('src/compiled/ws')
|
2021-10-15 09:09:54 +02:00
|
|
|
}
|
|
|
|
|
2020-03-30 00:41:15 +02:00
|
|
|
externals['path-to-regexp'] = 'next/dist/compiled/path-to-regexp'
|
2020-03-29 19:17:06 +02:00
|
|
|
export async function path_to_regexp(task, opts) {
|
|
|
|
await task
|
2023-01-03 10:05:50 +01:00
|
|
|
.source(relative(__dirname, require.resolve('path-to-regexp')))
|
2020-03-29 19:17:06 +02:00
|
|
|
.target('dist/compiled/path-to-regexp')
|
|
|
|
}
|
2020-03-29 19:31:43 +02:00
|
|
|
|
2023-02-22 16:08:22 +01:00
|
|
|
// eslint-disable-next-line camelcase
|
|
|
|
externals['@opentelemetry/api'] = 'next/dist/compiled/@opentelemetry/api'
|
|
|
|
export async function ncc_opentelemetry_api(task, opts) {
|
|
|
|
await task
|
|
|
|
.source(
|
|
|
|
opts.src || relative(__dirname, require.resolve('@opentelemetry/api'))
|
|
|
|
)
|
|
|
|
.ncc({ packageName: '@opentelemetry/api', externals })
|
|
|
|
.target('src/compiled/@opentelemetry/api')
|
|
|
|
}
|
|
|
|
|
2023-03-08 21:23:32 +01:00
|
|
|
// eslint-disable-next-line camelcase
|
|
|
|
externals['http-proxy-agent'] = 'next/dist/compiled/http-proxy-agent'
|
|
|
|
export async function ncc_http_proxy_agent(task, opts) {
|
|
|
|
await task
|
|
|
|
.source(relative(__dirname, require.resolve('http-proxy-agent')))
|
|
|
|
.ncc({ packageName: 'http-proxy-agent', externals })
|
|
|
|
.target('src/compiled/http-proxy-agent')
|
|
|
|
}
|
|
|
|
|
|
|
|
// eslint-disable-next-line camelcase
|
|
|
|
externals['https-proxy-agent'] = 'next/dist/compiled/https-proxy-agent'
|
|
|
|
export async function ncc_https_proxy_agent(task, opts) {
|
|
|
|
await task
|
|
|
|
.source(relative(__dirname, require.resolve('https-proxy-agent')))
|
|
|
|
.ncc({ packageName: 'https-proxy-agent', externals })
|
|
|
|
.target('src/compiled/https-proxy-agent')
|
|
|
|
}
|
|
|
|
|
2021-02-03 18:02:44 +01:00
|
|
|
export async function precompile(task, opts) {
|
|
|
|
await task.parallel(
|
2022-08-09 19:10:33 +02:00
|
|
|
[
|
|
|
|
'browser_polyfills',
|
|
|
|
'path_to_regexp',
|
|
|
|
'copy_ncced',
|
|
|
|
'copy_styled_jsx_assets',
|
|
|
|
],
|
2021-02-03 18:02:44 +01:00
|
|
|
opts
|
|
|
|
)
|
2019-02-27 15:12:40 +01:00
|
|
|
}
|
|
|
|
|
2020-04-07 15:42:16 +02:00
|
|
|
// eslint-disable-next-line camelcase
|
|
|
|
export async function copy_ncced(task) {
|
|
|
|
// we don't ncc every time we build since these won't change
|
|
|
|
// that often and can be committed to the repo saving build time
|
2023-01-03 10:05:50 +01:00
|
|
|
await task.source('src/compiled/**/*').target('dist/compiled')
|
2020-04-07 15:42:16 +02:00
|
|
|
}
|
|
|
|
|
2021-02-03 18:02:44 +01:00
|
|
|
export async function ncc(task, opts) {
|
2020-07-01 17:34:00 +02:00
|
|
|
await task
|
|
|
|
.clear('compiled')
|
2021-02-03 18:02:44 +01:00
|
|
|
.parallel(
|
|
|
|
[
|
2021-12-21 16:13:45 +01:00
|
|
|
'ncc_node_html_parser',
|
|
|
|
'ncc_napirs_triples',
|
2021-12-20 14:01:35 +01:00
|
|
|
'ncc_p_limit',
|
|
|
|
'ncc_raw_body',
|
|
|
|
'ncc_image_size',
|
2024-02-08 12:00:34 +01:00
|
|
|
'ncc_get_orientation',
|
2021-12-20 14:01:35 +01:00
|
|
|
'ncc_hapi_accept',
|
2024-03-02 00:12:47 +01:00
|
|
|
'ncc_commander',
|
2022-01-17 16:17:22 +01:00
|
|
|
'ncc_node_fetch',
|
2022-10-11 16:11:57 +02:00
|
|
|
'ncc_node_anser',
|
|
|
|
'ncc_node_stacktrace_parser',
|
|
|
|
'ncc_node_data_uri_to_buffer',
|
|
|
|
'ncc_node_cssescape',
|
|
|
|
'ncc_node_platform',
|
|
|
|
'ncc_node_shell_quote',
|
2021-12-20 14:01:35 +01:00
|
|
|
'ncc_acorn',
|
2021-02-03 18:02:44 +01:00
|
|
|
'ncc_amphtml_validator',
|
|
|
|
'ncc_async_retry',
|
|
|
|
'ncc_async_sema',
|
2023-02-24 19:05:21 +01:00
|
|
|
'ncc_postcss_plugin_stub_for_cssnano_simple',
|
2021-12-20 14:01:35 +01:00
|
|
|
'ncc_assert',
|
|
|
|
'ncc_browser_zlib',
|
|
|
|
'ncc_buffer',
|
|
|
|
'ncc_crypto_browserify',
|
|
|
|
'ncc_domain_browser',
|
|
|
|
'ncc_events',
|
2022-01-17 16:17:22 +01:00
|
|
|
'ncc_stream_browserify',
|
2021-12-20 14:01:35 +01:00
|
|
|
'ncc_stream_http',
|
|
|
|
'ncc_https_browserify',
|
|
|
|
'ncc_os_browserify',
|
|
|
|
'ncc_path_browserify',
|
|
|
|
'ncc_process',
|
|
|
|
'ncc_querystring_es3',
|
|
|
|
'ncc_string_decoder',
|
|
|
|
'ncc_util',
|
2022-01-03 20:31:23 +01:00
|
|
|
'ncc_punycode',
|
|
|
|
'ncc_set_immediate',
|
2021-12-20 14:01:35 +01:00
|
|
|
'ncc_timers_browserify',
|
|
|
|
'ncc_tty_browserify',
|
|
|
|
'ncc_vm_browserify',
|
2021-02-03 18:02:44 +01:00
|
|
|
'ncc_babel_bundle',
|
2022-02-25 03:04:02 +01:00
|
|
|
'ncc_bytes',
|
2021-02-03 18:02:44 +01:00
|
|
|
'ncc_ci_info',
|
2021-08-04 23:53:15 +02:00
|
|
|
'ncc_cli_select',
|
2021-02-03 18:02:44 +01:00
|
|
|
'ncc_comment_json',
|
|
|
|
'ncc_compression',
|
|
|
|
'ncc_conf',
|
2021-11-02 00:23:24 +01:00
|
|
|
'ncc_content_disposition',
|
2021-02-03 18:02:44 +01:00
|
|
|
'ncc_content_type',
|
|
|
|
'ncc_cookie',
|
2021-08-04 23:53:15 +02:00
|
|
|
'ncc_cross_spawn',
|
2021-02-03 18:02:44 +01:00
|
|
|
'ncc_debug',
|
|
|
|
'ncc_devalue',
|
|
|
|
'ncc_find_up',
|
|
|
|
'ncc_fresh',
|
2021-08-16 21:29:11 +02:00
|
|
|
'ncc_glob',
|
2021-02-03 18:02:44 +01:00
|
|
|
'ncc_gzip_size',
|
|
|
|
'ncc_http_proxy',
|
|
|
|
'ncc_ignore_loader',
|
|
|
|
'ncc_is_animated',
|
|
|
|
'ncc_is_docker',
|
|
|
|
'ncc_is_wsl',
|
|
|
|
'ncc_json5',
|
|
|
|
'ncc_jsonwebtoken',
|
2023-02-18 07:24:40 +01:00
|
|
|
'ncc_loader_runner',
|
2021-11-08 19:37:25 +01:00
|
|
|
'ncc_loader_utils2',
|
|
|
|
'ncc_loader_utils3',
|
2021-02-03 18:02:44 +01:00
|
|
|
'ncc_lodash_curry',
|
|
|
|
'ncc_lru_cache',
|
|
|
|
'ncc_nanoid',
|
2021-10-18 17:46:39 +02:00
|
|
|
'ncc_native_url',
|
2021-02-03 18:02:44 +01:00
|
|
|
'ncc_neo_async',
|
|
|
|
'ncc_ora',
|
2021-09-02 08:45:35 +02:00
|
|
|
'ncc_postcss_safe_parser',
|
2021-02-03 18:02:44 +01:00
|
|
|
'ncc_postcss_flexbugs_fixes',
|
|
|
|
'ncc_postcss_preset_env',
|
|
|
|
'ncc_postcss_scss',
|
2021-09-02 08:45:35 +02:00
|
|
|
'ncc_postcss_modules_extract_imports',
|
|
|
|
'ncc_postcss_modules_local_by_default',
|
|
|
|
'ncc_postcss_modules_scope',
|
|
|
|
'ncc_postcss_modules_values',
|
|
|
|
'ncc_postcss_value_parser',
|
|
|
|
'ncc_icss_utils',
|
2021-09-21 19:17:16 +02:00
|
|
|
'ncc_schema_utils2',
|
2021-02-03 18:02:44 +01:00
|
|
|
'ncc_schema_utils3',
|
|
|
|
'ncc_semver',
|
|
|
|
'ncc_send',
|
|
|
|
'ncc_source_map',
|
2024-01-22 10:04:34 +01:00
|
|
|
'ncc_source_map08',
|
2021-02-03 18:02:44 +01:00
|
|
|
'ncc_string_hash',
|
|
|
|
'ncc_strip_ansi',
|
2023-09-28 11:05:36 +02:00
|
|
|
'ncc_superstruct',
|
refactor: rewrite config schema in zod (#56383)
The PR supersedes the https://github.com/vercel/next.js/pull/53150, which is way too outdated, has way too many conflicts, and also heavily relies on GitHub Copilot (which makes the progress slow and tedious).
The PR uses [`json-schema-to-zod`](https://github.com/StefanTerdell/json-schema-to-zod) (instead of the GitHub Copilot) to generate the zod schema, and manually replaces all generated `z.customRefine` with my hand-written zod schema.
TODO:
- [x] Convert schema
- [x] Reduce `z.any()` usage
- [x] Create human-readable errors from the `ZodError`
- [x] Update test cases to reflect the latest error message
-----
The benefit of using zod over ajv:
- Easier maintenance: zod schema is straightforward to compose.
- Better typescript support: config schema now strictly reflects the `NextConfig` type.
- Smaller installation size: by replacing `ajv` and `@segment/ajv-human-errors` w/ `zod`, I am able to reduce installation size by 114 KiB.
- Better Extension: the zod error message is easy to customize.
-----
In the previous PR https://github.com/vercel/next.js/pull/56083, @feedthejim replaces `zod` w/ `superstruct`. `superstruct` is lightweight and fast, which makes it perfect for creating simple schemas for RSC payload. But, this also means `superstruct` has its limitations compared to `zod`:
- `superstruct`'s syntax is different, and some utilities's usage is counter-intuitive:
- `z.array(z.string()).gt(1)` vs `s.size(s.array(s.string()), 1)`
- `z.numer().gt(1)` vs `s.size(s.number(), 1)`, `s.min(s.number(), 1)`
- `z.boolean().optional().nullable()` vs `s.nullable(s.optional(z.boolean()))`
- `superstruct` has weaker TypeScript support and worse DX compared to `zod` when composing huge schema:
- `zod.ZodType + z.object()` can provide a more detailed type mismatch message on which specific property is the culprit, while `Describe + s.object()` provides almost no information at all.
- `zod`'s schema is more powerful
- `z.function()` supports `z.args()` and `z.returns()`, while `superstruct` only has `s.func()`
- zod also has Promise type `z.promise()` and intersection type `z.and()`
- `superstruct`'s error is harder to parse compared to `zod`'s `ZodError`
So in the PR, I re-introduced `zod` for `next.config.js` validation.
2023-10-05 17:46:53 +02:00
|
|
|
'ncc_zod',
|
2021-08-16 21:29:11 +02:00
|
|
|
'ncc_nft',
|
2022-05-02 23:11:45 +02:00
|
|
|
'ncc_tar',
|
2021-02-03 18:02:44 +01:00
|
|
|
'ncc_terser',
|
|
|
|
'ncc_text_table',
|
|
|
|
'ncc_unistore',
|
2024-01-08 19:45:19 +01:00
|
|
|
'ncc_watchpack',
|
2021-02-03 18:02:44 +01:00
|
|
|
'ncc_web_vitals',
|
add attribution to web vitals (#39368)
This commit implements the main proposal presented in
https://github.com/vercel/next.js/issues/39241
to add attribution to web vitals.
Attribution adds more specific debugging info to web vitals,
for example in the case of Cumulative Layout Shift (CLS),
we might want to know
> What's the first element that shifted when the single largest layout shift occurred?
on in the case of Largest Contentful Paint (LCP),
> What's the element corresponding to the LCP for the page?
> If it is an image, what's the URL of the image resource?
Attribution is *disabled* by default because it could potentially
generate a lot data and overwhelm the RUM backend.
It is enabled *per metric* (LCP, FCP, CLS, etc)
As part of this change, `web-vitals` has been upgraded to v3.0.0
This version contains minor bug fixes, please see changelog at
https://github.com/GoogleChrome/web-vitals/commit/9fe3cc02c875cb70ac0f1803f5e11b428e7a4014
Fixes #39241
## Bug
- [ ] Related issues linked using `fixes #number`
- [ ] Integration tests added
- [ ] Errors have helpful link attached, see `contributing.md`
## Feature
- [x] Implements an existing feature request or RFC. Make sure the feature request has been accepted for implementation before opening a PR.
- [x] Related issues linked using `fixes #number`
- [x] Integration tests added
- [x] Documentation added
- [ ] Telemetry added. In case of a feature if it's used or not.
- [ ] Errors have helpful link attached, see `contributing.md`
## Documentation / Examples
- [ ] Make sure the linting passes by running `pnpm lint`
- [x] The examples guidelines are followed from [our contributing doc](https://github.com/vercel/next.js/blob/canary/contributing.md#adding-examples)
Co-authored-by: JJ Kasper <22380829+ijjk@users.noreply.github.com>
2022-10-04 02:17:30 +02:00
|
|
|
'ncc_web_vitals_attribution',
|
2021-02-03 18:02:44 +01:00
|
|
|
'ncc_webpack_bundle5',
|
2021-09-21 19:17:16 +02:00
|
|
|
'ncc_webpack_sources1',
|
2021-07-29 18:10:51 +02:00
|
|
|
'ncc_webpack_sources3',
|
2021-10-15 09:09:54 +02:00
|
|
|
'ncc_ws',
|
2021-10-20 19:52:11 +02:00
|
|
|
'ncc_ua_parser_js',
|
2021-10-22 20:55:45 +02:00
|
|
|
'ncc_minimatch',
|
2023-02-22 16:08:22 +01:00
|
|
|
'ncc_opentelemetry_api',
|
2023-03-08 21:23:32 +01:00
|
|
|
'ncc_http_proxy_agent',
|
|
|
|
'ncc_https_proxy_agent',
|
2021-05-12 18:04:01 +02:00
|
|
|
'ncc_mini_css_extract_plugin',
|
2021-02-03 18:02:44 +01:00
|
|
|
],
|
|
|
|
opts
|
|
|
|
)
|
2021-12-14 11:33:04 +01:00
|
|
|
await task.parallel(['ncc_webpack_bundle_packages'], opts)
|
2021-08-22 21:06:58 +02:00
|
|
|
await task.parallel(['ncc_babel_bundle_packages'], opts)
|
2021-12-21 16:13:45 +01:00
|
|
|
await task.serial(
|
|
|
|
[
|
2022-02-02 20:23:51 +01:00
|
|
|
'ncc_browserslist',
|
2023-02-24 19:05:21 +01:00
|
|
|
'ncc_cssnano_simple_bundle',
|
2021-12-21 16:13:45 +01:00
|
|
|
'copy_regenerator_runtime',
|
|
|
|
'copy_babel_runtime',
|
2023-03-31 04:29:10 +02:00
|
|
|
'copy_vercel_og',
|
2021-12-21 16:13:45 +01:00
|
|
|
'copy_constants_browserify',
|
2023-08-06 22:00:12 +02:00
|
|
|
'copy_vendor_react',
|
2022-01-17 16:17:22 +01:00
|
|
|
'copy_react_is',
|
2022-07-27 06:12:54 +02:00
|
|
|
'ncc_sass_loader',
|
2022-01-17 16:17:22 +01:00
|
|
|
'ncc_jest_worker',
|
2023-02-17 15:10:09 +01:00
|
|
|
'ncc_edge_runtime_cookies',
|
2022-07-21 20:29:19 +02:00
|
|
|
'ncc_edge_runtime_primitives',
|
2023-05-31 10:03:20 +02:00
|
|
|
'ncc_edge_runtime_ponyfill',
|
2022-07-21 20:29:19 +02:00
|
|
|
'ncc_edge_runtime',
|
2023-08-15 04:31:00 +02:00
|
|
|
'ncc_mswjs_interceptors',
|
2021-12-21 16:13:45 +01:00
|
|
|
],
|
|
|
|
opts
|
|
|
|
)
|
2021-02-03 18:02:44 +01:00
|
|
|
}
|
|
|
|
|
2023-09-08 18:05:29 +02:00
|
|
|
export async function next_compile(task, opts) {
|
2021-02-03 18:02:44 +01:00
|
|
|
await task.parallel(
|
|
|
|
[
|
|
|
|
'cli',
|
|
|
|
'bin',
|
|
|
|
'server',
|
2022-09-28 12:29:22 +02:00
|
|
|
'server_esm',
|
Alias nextjs api entry to esm version for app router (#59852)
## What
When users specify `"type": "module"` in Next.js app, especially with
`create-next-app`, `Image` component is not working. An error
`Unsupported Server Component type: {...}` is thrown.
## Why
`next/image` API is mixing with a client component as default export and
a named export as server component. But the entry file of the API is
still CJS file, which will import the module as the object. So you'll
get `{ default, unstable_getImageProps }` when you do `import Image from
'next/image'` instead of `Image` component itself, where the CJS module
load all the exports as an object. This is expected behavior for ESM but
breaks the usage.
It only errors when you're using js extensions, if you're using
typescript, it still works. If you're using turbopack, it works in dev
mode.
This is also because webpack can't analyze the exports from CJS module
of that `next/image` entry file. Usually we can assign the default
export to the module itself, then attach other named exports onto it, so
the default export equals the `module.exports` itself. But for
`next/image` since the default export is an client component, doing that
will error with React as you cannot modify the react client reference.
Turbopack doesn't use the same way to analyze the default export, so it
doesn't have this problem.
## How
We create few ESM version of entry files of nextjs APIs, then pick up
them to let app router for bundling, instead of using the `next/<api
name>.js` CJS files. Those ESM entries still point to the `next/dist/..`
CJS files. In this way webpack and directly gets the exports from the
`next/dist/...` files and be aware of the module exports. No more CJS
module wrapping the ESM module, the default and named exports can
preserve correctly.
Fixes #54777
Closes NEXT-1774
Closes NEXT-1879
Closes NEXT-1923
2023-12-23 17:46:50 +01:00
|
|
|
'api_esm',
|
2021-02-03 18:02:44 +01:00
|
|
|
'nextbuild',
|
2022-05-11 20:13:13 +02:00
|
|
|
'nextbuildjest',
|
2021-02-03 18:02:44 +01:00
|
|
|
'nextbuildstatic',
|
2023-11-30 23:41:55 +01:00
|
|
|
'nextbuildstatic_esm',
|
2022-09-28 12:29:22 +02:00
|
|
|
'nextbuild_esm',
|
2021-02-03 18:02:44 +01:00
|
|
|
'pages',
|
2022-09-28 12:29:22 +02:00
|
|
|
'pages_esm',
|
2021-02-03 18:02:44 +01:00
|
|
|
'lib',
|
2022-09-28 12:29:22 +02:00
|
|
|
'lib_esm',
|
2021-02-03 18:02:44 +01:00
|
|
|
'client',
|
2022-09-28 12:29:22 +02:00
|
|
|
'client_esm',
|
2021-02-03 18:02:44 +01:00
|
|
|
'telemetry',
|
2021-09-13 15:49:29 +02:00
|
|
|
'trace',
|
2021-06-30 11:43:31 +02:00
|
|
|
'shared',
|
2022-09-28 12:29:22 +02:00
|
|
|
'shared_esm',
|
2022-04-26 18:15:49 +02:00
|
|
|
'shared_re_exported',
|
2022-09-28 12:29:22 +02:00
|
|
|
'shared_re_exported_esm',
|
2021-06-30 13:44:40 +02:00
|
|
|
'server_wasm',
|
2023-08-14 20:45:50 +02:00
|
|
|
'experimental_testmode',
|
2021-02-11 10:55:56 +01:00
|
|
|
// we compile this each time so that fresh runtime data is pulled
|
|
|
|
// before each publish
|
|
|
|
'ncc_amp_optimizer',
|
2021-02-03 18:02:44 +01:00
|
|
|
],
|
|
|
|
opts
|
|
|
|
)
|
2023-09-08 18:05:29 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
export async function compile(task, opts) {
|
|
|
|
await task.serial(['next_compile', 'next_bundle'], opts)
|
|
|
|
|
2023-01-06 23:58:17 +01:00
|
|
|
await task.serial([
|
|
|
|
'ncc_react_refresh_utils',
|
2023-02-16 15:33:39 +01:00
|
|
|
'ncc_next_font',
|
2023-03-27 05:29:28 +02:00
|
|
|
'capsize_metrics',
|
2023-01-06 23:58:17 +01:00
|
|
|
])
|
2018-10-01 01:02:10 +02:00
|
|
|
}
|
|
|
|
|
2019-11-11 04:24:53 +01:00
|
|
|
export async function bin(task, opts) {
|
2019-05-29 13:57:26 +02:00
|
|
|
await task
|
2023-01-03 10:05:50 +01:00
|
|
|
.source('src/bin/*')
|
2021-07-14 20:12:04 +02:00
|
|
|
.swc('server', { stripExtension: true, dev: opts.dev })
|
2019-05-29 13:57:26 +02:00
|
|
|
.target('dist/bin', { mode: '0755' })
|
2018-10-01 01:02:10 +02:00
|
|
|
}
|
|
|
|
|
2019-11-11 04:24:53 +01:00
|
|
|
export async function cli(task, opts) {
|
2019-05-29 13:57:26 +02:00
|
|
|
await task
|
2023-01-03 10:05:50 +01:00
|
|
|
.source('src/cli/**/*.+(js|ts|tsx)')
|
2021-07-14 20:12:04 +02:00
|
|
|
.swc('server', { dev: opts.dev })
|
2019-05-29 13:57:26 +02:00
|
|
|
.target('dist/cli')
|
2019-02-26 21:57:32 +01:00
|
|
|
}
|
|
|
|
|
2019-11-11 04:24:53 +01:00
|
|
|
export async function lib(task, opts) {
|
2019-05-29 13:57:26 +02:00
|
|
|
await task
|
2023-02-17 01:55:03 +01:00
|
|
|
.source('src/lib/**/!(*.test).+(js|ts|tsx|json)')
|
2021-07-14 20:12:04 +02:00
|
|
|
.swc('server', { dev: opts.dev })
|
2019-05-29 13:57:26 +02:00
|
|
|
.target('dist/lib')
|
2018-10-01 01:02:10 +02:00
|
|
|
}
|
|
|
|
|
2022-09-28 12:29:22 +02:00
|
|
|
export async function lib_esm(task, opts) {
|
|
|
|
await task
|
2023-02-17 01:55:03 +01:00
|
|
|
.source('src/lib/**/!(*.test).+(js|ts|tsx|json)')
|
2022-09-28 12:29:22 +02:00
|
|
|
.swc('server', { dev: opts.dev, esm: true })
|
|
|
|
.target('dist/esm/lib')
|
|
|
|
}
|
|
|
|
|
2019-11-11 04:24:53 +01:00
|
|
|
export async function server(task, opts) {
|
2019-05-29 13:57:26 +02:00
|
|
|
await task
|
2023-02-17 01:55:03 +01:00
|
|
|
.source('src/server/**/!(*.test).+(js|ts|tsx)')
|
2021-07-14 20:12:04 +02:00
|
|
|
.swc('server', { dev: opts.dev })
|
2019-05-29 13:57:26 +02:00
|
|
|
.target('dist/server')
|
2018-10-01 01:02:10 +02:00
|
|
|
}
|
|
|
|
|
2022-09-28 12:29:22 +02:00
|
|
|
export async function server_esm(task, opts) {
|
|
|
|
await task
|
2023-09-11 22:17:52 +02:00
|
|
|
.source('src/server/**/!(*.test).+(js|mts|ts|tsx)')
|
2022-09-28 12:29:22 +02:00
|
|
|
.swc('server', { dev: opts.dev, esm: true })
|
|
|
|
.target('dist/esm/server')
|
|
|
|
}
|
|
|
|
|
Alias nextjs api entry to esm version for app router (#59852)
## What
When users specify `"type": "module"` in Next.js app, especially with
`create-next-app`, `Image` component is not working. An error
`Unsupported Server Component type: {...}` is thrown.
## Why
`next/image` API is mixing with a client component as default export and
a named export as server component. But the entry file of the API is
still CJS file, which will import the module as the object. So you'll
get `{ default, unstable_getImageProps }` when you do `import Image from
'next/image'` instead of `Image` component itself, where the CJS module
load all the exports as an object. This is expected behavior for ESM but
breaks the usage.
It only errors when you're using js extensions, if you're using
typescript, it still works. If you're using turbopack, it works in dev
mode.
This is also because webpack can't analyze the exports from CJS module
of that `next/image` entry file. Usually we can assign the default
export to the module itself, then attach other named exports onto it, so
the default export equals the `module.exports` itself. But for
`next/image` since the default export is an client component, doing that
will error with React as you cannot modify the react client reference.
Turbopack doesn't use the same way to analyze the default export, so it
doesn't have this problem.
## How
We create few ESM version of entry files of nextjs APIs, then pick up
them to let app router for bundling, instead of using the `next/<api
name>.js` CJS files. Those ESM entries still point to the `next/dist/..`
CJS files. In this way webpack and directly gets the exports from the
`next/dist/...` files and be aware of the module exports. No more CJS
module wrapping the ESM module, the default and named exports can
preserve correctly.
Fixes #54777
Closes NEXT-1774
Closes NEXT-1879
Closes NEXT-1923
2023-12-23 17:46:50 +01:00
|
|
|
// Provide ESM entry files for Next.js apis,
|
|
|
|
// Remain in ESM both for dist/ and dist/esm
|
|
|
|
export async function api_esm(task, opts) {
|
|
|
|
await task
|
|
|
|
.source('src/api/**/*.+(js|mts|ts|tsx)')
|
|
|
|
.swc('server', { dev: opts.dev, esm: true })
|
|
|
|
.target('dist/api')
|
|
|
|
.target('dist/esm/api')
|
|
|
|
}
|
|
|
|
|
2019-11-11 04:24:53 +01:00
|
|
|
export async function nextbuild(task, opts) {
|
2019-05-29 13:57:26 +02:00
|
|
|
await task
|
2023-09-25 19:05:07 +02:00
|
|
|
.source('src/build/**/*.+(js|ts|tsx)', {
|
|
|
|
ignore: [
|
|
|
|
'**/fixture/**',
|
|
|
|
'**/tests/**',
|
|
|
|
'**/jest/**',
|
|
|
|
'**/*.test.d.ts',
|
|
|
|
'**/*.test.+(js|ts|tsx)',
|
|
|
|
],
|
2021-08-03 14:02:23 +02:00
|
|
|
})
|
2021-07-14 20:12:04 +02:00
|
|
|
.swc('server', { dev: opts.dev })
|
2019-05-29 13:57:26 +02:00
|
|
|
.target('dist/build')
|
2018-10-01 01:02:10 +02:00
|
|
|
}
|
|
|
|
|
2022-09-28 12:29:22 +02:00
|
|
|
export async function nextbuild_esm(task, opts) {
|
|
|
|
await task
|
2023-09-25 19:05:07 +02:00
|
|
|
.source('src/build/**/*.+(js|ts|tsx)', {
|
|
|
|
ignore: [
|
|
|
|
'**/fixture/**',
|
|
|
|
'**/tests/**',
|
|
|
|
'**/jest/**',
|
|
|
|
'**/*.test.d.ts',
|
|
|
|
'**/*.test.+(js|ts|tsx)',
|
|
|
|
],
|
2022-09-28 12:29:22 +02:00
|
|
|
})
|
|
|
|
.swc('server', { dev: opts.dev, esm: true })
|
|
|
|
.target('dist/esm/build')
|
|
|
|
}
|
|
|
|
|
2022-05-11 20:13:13 +02:00
|
|
|
export async function nextbuildjest(task, opts) {
|
|
|
|
await task
|
2023-09-25 19:05:07 +02:00
|
|
|
.source('src/build/jest/**/*.+(js|ts|tsx)', {
|
|
|
|
ignore: [
|
|
|
|
'**/fixture/**',
|
|
|
|
'**/tests/**',
|
|
|
|
'**/*.test.d.ts',
|
|
|
|
'**/*.test.+(js|ts|tsx)',
|
|
|
|
],
|
2022-05-11 20:13:13 +02:00
|
|
|
})
|
|
|
|
.swc('server', { dev: opts.dev, interopClientDefaultExport: true })
|
|
|
|
.target('dist/build/jest')
|
|
|
|
}
|
|
|
|
|
2019-11-11 04:24:53 +01:00
|
|
|
export async function client(task, opts) {
|
2019-05-29 13:57:26 +02:00
|
|
|
await task
|
2023-02-17 01:55:03 +01:00
|
|
|
.source('src/client/**/!(*.test).+(js|ts|tsx)')
|
2022-04-12 16:32:42 +02:00
|
|
|
.swc('client', { dev: opts.dev, interopClientDefaultExport: true })
|
2019-05-29 13:57:26 +02:00
|
|
|
.target('dist/client')
|
2018-10-01 01:02:10 +02:00
|
|
|
}
|
|
|
|
|
2022-09-28 12:29:22 +02:00
|
|
|
export async function client_esm(task, opts) {
|
|
|
|
await task
|
2023-02-17 01:55:03 +01:00
|
|
|
.source('src/client/**/!(*.test).+(js|ts|tsx)')
|
2022-09-28 12:29:22 +02:00
|
|
|
.swc('client', { dev: opts.dev, esm: true })
|
|
|
|
.target('dist/esm/client')
|
|
|
|
}
|
|
|
|
|
2018-10-01 01:02:10 +02:00
|
|
|
// export is a reserved keyword for functions
|
2019-11-11 04:24:53 +01:00
|
|
|
export async function nextbuildstatic(task, opts) {
|
2019-05-29 13:57:26 +02:00
|
|
|
await task
|
2023-02-17 01:55:03 +01:00
|
|
|
.source('src/export/**/!(*.test).+(js|ts|tsx)')
|
2021-07-14 20:12:04 +02:00
|
|
|
.swc('server', { dev: opts.dev })
|
2019-05-29 13:57:26 +02:00
|
|
|
.target('dist/export')
|
2018-10-01 01:02:10 +02:00
|
|
|
}
|
|
|
|
|
2023-11-30 23:41:55 +01:00
|
|
|
// export is a reserved keyword for functions
|
|
|
|
export async function nextbuildstatic_esm(task, opts) {
|
|
|
|
await task
|
|
|
|
.source('src/export/**/!(*.test).+(js|ts|tsx)')
|
|
|
|
.swc('server', { dev: opts.dev, esm: true })
|
|
|
|
.target('dist/esm/export')
|
|
|
|
}
|
|
|
|
|
2021-02-03 18:02:44 +01:00
|
|
|
export async function pages_app(task, opts) {
|
|
|
|
await task
|
2023-01-03 10:05:50 +01:00
|
|
|
.source('src/pages/_app.tsx')
|
2022-11-24 18:10:45 +01:00
|
|
|
.swc('client', {
|
|
|
|
dev: opts.dev,
|
2023-09-15 17:41:05 +02:00
|
|
|
keepImportAttributes: true,
|
|
|
|
emitAssertForImportAttributes: true,
|
2022-11-24 18:10:45 +01:00
|
|
|
interopClientDefaultExport: true,
|
|
|
|
})
|
2021-02-03 18:02:44 +01:00
|
|
|
.target('dist/pages')
|
2020-01-21 15:18:06 +01:00
|
|
|
}
|
|
|
|
|
2021-02-03 18:02:44 +01:00
|
|
|
export async function pages_error(task, opts) {
|
|
|
|
await task
|
2023-01-03 10:05:50 +01:00
|
|
|
.source('src/pages/_error.tsx')
|
2022-11-23 06:37:18 +01:00
|
|
|
.swc('client', {
|
|
|
|
dev: opts.dev,
|
2023-09-15 17:41:05 +02:00
|
|
|
keepImportAttributes: true,
|
|
|
|
emitAssertForImportAttributes: true,
|
2022-11-23 06:37:18 +01:00
|
|
|
interopClientDefaultExport: true,
|
|
|
|
})
|
2021-02-03 18:02:44 +01:00
|
|
|
.target('dist/pages')
|
2018-10-01 01:02:10 +02:00
|
|
|
}
|
|
|
|
|
2021-02-03 18:02:44 +01:00
|
|
|
export async function pages_document(task, opts) {
|
|
|
|
await task
|
2023-01-03 10:05:50 +01:00
|
|
|
.source('src/pages/_document.tsx')
|
2023-09-15 17:41:05 +02:00
|
|
|
.swc('server', {
|
|
|
|
dev: opts.dev,
|
|
|
|
keepImportAttributes: true,
|
|
|
|
emitAssertForImportAttributes: true,
|
|
|
|
})
|
2021-02-03 18:02:44 +01:00
|
|
|
.target('dist/pages')
|
2020-01-21 15:18:06 +01:00
|
|
|
}
|
|
|
|
|
2022-09-28 12:29:22 +02:00
|
|
|
export async function pages_app_esm(task, opts) {
|
|
|
|
await task
|
2023-01-03 10:05:50 +01:00
|
|
|
.source('src/pages/_app.tsx')
|
2023-09-15 17:41:05 +02:00
|
|
|
.swc('client', {
|
|
|
|
dev: opts.dev,
|
|
|
|
keepImportAttributes: true,
|
|
|
|
emitAssertForImportAttributes: true,
|
|
|
|
esm: true,
|
|
|
|
})
|
2022-09-28 12:29:22 +02:00
|
|
|
.target('dist/esm/pages')
|
|
|
|
}
|
|
|
|
|
|
|
|
export async function pages_error_esm(task, opts) {
|
|
|
|
await task
|
2023-01-03 10:05:50 +01:00
|
|
|
.source('src/pages/_error.tsx')
|
2023-09-15 17:41:05 +02:00
|
|
|
.swc('client', {
|
|
|
|
dev: opts.dev,
|
|
|
|
keepImportAttributes: true,
|
|
|
|
emitAssertForImportAttributes: true,
|
|
|
|
esm: true,
|
|
|
|
})
|
2022-09-28 12:29:22 +02:00
|
|
|
.target('dist/esm/pages')
|
|
|
|
}
|
|
|
|
|
|
|
|
export async function pages_document_esm(task, opts) {
|
|
|
|
await task
|
2023-01-03 10:05:50 +01:00
|
|
|
.source('src/pages/_document.tsx')
|
2023-09-15 17:41:05 +02:00
|
|
|
.swc('server', {
|
|
|
|
dev: opts.dev,
|
|
|
|
keepImportAttributes: true,
|
|
|
|
emitAssertForImportAttributes: true,
|
|
|
|
esm: true,
|
|
|
|
})
|
2022-09-28 12:29:22 +02:00
|
|
|
.target('dist/esm/pages')
|
|
|
|
}
|
|
|
|
|
2021-02-03 18:02:44 +01:00
|
|
|
export async function pages(task, opts) {
|
2022-05-20 20:07:20 +02:00
|
|
|
await task.parallel(['pages_app', 'pages_error', 'pages_document'], opts)
|
2020-01-21 15:18:06 +01:00
|
|
|
}
|
|
|
|
|
2022-09-28 12:29:22 +02:00
|
|
|
export async function pages_esm(task, opts) {
|
|
|
|
await task.parallel(
|
|
|
|
['pages_app_esm', 'pages_error_esm', 'pages_document_esm'],
|
|
|
|
opts
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
2019-11-11 04:24:53 +01:00
|
|
|
export async function telemetry(task, opts) {
|
2019-08-29 18:43:06 +02:00
|
|
|
await task
|
2023-01-03 10:05:50 +01:00
|
|
|
.source('src/telemetry/**/*.+(js|ts|tsx)')
|
2021-07-14 20:12:04 +02:00
|
|
|
.swc('server', { dev: opts.dev })
|
2019-08-29 18:43:06 +02:00
|
|
|
.target('dist/telemetry')
|
|
|
|
}
|
|
|
|
|
2021-09-13 15:49:29 +02:00
|
|
|
export async function trace(task, opts) {
|
|
|
|
await task
|
2023-01-03 10:05:50 +01:00
|
|
|
.source('src/trace/**/*.+(js|ts|tsx)')
|
2021-09-13 15:49:29 +02:00
|
|
|
.swc('server', { dev: opts.dev })
|
|
|
|
.target('dist/trace')
|
|
|
|
}
|
|
|
|
|
2021-02-03 18:02:44 +01:00
|
|
|
export async function build(task, opts) {
|
refactor: rewrite config schema in zod (#56383)
The PR supersedes the https://github.com/vercel/next.js/pull/53150, which is way too outdated, has way too many conflicts, and also heavily relies on GitHub Copilot (which makes the progress slow and tedious).
The PR uses [`json-schema-to-zod`](https://github.com/StefanTerdell/json-schema-to-zod) (instead of the GitHub Copilot) to generate the zod schema, and manually replaces all generated `z.customRefine` with my hand-written zod schema.
TODO:
- [x] Convert schema
- [x] Reduce `z.any()` usage
- [x] Create human-readable errors from the `ZodError`
- [x] Update test cases to reflect the latest error message
-----
The benefit of using zod over ajv:
- Easier maintenance: zod schema is straightforward to compose.
- Better typescript support: config schema now strictly reflects the `NextConfig` type.
- Smaller installation size: by replacing `ajv` and `@segment/ajv-human-errors` w/ `zod`, I am able to reduce installation size by 114 KiB.
- Better Extension: the zod error message is easy to customize.
-----
In the previous PR https://github.com/vercel/next.js/pull/56083, @feedthejim replaces `zod` w/ `superstruct`. `superstruct` is lightweight and fast, which makes it perfect for creating simple schemas for RSC payload. But, this also means `superstruct` has its limitations compared to `zod`:
- `superstruct`'s syntax is different, and some utilities's usage is counter-intuitive:
- `z.array(z.string()).gt(1)` vs `s.size(s.array(s.string()), 1)`
- `z.numer().gt(1)` vs `s.size(s.number(), 1)`, `s.min(s.number(), 1)`
- `z.boolean().optional().nullable()` vs `s.nullable(s.optional(z.boolean()))`
- `superstruct` has weaker TypeScript support and worse DX compared to `zod` when composing huge schema:
- `zod.ZodType + z.object()` can provide a more detailed type mismatch message on which specific property is the culprit, while `Describe + s.object()` provides almost no information at all.
- `zod`'s schema is more powerful
- `z.function()` supports `z.args()` and `z.returns()`, while `superstruct` only has `s.func()`
- zod also has Promise type `z.promise()` and intersection type `z.and()`
- `superstruct`'s error is harder to parse compared to `zod`'s `ZodError`
So in the PR, I re-introduced `zod` for `next.config.js` validation.
2023-10-05 17:46:53 +02:00
|
|
|
await task.serial(['precompile', 'compile', 'generate_types'], opts)
|
2023-09-20 20:19:43 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
export async function generate_types(task, opts) {
|
2023-09-21 18:03:26 +02:00
|
|
|
await execa.command('pnpm run types', {
|
|
|
|
stdio: 'inherit',
|
|
|
|
})
|
2018-10-01 01:02:10 +02:00
|
|
|
}
|
|
|
|
|
2020-05-18 21:24:37 +02:00
|
|
|
export default async function (task) {
|
2021-02-03 18:02:44 +01:00
|
|
|
const opts = { dev: true }
|
2018-11-30 13:10:30 +01:00
|
|
|
await task.clear('dist')
|
2021-02-03 18:02:44 +01:00
|
|
|
await task.start('build', opts)
|
2023-01-03 15:52:18 +01:00
|
|
|
await task.watch('src/bin', 'bin', opts)
|
|
|
|
await task.watch('src/pages', 'pages', opts)
|
|
|
|
await task.watch('src/server', ['server', 'server_esm', 'server_wasm'], opts)
|
Alias nextjs api entry to esm version for app router (#59852)
## What
When users specify `"type": "module"` in Next.js app, especially with
`create-next-app`, `Image` component is not working. An error
`Unsupported Server Component type: {...}` is thrown.
## Why
`next/image` API is mixing with a client component as default export and
a named export as server component. But the entry file of the API is
still CJS file, which will import the module as the object. So you'll
get `{ default, unstable_getImageProps }` when you do `import Image from
'next/image'` instead of `Image` component itself, where the CJS module
load all the exports as an object. This is expected behavior for ESM but
breaks the usage.
It only errors when you're using js extensions, if you're using
typescript, it still works. If you're using turbopack, it works in dev
mode.
This is also because webpack can't analyze the exports from CJS module
of that `next/image` entry file. Usually we can assign the default
export to the module itself, then attach other named exports onto it, so
the default export equals the `module.exports` itself. But for
`next/image` since the default export is an client component, doing that
will error with React as you cannot modify the react client reference.
Turbopack doesn't use the same way to analyze the default export, so it
doesn't have this problem.
## How
We create few ESM version of entry files of nextjs APIs, then pick up
them to let app router for bundling, instead of using the `next/<api
name>.js` CJS files. Those ESM entries still point to the `next/dist/..`
CJS files. In this way webpack and directly gets the exports from the
`next/dist/...` files and be aware of the module exports. No more CJS
module wrapping the ESM module, the default and named exports can
preserve correctly.
Fixes #54777
Closes NEXT-1774
Closes NEXT-1879
Closes NEXT-1923
2023-12-23 17:46:50 +01:00
|
|
|
await task.watch('src/api', 'api_esm', opts)
|
2022-04-26 18:15:49 +02:00
|
|
|
await task.watch(
|
2023-01-03 15:52:18 +01:00
|
|
|
'src/build',
|
2022-12-14 16:06:53 +01:00
|
|
|
['nextbuild', 'nextbuild_esm', 'nextbuildjest'],
|
2022-04-26 18:15:49 +02:00
|
|
|
opts
|
|
|
|
)
|
2023-01-03 15:52:18 +01:00
|
|
|
await task.watch('src/export', 'nextbuildstatic', opts)
|
2023-11-30 23:41:55 +01:00
|
|
|
await task.watch('src/export', 'nextbuildstatic_esm', opts)
|
2023-01-03 15:52:18 +01:00
|
|
|
await task.watch('src/client', 'client', opts)
|
|
|
|
await task.watch('src/client', 'client_esm', opts)
|
|
|
|
await task.watch('src/lib', 'lib', opts)
|
|
|
|
await task.watch('src/lib', 'lib_esm', opts)
|
|
|
|
await task.watch('src/cli', 'cli', opts)
|
|
|
|
await task.watch('src/telemetry', 'telemetry', opts)
|
|
|
|
await task.watch('src/trace', 'trace', opts)
|
2022-04-26 18:15:49 +02:00
|
|
|
await task.watch(
|
2023-01-03 15:52:18 +01:00
|
|
|
'src/shared',
|
2022-12-14 16:06:53 +01:00
|
|
|
['shared_re_exported', 'shared_re_exported_esm', 'shared', 'shared_esm'],
|
2022-04-26 18:15:49 +02:00
|
|
|
opts
|
|
|
|
)
|
2019-09-04 16:00:54 +02:00
|
|
|
}
|
|
|
|
|
2021-06-30 11:43:31 +02:00
|
|
|
export async function shared(task, opts) {
|
|
|
|
await task
|
2023-09-25 19:05:07 +02:00
|
|
|
.source('src/shared/**/*.+(js|ts|tsx)', {
|
|
|
|
ignore: [
|
|
|
|
'src/shared/**/{amp,config,constants,dynamic,app-dynamic,head,runtime-config}.+(js|ts|tsx)',
|
|
|
|
'**/*.test.d.ts',
|
|
|
|
'**/*.test.+(js|ts|tsx)',
|
|
|
|
],
|
|
|
|
})
|
2022-06-29 18:34:03 +02:00
|
|
|
.swc('client', { dev: opts.dev })
|
2021-06-30 11:43:31 +02:00
|
|
|
.target('dist/shared')
|
|
|
|
}
|
|
|
|
|
2022-09-28 12:29:22 +02:00
|
|
|
export async function shared_esm(task, opts) {
|
|
|
|
await task
|
2023-09-25 19:05:07 +02:00
|
|
|
.source('src/shared/**/*.+(js|ts|tsx)', {
|
|
|
|
ignore: [
|
|
|
|
'src/shared/**/{amp,config,constants,dynamic,app-dynamic,head,runtime-config}.+(js|ts|tsx)',
|
|
|
|
'**/*.test.d.ts',
|
|
|
|
'**/*.test.+(js|ts|tsx)',
|
|
|
|
],
|
|
|
|
})
|
2022-09-28 12:29:22 +02:00
|
|
|
.swc('client', { dev: opts.dev, esm: true })
|
|
|
|
.target('dist/esm/shared')
|
|
|
|
}
|
|
|
|
|
2022-04-26 18:15:49 +02:00
|
|
|
export async function shared_re_exported(task, opts) {
|
|
|
|
await task
|
|
|
|
.source(
|
2023-09-25 19:05:07 +02:00
|
|
|
'src/shared/**/{amp,config,constants,dynamic,app-dynamic,head,runtime-config}.+(js|ts|tsx)',
|
|
|
|
{
|
|
|
|
ignore: ['**/*.test.d.ts', '**/*.test.+(js|ts|tsx)'],
|
|
|
|
}
|
2022-04-26 18:15:49 +02:00
|
|
|
)
|
2022-06-29 18:34:03 +02:00
|
|
|
.swc('client', { dev: opts.dev, interopClientDefaultExport: true })
|
2022-04-26 18:15:49 +02:00
|
|
|
.target('dist/shared')
|
|
|
|
}
|
|
|
|
|
2022-09-28 12:29:22 +02:00
|
|
|
export async function shared_re_exported_esm(task, opts) {
|
|
|
|
await task
|
2023-02-10 22:30:05 +01:00
|
|
|
.source(
|
2023-09-25 19:05:07 +02:00
|
|
|
'src/shared/**/{amp,config,constants,app-dynamic,dynamic,head}.+(js|ts|tsx)',
|
|
|
|
{
|
|
|
|
ignore: ['**/*.test.d.ts', '**/*.test.+(js|ts|tsx)'],
|
|
|
|
}
|
2023-02-10 22:30:05 +01:00
|
|
|
)
|
2022-09-28 12:29:22 +02:00
|
|
|
.swc('client', {
|
|
|
|
dev: opts.dev,
|
|
|
|
esm: true,
|
|
|
|
})
|
|
|
|
.target('dist/esm/shared')
|
|
|
|
}
|
|
|
|
|
2021-06-30 13:44:40 +02:00
|
|
|
export async function server_wasm(task, opts) {
|
2023-01-03 10:05:50 +01:00
|
|
|
await task.source('src/server/**/*.+(wasm)').target('dist/server')
|
2021-02-18 11:23:24 +01:00
|
|
|
}
|
|
|
|
|
2023-08-14 20:45:50 +02:00
|
|
|
export async function experimental_testmode(task, opts) {
|
|
|
|
await task
|
|
|
|
.source('src/experimental/testmode/**/!(*.test).+(js|ts|tsx)')
|
|
|
|
.swc('server', {})
|
|
|
|
.target('dist/experimental/testmode')
|
|
|
|
}
|
|
|
|
|
2019-11-11 04:24:53 +01:00
|
|
|
export async function release(task) {
|
2018-10-01 01:02:10 +02:00
|
|
|
await task.clear('dist').start('build')
|
|
|
|
}
|
2023-07-10 17:40:06 +02:00
|
|
|
|
server: bundle vendored react (#55362)
## What
This PR changes Next.js to bundle its vendored React libraries so that the App Router pages can use those built-in versions.
## Why
Next.js supports both Pages and App Router and we've gone through a lot of iteration to make sure that Next.js stays flexible wrt to the version of React used: in Pages, we want to use the React provided by the user and in the App Router, to be able to use it, we need to use the canary version of React, which we've built into Next.js for convenience.
The problem stems from the fact that you can't run two different instances of React (by design).
Previously we have a dual worker setup, where we would separate completely each Next.js versions (App and Pages) so that they would not overlap with each other, however this approach was not great performance and memory wise.
We've recently tried using an ESM loader and a single process, but this change would still opt you into the React canary version if you had an app page, which breaks some assumptions.
## How
A list of the changes in this PR:
### New versions of the Next.js runtime
Since we now compile a runtime per type of page (app/route/api/pages), in order to bundle the two versions of React that we vendored, we introduced a new type of bundle suffixed by `-experimental`. This bundle will have the bleeding edge React needed for Server Actions and Next.js will opt you in into that runtime automatically.
For internal contributors, it means that we now run a compiler for 10 subparts of Next.js:
- next_bundle_server
- next_bundle_pages_prod
- next_bundle_pages_turbo
- next_bundle_pages_dev
- next_bundle_app_turbo_experimental
- next_bundle_app_prod
- next_bundle_app_prod_experimental
- next_bundle_app_turbo
- next_bundle_app_dev_experimental
- next_bundle_app_dev
![image](https://github.com/vercel/next.js/assets/11064311/f340417d-845e-45b9-8e86-5b287a295c82)
### Simplified require-hook
Since the versions of React are correctly re-routed at build time for app pages, we don't need the require hook anymore
### Turbopack changes
The bundling logic in Turbopack has been addressed to properly follow the new logic
### Changes to the shared contexts system
Some context files need to have a shared instance between the rendering runtime and the user code, like the one that powers the `next/image` component. In general, the aliasing setup takes care of that but we need the require hook for code that is not compiled to reroute to the correct runtime. This only happens for pages node_modules.
A new Turbopack resolving plugin has been added to handle that logic in Turbopack.
### Misc changes
- `runtime-config` (that powers `next/config`) has been converted to an `.external` file, as it should have been
- there are some rules that have been added to the aliases to support the usage of `react-dom/server` in a server-components. We can do that now since the runtime takes care of separating the versions of React.
Co-authored-by: JJ Kasper <22380829+ijjk@users.noreply.github.com>
2023-09-15 21:49:39 +02:00
|
|
|
export async function next_bundle_app_turbo(task, opts) {
|
|
|
|
await task.source('dist').webpack({
|
|
|
|
watch: opts.dev,
|
|
|
|
config: require('./webpack.config')({
|
|
|
|
turbo: true,
|
|
|
|
bundleType: 'app',
|
|
|
|
}),
|
|
|
|
name: 'next-bundle-app-turbo',
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
export async function next_bundle_app_prod(task, opts) {
|
2023-09-08 18:05:29 +02:00
|
|
|
await task.source('dist').webpack({
|
|
|
|
watch: opts.dev,
|
|
|
|
config: require('./webpack.config')({
|
|
|
|
dev: false,
|
server: bundle vendored react (#55362)
## What
This PR changes Next.js to bundle its vendored React libraries so that the App Router pages can use those built-in versions.
## Why
Next.js supports both Pages and App Router and we've gone through a lot of iteration to make sure that Next.js stays flexible wrt to the version of React used: in Pages, we want to use the React provided by the user and in the App Router, to be able to use it, we need to use the canary version of React, which we've built into Next.js for convenience.
The problem stems from the fact that you can't run two different instances of React (by design).
Previously we have a dual worker setup, where we would separate completely each Next.js versions (App and Pages) so that they would not overlap with each other, however this approach was not great performance and memory wise.
We've recently tried using an ESM loader and a single process, but this change would still opt you into the React canary version if you had an app page, which breaks some assumptions.
## How
A list of the changes in this PR:
### New versions of the Next.js runtime
Since we now compile a runtime per type of page (app/route/api/pages), in order to bundle the two versions of React that we vendored, we introduced a new type of bundle suffixed by `-experimental`. This bundle will have the bleeding edge React needed for Server Actions and Next.js will opt you in into that runtime automatically.
For internal contributors, it means that we now run a compiler for 10 subparts of Next.js:
- next_bundle_server
- next_bundle_pages_prod
- next_bundle_pages_turbo
- next_bundle_pages_dev
- next_bundle_app_turbo_experimental
- next_bundle_app_prod
- next_bundle_app_prod_experimental
- next_bundle_app_turbo
- next_bundle_app_dev_experimental
- next_bundle_app_dev
![image](https://github.com/vercel/next.js/assets/11064311/f340417d-845e-45b9-8e86-5b287a295c82)
### Simplified require-hook
Since the versions of React are correctly re-routed at build time for app pages, we don't need the require hook anymore
### Turbopack changes
The bundling logic in Turbopack has been addressed to properly follow the new logic
### Changes to the shared contexts system
Some context files need to have a shared instance between the rendering runtime and the user code, like the one that powers the `next/image` component. In general, the aliasing setup takes care of that but we need the require hook for code that is not compiled to reroute to the correct runtime. This only happens for pages node_modules.
A new Turbopack resolving plugin has been added to handle that logic in Turbopack.
### Misc changes
- `runtime-config` (that powers `next/config`) has been converted to an `.external` file, as it should have been
- there are some rules that have been added to the aliases to support the usage of `react-dom/server` in a server-components. We can do that now since the runtime takes care of separating the versions of React.
Co-authored-by: JJ Kasper <22380829+ijjk@users.noreply.github.com>
2023-09-15 21:49:39 +02:00
|
|
|
bundleType: 'app',
|
2023-09-08 18:05:29 +02:00
|
|
|
}),
|
server: bundle vendored react (#55362)
## What
This PR changes Next.js to bundle its vendored React libraries so that the App Router pages can use those built-in versions.
## Why
Next.js supports both Pages and App Router and we've gone through a lot of iteration to make sure that Next.js stays flexible wrt to the version of React used: in Pages, we want to use the React provided by the user and in the App Router, to be able to use it, we need to use the canary version of React, which we've built into Next.js for convenience.
The problem stems from the fact that you can't run two different instances of React (by design).
Previously we have a dual worker setup, where we would separate completely each Next.js versions (App and Pages) so that they would not overlap with each other, however this approach was not great performance and memory wise.
We've recently tried using an ESM loader and a single process, but this change would still opt you into the React canary version if you had an app page, which breaks some assumptions.
## How
A list of the changes in this PR:
### New versions of the Next.js runtime
Since we now compile a runtime per type of page (app/route/api/pages), in order to bundle the two versions of React that we vendored, we introduced a new type of bundle suffixed by `-experimental`. This bundle will have the bleeding edge React needed for Server Actions and Next.js will opt you in into that runtime automatically.
For internal contributors, it means that we now run a compiler for 10 subparts of Next.js:
- next_bundle_server
- next_bundle_pages_prod
- next_bundle_pages_turbo
- next_bundle_pages_dev
- next_bundle_app_turbo_experimental
- next_bundle_app_prod
- next_bundle_app_prod_experimental
- next_bundle_app_turbo
- next_bundle_app_dev_experimental
- next_bundle_app_dev
![image](https://github.com/vercel/next.js/assets/11064311/f340417d-845e-45b9-8e86-5b287a295c82)
### Simplified require-hook
Since the versions of React are correctly re-routed at build time for app pages, we don't need the require hook anymore
### Turbopack changes
The bundling logic in Turbopack has been addressed to properly follow the new logic
### Changes to the shared contexts system
Some context files need to have a shared instance between the rendering runtime and the user code, like the one that powers the `next/image` component. In general, the aliasing setup takes care of that but we need the require hook for code that is not compiled to reroute to the correct runtime. This only happens for pages node_modules.
A new Turbopack resolving plugin has been added to handle that logic in Turbopack.
### Misc changes
- `runtime-config` (that powers `next/config`) has been converted to an `.external` file, as it should have been
- there are some rules that have been added to the aliases to support the usage of `react-dom/server` in a server-components. We can do that now since the runtime takes care of separating the versions of React.
Co-authored-by: JJ Kasper <22380829+ijjk@users.noreply.github.com>
2023-09-15 21:49:39 +02:00
|
|
|
name: 'next-bundle-app-prod',
|
2023-07-10 17:40:06 +02:00
|
|
|
})
|
2023-09-08 18:05:29 +02:00
|
|
|
}
|
2023-07-10 17:40:06 +02:00
|
|
|
|
server: bundle vendored react (#55362)
## What
This PR changes Next.js to bundle its vendored React libraries so that the App Router pages can use those built-in versions.
## Why
Next.js supports both Pages and App Router and we've gone through a lot of iteration to make sure that Next.js stays flexible wrt to the version of React used: in Pages, we want to use the React provided by the user and in the App Router, to be able to use it, we need to use the canary version of React, which we've built into Next.js for convenience.
The problem stems from the fact that you can't run two different instances of React (by design).
Previously we have a dual worker setup, where we would separate completely each Next.js versions (App and Pages) so that they would not overlap with each other, however this approach was not great performance and memory wise.
We've recently tried using an ESM loader and a single process, but this change would still opt you into the React canary version if you had an app page, which breaks some assumptions.
## How
A list of the changes in this PR:
### New versions of the Next.js runtime
Since we now compile a runtime per type of page (app/route/api/pages), in order to bundle the two versions of React that we vendored, we introduced a new type of bundle suffixed by `-experimental`. This bundle will have the bleeding edge React needed for Server Actions and Next.js will opt you in into that runtime automatically.
For internal contributors, it means that we now run a compiler for 10 subparts of Next.js:
- next_bundle_server
- next_bundle_pages_prod
- next_bundle_pages_turbo
- next_bundle_pages_dev
- next_bundle_app_turbo_experimental
- next_bundle_app_prod
- next_bundle_app_prod_experimental
- next_bundle_app_turbo
- next_bundle_app_dev_experimental
- next_bundle_app_dev
![image](https://github.com/vercel/next.js/assets/11064311/f340417d-845e-45b9-8e86-5b287a295c82)
### Simplified require-hook
Since the versions of React are correctly re-routed at build time for app pages, we don't need the require hook anymore
### Turbopack changes
The bundling logic in Turbopack has been addressed to properly follow the new logic
### Changes to the shared contexts system
Some context files need to have a shared instance between the rendering runtime and the user code, like the one that powers the `next/image` component. In general, the aliasing setup takes care of that but we need the require hook for code that is not compiled to reroute to the correct runtime. This only happens for pages node_modules.
A new Turbopack resolving plugin has been added to handle that logic in Turbopack.
### Misc changes
- `runtime-config` (that powers `next/config`) has been converted to an `.external` file, as it should have been
- there are some rules that have been added to the aliases to support the usage of `react-dom/server` in a server-components. We can do that now since the runtime takes care of separating the versions of React.
Co-authored-by: JJ Kasper <22380829+ijjk@users.noreply.github.com>
2023-09-15 21:49:39 +02:00
|
|
|
export async function next_bundle_app_dev(task, opts) {
|
2023-09-08 18:05:29 +02:00
|
|
|
await task.source('dist').webpack({
|
|
|
|
watch: opts.dev,
|
|
|
|
config: require('./webpack.config')({
|
|
|
|
dev: true,
|
server: bundle vendored react (#55362)
## What
This PR changes Next.js to bundle its vendored React libraries so that the App Router pages can use those built-in versions.
## Why
Next.js supports both Pages and App Router and we've gone through a lot of iteration to make sure that Next.js stays flexible wrt to the version of React used: in Pages, we want to use the React provided by the user and in the App Router, to be able to use it, we need to use the canary version of React, which we've built into Next.js for convenience.
The problem stems from the fact that you can't run two different instances of React (by design).
Previously we have a dual worker setup, where we would separate completely each Next.js versions (App and Pages) so that they would not overlap with each other, however this approach was not great performance and memory wise.
We've recently tried using an ESM loader and a single process, but this change would still opt you into the React canary version if you had an app page, which breaks some assumptions.
## How
A list of the changes in this PR:
### New versions of the Next.js runtime
Since we now compile a runtime per type of page (app/route/api/pages), in order to bundle the two versions of React that we vendored, we introduced a new type of bundle suffixed by `-experimental`. This bundle will have the bleeding edge React needed for Server Actions and Next.js will opt you in into that runtime automatically.
For internal contributors, it means that we now run a compiler for 10 subparts of Next.js:
- next_bundle_server
- next_bundle_pages_prod
- next_bundle_pages_turbo
- next_bundle_pages_dev
- next_bundle_app_turbo_experimental
- next_bundle_app_prod
- next_bundle_app_prod_experimental
- next_bundle_app_turbo
- next_bundle_app_dev_experimental
- next_bundle_app_dev
![image](https://github.com/vercel/next.js/assets/11064311/f340417d-845e-45b9-8e86-5b287a295c82)
### Simplified require-hook
Since the versions of React are correctly re-routed at build time for app pages, we don't need the require hook anymore
### Turbopack changes
The bundling logic in Turbopack has been addressed to properly follow the new logic
### Changes to the shared contexts system
Some context files need to have a shared instance between the rendering runtime and the user code, like the one that powers the `next/image` component. In general, the aliasing setup takes care of that but we need the require hook for code that is not compiled to reroute to the correct runtime. This only happens for pages node_modules.
A new Turbopack resolving plugin has been added to handle that logic in Turbopack.
### Misc changes
- `runtime-config` (that powers `next/config`) has been converted to an `.external` file, as it should have been
- there are some rules that have been added to the aliases to support the usage of `react-dom/server` in a server-components. We can do that now since the runtime takes care of separating the versions of React.
Co-authored-by: JJ Kasper <22380829+ijjk@users.noreply.github.com>
2023-09-15 21:49:39 +02:00
|
|
|
bundleType: 'app',
|
2023-09-08 18:05:29 +02:00
|
|
|
}),
|
server: bundle vendored react (#55362)
## What
This PR changes Next.js to bundle its vendored React libraries so that the App Router pages can use those built-in versions.
## Why
Next.js supports both Pages and App Router and we've gone through a lot of iteration to make sure that Next.js stays flexible wrt to the version of React used: in Pages, we want to use the React provided by the user and in the App Router, to be able to use it, we need to use the canary version of React, which we've built into Next.js for convenience.
The problem stems from the fact that you can't run two different instances of React (by design).
Previously we have a dual worker setup, where we would separate completely each Next.js versions (App and Pages) so that they would not overlap with each other, however this approach was not great performance and memory wise.
We've recently tried using an ESM loader and a single process, but this change would still opt you into the React canary version if you had an app page, which breaks some assumptions.
## How
A list of the changes in this PR:
### New versions of the Next.js runtime
Since we now compile a runtime per type of page (app/route/api/pages), in order to bundle the two versions of React that we vendored, we introduced a new type of bundle suffixed by `-experimental`. This bundle will have the bleeding edge React needed for Server Actions and Next.js will opt you in into that runtime automatically.
For internal contributors, it means that we now run a compiler for 10 subparts of Next.js:
- next_bundle_server
- next_bundle_pages_prod
- next_bundle_pages_turbo
- next_bundle_pages_dev
- next_bundle_app_turbo_experimental
- next_bundle_app_prod
- next_bundle_app_prod_experimental
- next_bundle_app_turbo
- next_bundle_app_dev_experimental
- next_bundle_app_dev
![image](https://github.com/vercel/next.js/assets/11064311/f340417d-845e-45b9-8e86-5b287a295c82)
### Simplified require-hook
Since the versions of React are correctly re-routed at build time for app pages, we don't need the require hook anymore
### Turbopack changes
The bundling logic in Turbopack has been addressed to properly follow the new logic
### Changes to the shared contexts system
Some context files need to have a shared instance between the rendering runtime and the user code, like the one that powers the `next/image` component. In general, the aliasing setup takes care of that but we need the require hook for code that is not compiled to reroute to the correct runtime. This only happens for pages node_modules.
A new Turbopack resolving plugin has been added to handle that logic in Turbopack.
### Misc changes
- `runtime-config` (that powers `next/config`) has been converted to an `.external` file, as it should have been
- there are some rules that have been added to the aliases to support the usage of `react-dom/server` in a server-components. We can do that now since the runtime takes care of separating the versions of React.
Co-authored-by: JJ Kasper <22380829+ijjk@users.noreply.github.com>
2023-09-15 21:49:39 +02:00
|
|
|
name: 'next-bundle-app-dev',
|
2023-07-10 17:40:06 +02:00
|
|
|
})
|
2023-09-08 18:05:29 +02:00
|
|
|
}
|
2023-07-10 17:40:06 +02:00
|
|
|
|
server: bundle vendored react (#55362)
## What
This PR changes Next.js to bundle its vendored React libraries so that the App Router pages can use those built-in versions.
## Why
Next.js supports both Pages and App Router and we've gone through a lot of iteration to make sure that Next.js stays flexible wrt to the version of React used: in Pages, we want to use the React provided by the user and in the App Router, to be able to use it, we need to use the canary version of React, which we've built into Next.js for convenience.
The problem stems from the fact that you can't run two different instances of React (by design).
Previously we have a dual worker setup, where we would separate completely each Next.js versions (App and Pages) so that they would not overlap with each other, however this approach was not great performance and memory wise.
We've recently tried using an ESM loader and a single process, but this change would still opt you into the React canary version if you had an app page, which breaks some assumptions.
## How
A list of the changes in this PR:
### New versions of the Next.js runtime
Since we now compile a runtime per type of page (app/route/api/pages), in order to bundle the two versions of React that we vendored, we introduced a new type of bundle suffixed by `-experimental`. This bundle will have the bleeding edge React needed for Server Actions and Next.js will opt you in into that runtime automatically.
For internal contributors, it means that we now run a compiler for 10 subparts of Next.js:
- next_bundle_server
- next_bundle_pages_prod
- next_bundle_pages_turbo
- next_bundle_pages_dev
- next_bundle_app_turbo_experimental
- next_bundle_app_prod
- next_bundle_app_prod_experimental
- next_bundle_app_turbo
- next_bundle_app_dev_experimental
- next_bundle_app_dev
![image](https://github.com/vercel/next.js/assets/11064311/f340417d-845e-45b9-8e86-5b287a295c82)
### Simplified require-hook
Since the versions of React are correctly re-routed at build time for app pages, we don't need the require hook anymore
### Turbopack changes
The bundling logic in Turbopack has been addressed to properly follow the new logic
### Changes to the shared contexts system
Some context files need to have a shared instance between the rendering runtime and the user code, like the one that powers the `next/image` component. In general, the aliasing setup takes care of that but we need the require hook for code that is not compiled to reroute to the correct runtime. This only happens for pages node_modules.
A new Turbopack resolving plugin has been added to handle that logic in Turbopack.
### Misc changes
- `runtime-config` (that powers `next/config`) has been converted to an `.external` file, as it should have been
- there are some rules that have been added to the aliases to support the usage of `react-dom/server` in a server-components. We can do that now since the runtime takes care of separating the versions of React.
Co-authored-by: JJ Kasper <22380829+ijjk@users.noreply.github.com>
2023-09-15 21:49:39 +02:00
|
|
|
export async function next_bundle_app_turbo_experimental(task, opts) {
|
2023-09-08 18:05:29 +02:00
|
|
|
await task.source('dist').webpack({
|
|
|
|
watch: opts.dev,
|
|
|
|
config: require('./webpack.config')({
|
|
|
|
turbo: true,
|
server: bundle vendored react (#55362)
## What
This PR changes Next.js to bundle its vendored React libraries so that the App Router pages can use those built-in versions.
## Why
Next.js supports both Pages and App Router and we've gone through a lot of iteration to make sure that Next.js stays flexible wrt to the version of React used: in Pages, we want to use the React provided by the user and in the App Router, to be able to use it, we need to use the canary version of React, which we've built into Next.js for convenience.
The problem stems from the fact that you can't run two different instances of React (by design).
Previously we have a dual worker setup, where we would separate completely each Next.js versions (App and Pages) so that they would not overlap with each other, however this approach was not great performance and memory wise.
We've recently tried using an ESM loader and a single process, but this change would still opt you into the React canary version if you had an app page, which breaks some assumptions.
## How
A list of the changes in this PR:
### New versions of the Next.js runtime
Since we now compile a runtime per type of page (app/route/api/pages), in order to bundle the two versions of React that we vendored, we introduced a new type of bundle suffixed by `-experimental`. This bundle will have the bleeding edge React needed for Server Actions and Next.js will opt you in into that runtime automatically.
For internal contributors, it means that we now run a compiler for 10 subparts of Next.js:
- next_bundle_server
- next_bundle_pages_prod
- next_bundle_pages_turbo
- next_bundle_pages_dev
- next_bundle_app_turbo_experimental
- next_bundle_app_prod
- next_bundle_app_prod_experimental
- next_bundle_app_turbo
- next_bundle_app_dev_experimental
- next_bundle_app_dev
![image](https://github.com/vercel/next.js/assets/11064311/f340417d-845e-45b9-8e86-5b287a295c82)
### Simplified require-hook
Since the versions of React are correctly re-routed at build time for app pages, we don't need the require hook anymore
### Turbopack changes
The bundling logic in Turbopack has been addressed to properly follow the new logic
### Changes to the shared contexts system
Some context files need to have a shared instance between the rendering runtime and the user code, like the one that powers the `next/image` component. In general, the aliasing setup takes care of that but we need the require hook for code that is not compiled to reroute to the correct runtime. This only happens for pages node_modules.
A new Turbopack resolving plugin has been added to handle that logic in Turbopack.
### Misc changes
- `runtime-config` (that powers `next/config`) has been converted to an `.external` file, as it should have been
- there are some rules that have been added to the aliases to support the usage of `react-dom/server` in a server-components. We can do that now since the runtime takes care of separating the versions of React.
Co-authored-by: JJ Kasper <22380829+ijjk@users.noreply.github.com>
2023-09-15 21:49:39 +02:00
|
|
|
bundleType: 'app',
|
|
|
|
experimental: true,
|
|
|
|
}),
|
|
|
|
name: 'next-bundle-app-turbo-experimental',
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
export async function next_bundle_app_prod_experimental(task, opts) {
|
|
|
|
await task.source('dist').webpack({
|
|
|
|
watch: opts.dev,
|
|
|
|
config: require('./webpack.config')({
|
|
|
|
dev: false,
|
|
|
|
bundleType: 'app',
|
|
|
|
experimental: true,
|
2023-09-08 18:05:29 +02:00
|
|
|
}),
|
server: bundle vendored react (#55362)
## What
This PR changes Next.js to bundle its vendored React libraries so that the App Router pages can use those built-in versions.
## Why
Next.js supports both Pages and App Router and we've gone through a lot of iteration to make sure that Next.js stays flexible wrt to the version of React used: in Pages, we want to use the React provided by the user and in the App Router, to be able to use it, we need to use the canary version of React, which we've built into Next.js for convenience.
The problem stems from the fact that you can't run two different instances of React (by design).
Previously we have a dual worker setup, where we would separate completely each Next.js versions (App and Pages) so that they would not overlap with each other, however this approach was not great performance and memory wise.
We've recently tried using an ESM loader and a single process, but this change would still opt you into the React canary version if you had an app page, which breaks some assumptions.
## How
A list of the changes in this PR:
### New versions of the Next.js runtime
Since we now compile a runtime per type of page (app/route/api/pages), in order to bundle the two versions of React that we vendored, we introduced a new type of bundle suffixed by `-experimental`. This bundle will have the bleeding edge React needed for Server Actions and Next.js will opt you in into that runtime automatically.
For internal contributors, it means that we now run a compiler for 10 subparts of Next.js:
- next_bundle_server
- next_bundle_pages_prod
- next_bundle_pages_turbo
- next_bundle_pages_dev
- next_bundle_app_turbo_experimental
- next_bundle_app_prod
- next_bundle_app_prod_experimental
- next_bundle_app_turbo
- next_bundle_app_dev_experimental
- next_bundle_app_dev
![image](https://github.com/vercel/next.js/assets/11064311/f340417d-845e-45b9-8e86-5b287a295c82)
### Simplified require-hook
Since the versions of React are correctly re-routed at build time for app pages, we don't need the require hook anymore
### Turbopack changes
The bundling logic in Turbopack has been addressed to properly follow the new logic
### Changes to the shared contexts system
Some context files need to have a shared instance between the rendering runtime and the user code, like the one that powers the `next/image` component. In general, the aliasing setup takes care of that but we need the require hook for code that is not compiled to reroute to the correct runtime. This only happens for pages node_modules.
A new Turbopack resolving plugin has been added to handle that logic in Turbopack.
### Misc changes
- `runtime-config` (that powers `next/config`) has been converted to an `.external` file, as it should have been
- there are some rules that have been added to the aliases to support the usage of `react-dom/server` in a server-components. We can do that now since the runtime takes care of separating the versions of React.
Co-authored-by: JJ Kasper <22380829+ijjk@users.noreply.github.com>
2023-09-15 21:49:39 +02:00
|
|
|
name: 'next-bundle-app-prod-experimental',
|
2023-07-10 17:40:06 +02:00
|
|
|
})
|
2023-09-08 18:05:29 +02:00
|
|
|
}
|
server: bundle vendored react (#55362)
## What
This PR changes Next.js to bundle its vendored React libraries so that the App Router pages can use those built-in versions.
## Why
Next.js supports both Pages and App Router and we've gone through a lot of iteration to make sure that Next.js stays flexible wrt to the version of React used: in Pages, we want to use the React provided by the user and in the App Router, to be able to use it, we need to use the canary version of React, which we've built into Next.js for convenience.
The problem stems from the fact that you can't run two different instances of React (by design).
Previously we have a dual worker setup, where we would separate completely each Next.js versions (App and Pages) so that they would not overlap with each other, however this approach was not great performance and memory wise.
We've recently tried using an ESM loader and a single process, but this change would still opt you into the React canary version if you had an app page, which breaks some assumptions.
## How
A list of the changes in this PR:
### New versions of the Next.js runtime
Since we now compile a runtime per type of page (app/route/api/pages), in order to bundle the two versions of React that we vendored, we introduced a new type of bundle suffixed by `-experimental`. This bundle will have the bleeding edge React needed for Server Actions and Next.js will opt you in into that runtime automatically.
For internal contributors, it means that we now run a compiler for 10 subparts of Next.js:
- next_bundle_server
- next_bundle_pages_prod
- next_bundle_pages_turbo
- next_bundle_pages_dev
- next_bundle_app_turbo_experimental
- next_bundle_app_prod
- next_bundle_app_prod_experimental
- next_bundle_app_turbo
- next_bundle_app_dev_experimental
- next_bundle_app_dev
![image](https://github.com/vercel/next.js/assets/11064311/f340417d-845e-45b9-8e86-5b287a295c82)
### Simplified require-hook
Since the versions of React are correctly re-routed at build time for app pages, we don't need the require hook anymore
### Turbopack changes
The bundling logic in Turbopack has been addressed to properly follow the new logic
### Changes to the shared contexts system
Some context files need to have a shared instance between the rendering runtime and the user code, like the one that powers the `next/image` component. In general, the aliasing setup takes care of that but we need the require hook for code that is not compiled to reroute to the correct runtime. This only happens for pages node_modules.
A new Turbopack resolving plugin has been added to handle that logic in Turbopack.
### Misc changes
- `runtime-config` (that powers `next/config`) has been converted to an `.external` file, as it should have been
- there are some rules that have been added to the aliases to support the usage of `react-dom/server` in a server-components. We can do that now since the runtime takes care of separating the versions of React.
Co-authored-by: JJ Kasper <22380829+ijjk@users.noreply.github.com>
2023-09-15 21:49:39 +02:00
|
|
|
|
|
|
|
export async function next_bundle_app_dev_experimental(task, opts) {
|
|
|
|
await task.source('dist').webpack({
|
|
|
|
watch: opts.dev,
|
|
|
|
config: require('./webpack.config')({
|
|
|
|
dev: true,
|
|
|
|
bundleType: 'app',
|
|
|
|
experimental: true,
|
|
|
|
}),
|
|
|
|
name: 'next-bundle-app-dev-experimental',
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
export async function next_bundle_pages_prod(task, opts) {
|
|
|
|
await task.source('dist').webpack({
|
|
|
|
watch: opts.dev,
|
|
|
|
config: require('./webpack.config')({
|
|
|
|
dev: false,
|
|
|
|
bundleType: 'pages',
|
|
|
|
}),
|
|
|
|
name: 'next-bundle-pages-prod',
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
export async function next_bundle_pages_dev(task, opts) {
|
|
|
|
await task.source('dist').webpack({
|
|
|
|
watch: opts.dev,
|
|
|
|
config: require('./webpack.config')({
|
|
|
|
dev: true,
|
|
|
|
bundleType: 'pages',
|
|
|
|
}),
|
|
|
|
name: 'next-bundle-pages-dev',
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
export async function next_bundle_pages_turbo(task, opts) {
|
|
|
|
await task.source('dist').webpack({
|
|
|
|
watch: opts.dev,
|
|
|
|
config: require('./webpack.config')({
|
|
|
|
turbo: true,
|
|
|
|
bundleType: 'pages',
|
|
|
|
}),
|
|
|
|
name: 'next-bundle-pages-turbo',
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
export async function next_bundle_server(task, opts) {
|
|
|
|
await task.source('dist').webpack({
|
|
|
|
watch: opts.dev,
|
|
|
|
config: require('./webpack.config')({
|
|
|
|
dev: false,
|
|
|
|
bundleType: 'server',
|
|
|
|
}),
|
|
|
|
name: 'next-bundle-server',
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2023-09-08 18:05:29 +02:00
|
|
|
export async function next_bundle(task, opts) {
|
|
|
|
await task.parallel(
|
server: bundle vendored react (#55362)
## What
This PR changes Next.js to bundle its vendored React libraries so that the App Router pages can use those built-in versions.
## Why
Next.js supports both Pages and App Router and we've gone through a lot of iteration to make sure that Next.js stays flexible wrt to the version of React used: in Pages, we want to use the React provided by the user and in the App Router, to be able to use it, we need to use the canary version of React, which we've built into Next.js for convenience.
The problem stems from the fact that you can't run two different instances of React (by design).
Previously we have a dual worker setup, where we would separate completely each Next.js versions (App and Pages) so that they would not overlap with each other, however this approach was not great performance and memory wise.
We've recently tried using an ESM loader and a single process, but this change would still opt you into the React canary version if you had an app page, which breaks some assumptions.
## How
A list of the changes in this PR:
### New versions of the Next.js runtime
Since we now compile a runtime per type of page (app/route/api/pages), in order to bundle the two versions of React that we vendored, we introduced a new type of bundle suffixed by `-experimental`. This bundle will have the bleeding edge React needed for Server Actions and Next.js will opt you in into that runtime automatically.
For internal contributors, it means that we now run a compiler for 10 subparts of Next.js:
- next_bundle_server
- next_bundle_pages_prod
- next_bundle_pages_turbo
- next_bundle_pages_dev
- next_bundle_app_turbo_experimental
- next_bundle_app_prod
- next_bundle_app_prod_experimental
- next_bundle_app_turbo
- next_bundle_app_dev_experimental
- next_bundle_app_dev
![image](https://github.com/vercel/next.js/assets/11064311/f340417d-845e-45b9-8e86-5b287a295c82)
### Simplified require-hook
Since the versions of React are correctly re-routed at build time for app pages, we don't need the require hook anymore
### Turbopack changes
The bundling logic in Turbopack has been addressed to properly follow the new logic
### Changes to the shared contexts system
Some context files need to have a shared instance between the rendering runtime and the user code, like the one that powers the `next/image` component. In general, the aliasing setup takes care of that but we need the require hook for code that is not compiled to reroute to the correct runtime. This only happens for pages node_modules.
A new Turbopack resolving plugin has been added to handle that logic in Turbopack.
### Misc changes
- `runtime-config` (that powers `next/config`) has been converted to an `.external` file, as it should have been
- there are some rules that have been added to the aliases to support the usage of `react-dom/server` in a server-components. We can do that now since the runtime takes care of separating the versions of React.
Co-authored-by: JJ Kasper <22380829+ijjk@users.noreply.github.com>
2023-09-15 21:49:39 +02:00
|
|
|
[
|
|
|
|
// builds the app (route/page) bundles
|
|
|
|
'next_bundle_app_turbo',
|
|
|
|
'next_bundle_app_prod',
|
|
|
|
'next_bundle_app_dev',
|
|
|
|
// builds the app (route/page) bundles with react experimental
|
|
|
|
'next_bundle_app_turbo_experimental',
|
|
|
|
'next_bundle_app_prod_experimental',
|
|
|
|
'next_bundle_app_dev_experimental',
|
|
|
|
// builds the pages (page/api) bundles
|
|
|
|
'next_bundle_pages_prod',
|
|
|
|
'next_bundle_pages_dev',
|
|
|
|
'next_bundle_pages_turbo',
|
|
|
|
// builds the minimal server
|
|
|
|
'next_bundle_server',
|
|
|
|
],
|
2023-09-08 18:05:29 +02:00
|
|
|
opts
|
2023-07-10 17:40:06 +02:00
|
|
|
)
|
|
|
|
}
|
2023-10-06 00:01:45 +02:00
|
|
|
|
|
|
|
function writeJson(file, obj, { spaces = 0 } = {}) {
|
|
|
|
return fs.writeFile(
|
|
|
|
file,
|
|
|
|
JSON.stringify(obj, null, spaces) + (spaces === 0 ? '\n' : '')
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
function rmrf(path, options) {
|
|
|
|
return fs.rm(path, { recursive: true, force: true, ...options })
|
|
|
|
}
|
|
|
|
|
|
|
|
function readJson(path) {
|
|
|
|
return fs.readFile(path, 'utf8').then((content) => JSON.parse(content))
|
|
|
|
}
|