fixclosure
JavaScript dependency checker/fixer for Closure Library based on ECMAScript AST
Last updated 3 months ago by teppeis .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ cnpm install fixclosure 
SYNC missed versions from official npm registry.

fixclosure

fixclosure is JavaScript dependency checker/fixer for Closure Library based on ECMAScript AST. It finds namespaces used in a JavaScript file and insert/remove goog.provide, goog.require, goog.requireType and goog.forwardDeclare automatically.

npm version Node.js Version Support Build Status Dependency Status Coverage Status License

Install

$ npm install fixclosure

Usage

The following code goog.require()s an unused namespace goog.unused, also goog.missing is used but not goog.require()d.

// foo.js (before)
goog.provide('goog.foo.Bar');

goog.require('goog.foo');
goog.require('goog.unused');

goog.foo.Bar = function() {
  goog.foo.baz();
  goog.missing.require();
};

Fix it !

$ npx fixclosure --fix-in-place --namespaces=goog.foo,goog.missing foo.js
File: foo.js

Provided:
- goog.foo.Bar

Required:
- goog.foo
- goog.unused

Missing Require:
- goog.missing

Unnecessary Require:
- goog.unused

FIXED!

Total: 1 files
Passed: 0 files
Fixed: 1 files

goog.require('goog.unused') is removed and goog.require('goog.missing') is inserted.

// foo.js (fixed)
goog.provide('goog.foo.Bar');

goog.require('goog.foo');
goog.require('goog.missing');

goog.foo.Bar = function() {
  goog.foo.baz();
  goog.missing.require();
};

Rules fixclosure checked

fixclosure checks and fixes:

  • Duplicated provide/require/requireType/forwardDeclare
  • Missing provide/require/requireType/forwardDeclare
  • Unnecessary provide/require/requireType/forwardDeclare

Globbing

