mirror of
https://github.com/grafana/grafana.git
synced 2025-08-01 07:32:12 +08:00
Build: Introduce ESM and Treeshaking to NPM package builds (#51517)
* Revert "Chore: Bump terser to fix security vulnerability (#53052)" This reverts commit 7ae74d2a18f961dfc868bcab4c380ef910e36884. * feat: use tsc and rollup directly with esbuild and publishConfig, files props * refactor(grafana-data): fix isolatedModules re-export type error * refactor(grafana-data): import paths from src not package name * refactor(rollup): fix dts output.file * chore(grafana-schema): delete dashboard_experimental.gen.ts - cannot work with isolatedModules * refactor(grafana-e2e-selectors): fix export types isolatedModules error * refactor(grafana-runtime): fix isolatedModules re-export type error * refactor(grafana-ui): fix isolatedModules re-export type error * feat(grafana-ui): use named imports for treeshaking * refactor(grafana-ui): use named imports for treeshaking * feat: react and react-dom as peerDeps for packages * feat(grafana-ui): emotion packages as peerDeps * feat(grafana-e2e): use tsc, rollup, esbuild for bundling * chore(packages): clean up redundant dependencies * chore(toolkit): deprecate unused package:build task * chore(schema): put back dashboard_experimental and exclude to prevent isolatedModules error * docs(packages): update readme * chore(storybook): disable isolatedModules for builds * chore: relax peerDeps for emotion and react * revert(grafana-ui): put @emotion dependencies back * refactor: replace relative package imports with package name * build(packages): set emitDeclaration false for typecheck scripts to work * test(publicdashboarddatasource): move test next to implementation. try to appease the betterer gods * chore(storybook): override ts-node config for storybook compilation * refactor(grafana-data): use ternary so babel doesnt complain about expecting flow types * chore(toolkit): prefer files and publishConfig package.json props over copying * build(npm): remove --contents dist arg from publishing commands * chore(packages): introduce sideEffects prop to package.json to hint package can be treeshaken * chore(packages): remove redundant index.js files * feat(packages): set publishConfig.access to public * feat(packages): use yarn berry and npm for packaging and publishing * refactor(packages): simplify rollup configs * chore(schema): add comment explaining need to exclude dashboard_experimental * revert(toolkit): put back clean to prevent cli failures * ci(packages): run packages:pack before a canary publish * chore(gitignore): add npm-artifacts directory to ignore list * test(publicdashboarddatasource): fix module mocking * chore(packages): delete package.tgz when running clean * chore(grafana-data): move dependencies from devDeps to prevent build resolution errors
This commit is contained in:
@ -30,6 +30,9 @@ export const run = (includeInternalScripts = false) => {
|
||||
.option('-s, --scope <packages>', 'packages=[data|runtime|ui|toolkit|e2e|e2e-selectors]')
|
||||
.description('Builds @grafana/* package to packages/grafana-*/dist')
|
||||
.action(async (cmd) => {
|
||||
console.warn(
|
||||
'@grafana/toolkit package:build task is deprecated and will be removed in @grafana/toolkit@10.0.0.'
|
||||
);
|
||||
await execTask(buildPackageTask)({
|
||||
scope: cmd.scope,
|
||||
});
|
||||
|
@ -22,34 +22,8 @@ const compile = () =>
|
||||
}
|
||||
});
|
||||
|
||||
const savePackage = ({ path, pkg }: { path: string; pkg: {} }) =>
|
||||
useSpinner('Updating package.json', async () => {
|
||||
new Promise<void>((resolve, reject) => {
|
||||
fs.writeFile(path, JSON.stringify(pkg, null, 2), (err) => {
|
||||
if (err) {
|
||||
reject(err);
|
||||
return;
|
||||
}
|
||||
resolve();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
const preparePackage = async (pkg: any) => {
|
||||
pkg.bin = {
|
||||
'grafana-toolkit': './bin/grafana-toolkit.js',
|
||||
};
|
||||
|
||||
await savePackage({
|
||||
path: `${cwd}/dist/package.json`,
|
||||
pkg,
|
||||
});
|
||||
};
|
||||
|
||||
const copyFiles = () => {
|
||||
const files = [
|
||||
'README.md',
|
||||
'CHANGELOG.md',
|
||||
'config/circleci/config.yml',
|
||||
'bin/grafana-toolkit.js',
|
||||
'src/config/prettier.plugin.config.json',
|
||||
@ -115,7 +89,6 @@ const toolkitBuildTaskRunner: TaskRunner<ToolkitBuildOptions> = async () => {
|
||||
|
||||
await clean();
|
||||
await compile();
|
||||
await preparePackage(pkg);
|
||||
fs.mkdirSync('./dist/bin');
|
||||
fs.mkdirSync('./dist/sass');
|
||||
await copyFiles();
|
||||
|
Reference in New Issue
Block a user