@ms-cloudpack/api-server 0.31.6-beta.0 → 0.31.7-beta.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/lib/apis/ensurePackageBundled.d.ts.map +1 -1
- package/lib/apis/ensurePackageBundled.js +3 -5
- package/lib/apis/ensurePackageBundled.js.map +1 -1
- package/lib/common/createPartialApiContext.d.ts.map +1 -1
- package/lib/common/createPartialApiContext.js +1 -5
- package/lib/common/createPartialApiContext.js.map +1 -1
- package/lib/common/createSession.js.map +1 -1
- package/lib/startApiServer.js +2 -2
- package/lib/startApiServer.js.map +1 -1
- package/lib/trpc/createCloudpackServer.d.ts +1 -1
- package/lib/trpc/createCloudpackServer.d.ts.map +1 -1
- package/lib/trpc/createCloudpackServer.js +2 -1
- package/lib/trpc/createCloudpackServer.js.map +1 -1
- package/lib/trpc/createContextFactory.d.ts +1 -1
- package/lib/trpc/createContextFactory.d.ts.map +1 -1
- package/lib/trpc/createContextFactory.js +1 -1
- package/lib/trpc/createContextFactory.js.map +1 -1
- package/lib/tsdoc-metadata.json +11 -0
- package/lib/types/BundleRequest.d.ts +1 -9
- package/lib/types/BundleRequest.d.ts.map +1 -1
- package/lib/types/BundleRequest.js.map +1 -1
- package/lib/types/Context.d.ts +1 -1
- package/lib/types/Context.d.ts.map +1 -1
- package/lib/types/Context.js.map +1 -1
- package/lib/types/CreateHtmlOptions.d.ts +1 -1
- package/lib/types/CreateHtmlOptions.d.ts.map +1 -1
- package/lib/types/CreateHtmlOptions.js.map +1 -1
- package/lib/types/Session.d.ts +2 -1
- package/lib/types/Session.d.ts.map +1 -1
- package/lib/types/Session.js.map +1 -1
- package/lib/utilities/addOverride.js +4 -4
- package/lib/utilities/addOverride.js.map +1 -1
- package/lib/utilities/bundleTask.d.ts +12 -4
- package/lib/utilities/bundleTask.d.ts.map +1 -1
- package/lib/utilities/bundleTask.js +14 -13
- package/lib/utilities/bundleTask.js.map +1 -1
- package/lib/utilities/createBundleRequestForPackage.d.ts +0 -4
- package/lib/utilities/createBundleRequestForPackage.d.ts.map +1 -1
- package/lib/utilities/createBundleRequestForPackage.js +0 -1
- package/lib/utilities/createBundleRequestForPackage.js.map +1 -1
- package/lib/utilities/createBundleTask.d.ts +15 -7
- package/lib/utilities/createBundleTask.d.ts.map +1 -1
- package/lib/utilities/createBundleTask.js +16 -5
- package/lib/utilities/createBundleTask.js.map +1 -1
- package/lib/utilities/getBundleInfo.d.ts.map +1 -1
- package/lib/utilities/getBundleInfo.js +9 -22
- package/lib/utilities/getBundleInfo.js.map +1 -1
- package/lib/utilities/parseRequestInfo.d.ts +3 -0
- package/lib/utilities/parseRequestInfo.d.ts.map +1 -1
- package/lib/utilities/parseRequestInfo.js +4 -2
- package/lib/utilities/parseRequestInfo.js.map +1 -1
- package/package.json +11 -10
package/lib/types/Session.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Session.js","sourceRoot":"","sources":["../../src/types/Session.ts"],"names":[],"mappings":"","sourcesContent":["import type { ImportMap
|
|
1
|
+
{"version":3,"file":"Session.js","sourceRoot":"","sources":["../../src/types/Session.ts"],"names":[],"mappings":"","sourcesContent":["import type { ImportMap } from '@ms-cloudpack/import-map';\nimport type { ResolveMap } from '@ms-cloudpack/package-utilities';\nimport type { CloudpackConfig } from '@ms-cloudpack/config-types';\n\nexport interface Session {\n /**\n * The session id, used for identifying\n */\n id: string;\n\n /**\n * The config used by the session.\n */\n config: CloudpackConfig;\n\n /**\n * The primary application path to monitor.\n */\n appPath: string;\n\n /**\n * The type of session controls how the code is served via start.\n * Web apps require app server and asset hosting, while libraries\n * only need a bundle service.\n */\n type: 'web-app' | 'library';\n\n /**\n * The mode of the session controls how the code is bundled. Library\n * mode bundles each package in isolation, while development and\n * production modes bundle the full app graph together. Library\n * mode is fastest but packages must be complaint for loading in\n * the browser.\n */\n mode: 'library' | 'development' | 'production';\n\n /**\n * Used to resolve packages in the dependency graph.\n */\n resolveMap: ResolveMap;\n\n /**\n * Reload sequence to ensure that the client is always\n * up to date with the latest changes.\n */\n sequence: number;\n\n /**\n * Get session version.\n * Used to force a hard refresh on the client.\n */\n getSessionVersion: () => number;\n\n /**\n * Used to increment the session version by 1.\n */\n incrementSessionVersion: () => void;\n\n /**\n * The name of the project folder.\n * Used to differentiate between multiple projects.\n */\n projectName: string;\n\n /**\n * The version of each target.\n * Used to force a client cache refresh on a single target.\n */\n targetVersions: Record<string, number>;\n\n /**\n * Increments the version for the given target.\n */\n incrementTargetVersion: (inputPath: string) => void;\n\n /**\n * The import map for the session.\n */\n getImportMap: () => ImportMap | undefined;\n\n setImportMap: (newImportMap: ImportMap) => ImportMap;\n}\n"]}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { checkMatch, readUserConfig, writeUserConfig } from '@ms-cloudpack/config';
|
|
2
2
|
import { addExportsMapEntry, findResolveMapEntry, flattenExportsMap, getExportsMap, } from '@ms-cloudpack/package-utilities';
|
|
3
|
+
import { normalizeRelativePath } from '@ms-cloudpack/path-string-parsing';
|
|
3
4
|
import { parseRequestUrl } from './parseRequestUrl.js';
|
|
4
|
-
import { safeRelativePath } from '@ms-cloudpack/path-string-parsing';
|
|
5
5
|
/**
|
|
6
6
|
* The addOverride method is triggered by a user action in the overlay, when we detect new usage of an import path
|
|
7
7
|
* that isn't recognized. When the user triggers this override, we write it to the cloudpack user config, rather
|
|
@@ -30,7 +30,7 @@ export async function addOverride(options, context) {
|
|
|
30
30
|
const exports = await getExportsMap({ packagePath: entry.path }, { packages, config: session.config });
|
|
31
31
|
const flattenedExports = flattenExportsMap(exports);
|
|
32
32
|
// Return false if the import path already exists in the exports map.
|
|
33
|
-
if (flattenedExports[
|
|
33
|
+
if (flattenedExports[normalizeRelativePath(importPath)]) {
|
|
34
34
|
console.debug(`The import path "${importPath}" already exists in the exports map for "${packageName}".`);
|
|
35
35
|
return addedEntry;
|
|
36
36
|
}
|
|
@@ -62,7 +62,7 @@ export async function addOverride(options, context) {
|
|
|
62
62
|
configMatches[0].exports ??= {};
|
|
63
63
|
const flattenedMatchExports = flattenExportsMap(configMatches[0].exports);
|
|
64
64
|
// Return false if the import path already exists in the match exports map.
|
|
65
|
-
if (flattenedMatchExports[
|
|
65
|
+
if (flattenedMatchExports[normalizeRelativePath(importPath)]) {
|
|
66
66
|
console.debug(`The import path "${importPath}" already exists in the config exports map for "${packageName}".`);
|
|
67
67
|
return addedEntry;
|
|
68
68
|
}
|
|
@@ -79,7 +79,7 @@ export async function addOverride(options, context) {
|
|
|
79
79
|
console.debug(`Added override for "${packageName}" to "cloudpack.config.json".`);
|
|
80
80
|
}
|
|
81
81
|
else {
|
|
82
|
-
console.warn(`Unable to add override for package ${packageName} to "cloudpack.config.json". The file ${
|
|
82
|
+
console.warn(`Unable to add override for package ${packageName} to "cloudpack.config.json". The file ${normalizeRelativePath(importPath)} could not be found. Please check the import path and try again.`);
|
|
83
83
|
}
|
|
84
84
|
return addedEntry;
|
|
85
85
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"addOverride.js","sourceRoot":"","sources":["../../src/utilities/addOverride.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,cAAc,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAC;AACnF,OAAO,EACL,kBAAkB,EAClB,mBAAmB,EACnB,iBAAiB,EACjB,aAAa,GACd,MAAM,iCAAiC,CAAC;AACzC,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"addOverride.js","sourceRoot":"","sources":["../../src/utilities/addOverride.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,cAAc,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAC;AACnF,OAAO,EACL,kBAAkB,EAClB,mBAAmB,EACnB,iBAAiB,EACjB,aAAa,GACd,MAAM,iCAAiC,CAAC;AACzC,OAAO,EAAE,qBAAqB,EAAE,MAAM,mCAAmC,CAAC;AAG1E,OAAO,EAAE,eAAe,EA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AAE,CAAC;YAC7D,OAAO,CAAC,KAAK,CAAC,oBAAoB,UAAU,mDAAmD,WAAW,IAAI,CAAC,CAAC;YAChH,OAAO,UAAU,CAAC;QACpB,CAAC;QAED,6DAA6D;QAC7D,UAAU,GAAG,MAAM,kBAAkB,CACnC;YACE,OAAO,EAAE,aAAa,CAAC,CAAC,CAAC,CAAC,OAAO;YACjC,WAAW,EAAE,KAAK,CAAC,IAAI;YACvB,UAAU;SACX,EACD,EAAE,QAAQ,EAAE,MAAM,EAAE,OAAO,CAAC,MAAM,EAAE,CACrC,CAAC;IACJ,CAAC;IAED,gBAAgB;IAChB,IAAI,UAAU,EAAE,CAAC;QACf,MAAM,eAAe,CAAC,MAAM,EAAE,OAAO,CAAC,OAAO,CAAC,CAAC;QAC/C,OAAO,CAAC,KAAK,CAAC,uBAAuB,WAAW,+BAA+B,CAAC,CAAC;IACnF,CAAC;SAAM,CAAC;QACN,OAAO,CAAC,IAAI,CACV,sCAAsC,WAAW,yCAAyC,qBAAqB,CAC7G,UAAU,CACX,kEAAkE,CACpE,CAAC;IACJ,CAAC;IAED,OAAO,UAAU,CAAC;AACpB,CAAC","sourcesContent":["import { checkMatch, readUserConfig, writeUserConfig } from '@ms-cloudpack/config';\nimport {\n addExportsMapEntry,\n findResolveMapEntry,\n flattenExportsMap,\n getExportsMap,\n} from '@ms-cloudpack/package-utilities';\nimport { normalizeRelativePath } from '@ms-cloudpack/path-string-parsing';\nimport type { Context } from '../types/Context.js';\nimport type { OverrideOptions } from '../types/OverrideOptions.js';\nimport { parseRequestUrl } from './parseRequestUrl.js';\n\n/**\n * The addOverride method is triggered by a user action in the overlay, when we detect new usage of an import path\n * that isn't recognized. When the user triggers this override, we write it to the cloudpack user config, rather\n * than generated configs which could get \"reset\" on `init --reset`.\n */\nexport async function addOverride(\n options: OverrideOptions,\n context: Pick<Context, 'packages' | 'session'>,\n): Promise<boolean> {\n const { packageName, importPath, issuerUrl } = options;\n const { session, packages } = context;\n let definition = undefined;\n let addedEntry = false;\n\n if (issuerUrl) {\n const { packageName: name, version } = parseRequestUrl(issuerUrl);\n definition = { name, version };\n }\n\n const entry = findResolveMapEntry({\n packageName,\n resolveMap: session.resolveMap,\n definition,\n });\n\n if (!entry) {\n console.error(`Could not find entry of package \"${packageName}\" in resolve map`);\n return addedEntry;\n }\n\n // Get current exports. We want to add an additional entry to what's there - not replace the default exports,\n // so we need the full map for the package.\n const exports = await getExportsMap({ packagePath: entry.path }, { packages, config: session.config });\n const flattenedExports = flattenExportsMap(exports);\n\n // Return false if the import path already exists in the exports map.\n if (flattenedExports[normalizeRelativePath(importPath)]) {\n console.debug(`The import path \"${importPath}\" already exists in the exports map for \"${packageName}\".`);\n return addedEntry;\n }\n\n // Add the single new exports entry to the exports map.\n addedEntry = await addExportsMapEntry(\n {\n exports,\n packagePath: entry.path,\n importPath,\n },\n { packages, config: session.config },\n );\n\n // Parse the user config if it exists.\n const config = await readUserConfig(session.appPath);\n\n // Ensure packageSettings exist.\n config.packageSettings ??= [];\n\n const configMatches = config.packageSettings.filter(({ match }) =>\n checkMatch({ name: packageName, version: entry.version, match, firstMatch: true }),\n );\n\n if (!configMatches.length) {\n config.packageSettings.push({\n match: {\n name: packageName,\n version: entry.version?.match(/^\\d+\\.\\d+\\.\\d+(-[a-z0-9.-]+)?$/) ? `^${entry.version}` : undefined,\n },\n exports,\n });\n } else {\n if (configMatches.length > 1) {\n console.debug(\n `Found multiple matches for package \"${packageName}\" in cloudpack.config.json. Using the first match.`,\n );\n }\n // Use the first match.\n configMatches[0].exports ??= {};\n\n const flattenedMatchExports = flattenExportsMap(configMatches[0].exports);\n\n // Return false if the import path already exists in the match exports map.\n if (flattenedMatchExports[normalizeRelativePath(importPath)]) {\n console.debug(`The import path \"${importPath}\" already exists in the config exports map for \"${packageName}\".`);\n return addedEntry;\n }\n\n // Add the single new exports entry to the match exports map.\n addedEntry = await addExportsMapEntry(\n {\n exports: configMatches[0].exports,\n packagePath: entry.path,\n importPath,\n },\n { packages, config: session.config },\n );\n }\n\n // Write config.\n if (addedEntry) {\n await writeUserConfig(config, session.appPath);\n console.debug(`Added override for \"${packageName}\" to \"cloudpack.config.json\".`);\n } else {\n console.warn(\n `Unable to add override for package ${packageName} to \"cloudpack.config.json\". The file ${normalizeRelativePath(\n importPath,\n )} could not be found. Please check the import path and try again.`,\n );\n }\n\n return addedEntry;\n}\n"]}
|
|
@@ -1,11 +1,19 @@
|
|
|
1
|
+
import type { PackageDefinitionsCache } from '@ms-cloudpack/bundler-types';
|
|
2
|
+
import type { CloudpackConfig } from '@ms-cloudpack/config-types';
|
|
3
|
+
import type { PackageHashes } from '@ms-cloudpack/package-hashes';
|
|
1
4
|
import { type TaskReporter } from '@ms-cloudpack/task-reporter';
|
|
2
|
-
import type { BundleTaskOptions } from '../types/BundleTaskOptions.js';
|
|
3
|
-
import type { BundleRequest } from '../types/BundleRequest.js';
|
|
4
5
|
import type { TelemetryClient } from '@ms-cloudpack/telemetry';
|
|
6
|
+
import type { BundleRequest } from '../types/BundleRequest.js';
|
|
7
|
+
import type { BundleTaskOptions } from '../types/BundleTaskOptions.js';
|
|
5
8
|
export declare function bundleTask(params: {
|
|
6
9
|
bundleRequest: BundleRequest;
|
|
7
10
|
options?: BundleTaskOptions;
|
|
8
|
-
|
|
9
|
-
|
|
11
|
+
context: {
|
|
12
|
+
packages: PackageDefinitionsCache;
|
|
13
|
+
config: CloudpackConfig;
|
|
14
|
+
packageHashes: PackageHashes;
|
|
15
|
+
reporter?: TaskReporter;
|
|
16
|
+
telemetryClient?: TelemetryClient;
|
|
17
|
+
};
|
|
10
18
|
}): Promise<BundleRequest>;
|
|
11
19
|
//# sourceMappingURL=bundleTask.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"bundleTask.d.ts","sourceRoot":"","sources":["../../src/utilities/bundleTask.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"bundleTask.d.ts","sourceRoot":"","sources":["../../src/utilities/bundleTask.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAiB,uBAAuB,EAAE,MAAM,6BAA6B,CAAC;AAC1F,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,4BAA4B,CAAC;AAClE,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,8BAA8B,CAAC;AAKlE,OAAO,EAGL,KAAK,YAAY,EAElB,MAAM,6BAA6B,CAAC;AACrC,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,yBAAyB,CAAC;AAG/D,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,2BAA2B,CAAC;AAC/D,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,+BAA+B,CAAC;AAUvE,wBAAsB,UAAU,CAAC,MAAM,EAAE;IACvC,aAAa,EAAE,aAAa,CAAC;IAC7B,OAAO,CAAC,EAAE,iBAAiB,CAAC;IAC5B,OAAO,EAAE;QACP,QAAQ,EAAE,uBAAuB,CAAC;QAClC,MAAM,EAAE,eAAe,CAAC;QACxB,aAAa,EAAE,aAAa,CAAC;QAC7B,QAAQ,CAAC,EAAE,YAAY,CAAC;QACxB,eAAe,CAAC,EAAE,eAAe,CAAC;KACnC,CAAC;CACH,GAAG,OAAO,CAAC,aAAa,CAAC,CAqEzB"}
|
|
@@ -1,30 +1,30 @@
|
|
|
1
1
|
import { bundle as bundleInternal, getEntriesMapFromPackage, getExternalsFromPackage } from '@ms-cloudpack/bundler';
|
|
2
|
+
import { getPackageSettings } from '@ms-cloudpack/config';
|
|
2
3
|
import { writeJson } from '@ms-cloudpack/json-utilities';
|
|
3
|
-
import {
|
|
4
|
+
import { getExportsMap } from '@ms-cloudpack/package-utilities';
|
|
5
|
+
import { normalizeRelativePath } from '@ms-cloudpack/path-string-parsing';
|
|
4
6
|
import { bulletedList, formatPackageName, } from '@ms-cloudpack/task-reporter';
|
|
5
7
|
import path from 'path';
|
|
6
8
|
import { prepareOutputPath } from '../common/prepareOutputPath.js';
|
|
9
|
+
import { diskCacheRatioMetricEventAggregator } from './diskCacheRatioMetricEventAggregator.js';
|
|
7
10
|
import { formatBundleErrors } from './formatBundleErrors.js';
|
|
11
|
+
import { getBundleInfo } from './getBundleInfo.js';
|
|
12
|
+
import { getBundleLocation } from './getBundleLocation.js';
|
|
8
13
|
import { getFileSizeSync } from './getFileSizeSync.js';
|
|
9
|
-
import { getPackageSettings } from '@ms-cloudpack/config';
|
|
10
14
|
import { isCachedResultValid } from './isCachedResultValid.js';
|
|
11
|
-
import { diskCacheRatioMetricEventAggregator } from './diskCacheRatioMetricEventAggregator.js';
|
|
12
|
-
import { getBundleLocation } from './getBundleLocation.js';
|
|
13
|
-
import { getBundleInfo } from './getBundleInfo.js';
|
|
14
|
-
import { getExportsMap } from '@ms-cloudpack/package-utilities';
|
|
15
15
|
import { readResultFromCache } from './readResultFromCache.js';
|
|
16
16
|
import { saveResultToCache } from './saveResultToCache.js';
|
|
17
17
|
export async function bundleTask(params) {
|
|
18
|
-
const { bundleRequest, options = {},
|
|
18
|
+
const { bundleRequest, options = {}, context } = params;
|
|
19
19
|
const { packageName, version } = bundleRequest;
|
|
20
|
-
const {
|
|
20
|
+
const { reporter, telemetryClient } = context;
|
|
21
21
|
const taskName = `Bundle ${formatPackageName({
|
|
22
22
|
name: packageName,
|
|
23
23
|
version,
|
|
24
24
|
})}`;
|
|
25
25
|
telemetryClient?.performance.registerAggregator(diskCacheRatioMetricEventAggregator);
|
|
26
26
|
const executeBundle = async () => {
|
|
27
|
-
await bundle(bundleRequest,
|
|
27
|
+
await bundle({ bundleRequest, context, options });
|
|
28
28
|
diskCacheRatioMetricEventAggregator?.record({
|
|
29
29
|
isCacheHit: !!bundleRequest.resultFromCache,
|
|
30
30
|
isExternal: bundleRequest.isExternal,
|
|
@@ -56,7 +56,7 @@ export async function bundleTask(params) {
|
|
|
56
56
|
`Entries:`,
|
|
57
57
|
Object.values(result.entries || {}),
|
|
58
58
|
`Output path: ${result.outputPath}`,
|
|
59
|
-
result.outputFiles?.map((file) => `${
|
|
59
|
+
result.outputFiles?.map((file) => `${normalizeRelativePath(file.outputPath)} (${getFileSizeSync(path.resolve(result.outputPath, file.outputPath))})`),
|
|
60
60
|
]),
|
|
61
61
|
}),
|
|
62
62
|
};
|
|
@@ -69,9 +69,10 @@ export async function bundleTask(params) {
|
|
|
69
69
|
}
|
|
70
70
|
return bundleRequest;
|
|
71
71
|
}
|
|
72
|
-
async function bundle(
|
|
73
|
-
const {
|
|
74
|
-
const
|
|
72
|
+
async function bundle(params) {
|
|
73
|
+
const { bundleRequest, context, options = {} } = params;
|
|
74
|
+
const { config, packageHashes } = context;
|
|
75
|
+
const { force } = options;
|
|
75
76
|
// If force is set, dispose the existing result.
|
|
76
77
|
if (force && bundleRequest?.result?.dispose) {
|
|
77
78
|
bundleRequest.result.dispose();
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"bundleTask.js","sourceRoot":"","sources":["../../src/utilities/bundleTask.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,IAAI,cAAc,EAAE,wBAAwB,EAAE,uBAAuB,EAAE,MAAM,uBAAuB,CAAC;AACpH,OAAO,EAAE,SAAS,EAAE,MAAM,8BAA8B,CAAC;AACzD,OAAO,EAAE,gBAAgB,EAAE,MAAM,mCAAmC,CAAC;AACrE,OAAO,EACL,YAAY,EACZ,iBAAiB,GAGlB,MAAM,6BAA6B,CAAC;AACrC,OAAO,IAAI,MAAM,MAAM,CAAC;AACxB,OAAO,EAAE,iBAAiB,EAAE,MAAM,gCAAgC,CAAC;AAGnE,OAAO,EAAE,kBAAkB,EAAE,MAAM,yBAAyB,CAAC;AAC7D,OAAO,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAC;AAEvD,OAAO,EAAE,kBAAkB,EAAE,MAAM,sBAAsB,CAAC;AAC1D,OAAO,EAAE,mBAAmB,EAAE,MAAM,0BAA0B,CAAC;AAE/D,OAAO,EAAE,mCAAmC,EAAE,MAAM,0CAA0C,CAAC;AAC/F,OAAO,EAAE,iBAA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AAC","sourcesContent":["import { bundle as bundleInternal, getEntriesMapFromPackage, getExternalsFromPackage } from '@ms-cloudpack/bundler';\nimport { writeJson } from '@ms-cloudpack/json-utilities';\nimport { safeRelativePath } from '@ms-cloudpack/path-string-parsing';\nimport {\n bulletedList,\n formatPackageName,\n type TaskReporter,\n type TaskReporterTaskResult,\n} from '@ms-cloudpack/task-reporter';\nimport path from 'path';\nimport { prepareOutputPath } from '../common/prepareOutputPath.js';\nimport type { BundleTaskOptions } from '../types/BundleTaskOptions.js';\nimport type { BundleRequest } from '../types/BundleRequest.js';\nimport { formatBundleErrors } from './formatBundleErrors.js';\nimport { getFileSizeSync } from './getFileSizeSync.js';\nimport type { BundleOptions } from '@ms-cloudpack/bundler-types';\nimport { getPackageSettings } from '@ms-cloudpack/config';\nimport { isCachedResultValid } from './isCachedResultValid.js';\nimport type { TelemetryClient } from '@ms-cloudpack/telemetry';\nimport { diskCacheRatioMetricEventAggregator } from './diskCacheRatioMetricEventAggregator.js';\nimport { getBundleLocation } from './getBundleLocation.js';\nimport { getBundleInfo } from './getBundleInfo.js';\nimport { getExportsMap } from '@ms-cloudpack/package-utilities';\nimport { readResultFromCache } from './readResultFromCache.js';\nimport { saveResultToCache } from './saveResultToCache.js';\n\nexport async function bundleTask(params: {\n bundleRequest: BundleRequest;\n options?: BundleTaskOptions;\n reporter?: TaskReporter;\n telemetryClient?: TelemetryClient;\n}): Promise<BundleRequest> {\n const { bundleRequest, options = {}, reporter, telemetryClient } = params;\n const { packageName, version } = bundleRequest;\n const { force } = options || {};\n\n const taskName = `Bundle ${formatPackageName({\n name: packageName,\n version,\n })}`;\n\n telemetryClient?.performance.registerAggregator(diskCacheRatioMetricEventAggregator);\n\n const executeBundle = async (): Promise<TaskReporterTaskResult> => {\n await bundle(bundleRequest, force);\n\n diskCacheRatioMetricEventAggregator?.record({\n isCacheHit: !!bundleRequest.resultFromCache,\n isExternal: bundleRequest.isExternal,\n });\n\n const { result } = bundleRequest;\n\n if (!result) {\n return {\n status: 'fail',\n details: `No result was found for \"${packageName}@${version}\"`,\n };\n }\n\n result.outputFiles ??= [];\n result.errors ??= [];\n result.warnings ??= [];\n\n if (!result.outputFiles.length && !result.errors?.length) {\n result.warnings.push({\n text: `No output files were found for \"${packageName}\" in \"${result.outputPath}\"`,\n });\n }\n\n return {\n status: result.errors.length ? 'fail' : 'complete',\n ...(result.errors?.length\n ? formatBundleErrors(result.errors)\n : {\n details: bulletedList([\n `Package: ${bundleRequest.packageName}@${bundleRequest.version}`,\n `Bundler: ${result.bundlerName || 'unknown'}`,\n `Input path: ${bundleRequest.packagePath}`,\n `Entries:`,\n Object.values(result.entries || {}),\n `Output path: ${result.outputPath}`,\n result.outputFiles?.map(\n (file) =>\n `${safeRelativePath(path.relative(result.outputPath, file.outputPath))} (${getFileSizeSync(\n path.resolve(result.outputPath, file.outputPath),\n )})`,\n ),\n ]),\n }),\n };\n };\n\n if (reporter) {\n await reporter.runTask(taskName, executeBundle);\n } else {\n await executeBundle();\n }\n\n return bundleRequest;\n}\n\nasync function bundle(bundleRequest: BundleRequest, force?: boolean): Promise<BundleRequest> {\n const { packages, config, packageHashes } = bundleRequest;\n const context = { packages, config, packageHashes };\n\n // If force is set, dispose the existing result.\n if (force && bundleRequest?.result?.dispose) {\n bundleRequest.result.dispose();\n bundleRequest.result = undefined;\n }\n\n const { packagePath, isExternal, isIncremental, disableSourceMaps, shouldGetBundleInfo } = bundleRequest;\n\n const outputPath =\n bundleRequest.outputPath ?? (await getBundleLocation({ packagePath, shouldRecalculate: force }, context)).path;\n\n // Rehydrate the result if not incremental.\n if (bundleRequest.result === undefined && !force) {\n bundleRequest.result = await readResultFromCache(outputPath, {\n inputPath: packagePath,\n });\n }\n\n const hash = !isExternal\n ? await packageHashes.get({ packagePath, isSourceHashingEnabled: true, shouldRecalculate: true })\n : undefined;\n\n // if the cached result is valid, use it.\n if (!force && isCachedResultValid({ bundleRequest, hash })) {\n console.debug(`Using cached result for ${bundleRequest.packageName}@${bundleRequest.version}`);\n bundleRequest.resultFromCache = true;\n } else {\n bundleRequest.resultFromCache = false;\n\n // Only use cached result if it's successful.\n await prepareOutputPath(outputPath);\n\n if (bundleRequest.result?.rebuild) {\n bundleRequest.result = {\n ...(await bundleRequest.result.rebuild()),\n outputPath: bundleRequest.result.outputPath,\n hash,\n };\n } else {\n const { userPackageSettings, generatedPackageSettings } =\n getPackageSettings({\n name: bundleRequest.packageName,\n version: bundleRequest.version,\n config,\n }) || {};\n const { bundlerType, bundlerOptions } = userPackageSettings || {};\n\n const inlinedDependencies = [\n ...(userPackageSettings?.inlinedDependencies || []),\n ...(generatedPackageSettings?.inlinedDependencies || []),\n ];\n\n const bundleOptions: BundleOptions = {\n bundlerType: bundleRequest.bundlerType || bundlerType,\n overrideOptions: bundlerOptions,\n inputPath: packagePath,\n outputPath,\n incremental: isIncremental !== undefined ? isIncremental : !isExternal,\n sourcemap: disableSourceMaps ? undefined : 'linked',\n entries: await getEntriesMapFromPackage({ inputPath: packagePath }, context),\n inlined: inlinedDependencies,\n external: await getExternalsFromPackage({ inputPath: packagePath }, context),\n };\n\n const bundleInternalResult = await bundleInternal(bundleOptions, { config });\n bundleRequest.result = {\n ...bundleInternalResult,\n outputPath: bundleOptions.outputPath ?? outputPath,\n hash,\n };\n }\n\n // Write the result to disk.\n await saveResultToCache(bundleRequest.result);\n }\n\n // If we should find required imports and exports per bundle\n if (shouldGetBundleInfo && !bundleRequest.result?.errors?.length && bundleRequest.result?.outputFiles?.length) {\n const bundleInfoPath = path.join(outputPath, 'bundle-info.json');\n\n // Exports map is needed to find the bundle info per entry we intend to bundle.\n // Exports map is used instead of bundleRequest.entries since it is easier to use\n // because it contains the paths other packages use to import the entry and\n // the relative location of the bundled files.\n const exportsMap = await getExportsMap({ packagePath }, context);\n\n const bundleInfo = await getBundleInfo({\n outputPath,\n outputFiles: bundleRequest.result.outputFiles,\n exportsMap,\n isExternal,\n });\n\n bundleRequest.result.info = bundleInfo;\n\n // Write to cache for future use. (Ignore the promise result.)\n // eslint-disable-next-line @typescript-eslint/no-floating-promises\n writeJson(bundleInfoPath, bundleInfo);\n }\n\n return bundleRequest;\n}\n"]}
|
|
1
|
+
{"version":3,"file":"bundleTask.js","sourceRoot":"","sources":["../../src/utilities/bundleTask.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,IAAI,cAAc,EAAE,wBAAwB,EAAE,uBAAuB,EAAE,MAAM,uBAAuB,CAAC;AAIpH,OAAO,EAAE,kBAAkB,EAAE,MAAM,sBAAsB,CAAC;AAC1D,OAAO,EAAE,SAAS,EAAE,MAAM,8BAA8B,CAAC;AACzD,OAAO,EAAE,aAAa,EAAE,MAAM,iCAAiC,CAAC;AAChE,OAAO,EAAE,qBAAqB,EAAE,MAAM,mCAAmC,CAAC;AAC1E,OAAO,EACL,YAAY,EACZ,iBAAiB,GAGlB,MAAM,6BAA6B,CAAC;AAErC,OAAO,IAAI,MAAM,MAAM,CAAC;AACxB,OAAO,EAAE,iBAAiB,EAAE,MAAM,gCAAgC,CAAC;AAGnE,OAAO,EAAE,mCAAmC,EAAE,MAAM,0CAA0C,CAAC;AAC/F,OAAO,EAAE,kBAAkB,EAAE,MAAM,yBAAyB,CAAC;AAC7D,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AACnD,OAAO,EAAE,iBAAiB,EAAE,MAAM,wBAAwB,CAAC;AAC3D,OAAO,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAC;AACvD,OAAO,EAAE,mBAAmB,EAAE,MAAM,0BAA0B,CAAC;AAC/D,OAAO,EAAE,mBAAmB,EAAE,MAAM,0BAA0B,CAAC;AAC/D,OAAO,EAAE,iBAAiB,EAAE,MAAM,wBAAwB,CAAC;AAE3D,MAAM,CAAC,KAAK,UAAU,UAAU,CAAC,MAUhC;IACC,MAAM,EAAE,aAAa,EAAE,OAAO,GAAG,EAAE,EAAE,OAAO,EAAE,GAAG,MAAM,CAAC;IACxD,MAAM,EAAE,WAAW,EAAE,OAA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AClD,IAAI;aACL,CAAC;QACJ,CAAC;QAED,4BAA4B;QAC5B,MAAM,iBAAiB,CAAC,aAAa,CAAC,MAAM,CAAC,CAAC;IAChD,CAAC;IAED,4DAA4D;IAC5D,IAAI,mBAAmB,IAAI,CAAC,aAAa,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,IAAI,aAAa,CAAC,MAAM,EAAE,WAAW,EAAE,MAAM,EAAE,CAAC;QAC9G,MAAM,cAAc,GAAG,IAAI,CAAC,IAAI,CAAC,UAAU,EAAE,kBAAkB,CAAC,CAAC;QAEjE,+EAA+E;QAC/E,iFAAiF;QACjF,2EAA2E;QAC3E,8CAA8C;QAC9C,MAAM,UAAU,GAAG,MAAM,aAAa,CAAC,EAAE,WAAW,EAAE,EAAE,OAAO,CAAC,CAAC;QAEjE,MAAM,UAAU,GAAG,MAAM,aAAa,CAAC;YACrC,UAAU;YACV,WAAW,EAAE,aAAa,CAAC,MAAM,CAAC,WAAW;YAC7C,UAAU;YACV,UAAU;SACX,CAAC,CAAC;QAEH,aAAa,CAAC,MAAM,CAAC,IAAI,GAAG,UAAU,CAAC;QAEvC,8DAA8D;QAC9D,mEAAmE;QACnE,SAAS,CAAC,cAAc,EAAE,UAAU,CAAC,CAAC;IACxC,CAAC;IAED,OAAO,aAAa,CAAC;AACvB,CAAC","sourcesContent":["import { bundle as bundleInternal, getEntriesMapFromPackage, getExternalsFromPackage } from '@ms-cloudpack/bundler';\nimport type { BundleOptions, PackageDefinitionsCache } from '@ms-cloudpack/bundler-types';\nimport type { CloudpackConfig } from '@ms-cloudpack/config-types';\nimport type { PackageHashes } from '@ms-cloudpack/package-hashes';\nimport { getPackageSettings } from '@ms-cloudpack/config';\nimport { writeJson } from '@ms-cloudpack/json-utilities';\nimport { getExportsMap } from '@ms-cloudpack/package-utilities';\nimport { normalizeRelativePath } from '@ms-cloudpack/path-string-parsing';\nimport {\n bulletedList,\n formatPackageName,\n type TaskReporter,\n type TaskReporterTaskResult,\n} from '@ms-cloudpack/task-reporter';\nimport type { TelemetryClient } from '@ms-cloudpack/telemetry';\nimport path from 'path';\nimport { prepareOutputPath } from '../common/prepareOutputPath.js';\nimport type { BundleRequest } from '../types/BundleRequest.js';\nimport type { BundleTaskOptions } from '../types/BundleTaskOptions.js';\nimport { diskCacheRatioMetricEventAggregator } from './diskCacheRatioMetricEventAggregator.js';\nimport { formatBundleErrors } from './formatBundleErrors.js';\nimport { getBundleInfo } from './getBundleInfo.js';\nimport { getBundleLocation } from './getBundleLocation.js';\nimport { getFileSizeSync } from './getFileSizeSync.js';\nimport { isCachedResultValid } from './isCachedResultValid.js';\nimport { readResultFromCache } from './readResultFromCache.js';\nimport { saveResultToCache } from './saveResultToCache.js';\n\nexport async function bundleTask(params: {\n bundleRequest: BundleRequest;\n options?: BundleTaskOptions;\n context: {\n packages: PackageDefinitionsCache;\n config: CloudpackConfig;\n packageHashes: PackageHashes;\n reporter?: TaskReporter;\n telemetryClient?: TelemetryClient;\n };\n}): Promise<BundleRequest> {\n const { bundleRequest, options = {}, context } = params;\n const { packageName, version } = bundleRequest;\n const { reporter, telemetryClient } = context;\n\n const taskName = `Bundle ${formatPackageName({\n name: packageName,\n version,\n })}`;\n\n telemetryClient?.performance.registerAggregator(diskCacheRatioMetricEventAggregator);\n\n const executeBundle = async (): Promise<TaskReporterTaskResult> => {\n await bundle({ bundleRequest, context, options });\n\n diskCacheRatioMetricEventAggregator?.record({\n isCacheHit: !!bundleRequest.resultFromCache,\n isExternal: bundleRequest.isExternal,\n });\n\n const { result } = bundleRequest;\n\n if (!result) {\n return {\n status: 'fail',\n details: `No result was found for \"${packageName}@${version}\"`,\n };\n }\n\n result.outputFiles ??= [];\n result.errors ??= [];\n result.warnings ??= [];\n\n if (!result.outputFiles.length && !result.errors?.length) {\n result.warnings.push({\n text: `No output files were found for \"${packageName}\" in \"${result.outputPath}\"`,\n });\n }\n\n return {\n status: result.errors.length ? 'fail' : 'complete',\n ...(result.errors?.length\n ? formatBundleErrors(result.errors)\n : {\n details: bulletedList([\n `Package: ${bundleRequest.packageName}@${bundleRequest.version}`,\n `Bundler: ${result.bundlerName || 'unknown'}`,\n `Input path: ${bundleRequest.packagePath}`,\n `Entries:`,\n Object.values(result.entries || {}),\n `Output path: ${result.outputPath}`,\n result.outputFiles?.map(\n (file) =>\n `${normalizeRelativePath(file.outputPath)} (${getFileSizeSync(\n path.resolve(result.outputPath, file.outputPath),\n )})`,\n ),\n ]),\n }),\n };\n };\n\n if (reporter) {\n await reporter.runTask(taskName, executeBundle);\n } else {\n await executeBundle();\n }\n\n return bundleRequest;\n}\n\nasync function bundle(params: {\n bundleRequest: BundleRequest;\n context: {\n packages: PackageDefinitionsCache;\n config: CloudpackConfig;\n packageHashes: PackageHashes;\n };\n options?: { force?: boolean };\n}): Promise<BundleRequest> {\n const { bundleRequest, context, options = {} } = params;\n const { config, packageHashes } = context;\n const { force } = options;\n\n // If force is set, dispose the existing result.\n if (force && bundleRequest?.result?.dispose) {\n bundleRequest.result.dispose();\n bundleRequest.result = undefined;\n }\n\n const { packagePath, isExternal, isIncremental, disableSourceMaps, shouldGetBundleInfo } = bundleRequest;\n\n const outputPath =\n bundleRequest.outputPath ?? (await getBundleLocation({ packagePath, shouldRecalculate: force }, context)).path;\n\n // Rehydrate the result if not incremental.\n if (bundleRequest.result === undefined && !force) {\n bundleRequest.result = await readResultFromCache(outputPath, {\n inputPath: packagePath,\n });\n }\n\n const hash = !isExternal\n ? await packageHashes.get({ packagePath, isSourceHashingEnabled: true, shouldRecalculate: true })\n : undefined;\n\n // if the cached result is valid, use it.\n if (!force && isCachedResultValid({ bundleRequest, hash })) {\n console.debug(`Using cached result for ${bundleRequest.packageName}@${bundleRequest.version}`);\n bundleRequest.resultFromCache = true;\n } else {\n bundleRequest.resultFromCache = false;\n\n // Only use cached result if it's successful.\n await prepareOutputPath(outputPath);\n\n if (bundleRequest.result?.rebuild) {\n bundleRequest.result = {\n ...(await bundleRequest.result.rebuild()),\n outputPath: bundleRequest.result.outputPath,\n hash,\n };\n } else {\n const { userPackageSettings, generatedPackageSettings } =\n getPackageSettings({\n name: bundleRequest.packageName,\n version: bundleRequest.version,\n config,\n }) || {};\n const { bundlerType, bundlerOptions } = userPackageSettings || {};\n\n const inlinedDependencies = [\n ...(userPackageSettings?.inlinedDependencies || []),\n ...(generatedPackageSettings?.inlinedDependencies || []),\n ];\n\n const bundleOptions: BundleOptions = {\n bundlerType: bundleRequest.bundlerType || bundlerType,\n overrideOptions: bundlerOptions,\n inputPath: packagePath,\n outputPath,\n incremental: isIncremental !== undefined ? isIncremental : !isExternal,\n sourcemap: disableSourceMaps ? undefined : 'linked',\n entries: await getEntriesMapFromPackage({ inputPath: packagePath }, context),\n inlined: inlinedDependencies,\n external: await getExternalsFromPackage({ inputPath: packagePath }, context),\n };\n\n const bundleInternalResult = await bundleInternal(bundleOptions, { config });\n bundleRequest.result = {\n ...bundleInternalResult,\n outputPath: bundleOptions.outputPath ?? outputPath,\n hash,\n };\n }\n\n // Write the result to disk.\n await saveResultToCache(bundleRequest.result);\n }\n\n // If we should find required imports and exports per bundle\n if (shouldGetBundleInfo && !bundleRequest.result?.errors?.length && bundleRequest.result?.outputFiles?.length) {\n const bundleInfoPath = path.join(outputPath, 'bundle-info.json');\n\n // Exports map is needed to find the bundle info per entry we intend to bundle.\n // Exports map is used instead of bundleRequest.entries since it is easier to use\n // because it contains the paths other packages use to import the entry and\n // the relative location of the bundled files.\n const exportsMap = await getExportsMap({ packagePath }, context);\n\n const bundleInfo = await getBundleInfo({\n outputPath,\n outputFiles: bundleRequest.result.outputFiles,\n exportsMap,\n isExternal,\n });\n\n bundleRequest.result.info = bundleInfo;\n\n // Write to cache for future use. (Ignore the promise result.)\n // eslint-disable-next-line @typescript-eslint/no-floating-promises\n writeJson(bundleInfoPath, bundleInfo);\n }\n\n return bundleRequest;\n}\n"]}
|
|
@@ -1,8 +1,6 @@
|
|
|
1
1
|
import type { CloudpackConfig } from '@ms-cloudpack/config-types';
|
|
2
2
|
import type { ResolveMapEntry } from '@ms-cloudpack/package-utilities';
|
|
3
|
-
import type { PackageDefinitionsCache } from '@ms-cloudpack/bundler-types';
|
|
4
3
|
import type { BundleRequest } from '../types/BundleRequest.js';
|
|
5
|
-
import type { PackageHashes } from '@ms-cloudpack/package-hashes';
|
|
6
4
|
export declare function createBundleRequestForPackage(options: {
|
|
7
5
|
packageEntry: ResolveMapEntry;
|
|
8
6
|
outputPath?: string;
|
|
@@ -13,7 +11,5 @@ export declare function createBundleRequestForPackage(options: {
|
|
|
13
11
|
isIncremental?: boolean;
|
|
14
12
|
}, context: {
|
|
15
13
|
config: CloudpackConfig;
|
|
16
|
-
packages: PackageDefinitionsCache;
|
|
17
|
-
packageHashes: PackageHashes;
|
|
18
14
|
}): BundleRequest;
|
|
19
15
|
//# sourceMappingURL=createBundleRequestForPackage.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"createBundleRequestForPackage.d.ts","sourceRoot":"","sources":["../../src/utilities/createBundleRequestForPackage.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,4BAA4B,CAAC;AAClE,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,iCAAiC,CAAC;AACvE,OAAO,KAAK,EAAE,
|
|
1
|
+
{"version":3,"file":"createBundleRequestForPackage.d.ts","sourceRoot":"","sources":["../../src/utilities/createBundleRequestForPackage.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,4BAA4B,CAAC;AAClE,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,iCAAiC,CAAC;AACvE,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,2BAA2B,CAAC;AAE/D,wBAAgB,6BAA6B,CAC3C,OAAO,EAAE;IACP,YAAY,EAAE,eAAe,CAAC;IAC9B,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,iBAAiB,CAAC,EAAE,OAAO,CAAC;IAC5B,mBAAmB,CAAC,EAAE,OAAO,CAAC;IAC9B,YAAY,CAAC,EAAE,OAAO,CAAC;IACvB,aAAa,CAAC,EAAE,OAAO,CAAC;CACzB,EACD,OAAO,EAAE;IACP,MAAM,EAAE,eAAe,CAAC;CACzB,GACA,aAAa,CAmBf"}
|
|
@@ -15,7 +15,6 @@ export function createBundleRequestForPackage(options, context) {
|
|
|
15
15
|
shouldGetBundleInfo: options.shouldGetBundleInfo ?? features.enqueueDependencies,
|
|
16
16
|
disableCache: options.disableCache,
|
|
17
17
|
bundlerType: options.bundlerType,
|
|
18
|
-
...context,
|
|
19
18
|
};
|
|
20
19
|
}
|
|
21
20
|
//# sourceMappingURL=createBundleRequestForPackage.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"createBundleRequestForPackage.js","sourceRoot":"","sources":["../../src/utilities/createBundleRequestForPackage.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"createBundleRequestForPackage.js","sourceRoot":"","sources":["../../src/utilities/createBundleRequestForPackage.ts"],"names":[],"mappings":"AAIA,MAAM,UAAU,6BAA6B,CAC3C,OAQC,EACD,OAEC;IAED,MAAM,EAAE,YAAY,EAAE,aAAa,EAAE,GAAG,OAAO,CAAC;IAChD,MAAM,EAAE,MAAM,EAAE,GAAG,OAAO,CAAC;IAC3B,MAAM,EAAE,QAAQ,GAAG,EAAE,EAAE,GAAG,MAAM,CAAC;IACjC,MAAM,EAAE,IAAI,EAAE,OAAO,EAAE,IAAI,EAAE,UAAU,EAAE,GAAG,YAAY,CAAC;IAEzD,OAAO;QACL,EAAE,EAAE,IAAI;QACR,WAAW,EAAE,IAAI;QACjB,WAAW,EAAE,IAAI;QACjB,UAAU,EAAE,CAAC,CAAC,UAAU;QACxB,aAAa,EAAE,aAAa;QAC5B,UAAU,EAAE,OAAO,CAAC,UAAU;QAC9B,OAAO;QACP,iBAAiB,EAAE,OAAO,CAAC,iBAAiB,IAAI,QAAQ,CAAC,iBAAiB;QAC1E,mBAAmB,EAAE,OAAO,CAAC,mBAAmB,IAAI,QAAQ,CAAC,mBAAmB;QAChF,YAAY,EAAE,OAAO,CAAC,YAAY;QAClC,WAAW,EAAE,OAAO,CAAC,WAAW;KACjC,CAAC;AACJ,CAAC","sourcesContent":["import type { CloudpackConfig } from '@ms-cloudpack/config-types';\nimport type { ResolveMapEntry } from '@ms-cloudpack/package-utilities';\nimport type { BundleRequest } from '../types/BundleRequest.js';\n\nexport function createBundleRequestForPackage(\n options: {\n packageEntry: ResolveMapEntry;\n outputPath?: string;\n bundlerType?: string;\n disableSourceMaps?: boolean;\n shouldGetBundleInfo?: boolean;\n disableCache?: boolean;\n isIncremental?: boolean;\n },\n context: {\n config: CloudpackConfig;\n },\n): BundleRequest {\n const { packageEntry, isIncremental } = options;\n const { config } = context;\n const { features = {} } = config;\n const { path, version, name, isExternal } = packageEntry;\n\n return {\n id: path,\n packagePath: path,\n packageName: name,\n isExternal: !!isExternal,\n isIncremental: isIncremental,\n outputPath: options.outputPath,\n version,\n disableSourceMaps: options.disableSourceMaps ?? features.disableSourceMaps,\n shouldGetBundleInfo: options.shouldGetBundleInfo ?? features.enqueueDependencies,\n disableCache: options.disableCache,\n bundlerType: options.bundlerType,\n };\n}\n"]}
|
|
@@ -4,15 +4,23 @@ import type { Task } from '../types/Task.js';
|
|
|
4
4
|
import type { TaskReporter } from '@ms-cloudpack/task-reporter';
|
|
5
5
|
import type { Session } from '../types/Session.js';
|
|
6
6
|
import type { TelemetryClient } from '@ms-cloudpack/telemetry';
|
|
7
|
-
import type { PackageImportPaths } from '@ms-cloudpack/
|
|
7
|
+
import type { PackageImportPaths } from '@ms-cloudpack/import-map';
|
|
8
|
+
import type { PackageDefinitionsCache } from '@ms-cloudpack/bundler-types';
|
|
9
|
+
import type { PackageHashes } from '@ms-cloudpack/package-hashes';
|
|
8
10
|
/**
|
|
9
11
|
* Creates a bundle task tracked in the task runner of the api server. This allows active tasks to be tracked
|
|
10
12
|
* remotely (e.g. in the browser) and allows the user to cancel tasks.
|
|
11
13
|
*/
|
|
12
|
-
export declare function createBundleTask(
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
14
|
+
export declare function createBundleTask(params: {
|
|
15
|
+
bundleRequest: BundleRequest;
|
|
16
|
+
context: {
|
|
17
|
+
session: Session;
|
|
18
|
+
packages: PackageDefinitionsCache;
|
|
19
|
+
packageHashes: PackageHashes;
|
|
20
|
+
packageImportPaths: PackageImportPaths;
|
|
21
|
+
reporter?: TaskReporter;
|
|
22
|
+
telemetryClient?: TelemetryClient;
|
|
23
|
+
};
|
|
24
|
+
options?: BundleTaskOptions;
|
|
25
|
+
}): Task<BundleRequest>;
|
|
18
26
|
//# sourceMappingURL=createBundleTask.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"createBundleTask.d.ts","sourceRoot":"","sources":["../../src/utilities/createBundleTask.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,+BAA+B,CAAC;AACvE,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,2BAA2B,CAAC;AAC/D,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,kBAAkB,CAAC;AAK7C,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,6BAA6B,CAAC;AAEhE,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,qBAAqB,CAAC;AACnD,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,yBAAyB,CAAC;AAC/D,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,
|
|
1
|
+
{"version":3,"file":"createBundleTask.d.ts","sourceRoot":"","sources":["../../src/utilities/createBundleTask.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,+BAA+B,CAAC;AACvE,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,2BAA2B,CAAC;AAC/D,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,kBAAkB,CAAC;AAK7C,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,6BAA6B,CAAC;AAEhE,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,qBAAqB,CAAC;AACnD,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,yBAAyB,CAAC;AAC/D,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,0BAA0B,CAAC;AACnE,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,6BAA6B,CAAC;AAC3E,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,8BAA8B,CAAC;AAElE;;;GAGG;AACH,wBAAgB,gBAAgB,CAAC,MAAM,EAAE;IACvC,aAAa,EAAE,aAAa,CAAC;IAC7B,OAAO,EAAE;QACP,OAAO,EAAE,OAAO,CAAC;QACjB,QAAQ,EAAE,uBAAuB,CAAC;QAClC,aAAa,EAAE,aAAa,CAAC;QAC7B,kBAAkB,EAAE,kBAAkB,CAAC;QACvC,QAAQ,CAAC,EAAE,YAAY,CAAC;QACxB,eAAe,CAAC,EAAE,eAAe,CAAC;KACnC,CAAC;IACF,OAAO,CAAC,EAAE,iBAAiB,CAAC;CAC7B,GAAG,IAAI,CAAC,aAAa,CAAC,CAgEtB"}
|
|
@@ -1,21 +1,32 @@
|
|
|
1
1
|
import path from 'path';
|
|
2
2
|
import fs from 'fs';
|
|
3
3
|
import { bundleTask } from './bundleTask.js';
|
|
4
|
-
import { addImportMapHash } from '@ms-cloudpack/
|
|
4
|
+
import { addImportMapHash } from '@ms-cloudpack/import-map';
|
|
5
5
|
/**
|
|
6
6
|
* Creates a bundle task tracked in the task runner of the api server. This allows active tasks to be tracked
|
|
7
7
|
* remotely (e.g. in the browser) and allows the user to cancel tasks.
|
|
8
8
|
*/
|
|
9
|
-
export function createBundleTask(
|
|
10
|
-
const {
|
|
11
|
-
const {
|
|
9
|
+
export function createBundleTask(params) {
|
|
10
|
+
const { bundleRequest, context, options } = params;
|
|
11
|
+
const { id, packageName, version, packagePath, isExternal } = bundleRequest;
|
|
12
|
+
const { session, reporter, telemetryClient, packageImportPaths, packages, packageHashes } = context;
|
|
12
13
|
return {
|
|
13
14
|
name: `Bundle ${packageName}@${version}`,
|
|
14
15
|
id,
|
|
15
16
|
dir: `${path.join(packagePath, 'src')}`,
|
|
16
17
|
watch: !isExternal,
|
|
17
18
|
async execute() {
|
|
18
|
-
await bundleTask({
|
|
19
|
+
await bundleTask({
|
|
20
|
+
bundleRequest,
|
|
21
|
+
options,
|
|
22
|
+
context: {
|
|
23
|
+
packages,
|
|
24
|
+
packageHashes,
|
|
25
|
+
config: session.config,
|
|
26
|
+
reporter,
|
|
27
|
+
telemetryClient,
|
|
28
|
+
},
|
|
29
|
+
});
|
|
19
30
|
try {
|
|
20
31
|
const hash = await packageHashes.get({ packagePath, isSourceHashingEnabled: !isExternal });
|
|
21
32
|
addImportMapHash({ packageName, version, importMap: session.getImportMap(), resolveMap: session.resolveMap, hash }, {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"createBundleTask.js","sourceRoot":"","sources":["../../src/utilities/createBundleTask.ts"],"names":[],"mappings":"AAIA,OAAO,IAAI,MAAM,MAAM,CAAC;AACxB,OAAO,EAAE,MAAM,IAAI,CAAC;AACpB,OAAO,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAE7C,OAAO,EAAE,gBAAgB,EAAE,MAAM,
|
|
1
|
+
{"version":3,"file":"createBundleTask.js","sourceRoot":"","sources":["../../src/utilities/createBundleTask.ts"],"names":[],"mappings":"AAIA,OAAO,IAAI,MAAM,MAAM,CAAC;AACxB,OAAO,EAAE,MAAM,IAAI,CAAC;AACpB,OAAO,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAE7C,OAAO,EAAE,gBAAgB,EAAE,MAAM,0BAA0B,CAAC;AAO5D;;;GAGG;AACH,MAAM,UAAU,gBAAgB,CAAC,MAWhC;IACC,MAAM,EAAE,aAAa,EA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aAAa,CAAC,MAAM,CAAC,OAAO,EAAE,EAAE,CAAC;YAEjC,qGAAqG;YACrG,EAAE,CAAC,MAAM,CAAC,aAAa,CAAC,MAAM,CAAC,UAAU,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC,CAAC;YAE7E,aAAa,CAAC,MAAM,GAAG,SAAS,CAAC;QACnC,CAAC;QACD,SAAS,EAAE,GAAG,EAAE;YACd,aAAa,CAAC,MAAM,EAAE,OAAO,EAAE,EAAE,CAAC;QACpC,CAAC;QACD,SAAS,EAAE,GAAG,EAAE,CAAC,aAAa,CAAC,MAAM,EAAE,MAAM;QAC7C,mBAAmB,EAAE,GAAG,EAAE,CAAC,CAAC;YAC1B,EAAE;YACF,IAAI,EAAE,UAAU,WAAW,IAAI,OAAO,EAAE;YACxC,SAAS,EAAE,WAAW,IAAI,EAAE;SAC7B,CAAC;QACF,iBAAiB,EAAE,CAAC,UAAU,EAAE,EAAE,CAChC,CAAC;YACC,EAAE;YACF,MAAM,EAAE,UAAU,EAAE,MAAM,EAAE,MAAM;YAClC,QAAQ,EAAE,UAAU,EAAE,MAAM,EAAE,QAAQ;YACtC,UAAU,EAAE,aAAa,CAAC,MAAM,EAAE,UAAU,IAAI,EAAE;SACnD,CAAuB;KAC3B,CAAC;AACJ,CAAC","sourcesContent":["import type { BundleTaskOptions } from '../types/BundleTaskOptions.js';\nimport type { BundleRequest } from '../types/BundleRequest.js';\nimport type { Task } from '../types/Task.js';\nimport type { TaskEndDescription } from '../types/TaskEndDescription.js';\nimport path from 'path';\nimport fs from 'fs';\nimport { bundleTask } from './bundleTask.js';\nimport type { TaskReporter } from '@ms-cloudpack/task-reporter';\nimport { addImportMapHash } from '@ms-cloudpack/import-map';\nimport type { Session } from '../types/Session.js';\nimport type { TelemetryClient } from '@ms-cloudpack/telemetry';\nimport type { PackageImportPaths } from '@ms-cloudpack/import-map';\nimport type { PackageDefinitionsCache } from '@ms-cloudpack/bundler-types';\nimport type { PackageHashes } from '@ms-cloudpack/package-hashes';\n\n/**\n * Creates a bundle task tracked in the task runner of the api server. This allows active tasks to be tracked\n * remotely (e.g. in the browser) and allows the user to cancel tasks.\n */\nexport function createBundleTask(params: {\n bundleRequest: BundleRequest;\n context: {\n session: Session;\n packages: PackageDefinitionsCache;\n packageHashes: PackageHashes;\n packageImportPaths: PackageImportPaths;\n reporter?: TaskReporter;\n telemetryClient?: TelemetryClient;\n };\n options?: BundleTaskOptions;\n}): Task<BundleRequest> {\n const { bundleRequest, context, options } = params;\n const { id, packageName, version, packagePath, isExternal } = bundleRequest;\n const { session, reporter, telemetryClient, packageImportPaths, packages, packageHashes } = context;\n\n return {\n name: `Bundle ${packageName}@${version}`,\n id,\n dir: `${path.join(packagePath, 'src')}`,\n watch: !isExternal,\n async execute(): Promise<BundleRequest> {\n await bundleTask({\n bundleRequest,\n options,\n context: {\n packages,\n packageHashes,\n config: session.config,\n reporter,\n telemetryClient,\n },\n });\n try {\n const hash = await packageHashes.get({ packagePath, isSourceHashingEnabled: !isExternal });\n addImportMapHash(\n { packageName, version, importMap: session.getImportMap(), resolveMap: session.resolveMap, hash },\n {\n packageImportPaths,\n },\n );\n } catch (e) {\n console.error(`Error adding hash to import map for ${bundleRequest.packagePath}`, e);\n }\n return bundleRequest;\n },\n clear: () => {\n if (!bundleRequest.result) {\n return;\n }\n\n bundleRequest.result.dispose?.();\n\n // eslint-disable-next-line @ms-cloudpack/internal/no-sync-filesystem -- this function can't be async\n fs.rmSync(bundleRequest.result.outputPath, { recursive: true, force: true });\n\n bundleRequest.result = undefined;\n },\n onDispose: () => {\n bundleRequest.result?.dispose?.();\n },\n getErrors: () => bundleRequest.result?.errors,\n getStartDescription: () => ({\n id,\n name: `Bundle ${packageName}@${version}`,\n inputPath: packagePath || '',\n }),\n getEndDescription: (taskResult) =>\n ({\n id,\n errors: taskResult?.result?.errors,\n warnings: taskResult?.result?.warnings,\n outputPath: bundleRequest.result?.outputPath || '',\n }) as TaskEndDescription,\n };\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getBundleInfo.d.ts","sourceRoot":"","sources":["../../src/utilities/getBundleInfo.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,6BAA6B,CAAC;AACpE,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,4BAA4B,CAAC;AAIrE,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,wBAAwB,CAAC;AAEzD;;GAEG;AACH,wBAAsB,aAAa,CAAC,MAAM,EAAE;IAC1C,UAAU,EAAE,MAAM,CAAC;IACnB,WAAW,EAAE,gBAAgB,EAAE,CAAC;IAChC,UAAU,EAAE,kBAAkB,CAAC;IAC/B,UAAU,EAAE,OAAO,CAAC;CACrB,GAAG,OAAO,CAAC,UAAU,CAAC,
|
|
1
|
+
{"version":3,"file":"getBundleInfo.d.ts","sourceRoot":"","sources":["../../src/utilities/getBundleInfo.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,6BAA6B,CAAC;AACpE,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,4BAA4B,CAAC;AAIrE,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,wBAAwB,CAAC;AAEzD;;GAEG;AACH,wBAAsB,aAAa,CAAC,MAAM,EAAE;IAC1C,UAAU,EAAE,MAAM,CAAC;IACnB,WAAW,EAAE,gBAAgB,EAAE,CAAC;IAChC,UAAU,EAAE,kBAAkB,CAAC;IAC/B,UAAU,EAAE,OAAO,CAAC;CACrB,GAAG,OAAO,CAAC,UAAU,CAAC,CAoHtB"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import { getRuntimeEntryPaths } from '@ms-cloudpack/import-map';
|
|
2
|
+
import { normalizeRelativePath } from '@ms-cloudpack/path-string-parsing';
|
|
3
3
|
import path from 'path';
|
|
4
4
|
import { getImportsAndExports } from './getImportsAndExports.js';
|
|
5
5
|
/**
|
|
@@ -18,38 +18,25 @@ export async function getBundleInfo(params) {
|
|
|
18
18
|
const outputFileInfo = {};
|
|
19
19
|
outputFiles.forEach((file) => {
|
|
20
20
|
// Normalize the path to start with ./ (or . for an empty path)
|
|
21
|
-
const safePath =
|
|
21
|
+
const safePath = normalizeRelativePath(file.outputPath);
|
|
22
22
|
// Store safe path to possible entry path and exports.
|
|
23
23
|
outputFileInfo[safePath] = {
|
|
24
24
|
entry: safePath,
|
|
25
25
|
produces: new Set(file.exports),
|
|
26
26
|
};
|
|
27
27
|
});
|
|
28
|
-
// Get both the unbundled and bundled entries from the exports map
|
|
29
|
-
const unbundledExportsMap = flattenExportsMap(exportsMap, {
|
|
30
|
-
conditions: ['browser-esm'],
|
|
31
|
-
requiredConditions: ['browser-esm'],
|
|
32
|
-
});
|
|
33
|
-
const bundledExportsMap = flattenExportsMap(exportsMap);
|
|
34
28
|
const repeatedExports = {};
|
|
35
|
-
|
|
36
|
-
for (const [
|
|
37
|
-
|
|
38
|
-
continue;
|
|
39
|
-
}
|
|
40
|
-
const resolvedFilePath = getResolvedFilePath({ entryPath, isExternal, unbundledExportsMap, bundledFilePath });
|
|
41
|
-
if (resolvedFilePath === undefined) {
|
|
42
|
-
continue; // entry is ignored
|
|
43
|
-
}
|
|
44
|
-
const safePath = safeRelativePath(resolvedFilePath);
|
|
29
|
+
const entryPaths = getRuntimeEntryPaths({ isExternal, exportsMap });
|
|
30
|
+
for (const [importPath, actualEntryPath] of Object.entries(entryPaths)) {
|
|
31
|
+
const safePath = normalizeRelativePath(actualEntryPath);
|
|
45
32
|
if (outputFileInfo[safePath]) {
|
|
46
33
|
if (repeatedExports[safePath]) {
|
|
47
|
-
repeatedExports[safePath].push(
|
|
34
|
+
repeatedExports[safePath].push(importPath);
|
|
48
35
|
}
|
|
49
36
|
else {
|
|
50
37
|
// Change best guess entry path to exports map entry.
|
|
51
|
-
outputFileInfo[safePath].entry =
|
|
52
|
-
repeatedExports[safePath] = [
|
|
38
|
+
outputFileInfo[safePath].entry = importPath;
|
|
39
|
+
repeatedExports[safePath] = [importPath];
|
|
53
40
|
}
|
|
54
41
|
}
|
|
55
42
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getBundleInfo.js","sourceRoot":"","sources":["../../src/utilities/getBundleInfo.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,iBAAiB,EAAE,mBAAmB,EAAE,MAAM,iCAAiC,CAAC;AACzF,OAAO,EAAE,gBAAgB,EAAE,MAAM,mCAAmC,CAAC;AACrE,OAAO,IAAI,MAAM,MAAM,CAAC;AAExB,OAAO,EAAE,oBAAoB,EAAE,MAAM,2BAA2B,CAAC;AACjE;;GAEG;AACH,MAAM,CAAC,KAAK,UAAU,aAAa,CAAC,MAKnC;IACC,MAAM,EAAE,UAAU,EAAE,WAAW,EAAE,UAAU,EAAE,UAAU,EAAE,GAAG,MAAM,CAAC;IACnE,MAAM,UAAU,GAAe;QAC7B,KAAK,EAAE,EAAE;KACV,CAAC;IAEF,8DAA8D;IAC9D,IAAI,CAAC,WAAW,CAAC,MAAM,EAAE,CAAC;QACxB,OAAO,UAAU,CAAC;IACpB,CAAC;IAED,mGAAmG;IACnG,MAAM,cAAc,GAA6D,EAAE,CAAC;IACpF,WAAW,CAAC,OAAO,CAAC,CAAC,IAAI,EAAE,EAAE;QAC3B,+DAA+D;QAC/D,MAAM,QAAQ,GAAG,gBAAgB,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC;QACnD,sDAAsD;QACtD,cAAc,CAAC,QAAQ,CAAC,GAAG;YACzB,KAAK,EAAE,QAAQ;YACf,QAAQ,EAAE,IAAI,GAAG,CAAS,IAAI,CAAC,OAAO,CAAC;SACxC,CAAC;IACJ,CAAC,CAAC,CAAC;IAEH,kEAAkE;IAClE,MAAM,mBAAmB,GAAG,iBAAiB,CAAC,UAAU,EAAE;QACxD,UAAU,EAAE,CAAC,aAAa,CAAC;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CAAC,CAAC,GAAG,KAAK,EAAE,GAAG,UAAU,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC,QAAQ,CAAC,UAAU,CAAC,CAAC,KAAK,CAAC,CAAC,CAC3E,CAAC;gBACJ,CAAC;YACH,CAAC;QACH,CAAC;QACD,IAAI,eAAe,CAAC,QAAQ,CAAC,EAAE,MAAM,GAAG,CAAC,EAAE,CAAC;YAC1C,sCAAsC;YACtC,KAAK,MAAM,aAAa,IAAI,eAAe,CAAC,QAAQ,CAAC,EAAE,CAAC;gBACtD,IAAI,aAAa,KAAK,KAAK,EAAE,CAAC;oBAC5B,UAAU,CAAC,KAAK,CAAC,aAAa,CAAC,GAAG,UAAU,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC;gBAC5D,CAAC;YACH,CAAC;QACH,CAAC;IACH,CAAC;IAED,OAAO,UAAU,CAAC;AACpB,CAAC","sourcesContent":["import type { BundleOutputFile } from '@ms-cloudpack/bundler-types';\nimport type { PackageJsonExports } from '@ms-cloudpack/config-types';\nimport { flattenExportsMap, getResolvedFilePath } from '@ms-cloudpack/package-utilities';\nimport { safeRelativePath } from '@ms-cloudpack/path-string-parsing';\nimport path from 'path';\nimport type { BundleInfo } from '../types/BundleInfo.js';\nimport { getImportsAndExports } from './getImportsAndExports.js';\n/**\n * Returns a mapping from entry file path to list of paths that are produced and consumed in the searched files.\n */\nexport async function getBundleInfo(params: {\n outputPath: string;\n outputFiles: BundleOutputFile[];\n exportsMap: PackageJsonExports;\n isExternal: boolean;\n}): Promise<BundleInfo> {\n const { outputPath, outputFiles, exportsMap, isExternal } = params;\n const bundleInfo: BundleInfo = {\n entry: {},\n };\n\n // If there are no output files, return the empty bundle info.\n if (!outputFiles.length) {\n return bundleInfo;\n }\n\n /** Mapping from output file (safe/normalized relative path) to possible entry path and exports. */\n const outputFileInfo: Record<string, { entry: string; produces: Set<string> }> = {};\n outputFiles.forEach((file) => {\n // Normalize the path to start with ./ (or . for an empty path)\n const safePath = safeRelativePath(file.outputPath);\n // Store safe path to possible entry path and exports.\n outputFileInfo[safePath] = {\n entry: safePath,\n produces: new Set<string>(file.exports),\n };\n });\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 const repeatedExports: Record<string, string[]> = {};\n\n // Verify the bundled entries, but prefer unbundled if the entry exists.\n for (const [entryPath, bundledFilePath] of Object.entries(bundledExportsMap)) {\n if (typeof entryPath !== 'string' || typeof bundledFilePath !== 'string') {\n continue;\n }\n\n const resolvedFilePath = getResolvedFilePath({ entryPath, isExternal, unbundledExportsMap, bundledFilePath });\n if (resolvedFilePath === undefined) {\n continue; // entry is ignored\n }\n\n const safePath = safeRelativePath(resolvedFilePath);\n\n if (outputFileInfo[safePath]) {\n if (repeatedExports[safePath]) {\n repeatedExports[safePath].push(entryPath);\n } else {\n // Change best guess entry path to exports map entry.\n outputFileInfo[safePath].entry = entryPath;\n repeatedExports[safePath] = [entryPath];\n }\n }\n }\n\n const localPathToSafe: Record<string, string> = {};\n Object.keys(outputFileInfo).forEach((safePath) => {\n localPathToSafe[path.resolve(outputPath, safePath)] = safePath;\n });\n\n const filePaths = Object.keys(localPathToSafe);\n const visitedPaths = new Set(filePaths);\n const pathsToParse = [...filePaths];\n\n while (pathsToParse.length) {\n const filePath = pathsToParse.shift();\n // Ignore any non-JS/TS files such as SVGs and sourcemaps\n if (!filePath || path.extname(filePath) !== '.js') {\n continue;\n }\n\n const safePath = localPathToSafe[filePath];\n if (safePath === undefined) {\n throw new Error(`Found file that was not expected to be processed: ${filePath}`);\n }\n\n const parseResult = await getImportsAndExports(filePath);\n if (!parseResult) {\n continue;\n }\n const { exportNames, imports } = parseResult;\n\n const { entry, produces } = outputFileInfo[safePath] || {\n entry: safePath,\n produces: new Set<string>(),\n };\n exportNames.forEach((name) => produces.add(name));\n\n bundleInfo.entry[entry] ??= {\n bundlePath: safePath,\n produces: Array.from(produces),\n consumes: [],\n };\n\n for (const { packageName, importPath, names } of imports) {\n if (packageName?.startsWith('.')) {\n const localPath = path.resolve(path.dirname(filePath), packageName, importPath || '');\n\n if (!visitedPaths.has(localPath)) {\n visitedPaths.add(localPath);\n pathsToParse.push(localPath);\n localPathToSafe[localPath] = importPath;\n }\n } else if (packageName && !packageName.startsWith('node:')) {\n // Find if the import is already in the consumes list.\n const entryIndex = bundleInfo.entry[entry].consumes.findIndex(\n (c) => c.packageName === packageName && c.importPath === importPath,\n );\n if (entryIndex < 0) {\n // If not, add it.\n bundleInfo.entry[entry].consumes.push({ packageName, importPath: importPath || '.', names: [...names] });\n } else {\n // If so, add the names to the existing entry.\n // This is necessary because the same import may be used in multiple places.\n bundleInfo.entry[entry].consumes[entryIndex].names = Array.from(\n new Set([...names, ...bundleInfo.entry[entry].consumes[entryIndex].names]),\n );\n }\n }\n }\n if (repeatedExports[safePath]?.length > 1) {\n // Multiple entries for the same path.\n for (const repeatedEntry of repeatedExports[safePath]) {\n if (repeatedEntry !== entry) {\n bundleInfo.entry[repeatedEntry] = bundleInfo.entry[entry];\n }\n }\n }\n }\n\n return bundleInfo;\n}\n"]}
|
|
1
|
+
{"version":3,"file":"getBundleInfo.js","sourceRoot":"","sources":["../../src/utilities/getBundleInfo.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,oBAAoB,EAAE,MAAM,0BAA0B,CAAC;AAChE,OAAO,EAAE,qBAAqB,EAAE,MAAM,mCAAmC,CAAC;AAC1E,OAAO,IAAI,MAAM,MAAM,CAAC;AAExB,OAAO,EAAE,oBAAoB,EAAE,MAAM,2BAA2B,CAAC;AACjE;;GAEG;AACH,MAAM,CAAC,KAAK,UAAU,aAAa,CAAC,MAKnC;IACC,MAAM,EAAE,UAAU,EAAE,WAAW,EAAE,UAAU,EAAE,UAAU,EAAE,GAAG,MAAM,CAAC;IACnE,MAAM,UAAU,GAAe;QAC7B,KAAK,EAAE,EAAE;KACV,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U,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC,QAAQ,CAAC,UAAU,CAAC,CAAC,KAAK,GAAG,KAAK,CAAC,IAAI,CAC7D,IAAI,GAAG,CAAC,CAAC,GAAG,KAAK,EAAE,GAAG,UAAU,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC,QAAQ,CAAC,UAAU,CAAC,CAAC,KAAK,CAAC,CAAC,CAC3E,CAAC;gBACJ,CAAC;YACH,CAAC;QACH,CAAC;QACD,IAAI,eAAe,CAAC,QAAQ,CAAC,EAAE,MAAM,GAAG,CAAC,EAAE,CAAC;YAC1C,sCAAsC;YACtC,KAAK,MAAM,aAAa,IAAI,eAAe,CAAC,QAAQ,CAAC,EAAE,CAAC;gBACtD,IAAI,aAAa,KAAK,KAAK,EAAE,CAAC;oBAC5B,UAAU,CAAC,KAAK,CAAC,aAAa,CAAC,GAAG,UAAU,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC;gBAC5D,CAAC;YACH,CAAC;QACH,CAAC;IACH,CAAC;IAED,OAAO,UAAU,CAAC;AACpB,CAAC","sourcesContent":["import type { BundleOutputFile } from '@ms-cloudpack/bundler-types';\nimport type { PackageJsonExports } from '@ms-cloudpack/config-types';\nimport { getRuntimeEntryPaths } from '@ms-cloudpack/import-map';\nimport { normalizeRelativePath } from '@ms-cloudpack/path-string-parsing';\nimport path from 'path';\nimport type { BundleInfo } from '../types/BundleInfo.js';\nimport { getImportsAndExports } from './getImportsAndExports.js';\n/**\n * Returns a mapping from entry file path to list of paths that are produced and consumed in the searched files.\n */\nexport async function getBundleInfo(params: {\n outputPath: string;\n outputFiles: BundleOutputFile[];\n exportsMap: PackageJsonExports;\n isExternal: boolean;\n}): Promise<BundleInfo> {\n const { outputPath, outputFiles, exportsMap, isExternal } = params;\n const bundleInfo: BundleInfo = {\n entry: {},\n };\n\n // If there are no output files, return the empty bundle info.\n if (!outputFiles.length) {\n return bundleInfo;\n }\n\n /** Mapping from output file (safe/normalized relative path) to possible entry path and exports. */\n const outputFileInfo: Record<string, { entry: string; produces: Set<string> }> = {};\n outputFiles.forEach((file) => {\n // Normalize the path to start with ./ (or . for an empty path)\n const safePath = normalizeRelativePath(file.outputPath);\n // Store safe path to possible entry path and exports.\n outputFileInfo[safePath] = {\n entry: safePath,\n produces: new Set<string>(file.exports),\n };\n });\n\n const repeatedExports: Record<string, string[]> = {};\n const entryPaths = getRuntimeEntryPaths({ isExternal, exportsMap });\n\n for (const [importPath, actualEntryPath] of Object.entries(entryPaths)) {\n const safePath = normalizeRelativePath(actualEntryPath);\n\n if (outputFileInfo[safePath]) {\n if (repeatedExports[safePath]) {\n repeatedExports[safePath].push(importPath);\n } else {\n // Change best guess entry path to exports map entry.\n outputFileInfo[safePath].entry = importPath;\n repeatedExports[safePath] = [importPath];\n }\n }\n }\n\n const localPathToSafe: Record<string, string> = {};\n Object.keys(outputFileInfo).forEach((safePath) => {\n localPathToSafe[path.resolve(outputPath, safePath)] = safePath;\n });\n\n const filePaths = Object.keys(localPathToSafe);\n const visitedPaths = new Set(filePaths);\n const pathsToParse = [...filePaths];\n\n while (pathsToParse.length) {\n const filePath = pathsToParse.shift();\n // Ignore any non-JS/TS files such as SVGs and sourcemaps\n if (!filePath || path.extname(filePath) !== '.js') {\n continue;\n }\n\n const safePath = localPathToSafe[filePath];\n if (safePath === undefined) {\n throw new Error(`Found file that was not expected to be processed: ${filePath}`);\n }\n\n const parseResult = await getImportsAndExports(filePath);\n if (!parseResult) {\n continue;\n }\n const { exportNames, imports } = parseResult;\n\n const { entry, produces } = outputFileInfo[safePath] || {\n entry: safePath,\n produces: new Set<string>(),\n };\n exportNames.forEach((name) => produces.add(name));\n\n bundleInfo.entry[entry] ??= {\n bundlePath: safePath,\n produces: Array.from(produces),\n consumes: [],\n };\n\n for (const { packageName, importPath, names } of imports) {\n if (packageName?.startsWith('.')) {\n const localPath = path.resolve(path.dirname(filePath), packageName, importPath || '');\n\n if (!visitedPaths.has(localPath)) {\n visitedPaths.add(localPath);\n pathsToParse.push(localPath);\n localPathToSafe[localPath] = importPath;\n }\n } else if (packageName && !packageName.startsWith('node:')) {\n // Find if the import is already in the consumes list.\n const entryIndex = bundleInfo.entry[entry].consumes.findIndex(\n (c) => c.packageName === packageName && c.importPath === importPath,\n );\n if (entryIndex < 0) {\n // If not, add it.\n bundleInfo.entry[entry].consumes.push({ packageName, importPath: importPath || '.', names: [...names] });\n } else {\n // If so, add the names to the existing entry.\n // This is necessary because the same import may be used in multiple places.\n bundleInfo.entry[entry].consumes[entryIndex].names = Array.from(\n new Set([...names, ...bundleInfo.entry[entry].consumes[entryIndex].names]),\n );\n }\n }\n }\n if (repeatedExports[safePath]?.length > 1) {\n // Multiple entries for the same path.\n for (const repeatedEntry of repeatedExports[safePath]) {\n if (repeatedEntry !== entry) {\n bundleInfo.entry[repeatedEntry] = bundleInfo.entry[entry];\n }\n }\n }\n }\n\n return bundleInfo;\n}\n"]}
|
|
@@ -6,6 +6,7 @@
|
|
|
6
6
|
* - Package name (and optionally `@version`)
|
|
7
7
|
* - Optional refresh version `v#.#`
|
|
8
8
|
* - Optional type `bundled` or `unbundled` (defaults to unbundled)
|
|
9
|
+
* - Optional property `missing` (defaults to false)
|
|
9
10
|
* - Optional file path with leading slash (empty if no path)
|
|
10
11
|
*
|
|
11
12
|
* @param requestPath Pathname (server-relative URL) of the requested file.
|
|
@@ -23,5 +24,7 @@ export declare function parseRequestInfo(requestPath: string): {
|
|
|
23
24
|
bundled: boolean;
|
|
24
25
|
/** Optional file path (default: empty string) */
|
|
25
26
|
filePath: string;
|
|
27
|
+
/** Whether the file is missing (default: false) */
|
|
28
|
+
missing: boolean;
|
|
26
29
|
};
|
|
27
30
|
//# sourceMappingURL=parseRequestInfo.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"parseRequestInfo.d.ts","sourceRoot":"","sources":["../../src/utilities/parseRequestInfo.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"parseRequestInfo.d.ts","sourceRoot":"","sources":["../../src/utilities/parseRequestInfo.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,gBAAgB,CAAC,WAAW,EAAE,MAAM,GAAG;IACrD,qDAAqD;IACrD,WAAW,EAAE,MAAM,CAAC;IACpB,uDAAuD;IACvD,OAAO,EAAE,MAAM,CAAC;IAChB,4CAA4C;IAC5C,IAAI,EAAE,MAAM,CAAC;IACb,gEAAgE;IAChE,OAAO,EAAE,OAAO,CAAC;IACjB,iDAAiD;IACjD,QAAQ,EAAE,MAAM,CAAC;IACjB,mDAAmD;IACnD,OAAO,EAAE,OAAO,CAAC;CAClB,CAoBA"}
|
|
@@ -6,6 +6,7 @@
|
|
|
6
6
|
* - Package name (and optionally `@version`)
|
|
7
7
|
* - Optional refresh version `v#.#`
|
|
8
8
|
* - Optional type `bundled` or `unbundled` (defaults to unbundled)
|
|
9
|
+
* - Optional property `missing` (defaults to false)
|
|
9
10
|
* - Optional file path with leading slash (empty if no path)
|
|
10
11
|
*
|
|
11
12
|
* @param requestPath Pathname (server-relative URL) of the requested file.
|
|
@@ -19,14 +20,15 @@ export function parseRequestInfo(requestPath) {
|
|
|
19
20
|
// - For character classes containing - , putting the - at the beginning
|
|
20
21
|
// - Anchoring to the beginning of the string with ^
|
|
21
22
|
const matches = requestPath.match(
|
|
22
|
-
// 1 package name 2 hash 3 version refresh 4 bundled
|
|
23
|
-
/^\/?((?:@[-\w.]+\/)?[-\w.]+)(?:@([-\w.]+))?(?:\/h-([-0-9a-z.]+))?(?:\/v[\d.]+)?(?:\/(bundled|unbundled))?(\/[-@\w.+/]+)?(?:\?|$)/) || [];
|
|
23
|
+
// 1 package name 2 hash 3 version refresh 4 bundled or missing 4 file path end or query
|
|
24
|
+
/^\/?((?:@[-\w.]+\/)?[-\w.]+)(?:@([-\w.]+))?(?:\/h-([-0-9a-z.]+))?(?:\/v[\d.]+)?(?:\/(bundled|unbundled|missing))?(\/[-@\w.+/]+)?(?:\?|$)/) || [];
|
|
24
25
|
return {
|
|
25
26
|
packageName: matches[1] || '',
|
|
26
27
|
version: matches[2] || '',
|
|
27
28
|
hash: matches[3] || '',
|
|
28
29
|
bundled: matches[4] === 'bundled',
|
|
29
30
|
filePath: matches[5] || '',
|
|
31
|
+
missing: matches[4] === 'missing',
|
|
30
32
|
};
|
|
31
33
|
}
|
|
32
34
|
//# sourceMappingURL=parseRequestInfo.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"parseRequestInfo.js","sourceRoot":"","sources":["../../src/utilities/parseRequestInfo.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"parseRequestInfo.js","sourceRoot":"","sources":["../../src/utilities/parseRequestInfo.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AACH,MAAM,UAAU,gBAAgB,CAAC,WAAmB;IAclD,gFAAgF;IAChF,4DAA4D;IAC5D,kEAAkE;IAClE,wEAAwE;IACxE,oDAAoD;IACpD,MAAM,OAAO,GACX,WAAW,CAAC,KAAK;IACf,wIAAwI;IACxI,0IAA0I,CAC3I,IAAI,EAAE,CAAC;IAEV,OAAO;QACL,WAAW,EAAE,OAAO,CAAC,CAAC,CAAC,IAAI,EAAE;QAC7B,OAAO,EAAE,OAAO,CAAC,CAAC,CAAC,IAAI,EAAE;QACzB,IAAI,EAAE,OAAO,CAAC,CAAC,CAAC,IAAI,EAAE;QACtB,OAAO,EAAE,OAAO,CAAC,CAAC,CAAC,KAAK,SAAS;QACjC,QAAQ,EAAE,OAAO,CAAC,CAAC,CAAC,IAAI,EAAE;QAC1B,OAAO,EAAE,OAAO,CAAC,CAAC,CAAC,KAAK,SAAS;KAClC,CAAC;AACJ,CAAC","sourcesContent":["/**\n * Parse a request for package file from the bundle server, such as\n * `/@scope/package@version/v3.2/bundled/path/to/file.js`\n *\n * Segments:\n * - Package name (and optionally `@version`)\n * - Optional refresh version `v#.#`\n * - Optional type `bundled` or `unbundled` (defaults to unbundled)\n * - Optional property `missing` (defaults to false)\n * - Optional file path with leading slash (empty if no path)\n *\n * @param requestPath Pathname (server-relative URL) of the requested file.\n * @returns Info about the requested file. If `requestPath` doesn't follow the expected format,\n * the object will contain empty strings.\n */\nexport function parseRequestInfo(requestPath: string): {\n /** Package name (empty string if invalid request) */\n packageName: string;\n /** Optional package version (default: empty string) */\n version: string;\n /** Optional hash (default: empty string) */\n hash: string;\n /** Whether the bundled version is requested (default: false) */\n bundled: boolean;\n /** Optional file path (default: empty string) */\n filePath: string;\n /** Whether the file is missing (default: false) */\n missing: boolean;\n} {\n // This is a hot path, and the following things appear to make the regex faster:\n // - /(?:Non-capturing groups)/ where capturing isn't needed\n // - /(Indexed capturing groups)/ instead of /(?<namedGroups>...)/\n // - For character classes containing - , putting the - at the beginning\n // - Anchoring to the beginning of the string with ^\n const matches =\n requestPath.match(\n // 1 package name 2 hash 3 version refresh 4 bundled or missing 4 file path end or query\n /^\\/?((?:@[-\\w.]+\\/)?[-\\w.]+)(?:@([-\\w.]+))?(?:\\/h-([-0-9a-z.]+))?(?:\\/v[\\d.]+)?(?:\\/(bundled|unbundled|missing))?(\\/[-@\\w.+/]+)?(?:\\?|$)/,\n ) || [];\n\n return {\n packageName: matches[1] || '',\n version: matches[2] || '',\n hash: matches[3] || '',\n bundled: matches[4] === 'bundled',\n filePath: matches[5] || '',\n missing: matches[4] === 'missing',\n };\n}\n"]}
|