question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

allow to specify global-transforms

See original GitHub issue

For the sake of argument lets say I’m working on a project A which depends on point-generator.

point-generator depends on xtend.

So now I’m trying to apply a transform to the index.js file in xtend. To do that I’ll add my transform to the package.json of my package A.

No transforms are specified in xtend or its dependent package.jsons and my higher level transform doesn’t get called when node_modules/point-generator/node_modules/xtend/index.js is resolved.

As a result I have no chance to transform xtend/index.js since my transform is never called.

This is where global transforms could help. They would be called for EVERY file that is resolved, even the ones from child dependencies.

Lets take the example of browserify-swap. With this I want to swap out modules when a certain configuration applies. So it would be called with all resolved files and try to match the regex and depending on the result apply a transform or just pass it through.

{
  "browserify": {
    "global-transform": [ "browserify-swap" ]
  },
  "browserify-swap": {
    "dev": {
      ".*node_modules\/xtend\/\\S+\\.js$": "./swap/other-xtend.js"
    },
    "test": {
       ".*node_modules\/xtend\/\\S+\\.js$": "./swap/stubable-xtend.js"
    }
  }
}

Swapping makes sense for different use cases:

  • only pulling large modules needed for diagnostics when a flag is set and otherwise replacing with empty stub, greatly speeding up bundling time when it’s not needed
    • good example is hyperwatch which depends on hypernal (huge)
  • stubbing out modules during testing

However I think there will be other situations where global transforms would be a great help.

To avoid non-determinism, local transforms should always execute first, so that their input cannot be affected by a global transform getting in the middle.

Additionally global transforms only apply if the package.json that they are defined in is the root of the project (i.e. the current dir).

Issue Analytics

  • State:closed
  • Created 10 years ago
  • Reactions:1
  • Comments:5

github_iconTop GitHub Comments

2reactions
pronebirdcommented, Jun 24, 2017

@substack So what about global-transforms in package.json stuff?

2reactions
ghostcommented, Dec 29, 2013

Global transforms just landed in 3.17.0. I’m not sure about the package.json stuff but you can use them with -g or via the API by doing .transform({ global: true }, tr).

Read more comments on GitHub >

github_iconTop Results From Across the Web

Allow global transforms with grunt browserify - Stack Overflow
Browserify docs say that you cannot apply global-transforms in package file so the following don't work, (which I thought would):
Read more >
browserify-dev-middleware/README.md at master - GitHub
Specify global transforms too. app.use(require('browserify-dev-middleware')( ...
Read more >
Assigning to global transforms of current gameobject - Unity Answers
For optimization, is it necessary to assign to global the transforms of the gameobject the current script is in? i.e., start(){var t:transform;} update(t....
Read more >
Neos VR Tutorial: Let CopyGlobalTransform... copy ... - YouTube
This component is dead simple to use but in the video I talk ... Neos VR Tutorial: Let CopyGlobalTransform... copy global transforms for...
Read more >
moveit_core: moveit::core::AttachedBody Class Reference
The set of links that are allowed to be touched by this object is specified by touch_links. ... Get the global transforms for...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found