NpmRegistry class
In-memory registry collecting NpmDependency declarations and generating ESM import maps.
Collects dependencies declared during application initialization or build steps and generates standard W3C browser import maps as JSON or HTML tags.
Specifier Resolution
When registering dependencies via register or registerAll, if a specifier is registered more than once, the latest registration silently replaces earlier ones.
void main() {
NpmRegistry.registerAll([
const NpmDependency('canvas-confetti', '^1.9.2'),
const NpmDependency('dayjs', '^1.11.10'),
]);
final importMapTag = NpmRegistry.generateImportMapTag(pretty: true);
}
Properties
- hashCode → int
-
The hash code for this object.
no setterinherited
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
Methods
-
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
toString(
) → String -
A string representation of this object.
inherited
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited
Static Properties
-
all
→ Map<
String, NpmDependency> -
Unmodifiable map view of all currently registered dependencies, keyed by specifier.
no setter
Static Methods
-
clear(
) → void - Clears all registered dependencies from the registry.
-
conflicts(
) → List< String> - Returns specifiers that were registered with conflicting versions.
-
generateImportMapJson(
{bool pretty = false}) → String -
Generates a standard W3C Import Map JSON string with
importsandscopes. -
generateImportMapTag(
{bool pretty = false}) → String -
Generates an HTML
<script type="importmap">tag containing the generated import map JSON. -
register(
NpmDependency dep) → void -
Registers a single
dep. -
registerAll(
Iterable< NpmDependency> deps) → void - Registers multiple dependencies sequentially via register.
-
toMap(
) → Map< String, dynamic> -
Returns the top-level import map as a Dart Map with an
'imports'key.