-
Notifications
You must be signed in to change notification settings - Fork 8.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[kbn/optimizer] add support for --focus option (#80436)
Co-authored-by: spalger <spalger@users.noreply.github.com>
- Loading branch information
Showing
5 changed files
with
158 additions
and
6 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
80 changes: 80 additions & 0 deletions
80
packages/kbn-optimizer/src/optimizer/focus_bundles.test.ts
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,80 @@ | ||
/* | ||
* Licensed to Elasticsearch B.V. under one or more contributor | ||
* license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright | ||
* ownership. Elasticsearch B.V. licenses this file to you under | ||
* the Apache License, Version 2.0 (the "License"); you may | ||
* not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, | ||
* software distributed under the License is distributed on an | ||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
* KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations | ||
* under the License. | ||
*/ | ||
|
||
import Path from 'path'; | ||
|
||
import { focusBundles } from './focus_bundles'; | ||
import { Bundle } from '../common'; | ||
|
||
function createBundle(id: string, deps: ReturnType<Bundle['readBundleDeps']>) { | ||
const bundle = new Bundle({ | ||
type: id === 'core' ? 'entry' : 'plugin', | ||
id, | ||
contextDir: Path.resolve('/kibana/plugins', id), | ||
outputDir: Path.resolve('/kibana/plugins', id, 'target/public'), | ||
publicDirNames: ['public'], | ||
sourceRoot: Path.resolve('/kibana'), | ||
}); | ||
|
||
jest.spyOn(bundle, 'readBundleDeps').mockReturnValue(deps); | ||
|
||
return bundle; | ||
} | ||
|
||
const BUNDLES = [ | ||
createBundle('core', { | ||
implicit: [], | ||
explicit: [], | ||
}), | ||
createBundle('foo', { | ||
implicit: ['core'], | ||
explicit: [], | ||
}), | ||
createBundle('bar', { | ||
implicit: ['core'], | ||
explicit: ['foo'], | ||
}), | ||
createBundle('baz', { | ||
implicit: ['core'], | ||
explicit: ['bar'], | ||
}), | ||
createBundle('box', { | ||
implicit: ['core'], | ||
explicit: ['foo'], | ||
}), | ||
]; | ||
|
||
function test(filters: string[]) { | ||
return focusBundles(filters, BUNDLES) | ||
.map((b) => b.id) | ||
.sort((a, b) => a.localeCompare(b)) | ||
.join(', '); | ||
} | ||
|
||
it('returns all bundles when no focus filters are defined', () => { | ||
expect(test([])).toMatchInlineSnapshot(`"bar, baz, box, core, foo"`); | ||
}); | ||
|
||
it('includes a single instance of all implicit and explicit dependencies', () => { | ||
expect(test(['core'])).toMatchInlineSnapshot(`"core"`); | ||
expect(test(['foo'])).toMatchInlineSnapshot(`"core, foo"`); | ||
expect(test(['bar'])).toMatchInlineSnapshot(`"bar, core, foo"`); | ||
expect(test(['baz'])).toMatchInlineSnapshot(`"bar, baz, core, foo"`); | ||
expect(test(['box'])).toMatchInlineSnapshot(`"box, core, foo"`); | ||
}); |
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,44 @@ | ||
/* | ||
* Licensed to Elasticsearch B.V. under one or more contributor | ||
* license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright | ||
* ownership. Elasticsearch B.V. licenses this file to you under | ||
* the Apache License, Version 2.0 (the "License"); you may | ||
* not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, | ||
* software distributed under the License is distributed on an | ||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
* KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations | ||
* under the License. | ||
*/ | ||
|
||
import { Bundle } from '../common'; | ||
import { filterById } from './filter_by_id'; | ||
|
||
export function focusBundles(filters: string[], bundles: Bundle[]) { | ||
if (!filters.length) { | ||
return [...bundles]; | ||
} | ||
|
||
const queue = new Set<Bundle>(filterById(filters, bundles)); | ||
const focused: Bundle[] = []; | ||
|
||
for (const bundle of queue) { | ||
focused.push(bundle); | ||
|
||
const { explicit, implicit } = bundle.readBundleDeps(); | ||
const depIds = [...explicit, ...implicit]; | ||
if (depIds.length) { | ||
for (const dep of filterById(depIds, bundles)) { | ||
queue.add(dep); | ||
} | ||
} | ||
} | ||
|
||
return focused; | ||
} |
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