@ms-cloudpack/package-utilities
Advanced tools
Comparing version 11.3.6 to 12.0.0
@@ -38,2 +38,6 @@ import type { CloudpackConfig, PackageDefinitionsCache, GeneratedExports } from '@ms-cloudpack/common-types'; | ||
environmentCondition?: 'browser' | 'node'; | ||
/** | ||
* Whether to resolve web extensions (e.g. `.web.js`). | ||
*/ | ||
resolveWebExtensions: boolean; | ||
} | ||
@@ -40,0 +44,0 @@ /** |
@@ -12,3 +12,3 @@ import { normalizeRelativePath } from '@ms-cloudpack/path-string-parsing'; | ||
export async function addExportsMapEntry(options, context) { | ||
const { exports, packagePath } = options; | ||
const { exports, packagePath, resolveWebExtensions } = options; | ||
// We try to enforce these conditions in the types, but also do an explicit check in case of | ||
@@ -22,2 +22,3 @@ // casting or other unexpected input. | ||
filePath: options.filePath || options.importPath || '', | ||
resolveWebExtensions, | ||
}, context); | ||
@@ -24,0 +25,0 @@ return _addEntry(options, foundFile); |
@@ -10,2 +10,3 @@ import type { CloudpackConfig, PackageDefinitionsCache, PackageJsonExports } from '@ms-cloudpack/common-types'; | ||
disableTransforms?: boolean; | ||
resolveWebExtensions: boolean; | ||
}, context: { | ||
@@ -12,0 +13,0 @@ packages: PackageDefinitionsCache; |
@@ -9,3 +9,3 @@ import { normalizeRelativePath } from '@ms-cloudpack/path-string-parsing'; | ||
export async function createExportsMap(options, context) { | ||
const { packagePath } = options; | ||
const { packagePath, resolveWebExtensions } = options; | ||
const { packages } = context; | ||
@@ -28,2 +28,3 @@ const definition = await packages.get(packagePath, { disableTransforms: options.disableTransforms }); | ||
requestCondition: type === 'module' ? 'import' : undefined, | ||
resolveWebExtensions, | ||
}, context); | ||
@@ -37,2 +38,3 @@ } | ||
requestCondition: type === 'module' ? 'import' : undefined, | ||
resolveWebExtensions, | ||
}, context); | ||
@@ -46,2 +48,3 @@ } | ||
requestCondition: 'import', | ||
resolveWebExtensions, | ||
}, context); | ||
@@ -51,3 +54,3 @@ } | ||
if (typeof definition.browser === 'string') { | ||
await addExportsMapEntry({ exports, packagePath, filePath: definition.browser, environmentCondition: 'browser' }, context); | ||
await addExportsMapEntry({ exports, packagePath, filePath: definition.browser, environmentCondition: 'browser', resolveWebExtensions }, context); | ||
} | ||
@@ -76,2 +79,3 @@ else if (typeof definition.browser === 'object') { | ||
requestCondition: isDefaultModule || (isDefaultMain && type === 'module') ? 'import' : undefined, | ||
resolveWebExtensions, | ||
}, context); | ||
@@ -86,5 +90,5 @@ } | ||
if (Object.keys(exports).length === 0) { | ||
(await addExportsMapEntry({ exports, packagePath, filePath: './lib/index.js' }, context)) || | ||
(await addExportsMapEntry({ exports, packagePath, filePath: './lib/main.js' }, context)) || | ||
(await addExportsMapEntry({ exports, packagePath, filePath: './index.js' }, context)); | ||
(await addExportsMapEntry({ exports, packagePath, filePath: './lib/index.js', resolveWebExtensions }, context)) || | ||
(await addExportsMapEntry({ exports, packagePath, filePath: './lib/main.js', resolveWebExtensions }, context)) || | ||
(await addExportsMapEntry({ exports, packagePath, filePath: './index.js', resolveWebExtensions }, context)); | ||
} | ||
@@ -91,0 +95,0 @@ return exports; |
@@ -12,3 +12,4 @@ import type { CloudpackConfig, PackageDefinitionsCache, PackageJsonExports } from '@ms-cloudpack/common-types'; | ||
packagePath: string; | ||
disableTransforms?: boolean; | ||
disableTransforms: boolean; | ||
resolveWebExtensions: boolean; | ||
}, context: { | ||
@@ -18,2 +19,8 @@ packages: PackageDefinitionsCache; | ||
}): Promise<PackageJsonExports>; | ||
export declare function getExportsMap(options: { | ||
packagePath: string; | ||
}, context: { | ||
packages: PackageDefinitionsCache; | ||
config: Pick<CloudpackConfig, 'features'>; | ||
}): Promise<PackageJsonExports>; | ||
//# sourceMappingURL=getExportsMap.d.ts.map |
import { createExportsMap } from './createExportsMap.js'; | ||
/** | ||
* Get a package's provided exports map, or create one based on other entry info and the | ||
* package structure as a fallback. | ||
* | ||
* NOTE: Unless `disableTransforms` is true, this will use the cached exports map that was created | ||
* by `createPackageSettingsTransform`. (Exception is tests within `package-utilities` or other | ||
* contexts that didn't use `createPackageDefinitions`.) | ||
*/ | ||
// Implementation | ||
export async function getExportsMap(options, context) { | ||
const { packagePath } = options; | ||
const { packagePath, disableTransforms } = options; | ||
const { packages } = context; | ||
const definition = await packages.get(packagePath, options); | ||
if (disableTransforms !== undefined && options.resolveWebExtensions === undefined) { | ||
// When disableTransforms is defined, we need to know if we should resolve web extensions. | ||
throw new Error('resolveWebExtensions is required when disableTransforms is true (this is a Cloudpack bug).'); | ||
} | ||
if (definition.exports !== undefined) { | ||
return definition.exports; | ||
} | ||
return createExportsMap(options, context); | ||
return createExportsMap({ | ||
...options, | ||
resolveWebExtensions: options.resolveWebExtensions ?? | ||
definition.cloudpack?.bundlerCapabilities?.['resolve-web-extensions'] ?? | ||
// eslint-disable-next-line etc/no-deprecated | ||
Boolean(context.config.features?.resolveWebExtensions), | ||
}, context); | ||
} | ||
//# sourceMappingURL=getExportsMap.js.map |
@@ -5,2 +5,3 @@ import type { CloudpackConfig, PackageDefinitionsCache } from '@ms-cloudpack/common-types'; | ||
filePath: string; | ||
resolveWebExtensions: boolean; | ||
}; | ||
@@ -7,0 +8,0 @@ export type FindFileInPackageResult = { |
@@ -20,2 +20,3 @@ import { normalizeRelativePath, slash } from '@ms-cloudpack/path-string-parsing'; | ||
export async function findFileInPackage(options, context) { | ||
const { resolveWebExtensions } = options; | ||
const originalPath = normalizeRelativePath(options.filePath); | ||
@@ -39,3 +40,3 @@ const packagePath = slash(options.packagePath); | ||
for (const currentPath of pathsToConsider) { | ||
const candidates = await getCandidates({ filePath: currentPath, packagePath }, context); | ||
const candidates = await getCandidates({ filePath: currentPath, packagePath, resolveWebExtensions }, context); | ||
// Try and resolve a physical file given the candidates. | ||
@@ -57,2 +58,3 @@ filePath = candidates.find((candidate) => isFileSync(path.join(packagePath, candidate))); | ||
filePath: normalizeRelativePath(path.relative(packagePath, path.join(nestedDefinitionPath, entryPath))), | ||
resolveWebExtensions: options.resolveWebExtensions, | ||
}, context); | ||
@@ -59,0 +61,0 @@ } |
@@ -1,2 +0,2 @@ | ||
import { type CloudpackConfig, type PackageDefinitionsCache } from '@ms-cloudpack/common-types'; | ||
import { type PackageDefinitionsCache } from '@ms-cloudpack/common-types'; | ||
/** | ||
@@ -12,6 +12,6 @@ * Given a packagePath and a filePath from its exports map (or main/module), build candidate paths | ||
packagePath: string; | ||
resolveWebExtensions: boolean; | ||
}, context: { | ||
config: Pick<CloudpackConfig, 'features'>; | ||
packages: PackageDefinitionsCache; | ||
}): Promise<string[]>; | ||
//# sourceMappingURL=getCandidates.d.ts.map |
@@ -35,4 +35,3 @@ import { normalizeRelativePath } from '@ms-cloudpack/path-string-parsing'; | ||
const outputPaths = await findPackageOutputPaths(options.packagePath, context); | ||
const { filePath, packagePath } = options; | ||
const resolveWebExtensions = Boolean(context.config.features?.resolveWebExtensions); | ||
const { filePath, packagePath, resolveWebExtensions } = options; | ||
const isBlankPath = !filePath || filePath === '.'; | ||
@@ -39,0 +38,0 @@ const originalPath = isBlankPath ? './index' : normalizeRelativePath(filePath); |
{ | ||
"name": "@ms-cloudpack/package-utilities", | ||
"version": "11.3.6", | ||
"version": "12.0.0", | ||
"description": "Utilities for resolving/parsing packages and their imports.", | ||
@@ -17,6 +17,6 @@ "license": "MIT", | ||
"dependencies": { | ||
"@ms-cloudpack/common-types": "^0.24.9", | ||
"@ms-cloudpack/common-types": "^0.24.10", | ||
"@ms-cloudpack/json-utilities": "^0.1.10", | ||
"@ms-cloudpack/path-string-parsing": "^1.2.6", | ||
"@ms-cloudpack/path-utilities": "^3.0.6", | ||
"@ms-cloudpack/path-utilities": "^3.0.7", | ||
"@ms-cloudpack/task-reporter": "^0.15.1", | ||
@@ -23,0 +23,0 @@ "acorn": "^8.11.2", |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
321044
2625