@oazmi/esbuild-plugin-deno - v0.4.4
    Preparing search index...

    Class WorkspacePackage<SCHEMA>Abstract

    the WorkspacePackage abstract class adds support for resolving import and export aliases from workspace packages. check the base class RuntimePackage for more details.

    Type Parameters

    • SCHEMA extends Record<string, any>

    Hierarchy (View Summary)

    Index

    Constructors

    Properties

    packagePath: string

    the path or url of the package json(c) file.

    the base class does nothing with this information; it is just there so that subclasses can make uses of this information (usually for resolving relative paths).

    packageInfo: SCHEMA

    the fetched/parsed package metadata file's raw contents.

    importMapSortedEntries: ImportMapSortedEntries

    the import-map entries of the package, sorted from the largest key-alias to the shortest.

    Note

    each subclass will have to assign on their own, in addition to ensuring the required sorting order.

    exportMapSortedEntries: ImportMapSortedEntries

    the export-map entries of the package, sorted from the largest key-alias to the shortest.

    Note

    each subclass will have to assign on their own, in addition to ensuring the required sorting order.

    workspaceChildren: WorkspacePackage<any>[]

    specify all child workspaces of this package.

    • the exports of every child-workspace package are inherited by this runtime package.

      example: if packageB is child-workspace of packageA, then packageA.exports would be a superset of packageB.exports.

    • similarly, the imports of this runtime package will be implicitly available for all child-workspace packages.

      example: if packageB is child-workspace of packageA, then packageA.imports would be a subset of packageB.imports.

      Note

      since child-workspaces are also considered to be dependencies of the parent package (the monorepo), each child-workspace would be available to for importation by all child-workspaces. in other words, sibling packages of the workspace would be able to import one another.

    Important

    the constructor of the subclasses do not typically parse the workspace paths from the provided schema, nor do they load the WorkspacePackage associated with those workspaces, since it would require asynchronous operations (such as fetch) which cannot be performed inside the constructor. this is why you would either need to manually add/push your child/parent-workspace WorkspacePackage object, or use the asynchronous fromUrl static method in the subclasses to take care of auto-loading and auto-injecting parent and child workspaces.

    workspaceParents: WorkspacePackage<any>[]

    specify all parent workspaces of this package.

    • the imports of this runtime package will be implicitly available for all child-workspace packages.

      example: if packageB is child-workspace of packageA, then packageA.imports would be a subset of packageB.imports.

    • the exports of every child-workspace package are inherited by this runtime package.

      example: if packageB is child-workspace of packageA, then packageA.exports would be a superset of packageB.exports.

    Important

    the constructor of the subclasses do not typically parse the workspace paths from the provided schema, nor do they load the WorkspacePackage associated with those workspaces, since it would require asynchronous operations (such as fetch) which cannot be performed inside the constructor. this is why you would either need to manually add/push your child/parent-workspace WorkspacePackage object, or use the asynchronous fromUrl static method in the subclasses to take care of auto-loading and auto-injecting parent and child workspaces.

    Methods

    • get the path/url to the package's json(c) file.

      the base class does nothing with this information; it is just there so that subclasses can make uses of this information (usually for resolving relative paths).

      Returns string

    • create an instance of this class by loading a package's json(c) file from a url or local file-system path.

      Important

      the resulting new instance is cached (memorized), so that it can be reused if another query with the same normalized path is provided.

      why are we forcing a cache mechanism on the base class?

      because the workspace children/parents, in the WorkspacePackage subclass, are referenced by their absolute path, and resolving an import through a workspace package would involve the creation of that child/parent runtime package via this method, thus leading to an exponential number of redundant re-creation of identical package manager objects.

      Tip

      the constructor uses a "JSONC" parser (from @oazmi/kitchensink/stringman) for the fetched files. therefore, you may provide links to ".jsonc" files, instead of parsing them yourself before calling the super constructor.

      Type Parameters

      Parameters

      • this: ConstructorOf<INSTANCE, [SCHEMA, string]>
      • package_jsonc_path: string | URL

      Returns Promise<INSTANCE>

    • add a child workspace package, either by providing its path (absolute or relative), or by providing its WorkspacePackage object.

      the exports of the added child workspace will become available to this package during workspace export-resolution (resolveWorkspaceExport).

      Parameters

      • package_jsonc_path: string | URL

      Returns Promise<void>

    • add a child workspace package, either by providing its path (absolute or relative), or by providing its WorkspacePackage object.

      the exports of the added child workspace will become available to this package during workspace export-resolution (resolveWorkspaceExport).

      Parameters

      Returns Promise<void>

    • add a parent (monorepo) to this package, either by providing its path (absolute or relative), or by providing its WorkspacePackage object.

      the imports of the added parent workspace will become available to this package during workspace import-resolution (resolveWorkspaceImport).

      Parameters

      • package_jsonc_path: string | URL

      Returns Promise<void>

    • add a parent (monorepo) to this package, either by providing its path (absolute or relative), or by providing its WorkspacePackage object.

      the imports of the added parent workspace will become available to this package during workspace import-resolution (resolveWorkspaceImport).

      Parameters

      Returns Promise<void>

    • this method tries to resolve the provided export path_alias to an absolute resource path, using this package's child workspaces (i.e. not including this package's own exports).

      • if the action is successful, then a 2-tuple is returned, consisting of the resolved_path and the child_workspace_package that managed to resolve the provided path_alias.
      • if there are no child-workspaces, or if the child-workspaces fail to resolve the exported path_alias, then undefined will be returned.
      • this method does not inspect this package's own exports. you should use resolveExport for that.

      Parameters

      Returns undefined | ResolveWorkspaceReturnType

    • this method tries to resolve the provided import path_alias done by some resource within this package, using the internal importMapSortedEntries list of import-aliases that this package uses.

      • if the action is successful, then a 2-tuple is returned, consisting of the resolved_path and the child_workspace_package that managed to resolve the provided path_alias.
      • if no import resources match the given path_alias within this package, then this package's workspaceParents will be traversed.
      • if there are no parent-workspaces, or if the parent-workspaces fail to resolve this path_alias, then undefined will be returned. (which would probably imply that the given path_alias is already either an absolute or relative path, or perhaps incorrect altogether)
      Tip

      for test case examples and configuration options, see the documentation comments of resolvePathFromImportMapEntries

      Parameters

      Returns undefined | ResolveWorkspaceReturnType