@ms-cloudpack/package-hashes 0.8.47 → 0.8.48

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,4 +1,4 @@
1
- import type { CloudpackConfig, PackageDefinitionsCache, PackageHashOptions, PackageHashesCache, ResolveMap, SerializablePackageHashesCache } from '@ms-cloudpack/common-types';
1
+ import type { CloudpackConfig, Features, PackageDefinitionsCache, PackageHashOptions, PackageHashesCache, ResolveMap, SerializablePackageHashesCache } from '@ms-cloudpack/common-types';
2
2
  import type { HashFunction } from './types/HashFunction.js';
3
3
  /**
4
4
  * Constructor options for the PackageHashes class.
@@ -12,7 +12,9 @@ type PackageHashesOptions = {
12
12
  * Context for the hash calculations.
13
13
  */
14
14
  context: {
15
- config: Pick<CloudpackConfig, 'patchFilesGlobPattern' | 'bundlerCapabilitiesRegistry' | 'defaultBundler' | 'define' | 'mode'>;
15
+ config: Pick<CloudpackConfig, 'patchFilesGlobPattern' | 'bundlerCapabilitiesRegistry' | 'defaultBundler' | 'define' | 'mode'> & {
16
+ features?: Pick<Features, 'hmr'>;
17
+ };
16
18
  packages: PackageDefinitionsCache;
17
19
  resolveMap: ResolveMap;
18
20
  };
@@ -1 +1 @@
1
- {"version":3,"file":"PackageHashes.d.ts","sourceRoot":"","sources":["../src/PackageHashes.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,eAAe,EACf,uBAAuB,EACvB,kBAAkB,EAClB,kBAAkB,EAClB,UAAU,EACV,8BAA8B,EAC/B,MAAM,4BAA4B,CAAC;AAEpC,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,yBAAyB,CAAC;AAI5D;;;;GAIG;AACH,KAAK,oBAAoB,GACrB;IACE,iFAAiF;IACjF,GAAG,EAAE,MAAM,CAAC;IACZ;;OAEG;IACH,OAAO,EAAE;QACP,MAAM,EAAE,IAAI,CACV,eAAe,EACf,uBAAuB,GAAG,6BAA6B,GAAG,gBAAgB,GAAG,QAAQ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AAQ,CAAC,EAAE,IAAI,CAAC,QAAQ,EAAE,KAAK,CAAC,CAAC;SAClC,CAAC;QACF,QAAQ,EAAE,uBAAuB,CAAC;QAClC,UAAU,EAAE,UAAU,CAAC;KACxB,CAAC;CACH,GACD;IACE;;OAEG;IACH,IAAI,EAAE,YAAY,CAAC;CACpB,CAAC;AAEN;;GAEG;AACH,qBAAa,aAAc,YAAW,kBAAkB;IAa1C,QAAQ,CAAC,OAAO,EAAE,oBAAoB;IAZlD,mEAAmE;IACnE,OAAO,CAAC,QAAQ,CAAC,iBAAiB,CAGhC;IACF,uEAAuE;IACvE,OAAO,CAAC,QAAQ,CAAC,mBAAmB,CAGlC;IACF,OAAO,CAAC,QAAQ,CAAC,KAAK,CAAe;gBAEhB,OAAO,EAAE,oBAAoB;IA2B5C,GAAG,CAAC,KAAK,EAAE,kBAAkB,GAAG,OAAO,CAAC,MAAM,CAAC;IAgBrD;;OAEG;IACH,cAAc,IAAI,8BAA8B;IAahD,GAAG,CAAC,KAAK,EAAE,IAAI,CAAC,kBAAkB,EAAE,mBAAmB,CAAC,EAAE,IAAI,EAAE,MAAM,GAAG,IAAI;IAM7E,MAAM,CAAC,KAAK,EAAE,8BAA8B,GAAG,IAAI;CAcpD"}
@@ -37,6 +37,7 @@ export class PackageHashes {
37
37
  bundlerCapabilitiesCache,
38
38
  defaultBundler: config.defaultBundler,
39
39
  defineFlags: config.mode === 'production' ? (config.define ?? {}) : {},
40
+ hmr: !!config.features?.hmr,
40
41
  },
41
42
  });
42
43
  }
@@ -1 +1 @@
1
- {"version":3,"file":"PackageHashes.js","sourceRoot":"","sources":["../src/PackageHashes.ts"],"names":[],"mappings":"AAQA,OAAO,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAE/C,OAAO,EAAE,mBAAmB,EAAE,MAAM,0BAA0B,CAAC;AAC/D,OAAO,EAAE,wBAAwB,EAAE,MAAM,+BAA+B,CAAC;AA8BzE;;GAEG;AACH,MAAM,OAAO,aAAa;IA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;QAC1C,0DAA0D;QAC1D,MAAM,SAAS,GAAG,CAAC,GAAwB,EAAE,MAA8B,EAAE,EAAQ,EAAE;YACrF,KAAK,MAAM,CAAC,GAAG,EAAE,KAAK,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,GAAG,CAAC,EAAE,CAAC;gBAC/C,GAAG,CAAC,GAAG,CAAC,GAAG,EAAE,KAAK,CAAC,CAAC;YACtB,CAAC;QACH,CAAC,CAAC;QAEF,+BAA+B;QAC/B,SAAS,CAAC,IAAI,CAAC,iBAAiB,CAAC,OAAO,EAAE,KAAK,CAAC,gBAAgB,EAAE,OAAO,CAAC,CAAC;QAC3E,SAAS,CAAC,IAAI,CAAC,iBAAiB,CAAC,IAAI,EAAE,KAAK,CAAC,gBAAgB,EAAE,IAAI,CAAC,CAAC;QACrE,SAAS,CAAC,IAAI,CAAC,mBAAmB,CAAC,OAAO,EAAE,KAAK,CAAC,kBAAkB,EAAE,OAAO,CAAC,CAAC;QAC/E,SAAS,CAAC,IAAI,CAAC,mBAAmB,CAAC,IAAI,EAAE,KAAK,CAAC,kBAAkB,EAAE,IAAI,CAAC,CAAC;IAC3E,CAAC;CACF","sourcesContent":["import type {\n CloudpackConfig,\n PackageDefinitionsCache,\n PackageHashOptions,\n PackageHashesCache,\n ResolveMap,\n SerializablePackageHashesCache,\n} from '@ms-cloudpack/common-types';\nimport { hashPackage } from './hashPackage.js';\nimport type { HashFunction } from './types/HashFunction.js';\nimport { PackagePatchesCache } from './PackagePatchesCache.js';\nimport { BundlerCapabilitiesCache } from './BundlerCapabilitiesCache.js';\n\n/**\n * Constructor options for the PackageHashes class.\n *\n * (For `PackageHashes.get` options, see `PackageHashOptions`.)\n */\ntype PackageHashesOptions =\n | {\n /** Working directory used to find the project root (usually repository root). */\n cwd: string;\n /**\n * Context for the hash calculations.\n */\n context: {\n config: Pick<\n CloudpackConfig,\n 'patchFilesGlobPattern' | 'bundlerCapabilitiesRegistry' | 'defaultBundler' | 'define' | 'mode'\n >;\n packages: PackageDefinitionsCache;\n resolveMap: ResolveMap;\n };\n }\n | {\n /**\n * A function that returns the hash for a given package path. This is intended for testing purposes.\n */\n hash: HashFunction;\n };\n\n/**\n * Utility class for hashing packages and caching the results.\n */\nexport class PackageHashes implements PackageHashesCache {\n /** Mapping from package path to hash (considering source files) */\n private readonly _hashesWithSource = {\n browser: new Map<string, string>(),\n node: new Map<string, string>(),\n };\n /** Mapping from package path to hash (not considering source files) */\n private readonly _hashesWithNoSource = {\n browser: new Map<string, string>(),\n node: new Map<string, string>(),\n };\n private readonly _hash: HashFunction;\n\n constructor(readonly options: PackageHashesOptions) {\n if ('hash' in options) {\n this._hash = options.hash;\n return;\n }\n\n const { config } = options.context;\n const patches = new PackagePatchesCache({\n cwd: options.cwd,\n globPattern: config.patchFilesGlobPattern,\n });\n const bundlerCapabilitiesCache = new BundlerCapabilitiesCache(config.bundlerCapabilitiesRegistry);\n\n this._hash = (input) =>\n hashPackage({\n input,\n context: {\n ...options.context,\n patches,\n bundlerCapabilitiesCache,\n defaultBundler: config.defaultBundler,\n defineFlags: config.mode === 'production' ? (config.define ?? {}) : {},\n },\n });\n }\n\n async get(input: PackageHashOptions): Promise<string> {\n const { packagePath, isSourceHashingEnabled, shouldRecalculate, targetEnvironment } = input;\n\n const map = (isSourceHashingEnabled ? this._hashesWithSource : this._hashesWithNoSource)[targetEnvironment];\n\n if (!shouldRecalculate && map.has(packagePath)) {\n return map.get(packagePath) as string;\n }\n\n const hash = await this._hash(input);\n\n map.set(packagePath, hash);\n\n return hash;\n }\n\n /**\n * Creates a serializable representation of the cache.\n */\n toSerializable(): SerializablePackageHashesCache {\n return {\n hashesWithSource: {\n browser: Object.fromEntries(this._hashesWithSource.browser),\n node: Object.fromEntries(this._hashesWithSource.node),\n },\n hashesWithNoSource: {\n browser: Object.fromEntries(this._hashesWithNoSource.browser),\n node: Object.fromEntries(this._hashesWithNoSource.node),\n },\n };\n }\n\n set(input: Omit<PackageHashOptions, 'shouldRecalculate'>, hash: string): void {\n const { packagePath, isSourceHashingEnabled, targetEnvironment } = input;\n const map = (isSourceHashingEnabled ? this._hashesWithSource : this._hashesWithNoSource)[targetEnvironment];\n map.set(packagePath, hash);\n }\n\n extend(input: SerializablePackageHashesCache): void {\n // Helper function to merge an object's entries into a Map\n const extendMap = (map: Map<string, string>, obj: Record<string, string> = {}): void => {\n for (const [key, value] of Object.entries(obj)) {\n map.set(key, value);\n }\n };\n\n // Apply to all map collections\n extendMap(this._hashesWithSource.browser, input.hashesWithSource?.browser);\n extendMap(this._hashesWithSource.node, input.hashesWithSource?.node);\n extendMap(this._hashesWithNoSource.browser, input.hashesWithNoSource?.browser);\n extendMap(this._hashesWithNoSource.node, input.hashesWithNoSource?.node);\n }\n}\n"]}
1
+ {"version":3,"file":"PackageHashes.js","sourceRoot":"","sources":["../src/PackageHashes.ts"],"names":[],"mappings":"AASA,OAAO,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAE/C,OAAO,EAAE,mBAAmB,EAAE,MAAM,0BAA0B,CAAC;AAC/D,OAAO,EAAE,wBAAwB,EAAE,MAAM,+BAA+B,CAAC;AAgCzE;;GAEG;AACH,MAAM,OAAO,aAAa;IAaH;IAZrB,mEAAmE;IAClD,iBAAiB,GAAG;QACnC,OAAO,EAAE,IAAI,GAAG,EAAkB;QAClC,IAAI,EAAE,IAAI,GAAG,EAAkB;KAChC,CAAC;IACF,uEAAuE;IACtD,mBAAmB,GAAG;QACrC,OAAO,EAAE,IAAI,GAAG,EAAkB;QAClC,IAAI,EAAE,IAAI,GAAG,EAAkB;KAChC,CAAC;IACe,KAAK,CAAe;IAErC,YAAqB,OAA6B;QAA7B,YAAO,GAAP,OAAO,CAAsB;QAChD,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,CAA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iBAAiB,CAAC,IAAI,EAAE,KAAK,CAAC,gBAAgB,EAAE,IAAI,CAAC,CAAC;QACrE,SAAS,CAAC,IAAI,CAAC,mBAAmB,CAAC,OAAO,EAAE,KAAK,CAAC,kBAAkB,EAAE,OAAO,CAAC,CAAC;QAC/E,SAAS,CAAC,IAAI,CAAC,mBAAmB,CAAC,IAAI,EAAE,KAAK,CAAC,kBAAkB,EAAE,IAAI,CAAC,CAAC;IAC3E,CAAC;CACF","sourcesContent":["import type {\n CloudpackConfig,\n Features,\n PackageDefinitionsCache,\n PackageHashOptions,\n PackageHashesCache,\n ResolveMap,\n SerializablePackageHashesCache,\n} from '@ms-cloudpack/common-types';\nimport { hashPackage } from './hashPackage.js';\nimport type { HashFunction } from './types/HashFunction.js';\nimport { PackagePatchesCache } from './PackagePatchesCache.js';\nimport { BundlerCapabilitiesCache } from './BundlerCapabilitiesCache.js';\n\n/**\n * Constructor options for the PackageHashes class.\n *\n * (For `PackageHashes.get` options, see `PackageHashOptions`.)\n */\ntype PackageHashesOptions =\n | {\n /** Working directory used to find the project root (usually repository root). */\n cwd: string;\n /**\n * Context for the hash calculations.\n */\n context: {\n config: Pick<\n CloudpackConfig,\n 'patchFilesGlobPattern' | 'bundlerCapabilitiesRegistry' | 'defaultBundler' | 'define' | 'mode'\n > & {\n features?: Pick<Features, 'hmr'>;\n };\n packages: PackageDefinitionsCache;\n resolveMap: ResolveMap;\n };\n }\n | {\n /**\n * A function that returns the hash for a given package path. This is intended for testing purposes.\n */\n hash: HashFunction;\n };\n\n/**\n * Utility class for hashing packages and caching the results.\n */\nexport class PackageHashes implements PackageHashesCache {\n /** Mapping from package path to hash (considering source files) */\n private readonly _hashesWithSource = {\n browser: new Map<string, string>(),\n node: new Map<string, string>(),\n };\n /** Mapping from package path to hash (not considering source files) */\n private readonly _hashesWithNoSource = {\n browser: new Map<string, string>(),\n node: new Map<string, string>(),\n };\n private readonly _hash: HashFunction;\n\n constructor(readonly options: PackageHashesOptions) {\n if ('hash' in options) {\n this._hash = options.hash;\n return;\n }\n\n const { config } = options.context;\n const patches = new PackagePatchesCache({\n cwd: options.cwd,\n globPattern: config.patchFilesGlobPattern,\n });\n const bundlerCapabilitiesCache = new BundlerCapabilitiesCache(config.bundlerCapabilitiesRegistry);\n\n this._hash = (input) =>\n hashPackage({\n input,\n context: {\n ...options.context,\n patches,\n bundlerCapabilitiesCache,\n defaultBundler: config.defaultBundler,\n defineFlags: config.mode === 'production' ? (config.define ?? {}) : {},\n hmr: !!config.features?.hmr,\n },\n });\n }\n\n async get(input: PackageHashOptions): Promise<string> {\n const { packagePath, isSourceHashingEnabled, shouldRecalculate, targetEnvironment } = input;\n\n const map = (isSourceHashingEnabled ? this._hashesWithSource : this._hashesWithNoSource)[targetEnvironment];\n\n if (!shouldRecalculate && map.has(packagePath)) {\n return map.get(packagePath) as string;\n }\n\n const hash = await this._hash(input);\n\n map.set(packagePath, hash);\n\n return hash;\n }\n\n /**\n * Creates a serializable representation of the cache.\n */\n toSerializable(): SerializablePackageHashesCache {\n return {\n hashesWithSource: {\n browser: Object.fromEntries(this._hashesWithSource.browser),\n node: Object.fromEntries(this._hashesWithSource.node),\n },\n hashesWithNoSource: {\n browser: Object.fromEntries(this._hashesWithNoSource.browser),\n node: Object.fromEntries(this._hashesWithNoSource.node),\n },\n };\n }\n\n set(input: Omit<PackageHashOptions, 'shouldRecalculate'>, hash: string): void {\n const { packagePath, isSourceHashingEnabled, targetEnvironment } = input;\n const map = (isSourceHashingEnabled ? this._hashesWithSource : this._hashesWithNoSource)[targetEnvironment];\n map.set(packagePath, hash);\n }\n\n extend(input: SerializablePackageHashesCache): void {\n // Helper function to merge an object's entries into a Map\n const extendMap = (map: Map<string, string>, obj: Record<string, string> = {}): void => {\n for (const [key, value] of Object.entries(obj)) {\n map.set(key, value);\n }\n };\n\n // Apply to all map collections\n extendMap(this._hashesWithSource.browser, input.hashesWithSource?.browser);\n extendMap(this._hashesWithSource.node, input.hashesWithSource?.node);\n extendMap(this._hashesWithNoSource.browser, input.hashesWithNoSource?.browser);\n extendMap(this._hashesWithNoSource.node, input.hashesWithNoSource?.node);\n }\n}\n"]}
@@ -28,6 +28,8 @@ export interface PackageHashEntries {
28
28
  defaultBundler?: string;
29
29
  /** Define flags from the app config */
30
30
  defineFlags?: DefineFlags;
31
+ /** Whether HMR is enabled in the app config */
32
+ hmr?: boolean;
31
33
  }
32
34
  /**
33
35
  * Get an object that's used to calculate the hash of the package.
@@ -42,6 +44,8 @@ export declare function getPackageHashEntries(params: {
42
44
  defaultBundler: string | undefined;
43
45
  /** Define flags from the app config */
44
46
  defineFlags: DefineFlags | undefined;
47
+ /** Whether HMR is enabled in the app config */
48
+ hmr: boolean | undefined;
45
49
  };
46
50
  }): Promise<PackageHashEntries>;
47
51
  //# sourceMappingURL=getPackageHashEntries.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"getPackageHashEntries.d.ts","sourceRoot":"","sources":["../src/getPackageHashEntries.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,uBAAuB,EACvB,wBAAwB,EACxB,uBAAuB,EACvB,kBAAkB,EAClB,iBAAiB,EAClB,MAAM,4BAA4B,CAAC;AAEpC,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,yBAAyB,CAAC;AACnE,OAAO,EAAiB,KAAK,SAAS,EAAE,MAAM,oBAAoB,CAAC;AACnE,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,0BAA0B,CAAC;AACpE,OAAO,KAAK,EAAE,wBAAwB,EAAE,MAAM,+BAA+B,CAAC;AAC9E,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,oCAAoC,CAAC;AAEtE;;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,g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AAG,OAAO,CAAC,kBAAkB,CAAC,CA6D9B"}
