@ms-cloudpack/package-utilities 5.3.0 → 5.3.2
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.
|
@@ -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,UAAU,EAAE,IAAI,GAAG,SAAS,EAAE,GAAG,OAAO,CAAC;IAClF,MAAM,EAAE,kBAAkB,EAAE,GAAG,OAAO,CAAC;IACvC,MAAM,YAAY,GAAG,UAAU,CAAC,WAAW,CAAC,CAAC;IAE7C,IAAI,CAAC,SAAS,EAAE;QACd,OAAO;KACR;IAED,IAAI,CAAC,YAAY,EAAE;QACjB,MAAM,IAAI,KAAK,CAAC,0BAA0B,WAAW,sBAAsB,CAAC,CAAC;KAC9E;IAED,IAAI,OAAO,KAAK,YAAY,CAAC,OAAO,EAAE;QACpC,wBAAwB;QACxB,MAAM,KAAK,GAAG,YAAY,CAAC;QAC3B,MAAM,UAAU,GAAG,GAAG,KAAK,CAAC,IAAI,IAAI,KAAK,CAAC,OAA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UAAU,CAAC,SAAS,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,UAAU,CAAC,EAAE,UAAU,EAAE,IAAI,CAAC,CAAC;YACtG,CAAC,CAAC,CAAC;SACJ;KACF;AACH,CAAC;AAED;;;;;;;GAOG;AACH,MAAM,UAAU,UAAU,CAAC,GAAW,EAAE,UAAkB,EAAE,IAAY;IACtE,MAAM,MAAM,GAAG,GAAG,CAAC,OAAO,CAAC,UAAU,CAAC,CAAC;IACvC,IAAI,MAAM,KAAK,CAAC,CAAC,EAAE;QACjB,MAAM,SAAS,GAAG,MAAM,GAAG,UAAU,CAAC,MAAM,CAAC;QAC7C,MAAM,MAAM,GAAG,IAAI,CAAC;QACpB,IAAI,GAAG,CAAC,UAAU,CAAC,MAAM,EAAE,SAAS,GAAG,CAAC,CAAC,EAAE;YACzC,oCAAoC;YACpC,MAAM,OAAO,GAAG,GAAG,CAAC,OAAO,CAAC,GAAG,EAAE,SAAS,GAAG,MAAM,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC;YAChE,GAAG,GAAG,GAAG,CAAC,KAAK,CAAC,CAAC,EAAE,SAAS,CAAC,GAAG,MAAM,IAAI,EAAE,GAAG,GAAG,CAAC,KAAK,CAAC,OAAO,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.
|
|
3
|
+
"version": "5.3.2",
|
|
4
4
|
"description": "Utilities for resolving/parsing packages and their imports.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"type": "module",
|
|
@@ -15,7 +15,7 @@
|
|
|
15
15
|
},
|
|
16
16
|
"dependencies": {
|
|
17
17
|
"@ms-cloudpack/bundler-types": "^0.20.0",
|
|
18
|
-
"@ms-cloudpack/json-utilities": "^0.0
|
|
18
|
+
"@ms-cloudpack/json-utilities": "^0.1.0",
|
|
19
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",
|
|
@@ -23,7 +23,7 @@
|
|
|
23
23
|
"merge": "^2.1.1",
|
|
24
24
|
"resolve": "^1.22.0",
|
|
25
25
|
"semver": "^7.3.7",
|
|
26
|
-
"workspace-tools": "^0.
|
|
26
|
+
"workspace-tools": "^0.36.3"
|
|
27
27
|
},
|
|
28
28
|
"devDependencies": {
|
|
29
29
|
"@ms-cloudpack/eslint-plugin-internal": "*",
|