taskfile.js 24.6 KB
Newer Older
T
Tim Neutkens 已提交
1
const notifier = require('node-notifier')
T
Tim Neutkens 已提交
2
const relative = require('path').relative
3

G
Guy Bedford 已提交
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34
export async function next__polyfill_nomodule(task, opts) {
  await task
    .source(
      opts.src ||
        relative(__dirname, require.resolve('@next/polyfill-nomodule'))
    )
    .target('dist/build/polyfills')
}

export async function finally_polyfill(task, opts) {
  await task
    .source(
      opts.src || relative(__dirname, require.resolve('finally-polyfill'))
    )
    .target('dist/build/polyfills')
}

export async function unfetch(task, opts) {
  await task
    .source(opts.src || relative(__dirname, require.resolve('unfetch')))
    .target('dist/build/polyfills')
}

export async function browser_polyfills(task) {
  await task.parallel([
    'next__polyfill_nomodule',
    'finally_polyfill',
    'unfetch',
  ])
}

G
Guy Bedford 已提交
35
const externals = {
G
Guy Bedford 已提交
36 37 38 39 40 41 42 43
  // Babel
  '@babel/core': '@babel/core',

  // Browserslist (post-css plugins)
  browserslist: 'browserslist',

  // Webpack indirect and direct dependencies:
  webpack: 'webpack',
44 45 46
  // dependents: webpack-dev-middleware
  'webpack/lib/node/NodeOutputFileSystem':
    'webpack/lib/node/NodeOutputFileSystem',
G
Guy Bedford 已提交
47 48 49
  chokidar: 'chokidar',
  // dependents: babel-loader, async-retry, autodll-webpack-plugin, cache-loader
  'find-cache-dir': 'find-cache-dir',
G
Guy Bedford 已提交
50 51
  // dependents: thread-loader
  'loader-runner': 'loader-runner',
G
Guy Bedford 已提交
52
  // dependents: thread-loader, babel-loader
G
Guy Bedford 已提交
53
  'loader-utils': 'loader-utils',
G
Guy Bedford 已提交
54 55 56 57 58 59
  // dependents: babel-loader
  mkdirp: 'mkdirp',
  // dependents: thread-loader, cache-loader
  'neo-async': 'neo-async',
  // dependents: cache-loader, style-loader, file-loader
  'schema-utils': 'schema-utils',
G
Guy Bedford 已提交
60 61
}

G
Guy Bedford 已提交
62
// eslint-disable-next-line camelcase
63
externals['amphtml-validator'] = 'next/dist/compiled/amphtml-validator'
G
Guy Bedford 已提交
64 65 66 67 68
export async function ncc_amphtml_validator(task, opts) {
  await task
    .source(
      opts.src || relative(__dirname, require.resolve('amphtml-validator'))
    )
G
Guy Bedford 已提交
69
    .ncc({ packageName: 'amphtml-validator', externals })
70
    .target('compiled/amphtml-validator')
G
Guy Bedford 已提交
71
}
T
Tim Neutkens 已提交
72
// eslint-disable-next-line camelcase
73
externals['arg'] = 'distcompiled/arg'
74
export async function ncc_arg(task, opts) {
T
Tim Neutkens 已提交
75 76 77
  await task
    .source(opts.src || relative(__dirname, require.resolve('arg')))
    .ncc({ packageName: 'arg' })
78
    .target('compiled/arg')
T
Tim Neutkens 已提交
79
}
80
// eslint-disable-next-line camelcase
81
externals['async-retry'] = 'next/dist/compiled/async-retry'
G
Guy Bedford 已提交
82 83 84
export async function ncc_async_retry(task, opts) {
  await task
    .source(opts.src || relative(__dirname, require.resolve('async-retry')))
G
Guy Bedford 已提交
85 86
    .ncc({
      packageName: 'async-retry',
G
Guy Bedford 已提交
87
      externals,
G
Guy Bedford 已提交
88
    })
89
    .target('compiled/async-retry')
G
Guy Bedford 已提交
90 91
}
// eslint-disable-next-line camelcase
92
externals['async-sema'] = 'next/dist/compiled/async-sema'
G
Guy Bedford 已提交
93 94 95
export async function ncc_async_sema(task, opts) {
  await task
    .source(opts.src || relative(__dirname, require.resolve('async-sema')))
G
Guy Bedford 已提交
96
    .ncc({ packageName: 'async-sema', externals })
97
    .target('compiled/async-sema')
G
Guy Bedford 已提交
98 99
}
// eslint-disable-next-line camelcase
G
Guy Bedford 已提交
100 101 102 103 104 105
externals['autodll-webpack-plugin'] =
  'next/dist/compiled/autodll-webpack-plugin'
