@ms-cloudpack/package-hashes 0.0.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/README.md ADDED
@@ -0,0 +1,3 @@
1
+ # @ms-cloudpack/package-hashes
2
+
3
+ Utilities for hashing packages.
@@ -0,0 +1,25 @@
1
+ import type { PackageHashesOptions } from './types/PackageHashOptions.js';
2
+ export declare class PackageHashes {
3
+ readonly options: PackageHashesOptions;
4
+ private readonly _hashesWithSource;
5
+ private readonly _hashesWithNoSource;
6
+ private readonly _hash;
7
+ constructor(options: PackageHashesOptions);
8
+ /**
9
+ * Gets the hash for a given package path. This is useful for caching, to determine if the package has changed.
10
+ * If the package definition has not been calculated, it will be calculated and cached.
11
+ * @param packagePath - The package path to get the hash for.
12
+ * @returns The hash for the package.
13
+ */
14
+ get(params: {
15
+ packagePath: string;
16
+ isSourceHashingEnabled: boolean;
17
+ }): Promise<string>;
18
+ /**
19
+ * Removes the hash for a given package path from the local hash cache.
20
+ * This is useful when a package has changed, and you want to force a re-calculation of the hash.
21
+ * @param packagePath - The package path to remove the hash for.
22
+ */
23
+ remove(packagePath: string): void;
24
+ }
25
+ //# sourceMappingURL=PackageHashes.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"PackageHashes.d.ts","sourceRoot":"","sources":["../src/PackageHashes.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,+BAA+B,CAAC;AAE1E,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;IAIlD;;;;;OAKG;IACG,GAAG,CAAC,MAAM,EAAE;QAAE,WAAW,EAAE,MAAM,CAAC;QAAC,sBAAsB,EAAE,OAAO,CAAA;KAAE,GAAG,OAAO,CAAC,MAAM,CAAC;IAe5F;;;;OAIG;IACH,MAAM,CAAC,WAAW,EAAE,MAAM;CAI3B"}
@@ -0,0 +1,35 @@
1
+ import { hashPackage } from './hashPackage.js';
2
+ export class PackageHashes {
3
+ constructor(options) {
4
+ this.options = options;
5
+ this._hashesWithSource = new Map();
6
+ this._hashesWithNoSource = new Map();
7
+ this._hash = 'hash' in options ? options.hash : (input) => hashPackage({ input, context: options.context });
8
+ }
9
+ /**
10
+ * Gets the hash for a given package path. This is useful for caching, to determine if the package has changed.
11
+ * If the package definition has not been calculated, it will be calculated and cached.
12
+ * @param packagePath - The package path to get the hash for.
13
+ * @returns The hash for the package.
14
+ */
15
+ async get(params) {
16
+ const { packagePath, isSourceHashingEnabled } = params;
17
+ const map = isSourceHashingEnabled ? this._hashesWithSource : this._hashesWithNoSource;
18
+ if (map.has(packagePath)) {
19
+ return map.get(packagePath);
20
+ }
21
+ const hash = await this._hash(params);
22
+ map.set(packagePath, hash);
23
+ return hash;
24
+ }
25
+ /**
26
+ * Removes the hash for a given package path from the local hash cache.
27
+ * This is useful when a package has changed, and you want to force a re-calculation of the hash.
28
+ * @param packagePath - The package path to remove the hash for.
29
+ */
30
+ remove(packagePath) {
31
+ this._hashesWithSource.delete(packagePath);
32
+ this._hashesWithNoSource.delete(packagePath);
33
+ }
34
+ }
35
+ //# sourceMappingURL=PackageHashes.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"PackageHashes.js","sourceRoot":"","sources":["../src/PackageHashes.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAI/C,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,CAAC,KAAK,GAAG,MAAM,IAAI,OAAO,CAAC,CAAC,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,WAAW,CAAC,EAAE,KAAK,EAAE,OAAO,EAAE,OAAO,CAAC,OAAO,EAAE,CAAC,CAAC;IAC9G,CAAC;IAED;;;;;OAKG;IACH,KAAK,CAAC,GAAG,CAAC,MAAgE;QACxE,MAAM,EAAE,WAAW,EAAE,sBAAsB,EAAE,GAAG,MAAM,CAAC;QACvD,MAAM,GAAG,GAAG,sBAAsB,CAAC,CAAC,CAAC,IAAI,CAAC,iBAAiB,CAAC,CAAC,CAAC,IAAI,CAAC,mBAAmB,CAAC;QAEvF,IAAI,GAAG,CAAC,GAAG,CAAC,WAAW,CAAC,EAAE;YACxB,OAAO,GAAG,CAAC,GAAG,CAAC,WAAW,CAAW,CAAC;SACvC;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;IAED;;;;OAIG;IACH,MAAM,CAAC,WAAmB;QACxB,IAAI,CAAC,iBAAiB,CAAC,MAAM,CAAC,WAAW,CAAC,CAAC;QAC3C,IAAI,CAAC,mBAAmB,CAAC,MAAM,CAAC,WAAW,CAAC,CAAC;IAC/C,CAAC;CACF","sourcesContent":["import { hashPackage } from './hashPackage.js';\nimport type { HashFunction } from './types/HashFunctions.js';\nimport type { PackageHashesOptions } from './types/PackageHashOptions.js';\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 this._hash = 'hash' in options ? options.hash : (input) => hashPackage({ input, context: options.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 * @returns The hash for the package.\n */\n async get(params: { packagePath: string; isSourceHashingEnabled: boolean }): Promise<string> {\n const { packagePath, isSourceHashingEnabled } = params;\n const map = isSourceHashingEnabled ? this._hashesWithSource : this._hashesWithNoSource;\n\n if (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 /**\n * Removes the hash for a given package path from the local hash cache.\n * This is useful when a package has changed, and you want to force a re-calculation of the hash.\n * @param packagePath - The package path to remove the hash for.\n */\n remove(packagePath: string) {\n this._hashesWithSource.delete(packagePath);\n this._hashesWithNoSource.delete(packagePath);\n }\n}\n"]}
@@ -0,0 +1,15 @@
1
+ import type { PackageJson } from '@ms-cloudpack/bundler-types';
2
+ import { type ResolveMap } from '@ms-cloudpack/package-utilities';
3
+ import { type CloudpackConfig } from '@ms-cloudpack/config';
4
+ export declare function getInlinedDependenciesPaths(params: {
5
+ options: {
6
+ packageName: string;
7
+ version: string;
8
+ definition: PackageJson;
9
+ };
10
+ context: {
11
+ resolveMap: ResolveMap;
12
+ config: CloudpackConfig;
13
+ };
14
+ }): string[];
15
+ //# sourceMappingURL=getInlinedDependenciesPaths.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"getInlinedDependenciesPaths.d.ts","sourceRoot":"","sources":["../src/getInlinedDependenciesPaths.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,6BAA6B,CAAC;AAC/D,OAAO,EAAuB,KAAK,UAAU,EAAE,MAAM,iCAAiC,CAAC;AACvF,OAAO,EAAsB,KAAK,eAAe,EAAE,MAAM,sBAAsB,CAAC;AAiBhF,wBAAgB,2BAA2B,CAAC,MAAM,EAAE;IAClD,OAAO,EAAE;QACP,WAAW,EAAE,MAAM,CAAC;QACpB,OAAO,EAAE,MAAM,CAAC;QAChB,UAAU,EAAE,WAAW,CAAC;KACzB,CAAC;IACF,OAAO,EAAE;QACP,UAAU,EAAE,UAAU,CAAC;QACvB,MAAM,EAAE,eAAe,CAAC;KACzB,CAAC;CACH,YAqBA"}
@@ -0,0 +1,31 @@
1
+ import { findResolveMapEntry } from '@ms-cloudpack/package-utilities';
2
+ import { getPackageSettings } from '@ms-cloudpack/config';
3
+ function getInlinedDependencies(params) {
4
+ const { options, context } = params;
5
+ const { packageName, version } = options;
6
+ const { config } = context;
7
+ const { generatedPackageSettings, userPackageSettings } = getPackageSettings({ name: packageName, version, config });
8
+ return [
9
+ ...(userPackageSettings?.inlinedDependencies || []),
10
+ ...(generatedPackageSettings?.inlinedDependencies || []),
11
+ ];
12
+ }
13
+ export function getInlinedDependenciesPaths(params) {
14
+ const { options, context } = params;
15
+ const { definition } = options;
16
+ const { resolveMap } = context;
17
+ const inlinedDependencies = getInlinedDependencies({ options, context });
18
+ const result = [];
19
+ const inlinedDependencyEntries = inlinedDependencies.map((dependency) => findResolveMapEntry({
20
+ packageName: dependency,
21
+ resolveMap,
22
+ definition,
23
+ }));
24
+ for (const inlinedDependencyEntry of inlinedDependencyEntries) {
25
+ if (inlinedDependencyEntry) {
26
+ result.push(inlinedDependencyEntry.path);
27
+ }
28
+ }
29
+ return result;
30
+ }
31
+ //# sourceMappingURL=getInlinedDependenciesPaths.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"getInlinedDependenciesPaths.js","sourceRoot":"","sources":["../src/getInlinedDependenciesPaths.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,mBAAmB,EAAmB,MAAM,iCAAiC,CAAC;AACvF,OAAO,EAAE,kBAAkB,EAAwB,MAAM,sBAAsB,CAAC;AAEhF,SAAS,sBAAsB,CAAC,MAG/B;IACC,MAAM,EAAE,OAAO,EAAE,OAAO,EAAE,GAAG,MAAM,CAAC;IACpC,MAAM,EAAE,WAAW,EAAE,OAAO,EAAE,GAAG,OAAO,CAAC;IACzC,MAAM,EAAE,MAAM,EAAE,GAAG,OAAO,CAAC;IAE3B,MAAM,EAAE,wBAAwB,EAAE,mBAAmB,EAAE,GAAG,kBAAkB,CAAC,EAAE,IAAI,EAAE,WAAW,EAAE,OAAO,EAAE,MAAM,EAAE,CAAC,CAAC;IACrH,OAAO;QACL,GAAG,CAAC,mBAAmB,EAAE,mBAAmB,IAAI,EAAE,CAAC;QACnD,GAAG,CAAC,wBAAwB,EAAE,mBAAmB,IAAI,EAAE,CAAC;KACzD,CAAC;AACJ,CAAC;AAED,MAAM,UAAU,2BAA2B,CAAC,MAU3C;IACC,MAAM,EAAE,OAAO,EAAE,OAAO,EAAE,GAAG,MAAM,CAAC;IACpC,MAAM,EAAE,UAAU,EAAE,GAAG,OAAO,CAAC;IAC/B,MAAM,EAAE,UAAU,EAAE,GAAG,OAAO,CAAC;IAC/B,MAAM,mBAAmB,GAAG,sBAAsB,CAAC,EAAE,OAAO,EAAE,OAAO,EAAE,CAAC,CAAC;IACzE,MAAM,MAAM,GAAa,EAAE,CAAC;IAC5B,MAAM,wBAAwB,GAAG,mBAAmB,CAAC,GAAG,CAAC,CAAC,UAAU,EAAE,EAAE,CACtE,mBAAmB,CAAC;QAClB,WAAW,EAAE,UAAU;QACvB,UAAU;QACV,UAAU;KACX,CAAC,CACH,CAAC;IAEF,KAAK,MAAM,sBAAsB,IAAI,wBAAwB,EAAE;QAC7D,IAAI,sBAAsB,EAAE;YAC1B,MAAM,CAAC,IAAI,CAAC,sBAAsB,CAAC,IAAI,CAAC,CAAC;SAC1C;KACF;IAED,OAAO,MAAM,CAAC;AAChB,CAAC","sourcesContent":["import type { PackageJson } from '@ms-cloudpack/bundler-types';\nimport { findResolveMapEntry, type ResolveMap } from '@ms-cloudpack/package-utilities';\nimport { getPackageSettings, type CloudpackConfig } from '@ms-cloudpack/config';\n\nfunction getInlinedDependencies(params: {\n options: { packageName: string; version: string };\n context: { config: CloudpackConfig };\n}) {\n const { options, context } = params;\n const { packageName, version } = options;\n const { config } = context;\n\n const { generatedPackageSettings, userPackageSettings } = getPackageSettings({ name: packageName, version, config });\n return [\n ...(userPackageSettings?.inlinedDependencies || []),\n ...(generatedPackageSettings?.inlinedDependencies || []),\n ];\n}\n\nexport function getInlinedDependenciesPaths(params: {\n options: {\n packageName: string;\n version: string;\n definition: PackageJson;\n };\n context: {\n resolveMap: ResolveMap;\n config: CloudpackConfig;\n };\n}) {\n const { options, context } = params;\n const { definition } = options;\n const { resolveMap } = context;\n const inlinedDependencies = getInlinedDependencies({ options, context });\n const result: string[] = [];\n const inlinedDependencyEntries = inlinedDependencies.map((dependency) =>\n findResolveMapEntry({\n packageName: dependency,\n resolveMap,\n definition,\n }),\n );\n\n for (const inlinedDependencyEntry of inlinedDependencyEntries) {\n if (inlinedDependencyEntry) {\n result.push(inlinedDependencyEntry.path);\n }\n }\n\n return result;\n}\n"]}
@@ -0,0 +1,69 @@
1
+ import type { PackageDefinitionsCache } from '@ms-cloudpack/bundler-types';
2
+ /**
3
+ * @returns the entries that are used to calculate the hash of a package
4
+ */
5
+ export declare function getPackageHashEntries(params: {
6
+ options: {
7
+ packagePath: string;
8
+ isSourceHashingEnabled: boolean;
9
+ };
10
+ context: {
11
+ packages: PackageDefinitionsCache;
12
+ };
13
+ }): Promise<{
14
+ name: string;
15
+ version: string;
16
+ filesHash: Record<string, string> | null | undefined;
17
+ description?: string | undefined;
18
+ files?: string[] | undefined;
19
+ directories?: {
20
+ [directoryType: string]: string | undefined;
21
+ bin?: string | undefined;
22
+ lib?: string | undefined;
23
+ } | undefined;
24
+ type?: "module" | "commonjs" | undefined;
25
+ main?: string | undefined;
26
+ module?: string | undefined;
27
+ bin?: string | Partial<Record<string, string>> | undefined;
28
+ esnext?: string | {
29
+ [moduleName: string]: string | undefined;
30
+ main?: string | undefined;
31
+ browser?: string | undefined;
32
+ } | undefined;
33
+ browser?: string | Partial<Record<string, string | false>> | undefined;
34
+ sideEffects?: boolean | string[] | undefined;
35
+ types?: string | undefined;
36
+ typings?: string | undefined;
37
+ typesVersions?: Partial<Record<string, Partial<Record<string, string[]>>>> | undefined;
38
+ exports?: import("@ms-cloudpack/bundler-types").PackageJsonExports | undefined;
39
+ imports?: import("@ms-cloudpack/bundler-types").PackageJsonImports | undefined;
40
+ dependencies?: Partial<Record<string, string>> | undefined;
41
+ devDependencies?: Partial<Record<string, string>> | undefined;
42
+ peerDependencies?: Partial<Record<string, string>> | undefined;
43
+ peerDependenciesMeta?: Partial<Record<string, {
44
+ optional: true;
45
+ }>> | undefined;
46
+ optionalDependencies?: Partial<Record<string, string>> | undefined;
47
+ bundledDependencies?: Partial<Record<string, string>> | undefined;
48
+ bundleDependencies?: Partial<Record<string, string>> | undefined;
49
+ engines?: {
50
+ [x: string & Record<never, never>]: string | undefined;
51
+ node?: string | undefined;
52
+ npm?: string | undefined;
53
+ } | undefined;
54
+ os?: import("@ms-cloudpack/bundler-types").LiteralOrString<"aix" | "darwin" | "freebsd" | "linux" | "openbsd" | "sunos" | "win32" | "!aix" | "!darwin" | "!freebsd" | "!linux" | "!openbsd" | "!sunos" | "!win32">[] | undefined;
55
+ cpu?: import("@ms-cloudpack/bundler-types").LiteralOrString<"arm" | "arm64" | "ia32" | "mips" | "mipsel" | "ppc" | "ppc64" | "s390" | "s390x" | "x32" | "x64" | "!arm" | "!arm64" | "!ia32" | "!mips" | "!mipsel" | "!ppc" | "!ppc64" | "!s390" | "!s390x" | "!x32" | "!x64">[] | undefined;
56
+ private?: boolean | undefined;
57
+ publishConfig?: {
58
+ [additionalProperties: string]: unknown;
59
+ access?: "public" | "restricted" | undefined;
60
+ registry?: string | undefined;
61
+ tag?: string | undefined;
62
+ } | undefined;
63
+ packageManager?: string | undefined;
64
+ workspaces?: string[] | {
65
+ packages?: string[] | undefined;
66
+ nohoist?: string[] | undefined;
67
+ } | undefined;
68
+ }>;
69
+ //# sourceMappingURL=getPackageHashEntries.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"getPackageHashEntries.d.ts","sourceRoot":"","sources":["../src/getPackageHashEntries.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,6BAA6B,CAAC;AAI3E;;GAEG;AACH,wBAAsB,qBAAqB,CAAC,MAAM,EAAE;IAClD,OAAO,EAAE;QACP,WAAW,EAAE,MAAM,CAAC;QACpB,sBAAsB,EAAE,OAAO,CAAC;KACjC,CAAC;IACF,OAAO,EAAE;QACP,QAAQ,EAAE,uBAAuB,CAAC;KACnC,CAAC;CACH;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4BA"}
@@ -0,0 +1,28 @@
1
+ import { isExternalPackage } from '@ms-cloudpack/package-utilities';
2
+ import { getSourceHash } from './getSourceHash.js';
3
+ /**
4
+ * @returns the entries that are used to calculate the hash of a package
5
+ */
6
+ export async function getPackageHashEntries(params) {
7
+ const { options, context } = params;
8
+ const { packagePath, isSourceHashingEnabled } = options;
9
+ const { packages } = context;
10
+ const definition = await packages.get(packagePath);
11
+ if (!definition) {
12
+ throw new Error(`Package definition (package.json) missing or invalid at "${packagePath}"`);
13
+ }
14
+ const { name } = definition;
15
+ if (!name) {
16
+ throw new Error(`Package definition (package.json) missing name at "${packagePath}"`);
17
+ }
18
+ const isExternal = isExternalPackage(packagePath);
19
+ const filesHash = !isExternal && isSourceHashingEnabled ? await getSourceHash({ packagePath }) : undefined;
20
+ const version = (isExternal ? definition.version : packagePath) || packagePath;
21
+ return {
22
+ ...definition,
23
+ name,
24
+ version,
25
+ filesHash,
26
+ };
27
+ }
28
+ //# sourceMappingURL=getPackageHashEntries.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"getPackageHashEntries.js","sourceRoot":"","sources":["../src/getPackageHashEntries.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,iBAAiB,EAAE,MAAM,iCAAiC,CAAC;AACpE,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AAEnD;;GAEG;AACH,MAAM,CAAC,KAAK,UAAU,qBAAqB,CAAC,MAQ3C;IACC,MAAM,EAAE,OAAO,EAAE,OAAO,EAAE,GAAG,MAAM,CAAC;IACpC,MAAM,EAAE,WAAW,EAAE,sBAAsB,EAAE,GAAG,OAAO,CAAC;IACxD,MAAM,EAAE,QAAQ,EAAE,GAAG,OAAO,CAAC;IAE7B,MAAM,UAAU,GAAG,MAAM,QAAQ,CAAC,GAAG,CAAC,WAAW,CAAC,CAAC;IAEnD,IAAI,CAAC,UAAU,EAAE;QACf,MAAM,IAAI,KAAK,CAAC,4DAA4D,WAAW,GAAG,CAAC,CAAC;KAC7F;IAED,MAAM,EAAE,IAAI,EAAE,GAAG,UAAU,CAAC;IAC5B,IAAI,CAAC,IAAI,EAAE;QACT,MAAM,IAAI,KAAK,CAAC,sDAAsD,WAAW,GAAG,CAAC,CAAC;KACvF;IAED,MAAM,UAAU,GAAG,iBAAiB,CAAC,WAAW,CAAC,CAAC;IAElD,MAAM,SAAS,GAAG,CAAC,UAAU,IAAI,sBAAsB,CAAC,CAAC,CAAC,MAAM,aAAa,CAAC,EAAE,WAAW,EAAE,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC;IAE3G,MAAM,OAAO,GAAG,CAAC,UAAU,CAAC,CAAC,CAAC,UAAU,CAAC,OAAO,CAAC,CAAC,CAAC,WAAW,CAAC,IAAI,WAAW,CAAC;IAE/E,OAAO;QACL,GAAG,UAAU;QACb,IAAI;QACJ,OAAO;QACP,SAAS;KACV,CAAC;AACJ,CAAC","sourcesContent":["import type { PackageDefinitionsCache } from '@ms-cloudpack/bundler-types';\nimport { isExternalPackage } from '@ms-cloudpack/package-utilities';\nimport { getSourceHash } from './getSourceHash.js';\n\n/**\n * @returns the entries that are used to calculate the hash of a package\n */\nexport async function getPackageHashEntries(params: {\n options: {\n packagePath: string;\n isSourceHashingEnabled: boolean;\n };\n context: {\n packages: PackageDefinitionsCache;\n };\n}) {\n const { options, context } = params;\n const { packagePath, isSourceHashingEnabled } = options;\n const { packages } = context;\n\n const definition = await packages.get(packagePath);\n\n if (!definition) {\n throw new Error(`Package definition (package.json) missing or invalid at \"${packagePath}\"`);\n }\n\n const { name } = definition;\n if (!name) {\n throw new Error(`Package definition (package.json) missing name at \"${packagePath}\"`);\n }\n\n const isExternal = isExternalPackage(packagePath);\n\n const filesHash = !isExternal && isSourceHashingEnabled ? await getSourceHash({ packagePath }) : undefined;\n\n const version = (isExternal ? definition.version : packagePath) || packagePath;\n\n return {\n ...definition,\n name,\n version,\n filesHash,\n };\n}\n"]}
@@ -0,0 +1,9 @@
1
+ /**
2
+ * Get the hash of the source files in a package
3
+ * If there is a src folder, only hash the files in that folder and the .*json files
4
+ * Otherwise, hash all files except node_modules
5
+ */
6
+ export declare function getSourceHash(options: {
7
+ packagePath: string;
8
+ }): Promise<Record<string, string> | null>;
9
+ //# sourceMappingURL=getSourceHash.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"getSourceHash.d.ts","sourceRoot":"","sources":["../src/getSourceHash.ts"],"names":[],"mappings":"AAOA;;;;GAIG;AACH,wBAAsB,aAAa,CAAC,OAAO,EAAE;IAAE,WAAW,EAAE,MAAM,CAAA;CAAE,0CAgBnE"}
@@ -0,0 +1,23 @@
1
+ import glob from 'fast-glob';
2
+ import { existsSync } from 'fs';
3
+ import { hash } from 'glob-hasher';
4
+ import path from 'path';
5
+ const excludeNodeModules = '!**/node_modules/**';
6
+ /**
7
+ * Get the hash of the source files in a package
8
+ * If there is a src folder, only hash the files in that folder and the .*json files
9
+ * Otherwise, hash all files except node_modules
10
+ */
11
+ export async function getSourceHash(options) {
12
+ const start = performance.now();
13
+ const { packagePath } = options;
14
+ const shouldUseSrc = existsSync(path.join(packagePath, 'src'));
15
+ const patterns = shouldUseSrc ? ['src/**', '*.json', excludeNodeModules] : ['**', excludeNodeModules];
16
+ const files = await glob(patterns, {
17
+ cwd: packagePath,
18
+ });
19
+ const globHash = hash(files, { cwd: packagePath });
20
+ console.debug(`Hashed source files in ${packagePath} in ${performance.now() - start}ms`);
21
+ return globHash;
22
+ }
23
+ //# sourceMappingURL=getSourceHash.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"getSourceHash.js","sourceRoot":"","sources":["../src/getSourceHash.ts"],"names":[],"mappings":"AAAA,OAAO,IAAI,MAAM,WAAW,CAAC;AAC7B,OAAO,EAAE,UAAU,EAAE,MAAM,IAAI,CAAC;AAChC,OAAO,EAAE,IAAI,EAAE,MAAM,aAAa,CAAC;AACnC,OAAO,IAAI,MAAM,MAAM,CAAC;AAExB,MAAM,kBAAkB,GAAG,qBAAqB,CAAC;AAEjD;;;;GAIG;AACH,MAAM,CAAC,KAAK,UAAU,aAAa,CAAC,OAAgC;IAClE,MAAM,KAAK,GAAG,WAAW,CAAC,GAAG,EAAE,CAAC;IAEhC,MAAM,EAAE,WAAW,EAAE,GAAG,OAAO,CAAC;IAChC,MAAM,YAAY,GAAG,UAAU,CAAC,IAAI,CAAC,IAAI,CAAC,WAAW,EAAE,KAAK,CAAC,CAAC,CAAC;IAC/D,MAAM,QAAQ,GAAG,YAAY,CAAC,CAAC,CAAC,CAAC,QAAQ,EAAE,QAAQ,EAAE,kBAAkB,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,EAAE,kBAAkB,CAAC,CAAC;IAEtG,MAAM,KAAK,GAAG,MAAM,IAAI,CAAC,QAAQ,EAAE;QACjC,GAAG,EAAE,WAAW;KACjB,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 glob from 'fast-glob';\nimport { existsSync } from 'fs';\nimport { hash } from 'glob-hasher';\nimport path from 'path';\n\nconst excludeNodeModules = '!**/node_modules/**';\n\n/**\n * Get the hash of the source files in a package\n * If there is a src folder, only hash the files in that folder and the .*json files\n * Otherwise, hash all files except node_modules\n */\nexport async function getSourceHash(options: { packagePath: string }) {\n const start = performance.now();\n\n const { packagePath } = options;\n const shouldUseSrc = existsSync(path.join(packagePath, 'src'));\n const patterns = shouldUseSrc ? ['src/**', '*.json', excludeNodeModules] : ['**', excludeNodeModules];\n\n const files = await glob(patterns, {\n cwd: packagePath,\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"]}
@@ -0,0 +1,15 @@
1
+ import type { PackageDefinitionsCache } from '@ms-cloudpack/bundler-types';
2
+ import { type ResolveMap } from '@ms-cloudpack/package-utilities';
3
+ import { type CloudpackConfig } from '@ms-cloudpack/config';
4
+ export declare function hashPackage(params: {
5
+ input: {
6
+ packagePath: string;
7
+ isSourceHashingEnabled: boolean;
8
+ };
9
+ context: {
10
+ packages: PackageDefinitionsCache;
11
+ config?: CloudpackConfig;
12
+ resolveMap: ResolveMap;
13
+ };
14
+ }): Promise<string>;
15
+ //# sourceMappingURL=hashPackage.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"hashPackage.d.ts","sourceRoot":"","sources":["../src/hashPackage.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,6BAA6B,CAAC;AAC3E,OAAO,EAAE,KAAK,UAAU,EAAE,MAAM,iCAAiC,CAAC;AAGlE,OAAO,EAAE,KAAK,eAAe,EAAE,MAAM,sBAAsB,CAAC;AAO5D,wBAAsB,WAAW,CAAC,MAAM,EAAE;IACxC,KAAK,EAAE;QACL,WAAW,EAAE,MAAM,CAAC;QACpB,sBAAsB,EAAE,OAAO,CAAC;KACjC,CAAC;IACF,OAAO,EAAE;QACP,QAAQ,EAAE,uBAAuB,CAAC;QAClC,MAAM,CAAC,EAAE,eAAe,CAAC;QACzB,UAAU,EAAE,UAAU,CAAC;KACxB,CAAC;CACH,GAAG,OAAO,CAAC,MAAM,CAAC,CA0ClB"}
@@ -0,0 +1,44 @@
1
+ import {} from '@ms-cloudpack/package-utilities';
2
+ import objectHash from 'object-hash';
3
+ import { getPackageHashEntries } from './getPackageHashEntries.js';
4
+ import {} from '@ms-cloudpack/config';
5
+ import { getInlinedDependenciesPaths } from './getInlinedDependenciesPaths.js';
6
+ let totalTime = 0;
7
+ const hashVersion = 0;
8
+ export async function hashPackage(params) {
9
+ const start = performance.now();
10
+ const { input, context } = params;
11
+ const { packagePath, isSourceHashingEnabled } = input;
12
+ const { resolveMap, config, packages } = context;
13
+ const hashEntriesArray = [];
14
+ const packagesToHash = [packagePath];
15
+ while (packagesToHash.length > 0) {
16
+ const packageToHash = packagesToHash.pop();
17
+ if (!packageToHash) {
18
+ continue;
19
+ }
20
+ const hashEntries = await getPackageHashEntries({
21
+ options: { isSourceHashingEnabled, packagePath: packageToHash },
22
+ context: { packages },
23
+ });
24
+ hashEntriesArray.push(hashEntries);
25
+ if (config) {
26
+ const inlinedDependenciesPaths = getInlinedDependenciesPaths({
27
+ options: {
28
+ packageName: hashEntries.name,
29
+ version: hashEntries.version,
30
+ definition: hashEntries,
31
+ },
32
+ context: { config, resolveMap },
33
+ });
34
+ packagesToHash.push(...inlinedDependenciesPaths);
35
+ }
36
+ }
37
+ const hashResult = objectHash(hashEntriesArray);
38
+ const { name, version } = hashEntriesArray[0];
39
+ const elapsedTime = performance.now() - start;
40
+ totalTime += elapsedTime;
41
+ console.debug(`Hashed ${name}@${version} in ${elapsedTime}ms, total time: ${totalTime}ms`);
42
+ return `v${hashVersion}-${hashResult}`;
43
+ }
44
+ //# sourceMappingURL=hashPackage.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"hashPackage.js","sourceRoot":"","sources":["../src/hashPackage.ts"],"names":[],"mappings":"AACA,OAAO,EAAmB,MAAM,iCAAiC,CAAC;AAClE,OAAO,UAAU,MAAM,aAAa,CAAC;AACrC,OAAO,EAAE,qBAAqB,EAAE,MAAM,4BAA4B,CAAC;AACnE,OAAO,EAAwB,MAAM,sBAAsB,CAAC;AAC5D,OAAO,EAAE,2BAA2B,EAAE,MAAM,kCAAkC,CAAC;AAE/E,IAAI,SAAS,GAAG,CAAC,CAAC;AAElB,MAAM,WAAW,GAAG,CAAC,CAAC;AAEtB,MAAM,CAAC,KAAK,UAAU,WAAW,CAAC,MAUjC;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,MAAM,EAAE,QAAQ,EAAE,GAAG,OAAO,CAAC;IACjD,MAAM,gBAAgB,GAAwD,EAAE,CAAC;IACjF,MAAM,cAAc,GAAa,CAAC,WAAW,CAAC,CAAC;IAE/C,OAAO,cAAc,CAAC,MAAM,GAAG,CAAC,EAAE;QAChC,MAAM,aAAa,GAAG,cAAc,CAAC,GAAG,EAAE,CAAC;QAC3C,IAAI,CAAC,aAAa,EAAE;YAClB,SAAS;SACV;QAED,MAAM,WAAW,GAAG,MAAM,qBAAqB,CAAC;YAC9C,OAAO,EAAE,EAAE,sBAAsB,EAAE,WAAW,EAAE,aAAa,EAAE;YAC/D,OAAO,EAAE,EAAE,QAAQ,EAAE;SACtB,CAAC,CAAC;QAEH,gBAAgB,CAAC,IAAI,CAAC,WAAW,CAAC,CAAC;QAEnC,IAAI,MAAM,EAAE;YACV,MAAM,wBAAwB,GAAG,2BAA2B,CAAC;gBAC3D,OAAO,EAAE;oBACP,WAAW,EAAE,WAAW,CAAC,IAAI;oBAC7B,OAAO,EAAE,WAAW,CAAC,OAAO;oBAC5B,UAAU,EAAE,WAAW;iBACxB;gBACD,OAAO,EAAE,EAAE,MAAM,EAAE,UAAU,EAAE;aAChC,CAAC,CAAC;YACH,cAAc,CAAC,IAAI,CAAC,GAAG,wBAAwB,CAAC,CAAC;SAClD;KACF;IAED,MAAM,UAAU,GAAG,UAAU,CAAC,gBAAgB,CAAC,CAAC;IAEhD,MAAM,EAAE,IAAI,EAAE,OAAO,EAAE,GAAG,gBAAgB,CAAC,CAAC,CAAC,CAAC;IAC9C,MAAM,WAAW,GAAG,WAAW,CAAC,GAAG,EAAE,GAAG,KAAK,CAAC;IAC9C,SAAS,IAAI,WAAW,CAAC;IACzB,OAAO,CAAC,KAAK,CAAC,UAAU,IAAI,IAAI,OAAO,OAAO,WAAW,mBAAmB,SAAS,IAAI,CAAC,CAAC;IAE3F,OAAO,IAAI,WAAW,IAAI,UAAU,EAAE,CAAC;AACzC,CAAC","sourcesContent":["import type { PackageDefinitionsCache } from '@ms-cloudpack/bundler-types';\nimport { type ResolveMap } from '@ms-cloudpack/package-utilities';\nimport objectHash from 'object-hash';\nimport { getPackageHashEntries } from './getPackageHashEntries.js';\nimport { type CloudpackConfig } from '@ms-cloudpack/config';\nimport { getInlinedDependenciesPaths } from './getInlinedDependenciesPaths.js';\n\nlet totalTime = 0;\n\nconst hashVersion = 0;\n\nexport async function hashPackage(params: {\n input: {\n packagePath: string;\n isSourceHashingEnabled: boolean;\n };\n context: {\n packages: PackageDefinitionsCache;\n config?: CloudpackConfig;\n resolveMap: ResolveMap;\n };\n}): Promise<string> {\n const start = performance.now();\n const { input, context } = params;\n const { packagePath, isSourceHashingEnabled } = input;\n const { resolveMap, config, packages } = 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 },\n });\n\n hashEntriesArray.push(hashEntries);\n\n if (config) {\n const inlinedDependenciesPaths = getInlinedDependenciesPaths({\n options: {\n packageName: hashEntries.name,\n version: hashEntries.version,\n definition: hashEntries,\n },\n context: { config, resolveMap },\n });\n packagesToHash.push(...inlinedDependenciesPaths);\n }\n }\n\n const hashResult = objectHash(hashEntriesArray);\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 ADDED
@@ -0,0 +1,4 @@
1
+ export { PackageHashes } from './PackageHashes.js';
2
+ export type { PackageHashesOptions } from './types/PackageHashOptions.js';
3
+ export type { HashFunction } from './types/HashFunctions.js';
4
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AACnD,YAAY,EAAE,oBAAoB,EAAE,MAAM,+BAA+B,CAAC;AAC1E,YAAY,EAAE,YAAY,EAAE,MAAM,0BAA0B,CAAC"}
package/lib/index.js ADDED
@@ -0,0 +1,2 @@
1
+ export { PackageHashes } from './PackageHashes.js';
2
+ //# sourceMappingURL=index.js.map
@@ -0,0 +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';\nexport type { PackageHashesOptions } from './types/PackageHashOptions.js';\nexport type { HashFunction } from './types/HashFunctions.js';\n"]}
@@ -0,0 +1,11 @@
1
+ // This file is read by tools that parse documentation comments conforming to the TSDoc standard.
2
+ // It should be published with your NPM package. It should not be tracked by Git.
3
+ {
4
+ "tsdocVersion": "0.12",
5
+ "toolPackages": [
6
+ {
7
+ "packageName": "@microsoft/api-extractor",
8
+ "packageVersion": "7.37.1"
9
+ }
10
+ ]
11
+ }
@@ -0,0 +1,5 @@
1
+ export type HashFunction = (params: {
2
+ packagePath: string;
3
+ isSourceHashingEnabled: boolean;
4
+ }) => Promise<string>;
5
+ //# sourceMappingURL=HashFunctions.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"HashFunctions.d.ts","sourceRoot":"","sources":["../../src/types/HashFunctions.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,YAAY,GAAG,CAAC,MAAM,EAAE;IAAE,WAAW,EAAE,MAAM,CAAC;IAAC,sBAAsB,EAAE,OAAO,CAAA;CAAE,KAAK,OAAO,CAAC,MAAM,CAAC,CAAC"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=HashFunctions.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"HashFunctions.js","sourceRoot":"","sources":["../../src/types/HashFunctions.ts"],"names":[],"mappings":"","sourcesContent":["export type HashFunction = (params: { packagePath: string; isSourceHashingEnabled: boolean }) => Promise<string>;\n"]}
@@ -0,0 +1,23 @@
1
+ import type { PackageDefinitionsCache } from '@ms-cloudpack/bundler-types';
2
+ import type { CloudpackConfig } from '@ms-cloudpack/config';
3
+ import type { ResolveMap } from '@ms-cloudpack/package-utilities';
4
+ import type { HashFunction } from './HashFunctions.js';
5
+ /**
6
+ * Options for the PackageHashes class.
7
+ */
8
+ export type PackageHashesOptions = {
9
+ /**
10
+ * A function that returns the hash for a given package path. This is intended for testing purposes.
11
+ */
12
+ hash: HashFunction;
13
+ } | {
14
+ /**
15
+ * Context for the hash calculations.
16
+ */
17
+ context: {
18
+ packages: PackageDefinitionsCache;
19
+ config: CloudpackConfig;
20
+ resolveMap: ResolveMap;
21
+ };
22
+ };
23
+ //# sourceMappingURL=PackageHashOptions.d.ts.map
@@ -0,0 +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,sBAAsB,CAAC;AAC5D,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"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=PackageHashOptions.js.map
@@ -0,0 +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';\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"]}
package/package.json ADDED
@@ -0,0 +1,44 @@
1
+ {
2
+ "name": "@ms-cloudpack/package-hashes",
3
+ "version": "0.0.1",
4
+ "description": "Utilities for hashing packages.",
5
+ "license": "MIT",
6
+ "type": "module",
7
+ "types": "./lib/index.d.ts",
8
+ "sideEffects": false,
9
+ "exports": {
10
+ ".": {
11
+ "source": "./src/index.ts",
12
+ "types": "./lib/index.d.ts",
13
+ "import": "./lib/index.js"
14
+ }
15
+ },
16
+ "dependencies": {
17
+ "@ms-cloudpack/bundler-types": "^0.19.4",
18
+ "@ms-cloudpack/package-utilities": "^5.2.0",
19
+ "@ms-cloudpack/config": "^0.14.5",
20
+ "fast-glob": "^3.2.12",
21
+ "glob-hasher": "^1.2.1",
22
+ "object-hash": "^3.0.0"
23
+ },
24
+ "devDependencies": {
25
+ "@ms-cloudpack/eslint-plugin-internal": "*",
26
+ "@ms-cloudpack/scripts": "*",
27
+ "@ms-cloudpack/test-utilities": "*",
28
+ "@types/object-hash": "^3.0.2"
29
+ },
30
+ "scripts": {
31
+ "api": "cloudpack-scripts api",
32
+ "build:watch": "cloudpack-scripts build-watch",
33
+ "build": "cloudpack-scripts build",
34
+ "lint:update": "cloudpack-scripts lint-update",
35
+ "lint": "cloudpack-scripts lint",
36
+ "prepack": "cp .npmignore lib/.npmignore",
37
+ "test:update": "cloudpack-scripts test-update",
38
+ "test:watch": "cloudpack-scripts test-watch",
39
+ "test": "cloudpack-scripts test"
40
+ },
41
+ "files": [
42
+ "lib/**/!(*.test.*)"
43
+ ]
44
+ }