Security News
UK Officials Consider Banning Ransomware Payments from Public Entities
The UK is proposing a bold ban on ransomware payments by public entities to disrupt cybercrime, protect critical services, and lead global cybersecurity efforts.
The Google Closure Tools are a powerful set of utilities that aim to make large scale JavaScript development more manageable. This project brings the power of the closure tools to the node platform. The closure tools gives developers the utilities required to improve code design and maintainability by providing support for:
Install nclosure
. By:
npm install nclosure
Or better yet, by getting the source:
git clone git://github.com/gatapia/nclosure.git
cd nclosure
npm link NOTE: npm link does not work on windows! :(
For full details on utilities provided in the closure library refer to the official docs. To use any utility provided in the closure library just:
Include nclosure
in your application by require
(ing) it and initialising
it.
require('nclosure').nclosure(); // nclosure() initialises the framework
goog.require
any namespace from the Closure library.
goog.require('goog.structs.Trie');
That's it, use the imported namespaces anywhere in your file.
var trie = new goog.structs.Trie();
Using the Closure Compiler requires a small investment in learning but once you have worked your way through the docs you can take advantage of the compiler's support for:
Once your source code is annotated and ready for compilation just run the following command:
nccompile source.js
The nccompile
command accepts various arguments:
To run nclosure
's documentation tool simply run:
ncdoc <directory or source file>
For full documentation details please read the official jsdoc-toolkit docs.
For a sample source code documentation project using nclosure ncdoc see the node.js core libs as they would look if generated by nclosure.
nclosure
supports testing using Closure's 'goog.testing.jsunit' test tools.
To set up a unit test simply create a test file like:
#!/usr/bin/env node
// You can now run the test just by executing this file
require('nclosure').nclosure();
goog.require('goog.testing.jsunit');
// Import the code you are testing (may need an additionalDeps defined)
goog.require('nclosure.examples.simple.Example');
// Any testXXX function are auto-discovered and run
var testFunction1 = function() {
assertNotEquals(typeof(example_), 'undefined');
};
// Also auto discovered
function testFunction2() {
assertTrue(false);
}
If the tests are not in the same directory as your code you will have to
ensure that the deps.js file of the code you are testing
is declared in the closure.json file of the tests directory or passed in to the
call to nclosure();
like:
require('nclosure').nclosure({additionalDeps:['/pathToDeps/deps.js']});
To run a single test just execute:
./testSourceFile.js <optionalTestName>
To run all tests (files with the word test or suite in them) in a single directory (recursive) run the following command:
nctest <dirname>
The testing framework also supports test suite files. If you want to have a test suite simply have an array var named suite with the files to test (relative to the suite file). I.e.
// Run all the tests inside the '../examples/simple/' directory
// This array can be directories or specific test (or other suite)
// files
var suite = ['../examples/simple/'];
For detailed code style checking you can also use nclosure
's
linter support. To use linter you will need to download and install
Closure Linter.
Closure Linter checks your code against Google's own JavaScript Style Guide which is a mature and highly scalable framework for developing JavaScript code.
To install Closure Linter read the following page.
Once installed simply run the following command to linter
your code.
ncstyle <directory>
NClosure contains a set of wrappers around the core node.js libraries. These wrappers can be used to give type safety when using these libraries. Eg:
goog.provide('namespace');
// Import the 'node.fs' namespace. All node core libs live inside the
// 'node' namespace.
goog.require('node.fs');
console.log('Files: ' + node.fs.readdirSync('.'));
nclosure
can be configured in several ways. The easiest is to modify the
bin/closure.json
file with your global settings. Settings here can be
extended by placing a closure.json
file in your source directory. You can
also place a closure.json
in the directory running node
(The cwd).
Finally, nclosure
can also be configured by passing an optional options
object to the require('nclosure').nclosure(opts);
call.
All configuration files and configuration objects take the following format:
{
closureBasePath: Location of the closure-library. This defaults to
the closure library included in this package.
additionalDeps: Any additional dependency files required to run your
code. These files generally point to other closure libraries.
Note these deps files must have paths relative to this setting
file or be absolute.
compiler_jar: Path to the compiler jar you want to use. This defaults
to the included compiler.jar file so only change this if you want
to use a custom compiler.
additionalCompileOptions: Additional compiler options,
e.g.: "['--jscomp_warning=newWarningType']"
additionalCompileRoots: These are directories containing source code
that needs to be included in the compilation. If this is not
included then additionalDeps is used to try to guess any additional
roots required (assumes that the deps.js file is in the root folder
of the source directory).
jsdocToolkitDir: The location of jsdoc-toolkit. This is only required
if you want to use jsdoc-toolkit to document your source code. This
defaults to the jsdoc instance included in this package.
additionalJSDocToolkitOptions: Additional jsdoc-toolkit options,
e.g.: "['-D="noGlobal:true"']"
additionalLinterOptions: Additional gjslint and fixjsstyle options,
e.g.: "['--summary=true']"
nodeDir: The location of the node source code. This is only required
if you are contributing to the nclosure project or would like to
update your node-extern files.
}
Note: All paths can be absolute or relative to the location of the current settings file.
The best way to get going with nclosure is to look at the nclosure code (bin, lib and examples directories). All nclosure code is annotated and should give you a good introduction to what can be acchieved with the tool.
If you have any questions, issues, complaints, suggestions, .... just email me (guido@tapia.com.au) and I'll see what I can do to help.
Since the Node.js core libs are not jsdoc'ed in any way I could not give any type safety when using these core libs.
The documentation template is lacking in several areas this will be improved in the future.
Linter is a pain to instal.
Poor project documentation.
For an up to date list of issues see the TODO.txt file. Later I will start an issues list on github.
Copyright 2011 Guido Tapia (guido@tapia.com.au)
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
FAQs
Server-side Google Closure with Node.js
We found that nclosure demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 2 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
The UK is proposing a bold ban on ransomware payments by public entities to disrupt cybercrime, protect critical services, and lead global cybersecurity efforts.
Security News
Snyk's use of malicious npm packages for research raises ethical concerns, highlighting risks in public deployment, data exfiltration, and unauthorized testing.
Research
Security News
Socket researchers found several malicious npm packages typosquatting Chalk and Chokidar, targeting Node.js developers with kill switches and data theft.