Skip to content

Commit aab1f8c

Browse files
elliottsjNicholas Pape
authored andcommitted
Add a libESNextFolder option (microsoft#577)
* Add a `libESNextFolder` option This option allows projects to emit modules to the specified directory using `module: 'esnext'`. * rush change
1 parent 7477a3c commit aab1f8c

8 files changed

Lines changed: 61 additions & 3 deletions

File tree

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{
2+
"changes": [
3+
{
4+
"packageName": "@microsoft/gulp-core-build-typescript",
5+
"comment": "Add a `libESNextFolder` option",
6+
"type": "minor"
7+
}
8+
],
9+
"packageName": "@microsoft/gulp-core-build-typescript",
10+
"email": "elliottsj@users.noreply.github.com"
11+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{
2+
"changes": [
3+
{
4+
"packageName": "@microsoft/gulp-core-build",
5+
"comment": "Add a `libESNextFolder` option",
6+
"type": "minor"
7+
}
8+
],
9+
"packageName": "@microsoft/gulp-core-build",
10+
"email": "elliottsj@users.noreply.github.com"
11+
}

‎common/reviews/api/gulp-core-build.api.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,7 @@ interface IBuildConfig {
113113
jestEnabled?: boolean;
114114
libAMDFolder?: string;
115115
libES6Folder?: string;
116+
libESNextFolder?: string;
116117
libFolder: string;
117118
onTaskEnd?: (taskName: string, duration: number[], error?: any) => void;
118119
onTaskStart?: (taskName: string) => void;

‎common/reviews/api/node-library-build.api.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,7 @@ interface IBuildConfig {
121121
jestEnabled?: boolean;
122122
libAMDFolder?: string;
123123
libES6Folder?: string;
124+
libESNextFolder?: string;
124125
libFolder: string;
125126
onTaskEnd?: (taskName: string, duration: number[], error?: any) => void;
126127
onTaskStart?: (taskName: string) => void;

‎common/reviews/api/web-library-build.api.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,7 @@ interface IBuildConfig {
121121
jestEnabled?: boolean;
122122
libAMDFolder?: string;
123123
libES6Folder?: string;
124+
libESNextFolder?: string;
124125
libFolder: string;
125126
onTaskEnd?: (taskName: string, duration: number[], error?: any) => void;
126127
onTaskStart?: (taskName: string) => void;

‎core-build/gulp-core-build-typescript/src/TypeScriptTask.ts‎

Lines changed: 30 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -61,15 +61,20 @@ export interface ITypeScriptTaskConfig {
6161
libDir?: string;
6262

6363
/**
64-
* If defined, drop typescript files from an AMD build here. Defaults to buildConfig.libAMDFolder
64+
* If defined, emit compiled typescript modules here using `module: 'amd'`. Defaults to buildConfig.libAMDFolder
6565
*/
6666
libAMDDir?: string;
6767

6868
/**
69-
* If defined, drop typescript files build using modules=ES6.
69+
* If defined, emit compiled typescript modules here using `module: 'es6'`. Defaults to buildConfig.libES6Folder
7070
*/
7171
libES6Dir?: string;
7272

73+
/**
74+
* If defined, emit compiled typescript modules here using `module: 'esnext'`. Defaults to buildConfig.libESNextFolder
75+
*/
76+
libESNextDir?: string;
77+
7378
/**
7479
* If defined, apply these settings on top of the standardized project TypeScript compiler configuration.
7580
*/
@@ -83,6 +88,7 @@ export class TypeScriptTask extends GulpTask<ITypeScriptTaskConfig> {
8388
private _tsProject: ts.Project;
8489
private _tsAMDProject: ts.Project;
8590
private _tsES6Project: ts.Project;
91+
private _tsESNextProject: ts.Project;
8692

8793
constructor() {
8894
super(
@@ -124,7 +130,8 @@ export class TypeScriptTask extends GulpTask<ITypeScriptTaskConfig> {
124130
emitSourceMaps: true,
125131
libDir: undefined,
126132
libAMDDir: undefined,
127-
libES6Dir: undefined
133+
libES6Dir: undefined,
134+
libESNextDir: undefined
128135
}
129136
);
130137
}
@@ -195,6 +202,18 @@ export class TypeScriptTask extends GulpTask<ITypeScriptTaskConfig> {
195202
this._compileProject(gulp, this._tsES6Project, this.taskConfig.libES6Dir, allStreams, result);
196203
}
197204

205+
// If esnext modules are required, also build that.
206+
if (this.taskConfig.libESNextDir) {
207+
allStreams.push(
208+
staticSrc.pipe(gulp.dest(this.taskConfig.libESNextDir)));
209+
210+
this._tsESNextProject = (
211+
this._tsESNextProject ||
212+
ts.createProject(assign({}, compilerOptions, { module: 'esnext' }))
213+
);
214+
this._compileProject(gulp, this._tsESNextProject, this.taskConfig.libESNextDir, allStreams, result);
215+
}
216+
198217
// Listen for pass/fail, and ensure that the task passes/fails appropriately.
199218
merge(allStreams)
200219
.on('queueDrain', () => {
@@ -223,6 +242,10 @@ export class TypeScriptTask extends GulpTask<ITypeScriptTaskConfig> {
223242
cleanMatch.push(this.taskConfig.libES6Dir);
224243
}
225244

245+
if (this.taskConfig.libESNextDir) {
246+
cleanMatch.push(this.taskConfig.libESNextDir);
247+
}
248+
226249
return cleanMatch;
227250
}
228251

@@ -243,6 +266,10 @@ export class TypeScriptTask extends GulpTask<ITypeScriptTaskConfig> {
243266
if (!this.taskConfig.libES6Dir) {
244267
this.taskConfig.libES6Dir = buildConfig.libES6Folder;
245268
}
269+
270+
if (!this.taskConfig.libESNextDir) {
271+
this.taskConfig.libESNextDir = buildConfig.libESNextFolder;
272+
}
246273
}
247274

248275
private _compileProject(gulp: gulpType.Gulp, tsProject: ts.Project, destDir: string,

‎core-build/gulp-core-build/src/IBuildConfig.ts‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,11 @@ export interface IBuildConfig {
5353
*/
5454
libES6Folder?: string;
5555

56+
/**
57+
* Unbundled esnext modules folder, which can be optionally set to cause build tasks to output esnext modules.
58+
*/
59+
libESNextFolder?: string;
60+
5661
/**
5762
* Dist folder, which includes all bundled resources which would be copied to a CDN for the project.
5863
*/

‎core-build/gulp-core-build/src/index.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ let _buildConfig: IBuildConfig = {
6969
srcFolder: 'src',
7070
distFolder: path.join(packageFolder, 'dist'),
7171
libAMDFolder: undefined,
72+
libESNextFolder: undefined,
7273
libFolder: path.join(packageFolder, 'lib'),
7374
tempFolder: 'temp',
7475
properties: {},

0 commit comments

Comments
 (0)