From a71d66fb9ae62d5ad1dacca2520c950d8b0da495 Mon Sep 17 00:00:00 2001 From: Aman Kumar Date: Fri, 7 Feb 2025 18:11:18 +0530 Subject: [PATCH] fix: removed esm Module for Node.js v22.12.0+ Compatibility --- .github/workflows/release.yml | 6 +++--- package-lock.json | 25 ++-------------------- package.json | 4 +--- src/util/cloud-function/cloud-functions.ts | 10 +++------ 4 files changed, 9 insertions(+), 36 deletions(-) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index d9efa71..01e5f2c 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -32,13 +32,13 @@ jobs: needs: build steps: - name: Checkout - uses: actions/checkout@v3.5.3 + uses: actions/checkout@v4 with: fetch-depth: 0 - name: Setup Node.js - uses: actions/setup-node@v3.7.0 + uses: actions/setup-node@v4 with: - node-version: "18.x" + node-version: "22.x" - name: Installing dependencies run: npm install - name: Download dist diff --git a/package-lock.json b/package-lock.json index 8770eb2..390bbc5 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "@contentstack/cli-launch", - "version": "1.5.0", + "version": "1.5.1", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "@contentstack/cli-launch", - "version": "1.5.0", + "version": "1.5.1", "license": "MIT", "dependencies": { "@apollo/client": "^3.11.8", @@ -21,7 +21,6 @@ "chalk": "^4.1.2", "cross-fetch": "^3.1.8", "dotenv": "^16.4.7", - "esm": "^3.2.25", "express": "^4.21.1", "form-data": "^4.0.0", "graphql": "^16.9.0", @@ -37,7 +36,6 @@ "@oclif/test": "^4.1.3", "@types/adm-zip": "^0.5.7", "@types/chai": "^4.3.20", - "@types/esm": "^3.2.2", "@types/ini": "^1.3.34", "@types/lodash": "^4.17.13", "@types/mocha": "^10.0.10", @@ -2609,16 +2607,6 @@ "@types/node": "*" } }, - "node_modules/@types/esm": { - "version": "3.2.2", - "resolved": "https://registry.npmjs.org/@types/esm/-/esm-3.2.2.tgz", - "integrity": "sha512-l3IQQD2sChjNiQVNf28qq+sY9Sjvz7HrcOO3g4ZeSaiQRXQccBaR6cpqXPpzJ3QYCt6UF7+4ugabMRsQTPV+Eg==", - "dev": true, - "license": "MIT", - "dependencies": { - "@types/node": "*" - } - }, "node_modules/@types/estree": { "version": "1.0.6", "resolved": "https://registry.npmjs.org/@types/estree/-/estree-1.0.6.tgz", @@ -6957,15 +6945,6 @@ "node": "*" } }, - "node_modules/esm": { - "version": "3.2.25", - "resolved": "https://registry.npmjs.org/esm/-/esm-3.2.25.tgz", - "integrity": "sha512-U1suiZ2oDVWv4zPO56S0NcR5QriEahGtdN2OR6FiOG4WJvcjBVFB0qI4+eKoWFH483PKGuLuu6V8Z4T5g63UVA==", - "license": "MIT", - "engines": { - "node": ">=6" - } - }, "node_modules/espree": { "version": "7.3.1", "resolved": "https://registry.npmjs.org/espree/-/espree-7.3.1.tgz", diff --git a/package.json b/package.json index f5d2590..8e68c87 100755 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@contentstack/cli-launch", - "version": "1.5.0", + "version": "1.5.1", "description": "Launch related operations", "author": "Contentstack CLI", "bin": { @@ -32,7 +32,6 @@ "chalk": "^4.1.2", "cross-fetch": "^3.1.8", "dotenv": "^16.4.7", - "esm": "^3.2.25", "express": "^4.21.1", "form-data": "^4.0.0", "graphql": "^16.9.0", @@ -45,7 +44,6 @@ "@oclif/test": "^4.1.3", "@types/adm-zip": "^0.5.7", "@types/chai": "^4.3.20", - "@types/esm": "^3.2.2", "@types/ini": "^1.3.34", "@types/lodash": "^4.17.13", "@types/mocha": "^10.0.10", diff --git a/src/util/cloud-function/cloud-functions.ts b/src/util/cloud-function/cloud-functions.ts index 5f7abe8..179e33e 100755 --- a/src/util/cloud-function/cloud-functions.ts +++ b/src/util/cloud-function/cloud-functions.ts @@ -1,5 +1,4 @@ import dotenv from 'dotenv'; -import esm from 'esm'; import express, { Request, Response, @@ -70,13 +69,11 @@ export class CloudFunctions { cloudFunctionResources: CloudFunctionResource[], app: Express ): Promise { - const loadAsESM = esm(module); - await Promise.all( cloudFunctionResources.map(async (cloudFunctionResource) => { - const handler = loadAsESM( + const handler = await import( `${cloudFunctionResource.cloudFunctionFilePath}` - ).default; + ); app.use(express.json()); app.use(express.urlencoded({ extended: true })); @@ -182,12 +179,11 @@ export class CloudFunctions { private async checkDefaultExport(filepath: string): Promise { const exportType = "function"; - const loadAsESM = esm(module); const fullPath = normalize(path.resolve(process.cwd(), filepath)).replace( /^(\.\.(\/|\\|$))+/, "" ); - const handler = await loadAsESM(fullPath); + const handler = await import(fullPath); return typeof handler.default === exportType; }