Skip to content

Commit a99313c

Browse files
authoredJul 24, 2020
fix: Lazily import git-rev-sync in non-production (#1972)
1 parent fc91c36 commit a99313c

File tree

4 files changed

+22
-6
lines changed

4 files changed

+22
-6
lines changed
 

‎package-lock.json

+10-3
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,6 @@
7373
"firefox-profile": "2.0.0",
7474
"fs-extra": "9.0.1",
7575
"fx-runner": "1.0.13",
76-
"git-rev-sync": "2.0.0",
7776
"import-fresh": "3.2.1",
7877
"mkdirp": "1.0.4",
7978
"multimatch": "4.0.0",
@@ -116,6 +115,7 @@
116115
"eslint-plugin-flowtype": "5.2.0",
117116
"eslint-plugin-import": "2.22.0",
118117
"flow-bin": "0.129.0",
118+
"git-rev-sync": "2.0.0",
119119
"html-entities": "1.3.1",
120120
"mocha": "8.0.1",
121121
"nyc": "15.1.0",

‎src/program.js

+5-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ import {readFileSync} from 'fs';
55

66
import camelCase from 'camelcase';
77
import decamelize from 'decamelize';
8-
import git from 'git-rev-sync';
98
import yargs from 'yargs';
109
import { Parser as yargsParser } from 'yargs/yargs';
1110

@@ -353,6 +352,11 @@ export function defaultVersionGetter(
353352
return JSON.parse(packageData).version;
354353
} else {
355354
log.debug('Getting version from the git revision');
355+
// This branch is only reached during development.
356+
// git-rev-sync is in devDependencies, and lazily imported using require.
357+
// This also avoids logspam from https://github.com/mozilla/web-ext/issues/1916
358+
// eslint-disable-next-line import/no-extraneous-dependencies
359+
const git = require('git-rev-sync');
356360
return `${git.branch(absolutePackageDir)}-${git.long(absolutePackageDir)}`;
357361
}
358362
}

‎webpack.config.js

+6-1
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,12 @@ module.exports = {
3939
externals: [
4040
nodeExternals({
4141
modulesFromFile: {
42-
excludeFromBundle: ['dependencies'],
42+
// We shouldn't bundle devDependencies. E.g. git-rev-sync would be
43+
// bundled if we omitted "devDependencies" from this list, which is
44+
// undesired because the branch is never reached on production, so it
45+
// is intentionally part of devDependencies to avoid the unnecessary
46+
// dependency and bundling on production.
47+
excludeFromBundle: ['dependencies', 'devDependencies'],
4348
},
4449
}),
4550
],

0 commit comments

Comments
 (0)
Please sign in to comment.