Skip to content

Commit

Permalink
Fix: Migrate 'latest-version' version to 7.0.0 and fit it with ESM.
Browse files Browse the repository at this point in the history
Migrating 'latest-version' from 5.1.0 to 7.0.0. New version uses ESM instead of CommonJS. A new script has been added to allow 'latest-version' to be updated.

Ref: #5464
  • Loading branch information
benny.taccardi committed Mar 25, 2023
1 parent 98070cd commit cee6d03
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 2 deletions.
5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,9 @@
"eslint-plugin-markdown": "^2.2.1",
"fs-extra": "^11.1.0",
"globby": "^11.0.4",
"hint": "^7.1.5",
"json-schema-to-typescript": "^11.0.3",
"latest-version": "^5.1.0",
"latest-version": "^7.0.0",
"listr": "^0.14.2",
"listr-inquirer": "^0.1.0",
"markdown-link-validator": "^1.0.1",
Expand Down Expand Up @@ -50,7 +51,7 @@
"build": "yarn clean && yarn update:references && node scripts/build-or-test-all.js build",
"build:scripts": "npm run clean:root && npm run lint:scripts && npm-run-all --parallel build:scripts:*",
"build:scripts:non-ts": "copyfiles \"./scripts/**/{!(*.ts),.!(ts)}\" dist",
"build:scripts:ts": "tsc",
"build:scripts:ts": "tsc && node scripts/adapt-cjs-to-esm.js",
"build:ts": "tsc -b",
"cache": "node scripts/ava-cache.js",
"clean": "npm-run-all clean:*",
Expand Down
21 changes: 21 additions & 0 deletions scripts/adapt-cjs-to-esm.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
const fs = require('fs');

// Read the file content
const filePath = 'dist/release/tasks/get-packages.js';

fs.readFile(filePath, 'utf-8', (err, fileContent) => {
if (err) {
throw err;
}

// Replace the statement with a new one
const newContent = fileContent.replace(/const latest_version_1 = require\("latest-version"\);/, /const latest_version_1 = await require\("latest-version"\);/);

// Write the updated content back to the file
fs.writeFile(filePath, newContent, 'utf-8', (err) => {
if (err) {
throw err;
}
console.log('File updated successfully!');
});
});

0 comments on commit cee6d03

Please sign in to comment.