11'use strict' ;
22const {
3+ ArrayPrototypeConcat,
34 ArrayPrototypeFlatMap,
45 ArrayPrototypeForEach,
56 ArrayPrototypeJoin,
@@ -28,29 +29,43 @@ const { inspect } = require('util');
2829const { setTimeout, clearTimeout } = require ( 'timers' ) ;
2930const { resolve } = require ( 'path' ) ;
3031const { once } = require ( 'events' ) ;
31- const { createMatcher } = require ( 'internal/fs/glob' ) ;
3232const { globSync } = require ( 'fs' ) ;
3333
3434prepareMainThreadExecution ( false , false ) ;
3535markBootstrapComplete ( ) ;
3636
37- function hasGlobPattern ( path ) {
38- return createMatcher ( path ) . hasMagic ( ) ;
37+ const kWatchPath = getOptionValue ( '--watch-path' ) ;
38+ const kWatchPattern = getOptionValue ( '--watch-pattern' ) ;
39+
40+ function isOptionNotGiven ( option ) {
41+ return option . length === 0 ;
42+ }
43+
44+ function isOptionGiven ( option ) {
45+ return option . length > 0 ;
3946}
4047
41- function handleWatchedPath ( path ) {
42- if ( hasGlobPattern ( path ) ) {
43- const matchedFilesFromGlob = globSync ( path ) ;
44- const resolvedMatchedFiles = ArrayPrototypeMap ( matchedFilesFromGlob , ( path ) => resolve ( path ) ) ;
45- return resolvedMatchedFiles ;
48+ function handleWatchedPaths ( ) {
49+ const watchedPaths = [ ] ;
50+ if ( isOptionGiven ( kWatchPath ) ) {
51+ ArrayPrototypeForEach ( kWatchPath , ( path ) => {
52+ ArrayPrototypePush ( watchedPaths , resolve ( path ) ) ;
53+ } ) ;
54+ }
55+ if ( isOptionGiven ( kWatchPattern ) ) {
56+ ArrayPrototypeForEach ( kWatchPattern , ( path ) => {
57+ const matchedPaths = globSync ( path ) ;
58+ ArrayPrototypeForEach ( matchedPaths , ( matchedPathFromGlobPattern ) =>
59+ ArrayPrototypePush ( watchedPaths , resolve ( matchedPathFromGlobPattern ) ) ) ;
60+ } ) ;
4661 }
47- return resolve ( path ) ;
62+ return watchedPaths ;
4863}
4964
5065const kKillSignal = convertToValidSignal ( getOptionValue ( '--watch-kill-signal' ) ) ;
51- const kShouldFilterModules = getOptionValue ( '--watch-pattern' ) . length === 0 ;
66+ const kShouldFilterModules = isOptionNotGiven ( kWatchPath ) && isOptionNotGiven ( kWatchPattern ) ;
5267const kEnvFile = getOptionValue ( '--env-file' ) || getOptionValue ( '--env-file-if-exists' ) ;
53- const kWatchedPaths = ArrayPrototypeFlatMap ( getOptionValue ( '--watch-path' ) , ( path ) => handleWatchedPath ( path ) ) ;
68+ const kWatchedPaths = handleWatchedPaths ( ) ;
5469const kPreserveOutput = getOptionValue ( '--watch-preserve-output' ) ;
5570const kCommand = ArrayPrototypeSlice ( process . argv , 1 ) ;
5671const kCommandStr = inspect ( ArrayPrototypeJoin ( kCommand , ' ' ) ) ;
@@ -72,6 +87,12 @@ for (let i = 0; i < process.execArgv.length; i++) {
7287 }
7388 continue ;
7489 }
90+ if ( StringPrototypeStartsWith ( arg , '--watch-pattern' ) ) {
91+ if ( arg [ '--watch-pattern' . length ] !== '=' ) {
92+ i ++ ;
93+ }
94+ continue ;
95+ }
7596 if ( StringPrototypeStartsWith ( arg , '--watch-path' ) ) {
7697 const lengthOfWatchPathStr = 12 ;
7798 if ( arg [ lengthOfWatchPathStr ] !== '=' ) {
0 commit comments