Skip to content

Improve interfacing deeper to allow more flexibility in custom resolvers #8

@rubeniskov

Description

@rubeniskov

Motivation

In order to allow more flexibility for dependencies, transforms and readFile resolution, I suggest to create a minimalist interface with the logic of glslify-deps avoiding restrictions associated to the environment. This will delegates on top level, which strategy use for shader resolution in order to make this library compatible with systems without filesystem or node_modules. This library may be used in an environment which has not such capability, like a browser.

Drawbacks of the existing version

This library is using find-up and resolver for find packages, so this behaviour is restricted to be used in an environment where the system has a filesystem discoverable with node_packages directory. Also transform are retrieved using nodejs commonjs require.

var findup = require('@choojs/findup')

var nodeResolve = require('resolve')

transform = require(transform)

Main goals of this proposal

There are functions with the same functionality duplicate in both files sync and async

glslify-deps/sync.js

Lines 296 to 309 in 2683223

function glslifyPreprocessor(data) {
return /#pragma glslify:/.test(data)
}
function glslifyExport(data) {
return /#pragma glslify:\s*export\(([^\)]+)\)/.exec(data)
}
function glslifyImport(data) {
return /#pragma glslify:\s*([^=\s]+)\s*=\s*require\(([^\)]+)\)/.exec(data)
}
function defaultRead(src) {
return fs.readFileSync(src, 'utf8')

Secondary goals

Each goal will be a PR to accomplish a good tracking of changes and approbation for the maintainer,
Each PR will be rebased with the previous, so its important to merge using the implementation order

Playground

http://rubeniskov.com/blog/en/shader-sandbox-glslify

output

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions