@ms-cloudpack/package-utilities 5.0.1 → 5.1.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.
@@ -1,18 +1,20 @@
1
1
  import type { PackageJson, PackageDefinitionTransform, PackageDefinitionsCache } from '@ms-cloudpack/bundler-types';
2
2
  export declare class PackageDefinitions implements PackageDefinitionsCache {
3
- private _cache;
3
+ private _definitions;
4
+ private _transformedDefinitions;
4
5
  private _config;
5
6
  private _transforms;
6
7
  private _transformFactories;
7
8
  /**
8
9
  * Constructor for PackageDefinitions.
9
- * @param definitionMap - The map of package paths to package definitions, used mainly for testing.
10
+ * @param definitionCache - The map of package paths to package definitions, used mainly for testing.
10
11
  * @param config - The optional config object to pass to transforms. When `reset` is called with a new value, the
11
12
  * transforms will be re-created using the new config.
12
13
  */
13
- constructor(definitionMap?: Record<string, PackageJson>, config?: unknown);
14
+ constructor(definitionCache?: Record<string, PackageJson>, config?: unknown);
14
15
  get(packagePath: string, options?: {
15
- refresh: boolean;
16
+ refresh?: boolean;
17
+ disableTransforms?: boolean;
16
18
  }): Promise<PackageJson | undefined>;
17
19
  /**
18
20
  * Registers a transform factory function, which will be called on initialization, and when reset, to re-generate
@@ -1 +1 @@
1
- {"version":3,"file":"PackageDefinitions.d.ts","sourceRoot":"","sources":["../src/PackageDefinitions.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,WAAW,EAAE,0BAA0B,EAAE,uBAAuB,EAAE,MAAM,6BAA6B,CAAC;AAEpH,qBAAa,kBAAmB,YAAW,uBAAuB;IAChE,OAAO,CAAC,MAAM,CAA8B;IAC5C,OAAO,CAAC,OAAO,CAAU;IACzB,OAAO,CAAC,WAAW,CAAoC;IACvD,OAAO,CAAC,mBAAmB,CAAuD;IAElF;;;;;OAKG;gBACS,aAAa,GAAE,MAAM,CAAC,MAAM,EAAE,WAAW,CAAM,EAAE,MAAM,CAAC,EAAE,OAAO;IAOvE,GAAG,CAAC,WAAW,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE;QAAE,OAAO,EAAE,OAAO,CAAA;KAAE,GAAG,OAAO,CAAC,WAAW,GAAG,SAAS,CAAC;IAuBhG;;;;OAIG;IACH,iBAAiB,CAAC,OAAO,EAAE,CAAC,MAAM,CAAC,EAAE,OAAO,KAAK,0BAA0B;IAO3E;;OAEG;IACH,KAAK,CAAC,OAAO,CAAC,EAAE;QAAE,SAAS,CAAC,EAAE,OAAO,CAAA;KAAE;CAUxC"}
1
+ {"version":3,"file":"PackageDefinitions.d.ts","sourceRoot":"","sources":["../src/PackageDefinitions.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,WAAW,EAAE,0BAA0B,EAAE,uBAAuB,EAAE,MAAM,6BAA6B,CAAC;AAEpH,qBAAa,kBAAmB,YAAW,uBAAuB;IAChE,OAAO,CAAC,YAAY,CAA8B;IAClD,OAAO,CAAC,uBAAuB,CAA8B;IAC7D,OAAO,CAAC,OAAO,CAAU;IACzB,OAAO,CAAC,WAAW,CAAoC;IACvD,OAAO,CAAC,mBAAmB,CAAuD;IAElF;;;;;OAKG;gBACS,eAAe,GAAE,MAAM,CAAC,MAAM,EAAE,WAAW,CAAM,EAAE,MAAM,CAAC,EAAE,OAAO;IAQzE,GAAG,CACP,WAAW,EAAE,MAAM,EACnB,OAAO,CAAC,EAAE;QAAE,OAAO,CAAC,EAAE,OAAO,CAAC;QAAC,iBAAiB,CAAC,EAAE,OAAO,CAAA;KAAE,GAC3D,OAAO,CAAC,WAAW,GAAG,SAAS,CAAC;IAwCnC;;;;OAIG;IACH,iBAAiB,CAAC,OAAO,EAAE,CAAC,MAAM,CAAC,EAAE,OAAO,KAAK,0BAA0B;IAO3E;;OAEG;IACH,KAAK,CAAC,OAAO,CAAC,EAAE;QAAE,SAAS,CAAC,EAAE,OAAO,CAAA;KAAE;CAWxC"}
@@ -4,33 +4,48 @@ import { readJson } from '@ms-cloudpack/json-utilities';
4
4
  export class PackageDefinitions {
5
5
  /**
6
6
  * Constructor for PackageDefinitions.
7
- * @param definitionMap - The map of package paths to package definitions, used mainly for testing.
7
+ * @param definitionCache - The map of package paths to package definitions, used mainly for testing.
8
8
  * @param config - The optional config object to pass to transforms. When `reset` is called with a new value, the
9
9
  * transforms will be re-created using the new config.
10
10
  */
11
- constructor(definitionMap = {}, config) {
11
+ constructor(definitionCache = {}, config) {
12
12
  this._transforms = [];
13
- this._cache = definitionMap;
13
+ this._definitions = definitionCache;
14
+ this._transformedDefinitions = {};
14
15
  this._config = config;
15
16
  this._transforms = [applyOverrides];
16
17
  this._transformFactories = [];
17
18
  }
18
19
  async get(packagePath, options) {
19
- let existingDefinition = this._cache[packagePath];
20
- if (!existingDefinition || options?.refresh) {
21
- try {
22
- // Load the package and apply transforms.
23
- const definition = await readJson(path.join(packagePath, 'package.json'));
24
- // If we have loaded a definition, apply transforms and cache/return the result.
25
- if (definition) {
26
- existingDefinition = this._cache[packagePath] = this._transforms.reduce((def, transform) => transform(def) || def, definition);
27
- }
20
+ let definition = this._definitions[packagePath];
21
+ let transformedDefinition = this._transformedDefinitions[packagePath];
22
+ const { refresh, disableTransforms } = options || {};
23
+ // If we already have the answer they need, return immediately.
24
+ if (!refresh) {
25
+ if (disableTransforms && definition) {
26
+ return definition;
28
27
  }
29
- catch (e) {
30
- /* no-op */
28
+ if (!disableTransforms && transformedDefinition) {
29
+ return transformedDefinition;
31
30
  }
32
31
  }
33
- return existingDefinition;
32
+ // If we don't have the definition, try to load it.
33
+ if (!definition || refresh) {
34
+ definition = await readJson(path.join(packagePath, 'package.json'));
35
+ if (!definition) {
36
+ return undefined;
37
+ }
38
+ this._definitions[packagePath] = definition;
39
+ }
40
+ // If we don't want to skip the transform, transform the definition.
41
+ if (!disableTransforms && (!transformedDefinition || refresh)) {
42
+ for (const transform of this._transforms) {
43
+ transformedDefinition =
44
+ (await transform(transformedDefinition || definition, packagePath, this)) || transformedDefinition;
45
+ }
46
+ this._transformedDefinitions[packagePath] = transformedDefinition;
47
+ }
48
+ return (!disableTransforms && transformedDefinition) || definition;
34
49
  }
35
50
  /**
36
51
  * Registers a transform factory function, which will be called on initialization, and when reset, to re-generate
@@ -46,7 +61,8 @@ export class PackageDefinitions {
46
61
  * Resets the cache of package definitions. This is useful when testing, to ensure that the cache is empty.
47
62
  */
48
63
  reset(options) {
49
- this._cache = {};
64
+ this._definitions = {};
65
+ this._transformedDefinitions = {};
50
66
  const { newConfig } = options || {};
51
67
  if (newConfig) {
52
68
  this._config = newConfig;
@@ -1 +1 @@
1
- {"version":3,"file":"PackageDefinitions.js","sourceRoot":"","sources":["../src/PackageDefinitions.ts"],"names":[],"mappings":"AAAA,OAAO,IAAI,MAAM,MAAM,CAAC;AACxB,OAAO,EAAE,cAAc,EAAE,MAAM,iCAAiC,CAAC;AACjE,OAAO,EAAE,QAAQ,EAAE,MAAM,8BAA8B,CAAC;AAGxD,MAAM,OAAO,kBAAkB;IAM7B;;;;;OAKG;IACH,YAAY,gBAA6C,EAAE,EAAE,MAAgB;QATrE,gBAAW,GAAiC,EAAE,CAAC;QAUrD,IAAI,CAAC,MAAM,GAAG,aAAa,CAAC;QAC5B,IAAI,CAAC,OAAO,GAAG,MAAM,CAAC;QACtB,IAAI,CAAC,WAAW,GAAG,CAAC,cAAc,CAAC,CAAC;QACpC,IAAI,CAAC,mBAAmB,GAAG,EAAE,CAAC;IAChC,CAAC;IAED,KAAK,CAAC,GAAG,CAAC,WAAmB,EAAE,OAA8B;QAC3D,IAAI,kBAAkB,GAAG,IAAI,CAAC,MAAM,CAAC,WAAW,CAAC,CAAC;QAElD,IAAI,CAAC,kBAAkB,IAAI,OAAO,EAAE,OAAO,EAAE;YAC3C,IAAI;gBACF,yCAAyC;gBACzC,MAAM,UAAU,GAA4B,MAAM,QAAQ,CAAC,IAAI,CAAC,IAAI,CAAC,WAAW,EAAE,cAAc,CAAC,CAAC,CAAC;gBAEnG,gFAAgF;gBAChF,IAAI,UAAU,EAAE;oBACd,kBAAkB,GAAG,IAAI,CAAC,MAAM,CAAC,WAAW,CAAC,GAAG,IAAI,CAAC,WAAW,CAAC,MAAM,CACrE,CAAC,GAAG,EAAE,SAAS,EAAE,EAAE,CAAC,SAAS,CAAC,GAAG,CAAC,IAAI,GAAG,EACzC,UAAU,CACX,CAAC;iBACH;aACF;YAAC,OAAO,CAAC,EAAE;gBACV,WAAW;aACZ;SACF;QAED,OAAO,kBAAkB,CAAC;IAC5B,CAAC;IAED;;;;OAIG;IACH,iBAAiB,CAAC,OAAyD;QACzE,IAAI,CAAC,mBAAmB,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;QACvC,IAAI,CAAC,WAAW,CAAC,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC,CAAC;QAE7C,IAAI,CAAC,KAAK,EAAE,CAAC;IACf,CAAC;IAED;;OAEG;IACH,KAAK,CAAC,OAAiC;QACrC,IAAI,CAAC,MAAM,GAAG,EAAE,CAAC;QAEjB,MAAM,EAAE,SAAS,EAAE,GAAG,OAAO,IAAI,EAAE,CAAC;QAEpC,IAAI,SAAS,EAAE;YACb,IAAI,CAAC,OAAO,GAAG,SAAS,CAAC;YACzB,IAAI,CAAC,WAAW,GAAG,CAAC,cAAc,EAAE,GAAG,IAAI,CAAC,mBAAmB,CAAC,GAAG,CAAC,CAAC,OAAO,EAAE,EAAE,CAAC,OAAO,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC;SACvG;IACH,CAAC;CACF","sourcesContent":["import path from 'path';\nimport { applyOverrides } from '@ms-cloudpack/package-overrides';\nimport { readJson } from '@ms-cloudpack/json-utilities';\nimport type { PackageJson, PackageDefinitionTransform, PackageDefinitionsCache } from '@ms-cloudpack/bundler-types';\n\nexport class PackageDefinitions implements PackageDefinitionsCache {\n private _cache: Record<string, PackageJson>;\n private _config: unknown;\n private _transforms: PackageDefinitionTransform[] = [];\n private _transformFactories: ((config?: unknown) => PackageDefinitionTransform)[];\n\n /**\n * Constructor for PackageDefinitions.\n * @param definitionMap - 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(definitionMap: Record<string, PackageJson> = {}, config?: unknown) {\n this._cache = definitionMap;\n this._config = config;\n this._transforms = [applyOverrides];\n this._transformFactories = [];\n }\n\n async get(packagePath: string, options?: { refresh: boolean }): Promise<PackageJson | undefined> {\n let existingDefinition = this._cache[packagePath];\n\n if (!existingDefinition || options?.refresh) {\n try {\n // Load the package and apply transforms.\n const definition: PackageJson | undefined = await readJson(path.join(packagePath, 'package.json'));\n\n // If we have loaded a definition, apply transforms and cache/return the result.\n if (definition) {\n existingDefinition = this._cache[packagePath] = this._transforms.reduce(\n (def, transform) => transform(def) || def,\n definition,\n );\n }\n } catch (e) {\n /* no-op */\n }\n }\n\n return existingDefinition;\n }\n\n /**\n * Registers a transform factory function, which will be called on initialization, and when reset, to re-generate\n * the transform function. Transform functions are called only when the package definition hasn't been loaded before,\n * and the result will be cached. Calling `reset` will reset the cache.\n */\n registerTransform(factory: (config?: unknown) => PackageDefinitionTransform) {\n this._transformFactories.push(factory);\n this._transforms.push(factory(this._config));\n\n this.reset();\n }\n\n /**\n * Resets the cache of package definitions. This is useful when testing, to ensure that the cache is empty.\n */\n reset(options?: { newConfig?: unknown }) {\n this._cache = {};\n\n const { newConfig } = options || {};\n\n if (newConfig) {\n this._config = newConfig;\n this._transforms = [applyOverrides, ...this._transformFactories.map((factory) => factory(newConfig))];\n }\n }\n}\n"]}
1
+ {"version":3,"file":"PackageDefinitions.js","sourceRoot":"","sources":["../src/PackageDefinitions.ts"],"names":[],"mappings":"AAAA,OAAO,IAAI,MAAM,MAAM,CAAC;AACxB,OAAO,EAAE,cAAc,EAAE,MAAM,iCAAiC,CAAC;AACjE,OAAO,EAAE,QAAQ,EAAE,MAAM,8BAA8B,CAAC;AAGxD,MAAM,OAAO,kBAAkB;IAO7B;;;;;OAKG;IACH,YAAY,kBAA+C,EAAE,EAAE,MAA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UAAU,EAAE,WAAW,EAAE,IAAI,CAAC,CAAC,IAAI,qBAAqB,CAAC;aACtG;YAED,IAAI,CAAC,uBAAuB,CAAC,WAAW,CAAC,GAAG,qBAAqB,CAAC;SACnE;QAED,OAAO,CAAC,CAAC,iBAAiB,IAAI,qBAAqB,CAAC,IAAI,UAAU,CAAC;IACrE,CAAC;IAED;;;;OAIG;IACH,iBAAiB,CAAC,OAAyD;QACzE,IAAI,CAAC,mBAAmB,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;QACvC,IAAI,CAAC,WAAW,CAAC,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC,CAAC;QAE7C,IAAI,CAAC,KAAK,EAAE,CAAC;IACf,CAAC;IAED;;OAEG;IACH,KAAK,CAAC,OAAiC;QACrC,IAAI,CAAC,YAAY,GAAG,EAAE,CAAC;QACvB,IAAI,CAAC,uBAAuB,GAAG,EAAE,CAAC;QAElC,MAAM,EAAE,SAAS,EAAE,GAAG,OAAO,IAAI,EAAE,CAAC;QAEpC,IAAI,SAAS,EAAE;YACb,IAAI,CAAC,OAAO,GAAG,SAAS,CAAC;YACzB,IAAI,CAAC,WAAW,GAAG,CAAC,cAAc,EAAE,GAAG,IAAI,CAAC,mBAAmB,CAAC,GAAG,CAAC,CAAC,OAAO,EAAE,EAAE,CAAC,OAAO,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC;SACvG;IACH,CAAC;CACF","sourcesContent":["import path from 'path';\nimport { applyOverrides } from '@ms-cloudpack/package-overrides';\nimport { readJson } from '@ms-cloudpack/json-utilities';\nimport type { PackageJson, PackageDefinitionTransform, PackageDefinitionsCache } from '@ms-cloudpack/bundler-types';\n\nexport class PackageDefinitions implements PackageDefinitionsCache {\n private _definitions: Record<string, PackageJson>;\n private _transformedDefinitions: Record<string, PackageJson>;\n private _config: unknown;\n private _transforms: PackageDefinitionTransform[] = [];\n private _transformFactories: ((config?: unknown) => PackageDefinitionTransform)[];\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?: unknown) {\n this._definitions = definitionCache;\n this._transformedDefinitions = {};\n this._config = config;\n this._transforms = [applyOverrides];\n this._transformFactories = [];\n }\n\n async get(\n packagePath: string,\n options?: { refresh?: boolean; disableTransforms?: boolean },\n ): Promise<PackageJson | undefined> {\n let definition: PackageJson | undefined = this._definitions[packagePath];\n let transformedDefinition: PackageJson | undefined = this._transformedDefinitions[packagePath];\n const { refresh, disableTransforms } = options || {};\n\n // If we already have the answer they need, return immediately.\n if (!refresh) {\n if (disableTransforms && definition) {\n return definition;\n }\n\n if (!disableTransforms && transformedDefinition) {\n return transformedDefinition;\n }\n }\n\n // If we don't have the definition, try to load it.\n if (!definition || refresh) {\n definition = await readJson(path.join(packagePath, 'package.json'));\n\n if (!definition) {\n return undefined;\n }\n\n this._definitions[packagePath] = definition;\n }\n\n // If we don't want to skip the transform, transform the definition.\n if (!disableTransforms && (!transformedDefinition || refresh)) {\n for (const transform of this._transforms) {\n transformedDefinition =\n (await transform(transformedDefinition || definition, packagePath, this)) || transformedDefinition;\n }\n\n this._transformedDefinitions[packagePath] = transformedDefinition;\n }\n\n return (!disableTransforms && transformedDefinition) || definition;\n }\n\n /**\n * Registers a transform factory function, which will be called on initialization, and when reset, to re-generate\n * the transform function. Transform functions are called only when the package definition hasn't been loaded before,\n * and the result will be cached. Calling `reset` will reset the cache.\n */\n registerTransform(factory: (config?: unknown) => PackageDefinitionTransform) {\n this._transformFactories.push(factory);\n this._transforms.push(factory(this._config));\n\n this.reset();\n }\n\n /**\n * Resets the cache of package definitions. This is useful when testing, to ensure that the cache is empty.\n */\n reset(options?: { newConfig?: unknown }) {\n this._definitions = {};\n this._transformedDefinitions = {};\n\n const { newConfig } = options || {};\n\n if (newConfig) {\n this._config = newConfig;\n this._transforms = [applyOverrides, ...this._transformFactories.map((factory) => factory(newConfig))];\n }\n }\n}\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"addExportsMapEntry.d.ts","sourceRoot":"","sources":["../src/addExportsMapEntry.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,uBAAuB,EAAE,kBAAkB,EAAE,MAAM,6BAA6B,CAAC;AAG/F;;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;;;OAGG;IACH,SAAS,CAAC,EAAE,MAAM,CAAC;IAEnB;;OAEG;IACH,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB;AAED;;GAEG;AACH,wBAAsB,kBAAkB,CACtC,OAAO,EAAE,yBAAyB,EAClC,OAAO,EAAE;IAAE,QAAQ,EAAE,uBAAuB,CAAA;CAAE,GAC7C,OAAO,CAAC,OAAO,CAAC,CAyClB"}
1
+ {"version":3,"file":"addExportsMapEntry.d.ts","sourceRoot":"","sources":["../src/addExportsMapEntry.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,uBAAuB,EAAE,kBAAkB,EAAE,MAAM,6BAA6B,CAAC;AAG/F;;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;;;OAGG;IACH,SAAS,CAAC,EAAE,MAAM,CAAC;IAEnB;;OAEG;IACH,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB;AAED;;GAEG;AACH,wBAAsB,kBAAkB,CACtC,OAAO,EAAE,yBAAyB,EAClC,OAAO,EAAE;IAAE,QAAQ,EAAE,uBAAuB,CAAA;CAAE,GAC7C,OAAO,CAAC,OAAO,CAAC,CAkDlB"}
@@ -11,23 +11,31 @@ export async function addExportsMapEntry(options, context) {
11
11
  filePath: options.filePath || options.importPath || '',
12
12
  }, context);
13
13
  // Create a local for casting.
14
- // TODO: this is potentially clobbering or not correctly handling certain existing structures
15
14
  const localExports = exports;
16
15
  // Only do work if a file path was provided.
17
16
  if (filePath) {
18
- let exportsEntry = (localExports[importPath] ??= {});
19
- // Promote string-based exports into objects with default conditions.
20
- if (typeof exportsEntry === 'string') {
21
- exportsEntry = exports[importPath] = { default: exportsEntry };
17
+ // If this is the only entry we're adding, set it to a string to minimize the exports map.
18
+ if (!typesPath &&
19
+ !sourcePath &&
20
+ condition === 'default' &&
21
+ (!localExports[importPath] || typeof localExports[importPath] === 'string')) {
22
+ localExports[importPath] = filePath;
22
23
  }
23
- if (typesPath) {
24
- exportsEntry['types'] = typesPath;
24
+ else {
25
+ let exportsEntry = (localExports[importPath] ??= {});
26
+ // Promote string-based exports into objects with default conditions.
27
+ if (typeof exportsEntry === 'string') {
28
+ exportsEntry = exports[importPath] = { default: exportsEntry };
29
+ }
30
+ if (typesPath) {
31
+ exportsEntry['types'] = typesPath;
32
+ }
33
+ if (sourcePath) {
34
+ exportsEntry['source'] = sourcePath;
35
+ }
36
+ // Add the entry for the condition.
37
+ exportsEntry[condition] = filePath;
25
38
  }
26
- if (sourcePath) {
27
- exportsEntry['source'] = sourcePath;
28
- }
29
- // Add the entry for the condition.
30
- exportsEntry[condition] = filePath;
31
39
  }
32
40
  return !!filePath;
33
41
  }
@@ -1 +1 @@
1
- {"version":3,"file":"addExportsMapEntry.js","sourceRoot":"","sources":["../src/addExportsMapEntry.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,wBAAwB,CAAC;AAE3D,OAAO,EAAE,gBA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AAG,IAAI,GAAG,KAAK,EAAE,IAAI,GAAG,KAAK,GAAG,EAAE;QACrC,OAAO,GAAG,CAAC;KACZ;IAED,4CAA4C;IAC5C,IAAI,GAAG,CAAC,UAAU,CAAC,GAAG,CAAC,EAAE;QACvB,GAAG,GAAG,GAAG,GAAG,GAAG,CAAC;KACjB;IAED,6CAA6C;IAC7C,IAAI,CAAC,GAAG,CAAC,UAAU,CAAC,IAAI,CAAC,EAAE;QACzB,GAAG,GAAG,IAAI,GAAG,GAAG,CAAC;KAClB;IAED,OAAO,GAAG,CAAC;AACb,CAAC","sourcesContent":["import { findFileInPackage } from './findFileInPackage.js';\nimport type { PackageDefinitionsCache, PackageJsonExports } from '@ms-cloudpack/bundler-types';\nimport { safeRelativePath } from '@ms-cloudpack/path-string-parsing';\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 * Optional types path. If not provided, types will be discovered for internal packages that have source files.\n * This is useful mainly when converting the default import from a package.json that has explicit typings listed.\n */\n typesPath?: string;\n\n /**\n * The condition to add the entry for. (Example: \"import\", \"require\", \"browser\", \"types\") Defaults to \"default\"\n */\n condition?: string;\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 },\n): Promise<boolean> {\n const { exports, packagePath, condition = 'default' } = options;\n const importPath = makeSafeImportKey(options.importPath || '.');\n const {\n filePath,\n sourcePath,\n typesPath = options.typesPath ? safeRelativePath(options.typesPath) : undefined,\n } = await findFileInPackage(\n {\n packagePath,\n filePath: options.filePath || options.importPath || '',\n },\n context,\n );\n\n // Create a local for casting.\n // TODO: this is potentially clobbering or not correctly handling certain existing structures\n const localExports = exports as Record<string, Record<string, string>>;\n\n // Only do work if a file path was provided.\n if (filePath) {\n let exportsEntry = (localExports[importPath] ??= {});\n\n // Promote string-based exports into objects with default conditions.\n if (typeof exportsEntry === 'string') {\n exportsEntry = (exports as Record<string, Record<string, string>>)[importPath] = { default: exportsEntry };\n }\n\n if (typesPath) {\n exportsEntry['types'] = typesPath;\n }\n\n if (sourcePath) {\n exportsEntry['source'] = sourcePath;\n }\n\n // Add the entry for the condition.\n exportsEntry[condition] = filePath;\n }\n\n return !!filePath;\n}\n\nfunction makeSafeImportKey(key: string) {\n if (!key || key === '' || key === '.') {\n return '.';\n }\n\n // if the key starts with a slash, add a dot\n if (key.startsWith('/')) {\n key = '.' + key;\n }\n\n // if the key doesn't start with \"./\", add it\n if (!key.startsWith('./')) {\n key = './' + key;\n }\n\n return key;\n}\n"]}
1
+ {"version":3,"file":"addExportsMapEntry.js","sourceRoot":"","sources":["../src/addExportsMapEntry.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,wBAAwB,CAAC;AAE3D,OAAO,EAAE,gBAAgB,EAAE,MAAM,mCAAmC,CAAC;AAyCrE;;GAEG;AACH,MAAM,CAAC,KAAK,UAAU,kBAAkB,CACtC,OAAkC,EAClC,OAA8C;IAE9C,MAAM,EAAE,OAAO,EAAE,WAAW,EAAE,SAAS,GAAG,SAAS,EAAE,GAAG,OAAO,CAAC;IAChE,MAAM,UAAU,GAAG,iBAAiB,CAAC,OAAO,CAAC,UAAU,IAAI,GAAG,CAAC,CAAC;IAChE,MAAM,EACJ,QAAQ,EACR,UAAU,EACV,SAAS,GAAG,OAAO,CAAC,SAAS,CAAC,CAAC,CAAC,gBAAgB,CAAC,OAAO,CAAC,SAAS,CAAC,CAAC,CAAC,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GAAG,GAAG,CAAC;KACjB;IAED,6CAA6C;IAC7C,IAAI,CAAC,GAAG,CAAC,UAAU,CAAC,IAAI,CAAC,EAAE;QACzB,GAAG,GAAG,IAAI,GAAG,GAAG,CAAC;KAClB;IAED,OAAO,GAAG,CAAC;AACb,CAAC","sourcesContent":["import { findFileInPackage } from './findFileInPackage.js';\nimport type { PackageDefinitionsCache, PackageJsonExports } from '@ms-cloudpack/bundler-types';\nimport { safeRelativePath } from '@ms-cloudpack/path-string-parsing';\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 * Optional types path. If not provided, types will be discovered for internal packages that have source files.\n * This is useful mainly when converting the default import from a package.json that has explicit typings listed.\n */\n typesPath?: string;\n\n /**\n * The condition to add the entry for. (Example: \"import\", \"require\", \"browser\", \"types\") Defaults to \"default\"\n */\n condition?: string;\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 },\n): Promise<boolean> {\n const { exports, packagePath, condition = 'default' } = options;\n const importPath = makeSafeImportKey(options.importPath || '.');\n const {\n filePath,\n sourcePath,\n typesPath = options.typesPath ? safeRelativePath(options.typesPath) : undefined,\n } = await findFileInPackage(\n {\n packagePath,\n filePath: options.filePath || options.importPath || '',\n },\n context,\n );\n\n // Create a local for casting.\n const localExports = exports as Record<string, string | Record<string, string>>;\n\n // Only do work if a file path was provided.\n if (filePath) {\n // If this is the only entry we're adding, set it to a string to minimize the exports map.\n if (\n !typesPath &&\n !sourcePath &&\n condition === 'default' &&\n (!localExports[importPath] || typeof localExports[importPath] === 'string')\n ) {\n localExports[importPath] = filePath;\n } else {\n let exportsEntry = (localExports[importPath] ??= {});\n\n // Promote string-based exports into objects with default conditions.\n if (typeof exportsEntry === 'string') {\n exportsEntry = (exports as Record<string, Record<string, string>>)[importPath] = { default: exportsEntry };\n }\n\n if (typesPath) {\n exportsEntry['types'] = typesPath;\n }\n\n if (sourcePath) {\n exportsEntry['source'] = sourcePath;\n }\n\n // Add the entry for the condition.\n exportsEntry[condition] = filePath;\n }\n }\n\n return !!filePath;\n}\n\nfunction makeSafeImportKey(key: string) {\n if (!key || key === '' || key === '.') {\n return '.';\n }\n\n // if the key starts with a slash, add a dot\n if (key.startsWith('/')) {\n key = '.' + key;\n }\n\n // if the key doesn't start with \"./\", add it\n if (!key.startsWith('./')) {\n key = './' + key;\n }\n\n return key;\n}\n"]}
@@ -4,6 +4,7 @@ import type { PackageJsonExports, PackageDefinitionsCache } from '@ms-cloudpack/
4
4
  */
5
5
  export declare function createExportsMap(options: {
6
6
  packagePath: string;
7
+ disableTransforms?: boolean;
7
8
  }, context: {
8
9
  packages: PackageDefinitionsCache;
9
10
  }): Promise<PackageJsonExports>;
@@ -1 +1 @@
1
- {"version":3,"file":"createExportsMap.d.ts","sourceRoot":"","sources":["../src/createExportsMap.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,kBAAkB,EAAE,uBAAuB,EAAE,MAAM,6BAA6B,CAAC;AAI/F;;GAEG;AACH,wBAAsB,gBAAgB,CACpC,OAAO,EAAE;IACP,WAAW,EAAE,MAAM,CAAC;CACrB,EACD,OAAO,EAAE;IAAE,QAAQ,EAAE,uBAAuB,CAAA;CAAE,GAC7C,OAAO,CAAC,kBAAkB,CAAC,CAoF7B"}
1
+ {"version":3,"file":"createExportsMap.d.ts","sourceRoot":"","sources":["../src/createExportsMap.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,kBAAkB,EAAE,uBAAuB,EAAE,MAAM,6BAA6B,CAAC;AAI/F;;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,CAAA;CAAE,GAC7C,OAAO,CAAC,kBAAkB,CAAC,CAoF7B"}
@@ -6,7 +6,7 @@ import { safeRelativePath } from '@ms-cloudpack/path-string-parsing';
6
6
  export async function createExportsMap(options, context) {
7
7
  const { packagePath } = options;
8
8
  const { packages } = context;
9
- const definition = await packages.get(packagePath);
9
+ const definition = await packages.get(packagePath, { disableTransforms: options.disableTransforms });
10
10
  if (!definition) {
11
11
  throw new Error(`Package definition not found for ${packagePath}`);
12
12
  }
@@ -1 +1 @@
1
- {"version":3,"file":"createExportsMap.js","sourceRoot":"","sources":["../src/createExportsMap.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,kBAAkB,EAAE,MAAM,yBAAyB,CAAC;AAC7D,OAAO,EAAE,gBAAgB,EAAE,MAAM,mCAAmC,CAAC;AAErE;;GAEG;AACH,MAAM,CAAC,KAAK,UAAU,gBAAgB,CACpC,OAEC,EACD,OAA8C;IAE9C,MAAM,EAAE,WAAW,EAAE,GAAG,OAAO,CAAC;IAChC,MAAM,EAAE,QAAQ,EAAE,GAAG,OAAO,CAAC;IAC7B,MAAM,UAAU,GAAG,MAAM,QAAQ,CAAC,GAAG,CAAC,WAAW,CAAC,CAAC;IAEnD,IAAI,CAAC,UAAU,EAAE;QACf,MAAM,IAAI,KAAK,CAAC,oCAAoC,WAAW,EAAE,CAAC,CAAC;KACpE;IAED,qEAAqE;IACrE,IAAI,UAAU,CAAC,OAAO,EAAE;QACtB,OAAO,UAAU,CAAC,OAAO,CAAC;KAC3B;IAED,MAAM,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,OA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AK,gBAAgB,CAAC,GAAG,CAAC,CAAC;oBAEnF,MAAM,WAAW,GAAG,eAAe,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC;oBAEpD,IAAI,CAAC,eAAe,IAAI,GAAG,CAAC,QAAQ,CAAC,KAAK,CAAC,EAAE;wBAC3C,WAAW,CAAC,IAAI,CAAC,GAAG,CAAC,OAAO,CAAC,OAAO,EAAE,EAAE,CAAC,CAAC,CAAC;qBAC5C;oBAED,KAAK,MAAM,UAAU,IAAI,WAAW,EAAE;wBACpC,MAAM,kBAAkB,CACtB;4BACE,OAAO;4BACP,WAAW;4BACX,UAAU;4BACV,QAAQ,EAAE,KAAK;4BACf,SAAS,EAAE,SAAS;yBACrB,EACD,OAAO,CACR,CAAC;qBACH;iBACF;aACF;SACF;KACF;IAED,qEAAqE;IACrE,+CAA+C;IAC/C,mEAAmE;IACnE,IAAI,MAAM,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC,MAAM,KAAK,CAAC,EAAE;QACrC,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;KACzF;IAED,OAAO,OAAO,CAAC;AACjB,CAAC","sourcesContent":["import type { PackageJsonExports, PackageDefinitionsCache } from '@ms-cloudpack/bundler-types';\nimport { addExportsMapEntry } from './addExportsMapEntry.js';\nimport { safeRelativePath } from '@ms-cloudpack/path-string-parsing';\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 },\n context: { packages: PackageDefinitionsCache },\n): Promise<PackageJsonExports> {\n const { packagePath } = options;\n const { packages } = context;\n const definition = await packages.get(packagePath);\n\n if (!definition) {\n throw new Error(`Package definition not found for ${packagePath}`);\n }\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, types, typings, type } = definition;\n const exports = {};\n const typesPath = types || typings;\n\n await addExportsMapEntry(\n {\n exports,\n packagePath,\n filePath: 'index.js',\n typesPath,\n condition: type === 'module' ? 'import' : 'default',\n },\n context,\n );\n main &&\n (await addExportsMapEntry(\n {\n exports,\n packagePath,\n filePath: main,\n typesPath,\n condition: type === 'module' ? 'import' : 'default',\n },\n context,\n ),\n context);\n module &&\n (await addExportsMapEntry({ exports, packagePath, filePath: module, typesPath, condition: 'import' }, context));\n\n if (browser) {\n if (typeof definition.browser === 'string') {\n await addExportsMapEntry({ exports, packagePath, filePath: definition.browser, condition: 'browser' }, context);\n } else if (typeof definition.browser === 'object') {\n for (const [key, value] of Object.entries(definition.browser)) {\n if (value && typeof value === 'string') {\n const isDefaultImport = safeRelativePath(module || main) === safeRelativePath(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 condition: 'browser',\n },\n context,\n );\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
+ {"version":3,"file":"createExport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BACF;aACF;SACF;KACF;IAED,qEAAqE;IACrE,+CAA+C;IAC/C,mEAAmE;IACnE,IAAI,MAAM,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC,MAAM,KAAK,CAAC,EAAE;QACrC,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;KACzF;IAED,OAAO,OAAO,CAAC;AACjB,CAAC","sourcesContent":["import type { PackageJsonExports, PackageDefinitionsCache } from '@ms-cloudpack/bundler-types';\nimport { addExportsMapEntry } from './addExportsMapEntry.js';\nimport { safeRelativePath } from '@ms-cloudpack/path-string-parsing';\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 },\n): Promise<PackageJsonExports> {\n const { packagePath } = options;\n const { packages } = context;\n const definition = await packages.get(packagePath, { disableTransforms: options.disableTransforms });\n\n if (!definition) {\n throw new Error(`Package definition not found for ${packagePath}`);\n }\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, types, typings, type } = definition;\n const exports = {};\n const typesPath = types || typings;\n\n await addExportsMapEntry(\n {\n exports,\n packagePath,\n filePath: 'index.js',\n typesPath,\n condition: type === 'module' ? 'import' : 'default',\n },\n context,\n );\n main &&\n (await addExportsMapEntry(\n {\n exports,\n packagePath,\n filePath: main,\n typesPath,\n condition: type === 'module' ? 'import' : 'default',\n },\n context,\n ),\n context);\n module &&\n (await addExportsMapEntry({ exports, packagePath, filePath: module, typesPath, condition: 'import' }, context));\n\n if (browser) {\n if (typeof definition.browser === 'string') {\n await addExportsMapEntry({ exports, packagePath, filePath: definition.browser, condition: 'browser' }, context);\n } else if (typeof definition.browser === 'object') {\n for (const [key, value] of Object.entries(definition.browser)) {\n if (value && typeof value === 'string') {\n const isDefaultImport = safeRelativePath(module || main) === safeRelativePath(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 condition: 'browser',\n },\n context,\n );\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,6 +1,7 @@
1
1
  import type { PackageDefinitionsCache, PackageJsonExports } from '@ms-cloudpack/bundler-types';
2
2
  export declare function getExportsMap(options: {
3
3
  packagePath: string;
4
+ disableTransforms?: boolean;
4
5
  }, context: {
5
6
  packages: PackageDefinitionsCache;
6
7
  }): Promise<PackageJsonExports>;
@@ -1 +1 @@
1
- {"version":3,"file":"getExportsMap.d.ts","sourceRoot":"","sources":["../src/getExportsMap.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,uBAAuB,EAAE,kBAAkB,EAAE,MAAM,6BAA6B,CAAC;AAG/F,wBAAsB,aAAa,CACjC,OAAO,EAAE;IAAE,WAAW,EAAE,MAAM,CAAA;CAAE,EAChC,OAAO,EAAE;IAAE,QAAQ,EAAE,uBAAuB,CAAA;CAAE,GAC7C,OAAO,CAAC,kBAAkB,CAAC,CAY7B"}
1
+ {"version":3,"file":"getExportsMap.d.ts","sourceRoot":"","sources":["../src/getExportsMap.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,uBAAuB,EAAE,kBAAkB,EAAE,MAAM,6BAA6B,CAAC;AAG/F,wBAAsB,aAAa,CACjC,OAAO,EAAE;IAAE,WAAW,EAAE,MAAM,CAAC;IAAC,iBAAiB,CAAC,EAAE,OAAO,CAAA;CAAE,EAC7D,OAAO,EAAE;IAAE,QAAQ,EAAE,uBAAuB,CAAA;CAAE,GAC7C,OAAO,CAAC,kBAAkB,CAAC,CAY7B"}
@@ -2,7 +2,7 @@ import { createExportsMap } from './createExportsMap.js';
2
2
  export async function getExportsMap(options, context) {
3
3
  const { packagePath } = options;
4
4
  const { packages } = context;
5
- const packageDefinition = await packages.get(packagePath);
5
+ const packageDefinition = await packages.get(packagePath, options);
6
6
  if (!packageDefinition) {
7
7
  throw new Error(`Package definition not found for ${packagePath}`);
8
8
  }
@@ -1 +1 @@
1
- {"version":3,"file":"getExportsMap.js","sourceRoot":"","sources":["../src/getExportsMap.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAC;AAEzD,MAAM,CAAC,KAAK,UAAU,aAAa,CACjC,OAAgC,EAChC,OAA8C;IAE9C,MAAM,EAAE,WAAW,EAAE,GAAG,OAAO,CAAC;IAChC,MAAM,EAAE,QAAQ,EAAE,GAAG,OAAO,CAAC;IAC7B,MAAM,iBAAiB,GAAG,MAAM,QAAQ,CAAC,GAAG,CAAC,WAAW,CAAC,CAAC;IAE1D,IAAI,CAAC,iBAAiB,EAAE;QACtB,MAAM,IAAI,KAAK,CAAC,oCAAoC,WAAW,EAAE,CAAC,CAAC;KACpE;IAED,MAAM,EAAE,OAAO,EAAE,GAAG,iBAAiB,CAAC;IAEtC,OAAO,OAAO,KAAK,SAAS,CAAC,CAAC,CAAC,MAAM,gBAAgB,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC;AACpF,CAAC","sourcesContent":["import type { PackageDefinitionsCache, PackageJsonExports } from '@ms-cloudpack/bundler-types';\nimport { createExportsMap } from './createExportsMap.js';\n\nexport async function getExportsMap(\n options: { packagePath: string },\n context: { packages: PackageDefinitionsCache },\n): Promise<PackageJsonExports> {\n const { packagePath } = options;\n const { packages } = context;\n const packageDefinition = await packages.get(packagePath);\n\n if (!packageDefinition) {\n throw new Error(`Package definition not found for ${packagePath}`);\n }\n\n const { exports } = packageDefinition;\n\n return exports === undefined ? await createExportsMap(options, context) : exports;\n}\n"]}
1
+ {"version":3,"file":"getExportsMap.js","sourceRoot":"","sources":["../src/getExportsMap.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAC;AAEzD,MAAM,CAAC,KAAK,UAAU,aAAa,CACjC,OAA6D,EAC7D,OAA8C;IAE9C,MAAM,EAAE,WAAW,EAAE,GAAG,OAAO,CAAC;IAChC,MAAM,EAAE,QAAQ,EAAE,GAAG,OAAO,CAAC;IAC7B,MAAM,iBAAiB,GAAG,MAAM,QAAQ,CAAC,GAAG,CAAC,WAAW,EAAE,OAAO,CAAC,CAAC;IAEnE,IAAI,CAAC,iBAAiB,EAAE;QACtB,MAAM,IAAI,KAAK,CAAC,oCAAoC,WAAW,EAAE,CAAC,CAAC;KACpE;IAED,MAAM,EAAE,OAAO,EAAE,GAAG,iBAAiB,CAAC;IAEtC,OAAO,OAAO,KAAK,SAAS,CAAC,CAAC,CAAC,MAAM,gBAAgB,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC;AACpF,CAAC","sourcesContent":["import type { PackageDefinitionsCache, PackageJsonExports } from '@ms-cloudpack/bundler-types';\nimport { createExportsMap } from './createExportsMap.js';\n\nexport async function getExportsMap(\n options: { packagePath: string; disableTransforms?: boolean },\n context: { packages: PackageDefinitionsCache },\n): Promise<PackageJsonExports> {\n const { packagePath } = options;\n const { packages } = context;\n const packageDefinition = await packages.get(packagePath, options);\n\n if (!packageDefinition) {\n throw new Error(`Package definition not found for ${packagePath}`);\n }\n\n const { exports } = packageDefinition;\n\n return exports === undefined ? await createExportsMap(options, context) : exports;\n}\n"]}
@@ -5,7 +5,7 @@
5
5
  "toolPackages": [
6
6
  {
7
7
  "packageName": "@microsoft/api-extractor",
8
- "packageVersion": "7.36.2"
8
+ "packageVersion": "7.36.3"
9
9
  }
10
10
  ]
11
11
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ms-cloudpack/package-utilities",
3
- "version": "5.0.1",
3
+ "version": "5.1.0",
4
4
  "description": "Utilities for resolving/parsing packages and their imports.",
5
5
  "license": "MIT",
6
6
  "type": "module",
@@ -13,24 +13,22 @@
13
13
  }
14
14
  },
15
15
  "dependencies": {
16
- "@babel/parser": "^7.16.12",
17
- "@babel/traverse": "^7.16.10",
18
- "@ms-cloudpack/bundler-types": "^0.16.0",
16
+ "@ms-cloudpack/bundler-types": "^0.17.0",
19
17
  "@ms-cloudpack/json-utilities": "^0.0.7",
20
- "@ms-cloudpack/package-overrides": "^0.3.11",
21
- "@ms-cloudpack/path-utilities": "^2.3.1",
18
+ "@ms-cloudpack/package-overrides": "^0.4.0",
19
+ "@ms-cloudpack/path-utilities": "^2.3.2",
22
20
  "@ms-cloudpack/path-string-parsing": "^1.0.3",
23
21
  "fast-glob": "^3.2.12",
24
22
  "merge": "^2.1.1",
25
23
  "resolve": "^1.22.0",
24
+ "semver": "^7.3.7",
26
25
  "workspace-tools": "^0.35.0"
27
26
  },
28
27
  "devDependencies": {
29
28
  "@ms-cloudpack/eslint-plugin-internal": "*",
30
29
  "@ms-cloudpack/scripts": "*",
31
30
  "@ms-cloudpack/test-utilities": "*",
32
- "@types/resolve": "^1.20.2",
33
- "@babel/types": "^7.21.4"
31
+ "@types/resolve": "^1.20.2"
34
32
  },
35
33
  "scripts": {
36
34
  "api": "cloudpack-scripts api",