Changes between Version 1 and Version 2 of Ticket #16414, comment 14


Ignore:
Timestamp:
Mar 27, 2013, 2:56:12 AM (8 years ago)
Author:
ben hockey
Comment:

Legend:

Unmodified
Added
Removed
Modified
  • Ticket #16414, comment 14

    v1 v2  
    1 i have a possible solution:
    2 
    3 {{{#!diff
    4 diff --git a/node.js b/node.js
    5 index f33d8ae..fdd8dcf 100644
    6 --- a/node.js
    7 +++ b/node.js
    8 @@ -3,6 +3,8 @@ define(["./has"], function(has){
    9         throw new Error("node plugin failed to load because environment is not Node.js");
    10     }
    11  
    12 +   var pathUtil = require.nodeRequire("path");
    13 +
    14     return {
    15         // summary:
    16         //      This AMD plugin module allows native Node.js modules to be loaded by AMD modules using the Dojo
    17 @@ -39,9 +41,21 @@ define(["./has"], function(has){
    18             })(id, require.nodeRequire));
    19         },
    20  
    21 -       normalize: function (/**string*/ id) {
    22 -           if (id.charAt(0) === '.') {
    23 -               id = require.baseUrl + id;
    24 +       normalize: function(/**string*/ id, /*Function*/ normalize){
    25 +           // summary:
    26 +           //      Produces a normalized id to be used by node. Relative ids are resolved relative to the requesting
    27 +           //      module's location in the filesystem and will return an id with path separators appropriate for
    28 +           //      the local filesystem.
    29 +
    30 +           if (id.charAt(0) === '.'){
    31 +               // dirname of the reference module - normalized to match the local file system
    32 +               var referenceModuleDirname = require.toUrl(normalize('.')).replace('/', pathUtil.sep);
    33 +               var segments = id.split('/');
    34 +               segments.unshift(referenceModuleDirname);
    35 +               // this will produce an absolute path normalized to the semantics of the underlying
    36 +               // file system.
    37 +               id = pathUtil.join.apply(pathUtil, segments);
    38             }
    39  
    40             return id;
    41 }}}
     1i have a possible solution - see the attached patch