@ms-cloudpack/package-hashes 0.7.31 → 0.7.32
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,9 +1,10 @@
|
|
|
1
1
|
import fsPromises from 'fs/promises';
|
|
2
2
|
import { makeUrl } from '@ms-cloudpack/path-string-parsing';
|
|
3
3
|
export class BundlerCapabilitiesCache {
|
|
4
|
+
bundlerCapabilitiesRegistry;
|
|
5
|
+
_bundlerCapabilitiesFiles = {};
|
|
4
6
|
constructor(bundlerCapabilitiesRegistry) {
|
|
5
7
|
this.bundlerCapabilitiesRegistry = bundlerCapabilitiesRegistry;
|
|
6
|
-
this._bundlerCapabilitiesFiles = {};
|
|
7
8
|
}
|
|
8
9
|
async read(bundlerCapabilityURL) {
|
|
9
10
|
try {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"BundlerCapabilitiesCache.js","sourceRoot":"","sources":["../src/BundlerCapabilitiesCache.ts"],"names":[],"mappings":"AAAA,OAAO,UAAU,MAAM,aAAa,CAAC;AACrC,OAAO,EAAE,OAAO,EAAE,MAAM,mCAAmC,CAAC;AAG5D,MAAM,OAAO,wBAAwB;
|
|
1
|
+
{"version":3,"file":"BundlerCapabilitiesCache.js","sourceRoot":"","sources":["../src/BundlerCapabilitiesCache.ts"],"names":[],"mappings":"AAAA,OAAO,UAAU,MAAM,aAAa,CAAC;AACrC,OAAO,EAAE,OAAO,EAAE,MAAM,mCAAmC,CAAC;AAG5D,MAAM,OAAO,wBAAwB;IAGN;IAFrB,yBAAyB,GAA2B,EAAE,CAAC;IAE/D,YAA6B,2BAAoD;QAApD,gCAA2B,GAA3B,2BAA2B,CAAyB;IAAG,CAAC;IAE7E,KAAK,CAAC,IAAI,CAAC,oBAA4B;QAC7C,IAAI,CAAC;YACH,8CAA8C;YAC9C,OAAO,MAAM,UAAU,CAAC,QAAQ,CAAC,OAAO,CAAC,oBAAoB,CAAC,EAAE,OAAO,CAAC,CAAC;QAC3E,CAAC;QAAC,OAAO,CAAC,EAAE,CAAC;YACX,OAAO,CAAC,IAAI,CAAC,0CAA0C,oBAAoB,MAAM,CAAC,EAAE,CAAC,CAAC;YACtF,OAAO,EAAE,CAAC;QACZ,CAAC;IACH,CAAC;IAEM,KAAK,CAAC,GAAG,CACd,mBAA2D;QAE3D,IAAI,CAAC,mBAAmB,IAAI,CAAC,IAAI,CAAC,2BAA2B,EAAE,CAAC;YAC9D,OAAO,SAAS,CAAC;QACnB,CAAC;QACD,MAAM,MAAM,GAA2B,EAAE,CAAC;QAC1C,2GAA2G;QAC3G,MAAM,IAAI,GAAG,MAAM,CAAC,IAAI,CAAC,mBAAmB,CAAC,CAAC,MAAM,CAClD,CAAC,GAAG,EAAE,EAAE,CAAC,mBAAmB,CAAC,GAAG,CAAC,KAAK,KAAK,IAAI,IAAI,CAAC,2BAA2B,EAAE,CAAC,GAAG,CAAC,CACvF,CAAC;QAEF,KAAK,MAAM,GAAG,IAAI,IAAI,EAAE,CAAC;YACvB,IAAI,IAAI,CAAC,yBAAyB,CAAC,GAAG,CAAC,KAAK,SAAS,EAAE,CAAC;gBACtD,IAAI,CAAC,yBAAyB,CAAC,GAAG,CAAC,GAAG,MAAM,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,2BAA2B,CAAC,GAAG,CAAC,CAAC,CAAC;YAC/F,CAAC;YACD,MAAM,CAAC,GAAG,CAAC,GAAG,IAAI,CAAC,yBAAyB,CAAC,GAAG,CAAC,CAAC;QACpD,CAAC;QAED,OAAO,MAAM,CAAC;IAChB,CAAC;CACF","sourcesContent":["import fsPromises from 'fs/promises';\nimport { makeUrl } from '@ms-cloudpack/path-string-parsing';\nimport type { BundlerCapabilitiesOptions } from '@ms-cloudpack/common-types';\n\nexport class BundlerCapabilitiesCache {\n private _bundlerCapabilitiesFiles: Record<string, string> = {};\n\n constructor(private readonly bundlerCapabilitiesRegistry?: Record<string, string>) {}\n\n private async read(bundlerCapabilityURL: string): Promise<string> {\n try {\n // fs accepts URL objects, but not URL strings\n return await fsPromises.readFile(makeUrl(bundlerCapabilityURL), 'utf-8');\n } catch (e) {\n console.warn(`Error reading bundler capability file \"${bundlerCapabilityURL}\": ${e}`);\n return '';\n }\n }\n\n public async get(\n bundlerCapabilities: BundlerCapabilitiesOptions | undefined,\n ): Promise<Record<string, string> | undefined> {\n if (!bundlerCapabilities || !this.bundlerCapabilitiesRegistry) {\n return undefined;\n }\n const result: Record<string, string> = {};\n // Only include the capabilities that are enabled and have a registry entry (exclude internal capabilities)\n const keys = Object.keys(bundlerCapabilities).filter(\n (key) => bundlerCapabilities[key] !== false && this.bundlerCapabilitiesRegistry?.[key],\n );\n\n for (const key of keys) {\n if (this._bundlerCapabilitiesFiles[key] === undefined) {\n this._bundlerCapabilitiesFiles[key] = await this.read(this.bundlerCapabilitiesRegistry[key]);\n }\n result[key] = this._bundlerCapabilitiesFiles[key];\n }\n\n return result;\n }\n}\n"]}
|
package/lib/PackageHashes.js
CHANGED
|
@@ -5,18 +5,20 @@ import { BundlerCapabilitiesCache } from './BundlerCapabilitiesCache.js';
|
|
|
5
5
|
* Utility class for hashing packages and caching the results.
|
|
6
6
|
*/
|
|
7
7
|
export class PackageHashes {
|
|
8
|
+
options;
|
|
9
|
+
/** Mapping from package path to hash (considering source files) */
|
|
10
|
+
_hashesWithSource = {
|
|
11
|
+
browser: new Map(),
|
|
12
|
+
node: new Map(),
|
|
13
|
+
};
|
|
14
|
+
/** Mapping from package path to hash (not considering source files) */
|
|
15
|
+
_hashesWithNoSource = {
|
|
16
|
+
browser: new Map(),
|
|
17
|
+
node: new Map(),
|
|
18
|
+
};
|
|
19
|
+
_hash;
|
|
8
20
|
constructor(options) {
|
|
9
21
|
this.options = options;
|
|
10
|
-
/** Mapping from package path to hash (considering source files) */
|
|
11
|
-
this._hashesWithSource = {
|
|
12
|
-
browser: new Map(),
|
|
13
|
-
node: new Map(),
|
|
14
|
-
};
|
|
15
|
-
/** Mapping from package path to hash (not considering source files) */
|
|
16
|
-
this._hashesWithNoSource = {
|
|
17
|
-
browser: new Map(),
|
|
18
|
-
node: new Map(),
|
|
19
|
-
};
|
|
20
22
|
if ('hash' in options) {
|
|
21
23
|
this._hash = options.hash;
|
|
22
24
|
return;
|
package/lib/PackageHashes.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"PackageHashes.js","sourceRoot":"","sources":["../src/PackageHashes.ts"],"names":[],"mappings":"AAQA,OAAO,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAE/C,OAAO,EAAE,mBAAmB,EAAE,MAAM,0BAA0B,CAAC;AAC/D,OAAO,EAAE,wBAAwB,EAAE,MAAM,+BAA+B,CAAC;AA2BzE;;GAEG;AACH,MAAM,OAAO,aAAa;
|
|
1
|
+
{"version":3,"file":"PackageHashes.js","sourceRoot":"","sources":["../src/PackageHashes.ts"],"names":[],"mappings":"AAQA,OAAO,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAE/C,OAAO,EAAE,mBAAmB,EAAE,MAAM,0BAA0B,CAAC;AAC/D,OAAO,EAAE,wBAAwB,EAAE,MAAM,+BAA+B,CAAC;AA2BzE;;GAEG;AACH,MAAM,OAAO,aAAa;IAaH;IAZrB,mEAAmE;IAClD,iBAAiB,GAAG;QACnC,OAAO,EAAE,IAAI,GAAG,EAAkB;QAClC,IAAI,EAAE,IAAI,GAAG,EAAkB;KAChC,CAAC;IACF,uEAAuE;IACtD,mBAAmB,GAAG;QACrC,OAAO,EAAE,IAAI,GAAG,EAAkB;QAClC,IAAI,EAAE,IAAI,GAAG,EAAkB;KAChC,CAAC;IACe,KAAK,CAAe;IAErC,YAAqB,OAA6B;QAA7B,YAAO,GAAP,OAAO,CAAsB;QAChD,IAAI,MAAM,IAAI,OAAO,EAAE,CAAC;YACtB,IAAI,CAAC,KAAK,GAAG,OAAO,CAAC,IAAI,CAAC;YAC1B,OAAO;QACT,CAAC;QAED,MAAM,EAAE,MAAM,EAAE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,CAAC,IAAI,CAAC;aACtD;YACD,kBAAkB,EAAE;gBAClB,OAAO,EAAE,MAAM,CAAC,WAAW,CAAC,IAAI,CAAC,mBAAmB,CAAC,OAAO,CAAC;gBAC7D,IAAI,EAAE,MAAM,CAAC,WAAW,CAAC,IAAI,CAAC,mBAAmB,CAAC,IAAI,CAAC;aACxD;SACF,CAAC;IACJ,CAAC;CACF","sourcesContent":["import type {\n CloudpackConfig,\n PackageDefinitionsCache,\n PackageHashOptions,\n PackageHashesCache,\n ResolveMap,\n SerializablePackageHashesCache,\n} from '@ms-cloudpack/common-types';\nimport { hashPackage } from './hashPackage.js';\nimport type { HashFunction } from './types/HashFunction.js';\nimport { PackagePatchesCache } from './PackagePatchesCache.js';\nimport { BundlerCapabilitiesCache } from './BundlerCapabilitiesCache.js';\n\n/**\n * Constructor options for the PackageHashes class.\n *\n * (For `PackageHashes.get` options, see `PackageHashOptions`.)\n */\ntype PackageHashesOptions =\n | {\n /** Working directory used to find the project root (usually repository root). */\n cwd: string;\n /**\n * Context for the hash calculations.\n */\n context: {\n config: Pick<CloudpackConfig, 'patchFilesGlobPattern' | 'bundlerCapabilitiesRegistry'>;\n packages: PackageDefinitionsCache;\n resolveMap: ResolveMap;\n };\n }\n | {\n /**\n * A function that returns the hash for a given package path. This is intended for testing purposes.\n */\n hash: HashFunction;\n };\n\n/**\n * Utility class for hashing packages and caching the results.\n */\nexport class PackageHashes implements PackageHashesCache {\n /** Mapping from package path to hash (considering source files) */\n private readonly _hashesWithSource = {\n browser: new Map<string, string>(),\n node: new Map<string, string>(),\n };\n /** Mapping from package path to hash (not considering source files) */\n private readonly _hashesWithNoSource = {\n browser: new Map<string, string>(),\n node: new Map<string, string>(),\n };\n private readonly _hash: HashFunction;\n\n constructor(readonly options: PackageHashesOptions) {\n if ('hash' in options) {\n this._hash = options.hash;\n return;\n }\n\n const { config } = options.context;\n const patches = new PackagePatchesCache({\n cwd: options.cwd,\n globPattern: config.patchFilesGlobPattern,\n });\n const bundlerCapabilitiesCache = new BundlerCapabilitiesCache(config.bundlerCapabilitiesRegistry);\n\n this._hash = (input) =>\n hashPackage({\n input,\n context: {\n ...options.context,\n patches,\n bundlerCapabilitiesCache,\n },\n });\n }\n\n async get(input: PackageHashOptions): Promise<string> {\n const { packagePath, isSourceHashingEnabled, shouldRecalculate, targetEnvironment } = input;\n\n const map = (isSourceHashingEnabled ? this._hashesWithSource : this._hashesWithNoSource)[targetEnvironment];\n\n if (!shouldRecalculate && map.has(packagePath)) {\n return map.get(packagePath) as string;\n }\n\n const hash = await this._hash(input);\n\n map.set(packagePath, hash);\n\n return hash;\n }\n\n /**\n * Creates a serializable representation of the cache.\n */\n toSerializable(): SerializablePackageHashesCache {\n return {\n hashesWithSource: {\n browser: Object.fromEntries(this._hashesWithSource.browser),\n node: Object.fromEntries(this._hashesWithSource.node),\n },\n hashesWithNoSource: {\n browser: Object.fromEntries(this._hashesWithNoSource.browser),\n node: Object.fromEntries(this._hashesWithNoSource.node),\n },\n };\n }\n}\n"]}
|
|
@@ -9,6 +9,13 @@ import { parsePatchFilePath } from './parsePatchFilePath.js';
|
|
|
9
9
|
* path and contents for a given package name and version.
|
|
10
10
|
*/
|
|
11
11
|
export class PackagePatchesCache {
|
|
12
|
+
settings;
|
|
13
|
+
/**
|
|
14
|
+
* Mapping from `${packageName}@${version}` to patch file path and contents.
|
|
15
|
+
* The paths are saved on an initial pass, but the contents are only saved on first read
|
|
16
|
+
* (in case of very large patch files which are never used).
|
|
17
|
+
*/
|
|
18
|
+
_patches;
|
|
12
19
|
constructor(settings) {
|
|
13
20
|
this.settings = settings;
|
|
14
21
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"PackagePatchesCache.js","sourceRoot":"","sources":["../src/PackagePatchesCache.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,8BAA8B,CAAC;AAC/D,OAAO,UAAU,MAAM,aAAa,CAAC;AACrC,OAAO,IAAI,MAAM,WAA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AC,WAAW,EAAE,OAAO,CAAC,CAAC,CAAC;QAErE,IAAI,SAAS,EAAE,CAAC;YACd,+BAA+B;YAC/B,SAAS,CAAC,QAAQ,KAAK,MAAM,IAAI,CAAC,aAAa,CAAC,SAAS,CAAC,IAAI,CAAC,CAAC;YAChE,OAAO,SAAS,CAAC;QACnB,CAAC;QAED,OAAO,SAAS,CAAC;IACnB,CAAC;CACF","sourcesContent":["import { findProjectRoot } from '@ms-cloudpack/path-utilities';\nimport fsPromises from 'fs/promises';\nimport glob from 'fast-glob';\nimport path from 'path';\nimport { parsePatchFilePath } from './parsePatchFilePath.js';\n\nexport interface PackagePatchesSettings {\n /** Working directory, used to determine the project root where patches are stored. */\n cwd: string;\n\n /** Custom glob pattern for patch files (from `AppConfig.patchFilesGlobPattern`). */\n globPattern?: string;\n\n /** Patches to use instead of reading from disk (for testing). */\n patches?: Record<`${string}@${string}`, PackagePatch>;\n}\n\ninterface PackagePatch {\n path: string;\n contents?: string;\n}\n\n/**\n * PackagePatchesCache manages a cache of information about patch files, which are usually stored in the\n * `patches` folder at the root of the repo. It provides a method to retrieve the patch file\n * path and contents for a given package name and version.\n */\nexport class PackagePatchesCache {\n /**\n * Mapping from `${packageName}@${version}` to patch file path and contents.\n * The paths are saved on an initial pass, but the contents are only saved on first read\n * (in case of very large patch files which are never used).\n */\n private _patches: Record<`${string}@${string}`, PackagePatch> | undefined;\n\n constructor(private readonly settings: PackagePatchesSettings) {}\n\n private getKey(packageName: string, version: string): `${string}@${string}` {\n return `${packageName}@${version}`;\n }\n\n /**\n * Loads the list of patched packages from the `patches` folder.\n */\n private async loadPatchedPackages(): Promise<void> {\n if (this.settings.patches) {\n this._patches = this.settings.patches;\n return;\n }\n\n this._patches = {};\n\n // get the repo root\n const rootPath = findProjectRoot(this.settings.cwd) || this.settings.cwd;\n\n if (!rootPath) {\n console.info('Could not find the root of the repo. Skipping loading patched packages.');\n return;\n }\n\n // get the files with .patch extension\n const patchFiles = await glob(this.settings.globPattern || 'patches/*.patch', {\n cwd: rootPath,\n absolute: true,\n });\n\n for (const absoluteFilePath of patchFiles) {\n try {\n const normalizedPath = path.normalize(absoluteFilePath);\n\n const { packageName, version } = parsePatchFilePath(normalizedPath);\n\n console.debug(`Found patch file for package: ${packageName}@${version}`);\n\n this._patches[this.getKey(packageName, version)] = { path: normalizedPath };\n } catch (e) {\n console.warn(`Invalid patch file \"${absoluteFilePath}\": ${e}`);\n }\n }\n }\n\n private async readPatchFile(patchFilePath: string): Promise<string> {\n try {\n return await fsPromises.readFile(patchFilePath, 'utf-8');\n } catch (e) {\n console.warn(`Error reading patch file \"${patchFilePath}\": ${e}`);\n return '';\n }\n }\n\n /**\n * Gets info about the patch file for the specified package.\n * @param packageName - The name of the package to check.\n * @param version - The version of the package to check.\n * @returns Patch file path and contents if the package has been patched, undefined otherwise.\n */\n public async getPackagePatch(packageName: string, version: string): Promise<PackagePatch | undefined> {\n if (!this._patches) {\n await this.loadPatchedPackages();\n }\n\n const patchInfo = this._patches?.[this.getKey(packageName, version)];\n\n if (patchInfo) {\n // The contents are lazy loaded\n patchInfo.contents ??= await this.readPatchFile(patchInfo.path);\n return patchInfo;\n }\n\n return undefined;\n }\n}\n"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ms-cloudpack/package-hashes",
|
|
3
|
-
"version": "0.7.
|
|
3
|
+
"version": "0.7.32",
|
|
4
4
|
"description": "Utilities for hashing packages.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"type": "module",
|
|
@@ -15,8 +15,8 @@
|
|
|
15
15
|
},
|
|
16
16
|
"dependencies": {
|
|
17
17
|
"@ms-cloudpack/common-types": "^0.24.10",
|
|
18
|
-
"@ms-cloudpack/config": "^0.33.
|
|
19
|
-
"@ms-cloudpack/package-utilities": "^12.0.
|
|
18
|
+
"@ms-cloudpack/config": "^0.33.20",
|
|
19
|
+
"@ms-cloudpack/package-utilities": "^12.0.1",
|
|
20
20
|
"@ms-cloudpack/path-string-parsing": "^1.2.6",
|
|
21
21
|
"@ms-cloudpack/path-utilities": "^3.0.7",
|
|
22
22
|
"fast-glob": "^3.2.12",
|