Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

implement includeCoreBundle: boolean config #30

Merged
merged 1 commit into from
Apr 21, 2020
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
10 changes: 9 additions & 1 deletion packages/kbn-optimizer/src/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,11 @@ run(
throw createFlagError('expected --cache to have no value');
}

const includeCoreBundle = flags.core ?? true;
if (typeof includeCoreBundle !== 'boolean') {
throw createFlagError('expected --core to have no value');
}

const dist = flags.dist ?? false;
if (typeof dist !== 'boolean') {
throw createFlagError('expected --dist to have no value');
Expand Down Expand Up @@ -87,6 +92,7 @@ run(
profileWebpack,
extraPluginScanDirs,
inspectWorkers,
includeCoreBundle,
});

await runOptimizer(config)
Expand All @@ -95,9 +101,10 @@ run(
},
{
flags: {
boolean: ['watch', 'oss', 'examples', 'dist', 'cache', 'profile', 'inspect-workers'],
boolean: ['core', 'watch', 'oss', 'examples', 'dist', 'cache', 'profile', 'inspect-workers'],
string: ['workers', 'scan-dir'],
default: {
core: true,
examples: true,
cache: true,
'inspect-workers': true,
Expand All @@ -107,6 +114,7 @@ run(
--workers max number of workers to use
--oss only build oss plugins
--profile profile the webpack builds and write stats.json files to build outputs
--no-core disable generating the core bundle
--no-cache disable the cache
--no-examples don't build the example plugins
--dist create bundles that are suitable for inclusion in the Kibana distributable
Expand Down

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ it('builds expected bundles, saves bundle counts to metadata', async () => {
(msg.event?.type === 'bundle cached' || msg.event?.type === 'bundle not cached') &&
msg.state.phase === 'initializing'
);
assert('produce three bundle cache events while initializing', bundleCacheStates.length === 3);
assert('produce two bundle cache events while initializing', bundleCacheStates.length === 2);

const initializedStates = msgs.filter(msg => msg.state.phase === 'initialized');
assert('produce at least one initialized event', initializedStates.length >= 1);
Expand All @@ -101,12 +101,12 @@ it('builds expected bundles, saves bundle counts to metadata', async () => {

const runningStates = msgs.filter(msg => msg.state.phase === 'running');
assert(
'produce four or five "running" states',
runningStates.length === 4 || runningStates.length === 5
'produce two or three "running" states',
runningStates.length === 2 || runningStates.length === 3
);

const bundleNotCachedEvents = msgs.filter(msg => msg.event?.type === 'bundle not cached');
assert('produce three "bundle not cached" events', bundleNotCachedEvents.length === 3);
assert('produce two "bundle not cached" events', bundleNotCachedEvents.length === 2);

const successStates = msgs.filter(msg => msg.state.phase === 'success');
assert(
Expand All @@ -124,10 +124,6 @@ it('builds expected bundles, saves bundle counts to metadata', async () => {
);
assert('produce zero unexpected states', otherStates.length === 0, otherStates);

expect(
Fs.readFileSync(Path.resolve(MOCK_REPO_DIR, 'src/core/target/public/core.entry.js'), 'utf8')
).toMatchSnapshot('core bundle');

expect(
Fs.readFileSync(Path.resolve(MOCK_REPO_DIR, 'plugins/foo/target/public/foo.plugin.js'), 'utf8')
).toMatchSnapshot('foo bundle');
Expand Down Expand Up @@ -202,7 +198,6 @@ it('uses cache on second run and exist cleanly', async () => {
"initializing",
"initializing",
"initializing",
"initializing",
"initialized",
"success",
]
Expand Down
30 changes: 0 additions & 30 deletions packages/kbn-optimizer/src/integration_tests/bundle_cache.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,11 +83,6 @@ it('emits "bundle cached" event when everything is updated', async () => {

expect(cacheEvents).toMatchInlineSnapshot(`
Array [
Object {
"bundle": <Bundle>,
"reason": "missing optimizer cache key",
"type": "bundle not cached",
},
Object {
"bundle": <Bundle>,
"type": "bundle cached",
Expand Down Expand Up @@ -133,11 +128,6 @@ it('emits "bundle not cached" event when cacheKey is up to date but caching is d
"reason": "cache disabled",
"type": "bundle not cached",
},
Object {
"bundle": <Bundle>,
"reason": "cache disabled",
"type": "bundle not cached",
},
]
`);
});
Expand Down Expand Up @@ -178,11 +168,6 @@ it('emits "bundle not cached" event when optimizerCacheKey is missing', async ()
"reason": "missing optimizer cache key",
"type": "bundle not cached",
},
Object {
"bundle": <Bundle>,
"reason": "missing optimizer cache key",
"type": "bundle not cached",
},
]
`);
});
Expand Down Expand Up @@ -228,11 +213,6 @@ it('emits "bundle not cached" event when optimizerCacheKey is outdated, includes
"reason": "optimizer cache key mismatch",
"type": "bundle not cached",
},
Object {
"bundle": <Bundle>,
"reason": "missing optimizer cache key",
"type": "bundle not cached",
},
]
`);
});
Expand Down Expand Up @@ -271,11 +251,6 @@ it('emits "bundle not cached" event when cacheKey is missing', async () => {
"reason": "missing cache key",
"type": "bundle not cached",
},
Object {
"bundle": <Bundle>,
"reason": "missing optimizer cache key",
"type": "bundle not cached",
},
]
`);
});
Expand Down Expand Up @@ -311,11 +286,6 @@ it('emits "bundle not cached" event when cacheKey is outdated', async () => {

expect(cacheEvents).toMatchInlineSnapshot(`
Array [
Object {
"bundle": <Bundle>,
"reason": "missing optimizer cache key",
"type": "bundle not cached",
},
Object {
"bundle": <Bundle>,
"diff": "- Expected
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,13 @@

import { createAbsolutePathSerializer } from '@kbn/dev-utils';

import { getBundles } from './get_bundles';
import { getPluginBundles } from './get_plugin_bundles';

expect.addSnapshotSerializer(createAbsolutePathSerializer('/repo'));

it('returns a bundle for core and each plugin', () => {
expect(
getBundles(
getPluginBundles(
[
{
directory: '/repo/plugins/foo',
Expand All @@ -47,14 +47,6 @@ it('returns a bundle for core and each plugin', () => {
).map(b => b.toSpec())
).toMatchInlineSnapshot(`
Array [
Object {
"contextDir": <absolute path>/src/core,
"entry": "./public/entry_point",
"id": "core",
"outputDir": <absolute path>/src/core/target/public,
"sourceRoot": <absolute path>,
"type": "entry",
},
Object {
"contextDir": <absolute path>/plugins/foo,
"entry": "./public/index",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,17 +23,8 @@ import { Bundle } from '../common';

import { KibanaPlatformPlugin } from './kibana_platform_plugins';

export function getBundles(plugins: KibanaPlatformPlugin[], repoRoot: string) {
const coreBundle = new Bundle({
type: 'entry',
id: 'core',
entry: './public/entry_point',
sourceRoot: repoRoot,
contextDir: Path.resolve(repoRoot, 'src/core'),
outputDir: Path.resolve(repoRoot, 'src/core/target/public'),
});

const pluginBundles = plugins
export function getPluginBundles(plugins: KibanaPlatformPlugin[], repoRoot: string) {
return plugins
.filter(p => p.isUiPlugin)
.map(
p =>
Expand All @@ -46,6 +37,4 @@ export function getBundles(plugins: KibanaPlatformPlugin[], repoRoot: string) {
outputDir: Path.resolve(p.directory, 'target/public'),
})
);

return [coreBundle, ...pluginBundles];
}
28 changes: 22 additions & 6 deletions packages/kbn-optimizer/src/optimizer/optimizer_config.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

jest.mock('./assign_bundles_to_workers.ts');
jest.mock('./kibana_platform_plugins.ts');
jest.mock('./get_bundles.ts');
jest.mock('./get_plugin_bundles.ts');

import Path from 'path';
import Os from 'os';
Expand Down Expand Up @@ -90,6 +90,7 @@ describe('OptimizerConfig::parseOptions()', () => {
Object {
"cache": true,
"dist": false,
"includeCoreBundle": false,
"inspectWorkers": false,
"maxWorkerCount": 2,
"pluginPaths": Array [],
Expand All @@ -114,6 +115,7 @@ describe('OptimizerConfig::parseOptions()', () => {
Object {
"cache": false,
"dist": false,
"includeCoreBundle": false,
"inspectWorkers": false,
"maxWorkerCount": 2,
"pluginPaths": Array [],
Expand All @@ -138,6 +140,7 @@ describe('OptimizerConfig::parseOptions()', () => {
Object {
"cache": true,
"dist": false,
"includeCoreBundle": false,
"inspectWorkers": false,
"maxWorkerCount": 2,
"pluginPaths": Array [],
Expand All @@ -164,6 +167,7 @@ describe('OptimizerConfig::parseOptions()', () => {
Object {
"cache": true,
"dist": false,
"includeCoreBundle": false,
"inspectWorkers": false,
"maxWorkerCount": 2,
"pluginPaths": Array [],
Expand All @@ -187,6 +191,7 @@ describe('OptimizerConfig::parseOptions()', () => {
Object {
"cache": true,
"dist": false,
"includeCoreBundle": false,
"inspectWorkers": false,
"maxWorkerCount": 2,
"pluginPaths": Array [],
Expand All @@ -210,6 +215,7 @@ describe('OptimizerConfig::parseOptions()', () => {
Object {
"cache": true,
"dist": false,
"includeCoreBundle": false,
"inspectWorkers": false,
"maxWorkerCount": 100,
"pluginPaths": Array [],
Expand All @@ -230,6 +236,7 @@ describe('OptimizerConfig::parseOptions()', () => {
Object {
"cache": false,
"dist": false,
"includeCoreBundle": false,
"inspectWorkers": false,
"maxWorkerCount": 100,
"pluginPaths": Array [],
Expand All @@ -250,6 +257,7 @@ describe('OptimizerConfig::parseOptions()', () => {
Object {
"cache": false,
"dist": false,
"includeCoreBundle": false,
"inspectWorkers": false,
"maxWorkerCount": 100,
"pluginPaths": Array [],
Expand All @@ -271,6 +279,7 @@ describe('OptimizerConfig::parseOptions()', () => {
Object {
"cache": false,
"dist": false,
"includeCoreBundle": false,
"inspectWorkers": false,
"maxWorkerCount": 100,
"pluginPaths": Array [],
Expand All @@ -292,6 +301,7 @@ describe('OptimizerConfig::parseOptions()', () => {
Object {
"cache": true,
"dist": false,
"includeCoreBundle": false,
"inspectWorkers": false,
"maxWorkerCount": 100,
"pluginPaths": Array [],
Expand All @@ -314,7 +324,7 @@ describe('OptimizerConfig::create()', () => {
.assignBundlesToWorkers;
const findKibanaPlatformPlugins: jest.Mock = jest.requireMock('./kibana_platform_plugins.ts')
.findKibanaPlatformPlugins;
const getBundles: jest.Mock = jest.requireMock('./get_bundles.ts').getBundles;
const getPluginBundles: jest.Mock = jest.requireMock('./get_plugin_bundles.ts').getPluginBundles;

beforeEach(() => {
if ('mock' in OptimizerConfig.parseOptions) {
Expand All @@ -326,7 +336,7 @@ describe('OptimizerConfig::create()', () => {
{ config: Symbol('worker config 2') },
]);
findKibanaPlatformPlugins.mockReturnValue(Symbol('new platform plugins'));
getBundles.mockReturnValue(Symbol('bundles'));
getPluginBundles.mockReturnValue([Symbol('bundle1'), Symbol('bundle2')]);

jest.spyOn(OptimizerConfig, 'parseOptions').mockImplementation((): any => ({
cache: Symbol('parsed cache'),
Expand All @@ -348,7 +358,10 @@ describe('OptimizerConfig::create()', () => {

expect(config).toMatchInlineSnapshot(`
OptimizerConfig {
"bundles": Symbol(bundles),
"bundles": Array [
Symbol(bundle1),
Symbol(bundle2),
],
"cache": Symbol(parsed cache),
"dist": Symbol(parsed dist),
"inspectWorkers": Symbol(parsed inspect workers),
Expand Down Expand Up @@ -383,7 +396,7 @@ describe('OptimizerConfig::create()', () => {
}
`);

expect(getBundles.mock).toMatchInlineSnapshot(`
expect(getPluginBundles.mock).toMatchInlineSnapshot(`
Object {
"calls": Array [
Array [
Expand All @@ -400,7 +413,10 @@ describe('OptimizerConfig::create()', () => {
"results": Array [
Object {
"type": "return",
"value": Symbol(bundles),
"value": Array [
Symbol(bundle1),
Symbol(bundle2),
],
},
],
}
Expand Down
Loading