jspm

Class Generator

Generator.

Hierarchy

  • Generator

Constructors

  • 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

    Returns Generator

Properties

baseUrl: URL
installCnt: number = 0

The number of concurrent installs the generator is busy processing.

integrity: boolean
log: Log
logStream: LogStream
mapUrl: URL
rootUrl: URL
traceMap: default

Accessors

Methods

  • Parameters

    • Optional install: string | Install | (string | Install)[]
    • Optional mode: InstallMode

    Returns Promise<void | {
        dynamicDeps: string[];
        staticDeps: 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[]>

  • Parameters

    • pins: string | string[]
    • Optional mapUrl: string | URL
    • Optional rootUrl: string | URL
    • Optional integrity: boolean

    Returns Promise<{
        dynamicDeps: string[];
        map: IImportMap;
        staticDeps: string[];
    }>

  • Retrieve the lockfile data from the installer

    Returns LockResolutions

  • Parameters

    • Optional mapUrl: string | URL
    • Optional rootUrl: string | URL

    Returns IImportMap

  • 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 esModuleShims?: 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 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

    • Optional install: string | Install | (string | Install)[]

      Package or list of packages to install into the import map.

    Returns Promise<void | {
        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: string

      Optional parent URL

    Returns Promise<{
        dynamicDeps: string[];
        staticDeps: 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 | URL

      URL of the given HTML

    Returns Promise<string[]>

  • Locking install, retraces all top-level pins but does not change the versions of anything (similar to "npm ci").

    Returns Promise<{
        dynamicDeps: string[];
        staticDeps: string[];
    }>

  • Resolve a specifier using the import map.

    Returns

    Resolved URL string

    Parameters

    • specifier: string

      Module to resolve

    • parentUrl: string | URL = ...

      ParentURL of module to resolve

    Returns string

  • Parameters

    • names: string | string[]

    Returns 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