You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
load.fromText to use full plugin moduleID not name moduleID #638
I had an issue today, where I had a folder structure looking like this -
-data-list.coffee
-data-list.hbs
-data-list.less
And I was loading hbs!./data-list and less!./data-list within data-list.coffee.
The callback for defining data-list.coffee would never return because there was a name collision of the data-list id.
The reason for this seems to be that the plugin load.fromText function loads the item as the moduleID data-list for both plugins instead of hbs!data-list or cs!data-list for the separate plugins.
Ideally, load.fromText should define into the plugin ID form I think.
This is a bit tricky, because a transpiler could just write out a plain JS module for the value, and that plain JS module would have the data-list ID, using this example, so it would claim that ID, and that ID may be emitted as part of a build -- a plain JS file at the data-list.js location. Then, some sort of config could point to that ID to use for that resource ID.
At least that was the thinking behind reserving the name. I'm open to thinking about this in a different way. Addressing that first design issue would be the way to start.
I'm not sure I completely follow. Are you saying that the difficulty is in altering the define in the load.fromText to use the plugin ID form of plugin!name, or that it is a feature to be able to build the name ID since it is more compatible with builds?
The choice was done to explicitly use the JS ID for the fromText evaluation, because I though transpilers might want to output transformed code to the dependencyId.js location.
Looking more into this, the text plugin can write out .js resources, although what I did there was to create the JS form at example.html.js instead of example.js. So perhaps that is what the suggested path for transpilers should be. For instance, for a coffeescript one, example.coffee is saved as example.coffee.js.
The tricky part is communicating that knowledge to the loader or the loader plugin after a build. Perhaps that is just map config:
With that, then maybe the loader can just swap in the load.fromText definition for the 'cs!example' ID in the non-build case. Although loader plugins would need to then remove the require() they used to do at the end of their load functions to then bind to the resource:
that pattern is already deprecated in 2.1 -- the loader does that internally now, and only allows fromText to be called once and it is associated with the 'cs!example' ID automatically (but just not explicitly bound).
So I that might work out, but given the hard deprecation/force of change for transpiler plugins, putting this in the 2.2.0 bucket.
From a build perspective, I would think it is worth strongly advising against loading non-layered scripts in production. The reason being that loading a combined layer is always more efficient than loading files separately.
So when I run builds, I expect all resources to be built into layers that have a chance of being used. During production testing, any layers that load say CoffeeScript could still work by downloading the CoffeeScript compiler, but these should ultimately be mapped to a layer I would have thought. Thus, I always imagine the fromText defining into the plugin ID itself, and not some derived ID, and for that built file to always be loaded as part of a larger layer.
It seems I've had the incorrect picture though - understanding this plugin scenario (which I was previously never aware of) has finally made the writeFile plugin hook click. I've read that over and over and never understood that it transpiled to a js file like that!
That's my current perspective, although there may well be cases, where loading individual files in this way is entirely necessary say for loading configuration files etc. It seems the way things are set up is far more flexible and open to the most customisation, which is a good thing.
So one could either remove this build flexibility, which should be carefully considered or otherwise your solution sounds perfect.
I have included code in the transpiler base to automatically load from '.js' extensions where 'precompiled' paths prefixes have been set.
When stubbing the module entirely, that would imply that all paths have been precompiled. But at the moment, a stub module won't know that a file 'cs!some-module' should be found at 'some-module.coffee.js'.
In order to allow this I would suggest a convention that can be used to allow for this and avoid these name conflicts:
Follow up on this: I do not want to ban "loading non-layered scripts in production", so I want to get this to work for that scenario too.
Some more motivation for fixing this ticket: #765 points out an issue with trying to use "cs!something" and "hbr!something" -- if both are transpilers, the load.fromText thing I think is messing things up.
I really do not like needing an "after build" switch to either map the compiled output to the plugin resource ID or some other switch.
This may not work out, but maybe I can just bind load.fromText to really just assign to the full plugin resource ID instead of doing the current fromText route, and look at maybe look at write.asModule doing the same thing. I am going off partial memory, and I just skimmed this ticket again, so there is probably an issue with that, but going to temporarily put this in the 2.1.7 bucket. It could very easily get pushed back to 2.2.0.
Some older loader plugins may still do the require() for the resourceId after calling fromText, and I do not feel comfortable changing that in the .1 series. I am
Activity
jrburke commentedon Feb 19, 2013
This is a bit tricky, because a transpiler could just write out a plain JS module for the value, and that plain JS module would have the
data-listID, using this example, so it would claim that ID, and that ID may be emitted as part of a build -- a plain JS file at the data-list.js location. Then, some sort of config could point to that ID to use for that resource ID.At least that was the thinking behind reserving the name. I'm open to thinking about this in a different way. Addressing that first design issue would be the way to start.
guybedford commentedon Feb 19, 2013
I'm not sure I completely follow. Are you saying that the difficulty is in altering the define in the
load.fromTextto use the plugin ID form ofplugin!name, or that it is a feature to be able to build the name ID since it is more compatible with builds?jrburke commentedon Feb 19, 2013
The choice was done to explicitly use the JS ID for the fromText evaluation, because I though transpilers might want to output transformed code to the dependencyId.js location.
Looking more into this, the text plugin can write out .js resources, although what I did there was to create the JS form at
example.html.jsinstead ofexample.js. So perhaps that is what the suggested path for transpilers should be. For instance, for a coffeescript one,example.coffeeis saved asexample.coffee.js.The tricky part is communicating that knowledge to the loader or the loader plugin after a build. Perhaps that is just map config:
With that, then maybe the loader can just swap in the load.fromText definition for the 'cs!example' ID in the non-build case. Although loader plugins would need to then remove the require() they used to do at the end of their load functions to then bind to the resource:
https://github.com/jrburke/require-cs/blob/master/cs.js#L152
that pattern is already deprecated in 2.1 -- the loader does that internally now, and only allows fromText to be called once and it is associated with the 'cs!example' ID automatically (but just not explicitly bound).
So I that might work out, but given the hard deprecation/force of change for transpiler plugins, putting this in the 2.2.0 bucket.
guybedford commentedon Feb 20, 2013
From a build perspective, I would think it is worth strongly advising against loading non-layered scripts in production. The reason being that loading a combined layer is always more efficient than loading files separately.
So when I run builds, I expect all resources to be built into layers that have a chance of being used. During production testing, any layers that load say CoffeeScript could still work by downloading the CoffeeScript compiler, but these should ultimately be mapped to a layer I would have thought. Thus, I always imagine the
fromTextdefining into the plugin ID itself, and not some derived ID, and for that built file to always be loaded as part of a larger layer.It seems I've had the incorrect picture though - understanding this plugin scenario (which I was previously never aware of) has finally made the
writeFileplugin hook click. I've read that over and over and never understood that it transpiled to a js file like that!That's my current perspective, although there may well be cases, where loading individual files in this way is entirely necessary say for loading configuration files etc. It seems the way things are set up is far more flexible and open to the most customisation, which is a good thing.
So one could either remove this build flexibility, which should be carefully considered or otherwise your solution sounds perfect.
guybedford commentedon Mar 27, 2013
I have included code in the transpiler base to automatically load from '.js' extensions where 'precompiled' paths prefixes have been set.
When stubbing the module entirely, that would imply that all paths have been precompiled. But at the moment, a stub module won't know that a file 'cs!some-module' should be found at 'some-module.coffee.js'.
In order to allow this I would suggest a convention that can be used to allow for this and avoid these name conflicts:
So
{moduleID}.{pluginID}.jsLet me know if that sounds sensible. It would solve the issues above quite nicely avoiding name conflicts and working with builds.
jrburke commentedon Jun 11, 2013
Follow up on this: I do not want to ban "loading non-layered scripts in production", so I want to get this to work for that scenario too.
Some more motivation for fixing this ticket: #765 points out an issue with trying to use "cs!something" and "hbr!something" -- if both are transpilers, the load.fromText thing I think is messing things up.
I really do not like needing an "after build" switch to either map the compiled output to the plugin resource ID or some other switch.
This may not work out, but maybe I can just bind load.fromText to really just assign to the full plugin resource ID instead of doing the current fromText route, and look at maybe look at write.asModule doing the same thing. I am going off partial memory, and I just skimmed this ticket again, so there is probably an issue with that, but going to temporarily put this in the 2.1.7 bucket. It could very easily get pushed back to 2.2.0.
jrburke commentedon Jul 7, 2013
Going to push to 2.2.0. Main issues: