@ms-cloudpack/package-utilities 5.1.10 → 5.1.11
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.
|
@@ -5,6 +5,7 @@ export declare class PackageDefinitions implements PackageDefinitionsCache {
|
|
|
5
5
|
private _config;
|
|
6
6
|
private _transforms;
|
|
7
7
|
private _transformFactories;
|
|
8
|
+
private _hashes;
|
|
8
9
|
/**
|
|
9
10
|
* Constructor for PackageDefinitions.
|
|
10
11
|
* @param definitionCache - The map of package paths to package definitions, used mainly for testing.
|
|
@@ -28,5 +29,16 @@ export declare class PackageDefinitions implements PackageDefinitionsCache {
|
|
|
28
29
|
reset(options?: {
|
|
29
30
|
newConfig?: unknown;
|
|
30
31
|
}): void;
|
|
32
|
+
/**
|
|
33
|
+
* Gets the hash for a given package path. This is useful for caching, to determine if the package has changed.
|
|
34
|
+
* @param packagePath - The package path to get the hash for.
|
|
35
|
+
* @returns The hash for the package.
|
|
36
|
+
*/
|
|
37
|
+
getHash(packagePath: string): Promise<string>;
|
|
38
|
+
/**
|
|
39
|
+
* Removes the hash for a given package path.
|
|
40
|
+
* @param packagePath - The package path to remove the hash for.
|
|
41
|
+
*/
|
|
42
|
+
removeHash(packagePath: string): void;
|
|
31
43
|
}
|
|
32
44
|
//# sourceMappingURL=PackageDefinitions.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"PackageDefinitions.d.ts","sourceRoot":"","sources":["../src/PackageDefinitions.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,WAAW,EAAE,0BAA0B,EAAE,uBAAuB,EAAE,MAAM,6BAA6B,CAAC;
|
|
1
|
+
{"version":3,"file":"PackageDefinitions.d.ts","sourceRoot":"","sources":["../src/PackageDefinitions.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,WAAW,EAAE,0BAA0B,EAAE,uBAAuB,EAAE,MAAM,6BAA6B,CAAC;AAIpH,qBAAa,kBAAmB,YAAW,uBAAuB;IAChE,OAAO,CAAC,YAAY,CAA8B;IAClD,OAAO,CAAC,uBAAuB,CAA8B;IAC7D,OAAO,CAAC,OAAO,CAAU;IACzB,OAAO,CAAC,WAAW,CAAoC;IACvD,OAAO,CAAC,mBAAmB,CAAuD;IAClF,OAAO,CAAC,OAAO,CAA6B;IAE5C;;;;;OAKG;gBACS,eAAe,GAAE,MAAM,CAAC,MAAM,EAAE,WAAW,CAAM,EAAE,MAAM,CAAC,EAAE,OAAO;IAQzE,GAAG,CACP,WAAW,EAAE,MAAM,EACnB,OAAO,CAAC,EAAE;QAAE,OAAO,CAAC,EAAE,OAAO,CAAC;QAAC,iBAAiB,CAAC,EAAE,OAAO,CAAA;KAAE,GAC3D,OAAO,CAAC,WAAW,GAAG,SAAS,CAAC;IAwCnC;;;;OAIG;IACH,iBAAiB,CAAC,OAAO,EAAE,CAAC,MAAM,CAAC,EAAE,OAAO,KAAK,0BAA0B;IAO3E;;OAEG;IACH,KAAK,CAAC,OAAO,CAAC,EAAE;QAAE,SAAS,CAAC,EAAE,OAAO,CAAA;KAAE;IAYvC;;;;OAIG;IACG,OAAO,CAAC,WAAW,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC;IA2BnD;;;OAGG;IACH,UAAU,CAAC,WAAW,EAAE,MAAM;CAG/B"}
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import path from 'path';
|
|
2
2
|
import { applyOverrides } from '@ms-cloudpack/package-overrides';
|
|
3
3
|
import { readJson } from '@ms-cloudpack/json-utilities';
|
|
4
|
+
import hash from 'object-hash';
|
|
5
|
+
import { isExternalPackage } from './isExternalPackage.js';
|
|
4
6
|
export class PackageDefinitions {
|
|
5
7
|
/**
|
|
6
8
|
* Constructor for PackageDefinitions.
|
|
@@ -10,6 +12,7 @@ export class PackageDefinitions {
|
|
|
10
12
|
*/
|
|
11
13
|
constructor(definitionCache = {}, config) {
|
|
12
14
|
this._transforms = [];
|
|
15
|
+
this._hashes = new Map();
|
|
13
16
|
this._definitions = definitionCache;
|
|
14
17
|
this._transformedDefinitions = {};
|
|
15
18
|
this._config = config;
|
|
@@ -69,5 +72,38 @@ export class PackageDefinitions {
|
|
|
69
72
|
this._transforms = [applyOverrides, ...this._transformFactories.map((factory) => factory(newConfig))];
|
|
70
73
|
}
|
|
71
74
|
}
|
|
75
|
+
/**
|
|
76
|
+
* Gets the hash for a given package path. This is useful for caching, to determine if the package has changed.
|
|
77
|
+
* @param packagePath - The package path to get the hash for.
|
|
78
|
+
* @returns The hash for the package.
|
|
79
|
+
*/
|
|
80
|
+
async getHash(packagePath) {
|
|
81
|
+
if (this._hashes.has(packagePath)) {
|
|
82
|
+
return this._hashes.get(packagePath);
|
|
83
|
+
}
|
|
84
|
+
const definition = await this.get(packagePath);
|
|
85
|
+
if (!definition) {
|
|
86
|
+
throw new Error(`Package definition (package.json) missing or invalid at "${packagePath}"`);
|
|
87
|
+
}
|
|
88
|
+
const { name, version } = definition;
|
|
89
|
+
if (!name) {
|
|
90
|
+
throw new Error(`Package definition (package.json) missing name at "${packagePath}"`);
|
|
91
|
+
}
|
|
92
|
+
const isExternal = isExternalPackage(packagePath);
|
|
93
|
+
const bundleId = hash({
|
|
94
|
+
name,
|
|
95
|
+
...definition,
|
|
96
|
+
version: (isExternal ? version : packagePath) || packagePath,
|
|
97
|
+
});
|
|
98
|
+
this._hashes.set(packagePath, bundleId);
|
|
99
|
+
return bundleId;
|
|
100
|
+
}
|
|
101
|
+
/**
|
|
102
|
+
* Removes the hash for a given package path.
|
|
103
|
+
* @param packagePath - The package path to remove the hash for.
|
|
104
|
+
*/
|
|
105
|
+
removeHash(packagePath) {
|
|
106
|
+
this._hashes.delete(packagePath);
|
|
107
|
+
}
|
|
72
108
|
}
|
|
73
109
|
//# sourceMappingURL=PackageDefinitions.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"PackageDefinitions.js","sourceRoot":"","sources":["../src/PackageDefinitions.ts"],"names":[],"mapp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ent":["import path from 'path';\nimport { applyOverrides } from '@ms-cloudpack/package-overrides';\nimport { readJson } from '@ms-cloudpack/json-utilities';\nimport type { PackageJson, PackageDefinitionTransform, PackageDefinitionsCache } from '@ms-cloudpack/bundler-types';\nimport hash from 'object-hash';\nimport { isExternalPackage } from './isExternalPackage.js';\n\nexport class PackageDefinitions implements PackageDefinitionsCache {\n private _definitions: Record<string, PackageJson>;\n private _transformedDefinitions: Record<string, PackageJson>;\n private _config: unknown;\n private _transforms: PackageDefinitionTransform[] = [];\n private _transformFactories: ((config?: unknown) => PackageDefinitionTransform)[];\n private _hashes = new Map<string, string>();\n\n /**\n * Constructor for PackageDefinitions.\n * @param definitionCache - The map of package paths to package definitions, used mainly for testing.\n * @param config - The optional config object to pass to transforms. When `reset` is called with a new value, the\n * transforms will be re-created using the new config.\n */\n constructor(definitionCache: Record<string, PackageJson> = {}, config?: unknown) {\n this._definitions = definitionCache;\n this._transformedDefinitions = {};\n this._config = config;\n this._transforms = [applyOverrides];\n this._transformFactories = [];\n }\n\n async get(\n packagePath: string,\n options?: { refresh?: boolean; disableTransforms?: boolean },\n ): Promise<PackageJson | undefined> {\n let definition: PackageJson | undefined = this._definitions[packagePath];\n let transformedDefinition: PackageJson | undefined = this._transformedDefinitions[packagePath];\n const { refresh, disableTransforms } = options || {};\n\n // If we already have the answer they need, return immediately.\n if (!refresh) {\n if (disableTransforms && definition) {\n return definition;\n }\n\n if (!disableTransforms && transformedDefinition) {\n return transformedDefinition;\n }\n }\n\n // If we don't have the definition, try to load it.\n if (!definition || refresh) {\n definition = await readJson(path.join(packagePath, 'package.json'));\n\n if (!definition) {\n return undefined;\n }\n\n this._definitions[packagePath] = definition;\n }\n\n // If we don't want to skip the transform, transform the definition.\n if (!disableTransforms && (!transformedDefinition || refresh)) {\n for (const transform of this._transforms) {\n transformedDefinition =\n (await transform(transformedDefinition || definition, packagePath, this)) || transformedDefinition;\n }\n\n this._transformedDefinitions[packagePath] = transformedDefinition;\n }\n\n return (!disableTransforms && transformedDefinition) || definition;\n }\n\n /**\n * Registers a transform factory function, which will be called on initialization, and when reset, to re-generate\n * the transform function. Transform functions are called only when the package definition hasn't been loaded before,\n * and the result will be cached. Calling `reset` will reset the cache.\n */\n registerTransform(factory: (config?: unknown) => PackageDefinitionTransform) {\n this._transformFactories.push(factory);\n this._transforms.push(factory(this._config));\n\n this.reset();\n }\n\n /**\n * Resets the cache of package definitions. This is useful when testing, to ensure that the cache is empty.\n */\n reset(options?: { newConfig?: unknown }) {\n this._definitions = {};\n this._transformedDefinitions = {};\n\n const { newConfig } = options || {};\n\n if (newConfig) {\n this._config = newConfig;\n this._transforms = [applyOverrides, ...this._transformFactories.map((factory) => factory(newConfig))];\n }\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 * @param packagePath - The package path to get the hash for.\n * @returns The hash for the package.\n */\n async getHash(packagePath: string): Promise<string> {\n if (this._hashes.has(packagePath)) {\n return this._hashes.get(packagePath) as string;\n }\n\n const definition = await this.get(packagePath);\n if (!definition) {\n throw new Error(`Package definition (package.json) missing or invalid at \"${packagePath}\"`);\n }\n\n const { name, version } = definition;\n if (!name) {\n throw new Error(`Package definition (package.json) missing name at \"${packagePath}\"`);\n }\n\n const isExternal = isExternalPackage(packagePath);\n const bundleId = hash({\n name,\n ...definition,\n version: (isExternal ? version : packagePath) || packagePath,\n });\n\n this._hashes.set(packagePath, bundleId);\n\n return bundleId;\n }\n\n /**\n * Removes the hash for a given package path.\n * @param packagePath - The package path to remove the hash for.\n */\n removeHash(packagePath: string) {\n this._hashes.delete(packagePath);\n }\n}\n"]}
|
package/lib/tsdoc-metadata.json
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ms-cloudpack/package-utilities",
|
|
3
|
-
"version": "5.1.
|
|
3
|
+
"version": "5.1.11",
|
|
4
4
|
"description": "Utilities for resolving/parsing packages and their imports.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"type": "module",
|
|
@@ -14,12 +14,13 @@
|
|
|
14
14
|
}
|
|
15
15
|
},
|
|
16
16
|
"dependencies": {
|
|
17
|
-
"@ms-cloudpack/bundler-types": "^0.19.
|
|
17
|
+
"@ms-cloudpack/bundler-types": "^0.19.3",
|
|
18
18
|
"@ms-cloudpack/json-utilities": "^0.0.8",
|
|
19
|
-
"@ms-cloudpack/package-overrides": "^0.4.
|
|
19
|
+
"@ms-cloudpack/package-overrides": "^0.4.6",
|
|
20
20
|
"@ms-cloudpack/path-utilities": "^2.3.5",
|
|
21
21
|
"@ms-cloudpack/path-string-parsing": "^1.1.1",
|
|
22
22
|
"fast-glob": "^3.2.12",
|
|
23
|
+
"object-hash": "^3.0.0",
|
|
23
24
|
"merge": "^2.1.1",
|
|
24
25
|
"resolve": "^1.22.0",
|
|
25
26
|
"semver": "^7.3.7",
|
|
@@ -29,6 +30,7 @@
|
|
|
29
30
|
"@ms-cloudpack/eslint-plugin-internal": "*",
|
|
30
31
|
"@ms-cloudpack/scripts": "*",
|
|
31
32
|
"@ms-cloudpack/test-utilities": "*",
|
|
33
|
+
"@types/object-hash": "^3.0.2",
|
|
32
34
|
"@types/resolve": "^1.20.2"
|
|
33
35
|
},
|
|
34
36
|
"scripts": {
|