@ms-cloudpack/package-utilities 8.2.0 → 9.0.1

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.
@@ -28,9 +28,14 @@ export interface AddExportsMapEntryOptions {
28
28
  */
29
29
  typesPath?: string;
30
30
  /**
31
- * The condition to add the entry for. (Example: "import", "require", "browser", "types") Defaults to "default"
31
+ * The condition to add the entry for. (Example: "import", "require") Defaults to "default".
32
32
  */
33
- condition?: string;
33
+ requestCondition?: 'import' | 'require' | 'browser';
34
+ /**
35
+ * The condition that describes the environment the entry is for. (Example: "browser", "node".)
36
+ * Unspecified implies environmentally agnostic.
37
+ */
38
+ environmentCondition?: 'browser' | 'node';
34
39
  }
35
40
  /**
36
41
  * Given an exports map and details about an import path, adds the entry.
@@ -1 +1 @@
1
- {"version":3,"file":"addExportsMapEntry.d.ts","sourceRoot":"","sources":["../src/addExportsMapEntry.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,uBAAuB,EAAE,kBAAkB,EAAE,MAAM,4BAA4B,CAAC;AAI/G;;GAEG;AACH,MAAM,WAAW,yBAAyB;IACxC;;OAEG;IACH,OAAO,EAAE,kBAAkB,CAAC;IAE5B;;OAEG;IACH,WAAW,EAAE,MAAM,CAAC;IAEpB;;;OAGG;IACH,UAAU,CAAC,EAAE,MAAM,CAAC;IAEpB;;;;OAIG;IACH,QAAQ,CAAC,EAAE,MAAM,CAAC;IAElB;;;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,CAAC;IAAC,MAAM,EAAE,eAAe,CAAA;CAAE,GACtE,OAAO,CAAC,OAAO,CAAC,CAoDlB"}
1
+ {"version":3,"file":"addExportsMapEntry.d.ts","sourceRoot":"","sources":["../src/addExportsMapEntry.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,uBAAuB,EAAE,kBAAkB,EAAE,MAAM,4BAA4B,CAAC;AAI/G;;GAEG;AACH,MAAM,WAAW,yBAAyB;IACxC;;OAEG;IACH,OAAO,EAAE,kBAAkB,CAAC;IAE5B;;OAEG;IACH,WAAW,EAAE,MAAM,CAAC;IAEpB;;;OAGG;IACH,UAAU,CAAC,EAAE,MAAM,CAAC;IAEpB;;;;OAIG;IACH,QAAQ,CAAC,EAAE,MAAM,CAAC;IAElB;;;OAGG;IACH,SAAS,CAAC,EAAE,MAAM,CAAC;IAEnB;;OAEG;IACH,gBAAgB,CAAC,EAAE,QAAQ,GAAG,SAAS,GAAG,SAAS,CAAC;IAEpD;;;OAGG;IACH,oBAAoB,CAAC,EAAE,SAAS,GAAG,MAAM,CAAC;CAC3C;AAED;;GAEG;AACH,wBAAsB,kBAAkB,CACtC,OAAO,EAAE,yBAAyB,EAClC,OAAO,EAAE;IAAE,QAAQ,EAAE,uBAAuB,CAAC;IAAC,MAAM,EAAE,eAAe,CAAA;CAAE,GACtE,OAAO,CAAC,OAAO,CAAC,CA6ClB"}
@@ -4,7 +4,7 @@ import { findFileInPackage } from './findFileInPackage.js';
4
4
  * Given an exports map and details about an import path, adds the entry.
5
5
  */
