@ms-cloudpack/package-hashes 0.7.35 → 0.7.37

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.
@@ -38,6 +38,8 @@ export declare class PackageHashes implements PackageHashesCache {
38
38
  * Creates a serializable representation of the cache.
39
39
  */
40
40
  toSerializable(): SerializablePackageHashesCache;
41
+ set(input: Omit<PackageHashOptions, 'shouldRecalculate'>, hash: string): void;
42
+ extend(input: SerializablePackageHashesCache): void;
41
43
  }
42
44
  export {};
43
45
  //# sourceMappingURL=PackageHashes.d.ts.map
@@ -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,EACV,8BAA8B,EAC/B,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;IAa1C,QAAQ,CAAC,OAAO,EAAE,oBAAoB;IAZlD,mEAAmE;IACnE,OAAO,CAAC,QAAQ,CAAC,iBAAiB,CAGhC;IACF,uEAAuE;IACvE,OAAO,CAAC,QAAQ,CAAC,mBAAmB,CAGlC;IACF,OAAO,CAAC,QAAQ,CAAC,KAAK,CAAe;gBAEhB,OAAO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MAAM,CAAC,KAAK,EAAE,8BAA8B,GAAG,IAAI;CAcpD"}
@@ -63,5 +63,23 @@ export class PackageHashes {
63
63
  },
64
64
  };
65
65
  }
66
+ set(input, hash) {
67
+ const { packagePath, isSourceHashingEnabled, targetEnvironment } = input;
68
+ const map = (isSourceHashingEnabled ? this._hashesWithSource : this._hashesWithNoSource)[targetEnvironment];
69
+ map.set(packagePath, hash);
70
+ }
71
+ extend(input) {
72
+ // Helper function to merge an object's entries into a Map
73
+ const extendMap = (map, obj = {}) => {
74
+ for (const [key, value] of Object.entries(obj)) {
75
+ map.set(key, value);
76
+ }
77
+ };
78
+ // Apply to all map collections
79
+ extendMap(this._hashesWithSource.browser, input.hashesWithSource?.browser);
80
+ extendMap(this._hashesWithSource.node, input.hashesWithSource?.node);
81
+ extendMap(this._hashesWithNoSource.browser, input.hashesWithNoSource?.browser);
82
+ extendMap(this._hashesWithNoSource.node, input.hashesWithNoSource?.node);
83
+ }
66
84
  }
67
85
  //# sourceMappingURL=PackageHashes.js.map
