Toolkit: Remove deprecated `package:build`, `node-version-check` and `toolkit:build` commands (#67475)

pull/67476/head
Esteban Beltran 2 years ago committed by GitHub
parent 82838a2176
commit 0ec40a51eb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 5
      .betterer.results
  2. 6
      packages/grafana-toolkit/package.json
  3. 44
      packages/grafana-toolkit/src/cli/index.ts
  4. 77
      packages/grafana-toolkit/src/cli/tasks/nodeVersionChecker.ts
  5. 92
      packages/grafana-toolkit/src/cli/tasks/package.build.ts
  6. 99
      packages/grafana-toolkit/src/cli/tasks/toolkit.build.ts
  7. 27
      yarn.lock

@ -871,11 +871,6 @@ exports[`better eslint`] = {
[0, 0, 0, "Do not use any type assertions.", "5"],
[0, 0, 0, "Do not use any type assertions.", "6"]
],
"packages/grafana-toolkit/src/cli/tasks/package.build.ts:5381": [
[0, 0, 0, "Unexpected any. Specify a different type.", "0"],
[0, 0, 0, "Unexpected any. Specify a different type.", "1"],
[0, 0, 0, "Unexpected any. Specify a different type.", "2"]
],
"packages/grafana-toolkit/src/cli/tasks/task.ts:5381": [
[0, 0, 0, "Unexpected any. Specify a different type.", "0"],
[0, 0, 0, "Do not use any type assertions.", "1"],

@ -58,12 +58,11 @@
"@jest/core": "27.5.1",
"@types/eslint": "8.4.1",
"@types/jest": "27.4.1",
"@types/lodash": "4.14.181",
"@types/lodash": "^4.14.194",
"@types/node": "16.11.26",
"@types/prettier": "2.6.3",
"@types/react-dev-utils": "9.0.10",
"@types/rimraf": "3.0.2",
"@types/semver": "7.3.9",
"@types/tmp": "0.2.3",
"@typescript-eslint/eslint-plugin": "5.36.2",
"@typescript-eslint/parser": "5.36.2",
@ -90,7 +89,7 @@
"jest-junit": "13.1.0",
"less": "^4.1.2",
"less-loader": "^10.2.0",
"lodash": "^4.17.21",
"lodash": "4.17.21",
"mini-css-extract-plugin": "^2.6.0",
"ora": "^5.4.1",
"postcss": "^8.4.12",
@ -103,7 +102,6 @@
"rimraf": "3.0.2",
"sass": "^1.49.9",
"sass-loader": "^12.6.0",
"semver": "^7.3.7",
"style-loader": "^3.3.1",
"terser-webpack-plugin": "^5.3.1",
"ts-jest": "27.1.3",

@ -1,65 +1,21 @@
import chalk from 'chalk';
import { program } from 'commander';
import { nodeVersionCheckerTask } from './tasks/nodeVersionChecker';
import { buildPackageTask } from './tasks/package.build';
import { pluginBuildTask } from './tasks/plugin.build';
import { getToolkitVersion } from './tasks/plugin.utils';
import { templateTask } from './tasks/template';
import { toolkitBuildTask } from './tasks/toolkit.build';
import { execTask } from './utils/execTask';
export const run = (includeInternalScripts = false) => {
if (includeInternalScripts) {
program.option('-d, --depreciate <scripts>', 'Inform about npm script deprecation', (v) => v.split(','));
program
.command('package:build')
.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,
});
});
program
.command('node-version-check')
.description('[deprecated] Verify node version')
.action(async () => {
console.log(
chalk.yellow.bold(
` This command is deprecated and will be removed in v10. No further support will be provided. ⚠`
)
);
console.log(
'if you were reliant on this command we recommend https://www.npmjs.com/package/check-node-version'
);
await execTask(nodeVersionCheckerTask)({});
});
program
.command('debug:template')
.description('Just testing')
.action(async (cmd) => {
await execTask(templateTask)({});
});
program
.command('toolkit:build')
.description('[Deprecated] Prepares grafana/toolkit dist package')
.action(async (cmd) => {
console.log(
chalk.yellow.bold(
` This command is deprecated and will be removed in v10. No further support will be provided. ⚠`
)
);
await execTask(toolkitBuildTask)({});
});
}
program.option('-v, --version', 'Toolkit version').action(async () => {

@ -1,77 +0,0 @@
import chalk from 'chalk';
import { readFileSync } from 'fs';
import { coerce, satisfies } from 'semver';
import { Task, TaskRunner } from './task';
interface FailedVersionCheck {
file: string;
line: string;
}
interface NodeVersionCheckerOptions {}
const pattern = /(circleci\/|FROM )node\:([0-9]+(\.[0-9]+){0,2})/gm;
const packageJsonFile = 'package.json';
const failures: FailedVersionCheck[] = [];
export const nodeVersionFiles = [packageJsonFile, 'Dockerfile'];
const nodeVersionCheckerRunner: TaskRunner<NodeVersionCheckerOptions> = async () => {
// Read version from package json and treat that as the expected version in all other locations
const packageJson = require(`${process.cwd()}/${packageJsonFile}`);
const expectedVersion = packageJson.engines.node;
console.log(chalk.yellow(`Specified node version in package.json is: ${expectedVersion}`));
for (const file of nodeVersionFiles) {
const fileContent = readFileSync(`${process.cwd()}/${file}`);
const matches = fileContent.toString('utf8').match(pattern);
if (!matches) {
continue;
}
for (const match of matches) {
const actualVersion = coerce(match);
if (!actualVersion) {
failures.push({
file,
line: match,
});
continue;
}
const satisfied = satisfies(actualVersion, expectedVersion);
if (!satisfied) {
failures.push({
file,
line: match,
});
}
}
}
if (failures.length > 0) {
console.log(chalk.red('--------------------------------------------------------------------'));
console.log(chalk.red(`These entries don't satisfy the engine version in ${packageJsonFile}`));
console.log(chalk.red('--------------------------------------------------------------------'));
for (let index = 0; index < failures.length; index++) {
const failure = failures[index];
console.log(chalk.green(`\tIn ${failure.file} the line ${failure.line} does not satisfy ${expectedVersion}.`));
}
throw new Error('Node versions not in sync');
}
console.log(chalk.yellow('--------------------------------------------------------------------'));
console.log(chalk.yellow('All node versions seem ok.'));
console.log(chalk.yellow('--------------------------------------------------------------------'));
};
export const nodeVersionCheckerTask = new Task<NodeVersionCheckerOptions>(
'Node Version Checker',
nodeVersionCheckerRunner
);

@ -1,92 +0,0 @@
import chalk from 'chalk';
import execa = require('execa');
import { promises as fs } from 'fs';
import globby from 'globby';
import { cloneDeep } from 'lodash';
import * as path from 'path';
import { useSpinner } from '../utils/useSpinner';
import { Task, TaskRunner } from './task';
const clean = (cwd: string) => useSpinner('Cleaning', () => execa('npm', ['run', 'clean'], { cwd }));
const compile = (cwd: string) =>
useSpinner('Compiling sources', () => execa('tsc', ['-p', './tsconfig.build.json'], { cwd }));
const bundle = (cwd: string) => useSpinner('Bundling', () => execa('npm', ['run', 'bundle'], { cwd }));
const preparePackage = async (packageDist: string, pkg: any) => {
pkg = cloneDeep(pkg); // avoid mutations
pkg.main = 'index.js';
pkg.types = 'index.d.ts';
const version: string = pkg.version;
const name: string = pkg.name;
const deps: any = pkg.dependencies;
// Below we are adding cross-dependencies to Grafana's packages
// with the version being published
if (name.endsWith('/ui')) {
deps['@grafana/data'] = version;
} else if (name.endsWith('/runtime')) {
deps['@grafana/data'] = version;
deps['@grafana/ui'] = version;
} else if (name.endsWith('/toolkit')) {
deps['@grafana/data'] = version;
deps['@grafana/ui'] = version;
}
await useSpinner('Updating package.json', () =>
fs.writeFile(`${packageDist}/package.json`, JSON.stringify(pkg, null, 2))
);
};
const moveFiles = (fromPath: string, toPath: string) => {
const files = ['README.md', 'CHANGELOG.md', 'index.js'];
return useSpinner(`Moving ${files.join(', ')} files`, () => {
const promises = files.map((file) => fs.copyFile(`${fromPath}/${file}`, `${toPath}/${file}`));
return Promise.all(promises);
});
};
const moveStaticFiles = async (packageRoot: string, pkg: any) => {
if (pkg.name.endsWith('/ui')) {
return useSpinner('Moving static files', async () => {
const staticFiles = await globby(`${packageRoot}/src/**/*.{png,svg,gif,jpg}`);
const pathSearch = new RegExp(`^${packageRoot}/src`);
const pathReplace = `${packageRoot}/compiled`;
const promises = staticFiles.map((file) => fs.copyFile(file, file.replace(pathSearch, pathReplace)));
await Promise.all(promises);
});
}
};
interface PackageBuildOptions {
scope: string;
}
const buildTaskRunner: TaskRunner<PackageBuildOptions> = async ({ scope }) => {
if (!scope) {
throw new Error('Provide packages with -s, --scope <packages>');
}
const scopes = scope.split(',').map(async (s) => {
const packageRoot = path.resolve(__dirname, `../../../../grafana-${s}`);
const packageDist = `${packageRoot}/dist`;
const pkg = require(`${packageRoot}/package.json`);
console.log(chalk.yellow(`Building ${pkg.name} (package.json version: ${pkg.version})`));
await clean(packageRoot);
await compile(packageRoot);
await moveStaticFiles(packageRoot, pkg);
await bundle(packageRoot);
await preparePackage(packageDist, pkg);
await moveFiles(packageRoot, packageDist);
});
await Promise.all(scopes);
};
export const buildPackageTask = new Task<PackageBuildOptions>('Package build', buildTaskRunner);

@ -1,99 +0,0 @@
import chalk from 'chalk';
import execa = require('execa');
import * as fs from 'fs';
import { useSpinner } from '../utils/useSpinner';
import { Task, TaskRunner } from './task';
const path = require('path');
let distDir: string, cwd: string;
const clean = () => useSpinner('Cleaning', () => execa('npm', ['run', 'clean']));
const compile = () =>
useSpinner('Compiling sources', async () => {
try {
await execa('tsc', ['-p', './tsconfig.json']);
} catch (e) {
console.log(e);
throw e;
}
});
const copyFiles = () => {
const files = [
'src/config/prettier.plugin.config.json',
'src/config/prettier.plugin.rc.js',
'src/config/tsconfig.plugin.json',
'src/config/tsconfig.plugin.local.json',
'src/config/eslint.plugin.js',
'src/config/styles.mock.js',
'src/config/jest.babel.config.js',
'src/config/jest.plugin.config.local.js',
'src/config/matchMedia.js',
'src/config/react-inlinesvg.tsx',
];
return useSpinner(`Moving ${files.join(', ')} files`, async () => {
const promises = files.map((file) => {
return new Promise<void>((resolve, reject) => {
const basedir = path.dirname(`${distDir}/${file}`);
if (!fs.existsSync(basedir)) {
fs.mkdirSync(basedir, { recursive: true });
}
fs.copyFile(`${cwd}/${file}`, `${distDir}/${file}`, (err) => {
if (err) {
reject(err);
return;
}
resolve();
});
});
});
await Promise.all(promises);
});
};
const copySassFiles = () => {
const files = ['_variables.generated.scss', '_variables.dark.generated.scss', '_variables.light.generated.scss'];
const exportDir = `${cwd}/sass`;
return useSpinner(`Copy scss files ${files.join(', ')} files`, async () => {
const sassDir = path.resolve(cwd, '../../public/sass/');
if (!fs.existsSync(exportDir)) {
fs.mkdirSync(exportDir);
}
const promises = files.map((file) => {
return new Promise<void>((resolve, reject) => {
const name = file.replace('.generated', '');
fs.copyFile(`${sassDir}/${file}`, `${exportDir}/${name}`, (err) => {
if (err) {
reject(err);
return;
}
resolve();
});
});
});
await Promise.all(promises);
});
};
interface ToolkitBuildOptions {}
const toolkitBuildTaskRunner: TaskRunner<ToolkitBuildOptions> = async () => {
cwd = path.resolve(__dirname, '../../../');
distDir = `${cwd}/dist`;
const pkg = require(`${cwd}/package.json`);
console.log(chalk.yellow(`Building ${pkg.name} (package.json version: ${pkg.version})`));
await clean();
await compile();
await copyFiles();
await copySassFiles();
};
export const toolkitBuildTask = new Task<ToolkitBuildOptions>('@grafana/toolkit build', toolkitBuildTaskRunner);

@ -3400,12 +3400,11 @@ __metadata:
"@jest/core": 27.5.1
"@types/eslint": 8.4.1
"@types/jest": 27.4.1
"@types/lodash": 4.14.181
"@types/lodash": ^4.14.194
"@types/node": 16.11.26
"@types/prettier": 2.6.3
"@types/react-dev-utils": 9.0.10
"@types/rimraf": 3.0.2
"@types/semver": 7.3.9
"@types/tmp": 0.2.3
"@typescript-eslint/eslint-plugin": 5.36.2
"@typescript-eslint/parser": 5.36.2
@ -3432,7 +3431,7 @@ __metadata:
jest-junit: 13.1.0
less: ^4.1.2
less-loader: ^10.2.0
lodash: ^4.17.21
lodash: 4.17.21
mini-css-extract-plugin: ^2.6.0
ora: ^5.4.1
postcss: ^8.4.12
@ -3445,7 +3444,6 @@ __metadata:
rimraf: 3.0.2
sass: ^1.49.9
sass-loader: ^12.6.0
semver: ^7.3.7
style-loader: ^3.3.1
terser-webpack-plugin: ^5.3.1
ts-jest: 27.1.3
@ -9756,13 +9754,6 @@ __metadata:
languageName: node
linkType: hard
"@types/lodash@npm:4.14.181":
version: 4.14.181
resolution: "@types/lodash@npm:4.14.181"
checksum: 0d1863d8383fd2f8bb42e9e3fc1d6255bb88ff034d6df848941063698944313dae944fc1270315613e3d303fae7c7a9a86085ad3235ed6204c56c4b0b3699aa9
languageName: node
linkType: hard
"@types/lodash@npm:4.14.191":
version: 4.14.191
resolution: "@types/lodash@npm:4.14.191"
@ -9784,6 +9775,13 @@ __metadata:
languageName: node
linkType: hard
"@types/lodash@npm:^4.14.194":
version: 4.14.194
resolution: "@types/lodash@npm:4.14.194"
checksum: 113f34831c461469d91feca2dde737f88487732898b4d25e9eb23b087bb193985f864d1e1e0f3b777edc5022e460443588b6000a3b2348c966f72d17eedc35ea
languageName: node
linkType: hard
"@types/logfmt@npm:^1.2.3":
version: 1.2.3
resolution: "@types/logfmt@npm:1.2.3"
@ -10302,13 +10300,6 @@ __metadata:
languageName: node
linkType: hard
"@types/semver@npm:7.3.9":
version: 7.3.9
resolution: "@types/semver@npm:7.3.9"
checksum: 60bfcfdfa7f937be2c6f4b37ddb6714fb0f27b05fe4cbdfdd596a97d35ed95d13ee410efdd88e72a66449d0384220bf20055ab7d6b5df10de4990fbd20e5cbe0
languageName: node
linkType: hard
"@types/serve-index@npm:^1.9.1":
version: 1.9.1
resolution: "@types/serve-index@npm:1.9.1"

Loading…
Cancel
Save