@ms-cloudpack/package-utilities 11.1.2 → 11.3.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,6 +1,8 @@
1
1
  import type { CloudpackConfig, PackageDefinitionsCache, PackageJsonExports } from '@ms-cloudpack/common-types';
2
2
  /**
3
- * Given a package path, generates an export map for the package.
3
+ * Given a package path, return its exports if already set (this could be from either the original
4
+ * package.json or as generated by `createPackageSettingsTransform`), or otherwise generate an
5
+ * exports map based on other fields in the package definition.
4
6
  */
5
7
  export declare function createExportsMap(options: {
6
8
  packagePath: string;
@@ -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;;GAEG;AACH,wBAAsB,gBAAgB,CACpC,OAAO,EAAE;IACP,WAAW,EAAE,MAAM,CAAC;IACpB,iBAAiB,CAAC,EAAE,OAAO,CAAC;CAC7B,EACD,OAAO,EAAE;IAAE,QAAQ,EAAE,uBAAuB,CAAC;IAAC,MAAM,EAAE,IAAI,CAAC,eAAe,EAAE,UAAU,CAAC,CAAA;CAAE,GACxF,OAAO,CAAC,kBAAkB,CAAC,CAqG7B"}
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;CAC7B,EACD,OAAO,EAAE;IAAE,QAAQ,EAAE,uBAAuB,CAAC;IAAC,MAAM,EAAE,IAAI,CAAC,eAAe,EAAE,UAAU,CAAC,CAAA;CAAE,GACxF,OAAO,CAAC,kBAAkB,CAAC,CAqG7B"}
@@ -1,7 +1,9 @@
1
1
  import { normalizeRelativePath } from '@ms-cloudpack/path-string-parsing';
2
2
  import { addExportsMapEntry } from './addExportsMapEntry.js';
3
3
  /**
4
- * Given a package path, generates an export map for the package.
4
+ * Given a package path, return its exports if already set (this could be from either the original
5
+ * package.json or as generated by `createPackageSettingsTransform`), or otherwise generate an
6
+ * exports map based on other fields in the package definition.
5
7
  */
6
8
  export async function createExportsMap(options, context) {
7
9
  const { packagePath } = options;
@@ -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;;GAEG;AACH,MAAM,CAAC,KAAK,UAAU,gBAAgB,CACpC,OAGC,EACD,OAAyF;IAEzF,MAAM,EAAE,WAAW,EAAE,GAAG,OAAO,CAAC;IAChC,MAAM,EAAE,QAAQ,EAAE,GAAG,OAAO,CAAC;IAC7B,MAAM,UAAU,GAAG,MAAM,QAAQ,CAAC,GAAG,CAAC,WAAW,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,MAAM,OAAO,GAAqB,EAAE,CAAC;IAErC,iFAAiF;IACjF,IAAI,CAAC,CAAC,IAAI,IAAI,MAAM,IAAI,OAAO,CAAC,EAAE,CAAC;QACjC,M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sCache,\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, generates an export map for the package.\n */\nexport async function createExportsMap(\n options: {\n packagePath: string;\n disableTransforms?: boolean;\n },\n context: { packages: PackageDefinitionsCache; config: Pick<CloudpackConfig, 'features'> },\n): Promise<PackageJsonExports> {\n const { packagePath } = options;\n const { packages } = context;\n const definition = await packages.get(packagePath, { disableTransforms: options.disableTransforms });\n\n // Don't create an exports map for a definition that already has one.\n if (definition.exports) {\n return definition.exports;\n }\n\n const { browser, main, module, type } = definition;\n // 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 },\n context,\n );\n }\n\n if (main) {\n await addExportsMapEntry(\n {\n exports,\n packagePath,\n filePath: main,\n requestCondition: type === 'module' ? 'import' : undefined,\n },\n context,\n );\n }\n\n if (module) {\n await addExportsMapEntry(\n {\n exports,\n packagePath,\n filePath: module,\n requestCondition: 'import',\n },\n context,\n );\n }\n\n if (browser) {\n if (typeof definition.browser === 'string') {\n await addExportsMapEntry(\n { exports, packagePath, filePath: definition.browser, environmentCondition: '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 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 },\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/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,OAGC,EACD,OAAyF;IAEzF,MAAM,EAAE,WAAW,EAAE,GAAG,OAAO,CAAC;IAChC,MAAM,EAAE,QAAQ,EAAE,GAAG,OAAO,CAAC;IAC7B,MAAM,UAAU,GAAG,MAAM,QAAQ,CAAC,GAAG,CAAC,WAAW,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,MAAM,OAAO,GAAqB,EAAE,CAAC;IAErC,iFAAiF;IACjF,IAAI,CAAC,CAAC,IAAI,IAAI,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AAC","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 },\n context: { packages: PackageDefinitionsCache; config: Pick<CloudpackConfig, 'features'> },\n): Promise<PackageJsonExports> {\n const { packagePath } = options;\n const { packages } = context;\n const definition = await packages.get(packagePath, { disableTransforms: options.disableTransforms });\n\n // Don't create an exports map for a definition that already has one.\n if (definition.exports) {\n return definition.exports;\n }\n\n const { browser, main, module, type } = definition;\n // 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 },\n context,\n );\n }\n\n if (main) {\n await addExportsMapEntry(\n {\n exports,\n packagePath,\n filePath: main,\n requestCondition: type === 'module' ? 'import' : undefined,\n },\n context,\n );\n }\n\n if (module) {\n await addExportsMapEntry(\n {\n exports,\n packagePath,\n filePath: module,\n requestCondition: 'import',\n },\n context,\n );\n }\n\n if (browser) {\n if (typeof definition.browser === 'string') {\n await addExportsMapEntry(\n { exports, packagePath, filePath: definition.browser, environmentCondition: '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 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 },\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,8 +1,6 @@
1
1
  import type { PackageJsonExports } from '@ms-cloudpack/common-types';
2
2
  /**
3
3
  * Given a package definition and applicable conditions, return a flat map of package import to physical (relative) path.
4
- * Optionally return the exports map fully qualified with conditions intact using the `fullExports` option.
5
- * Optionally takes in a `packagePath` to resolve entries and values that end in `/` and with wildcards `*`.
6
4
  *
7
5
  * Notes:
8
6
  * - This diverges from the behavior of Node in that conditions are considered in order of
@@ -14,10 +12,17 @@ import type { PackageJsonExports } from '@ms-cloudpack/common-types';
14
12
  * (This differs from the behavior of typescript and webpack.)
15
13
  */
16
14
  export declare function flattenExportsMap(exportsMap: PackageJsonExports, options?: {
17
- /** The conditions to check for in the exports object. */
18
- conditions?: string[];
15
+ /**
16
+ * The conditions to check for in the exports object.
17
+ * - `'browser-defaults'` uses the default browser-appropriate conditions.
18
+ * - `'node-defaults'` uses the default Node-appropriate conditions.
19
+ * - An array is a custom list of conditions. Use `'...'` to include the default browser conditions.
20
+ * @default 'browser-defaults'
21
+ */
22
+ conditions?: 'node-defaults' | 'browser-defaults' | string[];
19
23
  /** The conditions that must be matched to add the export. */
20
24
  requiredConditions?: string[];
25
+ /** Path to the package, used to resolve entries and values that end in `/` and with wildcards `*`. */
21
26
  packagePath?: string;
22
27
  }): Record<string, string>;
23
28
  //# sourceMappingURL=flattenExportsMap.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"flattenExportsMap.d.ts","sourceRoot":"","sources":["../../src/exportsMap/flattenExportsMap.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAA4B,kBAAkB,EAAE,MAAM,4BAA4B,CAAC;AAM/F;;;;;;;;;;;;;GAaG;AACH,wBAAgB,iBAAiB,CAC/B,UAAU,EAAE,kBAAkB,EAC9B,OAAO,GAAE;IACP,yDAAyD;IACzD,UAAU,CAAC,EAAE,MAAM,EAAE,CAAC;IACtB,6DAA6D;IAC7D,kBAAkB,CAAC,EAAE,MAAM,EAAE,CAAC;IAC9B,WAAW,CAAC,EAAE,MAAM,CAAC;CACjB,GACL,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAoBxB"}
1
+ {"version":3,"file":"flattenExportsMap.d.ts","sourceRoot":"","sources":["../../src/exportsMap/flattenExportsMap.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAA4B,kBAAkB,EAAE,MAAM,4BAA4B,CAAC;AAc/F;;;;;;;;;;;GAWG;AACH,wBAAgB,iBAAiB,CAC/B,UAAU,EAAE,kBAAkB,EAC9B,OAAO,GAAE;IACP;;;;;;OAMG;IACH,UAAU,CAAC,EAAE,eAAe,GAAG,kBAAkB,GAAG,MAAM,EAAE,CAAC;IAC7D,6DAA6D;IAC7D,kBAAkB,CAAC,EAAE,MAAM,EAAE,CAAC;IAC9B,sGAAsG;IACtG,WAAW,CAAC,EAAE,MAAM,CAAC;CACjB,GACL,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAyBxB"}
@@ -1,11 +1,17 @@
1
1
  import path from 'path';
2
2
  import glob from 'fast-glob';
3
3
  import { mergeArrayDefaults } from '../object/mergeArrayDefaults.js';
4
- const defaultConditions = ['browser', 'module', 'import', 'density', 'default'];
4
+ // The 'module' condition may be a webpack-ism, explained on this page:
5
+ // https://webpack.js.org/guides/package-exports/#conditions
6
+ // With that approach (used by @emotion/styled ^11.11.0), the 'module' key indicates actual ESM,
7
+ // whereas 'import' may indicate a wrapper around a CJS module. The proper way to specify precedence
8
+ // is by key order in the exports map, but flattenExportsMap doesn't currently respect that, so
9
+ // instead we have to ensure 'module' comes before other conditions here.
10
+ // (emotion issue was found here: https://github.com/microsoft/cloudpack/pull/1088)
11
+ const browserDefaults = ['browser', 'module', 'import', 'density', 'default'];
12
+ const nodeDefaults = ['node', 'module', 'import', 'default', 'require'];
5
13
  /**
6
14
  * Given a package definition and applicable conditions, return a flat map of package import to physical (relative) path.
7
- * Optionally return the exports map fully qualified with conditions intact using the `fullExports` option.
8
- * Optionally takes in a `packagePath` to resolve entries and values that end in `/` and with wildcards `*`.
9
15
  *
10
16
  * Notes:
11
17
  * - This diverges from the behavior of Node in that conditions are considered in order of
@@ -17,8 +23,12 @@ const defaultConditions = ['browser', 'module', 'import', 'density', 'default'];
17
23
  * (This differs from the behavior of typescript and webpack.)
18
24
  */
19
25
  export function flattenExportsMap(exportsMap, options = {}) {
20
- const { requiredConditions, packagePath } = options;
21
- const conditions = mergeArrayDefaults(options.conditions, defaultConditions);
26
+ const { requiredConditions, packagePath, conditions: rawConditions = 'browser-defaults' } = options;
27
+ const conditions = rawConditions === 'browser-defaults'
28
+ ? browserDefaults
29
+ : rawConditions === 'node-defaults'
30
+ ? nodeDefaults
31
+ : mergeArrayDefaults(rawConditions, browserDefaults);
22
32
  if (typeof exportsMap === 'string' && conditions.includes('default')) {
23
33
  return {
24
34
  '.': cleanEntry(exportsMap),
@@ -1 +1 @@
1
- {"version":3,"file":"flattenExportsMap.js","sourceRoot":"","sources":["../../src/exportsMap/flattenExportsMap.ts"],"names":[],"mappings":"AAAA,OAAO,IAAI,MAAM,MAAM,CAAC;AAExB,OAAO,IAAI,MAAM,WAAW,CAAC;AAC7B,OAAO,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AAa,GAAG,CAAC,CAAC;SACxC,CAAC;IACJ,CAAC;AACH,CAAC;AAED,SAAS,UAAU,CAAC,SAAiB;IACnC,IAAI,IAAI,CAAC,OAAO,CAAC,SAAS,CAAC,KAAK,EAAE,EAAE,CAAC;QACnC,SAAS,IAAI,KAAK,CAAC;IACrB,CAAC;IAED,IAAI,CAAC,SAAS,CAAC,UAAU,CAAC,IAAI,CAAC,EAAE,CAAC;QAChC,SAAS,GAAG,KAAK,SAAS,EAAE,CAAC;IAC/B,CAAC;IAED,OAAO,SAAS,CAAC;AACnB,CAAC","sourcesContent":["import path from 'path';\nimport type { PackageJsonExportsObject, PackageJsonExports } from '@ms-cloudpack/common-types';\nimport glob from 'fast-glob';\nimport { mergeArrayDefaults } from '../object/mergeArrayDefaults.js';\n\nconst defaultConditions = ['browser', 'module', 'import', 'density', 'default'];\n\n/**\n * Given a package definition and applicable conditions, return a flat map of package import to physical (relative) path.\n * Optionally return the exports map fully qualified with conditions intact using the `fullExports` option.\n * Optionally takes in a `packagePath` to resolve entries and values that end in `/` and with wildcards `*`.\n *\n * Notes:\n * - This diverges from the behavior of Node in that conditions are considered in order of\n * the `conditions` array, NOT in the order keys are defined in the exports map.\n * - Null export values are supported only for generated config. A null export signals to Cloudpack\n * that the entry should be completely dropped from the flattened exports map.\n * - Following the behavior of Node, for perf reasons, we do NOT verify whether any entries\n * exist on disk except wildcard or trailing slash exports since it is required.\n * (This differs from the behavior of typescript and webpack.)\n */\nexport function flattenExportsMap(\n exportsMap: PackageJsonExports,\n options: {\n /** The conditions to check for in the exports object. */\n conditions?: string[];\n /** The conditions that must be matched to add the export. */\n requiredConditions?: string[];\n packagePath?: string;\n } = {},\n): Record<string, string> {\n const { requiredConditions, packagePath } = options;\n\n const conditions = mergeArrayDefaults(options.conditions, defaultConditions);\n\n if (typeof exportsMap === 'string' && conditions.includes('default')) {\n return {\n '.': cleanEntry(exportsMap),\n };\n }\n\n return extractExports({\n exports: exportsMap,\n conditions,\n requiredConditions,\n flatExports: {},\n importMatch: '.',\n matchedConditions: [],\n packagePath,\n });\n}\n\n/**\n * Extract the exports from an exports object or sub-object and add them to the flat exports map.\n *\n * @returns The cumulative flat exports map.\n */\nfunction extractExports(params: {\n /** The exports object to extract or a sub-object. */\n exports: PackageJsonExports;\n /** The conditions to check for in the exports object. */\n conditions: string[];\n /** The conditions that must be matched to add the export. */\n requiredConditions?: string[];\n /** The cumulative flat exports map to add the exports to. */\n flatExports: Record<string, string>;\n /** The import path to match */\n importMatch: string;\n /** The conditions that have been matched so far. */\n matchedConditions: string[];\n /** The path to the package. */\n packagePath?: string | undefined;\n}): Record<string, string> {\n const { exports, conditions, requiredConditions, flatExports, matchedConditions, packagePath, importMatch } = params;\n\n if (\n typeof exports === 'string' &&\n (!requiredConditions || requiredConditions.every((condition) => matchedConditions.includes(condition)))\n ) {\n addExportsEntry({ flatExports, key: importMatch, value: exports, packagePath });\n } else if (Array.isArray(exports)) {\n for (const exportEntry of exports) {\n extractExports({ ...params, exports: exportEntry });\n }\n } else if (exports && typeof exports === 'object') {\n // Iterate through condition matches and go deeper if a match is found.\n for (const condition of conditions) {\n const conditionExports = (exports as PackageJsonExportsObject)[condition];\n\n if (conditionExports) {\n extractExports({\n ...params,\n exports: conditionExports,\n matchedConditions: matchedConditions.concat(condition),\n });\n // Stop at the first match.\n return flatExports;\n }\n }\n\n // No conditions are available. Check for import entries.\n for (const [key, value] of Object.entries(exports)) {\n if (!key.startsWith('.')) {\n continue; // not a path\n }\n\n if (typeof value === 'string') {\n if (!flatExports[key] && (!requiredConditions || requiredConditions?.includes(key))) {\n addExportsEntry({ flatExports, key, value, packagePath });\n }\n } else if (value) {\n extractExports({\n ...params,\n exports: value,\n importMatch: key,\n matchedConditions: [...matchedConditions, key],\n });\n } else {\n delete flatExports[key];\n }\n }\n }\n\n return flatExports;\n}\n\n/**\n * Add an entry to the flattened exports map if the key and value are valid\n * and the key is not already in the map.\n *\n * Does nothing if the key contains a wildcard or a trailing slash and the value does not, such as it being `null`.\n */\nfunction addExportsEntry(params: {\n /** The path to the package. */\n flatExports: Record<string, string>;\n /** The flattened exports map. */\n key: string;\n /** The key to add to the map. */\n value: string;\n /** The relative physical path to add to the map. */\n packagePath: string | undefined;\n}): void {\n const { flatExports, key, value, packagePath } = params;\n\n const basename = path.basename(value);\n const isValid = basename !== '' && basename !== '.';\n const isMany = value.endsWith('/') || value.indexOf('*') !== -1 || key.indexOf('*') !== -1 || key.endsWith('/');\n\n // Skip if the key is already in the map.\n if (flatExports[key]) return;\n\n if (isValid && !isMany) {\n flatExports[key] = cleanEntry(value);\n return;\n }\n\n if (value === null) {\n // Debug log for null values in the exports map.\n console.debug(`Skipping null value for key \"${key}\" in exports map${packagePath ? ` of \"${packagePath}\"` : ''}.`);\n return;\n }\n\n // Debug log for export patterns found in the exports map.\n console.debug(`Found export patterns in ${packagePath ? `\"${packagePath}\" ` : ''}exports map: \"${key}\": \"${value}\"`);\n\n // A package path is required to resolve entries and values that end in `/` or that include a wildcard `*`.\n if (!packagePath) return;\n\n // Check for wildcards in the key and value.\n // The wildcards\n const keyWildcard = key.indexOf('*', 1);\n const valueWildcard = value.indexOf('*', 1);\n\n if ((key.endsWith('/') && value.endsWith('/')) || (keyWildcard !== -1 && valueWildcard !== -1)) {\n const searchGlob = valueToGlob(value, valueWildcard);\n const keySplit = splitByGlob(key, keyWildcard);\n const valueSplit = splitByGlob(value, valueWildcard);\n if (!searchGlob || !keySplit || !valueSplit) return;\n // We only want to search for files.\n const matches = glob.sync(searchGlob, { cwd: packagePath, onlyFiles: true });\n for (const match of matches) {\n // Skip files that don't have an extension or have a `.` extension.\n if (path.extname(match).length <= 1) continue;\n // Get the glob match shared between the key and value.\n const globMatch = match.substring(\n // Globs that start with `./` don't return matches with `./` in the beginning.\n match.startsWith(valueSplit.start) ? valueSplit.start.length : 0,\n match.length - valueSplit.end.length,\n );\n // Replace the glob match in the key with the resolved glob match in the value.\n const matchKey = keySplit.start + globMatch + keySplit.end;\n if (!flatExports[matchKey]) {\n flatExports[matchKey] = cleanEntry(match);\n }\n }\n }\n}\n\n/**\n * Convert a value to a glob pattern.\n *\n * @param value The value to convert.\n * @param valueWildcard The index of the wildcard in the value.\n * @returns A value converted to a glob pattern.\n */\nfunction valueToGlob(value: string, valueWildcard: number = value.indexOf('*', 1)): string | undefined {\n if (value.endsWith('/')) {\n return value + '**/*';\n } else if (valueWildcard !== -1) {\n return value.substring(0, valueWildcard) + '**/*' + value.substring(valueWildcard + 1);\n }\n}\n\n/**\n * Split a value by the location of the trailing slash or wildcard.\n *\n * @param value The value to split.\n * @param valueWildcard The index of the wildcard in the value.\n * @returns An object with the start and end substring of the split value.\n */\nfunction splitByGlob(\n value: string,\n valueWildcard: number = value.indexOf('*', 1),\n): { start: string; end: string } | undefined {\n if (value.endsWith('/')) {\n return { start: value, end: '' };\n } else if (valueWildcard !== -1) {\n return {\n start: value.substring(0, valueWildcard),\n end: value.substring(valueWildcard + 1),\n };\n }\n}\n\nfunction cleanEntry(entryName: string) {\n if (path.extname(entryName) === '') {\n entryName += '.js';\n }\n\n if (!entryName.startsWith('./')) {\n entryName = `./${entryName}`;\n }\n\n return entryName;\n}\n"]}
1
+ {"version":3,"file":"flattenExportsMap.js","sourceRoot":"","sources":["../../src/exportsMap/flattenExportsMap.ts"],"names":[],"mappings":"AAAA,OAAO,IAAI,MAAM,MAAM,CAAC;AAExB,OAAO,IAAI,MAAM,WAAW,CAAC;AAC7B,OAAO,EAAE,kBAAkB,EAAE,MAAM,iCAAiC,CAAC;AAErE,uEAAuE;AACvE,4DAA4D;AAC5D,gGAAgG;AAChG,oGAAoG;AACpG,+FAA+F;AAC/F,yEAAyE;AACzE,mFAAmF;AACnF,MAAM,eAAe,GAAG,CAAC,SAAS,EAAE,QAAQ,EAAE,QAAQ,EAAE,SAAS,EAAE,SAAS,CAAC,CAAC;AAC9E,MAAM,YAAY,GAAG,CAAC,MAAM,EAAE,QAAQ,EAAE,QAAQ,EAAE,SAAS,EAAE,SAAS,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AS,CAAC,aAAa,GAAG,CAAC,CAAC;SACxC,CAAC;IACJ,CAAC;AACH,CAAC;AAED,SAAS,UAAU,CAAC,SAAiB;IACnC,IAAI,IAAI,CAAC,OAAO,CAAC,SAAS,CAAC,KAAK,EAAE,EAAE,CAAC;QACnC,SAAS,IAAI,KAAK,CAAC;IACrB,CAAC;IAED,IAAI,CAAC,SAAS,CAAC,UAAU,CAAC,IAAI,CAAC,EAAE,CAAC;QAChC,SAAS,GAAG,KAAK,SAAS,EAAE,CAAC;IAC/B,CAAC;IAED,OAAO,SAAS,CAAC;AACnB,CAAC","sourcesContent":["import path from 'path';\nimport type { PackageJsonExportsObject, PackageJsonExports } from '@ms-cloudpack/common-types';\nimport glob from 'fast-glob';\nimport { mergeArrayDefaults } from '../object/mergeArrayDefaults.js';\n\n// The 'module' condition may be a webpack-ism, explained on this page:\n// https://webpack.js.org/guides/package-exports/#conditions\n// With that approach (used by @emotion/styled ^11.11.0), the 'module' key indicates actual ESM,\n// whereas 'import' may indicate a wrapper around a CJS module. The proper way to specify precedence\n// is by key order in the exports map, but flattenExportsMap doesn't currently respect that, so\n// instead we have to ensure 'module' comes before other conditions here.\n// (emotion issue was found here: https://github.com/microsoft/cloudpack/pull/1088)\nconst browserDefaults = ['browser', 'module', 'import', 'density', 'default'];\nconst nodeDefaults = ['node', 'module', 'import', 'default', 'require'];\n\n/**\n * Given a package definition and applicable conditions, return a flat map of package import to physical (relative) path.\n *\n * Notes:\n * - This diverges from the behavior of Node in that conditions are considered in order of\n * the `conditions` array, NOT in the order keys are defined in the exports map.\n * - Null export values are supported only for generated config. A null export signals to Cloudpack\n * that the entry should be completely dropped from the flattened exports map.\n * - Following the behavior of Node, for perf reasons, we do NOT verify whether any entries\n * exist on disk except wildcard or trailing slash exports since it is required.\n * (This differs from the behavior of typescript and webpack.)\n */\nexport function flattenExportsMap(\n exportsMap: PackageJsonExports,\n options: {\n /**\n * The conditions to check for in the exports object.\n * - `'browser-defaults'` uses the default browser-appropriate conditions.\n * - `'node-defaults'` uses the default Node-appropriate conditions.\n * - An array is a custom list of conditions. Use `'...'` to include the default browser conditions.\n * @default 'browser-defaults'\n */\n conditions?: 'node-defaults' | 'browser-defaults' | string[];\n /** The conditions that must be matched to add the export. */\n requiredConditions?: string[];\n /** Path to the package, used to resolve entries and values that end in `/` and with wildcards `*`. */\n packagePath?: string;\n } = {},\n): Record<string, string> {\n const { requiredConditions, packagePath, conditions: rawConditions = 'browser-defaults' } = options;\n\n const conditions =\n rawConditions === 'browser-defaults'\n ? browserDefaults\n : rawConditions === 'node-defaults'\n ? nodeDefaults\n : mergeArrayDefaults(rawConditions, browserDefaults);\n\n if (typeof exportsMap === 'string' && conditions.includes('default')) {\n return {\n '.': cleanEntry(exportsMap),\n };\n }\n\n return extractExports({\n exports: exportsMap,\n conditions,\n requiredConditions,\n flatExports: {},\n importMatch: '.',\n matchedConditions: [],\n packagePath,\n });\n}\n\n/**\n * Extract the exports from an exports object or sub-object and add them to the flat exports map.\n *\n * @returns The cumulative flat exports map.\n */\nfunction extractExports(params: {\n /** The exports object to extract or a sub-object. */\n exports: PackageJsonExports;\n /** The conditions to check for in the exports object. */\n conditions: ReadonlyArray<string>;\n /** The conditions that must be matched to add the export. */\n requiredConditions?: ReadonlyArray<string>;\n /** The cumulative flat exports map to add the exports to. */\n flatExports: Record<string, string>;\n /** The import path to match */\n importMatch: string;\n /** The conditions that have been matched so far. */\n matchedConditions: string[];\n /** The path to the package. */\n packagePath?: string | undefined;\n}): Record<string, string> {\n const { exports, conditions, requiredConditions, flatExports, matchedConditions, packagePath, importMatch } = params;\n\n if (\n typeof exports === 'string' &&\n (!requiredConditions || requiredConditions.every((condition) => matchedConditions.includes(condition)))\n ) {\n addExportsEntry({ flatExports, key: importMatch, value: exports, packagePath });\n } else if (Array.isArray(exports)) {\n for (const exportEntry of exports) {\n extractExports({ ...params, exports: exportEntry });\n }\n } else if (exports && typeof exports === 'object') {\n // Iterate through condition matches and go deeper if a match is found.\n for (const condition of conditions) {\n const conditionExports = (exports as PackageJsonExportsObject)[condition];\n\n if (conditionExports) {\n extractExports({\n ...params,\n exports: conditionExports,\n matchedConditions: matchedConditions.concat(condition),\n });\n // Stop at the first match.\n return flatExports;\n }\n }\n\n // No conditions are available. Check for import entries.\n for (const [key, value] of Object.entries(exports)) {\n if (!key.startsWith('.')) {\n continue; // not a path\n }\n\n if (typeof value === 'string') {\n if (!flatExports[key] && (!requiredConditions || requiredConditions?.includes(key))) {\n addExportsEntry({ flatExports, key, value, packagePath });\n }\n } else if (value) {\n extractExports({\n ...params,\n exports: value,\n importMatch: key,\n matchedConditions: [...matchedConditions, key],\n });\n } else {\n delete flatExports[key];\n }\n }\n }\n\n return flatExports;\n}\n\n/**\n * Add an entry to the flattened exports map if the key and value are valid\n * and the key is not already in the map.\n *\n * Does nothing if the key contains a wildcard or a trailing slash and the value does not, such as it being `null`.\n */\nfunction addExportsEntry(params: {\n /** The path to the package. */\n flatExports: Record<string, string>;\n /** The flattened exports map. */\n key: string;\n /** The key to add to the map. */\n value: string;\n /** The relative physical path to add to the map. */\n packagePath: string | undefined;\n}): void {\n const { flatExports, key, value, packagePath } = params;\n\n const basename = path.basename(value);\n const isValid = basename !== '' && basename !== '.';\n const isMany = value.endsWith('/') || value.indexOf('*') !== -1 || key.indexOf('*') !== -1 || key.endsWith('/');\n\n // Skip if the key is already in the map.\n if (flatExports[key]) return;\n\n if (isValid && !isMany) {\n flatExports[key] = cleanEntry(value);\n return;\n }\n\n if (value === null) {\n // Debug log for null values in the exports map.\n console.debug(`Skipping null value for key \"${key}\" in exports map${packagePath ? ` of \"${packagePath}\"` : ''}.`);\n return;\n }\n\n // Debug log for export patterns found in the exports map.\n console.debug(`Found export patterns in ${packagePath ? `\"${packagePath}\" ` : ''}exports map: \"${key}\": \"${value}\"`);\n\n // A package path is required to resolve entries and values that end in `/` or that include a wildcard `*`.\n if (!packagePath) return;\n\n // Check for wildcards in the key and value.\n // The wildcards\n const keyWildcard = key.indexOf('*', 1);\n const valueWildcard = value.indexOf('*', 1);\n\n if ((key.endsWith('/') && value.endsWith('/')) || (keyWildcard !== -1 && valueWildcard !== -1)) {\n const searchGlob = valueToGlob(value, valueWildcard);\n const keySplit = splitByGlob(key, keyWildcard);\n const valueSplit = splitByGlob(value, valueWildcard);\n if (!searchGlob || !keySplit || !valueSplit) return;\n // We only want to search for files.\n const matches = glob.sync(searchGlob, { cwd: packagePath, onlyFiles: true });\n for (const match of matches) {\n // Skip files that don't have an extension or have a `.` extension.\n if (path.extname(match).length <= 1) continue;\n // Get the glob match shared between the key and value.\n const globMatch = match.substring(\n // Globs that start with `./` don't return matches with `./` in the beginning.\n match.startsWith(valueSplit.start) ? valueSplit.start.length : 0,\n match.length - valueSplit.end.length,\n );\n // Replace the glob match in the key with the resolved glob match in the value.\n const matchKey = keySplit.start + globMatch + keySplit.end;\n if (!flatExports[matchKey]) {\n flatExports[matchKey] = cleanEntry(match);\n }\n }\n }\n}\n\n/**\n * Convert a value to a glob pattern.\n *\n * @param value The value to convert.\n * @param valueWildcard The index of the wildcard in the value.\n * @returns A value converted to a glob pattern.\n */\nfunction valueToGlob(value: string, valueWildcard: number = value.indexOf('*', 1)): string | undefined {\n if (value.endsWith('/')) {\n return value + '**/*';\n } else if (valueWildcard !== -1) {\n return value.substring(0, valueWildcard) + '**/*' + value.substring(valueWildcard + 1);\n }\n}\n\n/**\n * Split a value by the location of the trailing slash or wildcard.\n *\n * @param value The value to split.\n * @param valueWildcard The index of the wildcard in the value.\n * @returns An object with the start and end substring of the split value.\n */\nfunction splitByGlob(\n value: string,\n valueWildcard: number = value.indexOf('*', 1),\n): { start: string; end: string } | undefined {\n if (value.endsWith('/')) {\n return { start: value, end: '' };\n } else if (valueWildcard !== -1) {\n return {\n start: value.substring(0, valueWildcard),\n end: value.substring(valueWildcard + 1),\n };\n }\n}\n\nfunction cleanEntry(entryName: string) {\n if (path.extname(entryName) === '') {\n entryName += '.js';\n }\n\n if (!entryName.startsWith('./')) {\n entryName = `./${entryName}`;\n }\n\n return entryName;\n}\n"]}
@@ -23,10 +23,10 @@ export async function findFileInPackage(options, context) {
23
23
  let sourcePath;
24
24
  const isInternal = !isExternalPackage(packagePath);
25
25
  const pathsToConsider = [originalPath];
26
- const definition = await context.packages.tryGet(packagePath, { disableTransforms: true });
26
+ const originalDefinition = await context.packages.tryGet(packagePath, { disableTransforms: true });
27
27
  // If the original package.json has an exports map, we should not use main and module as hints.
28
- if (originalPath === '.' && definition && !definition.exports) {
29
- const { main, module } = definition;
28
+ if (originalPath === '.' && originalDefinition && !originalDefinition.exports) {
29
+ const { main, module } = originalDefinition;
30
30
  if (main) {
31
31
  pathsToConsider.unshift(main);
32
32
  }
@@ -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,wBAAwB,GACzB,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;AAE/D,MAAM,gBAAgB,GAAG,CAAC,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,CAAC,CAAC;AACjE,MAAM,oBAAoB,GAAG,CAAC,KAAK,EAAE,MAAM,EAAE,MAAM,CAAC,CAAC;AAYrD;;;;;;;;;GASG;AACH,MAAM,CAAC,KAAK,UAAU,iBAAiB,CACrC,OAAiC,EACjC,OAAyF;IAEzF,MAAM,YAAY,GAAG,qBAAqB,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAC;IAC7D,MAAM,WAAW,GAAG,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QAAQ,EAAE,WAAW,CAAC,CAAC;YAE7D,mDAAmD;YACnD,IAAI,UAAU,KAAK,QAAQ,EAAE,CAAC;gBAC5B,UAAU,GAAG,SAAS,CAAC;YACzB,CAAC;QACH,CAAC;IACH,CAAC;IAED,IAAI,QAAQ,EAAE,CAAC;QACb,MAAM,CAAC,QAAQ,GAAG,qBAAqB,CAAC,QAAQ,CAAC,CAAC;IACpD,CAAC;IAED,IAAI,UAAU,EAAE,CAAC;QACf,MAAM,CAAC,UAAU,GAAG,qBAAqB,CAAC,UAAU,CAAC,CAAC;IACxD,CAAC;IAED,OAAO,MAAM,CAAC;AAChB,CAAC","sourcesContent":["import type { CloudpackConfig, PackageDefinitionsCache } from '@ms-cloudpack/common-types';\nimport { normalizeRelativePath, slash } from '@ms-cloudpack/path-string-parsing';\nimport {\n intermediateToSourcePath,\n isExternalPackage,\n isFileSync,\n sourceToIntermediatePath,\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\nconst sourceExtensions = ['.ts', '.tsx', '.cts', '.mts', '.jsx'];\nconst javascriptExtensions = ['.js', '.mjs', '.cjs'];\n\nexport type FindFileInPackageOptions = {\n packagePath: string;\n filePath: string;\n};\n\nexport type FindFileInPackageResult = {\n filePath?: string;\n sourcePath?: string;\n};\n\n/**\n * Given a requested partial filePath, resolves the relative intermediate path if the file exists, with special\n * consideration for internal packages, which may not have intermediate files but only source files. Paths returned\n * are always relative and start with `./`.\n *\n * This helper is used in deriving if the given package.json entries are actual validate candidates when constructing an\n * exports map from existing metadata. For example, a package.json may list `main` as `lib/index.js`. If this file\n * exists, or in internal packages, if `src/index.tsx` exists, then this is a valid candidate. If the file does not\n * exist, then we should not include it in the exports map.\n */\nexport async function findFileInPackage(\n options: FindFileInPackageOptions,\n context: { packages: PackageDefinitionsCache; config: Pick<CloudpackConfig, 'features'> },\n): Promise<FindFileInPackageResult> {\n const originalPath = normalizeRelativePath(options.filePath);\n const packagePath = slash(options.packagePath);\n let filePath: string | undefined;\n let sourcePath: string | undefined;\n const isInternal = !isExternalPackage(packagePath);\n const pathsToConsider = [originalPath];\n\n const definition = await context.packages.tryGet(packagePath, { disableTransforms: true });\n // If the original package.json has an exports map, we should not use main and module as hints.\n if (originalPath === '.' && definition && !definition.exports) {\n const { main, module } = definition;\n if (main) {\n pathsToConsider.unshift(main);\n }\n if (module) {\n pathsToConsider.unshift(module);\n }\n }\n\n for (const currentPath of pathsToConsider) {\n const candidates = await getCandidates({ filePath: currentPath, packagePath }, context);\n\n // Try and resolve a physical file given the candidates.\n filePath = candidates.find((candidate) => isFileSync(path.join(packagePath, candidate)));\n if (filePath) {\n break;\n }\n }\n\n const isNestedPackageDefinition =\n filePath && path.basename(filePath) === 'package.json' && path.basename(originalPath) !== 'package.json';\n const result: FindFileInPackageResult = {};\n\n if (isNestedPackageDefinition) {\n const nestedDefinitionPath = path.dirname(path.join(packagePath, filePath as string));\n const exportsMap = await getExportsMap({ packagePath: nestedDefinitionPath }, context);\n const entryPath = flattenExportsMap(exportsMap)['.'];\n\n if (entryPath) {\n return findFileInPackage(\n {\n packagePath,\n filePath: normalizeRelativePath(path.relative(packagePath, path.join(nestedDefinitionPath, entryPath))),\n },\n context,\n );\n } else {\n // If we can't find an entry, we should not include this in the exports map.\n // This avoids adding a \"./package.json\" value to a \".\" entry.\n return result;\n }\n }\n\n // If the resolved file is a typescript file in an internal package, try to resolve the intermediate.\n if (filePath && sourceExtensions.includes(path.extname(filePath))) {\n sourcePath = filePath;\n filePath = isInternal ? sourceToIntermediatePath(filePath) : undefined;\n }\n\n // If we haven't resolved a sourcePath, try to resolve it from the intermediate.\n if (isInternal && filePath && !sourcePath) {\n const ext = path.extname(filePath);\n const isJavaScriptExt = javascriptExtensions.includes(ext);\n\n if (isJavaScriptExt) {\n // Not a TS file, but a JS file. Try to find the source.\n sourcePath = intermediateToSourcePath(filePath, packagePath);\n\n // If we couldn't find a TS file, clear sourcePath.\n if (sourcePath === filePath) {\n sourcePath = undefined;\n }\n }\n }\n\n if (filePath) {\n result.filePath = normalizeRelativePath(filePath);\n }\n\n if (sourcePath) {\n result.sourcePath = normalizeRelativePath(sourcePath);\n }\n\n return result;\n}\n"]}
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,wBAAwB,GACzB,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;AAE/D,MAAM,gBAAgB,GAAG,CAAC,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,CAAC,CAAC;AACjE,MAAM,oBAAoB,GAAG,CAAC,KAAK,EAAE,MAAM,EAAE,MAAM,CAAC,CAAC;AAYrD;;;;;;;;;GASG;AACH,MAAM,CAAC,KAAK,UAAU,iBAAiB,CACrC,OAAiC,EACjC,OAAyF;IAEzF,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,M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,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 sourceToIntermediatePath,\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\nconst sourceExtensions = ['.ts', '.tsx', '.cts', '.mts', '.jsx'];\nconst javascriptExtensions = ['.js', '.mjs', '.cjs'];\n\nexport type FindFileInPackageOptions = {\n packagePath: string;\n filePath: string;\n};\n\nexport type FindFileInPackageResult = {\n filePath?: string;\n sourcePath?: string;\n};\n\n/**\n * Given a requested partial filePath, resolves the relative intermediate path if the file exists, with special\n * consideration for internal packages, which may not have intermediate files but only source files. Paths returned\n * are always relative and start with `./`.\n *\n * This helper is used in deriving if the given package.json entries are actual validate candidates when constructing an\n * exports map from existing metadata. For example, a package.json may list `main` as `lib/index.js`. If this file\n * exists, or in internal packages, if `src/index.tsx` exists, then this is a valid candidate. If the file does not\n * exist, then we should not include it in the exports map.\n */\nexport async function findFileInPackage(\n options: FindFileInPackageOptions,\n context: { packages: PackageDefinitionsCache; config: Pick<CloudpackConfig, 'features'> },\n): Promise<FindFileInPackageResult> {\n const originalPath = normalizeRelativePath(options.filePath);\n const packagePath = slash(options.packagePath);\n let filePath: string | undefined;\n let sourcePath: string | undefined;\n const isInternal = !isExternalPackage(packagePath);\n const pathsToConsider = [originalPath];\n\n const 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 for (const currentPath of pathsToConsider) {\n const candidates = await getCandidates({ filePath: currentPath, packagePath }, context);\n\n // Try and resolve a physical file given the candidates.\n filePath = candidates.find((candidate) => isFileSync(path.join(packagePath, candidate)));\n if (filePath) {\n break;\n }\n }\n\n const isNestedPackageDefinition =\n filePath && path.basename(filePath) === 'package.json' && path.basename(originalPath) !== 'package.json';\n const result: FindFileInPackageResult = {};\n\n if (isNestedPackageDefinition) {\n const nestedDefinitionPath = path.dirname(path.join(packagePath, filePath as string));\n const exportsMap = await getExportsMap({ packagePath: nestedDefinitionPath }, context);\n const entryPath = flattenExportsMap(exportsMap)['.'];\n\n if (entryPath) {\n return findFileInPackage(\n {\n packagePath,\n filePath: normalizeRelativePath(path.relative(packagePath, path.join(nestedDefinitionPath, entryPath))),\n },\n context,\n );\n } else {\n // If we can't find an entry, we should not include this in the exports map.\n // This avoids adding a \"./package.json\" value to a \".\" entry.\n return result;\n }\n }\n\n // If the resolved file is a typescript file in an internal package, try to resolve the intermediate.\n if (filePath && sourceExtensions.includes(path.extname(filePath))) {\n sourcePath = filePath;\n filePath = isInternal ? sourceToIntermediatePath(filePath) : undefined;\n }\n\n // If we haven't resolved a sourcePath, try to resolve it from the intermediate.\n if (isInternal && filePath && !sourcePath) {\n const ext = path.extname(filePath);\n const isJavaScriptExt = javascriptExtensions.includes(ext);\n\n if (isJavaScriptExt) {\n // Not a TS file, but a JS file. Try to find the source.\n sourcePath = intermediateToSourcePath(filePath, packagePath);\n\n // If we couldn't find a TS file, clear sourcePath.\n if (sourcePath === filePath) {\n sourcePath = undefined;\n }\n }\n }\n\n if (filePath) {\n result.filePath = normalizeRelativePath(filePath);\n }\n\n if (sourcePath) {\n result.sourcePath = normalizeRelativePath(sourcePath);\n }\n\n return result;\n}\n"]}
package/lib/index.d.ts CHANGED
@@ -6,7 +6,6 @@ export type { DiffResolveMapsChanges, DiffResolveMapsStats } from './resolveMap/
6
6
  export { diffResolveMaps } from './resolveMap/diffResolveMaps.js';
7
7
  export { ensureResolveMapEntry } from './resolveMap/ensureResolveMapEntry.js';
8
8
  export { flattenExportsMap } from './exportsMap/flattenExportsMap.js';
9
- export { createExportsMap } from './exportsMap/createExportsMap.js';
10
9
  export { addExportsMapEntry, type AddExportsMapEntryOptions } from './exportsMap/addExportsMapEntry.js';
11
10
  export { getExportsMap } from './exportsMap/getExportsMap.js';
12
11
  export { getSourceEntry } from './exportsMap/getSourceEntry.js';
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,kBAAkB,EAAE,MAAM,4CAA4C,CAAC;AAChF,OAAO,EAAE,sBAAsB,EAAE,MAAM,gDAAgD,CAAC;AAGxF,OAAO,EAAE,gBAAgB,EAAE,MAAM,kCAAkC,CAAC;AACpE,OAAO,EAAE,mBAAmB,EAAE,MAAM,qCAAqC,CAAC;AAC1E,YAAY,EAAE,sBAAsB,EAAE,oBAAoB,EAAE,MAAM,iCAAiC,CAAC;AACpG,OAAO,EAAE,eAAe,EAAE,MAAM,iCAAiC,CAAC;AAClE,OAAO,EAAE,qBAAqB,EAAE,MAAM,uCAAuC,CAAC;AAG9E,OAAO,EAAE,iBAAiB,EAAE,MAAM,mCAAmC,CAAC;AACtE,OAAO,EAAE,gBAAgB,EAAE,MAAM,kCAAkC,CAAC;AACpE,OAAO,EAAE,kBAAkB,EAAE,KAAK,yBAAyB,EAAE,MAAM,oCAAoC,CAAC;AACxG,OAAO,EAAE,aAAa,EAAE,MAAM,+BAA+B,CAAC;AAC9D,OAAO,EAAE,cAAc,EAAE,MAAM,gCAAgC,CAAC;AAGhE,OAAO,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAC;AACzD,OAAO,EACL,iBAAiB,E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CAAC;AAC5E,OAAO,EAAE,eAAe,EAAE,MAAM,kCAAkC,CAAC;AACnE,OAAO,EAAE,qBAAqB,EAAE,MAAM,wCAAwC,CAAC;AAG/E,OAAO,EAAE,kBAAkB,EAAE,MAAM,gCAAgC,CAAC;AACpE,OAAO,EAAE,YAAY,EAAE,MAAM,0BAA0B,CAAC"}
package/lib/index.js CHANGED
@@ -8,7 +8,6 @@ export { diffResolveMaps } from './resolveMap/diffResolveMaps.js';
8
8
  export { ensureResolveMapEntry } from './resolveMap/ensureResolveMapEntry.js';
9
9
  // ExportsMap parsing and creation
10
10
  export { flattenExportsMap } from './exportsMap/flattenExportsMap.js';
11
- export { createExportsMap } from './exportsMap/createExportsMap.js';
12
11
  export { addExportsMapEntry } from './exportsMap/addExportsMapEntry.js';
13
12
  export { getExportsMap } from './exportsMap/getExportsMap.js';
14
13
  export { getSourceEntry } from './exportsMap/getSourceEntry.js';
package/lib/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,6BAA6B;AAC7B,OAAO,EAAE,kBAAkB,EAAE,MAAM,4CAA4C,CAAC;AAChF,OAAO,EAAE,sBAAsB,EAAE,MAAM,gDAAgD,CAAC;AAExF,cAAc;AACd,OAAO,EAAE,gBAAgB,EAAE,MAAM,kCAAkC,CAAC;AACpE,OAAO,EAAE,mBAAmB,EAAE,MAAM,qCAAqC,CAAC;AAE1E,OAAO,EAAE,eAAe,EAAE,MAAM,iCAAiC,CAAC;AAClE,OAAO,EAAE,qBAAqB,EAAE,MAAM,uCAAuC,CAAC;AAE9E,kCAAkC;AAClC,OAAO,EAAE,iBAAiB,EAAE,MAAM,mCAAmC,CAAC;AACtE,OAAO,EAAE,gBAAgB,EAAE,MAAM,kCAAkC,CAAC;AACpE,OAAO,EAAE,kBAAkB,EAAkC,MAAM,oCAAoC,CAAC;AACxG,OAAO,EAAE,aAAa,EAAE,MAAM,+BAA+B,CAAC;AAC9D,OAAO,EAAE,cAAc,EAAE,MAAM,gCAAgC,CAAC;AAEhE,0BAA0B;AAC1B,OAAO,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAC;AACzD,OAAO,EACL,iBAAiB,GAGlB,MAAM,0CAA0C,CAAC;AAClD,OAAO,EAAE,UAAU,EAAE,iBAAiB,EAAE,MAAM,6BAA6B,CAAC;AAC5E,OAAO,EAAE,eAAe,EAAE,MAAM,kCAAkC,CAAC;AACnE,OAAO,EAAE,qBAAqB,EAAE,MAAM,wCAAwC,CAAC;AAE/E,qFAAqF;AACrF,OAAO,EAAE,kBAAkB,EAAE,MAAM,gCAAgC,CAAC;AACpE,OAAO,EAAE,YAAY,EAAE,MAAM,0BAA0B,CAAC","sourcesContent":["// Package definition parsing\nexport { PackageDefinitions } from './packageDefinitions/PackageDefinitions.js';\nexport { MockPackageDefinitions } from './packageDefinitions/MockPackageDefinitions.js';\n\n// ResolveMaps\nexport { createResolveMap } from './resolveMap/createResolveMap.js';\nexport { findResolveMapEntry } from './resolveMap/findResolveMapEntry.js';\nexport type { DiffResolveMapsChanges, DiffResolveMapsStats } from './resolveMap/diffResolveMaps.js';\nexport { diffResolveMaps } from './resolveMap/diffResolveMaps.js';\nexport { ensureResolveMapEntry } from './resolveMap/ensureResolveMapEntry.js';\n\n// ExportsMap parsing and creation\nexport { flattenExportsMap } from './exportsMap/flattenExportsMap.js';\nexport { createExportsMap } from './exportsMap/createExportsMap.js';\nexport { addExportsMapEntry, type AddExportsMapEntryOptions } from './exportsMap/addExportsMapEntry.js';\nexport { getExportsMap } from './exportsMap/getExportsMap.js';\nexport { getSourceEntry } from './exportsMap/getSourceEntry.js';\n\n// Other package utilities\nexport { detectModuleType } from './detectModuleType.js';\nexport {\n findFileInPackage,\n type FindFileInPackageOptions,\n type FindFileInPackageResult,\n} from './findFileInPackage/findFileInPackage.js';\nexport { getVersion, getDisplayVersion } from './packageJson/getVersion.js';\nexport { getDependencies } from './packageJson/getDependencies.js';\nexport { getUnusedDependencies } from './packageJson/getUnusedDependencies.js';\n\n// Object utilities which could be moved to a separate package if we add more of them\nexport { mergeArrayDefaults } from './object/mergeArrayDefaults.js';\nexport { mergeObjects } from './object/mergeObjects.js';\n"]}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,6BAA6B;AAC7B,OAAO,EAAE,kBAAkB,EAAE,MAAM,4CAA4C,CAAC;AAChF,OAAO,EAAE,sBAAsB,EAAE,MAAM,gDAAgD,CAAC;AAExF,cAAc;AACd,OAAO,EAAE,gBAAgB,EAAE,MAAM,kCAAkC,CAAC;AACpE,OAAO,EAAE,mBAAmB,EAAE,MAAM,qCAAqC,CAAC;AAE1E,OAAO,EAAE,eAAe,EAAE,MAAM,iCAAiC,CAAC;AAClE,OAAO,EAAE,qBAAqB,EAAE,MAAM,uCAAuC,CAAC;AAE9E,kCAAkC;AAClC,OAAO,EAAE,iBAAiB,EAAE,MAAM,mCAAmC,CAAC;AACtE,OAAO,EAAE,kBAAkB,EAAkC,MAAM,oCAAoC,CAAC;AACxG,OAAO,EAAE,aAAa,EAAE,MAAM,+BAA+B,CAAC;AAC9D,OAAO,EAAE,cAAc,EAAE,MAAM,gCAAgC,CAAC;AAEhE,0BAA0B;AAC1B,OAAO,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAC;AACzD,OAAO,EACL,iBAAiB,GAGlB,MAAM,0CAA0C,CAAC;AAClD,OAAO,EAAE,UAAU,EAAE,iBAAiB,EAAE,MAAM,6BAA6B,CAAC;AAC5E,OAAO,EAAE,eAAe,EAAE,MAAM,kCAAkC,CAAC;AACnE,OAAO,EAAE,qBAAqB,EAAE,MAAM,wCAAwC,CAAC;AAE/E,qFAAqF;AACrF,OAAO,EAAE,kBAAkB,EAAE,MAAM,gCAAgC,CAAC;AACpE,OAAO,EAAE,YAAY,EAAE,MAAM,0BAA0B,CAAC","sourcesContent":["// Package definition parsing\nexport { PackageDefinitions } from './packageDefinitions/PackageDefinitions.js';\nexport { MockPackageDefinitions } from './packageDefinitions/MockPackageDefinitions.js';\n\n// ResolveMaps\nexport { createResolveMap } from './resolveMap/createResolveMap.js';\nexport { findResolveMapEntry } from './resolveMap/findResolveMapEntry.js';\nexport type { DiffResolveMapsChanges, DiffResolveMapsStats } from './resolveMap/diffResolveMaps.js';\nexport { diffResolveMaps } from './resolveMap/diffResolveMaps.js';\nexport { ensureResolveMapEntry } from './resolveMap/ensureResolveMapEntry.js';\n\n// ExportsMap parsing and creation\nexport { flattenExportsMap } from './exportsMap/flattenExportsMap.js';\nexport { addExportsMapEntry, type AddExportsMapEntryOptions } from './exportsMap/addExportsMapEntry.js';\nexport { getExportsMap } from './exportsMap/getExportsMap.js';\nexport { getSourceEntry } from './exportsMap/getSourceEntry.js';\n\n// Other package utilities\nexport { detectModuleType } from './detectModuleType.js';\nexport {\n findFileInPackage,\n type FindFileInPackageOptions,\n type FindFileInPackageResult,\n} from './findFileInPackage/findFileInPackage.js';\nexport { getVersion, getDisplayVersion } from './packageJson/getVersion.js';\nexport { getDependencies } from './packageJson/getDependencies.js';\nexport { getUnusedDependencies } from './packageJson/getUnusedDependencies.js';\n\n// Object utilities which could be moved to a separate package if we add more of them\nexport { mergeArrayDefaults } from './object/mergeArrayDefaults.js';\nexport { mergeObjects } from './object/mergeObjects.js';\n"]}
@@ -7,11 +7,11 @@ export function mergeArrayDefaults(values, defaults) {
7
7
  if (!values) {
8
8
  return [...defaults];
9
9
  }
10
- values = [...values];
10
+ const newValues = [...values];
11
11
  const defaultsIndex = values.indexOf('...');
12
12
  if (defaultsIndex > -1) {
13
- values.splice(defaultsIndex, 1, ...defaults);
13
+ newValues.splice(defaultsIndex, 1, ...defaults);
14
14
  }
15
- return values;
15
+ return newValues;
16
16
  }
17
17
  //# sourceMappingURL=mergeArrayDefaults.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"mergeArrayDefaults.js","sourceRoot":"","sources":["../../src/object/mergeArrayDefaults.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,MAAM,UAAU,kBAAkB,CAAI,MAAiC,EAAE,QAAa;IACpF,IAAI,CAAC,MAAM,EAAE,CAAC;QACZ,OAAO,CAAC,GAAG,QAAQ,CAAC,CAAC;IACvB,CAAC;IACD,MAAM,GAAG,CAAC,GAAG,MAAM,CAAC,CAAC;IACrB,MAAM,aAAa,GAAG,MAAM,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC;IAC5C,IAAI,aAAa,GAAG,CAAC,CAAC,EAAE,CAAC;QACvB,MAAM,CAAC,MAAM,CAAC,aAAa,EAAE,CAAC,EAAE,GAAG,QAAQ,CAAC,CAAC;IAC/C,CAAC;IACD,OAAO,MAAa,CAAC;AACvB,CAAC","sourcesContent":["/**\n * Replace a '...' in an array with the provided defaults.\n * Returns a new array regardless of whether a replacement was made.\n * If `values` is undefined, returns a copy of the defaults array.\n */\nexport function mergeArrayDefaults<T>(values: (T | '...')[] | undefined, defaults: T[]): T[] {\n if (!values) {\n return [...defaults];\n }\n values = [...values];\n const defaultsIndex = values.indexOf('...');\n if (defaultsIndex > -1) {\n values.splice(defaultsIndex, 1, ...defaults);\n }\n return values as T[];\n}\n"]}
1
+ {"version":3,"file":"mergeArrayDefaults.js","sourceRoot":"","sources":["../../src/object/mergeArrayDefaults.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,MAAM,UAAU,kBAAkB,CAAI,MAAiC,EAAE,QAAa;IACpF,IAAI,CAAC,MAAM,EAAE,CAAC;QACZ,OAAO,CAAC,GAAG,QAAQ,CAAC,CAAC;IACvB,CAAC;IACD,MAAM,SAAS,GAAG,CAAC,GAAG,MAAM,CAAQ,CAAC;IACrC,MAAM,aAAa,GAAG,MAAM,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC;IAC5C,IAAI,aAAa,GAAG,CAAC,CAAC,EAAE,CAAC;QACvB,SAAS,CAAC,MAAM,CAAC,aAAa,EAAE,CAAC,EAAE,GAAG,QAAQ,CAAC,CAAC;IAClD,CAAC;IACD,OAAO,SAAS,CAAC;AACnB,CAAC","sourcesContent":["/**\n * Replace a '...' in an array with the provided defaults.\n * Returns a new array regardless of whether a replacement was made.\n * If `values` is undefined, returns a copy of the defaults array.\n */\nexport function mergeArrayDefaults<T>(values: (T | '...')[] | undefined, defaults: T[]): T[] {\n if (!values) {\n return [...defaults];\n }\n const newValues = [...values] as T[];\n const defaultsIndex = values.indexOf('...');\n if (defaultsIndex > -1) {\n newValues.splice(defaultsIndex, 1, ...defaults);\n }\n return newValues;\n}\n"]}
@@ -1,7 +1,10 @@
1
1
  import type { PackageJson, PackageJsonDependencies } from '@ms-cloudpack/common-types';
2
2
  /**
3
3
  * Get the dependencies that are potentially used at runtime and considered for bundling by cloudpack
4
- * (currently prod and peer).
4
+ * (currently prod and peer). Or if `options.includeAll` is true, also include dev and optional.
5
5
  */
6
- export declare function getDependencies(definition: PackageJson): PackageJsonDependencies;
6
+ export declare function getDependencies(definition: PackageJson, options?: {
7
+ /** If true, also include dev and optional dependencies. */
8
+ includeAll?: boolean;
9
+ }): PackageJsonDependencies;
7
10
  //# sourceMappingURL=getDependencies.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"getDependencies.d.ts","sourceRoot":"","sources":["../../src/packageJson/getDependencies.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,uBAAuB,EAAE,MAAM,4BAA4B,CAAC;AAEvF;;;GAGG;AACH,wBAAgB,eAAe,CAAC,UAAU,EAAE,WAAW,GAAG,uBAAuB,CAOhF"}
1
+ {"version":3,"file":"getDependencies.d.ts","sourceRoot":"","sources":["../../src/packageJson/getDependencies.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,uBAAuB,EAAE,MAAM,4BAA4B,CAAC;AAEvF;;;GAGG;AACH,wBAAgB,eAAe,CAC7B,UAAU,EAAE,WAAW,EACvB,OAAO,CAAC,EAAE;IACR,2DAA2D;IAC3D,UAAU,CAAC,EAAE,OAAO,CAAC;CACtB,GACA,uBAAuB,CASzB"}
@@ -1,11 +1,12 @@
1
1
  /**
2
2
  * Get the dependencies that are potentially used at runtime and considered for bundling by cloudpack
3
- * (currently prod and peer).
3
+ * (currently prod and peer). Or if `options.includeAll` is true, also include dev and optional.
4
4
  */
5
- export function getDependencies(definition) {
6
- // This is very simple but needs to be consistent between multiple places,
7
- // especially in case it needs to be changed somehow later.
5
+ export function getDependencies(definition, options) {
6
+ const { includeAll } = options || {};
8
7
  return {
8
+ ...(includeAll ? definition.devDependencies : {}),
9
+ ...(includeAll ? definition.optionalDependencies : {}),
9
10
  ...definition.dependencies,
10
11
  ...definition.peerDependencies,
11
12
  };
@@ -1 +1 @@
1
- {"version":3,"file":"getDependencies.js","sourceRoot":"","sources":["../../src/packageJson/getDependencies.ts"],"names":[],"mappings":"AAEA;;;GAGG;AACH,MAAM,UAAU,eAAe,CAAC,UAAuB;IACrD,0EAA0E;IAC1E,2DAA2D;IAC3D,OAAO;QACL,GAAG,UAAU,CAAC,YAAY;QAC1B,GAAG,UAAU,CAAC,gBAAgB;KAC/B,CAAC;AACJ,CAAC","sourcesContent":["import type { PackageJson, PackageJsonDependencies } from '@ms-cloudpack/common-types';\n\n/**\n * Get the dependencies that are potentially used at runtime and considered for bundling by cloudpack\n * (currently prod and peer).\n */\nexport function getDependencies(definition: PackageJson): PackageJsonDependencies {\n // This is very simple but needs to be consistent between multiple places,\n // especially in case it needs to be changed somehow later.\n return {\n ...definition.dependencies,\n ...definition.peerDependencies,\n };\n}\n"]}
1
+ {"version":3,"file":"getDependencies.js","sourceRoot":"","sources":["../../src/packageJson/getDependencies.ts"],"names":[],"mappings":"AAEA;;;GAGG;AACH,MAAM,UAAU,eAAe,CAC7B,UAAuB,EACvB,OAGC;IAED,MAAM,EAAE,UAAU,EAAE,GAAG,OAAO,IAAI,EAAE,CAAC;IAErC,OAAO;QACL,GAAG,CAAC,UAAU,CAAC,CAAC,CAAC,UAAU,CAAC,eAAe,CAAC,CAAC,CAAC,EAAE,CAAC;QACjD,GAAG,CAAC,UAAU,CAAC,CAAC,CAAC,UAAU,CAAC,oBAAoB,CAAC,CAAC,CAAC,EAAE,CAAC;QACtD,GAAG,UAAU,CAAC,YAAY;QAC1B,GAAG,UAAU,CAAC,gBAAgB;KAC/B,CAAC;AACJ,CAAC","sourcesContent":["import type { PackageJson, PackageJsonDependencies } from '@ms-cloudpack/common-types';\n\n/**\n * Get the dependencies that are potentially used at runtime and considered for bundling by cloudpack\n * (currently prod and peer). Or if `options.includeAll` is true, also include dev and optional.\n */\nexport function getDependencies(\n definition: PackageJson,\n options?: {\n /** If true, also include dev and optional dependencies. */\n includeAll?: boolean;\n },\n): PackageJsonDependencies {\n const { includeAll } = options || {};\n\n return {\n ...(includeAll ? definition.devDependencies : {}),\n ...(includeAll ? definition.optionalDependencies : {}),\n ...definition.dependencies,\n ...definition.peerDependencies,\n };\n}\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ms-cloudpack/package-utilities",
3
- "version": "11.1.2",
3
+ "version": "11.3.0",
4
4
  "description": "Utilities for resolving/parsing packages and their imports.",
5
5
  "license": "MIT",
6
6
  "type": "module",
@@ -14,10 +14,10 @@
14
14
  }
15
15
  },
16
16
  "dependencies": {
17
- "@ms-cloudpack/common-types": "^0.24.2",
17
+ "@ms-cloudpack/common-types": "^0.24.3",
18
18
  "@ms-cloudpack/json-utilities": "^0.1.10",
19
19
  "@ms-cloudpack/path-string-parsing": "^1.2.6",
20
- "@ms-cloudpack/path-utilities": "^2.8.3",
20
+ "@ms-cloudpack/path-utilities": "^3.0.0",
21
21
  "@ms-cloudpack/task-reporter": "^0.14.8",
22
22
  "acorn": "^8.11.2",
23
23
  "acorn-walk": "^8.2.1",