@ms-cloudpack/package-utilities 13.3.4 → 13.5.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,24 +1,20 @@
1
1
  import type { CloudpackConfig, PackageDefinitionsCache, GeneratedExports } from '@ms-cloudpack/common-types';
2
- import { type FindFileInPackageResult } from '../findFileInPackage/findFileInPackage.js';
2
+ import { type FindFileInPackageOptions, type FindFileInPackageResult } from '../findFileInPackage/findFileInPackage.js';
3
3
  /**
4
4
  * Options for `addExportsMapEntry`.
5
5
  */
6
- export interface AddExportsMapEntryOptions {
6
+ export interface AddExportsMapEntryOptions extends Pick<FindFileInPackageOptions, 'packagePath' | 'resolveWebExtensions'> {
7
7
  /**
8
8
  * The generated exports map to add the entry to.
9
9
  */
10
10
  exports: GeneratedExports;
11
- /**
12
- * The package path to add the entry for. This is used to resolve relative paths.
13
- */
14
- packagePath: string;
15
11
  /**
16
12
  * The import path to add the entry for. This is used as the key in the exports map.
17
13
  * Defaults to `'.'` (the package import).
18
14
  */
19
15
  importPath?: string;
20
16
  /**
21
- * The relative path to the physical file location, representing the "key" in the exports map.
17
+ * The relative path to the physical file location, used to derive the exports map value.
22
18
  * Can be a partial location, in which case we'll search for the file and associated source/d.ts files.
23
19
  * Defaults to `importPath` if provided, or `'index.js'`.
24
20
  */
@@ -35,10 +31,6 @@ export interface AddExportsMapEntryOptions {
35
31
  * - `node` is used for server rendering.
36
32
  */
37
33
  environmentCondition?: 'browser' | 'node';
38
- /**
39
- * Whether to resolve web extensions (e.g. `.web.js`).
40
- */
41
- resolveWebExtensions: boolean;
42
34
  }
43
35
  /**
44
36
  * Add an import path to an exports map. This is intended for use with generated exports maps,
@@ -50,7 +42,8 @@ export interface AddExportsMapEntryOptions {
50
42
  */
51
43
  export declare function addExportsMapEntry(options: AddExportsMapEntryOptions, context: {
52
44
  packages: PackageDefinitionsCache;
53
- config: Pick<CloudpackConfig, 'features'>;
45
+ /** @deprecated Pass `resolveWebExtensions` option directly */
46
+ config?: Pick<CloudpackConfig, 'features'>;
54
47
  }): Promise<boolean>;
55
48
  /**
56
49
  * Internal logic of adding an entry to an exports map.
@@ -1 +1 @@
1
- {"version":3,"file":"addExportsMapEntry.d.ts","sourceRoot":"","sources":["../../src/exportsMap/addExportsMapEntry.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,uBAAuB,EAAE,gBAAgB,EAAE,MAAM,4BAA4B,CAAC;AAE7G,OAAO,EAAqB,KAAK,uBAAuB,EAAE,MAAM,2CAA2C,CAAC;AAE5G;;GAEG;AACH,MAAM,WAAW,yBAAyB;IACxC;;OAEG;IACH,OAAO,EAAE,gBAAgB,CAAC;IAE1B;;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,gBAAgB,CAAC,EAAE,QAAQ,GAAG,SAAS,GAAG,SAAS,CAAC;IAEpD;;;;;OAKG;IACH,oBAAoB,CAAC,EAAE,SAAS,GAAG,MAAM,CAAC;IAE1C;;OAEG;IACH,oBAAoB,EAAE,OAAO,CAAC;CAC/B;AAED;;;;;;;GAOG;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,CAmBlB;AAED;;;;GAIG;AACH,wBAAgB,SAAS,CACvB,OAAO,EAAE,IAAI,CAAC,yBAAyB,EAAE,aAAa,GAAG,UAAU,CAAC,EACpE,SAAS,EAAE,uBAAuB,GACjC,OAAO,CAgDT"}
1
+ {"version":3,"file":"addExportsMapEntry.d.ts","sourceRoot":"","sources":["../../src/exportsMap/addExportsMapEntry.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,uBAAuB,EAAE,gBAAgB,EAAE,MAAM,4BAA4B,CAAC;AAE7G,OAAO,EAEL,KAAK,wBAAwB,EAC7B,KAAK,uBAAuB,EAC7B,MAAM,2CAA2C,CAAC;AAEnD;;GAEG;AACH,MAAM,WAAW,yBAA0B,SAAQ,IAAI,CACrD,wBAAwB,EACxB,aAAa,GAAG,sBAAsB,CACvC;IACC;;OAEG;IACH,OAAO,EAAE,gBAAgB,CAAC;IAE1B;;;OAGG;IACH,UAAU,CAAC,EAAE,MAAM,CAAC;IAEpB;;;;OAIG;IACH,QAAQ,CAAC,EAAE,MAAM,CAAC;IAElB;;;OAGG;IACH,gBAAgB,CAAC,EAAE,QAAQ,GAAG,SAAS,GAAG,SAAS,CAAC;IAEpD;;;;;OAKG;IACH,oBAAoB,CAAC,EAAE,SAAS,GAAG,MAAM,CAAC;CAC3C;AAED;;;;;;;GAOG;AACH,wBAAsB,kBAAkB,CACtC,OAAO,EAAE,yBAAyB,EAClC,OAAO,EAAE;IACP,QAAQ,EAAE,uBAAuB,CAAC;IAClC,8DAA8D;IAC9D,MAAM,CAAC,EAAE,IAAI,CAAC,eAAe,EAAE,UAAU,CAAC,CAAC;CAC5C,GACA,OAAO,CAAC,OAAO,CAAC,CAwBlB;AAED;;;;GAIG;AACH,wBAAgB,SAAS,CACvB,OAAO,EAAE,IAAI,CAAC,yBAAyB,EAAE,aAAa,GAAG,UAAU,CAAC,EACpE,SAAS,EAAE,uBAAuB,GACjC,OAAO,CAgDT"}
@@ -1,5 +1,5 @@
1
1
  import { normalizeRelativePath } from '@ms-cloudpack/path-string-parsing';
2
- import { findFileInPackage } from '../findFileInPackage/findFileInPackage.js';
2
+ import { findFileInPackage, } from '../findFileInPackage/findFileInPackage.js';
3
3
  /**
4
4
  * Add an import path to an exports map. This is intended for use with generated exports maps,
5
5
  * either in the context of the generated config, or generated for a package which doesn't have
@@ -9,7 +9,12 @@ import { findFileInPackage } from '../findFileInPackage/findFileInPackage.js';
9
9
  * being updated is an array (it should have been normalized to object format before calling).
10
10
  */
11
11
  export async function addExportsMapEntry(options, context) {
12
- const { exports, packagePath, resolveWebExtensions } = options;
12
+ // resolveWebExtensions should only be missing in weird dependency mismatch cases, and it's
13
+ // rarely used anyway. In this context, definitions.get() could cause an infinite loop,
14
+ // so fall back to checking the config only.
15
+ // eslint-disable-next-line etc/no-deprecated
16
+ const { exports, packagePath, resolveWebExtensions = !!context.config?.features?.resolveWebExtensions } = options;
17
+ const { packages } = context;
13
18
  // We try to enforce these conditions in the types, but also do an explicit check in case of
14
19
  // casting or other unexpected input.
15
20
  if (exports === null || Array.isArray(exports) || typeof exports === 'string') {
@@ -19,7 +24,7 @@ export async function addExportsMapEntry(options, context) {
19
24
  packagePath,
20
25
  filePath: options.filePath || options.importPath || '',
21
26
  resolveWebExtensions,
22
- }, context);
27
+ }, { packages });
23
28
  return _addEntry(options, foundFile);
24
29
  }