export async function ncc_autodll_webpack_plugin(task, opts) {
  await task
    .source(opts.src || 'build/bundles/autodll-webpack-plugin.js')
    .ncc({ packageName: 'autodll-webpack-plugin', externals })
106
    .target('compiled/autodll-webpack-plugin')
G
Guy Bedford 已提交
107 108
}
// eslint-disable-next-line camelcase
G
Guy Bedford 已提交
109 110 111 112 113
externals['babel-loader'] = 'next/dist/compiled/babel-loader'
export async function ncc_babel_loader(task, opts) {
  await task
    .source(opts.src || relative(__dirname, require.resolve('babel-loader')))
    .ncc({ packageName: 'babel-loader', externals })
114
    .target('compiled/babel-loader')
G
Guy Bedford 已提交
115 116 117 118 119 120 121
}
// eslint-disable-next-line camelcase
externals['cache-loader'] = 'next/dist/compiled/cache-loader'
export async function ncc_cache_loader(task, opts) {
  await task
    .source(opts.src || relative(__dirname, require.resolve('cache-loader')))
    .ncc({ packageName: 'cache-loader', externals })
122
    .target('compiled/cache-loader')
G
Guy Bedford 已提交
123 124
}
// eslint-disable-next-line camelcase
G
Guy Bedford 已提交
125 126
// NB: Used by other dependencies, but Zeit version is a duplicate
// version so can be inlined anyway (although may change in future)
127
externals['chalk'] = 'next/dist/compiled/chalk'
G
Guy Bedford 已提交
128 129 130
export async function ncc_chalk(task, opts) {
  await task
    .source(opts.src || relative(__dirname, require.resolve('chalk')))
G
Guy Bedford 已提交
131
    .ncc({ packageName: 'chalk', externals })
132
    .target('compiled/chalk')
G
Guy Bedford 已提交
133 134
}
// eslint-disable-next-line camelcase
135
externals['ci-info'] = 'next/dist/compiled/ci-info'
G
Guy Bedford 已提交
136 137 138
export async function ncc_ci_info(task, opts) {
  await task
    .source(opts.src || relative(__dirname, require.resolve('ci-info')))
G
Guy Bedford 已提交
139
    .ncc({ packageName: 'ci-info', externals })
140
    .target('compiled/ci-info')
G
Guy Bedford 已提交
141 142
}
// eslint-disable-next-line camelcase
143
externals['compression'] = 'next/dist/compiled/compression'
G
Guy Bedford 已提交
144 145 146
export async function ncc_compression(task, opts) {
  await task
    .source(opts.src || relative(__dirname, require.resolve('compression')))
G
Guy Bedford 已提交
147
    .ncc({ packageName: 'compression', externals })
148
    .target('compiled/compression')
G
Guy Bedford 已提交
149 150
}
// eslint-disable-next-line camelcase
151
externals['conf'] = 'next/dist/compiled/conf'
G
conf  
Guy Bedford 已提交
152 153 154
export async function ncc_conf(task, opts) {
  await task
    .source(opts.src || relative(__dirname, require.resolve('conf')))
G
Guy Bedford 已提交
155
    .ncc({ packageName: 'conf', externals })
156
    .target('compiled/conf')
G
conf  
Guy Bedford 已提交
157 158
}
// eslint-disable-next-line camelcase
159
externals['content-type'] = 'next/dist/compiled/content-type'
G
Guy Bedford 已提交
160 161 162
export async function ncc_content_type(task, opts) {
  await task
    .source(opts.src || relative(__dirname, require.resolve('content-type')))
G
Guy Bedford 已提交
163
    .ncc({ packageName: 'content-type', externals })
164
    .target('compiled/content-type')
G
Guy Bedford 已提交
165 166
}
// eslint-disable-next-line camelcase
167
externals['cookie'] = 'next/dist/compiled/cookie'
G
cookie  
Guy Bedford 已提交
168 169 170
export async function ncc_cookie(task, opts) {
  await task
    .source(opts.src || relative(__dirname, require.resolve('cookie')))
G
Guy Bedford 已提交
171
    .ncc({ packageName: 'cookie', externals })
172
    .target('compiled/cookie')
G
cookie  
Guy Bedford 已提交
173 174
}
// eslint-disable-next-line camelcase
G
Guy Bedford 已提交
175 176 177 178 179
externals['cssnano-simple'] = 'next/dist/compiled/cssnano-simple'
export async function ncc_cssnano_simple(task, opts) {
  await task
    .source(opts.src || relative(__dirname, require.resolve('cssnano-simple')))
    .ncc({ packageName: 'cssnano-simple', externals })
180
    .target('compiled/cssnano-simple')
G
Guy Bedford 已提交
181 182
}
// eslint-disable-next-line camelcase
183
externals['devalue'] = 'next/dist/compiled/devalue'
G
devalue  
Guy Bedford 已提交
184 185 186
export async function ncc_devalue(task, opts) {
  await task
    .source(opts.src || relative(__dirname, require.resolve('devalue')))
G
Guy Bedford 已提交
187
    .ncc({ packageName: 'devalue', externals })
188
    .target('compiled/devalue')
G
devalue  
Guy Bedford 已提交
189 190
}
// eslint-disable-next-line camelcase
191
externals['dotenv'] = 'next/dist/compiled/dotenv'
192 193 194
export async function ncc_dotenv(task, opts) {
  await task
    .source(opts.src || relative(__dirname, require.resolve('dotenv')))
G
Guy Bedford 已提交
195
    .ncc({ packageName: 'dotenv', externals })
196
    .target('compiled/dotenv')
197 198
}
// eslint-disable-next-line camelcase
199
externals['dotenv-expand'] = 'next/dist/compiled/dotenv-expand'
200 201 202
export async function ncc_dotenv_expand(task, opts) {
  await task
    .source(opts.src || relative(__dirname, require.resolve('dotenv-expand')))
G
Guy Bedford 已提交
203
    .ncc({ packageName: 'dotenv-expand', externals })
204
    .target('compiled/dotenv-expand')
205
}
206
externals['escape-string-regexp'] = 'next/dist/compiled/escape-string-regexp'
207
// eslint-disable-next-line camelcase
G
Guy Bedford 已提交
208 209 210 211 212
export async function ncc_escape_string_regexp(task, opts) {
  await task
    .source(
      opts.src || relative(__dirname, require.resolve('escape-string-regexp'))
    )
G
Guy Bedford 已提交
213
    .ncc({ packageName: 'escape-string-regexp', externals })
214
    .target('compiled/escape-string-regexp')
G
Guy Bedford 已提交
215 216
}
// eslint-disable-next-line camelcase
217
externals['etag'] = 'next/dist/compiled/etag'
G
etag  
Guy Bedford 已提交
218 219 220
export async function ncc_etag(task, opts) {
  await task
    .source(opts.src || relative(__dirname, require.resolve('etag')))
G
Guy Bedford 已提交
221
    .ncc({ packageName: 'etag', externals })
222
    .target('compiled/etag')
G
etag  
Guy Bedford 已提交
223 224
}
// eslint-disable-next-line camelcase
G
Guy Bedford 已提交
225 226 227 228 229
externals['file-loader'] = 'next/dist/compiled/file-loader'
export async function ncc_file_loader(task, opts) {
  await task
    .source(opts.src || relative(__dirname, require.resolve('file-loader')))
    .ncc({ packageName: 'file-loader', externals })
230
    .target('compiled/file-loader')
G
Guy Bedford 已提交
231 232
}
// eslint-disable-next-line camelcase
233
externals['find-up'] = 'next/dist/compiled/find-up'
G
find-up  
Guy Bedford 已提交
234 235 236 237
export async function ncc_find_up(task, opts) {
  await task
    .source(opts.src || relative(__dirname, require.resolve('find-up')))
    .ncc({ packageName: 'find-up', externals })
238
    .target('compiled/find-up')
G
find-up  
Guy Bedford 已提交
239 240
}
// eslint-disable-next-line camelcase
241
externals['fresh'] = 'next/dist/compiled/fresh'
G
fresh  
Guy Bedford 已提交
242 243 244
export async function ncc_fresh(task, opts) {
  await task
    .source(opts.src || relative(__dirname, require.resolve('fresh')))
G
Guy Bedford 已提交
245
    .ncc({ packageName: 'fresh', externals })
246
    .target('compiled/fresh')
G
fresh  
Guy Bedford 已提交
247 248
}
// eslint-disable-next-line camelcase
249
externals['gzip-size'] = 'next/dist/compiled/gzip-size'
G
Guy Bedford 已提交
250 251 252
export async function ncc_gzip_size(task, opts) {
  await task
    .source(opts.src || relative(__dirname, require.resolve('gzip-size')))
G
Guy Bedford 已提交
253
    .ncc({ packageName: 'gzip-size', externals })
254
    .target('compiled/gzip-size')
G
Guy Bedford 已提交
255 256
}
// eslint-disable-next-line camelcase
257
externals['http-proxy'] = 'next/dist/compiled/http-proxy'
G
Guy Bedford 已提交
258 259 260
export async function ncc_http_proxy(task, opts) {
  await task
    .source(opts.src || relative(__dirname, require.resolve('http-proxy')))
G
Guy Bedford 已提交
261
    .ncc({ packageName: 'http-proxy', externals })
262
    .target('compiled/http-proxy')
G
Guy Bedford 已提交
263 264
}
// eslint-disable-next-line camelcase
G
Guy Bedford 已提交
265 266 267 268 269
externals['ignore-loader'] = 'next/dist/compiled/ignore-loader'
export async function ncc_ignore_loader(task, opts) {
  await task
    .source(opts.src || relative(__dirname, require.resolve('ignore-loader')))
    .ncc({ packageName: 'ignore-loader', externals })
270
    .target('compiled/ignore-loader')
G
Guy Bedford 已提交
271 272
}
// eslint-disable-next-line camelcase
273
externals['is-docker'] = 'next/dist/compiled/is-docker'
G
Guy Bedford 已提交
274 275 276
export async function ncc_is_docker(task, opts) {
  await task
    .source(opts.src || relative(__dirname, require.resolve('is-docker')))
G
Guy Bedford 已提交
277
    .ncc({ packageName: 'is-docker', externals })
278
    .target('compiled/is-docker')
G
Guy Bedford 已提交
279 280
}
// eslint-disable-next-line camelcase
281
externals['is-wsl'] = 'next/dist/compiled/is-wsl'
G
Guy Bedford 已提交
282 283 284
export async function ncc_is_wsl(task, opts) {
  await task
    .source(opts.src || relative(__dirname, require.resolve('is-wsl')))
G
Guy Bedford 已提交
285
    .ncc({ packageName: 'is-wsl', externals })
286
    .target('compiled/is-wsl')
G
Guy Bedford 已提交
287 288
}
// eslint-disable-next-line camelcase
289
externals['json5'] = 'next/dist/compiled/json5'
G
json5  
Guy Bedford 已提交
290 291 292
export async function ncc_json5(task, opts) {
  await task
    .source(opts.src || relative(__dirname, require.resolve('json5')))
G
Guy Bedford 已提交
293
    .ncc({ packageName: 'json5', externals })
294
    .target('compiled/json5')
G
json5  
Guy Bedford 已提交
295 296
}
// eslint-disable-next-line camelcase
297
externals['jsonwebtoken'] = 'next/dist/compiled/jsonwebtoken'
G
Guy Bedford 已提交
298 299 300
export async function ncc_jsonwebtoken(task, opts) {
  await task
    .source(opts.src || relative(__dirname, require.resolve('jsonwebtoken')))
G
Guy Bedford 已提交
301
    .ncc({ packageName: 'jsonwebtoken', externals })
302
    .target('compiled/jsonwebtoken')
G
Guy Bedford 已提交
303 304
}
// eslint-disable-next-line camelcase
305
externals['launch-editor'] = 'next/dist/compiled/launch-editor'
G
Guy Bedford 已提交
306 307 308
export async function ncc_launch_editor(task, opts) {
  await task
    .source(opts.src || relative(__dirname, require.resolve('launch-editor')))
G
Guy Bedford 已提交
309
    .ncc({ packageName: 'launch-editor', externals })
310
    .target('compiled/launch-editor')
G
Guy Bedford 已提交
311 312
}
// eslint-disable-next-line camelcase
313
externals['lodash.curry'] = 'next/dist/compiled/lodash.curry'
G
Guy Bedford 已提交
314 315 316
export async function ncc_lodash_curry(task, opts) {
  await task
    .source(opts.src || relative(__dirname, require.resolve('lodash.curry')))
G
Guy Bedford 已提交
317
    .ncc({ packageName: 'lodash.curry', externals })
318
    .target('compiled/lodash.curry')
G
Guy Bedford 已提交
319 320
}
// eslint-disable-next-line camelcase
321
externals['lru-cache'] = 'next/dist/compiled/lru-cache'
G
Guy Bedford 已提交
322 323 324
export async function ncc_lru_cache(task, opts) {
  await task
    .source(opts.src || relative(__dirname, require.resolve('lru-cache')))
G
Guy Bedford 已提交
325
    .ncc({ packageName: 'lru-cache', externals })
326
    .target('compiled/lru-cache')
G
Guy Bedford 已提交
327 328
}
// eslint-disable-next-line camelcase
329
externals['nanoid'] = 'next/dist/compiled/nanoid'
330 331 332
export async function ncc_nanoid(task, opts) {
  await task
    .source(opts.src || relative(__dirname, require.resolve('nanoid')))
G
Guy Bedford 已提交
333
    .ncc({ packageName: 'nanoid', externals })
334
    .target('compiled/nanoid')
335 336
}
// eslint-disable-next-line camelcase
337
externals['node-fetch'] = 'next/dist/compiled/node-fetch'
G
Guy Bedford 已提交
338 339 340
export async function ncc_node_fetch(task, opts) {
  await task
    .source(opts.src || relative(__dirname, require.resolve('node-fetch')))
G
Guy Bedford 已提交
341
    .ncc({ packageName: 'node-fetch', externals })
342
    .target('compiled/node-fetch')
G
Guy Bedford 已提交
343 344
}
// eslint-disable-next-line camelcase
345
externals['ora'] = 'next/dist/compiled/ora'
G
Guy Bedford 已提交
346 347 348
export async function ncc_ora(task, opts) {
  await task
    .source(opts.src || relative(__dirname, require.resolve('ora')))
G
Guy Bedford 已提交
349
    .ncc({ packageName: 'ora', externals })
350
    .target('compiled/ora')
G
Guy Bedford 已提交
351 352
}
// eslint-disable-next-line camelcase
G
Guy Bedford 已提交
353 354 355 356 357 358 359 360
externals['postcss-flexbugs-fixes'] =
  'next/dist/compiled/postcss-flexbugs-fixes'
