mirror of
https://github.com/elastic/kibana.git
synced 2025-06-28 11:05:39 -04:00
Move node-libs-browser
to ui-shared-deps-npm
(#130877)
Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com>
This commit is contained in:
parent
26217f3a7a
commit
ac8df39f07
5 changed files with 69 additions and 0 deletions
|
@ -0,0 +1,53 @@
|
||||||
|
/*
|
||||||
|
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
|
||||||
|
* or more contributor license agreements. Licensed under the Elastic License
|
||||||
|
* 2.0 and the Server Side Public License, v 1; you may not use this file except
|
||||||
|
* in compliance with, at your election, the Elastic License 2.0 or the Server
|
||||||
|
* Side Public License, v 1.
|
||||||
|
*/
|
||||||
|
|
||||||
|
import Path from 'path';
|
||||||
|
|
||||||
|
import { run } from '@kbn/dev-utils';
|
||||||
|
import { REPO_ROOT } from '@kbn/utils';
|
||||||
|
|
||||||
|
import { OptimizerConfig } from '../optimizer';
|
||||||
|
import { parseStats, inAnyEntryChunk } from './parse_stats';
|
||||||
|
|
||||||
|
export async function runFindNodeLibsBrowserPolyfillsInEntryBundlesCli() {
|
||||||
|
run(async ({ log }) => {
|
||||||
|
const config = OptimizerConfig.create({
|
||||||
|
includeCoreBundle: true,
|
||||||
|
repoRoot: REPO_ROOT,
|
||||||
|
});
|
||||||
|
|
||||||
|
const paths = config.bundles.map((b) => Path.resolve(b.outputDir, 'stats.json'));
|
||||||
|
|
||||||
|
log.info('analyzing', paths.length, 'stats files');
|
||||||
|
log.verbose(paths);
|
||||||
|
|
||||||
|
const imports = new Set();
|
||||||
|
for (const path of paths) {
|
||||||
|
const stats = parseStats(path);
|
||||||
|
|
||||||
|
for (const module of stats.modules) {
|
||||||
|
if (!inAnyEntryChunk(stats, module)) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Relying on module name instead of actual imports because these are usual polyfills that assume the global
|
||||||
|
// Node.js environment when development (i.e.: Buffer doesn't require an import to be used).
|
||||||
|
if (module.name.includes('node-libs-browser/node_modules/')) {
|
||||||
|
imports.add(module.name);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
log.success('found', imports.size, 'node-libs-browser/* imports in entry bundles');
|
||||||
|
log.write(
|
||||||
|
Array.from(imports, (i) => `'${i}',`)
|
||||||
|
.sort()
|
||||||
|
.join('\n')
|
||||||
|
);
|
||||||
|
});
|
||||||
|
}
|
|
@ -7,3 +7,4 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
export * from './find_babel_runtime_helpers_in_entry_bundles';
|
export * from './find_babel_runtime_helpers_in_entry_bundles';
|
||||||
|
export * from './find_node_libs_browser_polyfills_in_entry_bundles';
|
||||||
|
|
|
@ -20,6 +20,7 @@ const partialObject = <P extends Props>(props: P) => {
|
||||||
export type Module = TypeOf<typeof moduleSchema>;
|
export type Module = TypeOf<typeof moduleSchema>;
|
||||||
const moduleSchema = partialObject({
|
const moduleSchema = partialObject({
|
||||||
identifier: schema.string(),
|
identifier: schema.string(),
|
||||||
|
name: schema.string(),
|
||||||
chunks: schema.arrayOf(schema.oneOf([schema.string(), schema.number()])),
|
chunks: schema.arrayOf(schema.oneOf([schema.string(), schema.number()])),
|
||||||
reasons: schema.arrayOf(
|
reasons: schema.arrayOf(
|
||||||
partialObject({
|
partialObject({
|
||||||
|
|
|
@ -37,6 +37,10 @@ module.exports = (_, argv) => {
|
||||||
'regenerator-runtime/runtime',
|
'regenerator-runtime/runtime',
|
||||||
'whatwg-fetch',
|
'whatwg-fetch',
|
||||||
'symbol-observable',
|
'symbol-observable',
|
||||||
|
// Parts of node-libs-browser that are used in many places across Kibana
|
||||||
|
'buffer',
|
||||||
|
'punycode',
|
||||||
|
'util',
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* babel runtime helpers referenced from entry chunks
|
* babel runtime helpers referenced from entry chunks
|
||||||
|
|
10
scripts/find_node_libs_browser_polyfills_in_use.js
Normal file
10
scripts/find_node_libs_browser_polyfills_in_use.js
Normal file
|
@ -0,0 +1,10 @@
|
||||||
|
/*
|
||||||
|
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
|
||||||
|
* or more contributor license agreements. Licensed under the Elastic License
|
||||||
|
* 2.0 and the Server Side Public License, v 1; you may not use this file except
|
||||||
|
* in compliance with, at your election, the Elastic License 2.0 or the Server
|
||||||
|
* Side Public License, v 1.
|
||||||
|
*/
|
||||||
|
|
||||||
|
require('../src/setup_node_env/no_transpilation');
|
||||||
|
require('@kbn/optimizer').runFindNodeLibsBrowserPolyfillsInEntryBundlesCli();
|
Loading…
Add table
Add a link
Reference in a new issue