Skip to content

Commit

Permalink
[CI] Auto-commit changed files from 'node scripts/eslint --no-cache -…
Browse files Browse the repository at this point in the history
…-fix'
  • Loading branch information
kibanamachine committed Mar 23, 2023
1 parent 52f6171 commit 32ea954
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 44 deletions.
17 changes: 8 additions & 9 deletions packages/kbn-optimizer/src/common/bundle.ts
Expand Up @@ -168,13 +168,15 @@ export class Bundle {
// This is only used to build legacy third party plugins in the @kbn/plugin-helpers

if (!isObj(parsed)) {
throw new Error(
`Expected [${this.manifestPath}] to be a jsonc parseable file`
);
throw new Error(`Expected [${this.manifestPath}] to be a jsonc parseable file`);
}

const requiredBundles = isObj(parsed.plugin) ? parsed.plugin.requiredBundles : parsed.requiredBundles;
const requiredPlugins = isObj(parsed.plugin) ? parsed.plugin.requiredPlugins : parsed.requiredPlugins;
const requiredBundles = isObj(parsed.plugin)
? parsed.plugin.requiredBundles
: parsed.requiredBundles;
const requiredPlugins = isObj(parsed.plugin)
? parsed.plugin.requiredPlugins
: parsed.requiredPlugins;
const requiredBundlesStringArray = toStringArray(requiredBundles);
const requiredPluginsStringArray = toStringArray(requiredPlugins);
// END-OF-TD: we just need to check for parse.plugin and not for legacy plugins manifest types
Expand All @@ -193,10 +195,7 @@ export class Bundle {

return {
explicit: [...(requiredBundlesStringArray || [])],
implicit: [
...DEFAULT_IMPLICIT_BUNDLE_DEPS,
...(requiredPluginsStringArray || [])
],
implicit: [...DEFAULT_IMPLICIT_BUNDLE_DEPS, ...(requiredPluginsStringArray || [])],
};
}
}
Expand Down
37 changes: 24 additions & 13 deletions packages/kbn-plugin-helpers/src/tasks/optimize.ts
Expand Up @@ -20,7 +20,15 @@ import { TaskContext } from '../task_context';

type WorkerMsg = { success: true; warnings: string } | { success: false; error: string };

export async function optimize({ log, dev, dist, watch, plugin, sourceDir, buildDir }: TaskContext) {
export async function optimize({
log,
dev,
dist,
watch,
plugin,
sourceDir,
buildDir,
}: TaskContext) {
if (!plugin.manifest.ui) {
return;
}
Expand All @@ -33,7 +41,7 @@ export async function optimize({ log, dev, dist, watch, plugin, sourceDir, build
testPlugins: false,
includeCoreBundle: true,
dist: !!dist,
watch: !!watch
watch: !!watch,
});

const bundle = new Bundle({
Expand Down Expand Up @@ -63,21 +71,24 @@ export async function optimize({ log, dev, dist, watch, plugin, sourceDir, build

// Observe all events from child process
const eventObservable = Rx.merge(
observeLines(proc.stdout!).pipe(
Rx.map((line) => ({ type: 'stdout', data: line }))
),
observeLines(proc.stderr!).pipe(
Rx.map((line) => ({ type: 'stderr', data: line }))
),
observeLines(proc.stdout!).pipe(Rx.map((line) => ({ type: 'stdout', data: line }))),
observeLines(proc.stderr!).pipe(Rx.map((line) => ({ type: 'stderr', data: line }))),
Rx.fromEvent<[WorkerMsg]>(proc, 'message').pipe(
Rx.map((msg) => ({ type: 'message', data: msg[0] }))
),
Rx.fromEvent<Error>(proc, 'error').pipe(
Rx.map((error) => ({ type: 'error', data: error }))
)
Rx.fromEvent<Error>(proc, 'error').pipe(Rx.map((error) => ({ type: 'error', data: error })))
);

const simpleOrWatchObservable = watch ? eventObservable : eventObservable.pipe(Rx.take(1), Rx.tap({ complete() { proc.kill('SIGKILL'); }}));
const simpleOrWatchObservable = watch
? eventObservable
: eventObservable.pipe(
Rx.take(1),
Rx.tap({
complete() {
proc.kill('SIGKILL');
},
})
);

// Subscribe to eventObservable to log events
const eventSubscription = simpleOrWatchObservable.subscribe((event) => {
Expand All @@ -96,7 +107,7 @@ export async function optimize({ log, dev, dist, watch, plugin, sourceDir, build
log.success(`browser bundle created at ${rel}`);
}
} else if (event.type === 'error') {
log.error(event.data as Error)
log.error(event.data as Error);
}
});

Expand Down
47 changes: 25 additions & 22 deletions packages/kbn-plugin-helpers/src/tasks/optimize_worker.ts
Expand Up @@ -26,30 +26,33 @@ process.on('message', (msg: any) => {
const webpackConfig = getWebpackConfig(bundle, remotes, workerConfig);
const compiler = webpack(webpackConfig);

compiler.watch({
// Example
aggregateTimeout: 300,
poll: undefined,
}, (error, stats) => {
if (error) {
send.call(process, {
success: false,
error: error.message,
});
return;
}
compiler.watch(
{
// Example
aggregateTimeout: 300,
poll: undefined,
},
(error, stats) => {
if (error) {
send.call(process, {
success: false,
error: error.message,
});
return;
}

if (stats.hasErrors()) {
send.call(process, {
success: false,
error: `Failed to compile with webpack:\n${stats.toString()}`,
});
return;
}

if (stats.hasErrors()) {
send.call(process, {
success: false,
error: `Failed to compile with webpack:\n${stats.toString()}`,
success: true,
warnings: stats.hasWarnings() ? stats.toString() : '',
});
return;
}

send.call(process, {
success: true,
warnings: stats.hasWarnings() ? stats.toString() : '',
});
});
);
});

0 comments on commit 32ea954

Please sign in to comment.