Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

glslify-import

Package Overview
Dependencies
Maintainers
1
Versions
6
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

glslify-import - npm Package Compare versions

Comparing version 0.0.1 to 1.0.0

LICENSE.md

71

index.js

@@ -1,47 +0,46 @@

var combine = require('stream-combiner')
var glslify = require('glslify-stream')
var concat = require('concat-stream')
var map = require('map-stream')
var fs = require('graceful-fs')
var split = require('split')
var eol = require('os').EOL
const string = require('glsl-token-string')
const tokenize = require('glsl-tokenizer')
const resolve = require('glsl-resolve')
const path = require('path')
const fs = require('fs')
module.exports = include
module.exports = glslifyImport
function include(file) {
var stream = combine(split(), map(write))
function glslifyImport(file, src, opts, done) {
const tokens = tokenize(src)
return stream
var total = 0
function write(line, next) {
var cache = {}
var match
for (var i = 0; i < tokens.length; i++) (function(i) {
var token = tokens[i]
if (token.type !== 'preprocessor') return
line = String(line)
line = line.replace(/^\s*?#pragma\s+import\:(.+)$/g, function(full, name) {
match = name.trim()
return ''
})
var imported = /#pragma glslify:\s*import\(([^\)]+)\)/.exec(token.data)
if (!imported) return
if (!imported[1]) return
if (!match) return next(null, line + eol)
var target = imported[1]
.trim()
.replace(/^'|'$/g, '')
.replace(/^"|"$/g, '')
glslify.resolve(file, match, function(err, dest) {
if (err) return stream.emit('error', err)
if (cache[dest]) return next(null, cache[dest])
total++
// Handle imports recursively too!
fs.createReadStream(dest)
.on('error', error)
.pipe(include(dest))
.on('error', error)
.pipe(concat(function(data) {
next(null, cache[dest] = data + eol)
}))
.on('error', error)
resolve(target, {
basedir: path.dirname(file)
}, function(err, resolved) {
if (err) return done(err)
function error(err) {
return stream.emit('error', err)
}
fs.readFile(resolved, 'utf8', function(err, contents) {
if (err) return done(err)
token.data = contents
if (--total) return
done(null, string(tokens))
})
})
}
})(i)
if (!total) return done(null, src)
}
{
"name": "glslify-import",
"version": "0.0.1",
"version": "1.0.0",
"description": "A transform stream for glslify that adds an `import` directive to your shaders.",
"main": "index.js",
"dependencies": {
"map-stream": "0.0.3",
"split": "~0.2.10",
"stream-combiner": "0.0.2",
"concat-stream": "~1.0.1",
"glsl-deparser": "0.0.2",
"graceful-fs": "~2.0.1",
"glslify-stream": "0.0.1"
"glsl-resolve": "0.0.1",
"glsl-token-string": "^1.0.1",
"glsl-tokenizer": "^2.0.2"
},
"devDependencies": {},
"devDependencies": {
"glslify": "^2.1.2",
"tap-spec": "^3.0.0",
"tape": "^4.0.0"
},
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
"test": "node test | tap-spec"
},

@@ -19,0 +19,0 @@ "author": "Hugh Kennedy <hughskennedy@gmail.com> (http://hughskennedy.com/)",

# glslify-import #
A transform stream for [glslify](http://github.com/chrisdickinson/glslify)
A transform stream for [glslify](http://github.com/stackgl/glslify)
that adds an `import` directive to your shaders.

@@ -12,3 +12,3 @@

// main.frag
#pragma import: ./common.glsl
#pragma glslify: import('./common.glsl')

@@ -15,0 +15,0 @@ void main() {

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc