Skip to content

Commit

Permalink
chore: escape template literals in prebuild script (#3745)
Browse files Browse the repository at this point in the history
Co-authored-by: Nate Moore <[email protected]>
  • Loading branch information
natemoo-re and natemoo-re authored Jun 28, 2022
1 parent 8829cc7 commit 199fd91
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions scripts/cmd/prebuild.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
import * as terser from 'terser';
import esbuild from 'esbuild';
import glob from 'tiny-glob';
import fs from 'fs';
import path from 'path';
import { pathToFileURL, fileURLToPath } from 'url';

function escapeTemplateLiterals(str) {
return str.replace(/\`/g, '\\`').replace(/\$\{/g, '\\${');
}

export default async function prebuild(...args) {
let buildToString = args.indexOf('--to-string');
if (buildToString !== -1) {
Expand Down Expand Up @@ -49,7 +52,7 @@ export default async function prebuild(...args) {
* to generate this file.
*/
export default \`${esbuildresult.code.trim()}\`;`;
export default \`${escapeTemplateLiterals(esbuildresult.code.trim())}\`;`;
const url = getPrebuildURL(filepath);
await fs.promises.writeFile(url, mod, 'utf-8');
}
Expand Down

0 comments on commit 199fd91

Please sign in to comment.