Skip to content
This repository has been archived by the owner on Mar 29, 2020. It is now read-only.

Include top level package #110

Merged
merged 4 commits into from
Aug 13, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 16 additions & 4 deletions packages/@hothouse/monorepo-lerna/__tests__/index.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,18 @@ test("Lerna#match should returns true if directory not have lerna.json", async (
);
});

test("Lerna#getPackages should include top-level package.json", async () => {
const lerna = new Lerna();
const pkg = path.join(__dirname, "fixtures", "lockfile-npm");
const expected = [
path.join(pkg),
path.join(pkg, "packages", "has-not-package-lock-json"),
path.join(pkg, "packages", "has-package-lock-json")
];
const actual = await lerna.getPackages(pkg);
expect(expected).toEqual(actual);
});

test("Lerna#getChanges should return [prefix/package.json] when lockfile not exists", async () => {
const lerna = new Lerna();
const prefix = path.join("packages", "has-not-package-lock-json");
Expand All @@ -32,7 +44,7 @@ test("Lerna#getChanges should return [prefix/package.json] when lockfile not exi
path.join(__dirname, "fixtures", "lockfile-npm"),
new Npm()
);
assert.deepStrictEqual(actual, expected);
expect(expected).toEqual(actual);
});
test("Lerna#getChanges should return [prefix/package.json, prefix/package-lock.json] when npmClient=npm lockfile exists", async () => {
const lerna = new Lerna();
Expand All @@ -52,7 +64,7 @@ test("Lerna#getChanges should return [prefix/package.json, prefix/package-lock.j
path.join(__dirname, "fixtures", "lockfile-npm"),
new Npm()
);
assert.deepStrictEqual(actual, expected);
expect(expected).toEqual(actual);
});
test("Lerna#getChanges should return [prefix/package.json] when npmClient=yarn lockfile not exists", async () => {
const lerna = new Lerna();
Expand All @@ -69,7 +81,7 @@ test("Lerna#getChanges should return [prefix/package.json] when npmClient=yarn l
path.join(__dirname, "fixtures", "lockfile-yarn"),
new Yarn()
);
assert.deepStrictEqual(actual, expected);
expect(expected).toEqual(actual);
});
test("Lerna#getChanges should return [prefix/package.json, prefix/yarn.lock] when npmClient=yarn lockfile exists", async () => {
const lerna = new Lerna();
Expand All @@ -89,5 +101,5 @@ test("Lerna#getChanges should return [prefix/package.json, prefix/yarn.lock] whe
path.join(__dirname, "fixtures", "lockfile-yarn"),
new Yarn()
);
assert.deepStrictEqual(actual, expected);
expect(expected).toEqual(actual);
});
30 changes: 16 additions & 14 deletions packages/@hothouse/monorepo-lerna/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,20 +15,22 @@ class Lerna implements Structure {
async getPackages(directory: string): Promise<Array<string>> {
// $FlowFixMe(dynamic-require)
const settings = require(path.join(directory, "lerna.json"));
return settings.packages
.reduce((acc, pkg) => acc.concat(glob.sync(pkg, { absolute: true })), [])
.filter(packagePath => {
const isPackage = fs.existsSync(path.join(packagePath, "package.json"));
if (!isPackage) {
debug(
`${path.relative(
directory,
packagePath
)} is not a npm package. Ignored`
);
}
return isPackage;
});
const children = settings.packages.reduce((acc, pattern) => {
const prefix = path.join(directory, pattern);
return acc.concat(glob.sync(prefix, { absolute: true }));
}, []);
return [directory, ...children].filter(packagePath => {
const isPackage = fs.existsSync(path.join(packagePath, "package.json"));
if (!isPackage) {
debug(
`${path.relative(
directory,
packagePath
)} is not a npm package. Ignored`
);
}
return isPackage;
});
}

async install(
Expand Down
25 changes: 14 additions & 11 deletions packages/@hothouse/monorepo-yarn-workspaces/__tests__/index.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,34 +29,37 @@ test("YarnWorkspaces#match must returns false if directory not have package.json
);
});

test("YarnWorkspaces#getPackages should return [package.json, yarn.lock] when lockfile exists", async () => {
const lerna = new YarnWorkspaces();
test("YarnWorkspaces#getPackages should return package when lockfile exists", async () => {
const yarnWorkspaces = new YarnWorkspaces();
const prefix = path.join(
__dirname,
"fixtures",
"has-yarn-workspaces-with-lockfile"
);
const expected = [path.join(prefix, "packages", "child-a")];
const actual = await lerna.getPackages(prefix);
assert.deepStrictEqual(actual, expected);
const expected = [
path.join(prefix),
path.join(prefix, "packages", "child-a")
];
const actual = await yarnWorkspaces.getPackages(prefix);
expect(expected).toEqual(actual);
});

test("YarnWorkspaces#getChanges should return [package.json] when lockfile not exists", async () => {
const lerna = new YarnWorkspaces();
const yarnWorkspaces = new YarnWorkspaces();
const expected = new Set(["package.json"]);
const actual = await lerna.getChanges(
const actual = await yarnWorkspaces.getChanges(
path.join(__dirname, "fixtures", "is-yarn-workspaces"),
path.join(__dirname, "fixtures", "is-yarn-workspaces")
);
assert.deepStrictEqual(actual, expected);
expect(expected).toEqual(actual);
});
test("YarnWorkspaces#getChanges should return [package.json, yarn.lock] when lockfile exists", async () => {
const lerna = new YarnWorkspaces();
const yarnWorkspaces = new YarnWorkspaces();
const expected = new Set([
path.join("packages", "child-a", "package.json"),
"yarn.lock"
]);
const actual = await lerna.getChanges(
const actual = await yarnWorkspaces.getChanges(
path.join(
__dirname,
"fixtures",
Expand All @@ -66,5 +69,5 @@ test("YarnWorkspaces#getChanges should return [package.json, yarn.lock] when loc
),
path.join(__dirname, "fixtures", "has-yarn-workspaces-with-lockfile")
);
assert.deepStrictEqual(actual, expected);
expect(expected).toEqual(actual);
});
36 changes: 17 additions & 19 deletions packages/@hothouse/monorepo-yarn-workspaces/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,27 +19,25 @@ class YarnWorkspaces implements Structure {
async getPackages(directory: string): Promise<Array<string>> {
// $FlowFixMe(dynamic-require)
const settings = require(path.join(directory, "package.json"));
const packages = Array.isArray(settings.workspaces)
const globs = Array.isArray(settings.workspaces)
? settings.workspaces
: settings.workspaces.packages;
return packages
.reduce(
(acc, pkg) =>
acc.concat(glob.sync(path.join(directory, pkg), { absolute: true })),
[]
)
.filter(packagePath => {
const isPackage = fs.existsSync(path.join(packagePath, "package.json"));
if (!isPackage) {
debug(
`${path.relative(
directory,
packagePath
)} is not a npm package. Ignored`
);
}
return isPackage;
});
const children = globs.reduce((acc, pattern) => {
const prefix = path.join(directory, pattern);
return acc.concat(glob.sync(prefix, { absolute: true }));
}, []);
return [directory, ...children].filter(packagePath => {
const isPackage = fs.existsSync(path.join(packagePath, "package.json"));
if (!isPackage) {
debug(
`${path.relative(
directory,
packagePath
)} is not a npm package. Ignored`
);
}
return isPackage;
});
}

async install(
Expand Down