Skip to content

Commit 989d1d4

Browse files
authored
chore: remove gulp-typescript (#4675)
1 parent e48bc13 commit 989d1d4

File tree

4 files changed

+58
-49
lines changed

4 files changed

+58
-49
lines changed

antd-tools/gulpfile.js

+51-47
Original file line numberDiff line numberDiff line change
@@ -17,23 +17,22 @@ const chalk = require('chalk');
1717
const getNpmArgs = require('./utils/get-npm-args');
1818
const getChangelog = require('./utils/getChangelog');
1919
const path = require('path');
20-
// const watch = require('gulp-watch')
21-
const ts = require('gulp-typescript');
2220
const gulp = require('gulp');
21+
const fg = require('fast-glob');
2322
const fs = require('fs');
2423
const rimraf = require('rimraf');
24+
const { createCompilerHost, createProgram } = require('typescript');
2525
const stripCode = require('gulp-strip-code');
2626
const compareVersions = require('compare-versions');
27-
const getTSCommonConfig = require('./getTSCommonConfig');
27+
// const getTSCommonConfig = require('./getTSCommonConfig');
2828
const replaceLib = require('./replaceLib');
2929

3030
const packageJson = require(getProjectPath('package.json'));
31-
const tsDefaultReporter = ts.reporter.defaultReporter();
3231
const cwd = process.cwd();
3332
const libDir = getProjectPath('lib');
3433
const esDir = getProjectPath('es');
3534

36-
const tsConfig = getTSCommonConfig();
35+
// const tsConfig = getTSCommonConfig();
3736

3837
function dist(done) {
3938
rimraf.sync(path.join(cwd, 'dist'));
@@ -72,29 +71,51 @@ function dist(done) {
7271
});
7372
}
7473

75-
const tsFiles = ['**/*.ts', '**/*.tsx', '!node_modules/**/*.*', 'typings/**/*.d.ts'];
74+
async function compileTs(modules = false, cb) {
75+
const options = {
76+
allowJs: true,
77+
declaration: true,
78+
emitDeclarationOnly: true,
79+
};
7680

77-
function compileTs(stream) {
78-
return stream
79-
.pipe(ts(tsConfig))
80-
.js.pipe(
81-
through2.obj(function (file, encoding, next) {
82-
// console.log(file.path, file.base);
83-
file.path = file.path.replace(/\.[jt]sx$/, '.js');
84-
this.push(file);
85-
next();
86-
}),
87-
)
88-
.pipe(gulp.dest(process.cwd()));
81+
const createdFiles = {};
82+
const host = createCompilerHost(options);
83+
host.writeFile = (fileName, contents) => {
84+
createdFiles[path.isAbsolute(fileName) ? path.relative(cwd, fileName) : fileName] = contents;
85+
};
86+
87+
const files = await fg(
88+
[
89+
'components/**/*.js',
90+
'components/**/*.jsx',
91+
'components/**/*.tsx',
92+
'components/**/*.ts',
93+
'!components/*/__tests__/*',
94+
'!components/*/style/*',
95+
'!components/styles.ts',
96+
],
97+
{ cwd },
98+
);
99+
100+
const program = createProgram(files, options, host);
101+
program.emit();
102+
103+
Object.keys(createdFiles).forEach(fileName => {
104+
const contents = createdFiles[fileName];
105+
const filePath = path.join(
106+
cwd,
107+
fileName.replace(/^components/, modules === false ? 'es' : 'lib'),
108+
);
109+
const dir = path.dirname(filePath);
110+
if (!fs.existsSync(dir)) {
111+
fs.mkdirSync(dir, { recursive: true });
112+
}
113+
fs.writeFileSync(filePath, contents);
114+
});
115+
cb(0);
89116
}
90117

91-
gulp.task('tsc', () =>
92-
compileTs(
93-
gulp.src(tsFiles, {
94-
base: cwd,
95-
}),
96-
),
97-
);
118+
gulp.task('tsc', () => compileTs());
98119

99120
function babelify(js, modules) {
100121
const babelConfig = getBabelCommonConfig(modules);
@@ -169,7 +190,7 @@ function compile(modules) {
169190
const assets = gulp
170191
.src(['components/**/*.@(png|svg)'])
171192
.pipe(gulp.dest(modules === false ? esDir : libDir));
172-
let error = 0;
193+
// let error = 0;
173194
const source = [
174195
'components/**/*.js',
175196
'components/**/*.jsx',
@@ -179,27 +200,8 @@ function compile(modules) {
179200
'!components/*/__tests__/*',
180201
];
181202

182-
const tsResult = gulp.src(source).pipe(
183-
ts(tsConfig, {
184-
error(e) {
185-
tsDefaultReporter.error(e);
186-
error = 1;
187-
},
188-
finish: tsDefaultReporter.finish,
189-
}),
190-
);
191-
192-
function check() {
193-
if (error && !argv['ignore-error']) {
194-
process.exit(1);
195-
}
196-
}
197-
198-
tsResult.on('finish', check);
199-
tsResult.on('end', check);
200-
const tsFilesStream = babelify(tsResult.js, modules);
201-
const tsd = tsResult.dts.pipe(gulp.dest(modules === false ? esDir : libDir));
202-
return merge2([less, tsFilesStream, tsd, assets]);
203+
const jsFilesStream = babelify(gulp.src(source), modules);
204+
return merge2([less, jsFilesStream, assets]);
203205
}
204206

205207
function tag() {
@@ -329,11 +331,13 @@ function pub(done) {
329331
gulp.task('compile-with-es', done => {
330332
console.log('[Parallel] Compile to es...');
331333
compile(false).on('finish', done);
334+
compileTs(false, done);
332335
});
333336

334337
gulp.task('compile-with-lib', done => {
335338
console.log('[Parallel] Compile to js...');
336339
compile().on('finish', done);
340+
compileTs(true, done);
337341
});
338342

339343
gulp.task(

components/vc-progress/index.ts

+3-1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
import Progress, { Line, Circle } from './src';
33

44
import type { ProgressProps } from './src';
5-
export { Line, Circle, ProgressProps };
5+
export { Line, Circle };
6+
7+
export type { ProgressProps };
68

79
export default Progress;

components/vc-progress/src/index.ts

+3-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@ import Line from './Line';
22
import Circle from './Circle';
33
import type { ProgressProps } from './types';
44

5-
export { Line, Circle, ProgressProps };
5+
export { Line, Circle };
6+
7+
export type { ProgressProps };
68

79
export default {
810
Line,

package.json

+1
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,7 @@
147147
"eslint-plugin-no-explicit-type-exports": "^0.11.10",
148148
"eslint-plugin-prettier": "^3.1.0",
149149
"eslint-plugin-vue": "^7.1.0",
150+
"fast-glob": "^3.2.7",
150151
"fetch-jsonp": "^1.1.3",
151152
"fs-extra": "^10.0.0",
152153
"glob": "^7.1.2",

0 commit comments

Comments
 (0)