@ms-cloudpack/api-server 0.28.3 → 0.29.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.
Files changed (34) hide show
  1. package/lib/apis/ensurePackageBundled.d.ts +1 -1
  2. package/lib/apis/ensurePackageBundled.d.ts.map +1 -1
  3. package/lib/apis/ensurePackageBundled.js +31 -15
  4. package/lib/apis/ensurePackageBundled.js.map +1 -1
  5. package/lib/index.d.ts +1 -1
  6. package/lib/index.d.ts.map +1 -1
  7. package/lib/index.js.map +1 -1
  8. package/lib/types/BundleInfo.d.ts +25 -0
  9. package/lib/types/BundleInfo.d.ts.map +1 -0
  10. package/lib/types/BundleInfo.js +2 -0
  11. package/lib/types/BundleInfo.js.map +1 -0
  12. package/lib/types/BundleRequest.d.ts +4 -8
  13. package/lib/types/BundleRequest.d.ts.map +1 -1
  14. package/lib/types/BundleRequest.js.map +1 -1
  15. package/lib/utilities/bundleTask.d.ts.map +1 -1
  16. package/lib/utilities/bundleTask.js +22 -18
  17. package/lib/utilities/bundleTask.js.map +1 -1
  18. package/lib/utilities/createBundleRequestForPackage.d.ts +1 -1
  19. package/lib/utilities/createBundleRequestForPackage.d.ts.map +1 -1
  20. package/lib/utilities/createBundleRequestForPackage.js +1 -1
  21. package/lib/utilities/createBundleRequestForPackage.js.map +1 -1
  22. package/lib/utilities/getBundleInfo.d.ts +14 -0
  23. package/lib/utilities/getBundleInfo.d.ts.map +1 -0
  24. package/lib/utilities/getBundleInfo.js +212 -0
  25. package/lib/utilities/getBundleInfo.js.map +1 -0
  26. package/package.json +10 -10
  27. package/lib/types/DetectedImports.d.ts +0 -6
  28. package/lib/types/DetectedImports.d.ts.map +0 -1
  29. package/lib/types/DetectedImports.js +0 -2
  30. package/lib/types/DetectedImports.js.map +0 -1
  31. package/lib/utilities/findImports.d.ts +0 -7
  32. package/lib/utilities/findImports.d.ts.map +0 -1
  33. package/lib/utilities/findImports.js +0 -75
  34. package/lib/utilities/findImports.js.map +0 -1
@@ -3,7 +3,7 @@ import type { ApiParams } from '../types/ApiParams.js';
3
3
  /**
4
4
  * Input for `ensurePackageBundled`.
5
5
  */
