-
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.
Merge branch 'main' into fix/telemetry-notice
- Loading branch information
Showing
104 changed files
with
923 additions
and
2,809 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
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
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
52 changes: 52 additions & 0 deletions
52
...es/kbn-optimizer/src/babel_runtime_helpers/find_babel_runtime_helpers_in_entry_bundles.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,52 @@ | ||
/* | ||
* 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, REPO_ROOT } from '@kbn/dev-utils'; | ||
|
||
import { OptimizerConfig } from '../optimizer'; | ||
import { parseStats, inAnyEntryChunk } from './parse_stats'; | ||
|
||
export async function runFindBabelHelpersInEntryBundlesCli() { | ||
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; | ||
} | ||
|
||
for (const { userRequest } of module.reasons) { | ||
if (userRequest.startsWith('@babel/runtime/')) { | ||
imports.add(userRequest); | ||
} | ||
} | ||
} | ||
} | ||
|
||
log.success('found', imports.size, '@babel/register imports in entry bundles'); | ||
log.write( | ||
Array.from(imports, (i) => `'${i}',`) | ||
.sort() | ||
.join('\n') | ||
); | ||
}); | ||
} |
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,9 @@ | ||
/* | ||
* 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. | ||
*/ | ||
|
||
export * from './find_babel_runtime_helpers_in_entry_bundles'; |
79 changes: 79 additions & 0 deletions
79
packages/kbn-optimizer/src/babel_runtime_helpers/parse_stats.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,79 @@ | ||
/* | ||
* 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 Fs from 'fs'; | ||
|
||
import dedent from 'dedent'; | ||
import { schema, Props, TypeOf } from '@kbn/config-schema'; | ||
|
||
const partialObject = <P extends Props>(props: P) => { | ||
return schema.object(props, { | ||
unknowns: 'ignore', | ||
}); | ||
}; | ||
|
||
export type Module = TypeOf<typeof moduleSchema>; | ||
const moduleSchema = partialObject({ | ||
identifier: schema.string(), | ||
chunks: schema.arrayOf(schema.oneOf([schema.string(), schema.number()])), | ||
reasons: schema.arrayOf( | ||
partialObject({ | ||
userRequest: schema.string(), | ||
}) | ||
), | ||
}); | ||
|
||
export type Chunk = TypeOf<typeof chunkSchema>; | ||
const chunkSchema = partialObject({ | ||
id: schema.oneOf([schema.string(), schema.number()]), | ||
entry: schema.boolean(), | ||
initial: schema.boolean(), | ||
}); | ||
|
||
const statsSchema = partialObject({ | ||
chunks: schema.arrayOf(chunkSchema), | ||
modules: schema.arrayOf(moduleSchema), | ||
}); | ||
|
||
export interface Stats { | ||
path: string; | ||
modules: Module[]; | ||
chunks: Chunk[]; | ||
} | ||
export function parseStats(path: string): Stats { | ||
try { | ||
return { | ||
path, | ||
...statsSchema.validate(JSON.parse(Fs.readFileSync(path, 'utf-8'))), | ||
}; | ||
} catch (error) { | ||
if (error.code === 'ENOENT') { | ||
throw new Error(dedent` | ||
unable to find stats file at [${path}]. Make sure you run the following | ||
before running this script: | ||
node scripts/build_kibana_platform_plugins --dist --profile | ||
`); | ||
} | ||
|
||
throw error; | ||
} | ||
} | ||
|
||
export function inAnyEntryChunk(stats: Stats, module: Module): boolean { | ||
return module.chunks.some((id) => { | ||
const chunk = stats.chunks.find((c) => c.id === id); | ||
if (!chunk) { | ||
throw new Error( | ||
`unable to find chunk ${id} for module ${module.identifier} in ${stats.path}` | ||
); | ||
} | ||
|
||
return chunk.entry || chunk.initial; | ||
}); | ||
} |
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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').runFindBabelHelpersInEntryBundlesCli(); |
Oops, something went wrong.