Skip to content

Commit

Permalink
fix: Lazily import git-rev-sync in non-production (#1972)
Browse files Browse the repository at this point in the history
  • Loading branch information
Rob--W committed Jul 24, 2020
1 parent fc91c36 commit a99313c
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 6 deletions.
13 changes: 10 additions & 3 deletions package-lock.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 @@ -73,7 +73,6 @@
"firefox-profile": "2.0.0",
"fs-extra": "9.0.1",
"fx-runner": "1.0.13",
"git-rev-sync": "2.0.0",
"import-fresh": "3.2.1",
"mkdirp": "1.0.4",
"multimatch": "4.0.0",
Expand Down Expand Up @@ -116,6 +115,7 @@
"eslint-plugin-flowtype": "5.2.0",
"eslint-plugin-import": "2.22.0",
"flow-bin": "0.129.0",
"git-rev-sync": "2.0.0",
"html-entities": "1.3.1",
"mocha": "8.0.1",
"nyc": "15.1.0",
Expand Down
6 changes: 5 additions & 1 deletion src/program.js
Expand Up @@ -5,7 +5,6 @@ import {readFileSync} from 'fs';

import camelCase from 'camelcase';
import decamelize from 'decamelize';
import git from 'git-rev-sync';
import yargs from 'yargs';
import { Parser as yargsParser } from 'yargs/yargs';

Expand Down Expand Up @@ -353,6 +352,11 @@ export function defaultVersionGetter(
return JSON.parse(packageData).version;
} else {
log.debug('Getting version from the git revision');
// This branch is only reached during development.
// git-rev-sync is in devDependencies, and lazily imported using require.
// This also avoids logspam from https://github.com/mozilla/web-ext/issues/1916
// eslint-disable-next-line import/no-extraneous-dependencies
const git = require('git-rev-sync');
return `${git.branch(absolutePackageDir)}-${git.long(absolutePackageDir)}`;
}
}
Expand Down
7 changes: 6 additions & 1 deletion webpack.config.js
Expand Up @@ -39,7 +39,12 @@ module.exports = {
externals: [
nodeExternals({
modulesFromFile: {
excludeFromBundle: ['dependencies'],
// We shouldn't bundle devDependencies. E.g. git-rev-sync would be
// bundled if we omitted "devDependencies" from this list, which is
// undesired because the branch is never reached on production, so it
// is intentionally part of devDependencies to avoid the unnecessary
// dependency and bundling on production.
excludeFromBundle: ['dependencies', 'devDependencies'],
},
}),
],
Expand Down

0 comments on commit a99313c

Please sign in to comment.