6
6
  export async function addExportsMapEntry(options, context) {
7
- const { exports, packagePath, condition = 'default' } = options;
7
+ const { exports, packagePath, environmentCondition, requestCondition } = options;
8
8
  const importPath = normalizeRelativePath(options.importPath);
9
9
  const { filePath, sourcePath, typesPath = options.typesPath ? normalizeRelativePath(options.typesPath) : undefined, } = await findFileInPackage({
10
10
  packagePath,
@@ -16,28 +16,23 @@ export async function addExportsMapEntry(options, context) {
16
16
  }
17
17
  // Create a local for casting.
18
18
  const localExports = exports;
19
+ let exportValue;
19
20
  // If this is the only entry we're adding, set it to a string to minimize the exports map.
20
- if (!typesPath &&
21
- !sourcePath &&
22
- condition === 'default' &&
23
- (!localExports[importPath] || typeof localExports[importPath] === 'string')) {
24
- localExports[importPath] = filePath;
21
+ if (!typesPath && !sourcePath && !requestCondition) {
22
+ exportValue = filePath;
25
23
  }
26
24
  else {
27
- let exportsEntry = (localExports[importPath] ??= {});
28
- // Promote string-based exports into objects with default conditions.
29
- if (typeof exportsEntry === 'string') {
30
- exportsEntry = exports[importPath] = { default: exportsEntry };
31
- }
25
+ exportValue = {};
32
26
  if (typesPath) {
33
- exportsEntry['types'] = typesPath;
27
+ exportValue['types'] = typesPath;
34
28
  }
35
29
  if (sourcePath) {
36
- exportsEntry['source'] = sourcePath;
30
+ exportValue['source'] = sourcePath;
37
31
  }
38
32
  // Add the entry for the condition.
39
- exportsEntry[condition] = filePath;
33
+ exportValue[requestCondition || 'default'] = filePath;
40
34
  }
35
+ localExports[importPath] = environmentCondition ? { [environmentCondition]: exportValue } : exportValue;
41
36
  return true;
42
37
  }
43
38
  //# sourceMappingURL=addExportsMapEntry.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"addExportsMapEntry.js","sourceRoot":"","sources":["../src/addExportsMapEntry.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,qBAAqB,EAAE,MAAM,mCAAmC,CAAC;AAC1E,OAAO,EAAE,iBAAiB,EAAE,MAAM,wBAAwB,CAAC;AAyC3D;;GAEG;AACH,MAAM,CAAC,KAAK,UAAU,kBAAkB,CACtC,OAAkC,EAClC,OAAuE;IAEvE,MAAM,EAAE,OAAO,EAAE,WAAW,EAAE,SAAS,GAAG,SAAS,EAAE,GAAG,OAAO,CAAC;IAChE,MAAM,UAAU,GAAG,qBAAqB,CAAC,OAAO,CAAC,UAAU,CAAC,CAAC;IAC7D,MAAM,EACJ,QAAQ,EACR,UAAU,EACV,SAAS,GAAG,OAAO,CAAC,SAAS,CAAC,CAAC,CAAC,qBAAqB,CAAC,OAAO,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC,SAAS,GACrF,GAAG,MAAM,iBAAiB,CACzB;QACE,WAAW;QACX,QAAQ,EAAE,OAAO,CAAC,QAAQ,IAAI,OAAO,CAAC,UAAU,IAAI,EAAE;KACvD,EACD,OAAO,CACR,CAAC;IAEF,yCAAyC;IACzC,IAAI,CAAC,QAAQ,EAAE,CAAC;QACd,OAAO,KAAK,CAAC;IACf,CAAC;IAED,8BAA8B;IAC9B,MAAM,YAAY,GAAG,OAA0D,CAAC;IAEhF,0FAA0F;IAC1F,IACE,CAAC,SAAS;QACV,CAAC,UAAU;QACX,SAAS,KAAK,SAAS;QACvB,CAAC,CAAC,YAAY,CAAC,UAAU,CAAC,IAAI,OAAO,YAAY,CAAC,UAAU,CAAC,KAAK,QAAQ,CAAC,EAC3E,CAAC;QACD,YAAY,CAAC,UAAU,CAAC,GAAG,QAAQ,CAAC;IACtC,CAAC;SAAM,CAAC;QACN,IAAI,YAAY,GAAG,CAAC,YAAY,CAAC,UAAU,CAAC,KAAK,EAAE,CAAC,CAAC;QAErD,qEAAqE;QACrE,IAAI,OAAO,YAAY,KAAK,QAAQ,EAAE,CAAC;YACrC,YAAY,GAAI,OAAkD,CAAC,UAAU,CAAC,GAAG,EAAE,OAAO,EAAE,YAAY,EAAE,CAAC;QAC7G,CAAC;QAED,IAAI,SAAS,EAAE,CAAC;YACd,YAAY,CAAC,OAAO,CAAC,GAAG,SAAS,CAAC;QACpC,CAAC;QAED,IAAI,UAAU,EAAE,CAAC;YACf,YAAY,CAAC,QAAQ,CAAC,GAAG,UAAU,CAAC;QACtC,CAAC;QAED,mCAAmC;QACnC,YAAY,CAAC,SAAS,CAAC,GAAG,QAAQ,CAAC;IACrC,CAAC;IAED,OAAO,IAAI,CAAC;AACd,CAAC","sourcesContent":["import type { CloudpackConfig, PackageDefinitionsCache, PackageJsonExports } from '@ms-cloudpack/common-types';\nimport { normalizeRelativePath } from '@ms-cloudpack/path-string-parsing';\nimport { findFileInPackage } from './findFileInPackage.js';\n\n/**\n * Options fo addExportsMapEntry.\n */\nexport interface AddExportsMapEntryOptions {\n /**\n * The exports map to add the entry to.\n */\n exports: PackageJsonExports;\n\n /**\n * The package path to add the entry for. This is used to resolve relative paths.\n */\n packagePath: string;\n\n /**\n * The import path to add the entry for. This is used as the key in the exports map. Defaults\n * to \".\" being the package import.\n */\n importPath?: string;\n\n /**\n * The relative path to the physical file location, representing the \"key\" in the exports map. Can be a partial\n * location, in which case we will attempt to search for the file and associated source/d.ts files. Defaults to\n * assuming `index.js`.\n */\n filePath?: string;\n\n /**\n * 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; config: CloudpackConfig },\n): Promise<boolean> {\n const { exports, packagePath, condition = 'default' } = options;\n const importPath = normalizeRelativePath(options.importPath);\n const {\n filePath,\n sourcePath,\n typesPath = options.typesPath ? normalizeRelativePath(options.typesPath) : undefined,\n } = await findFileInPackage(\n {\n packagePath,\n filePath: options.filePath || options.importPath || '',\n },\n context,\n );\n\n // Only do work if a file path was found.\n if (!filePath) {\n return false;\n }\n\n // Create a local for casting.\n const localExports = exports as Record<string, string | Record<string, string>>;\n\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 return true;\n}\n"]}
1
+ {"version":3,"file":"addExportsMapEntry.js","sourceRoot":"","sources":["../src/addExportsMapEntry.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,qBAAqB,EAAE,MAAM,mCAAmC,CAAC;AAC1E,OAAO,EAAE,iBAAiB,EAAE,MAAM,wBAAwB,CAAC;AA+C3D;;GAEG;AACH,MAAM,CAAC,KAAK,UAAU,kBAAkB,CACtC,OAAkC,EAClC,OAAuE;IAEvE,MAAM,EAAE,OAAO,EAAE,WAAW,EAAE,oBAAoB,EAAE,gBAAgB,EAAE,GAAG,OAAO,CAAC;IACjF,MAAM,UAAU,GAAG,qBAAqB,CAAC,OAAO,CAAC,UAAU,CAAC,CAAC;IAC7D,MAAM,EACJ,QAAQ,EACR,UAAU,EACV,SAAS,GAAG,OAAO,CAAC,SAAS,CAAC,CAAC,CAAC,qBAAqB,CAAC,OAAO,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC,SAAS,GACrF,GAAG,MAAM,iBAAiB,CACzB;QACE,WAAW;QACX,QAAQ,EAAE,OAAO,CAAC,QAAQ,IAAI,OAAO,CAAC,UAAU,IAAI,EAAE;KACvD,EACD,OAAO,CACR,CAAC;IAEF,yCAAyC;IACzC,IAAI,CAAC,QAAQ,EAAE,CAAC;QACd,OAAO,KAAK,CAAC;IACf,CAAC;IAED,8BAA8B;IAC9B,MAAM,YAAY,GAAG,OAAmF,CAAC;IACzG,IAAI,WAA4C,CAAC;IAEjD,0FAA0F;IAC1F,IAAI,CAAC,SAAS,IAAI,CAAC,UAAU,IAAI,CAAC,gBAAgB,EAAE,CAAC;QACnD,WAAW,GAAG,QAAQ,CAAC;IACzB,CAAC;SAAM,CAAC;QACN,WAAW,GAAG,EAAE,CAAC;QAEjB,IAAI,SAAS,EAAE,CAAC;YACd,WAAW,CAAC,OAAO,CAAC,GAAG,SAAS,CAAC;QACnC,CAAC;QAED,IAAI,UAAU,EAAE,CAAC;YACf,WAAW,CAAC,QAAQ,CAAC,GAAG,UAAU,CAAC;QACrC,CAAC;QAED,mCAAmC;QACnC,WAAW,CAAC,gBAAgB,IAAI,SAAS,CAAC,GAAG,QAAQ,CAAC;IACxD,CAAC;IAED,YAAY,CAAC,UAAU,CAAC,GAAG,oBAAoB,CAAC,CAAC,CAAC,EAAE,CAAC,oBAAoB,CAAC,EAAE,WAAW,EAAE,CAAC,CAAC,CAAC,WAAW,CAAC;IAExG,OAAO,IAAI,CAAC;AACd,CAAC","sourcesContent":["import type { CloudpackConfig, PackageDefinitionsCache, PackageJsonExports } from '@ms-cloudpack/common-types';\nimport { normalizeRelativePath } from '@ms-cloudpack/path-string-parsing';\nimport { findFileInPackage } from './findFileInPackage.js';\n\n/**\n * Options fo addExportsMapEntry.\n */\nexport interface AddExportsMapEntryOptions {\n /**\n * The exports map to add the entry to.\n */\n exports: PackageJsonExports;\n\n /**\n * The package path to add the entry for. This is used to resolve relative paths.\n */\n packagePath: string;\n\n /**\n * The import path to add the entry for. This is used as the key in the exports map. Defaults\n * to \".\" being the package import.\n */\n importPath?: string;\n\n /**\n * The relative path to the physical file location, representing the \"key\" in the exports map. Can be a partial\n * location, in which case we will attempt to search for the file and associated source/d.ts files. Defaults to\n * assuming `index.js`.\n */\n filePath?: string;\n\n /**\n * 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\") Defaults to \"default\".\n */\n requestCondition?: 'import' | 'require' | 'browser';\n\n /**\n * The condition that describes the environment the entry is for. (Example: \"browser\", \"node\".)\n * Unspecified implies environmentally agnostic.\n */\n environmentCondition?: 'browser' | 'node';\n}\n\n/**\n * Given an exports map and details about an import path, adds the entry.\n */\nexport async function addExportsMapEntry(\n options: AddExportsMapEntryOptions,\n context: { packages: PackageDefinitionsCache; config: CloudpackConfig },\n): Promise<boolean> {\n const { exports, packagePath, environmentCondition, requestCondition } = options;\n const importPath = normalizeRelativePath(options.importPath);\n const {\n filePath,\n sourcePath,\n typesPath = options.typesPath ? normalizeRelativePath(options.typesPath) : undefined,\n } = await findFileInPackage(\n {\n packagePath,\n filePath: options.filePath || options.importPath || '',\n },\n context,\n );\n\n // Only do work if a file path was found.\n if (!filePath) {\n return false;\n }\n\n // Create a local for casting.\n const localExports = exports as Record<string, string | Record<string, string | Record<string, string>>>;\n let exportValue: string | Record<string, string>;\n\n // If this is the only entry we're adding, set it to a string to minimize the exports map.\n if (!typesPath && !sourcePath && !requestCondition) {\n exportValue = filePath;\n } else {\n exportValue = {};\n\n if (typesPath) {\n exportValue['types'] = typesPath;\n }\n\n if (sourcePath) {\n exportValue['source'] = sourcePath;\n }\n\n // Add the entry for the condition.\n exportValue[requestCondition || 'default'] = filePath;\n }\n\n localExports[importPath] = environmentCondition ? { [environmentCondition]: exportValue } : exportValue;\n\n return true;\n}\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"createExportsMap.d.ts","sourceRoot":"","sources":["../src/createExportsMap.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,uBAAuB,EAAE,kBAAkB,EAAE,MAAM,4BAA4B,CAAC;AAI/G;;GAEG;AACH,wBAAsB,gBAAgB,CACpC,OAAO,EAAE;IACP,WAAW,EAAE,MAAM,CAAC;IACpB,iBAAiB,CAAC,EAAE,OAAO,CAAC;CAC7B,EACD,OAAO,EAAE;IAAE,QAAQ,EAAE,uBAAuB,CAAC;IAAC,MAAM,EAAE,eAAe,CAAA;CAAE,GACtE,OAAO,CAAC,kBAAkB,CAAC,CAqG7B"}
1
+ {"version":3,"file":"createExportsMap.d.ts","sourceRoot":"","sources":["../src/createExportsMap.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,uBAAuB,EAAE,kBAAkB,EAAE,MAAM,4BAA4B,CAAC;AAI/G;;GAEG;AACH,wBAAsB,gBAAgB,CACpC,OAAO,EAAE;IACP,WAAW,EAAE,MAAM,CAAC;IACpB,iBAAiB,CAAC,EAAE,OAAO,CAAC;CAC7B,EACD,OAAO,EAAE;IAAE,QAAQ,EAAE,uBAAuB,CAAC;IAAC,MAAM,EAAE,eAAe,CAAA;CAAE,GACtE,OAAO,CAAC,kBAAkB,CAAC,CAwG7B"}
@@ -24,7 +24,7 @@ export async function createExportsMap(options, context) {
24
24
  packagePath,
25
25
  filePath: 'index.js',
26
26
  typesPath,
27
- condition: type === 'module' ? 'import' : 'default',
27
+ requestCondition: type === 'module' ? 'import' : undefined,
28
28
  }, context);
29
29
  }
30
30
  if (main) {
@@ -33,7 +33,7 @@ export async function createExportsMap(options, context) {
33
33
  packagePath,
34
34
  filePath: main,
35
35
  typesPath,
36
- condition: type === 'module' ? 'import' : 'default',
36
+ requestCondition: type === 'module' ? 'import' : undefined,
37
37
  }, context);
38
38
  }
39
39
  if (module) {
@@ -42,12 +42,12 @@ export async function createExportsMap(options, context) {
42
42
  packagePath,
43
43
  filePath: module,
44
44
  typesPath,
45
- condition: 'import',
45
+ requestCondition: 'import',
46
46
  }, context);
47
47
  }
48
48
  if (browser) {
49
49
  if (typeof definition.browser === 'string') {
50
- await addExportsMapEntry({ exports, packagePath, filePath: definition.browser, condition: 'browser' }, context);
50
+ await addExportsMapEntry({ exports, packagePath, filePath: definition.browser, requestCondition: 'browser' }, context);
51
51
  }
52
52
  else if (typeof definition.browser === 'object') {
53
53
  for (const [key, value] of Object.entries(definition.browser)) {
@@ -65,7 +65,7 @@ export async function createExportsMap(options, context) {
65
65
  packagePath,
66
66
  importPath,
67
67
  filePath: value,
68
- condition: 'browser',
68
+ requestCondition: 'browser',
69
69
  }, context);
70
70
  }
71
71
  }
@@ -1 +1 @@
1
- {"version":3,"file":"createExportsMap.js","sourceRoot":"","sources":["../src/createExportsMap.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,qBAAqB,EAAE,MAAM,mCAAmC,CAAC;AAC1E,OAAO,EAAE,kB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W;wBACX,UAAU;wBACV,QAAQ,EAAE,KAAK;wBACf,SAAS,EAAE,SAAS;qBACrB,EACD,OAAO,CACR,CAAC;gBACJ,CAAC;YACH,CAAC;QACH,CAAC;IACH,CAAC;IAED,qEAAqE;IACrE,+CAA+C;IAC/C,mEAAmE;IACnE,IAAI,MAAM,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;QACtC,CAAC,MAAM,kBAAkB,CAAC,EAAE,OAAO,EAAE,WAAW,EAAE,QAAQ,EAAE,gBAAgB,EAAE,EAAE,OAAO,CAAC,CAAC;YACvF,CAAC,MAAM,kBAAkB,CAAC,EAAE,OAAO,EAAE,WAAW,EAAE,QAAQ,EAAE,eAAe,EAAE,EAAE,OAAO,CAAC,CAAC;YACxF,CAAC,MAAM,kBAAkB,CAAC,EAAE,OAAO,EAAE,WAAW,EAAE,QAAQ,EAAE,YAAY,EAAE,EAAE,OAAO,CAAC,CAAC,CAAC;IAC1F,CAAC;IAED,OAAO,OAAO,CAAC;AACjB,CAAC","sourcesContent":["import type { CloudpackConfig, PackageDefinitionsCache, PackageJsonExports } from '@ms-cloudpack/common-types';\nimport { normalizeRelativePath } from '@ms-cloudpack/path-string-parsing';\nimport { addExportsMapEntry } from './addExportsMapEntry.js';\n\n/**\n * Given a package path, generates an export map for the package.\n */\nexport async function createExportsMap(\n options: {\n packagePath: string;\n disableTransforms?: boolean;\n },\n context: { packages: PackageDefinitionsCache; config: CloudpackConfig },\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 // 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 typesPath,\n condition: type === 'module' ? 'import' : 'default',\n },\n context,\n );\n }\n\n if (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 }\n\n if (module) {\n await addExportsMapEntry(\n {\n exports,\n packagePath,\n filePath: module,\n typesPath,\n condition: 'import',\n },\n context,\n );\n }\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 continue;\n }\n\n const isDefaultImport = normalizeRelativePath(module || main) === normalizeRelativePath(key);\n\n const importPaths = isDefaultImport ? ['.'] : [key];\n\n if (!isDefaultImport && key.endsWith('.js')) {\n importPaths.push(key.replace(/\\.js$/, ''));\n }\n\n for (const importPath of importPaths) {\n await addExportsMapEntry(\n {\n exports,\n packagePath,\n importPath,\n filePath: value,\n condition: 'browser',\n },\n context,\n );\n }\n }\n }\n }\n\n // If we couldn't infer the exports map shape from existing metadata,\n // formulate based off inferred file structure.\n // Note: CRA defaults to src/index.js, Vite defaults to src/main.js\n if (Object.keys(exports).length === 0) {\n (await addExportsMapEntry({ exports, packagePath, filePath: './lib/index.js' }, context)) ||\n (await addExportsMapEntry({ exports, packagePath, filePath: './lib/main.js' }, context)) ||\n (await addExportsMapEntry({ exports, packagePath, filePath: './index.js' }, context));\n }\n\n return exports;\n}\n"]}
1
+ {"version":3,"file":"createExportsMap.js","sourceRoot":"","sources":["../src/createExportsMap.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,qBAAqB,EAAE,MAAM,mCAAmC,CAAC;AAC1E,OAAO,EAAE,kBAAkB,EAAE,MAAM,yBAAyB,CAAC;AAE7D;;GAEG;AACH,MAAM,CAAC,KAAK,UAAU,gBAAgB,CACpC,OA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AAO,CACR,CAAC;gBACJ,CAAC;YACH,CAAC;QACH,CAAC;IACH,CAAC;IAED,qEAAqE;IACrE,+CAA+C;IAC/C,mEAAmE;IACnE,IAAI,MAAM,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;QACtC,CAAC,MAAM,kBAAkB,CAAC,EAAE,OAAO,EAAE,WAAW,EAAE,QAAQ,EAAE,gBAAgB,EAAE,EAAE,OAAO,CAAC,CAAC;YACvF,CAAC,MAAM,kBAAkB,CAAC,EAAE,OAAO,EAAE,WAAW,EAAE,QAAQ,EAAE,eAAe,EAAE,EAAE,OAAO,CAAC,CAAC;YACxF,CAAC,MAAM,kBAAkB,CAAC,EAAE,OAAO,EAAE,WAAW,EAAE,QAAQ,EAAE,YAAY,EAAE,EAAE,OAAO,CAAC,CAAC,CAAC;IAC1F,CAAC;IAED,OAAO,OAAO,CAAC;AACjB,CAAC","sourcesContent":["import type { CloudpackConfig, PackageDefinitionsCache, PackageJsonExports } from '@ms-cloudpack/common-types';\nimport { normalizeRelativePath } from '@ms-cloudpack/path-string-parsing';\nimport { addExportsMapEntry } from './addExportsMapEntry.js';\n\n/**\n * Given a package path, generates an export map for the package.\n */\nexport async function createExportsMap(\n options: {\n packagePath: string;\n disableTransforms?: boolean;\n },\n context: { packages: PackageDefinitionsCache; config: CloudpackConfig },\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 // 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 typesPath,\n requestCondition: type === 'module' ? 'import' : undefined,\n },\n context,\n );\n }\n\n if (main) {\n await addExportsMapEntry(\n {\n exports,\n packagePath,\n filePath: main,\n typesPath,\n requestCondition: type === 'module' ? 'import' : undefined,\n },\n context,\n );\n }\n\n if (module) {\n await addExportsMapEntry(\n {\n exports,\n packagePath,\n filePath: module,\n typesPath,\n requestCondition: 'import',\n },\n context,\n );\n }\n\n if (browser) {\n if (typeof definition.browser === 'string') {\n await addExportsMapEntry(\n { exports, packagePath, filePath: definition.browser, requestCondition: 'browser' },\n context,\n );\n } else if (typeof definition.browser === 'object') {\n for (const [key, value] of Object.entries(definition.browser)) {\n if (!value || typeof value !== 'string') {\n continue;\n }\n\n const isDefaultImport = normalizeRelativePath(module || main) === normalizeRelativePath(key);\n\n const importPaths = isDefaultImport ? ['.'] : [key];\n\n if (!isDefaultImport && key.endsWith('.js')) {\n importPaths.push(key.replace(/\\.js$/, ''));\n }\n\n for (const importPath of importPaths) {\n await addExportsMapEntry(\n {\n exports,\n packagePath,\n importPath,\n filePath: value,\n requestCondition: 'browser',\n },\n context,\n );\n }\n }\n }\n }\n\n // If we couldn't infer the exports map shape from existing metadata,\n // formulate based off inferred file structure.\n // Note: CRA defaults to src/index.js, Vite defaults to src/main.js\n if (Object.keys(exports).length === 0) {\n (await addExportsMapEntry({ exports, packagePath, filePath: './lib/index.js' }, context)) ||\n (await addExportsMapEntry({ exports, packagePath, filePath: './lib/main.js' }, context)) ||\n (await addExportsMapEntry({ exports, packagePath, filePath: './index.js' }, context));\n }\n\n return exports;\n}\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ms-cloudpack/package-utilities",
3
- "version": "8.2.0",
3
+ "version": "9.0.1",
4
4
  "description": "Utilities for resolving/parsing packages and their imports.",
5
5
  "license": "MIT",
6
6
  "type": "module",
@@ -14,11 +14,11 @@
14
14
  }
15
15
  },
16
16
  "dependencies": {
17
- "@ms-cloudpack/common-types": "^0.14.0",
18
- "@ms-cloudpack/json-utilities": "^0.1.6",
19
- "@ms-cloudpack/package-overrides": "^0.9.16",
17
+ "@ms-cloudpack/common-types": "^0.15.0",
18
+ "@ms-cloudpack/json-utilities": "^0.1.7",
19
+ "@ms-cloudpack/package-overrides": "^0.9.18",
20
20
  "@ms-cloudpack/path-string-parsing": "^1.2.4",
21
- "@ms-cloudpack/path-utilities": "^2.7.31",
21
+ "@ms-cloudpack/path-utilities": "^2.7.32",
22
22
  "@ms-cloudpack/task-reporter": "^0.14.4",
23
23
  "acorn": "^8.11.2",
24
24
  "acorn-walk": "^8.2.1",