mirror of
https://github.com/github/codeql-action.git
synced 2026-05-21 10:11:48 +00:00
Action size: Reduce duplication between upload-lib and entry-points
This commit is contained in:
@@ -65,12 +65,22 @@ const onEndPlugin = {
|
||||
/** The name of the virtual `entry-points` module. */
|
||||
const SHARED_ENTRYPOINT = "entry-points";
|
||||
|
||||
/** The property name under which `upload-lib`'s namespace is exposed on `entry-points`. */
|
||||
const UPLOAD_LIB_EXPORT = "uploadLib";
|
||||
|
||||
/** The relative source path of the `upload-lib` module that we re-export from `entry-points`. */
|
||||
const UPLOAD_LIB_SRC = "./src/upload-lib";
|
||||
|
||||
/**
|
||||
* This plugin finds all source files that contain Action entry points.
|
||||
* It then generates the virtual `entry-points` module which imports all identified files,
|
||||
* and re-exports their `runWrapper` functions with suitable aliases.
|
||||
* A tiny stub file is emitted for each Action entrypoint. Each stub imports the shared bundle
|
||||
* and calls the respective entry point.
|
||||
* This plugin finds all source files that contain Action entry points. It then generates the
|
||||
* virtual `entry-points` module which imports all identified files, and re-exports their
|
||||
* `runWrapper` functions with suitable aliases.
|
||||
*
|
||||
* The virtual module additionally re-exports `upload-lib` under the `uploadLib` namespace so that
|
||||
* external consumers can access it via the small `lib/upload-lib.js` stub emitted below.
|
||||
*
|
||||
* A tiny stub file is emitted for each Action entrypoint, and one for `upload-lib`. Each stub
|
||||
* imports the shared bundle and calls/re-exports from the respective entry point.
|
||||
*
|
||||
* @type {esbuild.Plugin}
|
||||
*/
|
||||
@@ -136,15 +146,19 @@ const entryPointsPlugin = {
|
||||
)
|
||||
.join("\n\n");
|
||||
|
||||
// Also re-export the `upload-lib` namespace so that external consumers can reach it
|
||||
// via the `lib/upload-lib.js` stub without us having to bundle a second copy.
|
||||
const uploadLibReExport = `export * as ${UPLOAD_LIB_EXPORT} from "${UPLOAD_LIB_SRC}";`;
|
||||
|
||||
return {
|
||||
contents: `"use strict";\n${imports}\n\n${wrappers}\n`,
|
||||
contents: `"use strict";\n${imports}\n\n${wrappers}\n\n${uploadLibReExport}\n`,
|
||||
resolveDir: ".",
|
||||
loader: "ts",
|
||||
};
|
||||
});
|
||||
|
||||
// Emit entry point stubs for each Action using the entry template.
|
||||
build.onEnd(async (result) => {
|
||||
build.onEnd(async () => {
|
||||
// Read the entry point template.
|
||||
const templatePath = "action-entry.js.tpl";
|
||||
const template = await readFile(join(SRC_DIR, templatePath), "utf-8");
|
||||
@@ -163,16 +177,22 @@ const entryPointsPlugin = {
|
||||
template.replaceAll("__ACTION__", action.pascalCaseName),
|
||||
);
|
||||
}
|
||||
|
||||
// Write a small stub for `upload-lib` that re-exports it from the shared bundle.
|
||||
// External callers (e.g. internal testing environments) `require("./lib/upload-lib")`
|
||||
// and expect the same shape as before, so we expose the namespace as `module.exports`.
|
||||
await writeFile(
|
||||
join(OUT_DIR, "upload-lib.js"),
|
||||
`// Automatically generated stub re-exporting '${UPLOAD_LIB_SRC}.ts' from '${SHARED_ENTRYPOINT}.js'.\n\n` +
|
||||
`"use strict";\n\n` +
|
||||
`module.exports = require("./${SHARED_ENTRYPOINT}").${UPLOAD_LIB_EXPORT};\n`,
|
||||
);
|
||||
});
|
||||
},
|
||||
};
|
||||
|
||||
const context = await esbuild.context({
|
||||
// Include upload-lib.ts as an entry point for use in testing environments.
|
||||
entryPoints: [
|
||||
{ in: SHARED_ENTRYPOINT, out: SHARED_ENTRYPOINT },
|
||||
join(SRC_DIR, "upload-lib.ts"),
|
||||
],
|
||||
entryPoints: [{ in: SHARED_ENTRYPOINT, out: SHARED_ENTRYPOINT }],
|
||||
bundle: true,
|
||||
format: "cjs",
|
||||
outdir: OUT_DIR,
|
||||
|
||||
Generated
+25
-2
@@ -144948,7 +144948,8 @@ __export(entry_points_exports, {
|
||||
runStartProxyAction: () => runStartProxyAction,
|
||||
runStartProxyPostAction: () => runStartProxyPostAction,
|
||||
runUploadSarifAction: () => runUploadSarifAction,
|
||||
runUploadSarifPostAction: () => runUploadSarifPostAction
|
||||
runUploadSarifPostAction: () => runUploadSarifPostAction,
|
||||
uploadLib: () => upload_lib_exports
|
||||
});
|
||||
module.exports = __toCommonJS(entry_points_exports);
|
||||
|
||||
@@ -155484,6 +155485,27 @@ async function sendUnhandledErrorStatusReport(actionName, actionStartedAt, error
|
||||
}
|
||||
|
||||
// src/upload-lib.ts
|
||||
var upload_lib_exports = {};
|
||||
__export(upload_lib_exports, {
|
||||
buildPayload: () => buildPayload,
|
||||
filterAlertsByDiffRange: () => filterAlertsByDiffRange,
|
||||
findSarifFilesInDir: () => findSarifFilesInDir,
|
||||
getGroupedSarifFilePaths: () => getGroupedSarifFilePaths,
|
||||
populateRunAutomationDetails: () => populateRunAutomationDetails,
|
||||
postProcessSarifFiles: () => postProcessSarifFiles,
|
||||
readSarifFileOrThrow: () => readSarifFileOrThrow,
|
||||
shouldConsiderConfigurationError: () => shouldConsiderConfigurationError,
|
||||
shouldConsiderInvalidRequest: () => shouldConsiderInvalidRequest,
|
||||
shouldShowCombineSarifFilesDeprecationWarning: () => shouldShowCombineSarifFilesDeprecationWarning,
|
||||
throwIfCombineSarifFilesDisabled: () => throwIfCombineSarifFilesDisabled,
|
||||
uploadFiles: () => uploadFiles,
|
||||
uploadPayload: () => uploadPayload,
|
||||
uploadPostProcessedFiles: () => uploadPostProcessedFiles,
|
||||
validateSarifFileSchema: () => validateSarifFileSchema,
|
||||
validateUniqueCategory: () => validateUniqueCategory,
|
||||
waitForProcessing: () => waitForProcessing,
|
||||
writePostProcessedFiles: () => writePostProcessedFiles
|
||||
});
|
||||
var fs21 = __toESM(require("fs"));
|
||||
var path18 = __toESM(require("path"));
|
||||
var url = __toESM(require("url"));
|
||||
@@ -161271,7 +161293,8 @@ async function runUploadSarifPostAction() {
|
||||
runStartProxyAction,
|
||||
runStartProxyPostAction,
|
||||
runUploadSarifAction,
|
||||
runUploadSarifPostAction
|
||||
runUploadSarifPostAction,
|
||||
uploadLib
|
||||
});
|
||||
/*! Bundled license information:
|
||||
|
||||
|
||||
Generated
+3
-93734
File diff suppressed because one or more lines are too long
Reference in New Issue
Block a user