Skip to content
This repository has been archived by the owner on Mar 31, 2024. It is now read-only.

Commit

Permalink
Revert "[7.x] [kbn/optimizer] fix ui/* url rewrites in dist (elastic#…
Browse files Browse the repository at this point in the history
…58627) (elastic#59093)"

This reverts commit 1254203.
  • Loading branch information
spalger committed Apr 7, 2020
1 parent 2f7930f commit c1b5559
Show file tree
Hide file tree
Showing 13 changed files with 547 additions and 291 deletions.
1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -349,7 +349,6 @@
"@types/mustache": "^0.8.31",
"@types/node": ">=10.17.17 <10.20.0",
"@types/node-forge": "^0.9.0",
"@types/normalize-path": "^3.0.0",
"@types/numeral": "^0.0.26",
"@types/opn": "^5.1.0",
"@types/pegjs": "^0.10.1",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
* under the License.
*/

import './legacy/styles.scss';
import { fooLibFn } from '../../foo/public/index';
export * from './lib';
export { fooLibFn };

This file was deleted.

This file was deleted.

This file was deleted.

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,14 @@ import { inspect } from 'util';
import cpy from 'cpy';
import del from 'del';
import { toArray, tap } from 'rxjs/operators';
import { createAbsolutePathSerializer, ToolingLog, REPO_ROOT } from '@kbn/dev-utils';
import { runOptimizer, OptimizerConfig, OptimizerUpdate, logOptimizerState } from '@kbn/optimizer';
import { createAbsolutePathSerializer } from '@kbn/dev-utils';
import { runOptimizer, OptimizerConfig, OptimizerUpdate } from '@kbn/optimizer';

const TMP_DIR = Path.resolve(__dirname, '../__fixtures__/__tmp__');
const MOCK_REPO_SRC = Path.resolve(__dirname, '../__fixtures__/mock_repo');
const MOCK_REPO_DIR = Path.resolve(TMP_DIR, 'mock_repo');

expect.addSnapshotSerializer(createAbsolutePathSerializer(REPO_ROOT));
expect.addSnapshotSerializer(createAbsolutePathSerializer(MOCK_REPO_DIR));

beforeAll(async () => {
await del(TMP_DIR);
Expand All @@ -51,25 +51,20 @@ it('builds expected bundles, saves bundle counts to metadata', async () => {
repoRoot: MOCK_REPO_DIR,
pluginScanDirs: [Path.resolve(MOCK_REPO_DIR, 'plugins')],
maxWorkerCount: 1,
dist: true,
});

expect(config).toMatchSnapshot('OptimizerConfig');

const log = new ToolingLog({
level: 'error',
writeTo: {
write(chunk) {
if (chunk.endsWith('\n')) {
chunk = chunk.slice(0, -1);
}
// eslint-disable-next-line no-console
console.error(chunk);
},
},
});
const msgs = await runOptimizer(config)
.pipe(logOptimizerState(log, config), toArray())
.pipe(
tap(state => {
if (state.event?.type === 'worker stdio') {
// eslint-disable-next-line no-console
console.log('worker', state.event.stream, state.event.chunk.toString('utf8'));
}
}),
toArray()
)
.toPromise();

const assert = (statement: string, truth: boolean, altStates?: OptimizerUpdate[]) => {
Expand Down Expand Up @@ -138,31 +133,23 @@ it('builds expected bundles, saves bundle counts to metadata', async () => {
expect(foo.cache.getModuleCount()).toBe(3);
expect(foo.cache.getReferencedFiles()).toMatchInlineSnapshot(`
Array [
<absolute path>/packages/kbn-optimizer/src/__fixtures__/__tmp__/mock_repo/plugins/foo/public/ext.ts,
<absolute path>/packages/kbn-optimizer/src/__fixtures__/__tmp__/mock_repo/plugins/foo/public/index.ts,
<absolute path>/packages/kbn-optimizer/src/__fixtures__/__tmp__/mock_repo/plugins/foo/public/lib.ts,
<absolute path>/plugins/foo/public/ext.ts,
<absolute path>/plugins/foo/public/index.ts,
<absolute path>/plugins/foo/public/lib.ts,
]
`);

const bar = config.bundles.find(b => b.id === 'bar')!;
expect(bar).toBeTruthy();
bar.cache.refresh();
expect(bar.cache.getModuleCount()).toBe(
// code + styles + style/css-loader runtime
14
);

expect(bar.cache.getModuleCount()).toBe(5);
expect(bar.cache.getReferencedFiles()).toMatchInlineSnapshot(`
Array [
<absolute path>/node_modules/css-loader/package.json,
<absolute path>/node_modules/style-loader/package.json,
<absolute path>/packages/kbn-optimizer/src/__fixtures__/__tmp__/mock_repo/plugins/bar/public/index.ts,
<absolute path>/packages/kbn-optimizer/src/__fixtures__/__tmp__/mock_repo/plugins/bar/public/legacy/styles.scss,
<absolute path>/packages/kbn-optimizer/src/__fixtures__/__tmp__/mock_repo/plugins/bar/public/lib.ts,
<absolute path>/packages/kbn-optimizer/src/__fixtures__/__tmp__/mock_repo/plugins/foo/public/ext.ts,
<absolute path>/packages/kbn-optimizer/src/__fixtures__/__tmp__/mock_repo/plugins/foo/public/index.ts,
<absolute path>/packages/kbn-optimizer/src/__fixtures__/__tmp__/mock_repo/plugins/foo/public/lib.ts,
<absolute path>/packages/kbn-optimizer/src/__fixtures__/__tmp__/mock_repo/src/legacy/ui/public/icon.svg,
<absolute path>/plugins/foo/public/ext.ts,
<absolute path>/plugins/foo/public/index.ts,
<absolute path>/plugins/foo/public/lib.ts,
<absolute path>/plugins/bar/public/index.ts,
<absolute path>/plugins/bar/public/lib.ts,
]
`);
});
Expand All @@ -172,7 +159,6 @@ it('uses cache on second run and exist cleanly', async () => {
repoRoot: MOCK_REPO_DIR,
pluginScanDirs: [Path.resolve(MOCK_REPO_DIR, 'plugins')],
maxWorkerCount: 1,
dist: true,
});

const msgs = await runOptimizer(config)
Expand Down

This file was deleted.

43 changes: 0 additions & 43 deletions packages/kbn-optimizer/src/worker/parse_path.ts

This file was deleted.

16 changes: 8 additions & 8 deletions packages/kbn-optimizer/src/worker/run_compilers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,9 @@ import webpack, { Stats } from 'webpack';
import * as Rx from 'rxjs';
import { mergeMap, map, mapTo, takeUntil } from 'rxjs/operators';

import { CompilerMsgs, CompilerMsg, maybeMap, Bundle, WorkerConfig, ascending } from '../common';
import { CompilerMsgs, CompilerMsg, maybeMap, Bundle, WorkerConfig } from '../common';
import { getWebpackConfig } from './webpack.config';
import { isFailureStats, failedStatsToErrorMessage } from './webpack_helpers';
import { parseFilePath } from './parse_path';
import {
isExternalModule,
isNormalModule,
Expand Down Expand Up @@ -109,19 +108,20 @@ const observeCompiler = (

for (const module of normalModules) {
const path = getModulePath(module);
const parsedPath = parseFilePath(path);

if (!parsedPath.dirs.includes('node_modules')) {
const parsedPath = Path.parse(path);
const dirSegments = parsedPath.dir.split(Path.sep);
if (!dirSegments.includes('node_modules')) {
referencedFiles.add(path);
continue;
}

const nmIndex = parsedPath.dirs.lastIndexOf('node_modules');
const isScoped = parsedPath.dirs[nmIndex + 1].startsWith('@');
const nmIndex = dirSegments.lastIndexOf('node_modules');
const isScoped = dirSegments[nmIndex + 1].startsWith('@');
referencedFiles.add(
Path.join(
parsedPath.root,
...parsedPath.dirs.slice(0, nmIndex + 1 + (isScoped ? 2 : 1)),
...dirSegments.slice(0, nmIndex + 1 + (isScoped ? 2 : 1)),
'package.json'
)
);
Expand All @@ -146,7 +146,7 @@ const observeCompiler = (
optimizerCacheKey: workerConfig.optimizerCacheKey,
cacheKey: bundle.createCacheKey(files, mtimes),
moduleCount: normalModules.length,
files: files.sort(ascending(f => f)),
files,
});

return compilerMsgs.compilerSuccess({
Expand Down
Loading

0 comments on commit c1b5559

Please sign in to comment.