remove filename comments

This commit is contained in:
2022-06-09 10:56:50 -05:00
parent 6e881ebd6f
commit 57f7599739
3 changed files with 38 additions and 4 deletions

View File

@@ -1,6 +1,6 @@
import { buildSync, BuildFailure, BuildOptions } from 'esbuild'
import { existsSync, writeFileSync, unlinkSync } from 'fs'
import { DistPath, ScriptPath } from './paths'
import { DistPath, ScriptBase, ScriptPath } from './paths'
import { UserScriptMetaFull } from './types'
import readMeta from './readmeta'
@@ -140,7 +140,7 @@ function runEsbuild(
let res = buildSync(opts)
let content = ''
if (res.outputFiles && res.outputFiles.length > 0) {
content = res.outputFiles[0].text
content = clearFilenameComments(res.outputFiles[0].text)
}
if (content === '') {
return {
@@ -159,3 +159,21 @@ function runEsbuild(
}
}
}
// //only remove the filename comments if there's only 1 file
// function clearFilenameComments(content: string): string {
// let regexp = new RegExp(`//\\s*${ScriptBase}/.*(?:\\n|$)`, 'g')
// let matches = content.match(regexp)
// if (matches) {
// if (matches.length === 1) {
// content = content.replace(regexp, '')
// }
// }
// return content
// }
//remove all filename comments
function clearFilenameComments(content: string): string {
let regexp = new RegExp(`//\\s*${ScriptBase}/.*(?:\\n|$)`, 'g')
return content.replace(regexp, '')
}