NpmDependency class

Declaration of an npm package dependency resolved via browser ESM import maps.

Encapsulates metadata required to generate standard W3C <script type="importmap"> entries so that browser JavaScript or JS interop can import npm packages directly.

Packages are resolved from an ESM CDN (defaulting to cdn = 'https://esm.sh') or local vendored bundles. If subPath is specified (e.g. 'icons' on 'lucide'), the import map will emit an ESM scopes block targeting the package base URL.

// Declare and register an npm package
const zod = NpmDependency('zod', '^3.23.0');
NpmRegistry.register(zod);

// Custom alias and CDN subpath
const lucideIcons = NpmDependency(
  'lucide',
  '0.344.0',
  importAs: 'lucide-icons',
  subPath: 'icons',
);
NpmRegistry.register(lucideIcons);

Constructors

NpmDependency(String name, String version, {String? importAs, String cdn = 'https://esm.sh', String? integrity, String? subPath})
Creates an NpmDependency descriptor.
const

Properties

cdn → String
CDN base URL provider. Defaults to 'https://esm.sh'.
final
hashCode → int
The hash code for this object.
no setterinherited
importAs → String?
Custom import specifier alias override.
final
integrity → String?
Sub-Resource Integrity (SRI) hash, e.g. 'sha384-abc...'.
final
name → String
Package name in the npm registry, e.g. 'zod', 'date-fns', or 'lucide'.
final
runtimeType → Type
A representation of the runtime type of the object.
no setterinherited
specifier → String
The resolved import specifier key used in import statements and import maps.
no setter
subPath → String?
Optional package sub-path specifier, e.g. 'icons' for a lucide/icons scoped import.
final
url → String
The fully resolved ESM CDN URL, e.g. 'https://esm.sh/zod@^3.23.0'.
no setter
version → String
Semver range or exact version string, e.g. '^3.23.0' or '4.1.0'.
final

Methods

noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
toJson() → Map<String, dynamic>
Serializes dependency metadata to a JSON-encodable map.
toString() → String
A string representation of this object.
inherited

Operators

operator ==(Object other) → bool
The equality operator.
inherited