Commit c2bd36f5 by Dominik Prokop Committed by GitHub

grafana/toolkit: Find module files correctly and add basic error tracing (#19089)

* Find correct module files

* Add basic error tracing
parent ecb97488
...@@ -9,7 +9,7 @@ export const execTask = <TOptions>(task: Task<TOptions>) => async (options: TOpt ...@@ -9,7 +9,7 @@ export const execTask = <TOptions>(task: Task<TOptions>) => async (options: TOpt
await task.exec(); await task.exec();
console.groupEnd(); console.groupEnd();
} catch (e) { } catch (e) {
console.log(e); console.trace(e);
process.exit(1); process.exit(1);
} }
}; };
...@@ -10,6 +10,7 @@ export const useSpinner = <T>(spinnerLabel: string, fn: FnToSpin<T>, killProcess ...@@ -10,6 +10,7 @@ export const useSpinner = <T>(spinnerLabel: string, fn: FnToSpin<T>, killProcess
await fn(options); await fn(options);
spinner.succeed(); spinner.succeed();
} catch (e) { } catch (e) {
console.trace(e);
spinner.fail(e.message || e); spinner.fail(e.message || e);
if (killProcess) { if (killProcess) {
process.exit(1); process.exit(1);
......
import { findModuleFiles } from './webpack.plugin.config';
const fs = require('fs');
jest.mock('fs');
const modulePathsMock = [
'some/path/module.ts',
'some/path/module.ts.whatever',
'some/path/module.tsx',
'some/path/module.tsx.whatever',
'some/path/anotherFile.ts',
'some/path/anotherFile.tsx',
];
describe('Plugin webpack config', () => {
describe('findModuleTs', () => {
beforeAll(() => {
fs.statSync.mockReturnValue({
isDirectory: () => false,
});
});
it('finds module.ts and module.tsx files', () => {
const moduleFiles = findModuleFiles('/', modulePathsMock);
expect(moduleFiles.length).toBe(2);
expect(moduleFiles).toEqual(['/some/path/module.ts', '/some/path/module.tsx']);
});
});
});
...@@ -16,7 +16,7 @@ interface WebpackConfigurationOptions { ...@@ -16,7 +16,7 @@ interface WebpackConfigurationOptions {
} }
type WebpackConfigurationGetter = (options: WebpackConfigurationOptions) => webpack.Configuration; type WebpackConfigurationGetter = (options: WebpackConfigurationOptions) => webpack.Configuration;
const findModuleTs = (base: string, files?: string[], result?: string[]) => { export const findModuleFiles = (base: string, files?: string[], result?: string[]) => {
files = files || fs.readdirSync(base); files = files || fs.readdirSync(base);
result = result || []; result = result || [];
...@@ -24,9 +24,10 @@ const findModuleTs = (base: string, files?: string[], result?: string[]) => { ...@@ -24,9 +24,10 @@ const findModuleTs = (base: string, files?: string[], result?: string[]) => {
files.forEach(file => { files.forEach(file => {
const newbase = path.join(base, file); const newbase = path.join(base, file);
if (fs.statSync(newbase).isDirectory()) { if (fs.statSync(newbase).isDirectory()) {
result = findModuleTs(newbase, fs.readdirSync(newbase), result); result = findModuleFiles(newbase, fs.readdirSync(newbase), result);
} else { } else {
if (file.indexOf('module.ts') > -1) { const filename = path.basename(file);
if (/^module.tsx?$/.exec(filename)) {
// @ts-ignore // @ts-ignore
result.push(newbase); result.push(newbase);
} }
...@@ -37,7 +38,7 @@ const findModuleTs = (base: string, files?: string[], result?: string[]) => { ...@@ -37,7 +38,7 @@ const findModuleTs = (base: string, files?: string[], result?: string[]) => {
}; };
const getModuleFiles = () => { const getModuleFiles = () => {
return findModuleTs(path.resolve(process.cwd(), 'src')); return findModuleFiles(path.resolve(process.cwd(), 'src'));
}; };
const getManualChunk = (id: string) => { const getManualChunk = (id: string) => {
...@@ -206,11 +207,5 @@ export const getWebpackConfig: WebpackConfigurationGetter = options => { ...@@ -206,11 +207,5 @@ export const getWebpackConfig: WebpackConfigurationGetter = options => {
], ],
}, },
optimization, optimization,
// optimization: {
// splitChunks: {
// chunks: 'all',
// name: 'shared'
// }
// }
}; };
}; };
{ {
"extends": "../../tslint.json", "extends": "../../tslint.json",
"rules": { "rules": {
"import-blacklist": [true, ["^@grafana/runtime.*"]] "import-blacklist": [true, ["^@grafana/runtime.*"]],
"no-console": [true, "debug", "info", "time", "timeEnd"]
} }
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment