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

fix: Lazily import git-rev-sync in non-production #1972

Merged
merged 1 commit into from
Jul 24, 2020
Merged
Show file tree
Hide file tree
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
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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