npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

google-closure-deps

v20230802.0.0

Published

Library to parse dependencies for Closure Library. Also includes a CLI to generate deps.js files for Closure Library's debug loader.

Downloads

39,165

Readme

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]