@ms-cloudpack/import-map
Advanced tools
Comparing version 0.4.0 to 0.5.0
@@ -1,4 +0,4 @@ | ||
import type { ResolveMap, ResolveMapEntry } from '@ms-cloudpack/package-utilities'; | ||
import type { ResolveMapEntry } from '@ms-cloudpack/package-utilities'; | ||
import type { ImportMap } from './types/ImportMap.js'; | ||
import type { PackageImportPaths } from './types/PackageImportPaths.js'; | ||
import type { CreateImportMapContext } from './types/CreateImportMapContext.js'; | ||
/** | ||
@@ -11,6 +11,4 @@ * Adds hash to import map for a package. | ||
hash: string | undefined; | ||
}, context: { | ||
importMap: ImportMap | undefined; | ||
resolveMap: ResolveMap; | ||
packageImportPaths: PackageImportPaths; | ||
}, context: Pick<CreateImportMapContext, 'resolveMap' | 'packageImportPaths' | 'urls'> & { | ||
importMap: ImportMap; | ||
}): void; | ||
@@ -17,0 +15,0 @@ /** |
@@ -1,2 +0,1 @@ | ||
import { makeUrl } from '@ms-cloudpack/path-string-parsing'; | ||
/** | ||
@@ -8,5 +7,2 @@ * Adds hash to import map for a package. | ||
const { importMap, resolveMap, packageImportPaths } = context; | ||
if (!importMap) { | ||
return; | ||
} | ||
const resolveEntry = resolveMap[packageName]; | ||
@@ -16,2 +12,6 @@ if (!resolveEntry) { | ||
} | ||
const bundleServerUrl = context.urls.bundleServer; | ||
if (!bundleServerUrl) { | ||
throw new Error('Bundle server URL is not set in the session.'); | ||
} | ||
if (version === resolveEntry.version) { | ||
@@ -30,3 +30,2 @@ // Package is not scoped | ||
if (importPaths) { | ||
const bundleServerUrl = makeUrl(Object.values(importMap.imports)[0]).origin; | ||
for (const requiredById of Object.keys(entry.requiredBy)) { | ||
@@ -33,0 +32,0 @@ const key = `${bundleServerUrl}/${requiredById}/`; |
@@ -8,3 +8,3 @@ export { createImportMap } from './createImportMap.js'; | ||
export { getRuntimeEntryPaths } from './getRuntimeEntryPaths.js'; | ||
export { parseRequestInfo } from './parseRequestInfo.js'; | ||
export { parseRequestInfo, combinedServerBundleRequestPrefix } from './parseRequestInfo.js'; | ||
//# sourceMappingURL=index.d.ts.map |
@@ -7,3 +7,3 @@ // ImportMap creation | ||
export { getRuntimeEntryPaths } from './getRuntimeEntryPaths.js'; | ||
export { parseRequestInfo } from './parseRequestInfo.js'; | ||
export { parseRequestInfo, combinedServerBundleRequestPrefix } from './parseRequestInfo.js'; | ||
//# sourceMappingURL=index.js.map |
import type { BundleRequestInfo } from './types/BundleRequestInfo.js'; | ||
/** | ||
* URL prefix segment used when the app server and bundle server are combined | ||
* (`useSingleWebServer` feature is enabled). | ||
*/ | ||
export declare const combinedServerBundleRequestPrefix: string; | ||
/** | ||
* Parse a request for package file from the bundle server, such as | ||
@@ -7,2 +12,3 @@ * `/@scope/package@version/v3.2/bundled/path/to/file.js` | ||
* Segments: | ||
* - Optional prefix if the bundle server and app server are combined | ||
* - Package name (and optionally `@version`) | ||
@@ -9,0 +15,0 @@ * - Optional refresh version `v#.#` |
/** | ||
* URL prefix segment used when the app server and bundle server are combined | ||
* (`useSingleWebServer` feature is enabled). | ||
*/ | ||
export const combinedServerBundleRequestPrefix = '__bundles__'; | ||
// This is a hot path, and the following things appear to make the regex faster: | ||
// - /(?:Non-capturing groups)/ where capturing isn't needed | ||
// - /(Indexed capturing groups)/ instead of /(?<namedGroups>...)/ | ||
// - For character classes containing - , putting the - at the beginning | ||
// - Anchoring to the beginning of the string with ^ | ||
const requestInfoRegex = new RegExp( | ||
// optional leading slash | ||
// 1 optional prefix | ||
`^/?(?:(${combinedServerBundleRequestPrefix})/)?` + | ||
// 2 package name | ||
'((?:@[-\\w.]+/)?[-\\w.]+)' + | ||
// 3 version | ||
'(?:@([-\\w.]+))?' + | ||
// 4 hash | ||
'(?:/h-([-0-9a-z.]+))?' + | ||
// version refresh | ||
'(?:/v[\\d.]+)?' + | ||
// 5 bundled or missing | ||
'(?:/(bundled|unbundled|missing))?' + | ||
// 6 file path | ||
'(/[-@\\w.+/]+)?' + | ||
// end or query | ||
'(?:\\?|$)'); | ||
/** | ||
* Parse a request for package file from the bundle server, such as | ||
@@ -6,2 +34,3 @@ * `/@scope/package@version/v3.2/bundled/path/to/file.js` | ||
* Segments: | ||
* - Optional prefix if the bundle server and app server are combined | ||
* - Package name (and optionally `@version`) | ||
@@ -18,19 +47,13 @@ * - Optional refresh version `v#.#` | ||
export function parseRequestInfo(requestPath) { | ||
// This is a hot path, and the following things appear to make the regex faster: | ||
// - /(?:Non-capturing groups)/ where capturing isn't needed | ||
// - /(Indexed capturing groups)/ instead of /(?<namedGroups>...)/ | ||
// - For character classes containing - , putting the - at the beginning | ||
// - Anchoring to the beginning of the string with ^ | ||
const matches = requestPath.match( | ||
// 1 package name 2 hash 3 version refresh 4 bundled or missing 4 file path end or query | ||
/^\/?((?:@[-\w.]+\/)?[-\w.]+)(?:@([-\w.]+))?(?:\/h-([-0-9a-z.]+))?(?:\/v[\d.]+)?(?:\/(bundled|unbundled|missing))?(\/[-@\w.+/]+)?(?:\?|$)/) || []; | ||
const matches = requestPath.match(requestInfoRegex) || []; | ||
return { | ||
packageName: matches[1] || '', | ||
version: matches[2] || '', | ||
hash: matches[3] || '', | ||
bundled: matches[4] === 'bundled', | ||
filePath: matches[5] || '', | ||
missing: matches[4] === 'missing', | ||
prefix: matches[1] || '', | ||
packageName: matches[2] || '', | ||
version: matches[3] || '', | ||
hash: matches[4] || '', | ||
bundled: matches[5] === 'bundled', | ||
filePath: matches[6] || '', | ||
missing: matches[5] === 'missing', | ||
}; | ||
} | ||
//# sourceMappingURL=parseRequestInfo.js.map |
@@ -8,5 +8,5 @@ // This file is read by tools that parse documentation comments conforming to the TSDoc standard. | ||
"packageName": "@microsoft/api-extractor", | ||
"packageVersion": "7.39.4" | ||
"packageVersion": "7.43.2" | ||
} | ||
] | ||
} |
@@ -17,3 +17,9 @@ /** | ||
missing: boolean; | ||
/** | ||
* Prefix used for bundle URLs when the app server and bundle server are combined | ||
* (`useSingleWebServer` feature is enabled). | ||
* Default: empty string | ||
*/ | ||
prefix: string; | ||
} | ||
//# sourceMappingURL=BundleRequestInfo.d.ts.map |
{ | ||
"name": "@ms-cloudpack/import-map", | ||
"version": "0.4.0", | ||
"version": "0.5.0", | ||
"description": "Utilities for creating/updating import maps.", | ||
@@ -17,6 +17,6 @@ "license": "MIT", | ||
"dependencies": { | ||
"@ms-cloudpack/common-types": "^0.5.0", | ||
"@ms-cloudpack/package-utilities": "^7.4.2", | ||
"@ms-cloudpack/common-types": "^0.5.1", | ||
"@ms-cloudpack/package-utilities": "^7.4.3", | ||
"@ms-cloudpack/path-string-parsing": "^1.2.2", | ||
"@ms-cloudpack/path-utilities": "^2.7.7", | ||
"@ms-cloudpack/path-utilities": "^2.7.8", | ||
"merge": "^2.1.1" | ||
@@ -23,0 +23,0 @@ }, |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
47034
406