Skip to content

Conversation

@angelcaamal
Copy link

Description

Fixes #

Note: Before submitting a pull request, please open an issue for discussion if you are not associated with Google.

Checklist

  • I have followed guidelines from CONTRIBUTING.MD and Samples Style Guide
  • Tests pass: npm test (see Testing)
  • Lint pass: npm run lint (see Style)
  • Required CI tests pass (see CI testing)
  • These samples need a new API enabled in testing projects to pass (let us know which ones)
  • These samples need a new/updated env vars in testing projects set to pass (let us know which ones)
  • This pull request is from a branch created directly off of GoogleCloudPlatform/nodejs-docs-samples. Not a fork.
  • This sample adds a new sample directory, and I updated the CODEOWNERS file with the codeowners for this sample
  • This sample adds a new sample directory, and I created GitHub Actions workflow for this sample
  • This sample adds a new Product API, and I updated the Blunderbuss issue/PR auto-assigner with the codeowners for this sample
  • Please merge this PR for me once it is approved

Note: Any check with (dev), (experimental), or (legacy) can be ignored and should not block your PR from merging (see CI testing).

@angelcaamal angelcaamal requested review from a team as code owners December 8, 2025 22:16
@google-cla
Copy link

google-cla bot commented Dec 8, 2025

Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

View this failed invocation of the CLA check for more information.

For the most up to date status, view the checks section at the bottom of the pull request.

@product-auto-label product-auto-label bot added samples Issues that are directly related to samples. api: run Issues related to the Cloud Run API. asset: pattern DEE Asset tagging - Pattern. labels Dec 8, 2025
@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello @angelcaamal, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request modernizes the markdown-preview sample by transitioning its codebase to use ES Modules, updating several core dependencies to their latest versions, and bumping the minimum required Node.js version. These changes ensure the sample remains current with Node.js best practices and benefits from the latest features and security updates provided by its dependencies.

Highlights

  • ES Module Migration: The markdown-preview service, encompassing both its editor and renderer components, has been fully migrated from CommonJS require/module.exports syntax to modern ES Module import/export syntax.
  • Dependency Upgrades: Key dependencies including got (from v11 to v14), handlebars, and mocha have been updated to their latest major versions, bringing performance improvements and bug fixes.
  • Node.js Version Bump: The minimum required Node.js engine version has been updated from >=16.0.0 to >=20.0.0 to align with the ES Module migration and newer dependency requirements.
  • got API Adaptation: The timeout configuration for the got library was adjusted in render.js to match the breaking changes introduced in its v12 update, now requiring an object { request: 3000 } instead of a direct number.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request migrates the markdown-preview services to ES Modules and upgrades the got library. The changes are well-executed, converting require to import/export syntax and updating package.json files accordingly. I've provided a few suggestions to improve the implementation by using modern ES module features for handling file paths and importing JSON, which will make the code more robust and maintainable.

Comment on lines +27 to 34
const dirname = process.cwd();
try {
markdownDefault = await readFile(__dirname + '/templates/markdown.md');
markdownDefault = await fs.promises.readFile(
dirname + '/templates/markdown.md'
);
compiledTemplate = handlebars.compile(
await readFile(__dirname + '/templates/index.html', 'utf8')
await fs.promises.readFile(dirname + '/templates/index.html', 'utf8')
);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

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 using import.meta.url. This makes file path resolution more robust.

You'll also need to add import path from 'path'; and import { fileURLToPath } from 'url'; at the top of the file.

Suggested change
const dirname = process.cwd();
try {
markdownDefault = await readFile(__dirname + '/templates/markdown.md');
markdownDefault = await fs.promises.readFile(
dirname + '/templates/markdown.md'
);
compiledTemplate = handlebars.compile(
await readFile(__dirname + '/templates/index.html', 'utf8')
await fs.promises.readFile(dirname + '/templates/index.html', 'utf8')
);
const __dirname = path.dirname(fileURLToPath(import.meta.url));
try {
markdownDefault = await fs.promises.readFile(
path.join(__dirname, 'templates/markdown.md')
);
compiledTemplate = handlebars.compile(
await fs.promises.readFile(path.join(__dirname, 'templates/index.html'), 'utf8')
);

Comment on lines +16 to +18
import fs from 'fs';

const pkg = JSON.parse(fs.readFileSync('./package.json'));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

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
import fs from 'fs';
const pkg = JSON.parse(fs.readFileSync('./package.json'));
import pkg from './package.json' assert { type: 'json' };

Comment on lines +16 to +18
import fs from 'fs';

const pkg = JSON.parse(fs.readFileSync('./package.json'));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

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
import fs from 'fs';
const pkg = JSON.parse(fs.readFileSync('./package.json'));
import pkg from './package.json' assert { type: 'json' };

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

api: run Issues related to the Cloud Run API. asset: pattern DEE Asset tagging - Pattern. samples Issues that are directly related to samples.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant