Skip to content

Commit 63d0b60

Browse files
authored
chore(NA): merge and solve conflicts with master (#54782)
1 parent e9fc194 commit 63d0b60

13 files changed

Lines changed: 216 additions & 69 deletions

File tree

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -251,6 +251,7 @@
251251
"rison-node": "1.0.2",
252252
"rxjs": "^6.5.3",
253253
"script-loader": "0.7.2",
254+
"seedrandom": "^3.0.5",
254255
"semver": "^5.5.0",
255256
"style-loader": "0.23.1",
256257
"symbol-observable": "^1.2.0",

src/dev/build/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ The majority of this logic is extracted from the grunt build that has existed fo
4444

4545
We have introduced in our bundle a webpack dll for the client vendor modules in order to improve
4646
the optimization time both in dev and in production. As for those modules we already have the
47-
code into the vendors.bundle.dll.js we have decided to delete those bundled modules from the
47+
code into the vendors_${chunk_number}.bundle.dll.js we have decided to delete those bundled modules from the
4848
distributable node_modules folder. However, in order to accomplish this, we need to exclude
4949
every node_module used in the server side code. This logic is performed
5050
under `nodejs_modules/clean_client_modules_on_dll_task.js`. In case we need to add any new cli

src/dev/build/tasks/nodejs_modules/clean_client_modules_on_dll_task.js

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -98,12 +98,16 @@ export const CleanClientModulesOnDLLTask = {
9898
// Consider this as our whiteList for the modules we can't delete
9999
const whiteListedModules = [...serverDependencies, ...kbnWebpackLoaders, ...manualExceptions];
100100

101-
// Resolve the client vendors dll manifest path
102-
const dllManifestPath = `${baseDir}/built_assets/dlls/vendors.manifest.dll.json`;
101+
// Resolve the client vendors dll manifest paths
102+
// excluding the runtime one
103+
const dllManifestPaths = await globby([
104+
`${baseDir}/built_assets/dlls/vendors_*.manifest.dll.json`,
105+
`!${baseDir}/built_assets/dlls/vendors_runtime.manifest.dll.json`,
106+
]);
103107

104108
// Get dll entries filtering out the ones
105109
// from any whitelisted module
106-
const dllEntries = await getDllEntries(dllManifestPath, whiteListedModules, baseDir);
110+
const dllEntries = await getDllEntries(dllManifestPaths, whiteListedModules, baseDir);
107111

108112
for (const relativeEntryPath of dllEntries) {
109113
const entryPath = `${baseDir}/${relativeEntryPath}`;

src/dev/build/tasks/nodejs_modules/webpack_dll.js

Lines changed: 27 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -28,27 +28,37 @@ function checkDllEntryAccess(entry, baseDir = '') {
2828
return isFileAccessible(resolvedPath);
2929
}
3030

31-
export async function getDllEntries(manifestPath, whiteListedModules, baseDir = '') {
32-
const manifest = JSON.parse(await read(manifestPath));
33-
34-
if (!manifest || !manifest.content) {
35-
// It should fails because if we don't have the manifest file
36-
// or it is malformed something wrong is happening and we
37-
// should stop
38-
throw new Error(`The following dll manifest doesn't exists: ${manifestPath}`);
39-
}
31+
export async function getDllEntries(manifestPaths, whiteListedModules, baseDir = '') {
32+
// Read and parse all manifests
33+
const manifests = await Promise.all(
34+
manifestPaths.map(async manifestPath => JSON.parse(await read(manifestPath)))
35+
);
4036

41-
const modules = Object.keys(manifest.content);
42-
if (!modules.length) {
43-
// It should fails because if we don't have any
44-
// module inside the client vendors dll something
45-
// wrong is happening and we should stop too
46-
throw new Error(`The following dll manifest is reporting an empty dll: ${manifestPath}`);
47-
}
37+
// Process and group modules from all manifests
38+
const manifestsModules = manifests.flatMap((manifest, idx) => {
39+
if (!manifest || !manifest.content) {
40+
// It should fails because if we don't have the manifest file
41+
// or it is malformed something wrong is happening and we
42+
// should stop
43+
throw new Error(`The following dll manifest doesn't exists: ${manifestPaths[idx]}`);
44+
}
45+
46+
const modules = Object.keys(manifest.content);
47+
if (!modules.length) {
48+
// It should fails because if we don't have any
49+
// module inside the client vendors dll something
50+
// wrong is happening and we should stop too
51+
throw new Error(
52+
`The following dll manifest is reporting an empty dll: ${manifestPaths[idx]}`
53+
);
54+
}
55+
56+
return modules;
57+
});
4858

4959
// Only includes modules who are not in the white list of modules
5060
// and that are node_modules
51-
return modules.filter(entry => {
61+
return manifestsModules.filter(entry => {
5262
const isWhiteListed = whiteListedModules.some(nonEntry =>
5363
normalizePosixPath(entry).includes(`node_modules/${nonEntry}`)
5464
);

src/dev/build/tasks/nodejs_modules/webpack_dll.test.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ describe('Webpack DLL Build Tasks Utils', () => {
5252

5353
isFileAccessible.mockImplementation(() => true);
5454

55-
const mockManifestPath = '/mock/mock_dll_manifest.json';
55+
const mockManifestPath = ['/mock/mock_dll_manifest.json'];
5656
const mockModulesWhitelist = ['dep1'];
5757
const dllEntries = await getDllEntries(mockManifestPath, mockModulesWhitelist);
5858

@@ -66,7 +66,7 @@ describe('Webpack DLL Build Tasks Utils', () => {
6666

6767
isFileAccessible.mockImplementation(() => false);
6868

69-
const mockManifestPath = '/mock/mock_dll_manifest.json';
69+
const mockManifestPath = ['/mock/mock_dll_manifest.json'];
7070
const mockModulesWhitelist = ['dep1'];
7171
const dllEntries = await getDllEntries(mockManifestPath, mockModulesWhitelist);
7272

@@ -78,7 +78,7 @@ describe('Webpack DLL Build Tasks Utils', () => {
7878
it('should throw an error for no manifest file', async () => {
7979
read.mockImplementationOnce(async () => noManifestMock);
8080

81-
const mockManifestPath = '/mock/mock_dll_manifest.json';
81+
const mockManifestPath = ['/mock/mock_dll_manifest.json'];
8282

8383
try {
8484
await getDllEntries(mockManifestPath, []);
@@ -92,7 +92,7 @@ describe('Webpack DLL Build Tasks Utils', () => {
9292
it('should throw an error for no manifest content field', async () => {
9393
read.mockImplementation(async () => noContentFieldManifestMock);
9494

95-
const mockManifestPath = '/mock/mock_dll_manifest.json';
95+
const mockManifestPath = ['/mock/mock_dll_manifest.json'];
9696

9797
try {
9898
await getDllEntries(mockManifestPath, []);
@@ -106,7 +106,7 @@ describe('Webpack DLL Build Tasks Utils', () => {
106106
it('should throw an error for manifest file without any content', async () => {
107107
read.mockImplementation(async () => emptyManifestContentMock);
108108

109-
const mockManifestPath = '/mock/mock_dll_manifest.json';
109+
const mockManifestPath = ['/mock/mock_dll_manifest.json'];
110110

111111
try {
112112
await getDllEntries(mockManifestPath, []);

src/legacy/ui/ui_render/bootstrap/template.js.hbs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,10 @@ if (window.__kbnStrictCsp__ && window.__kbnCspNotEnforced__) {
1313

1414
window.onload = function () {
1515
var files = [
16-
'{{dllBundlePath}}/vendors.bundle.dll.js',
16+
'{{dllBundlePath}}/vendors_runtime.bundle.dll.js',
17+
{{#each dllJsChunks}}
18+
'{{this}}',
19+
{{/each}}
1720
'{{regularBundlePath}}/kbn-ui-shared-deps/{{sharedDepsFilename}}',
1821
'{{regularBundlePath}}/commons.bundle.js',
1922
'{{regularBundlePath}}/{{appId}}.bundle.js'

src/legacy/ui/ui_render/ui_render_mixin.js

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ import * as UiSharedDeps from '@kbn/ui-shared-deps';
2525
import { AppBootstrap } from './bootstrap';
2626
// eslint-disable-next-line @kbn/eslint/no-restricted-paths
2727
import { fromRoot } from '../../../core/server/utils';
28+
import { DllCompiler } from '../../../optimize/dynamic_dll_plugin';
2829

2930
/**
3031
* @typedef {import('../../server/kbn_server').default} KbnServer
@@ -102,8 +103,14 @@ export function uiRenderMixin(kbnServer, server, config) {
102103
const basePath = config.get('server.basePath');
103104
const regularBundlePath = `${basePath}/bundles`;
104105
const dllBundlePath = `${basePath}/built_assets/dlls`;
106+
const dllStyleChunks = DllCompiler.getRawDllConfig().chunks.map(
107+
chunk => `${dllBundlePath}/vendors${chunk}.style.dll.css`
108+
);
109+
const dllJsChunks = DllCompiler.getRawDllConfig().chunks.map(
110+
chunk => `${dllBundlePath}/vendors${chunk}.bundle.dll.js`
111+
);
105112
const styleSheetPaths = [
106-
`${dllBundlePath}/vendors.style.dll.css`,
113+
...dllStyleChunks,
107114
...(darkMode
108115
? [
109116
`${basePath}/bundles/kbn-ui-shared-deps/${UiSharedDeps.darkCssDistFilename}`,
@@ -131,6 +138,7 @@ export function uiRenderMixin(kbnServer, server, config) {
131138
appId: isCore ? 'core' : app.getId(),
132139
regularBundlePath,
133140
dllBundlePath,
141+
dllJsChunks,
134142
styleSheetPaths,
135143
sharedDepsFilename: UiSharedDeps.distFilename,
136144
},

0 commit comments

Comments
 (0)