chore: escape template literals in prebuild script (#3745)
Co-authored-by: Nate Moore <nate@astro.build>
This commit is contained in:
parent
8829cc7ab6
commit
199fd91e8f
1 changed files with 5 additions and 2 deletions
|
@ -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) {
|
||||
|
@ -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');
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue