20230802.0.0 • Published 8 months ago

google-closure-deps v20230802.0.0

Weekly downloads
1,174
License
Apache-2.0
Repository
github
Last release
8 months ago

Closure Dependencies

This is a separate utility node package for Closure Library related to dependency management with Closure files.

For more information on Closure Library visit the Google Developers or GitHub sites.

This is meant to replace similar Python scripts that already exist in Closure Library. We're JavaScript deps and should be providing tooling written in JavaScript, where possible! Those Python tools will continue to exist but will not be updated and should be considered deprecated.

Installation

Install via npm:

npm install google-closure-deps

To use the CLI below from any directory install the package globally:

npm install -g google-closure-deps

Command Line Interface

closure-make-deps

closure-make-deps is a utility to produce a dependency file for Closure Library's debug code loader. Closure Library is capable of loading code in a web browser or in Node but must know the dependency graph ahead of time. Generally this is done by loading Closure's base.js file and then loading a dependency file containing repeated calls to goog.addDependency`. Closure comes bundled with a file named deps.js for itself and is capable of auto loading this file.

get-js-version

get-js-version is a generally useful utility that determines the highest level version of a JavaScript program from stdin. The output format is determined by the Closure Compiler's FeatureSet#version method and should match what goog.addDependency expects for a lang load flag.

$ echo "const foo = 0;" | get-js-version
es6

Library

This Node module also exposes standard functions to parse Closure files and retrieve a dependency graph.

This is an in-code example for clarity, but there are also functions to parse files rather than strings.

const {parser, depGraph} = require('google-closure-deps');

// A file that provides "goog" is required for any file that references Closure.
// Usually this is Closure's base.js file.
const goog = parser.parseText('/** @provideGoog */', '/base.js').dependencies;

const firstFile =
    parser.parseText(`goog.module('first.module')`, '/first.js').dependencies;
const secondFile = parser.parseText(`
goog.module('second.module');
const firstModule = goog.require('first.module');
`, '/second.js').dependencies;
const graph = new depGraph.Graph([...goog, ...firstFile, ...secondFile]);
graph.order(...secondFile); // [goog, firstFile, secondFile]
graph.depsBySymbol.get('first.module'); // firstFile
graph.depsByPath.get('/second.js'); // secondFile

This also supports parsing ES6 modules now that Closure Library has support for them!

const {parser, depGraph} = require('google-closure-deps');

// A file that provides "goog" is required for any file that references Closure.
// Usually this is Closure's base.js file.
const goog = parser.parseText('/** @provideGoog */', '/base.js').dependencies;

const firstFile = parser.parseText(
`
goog.declareModuleId('first.module');
export const FOO = 'foo';
`, "/first.js").dependencies;

const secondFile = parser.parseText(
    'import {FOO} from "./first.js";',
    '/second.js').dependencies;

const thirdFile = parser.parseText(
`
goog.module("third.module");
const firstModule = goog.require("first.module");
`, '/third.js').dependencies;

const graph = new depGraph.Graph([...goog, ...firstFile, ...secondFile, ...thirdFile]);
graph.order(...secondFile, ...thirdFile); // [goog, firstFile, secondFile, thirdFile]
20230802.0.0

8 months ago

20230502.0.0

11 months ago

20230411.0.0

1 year ago

20230228.0.0

1 year ago

20230206.0.0

1 year ago

20230103.0.0

1 year ago

20221102.0.0

1 year ago

20221004.0.0

1 year ago

20220905.0.0

2 years ago

20220803.0.0

2 years ago

20220601.0.0

2 years ago

20220719.0.0

2 years ago

20220405.0.0

2 years ago

20220502.0.0

2 years ago

20220301.0.0

2 years ago

20220202.0.0

2 years ago

20220104.0.0

2 years ago

20211201.0.0

2 years ago

20211006.0.0

2 years ago

20210906.0.0

2 years ago

20211107.0.0

2 years ago

20210907.0.0

2 years ago

20210808.0.0

3 years ago

20210601.0.0

3 years ago

20210406.0.0

3 years ago

20210202.0.0

3 years ago

20210106.0.0

3 years ago

20201102.0.1

3 years ago

20200830.0.0

4 years ago

20200719.0.0

4 years ago

20200628.0.0

4 years ago

20200614.0.0

4 years ago

20200517.0.0

4 years ago

20200504.0.0

4 years ago

20200406.0.0

4 years ago

20200315.0.0

4 years ago

20200224.0.0

4 years ago

20200204.0.0

4 years ago

20200112.0.0

4 years ago

20200101.0.0

4 years ago

20191111.0.0

4 years ago

20191027.0.1

4 years ago

20191027.0.0

4 years ago

20190929.0.0

5 years ago

20190909.0.0

5 years ago

20190819.0.0

5 years ago

20190729.0.0

5 years ago

20190709.0.0

5 years ago

20190618.0.0

5 years ago

20190528.0.0

5 years ago

20190513.0.0

5 years ago

20190415.0.0

5 years ago

20190325.0.0

5 years ago

20190215.0.0

5 years ago

20190121.0.0

5 years ago

20180910.1.0

6 years ago

20180910.0.0

6 years ago

20180805.0.1

6 years ago

20180805.0.0

6 years ago

1.0.0

6 years ago