@manypkg/get-packages
Advanced tools
Comparing version 1.0.1 to 1.1.0
# @manypkg/get-packages | ||
## 1.1.0 | ||
### Minor Changes | ||
- [`a4db72a`](https://github.com/Thinkmill/manypkg/commit/a4db72a8b272f1b642fa751639d7840f4fa3658c) [#63](https://github.com/Thinkmill/manypkg/pull/63) Thanks [@evocateur](https://github.com/evocateur)! - Add support for Lerna monorepos | ||
### Patch Changes | ||
- Updated dependencies [[`a4db72a`](https://github.com/Thinkmill/manypkg/commit/a4db72a8b272f1b642fa751639d7840f4fa3658c)]: | ||
- @manypkg/find-root@1.1.0 | ||
## 1.0.1 | ||
@@ -4,0 +15,0 @@ |
import { PackageJSON } from "@changesets/types"; | ||
export declare type Tool = "yarn" | "bolt" | "pnpm" | "root"; | ||
export declare type Tool = "yarn" | "bolt" | "pnpm" | "lerna" | "root"; | ||
export declare type Package = { | ||
@@ -4,0 +4,0 @@ packageJson: PackageJSON; |
@@ -47,3 +47,3 @@ 'use strict'; | ||
_regeneratorRuntime.mark(function _callee(dir) { | ||
var cwd, pkg, tool, manifest, root, directories, pkgJsonsMissingNameField, results; | ||
var cwd, pkg, tool, manifest, lernaJson, root, directories, pkgJsonsMissingNameField, results; | ||
return _regeneratorRuntime.wrap(function _callee$(_context) { | ||
@@ -81,3 +81,3 @@ while (1) { | ||
_context.next = 25; | ||
_context.next = 37; | ||
break; | ||
@@ -95,3 +95,3 @@ | ||
}; | ||
_context.next = 25; | ||
_context.next = 37; | ||
break; | ||
@@ -130,6 +130,40 @@ | ||
if (tool) { | ||
_context.next = 30; | ||
_context.next = 37; | ||
break; | ||
} | ||
_context.prev = 26; | ||
_context.next = 29; | ||
return fs.readJson(path.join(cwd, "lerna.json")); | ||
case 29: | ||
lernaJson = _context.sent; | ||
if (lernaJson) { | ||
tool = { | ||
type: "lerna", | ||
packageGlobs: lernaJson.packages || ["packages/*"] | ||
}; | ||
} | ||
_context.next = 37; | ||
break; | ||
case 33: | ||
_context.prev = 33; | ||
_context.t1 = _context["catch"](26); | ||
if (!(_context.t1.code !== "ENOENT")) { | ||
_context.next = 37; | ||
break; | ||
} | ||
throw _context.t1; | ||
case 37: | ||
if (tool) { | ||
_context.next = 42; | ||
break; | ||
} | ||
root = { | ||
@@ -141,3 +175,3 @@ dir: cwd, | ||
if (pkg.name) { | ||
_context.next = 29; | ||
_context.next = 41; | ||
break; | ||
@@ -148,3 +182,3 @@ } | ||
case 29: | ||
case 41: | ||
return _context.abrupt("return", { | ||
@@ -156,4 +190,4 @@ tool: "root", | ||
case 30: | ||
_context.next = 32; | ||
case 42: | ||
_context.next = 44; | ||
return globby__default(tool.packageGlobs, { | ||
@@ -167,6 +201,6 @@ cwd: cwd, | ||
case 32: | ||
case 44: | ||
directories = _context.sent; | ||
pkgJsonsMissingNameField = []; | ||
_context.next = 36; | ||
_context.next = 48; | ||
return Promise.all(directories.sort().map(function (dir) { | ||
@@ -191,11 +225,11 @@ return fs.readJson(path.join(dir, "package.json")).then(function (packageJson) { | ||
case 36: | ||
_context.t1 = function (x) { | ||
case 48: | ||
_context.t2 = function (x) { | ||
return x; | ||
}; | ||
results = _context.sent.filter(_context.t1); | ||
results = _context.sent.filter(_context.t2); | ||
if (!(pkgJsonsMissingNameField.length !== 0)) { | ||
_context.next = 41; | ||
_context.next = 53; | ||
break; | ||
@@ -207,3 +241,3 @@ } | ||
case 41: | ||
case 53: | ||
return _context.abrupt("return", { | ||
@@ -218,3 +252,3 @@ tool: tool.type, | ||
case 42: | ||
case 54: | ||
case "end": | ||
@@ -224,3 +258,3 @@ return _context.stop(); | ||
} | ||
}, _callee, null, [[14, 21]]); | ||
}, _callee, null, [[14, 21], [26, 33]]); | ||
})); | ||
@@ -267,2 +301,19 @@ return _getPackages.apply(this, arguments); | ||
} | ||
if (!tool) { | ||
try { | ||
var lernaJson = fs.readJsonSync(path.join(cwd, "lerna.json")); | ||
if (lernaJson) { | ||
tool = { | ||
type: "lerna", | ||
packageGlobs: lernaJson.packages || ["packages/*"] | ||
}; | ||
} | ||
} catch (err) { | ||
if (err.code !== "ENOENT") { | ||
throw err; | ||
} | ||
} | ||
} | ||
} | ||
@@ -269,0 +320,0 @@ |
@@ -26,3 +26,3 @@ "use strict"; | ||
return (_getPackages = _asyncToGenerator(_regeneratorRuntime.mark(function _callee(dir) { | ||
var cwd, pkg, tool, manifest, root, directories, pkgJsonsMissingNameField, results; | ||
var cwd, pkg, tool, manifest, lernaJson, root, directories, pkgJsonsMissingNameField, results; | ||
return _regeneratorRuntime.wrap(function(_context) { | ||
@@ -47,3 +47,3 @@ for (;;) switch (_context.prev = _context.next) { | ||
packageGlobs: pkg.workspaces.packages | ||
}), _context.next = 25; | ||
}), _context.next = 37; | ||
break; | ||
@@ -59,3 +59,3 @@ | ||
packageGlobs: pkg.bolt.workspaces | ||
}, _context.next = 25; | ||
}, _context.next = 37; | ||
break; | ||
@@ -82,5 +82,26 @@ | ||
if (tool) { | ||
_context.next = 30; | ||
_context.next = 37; | ||
break; | ||
} | ||
return _context.prev = 26, _context.next = 29, fs.readJson(path.join(cwd, "lerna.json")); | ||
case 29: | ||
(lernaJson = _context.sent) && (tool = { | ||
type: "lerna", | ||
packageGlobs: lernaJson.packages || [ "packages/*" ] | ||
}), _context.next = 37; | ||
break; | ||
case 33: | ||
if (_context.prev = 33, _context.t1 = _context.catch(26), "ENOENT" === _context.t1.code) { | ||
_context.next = 37; | ||
break; | ||
} | ||
throw _context.t1; | ||
case 37: | ||
if (tool) { | ||
_context.next = 42; | ||
break; | ||
} | ||
if (root = { | ||
@@ -90,3 +111,3 @@ dir: cwd, | ||
}, pkg.name) { | ||
_context.next = 29; | ||
_context.next = 41; | ||
break; | ||
@@ -96,3 +117,3 @@ } | ||
case 29: | ||
case 41: | ||
return _context.abrupt("return", { | ||
@@ -104,4 +125,4 @@ tool: "root", | ||
case 30: | ||
return _context.next = 32, globby__default(tool.packageGlobs, { | ||
case 42: | ||
return _context.next = 44, globby__default(tool.packageGlobs, { | ||
cwd: cwd, | ||
@@ -114,4 +135,4 @@ onlyDirectories: !0, | ||
case 32: | ||
return directories = _context.sent, pkgJsonsMissingNameField = [], _context.next = 36, | ||
case 44: | ||
return directories = _context.sent, pkgJsonsMissingNameField = [], _context.next = 48, | ||
Promise.all(directories.sort().map(function(dir) { | ||
@@ -130,7 +151,7 @@ return fs.readJson(path.join(dir, "package.json")).then(function(packageJson) { | ||
case 36: | ||
if (_context.t1 = function(x) { | ||
case 48: | ||
if (_context.t2 = function(x) { | ||
return x; | ||
}, results = _context.sent.filter(_context.t1), 0 === pkgJsonsMissingNameField.length) { | ||
_context.next = 41; | ||
}, results = _context.sent.filter(_context.t2), 0 === pkgJsonsMissingNameField.length) { | ||
_context.next = 53; | ||
break; | ||
@@ -140,3 +161,3 @@ } | ||
case 41: | ||
case 53: | ||
return _context.abrupt("return", { | ||
@@ -151,7 +172,7 @@ tool: tool.type, | ||
case 42: | ||
case 54: | ||
case "end": | ||
return _context.stop(); | ||
} | ||
}, _callee, null, [ [ 14, 21 ] ]); | ||
}, _callee, null, [ [ 14, 21 ], [ 26, 33 ] ]); | ||
}))).apply(this, arguments); | ||
@@ -171,10 +192,21 @@ } | ||
packageGlobs: pkg.bolt.workspaces | ||
}; else try { | ||
var manifest = readYamlFile.sync(path.join(cwd, "pnpm-workspace.yaml")); | ||
manifest && manifest.packages && (tool = { | ||
type: "pnpm", | ||
packageGlobs: manifest.packages | ||
}); | ||
} catch (err) { | ||
if ("ENOENT" !== err.code) throw err; | ||
}; else { | ||
try { | ||
var manifest = readYamlFile.sync(path.join(cwd, "pnpm-workspace.yaml")); | ||
manifest && manifest.packages && (tool = { | ||
type: "pnpm", | ||
packageGlobs: manifest.packages | ||
}); | ||
} catch (err) { | ||
if ("ENOENT" !== err.code) throw err; | ||
} | ||
if (!tool) try { | ||
var lernaJson = fs.readJsonSync(path.join(cwd, "lerna.json")); | ||
lernaJson && (tool = { | ||
type: "lerna", | ||
packageGlobs: lernaJson.packages || [ "packages/*" ] | ||
}); | ||
} catch (err) { | ||
if ("ENOENT" !== err.code) throw err; | ||
} | ||
} | ||
@@ -181,0 +213,0 @@ if (!tool) { |
{ | ||
"name": "@manypkg/get-packages", | ||
"version": "1.0.1", | ||
"version": "1.1.0", | ||
"main": "dist/get-packages.cjs.js", | ||
"dependencies": { | ||
"@babel/runtime": "^7.5.5", | ||
"@manypkg/find-root": "^1.0.0", | ||
"@manypkg/find-root": "^1.1.0", | ||
"fs-extra": "^8.1.0", | ||
@@ -9,0 +9,0 @@ "globby": "^11.0.0", |
@@ -72,2 +72,33 @@ import fixturez from "fixturez"; | ||
it("should resolve workspaces for lerna", async () => { | ||
const allPackages = await getPackages(f.copy("lerna-workspace-base")); | ||
if (allPackages.packages === null) { | ||
return expect(allPackages.packages).not.toBeNull(); | ||
} | ||
expect(allPackages.packages[0].packageJson.name).toEqual( | ||
"lerna-workspace-base-pkg-a" | ||
); | ||
expect(allPackages.packages[1].packageJson.name).toEqual( | ||
"lerna-workspace-base-pkg-b" | ||
); | ||
expect(allPackages.packages).toHaveLength(2); | ||
expect(allPackages.tool).toEqual("lerna"); | ||
}); | ||
it("should resolve workspaces for lerna without explicit packages config", async () => { | ||
const allPackages = await getPackages(f.copy("basic-lerna")); | ||
if (allPackages.packages === null) { | ||
return expect(allPackages.packages).not.toBeNull(); | ||
} | ||
expect(allPackages.packages[0].packageJson.name).toEqual( | ||
"@manypkg/basic-lerna-fixture-pkg-one" | ||
); | ||
expect(allPackages.packages).toHaveLength(1); | ||
expect(allPackages.tool).toEqual("lerna"); | ||
}); | ||
it("should resolve the main package", async () => { | ||
@@ -74,0 +105,0 @@ const path = f.copy("root-only"); |
@@ -12,3 +12,3 @@ // This is a modified version of the package-getting in bolt | ||
export type Tool = "yarn" | "bolt" | "pnpm" | "root"; | ||
export type Tool = "yarn" | "bolt" | "pnpm" | "lerna" | "root"; | ||
@@ -79,2 +79,20 @@ export type Package = { packageJson: PackageJSON; dir: string }; | ||
} | ||
if (!tool) { | ||
try { | ||
const lernaJson = await fs.readJson( | ||
path.join(cwd, "lerna.json") | ||
); | ||
if (lernaJson) { | ||
tool = { | ||
type: "lerna", | ||
packageGlobs: lernaJson.packages || ["packages/*"], | ||
} | ||
} | ||
} catch (err) { | ||
if (err.code !== "ENOENT") { | ||
throw err; | ||
} | ||
} | ||
} | ||
} | ||
@@ -187,2 +205,20 @@ | ||
} | ||
if (!tool) { | ||
try { | ||
const lernaJson = fs.readJsonSync( | ||
path.join(cwd, "lerna.json") | ||
); | ||
if (lernaJson) { | ||
tool = { | ||
type: "lerna", | ||
packageGlobs: lernaJson.packages || ["packages/*"], | ||
} | ||
} | ||
} catch (err) { | ||
if (err.code !== "ENOENT") { | ||
throw err; | ||
} | ||
} | ||
} | ||
} | ||
@@ -189,0 +225,0 @@ |
33271
936
Updated@manypkg/find-root@^1.1.0