-
Notifications
You must be signed in to change notification settings - Fork 2k
fix(markdown-preview): Upgrade 'got' library and migrate to ES Modules #4201
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
Changes from all commits
2ed11cc
c1ab262
2f6f7ab
3ac9c79
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 | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -12,8 +12,9 @@ | |||||||||
| // See the License for the specific language governing permissions and | ||||||||||
| // limitations under the License. | ||||||||||
|
|
||||||||||
| const {app} = require('./app'); | ||||||||||
| const pkg = require('./package.json'); | ||||||||||
| const PORT = parseInt(process.env.PORT) || 8080; | ||||||||||
| import app from './app.js'; | ||||||||||
| import fs from 'fs'; | ||||||||||
|
|
||||||||||
| const pkg = JSON.parse(fs.readFileSync('./package.json')); | ||||||||||
|
Comment on lines
+16
to
+18
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. Since you're using Node.js version 20+, you can use import assertions to import JSON files directly. This is cleaner than reading and parsing the file manually, and resolves paths relative to the file, which is more robust than relying on the current working directory.
Suggested change
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. @angelcaamal another one to validate |
||||||||||
| const PORT = parseInt(process.env.PORT) || 8080; | ||||||||||
| app.listen(PORT, () => console.log(`${pkg.name} listening on port ${PORT}`)); | ||||||||||
| Original file line number | Diff line number | Diff line change | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -12,8 +12,10 @@ | |||||||||
| // See the License for the specific language governing permissions and | ||||||||||
| // limitations under the License. | ||||||||||
|
|
||||||||||
| const app = require('./app'); | ||||||||||
| const pkg = require('./package.json'); | ||||||||||
| import app from './app.js'; | ||||||||||
| import fs from 'fs'; | ||||||||||
|
|
||||||||||
| const pkg = JSON.parse(fs.readFileSync('./package.json')); | ||||||||||
|
Comment on lines
+16
to
+18
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. Since you're using Node.js version 20+, you can use import assertions to import JSON files directly. This is cleaner than reading and parsing the file manually, and resolves paths relative to the file, which is more robust than relying on the current working directory.
Suggested change
|
||||||||||
| const PORT = parseInt(process.env.PORT) || 8080; | ||||||||||
|
|
||||||||||
| app.listen(PORT, () => console.log(`${pkg.name} listening on port ${PORT}`)); | ||||||||||
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.
Using
process.cwd()can be brittle as it depends on the directory from which the Node.js process is started. In ES modules, the recommended way to get the current directory is by usingimport.meta.url. This makes file path resolution more robust.You'll also need to add
import path from 'path';andimport { fileURLToPath } from 'url';at the top of the file.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.
@angelcaamal can you take a look at this recommendation and validate whether it works?