File tree Expand file tree Collapse file tree 7 files changed +48
-21
lines changed Expand file tree Collapse file tree 7 files changed +48
-21
lines changed Original file line number Diff line number Diff line change @@ -38,7 +38,7 @@ export type CmdRunParams = {|
38
38
noReload : boolean ,
39
39
preInstall : boolean ,
40
40
sourceDir : string ,
41
- watchFile ?: string ,
41
+ watchFile ?: Array < string > ,
42
42
watchIgnored ?: Array < string > ,
43
43
startUrl ?: Array < string > ,
44
44
target ?: Array < string > ,
@@ -119,6 +119,11 @@ export default async function run(
119
119
noReload = true ;
120
120
}
121
121
122
+ if ( watchFile != null && ( ! Array . isArray ( watchFile ) ||
123
+ ! watchFile . every ( ( el ) => typeof el === 'string' ) ) ) {
124
+ throw new UsageError ( 'Unexpected watchFile type' ) ;
125
+ }
126
+
122
127
// Create an alias for --pref since it has been transformed into an
123
128
// object containing one or more preferences.
124
129
const customPrefs = pref ;
Original file line number Diff line number Diff line change @@ -239,7 +239,7 @@ export class MultiExtensionRunner {
239
239
export type WatcherCreatorParams = { |
240
240
reloadExtension : ( string ) = > void ,
241
241
sourceDir : string ,
242
- watchFile ? : string ,
242
+ watchFile ?: Array < string > ,
243
243
watchIgnored ?: Array < string > ,
244
244
artifactsDir : string ,
245
245
onSourceChange ? : OnSourceChangeFn ,
@@ -276,7 +276,7 @@ export function defaultWatcherCreator(
276
276
export type ReloadStrategyParams = { |
277
277
extensionRunner : IExtensionRunner ,
278
278
sourceDir : string ,
279
- watchFile ?: string ,
279
+ watchFile ?: Array < string > ,
280
280
watchIgnored ?: Array < string > ,
281
281
artifactsDir : string ,
282
282
ignoreFiles ?: Array < string > ,
Original file line number Diff line number Diff line change @@ -621,7 +621,7 @@ Example: $0 --help run.
621
621
' file changes. This is useful if you use a custom' +
622
622
' build process for your extension' ,
623
623
demandOption : false ,
624
- type : 'string ' ,
624
+ type : 'array ' ,
625
625
} ,
626
626
'watch-ignored' : {
627
627
describe : 'Paths and globs patterns that should not be ' +
Original file line number Diff line number Diff line change @@ -18,7 +18,7 @@ export type OnChangeFn = () => any;
18
18
19
19
export type OnSourceChangeParams = { |
20
20
sourceDir : string ,
21
- watchFile ?: string ,
21
+ watchFile ?: Array < string > ,
22
22
watchIgnored ?: Array < string > ,
23
23
artifactsDir : string ,
24
24
onChange : OnChangeFn ,
@@ -57,18 +57,22 @@ export default function onSourceChange(
57
57
proxyFileChanges ( { artifactsDir, onChange, filePath, shouldWatchFile} ) ;
58
58
} ) ;
59
59
60
- log . debug ( `Watching for file changes in ${ watchFile || sourceDir } ` ) ;
60
+ log . debug (
61
+ `Watching ${ watchFile ? watchFile . join ( ',' ) : sourceDir } for changes`
62
+ ) ;
61
63
62
64
const watchedDirs = [ ] ;
63
65
const watchedFiles = [ ] ;
64
66
65
67
if ( watchFile ) {
66
- if ( fs . existsSync ( watchFile ) && ! fs . lstatSync ( watchFile ) . isFile ( ) ) {
67
- throw new UsageError ( 'Invalid --watch-file value: ' +
68
- `"${ watchFile } " is not a file.` ) ;
69
- }
68
+ for ( const filePath of watchFile ) {
69
+ if ( fs . existsSync ( filePath ) && ! fs . lstatSync ( filePath ) . isFile ( ) ) {
70
+ throw new UsageError ( 'Invalid --watch-file value: ' +
71
+ `"${ filePath } " is not a file.` ) ;
72
+ }
70
73
71
- watchedFiles . push ( watchFile ) ;
74
+ watchedFiles . push ( filePath ) ;
75
+ }
72
76
} else {
73
77
watchedDirs . push ( sourceDir ) ;
74
78
}
Original file line number Diff line number Diff line change @@ -161,12 +161,22 @@ describe('run', () => {
161
161
} , { firefoxApp, firefoxClient} ) ;
162
162
} ) ;
163
163
164
+ it ( 'throws if watchFile is not an array' , async ( ) => {
165
+ const cmd = prepareRun ( ) ;
166
+ await assert . isRejected (
167
+ cmd . run ( { noReload : false , watchFile : 'invalid-value.txt' } ) ,
168
+ / U n e x p e c t e d w a t c h F i l e t y p e /
169
+ ) ;
170
+ } ) ;
171
+
164
172
it ( 'can watch and reload the extension' , async ( ) => {
165
173
const cmd = prepareRun ( ) ;
166
174
const { sourceDir, artifactsDir} = cmd . argv ;
167
175
const { reloadStrategy} = cmd . options ;
168
176
169
- const watchFile = fixturePath ( 'minimal-web-ext' , 'manifest.json' ) ;
177
+ const watchFile = [
178
+ fixturePath ( 'minimal-web-ext' , 'manifest.json' ) ,
179
+ ] ;
170
180
171
181
await cmd . run ( { noReload : false , watchFile } ) ;
172
182
assert . equal ( reloadStrategy . called , true ) ;
Original file line number Diff line number Diff line change @@ -543,22 +543,30 @@ describe('program.main', () => {
543
543
} ) ;
544
544
} ) ;
545
545
546
- it ( 'calls run with a watched file' , ( ) => {
547
- const watchFile = 'path/to/fake/file.txt' ;
548
-
546
+ async function testWatchFileOption ( watchFile ) {
549
547
const fakeCommands = fake ( commands , {
550
548
run : ( ) => Promise . resolve ( ) ,
551
549
} ) ;
552
550
553
551
return execProgram (
554
- [ 'run' , '--watch-file' , watchFile ] ,
552
+ [ 'run' , '--watch-file' , ... watchFile ] ,
555
553
{ commands : fakeCommands } )
556
554
. then ( ( ) => {
557
555
sinon . assert . calledWithMatch (
558
556
fakeCommands . run ,
559
557
{ watchFile}
560
558
) ;
561
559
} ) ;
560
+ }
561
+
562
+ it ( 'calls run with a watched file' , ( ) => {
563
+ testWatchFileOption ( [ 'path/to/fake/file.txt' ] ) ;
564
+ } ) ;
565
+
566
+ it ( 'calls run with multiple watched files' , ( ) => {
567
+ testWatchFileOption (
568
+ [ 'path/to/fake/file.txt' , 'path/to/fake/file2.txt' ]
569
+ ) ;
562
570
} ) ;
563
571
564
572
async function testWatchIgnoredOption ( watchIgnored ) {
Original file line number Diff line number Diff line change @@ -13,7 +13,7 @@ import {withTempDir} from '../../src/util/temp-dir';
13
13
import { makeSureItFails } from './helpers' ;
14
14
15
15
type AssertWatchedParams = {
16
- watchFile ?: string ,
16
+ watchFile ?: Array < string > ,
17
17
touchedFile : string ,
18
18
}
19
19
@@ -28,7 +28,7 @@ describe('watcher', () => {
28
28
const someFile = path . join ( tmpDir . path ( ) , touchedFile ) ;
29
29
30
30
if ( watchFile ) {
31
- watchFile = path . join ( tmpDir . path ( ) , watchFile ) ;
31
+ watchFile = watchFile . map ( ( f ) => path . join ( tmpDir . path ( ) , f ) ) ;
32
32
}
33
33
34
34
var resolveChange ;
@@ -116,7 +116,7 @@ describe('watcher', () => {
116
116
watchedDirPath,
117
117
tmpDirPath,
118
118
} = await watchChange ( {
119
- watchFile : 'foo.txt' ,
119
+ watchFile : [ 'foo.txt' ] ,
120
120
touchedFile : 'foo.txt' ,
121
121
} ) ;
122
122
@@ -132,7 +132,7 @@ describe('watcher', () => {
132
132
watchedDirPath,
133
133
tmpDirPath,
134
134
} = await watchChange ( {
135
- watchFile : 'bar.txt' ,
135
+ watchFile : [ 'bar.txt' ] ,
136
136
touchedFile : 'foo.txt' ,
137
137
} ) ;
138
138
@@ -143,7 +143,7 @@ describe('watcher', () => {
143
143
144
144
it ( 'throws error if a non-file is passed into --watch-file' , ( ) => {
145
145
return watchChange ( {
146
- watchFile : '/' ,
146
+ watchFile : [ '/' ] ,
147
147
touchedFile : 'foo.txt' ,
148
148
} ) . then ( makeSureItFails ( ) ) . catch ( ( error ) => {
149
149
assert . match (
You can’t perform that action at this time.
0 commit comments