remove filename comments
This commit is contained in:
22
src/build.ts
22
src/build.ts
@@ -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, '')
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user