apollovm_pub library
Optional Dart package importer for ApolloVM.
This is an opt-in entrypoint, intentionally NOT re-exported from the
web-safe package:apollovm/apollovm.dart. It resolves Dart package:
imports against real pub packages — from a project's
.dart_tool/package_config.json (PackageConfigProvider, the default,
dependency-free) or by downloading from a pub host (PubDevProvider).
Web-safe: the filesystem/network providers are pulled in only when
dart:io is available; web builds get no-op stubs.
Usage:
import 'package:apollovm/apollovm.dart';
import 'package:apollovm/apollovm_pub.dart';
final vm = ApolloVM();
await vm.loadCodeUnit(SourceCodeUnit('dart', mainSource, id: 'main.dart'));
final loader = DartPackageLoader(vm, PackageConfigProvider());
vm.moduleLoader = loader;
await loader.provision(); // fetch/load `package:` imports
final diagnostics = vm.resolve(language: 'dart');
Classes
- CompositeModuleLoader
- A ModuleLoader that delegates to a chain of loaders, returning the first non-null result for each operation. Web-safe: it adds no capabilities of its own, only composition, so an optional (e.g. filesystem/pub) loader can be layered on top of the in-memory VMModuleLoader without touching the core.
- DartPackageImporter
-
Fetches Dart
package:imports through a PackageProvider and loads their sources into an ApolloVM as modules, so the (synchronous) resolver can then resolve them like any other loaded unit. - DartPackageLoader
-
A ModuleLoader for Dart projects that use
package:imports. - FilePackageCache
-
Web stand-in for
FilePackageCache: no filesystem on the web, so it behaves as an in-memory cache (the directory argument is ignored). - MemoryPackageCache
- An in-memory PackageCache — the default, and the only one usable on the web (no filesystem).
- NoopPackageProvider
-
A PackageProvider that resolves nothing — the web-safe default so code
depending on the provider API compiles for web without pulling in
dart:io. - PackageArchive
-
A downloaded package archive (the raw
.tar.gzbytes) plus its resolved version. Cached so a package is fetched from the host only once. - PackageCache
-
Caches downloaded PackageArchives by package name. Web-safe by contract:
the default MemoryPackageCache holds bytes in memory; a disk-backed
implementation is provided for the VM (see
FilePackageCache). - PackageConfigProvider
-
Web no-op stand-in for
PackageConfigProvider(resolves nothing — there is no local pub cache /.dart_tool/package_config.jsonon the web). - PackageProvider
-
Resolves a Dart
package:import to its library source, from a package host (pub.dev or another) compatible withpubspecdependency declarations. - PackageSource
- A resolved package source: the source code and the moduleId it should be loaded under.
- PackageUri
-
A parsed
package:import URI:package:<package>/<libPath>. - PubDevProvider
-
A PackageProvider that downloads Dart packages from a pub host (pub.dev by
default, or a custom/private/mirror host) and resolves
package:imports from the extracted archives — honoring version constraints from a projectpubspec.