Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Require-CS not working with Cajon #13

Closed
skyrpex opened this issue Aug 8, 2014 · 3 comments
Closed

Require-CS not working with Cajon #13

skyrpex opened this issue Aug 8, 2014 · 3 comments

Comments

@skyrpex
Copy link

skyrpex commented Aug 8, 2014

Is it possible that Cajon doesn't use the cs! plugin to parse a .coffee file before reading it's dependencies?

@jrburke
Copy link
Member

jrburke commented Aug 8, 2014

Cajon just allows using CommonJS syntax for a module API. So, like the AMD sugar syntax just without the define() wrapper. It does not assume or shim anything around how Node handles ID resolution. In particular, it does not do the require.extensions thing that Node does to handle different code types, like coffeescript (side note, that would be extremely expensive for a front-end browser loader, doing multiple network fetches, many that would be 404s).

If you have coffeescript in the project, then the dependency IDs need to have 'cs!' prefixes for the coffeescript files, if they are to be handled by require-cs (and have require-cs installed in the project).

I believe that is the core of the question, so closing as a discussion ticket. So feel free to continue discussion here, just closing to indicate a bug fix does not need to be scheduled.

@jrburke jrburke closed this as completed Aug 8, 2014
@skyrpex
Copy link
Author

skyrpex commented Aug 9, 2014

I'm sorry, my description was so vague that I didn't explain myself. I think there's a bug when Cajon reads the dependency list of a module. Here is a minimal complete example.

bower.json

{
  "name": "cajon-test",
  "dependencies": {
    "require-cs": "~0.5.0",
    "cajon": "~0.2.4"
  }
}

index.html

<html>
<head>
    <script src="bower_components/cajon/cajon.js"></script>
    <script>
    requirejs.config({
        paths: {
            cs: 'bower_components/require-cs/cs',
            'coffee-script': 'bower_components/coffeescript/extras/coffee-script'
        },
        // Convenient shim for CoffeeScript
        shim: { 'coffee-script': { deps: [] } }
    });

    require(['cs!main']);
    </script>
</head>
<body>
</body>
</html>

main.coffee

console.log 'Main'
require 'cs!./dep'

dep.coffee

console.log 'Dep'

If you run this example, you will see Uncaught Error: fromText eval for cs!main failed: Error: Module name "cs!dep" has not been loaded yet for context: _. Use require([]).

Cajon didn't load dep.coffee before executing main.coffee. If you convert main.coffee to it's JS equivalent, it works just fine.

@skyrpex
Copy link
Author

skyrpex commented Aug 20, 2014

@jrburke There's an example above that reproduces the problem, if you want to take a look...

Thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants