Skip to content

Commit 2a73406

Browse files
committed
Address review comments
1 parent fcc1e31 commit 2a73406

3 files changed

Lines changed: 26 additions & 13 deletions

File tree

build.mjs

Lines changed: 22 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ const onEndPlugin = {
6565
/** The name of the virtual `entry-points` module. */
6666
const 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`. */
6969
const 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
},

lib/upload-lib.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/upload-lib-stub.js.tpl

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
"use strict";
2+
3+
module.exports = require("./entry-points").__UPLOAD_LIB_EXPORT__;

0 commit comments

Comments
 (0)