-
Notifications
You must be signed in to change notification settings - Fork 7
Add node-fetch patch for isAbortSignal #433
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,17 @@ | ||
| package bundler | ||
|
|
||
| func init() { | ||
| patches["node-fetch"] = patchModule{ | ||
| Module: "node-fetch", | ||
| Filename: "src/utils/is", | ||
| Functions: map[string]patchAction{ | ||
| "isAbortSignal": { | ||
| After: `if (result) { return true; } | ||
| if (_args[0] && _args[0].constructor.name === 'AbortSignal') { | ||
| return true; | ||
| } | ||
| `, | ||
| }, | ||
| }, | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change | ||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -101,26 +101,47 @@ func createPlugin(logger logger.Logger, dir string, shimSourceMap bool) api.Plug | |||||||||||||
| } | ||||||||||||||
| contents := string(buf) | ||||||||||||||
| var suffix strings.Builder | ||||||||||||||
| isJS := strings.HasSuffix(args.Path, ".js") | ||||||||||||||
| for fn, mod := range mod.Functions { | ||||||||||||||
| fnname := "function " + fn | ||||||||||||||
| index := strings.Index(contents, fnname) | ||||||||||||||
| var isConstVariable bool | ||||||||||||||
| if index == -1 { | ||||||||||||||
| continue | ||||||||||||||
| fnname = "const " + fn + " = " | ||||||||||||||
| index = strings.Index(contents, fnname) | ||||||||||||||
| isConstVariable = true | ||||||||||||||
| if index == -1 { | ||||||||||||||
| continue | ||||||||||||||
| } | ||||||||||||||
| } | ||||||||||||||
| eol := searchBackwards(contents, index, '\n') | ||||||||||||||
| if eol < 0 { | ||||||||||||||
| continue | ||||||||||||||
| } | ||||||||||||||
| prefix := strings.TrimSpace(contents[eol+1 : index]) | ||||||||||||||
| isAsync := strings.Contains(prefix, "async") | ||||||||||||||
| isExport := strings.Contains(prefix, "export") | ||||||||||||||
| newname := "__agentuity_" + fn | ||||||||||||||
| newfnname := "function " + newname | ||||||||||||||
| var newfnname string | ||||||||||||||
| if isConstVariable { | ||||||||||||||
| newfnname = "const " + newname + " = " | ||||||||||||||
| } else { | ||||||||||||||
| newfnname = "function " + newname | ||||||||||||||
| } | ||||||||||||||
| var fnprefix string | ||||||||||||||
| if isAsync { | ||||||||||||||
| fnprefix = "async " | ||||||||||||||
| } | ||||||||||||||
| if isExport { | ||||||||||||||
| fnprefix += "export " + fnprefix | ||||||||||||||
|
Comment on lines
+135
to
+136
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fix incorrect string concatenation in export prefix. The export prefix is being concatenated incorrectly. The current code produces -if isExport {
- fnprefix += "export " + fnprefix
-}
+if isExport {
+ fnprefix = "export " + fnprefix
+}📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||||||||||
| } | ||||||||||||||
| contents = strings.Replace(contents, fnname, newfnname, 1) | ||||||||||||||
| suffix.WriteString(fnprefix + fnname + "(...args) {\n") | ||||||||||||||
| if isJS { | ||||||||||||||
| suffix.WriteString(fnprefix + fnname + "() => {\n") | ||||||||||||||
| suffix.WriteString("let args = arguments;\n") | ||||||||||||||
|
Comment on lines
+139
to
+141
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fix malformed arrow function syntax for JS targets. The generated arrow function syntax is incorrect. Arrow functions should be declared as -if isJS {
- suffix.WriteString(fnprefix + fnname + "() => {\n")
- suffix.WriteString("let args = arguments;\n")
+if isJS {
+ suffix.WriteString(fnprefix + fnname + "(...args) => {\n")Also note that arrow functions don't have their own 📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||||||||||
| } else { | ||||||||||||||
| suffix.WriteString(fnprefix + fnname + "(...args) {\n") | ||||||||||||||
| } | ||||||||||||||
| suffix.WriteString("\tlet _args = args;\n") | ||||||||||||||
| if mod.Before != "" { | ||||||||||||||
| suffix.WriteString(mod.Before) | ||||||||||||||
|
|
@@ -150,7 +171,7 @@ func createPlugin(logger logger.Logger, dir string, shimSourceMap bool) api.Plug | |||||||||||||
| } | ||||||||||||||
| } | ||||||||||||||
| loader := api.LoaderJS | ||||||||||||||
| if strings.HasSuffix(args.Path, ".ts") { | ||||||||||||||
| if !isJS { | ||||||||||||||
| loader = api.LoaderTS | ||||||||||||||
| } | ||||||||||||||
| return api.OnLoadResult{ | ||||||||||||||
|
|
||||||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🛠️ Refactor suggestion
Consider defensive programming for constructor name check.
The
constructor.nameproperty can be minified or altered in production builds, making this check potentially unreliable. Consider adding additional checks or usinginstanceofif the AbortSignal class is available.After: `if (result) { return true; } -if (_args[0] && _args[0].constructor.name === 'AbortSignal') { +if (_args[0] && (_args[0].constructor.name === 'AbortSignal' || (typeof AbortSignal !== 'undefined' && _args[0] instanceof AbortSignal))) { return true; } `,📝 Committable suggestion
🤖 Prompt for AI Agents