Skip to content

Commit

Permalink
fix: escapeRegExp for ftl matched
Browse files Browse the repository at this point in the history
  • Loading branch information
northword committed Jan 6, 2025
1 parent f2a9d47 commit 5561a0d
Showing 1 changed file with 3 additions and 4 deletions.
7 changes: 3 additions & 4 deletions packages/scaffold/src/core/builder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { basename, dirname, join } from "node:path";
import process from "node:process";
import AdmZip from "adm-zip";
import chalk from "chalk";
import { toMerged } from "es-toolkit";
import { escapeRegExp, toMerged } from "es-toolkit";
import { build as buildAsync } from "esbuild";
import { copy, emptyDir, move, outputFile, outputJSON, readJSON, writeJson } from "fs-extra/esm";
import { glob } from "tinyglobby";
Expand Down Expand Up @@ -168,12 +168,11 @@ export default class Build extends Base {
const matches = [...ftlContent.matchAll(FTL_MESSAGE_PATTERN)];

for (const match of matches) {
const message = match.groups?.message;
const [matched, message, _pattern] = match;
if (message) {
const namespacedMessage = `${namespace}-${message}`;
localeMessages.add(message);
allMessages.add(message);
ftlContent = ftlContent.replace(new RegExp(`^${message}`, "gm"), namespacedMessage);
ftlContent = ftlContent.replace(new RegExp(`^${escapeRegExp(matched)}`, "gm"), `${namespace}-${matched}`);
}
}

Expand Down

0 comments on commit 5561a0d

Please sign in to comment.