cujojs / curl

curl.js is small, fast, extensible module loader that handles AMD, CommonJS Modules/1.1, CSS, HTML/text, and legacy scripts.
https://github.com/cujojs/curl/wiki
Other
1.89k stars 216 forks source link

Syntax or http error when upgrading from 0.6.2 to 0.7.0 #143

Closed dizzib closed 11 years ago

dizzib commented 11 years ago

I'm currently on v0.6.2 of the kitchen-sink dist curl.js which is working fine with the following config:

curl = {
    baseUrl:        '.',
    paths: {
        curl:           'lib.3p/cujojs/curl',
        jquery:         'lib.3p/jquery-1.8.2.min',
        knockout:       'lib.3p.extension/knockout',
        modernizr:      'lib.3p.extension/modernizr',
        sizzle:         'lib.3p/sizzle.min',
        underscore:     'lib.3p/underscore.min'         // TODO https://github.com/unscriptable/underscore/downloads!
    },
    packages: [
            { name:'aop', path:'lib.3p/cujojs/wire/aop', main:'./' },
            { name:'when', path:'lib.3p/cujojs/when', main:'./when' },
            { name:'wire', path:'lib.3p/cujojs/wire', main:'./wire' }
    ]
};

When I upgrade to curl v0.7.0 I get the following error:

Syntax or http error: ./lib.3p/cujojs/curl/plugin/wire.js

Seems it's now looking in the wrong place for wire.js (which is actually located at lib.3p/cujojs/wire.js) but there's no mention of curl/plugin path anywhere in my project!

Any ideas ? Ta, Andy.

pluma commented 11 years ago

It's looking for the wire plugin, not wire.js itself. Check the dependencies of your packages. Do any of them begin with wire!? It's expecting to find the wire plugin at that URL because you aliased curl to lib.3p/cujojs/curl (and the default plugin path is curl/plugin).

dizzib commented 11 years ago

Hi aspq! The only reference to 'wire!' in my entire project is this code:

curl('lib.boot').next('wire!app.wire').then _init, _abort

Thanks for the clarification. I believe the dist version of curl.js contains the wire plugin compiled in, but I'm struggling to find the relevant source code and/or mechanism.

Cheers, Andy.

unscriptable commented 11 years ago

Hey @dizzib!

Yes, there's an issue in 0.7.0 we're fixing. The current dev branch has a fix for the problem, but it also breaks plugin-specific configs. If you don't know what "plugin-specific configs" means or are sure you're not using them, then feel free to use the dev branch for now. :)

Fwiw, we may skip 0.7.1 and go straight to 0.8.0 which makes the configuration of packages, paths, and plugins much more consistent.

I believe the dist version of curl.js contains the wire plugin compiled in It does not. The wire plugin is within wire/wire.js itself. The fact that it's a main module and a plugin was the crux of the problem.

-- John

unscriptable commented 11 years ago

Just looking at your code. Interesting configuration for turning the wire/aop module into a package.

{ name:'aop', path:'lib.3p/cujojs/wire/aop', main:'./' }

Let me know if that still works in 0.7.x. I don't think I have a test case for that. More importantly, have you ensured that the file isn't downloaded twice?

dizzib commented 11 years ago

@unscriptable thanks for the clarification! I'll wait for 0.8.0 since there's no rush on my side.

That aop config is the only way I could get things to work with this wire spec:

plugins: [
    { module: 'wire/aop' }
]

According to the browser diags, aop.js only gets downloaded once. It's entirely possible I'm doing this wrong !?

unscriptable commented 11 years ago

hm. You shouldn't have to map a path to 'aop' if you're only using 'wire/aop' in specs. Do you have specs or modules that explicitly specify 'aop' (vs 'wire/aop')?

dizzib commented 11 years ago

I don't have any refs to 'aop' vs 'wire/aop'. Curl gives a 404 for aop.js if I remove this line:

{ name:'aop', path:'lib.3p/cujojs/wire/aop', main:'./' },

64 contains my previous attempts to tweak the config.

briancavalier commented 11 years ago

It sounds like there's not a problem with wire/aop here, but I figured I would take the opportunity shed a little light on what's possibly a confusing situation with the name "aop" in cujojs. The confusion will hopefully go away when wire 0.9 is released.

There are 2 things in cujojs named aop.js. The first is the AOP library formerly known as "aop", but recently renamed to "meld" (partly to avoid this name confusion!). The second is wire's AOP plugin, typically referred to as "wire/aop". In versions of wire <= 0.8.x, wire/aop (the plugin) uses aop (the library), and so lists "aop" in its AMD dependency list.

What that means is that curl needs to be configured so that the module id "aop" points to aop the library, and that "wire/aop" points to wire/aop the plugin. Typically, but not always, a package config that contains the following two things will do the trick:

packages: [
    // Configure aop the library
    { name: 'aop', location: 'path/to/dir/containing/aop', main: 'aop' },
    // Configure wire, which includes the wire/aop plugin
    { name: 'wire', location: 'path/to/dir/containing/wire', main: 'wire' },
    // ... more packages
]

Where your dir structure would look like:

path/to/dir/containing/
    wire/
        wire.js
        aop.js (the wire plugin)
        ... other wire files
    aop/
        aop.js (the aop library)
        ... other aop files

Then, in a wire spec, you should be able to load wire's aop plugin:

plugins: [
    // Load wire's aop plugin
    // Internally, the plugin will load aop the library
    { module: 'wire/aop' }
]

