Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

chore(ci): migrate ai-platform/snippets via ESM#4102

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Draft
davidcavazos wants to merge7 commits intomain
base:main
Choose a base branch
Loading
fromcustard-ai-module

Conversation

@davidcavazos
Copy link

@davidcavazosdavidcavazos commentedMay 30, 2025
edited
Loading

Based from#4100

Experiment to migrate CJS to ESM, adding"type": "module" to package.json.

cd ai-platform/snippetsnpx eslint-cjs-to-esm"**/*.js" --fixnpx lebab --replace. --transform commonjs
  • Pleasemerge this PR for me once it is approved

Note: Any check with(dev),(experimental), or(legacy) can be ignored and shouldnot block your PR from merging (seeCI testing).

@product-auto-labelproduct-auto-labelbot added samplesIssues that are directly related to samples. api: aiplatformIssues related to the AI Platform API. labelsMay 30, 2025
Copy link
Contributor

@gemini-code-assistgemini-code-assistbot left a comment

Choose a reason for hiding this comment

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

Hello@davidcavazos, 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!

Summary of Changes

Hello team! Gemini here to provide a summary of this pull request.

This PR focuses on migrating theai-platform/snippets directory from CommonJS (CJS) to ECMAScript Modules (ESM). This is an experimental change as noted in the description, utilizing tools likeeslint-cjs-to-esm andlebab to automate the conversion process.

In addition to the module system migration, the PR also updates several package dependencies and development dependencies within theai-platform/snippets package. A new CI configuration file is added, and the CI test configurations are updated to reflect that theai-platform/snippets tests are now expected to pass in the main CI run.

Highlights

  • ESM Migration: The core change is the migration of JavaScript files inai-platform/snippets from CommonJS (require/module.exports) to ECMAScript Modules (import/export). This involves changes across numerous snippet and test files.
  • Dependency Updates: Several dependencies and devDependencies inai-platform/snippets/package.json have been updated to newer versions, including@google-cloud/aiplatform,@google-cloud/bigquery,chai,mocha,uuid, andsinon.
  • CI Configuration Changes: The CI configuration is updated to removeai-platform/snippets from the list of failing tests in the main CI and add it to the list of tests skipped in the dev CI (as they are expected to pass in prod). A newci-setup.json file is added for the directory.

Changelog

