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

css-module-deps

v3.0.0

Published

walk the css dependency graph to generate a stream of json output

Downloads

5

Readme

css-module-deps

version status coverage dependencies devDependencies node

Walk the css dependency graph to generate a stream of json output.

Related

Example

var Deps = require('..')
var path = require('path')
var url = require('postcss-custom-url')
var atImport = require('postcss-simple-import')
var vars = require('postcss-advanced-variables')
var JSONStream = require('JSONStream')

var fixtures = path.resolve.bind(path, __dirname, 'src')

var stream = Deps({
  atRuleName: 'external',
  basedir: fixtures(),
  processor: [ atImport(), url(), vars() ],
})
stream.end({ file: './import-and-deps.css' })

stream.pipe(
  JSONStream.stringify(false, null, null, 2)
)
.pipe(process.stdout)

Directory structure:

⌘ tree example/src
example/src
├── import-and-deps.css
├── import-url.css
└── node_modules
    ├── helper
    │   └── vars.css
    └── sprites
        └── dialog
            ├── index.css
            └── sp-dialog.png

import-and-deps.css:

@external "./import-url";
@import "helper/vars";

.import-and-deps {
  color: $red;
}

import-url.css

@import "sprites/dialog";
.importUrl{}

helper/vars.css:

$red: #FF0000;

sprites/dialog/index.css:

.dialog {
  background: url(sp-dialog.png)
}

output:

⌘ node example/deps.js
{
  "file": "/Users/zoubin/usr/src/self/css-module-deps/example/src/import-url.css",
  "source": ".dialog {\n  background: url(node_modules/sprites/dialog/sp-dialog.png)\n}\n.importUrl{}\n\n",
  "deps": {},
  "id": "/Users/zoubin/usr/src/self/css-module-deps/example/src/import-url.css"
}
{
  "file": "/Users/zoubin/usr/src/self/css-module-deps/example/src/import-and-deps.css",
  "source": ".import-and-deps {\n  color: #FF0000;\n}\n\n",
  "deps": {
    "./import-url": "/Users/zoubin/usr/src/self/css-module-deps/example/src/import-url.css"
  },
  "id": "/Users/zoubin/usr/src/self/css-module-deps/example/src/import-and-deps.css"
}

stream = Deps(opts)

Return an object stream that expects { file: ... } objects as input, and produces objects for every dependency from a recursive module traversal as output.

opts

resolve

Specify how to resolve a file path

Type: Function

Receives the string to be resolved, and an option object with basedir.

Should return a promise, or the absolute path.

noParse

Specify which files to skip parsing.

Type: Array

Passed to multimatch to do matching.

atRuleName

Specify the name of at-rules to declare a dependency.

Type: String

Default: deps

Dependencies are declared through the @deps at-rule by default.

transform

Used to transform each file in the dependency graph.

Type: Function, Array

Signature: fn(result)

Return a promise to make it asynchronous.

result is an instance of Result.

processor

Specify postcss plugins to transform css file contents.

Type: Array

basedir

Type: String

Used to resolve input filenames.

dependenciesFilter

To filter the resolved dependencies.

Type: Function

Signature: var newDeps = dependenciesFilter(deps, file)

Result

var r = new Result(row)

Each row has the following fields:

  • file: file path
  • source: file contents

Read or modify r.root (the AST object) or r.css to do transformations.

Usually, you do not have to access both.

r.from is the file path.

r is an emitter.

Events

stream.on('file', file => {})

Before readFile called.

stream.on('transform', (result, file) => {})

Before applying transforms.

result is an Result.