@@ -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;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,CA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,EAAE;gBAChB,OAAO,EAAE,MAAM,CAAC,WAAW,CAAC,IAAI,CAAC,iBAAiB,CAAC,OAAO,CAAC;gBAC3D,IAAI,EAAE,MAAM,CAAC,WAAW,CAAC,IAAI,CAAC,iBAAiB,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"]}
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,EAA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,EAAE,KAAK,CAAC,gBAAgB,EAAE,OAAO,CAAC,CAAC;QAC3E,SAAS,CAAC,IAAI,CAAC,iBAAiB,CAAC,IAAI,EAAE,KAAK,CAAC,gBAAgB,EAAE,IAAI,CAAC,CAAC;QACrE,SAAS,CAAC,IAAI,CAAC,mBAAmB,CAAC,OAAO,EAAE,KAAK,CAAC,kBAAkB,EAAE,OAAO,CAAC,CAAC;QAC/E,SAAS,CAAC,IAAI,CAAC,mBAAmB,CAAC,IAAI,EAAE,KAAK,CAAC,kBAAkB,EAAE,IAAI,CAAC,CAAC;IAC3E,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 set(input: Omit<PackageHashOptions, 'shouldRecalculate'>, hash: string): void {\n const { packagePath, isSourceHashingEnabled, targetEnvironment } = input;\n const map = (isSourceHashingEnabled ? this._hashesWithSource : this._hashesWithNoSource)[targetEnvironment];\n map.set(packagePath, hash);\n }\n\n extend(input: SerializablePackageHashesCache): void {\n // Helper function to merge an object's entries into a Map\n const extendMap = (map: Map<string, string>, obj: Record<string, string> = {}): void => {\n for (const [key, value] of Object.entries(obj)) {\n map.set(key, value);\n }\n };\n\n // Apply to all map collections\n extendMap(this._hashesWithSource.browser, input.hashesWithSource?.browser);\n extendMap(this._hashesWithSource.node, input.hashesWithSource?.node);\n extendMap(this._hashesWithNoSource.browser, input.hashesWithNoSource?.browser);\n extendMap(this._hashesWithNoSource.node, input.hashesWithNoSource?.node);\n }\n}\n"]}
@@ -1,3 +1,4 @@
1
+ import type { PackageJson } from '@ms-cloudpack/common-types';
1
2
  export interface PackagePatchesSettings {
2
3
  /** Working directory, used to determine the project root where patches are stored. */
3
4
  cwd: string;
@@ -12,17 +13,20 @@ interface PackagePatch {
12
13
  }
13
14
  /**
14
15
  * PackagePatchesCache manages a cache of information about patch files, which are usually stored in the
15
- * `patches` folder at the root of the repo. It provides a method to retrieve the patch file
16
- * path and contents for a given package name and version.
16
+ * `patches` folder at the root of the repo (also handles yarn v2+ patches).
17
17
  */
18
18
  export declare class PackagePatchesCache {
19
19
  private readonly settings;
20
20
  /**
21
- * Mapping from `${packageName}@${version}` to patch file path and contents.
22
- * The paths are saved on an initial pass, but the contents are only saved on first read
23
- * (in case of very large patch files which are never used).
21
+ * Mapping from package key (see `getKey`) to patch file path and contents.
22
+ *
23
+ * The paths from `globPattern` (or `defaultGlobPattern`) are saved in an initial pass, but the
24
+ * contents are only read on first request (in case of very large patches for packages that
25
+ * cloudpack doesn't process). Yarn v2+ patches are also lazy loaded.
24
26
  */
25
27
  private _patches;
28
+ private _loaded;
29
+ private _rootPath;
26
30
  constructor(settings: PackagePatchesSettings);
27
31
  private getKey;
28
32
  /**
@@ -32,11 +36,9 @@ export declare class PackagePatchesCache {
32
36
  private readPatchFile;
33
37
  /**
34
38
  * Gets info about the patch file for the specified package.
35
- * @param packageName - The name of the package to check.
36
- * @param version - The version of the package to check.
37
39
  * @returns Patch file path and contents if the package has been patched, undefined otherwise.
38
40
  */
39
- getPackagePatch(packageName: string, version: string): Promise<PackagePatch | undefined>;
41
+ getPackagePatch(definition: PackageJson): Promise<PackagePatch | undefined>;
40
42
  }
41
43
  export {};
42
44
  //# sourceMappingURL=PackagePatchesCache.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"PackagePatchesCache.d.ts","sourceRoot":"","sources":["../src/PackagePatchesCache.ts"],"names":[],"mappings":"AAMA,MAAM,WAAW,sBAAsB;IACrC,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AAO,CAAC,OAAO,CAAS;IACxB,OAAO,CAAC,SAAS,CAAqB;gBAET,QAAQ,EAAE,sBAAsB;IAI7D,OAAO,CAAC,MAAM;IAId;;OAEG;YACW,mBAAmB;YA+BnB,aAAa;IAS3B;;;OAGG;IACU,eAAe,CAAC,UAAU,EAAE,WAAW,GAAG,OAAO,CAAC,YAAY,GAAG,SAAS,CAAC;CA0BzF"}
@@ -3,21 +3,27 @@ import fsPromises from 'fs/promises';
3
3
  import glob from 'fast-glob';
4
4
  import path from 'path';
5
5
  import { parsePatchFilePath } from './parsePatchFilePath.js';
6
+ /** Default `patch-package` patches path. (yarn v2+ patches are handled separately.) */
7
+ const defaultGlobPattern = 'patches/*.patch';
6
8
  /**
7
9
  * PackagePatchesCache manages a cache of information about patch files, which are usually stored in the
8
- * `patches` folder at the root of the repo. It provides a method to retrieve the patch file
9
- * path and contents for a given package name and version.
10
+ * `patches` folder at the root of the repo (also handles yarn v2+ patches).
10
11
  */
11
12
  export class PackagePatchesCache {
12
13
  settings;
13
14
  /**
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).
15
+ * Mapping from package key (see `getKey`) to patch file path and contents.
16
+ *
17
+ * The paths from `globPattern` (or `defaultGlobPattern`) are saved in an initial pass, but the
18
+ * contents are only read on first request (in case of very large patches for packages that
19
+ * cloudpack doesn't process). Yarn v2+ patches are also lazy loaded.
17
20
  */
18
21
  _patches;
22
+ _loaded = false;
23
+ _rootPath;
19
24
  constructor(settings) {
20
25
  this.settings = settings;
26
+ this._patches = settings.patches || {};
21
27
  }
22
28
  getKey(packageName, version) {
23
29
  return `${packageName}@${version}`;
@@ -26,20 +32,15 @@ export class PackagePatchesCache {
26
32
  * Loads the list of patched packages from the `patches` folder.
27
33
  */
28
34
  async loadPatchedPackages() {
29
- if (this.settings.patches) {
30
- this._patches = this.settings.patches;
35
+ if (this._loaded) {
31
36
  return;
32
37
  }
33
- this._patches = {};
38
+ this._loaded = true;
34
39
  // get the repo root
35
- const rootPath = findProjectRoot(this.settings.cwd) || this.settings.cwd;
36
- if (!rootPath) {
37
- console.info('Could not find the root of the repo. Skipping loading patched packages.');
38
- return;
39
- }
40
+ this._rootPath = findProjectRoot(this.settings.cwd) || this.settings.cwd;
40
41
  // get the files with .patch extension
41
- const patchFiles = await glob(this.settings.globPattern || 'patches/*.patch', {
42
- cwd: rootPath,
42
+ const patchFiles = await glob(this.settings.globPattern || defaultGlobPattern, {
43
+ cwd: this._rootPath,
43
44
  absolute: true,
44
45
  });
45
46
  for (const absoluteFilePath of patchFiles) {
@@ -65,15 +66,22 @@ export class PackagePatchesCache {
65
66
  }
66
67
  /**
67
68
  * Gets info about the patch file for the specified package.
68
- * @param packageName - The name of the package to check.
69
- * @param version - The version of the package to check.
70
69
  * @returns Patch file path and contents if the package has been patched, undefined otherwise.
71
70
  */
72
- async getPackagePatch(packageName, version) {
73
- if (!this._patches) {
71
+ async getPackagePatch(definition) {
72
+ if (!this._loaded) {
74
73
  await this.loadPatchedPackages();
75
74
  }
76
- const patchInfo = this._patches?.[this.getKey(packageName, version)];
75
+ const key = this.getKey(definition.name, definition.version);
76
+ let patchInfo = this._patches[key];
77
+ if (!patchInfo && definition.cloudpack?.patchFilePath && this._rootPath) {
78
+ // Yarn v2+ patch files don't use a parseable name, so we handle them separately.
79
+ // The file paths are like .yarn/patches/@foo-bar-baz-npm-4.3.0-e85334d38f.patch
80
+ // without a way to distinguish where the scope ends.
81
+ console.debug(`Found yarn patch file for package: ${key}`);
82
+ patchInfo = { path: path.join(this._rootPath, definition.cloudpack.patchFilePath) };
83
+ this._patches[key] = patchInfo;
84
+ }
77
85
  if (patchInfo) {
78
86
  // The contents are lazy loaded
79
87
  patchInfo.contents ??= await this.readPatchFile(patchInfo.path);
@@ -1 +1 @@
1
- {"version":3,"file":"PackagePatchesCache.js","sourceRoot":"","sources":["../src/PackagePatchesCache.ts"],"names":[],"mappings":"AAAA,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nB,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"]}
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,WAAW,CAAC;AAC7B,OAAO,IAAI,MAAM,MAAM,CAAC;AACxB,OAAO,EAAE,kBAAkB,EAAE,MAAM,yBAAyB,CAAC;AAG7D,uFAAuF;AACvF,MAAM,kBAAkB,GAAG,iBAAiB,CAAC;AAkB7C;;;GAGG;AACH,MAAM,OAAO,mBAAmB;IAYD;IAX7B;;;;;;OAMG;IACK,QAAQ,CAA8C;IACtD,OAAO,GAAG,KAAK,CAAC;IAChB,SAAS,CAAqB;IAEtC,YAA6B,QAAgC;QAAhC,aAAQ,GAAR,QAAQ,CAAwB;QAC3D,IAAI,CAAC,QAAQ,GAAG,QAAQ,CAAC,OAAO,IAAI,EAAE,CAAC;IACzC,CAAC;IAEO,MAAM,CAAC,WAAmB,EAAE,OAAe;QACjD,OAAO,GAAG,WAAW,IAAI,OAAO,EAAE,CAAC;IACrC,CAAC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AAO,CAAC,IAAI,CAAC,6BAA6B,aAAa,MAAM,CAAC,EAAE,CAAC,CAAC;YAClE,OAAO,EAAE,CAAC;QACZ,CAAC;IACH,CAAC;IAED;;;OAGG;IACI,KAAK,CAAC,eAAe,CAAC,UAAuB;QAClD,IAAI,CAAC,IAAI,CAAC,OAAO,EAAE,CAAC;YAClB,MAAM,IAAI,CAAC,mBAAmB,EAAE,CAAC;QACnC,CAAC;QAED,MAAM,GAAG,GAAG,IAAI,CAAC,MAAM,CAAC,UAAU,CAAC,IAAI,EAAE,UAAU,CAAC,OAAO,CAAC,CAAC;QAE7D,IAAI,SAAS,GAAG,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC;QAEnC,IAAI,CAAC,SAAS,IAAI,UAAU,CAAC,SAAS,EAAE,aAAa,IAAI,IAAI,CAAC,SAAS,EAAE,CAAC;YACxE,iFAAiF;YACjF,gFAAgF;YAChF,qDAAqD;YACrD,OAAO,CAAC,KAAK,CAAC,sCAAsC,GAAG,EAAE,CAAC,CAAC;YAC3D,SAAS,GAAG,EAAE,IAAI,EAAE,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,SAAS,EAAE,UAAU,CAAC,SAAS,CAAC,aAAa,CAAC,EAAE,CAAC;YACpF,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,GAAG,SAAS,CAAC;QACjC,CAAC;QAED,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';\nimport type { PackageJson } from '@ms-cloudpack/common-types';\n\n/** Default `patch-package` patches path. (yarn v2+ patches are handled separately.) */\nconst defaultGlobPattern = 'patches/*.patch';\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 (also handles yarn v2+ patches).\n */\nexport class PackagePatchesCache {\n /**\n * Mapping from package key (see `getKey`) to patch file path and contents.\n *\n * The paths from `globPattern` (or `defaultGlobPattern`) are saved in an initial pass, but the\n * contents are only read on first request (in case of very large patches for packages that\n * cloudpack doesn't process). Yarn v2+ patches are also lazy loaded.\n */\n private _patches: Record<`${string}@${string}`, PackagePatch>;\n private _loaded = false;\n private _rootPath: string | undefined;\n\n constructor(private readonly settings: PackagePatchesSettings) {\n this._patches = settings.patches || {};\n }\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._loaded) {\n return;\n }\n\n this._loaded = true;\n\n // get the repo root\n this._rootPath = findProjectRoot(this.settings.cwd) || this.settings.cwd;\n\n // get the files with .patch extension\n const patchFiles = await glob(this.settings.globPattern || defaultGlobPattern, {\n cwd: this._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 * @returns Patch file path and contents if the package has been patched, undefined otherwise.\n */\n public async getPackagePatch(definition: PackageJson): Promise<PackagePatch | undefined> {\n if (!this._loaded) {\n await this.loadPatchedPackages();\n }\n\n const key = this.getKey(definition.name, definition.version);\n\n let patchInfo = this._patches[key];\n\n if (!patchInfo && definition.cloudpack?.patchFilePath && this._rootPath) {\n // Yarn v2+ patch files don't use a parseable name, so we handle them separately.\n // The file paths are like .yarn/patches/@foo-bar-baz-npm-4.3.0-e85334d38f.patch\n // without a way to distinguish where the scope ends.\n console.debug(`Found yarn patch file for package: ${key}`);\n patchInfo = { path: path.join(this._rootPath, definition.cloudpack.patchFilePath) };\n this._patches[key] = patchInfo;\n }\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"]}
@@ -16,7 +16,7 @@ export async function getPackageHashEntries(params) {
16
16
  const filesHash = !isExternal && isSourceHashingEnabled
17
17
  ? await getSourceHash({ packagePath, inputPaths: packageSettings.inputPaths })
18
18
  : undefined;
19
- const patchFileContent = isExternal ? (await patches.getPackagePatch(name, version))?.contents : undefined;
19
+ const patchFileContent = isExternal ? (await patches.getPackagePatch(definition))?.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
@@ -1 +1 @@
1
- {"version":3,"file":"getPackageHashEntries.js","sourceRoot":"","sources":["../src/getPackageHashEntries.ts"],"names":[],"mappings":"AAOA,OAAO,EAAE,iBAAiB,EAAE,MAAM,8BAA8B,CAAC;AAEjE,OAAO,EAAE,aAAa,EAAkB,MAAM,oBAAoB,CAAC;AA0BnE;;GAEG;AACH,MAAM,C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U,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,sEAAsE;IACtE,IAAI,iBAAiB,KAAK,SAAS,EAAE,CAAC;QACpC,MAAM,CAAC,iBAAiB,GAAG,iBAAiB,CAAC;IAC/C,CAAC;IAED,OAAO,MAAM,CAAC;AAChB,CAAC","sourcesContent":["import type {\n PackageDefinitionsCache,\n PackageJsonCloudpackMeta,\n PackageJsonDependencies,\n PackageJsonExports,\n TargetEnvironment,\n} from '@ms-cloudpack/common-types';\nimport { isExternalPackage } from '@ms-cloudpack/path-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<PackageJsonCloudpackMeta>;\n /** Content of any bundler capabilities files for the package. */\n bundlerCapabilitiesContent?: Record<string, string>;\n /** Target environment, if not `'browser'` */\n targetEnvironment?: TargetEnvironment;\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, targetEnvironment, isSourceHashingEnabled } = options;\n const { packages, patches, bundlerCapabilitiesCache } = context;\n\n const definition = await packages.get(packagePath);\n const originalDefinition = 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: originalDefinition.dependencies,\n peerDependencies: originalDefinition.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 // Conditionally setting this prevents invalidating all cached content\n if (targetEnvironment !== 'browser') {\n result.targetEnvironment = targetEnvironment;\n }\n\n return result;\n}\n"]}
1
+ {"version":3,"file":"getPackageHashEntries.js","sourceRoot":"","sources":["../src/getPackageHashEntries.ts"],"names":[],"mappings":"AAOA,OAAO,EAAE,iBAAiB,EAAE,MAAM,8BAA8B,CAAC;AAEjE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AAE,kBAAkB,CAAC,gBAAgB;QACrD,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,sEAAsE;IACtE,IAAI,iBAAiB,KAAK,SAAS,EAAE,CAAC;QACpC,MAAM,CAAC,iBAAiB,GAAG,iBAAiB,CAAC;IAC/C,CAAC;IAED,OAAO,MAAM,CAAC;AAChB,CAAC","sourcesContent":["import type {\n PackageDefinitionsCache,\n PackageJsonCloudpackMeta,\n PackageJsonDependencies,\n PackageJsonExports,\n TargetEnvironment,\n} from '@ms-cloudpack/common-types';\nimport { isExternalPackage } from '@ms-cloudpack/path-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<PackageJsonCloudpackMeta>;\n /** Content of any bundler capabilities files for the package. */\n bundlerCapabilitiesContent?: Record<string, string>;\n /** Target environment, if not `'browser'` */\n targetEnvironment?: TargetEnvironment;\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, targetEnvironment, isSourceHashingEnabled } = options;\n const { packages, patches, bundlerCapabilitiesCache } = context;\n\n const definition = await packages.get(packagePath);\n const originalDefinition = 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(definition))?.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: originalDefinition.dependencies,\n peerDependencies: originalDefinition.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 // Conditionally setting this prevents invalidating all cached content\n if (targetEnvironment !== 'browser') {\n result.targetEnvironment = targetEnvironment;\n }\n\n return result;\n}\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ms-cloudpack/package-hashes",
3
- "version": "0.7.35",
3
+ "version": "0.7.37",
4
4
  "description": "Utilities for hashing packages.",
5
5
  "license": "MIT",
6
6
  "type": "module",
@@ -14,11 +14,11 @@
14
14
  }
15
15
  },
16
16
  "dependencies": {
17
- "@ms-cloudpack/common-types": "^0.24.11",
18
- "@ms-cloudpack/config": "^0.33.23",
19
- "@ms-cloudpack/package-utilities": "^12.0.2",
20
- "@ms-cloudpack/path-string-parsing": "^1.2.6",
21
- "@ms-cloudpack/path-utilities": "^3.0.8",
17
+ "@ms-cloudpack/common-types": "^0.24.13",
18
+ "@ms-cloudpack/config": "^0.33.25",
19
+ "@ms-cloudpack/package-utilities": "^12.1.0",
20
+ "@ms-cloudpack/path-string-parsing": "^1.2.7",
21
+ "@ms-cloudpack/path-utilities": "^3.0.10",
22
22
  "fast-glob": "^3.2.12",
23
23
  "glob-hasher": "^1.4.2",
24
24
  "object-hash": "^3.0.0"