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
Private
freeze
install Cnt
The number of concurrent installs the generator is busy processing.
Private
latest
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): Promise<{
dynamicDeps: string[];
map: IImportMap;
staticDeps: string[];
}> -
Parameters
-
pins: string | string[]
-
Optional
mapUrl: string | URL -
Optional
rootUrl: string | URL
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 Generate
- html
Generate(html: string, injectOptions?: {
comment?: string | boolean;
esModuleShims?: string | boolean;
htmlUrl?: string | URL;
integrity?: boolean;
mapUrl?: string | URL;
preload?: boolean | "all" | "static";
rootUrl?: string | URL;
whitespace?: boolean;
}): Promise<string> -
Generate and inject an import map for an HTML file
Deprecated
Instead use: const pins = await generator.addMappings(html, mapUrl, rootUrl); return await generator.htmlInject(html, { pins, htmlUrl: mapUrl, rootUrl, preload, integrity, whitespace, esModuleShims, comment });
Traces the module scripts of the HTML via link and install for URL-like specifiers and bare specifiers respectively.
Injects the final generated import map returning the injected HTML
Parameters
-
html: string
String
-
injectOptions: {
comment?: string | boolean;
esModuleShims?: string | boolean;
htmlUrl?: string | URL;
integrity?: boolean;
mapUrl?: string | URL;
preload?: boolean | "all" | "static";
rootUrl?: string | URL;
whitespace?: boolean;
} = {}Injection options
Injection options are:
htmlUrl
,preload
,integrity
,whitespace
andesModuleShims
. The default is\{ esModuleShims: true, whitespace: true \}
.ES Module shims will be resolved to the latest version against the provider
Example:
const outputHtml = await generator.htmlGenerate(`
<!doctype html>
<script type="module">import 'react'</script>
`);
// <!doctype html>
// <!-- Generated by @jspm/generator - https://github.com/jspm/generator -->
// <script async src="https://ga.jspm.io/npm:es-module-shims@1.4.1/dist/es-module-shims.js"></script>
// <script type="importmap">
// {...}
// </script>
// <script type="module">import 'react'</script>-
Optional
comment?: string | boolean -
Optional
esModule Shims?: string | boolean -
Optional
htmlUrl?: string | URL -
Optional
integrity?: boolean -
Optional
mapUrl?: string | URL -
Optional
preload?: boolean | "all" | "static" -
Optional
rootUrl?: string | URL -
Optional
whitespace?: boolean
-
Returns Promise<string>
-
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 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[]>
-
pin
- pin(specifier: string, parentUrl?: string): Promise<{
dynamicDeps: string[];
staticDeps: string[];
}> -
Trace and pin a module, installing all dependencies necessary into the map to support its execution including static and dynamic module imports.
Deprecated
Use "link" instead.
Parameters
-
specifier: string
-
Optional
parentUrl: string
Returns Promise<{
dynamicDeps: string[];
staticDeps: string[];
}> -
reinstall
- reinstall(): Promise<{
dynamicDeps: string[];
staticDeps: string[];
}> -
Locking install, retraces all top-level pins but does not change the versions of anything (similar to "npm ci").
Deprecated
Use install() with the "freeze: true" option.
Returns Promise<{
dynamicDeps: string[];
staticDeps: string[];
}>
resolve
trace Install
- trace
Install(specifier: string | string[], parentUrl?: string): Promise<{
dynamicDeps: string[];
staticDeps: string[];
}> -
Trace a module, installing all dependencies necessary into the map to support its execution including static and dynamic module imports.
Deprecated
Use "link" instead.
Parameters
-
specifier: string | string[]
Module to trace
-
Optional
parentUrl: stringOptional parent URL
Returns Promise<{
dynamicDeps: string[];
staticDeps: string[];
}> -
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.