diff --git a/package-lock.json b/package-lock.json index 04a975a0..6d03f81f 100644 --- a/package-lock.json +++ b/package-lock.json @@ -50,7 +50,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", @@ -6048,18 +6047,6 @@ "integrity": "sha512-bLGGlR1QxBcynn2d5YmDX4MGjlZvy2MRBDRNHLJ8VI6l6+9FUiyTFNJ0IveOSP0bcXgVDPRcfGqA0pjaqUpfVg==", "dev": true }, - "node_modules/slash": { - "version": "4.0.0", - "resolved": "https://registry.npmjs.org/slash/-/slash-4.0.0.tgz", - "integrity": "sha512-3dOsAHXXUkQTpOYcoAxLIorMTp4gIQr5IW3iVb7A7lFIp0VHhnynm9izx6TssdrIcVIESAlVjtnO2K8bg+Coew==", - "dev": true, - "engines": { - "node": ">=12" - }, - "funding": { - "url": "https://github.com/sponsors/sindresorhus" - } - }, "node_modules/snapdragon": { "version": "0.8.2", "resolved": "https://registry.npmjs.org/snapdragon/-/snapdragon-0.8.2.tgz", @@ -12032,12 +12019,6 @@ "integrity": "sha512-bLGGlR1QxBcynn2d5YmDX4MGjlZvy2MRBDRNHLJ8VI6l6+9FUiyTFNJ0IveOSP0bcXgVDPRcfGqA0pjaqUpfVg==", "dev": true }, - "slash": { - "version": "4.0.0", - "resolved": "https://registry.npmjs.org/slash/-/slash-4.0.0.tgz", - "integrity": "sha512-3dOsAHXXUkQTpOYcoAxLIorMTp4gIQr5IW3iVb7A7lFIp0VHhnynm9izx6TssdrIcVIESAlVjtnO2K8bg+Coew==", - "dev": true - }, "snapdragon": { "version": "0.8.2", "resolved": "https://registry.npmjs.org/snapdragon/-/snapdragon-0.8.2.tgz", diff --git a/package.json b/package.json index cd28c7cc..e2c19ce8 100644 --- a/package.json +++ b/package.json @@ -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", diff --git a/src/cli-main.ts b/src/cli-main.ts index 73f9380a..ea0c8d41 100644 --- a/src/cli-main.ts +++ b/src/cli-main.ts @@ -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(',') diff --git a/src/index.ts b/src/index.ts index 7733a944..25ee00a4 100644 --- a/src/index.ts +++ b/src/index.ts @@ -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' @@ -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}`) diff --git a/src/utils.ts b/src/utils.ts index 703bc0fc..46b7bfa1 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -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 @@ -108,3 +103,15 @@ export function debouncePromise( } } } + +// 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, '/') +}