coffeescript icon indicating copy to clipboard operation
coffeescript copied to clipboard

compile order in sub-directories

Open brunoimbrizi opened this issue 14 years ago • 6 comments

Compiler seems to follow alphabetical order instead of folder hierarchy. Please consider the following example:

src/App.coffee src/view/B.coffee src/view/a/A.coffee

Where class A extends B.

Compile with this line:

coffee --join js/app.js --compile src/view/ src/App.coffee

This throws an error in the browser:

Uncaught TypeError: Cannot read property 'prototype' of undefined 

If folder a is renamed to z, the error is gone and everything works fine.

Shouldn't the compiler read all files from src/view/ before it moves on to src/view/[sub-dir] ?

brunoimbrizi avatar Jul 11 '12 15:07 brunoimbrizi

I had the same problem. But I think ordering by folder won't fix all the dependency problems.

for example in this case: src/errors/BigError.coffee src/errors/Error.coffee

where BigError extends Error

You will got the same error from the browser. Is there a right solution for that?

bkris avatar Aug 08 '12 12:08 bkris

@bkris I'm having the same issue, wondering if there is a solution. ie: a way to set a preference in the compile order

Tolmark12 avatar Sep 21 '12 22:09 Tolmark12

+1 This is a minor problem for me, I get around it by using ugly numeric prefixes in filenames

sgb-io avatar Sep 30 '12 15:09 sgb-io

+1 similar to what samuelgbrown does, except the ugly numeric prefixes are used to group files. 00 group files go first and among them order does not matter. The next group prefix is 10, then 20. This also allows files to be inserted between later, e.g 05 prefix for a file that should be put between 00 and 10.

ghost avatar Oct 31 '12 07:10 ghost

I have a project that solves this problem by using Sprockets-like directives. It allows you to use things like

###
= require 'somefile'
= requireTree 'someDirectory'
= requireself
= require 'someotherfile'
###

And will compile/concat (and optionally compress) in the correct order, resolving all dependencies from included files.

Let me know if there is interest and I'll type of some examples in the README. The project is currently lacking docs but you can (see it here)[https://github.com/caseywebdev/xl8].

caseywebdev avatar Oct 31 '12 13:10 caseywebdev

This can be resolved using modules, CommonJS, or tools like Gulp or Webpack or Browserify. It is out of scope for the CoffeeScript compiler.

GeoffreyBooth avatar Apr 28 '17 23:04 GeoffreyBooth