-
Notifications
You must be signed in to change notification settings - Fork 2.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(init): detect existing package manager and auto-install packages (…
- Loading branch information
Showing
11 changed files
with
320 additions
and
18 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
import { Fixture, normalizeEnvironment } from "@lerna/e2e-utils"; | ||
import { writeFileSync } from "fs-extra"; | ||
|
||
expect.addSnapshotSerializer({ | ||
serialize(str: string) { | ||
return normalizeEnvironment(str); | ||
}, | ||
test(val: string) { | ||
return val != null && typeof val === "string"; | ||
}, | ||
}); | ||
|
||
describe("lerna-init-npm", () => { | ||
let fixture: Fixture; | ||
|
||
beforeEach(async () => { | ||
fixture = await Fixture.create({ | ||
e2eRoot: process.env.E2E_ROOT, | ||
name: "lerna-init-npm", | ||
packageManager: "npm", | ||
initializeGit: false, | ||
lernaInit: false, | ||
installDependencies: false, | ||
}); | ||
|
||
writeFileSync( | ||
fixture.getWorkspacePath("package.json"), | ||
JSON.stringify({ | ||
name: "root", | ||
private: true, | ||
workspaces: ["packages/*"], | ||
}) | ||
); | ||
|
||
await fixture.install(); | ||
}); | ||
|
||
afterEach(() => fixture.destroy()); | ||
|
||
it("should not set npmClient in lerna.json", async () => { | ||
const result = await fixture.lernaInit(); | ||
|
||
expect(result.combinedOutput).toMatchInlineSnapshot(` | ||
lerna notice cli v999.9.9-e2e.0 | ||
lerna info Applying the following file system updates: | ||
CREATE lerna.json | ||
UPDATE package.json | ||
CREATE .gitignore | ||
lerna info Initializing Git repository | ||
lerna info Using npm to install packages | ||
lerna success Initialized Lerna files | ||
lerna info New to Lerna? Check out the docs: https://lerna.js.org/docs/getting-started | ||
`); | ||
|
||
const lernaJson = await fixture.readWorkspaceFile("lerna.json"); | ||
|
||
expect(lernaJson).toMatchInlineSnapshot(` | ||
{ | ||
"$schema": "node_modules/lerna/schemas/lerna-schema.json", | ||
"version": "0.0.0" | ||
} | ||
`); | ||
}); | ||
|
||
describe("--skip-install", () => { | ||
it("should not install packages", async () => { | ||
const result = await fixture.lernaInit("--skip-install"); | ||
|
||
expect(result.combinedOutput).toMatchInlineSnapshot(` | ||
lerna notice cli v999.9.9-e2e.0 | ||
lerna info Applying the following file system updates: | ||
CREATE lerna.json | ||
UPDATE package.json | ||
CREATE .gitignore | ||
lerna info Initializing Git repository | ||
lerna success Initialized Lerna files | ||
lerna info New to Lerna? Check out the docs: https://lerna.js.org/docs/getting-started | ||
`); | ||
|
||
const lernaJson = await fixture.readWorkspaceFile("lerna.json"); | ||
|
||
expect(lernaJson).toMatchInlineSnapshot(` | ||
{ | ||
"$schema": "node_modules/lerna/schemas/lerna-schema.json", | ||
"version": "0.0.0" | ||
} | ||
`); | ||
}); | ||
}); | ||
}); |
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,71 @@ | ||
import { Fixture, getPublishedVersion, normalizeEnvironment } from "@lerna/e2e-utils"; | ||
import { writeFileSync } from "fs-extra"; | ||
|
||
expect.addSnapshotSerializer({ | ||
serialize(str: string) { | ||
return normalizeEnvironment(str) | ||
.replace(/\.+\/\.?pnpm.*\n/g, "") | ||
.replace("info cli using local version of lerna\n", ""); | ||
}, | ||
test(val: string) { | ||
return val != null && typeof val === "string"; | ||
}, | ||
}); | ||
|
||
describe("lerna-init-pnpm", () => { | ||
let fixture: Fixture; | ||
|
||
beforeEach(async () => { | ||
fixture = await Fixture.create({ | ||
e2eRoot: process.env.E2E_ROOT, | ||
name: "lerna-init-pnpm", | ||
packageManager: "pnpm", | ||
initializeGit: false, | ||
lernaInit: false, | ||
installDependencies: false, | ||
}); | ||
|
||
writeFileSync( | ||
fixture.getWorkspacePath("package.json"), | ||
JSON.stringify({ | ||
name: "root", | ||
private: true, | ||
devDependencies: { | ||
lerna: getPublishedVersion(), | ||
}, | ||
}) | ||
); | ||
|
||
await fixture.install(); | ||
}); | ||
|
||
afterEach(() => fixture.destroy()); | ||
|
||
it("should set npmClient to pnpm in lerna.json", async () => { | ||
const result = await fixture.lernaInit(); | ||
|
||
expect(result.combinedOutput).toMatchInlineSnapshot(` | ||
lerna notice cli v999.9.9-e2e.0 | ||
lerna info Applying the following file system updates: | ||
CREATE lerna.json | ||
UPDATE package.json | ||
CREATE .gitignore | ||
lerna info Initializing Git repository | ||
lerna info Using pnpm to install packages | ||
lerna success Initialized Lerna files | ||
lerna info New to Lerna? Check out the docs: https://lerna.js.org/docs/getting-started | ||
`); | ||
|
||
const lernaJson = await fixture.readWorkspaceFile("lerna.json"); | ||
|
||
expect(lernaJson).toMatchInlineSnapshot(` | ||
{ | ||
"$schema": "node_modules/lerna/schemas/lerna-schema.json", | ||
"version": "0.0.0", | ||
"npmClient": "pnpm" | ||
} | ||
`); | ||
}); | ||
}); |
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,67 @@ | ||
import { Fixture, normalizeEnvironment } from "@lerna/e2e-utils"; | ||
import { writeFileSync } from "fs-extra"; | ||
|
||
expect.addSnapshotSerializer({ | ||
serialize(str: string) { | ||
return normalizeEnvironment(str); | ||
}, | ||
test(val: string) { | ||
return val != null && typeof val === "string"; | ||
}, | ||
}); | ||
|
||
describe("lerna-init-yarn", () => { | ||
let fixture: Fixture; | ||
|
||
beforeEach(async () => { | ||
fixture = await Fixture.create({ | ||
e2eRoot: process.env.E2E_ROOT, | ||
name: "lerna-init-yarn", | ||
packageManager: "yarn", | ||
initializeGit: false, | ||
lernaInit: false, | ||
installDependencies: false, | ||
}); | ||
|
||
writeFileSync( | ||
fixture.getWorkspacePath("package.json"), | ||
JSON.stringify({ | ||
name: "root", | ||
private: true, | ||
workspaces: ["packages/*"], | ||
}) | ||
); | ||
|
||
await fixture.install(); | ||
}); | ||
|
||
afterEach(() => fixture.destroy()); | ||
|
||
it("should set npmClient to yarn in lerna.json", async () => { | ||
const result = await fixture.lernaInit(); | ||
|
||
expect(result.combinedOutput).toMatchInlineSnapshot(` | ||
lerna notice cli v999.9.9-e2e.0 | ||
lerna info Applying the following file system updates: | ||
CREATE lerna.json | ||
UPDATE package.json | ||
CREATE .gitignore | ||
lerna info Initializing Git repository | ||
lerna info Using yarn to install packages | ||
lerna success Initialized Lerna files | ||
lerna info New to Lerna? Check out the docs: https://lerna.js.org/docs/getting-started | ||
`); | ||
|
||
const lernaJson = await fixture.readWorkspaceFile("lerna.json"); | ||
|
||
expect(lernaJson).toMatchInlineSnapshot(` | ||
{ | ||
"$schema": "node_modules/lerna/schemas/lerna-schema.json", | ||
"version": "0.0.0", | ||
"npmClient": "yarn" | ||
} | ||
`); | ||
}); | ||
}); |
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
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
Oops, something went wrong.