@ms-cloudpack/package-hashes 0.3.14 → 0.3.15

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 +1 @@
1
- {"version":3,"file":"PackageHashes.d.ts","sourceRoot":"","sources":["../src/PackageHashes.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,+BAA+B,CAAC;AAE1E;;GAEG;AACH,qBAAa,aAAa;IAKZ,QAAQ,CAAC,OAAO,EAAE,oBAAoB;IAJlD,OAAO,CAAC,QAAQ,CAAC,iBAAiB,CAA0D;IAC5F,OAAO,CAAC,QAAQ,CAAC,mBAAmB,CAA0D;IAC9F,OAAO,CAAC,QAAQ,CAAC,KAAK,CAAe;gBAEhB,OAAO,EAAE,oBAAoB;IAmBlD;;;;;;;OAOG;IACG,GAAG,CAAC,MAAM,EAAE;QAChB,WAAW,EAAE,MAAM,CAAC;QACpB,sBAAsB,EAAE,OAAO,CAAC;QAChC,iBAAiB,CAAC,EAAE,OAAO,CAAC;KAC7B,GAAG,OAAO,CAAC,MAAM,CAAC;CAepB"}
1
+ {"version":3,"file":"PackageHashes.d.ts","sourceRoot":"","sources":["../src/PackageHashes.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,+BAA+B,CAAC;AAE1E;;GAEG;AACH,qBAAa,aAAa;IAKZ,QAAQ,CAAC,OAAO,EAAE,oBAAoB;IAJlD,OAAO,CAAC,QAAQ,CAAC,iBAAiB,CAA0D;IAC5F,OAAO,CAAC,QAAQ,CAAC,mBAAmB,CAA0D;IAC9F,OAAO,CAAC,QAAQ,CAAC,KAAK,CAAe;gBAEhB,OAAO,EAAE,oBAAoB;IAoBlD;;;;;;;OAOG;IACG,GAAG,CAAC,MAAM,EAAE;QAChB,WAAW,EAAE,MAAM,CAAC;QACpB,sBAAsB,EAAE,OAAO,CAAC;QAChC,iBAAiB,CAAC,EAAE,OAAO,CAAC;KAC7B,GAAG,OAAO,CAAC,MAAM,CAAC;CAepB"}
@@ -14,6 +14,7 @@ export class PackageHashes {
14
14
  }
15
15
  const { config } = options.context;
16
16
  const patches = new PackagePatchesCache({
17
+ cwd: options.cwd,
17
18
  globPattern: config.patchFilesGlobPattern,
18
19
  });
19
20
  const context = {
@@ -1 +1 @@
1
- {"version":3,"file":"PackageHashes.js","sourceRoot":"","sources":["../src/PackageHashes.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,mBAAmB,EAAE,MAAM,0BAA0B,CAAC;AAC/D,OAAO,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAI/C;;GAEG;AACH,MAAM,OAAO,aAAa;IAKxB,YAAqB,OAA6B;QAA7B,YAAO,GAAP,OAAO,CAAsB;QAJjC,sBAAiB,GAAG,IAAI,GAAG,EAA+C,CAAC;QAC3E,wBAAmB,GAAG,IAAI,GAAG,EAA+C,CAAC;QAI5F,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,WAAW,EAAE,MAAM,CAAC,qBAAqB;SAC1C,CAAC,CAAC;QAEH,MAAM,OAAO,GAAG;YACd,GAAG,OAAO,CAAC,OAAO;YAClB,OAAO;SACR,CAAC;QAEF,IAAI,CAAC,KAAK,GAAG,CAAC,KAAK,EAAE,EAAE,CAAC,WAAW,CAAC,EAAE,KAAK,EAAE,OAAO,EAAE,CAAC,CAAC;IAC1D,CAAC;IAED;;;;;;;OAOG;IACH,KAAK,CAAC,GAAG,CAAC,MAIT;QACC,MAAM,EAAE,WAAW,EAAE,sBAAsB,EAAE,iBAAiB,EAAE,GAAG,MAAM,CAAC;QAE1E,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,MAAM,CAAC,CAAC;QAEtC,GAAG,CAAC,GAAG,CAAC,WAAW,EAAE,IAAI,CAAC,CAAC;QAE3B,OAAO,IAAI,CAAC;IACd,CAAC;CACF","sourcesContent":["import { PackagePatchesCache } from './PackagePatchesCache.js';\nimport { hashPackage } from './hashPackage.js';\nimport type { HashFunction } from './types/HashFunctions.js';\nimport type { PackageHashesOptions } from './types/PackageHashOptions.js';\n\n/**\n * Utility class for hashing packages and caching the results.\n */\nexport class PackageHashes {\n private readonly _hashesWithSource = new Map<string /* packagePath */, string /* hash */>();\n private readonly _hashesWithNoSource = new Map<string /* packagePath */, string /* hash */>();\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 globPattern: config.patchFilesGlobPattern,\n });\n\n const context = {\n ...options.context,\n patches,\n };\n\n this._hash = (input) => hashPackage({ input, context });\n }\n\n /**\n * Gets the hash for a given package path. This is useful for caching, to determine if the package has changed.\n * If the package definition has not been calculated, it will be calculated and cached.\n * @param packagePath - The package path to get the hash for.\n * @param isSourceHashingEnabled - Whether or not to hash the source files.\n * @param shouldRecalculate - Whether or not to force a re-calculation of the hash.\n * @returns The hash for the package.\n */\n async get(params: {\n packagePath: string;\n isSourceHashingEnabled: boolean;\n shouldRecalculate?: boolean;\n }): Promise<string> {\n const { packagePath, isSourceHashingEnabled, shouldRecalculate } = params;\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(params);\n\n map.set(packagePath, hash);\n\n return hash;\n }\n}\n"]}
1
+ {"version":3,"file":"PackageHashes.js","sourceRoot":"","sources":["../src/PackageHashes.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,mBAAmB,EAAE,MAAM,0BAA0B,CAAC;AAC/D,OAAO,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAI/C;;GAEG;AACH,MAAM,OAAO,aAAa;IAKxB,YAAqB,OAA6B;QAA7B,YAAO,GAAP,OAAO,CAAsB;QAJjC,sBAAiB,GAAG,IAAI,GAAG,EAA+C,CAAC;QAC3E,wBAAmB,GAAG,IAAI,GAAG,EAA+C,CAAC;QAI5F,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;QAEH,MAAM,OAAO,GAAG;YACd,GAAG,OAAO,CAAC,OAAO;YAClB,OAAO;SACR,CAAC;QAEF,IAAI,CAAC,KAAK,GAAG,CAAC,KAAK,EAAE,EAAE,CAAC,WAAW,CAAC,EAAE,KAAK,EAAE,OAAO,EAAE,CAAC,CAAC;IAC1D,CAAC;IAED;;;;;;;OAOG;IACH,KAAK,CAAC,GAAG,CAAC,MAIT;QACC,MAAM,EAAE,WAAW,EAAE,sBAAsB,EAAE,iBAAiB,EAAE,GAAG,MAAM,CAAC;QAE1E,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,MAAM,CAAC,CAAC;QAEtC,GAAG,CAAC,GAAG,CAAC,WAAW,EAAE,IAAI,CAAC,CAAC;QAE3B,OAAO,IAAI,CAAC;IACd,CAAC;CACF","sourcesContent":["import { PackagePatchesCache } from './PackagePatchesCache.js';\nimport { hashPackage } from './hashPackage.js';\nimport type { HashFunction } from './types/HashFunctions.js';\nimport type { PackageHashesOptions } from './types/PackageHashOptions.js';\n\n/**\n * Utility class for hashing packages and caching the results.\n */\nexport class PackageHashes {\n private readonly _hashesWithSource = new Map<string /* packagePath */, string /* hash */>();\n private readonly _hashesWithNoSource = new Map<string /* packagePath */, string /* hash */>();\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\n const context = {\n ...options.context,\n patches,\n };\n\n this._hash = (input) => hashPackage({ input, context });\n }\n\n /**\n * Gets the hash for a given package path. This is useful for caching, to determine if the package has changed.\n * If the package definition has not been calculated, it will be calculated and cached.\n * @param packagePath - The package path to get the hash for.\n * @param isSourceHashingEnabled - Whether or not to hash the source files.\n * @param shouldRecalculate - Whether or not to force a re-calculation of the hash.\n * @returns The hash for the package.\n */\n async get(params: {\n packagePath: string;\n isSourceHashingEnabled: boolean;\n shouldRecalculate?: boolean;\n }): Promise<string> {\n const { packagePath, isSourceHashingEnabled, shouldRecalculate } = params;\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(params);\n\n map.set(packagePath, hash);\n\n return hash;\n }\n}\n"]}
@@ -1,6 +1,7 @@
1
1
  import type { PackagePatches } from './types/PackagePatches.js';
2
2
  export interface PackagePatchesSettings {
3
- globRootPath?: string;
3
+ /** Working directory, used to determine the project root where patches are stored. */
4
+ cwd: string;
4
5
  globPattern?: string;
5
6
  }
6
7
  /**
@@ -1 +1 @@
1
- {"version":3,"file":"PackagePatchesCache.d.ts","sourceRoot":"","sources":["../src/PackagePatchesCache.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,2BAA2B,CAAC;AAEhE,MAAM,WAAW,sBAAsB;IACrC,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,WAAW,CAAC,EAAE,MAAM,CAAC;CACtB;AAED;;;;;;;;GAQG;AACH,qBAAa,mBAAoB,YAAW,cAAc;IAG5C,OAAO,CAAC,QAAQ,CAAC,QAAQ;IAFrC,OAAO,CAAC,QAAQ,CAAmG;gBAEtF,QAAQ,EAAE,sBAAsB;IAE7D,OAAO,CAAC,MAAM;IAId;;OAEG;YACW,mBAAmB;IAgCjC;;;;;OAKG;IACU,eAAe,CAAC,WAAW,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM;CAMlE"}
1
+ {"version":3,"file":"PackagePatchesCache.d.ts","sourceRoot":"","sources":["../src/PackagePatchesCache.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,2BAA2B,CAAC;AAEhE,MAAM,WAAW,sBAAsB;IACrC,sFAAsF;IACtF,GAAG,EAAE,MAAM,CAAC;IACZ,WAAW,CAAC,EAAE,MAAM,CAAC;CACtB;AAED;;;;;;;;GAQG;AACH,qBAAa,mBAAoB,YAAW,cAAc;IAG5C,OAAO,CAAC,QAAQ,CAAC,QAAQ;IAFrC,OAAO,CAAC,QAAQ,CAAmG;gBAEtF,QAAQ,EAAE,sBAAsB;IAE7D,OAAO,CAAC,MAAM;IAId;;OAEG;YACW,mBAAmB;IAgCjC;;;;;OAKG;IACU,eAAe,CAAC,WAAW,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM;CAMlE"}
@@ -24,7 +24,7 @@ export class PackagePatchesCache {
24
24
  async loadPatchedPackages() {
25
25
  this._patches = {};
26
26
  // get the repo root
27
- const rootPath = this.settings.globRootPath || findProjectRoot(process.cwd());
27
+ const rootPath = findProjectRoot(this.settings.cwd) || this.settings.cwd;
28
28
  if (!rootPath) {
29
29
  console.info('Could not find the root of the repo. Skipping loading patched packages.');
30
30
  return;
@@ -1 +1 @@
1
- {"version":3,"file":"PackagePatchesCache.js","sourceRoot":"","sources":["../src/PackagePatchesCache.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,iCAAiC,CAAC;AAClE,OAAO,IAAI,MAAM,WAAW,CAAC;AAC7B,OAAO,IAAI,MAAM,MAAM,CAAC;AACxB,OAAO,EAAE,kBAAkB,EAAE,MAAM,yBAAyB,CAAC;AAQ7D;;;;;;;;GAQG;AACH,MAAM,OAAO,mBAAmB;IAG9B,YAA6B,QAAgC;QAAhC,aAAQ,GAAR,QAAQ,CAAwB;IAAG,CAAC;IAEzD,MAAM,CAAC,WAAmB,EAAE,OAAe;QACjD,OAAO,GAAG,WAAW,IAAI,OAAO,EAAE,CAAC;IACrC,CAAC;IAED;;OAEG;IACK,KAAK,CAAC,mBAAmB;QAC/B,IAAI,CAAC,QAAQ,GAAG,EAAE,CAAC;QAEnB,oBAAoB;QACpB,MAAM,QAAQ,GAAG,IAAI,CAAC,QAAQ,CAAC,YAAY,IAAI,eAAe,CAAC,OAAO,CAAC,GAAG,EAAE,CAAC,CAAC;QAE9E,IAAI,CAAC,QAAQ,EAAE,CAAC;YACd,OAAO,CAAC,IAAI,CAAC,yEAAyE,CAAC,CAAC;YACxF,OAAO;QACT,CAAC;QAED,sCAAsC;QACtC,MAAM,UAAU,GAAG,MAAM,IAAI,CAAC,IAAI,CAAC,QAAQ,CAAC,WAAW,IAAI,iBAAiB,EAAE;YAC5E,GAAG,EAAE,QAAQ;YACb,QAAQ,EAAE,IAAI;SACf,CAAC,CAAC;QAEH,KAAK,MAAM,gBAAgB,IAAI,UAAU,EAAE,CAAC;YAC1C,IAAI,CAAC;gBACH,MAAM,cAAc,GAAG,IAAI,CAAC,SAAS,CAAC,gBAAgB,CAAC,CAAC;gBAExD,MAAM,EAAE,WAAW,EAAE,OAAO,EAAE,GAAG,kBAAkB,CAAC,cAAc,CAAC,CAAC;gBAEpE,OAAO,CAAC,KAAK,CAAC,iCAAiC,WAAW,IAAI,OAAO,EAAE,CAAC,CAAC;gBAEzE,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,MAAM,CAAC,WAAW,EAAE,OAAO,CAAC,CAAC,GAAG,cAAc,CAAC;YACpE,CAAC;YAAC,OAAO,CAAC,EAAE,CAAC;gBACX,OAAO,CAAC,IAAI,CAAC,uBAAuB,gBAAgB,EAAE,CAAC,CAAC;YAC1D,CAAC;QACH,CAAC;IACH,CAAC;IAED;;;;;OAKG;IACI,KAAK,CAAC,eAAe,CAAC,WAAmB,EAAE,OAAe;QAC/D,IAAI,CAAC,IAAI,CAAC,QAAQ,EAAE,CAAC;YACnB,MAAM,IAAI,CAAC,mBAAmB,EAAE,CAAC;QACnC,CAAC;QACD,OAAO,IAAI,CAAC,QAAQ,EAAE,CAAC,IAAI,CAAC,MAAM,CAAC,WAAW,EAAE,OAAO,CAAC,CAAC,CAAC;IAC5D,CAAC;CACF","sourcesContent":["import { findProjectRoot } from '@ms-cloudpack/package-utilities';\nimport glob from 'fast-glob';\nimport path from 'path';\nimport { parsePatchFilePath } from './parsePatchFilePath.js';\nimport type { PackagePatches } from './types/PackagePatches.js';\n\nexport interface PackagePatchesSettings {\n globRootPath?: string;\n globPattern?: string;\n}\n\n/**\n * PackagePatchesCache is a class responsible for managing a cache of patched packages\n * by reading and storing information about patch files in the patches folder at the root of the repo.\n * It provides a method to retrieve the path to the patch file for a given package\n * based on the package name and version.\n *\n * @class PackagePatchesCache\n * @implements {PackagePatches}\n */\nexport class PackagePatchesCache implements PackagePatches {\n private _patches: Record<`${string}@${string}` /* ${packageName}@${version} */, string /* filePath */> | 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() {\n this._patches = {};\n\n // get the repo root\n const rootPath = this.settings.globRootPath || findProjectRoot(process.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)] = normalizedPath;\n } catch (e) {\n console.warn(`Invalid patch file: ${absoluteFilePath}`);\n }\n }\n }\n\n /**\n * Gets the path to 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 - Path to the patch file if the package has been patched, undefined otherwise.\n */\n public async getPackagePatch(packageName: string, version: string) {\n if (!this._patches) {\n await this.loadPatchedPackages();\n }\n return this._patches?.[this.getKey(packageName, version)];\n }\n}\n"]}
1
+ {"version":3,"file":"PackagePatchesCache.js","sourceRoot":"","sources":["../src/PackagePatchesCache.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,iCAAiC,CAAC;AAClE,OAAO,IAAI,MAAM,WAAW,CAAC;AAC7B,OAAO,IAAI,MAAM,MAAM,CAAC;AACxB,OAAO,EAAE,kBAAkB,EAAE,MAAM,yBAAyB,CAAC;AAS7D;;;;;;;;GAQG;AACH,MAAM,OAAO,mBAAmB;IAG9B,YAA6B,QAAgC;QAAhC,aAAQ,GAAR,QAAQ,CAAwB;IAAG,CAAC;IAEzD,MAAM,CAAC,WAAmB,EAAE,OAAe;QACjD,OAAO,GAAG,WAAW,IAAI,OAAO,EAAE,CAAC;IACrC,CAAC;IAED;;OAEG;IACK,KAAK,CAAC,mBAAmB;QAC/B,IAAI,CAAC,QAAQ,GAAG,EAAE,CAAC;QAEnB,oBAAoB;QACpB,MAAM,QAAQ,GAAG,eAAe,CAAC,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,IAAI,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC;QAEzE,IAAI,CAAC,QAAQ,EAAE,CAAC;YACd,OAAO,CAAC,IAAI,CAAC,yEAAyE,CAAC,CAAC;YACxF,OAAO;QACT,CAAC;QAED,sCAAsC;QACtC,MAAM,UAAU,GAAG,MAAM,IAAI,CAAC,IAAI,CAAC,QAAQ,CAAC,WAAW,IAAI,iBAAiB,EAAE;YAC5E,GAAG,EAAE,QAAQ;YACb,QAAQ,EAAE,IAAI;SACf,CAAC,CAAC;QAEH,KAAK,MAAM,gBAAgB,IAAI,UAAU,EAAE,CAAC;YAC1C,IAAI,CAAC;gBACH,MAAM,cAAc,GAAG,IAAI,CAAC,SAAS,CAAC,gBAAgB,CAAC,CAAC;gBAExD,MAAM,EAAE,WAAW,EAAE,OAAO,EAAE,GAAG,kBAAkB,CAAC,cAAc,CAAC,CAAC;gBAEpE,OAAO,CAAC,KAAK,CAAC,iCAAiC,WAAW,IAAI,OAAO,EAAE,CAAC,CAAC;gBAEzE,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,MAAM,CAAC,WAAW,EAAE,OAAO,CAAC,CAAC,GAAG,cAAc,CAAC;YACpE,CAAC;YAAC,OAAO,CAAC,EAAE,CAAC;gBACX,OAAO,CAAC,IAAI,CAAC,uBAAuB,gBAAgB,EAAE,CAAC,CAAC;YAC1D,CAAC;QACH,CAAC;IACH,CAAC;IAED;;;;;OAKG;IACI,KAAK,CAAC,eAAe,CAAC,WAAmB,EAAE,OAAe;QAC/D,IAAI,CAAC,IAAI,CAAC,QAAQ,EAAE,CAAC;YACnB,MAAM,IAAI,CAAC,mBAAmB,EAAE,CAAC;QACnC,CAAC;QACD,OAAO,IAAI,CAAC,QAAQ,EAAE,CAAC,IAAI,CAAC,MAAM,CAAC,WAAW,EAAE,OAAO,CAAC,CAAC,CAAC;IAC5D,CAAC;CACF","sourcesContent":["import { findProjectRoot } from '@ms-cloudpack/package-utilities';\nimport glob from 'fast-glob';\nimport path from 'path';\nimport { parsePatchFilePath } from './parsePatchFilePath.js';\nimport type { PackagePatches } from './types/PackagePatches.js';\n\nexport interface PackagePatchesSettings {\n /** Working directory, used to determine the project root where patches are stored. */\n cwd: string;\n globPattern?: string;\n}\n\n/**\n * PackagePatchesCache is a class responsible for managing a cache of patched packages\n * by reading and storing information about patch files in the patches folder at the root of the repo.\n * It provides a method to retrieve the path to the patch file for a given package\n * based on the package name and version.\n *\n * @class PackagePatchesCache\n * @implements {PackagePatches}\n */\nexport class PackagePatchesCache implements PackagePatches {\n private _patches: Record<`${string}@${string}` /* ${packageName}@${version} */, string /* filePath */> | 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() {\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)] = normalizedPath;\n } catch (e) {\n console.warn(`Invalid patch file: ${absoluteFilePath}`);\n }\n }\n }\n\n /**\n * Gets the path to 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 - Path to the patch file if the package has been patched, undefined otherwise.\n */\n public async getPackagePatch(packageName: string, version: string) {\n if (!this._patches) {\n await this.loadPatchedPackages();\n }\n return this._patches?.[this.getKey(packageName, version)];\n }\n}\n"]}
@@ -11,6 +11,8 @@ export type PackageHashesOptions = {
11
11
  */
12
12
  hash: HashFunction;
13
13
  } | {
14
+ /** Working directory used to find the project root (usually repository root). */
15
+ cwd: string;
14
16
  /**
15
17
  * Context for the hash calculations.
16
18
  */
@@ -1 +1 @@
1
- {"version":3,"file":"PackageHashOptions.d.ts","sourceRoot":"","sources":["../../src/types/PackageHashOptions.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,6BAA6B,CAAC;AAC3E,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,4BAA4B,CAAC;AAClE,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,iCAAiC,CAAC;AAClE,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAEvD;;GAEG;AACH,MAAM,MAAM,oBAAoB,GAC5B;IACE;;OAEG;IACH,IAAI,EAAE,YAAY,CAAC;CACpB,GACD;IACE;;OAEG;IACH,OAAO,EAAE;QACP,QAAQ,EAAE,uBAAuB,CAAC;QAClC,MAAM,EAAE,eAAe,CAAC;QACxB,UAAU,EAAE,UAAU,CAAC;KACxB,CAAC;CACH,CAAC"}
1
+ {"version":3,"file":"PackageHashOptions.d.ts","sourceRoot":"","sources":["../../src/types/PackageHashOptions.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,6BAA6B,CAAC;AAC3E,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,4BAA4B,CAAC;AAClE,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,iCAAiC,CAAC;AAClE,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAEvD;;GAEG;AACH,MAAM,MAAM,oBAAoB,GAC5B;IACE;;OAEG;IACH,IAAI,EAAE,YAAY,CAAC;CACpB,GACD;IACE,iFAAiF;IACjF,GAAG,EAAE,MAAM,CAAC;IACZ;;OAEG;IACH,OAAO,EAAE;QACP,QAAQ,EAAE,uBAAuB,CAAC;QAClC,MAAM,EAAE,eAAe,CAAC;QACxB,UAAU,EAAE,UAAU,CAAC;KACxB,CAAC;CACH,CAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"PackageHashOptions.js","sourceRoot":"","sources":["../../src/types/PackageHashOptions.ts"],"names":[],"mappings":"","sourcesContent":["import type { PackageDefinitionsCache } from '@ms-cloudpack/bundler-types';\nimport type { CloudpackConfig } from '@ms-cloudpack/config-types';\nimport type { ResolveMap } from '@ms-cloudpack/package-utilities';\nimport type { HashFunction } from './HashFunctions.js';\n\n/**\n * Options for the PackageHashes class.\n */\nexport type PackageHashesOptions =\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 * Context for the hash calculations.\n */\n context: {\n packages: PackageDefinitionsCache;\n config: CloudpackConfig;\n resolveMap: ResolveMap;\n };\n };\n"]}
1
+ {"version":3,"file":"PackageHashOptions.js","sourceRoot":"","sources":["../../src/types/PackageHashOptions.ts"],"names":[],"mappings":"","sourcesContent":["import type { PackageDefinitionsCache } from '@ms-cloudpack/bundler-types';\nimport type { CloudpackConfig } from '@ms-cloudpack/config-types';\nimport type { ResolveMap } from '@ms-cloudpack/package-utilities';\nimport type { HashFunction } from './HashFunctions.js';\n\n/**\n * Options for the PackageHashes class.\n */\nexport type PackageHashesOptions =\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 /** 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 packages: PackageDefinitionsCache;\n config: CloudpackConfig;\n resolveMap: ResolveMap;\n };\n };\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ms-cloudpack/package-hashes",
3
- "version": "0.3.14",
3
+ "version": "0.3.15",
4
4
  "description": "Utilities for hashing packages.",
5
5
  "license": "MIT",
6
6
  "type": "module",