Click here to see the changelog
  • .github/config/nodejs-dev.jsonc
    • Addedai-platform/snippets to the list of directories skipped in dev CI (line 80).
  • .github/config/nodejs.jsonc
    • Removedai-platform/snippets from the list of directories with failing tests in main CI (line 78).
  • ai-platform/snippets/ci-setup.json
    • Added new CI setup file with timeout and secret configuration (lines 1-6).
  • ai-platform/snippets/expensive-test/create-data-labeling-job-image.test.js
    • Convertedrequire statements toimport statements for built-in modules (path,child_process) and external libraries (chai,mocha,uuid) (lines 19-23).
  • ai-platform/snippets/expensive-test/create-data-labeling-job-video.test.js
    • Convertedrequire statements toimport statements for built-in modules (path,child_process) and external libraries (chai,mocha,uuid) (lines 19-23).
  • ai-platform/snippets/expensive-test/create-data-labeling-job.test.js
    • Convertedrequire statements toimport statements for built-in modules (path,child_process) and external libraries (chai,mocha,uuid) (lines 19-23).
  • ai-platform/snippets/expensive-test/get-training-pipeline.test.js
    • Convertedrequire statements toimport statements for built-in modules (path,child_process) and external libraries (chai,mocha) (lines 19-22).
  • ai-platform/snippets/expensive-test/import-data-text-entity-extraction.test.js
    • Convertedrequire statements toimport statements for built-in modules (path,child_process) and external libraries (chai,mocha) (lines 19-22).
  • ai-platform/snippets/expensive-test/import-data-text-sentiment-analysis.test.js
    • Convertedrequire statements toimport statements for built-in modules (path,child_process) and external libraries (chai,mocha) (lines 19-22).
  • ai-platform/snippets/expensive-test/import-data-video-object-tracking.test.js
    • Convertedrequire statements toimport statements for built-in modules (path,child_process) and external libraries (chai,mocha) (lines 19-22).
  • ai-platform/snippets/gemma2PredictGpu.js
    • Convertedmodule.exports toexport default (line 68).
  • ai-platform/snippets/gemma2PredictTpu.js
    • Convertedmodule.exports toexport default (line 71).
  • ai-platform/snippets/imagen-edit-image-inpainting-insert-mask.js
    • Convertedrequire('fs') torequire('node:fs') andrequire('util') torequire('node:util') (lines 47-48).
  • ai-platform/snippets/imagen-edit-image-inpainting-remove-mask.js
    • Convertedrequire('fs') torequire('node:fs') andrequire('util') torequire('node:util') (lines 47-48).
  • ai-platform/snippets/imagen-edit-image-mask-free.js
    • Convertedrequire('fs') torequire('node:fs') andrequire('util') torequire('node:util') (lines 46-47).
  • ai-platform/snippets/imagen-edit-image-outpainting-mask.js
    • Convertedrequire('fs') torequire('node:fs') andrequire('util') torequire('node:util') (lines 47-48).
  • ai-platform/snippets/imagen-generate-image.js
    • Convertedrequire('fs') torequire('node:fs') andrequire('util') torequire('node:util') (lines 45-46).
  • ai-platform/snippets/imagen-get-short-form-image-captions.js
    • Convertedrequire('fs') torequire('node:fs') (line 45).
  • ai-platform/snippets/imagen-get-short-form-image-responses.js
    • Convertedrequire('fs') torequire('node:fs') (line 47).
  • ai-platform/snippets/package.json
    • Added"type": "module" to enable ESM (line 6).
    • Updated test script to include--reporter list (line 14).
    • Updated@google-cloud/aiplatform dependency from ^3.0.0 to ^4.0.0 (line 17).
    • Updated@google-cloud/bigquery dependency from ^7.0.0 to ^8.0.0 (line 18).
    • Updatedchai devDependency from ^4.5.0 to ^5.0.0 (line 23).
    • Updatedmocha devDependency from ^10.0.0 to ^11.0.0 (line 24).
    • Updateduuid devDependency from ^10.0.0 to ^11.0.0 (line 25).
    • Updatedsinon devDependency from ^18.0.0 to ^20.0.0 (line 26).
  • ai-platform/snippets/predict-custom-trained-model.js
    • Convertedrequire('util') torequire('node:util') andrequire('fs') torequire('node:fs') (lines 30-31).
  • ai-platform/snippets/predict-image-classification.js
    • Convertedrequire('fs') torequire('node:fs') (line 55).
  • ai-platform/snippets/predict-image-from-image-and-text.js
    • Convertedrequire('fs') torequire('node:fs') (line 57).
    • Convertedexports.predictImageFromImageAndText = main toexport {main as predictImageFromImageAndText} (line 98).
  • ai-platform/snippets/predict-image-object-detection.js
    • Convertedrequire('fs') torequire('node:fs') (line 55).
  • ai-platform/snippets/test/batch-prediction-gemini.test.js
    • Convertedrequire statements toimport statements for external libraries (chai,mocha,@google-cloud/aiplatform) and built-in module (child_process) (lines 19-22).
    • Aliased importedexecSync fromnode:child_process to_execSync (line 21).
  • ai-platform/snippets/test/create-batch-prediction-job-text-classification.test.js
    • Convertedrequire statements toimport statements for external libraries (chai,mocha,uuid,@google-cloud/aiplatform) and built-in module (child_process) (lines 19-25).
    • Aliased importedexecSync fromnode:child_process to_execSync (line 22).
  • ai-platform/snippets/test/create-batch-prediction-job-text-entity-extraction.test.js
    • Convertedrequire statements toimport statements for external libraries (chai,mocha,uuid,@google-cloud/aiplatform) and built-in module (child_process) (lines 19-25).
  • ai-platform/snippets/test/create-batch-prediction-job-text-sentiment-analysis.test.js
    • Convertedrequire statements toimport statements for external libraries (chai,mocha,uuid,@google-cloud/aiplatform) and built-in module (child_process) (lines 19-25).
  • ai-platform/snippets/test/create-batch-prediction-job-video-classification.test.js
    • Convertedrequire statements toimport statements for built-in modules (path,child_process) and external libraries (chai,mocha,uuid,@google-cloud/aiplatform) (lines 19-27).
  • ai-platform/snippets/test/create-batch-prediction-job-video-object-tracking.test.js
    • Convertedrequire statements toimport statements for built-in modules (path,child_process) and external libraries (chai,mocha,uuid,@google-cloud/aiplatform) (lines 19-27).
  • ai-platform/snippets/test/create-custom-job.test.js
    • Convertedrequire statements toimport statements for built-in modules (path,child_process) and external libraries (chai,mocha,uuid) (lines 19-23).
  • ai-platform/snippets/test/create-dataset-image.test.js
    • Convertedrequire statements toimport statements for built-in modules (path,child_process) and external libraries (chai,mocha,uuid) (lines 19-23).
  • ai-platform/snippets/test/create-dataset-tabular-bigquery.test.js
    • Convertedrequire statements toimport statements for built-in modules (path,child_process) and external libraries (chai,mocha,uuid) (lines 19-23).
  • ai-platform/snippets/test/create-dataset-tabular-gcs.test.js
    • Convertedrequire statements toimport statements for built-in modules (path,child_process) and external libraries (chai,mocha,uuid) (lines 19-23).
  • ai-platform/snippets/test/create-dataset-text.test.js
    • Convertedrequire statements toimport statements for built-in modules (path,child_process) and external libraries (chai,mocha,uuid) (lines 19-23).
  • ai-platform/snippets/test/create-dataset-video.test.js
    • Convertedrequire statements toimport statements for built-in modules (path,child_process) and external libraries (chai,mocha,uuid) (lines 19-23).
  • ai-platform/snippets/test/create-dataset.test.js
    • Convertedrequire statements toimport statements for built-in modules (path,child_process) and external libraries (chai,mocha,uuid) (lines 19-23).
  • ai-platform/snippets/test/create-endpoint.test.js
    • Convertedrequire statements toimport statements for built-in module (child_process) and external libraries (chai,mocha,uuid) (lines 19-23).
  • ai-platform/snippets/test/create-featurestore-fixed-nodes-sample.test.js
    • Convertedrequire statements toimport statements for built-in module (child_process) and external libraries (chai,mocha,uuid) (lines 19-23).
  • ai-platform/snippets/test/create-featurestore-sample.test.js
    • Convertedrequire statements toimport statements for built-in module (child_process) and external libraries (chai,mocha,uuid) (lines 19-23).
  • ai-platform/snippets/test/create-hyperparameter-tuning-job.test.js
    • Convertedrequire statements toimport statements for built-in module (child_process) and external libraries (chai,mocha,uuid,@google-cloud/aiplatform) (lines 19-26).
  • ai-platform/snippets/test/create-training-pipeline-image-classification.test.js
    • Convertedrequire statements toimport statements for built-in module (child_process) and external libraries (chai,mocha,uuid,@google-cloud/aiplatform) (lines 19-26).
  • ai-platform/snippets/test/create-training-pipeline-image-object-detection.test.js
    • Convertedrequire statements toimport statements for built-in modules (path,child_process) and external libraries (chai,mocha,uuid,@google-cloud/aiplatform) (lines 19-28).
  • ai-platform/snippets/test/create-training-pipeline-tabular-classification.test.js
    • Convertedrequire statements toimport statements for built-in modules (path,child_process) and external libraries (chai,mocha,uuid,@google-cloud/aiplatform) (lines 19-28).
  • ai-platform/snippets/test/create-training-pipeline-tabular-regression.test.js
    • Convertedrequire statements toimport statements for built-in modules (path,child_process) and external libraries (chai,mocha,uuid,@google-cloud/aiplatform) (lines 19-28).
  • ai-platform/snippets/test/create-training-pipeline-text-entity-extraction.test.js
    • Convertedrequire statements toimport statements for built-in modules (path,child_process) and external libraries (chai,mocha,uuid,@google-cloud/aiplatform) (lines 19-28).
  • ai-platform/snippets/test/create-training-pipeline-text-sentiment-analysis.test.js
    • Convertedrequire statements toimport statements for built-in modules (path,child_process) and external libraries (chai,mocha,uuid,@google-cloud/aiplatform) (lines 19-28).
  • ai-platform/snippets/test/create-training-pipeline-video-action-recognition.test.js
    • Convertedrequire statements toimport statements for built-in module (child_process) and external libraries (chai,mocha,uuid,@google-cloud/aiplatform) (lines 19-26).
  • ai-platform/snippets/test/create-training-pipeline-video-classification.test.js
    • Convertedrequire statements toimport statements for built-in modules (path,child_process) and external libraries (chai,mocha,uuid,@google-cloud/aiplatform) (lines 19-28).
  • ai-platform/snippets/test/create-training-pipeline-video-object-tracking.test.js
    • Convertedrequire statements toimport statements for built-in modules (path,child_process) and external libraries (chai,mocha,uuid,@google-cloud/aiplatform) (lines 19-28).
  • ai-platform/snippets/test/deploy-model.test.js
    • Convertedrequire statements toimport statements for built-in module (child_process) and external libraries (chai,mocha,uuid) (lines 19-23).
  • ai-platform/snippets/test/embedding-model-tuning.test.js
    • Convertedrequire statements toimport statements for built-in modules (path,child_process) and external libraries (chai,mocha,@google-cloud/aiplatform) (lines 19-23).
  • ai-platform/snippets/test/entity-type-samples.test.js
    • Convertedrequire statements toimport statements for built-in module (child_process) and external libraries (chai,mocha,uuid) (lines 19-23).
  • ai-platform/snippets/test/export-model-tabular-classification.test.js
    • Convertedrequire statements toimport statements for built-in modules (path,child_process) and external libraries (chai,mocha) (lines 19-22).
  • ai-platform/snippets/test/feature-samples.test.js
    • Convertedrequire statements toimport statements for built-in module (child_process) and external libraries (chai,mocha,uuid) (lines 19-23).
  • ai-platform/snippets/test/feature-values-samples.test.js
    • Convertedrequire statements toimport statements for built-in module (child_process) and external libraries (@google-cloud/bigquery,chai,mocha,uuid) (lines 19-24).
  • ai-platform/snippets/test/featurestore-samples.test.js
    • Convertedrequire statements toimport statements for built-in module (child_process) and external libraries (chai,mocha,uuid) (lines 19-23).
  • ai-platform/snippets/test/gemma2Prediction.test.js
    • Convertedrequire statements toimport statements for external libraries (chai,mocha,sinon) and local files (../gemma2PredictGpu.js,../gemma2PredictTpu.js) (lines 19-23).
  • ai-platform/snippets/test/get-custom-job.test.js
    • Convertedrequire statements toimport statements for built-in modules (path,child_process) and external libraries (chai,mocha) (lines 19-22).
  • ai-platform/snippets/test/get-hyperparameter-tuning-job.test.js
    • Convertedrequire statements toimport statements for built-in module (child_process) and external libraries (chai,mocha) (lines 19-21).
  • ai-platform/snippets/test/get-model-evaluation-slice.test.js
    • Convertedrequire statements toimport statements for built-in modules (path,child_process) and external libraries (chai,mocha) (lines 19-22).
  • ai-platform/snippets/test/get-model-evaluation-tabular-classification.test.js
    • Convertedrequire statements toimport statements for built-in modules (path,child_process) and external libraries (chai,mocha) (lines 19-22).
  • ai-platform/snippets/test/get-model-evaluation-tabular-regression.test.js
    • Convertedrequire statements toimport statements for built-in modules (path,child_process) and external libraries (chai,mocha) (lines 19-22).
  • ai-platform/snippets/test/get-model-evaluation-video-action-recognition.test.js
    • Convertedrequire statements toimport statements for built-in module (child_process) and external libraries (chai,mocha) (lines 19-21).
  • ai-platform/snippets/test/get-model-evaluation-video-classification.test.js
    • Convertedrequire statements toimport statements for built-in modules (path,child_process) and external libraries (chai,mocha) (lines 19-22).
  • ai-platform/snippets/test/get-model-evaluation-video-object-tracking.test.js
    • Convertedrequire statements toimport statements for built-in modules (path,child_process) and external libraries (chai,mocha) (lines 19-22).
  • ai-platform/snippets/test/get-model.test.js
    • Convertedrequire statements toimport statements for built-in modules (path,child_process) and external libraries (chai,mocha) (lines 19-22).
  • ai-platform/snippets/test/get-training-pipeline.test.js
    • Convertedrequire statements toimport statements for built-in module (child_process) and external libraries (chai,mocha) (lines 19-21).
  • ai-platform/snippets/test/imagen.test.js
    • Convertedrequire statements toimport statements for built-in modules (path,child_process) and external libraries (chai,mocha) (lines 19-22).
  • ai-platform/snippets/test/import-data-video-classification.test.js
    • Convertedrequire statements toimport statements for built-in modules (path,child_process) and external libraries (chai,mocha) (lines 19-22).
  • ai-platform/snippets/test/list-endpoints.test.js
    • Convertedrequire statements toimport statements for built-in modules (path,child_process) and external libraries (chai,mocha) (lines 18-21).
  • ai-platform/snippets/test/list-model-evaluation-slices.test.js
    • Convertedrequire statements toimport statements for built-in modules (path,child_process) and external libraries (chai,mocha) (lines 19-22).
  • ai-platform/snippets/test/predict-image-from-image-and-text.test.js
    • Convertedrequire statements toimport statements for external libraries (chai,mocha,sinon) and local file (../predict-image-from-image-and-text) (lines 19-22).
  • ai-platform/snippets/test/predict-image-object-detection.test.js
    • Convertedrequire statements toimport statements for built-in modules (path,child_process) and external libraries (chai,mocha) (lines 19-22).
  • ai-platform/snippets/test/predict-tabular-classification.test.js
    • Convertedrequire statements toimport statements for built-in modules (path,child_process) and external libraries (chai,mocha) (lines 19-22).
  • ai-platform/snippets/test/predict-tabular-regression.test.js
    • Convertedrequire statements toimport statements for built-in modules (path,child_process) and external libraries (chai,mocha) (lines 19-22).
  • ai-platform/snippets/test/predict-text-classification.test.js
    • Convertedrequire statements toimport statements for built-in modules (path,child_process) and external libraries (chai,mocha) (lines 19-22).
  • ai-platform/snippets/test/predict-text-embeddings.test.js
    • Convertedrequire statements toimport statements for built-in modules (path,child_process) and external libraries (chai,mocha) (lines 19-22).
  • ai-platform/snippets/test/predict-text-entity-extraction.test.js
    • Convertedrequire statements toimport statements for built-in modules (path,child_process) and external libraries (chai,mocha) (lines 19-22).
  • ai-platform/snippets/test/upload-model.test.js
    • Convertedrequire statements toimport statements for built-in modules (path,child_process) and external libraries (chai,mocha,uuid) (lines 19-23).
Using Gemini Code Assist

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

Invoking Gemini

You can request assistance from Gemini at any point in your pull request via creating an issue comment (i.e. comment on the pull request page) using either/gemini <command> or@gemini-code-assist <command>. Below is a summary of the supported commands.

FeatureCommandDescription
Code Review/gemini reviewPerforms a code review for the current pull request in its current state.
Pull Request Summary/gemini summaryProvides a summary of the current pull request in its current state.
Comment@gemini-code-assistResponds in comments when explicitly tagged, both in issue comments and review comments.
Help/gemini helpDisplays 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 foundhere.

Limitations & Feedback

Gemini Code Assist is currently in preview and 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 to provide feedback.

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


From CJS to ESM,
A module journey starts,
Imports now lead the way,
Changing code's old parts,
A modern Node.js heart.

Footnotes

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

Copy link
Contributor

@gemini-code-assistgemini-code-assistbot 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 PR initiates the migration ofai-platform/snippets to ES Modules. While the intention is good, the migration appears incomplete, with issues related to__dirname usage in ESM contexts and inconsistent module imports. Addressing these is crucial for the snippets to function correctly.

Summary of Findings

  • Usage of__dirname in ES Modules:__dirname is not available in ES modules by default, causingReferenceError in test files. Update these usingimport.meta.url andfileURLToPath.
  • Incomplete CJS to ESM Conversion (require statements): Several files (gemma2Predict*.js,featurestore tests, and snippet files likeimagen-*.js) still containrequire() calls, particularly for@google-cloud/aiplatform and Node.js built-in modules. Convert these toimport statements.
  • Inconsistent Import Styles: The import style for@google-cloud/aiplatform (default vs. namedv1 import) varies across test files. Standardize this.
  • Dependency Version Bumps: Major versions of dependencies (e.g.,@google-cloud/aiplatform,chai,mocha) have been bumped. Ensure all snippets are re-tested with these new versions to catch breaking changes.

