@@ -8,6 +8,7 @@ import 'dart:convert';
88import 'dart:io' ;
99import 'dart:typed_data' ;
1010
11+ import 'package:args/args.dart' ;
1112import 'package:dev_compiler/dev_compiler.dart' ;
1213import 'package:dev_compiler/src/command/command.dart' ;
1314import 'package:dev_compiler/src/kernel/hot_reload_delta_inspector.dart' ;
@@ -42,12 +43,14 @@ class IncrementalJavaScriptBundler {
4243 this .emitDebugSymbols = false ,
4344 this .canaryFeatures = false ,
4445 String ? moduleFormat,
46+ this .extraDdcOptions = const [],
4547 }) : _moduleFormat = parseModuleFormat (moduleFormat ?? 'amd' );
4648
4749 final bool useDebuggerModuleNames;
4850 final bool emitDebugMetadata;
4951 final bool emitDebugSymbols;
5052 final ModuleFormat _moduleFormat;
53+ final List <String > extraDdcOptions;
5154 final bool canaryFeatures;
5255 final FileSystem ? _fileSystem;
5356 final Set <Library > _loadedLibraries;
@@ -185,6 +188,20 @@ class IncrementalJavaScriptBundler {
185188 }
186189 }
187190
191+ /// Reports if [option] in [extraDdcOptions] was overridden or extended
192+ /// to [newValue] before being passed to DDC.
193+ void _checkOverriddenExtraDdcOption (
194+ ArgResults extraDdcOptionsResults, String option, dynamic newValue) {
195+ if (extraDdcOptionsResults.wasParsed (option)) {
196+ if (newValue is List ) {
197+ if (listEquals (extraDdcOptionsResults[option], newValue)) return ;
198+ } else if (newValue == extraDdcOptionsResults[option]) {
199+ return ;
200+ }
201+ print ("Warning: DDC option '$option ' was overridden to '$newValue '." );
202+ }
203+ }
204+
188205 /// Compile each component into a single JavaScript library bundle.
189206 Future <Map <String , Compiler >> compile (
190207 ClassHierarchy classHierarchy,
@@ -221,18 +238,42 @@ class IncrementalJavaScriptBundler {
221238
222239 final String componentUrl =
223240 urlForComponentUri (libraryBundleImport, packageConfig);
224- // library bundle name to use in trackLibraries
225- // use full path for tracking if library bundle uri is not a package uri.
241+ // Library bundle name to use in trackLibraries. Use the full path for
242+ // tracking if library bundle uri is not a package uri.
226243 final String libraryBundleName = makeLibraryBundleName (componentUrl);
227- final Options ddcOptions = new Options (
228- sourceMap: true ,
229- summarizeApi: false ,
230- emitDebugMetadata: emitDebugMetadata,
231- emitDebugSymbols: emitDebugSymbols,
232- moduleName: libraryBundleName,
233- canaryFeatures: canaryFeatures,
234- moduleFormats: [_moduleFormat],
235- );
244+ // Issue a warning when provided [extraDdcOptions] were overridden.
245+ final ArgResults extraDdcOptionsResults =
246+ Options .nonSdkArgParser ().parse (extraDdcOptions);
247+ _checkOverriddenExtraDdcOption (
248+ extraDdcOptionsResults, 'source-map' , true );
249+ _checkOverriddenExtraDdcOption (
250+ extraDdcOptionsResults, 'summarize' , false );
251+ _checkOverriddenExtraDdcOption (extraDdcOptionsResults,
252+ 'experimental-emit-debug-metadata' , emitDebugMetadata);
253+ _checkOverriddenExtraDdcOption (
254+ extraDdcOptionsResults, 'emit-debug-symbols' , emitDebugSymbols);
255+ _checkOverriddenExtraDdcOption (
256+ extraDdcOptionsResults, 'canary' , canaryFeatures);
257+ _checkOverriddenExtraDdcOption (
258+ extraDdcOptionsResults, 'module-name' , libraryBundleName);
259+ _checkOverriddenExtraDdcOption (
260+ extraDdcOptionsResults, 'modules' , [libraryBundleName]);
261+ // Apply existing Frontend Server flags over options selected in
262+ // [extraDdcOptions].
263+ final List <String > ddcArgs = [
264+ ...extraDdcOptions,
265+ '--source-map' ,
266+ '--no-summarize' ,
267+ emitDebugMetadata
268+ ? '--experimental-emit-debug-metadata'
269+ : '--no-experimental-emit-debug-metadata' ,
270+ emitDebugSymbols ? '--emit-debug-symbols' : '--no-emit-debug-symbols' ,
271+ canaryFeatures ? '--canary' : '--no-canary' ,
272+ '--module-name=$libraryBundleName ' ,
273+ '--modules=${_moduleFormat .flagName }' ,
274+ ];
275+ final Options ddcOptions =
276+ new Options .fromArguments (Options .nonSdkArgParser ().parse (ddcArgs));
236277 Compiler compiler;
237278 if (ddcOptions.emitLibraryBundle) {
238279 compiler = new LibraryBundleCompiler (
0 commit comments