-
Notifications
You must be signed in to change notification settings - Fork 72
remove eval
calls introduced by depd
wrapped functions
#410
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 1 commit
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
--- | ||
"@opennextjs/cloudflare": patch | ||
--- | ||
|
||
remove `eval` calls introduced by `depd` wrapped functions | ||
|
||
Some dependencies of Next.js (`raw-body` and `send`) use `depd` to deprecate some of their functions, | ||
`depd` uses `eval` to generate a deprecated version of such functions, this causes `eval` warnings in | ||
the terminal even if these functions are never called, the changes here by patching the depd `wrapfunction` | ||
function so that it still retains the same type of behavior but without using `eval` |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
32 changes: 32 additions & 0 deletions
32
packages/cloudflare/src/cli/build/patches/plugins/patch-depd-deprecations.spec.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import { describe, expect, test } from "vitest"; | ||
|
||
import { patchCode } from "../ast/util.js"; | ||
import { rule } from "./patch-depd-deprecations.js"; | ||
|
||
describe("patchDepdDeprecations", () => { | ||
test("patch", () => { | ||
const code = ` | ||
function prepareObjectStackTrace(e,t){ | ||
return t | ||
} | ||
function wrapfunction(fn,message){ | ||
if(typeof fn!=="function"){ | ||
throw new TypeError("argument fn must be a function") | ||
} | ||
var args=createArgumentsString(fn.length); | ||
var deprecate=this; | ||
var stack=getStack(); | ||
var site=callSiteLocation(stack[1]); | ||
site.name=fn.name; | ||
var deprecatedfn=eval("(function ("+args+") {\\n"+'"use strict"\\n'+"log.call(deprecate, message, site)\\n"+"return fn.apply(this, arguments)\\n"+"})"); | ||
return deprecatedfn; | ||
}`; | ||
|
||
expect(patchCode(code, rule)).toMatchInlineSnapshot(` | ||
"function prepareObjectStackTrace(e,t){ | ||
return t | ||
} | ||
function wrapfunction(fn, message) { if(typeof fn !== 'function') throw new Error("argument fn must be a function"); return (...args) => { console.warn(message); return fn(...args); } }" | ||
`); | ||
}); | ||
}); |
43 changes: 43 additions & 0 deletions
43
packages/cloudflare/src/cli/build/patches/plugins/patch-depd-deprecations.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
import { patchCode } from "../ast/util.js"; | ||
import type { ContentUpdater } from "./content-updater.js"; | ||
|
||
/** | ||
* Some dependencies of Next.js use depd to deprecate some of their functions, depd uses `eval` to generate | ||
* a deprecated version of such functions, this causes `eval` warnings in the terminal even if these functions | ||
* are never called, this function fixes that by patching the depd `wrapfunction` function so that it still | ||
* retains the same type of behavior but without using `eval` | ||
*/ | ||
export function patchDepdDeprecations(updater: ContentUpdater) { | ||
return updater.updateContent( | ||
"patch-depd-deprecations", | ||
{ filter: /\.(js|mjs|cjs|jsx|ts|tsx)$/, contentFilter: /argument fn must be a function/ }, | ||
({ contents }) => patchCode(contents, rule) | ||
); | ||
} | ||
|
||
export const rule = ` | ||
rule: | ||
kind: function_declaration | ||
pattern: function wrapfunction($FN, $MESSAGE) { $$$ } | ||
all: | ||
- has: | ||
kind: variable_declarator | ||
stopBy: end | ||
has: | ||
field: name | ||
pattern: deprecatedfn | ||
- has: | ||
kind: call_expression | ||
stopBy: end | ||
has: | ||
kind: identifier | ||
pattern: eval | ||
fix: | ||
function wrapfunction($FN, $MESSAGE) { | ||
if(typeof $FN !== 'function') throw new Error("argument fn must be a function"); | ||
return (...args) => { | ||
console.warn($MESSAGE); | ||
return $FN(...args); | ||
} | ||
} | ||
`; |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.