Browse Source

chore: Migrate CJS to ESM (#42064)

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

3
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",

17
scripts/check-ts-demo.js → 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) {
Loading…
Cancel
Save