Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
childProcess.spawn(
`npx bottender start ${isConsole ? '--console' : ''} --port ${port}`,
{
stdio: 'inherit',
}
);
let cp = createProcess();
const handleExit = (code: number | null) => {
process.exit(code || undefined);
};
cp.on('exit', handleExit);
const wp = new Watchpack({
aggregateTimeout: 1000,
poll: true,
ignored: ['**/.git', '**/node_modules'],
});
wp.watch([], ['.']);
wp.on('aggregated', (changes, removals) => {
console.log('App restarted due to: ', changes, removals);
cp.off('exit', handleExit);
cp.kill('SIGTERM');
cp = createProcess();
});
const useTypeScript = false; // FIXME
return new Promise(resolve => {
const pagesDir = this.pagesDir
// Watchpack doesn't emit an event for an empty directory
fs.readdir(pagesDir!, (_, files) => {
if (files && files.length) {
return
}
if (!resolved) {
resolve()
resolved = true
}
})
let wp = (this.webpackWatcher = new Watchpack())
wp.watch([], [pagesDir!], 0)
wp.on('aggregated', () => {
const dynamicRoutedPages = []
const knownFiles = wp.getTimeInfoEntries()
for (const [fileName, { accuracy }] of knownFiles) {
if (accuracy === undefined) {
continue
}
let pageName =
'/' + relative(pagesDir!, fileName).replace(/\\+/g, '/')
pageName = pageName.replace(
new RegExp(`\\.+(?:${this.nextConfig.pageExtensions.join('|')})$`),
''
export default function onSourceChange(
{sourceDir, artifactsDir, onChange, shouldWatchFile}: OnSourceChangeParams
): Watchpack {
// TODO: For network disks, we would need to add {poll: true}.
const watcher = new Watchpack();
const executeImmediately = true;
onChange = debounce(onChange, 1000, executeImmediately);
watcher.on('change', (filePath) => {
proxyFileChanges({artifactsDir, onChange, filePath, shouldWatchFile});
});
log.debug(`Watching for file changes in ${sourceDir}`);
watcher.watch([], [sourceDir], Date.now());
// TODO: support interrupting the watcher on Windows.
// https://github.com/mozilla/web-ext/issues/225
process.on('SIGINT', () => watcher.close());
return watcher;
}
const doneFn = () => {
if (this.watching && !this.watching.closed) {
const oldWatcher = this.watcher;
this.watcher = new Watchpack(
this.watching.watchFileSystem
? this.watching.watchFileSystem.watcherOptions
: {}
);
this.watcher.watch(
this.fileDependencies,
this.contextDependencies,
Date.now()
);
this.watcher.once("change", () => {
if (!this.needRegenerate) {
this.needRegenerate = true;
hookFn(() => {
this.needRegenerate = false;
});
}
export const watchDevelopmentPlugins = keepAliveOperation(({ getStore, dispatch, executeOperation }) => {
interface ErrorEntry {
package: string
reasons: string[]
}
const developmentPluginDirs = getDevelopPluginDirs(getStore)
const wp = new Watchpack({
aggregateTimeout: 1000,
})
wp.watch([], developmentPluginDirs, Date.now())
wp.on('aggregated', async (changes: string[]) => {
const updatedPackages: any[] = []
const failedPackages: ErrorEntry[] = []
for (const packageDir of changes) {
try {
const packageJsonPath = join(packageDir, 'package.json')
if (!(await (exists as any)(packageJsonPath))) return
const packageInfo = await FSPluginLoader.loadPackage(packageDir)
const valid = Delir.PluginRegistry.validateEffectPluginPackageJSON(packageInfo.packageJson)
}
fs.removeSync(distDir)
function onChange(filePath: string) {
if (!fs.existsSync(filePath)) {
fs.removeSync(
`${distDir}${filePath.replace(storeDir, '')}`
)
}
emitFiles(storeDir, distDir, config, constants)
}
if (config.build) {
emitFiles(storeDir, distDir, config, constants)
} else {
const wp = new Watchpack({})
wp.watch([], [storeDir])
wp.on('change', onChange)
}
}