export async function ncc_postcss_flexbugs_fixes(task, opts) {
  await task
    .source(
      opts.src || relative(__dirname, require.resolve('postcss-flexbugs-fixes'))
    )
    .ncc({ packageName: 'postcss-flexbugs-fixes', externals })
361
    .target('compiled/postcss-flexbugs-fixes')
G
Guy Bedford 已提交
362 363 364 365 366 367 368
}
// eslint-disable-next-line camelcase
externals['postcss-loader'] = 'next/dist/compiled/postcss-loader'
export async function ncc_postcss_loader(task, opts) {
  await task
    .source(opts.src || relative(__dirname, require.resolve('postcss-loader')))
    .ncc({ packageName: 'postcss-loader', externals })
369
    .target('compiled/postcss-loader')
G
Guy Bedford 已提交
370 371 372 373 374 375 376 377 378
}
// 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
    .source(
      opts.src || relative(__dirname, require.resolve('postcss-preset-env'))
    )
    .ncc({ packageName: 'postcss-preset-env', externals })
379
    .target('compiled/postcss-preset-env')
G
Guy Bedford 已提交
380 381
}
// eslint-disable-next-line camelcase
382
externals['raw-body'] = 'next/dist/compiled/raw-body'
G
Guy Bedford 已提交
383 384 385
export async function ncc_raw_body(task, opts) {
  await task
    .source(opts.src || relative(__dirname, require.resolve('raw-body')))
G
Guy Bedford 已提交
386
    .ncc({ packageName: 'raw-body', externals })
387
    .target('compiled/raw-body')
G
Guy Bedford 已提交
388 389
}
// eslint-disable-next-line camelcase
390
externals['recast'] = 'next/dist/compiled/recast'
G
Guy Bedford 已提交
391 392 393
export async function ncc_recast(task, opts) {
  await task
    .source(opts.src || relative(__dirname, require.resolve('recast')))
G
Guy Bedford 已提交
394
    .ncc({ packageName: 'recast', externals })
395
    .target('compiled/recast')
G
Guy Bedford 已提交
396 397
}
// eslint-disable-next-line camelcase
G
Guy Bedford 已提交
398 399
// NB: Used by other dependencies, but Zeit version is a duplicate
// version so can be inlined anyway (although may change in future)
400
externals['resolve'] = 'next/dist/compiled/resolve'
401 402 403
export async function ncc_resolve(task, opts) {
  await task
    .source(opts.src || relative(__dirname, require.resolve('resolve')))
G
Guy Bedford 已提交
404
    .ncc({ packageName: 'resolve', externals })
405
    .target('compiled/resolve')
406 407
}
// eslint-disable-next-line camelcase
408
externals['send'] = 'next/dist/compiled/send'
G
send  
Guy Bedford 已提交
409 410 411
export async function ncc_send(task, opts) {
  await task
    .source(opts.src || relative(__dirname, require.resolve('send')))
G
Guy Bedford 已提交
412
    .ncc({ packageName: 'send', externals })
413
    .target('compiled/send')
G
send  
Guy Bedford 已提交
414 415
}
// eslint-disable-next-line camelcase
G
Guy Bedford 已提交
416 417
// NB: Used by other dependencies, but Zeit version is a duplicate
// version so can be inlined anyway (although may change in future)
418
externals['source-map'] = 'next/dist/compiled/source-map'
G
Guy Bedford 已提交
419 420 421
export async function ncc_source_map(task, opts) {
  await task
    .source(opts.src || relative(__dirname, require.resolve('source-map')))
G
Guy Bedford 已提交
422
    .ncc({ packageName: 'source-map', externals })
423
    .target('compiled/source-map')
G
Guy Bedford 已提交
424 425
}
// eslint-disable-next-line camelcase
426
externals['string-hash'] = 'next/dist/compiled/string-hash'
G
Guy Bedford 已提交
427 428 429
export async function ncc_string_hash(task, opts) {
  await task
    .source(opts.src || relative(__dirname, require.resolve('string-hash')))
G
Guy Bedford 已提交
430
    .ncc({ packageName: 'string-hash', externals })
431
    .target('compiled/string-hash')
G
Guy Bedford 已提交
432 433
}
// eslint-disable-next-line camelcase
434
externals['strip-ansi'] = 'next/dist/compiled/strip-ansi'
G
Guy Bedford 已提交
435 436 437
export async function ncc_strip_ansi(task, opts) {
  await task
    .source(opts.src || relative(__dirname, require.resolve('strip-ansi')))
G
Guy Bedford 已提交
438
    .ncc({ packageName: 'strip-ansi', externals })
439
    .target('compiled/strip-ansi')
G
Guy Bedford 已提交
440 441
}
// eslint-disable-next-line camelcase
442
externals['terser'] = 'next/dist/compiled/terser'
G
terser  
Guy Bedford 已提交
443 444 445
export async function ncc_terser(task, opts) {
  await task
    .source(opts.src || relative(__dirname, require.resolve('terser')))
G
Guy Bedford 已提交
446
    .ncc({ packageName: 'terser', externals })
447
    .target('compiled/terser')
G
terser  
Guy Bedford 已提交
448 449
}
// eslint-disable-next-line camelcase
450
externals['text-table'] = 'next/dist/compiled/text-table'
451 452 453
export async function ncc_text_table(task, opts) {
  await task
    .source(opts.src || relative(__dirname, require.resolve('text-table')))
G
Guy Bedford 已提交
454
    .ncc({ packageName: 'text-table', externals })
455
    .target('compiled/text-table')
456 457
}
// eslint-disable-next-line camelcase
G
Guy Bedford 已提交
458 459 460 461 462
externals['thread-loader'] = 'next/dist/compiled/thread-loader'
export async function ncc_thread_loader(task, opts) {
  await task
    .source(opts.src || relative(__dirname, require.resolve('thread-loader')))
    .ncc({ packageName: 'thread-loader', externals })
463
    .target('compiled/thread-loader')
G
Guy Bedford 已提交
464 465
}
// eslint-disable-next-line camelcase
466
externals['unistore'] = 'next/dist/compiled/unistore'
467 468 469
export async function ncc_unistore(task, opts) {
  await task
    .source(opts.src || relative(__dirname, require.resolve('unistore')))
G
Guy Bedford 已提交
470
    .ncc({ packageName: 'unistore', externals })
471
    .target('compiled/unistore')
472
}
473 474 475 476 477 478 479 480 481
// eslint-disable-next-line camelcase
externals['webpack-dev-middleware'] =
  'next/dist/compiled/webpack-dev-middleware'
export async function ncc_webpack_dev_middleware(task, opts) {
  await task
    .source(
      opts.src || relative(__dirname, require.resolve('webpack-dev-middleware'))
    )
    .ncc({ packageName: 'webpack-dev-middleware', externals })
482
    .target('compiled/webpack-dev-middleware')
483 484 485 486 487 488 489 490 491 492
}
// eslint-disable-next-line camelcase
externals['webpack-hot-middleware'] =
  'next/dist/compiled/webpack-hot-middleware'
export async function ncc_webpack_hot_middleware(task, opts) {
  await task
    .source(
      opts.src || relative(__dirname, require.resolve('webpack-hot-middleware'))
    )
    .ncc({ packageName: 'webpack-hot-middleware', externals })
493
    .target('compiled/webpack-hot-middleware')
494 495
}
externals['path-to-regexp'] = 'next/dist/compiled/path-to-regexp'
G
Guy Bedford 已提交
496 497 498 499 500
export async function path_to_regexp(task, opts) {
  await task
    .source(opts.src || relative(__dirname, require.resolve('path-to-regexp')))
    .target('dist/compiled/path-to-regexp')
}
501
externals['react-error-overlay'] = 'next/dist/compiled/react-error-overlay'
G
Guy Bedford 已提交
502 503 504 505 506 507 508 509
export async function react_error_overlay(task, opts) {
  await task
    .source(
      opts.src || relative(__dirname, require.resolve('react-error-overlay'))
    )
    .target('dist/compiled/react-error-overlay')
}

510
export async function precompile(task) {
511
  await task.parallel([
G
Guy Bedford 已提交
512
    'browser_polyfills',
G
Guy Bedford 已提交
513
    'path_to_regexp',
G
Guy Bedford 已提交
514
    'react_error_overlay',
515
    'copy_ncced',
516
  ])
517 518
}

519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583
// 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
  await task.source('compiled/**/*').target('dist/compiled')
}

export async function ncc(task) {
  await task
    .clear('compiled')
    .parallel([
      'ncc_amphtml_validator',
      'ncc_arg',
      'ncc_async_retry',
      'ncc_async_sema',
      'ncc_autodll_webpack_plugin',
      'ncc_babel_loader',
      'ncc_cache_loader',
      'ncc_chalk',
      'ncc_ci_info',
      'ncc_compression',
      'ncc_conf',
      'ncc_content_type',
      'ncc_cookie',
      'ncc_cssnano_simple',
      'ncc_devalue',
      'ncc_dotenv',
      'ncc_dotenv_expand',
      'ncc_escape_string_regexp',
      'ncc_etag',
      'ncc_file_loader',
      'ncc_find_up',
      'ncc_fresh',
      'ncc_gzip_size',
      'ncc_http_proxy',
      'ncc_ignore_loader',
      'ncc_is_docker',
      'ncc_is_wsl',
      'ncc_json5',
      'ncc_jsonwebtoken',
      'ncc_launch_editor',
      'ncc_lodash_curry',
      'ncc_lru_cache',
      'ncc_nanoid',
      'ncc_node_fetch',
      'ncc_ora',
      'ncc_postcss_flexbugs_fixes',
      'ncc_postcss_loader',
      'ncc_postcss_preset_env',
      'ncc_raw_body',
      'ncc_recast',
      'ncc_resolve',
      'ncc_send',
      'ncc_source_map',
      'ncc_string_hash',
      'ncc_strip_ansi',
      'ncc_terser',
      'ncc_text_table',
      'ncc_thread_loader',
      'ncc_unistore',
      'ncc_webpack_dev_middleware',
      'ncc_webpack_hot_middleware',
    ])
}

584
export async function compile(task) {
585 586 587 588 589 590 591 592
  await task.parallel([
    'cli',
    'bin',
    'server',
    'nextbuild',
    'nextbuildstatic',
    'pages',
    'lib',
J
Joe Haddad 已提交
593
    'client',
594 595
    'telemetry',
    'nextserverserver',
596
    'nextserverlib',
597
  ])
T
Tim Neutkens 已提交
598 599
}

600
export async function bin(task, opts) {
601 602
  await task
    .source(opts.src || 'bin/*')
603
    .babel('server', { stripExtension: true })
604
    .target('dist/bin', { mode: '0755' })
T
Tim Neutkens 已提交
605 606 607
  notify('Compiled binaries')
}

608
export async function cli(task, opts) {
609 610
  await task
    .source(opts.src || 'cli/**/*.+(js|ts|tsx)')
611
    .babel('server')
612
    .target('dist/cli')
C
Connor Davis 已提交
613 614 615
  notify('Compiled cli files')
}

616
export async function lib(task, opts) {
617 618
  await task
    .source(opts.src || 'lib/**/*.+(js|ts|tsx)')
619
    .babel('server')
620
    .target('dist/lib')
T
Tim Neutkens 已提交
621 622 623
  notify('Compiled lib files')
}

624
export async function server(task, opts) {
625 626
  await task
    .source(opts.src || 'server/**/*.+(js|ts|tsx)')
627
    .babel('server')
628
    .target('dist/server')
T
Tim Neutkens 已提交
629 630 631
  notify('Compiled server files')
}

632
export async function nextbuild(task, opts) {
633 634
  await task
    .source(opts.src || 'build/**/*.+(js|ts|tsx)')
635
    .babel('server')
636
    .target('dist/build')
T
Tim Neutkens 已提交
637 638 639
  notify('Compiled build files')
}

640
export async function client(task, opts) {
641 642
  await task
    .source(opts.src || 'client/**/*.+(js|ts|tsx)')
643
    .babel('client')
644
    .target('dist/client')
T
Tim Neutkens 已提交
645 646 647 648
  notify('Compiled client files')
}

// export is a reserved keyword for functions
649
export async function nextbuildstatic(task, opts) {
650 651
  await task
    .source(opts.src || 'export/**/*.+(js|ts|tsx)')
652
    .babel('server')
653
    .target('dist/export')
T
Tim Neutkens 已提交
654 655 656
  notify('Compiled export files')
}

657 658 659
export async function pages_app(task) {
  await task
    .source('pages/_app.tsx')
660
    .babel('client')
661 662 663 664
    .target('dist/pages')
}

export async function pages_error(task) {
665
  await task
666
    .source('pages/_error.tsx')
667
    .babel('client')
668
    .target('dist/pages')
T
Tim Neutkens 已提交
669 670
}

671 672 673
export async function pages_document(task) {
  await task
    .source('pages/_document.tsx')
674
    .babel('server')
675 676 677 678 679 680 681
    .target('dist/pages')
}

