@ms-cloudpack/package-utilities 6.0.0 → 6.0.2

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,4 +1,3 @@
1
- import {} from '@ms-cloudpack/config-types';
2
1
  import { normalizeRelativePath, slash } from '@ms-cloudpack/path-string-parsing';
3
2
  import { intermediateToSourcePath, isFileSync, sourceToIntermediatePath } from '@ms-cloudpack/path-utilities';
4
3
  import path from 'path';
@@ -1 +1 @@
1
- {"version":3,"file":"findFileInPackage.js","sourceRoot":"","sources":["../src/findFileInPackage.ts"],"names":[],"mappings":"AACA,OAAO,EAAwB,MAAM,4BAA4B,CAAC;AAClE,OAAO,EAAE,qBAAqB,EAAE,KAAK,EAAE,MAAM,mCAAmC,CAAC;AACjF,OAAO,EAAE,wBAAwB,EAAE,UAAU,EAAE,wBAAwB,EAAE,MAAM,8BAA8B,CAAC;AAC9G,OAAO,IAAI,MAAM,MAAM,CAAC;AACxB,OAAO,EAAE,iBAAiB,EAAE,MAAM,wBAAwB,CAAC;AAC3D,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AACnD,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AACnD,OAAO,EAAE,iBAAiB,EAAE,MAAM,wBAAwB,CAAC;AAE3D,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;AAarD;;;;;;;;;GASG;AACH,MAAM,CAAC,KAAK,UAAU,iBAAiB,CACrC,OAAiC,EACjC,OAAuE;IAEvE,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,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AS,CAAC;QACxB,CAAC;IACH,CAAC;IAED,IAAI,SAAS,EAAE,CAAC;QACd,MAAM,CAAC,SAAS,GAAG,qBAAqB,CAAC,SAAS,CAAC,CAAC;IACtD,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 { PackageDefinitionsCache } from '@ms-cloudpack/bundler-types';\nimport { type CloudpackConfig } from '@ms-cloudpack/config-types';\nimport { normalizeRelativePath, slash } from '@ms-cloudpack/path-string-parsing';\nimport { intermediateToSourcePath, isFileSync, sourceToIntermediatePath } from '@ms-cloudpack/path-utilities';\nimport path from 'path';\nimport { flattenExportsMap } from './flattenExportsMap.js';\nimport { getCandidates } from './getCandidates.js';\nimport { getExportsMap } from './getExportsMap.js';\nimport { isExternalPackage } from './isExternalPackage.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 typesPath?: 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: CloudpackConfig },\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 let typesPath: string | undefined;\n const isInternal = !isExternalPackage(packagePath);\n const candidates = getCandidates({ filePath: originalPath, packagePath }, context);\n\n // Try and resolve a physical file given the candidates.\n // eslint-disable-next-line @ms-cloudpack/internal/no-sync-filesystem\n filePath = candidates.find((candidate) => isFileSync(path.join(packagePath, candidate)));\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 typesPath = flattenExportsMap(exportsMap, { conditions: ['types'] })['.'];\n\n return {\n ...(await findFileInPackage(\n {\n packagePath,\n filePath: normalizeRelativePath(path.relative(packagePath, path.join(nestedDefinitionPath, entryPath))),\n },\n context,\n )),\n typesPath:\n typesPath && normalizeRelativePath(path.relative(packagePath, path.join(nestedDefinitionPath, typesPath))),\n };\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 // Try to resolve the typesPath\n if (sourcePath && filePath) {\n typesPath = filePath.replace(/\\.js$/, '.d.ts');\n\n // eslint-disable-next-line @ms-cloudpack/internal/no-sync-filesystem\n if (!isInternal && !isFileSync(path.join(packagePath, typesPath))) {\n typesPath = undefined;\n }\n }\n\n if (typesPath) {\n result.typesPath = normalizeRelativePath(typesPath);\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.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,qBAAqB,EAAE,KAAK,EAAE,MAAM,mCAAmC,CAAC;AACjF,OAAO,EAAE,wBAAwB,EAAE,UAAU,EAAE,wBAAwB,EAAE,MAAM,8BAA8B,CAAC;AAC9G,OAAO,IAAI,MAAM,MAAM,CAAC;AACxB,OAAO,EAAE,iBAAiB,EAAE,MAAM,wBAAwB,CAAC;AAC3D,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AACnD,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AACnD,OAAO,EAAE,iBAAiB,EAAE,MAAM,wBAAwB,CAAC;AAE3D,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;AAarD;;;;;;;;;GASG;AACH,MAAM,CAAC,KAAK,UAAU,iBAAiB,CACrC,OAAiC,EACjC,OAAuE;IAEvE,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,IAAI,SAA6B,CAAC;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AAC;QACd,MAAM,CAAC,SAAS,GAAG,qBAAqB,CAAC,SAAS,CAAC,CAAC;IACtD,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 { PackageDefinitionsCache } from '@ms-cloudpack/bundler-types';\nimport { type CloudpackConfig } from '@ms-cloudpack/config-types';\nimport { normalizeRelativePath, slash } from '@ms-cloudpack/path-string-parsing';\nimport { intermediateToSourcePath, isFileSync, sourceToIntermediatePath } from '@ms-cloudpack/path-utilities';\nimport path from 'path';\nimport { flattenExportsMap } from './flattenExportsMap.js';\nimport { getCandidates } from './getCandidates.js';\nimport { getExportsMap } from './getExportsMap.js';\nimport { isExternalPackage } from './isExternalPackage.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 typesPath?: 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: CloudpackConfig },\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 let typesPath: string | undefined;\n const isInternal = !isExternalPackage(packagePath);\n const candidates = getCandidates({ filePath: originalPath, packagePath }, context);\n\n // Try and resolve a physical file given the candidates.\n // eslint-disable-next-line @ms-cloudpack/internal/no-sync-filesystem\n filePath = candidates.find((candidate) => isFileSync(path.join(packagePath, candidate)));\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 typesPath = flattenExportsMap(exportsMap, { conditions: ['types'] })['.'];\n\n return {\n ...(await findFileInPackage(\n {\n packagePath,\n filePath: normalizeRelativePath(path.relative(packagePath, path.join(nestedDefinitionPath, entryPath))),\n },\n context,\n )),\n typesPath:\n typesPath && normalizeRelativePath(path.relative(packagePath, path.join(nestedDefinitionPath, typesPath))),\n };\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 // Try to resolve the typesPath\n if (sourcePath && filePath) {\n typesPath = filePath.replace(/\\.js$/, '.d.ts');\n\n // eslint-disable-next-line @ms-cloudpack/internal/no-sync-filesystem\n if (!isInternal && !isFileSync(path.join(packagePath, typesPath))) {\n typesPath = undefined;\n }\n }\n\n if (typesPath) {\n result.typesPath = normalizeRelativePath(typesPath);\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 +1 @@
1
- {"version":3,"file":"findPackage.d.ts","sourceRoot":"","sources":["../src/findPackage.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,4BAA4B,CAAC;AAC9D,OAAO,KAAK,EAAE,uBAAuB,EAAE,sBAAsB,EAAE,MAAM,6BAA6B,CAAC;AAEnG;;;GAGG;AACH,wBAAsB,WAAW,CAC/B,OAAO,EAAE;IACP,cAAc,EAAE,MAAM,CAAC;IACvB,SAAS,EAAE,MAAM,CAAC;IAClB,eAAe,CAAC,EAAE,sBAAsB,CAAC;IACzC,QAAQ,CAAC,EAAE,MAAM,CAAC;CACnB,EACD,OAAO,EAAE;IACP,QAAQ,EAAE,uBAAuB,CAAC;CACnC,GACA,OAAO,CAAC;IAAE,WAAW,EAAE,MAAM,CAAC;IAAC,UAAU,EAAE,WAAW,CAAA;CAAE,GAAG,SAAS,CAAC,CA6BvE"}
1
+ {"version":3,"file":"findPackage.d.ts","sourceRoot":"","sources":["../src/findPackage.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,4BAA4B,CAAC;AAC9D,OAAO,KAAK,EAAE,uBAAuB,EAAE,sBAAsB,EAAE,MAAM,6BAA6B,CAAC;AAEnG;;;GAGG;AACH,wBAAsB,WAAW,CAC/B,OAAO,EAAE;IACP,cAAc,EAAE,MAAM,CAAC;IACvB,SAAS,EAAE,MAAM,CAAC;IAClB,eAAe,CAAC,EAAE,sBAAsB,CAAC;IACzC,QAAQ,CAAC,EAAE,MAAM,CAAC;CACnB,EACD,OAAO,EAAE;IACP,QAAQ,EAAE,uBAAuB,CAAC;CACnC,GACA,OAAO,CAAC;IAAE,WAAW,EAAE,MAAM,CAAC;IAAC,UAAU,EAAE,WAAW,CAAA;CAAE,GAAG,SAAS,CAAC,CAgCvE"}
@@ -8,6 +8,7 @@ export async function findPackage(options, context) {
8
8
  const { dependencyName, rootPath, startPath, importerContext } = options;
9
9
  const { packages } = context;
10
10
  let packagePath = startPath;
11
+ const isStoreLayout = /[\\/]\.(pnpm|store)[\\/]/.test(packagePath);
11
12
  do {
12
13
  const resolvedPath = path.join(packagePath, 'node_modules', dependencyName);
13
14
  const definition = await packages.get(resolvedPath, { importerContext });
@@ -17,7 +18,9 @@ export async function findPackage(options, context) {
17
18
  // We haven't found it. Try to move up a directory.
18
19
  packagePath = path.dirname(packagePath);
19
20
  // If we moved up into a scope folder, skip over it.
20
- if (path.basename(packagePath).startsWith('@')) {
21
+ // Exception: in a manager using a store layout, packages starting with @ are NOT scope folders;
22
+ // e.g. @foo/bar will be in a folder like @foo-bar-npm-1.2.3-abcdef1234 or @foo-bar@1.2.3
23
+ if (!isStoreLayout && path.basename(packagePath).startsWith('@')) {
21
24
  packagePath = path.dirname(packagePath);
22
25
  }
23
26
  // Skip over nested node_modules folders.
@@ -1 +1 @@
1
- {"version":3,"file":"findPackage.js","sourceRoot":"","sources":["../src/findPackage.ts"],"names":[],"mappings":"AAAA,OAAO,IAAI,MAAM,MAAM,CAAC;AACxB,OAAO,UAAU,MAAM,aAAa,CAAC;AAIrC;;;GAGG;AACH,MAAM,CAAC,KAAK,UAAU,WAAW,CAC/B,OAKC,EACD,OAEC;IAED,MAAM,EAAE,cAAc,EAAE,QAAQ,EAAE,SAAS,EAAE,eAAe,EAAE,GAAG,OAAO,CAAC;IACzE,MAAM,EAAE,QAAQ,EAAE,GAAG,OAAO,CAAC;IAE7B,IAAI,WAAW,GAAG,SAAS,CAAC;IAE5B,GAAG,CAAC;QACF,MAAM,YAAY,GAAG,IAAI,CAAC,IAAI,CAAC,WAAW,EAAE,cAAc,EAAE,cAAc,CAAC,CAAC;QAC5E,MAAM,UAAU,GAAG,MAAM,QAAQ,CAAC,GAAG,CAAC,YAAY,EAAE,EAAE,eAAe,EAAE,CAAC,CAAC;QAEzE,IAAI,UAAU,EAAE,CAAC;YACf,OAAO,EAAE,WAAW,EAAE,MAAM,UAAU,CAAC,QAAQ,CAAC,YAAY,CAAC,EAAE,UAAU,EAAE,CAAC;QAC9E,CAAC;QAED,mDAAmD;QACnD,WAAW,GAAG,IAAI,CAAC,OAAO,CAAC,WAAW,CAAC,CAAC;QAExC,oDAAoD;QACpD,IAAI,IAAI,CAAC,QAAQ,CAAC,WAAW,CAAC,CAAC,UAAU,CAAC,GAAG,CAAC,EAAE,CAAC;YAC/C,WAAW,GAAG,IAAI,CAAC,OAAO,CAAC,WAAW,CAAC,CAAC;QAC1C,CAAC;QAED,yCAAyC;QACzC,IAAI,WAAW,CAAC,QAAQ,CAAC,cAAc,CAAC,EAAE,CAAC;YACzC,WAAW,GAAG,IAAI,CAAC,OAAO,CAAC,WAAW,CAAC,CAAC;QAC1C,CAAC;IACH,CAAC,QAAQ,CAAC,CAAC,QAAQ,IAAI,WAAW,CAAC,MAAM,IAAI,QAAQ,CAAC,MAAM,CAAC,IAAI,IAAI,CAAC,OAAO,CAAC,WAAW,CAAC,KAAK,WAAW,EAAE;IAE5G,OAAO,SAAS,CAAC;AACnB,CAAC","sourcesContent":["import path from 'path';\nimport fsPromises from 'fs/promises';\nimport type { PackageJson } from '@ms-cloudpack/config-types';\nimport type { PackageDefinitionsCache, PackageImporterContext } from '@ms-cloudpack/bundler-types';\n\n/**\n * Find the package.json contents for `dependencyName`, searching up under `node_modules` folders\n * starting at `startPath` and ending at `rootPath` (usually the git root) or the filesystem root.\n */\nexport async function findPackage(\n options: {\n dependencyName: string;\n startPath: string;\n importerContext?: PackageImporterContext;\n rootPath?: string;\n },\n context: {\n packages: PackageDefinitionsCache;\n },\n): Promise<{ packagePath: string; definition: PackageJson } | undefined> {\n const { dependencyName, rootPath, startPath, importerContext } = options;\n const { packages } = context;\n\n let packagePath = startPath;\n\n do {\n const resolvedPath = path.join(packagePath, 'node_modules', dependencyName);\n const definition = await packages.get(resolvedPath, { importerContext });\n\n if (definition) {\n return { packagePath: await fsPromises.realpath(resolvedPath), definition };\n }\n\n // We haven't found it. Try to move up a directory.\n packagePath = path.dirname(packagePath);\n\n // If we moved up into a scope folder, skip over it.\n if (path.basename(packagePath).startsWith('@')) {\n packagePath = path.dirname(packagePath);\n }\n\n // Skip over nested node_modules folders.\n if (packagePath.endsWith('node_modules')) {\n packagePath = path.dirname(packagePath);\n }\n } while ((!rootPath || packagePath.length >= rootPath.length) && path.dirname(packagePath) !== packagePath);\n\n return undefined;\n}\n"]}
1
+ {"version":3,"file":"findPackage.js","sourceRoot":"","sources":["../src/findPackage.ts"],"names":[],"mappings":"AAAA,OAAO,IAAI,MAAM,MAAM,CAAC;AACxB,OAAO,UAAU,MAAM,aAAa,CAAC;AAIrC;;;GAGG;AACH,MAAM,CAAC,KAAK,UAAU,WAAW,CAC/B,OAKC,EACD,OAEC;IAED,MAAM,EAAE,cAAc,EAAE,QAAQ,EAAE,SAAS,EAAE,eAAe,EAAE,GAAG,OAAO,CAAC;IACzE,MAAM,EAAE,QAAQ,EAAE,GAAG,OAAO,CAAC;IAE7B,IAAI,WAAW,GAAG,SAAS,CAAC;IAC5B,MAAM,aAAa,GAAG,0BAA0B,CAAC,IAAI,CAAC,WAAW,CAAC,CAAC;IAEnE,GAAG,CAAC;QACF,MAAM,YAAY,GAAG,IAAI,CAAC,IAAI,CAAC,WAAW,EAAE,cAAc,EAAE,cAAc,CAAC,CAAC;QAC5E,MAAM,UAAU,GAAG,MAAM,QAAQ,CAAC,GAAG,CAAC,YAAY,EAAE,EAAE,eAAe,EAAE,CAAC,CAAC;QAEzE,IAAI,UAAU,EAAE,CAAC;YACf,OAAO,EAAE,WAAW,EAAE,MAAM,UAAU,CAAC,QAAQ,CAAC,YAAY,CAAC,EAAE,UAAU,EAAE,CAAC;QAC9E,CAAC;QAED,mDAAmD;QACnD,WAAW,GAAG,IAAI,CAAC,OAAO,CAAC,WAAW,CAAC,CAAC;QAExC,oDAAoD;QACpD,gGAAgG;QAChG,yFAAyF;QACzF,IAAI,CAAC,aAAa,IAAI,IAAI,CAAC,QAAQ,CAAC,WAAW,CAAC,CAAC,UAAU,CAAC,GAAG,CAAC,EAAE,CAAC;YACjE,WAAW,GAAG,IAAI,CAAC,OAAO,CAAC,WAAW,CAAC,CAAC;QAC1C,CAAC;QAED,yCAAyC;QACzC,IAAI,WAAW,CAAC,QAAQ,CAAC,cAAc,CAAC,EAAE,CAAC;YACzC,WAAW,GAAG,IAAI,CAAC,OAAO,CAAC,WAAW,CAAC,CAAC;QAC1C,CAAC;IACH,CAAC,QAAQ,CAAC,CAAC,QAAQ,IAAI,WAAW,CAAC,MAAM,IAAI,QAAQ,CAAC,MAAM,CAAC,IAAI,IAAI,CAAC,OAAO,CAAC,WAAW,CAAC,KAAK,WAAW,EAAE;IAE5G,OAAO,SAAS,CAAC;AACnB,CAAC","sourcesContent":["import path from 'path';\nimport fsPromises from 'fs/promises';\nimport type { PackageJson } from '@ms-cloudpack/config-types';\nimport type { PackageDefinitionsCache, PackageImporterContext } from '@ms-cloudpack/bundler-types';\n\n/**\n * Find the package.json contents for `dependencyName`, searching up under `node_modules` folders\n * starting at `startPath` and ending at `rootPath` (usually the git root) or the filesystem root.\n */\nexport async function findPackage(\n options: {\n dependencyName: string;\n startPath: string;\n importerContext?: PackageImporterContext;\n rootPath?: string;\n },\n context: {\n packages: PackageDefinitionsCache;\n },\n): Promise<{ packagePath: string; definition: PackageJson } | undefined> {\n const { dependencyName, rootPath, startPath, importerContext } = options;\n const { packages } = context;\n\n let packagePath = startPath;\n const isStoreLayout = /[\\\\/]\\.(pnpm|store)[\\\\/]/.test(packagePath);\n\n do {\n const resolvedPath = path.join(packagePath, 'node_modules', dependencyName);\n const definition = await packages.get(resolvedPath, { importerContext });\n\n if (definition) {\n return { packagePath: await fsPromises.realpath(resolvedPath), definition };\n }\n\n // We haven't found it. Try to move up a directory.\n packagePath = path.dirname(packagePath);\n\n // If we moved up into a scope folder, skip over it.\n // Exception: in a manager using a store layout, packages starting with @ are NOT scope folders;\n // e.g. @foo/bar will be in a folder like @foo-bar-npm-1.2.3-abcdef1234 or @foo-bar@1.2.3\n if (!isStoreLayout && path.basename(packagePath).startsWith('@')) {\n packagePath = path.dirname(packagePath);\n }\n\n // Skip over nested node_modules folders.\n if (packagePath.endsWith('node_modules')) {\n packagePath = path.dirname(packagePath);\n }\n } while ((!rootPath || packagePath.length >= rootPath.length) && path.dirname(packagePath) !== packagePath);\n\n return undefined;\n}\n"]}
@@ -1,5 +1,4 @@
1
1
  import { normalizeRelativePath } from '@ms-cloudpack/path-string-parsing';
2
- import {} from '@ms-cloudpack/config-types';
3
2
  import path from 'path';
4
3
  import { isExternalPackage } from './isExternalPackage.js';
5
4
  // Mappings to possible candidate extensions for a given input extension.
@@ -1 +1 @@
1
- {"version":3,"file":"getCandidates.js","sourceRoot":"","sources":["../src/getCandidates.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,qBAAqB,EAAE,MAAM,mCAAmC,CAAC;AAC1E,OAAO,EAAwB,MAAM,4BAA4B,CAAC;AAClE,OAAO,IAAI,MAAM,MAAM,CAAC;AACxB,OAAO,EAAE,iBAAiB,EAAE,MAAM,wBAAwB,CAAC;AAE3D,yEAAyE;AACzE,MAAM,kBAAkB,GAAG,CAAC,KAAK,EAAE,MAAM,EAAE,MAAM,CAAC,CAAC;AACnD,MAAM,kBAAkB,GAAG,CAAC,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,MAAM,CAAC,CAAC;AAC1F,MAAM,oBAAoB,GAA6B;IACrD,KAAK,EAAE,CAAC,KAAK,EAAE,KAAK,CAAC;IACrB,MAAM,EAAE,CAAC,MAAM,EAAE,KAAK,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AAC,IAAI,CAAC,gBAAgB,CAAC,CAAC;YACpC,CAAC;iBAAM,CAAC;gBACN,sBAAsB;gBACtB,IAAI,aAAa,EAAE,CAAC;oBAClB,WAAW,GAAG,WAAW,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC;gBACzC,CAAC;gBAED,UAAU,CAAC,IAAI,CAAC,GAAG,gBAAgB,CAAC,WAAW,GAAG,QAAQ,EAAE,UAAU,CAAC,CAAC,CAAC;gBACzE,UAAU,CAAC,IAAI,CAAC,WAAW,GAAG,eAAe,CAAC,CAAC;YACjD,CAAC;QACH,CAAC;QAED,yEAAyE;QACzE,IAAI,CAAC,UAAU,IAAI,eAAe,EAAE,CAAC;YACnC,UAAU,CAAC,IAAI,CAAC,WAAW,CAAC,CAAC;QAC/B,CAAC;IACH,CAAC;IAED,OAAO,UAAU,CAAC;AACpB,CAAC;AAED;;;;;;;;GAQG;AACH,SAAS,gBAAgB,CAAC,QAAgB,EAAE,UAAoB;IAC9D,MAAM,MAAM,GAAa,EAAE,CAAC;IAC5B,MAAM,GAAG,GAAG,IAAI,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAC;IAEnC,IAAI,UAAU,CAAC,QAAQ,CAAC,GAAG,CAAC,EAAE,CAAC;QAC7B,QAAQ,GAAG,GAAG,QAAQ,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,GAAG,CAAC,MAAM,CAAC,EAAE,CAAC;IACjD,CAAC;IAED,KAAK,MAAM,UAAU,IAAI,UAAU,EAAE,CAAC;QACpC,MAAM,CAAC,IAAI,CAAC,QAAQ,GAAG,UAAU,CAAC,CAAC;IACrC,CAAC;IAED,OAAO,MAAM,CAAC;AAChB,CAAC","sourcesContent":["import { normalizeRelativePath } from '@ms-cloudpack/path-string-parsing';\nimport { type CloudpackConfig } from '@ms-cloudpack/config-types';\nimport path from 'path';\nimport { isExternalPackage } from './isExternalPackage.js';\n\n// Mappings to possible candidate extensions for a given input extension.\nconst externalExtensions = ['.js', '.mjs', '.cjs'];\nconst internalExtensions = ['.ts', '.tsx', '.mts', '.cts', '.jsx', '.js', '.mjs', '.cjs'];\nconst internalExtensionMap: Record<string, string[]> = {\n '.ts': ['.ts', '.js'],\n '.tsx': ['.tsx', '.js'],\n '.mts': ['.mts', '.mjs', '.js'],\n '.cts': ['.cts', '.cjs', '.js'],\n '.jsx': ['.jsx', '.js'],\n '.js': ['.ts', '.tsx', '.mts', '.cts', '.jsx', '.js'],\n '.mjs': ['.mjs', '.js'],\n '.cjs': ['.cjs', '.js'],\n};\nconst externalExtensionMap: Record<string, string[]> = {\n '.ts': ['.js'],\n '.tsx': ['.js'],\n '.mts': ['.mjs'],\n '.cts': ['.cjs'],\n '.jsx': ['.js'],\n '.js': ['.js'],\n};\n\n/**\n * Given a packagePath and a filePath from its exports map (or main/module), build candidate paths\n * to look for the physical file in order of priority. For internal packages, we try to discover\n * source files first, and then fallback to the original file name. We also search for index files\n * and expand folder paths as well for ambiguous references. For external packages, we prioritize\n * intermediate paths.\n */\nexport function getCandidates(\n options: { filePath: string; packagePath: string },\n context: { config: CloudpackConfig },\n) {\n const { filePath, packagePath } = options;\n const resolveWebExtensions = Boolean(context.config.features?.resolveWebExtensions);\n const isBlankPath = !filePath || filePath === '.';\n const originalPath = isBlankPath ? './index' : normalizeRelativePath(filePath);\n const originalExt = path.extname(originalPath);\n const isInternal = !isExternalPackage(packagePath);\n const endsWithSlash = originalPath.endsWith('/');\n const candidates = [];\n const defaultExtensions = isInternal ? internalExtensions : externalExtensions;\n const defaultExtensionsWithSuffixes = resolveWebExtensions\n ? [...defaultExtensions.map((ext) => `.web${ext}`), ...defaultExtensions]\n : defaultExtensions;\n const extensions =\n (isInternal ? internalExtensionMap : externalExtensionMap)[originalExt] || defaultExtensionsWithSuffixes;\n const pathsToAdd = [originalPath];\n\n if (isInternal && originalPath.startsWith('./lib')) {\n pathsToAdd.unshift(originalPath.replace(/^\\.\\/lib/, './src'));\n }\n\n for (let currentPath of pathsToAdd) {\n const unrecognizedExt = originalExt && !extensions.includes(path.extname(currentPath));\n\n // For internal packages, we try and resolve the original file name first.\n if (isInternal && unrecognizedExt) {\n candidates.push(currentPath);\n }\n\n // If the path doesn't end with a slash, it could be a file. Add extensions.\n if (!endsWithSlash) {\n candidates.push(...expandExtensions(currentPath, extensions));\n }\n\n // For non-extension references, we might be referring to a folder, or a barrel file within a folder. Add the\n // appropriate extensions for the barrel file, and fall back to a package.json in the case of nested definitions.\n if (!originalExt) {\n if (isBlankPath) {\n candidates.push('./package.json');\n } else {\n // Trim trailing slash\n if (endsWithSlash) {\n currentPath = currentPath.slice(0, -1);\n }\n\n candidates.push(...expandExtensions(currentPath + '/index', extensions));\n candidates.push(currentPath + '/package.json');\n }\n }\n\n // For external packages, we try and resolve the original file name last.\n if (!isInternal && unrecognizedExt) {\n candidates.push(currentPath);\n }\n }\n\n return candidates;\n}\n\n/**\n * Given a filepath and list of extensions, maps extensions to prepend the filepath. In the case that\n * the filepath has an extension already in the list, avoids appending the extension twice.\n *\n * For example, filePath = './foo/bar.js' with extensions ['.ts', '.js'] would result in:\n *\n * ['./foo/bar.ts.js', './foo/bar.js'].\n *\n */\nfunction expandExtensions(filePath: string, extensions: string[]) {\n const result: string[] = [];\n const ext = path.extname(filePath);\n\n if (extensions.includes(ext)) {\n filePath = `${filePath.slice(0, -ext.length)}`;\n }\n\n for (const currentExt of extensions) {\n result.push(filePath + currentExt);\n }\n\n return result;\n}\n"]}
1
+ {"version":3,"file":"getCandidates.js","sourceRoot":"","sources":["../src/getCandidates.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,qBAAqB,EAAE,MAAM,mCAAmC,CAAC;AAE1E,OAAO,IAAI,MAAM,MAAM,CAAC;AACxB,OAAO,EAAE,iBAAiB,EAAE,MAAM,wBAAwB,CAAC;AAE3D,yEAAyE;AACzE,MAAM,kBAAkB,GAAG,CAAC,KAAK,EAAE,MAAM,EAAE,MAAM,CAAC,CAAC;AACnD,MAAM,kBAAkB,GA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CAAC,CAAC;IACrC,CAAC;IAED,OAAO,MAAM,CAAC;AAChB,CAAC","sourcesContent":["import { normalizeRelativePath } from '@ms-cloudpack/path-string-parsing';\nimport { type CloudpackConfig } from '@ms-cloudpack/config-types';\nimport path from 'path';\nimport { isExternalPackage } from './isExternalPackage.js';\n\n// Mappings to possible candidate extensions for a given input extension.\nconst externalExtensions = ['.js', '.mjs', '.cjs'];\nconst internalExtensions = ['.ts', '.tsx', '.mts', '.cts', '.jsx', '.js', '.mjs', '.cjs'];\nconst internalExtensionMap: Record<string, string[]> = {\n '.ts': ['.ts', '.js'],\n '.tsx': ['.tsx', '.js'],\n '.mts': ['.mts', '.mjs', '.js'],\n '.cts': ['.cts', '.cjs', '.js'],\n '.jsx': ['.jsx', '.js'],\n '.js': ['.ts', '.tsx', '.mts', '.cts', '.jsx', '.js'],\n '.mjs': ['.mjs', '.js'],\n '.cjs': ['.cjs', '.js'],\n};\nconst externalExtensionMap: Record<string, string[]> = {\n '.ts': ['.js'],\n '.tsx': ['.js'],\n '.mts': ['.mjs'],\n '.cts': ['.cjs'],\n '.jsx': ['.js'],\n '.js': ['.js'],\n};\n\n/**\n * Given a packagePath and a filePath from its exports map (or main/module), build candidate paths\n * to look for the physical file in order of priority. For internal packages, we try to discover\n * source files first, and then fallback to the original file name. We also search for index files\n * and expand folder paths as well for ambiguous references. For external packages, we prioritize\n * intermediate paths.\n */\nexport function getCandidates(\n options: { filePath: string; packagePath: string },\n context: { config: CloudpackConfig },\n) {\n const { filePath, packagePath } = options;\n const resolveWebExtensions = Boolean(context.config.features?.resolveWebExtensions);\n const isBlankPath = !filePath || filePath === '.';\n const originalPath = isBlankPath ? './index' : normalizeRelativePath(filePath);\n const originalExt = path.extname(originalPath);\n const isInternal = !isExternalPackage(packagePath);\n const endsWithSlash = originalPath.endsWith('/');\n const candidates = [];\n const defaultExtensions = isInternal ? internalExtensions : externalExtensions;\n const defaultExtensionsWithSuffixes = resolveWebExtensions\n ? [...defaultExtensions.map((ext) => `.web${ext}`), ...defaultExtensions]\n : defaultExtensions;\n const extensions =\n (isInternal ? internalExtensionMap : externalExtensionMap)[originalExt] || defaultExtensionsWithSuffixes;\n const pathsToAdd = [originalPath];\n\n if (isInternal && originalPath.startsWith('./lib')) {\n pathsToAdd.unshift(originalPath.replace(/^\\.\\/lib/, './src'));\n }\n\n for (let currentPath of pathsToAdd) {\n const unrecognizedExt = originalExt && !extensions.includes(path.extname(currentPath));\n\n // For internal packages, we try and resolve the original file name first.\n if (isInternal && unrecognizedExt) {\n candidates.push(currentPath);\n }\n\n // If the path doesn't end with a slash, it could be a file. Add extensions.\n if (!endsWithSlash) {\n candidates.push(...expandExtensions(currentPath, extensions));\n }\n\n // For non-extension references, we might be referring to a folder, or a barrel file within a folder. Add the\n // appropriate extensions for the barrel file, and fall back to a package.json in the case of nested definitions.\n if (!originalExt) {\n if (isBlankPath) {\n candidates.push('./package.json');\n } else {\n // Trim trailing slash\n if (endsWithSlash) {\n currentPath = currentPath.slice(0, -1);\n }\n\n candidates.push(...expandExtensions(currentPath + '/index', extensions));\n candidates.push(currentPath + '/package.json');\n }\n }\n\n // For external packages, we try and resolve the original file name last.\n if (!isInternal && unrecognizedExt) {\n candidates.push(currentPath);\n }\n }\n\n return candidates;\n}\n\n/**\n * Given a filepath and list of extensions, maps extensions to prepend the filepath. In the case that\n * the filepath has an extension already in the list, avoids appending the extension twice.\n *\n * For example, filePath = './foo/bar.js' with extensions ['.ts', '.js'] would result in:\n *\n * ['./foo/bar.ts.js', './foo/bar.js'].\n *\n */\nfunction expandExtensions(filePath: string, extensions: string[]) {\n const result: string[] = [];\n const ext = path.extname(filePath);\n\n if (extensions.includes(ext)) {\n filePath = `${filePath.slice(0, -ext.length)}`;\n }\n\n for (const currentExt of extensions) {\n result.push(filePath + currentExt);\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": "6.0.0",
3
+ "version": "6.0.2",
4
4
  "description": "Utilities for resolving/parsing packages and their imports.",
5
5
  "license": "MIT",
6
6
  "type": "module",
@@ -14,12 +14,12 @@
14
14
  }
15
15
  },
16
16
  "dependencies": {
17
- "@ms-cloudpack/bundler-types": "^0.25.1",
18
- "@ms-cloudpack/config-types": "^0.6.0",
17
+ "@ms-cloudpack/bundler-types": "^0.25.2",
18
+ "@ms-cloudpack/config-types": "^0.7.0",
19
19
  "@ms-cloudpack/json-utilities": "^0.1.4",
20
- "@ms-cloudpack/package-overrides": "^0.6.23",
21
- "@ms-cloudpack/path-utilities": "^2.6.0",
22
- "@ms-cloudpack/path-string-parsing": "^1.2.0",
20
+ "@ms-cloudpack/package-overrides": "^0.6.24",
21
+ "@ms-cloudpack/path-string-parsing": "^1.2.1",
22
+ "@ms-cloudpack/path-utilities": "^2.6.1",
23
23
  "acorn": "^8.11.2",
24
24
  "acorn-walk": "^8.2.1",
25
25
  "fast-glob": "^3.2.12",