@@ -8,6 +8,7 @@ import type {
8
8
Module ,
9
9
} from 'webpack' ;
10
10
import { join , dirname , resolve , relative , posix , isAbsolute } from 'path' ;
11
+ import { createHash } from 'crypto' ;
11
12
import { mergeWith , flatten , zip } from 'lodash' ;
12
13
import { writeFileSync , realpathSync , readFileSync } from 'fs' ;
13
14
import { compile , registerHelper } from 'handlebars' ;
@@ -25,6 +26,7 @@ import { ensureDirSync, symlinkSync, existsSync } from 'fs-extra';
25
26
import MiniCssExtractPlugin from 'mini-css-extract-plugin' ;
26
27
import minimatch from 'minimatch' ;
27
28
import { TransformOptions } from '@babel/core' ;
29
+ import { stripQuery } from './util' ;
28
30
29
31
const EXTENSIONS = [ '.js' , '.ts' , '.json' ] ;
30
32
@@ -35,6 +37,27 @@ registerHelper('join', function (list, connector) {
35
37
return list . join ( connector ) ;
36
38
} ) ;
37
39
40
+ const moduleIdMap = new Map < string , string > ( ) ;
41
+
42
+ function moduleToId ( moduleSpecifier : string ) {
43
+ let id = moduleSpecifier ;
44
+
45
+ // if the module contains characters that need to be escaped, then map this to a hash instead, so we can easily replace this later
46
+ if ( moduleSpecifier . includes ( '"' ) || moduleSpecifier . includes ( "'" ) ) {
47
+ id = createHash ( 'md5' ) . update ( 'some_string' ) . digest ( 'hex' ) ;
48
+
49
+ moduleIdMap . set ( id , moduleSpecifier ) ;
50
+ }
51
+
52
+ return id ;
53
+ }
54
+
55
+ function idToModule ( id : string ) {
56
+ return moduleIdMap . get ( id ) ?? id ;
57
+ }
58
+
59
+ registerHelper ( 'module-to-id' , moduleToId ) ;
60
+
38
61
const entryTemplate = compile (
39
62
`
40
63
module.exports = (function(){
@@ -52,7 +75,7 @@ module.exports = (function(){
52
75
return r('_eai_sync_' + specifier)(Array.prototype.slice.call(arguments, 1))
53
76
};
54
77
{{#each staticImports as |module|}}
55
- d('{{js-string-escape module.specifier}}', EAI_DISCOVERED_EXTERNALS('{{js-string-escape module.specifier}}'), function() { return require('{{js-string-escape module.specifier}}'); });
78
+ d('{{js-string-escape module.specifier}}', EAI_DISCOVERED_EXTERNALS('{{module-to-id module.specifier}}'), function() { return require('{{js-string-escape module.specifier}}'); });
56
79
{{/each}}
57
80
{{#each dynamicImports as |module|}}
58
81
d('_eai_dyn_{{js-string-escape module.specifier}}', [], function() { return import('{{js-string-escape module.specifier}}'); });
@@ -368,7 +391,11 @@ export default class WebpackBundler extends Plugin implements Bundler {
368
391
369
392
// Handling full-name imports that point at the app itself e.g. app-name/lib/thingy
370
393
if ( name === this . opts . rootPackage . name ) {
371
- if ( this . importMatchesAppImports ( request . slice ( name . length + 1 ) ) ) {
394
+ if (
395
+ this . importMatchesAppImports (
396
+ stripQuery ( request . slice ( name . length + 1 ) )
397
+ )
398
+ ) {
372
399
// webpack should handle this because it's another file in the app that matches allowAppImports
373
400
return callback ( ) ;
374
401
} else {
@@ -481,7 +508,7 @@ export default class WebpackBundler extends Plugin implements Bundler {
481
508
/ E A I _ D I S C O V E R E D _ E X T E R N A L S \( [ ' " ] ( [ ^ ' " ] + ) [ ' " ] \) / g,
482
509
( _substr : string , matched : string ) => {
483
510
let deps = build
484
- . externalDepsFor ( matched )
511
+ . externalDepsFor ( idToModule ( matched ) )
485
512
. filter ( ( dep ) => this . externalizedByUs . has ( dep ) ) ;
486
513
return '[' + deps . map ( ( d ) => `'${ d } '` ) . join ( ',' ) + ']' ;
487
514
}
0 commit comments