@ms-cloudpack/package-utilities 10.1.2 → 10.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/PackageDefinitions.d.ts.map +1 -1
- package/lib/PackageDefinitions.js +7 -1
- package/lib/PackageDefinitions.js.map +1 -1
- package/lib/addExportsMapEntry.d.ts +0 -5
- package/lib/addExportsMapEntry.d.ts.map +1 -1
- package/lib/addExportsMapEntry.js +2 -5
- package/lib/addExportsMapEntry.js.map +1 -1
- package/lib/createExportsMap.d.ts.map +1 -1
- package/lib/createExportsMap.js +1 -5
- package/lib/createExportsMap.js.map +1 -1
- package/lib/findFileInPackage.d.ts +0 -1
- package/lib/findFileInPackage.d.ts.map +1 -1
- package/lib/findFileInPackage.js +4 -19
- package/lib/findFileInPackage.js.map +1 -1
- package/lib/getTypesTransform.d.ts +7 -0
- package/lib/getTypesTransform.d.ts.map +1 -0
- package/lib/getTypesTransform.js +32 -0
- package/lib/getTypesTransform.js.map +1 -0
- package/lib/tsdoc-metadata.json +1 -1
- package/package.json +4 -4
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"PackageDefinitions.d.ts","sourceRoot":"","sources":["../src/PackageDefinitions.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EACV,eAAe,EACf,2BAA2B,EAE3B,iCAAiC,EACjC,uBAAuB,EACvB,WAAW,EACZ,MAAM,4BAA4B,CAAC;
|
|
1
|
+
{"version":3,"file":"PackageDefinitions.d.ts","sourceRoot":"","sources":["../src/PackageDefinitions.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EACV,eAAe,EACf,2BAA2B,EAE3B,iCAAiC,EACjC,uBAAuB,EACvB,WAAW,EACZ,MAAM,4BAA4B,CAAC;AAmBpC,qBAAa,kBAAmB,YAAW,uBAAuB;IAChE,OAAO,CAAC,YAAY,CAA0C;IAC9D,OAAO,CAAC,uBAAuB,CAA8B;IAC7D,OAAO,CAAC,OAAO,CAA8B;IAC7C,OAAO,CAAC,WAAW,CAAoC;IACvD,OAAO,CAAC,mBAAmB,CAAsC;IAEjE;;;;;OAKG;gBACS,eAAe,GAAE,MAAM,CAAC,MAAM,EAAE,WAAW,CAAM,EAAE,MAAM,CAAC,EAAE,eAAe;IAQjF,GAAG,CAAC,WAAW,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,2BAA2B,GAAG,OAAO,CAAC,WAAW,CAAC;IAQrF,MAAM,CAAC,WAAW,EAAE,MAAM,EAAE,OAAO,GAAE,2BAAgC,GAAG,OAAO,CAAC,WAAW,GAAG,SAAS,CAAC;IAkD9G,iBAAiB,CAAC,OAAO,EAAE,iCAAiC;IAO5D,KAAK,CAAC,OAAO,CAAC,EAAE;QAAE,SAAS,CAAC,EAAE,eAAe,CAAA;KAAE;IAY/C,OAAO,CAAC,OAAO,CAAC,EAAE,IAAI,CAAC,2BAA2B,EAAE,mBAAmB,CAAC,GAAG,MAAM,CAAC,MAAM,EAAE,WAAW,GAAG,SAAS,CAAC;CAGnH"}
|
|
@@ -4,11 +4,17 @@ import { getApplyOverridesTransform } from '@ms-cloudpack/package-overrides';
|
|
|
4
4
|
import { getNonSemverTransform } from './getNonSemverTransform.js';
|
|
5
5
|
import { getApiServerTransform } from './getApiServerTransform.js';
|
|
6
6
|
import { slash } from '@ms-cloudpack/path-string-parsing';
|
|
7
|
+
import { getTypesTransform } from './getTypesTransform.js';
|
|
7
8
|
/**
|
|
8
9
|
* `nonSemverTransform` has state defined when the function is called, so we need a wrapper function
|
|
9
10
|
* which returns new transforms to ensure that state is cleared when resetting.
|
|
10
11
|
*/
|
|
11
|
-
const getDefaultTransforms = () => [
|
|
12
|
+
const getDefaultTransforms = () => [
|
|
13
|
+
getApiServerTransform(),
|
|
14
|
+
getTypesTransform(),
|
|
15
|
+
getNonSemverTransform(),
|
|
16
|
+
getApplyOverridesTransform(),
|
|
17
|
+
];
|
|
12
18
|
export class PackageDefinitions {
|
|
13
19
|
/**
|
|
14
20
|
* Constructor for PackageDefinitions.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"PackageDefinitions.js","sourceRoot":"","sources":["../src/PackageDefinitions.ts"],"names":[],"mappings":"AAAA,OAAO,IAAI,MAAM,MAAM,CAAC;AASxB,OAAO,EAAE,QAAQ,EAAE,MAAM,8BAA8B,CAAC;AACxD,OAAO,EAAE,0BAA0B,EAAE,MAAM,iCAAiC,CAAC;AAC7E,OAAO,EAAE,qBAAqB,EAAE,MAAM,4BAA4B,CAAC;AACnE,OAAO,EAAE,qBAAqB,EAAE,MAAM,4BAA4B,CAAC;AACnE,OAAO,EAAE,KAAK,EAAE,MAAM,mCAAmC,CAAC;
|
|
1
|
+
{"version":3,"file":"PackageDefinitions.js","sourceRoot":"","sources":["../src/PackageDefinitions.ts"],"names":[],"mappings":"AAAA,OAAO,IAAI,MAAM,MAAM,CAAC;AASxB,OAAO,EAAE,QAAQ,EAAE,MAAM,8BAA8B,CAAC;AACxD,OAAO,EAAE,0BAA0B,EAAE,MAAM,iCAAiC,CAAC;AAC7E,OAAO,EAAE,qBAAqB,EAAE,MAAM,4BAA4B,CAAC;AACnE,OAAO,EAAE,qBAAqB,EAAE,MAAM,4BAA4B,CAAC;AACnE,OAAO,EAAE,KAAK,EAAE,MAAM,mCAAmC,CAAC;AAC1D,OAAO,EAAE,iBAAiB,EAAE,MAAM,wBAAwB,CAAC;AAE3D;;;GAGG;AACH,MAAM,oBAAoB,GAAG,GAAG,EAAE,CAAC;IACjC,qBAAqB,EAAE;IACvB,iBAAiB,EAAE;IACnB,qBAAqB,EAAE;IACvB,0BAA0B,EAAE;CAC7B,CAAC;AAEF,MAAM,OAAO,kBAAkB;IAO7B;;;;;OAKG;IACH,YAAY,kBAA+C,EAAE,EAAE,MAAwB;QAT/E,gBAAW,GAAiC,EAAE,CAAC;QAUrD,IAAI,CAAC,YAAY,GAAG,eAAe,CAAC;QACpC,IAAI,CAAC,uBAAuB,GAAG,EAAE,CAAC;QAClC,IAAI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AAW,GAAG,CAAC,GAAG,oBAAoB,EAAE,EAAE,GAAG,IAAI,CAAC,mBAAmB,CAAC,GAAG,CAAC,CAAC,OAAO,EAAE,EAAE,CAAC,OAAO,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC;QACnH,CAAC;IACH,CAAC;IAED,OAAO,CAAC,OAAgE;QACtE,OAAO,OAAO,EAAE,iBAAiB,CAAC,CAAC,CAAC,IAAI,CAAC,YAAY,CAAC,CAAC,CAAC,IAAI,CAAC,uBAAuB,CAAC;IACvF,CAAC;CACF","sourcesContent":["import path from 'path';\nimport type {\n CloudpackConfig,\n GetPackageDefinitionOptions,\n PackageDefinitionTransform,\n PackageDefinitionTransformFactory,\n PackageDefinitionsCache,\n PackageJson,\n} from '@ms-cloudpack/common-types';\nimport { readJson } from '@ms-cloudpack/json-utilities';\nimport { getApplyOverridesTransform } from '@ms-cloudpack/package-overrides';\nimport { getNonSemverTransform } from './getNonSemverTransform.js';\nimport { getApiServerTransform } from './getApiServerTransform.js';\nimport { slash } from '@ms-cloudpack/path-string-parsing';\nimport { getTypesTransform } from './getTypesTransform.js';\n\n/**\n * `nonSemverTransform` has state defined when the function is called, so we need a wrapper function\n * which returns new transforms to ensure that state is cleared when resetting.\n */\nconst getDefaultTransforms = () => [\n getApiServerTransform(),\n getTypesTransform(),\n getNonSemverTransform(),\n getApplyOverridesTransform(),\n];\n\nexport class PackageDefinitions implements PackageDefinitionsCache {\n private _definitions: Record<string, PackageJson | undefined>;\n private _transformedDefinitions: Record<string, PackageJson>;\n private _config: CloudpackConfig | undefined;\n private _transforms: PackageDefinitionTransform[] = [];\n private _transformFactories: PackageDefinitionTransformFactory[];\n\n /**\n * Constructor for PackageDefinitions.\n * @param definitionCache - The map of package paths to package definitions, used mainly for testing.\n * @param config - The optional config object to pass to transforms. When `reset` is called with a new value, the\n * transforms will be re-created using the new config.\n */\n constructor(definitionCache: Record<string, PackageJson> = {}, config?: CloudpackConfig) {\n this._definitions = definitionCache;\n this._transformedDefinitions = {};\n this._config = config;\n this._transforms = [...getDefaultTransforms()];\n this._transformFactories = [];\n }\n\n async get(packagePath: string, options?: GetPackageDefinitionOptions): Promise<PackageJson> {\n const definition = await this.tryGet(packagePath, options);\n if (!definition) {\n throw new Error(`package.json not found at \"${packagePath}\"`);\n }\n return definition;\n }\n\n async tryGet(packagePath: string, options: GetPackageDefinitionOptions = {}): Promise<PackageJson | undefined> {\n const { refresh, disableTransforms, importerContext } = options;\n\n // Normalize the path used for caching to ensure consistency and avoid duplicates.\n const normalizedPath = slash(packagePath);\n\n if (refresh) {\n delete this._definitions[normalizedPath];\n delete this._transformedDefinitions[normalizedPath];\n }\n\n // If the definition is not in the cache, read it from disk.\n // (If the definition was invalid JSON or not found, undefined is cached.)\n let definition = this._definitions[normalizedPath];\n if (!(normalizedPath in this._definitions)) {\n // `verbose` logs if the file exists but isn't valid JSON (or can't be read for some reason)\n definition = await readJson<PackageJson>(path.join(packagePath, 'package.json'), { verbose: true });\n this._definitions[normalizedPath] = definition;\n\n if (definition) {\n definition.name ??= `unknown-${packagePath.replace(/[^\\w-]/g, '-')}`;\n definition.version ??= '0.0.0-unknown';\n }\n }\n\n if (disableTransforms || !definition) {\n return definition;\n }\n\n // If we don't want to skip the transform, transform the definition.\n let transformedDefinition = this._transformedDefinitions[normalizedPath];\n if (!transformedDefinition) {\n transformedDefinition = definition;\n\n for (const transform of this._transforms) {\n transformedDefinition =\n (await transform({\n definition: transformedDefinition,\n packagePath: normalizedPath,\n packages: this,\n importerContext,\n })) || transformedDefinition;\n }\n\n this._transformedDefinitions[normalizedPath] = transformedDefinition;\n }\n\n return transformedDefinition;\n }\n\n registerTransform(factory: PackageDefinitionTransformFactory) {\n this._transformFactories.push(factory);\n this._transforms.push(factory(this._config));\n\n this.reset();\n }\n\n reset(options?: { newConfig?: CloudpackConfig }) {\n this._definitions = {};\n this._transformedDefinitions = {};\n\n const { newConfig } = options || {};\n\n if (newConfig) {\n this._config = newConfig;\n this._transforms = [...getDefaultTransforms(), ...this._transformFactories.map((factory) => factory(newConfig))];\n }\n }\n\n _getAll(options?: Pick<GetPackageDefinitionOptions, 'disableTransforms'>): Record<string, PackageJson | undefined> {\n return options?.disableTransforms ? this._definitions : this._transformedDefinitions;\n }\n}\n"]}
|
|
@@ -22,11 +22,6 @@ export interface AddExportsMapEntryOptions {
|
|
|
22
22
|
* assuming `index.js`.
|
|
23
23
|
*/
|
|
24
24
|
filePath?: string;
|
|
25
|
-
/**
|
|
26
|
-
* Optional types path. If not provided, types will be discovered for internal packages that have source files.
|
|
27
|
-
* This is useful mainly when converting the default import from a package.json that has explicit typings listed.
|
|
28
|
-
*/
|
|
29
|
-
typesPath?: string;
|
|
30
25
|
/**
|
|
31
26
|
* The condition to add the entry for. (Example: "import", "require") Defaults to "default".
|
|
32
27
|
*/
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"addExportsMapEntry.d.ts","sourceRoot":"","sources":["../src/addExportsMapEntry.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,uBAAuB,EAAE,kBAAkB,EAAE,MAAM,4BAA4B,CAAC;AAI/G;;GAEG;AACH,MAAM,WAAW,yBAAyB;IACxC;;OAEG;IACH,OAAO,EAAE,kBAAkB,CAAC;IAE5B;;OAEG;IACH,WAAW,EAAE,MAAM,CAAC;IAEpB;;;OAGG;IACH,UAAU,CAAC,EAAE,MAAM,CAAC;IAEpB;;;;OAIG;IACH,QAAQ,CAAC,EAAE,MAAM,CAAC;IAElB
|
|
1
|
+
{"version":3,"file":"addExportsMapEntry.d.ts","sourceRoot":"","sources":["../src/addExportsMapEntry.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,uBAAuB,EAAE,kBAAkB,EAAE,MAAM,4BAA4B,CAAC;AAI/G;;GAEG;AACH,MAAM,WAAW,yBAAyB;IACxC;;OAEG;IACH,OAAO,EAAE,kBAAkB,CAAC;IAE5B;;OAEG;IACH,WAAW,EAAE,MAAM,CAAC;IAEpB;;;OAGG;IACH,UAAU,CAAC,EAAE,MAAM,CAAC;IAEpB;;;;OAIG;IACH,QAAQ,CAAC,EAAE,MAAM,CAAC;IAElB;;OAEG;IACH,gBAAgB,CAAC,EAAE,QAAQ,GAAG,SAAS,GAAG,SAAS,CAAC;IAEpD;;;OAGG;IACH,oBAAoB,CAAC,EAAE,SAAS,GAAG,MAAM,CAAC;CAC3C;AAED;;GAEG;AACH,wBAAsB,kBAAkB,CACtC,OAAO,EAAE,yBAAyB,EAClC,OAAO,EAAE;IAAE,QAAQ,EAAE,uBAAuB,CAAC;IAAC,MAAM,EAAE,IAAI,CAAC,eAAe,EAAE,UAAU,CAAC,CAAA;CAAE,GACxF,OAAO,CAAC,OAAO,CAAC,CAqClB"}
|
|
@@ -6,7 +6,7 @@ import { findFileInPackage } from './findFileInPackage.js';
|
|
|
6
6
|
export async function addExportsMapEntry(options, context) {
|
|
7
7
|
const { exports, packagePath, environmentCondition, requestCondition } = options;
|
|
8
8
|
const importPath = normalizeRelativePath(options.importPath);
|
|
9
|
-
const { filePath, sourcePath
|
|
9
|
+
const { filePath, sourcePath } = await findFileInPackage({
|
|
10
10
|
packagePath,
|
|
11
11
|
filePath: options.filePath || options.importPath || '',
|
|
12
12
|
}, context);
|
|
@@ -18,14 +18,11 @@ export async function addExportsMapEntry(options, context) {
|
|
|
18
18
|
const localExports = exports;
|
|
19
19
|
let exportValue;
|
|
20
20
|
// If this is the only entry we're adding, set it to a string to minimize the exports map.
|
|
21
|
-
if (!
|
|
21
|
+
if (!sourcePath && !requestCondition) {
|
|
22
22
|
exportValue = filePath;
|
|
23
23
|
}
|
|
24
24
|
else {
|
|
25
25
|
exportValue = {};
|
|
26
|
-
if (typesPath) {
|
|
27
|
-
exportValue['types'] = typesPath;
|
|
28
|
-
}
|
|
29
26
|
if (sourcePath) {
|
|
30
27
|
exportValue['source'] = sourcePath;
|
|
31
28
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"addExportsMapEntry.js","sourceRoot":"","sources":["../src/addExportsMapEntry.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,qBAAqB,EAAE,MAAM,mCAAmC,CAAC;AAC1E,OAAO,EAAE,iBAAiB,EAAE,MAAM,wBAAwB,CAAC;
|
|
1
|
+
{"version":3,"file":"addExportsMapEntry.js","sourceRoot":"","sources":["../src/addExportsMapEntry.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,qBAAqB,EAAE,MAAM,mCAAmC,CAAC;AAC1E,OAAO,EAAE,iBAAiB,EAAE,MAAM,wBAAwB,CAAC;AAyC3D;;GAEG;AACH,MAAM,CAAC,KAAK,UAAU,kBAAkB,CACtC,OAAkC,EAClC,OAAyF;IAEzF,MAAM,EAAE,OAAO,EAAE,WAAW,EAAE,oBAAoB,EAAE,gBAAgB,EAAE,GAAG,OAAO,CAAC;IACjF,MAAM,UAAU,GAAG,qBAAqB,CAAC,OAAO,CAAC,UAAU,CAAC,CAAC;IAC7D,MAAM,EAAE,QAAQ,EAAE,UAAU,EAAE,GAAG,MAAM,iBAAiB,CACtD;QACE,WAAW;QACX,QAAQ,EAAE,OAAO,CAAC,QAAQ,IAAI,OAAO,CAAC,UAAU,IAAI,EAAE;KACvD,EACD,OAAO,CACR,CAAC;IAEF,yCAAyC;IACzC,IAAI,CAAC,QAAQ,EAAE,CAAC;QACd,OAAO,KAAK,CAAC;IACf,CAAC;IAED,8BAA8B;IAC9B,MAAM,YAAY,GAAG,OAAmF,CAAC;IACzG,IAAI,WAA4C,CAAC;IAEjD,0FAA0F;IAC1F,IAAI,CAAC,UAAU,IAAI,CAAC,gBAAgB,EAAE,CAAC;QACrC,WAAW,GAAG,QAAQ,CAAC;IACzB,CAAC;SAAM,CAAC;QACN,WAAW,GAAG,EAAE,CAAC;QAEjB,IAAI,UAAU,EAAE,CAAC;YACf,WAAW,CAAC,QAAQ,CAAC,GAAG,UAAU,CAAC;QACrC,CAAC;QAED,mCAAmC;QACnC,WAAW,CAAC,gBAAgB,IAAI,SAAS,CAAC,GAAG,QAAQ,CAAC;IACxD,CAAC;IAED,YAAY,CAAC,UAAU,CAAC,GAAG,oBAAoB,CAAC,CAAC,CAAC,EAAE,CAAC,oBAAoB,CAAC,EAAE,WAAW,EAAE,CAAC,CAAC,CAAC,WAAW,CAAC;IAExG,OAAO,IAAI,CAAC;AACd,CAAC","sourcesContent":["import type { CloudpackConfig, PackageDefinitionsCache, PackageJsonExports } from '@ms-cloudpack/common-types';\nimport { normalizeRelativePath } from '@ms-cloudpack/path-string-parsing';\nimport { findFileInPackage } from './findFileInPackage.js';\n\n/**\n * Options fo addExportsMapEntry.\n */\nexport interface AddExportsMapEntryOptions {\n /**\n * The exports map to add the entry to.\n */\n exports: PackageJsonExports;\n\n /**\n * The package path to add the entry for. This is used to resolve relative paths.\n */\n packagePath: string;\n\n /**\n * The import path to add the entry for. This is used as the key in the exports map. Defaults\n * to \".\" being the package import.\n */\n importPath?: string;\n\n /**\n * The relative path to the physical file location, representing the \"key\" in the exports map. Can be a partial\n * location, in which case we will attempt to search for the file and associated source/d.ts files. Defaults to\n * assuming `index.js`.\n */\n filePath?: string;\n\n /**\n * The condition to add the entry for. (Example: \"import\", \"require\") Defaults to \"default\".\n */\n requestCondition?: 'import' | 'require' | 'browser';\n\n /**\n * The condition that describes the environment the entry is for. (Example: \"browser\", \"node\".)\n * Unspecified implies environmentally agnostic.\n */\n environmentCondition?: 'browser' | 'node';\n}\n\n/**\n * Given an exports map and details about an import path, adds the entry.\n */\nexport async function addExportsMapEntry(\n options: AddExportsMapEntryOptions,\n context: { packages: PackageDefinitionsCache; config: Pick<CloudpackConfig, 'features'> },\n): Promise<boolean> {\n const { exports, packagePath, environmentCondition, requestCondition } = options;\n const importPath = normalizeRelativePath(options.importPath);\n const { filePath, sourcePath } = await findFileInPackage(\n {\n packagePath,\n filePath: options.filePath || options.importPath || '',\n },\n context,\n );\n\n // Only do work if a file path was found.\n if (!filePath) {\n return false;\n }\n\n // Create a local for casting.\n const localExports = exports as Record<string, string | Record<string, string | Record<string, string>>>;\n let exportValue: string | Record<string, string>;\n\n // If this is the only entry we're adding, set it to a string to minimize the exports map.\n if (!sourcePath && !requestCondition) {\n exportValue = filePath;\n } else {\n exportValue = {};\n\n if (sourcePath) {\n exportValue['source'] = sourcePath;\n }\n\n // Add the entry for the condition.\n exportValue[requestCondition || 'default'] = filePath;\n }\n\n localExports[importPath] = environmentCondition ? { [environmentCondition]: exportValue } : exportValue;\n\n return true;\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"createExportsMap.d.ts","sourceRoot":"","sources":["../src/createExportsMap.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,uBAAuB,EAAE,kBAAkB,EAAE,MAAM,4BAA4B,CAAC;AAI/G;;GAEG;AACH,wBAAsB,gBAAgB,CACpC,OAAO,EAAE;IACP,WAAW,EAAE,MAAM,CAAC;IACpB,iBAAiB,CAAC,EAAE,OAAO,CAAC;CAC7B,EACD,OAAO,EAAE;IAAE,QAAQ,EAAE,uBAAuB,CAAC;IAAC,MAAM,EAAE,IAAI,CAAC,eAAe,EAAE,UAAU,CAAC,CAAA;CAAE,GACxF,OAAO,CAAC,kBAAkB,CAAC,
|
|
1
|
+
{"version":3,"file":"createExportsMap.d.ts","sourceRoot":"","sources":["../src/createExportsMap.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,uBAAuB,EAAE,kBAAkB,EAAE,MAAM,4BAA4B,CAAC;AAI/G;;GAEG;AACH,wBAAsB,gBAAgB,CACpC,OAAO,EAAE;IACP,WAAW,EAAE,MAAM,CAAC;IACpB,iBAAiB,CAAC,EAAE,OAAO,CAAC;CAC7B,EACD,OAAO,EAAE;IAAE,QAAQ,EAAE,uBAAuB,CAAC;IAAC,MAAM,EAAE,IAAI,CAAC,eAAe,EAAE,UAAU,CAAC,CAAA;CAAE,GACxF,OAAO,CAAC,kBAAkB,CAAC,CAgG7B"}
|
package/lib/createExportsMap.js
CHANGED
|
@@ -11,16 +11,14 @@ export async function createExportsMap(options, context) {
|
|
|
11
11
|
if (definition.exports) {
|
|
12
12
|
return definition.exports;
|
|
13
13
|
}
|
|
14
|
-
const { browser, main, module,
|
|
14
|
+
const { browser, main, module, type } = definition;
|
|
15
15
|
const exports = {};
|
|
16
|
-
const typesPath = types || typings;
|
|
17
16
|
// Only try to add `index.js` as an entry if main/module/browser isn't available.
|
|
18
17
|
if (!(main || module || browser)) {
|
|
19
18
|
await addExportsMapEntry({
|
|
20
19
|
exports,
|
|
21
20
|
packagePath,
|
|
22
21
|
filePath: 'index.js',
|
|
23
|
-
typesPath,
|
|
24
22
|
requestCondition: type === 'module' ? 'import' : undefined,
|
|
25
23
|
}, context);
|
|
26
24
|
}
|
|
@@ -29,7 +27,6 @@ export async function createExportsMap(options, context) {
|
|
|
29
27
|
exports,
|
|
30
28
|
packagePath,
|
|
31
29
|
filePath: main,
|
|
32
|
-
typesPath,
|
|
33
30
|
requestCondition: type === 'module' ? 'import' : undefined,
|
|
34
31
|
}, context);
|
|
35
32
|
}
|
|
@@ -38,7 +35,6 @@ export async function createExportsMap(options, context) {
|
|
|
38
35
|
exports,
|
|
39
36
|
packagePath,
|
|
40
37
|
filePath: module,
|
|
41
|
-
typesPath,
|
|
42
38
|
requestCondition: 'import',
|
|
43
39
|
}, context);
|
|
44
40
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"createExportsMap.js","sourceRoot":"","sources":["../src/createExportsMap.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,qBAAqB,EAAE,MAAM,mCAAmC,CAAC;AAC1E,OAAO,EAAE,kBAAkB,EAAE,MAAM,yBAAyB,CAAC;AAE7D;;GAEG;AACH,MAAM,CAAC,KAAK,UAAU,gBAAgB,CACpC,OAGC,EACD,OAAyF;IAEzF,MAAM,EAAE,WAAW,EAAE,GAAG,OAAO,CAAC;IAChC,MAAM,EAAE,QAAQ,E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e,IAAI,GAAG,CAAC,QAAQ,CAAC,KAAK,CAAC,EAAE,CAAC;oBAC5C,WAAW,CAAC,IAAI,CAAC,GAAG,CAAC,OAAO,CAAC,OAAO,EAAE,EAAE,CAAC,CAAC,CAAC;gBAC7C,CAAC;gBAED,KAAK,MAAM,UAAU,IAAI,WAAW,EAAE,CAAC;oBACrC,MAAM,kBAAkB,CACtB;wBACE,OAAO;wBACP,WAAW;wBACX,UAAU;wBACV,QAAQ,EAAE,KAAK;wBACf,gBAAgB,EAAE,SAAS;qBAC5B,EACD,OAAO,CACR,CAAC;gBACJ,CAAC;YACH,CAAC;QACH,CAAC;IACH,CAAC;IAED,qEAAqE;IACrE,+CAA+C;IAC/C,mEAAmE;IACnE,IAAI,MAAM,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;QACtC,CAAC,MAAM,kBAAkB,CAAC,EAAE,OAAO,EAAE,WAAW,EAAE,QAAQ,EAAE,gBAAgB,EAAE,EAAE,OAAO,CAAC,CAAC;YACvF,CAAC,MAAM,kBAAkB,CAAC,EAAE,OAAO,EAAE,WAAW,EAAE,QAAQ,EAAE,eAAe,EAAE,EAAE,OAAO,CAAC,CAAC;YACxF,CAAC,MAAM,kBAAkB,CAAC,EAAE,OAAO,EAAE,WAAW,EAAE,QAAQ,EAAE,YAAY,EAAE,EAAE,OAAO,CAAC,CAAC,CAAC;IAC1F,CAAC;IAED,OAAO,OAAO,CAAC;AACjB,CAAC","sourcesContent":["import type { CloudpackConfig, PackageDefinitionsCache, PackageJsonExports } from '@ms-cloudpack/common-types';\nimport { normalizeRelativePath } from '@ms-cloudpack/path-string-parsing';\nimport { addExportsMapEntry } from './addExportsMapEntry.js';\n\n/**\n * Given a package path, generates an export map for the package.\n */\nexport async function createExportsMap(\n options: {\n packagePath: string;\n disableTransforms?: boolean;\n },\n context: { packages: PackageDefinitionsCache; config: Pick<CloudpackConfig, 'features'> },\n): Promise<PackageJsonExports> {\n const { packagePath } = options;\n const { packages } = context;\n const definition = await packages.get(packagePath, { disableTransforms: options.disableTransforms });\n\n // Don't create an exports map for a definition that already has one.\n if (definition.exports) {\n return definition.exports;\n }\n\n const { browser, main, module, type } = definition;\n const exports = {};\n\n // Only try to add `index.js` as an entry if main/module/browser isn't available.\n if (!(main || module || browser)) {\n await addExportsMapEntry(\n {\n exports,\n packagePath,\n filePath: 'index.js',\n requestCondition: type === 'module' ? 'import' : undefined,\n },\n context,\n );\n }\n\n if (main) {\n await addExportsMapEntry(\n {\n exports,\n packagePath,\n filePath: main,\n requestCondition: type === 'module' ? 'import' : undefined,\n },\n context,\n );\n }\n\n if (module) {\n await addExportsMapEntry(\n {\n exports,\n packagePath,\n filePath: module,\n requestCondition: 'import',\n },\n context,\n );\n }\n\n if (browser) {\n if (typeof definition.browser === 'string') {\n await addExportsMapEntry(\n { exports, packagePath, filePath: definition.browser, requestCondition: 'browser' },\n context,\n );\n } else if (typeof definition.browser === 'object') {\n for (const [key, value] of Object.entries(definition.browser)) {\n if (!value || typeof value !== 'string') {\n continue;\n }\n\n const isDefaultImport = normalizeRelativePath(module || main) === normalizeRelativePath(key);\n\n const importPaths = isDefaultImport ? ['.'] : [key];\n\n if (!isDefaultImport && key.endsWith('.js')) {\n importPaths.push(key.replace(/\\.js$/, ''));\n }\n\n for (const importPath of importPaths) {\n await addExportsMapEntry(\n {\n exports,\n packagePath,\n importPath,\n filePath: value,\n requestCondition: 'browser',\n },\n context,\n );\n }\n }\n }\n }\n\n // If we couldn't infer the exports map shape from existing metadata,\n // formulate based off inferred file structure.\n // Note: CRA defaults to src/index.js, Vite defaults to src/main.js\n if (Object.keys(exports).length === 0) {\n (await addExportsMapEntry({ exports, packagePath, filePath: './lib/index.js' }, context)) ||\n (await addExportsMapEntry({ exports, packagePath, filePath: './lib/main.js' }, context)) ||\n (await addExportsMapEntry({ exports, packagePath, filePath: './index.js' }, context));\n }\n\n return exports;\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"findFileInPackage.d.ts","sourceRoot":"","sources":["../src/findFileInPackage.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,uBAAuB,EAAE,MAAM,4BAA4B,CAAC;AAY3F,MAAM,MAAM,wBAAwB,GAAG;IACrC,WAAW,EAAE,MAAM,CAAC;IACpB,QAAQ,EAAE,MAAM,CAAC;CAClB,CAAC;AAEF,MAAM,MAAM,uBAAuB,GAAG;IACpC,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,
|
|
1
|
+
{"version":3,"file":"findFileInPackage.d.ts","sourceRoot":"","sources":["../src/findFileInPackage.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,uBAAuB,EAAE,MAAM,4BAA4B,CAAC;AAY3F,MAAM,MAAM,wBAAwB,GAAG;IACrC,WAAW,EAAE,MAAM,CAAC;IACpB,QAAQ,EAAE,MAAM,CAAC;CAClB,CAAC;AAEF,MAAM,MAAM,uBAAuB,GAAG;IACpC,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,UAAU,CAAC,EAAE,MAAM,CAAC;CACrB,CAAC;AAEF;;;;;;;;;GASG;AACH,wBAAsB,iBAAiB,CACrC,OAAO,EAAE,wBAAwB,EACjC,OAAO,EAAE;IAAE,QAAQ,EAAE,uBAAuB,CAAC;IAAC,MAAM,EAAE,IAAI,CAAC,eAAe,EAAE,UAAU,CAAC,CAAA;CAAE,GACxF,OAAO,CAAC,uBAAuB,CAAC,CAqFlC"}
|
package/lib/findFileInPackage.js
CHANGED
|
@@ -22,7 +22,6 @@ export async function findFileInPackage(options, context) {
|
|
|
22
22
|
const packagePath = slash(options.packagePath);
|
|
23
23
|
let filePath;
|
|
24
24
|
let sourcePath;
|
|
25
|
-
let typesPath;
|
|
26
25
|
const isInternal = !isExternalPackage(packagePath);
|
|
27
26
|
const pathsToConsider = [originalPath];
|
|
28
27
|
const definition = await context.packages.tryGet(packagePath, { disableTransforms: true });
|
|
@@ -51,14 +50,10 @@ export async function findFileInPackage(options, context) {
|
|
|
51
50
|
const exportsMap = await getExportsMap({ packagePath: nestedDefinitionPath }, context);
|
|
52
51
|
const entryPath = flattenExportsMap(exportsMap)['.'];
|
|
53
52
|
if (entryPath) {
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
filePath: normalizeRelativePath(path.relative(packagePath, path.join(nestedDefinitionPath, entryPath))),
|
|
59
|
-
}, context)),
|
|
60
|
-
typesPath: typesPath && normalizeRelativePath(path.relative(packagePath, path.join(nestedDefinitionPath, typesPath))),
|
|
61
|
-
};
|
|
53
|
+
return findFileInPackage({
|
|
54
|
+
packagePath,
|
|
55
|
+
filePath: normalizeRelativePath(path.relative(packagePath, path.join(nestedDefinitionPath, entryPath))),
|
|
56
|
+
}, context);
|
|
62
57
|
}
|
|
63
58
|
else {
|
|
64
59
|
// If we can't find an entry, we should not include this in the exports map.
|
|
@@ -84,16 +79,6 @@ export async function findFileInPackage(options, context) {
|
|
|
84
79
|
}
|
|
85
80
|
}
|
|
86
81
|
}
|
|
87
|
-
// Try to resolve the typesPath
|
|
88
|
-
if (sourcePath && filePath) {
|
|
89
|
-
typesPath = filePath.replace(/\.js$/, '.d.ts');
|
|
90
|
-
if (!isInternal && !isFileSync(path.join(packagePath, typesPath))) {
|
|
91
|
-
typesPath = undefined;
|
|
92
|
-
}
|
|
93
|
-
}
|
|
94
|
-
if (typesPath) {
|
|
95
|
-
result.typesPath = normalizeRelativePath(typesPath);
|
|
96
|
-
}
|
|
97
82
|
if (filePath) {
|
|
98
83
|
result.filePath = normalizeRelativePath(filePath);
|
|
99
84
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"findFileInPackage.js","sourceRoot":"","sources":["../src/findFileInPackage.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,qBAAqB,EAAE,KAAK,EAAE,MAAM,mCAAmC,CAAC;AACjF,OAAO,EAAE,wBAAwB,EAAE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eAAe,EAAE,CAAC;YACpB,wDAAwD;YACxD,UAAU,GAAG,wBAAwB,CAAC,QAAQ,EAAE,WAAW,CAAC,CAAC;YAE7D,mDAAmD;YACnD,IAAI,UAAU,KAAK,QAAQ,EAAE,CAAC;gBAC5B,UAAU,GAAG,SAAS,CAAC;YACzB,CAAC;QACH,CAAC;IACH,CAAC;IAED,IAAI,QAAQ,EAAE,CAAC;QACb,MAAM,CAAC,QAAQ,GAAG,qBAAqB,CAAC,QAAQ,CAAC,CAAC;IACpD,CAAC;IAED,IAAI,UAAU,EAAE,CAAC;QACf,MAAM,CAAC,UAAU,GAAG,qBAAqB,CAAC,UAAU,CAAC,CAAC;IACxD,CAAC;IAED,OAAO,MAAM,CAAC;AAChB,CAAC","sourcesContent":["import type { CloudpackConfig, PackageDefinitionsCache } from '@ms-cloudpack/common-types';\nimport { normalizeRelativePath, slash } from '@ms-cloudpack/path-string-parsing';\nimport { intermediateToSourcePath, isFileSync, sourceToIntermediatePath } from '@ms-cloudpack/path-utilities';\nimport path from 'path';\nimport { flattenExportsMap } from './flattenExportsMap.js';\nimport { getCandidates } from './getCandidates.js';\nimport { getExportsMap } from './getExportsMap.js';\nimport { isExternalPackage } from './isExternalPackage.js';\n\nconst sourceExtensions = ['.ts', '.tsx', '.cts', '.mts', '.jsx'];\nconst javascriptExtensions = ['.js', '.mjs', '.cjs'];\n\nexport type FindFileInPackageOptions = {\n packagePath: string;\n filePath: string;\n};\n\nexport type FindFileInPackageResult = {\n filePath?: string;\n sourcePath?: string;\n};\n\n/**\n * Given a requested partial filePath, resolves the relative intermediate path if the file exists, with special\n * consideration for internal packages, which may not have intermediate files but only source files. Paths returned\n * are always relative and start with `./`.\n *\n * This helper is used in deriving if the given package.json entries are actual validate candidates when constructing an\n * exports map from existing metadata. For example, a package.json may list `main` as `lib/index.js`. If this file\n * exists, or in internal packages, if `src/index.tsx` exists, then this is a valid candidate. If the file does not\n * exist, then we should not include it in the exports map.\n */\nexport async function findFileInPackage(\n options: FindFileInPackageOptions,\n context: { packages: PackageDefinitionsCache; config: Pick<CloudpackConfig, 'features'> },\n): Promise<FindFileInPackageResult> {\n const originalPath = normalizeRelativePath(options.filePath);\n const packagePath = slash(options.packagePath);\n let filePath: string | undefined;\n let sourcePath: string | undefined;\n const isInternal = !isExternalPackage(packagePath);\n const pathsToConsider = [originalPath];\n\n const definition = await context.packages.tryGet(packagePath, { disableTransforms: true });\n // If the original package.json has an exports map, we should not use main and module as hints.\n if (originalPath === '.' && definition && !definition.exports) {\n const { main, module } = definition;\n if (main) {\n pathsToConsider.unshift(main);\n }\n if (module) {\n pathsToConsider.unshift(module);\n }\n }\n\n for (const currentPath of pathsToConsider) {\n const candidates = await getCandidates({ filePath: currentPath, packagePath }, context);\n\n // Try and resolve a physical file given the candidates.\n filePath = candidates.find((candidate) => isFileSync(path.join(packagePath, candidate)));\n if (filePath) {\n break;\n }\n }\n\n const isNestedPackageDefinition =\n filePath && path.basename(filePath) === 'package.json' && path.basename(originalPath) !== 'package.json';\n const result: FindFileInPackageResult = {};\n\n if (isNestedPackageDefinition) {\n const nestedDefinitionPath = path.dirname(path.join(packagePath, filePath as string));\n const exportsMap = await getExportsMap({ packagePath: nestedDefinitionPath }, context);\n const entryPath = flattenExportsMap(exportsMap)['.'];\n\n if (entryPath) {\n return findFileInPackage(\n {\n packagePath,\n filePath: normalizeRelativePath(path.relative(packagePath, path.join(nestedDefinitionPath, entryPath))),\n },\n context,\n );\n } else {\n // If we can't find an entry, we should not include this in the exports map.\n // This avoids adding a \"./package.json\" value to a \".\" entry.\n return result;\n }\n }\n\n // If the resolved file is a typescript file in an internal package, try to resolve the intermediate.\n if (filePath && sourceExtensions.includes(path.extname(filePath))) {\n sourcePath = filePath;\n filePath = isInternal ? sourceToIntermediatePath(filePath) : undefined;\n }\n\n // If we haven't resolved a sourcePath, try to resolve it from the intermediate.\n if (isInternal && filePath && !sourcePath) {\n const ext = path.extname(filePath);\n const isJavaScriptExt = javascriptExtensions.includes(ext);\n\n if (isJavaScriptExt) {\n // Not a TS file, but a JS file. Try to find the source.\n sourcePath = intermediateToSourcePath(filePath, packagePath);\n\n // If we couldn't find a TS file, clear sourcePath.\n if (sourcePath === filePath) {\n sourcePath = undefined;\n }\n }\n }\n\n if (filePath) {\n result.filePath = normalizeRelativePath(filePath);\n }\n\n if (sourcePath) {\n result.sourcePath = normalizeRelativePath(sourcePath);\n }\n\n return result;\n}\n"]}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { PackageDefinitionTransform } from '@ms-cloudpack/common-types';
|
|
2
|
+
/**
|
|
3
|
+
* `@types/` dependencies should never be relevant for Cloudpack's purposes, so move them from
|
|
4
|
+
* `dependencies` or `peerDependencies` to `devDependencies` so they're not processed by default.
|
|
5
|
+
*/
|
|
6
|
+
export declare function getTypesTransform(): PackageDefinitionTransform;
|
|
7
|
+
//# sourceMappingURL=getTypesTransform.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"getTypesTransform.d.ts","sourceRoot":"","sources":["../src/getTypesTransform.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,0BAA0B,EAAe,MAAM,4BAA4B,CAAC;AAK1F;;;GAGG;AACH,wBAAgB,iBAAiB,IAAI,0BAA0B,CA6B9D"}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
const depTypes = ['dependencies', 'peerDependencies', 'devDependencies', 'optionalDependencies'];
|
|
2
|
+
/**
|
|
3
|
+
* `@types/` dependencies should never be relevant for Cloudpack's purposes, so move them from
|
|
4
|
+
* `dependencies` or `peerDependencies` to `devDependencies` so they're not processed by default.
|
|
5
|
+
*/
|
|
6
|
+
export function getTypesTransform() {
|
|
7
|
+
return ({ definition }) => {
|
|
8
|
+
let transformedDefinition;
|
|
9
|
+
for (const depType of ['dependencies', 'peerDependencies']) {
|
|
10
|
+
const deps = definition[depType];
|
|
11
|
+
if (!deps) {
|
|
12
|
+
continue;
|
|
13
|
+
}
|
|
14
|
+
for (const depName of Object.keys(deps)) {
|
|
15
|
+
if (!depName.startsWith('@types/')) {
|
|
16
|
+
continue;
|
|
17
|
+
}
|
|
18
|
+
const depVersion = deps[depName];
|
|
19
|
+
transformedDefinition ??= {
|
|
20
|
+
...definition,
|
|
21
|
+
devDependencies: { ...definition.devDependencies },
|
|
22
|
+
[depType]: { ...deps },
|
|
23
|
+
};
|
|
24
|
+
delete transformedDefinition[depType]?.[depName];
|
|
25
|
+
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
26
|
+
transformedDefinition.devDependencies[depName] = depVersion;
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
return transformedDefinition;
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
//# sourceMappingURL=getTypesTransform.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"getTypesTransform.js","sourceRoot":"","sources":["../src/getTypesTransform.ts"],"names":[],"mappings":"AAEA,MAAM,QAAQ,GAAG,CAAC,cAAc,EAAE,kBAAkB,EAAE,iBAAiB,EAAE,sBAAsB,CAAU,CAAC;AAG1G;;;GAGG;AACH,MAAM,UAAU,iBAAiB;IAC/B,OAAO,CAAC,EAAE,UAAU,EAAE,EAAE,EAAE;QACxB,IAAI,qBAA8C,CAAC;QAEnD,KAAK,MAAM,OAAO,IAAI,CAAC,cAAc,EAAE,kBAAkB,CAAU,EAAE,CAAC;YACpE,MAAM,IAAI,GAAG,UAAU,CAAC,OAAO,CAAC,CAAC;YACjC,IAAI,CAAC,IAAI,EAAE,CAAC;gBACV,SAAS;YACX,CAAC;YAED,KAAK,MAAM,OAAO,IAAI,MAAM,CAAC,IAAI,CAAC,IAAI,CAAc,EAAE,CAAC;gBACrD,IAAI,CAAC,OAAO,CAAC,UAAU,CAAC,SAAS,CAAC,EAAE,CAAC;oBACnC,SAAS;gBACX,CAAC;gBAED,MAAM,UAAU,GAAG,IAAI,CAAC,OAAO,CAAC,CAAC;gBACjC,qBAAqB,KAAK;oBACxB,GAAG,UAAU;oBACb,eAAe,EAAE,EAAE,GAAG,UAAU,CAAC,eAAe,EAAE;oBAClD,CAAC,OAAO,CAAC,EAAE,EAAE,GAAG,IAAI,EAAE;iBACvB,CAAC;gBACF,OAAO,qBAAqB,CAAC,OAAO,CAAC,EAAE,CAAC,OAAO,CAAC,CAAC;gBACjD,oEAAoE;gBACpE,qBAAqB,CAAC,eAAgB,CAAC,OAAO,CAAC,GAAG,UAAU,CAAC;YAC/D,CAAC;QACH,CAAC;QAED,OAAO,qBAAqB,CAAC;IAC/B,CAAC,CAAC;AACJ,CAAC","sourcesContent":["import type { PackageDefinitionTransform, PackageJson } from '@ms-cloudpack/common-types';\n\nconst depTypes = ['dependencies', 'peerDependencies', 'devDependencies', 'optionalDependencies'] as const;\ntype DepType = (typeof depTypes)[number];\n\n/**\n * `@types/` dependencies should never be relevant for Cloudpack's purposes, so move them from\n * `dependencies` or `peerDependencies` to `devDependencies` so they're not processed by default.\n */\nexport function getTypesTransform(): PackageDefinitionTransform {\n return ({ definition }) => {\n let transformedDefinition: PackageJson | undefined;\n\n for (const depType of ['dependencies', 'peerDependencies'] as const) {\n const deps = definition[depType];\n if (!deps) {\n continue;\n }\n\n for (const depName of Object.keys(deps) as DepType[]) {\n if (!depName.startsWith('@types/')) {\n continue;\n }\n\n const depVersion = deps[depName];\n transformedDefinition ??= {\n ...definition,\n devDependencies: { ...definition.devDependencies },\n [depType]: { ...deps },\n };\n delete transformedDefinition[depType]?.[depName];\n // eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n transformedDefinition.devDependencies![depName] = depVersion;\n }\n }\n\n return transformedDefinition;\n };\n}\n"]}
|
package/lib/tsdoc-metadata.json
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ms-cloudpack/package-utilities",
|
|
3
|
-
"version": "10.
|
|
3
|
+
"version": "10.2.0",
|
|
4
4
|
"description": "Utilities for resolving/parsing packages and their imports.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"type": "module",
|
|
@@ -14,11 +14,11 @@
|
|
|
14
14
|
}
|
|
15
15
|
},
|
|
16
16
|
"dependencies": {
|
|
17
|
-
"@ms-cloudpack/common-types": "^0.
|
|
17
|
+
"@ms-cloudpack/common-types": "^0.21.0",
|
|
18
18
|
"@ms-cloudpack/json-utilities": "^0.1.7",
|
|
19
|
-
"@ms-cloudpack/package-overrides": "^0.9.
|
|
19
|
+
"@ms-cloudpack/package-overrides": "^0.9.32",
|
|
20
20
|
"@ms-cloudpack/path-string-parsing": "^1.2.4",
|
|
21
|
-
"@ms-cloudpack/path-utilities": "^2.7.
|
|
21
|
+
"@ms-cloudpack/path-utilities": "^2.7.46",
|
|
22
22
|
"@ms-cloudpack/task-reporter": "^0.14.5",
|
|
23
23
|
"acorn": "^8.11.2",
|
|
24
24
|
"acorn-walk": "^8.2.1",
|