25
30
  /**
@@ -1 +1 @@
1
- {"version":3,"file":"addExportsMapEntry.js","sourceRoot":"","sources":["../../src/exportsMap/addExportsMapEntry.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,qBAAqB,EAAE,MAAM,mCAAmC,CAAC;AAC1E,OAAO,EAAE,iBAAiB,EAAgC,MAAM,2CAA2C,CAAC;AAiD5G;;;;;;;GAOG;AACH,MAAM,CAAC,KAAK,UAAU,kBAAkB,CACtC,OAAkC,EAClC,OAAyF;IAEzF,MAAM,EAAE,OAAO,EAAE,WAAW,EAAE,oBAAoB,EAAE,GAAG,OAAO,CAAC;IAE/D,4FAA4F;IAC5F,qCAAqC;IACrC,IAAI,OAAO,KAAK,IAAI,IAAI,KAAK,CAAC,OAAO,CAAC,OAAO,CAAC,IAAI,OAAO,OAAO,KAAK,QAAQ,EAAE,CAAC;QAC9E,MAAM,IAAI,KAAK,CAAC,qEAAqE,IAAI,CAAC,SAAS,CAAC,OAAO,CAAC,EAAE,CAAC,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,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC;IAC9E,KAAK,MAAM,GAAG,IAAI,OAAO,EAAE,CAAC;QAC1B,IAAI,QAAQ,CAAC,GAAG,CAAC,EAAE,CAAC;YAClB,MAAM,CAAC,GAAG,CAAC,GAAG,YAAY,CAAC,EAAE,QAAQ,EAAE,QAAQ,CAAC,GAAG,CAAC,EAAE,QAAQ,EAAE,QAAQ,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC;QACnF,CAAC;aAAM,CAAC;YACN,MAAM,CAAC,GAAG,CAAC,GAAG,QAAQ,CAAC,GAAG,CAAC,CAAC;QAC9B,CAAC;IACH,CAAC;IAED,MAAM,YAAY,GAAG,MAAM,CAAC,OAAO,CAAC;IACpC,IAAI,YAAY,EAAE,CAAC;QACjB,IAAI,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;YACrC,oCAAoC;YACpC,OAAO,YAAY,CAAC;QACtB,CAAC;QAED,6DAA6D;QAC7D,OAAO,MAAM,CAAC,OAAO,CAAC;QACtB,MAAM,CAAC,OAAO,GAAG,YAAY,CAAC;IAChC,CAAC;IAED,OAAO,MAAW,CAAC;AACrB,CAAC","sourcesContent":["import type { CloudpackConfig, PackageDefinitionsCache, GeneratedExports } from '@ms-cloudpack/common-types';\nimport { normalizeRelativePath } from '@ms-cloudpack/path-string-parsing';\nimport { findFileInPackage, type FindFileInPackageResult } from '../findFileInPackage/findFileInPackage.js';\n\n/**\n * Options for `addExportsMapEntry`.\n */\nexport interface AddExportsMapEntryOptions {\n /**\n * The generated exports map to add the entry to.\n */\n exports: GeneratedExports;\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.\n * Defaults to `'.'` (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.\n * Can be a partial location, in which case we'll search for the file and associated source/d.ts files.\n * Defaults to `importPath` if provided, or `'index.js'`.\n */\n filePath?: string;\n\n /**\n * Module type condition to add the entry for.\n * @default 'default'\n */\n requestCondition?: 'import' | 'require' | 'default';\n\n /**\n * The condition that describes the environment the entry is for.\n * Unspecified implies environmentally agnostic.\n * - `browser` is used for cases such as `browser` entries in package.json or implicit exports defined in routes.\n * - `node` is used for server rendering.\n */\n environmentCondition?: 'browser' | 'node';\n\n /**\n * Whether to resolve web extensions (e.g. `.web.js`).\n */\n resolveWebExtensions: boolean;\n}\n\n/**\n * Add an import path to an exports map. This is intended for use with generated exports maps,\n * either in the context of the generated config, or generated for a package which doesn't have\n * an exports map.\n *\n * Throws an error if the exports map passed in is not an object, or if the value of the key\n * being updated is an array (it should have been normalized to object format before calling).\n */\nexport async function addExportsMapEntry(\n options: AddExportsMapEntryOptions,\n context: { packages: PackageDefinitionsCache; config: Pick<CloudpackConfig, 'features'> },\n): Promise<boolean> {\n const { exports, packagePath, resolveWebExtensions } = options;\n\n // We try to enforce these conditions in the types, but also do an explicit check in case of\n // casting or other unexpected input.\n if (exports === null || Array.isArray(exports) || typeof exports === 'string') {\n throw new Error(`Exports passed to addExportsMapEntry must be an object; received: ${JSON.stringify(exports)}`);\n }\n\n const foundFile = await findFileInPackage(\n {\n packagePath,\n filePath: options.filePath || options.importPath || '',\n resolveWebExtensions,\n },\n context,\n );\n\n return _addEntry(options, foundFile);\n}\n\n/**\n * Internal logic of adding an entry to an exports map.\n * Exported for testing this logic separately from the filesystem parts.\n * @internal\n */\nexport function _addEntry(\n options: Omit<AddExportsMapEntryOptions, 'packagePath' | 'filePath'>,\n foundFile: FindFileInPackageResult,\n): boolean {\n const { exports, environmentCondition, requestCondition = 'default' } = options;\n const { filePath, sourcePath } = foundFile;\n\n // Only do work if a file path was found.\n if (!filePath) {\n return false;\n }\n\n // Normalize the import path (this also converts undefined to '.')\n const importPath = normalizeRelativePath(options.importPath);\n\n const oldEntry = exports[importPath];\n if (Array.isArray(oldEntry)) {\n // This should never happen with the standardized generated exports map format.\n // In theory we could handle it by pushing to the array, but nesting conditions inside arrays\n // isn't valid in the exports map spec.\n throw new Error(`Cannot add to an array of exports for \"${importPath}\"`);\n }\n\n let exportValue: string | Record<string, string>;\n\n if (!sourcePath && !requestCondition) {\n // If this is the only entry we're adding, set it to a string to minimize the exports map.\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] = filePath;\n\n if (requestCondition === 'default' && Object.keys(exportValue).length === 1) {\n // Only the default condition is present, so flatten to a string\n exportValue = filePath;\n }\n }\n\n const newEntry: GeneratedExports[string] = environmentCondition\n ? { [environmentCondition]: exportValue }\n : exportValue;\n\n exports[importPath] = mergeEntries({ oldEntry, newEntry });\n\n return true;\n}\n\n/**\n * This handles the merging of potential nested environment and request conditions, and ensures that\n * the `default` key is in the correct order (always last).\n */\nfunction mergeEntries<T extends string | Record<string, T>>(params: {\n oldEntry: T | null | undefined;\n newEntry: T;\n}): T {\n const { oldEntry, newEntry } = params;\n\n if (!oldEntry) {\n return newEntry;\n }\n\n // If oldEntry is a string... (using !== object instead of === string so TS infers the correct type later)\n if (typeof oldEntry !== 'object') {\n // If newEntry is an object without a default, use oldEntry as the default.\n if (typeof newEntry === 'object' && !newEntry.default) {\n return { ...newEntry, default: oldEntry };\n }\n // Otherwise ignore oldEntry.\n return newEntry;\n }\n\n if (typeof newEntry !== 'object') {\n // oldEntry object, newEntry string => use newEntry as default\n return { ...oldEntry, default: newEntry };\n }\n\n // both objects => full merge (the typings get imprecise here)\n const merged: Record<string, T> = {};\n // put the new keys first in the merged object (this could be made configurable later if needed)\n const allKeys = new Set([...Object.keys(newEntry), ...Object.keys(oldEntry)]);\n for (const key of allKeys) {\n if (newEntry[key]) {\n merged[key] = mergeEntries({ oldEntry: oldEntry[key], newEntry: newEntry[key] });\n } else {\n merged[key] = oldEntry[key];\n }\n }\n\n const defaultValue = merged.default;\n if (defaultValue) {\n if (Object.keys(merged).length === 1) {\n // flatten out the default condition\n return defaultValue;\n }\n\n // ensure the default is last (exports maps keys are ordered)\n delete merged.default;\n merged.default = defaultValue;\n }\n\n return merged as T;\n}\n"]}
1
+ {"version":3,"file":"addExportsMapEntry.js","sourceRoot":"","sources":["../../src/exportsMap/addExportsMapEntry.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,qBAAqB,EAAE,MAAM,mCAAmC,CAAC;AAC1E,OAAO,EACL,iBAAiB,GAGlB,MAAM,2CAA2C,CAAC;AA0CnD;;;;;;;GAOG;AACH,MAAM,CAAC,KAAK,UAAU,kBAAkB,CACtC,OAAkC,EAClC,OAIC;IAED,2FAA2F;IAC3F,uFAAuF;IACvF,4CAA4C;IAC5C,6CAA6C;IAC7C,MAAM,EAAE,OAAO,EAAE,WAAW,EAAE,oBAAoB,GAAG,CAAC,CAAC,OAAO,CAAC,MAAM,EAAE,QAAQ,EAAE,oBAAoB,EAAE,GAAG,OAAO,CAAC;IAClH,MAAM,EAAE,QAAQ,EAAE,GAAG,OAAO,CAAC;IAE7B,4FAA4F;IAC5F,qCAAqC;IACrC,IAAI,OAAO,KAAK,IAAI,IAAI,KAAK,CAAC,OAAO,CAAC,OAAO,CAAC,IAAI,OAAO,OAAO,KAAK,QAAQ,EAAE,CAAC;QAC9E,MAAM,IAAI,KAAK,CAAC,qEAAqE,IAAI,CAAC,SAAS,CAAC,OAAO,CAAC,EAAE,CAAC,CAAC;IAClH,CAAC;IAED,MAAM,SAAS,GAAG,MAAM,iBAAiB,CACvC;QACE,WAAW;QACX,QAAQ,EAAE,OAAO,CAAC,QAAQ,IAAI,OAAO,CAAC,UAAU,IAAI,EAAE;QACtD,oBAAoB;KACrB,EACD,EAAE,QAAQ,EAAE,CACb,CAAC;IAEF,OAAO,SAAS,CAAC,OAAO,EAAE,SAAS,CAAC,CAAC;AACvC,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,SAAS,CACvB,OAAoE,EACpE,SAAkC;IAElC,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AAM,CAAC,GAAG,CAAC,GAAG,QAAQ,CAAC,GAAG,CAAC,CAAC;QAC9B,CAAC;IACH,CAAC;IAED,MAAM,YAAY,GAAG,MAAM,CAAC,OAAO,CAAC;IACpC,IAAI,YAAY,EAAE,CAAC;QACjB,IAAI,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;YACrC,oCAAoC;YACpC,OAAO,YAAY,CAAC;QACtB,CAAC;QAED,6DAA6D;QAC7D,OAAO,MAAM,CAAC,OAAO,CAAC;QACtB,MAAM,CAAC,OAAO,GAAG,YAAY,CAAC;IAChC,CAAC;IAED,OAAO,MAAW,CAAC;AACrB,CAAC","sourcesContent":["import type { CloudpackConfig, PackageDefinitionsCache, GeneratedExports } from '@ms-cloudpack/common-types';\nimport { normalizeRelativePath } from '@ms-cloudpack/path-string-parsing';\nimport {\n findFileInPackage,\n type FindFileInPackageOptions,\n type FindFileInPackageResult,\n} from '../findFileInPackage/findFileInPackage.js';\n\n/**\n * Options for `addExportsMapEntry`.\n */\nexport interface AddExportsMapEntryOptions extends Pick<\n FindFileInPackageOptions,\n 'packagePath' | 'resolveWebExtensions'\n> {\n /**\n * The generated exports map to add the entry to.\n */\n exports: GeneratedExports;\n\n /**\n * The import path to add the entry for. This is used as the key in the exports map.\n * Defaults to `'.'` (the package import).\n */\n importPath?: string;\n\n /**\n * The relative path to the physical file location, used to derive the exports map value.\n * Can be a partial location, in which case we'll search for the file and associated source/d.ts files.\n * Defaults to `importPath` if provided, or `'index.js'`.\n */\n filePath?: string;\n\n /**\n * Module type condition to add the entry for.\n * @default 'default'\n */\n requestCondition?: 'import' | 'require' | 'default';\n\n /**\n * The condition that describes the environment the entry is for.\n * Unspecified implies environmentally agnostic.\n * - `browser` is used for cases such as `browser` entries in package.json or implicit exports defined in routes.\n * - `node` is used for server rendering.\n */\n environmentCondition?: 'browser' | 'node';\n}\n\n/**\n * Add an import path to an exports map. This is intended for use with generated exports maps,\n * either in the context of the generated config, or generated for a package which doesn't have\n * an exports map.\n *\n * Throws an error if the exports map passed in is not an object, or if the value of the key\n * being updated is an array (it should have been normalized to object format before calling).\n */\nexport async function addExportsMapEntry(\n options: AddExportsMapEntryOptions,\n context: {\n packages: PackageDefinitionsCache;\n /** @deprecated Pass `resolveWebExtensions` option directly */\n config?: Pick<CloudpackConfig, 'features'>;\n },\n): Promise<boolean> {\n // resolveWebExtensions should only be missing in weird dependency mismatch cases, and it's\n // rarely used anyway. In this context, definitions.get() could cause an infinite loop,\n // so fall back to checking the config only.\n // eslint-disable-next-line etc/no-deprecated\n const { exports, packagePath, resolveWebExtensions = !!context.config?.features?.resolveWebExtensions } = options;\n const { packages } = context;\n\n // We try to enforce these conditions in the types, but also do an explicit check in case of\n // casting or other unexpected input.\n if (exports === null || Array.isArray(exports) || typeof exports === 'string') {\n throw new Error(`Exports passed to addExportsMapEntry must be an object; received: ${JSON.stringify(exports)}`);\n }\n\n const foundFile = await findFileInPackage(\n {\n packagePath,\n filePath: options.filePath || options.importPath || '',\n resolveWebExtensions,\n },\n { packages },\n );\n\n return _addEntry(options, foundFile);\n}\n\n/**\n * Internal logic of adding an entry to an exports map.\n * Exported for testing this logic separately from the filesystem parts.\n * @internal\n */\nexport function _addEntry(\n options: Omit<AddExportsMapEntryOptions, 'packagePath' | 'filePath'>,\n foundFile: FindFileInPackageResult,\n): boolean {\n const { exports, environmentCondition, requestCondition = 'default' } = options;\n const { filePath, sourcePath } = foundFile;\n\n // Only do work if a file path was found.\n if (!filePath) {\n return false;\n }\n\n // Normalize the import path (this also converts undefined to '.')\n const importPath = normalizeRelativePath(options.importPath);\n\n const oldEntry = exports[importPath];\n if (Array.isArray(oldEntry)) {\n // This should never happen with the standardized generated exports map format.\n // In theory we could handle it by pushing to the array, but nesting conditions inside arrays\n // isn't valid in the exports map spec.\n throw new Error(`Cannot add to an array of exports for \"${importPath}\"`);\n }\n\n let exportValue: string | Record<string, string>;\n\n if (!sourcePath && !requestCondition) {\n // If this is the only entry we're adding, set it to a string to minimize the exports map.\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] = filePath;\n\n if (requestCondition === 'default' && Object.keys(exportValue).length === 1) {\n // Only the default condition is present, so flatten to a string\n exportValue = filePath;\n }\n }\n\n const newEntry: GeneratedExports[string] = environmentCondition\n ? { [environmentCondition]: exportValue }\n : exportValue;\n\n exports[importPath] = mergeEntries({ oldEntry, newEntry });\n\n return true;\n}\n\n/**\n * This handles the merging of potential nested environment and request conditions, and ensures that\n * the `default` key is in the correct order (always last).\n */\nfunction mergeEntries<T extends string | Record<string, T>>(params: {\n oldEntry: T | null | undefined;\n newEntry: T;\n}): T {\n const { oldEntry, newEntry } = params;\n\n if (!oldEntry) {\n return newEntry;\n }\n\n // If oldEntry is a string... (using !== object instead of === string so TS infers the correct type later)\n if (typeof oldEntry !== 'object') {\n // If newEntry is an object without a default, use oldEntry as the default.\n if (typeof newEntry === 'object' && !newEntry.default) {\n return { ...newEntry, default: oldEntry };\n }\n // Otherwise ignore oldEntry.\n return newEntry;\n }\n\n if (typeof newEntry !== 'object') {\n // oldEntry object, newEntry string => use newEntry as default\n return { ...oldEntry, default: newEntry };\n }\n\n // both objects => full merge (the typings get imprecise here)\n const merged: Record<string, T> = {};\n // put the new keys first in the merged object (this could be made configurable later if needed)\n const allKeys = new Set([...Object.keys(newEntry), ...Object.keys(oldEntry)]);\n for (const key of allKeys) {\n if (newEntry[key]) {\n merged[key] = mergeEntries({ oldEntry: oldEntry[key], newEntry: newEntry[key] });\n } else {\n merged[key] = oldEntry[key];\n }\n }\n\n const defaultValue = merged.default;\n if (defaultValue) {\n if (Object.keys(merged).length === 1) {\n // flatten out the default condition\n return defaultValue;\n }\n\n // ensure the default is last (exports maps keys are ordered)\n delete merged.default;\n merged.default = defaultValue;\n }\n\n return merged as T;\n}\n"]}
@@ -1,15 +1,18 @@
1
- import type { CloudpackConfig, PackageDefinitionsCache, PackageJsonExports } from '@ms-cloudpack/common-types';
1
+ import type { PackageDefinitionsCache, PackageJsonExports } from '@ms-cloudpack/common-types';
2
+ import { type AddExportsMapEntryOptions } from './addExportsMapEntry.js';
3
+ export interface CreateExportsMapOptions extends Pick<AddExportsMapEntryOptions, 'packagePath' | 'resolveWebExtensions'> {
4
+ /**
5
+ * If true, create the exports map based on the original package definition, not the
6
+ * transformed one.
7
+ */
8
+ disableTransforms?: boolean;
9
+ }
2
10
  /**
3
11
  * Given a package path, return its exports if already set (this could be from either the original
4
12
  * package.json or as generated by `createPackageSettingsTransform`), or otherwise generate an
5
13
  * exports map based on other fields in the package definition.
6
14
  */
7
- export declare function createExportsMap(options: {
8
- packagePath: string;
9
- disableTransforms?: boolean;
10
- resolveWebExtensions: boolean;
11
- }, context: {
15
+ export declare function createExportsMap(options: CreateExportsMapOptions, context: {
12
16
  packages: PackageDefinitionsCache;
13
- config: Pick<CloudpackConfig, 'features'>;
14
17
  }): Promise<PackageJsonExports>;
15
18
  //# sourceMappingURL=createExportsMap.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"createExportsMap.d.ts","sourceRoot":"","sources":["../../src/exportsMap/createExportsMap.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,eAAe,EACf,uBAAuB,EACvB,kBAAkB,EAEnB,MAAM,4BAA4B,CAAC;AAIpC;;;;GAIG;AACH,wBAAsB,gBAAgB,CACpC,OAAO,EAAE;IACP,WAAW,EAAE,MAAM,CAAC;IACpB,iBAAiB,CAAC,EAAE,OAAO,CAAC;IAC5B,oBAAoB,EAAE,OAAO,CAAC;CAC/B,EACD,OAAO,EAAE;IAAE,QAAQ,EAAE,uBAAuB,CAAC;IAAC,MAAM,EAAE,IAAI,CAAC,eAAe,EAAE,UAAU,CAAC,CAAA;CAAE,GACxF,OAAO,CAAC,kBAAkB,CAAC,CAyG7B"}
1
+ {"version":3,"file":"createExportsMap.d.ts","sourceRoot":"","sources":["../../src/exportsMap/createExportsMap.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,uBAAuB,EAAE,kBAAkB,EAAoB,MAAM,4BAA4B,CAAC;AAEhH,OAAO,EAAsB,KAAK,yBAAyB,EAAE,MAAM,yBAAyB,CAAC;AAE7F,MAAM,WAAW,uBAAwB,SAAQ,IAAI,CACnD,yBAAyB,EACzB,aAAa,GAAG,sBAAsB,CACvC;IACC;;;OAGG;IACH,iBAAiB,CAAC,EAAE,OAAO,CAAC;CAC7B;AAED;;;;GAIG;AACH,wBAAsB,gBAAgB,CACpC,OAAO,EAAE,uBAAuB,EAChC,OAAO,EAAE;IAAE,QAAQ,EAAE,uBAAuB,CAAA;CAAE,GAC7C,OAAO,CAAC,kBAAkB,CAAC,CAyG7B"}
@@ -1 +1 @@
1
- {"version":3,"file":"createExportsMap.js","sourceRoot":"","sources":["../../src/exportsMap/createExportsMap.ts"],"names":[],"mappings":"AAMA,OAAO,EAAE,qBAAqB,EAAE,MAAM,mCAAmC,CAAC;AAC1E,OAAO,EAAE,kBAAkB,EAAE,MAAM,yBAAyB,CAAC;AAE7D;;;;GAIG;AACH,MAAM,CAAC,KAAK,UAAU,gBAAgB,CACpC,OAIC,EACD,OAAyF;IAEzF,MAAM,EAAE,WAAW,EAAE,oBAAoB,EAAE,GAAG,OAAO,CAAC;IACtD,MAAM,EAAE,QAAQ,EAAE,GAAG,OAAO,CAAC;IAC7B,MAAM,UAAU,GAAG,MAAM,QAAQ,CAAC,GAAG,CAAC,WAAW,EAAE,EAAE,iBAAiB,EAAE,OAAO,CAAC,iBAAiB,EAAE,CAAC,CAAC;IAErG,qEAAqE;IACrE,IAAI,UAAU,CAAC,OAAO,EAAE,CAAC;QACvB,OAAO,UAAU,CAAC,OAAO,CAAC;IAC5B,CAAC;IAED,MAAM,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,GAAG,UAAU,CAAC;IACnD,2FAA2F;IAC3F,6FAA6F;IAC7F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E,EAAE,OAAO,CAAC,CAAC;YAC9G,CAAC,MAAM,kBAAkB,CAAC,EAAE,OAAO,EAAE,WAAW,EAAE,QAAQ,EAAE,YAAY,EAAE,oBAAoB,EAAE,EAAE,OAAO,CAAC,CAAC,CAAC;IAChH,CAAC;IAED,OAAO,OAAO,CAAC;AACjB,CAAC","sourcesContent":["import type {\n CloudpackConfig,\n PackageDefinitionsCache,\n PackageJsonExports,\n GeneratedExports,\n} 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, return its exports if already set (this could be from either the original\n * package.json or as generated by `createPackageSettingsTransform`), or otherwise generate an\n * exports map based on other fields in the package definition.\n */\nexport async function createExportsMap(\n options: {\n packagePath: string;\n disableTransforms?: boolean;\n resolveWebExtensions: boolean;\n },\n context: { packages: PackageDefinitionsCache; config: Pick<CloudpackConfig, 'features'> },\n): Promise<PackageJsonExports> {\n const { packagePath, resolveWebExtensions } = 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 // Use the GeneratedExports type internally because it matches up with the more constrained\n // format of the exports map we're creating here (and addExportsMapEntry requires this type).\n const exports: GeneratedExports = {};\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 resolveWebExtensions,\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 resolveWebExtensions,\n },\n context,\n );\n }\n\n if (module) {\n await addExportsMapEntry(\n {\n exports,\n packagePath,\n filePath: module,\n requestCondition: 'import',\n resolveWebExtensions,\n },\n context,\n );\n }\n\n if (browser) {\n if (typeof definition.browser === 'string') {\n await addExportsMapEntry(\n { exports, packagePath, filePath: definition.browser, environmentCondition: 'browser', resolveWebExtensions },\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 isDefaultModule = normalizeRelativePath(module) === normalizeRelativePath(key);\n const isDefaultMain = normalizeRelativePath(main) === normalizeRelativePath(key);\n\n let importPaths: string[];\n if (isDefaultMain || isDefaultModule) {\n importPaths = ['.'];\n } else {\n importPaths = [key, 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 environmentCondition: 'browser',\n requestCondition: isDefaultModule || (isDefaultMain && type === 'module') ? 'import' : undefined,\n resolveWebExtensions,\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', resolveWebExtensions }, context)) ||\n (await addExportsMapEntry({ exports, packagePath, filePath: './lib/main.js', resolveWebExtensions }, context)) ||\n (await addExportsMapEntry({ exports, packagePath, filePath: './index.js', resolveWebExtensions }, context));\n }\n\n return exports;\n}\n"]}
1
+ {"version":3,"file":"createExportsMap.js","sourceRoot":"","sources":["../../src/exportsMap/createExportsMap.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,qBAAqB,EAAE,MAAM,mCAAmC,CAAC;AAC1E,OAAO,EAAE,kBAAkB,EAAkC,MAAM,yBAAyB,CAAC;AAa7F;;;;GAIG;AACH,MAAM,CAAC,KAAK,UAAU,gBAAgB,CACpC,OAAgC,EAChC,OAA8C;IAE9C,MAAM,EAAE,WAAW,EAAE,oBAAoB,EAAE,GAAG,OAAO,CAAC;IACtD,MAAM,EAAE,QAAQ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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,oBAAoB,EAAE,EAAE,OAAO,CAAC,CAAC;YAC7G,CAAC,MAAM,kBAAkB,CAAC,EAAE,OAAO,EAAE,WAAW,EAAE,QAAQ,EAAE,eAAe,EAAE,oBAAoB,EAAE,EAAE,OAAO,CAAC,CAAC;YAC9G,CAAC,MAAM,kBAAkB,CAAC,EAAE,OAAO,EAAE,WAAW,EAAE,QAAQ,EAAE,YAAY,EAAE,oBAAoB,EAAE,EAAE,OAAO,CAAC,CAAC,CAAC;IAChH,CAAC;IAED,OAAO,OAAO,CAAC;AACjB,CAAC","sourcesContent":["import type { PackageDefinitionsCache, PackageJsonExports, GeneratedExports } from '@ms-cloudpack/common-types';\nimport { normalizeRelativePath } from '@ms-cloudpack/path-string-parsing';\nimport { addExportsMapEntry, type AddExportsMapEntryOptions } from './addExportsMapEntry.js';\n\nexport interface CreateExportsMapOptions extends Pick<\n AddExportsMapEntryOptions,\n 'packagePath' | 'resolveWebExtensions'\n> {\n /**\n * If true, create the exports map based on the original package definition, not the\n * transformed one.\n */\n disableTransforms?: boolean;\n}\n\n/**\n * Given a package path, return its exports if already set (this could be from either the original\n * package.json or as generated by `createPackageSettingsTransform`), or otherwise generate an\n * exports map based on other fields in the package definition.\n */\nexport async function createExportsMap(\n options: CreateExportsMapOptions,\n context: { packages: PackageDefinitionsCache },\n): Promise<PackageJsonExports> {\n const { packagePath, resolveWebExtensions } = 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 // Use the GeneratedExports type internally because it matches up with the more constrained\n // format of the exports map we're creating here (and addExportsMapEntry requires this type).\n const exports: GeneratedExports = {};\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 resolveWebExtensions,\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 resolveWebExtensions,\n },\n context,\n );\n }\n\n if (module) {\n await addExportsMapEntry(\n {\n exports,\n packagePath,\n filePath: module,\n requestCondition: 'import',\n resolveWebExtensions,\n },\n context,\n );\n }\n\n if (browser) {\n if (typeof definition.browser === 'string') {\n await addExportsMapEntry(\n { exports, packagePath, filePath: definition.browser, environmentCondition: 'browser', resolveWebExtensions },\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 isDefaultModule = normalizeRelativePath(module) === normalizeRelativePath(key);\n const isDefaultMain = normalizeRelativePath(main) === normalizeRelativePath(key);\n\n let importPaths: string[];\n if (isDefaultMain || isDefaultModule) {\n importPaths = ['.'];\n } else {\n importPaths = [key, 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 environmentCondition: 'browser',\n requestCondition: isDefaultModule || (isDefaultMain && type === 'module') ? 'import' : undefined,\n resolveWebExtensions,\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', resolveWebExtensions }, context)) ||\n (await addExportsMapEntry({ exports, packagePath, filePath: './lib/main.js', resolveWebExtensions }, context)) ||\n (await addExportsMapEntry({ exports, packagePath, filePath: './index.js', resolveWebExtensions }, context));\n }\n\n return exports;\n}\n"]}
@@ -1,4 +1,5 @@
1
- import type { CloudpackConfig, PackageDefinitionsCache, PackageJsonExports } from '@ms-cloudpack/common-types';
1
+ import type { CloudpackConfig, PackageDefinitionsCache, PackageJsonExports, WithOptional } from '@ms-cloudpack/common-types';
2
+ import { type CreateExportsMapOptions } from './createExportsMap.js';
2
3
  /**
3
4
  * Get a package's provided exports map, or create one based on other entry info and the
4
5
  * package structure as a fallback.
@@ -7,18 +8,14 @@ import type { CloudpackConfig, PackageDefinitionsCache, PackageJsonExports } fro
7
8
  * by `createPackageSettingsTransform`. (Exception is tests within `package-utilities` or other
8
9
  * contexts that didn't use `createPackageDefinitions`.)
9
10
  */
10
- export declare function getExportsMap(options: {
11
- packagePath: string;
12
- disableTransforms: boolean;
13
- resolveWebExtensions: boolean;
14
- }, context: {
11
+ export declare function getExportsMap(options: Required<CreateExportsMapOptions>, context: {
15
12
  packages: PackageDefinitionsCache;
16
- config: Pick<CloudpackConfig, 'features'>;
13
+ /** @deprecated Pass `resolveWebExtensions` option directly */
14
+ config?: Pick<CloudpackConfig, 'features'>;
17
15
  }): Promise<PackageJsonExports>;
18
- export declare function getExportsMap(options: {
19
- packagePath: string;
20
- }, context: {
16
+ export declare function getExportsMap(options: WithOptional<Omit<CreateExportsMapOptions, 'disableTransforms'>, 'resolveWebExtensions'>, context: {
21
17
  packages: PackageDefinitionsCache;
22
- config: Pick<CloudpackConfig, 'features'>;
18
+ /** @deprecated Pass `resolveWebExtensions` option directly */
19
+ config?: Pick<CloudpackConfig, 'features'>;
23
20
  }): Promise<PackageJsonExports>;
24
21
  //# sourceMappingURL=getExportsMap.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"getExportsMap.d.ts","sourceRoot":"","sources":["../../src/exportsMap/getExportsMap.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,eAAe,EAE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O,EAAE;IACP,QAAQ,EAAE,uBAAuB,CAAC;IAClC,8DAA8D;IAC9D,MAAM,CAAC,EAAE,IAAI,CAAC,eAAe,EAAE,UAAU,CAAC,CAAC;CAC5C,GACA,OAAO,CAAC,kBAAkB,CAAC,CAAC"}
@@ -4,7 +4,7 @@ export async function getExportsMap(options, context) {
4
4
  const { packagePath, disableTransforms } = options;
5
5
  const { packages } = context;
6
6
  const definition = await packages.get(packagePath, options);
7
- if (disableTransforms !== undefined && options.resolveWebExtensions === undefined) {
7
+ if (disableTransforms && options.resolveWebExtensions === undefined) {
8
8
  // When disableTransforms is defined, we need to know if we should resolve web extensions.
9
9
  throw new Error('resolveWebExtensions is required when disableTransforms is true (this is a Cloudpack bug).');
10
10
  }
@@ -17,7 +17,7 @@ export async function getExportsMap(options, context) {
17
17
  resolveWebExtensions: options.resolveWebExtensions ??
18
18
  bundlerCapabilities['resolve-web-extensions'] ??
19
19
  // eslint-disable-next-line etc/no-deprecated
20
- !!context.config.features?.resolveWebExtensions,
20
+ !!context.config?.features?.resolveWebExtensions,
21
21
  }, context);
22
22
  }
23
23
  //# sourceMappingURL=getExportsMap.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"getExportsMap.js","sourceRoot":"","sources":["../../src/exportsMap/getExportsMap.ts"],"names":[],"mappings":"AAMA,OAAO,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAC;AAoBzD,iBAAiB;AACjB,MAAM,CAAC,KAAK,UAAU,aAAa,CACjC,OAA6F,EAC7F,OAAyF;IAEzF,MAAM,EAAE,WAAW,EAAE,iBAAiB,EAAE,GAAG,OAAO,CAAC;IACnD,MAAM,EAAE,QAAQ,EAAE,GAAG,OAAO,CAAC;IAC7B,MAAM,UAAU,GAAG,MAAM,QAAQ,CAAC,GAAG,CAAC,WAAW,EAAE,OAAO,CAAC,CAAC;IAE5D,IAAI,iBAAiB,KAAK,SAAS,IAAI,OAAO,CAAC,oBAAoB,KAAK,SAAS,EAAE,CAAC;QAClF,0FAA0F;QAC1F,MAAM,IAAI,KAAK,CAAC,4FAA4F,CAAC,CAAC;IAChH,CAAC;IAED,IAAI,UAAU,CAAC,OAAO,KAAK,SAAS,EAAE,CAAC;QACrC,OAAO,UAAU,CAAC,OAAO,CAAC;IAC5B,CAAC;IAED,MAAM,mBAAmB,GAAG,CAAC,UAAU,CAAC,SAAS,EAAE,mBAAmB,IAAI,EAAE,CAAuC,CAAC;IAEpH,OAAO,gBAAgB,CACrB;QACE,GAAG,OAAO;QACV,oBAAoB,EAClB,OAAO,CAAC,oBAAoB;YAC5B,mBAAmB,CAAC,wBAAwB,CAAC;YAC7C,6CAA6C;YAC7C,CAAC,CAAC,OAAO,CAAC,MAAM,CAAC,QAAQ,EAAE,oBAAoB;KAClD,EACD,OAAO,CACR,CAAC;AACJ,CAAC","sourcesContent":["import type {\n CloudpackConfig,\n InternalBundlerCapabilitiesOptions,\n PackageDefinitionsCache,\n PackageJsonExports,\n} from '@ms-cloudpack/common-types';\nimport { createExportsMap } from './createExportsMap.js';\n\n/**\n * Get a package's provided exports map, or create one based on other entry info and the\n * package structure as a fallback.\n *\n * NOTE: Unless `disableTransforms` is true, this will use the cached exports map that was created\n * by `createPackageSettingsTransform`. (Exception is tests within `package-utilities` or other\n * contexts that didn't use `createPackageDefinitions`.)\n */\n// When disableTransforms is defined, resolveWebExtensions is required\nexport async function getExportsMap(\n options: { packagePath: string; disableTransforms: boolean; resolveWebExtensions: boolean },\n context: { packages: PackageDefinitionsCache; config: Pick<CloudpackConfig, 'features'> },\n): Promise<PackageJsonExports>;\n// When disableTransforms is undefined, resolveWebExtensions is not required since we can get it from cached settings\nexport async function getExportsMap(\n options: { packagePath: string },\n context: { packages: PackageDefinitionsCache; config: Pick<CloudpackConfig, 'features'> },\n): Promise<PackageJsonExports>;\n// Implementation\nexport async function getExportsMap(\n options: { packagePath: string; disableTransforms?: boolean; resolveWebExtensions?: boolean },\n context: { packages: PackageDefinitionsCache; config: Pick<CloudpackConfig, 'features'> },\n): Promise<PackageJsonExports> {\n const { packagePath, disableTransforms } = options;\n const { packages } = context;\n const definition = await packages.get(packagePath, options);\n\n if (disableTransforms !== undefined && options.resolveWebExtensions === undefined) {\n // When disableTransforms is defined, we need to know if we should resolve web extensions.\n throw new Error('resolveWebExtensions is required when disableTransforms is true (this is a Cloudpack bug).');\n }\n\n if (definition.exports !== undefined) {\n return definition.exports;\n }\n\n const bundlerCapabilities = (definition.cloudpack?.bundlerCapabilities || {}) as InternalBundlerCapabilitiesOptions;\n\n return createExportsMap(\n {\n ...options,\n resolveWebExtensions:\n options.resolveWebExtensions ??\n bundlerCapabilities['resolve-web-extensions'] ??\n // eslint-disable-next-line etc/no-deprecated\n !!context.config.features?.resolveWebExtensions,\n },\n context,\n );\n}\n"]}
1
+ {"version":3,"file":"getExportsMap.js","sourceRoot":"","sources":["../../src/exportsMap/getExportsMap.ts"],"names":[],"mappings":"AAOA,OAAO,EAAE,gBAAgB,EAAgC,MAAM,uBAAuB,CAAC;AA4BvF,iBAAiB;AACjB,MAAM,CAAC,KAAK,UAAU,aAAa,CACjC,OAA6F,EAC7F,OAA0F;IAE1F,MAAM,EAAE,WAAW,EAAE,iBAAiB,EAAE,GAAG,OAAO,CAAC;IACnD,MAAM,EAAE,QAAQ,EAAE,GAAG,OAAO,CAAC;IAC7B,MAAM,UAAU,GAAG,MAAM,QAAQ,CAAC,GAAG,CAAC,WAAW,EAAE,OAAO,CAAC,CAAC;IAE5D,IAAI,iBAAiB,IAAI,OAAO,CAAC,oBAAoB,KAAK,SAAS,EAAE,CAAC;QACpE,0FAA0F;QAC1F,MAAM,IAAI,KAAK,CAAC,4FAA4F,CAAC,CAAC;IAChH,CAAC;IAED,IAAI,UAAU,CAAC,OAAO,KAAK,SAAS,EAAE,CAAC;QACrC,OAAO,UAAU,CAAC,OAAO,CAAC;IAC5B,CAAC;IAED,MAAM,mBAAmB,GAAG,CAAC,UAAU,CAAC,SAAS,EAAE,mBAAmB,IAAI,EAAE,CAAuC,CAAC;IAEpH,OAAO,gBAAgB,CACrB;QACE,GAAG,OAAO;QACV,oBAAoB,EAClB,OAAO,CAAC,oBAAoB;YAC5B,mBAAmB,CAAC,wBAAwB,CAAC;YAC7C,6CAA6C;YAC7C,CAAC,CAAC,OAAO,CAAC,MAAM,EAAE,QAAQ,EAAE,oBAAoB;KACnD,EACD,OAAO,CACR,CAAC;AACJ,CAAC","sourcesContent":["import type {\n CloudpackConfig,\n InternalBundlerCapabilitiesOptions,\n PackageDefinitionsCache,\n PackageJsonExports,\n WithOptional,\n} from '@ms-cloudpack/common-types';\nimport { createExportsMap, type CreateExportsMapOptions } from './createExportsMap.js';\n\n/**\n * Get a package's provided exports map, or create one based on other entry info and the\n * package structure as a fallback.\n *\n * NOTE: Unless `disableTransforms` is true, this will use the cached exports map that was created\n * by `createPackageSettingsTransform`. (Exception is tests within `package-utilities` or other\n * contexts that didn't use `createPackageDefinitions`.)\n */\n// When disableTransforms is defined, resolveWebExtensions is required\nexport async function getExportsMap(\n options: Required<CreateExportsMapOptions>,\n context: {\n packages: PackageDefinitionsCache;\n /** @deprecated Pass `resolveWebExtensions` option directly */\n config?: Pick<CloudpackConfig, 'features'>;\n },\n): Promise<PackageJsonExports>;\n// When disableTransforms is undefined, resolveWebExtensions is not required since we can get it from cached settings\nexport async function getExportsMap(\n options: WithOptional<Omit<CreateExportsMapOptions, 'disableTransforms'>, 'resolveWebExtensions'>,\n context: {\n packages: PackageDefinitionsCache;\n /** @deprecated Pass `resolveWebExtensions` option directly */\n config?: Pick<CloudpackConfig, 'features'>;\n },\n): Promise<PackageJsonExports>;\n// Implementation\nexport async function getExportsMap(\n options: { packagePath: string; disableTransforms?: boolean; resolveWebExtensions?: boolean },\n context: { packages: PackageDefinitionsCache; config?: Pick<CloudpackConfig, 'features'> },\n): Promise<PackageJsonExports> {\n const { packagePath, disableTransforms } = options;\n const { packages } = context;\n const definition = await packages.get(packagePath, options);\n\n if (disableTransforms && options.resolveWebExtensions === undefined) {\n // When disableTransforms is defined, we need to know if we should resolve web extensions.\n throw new Error('resolveWebExtensions is required when disableTransforms is true (this is a Cloudpack bug).');\n }\n\n if (definition.exports !== undefined) {\n return definition.exports;\n }\n\n const bundlerCapabilities = (definition.cloudpack?.bundlerCapabilities || {}) as InternalBundlerCapabilitiesOptions;\n\n return createExportsMap(\n {\n ...options,\n resolveWebExtensions:\n options.resolveWebExtensions ??\n bundlerCapabilities['resolve-web-extensions'] ??\n // eslint-disable-next-line etc/no-deprecated\n !!context.config?.features?.resolveWebExtensions,\n },\n context,\n );\n}\n"]}
@@ -1,25 +1,40 @@
1
1
  import type { CloudpackConfig, PackageDefinitionsCache } from '@ms-cloudpack/common-types';
2
- export type FindFileInPackageOptions = {
2
+ export interface FindFileInPackageOptions {
3
+ /** Absolute path to the package root, used to resolve relative paths. */
3
4
  packagePath: string;
5
+ /**
6
+ * The relative path to the physical file location.
7
+ * Can be a partial location, in which case we'll search for the file.
8
+ */
4
9
  filePath: string;
10
+ /** Whether to try `.web.*` extensions when resolving files. */
5
11
  resolveWebExtensions: boolean;
6
- };
7
- export type FindFileInPackageResult = {
12
+ }
13
+ export interface FindFileInPackageResult {
14
+ /**
15
+ * Relative path to the resolved file (if found), with leading `./`
16
+ */
8
17
  filePath?: string;
18
+ /**
19
+ * For internal packages only: relative path to the corresponding source file (if found),
20
+ * with leading `./`
21
+ */
9
22
  sourcePath?: string;
10
- };
23
+ }
11
24
  /**
12
- * Given a requested partial filePath, resolves the relative intermediate path if the file exists, with special
13
- * consideration for internal packages, which may not have intermediate files but only source files. Paths returned
14
- * are always relative and start with `./`.
25
+ * Given a requested partial `filePath`, resolves the relative intermediate path if the file exists,
26
+ * with special consideration for internal packages (which may not have intermediate files, only
27
+ * source files).
15
28
  *
16
- * This helper is used in deriving if the given package.json entries are actual validate candidates when constructing an
17
- * exports map from existing metadata. For example, a package.json may list `main` as `lib/index.js`. If this file
18
- * exists, or in internal packages, if `src/index.tsx` exists, then this is a valid candidate. If the file does not
19
- * exist, then we should not include it in the exports map.
29
+ * This helper is used in deriving if the given package.json entries are actual validate candidates
30
+ * when constructing an exports map from existing metadata. For example, a package.json may list
31
+ * `main` as `lib/index.js`. If this file exists, or in internal packages, if `src/index.tsx` exists,
32
+ * then this is a valid candidate. If the file does not exist, then we should not include it in the
33
+ * exports map.
20
34
  */
21
35
  export declare function findFileInPackage(options: FindFileInPackageOptions, context: {
22
36
  packages: PackageDefinitionsCache;
23
- config: Pick<CloudpackConfig, 'features'>;
37
+ /** @deprecated Pass `resolveWebExtensions` directly instead */
38
+ config?: Pick<CloudpackConfig, 'features'>;
24
39
  }): Promise<FindFileInPackageResult>;
25
40
  //# sourceMappingURL=findFileInPackage.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"findFileInPackage.d.ts","sourceRoot":"","sources":["../../src/findFileInPackage/findFileInPackage.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,uBAAuB,EAAE,MAAM,4BAA4B,CAAC;AAe3F,MAAM,MAAM,wBAAwB,GAAG;IACrC,WAAW,EAAE,MAAM,CAAC;IACpB,QAAQ,EAAE,MAAM,CAAC;IACjB,oBAAoB,EAAE,OAAO,CAAC;CAC/B,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,CA2FlC"}
1
+ {"version":3,"file":"findFileInPackage.d.ts","sourceRoot":"","sources":["../../src/findFileInPackage/findFileInPackage.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,uBAAuB,EAAE,MAAM,4BAA4B,CAAC;AAe3F,MAAM,WAAW,wBAAwB;IACvC,yEAAyE;IACzE,WAAW,EAAE,MAAM,CAAC;IACpB;;;OAGG;IACH,QAAQ,EAAE,MAAM,CAAC;IACjB,+DAA+D;IAC/D,oBAAoB,EAAE,OAAO,CAAC;CAC/B;AAED,MAAM,WAAW,uBAAuB;IACtC;;OAEG;IACH,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB;;;OAGG;IACH,UAAU,CAAC,EAAE,MAAM,CAAC;CACrB;AAED;;;;;;;;;;GAUG;AACH,wBAAsB,iBAAiB,CACrC,OAAO,EAAE,wBAAwB,EACjC,OAAO,EAAE;IACP,QAAQ,EAAE,uBAAuB,CAAC;IAClC,+DAA+D;IAC/D,MAAM,CAAC,EAAE,IAAI,CAAC,eAAe,EAAE,UAAU,CAAC,CAAC;CAC5C,GACA,OAAO,CAAC,uBAAuB,CAAC,CAoGlC"}
@@ -5,24 +5,30 @@ import { flattenExportsMap } from '../exportsMap/flattenExportsMap.js';
5
5
  import { getCandidates } from './getCandidates.js';
6
6
  import { getExportsMap } from '../exportsMap/getExportsMap.js';
7
7
  /**
8
- * Given a requested partial filePath, resolves the relative intermediate path if the file exists, with special
9
- * consideration for internal packages, which may not have intermediate files but only source files. Paths returned
10
- * are always relative and start with `./`.
8
+ * Given a requested partial `filePath`, resolves the relative intermediate path if the file exists,
9
+ * with special consideration for internal packages (which may not have intermediate files, only
10
+ * source files).
11
11
  *
12
- * This helper is used in deriving if the given package.json entries are actual validate candidates when constructing an
13
- * exports map from existing metadata. For example, a package.json may list `main` as `lib/index.js`. If this file
14
- * exists, or in internal packages, if `src/index.tsx` exists, then this is a valid candidate. If the file does not
15
- * exist, then we should not include it in the exports map.
12
+ * This helper is used in deriving if the given package.json entries are actual validate candidates
13
+ * when constructing an exports map from existing metadata. For example, a package.json may list
14
+ * `main` as `lib/index.js`. If this file exists, or in internal packages, if `src/index.tsx` exists,
15
+ * then this is a valid candidate. If the file does not exist, then we should not include it in the
16
+ * exports map.
16
17
  */
17
18
  export async function findFileInPackage(options, context) {
18
- const { resolveWebExtensions } = options;
19
+ // resolveWebExtensions should only be missing in weird dependency mismatch cases, and it's
20
+ // rarely used anyway. In this context, definitions.get() could cause an infinite loop,
21
+ // so fall back to checking the config only.
22
+ // eslint-disable-next-line etc/no-deprecated
23
+ const { resolveWebExtensions = !!context.config?.features?.resolveWebExtensions } = options;
24
+ const { packages } = context;
19
25
  const originalPath = normalizeRelativePath(options.filePath);
20
26
  const packagePath = slash(options.packagePath);
27
+ const isInternal = !isExternalPackage(packagePath);
21
28
  let filePath;
22
29
  let sourcePath;
23
- const isInternal = !isExternalPackage(packagePath);
24
30
  const pathsToConsider = [originalPath];
25
- const originalDefinition = await context.packages.tryGet(packagePath, { disableTransforms: true });
31
+ const originalDefinition = await packages.tryGet(packagePath, { disableTransforms: true });
26
32
  // If the original package.json has an exports map, we should not use main and module as hints.
27
33
  if (originalPath === '.' && originalDefinition && !originalDefinition.exports) {
28
34
  const { main, module } = originalDefinition;
@@ -42,18 +48,18 @@ export async function findFileInPackage(options, context) {
42
48
  }
43
49
  }
44
50
  for (const currentPath of pathsToConsider) {
45
- const candidates = await getCandidates({ filePath: currentPath, packagePath, resolveWebExtensions }, context);
51
+ const candidates = await getCandidates({ filePath: currentPath, packagePath, resolveWebExtensions }, { packages });
46
52
  // Try and resolve a physical file given the candidates.
47
53
  filePath = candidates.find((candidate) => isFileSync(path.join(packagePath, candidate)));
48
54
  if (filePath) {
49
55
  break;
50
56
  }
51
57
  }
52
- const isNestedPackageDefinition = filePath && path.basename(filePath) === 'package.json' && path.basename(originalPath) !== 'package.json';
53
58
  const result = {};
54
- if (isNestedPackageDefinition) {
59
+ if (filePath && path.basename(filePath) === 'package.json' && path.basename(originalPath) !== 'package.json') {
60
+ // Nested package.json reference
55
61
  const nestedDefinitionPath = path.dirname(path.join(packagePath, filePath));
56
- const exportsMap = await getExportsMap({ packagePath: nestedDefinitionPath }, context);
62
+ const exportsMap = await getExportsMap({ packagePath: nestedDefinitionPath, resolveWebExtensions: options.resolveWebExtensions }, { packages });
57
63
  const entryPath = flattenExportsMap(exportsMap)['.'];
58
64
  if (entryPath) {
59
65
  return findFileInPackage({
@@ -1 +1 @@
1
- {"version":3,"file":"findFileInPackage.js","sourceRoot":"","sources":["../../src/findFileInPackage/findFileInPackage.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,qBAAqB,EAAE,KAAK,EAAE,MAAM,mCAAmC,CAAC;AACjF,OAAO,EACL,wBAAwB,EACxB,iBAAiB,EACjB,UAAU,EACV,YAAY,EACZ,wBAAwB,EACxB,qBAAqB,GACtB,MAAM,8BAA8B,CAAC;AACtC,OAAO,IAAI,MAAM,MAAM,CAAC;AACxB,OAAO,EAAE,iBAAiB,EAAE,MAAM,oCAAoC,CAAC;AACvE,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AACnD,OAAO,EAAE,aAAa,EAAE,MAAM,gCAAgC,CAAC;AAa/D;;;;;;;;;GASG;AACH,MAAM,CAAC,KAAK,UAAU,iBAAiB,CACrC,OAAiC,EACjC,OAAyF;IAEzF,MAAM,EAAE,oBAAoB,EAAE,GAAG,OAAO,CAAC;IACzC,MAAM,YAAY,GAAG,qBAAqB,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAC;IAC7D,MAAM,WAAW,GAAG,KAAK,CAAC,OAAO,CAAC,WAAW,CAAC,CAAC;IAC/C,IAAI,QAA4B,CAAC;IACjC,IAAI,UAA8B,CAAC;IACnC,MAAM,UAAU,GAAG,CAAC,iBAAiB,CAAC,WAAW,CAAC,CAAC;IACnD,MAAM,eAAe,GAAG,CAAC,YAAY,CAAC,CAAC;IAEvC,MAAM,kBAAkB,GAAG,MAAM,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAC,WAAW,EAAE,EAAE,iBAAiB,EAAE,IAAI,EAAE,CAAC,CAAC;IACnG,+FAA+F;IAC/F,IAAI,YAAY,KAAK,GAAG,IAAI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C;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 {\n intermediateToSourcePath,\n isExternalPackage,\n isFileSync,\n plainJsRegex,\n sourceToIntermediatePath,\n transpiledSourceRegex,\n} from '@ms-cloudpack/path-utilities';\nimport path from 'path';\nimport { flattenExportsMap } from '../exportsMap/flattenExportsMap.js';\nimport { getCandidates } from './getCandidates.js';\nimport { getExportsMap } from '../exportsMap/getExportsMap.js';\n\nexport type FindFileInPackageOptions = {\n packagePath: string;\n filePath: string;\n resolveWebExtensions: boolean;\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 { resolveWebExtensions } = options;\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 originalDefinition = 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 === '.' && originalDefinition && !originalDefinition.exports) {\n const { main, module } = originalDefinition;\n if (main) {\n pathsToConsider.unshift(main);\n }\n if (module) {\n pathsToConsider.unshift(module);\n }\n }\n\n if (originalDefinition && originalDefinition.exports) {\n // Pass in packagePath so that we can expand wildcards in the exports map.\n const expandedExportsMap = flattenExportsMap(originalDefinition.exports, { packagePath });\n if (expandedExportsMap[originalPath]) {\n // If the original path is an entry in the exports map, we should use that as a candidate.\n pathsToConsider.unshift(expandedExportsMap[originalPath]);\n }\n }\n\n for (const currentPath of pathsToConsider) {\n const candidates = await getCandidates({ filePath: currentPath, packagePath, resolveWebExtensions }, 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 resolveWebExtensions: options.resolveWebExtensions,\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 && transpiledSourceRegex.test(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 && plainJsRegex.test(filePath)) {\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 if (filePath) {\n result.filePath = normalizeRelativePath(filePath);\n }\n\n if (sourcePath) {\n result.sourcePath = normalizeRelativePath(sourcePath);\n }\n\n return result;\n}\n"]}
1
+ {"version":3,"file":"findFileInPackage.js","sourceRoot":"","sources":["../../src/findFileInPackage/findFileInPackage.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,qBAAqB,EAAE,KAAK,EAAE,MAAM,mCAAmC,CAAC;AACjF,OAAO,EACL,wBAAwB,EACxB,iBAAiB,EACjB,UAAU,EACV,YAAY,EACZ,wBAAwB,EACxB,qBAAqB,GACtB,MAAM,8BAA8B,CAAC;AACtC,OAAO,IAAI,MAAM,MAAM,CAAC;AACxB,OAAO,EAAE,iBAAiB,EAAE,MAAM,oCAAoC,CAAC;AACvE,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AACnD,OAAO,EAAE,aAAa,EAAE,MAAM,gCAAgC,CAAC;AA0B/D;;;;;;;;;;GAUG;AACH,MAAM,CAAC,KAAK,UAAU,iBAAiB,CACrC,OAAiC,EACjC,OAIC;IAED,2FAA2F;IAC3F,uFAAuF;IACvF,4CAA4C;IAC5C,6CAA6C;IAC7C,MAAM,EAAE,oBAAoB,GAAG,CAAC,CAAC,OAAO,CAAC,MAAM,EAAE,QAAQ,EAAE,oBAAoB,EAAE,GAAG,OAAO,CAAC;IAC5F,MAAM,EAAE,QAAQ,EAAE,GAAG,OAAO,CAAC;IAE7B,MAAM,YAAY,GAAG,qBAAqB,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAC;IAC7D,MAAM,WAAW,GAAG,KAAK,CAAC,OAAO,CAAC,WAAW,CAAC,CAAC;IAC/C,MAAM,UAAU,GAAG,CAAC,iBAAiB,CAAC,WAAW,CAAC,CAAC;IAEnD,IAAI,QAA4B,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I,UAAU,IAAI,QAAQ,IAAI,CAAC,UAAU,IAAI,YAAY,CAAC,IAAI,CAAC,QAAQ,CAAC,EAAE,CAAC;QACzE,wDAAwD;QACxD,UAAU,GAAG,wBAAwB,CAAC,QAAQ,EAAE,WAAW,CAAC,CAAC;QAE7D,mDAAmD;QACnD,IAAI,UAAU,KAAK,QAAQ,EAAE,CAAC;YAC5B,UAAU,GAAG,SAAS,CAAC;QACzB,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 {\n intermediateToSourcePath,\n isExternalPackage,\n isFileSync,\n plainJsRegex,\n sourceToIntermediatePath,\n transpiledSourceRegex,\n} from '@ms-cloudpack/path-utilities';\nimport path from 'path';\nimport { flattenExportsMap } from '../exportsMap/flattenExportsMap.js';\nimport { getCandidates } from './getCandidates.js';\nimport { getExportsMap } from '../exportsMap/getExportsMap.js';\n\nexport interface FindFileInPackageOptions {\n /** Absolute path to the package root, used to resolve relative paths. */\n packagePath: string;\n /**\n * The relative path to the physical file location.\n * Can be a partial location, in which case we'll search for the file.\n */\n filePath: string;\n /** Whether to try `.web.*` extensions when resolving files. */\n resolveWebExtensions: boolean;\n}\n\nexport interface FindFileInPackageResult {\n /**\n * Relative path to the resolved file (if found), with leading `./`\n */\n filePath?: string;\n /**\n * For internal packages only: relative path to the corresponding source file (if found),\n * with leading `./`\n */\n sourcePath?: string;\n}\n\n/**\n * Given a requested partial `filePath`, resolves the relative intermediate path if the file exists,\n * with special consideration for internal packages (which may not have intermediate files, only\n * source files).\n *\n * This helper is used in deriving if the given package.json entries are actual validate candidates\n * when constructing an exports map from existing metadata. For example, a package.json may list\n * `main` as `lib/index.js`. If this file exists, or in internal packages, if `src/index.tsx` exists,\n * then this is a valid candidate. If the file does not exist, then we should not include it in the\n * exports map.\n */\nexport async function findFileInPackage(\n options: FindFileInPackageOptions,\n context: {\n packages: PackageDefinitionsCache;\n /** @deprecated Pass `resolveWebExtensions` directly instead */\n config?: Pick<CloudpackConfig, 'features'>;\n },\n): Promise<FindFileInPackageResult> {\n // resolveWebExtensions should only be missing in weird dependency mismatch cases, and it's\n // rarely used anyway. In this context, definitions.get() could cause an infinite loop,\n // so fall back to checking the config only.\n // eslint-disable-next-line etc/no-deprecated\n const { resolveWebExtensions = !!context.config?.features?.resolveWebExtensions } = options;\n const { packages } = context;\n\n const originalPath = normalizeRelativePath(options.filePath);\n const packagePath = slash(options.packagePath);\n const isInternal = !isExternalPackage(packagePath);\n\n let filePath: string | undefined;\n let sourcePath: string | undefined;\n const pathsToConsider = [originalPath];\n\n const originalDefinition = await 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 === '.' && originalDefinition && !originalDefinition.exports) {\n const { main, module } = originalDefinition;\n if (main) {\n pathsToConsider.unshift(main);\n }\n if (module) {\n pathsToConsider.unshift(module);\n }\n }\n\n if (originalDefinition && originalDefinition.exports) {\n // Pass in packagePath so that we can expand wildcards in the exports map.\n const expandedExportsMap = flattenExportsMap(originalDefinition.exports, { packagePath });\n if (expandedExportsMap[originalPath]) {\n // If the original path is an entry in the exports map, we should use that as a candidate.\n pathsToConsider.unshift(expandedExportsMap[originalPath]);\n }\n }\n\n for (const currentPath of pathsToConsider) {\n const candidates = await getCandidates({ filePath: currentPath, packagePath, resolveWebExtensions }, { packages });\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 result: FindFileInPackageResult = {};\n\n if (filePath && path.basename(filePath) === 'package.json' && path.basename(originalPath) !== 'package.json') {\n // Nested package.json reference\n const nestedDefinitionPath = path.dirname(path.join(packagePath, filePath));\n const exportsMap = await getExportsMap(\n { packagePath: nestedDefinitionPath, resolveWebExtensions: options.resolveWebExtensions },\n { packages },\n );\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 resolveWebExtensions: options.resolveWebExtensions,\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 && transpiledSourceRegex.test(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 && plainJsRegex.test(filePath)) {\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 if (filePath) {\n result.filePath = normalizeRelativePath(filePath);\n }\n\n if (sourcePath) {\n result.sourcePath = normalizeRelativePath(sourcePath);\n }\n\n return result;\n}\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ms-cloudpack/package-utilities",
3
- "version": "13.3.4",
3
+ "version": "13.5.0",
4
4
  "description": "Utilities for resolving/parsing packages and their imports in Cloudpack",
5
5
  "license": "MIT",
6
6
  "type": "module",
@@ -29,7 +29,7 @@
29
29
  "@ms-cloudpack/json-utilities": "^0.1.11",
30
30
  "@ms-cloudpack/path-string-parsing": "^1.3.0",
31
31
  "@ms-cloudpack/path-utilities": "^3.2.5",
32
- "@ms-cloudpack/task-reporter": "^0.17.4",
32
+ "@ms-cloudpack/task-reporter": "^0.19.0",
33
33
  "acorn": "^8.11.2",
34
34
  "acorn-walk": "^8.2.1",
35
35
  "semver": "^7.6.0",