[kbn-pm] Include 'packages' and 'plugins' folders within projects as projects (#16713)

This commit is contained in:
Kim Joar Bekkelund 2018-02-15 12:45:00 +01:00 committed by GitHub
parent cb8bae8379
commit 5c180d0c93
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 90 additions and 39 deletions

View file

@ -6067,26 +6067,13 @@ Object.defineProperty(exports, "__esModule", {
exports.getProjects = undefined;
let getProjects = exports.getProjects = (() => {
var _ref = _asyncToGenerator(function* (rootPath, projectsPaths) {
const globOpts = {
cwd: rootPath,
// Should throw in case of unusual errors when reading the file system
strict: true,
// Always returns absolute paths for matched files
absolute: true,
// Do not match ** against multiple filenames
// (This is only specified because we currently don't have a need for it.)
noglobstar: true
};
var _ref = _asyncToGenerator(function* (rootPath, projectsPathsPatterns) {
const projects = new Map();
for (const globPath of projectsPaths) {
const files = yield glob(_path2.default.join(globPath, 'package.json'), globOpts);
for (const pattern of projectsPathsPatterns) {
const pathsToProcess = yield packagesFromGlobPattern({ pattern, rootPath });
for (const filePath of files) {
for (const filePath of pathsToProcess) {
const projectConfigPath = normalize(filePath);
const projectDir = _path2.default.dirname(projectConfigPath);
const project = yield _project.Project.fromPath(projectDir);
@ -6110,11 +6097,6 @@ let getProjects = exports.getProjects = (() => {
};
})();
// https://github.com/isaacs/node-glob/blob/master/common.js#L104
// glob always returns "\\" as "/" in windows, so everyone
// gets normalized because we can't have nice things.
exports.buildProjectGraph = buildProjectGraph;
exports.topologicallyBatchProjects = topologicallyBatchProjects;
@ -6140,6 +6122,27 @@ function _asyncToGenerator(fn) { return function () { var gen = fn.apply(this, a
const glob = (0, _pify2.default)(_glob3.default);
function packagesFromGlobPattern({ pattern, rootPath }) {
const globOptions = {
cwd: rootPath,
// Should throw in case of unusual errors when reading the file system
strict: true,
// Always returns absolute paths for matched files
absolute: true,
// Do not match ** against multiple filenames
// (This is only specified because we currently don't have a need for it.)
noglobstar: true
};
return glob(_path2.default.join(pattern, 'package.json'), globOptions);
}
// https://github.com/isaacs/node-glob/blob/master/common.js#L104
// glob always returns "\\" as "/" in windows, so everyone
// gets normalized because we can't have nice things.
function normalize(dir) {
return _path2.default.normalize(dir);
}
@ -22239,6 +22242,8 @@ function getProjectPaths(rootPath, options) {
if (!skipKibanaExtra) {
projectPaths.push((0, _path.resolve)(rootPath, '../kibana-extra/*'));
projectPaths.push((0, _path.resolve)(rootPath, '../kibana-extra/*/packages/*'));
projectPaths.push((0, _path.resolve)(rootPath, '../kibana-extra/*/plugins/*'));
}
return projectPaths;

View file

@ -15,6 +15,8 @@ export function getProjectPaths(rootPath, options) {
if (!skipKibanaExtra) {
projectPaths.push(resolve(rootPath, '../kibana-extra/*'));
projectPaths.push(resolve(rootPath, '../kibana-extra/*/packages/*'));
projectPaths.push(resolve(rootPath, '../kibana-extra/*/plugins/*'));
}
return projectPaths;

View file

@ -0,0 +1,4 @@
{
"name": "with-additional-projects",
"version": "1.0.0"
}

View file

@ -0,0 +1,7 @@
{
"name": "baz",
"version": "1.0.0",
"dependencies": {
"bar": "link:../../../../kibana/packages/bar"
}
}

View file

@ -0,0 +1,8 @@
{
"name": "quux",
"version": "1.0.0",
"dependencies": {
"bar": "link:../../../../kibana/packages/bar",
"baz": "link:../../packages/baz"
}
}

View file

@ -7,26 +7,13 @@ import { Project } from './project';
const glob = promisify(_glob);
export async function getProjects(rootPath, projectsPaths) {
const globOpts = {
cwd: rootPath,
// Should throw in case of unusual errors when reading the file system
strict: true,
// Always returns absolute paths for matched files
absolute: true,
// Do not match ** against multiple filenames
// (This is only specified because we currently don't have a need for it.)
noglobstar: true,
};
export async function getProjects(rootPath, projectsPathsPatterns) {
const projects = new Map();
for (const globPath of projectsPaths) {
const files = await glob(path.join(globPath, 'package.json'), globOpts);
for (const pattern of projectsPathsPatterns) {
const pathsToProcess = await packagesFromGlobPattern({ pattern, rootPath });
for (const filePath of files) {
for (const filePath of pathsToProcess) {
const projectConfigPath = normalize(filePath);
const projectDir = path.dirname(projectConfigPath);
const project = await Project.fromPath(projectDir);
@ -48,6 +35,24 @@ export async function getProjects(rootPath, projectsPaths) {
return projects;
}
function packagesFromGlobPattern({ pattern, rootPath }) {
const globOptions = {
cwd: rootPath,
// Should throw in case of unusual errors when reading the file system
strict: true,
// Always returns absolute paths for matched files
absolute: true,
// Do not match ** against multiple filenames
// (This is only specified because we currently don't have a need for it.)
noglobstar: true,
};
return glob(path.join(pattern, 'package.json'), globOptions);
}
// https://github.com/isaacs/node-glob/blob/master/common.js#L104
// glob always returns "\\" as "/" in windows, so everyone
// gets normalized because we can't have nice things.

View file

@ -5,6 +5,7 @@ import {
buildProjectGraph,
topologicallyBatchProjects,
} from './projects';
import { getProjectPaths } from '../config';
const rootPath = resolve(`${__dirname}/__fixtures__/kibana`);
@ -46,6 +47,25 @@ describe('#getProjects', () => {
'There are multiple projects with the same name [baz]'
);
});
test('includes additional projects in package.json', async () => {
const projectPaths = getProjectPaths(rootPath, {});
const projects = await getProjects(rootPath, projectPaths);
const expectedProjects = [
'kibana',
'bar',
'foo',
'with-additional-projects',
'quux',
'baz',
];
expect([...projects.keys()]).toEqual(
expect.arrayContaining(expectedProjects)
);
expect(projects.size).toBe(expectedProjects.length);
});
});
describe('#buildProjectGraph', () => {