@ms-cloudpack/package-utilities 2.4.2 → 2.4.3

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 +1 @@
1
- {"version":3,"file":"findFileInPackage.d.ts","sourceRoot":"","sources":["../src/findFileInPackage.ts"],"names":[],"mappings":"AAOA,MAAM,MAAM,wBAAwB,GAAG;IACrC,WAAW,EAAE,MAAM,CAAC;IACpB,QAAQ,EAAE,MAAM,CAAC;CAClB,CAAC;AAEF,MAAM,MAAM,uBAAuB,GAAG;IACpC,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,UAAU,CAAC,EAAE,MAAM,CAAC;CACrB,CAAC;AAEF;;;;;;;;;GASG;AAEH,wBAAsB,iBAAiB,CAAC,OAAO,EAAE,wBAAwB,GAAG,OAAO,CAAC,uBAAuB,CAAC,CA+E3G"}
1
+ {"version":3,"file":"findFileInPackage.d.ts","sourceRoot":"","sources":["../src/findFileInPackage.ts"],"names":[],"mappings":"AAOA,MAAM,MAAM,wBAAwB,GAAG;IACrC,WAAW,EAAE,MAAM,CAAC;IACpB,QAAQ,EAAE,MAAM,CAAC;CAClB,CAAC;AAEF,MAAM,MAAM,uBAAuB,GAAG;IACpC,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,UAAU,CAAC,EAAE,MAAM,CAAC;CACrB,CAAC;AAEF;;;;;;;;;GASG;AAEH,wBAAsB,iBAAiB,CAAC,OAAO,EAAE,wBAAwB,GAAG,OAAO,CAAC,uBAAuB,CAAC,CAkF3G"}
@@ -59,14 +59,16 @@ export async function findFileInPackage(options) {
59
59
  const nestedDefinitionPath = path.dirname(path.join(packagePath, filePath));
60
60
  const exportsMap = await getExportsMap(nestedDefinitionPath);
61
61
  const entryPath = flattenExportsMap(exportsMap)['.'];
62
- typesPath = flattenExportsMap(exportsMap, { conditions: ['types'] })['.'];
63
- return {
64
- ...(await findFileInPackage({
65
- packagePath,
66
- filePath: safeRelativePath(path.relative(packagePath, path.join(nestedDefinitionPath, entryPath))),
67
- })),
68
- typesPath: safeRelativePath(path.relative(packagePath, path.join(nestedDefinitionPath, typesPath))),
69
- };
62
+ if (entryPath) {
63
+ typesPath = flattenExportsMap(exportsMap, { conditions: ['types'] })['.'];
64
+ return {
65
+ ...(await findFileInPackage({
66
+ packagePath,
67
+ filePath: safeRelativePath(path.relative(packagePath, path.join(nestedDefinitionPath, entryPath))),
68
+ })),
69
+ typesPath: typesPath && safeRelativePath(path.relative(packagePath, path.join(nestedDefinitionPath, typesPath))),
70
+ };
71
+ }
70
72
  }
