@@ -21,14 +21,11 @@ void main() {
2121 initializePlatforms ();
2222
2323 final startingBuilders = {
24- // Uses the real sdk copy builder to copy required files from the SDK.
25- sdkJsCopyRequirejs (const BuilderOptions ({})),
26- sdkJsCompile (defaultBuilderOptions),
2724 const ModuleLibraryBuilder (),
2825 MetaModuleBuilder (ddcPlatform),
2926 MetaModuleCleanBuilder (ddcPlatform),
3027 ModuleBuilder (ddcPlatform),
31- ddcKernelBuilder (const BuilderOptions ({})),
28+ ddcKernelBuilder (const BuilderOptions ({'ddc-library-bundle' : true })),
3229 DevCompilerBuilder (
3330 platform: ddcPlatform,
3431 ddcLibraryBundle: ddcLibraryBundle,
@@ -50,6 +47,11 @@ void main() {
5047 'b|lib/b.dart' : '''final world = 'world';''' ,
5148 // Add a fake asset so that the build_web_compilers package exists.
5249 'build_web_compilers|fake.txt' : '' ,
50+ 'build_web_compilers|lib/src/dev_compiler/dart_sdk.js' : '' ,
51+ 'build_web_compilers|lib/src/dev_compiler/require.js' : '' ,
52+ 'build_web_compilers|lib/src/dev_compiler/ddc_module_loader.js' : '' ,
53+ 'build_web_compilers|lib/src/dev_compiler_stack_trace/stack_trace_mapper.dart.js' :
54+ '' ,
5355 };
5456 final startingExpectedOutputs = < String , Object > {
5557 'a|lib/.ddc.meta_module.clean' : isNotNull,
@@ -76,11 +78,6 @@ void main() {
7678 'b|lib/b.module.library' : isNotNull,
7779 'build_web_compilers|lib/.ddc.meta_module.clean' : isNotNull,
7880 'build_web_compilers|lib/.ddc.meta_module.raw' : isNotNull,
79- 'build_web_compilers|lib/src/dev_compiler/dart_sdk.js.map' : isNotNull,
80- 'build_web_compilers|lib/src/dev_compiler/dart_sdk.js' : isNotNull,
81- 'build_web_compilers|lib/src/dev_compiler/ddc_module_loader.js' :
82- isNotNull,
83- 'build_web_compilers|lib/src/dev_compiler/require.js' : isNotNull,
8481 };
8582
8683 test ('base build' , () async {
@@ -115,16 +112,10 @@ void main() {
115112 // Contains a script pointer to main's bootstrap.js file.
116113 contains ('"src": "index.dart.bootstrap.js", "id": "data-main"' ),
117114 // Maps non-lib modules to remove the top level dir.
118- contains (
119- '"src": "index.ddc.js", "id": "org-dartlang-app:///web/index.dart"' ,
120- ),
115+ contains ('"src": "index.ddc.js", "id": "web/index"' ),
121116 // Maps lib modules to packages path
122- contains (
123- '"src": "packages/a/a.ddc.js", "id": "package:a/a.dart"' ,
124- ),
125- contains (
126- '"src": "packages/b/b.ddc.js", "id": "package:b/b.dart"' ,
127- ),
117+ contains ('"src": "packages/a/a.ddc.js", "id": "packages/a/a"' ),
118+ contains ('"src": "packages/b/b.ddc.js", "id": "packages/b/b"' ),
128119 // Imports the dart sdk.
129120 contains ('"id": "dart_sdk"' ),
130121 isNot (contains ('lib/a' )),
@@ -157,6 +148,11 @@ void main() {
157148 ''' ,
158149 // Add a fake asset so that the build_web_compilers package exists.
159150 'build_web_compilers|fake.txt' : '' ,
151+ 'build_web_compilers|lib/src/dev_compiler/dart_sdk.js' : '' ,
152+ 'build_web_compilers|lib/src/dev_compiler/require.js' : '' ,
153+ 'build_web_compilers|lib/src/dev_compiler/ddc_module_loader.js' : '' ,
154+ 'build_web_compilers|lib/src/dev_compiler_stack_trace/stack_trace_mapper.dart.js' :
155+ '' ,
160156 };
161157 // Check that we are invoking the correct
162158 final expectedOutputs = {
@@ -174,9 +170,7 @@ void main() {
174170 'a|web/b.dart.js' : decodedMatches (
175171 allOf ([
176172 // Confirm that `a.dart` is the actual primary source.
177- contains (
178- '"src": "a.ddc.js", "id": "org-dartlang-app:///web/a.dart"' ,
179- ),
173+ contains ('"src": "a.ddc.js", "id": "web/a"' ),
180174 // And `b.dart` is the application whose 'main' is being invoked.
181175 contains ('"src": "b.dart.bootstrap.js", "id": "data-main' ),
182176 ]),
@@ -186,11 +180,6 @@ void main() {
186180 'a|web/b.module.library' : isNotNull,
187181 'build_web_compilers|lib/.ddc.meta_module.clean' : isNotNull,
188182 'build_web_compilers|lib/.ddc.meta_module.raw' : isNotNull,
189- 'build_web_compilers|lib/src/dev_compiler/dart_sdk.js.map' : isNotNull,
190- 'build_web_compilers|lib/src/dev_compiler/dart_sdk.js' : isNotNull,
191- 'build_web_compilers|lib/src/dev_compiler/ddc_module_loader.js' :
192- isNotNull,
193- 'build_web_compilers|lib/src/dev_compiler/require.js' : isNotNull,
194183 };
195184
196185 await testBuilders (
@@ -206,6 +195,11 @@ void main() {
206195 'a|lib/app.dart' : 'void main() {}' ,
207196 // Add a fake asset so that the build_web_compilers package exists.
208197 'build_web_compilers|fake.txt' : '' ,
198+ 'build_web_compilers|lib/src/dev_compiler/dart_sdk.js' : '' ,
199+ 'build_web_compilers|lib/src/dev_compiler/require.js' : '' ,
200+ 'build_web_compilers|lib/src/dev_compiler/ddc_module_loader.js' : '' ,
201+ 'build_web_compilers|lib/src/dev_compiler_stack_trace/stack_trace_mapper.dart.js' :
202+ '' ,
209203 };
210204 final expectedOutputs = {
211205 'a|lib/.ddc.meta_module.clean' : isNotNull,
@@ -216,9 +210,7 @@ void main() {
216210 'a|lib/app.dart.js' : decodedMatches (
217211 // Confirm that the child name is referenced via a package: uri
218212 // and not relative path to the root dir being served.
219- contains (
220- '"src": "packages/a/app.ddc.js", "id": "package:a/app.dart"' ,
221- ),
213+ contains ('"src": "packages/a/app.ddc.js", "id": "packages/a/app"' ),
222214 ),
223215 'a|lib/app.ddc.dill' : isNotNull,
224216 'a|lib/app.ddc.js.map' : isNotNull,
@@ -229,11 +221,6 @@ void main() {
229221 'a|lib/app.module.library' : isNotNull,
230222 'build_web_compilers|lib/.ddc.meta_module.clean' : isNotNull,
231223 'build_web_compilers|lib/.ddc.meta_module.raw' : isNotNull,
232- 'build_web_compilers|lib/src/dev_compiler/dart_sdk.js.map' : isNotNull,
233- 'build_web_compilers|lib/src/dev_compiler/dart_sdk.js' : isNotNull,
234- 'build_web_compilers|lib/src/dev_compiler/ddc_module_loader.js' :
235- isNotNull,
236- 'build_web_compilers|lib/src/dev_compiler/require.js' : isNotNull,
237224 };
238225
239226 await testBuilders (
@@ -279,5 +266,125 @@ void main() {
279266 'longer locked behind the --canary flag' ,
280267 );
281268 });
269+ group ('module system' , () {
270+ test ('resolves paths correctly in nested entrypoints' , () async {
271+ // Test that an entrypoint compiled at web/sub_dir/main.dart is served
272+ // relative to the entrypoint directory (e.g., web/sub_dir/main.ddc.js
273+ // and not web/sub_dir/sub_dir/main.ddc.js)
274+ final builderOptions = const BuilderOptions ({
275+ 'compiler' : 'dartdevc' ,
276+ 'ddc-library-bundle' : true ,
277+ 'native_null_assertions' : false ,
278+ });
279+ final builder = WebEntrypointBuilder .fromOptions (builderOptions);
280+ final assets = {
281+ 'a|web/sub/main.dart' : 'void main() {}' ,
282+ 'build_web_compilers|fake.txt' : '' ,
283+ 'build_web_compilers|lib/src/dev_compiler/dart_sdk.js' : '' ,
284+ 'build_web_compilers|lib/src/dev_compiler/require.js' : '' ,
285+ 'build_web_compilers|lib/src/dev_compiler/ddc_module_loader.js' : '' ,
286+ 'build_web_compilers|lib/src/dev_compiler_stack_trace/stack_trace_mapper.dart.js' :
287+ '' ,
288+ };
289+
290+ final ddcLibraryBundleBuilders = {
291+ const ModuleLibraryBuilder (),
292+ MetaModuleBuilder (ddcPlatform),
293+ MetaModuleCleanBuilder (ddcPlatform),
294+ ModuleBuilder (ddcPlatform),
295+ ddcKernelBuilder (const BuilderOptions ({'ddc-library-bundle' : true })),
296+ DevCompilerBuilder (platform: ddcPlatform, ddcLibraryBundle: true ),
297+ };
298+
299+ final expectedOutputs = {
300+ 'a|web/sub/main.dart.js' : decodedMatches (
301+ allOf ([
302+ contains ('"src": "main.ddc.js"' ),
303+ isNot (contains ('"src": "sub/main.ddc.js"' )),
304+ ]),
305+ ),
306+ 'build_web_compilers|lib/.ddc.meta_module.raw' : isNotNull,
307+ 'build_web_compilers|lib/.ddc.meta_module.clean' : isNotNull,
308+ 'a|web/sub/main.module.library' : isNotNull,
309+ 'a|lib/.ddc.meta_module.raw' : isNotNull,
310+ 'a|lib/.ddc.meta_module.clean' : isNotNull,
311+ 'a|web/sub/main.ddc.module' : isNotNull,
312+ 'a|web/sub/main.ddc.dill' : isNotNull,
313+ 'a|web/sub/main.ddc.js' : isNotNull,
314+ 'a|web/sub/main.ddc.js.map' : isNotNull,
315+ 'a|web/sub/main.ddc.js.metadata' : isNotNull,
316+ 'a|web/sub/main.dart.bootstrap.js' : isNotNull,
317+ 'a|web/sub/main.dart.bootstrap.end.js' : isNotNull,
318+ 'a|web/sub/main.digests' : isNotNull,
319+ 'a|web/sub/main.dart.ddc_merged_metadata' : isNotNull,
320+ };
321+
322+ await testBuilders (
323+ [...ddcLibraryBundleBuilders, builder],
324+ assets,
325+ outputs: expectedOutputs,
326+ );
327+ });
328+
329+ test ('properly outputs script names during bootstrap' , () async {
330+ final builderOptions = const BuilderOptions ({
331+ 'compiler' : 'dartdevc' ,
332+ 'ddc-library-bundle' : true ,
333+ 'native_null_assertions' : false ,
334+ });
335+ final builder = WebEntrypointBuilder .fromOptions (builderOptions);
336+ final assets = {
337+ 'a|web/main.dart' : 'void main() {}' ,
338+ 'build_web_compilers|fake.txt' : '' ,
339+ 'build_web_compilers|lib/src/dev_compiler/dart_sdk.js' : '' ,
340+ 'build_web_compilers|lib/src/dev_compiler/require.js' : '' ,
341+ 'build_web_compilers|lib/src/dev_compiler/ddc_module_loader.js' : '' ,
342+ 'build_web_compilers|lib/src/dev_compiler_stack_trace/stack_trace_mapper.dart.js' :
343+ '' ,
344+ };
345+
346+ final ddcLibraryBundleBuilders = {
347+ const ModuleLibraryBuilder (),
348+ MetaModuleBuilder (ddcPlatform),
349+ MetaModuleCleanBuilder (ddcPlatform),
350+ ModuleBuilder (ddcPlatform),
351+ ddcKernelBuilder (const BuilderOptions ({'ddc-library-bundle' : true })),
352+ DevCompilerBuilder (platform: ddcPlatform, ddcLibraryBundle: true ),
353+ };
354+
355+ await testBuilders (
356+ [...ddcLibraryBundleBuilders, builder],
357+ assets,
358+ outputs: {
359+ 'a|web/main.dart.js' : decodedMatches (
360+ allOf ([
361+ contains ('"id": "web/main"' ),
362+ isNot (contains ('"id": "org-dartlang-app:///web/main.dart"' )),
363+ contains ('"src": "main.ddc.js"' ),
364+ ]),
365+ ),
366+ 'a|web/main.ddc.js.map' : decodedMatches (
367+ allOf ([
368+ contains ('"file":"main.ddc.js"' ),
369+ contains ('"sources":["main.dart"]' ),
370+ ]),
371+ ),
372+ 'build_web_compilers|lib/.ddc.meta_module.raw' : isNotNull,
373+ 'build_web_compilers|lib/.ddc.meta_module.clean' : isNotNull,
374+ 'a|web/main.module.library' : isNotNull,
375+ 'a|lib/.ddc.meta_module.raw' : isNotNull,
376+ 'a|lib/.ddc.meta_module.clean' : isNotNull,
377+ 'a|web/main.ddc.module' : isNotNull,
378+ 'a|web/main.ddc.dill' : isNotNull,
379+ 'a|web/main.ddc.js' : isNotNull,
380+ 'a|web/main.ddc.js.metadata' : isNotNull,
381+ 'a|web/main.dart.bootstrap.js' : isNotNull,
382+ 'a|web/main.dart.bootstrap.end.js' : isNotNull,
383+ 'a|web/main.digests' : isNotNull,
384+ 'a|web/main.dart.ddc_merged_metadata' : isNotNull,
385+ },
386+ );
387+ });
388+ });
282389 });
283390}
0 commit comments