File tree Expand file tree Collapse file tree 2 files changed +18
-0
lines changed Expand file tree Collapse file tree 2 files changed +18
-0
lines changed Original file line number Diff line number Diff line change @@ -31,3 +31,11 @@ test('getHostedModuleUrl', () => {
31
31
. pathname
32
32
) . toBe ( '/npm/@jupyter-widgets/[email protected] /css/index.css' ) ;
33
33
} ) ;
34
+
35
+ test ( 'requirejs magic modules' , async ( ) => {
36
+ const loader = new Loader ( ) ;
37
+ loader . define ( 'foo' , [ 'module' ] , ( module ) => {
38
+ return `module: ${ module . id } ` ;
39
+ } ) ;
40
+ expect ( await loader . load ( 'foo' ) ) . toBe ( 'module: foo' ) ;
41
+ } ) ;
Original file line number Diff line number Diff line change @@ -91,6 +91,14 @@ export class Loader {
91
91
const requirements = await Promise . all (
92
92
module . dependencies . map ( ( dependency ) => {
93
93
const definition = this . definitions . get ( dependency ) ;
94
+ // Support requirejs magic modules:
95
+ // https://github.com/requirejs/requirejs/wiki/Differences-between-the-simplified-CommonJS-wrapper-and-standard-AMD-define#magic
96
+ if ( dependency === 'module' ) {
97
+ return {
98
+ id : module . id ,
99
+ url : this . resolveModule ( module . id ) ,
100
+ } ;
101
+ }
94
102
if ( ! definition ) {
95
103
throw new Error ( `Unknown dependency ${ dependency } ` ) ;
96
104
}
@@ -121,6 +129,7 @@ export class Loader {
121
129
const module = {
122
130
factory : factory as ( ) => unknown ,
123
131
dependencies,
132
+ id : moduleId ,
124
133
} ;
125
134
if ( ! definition ) {
126
135
this . definitions . set ( moduleId , {
@@ -158,6 +167,7 @@ interface Definition {
158
167
}
159
168
160
169
interface Module {
170
+ id : string ;
161
171
dependencies : string [ ] ;
162
172
factory : ( ...args : unknown [ ] ) => unknown ;
163
173
exports ?: Promise < unknown > ;
You can’t perform that action at this time.
0 commit comments