Merge pull request #27769 from backstage/reduce-yarn-plugin-bundle-size

Reduce yarn plugin bundle size
This commit is contained in:
Patrik Oldsberg
2024-11-23 00:30:50 +01:00
committed by GitHub
6 changed files with 20 additions and 13 deletions
+1 -1
View File
@@ -34,7 +34,7 @@
"@backstage/release-manifests": "workspace:^",
"@yarnpkg/core": "^4.0.3",
"@yarnpkg/fslib": "^3.0.2",
"chalk": "^4.0.0",
"@yarnpkg/plugin-pack": "^4.0.0",
"lodash": "^4.17.21",
"semver": "^7.6.0"
},
+2 -1
View File
@@ -3,9 +3,10 @@
> Do not edit this file. It is a report generated by [API Extractor](https://api-extractor.com/).
```ts
import { Hooks } from '@yarnpkg/plugin-pack';
import { Plugin as Plugin_2 } from '@yarnpkg/core';
// @public (undocumented)
const plugin: Plugin_2;
const plugin: Plugin_2<Hooks>;
export default plugin;
```
@@ -15,7 +15,6 @@
*/
import { Descriptor, Workspace, structUtils } from '@yarnpkg/core';
import { some } from 'lodash';
import {
bindBackstageVersion,
getCurrentBackstageVersion,
@@ -76,9 +75,11 @@ export const beforeWorkspacePacking = async (
}
if (
some(
['dependencies', 'devDependencies', 'optionalDependencies'],
dependencyType => some(rawManifest[dependencyType], hasBackstageVersion),
['dependencies', 'devDependencies', 'optionalDependencies'].some(
dependencyType =>
Object.values<string>(rawManifest[dependencyType] ?? {}).some(
hasBackstageVersion,
),
)
) {
throw new Error(
+10 -5
View File
@@ -22,16 +22,21 @@
*/
import { Plugin, semverUtils, YarnVersion } from '@yarnpkg/core';
import chalk from 'chalk';
import { Hooks } from '@yarnpkg/plugin-pack';
import { beforeWorkspacePacking } from './handlers/beforeWorkspacePacking';
import { BackstageResolver } from './resolver/BackstageResolver';
// All dependencies of the yarn plugin are bundled during the build. Chalk
// triples the size of the plugin bundle when included, so we avoid the
// dependency by hard-coding the ANSI escape codes for the one bit of formatting
// we need.
const RED_BOLD = `\u001B[31;1m`;
const RESET = '\u001B[0m';
if (!semverUtils.satisfiesWithPrereleases(YarnVersion, '^4.1.1')) {
console.error();
console.error(
`${chalk.bold.red(
'Unsupported yarn version.',
)}: The Backstage yarn plugin only works with yarn ^4.1.1. Please upgrade yarn, or remove this plugin with "yarn plugin remove @yarnpkg/plugin-backstage".`,
`${RED_BOLD}Unsupported yarn version${RESET}: The Backstage yarn plugin only works with yarn ^4.1.1. Please upgrade yarn, or remove this plugin with "yarn plugin remove @yarnpkg/plugin-backstage".`,
);
console.error();
}
@@ -39,7 +44,7 @@ if (!semverUtils.satisfiesWithPrereleases(YarnVersion, '^4.1.1')) {
/**
* @public
*/
const plugin: Plugin = {
const plugin: Plugin<Hooks> = {
hooks: {
beforeWorkspacePacking,
},
+1 -1
View File
@@ -16,7 +16,7 @@
import { ppath, xfs } from '@yarnpkg/fslib';
import { valid as semverValid } from 'semver';
import { memoize } from 'lodash';
import memoize from 'lodash/memoize';
import { getManifestByVersion as getManifestByVersionBase } from '@backstage/release-manifests';
import { BACKSTAGE_JSON, findPaths } from '@backstage/cli-common';
import { Descriptor, structUtils } from '@yarnpkg/core';
+1 -1
View File
@@ -45427,7 +45427,7 @@ __metadata:
"@yarnpkg/builder": ^4.0.0
"@yarnpkg/core": ^4.0.3
"@yarnpkg/fslib": ^3.0.2
chalk: ^4.0.0
"@yarnpkg/plugin-pack": ^4.0.0
lodash: ^4.17.21
nodemon: ^3.0.1
semver: ^7.6.0