mirror of
https://github.com/zhigang1992/esbuild.git
synced 2026-01-12 09:03:40 +08:00
enable custom hints per api kind
This commit is contained in:
@@ -117,6 +117,8 @@ var helpText = func(colors logger.Colors) string {
|
||||
}
|
||||
|
||||
func main() {
|
||||
logger.API = logger.CLIAPI
|
||||
|
||||
osArgs := os.Args[1:]
|
||||
heapFile := ""
|
||||
traceFile := ""
|
||||
|
||||
@@ -47,6 +47,8 @@ type outgoingPacket struct {
|
||||
}
|
||||
|
||||
func runService(sendPings bool) {
|
||||
logger.API = logger.JSAPI
|
||||
|
||||
service := serviceType{
|
||||
callbacks: make(map[uint32]responseCallback),
|
||||
rebuilds: make(map[int]rebuildCallback),
|
||||
|
||||
@@ -432,7 +432,14 @@ func parseFile(args parseArgs) {
|
||||
}
|
||||
if args.options.Platform != config.PlatformNode {
|
||||
if _, ok := resolver.BuiltInNodeModules[record.Path.Text]; ok {
|
||||
hint = " (set platform to \"node\" when building for node)"
|
||||
switch logger.API {
|
||||
case logger.CLIAPI:
|
||||
hint = " (use \"--platform=node\" when building for node)"
|
||||
case logger.JSAPI:
|
||||
hint = " (use \"platform: 'node'\" when building for node)"
|
||||
case logger.GoAPI:
|
||||
hint = " (use \"Platform: api.PlatformNode\" when building for node)"
|
||||
}
|
||||
}
|
||||
}
|
||||
if absResolveDir == "" && pluginName != "" {
|
||||
@@ -1912,9 +1919,18 @@ func (b *Bundle) Compile(log logger.Log, options config.Options, timer *helpers.
|
||||
for _, outputFile := range outputFiles {
|
||||
lowerAbsPath := lowerCaseAbsPathForWindows(outputFile.AbsPath)
|
||||
if sourceIndex, ok := sourceAbsPaths[lowerAbsPath]; ok {
|
||||
hint := ""
|
||||
switch logger.API {
|
||||
case logger.CLIAPI:
|
||||
hint = " (use \"--allow-overwrite\" to allow this)"
|
||||
case logger.JSAPI:
|
||||
hint = " (use \"allowOverwrite: true\" to allow this)"
|
||||
case logger.GoAPI:
|
||||
hint = " (use \"AllowOverwrite: true\" to allow this)"
|
||||
}
|
||||
log.AddError(nil, logger.Loc{},
|
||||
fmt.Sprintf("Refusing to overwrite input file %q without permission (enable \"allow overwrite\" to proceed)",
|
||||
b.files[sourceIndex].inputFile.Source.PrettyPath))
|
||||
fmt.Sprintf("Refusing to overwrite input file %q%s",
|
||||
b.files[sourceIndex].inputFile.Source.PrettyPath, hint))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1278,7 +1278,7 @@ func TestRequireFSBrowser(t *testing.T) {
|
||||
AbsOutputFile: "/out.js",
|
||||
Platform: config.PlatformBrowser,
|
||||
},
|
||||
expectedScanLog: `entry.js: error: Could not resolve "fs" (set platform to "node" when building for node)
|
||||
expectedScanLog: `entry.js: error: Could not resolve "fs" (use "Platform: api.PlatformNode" when building for node)
|
||||
`,
|
||||
})
|
||||
}
|
||||
@@ -1335,7 +1335,7 @@ func TestImportFSBrowser(t *testing.T) {
|
||||
AbsOutputFile: "/out.js",
|
||||
Platform: config.PlatformBrowser,
|
||||
},
|
||||
expectedScanLog: `entry.js: error: Could not resolve "fs" (set platform to "node" when building for node)
|
||||
expectedScanLog: `entry.js: error: Could not resolve "fs" (use "Platform: api.PlatformNode" when building for node)
|
||||
`,
|
||||
})
|
||||
}
|
||||
@@ -1396,7 +1396,7 @@ func TestExportFSBrowser(t *testing.T) {
|
||||
AbsOutputFile: "/out.js",
|
||||
Platform: config.PlatformBrowser,
|
||||
},
|
||||
expectedScanLog: `entry.js: error: Could not resolve "fs" (set platform to "node" when building for node)
|
||||
expectedScanLog: `entry.js: error: Could not resolve "fs" (use "Platform: api.PlatformNode" when building for node)
|
||||
`,
|
||||
})
|
||||
}
|
||||
@@ -2646,7 +2646,8 @@ func TestNoOverwriteInputFileError(t *testing.T) {
|
||||
Mode: config.ModeBundle,
|
||||
AbsOutputDir: "/",
|
||||
},
|
||||
expectedCompileLog: "error: Refusing to overwrite input file: entry.js\n",
|
||||
expectedCompileLog: `error: Refusing to overwrite input file "entry.js" (use "AllowOverwrite: true" to allow this)
|
||||
`,
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
@@ -349,6 +349,17 @@ func errorAndWarningSummary(errors int, warnings int, shownErrors int, shownWarn
|
||||
}
|
||||
}
|
||||
|
||||
type APIKind uint8
|
||||
|
||||
const (
|
||||
GoAPI APIKind = iota
|
||||
CLIAPI
|
||||
JSAPI
|
||||
)
|
||||
|
||||
// This can be used to customize error messages for the current API kind
|
||||
var API APIKind
|
||||
|
||||
type TerminalInfo struct {
|
||||
IsTTY bool
|
||||
UseColorEscapes bool
|
||||
|
||||
@@ -418,7 +418,11 @@ func validateDefines(
|
||||
// The key must be a dot-separated identifier list
|
||||
for _, part := range strings.Split(key, ".") {
|
||||
if !js_lexer.IsIdentifier(part) {
|
||||
log.AddError(nil, logger.Loc{}, fmt.Sprintf("Invalid define key: %q", key))
|
||||
if part == key {
|
||||
log.AddError(nil, logger.Loc{}, fmt.Sprintf("The define key %q must be a valid identifier", key))
|
||||
} else {
|
||||
log.AddError(nil, logger.Loc{}, fmt.Sprintf("The define key %q contains invalid identifier %q", key, part))
|
||||
}
|
||||
continue
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user