Repository navigation
chore!: require Node ≥24.22.1 #444
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
5 commits
Select commit
Hold shift + click to select a range
e789373
chore: modernize development toolchain
jvbriones a02b9a9
chore: modernize development toolchain
jvbriones 0a6be50
chore: modernize development toolchain
jvbriones f1e5afa
chore: modernize development toolchain
jvbriones 3a9c7c0
Merge branch 'main' into chore/modernize-node-ci
jvbriones 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
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 |
|---|---|---|
| @@ -1 +1 @@ | ||
| v20.19.1 | ||
| v24.22.2 |
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 |
|---|---|---|
| @@ -0,0 +1,212 @@ | ||
| const fs = require('fs'); | ||
| const http = require('http'); | ||
| const path = require('path'); | ||
|
|
||
| const fsPromises = fs.promises; | ||
| const artifactDirectory = path.resolve(process.argv[2] || 'dist'); | ||
| const requestTimeout = 5000; | ||
| const testTimeout = 30000; | ||
| let activeServer; | ||
|
|
||
| const contentTypes = { | ||
| '.css': 'text/css', | ||
| '.html': 'text/html', | ||
| '.js': 'text/javascript', | ||
| '.json': 'application/json', | ||
| '.svg': 'image/svg+xml', | ||
| }; | ||
|
|
||
| function fail(message) { | ||
| throw new Error(message); | ||
| } | ||
|
|
||
| function resolveArtifactPath(urlPath) { | ||
| const decodedPath = decodeURIComponent(urlPath.split('?')[0]); | ||
| const relativePath = | ||
| decodedPath === '/' ? 'index.html' : decodedPath.slice(1); | ||
| const resolvedPath = path.resolve(artifactDirectory, relativePath); | ||
|
|
||
| if ( | ||
| resolvedPath !== artifactDirectory && | ||
| !resolvedPath.startsWith(`${artifactDirectory}${path.sep}`) | ||
| ) { | ||
| return null; | ||
| } | ||
|
|
||
| return resolvedPath; | ||
| } | ||
|
|
||
| function createServer() { | ||
| return http.createServer(async (incomingRequest, response) => { | ||
| let filePath; | ||
|
|
||
| try { | ||
| filePath = resolveArtifactPath(incomingRequest.url); | ||
| } catch { | ||
| response.writeHead(400); | ||
| response.end(); | ||
| return; | ||
| } | ||
|
|
||
| let file; | ||
|
|
||
| try { | ||
| file = await fsPromises.readFile(filePath); | ||
| } catch { | ||
| response.writeHead(404); | ||
| response.end(); | ||
| return; | ||
| } | ||
|
|
||
| const contentType = | ||
| contentTypes[path.extname(filePath)] || 'application/octet-stream'; | ||
| response.writeHead(200, { 'Content-Type': contentType }); | ||
| response.end(file); | ||
| }); | ||
| } | ||
|
|
||
| function request(serverUrl, urlPath) { | ||
| return new Promise((resolve, reject) => { | ||
| const clientRequest = http.get(`${serverUrl}${urlPath}`, (response) => { | ||
| const chunks = []; | ||
|
|
||
| response.on('data', (chunk) => chunks.push(chunk)); | ||
| response.on('end', () => { | ||
| resolve({ | ||
| body: Buffer.concat(chunks), | ||
| contentType: response.headers['content-type'] || '', | ||
| statusCode: response.statusCode, | ||
| }); | ||
| }); | ||
| }); | ||
|
|
||
| clientRequest.setTimeout(requestTimeout, () => { | ||
| clientRequest.destroy(new Error(`Request timed out: ${urlPath}`)); | ||
| }); | ||
| clientRequest.on('error', reject); | ||
| }); | ||
| } | ||
|
|
||
| function localReferences(html) { | ||
| const references = new Set(); | ||
| const referencePattern = /(?:src|href)="([^"]+)"/gu; | ||
| let match; | ||
|
|
||
| while ((match = referencePattern.exec(html))) { | ||
| const reference = match[1]; | ||
| if (!/^(?:[a-z]+:|\/\/|#|data:)/iu.test(reference)) { | ||
| references.add(new URL(reference, 'http://localhost/').pathname); | ||
| } | ||
| } | ||
|
|
||
| return references; | ||
| } | ||
|
|
||
| async function runSmokeTest() { | ||
| try { | ||
| if (!(await fsPromises.stat(artifactDirectory)).isDirectory()) { | ||
| fail(`Artifact path is not a directory: ${artifactDirectory}`); | ||
| } | ||
| } catch (error) { | ||
| if (error.code === 'ENOENT') { | ||
| fail(`Artifact directory does not exist: ${artifactDirectory}`); | ||
| } | ||
| throw error; | ||
| } | ||
|
|
||
| const server = createServer(); | ||
| activeServer = server; | ||
|
|
||
| await new Promise((resolve, reject) => { | ||
| server.once('error', reject); | ||
| server.listen(0, '127.0.0.1', resolve); | ||
| }); | ||
|
|
||
| const address = server.address(); | ||
| const serverUrl = `http://127.0.0.1:${address.port}`; | ||
|
|
||
| try { | ||
| const pages = [ | ||
| { path: '/', title: 'E2E Test Dapp', script: 'main.js' }, | ||
| { | ||
| path: '/request.html', | ||
| title: 'E2E Test Dapp - Send Individual Request', | ||
| script: 'request.js', | ||
| }, | ||
| ]; | ||
| const references = new Set(['/constants.json']); | ||
|
|
||
| for (const page of pages) { | ||
| const response = await request(serverUrl, page.path); | ||
| const html = response.body.toString(); | ||
|
|
||
| if ( | ||
| response.statusCode !== 200 || | ||
| !response.contentType.startsWith('text/html') | ||
| ) { | ||
| fail(`Expected HTML page at ${page.path}`); | ||
| } | ||
| if (!html.includes(`<title>${page.title}</title>`)) { | ||
| fail(`Unexpected title at ${page.path}`); | ||
| } | ||
| if (!html.includes(`src="${page.script}"`)) { | ||
| fail(`Expected script ${page.script} in ${page.path}`); | ||
| } | ||
|
|
||
| for (const reference of localReferences(html)) { | ||
| references.add(reference); | ||
| } | ||
| } | ||
|
|
||
| for (const reference of references) { | ||
| const response = await request(serverUrl, reference); | ||
| if (response.statusCode !== 200 || response.body.length === 0) { | ||
| fail(`Expected a non-empty local asset at ${reference}`); | ||
| } | ||
|
|
||
| const extension = path.extname(reference); | ||
| const expectedContentType = contentTypes[extension]; | ||
| if ( | ||
| expectedContentType && | ||
| !response.contentType.startsWith(expectedContentType) | ||
| ) { | ||
| fail( | ||
| `Unexpected content type for ${reference}: ${response.contentType}`, | ||
| ); | ||
| } | ||
| } | ||
|
|
||
| const constants = await request(serverUrl, '/constants.json'); | ||
| JSON.parse(constants.body.toString()); | ||
|
|
||
| const missingRoute = await request(serverUrl, '/does-not-exist'); | ||
| if (missingRoute.statusCode !== 404) { | ||
| fail( | ||
| `Expected unknown route to return 404, got ${missingRoute.statusCode}`, | ||
| ); | ||
| } | ||
| } finally { | ||
| await new Promise((resolve) => server.close(resolve)); | ||
| activeServer = undefined; | ||
| } | ||
| } | ||
|
|
||
| const timeout = new Promise((_, reject) => { | ||
| const timer = setTimeout(() => { | ||
| if (activeServer) { | ||
| activeServer.closeAllConnections(); | ||
| activeServer.close(); | ||
| } | ||
| reject(new Error('Smoke test timed out')); | ||
| }, testTimeout); | ||
| timer.unref(); | ||
| }); | ||
|
|
||
| Promise.race([runSmokeTest(), timeout]) | ||
| .then(() => { | ||
| console.log(`Production artifact smoke test passed: ${artifactDirectory}`); | ||
| }) | ||
| .catch((error) => { | ||
| console.error(error.message); | ||
| process.exitCode = 1; | ||
| }); | ||
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.