diff --git a/fixtures/lerna-with-defaults/lerna.json b/fixtures/lerna-with-defaults/lerna.json deleted file mode 100644 index 0967ef4..0000000 --- a/fixtures/lerna-with-defaults/lerna.json +++ /dev/null @@ -1 +0,0 @@ -{} diff --git a/fixtures/lerna-with-defaults/package.json b/fixtures/lerna-with-defaults/package.json deleted file mode 100644 index 81c88a7..0000000 --- a/fixtures/lerna-with-defaults/package.json +++ /dev/null @@ -1,4 +0,0 @@ -{ - "name": "lerna-with-defaults", - "private": true -} diff --git a/fixtures/lerna-with-defaults/packages/a/package.json b/fixtures/lerna-with-defaults/packages/a/package.json deleted file mode 100644 index 55f5e85..0000000 --- a/fixtures/lerna-with-defaults/packages/a/package.json +++ /dev/null @@ -1,4 +0,0 @@ -{ - "name": "@lerna-with-defaults/a", - "private": true -} diff --git a/fixtures/lerna-with-defaults/packages/b/package.json b/fixtures/lerna-with-defaults/packages/b/package.json deleted file mode 100644 index ddc8a4e..0000000 --- a/fixtures/lerna-with-defaults/packages/b/package.json +++ /dev/null @@ -1,4 +0,0 @@ -{ - "name": "@lerna-with-defaults/b", - "private": true -} diff --git a/fixtures/lerna-with-packages/lerna.json b/fixtures/lerna-with-packages/lerna.json new file mode 100644 index 0000000..da7d836 --- /dev/null +++ b/fixtures/lerna-with-packages/lerna.json @@ -0,0 +1 @@ +{ "packages": ["packages/*"] } diff --git a/fixtures/lerna-with-packages/package.json b/fixtures/lerna-with-packages/package.json new file mode 100644 index 0000000..21f829d --- /dev/null +++ b/fixtures/lerna-with-packages/package.json @@ -0,0 +1,4 @@ +{ + "name": "lerna", + "private": true +} diff --git a/fixtures/lerna-with-packages/packages/a/package.json b/fixtures/lerna-with-packages/packages/a/package.json new file mode 100644 index 0000000..e281215 --- /dev/null +++ b/fixtures/lerna-with-packages/packages/a/package.json @@ -0,0 +1,4 @@ +{ + "name": "@lerna-with-packages/a", + "private": true +} diff --git a/fixtures/lerna-with-packages/packages/b/package.json b/fixtures/lerna-with-packages/packages/b/package.json new file mode 100644 index 0000000..8a8cb11 --- /dev/null +++ b/fixtures/lerna-with-packages/packages/b/package.json @@ -0,0 +1,4 @@ +{ + "name": "@lerna-with-packages/b", + "private": true +} diff --git a/fixtures/lerna/lerna.json b/fixtures/lerna/lerna.json index da7d836..0967ef4 100644 --- a/fixtures/lerna/lerna.json +++ b/fixtures/lerna/lerna.json @@ -1 +1 @@ -{ "packages": ["packages/*"] } +{} diff --git a/fixtures/lerna/package.json b/fixtures/lerna/package.json index 21f829d..0656869 100644 --- a/fixtures/lerna/package.json +++ b/fixtures/lerna/package.json @@ -1,4 +1,7 @@ { "name": "lerna", - "private": true + "private": true, + "workspaces": [ + "packages/*" + ] } diff --git a/index.ts b/index.ts index 792ad29..122d975 100644 --- a/index.ts +++ b/index.ts @@ -111,14 +111,11 @@ function resolveLernaGlobs(dir: string): string[] | null { const lernaJson = resolveJSONFile(dir, "lerna.json"); if (lernaJson === undefined) return null; - if (isObject(lernaJson)) { - if (lernaJson.useWorkspaces === true) return null; - if (!lernaJson.packages) return ["packages/*"]; - if (isStringArray(lernaJson.packages)) return lernaJson.packages; - return null; + if (isObject(lernaJson) && isStringArray(lernaJson.packages)) { + return lernaJson.packages; } - return ["packages/*"]; + return null; } function resolvePnpmGlobs(dir: string): string[] | null { diff --git a/tests/findRoot.test.ts b/tests/findRoot.test.ts index 4ff3c75..252d9b9 100644 --- a/tests/findRoot.test.ts +++ b/tests/findRoot.test.ts @@ -19,23 +19,23 @@ assert.deepStrictEqual(findWorkspacesRoot(join("fixtures", "bolt")), { globs: ["packages/**/*"], }); -assert.deepStrictEqual(findWorkspacesRoot(join("fixtures", "lerna")), { - location: posixResolve("fixtures", "lerna"), - globs: ["packages/*"], -}); +assert.deepStrictEqual( + findWorkspacesRoot(join("fixtures", "lerna-with-packages")), + { + location: posixResolve("fixtures", "lerna-with-packages"), + globs: ["packages/*"], + }, +); assert.strictEqual( findWorkspacesRoot(join("fixtures", "lerna-with-invalid-packages")), null, ); -assert.deepStrictEqual( - findWorkspacesRoot(join("fixtures", "lerna-with-defaults")), - { - location: posixResolve("fixtures", "lerna-with-defaults"), - globs: ["packages/*"], - }, -); +assert.deepStrictEqual(findWorkspacesRoot(join("fixtures", "lerna")), { + location: posixResolve("fixtures", "lerna"), + globs: ["packages/*"], +}); assert.strictEqual( findWorkspacesRoot(join("fixtures", "lerna-with-invalid-workspaces")), diff --git a/tests/findWorkspaces.test.ts b/tests/findWorkspaces.test.ts index 18463f1..0017f77 100644 --- a/tests/findWorkspaces.test.ts +++ b/tests/findWorkspaces.test.ts @@ -16,46 +16,46 @@ assert.deepStrictEqual(findWorkspaces(join("fixtures", "bolt")), [ }, ]); -assert.deepStrictEqual(findWorkspaces(join("fixtures", "lerna")), [ - { - location: posixResolve("fixtures", "lerna", "packages", "a"), - package: { name: "@lerna/a", private: true }, - }, - { - location: posixResolve("fixtures", "lerna", "packages", "b"), - package: { name: "@lerna/b", private: true }, - }, -]); - -assert.strictEqual( - findWorkspaces(join("fixtures", "lerna-with-invalid-packages")), - null, -); - assert.deepStrictEqual( - findWorkspaces(join("fixtures", "lerna-with-defaults")), + findWorkspaces(join("fixtures", "lerna-with-packages")), [ { location: posixResolve( "fixtures", - "lerna-with-defaults", + "lerna-with-packages", "packages", "a", ), - package: { name: "@lerna-with-defaults/a", private: true }, + package: { name: "@lerna-with-packages/a", private: true }, }, { location: posixResolve( "fixtures", - "lerna-with-defaults", + "lerna-with-packages", "packages", "b", ), - package: { name: "@lerna-with-defaults/b", private: true }, + package: { name: "@lerna-with-packages/b", private: true }, }, ], ); +assert.strictEqual( + findWorkspaces(join("fixtures", "lerna-with-invalid-packages")), + null, +); + +assert.deepStrictEqual(findWorkspaces(join("fixtures", "lerna")), [ + { + location: posixResolve("fixtures", "lerna", "packages", "a"), + package: { name: "@lerna/a", private: true }, + }, + { + location: posixResolve("fixtures", "lerna", "packages", "b"), + package: { name: "@lerna/b", private: true }, + }, +]); + assert.strictEqual( findWorkspaces(join("fixtures", "lerna-with-invalid-workspaces")), null, @@ -63,7 +63,7 @@ assert.strictEqual( assert.deepStrictEqual( findWorkspaces(join("fixtures", "lerna-with-invalid-lerna-json")), - [], + null, ); assert.strictEqual( @@ -186,53 +186,67 @@ assert.deepStrictEqual(findWorkspaces(posixResolve("fixtures", "yarn-npm")), [ const cache = createWorkspacesCache(); assert.deepStrictEqual( - findWorkspaces(posixResolve("fixtures", "lerna", "foo"), { cache }), - [ - { - location: posixResolve("fixtures", "lerna", "packages", "a"), - package: { name: "@lerna/a", private: true }, - }, - { - location: posixResolve("fixtures", "lerna", "packages", "b"), - package: { name: "@lerna/b", private: true }, - }, - ], -); - -assert.deepStrictEqual( - findWorkspaces(posixResolve("fixtures", "lerna", "bar"), { cache }), + findWorkspaces(posixResolve("fixtures", "lerna-with-packages", "foo"), { + cache, + }), [ { - location: posixResolve("fixtures", "lerna", "packages", "a"), - package: { name: "@lerna/a", private: true }, + location: posixResolve( + "fixtures", + "lerna-with-packages", + "packages", + "a", + ), + package: { name: "@lerna-with-packages/a", private: true }, }, { - location: posixResolve("fixtures", "lerna", "packages", "b"), - package: { name: "@lerna/b", private: true }, + location: posixResolve( + "fixtures", + "lerna-with-packages", + "packages", + "b", + ), + package: { name: "@lerna-with-packages/b", private: true }, }, ], ); assert.deepStrictEqual( - findWorkspaces(posixResolve("fixtures", "lerna-with-defaults"), { cache }), + findWorkspaces(posixResolve("fixtures", "lerna-with-packages", "bar"), { + cache, + }), [ { location: posixResolve( "fixtures", - "lerna-with-defaults", + "lerna-with-packages", "packages", "a", ), - package: { name: "@lerna-with-defaults/a", private: true }, + package: { name: "@lerna-with-packages/a", private: true }, }, { location: posixResolve( "fixtures", - "lerna-with-defaults", + "lerna-with-packages", "packages", "b", ), - package: { name: "@lerna-with-defaults/b", private: true }, + package: { name: "@lerna-with-packages/b", private: true }, + }, + ], +); + +assert.deepStrictEqual( + findWorkspaces(posixResolve("fixtures", "lerna"), { cache }), + [ + { + location: posixResolve("fixtures", "lerna", "packages", "a"), + package: { name: "@lerna/a", private: true }, + }, + { + location: posixResolve("fixtures", "lerna", "packages", "b"), + package: { name: "@lerna/b", private: true }, }, ], ); @@ -241,14 +255,17 @@ assert.deepStrictEqual( cache.root, new Map([ [ - resolve("fixtures", "lerna"), - { globs: ["packages/*"], location: posixResolve("fixtures", "lerna") }, + resolve("fixtures", "lerna-with-packages"), + { + globs: ["packages/*"], + location: posixResolve("fixtures", "lerna-with-packages"), + }, ], [ - resolve("fixtures", "lerna-with-defaults"), + resolve("fixtures", "lerna"), { globs: ["packages/*"], - location: posixResolve("fixtures", "lerna-with-defaults"), + location: posixResolve("fixtures", "lerna"), }, ], ]), @@ -258,38 +275,38 @@ assert.deepStrictEqual( cache.workspaces, new Map([ [ - posixResolve("fixtures", "lerna"), - [ - { - location: posixResolve("fixtures", "lerna", "packages", "a"), - package: { name: "@lerna/a", private: true }, - }, - { - location: posixResolve("fixtures", "lerna", "packages", "b"), - package: { name: "@lerna/b", private: true }, - }, - ], - ], - [ - posixResolve("fixtures", "lerna-with-defaults"), + posixResolve("fixtures", "lerna-with-packages"), [ { location: posixResolve( "fixtures", - "lerna-with-defaults", + "lerna-with-packages", "packages", "a", ), - package: { name: "@lerna-with-defaults/a", private: true }, + package: { name: "@lerna-with-packages/a", private: true }, }, { location: posixResolve( "fixtures", - "lerna-with-defaults", + "lerna-with-packages", "packages", "b", ), - package: { name: "@lerna-with-defaults/b", private: true }, + package: { name: "@lerna-with-packages/b", private: true }, + }, + ], + ], + [ + posixResolve("fixtures", "lerna"), + [ + { + location: posixResolve("fixtures", "lerna", "packages", "a"), + package: { name: "@lerna/a", private: true }, + }, + { + location: posixResolve("fixtures", "lerna", "packages", "b"), + package: { name: "@lerna/b", private: true }, }, ], ],