blob: 45e6508eb5092c2700423073b7fbe2ae04e1c9a7 [file] [log] [blame]
// Copyright (c) 2020, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
import 'dart:async';
import 'dart:io';
import 'package:path/path.dart' as path;
List<String> dart2JsCommand(List<String> args) {
String basePath = path.fromUri(Platform.script);
while (path.basename(basePath) != 'sdk') {
basePath = path.dirname(basePath);
}
String dart2jsPath =
path.normalize(path.join(basePath, 'pkg/compiler/lib/src/dart2js.dart'));
final command = <String>[];
command.add('--no-sound-null-safety');
if (Platform.packageConfig != null) {
command.add('--packages=${Platform.packageConfig}');
}
command.add(dart2jsPath);
command.addAll(args);
return command;
}
Future<ProcessResult> launchDart2Js(args, {bool noStdoutEncoding = false}) {
if (noStdoutEncoding) {
return Process.run(Platform.executable, dart2JsCommand(args),
stdoutEncoding: null);
} else {
return Process.run(Platform.executable, dart2JsCommand(args));
}
}