@@ -65,7 +65,7 @@ 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`. */
68+ /** The property name under which `upload-lib`'s namespace is exposed in `entry-points`. */
6969const UPLOAD_LIB_EXPORT = "uploadLib" ;
7070
7171/** The relative source path of the `upload-lib` module that we re-export from `entry-points`. */
@@ -151,41 +151,51 @@ const entryPointsPlugin = {
151151 const uploadLibReExport = `export * as ${ UPLOAD_LIB_EXPORT } from "${ UPLOAD_LIB_SRC } ";` ;
152152
153153 return {
154- contents : `"use strict";\n${ imports } \n\n${ wrappers } \n\n${ uploadLibReExport } \n` ,
154+ contents : `"use strict";\n${ imports } \n\n${ uploadLibReExport } \n\n${ wrappers } \n` ,
155155 resolveDir : "." ,
156156 loader : "ts" ,
157157 } ;
158158 } ) ;
159159
160160 // Emit entry point stubs for each Action using the entry template.
161161 build . onEnd ( async ( ) => {
162- // Read the entry point template.
163- const templatePath = "action-entry.js.tpl" ;
164- const template = await readFile ( join ( SRC_DIR , templatePath ) , "utf-8" ) ;
165-
166- const makeHeader = ( sourceFile ) =>
162+ const makeHeader = ( templatePath , sourceFile ) =>
167163 `// Automatically generated from '${ templatePath } ' for 'src/${ basename ( sourceFile ) } '.\n\n` ;
168164
165+ // Read the entry point template.
166+ const actionTemplatePath = "action-entry.js.tpl" ;
167+ const actionTemplate = await readFile (
168+ join ( SRC_DIR , actionTemplatePath ) ,
169+ "utf-8" ,
170+ ) ;
171+
169172 // Write entry point stubs for each Action.
170173 for ( const action of actions ) {
171174 await writeFile (
172175 join (
173176 OUT_DIR ,
174177 `${ action . name } ${ action . isPost ? "-post" : "" } -entry.js` ,
175178 ) ,
176- makeHeader ( action . path ) +
177- template . replaceAll ( "__ACTION__" , action . pascalCaseName ) ,
179+ makeHeader ( actionTemplatePath , action . path ) +
180+ actionTemplate . replaceAll ( "__ACTION__" , action . pascalCaseName ) ,
178181 ) ;
179182 }
180183
181184 // Write a small stub for `upload-lib` that re-exports it from the shared bundle.
182185 // External callers (e.g. internal testing environments) `require("./lib/upload-lib")`
183186 // and expect the same shape as before, so we expose the namespace as `module.exports`.
187+ const uploadLibStubTemplatePath = "upload-lib-stub.js.tpl" ;
188+ const uploadLibStubTemplate = await readFile (
189+ join ( SRC_DIR , uploadLibStubTemplatePath ) ,
190+ "utf-8" ,
191+ ) ;
184192 await writeFile (
185193 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` ,
194+ makeHeader ( uploadLibStubTemplatePath , `${ UPLOAD_LIB_SRC } .ts` ) +
195+ uploadLibStubTemplate . replaceAll (
196+ "__UPLOAD_LIB_EXPORT__" ,
197+ UPLOAD_LIB_EXPORT ,
198+ ) ,
189199 ) ;
190200 } ) ;
191201 } ,
0 commit comments