71
73
  if (typesPath) {
72
74
  result.typesPath = safeRelativePath(typesPath);
@@ -1 +1 @@
1
- {"version":3,"file":"findFileInPackage.js","sourceRoot":"","sources":["../src/findFileInPackage.ts"],"names":[],"mappings":"AAAA,OAAO,IAAI,MAAM,MAAM,CAAC;AACxB,OAAO,EAAE,wBAAwB,EAAE,wBAAwB,EAAE,MAAM,EAAE,MAAM,8BAA8B,CAAC;AAC1G,OAAO,EAAE,iBAAiB,EAAE,MAAM,wBAAwB,CAAC;AAC3D,OAAO,EAAE,gBAAgB,EAAE,MAAM,mCAAmC,CAAC;AACrE,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AACnD,OAAO,EAAE,iBAAiB,EAAE,MAAM,wBAAwB,CAAC;AAa3D;;;;;;;;;GASG;AAEH,MAAM,CAAC,KAAK,UAAU,iBAAiB,CAAC,OAAiC;IACvE,MAAM,EAAE,WAAW,EAAE,GAAG,OAAO,CAAC;IAChC,IAAI,QAAQ,GAAuB,gBAAgB,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAC;IACtE,IAAI,UAA8B,CAAC;IACnC,IAAI,SAA6B,CAAC;IAClC,MAAM,UAAU,GAAG,CAAC,iBAAiB,CAAC,WAAW,CAAC,CAAC;IAEnD,MAAM,UAAU,GAAG;QAC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ediatePath, isFile } from '@ms-cloudpack/path-utilities';\nimport { isExternalPackage } from './isExternalPackage.js';\nimport { safeRelativePath } from '@ms-cloudpack/path-string-parsing';\nimport { getExportsMap } from './getExportsMap.js';\nimport { flattenExportsMap } from './flattenExportsMap.js';\n\nexport type FindFileInPackageOptions = {\n packagePath: string;\n filePath: string;\n};\n\nexport type FindFileInPackageResult = {\n filePath?: string;\n typesPath?: string;\n sourcePath?: string;\n};\n\n/**\n * Given a requested partial filePath, resolves the relative path 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 */\n\nexport async function findFileInPackage(options: FindFileInPackageOptions): Promise<FindFileInPackageResult> {\n const { packagePath } = options;\n let filePath: string | undefined = safeRelativePath(options.filePath);\n let sourcePath: string | undefined;\n let typesPath: string | undefined;\n const isInternal = !isExternalPackage(packagePath);\n\n const candidates = [\n filePath,\n filePath + '.js',\n safeRelativePath(path.join(filePath, 'index.js')),\n safeRelativePath(path.join(filePath, 'package.json')),\n ];\n\n filePath = undefined;\n for (const candidate of candidates) {\n if (await isFile(path.join(packagePath, candidate))) {\n filePath = candidate;\n break;\n }\n }\n\n // For internal packages, try and find source/typings and convert to intermediate (which may be missing.)\n if (isInternal) {\n for (const candidate of candidates) {\n const intermediateCandidate = intermediateToSourcePath(candidate, packagePath);\n if (intermediateCandidate && (await isFile(path.join(packagePath, intermediateCandidate)))) {\n sourcePath = intermediateCandidate;\n break;\n }\n }\n\n // If we couldn't find a unique source file, stick with the resolved intermediate file as the only known truth.\n if (filePath && sourcePath === filePath) {\n sourcePath = undefined;\n }\n\n if (sourcePath) {\n if (!filePath) {\n filePath = sourceToIntermediatePath(sourcePath);\n }\n\n typesPath = filePath && path.extname(filePath) === '.js' ? filePath.replace(/\\.js$/, '.d.ts') : undefined;\n }\n }\n\n const isNestedPackageDefinition =\n filePath && path.basename(filePath) === 'package.json' && path.basename(options.filePath) !== '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(nestedDefinitionPath);\n const entryPath = flattenExportsMap(exportsMap)['.'];\n\n typesPath = flattenExportsMap(exportsMap, { conditions: ['types'] })['.'];\n\n return {\n ...(await findFileInPackage({\n packagePath,\n filePath: safeRelativePath(path.relative(packagePath, path.join(nestedDefinitionPath, entryPath))),\n })),\n typesPath: safeRelativePath(path.relative(packagePath, path.join(nestedDefinitionPath, typesPath))),\n };\n }\n\n if (typesPath) {\n result.typesPath = safeRelativePath(typesPath);\n }\n\n if (filePath) {\n result.filePath = safeRelativePath(filePath);\n }\n\n if (sourcePath) {\n result.sourcePath = safeRelativePath(sourcePath);\n }\n\n return result;\n}\n"]}
1
+ {"version":3,"file":"findFileInPackage.js","sourceRoot":"","sources":["../src/findFileInPackage.ts"],"names":[],"mappings":"AAAA,OAAO,IAAI,MAAM,MAAM,CAAC;AACxB,OAAO,EAAE,wBAAwB,EAAE,wBAAwB,EAAE,MAAM,EAAE,MAAM,8BAA8B,CAAC;AAC1G,OAAO,EAAE,iBAAiB,EAAE,MAAM,wBAAwB,CAAC;AAC3D,OAAO,EAAE,gBAAgB,EAAE,MAAM,mCAAmC,CAAC;AACrE,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AACnD,OAAO,EAAE,iBAAiB,EAAE,MAAM,wBAAwB,CAAC;AAa3D;;;;;;;;;GASG;AAEH,MAAM,CAAC,KAAK,UAAU,iBAAiB,CAAC,OAAiC;IACvE,MAAM,EAAE,WAAW,EAAE,GAAG,OAAO,CAAC;IAChC,IAAI,QAAQ,GAAuB,gBAAgB,CAAC,OAAO,CAAC,QAAQ,CAAC,CAA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,CAAC;KAC9C;IAED,IAAI,UAAU,EAAE;QACd,MAAM,CAAC,UAAU,GAAG,gBAAgB,CAAC,UAAU,CAAC,CAAC;KAClD;IAED,OAAO,MAAM,CAAC;AAChB,CAAC","sourcesContent":["import path from 'path';\nimport { intermediateToSourcePath, sourceToIntermediatePath, isFile } from '@ms-cloudpack/path-utilities';\nimport { isExternalPackage } from './isExternalPackage.js';\nimport { safeRelativePath } from '@ms-cloudpack/path-string-parsing';\nimport { getExportsMap } from './getExportsMap.js';\nimport { flattenExportsMap } from './flattenExportsMap.js';\n\nexport type FindFileInPackageOptions = {\n packagePath: string;\n filePath: string;\n};\n\nexport type FindFileInPackageResult = {\n filePath?: string;\n typesPath?: string;\n sourcePath?: string;\n};\n\n/**\n * Given a requested partial filePath, resolves the relative path 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 */\n\nexport async function findFileInPackage(options: FindFileInPackageOptions): Promise<FindFileInPackageResult> {\n const { packagePath } = options;\n let filePath: string | undefined = safeRelativePath(options.filePath);\n let sourcePath: string | undefined;\n let typesPath: string | undefined;\n const isInternal = !isExternalPackage(packagePath);\n\n const candidates = [\n filePath,\n filePath + '.js',\n safeRelativePath(path.join(filePath, 'index.js')),\n safeRelativePath(path.join(filePath, 'package.json')),\n ];\n\n filePath = undefined;\n for (const candidate of candidates) {\n if (await isFile(path.join(packagePath, candidate))) {\n filePath = candidate;\n break;\n }\n }\n\n // For internal packages, try and find source/typings and convert to intermediate (which may be missing.)\n if (isInternal) {\n for (const candidate of candidates) {\n const intermediateCandidate = intermediateToSourcePath(candidate, packagePath);\n if (intermediateCandidate && (await isFile(path.join(packagePath, intermediateCandidate)))) {\n sourcePath = intermediateCandidate;\n break;\n }\n }\n\n // If we couldn't find a unique source file, stick with the resolved intermediate file as the only known truth.\n if (filePath && sourcePath === filePath) {\n sourcePath = undefined;\n }\n\n if (sourcePath) {\n if (!filePath) {\n filePath = sourceToIntermediatePath(sourcePath);\n }\n\n typesPath = filePath && path.extname(filePath) === '.js' ? filePath.replace(/\\.js$/, '.d.ts') : undefined;\n }\n }\n\n const isNestedPackageDefinition =\n filePath && path.basename(filePath) === 'package.json' && path.basename(options.filePath) !== '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(nestedDefinitionPath);\n const entryPath = flattenExportsMap(exportsMap)['.'];\n\n if (entryPath) {\n typesPath = flattenExportsMap(exportsMap, { conditions: ['types'] })['.'];\n\n return {\n ...(await findFileInPackage({\n packagePath,\n filePath: safeRelativePath(path.relative(packagePath, path.join(nestedDefinitionPath, entryPath))),\n })),\n typesPath:\n typesPath && safeRelativePath(path.relative(packagePath, path.join(nestedDefinitionPath, typesPath))),\n };\n }\n }\n\n if (typesPath) {\n result.typesPath = safeRelativePath(typesPath);\n }\n\n if (filePath) {\n result.filePath = safeRelativePath(filePath);\n }\n\n if (sourcePath) {\n result.sourcePath = safeRelativePath(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": "2.4.2",
3
+ "version": "2.4.3",
4
4
  "description": "Utilities for resolving/parsing packages and their imports.",
5
5
  "license": "MIT",
6
6
  "type": "module",