-
Notifications
You must be signed in to change notification settings - Fork 151
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(cli): add frontend dynamic plugins base build config (#747)
* feat(cli): build dynamic frontend plugins chore(ci): bump test node version (#831) feat(cli): add frontend dynamic plugins base build config fix(cli): resolve post dynamic build stats errors fix(cli): remove eager consumption settings from shared modules Eager packages will always end up within the container entry JS files which significantly increases the network bandwidth even if packages the shared packages have been already initialized in the shared scope via different container. fix(cli): remove the requirement for root tsconfig.json chore(dynamic-plugins): add sample dynamic plugin package chore(app-next): add sample app with dynamic plugins fix(cli): align versions of @backstage/backend-common package feat(app-next): dynamically load entire backstage plugins chore(app-next): add readme chore(app-next): fix eslint errors fix(cli): do not treat warnings as errors on CI chore(dependencies): align dependency versions * chore(cli): cleanup and enable quay dynamic build Signed-off-by: Tomas Coufal <[email protected]> --------- Signed-off-by: Tomas Coufal <[email protected]> Co-authored-by: Tomas Coufal <[email protected]>
- Loading branch information
1 parent
04b2d07
commit 91e06da
Showing
18 changed files
with
717 additions
and
161 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import { PluginBuildMetadata } from '@openshift/dynamic-plugin-sdk-webpack'; | ||
|
||
import { buildScalprumBundle } from '../bundler/bundlePlugin'; | ||
import { loadCliConfig } from '../config'; | ||
import { getEnvironmentParallelism } from '../parallel'; | ||
|
||
interface BuildScalprumPluginOptions { | ||
targetDir: string; | ||
writeStats: boolean; | ||
configPaths: string[]; | ||
pluginMetadata: PluginBuildMetadata; | ||
fromPackage: string; | ||
} | ||
|
||
export async function buildScalprumPlugin(options: BuildScalprumPluginOptions) { | ||
const { targetDir, pluginMetadata, fromPackage } = options; | ||
await buildScalprumBundle({ | ||
targetDir, | ||
entry: 'src/index', | ||
parallelism: getEnvironmentParallelism(), | ||
pluginMetadata, | ||
...(await loadCliConfig({ | ||
args: [], | ||
fromPackage, | ||
})), | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,123 @@ | ||
import { | ||
measureFileSizesBeforeBuild, | ||
printFileSizesAfterBuild, | ||
} from 'react-dev-utils/FileSizeReporter'; | ||
import formatWebpackMessages from 'react-dev-utils/formatWebpackMessages'; | ||
|
||
import chalk from 'chalk'; | ||
import fs from 'fs-extra'; | ||
import webpack from 'webpack'; | ||
import yn from 'yn'; | ||
|
||
import { resolveBaseUrl } from './config'; | ||
import { BundlingPathsOptions, resolveBundlingPaths } from './paths'; | ||
import { createScalprumConfig } from './scalprumConfig'; | ||
import { DynamicPluginOptions } from './types'; | ||
|
||
// TODO(Rugvip): Limits from CRA, we might want to tweak these though. | ||
const WARN_AFTER_BUNDLE_GZIP_SIZE = 512 * 1024; | ||
const WARN_AFTER_CHUNK_GZIP_SIZE = 1024 * 1024; | ||
|
||
function applyContextToError(error: string, moduleName: string): string { | ||
return `Failed to compile '${moduleName}':\n ${error}`; | ||
} | ||
|
||
export async function buildScalprumBundle( | ||
options: BundlingPathsOptions & DynamicPluginOptions, | ||
) { | ||
const paths = resolveBundlingPaths(options); | ||
const config = await createScalprumConfig(paths, { | ||
...options, | ||
checksEnabled: false, | ||
isDev: false, | ||
baseUrl: resolveBaseUrl(options.frontendConfig), | ||
}); | ||
|
||
const isCi = yn(process.env.CI, { default: false }); | ||
|
||
const previousFileSizes = await measureFileSizesBeforeBuild( | ||
paths.targetScalprumDist, | ||
); | ||
await fs.emptyDir(paths.targetScalprumDist); | ||
|
||
if (paths.targetPublic) { | ||
await fs.copy(paths.targetPublic, paths.targetDist, { | ||
dereference: true, | ||
filter: file => file !== paths.targetHtml, | ||
}); | ||
} | ||
|
||
const { stats } = await build(config, isCi); | ||
|
||
if (!stats) { | ||
throw new Error('No stats returned'); | ||
} | ||
|
||
printFileSizesAfterBuild( | ||
stats, | ||
previousFileSizes, | ||
paths.targetScalprumDist, | ||
WARN_AFTER_BUNDLE_GZIP_SIZE, | ||
WARN_AFTER_CHUNK_GZIP_SIZE, | ||
); | ||
} | ||
|
||
async function build(config: webpack.Configuration, isCi: boolean) { | ||
const stats = await new Promise<webpack.Stats | undefined>( | ||
(resolve, reject) => { | ||
webpack(config, (err, buildStats) => { | ||
if (err) { | ||
if (err.message) { | ||
const { errors } = formatWebpackMessages({ | ||
errors: [err.message], | ||
warnings: new Array<string>(), | ||
_showErrors: true, | ||
_showWarnings: true, | ||
}); | ||
|
||
throw new Error(errors[0]); | ||
} else { | ||
reject(err); | ||
} | ||
} else { | ||
resolve(buildStats); | ||
} | ||
}); | ||
}, | ||
); | ||
|
||
if (!stats) { | ||
throw new Error('Failed to compile: No stats provided'); | ||
} | ||
|
||
const serializedStats = stats.toJson({ | ||
all: false, | ||
warnings: true, | ||
errors: true, | ||
}); | ||
const { errors, warnings } = formatWebpackMessages({ | ||
errors: serializedStats.errors, | ||
warnings: serializedStats.warnings, | ||
}); | ||
|
||
if (errors.length) { | ||
// Only keep the first error. Others are often indicative | ||
// of the same problem, but confuse the reader with noise. | ||
const errorWithContext = applyContextToError( | ||
errors[0], | ||
serializedStats.errors?.[0]?.moduleName ?? '', | ||
); | ||
throw new Error(errorWithContext); | ||
} | ||
if (isCi && warnings.length) { | ||
const warningsWithContext = warnings.map((warning, i) => { | ||
return applyContextToError( | ||
warning, | ||
serializedStats.warnings?.[i]?.moduleName ?? '', | ||
); | ||
}); | ||
console.log(chalk.yellow(warningsWithContext.join('\n\n'))); | ||
} | ||
|
||
return { stats }; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.