Merge Readiness

This pull request has issues related to the incomplete ESM migration (usage of__dirname and remainingrequire statements). These issues will likely cause runtime errors and test failures. Therefore, I recommend that these changesnot be merged until these issues are addressed. After the fixes, thorough testing of all snippets would be advisable, especially given the major dependency version upgrades. I am not authorized to approve pull requests.

import{v4asuuid}from'uuid';
importcpfrom'node:child_process';
constexecSync=cmd=>cp.execSync(cmd,{encoding:'utf-8'});
constcwd=path.join(__dirname,'..');
Copy link
Contributor

Choose a reason for hiding this comment

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

high

The__dirname variable is not available by default in ES modules, leading to aReferenceError at runtime. Refactor to determine the current directory path in an ESM context.

This issue applies to many other test files using__dirname:

  • ai-platform/snippets/expensive-test/create-data-labeling-job-video.test.js
  • ai-platform/snippets/expensive-test/create-data-labeling-job.test.js
  • ai-platform/snippets/test/create-batch-prediction-job-video-classification.test.js
  • ...and others.

Update these files to use the ESM-compatible way of getting the directory name?

Suggested change
constcwd=path.join(__dirname,'..');
import{fileURLToPath}from'node:url';
import{dirname}from'node:path';
const__filename=fileURLToPath(import.meta.url);
const__dirname=dirname(__filename);
constcwd=path.join(__dirname,'..');