Again, it seems like this is not a problem for @dizzib (even though your config looks as if perhaps you've placed aop (the library) inside the wire directory?). I just felt it was worth trying to shed some light on the two "aop" names :)

dizzib commented 11 years ago

Hi Brian and thanks for that explanation. My cujojs folder looks like this:

/cujojs
    wire.js
    /wire
        aop.js (the wire plugin)

The aop library doesn't exist in this folder so in theory wire/aop plugin should fail. However I'm using wire/aop just for introductions and looking at the source, I suspect the aop library is not invoked at all for this purpose.

Which might explain why things are working for me when they shouldn't be :)

unscriptable commented 11 years ago

Try with version 0.7.1. There were some issues with wire that are now fixed. :) -- John

dizzib commented 11 years ago

Thanks John. Unfortunately I'm now getting the following error with 0.7.1:

Syntax or http error: ./lib.3p/cujojs/wire/wire.js

I can fix this by truncating my packages paths like so:

packages: [
        { name:'aop', path:'lib.3p/cujojs', main:'./aop' },
        { name:'when', path:'lib.3p/cujojs', main:'./when' },
        { name:'wire', path:'lib.3p/cujojs', main:'./wire' }
]

but this causes wire to miss the 'wire/aop' plugin (please note I've now put the aop.js library at lib.3p/cujojs/aop.js, following Brian's explanation above)

Also, I have some code which adds a path at runtime, but this no longer seems to work in 0.7.1:

_.extend curl_cfg.paths, { plugin:PluginPath.value() }
curl curl_cfg

Finally, I notice css plugins '!order' directive now causes load failure. Removing '!order' bypasses this problem.

Cheers! Andy.

unscriptable commented 11 years ago

Hey Andy,

packages: [
        { name:'aop', path:'lib.3p/cujojs', main:'./aop' },
        { name:'when', path:'lib.3p/cujojs', main:'./when' },
        { name:'wire', path:'lib.3p/cujojs', main:'./wire' }
]

This configuration looks correct. However, I think we've miscommunicated about the location of wire's aop plugin. It should stay under the wire folder.

To be clear, there should be two aop.js files: 1) the wire plugin, and 2) the package/library. The plugin resides at lib.3p/cujojs/wire/aop.js, the package at lib.3p/cujojs/aop/aop.js

Also, I have some code which adds a path at runtime, but this no longer seems to work in 0.7.1

_.extend curl_cfg.paths, { plugin:PluginPath.value() }
curl curl_cfg

Just a minor point: you don't have to extend the paths externally. curl will do this internally (but may modify the object you hand it to "normalize" it). This should work:

curl { paths: { moduleID: "path/to/somewhere" } }

Do you actually, have a plugin called "plugin" or is that standing in for something else?

Finally, I notice css plugins '!order' directive now causes load failure. Removing '!order' bypasses this problem.

The css! plugin doesn't support the !order directive. That's just for the js! plugin. Hm, but it shouldn't fail. I'll look into this.

unscriptable commented 11 years ago

OT: we've got a new cujojs/quickstart repo that shows a sample folder layout and AMD config: https://github.com/cujojs/quickstart

dizzib commented 11 years ago

Hi John, thanks for your help but unfortunately I'm still having issues with 0.7.2 :(

The plugin resides at lib.3p/cujojs/wire/aop.js, the package at lib.3p/cujojs/aop/aop.js

Here's my folder structure:

lib.3p
    cujojs
        aop
            aop.js      <-- aop library v0.5.3 (10Kb)
        wire
            aop.js      <-- wire plugin (7Kb)
        wire.js         <-- v0.8.2

Aop now fails silently i.e. my introductions don't get applied but there's no error from curl or wire.

However I've discovered a workaround by amending the module in the wire spec to be more explicit, from:

    { module: 'wire/aop' }

to:

    { module: 'lib.3p/cujojs/wire/aop' }

you don't have to extend the paths externally. curl will do this internally

I'm unable to get this to work. For example, the following code seems to blat any paths already there, resulting in subsequent 'Syntax or http' errors.

curl { paths: { foo:'bar' } }

Do you actually, have a plugin called "plugin" or is that standing in for something else?

My app has it's own concept of plugin, not to be confused with curl plugins! The idea is my app can load different plugins at runtime.

The css! plugin doesn't support the !order directive.

No probs since I don't need this, but css order can matter when specificities are identical AFAIK.

Cheers!

dizzib commented 11 years ago

I've just spotted my wire.js may be in the wrong place. I'll try putting it into the /wire directory on Monday. Ta!

unscriptable commented 11 years ago

Ha ha! I didn't even notice!

Your config should look like this:

packages: [
        { name:'aop', path:'lib.3p/cujojs/aop', main:'./aop' },
        { name:'when', path:'lib.3p/cujojs/when', main:'./when' },
        { name:'wire', path:'lib.3p/cujojs/wire', main:'./wire' }
]

And your folder structure should look like this:

lib.3p
    cujojs
        aop
            aop.js
        when
            when.js
        wire
            wire.js       
            aop.js // and other stuff

Each package wants to be in it's own folder. :)

-- J

dizzib commented 11 years ago

Yes, it took me a while to spot, doh :)

After much head scratching, I fixed the non-load of the aop library by upgrading wire to 0.9.0 and fixing the folder structure as per your last post above.

Note my config does look slightly different:

packages: [
        { name:'meld', path:'lib.3p/cujojs/meld', main:'meld' },
        { name:'when', path:'lib.3p/cujojs/when', main:'when' },
        { name:'wire', path:'lib.3p/cujojs/wire', main:'wire' }
]

Anyway, I'm happy to say my original issue is now fixed.

Thanks! Andy.