@ms-cloudpack/package-hashes 0.7.13 → 0.7.14
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.
- package/lib/BundlerCapabilitiesCache.d.ts +9 -0
- package/lib/BundlerCapabilitiesCache.d.ts.map +1 -0
- package/lib/BundlerCapabilitiesCache.js +34 -0
- package/lib/BundlerCapabilitiesCache.js.map +1 -0
- package/lib/PackageHashes.d.ts +1 -1
- package/lib/PackageHashes.d.ts.map +1 -1
- package/lib/PackageHashes.js +3 -0
- package/lib/PackageHashes.js.map +1 -1
- package/lib/getPackageHashEntries.d.ts +4 -0
- package/lib/getPackageHashEntries.d.ts.map +1 -1
- package/lib/getPackageHashEntries.js +7 -2
- package/lib/getPackageHashEntries.js.map +1 -1
- package/lib/hashPackage.d.ts +2 -0
- package/lib/hashPackage.d.ts.map +1 -1
- package/lib/hashPackage.js +2 -2
- package/lib/hashPackage.js.map +1 -1
- package/package.json +2 -1
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { BundlerCapabilitiesOptions } from '@ms-cloudpack/common-types';
|
|
2
|
+
export declare class BundlerCapabilitiesCache {
|
|
3
|
+
private readonly bundlerCapabilitiesRegistry?;
|
|
4
|
+
private _bundlerCapabilitiesFiles;
|
|
5
|
+
constructor(bundlerCapabilitiesRegistry?: Record<string, string> | undefined);
|
|
6
|
+
private read;
|
|
7
|
+
get(bundlerCapabilities: BundlerCapabilitiesOptions | undefined): Promise<Record<string, string> | undefined>;
|
|
8
|
+
}
|
|
9
|
+
//# sourceMappingURL=BundlerCapabilitiesCache.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"BundlerCapabilitiesCache.d.ts","sourceRoot":"","sources":["../src/BundlerCapabilitiesCache.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,0BAA0B,EAAE,MAAM,4BAA4B,CAAC;AAE7E,qBAAa,wBAAwB;IAGvB,OAAO,CAAC,QAAQ,CAAC,2BAA2B,CAAC;IAFzD,OAAO,CAAC,yBAAyB,CAA8B;gBAElC,2BAA2B,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,YAAA;YAEnE,IAAI;IAUL,GAAG,CACd,mBAAmB,EAAE,0BAA0B,GAAG,SAAS,GAC1D,OAAO,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,GAAG,SAAS,CAAC;CAmB/C"}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import fsPromises from 'fs/promises';
|
|
2
|
+
import { makeUrl } from '@ms-cloudpack/path-string-parsing';
|
|
3
|
+
export class BundlerCapabilitiesCache {
|
|
4
|
+
constructor(bundlerCapabilitiesRegistry) {
|
|
5
|
+
this.bundlerCapabilitiesRegistry = bundlerCapabilitiesRegistry;
|
|
6
|
+
this._bundlerCapabilitiesFiles = {};
|
|
7
|
+
}
|
|
8
|
+
async read(bundlerCapabilityURL) {
|
|
9
|
+
try {
|
|
10
|
+
// fs accepts URL objects, but not URL strings
|
|
11
|
+
return await fsPromises.readFile(makeUrl(bundlerCapabilityURL), 'utf-8');
|
|
12
|
+
}
|
|
13
|
+
catch (e) {
|
|
14
|
+
console.warn(`Error reading bundler capability file "${bundlerCapabilityURL}": ${e}`);
|
|
15
|
+
return '';
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
async get(bundlerCapabilities) {
|
|
19
|
+
if (!bundlerCapabilities || !this.bundlerCapabilitiesRegistry) {
|
|
20
|
+
return undefined;
|
|
21
|
+
}
|
|
22
|
+
const result = {};
|
|
23
|
+
// Only include the capabilities that are enabled and have a registry entry (exclude internal capabilities)
|
|
24
|
+
const keys = Object.keys(bundlerCapabilities).filter((key) => bundlerCapabilities[key] !== false && this.bundlerCapabilitiesRegistry?.[key]);
|
|
25
|
+
for (const key of keys) {
|
|
26
|
+
if (this._bundlerCapabilitiesFiles[key] === undefined) {
|
|
27
|
+
this._bundlerCapabilitiesFiles[key] = await this.read(this.bundlerCapabilitiesRegistry[key]);
|
|
28
|
+
}
|
|
29
|
+
result[key] = this._bundlerCapabilitiesFiles[key];
|
|
30
|
+
}
|
|
31
|
+
return result;
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
//# sourceMappingURL=BundlerCapabilitiesCache.js.map
|
|
@@ -0,0 +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;IAGnC,YAA6B,2BAAoD;QAApD,gCAA2B,GAA3B,2BAA2B,CAAyB;QAFzE,8BAAyB,GAA2B,EAAE,CAAC;IAEqB,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.d.ts
CHANGED
|
@@ -12,7 +12,7 @@ type PackageHashesOptions = {
|
|
|
12
12
|
* Context for the hash calculations.
|
|
13
13
|
*/
|
|
14
14
|
context: {
|
|
15
|
-
config: Pick<CloudpackConfig, 'patchFilesGlobPattern'>;
|
|
15
|
+
config: Pick<CloudpackConfig, 'patchFilesGlobPattern' | 'bundlerCapabilitiesRegistry'>;
|
|
16
16
|
packages: PackageDefinitionsCache;
|
|
17
17
|
resolveMap: ResolveMap;
|
|
18
18
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"PackageHashes.d.ts","sourceRoot":"","sources":["../src/PackageHashes.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,eAAe,EACf,uBAAuB,EACvB,kBAAkB,EAClB,kBAAkB,EAClB,UAAU,EACX,MAAM,4BAA4B,CAAC;AAEpC,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,yBAAyB,CAAC;
|
|
1
|
+
{"version":3,"file":"PackageHashes.d.ts","sourceRoot":"","sources":["../src/PackageHashes.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,eAAe,EACf,uBAAuB,EACvB,kBAAkB,EAClB,kBAAkB,EAClB,UAAU,EACX,MAAM,4BAA4B,CAAC;AAEpC,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,yBAAyB,CAAC;AAI5D;;;;GAIG;AACH,KAAK,oBAAoB,GACrB;IACE,iFAAiF;IACjF,GAAG,EAAE,MAAM,CAAC;IACZ;;OAEG;IACH,OAAO,EAAE;QACP,MAAM,EAAE,IAAI,CAAC,eAAe,EAAE,uBAAuB,GAAG,6BAA6B,CAAC,CAAC;QACvF,QAAQ,EAAE,uBAAuB,CAAC;QAClC,UAAU,EAAE,UAAU,CAAC;KACxB,CAAC;CACH,GACD;IACE;;OAEG;IACH,IAAI,EAAE,YAAY,CAAC;CACpB,CAAC;AAEN;;GAEG;AACH,qBAAa,aAAc,YAAW,kBAAkB;IAO1C,QAAQ,CAAC,OAAO,EAAE,oBAAoB;IANlD,mEAAmE;IACnE,OAAO,CAAC,QAAQ,CAAC,iBAAiB,CAA6B;IAC/D,uEAAuE;IACvE,OAAO,CAAC,QAAQ,CAAC,mBAAmB,CAA6B;IACjE,OAAO,CAAC,QAAQ,CAAC,KAAK,CAAe;gBAEhB,OAAO,EAAE,oBAAoB;IAwB5C,GAAG,CAAC,KAAK,EAAE,kBAAkB,GAAG,OAAO,CAAC,MAAM,CAAC;CAetD"}
|
package/lib/PackageHashes.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { hashPackage } from './hashPackage.js';
|
|
2
2
|
import { PackagePatchesCache } from './PackagePatchesCache.js';
|
|
3
|
+
import { BundlerCapabilitiesCache } from './BundlerCapabilitiesCache.js';
|
|
3
4
|
/**
|
|
4
5
|
* Utility class for hashing packages and caching the results.
|
|
5
6
|
*/
|
|
@@ -19,11 +20,13 @@ export class PackageHashes {
|
|
|
19
20
|
cwd: options.cwd,
|
|
20
21
|
globPattern: config.patchFilesGlobPattern,
|
|
21
22
|
});
|
|
23
|
+
const bundlerCapabilitiesCache = new BundlerCapabilitiesCache(config.bundlerCapabilitiesRegistry);
|
|
22
24
|
this._hash = (input) => hashPackage({
|
|
23
25
|
input,
|
|
24
26
|
context: {
|
|
25
27
|
...options.context,
|
|
26
28
|
patches,
|
|
29
|
+
bundlerCapabilitiesCache,
|
|
27
30
|
},
|
|
28
31
|
});
|
|
29
32
|
}
|
package/lib/PackageHashes.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"PackageHashes.js","sourceRoot":"","sources":["../src/PackageHashes.ts"],"names":[],"mappings":"AAOA,OAAO,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAE/C,OAAO,EAAE,mBAAmB,EAAE,MAAM,0BAA0B,CAAC;
|
|
1
|
+
{"version":3,"file":"PackageHashes.js","sourceRoot":"","sources":["../src/PackageHashes.ts"],"names":[],"mappings":"AAOA,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;IAOxB,YAAqB,OAA6B;QAA7B,YAAO,GAAP,OAAO,CAAsB;QANlD,mEAAmE;QAClD,sBAAiB,GAAG,IAAI,GAAG,EAAkB,CAAC;QAC/D,uEAAuE;QACtD,wBAAmB,GAAG,IAAI,GAAG,EAAkB,CAAC;QAI/D,IAAI,MAAM,IAAI,OAAO,EAAE,CAAC;YACtB,IAAI,CAAC,KAAK,GAAG,OAAO,CAAC,IAAI,CAAC;YAC1B,OAAO;QACT,CAAC;QAED,MAAM,EAAE,MAAM,EAAE,GAAG,OAAO,CAAC,OAAO,CAAC;QACnC,MAAM,OAAO,GAAG,IAAI,mBAAmB,CAAC;YACtC,GAAG,EAAE,OAAO,CAAC,GAAG;YAChB,WAAW,EAAE,MAAM,CAAC,qBAAqB;SAC1C,CAAC,CAAC;QACH,MAAM,wBAAwB,GAAG,IAAI,wBAAwB,CAAC,MAAM,CAAC,2BAA2B,CAAC,CAAC;QAElG,IAAI,CAAC,KAAK,GAAG,CAAC,KAAK,EAAE,EAAE,CACrB,WAAW,CAAC;YACV,KAAK;YACL,OAAO,EAAE;gBACP,GAAG,OAAO,CAAC,OAAO;gBAClB,OAAO;gBACP,wBAAwB;aACzB;SACF,CAAC,CAAC;IACP,CAAC;IAED,KAAK,CAAC,GAAG,CAAC,KAAyB;QACjC,MAAM,EAAE,WAAW,EAAE,sBAAsB,EAAE,iBAAiB,EAAE,GAAG,KAAK,CAAC;QAEzE,MAAM,GAAG,GAAG,sBAAsB,CAAC,CAAC,CAAC,IAAI,CAAC,iBAAiB,CAAC,CAAC,CAAC,IAAI,CAAC,mBAAmB,CAAC;QAEvF,IAAI,CAAC,iBAAiB,IAAI,GAAG,CAAC,GAAG,CAAC,WAAW,CAAC,EAAE,CAAC;YAC/C,OAAO,GAAG,CAAC,GAAG,CAAC,WAAW,CAAW,CAAC;QACxC,CAAC;QAED,MAAM,IAAI,GAAG,MAAM,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC;QAErC,GAAG,CAAC,GAAG,CAAC,WAAW,EAAE,IAAI,CAAC,CAAC;QAE3B,OAAO,IAAI,CAAC;IACd,CAAC;CACF","sourcesContent":["import type {\n CloudpackConfig,\n PackageDefinitionsCache,\n PackageHashOptions,\n PackageHashesCache,\n ResolveMap,\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 = new Map<string, string>();\n /** Mapping from package path to hash (not considering source files) */\n private readonly _hashesWithNoSource = new Map<string, string>();\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 } = input;\n\n const map = isSourceHashingEnabled ? this._hashesWithSource : this._hashesWithNoSource;\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"]}
|
|
@@ -2,6 +2,7 @@ import type { PackageDefinitionsCache, PackageJson, PackageJsonDependencies, Pac
|
|
|
2
2
|
import type { HashFunctionOptions } from './types/HashFunction.js';
|
|
3
3
|
import { type FilesHash } from './getSourceHash.js';
|
|
4
4
|
import type { PackagePatchesCache } from './PackagePatchesCache.js';
|
|
5
|
+
import type { BundlerCapabilitiesCache } from './BundlerCapabilitiesCache.js';
|
|
5
6
|
/**
|
|
6
7
|
* Values used to calculate the hash of a package.
|
|
7
8
|
*/
|
|
@@ -18,6 +19,8 @@ export interface PackageHashEntries {
|
|
|
18
19
|
patchFileContent: string | undefined;
|
|
19
20
|
/** Subset of calculated package settings and other info saved under `PackageJson.cloudpack`. */
|
|
20
21
|
packageSettings: Partial<NonNullable<PackageJson['cloudpack']>>;
|
|
22
|
+
/** Content of any bundler capabilities files for the package. */
|
|
23
|
+
bundlerCapabilitiesContent?: Record<string, string>;
|
|
21
24
|
}
|
|
22
25
|
/**
|
|
23
26
|
* Get an object that's used to calculate the hash of the package.
|
|
@@ -27,6 +30,7 @@ export declare function getPackageHashEntries(params: {
|
|
|
27
30
|
context: {
|
|
28
31
|
packages: PackageDefinitionsCache;
|
|
29
32
|
patches: PackagePatchesCache;
|
|
33
|
+
bundlerCapabilitiesCache: BundlerCapabilitiesCache;
|
|
30
34
|
};
|
|
31
35
|
}): Promise<PackageHashEntries>;
|
|
32
36
|
//# sourceMappingURL=getPackageHashEntries.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getPackageHashEntries.d.ts","sourceRoot":"","sources":["../src/getPackageHashEntries.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,uBAAuB,EACvB,WAAW,EACX,uBAAuB,EACvB,kBAAkB,EACnB,MAAM,4BAA4B,CAAC;AAEpC,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,yBAAyB,CAAC;AACnE,OAAO,EAAiB,KAAK,SAAS,EAAE,MAAM,oBAAoB,CAAC;AACnE,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,0BAA0B,CAAC;
|
|
1
|
+
{"version":3,"file":"getPackageHashEntries.d.ts","sourceRoot":"","sources":["../src/getPackageHashEntries.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,uBAAuB,EACvB,WAAW,EACX,uBAAuB,EACvB,kBAAkB,EACnB,MAAM,4BAA4B,CAAC;AAEpC,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,yBAAyB,CAAC;AACnE,OAAO,EAAiB,KAAK,SAAS,EAAE,MAAM,oBAAoB,CAAC;AACnE,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,0BAA0B,CAAC;AACpE,OAAO,KAAK,EAAE,wBAAwB,EAAE,MAAM,+BAA+B,CAAC;AAE9E;;GAEG;AACH,MAAM,WAAW,kBAAkB;IACjC,IAAI,EAAE,MAAM,CAAC;IACb,gGAAgG;IAChG,OAAO,EAAE,MAAM,CAAC;IAChB,OAAO,EAAE,kBAAkB,GAAG,SAAS,CAAC;IACxC,YAAY,EAAE,uBAAuB,GAAG,SAAS,CAAC;IAClD,gBAAgB,EAAE,uBAAuB,GAAG,SAAS,CAAC;IACtD,oCAAoC;IACpC,SAAS,EAAE,SAAS,GAAG,SAAS,CAAC;IACjC,oDAAoD;IACpD,gBAAgB,EAAE,MAAM,GAAG,SAAS,CAAC;IACrC,gGAAgG;IAChG,eAAe,EAAE,OAAO,CAAC,WAAW,CAAC,WAAW,CAAC,WAAW,CAAC,CAAC,CAAC,CAAC;IAChE,iEAAiE;IACjE,0BAA0B,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;CACrD;AAED;;GAEG;AACH,wBAAsB,qBAAqB,CAAC,MAAM,EAAE;IAClD,OAAO,EAAE,mBAAmB,CAAC;IAC7B,OAAO,EAAE;QACP,QAAQ,EAAE,uBAAuB,CAAC;QAClC,OAAO,EAAE,mBAAmB,CAAC;QAC7B,wBAAwB,EAAE,wBAAwB,CAAC;KACpD,CAAC;CACH,GAAG,OAAO,CAAC,kBAAkB,CAAC,CA4C9B"}
|
|
@@ -6,7 +6,7 @@ import { getSourceHash } from './getSourceHash.js';
|
|
|
6
6
|
export async function getPackageHashEntries(params) {
|
|
7
7
|
const { options, context } = params;
|
|
8
8
|
const { packagePath, isSourceHashingEnabled } = options;
|
|
9
|
-
const { packages, patches } = context;
|
|
9
|
+
const { packages, patches, bundlerCapabilitiesCache } = context;
|
|
10
10
|
const definition = await packages.get(packagePath);
|
|
11
11
|
const disabledTransformsDefinition = await packages.get(packagePath, { disableTransforms: true });
|
|
12
12
|
const { name, version } = definition;
|
|
@@ -18,7 +18,7 @@ export async function getPackageHashEntries(params) {
|
|
|
18
18
|
: undefined;
|
|
19
19
|
const patchFileContent = isExternal ? (await patches.getPackagePatch(name, version))?.contents : undefined;
|
|
20
20
|
// Only include a subset of package.json properties to reduce the amount hashed.
|
|
21
|
-
|
|
21
|
+
const result = {
|
|
22
22
|
// This will be calculated by createPackageSettingsTransform and incorporates the original
|
|
23
23
|
// exports as well as main and module.
|
|
24
24
|
exports: definition.exports,
|
|
@@ -32,5 +32,10 @@ export async function getPackageHashEntries(params) {
|
|
|
32
32
|
patchFileContent,
|
|
33
33
|
packageSettings,
|
|
34
34
|
};
|
|
35
|
+
const bundlerCapabilitiesContent = await bundlerCapabilitiesCache.get(packageSettings.bundlerCapabilities);
|
|
36
|
+
if (Object.keys(bundlerCapabilitiesContent || {}).length > 0) {
|
|
37
|
+
result.bundlerCapabilitiesContent = bundlerCapabilitiesContent;
|
|
38
|
+
}
|
|
39
|
+
return result;
|
|
35
40
|
}
|
|
36
41
|
//# sourceMappingURL=getPackageHashEntries.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getPackageHashEntries.js","sourceRoot":"","sources":["../src/getPackageHashEntries.ts"],"names":[],"mappings":"AAMA,OAAO,EAAE,iBAAiB,EAAE,MAAM,iCAAiC,CAAC;AAEpE,OAAO,EAAE,aAAa,EAAkB,MAAM,oBAAoB,CAAC;
|
|
1
|
+
{"version":3,"file":"getPackageHashEntries.js","sourceRoot":"","sources":["../src/getPackageHashEntries.ts"],"names":[],"mappings":"AAMA,OAAO,EAAE,iBAAiB,EAAE,MAAM,iCAAiC,CAAC;AAEpE,OAAO,EAAE,aAAa,EAAkB,MAAM,oBAAoB,CAAC;AAwBnE;;GAEG;AACH,MAAM,CAAC,KAAK,UAAU,qBAAqB,CAAC,MAO3C;IACC,MAAM,EAAE,OAAO,EAAE,OAAO,EAAE,GAAG,MAAM,CAAC;IACpC,MAAM,EAAE,WAAW,EAAE,sBAAsB,EAAE,GAAG,OAAO,CAAC;IACxD,MAAM,EAAE,QAAQ,EAAE,OAAO,EAAE,wBAAwB,EAAE,GAAG,OAAO,CAAC;IAEhE,MAAM,UAAU,GAAG,MAAM,QAAQ,CAAC,GAAG,CAAC,WAAW,CAAC,CAAC;IACnD,MAAM,4BAA4B,GAAG,MAAM,QAAQ,CAAC,GAAG,CAAC,WAAW,EAAE,EAAE,iBAAiB,EAAE,IAAI,EAAE,CAAC,CAAC;IAElG,MAAM,EAAE,IAAI,EAAE,OAAO,EAAE,GAAG,UAAU,CAAC;IAErC,4FAA4F;IAC5F,MAAM,eAAe,GAAG,EAAE,GAAG,UAAU,CAAC,SAAS,EAAE,CAAC;IAEpD,MAAM,UAAU,GAAG,iBAAiB,CAAC,WAAW,CAAC,CAAC;IAElD,MAAM,SAAS,GACb,CAAC,UAAU,IAAI,sBAAsB;QACnC,CAAC,CAAC,MAAM,aAAa,CAAC,EAAE,WAAW,EAAE,UAAU,EAAE,eAAe,CAAC,UAAU,EAAE,CAAC;QAC9E,CAAC,CAAC,SAAS,CAAC;IAEhB,MAAM,gBAAgB,GAAG,UAAU,CAAC,CAAC,CAAC,CAAC,MAAM,OAAO,CAAC,eAAe,CAAC,IAAI,EAAE,OAAO,CAAC,CAAC,EAAE,QAAQ,CAAC,CAAC,CAAC,SAAS,CAAC;IAE3G,gFAAgF;IAChF,MAAM,MAAM,GAAuB;QACjC,0FAA0F;QAC1F,sCAAsC;QACtC,OAAO,EAAE,UAAU,CAAC,OAAO;QAC3B,uEAAuE;QACvE,iDAAiD;QACjD,YAAY,EAAE,4BAA4B,CAAC,YAAY;QACvD,gBAAgB,EAAE,4BAA4B,CAAC,gBAAgB;QAC/D,IAAI;QACJ,OAAO,EAAE,UAAU,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,WAAW;QAC3C,SAAS;QACT,gBAAgB;QAChB,eAAe;KAChB,CAAC;IAEF,MAAM,0BAA0B,GAAG,MAAM,wBAAwB,CAAC,GAAG,CAAC,eAAe,CAAC,mBAAmB,CAAC,CAAC;IAC3G,IAAI,MAAM,CAAC,IAAI,CAAC,0BAA0B,IAAI,EAAE,CAAC,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;QAC7D,MAAM,CAAC,0BAA0B,GAAG,0BAA0B,CAAC;IACjE,CAAC;IAED,OAAO,MAAM,CAAC;AAChB,CAAC","sourcesContent":["import type {\n PackageDefinitionsCache,\n PackageJson,\n PackageJsonDependencies,\n PackageJsonExports,\n} from '@ms-cloudpack/common-types';\nimport { isExternalPackage } from '@ms-cloudpack/package-utilities';\nimport type { HashFunctionOptions } from './types/HashFunction.js';\nimport { getSourceHash, type FilesHash } from './getSourceHash.js';\nimport type { PackagePatchesCache } from './PackagePatchesCache.js';\nimport type { BundlerCapabilitiesCache } from './BundlerCapabilitiesCache.js';\n\n/**\n * Values used to calculate the hash of a package.\n */\nexport interface PackageHashEntries {\n name: string;\n /** This will be the actual version if the package is external, or the path if it's internal. */\n version: string;\n exports: PackageJsonExports | undefined;\n dependencies: PackageJsonDependencies | undefined;\n peerDependencies: PackageJsonDependencies | undefined;\n /** Hash of files in the package. */\n filesHash: FilesHash | undefined;\n /** Content of any `.patch` file for the package. */\n patchFileContent: string | undefined;\n /** Subset of calculated package settings and other info saved under `PackageJson.cloudpack`. */\n packageSettings: Partial<NonNullable<PackageJson['cloudpack']>>;\n /** Content of any bundler capabilities files for the package. */\n bundlerCapabilitiesContent?: Record<string, string>;\n}\n\n/**\n * Get an object that's used to calculate the hash of the package.\n */\nexport async function getPackageHashEntries(params: {\n options: HashFunctionOptions;\n context: {\n packages: PackageDefinitionsCache;\n patches: PackagePatchesCache;\n bundlerCapabilitiesCache: BundlerCapabilitiesCache;\n };\n}): Promise<PackageHashEntries> {\n const { options, context } = params;\n const { packagePath, isSourceHashingEnabled } = options;\n const { packages, patches, bundlerCapabilitiesCache } = context;\n\n const definition = await packages.get(packagePath);\n const disabledTransformsDefinition = await packages.get(packagePath, { disableTransforms: true });\n\n const { name, version } = definition;\n\n // This has the cached calculated package settings, with included and excluded deps removed.\n const packageSettings = { ...definition.cloudpack };\n\n const isExternal = isExternalPackage(packagePath);\n\n const filesHash =\n !isExternal && isSourceHashingEnabled\n ? await getSourceHash({ packagePath, inputPaths: packageSettings.inputPaths })\n : undefined;\n\n const patchFileContent = isExternal ? (await patches.getPackagePatch(name, version))?.contents : undefined;\n\n // Only include a subset of package.json properties to reduce the amount hashed.\n const result: PackageHashEntries = {\n // This will be calculated by createPackageSettingsTransform and incorporates the original\n // exports as well as main and module.\n exports: definition.exports,\n // Use the original dependencies to ensure that the hash is consistent,\n // and unaffected by include and exclude changes.\n dependencies: disabledTransformsDefinition.dependencies,\n peerDependencies: disabledTransformsDefinition.peerDependencies,\n name,\n version: isExternal ? version : packagePath,\n filesHash,\n patchFileContent,\n packageSettings,\n };\n\n const bundlerCapabilitiesContent = await bundlerCapabilitiesCache.get(packageSettings.bundlerCapabilities);\n if (Object.keys(bundlerCapabilitiesContent || {}).length > 0) {\n result.bundlerCapabilitiesContent = bundlerCapabilitiesContent;\n }\n\n return result;\n}\n"]}
|
package/lib/hashPackage.d.ts
CHANGED
|
@@ -2,12 +2,14 @@ import type { PackageDefinitionsCache } from '@ms-cloudpack/common-types';
|
|
|
2
2
|
import { type ResolveMap } from '@ms-cloudpack/package-utilities';
|
|
3
3
|
import type { PackagePatchesCache } from './PackagePatchesCache.js';
|
|
4
4
|
import type { HashFunctionOptions } from './types/HashFunction.js';
|
|
5
|
+
import type { BundlerCapabilitiesCache } from './BundlerCapabilitiesCache.js';
|
|
5
6
|
export declare function hashPackage(params: {
|
|
6
7
|
input: HashFunctionOptions;
|
|
7
8
|
context: {
|
|
8
9
|
packages: PackageDefinitionsCache;
|
|
9
10
|
resolveMap: ResolveMap;
|
|
10
11
|
patches: PackagePatchesCache;
|
|
12
|
+
bundlerCapabilitiesCache: BundlerCapabilitiesCache;
|
|
11
13
|
};
|
|
12
14
|
}): Promise<string>;
|
|
13
15
|
//# sourceMappingURL=hashPackage.d.ts.map
|
package/lib/hashPackage.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"hashPackage.d.ts","sourceRoot":"","sources":["../src/hashPackage.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,4BAA4B,CAAC;AAC1E,OAAO,EAAE,KAAK,UAAU,EAAE,MAAM,iCAAiC,CAAC;AAIlE,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,0BAA0B,CAAC;AAEpE,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,yBAAyB,CAAC;
|
|
1
|
+
{"version":3,"file":"hashPackage.d.ts","sourceRoot":"","sources":["../src/hashPackage.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,4BAA4B,CAAC;AAC1E,OAAO,EAAE,KAAK,UAAU,EAAE,MAAM,iCAAiC,CAAC;AAIlE,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,0BAA0B,CAAC;AAEpE,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,yBAAyB,CAAC;AACnE,OAAO,KAAK,EAAE,wBAAwB,EAAE,MAAM,+BAA+B,CAAC;AAI9E,wBAAsB,WAAW,CAAC,MAAM,EAAE;IACxC,KAAK,EAAE,mBAAmB,CAAC;IAC3B,OAAO,EAAE;QACP,QAAQ,EAAE,uBAAuB,CAAC;QAClC,UAAU,EAAE,UAAU,CAAC;QACvB,OAAO,EAAE,mBAAmB,CAAC;QAC7B,wBAAwB,EAAE,wBAAwB,CAAC;KACpD,CAAC;CACH,GAAG,OAAO,CAAC,MAAM,CAAC,CAgDlB"}
|
package/lib/hashPackage.js
CHANGED
|
@@ -7,7 +7,7 @@ export async function hashPackage(params) {
|
|
|
7
7
|
const start = performance.now();
|
|
8
8
|
const { input, context } = params;
|
|
9
9
|
const { packagePath, isSourceHashingEnabled } = input;
|
|
10
|
-
const { resolveMap, packages, patches } = context;
|
|
10
|
+
const { resolveMap, packages, patches, bundlerCapabilitiesCache } = context;
|
|
11
11
|
const hashEntriesArray = [];
|
|
12
12
|
const packagesToHash = [packagePath];
|
|
13
13
|
while (packagesToHash.length > 0) {
|
|
@@ -17,7 +17,7 @@ export async function hashPackage(params) {
|
|
|
17
17
|
}
|
|
18
18
|
const hashEntries = await getPackageHashEntries({
|
|
19
19
|
options: { isSourceHashingEnabled, packagePath: packageToHash },
|
|
20
|
-
context: { packages, patches },
|
|
20
|
+
context: { packages, patches, bundlerCapabilitiesCache },
|
|
21
21
|
});
|
|
22
22
|
hashEntriesArray.push(hashEntries);
|
|
23
23
|
if (hashEntries.packageSettings.inlinedDependencies) {
|
package/lib/hashPackage.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"hashPackage.js","sourceRoot":"","sources":["../src/hashPackage.ts"],"names":[],"mappings":"AAEA,OAAO,UAAU,MAAM,aAAa,CAAC;AACrC,OAAO,EAAE,qBAAqB,
|
|
1
|
+
{"version":3,"file":"hashPackage.js","sourceRoot":"","sources":["../src/hashPackage.ts"],"names":[],"mappings":"AAEA,OAAO,UAAU,MAAM,aAAa,CAAC;AACrC,OAAO,EAAE,qBAAqB,EAA2B,MAAM,4BAA4B,CAAC;AAC5F,OAAO,EAAE,2BAA2B,EAAE,MAAM,kCAAkC,CAAC;AAE/E,OAAO,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAI/C,IAAI,SAAS,GAAG,CAAC,CAAC;AAElB,MAAM,CAAC,KAAK,UAAU,WAAW,CAAC,MAQjC;IACC,MAAM,KAAK,GAAG,WAAW,CAAC,GAAG,EAAE,CAAC;IAChC,MAAM,EAAE,KAAK,EAAE,OAAO,EAAE,GAAG,MAAM,CAAC;IAClC,MAAM,EAAE,WAAW,EAAE,sBAAsB,EAAE,GAAG,KAAK,CAAC;IACtD,MAAM,EAAE,UAAU,EAAE,QAAQ,EAAE,OAAO,EAAE,wBAAwB,EAAE,GAAG,OAAO,CAAC;IAC5E,MAAM,gBAAgB,GAAyB,EAAE,CAAC;IAClD,MAAM,cAAc,GAAa,CAAC,WAAW,CAAC,CAAC;IAE/C,OAAO,cAAc,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;QACjC,MAAM,aAAa,GAAG,cAAc,CAAC,GAAG,EAAE,CAAC;QAC3C,IAAI,CAAC,aAAa,EAAE,CAAC;YACnB,SAAS;QACX,CAAC;QAED,MAAM,WAAW,GAAG,MAAM,qBAAqB,CAAC;YAC9C,OAAO,EAAE,EAAE,sBAAsB,EAAE,WAAW,EAAE,aAAa,EAAE;YAC/D,OAAO,EAAE,EAAE,QAAQ,EAAE,OAAO,EAAE,wBAAwB,EAAE;SACzD,CAAC,CAAC;QAEH,gBAAgB,CAAC,IAAI,CAAC,WAAW,CAAC,CAAC;QAEnC,IAAI,WAAW,CAAC,eAAe,CAAC,mBAAmB,EAAE,CAAC;YACpD,MAAM,wBAAwB,GAAG,2BAA2B,CAAC;gBAC3D,OAAO,EAAE;oBACP,WAAW,EAAE,WAAW,CAAC,IAAI;oBAC7B,UAAU,EAAE,WAAW;oBACvB,mBAAmB,EAAE,WAAW,CAAC,eAAe,CAAC,mBAAmB;iBACrE;gBACD,OAAO,EAAE,EAAE,UAAU,EAAE;aACxB,CAAC,CAAC;YACH,cAAc,CAAC,IAAI,CAAC,GAAG,wBAAwB,CAAC,CAAC;QACnD,CAAC;IACH,CAAC;IAED,MAAM,UAAU,GAAG,UAAU,CAAC,gBAAgB,EAAE;QAC9C,WAAW,EAAE,KAAK;QAClB,eAAe,EAAE,IAAI;QACrB,aAAa,EAAE,IAAI;QACnB,gBAAgB,EAAE,IAAI;QACtB,aAAa,EAAE,IAAI;KACpB,CAAC,CAAC;IAEH,MAAM,EAAE,IAAI,EAAE,OAAO,EAAE,GAAG,gBAAgB,CAAC,CAAC,CAAC,CAAC;IAC9C,MAAM,WAAW,GAAG,WAAW,CAAC,GAAG,EAAE,GAAG,KAAK,CAAC;IAC9C,SAAS,IAAI,WAAW,CAAC;IACzB,OAAO,CAAC,KAAK,CAAC,UAAU,IAAI,IAAI,OAAO,OAAO,WAAW,mBAAmB,SAAS,IAAI,CAAC,CAAC;IAE3F,OAAO,IAAI,WAAW,IAAI,UAAU,EAAE,CAAC;AACzC,CAAC","sourcesContent":["import type { PackageDefinitionsCache } from '@ms-cloudpack/common-types';\nimport { type ResolveMap } from '@ms-cloudpack/package-utilities';\nimport objectHash from 'object-hash';\nimport { getPackageHashEntries, type PackageHashEntries } from './getPackageHashEntries.js';\nimport { getInlinedDependenciesPaths } from './getInlinedDependenciesPaths.js';\nimport type { PackagePatchesCache } from './PackagePatchesCache.js';\nimport { hashVersion } from './hashVersion.js';\nimport type { HashFunctionOptions } from './types/HashFunction.js';\nimport type { BundlerCapabilitiesCache } from './BundlerCapabilitiesCache.js';\n\nlet totalTime = 0;\n\nexport async function hashPackage(params: {\n input: HashFunctionOptions;\n context: {\n packages: PackageDefinitionsCache;\n resolveMap: ResolveMap;\n patches: PackagePatchesCache;\n bundlerCapabilitiesCache: BundlerCapabilitiesCache;\n };\n}): Promise<string> {\n const start = performance.now();\n const { input, context } = params;\n const { packagePath, isSourceHashingEnabled } = input;\n const { resolveMap, packages, patches, bundlerCapabilitiesCache } = context;\n const hashEntriesArray: PackageHashEntries[] = [];\n const packagesToHash: string[] = [packagePath];\n\n while (packagesToHash.length > 0) {\n const packageToHash = packagesToHash.pop();\n if (!packageToHash) {\n continue;\n }\n\n const hashEntries = await getPackageHashEntries({\n options: { isSourceHashingEnabled, packagePath: packageToHash },\n context: { packages, patches, bundlerCapabilitiesCache },\n });\n\n hashEntriesArray.push(hashEntries);\n\n if (hashEntries.packageSettings.inlinedDependencies) {\n const inlinedDependenciesPaths = getInlinedDependenciesPaths({\n options: {\n packageName: hashEntries.name,\n definition: hashEntries,\n inlinedDependencies: hashEntries.packageSettings.inlinedDependencies,\n },\n context: { resolveMap },\n });\n packagesToHash.push(...inlinedDependenciesPaths);\n }\n }\n\n const hashResult = objectHash(hashEntriesArray, {\n respectType: false,\n unorderedArrays: true,\n unorderedSets: true,\n unorderedObjects: true,\n ignoreUnknown: true,\n });\n\n const { name, version } = hashEntriesArray[0];\n const elapsedTime = performance.now() - start;\n totalTime += elapsedTime;\n console.debug(`Hashed ${name}@${version} in ${elapsedTime}ms, total time: ${totalTime}ms`);\n\n return `v${hashVersion}-${hashResult}`;\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.14",
|
|
4
4
|
"description": "Utilities for hashing packages.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"type": "module",
|
|
@@ -17,6 +17,7 @@
|
|
|
17
17
|
"@ms-cloudpack/common-types": "^0.23.5",
|
|
18
18
|
"@ms-cloudpack/config": "^0.33.2",
|
|
19
19
|
"@ms-cloudpack/package-utilities": "^10.4.1",
|
|
20
|
+
"@ms-cloudpack/path-string-parsing": "^1.2.5",
|
|
20
21
|
"fast-glob": "^3.2.12",
|
|
21
22
|
"glob-hasher": "^1.4.2",
|
|
22
23
|
"object-hash": "^3.0.0"
|