|
1 | 1 | // @ts-check |
2 | 2 | /** @typedef {import('glsl-resolve')} GlslResolve */ |
3 | | -var path = require('path') |
4 | 3 | var Emitter = require('events/') |
5 | 4 | var inherits = require('inherits') |
6 | 5 | var map = require('map-limit') |
|
70 | 69 | /** |
71 | 70 | * @typedef {Object} DepperOptions |
72 | 71 | * @prop {Boolean} [async] Defines the mechanism flow resolution. |
73 | | - * @prop {String} [cwd] The root directory of your shader. Defaults to process.cwd(). |
74 | 72 | * @prop {Function} [readFile] pass in a custom function reading files. |
75 | 73 | * @prop {GlslResolve} [resolve] pass in a custom function for resolving require calls. It has the same signature as glsl-resolve. |
76 | 74 | * @prop {Object<string, string>} [files] a filename/source object mapping of files to prepopulate the file cache with. Useful for overriding. |
@@ -101,17 +99,12 @@ function Depper(opts) { |
101 | 99 |
|
102 | 100 | this._cache = {} |
103 | 101 | this._fileCache = parseFiles(Object.assign({}, opts.files) || {}) |
104 | | - this._cwd = opts.cwd || process.cwd() |
105 | 102 |
|
106 | 103 | /** @type {TransformDefinition[]} */ |
107 | 104 | this._transforms = [] |
108 | 105 | /** @type {TransformDefinition[]} */ |
109 | 106 | this._globalTransforms = [] |
110 | 107 |
|
111 | | - if (typeof this._cwd !== 'string') { |
112 | | - throw new Error('glslify-deps: cwd must be a string path') |
113 | | - } |
114 | | - |
115 | 108 | if (!opts.readFile) { |
116 | 109 | throw new Error('glslify-deps: readFile must be defined') |
117 | 110 | } |
@@ -139,10 +132,9 @@ function Depper(opts) { |
139 | 132 | } |
140 | 133 | } |
141 | 134 |
|
142 | | -Depper.prototype.inline = function(source, basedir, done) { |
143 | | - var inlineFile = path.resolve(basedir || this._cwd, this._inlineName) |
| 135 | +Depper.prototype.inline = function(source, filename, done) { |
144 | 136 | this._inlineSource = source |
145 | | - return this.add(inlineFile, done) |
| 137 | + return this.add(filename || this._inlineName, done) |
146 | 138 | } |
147 | 139 |
|
148 | 140 | /** |
@@ -263,11 +255,16 @@ Depper.prototype.transform = function(transform, opts) { |
263 | 255 | * |
264 | 256 | * |
265 | 257 | * @param {String|GlslTransform} transform |
| 258 | + * @param {Object} [opts] The options will be pased to transformRequire function. |
266 | 259 | * @param {(err: Error, transform?: GlslTransform) => any} [done] Applies if is defined |
267 | 260 | * @return {Function} |
268 | 261 | */ |
269 | | -Depper.prototype.resolveTransform = function(transform, done) { |
270 | | - var opts = { cwd: this._cwd } |
| 262 | +Depper.prototype.resolveTransform = function(transform, opts, done) { |
| 263 | + if (typeof opts === 'function') { |
| 264 | + done = opts |
| 265 | + opts = {} |
| 266 | + } |
| 267 | + |
271 | 268 | var self = this |
272 | 269 |
|
273 | 270 | if (typeof transform === 'function') { |
@@ -358,7 +355,7 @@ Depper.prototype._addDep = function(file, extra) { |
358 | 355 | } |
359 | 356 |
|
360 | 357 | /** |
361 | | - * Internal method to register |
| 358 | + * Internal method to register transforms |
362 | 359 | * @param {TransformDefinition[]} transforms |
363 | 360 | * @param {(err: Error, resolved?: TransformResolved[]) => any} cb |
364 | 361 | * @returns {TransformResolved[]} |
@@ -444,7 +441,7 @@ Depper.prototype._resolveImports = function(imports, opts, done) { |
444 | 441 | } |
445 | 442 |
|
446 | 443 | Depper.prototype.readFile = function(filename, done) { |
447 | | - if (path.basename(filename) !== this._inlineName) |
| 444 | + if (filename !== this._inlineName) |
448 | 445 | return this._readFile(filename, done) |
449 | 446 |
|
450 | 447 | if(this._async) { |
|
0 commit comments