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

glslify-deps

v1.3.2

Published

Walk the dependency graph of a glslify shader.

Downloads

977,225

Readme

glslify-deps

Walk the dependency graph of a glslify shader.

glslify-deps is responsible for resolving your shader's dependencies and applying their transforms before the actual source modification occurs. You may notice some parallels here with browserify's module-deps package.

While glslify-deps is an "internal" package for glslify, it may be useful to use this package directly in specific cases, e.g. building a file tree server-side but bundling the final shader on the client.

Module API

There is an asynchronous and a synchronous API:

var glslifyDeps = require('glslify-deps')
var glslifyDepsSync = require('glslify-deps/sync')

The asynchronous API is documented below. For every method in the asychronous API, instead of a callback(err, result), the result is available as the return value of the method.

depper = glslifyDeps([options])

Creates a fresh glslify-deps instance. Accepts the following options:

  • cwd: the current working directory to resolve relative file paths from.
  • readFile: pass in a custom function reading files.
  • resolve: pass in a custom function for resolving require calls. It has the same signature as glsl-resolve.
  • files: a filename/source object mapping of files to prepopulate the file cache with. Useful for overriding particular file paths manually, most notably the "entry" file.

depper.transform(transform, [options])

Adds a new transform – should be used before calling depper.add.

transform may either be a string (which is resolved like a require call), or a function. More information on transforms can be found below.

depper.add(filename, [callback])

Adds a new file to the dependency graph.

depper.inline(source, basedir, [callback])

Adds a new inline file to the dependency graph, where source is the GLSL source to include and basedir is the directory to pretend it's being created in. A basedir is required to properly resolve requires and transforms, and defaults to process.cwd().

depper.on('file', cb(filename))

Emitted whenever a new file has been included in the dependency graph.

Example Output

[
  {
    "id": 0,
    "deps": { "glsl-random": 1 },
    "file": "index.glsl",
    "source": "precision mediump float;\n#pragma glslify: random = require(glsl-random)\n",
    "entry": true
  },
  {
    "id": 1,
    "deps": {},
    "file": "node_modules/glsl-random/index.glsl",
    "source": "highp float random(vec2 co)\n{\n    highp float a = 12.9898;\n    highp float b = 78.233;\n    highp float c = 43758.5453;\n    highp float dt= dot(co.xy ,vec2(a,b));\n    highp float sn= mod(dt,3.14);\n    return fract(sin(sn) * c);\n}\n\n#pragma glslify: export(random)",
    "entry": false
  }
]

Transform API

The transform API has changed since glslify 1.0 to make it more "vanilla".

With the asynchronous API, transforms have this signature:

module.exports = function(file, source, options, done) {
  done(null, source.toUpperCase())
}

and using the synchronous API, transforms have this signature:

module.exports.sync = function(file, source, options) {
  return source.toUpperCase()
}

For an example that is compatible with both the async and sync APIs, here's glslify-hex rewritten using the new API:

var through = require('through')

var regexLong  = /#([a-f0-9]{2})([a-f0-9]{2})([a-f0-9]{2})([a-f0-9]{2})?/gi
var regexShort = /#([a-f0-9])([a-f0-9])([a-f0-9])([a-f0-9])?/gi

module.exports = transform
module.exports.sync = transform

function transform(filename, src, opts, done) {
  src = src.replace(regexShort, function(whole, r, g, b, a) {
    return !a
      ? '#' + r + r + g + g + b + b
      : '#' + r + r + g + g + b + b + a + a
  }).replace(regexLong, function(whole, r, g, b, a) {
    r = makeFloat(parseInt(r, 16) / 255)
    g = makeFloat(parseInt(g, 16) / 255)
    b = makeFloat(parseInt(b, 16) / 255)
    a = makeFloat(parseInt(a, 16) / 255)

    return isNaN(a)
      ? 'vec3('+[r,g,b].join(',')+')'
      : 'vec4('+[r,g,b,a].join(',')+')'
  })

  if (typeof done === 'function') done(null, src)
  return src
}

function makeFloat(n) {
  return String(n).indexOf('.') === -1
    ? n + '.'
    : n
}

Transforms in package.json

Transforms now support options specified in package.json:

{
  "glslify": {
    "transform": [
       "glslify-hex",
      ["glslify-optimize", { "mangle": true }]
    ]
  }
}