@ms-cloudpack/package-hashes 0.6.39 → 0.7.1
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/PackageHashes.d.ts +29 -15
- package/lib/PackageHashes.d.ts.map +1 -1
- package/lib/PackageHashes.js +3 -9
- package/lib/PackageHashes.js.map +1 -1
- package/lib/PackagePatchesCache.d.ts +22 -13
- package/lib/PackagePatchesCache.d.ts.map +1 -1
- package/lib/PackagePatchesCache.js +28 -12
- package/lib/PackagePatchesCache.js.map +1 -1
- package/lib/getPackageHashEntries.d.ts +24 -29
- package/lib/getPackageHashEntries.d.ts.map +1 -1
- package/lib/getPackageHashEntries.js +1 -2
- package/lib/getPackageHashEntries.js.map +1 -1
- package/lib/getSourceHash.d.ts +7 -5
- package/lib/getSourceHash.d.ts.map +1 -1
- package/lib/getSourceHash.js +7 -6
- package/lib/getSourceHash.js.map +1 -1
- package/lib/hashPackage.d.ts +4 -6
- package/lib/hashPackage.d.ts.map +1 -1
- package/lib/hashPackage.js.map +1 -1
- package/lib/index.d.ts +0 -2
- package/lib/index.d.ts.map +1 -1
- package/lib/index.js.map +1 -1
- package/lib/parsePatchFilePath.d.ts +2 -2
- package/lib/parsePatchFilePath.d.ts.map +1 -1
- package/lib/parsePatchFilePath.js +8 -10
- package/lib/parsePatchFilePath.js.map +1 -1
- package/lib/types/HashFunction.d.ts +4 -4
- package/lib/types/HashFunction.d.ts.map +1 -1
- package/lib/types/HashFunction.js.map +1 -1
- package/package.json +4 -4
- package/lib/getPatchFileContent.d.ts +0 -9
- package/lib/getPatchFileContent.d.ts.map +0 -1
- package/lib/getPatchFileContent.js +0 -16
- package/lib/getPatchFileContent.js.map +0 -1
- package/lib/types/PackageHashOptions.d.ts +0 -24
- package/lib/types/PackageHashOptions.d.ts.map +0 -1
- package/lib/types/PackageHashOptions.js +0 -2
- package/lib/types/PackageHashOptions.js.map +0 -1
- package/lib/types/PackagePatches.d.ts +0 -4
- package/lib/types/PackagePatches.d.ts.map +0 -1
- package/lib/types/PackagePatches.js +0 -2
- package/lib/types/PackagePatches.js.map +0 -1
package/lib/PackageHashes.d.ts
CHANGED
|
@@ -1,25 +1,39 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { CloudpackConfig, PackageDefinitionsCache, PackageHashOptions, PackageHashesCache, ResolveMap } from '@ms-cloudpack/common-types';
|
|
2
|
+
import type { HashFunction } from './types/HashFunction.js';
|
|
3
|
+
/**
|
|
4
|
+
* Constructor options for the PackageHashes class.
|
|
5
|
+
*
|
|
6
|
+
* (For `PackageHashes.get` options, see `PackageHashOptions`.)
|
|
7
|
+
*/
|
|
8
|
+
type PackageHashesOptions = {
|
|
9
|
+
/** Working directory used to find the project root (usually repository root). */
|
|
10
|
+
cwd: string;
|
|
11
|
+
/**
|
|
12
|
+
* Context for the hash calculations.
|
|
13
|
+
*/
|
|
14
|
+
context: {
|
|
15
|
+
config: Pick<CloudpackConfig, 'patchFilesGlobPattern'>;
|
|
16
|
+
packages: PackageDefinitionsCache;
|
|
17
|
+
resolveMap: ResolveMap;
|
|
18
|
+
};
|
|
19
|
+
} | {
|
|
20
|
+
/**
|
|
21
|
+
* A function that returns the hash for a given package path. This is intended for testing purposes.
|
|
22
|
+
*/
|
|
23
|
+
hash: HashFunction;
|
|
24
|
+
};
|
|
2
25
|
/**
|
|
3
26
|
* Utility class for hashing packages and caching the results.
|
|
4
27
|
*/
|
|
5
|
-
export declare class PackageHashes {
|
|
28
|
+
export declare class PackageHashes implements PackageHashesCache {
|
|
6
29
|
readonly options: PackageHashesOptions;
|
|
30
|
+
/** Mapping from package path to hash (considering source files) */
|
|
7
31
|
private readonly _hashesWithSource;
|
|
32
|
+
/** Mapping from package path to hash (not considering source files) */
|
|
8
33
|
private readonly _hashesWithNoSource;
|
|
9
34
|
private readonly _hash;
|
|
10
35
|
constructor(options: PackageHashesOptions);
|
|
11
|
-
|
|
12
|
-
* Gets the hash for a given package path. This is useful for caching, to determine if the package has changed.
|
|
13
|
-
* If the package definition has not been calculated, it will be calculated and cached.
|
|
14
|
-
* @param packagePath - The package path to get the hash for.
|
|
15
|
-
* @param isSourceHashingEnabled - Whether or not to hash the source files.
|
|
16
|
-
* @param shouldRecalculate - Whether or not to force a re-calculation of the hash.
|
|
17
|
-
* @returns The hash for the package.
|
|
18
|
-
*/
|
|
19
|
-
get(input: {
|
|
20
|
-
packagePath: string;
|
|
21
|
-
isSourceHashingEnabled: boolean;
|
|
22
|
-
shouldRecalculate?: boolean;
|
|
23
|
-
}): Promise<string>;
|
|
36
|
+
get(input: PackageHashOptions): Promise<string>;
|
|
24
37
|
}
|
|
38
|
+
export {};
|
|
25
39
|
//# sourceMappingURL=PackageHashes.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"PackageHashes.d.ts","sourceRoot":"","sources":["../src/PackageHashes.ts"],"names":[],"mappings":"
|
|
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;AAG5D;;;;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,CAAC,CAAC;QACvD,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;IAsB5C,GAAG,CAAC,KAAK,EAAE,kBAAkB,GAAG,OAAO,CAAC,MAAM,CAAC;CAetD"}
|
package/lib/PackageHashes.js
CHANGED
|
@@ -1,12 +1,14 @@
|
|
|
1
|
-
import { PackagePatchesCache } from './PackagePatchesCache.js';
|
|
2
1
|
import { hashPackage } from './hashPackage.js';
|
|
2
|
+
import { PackagePatchesCache } from './PackagePatchesCache.js';
|
|
3
3
|
/**
|
|
4
4
|
* Utility class for hashing packages and caching the results.
|
|
5
5
|
*/
|
|
6
6
|
export class PackageHashes {
|
|
7
7
|
constructor(options) {
|
|
8
8
|
this.options = options;
|
|
9
|
+
/** Mapping from package path to hash (considering source files) */
|
|
9
10
|
this._hashesWithSource = new Map();
|
|
11
|
+
/** Mapping from package path to hash (not considering source files) */
|
|
10
12
|
this._hashesWithNoSource = new Map();
|
|
11
13
|
if ('hash' in options) {
|
|
12
14
|
this._hash = options.hash;
|
|
@@ -25,14 +27,6 @@ export class PackageHashes {
|
|
|
25
27
|
},
|
|
26
28
|
});
|
|
27
29
|
}
|
|
28
|
-
/**
|
|
29
|
-
* Gets the hash for a given package path. This is useful for caching, to determine if the package has changed.
|
|
30
|
-
* If the package definition has not been calculated, it will be calculated and cached.
|
|
31
|
-
* @param packagePath - The package path to get the hash for.
|
|
32
|
-
* @param isSourceHashingEnabled - Whether or not to hash the source files.
|
|
33
|
-
* @param shouldRecalculate - Whether or not to force a re-calculation of the hash.
|
|
34
|
-
* @returns The hash for the package.
|
|
35
|
-
*/
|
|
36
30
|
async get(input) {
|
|
37
31
|
const { packagePath, isSourceHashingEnabled, shouldRecalculate } = input;
|
|
38
32
|
const map = isSourceHashingEnabled ? this._hashesWithSource : this._hashesWithNoSource;
|
package/lib/PackageHashes.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"PackageHashes.js","sourceRoot":"","sources":["../src/PackageHashes.ts"],"names":[],"mappings":"
|
|
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;AA2B/D;;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;QAEH,IAAI,CAAC,KAAK,GAAG,CAAC,KAAK,EAAE,EAAE,CACrB,WAAW,CAAC;YACV,KAAK;YACL,OAAO,EAAE;gBACP,GAAG,OAAO,CAAC,OAAO;gBAClB,OAAO;aACR;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';\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'>;\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\n this._hash = (input) =>\n hashPackage({\n input,\n context: {\n ...options.context,\n patches,\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"]}
|
|
@@ -1,33 +1,42 @@
|
|
|
1
|
-
import type { PackagePatches } from './types/PackagePatches.js';
|
|
2
1
|
export interface PackagePatchesSettings {
|
|
3
2
|
/** Working directory, used to determine the project root where patches are stored. */
|
|
4
3
|
cwd: string;
|
|
4
|
+
/** Custom glob pattern for patch files (from `AppConfig.patchFilesGlobPattern`). */
|
|
5
5
|
globPattern?: string;
|
|
6
|
+
/** Patches to use instead of reading from disk (for testing). */
|
|
7
|
+
patches?: Record<`${string}@${string}`, PackagePatch>;
|
|
8
|
+
}
|
|
9
|
+
interface PackagePatch {
|
|
10
|
+
path: string;
|
|
11
|
+
contents?: string;
|
|
6
12
|
}
|
|
7
13
|
/**
|
|
8
|
-
* PackagePatchesCache
|
|
9
|
-
*
|
|
10
|
-
*
|
|
11
|
-
* based on the package name and version.
|
|
12
|
-
*
|
|
13
|
-
* @class PackagePatchesCache
|
|
14
|
-
* @implements {PackagePatches}
|
|
14
|
+
* 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.
|
|
15
17
|
*/
|
|
16
|
-
export declare class PackagePatchesCache
|
|
18
|
+
export declare class PackagePatchesCache {
|
|
17
19
|
private readonly settings;
|
|
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).
|
|
24
|
+
*/
|
|
18
25
|
private _patches;
|
|
19
26
|
constructor(settings: PackagePatchesSettings);
|
|
20
27
|
private getKey;
|
|
21
28
|
/**
|
|
22
|
-
* Loads the list of patched packages from the patches folder.
|
|
29
|
+
* Loads the list of patched packages from the `patches` folder.
|
|
23
30
|
*/
|
|
24
31
|
private loadPatchedPackages;
|
|
32
|
+
private readPatchFile;
|
|
25
33
|
/**
|
|
26
|
-
* Gets
|
|
34
|
+
* Gets info about the patch file for the specified package.
|
|
27
35
|
* @param packageName - The name of the package to check.
|
|
28
36
|
* @param version - The version of the package to check.
|
|
29
|
-
* @returns
|
|
37
|
+
* @returns Patch file path and contents if the package has been patched, undefined otherwise.
|
|
30
38
|
*/
|
|
31
|
-
getPackagePatch(packageName: string, version: string): Promise<
|
|
39
|
+
getPackagePatch(packageName: string, version: string): Promise<PackagePatch | undefined>;
|
|
32
40
|
}
|
|
41
|
+
export {};
|
|
33
42
|
//# sourceMappingURL=PackagePatchesCache.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"PackagePatchesCache.d.ts","sourceRoot":"","sources":["../src/PackagePatchesCache.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"PackagePatchesCache.d.ts","sourceRoot":"","sources":["../src/PackagePatchesCache.ts"],"names":[],"mappings":"AAMA,MAAM,WAAW,sBAAsB;IACrC,sFAAsF;IACtF,GAAG,EAAE,MAAM,CAAC;IAEZ,oFAAoF;IACpF,WAAW,CAAC,EAAE,MAAM,CAAC;IAErB,iEAAiE;IACjE,OAAO,CAAC,EAAE,MAAM,CAAC,GAAG,MAAM,IAAI,MAAM,EAAE,EAAE,YAAY,CAAC,CAAC;CACvD;AAED,UAAU,YAAY;IACpB,IAAI,EAAE,MAAM,CAAC;IACb,QAAQ,CAAC,EAAE,MAAM,CAAC;CACnB;AAED;;;;GAIG;AACH,qBAAa,mBAAmB;IAQlB,OAAO,CAAC,QAAQ,CAAC,QAAQ;IAPrC;;;;OAIG;IACH,OAAO,CAAC,QAAQ,CAA0D;gBAE7C,QAAQ,EAAE,sBAAsB;IAE7D,OAAO,CAAC,MAAM;IAId;;OAEG;YACW,mBAAmB;YAqCnB,aAAa;IAS3B;;;;;OAKG;IACU,eAAe,CAAC,WAAW,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,YAAY,GAAG,SAAS,CAAC;CAetG"}
|
|
@@ -1,15 +1,12 @@
|
|
|
1
1
|
import { findProjectRoot } from '@ms-cloudpack/package-utilities';
|
|
2
|
+
import fsPromises from 'fs/promises';
|
|
2
3
|
import glob from 'fast-glob';
|
|
3
4
|
import path from 'path';
|
|
4
5
|
import { parsePatchFilePath } from './parsePatchFilePath.js';
|
|
5
6
|
/**
|
|
6
|
-
* PackagePatchesCache
|
|
7
|
-
*
|
|
8
|
-
*
|
|
9
|
-
* based on the package name and version.
|
|
10
|
-
*
|
|
11
|
-
* @class PackagePatchesCache
|
|
12
|
-
* @implements {PackagePatches}
|
|
7
|
+
* 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.
|
|
13
10
|
*/
|
|
14
11
|
export class PackagePatchesCache {
|
|
15
12
|
constructor(settings) {
|
|
@@ -19,9 +16,13 @@ export class PackagePatchesCache {
|
|
|
19
16
|
return `${packageName}@${version}`;
|
|
20
17
|
}
|
|
21
18
|
/**
|
|
22
|
-
* Loads the list of patched packages from the patches folder.
|
|
19
|
+
* Loads the list of patched packages from the `patches` folder.
|
|
23
20
|
*/
|
|
24
21
|
async loadPatchedPackages() {
|
|
22
|
+
if (this.settings.patches) {
|
|
23
|
+
this._patches = this.settings.patches;
|
|
24
|
+
return;
|
|
25
|
+
}
|
|
25
26
|
this._patches = {};
|
|
26
27
|
// get the repo root
|
|
27
28
|
const rootPath = findProjectRoot(this.settings.cwd) || this.settings.cwd;
|
|
@@ -39,24 +40,39 @@ export class PackagePatchesCache {
|
|
|
39
40
|
const normalizedPath = path.normalize(absoluteFilePath);
|
|
40
41
|
const { packageName, version } = parsePatchFilePath(normalizedPath);
|
|
41
42
|
console.debug(`Found patch file for package: ${packageName}@${version}`);
|
|
42
|
-
this._patches[this.getKey(packageName, version)] = normalizedPath;
|
|
43
|
+
this._patches[this.getKey(packageName, version)] = { path: normalizedPath };
|
|
43
44
|
}
|
|
44
45
|
catch (e) {
|
|
45
46
|
console.warn(`Invalid patch file "${absoluteFilePath}": ${e}`);
|
|
46
47
|
}
|
|
47
48
|
}
|
|
48
49
|
}
|
|
50
|
+
async readPatchFile(patchFilePath) {
|
|
51
|
+
try {
|
|
52
|
+
return await fsPromises.readFile(patchFilePath, 'utf-8');
|
|
53
|
+
}
|
|
54
|
+
catch (e) {
|
|
55
|
+
console.warn(`Error reading patch file "${patchFilePath}": ${e}`);
|
|
56
|
+
return '';
|
|
57
|
+
}
|
|
58
|
+
}
|
|
49
59
|
/**
|
|
50
|
-
* Gets
|
|
60
|
+
* Gets info about the patch file for the specified package.
|
|
51
61
|
* @param packageName - The name of the package to check.
|
|
52
62
|
* @param version - The version of the package to check.
|
|
53
|
-
* @returns
|
|
63
|
+
* @returns Patch file path and contents if the package has been patched, undefined otherwise.
|
|
54
64
|
*/
|
|
55
65
|
async getPackagePatch(packageName, version) {
|
|
56
66
|
if (!this._patches) {
|
|
57
67
|
await this.loadPatchedPackages();
|
|
58
68
|
}
|
|
59
|
-
|
|
69
|
+
const patchInfo = this._patches?.[this.getKey(packageName, version)];
|
|
70
|
+
if (patchInfo) {
|
|
71
|
+
// The contents are lazy loaded
|
|
72
|
+
patchInfo.contents ??= await this.readPatchFile(patchInfo.path);
|
|
73
|
+
return patchInfo;
|
|
74
|
+
}
|
|
75
|
+
return undefined;
|
|
60
76
|
}
|
|
61
77
|
}
|
|
62
78
|
//# sourceMappingURL=PackagePatchesCache.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"PackagePatchesCache.js","sourceRoot":"","sources":["../src/PackagePatch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,CAAC,MAAM,CAAC,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/package-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() {\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,37 +1,32 @@
|
|
|
1
|
-
import type { PackageDefinitionsCache } from '@ms-cloudpack/common-types';
|
|
2
|
-
import type {
|
|
1
|
+
import type { PackageDefinitionsCache, PackageJson, PackageJsonDependencies, PackageJsonExports } from '@ms-cloudpack/common-types';
|
|
2
|
+
import type { HashFunctionOptions } from './types/HashFunction.js';
|
|
3
|
+
import { type FilesHash } from './getSourceHash.js';
|
|
4
|
+
import type { PackagePatchesCache } from './PackagePatchesCache.js';
|
|
5
|
+
/**
|
|
6
|
+
* Values used to calculate the hash of a package.
|
|
7
|
+
*/
|
|
8
|
+
export interface PackageHashEntries {
|
|
9
|
+
name: string;
|
|
10
|
+
/** This will be the actual version if the package is external, or the path if it's internal. */
|
|
11
|
+
version: string;
|
|
12
|
+
exports: PackageJsonExports | undefined;
|
|
13
|
+
dependencies: PackageJsonDependencies | undefined;
|
|
14
|
+
peerDependencies: PackageJsonDependencies | undefined;
|
|
15
|
+
/** Hash of files in the package. */
|
|
16
|
+
filesHash: FilesHash | undefined;
|
|
17
|
+
/** Content of any `.patch` file for the package. */
|
|
18
|
+
patchFileContent: string | undefined;
|
|
19
|
+
/** Subset of calculated package settings and other info saved under `PackageJson.cloudpack`. */
|
|
20
|
+
packageSettings: Partial<NonNullable<PackageJson['cloudpack']>>;
|
|
21
|
+
}
|
|
3
22
|
/**
|
|
4
23
|
* Get an object that's used to calculate the hash of the package.
|
|
5
24
|
*/
|
|
6
25
|
export declare function getPackageHashEntries(params: {
|
|
7
|
-
options:
|
|
8
|
-
packagePath: string;
|
|
9
|
-
isSourceHashingEnabled: boolean;
|
|
10
|
-
};
|
|
26
|
+
options: HashFunctionOptions;
|
|
11
27
|
context: {
|
|
12
28
|
packages: PackageDefinitionsCache;
|
|
13
|
-
patches:
|
|
14
|
-
};
|
|
15
|
-
}): Promise<{
|
|
16
|
-
exports: import("@ms-cloudpack/common-types").PackageJsonExports | undefined;
|
|
17
|
-
dependencies: Partial<Record<string, string>> | undefined;
|
|
18
|
-
peerDependencies: Partial<Record<string, string>> | undefined;
|
|
19
|
-
name: string;
|
|
20
|
-
version: string;
|
|
21
|
-
filesHash: Record<string, string | null | undefined> | null | undefined;
|
|
22
|
-
patchFileContent: string | undefined;
|
|
23
|
-
packageSettings: {
|
|
24
|
-
inputPaths?: string[];
|
|
25
|
-
link?: import("@ms-cloudpack/common-types").LinkOptions;
|
|
26
|
-
inlinedDependencies?: string[];
|
|
27
|
-
bundler?: string;
|
|
28
|
-
bundlerType?: string;
|
|
29
|
-
bundlerOptions?: Record<string, unknown>;
|
|
30
|
-
ignoreMissingExports?: boolean | Record<string, string[]>;
|
|
31
|
-
dynamicImports?: string[];
|
|
32
|
-
ignoredBundlerWarnings?: string[];
|
|
33
|
-
bundlerCapabilities?: import("@ms-cloudpack/common-types").BundlerCapabilitiesOptions;
|
|
34
|
-
mode?: import("@ms-cloudpack/common-types").BundleMode | undefined;
|
|
29
|
+
patches: PackagePatchesCache;
|
|
35
30
|
};
|
|
36
|
-
}>;
|
|
31
|
+
}): Promise<PackageHashEntries>;
|
|
37
32
|
//# sourceMappingURL=getPackageHashEntries.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getPackageHashEntries.d.ts","sourceRoot":"","sources":["../src/getPackageHashEntries.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,
|
|
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;AAEpE;;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;CACjE;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;KAC9B,CAAC;CACH,GAAG,OAAO,CAAC,kBAAkB,CAAC,CAqC9B"}
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { isExternalPackage } from '@ms-cloudpack/package-utilities';
|
|
2
2
|
import { getSourceHash } from './getSourceHash.js';
|
|
3
|
-
import { getPatchFileContent } from './getPatchFileContent.js';
|
|
4
3
|
/**
|
|
5
4
|
* Get an object that's used to calculate the hash of the package.
|
|
6
5
|
*/
|
|
@@ -17,7 +16,7 @@ export async function getPackageHashEntries(params) {
|
|
|
17
16
|
const filesHash = !isExternal && isSourceHashingEnabled
|
|
18
17
|
? await getSourceHash({ packagePath, inputPaths: packageSettings.inputPaths })
|
|
19
18
|
: undefined;
|
|
20
|
-
const patchFileContent = isExternal ? await
|
|
19
|
+
const patchFileContent = isExternal ? (await patches.getPackagePatch(name, version))?.contents : undefined;
|
|
21
20
|
// Only include a subset of package.json properties to reduce the amount hashed.
|
|
22
21
|
return {
|
|
23
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":"
|
|
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;AAqBnE;;GAEG;AACH,MAAM,CAAC,KAAK,UAAU,qBAAqB,CAAC,MAM3C;IACC,MAAM,EAAE,OAAO,EAAE,OAAO,EAAE,GAAG,MAAM,CAAC;IACpC,MAAM,EAAE,WAAW,EAAE,sBAAsB,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,\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';\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}\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 };\n}): Promise<PackageHashEntries> {\n const { options, context } = params;\n const { packagePath, isSourceHashingEnabled } = options;\n const { packages, patches } = 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 return {\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"]}
|
package/lib/getSourceHash.d.ts
CHANGED
|
@@ -1,12 +1,14 @@
|
|
|
1
|
+
import { hash } from 'glob-hasher';
|
|
2
|
+
export type FilesHash = ReturnType<typeof hash>;
|
|
1
3
|
/**
|
|
2
|
-
* Get the hash of the source files in a package
|
|
3
|
-
* If there is
|
|
4
|
-
* If there are inputPaths
|
|
5
|
-
* Otherwise, hash all files except node_modules
|
|
4
|
+
* Get the hash of the source files in a package.
|
|
5
|
+
* - If there is an `src` folder, hash the files in that folder, the `*.json` files and the `inputPaths`.
|
|
6
|
+
* - If there are `inputPaths`, hash only those files.
|
|
7
|
+
* - Otherwise, hash all files except `node_modules`.
|
|
6
8
|
*/
|
|
7
9
|
export declare function getSourceHash(options: {
|
|
8
10
|
packagePath: string;
|
|
9
11
|
/** Input paths from the package settings */
|
|
10
12
|
inputPaths: string[] | undefined;
|
|
11
|
-
}): Promise<
|
|
13
|
+
}): Promise<FilesHash>;
|
|
12
14
|
//# sourceMappingURL=getSourceHash.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getSourceHash.d.ts","sourceRoot":"","sources":["../src/getSourceHash.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"getSourceHash.d.ts","sourceRoot":"","sources":["../src/getSourceHash.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,IAAI,EAAE,MAAM,aAAa,CAAC;AAKnC,MAAM,MAAM,SAAS,GAAG,UAAU,CAAC,OAAO,IAAI,CAAC,CAAC;AAEhD;;;;;GAKG;AACH,wBAAsB,aAAa,CAAC,OAAO,EAAE;IAC3C,WAAW,EAAE,MAAM,CAAC;IACpB,4CAA4C;IAC5C,UAAU,EAAE,MAAM,EAAE,GAAG,SAAS,CAAC;CAClC,GAAG,OAAO,CAAC,SAAS,CAAC,CA6BrB"}
|
package/lib/getSourceHash.js
CHANGED
|
@@ -5,24 +5,25 @@ import { hash } from 'glob-hasher';
|
|
|
5
5
|
import path from 'path';
|
|
6
6
|
const excludeNodeModules = '!**/node_modules/**';
|
|
7
7
|
/**
|
|
8
|
-
* Get the hash of the source files in a package
|
|
9
|
-
* If there is
|
|
10
|
-
* If there are inputPaths
|
|
11
|
-
* Otherwise, hash all files except node_modules
|
|
8
|
+
* Get the hash of the source files in a package.
|
|
9
|
+
* - If there is an `src` folder, hash the files in that folder, the `*.json` files and the `inputPaths`.
|
|
10
|
+
* - If there are `inputPaths`, hash only those files.
|
|
11
|
+
* - Otherwise, hash all files except `node_modules`.
|
|
12
12
|
*/
|
|
13
13
|
export async function getSourceHash(options) {
|
|
14
14
|
const start = performance.now();
|
|
15
15
|
const { packagePath, inputPaths } = options;
|
|
16
|
-
// Use the inputPaths if they are defined, otherwise use the src folder if it exists
|
|
17
|
-
// Otherwise, use all files except node_modules
|
|
18
16
|
let patterns;
|
|
19
17
|
if (inputPaths?.length) {
|
|
18
|
+
// Use the inputPaths if they are defined
|
|
20
19
|
patterns = inputPaths;
|
|
21
20
|
}
|
|
22
21
|
else if (existsSync(path.join(packagePath, 'src'))) {
|
|
22
|
+
// Otherwise, use the src folder (and *.json files) if it exists
|
|
23
23
|
patterns = ['src/**', '*.json', excludeNodeModules];
|
|
24
24
|
}
|
|
25
25
|
else {
|
|
26
|
+
// Otherwise, use all files except node_modules
|
|
26
27
|
patterns = ['**', excludeNodeModules];
|
|
27
28
|
}
|
|
28
29
|
const files = await glob(patterns, {
|
package/lib/getSourceHash.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getSourceHash.js","sourceRoot":"","sources":["../src/getSourceHash.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,uBAAuB,EAAE,MAAM,sBAAsB,CAAC;AAClF,OAAO,IAAI,MAAM,WAAW,CAAC;AAC7B,OAAO,EAAE,UAAU,EAAE,MAAM,IAAI,CAAC;AAChC,OAAO,EAAE,IAAI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D,CAAC,CAAC;IAEH,MAAM,QAAQ,GAAG,IAAI,CAAC,KAAK,EAAE,EAAE,GAAG,EAAE,WAAW,EAAE,CAAC,CAAC;IAEnD,OAAO,CAAC,KAAK,CAAC,0BAA0B,WAAW,OAAO,WAAW,CAAC,GAAG,EAAE,GAAG,KAAK,IAAI,CAAC,CAAC;IAEzF,OAAO,QAAQ,CAAC;AAClB,CAAC","sourcesContent":["import { appConfigFileName, generatedConfigFileName } from '@ms-cloudpack/config';\nimport glob from 'fast-glob';\nimport { existsSync } from 'fs';\nimport { hash } from 'glob-hasher';\nimport path from 'path';\n\nconst excludeNodeModules = '!**/node_modules/**';\n\nexport type FilesHash = ReturnType<typeof hash>;\n\n/**\n * Get the hash of the source files in a package.\n * - If there is an `src` folder, hash the files in that folder, the `*.json` files and the `inputPaths`.\n * - If there are `inputPaths`, hash only those files.\n * - Otherwise, hash all files except `node_modules`.\n */\nexport async function getSourceHash(options: {\n packagePath: string;\n /** Input paths from the package settings */\n inputPaths: string[] | undefined;\n}): Promise<FilesHash> {\n const start = performance.now();\n\n const { packagePath, inputPaths } = options;\n let patterns: string[];\n if (inputPaths?.length) {\n // Use the inputPaths if they are defined\n patterns = inputPaths;\n } else if (existsSync(path.join(packagePath, 'src'))) {\n // Otherwise, use the src folder (and *.json files) if it exists\n patterns = ['src/**', '*.json', excludeNodeModules];\n } else {\n // Otherwise, use all files except node_modules\n patterns = ['**', excludeNodeModules];\n }\n\n const files = await glob(patterns, {\n cwd: packagePath,\n // We want to ignore the app config and generated config files because they are not part of the source code.\n // Ignoring the generated config is especially important because it changes during init,\n // and it would invalidate the cache for the entry package with the generated config.\n ignore: [appConfigFileName, generatedConfigFileName],\n });\n\n const globHash = hash(files, { cwd: packagePath });\n\n console.debug(`Hashed source files in ${packagePath} in ${performance.now() - start}ms`);\n\n return globHash;\n}\n"]}
|
package/lib/hashPackage.d.ts
CHANGED
|
@@ -1,15 +1,13 @@
|
|
|
1
1
|
import type { PackageDefinitionsCache } from '@ms-cloudpack/common-types';
|
|
2
2
|
import { type ResolveMap } from '@ms-cloudpack/package-utilities';
|
|
3
|
-
import type {
|
|
3
|
+
import type { PackagePatchesCache } from './PackagePatchesCache.js';
|
|
4
|
+
import type { HashFunctionOptions } from './types/HashFunction.js';
|
|
4
5
|
export declare function hashPackage(params: {
|
|
5
|
-
input:
|
|
6
|
-
packagePath: string;
|
|
7
|
-
isSourceHashingEnabled: boolean;
|
|
8
|
-
};
|
|
6
|
+
input: HashFunctionOptions;
|
|
9
7
|
context: {
|
|
10
8
|
packages: PackageDefinitionsCache;
|
|
11
9
|
resolveMap: ResolveMap;
|
|
12
|
-
patches:
|
|
10
|
+
patches: PackagePatchesCache;
|
|
13
11
|
};
|
|
14
12
|
}): Promise<string>;
|
|
15
13
|
//# 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,
|
|
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;AAInE,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;KAC9B,CAAC;CACH,GAAG,OAAO,CAAC,MAAM,CAAC,CAgDlB"}
|
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,EAAE,MAAM,4BAA4B,CAAC;AACnE,OAAO,EAAE,2BAA2B,EAAE,MAAM,kCAAkC,CAAC;AAE/E,OAAO,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;
|
|
1
|
+
{"version":3,"file":"hashPackage.js","sourceRoot":"","sources":["../src/hashPackage.ts"],"names":[],"mappings":"AAEA,OAAO,UAAU,MAAM,aAAa,CAAC;AACrC,OAAO,EAAE,qBAAqB,EAAE,MAAM,4BAA4B,CAAC;AACnE,OAAO,EAAE,2BAA2B,EAAE,MAAM,kCAAkC,CAAC;AAE/E,OAAO,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAG/C,IAAI,SAAS,GAAG,CAAC,CAAC;AAElB,MAAM,CAAC,KAAK,UAAU,WAAW,CAAC,MAOjC;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,GAAG,OAAO,CAAC;IAClD,MAAM,gBAAgB,GAAwD,EAAE,CAAC;IACjF,MAAM,cAAc,GAAa,CAAC,WAAW,CAAC,CAAC;IAE/C,OAAO,cAAc,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;QACjC,MAAM,aAAa,GAAG,cAAc,CAAC,GAAG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ache } from '@ms-cloudpack/common-types';\nimport { type ResolveMap } from '@ms-cloudpack/package-utilities';\nimport objectHash from 'object-hash';\nimport { getPackageHashEntries } 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';\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 };\n}): Promise<string> {\n const start = performance.now();\n const { input, context } = params;\n const { packagePath, isSourceHashingEnabled } = input;\n const { resolveMap, packages, patches } = context;\n const hashEntriesArray: Awaited<ReturnType<typeof getPackageHashEntries>>[] = [];\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 },\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/lib/index.d.ts
CHANGED
package/lib/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC"}
|
package/lib/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC","sourcesContent":["export { PackageHashes } from './PackageHashes.js';\
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC","sourcesContent":["export { PackageHashes } from './PackageHashes.js';\n"]}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Parses a patch file name and returns the package name and version
|
|
3
|
-
* @param filePath - The path of the patch file (e.g. users/test/repo/my-repo/patches/@fluentui+react-combobox+9.5.28.patch)
|
|
4
|
-
* @returns An object with the package name and version (e.g. { packageName: '@fluentui/react-combobox', version: '9.5.28' })
|
|
3
|
+
* @param filePath - The path of the patch file (e.g. `users/test/repo/my-repo/patches/@fluentui+react-combobox+9.5.28.patch`)
|
|
4
|
+
* @returns An object with the package name and version (e.g. `{ packageName: '@fluentui/react-combobox', version: '9.5.28' }`)
|
|
5
5
|
*/
|
|
6
6
|
export declare function parsePatchFilePath(filePath: string): {
|
|
7
7
|
packageName: string;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"parsePatchFilePath.d.ts","sourceRoot":"","sources":["../src/parsePatchFilePath.ts"],"names":[],"mappings":"AAEA;;;;GAIG;AACH,wBAAgB,kBAAkB,CAAC,QAAQ,EAAE,MAAM,GAAG;IAAE,WAAW,EAAE,MAAM,CAAC;IAAC,OAAO,EAAE,MAAM,CAAA;CAAE,
|
|
1
|
+
{"version":3,"file":"parsePatchFilePath.d.ts","sourceRoot":"","sources":["../src/parsePatchFilePath.ts"],"names":[],"mappings":"AAEA;;;;GAIG;AACH,wBAAgB,kBAAkB,CAAC,QAAQ,EAAE,MAAM,GAAG;IAAE,WAAW,EAAE,MAAM,CAAC;IAAC,OAAO,EAAE,MAAM,CAAA;CAAE,CAqB7F"}
|
|
@@ -1,25 +1,23 @@
|
|
|
1
1
|
import path from 'path';
|
|
2
2
|
/**
|
|
3
3
|
* Parses a patch file name and returns the package name and version
|
|
4
|
-
* @param filePath - The path of the patch file (e.g. users/test/repo/my-repo/patches/@fluentui+react-combobox+9.5.28.patch)
|
|
5
|
-
* @returns An object with the package name and version (e.g. { packageName: '@fluentui/react-combobox', version: '9.5.28' })
|
|
4
|
+
* @param filePath - The path of the patch file (e.g. `users/test/repo/my-repo/patches/@fluentui+react-combobox+9.5.28.patch`)
|
|
5
|
+
* @returns An object with the package name and version (e.g. `{ packageName: '@fluentui/react-combobox', version: '9.5.28' }`)
|
|
6
6
|
*/
|
|
7
7
|
export function parsePatchFilePath(filePath) {
|
|
8
|
-
const fileName = path.basename(filePath);
|
|
8
|
+
const fileName = path.basename(filePath, '.patch');
|
|
9
9
|
// Split the packageString based on '+'
|
|
10
|
-
const parts = fileName.
|
|
10
|
+
const parts = fileName.split('+');
|
|
11
11
|
// If the parts array doesn't have the expected length throw an error
|
|
12
12
|
if (parts.length < 2) {
|
|
13
|
-
throw new Error(`Invalid patch file name: ${fileName}
|
|
13
|
+
throw new Error(`Invalid patch file name: "${fileName}" - it should contain the package name and version separated by '+'`);
|
|
14
14
|
}
|
|
15
|
-
// Extract the
|
|
15
|
+
// Extract the package name and version
|
|
16
16
|
const version = parts[parts.length - 1];
|
|
17
|
-
const packageName = parts.slice(0,
|
|
18
|
-
|
|
19
|
-
const result = {
|
|
17
|
+
const packageName = parts.slice(0, -1).join('/');
|
|
18
|
+
return {
|
|
20
19
|
packageName,
|
|
21
20
|
version,
|
|
22
21
|
};
|
|
23
|
-
return result;
|
|
24
22
|
}
|
|
25
23
|
//# sourceMappingURL=parsePatchFilePath.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"parsePatchFilePath.js","sourceRoot":"","sources":["../src/parsePatchFilePath.ts"],"names":[],"mappings":"AAAA,OAAO,IAAI,MAAM,MAAM,CAAC;AAExB;;;;GAIG;AACH,MAAM,UAAU,kBAAkB,CAAC,QAAgB;IACjD,MAAM,QAAQ,GAAG,IAAI,CAAC,QAAQ,CAAC,QAAQ,CAAC,CAAC;
|
|
1
|
+
{"version":3,"file":"parsePatchFilePath.js","sourceRoot":"","sources":["../src/parsePatchFilePath.ts"],"names":[],"mappings":"AAAA,OAAO,IAAI,MAAM,MAAM,CAAC;AAExB;;;;GAIG;AACH,MAAM,UAAU,kBAAkB,CAAC,QAAgB;IACjD,MAAM,QAAQ,GAAG,IAAI,CAAC,QAAQ,CAAC,QAAQ,EAAE,QAAQ,CAAC,CAAC;IAEnD,uCAAuC;IACvC,MAAM,KAAK,GAAG,QAAQ,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;IAElC,qEAAqE;IACrE,IAAI,KAAK,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;QACrB,MAAM,IAAI,KAAK,CACb,6BAA6B,QAAQ,qEAAqE,CAC3G,CAAC;IACJ,CAAC;IAED,uCAAuC;IACvC,MAAM,OAAO,GAAG,KAAK,CAAC,KAAK,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC;IACxC,MAAM,WAAW,GAAG,KAAK,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;IAEjD,OAAO;QACL,WAAW;QACX,OAAO;KACR,CAAC;AACJ,CAAC","sourcesContent":["import path from 'path';\n\n/**\n * Parses a patch file name and returns the package name and version\n * @param filePath - The path of the patch file (e.g. `users/test/repo/my-repo/patches/@fluentui+react-combobox+9.5.28.patch`)\n * @returns An object with the package name and version (e.g. `{ packageName: '@fluentui/react-combobox', version: '9.5.28' }`)\n */\nexport function parsePatchFilePath(filePath: string): { packageName: string; version: string } {\n const fileName = path.basename(filePath, '.patch');\n\n // Split the packageString based on '+'\n const parts = fileName.split('+');\n\n // If the parts array doesn't have the expected length throw an error\n if (parts.length < 2) {\n throw new Error(\n `Invalid patch file name: \"${fileName}\" - it should contain the package name and version separated by '+'`,\n );\n }\n\n // Extract the package name and version\n const version = parts[parts.length - 1];\n const packageName = parts.slice(0, -1).join('/');\n\n return {\n packageName,\n version,\n };\n}\n"]}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
1
|
+
import type { PackageHashOptions } from '@ms-cloudpack/common-types';
|
|
2
|
+
export type HashFunctionOptions = Omit<PackageHashOptions, 'shouldRecalculate'>;
|
|
3
|
+
/** Function for hashing a package. */
|
|
4
|
+
export type HashFunction = (params: HashFunctionOptions) => Promise<string>;
|
|
5
5
|
//# sourceMappingURL=HashFunction.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"HashFunction.d.ts","sourceRoot":"","sources":["../../src/types/HashFunction.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,
|
|
1
|
+
{"version":3,"file":"HashFunction.d.ts","sourceRoot":"","sources":["../../src/types/HashFunction.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,4BAA4B,CAAC;AAErE,MAAM,MAAM,mBAAmB,GAAG,IAAI,CAAC,kBAAkB,EAAE,mBAAmB,CAAC,CAAC;AAEhF,sCAAsC;AACtC,MAAM,MAAM,YAAY,GAAG,CAAC,MAAM,EAAE,mBAAmB,KAAK,OAAO,CAAC,MAAM,CAAC,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"HashFunction.js","sourceRoot":"","sources":["../../src/types/HashFunction.ts"],"names":[],"mappings":"","sourcesContent":["
|
|
1
|
+
{"version":3,"file":"HashFunction.js","sourceRoot":"","sources":["../../src/types/HashFunction.ts"],"names":[],"mappings":"","sourcesContent":["import type { PackageHashOptions } from '@ms-cloudpack/common-types';\n\nexport type HashFunctionOptions = Omit<PackageHashOptions, 'shouldRecalculate'>;\n\n/** Function for hashing a package. */\nexport type HashFunction = (params: HashFunctionOptions) => Promise<string>;\n"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ms-cloudpack/package-hashes",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.7.1",
|
|
4
4
|
"description": "Utilities for hashing packages.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"type": "module",
|
|
@@ -14,9 +14,9 @@
|
|
|
14
14
|
}
|
|
15
15
|
},
|
|
16
16
|
"dependencies": {
|
|
17
|
-
"@ms-cloudpack/common-types": "^0.
|
|
18
|
-
"@ms-cloudpack/config": "^0.31.
|
|
19
|
-
"@ms-cloudpack/package-utilities": "^10.2.
|
|
17
|
+
"@ms-cloudpack/common-types": "^0.22.0",
|
|
18
|
+
"@ms-cloudpack/config": "^0.31.3",
|
|
19
|
+
"@ms-cloudpack/package-utilities": "^10.2.3",
|
|
20
20
|
"fast-glob": "^3.2.12",
|
|
21
21
|
"glob-hasher": "^1.4.2",
|
|
22
22
|
"object-hash": "^3.0.0"
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
import type { PackagePatches } from './types/PackagePatches.js';
|
|
2
|
-
/**
|
|
3
|
-
* Finds a .patch file for a package and returns its hash.
|
|
4
|
-
* @param packageName - the name of the package
|
|
5
|
-
* @param version - the version of the package
|
|
6
|
-
* @returns the hash of the .patch file for the package, or undefined if no .patch file exists
|
|
7
|
-
*/
|
|
8
|
-
export declare function getPatchFileContent(patches: PackagePatches, packageName: string, version: string): Promise<string | undefined>;
|
|
9
|
-
//# sourceMappingURL=getPatchFileContent.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"getPatchFileContent.d.ts","sourceRoot":"","sources":["../src/getPatchFileContent.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,2BAA2B,CAAC;AAGhE;;;;;GAKG;AACH,wBAAsB,mBAAmB,CAAC,OAAO,EAAE,cAAc,EAAE,WAAW,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,+BAUtG"}
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
import { readFile } from 'fs/promises';
|
|
2
|
-
/**
|
|
3
|
-
* Finds a .patch file for a package and returns its hash.
|
|
4
|
-
* @param packageName - the name of the package
|
|
5
|
-
* @param version - the version of the package
|
|
6
|
-
* @returns the hash of the .patch file for the package, or undefined if no .patch file exists
|
|
7
|
-
*/
|
|
8
|
-
export async function getPatchFileContent(patches, packageName, version) {
|
|
9
|
-
const patchFilePath = await patches.getPackagePatch(packageName, version);
|
|
10
|
-
if (!patchFilePath) {
|
|
11
|
-
return undefined;
|
|
12
|
-
}
|
|
13
|
-
const patchFileHash = await readFile(patchFilePath, 'utf-8');
|
|
14
|
-
return patchFileHash;
|
|
15
|
-
}
|
|
16
|
-
//# sourceMappingURL=getPatchFileContent.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"getPatchFileContent.js","sourceRoot":"","sources":["../src/getPatchFileContent.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AAEvC;;;;;GAKG;AACH,MAAM,CAAC,KAAK,UAAU,mBAAmB,CAAC,OAAuB,EAAE,WAAmB,EAAE,OAAe;IACrG,MAAM,aAAa,GAAG,MAAM,OAAO,CAAC,eAAe,CAAC,WAAW,EAAE,OAAO,CAAC,CAAC;IAE1E,IAAI,CAAC,aAAa,EAAE,CAAC;QACnB,OAAO,SAAS,CAAC;IACnB,CAAC;IAED,MAAM,aAAa,GAAG,MAAM,QAAQ,CAAC,aAAa,EAAE,OAAO,CAAC,CAAC;IAE7D,OAAO,aAAa,CAAC;AACvB,CAAC","sourcesContent":["import type { PackagePatches } from './types/PackagePatches.js';\nimport { readFile } from 'fs/promises';\n\n/**\n * Finds a .patch file for a package and returns its hash.\n * @param packageName - the name of the package\n * @param version - the version of the package\n * @returns the hash of the .patch file for the package, or undefined if no .patch file exists\n */\nexport async function getPatchFileContent(patches: PackagePatches, packageName: string, version: string) {\n const patchFilePath = await patches.getPackagePatch(packageName, version);\n\n if (!patchFilePath) {\n return undefined;\n }\n\n const patchFileHash = await readFile(patchFilePath, 'utf-8');\n\n return patchFileHash;\n}\n"]}
|
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
import type { CloudpackConfig, PackageDefinitionsCache } from '@ms-cloudpack/common-types';
|
|
2
|
-
import type { HashFunction } from './HashFunction.js';
|
|
3
|
-
import type { ResolveMap } from '@ms-cloudpack/package-utilities';
|
|
4
|
-
/**
|
|
5
|
-
* Options for the PackageHashes class.
|
|
6
|
-
*/
|
|
7
|
-
export type PackageHashesOptions = {
|
|
8
|
-
/**
|
|
9
|
-
* A function that returns the hash for a given package path. This is intended for testing purposes.
|
|
10
|
-
*/
|
|
11
|
-
hash: HashFunction;
|
|
12
|
-
} | {
|
|
13
|
-
/** Working directory used to find the project root (usually repository root). */
|
|
14
|
-
cwd: string;
|
|
15
|
-
/**
|
|
16
|
-
* Context for the hash calculations.
|
|
17
|
-
*/
|
|
18
|
-
context: {
|
|
19
|
-
config: Pick<CloudpackConfig, 'patchFilesGlobPattern'>;
|
|
20
|
-
packages: PackageDefinitionsCache;
|
|
21
|
-
resolveMap: ResolveMap;
|
|
22
|
-
};
|
|
23
|
-
};
|
|
24
|
-
//# sourceMappingURL=PackageHashOptions.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"PackageHashOptions.d.ts","sourceRoot":"","sources":["../../src/types/PackageHashOptions.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,uBAAuB,EAAE,MAAM,4BAA4B,CAAC;AAC3F,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AACtD,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,iCAAiC,CAAC;AAElE;;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,MAAM,EAAE,IAAI,CAAC,eAAe,EAAE,uBAAuB,CAAC,CAAC;QACvD,QAAQ,EAAE,uBAAuB,CAAC;QAClC,UAAU,EAAE,UAAU,CAAC;KACxB,CAAC;CACH,CAAC"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"PackageHashOptions.js","sourceRoot":"","sources":["../../src/types/PackageHashOptions.ts"],"names":[],"mappings":"","sourcesContent":["import type { CloudpackConfig, PackageDefinitionsCache } from '@ms-cloudpack/common-types';\nimport type { HashFunction } from './HashFunction.js';\nimport type { ResolveMap } from '@ms-cloudpack/package-utilities';\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 config: Pick<CloudpackConfig, 'patchFilesGlobPattern'>;\n packages: PackageDefinitionsCache;\n resolveMap: ResolveMap;\n };\n };\n"]}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"PackagePatches.d.ts","sourceRoot":"","sources":["../../src/types/PackagePatches.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,cAAc;IAC7B,eAAe,CAAC,WAAW,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,GAAG,SAAS,CAAC,CAAC;CACpF"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"PackagePatches.js","sourceRoot":"","sources":["../../src/types/PackagePatches.ts"],"names":[],"mappings":"","sourcesContent":["export interface PackagePatches {\n getPackagePatch(packageName: string, version: string): Promise<string | undefined>;\n}\n"]}
|