@ms-cloudpack/api-server 0.56.6 → 0.56.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/utilities/addOverride.d.ts.map +1 -1
- package/lib/utilities/addOverride.js +1 -3
- package/lib/utilities/addOverride.js.map +1 -1
- package/lib/utilities/bundleTask.d.ts.map +1 -1
- package/lib/utilities/bundleTask.js +3 -0
- package/lib/utilities/bundleTask.js.map +1 -1
- package/lib/utilities/editCloudpackConfig.d.ts.map +1 -1
- package/lib/utilities/editCloudpackConfig.js +2 -9
- package/lib/utilities/editCloudpackConfig.js.map +1 -1
- package/lib/utilities/getBundleInfo.d.ts +2 -1
- package/lib/utilities/getBundleInfo.d.ts.map +1 -1
- package/lib/utilities/getBundleInfo.js +49 -71
- package/lib/utilities/getBundleInfo.js.map +1 -1
- package/lib/utilities/getImportsAndExports.d.ts +1 -0
- package/lib/utilities/getImportsAndExports.d.ts.map +1 -1
- package/lib/utilities/getImportsAndExports.js +65 -64
- package/lib/utilities/getImportsAndExports.js.map +1 -1
- package/lib/utilities/validateOverride.d.ts.map +1 -1
- package/lib/utilities/validateOverride.js +1 -5
- package/lib/utilities/validateOverride.js.map +1 -1
- package/package.json +11 -11
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"addOverride.d.ts","sourceRoot":"","sources":["../../src/utilities/addOverride.ts"],"names":[],"mappings":"AAEA,OAAO,EAKL,KAAK,eAAe,EACrB,MAAM,iCAAiC,CAAC;AAEzC,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,qBAAqB,CAAC;AACnD,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,6BAA6B,CAAC;AAEnE,KAAK,cAAc,GAAG;IACpB,kDAAkD;IAClD,aAAa,EAAE,OAAO,CAAC;IACvB,sEAAsE;IACtE,KAAK,EAAE,eAAe,GAAG,SAAS,CAAC;CACpC,CAAC;AAaF;;;GAGG;AACH,wBAAsB,WAAW,CAC/B,OAAO,EAAE,eAAe,EACxB,OAAO,EAAE,IAAI,CAAC,OAAO,EAAE,UAAU,GAAG,SAAS,CAAC,GAC7C,OAAO,CAAC,cAAc,CAAC,
|
|
1
|
+
{"version":3,"file":"addOverride.d.ts","sourceRoot":"","sources":["../../src/utilities/addOverride.ts"],"names":[],"mappings":"AAEA,OAAO,EAKL,KAAK,eAAe,EACrB,MAAM,iCAAiC,CAAC;AAEzC,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,qBAAqB,CAAC;AACnD,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,6BAA6B,CAAC;AAEnE,KAAK,cAAc,GAAG;IACpB,kDAAkD;IAClD,aAAa,EAAE,OAAO,CAAC;IACvB,sEAAsE;IACtE,KAAK,EAAE,eAAe,GAAG,SAAS,CAAC;CACpC,CAAC;AAaF;;;GAGG;AACH,wBAAsB,WAAW,CAC/B,OAAO,EAAE,eAAe,EACxB,OAAO,EAAE,IAAI,CAAC,OAAO,EAAE,UAAU,GAAG,SAAS,CAAC,GAC7C,OAAO,CAAC,cAAc,CAAC,CA2GzB"}
|
|
@@ -57,9 +57,7 @@ export async function addOverride(options, context) {
|
|
|
57
57
|
const generatedConfig = await readGeneratedConfig(appPath);
|
|
58
58
|
// Ensure packageSettings exists.
|
|
59
59
|
const generatedPackageSettings = await ensureGeneratedSettingsForPackage({ packagePath }, { config: { generated: generatedConfig }, packages });
|
|
60
|
-
if (generatedPackageSettings?.exports &&
|
|
61
|
-
generatedPackageSettings.exports[normalizedImportPath] ===
|
|
62
|
-
null) {
|
|
60
|
+
if (generatedPackageSettings?.exports && generatedPackageSettings.exports[normalizedImportPath] === null) {
|
|
63
61
|
delete generatedPackageSettings.exports[normalizedImportPath];
|
|
64
62
|
deletedNullExport = true;
|
|
65
63
|
if (Object.keys(generatedPackageSettings.exports).length === 0) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"addOverride.js","sourceRoot":"","sources":["../../src/utilities/addOverride.ts"],"names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IAAI,mCAAmC,CAAC,CAAC;gBAC1F,IAAI,MAAM,KAAK,SAAS,EAAE,CAAC;oBACzB,OAAO,CAAC,GAAG,CAAC,4DAA4D,CAAC,CAAC;gBAC5E,CAAC;YACH,CAAC;iBAAM,IAAI,MAAM,KAAK,SAAS,EAAE,CAAC;gBAChC,OAAO,CAAC,GAAG,CAAC,sBAAsB,IAAI,iCAAiC,CAAC,CAAC;YAC3E,CAAC;QACH,CAAC;QAED,0EAA0E;QAC1E,MAAM,QAAQ,CAAC,GAAG,CAAC,WAAW,EAAE,EAAE,OAAO,EAAE,IAAI,EAAE,CAAC,CAAC;QAEnD,OAAO,EAAE,aAAa,EAAE,KAAK,EAAE,CAAC;IAClC,CAAC,CAAC,CAAC;IAEH,OAAO,iBAAiB,CAAC;AAC3B,CAAC","sourcesContent":["import { ensureGeneratedSettingsForPackage, readGeneratedConfig, writeGeneratedConfig } from '@ms-cloudpack/config';\nimport { parseRequestInfo } from '@ms-cloudpack/import-map';\nimport {\n addExportsMapEntry,\n findResolveMapEntry,\n flattenExportsMap,\n getExportsMap,\n type ResolveMapEntry,\n} from '@ms-cloudpack/package-utilities';\nimport { makeUrl, normalizeRelativePath } from '@ms-cloudpack/path-string-parsing';\nimport type { Context } from '../types/Context.js';\nimport type { OverrideOptions } from '../types/OverrideOptions.js';\n\ntype OverrideReturn = {\n /** Whether the override was successfully added */\n addedOverride: boolean;\n /** The entry (if any) in the resolve map the override was added to */\n entry: ResolveMapEntry | undefined;\n};\n\n/**\n * Helper so that when addOverride is called multiple times in quick succession, we only process one at a time.\n * This is to avoid that multiple calls of addOverride first read the same version of the generated config,\n * then write the same version of the config with its corresponding update,\n * which would result in the last call overwriting the changes of the previous calls.\n */\nlet overrideInProcess: Promise<OverrideReturn> = Promise.resolve({\n addedOverride: false,\n entry: undefined,\n});\n\n/**\n * The addOverride method is triggered by a user action in the overlay, when we detect new usage of an import path\n * that isn't recognized. When the user triggers this override, we write it to the cloudpack generated config.\n */\nexport async function addOverride(\n options: OverrideOptions,\n context: Pick<Context, 'packages' | 'session'>,\n): Promise<OverrideReturn> {\n overrideInProcess = overrideInProcess.then(async () => {\n const { packageName, importPath, version, issuerUrl } = options;\n const { session, packages } = context;\n const { appPath } = session.config;\n let addedOverride = false;\n let deletedNullExport = false;\n let requiredBy = undefined;\n\n if (importPath.endsWith('/')) {\n console.error(`The import path \"${importPath}\" is invalid. Please remove the trailing slash and try again.`);\n return { addedOverride, entry: undefined };\n }\n\n if (issuerUrl) {\n const { packageName: issuerName, version: issuerVersion } = parseRequestInfo(makeUrl(issuerUrl).pathname);\n requiredBy = { name: issuerName, version: issuerVersion };\n }\n\n const entry = findResolveMapEntry({\n packageName,\n resolveMap: session.resolveMap,\n definition: requiredBy,\n version,\n });\n\n if (!entry) {\n console.error(`Could not find entry of package \"${packageName}\" in resolve map`);\n return { addedOverride, entry };\n }\n\n const packagePath = entry.path;\n\n // Get current exports. We want to add an additional entry to what's there - not replace the default exports,\n // so we need the full map for the package.\n const exports = await getExportsMap({ packagePath }, { packages, config: session.config });\n const flattenedExports = flattenExportsMap(exports);\n const normalizedImportPath = normalizeRelativePath(importPath);\n\n // Return false if the import path already exists in the exports map.\n if (flattenedExports[normalizedImportPath]) {\n console.debug(`The import path \"${importPath}\" already exists in the exports map for \"${packageName}\".`);\n return { addedOverride, entry };\n }\n\n // Parse the generated config if it exists.\n const generatedConfig = await readGeneratedConfig(appPath);\n\n // Ensure packageSettings exists.\n const generatedPackageSettings = await ensureGeneratedSettingsForPackage(\n { packagePath },\n { config: { generated: generatedConfig }, packages },\n );\n\n if (generatedPackageSettings?.exports && generatedPackageSettings.exports[normalizedImportPath] === null) {\n delete generatedPackageSettings.exports[normalizedImportPath];\n deletedNullExport = true;\n\n if (Object.keys(generatedPackageSettings.exports).length === 0) {\n delete generatedPackageSettings.exports;\n }\n addedOverride = true;\n } else {\n const generatedExports = (generatedPackageSettings.exports ??= {});\n\n // Add the single new exports entry to the exports map.\n addedOverride = await addExportsMapEntry(\n {\n exports: generatedExports,\n packagePath,\n importPath,\n },\n { packages, config: session.config },\n );\n\n if (!addedOverride) {\n console.warn(\n `Unable to add override for package \"${packageName}\" to \"cloudpack.generated.json\".` +\n ` The file \"${normalizedImportPath}\" could not be found.` +\n ` Please check the import path and try again.`,\n );\n return { addedOverride, entry };\n }\n }\n\n // Write the updated generated config\n session.config.generated = generatedConfig;\n const result = await writeGeneratedConfig(generatedConfig, appPath);\n const desc = `\"${packageName}\" (path \"${normalizedImportPath}\")`;\n if (result !== 'no-op') {\n if (deletedNullExport) {\n console.log(`Removed generated null export for ${desc} from \"cloudpack.generated.json\".`);\n if (result === 'deleted') {\n console.log(`Deleted \"cloudpack.generated.json\" because it's now empty.`);\n }\n } else if (result === 'written') {\n console.log(`Added override for ${desc} to \"cloudpack.generated.json\".`);\n }\n }\n\n // Apply the generated exports again to ensure the exports are up to date.\n await packages.get(packagePath, { refresh: true });\n\n return { addedOverride, entry };\n });\n\n return overrideInProcess;\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"bundleTask.d.ts","sourceRoot":"","sources":["../../src/utilities/bundleTask.ts"],"names":[],"mappings":"AAOA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,2BAA2B,CAAC;AAC/D,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,+BAA+B,CAAC;AAOvE,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AAE1D,MAAM,MAAM,yBAAyB,GAAG,iBAAiB,GAAG;IAAE,aAAa,EAAE,aAAa,CAAA;CAAE,CAAC;AAC7F,MAAM,MAAM,yBAAyB,GAAG,cAAc,CACpD,UAAU,GAAG,eAAe,GAAG,UAAU,GAAG,iBAAiB,EAC7D,YAAY,GAAG,QAAQ,GAAG,UAAU,GAAG,WAAW,CACnD,CAAC;AAEF;;GAEG;AACH,wBAAsB,UAAU,CAC9B,OAAO,EAAE,yBAAyB,EAClC,OAAO,EAAE,yBAAyB,GACjC,OAAO,CAAC,IAAI,CAAC,
|
|
1
|
+
{"version":3,"file":"bundleTask.d.ts","sourceRoot":"","sources":["../../src/utilities/bundleTask.ts"],"names":[],"mappings":"AAOA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,2BAA2B,CAAC;AAC/D,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,+BAA+B,CAAC;AAOvE,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AAE1D,MAAM,MAAM,yBAAyB,GAAG,iBAAiB,GAAG;IAAE,aAAa,EAAE,aAAa,CAAA;CAAE,CAAC;AAC7F,MAAM,MAAM,yBAAyB,GAAG,cAAc,CACpD,UAAU,GAAG,eAAe,GAAG,UAAU,GAAG,iBAAiB,EAC7D,YAAY,GAAG,QAAQ,GAAG,UAAU,GAAG,WAAW,CACnD,CAAC;AAEF;;GAEG;AACH,wBAAsB,UAAU,CAC9B,OAAO,EAAE,yBAAyB,EAClC,OAAO,EAAE,yBAAyB,GACjC,OAAO,CAAC,IAAI,CAAC,CAoIf"}
|
|
@@ -78,6 +78,9 @@ export async function bundleTask(options, context) {
|
|
|
78
78
|
bundlerCapabilities,
|
|
79
79
|
};
|
|
80
80
|
const bundleInternalResult = await bundle(bundleOptions, { config });
|
|
81
|
+
if (bundleInternalResult.bundler) {
|
|
82
|
+
span.setAttribute('bundler', bundleInternalResult.bundler);
|
|
83
|
+
}
|
|
81
84
|
bundleRequest.result = {
|
|
82
85
|
...bundleInternalResult,
|
|
83
86
|
outputPath: bundleOptions.outputPath ?? outputPath,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"bundleTask.js","sourceRoot":"","sources":["../../src/utilities/bundleTask.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,wBAAwB,EAAE,uBAAuB,EAAE,MAAM,uBAAuB,CAAC;AAElG,OAAO,EAAE,SAAS,EAAE,MAAM,8BAA8B,CAAC;AACzD,OAAO,EAAE,aAAa,E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CAAC;AACL,CAAC","sourcesContent":["import { bundle, getEntriesMapFromPackage, getExternalsFromPackage } from '@ms-cloudpack/bundler';\nimport type { BundleOptions } from '@ms-cloudpack/common-types';\nimport { writeJson } from '@ms-cloudpack/json-utilities';\nimport { getExportsMap } from '@ms-cloudpack/package-utilities';\nimport { formatPackageName } from '@ms-cloudpack/task-reporter';\nimport path from 'path';\nimport { prepareOutputPath } from '../common/prepareOutputPath.js';\nimport type { BundleRequest } from '../types/BundleRequest.js';\nimport type { BundleTaskOptions } from '../types/BundleTaskOptions.js';\nimport { getBundleInfo } from './getBundleInfo.js';\nimport { getBundleLocation } from './getBundleLocation.js';\nimport { isCachedResultValid } from './isCachedResultValid.js';\nimport { readResultFromCache } from './readResultFromCache.js';\nimport { saveResultToCache } from './saveResultToCache.js';\nimport { formatBundleTaskResult } from './formatBundleTaskResult.js';\nimport type { PartialContext } from '../types/Context.js';\n\nexport type BundleTaskInternalOptions = BundleTaskOptions & { bundleRequest: BundleRequest };\nexport type BundleTaskInternalContext = PartialContext<\n 'packages' | 'packageHashes' | 'reporter' | 'telemetryClient',\n 'resolveMap' | 'config' | 'sequence' | 'cachePath'\n>;\n\n/**\n * Create and run a TaskReporter task which calls `bundle()` from `@ms-cloudpack/bundler` and formats the result.\n */\nexport async function bundleTask(\n options: BundleTaskInternalOptions,\n context: BundleTaskInternalContext,\n): Promise<void> {\n const { bundleRequest, force, hash, sourceHash } = options;\n const { packageName, version } = bundleRequest;\n const { reporter, telemetryClient, packageHashes, packages, session } = context;\n const { config, sequence } = session;\n const { mode } = config;\n const { retryCount } = options;\n\n const taskName = `Bundle ${formatPackageName({\n name: packageName,\n version,\n })}${retryCount ? ` (retry ${retryCount})` : ''}`;\n\n await reporter.runTask(taskName, async () => {\n await telemetryClient.tracer.startActiveSpan('BUNDLE_TASK', async (span) => {\n // If force is set, dispose the existing result.\n if (force && bundleRequest?.result?.dispose) {\n bundleRequest.result.dispose();\n bundleRequest.result = undefined;\n }\n\n const { packagePath, isExternal, isIncremental, disableSourceMaps, shouldGetBundleInfo } = bundleRequest;\n\n const outputPath =\n bundleRequest.outputPath ??\n (await getBundleLocation({ packagePath, shouldRecalculate: force, hash }, context)).path;\n\n // Rehydrate the result if not incremental.\n if (bundleRequest.result === undefined && !force) {\n bundleRequest.result = await readResultFromCache(outputPath, {\n inputPath: packagePath,\n });\n }\n\n const cacheValidationHash = !isExternal\n ? sourceHash ||\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: cacheValidationHash })) {\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: cacheValidationHash,\n };\n } else {\n const {\n bundler,\n bundlerOptions,\n inlinedDependencies,\n dynamicImports,\n bundlerCapabilities,\n ignoredBundlerWarnings,\n } = (await packages.get(packagePath)).cloudpack || {};\n\n const bundleOptions: BundleOptions = {\n bundler,\n minify: mode === 'production',\n bundlerOptions,\n inputPath: packagePath,\n outputPath,\n incremental: isIncremental !== undefined ? isIncremental : false,\n sourcemap: !disableSourceMaps,\n entries: await getEntriesMapFromPackage({ inputPath: packagePath }, { packages, config }),\n inlined: inlinedDependencies,\n external: await getExternalsFromPackage({ inputPath: packagePath }, { packages }),\n dynamicImports,\n ignoredBundlerWarnings,\n bundlerCapabilities,\n };\n\n const bundleInternalResult = await bundle(bundleOptions, { config });\n bundleRequest.result = {\n ...bundleInternalResult,\n outputPath: bundleOptions.outputPath ?? outputPath,\n hash: cacheValidationHash,\n };\n }\n\n // Write the result to disk.\n await saveResultToCache(bundleRequest.result);\n }\n\n // If we should find required imports and exports per bundle\n if (shouldGetBundleInfo && !bundleRequest.result?.errors?.length && bundleRequest.result?.outputFiles?.length) {\n const bundleInfoPath = path.join(outputPath, 'bundle-info.json');\n\n // Exports map is needed to find the bundle info per entry we intend to bundle.\n // Exports map is used instead of bundleRequest.entries since it is easier to use\n // because it contains the paths other packages use to import the entry and\n // the relative location of the bundled files.\n const exportsMap = await getExportsMap({ packagePath }, { packages, config });\n\n const bundleInfo = await getBundleInfo({\n outputPath,\n outputFiles: bundleRequest.result.outputFiles,\n exportsMap,\n isExternal,\n packagePath,\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 span.setAttributes({\n sequence,\n isCacheHit: !!bundleRequest.resultFromCache,\n isExternal: bundleRequest.isExternal,\n });\n\n const taskResult = formatBundleTaskResult(bundleRequest);\n\n return taskResult;\n });\n });\n}\n"]}
|
|
1
|
+
{"version":3,"file":"bundleTask.js","sourceRoot":"","sources":["../../src/utilities/bundleTask.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,wBAAwB,EAAE,uBAAuB,EAAE,MAAM,uBAAuB,CAAC;AAElG,OAAO,EAAE,SAAS,EAAE,MAAM,8BAA8B,CAAC;AACzD,OAAO,EAAE,aAAa,EAAE,MAAM,iCAAiC,CAAC;AAChE,OAAO,EAAE,iBAAiB,EAAE,MAAM,6BAA6B,CAAC;AAChE,OAAO,IAAI,MAAM,MAAM,CAAC;AACxB,OAAO,EAAE,iBAAiB,EAAE,MAAM,gCAAgC,CAAC;AAGnE,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AACnD,OAAO,EAAE,iBAAiB,EAAE,MAAM,wBAAwB,CAAC;AAC3D,OAAO,EAAE,mBAAmB,EAAE,MAAM,0BAA0B,CAAC;AAC/D,OAAO,EAAE,mBAAmB,EAAE,MAAM,0BAA0B,CAAC;AAC/D,OAAO,E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AI,mBAAmB,IAAI,CAAC,aAAa,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,IAAI,aAAa,CAAC,MAAM,EAAE,WAAW,EAAE,MAAM,EAAE,CAAC;gBAC9G,MAAM,cAAc,GAAG,IAAI,CAAC,IAAI,CAAC,UAAU,EAAE,kBAAkB,CAAC,CAAC;gBAEjE,+EAA+E;gBAC/E,iFAAiF;gBACjF,2EAA2E;gBAC3E,8CAA8C;gBAC9C,MAAM,UAAU,GAAG,MAAM,aAAa,CAAC,EAAE,WAAW,EAAE,EAAE,EAAE,QAAQ,EAAE,MAAM,EAAE,CAAC,CAAC;gBAE9E,MAAM,UAAU,GAAG,MAAM,aAAa,CAAC;oBACrC,UAAU;oBACV,WAAW,EAAE,aAAa,CAAC,MAAM,CAAC,WAAW;oBAC7C,UAAU;oBACV,UAAU;oBACV,WAAW;iBACZ,CAAC,CAAC;gBAEH,aAAa,CAAC,MAAM,CAAC,IAAI,GAAG,UAAU,CAAC;gBAEvC,8DAA8D;gBAC9D,mEAAmE;gBACnE,SAAS,CAAC,cAAc,EAAE,UAAU,CAAC,CAAC;YACxC,CAAC;YAED,IAAI,CAAC,aAAa,CAAC;gBACjB,QAAQ;gBACR,UAAU,EAAE,CAAC,CAAC,aAAa,CAAC,eAAe;gBAC3C,UAAU,EAAE,aAAa,CAAC,UAAU;aACrC,CAAC,CAAC;YAEH,MAAM,UAAU,GAAG,sBAAsB,CAAC,aAAa,CAAC,CAAC;YAEzD,OAAO,UAAU,CAAC;QACpB,CAAC,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;AACL,CAAC","sourcesContent":["import { bundle, getEntriesMapFromPackage, getExternalsFromPackage } from '@ms-cloudpack/bundler';\nimport type { BundleOptions } from '@ms-cloudpack/common-types';\nimport { writeJson } from '@ms-cloudpack/json-utilities';\nimport { getExportsMap } from '@ms-cloudpack/package-utilities';\nimport { formatPackageName } from '@ms-cloudpack/task-reporter';\nimport path from 'path';\nimport { prepareOutputPath } from '../common/prepareOutputPath.js';\nimport type { BundleRequest } from '../types/BundleRequest.js';\nimport type { BundleTaskOptions } from '../types/BundleTaskOptions.js';\nimport { getBundleInfo } from './getBundleInfo.js';\nimport { getBundleLocation } from './getBundleLocation.js';\nimport { isCachedResultValid } from './isCachedResultValid.js';\nimport { readResultFromCache } from './readResultFromCache.js';\nimport { saveResultToCache } from './saveResultToCache.js';\nimport { formatBundleTaskResult } from './formatBundleTaskResult.js';\nimport type { PartialContext } from '../types/Context.js';\n\nexport type BundleTaskInternalOptions = BundleTaskOptions & { bundleRequest: BundleRequest };\nexport type BundleTaskInternalContext = PartialContext<\n 'packages' | 'packageHashes' | 'reporter' | 'telemetryClient',\n 'resolveMap' | 'config' | 'sequence' | 'cachePath'\n>;\n\n/**\n * Create and run a TaskReporter task which calls `bundle()` from `@ms-cloudpack/bundler` and formats the result.\n */\nexport async function bundleTask(\n options: BundleTaskInternalOptions,\n context: BundleTaskInternalContext,\n): Promise<void> {\n const { bundleRequest, force, hash, sourceHash } = options;\n const { packageName, version } = bundleRequest;\n const { reporter, telemetryClient, packageHashes, packages, session } = context;\n const { config, sequence } = session;\n const { mode } = config;\n const { retryCount } = options;\n\n const taskName = `Bundle ${formatPackageName({\n name: packageName,\n version,\n })}${retryCount ? ` (retry ${retryCount})` : ''}`;\n\n await reporter.runTask(taskName, async () => {\n await telemetryClient.tracer.startActiveSpan('BUNDLE_TASK', async (span) => {\n // If force is set, dispose the existing result.\n if (force && bundleRequest?.result?.dispose) {\n bundleRequest.result.dispose();\n bundleRequest.result = undefined;\n }\n\n const { packagePath, isExternal, isIncremental, disableSourceMaps, shouldGetBundleInfo } = bundleRequest;\n\n const outputPath =\n bundleRequest.outputPath ??\n (await getBundleLocation({ packagePath, shouldRecalculate: force, hash }, context)).path;\n\n // Rehydrate the result if not incremental.\n if (bundleRequest.result === undefined && !force) {\n bundleRequest.result = await readResultFromCache(outputPath, {\n inputPath: packagePath,\n });\n }\n\n const cacheValidationHash = !isExternal\n ? sourceHash ||\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: cacheValidationHash })) {\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: cacheValidationHash,\n };\n } else {\n const {\n bundler,\n bundlerOptions,\n inlinedDependencies,\n dynamicImports,\n bundlerCapabilities,\n ignoredBundlerWarnings,\n } = (await packages.get(packagePath)).cloudpack || {};\n\n const bundleOptions: BundleOptions = {\n bundler,\n minify: mode === 'production',\n bundlerOptions,\n inputPath: packagePath,\n outputPath,\n incremental: isIncremental !== undefined ? isIncremental : false,\n sourcemap: !disableSourceMaps,\n entries: await getEntriesMapFromPackage({ inputPath: packagePath }, { packages, config }),\n inlined: inlinedDependencies,\n external: await getExternalsFromPackage({ inputPath: packagePath }, { packages }),\n dynamicImports,\n ignoredBundlerWarnings,\n bundlerCapabilities,\n };\n\n const bundleInternalResult = await bundle(bundleOptions, { config });\n if (bundleInternalResult.bundler) {\n span.setAttribute('bundler', bundleInternalResult.bundler);\n }\n bundleRequest.result = {\n ...bundleInternalResult,\n outputPath: bundleOptions.outputPath ?? outputPath,\n hash: cacheValidationHash,\n };\n }\n\n // Write the result to disk.\n await saveResultToCache(bundleRequest.result);\n }\n\n // If we should find required imports and exports per bundle\n if (shouldGetBundleInfo && !bundleRequest.result?.errors?.length && bundleRequest.result?.outputFiles?.length) {\n const bundleInfoPath = path.join(outputPath, 'bundle-info.json');\n\n // Exports map is needed to find the bundle info per entry we intend to bundle.\n // Exports map is used instead of bundleRequest.entries since it is easier to use\n // because it contains the paths other packages use to import the entry and\n // the relative location of the bundled files.\n const exportsMap = await getExportsMap({ packagePath }, { packages, config });\n\n const bundleInfo = await getBundleInfo({\n outputPath,\n outputFiles: bundleRequest.result.outputFiles,\n exportsMap,\n isExternal,\n packagePath,\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 span.setAttributes({\n sequence,\n isCacheHit: !!bundleRequest.resultFromCache,\n isExternal: bundleRequest.isExternal,\n });\n\n const taskResult = formatBundleTaskResult(bundleRequest);\n\n return taskResult;\n });\n });\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"editCloudpackConfig.d.ts","sourceRoot":"","sources":["../../src/utilities/editCloudpackConfig.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"editCloudpackConfig.d.ts","sourceRoot":"","sources":["../../src/utilities/editCloudpackConfig.ts"],"names":[],"mappings":"AAGA;;GAEG;AACH,wBAAsB,mBAAmB,CAAC,GAAG,EAAE,MAAM,iBAIpD"}
|
|
@@ -1,17 +1,10 @@
|
|
|
1
|
-
import { writeJson } from '@ms-cloudpack/json-utilities';
|
|
2
|
-
import { isFile } from '@ms-cloudpack/path-utilities';
|
|
3
1
|
import { execSync } from 'child_process';
|
|
4
|
-
import {
|
|
2
|
+
import { ensureAppConfig } from '@ms-cloudpack/config';
|
|
5
3
|
/**
|
|
6
4
|
* Opens the cloudpack config file in the editor.
|
|
7
5
|
*/
|
|
8
6
|
export async function editCloudpackConfig(cwd) {
|
|
9
|
-
const
|
|
10
|
-
// Check if file exists
|
|
11
|
-
if (!(await isFile(appConfigPath))) {
|
|
12
|
-
// Create file with default config
|
|
13
|
-
await writeJson(appConfigPath, configTemplate);
|
|
14
|
-
}
|
|
7
|
+
const appConfigPath = await ensureAppConfig(cwd);
|
|
15
8
|
execSync(`code --goto ${JSON.stringify(appConfigPath)}`, { cwd });
|
|
16
9
|
}
|
|
17
10
|
//# sourceMappingURL=editCloudpackConfig.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"editCloudpackConfig.js","sourceRoot":"","sources":["../../src/utilities/editCloudpackConfig.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"editCloudpackConfig.js","sourceRoot":"","sources":["../../src/utilities/editCloudpackConfig.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AACzC,OAAO,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAC;AAEvD;;GAEG;AACH,MAAM,CAAC,KAAK,UAAU,mBAAmB,CAAC,GAAW;IACnD,MAAM,aAAa,GAAG,MAAM,eAAe,CAAC,GAAG,CAAC,CAAC;IAEjD,QAAQ,CAAC,eAAe,IAAI,CAAC,SAAS,CAAC,aAAa,CAAC,EAAE,EAAE,EAAE,GAAG,EAAE,CAAC,CAAC;AACpE,CAAC","sourcesContent":["import { execSync } from 'child_process';\nimport { ensureAppConfig } from '@ms-cloudpack/config';\n\n/**\n * Opens the cloudpack config file in the editor.\n */\nexport async function editCloudpackConfig(cwd: string) {\n const appConfigPath = await ensureAppConfig(cwd);\n\n execSync(`code --goto ${JSON.stringify(appConfigPath)}`, { cwd });\n}\n"]}
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import type { BundleOutputFile, PackageJsonExports } from '@ms-cloudpack/common-types';
|
|
2
2
|
import type { BundleInfo } from '../types/BundleInfo.js';
|
|
3
3
|
/**
|
|
4
|
-
* Returns a mapping from entry file path to list of paths that are produced
|
|
4
|
+
* Returns a mapping from entry file path (exports map key) to list of paths that are produced
|
|
5
|
+
* and consumed in that file.
|
|
5
6
|
*/
|
|
6
7
|
export declare function getBundleInfo(params: {
|
|
7
8
|
packagePath: string;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getBundleInfo.d.ts","sourceRoot":"","sources":["../../src/utilities/getBundleInfo.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,kBAAkB,EAAE,MAAM,4BAA4B,CAAC;AAIvF,OAAO,KAAK,
|
|
1
|
+
{"version":3,"file":"getBundleInfo.d.ts","sourceRoot":"","sources":["../../src/utilities/getBundleInfo.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,kBAAkB,EAAE,MAAM,4BAA4B,CAAC;AAIvF,OAAO,KAAK,EAAmB,UAAU,EAAE,MAAM,wBAAwB,CAAC;AAG1E;;;GAGG;AACH,wBAAsB,aAAa,CAAC,MAAM,EAAE;IAC1C,WAAW,EAAE,MAAM,CAAC;IACpB,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+FtB"}
|
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import { getRuntimeEntryPaths } from '@ms-cloudpack/import-map';
|
|
2
|
-
import {
|
|
2
|
+
import { normalizedPathRelativeTo } from '@ms-cloudpack/path-utilities';
|
|
3
3
|
import path from 'path';
|
|
4
4
|
import { getImportsAndExports } from './getImportsAndExports.js';
|
|
5
5
|
/**
|
|
6
|
-
* Returns a mapping from entry file path to list of paths that are produced
|
|
6
|
+
* Returns a mapping from entry file path (exports map key) to list of paths that are produced
|
|
7
|
+
* and consumed in that file.
|
|
7
8
|
*/
|
|
8
9
|
export async function getBundleInfo(params) {
|
|
9
10
|
const { packagePath, outputPath, outputFiles, exportsMap, isExternal } = params;
|
|
@@ -12,97 +13,74 @@ export async function getBundleInfo(params) {
|
|
|
12
13
|
if (!outputFiles.length) {
|
|
13
14
|
return bundleInfo;
|
|
14
15
|
}
|
|
15
|
-
/** Mapping from output file
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
const safePath = normalizeRelativePath(actualEntryPath);
|
|
30
|
-
if (outputFileInfo[safePath]) {
|
|
31
|
-
if (repeatedExports[safePath]) {
|
|
32
|
-
repeatedExports[safePath].push(importPath);
|
|
33
|
-
}
|
|
34
|
-
else {
|
|
35
|
-
// Change best guess entry path to exports map entry.
|
|
36
|
-
outputFileInfo[safePath].entry = importPath;
|
|
37
|
-
repeatedExports[safePath] = [importPath];
|
|
38
|
-
}
|
|
39
|
-
}
|
|
16
|
+
/** Mapping from normalized relative output file path to info about which entry paths
|
|
17
|
+
* (exports map keys) pointed to that file, and what export names it produces.
|
|
18
|
+
* Usually there's at most one entry path per output file. */
|
|
19
|
+
const outputFileInfo = Object.fromEntries(outputFiles.map((file) => [
|
|
20
|
+
file.outputPath,
|
|
21
|
+
{ exportsKeys: [], produces: new Set(file.exports) },
|
|
22
|
+
]));
|
|
23
|
+
// For each entry path (exports map key), get the normalized relative path to the output file
|
|
24
|
+
// that will be used at runtime based on conditions.
|
|
25
|
+
const entryToOutputFile = getRuntimeEntryPaths({ packagePath, isExternal, exportsMap });
|
|
26
|
+
// Update the output file info with the entry paths (exports keys) that point to each output file.
|
|
27
|
+
// Usually there's at most one per output file (or none if it's a shared chunk).
|
|
28
|
+
for (const [entryPath, relOutputFile] of Object.entries(entryToOutputFile)) {
|
|
29
|
+
outputFileInfo[relOutputFile]?.exportsKeys.push(entryPath);
|
|
40
30
|
}
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
});
|
|
45
|
-
const filePaths = Object.keys(localPathToSafe);
|
|
46
|
-
const visitedPaths = new Set(filePaths);
|
|
47
|
-
const pathsToParse = [...filePaths];
|
|
48
|
-
while (pathsToParse.length) {
|
|
49
|
-
const filePath = pathsToParse.shift();
|
|
31
|
+
// Build the bundle info based on imports and exports for each output file.
|
|
32
|
+
// exportsKeys are the export map key(s) that point to the output file.
|
|
33
|
+
for (const [relOutputFile, { exportsKeys, produces }] of Object.entries(outputFileInfo)) {
|
|
50
34
|
// Ignore any non-JS/TS files such as SVGs and sourcemaps
|
|
51
|
-
if (
|
|
35
|
+
if (path.extname(relOutputFile) !== '.js') {
|
|
52
36
|
continue;
|
|
53
37
|
}
|
|
54
|
-
const
|
|
55
|
-
|
|
56
|
-
throw new Error(`Found file that was not expected to be processed: ${filePath}`);
|
|
57
|
-
}
|
|
58
|
-
const parseResult = await getImportsAndExports(filePath, packagePath);
|
|
38
|
+
const absOutputFile = path.resolve(outputPath, relOutputFile);
|
|
39
|
+
const parseResult = await getImportsAndExports(absOutputFile, packagePath);
|
|
59
40
|
if (!parseResult) {
|
|
60
41
|
continue;
|
|
61
42
|
}
|
|
62
43
|
const { exportNames, imports, dynamicImports } = parseResult;
|
|
63
|
-
const { entry, produces } = outputFileInfo[safePath];
|
|
64
44
|
exportNames.forEach((name) => produces.add(name));
|
|
65
|
-
|
|
66
|
-
|
|
45
|
+
// Create a bundle info entry for this output file.
|
|
46
|
+
// If there wasn't an exports map key pointing to this file, just use the output path.
|
|
47
|
+
const pathsInBundleInfo = exportsKeys.length ? exportsKeys : [relOutputFile];
|
|
48
|
+
const fileBundleInfo = bundleInfo[pathsInBundleInfo[0]] || {
|
|
49
|
+
bundlePath: relOutputFile,
|
|
67
50
|
produces: Array.from(produces),
|
|
68
51
|
consumes: [],
|
|
69
52
|
};
|
|
53
|
+
// Use the same object for all paths that point to this file.
|
|
54
|
+
pathsInBundleInfo.forEach((p) => (bundleInfo[p] = fileBundleInfo));
|
|
70
55
|
if (dynamicImports.length) {
|
|
71
|
-
|
|
56
|
+
fileBundleInfo.dynamicImports = dynamicImports;
|
|
72
57
|
}
|
|
73
58
|
for (const { packageName, importPath, names } of imports) {
|
|
74
|
-
if (packageName
|
|
75
|
-
const localPath = path.resolve(path.dirname(
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
59
|
+
if (packageName === '.') {
|
|
60
|
+
const localPath = normalizedPathRelativeTo(outputPath, path.resolve(path.dirname(absOutputFile), importPath));
|
|
61
|
+
// Pretty sure any path in the current package which is imported in the bundle output should be
|
|
62
|
+
// in outputFiles, but make it obvious if not.
|
|
63
|
+
if (!outputFileInfo[localPath]) {
|
|
64
|
+
throw new Error(`Imported local file not found in output files for ${outputPath}: ${localPath} ` +
|
|
65
|
+
`(imported from ${absOutputFile} with import path "${importPath}")`);
|
|
80
66
|
}
|
|
81
67
|
}
|
|
82
|
-
else if (
|
|
83
|
-
// Find if the
|
|
84
|
-
const
|
|
85
|
-
if (
|
|
86
|
-
// If
|
|
87
|
-
|
|
68
|
+
else if (!packageName.startsWith('node:')) {
|
|
69
|
+
// Find if the imported package is already in the consumes list.
|
|
70
|
+
const consumesFromPackage = fileBundleInfo.consumes.find((c) => c.packageName === packageName && c.importPath === importPath);
|
|
71
|
+
if (consumesFromPackage) {
|
|
72
|
+
// If so, add the names to the existing entry.
|
|
73
|
+
// This is necessary because the same import may be used in multiple places.
|
|
74
|
+
consumesFromPackage.names = Array.from(new Set([...names, ...consumesFromPackage.names]));
|
|
75
|
+
}
|
|
76
|
+
else {
|
|
77
|
+
// Otherwise, add it.
|
|
78
|
+
fileBundleInfo.consumes.push({
|
|
88
79
|
packageName: packageName,
|
|
89
80
|
importPath: importPath || '.',
|
|
90
81
|
names: [...names],
|
|
91
82
|
});
|
|
92
83
|
}
|
|
93
|
-
else {
|
|
94
|
-
// If so, add the names to the existing entry.
|
|
95
|
-
// This is necessary because the same import may be used in multiple places.
|
|
96
|
-
bundleInfo[entry].consumes[entryIndex].names = Array.from(new Set([...names, ...bundleInfo[entry].consumes[entryIndex].names]));
|
|
97
|
-
}
|
|
98
|
-
}
|
|
99
|
-
}
|
|
100
|
-
if (repeatedExports[safePath]?.length > 1) {
|
|
101
|
-
// Multiple entries for the same path.
|
|
102
|
-
for (const repeatedEntry of repeatedExports[safePath]) {
|
|
103
|
-
if (repeatedEntry !== entry) {
|
|
104
|
-
bundleInfo[repeatedEntry] = bundleInfo[entry];
|
|
105
|
-
}
|
|
106
84
|
}
|
|
107
85
|
}
|
|
108
86
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getBundleInfo.js","sourceRoot":"","sources":["../../src/utilities/getBundleInfo.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,oBAAoB,EAAE,MAAM,0BAA0B,CAAC;AAChE,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"getBundleInfo.js","sourceRoot":"","sources":["../../src/utilities/getBundleInfo.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,oBAAoB,EAAE,MAAM,0BAA0B,CAAC;AAChE,OAAO,EAAE,wBAAwB,EAAE,MAAM,8BAA8B,CAAC;AACxE,OAAO,IAAI,MAAM,MAAM,CAAC;AAExB,OAAO,EAAE,oBAAoB,EAAE,MAAM,2BAA2B,CAAC;AAEjE;;;GAGG;AACH,MAAM,CAAC,KAAK,UAAU,aAAa,CAAC,MAMnC;IACC,MAAM,EAAE,WAAW,EAAE,UAAU,EAAE,WAAW,EAAE,UAAU,EAAE,UAAU,EAAE,GAAG,MAAM,CAAC;IAChF,MAAM,UAAU,GAAe,EAAE,CAAC;IAElC,8DAA8D;IAC9D,IAAI,CAAC,WAAW,CAAC,MAAM,EAAE,CAAC;QACxB,OAAO,UAAU,CAAC;IACpB,CAAC;IAED;;iEAE6D;IAC7D,MAAM,cAAc,GAAG,MAAM,CAAC,WAAW,CACvC,WAAW,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC;QACxB,IAAI,CAAC,UAAU;QACf,EAAE,WAAW,EAAE,EAAc,EAAE,QAAQ,EAAE,IAAI,GAAG,CAAS,IAAI,CAAC,OAAO,CAAC,EAAE;KACzE,CAAC,CACH,CAAC;IAEF,6FAA6F;IAC7F,oDAAoD;IACpD,MAAM,iBAAiB,GAAG,oBAAoB,CAAC,EA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AC,CAAC,CAAC,CAAC;gBAC5F,CAAC;qBAAM,CAAC;oBACN,qBAAqB;oBACrB,cAAc,CAAC,QAAQ,CAAC,IAAI,CAAC;wBAC3B,WAAW,EAAE,WAAW;wBACxB,UAAU,EAAE,UAAU,IAAI,GAAG;wBAC7B,KAAK,EAAE,CAAC,GAAG,KAAK,CAAC;qBAClB,CAAC,CAAC;gBACL,CAAC;YACH,CAAC;QACH,CAAC;IACH,CAAC;IAED,OAAO,UAAU,CAAC;AACpB,CAAC","sourcesContent":["import type { BundleOutputFile, PackageJsonExports } from '@ms-cloudpack/common-types';\nimport { getRuntimeEntryPaths } from '@ms-cloudpack/import-map';\nimport { normalizedPathRelativeTo } from '@ms-cloudpack/path-utilities';\nimport path from 'path';\nimport type { BundleEntryInfo, BundleInfo } from '../types/BundleInfo.js';\nimport { getImportsAndExports } from './getImportsAndExports.js';\n\n/**\n * Returns a mapping from entry file path (exports map key) to list of paths that are produced\n * and consumed in that file.\n */\nexport async function getBundleInfo(params: {\n packagePath: string;\n outputPath: string;\n outputFiles: BundleOutputFile[];\n exportsMap: PackageJsonExports;\n isExternal: boolean;\n}): Promise<BundleInfo> {\n const { packagePath, outputPath, outputFiles, exportsMap, isExternal } = params;\n const bundleInfo: BundleInfo = {};\n\n // If there are no output files, return the empty bundle info.\n if (!outputFiles.length) {\n return bundleInfo;\n }\n\n /** Mapping from normalized relative output file path to info about which entry paths\n * (exports map keys) pointed to that file, and what export names it produces.\n * Usually there's at most one entry path per output file. */\n const outputFileInfo = Object.fromEntries(\n outputFiles.map((file) => [\n file.outputPath,\n { exportsKeys: [] as string[], produces: new Set<string>(file.exports) },\n ]),\n );\n\n // For each entry path (exports map key), get the normalized relative path to the output file\n // that will be used at runtime based on conditions.\n const entryToOutputFile = getRuntimeEntryPaths({ packagePath, isExternal, exportsMap });\n\n // Update the output file info with the entry paths (exports keys) that point to each output file.\n // Usually there's at most one per output file (or none if it's a shared chunk).\n for (const [entryPath, relOutputFile] of Object.entries(entryToOutputFile)) {\n outputFileInfo[relOutputFile]?.exportsKeys.push(entryPath);\n }\n\n // Build the bundle info based on imports and exports for each output file.\n // exportsKeys are the export map key(s) that point to the output file.\n for (const [relOutputFile, { exportsKeys, produces }] of Object.entries(outputFileInfo)) {\n // Ignore any non-JS/TS files such as SVGs and sourcemaps\n if (path.extname(relOutputFile) !== '.js') {\n continue;\n }\n\n const absOutputFile = path.resolve(outputPath, relOutputFile);\n\n const parseResult = await getImportsAndExports(absOutputFile, packagePath);\n if (!parseResult) {\n continue;\n }\n const { exportNames, imports, dynamicImports } = parseResult;\n\n exportNames.forEach((name) => produces.add(name));\n\n // Create a bundle info entry for this output file.\n // If there wasn't an exports map key pointing to this file, just use the output path.\n const pathsInBundleInfo = exportsKeys.length ? exportsKeys : [relOutputFile];\n const fileBundleInfo: BundleEntryInfo = bundleInfo[pathsInBundleInfo[0]] || {\n bundlePath: relOutputFile,\n produces: Array.from(produces),\n consumes: [],\n };\n // Use the same object for all paths that point to this file.\n pathsInBundleInfo.forEach((p) => (bundleInfo[p] = fileBundleInfo));\n\n if (dynamicImports.length) {\n fileBundleInfo.dynamicImports = dynamicImports;\n }\n\n for (const { packageName, importPath, names } of imports) {\n if (packageName === '.') {\n const localPath = normalizedPathRelativeTo(outputPath, path.resolve(path.dirname(absOutputFile), importPath));\n // Pretty sure any path in the current package which is imported in the bundle output should be\n // in outputFiles, but make it obvious if not.\n if (!outputFileInfo[localPath]) {\n throw new Error(\n `Imported local file not found in output files for ${outputPath}: ${localPath} ` +\n `(imported from ${absOutputFile} with import path \"${importPath}\")`,\n );\n }\n } else if (!packageName.startsWith('node:')) {\n // Find if the imported package is already in the consumes list.\n const consumesFromPackage = fileBundleInfo.consumes.find(\n (c) => c.packageName === packageName && c.importPath === importPath,\n );\n if (consumesFromPackage) {\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 consumesFromPackage.names = Array.from(new Set([...names, ...consumesFromPackage.names]));\n } else {\n // Otherwise, add it.\n fileBundleInfo.consumes.push({\n packageName: packageName,\n importPath: importPath || '.',\n names: [...names],\n });\n }\n }\n }\n }\n\n return bundleInfo;\n}\n"]}
|
|
@@ -6,6 +6,7 @@ import type { ConsumedImport, DynamicImport } from '../types/BundleInfo.js';
|
|
|
6
6
|
export declare function getImportsAndExports(filePath: string, packagePath?: string): Promise<{
|
|
7
7
|
exportNames: Set<string>;
|
|
8
8
|
imports: ConsumedImport[];
|
|
9
|
+
/** Dynamic (async) imports with non-literal paths consumed by this file. */
|
|
9
10
|
dynamicImports: DynamicImport[];
|
|
10
11
|
} | undefined>;
|
|
11
12
|
//# sourceMappingURL=getImportsAndExports.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getImportsAndExports.d.ts","sourceRoot":"","sources":["../../src/utilities/getImportsAndExports.ts"],"names":[],"mappings":"AAMA,OAAO,KAAK,EAAE,cAAc,EAAE,aAAa,EAAE,MAAM,wBAAwB,CAAC;AAE5E;;;GAGG;AACH,wBAAsB,oBAAoB,CACxC,QAAQ,EAAE,MAAM,EAChB,WAAW,CAAC,EAAE,MAAM,GACnB,OAAO,CACN;IACE,WAAW,EAAE,GAAG,CAAC,MAAM,CAAC,CAAC;IACzB,OAAO,EAAE,cAAc,EAAE,CAAC;IAC1B,cAAc,EAAE,aAAa,EAAE,CAAC;CACjC,GACD,SAAS,CACZ,
|
|
1
|
+
{"version":3,"file":"getImportsAndExports.d.ts","sourceRoot":"","sources":["../../src/utilities/getImportsAndExports.ts"],"names":[],"mappings":"AAMA,OAAO,KAAK,EAAE,cAAc,EAAE,aAAa,EAAE,MAAM,wBAAwB,CAAC;AAE5E;;;GAGG;AACH,wBAAsB,oBAAoB,CACxC,QAAQ,EAAE,MAAM,EAChB,WAAW,CAAC,EAAE,MAAM,GACnB,OAAO,CACN;IACE,WAAW,EAAE,GAAG,CAAC,MAAM,CAAC,CAAC;IACzB,OAAO,EAAE,cAAc,EAAE,CAAC;IAC1B,4EAA4E;IAC5E,cAAc,EAAE,aAAa,EAAE,CAAC;CACjC,GACD,SAAS,CACZ,CAqIA"}
|
|
@@ -34,85 +34,86 @@ export async function getImportsAndExports(filePath, packagePath) {
|
|
|
34
34
|
// es-module-lexer doesn't handle export * from statements correctly as it parses them as
|
|
35
35
|
// imports but not as exports. We need to handle them separately.
|
|
36
36
|
// TODO: Remove when https://github.com/guybedford/es-module-lexer/issues/76 is fixed
|
|
37
|
-
const
|
|
37
|
+
const exportStarPaths = [];
|
|
38
38
|
const imports = [];
|
|
39
39
|
const dynamicImports = [];
|
|
40
40
|
for (const imprt of new Set(rawImports)) {
|
|
41
|
-
|
|
42
|
-
|
|
41
|
+
if (imprt.d === -2) {
|
|
42
|
+
continue; // -2 means import.meta, which we don't care about
|
|
43
|
+
}
|
|
44
|
+
// es-module-lexer returns objects where the "n" property is the import source,
|
|
45
|
+
// e.g. "@fluentui/react/lib/Button" for this import:
|
|
43
46
|
// import { Button } from '@fluentui/react/lib/Button';
|
|
44
|
-
//
|
|
47
|
+
// However, "n" will be undefined for import() if isn't a plain string literal.
|
|
45
48
|
let importPath = imprt.n;
|
|
46
49
|
// ss and se point to the entire import string's start/end
|
|
47
50
|
const importCode = source.slice(imprt.ss, imprt.se);
|
|
48
51
|
// s and e point to the specificer's start/end, including quotes -- e.g. "@fluentui/react/lib/Button"
|
|
49
52
|
const importSpecifier = source.slice(imprt.s, imprt.e);
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
53
|
+
// Currently when the import source is a backtick string, the path ("n" property) is undefined.
|
|
54
|
+
// This is a limitation in es-module-lexer.
|
|
55
|
+
if (/^`[^$`]+`$/.test(importSpecifier)) {
|
|
56
|
+
// If it's a static string which happened to use backticks for some reason, we can parse that.
|
|
57
|
+
importPath = importSpecifier.slice(1, -1);
|
|
58
|
+
}
|
|
59
|
+
// Handle literal paths first
|
|
60
|
+
if (importPath) {
|
|
61
|
+
// Handling `export * from` import statements
|
|
62
|
+
if (/export\s*\*\s*from/.test(importCode)) {
|
|
63
|
+
exportStarPaths.push(importPath);
|
|
59
64
|
}
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
try {
|
|
65
|
-
rawSourceMap = JSON.parse(await fsPromises.readFile(`${filePath}.map`, 'utf-8'));
|
|
66
|
-
const consumer = await new SourceMapConsumer(rawSourceMap);
|
|
67
|
-
const pos = getLineAndColumn(source, imprt.s);
|
|
68
|
-
const originalPos = consumer.originalPositionFor(pos);
|
|
69
|
-
originalSource = originalPos.source;
|
|
70
|
-
consumer.destroy(); // Clean up the consumer
|
|
71
|
-
if (originalSource === null) {
|
|
72
|
-
console.debug(`Failed to find original source for import:\nFilename:${filePath}\nImport:\n ${importCode}`);
|
|
73
|
-
}
|
|
74
|
-
}
|
|
75
|
-
catch (err) {
|
|
76
|
-
console.debug(`Failed to read sourcemap for import:\nFilename:${filePath}\nImport:\n ${importCode}`, err);
|
|
77
|
-
}
|
|
78
|
-
// Original source where the import was found.
|
|
79
|
-
const absoluteImportSpecifier = originalSource
|
|
80
|
-
? path.resolve(path.dirname(filePath), originalSource)
|
|
81
|
-
: filePath;
|
|
82
|
-
let packageName = '.'; // Default to local package
|
|
83
|
-
// Remove leading quote from the import specifier if it exists.
|
|
84
|
-
const lazyCleanImportSpecifier = importSpecifier.replace(/^["'`]/, '');
|
|
85
|
-
if (!lazyCleanImportSpecifier.startsWith('.')) {
|
|
86
|
-
packageName = parseImportString(lazyCleanImportSpecifier).packageName;
|
|
87
|
-
}
|
|
88
|
-
dynamicImports.push({
|
|
89
|
-
packageName,
|
|
90
|
-
// Relative path from package path to file with import. Prefer original source if available.
|
|
91
|
-
// or use the file path if original source is not available.
|
|
92
|
-
importOrigin: normalizedPathRelativeTo(packagePath, absoluteImportSpecifier),
|
|
93
|
-
importSpecifier,
|
|
94
|
-
});
|
|
95
|
-
continue;
|
|
65
|
+
let importedNames;
|
|
66
|
+
if (imprt.d >= 0) {
|
|
67
|
+
// This is a dynamic import. In this case we don't know which names are used, so assume all of them.
|
|
68
|
+
importedNames = ['*'];
|
|
96
69
|
}
|
|
97
70
|
else {
|
|
98
|
-
|
|
99
|
-
|
|
71
|
+
// Parse the import string into its component parts.
|
|
72
|
+
importedNames = parseNamedImports(importCode);
|
|
100
73
|
}
|
|
74
|
+
imports.push({
|
|
75
|
+
...parseImportString(importPath),
|
|
76
|
+
names: Array.from(new Set(importedNames)),
|
|
77
|
+
});
|
|
101
78
|
}
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
79
|
+
else if (packagePath) {
|
|
80
|
+
// Non-literal path.
|
|
81
|
+
// Find the original source of the import.
|
|
82
|
+
let rawSourceMap;
|
|
83
|
+
let originalSource = null;
|
|
84
|
+
try {
|
|
85
|
+
rawSourceMap = JSON.parse(await fsPromises.readFile(`${filePath}.map`, 'utf-8'));
|
|
86
|
+
const consumer = await new SourceMapConsumer(rawSourceMap);
|
|
87
|
+
const pos = getLineAndColumn(source, imprt.s);
|
|
88
|
+
originalSource = consumer.originalPositionFor(pos).source;
|
|
89
|
+
consumer.destroy(); // Clean up the consumer
|
|
90
|
+
if (originalSource === null) {
|
|
91
|
+
console.debug(`Failed to find original source for import:\nFilename:${filePath}\nImport:\n ${importCode}`);
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
catch (err) {
|
|
95
|
+
console.debug(`Failed to read sourcemap for import:\nFilename:${filePath}\nImport:\n ${importCode}`, err);
|
|
96
|
+
}
|
|
97
|
+
// Original source where the import was found.
|
|
98
|
+
const absoluteImportSpecifier = originalSource ? path.resolve(path.dirname(filePath), originalSource) : filePath;
|
|
99
|
+
// TODO: This will give a bad path for a lot of template or concatenated strings
|
|
100
|
+
let packageName = '.'; // Default to local package
|
|
101
|
+
// Remove leading quote from the import specifier if it exists.
|
|
102
|
+
const cleanImportSpecifier = importSpecifier.replace(/^["'`]/, '');
|
|
103
|
+
if (!cleanImportSpecifier.startsWith('.')) {
|
|
104
|
+
packageName = parseImportString(cleanImportSpecifier).packageName;
|
|
105
|
+
}
|
|
106
|
+
dynamicImports.push({
|
|
107
|
+
packageName,
|
|
108
|
+
// Relative path from package path to file with import. Prefer original source if available.
|
|
109
|
+
// or use the file path if original source is not available.
|
|
110
|
+
importOrigin: normalizedPathRelativeTo(packagePath, absoluteImportSpecifier),
|
|
111
|
+
importSpecifier,
|
|
112
|
+
});
|
|
105
113
|
}
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
if (imprt.d >= 0 && !importedNames.length) {
|
|
109
|
-
// This is a dynamic import. In this case we don't know which names are used, so assume all of them.
|
|
110
|
-
importedNames.push('*');
|
|
114
|
+
else {
|
|
115
|
+
console.debug(`Found an import that didn't have a static path:\nFilename:${filePath}\nImport:\n ${importCode}`);
|
|
111
116
|
}
|
|
112
|
-
imports.push({
|
|
113
|
-
...parseImportString(importPath),
|
|
114
|
-
names: Array.from(new Set(importedNames)),
|
|
115
|
-
});
|
|
116
117
|
}
|
|
117
118
|
// Processing exports is cheap as we already have to parse the source.
|
|
118
119
|
// Helps find exports uncaught by output files.
|
|
@@ -127,7 +128,7 @@ export async function getImportsAndExports(filePath, packagePath) {
|
|
|
127
128
|
console.debug(`Found an export that didn't parse correctly:\nFilename: ${filePath}\nExport:\n ${source.slice(exprt.s, exprt.e)}`);
|
|
128
129
|
}
|
|
129
130
|
}
|
|
130
|
-
for (const exportPath of
|
|
131
|
+
for (const exportPath of exportStarPaths) {
|
|
131
132
|
// This follows the following convention: https://github.com/guybedford/es-module-lexer/issues/76#issuecomment-868561807
|
|
132
133
|
exportNames.add(`*${exportPath}`);
|
|
133
134
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getImportsAndExports.js","sourceRoot":"","sources":["../../src/utilities/getImportsAndExports.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,iBAAiB,EAAE,MAAM,mCAAmC,CAA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AAC;QAClC,IAAI,MAAM,CAAC,CAAC,CAAC,KAAK,IAAI,EAAE,CAAC;YACvB,IAAI,EAAE,CAAC;YACP,MAAM,GAAG,CAAC,CAAC;QACb,CAAC;aAAM,CAAC;YACN,MAAM,EAAE,CAAC;QACX,CAAC;IACH,CAAC;IAED,OAAO,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC;AAC1B,CAAC","sourcesContent":["import { parseImportString, parseNamedImports } from '@ms-cloudpack/path-string-parsing';\nimport { parse, type ImportSpecifier, type ExportSpecifier } from 'es-module-lexer';\nimport fsPromises from 'fs/promises';\nimport { SourceMapConsumer, type RawSourceMap } from 'source-map';\nimport path from 'path';\nimport { normalizedPathRelativeTo } from '@ms-cloudpack/path-utilities';\nimport type { ConsumedImport, DynamicImport } from '../types/BundleInfo.js';\n\n/**\n * Get info about imports and exports from a file.\n * Returns undefined if the file doesn't exist or can't be parsed.\n */\nexport async function getImportsAndExports(\n filePath: string,\n packagePath?: string,\n): Promise<\n | {\n exportNames: Set<string>;\n imports: ConsumedImport[];\n dynamicImports: DynamicImport[];\n }\n | undefined\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 ${filePath}:`, err);\n return;\n }\n\n let rawImports: readonly ImportSpecifier[];\n let rawExports: readonly ExportSpecifier[];\n try {\n // es-module-lexer/parse may return Promise in some conditions\n // https://github.com/guybedford/es-module-lexer/issues/155\n // eslint-disable-next-line @typescript-eslint/await-thenable\n [rawImports, rawExports] = await parse(source);\n } catch (err) {\n // This could happen if the source file isn't valid JS\n console.warn(`Failed to parse ${filePath}: ${err}\\nSource is:\\n${source}`);\n return;\n }\n\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 // TODO: Remove when https://github.com/guybedford/es-module-lexer/issues/76 is fixed\n const exportStarImport = [];\n\n const imports: ConsumedImport[] = [];\n const dynamicImports: DynamicImport[] = [];\n for (const imprt of new Set(rawImports)) {\n // 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 // import { Button } from '@fluentui/react/lib/Button';\n // imprt.n is \"@fluentui/react/lib/Button\"\n let importPath = imprt.n;\n // ss and se point to the entire import string's start/end\n const importCode = source.slice(imprt.ss, imprt.se);\n // s and e point to the specificer's start/end, including quotes -- e.g. \"@fluentui/react/lib/Button\"\n const importSpecifier = source.slice(imprt.s, imprt.e);\n\n if (!importPath) {\n if (imprt.d === -2) {\n continue; // -2 means import.meta, which we don't care about\n }\n\n // Currently when the import source is a backtick string, the path (\"n\" property) is undefined.\n // This is a limitation in es-module-lexer.\n if (/^`[^$`]+`$/.test(importSpecifier)) {\n // If it's a static string which happened to use backticks for some reason, we can parse that.\n importPath = importSpecifier.slice(1, -1);\n } else if (packagePath) {\n // Find the original source of the import.\n let rawSourceMap: RawSourceMap;\n let originalSource: string | null = null;\n try {\n rawSourceMap = JSON.parse(await fsPromises.readFile(`${filePath}.map`, 'utf-8')) as RawSourceMap;\n const consumer = await new SourceMapConsumer(rawSourceMap);\n const pos = getLineAndColumn(source, imprt.s);\n const originalPos = consumer.originalPositionFor(pos);\n originalSource = originalPos.source;\n consumer.destroy(); // Clean up the consumer\n if (originalSource === null) {\n console.debug(`Failed to find original source for import:\\nFilename:${filePath}\\nImport:\\n ${importCode}`);\n }\n } catch (err) {\n console.debug(`Failed to read sourcemap for import:\\nFilename:${filePath}\\nImport:\\n ${importCode}`, err);\n }\n\n // Original source where the import was found.\n const absoluteImportSpecifier = originalSource\n ? path.resolve(path.dirname(filePath), originalSource)\n : filePath;\n\n let packageName = '.'; // Default to local package\n // Remove leading quote from the import specifier if it exists.\n const lazyCleanImportSpecifier = importSpecifier.replace(/^[\"'`]/, '');\n if (!lazyCleanImportSpecifier.startsWith('.')) {\n packageName = parseImportString(lazyCleanImportSpecifier).packageName;\n }\n dynamicImports.push({\n packageName,\n // Relative path from package path to file with import. Prefer original source if available.\n // or use the file path if original source is not available.\n importOrigin: normalizedPathRelativeTo(packagePath, absoluteImportSpecifier),\n importSpecifier,\n });\n continue;\n } else {\n console.debug(\n `Found an import that didn't have a static path:\\nFilename:${filePath}\\nImport:\\n ${importCode}`,\n );\n continue;\n }\n }\n\n // Handling export * from import statements\n if (importCode.includes('export * from')) {\n exportStarImport.push(importPath);\n }\n\n // Parse the import string into its component parts.\n const importedNames = parseNamedImports(importCode);\n if (imprt.d >= 0 && !importedNames.length) {\n // This is a dynamic import. In this case we don't know which names are used, so assume all of them.\n importedNames.push('*');\n }\n\n imports.push({\n ...parseImportString(importPath),\n names: Array.from(new Set<string>(importedNames)),\n });\n }\n\n // Processing exports is cheap as we already have to parse the source.\n // Helps find exports uncaught by output files.\n const exportNames = new Set<string>();\n for (const exprt of rawExports) {\n if (exprt.n) {\n // Exports don't need to be parsed as it is\n // already in the format we need.\n exportNames.add(exprt.n);\n } else {\n console.debug(\n `Found an export that didn't parse correctly:\\nFilename: ${filePath}\\nExport:\\n ${source.slice(exprt.s, exprt.e)}`,\n );\n }\n }\n\n for (const exportPath of exportStarImport) {\n // This follows the following convention: https://github.com/guybedford/es-module-lexer/issues/76#issuecomment-868561807\n exportNames.add(`*${exportPath}`);\n }\n\n return { exportNames, imports, dynamicImports };\n}\n\nfunction getLineAndColumn(source: string, position: number): { line: number; column: number } {\n let line = 1;\n let column = 1;\n\n for (let i = 0; i < position; i++) {\n if (source[i] === '\\n') {\n line++;\n column = 1;\n } else {\n column++;\n }\n }\n\n return { line, column };\n}\n"]}
|
|
1
|
+
{"version":3,"file":"getImportsAndExports.js","sourceRoot":"","sources":["../../src/utilities/getImportsAndExports.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,iBAAiB,EAAE,MAAM,mCAAmC,CAAC;AACzF,OAAO,EAAE,KAAK,EAA8C,MAAM,iBAAiB,CAAC;AACpF,OAAO,UAAU,MAAM,aAAa,CAAC;AACrC,OAAO,EAAE,iBAAiB,EAAqB,MA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ACX,CAAC;IACH,CAAC;IAED,OAAO,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC;AAC1B,CAAC","sourcesContent":["import { parseImportString, parseNamedImports } from '@ms-cloudpack/path-string-parsing';\nimport { parse, type ImportSpecifier, type ExportSpecifier } from 'es-module-lexer';\nimport fsPromises from 'fs/promises';\nimport { SourceMapConsumer, type RawSourceMap } from 'source-map';\nimport path from 'path';\nimport { normalizedPathRelativeTo } from '@ms-cloudpack/path-utilities';\nimport type { ConsumedImport, DynamicImport } from '../types/BundleInfo.js';\n\n/**\n * Get info about imports and exports from a file.\n * Returns undefined if the file doesn't exist or can't be parsed.\n */\nexport async function getImportsAndExports(\n filePath: string,\n packagePath?: string,\n): Promise<\n | {\n exportNames: Set<string>;\n imports: ConsumedImport[];\n /** Dynamic (async) imports with non-literal paths consumed by this file. */\n dynamicImports: DynamicImport[];\n }\n | undefined\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 ${filePath}:`, err);\n return;\n }\n\n let rawImports: readonly ImportSpecifier[];\n let rawExports: readonly ExportSpecifier[];\n try {\n // es-module-lexer/parse may return Promise in some conditions\n // https://github.com/guybedford/es-module-lexer/issues/155\n // eslint-disable-next-line @typescript-eslint/await-thenable\n [rawImports, rawExports] = await parse(source);\n } catch (err) {\n // This could happen if the source file isn't valid JS\n console.warn(`Failed to parse ${filePath}: ${err}\\nSource is:\\n${source}`);\n return;\n }\n\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 // TODO: Remove when https://github.com/guybedford/es-module-lexer/issues/76 is fixed\n const exportStarPaths: string[] = [];\n\n const imports: ConsumedImport[] = [];\n const dynamicImports: DynamicImport[] = [];\n for (const imprt of new Set(rawImports)) {\n if (imprt.d === -2) {\n continue; // -2 means import.meta, which we don't care about\n }\n\n // es-module-lexer returns objects where the \"n\" property is the import source,\n // e.g. \"@fluentui/react/lib/Button\" for this import:\n // import { Button } from '@fluentui/react/lib/Button';\n // However, \"n\" will be undefined for import() if isn't a plain string literal.\n let importPath = imprt.n;\n // ss and se point to the entire import string's start/end\n const importCode = source.slice(imprt.ss, imprt.se);\n // s and e point to the specificer's start/end, including quotes -- e.g. \"@fluentui/react/lib/Button\"\n const importSpecifier = source.slice(imprt.s, imprt.e);\n\n // Currently when the import source is a backtick string, the path (\"n\" property) is undefined.\n // This is a limitation in es-module-lexer.\n if (/^`[^$`]+`$/.test(importSpecifier)) {\n // If it's a static string which happened to use backticks for some reason, we can parse that.\n importPath = importSpecifier.slice(1, -1);\n }\n\n // Handle literal paths first\n if (importPath) {\n // Handling `export * from` import statements\n if (/export\\s*\\*\\s*from/.test(importCode)) {\n exportStarPaths.push(importPath);\n }\n\n let importedNames: string[];\n if (imprt.d >= 0) {\n // This is a dynamic import. In this case we don't know which names are used, so assume all of them.\n importedNames = ['*'];\n } else {\n // Parse the import string into its component parts.\n importedNames = parseNamedImports(importCode);\n }\n\n imports.push({\n ...parseImportString(importPath),\n names: Array.from(new Set(importedNames)),\n });\n } else if (packagePath) {\n // Non-literal path.\n // Find the original source of the import.\n let rawSourceMap: RawSourceMap;\n let originalSource: string | null = null;\n try {\n rawSourceMap = JSON.parse(await fsPromises.readFile(`${filePath}.map`, 'utf-8')) as RawSourceMap;\n const consumer = await new SourceMapConsumer(rawSourceMap);\n const pos = getLineAndColumn(source, imprt.s);\n originalSource = consumer.originalPositionFor(pos).source;\n consumer.destroy(); // Clean up the consumer\n if (originalSource === null) {\n console.debug(`Failed to find original source for import:\\nFilename:${filePath}\\nImport:\\n ${importCode}`);\n }\n } catch (err) {\n console.debug(`Failed to read sourcemap for import:\\nFilename:${filePath}\\nImport:\\n ${importCode}`, err);\n }\n\n // Original source where the import was found.\n const absoluteImportSpecifier = originalSource ? path.resolve(path.dirname(filePath), originalSource) : filePath;\n\n // TODO: This will give a bad path for a lot of template or concatenated strings\n let packageName = '.'; // Default to local package\n // Remove leading quote from the import specifier if it exists.\n const cleanImportSpecifier = importSpecifier.replace(/^[\"'`]/, '');\n if (!cleanImportSpecifier.startsWith('.')) {\n packageName = parseImportString(cleanImportSpecifier).packageName;\n }\n dynamicImports.push({\n packageName,\n // Relative path from package path to file with import. Prefer original source if available.\n // or use the file path if original source is not available.\n importOrigin: normalizedPathRelativeTo(packagePath, absoluteImportSpecifier),\n importSpecifier,\n });\n } else {\n console.debug(`Found an import that didn't have a static path:\\nFilename:${filePath}\\nImport:\\n ${importCode}`);\n }\n }\n\n // Processing exports is cheap as we already have to parse the source.\n // Helps find exports uncaught by output files.\n const exportNames = new Set<string>();\n for (const exprt of rawExports) {\n if (exprt.n) {\n // Exports don't need to be parsed as it is\n // already in the format we need.\n exportNames.add(exprt.n);\n } else {\n console.debug(\n `Found an export that didn't parse correctly:\\nFilename: ${filePath}\\nExport:\\n ${source.slice(exprt.s, exprt.e)}`,\n );\n }\n }\n\n for (const exportPath of exportStarPaths) {\n // This follows the following convention: https://github.com/guybedford/es-module-lexer/issues/76#issuecomment-868561807\n exportNames.add(`*${exportPath}`);\n }\n\n return { exportNames, imports, dynamicImports };\n}\n\nfunction getLineAndColumn(source: string, position: number): { line: number; column: number } {\n let line = 1;\n let column = 1;\n\n for (let i = 0; i < position; i++) {\n if (source[i] === '\\n') {\n line++;\n column = 1;\n } else {\n column++;\n }\n }\n\n return { line, column };\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"validateOverride.d.ts","sourceRoot":"","sources":["../../src/utilities/validateOverride.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,qBAAqB,CAAC;AACnD,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,6BAA6B,CAAC;AAGnE;;;GAGG;AACH,wBAAsB,gBAAgB,CACpC,OAAO,EAAE,eAAe,EACxB,OAAO,EAAE,IAAI,CAAC,OAAO,EAAE,SAAS,GAAG,UAAU,CAAC,GAC7C,OAAO,CAAC,OAAO,CAAC,
|
|
1
|
+
{"version":3,"file":"validateOverride.d.ts","sourceRoot":"","sources":["../../src/utilities/validateOverride.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,qBAAqB,CAAC;AACnD,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,6BAA6B,CAAC;AAGnE;;;GAGG;AACH,wBAAsB,gBAAgB,CACpC,OAAO,EAAE,eAAe,EACxB,OAAO,EAAE,IAAI,CAAC,OAAO,EAAE,SAAS,GAAG,UAAU,CAAC,GAC7C,OAAO,CAAC,OAAO,CAAC,CAqDlB"}
|
|
@@ -40,10 +40,6 @@ export async function validateOverride(options, context) {
|
|
|
40
40
|
const generatedConfig = await readGeneratedConfig(appPath);
|
|
41
41
|
// Ensure packageSettings exists.
|
|
42
42
|
const generatedPackageSettings = await ensureGeneratedSettingsForPackage({ packagePath: entry.path }, { config: { generated: generatedConfig }, packages });
|
|
43
|
-
|
|
44
|
-
generatedPackageSettings.exports[normalizeRelativePath(importPath)] === null) {
|
|
45
|
-
return true;
|
|
46
|
-
}
|
|
47
|
-
return false;
|
|
43
|
+
return (!!generatedPackageSettings?.exports && generatedPackageSettings.exports[normalizeRelativePath(importPath)] === null);
|
|
48
44
|
}
|
|
49
45
|
//# sourceMappingURL=validateOverride.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"validateOverride.js","sourceRoot":"","sources":["../../src/utilities/validateOverride.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,gBAAgB,EAAE,MAAM,0BAA0B,CAAC;AAC5D,OAAO,EAAE,iBAAiB,EAAE,mBAAmB,EAAE,MAAM,iCAAiC,CAAC;AACzF,OAAO,EAAE,OAAO,EAAE,qBAAqB,EAAE,MAAM,mCAAmC,CAAC;AAGnF,OAAO,EAAE,iCAAiC,EAAE,mBAAmB,EAAE,MAAM,sBAAsB,CAAC;AAE9F;;;GAGG;AACH,MAAM,CAAC,KAAK,UAAU,gBA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W;QACX,UAAU,EAAE,OAAO,CAAC,UAAU;QAC9B,UAAU,EAAE,UAAU;KACvB,CAAC,CAAC;IAEH,IAAI,CAAC,KAAK,EAAE,CAAC;QACX,OAAO,KAAK,CAAC;IACf,CAAC;IAED,MAAM,EAAE,QAAQ,EAAE,GAAG,MAAM,iBAAiB,CAC1C;QACE,WAAW,EAAE,KAAK,CAAC,IAAI;QACvB,QAAQ,EAAE,UAAU;KACrB,EACD,EAAE,QAAQ,EAAE,MAAM,EAAE,OAAO,CAAC,MAAM,EAAE,CACrC,CAAC;IAEF,IAAI,QAAQ,EAAE,CAAC;QACb,OAAO,IAAI,CAAC;IACd,CAAC;IAED,2CAA2C;IAC3C,MAAM,eAAe,GAAG,MAAM,mBAAmB,CAAC,OAAO,CAAC,CAAC;IAE3D,iCAAiC;IACjC,MAAM,wBAAwB,GAAG,MAAM,iCAAiC,CACtE,EAAE,WAAW,EAAE,KAAK,CAAC,IAAI,EAAE,EAC3B,EAAE,MAAM,EAAE,EAAE,SAAS,EAAE,eAAe,EAAE,EAAE,QAAQ,EAAE,CACrD,CAAC;IAEF,OAAO,CACL,CAAC,CAAC,wBAAwB,EAAE,OAAO,IAAI,wBAAwB,CAAC,OAAO,CAAC,qBAAqB,CAAC,UAAU,CAAC,CAAC,KAAK,IAAI,CACpH,CAAC;AACJ,CAAC","sourcesContent":["import type { PackageJson } from '@ms-cloudpack/common-types';\nimport { parseRequestInfo } from '@ms-cloudpack/import-map';\nimport { findFileInPackage, findResolveMapEntry } from '@ms-cloudpack/package-utilities';\nimport { makeUrl, normalizeRelativePath } from '@ms-cloudpack/path-string-parsing';\nimport type { Context } from '../types/Context.js';\nimport type { OverrideOptions } from '../types/OverrideOptions.js';\nimport { ensureGeneratedSettingsForPackage, readGeneratedConfig } from '@ms-cloudpack/config';\n\n/**\n * Given a package name, import path, and optional issuerUrl, returns a boolean indicating if the given\n * override is valid.\n */\nexport async function validateOverride(\n options: OverrideOptions,\n context: Pick<Context, 'session' | 'packages'>,\n): Promise<boolean> {\n const { packageName, importPath, issuerUrl } = options;\n const { session, packages } = context;\n const { config } = session;\n const { appPath } = config;\n\n let requiredBy: PackageJson | undefined = undefined;\n\n // Import paths with trailing slashes are not supported by import maps\n // in browser as they interpret the trailing slash as a wildcard partial match.\n if (importPath.endsWith('/')) {\n return false;\n }\n\n if (issuerUrl) {\n const { packageName: name, version } = parseRequestInfo(makeUrl(issuerUrl).pathname);\n requiredBy = { name, version };\n }\n\n const entry = findResolveMapEntry({\n packageName,\n resolveMap: session.resolveMap,\n definition: requiredBy,\n });\n\n if (!entry) {\n return false;\n }\n\n const { filePath } = await findFileInPackage(\n {\n packagePath: entry.path,\n filePath: importPath,\n },\n { packages, config: session.config },\n );\n\n if (filePath) {\n return true;\n }\n\n // Parse the generated config if it exists.\n const generatedConfig = await readGeneratedConfig(appPath);\n\n // Ensure packageSettings exists.\n const generatedPackageSettings = await ensureGeneratedSettingsForPackage(\n { packagePath: entry.path },\n { config: { generated: generatedConfig }, packages },\n );\n\n return (\n !!generatedPackageSettings?.exports && generatedPackageSettings.exports[normalizeRelativePath(importPath)] === null\n );\n}\n"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ms-cloudpack/api-server",
|
|
3
|
-
"version": "0.56.
|
|
3
|
+
"version": "0.56.8",
|
|
4
4
|
"description": "An implementation of the API server that does interacts with a task scheduler.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"type": "module",
|
|
@@ -27,21 +27,21 @@
|
|
|
27
27
|
"@lage-run/logger": "^1.3.0",
|
|
28
28
|
"@lage-run/scheduler": "^1.2.1",
|
|
29
29
|
"@lage-run/target-graph": "^0.9.0",
|
|
30
|
-
"@ms-cloudpack/bundler": "^0.23.
|
|
31
|
-
"@ms-cloudpack/common-types": "^0.23.
|
|
32
|
-
"@ms-cloudpack/config": "^0.
|
|
33
|
-
"@ms-cloudpack/create-express-app": "^1.10.
|
|
30
|
+
"@ms-cloudpack/bundler": "^0.23.18",
|
|
31
|
+
"@ms-cloudpack/common-types": "^0.23.4",
|
|
32
|
+
"@ms-cloudpack/config": "^0.33.1",
|
|
33
|
+
"@ms-cloudpack/create-express-app": "^1.10.6",
|
|
34
34
|
"@ms-cloudpack/data-bus": "^0.4.2",
|
|
35
35
|
"@ms-cloudpack/file-watcher": "^0.1.2",
|
|
36
|
-
"@ms-cloudpack/import-map": "^0.8.
|
|
36
|
+
"@ms-cloudpack/import-map": "^0.8.16",
|
|
37
37
|
"@ms-cloudpack/json-utilities": "^0.1.8",
|
|
38
|
-
"@ms-cloudpack/package-hashes": "^0.7.
|
|
39
|
-
"@ms-cloudpack/package-utilities": "^10.
|
|
38
|
+
"@ms-cloudpack/package-hashes": "^0.7.12",
|
|
39
|
+
"@ms-cloudpack/package-utilities": "^10.4.0",
|
|
40
40
|
"@ms-cloudpack/path-string-parsing": "^1.2.5",
|
|
41
|
-
"@ms-cloudpack/path-utilities": "^2.7.
|
|
42
|
-
"@ms-cloudpack/remote-cache": "^0.9.
|
|
41
|
+
"@ms-cloudpack/path-utilities": "^2.7.54",
|
|
42
|
+
"@ms-cloudpack/remote-cache": "^0.9.11",
|
|
43
43
|
"@ms-cloudpack/task-reporter": "^0.14.6",
|
|
44
|
-
"@ms-cloudpack/telemetry": "^0.9.
|
|
44
|
+
"@ms-cloudpack/telemetry": "^0.9.5",
|
|
45
45
|
"@trpc/client": "11.0.0-rc.608",
|
|
46
46
|
"@trpc/server": "11.0.0-rc.608",
|
|
47
47
|
"cors": "^2.8.5",
|