Skip to content

Commit

Permalink
chore: remove unnecessary write-json-file dep (#3534)
Browse files Browse the repository at this point in the history
  • Loading branch information
JamesHenry committed Feb 10, 2023
1 parent fa1f490 commit 02c534e
Show file tree
Hide file tree
Showing 13 changed files with 28 additions and 143 deletions.
8 changes: 4 additions & 4 deletions libs/commands/bootstrap/src/lib/bootstrap-command.spec.ts
Expand Up @@ -207,7 +207,7 @@ describe("BootstrapCommand", () => {
it("should not hoist when disallowed from lerna.json", async () => {
const testDir = await initFixture("basic");

await updateLernaConfig(testDir, {
updateLernaConfig(testDir, {
hoist: true,
nohoist: ["@test/package-1"],
});
Expand Down Expand Up @@ -285,7 +285,7 @@ describe("BootstrapCommand", () => {
it("respects config file { ci: false }", async () => {
const testDir = await initFixture("ci");

await updateLernaConfig(testDir, {
updateLernaConfig(testDir, {
command: {
bootstrap: {
ci: false,
Expand Down Expand Up @@ -500,7 +500,7 @@ describe("BootstrapCommand", () => {
it.skip("hoists appropriately", async () => {
const testDir = await initFixture("cold");

await updateLernaConfig(testDir, {
updateLernaConfig(testDir, {
hoist: true,
});
await lernaBootstrap(testDir)();
Expand All @@ -523,7 +523,7 @@ describe("BootstrapCommand", () => {
it.skip("hoists appropriately", async () => {
const testDir = await initFixture("warm");

await updateLernaConfig(testDir, {
updateLernaConfig(testDir, {
command: {
bootstrap: {
hoist: true,
Expand Down
2 changes: 1 addition & 1 deletion libs/commands/changed/src/lib/changed-command.spec.ts
Expand Up @@ -76,7 +76,7 @@ package-4
});

it("reads durable ignoreChanges config from version namespace", async () => {
await updateLernaConfig(cwd, {
updateLernaConfig(cwd, {
command: {
version: {
ignoreChanges: ["**/durable-ignore"],
Expand Down
2 changes: 1 addition & 1 deletion libs/commands/import/src/lib/import-command.spec.ts
Expand Up @@ -286,7 +286,7 @@ describe("ImportCommand", () => {

await fs.ensureDir(targetDir);

await updateLernaConfig(testDir, {
updateLernaConfig(testDir, {
packages: ["pkg/*"],
});

Expand Down
8 changes: 5 additions & 3 deletions libs/commands/init/src/index.ts
@@ -1,8 +1,8 @@
import { Command, Project } from "@lerna/core";
import { writeJsonFile } from "@nrwl/devkit";
import fs from "fs-extra";
import pMap from "p-map";
import path from "path";
import writeJsonFile from "write-json-file";

// eslint-disable-next-line @typescript-eslint/no-var-requires
const childProcess = require("@lerna/child-process");
Expand Down Expand Up @@ -96,7 +96,9 @@ class InitCommand extends Command {
pkg.workspaces = [Project.PACKAGE_GLOB];
}

return writeJsonFile(path.join(this.project.rootPath, "package.json"), pkg, { indent: 2 });
return writeJsonFile(path.join(this.project.rootPath, "package.json"), pkg, {
spaces: 2,
});
});
} else {
this.logger.info("", "Updating package.json");
Expand Down Expand Up @@ -185,7 +187,7 @@ class InitCommand extends Command {
useNx: useNx === false ? false : undefined,
});

return this.project.serializeConfig();
return Promise.resolve(this.project.serializeConfig());
});

return chain;
Expand Down
2 changes: 1 addition & 1 deletion libs/commands/version/src/index.ts
Expand Up @@ -628,7 +628,7 @@ class VersionCommand extends Command {
}

chain = chain.then(() =>
this.project.serializeConfig().then((lernaConfigLocation) => {
Promise.resolve(this.project.serializeConfig()).then((lernaConfigLocation) => {
// commit the version update
changedFiles.add(lernaConfigLocation);
})
Expand Down
11 changes: 6 additions & 5 deletions libs/commands/version/src/lib/update-lockfile-version.ts
Expand Up @@ -2,10 +2,10 @@
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-nocheck

import { writeJsonFile } from "@nrwl/devkit";
import loadJsonFile from "load-json-file";
import log from "npmlog";
import path from "path";
import writeJsonFile from "write-json-file";

module.exports.updateLockfileVersion = updateLockfileVersion;

Expand Down Expand Up @@ -42,10 +42,11 @@ function updateLockfileVersion(pkg) {
}
}

return writeJsonFile(lockfilePath, obj, {
detectIndent: true,
indent: 2,
}).then(() => lockfilePath);
writeJsonFile(lockfilePath, obj, {
spaces: 2,
});

return lockfilePath;
}
});

Expand Down
2 changes: 1 addition & 1 deletion libs/core/src/lib/command/index.spec.ts
Expand Up @@ -248,7 +248,7 @@ describe("command", () => {
it("is set from lerna.json config", async () => {
const cwd = await initFixture("basic");

await updateLernaConfig(cwd, { loglevel: "warn" });
updateLernaConfig(cwd, { loglevel: "warn" });
await testFactory({ cwd, onRejected });

expect(log.level).toBe("warn");
Expand Down
9 changes: 4 additions & 5 deletions libs/core/src/lib/project/index.ts
@@ -1,3 +1,4 @@
import { writeJsonFile } from "@nrwl/devkit";
import { cosmiconfigSync } from "cosmiconfig";
import dedent from "dedent";
import fs from "fs";
Expand All @@ -8,7 +9,6 @@ import loadJsonFile from "load-json-file";
import log from "npmlog";
import pMap from "p-map";
import path from "path";
import writeJsonFile from "write-json-file";
import { Package } from "../package";
import { ValidationError } from "../validation-error";
import { applyExtends } from "./apply-extends";
Expand Down Expand Up @@ -363,11 +363,10 @@ export class Project {
return this.version === "independent";
}

serializeConfig() {
serializeConfig(): string {
// TODO: might be package.json prop
return writeJsonFile(this.rootConfigLocation, this.config, { indent: 2, detectIndent: true }).then(
() => this.rootConfigLocation
);
writeJsonFile(this.rootConfigLocation, this.config, { spaces: 2 });
return this.rootConfigLocation;
}
}

Expand Down
2 changes: 1 addition & 1 deletion libs/test-helpers/src/index.ts
Expand Up @@ -14,7 +14,7 @@ export * from "./lib/npm";
* @param testDir where target lerna.json exists
* @param updates mixed into existing JSON via Object.assign
*/
export function updateLernaConfig(testDir: any, updates: any) {
export function updateLernaConfig(testDir: any, updates: any): string {
// eslint-disable-next-line @typescript-eslint/no-var-requires
const { Project } = require("@lerna/core");
const project = new Project(testDir);
Expand Down
2 changes: 1 addition & 1 deletion libs/test-helpers/src/lib/git/index.ts
Expand Up @@ -5,7 +5,7 @@ import execa from "execa";
import loadJsonFile from "load-json-file";
import os from "os";
import path from "path";
import writeJsonFile from "write-json-file";
import { writeJsonFile } from "@nrwl/devkit";

// eslint-disable-next-line @typescript-eslint/no-var-requires
const gitSHA = require("../serializers/serialize-git-sha");
Expand Down
121 changes: 3 additions & 118 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 02c534e

Please sign in to comment.