Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Allow for absolute paths for baseUrl #104

Closed
wants to merge 1 commit into from

1 participant

@wombleton

Issues #84 & #85 (and perhaps #45) relate to the need for absolute
paths for baseUrl.

This allows serving the same script references from the url /foo as
well as /foo/:id.

The test in project.js for absolute-ness could be more robust, but
will serve for most cases, with a given value for "most".

@wombleton wombleton Allow for absolute paths for baseUrl
Issues #84 & #85 (and perhaps #45) relate to the need for absolute
paths for `baseUrl`.

This allows serving the same script references from the url `/foo` as
`/foo/:id`.

The test in `project.js` could be more robust, but will serve for most
cases, with a given value for "most".
c6d3f3d
@wombleton

On review this isn't a good solution. I'll need to think about it some more.

@wombleton wombleton closed this
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Nov 26, 2012
  1. @wombleton

    Allow for absolute paths for baseUrl

    wombleton authored
    Issues #84 & #85 (and perhaps #45) relate to the need for absolute
    paths for `baseUrl`.
    
    This allows serving the same script references from the url `/foo` as
    `/foo/:id`.
    
    The test in `project.js` could be more robust, but will serve for most
    cases, with a given value for "most".
This page is out of date. Refresh to see the latest.
Showing with 28 additions and 12 deletions.
  1. +11 −6 lib/commands/install.js
  2. +17 −6 lib/project.js
View
17 lib/commands/install.js
@@ -21,7 +21,8 @@ var semver = require('semver'),
clean = require('./clean'),
async = require('async'),
path = require('path'),
- fs = require('fs');
+ fs = require('fs'),
+ url = require('url');
var pathExists = fs.exists || path.exists;
@@ -117,6 +118,8 @@ exports.run = function (settings, args) {
exports.extendOptions = function (proj_dir, settings, cfg, opt) {
+ var baseUrl;
+
if (!opt.target_dir) {
if (cfg.jam && cfg.jam.packageDir) {
opt.target_dir = path.resolve(proj_dir, cfg.jam.packageDir);
@@ -126,11 +129,13 @@ exports.extendOptions = function (proj_dir, settings, cfg, opt) {
}
}
if (!opt.baseurl) {
- if (cfg.jam && cfg.jam.baseUrl) {
- opt.baseurl = path.resolve(proj_dir, cfg.jam.baseUrl);
- }
- else {
- opt.baseurl = path.resolve(proj_dir, settings.baseUrl);
+ baseUrl = cfg.jam && cfg.jam.baseUrl || settings.baseUrl;
+
+ // if baseUrl is absolute, pass it directly
+ if (baseUrl && (baseUrl.indexOf('/') === 0 || url.parse(baseUrl).protocol)) {
+ opt.baseurl = baseUrl;
+ } else {
+ opt.baseurl = path.resolve(proj_dir, baseUrl);
}
}
return opt;
View
23 lib/project.js
@@ -6,7 +6,6 @@ var utils = require('./utils'),
ncp = require('ncp').ncp,
fs = require('fs');
-
var pathExists = fs.exists || path.exists;
@@ -146,11 +145,23 @@ exports.getAllPackages = function (dir, callback) {
};
exports.updateRequireConfig = function (package_dir, baseurl, callback) {
- var packages = [];
- var shims = {};
+ var packages = [],
+ shims = {},
+ basedir,
+ root;
- var basedir = baseurl ? path.relative(baseurl, package_dir): package_dir;
- var dir = basedir.split(path.sep).map(encodeURIComponent).join('/');
+ if (baseurl) {
+ // if the baseurl doesn't exist it's almost certainly intended as an absolute path
+ // TODO: use param instead to handle edge cases more robust
+ if (baseurl === '/' || !fs.existsSync(baseurl)) {
+ root = baseurl;
+ } else {
+ basedir = path.relative(baseurl, package_dir);
+ root = basedir.split(path.sep).map(encodeURIComponent).join('/');
+ }
+ } else {
+ root = package_dir.split(path.sep).map(encodeURIComponent).join('/');
+ }
exports.getAllPackages(package_dir, function (err, pkgs) {
if (err) {
@@ -161,7 +172,7 @@ exports.updateRequireConfig = function (package_dir, baseurl, callback) {
var cfg = pkg.cfg;
var val = {
name: cfg.name,
- location: dir + '/' + encodeURIComponent(pkg.dir)
+ location: root + '/' + encodeURIComponent(pkg.dir)
};
var main = cfg.main;
if (cfg.browser && cfg.browser.main) {
Something went wrong with that request. Please try again.