Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Windows support - Revision to #137 and #126 #144

Closed
wants to merge 3 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 12 additions & 9 deletions lib/wrap.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,14 @@ module.exports = function (opts) {
};

function Wrap (opts) {
if (opts.cache === undefined && process.env.HOME !== undefined) {
var home = process.env.HOME || process.env.USERPROFILE;
if (opts.cache === undefined && home) {
opts.cache = true;
}

if (opts.cache) {
if (typeof opts.cache === 'boolean') {
var file = process.env.HOME + '/.config/browserify/cache.json';
var file = home + '/.config/browserify/cache.json';
this.detective = deputy(file);
}
else {
Expand Down Expand Up @@ -159,7 +160,7 @@ Wrap.prototype.addEntry = function (file, opts) {

this.entries[file] = this.appends.length;

var target = opts.target || file.slice(dir.length);
var target = opts.target || file.slice(dir.length).replace(/\\/g, '/');
this.append((self.debug ? wrappers.entry_debug : wrappers.entry)
.replace(/\$__filename/g, function () {
return JSON.stringify(target)
Expand Down Expand Up @@ -274,22 +275,24 @@ Wrap.prototype.reload = function (name) {
};

function makeTarget (file, root) {
var base = path.resolve(__dirname, '..');
var base = path.resolve(__dirname, '..').replace(/\\/g, '/');
var nm = base + '/node_modules/';
file = file.replace(/\\/g, '/');
var s = file.slice(0, nm.length);

var result = '';

if (isPrefixOf(root + '/', file)) {
return path.normalize('/' + file.slice(root.length + 1));
return path.normalize('/' + file.slice(root.length + 1)).replace(/\\/g, '/');
}
else if (resolve.isCore(file) || !file.match(/^\//)) {
return path.normalize(file);
else if (resolve.isCore(file) || !file.match(/^\s*([a-zA-Z]:)?\//)) {
return path.normalize(file).replace(/\\/g, '/');
}
else if (s === nm && /^\/[^\/]+-browserify/.test(s)
&& file.slice(s.length), /^[^\/]+-browserify/.test(file.slice(s.length))) {
return file.slice(base.length);
}
else if (file.match(/\/node_modules\/.+/)) {
return path.normalize(file.match(/.*(\/node_modules\/.+)/)[1]);
return path.normalize(file.match(/.*(\/node_modules\/.+)/)[1]).replace(/\\/g, '/');
}
else {
throw new Error('Can only load non-root modules'
Expand Down