@@ -30,7 +30,14 @@ const MAX_COPY_RETRIES = 3
30
30
async function watch (
31
31
root ,
32
32
packages ,
33
- { scanOnce, quiet, forceInstall, monoRepoPackages, localPackages }
33
+ {
34
+ scanOnce,
35
+ quiet,
36
+ forceInstall,
37
+ monoRepoPackages,
38
+ localPackages,
39
+ packageNameToPath,
40
+ }
34
41
) {
35
42
setDefaultSpawnStdio ( quiet ? `ignore` : `inherit` )
36
43
// determine if in yarn workspace - if in workspace, force using verdaccio
@@ -123,6 +130,7 @@ async function watch(
123
130
root,
124
131
packages : _ . uniq ( localPackages ) ,
125
132
monoRepoPackages,
133
+ packageNameToPath,
126
134
} )
127
135
128
136
const allPackagesToWatch = packages
@@ -143,7 +151,7 @@ async function watch(
143
151
if ( allPackagesToWatch . length > 0 ) {
144
152
await publishPackagesLocallyAndInstall ( {
145
153
packagesToPublish : allPackagesToWatch ,
146
- root ,
154
+ packageNameToPath ,
147
155
localPackages,
148
156
ignorePackageJSONChanges,
149
157
yarnWorkspaceRoot,
@@ -186,7 +194,7 @@ async function watch(
186
194
)
187
195
const watchers = _ . uniq (
188
196
allPackagesToWatch
189
- . map ( p => path . join ( root , `/packages/` , p ) )
197
+ . map ( p => path . join ( packageNameToPath . get ( p ) ) )
190
198
. filter ( p => fs . existsSync ( p ) )
191
199
)
192
200
@@ -199,7 +207,7 @@ async function watch(
199
207
let anyPackageNotInstalled = false
200
208
201
209
const watchEvents = [ `change` , `add` ]
202
-
210
+ const packagePathMatchingEntries = Array . from ( packageNameToPath . entries ( ) )
203
211
chokidar
204
212
. watch ( watchers , {
205
213
ignored : [ filePath => _ . some ( ignored , reg => reg . test ( filePath ) ) ] ,
@@ -209,11 +217,22 @@ async function watch(
209
217
return
210
218
}
211
219
212
- const [ packageName ] = filePath
213
- . split ( / p a c k a g e s [ / \\ ] / )
214
- . pop ( )
215
- . split ( / [ / \\ ] / )
216
- const prefix = path . join ( root , `/packages/` , packageName )
220
+ // match against paths
221
+ let packageName
222
+
223
+ for ( const [ _packageName , packagePath ] of packagePathMatchingEntries ) {
224
+ const relativeToThisPackage = path . relative ( packagePath , filePath )
225
+ if ( ! relativeToThisPackage . startsWith ( `..` ) ) {
226
+ packageName = _packageName
227
+ break
228
+ }
229
+ }
230
+
231
+ if ( ! packageName ) {
232
+ return
233
+ }
234
+
235
+ const prefix = packageNameToPath . get ( packageName )
217
236
218
237
// Copy it over local version.
219
238
// Don't copy over the Gatsby bin file as that breaks the NPM symlink.
@@ -241,7 +260,7 @@ async function watch(
241
260
newPath,
242
261
packageName,
243
262
monoRepoPackages,
244
- root ,
263
+ packageNameToPath ,
245
264
isInitialScan,
246
265
ignoredPackageJSON,
247
266
} )
@@ -317,7 +336,7 @@ async function watch(
317
336
isPublishing = true
318
337
await publishPackagesLocallyAndInstall ( {
319
338
packagesToPublish : Array . from ( packagesToPublish ) ,
320
- root ,
339
+ packageNameToPath ,
321
340
localPackages,
322
341
ignorePackageJSONChanges,
323
342
} )
0 commit comments