Skip to content

load.fromText to use full plugin moduleID not name moduleID #638

Open

Description

@guybedford

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.

Activity

  1. jrburke commented on Feb 19, 2013

    @jrburke
    Member

    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.

  2. guybedford commented on Feb 19, 2013

    @guybedford
    ContributorAuthor

    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?

  3. jrburke commented on Feb 19, 2013

    @jrburke
    Member

    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:

    'cs!example': 'example.coffee' //loads example.coffee.js
    

    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.

  4. guybedford commented on Feb 20, 2013

    @guybedford
    ContributorAuthor

    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.

  5. guybedford commented on Mar 27, 2013

    @guybedford
    ContributorAuthor

    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:

    'cs!some-module' -> 'some-module.cs.js'
    'cs!some-module.litcoffee' -> 'some-module.litcoffee.cs.js'
    

    So {moduleID}.{pluginID}.js

    Let me know if that sounds sensible. It would solve the issues above quite nicely avoiding name conflicts and working with builds.

  6. jrburke commented on Jun 11, 2013

    @jrburke
    Member

    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.

  7. jrburke commented on Jul 7, 2013

    @jrburke
    Member

    Going to push to 2.2.0. Main issues:

    • 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
    • Need to give more thought on how it works for the pluginMap functionality talked about in Consider allowing map configs for loader plugin resource IDs #497, which is in the 2.2 bucket.
  8. modified the milestone: 2.2.0 on Mar 15, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions