@ms-cloudpack/package-utilities 5.2.0 → 5.3.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/PackageDefinitions.d.ts +0 -12
- package/lib/PackageDefinitions.d.ts.map +1 -1
- package/lib/PackageDefinitions.js +0 -36
- package/lib/PackageDefinitions.js.map +1 -1
- package/lib/addImportMapHash.d.ts +9 -6
- package/lib/addImportMapHash.d.ts.map +1 -1
- package/lib/addImportMapHash.js +8 -15
- package/lib/addImportMapHash.js.map +1 -1
- package/package.json +4 -6
|
@@ -5,7 +5,6 @@ export declare class PackageDefinitions implements PackageDefinitionsCache {
|
|
|
5
5
|
private _config;
|
|
6
6
|
private _transforms;
|
|
7
7
|
private _transformFactories;
|
|
8
|
-
private _hashes;
|
|
9
8
|
/**
|
|
10
9
|
* Constructor for PackageDefinitions.
|
|
11
10
|
* @param definitionCache - The map of package paths to package definitions, used mainly for testing.
|
|
@@ -29,16 +28,5 @@ export declare class PackageDefinitions implements PackageDefinitionsCache {
|
|
|
29
28
|
reset(options?: {
|
|
30
29
|
newConfig?: unknown;
|
|
31
30
|
}): 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;
|
|
43
31
|
}
|
|
44
32
|
//# 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;AACpH,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;IAElF;;;;;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;CAWxC"}
|
|
@@ -1,8 +1,6 @@
|
|
|
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';
|
|
6
4
|
export class PackageDefinitions {
|
|
7
5
|
/**
|
|
8
6
|
* Constructor for PackageDefinitions.
|
|
@@ -17,7 +15,6 @@ export class PackageDefinitions {
|
|
|
17
15
|
this._config = config;
|
|
18
16
|
this._transforms = [applyOverrides];
|
|
19
17
|
this._transformFactories = [];
|
|
20
|
-
this._hashes = new Map();
|
|
21
18
|
}
|
|
22
19
|
async get(packagePath, options) {
|
|
23
20
|
let definition = this._definitions[packagePath];
|
|
@@ -72,38 +69,5 @@ export class PackageDefinitions {
|
|
|
72
69
|
this._transforms = [applyOverrides, ...this._transformFactories.map((factory) => factory(newConfig))];
|
|
73
70
|
}
|
|
74
71
|
}
|
|
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
|
-
}
|
|
108
72
|
}
|
|
109
73
|
//# sourceMappingURL=PackageDefinitions.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"PackageDefinitions.js","sourceRoot":"","sources":["../src/PackageDefinitions.ts"],"names":[],"mappings":"AAAA,OAAO,IAAI,MAAM,MAAM,CAAC;AACxB,OAAO,EAAE,cAAc,EAAE,MAAM,iCAAiC,CAAC;AACjE,OAAO,EAAE,QAAQ,EAAE,MAAM,8BAA8B,CAAC;AAExD,
|
|
1
|
+
{"version":3,"file":"PackageDefinitions.js","sourceRoot":"","sources":["../src/PackageDefinitions.ts"],"names":[],"mappings":"AAAA,OAAO,IAAI,MAAM,MAAM,CAAC;AACxB,OAAO,EAAE,cAAc,EAAE,MAAM,iCAAiC,CAAC;AACjE,OAAO,EAAE,QAAQ,EAAE,MAAM,8BAA8B,CAAC;AAExD,MAAM,OAAO,kBAAkB;IAO7B;;;;;OAKG;IACH,YAAY,kBAA+C,EAAE,EAAE,MAAgB;QATvE,gBAAW,GAAiC,EAAE,CAAC;QAUrD,IAAI,CAAC,YAAY,GAAG,eAAe,CAAC;QACpC,IAAI,CAAC,uBAAuB,GAAG,EAAE,CAAC;QAClC,IAAI,CAAC,OAAO,GAAG,MAAM,CAAC;QACtB,IAAI,CAAC,WAAW,GAAG,CAAC,cAAc,CAAC,CAAC;QACpC,IAAI,CAAC,mBAAmB,GAAG,EAAE,CAAC;IAChC,CAAC;IAED,KAAK,CAAC,GAAG,CACP,WAAmB,EACnB,OAA4D;QAE5D,IAAI,UAAU,GAA4B,IAAI,CAAC,YAAY,CAAC,WAAW,CAAC,CAAC;QACzE,IAAI,qBAAqB,GAA4B,IAAI,CAAC,uBAAuB,CAAC,WAAW,CAAC,CAAC;QAC/F,MAAM,EAAE,OAAO,EAAE,iBAAiB,EAAE,GAAG,OAAO,IAAI,EAAE,CAAC;QAErD,+DAA+D;QAC/D,IAAI,CAAC,OAAO,EAAE;YACZ,IAAI,iBAAiB,IAAI,UAAU,EAAE;gBACnC,OAAO,UAAU,CAAC;aACnB;YAED,IAAI,CAAC,iBAAiB,IAAI,qBAAqB,EAAE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AS,CAAC;YACzB,IAAI,CAAC,WAAW,GAAG,CAAC,cAAc,EAAE,GAAG,IAAI,CAAC,mBAAmB,CAAC,GAAG,CAAC,CAAC,OAAO,EAAE,EAAE,CAAC,OAAO,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC;SACvG;IACH,CAAC;CACF","sourcesContent":["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';\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\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"]}
|
|
@@ -3,13 +3,16 @@ import type { ResolveMap } from './types/ResolveMap.js';
|
|
|
3
3
|
import type { PackageImportPaths } from './PackageImportPaths.js';
|
|
4
4
|
/**
|
|
5
5
|
* Adds hash to import map for a package.
|
|
6
|
-
* @param
|
|
7
|
-
* @param
|
|
8
|
-
* @param resolveMap Resolve map to use
|
|
9
|
-
* @param hash Hash to add
|
|
10
|
-
* @param context Context
|
|
6
|
+
* @param options - Options object containing package name, version, import map, resolve map, and optionally hash
|
|
7
|
+
* @param context - Context object containing package import paths
|
|
11
8
|
*/
|
|
12
|
-
export declare function addImportMapHash(
|
|
9
|
+
export declare function addImportMapHash(options: {
|
|
10
|
+
packageName: string;
|
|
11
|
+
version: string;
|
|
12
|
+
importMap: ImportMap | undefined;
|
|
13
|
+
resolveMap: ResolveMap;
|
|
14
|
+
hash?: string;
|
|
15
|
+
}, context: {
|
|
13
16
|
packageImportPaths: PackageImportPaths;
|
|
14
17
|
}): void;
|
|
15
18
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"addImportMapHash.d.ts","sourceRoot":"","sources":["../src/addImportMapHash.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,sBAAsB,CAAC;AACtD,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,uBAAuB,CAAC;AACxD,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,yBAAyB,CAAC;AAElE
|
|
1
|
+
{"version":3,"file":"addImportMapHash.d.ts","sourceRoot":"","sources":["../src/addImportMapHash.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,sBAAsB,CAAC;AACtD,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,uBAAuB,CAAC;AACxD,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,yBAAyB,CAAC;AAElE;;;;GAIG;AACH,wBAAgB,gBAAgB,CAC9B,OAAO,EAAE;IACP,WAAW,EAAE,MAAM,CAAC;IACpB,OAAO,EAAE,MAAM,CAAC;IAChB,SAAS,EAAE,SAAS,GAAG,SAAS,CAAC;IACjC,UAAU,EAAE,UAAU,CAAC;IACvB,IAAI,CAAC,EAAE,MAAM,CAAC;CACf,EACD,OAAO,EAAE;IAAE,kBAAkB,EAAE,kBAAkB,CAAA;CAAE,QAyCpD;AAED;;;;;;;GAOG;AACH,wBAAgB,UAAU,CAAC,GAAG,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,MAAM,CAehF"}
|
package/lib/addImportMapHash.js
CHANGED
|
@@ -1,17 +1,15 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Adds hash to import map for a package.
|
|
3
|
-
* @param
|
|
4
|
-
* @param
|
|
5
|
-
* @param resolveMap Resolve map to use
|
|
6
|
-
* @param hash Hash to add
|
|
7
|
-
* @param context Context
|
|
3
|
+
* @param options - Options object containing package name, version, import map, resolve map, and optionally hash
|
|
4
|
+
* @param context - Context object containing package import paths
|
|
8
5
|
*/
|
|
9
|
-
export function addImportMapHash(
|
|
6
|
+
export function addImportMapHash(options, context) {
|
|
7
|
+
const { packageName, version, importMap, resolveMap, hash = 'pending' } = options;
|
|
8
|
+
const { packageImportPaths } = context;
|
|
9
|
+
const resolveEntry = resolveMap[packageName];
|
|
10
10
|
if (!importMap) {
|
|
11
11
|
return;
|
|
12
12
|
}
|
|
13
|
-
const { packageImportPaths } = context;
|
|
14
|
-
const resolveEntry = resolveMap[packageName];
|
|
15
13
|
if (!resolveEntry) {
|
|
16
14
|
throw new Error(`Could not find package ${packageName} in the resolve map.`);
|
|
17
15
|
}
|
|
@@ -57,15 +55,10 @@ export function addHashUrl(url, packageUrl, hash) {
|
|
|
57
55
|
if (search !== -1) {
|
|
58
56
|
const hashIndex = search + packageUrl.length;
|
|
59
57
|
const prefix = 'h-';
|
|
60
|
-
const pending = 'pending';
|
|
61
58
|
if (url.startsWith(prefix, hashIndex + 1)) {
|
|
62
59
|
// Replace hash if it already exists
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
}
|
|
66
|
-
else {
|
|
67
|
-
url = url.slice(0, hashIndex) + `/h-${hash}` + url.slice(hashIndex + hash.length + prefix.length + 1);
|
|
68
|
-
}
|
|
60
|
+
const hashEnd = url.indexOf('/', hashIndex + prefix.length + 1);
|
|
61
|
+
url = url.slice(0, hashIndex) + `/h-${hash}` + url.slice(hashEnd);
|
|
69
62
|
}
|
|
70
63
|
else {
|
|
71
64
|
// Add hash after name and version
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"addImportMapHash.js","sourceRoot":"","sources":["../src/addImportMapHash.ts"],"names":[],"mappings":"AAIA
|
|
1
|
+
{"version":3,"file":"addImportMapHash.js","sourceRoot":"","sources":["../src/addImportMapHash.ts"],"names":[],"mappings":"AAIA;;;;GAIG;AACH,MAAM,UAAU,gBAAgB,CAC9B,OAMC,EACD,OAAmD;IAEnD,MAAM,EAAE,WAAW,EAAE,OAAO,EAAE,SAAS,EAAE,UAA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AAO,CAAC,CAAC;SACnE;aAAM;YACL,kCAAkC;YAClC,GAAG,GAAG,GAAG,CAAC,KAAK,CAAC,CAAC,EAAE,SAAS,CAAC,GAAG,MAAM,IAAI,EAAE,GAAG,GAAG,CAAC,KAAK,CAAC,SAAS,CAAC,CAAC;SACrE;KACF;IACD,OAAO,GAAG,CAAC;AACb,CAAC","sourcesContent":["import type { ImportMap } from './createImportMap.js';\nimport type { ResolveMap } from './types/ResolveMap.js';\nimport type { PackageImportPaths } from './PackageImportPaths.js';\n\n/**\n * Adds hash to import map for a package.\n * @param options - Options object containing package name, version, import map, resolve map, and optionally hash\n * @param context - Context object containing package import paths\n */\nexport function addImportMapHash(\n options: {\n packageName: string;\n version: string;\n importMap: ImportMap | undefined;\n resolveMap: ResolveMap;\n hash?: string;\n },\n context: { packageImportPaths: PackageImportPaths },\n) {\n const { packageName, version, importMap, resolveMap, hash = 'pending' } = options;\n const { packageImportPaths } = context;\n const resolveEntry = resolveMap[packageName];\n\n if (!importMap) {\n return;\n }\n\n if (!resolveEntry) {\n throw new Error(`Could not find package ${packageName} in the resolve map.`);\n }\n\n if (version === resolveEntry.version) {\n // Package is not scoped\n const entry = resolveEntry;\n const packageUrl = `${entry.name}@${entry.version}`;\n const importPaths = packageImportPaths.get(entry.path);\n importPaths.forEach((importPath) => {\n importMap.imports[importPath] = addHashUrl(importMap.imports[importPath], packageUrl, hash);\n });\n } else if (resolveEntry.scopedVersions?.[version] !== undefined && importMap.scopes) {\n // Package is scoped\n const entry = resolveEntry.scopedVersions?.[version];\n if (!entry) {\n throw new Error(`Could not find package ${packageName}@${version} in the resolve map.`);\n }\n const packageUrl = `${entry.name}@${entry.version}`;\n const importPaths = packageImportPaths.get(entry.path);\n const bundleServerUrl = new URL(Object.values(importMap.imports)[0]).origin;\n for (const requiredById of Object.keys(entry.requiredBy)) {\n const key = `${bundleServerUrl}/${requiredById}/`;\n importPaths.forEach((importPath) => {\n if (!importMap.scopes) {\n return;\n }\n importMap.scopes[key][importPath] = addHashUrl(importMap.scopes[key][importPath], packageUrl, hash);\n });\n }\n }\n}\n\n/**\n * Adds hash after name and version.\n * If hash already exists, replaces it.\n * @param url URL to add hash to\n * @param packageUrl Package name and version\n * @param hash Hash to add\n * @returns URL with hash\n */\nexport function addHashUrl(url: string, packageUrl: string, hash: string): string {\n const search = url.indexOf(packageUrl);\n if (search !== -1) {\n const hashIndex = search + packageUrl.length;\n const prefix = 'h-';\n if (url.startsWith(prefix, hashIndex + 1)) {\n // Replace hash if it already exists\n const hashEnd = url.indexOf('/', hashIndex + prefix.length + 1);\n url = url.slice(0, hashIndex) + `/h-${hash}` + url.slice(hashEnd);\n } else {\n // Add hash after name and version\n url = url.slice(0, hashIndex) + `/h-${hash}` + url.slice(hashIndex);\n }\n }\n return url;\n}\n"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ms-cloudpack/package-utilities",
|
|
3
|
-
"version": "5.
|
|
3
|
+
"version": "5.3.1",
|
|
4
4
|
"description": "Utilities for resolving/parsing packages and their imports.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"type": "module",
|
|
@@ -14,23 +14,21 @@
|
|
|
14
14
|
}
|
|
15
15
|
},
|
|
16
16
|
"dependencies": {
|
|
17
|
-
"@ms-cloudpack/bundler-types": "^0.
|
|
17
|
+
"@ms-cloudpack/bundler-types": "^0.20.0",
|
|
18
18
|
"@ms-cloudpack/json-utilities": "^0.0.8",
|
|
19
|
-
"@ms-cloudpack/package-overrides": "^0.4.
|
|
19
|
+
"@ms-cloudpack/package-overrides": "^0.4.8",
|
|
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",
|
|
24
23
|
"merge": "^2.1.1",
|
|
25
24
|
"resolve": "^1.22.0",
|
|
26
25
|
"semver": "^7.3.7",
|
|
27
|
-
"workspace-tools": "^0.
|
|
26
|
+
"workspace-tools": "^0.36.3"
|
|
28
27
|
},
|
|
29
28
|
"devDependencies": {
|
|
30
29
|
"@ms-cloudpack/eslint-plugin-internal": "*",
|
|
31
30
|
"@ms-cloudpack/scripts": "*",
|
|
32
31
|
"@ms-cloudpack/test-utilities": "*",
|
|
33
|
-
"@types/object-hash": "^3.0.2",
|
|
34
32
|
"@types/resolve": "^1.20.2"
|
|
35
33
|
},
|
|
36
34
|
"scripts": {
|