glslify-import
Advanced tools
Comparing version 0.0.1 to 1.0.0
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() { |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Filesystem access
Supply chain riskAccesses the file system, and could potentially read sensitive data.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
No tests
QualityPackage does not have any tests. This is a strong signal of a poorly maintained or low quality package.
Found 1 instance in 1 package
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
3757
3
4
1
3
34
1
+ Addedglsl-resolve@0.0.1
+ Addedglsl-token-string@^1.0.1
+ Addedglsl-tokenizer@^2.0.2
+ Addedcore-util-is@1.0.3(transitive)
+ Addedglsl-resolve@0.0.1(transitive)
+ Addedglsl-token-string@1.0.1(transitive)
+ Addedglsl-tokenizer@2.1.5(transitive)
+ Addedinherits@2.0.4(transitive)
+ Addedisarray@0.0.1(transitive)
+ Addedreadable-stream@1.0.34(transitive)
+ Addedresolve@0.6.3(transitive)
+ Addedstring_decoder@0.10.31(transitive)
+ Addedthrough2@0.6.5(transitive)
+ Addedxtend@2.2.04.0.2(transitive)
- Removedconcat-stream@~1.0.1
- Removedglsl-deparser@0.0.2
- Removedglslify-stream@0.0.1
- Removedgraceful-fs@~2.0.1
- Removedmap-stream@0.0.3
- Removedsplit@~0.2.10
- Removedstream-combiner@0.0.2
- Removedbase64-js@0.0.2(transitive)
- Removedbops@0.0.6(transitive)
- Removedconcat-stream@1.0.1(transitive)
- Removedcssauron@0.0.31.0.0(transitive)
- Removedcssauron-glsl@0.0.11.0.0(transitive)
- Removedduplexer@0.0.4(transitive)
- Removedglsl-deparser@0.0.2(transitive)
- Removedglsl-parser@0.0.9(transitive)
- Removedglsl-tokenizer@0.0.9(transitive)
- Removedglslify-stream@0.0.1(transitive)
- Removedgraceful-fs@2.0.3(transitive)
- Removedmap-stream@0.0.3(transitive)
- Removedshortest@0.0.0(transitive)
- Removedsplit@0.2.10(transitive)
- Removedstream-combiner@0.0.2(transitive)
- Removedthrough@1.1.22.3.8(transitive)
- Removedto-utf8@0.0.1(transitive)