Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add migration for adding $schema, increase some strictness
- Loading branch information
1 parent
834160c
commit 73ceac3
Showing
5 changed files
with
58 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
33 changes: 33 additions & 0 deletions
33
packages/lerna/src/migrations/add-schema-config/add-schema-config.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import { readJson, Tree, writeJson } from "@nx/devkit"; | ||
import { createTreeWithEmptyWorkspace } from "@nx/devkit/testing"; | ||
import addSchemaConfigMigration from "./add-schema-config"; | ||
|
||
describe("add-schema-config", () => { | ||
let tree: Tree; | ||
|
||
beforeEach(() => { | ||
tree = createTreeWithEmptyWorkspace(); | ||
}); | ||
|
||
it(`should add "$schema" config if not already present`, async () => { | ||
writeJson(tree, "lerna.json", {}); | ||
await addSchemaConfigMigration(tree); | ||
expect(readJson(tree, "lerna.json")).toMatchInlineSnapshot(` | ||
Object { | ||
"$schema": "node_modules/lerna/schemas/lerna-schema.json", | ||
} | ||
`); | ||
}); | ||
|
||
it(`should not not modify the "$schema" config if it is already present`, async () => { | ||
writeJson(tree, "lerna.json", { | ||
$schema: "./some/path/to/schema.json", | ||
}); | ||
await addSchemaConfigMigration(tree); | ||
expect(readJson(tree, "lerna.json")).toMatchInlineSnapshot(` | ||
Object { | ||
"$schema": "./some/path/to/schema.json", | ||
} | ||
`); | ||
}); | ||
}); |
12 changes: 12 additions & 0 deletions
12
packages/lerna/src/migrations/add-schema-config/add-schema-config.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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.$schema) { | ||
lernaJson.$schema = "node_modules/lerna/schemas/lerna-schema.json"; | ||
writeJson(tree, "lerna.json", lernaJson); | ||
} | ||
|
||
await formatFiles(tree); | ||
} |