@@ -6,7 +6,7 @@ import { getSourceHash } from './getSourceHash.js';
6
6
  export async function getPackageHashEntries(params) {
7
7
  const { options, context } = params;
8
8
  const { packagePath, targetEnvironment, isSourceHashingEnabled } = options;
9
- const { packages, patches, bundlerCapabilitiesCache, defaultBundler, defineFlags } = context;
9
+ const { packages, patches, bundlerCapabilitiesCache, defaultBundler, defineFlags, hmr } = context;
10
10
  const definition = await packages.get(packagePath);
11
11
  const originalDefinition = await packages.get(packagePath, { disableTransforms: true });
12
12
  const { name, version } = definition;
@@ -46,6 +46,9 @@ export async function getPackageHashEntries(params) {
46
46
  if (defineFlags) {
47
47
  result.defineFlags = defineFlags;
48
48
  }
49
+ if (hmr && !isExternal) {
50
+ result.hmr = hmr;
51
+ }
49
52
  return result;
50
53
  }
51
54
  //# sourceMappingURL=getPackageHashEntries.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"getPackageHashEntries.js","sourceRoot":"","sources":["../src/getPackageHashEntries.ts"],"names":[],"mappings":"AAOA,OAAO,EAAE,iBAAiB,EAAE,MAAM,8BAA8B,CAAC;AAEjE,OAAO,EAAE,aAAa,EAAkB,MAAM,oBAAoB,CAAC;AA+BnE;;GAEG;AACH,MAAM,CAAC,KAAK,UAAU,qBAAqB,CAAC,MAW3C;IACC,MAAM,EAAE,OAAO,EAAE,OAAO,EAAE,GAAG,MAAM,CAAC;IACpC,MAAM,EAAE,WAAW,EAAE,iBAAiB,EAAE,sBAAsB,EAAE,GAAG,OAAO,CAAC;IAC3E,MAAM,EAAE,QAAQ,EAAE,OAAO,EAAE,wBAAwB,EAAE,cAAc,EAAE,WAAW,EAAE,GAAG,OAAO,CAAC;IAE7F,MAAM,UAAU,GAAG,MAAM,QAAQ,CAAC,GAAG,CAAC,WAAW,CAAC,CAAC;IACnD,MAAM,kBAAkB,GAAG,MAAM,QAAQ,CAAC,GAAG,CAAC,WAAW,EAAE,EAAE,iBAAiB,EAAE,IAA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iB,GAAG,iBAAiB,CAAC;IAC/C,CAAC;IAED,IAAI,cAAc,EAAE,CAAC;QACnB,MAAM,CAAC,cAAc,GAAG,cAAc,CAAC;IACzC,CAAC;IAED,IAAI,WAAW,EAAE,CAAC;QAChB,MAAM,CAAC,WAAW,GAAG,WAAW,CAAC;IACnC,CAAC;IAED,OAAO,MAAM,CAAC;AAChB,CAAC","sourcesContent":["import type {\n PackageDefinitionsCache,\n PackageJsonCloudpackMeta,\n PackageJsonDependencies,\n PackageJsonExports,\n TargetEnvironment,\n} from '@ms-cloudpack/common-types';\nimport { isExternalPackage } from '@ms-cloudpack/path-utilities';\nimport type { HashFunctionOptions } from './types/HashFunction.js';\nimport { getSourceHash, type FilesHash } from './getSourceHash.js';\nimport type { PackagePatchesCache } from './PackagePatchesCache.js';\nimport type { BundlerCapabilitiesCache } from './BundlerCapabilitiesCache.js';\nimport type { DefineFlags } from '@ms-cloudpack/common-types-browser';\n\n/**\n * Values used to calculate the hash of a package.\n */\nexport interface PackageHashEntries {\n name: string;\n /** This will be the actual version if the package is external, or the path if it's internal. */\n version: string;\n exports: PackageJsonExports | undefined;\n dependencies: PackageJsonDependencies | undefined;\n peerDependencies: PackageJsonDependencies | undefined;\n /** Hash of files in the package. */\n filesHash: FilesHash | undefined;\n /** Content of any `.patch` file for the package. */\n patchFileContent: string | undefined;\n /** Subset of calculated package settings and other info saved under `PackageJson.cloudpack`. */\n packageSettings: Partial<PackageJsonCloudpackMeta>;\n /** Content of any bundler capabilities files for the package. */\n bundlerCapabilitiesContent?: Record<string, string>;\n /** Target environment, if not `'browser'` */\n targetEnvironment?: TargetEnvironment;\n /** Default bundler override, if set in config */\n defaultBundler?: string;\n /** Define flags from the app config */\n defineFlags?: DefineFlags;\n}\n\n/**\n * Get an object that's used to calculate the hash of the package.\n */\nexport async function getPackageHashEntries(params: {\n options: HashFunctionOptions;\n context: {\n packages: PackageDefinitionsCache;\n patches: PackagePatchesCache;\n bundlerCapabilitiesCache: BundlerCapabilitiesCache;\n /** Default bundler from the app config */\n defaultBundler: string | undefined;\n /** Define flags from the app config */\n defineFlags: DefineFlags | undefined;\n };\n}): Promise<PackageHashEntries> {\n const { options, context } = params;\n const { packagePath, targetEnvironment, isSourceHashingEnabled } = options;\n const { packages, patches, bundlerCapabilitiesCache, defaultBundler, defineFlags } = context;\n\n const definition = await packages.get(packagePath);\n const originalDefinition = await packages.get(packagePath, { disableTransforms: true });\n\n const { name, version } = definition;\n\n // This has the cached calculated package settings, with included and excluded deps removed.\n const packageSettings = { ...definition.cloudpack };\n\n const isExternal = isExternalPackage(packagePath);\n\n const filesHash =\n !isExternal && isSourceHashingEnabled\n ? await getSourceHash({ packagePath, inputPaths: packageSettings.inputPaths })\n : undefined;\n\n const patchFileContent = isExternal ? (await patches.getPackagePatch(definition))?.contents : undefined;\n\n // Only include a subset of package.json properties to reduce the amount hashed.\n const result: PackageHashEntries = {\n // This will be calculated by createPackageSettingsTransform and incorporates the original\n // exports as well as main and module.\n exports: definition.exports,\n // Use the original dependencies to ensure that the hash is consistent,\n // and unaffected by include and exclude changes.\n dependencies: originalDefinition.dependencies,\n peerDependencies: originalDefinition.peerDependencies,\n name,\n version: isExternal ? version : packagePath,\n filesHash,\n patchFileContent,\n packageSettings,\n };\n\n const bundlerCapabilitiesContent = await bundlerCapabilitiesCache.get(packageSettings.bundlerCapabilities);\n if (Object.keys(bundlerCapabilitiesContent || {}).length > 0) {\n result.bundlerCapabilitiesContent = bundlerCapabilitiesContent;\n }\n\n // Conditionally setting this prevents invalidating all cached content\n if (targetEnvironment !== 'browser') {\n result.targetEnvironment = targetEnvironment;\n }\n\n if (defaultBundler) {\n result.defaultBundler = defaultBundler;\n }\n\n if (defineFlags) {\n result.defineFlags = defineFlags;\n }\n\n return result;\n}\n"]}
1
+ {"version":3,"file":"getPackageHashEntries.js","sourceRoot":"","sources":["../src/getPackageHashEntries.ts"],"names":[],"mappings":"AAOA,OAAO,EAAE,iBAAiB,EAAE,MAAM,8BAA8B,CAA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EAAE,kBAAkB,CAAC,YAAY;QAC7C,gBAAgB,EAAE,kBAAkB,CAAC,gBAAgB;QACrD,IAAI;QACJ,OAAO,EAAE,UAAU,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,WAAW;QAC3C,SAAS;QACT,gBAAgB;QAChB,eAAe;KAChB,CAAC;IAEF,MAAM,0BAA0B,GAAG,MAAM,wBAAwB,CAAC,GAAG,CAAC,eAAe,CAAC,mBAAmB,CAAC,CAAC;IAC3G,IAAI,MAAM,CAAC,IAAI,CAAC,0BAA0B,IAAI,EAAE,CAAC,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;QAC7D,MAAM,CAAC,0BAA0B,GAAG,0BAA0B,CAAC;IACjE,CAAC;IAED,sEAAsE;IACtE,IAAI,iBAAiB,KAAK,SAAS,EAAE,CAAC;QACpC,MAAM,CAAC,iBAAiB,GAAG,iBAAiB,CAAC;IAC/C,CAAC;IAED,IAAI,cAAc,EAAE,CAAC;QACnB,MAAM,CAAC,cAAc,GAAG,cAAc,CAAC;IACzC,CAAC;IAED,IAAI,WAAW,EAAE,CAAC;QAChB,MAAM,CAAC,WAAW,GAAG,WAAW,CAAC;IACnC,CAAC;IAED,IAAI,GAAG,IAAI,CAAC,UAAU,EAAE,CAAC;QACvB,MAAM,CAAC,GAAG,GAAG,GAAG,CAAC;IACnB,CAAC;IAED,OAAO,MAAM,CAAC;AAChB,CAAC","sourcesContent":["import type {\n PackageDefinitionsCache,\n PackageJsonCloudpackMeta,\n PackageJsonDependencies,\n PackageJsonExports,\n TargetEnvironment,\n} from '@ms-cloudpack/common-types';\nimport { isExternalPackage } from '@ms-cloudpack/path-utilities';\nimport type { HashFunctionOptions } from './types/HashFunction.js';\nimport { getSourceHash, type FilesHash } from './getSourceHash.js';\nimport type { PackagePatchesCache } from './PackagePatchesCache.js';\nimport type { BundlerCapabilitiesCache } from './BundlerCapabilitiesCache.js';\nimport type { DefineFlags } from '@ms-cloudpack/common-types-browser';\n\n/**\n * Values used to calculate the hash of a package.\n */\nexport interface PackageHashEntries {\n name: string;\n /** This will be the actual version if the package is external, or the path if it's internal. */\n version: string;\n exports: PackageJsonExports | undefined;\n dependencies: PackageJsonDependencies | undefined;\n peerDependencies: PackageJsonDependencies | undefined;\n /** Hash of files in the package. */\n filesHash: FilesHash | undefined;\n /** Content of any `.patch` file for the package. */\n patchFileContent: string | undefined;\n /** Subset of calculated package settings and other info saved under `PackageJson.cloudpack`. */\n packageSettings: Partial<PackageJsonCloudpackMeta>;\n /** Content of any bundler capabilities files for the package. */\n bundlerCapabilitiesContent?: Record<string, string>;\n /** Target environment, if not `'browser'` */\n targetEnvironment?: TargetEnvironment;\n /** Default bundler override, if set in config */\n defaultBundler?: string;\n /** Define flags from the app config */\n defineFlags?: DefineFlags;\n /** Whether HMR is enabled in the app config */\n hmr?: boolean;\n}\n\n/**\n * Get an object that's used to calculate the hash of the package.\n */\nexport async function getPackageHashEntries(params: {\n options: HashFunctionOptions;\n context: {\n packages: PackageDefinitionsCache;\n patches: PackagePatchesCache;\n bundlerCapabilitiesCache: BundlerCapabilitiesCache;\n /** Default bundler from the app config */\n defaultBundler: string | undefined;\n /** Define flags from the app config */\n defineFlags: DefineFlags | undefined;\n /** Whether HMR is enabled in the app config */\n hmr: boolean | undefined;\n };\n}): Promise<PackageHashEntries> {\n const { options, context } = params;\n const { packagePath, targetEnvironment, isSourceHashingEnabled } = options;\n const { packages, patches, bundlerCapabilitiesCache, defaultBundler, defineFlags, hmr } = context;\n\n const definition = await packages.get(packagePath);\n const originalDefinition = await packages.get(packagePath, { disableTransforms: true });\n\n const { name, version } = definition;\n\n // This has the cached calculated package settings, with included and excluded deps removed.\n const packageSettings = { ...definition.cloudpack };\n\n const isExternal = isExternalPackage(packagePath);\n\n const filesHash =\n !isExternal && isSourceHashingEnabled\n ? await getSourceHash({ packagePath, inputPaths: packageSettings.inputPaths })\n : undefined;\n\n const patchFileContent = isExternal ? (await patches.getPackagePatch(definition))?.contents : undefined;\n\n // Only include a subset of package.json properties to reduce the amount hashed.\n const result: PackageHashEntries = {\n // This will be calculated by createPackageSettingsTransform and incorporates the original\n // exports as well as main and module.\n exports: definition.exports,\n // Use the original dependencies to ensure that the hash is consistent,\n // and unaffected by include and exclude changes.\n dependencies: originalDefinition.dependencies,\n peerDependencies: originalDefinition.peerDependencies,\n name,\n version: isExternal ? version : packagePath,\n filesHash,\n patchFileContent,\n packageSettings,\n };\n\n const bundlerCapabilitiesContent = await bundlerCapabilitiesCache.get(packageSettings.bundlerCapabilities);\n if (Object.keys(bundlerCapabilitiesContent || {}).length > 0) {\n result.bundlerCapabilitiesContent = bundlerCapabilitiesContent;\n }\n\n // Conditionally setting this prevents invalidating all cached content\n if (targetEnvironment !== 'browser') {\n result.targetEnvironment = targetEnvironment;\n }\n\n if (defaultBundler) {\n result.defaultBundler = defaultBundler;\n }\n\n if (defineFlags) {\n result.defineFlags = defineFlags;\n }\n\n if (hmr && !isExternal) {\n result.hmr = hmr;\n }\n\n return result;\n}\n"]}
@@ -17,6 +17,8 @@ export declare function hashPackage(params: {
17
17
  defaultBundler: string | undefined;
18
18
  /** Define flags from the app config */
19
19
  defineFlags: DefineFlags;
20
+ /** Whether HMR is enabled in the app config */
21
+ hmr: boolean | undefined;
20
22
  };
21
23
  }): Promise<string>;
