@ms-cloudpack/package-utilities 5.11.3-beta.0 → 6.0.0

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ms-cloudpack/package-utilities",
3
- "version": "5.11.3-beta.0",
3
+ "version": "6.0.0",
4
4
  "description": "Utilities for resolving/parsing packages and their imports.",
5
5
  "license": "MIT",
6
6
  "type": "module",
@@ -47,5 +47,9 @@
47
47
  "files": [
48
48
  "lib/**/!(*.test.*)"
49
49
  ],
50
- "beachball": {}
50
+ "beachball": {
51
+ "disallowedChangeTypes": [
52
+ "prerelease"
53
+ ]
54
+ }
51
55
  }
@@ -1,27 +0,0 @@
1
- /**
2
- * A class for storing the import paths for a given package path.
3
- * This is used to cache the import paths for a given package path, so that they don't need to be resolved again.
4
- * This is useful for performance, as resolving import paths can be expensive.
5
- */
6
- export declare class PackageImportPaths {
7
- private _importPaths;
8
- constructor();
9
- /**
10
- * Adds an import path to the list of paths for a given package path.
11
- * @param packagePath - The package path to add the path to.
12
- * @param resolvedImportPath - The import path to add.
13
- */
14
- add(packagePath: string, resolvedImportPath: string): void;
15
- /**
16
- * Gets the list of import paths for a given package path.
17
- * @param packagePath - The package path to get the paths for.
18
- * @returns The list of import paths for the given package path.
19
- */
20
- get(packagePath: string): string[];
21
- /**
22
- * Clears the list of import paths for a given package path.
23
- * @param packagePath - The package path to clear the import paths for.
24
- */
25
- clear(): void;
26
- }
27
- //# sourceMappingURL=PackageImportPaths.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"PackageImportPaths.d.ts","sourceRoot":"","sources":["../src/PackageImportPaths.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,qBAAa,kBAAkB;IAC7B,OAAO,CAAC,YAAY,CAAwB;;IAM5C;;;;OAIG;IACH,GAAG,CAAC,WAAW,EAAE,MAAM,EAAE,kBAAkB,EAAE,MAAM,GAAG,IAAI;IAO1D;;;;OAIG;IACH,GAAG,CAAC,WAAW,EAAE,MAAM,GAAG,MAAM,EAAE;IAIlC;;;OAGG;IACH,KAAK,IAAI,IAAI;CAGd"}
@@ -1,37 +0,0 @@
1
- /**
2
- * A class for storing the import paths for a given package path.
3
- * This is used to cache the import paths for a given package path, so that they don't need to be resolved again.
4
- * This is useful for performance, as resolving import paths can be expensive.
5
- */
6
- export class PackageImportPaths {
7
- constructor() {
8
- this._importPaths = new Map();
9
- }
10
- /**
11
- * Adds an import path to the list of paths for a given package path.
12
- * @param packagePath - The package path to add the path to.
13
- * @param resolvedImportPath - The import path to add.
14
- */
15
- add(packagePath, resolvedImportPath) {
16
- if (!this._importPaths.has(packagePath)) {
17
- this._importPaths.set(packagePath, []);
18
- }
19
- this._importPaths.get(packagePath)?.push(resolvedImportPath);
20
- }
21
- /**
22
- * Gets the list of import paths for a given package path.
23
- * @param packagePath - The package path to get the paths for.
24
- * @returns The list of import paths for the given package path.
25
- */
26
- get(packagePath) {
27
- return this._importPaths.get(packagePath) ?? [];
28
- }
29
- /**
30
- * Clears the list of import paths for a given package path.
31
- * @param packagePath - The package path to clear the import paths for.
32
- */
33
- clear() {
34
- this._importPaths.clear();
35
- }
36
- }
37
- //# sourceMappingURL=PackageImportPaths.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"PackageImportPaths.js","sourceRoot":"","sources":["../src/PackageImportPaths.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,MAAM,OAAO,kBAAkB;IAG7B;QACE,IAAI,CAAC,YAAY,GAAG,IAAI,GAAG,EAAoB,CAAC;IAClD,CAAC;IAED;;;;OAIG;IACH,GAAG,CAAC,WAAmB,EAAE,kBAA0B;QACjD,IAAI,CAAC,IAAI,CAAC,YAAY,CAAC,GAAG,CAAC,WAAW,CAAC,EAAE,CAAC;YACxC,IAAI,CAAC,YAAY,CAAC,GAAG,CAAC,WAAW,EAAE,EAAE,CAAC,CAAC;QACzC,CAAC;QACD,IAAI,CAAC,YAAY,CAAC,GAAG,CAAC,WAAW,CAAC,EAAE,IAAI,CAAC,kBAAkB,CAAC,CAAC;IAC/D,CAAC;IAED;;;;OAIG;IACH,GAAG,CAAC,WAAmB;QACrB,OAAO,IAAI,CAAC,YAAY,CAAC,GAAG,CAAC,WAAW,CAAC,IAAI,EAAE,CAAC;IAClD,CAAC;IAED;;;OAGG;IACH,KAAK;QACH,IAAI,CAAC,YAAY,CAAC,KAAK,EAAE,CAAC;IAC5B,CAAC;CACF","sourcesContent":["/**\n * A class for storing the import paths for a given package path.\n * This is used to cache the import paths for a given package path, so that they don't need to be resolved again.\n * This is useful for performance, as resolving import paths can be expensive.\n */\nexport class PackageImportPaths {\n private _importPaths: Map<string, string[]>;\n\n constructor() {\n this._importPaths = new Map<string, string[]>();\n }\n\n /**\n * Adds an import path to the list of paths for a given package path.\n * @param packagePath - The package path to add the path to.\n * @param resolvedImportPath - The import path to add.\n */\n add(packagePath: string, resolvedImportPath: string): void {\n if (!this._importPaths.has(packagePath)) {\n this._importPaths.set(packagePath, []);\n }\n this._importPaths.get(packagePath)?.push(resolvedImportPath);\n }\n\n /**\n * Gets the list of import paths for a given package path.\n * @param packagePath - The package path to get the paths for.\n * @returns The list of import paths for the given package path.\n */\n get(packagePath: string): string[] {\n return this._importPaths.get(packagePath) ?? [];\n }\n\n /**\n * Clears the list of import paths for a given package path.\n * @param packagePath - The package path to clear the import paths for.\n */\n clear(): void {\n this._importPaths.clear();\n }\n}\n"]}
@@ -1,27 +0,0 @@
1
- import type { ImportMap } from './createImportMap.js';
2
- import type { ResolveMap } from './types/ResolveMap.js';
3
- import type { PackageImportPaths } from './PackageImportPaths.js';
4
- /**
5
- * Adds hash to import map for a package.
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
8
- */
9
- export declare function addImportMapHash(options: {
10
- packageName: string;
11
- version: string;
12
- importMap: ImportMap | undefined;
13
- resolveMap: ResolveMap;
14
- hash?: string;
15
- }, context: {
16
- packageImportPaths: PackageImportPaths;
17
- }): void;
18
- /**
19
- * Adds hash after name and version.
20
- * If hash already exists, replaces it.
21
- * @param url URL to add hash to
22
- * @param packageUrl Package name and version
23
- * @param hash Hash to add
24
- * @returns URL with hash
25
- */
26
- export declare function addHashUrl(url: string, packageUrl: string, hash: string): string;
27
- //# sourceMappingURL=addImportMapHash.d.ts.map
@@ -1 +0,0 @@
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"}
@@ -1,70 +0,0 @@
1
- /**
2
- * Adds hash to import map for a package.
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
5
- */
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
- if (!importMap) {
11
- return;
12
- }
13
- if (!resolveEntry) {
14
- throw new Error(`Could not find package ${packageName} in the resolve map.`);
15
- }
16
- if (version === resolveEntry.version) {
17
- // Package is not scoped
18
- const entry = resolveEntry;
19
- const packageUrl = `${entry.name}@${entry.version}`;
20
- const importPaths = packageImportPaths.get(entry.path);
21
- importPaths.forEach((importPath) => {
22
- importMap.imports[importPath] = addHashUrl(importMap.imports[importPath], packageUrl, hash);
23
- });
24
- }
25
- else if (resolveEntry.scopedVersions?.[version] !== undefined && importMap.scopes) {
26
- // Package is scoped
27
- const entry = resolveEntry.scopedVersions?.[version];
28
- if (!entry) {
29
- throw new Error(`Could not find package ${packageName}@${version} in the resolve map.`);
30
- }
31
- const packageUrl = `${entry.name}@${entry.version}`;
32
- const importPaths = packageImportPaths.get(entry.path);
33
- const bundleServerUrl = new URL(Object.values(importMap.imports)[0]).origin;
34
- for (const requiredById of Object.keys(entry.requiredBy)) {
35
- const key = `${bundleServerUrl}/${requiredById}/`;
36
- importPaths.forEach((importPath) => {
37
- if (!importMap.scopes) {
38
- return;
39
- }
40
- importMap.scopes[key][importPath] = addHashUrl(importMap.scopes[key][importPath], packageUrl, hash);
41
- });
42
- }
43
- }
44
- }
45
- /**
46
- * Adds hash after name and version.
47
- * If hash already exists, replaces it.
48
- * @param url URL to add hash to
49
- * @param packageUrl Package name and version
50
- * @param hash Hash to add
51
- * @returns URL with hash
52
- */
53
- export function addHashUrl(url, packageUrl, hash) {
54
- const search = url.indexOf(packageUrl);
55
- if (search !== -1) {
56
- const hashIndex = search + packageUrl.length;
57
- const prefix = 'h-';
58
- if (url.startsWith(prefix, hashIndex + 1)) {
59
- // Replace hash if it already exists
60
- const hashEnd = url.indexOf('/', hashIndex + prefix.length + 1);
61
- url = url.slice(0, hashIndex) + `/h-${hash}` + url.slice(hashEnd);
62
- }
63
- else {
64
- // Add hash after name and version
65
- url = url.slice(0, hashIndex) + `/h-${hash}` + url.slice(hashIndex);
66
- }
67
- }
68
- return url;
69
- }
70
- //# sourceMappingURL=addImportMapHash.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"add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AG,CAAC,CAAC,EAAE,CAAC;YAC1C,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;QACpE,CAAC;aAAM,CAAC;YACN,kCAAkC;YAClC,GAAG,GAAG,GAAG,CAAC,KAAK,CAAC,CAAC,EAAE,SAAS,CAAC,GAAG,MAAM,IAAI,EAAE,GAAG,GAAG,CAAC,KAAK,CAAC,SAAS,CAAC,CAAC;QACtE,CAAC;IACH,CAAC;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"]}
@@ -1,24 +0,0 @@
1
- import type { PackageDefinitionsCache } from '@ms-cloudpack/bundler-types';
2
- import { type CloudpackConfig } from '@ms-cloudpack/config-types';
3
- import type { PackageImportPaths } from './PackageImportPaths.js';
4
- import type { ResolveMap } from './types/ResolveMap.js';
5
- export interface ImportMap {
6
- imports: Record<string, string>;
7
- scopes?: Record<string, Record<string, string>>;
8
- }
9
- export type CreateImportMapContext = {
10
- packages: PackageDefinitionsCache;
11
- packageImportPaths?: PackageImportPaths;
12
- getPackageHash: (packagePath: string) => Promise<string>;
13
- config: CloudpackConfig;
14
- };
15
- /**
16
- * Given a resolve map and a bundleServerUrl, returns an import map to be used in the browser.
17
- */
18
- export declare function createImportMap(options: {
19
- resolveMap: ResolveMap;
20
- bundleServerUrl: string;
21
- sessionVersion?: number;
22
- targetVersions?: Record<string, number>;
23
- }, context: CreateImportMapContext): Promise<ImportMap>;
24
- //# sourceMappingURL=createImportMap.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"createImportMap.d.ts","sourceRoot":"","sources":["../src/createImportMap.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,6BAA6B,CAAC;AAC3E,OAAO,EAAE,KAAK,eAAe,EAAE,MAAM,4BAA4B,CAAC;AAElE,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,yBAAyB,CAAC;AAGlE,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,uBAAuB,CAAC;AAIxD,MAAM,WAAW,SAAS;IACxB,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAChC,MAAM,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,CAAC;CACjD;AAED,MAAM,MAAM,sBAAsB,GAAG;IACnC,QAAQ,EAAE,uBAAuB,CAAC;IAClC,kBAAkB,CAAC,EAAE,kBAAkB,CAAC;IACxC,cAAc,EAAE,CAAC,WAAW,EAAE,MAAM,KAAK,OAAO,CAAC,MAAM,CAAC,CAAC;IACzD,MAAM,EAAE,eAAe,CAAC;CACzB,CAAC;AAEF;;GAEG;AACH,wBAAsB,eAAe,CACnC,OAAO,EAAE;IACP,UAAU,EAAE,UAAU,CAAC;IACvB,eAAe,EAAE,MAAM,CAAC;IACxB,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,cAAc,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;CACzC,EACD,OAAO,EAAE,sBAAsB,GAC9B,OAAO,CAAC,SAAS,CAAC,CAqCpB"}
@@ -1,76 +0,0 @@
1
- import {} from '@ms-cloudpack/config-types';
2
- import { merge } from 'merge';
3
- import { getExportsMap } from './getExportsMap.js';
4
- import { isExternalPackage } from './isExternalPackage.js';
5
- import { getRuntimeEntryPaths } from './getRuntimeEntryPaths.js';
6
- /**
7
- * Given a resolve map and a bundleServerUrl, returns an import map to be used in the browser.
8
- */
9
- export async function createImportMap(options, context) {
10
- const { resolveMap, bundleServerUrl, sessionVersion = 0, targetVersions } = options;
11
- const { packageImportPaths } = context;
12
- const importMap = {
13
- imports: {},
14
- };
15
- packageImportPaths?.clear();
16
- for (const resolveEntry of Object.values(resolveMap)) {
17
- merge(importMap.imports, await getImportMapFromEntry({
18
- options: { entry: resolveEntry, bundleServerUrl, targetVersions, sessionVersion },
19
- context,
20
- }));
21
- if (resolveEntry.scopedVersions) {
22
- // Initialize scopes
23
- importMap.scopes ??= {};
24
- for (const scopedEntry of Object.values(resolveEntry.scopedVersions)) {
25
- const importMapForEntry = await getImportMapFromEntry({
26
- options: { entry: scopedEntry, bundleServerUrl, sessionVersion, targetVersions },
27
- context,
28
- });
29
- for (const requiredById of Object.keys(scopedEntry.requiredBy)) {
30
- const scopes = (importMap.scopes[`${bundleServerUrl}/${requiredById}/`] ??= {});
31
- merge(scopes, importMapForEntry);
32
- }
33
- }
34
- }
35
- }
36
- return importMap;
37
- }
38
- async function getImportMapFromEntry(params) {
39
- const { options, context } = params;
40
- const { entry, bundleServerUrl, sessionVersion, targetVersions } = options;
41
- const { name } = entry;
42
- const { packages, packageImportPaths, getPackageHash, config } = context;
43
- const importMap = {};
44
- const definition = await packages.get(entry.path);
45
- const exportsMap = await getExportsMap({ packagePath: entry.path }, { packages, config });
46
- if (!definition ||
47
- !definition.version ||
48
- !exportsMap ||
49
- Object.keys(exportsMap).length === 0 ||
50
- name.startsWith('@types/')) {
51
- return importMap;
52
- }
53
- const packagePrefix = `${name}@${entry.version}/`;
54
- const baseUrl = `${bundleServerUrl}/${packagePrefix}`;
55
- const isExternal = isExternalPackage(entry.path);
56
- const targetVersion = targetVersions?.[entry.path];
57
- const cacheBuster = `v${sessionVersion ?? 0}${targetVersion ? `.${targetVersion}` : ''}/`;
58
- const hash = isExternal ? `h-${await getPackageHash(entry.path)}/` : 'h-pending/';
59
- // Add the bundled entries to the import map, but prefer unbundled if the entry exists.
60
- const entryPaths = getRuntimeEntryPaths({
61
- isExternal,
62
- exportsMap,
63
- bundledPrefix: `${hash}${cacheBuster}bundled/`,
64
- unbundledPrefix: `${hash}${cacheBuster}unbundled/`,
65
- });
66
- for (const [importPath, actualEntryPath] of Object.entries(entryPaths)) {
67
- const resolvedImportPath = importPath.replace('.', `${name}`);
68
- packageImportPaths?.add(entry.path, resolvedImportPath);
69
- importMap[resolvedImportPath] = new URL(actualEntryPath, baseUrl).href;
70
- }
71
- // Finally add a fallback for all other unexpected bundle entries. (Note, this should point to a script
72
- // which logs this as an error to the user and offers a way to add the entry to exports overrides.)
73
- // importMap[definition.name + '/'] = baseUrl + 'missing/';
74
- return importMap;
75
- }
76
- //# sourceMappingURL=createImportMap.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"createImportMap.js","sourceRoot":"","sources":["../src/createImportMap.ts"],"names":[],"mappings":"AACA,OAAO,EAAwB,MAAM,4BAA4B,CAAC;AAClE,OAAO,EAAE,KAAK,EAAE,MAAM,OAAO,CAAC;AAE9B,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AACnD,OAAO,EAAE,iBAAiB,EAAE,MAAM,wBAAwB,CAAC;AAG3D,OAAO,EAAE,oBAAoB,EAAE,MAAM,2BAA2B,CAAC;AAcjE;;GAEG;AACH,MAAM,CAAC,KAAK,UAAU,eAAe,CACnC,OAKC,EACD,OAA+B;IAE/B,MAAM,EAAE,UAAU,EAAE,eAAe,EAAE,cAAc,GAAG,CAAC,EAAE,cAAc,EAAE,GAAG,OAAO,CAAC;IACpF,MAAM,EAAE,kBAAkB,EAAE,GAAG,OAAO,CAAC;IACvC,MAAM,SAAS,GAAc;QAC3B,OAAO,EAAE,EAAE;KACZ,CAAC;IAEF,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AAE,GAAG,IAAI,GAAG,WAAW,YAAY;KACnD,CAAC,CAAC;IAEH,KAAK,MAAM,CAAC,UAAU,EAAE,eAAe,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,UAAU,CAAC,EAAE,CAAC;QACvE,MAAM,kBAAkB,GAAG,UAAU,CAAC,OAAO,CAAC,GAAG,EAAE,GAAG,IAAI,EAAE,CAAC,CAAC;QAC9D,kBAAkB,EAAE,GAAG,CAAC,KAAK,CAAC,IAAI,EAAE,kBAAkB,CAAC,CAAC;QACxD,SAAS,CAAC,kBAAkB,CAAC,GAAG,IAAI,GAAG,CAAC,eAAe,EAAE,OAAO,CAAC,CAAC,IAAI,CAAC;IACzE,CAAC;IAED,uGAAuG;IACvG,mGAAmG;IACnG,2DAA2D;IAE3D,OAAO,SAAS,CAAC;AACnB,CAAC","sourcesContent":["import type { PackageDefinitionsCache } from '@ms-cloudpack/bundler-types';\nimport { type CloudpackConfig } from '@ms-cloudpack/config-types';\nimport { merge } from 'merge';\nimport type { PackageImportPaths } from './PackageImportPaths.js';\nimport { getExportsMap } from './getExportsMap.js';\nimport { isExternalPackage } from './isExternalPackage.js';\nimport type { ResolveMap } from './types/ResolveMap.js';\nimport type { ResolveMapEntry } from './types/ResolveMapEntry.js';\nimport { getRuntimeEntryPaths } from './getRuntimeEntryPaths.js';\n\nexport interface ImportMap {\n imports: Record<string, string>;\n scopes?: Record<string, Record<string, string>>;\n}\n\nexport type CreateImportMapContext = {\n packages: PackageDefinitionsCache;\n packageImportPaths?: PackageImportPaths;\n getPackageHash: (packagePath: string) => Promise<string>;\n config: CloudpackConfig;\n};\n\n/**\n * Given a resolve map and a bundleServerUrl, returns an import map to be used in the browser.\n */\nexport async function createImportMap(\n options: {\n resolveMap: ResolveMap;\n bundleServerUrl: string;\n sessionVersion?: number;\n targetVersions?: Record<string, number>;\n },\n context: CreateImportMapContext,\n): Promise<ImportMap> {\n const { resolveMap, bundleServerUrl, sessionVersion = 0, targetVersions } = options;\n const { packageImportPaths } = context;\n const importMap: ImportMap = {\n imports: {},\n };\n\n packageImportPaths?.clear();\n\n for (const resolveEntry of Object.values(resolveMap)) {\n merge(\n importMap.imports,\n await getImportMapFromEntry({\n options: { entry: resolveEntry, bundleServerUrl, targetVersions, sessionVersion },\n context,\n }),\n );\n\n if (resolveEntry.scopedVersions) {\n // Initialize scopes\n importMap.scopes ??= {};\n\n for (const scopedEntry of Object.values(resolveEntry.scopedVersions)) {\n const importMapForEntry = await getImportMapFromEntry({\n options: { entry: scopedEntry, bundleServerUrl, sessionVersion, targetVersions },\n context,\n });\n\n for (const requiredById of Object.keys(scopedEntry.requiredBy)) {\n const scopes = (importMap.scopes[`${bundleServerUrl}/${requiredById}/`] ??= {});\n merge(scopes, importMapForEntry);\n }\n }\n }\n }\n\n return importMap;\n}\n\nasync function getImportMapFromEntry(params: {\n options: {\n entry: ResolveMapEntry;\n bundleServerUrl: string;\n sessionVersion: number;\n targetVersions?: Record<string, number>;\n };\n context: CreateImportMapContext;\n}): Promise<Record<string, string>> {\n const { options, context } = params;\n const { entry, bundleServerUrl, sessionVersion, targetVersions } = options;\n const { name } = entry;\n const { packages, packageImportPaths, getPackageHash, config } = context;\n const importMap: Record<string, string> = {};\n const definition = await packages.get(entry.path);\n const exportsMap = await getExportsMap({ packagePath: entry.path }, { packages, config });\n\n if (\n !definition ||\n !definition.version ||\n !exportsMap ||\n Object.keys(exportsMap).length === 0 ||\n name.startsWith('@types/')\n ) {\n return importMap;\n }\n\n const packagePrefix = `${name}@${entry.version}/`;\n const baseUrl = `${bundleServerUrl}/${packagePrefix}`;\n const isExternal = isExternalPackage(entry.path);\n const targetVersion = targetVersions?.[entry.path];\n const cacheBuster = `v${sessionVersion ?? 0}${targetVersion ? `.${targetVersion}` : ''}/`;\n const hash = isExternal ? `h-${await getPackageHash(entry.path)}/` : 'h-pending/';\n\n // Add the bundled entries to the import map, but prefer unbundled if the entry exists.\n const entryPaths = getRuntimeEntryPaths({\n isExternal,\n exportsMap,\n bundledPrefix: `${hash}${cacheBuster}bundled/`,\n unbundledPrefix: `${hash}${cacheBuster}unbundled/`,\n });\n\n for (const [importPath, actualEntryPath] of Object.entries(entryPaths)) {\n const resolvedImportPath = importPath.replace('.', `${name}`);\n packageImportPaths?.add(entry.path, resolvedImportPath);\n importMap[resolvedImportPath] = new URL(actualEntryPath, baseUrl).href;\n }\n\n // Finally add a fallback for all other unexpected bundle entries. (Note, this should point to a script\n // which logs this as an error to the user and offers a way to add the entry to exports overrides.)\n // importMap[definition.name + '/'] = baseUrl + 'missing/';\n\n return importMap;\n}\n"]}
@@ -1,12 +0,0 @@
1
- /**
2
- * @deprecated Use `getRuntimeEntryPaths`
3
- */
4
- export declare function getResolvedFilePath(params: {
5
- entryPath: string;
6
- isExternal: boolean;
7
- unbundledExportsMap: Record<string, string>;
8
- bundledFilePath: string;
9
- bundledPrefix?: string;
10
- unbundledPrefix?: string;
11
- }): string | undefined;
12
- //# sourceMappingURL=getResolvedFilePath.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"getResolvedFilePath.d.ts","sourceRoot":"","sources":["../src/getResolvedFilePath.ts"],"names":[],"mappings":"AAEA;;GAEG;AACH,wBAAgB,mBAAmB,CAAC,MAAM,EAAE;IAC1C,SAAS,EAAE,MAAM,CAAC;IAClB,UAAU,EAAE,OAAO,CAAC;IACpB,mBAAmB,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAC5C,eAAe,EAAE,MAAM,CAAC;IACxB,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,eAAe,CAAC,EAAE,MAAM,CAAC;CAC1B,GAAG,MAAM,GAAG,SAAS,CAmCrB"}
@@ -1,25 +0,0 @@
1
- import path from 'path';
2
- /**
3
- * @deprecated Use `getRuntimeEntryPaths`
4
- */
5
- export function getResolvedFilePath(params) {
6
- const { entryPath, isExternal, unbundledExportsMap, bundledFilePath, bundledPrefix = '', unbundledPrefix = '', } = params;
7
- const unbundledFilePath = isExternal ? unbundledExportsMap[entryPath] : undefined;
8
- let resolvedFilePath = unbundledFilePath ? unbundledPrefix + unbundledFilePath : bundledPrefix + bundledFilePath;
9
- const ext = path.extname(resolvedFilePath);
10
- // For bundled files:
11
- if (!unbundledFilePath) {
12
- // Ignore .d.ts entries
13
- if (resolvedFilePath.endsWith('.d.ts')) {
14
- return undefined;
15
- }
16
- // We always expect responses to come back as javascript (.js extensions.)
17
- if (ext !== '.js') {
18
- resolvedFilePath = path.join(path.dirname(resolvedFilePath), path.basename(resolvedFilePath, ext) + (ext === '.mjs' ? '.js' : ext + '.js'));
19
- }
20
- // Plus signs should be replaced with underscores.
21
- resolvedFilePath = resolvedFilePath.replace(/\+/g, '_');
22
- }
23
- return resolvedFilePath;
24
- }
25
- //# sourceMappingURL=getResolvedFilePath.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"getResolvedFilePath.js","sourceRoot":"","sources":["../src/getResolvedFilePath.ts"],"names":[],"mappings":"AAAA,OAAO,IAAI,MAAM,MAAM,CAAC;AAExB;;GAEG;AACH,MAAM,UAAU,mBAAmB,CAAC,MAOnC;IACC,MAAM,EACJ,SAAS,EACT,UAAU,EACV,mBAAmB,EACnB,eAAe,EACf,aAAa,GAAG,EAAE,EAClB,eAAe,GAAG,EAAE,GACrB,GAAG,MAAM,CAAC;IAEX,MAAM,iBAAiB,GAAG,UAAU,CAAC,CAAC,CAAC,mBAAmB,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC;IAClF,IAAI,gBAAgB,GAAG,iBAAiB,CAAC,CAAC,CAAC,eAAe,GAAG,iBAAiB,CAAC,CAAC,CAAC,aAAa,GAAG,eAAe,CAAC;IAEjH,MAAM,GAAG,GAAG,IAAI,CAAC,OAAO,CAAC,gBAAgB,CAAC,CAAC;IAE3C,qBAAqB;IACrB,IAAI,CAAC,iBAAiB,EAAE,CAAC;QACvB,uBAAuB;QACvB,IAAI,gBAAgB,CAAC,QAAQ,CAAC,OAAO,CAAC,EAAE,CAAC;YACvC,OAAO,SAAS,CAAC;QACnB,CAAC;QAED,0EAA0E;QAC1E,IAAI,GAAG,KAAK,KAAK,EAAE,CAAC;YAClB,gBAAgB,GAAG,IAAI,CAAC,IAAI,CAC1B,IAAI,CAAC,OAAO,CAAC,gBAAgB,CAAC,EAC9B,IAAI,CAAC,QAAQ,CAAC,gBAAgB,EAAE,GAAG,CAAC,GAAG,CAAC,GAAG,KAAK,MAAM,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,GAAG,GAAG,KAAK,CAAC,CAC9E,CAAC;QACJ,CAAC;QAED,kDAAkD;QAClD,gBAAgB,GAAG,gBAAgB,CAAC,OAAO,CAAC,KAAK,EAAE,GAAG,CAAC,CAAC;IAC1D,CAAC;IAED,OAAO,gBAAgB,CAAC;AAC1B,CAAC","sourcesContent":["import path from 'path';\n\n/**\n * @deprecated Use `getRuntimeEntryPaths`\n */\nexport function getResolvedFilePath(params: {\n entryPath: string;\n isExternal: boolean;\n unbundledExportsMap: Record<string, string>;\n bundledFilePath: string;\n bundledPrefix?: string;\n unbundledPrefix?: string;\n}): string | undefined {\n const {\n entryPath,\n isExternal,\n unbundledExportsMap,\n bundledFilePath,\n bundledPrefix = '',\n unbundledPrefix = '',\n } = params;\n\n const unbundledFilePath = isExternal ? unbundledExportsMap[entryPath] : undefined;\n let resolvedFilePath = unbundledFilePath ? unbundledPrefix + unbundledFilePath : bundledPrefix + bundledFilePath;\n\n const ext = path.extname(resolvedFilePath);\n\n // For bundled files:\n if (!unbundledFilePath) {\n // Ignore .d.ts entries\n if (resolvedFilePath.endsWith('.d.ts')) {\n return undefined;\n }\n\n // We always expect responses to come back as javascript (.js extensions.)\n if (ext !== '.js') {\n resolvedFilePath = path.join(\n path.dirname(resolvedFilePath),\n path.basename(resolvedFilePath, ext) + (ext === '.mjs' ? '.js' : ext + '.js'),\n );\n }\n\n // Plus signs should be replaced with underscores.\n resolvedFilePath = resolvedFilePath.replace(/\\+/g, '_');\n }\n\n return resolvedFilePath;\n}\n"]}
@@ -1,21 +0,0 @@
1
- import type { PackageJsonExports } from '@ms-cloudpack/config-types';
2
- /**
3
- * For each path in the exports map, get the actual file path that will be used at runtime.
4
- * - Prefers unbundled (browser-esm) paths for external packages if such paths exist.
5
- * - Otherwise, uses bundled paths with the correct extension.
6
- * - Omits any paths that won't exist at runtime, like .d.ts.
7
- *
8
- * @returns Mapping from import path (same as original exports map keys) to actual relative
9
- * file path that will be used at runtime.
10
- */
11
- export declare function getRuntimeEntryPaths(params: {
12
- /** Exports map for a package */
13
- exportsMap: PackageJsonExports;
14
- /** Whether the package is external to the repo */
15
- isExternal: boolean;
16
- /** Prefix for bundled file paths */
17
- bundledPrefix?: string;
18
- /** Prefix for unbundled file paths */
19
- unbundledPrefix?: string;
20
- }): Record<string, string>;
21
- //# sourceMappingURL=getRuntimeEntryPaths.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"getRuntimeEntryPaths.d.ts","sourceRoot":"","sources":["../src/getRuntimeEntryPaths.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,4BAA4B,CAAC;AAIrE;;;;;;;;GAQG;AACH,wBAAgB,oBAAoB,CAAC,MAAM,EAAE;IAC3C,gCAAgC;IAChC,UAAU,EAAE,kBAAkB,CAAC;IAC/B,kDAAkD;IAClD,UAAU,EAAE,OAAO,CAAC;IACpB,oCAAoC;IACpC,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,sCAAsC;IACtC,eAAe,CAAC,EAAE,MAAM,CAAC;CAC1B,GAAG,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CA0CzB"}
@@ -1,44 +0,0 @@
1
- import path from 'path';
2
- import { flattenExportsMap } from './flattenExportsMap.js';
3
- /**
4
- * For each path in the exports map, get the actual file path that will be used at runtime.
5
- * - Prefers unbundled (browser-esm) paths for external packages if such paths exist.
6
- * - Otherwise, uses bundled paths with the correct extension.
7
- * - Omits any paths that won't exist at runtime, like .d.ts.
8
- *
9
- * @returns Mapping from import path (same as original exports map keys) to actual relative
10
- * file path that will be used at runtime.
11
- */
12
- export function getRuntimeEntryPaths(params) {
13
- const { exportsMap, isExternal, bundledPrefix = '', unbundledPrefix = '' } = params;
14
- const result = {};
15
- // Get both the unbundled and bundled entries from the exports map
16
- const unbundledExportsMap = flattenExportsMap(exportsMap, {
17
- conditions: ['browser-esm'],
18
- requiredConditions: ['browser-esm'],
19
- });
20
- const bundledExportsMap = flattenExportsMap(exportsMap);
21
- for (const [importPath, bundledFilePath] of Object.entries(bundledExportsMap)) {
22
- const unbundledFilePath = isExternal ? unbundledExportsMap[importPath] : undefined;
23
- let actualFilePath = unbundledFilePath ? unbundledPrefix + unbundledFilePath : bundledPrefix + bundledFilePath;
24
- const ext = path.extname(actualFilePath);
25
- // For bundled files:
26
- if (!unbundledFilePath) {
27
- // Ignore .d.ts entries
28
- if (actualFilePath.endsWith('.d.ts')) {
29
- continue;
30
- }
31
- // We always expect responses to come back as javascript (.js extensions.)
32
- if (ext !== '.js') {
33
- actualFilePath = path.join(path.dirname(actualFilePath), path.basename(actualFilePath, ext) + (ext === '.mjs' ? '.js' : ext + '.js'));
34
- }
35
- // Plus signs should be replaced with underscores.
36
- actualFilePath = actualFilePath.replace(/\+/g, '_');
37
- }
38
- if (actualFilePath !== undefined) {
39
- result[importPath] = actualFilePath;
40
- }
41
- }
42
- return result;
43
- }
44
- //# sourceMappingURL=getRuntimeEntryPaths.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"getRuntimeEntryPaths.js","sourceRoot":"","sources":["../src/getRuntimeEntryPaths.ts"],"names":[],"mappings":"AACA,OAAO,IAAI,MAAM,MAAM,CAAC;AACxB,OAAO,EAAE,iBAAiB,EAAE,MAAM,wBAAwB,CAAC;AAE3D;;;;;;;;GAQG;AACH,MAAM,UAAU,oBAAoB,CAAC,MASpC;IACC,MAAM,EAAE,UAAU,EAAE,UAAU,EAAE,aAAa,GAAG,EAAE,EAAE,eAAe,GAAG,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C;QACtD,CAAC;QAED,IAAI,cAAc,KAAK,SAAS,EAAE,CAAC;YACjC,MAAM,CAAC,UAAU,CAAC,GAAG,cAAc,CAAC;QACtC,CAAC;IACH,CAAC;IAED,OAAO,MAAM,CAAC;AAChB,CAAC","sourcesContent":["import type { PackageJsonExports } from '@ms-cloudpack/config-types';\nimport path from 'path';\nimport { flattenExportsMap } from './flattenExportsMap.js';\n\n/**\n * For each path in the exports map, get the actual file path that will be used at runtime.\n * - Prefers unbundled (browser-esm) paths for external packages if such paths exist.\n * - Otherwise, uses bundled paths with the correct extension.\n * - Omits any paths that won't exist at runtime, like .d.ts.\n *\n * @returns Mapping from import path (same as original exports map keys) to actual relative\n * file path that will be used at runtime.\n */\nexport function getRuntimeEntryPaths(params: {\n /** Exports map for a package */\n exportsMap: PackageJsonExports;\n /** Whether the package is external to the repo */\n isExternal: boolean;\n /** Prefix for bundled file paths */\n bundledPrefix?: string;\n /** Prefix for unbundled file paths */\n unbundledPrefix?: string;\n}): Record<string, string> {\n const { exportsMap, isExternal, bundledPrefix = '', unbundledPrefix = '' } = params;\n const result: Record<string, string> = {};\n\n // Get both the unbundled and bundled entries from the exports map\n const unbundledExportsMap = flattenExportsMap(exportsMap, {\n conditions: ['browser-esm'],\n requiredConditions: ['browser-esm'],\n });\n const bundledExportsMap = flattenExportsMap(exportsMap);\n\n for (const [importPath, bundledFilePath] of Object.entries(bundledExportsMap)) {\n const unbundledFilePath = isExternal ? unbundledExportsMap[importPath] : undefined;\n let actualFilePath = unbundledFilePath ? unbundledPrefix + unbundledFilePath : bundledPrefix + bundledFilePath;\n\n const ext = path.extname(actualFilePath);\n\n // For bundled files:\n if (!unbundledFilePath) {\n // Ignore .d.ts entries\n if (actualFilePath.endsWith('.d.ts')) {\n continue;\n }\n\n // We always expect responses to come back as javascript (.js extensions.)\n if (ext !== '.js') {\n actualFilePath = path.join(\n path.dirname(actualFilePath),\n path.basename(actualFilePath, ext) + (ext === '.mjs' ? '.js' : ext + '.js'),\n );\n }\n\n // Plus signs should be replaced with underscores.\n actualFilePath = actualFilePath.replace(/\\+/g, '_');\n }\n\n if (actualFilePath !== undefined) {\n result[importPath] = actualFilePath;\n }\n }\n\n return result;\n}\n"]}