├── .gitignore
├── .gitmodules
├── .npmignore
├── .travis.yml
├── CONTRIBUTING.md
├── LICENSE
├── README.md
├── build_compiler.js
├── cmd.js
├── compile.js
├── index.js
├── lib
├── gulp.js
└── webpack.js
├── logger.js
├── package-lock.json
├── package.json
├── samples
├── .gitignore
├── README.md
├── gulpfile.js
├── package-lock.json
├── package.json
└── src
│ ├── helper.js
│ └── index.js
├── test
├── mocha.opts
└── simple.js
└── usage.txt
/.gitignore:
--------------------------------------------------------------------------------
1 | node_modules
2 | .DS_Store
3 |
4 | # build artifacts
5 | contrib
6 | externs
7 | jscomp.js
8 |
--------------------------------------------------------------------------------
/.gitmodules:
--------------------------------------------------------------------------------
1 | [submodule "closure-compiler"]
2 | path = closure-compiler
3 | url = https://github.com/google/closure-compiler
4 |
--------------------------------------------------------------------------------
/.npmignore:
--------------------------------------------------------------------------------
1 | closure-compiler
2 | node_modules
3 | .DS_Store
4 | externs/pom.xml
5 | test
6 | samples
7 |
--------------------------------------------------------------------------------
/.travis.yml:
--------------------------------------------------------------------------------
1 | language: node_js
2 |
3 | node_js:
4 | - lts/argon
5 | - stable
6 |
--------------------------------------------------------------------------------
/CONTRIBUTING.md:
--------------------------------------------------------------------------------
1 | Want to contribute? Great! First, read this page (including the small print at the end).
2 |
3 | ### Before you contribute
4 | Before we can use your code, you must sign the
5 | [Google Individual Contributor License Agreement](https://developers.google.com/open-source/cla/individual?csw=1)
6 | (CLA), which you can do online. The CLA is necessary mainly because you own the
7 | copyright to your changes, even after your contribution becomes part of our
8 | codebase, so we need your permission to use and distribute your code. We also
9 | need to be sure of various other things—for instance that you'll tell us if you
10 | know that your code infringes on other people's patents. You don't have to sign
11 | the CLA until after you've submitted your code for review and a member has
12 | approved it, but you must do it before we can put your code into our codebase.
13 | Before you start working on a larger contribution, you should get in touch with
14 | us first through the issue tracker with your idea so that we can help out and
15 | possibly guide you. Coordinating up front makes it much easier to avoid
16 | frustration later on.
17 |
18 | ### Code reviews
19 | All submissions, including submissions by project members, require review. We
20 | use Github pull requests for this purpose.
21 |
22 | ### The small print
23 | Contributions made by corporations are covered by a different agreement than
24 | the one above, the Software Grant and Corporate Contributor License Agreement.
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | Apache License
2 | Version 2.0, January 2004
3 | http://www.apache.org/licenses/
4 |
5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6 |
7 | 1. Definitions.
8 |
9 | "License" shall mean the terms and conditions for use, reproduction,
10 | and distribution as defined by Sections 1 through 9 of this document.
11 |
12 | "Licensor" shall mean the copyright owner or entity authorized by
13 | the copyright owner that is granting the License.
14 |
15 | "Legal Entity" shall mean the union of the acting entity and all
16 | other entities that control, are controlled by, or are under common
17 | control with that entity. For the purposes of this definition,
18 | "control" means (i) the power, direct or indirect, to cause the
19 | direction or management of such entity, whether by contract or
20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the
21 | outstanding shares, or (iii) beneficial ownership of such entity.
22 |
23 | "You" (or "Your") shall mean an individual or Legal Entity
24 | exercising permissions granted by this License.
25 |
26 | "Source" form shall mean the preferred form for making modifications,
27 | including but not limited to software source code, documentation
28 | source, and configuration files.
29 |
30 | "Object" form shall mean any form resulting from mechanical
31 | transformation or translation of a Source form, including but
32 | not limited to compiled object code, generated documentation,
33 | and conversions to other media types.
34 |
35 | "Work" shall mean the work of authorship, whether in Source or
36 | Object form, made available under the License, as indicated by a
37 | copyright notice that is included in or attached to the work
38 | (an example is provided in the Appendix below).
39 |
40 | "Derivative Works" shall mean any work, whether in Source or Object
41 | form, that is based on (or derived from) the Work and for which the
42 | editorial revisions, annotations, elaborations, or other modifications
43 | represent, as a whole, an original work of authorship. For the purposes
44 | of this License, Derivative Works shall not include works that remain
45 | separable from, or merely link (or bind by name) to the interfaces of,
46 | the Work and Derivative Works thereof.
47 |
48 | "Contribution" shall mean any work of authorship, including
49 | the original version of the Work and any modifications or additions
50 | to that Work or Derivative Works thereof, that is intentionally
51 | submitted to Licensor for inclusion in the Work by the copyright owner
52 | or by an individual or Legal Entity authorized to submit on behalf of
53 | the copyright owner. For the purposes of this definition, "submitted"
54 | means any form of electronic, verbal, or written communication sent
55 | to the Licensor or its representatives, including but not limited to
56 | communication on electronic mailing lists, source code control systems,
57 | and issue tracking systems that are managed by, or on behalf of, the
58 | Licensor for the purpose of discussing and improving the Work, but
59 | excluding communication that is conspicuously marked or otherwise
60 | designated in writing by the copyright owner as "Not a Contribution."
61 |
62 | "Contributor" shall mean Licensor and any individual or Legal Entity
63 | on behalf of whom a Contribution has been received by Licensor and
64 | subsequently incorporated within the Work.
65 |
66 | 2. Grant of Copyright License. Subject to the terms and conditions of
67 | this License, each Contributor hereby grants to You a perpetual,
68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69 | copyright license to reproduce, prepare Derivative Works of,
70 | publicly display, publicly perform, sublicense, and distribute the
71 | Work and such Derivative Works in Source or Object form.
72 |
73 | 3. Grant of Patent License. Subject to the terms and conditions of
74 | this License, each Contributor hereby grants to You a perpetual,
75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76 | (except as stated in this section) patent license to make, have made,
77 | use, offer to sell, sell, import, and otherwise transfer the Work,
78 | where such license applies only to those patent claims licensable
79 | by such Contributor that are necessarily infringed by their
80 | Contribution(s) alone or by combination of their Contribution(s)
81 | with the Work to which such Contribution(s) was submitted. If You
82 | institute patent litigation against any entity (including a
83 | cross-claim or counterclaim in a lawsuit) alleging that the Work
84 | or a Contribution incorporated within the Work constitutes direct
85 | or contributory patent infringement, then any patent licenses
86 | granted to You under this License for that Work shall terminate
87 | as of the date such litigation is filed.
88 |
89 | 4. Redistribution. You may reproduce and distribute copies of the
90 | Work or Derivative Works thereof in any medium, with or without
91 | modifications, and in Source or Object form, provided that You
92 | meet the following conditions:
93 |
94 | (a) You must give any other recipients of the Work or
95 | Derivative Works a copy of this License; and
96 |
97 | (b) You must cause any modified files to carry prominent notices
98 | stating that You changed the files; and
99 |
100 | (c) You must retain, in the Source form of any Derivative Works
101 | that You distribute, all copyright, patent, trademark, and
102 | attribution notices from the Source form of the Work,
103 | excluding those notices that do not pertain to any part of
104 | the Derivative Works; and
105 |
106 | (d) If the Work includes a "NOTICE" text file as part of its
107 | distribution, then any Derivative Works that You distribute must
108 | include a readable copy of the attribution notices contained
109 | within such NOTICE file, excluding those notices that do not
110 | pertain to any part of the Derivative Works, in at least one
111 | of the following places: within a NOTICE text file distributed
112 | as part of the Derivative Works; within the Source form or
113 | documentation, if provided along with the Derivative Works; or,
114 | within a display generated by the Derivative Works, if and
115 | wherever such third-party notices normally appear. The contents
116 | of the NOTICE file are for informational purposes only and
117 | do not modify the License. You may add Your own attribution
118 | notices within Derivative Works that You distribute, alongside
119 | or as an addendum to the NOTICE text from the Work, provided
120 | that such additional attribution notices cannot be construed
121 | as modifying the License.
122 |
123 | You may add Your own copyright statement to Your modifications and
124 | may provide additional or different license terms and conditions
125 | for use, reproduction, or distribution of Your modifications, or
126 | for any such Derivative Works as a whole, provided Your use,
127 | reproduction, and distribution of the Work otherwise complies with
128 | the conditions stated in this License.
129 |
130 | 5. Submission of Contributions. Unless You explicitly state otherwise,
131 | any Contribution intentionally submitted for inclusion in the Work
132 | by You to the Licensor shall be under the terms and conditions of
133 | this License, without any additional terms or conditions.
134 | Notwithstanding the above, nothing herein shall supersede or modify
135 | the terms of any separate license agreement you may have executed
136 | with Licensor regarding such Contributions.
137 |
138 | 6. Trademarks. This License does not grant permission to use the trade
139 | names, trademarks, service marks, or product names of the Licensor,
140 | except as required for reasonable and customary use in describing the
141 | origin of the Work and reproducing the content of the NOTICE file.
142 |
143 | 7. Disclaimer of Warranty. Unless required by applicable law or
144 | agreed to in writing, Licensor provides the Work (and each
145 | Contributor provides its Contributions) on an "AS IS" BASIS,
146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147 | implied, including, without limitation, any warranties or conditions
148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149 | PARTICULAR PURPOSE. You are solely responsible for determining the
150 | appropriateness of using or redistributing the Work and assume any
151 | risks associated with Your exercise of permissions under this License.
152 |
153 | 8. Limitation of Liability. In no event and under no legal theory,
154 | whether in tort (including negligence), contract, or otherwise,
155 | unless required by applicable law (such as deliberate and grossly
156 | negligent acts) or agreed to in writing, shall any Contributor be
157 | liable to You for damages, including any direct, indirect, special,
158 | incidental, or consequential damages of any character arising as a
159 | result of this License or out of the use or inability to use the
160 | Work (including but not limited to damages for loss of goodwill,
161 | work stoppage, computer failure or malfunction, or any and all
162 | other commercial damages or losses), even if such Contributor
163 | has been advised of the possibility of such damages.
164 |
165 | 9. Accepting Warranty or Additional Liability. While redistributing
166 | the Work or Derivative Works thereof, You may choose to offer,
167 | and charge a fee for, acceptance of support, warranty, indemnity,
168 | or other liability obligations and/or rights consistent with this
169 | License. However, in accepting such obligations, You may act only
170 | on Your own behalf and on Your sole responsibility, not on behalf
171 | of any other Contributor, and only if You agree to indemnify,
172 | defend, and hold each Contributor harmless for any liability
173 | incurred by, or claims asserted against, such Contributor by reason
174 | of your accepting any such warranty or additional liability.
175 |
176 | END OF TERMS AND CONDITIONS
177 |
178 | APPENDIX: How to apply the Apache License to your work.
179 |
180 | To apply the Apache License to your work, attach the following
181 | boilerplate notice, with the fields enclosed by brackets "{}"
182 | replaced with your own identifying information. (Don't include
183 | the brackets!) The text should be enclosed in the appropriate
184 | comment syntax for the file format. We also recommend that a
185 | file or class name and description of purpose be included on the
186 | same "printed page" as the copyright notice for easier
187 | identification within third-party archives.
188 |
189 | Copyright {yyyy} {name of copyright owner}
190 |
191 | Licensed under the Apache License, Version 2.0 (the "License");
192 | you may not use this file except in compliance with the License.
193 | You may obtain a copy of the License at
194 |
195 | http://www.apache.org/licenses/LICENSE-2.0
196 |
197 | Unless required by applicable law or agreed to in writing, software
198 | distributed under the License is distributed on an "AS IS" BASIS,
199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200 | See the License for the specific language governing permissions and
201 | limitations under the License.
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # closure-compiler-js
2 |
3 | **Note**: This package is now deprecated. Distribution of the JavaScript version has been moved to the main npm distribution at https://www.npmjs.com/package/google-closure-compiler. This package will continue
4 | to work, but no new versions of the package will be published.
5 |
6 |
7 |
8 | Check, compile, transpile, optimize and compress JavaScript with Closure Compiler in JS.
9 |
10 | This repo tracks issues related to the publication to npmjs.org and associated plugins.
11 | Any bugs not related to the plugins themselves should be reported to the [main repository](https://github.com/google/closure-compiler/).
12 |
13 | Unlike other packages, this allows Closure Compiler to run entirely in JS.
14 | *Java is not required.*
15 |
16 | This is an experimental release - meaning some features are not available and performance may not be on-par with the Java implementation - [details here](#transpilation).
17 |
18 | ## Usage
19 |
20 | *These instructions will continue to work, but the package is deprecated.
21 | Development has moved to https://www.npmjs.com/package/google-closure-compiler.*
22 |
23 | First, install the latest version:
24 |
25 | ```bash
26 | yarn add google-closure-compiler-js --dev # or
27 | npm install --save-dev google-closure-compiler-js
28 | ```
29 |
30 | The module supports modern web browsers as well as Node v4 LTS, and provides `compile` as a low-level method to compile JavaScript.
31 | By default, this compiles ES6 to ES5 and includes the default set of ECMAScript externs files.
32 | For example:
33 |
34 | ```js
35 | const compile = require('google-closure-compiler-js').compile;
36 |
37 | const flags = {
38 | jsCode: [{src: 'const x = 1 + 2;'}],
39 | };
40 | const out = compile(flags);
41 | console.info(out.compiledCode); // will print 'var x = 3;\n'
42 | ```
43 |
44 | Or to install the command-line version, do:
45 |
46 | ```bash
47 | npm install -g google-closure-compiler-js
48 | ```
49 |
50 | You should now be able to run `google-closure-compiler-js` as a command.
51 | The `google-closure-compiler-js` command can read from stdin or from a file.
52 | For example:
53 |
54 | ```bash
55 | google-closure-compiler-js code.js > minified.js
56 | ```
57 |
58 | Run `google-closure-compiler-js --help` for full usage information.
59 |
60 | ## Build Systems
61 |
62 | ### Webpack
63 |
64 | Your `webpack.config.js` should look like this:
65 |
66 | ```js
67 | const ClosureCompiler = require('google-closure-compiler-js').webpack;
68 | const path = require('path');
69 |
70 | module.exports = {
71 | entry: [
72 | path.join(__dirname, 'app.js')
73 | ],
74 | output: {
75 | path: path.join(__dirname, 'dist'),
76 | filename: 'app.min.js'
77 | },
78 | plugins: [
79 | new ClosureCompiler({
80 | options: {
81 | languageIn: 'ECMASCRIPT6',
82 | languageOut: 'ECMASCRIPT5',
83 | compilationLevel: 'ADVANCED',
84 | warningLevel: 'VERBOSE',
85 | },
86 | })
87 | ]
88 | };
89 | ```
90 |
91 | ### Gulp
92 |
93 | Your `gulpfile.js` should contain a task like this:
94 |
95 | ```js
96 | const compiler = require('google-closure-compiler-js').gulp();
97 |
98 | gulp.task('script', function() {
99 | return gulp.src('./path/to/src.js', {base: './'})
100 | // your other steps here
101 | .pipe(compiler({
102 | compilationLevel: 'SIMPLE',
103 | warningLevel: 'VERBOSE',
104 | outputWrapper: '(function(){\n%output%\n}).call(this)',
105 | jsOutputFile: 'output.min.js', // outputs single file
106 | createSourceMap: true,
107 | }))
108 | .pipe(gulp.dest('./dist'));
109 | });
110 | ```
111 |
112 | ## Flags
113 |
114 | | Flag | Default | Usage |
115 | |----------------------------------|---------|-------|
116 | | angularPass | false | Generate $inject properties for AngularJS for functions annotated with @ngInject |
117 | | applyInputSourceMaps | true | Compose input source maps into output source map |
118 | | assumeFunctionWrapper | false | Enable additional optimizations based on the assumption that the output will be wrapped with a function wrapper. This flag is used to indicate that "global" declarations will not actually be global but instead isolated to the compilation unit. This enables additional optimizations. |
119 | | checksOnly | false | Don't generate output. Run checks, but no optimization passes. |
120 | | compilationLevel | SIMPLE | Specifies the compilation level to use.
Options: WHITESPACE_ONLY, SIMPLE, ADVANCED |
121 | | dartPass | false | |
122 | | defines | null | Overrides the value of variables annotated with `@define`, an object mapping names to primitive types |
123 | | env | BROWSER | Determines the set of builtin externs to load.
Options: BROWSER, CUSTOM |
124 | | exportLocalPropertyDefinitions | false | |
125 | | generateExports | false | Generates export code for those marked with @export. |
126 | | languageIn | ES6 | Sets what language spec that input sources conform to. |
127 | | languageOut | ES5 | Sets what language spec the output should conform to. |
128 | | newTypeInf | false | Checks for type errors using the new type inference algorithm. |
129 | | outputWrapper | null | Interpolate output into this string, replacing the token `%output%` |
130 | | polymerVersion | null | Specify the Polymer version pass to use. |
131 | | preserveTypeAnnotations | false | |
132 | | processCommonJsModules | false | Process CommonJS modules to a concatenable form, i.e., support `require` statements. |
133 | | renamePrefixNamespace | | Specifies the name of an object that will be used to store all non-extern globals. |
134 | | rewritePolyfills | true | Rewrite ES6 library calls to use polyfills provided by the compiler's runtime. |
135 | | useTypesForOptimization | false | Enable or disable the optimizations based on available type information. Inaccurate type annotations may result in incorrect results. |
136 | | warningLevel | DEFAULT | Specifies the warning level to use.
Options: QUIET, DEFAULT, VERBOSE |
137 | | jsCode | [] | Specifies the source code to compile. |
138 | | externs | [] | Additional externs to use for this compile. |
139 | | createSourceMap | false | Generates a source map mapping the generated source file back to its original sources. |
140 |
141 | ### Languages
142 |
143 | The Closure Compiler supports the following languages:
144 | - `ECMASCRIPT3`, `ECMASCRIPT5` and `ECMASCRIPT5_STRICT`
145 | - `ECMASCRIPT6` and `ECMASCRIPT6_STRICT`
146 | - `ECMASCRIPT6_TYPED` (experimental)
147 | - `ECMASCRIPT_2017` (experimental)
148 |
149 | ### Source Code
150 |
151 | Unless you're using Gulp's or Webpack's plugins, you'll need to specify code via flags:
152 | - Both `jsCode` and `externs` accept an array containing objects in the form `{src, path, sourceMap}`.
153 | - Using `path` you can construct a virtual filesystem for use with ES6 or CommonJS imports — although for CommonJS you'll have to set `processCommonJsModules: true`.
154 |
155 | ## Transpilation
156 | The JavaScript version of the Closure-Compiler is transpiled by GWT from the Java source.
157 | For more details on the differences in behavior see the [super sourced files][1] in the main
158 | repository.
159 |
160 | [1]: https://github.com/google/closure-compiler/tree/master/src/com/google/javascript/jscomp/gwt/super
161 |
162 | ## Version History
163 |
164 | Closure Compiler release notes can be found on the
165 | [main repository wiki](https://github.com/google/closure-compiler/wiki/Binary-Downloads).
166 |
167 | ## License
168 |
169 | Copyright © 2017 The Closure Compiler Authors
170 |
171 | Licensed under the Apache License, Version 2.0 (the "License");
172 | you may not use this file except in compliance with the License.
173 | You may obtain a copy of the License at
174 |
175 | http://www.apache.org/licenses/LICENSE-2.0
176 |
177 | Unless required by applicable law or agreed to in writing, software
178 | distributed under the License is distributed on an "AS IS" BASIS,
179 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
180 | See the License for the specific language governing permissions and
181 | limitations under the License.
182 |
--------------------------------------------------------------------------------
/build_compiler.js:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env node
2 | /*
3 | * Copyright 2016 The Closure Compiler Authors.
4 | *
5 | * Licensed under the Apache License, Version 2.0 (the "License");
6 | * you may not use this file except in compliance with the License.
7 | * You may obtain a copy of the License at
8 | *
9 | * http://www.apache.org/licenses/LICENSE-2.0
10 | *
11 | * Unless required by applicable law or agreed to in writing, software
12 | * distributed under the License is distributed on an "AS IS" BASIS,
13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 | * See the License for the specific language governing permissions and
15 | * limitations under the License.
16 | */
17 |
18 | /**
19 | * @fileoverview Builds the Closure Compiler using Maven.
20 | */
21 |
22 | 'use strict';
23 |
24 | const spawn = require('child_process').spawnSync;
25 | const ncp = require('ncp');
26 |
27 | const moduleName = 'com.google.javascript:closure-compiler-gwt';
28 | const compilerBuild = spawn(
29 | 'mvn', ['-DskipTests', '--projects', moduleName, 'clean', 'install'], {
30 | cwd: './closure-compiler',
31 | stdio: 'inherit',
32 | });
33 |
34 | if (compilerBuild.status !== 0) {
35 | throw new Error('compiler build failed');
36 | }
37 |
38 | const pathsToCopy = ['contrib'];
39 | const targetPath = './closure-compiler/target/closure-compiler-gwt-1.0-SNAPSHOT/jscomp/jscomp.js';
40 | ncp(targetPath, './jscomp.js', (err) => {
41 | if (err) {
42 | throw new Error(err);
43 | }
44 | pathsToCopy.forEach((p) => {
45 | ncp('./closure-compiler/' + p, './' + p, function(err) {
46 | if (err) {
47 | throw new Error(err);
48 | }
49 | });
50 | });
51 | });
52 |
--------------------------------------------------------------------------------
/cmd.js:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env node
2 | /*
3 | * Copyright 2016 The Closure Compiler Authors.
4 | *
5 | * Licensed under the Apache License, Version 2.0 (the "License");
6 | * you may not use this file except in compliance with the License.
7 | * You may obtain a copy of the License at
8 | *
9 | * http://www.apache.org/licenses/LICENSE-2.0
10 | *
11 | * Unless required by applicable law or agreed to in writing, software
12 | * distributed under the License is distributed on an "AS IS" BASIS,
13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 | * See the License for the specific language governing permissions and
15 | * limitations under the License.
16 | */
17 |
18 | /**
19 | * @fileoverview Command-line interface for Google Closure Compiler in JS
20 | */
21 |
22 | 'use strict';
23 |
24 | const fs = require('fs');
25 | const path = require('path');
26 | const minimist = require('minimist');
27 | const compile = require('./compile.js');
28 | const logger = require('./logger.js');
29 |
30 | const argv = minimist(process.argv.slice(2), {
31 | alias: {h: 'help', v: 'version'},
32 | });
33 | if (argv.help) {
34 | const helpfile = path.join(__dirname, 'usage.txt');
35 | return fs.readFile(helpfile, 'utf8', (err, src) => {
36 | if (err) {
37 | error(err)
38 | } else {
39 | console.log(src);
40 | }
41 | });
42 | }
43 | if (argv.version) {
44 | return console.log(require('./package.json').version);
45 | }
46 |
47 | const infiles = argv._.concat(toArray(argv.jsCode)); // treat jsCode as _
48 | if (infiles.length === 0) {
49 | infiles.push(null); // if no files were specified, read from stdin
50 | }
51 | const sources = readAllFiles(infiles);
52 | delete argv._;
53 | delete argv.jsCode;
54 |
55 | const externs = readAllFiles(toArray(argv.externs));
56 | delete argv.externs;
57 |
58 | Promise.all([sources, externs]).then(arr => ready(arr[0], arr[1])).catch(error);
59 |
60 | /**
61 | * Minimist gives us a string, array or null: normalize to array.
62 | *
63 | * @param {(string|Array)}
64 | * @return {!Array}
65 | */
66 | function toArray(arg) {
67 | if (typeof arg === 'string') {
68 | return [arg];
69 | } else if (arg) {
70 | return arg;
71 | } else {
72 | return [];
73 | }
74 | }
75 |
76 | /**
77 | * @param {!Array} paths
78 | * @return {!Promise>}
79 | */
80 | function readAllFiles(paths) {
81 | return Promise.all(paths.map(path => readFile(path)));
82 | }
83 |
84 | /**
85 | * @param {?string} path
86 | * @return {!Promise<{src: string, path: string}>}
87 | */
88 | function readFile(path) {
89 | return new Promise((resolve, reject) => {
90 | if (path === null) {
91 | let src = '';
92 | process.stdin.resume();
93 | process.stdin.on('data', buf => src += buf.toString());
94 | process.stdin.on('end', () => resolve({src, path: '-'}));
95 | } else {
96 | fs.readFile(path, 'utf8', (err, src) => err ? reject(err) : resolve({src, path}));
97 | }
98 | });
99 | }
100 |
101 | function parseDefines(flags){
102 | /**
103 | * compile() expects 'defines' to be object, but minimist may only return array or string
104 | * so, we need to convert to proper object.
105 | * The supported format will be similar to the following,
106 | * https://github.com/google/closure-compiler/wiki/Annotating-JavaScript-for-the-Closure-Compiler#define-type-description
107 | * but instead of using --define 'name=value' we should support --defines 'name=value'
108 | */
109 |
110 | if (Array.isArray(flags.defines) || typeof flags.defines === "string"){
111 | let defines = {};
112 | function parseDefines(d) {
113 | let key, value;
114 | {
115 | let a = d.split("=");
116 | key = a[0];
117 | value = a[1];
118 | }
119 | defines[key] =
120 | /^(?:true|false)$/.test(value)
121 | ? value === 'true'
122 | : !isNaN(parseFloat(value)) && isFinite(value)
123 | ? parseFloat(value)
124 | : value;
125 | }
126 | if (Array.isArray(flags.defines)) {
127 | flags.defines.forEach(parseDefines);
128 | } else {
129 | parseDefines(flags.defines);
130 | }
131 | flags.defines = defines;
132 | }
133 | }
134 |
135 | function cmdCompile(flags) {
136 | parseDefines(flags);
137 | return compile(flags);
138 | }
139 | //Mostly for test purpuses.
140 | module.exports = cmdCompile;
141 |
142 | /**
143 | * @param {!Array<{src: string, path: string}>} sources
144 | * @param {!Array<{src: string, path: string}>} externs
145 | */
146 | function ready(sources, externs) {
147 | const flags = Object.assign(Object.assign({}, argv), {jsCode: sources, externs: externs});
148 | const output = cmdCompile(flags);
149 | let code = 0;
150 | if (logger(flags, output)) {
151 | code = 1;
152 | }
153 | console.log(output.compiledCode);
154 |
155 | process.exit(code);
156 | }
157 |
158 | function error(err) {
159 | console.error(err);
160 | process.exit(1);
161 | }
162 |
--------------------------------------------------------------------------------
/compile.js:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2016 The Closure Compiler Authors.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | /**
18 | * @fileoverview Wrapper for the natively built Closure Compiler GWT binary to
19 | * work around quirks. Depending on the release, this file could be empty.
20 | */
21 |
22 | 'use strict';
23 |
24 | const jscomp = require('./jscomp.js');
25 |
26 | module.exports = function(flags) {
27 | const clone = {};
28 | for (const k in flags) {
29 | clone[k] = flags[k];
30 | }
31 | const out = jscomp(clone);
32 |
33 | // hide weird GWT internals
34 | out.warnings = Array.prototype.slice.call(out.warnings);
35 | out.errors = Array.prototype.slice.call(out.errors);
36 |
37 | return out;
38 | };
39 |
--------------------------------------------------------------------------------
/index.js:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2016 The Closure Compiler Authors.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | /**
18 | * @fileoverview NodeJS plugins and build tools for Google Closure Compiler in JS
19 | */
20 |
21 | 'use strict';
22 |
23 | module.exports = {
24 | logger: require('./logger.js'),
25 | compile: require('./compile.js'),
26 | gulp: require('./lib/gulp'),
27 | webpack: require('./lib/webpack'),
28 | };
29 |
--------------------------------------------------------------------------------
/lib/gulp.js:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2016 The Closure Compiler Authors.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | /**
18 | * @fileoverview Gulp task for closure-compiler. Sends multiple input files
19 | * into the compile method of Closure Compiler. This will yield a single
20 | * vinyl file as output. Every input file includes contents, path and optional
21 | * sourcemap.
22 | */
23 |
24 | 'use strict';
25 |
26 | const PLUGIN_NAME = 'gulp-google-closure-compiler-js';
27 | const DEFAULT_OUTPUT_PATH = 'compiled.js';
28 |
29 |
30 | /**
31 | * Convert keys in the form "--foo_bar" or "zing_foo" to "fooBar" or "zingFoo", respectively.
32 | *
33 | * @param {string} key to convert
34 | * @return {string}
35 | */
36 | function cleanupOptionKey(key) {
37 | // replace "_foo" with "Foo"
38 | key = key.replace(/_(\w)/g, match => match[1].toUpperCase());
39 |
40 | // remove leading dashes
41 | key = key.replace(/^--/, '');
42 |
43 | return key;
44 | }
45 |
46 |
47 | /**
48 | * @return {function(Object=, Object=):Object}
49 | */
50 | module.exports = function() {
51 | const events = require('events');
52 | const path = require('path');
53 |
54 | const compile = require('../compile');
55 | const logger = require('../logger');
56 | const File = require('vinyl');
57 | const Transform = require('stream').Transform;
58 |
59 | class CompilationStream extends Transform {
60 | constructor(compilationOptions, pluginOptions) {
61 | super({objectMode: true});
62 |
63 | this.compilationOptions_ = compilationOptions;
64 | this.pluginName_ = pluginOptions.pluginName || PLUGIN_NAME;
65 | this.logger_ = pluginOptions.logger || (message => console.info(message));
66 |
67 | this.fileList_ = [];
68 | }
69 |
70 | _transform(file, enc, cb) {
71 | if (file.isNull()) {
72 | // Ignore empty files.
73 | } else if (file.isStream()) {
74 | this.emit('error', new PluginError(this.pluginName_, 'Streaming not supported'));
75 | } else {
76 | this.fileList_.push(file);
77 | }
78 | cb();
79 | }
80 |
81 | _flush(cb) {
82 | const options = {};
83 | for (const k in this.compilationOptions_) {
84 | options[cleanupOptionKey(k)] = this.compilationOptions_[k];
85 | }
86 | options.jsCode = (options.jsCode || []).concat(this.fileList_.map(file => {
87 | return {
88 | // TODO(samthor): It's not clear we always want to have modules rooted 'here'
89 | path: path.relative(process.cwd(), file.path),
90 | src: file.contents.toString(),
91 | sourceMap: file.sourceMap ? JSON.stringify(file.sourceMap) : undefined,
92 | };
93 | }));
94 |
95 | const outputFile = options.jsOutputFile;
96 | delete options.jsOutputFile;
97 |
98 | const output = compile(options);
99 | if (logger(options, output, this.logger_)) {
100 | const message = `Compilation error, ${output.errors.length} errors`;
101 | this.emit('error', new PluginError(this.pluginName_, message));
102 | }
103 |
104 | const file = new File({
105 | path: outputFile || DEFAULT_OUTPUT_PATH,
106 | contents: new Buffer(output.compiledCode),
107 | });
108 | if (output.sourceMap) {
109 | file.sourceMap = JSON.parse(output.sourceMap);
110 | }
111 | this.push(file);
112 |
113 | cb();
114 | }
115 | };
116 |
117 | return function(compilationOptions, pluginOptions) {
118 | return new CompilationStream(compilationOptions || {}, pluginOptions || {});
119 | };
120 | };
121 |
122 | class PluginError {
123 | constructor(plugin, message) {
124 | this.plugin = plugin;
125 | this.message = message;
126 | }
127 | }
128 |
--------------------------------------------------------------------------------
/lib/webpack.js:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2016 The Closure Compiler Authors.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | /**
18 | * @fileoverview Webpack plugin for Closure Compiler.
19 | */
20 |
21 | 'use strict';
22 |
23 | function formatMessage(msg) {
24 | let formatted = `(${msg.type}) ${msg.description}`;
25 |
26 | if (msg.file && msg.lineNo >= 0) {
27 | formatted = `${msg.file}:${msg.lineNo} ${formatted}`;
28 | }
29 |
30 | return formatted;
31 | }
32 |
33 | module.exports = function(args) {
34 | const compile = require('../compile');
35 | const RawSource = require('webpack-core/lib/RawSource');
36 | const SourceMapSource = require('webpack-core/lib/SourceMapSource');
37 |
38 | args.test = args && args.test ? new RegExp(args.test) : /\.js($|\?)/i;
39 |
40 | this.apply = function(compiler) {
41 | compiler.plugin('compilation', compilation => {
42 | compilation.plugin('normal-module-loader', context => {
43 | context.minimize = true;
44 | });
45 |
46 | compilation.plugin('optimize-chunk-assets', (chunks, callback) => {
47 | chunks.forEach(chunk => {
48 | const files = chunk.files.filter(name => args.test.test(name));
49 | files.forEach(name => {
50 | const options = args && args.options ? args.options : {}; // TODO
51 |
52 | const asset = compilation.assets[name];
53 | const sourceMap = asset.map();
54 | const file = {
55 | path: name,
56 | src: asset.source(),
57 | sourceMap: sourceMap ? JSON.stringify(sourceMap) : undefined,
58 | };
59 | options.jsCode = [file];
60 |
61 | const output = compile(options);
62 |
63 | output.errors.forEach(msg => {
64 | compilation.errors.push(new Error(formatMessage(msg)));
65 | });
66 |
67 | output.warnings.forEach(msg => {
68 | compilation.warnings.push(new Error(formatMessage(msg)));
69 | });
70 |
71 | if (output.errors.length > 0) {
72 | return; // don't save compilation
73 | }
74 |
75 | let result;
76 | if (output.sourceMap) {
77 | result = new SourceMapSource(
78 | output.compiledCode, name, JSON.parse(output.sourceMap), file.src, file.sourceMap);
79 | } else {
80 | result = new RawSource(output.compiledCode);
81 | }
82 | compilation.assets[name] = result;
83 | });
84 | });
85 |
86 | callback();
87 | });
88 |
89 | });
90 | };
91 |
92 | };
93 |
--------------------------------------------------------------------------------
/logger.js:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2016 The Closure Compiler Authors.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | /**
18 | * @fileoverview Logger for Closure Compiler output.
19 | */
20 |
21 | 'use strict';
22 |
23 | const ESC = '\u001B';
24 | const COLOR_END = ESC + '[0m';
25 | const COLOR_RED = ESC + '[91m';
26 | const COLOR_GREEN = ESC + '[92m';
27 | const COLOR_YELLOW = ESC + '[93m';
28 |
29 | /**
30 | * @param {string} line to generate prefix for
31 | * @param {number} charNo to generate prefix at
32 | * @return {string} prefix for showing a caret
33 | */
34 | function caretPrefix(line, charNo) {
35 | return line.substr(0, charNo).replace(/[^\t]/g, ' ');
36 | }
37 |
38 |
39 | /**
40 | * @param {!Object} options
41 | * @param {!Object} output
42 | * @param {function(string)} logger
43 | * @return {boolean} Whether this output should fail a compilation.
44 | */
45 | module.exports = function(options, output, logger) {
46 | logger = logger || console.warn;
47 | // TODO(samthor): If this file has a sourceMap, then follow it back out of the rabbit hole.
48 | function fileFor(file) {
49 | if (!file) { return null; }
50 |
51 | // Filenames are the same across source and externs, so prefer source files.
52 | for (const files of [options.jsCode, options.externs]) {
53 | if (!files) { continue; }
54 |
55 | for (const cand of files) {
56 | if (cand.path == file) {
57 | return cand;
58 | }
59 | }
60 | }
61 |
62 | return null;
63 | }
64 |
65 | function writemsg(color, msg) {
66 | if (!msg.file && msg.lineNo < 0) {
67 | logger(msg.type);
68 | } else {
69 | logger(`${msg.file}:${msg.lineNo} (${msg.type})`)
70 | }
71 | logger(msg.description);
72 |
73 | const file = fileFor(msg.file);
74 | if (file) {
75 | const lines = file.src.split('\n'); // TODO(samthor): cache this for logger?
76 | const line = lines[msg.lineNo - 1] || '';
77 | logger(color + line + COLOR_END);
78 | logger(COLOR_GREEN + caretPrefix(line, msg.charNo) + '^' + COLOR_END);
79 | }
80 | logger('');
81 | }
82 |
83 | output.warnings.forEach(writemsg.bind(null, COLOR_YELLOW));
84 | output.errors.forEach(writemsg.bind(null, COLOR_RED));
85 |
86 | return output.errors.length > 0;
87 | };
88 |
--------------------------------------------------------------------------------
/package-lock.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "google-closure-compiler-js",
3 | "version": "20180610.0.1",
4 | "lockfileVersion": 1,
5 | "requires": true,
6 | "dependencies": {
7 | "amdefine": {
8 | "version": "1.0.1",
9 | "resolved": "https://registry.npmjs.org/amdefine/-/amdefine-1.0.1.tgz",
10 | "integrity": "sha1-SlKCrBZHKek2Gbz9OtFR+BfOkfU="
11 | },
12 | "assertion-error": {
13 | "version": "1.0.2",
14 | "resolved": "https://registry.npmjs.org/assertion-error/-/assertion-error-1.0.2.tgz",
15 | "integrity": "sha1-E8pRXYYgbaC6xm6DTdOX2HWBCUw=",
16 | "dev": true
17 | },
18 | "balanced-match": {
19 | "version": "1.0.0",
20 | "resolved": "https://registry.npmjs.org/balanced-match/-/balanced-match-1.0.0.tgz",
21 | "integrity": "sha1-ibTRmasr7kneFk6gK4nORi1xt2c=",
22 | "dev": true
23 | },
24 | "brace-expansion": {
25 | "version": "1.1.8",
26 | "resolved": "https://registry.npmjs.org/brace-expansion/-/brace-expansion-1.1.8.tgz",
27 | "integrity": "sha1-wHshHHyVLsH479Uad+8NHTmQopI=",
28 | "dev": true,
29 | "requires": {
30 | "balanced-match": "^1.0.0",
31 | "concat-map": "0.0.1"
32 | }
33 | },
34 | "browser-stdout": {
35 | "version": "1.3.0",
36 | "resolved": "https://registry.npmjs.org/browser-stdout/-/browser-stdout-1.3.0.tgz",
37 | "integrity": "sha1-81HTKWnTL6XXpVZxVCY9korjvR8=",
38 | "dev": true
39 | },
40 | "chai": {
41 | "version": "4.1.2",
42 | "resolved": "https://registry.npmjs.org/chai/-/chai-4.1.2.tgz",
43 | "integrity": "sha1-D2RYS6ZC8PKs4oBiefTwbKI61zw=",
44 | "dev": true,
45 | "requires": {
46 | "assertion-error": "^1.0.1",
47 | "check-error": "^1.0.1",
48 | "deep-eql": "^3.0.0",
49 | "get-func-name": "^2.0.0",
50 | "pathval": "^1.0.0",
51 | "type-detect": "^4.0.0"
52 | }
53 | },
54 | "check-error": {
55 | "version": "1.0.2",
56 | "resolved": "https://registry.npmjs.org/check-error/-/check-error-1.0.2.tgz",
57 | "integrity": "sha1-V00xLt2Iu13YkS6Sht1sCu1KrII=",
58 | "dev": true
59 | },
60 | "clone": {
61 | "version": "2.1.1",
62 | "resolved": "https://registry.npmjs.org/clone/-/clone-2.1.1.tgz",
63 | "integrity": "sha1-0hfR6WERjjrJpLi7oyhVU79kfNs="
64 | },
65 | "clone-buffer": {
66 | "version": "1.0.0",
67 | "resolved": "https://registry.npmjs.org/clone-buffer/-/clone-buffer-1.0.0.tgz",
68 | "integrity": "sha1-4+JbIHrE5wGvch4staFnksrD3Fg="
69 | },
70 | "clone-stats": {
71 | "version": "1.0.0",
72 | "resolved": "https://registry.npmjs.org/clone-stats/-/clone-stats-1.0.0.tgz",
73 | "integrity": "sha1-s3gt/4u1R04Yuba/D9/ngvh3doA="
74 | },
75 | "cloneable-readable": {
76 | "version": "1.0.0",
77 | "resolved": "https://registry.npmjs.org/cloneable-readable/-/cloneable-readable-1.0.0.tgz",
78 | "integrity": "sha1-pikNQT8hemEjL5XkWP84QYz7ARc=",
79 | "requires": {
80 | "inherits": "^2.0.1",
81 | "process-nextick-args": "^1.0.6",
82 | "through2": "^2.0.1"
83 | },
84 | "dependencies": {
85 | "inherits": {
86 | "version": "2.0.3",
87 | "resolved": "https://registry.npmjs.org/inherits/-/inherits-2.0.3.tgz",
88 | "integrity": "sha1-Yzwsg+PaQqUC9SRmAiSA9CCCYd4="
89 | }
90 | }
91 | },
92 | "commander": {
93 | "version": "2.9.0",
94 | "resolved": "https://registry.npmjs.org/commander/-/commander-2.9.0.tgz",
95 | "integrity": "sha1-nJkJQXbhIkDLItbFFGCYQA/g99Q=",
96 | "dev": true,
97 | "requires": {
98 | "graceful-readlink": ">= 1.0.0"
99 | }
100 | },
101 | "concat-map": {
102 | "version": "0.0.1",
103 | "resolved": "https://registry.npmjs.org/concat-map/-/concat-map-0.0.1.tgz",
104 | "integrity": "sha1-2Klr13/Wjfd5OnMDajug1UBdR3s=",
105 | "dev": true
106 | },
107 | "core-util-is": {
108 | "version": "1.0.2",
109 | "resolved": "https://registry.npmjs.org/core-util-is/-/core-util-is-1.0.2.tgz",
110 | "integrity": "sha1-tf1UIgqivFq1eqtxQMlAdUUDwac="
111 | },
112 | "debug": {
113 | "version": "2.6.8",
114 | "resolved": "https://registry.npmjs.org/debug/-/debug-2.6.8.tgz",
115 | "integrity": "sha1-5zFTHKLt4n0YgiJCfaF4IdaP9Pw=",
116 | "dev": true,
117 | "requires": {
118 | "ms": "2.0.0"
119 | }
120 | },
121 | "deep-eql": {
122 | "version": "3.0.1",
123 | "resolved": "https://registry.npmjs.org/deep-eql/-/deep-eql-3.0.1.tgz",
124 | "integrity": "sha512-+QeIQyN5ZuO+3Uk5DYh6/1eKO0m0YmJFGNmFHGACpf1ClL1nmlV/p4gNgbl2pJGxgXb4faqo6UE+M5ACEMyVcw==",
125 | "dev": true,
126 | "requires": {
127 | "type-detect": "^4.0.0"
128 | }
129 | },
130 | "diff": {
131 | "version": "3.2.0",
132 | "resolved": "https://registry.npmjs.org/diff/-/diff-3.2.0.tgz",
133 | "integrity": "sha1-yc45Okt8vQsFinJck98pkCeGj/k=",
134 | "dev": true
135 | },
136 | "escape-string-regexp": {
137 | "version": "1.0.5",
138 | "resolved": "https://registry.npmjs.org/escape-string-regexp/-/escape-string-regexp-1.0.5.tgz",
139 | "integrity": "sha1-G2HAViGQqN/2rjuyzwIAyhMLhtQ=",
140 | "dev": true
141 | },
142 | "fs.realpath": {
143 | "version": "1.0.0",
144 | "resolved": "https://registry.npmjs.org/fs.realpath/-/fs.realpath-1.0.0.tgz",
145 | "integrity": "sha1-FQStJSMVjKpA20onh8sBQRmU6k8=",
146 | "dev": true
147 | },
148 | "get-func-name": {
149 | "version": "2.0.0",
150 | "resolved": "https://registry.npmjs.org/get-func-name/-/get-func-name-2.0.0.tgz",
151 | "integrity": "sha1-6td0q+5y4gQJQzoGY2YCPdaIekE=",
152 | "dev": true
153 | },
154 | "glob": {
155 | "version": "7.1.1",
156 | "resolved": "https://registry.npmjs.org/glob/-/glob-7.1.1.tgz",
157 | "integrity": "sha1-gFIR3wT6rxxjo2ADBs31reULLsg=",
158 | "dev": true,
159 | "requires": {
160 | "fs.realpath": "^1.0.0",
161 | "inflight": "^1.0.4",
162 | "inherits": "2",
163 | "minimatch": "^3.0.2",
164 | "once": "^1.3.0",
165 | "path-is-absolute": "^1.0.0"
166 | }
167 | },
168 | "graceful-readlink": {
169 | "version": "1.0.1",
170 | "resolved": "https://registry.npmjs.org/graceful-readlink/-/graceful-readlink-1.0.1.tgz",
171 | "integrity": "sha1-TK+tdrxi8C+gObL5Tpo906ORpyU=",
172 | "dev": true
173 | },
174 | "growl": {
175 | "version": "1.9.2",
176 | "resolved": "https://registry.npmjs.org/growl/-/growl-1.9.2.tgz",
177 | "integrity": "sha1-Dqd0NxXbjY3ixe3hd14bRayFwC8=",
178 | "dev": true
179 | },
180 | "has-flag": {
181 | "version": "1.0.0",
182 | "resolved": "https://registry.npmjs.org/has-flag/-/has-flag-1.0.0.tgz",
183 | "integrity": "sha1-nZ55MWXOAXoA8AQYxD+UKnsdEfo=",
184 | "dev": true
185 | },
186 | "he": {
187 | "version": "1.1.1",
188 | "resolved": "https://registry.npmjs.org/he/-/he-1.1.1.tgz",
189 | "integrity": "sha1-k0EP0hsAlzUVH4howvJx80J+I/0=",
190 | "dev": true
191 | },
192 | "inflight": {
193 | "version": "1.0.6",
194 | "resolved": "https://registry.npmjs.org/inflight/-/inflight-1.0.6.tgz",
195 | "integrity": "sha1-Sb1jMdfQLQwJvJEKEHW6gWW1bfk=",
196 | "dev": true,
197 | "requires": {
198 | "once": "^1.3.0",
199 | "wrappy": "1"
200 | }
201 | },
202 | "inherits": {
203 | "version": "2.0.3",
204 | "integrity": "sha1-Yzwsg+PaQqUC9SRmAiSA9CCCYd4=",
205 | "dev": true
206 | },
207 | "isarray": {
208 | "version": "1.0.0",
209 | "resolved": "https://registry.npmjs.org/isarray/-/isarray-1.0.0.tgz",
210 | "integrity": "sha1-u5NdSFgsuhaMBoNJV6VKPgcSTxE="
211 | },
212 | "json3": {
213 | "version": "3.3.2",
214 | "resolved": "https://registry.npmjs.org/json3/-/json3-3.3.2.tgz",
215 | "integrity": "sha1-PAQ0dD35Pi9cQq7nsZvLSDV19OE=",
216 | "dev": true
217 | },
218 | "lodash._baseassign": {
219 | "version": "3.2.0",
220 | "resolved": "https://registry.npmjs.org/lodash._baseassign/-/lodash._baseassign-3.2.0.tgz",
221 | "integrity": "sha1-jDigmVAPIVrQnlnxci/QxSv+Ck4=",
222 | "dev": true,
223 | "requires": {
224 | "lodash._basecopy": "^3.0.0",
225 | "lodash.keys": "^3.0.0"
226 | }
227 | },
228 | "lodash._basecopy": {
229 | "version": "3.0.1",
230 | "resolved": "https://registry.npmjs.org/lodash._basecopy/-/lodash._basecopy-3.0.1.tgz",
231 | "integrity": "sha1-jaDmqHbPNEwK2KVIghEd08XHyjY=",
232 | "dev": true
233 | },
234 | "lodash._basecreate": {
235 | "version": "3.0.3",
236 | "resolved": "https://registry.npmjs.org/lodash._basecreate/-/lodash._basecreate-3.0.3.tgz",
237 | "integrity": "sha1-G8ZhYU2qf8MRt9A78WgGoCE8+CE=",
238 | "dev": true
239 | },
240 | "lodash._getnative": {
241 | "version": "3.9.1",
242 | "resolved": "https://registry.npmjs.org/lodash._getnative/-/lodash._getnative-3.9.1.tgz",
243 | "integrity": "sha1-VwvH3t5G1hzc3mh9ZdPuy6o6r/U=",
244 | "dev": true
245 | },
246 | "lodash._isiterateecall": {
247 | "version": "3.0.9",
248 | "resolved": "https://registry.npmjs.org/lodash._isiterateecall/-/lodash._isiterateecall-3.0.9.tgz",
249 | "integrity": "sha1-UgOte6Ql+uhCRg5pbbnPPmqsBXw=",
250 | "dev": true
251 | },
252 | "lodash.create": {
253 | "version": "3.1.1",
254 | "resolved": "https://registry.npmjs.org/lodash.create/-/lodash.create-3.1.1.tgz",
255 | "integrity": "sha1-1/KEnw29p+BGgruM1yqwIkYd6+c=",
256 | "dev": true,
257 | "requires": {
258 | "lodash._baseassign": "^3.0.0",
259 | "lodash._basecreate": "^3.0.0",
260 | "lodash._isiterateecall": "^3.0.0"
261 | }
262 | },
263 | "lodash.isarguments": {
264 | "version": "3.1.0",
265 | "resolved": "https://registry.npmjs.org/lodash.isarguments/-/lodash.isarguments-3.1.0.tgz",
266 | "integrity": "sha1-L1c9hcaiQon/AGY7SRwdM4/zRYo=",
267 | "dev": true
268 | },
269 | "lodash.isarray": {
270 | "version": "3.0.4",
271 | "resolved": "https://registry.npmjs.org/lodash.isarray/-/lodash.isarray-3.0.4.tgz",
272 | "integrity": "sha1-eeTriMNqgSKvhvhEqpvNhRtfu1U=",
273 | "dev": true
274 | },
275 | "lodash.keys": {
276 | "version": "3.1.2",
277 | "resolved": "https://registry.npmjs.org/lodash.keys/-/lodash.keys-3.1.2.tgz",
278 | "integrity": "sha1-TbwEcrFWvlCgsoaFXRvQsMZWCYo=",
279 | "dev": true,
280 | "requires": {
281 | "lodash._getnative": "^3.0.0",
282 | "lodash.isarguments": "^3.0.0",
283 | "lodash.isarray": "^3.0.0"
284 | }
285 | },
286 | "minimatch": {
287 | "version": "3.0.4",
288 | "resolved": "https://registry.npmjs.org/minimatch/-/minimatch-3.0.4.tgz",
289 | "integrity": "sha512-yJHVQEhyqPLUTgt9B83PXu6W3rx4MvvHvSUvToogpwoGDOUQ+yDrR0HRot+yOCdCO7u4hX3pWft6kWBBcqh0UA==",
290 | "dev": true,
291 | "requires": {
292 | "brace-expansion": "^1.1.7"
293 | }
294 | },
295 | "minimist": {
296 | "version": "1.2.0",
297 | "resolved": "https://registry.npmjs.org/minimist/-/minimist-1.2.0.tgz",
298 | "integrity": "sha1-o1AIsg9BOD7sH7kU9M1d95omQoQ="
299 | },
300 | "mkdirp": {
301 | "version": "0.5.1",
302 | "resolved": "https://registry.npmjs.org/mkdirp/-/mkdirp-0.5.1.tgz",
303 | "integrity": "sha1-MAV0OOrGz3+MR2fzhkjWaX11yQM=",
304 | "dev": true,
305 | "requires": {
306 | "minimist": "0.0.8"
307 | },
308 | "dependencies": {
309 | "minimist": {
310 | "version": "0.0.8",
311 | "resolved": "https://registry.npmjs.org/minimist/-/minimist-0.0.8.tgz",
312 | "integrity": "sha1-hX/Kv8M5fSYluCKCYuhqp6ARsF0=",
313 | "dev": true
314 | }
315 | }
316 | },
317 | "mocha": {
318 | "version": "3.5.3",
319 | "resolved": "https://registry.npmjs.org/mocha/-/mocha-3.5.3.tgz",
320 | "integrity": "sha512-/6na001MJWEtYxHOV1WLfsmR4YIynkUEhBwzsb+fk2qmQ3iqsi258l/Q2MWHJMImAcNpZ8DEdYAK72NHoIQ9Eg==",
321 | "dev": true,
322 | "requires": {
323 | "browser-stdout": "1.3.0",
324 | "commander": "2.9.0",
325 | "debug": "2.6.8",
326 | "diff": "3.2.0",
327 | "escape-string-regexp": "1.0.5",
328 | "glob": "7.1.1",
329 | "growl": "1.9.2",
330 | "he": "1.1.1",
331 | "json3": "3.3.2",
332 | "lodash.create": "3.1.1",
333 | "mkdirp": "0.5.1",
334 | "supports-color": "3.1.2"
335 | }
336 | },
337 | "ms": {
338 | "version": "2.0.0",
339 | "resolved": "https://registry.npmjs.org/ms/-/ms-2.0.0.tgz",
340 | "integrity": "sha1-VgiurfwAvmwpAd9fmGF4jeDVl8g=",
341 | "dev": true
342 | },
343 | "ncp": {
344 | "version": "2.0.0",
345 | "resolved": "https://registry.npmjs.org/ncp/-/ncp-2.0.0.tgz",
346 | "integrity": "sha1-GVoh1sRuNh0vsSgbo4uR6d9727M=",
347 | "dev": true
348 | },
349 | "once": {
350 | "version": "1.4.0",
351 | "resolved": "https://registry.npmjs.org/once/-/once-1.4.0.tgz",
352 | "integrity": "sha1-WDsap3WWHUsROsF9nFC6753Xa9E=",
353 | "dev": true,
354 | "requires": {
355 | "wrappy": "1"
356 | }
357 | },
358 | "path-is-absolute": {
359 | "version": "1.0.1",
360 | "resolved": "https://registry.npmjs.org/path-is-absolute/-/path-is-absolute-1.0.1.tgz",
361 | "integrity": "sha1-F0uSaHNVNP+8es5r9TpanhtcX18=",
362 | "dev": true
363 | },
364 | "pathval": {
365 | "version": "1.1.0",
366 | "resolved": "https://registry.npmjs.org/pathval/-/pathval-1.1.0.tgz",
367 | "integrity": "sha1-uULm1L3mUwBe9rcTYd74cn0GReA=",
368 | "dev": true
369 | },
370 | "process-nextick-args": {
371 | "version": "1.0.7",
372 | "resolved": "https://registry.npmjs.org/process-nextick-args/-/process-nextick-args-1.0.7.tgz",
373 | "integrity": "sha1-FQ4gt1ZZCtP5EJPyWk8q2L/zC6M="
374 | },
375 | "readable-stream": {
376 | "version": "2.3.3",
377 | "resolved": "https://registry.npmjs.org/readable-stream/-/readable-stream-2.3.3.tgz",
378 | "integrity": "sha512-m+qzzcn7KUxEmd1gMbchF+Y2eIUbieUaxkWtptyHywrX0rE8QEYqPC07Vuy4Wm32/xE16NcdBctb8S0Xe/5IeQ==",
379 | "requires": {
380 | "core-util-is": "~1.0.0",
381 | "inherits": "~2.0.3",
382 | "isarray": "~1.0.0",
383 | "process-nextick-args": "~1.0.6",
384 | "safe-buffer": "~5.1.1",
385 | "string_decoder": "~1.0.3",
386 | "util-deprecate": "~1.0.1"
387 | },
388 | "dependencies": {
389 | "inherits": {
390 | "version": "2.0.3",
391 | "resolved": "https://registry.npmjs.org/inherits/-/inherits-2.0.3.tgz",
392 | "integrity": "sha1-Yzwsg+PaQqUC9SRmAiSA9CCCYd4="
393 | }
394 | }
395 | },
396 | "remove-trailing-separator": {
397 | "version": "1.1.0",
398 | "resolved": "https://registry.npmjs.org/remove-trailing-separator/-/remove-trailing-separator-1.1.0.tgz",
399 | "integrity": "sha1-wkvOKig62tW8P1jg1IJJuSN52O8="
400 | },
401 | "replace-ext": {
402 | "version": "1.0.0",
403 | "resolved": "https://registry.npmjs.org/replace-ext/-/replace-ext-1.0.0.tgz",
404 | "integrity": "sha1-3mMSg3P8v3w8z6TeWkgMRaZ5WOs="
405 | },
406 | "safe-buffer": {
407 | "version": "5.1.1",
408 | "resolved": "https://registry.npmjs.org/safe-buffer/-/safe-buffer-5.1.1.tgz",
409 | "integrity": "sha512-kKvNJn6Mm93gAczWVJg7wH+wGYWNrDHdWvpUmHyEsgCtIwwo3bqPtV4tR5tuPaUhTOo/kvhVwd8XwwOllGYkbg=="
410 | },
411 | "source-list-map": {
412 | "version": "0.1.8",
413 | "resolved": "https://registry.npmjs.org/source-list-map/-/source-list-map-0.1.8.tgz",
414 | "integrity": "sha1-xVCyq1Qn9rPyH1r+rYjE9Vh7IQY="
415 | },
416 | "source-map": {
417 | "version": "0.4.4",
418 | "resolved": "https://registry.npmjs.org/source-map/-/source-map-0.4.4.tgz",
419 | "integrity": "sha1-66T12pwNyZneaAMti092FzZSA2s=",
420 | "requires": {
421 | "amdefine": ">=0.0.4"
422 | }
423 | },
424 | "string_decoder": {
425 | "version": "1.0.3",
426 | "resolved": "https://registry.npmjs.org/string_decoder/-/string_decoder-1.0.3.tgz",
427 | "integrity": "sha512-4AH6Z5fzNNBcH+6XDMfA/BTt87skxqJlO0lAh3Dker5zThcAxG6mKz+iGu308UKoPPQ8Dcqx/4JhujzltRa+hQ==",
428 | "requires": {
429 | "safe-buffer": "~5.1.0"
430 | }
431 | },
432 | "supports-color": {
433 | "version": "3.1.2",
434 | "resolved": "https://registry.npmjs.org/supports-color/-/supports-color-3.1.2.tgz",
435 | "integrity": "sha1-cqJiiU2dQIuVbKBf83su2KbiotU=",
436 | "dev": true,
437 | "requires": {
438 | "has-flag": "^1.0.0"
439 | }
440 | },
441 | "through2": {
442 | "version": "2.0.3",
443 | "resolved": "https://registry.npmjs.org/through2/-/through2-2.0.3.tgz",
444 | "integrity": "sha1-AARWmzfHx0ujnEPzzteNGtlBQL4=",
445 | "requires": {
446 | "readable-stream": "^2.1.5",
447 | "xtend": "~4.0.1"
448 | }
449 | },
450 | "type-detect": {
451 | "version": "4.0.3",
452 | "resolved": "https://registry.npmjs.org/type-detect/-/type-detect-4.0.3.tgz",
453 | "integrity": "sha1-Dj8mcLRAmbC0bChNE2p+9Jx0wuo=",
454 | "dev": true
455 | },
456 | "util-deprecate": {
457 | "version": "1.0.2",
458 | "resolved": "https://registry.npmjs.org/util-deprecate/-/util-deprecate-1.0.2.tgz",
459 | "integrity": "sha1-RQ1Nyfpw3nMnYvvS1KKJgUGaDM8="
460 | },
461 | "vinyl": {
462 | "version": "2.1.0",
463 | "resolved": "https://registry.npmjs.org/vinyl/-/vinyl-2.1.0.tgz",
464 | "integrity": "sha1-Ah+cLPlR1rk5lDyJ617lrdT9kkw=",
465 | "requires": {
466 | "clone": "^2.1.1",
467 | "clone-buffer": "^1.0.0",
468 | "clone-stats": "^1.0.0",
469 | "cloneable-readable": "^1.0.0",
470 | "remove-trailing-separator": "^1.0.1",
471 | "replace-ext": "^1.0.0"
472 | }
473 | },
474 | "webpack-core": {
475 | "version": "0.6.9",
476 | "resolved": "https://registry.npmjs.org/webpack-core/-/webpack-core-0.6.9.tgz",
477 | "integrity": "sha1-/FcViMhVjad76e+23r3Fo7FyvcI=",
478 | "requires": {
479 | "source-list-map": "~0.1.7",
480 | "source-map": "~0.4.1"
481 | }
482 | },
483 | "wrappy": {
484 | "version": "1.0.2",
485 | "resolved": "https://registry.npmjs.org/wrappy/-/wrappy-1.0.2.tgz",
486 | "integrity": "sha1-tSQ9jz7BqjXxNkYFvA0QNuMKtp8=",
487 | "dev": true
488 | },
489 | "xtend": {
490 | "version": "4.0.1",
491 | "resolved": "https://registry.npmjs.org/xtend/-/xtend-4.0.1.tgz",
492 | "integrity": "sha1-pcbVMr5lbiPbgg77lDofBJmNY68="
493 | }
494 | }
495 | }
496 |
--------------------------------------------------------------------------------
/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "google-closure-compiler-js",
3 | "version": "20180610.0.1",
4 | "description": "Check, compile, transpile, optimize and compress JavaScript with Closure Compiler in JS",
5 | "main": "index.js",
6 | "bin": {
7 | "google-closure-compiler-js": "cmd.js"
8 | },
9 | "repository": {
10 | "type": "git",
11 | "url": "git+https://github.com/google/closure-compiler-js.git"
12 | },
13 | "keywords": [
14 | "javascript",
15 | "compiler",
16 | "optimizer",
17 | "minifier",
18 | "closure"
19 | ],
20 | "author": "The Closure Compiler Authors",
21 | "license": "Apache-2.0",
22 | "bugs": {
23 | "url": "https://github.com/google/closure-compiler/issues"
24 | },
25 | "homepage": "https://developers.google.com/closure/compiler/",
26 | "devDependencies": {
27 | "chai": "^4.1.2",
28 | "mocha": "^3.5.3",
29 | "ncp": "^2.0.0"
30 | },
31 | "dependencies": {
32 | "minimist": "^1.2.0",
33 | "vinyl": "^2.0.1",
34 | "webpack-core": "^0.6.8"
35 | },
36 | "scripts": {
37 | "test": "mocha",
38 | "pretest": "./build_compiler.js"
39 | }
40 | }
41 |
--------------------------------------------------------------------------------
/samples/.gitignore:
--------------------------------------------------------------------------------
1 | dist/
--------------------------------------------------------------------------------
/samples/README.md:
--------------------------------------------------------------------------------
1 | This folder contains a toy project that compiles with the Closure Compiler in JS.
2 |
3 | You'll need `gulp`.
4 | If you don't have it, run `npm install -g gulp`.
5 | Then, check out this repo, install the dependencies, and run the Gulp tool-
6 |
7 | ```bash
8 | $ git clone https://github.com/google/closure-compiler-js.git
9 | $ cd closure-compiler-js/samples
10 | $ npm install
11 | $ gulp
12 | ```
13 |
14 | This will generate an output file and source map inside `dist`.
15 | You can run the `output.min.js` file with Node, or inside a browser.
--------------------------------------------------------------------------------
/samples/gulpfile.js:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2016 The Closure Compiler Authors.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | /**
18 | * @fileoverview Gulpfile to compile with Closure Compiler in JS.
19 | */
20 |
21 | const compiler = require('google-closure-compiler-js').gulp();
22 | const gulp = require('gulp');
23 | const sourcemaps = require('gulp-sourcemaps');
24 |
25 | gulp.task('default', function() {
26 | return gulp.src(['src/helper.js', 'src/index.js'])
27 | .pipe(sourcemaps.init())
28 | .pipe(compiler({
29 | jsOutputFile: 'output.min.js', // filename returned to gulp
30 | compilationLevel: 'ADVANCED', // as opposed to 'SIMPLE', the default
31 | warningLevel: 'VERBOSE', // complain loudly on errors
32 | createSourceMap: true, // create output source map
33 | processCommonJsModules: true, // needed to support require()
34 | }))
35 | .pipe(sourcemaps.write('/'))
36 | .pipe(gulp.dest('./dist'));
37 | });
38 |
--------------------------------------------------------------------------------
/samples/package-lock.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "google-closure-compiler-js_samples",
3 | "version": "1.0.0",
4 | "lockfileVersion": 1,
5 | "requires": true,
6 | "dependencies": {
7 | "@gulp-sourcemaps/map-sources": {
8 | "version": "1.0.0",
9 | "resolved": "https://registry.npmjs.org/@gulp-sourcemaps/map-sources/-/map-sources-1.0.0.tgz",
10 | "integrity": "sha1-iQrnxdjId/bThIYCFazp1+yUW9o=",
11 | "requires": {
12 | "normalize-path": "2.1.1",
13 | "through2": "2.0.3"
14 | }
15 | },
16 | "acorn": {
17 | "version": "4.0.13",
18 | "resolved": "https://registry.npmjs.org/acorn/-/acorn-4.0.13.tgz",
19 | "integrity": "sha1-EFSVrlNh1pe9GVyCUZLhrX8lN4c="
20 | },
21 | "amdefine": {
22 | "version": "1.0.1",
23 | "resolved": "https://registry.npmjs.org/amdefine/-/amdefine-1.0.1.tgz",
24 | "integrity": "sha1-SlKCrBZHKek2Gbz9OtFR+BfOkfU="
25 | },
26 | "atob": {
27 | "version": "1.1.3",
28 | "resolved": "https://registry.npmjs.org/atob/-/atob-1.1.3.tgz",
29 | "integrity": "sha1-lfE2KbEsOlGl0hWr3OKqnzL4B3M="
30 | },
31 | "clone": {
32 | "version": "2.1.1",
33 | "resolved": "https://registry.npmjs.org/clone/-/clone-2.1.1.tgz",
34 | "integrity": "sha1-0hfR6WERjjrJpLi7oyhVU79kfNs="
35 | },
36 | "clone-buffer": {
37 | "version": "1.0.0",
38 | "resolved": "https://registry.npmjs.org/clone-buffer/-/clone-buffer-1.0.0.tgz",
39 | "integrity": "sha1-4+JbIHrE5wGvch4staFnksrD3Fg="
40 | },
41 | "clone-stats": {
42 | "version": "1.0.0",
43 | "resolved": "https://registry.npmjs.org/clone-stats/-/clone-stats-1.0.0.tgz",
44 | "integrity": "sha1-s3gt/4u1R04Yuba/D9/ngvh3doA="
45 | },
46 | "cloneable-readable": {
47 | "version": "1.0.0",
48 | "resolved": "https://registry.npmjs.org/cloneable-readable/-/cloneable-readable-1.0.0.tgz",
49 | "integrity": "sha1-pikNQT8hemEjL5XkWP84QYz7ARc=",
50 | "requires": {
51 | "inherits": "2.0.3",
52 | "process-nextick-args": "1.0.7",
53 | "through2": "2.0.3"
54 | }
55 | },
56 | "convert-source-map": {
57 | "version": "1.5.0",
58 | "resolved": "https://registry.npmjs.org/convert-source-map/-/convert-source-map-1.5.0.tgz",
59 | "integrity": "sha1-ms1whRxtXf3ZPZKC5e35SgP/RrU="
60 | },
61 | "core-util-is": {
62 | "version": "1.0.2",
63 | "resolved": "https://registry.npmjs.org/core-util-is/-/core-util-is-1.0.2.tgz",
64 | "integrity": "sha1-tf1UIgqivFq1eqtxQMlAdUUDwac="
65 | },
66 | "css": {
67 | "version": "2.2.1",
68 | "resolved": "https://registry.npmjs.org/css/-/css-2.2.1.tgz",
69 | "integrity": "sha1-c6TIHehdtmTU7mdPfUcIXjstVdw=",
70 | "requires": {
71 | "inherits": "2.0.3",
72 | "source-map": "0.1.43",
73 | "source-map-resolve": "0.3.1",
74 | "urix": "0.1.0"
75 | },
76 | "dependencies": {
77 | "source-map": {
78 | "version": "0.1.43",
79 | "resolved": "https://registry.npmjs.org/source-map/-/source-map-0.1.43.tgz",
80 | "integrity": "sha1-wkvBRspRfBRx9drL4lcbK3+eM0Y=",
81 | "requires": {
82 | "amdefine": "1.0.1"
83 | }
84 | }
85 | }
86 | },
87 | "debug": {
88 | "version": "2.6.9",
89 | "resolved": "https://registry.npmjs.org/debug/-/debug-2.6.9.tgz",
90 | "integrity": "sha512-bC7ElrdJaJnPbAP+1EotYvqZsb3ecl5wi6Bfi6BJTUcNowp6cvspg0jXznRTKDjm/E7AdgFBVeAPVMNcKGsHMA==",
91 | "requires": {
92 | "ms": "2.0.0"
93 | }
94 | },
95 | "debug-fabulous": {
96 | "version": "0.0.4",
97 | "resolved": "https://registry.npmjs.org/debug-fabulous/-/debug-fabulous-0.0.4.tgz",
98 | "integrity": "sha1-+gccXYdIRoVCSAdCHKSxawsaB2M=",
99 | "requires": {
100 | "debug": "2.6.9",
101 | "lazy-debug-legacy": "0.0.1",
102 | "object-assign": "4.1.0"
103 | }
104 | },
105 | "detect-newline": {
106 | "version": "2.1.0",
107 | "resolved": "https://registry.npmjs.org/detect-newline/-/detect-newline-2.1.0.tgz",
108 | "integrity": "sha1-9B8cEL5LAOh7XxPaaAdZ8sW/0+I="
109 | },
110 | "google-closure-compiler-js": {
111 | "version": "20170910.0.1",
112 | "resolved": "https://registry.npmjs.org/google-closure-compiler-js/-/google-closure-compiler-js-20170910.0.1.tgz",
113 | "integrity": "sha512-Vric7QFWxzHFxITZ10bmlG1H/5rhODb7hJuWyKWMD8GflpQzRmbMVqkFp3fKvN+U9tPwZItGVhkiOR+84PX3ew==",
114 | "requires": {
115 | "minimist": "1.2.0",
116 | "vinyl": "2.1.0",
117 | "webpack-core": "0.6.9"
118 | }
119 | },
120 | "graceful-fs": {
121 | "version": "4.1.11",
122 | "resolved": "https://registry.npmjs.org/graceful-fs/-/graceful-fs-4.1.11.tgz",
123 | "integrity": "sha1-Dovf5NHduIVNZOBOp8AOKgJuVlg="
124 | },
125 | "gulp-sourcemaps": {
126 | "version": "1.12.0",
127 | "resolved": "https://registry.npmjs.org/gulp-sourcemaps/-/gulp-sourcemaps-1.12.0.tgz",
128 | "integrity": "sha1-eG+XyUoPloSSRl1wVY4EJCxnlZg=",
129 | "requires": {
130 | "@gulp-sourcemaps/map-sources": "1.0.0",
131 | "acorn": "4.0.13",
132 | "convert-source-map": "1.5.0",
133 | "css": "2.2.1",
134 | "debug-fabulous": "0.0.4",
135 | "detect-newline": "2.1.0",
136 | "graceful-fs": "4.1.11",
137 | "source-map": "0.4.4",
138 | "strip-bom": "2.0.0",
139 | "through2": "2.0.3",
140 | "vinyl": "1.2.0"
141 | },
142 | "dependencies": {
143 | "clone": {
144 | "version": "1.0.2",
145 | "resolved": "https://registry.npmjs.org/clone/-/clone-1.0.2.tgz",
146 | "integrity": "sha1-Jgt6meux7f4kdTgXX3gyQ8sZ0Uk="
147 | },
148 | "clone-stats": {
149 | "version": "0.0.1",
150 | "resolved": "https://registry.npmjs.org/clone-stats/-/clone-stats-0.0.1.tgz",
151 | "integrity": "sha1-uI+UqCzzi4eR1YBG6kAprYjKmdE="
152 | },
153 | "replace-ext": {
154 | "version": "0.0.1",
155 | "resolved": "https://registry.npmjs.org/replace-ext/-/replace-ext-0.0.1.tgz",
156 | "integrity": "sha1-KbvZIHinOfC8zitO5B6DeVNSKSQ="
157 | },
158 | "vinyl": {
159 | "version": "1.2.0",
160 | "resolved": "https://registry.npmjs.org/vinyl/-/vinyl-1.2.0.tgz",
161 | "integrity": "sha1-XIgDbPVl5d8FVYv8kR+GVt8hiIQ=",
162 | "requires": {
163 | "clone": "1.0.2",
164 | "clone-stats": "0.0.1",
165 | "replace-ext": "0.0.1"
166 | }
167 | }
168 | }
169 | },
170 | "inherits": {
171 | "version": "2.0.3",
172 | "resolved": "https://registry.npmjs.org/inherits/-/inherits-2.0.3.tgz",
173 | "integrity": "sha1-Yzwsg+PaQqUC9SRmAiSA9CCCYd4="
174 | },
175 | "is-utf8": {
176 | "version": "0.2.1",
177 | "resolved": "https://registry.npmjs.org/is-utf8/-/is-utf8-0.2.1.tgz",
178 | "integrity": "sha1-Sw2hRCEE0bM2NA6AeX6GXPOffXI="
179 | },
180 | "isarray": {
181 | "version": "1.0.0",
182 | "resolved": "https://registry.npmjs.org/isarray/-/isarray-1.0.0.tgz",
183 | "integrity": "sha1-u5NdSFgsuhaMBoNJV6VKPgcSTxE="
184 | },
185 | "lazy-debug-legacy": {
186 | "version": "0.0.1",
187 | "resolved": "https://registry.npmjs.org/lazy-debug-legacy/-/lazy-debug-legacy-0.0.1.tgz",
188 | "integrity": "sha1-U3cWwHduTPeePtG2IfdljCkRsbE="
189 | },
190 | "minimist": {
191 | "version": "1.2.0",
192 | "resolved": "https://registry.npmjs.org/minimist/-/minimist-1.2.0.tgz",
193 | "integrity": "sha1-o1AIsg9BOD7sH7kU9M1d95omQoQ="
194 | },
195 | "ms": {
196 | "version": "2.0.0",
197 | "resolved": "https://registry.npmjs.org/ms/-/ms-2.0.0.tgz",
198 | "integrity": "sha1-VgiurfwAvmwpAd9fmGF4jeDVl8g="
199 | },
200 | "normalize-path": {
201 | "version": "2.1.1",
202 | "resolved": "https://registry.npmjs.org/normalize-path/-/normalize-path-2.1.1.tgz",
203 | "integrity": "sha1-GrKLVW4Zg2Oowab35vogE3/mrtk=",
204 | "requires": {
205 | "remove-trailing-separator": "1.1.0"
206 | }
207 | },
208 | "object-assign": {
209 | "version": "4.1.0",
210 | "resolved": "https://registry.npmjs.org/object-assign/-/object-assign-4.1.0.tgz",
211 | "integrity": "sha1-ejs9DpgGPUP0wD8uiubNUahog6A="
212 | },
213 | "process-nextick-args": {
214 | "version": "1.0.7",
215 | "resolved": "https://registry.npmjs.org/process-nextick-args/-/process-nextick-args-1.0.7.tgz",
216 | "integrity": "sha1-FQ4gt1ZZCtP5EJPyWk8q2L/zC6M="
217 | },
218 | "readable-stream": {
219 | "version": "2.3.3",
220 | "resolved": "https://registry.npmjs.org/readable-stream/-/readable-stream-2.3.3.tgz",
221 | "integrity": "sha512-m+qzzcn7KUxEmd1gMbchF+Y2eIUbieUaxkWtptyHywrX0rE8QEYqPC07Vuy4Wm32/xE16NcdBctb8S0Xe/5IeQ==",
222 | "requires": {
223 | "core-util-is": "1.0.2",
224 | "inherits": "2.0.3",
225 | "isarray": "1.0.0",
226 | "process-nextick-args": "1.0.7",
227 | "safe-buffer": "5.1.1",
228 | "string_decoder": "1.0.3",
229 | "util-deprecate": "1.0.2"
230 | }
231 | },
232 | "remove-trailing-separator": {
233 | "version": "1.1.0",
234 | "resolved": "https://registry.npmjs.org/remove-trailing-separator/-/remove-trailing-separator-1.1.0.tgz",
235 | "integrity": "sha1-wkvOKig62tW8P1jg1IJJuSN52O8="
236 | },
237 | "replace-ext": {
238 | "version": "1.0.0",
239 | "resolved": "https://registry.npmjs.org/replace-ext/-/replace-ext-1.0.0.tgz",
240 | "integrity": "sha1-3mMSg3P8v3w8z6TeWkgMRaZ5WOs="
241 | },
242 | "resolve-url": {
243 | "version": "0.2.1",
244 | "resolved": "https://registry.npmjs.org/resolve-url/-/resolve-url-0.2.1.tgz",
245 | "integrity": "sha1-LGN/53yJOv0qZj/iGqkIAGjiBSo="
246 | },
247 | "safe-buffer": {
248 | "version": "5.1.1",
249 | "resolved": "https://registry.npmjs.org/safe-buffer/-/safe-buffer-5.1.1.tgz",
250 | "integrity": "sha512-kKvNJn6Mm93gAczWVJg7wH+wGYWNrDHdWvpUmHyEsgCtIwwo3bqPtV4tR5tuPaUhTOo/kvhVwd8XwwOllGYkbg=="
251 | },
252 | "source-list-map": {
253 | "version": "0.1.8",
254 | "resolved": "https://registry.npmjs.org/source-list-map/-/source-list-map-0.1.8.tgz",
255 | "integrity": "sha1-xVCyq1Qn9rPyH1r+rYjE9Vh7IQY="
256 | },
257 | "source-map": {
258 | "version": "0.4.4",
259 | "resolved": "https://registry.npmjs.org/source-map/-/source-map-0.4.4.tgz",
260 | "integrity": "sha1-66T12pwNyZneaAMti092FzZSA2s=",
261 | "requires": {
262 | "amdefine": "1.0.1"
263 | }
264 | },
265 | "source-map-resolve": {
266 | "version": "0.3.1",
267 | "resolved": "https://registry.npmjs.org/source-map-resolve/-/source-map-resolve-0.3.1.tgz",
268 | "integrity": "sha1-YQ9hIqRFuN1RU1oqcbeD38Ekh2E=",
269 | "requires": {
270 | "atob": "1.1.3",
271 | "resolve-url": "0.2.1",
272 | "source-map-url": "0.3.0",
273 | "urix": "0.1.0"
274 | }
275 | },
276 | "source-map-url": {
277 | "version": "0.3.0",
278 | "resolved": "https://registry.npmjs.org/source-map-url/-/source-map-url-0.3.0.tgz",
279 | "integrity": "sha1-fsrxO1e80J2opAxdJp2zN5nUqvk="
280 | },
281 | "string_decoder": {
282 | "version": "1.0.3",
283 | "resolved": "https://registry.npmjs.org/string_decoder/-/string_decoder-1.0.3.tgz",
284 | "integrity": "sha512-4AH6Z5fzNNBcH+6XDMfA/BTt87skxqJlO0lAh3Dker5zThcAxG6mKz+iGu308UKoPPQ8Dcqx/4JhujzltRa+hQ==",
285 | "requires": {
286 | "safe-buffer": "5.1.1"
287 | }
288 | },
289 | "strip-bom": {
290 | "version": "2.0.0",
291 | "resolved": "https://registry.npmjs.org/strip-bom/-/strip-bom-2.0.0.tgz",
292 | "integrity": "sha1-YhmoVhZSBJHzV4i9vxRHqZx+aw4=",
293 | "requires": {
294 | "is-utf8": "0.2.1"
295 | }
296 | },
297 | "through2": {
298 | "version": "2.0.3",
299 | "resolved": "https://registry.npmjs.org/through2/-/through2-2.0.3.tgz",
300 | "integrity": "sha1-AARWmzfHx0ujnEPzzteNGtlBQL4=",
301 | "requires": {
302 | "readable-stream": "2.3.3",
303 | "xtend": "4.0.1"
304 | }
305 | },
306 | "urix": {
307 | "version": "0.1.0",
308 | "resolved": "https://registry.npmjs.org/urix/-/urix-0.1.0.tgz",
309 | "integrity": "sha1-2pN/emLiH+wf0Y1Js1wpNQZ6bHI="
310 | },
311 | "util-deprecate": {
312 | "version": "1.0.2",
313 | "resolved": "https://registry.npmjs.org/util-deprecate/-/util-deprecate-1.0.2.tgz",
314 | "integrity": "sha1-RQ1Nyfpw3nMnYvvS1KKJgUGaDM8="
315 | },
316 | "vinyl": {
317 | "version": "2.1.0",
318 | "resolved": "https://registry.npmjs.org/vinyl/-/vinyl-2.1.0.tgz",
319 | "integrity": "sha1-Ah+cLPlR1rk5lDyJ617lrdT9kkw=",
320 | "requires": {
321 | "clone": "2.1.1",
322 | "clone-buffer": "1.0.0",
323 | "clone-stats": "1.0.0",
324 | "cloneable-readable": "1.0.0",
325 | "remove-trailing-separator": "1.1.0",
326 | "replace-ext": "1.0.0"
327 | }
328 | },
329 | "webpack-core": {
330 | "version": "0.6.9",
331 | "resolved": "https://registry.npmjs.org/webpack-core/-/webpack-core-0.6.9.tgz",
332 | "integrity": "sha1-/FcViMhVjad76e+23r3Fo7FyvcI=",
333 | "requires": {
334 | "source-list-map": "0.1.8",
335 | "source-map": "0.4.4"
336 | }
337 | },
338 | "xtend": {
339 | "version": "4.0.1",
340 | "resolved": "https://registry.npmjs.org/xtend/-/xtend-4.0.1.tgz",
341 | "integrity": "sha1-pcbVMr5lbiPbgg77lDofBJmNY68="
342 | }
343 | }
344 | }
345 |
--------------------------------------------------------------------------------
/samples/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "google-closure-compiler-js_samples",
3 | "version": "1.0.0",
4 | "main": "index.js",
5 | "author": "The Closure Compiler Authors",
6 | "private": true,
7 | "license": "Apache-2.0",
8 | "dependencies": {
9 | "google-closure-compiler-js": "latest",
10 | "gulp-sourcemaps": "^1.6.0"
11 | }
12 | }
13 |
--------------------------------------------------------------------------------
/samples/src/helper.js:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2016 The Closure Compiler Authors.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | /**
18 | * @fileoverview Demo library for an application compiled with Closure.
19 | */
20 |
21 | let value = 0;
22 |
23 | module.exports = function() {
24 | return `I've been called ${++value} times`;
25 | };
26 |
--------------------------------------------------------------------------------
/samples/src/index.js:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2016 The Closure Compiler Authors.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | /**
18 | * @fileoverview Demo entry point for an application compiled with Closure.
19 | */
20 |
21 | 'use strict';
22 |
23 | const helperModule = require('./helper.js');
24 |
25 | let authors = 'The Closure Compiler Authors';
26 | console.info(`I'm a test module by ${authors}.`);
27 |
28 | if (typeof document !== 'undefined') {
29 | const h1 = document.createElement('h1');
30 | h1.textContent = 'Loud heading is loud';
31 | document.body.appendChild(h1);
32 | }
33 |
34 | console.warn('Output from helperModule: ' + helperModule());
35 | console.warn('Some more output from helperModule: ' + helperModule());
36 |
--------------------------------------------------------------------------------
/test/mocha.opts:
--------------------------------------------------------------------------------
1 | --ui tdd
2 | --timeout 30000
3 |
--------------------------------------------------------------------------------
/test/simple.js:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2017 The Closure Compiler Authors.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | const compile = require('../compile.js');
18 | const cmdCompile = require('../cmd.js');
19 | const assert = require('chai').assert;
20 |
21 | suite('closure', () => {
22 | function assertCompileOk(out, expected, opt_message) {
23 | assert.sameOrderedMembers(out.warnings, [], 'expected zero warnings');
24 | assert.sameOrderedMembers(out.errors, [], 'expected zero errors');
25 | assert.equal(out.compiledCode, expected, opt_message);
26 | }
27 |
28 | test('simple', () => {
29 | const flags = {
30 | jsCode: [{src: 'const x = 1 + 2;'}],
31 | warningLevel: 'VERBOSE',
32 | };
33 | const out = compile(flags);
34 | assertCompileOk(out, 'var x=3;')
35 | });
36 |
37 | test('advanced', () => {
38 | const flags = {
39 | jsCode: [{
40 | src: 'var x = 1;\nif (x)\nconsole.info(1);',
41 | path: 'foo.js',
42 | }],
43 | warningLevel: 'VERBOSE',
44 | };
45 |
46 | flags.compilationLevel = 'ADVANCED';
47 | const advanced = compile(flags);
48 |
49 | flags.compilationLevel = 'SIMPLE';
50 | const simple = compile(flags);
51 |
52 | assert.isBelow(advanced.compiledCode.length, simple.compiledCode.length,
53 | 'advanced code should be smaller');
54 | assertCompileOk(advanced, 'console.info(1);', 'advanced code was incorrect');
55 | assertCompileOk(simple, 'var x=1;console.info(1);', 'simple code was incorrect');
56 | });
57 |
58 | test('require()', () => {
59 | const flags = {
60 | jsCode: [{
61 | src: 'module.exports = () => { console.info(`Hello!`); };',
62 | path: 'src/hello.js',
63 | }, {
64 | src: '\'use strict\';\nconst x = require(\'./hello.js\');\nx();',
65 | path: 'src/index.js',
66 | }],
67 | processCommonJsModules: true,
68 | compilationLevel: 'ADVANCED',
69 | warningLevel: 'VERBOSE',
70 | };
71 | const out = compile(flags);
72 | assertCompileOk(out, 'console.info("Hello!");');
73 | });
74 |
75 | test('ES7 out', () => {
76 | const flags = {
77 | jsCode: [{
78 | src: 'console.log(`foo`)',
79 | path: 'foo.js',
80 | }],
81 | languageIn: 'ECMASCRIPT_2017',
82 | languageOut: 'ECMASCRIPT_2017',
83 | compilationLevel: 'ADVANCED',
84 | warningLevel: 'VERBOSE',
85 | };
86 | const out = compile(flags);
87 | assertCompileOk(out, '\'use strict\';console.log("foo");')
88 | });
89 |
90 | test('parse string defines on command line', () => {
91 | const flags = {
92 | jsCode: [{
93 | src: '/** @define {boolean} */ var foo = false; console.log(foo)',
94 | path: 'foo.js',
95 | }],
96 | compilationLevel: 'ADVANCED',
97 | warningLevel: 'VERBOSE',
98 | defines: 'foo=true'
99 | };
100 | const out = cmdCompile(flags);
101 | assertCompileOk(out, 'console.log(!0);')
102 | });
103 |
104 | test('parse array defines on command line', () => {
105 | const flags = {
106 | jsCode: [{
107 | src: '/** @define {boolean} */ var foo = false; console.log(foo)',
108 | path: 'foo.js',
109 | }],
110 | compilationLevel: 'ADVANCED',
111 | warningLevel: 'VERBOSE',
112 | defines: ['foo=true']
113 | };
114 | const out = cmdCompile(flags);
115 | assertCompileOk(out, 'console.log(!0);')
116 | });
117 |
118 | test('parse array defines with multiple values', () => {
119 | const flags = {
120 | jsCode: [{
121 | src: '/** @define {boolean} */ var bool = false; /** @define {number} */ var num = 0; /** @define {string} */ var str = "hello"; console.log(bool, num, str)',
122 | path: 'foo.js',
123 | }],
124 | compilationLevel: 'ADVANCED',
125 | warningLevel: 'VERBOSE',
126 | defines: ['bool=true', 'num=1', 'str="bye"']
127 | };
128 | const out = cmdCompile(flags);
129 | assertCompileOk(out, 'console.log(!0,1,\'"bye"\');')
130 | });
131 | });
132 |
--------------------------------------------------------------------------------
/usage.txt:
--------------------------------------------------------------------------------
1 | usage: google-closure-compiler-js {OPTIONS} [FILES]
2 |
3 | Compile FILES with google-closure-compiler-js.
4 |
5 | If FILES or --jsCode is not given, read from stdin.
6 |
7 | OPTIONS are:
8 |
9 | -h --help
10 |
11 | Show this message.
12 |
13 | -v --version
14 |
15 | Print the version number.
16 |
17 | --angularPass (default: false)
18 |
19 | Generate $inject properties for AngularJS for functions annotated with
20 | @ngInject
21 |
22 | --applyInputSourceMaps (default: true)
23 |
24 | Compose input source maps into output source map
25 |
26 | --assumeFunctionWrapper (default: false)
27 |
28 | Enable additional optimizations based on the assumption that the output will
29 | be wrapped with a function wrapper. This flag is used to indicate that
30 | "global" declarations will not actually be global but instead isolated to the
31 | compilation unit. This enables additional optimizations.
32 |
33 | --checksOnly (default: false)
34 |
35 | Don't generate output. Run checks, but no optimization passes.
36 |
37 | --compilationLevel (default: SIMPLE)
38 |
39 | Specifies the compilation level to use.
40 | Options: WHITESPACE_ONLY, SIMPLE, ADVANCED
41 |
42 | --dartPass (default: false)
43 |
44 | --defines (default: null)
45 |
46 | Overrides the value of variables annotated with `@define`, an object mapping
47 | names to primitive types.
48 |
49 | --env (default: BROWSER)
50 |
51 | Determines the set of builtin externs to load.
52 | Options: BROWSER, CUSTOM
53 |
54 | --exportLocalPropertyDefinitions (default: false)
55 |
56 | --externs
57 |
58 | Additional paths to externs to use for this compile.
59 |
60 | --generateExports (default: false)
61 |
62 | Generates export code for those marked with @export.
63 |
64 | --jsCode
65 |
66 | Specifies the paths to source code to compile.
67 |
68 | --languageIn (default: ES6)
69 |
70 | Sets what language spec that input sources conform to.
71 |
72 | --languageOut (default: ES5)
73 |
74 | Sets what language spec the output should conform to.
75 |
76 | --newTypeInf (default: false)
77 |
78 | Checks for type errors using the new type inference algorithm.
79 |
80 | --outputWrapper (default: null)
81 |
82 | Interpolate output into this string, replacing the token `%output%`
83 |
84 | --polymerVersion (default: null)
85 |
86 | Specify the Polymer version pass to use.
87 |
88 | --preserveTypeAnnotations (default: false)
89 |
90 | --processCommonJsModules (default: false)
91 |
92 | Process CommonJS modules to a concatenable form, i.e., support `require`
93 | statements.
94 |
95 | --renamePrefixNamespace
96 |
97 | Specifies the name of an object that will be used to store all non-extern globals.
98 |
99 | --rewritePolyfills (default: false)
100 |
101 | Rewrite ES6 library calls to use polyfills provided by the compiler's runtime.
102 |
103 | --useTypesForOptimization (default: false)
104 |
105 | Enable or disable the optimizations based on available type information.
106 | Inaccurate type annotations may result in incorrect results.
107 |
108 | --warningLevel (default: DEFAULT)
109 |
110 | Specifies the warning level to use.
111 | Options: QUIET, DEFAULT, VERBOSE
112 |
113 | --createSourceMap (default: false)
114 |
115 | Generates a source map mapping the generated source file back to its original
116 | sources.
117 |
--------------------------------------------------------------------------------