export async function pages(task, opts) {
  await task.parallel(['pages_app', 'pages_error', 'pages_document'])
}

682
export async function telemetry(task, opts) {
J
Joe Haddad 已提交
683 684
  await task
    .source(opts.src || 'telemetry/**/*.+(js|ts|tsx)')
685
    .babel('server')
J
Joe Haddad 已提交
686 687 688 689
    .target('dist/telemetry')
  notify('Compiled telemetry files')
}

690
export async function build(task) {
691
  await task.serial(['precompile', 'compile'])
T
Tim Neutkens 已提交
692 693
}

694
export default async function(task) {
695
  await task.clear('dist')
T
Tim Neutkens 已提交
696 697
  await task.start('build')
  await task.watch('bin/*', 'bin')
698 699 700
  await task.watch('pages/**/*.+(js|ts|tsx)', 'pages')
  await task.watch('server/**/*.+(js|ts|tsx)', 'server')
  await task.watch('build/**/*.+(js|ts|tsx)', 'nextbuild')
701
  await task.watch('export/**/*.+(js|ts|tsx)', 'nextbuildstatic')
702 703
  await task.watch('client/**/*.+(js|ts|tsx)', 'client')
  await task.watch('lib/**/*.+(js|ts|tsx)', 'lib')
J
Joe Haddad 已提交
704
  await task.watch('cli/**/*.+(js|ts|tsx)', 'cli')
J
Joe Haddad 已提交
705
  await task.watch('telemetry/**/*.+(js|ts|tsx)', 'telemetry')
706 707 708 709
  await task.watch('next-server/server/**/*.+(js|ts|tsx)', 'nextserverserver')
  await task.watch('next-server/lib/**/*.+(js|ts|tsx)', 'nextserverlib')
}

710
export async function nextserverlib(task, opts) {
711 712 713 714 715 716 717
  await task
    .source(opts.src || 'next-server/lib/**/*.+(js|ts|tsx)')
    .typescript({ module: 'commonjs' })
    .target('dist/next-server/lib')
  notify('Compiled lib files')
}

718
export async function nextserverserver(task, opts) {
719 720 721 722 723 724 725
  await task
    .source(opts.src || 'next-server/server/**/*.+(js|ts|tsx)')
    .typescript({ module: 'commonjs' })
    .target('dist/next-server/server')
  notify('Compiled server files')
}

726
export async function nextserverbuild(task) {
727
  await task.parallel(['nextserverserver', 'nextserverlib'])
T
Tim Neutkens 已提交
728 729
}

730
export async function release(task) {
T
Tim Neutkens 已提交
731
  await task.clear('dist').start('build')
732
  await task.clear('dist/next-server').start('nextserverbuild')
T
Tim Neutkens 已提交
733 734 735
}

// notification helper
736
function notify(msg) {
T
Tim Neutkens 已提交
737 738 739
  return notifier.notify({
    title: '▲ Next',
    message: msg,
740
    icon: false,
T
Tim Neutkens 已提交
741 742
  })
}