Skip to content

Add Gulpfile.ts#9068

Merged
weswigham merged 31 commits into
microsoft:masterfrom
weswigham:remove-jake
Jun 23, 2016
Merged

Add Gulpfile.ts#9068
weswigham merged 31 commits into
microsoft:masterfrom
weswigham:remove-jake

Conversation

@weswigham
Copy link
Copy Markdown
Member

@weswigham weswigham commented Jun 10, 2016

Last fall I always said I'd probably get around to doing this at some point.

I was frustrated earlier today by our Jake-based build, and I had always talked about how it'd be easier to work with as another task runner. So this evening I did just what I always said I would - I ported our Jakefile to a Gulpfile. Added bonus: It's now written in typescript! And there's a gulp help command!

Gulp is orders of magnitude more popular than Jake nowadays, and sees much more active use - external contributors are more likely to have existing experiences with gulp. We can also continue moving parts of the build to in-memory streams for a bit more efficiency once this is done.

@DanielRosenwasser @sandersn @yuit You guys should definitely take a look.

@weswigham weswigham added the Infrastructure Issue relates to TypeScript team infrastructure label Jun 10, 2016
@sandersn
Copy link
Copy Markdown
Member

@rbuckton can you take a look too? I think you know the most about gulp around here.

@sandersn
Copy link
Copy Markdown
Member

I almost always C-c tests when they pass and start linting. And when I realise I'm building the wrong thing, etc. The rename trick probably isn't going to work. :(

Comment thread Jakefile.js
var LKGDirectory = "lib/";

var copyright = "CopyrightNotice.txt";
var thirdParty = "ThirdPartyNoticeText.txt";
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't see this (yet) in the gulpfile.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It was unused. I'll double check if its actually used in the Jakefile and that I forgot something.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I double checked now that I am not on the bus. It's unused.

@yuit
Copy link
Copy Markdown
Contributor

yuit commented Jun 10, 2016

talk with @sandersn instead of deleting the JakeFile completely, may be we should keep the JakeFile for now and travis-CI to use Jake. In the team, we will start using gulp internally for a week or so before switch. Also @sandersn suggests that we should do this on Mon/Tue. instead of Friday. if we decide to merge so things won't break on weekend 😸

@rbuckton
Copy link
Copy Markdown
Contributor

Have you considered using the gulp-typescript plugin to replace compileFile and leverage our existing tsconfig.json files?

@weswigham
Copy link
Copy Markdown
Member Author

weswigham commented Jun 10, 2016

@yuit Considering its build is still broken (workin' on it), I have no illusions about this is getting merged this weekend, lol. As for keeping around the Jakefile for awhile... 🤷. I guess we could.

@rbuckton Yes! This is a thing I want to do! The only reason I didn't was because I wanted to start to replicating our Jakefile's functionality as closely as possible. (Maybe we wanted to keep on using our command-line interface? I dunno)

@weswigham
Copy link
Copy Markdown
Member Author

@sandersn I should have a fix incoming for the terribad workaround - passing an empty array to the types compiler option (thanks @RyanCavanaugh). Unfortunately, we don't (presently) support passing an empty array on the command line - so I'm going to make a PR for that. Then I'm going to swap us to using gulp-typescript in the gulpfile in this branch, which should also remove the issue.

Comment thread Gulpfile.ts Outdated
});
});

gulp.task("generate-code-coverage", "Generates code coverage data via instanbul", ["tests"], (done) => {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Typo: istanbul

@sandersn
Copy link
Copy Markdown
Member

I vote that you undo the removal of the Jakefile and make sure Travis still works with jake, then merge this. We can test it over the next week or so and then switch Travis.

@weswigham
Copy link
Copy Markdown
Member Author

weswigham commented Jun 14, 2016

@sandersn @rbuckton @yuit Updated! Kept the Jakefile for a transition period, as requested (and the package.json pointing at jake), and rewrote all the compilation tasks in the gulpfile to use gulp-typescript which, conveniently, removed the need for the @types folder hackery. Another interesting change this required was that instead of just building tsc.js to use the built local compiler, the entire services layer has to get made instead (in order to make our node-compatible typescript.js).

Comment thread Gulpfile.ts Outdated

function exec(cmd: string, args: string[], complete: () => void = (() => {}), error: (e: any, status: number) => void = (() => {})) {
console.log(`${cmd} ${args.join(" ")}`);
const ex = cp.spawn(cmd, args);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

consider:

const ex = cp.spawn(cmd, args, { stdio: "inherit" });

Then you can drop the ex.stdout.pipe(process.stdout); and ex.stderr.pipe(process.stderr); lines.

Copy link
Copy Markdown
Contributor

@rbuckton rbuckton Jun 17, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also if you do:

const ex = cp.spawn(isWin ? "cmd" : "/bin/sh", [isWin ? "/c" : "-c", cmd, ...args], { stdio: "inherit", windowsVerbatimArguments: true });

It will use the OS shell to launch the command, letting spawn leverage the PATH environment variable and automatically handle executables without appending .cmd, etc.

@weswigham
Copy link
Copy Markdown
Member Author

weswigham commented Jun 20, 2016

@rbuckton Updated to handle your comments and, now that newer is guarding every stream, add a watch task which runs runtests-parallel.

@weswigham
Copy link
Copy Markdown
Member Author

weswigham commented Jun 20, 2016

Sourcemaps should now work in every context (browser, vscode); without using inline sources.

@weswigham weswigham changed the title Remove Jakefile.js, Add Gulpfile.ts Add Gulpfile.ts Jun 20, 2016
Comment thread Gulpfile.ts Outdated
js.pipe(sourcemaps.write("."))

return merge2([
js.pipe(gIf(useDebugMode, insert.prepend(fs.readFileSync(copyright))))
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we make this less eager using lazypipe?

Comment thread Gulpfile.ts Outdated
.pipe(sourcemaps.init())
.pipe(tsc(localCompilerProject))
.pipe(gIf(useDebugMode, insert.prepend(fs.readFileSync(copyright))))
.pipe(gIf(useDebugMode, prependCopyright()))
Copy link
Copy Markdown
Contributor

@rbuckton rbuckton Jun 21, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I played around with this and this still ends up eagerly calling fs.readFileSync.

Another option that does not use gulp-if/lazypipe would be:

import { PassThrough } from "stream";

...

    return localCompilerProject.src()
        .pipe(newer(builtLocalCompiler))
        .pipe(sourcemaps.init())
        .pipe(tsc(localCompilerProject)) 
        .pipe(useDebugMode ? insert.prepend(fs.readFileSync(copyright)) : pass())
        .pipe(sourcemaps.write(".")) 
        .pipe(gulp.dest(builtLocalDirectory));

...

function pass() {
  return new PassThrough({ objectMode: true });
}

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Or why not just insert.prepend(useDebugMode ? fs.readFileSync(copyright) : ""), any avoid both of those dependencies?

Comment thread Gulpfile.ts Outdated
});

const scriptsTsdJson = path.join(scriptsDirectory, "tsd.json");
gulp.task("tsd-scripts", `Runs \`tsd --config ${scriptsTsdJson}\` install`, [], (done) => {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i would remove this.

Comment thread Gulpfile.ts
const nodeServerInFile = "tests/webTestServer.ts";
gulp.task(nodeServerOutFile, false, [servicesFile], () => {
const settings: tsc.Settings = getCompilerSettings({}, /*useBuiltCompiler*/ true);
const settings: tsc.Settings = getCompilerSettings({module: "commonjs"}, /*useBuiltCompiler*/ true);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: whitespace

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure what whitespace you're complaining about, but whatever it is I guess it should be codified because our lint rules don't catch it.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

probably { module: "commonjs" } -- spaces after { and before}

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah - this style is inconsistently enforced, I have instances both with and without spaces in the compiler. We need a lint rule for this, one way or the other, if people are going to display a preference.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Additionally, is this supposed to be consistent with binding patterns and/or template strings? I'm internally consistent in the Gulpefile (no leading/trailing whitespace for any), but again, we're inconsistent within the compiler.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can't find it, so probably we should just have a discussion and vote on which linter rule we want to turn on. (Does TSLint have it? ESLint does -- object curly spacing)

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't see any tslint rules white would cover whitespace before/after curlys.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've written a rule to check which is the dominant style - by and large with whitespace is more prevalent in our codebase, so I assume the default should be with whitespace.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm going to merge this without fixing these nits and the fix them when I merge the lint rule catching them, is that okay?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Works for me. @rbuckton ?

@weswigham weswigham merged commit be6c34f into microsoft:master Jun 23, 2016
@weswigham weswigham deleted the remove-jake branch October 12, 2017 08:05
@microsoft microsoft locked and limited conversation to collaborators Jun 19, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

Infrastructure Issue relates to TypeScript team infrastructure

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants