@@ -36,7 +36,11 @@ const { equals } = require("./util/ArrayHelpers");
3636const { getScheme } = require ( "./util/URLAbsoluteSpecifier" ) ;
3737const { compareIds } = require ( "./util/comparators" ) ;
3838const compileBooleanMatcher = require ( "./util/compileBooleanMatcher" ) ;
39- const { getUndoPath, toJsStringLiteral } = require ( "./util/identifier" ) ;
39+ const {
40+ RESOLVABLE_SPECIFIER_REGEXP ,
41+ getUndoPath,
42+ toJsStringLiteral
43+ } = require ( "./util/identifier" ) ;
4044const memoize = require ( "./util/memoize" ) ;
4145const { propertyAccess, propertyName } = require ( "./util/property" ) ;
4246const {
@@ -263,10 +267,6 @@ const ANALYZABLE_TOKEN_REGEXP = /\.\/@@webpackAnalyzableChunk:([\w-]+)@@/g;
263267// The same token read back out of one quoted specifier.
264268const ANALYZABLE_TOKEN_PAYLOAD = / @ @ w e b p a c k A n a l y z a b l e C h u n k : ( [ \w - ] + ) @ @ / ;
265269
266- // What `import()` resolves as a place rather than as a package name: relative,
267- // rooted, or carrying a scheme. Matched against the quote the specifier opens with.
268- const RESOLVABLE_SPECIFIER = / ^ " (?: \. { 0 , 2 } \/ | [ a - z A - Z ] [ \w + . - ] * : ) / ;
269-
270270// Stands in for the compilation hash inside an otherwise resolved filename, with the
271271// requested length when the placeholder asked for one.
272272const FULL_HASH_TOKEN_REGEXP = / @ @ w e b p a c k F u l l H a s h (?: - ( \d + ) ) ? @ @ / g;
@@ -3771,16 +3771,37 @@ class RuntimeTemplate {
37713771 }
37723772
37733773 /**
3774- * Whether the loader still needs to build a url from a chunk id: a chunk carrying
3775- * a runtime of its own is reached by a static import and so is never named in the
3776- * map, and only a runtime that can reach one has to keep the fallback.
3774+ * The chunks this loader can be handed an id for: the ones held by a group outside
3775+ * the initial wave, which is what an `import()` or a context map turns into an id.
3776+ * @param {Chunk } runtimeChunk the chunk holding the chunk loader
3777+ * @returns {Set<Chunk> } the chunks reachable from here through a non-initial group
3778+ */
3779+ _loadableChunks ( runtimeChunk ) {
3780+ const queue = new Set ( runtimeChunk . groupsIterable ) ;
3781+ /** @type {Set<Chunk> } */
3782+ const chunks = new Set ( ) ;
3783+ for ( const group of queue ) {
3784+ if ( ! group . isInitial ( ) ) {
3785+ for ( const chunk of group . chunks ) chunks . add ( chunk ) ;
3786+ }
3787+ for ( const child of group . childrenIterable ) queue . add ( child ) ;
3788+ }
3789+ return chunks ;
3790+ }
3791+
3792+ /**
3793+ * Whether the loader still needs to build a url from a chunk id, which is the case
3794+ * for a chunk it can be asked for that `analyzableChunkImports` leaves unnamed: one
3795+ * carrying a runtime of its own, or one a second entrypoint has at startup.
37773796 * @param {Chunk } runtimeChunk the chunk holding the chunk loader
37783797 * @param {ChunkGraph } chunkGraph the chunk graph
37793798 * @returns {boolean } true when an id the map does not hold can reach the loader
37803799 */
37813800 chunkImportsNeedRuntimeUrl ( runtimeChunk , chunkGraph ) {
3782- for ( const chunk of runtimeChunk . getAllReferencedChunks ( ) ) {
3783- if ( chunk === runtimeChunk || ! chunk . hasRuntime ( ) ) continue ;
3801+ const installed = new Set ( runtimeChunk . getAllInitialChunks ( ) ) ;
3802+ for ( const chunk of this . _loadableChunks ( runtimeChunk ) ) {
3803+ if ( chunk === runtimeChunk ) continue ;
3804+ if ( ! chunk . hasRuntime ( ) && ! installed . has ( chunk ) ) continue ;
37843805 if ( JavascriptModulesPlugin . chunkHasJs ( chunk , chunkGraph ) ) return true ;
37853806 }
37863807 return false ;
@@ -3843,7 +3864,7 @@ class RuntimeTemplate {
38433864 for ( const [ id , specifier ] of specifiers ) {
38443865 // A bare specifier is a package name, so spell it relative the way the
38453866 // runtime form's `.p + <file>` would have resolved it.
3846- if ( ! RESOLVABLE_SPECIFIER . test ( specifier ) ) {
3867+ if ( ! RESOLVABLE_SPECIFIER_REGEXP . test ( specifier . slice ( 1 ) ) ) {
38473868 specifiers . set ( id , `"./${ specifier . slice ( 1 ) } ` ) ;
38483869 }
38493870 }
@@ -4396,7 +4417,7 @@ class RuntimeTemplate {
43964417 // the chunk loader does. A literal part may still carry a stand-in of its own,
43974418 // so finish those here rather than scanning again.
43984419 return fillFullHash (
4399- / ^ (?: \. { 0 , 2 } \/ | [ a - z A - Z ] [ \w + . - ] * : ) / . test ( specifier )
4420+ RESOLVABLE_SPECIFIER_REGEXP . test ( specifier )
44004421 ? specifier
44014422 : `./${ specifier } `
44024423 ) ;
0 commit comments