Skip to content

Commit e975b59

Browse files
committed
Ensure that res/WELCOME.md is found even after compiling with ncc
According to vercel/ncc#829, `ncc` has some magic that includes the resource in the bundled package if the path is specified using `path.join(__dirname, ...)`. However, we're already using ESModule, therefore we need to use the `import.meta.url` syntax (`import.meta.dirname` unfortunately does not seem to work in my hands). Having said that, the promise was that `ncc` would include this asset in the `dist/index.js` file, but no matter what I tried, I could not make this work. For that reason, the `res/` folder will need to be copied into `dist/` before publishing as a GitHub Action. Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
1 parent 5d7df21 commit e975b59

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

lib/ci-helper.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import { IPatchSeriesMetadata } from "./patch-series-metadata.js";
1818
import { IConfig, getExternalConfig, setConfig } from "./project-config.js";
1919
import { getPullRequestKeyFromURL, pullRequestKey } from "./pullRequestKey.js";
2020
import { ISMTPOptions } from "./send-mail.js";
21+
import { fileURLToPath } from "url";
2122

2223
const readFile = util.promisify(fs.readFile);
2324
type CommentFunction = (comment: string) => Promise<void>;
@@ -874,6 +875,11 @@ export class CIHelper {
874875
}
875876
}
876877

878+
public static async getWelcomeMessage(username: string): Promise<string> {
879+
const resPath = path.resolve(fileURLToPath(new URL(".", import.meta.url)), "..", "res", "WELCOME.md");
880+
return (await readFile(resPath)).toString().replace(/\${username}/g, username);
881+
}
882+
877883
public async handlePush(repositoryOwner: string, prNumber: number): Promise<void> {
878884
const prKey = {
879885
owner: repositoryOwner,
@@ -897,7 +903,7 @@ export class CIHelper {
897903
this.smtpOptions,
898904
);
899905
if (!pr.hasComments && !gitGitGadget.isUserAllowed(pr.author)) {
900-
const welcome = (await readFile("res/WELCOME.md")).toString().replace(/\${username}/g, pr.author);
906+
const welcome = await CIHelper.getWelcomeMessage(pr.author);
901907
await this.github.addPRComment(prKey, welcome);
902908

903909
await this.github.addPRLabels(prKey, ["new user"]);

0 commit comments

Comments
 (0)