Skip to content

Commit

Permalink
feat(repair): add migration to remove unused "lerna" field from lerna…
Browse files Browse the repository at this point in the history
….json (#3734)
  • Loading branch information
JamesHenry committed Jun 16, 2023
1 parent e6c7427 commit 4fb0427
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 0 deletions.
6 changes: 6 additions & 0 deletions packages/lerna/migrations.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,12 @@
"description": "Remove invalid `init` config from lerna.json as it is no longer applicable, given init cannot be run on an existing workspace",
"implementation": "./dist/migrations/remove-invalid-init-config/remove-invalid-init-config"
},
"remove-invalid-lerna-config": {
"cli": "nx",
"version": "7.0.0-alpha.2",
"description": "Remove invalid `lerna` config from lerna.json as it is no longer used for anything",
"implementation": "./dist/migrations/remove-invalid-lerna-config/remove-invalid-lerna-config"
},
"remove-invalid-use-workspaces": {
"cli": "nx",
"version": "7.0.0-alpha.2",
Expand Down
1 change: 1 addition & 0 deletions packages/lerna/project.json
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@
"packages/lerna/src/commands/version/lib/update-lockfile-version.ts",
"packages/lerna/src/migrations/add-schema-config/add-schema-config.ts",
"packages/lerna/src/migrations/remove-invalid-init-config/remove-invalid-init-config.ts",
"packages/lerna/src/migrations/remove-invalid-lerna-config/remove-invalid-lerna-config.ts",
"packages/lerna/src/migrations/remove-invalid-use-workspaces/remove-invalid-use-workspaces.ts",
"packages/lerna/src/migrations/remove-unnecessary-use-nx/remove-unnecessary-use-nx.ts",
"packages/lerna/src/migrations/update-options-from-legacy-deprecate-config/update-options-from-legacy-deprecate-config.ts"
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import { readJson, Tree, writeJson } from "@nx/devkit";
import { createTreeWithEmptyWorkspace } from "@nx/devkit/testing";
import removeInvalidConfigMigration from "./remove-invalid-lerna-config";

describe("remove-invalid-lerna-config", () => {
let tree: Tree;

beforeEach(() => {
tree = createTreeWithEmptyWorkspace();
});

it(`should remove "lerna" config if present`, async () => {
writeJson(tree, "lerna.json", {
lerna: "2.0.0-rc.5",
});
await removeInvalidConfigMigration(tree);
expect(readJson(tree, "lerna.json")).toMatchInlineSnapshot(`Object {}`);
});

it(`should not not modify the file if no "lerna" config is present`, async () => {
writeJson(tree, "lerna.json", {
something: false,
somethingElse: {
nested: "value",
},
});
await removeInvalidConfigMigration(tree);
expect(readJson(tree, "lerna.json")).toMatchInlineSnapshot(`
Object {
"something": false,
"somethingElse": Object {
"nested": "value",
},
}
`);
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { formatFiles, readJson, Tree, writeJson } from "@nx/devkit";

export default async function generator(tree: Tree) {
const lernaJson = readJson(tree, "lerna.json");

if (lernaJson.lerna !== undefined) {
delete lernaJson.lerna;
writeJson(tree, "lerna.json", lernaJson);
}

await formatFiles(tree);
}

0 comments on commit 4fb0427

Please sign in to comment.