The arguments are globbed by globby. Directories are expanded as **/*.js.

$ fixclosure path/to/dir "foo/bar-*.js"

Use with Grunt

Use grunt-fixclosure plugin.

Configuration file

fixclosure loads options from .fixclosurerc config file like:

--provideRoots foo,bar
--replaceMap foo.foobar:foo.foo
--useForwardDeclare

fixclosure will find the file in the current directory and, if not found, will move one level up the directory tree all the way up to the filesystem root.

Options

-f or --fix-in-place

If an invalid file is found, fixclosure fixes the file in place.

--config <file>

.fixclosurerc file path.
Specify if your file is not in the search path. Default: ${process.cwd()}/.fixclosurerc

--provideRoots <roots>

Specify your root namespaces to provide. Default is goog. Comma separated list.

--namespaceMethods <methods> (deprecated)

Use --namespaces.

--namespaces <namespaces>

Specify method or property exported as a namespace itself like goog.dispose.
Comma separated list.

--replaceMap <map>

Replace method or property to namespace mapping like goog.disposeAll:goog.dispose.
Comma separated list of colon separated pairs like foo.bar1:foo.bar2,foo.bar3:foo.bar4.

--useForwardDeclare

Use goog.forwardDeclare() instead of goog.requireType() for types used only in JSDoc. Default: false

--depsJs <files>

Load namespace methods from deps.js files separated by comma. You can generate deps.js with google-closure-deps or duck.

--showSuccess

Show not only failed files but also passed files.

--no-color

Disable color output.

Inline hint

fixclosure reads "hint" for lint from special comments in your code.

ignore

fixclosure doesn't remove any goog.provide and goog.require with this hint.

goog.provide('goog.foo'); // fixclosure: ignore

goog.require('goog.bar'); // fixclosure: ignore

In the above, goog.provide('goog.foo') will not removed by fixclosure even if it isn't provided in the file. Also goog.require('goog.bar') will not removed if it isn't used. The hint affects only same line. Useful in module declaration.

fixclosure: suppressUnused is deprecated and will be removed next update.

suppressRequire

Suppress goog.require auto insertion.

// fixclosure: suppressRequire
goog.foo.bar();

In the above, goog.require('goog.foo') will not inserted. The hint affects only next line. This is useful to workaround cyclic reference.

suppressProvide

Suppress goog.provide auto insertion.

// fixclosure: suppressProvide
goog.Foo = function() {};

In the above, goog.provide('goog.Foo') will not inserted. The hint affects only next line.

Migration from v1 to v2

  • Old Node.js versions were no longer supported, use Node.js v10 or higher.
  • --namespaceMethods was deprecated, use --namespaces.
  • Deprecated --roots was removed, use --provideRoots.
  • --requireRoots was removed because fixclosure v2 no longer detects required namespaces heuristically. Use --namespaces or --depsJs to detect them. They can detect the namespaces correctly.
  • Types used only in JSDoc are reported as errors, while previously only types of @extends in @interface are reported. Add goog.requireType() or goog.fowardDeclare().

License

MIT License: Teppei Sato teppeis@gmail.com

Current Tags

  • 2.5.0                                ...           latest (3 months ago)
  • 2.0.0-alpha.4                                ...           next (10 months ago)

48 Versions

  • 2.5.0                                ...           3 months ago
  • 2.4.3                                ...           3 months ago
  • 2.4.2                                ...           9 months ago
  • 2.4.1                                ...           9 months ago
  • 2.4.0                                ...           9 months ago
  • 2.3.0                                ...           9 months ago
  • 2.2.1                                ...           10 months ago
  • 2.2.0                                ...           10 months ago
  • 2.1.1                                ...           10 months ago
  • 2.1.0                                ...           10 months ago
  • 2.0.1                                ...           10 months ago
  • 2.0.0                                ...           10 months ago
  • 2.0.0-alpha.4                                ...           10 months ago
  • 2.0.0-alpha.3                                ...           10 months ago
  • 2.0.0-alpha.2                                ...           10 months ago
  • 2.0.0-alpha.1                                ...           10 months ago
  • 2.0.0-alpha.0                                ...           10 months ago
  • 1.5.4                                ...           4 years ago
  • 1.5.3                                ...           4 years ago
  • 1.5.2                                ...           4 years ago
  • 1.5.1                                ...           4 years ago
  • 1.5.0                                ...           4 years ago
  • 1.4.0                                ...           4 years ago
  • 1.3.5                                ...           4 years ago
  • 1.3.4                                ...           4 years ago
  • 1.3.3                                ...           4 years ago
  • 1.3.2                                ...           6 years ago
  • 1.3.1                                ...           6 years ago
  • 1.3.0                                ...           6 years ago
  • 1.2.2                                ...           6 years ago
  • 1.2.1                                ...           6 years ago
  • 1.2.0                                ...           6 years ago
  • 1.1.0                                ...           6 years ago
  • 1.0.1                                ...           6 years ago
  • 1.0.0                                ...           6 years ago
  • 0.3.0-beta.2                                ...           6 years ago
  • 0.3.0-beta                                ...           6 years ago
  • 0.3.0-alpha.2                                ...           6 years ago
  • 0.2.1                                ...           6 years ago
  • 0.3.0-alpha.1                                ...           6 years ago
  • 0.2.0                                ...           6 years ago
  • 0.1.5                                ...           6 years ago
  • 0.1.3                                ...           7 years ago
  • 0.1.2                                ...           7 years ago
  • 0.1.1                                ...           7 years ago
  • 0.1.0                                ...           7 years ago
  • 0.0.2                                ...           7 years ago
  • 0.0.1                                ...           7 years ago
Maintainers (2)
Downloads
Today 0
This Week 0
This Month 0
Last Day 0
Last Week 0
Last Month 48
Dependencies (12)
Dev Dependencies (19)
Dependents (2)

Copyright 2014 - 2016 © taobao.org |