Skip to content

Commit

Permalink
Fix: npm script(dev:package) is not working on Windows (#40566)
Browse files Browse the repository at this point in the history
  • Loading branch information
t-hamano authored Apr 25, 2022
1 parent b0ee254 commit 1bf9f6e
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions bin/packages/watch.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,9 @@ function isDirectory( pathname ) {
function isSourceFile( filename ) {
// Only run this regex on the relative path, otherwise we might run
// into some false positives when eg. the project directory contains `src`
const relativePath = path.relative( process.cwd(), filename );
const relativePath = path
.relative( process.cwd(), filename )
.replace( /\\/g, '/' );

return (
/\/src\/.+\.(js|json|scss|ts|tsx)$/.test( relativePath ) &&
Expand Down Expand Up @@ -98,6 +100,7 @@ function isWatchableFile( filename, skip ) {
// Recursive file watching is not available on a Linux-based OS. If this is the case,
// the watcher library falls back to watching changes in the subdirectories
// and passes the directories to this filter callback instead.

if ( isDirectory( filename ) ) {
return true;
}
Expand All @@ -117,8 +120,9 @@ function isWatchableFile( filename, skip ) {
function getBuildFile( srcFile ) {
// Could just use string.replace, but the user might have the project
// checked out and nested under another src folder.
const packageDir = srcFile.substr( 0, srcFile.lastIndexOf( '/src/' ) );
const filePath = srcFile.substr( srcFile.lastIndexOf( '/src/' ) + 5 );
const srcDir = `${ path.sep }src${ path.sep }`;
const packageDir = srcFile.substr( 0, srcFile.lastIndexOf( srcDir ) );
const filePath = srcFile.substr( srcFile.lastIndexOf( srcDir ) + 5 );
return path.resolve( packageDir, 'build', filePath );
}

Expand Down

0 comments on commit 1bf9f6e

Please sign in to comment.