22
24
  //# sourceMappingURL=hashPackage.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"hashPackage.d.ts","sourceRoot":"","sources":["../src/hashPackage.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,uBAAuB,EAAE,UAAU,EAAE,MAAM,4BAA4B,CAAC;AAGtF,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,0BAA0B,CAAC;AAEpE,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,yBAAyB,CAAC;AACnE,OAAO,KAAK,EAAE,wBAAwB,EAAE,MAAM,+BAA+B,CAAC;AAE9E,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,oCAAoC,CAAC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AE,WAAW,EAAE,CAAC,CAAC;YACpG,IAAI,KAAK,EAAE,CAAC;gBACV,cAAc,CAAC,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;YAClC,CAAC;QACH,CAAC;IACH,CAAC;IAED,MAAM,UAAU,GAAG,UAAU,CAAC,gBAAgB,EAAE;QAC9C,WAAW,EAAE,KAAK;QAClB,eAAe,EAAE,IAAI;QACrB,aAAa,EAAE,IAAI;QACnB,gBAAgB,EAAE,IAAI;QACtB,aAAa,EAAE,IAAI;KACpB,CAAC,CAAC;IAEH,MAAM,EAAE,IAAI,EAAE,OAAO,EAAE,GAAG,gBAAgB,CAAC,CAAC,CAAC,CAAC;IAC9C,MAAM,WAAW,GAAG,WAAW,CAAC,GAAG,EAAE,GAAG,KAAK,CAAC;IAC9C,SAAS,IAAI,WAAW,CAAC;IACzB,OAAO,CAAC,KAAK,CAAC,UAAU,IAAI,IAAI,OAAO,OAAO,WAAW,mBAAmB,SAAS,IAAI,CAAC,CAAC;IAE3F,OAAO,IAAI,WAAW,IAAI,UAAU,EAAE,CAAC;AACzC,CAAC","sourcesContent":["import type { PackageDefinitionsCache, ResolveMap } from '@ms-cloudpack/common-types';\nimport objectHash from 'object-hash';\nimport { getPackageHashEntries, type PackageHashEntries } from './getPackageHashEntries.js';\nimport type { PackagePatchesCache } from './PackagePatchesCache.js';\nimport { hashVersion } from './hashVersion.js';\nimport type { HashFunctionOptions } from './types/HashFunction.js';\nimport type { BundlerCapabilitiesCache } from './BundlerCapabilitiesCache.js';\nimport { findResolveMapEntry } from '@ms-cloudpack/package-utilities';\nimport type { DefineFlags } from '@ms-cloudpack/common-types-browser';\n\nlet totalTime = 0;\n\n/**\n * Calculate the hash for a package and its inlined dependencies.\n */\nexport async function hashPackage(params: {\n input: HashFunctionOptions;\n context: {\n packages: PackageDefinitionsCache;\n resolveMap: ResolveMap;\n patches: PackagePatchesCache;\n bundlerCapabilitiesCache: BundlerCapabilitiesCache;\n /** Default bundler from the app config */\n defaultBundler: string | undefined;\n /** Define flags from the app config */\n defineFlags: DefineFlags;\n };\n}): Promise<string> {\n const start = performance.now();\n const { input, context } = params;\n const { packagePath, ...hashOptions } = input;\n const { resolveMap } = context;\n\n const hashEntriesArray: PackageHashEntries[] = [];\n const packagesToHash: string[] = [packagePath];\n\n while (packagesToHash.length > 0) {\n const packageToHash = packagesToHash.pop();\n if (!packageToHash) {\n continue;\n }\n\n const hashEntries = await getPackageHashEntries({\n options: { ...hashOptions, packagePath: packageToHash },\n context,\n });\n\n hashEntriesArray.push(hashEntries);\n\n for (const dependency of hashEntries.packageSettings.inlinedDependencies || []) {\n const entry = findResolveMapEntry({ packageName: dependency, resolveMap, definition: hashEntries });\n if (entry) {\n packagesToHash.push(entry.path);\n }\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"]}
