Browse Source

chore: Migrate CJS to ESM (#42060)

pull/42067/head
lijianan 2 years ago
committed by GitHub
parent
commit
9258e0bb24
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 3
      package.json
  2. 29
      scripts/post-script.ts

3
package.json

@ -82,7 +82,7 @@
"pub": "npm run version && npm run collect-token-statistic && npm run token-meta && antd-tools run pub",
"rome:format": "rome format --write .",
"prepublishOnly": "antd-tools run guard",
"postpublish": "node ./scripts/post-script.js",
"postpublish": "ts-node --esm --project tsconfig.node.json scripts/post-script.ts",
"site": "dumi build && cp .surgeignore _site",
"sort": "npx sort-package-json",
"sort-api": "antd-tools run sort-api-table",
@ -177,6 +177,7 @@
"@testing-library/user-event": "^14.4.2",
"@types/fs-extra": "^11.0.1",
"@types/gtag.js": "^0.0.12",
"@types/inquirer": "^9.0.3",
"@types/isomorphic-fetch": "^0.0.36",
"@types/jest": "^29.0.0",
"@types/jest-axe": "^3.5.3",

29
scripts/post-script.js → scripts/post-script.ts

@ -1,13 +1,13 @@
/* eslint-disable no-console */
const fetch = require('isomorphic-fetch');
const semver = require('semver');
const dayjs = require('dayjs');
const chalk = require('chalk');
const { spawnSync } = require('child_process');
const relativeTime = require('dayjs/plugin/relativeTime');
// const packageJson = require('../package.json');
import chalk from 'chalk';
import { spawnSync } from 'child_process';
import dayjs from 'dayjs';
import relativeTime from 'dayjs/plugin/relativeTime';
import fetch from 'isomorphic-fetch';
import semver from 'semver';
dayjs.extend(relativeTime);
const CONCH_TAG = 'conch-v5';
const DEPRECIATED_VERSION = {
@ -39,12 +39,12 @@ const DEPRECIATED_VERSION = {
],
};
function matchDeprecated(version) {
function matchDeprecated(version: string) {
const match = Object.keys(DEPRECIATED_VERSION).find((depreciated) =>
semver.satisfies(version, depreciated),
);
const reason = DEPRECIATED_VERSION[match] || [];
const reason = DEPRECIATED_VERSION[match as keyof typeof DEPRECIATED_VERSION] || [];
return {
match,
@ -98,12 +98,13 @@ const SAFE_DAYS_DIFF = 1000 * 60 * 60 * 24 * 3; // 3 days not update seems to be
const startDefaultVersionIndex = filteredLatestVersions.findIndex(
({ timeDiff }) => timeDiff >= SAFE_DAYS_START,
);
const defaultVersionList = filteredLatestVersions
.slice(0, startDefaultVersionIndex + 1)
.reverse();
// Find safe version
let defaultVersionObj;
let defaultVersionObj: any;
for (let i = 0; i < defaultVersionList.length - 1; i += 1) {
defaultVersionObj = defaultVersionList[i];
const nextVersionObj = defaultVersionList[i + 1];
@ -125,6 +126,7 @@ const SAFE_DAYS_DIFF = 1000 * 60 * 60 * 24 * 3; // 3 days not update seems to be
}
const { default: inquirer } = await import('inquirer');
// Selection
let { conchVersion } = await inquirer.prompt([
{
@ -136,8 +138,6 @@ const SAFE_DAYS_DIFF = 1000 * 60 * 60 * 24 * 3; // 3 days not update seems to be
const { value, publishTime, depreciated } = info;
const desc = dayjs(publishTime).fromNow();
//
return {
...info,
name: [
@ -188,9 +188,6 @@ const SAFE_DAYS_DIFF = 1000 * 60 * 60 * 24 * 3; // 3 days not update seems to be
console.log(`🎃 Conch Version not change. Safe to ${chalk.green('ignore')}.`);
} else {
console.log('💾 Tagging Conch Version:', chalk.green(conchVersion));
spawnSync('npm', ['dist-tag', 'add', `antd@${conchVersion}`, CONCH_TAG], {
stdio: 'inherit',
stdin: 'inherit',
});
spawnSync('npm', ['dist-tag', 'add', `antd@${conchVersion}`, CONCH_TAG], { stdio: 'inherit' });
}
})();
Loading…
Cancel
Save