benbria / browserify-transform-tools Goto Github PK
View Code? Open in Web Editor NEWUtilities for writing browserify transforms.
License: MIT License
Utilities for writing browserify transforms.
License: MIT License
When running browserify from the command line, I am not able to pass through the appliesTo
configuration.
browserify -t [ abc --opt1 val --appliesTo [ --includeExtensions [.html .abc] ] ] test.abc
Does anyone agree that this is this something we would want to support?
When loading configuration from package.json, we should start at the cwd and look upwards for package.json, instead of starting at the js file we're transforming.
hey, there!
i was wondering if there was any plan to support specifying aliases for require
in the makeRequireTransform
method. i ask because of things like proxyquireify and others that do "hygienic" require
monkey-patching by providing an alias, but still need to be potentially transformed.
i started poking at PRing the change for discussion, but encountered a brick wall in the form of (what seems like) necessarily breaking the current API. ideally, in my estimation, the require
"word" would be somehow linked to each "argument" in the transform callback. because of this, i decided to instead ask if it was even something considered worth supporting, and if so if there was any preference about how to support it. if desired, i am more than willing to do the work to support it.
thoughts?
thanks for your time!
Browserify's API for writing transforms allows transforms to accept two parameters: the file
name, which is mandatory if the transform is to do anything meaningful; and trOpts
, or transform options, which are optional but can be used by the transform if it so chooses.
Presently, the make*Transform
methods all return a function that accepts a file
parameter but no trOpts
. Consequently it's impossible for any parameters provided to the transform from somewhere upstream (i.e. via Browserify's own b.transform
API, or a build tool such as grunt-browserify) to be processed by the created transform.
I propose modifying the function signature of the transform
function returned by makeStringTransform
(see transformTools.coffee
line 53) from
transform = (file) ->
to
transform = (file, opts) ->
and to change the transformOptions
from
transformOptions = {
file: file,
configData, configData,
config: configData?.config
}
to
transformOptions = {
file: file,
configData, configData,
config: configData?.config,
opts: opts
}
Thoughts?
When using browserify-transform-tools (v 1.5.1), I am not able to programatically specify what file extensions to include (includeExtensions
).
Partial code sample:
var DEFAULT_EXTENSIONS = ['.js']
var options = { includeExtensions: DEFAULT_EXTENSIONS }
var myStringTransform = transformTools.makeStringTransform("hello", options, function(content, transformOptions, done) {
done(null, 'hello ' + content);
});
browserify({ entries: ['index.html'] })
.transform(myStringTransform, { appliesTo: { includeExtensions: ['.html'] } })
.bundle()
I want to use the transform I create with browserify-transform-tools to apply to reusable packages, but configuration can't be set for each package the same way browserify transforms are.
Browserify transforms are defined at the package level, but browserify-transform-tools reads configuration only from the top level package.
For example, I want to create a transform called somethingify. I then want to create a reusable package called reuseMe that uses somethingify and sets it's own configuration.
myProject
package.json <----Config for somethingify transform must be set here
node_modules
somethingify
reuseMe
package.json <---I should be able to set somethingify config here
node_modules
somethingify
To be consistent with browserify behavior, transform options should not apply to child packages. Each package should be responsible for describing the transforms it uses and the configurations for those transforms.
I'm using the following to change a require in a given transform:
var transform = transformTools.makeRequireTransform("requireTransform",
{evaluateArguments: true},
function(args, opts, cb) {
if (args[0] === 'modernizr') {
return cb(null, "require('../../../libs/modernizr/modernizr.js')");
} else {
return cb();
}
});
And yet I'm not seeing the relative file change. Is this something supported? Am I overlooking something?
I think you forget to emit an error event somewhere (may be somewhere here?)[https://github.com/benbria/browserify-transform-tools/blob/master/src/transformTools.coffee#L157] .
At least my node process crashes when having a syntax error whereas I get an error
event on the builder to handle.
Error: Line 5: Unexpected token ILLEGAL (while aliasify was processing /Users/bodokaiser/Documents/Repositories/satisfeet/app/index.js)
at throwError (/Users/bodokaiser/Documents/Repositories/satisfeet/node_modules/aliasify/node_modules/browserify-transform-tools/node_modules/falafel/node_modules/esprima/esprima.js:1472:21)
at scanPunctuator (/Users/bodokaiser/Documents/Repositories/satisfeet/node_modules/aliasify/node_modules/browserify-transform-tools/node_modules/falafel/node_modules/esprima/esprima.js:689:9)
at advance (/Users/bodokaiser/Documents/Repositories/satisfeet/node_modules/aliasify/node_modules/browserify-transform-tools/node_modules/falafel/node_modules/esprima/esprima.js:1065:16)
at lex (/Users/bodokaiser/Documents/Repositories/satisfeet/node_modules/aliasify/node_modules/browserify-transform-tools/node_modules/falafel/node_modules/esprima/esprima.js:1076:21)
at consumeSemicolon (/Users/bodokaiser/Documents/Repositories/satisfeet/node_modules/aliasify/node_modules/browserify-transform-tools/node_modules/falafel/node_modules/esprima/esprima.js:1589:13)
at parseVariableStatement (/Users/bodokaiser/Documents/Repositories/satisfeet/node_modules/aliasify/node_modules/browserify-transform-tools/node_modules/falafel/node_modules/esprima/esprima.js:2295:9)
at parseStatement (/Users/bodokaiser/Documents/Repositories/satisfeet/node_modules/aliasify/node_modules/browserify-transform-tools/node_modules/falafel/node_modules/esprima/esprima.js:2826:24)
at /Users/bodokaiser/Documents/Repositories/satisfeet/node_modules/aliasify/node_modules/browserify-transform-tools/node_modules/falafel/node_modules/esprima/esprima.js:3588:38
at parseSourceElement (/Users/bodokaiser/Documents/Repositories/satisfeet/node_modules/aliasify/node_modules/browserify-transform-tools/node_modules/falafel/node_modules/esprima/esprima.js:3068:24)
at parseSourceElements (/Users/bodokaiser/Documents/Repositories/satisfeet/node_modules/aliasify/node_modules/browserify-transform-tools/node_modules/falafel/node_modules/esprima/esprima.js:3106:29)
make: *** [boot] Error 8
The package.json specifies a dependency on falafel, version 1.0.2. The latest published npm version is 1.0.1, so npm installing the package fails...
Hi.
We have a global require transform that balks on a module that uses a const
variable decl. We get the following error:
error: SyntaxError: Unexpected token (83:6) (while requireTransform was processing /Users/tfennelly/projects/blueocean/blueocean-dashboard/node_modules/pem-jwk/index.js) while parsing file: /Users/tfennelly/projects/blueocean/blueocean-dashboard/node_modules/pem-jwk/index.js
at Parser.pp.raise (/Users/tfennelly/projects/blueocean/blueocean-dashboard/node_modules/acorn/dist/acorn.js:1745:13)
at Parser.pp.unexpected (/Users/tfennelly/projects/blueocean/blueocean-dashboard/node_modules/acorn/dist/acorn.js:2264:8)
at Parser.pp.semicolon (/Users/tfennelly/projects/blueocean/blueocean-dashboard/node_modules/acorn/dist/acorn.js:2243:59)
at Parser.pp.parseExpressionStatement (/Users/tfennelly/projects/blueocean/blueocean-dashboard/node_modules/acorn/dist/acorn.js:2677:8)
at Parser.pp.parseStatement (/Users/tfennelly/projects/blueocean/blueocean-dashboard/node_modules/acorn/dist/acorn.js:2462:160)
at Parser.pp.parseTopLevel (/Users/tfennelly/projects/blueocean/blueocean-dashboard/node_modules/acorn/dist/acorn.js:2379:21)
at parse (/Users/tfennelly/projects/blueocean/blueocean-dashboard/node_modules/acorn/dist/acorn.js:101:12)
at module.exports (/Users/tfennelly/projects/blueocean/blueocean-dashboard/node_modules/falafel/index.js:22:15)
at Stream.<anonymous> (/Users/tfennelly/projects/blueocean/blueocean-dashboard/node_modules/browserify-transform-tools/lib/transformTools.js:187:21)
at Stream.end (/Users/tfennelly/projects/blueocean/blueocean-dashboard/node_modules/browserify-transform-tools/lib/transformTools.js:108:30)
Where 83:6
is pointing at a const
.
I tried the latest version of browserify
and browserify-transform-tools
.
Is there anything I can do? Maybe I need to apply a global babel transform or something? Seems bad to publish unprocessed modules with const
etc in them.
For require and falafel transforms, it would be nice if there was an option to only parse js type files by default. Trying to run a JSON file through a require or falafel transform wouldn't go vey well, for example.
It would be nice if there was a way for end-users to specify what extensions should be processed in the module config, or even for them to specify exactly which files should be processed for performance optimization.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.