1
+ {"version":3,"file":"hashPackage.js","sourceRoot":"","sources":["../src/hashPackage.ts"],"names":[],"mappings":"AACA,OAAO,UAAU,MAAM,aAAa,CAAC;AACrC,OAAO,EAAE,qBAAqB,EAA2B,MAAM,4BAA4B,CAAC;AAE5F,OAAO,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAG/C,OAAO,EAAE,mBAAmB,EAAE,MAAM,iCAAiC,CAAC;AAGtE,IAAI,SAAS,GAAG,CAAC,CAAC;AAElB;;GAEG;AACH,MAAM,CAAC,KAAK,UAAU,WAAW,CAAC,MAcjC;IACC,MAAM,KAAK,GAAG,WAAW,CAAC,GAAG,EAAE,CAAC;IAChC,MAAM,EAAE,KAAK,EAAE,OAAO,EAAE,GAAG,MAAM,CAAC;IAClC,MAAM,EAAE,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I,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, ResolveMap } from '@ms-cloudpack/common-types';\nimport objectHash from 'object-hash';\nimport { getPackageHashEntries, type PackageHashEntries } from './getPackageHashEntries.js';\nimport type { PackagePatchesCache } from './PackagePatchesCache.js';\nimport { hashVersion } from './hashVersion.js';\nimport type { HashFunctionOptions } from './types/HashFunction.js';\nimport type { BundlerCapabilitiesCache } from './BundlerCapabilitiesCache.js';\nimport { findResolveMapEntry } from '@ms-cloudpack/package-utilities';\nimport type { DefineFlags } from '@ms-cloudpack/common-types-browser';\n\nlet totalTime = 0;\n\n/**\n * Calculate the hash for a package and its inlined dependencies.\n */\nexport async function hashPackage(params: {\n input: HashFunctionOptions;\n context: {\n packages: PackageDefinitionsCache;\n resolveMap: ResolveMap;\n patches: PackagePatchesCache;\n bundlerCapabilitiesCache: BundlerCapabilitiesCache;\n /** Default bundler from the app config */\n defaultBundler: string | undefined;\n /** Define flags from the app config */\n defineFlags: DefineFlags;\n /** Whether HMR is enabled in the app config */\n hmr: boolean | undefined;\n };\n}): Promise<string> {\n const start = performance.now();\n const { input, context } = params;\n const { packagePath, ...hashOptions } = input;\n const { resolveMap } = context;\n\n const hashEntriesArray: PackageHashEntries[] = [];\n const packagesToHash: string[] = [packagePath];\n\n while (packagesToHash.length > 0) {\n const packageToHash = packagesToHash.pop();\n if (!packageToHash) {\n continue;\n }\n\n const hashEntries = await getPackageHashEntries({\n options: { ...hashOptions, packagePath: packageToHash },\n context,\n });\n\n hashEntriesArray.push(hashEntries);\n\n for (const dependency of hashEntries.packageSettings.inlinedDependencies || []) {\n const entry = findResolveMapEntry({ packageName: dependency, resolveMap, definition: hashEntries });\n if (entry) {\n packagesToHash.push(entry.path);\n }\n }\n }\n\n const hashResult = objectHash(hashEntriesArray, {\n respectType: false,\n unorderedArrays: true,\n unorderedSets: true,\n unorderedObjects: true,\n ignoreUnknown: true,\n });\n\n const { name, version } = hashEntriesArray[0];\n const elapsedTime = performance.now() - start;\n totalTime += elapsedTime;\n console.debug(`Hashed ${name}@${version} in ${elapsedTime}ms, total time: ${totalTime}ms`);\n\n return `v${hashVersion}-${hashResult}`;\n}\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ms-cloudpack/package-hashes",
3
- "version": "0.8.47",
3
+ "version": "0.8.48",
4
4
  "description": "Utilities for hashing packages in Cloudpack",
5
5
  "license": "MIT",
6
6
  "type": "module",
@@ -24,12 +24,12 @@
24
24
  "test": "cloudpack-scripts test"
25
25
  },
26
26
  "dependencies": {
27
- "@ms-cloudpack/common-types": "^0.33.1",
28
- "@ms-cloudpack/common-types-browser": "^0.6.4",
29
- "@ms-cloudpack/config": "^0.38.22",
30
- "@ms-cloudpack/package-utilities": "^13.2.5",
31
- "@ms-cloudpack/path-string-parsing": "^1.2.7",
32
- "@ms-cloudpack/path-utilities": "^3.2.2",
27
+ "@ms-cloudpack/common-types": "^0.33.2",
28
+ "@ms-cloudpack/common-types-browser": "^0.6.5",
29
+ "@ms-cloudpack/config": "^0.38.23",
30
+ "@ms-cloudpack/package-utilities": "^13.2.6",
31
+ "@ms-cloudpack/path-string-parsing": "^1.3.0",
32
+ "@ms-cloudpack/path-utilities": "^3.2.3",
33
33
  "glob-hasher": "^1.4.2",
34
34
  "object-hash": "^3.0.0",
35
35
  "tinyglobby": "^0.2.13"