@@ -65,12 +65,22 @@ const onEndPlugin = {
6565/** The name of the virtual `entry-points` module. */
6666const SHARED_ENTRYPOINT = "entry-points" ;
6767
68+ /** The property name under which `upload-lib`'s namespace is exposed on `entry-points`. */
69+ const UPLOAD_LIB_EXPORT = "uploadLib" ;
70+
71+ /** The relative source path of the `upload-lib` module that we re-export from `entry-points`. */
72+ const UPLOAD_LIB_SRC = "./src/upload-lib" ;
73+
6874/**
69- * This plugin finds all source files that contain Action entry points.
70- * It then generates the virtual `entry-points` module which imports all identified files,
71- * and re-exports their `runWrapper` functions with suitable aliases.
72- * A tiny stub file is emitted for each Action entrypoint. Each stub imports the shared bundle
73- * and calls the respective entry point.
75+ * This plugin finds all source files that contain Action entry points. It then generates the
76+ * virtual `entry-points` module which imports all identified files, and re-exports their
77+ * `runWrapper` functions with suitable aliases.
78+ *
79+ * The virtual module additionally re-exports `upload-lib` under the `uploadLib` namespace so that
80+ * external consumers can access it via the small `lib/upload-lib.js` stub emitted below.
81+ *
82+ * A tiny stub file is emitted for each Action entrypoint, and one for `upload-lib`. Each stub
83+ * imports the shared bundle and calls/re-exports from the respective entry point.
7484 *
7585 * @type {esbuild.Plugin }
7686 */
@@ -136,15 +146,19 @@ const entryPointsPlugin = {
136146 )
137147 . join ( "\n\n" ) ;
138148
149+ // Also re-export the `upload-lib` namespace so that external consumers can reach it
150+ // via the `lib/upload-lib.js` stub without us having to bundle a second copy.
151+ const uploadLibReExport = `export * as ${ UPLOAD_LIB_EXPORT } from "${ UPLOAD_LIB_SRC } ";` ;
152+
139153 return {
140- contents : `"use strict";\n${ imports } \n\n${ wrappers } \n` ,
154+ contents : `"use strict";\n${ imports } \n\n${ wrappers } \n\n ${ uploadLibReExport } \n ` ,
141155 resolveDir : "." ,
142156 loader : "ts" ,
143157 } ;
144158 } ) ;
145159
146160 // Emit entry point stubs for each Action using the entry template.
147- build . onEnd ( async ( result ) => {
161+ build . onEnd ( async ( ) => {
148162 // Read the entry point template.
149163 const templatePath = "action-entry.js.tpl" ;
150164 const template = await readFile ( join ( SRC_DIR , templatePath ) , "utf-8" ) ;
@@ -163,16 +177,22 @@ const entryPointsPlugin = {
163177 template . replaceAll ( "__ACTION__" , action . pascalCaseName ) ,
164178 ) ;
165179 }
180+
181+ // Write a small stub for `upload-lib` that re-exports it from the shared bundle.
182+ // External callers (e.g. internal testing environments) `require("./lib/upload-lib")`
183+ // and expect the same shape as before, so we expose the namespace as `module.exports`.
184+ await writeFile (
185+ join ( OUT_DIR , "upload-lib.js" ) ,
186+ `// Automatically generated stub re-exporting '${ UPLOAD_LIB_SRC } .ts' from '${ SHARED_ENTRYPOINT } .js'.\n\n` +
187+ `"use strict";\n\n` +
188+ `module.exports = require("./${ SHARED_ENTRYPOINT } ").${ UPLOAD_LIB_EXPORT } ;\n` ,
189+ ) ;
166190 } ) ;
167191 } ,
168192} ;
169193
170194const context = await esbuild . context ( {
171- // Include upload-lib.ts as an entry point for use in testing environments.
172- entryPoints : [
173- { in : SHARED_ENTRYPOINT , out : SHARED_ENTRYPOINT } ,
174- join ( SRC_DIR , "upload-lib.ts" ) ,
175- ] ,
195+ entryPoints : [ { in : SHARED_ENTRYPOINT , out : SHARED_ENTRYPOINT } ] ,
176196 bundle : true ,
177197 format : "cjs" ,
178198 outdir : OUT_DIR ,
0 commit comments