refactor(app): migrate to ES modules and drop unused mocha - #132
Merged
Conversation
Convert the app from CommonJS to ES modules: set "type": "module" in package.json and switch the three source files from require/module.exports to import/export (keeping the .js extension - no .mjs rename). Relative imports now carry their .js extension as ESM requires, and the redundant 'use strict' pragmas are dropped since ES modules are always strict. Use the node: protocol for core builtins (node:http, node:crypto) so they can never be shadowed by a userland package. Remove the unused mocha devDependency: there are no test files and the test script is a stub, so it was dead weight (Node's built-in node:test covers future needs). Behaviour is unchanged - the explicit http.createServer(app) server handle is kept. Bump minor version 1.5.2 -> 1.6.0.
Up to standards ✅🟢 Issues
|
| Metric | Results |
|---|---|
| Complexity | 0 |
| Duplication | 0 |
NEW Get contextual insights on your PRs based on Codacy's metrics, along with PR and Jira context, without leaving GitHub. Enable AI reviewer
TIP This summary will be updated as you push new changes.
|
Application node-webserver-56e4f8a-132-pr-reviews has been created. |
|
Application node-webserver-56e4f8a-132-pr-reviews is in state Running. |
|
Application node-webserver-56e4f8a-132-pr-reviews is now running new version of deployments manifests. |
|
Application node-webserver-56e4f8a-132-pr-reviews has been deleted. |
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Summary
Modernises the app to ES modules and removes a dead devDependency. Behaviour is unchanged.
ES modules
"type": "module"inapp/package.jsonand converts the three source files fromrequire/module.exportstoimport/export. Keeps the.jsextension - no.mjsrename, which is the correct idiom for an all-ESM app..jsextension (./middleware.js,./routes.js), as ESM requires.'use strict'pragmas, which are redundant under ES modules (always strict).node: builtins
node:protocol (node:http,node:crypto) so they cannot be shadowed by a userland package.Remove unused mocha
mochawas the only devDependency but there are no test files and thetestscript is a stub, so it was dead weight. Node's built-innode:testcovers future needs.Also bumps the minor version
1.5.2->1.6.0.Changes
app/package.json: add"type": "module", removedevDependencies(mocha), bump to 1.6.0app/index.js,app/middleware.js,app/routes.js: CommonJS -> ESM,node:builtinsThe explicit
http.createServer(app)server handle is deliberately kept (useful for graceful shutdown, https/http2, or WebSockets).Testing
Verified locally:
node --checkpasses for all three files as ES modulesrequire/module.exports/'use strict'remain; builtins use thenode:prefixnpm installsucceeds;mochaabsent fromnode_modulesServer is running on port 8080GET /healthzreturns{"status":"healthy"}(200)GET /returns the expected JSON (Hello World!, random number, 40-char sha1) (200), confirmingnode:cryptoresolves at runtimeContent-Encoding: gzipNo functional changes.