From f34f4d485f1839cec8e8e38fc9a2f8f341affdf2 Mon Sep 17 00:00:00 2001 From: lijianan <574980606@qq.com> Date: Fri, 28 Apr 2023 16:53:24 +0800 Subject: [PATCH] chore: Migrate CJS to ESM (#42064) --- package.json | 3 ++- scripts/{check-ts-demo.js => check-ts-demo.ts} | 17 ++++++++--------- 2 files changed, 10 insertions(+), 10 deletions(-) rename scripts/{check-ts-demo.js => check-ts-demo.ts} (86%) diff --git a/package.json b/package.json index 00700eb76c..b1fa284a3d 100644 --- a/package.json +++ b/package.json @@ -50,7 +50,7 @@ "build": "npm run compile && NODE_OPTIONS='--max-old-space-size=4096' npm run dist", "size-limit": "size-limit", "check-commit": "node ./scripts/check-commit", - "check-ts-demo": "node ./scripts/check-ts-demo", + "check-ts-demo": "ts-node --esm --project tsconfig.node.json scripts/check-ts-demo.ts", "clean": "antd-tools run clean && rm -rf es lib coverage dist report.html", "clean-lockfiles": "rm -rf package-lock.json yarn.lock", "collect-token-statistic": "ts-node --project tsconfig.node.json scripts/collect-token-statistic.js", @@ -175,6 +175,7 @@ "@testing-library/jest-dom": "^5.16.3", "@testing-library/react": "^14.0.0", "@testing-library/user-event": "^14.4.2", + "@types/fs-extra": "^11.0.1", "@types/gtag.js": "^0.0.12", "@types/isomorphic-fetch": "^0.0.36", "@types/jest": "^29.0.0", diff --git a/scripts/check-ts-demo.js b/scripts/check-ts-demo.ts similarity index 86% rename from scripts/check-ts-demo.js rename to scripts/check-ts-demo.ts index 5a47fce8a5..c9d512d543 100644 --- a/scripts/check-ts-demo.js +++ b/scripts/check-ts-demo.ts @@ -1,10 +1,9 @@ /* eslint-disable no-await-in-loop, no-console */ - -const path = require('path'); -const { globSync } = require('glob'); -const fs = require('fs-extra'); -const chalk = require('chalk'); -const { spawn } = require('child_process'); +import chalk from 'chalk'; +import { spawn } from 'child_process'; +import fs from 'fs-extra'; +import { globSync } from 'glob'; +import path from 'path'; (async () => { console.time('Execution...'); @@ -15,11 +14,11 @@ const { spawn } = require('child_process'); await fs.remove(tmpFolder); await fs.ensureDir(tmpFolder); - function getTypescriptDemo(content, demoPath) { + function getTypescriptDemo(content: string, demoPath: string) { const lines = content.split(/[\n\r]/); const tsxStartLine = lines.findIndex((line) => - line.replace(/\s/g).toLowerCase().includes('```tsx'), + line.replace(/\s/g, '').toLowerCase().includes('```tsx'), ); if (tsxStartLine < 0) { @@ -72,7 +71,7 @@ const { spawn } = require('child_process'); child.stdout.pipe(process.stdout); child.stderr.pipe(process.stderr); - child.on('exit', async (code) => { + child.on('exit', async (code: number) => { console.timeEnd('Execution...'); if (code) {