Skip to content

Commit

Permalink
fix(builtin): use a local mod to revert a browserify change
Browse files Browse the repository at this point in the history
This is needed so that --preserve-symlinks browserify option also applies to the main
  • Loading branch information
alexeagle committed Jul 12, 2019
1 parent 1753ed5 commit 253e9cb
Show file tree
Hide file tree
Showing 7 changed files with 20 additions and 10 deletions.
3 changes: 2 additions & 1 deletion internal/npm_install/browserify-wrapped.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,14 +36,15 @@ browserify-wrapped: running with

// browserify is ncc bundled & terser minified into third_party
const browserify = require.resolve(
'build_bazel_rules_nodejs/third_party/github.com/browserify/browserify/index.min.js');
`build_bazel_rules_nodejs/third_party/github.com/browserify/browserify/index.${DEBUG ? '' : 'min.'}js`);

// named-amd plugin is vendored in under third_party
const namedAmd = require.resolve(
'build_bazel_rules_nodejs/third_party/github.com/jhermsmeier/browserify-named-amd/named-amd.js');

const args = [
browserify, entryPoint,
'--preserve-symlinks',
// Supply the name to use for the AMD define with named-amd plugin
'-p', '[', namedAmd, '--name', packageName, ']',
// Output a stand-alone UMD bundle. Sanitized version the supplied name is used for
Expand Down
10 changes: 8 additions & 2 deletions internal/npm_install/test/browserify.spec.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
const fs = require('fs');
const path = require('path');
const mainFile = 'build_bazel_rules_nodejs/third_party/github.com/browserify/browserify/index.min.js';
const directory = 'build_bazel_rules_nodejs/internal/npm_install/test';

describe('our bundled, vendored browserify binary', () => {
it('should preserve licenses', () => {
Expand All @@ -9,12 +11,16 @@ describe('our bundled, vendored browserify binary', () => {
expect(idxFile).toContain('The Dojo Foundation');
});
it('should have a named AMD module', () => {
const minimistUmd = require.resolve('build_bazel_rules_nodejs/internal/npm_install/test/minimist.umd.js');
const minimistUmd = require.resolve(path.join(directory, 'minimist.umd.js'));
expect(fs.readFileSync(minimistUmd, {encoding: 'utf-8'})).toContain(`define('minimist'`);
});
it('should work', () => {
const minimist = require('build_bazel_rules_nodejs/internal/npm_install/test/minimist.umd.js');
const minimist = require(path.join(directory, 'minimist.umd.js'));
const result = minimist('h');
expect(result._[0]).toBe('h');
});
it('should work for package that imports built-ins ' +
'(regression test for #771)', () => {
const coreUtilIsUmd = require(path.join(directory, 'core-util-is.umd.js'));
});
});
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
"@bazel/ibazel": "0.10.1",
"@commitlint/cli": "^8.0.0",
"@commitlint/config-conventional": "^8.0.0",
"@zeit/ncc": "0.20.2",
"@zeit/ncc": "^0.20.4",
"bazel_workspaces": "file:./tools/npm_packages/bazel_workspaces",
"browserify": "16.2.3",
"clang-format": "1.2.2",
Expand Down
3 changes: 3 additions & 0 deletions scripts/vendor_browserify.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ set -eu -o pipefail
echo "Compiling browserify with ncc"
./node_modules/.bin/ncc build node_modules/browserify/bin/cmd.js -o third_party/github.com/browserify/browserify

echo "Local mod: revert https://github.com/browserify/browserify/pull/1801"
sed -i 's#parent.id !== self._mdeps.top.id#parent.id#' third_party/github.com/browserify/browserify/index.js

echo "Copy LICENSE"
cp -f ./node_modules/browserify/LICENSE ./third_party/github.com/browserify/browserify

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24936,7 +24936,7 @@ Browserify.prototype._createDeps = function (opts) {
}
if (err) cb(err, file, pkg)
else if (file) {
if (opts.preserveSymlinks && parent.id !== self._mdeps.top.id) {
if (opts.preserveSymlinks && parent.id) {
return cb(err, path.resolve(file), pkg, file)
}

Expand Down

Large diffs are not rendered by default.

8 changes: 4 additions & 4 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -245,10 +245,10 @@
dependencies:
"@types/node" "*"

"@zeit/[email protected].2":
version "0.20.2"
resolved "https://registry.yarnpkg.com/@zeit/ncc/-/ncc-0.20.2.tgz#5f5f67b51d6bd1f92e334c4aeed799dc9625a459"
integrity sha512-pLc/iJ68//djAW3jE2xMm5vauAuN0wuq9bv4ha/AAlVOBhJXHrx7GBo8SITTZq11nT8wWzYrY0eotw4UfZBiiw==
"@zeit/ncc@^0.20.4":
version "0.20.4"
resolved "https://registry.yarnpkg.com/@zeit/ncc/-/ncc-0.20.4.tgz#00f0a25a88cac3712af4ba66561d9e281c6f05c9"
integrity sha512-fmq+F/QxPec+k/zvT7HiVpk7oiGFseS6brfT/AYqmCUp6QFRK7vZf2Ref46MImsg/g2W3g5X6SRvGRmOAvEfdA==

JSONStream@^1.0.3, JSONStream@^1.0.4:
version "1.3.5"
Expand Down

0 comments on commit 253e9cb

Please sign in to comment.