Skip to content

Commit

Permalink
Replace taskr.watch for core compilation (#44027)
Browse files Browse the repository at this point in the history
Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com>
  • Loading branch information
timneutkens and kodiakhq[bot] committed Dec 14, 2022
1 parent 2416357 commit 16a1116
Show file tree
Hide file tree
Showing 4 changed files with 79 additions and 309 deletions.
4 changes: 2 additions & 2 deletions packages/next/package.json
Expand Up @@ -71,7 +71,8 @@
"taskr": {
"requires": [
"./taskfile-ncc.js",
"./taskfile-swc.js"
"./taskfile-swc.js",
"./taskfile-watch.js"
]
},
"dependencies": {
Expand Down Expand Up @@ -133,7 +134,6 @@
"@segment/ajv-human-errors": "2.1.2",
"@taskr/clear": "1.1.0",
"@taskr/esnext": "1.1.0",
"@taskr/watch": "1.1.0",
"@types/amphtml-validator": "1.0.0",
"@types/babel__code-frame": "7.0.2",
"@types/babel__core": "7.1.12",
Expand Down
62 changes: 62 additions & 0 deletions packages/next/taskfile-watch.js
@@ -0,0 +1,62 @@
/*
Modified version of taskr.watch that uses watchpack instead of chokidar
https://github.com/lukeed/taskr/blob/7a50e6e8c1fb8c01c0020d9f0e4d8897ccc4cc28/license
The MIT License (MIT)
Copyright (c) 2015 Jorge Bucaran (https://github.com/JorgeBucaran)
Copyright (c) 2016 Luke Edwards (https://github.com/lukeed)
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
*/
const path = require('path')
// eslint-disable-next-line import/no-extraneous-dependencies
const Watchpack = require('watchpack')
const toArr = (val) => (Array.isArray(val) ? val : val == null ? [] : [val])

module.exports = function (Taskr, _utils) {
Taskr.plugin(
'watch',
{ every: false, files: false },
// eslint-disable-next-line require-yield
function* (_, directory, names, opts) {
const wp = new Watchpack({
aggregateTimeout: 5,
followSymlinks: true,
ignored: '**/.git',
})

names = toArr(names)
opts = opts || {}

const dirToWatch = path.join(__dirname, directory)
wp.watch({
directories: [dirToWatch],
startTime: Date.now() - 10000,
})

wp.on('aggregated', function (_changes, _removals) {
// No matter if there's a removal or change the task has to run
return Taskr.serial(names, opts)
})

return
}
)
}
45 changes: 15 additions & 30 deletions packages/next/taskfile.js
Expand Up @@ -2302,44 +2302,29 @@ export default async function (task) {
const opts = { dev: true }
await task.clear('dist')
await task.start('build', opts)
await task.watch('bin/*', 'bin', opts)
await task.watch('pages/**/*.+(js|ts|tsx)', 'pages', opts)
await task.watch('server/**/*.+(js|ts|tsx)', 'server', opts)
await task.watch('server/**/*.+(js|ts|tsx)', 'server_esm', opts)
await task.watch('build/**/*.+(js|ts|tsx)', 'nextbuild', opts)
await task.watch('build/**/*.+(js|ts|tsx)', 'nextbuild_esm', opts)
await task.watch('build/jest/**/*.+(js|ts|tsx)', 'nextbuildjest', opts)
await task.watch('export/**/*.+(js|ts|tsx)', 'nextbuildstatic', opts)
await task.watch('client/**/*.+(js|ts|tsx)', 'client', opts)
await task.watch('client/**/*.+(js|ts|tsx)', 'client_esm', opts)
await task.watch('lib/**/*.+(js|ts|tsx)', 'lib', opts)
await task.watch('lib/**/*.+(js|ts|tsx)', 'lib_esm', opts)
await task.watch('cli/**/*.+(js|ts|tsx)', 'cli', opts)
await task.watch('telemetry/**/*.+(js|ts|tsx)', 'telemetry', opts)
await task.watch('trace/**/*.+(js|ts|tsx)', 'trace', opts)
await task.watch('bin', 'bin', opts)
await task.watch('pages', 'pages', opts)
await task.watch('server', ['server', 'server_esm', 'server_wasm'], opts)
await task.watch(
'shared/lib/{amp,config,constants,dynamic,head,runtime-config}.+(js|ts|tsx)',
'shared_re_exported',
'build',
['nextbuild', 'nextbuild_esm', 'nextbuildjest'],
opts
)
await task.watch('export', 'nextbuildstatic', opts)
await task.watch('client', 'client', opts)
await task.watch('client', 'client_esm', opts)
await task.watch('lib', 'lib', opts)
await task.watch('lib', 'lib_esm', opts)
await task.watch('cli', 'cli', opts)
await task.watch('telemetry', 'telemetry', opts)
await task.watch('trace', 'trace', opts)
await task.watch(
'shared/**/!(amp|config|constants|dynamic|head|runtime-config).+(js|ts|tsx)',
'shared',
['shared_re_exported', 'shared_re_exported_esm', 'shared', 'shared_esm'],
opts
)
await task.watch(
'shared/**/!(amp|config|constants|dynamic|head).+(js|ts|tsx)',
'shared_esm',
opts
)
await task.watch(
'shared/lib/{amp,config,constants,dynamic,head}.+(js|ts|tsx)',
'shared_re_exported_esm',
opts
)
await task.watch('server/**/*.+(wasm)', 'server_wasm', opts)
await task.watch(
'../react-dev-overlay/dist/**/*.js',
'../react-dev-overlay/dist',
'ncc_next__react_dev_overlay',
opts
)
Expand Down

0 comments on commit 16a1116

Please sign in to comment.