Skip to content

Commit 6c1001f

Browse files
authored
build: update to gulp 4 (#21445)
We still depend on Gulp for a couple of CI tasks, but we've been stuck on version 3.8 for a while which doesn't support Node 12 and might break in other ways in the future. These changes update us to version 4.0.2, account for the breaking changes and remove some dependencies that have been replaced by functions in Gulp.
1 parent fb833e7 commit 6c1001f

File tree

9 files changed

+506
-678
lines changed

9 files changed

+506
-678
lines changed

package.json

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@
9696
"@types/browser-sync": "^2.26.1",
9797
"@types/fs-extra": "^9.0.5",
9898
"@types/glob": "^5.0.36",
99-
"@types/gulp": "3.8.32",
99+
"@types/gulp": "4.0.7",
100100
"@types/inquirer": "^7.3.1",
101101
"@types/jasmine": "^3.5.4",
102102
"@types/marked": "^1.2.1",
@@ -106,7 +106,6 @@
106106
"@types/node-fetch": "^2.5.5",
107107
"@types/parse5": "^5.0.0",
108108
"@types/resize-observer-browser": "^0.1.3",
109-
"@types/run-sequence": "^0.0.30",
110109
"@types/semver": "^7.3.4",
111110
"@types/send": "^0.14.5",
112111
"@types/stylelint": "^9.10.1",
@@ -122,9 +121,8 @@
122121
"firebase-tools": "^8.16.1",
123122
"fs-extra": "^9.0.1",
124123
"glob": "^7.1.2",
125-
"gulp": "^3.9.1",
126-
"gulp-clean": "^0.4.0",
127-
"gulp-cli": "^2.0.1",
124+
"gulp": "^4.0.2",
125+
"gulp-cli": "^2.3.0",
128126
"gulp-sass": "^4.0.2",
129127
"highlight.js": "^10.4.0",
130128
"husky": "^4.3.0",
@@ -157,7 +155,6 @@
157155
"rollup-plugin-commonjs": "^10.1.0",
158156
"rollup-plugin-node-resolve": "^5.2.0",
159157
"rollup-plugin-sourcemaps": "^0.6.3",
160-
"run-sequence": "^1.2.2",
161158
"sass": "^1.29.0",
162159
"scss-bundle": "^3.1.2",
163160
"selenium-webdriver": "^3.6.0",
@@ -176,8 +173,7 @@
176173
"yaml": "^1.10.0"
177174
},
178175
"resolutions": {
179-
"dgeni-packages/typescript": "4.1.2",
180-
"**/graceful-fs": "4.2.2"
176+
"dgeni-packages/typescript": "4.1.2"
181177
},
182178
"husky": {
183179
"hooks": {

tools/gulp/gulpfile.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,7 @@ import {
99
youTubePlayerPackage
1010
} from './packages';
1111

12-
import './tasks/ci';
13-
import './tasks/clean';
14-
import './tasks/unit-test';
15-
12+
// Build tasks have to be imported first, because the other tasks depend on them.
1613
createPackageBuildTasks(cdkPackage);
1714
createPackageBuildTasks(cdkExperimentalPackage);
1815
createPackageBuildTasks(materialPackage);
@@ -21,3 +18,6 @@ createPackageBuildTasks(momentAdapterPackage);
2118
createPackageBuildTasks(youTubePlayerPackage);
2219
createPackageBuildTasks(googleMapsPackage);
2320

21+
import './tasks/clean';
22+
import './tasks/unit-test';
23+
import './tasks/ci';

tools/gulp/tasks/ci.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
1-
import {task} from 'gulp';
1+
import {task, series} from 'gulp';
22

33
// Gulp sometimes does not exit properly on CI. This is to prevent that.
44
// TODO(devversion): look if there is some blocking child process.
5-
task('ci:test', ['test:single-run'], () => process.exit(0));
5+
task('ci:test', series('test:single-run', done => {
6+
done();
7+
process.exit(0);
8+
}));

tools/gulp/tasks/clean.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
1-
import {task, src} from 'gulp';
1+
import {task} from 'gulp';
22
import {buildConfig} from '../../package-tools';
33

4-
// This import lacks type definitions.
5-
const gulpClean = require('gulp-clean');
4+
const shelljs = require('shelljs');
65

76
/** Deletes the output directory. */
8-
task('clean', () => src(buildConfig.outputDir, { read: false }).pipe(gulpClean(null)));
7+
task('clean', done => {
8+
shelljs.rm('-rf', [buildConfig.outputDir]);
9+
done();
10+
});

tools/gulp/tasks/unit-test.ts

Lines changed: 27 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,26 @@
11
import {join} from 'path';
2-
import {task} from 'gulp';
3-
import {buildConfig, sequenceTask} from '../../package-tools';
2+
import {task, series} from 'gulp';
3+
import {buildConfig} from '../../package-tools';
44

55
// There are no type definitions available for these imports.
66
const shelljs = require('shelljs');
77

8+
/**
9+
* Tasks that builds the SystemJS configuration which is needed for the Karma
10+
* legacy unit tests.
11+
*/
12+
task(':test:build-system-config', done => {
13+
const configOutputPath = join(buildConfig.outputDir, 'karma-system-config.js');
14+
shelljs.cd(buildConfig.projectDir);
15+
const bazelGenfilesDir = shelljs.exec('yarn -s bazel info bazel-genfiles').stdout.trim();
16+
shelljs.exec('yarn -s bazel build //test:system-config.js');
17+
shelljs.cp(join(bazelGenfilesDir, 'test/system-config.js'), configOutputPath);
18+
shelljs.chmod('u+w', configOutputPath);
19+
done();
20+
});
21+
822
/** Builds everything that is necessary for karma. */
9-
task(':test:build', sequenceTask(
23+
task(':test:build', series(
1024
'clean',
1125
'cdk:build-no-bundles',
1226
'material:build-no-bundles',
@@ -22,7 +36,7 @@ task(':test:build', sequenceTask(
2236
* Runs the unit tests. Does not watch for changes.
2337
* This task should be used when running tests on the CI server.
2438
*/
25-
task('test:single-run', [':test:build'], (done: () => void) => {
39+
task('test:single-run', series(':test:build', done => {
2640
// Load karma not outside. Karma pollutes Promise with a different implementation.
2741
const karma = require('karma');
2842

@@ -31,21 +45,13 @@ task('test:single-run', [':test:build'], (done: () => void) => {
3145
autoWatch: false,
3246
singleRun: true
3347
}, (exitCode: number) => {
34-
// Immediately exit the process if Karma reported errors, because due to
35-
// potential still running tunnel-browsers gulp won't exit properly.
36-
exitCode === 0 ? done() : process.exit(exitCode);
48+
if (exitCode === 0) {
49+
done();
50+
} else {
51+
// Immediately exit the process if Karma reported errors, because due to
52+
// potential still running tunnel-browsers gulp won't exit properly.
53+
done(`Karma exited with code ${exitCode}.`);
54+
process.exit(exitCode);
55+
}
3756
}).start();
38-
});
39-
40-
/**
41-
* Tasks that builds the SystemJS configuration which is needed for the Karma
42-
* legacy unit tests.
43-
*/
44-
task(':test:build-system-config', () => {
45-
const configOutputPath = join(buildConfig.outputDir, 'karma-system-config.js');
46-
shelljs.cd(buildConfig.projectDir);
47-
const bazelGenfilesDir = shelljs.exec('yarn -s bazel info bazel-genfiles').stdout.trim();
48-
shelljs.exec('yarn -s bazel build //test:system-config.js');
49-
shelljs.cp(join(bazelGenfilesDir, 'test/system-config.js'), configOutputPath);
50-
shelljs.chmod('u+w', configOutputPath);
51-
});
57+
}));
Lines changed: 25 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,15 @@
1-
import {dest, src, task} from 'gulp';
1+
import {dest, src, task, series} from 'gulp';
22
import {join} from 'path';
33
import {BuildPackage} from '../build-package';
44
import {inlineResourcesForDirectory} from '../inline-resources';
55
import {buildScssPipeline} from './build-scss-pipeline';
6-
import {sequenceTask} from './sequence-task';
76

87
/**
98
* Creates a set of gulp tasks that can build the specified package.
109
* @param buildPackage Build package for which the gulp tasks will be generated
1110
* @param preBuildTasks List of gulp tasks that should run before building the package.
1211
*/
13-
export function createPackageBuildTasks(buildPackage: BuildPackage, preBuildTasks: string[] = []) {
12+
export function createPackageBuildTasks(buildPackage: BuildPackage) {
1413
// Name of the package build tasks for Gulp.
1514
const taskName = buildPackage.name;
1615

@@ -26,49 +25,36 @@ export function createPackageBuildTasks(buildPackage: BuildPackage, preBuildTask
2625
// Glob that matches every HTML file in the current package.
2726
const htmlGlob = join(buildPackage.sourceDir, '**/*.html');
2827

29-
task(`${taskName}:build-no-bundles`, sequenceTask(
30-
// Build assets before building the ESM output. Since we compile with NGC, the compiler
31-
// tries to resolve all required assets.
32-
`${taskName}:assets`,
33-
// Build the ESM output that includes all test files. Also build assets for the package.
34-
`${taskName}:build:esm:tests`,
35-
// Inline assets into ESM output.
36-
`${taskName}:assets:inline`
37-
));
38-
39-
/**
40-
* TypeScript compilation tasks. Tasks are creating ESM, FESM, UMD bundles for releases.
41-
*/
42-
43-
task(`${taskName}:build:esm:tests`, () => buildPackage.compileTests());
28+
task(`${taskName}:assets:scss`, () =>
29+
buildScssPipeline(buildPackage.sourceDir).pipe(dest(buildPackage.outputDir)));
30+
task(`${taskName}:assets:copy-styles`, () => src(styleGlobs).pipe(dest(buildPackage.outputDir)));
31+
task(`${taskName}:assets:html`, () => src(htmlGlob).pipe(dest(buildPackage.outputDir)));
32+
task(`${taskName}:assets:inline`, done => {
33+
inlineResourcesForDirectory(buildPackage.outputDir);
34+
done();
35+
});
4436

4537
/**
4638
* Asset tasks. Building Sass files and inlining CSS, HTML files into the ESM output.
4739
*/
48-
const assetTasks = [
40+
task(`${taskName}:assets`, series(
4941
`${taskName}:assets:scss`,
5042
`${taskName}:assets:copy-styles`,
5143
`${taskName}:assets:html`
52-
];
53-
54-
task(`${taskName}:assets`, assetTasks);
55-
56-
task(`${taskName}:assets:scss`, () => {
57-
return buildScssPipeline(buildPackage.sourceDir)
58-
.pipe(dest(buildPackage.outputDir));
59-
}
60-
);
61-
62-
task(`${taskName}:assets:copy-styles`, () => {
63-
return src(styleGlobs)
64-
.pipe(dest(buildPackage.outputDir));
65-
});
44+
));
6645

67-
task(`${taskName}:assets:html`, () => {
68-
return src(htmlGlob).pipe(dest(buildPackage.outputDir));
69-
});
46+
/**
47+
* TypeScript compilation tasks. Tasks are creating ESM, FESM, UMD bundles for releases.
48+
*/
49+
task(`${taskName}:build:esm:tests`, () => buildPackage.compileTests());
7050

71-
task(`${taskName}:assets:inline`, () => {
72-
return inlineResourcesForDirectory(buildPackage.outputDir);
73-
});
51+
task(`${taskName}:build-no-bundles`, series(
52+
// Build assets before building the ESM output. Since we compile with NGC, the compiler
53+
// tries to resolve all required assets.
54+
`${taskName}:assets`,
55+
// Build the ESM output that includes all test files. Also build assets for the package.
56+
`${taskName}:build:esm:tests`,
57+
// Inline assets into ESM output.
58+
`${taskName}:assets:inline`
59+
));
7460
}

tools/package-tools/gulp/sequence-task.ts

Lines changed: 0 additions & 12 deletions
This file was deleted.

tools/package-tools/index.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,3 @@ export * from './inline-resources';
66
// Expose gulp utilities.
77
export * from './gulp/build-tasks-gulp';
88
export * from './gulp/build-scss-pipeline';
9-
export * from './gulp/sequence-task';

0 commit comments

Comments
 (0)