jooking / closure-library

Automatically exported from code.google.com/p/closure-library
Apache License 2.0
0 stars 0 forks source link

calcdeps forces base path to base.js location #188

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
An issue was created addressing calcdeps sensitivity to running location:
http://code.google.com/p/closure-library/issues/detail?id=139

It was fixed in r134:
http://code.google.com/p/closure-library/source/detail?r=134

However, it is not always that case that base path should be located with 
base.js. This is the reason that base.js has the CLOSURE_BASE_PATH hook.

There should be a way to specify the base path

A patch file implementing the proposed change has been attached

Original issue reported on code.google.com by jordan.c...@gmail.com on 14 Jul 2010 at 11:08

Attachments:

GoogleCodeExporter commented 9 years ago
Can you elaborate on your use case?

the CLOSURE_BASE_PATH hook is fairly esoteric, and rarely used. In fact, most 
of the time that I've seen people use it, they used it incorrectly and just 
ended up masking real problems.

Original comment by Nicholas.J.Santos on 15 Jul 2010 at 4:02

GoogleCodeExporter commented 9 years ago

My requirements are:
1) I can not mess with the folder hierarchy that has already been established 
in our project. Our js files are very modular, separated with 
one-class-per-file and organized in a way similar to java packages
2) I want to take advantage of the dependency management system in our library

The hierarchy of the project is as follows:
/Scripts/
    buildScript1.py
    buildScript2.py 
/www/
    index.html
    img/
        ourImages...
    css/
        cssFiles...
    flash/
        src/
            ourLibrary...
        lib/
            otherFlashLibs...
        bin/
            compiled.swf
    javascript/
        src/
            ourLibrary...
        lib/
            closure-library/
        bin/
            compiled.js

In my initial attempts I directed calcdeps to generate a deps.js file using our 
javascript/src as the path and got an error to the effect of:
"can't find base.js"

I had to include a second path (-p javascript/lib/closure-library) before it 
would work, which seems unnecessary. This made deps.js very large as it 
included the entire Closure library as well as our large library. Also, the 
generated script tag for our files was referenced WRT base.js. Ideally, this 
would not be the case.

With my modification, all of these issues are resolved and leaves the 
re-assignment of the base path as an option (as is the case with 
CLOSURE_BASE_PATH). However, if there is a better way of doing this, I would 
love to know.

Also, I intend on compiling the entire app with the closure compiler (simple 
optimizations initially - advanced breaks our stuff). So I need to prepare for 
that.

Original comment by jordan.c...@gmail.com on 15 Jul 2010 at 4:46

GoogleCodeExporter commented 9 years ago
Instead of "-p javascript/lib/closure-library", try just doing "-d 
javascript/lib/closure-library". Calcdeps needs to be able to scan those 
symbols so that it can resolve references to them, but should not generate the 
dependency graph for them.

Then, you can just leave CLOSURE_BASE_PATH alone. If you add a link from your 
html pages to javascript/lib/closure-library/base.js and path/to/your/deps.js, 
the bootstrapping logic should "just work" out of the box. your directory 
structure is similar to my project's.

how does that work?

Original comment by Nicholas.J.Santos on 15 Jul 2010 at 5:29

GoogleCodeExporter commented 9 years ago
I ended up using "-d lib/closure-library" and "-p ./src". That did create a 
more svelte deps.js, however if I am including base.js as is, that means I am 
also including the deps.js located in the closure base path. But this is 
probably fine. Also, my script tags end up with paths looking like:
"/libs/closure-library/closure/goog/../../../../src/gc/ns1/Class1.js"
A bit obscure, bit still valid.

Since you have a similar structure, how does this affect calcdeps when using 
the "-o compiled" switch? Any recommendations?

Original comment by jordan.c...@gmail.com on 15 Jul 2010 at 6:18

GoogleCodeExporter commented 9 years ago
i haven't set this up for a while, but i think that when you use the -o 
compiled switch, you use -p lib/closure-library and --i ./src.

It should be smart enough to include all of ./src, and only the things in 
closure-library that ./src depends on.

Original comment by Nicholas.J.Santos on 15 Jul 2010 at 4:01

GoogleCodeExporter commented 9 years ago
yea, I got it compiling with "-p lib/closure-library". I find it a bit odd that 
-d is only used with "-o deps", it could be used in this case too...

Getting back to the issue:
Should there be a way to manually override the base path for the library. If 
"base path" is defined as: "the point upon which all paths in the deps.js file 
are referenced from", then there probably should be. However, if the definition 
is: "the location of base.js", then there is no need. However I think the first 
definition offers more flexibility (when considered with CLOSURE_BASE_PATH)

Original comment by jordan.c...@gmail.com on 16 Jul 2010 at 5:55

GoogleCodeExporter commented 9 years ago
I think CLOSURE_BASE_PATH is supposed to be "the location of base.js". Because 
base.js contains the code for bootstrapping other files, it's easier to think 
about the deps files as "relative to base.js". I think it's only necessary to 
change BASE_PATH when people have forked base.js in some non-trivial way.

Original comment by Nicholas.J.Santos on 17 Jul 2010 at 9:30

GoogleCodeExporter commented 9 years ago
i think that giving an option to control this would likely cause far more 
problems and confusion than it would solve, so i'm closing this bug.

Original comment by Nicholas.J.Santos on 28 Jul 2010 at 4:19

GoogleCodeExporter commented 9 years ago
Fair enough, in fact I probably wouldn't have even posted this bug if the '-d' 
switch was documented here, like the rest of the options:
http://code.google.com/closure/library/docs/calcdeps.html#opts

Original comment by jordan.c...@gmail.com on 28 Jul 2010 at 6:18

GoogleCodeExporter commented 9 years ago
So this is the official API f the depswriter.py script?

public/closure-library/closure/bin/build/depswriter.py --root_with_prefix="src 
../../../../src/" --root_with_prefix="public/closure-library/ 
../../../../public/closure-library/" > deps.js

That is, I basically have to come up with the relative path from base.js myself?

Original comment by elsdoer...@gmail.com on 28 Aug 2013 at 5:33