improve build watcher to also detect newly created files (#3791)

This commit is contained in:
sadan4 2025-11-21 07:07:42 -05:00 committed by GitHub
parent ed1060b400
commit f87a513150
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 13 additions and 4 deletions

View file

@ -20,7 +20,7 @@
// @ts-check
import { readdir } from "fs/promises";
import { join } from "path";
import { join, resolve } from "path";
import { BUILD_TIMESTAMP, commonOpts, exists, globPlugins, IS_DEV, IS_REPORTER, IS_ANTI_CRASH_TEST, IS_STANDALONE, IS_UPDATER_DISABLED, resolvePluginName, VERSION, commonRendererPlugins, watch, buildOrWatchAll, stringifyValues } from "./common.mjs";
@ -78,6 +78,10 @@ const globNativesPlugin = {
let code = "";
let natives = "\n";
let i = 0;
/**
* @type {string[]}
*/
const watchFiles = [];
for (const dir of pluginDirs) {
const dirPath = join("src", dir);
if (!await exists(dirPath)) continue;
@ -87,6 +91,8 @@ const globNativesPlugin = {
const nativePath = join(dirPath, fileName, "native.ts");
const indexNativePath = join(dirPath, fileName, "native/index.ts");
watchFiles.push(resolve(nativePath), resolve(indexNativePath));
if (!(await exists(nativePath)) && !(await exists(indexNativePath)))
continue;
@ -101,7 +107,9 @@ const globNativesPlugin = {
code += `export default {${natives}};`;
return {
contents: code,
resolveDir: "./src"
resolveDir: "./src",
watchDirs: pluginDirs.map(d => resolve("src", d)),
watchFiles,
};
});
}

View file

@ -26,7 +26,7 @@ import esbuild, { build, context } from "esbuild";
import { constants as FsConstants, readFileSync } from "fs";
import { access, readdir, readFile } from "fs/promises";
import { minify as minifyHtml } from "html-minifier-terser";
import { join, relative } from "path";
import { join, relative, resolve } from "path";
import { promisify } from "util";
import { getPluginTarget } from "../utils.mjs";
@ -190,7 +190,8 @@ export const globPlugins = kind => ({
code += `export default {${pluginsCode}};export const PluginMeta={${metaCode}};export const ExcludedPlugins={${excludedCode}};`;
return {
contents: code,
resolveDir: "./src"
resolveDir: "./src",
watchDirs: pluginDirs.map(d => resolve("src", d)),
};
});
}