Class Generator
Hierarchy
- Generator
Index
Constructors
Properties
Accessors
Methods
Constructors
constructor
- new
Generator(opts?: GeneratorOptions): Generator -
Constructs a new Generator instance.
For example:
const generator = new Generator({
mapUrl: import.meta.url,
inputMap: {
"imports": {
"react": "https://cdn.skypack.dev/react"
}
},
defaultProvider: 'jspm',
defaultRegistry: 'npm',
providers: {
'@orgscope': 'nodemodules'
},
customProviders: {},
env: ['production', 'browser'],
cache: false,
});Parameters
-
opts: GeneratorOptions = {}
Configuration for the new generator instance.
Returns Generator
-
Properties
base Url
install Cnt
The number of concurrent installs the generator is busy processing.
integrity
log
log Stream
map
map Url
root Url
trace Map
Accessors
import Map
Methods
Private
_install
add Mappings
- add
Mappings(jsonOrHtml: string | IImportMap, mapUrl?: string | URL, rootUrl?: string | URL, preloads?: string[]): Promise<string[]> -
Add new custom mappings and lock resolutions to the input map of the generator, which are then applied in subsequent installs.
Returns
The list of modules pinned by this import map or HTML.
Parameters
-
jsonOrHtml: string | IImportMap
The mappings are parsed as a JSON data object or string, falling back to reading an inline import map from an HTML file.
-
mapUrl: string | URL = ...
An optional URL for the map to handle relative resolutions, defaults to generator mapUrl.
-
rootUrl: string | URL = ...
An optional root URL for the map to handle root resolutions, defaults to generator rootUrl.
-
Optional
preloads: string[]
Returns Promise<string[]>
-
extract Map
- extract
Map(pins: string | string[], mapUrl?: string | URL, rootUrl?: string | URL, integrity?: boolean): Promise<{
dynamicDeps: string[];
map: IImportMap;
staticDeps: string[];
}> -
Parameters
-
pins: string | string[]
-
Optional
mapUrl: string | URL -
Optional
rootUrl: string | URL -
Optional
integrity: boolean
Returns Promise<{
dynamicDeps: string[];
map: IImportMap;
staticDeps: string[];
}> -
get Analysis
- get
Analysis(url: string | URL): ModuleAnalysis -
Parameters
-
url: string | URL
Returns ModuleAnalysis
-
get Lock
get Map
- get
Map(mapUrl?: string | URL, rootUrl?: string | URL): IImportMap -
Parameters
-
Optional
mapUrl: string | URL -
Optional
rootUrl: string | URL
Returns IImportMap
-
html Inject
- html
Inject(html: string, opts?: {
comment?: string | boolean;
esModuleShims?: string | boolean;
htmlUrl?: string | URL;
integrity?: boolean;
pins?: boolean | string[];
preload?: boolean | "all" | "static";
rootUrl?: string | URL;
trace?: boolean | string[];
whitespace?: boolean;
}): Promise<string> -
Inject the import map into the provided HTML source
Returns
HTML source with import map injection
Parameters
-
html: string
HTML source to inject into
-
opts: {
comment?: string | boolean;
esModuleShims?: string | boolean;
htmlUrl?: string | URL;
integrity?: boolean;
pins?: boolean | string[];
preload?: boolean | "all" | "static";
rootUrl?: string | URL;
trace?: boolean | string[];
whitespace?: boolean;
} = {}Injection options
-
Optional
comment?: string | boolean -
Optional
esModule Shims?: string | boolean -
Optional
htmlUrl?: string | URL -
Optional
integrity?: boolean -
Optional
pins?: boolean | string[] -
Optional
preload?: boolean | "all" | "static" -
Optional
rootUrl?: string | URL -
Optional
trace?: boolean | string[] -
Optional
whitespace?: boolean
-
Returns Promise<string>
-
install
- install(install?: string | Install | (string | Install)[]): Promise<void | {
dynamicDeps: string[];
staticDeps: string[];
}> -
Install a package target into the import map, including all its dependency resolutions via tracing.
Example
// Install a new package into the import map
await generator.install('react-dom');
// Install a package version and subpath into the import map (installs lit/decorators.js)
await generator.install('lit@2/decorators.js');
// Install a package version to a custom alias
await generator.install({ alias: 'react16', target: 'react@16' });
// Install a specific subpath of a package
await generator.install({ target: 'lit@2', subpath: './html.js' });
// Install an export from a locally located package folder into the map
// The package.json is used to determine the exports and dependencies.
await generator.install({ alias: 'mypkg', target: './packages/local-pkg', subpath: './feature' });Parameters
Returns Promise<void | {
dynamicDeps: string[];
staticDeps: string[];
}>
link
- link(specifier: string | string[], parentUrl?: string): Promise<{
dynamicDeps: string[];
staticDeps: string[];
}> -
Link a module, installing all dependencies necessary into the map to support its execution including static and dynamic module imports.
Parameters
-
specifier: string | string[]
Module or list of modules to link
-
Optional
parentUrl: stringOptional parent URL
Returns Promise<{
dynamicDeps: string[];
staticDeps: string[];
}> -
link Html
- link
Html(html: string | string[], htmlUrl?: string | URL): Promise<string[]> -
Links every imported module in the given HTML file, installing all dependencies necessary to support its execution.
Parameters
-
html: string | string[]
HTML to link
-
Optional
htmlUrl: string | URLURL of the given HTML
Returns Promise<string[]>
-
reinstall
resolve
uninstall
update
- update(pkgNames?: string | string[]): Promise<{
dynamicDeps: string[];
staticDeps: string[];
}> -
Updates the versions of the given packages to the latest versions compatible with their parent's package.json ranges. If no packages are given then all the top-level packages in the "imports" field of the initial import map are updated.
Parameters
-
Optional
pkgNames: string | string[]Package name or list of package names to update.
Returns Promise<{
dynamicDeps: string[];
staticDeps: string[];
}> -
Generated using TypeDoc
Generator.