Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
fix(windows): normalize path in watcher (#466)
Co-authored-by: EGOIST <0x142857@gmail.com>
  • Loading branch information
qianphong and egoist committed Nov 24, 2021
1 parent 6072da3 commit 9d4d3d7
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 27 deletions.
19 changes: 0 additions & 19 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion package.json
Expand Up @@ -62,7 +62,6 @@
"resolve": "^1.20.0",
"rollup-plugin-dts": "^3.0.2",
"rollup-plugin-hashbang": "^2.2.2",
"slash": "^4.0.0",
"string-argv": "^0.3.1",
"strip-json-comments": "^3.1.1",
"svelte": "3.37.0",
Expand Down
2 changes: 1 addition & 1 deletion src/cli-main.ts
Expand Up @@ -2,8 +2,8 @@ import { readFileSync } from 'fs'
import { join } from 'path'
import { cac } from 'cac'
import flat from 'flat'
import slash from 'slash'
import { Format, Options } from '.'
import { slash } from './utils'

function ensureArray(input: string): string[] {
return Array.isArray(input) ? input : input.split(',')
Expand Down
3 changes: 2 additions & 1 deletion src/index.ts
Expand Up @@ -2,7 +2,7 @@ import path from 'path'
import fs from 'fs'
import { Worker } from 'worker_threads'
import type { MarkRequired } from 'ts-essentials'
import { removeFiles, debouncePromise } from './utils'
import { removeFiles, debouncePromise, slash } from './utils'
import { loadTsupConfig, resolveTsConfig } from './load'
import glob from 'globby'
import { handleError, PrettyError } from './errors'
Expand Down Expand Up @@ -242,6 +242,7 @@ export async function build(_options: Options) {
ignored,
})
watcher.on('all', async (type, file) => {
file = slash(file)
if (!buildDependencies.has(file)) return

logger.info('CLI', `Change detected: ${type} ${file}`)
Expand Down
17 changes: 12 additions & 5 deletions src/utils.ts
Expand Up @@ -2,11 +2,6 @@ import fs from 'fs'
import glob from 'globby'
import resolveFrom from 'resolve-from'

// No backslash in path
function slash(input: string) {
return input.replace(/\\/g, '/')
}

export type External =
| string
| RegExp
Expand Down Expand Up @@ -108,3 +103,15 @@ export function debouncePromise<T extends unknown[]>(
}
}
}

// Taken from https://github.com/sindresorhus/slash/blob/main/index.js (MIT)
export function slash(path: string) {
const isExtendedLengthPath = /^\\\\\?\\/.test(path)
const hasNonAscii = /[^\u0000-\u0080]+/.test(path)

if (isExtendedLengthPath || hasNonAscii) {
return path
}

return path.replace(/\\/g, '/')
}

1 comment on commit 9d4d3d7

@vercel
Copy link

@vercel vercel bot commented on 9d4d3d7 Nov 24, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.