From 773e2b0efe6d86903490c080ece55e7fa9f1a6cc Mon Sep 17 00:00:00 2001 From: Prime Board Dev Date: Wed, 21 Jun 2023 10:13:13 +0100 Subject: [PATCH 1/2] Add .relative-deps-ignore file option, to prevent double rebuild in TS/built projects --- README.md | 7 +++++++ index.js | 16 ++++++++++++---- 2 files changed, 19 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 2ade0ad..f3b49d9 100644 --- a/README.md +++ b/README.md @@ -151,6 +151,13 @@ You can run `relative-deps watch` and it'll run `relative-deps` command when one This can go along with config of your project to watch over the relevant packages and it will automate the process completely, allowing you to change a library code and to enjoy the befefit of hot-reload. +### 🔔 If you get multiple re-builds (due to your project being compiled, and then "new changes" found again): for the relative-dep, in it's folder, add a `.relative-deps-ignore` file with `!dist` or similar entries +``` +!dist +!.output +!.built +``` + # How Roughly, it works like this (obviously this can get out of date quickly): diff --git a/index.js b/index.js index 0f4f7a9..645215f 100755 --- a/index.js +++ b/index.js @@ -81,8 +81,16 @@ async function watchRelativeDeps() { async function libraryHasChanged(name, libDir, targetDir, hashStore) { const hashFile = path.join(targetDir, "node_modules", name, ".relative-deps-hash") const referenceContents = fs.existsSync(hashFile) ? fs.readFileSync(hashFile, "utf8") : "" - // compute the hahses - const libFiles = await findFiles(libDir, targetDir) + // glob pattern list, relative to libDir, made for adding "dist" and similar + relativeDepsIgnoreFile = path.join(libDir, ".relative-deps-ignore") + const additionalIgnoredList = fs.existsSync(relativeDepsIgnoreFile) + ? fs.readFileSync(relativeDepsIgnoreFile, "utf8") + .split("\n") + .filter(line => line.trim() && !line.trim().startsWith('#')) + .map(line => line.split('#')[0]) + : undefined + // compute the hashes + const libFiles = await findFiles(libDir, targetDir, additionalIgnoredList) const hashes = [] for (file of libFiles) hashes.push(await getFileHash(path.join(libDir, file))) const contents = libFiles.map((file, index) => hashes[index] + " " + file).join("\n") @@ -106,8 +114,8 @@ async function libraryHasChanged(name, libDir, targetDir, hashStore) { return true } -async function findFiles(libDir, targetDir) { - const ignore = ["**/*", "!node_modules", "!.git"] +async function findFiles(libDir, targetDir, additionalIgnoredList = []) { + const ignore = ["**/*", "!node_modules", "!.git", ...additionalIgnoredList] // TODO: use resolved paths here if (targetDir.indexOf(libDir) === 0) { // The target dir is in the lib directory, make sure that path is excluded From c4ef238fddd84ce7631002563dd66248501915a2 Mon Sep 17 00:00:00 2001 From: Vladyslav Piskunov Date: Tue, 27 Jun 2023 12:47:48 +0100 Subject: [PATCH 2/2] Review fixes Co-authored-by: Nick Ribal --- index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/index.js b/index.js index 645215f..4e4b075 100755 --- a/index.js +++ b/index.js @@ -82,7 +82,7 @@ async function libraryHasChanged(name, libDir, targetDir, hashStore) { const hashFile = path.join(targetDir, "node_modules", name, ".relative-deps-hash") const referenceContents = fs.existsSync(hashFile) ? fs.readFileSync(hashFile, "utf8") : "" // glob pattern list, relative to libDir, made for adding "dist" and similar - relativeDepsIgnoreFile = path.join(libDir, ".relative-deps-ignore") + const relativeDepsIgnoreFile = path.join(libDir, ".relative-deps-ignore") const additionalIgnoredList = fs.existsSync(relativeDepsIgnoreFile) ? fs.readFileSync(relativeDepsIgnoreFile, "utf8") .split("\n")