Skip to content

Commit 105b6b9

Browse files
Sebastian McKenziebestander
authored andcommitted
restrict some kpm commands to only work when there's a lockfile (#143)
1 parent 09c58ea commit 105b6b9

File tree

6 files changed

+13
-16
lines changed

6 files changed

+13
-16
lines changed

src/cli/commands/check.js

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,14 @@ import type { Reporter } from "../../reporters/index.js";
1313
import type Config from "../../config.js";
1414
import { Install } from "./install.js";
1515
import Lockfile from "../../lockfile/index.js";
16-
import { MessageError } from "../../errors.js";
1716
import * as constants from "../../constants.js";
1817
import * as fs from "../../util/fs.js";
1918
import * as util from "../../util/misc.js";
2019

2120
let semver = require("semver");
2221
let path = require("path");
2322

23+
export let requireLockfile = true;
2424
export let noArguments = true;
2525

2626
export function setFlags(commander: Object) {
@@ -33,10 +33,6 @@ export async function run(
3333
flags: Object,
3434
args: Array<string>
3535
): Promise<void> {
36-
if (!await fs.exists(path.join(config.cwd, constants.LOCKFILE_FILENAME))) {
37-
throw new MessageError("No lockfile in this directory. Run `fbkpm install` to generate one.");
38-
}
39-
4036
let lockfile = await Lockfile.fromDirectory(config.cwd, reporter, {
4137
silent: true,
4238
strict: true

src/cli/commands/ls.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import Lockfile from "../../lockfile/index.js";
1919

2020
let invariant = require("invariant");
2121

22+
export let requireLockfile = true;
2223
export let noArguments = true;
2324

2425
function buildCount(trees: ?Trees): number {

src/cli/commands/uninstall.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ import * as fs from "../../util/fs.js";
2020

2121
let path = require("path");
2222

23+
export let requireLockfile = true;
24+
2325
export async function run(
2426
config: Config,
2527
reporter: Reporter,

src/cli/commands/upgrade.js

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -13,30 +13,21 @@ import type { Reporter } from "../../reporters/index.js";
1313
import type Config from "../../config.js";
1414
import { Install } from "./install.js";
1515
import Lockfile from "../../lockfile/index.js";
16-
import { MessageError } from "../../errors.js";
17-
import * as constants from "../../constants.js";
18-
import * as fs from "../../util/fs.js";
19-
20-
let path = require("path");
2116

2217
export function setFlags(commander: Object) {
2318
// TODO: support some flags that install command has
2419
commander;
2520
}
2621

2722
export let noArguments = true;
23+
export let requireLockfile = true;
2824

2925
export async function run(
3026
config: Config,
3127
reporter: Reporter,
3228
flags: Object,
3329
args: Array<string>
3430
): Promise<void> {
35-
if (!await fs.exists(path.join(config.cwd, constants.LOCKFILE_FILENAME))) {
36-
throw new MessageError("No lockfile in this directory. Run `fbkpm install` to generate one.");
37-
}
38-
39-
// TODO: show and make user approve of updated packages from lockfile. analyse for changes.
4031
let lockfile = new Lockfile(null, false);
4132
let install = new Install("update", flags, args, config, reporter, lockfile);
4233
return install.init();

src/cli/commands/why.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ import { Install } from "./install.js";
1616
import Lockfile from "../../lockfile/index.js";
1717
import * as fs from "../../util/fs.js";
1818

19+
export let requireLockfile = true;
20+
1921
let invariant = require("invariant");
2022
let emoji = require("node-emoji");
2123
let path = require("path");

src/cli/index.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,12 @@ if (network.isOffline()) {
110110
reporter.warn("You don't appear to have an internet connection.");
111111
}
112112

113+
//
114+
if (command.requireLockfile && !fs.existsSync(path.join(config.cwd, constants.LOCKFILE_FILENAME))) {
115+
reporter.error("No lockfile in this directory. Run `fbkpm install` to generate one.");
116+
process.exit(1);
117+
}
118+
113119
//
114120
const run = () => {
115121
return command.run(config, reporter, commander, commander.args).then(function () {
@@ -118,7 +124,6 @@ const run = () => {
118124
});
119125
};
120126

121-
122127
//
123128
const runEventually = () => {
124129
return new Promise((ok) => {

0 commit comments

Comments
 (0)