Skip to content

Commit

Permalink
fix(CLI): get rid of Browserify absolute path workaround
Browse files Browse the repository at this point in the history
We encountered a Browserify bug when releasing the CLI, where absolute
paths would be hard-coded in the final bundle. Since we were in the
middle of a release process, we added a quick and dirty
search-and-replace workaround on `concatenate-javascript.sh`.

After the release, we submitted a PR to Browserify which fixes the
issue. This commit makes use of my personal fork to be able to use such
fix while it gets merged to the main project.

See: browserify/browserify#1725
See: #1409
Fixes: #1429
Signed-off-by: Juan Cruz Viotti <jviotti@openmailbox.org>
  • Loading branch information
Juan Cruz Viotti committed May 17, 2017
1 parent 57e29a5 commit 23e5a0a
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 59 deletions.
88 changes: 53 additions & 35 deletions npm-shrinkwrap.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Expand Up @@ -115,7 +115,7 @@
"devDependencies": {
"angular-mocks": "1.6.3",
"asar": "^0.10.0",
"browserify": "^13.0.1",
"browserify": "github:jviotti/node-browserify#dynamic-dirname-filename",
"electron": "1.6.6",
"electron-builder": "^2.6.0",
"electron-mocha": "^3.1.1",
Expand Down
27 changes: 4 additions & 23 deletions scripts/build/concatenate-javascript.sh
Expand Up @@ -55,29 +55,10 @@ if [ -z "$ARGV_ENTRY_POINT" ] ||
usage
fi

"$BROWSERIFY" "$ARGV_BASE_DIRECTORY/$ARGV_ENTRY_POINT" --node --outfile "$ARGV_OUTPUT"

# This hack workarounds the fact the Browserify stores absolute paths
# of the machine that was used to produce the bundle, giving "not found"
# module errors when executing it in another computer.
# The fix is to replace absolute paths with `__dirname`
node <<EOF > "$ARGV_OUTPUT.TMP"
const separator = process.platform === 'win32' ? '\\\\\\\\\\\\\\\\' : '\\/';
const baseDirectory = process.platform === 'win32'
? "$ARGV_BASE_DIRECTORY".replace(/\//g, separator)
: "$ARGV_BASE_DIRECTORY";
const regex = new RegExp('"(.)+' + baseDirectory.replace(/\+/g, '\\\\+') + separator, 'g');
const contents = require('fs').readFileSync("$ARGV_OUTPUT", { encoding: 'utf8' });
console.log(contents.split('\n').map((line) => {
if (!regex.test(line)) return line;
return line
.replace(regex, 'require("path").join(__dirname,"')
.replace(new RegExp(separator, 'g'), '","') + ')';
}).join('\n'));
EOF
mv "$ARGV_OUTPUT.TMP" "$ARGV_OUTPUT"
"$BROWSERIFY" "$ARGV_ENTRY_POINT" \
--node \
--basedir "$ARGV_BASE_DIRECTORY" \
--outfile "$ARGV_OUTPUT"

if [ "$ARGV_MINIFY" == "true" ]; then
./scripts/build/check-dependency.sh uglifyjs
Expand Down

0 comments on commit 23e5a0a

Please sign in to comment.