ethanblake4 / dart_eval

Extensible Dart interpreter for Dart with full interop

Home Page:https://pub.dev/packages/dart_eval

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

CompileError: Bridge: cannot find library package:meiyou_extensions_lib/packages/crypto_dart/encoders/base64.dart at unknown (file package:example/main.dart)

Noobware1 opened this issue · comments

here's the plugin

class CryptoDartPlugin extends EvalPlugin {
  @override
  void configureForCompile(BridgeDeclarationRegistry registry) {
    registry.defineBridgeClass($Encoder.$declaration);
    registry.defineBridgeClass($Base64.$declaration);
    registry.defineBridgeClass($Hex.$declaration);
    registry.defineBridgeClass($Utf8.$declaration);
    registry.defineBridgeClass($Utf16.$declaration);
    registry.defineBridgeClass($Encoders.$declaration);
    registry.defineBridgeClass($CryptoDart.$declaration);
    registry.addSource(DartSource(
        'package:meiyou_extensions_lib/packages/crypto_dart/pbkdf2.dart',
        pkdf2Source));
    registry.addSource(DartSource(
        'package:meiyou_extensions_lib/packages/crypto_dart/evpkdf.dart',
        evpkdfSource));
  }

  @override
  void configureForRuntime(Runtime runtime) {
    $Base64.configureForRuntime(runtime);
    $Hex.configureForRuntime(runtime);
    $Utf8.configureForRuntime(runtime);
    $Utf16.configureForRuntime(runtime);
    $Encoders.configureForRuntime(runtime);
    $CryptoDart.configureForRuntime(runtime);
  }

  @override
  String get identifier => 'package:meiyou_extensions_lib/packages/crypto_dart';
}

here are the types I have shortened them to encoders only


class CryptoDartTypes {
  //Encoders
  static const encoder = BridgeTypeSpec(
      'package:meiyou_extensions_lib/packages/crypto_dart/encoders/encoder.dart',
      'Encoder');

  static const encoders = BridgeTypeSpec(
      'package:meiyou_extensions_lib/packages/crypto_dart/encoders/encoders.dart',
      'Encoders');

  static const base64 = BridgeTypeSpec(
      'package:meiyou_extensions_lib/packages/crypto_dart/encoders/base64.dart',
      'Base64');

  static const hex = BridgeTypeSpec(
      'package:meiyou_extensions_lib/packages/crypto_dart/encoders/hex.dart',
      'Hex');

  static const utf8 = BridgeTypeSpec(
      'package:meiyou_extensions_lib/packages/crypto_dart/encoders/utf8.dart',
      'Utf8');

  static const utf16 = BridgeTypeSpec(
      'package:meiyou_extensions_lib/packages/crypto_dart/encoders/utf16.dart',
      'Utf16');
}

here's the test case

import 'package:meiyou_extensions_lib/dart_eval/dart_eval.dart';
import 'package:meiyou_extensions_lib/src/bridge_models/packages/crypto_dart/plugin.dart';
import 'package:test/test.dart';

void main() {
  group('CryptoDart', () {
    late Compiler compiler;
    setUp(() {
      compiler = Compiler()..addPlugin(CryptoDartPlugin());
    });

    test('CryptoDart', () async {
      final compiled = compiler.compile({
        'example': {
          'main.dart': '''  
           import 'package:meiyou_extensions_lib/packages/crypto_dart/encoders/encoders.dart';

          String main() {
            final a = Encoders().BASE64.parse('aGVsbG8gd29ybGQ=');
            final b = Encoders().BASE64.stringify(a);
            return b;
          }  
 
          '''
        }
      }).write();
      final runtime = Runtime(compiled.buffer.asByteData())
        ..addPlugin(CryptoDartPlugin());
      final value = runtime.executeLib('package:example/main.dart', 'main');
      expect(value, 'hello world');
    });
  });
}

Can you try adding this to your plugin?

registry.addSource(DartSource(
        'package:meiyou_extensions_lib/packages/crypto_dart/encoders/encoders.dart',
        '''import 'package:meiyou_extensions_lib/packages/crypto_dart/encoders/base64.dart'; '''));

This adds an explicit import of the base64 file. (If this works it's probably a bug because that shouldn't be required, but I think it might fix the issue)

sorry for the late reply
I tried doing this but now it shows this error

CompileError: Bridge: cannot find library package:meiyou_extensions_lib/packages/crypto_dart/encoders/encoder.dart at unknown (file package:example/main.dart)

Yeah that's the same error just with a different file. Just add imports of all of the files you get that error for to the dart source string.

Fixed in v0.7.6