AbstractProtected Readonlypackagethe 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).
Protected Readonlypackagethe fetched/parsed package metadata file's raw contents.
Protected Abstractimportthe import-map entries of the package, sorted from the largest key-alias to the shortest.
each subclass will have to assign on their own, in addition to ensuring the required sorting order.
Protected Abstractexportthe export-map entries of the package, sorted from the largest key-alias to the shortest.
each subclass will have to assign on their own, in addition to ensuring the required sorting order.
Readonlyworkspacespecify all child workspaces of this package.
the exports of every child-workspace package are inherited by this runtime package.
example: if
packageBis child-workspace ofpackageA, thenpackageA.exportswould be a superset ofpackageB.exports.
similarly, the imports of this runtime package will be implicitly available for all child-workspace packages.
example: if
packageBis child-workspace ofpackageA, thenpackageA.importswould be a subset ofpackageB.imports.
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.
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.
Readonlyworkspacespecify all parent workspaces of this package.
example: if
packageBis child-workspace ofpackageA, thenpackageA.importswould be a subset ofpackageB.imports.
example: if
packageBis child-workspace ofpackageA, thenpackageA.exportswould be a superset ofpackageB.exports.
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.
Abstractgetget the package's name.
Abstractgetget the package's version string.
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).
this method tries to resolve the provided export path_alias of this package,
to an absolutely referenced path to the resource (using the internal exportMapSortedEntries).
if no exported resources match the given path_alias, then undefined will be returned.
for test case examples and configuration options, see the documentation comments of resolvePathFromImportMapEntries
Optionalconfig: Partial<RuntimePackageResolveImportConfig>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 no import resources match the given path_alias, then undefined will be returned
(which would probably mean that the given path_alias is already either an absolute or relative path, or perhaps incorrect altogether.
for test case examples and configuration options, see the documentation comments of resolvePathFromImportMapEntries
Optionalconfig: Partial<RuntimePackageResolveImportConfig>Staticfromcreate an instance of this class by loading a package's json(c) file from a url or local file-system path.
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.
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.
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).
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).
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).
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).
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).
resolved_path and the child_workspace_package that managed to resolve the provided path_alias.path_alias, then undefined will be returned.Optionalconfig: Partial<RuntimePackageResolveImportConfig>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.
resolved_path and the child_workspace_package that managed to resolve the provided path_alias.path_alias within this package, then this package's workspaceParents will be traversed.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)for test case examples and configuration options, see the documentation comments of resolvePathFromImportMapEntries
Optionalconfig: Partial<RuntimePackageResolveImportConfig>
the
WorkspacePackageabstract class adds support for resolving import and export aliases from workspace packages. check the base class RuntimePackage for more details.