registerGlobalVariables static method

void registerGlobalVariables(
  1. D4rt interpreter,
  2. String importPath, {
  3. bool include(
    1. String? sourceUri
    )?,
})

Registers all global variables with the interpreter.

importPath is the package import path for library-scoped registration. Collects all registration errors and throws a single exception with all error details if any registrations fail.

Implementation

static void registerGlobalVariables(
  D4rt interpreter,
  String importPath, {
  bool Function(String? sourceUri)? include,
}) {
  final errors = <String>[];

  if (include == null ||
      include('package:tom_dcli/src/installers/installer.dart')) {
    try {
      interpreter.registerGlobalVariable(
        'installFromSourceKey',
        $tom_dcli_18.installFromSourceKey,
        importPath,
        sourceUri: 'package:tom_dcli/src/installers/installer.dart',
      );
    } catch (e) {
      errors.add('Failed to register variable "installFromSourceKey": $e');
    }
  }
  if (include == null ||
      include('package:tom_dcli/src/script/dart_project.dart')) {
    try {
      interpreter.registerGlobalVariable(
        'overrideDCliPathKey',
        $tom_dcli_23.overrideDCliPathKey,
        importPath,
        sourceUri: 'package:tom_dcli/src/script/dart_project.dart',
      );
    } catch (e) {
      errors.add('Failed to register variable "overrideDCliPathKey": $e');
    }
  }
  if (include == null ||
      include('package:dcli_core/src/functions/env.dart')) {
    interpreter.registerGlobalGetter(
      'env',
      () => $dcli_core_9.env,
      importPath,
      sourceUri: 'package:dcli_core/src/functions/env.dart',
    );
  }
  if (include == null ||
      include('package:dcli_core/src/functions/env.dart')) {
    interpreter.registerGlobalGetter(
      'PATH',
      () => $dcli_core_9.PATH,
      importPath,
      sourceUri: 'package:dcli_core/src/functions/env.dart',
    );
  }
  if (include == null ||
      include('package:dcli_core/src/functions/env.dart')) {
    interpreter.registerGlobalGetter(
      'HOME',
      () => $dcli_core_9.HOME,
      importPath,
      sourceUri: 'package:dcli_core/src/functions/env.dart',
    );
  }
  if (include == null ||
      include('package:dcli_core/src/functions/env.dart')) {
    interpreter.registerGlobalGetter(
      'envs',
      () => $dcli_core_9.envs,
      importPath,
      sourceUri: 'package:dcli_core/src/functions/env.dart',
    );
  }
  if (include == null ||
      include('package:dcli_core/src/functions/pwd.dart')) {
    interpreter.registerGlobalGetter(
      'pwd',
      () => $dcli_core_15.pwd,
      importPath,
      sourceUri: 'package:dcli_core/src/functions/pwd.dart',
    );
  }
  if (include == null ||
      include('package:dcli_core/src/util/platform.dart')) {
    interpreter.registerGlobalGetter(
      'eol',
      () => $dcli_core_23.eol,
      importPath,
      sourceUri: 'package:dcli_core/src/util/platform.dart',
    );
  }
  if (include == null ||
      include('package:dcli_core/src/util/truepath.dart')) {
    interpreter.registerGlobalGetter(
      'rootPath',
      () => $dcli_core_26.rootPath,
      importPath,
      sourceUri: 'package:dcli_core/src/util/truepath.dart',
    );
  }
  if (include == null ||
      include('package:tom_dcli/src/functions/file_list.dart')) {
    interpreter.registerGlobalGetter(
      'fileList',
      () => $tom_dcli_7.fileList,
      importPath,
      sourceUri: 'package:tom_dcli/src/functions/file_list.dart',
    );
  }

  if (errors.isNotEmpty) {
    throw StateError(
      'Bridge registration errors (dcli):\n${errors.join("\n")}',
    );
  }
}