Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 98e8c4a

Browse filesBrowse files
committed
fix main aliasing support
just a quick hack for now, real fix will come when we produce the dep tree
1 parent 1d0f129 commit 98e8c4a
Copy full SHA for 98e8c4a

File tree

Expand file treeCollapse file tree

2 files changed

+23
-10
lines changed
Filter options
Expand file treeCollapse file tree

2 files changed

+23
-10
lines changed

‎lib/builder.js

Copy file name to clipboardExpand all lines: lib/builder.js
+22-9Lines changed: 22 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -818,44 +818,57 @@ function noop(builder, file, str){
818818

819819
function register(builder, file, js){
820820
var main = builder.config.main;
821+
var isMain = main == file;
821822
var orig = file;
822823

823824
// strip ./
824825
if ('./' == file.slice(0, 2)) file = file.slice(2);
825826

826-
// rewrite main to index.js
827-
// so that require() still grabs
828-
// the correct file without aliases
829-
if (file == main) file = 'index.js';
830-
831827
// determine prefix
832828
// TODO: should always be name / version combo
833829
var prefix = builder.root
834830
? builder.config.name
835831
: builder.basename;
836832

837-
838833
// prefix
839834
file = prefix + '/' + file;
840835

836+
// rewrite requires for dependencies,
837+
// and fix relative requires when .main
838+
// is not index.js
841839
js = requires(js, function(require){
842840
var deps = builder.config.dependencies || {};
843841
var path = require.path;
844842
var name = canonicalized(path, deps) || path;
845843
return 'require("' + name + '")';
846844
});
847845

846+
// register the module
848847
if (builder.sourceUrls) {
849-
js = JSON.stringify(js + '//@ sourceURL=' + prefix + '/' + orig);
848+
js = JSON.stringify(js + '//@ sourceURL=' + file);
850849
js = js.replace(/\\n/g, '\\n\\\n');
851-
return 'require.register("' + file + '", Function("exports, require, module",\n'
850+
js = 'require.register("' + file + '", Function("exports, require, module",\n'
852851
+ js
853852
+ '\n));';
854853
} else {
855-
return 'require.register("' + file + '", function(exports, require, module){\n'
854+
js = 'require.register("' + file + '", function(exports, require, module){\n'
856855
+ js
857856
+ '\n});';
858857
}
858+
859+
// main support
860+
// TODO: dear god, this is nasty, doesnt belong
861+
// in here but doing a separate tree walk is lame
862+
// so screw it, works for now, need to rewrite this thing
863+
864+
// once we produce a dep tree first then we can completely
865+
// remove all of this junk, as we'll know what all the mains
866+
// are and can simply rewrite
867+
if (isMain && 'index.js' != orig) {
868+
js += '\nrequire.main("' + prefix + '", "' + orig + '")';
869+
}
870+
871+
return js;
859872
}
860873

861874
/**

‎package.json

Copy file name to clipboardExpand all lines: package.json
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
],
99
"author": "TJ Holowaychuk <tj@vision-media.caa>",
1010
"dependencies": {
11-
"component-require": "1.0.0",
11+
"component-require": "1.0.1",
1212
"batch": "0.2.1",
1313
"mkdirp": "0.3.4",
1414
"debug": "*",

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.