Skip to content

Commit

Permalink
chore: Migrate CJS to ESM (ant-design#44742)
Browse files Browse the repository at this point in the history
  • Loading branch information
li-jia-nan authored Sep 11, 2023
1 parent 5b75f3f commit 535a7da
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 19 deletions.
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@
"pub": "npm run version && npm run collect-token-statistic && npm run token-meta && antd-tools run pub",
"biome:format": "biome format --write .",
"prepublishOnly": "antd-tools run guard",
"postpublish": "node ./scripts/post-script.js",
"postpublish": "tsx scripts/post-script.ts",
"site": "dumi build && cp .surgeignore _site",
"sort": "npx sort-package-json",
"sort-api": "antd-tools run sort-api-table",
Expand Down Expand Up @@ -241,7 +241,7 @@
"husky": "^8.0.1",
"identity-obj-proxy": "^3.0.0",
"immer": "^10.0.1",
"inquirer": "^9.1.2",
"inquirer": "^9.2.11",
"is-ci": "^3.0.1",
"isomorphic-fetch": "^3.0.0",
"jest": "^29.4.1",
Expand Down
31 changes: 14 additions & 17 deletions scripts/post-script.js → scripts/post-script.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
/* eslint-disable no-console */
const { spawnSync } = require('child_process');
const fetch = require('isomorphic-fetch');
const semver = require('semver');
const dayjs = require('dayjs');
const chalk = require('chalk');
const relativeTime = require('dayjs/plugin/relativeTime');
import { spawnSync } from 'child_process';
import chalk from 'chalk';
import dayjs from 'dayjs';
import relativeTime from 'dayjs/plugin/relativeTime';
import inquirer from 'inquirer';
import fetch from 'isomorphic-fetch';
import semver from 'semver';

dayjs.extend(relativeTime);

Expand Down Expand Up @@ -45,14 +46,14 @@ const DEPRECIATED_VERSION = {
'https://github.com/ant-design/ant-design/issues/43684',
],
'5.8.0': ['https://github.com/ant-design/ant-design/issues/43943'],
};
} as const;

function matchDeprecated(version) {
function matchDeprecated(v: string) {
const match = Object.keys(DEPRECIATED_VERSION).find((depreciated) =>
semver.satisfies(version, depreciated),
semver.satisfies(v, depreciated),
);

const reason = DEPRECIATED_VERSION[match] || [];
const reason = DEPRECIATED_VERSION[match as keyof typeof DEPRECIATED_VERSION] || [];

return {
match,
Expand All @@ -72,7 +73,7 @@ const SAFE_DAYS_DIFF = 1000 * 60 * 60 * 24 * 3; // 3 days not update seems to be
// }

const { time, 'dist-tags': distTags } = await fetch('http://registry.npmjs.org/antd').then(
(res) => res.json(),
(res: Response) => res.json(),
);

console.log('🐚 Latest Conch Version:', chalk.green(distTags[CONCH_TAG] || 'null'), '\n');
Expand Down Expand Up @@ -128,11 +129,10 @@ const SAFE_DAYS_DIFF = 1000 * 60 * 60 * 24 * 3; // 3 days not update seems to be
let defaultVersion = defaultVersionObj ? defaultVersionObj.value : null;

// If default version is less than current, use current
if (semver.compare(defaultVersion, distTags[CONCH_TAG]) < 0) {
if (semver.compare(defaultVersion!, distTags[CONCH_TAG]) < 0) {
defaultVersion = distTags[CONCH_TAG];
}

const { default: inquirer } = await import('inquirer');
// Selection
let { conchVersion } = await inquirer.prompt([
{
Expand Down Expand Up @@ -196,9 +196,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' });
}
})();

0 comments on commit 535a7da

Please sign in to comment.