Skip to content

Commit 60e669c

Browse files
jjuddevmar
authored andcommitted
Remove closure compilation from the CLI (#155)
This removes the need for google-closure-compiler to be a dependency. Now it can be a dev dependency and the CLI should just work when downloaded from npm. Because the closure compiler has been removed, temporary files are always output because tsickle is now a wrapper around the TypeScript compiler.
1 parent 9d641fb commit 60e669c

File tree

2 files changed

+7
-66
lines changed

2 files changed

+7
-66
lines changed

README.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,8 @@ well.
2626

2727
### Invocation
2828

29-
Run `tsickle --help` for the full syntax, but basically you specify the minified
30-
output bundle path and the input TypeScript project.
29+
Run `tsickle --help` for the full syntax, but basically you provide any tsickle
30+
specific options and use it as a TypeScript compiler.
3131

3232
## Development
3333

src/main.ts

+5-64
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
#!/usr/bin/env node
22

3-
import * as closure from 'google-closure-compiler';
43
import * as fs from 'fs';
54
import * as minimist from 'minimist';
65
import * as path from 'path';
@@ -18,26 +17,18 @@ const internalExternsFileName = 'tsickle_externs.js';
1817

1918
/** Tsickle settings passed on the command line. */
2019
interface Settings {
21-
/** If true, write temporary .js files to disk. Useful for debugging. */
22-
saveTemporaries?: boolean;
23-
2420
/** If provided, path to save externs to. */
2521
externsPath?: string;
26-
27-
/** Path to write the final JS bundle to. */
28-
outputPath: string;
2922
}
3023

3124
function usage() {
32-
console.error(`usage: tsickle [tsickle args] -- [tsc args]
25+
console.error(`usage: tsickle [tsickle options] -- [tsc options]
3326
3427
example:
35-
tsickle --output bundle.js -- -p src --noImplicitAny
28+
tsickle --externs=foo/externs.js -- -p src --noImplicitAny
3629
3730
tsickle flags are:
38-
--saveTemporaries save intermediate .js files to disk
3931
--externs=PATH save generated Closure externs.js to PATH
40-
--output=PATH write final Closure bundle to PATH
4132
`);
4233
}
4334

@@ -46,10 +37,7 @@ tsickle flags are:
4637
* the arguments to pass on to tsc.
4738
*/
4839
function loadSettingsFromArgs(args: string[]): {settings: Settings, tscArgs: string[]} {
49-
let settings: Settings = {
50-
saveTemporaries: null,
51-
outputPath: null,
52-
};
40+
let settings: Settings = {};
5341
let parsedArgs = minimist(args);
5442
for (let flag of Object.keys(parsedArgs)) {
5543
switch (flag) {
@@ -58,15 +46,9 @@ function loadSettingsFromArgs(args: string[]): {settings: Settings, tscArgs: str
5846
usage();
5947
process.exit(0);
6048
break;
61-
case 'saveTemporaries':
62-
settings.saveTemporaries = true;
63-
break;
6449
case 'externs':
6550
settings.externsPath = parsedArgs[flag];
6651
break;
67-
case 'output':
68-
settings.outputPath = parsedArgs[flag];
69-
break;
7052
case '_':
7153
// This is part of the minimist API, and holds args after the '--'.
7254
break;
@@ -76,11 +58,6 @@ function loadSettingsFromArgs(args: string[]): {settings: Settings, tscArgs: str
7658
process.exit(1);
7759
}
7860
}
79-
if (!settings.outputPath && !settings.externsPath) {
80-
console.error('must specify --output or --externs path');
81-
usage();
82-
process.exit(1);
83-
}
8461
// Arguments after the '--' arg are arguments to tsc.
8562
let tscArgs = parsedArgs['_'];
8663
return {settings, tscArgs};
@@ -220,32 +197,6 @@ function toClosureJS(options: ts.CompilerOptions, fileNames: string[]):
220197
return {jsFiles};
221198
}
222199

223-
function closureCompile(
224-
jsFiles: {[fileName: string]: string}, outFile: string,
225-
callback: (exitCode: number, output: string) => void): void {
226-
const closureOptions: closure.CompileOptions = {
227-
// Read input files from stdin as JSON.
228-
'json_streams': 'IN',
229-
// Write output file to disk.
230-
'js_output_file': outFile,
231-
'warning_level': 'VERBOSE',
232-
'language_in': 'ECMASCRIPT6_STRICT',
233-
'compilation_level': 'ADVANCED_OPTIMIZATIONS',
234-
};
235-
236-
let compiler = new closure.compiler(closureOptions);
237-
let process = compiler.run((exitCode, stdout, stderr) => { callback(exitCode, stderr); });
238-
239-
let jsonInput: closure.JSONStreamFile[] = [];
240-
for (let fileName of Object.keys(jsFiles)) {
241-
jsonInput.push({
242-
path: fileName,
243-
src: jsFiles[fileName],
244-
});
245-
}
246-
process.stdin.end(JSON.stringify(jsonInput));
247-
}
248-
249200
function main(args: string[]) {
250201
let {settings, tscArgs} = loadSettingsFromArgs(args);
251202
let {options, fileNames, errors} = loadTscConfig(tscArgs);
@@ -266,23 +217,13 @@ function main(args: string[]) {
266217
process.exit(1);
267218
}
268219

269-
if (settings.saveTemporaries) {
270-
for (let fileName of Object.keys(jsFiles)) {
271-
fs.writeFileSync(fileName, jsFiles[fileName]);
272-
}
220+
for (let fileName of Object.keys(jsFiles)) {
221+
fs.writeFileSync(fileName, jsFiles[fileName]);
273222
}
274223

275224
if (settings.externsPath) {
276225
fs.writeFileSync(settings.externsPath, jsFiles[internalExternsFileName]);
277226
}
278-
279-
if (settings.outputPath) {
280-
// Run Closure compiiler to convert JS files to output bundle.
281-
closureCompile(jsFiles, settings.outputPath, (exitCode, output) => {
282-
if (output) console.error(output);
283-
process.exit(exitCode);
284-
});
285-
}
286227
}
287228

288229
// CLI entry point

0 commit comments

Comments
 (0)