-
Notifications
You must be signed in to change notification settings - Fork 1.6k
fix: test failures due to esm.sh rate limits #5511
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
Draft
OEvgeny
wants to merge
9
commits into
main
Choose a base branch
from
fix/tests
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from 1 commit
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
a873bf0
fix: test failures due to esm.sh rate limits
OEvgeny 9198719
Update test definitions
OEvgeny c39183d
Potential fix for code scanning alert no. 34: Information exposure th…
OEvgeny 62a410a
Fix nits
OEvgeny 669b127
Increase timeout
OEvgeny 0ce6194
Revert "Increase timeout"
OEvgeny 86500de
Fix import /esm/
OEvgeny 98902d3
Fix test
OEvgeny d972d32
Improve ports mapping
OEvgeny 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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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 |
---|---|---|
|
@@ -25,6 +25,7 @@ | |
"serve-handler": "6.1.6" | ||
}, | ||
"devDependencies": { | ||
"@ast-grep/napi": "^0.38.6", | ||
"tsup": "^8.3.6" | ||
} | ||
} |
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,70 @@ | ||
/* eslint-disable no-magic-numbers */ | ||
import { parse, Lang, type Edit } from '@ast-grep/napi'; | ||
|
||
// Rule for rewriting ESM imports/exports | ||
// Use playground to test and modify the rule: | ||
// https://ast-grep.github.io/playground.html#eyJtb2RlIjoiQ29uZmlnIiwibGFuZyI6ImphdmFzY3JpcHQiLCJxdWVyeSI6ImltcG9ydCAkWCBmcm9tICRTUkMiLCJyZXdyaXRlIjoiaW1wb3J0ICRYIGZyb20gJFNSQyIsInN0cmljdG5lc3MiOiJzbWFydCIsInNlbGVjdG9yIjoiIiwiY29uZmlnIjoiIyBZQU1MIFJ1bGUgaXMgbW9yZSBwb3dlcmZ1bCFcbiMgaHR0cHM6Ly9hc3QtZ3JlcC5naXRodWIuaW8vZ3VpZGUvcnVsZS1jb25maWcuaHRtbCNydWxlXG5ydWxlOlxuICBraW5kOiBzdHJpbmdfZnJhZ21lbnRcbiAgcmVnZXg6IF5cXC9cbiAgcGF0dGVybjogXG4gICAgY29udGV4dDogJEFcbiAgaW5zaWRlOlxuICAgIGtpbmQ6IHN0cmluZ1xuICAgIG50aENoaWxkOlxuICAgICAgcG9zaXRpb246IDFcbiAgICAgIHJldmVyc2U6IHRydWVcbiAgICBpbnNpZGU6XG4gICAgICBhbnk6XG4gICAgICAgIC0ga2luZDogZXhwb3J0X3N0YXRlbWVudFxuICAgICAgICAtIGtpbmQ6IGltcG9ydF9zdGF0ZW1lbnRcbiAgICAgICAgLSBraW5kOiBhcmd1bWVudHNcbiAgICAgICAgICBpbnNpZGU6XG4gICAgICAgICAgICBraW5kOiBjYWxsX2V4cHJlc3Npb25cbiAgICAgICAgICAgIHBhdHRlcm46IGltcG9ydCgkJCQpXG5maXg6XG4gIC9lc20kQVxuIiwic291cmNlIjoiLyogZXNtLnNoIC0gcmVhY3RAMTkuMS4wICovXG5leHBvcnQgKiBmcm9tIFwiL3JlYWN0QDE5LjEuMC9lczIwMjIvcmVhY3QubWpzXCI7XG5leHBvcnQgeyBkZWZhdWx0IH0gZnJvbSBcIi9yZWFjdEAxOS4xLjAvZXMyMDIyL3JlYWN0Lm1qc1wiO1xuaW1wb3J0ICogYXMgZm9vIGZyb20gXCIvcmVhY3RAMTkuMS4wL2VzMjAyMi9yZWFjdC5tanNcIjtcbmltcG9ydCAnL3Rlc3QnXG5cbmltcG9ydCgnL2Zvby8nKVxudGVzdCgnL2Zvby8nKVxuIn0= | ||
const ruleConfig = { | ||
rule: { | ||
kind: 'string_fragment', | ||
regex: '^\\/', | ||
pattern: { | ||
context: '$A' | ||
}, | ||
inside: { | ||
kind: 'string', | ||
nthChild: { | ||
position: 1, | ||
reverse: true | ||
}, | ||
inside: { | ||
any: [ | ||
{ | ||
kind: 'export_statement' | ||
}, | ||
{ | ||
kind: 'import_statement' | ||
}, | ||
{ | ||
kind: 'arguments', | ||
inside: { | ||
kind: 'call_expression', | ||
pattern: 'import($$$)' | ||
} | ||
} | ||
] | ||
} | ||
} | ||
}, | ||
fix: '/esm$A' | ||
}; | ||
|
||
export const handleEsm = async (req, res) => { | ||
try { | ||
const targetPath = req.url.replace(/^\/esm/u, ''); | ||
const upstreamUrl = `http://esm:8080${targetPath}`; | ||
|
||
const upstreamRes = await fetch(upstreamUrl); | ||
if (!upstreamRes.ok) { | ||
res.writeHead(upstreamRes.status); | ||
return res.end(await upstreamRes.text()); | ||
} | ||
const sourceJS = await upstreamRes.text(); | ||
|
||
const root = parse(Lang.JavaScript, sourceJS).root(); | ||
const edits: Edit[] = []; | ||
|
||
for (const match of root.findAll(ruleConfig)) { | ||
const text = match.getMatch('A')?.text(); | ||
text && edits.push(match.replace(ruleConfig.fix.replace('$A', text))); | ||
} | ||
|
||
const outJS = root.commitEdits(edits); | ||
res.setHeader('Content-Type', 'application/javascript'); | ||
return res.end(outJS); | ||
} catch (err) { | ||
console.error('ESM proxy error:', err); | ||
res.writeHead(500); | ||
return res.end(err.stack); | ||
|
||
} | ||
}; |
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
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
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 |
---|---|---|
|
@@ -18,3 +18,5 @@ ENTRYPOINT ["node", "./index.js"] | |
ADD serve-test.json /var/web/serve.json | ||
ADD packages/test/web-server/dist/index.js /var/web/ | ||
RUN echo {}>/var/web/package.json | ||
WORKDIR /var/web/ | ||
RUN npm i @ast-grep/[email protected] |
Oops, something went wrong.
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.