Skip to content

Commit

Permalink
Do not send event to client when a file has no suffix. An attempt to …
Browse files Browse the repository at this point in the history
…solve #130
  • Loading branch information
tipiirai committed Jan 16, 2024
1 parent 8aa7ac4 commit 9948498
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 8 deletions.
19 changes: 12 additions & 7 deletions packages/nuekit/src/nuefs.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ export async function fswatch(dir, onfile, onremove) {
const file = parse(path)

// skip dotfiles and files that start with "_"
if (ignore(file.name) || ignore(file.dir)) return
if (!isLegit(file)) return

// skip double events
if (last.path == path && Date.now() - last.ts < 50) return
Expand All @@ -35,13 +35,11 @@ export async function fswatch(dir, onfile, onremove) {
// deploy everything on the directory
for (const path of paths) {
const file = parse(path)
if (!ignore(file.name) && !ignore(file.dir)) {
await onfile({ ...file, path })
}
if (isLegit(file)) await onfile({ ...file, path })
}

} else {
await onfile({ ...file, path, size: stat.size })
if (file.ext) await onfile({ ...file, path, size: stat.size })
}

last = { path, ts: Date.now() }
Expand All @@ -53,11 +51,14 @@ export async function fswatch(dir, onfile, onremove) {
})
}




export async function fswalk(root, _dir='', _ret=[]) {
const files = await fs.readdir(join(root, _dir), { withFileTypes: true })

for (const f of files) {
if (!ignore(f.name)) {
if (isLegit(f)) {
const path = join(_dir, f.name)
if (isDir(f)) await fswalk(root, path, _ret)
else _ret.push(path)
Expand All @@ -69,10 +70,14 @@ export async function fswalk(root, _dir='', _ret=[]) {

const IGNORE = ['node_modules', 'package.json', 'bun.lockb', 'pnpm-lock.yaml']

function ignore(name) {
function ignore(name='') {
return '._'.includes(name[0]) || IGNORE.includes(name)
}

function isLegit(file) {
return !ignore(file.name) && !ignore(file.dir)
}

// TODO: real symdir detection
function isDir(f) {
return f.isDirectory() || f.isSymbolicLink() && !f.name.includes('.')
Expand Down
4 changes: 3 additions & 1 deletion packages/nuekit/src/nuekit.js
Original file line number Diff line number Diff line change
Expand Up @@ -337,8 +337,10 @@ export async function createKit(args) {
}, async path => {
const dpath = join(dist, path)
await fs.rm(dpath, { recursive: true, force: true })
send({ remove: true, path, ...parsePath(path) })
log('Removed', dpath)

const file = parsePath(path)
if (file.ext) send({ remove: true, path, ...file })
})

try {
Expand Down

0 comments on commit 9948498

Please sign in to comment.