const{assert}=require('chai');
import{assert}from'chai';
const{FeaturestoreServiceClient}=require('@google-cloud/aiplatform').v1;
Copy link
Contributor

Choose a reason for hiding this comment

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

high

Therequire('@google-cloud/aiplatform').v1 statement forFeaturestoreServiceClient was not converted to an ESimport. In an ESM context, this will likely cause an error.

This issue is also present in other feature store related test files:

  • ai-platform/snippets/test/create-featurestore-sample.test.js
  • ai-platform/snippets/test/entity-type-samples.test.js
  • ai-platform/snippets/test/feature-samples.test.js
  • ai-platform/snippets/test/feature-values-samples.test.js (which also has arequire for@google-cloud/bigquery that needs conversion).

Update these to useimport syntax?

Suggested change
const{FeaturestoreServiceClient}=require('@google-cloud/aiplatform').v1;
import{FeaturestoreServiceClient}from'@google-cloud/aiplatform';
import{v1}from'@google-cloud/aiplatform';

Comment on lines +47 to +48
constfs=require('node:fs');
constutil=require('node:util');
Copy link
Contributor

Choose a reason for hiding this comment

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

medium

Theserequire calls forfs andutil are inside a function within an ES module. Use top-levelimport statements for better ESM compatibility. This also applies to therequire('@google-cloud/aiplatform') on line 30.

This pattern is present in several otherimagen-*.js,predict-custom-trained-model.js,predict-image-classification.js, andpredict-image-object-detection.js files. Refactor to use top-level imports?

importfsfrom'node:fs';importutilfrom'node:util';

constexecSync=cmd=>cp.execSync(cmd,{encoding:'utf-8'});

constaiplatform=require('@google-cloud/aiplatform');
importaiplatformfrom'@google-cloud/aiplatform';
Copy link
Contributor

Choose a reason for hiding this comment

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

medium

The importimport aiplatform from '@google-cloud/aiplatform'; is a default import. Later,aiplatform.v1.JobServiceClient is used.

Other files (e.g.,create-batch-prediction-job-text-classification.test.js) useimport { v1 } from '@google-cloud/aiplatform'; followed bynew v1.JobServiceClient(). Standardize the import style for@google-cloud/aiplatform across test files for consistency. Check the recommended import style for@google-cloud/aiplatform v4 and apply it consistently?

constendpoint=`projects/${project}/locations/${location}/publishers/${publisher}/models/${model}`;

constfs=require('fs');
constfs=require('node:fs');
Copy link
Contributor

Choose a reason for hiding this comment

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

medium

Similar to other snippet files, thisrequire('node:fs') is inside a function in an ES module. Move this to a top-levelimport fs from 'node:fs'; statement.

importfsfrom'node:fs';

@davidcavazosdavidcavazos changed the titlechore(ci): migrate ai-platform/snippetschore(ci): migrate ai-platform/snippets via ESMMay 30, 2025
@davidcavazos
Copy link
Author

There are still a lot of manual edits that would need to be done. Many imports are requires inside the function body, which would need to be transformed to imports, bubbled outside the function, and bubble up the region tags outside the function to include the imports.

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

Reviewers

1 more reviewer

@gemini-code-assistgemini-code-assist[bot]gemini-code-assist[bot] requested changes

Reviewers whose approvals may not affect merge requirements

At least 1 approving review is required to merge this pull request.

Assignees

No one assigned

Labels

api: aiplatformIssues related to the AI Platform API.samplesIssues that are directly related to samples.

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

2 participants

@davidcavazos@glasnt

[8]ページ先頭

©2009-2025 Movatter.jp