diff --git a/packages/core/integration-tests/test/integration/glob-package/node_modules/@scope/pkg/index.js b/packages/core/integration-tests/test/integration/glob-package/node_modules/@scope/pkg/deep/entry/point.js similarity index 100% rename from packages/core/integration-tests/test/integration/glob-package/node_modules/@scope/pkg/index.js rename to packages/core/integration-tests/test/integration/glob-package/node_modules/@scope/pkg/deep/entry/point.js diff --git a/packages/core/integration-tests/test/integration/glob-package/node_modules/@scope/pkg/package.json b/packages/core/integration-tests/test/integration/glob-package/node_modules/@scope/pkg/package.json index 09fcae8572f..b4c3eb71084 100644 --- a/packages/core/integration-tests/test/integration/glob-package/node_modules/@scope/pkg/package.json +++ b/packages/core/integration-tests/test/integration/glob-package/node_modules/@scope/pkg/package.json @@ -1,4 +1,4 @@ { "name": "@scope/pkg", - "module": "index.js" + "module": "deep/entry/point.js" } \ No newline at end of file diff --git a/packages/resolvers/glob/src/GlobResolver.js b/packages/resolvers/glob/src/GlobResolver.js index cc37739a48e..2539a9becc6 100644 --- a/packages/resolvers/glob/src/GlobResolver.js +++ b/packages/resolvers/glob/src/GlobResolver.js @@ -58,6 +58,9 @@ export default (new Resolver({ throw errorToThrowableDiagnostic(error, dependency); } + let invalidateOnFileCreate = []; + let invalidateOnFileChange = new Set(); + // if the specifier does not start with /, ~, or . then it's not a path but package-ish - we resolve // the package first, and then append the rest of the path if (!/^[/~.]/.test(specifier)) { @@ -91,25 +94,43 @@ export default (new Resolver({ logger, }); - const result = await resolver.resolve({ - filename: pkg, + let ctx = { + invalidateOnFileCreate, + invalidateOnFileChange, specifierType: dependency.specifierType, - parent: dependency.resolveFrom, - env: dependency.env, - sourcePath: dependency.sourcePath, loc: dependency.loc, - }); + }; - if (!result || !result.filePath) { + let result; + try { + result = await resolver.resolveModule({ + filename: pkg, + parent: dependency.resolveFrom, + env: dependency.env, + sourcePath: dependency.sourcePath, + ctx, + }); + } catch (err) { + if (err instanceof ThrowableDiagnostic) { + // Return instead of throwing so we can provide invalidations. + return { + diagnostics: err.diagnostics, + invalidateOnFileCreate, + invalidateOnFileChange: [...invalidateOnFileChange], + }; + } else { + throw err; + } + } + + if (!result || !result.moduleDir) { throw errorToThrowableDiagnostic( - `Unable to resolve ${pkg} from ${sourceFile} when evaluating specifier ${specifier}`, + `Unable to resolve ${pkg} from ${sourceFile} when resolving specifier ${specifier}`, dependency, ); - } else if (result.diagnostics) { - throw new ThrowableDiagnostic({diagnostic: result.diagnostics}); } - specifier = path.resolve(path.dirname(result.filePath), rest); + specifier = path.resolve(result.moduleDir, rest); } else { specifier = path.resolve(path.dirname(sourceFile), specifier); } @@ -151,6 +172,8 @@ export default (new Resolver({ } } + invalidateOnFileCreate.push({glob: normalized}); + return { filePath: path.join( dir, @@ -159,7 +182,8 @@ export default (new Resolver({ sourceAssetType, ), code, - invalidateOnFileCreate: [{glob: normalized}], + invalidateOnFileCreate, + invalidateOnFileChange: [...invalidateOnFileChange], pipeline: null, priority: 'sync', };