6
- export interface EnsurePackageBundledInput extends Pick<BundleRequest, 'outputPath' | 'version' | 'bundlerType' | 'disableSourceMaps' | 'shouldFindImports'> {
6
+ export interface EnsurePackageBundledInput extends Pick<BundleRequest, 'outputPath' | 'version' | 'bundlerType' | 'disableSourceMaps' | 'shouldGetBundleInfo'> {
7
7
  /** Package name */
8
8
  name: string;
9
9
  /** Whether to also ensure dependencies are bundled */
@@ -1 +1 @@
1
- {"version":3,"file":"ensurePackageBundled.d.ts","sourceRoot":"","sources":["../../src/apis/ensurePackageBundled.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,2BAA2B,CAAC;AAI/D,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,uBAAuB,CAAC;AAKvD;;GAEG;AACH,MAAM,WAAW,yBACf,SAAQ,IAAI,CAAC,aAAa,EAAE,YAAY,GAAG,SAAS,GAAG,aAAa,GAAG,mBAAmB,GAAG,mBAAmB,CAAC;IACjH,mBAAmB;IACnB,IAAI,EAAE,MAAM,CAAC;IACb,sDAAsD;IACtD,mBAAmB,CAAC,EAAE,OAAO,CAAC;IAC9B,wCAAwC;IACxC,WAAW,CAAC,EAAE,OAAO,CAAC;IACtB,4DAA4D;IAC5D,WAAW,CAAC,EAAE,OAAO,CAAC;IACtB,mCAAmC;IACnC,WAAW,CAAC,EAAE,OAAO,CAAC;IACtB,kCAAkC;IAClC,YAAY,CAAC,EAAE,OAAO,CAAC;IACvB,wFAAwF;IACxF,aAAa,CAAC,EAAE,OAAO,CAAC;CACzB;AAiBD;;GAEG;AACH,MAAM,WAAW,0BAA2B,SAAQ,IAAI,CAAC,WAAW,CAAC,aAAa,CAAC,QAAQ,CAAC,CAAC,EAAE,SAAS,GAAG,SAAS,CAAC;IACnH,mBAAmB;IACnB,IAAI,EAAE,MAAM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;IACtB,mCAAmC;IACnC,WAAW,CAAC,EAAE,OAAO,CAAC;IACtB,kCAAkC;IAClC,YAAY,CAAC,EAAE,OAAO,CAAC;IACvB,wFAAwF;IACxF,aAAa,CAAC,EAAE,OAAO,CAAC;CACzB;AAiBD;;GAEG;AACH,MAAM,WAAW,0BAA2B,SAAQ,IAAI,CAAC,WAAW,CAAC,aAAa,CAAC,QAAQ,CAAC,CAAC,EAAE,SAAS,GAAG,SAAS,CAAC;IACnH,mBAAmB;IACnB,IAAI,EAAE,MAAM,CAAC;IACb,sBAAsB;IACtB,OAAO,EAAE,MAAM,CAAC;IAChB,+CAA+C;IAC/C,YAAY,CAAC,EAAE,MAAM,EAAE,CAAC;IACxB,iEAAiE;IACjE,UAAU,EAAE,OAAO,CAAC;CACrB;AA4CD;;GAEG;AACH,MAAM,WAAW,0BAA0B;IACzC,sCAAsC;IACtC,MAAM,EAAE,0BAA0B,CAAC;IACnC,uCAAuC;IACvC,YAAY,EAAE,OAAO,CAAC,0BAA0B,EAAE,CAAC,CAAC;CACrD;AAOD;;;GAGG;AACH,wBAAsB,oBAAoB,CACxC,MAAM,EAAE,SAAS,CACf,yBAAyB,EACvB,KAAK,GACL,YAAY,GACZ,SAAS,GACT,SAAS,GACT,UAAU,GACV,UAAU,GACV,iBAAiB,GACjB,oBAAoB,GACpB,eAAe,CAClB,GACA,OAAO,CAAC,0BAA0B,CAAC,CAmCrC;yBAhDqB,oBAAoB;;;;;;;;;;;;;;;;AA4K1C,MAAM,MAAM,2BAA2B,GAAG,UAAU,CAAC,OAAO,oBAAoB,CAAC,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC"}
@@ -14,7 +14,7 @@ const ZodEnsurePackageBundledInput = matchingZodObject({
14
14
  bundlerType: z.string().optional(),
15
15
  disableSourceMaps: z.boolean().optional(),
16
16
  enqueueDependencies: z.boolean().optional(),
17
- shouldFindImports: z.boolean().optional(),
17
+ shouldGetBundleInfo: z.boolean().optional(),
18
18
  shouldRerun: z.boolean().optional(),
19
19
  shouldWatch: z.boolean().optional(),
20
20
  shouldForce: z.boolean().optional(),
@@ -42,7 +42,19 @@ const ZodEnsurePackageBundledResult = matchingZodObject({
42
42
  rawInput: z.record(z.unknown()).optional(),
43
43
  rawOutput: z.record(z.unknown()).optional(),
44
44
  isExternal: z.boolean(),
45
- imports: z.record(z.array(z.string())).optional(),
45
+ info: z
46
+ .object({
47
+ entry: z.record(z.object({
48
+ bundlePath: z.string(),
49
+ produces: z.array(z.string()),
50
+ consumes: z.array(z.object({
51
+ packageName: z.string(),
52
+ importPath: z.string(),
53
+ names: z.array(z.string()),
54
+ })),
55
+ })),
56
+ })
57
+ .optional(),
46
58
  });
47
59
  const ZodEnsurePackageBundledOutput = matchingZodObject({
48
60
  result: ZodEnsurePackageBundledResult,
@@ -87,7 +99,7 @@ export async function ensurePackageBundled(params) {
87
99
  }
88
100
  async function ensurePackageBundledInternal(params) {
89
101
  const { input, ctx, visited } = params;
90
- const { name, version, shouldWatch, bundlerType, disableSourceMaps, outputPath, shouldFindImports, shouldRerun, shouldForce, disableCache, isIncremental, } = input;
102
+ const { name, version, shouldWatch, bundlerType, disableSourceMaps, outputPath, shouldGetBundleInfo, shouldRerun, shouldForce, disableCache, isIncremental, } = input;
91
103
  const { taskRunner, session, watcher, packages, packageHashes } = ctx;
92
104
  const { resolveMap, config } = session;
93
105
  const { features } = config;
@@ -105,7 +117,7 @@ async function ensurePackageBundledInternal(params) {
105
117
  bundlerType,
106
118
  disableSourceMaps,
107
119
  outputPath,
108
- shouldFindImports: shouldFindImports || enqueueDependencies,
120
+ shouldGetBundleInfo: shouldGetBundleInfo || enqueueDependencies,
109
121
  disableCache,
110
122
  isIncremental,
111
123
  }, { config, packages, packageHashes });
@@ -140,18 +152,22 @@ async function ensurePackageBundledInternal(params) {
140
152
  });
141
153
  }
142
154
  // If enabled, enqueue dependencies.
143
- if (enqueueDependencies && result?.imports) {
144
- for (const dependencyName of Object.keys(result.imports)) {
145
- // If we've already visited this package, skip it.
146
- if (visited.has(`${dependencyName}@${packageEntry.dependencies[dependencyName]}`)) {
147
- continue;
155
+ if (enqueueDependencies && result?.info?.entry) {
156
+ for (const entryInfo of Object.values(result.info.entry)) {
157
+ // iterate through all package names of result.info.entry.consumes
158
+ for (const consume of entryInfo.consumes) {
159
+ const dependencyName = consume.packageName;
160
+ // If we've already visited this package, skip it.
161
+ if (visited.has(`${dependencyName}@${packageEntry.dependencies[dependencyName]}`)) {
162
+ continue;
163
+ }
164
+ dependencyInputs.push({
165
+ name: dependencyName,
166
+ version: packageEntry.dependencies[dependencyName],
167
+ shouldWatch,
168
+ enqueueDependencies,
169
+ });
148
170
  }
149
- dependencyInputs.push({
150
- name: dependencyName,
151
- version: packageEntry.dependencies[dependencyName],
152
- shouldWatch,
153
- enqueueDependencies,
154
- });
155
171
  }
156
172
  }
157
173
  return {
@@ -1 +1 @@
1
- {"version":3,"file":"ensurePackageBundled.js","sourceRoot":"","sources":["../../src/apis/ensurePackageBundled.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,EAAE,mBAAmB,EAAE,MAAM,iCAAiC,CAAC;AACtE,OAAO,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC;AACpD,OAAO,EAAE,YAAY,EAAE,MAAM,8BAA8B,CAAC;AAE5D,OAAO,EAAE,gBAAgB,EAAE,MAAM,kCAAkC,CAAC;AACpE,OAAO,EAAE,6BAA6B,EAAE,MAAM,+CAA+C,CAAC;AAC9F,OAAO,EAAE,cAAc,EAAE,MAAM,yBAAyB,CAAC;AAEzD,OAAO,EAAE,iBAAiB,EAAE,MAAM,mCAAmC,CAAC;AACtE,OAAO,EAAE,kBAAkB,EAAE,MAAM,sBAAsB,CAAC;AAwB1D,MAAM,4BAA4B,GAAG,iBAAiB,CAA4B;IAChF,IAAI,EAAE,CAAC,CAAC,MAAM,EAAE;IAChB,OAAO,EAAE,CAAC,CAAC,MAAM,EAAE;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AgB;KACjB,CAAC;AACJ,CAAC;AAED,2CAA2C;AAC3C,oBAAoB,CAAC,SAAS,GAAG,eAAe;KAC7C,KAAK,CAAC,4BAA4B,CAAC;KACnC,MAAM,CAAC,6BAA6B,CAAC;KACrC,QAAQ,CAAC,oBAAoB,CAAC,CAAC","sourcesContent":["import { z } from 'zod';\nimport { findResolveMapEntry } from '@ms-cloudpack/package-utilities';\nimport { publicProcedure } from '../trpc/common.js';\nimport { notifyReload } from '../utilities/notifyReload.js';\nimport type { BundleRequest } from '../types/BundleRequest.js';\nimport { createBundleTask } from '../utilities/createBundleTask.js';\nimport { createBundleRequestForPackage } from '../utilities/createBundleRequestForPackage.js';\nimport { ZodTaskMessage } from '../types/TaskMessage.js';\nimport type { ApiParams } from '../types/ApiParams.js';\nimport { matchingZodObject } from '../utilities/matchingZodObject.js';\nimport { getPackageSettings } from '@ms-cloudpack/config';\nimport type { WatchOptions } from '@ms-cloudpack/file-watcher';\n\n/**\n * Input for `ensurePackageBundled`.\n */\nexport interface EnsurePackageBundledInput\n extends Pick<BundleRequest, 'outputPath' | 'version' | 'bundlerType' | 'disableSourceMaps' | 'shouldFindImports'> {\n /** Package name */\n name: string;\n /** Whether to also ensure dependencies are bundled */\n enqueueDependencies?: boolean;\n /** Whether to re-run the bundle task */\n shouldRerun?: boolean;\n /** Whether to watch for changes (internal packages only) */\n shouldWatch?: boolean;\n /** Whether to force re-bundling */\n shouldForce?: boolean;\n /** Whether to disable caching. */\n disableCache?: boolean;\n /** Whether to support incremental rebuilds. Defaults to true for internal libraries. */\n isIncremental?: boolean;\n}\n\nconst ZodEnsurePackageBundledInput = matchingZodObject<EnsurePackageBundledInput>({\n name: z.string(),\n version: z.string(),\n outputPath: z.string().optional(),\n bundlerType: z.string().optional(),\n disableSourceMaps: z.boolean().optional(),\n enqueueDependencies: z.boolean().optional(),\n shouldFindImports: z.boolean().optional(),\n shouldRerun: z.boolean().optional(),\n shouldWatch: z.boolean().optional(),\n shouldForce: z.boolean().optional(),\n disableCache: z.boolean().optional(),\n isIncremental: z.boolean().optional(),\n});\n\n/**\n * Result of ensuring a single package is bundled.\n */\nexport interface EnsurePackageBundledResult extends Omit<NonNullable<BundleRequest['result']>, 'rebuild' | 'dispose'> {\n /** Package name */\n name: string;\n /** Package version */\n version: string;\n /** Package dependency names (prod and peer) */\n dependencies?: string[];\n /** Whether the package is external (not defined in this repo) */\n isExternal: boolean;\n}\n\nconst ZodEnsurePackageBundledResult = matchingZodObject<EnsurePackageBundledResult>({\n name: z.string(),\n version: z.string(),\n bundlerName: z.string().optional(),\n inputPath: z.string().optional(),\n outputPath: z.string(),\n entries: z.record(z.string()).optional(),\n dependencies: z.array(z.string()).optional(),\n hash: z.string().optional(),\n outputFiles: z\n .array(\n z.object({\n outputPath: z.string(),\n entryPoint: z.string().optional(),\n exports: z.array(z.string()).optional(),\n }),\n )\n .optional(),\n errors: z.array(ZodTaskMessage).optional(),\n warnings: z.array(ZodTaskMessage).optional(),\n rawInput: z.record(z.unknown()).optional(),\n rawOutput: z.record(z.unknown()).optional(),\n isExternal: z.boolean(),\n imports: z.record(z.array(z.string())).optional(),\n});\n\n/**\n * Complete output for `ensurePackageBundled`.\n */\nexport interface EnsurePackageBundledOutput {\n /** Result of bundling this package */\n result: EnsurePackageBundledResult;\n /** Results of bundling dependencies */\n dependencies: Promise<EnsurePackageBundledResult[]>;\n}\n\nconst ZodEnsurePackageBundledOutput = matchingZodObject<EnsurePackageBundledOutput>({\n result: ZodEnsurePackageBundledResult,\n dependencies: z.promise(ZodEnsurePackageBundledResult.array()),\n});\n\n/**\n * Checks if the package is bundled or needs bundling, and returns the result. For internal packages,\n * we also notify the watcher to monitor for code changes.\n */\nexport async function ensurePackageBundled(\n params: ApiParams<\n EnsurePackageBundledInput,\n | 'bus'\n | 'taskRunner'\n | 'session'\n | 'watcher'\n | 'packages'\n | 'reporter'\n | 'telemetryClient'\n | 'packageImportPaths'\n | 'packageHashes'\n >,\n): Promise<EnsurePackageBundledOutput> {\n const { input, ctx } = params;\n const results: EnsurePackageBundledResult[] = [];\n const visited = new Set<`${string}@${string}`>();\n const bundleResult = await ensurePackageBundledInternal({ input, ctx, visited });\n const { result } = bundleResult;\n const mainDependencies = bundleResult.dependencyInputs;\n\n let pending = 0;\n const dependencies = new Promise<EnsurePackageBundledResult[]>((resolve) => {\n const enqueue = (dependencyInputs: EnsurePackageBundledInput[]) => {\n for (const dependencyInput of dependencyInputs) {\n pending++;\n void ensurePackageBundledInternal({\n input: dependencyInput,\n ctx,\n visited,\n }).then((dependencyBundleResult) => {\n pending--;\n results.push(dependencyBundleResult.result);\n enqueue(dependencyBundleResult.dependencyInputs);\n if (!pending) {\n resolve(results);\n }\n });\n }\n };\n\n enqueue(mainDependencies);\n });\n\n return {\n result,\n dependencies,\n };\n}\n\nasync function ensurePackageBundledInternal(\n params: Parameters<typeof ensurePackageBundled>[0] & {\n visited: Set<`${string}@${string}`>;\n },\n): Promise<{ result: EnsurePackageBundledResult; dependencyInputs: EnsurePackageBundledInput[] }> {\n const { input, ctx, visited } = params;\n const {\n name,\n version,\n shouldWatch,\n bundlerType,\n disableSourceMaps,\n outputPath,\n shouldFindImports,\n shouldRerun,\n shouldForce,\n disableCache,\n isIncremental,\n } = input;\n const { taskRunner, session, watcher, packages, packageHashes } = ctx;\n const { resolveMap, config } = session;\n const { features } = config;\n const enqueueDependencies = input.enqueueDependencies ?? features?.enqueueDependencies;\n const dependencyInputs: EnsurePackageBundledInput[] = [];\n\n visited.add(`${name}@${version}`);\n\n // First, we find the resolve map entry. This helps us resolve the physical location of the package\n // according to the resolveMap used in the session. (This can change based on linking.)\n const packageEntry = findResolveMapEntry({ packageName: name, version, resolveMap });\n\n if (!packageEntry) {\n throw new Error(`Could not find package ${name} in the resolve map.`);\n }\n\n const bundleRequest = createBundleRequestForPackage(\n {\n packageEntry,\n bundlerType,\n disableSourceMaps,\n outputPath,\n shouldFindImports: shouldFindImports || enqueueDependencies,\n disableCache,\n isIncremental,\n },\n { config, packages, packageHashes },\n );\n\n const task = createBundleTask(bundleRequest, ctx, { force: shouldForce });\n\n // TODO: Add lage scheduling back.\n const { result } = await taskRunner.add<BundleRequest>(task, { rerun: shouldRerun });\n\n if (!result) {\n throw new Error('Bundle failed, no result');\n }\n\n const { isExternal } = bundleRequest;\n\n const { userPackageSettings } =\n getPackageSettings({\n name: bundleRequest.packageName,\n version: bundleRequest.version,\n config,\n }) || {};\n const { inputPaths } = userPackageSettings || {};\n const watchOptions: WatchOptions = {\n path: packageEntry.path,\n watchPaths: inputPaths,\n };\n // For internal packages, make sure we're watching the source to re-trigger bundling.\n if (shouldWatch && !isExternal) {\n const onPackageChange = async () => {\n const watchedResult = await taskRunner.add<BundleRequest>(task, { rerun: true });\n\n // If the result was successful, notify potential clients for reload.\n if (watchedResult.result?.errors?.length === 0) {\n notifyReload(ctx);\n }\n };\n watcher.watch(watchOptions, () => {\n void onPackageChange();\n });\n }\n\n // If enabled, enqueue dependencies.\n if (enqueueDependencies && result?.imports) {\n for (const dependencyName of Object.keys(result.imports)) {\n // If we've already visited this package, skip it.\n if (visited.has(`${dependencyName}@${packageEntry.dependencies[dependencyName]}`)) {\n continue;\n }\n\n dependencyInputs.push({\n name: dependencyName,\n version: packageEntry.dependencies[dependencyName],\n shouldWatch,\n enqueueDependencies,\n });\n }\n }\n\n return {\n result: {\n version,\n name,\n isExternal,\n ...result,\n },\n dependencyInputs,\n };\n}\n\n// Attach a trpc procedure to the function.\nensurePackageBundled.procedure = publicProcedure\n .input(ZodEnsurePackageBundledInput)\n .output(ZodEnsurePackageBundledOutput)\n .mutation(ensurePackageBundled);\n\nexport type EnsurePackageBundledContext = Parameters<typeof ensurePackageBundled>[0]['ctx'];\n"]}
1
+ {"version":3,"file":"ensurePackageBundled.js","sourceRoot":"","sources":["../../src/apis/ensurePackageBundled.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,EAAE,mBAAmB,EAAE,MAAM,i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,CAAC","sourcesContent":["import { z } from 'zod';\nimport { findResolveMapEntry } from '@ms-cloudpack/package-utilities';\nimport { publicProcedure } from '../trpc/common.js';\nimport { notifyReload } from '../utilities/notifyReload.js';\nimport type { BundleRequest } from '../types/BundleRequest.js';\nimport { createBundleTask } from '../utilities/createBundleTask.js';\nimport { createBundleRequestForPackage } from '../utilities/createBundleRequestForPackage.js';\nimport { ZodTaskMessage } from '../types/TaskMessage.js';\nimport type { ApiParams } from '../types/ApiParams.js';\nimport { matchingZodObject } from '../utilities/matchingZodObject.js';\nimport { getPackageSettings } from '@ms-cloudpack/config';\nimport type { WatchOptions } from '@ms-cloudpack/file-watcher';\n\n/**\n * Input for `ensurePackageBundled`.\n */\nexport interface EnsurePackageBundledInput\n extends Pick<BundleRequest, 'outputPath' | 'version' | 'bundlerType' | 'disableSourceMaps' | 'shouldGetBundleInfo'> {\n /** Package name */\n name: string;\n /** Whether to also ensure dependencies are bundled */\n enqueueDependencies?: boolean;\n /** Whether to re-run the bundle task */\n shouldRerun?: boolean;\n /** Whether to watch for changes (internal packages only) */\n shouldWatch?: boolean;\n /** Whether to force re-bundling */\n shouldForce?: boolean;\n /** Whether to disable caching. */\n disableCache?: boolean;\n /** Whether to support incremental rebuilds. Defaults to true for internal libraries. */\n isIncremental?: boolean;\n}\n\nconst ZodEnsurePackageBundledInput = matchingZodObject<EnsurePackageBundledInput>({\n name: z.string(),\n version: z.string(),\n outputPath: z.string().optional(),\n bundlerType: z.string().optional(),\n disableSourceMaps: z.boolean().optional(),\n enqueueDependencies: z.boolean().optional(),\n shouldGetBundleInfo: z.boolean().optional(),\n shouldRerun: z.boolean().optional(),\n shouldWatch: z.boolean().optional(),\n shouldForce: z.boolean().optional(),\n disableCache: z.boolean().optional(),\n isIncremental: z.boolean().optional(),\n});\n\n/**\n * Result of ensuring a single package is bundled.\n */\nexport interface EnsurePackageBundledResult extends Omit<NonNullable<BundleRequest['result']>, 'rebuild' | 'dispose'> {\n /** Package name */\n name: string;\n /** Package version */\n version: string;\n /** Package dependency names (prod and peer) */\n dependencies?: string[];\n /** Whether the package is external (not defined in this repo) */\n isExternal: boolean;\n}\n\nconst ZodEnsurePackageBundledResult = matchingZodObject<EnsurePackageBundledResult>({\n name: z.string(),\n version: z.string(),\n bundlerName: z.string().optional(),\n inputPath: z.string().optional(),\n outputPath: z.string(),\n entries: z.record(z.string()).optional(),\n dependencies: z.array(z.string()).optional(),\n hash: z.string().optional(),\n outputFiles: z\n .array(\n z.object({\n outputPath: z.string(),\n entryPoint: z.string().optional(),\n exports: z.array(z.string()).optional(),\n }),\n )\n .optional(),\n errors: z.array(ZodTaskMessage).optional(),\n warnings: z.array(ZodTaskMessage).optional(),\n rawInput: z.record(z.unknown()).optional(),\n rawOutput: z.record(z.unknown()).optional(),\n isExternal: z.boolean(),\n info: z\n .object({\n entry: z.record(\n z.object({\n bundlePath: z.string(),\n produces: z.array(z.string()),\n consumes: z.array(\n z.object({\n packageName: z.string(),\n importPath: z.string(),\n names: z.array(z.string()),\n }),\n ),\n }),\n ),\n })\n .optional(),\n});\n\n/**\n * Complete output for `ensurePackageBundled`.\n */\nexport interface EnsurePackageBundledOutput {\n /** Result of bundling this package */\n result: EnsurePackageBundledResult;\n /** Results of bundling dependencies */\n dependencies: Promise<EnsurePackageBundledResult[]>;\n}\n\nconst ZodEnsurePackageBundledOutput = matchingZodObject<EnsurePackageBundledOutput>({\n result: ZodEnsurePackageBundledResult,\n dependencies: z.promise(ZodEnsurePackageBundledResult.array()),\n});\n\n/**\n * Checks if the package is bundled or needs bundling, and returns the result. For internal packages,\n * we also notify the watcher to monitor for code changes.\n */\nexport async function ensurePackageBundled(\n params: ApiParams<\n EnsurePackageBundledInput,\n | 'bus'\n | 'taskRunner'\n | 'session'\n | 'watcher'\n | 'packages'\n | 'reporter'\n | 'telemetryClient'\n | 'packageImportPaths'\n | 'packageHashes'\n >,\n): Promise<EnsurePackageBundledOutput> {\n const { input, ctx } = params;\n const results: EnsurePackageBundledResult[] = [];\n const visited = new Set<`${string}@${string}`>();\n const bundleResult = await ensurePackageBundledInternal({ input, ctx, visited });\n const { result } = bundleResult;\n const mainDependencies = bundleResult.dependencyInputs;\n\n let pending = 0;\n const dependencies = new Promise<EnsurePackageBundledResult[]>((resolve) => {\n const enqueue = (dependencyInputs: EnsurePackageBundledInput[]) => {\n for (const dependencyInput of dependencyInputs) {\n pending++;\n void ensurePackageBundledInternal({\n input: dependencyInput,\n ctx,\n visited,\n }).then((dependencyBundleResult) => {\n pending--;\n results.push(dependencyBundleResult.result);\n enqueue(dependencyBundleResult.dependencyInputs);\n if (!pending) {\n resolve(results);\n }\n });\n }\n };\n\n enqueue(mainDependencies);\n });\n\n return {\n result,\n dependencies,\n };\n}\n\nasync function ensurePackageBundledInternal(\n params: Parameters<typeof ensurePackageBundled>[0] & {\n visited: Set<`${string}@${string}`>;\n },\n): Promise<{ result: EnsurePackageBundledResult; dependencyInputs: EnsurePackageBundledInput[] }> {\n const { input, ctx, visited } = params;\n const {\n name,\n version,\n shouldWatch,\n bundlerType,\n disableSourceMaps,\n outputPath,\n shouldGetBundleInfo,\n shouldRerun,\n shouldForce,\n disableCache,\n isIncremental,\n } = input;\n const { taskRunner, session, watcher, packages, packageHashes } = ctx;\n const { resolveMap, config } = session;\n const { features } = config;\n const enqueueDependencies = input.enqueueDependencies ?? features?.enqueueDependencies;\n const dependencyInputs: EnsurePackageBundledInput[] = [];\n\n visited.add(`${name}@${version}`);\n\n // First, we find the resolve map entry. This helps us resolve the physical location of the package\n // according to the resolveMap used in the session. (This can change based on linking.)\n const packageEntry = findResolveMapEntry({ packageName: name, version, resolveMap });\n\n if (!packageEntry) {\n throw new Error(`Could not find package ${name} in the resolve map.`);\n }\n\n const bundleRequest = createBundleRequestForPackage(\n {\n packageEntry,\n bundlerType,\n disableSourceMaps,\n outputPath,\n shouldGetBundleInfo: shouldGetBundleInfo || enqueueDependencies,\n disableCache,\n isIncremental,\n },\n { config, packages, packageHashes },\n );\n\n const task = createBundleTask(bundleRequest, ctx, { force: shouldForce });\n\n // TODO: Add lage scheduling back.\n const { result } = await taskRunner.add<BundleRequest>(task, { rerun: shouldRerun });\n\n if (!result) {\n throw new Error('Bundle failed, no result');\n }\n\n const { isExternal } = bundleRequest;\n\n const { userPackageSettings } =\n getPackageSettings({\n name: bundleRequest.packageName,\n version: bundleRequest.version,\n config,\n }) || {};\n const { inputPaths } = userPackageSettings || {};\n const watchOptions: WatchOptions = {\n path: packageEntry.path,\n watchPaths: inputPaths,\n };\n // For internal packages, make sure we're watching the source to re-trigger bundling.\n if (shouldWatch && !isExternal) {\n const onPackageChange = async () => {\n const watchedResult = await taskRunner.add<BundleRequest>(task, { rerun: true });\n\n // If the result was successful, notify potential clients for reload.\n if (watchedResult.result?.errors?.length === 0) {\n notifyReload(ctx);\n }\n };\n watcher.watch(watchOptions, () => {\n void onPackageChange();\n });\n }\n\n // If enabled, enqueue dependencies.\n if (enqueueDependencies && result?.info?.entry) {\n for (const entryInfo of Object.values(result.info.entry)) {\n // iterate through all package names of result.info.entry.consumes\n for (const consume of entryInfo.consumes) {\n const dependencyName = consume.packageName;\n // If we've already visited this package, skip it.\n if (visited.has(`${dependencyName}@${packageEntry.dependencies[dependencyName]}`)) {\n continue;\n }\n dependencyInputs.push({\n name: dependencyName,\n version: packageEntry.dependencies[dependencyName],\n shouldWatch,\n enqueueDependencies,\n });\n }\n }\n }\n\n return {\n result: {\n version,\n name,\n isExternal,\n ...result,\n },\n dependencyInputs,\n };\n}\n\n// Attach a trpc procedure to the function.\nensurePackageBundled.procedure = publicProcedure\n .input(ZodEnsurePackageBundledInput)\n .output(ZodEnsurePackageBundledOutput)\n .mutation(ensurePackageBundled);\n\nexport type EnsurePackageBundledContext = Parameters<typeof ensurePackageBundled>[0]['ctx'];\n"]}
package/lib/index.d.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  export type { ApiServer } from './types/ApiServer.js';
2
2
  export type { Context } from './types/Context.js';
3
- export type { DetectedImports } from './types/DetectedImports.js';
3
+ export type { BundleInfo } from './types/BundleInfo.js';
4
4
  export type { Session } from './types/Session.js';
5
5
  export type { TaskStats } from './types/TaskStats.js';
6
6
  export type { Task } from './types/Task.js';
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,YAAY,EAAE,SAAS,EAAE,MAAM,sBAAsB,CAAC;AACtD,YAAY,EAAE,OAAO,EAAE,MAAM,oBAAoB,CAAC;AAClD,YAAY,EAAE,eAAe,EAAE,MAAM,4BAA4B,CAAC;AAClE,YAAY,EAAE,OAAO,EAAE,MAAM,oBAAoB,CAAC;AAClD,YAAY,EAAE,SAAS,EAAE,MAAM,sBAAsB,CAAC;AACtD,YAAY,EAAE,IAAI,EAAE,MAAM,iBAAiB,CAAC;AAC5C,YAAY,EAAE,eAAe,EAAE,MAAM,4BAA4B,CAAC;AAClE,YAAY,EAAE,kBAAkB,EAAE,MAAM,+BAA+B,CAAC;AACxE,YAAY,EAAE,WAAW,EAAE,MAAM,wBAAwB,CAAC;AAC1D,YAAY,EAAE,WAAW,EAAE,MAAM,wBAAwB,CAAC;AAC1D,YAAY,EAAE,oBAAoB,EAAE,MAAM,iCAAiC,CAAC;AAC5E,YAAY,EAAE,eAAe,EAAE,MAAM,iCAAiC,CAAC;AAEvE,YAAY,EAAE,kBAAkB,EAAE,MAAM,+BAA+B,CAAC;AACxE,YAAY,EAAE,iBAAiB,EAAE,MAAM,8BAA8B,CAAC;AACtE,YAAY,EAAE,gBAAgB,EAAE,MAAM,6BAA6B,CAAC;AACpE,YAAY,EAAE,gBAAgB,EAAE,MAAM,6BAA6B,CAAC;AAEpE,OAAO,EAAE,UAAU,EAAE,MAAM,2BAA2B,CAAC;AACvD,OAAO,EAAE,iBAAiB,EAAE,cAAc,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAC;AAC1F,OAAO,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AACrD,OAAO,EAAE,qBAAqB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export type { ApiServer } from './types/ApiServer.js';\nexport type { Context } from './types/Context.js';\nexport type { DetectedImports } from './types/DetectedImports.js';\nexport type { Session } from './types/Session.js';\nexport type { TaskStats } from './types/TaskStats.js';\nexport type { Task } from './types/Task.js';\nexport type { TaskDescription } from './types/TaskDescription.js';\nexport type { TaskEndDescription } from './types/TaskEndDescription.js';\nexport type { TaskMessage } from './types/TaskMessage.js';\nexport type { TaskOptions } from './types/TaskOptions.js';\nexport type { TaskStartDescription } from './types/TaskStartDescription.js';\nexport type { CloudpackServer } from './trpc/createCloudpackServer.js';\n\nexport type { CreateHtmlFunction } from './types/CreateHtmlFunction.js';\nexport type { CreateHtmlOptions } from './types/CreateHtmlOptions.js';\nexport type { CreateHtmlResult } from './types/CreateHtmlResult.js';\nexport type { CreateHtmlScript } from './types/CreateHtmlScript.js';\n\nexport { TaskRunner } from './utilities/TaskRunner.js';\nexport { reloadCountSource, taskListSource, taskStatsSource } from './data/busSources.js';\nexport { startApiServer } from './startApiServer.js';\nexport { createCloudpackClient } from './trpc/createCloudpackClient.js';\nexport { createCloudpackServer } from './trpc/createCloudpackServer.js';\nexport { ZodTaskDescription } from './types/TaskDescription.js';\nexport { ZodTaskEndDescription } from './types/TaskEndDescription.js';\nexport { ZodTaskMessage } from './types/TaskMessage.js';\nexport { ZodTaskStartDescription } from './types/TaskStartDescription.js';\nexport { getCachePath, getLocalCachePath } from './utilities/getCachePath.js';\n\n// API types\nexport type { AddPackageOverrideInput } from './apis/addPackageOverride.js';\nexport type { OpenCodeEditorInput } from './apis/openCodeEditor.js';\nexport type { OpenFilePathInput } from './apis/openFilePath.js';\nexport type { ReportMetricInput } from './apis/reportMetric.js';\nexport type { ValidatePackageOverrideInput, ValidatePackageOverrideOutput } from './apis/validatePackageOverride.js';\n\n// Utilities\nexport { parseRequestInfo } from './utilities/parseRequestInfo.js';\n\n// TODO: delete these type exports once API reporting of \"forgotten\" exports is enabled\n// (they're not used and don't really need to be visible in the API)\nexport type {\n EnsurePackageBundledInput,\n EnsurePackageBundledOutput,\n EnsurePackageBundledResult,\n} from './apis/ensurePackageBundled.js';\nexport type { BundleRequest } from './types/BundleRequest.js';\nexport type { BundleTaskOptions } from './types/BundleTaskOptions.js';\nexport type { OverrideOptions } from './types/OverrideOptions.js';\n"]}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAkBA,OAAO,EAAE,UAAU,EAAE,MAAM,2BAA2B,CAAC;AACvD,OAAO,EAAE,iBAAiB,EAAE,cAAc,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAC;AAC1F,OAAO,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AACrD,OAAO,EAAE,qBAAqB,EAAE,MAAM,iCAAiC,CAAC;AACxE,OAAO,EAAE,qBAAqB,EAAE,MAAM,iCAAiC,CAAC;AACxE,OAAO,EAAE,kBAAkB,EAAE,MAAM,4BAA4B,CAAC;AAChE,OAAO,EAAE,qBAAqB,EAAE,MAAM,+BAA+B,CAAC;AACtE,OAAO,EAAE,cAAc,EAAE,MAAM,wBAAwB,CAAC;AACxD,OAAO,EAAE,uBAAuB,EAAE,MAAM,iCAAiC,CAAC;AAC1E,OAAO,EAAE,YAAY,EAAE,iBAAiB,EAAE,MAAM,6BAA6B,CAAC;AAS9E,YAAY;AACZ,OAAO,EAAE,gBAAgB,EAAE,MAAM,iCAAiC,CAAC","sourcesContent":["export type { ApiServer } from './types/ApiServer.js';\nexport type { Context } from './types/Context.js';\nexport type { BundleInfo } from './types/BundleInfo.js';\nexport type { Session } from './types/Session.js';\nexport type { TaskStats } from './types/TaskStats.js';\nexport type { Task } from './types/Task.js';\nexport type { TaskDescription } from './types/TaskDescription.js';\nexport type { TaskEndDescription } from './types/TaskEndDescription.js';\nexport type { TaskMessage } from './types/TaskMessage.js';\nexport type { TaskOptions } from './types/TaskOptions.js';\nexport type { TaskStartDescription } from './types/TaskStartDescription.js';\nexport type { CloudpackServer } from './trpc/createCloudpackServer.js';\n\nexport type { CreateHtmlFunction } from './types/CreateHtmlFunction.js';\nexport type { CreateHtmlOptions } from './types/CreateHtmlOptions.js';\nexport type { CreateHtmlResult } from './types/CreateHtmlResult.js';\nexport type { CreateHtmlScript } from './types/CreateHtmlScript.js';\n\nexport { TaskRunner } from './utilities/TaskRunner.js';\nexport { reloadCountSource, taskListSource, taskStatsSource } from './data/busSources.js';\nexport { startApiServer } from './startApiServer.js';\nexport { createCloudpackClient } from './trpc/createCloudpackClient.js';\nexport { createCloudpackServer } from './trpc/createCloudpackServer.js';\nexport { ZodTaskDescription } from './types/TaskDescription.js';\nexport { ZodTaskEndDescription } from './types/TaskEndDescription.js';\nexport { ZodTaskMessage } from './types/TaskMessage.js';\nexport { ZodTaskStartDescription } from './types/TaskStartDescription.js';\nexport { getCachePath, getLocalCachePath } from './utilities/getCachePath.js';\n\n// API types\nexport type { AddPackageOverrideInput } from './apis/addPackageOverride.js';\nexport type { OpenCodeEditorInput } from './apis/openCodeEditor.js';\nexport type { OpenFilePathInput } from './apis/openFilePath.js';\nexport type { ReportMetricInput } from './apis/reportMetric.js';\nexport type { ValidatePackageOverrideInput, ValidatePackageOverrideOutput } from './apis/validatePackageOverride.js';\n\n// Utilities\nexport { parseRequestInfo } from './utilities/parseRequestInfo.js';\n\n// TODO: delete these type exports once API reporting of \"forgotten\" exports is enabled\n// (they're not used and don't really need to be visible in the API)\nexport type {\n EnsurePackageBundledInput,\n EnsurePackageBundledOutput,\n EnsurePackageBundledResult,\n} from './apis/ensurePackageBundled.js';\nexport type { BundleRequest } from './types/BundleRequest.js';\nexport type { BundleTaskOptions } from './types/BundleTaskOptions.js';\nexport type { OverrideOptions } from './types/OverrideOptions.js';\n"]}
@@ -0,0 +1,25 @@
1
+ /**
2
+ * BundleInfo is a map of entry file paths to produce/consume information.
3
+ * e.g.:
4
+ * {
5
+ * ".": {
6
+ * "bundlePath": "./index.js",
7
+ * "produces": ['bar'],
8
+ * "consumes": [{ "packageName": "foo", "importPath": "foo", "names": [ "foo" ] }],
9
+ * },
10
+ * }
11
+ */
12
+ export type BundleInfo = {
13
+ entry: {
14
+ [filePath: string]: {
15
+ bundlePath: string;
16
+ produces: string[];
17
+ consumes: {
18
+ packageName: string;
19
+ importPath: string;
20
+ names: string[];
21
+ }[];
22
+ };
23
+ };
24
+ };
25
+ //# sourceMappingURL=BundleInfo.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"BundleInfo.d.ts","sourceRoot":"","sources":["../../src/types/BundleInfo.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AACH,MAAM,MAAM,UAAU,GAAG;IACvB,KAAK,EAAE;QACL,CAAC,QAAQ,EAAE,MAAM,GAAG;YAClB,UAAU,EAAE,MAAM,CAAC;YACnB,QAAQ,EAAE,MAAM,EAAE,CAAC;YACnB,QAAQ,EAAE;gBACR,WAAW,EAAE,MAAM,CAAC;gBACpB,UAAU,EAAE,MAAM,CAAC;gBACnB,KAAK,EAAE,MAAM,EAAE,CAAC;aACjB,EAAE,CAAC;SACL,CAAC;KACH,CAAC;CACH,CAAC"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=BundleInfo.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"BundleInfo.js","sourceRoot":"","sources":["../../src/types/BundleInfo.ts"],"names":[],"mappings":"","sourcesContent":["/**\n * BundleInfo is a map of entry file paths to produce/consume information.\n * e.g.:\n * {\n * \".\": {\n * \"bundlePath\": \"./index.js\",\n * \"produces\": ['bar'],\n * \"consumes\": [{ \"packageName\": \"foo\", \"importPath\": \"foo\", \"names\": [ \"foo\" ] }],\n * },\n * }\n */\nexport type BundleInfo = {\n entry: {\n [filePath: string]: {\n bundlePath: string;\n produces: string[];\n consumes: {\n packageName: string;\n importPath: string;\n names: string[];\n }[];\n };\n };\n};\n"]}
@@ -1,7 +1,7 @@
1
1
  import type { BundleResult, PackageDefinitionsCache } from '@ms-cloudpack/bundler-types';
2
2
  import type { CloudpackConfig } from '@ms-cloudpack/config-types';
3
3
  import type { PackageHashes } from '@ms-cloudpack/package-hashes';
4
- import type { DetectedImports } from './DetectedImports.js';
4
+ import type { BundleInfo } from './BundleInfo.js';
5
5
  /**
6
6
  * Tracks a given bundle request and its result.
7
7
  */
@@ -24,19 +24,15 @@ export interface BundleRequest {
24
24
  bundlerType?: string;
25
25
  /** Result of bundling */
26
26
  result?: Omit<BundleResult, 'outputPath'> & Required<Pick<BundleRequest, 'outputPath'>> & {
27
- /**
28
- * Mapping from dependency name to list of paths that are actually imported in the bundled files.
29
- * e.g. `{ '@fluentui/react': [ '.', './lib/Button' ] }`
30
- */
31
- imports?: DetectedImports;
32
27
  hash?: string;
28
+ info?: BundleInfo;
33
29
  };
34
30
  /** Whether the result was retrieved from the cache (set while bundling) */
35
31
  resultFromCache?: boolean;
36
32
  /** Whether to disable source maps */
37
33
  disableSourceMaps?: boolean;
38
- /** Whether to scan the bundled code for imports of other packages */
39
- shouldFindImports?: boolean;
34
+ /** Whether to scan the bundled code for imports and exports */
35
+ shouldGetBundleInfo?: boolean;
40
36
  /** Whether to enable caching of bundled packages from within the repo */
41
37
  shouldCacheInternalPackages?: boolean;
42
38
  /** Whether to disable caching */
@@ -1 +1 @@
1
- {"version":3,"file":"BundleRequest.d.ts","sourceRoot":"","sources":["../../src/types/BundleRequest.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,uBAAuB,EAAE,MAAM,6BAA6B,CAAC;AACzF,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,4BAA4B,CAAC;AAClE,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,8BAA8B,CAAC;AAClE,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAC;AAE5D;;GAEG;AACH,MAAM,WAAW,aAAa;IAC5B,wBAAwB;IACxB,EAAE,EAAE,MAAM,CAAC;IACX,iCAAiC;IACjC,WAAW,EAAE,MAAM,CAAC;IACpB,oCAAoC;IACpC,OAAO,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Request.ts"],"names":[],"mappings":"","sourcesContent":["import type { BundleResult, PackageDefinitionsCache } from '@ms-cloudpack/bundler-types';\nimport type { CloudpackConfig } from '@ms-cloudpack/config-types';\nimport type { PackageHashes } from '@ms-cloudpack/package-hashes';\nimport type { DetectedImports } from './DetectedImports.js';\n\n/**\n * Tracks a given bundle request and its result.\n */\nexport interface BundleRequest {\n /** ID for the bundle */\n id: string;\n /** Package name being bundled */\n packageName: string;\n /** Package version being bundled */\n version: string;\n /** Absolute path to the package */\n packagePath: string;\n /** Absolute path for the bundle output */\n outputPath?: string;\n /** Whether this is an external package (in node_modules) */\n isExternal: boolean;\n /** Whether we should force the incremental flag. */\n isIncremental?: boolean;\n /** Force using this bundler */\n bundlerType?: string;\n /** Result of bundling */\n result?: Omit<BundleResult, 'outputPath'> &\n Required<Pick<BundleRequest, 'outputPath'>> & {\n /**\n * Mapping from dependency name to list of paths that are actually imported in the bundled files.\n * e.g. `{ '@fluentui/react': [ '.', './lib/Button' ] }`\n */\n imports?: DetectedImports;\n hash?: string;\n };\n /** Whether the result was retrieved from the cache (set while bundling) */\n // TODO: this seems like it should be a property of the result?\n resultFromCache?: boolean;\n /** Whether to disable source maps */\n disableSourceMaps?: boolean;\n /** Whether to scan the bundled code for imports of other packages */\n shouldFindImports?: boolean;\n /** Whether to enable caching of bundled packages from within the repo */\n shouldCacheInternalPackages?: boolean;\n /** Whether to disable caching */\n disableCache?: boolean;\n /** Whether to use package hashes in the import map (as cache breakers) */\n hashPackages?: boolean;\n /** Cached package.jsons */\n packages: PackageDefinitionsCache;\n /** Cloudpack config */\n config: CloudpackConfig;\n /** Cached package hashes */\n packageHashes: PackageHashes;\n}\n"]}
1
+ {"version":3,"file":"BundleRequest.js","sourceRoot":"","sources":["../../src/types/BundleRequest.ts"],"names":[],"mappings":"","sourcesContent":["import type { BundleResult, PackageDefinitionsCache } from '@ms-cloudpack/bundler-types';\nimport type { CloudpackConfig } from '@ms-cloudpack/config-types';\nimport type { PackageHashes } from '@ms-cloudpack/package-hashes';\nimport type { BundleInfo } from './BundleInfo.js';\n\n/**\n * Tracks a given bundle request and its result.\n */\nexport interface BundleRequest {\n /** ID for the bundle */\n id: string;\n /** Package name being bundled */\n packageName: string;\n /** Package version being bundled */\n version: string;\n /** Absolute path to the package */\n packagePath: string;\n /** Absolute path for the bundle output */\n outputPath?: string;\n /** Whether this is an external package (in node_modules) */\n isExternal: boolean;\n /** Whether we should force the incremental flag. */\n isIncremental?: boolean;\n /** Force using this bundler */\n bundlerType?: string;\n /** Result of bundling */\n result?: Omit<BundleResult, 'outputPath'> &\n Required<Pick<BundleRequest, 'outputPath'>> & {\n hash?: string;\n info?: BundleInfo;\n };\n /** Whether the result was retrieved from the cache (set while bundling) */\n // TODO: this seems like it should be a property of the result?\n resultFromCache?: boolean;\n /** Whether to disable source maps */\n disableSourceMaps?: boolean;\n /** Whether to scan the bundled code for imports and exports */\n shouldGetBundleInfo?: boolean;\n /** Whether to enable caching of bundled packages from within the repo */\n shouldCacheInternalPackages?: boolean;\n /** Whether to disable caching */\n disableCache?: boolean;\n /** Whether to use package hashes in the import map (as cache breakers) */\n hashPackages?: boolean;\n /** Cached package.jsons */\n packages: PackageDefinitionsCache;\n /** Cloudpack config */\n config: CloudpackConfig;\n /** Cached package hashes */\n packageHashes: PackageHashes;\n}\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"bundleTask.d.ts","sourceRoot":"","sources":["../../src/utilities/bundleTask.ts"],"names":[],"mappings":"AAGA,OAAO,EAGL,KAAK,YAAY,EAElB,MAAM,6BAA6B,CAAC;AAIrC,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,+BAA+B,CAAC;AACvE,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,2BAA2B,CAAC;AAM/D,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,yBAAyB,CAAC;AAM/D,wBAAsB,UAAU,CAAC,MAAM,EAAE;IACvC,aAAa,EAAE,aAAa,CAAC;IAC7B,OAAO,CAAC,EAAE,iBAAiB,CAAC;IAC5B,QAAQ,CAAC,EAAE,YAAY,CAAC;IACxB,eAAe,CAAC,EAAE,eAAe,CAAC;CACnC,GAAG,OAAO,CAAC,aAAa,CAAC,CAqEzB"}
1
+ {"version":3,"file":"bundleTask.d.ts","sourceRoot":"","sources":["../../src/utilities/bundleTask.ts"],"names":[],"mappings":"AAGA,OAAO,EAGL,KAAK,YAAY,EAElB,MAAM,6BAA6B,CAAC;AAGrC,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,+BAA+B,CAAC;AACvE,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,2BAA2B,CAAC;AAM/D,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,yBAAyB,CAAC;AAQ/D,wBAAsB,UAAU,CAAC,MAAM,EAAE;IACvC,aAAa,EAAE,aAAa,CAAC;IAC7B,OAAO,CAAC,EAAE,iBAAiB,CAAC;IAC5B,QAAQ,CAAC,EAAE,YAAY,CAAC;IACxB,eAAe,CAAC,EAAE,eAAe,CAAC;CACnC,GAAG,OAAO,CAAC,aAAa,CAAC,CAqEzB"}
@@ -1,9 +1,8 @@
1
1
  import { bundle as bundleInternal, getEntriesMapFromPackage, getExternalsFromPackage } from '@ms-cloudpack/bundler';
2
- import { readJson, writeJson } from '@ms-cloudpack/json-utilities';
2
+ import { writeJson } from '@ms-cloudpack/json-utilities';
3
3
  import { safeRelativePath } from '@ms-cloudpack/path-string-parsing';
4
4
  import { bulletedList, formatPackageName, } from '@ms-cloudpack/task-reporter';
5
5
  import path from 'path';
6
- import { findImports } from './findImports.js';
7
6
  import { prepareOutputPath } from '../common/prepareOutputPath.js';
8
7
  import { formatBundleErrors } from './formatBundleErrors.js';
9
8
  import { getFileSizeSync } from './getFileSizeSync.js';
@@ -11,6 +10,8 @@ import { getPackageSettings } from '@ms-cloudpack/config';
11
10
  import { isCachedResultValid } from './isCachedResultValid.js';
12
11
  import { diskCacheRatioMetricEventAggregator } from './diskCacheRatioMetricEventAggregator.js';
13
12
  import { getBundleLocation } from './getBundleLocation.js';
13
+ import { getBundleInfo } from './getBundleInfo.js';
14
+ import { getExportsMap } from '@ms-cloudpack/package-utilities';
14
15
  import { readResultFromCache } from './readResultFromCache.js';
15
16
  import { saveResultToCache } from './saveResultToCache.js';
16
17
  export async function bundleTask(params) {
@@ -76,7 +77,7 @@ async function bundle(bundleRequest, force) {
76
77
  bundleRequest.result.dispose();
77
78
  bundleRequest.result = undefined;
78
79
  }
79
- const { packagePath, isExternal, isIncremental, disableSourceMaps, shouldFindImports, shouldCacheInternalPackages } = bundleRequest;
80
+ const { packagePath, isExternal, isIncremental, disableSourceMaps, shouldGetBundleInfo, shouldCacheInternalPackages, } = bundleRequest;
80
81
  const outputPath = bundleRequest.outputPath ?? (await getBundleLocation({ packagePath }, context)).path;
81
82
  // Rehydrate the result if not incremental.
82
83
  if (bundleRequest.result === undefined && (isExternal || shouldCacheInternalPackages) && !force) {
@@ -132,21 +133,24 @@ async function bundle(bundleRequest, force) {
132
133
  await saveResultToCache(bundleRequest.result);
133
134
  }
134
135
  }
135
- if (shouldFindImports && !bundleRequest.result?.errors?.length && bundleRequest.result?.outputFiles?.length) {
136
- const importsPath = path.join(outputPath, 'imports.json');
137
- let imports = await readJson(importsPath);
138
- // If we couldn't rehydrate imports from cache, compute them.
139
- if (!imports) {
140
- const scriptPaths = bundleRequest.result.outputFiles.map((f) => path.resolve(outputPath, f.outputPath));
141
- imports = await findImports(scriptPaths);
142
- // Write to cache for future use. (Ignore the promise result.)
143
- // eslint-disable-next-line @typescript-eslint/no-floating-promises
144
- writeJson(importsPath, imports);
145
- }
146
- bundleRequest.result.imports = imports;
147
- // Find imports that are in the output files and set dependencies.
148
- const outputFilePaths = bundleRequest.result.outputFiles?.map((f) => path.resolve(outputPath, f.outputPath));
149
- bundleRequest.result.imports = outputFilePaths && (await findImports(outputFilePaths));
136
+ // If we should find required imports and exports per bundle
137
+ if (shouldGetBundleInfo && !bundleRequest.result?.errors?.length && bundleRequest.result?.outputFiles?.length) {
138
+ const bundleInfoPath = path.join(outputPath, 'bundle-info.json');
139
+ // Exports map is needed to find the bundle info per entry we intend to bundle.
140
+ // Exports map is used instead of bundleRequest.entries since it is easier to use
141
+ // because it contains the paths other packages use to import the entry and
142
+ // the relative location of the bundled files.
143
+ const exportsMap = await getExportsMap({ packagePath }, context);
144
+ const bundleInfo = await getBundleInfo({
145
+ outputPath,
146
+ outputFiles: bundleRequest.result.outputFiles,
147
+ exportsMap,
148
+ isExternal,
149
+ });
150
+ bundleRequest.result.info = bundleInfo;
151
+ // Write to cache for future use. (Ignore the promise result.)
152
+ // eslint-disable-next-line @typescript-eslint/no-floating-promises
153
+ writeJson(bundleInfoPath, bundleInfo);
150
154
  }
151
155
  return bundleRequest;
152
156
  }
@@ -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,QAAQ,EAAE,SAAS,EAAE,MAAM,8BAA8B,CAAC;AACnE,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,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAC/C,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,E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IAED,OAAO,aAAa,CAAC;AACvB,CAAC","sourcesContent":["import { bundle as bundleInternal, getEntriesMapFromPackage, getExternalsFromPackage } from '@ms-cloudpack/bundler';\nimport { readJson, 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 { findImports } from './findImports.js';\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 { 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, shouldFindImports, shouldCacheInternalPackages } =\n bundleRequest;\n\n const outputPath = bundleRequest.outputPath ?? (await getBundleLocation({ packagePath }, context)).path;\n\n // Rehydrate the result if not incremental.\n if (bundleRequest.result === undefined && (isExternal || shouldCacheInternalPackages) && !force) {\n bundleRequest.result = await readResultFromCache(outputPath, {\n inputPath: packagePath,\n });\n }\n\n const hash =\n !isExternal && shouldCacheInternalPackages\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 } =\n getPackageSettings({\n name: bundleRequest.packageName,\n version: bundleRequest.version,\n config,\n }) || {};\n const { bundlerType, bundlerOptions } = userPackageSettings || {};\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 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 if (isExternal || shouldCacheInternalPackages) {\n await saveResultToCache(bundleRequest.result);\n }\n }\n\n if (shouldFindImports && !bundleRequest.result?.errors?.length && bundleRequest.result?.outputFiles?.length) {\n const importsPath = path.join(outputPath, 'imports.json');\n let imports = await readJson<Record<string, string[]>>(importsPath);\n\n // If we couldn't rehydrate imports from cache, compute them.\n if (!imports) {\n const scriptPaths = bundleRequest.result.outputFiles.map((f) => path.resolve(outputPath, f.outputPath));\n\n imports = await findImports(scriptPaths);\n\n // Write to cache for future use. (Ignore the promise result.)\n // eslint-disable-next-line @typescript-eslint/no-floating-promises\n writeJson(importsPath, imports);\n }\n\n bundleRequest.result.imports = imports;\n\n // Find imports that are in the output files and set dependencies.\n const outputFilePaths = bundleRequest.result.outputFiles?.map((f) => path.resolve(outputPath, f.outputPath));\n bundleRequest.result.imports = outputFilePaths && (await findImports(outputFilePaths));\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;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,iBAAiB,EAAE,MAAM,wBAAwB,CAAC;AAC3D,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AACnD,OAAO,EAAE,aAAa,EAAE,MAAM,iCAAiC,CAAC;AAChE,OAAO,EAAE,mBAAmB,EAAE,MAAM,0BAA0B,CAAC;AAC/D,OAAO,EAAE,iBAAiB,EAAE,MAAM,wBAAwB,CAAC;AAE3D,MAAM,CAAC,KAAK,UAAU,UAAU,CAAC,MAKhC;IACC,MAAM,EAAE,aAAa,EAAE,OAAO,GAAG,EAAE,EAAE,QAAQ,EAAE,eAAe,EAAE,GAAG,MAAM,CAAC;IAC1E,MAAM,EAAE,WAAW,EAAE,OAAO,EAAE,GAAG,aAAa,CAAC;IAC/C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AAc,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;KACvC;IAED,OAAO,aAAa,CAAC;AACvB,CAAC","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 {\n packagePath,\n isExternal,\n isIncremental,\n disableSourceMaps,\n shouldGetBundleInfo,\n shouldCacheInternalPackages,\n } = bundleRequest;\n\n const outputPath = bundleRequest.outputPath ?? (await getBundleLocation({ packagePath }, context)).path;\n\n // Rehydrate the result if not incremental.\n if (bundleRequest.result === undefined && (isExternal || shouldCacheInternalPackages) && !force) {\n bundleRequest.result = await readResultFromCache(outputPath, {\n inputPath: packagePath,\n });\n }\n\n const hash =\n !isExternal && shouldCacheInternalPackages\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 } =\n getPackageSettings({\n name: bundleRequest.packageName,\n version: bundleRequest.version,\n config,\n }) || {};\n const { bundlerType, bundlerOptions } = userPackageSettings || {};\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 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 if (isExternal || shouldCacheInternalPackages) {\n await saveResultToCache(bundleRequest.result);\n }\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"]}
@@ -8,7 +8,7 @@ export declare function createBundleRequestForPackage(options: {
8
8
  outputPath?: string;
9
9
  bundlerType?: string;
10
10
  disableSourceMaps?: boolean;
11
- shouldFindImports?: boolean;
11
+ shouldGetBundleInfo?: boolean;
12
12
  disableCache?: boolean;
13
13
  isIncremental?: boolean;
14
14
  }, context: {
@@ -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,uBAAuB,EAAE,MAAM,6BAA6B,CAAC;AAC3E,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,2BAA2B,CAAC;AAC/D,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,8BAA8B,CAAC;AAElE,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,iBAAiB,CAAC,EAAE,OAAO,CAAC;IAC5B,YAAY,CAAC,EAAE,OAAO,CAAC;IACvB,aAAa,CAAC,EAAE,OAAO,CAAC;CACzB,EACD,OAAO,EAAE;IACP,MAAM,EAAE,eAAe,CAAC;IACxB,QAAQ,EAAE,uBAAuB,CAAC;IAClC,aAAa,EAAE,aAAa,CAAC;CAC9B,GACA,aAAa,CAsBf"}
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,uBAAuB,EAAE,MAAM,6BAA6B,CAAC;AAC3E,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,2BAA2B,CAAC;AAC/D,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,8BAA8B,CAAC;AAElE,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;IACxB,QAAQ,EAAE,uBAAuB,CAAC;IAClC,aAAa,EAAE,aAAa,CAAC;CAC9B,GACA,aAAa,CAsBf"}
@@ -12,7 +12,7 @@ export function createBundleRequestForPackage(options, context) {
12
12
  outputPath: options.outputPath,
13
13
  version,
14
14
  disableSourceMaps: options.disableSourceMaps ?? features.disableSourceMaps,
15
- shouldFindImports: options.shouldFindImports ?? features.enqueueDependencies,
15
+ shouldGetBundleInfo: options.shouldGetBundleInfo ?? features.enqueueDependencies,
16
16
  disableCache: options.disableCache,
17
17
  shouldCacheInternalPackages: features.cacheInternalPackages,
18
18
  hashPackages: features.hashPackages,
@@ -1 +1 @@
1
- {"version":3,"file":"createBundleRequestForPackage.js","sourceRoot":"","sources":["../../src/utilities/createBundleRequestForPackage.ts"],"names":[],"mappings":"AAMA,MAAM,UAAU,6BAA6B,CAC3C,OAQC,EACD,OAIC;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,iBAAiB,EAAE,OAAO,CAAC,iBAAiB,IAAI,QAAQ,CAAC,mBAAmB;QAC5E,YAAY,EAAE,OAAO,CAAC,YAAY;QAClC,2BAA2B,EAAE,QAAQ,CAAC,qBAAqB;QAC3D,YAAY,EAAE,QAAQ,CAAC,YAAY;QACnC,WAAW,EAAE,OAAO,CAAC,WAAW;QAChC,GAAG,OAAO;KACX,CAAC;AACJ,CAAC","sourcesContent":["import type { CloudpackConfig } from '@ms-cloudpack/config-types';\nimport type { ResolveMapEntry } from '@ms-cloudpack/package-utilities';\nimport type { PackageDefinitionsCache } from '@ms-cloudpack/bundler-types';\nimport type { BundleRequest } from '../types/BundleRequest.js';\nimport type { PackageHashes } from '@ms-cloudpack/package-hashes';\n\nexport function createBundleRequestForPackage(\n options: {\n packageEntry: ResolveMapEntry;\n outputPath?: string;\n bundlerType?: string;\n disableSourceMaps?: boolean;\n shouldFindImports?: boolean;\n disableCache?: boolean;\n isIncremental?: boolean;\n },\n context: {\n config: CloudpackConfig;\n packages: PackageDefinitionsCache;\n packageHashes: PackageHashes;\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 shouldFindImports: options.shouldFindImports ?? features.enqueueDependencies,\n disableCache: options.disableCache,\n shouldCacheInternalPackages: features.cacheInternalPackages,\n hashPackages: features.hashPackages,\n bundlerType: options.bundlerType,\n ...context,\n };\n}\n"]}
1
+ {"version":3,"file":"createBundleRequestForPackage.js","sourceRoot":"","sources":["../../src/utilities/createBundleRequestForPackage.ts"],"names":[],"mappings":"AAMA,MAAM,UAAU,6BAA6B,CAC3C,OAQC,EACD,OAIC;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,2BAA2B,EAAE,QAAQ,CAAC,qBAAqB;QAC3D,YAAY,EAAE,QAAQ,CAAC,YAAY;QACnC,WAAW,EAAE,OAAO,CAAC,WAAW;QAChC,GAAG,OAAO;KACX,CAAC;AACJ,CAAC","sourcesContent":["import type { CloudpackConfig } from '@ms-cloudpack/config-types';\nimport type { ResolveMapEntry } from '@ms-cloudpack/package-utilities';\nimport type { PackageDefinitionsCache } from '@ms-cloudpack/bundler-types';\nimport type { BundleRequest } from '../types/BundleRequest.js';\nimport type { PackageHashes } from '@ms-cloudpack/package-hashes';\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 packages: PackageDefinitionsCache;\n packageHashes: PackageHashes;\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 shouldCacheInternalPackages: features.cacheInternalPackages,\n hashPackages: features.hashPackages,\n bundlerType: options.bundlerType,\n ...context,\n };\n}\n"]}
@@ -0,0 +1,14 @@
1
+ import type { BundleInfo } from '../types/BundleInfo.js';
2
+ import type { PackageJsonExports } from '@ms-cloudpack/config-types';
3
+ import type { BundleOutputFile } from '@ms-cloudpack/bundler-types';
4
+ /**
5
+ * Returns a mapping from dependency name to list of paths
6
+ * that are produced and consumed in the searched files.
7
+ */
8
+ export declare function getBundleInfo(params: {
9
+ outputPath: string;
10
+ outputFiles: BundleOutputFile[];
11
+ exportsMap: PackageJsonExports;
12
+ isExternal: boolean;
13
+ }): Promise<BundleInfo>;
14
+ //# sourceMappingURL=getBundleInfo.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"getBundleInfo.d.ts","sourceRoot":"","sources":["../../src/utilities/getBundleInfo.ts"],"names":[],"mappings":"AAUA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,wBAAwB,CAAC;AACzD,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,4BAA4B,CAAC;AACrE,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,6BAA6B,CAAC;AAEpE;;;GAGG;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,CA+OtB"}
@@ -0,0 +1,212 @@
1
+ import { parse } from 'es-module-lexer';
2
+ import fsPromises from 'fs/promises';
3
+ import path from 'path';
4
+ import { parseImportString, parseNamedImports, safeRelativePath, } from '@ms-cloudpack/path-string-parsing';
5
+ import { flattenExportsMap } from '@ms-cloudpack/package-utilities';
6
+ /**
7
+ * Returns a mapping from dependency name to list of paths
8
+ * that are produced and consumed in the searched files.
9
+ */
10
+ export async function getBundleInfo(params) {
11
+ const { outputPath, outputFiles, exportsMap, isExternal } = params;
12
+ const bundleInfo = {
13
+ entry: {},
14
+ };
15
+ // If there are no output files, return the empty bundle info.
16
+ if (!outputFiles.length) {
17
+ return bundleInfo;
18
+ }
19
+ const safeOutputFiles = {};
20
+ outputFiles.forEach((file) => {
21
+ // Make path safe
22
+ const safePath = safeRelativePath(file.outputPath);
23
+ // Store safe path to possible entry path and exports.
24
+ safeOutputFiles[safePath] = {
25
+ entry: safePath,
26
+ produces: new Set(file.exports),
27
+ };
28
+ });
29
+ // raw output file, safe output file, exports entry
30
+ // Get both the unbundled entries from the exports map
31
+ const unbundledExportsMap = flattenExportsMap(exportsMap, {
32
+ conditions: ['browser-esm'],
33
+ requiredConditions: ['browser-esm'],
34
+ });
35
+ const bundledExportsMap = flattenExportsMap(exportsMap);
36
+ const repeatedExports = {};
37
+ // Verify the bundled entries, but prefer unbundled if the entry exists.
38
+ for (const [entryPath, bundledFilePath] of Object.entries(bundledExportsMap)) {
39
+ if (typeof entryPath !== 'string' || typeof bundledFilePath !== 'string') {
40
+ continue;
41
+ }
42
+ const unbundledFilePath = isExternal ? unbundledExportsMap[entryPath] : undefined;
43
+ // TODO: This logic is the same from createImportMap.ts file.
44
+ // It should be moved into a shared function with tests.
45
+ // It is used here to use the same entry paths as the import map.
46
+ let resolvedFilePath = unbundledFilePath || bundledFilePath;
47
+ const ext = path.extname(resolvedFilePath);
48
+ // For bundled files:
49
+ if (!unbundledFilePath) {
50
+ // Ignore .d.ts entries
51
+ if (resolvedFilePath.endsWith('.d.ts')) {
52
+ continue;
53
+ }
54
+ // We always expect responses to come back as javascript (.js extensions.)
55
+ if (ext !== '.js') {
56
+ resolvedFilePath = path.join(path.dirname(resolvedFilePath), path.basename(resolvedFilePath, ext) + (ext === '.mjs' ? '.js' : ext + '.js'));
57
+ }
58
+ resolvedFilePath = resolvedFilePath.replace(/\+/g, '_');
59
+ }
60
+ const safePath = safeRelativePath(resolvedFilePath);
61
+ if (safeOutputFiles[safePath]) {
62
+ if (repeatedExports[safePath]) {
63
+ repeatedExports[safePath].push(entryPath);
64
+ }
65
+ else {
66
+ // Change best guess entry path to exports map entry.
67
+ safeOutputFiles[safePath].entry = entryPath;
68
+ repeatedExports[safePath] = [entryPath];
69
+ }
70
+ }
71
+ }
72
+ const localPathToSafe = {};
73
+ Object.keys(safeOutputFiles).forEach((safePath) => {
74
+ localPathToSafe[path.resolve(outputPath, safePath)] = safePath;
75
+ });
76
+ const filePaths = Object.keys(localPathToSafe);
77
+ const visitedPaths = new Set(filePaths);
78
+ const pathsToParse = [...filePaths];
79
+ while (pathsToParse.length) {
80
+ const filePath = pathsToParse.shift();
81
+ // Ignore any non-JS/TS files such as SVGs and sourcemaps
82
+ if (!filePath || path.extname(filePath) !== '.js') {
83
+ continue;
84
+ }
85
+ const safePath = localPathToSafe[filePath];
86
+ if (safePath === undefined) {
87
+ throw new Error(`Failed to find safe path for ${filePath}`);
88
+ }
89
+ let entry;
90
+ let produces;
91
+ if (!safeOutputFiles[safePath]) {
92
+ entry = safePath;
93
+ produces = new Set();
94
+ }
95
+ else {
96
+ const result = safeOutputFiles[safePath];
97
+ entry = result.entry;
98
+ produces = result.produces;
99
+ }
100
+ let source;
101
+ try {
102
+ source = await fsPromises.readFile(filePath, 'utf-8');
103
+ }
104
+ catch (err) {
105
+ // This could happen if a package is missing a file.
106
+ console.warn(`Failed to read import ${safePath}:`, err);
107
+ continue;
108
+ }
109
+ let rawImports;
110
+ let rawExports;
111
+ try {
112
+ // es-module-lexer/parse may return Promise in some conditions
113
+ // although it is not declared in the type definition
114
+ // https://github.com/guybedford/es-module-lexer/issues/155
115
+ [rawImports, rawExports] = await parse(source);
116
+ }
117
+ catch (err) {
118
+ // This could happen if the source file isn't valid JS
119
+ // (unlikely after adding the check above to only attempt parsing JS/TS files)
120
+ console.warn(`Failed to parse ${filePath}:`, err, '\nSource is:\n', source);
121
+ continue;
122
+ }
123
+ // TODO: Remove when https://github.com/guybedford/es-module-lexer/issues/76 is fixed
124
+ // es-module-lexer doesn't handle export * from statements correctly as it parses them as
125
+ // imports but not as exports. We need to handle them separately.
126
+ let exportStarImport = false;
127
+ const imports = Array.from(new Set(rawImports))
128
+ .map((i) => {
129
+ // The es-module-lexer returns entries where the "n" property equals the import source.
130
+ // This includes the package name and path. For example, in this case:
131
+ //
132
+ // import { Button } from '@fluentui/react/lib/Button';
133
+ //
134
+ // The "n" property would be "@fluentui/react/lib/Button".
135
+ // The "s" and "e" properties represent the start/end character positions of
136
+ // the import source. The "ss" and "se" properties represent the start/end
137
+ // character positions of the import specifier starting with "import". This
138
+ // is useful for parsing the import specifier into its component parts.
139
+ //
140
+ // Currently when the import source is a backtick string, the "n" property
141
+ // is undefined. This is a bug in es-module-lexer. We may need to handle this
142
+ // at the javascript layer and expand it into multiple potential imports.
143
+ if (!i.n) {
144
+ console.debug(`Found an import that didn't parse correctly:\nFilename:\n${filePath}\n\nImport:\n${source.slice(i.s, i.e)}`);
145
+ return undefined;
146
+ }
147
+ // Handling export * from import statements
148
+ if (source.slice(i.ss, i.se).includes('export * from')) {
149
+ exportStarImport = true;
150
+ }
151
+ // Parse the import string into its component parts.
152
+ const namedImports = {
153
+ ...parseImportString(i.n),
154
+ names: new Set(parseNamedImports(source.slice(i.ss, i.se))),
155
+ };
156
+ return namedImports;
157
+ })
158
+ .filter(Boolean);
159
+ // Processing exports is cheap as we already have to parse the source.
160
+ // Helps find exports uncaught by output files.
161
+ rawExports.forEach((i) => {
162
+ if (!i.n) {
163
+ console.debug(`Found an export that didn't parse correctly:\nFilename:\n${filePath}\nExport:\n${source.slice(i.s, i.e)}`);
164
+ return undefined;
165
+ }
166
+ // Exports don't need to be parsed as it is
167
+ // already in the format we need.
168
+ produces.add(i.n);
169
+ });
170
+ if (exportStarImport) {
171
+ produces.add('*');
172
+ }
173
+ bundleInfo.entry[entry] ??= {
174
+ bundlePath: safePath,
175
+ produces: Array.from(produces),
176
+ consumes: [],
177
+ };
178
+ for (const { packageName, importPath, names } of imports) {
179
+ if (packageName?.startsWith('.')) {
180
+ const localPath = path.resolve(path.dirname(filePath), packageName, importPath || '');
181
+ if (!visitedPaths.has(localPath)) {
182
+ visitedPaths.add(localPath);
183
+ pathsToParse.push(localPath);
184
+ localPathToSafe[localPath] = importPath;
185
+ }
186
+ }
187
+ else if (packageName && !packageName.startsWith('node:')) {
188
+ // Find if the import is already in the consumes list.
189
+ const entryIndex = bundleInfo.entry[entry].consumes.findIndex((c) => c.packageName === packageName && c.importPath === importPath);
190
+ if (entryIndex < 0) {
191
+ // If not, add it.
192
+ bundleInfo.entry[entry].consumes.push({ packageName, importPath: importPath || '.', names: [...names] });
193
+ }
194
+ else {
195
+ // If so, add the names to the existing entry.
196
+ // This is necessary because the same import may be used in multiple places.
197
+ bundleInfo.entry[entry].consumes[entryIndex].names = Array.from(new Set([...names, ...bundleInfo.entry[entry].consumes[entryIndex].names]));
198
+ }
199
+ }
200
+ }
201
+ if (repeatedExports[safePath]?.length > 1) {
202
+ // Multiple entries for the same path.
203
+ for (const repeatedEntry of repeatedExports[safePath]) {
204
+ if (repeatedEntry !== entry) {
205
+ bundleInfo.entry[repeatedEntry] = bundleInfo.entry[entry];
206
+ }
207
+ }
208
+ }
209
+ }
210
+ return bundleInfo;
211
+ }
212
+ //# sourceMappingURL=getBundleInfo.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"getBundleInfo.js","sourceRoot":"","sources":["../../src/utilities/getBundleInfo.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,iBAAiB,CAAC;AACxC,OAAO,UAAU,MAAM,aAAa,CAAC;AACrC,OAAO,IAAI,MAAM,MAAM,CAAC;AACxB,OAAO,EACL,iBAAiB,EACjB,iBAAiB,EAEjB,gBAAgB,GACjB,MAAM,mCAAmC,CAAC;AAC3C,OAAO,EAAE,iBAAiB,EAAE,MAAM,iCAAiC,CAAC;AAKpE;;;GAGG;AACH,MAAM,CAAC,KAAK,UAAU,aAAa,CAAC,MAKnC;IACC,MAAM,EAAE,UAAU,EAAE,WAAW,EAAE,UAAU,EAAE,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AC;AACpB,CAAC","sourcesContent":["import { parse } from 'es-module-lexer';\nimport fsPromises from 'fs/promises';\nimport path from 'path';\nimport {\n parseImportString,\n parseNamedImports,\n type ImportStringResult,\n safeRelativePath,\n} from '@ms-cloudpack/path-string-parsing';\nimport { flattenExportsMap } from '@ms-cloudpack/package-utilities';\nimport type { BundleInfo } from '../types/BundleInfo.js';\nimport type { PackageJsonExports } from '@ms-cloudpack/config-types';\nimport type { BundleOutputFile } from '@ms-cloudpack/bundler-types';\n\n/**\n * Returns a mapping from dependency name to list of paths\n * 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 const safeOutputFiles: Record<string, { entry: string; produces: Set<string> }> = {};\n outputFiles.forEach((file) => {\n // Make path safe\n const safePath = safeRelativePath(file.outputPath);\n // Store safe path to possible entry path and exports.\n safeOutputFiles[safePath] = {\n entry: safePath,\n produces: new Set<string>(file.exports),\n };\n });\n\n // raw output file, safe output file, exports entry\n\n // Get both the unbundled 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 const unbundledFilePath = isExternal ? unbundledExportsMap[entryPath] : undefined;\n\n // TODO: This logic is the same from createImportMap.ts file.\n // It should be moved into a shared function with tests.\n // It is used here to use the same entry paths as the import map.\n let resolvedFilePath = unbundledFilePath || bundledFilePath;\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 continue;\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 resolvedFilePath = resolvedFilePath.replace(/\\+/g, '_');\n }\n\n const safePath = safeRelativePath(resolvedFilePath);\n\n if (safeOutputFiles[safePath]) {\n if (repeatedExports[safePath]) {\n repeatedExports[safePath].push(entryPath);\n } else {\n // Change best guess entry path to exports map entry.\n safeOutputFiles[safePath].entry = entryPath;\n repeatedExports[safePath] = [entryPath];\n }\n }\n }\n\n const localPathToSafe: Record<string, string> = {};\n Object.keys(safeOutputFiles).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: string[] = [...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\n if (safePath === undefined) {\n throw new Error(`Failed to find safe path for ${filePath}`);\n }\n\n let entry: string;\n let produces: Set<string>;\n if (!safeOutputFiles[safePath]) {\n entry = safePath;\n produces = new Set();\n } else {\n const result = safeOutputFiles[safePath];\n entry = result.entry;\n produces = result.produces;\n }\n\n let source: string;\n try {\n source = await fsPromises.readFile(filePath, 'utf-8');\n } catch (err) {\n // This could happen if a package is missing a file.\n console.warn(`Failed to read import ${safePath}:`, err);\n continue;\n }\n let rawImports: ReturnType<typeof parse>[0];\n let rawExports: ReturnType<typeof parse>[1];\n try {\n // es-module-lexer/parse may return Promise in some conditions\n // although it is not declared in the type definition\n // https://github.com/guybedford/es-module-lexer/issues/155\n [rawImports, rawExports] = await (parse(source) as unknown as Promise<ReturnType<typeof parse>>);\n } catch (err) {\n // This could happen if the source file isn't valid JS\n // (unlikely after adding the check above to only attempt parsing JS/TS files)\n console.warn(`Failed to parse ${filePath}:`, err, '\\nSource is:\\n', source);\n continue;\n }\n\n // TODO: Remove when https://github.com/guybedford/es-module-lexer/issues/76 is fixed\n // es-module-lexer doesn't handle export * from statements correctly as it parses them as\n // imports but not as exports. We need to handle them separately.\n let exportStarImport = false;\n\n const imports = Array.from(new Set(rawImports))\n .map((i) => {\n // The es-module-lexer returns entries where the \"n\" property equals the import source.\n // This includes the package name and path. For example, in this case:\n //\n // import { Button } from '@fluentui/react/lib/Button';\n //\n // The \"n\" property would be \"@fluentui/react/lib/Button\".\n // The \"s\" and \"e\" properties represent the start/end character positions of\n // the import source. The \"ss\" and \"se\" properties represent the start/end\n // character positions of the import specifier starting with \"import\". This\n // is useful for parsing the import specifier into its component parts.\n //\n // Currently when the import source is a backtick string, the \"n\" property\n // is undefined. This is a bug in es-module-lexer. We may need to handle this\n // at the javascript layer and expand it into multiple potential imports.\n if (!i.n) {\n console.debug(\n `Found an import that didn't parse correctly:\\nFilename:\\n${filePath}\\n\\nImport:\\n${source.slice(\n i.s,\n i.e,\n )}`,\n );\n return undefined;\n }\n\n // Handling export * from import statements\n if (source.slice(i.ss, i.se).includes('export * from')) {\n exportStarImport = true;\n }\n\n // Parse the import string into its component parts.\n const namedImports = {\n ...parseImportString(i.n),\n names: new Set<string>(parseNamedImports(source.slice(i.ss, i.se))),\n };\n\n return namedImports;\n })\n .filter(Boolean) as ImportStringResult[] & { names: Set<string> }[];\n\n // Processing exports is cheap as we already have to parse the source.\n // Helps find exports uncaught by output files.\n rawExports.forEach((i) => {\n if (!i.n) {\n console.debug(\n `Found an export that didn't parse correctly:\\nFilename:\\n${filePath}\\nExport:\\n${source.slice(i.s, i.e)}`,\n );\n return undefined;\n }\n\n // Exports don't need to be parsed as it is\n // already in the format we need.\n produces.add(i.n);\n });\n\n if (exportStarImport) {\n produces.add('*');\n }\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"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ms-cloudpack/api-server",
3
- "version": "0.28.3",
3
+ "version": "0.29.0",
4
4
  "description": "An implementation of the API server that does interacts with a task scheduler.",
5
5
  "license": "MIT",
6
6
  "type": "module",
@@ -28,18 +28,18 @@
28
28
  "@lage-run/scheduler": "^1.1.9",
29
29
  "@lage-run/target-graph": "^0.8.7",
30
30
  "@lage-run/hasher": "^1.0.5",
31
- "@ms-cloudpack/bundler": "^0.17.10",
32
- "@ms-cloudpack/bundler-types": "^0.23.6",
33
- "@ms-cloudpack/config": "^0.17.10",
34
- "@ms-cloudpack/config-types": "^0.3.1",
35
- "@ms-cloudpack/create-express-app": "^1.3.15",
31
+ "@ms-cloudpack/bundler": "^0.17.11",
32
+ "@ms-cloudpack/bundler-types": "^0.23.7",
33
+ "@ms-cloudpack/config": "^0.17.11",
34
+ "@ms-cloudpack/config-types": "^0.3.2",
35
+ "@ms-cloudpack/create-express-app": "^1.3.16",
36
36
  "@ms-cloudpack/data-bus": "^0.4.2",
37
37
  "@ms-cloudpack/file-watcher": "^0.1.2",
38
38
  "@ms-cloudpack/json-utilities": "^0.1.3",
39
- "@ms-cloudpack/package-hashes": "^0.3.4",
40
- "@ms-cloudpack/package-utilities": "^5.7.4",
41
- "@ms-cloudpack/path-string-parsing": "^1.1.2",
42
- "@ms-cloudpack/path-utilities": "^2.4.1",
39
+ "@ms-cloudpack/package-hashes": "^0.3.5",
40
+ "@ms-cloudpack/package-utilities": "^5.7.5",
41
+ "@ms-cloudpack/path-string-parsing": "^1.1.3",
42
+ "@ms-cloudpack/path-utilities": "^2.4.2",
43
43
  "@ms-cloudpack/task-reporter": "^0.10.2",
44
44
  "@ms-cloudpack/telemetry": "^0.4.4",
45
45
  "@ms-cloudpack/remote-cache": "^0.3.0",
@@ -1,6 +0,0 @@
1
- /**
2
- * Mapping from dependency name to list of paths that are actually imported in the bundled files.
3
- * e.g. `{ '@fluentui/react': [ '.', './lib/Button' ] }`
4
- */
5
- export type DetectedImports = Record<string, string[]>;
6
- //# sourceMappingURL=DetectedImports.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"DetectedImports.d.ts","sourceRoot":"","sources":["../../src/types/DetectedImports.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,MAAM,MAAM,eAAe,GAAG,MAAM,CAAC,MAAM,EAAE,MAAM,EAAE,CAAC,CAAC"}
@@ -1,2 +0,0 @@
1
- export {};
2
- //# sourceMappingURL=DetectedImports.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"DetectedImports.js","sourceRoot":"","sources":["../../src/types/DetectedImports.ts"],"names":[],"mappings":"","sourcesContent":["/**\n * Mapping from dependency name to list of paths that are actually imported in the bundled files.\n * e.g. `{ '@fluentui/react': [ '.', './lib/Button' ] }`\n */\nexport type DetectedImports = Record<string, string[]>;\n"]}
@@ -1,7 +0,0 @@
1
- import type { DetectedImports } from '../types/DetectedImports.js';
2
- /**
3
- * Returns a mapping from dependency name to list of paths that are actually imported in the
4
- * searched files. e.g. `{ '@fluentui/react': [ '.', './lib/Button' ] }`
5
- */
6
- export declare function findImports(filePaths: string[]): Promise<DetectedImports>;
7
- //# sourceMappingURL=findImports.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"findImports.d.ts","sourceRoot":"","sources":["../../src/utilities/findImports.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,6BAA6B,CAAC;AAEnE;;;GAGG;AACH,wBAAsB,WAAW,CAAC,SAAS,EAAE,MAAM,EAAE,GAAG,OAAO,CAAC,eAAe,CAAC,CA6E/E"}
@@ -1,75 +0,0 @@
1
- import { parse } from 'es-module-lexer';
2
- import fsPromises from 'fs/promises';
3
- import path from 'path';
4
- import { parseImportString } from '@ms-cloudpack/path-string-parsing';
5
- /**
6
- * Returns a mapping from dependency name to list of paths that are actually imported in the
7
- * searched files. e.g. `{ '@fluentui/react': [ '.', './lib/Button' ] }`
8
- */
9
- export async function findImports(filePaths) {
10
- const requiredExports = {};
11
- const visitedPaths = new Set(filePaths);
12
- const pathsToParse = [...filePaths];
13
- while (pathsToParse.length) {
14
- const filePath = pathsToParse.shift();
15
- // Ignore any non-JS/TS files such as SVGs and sourcemaps
16
- if (!filePath || path.extname(filePath) !== '.js') {
17
- continue;
18
- }
19
- const source = await fsPromises.readFile(filePath, 'utf-8');
20
- let rawImports;
21
- try {
22
- // es-module-lexer/parse may return Promise in some conditions
23
- // although it is not declared in the type definition
24
- // https://github.com/guybedford/es-module-lexer/issues/155
25
- [rawImports] = await parse(source);
26
- }
27
- catch (err) {
28
- // This could happen if the source file isn't valid JS
29
- // (unlikely after adding the check above to only attempt parsing JS/TS files)
30
- console.warn(`Failed to parse ${filePath}:`, err, '\nSource is:\n', source);
31
- continue;
32
- }
33
- const imports = Array.from(new Set(rawImports))
34
- .map((i) => {
35
- // The es-module-lexer returns entries where the "n" property equals the import source.
36
- // This includes the package name and path. For example, in this case:
37
- //
38
- // import { Button } from '@fluentui/react/lib/Button';
39
- //
40
- // The "n" property would be "@fluentui/react/lib/Button".
41
- // The "s" and "e" properties represent the start/end character positions of
42
- // the import source. The "ss" and "se" properties represent the start/end
43
- // character positions of the import specifier starting with "import". This
44
- // may be useful for determining if the import is sync or async.
45
- //
46
- // Currently when the import source is a backtick string, the "n" property
47
- // is undefined. This is a bug in es-module-lexer. We may need to handle this
48
- // at the javascript layer and expand it into multiple potential imports.
49
- if (!i.n) {
50
- console.debug(`Found an import that didn't parse correctly:\nFilename:\n${filePath}\n\nImport:\n${source.slice(i.s, i.e)}`);
51
- return undefined;
52
- }
53
- return parseImportString(i.n);
54
- })
55
- .filter(Boolean);
56
- for (const { packageName, importPath } of imports) {
57
- if (packageName?.startsWith('.')) {
58
- const localPath = path.resolve(path.dirname(filePath), packageName, importPath || '');
59
- if (!visitedPaths.has(localPath)) {
60
- visitedPaths.add(localPath);
61
- pathsToParse.push(localPath);
62
- }
63
- }
64
- else if (packageName && !packageName.startsWith('node:')) {
65
- requiredExports[packageName] ??= new Set();
66
- requiredExports[packageName].add(importPath || '.');
67
- }
68
- }
69
- }
70
- return Object.entries(requiredExports).reduce((acc, [packageName, importPaths]) => {
71
- acc[packageName] = Array.from(importPaths);
72
- return acc;
73
- }, {});
74
- }
75
- //# sourceMappingURL=findImports.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"findImports.js","sourceRoot":"","sources":["../../src/utilities/findImports.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,iBAAiB,CAAC;AACxC,OAAO,UAAU,MAAM,aAAa,CAAC;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,GAAG,CAAC;IACb,CAAC,EACD,EAA8B,CAC/B,CAAC;AACJ,CAAC","sourcesContent":["import { parse } from 'es-module-lexer';\nimport fsPromises from 'fs/promises';\nimport path from 'path';\nimport { parseImportString, type ImportStringResult } from '@ms-cloudpack/path-string-parsing';\nimport type { DetectedImports } from '../types/DetectedImports.js';\n\n/**\n * Returns a mapping from dependency name to list of paths that are actually imported in the\n * searched files. e.g. `{ '@fluentui/react': [ '.', './lib/Button' ] }`\n */\nexport async function findImports(filePaths: string[]): Promise<DetectedImports> {\n const requiredExports: Record<string, Set<string>> = {};\n const visitedPaths = new Set(filePaths);\n const pathsToParse: string[] = [...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 source = await fsPromises.readFile(filePath, 'utf-8');\n let rawImports: ReturnType<typeof parse>[0];\n try {\n // es-module-lexer/parse may return Promise in some conditions\n // although it is not declared in the type definition\n // https://github.com/guybedford/es-module-lexer/issues/155\n [rawImports] = await (parse(source) as unknown as Promise<ReturnType<typeof parse>>);\n } catch (err) {\n // This could happen if the source file isn't valid JS\n // (unlikely after adding the check above to only attempt parsing JS/TS files)\n console.warn(`Failed to parse ${filePath}:`, err, '\\nSource is:\\n', source);\n continue;\n }\n const imports = Array.from(new Set(rawImports))\n .map((i) => {\n // The es-module-lexer returns entries where the \"n\" property equals the import source.\n // This includes the package name and path. For example, in this case:\n //\n // import { Button } from '@fluentui/react/lib/Button';\n //\n // The \"n\" property would be \"@fluentui/react/lib/Button\".\n // The \"s\" and \"e\" properties represent the start/end character positions of\n // the import source. The \"ss\" and \"se\" properties represent the start/end\n // character positions of the import specifier starting with \"import\". This\n // may be useful for determining if the import is sync or async.\n //\n // Currently when the import source is a backtick string, the \"n\" property\n // is undefined. This is a bug in es-module-lexer. We may need to handle this\n // at the javascript layer and expand it into multiple potential imports.\n if (!i.n) {\n console.debug(\n `Found an import that didn't parse correctly:\\nFilename:\\n${filePath}\\n\\nImport:\\n${source.slice(\n i.s,\n i.e,\n )}`,\n );\n return undefined;\n }\n\n return parseImportString(i.n);\n })\n .filter(Boolean) as ImportStringResult[];\n\n for (const { packageName, importPath } 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 }\n } else if (packageName && !packageName.startsWith('node:')) {\n requiredExports[packageName] ??= new Set();\n requiredExports[packageName].add(importPath || '.');\n }\n }\n }\n\n return Object.entries(requiredExports).reduce(\n (acc, [packageName, importPaths]) => {\n acc[packageName] = Array.from(importPaths);\n return acc;\n },\n {} as Record<string, string[]>,\n );\n}\n"]}