Skip to content

Commit

Permalink
chore: use relative instead of absolute paths for file watcher
Browse files Browse the repository at this point in the history
  • Loading branch information
ghiscoding committed Nov 16, 2024
1 parent a010e54 commit 6d8261c
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
7 changes: 5 additions & 2 deletions scripts/dev-watch.mjs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { subscribe } from '@parcel/watcher';
import browserSync from 'browser-sync';
import { relative } from 'node:path';
import yargs from 'yargs';
import { hideBin } from 'yargs/helpers';

Expand Down Expand Up @@ -36,7 +37,8 @@ const argv = yargs(hideBin(process.argv)).argv;
if (err) return onError(err);

for (const event of events) {
onFileChanged(event.path);
const absoluteFilePath = relative(process.cwd(), event.path);
onFileChanged(absoluteFilePath);
}
}, {
ignore: [
Expand Down Expand Up @@ -120,6 +122,8 @@ const argv = yargs(hideBin(process.argv)).argv;
return new Promise(async (resolve) => {
if (!processing) {
processing = true;
changedFiles.delete(filepath);

if (filepath.endsWith('.js') || filepath.endsWith('.ts')) {
// 1. ESM requires is always a full build since it is bundled into a single "index.js" file
await executeCjsEsmBuilds();
Expand All @@ -140,7 +144,6 @@ const argv = yargs(hideBin(process.argv)).argv;

// in every case, we want to reload the webpage
bsync.reload('*.html');
changedFiles.delete(filepath);
processing = false;
if (initialBuild) {
initialBuild = false;
Expand Down
2 changes: 1 addition & 1 deletion scripts/fs-utils.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { dirname } from 'node:path';
export function outputFileSync(file, ...args) {
const dir = dirname(file);
if (!existsSync(dir)) {
mkdirSync(outDir, { recursive: true });
mkdirSync(dir, { recursive: true });
}

writeFileSync(file, ...args);
Expand Down

0 comments on commit 6d8261c

Please sign in to comment.