Merge branch 'master' into new-release-31-aug-20

This commit is contained in:
Patrik Oldsberg
2020-09-02 16:17:40 +02:00
committed by GitHub
101 changed files with 2379 additions and 1145 deletions
+1 -1
View File
@@ -43,7 +43,7 @@
"@svgr/plugin-jsx": "5.4.x",
"@svgr/plugin-svgo": "4.3.x",
"@svgr/rollup": "5.4.x",
"@svgr/webpack": "4.3.x",
"@svgr/webpack": "5.4.x",
"@types/start-server-webpack-plugin": "^2.2.0",
"@types/webpack-env": "^1.15.2",
"@types/webpack-node-externals": "^2.5.0",
@@ -28,6 +28,7 @@ import {
} from '../../lib/codeowners';
import { paths } from '../../lib/paths';
import { Task, templatingTask } from '../../lib/tasks';
import { version as backstageVersion } from '../../lib/version';
const exec = promisify(execCb);
@@ -239,7 +240,11 @@ export default async () => {
await createTemporaryPluginFolder(tempDir);
Task.section('Preparing files');
await templatingTask(templateDir, tempDir, { ...answers, version });
await templatingTask(templateDir, tempDir, {
...answers,
version,
backstageVersion,
});
Task.section('Moving to final location');
await movePlugin(tempDir, pluginDir, answers.id);
+4 -1
View File
@@ -25,7 +25,7 @@ import {
yesPromptFunc,
} from '../../lib/diff';
import { paths } from '../../lib/paths';
import { version } from '../../lib/version';
import { version as backstageVersion } from '../../lib/version';
export type PluginData = {
id: string;
@@ -62,9 +62,12 @@ export default async (cmd: Command) => {
promptFunc = yesPromptFunc;
}
const { version } = await fs.readJson(paths.resolveTargetRoot('lerna.json'));
const data = await readPluginData();
const templateFiles = await diffTemplateFiles('default-plugin', {
version,
backstageVersion,
...data,
});
await handleAllFiles(fileHandlers, templateFiles, promptFunc);
+6
View File
@@ -57,6 +57,12 @@ export default async (cmd: Command) => {
}
}
// This is the only thing that is not implemented by jest.run(), so we do it here instead
// https://github.com/facebook/jest/blob/cd8828f7bbec6e55b4df5e41e853a5133c4a3ee1/packages/jest-cli/bin/jest.js#L12
if (!process.env.NODE_ENV) {
(process.env as any).NODE_ENV = 'test';
}
// eslint-disable-next-line jest/no-jest-import
await require('jest').run(args);
};
+14 -4
View File
@@ -88,15 +88,25 @@ export const makeConfigs = async (
}),
resolve({ mainFields }),
commonjs({
include: ['node_modules/**', '../../node_modules/**'],
exclude: ['**/*.stories.*', '**/*.test.*'],
include: /node_modules/,
exclude: [/\/[^/]+\.(?:stories|test)\.[^/]+$/],
}),
postcss(),
imageFiles({ exclude: '**/*.icon.svg' }),
imageFiles({
exclude: /\.icon\.svg$/,
include: [
/\.css$/,
/\.svg$/,
/\.png$/,
/\.gif$/,
/\.jpg$/,
/\.jpeg$/,
],
}),
json(),
yaml(),
svgr({
include: '**/*.icon.svg',
include: /\.icon\.svg$/,
template: svgrTemplate,
}),
esbuild({
+1 -1
View File
@@ -25,7 +25,7 @@ export async function serveBackend(
},
) {
const paths = resolveBundlingPaths(options);
const config = createBackendConfig(paths, {
const config = await createBackendConfig(paths, {
...options,
isDev: true,
});
+1 -1
View File
@@ -36,7 +36,7 @@ export async function buildBundle(options: BuildOptions) {
const { statsJsonEnabled } = options;
const paths = resolveBundlingPaths(options);
const config = createConfig(paths, {
const config = await createConfig(paths, {
...options,
checksEnabled: false,
isDev: false,
+58 -10
View File
@@ -14,6 +14,8 @@
* limitations under the License.
*/
import fs from 'fs-extra';
import { resolve as resolvePath } from 'path';
import ForkTsCheckerWebpackPlugin from 'fork-ts-checker-webpack-plugin';
import HtmlWebpackPlugin from 'html-webpack-plugin';
import ModuleScopePlugin from 'react-dev-utils/ModuleScopePlugin';
@@ -25,6 +27,9 @@ import { Config } from '@backstage/config';
import { BundlingPaths } from './paths';
import { transforms } from './transforms';
import { BundlingOptions, BackendBundlingOptions } from './types';
import { version } from '../../lib/version';
import { paths as cliPaths } from '../../lib/paths';
import { runPlain } from '../run';
export function resolveBaseUrl(config: Config): URL {
const baseUrl = config.getString('app.baseUrl');
@@ -35,10 +40,40 @@ export function resolveBaseUrl(config: Config): URL {
}
}
export function createConfig(
async function readBuildInfo() {
const timestamp = Date.now();
let commit = 'unknown';
try {
commit = await runPlain('git', 'rev-parse', 'HEAD');
} catch (error) {
console.warn(`WARNING: Failed to read git commit, ${error}`);
}
let gitVersion = 'unknown';
try {
gitVersion = await runPlain('git', 'describe', '--always');
} catch (error) {
console.warn(`WARNING: Failed to describe git version, ${error}`);
}
const { version: packageVersion } = await fs.readJson(
cliPaths.resolveTarget('package.json'),
);
return {
cliVersion: version,
gitVersion,
packageVersion,
timestamp,
commit,
};
}
export async function createConfig(
paths: BundlingPaths,
options: BundlingOptions,
): webpack.Configuration {
): Promise<webpack.Configuration> {
const { checksEnabled, isDev } = options;
const { plugins, loaders } = transforms(options);
@@ -81,6 +116,13 @@ export function createConfig(
}),
);
const buildInfo = await readBuildInfo();
plugins.push(
new webpack.DefinePlugin({
'process.env.BUILD_INFO': JSON.stringify(buildInfo),
}),
);
return {
mode: isDev ? 'development' : 'production',
profile: false,
@@ -130,14 +172,23 @@ export function createConfig(
};
}
export function createBackendConfig(
export async function createBackendConfig(
paths: BundlingPaths,
options: BackendBundlingOptions,
): webpack.Configuration {
): Promise<webpack.Configuration> {
const { checksEnabled, isDev } = options;
const { loaders } = transforms(options);
// Find all local monorepo packages and their node_modules, and mark them as external.
const LernaProject = require('@lerna/project');
const project = new LernaProject(cliPaths.targetDir);
const packages = await project.getPackages();
const localPackageNames = packages.map((p: any) => p.name);
const moduleDirs = packages.map((p: any) =>
resolvePath(p.location, 'node_modules'),
);
return {
mode: isDev ? 'development' : 'production',
profile: false,
@@ -152,11 +203,8 @@ export function createBackendConfig(
externals: [
nodeExternals({
modulesDir: paths.rootNodeModules,
allowlist: ['webpack/hot/poll?100', /\@backstage\/.*/],
}),
nodeExternals({
modulesDir: paths.targetNodeModules,
allowlist: ['webpack/hot/poll?100', /\@backstage\/.*/],
additionalModuleDirs: moduleDirs,
allowlist: ['webpack/hot/poll?100', ...localPackageNames],
}),
],
target: 'node' as const,
@@ -178,7 +226,7 @@ export function createBackendConfig(
resolve: {
extensions: ['.ts', '.tsx', '.mjs', '.js', '.jsx'],
mainFields: ['browser', 'module', 'main'],
modules: [paths.targetNodeModules, paths.rootNodeModules],
modules: [paths.rootNodeModules, ...moduleDirs],
plugins: [
new ModuleScopePlugin(
[paths.targetSrc, paths.targetDev],
-1
View File
@@ -63,7 +63,6 @@ export function resolveBundlingPaths(options: BundlingPathsOptions) {
targetDev: paths.resolveTarget('dev'),
targetEntry: resolveTargetModule(entry),
targetTsConfig: paths.resolveTargetRoot('tsconfig.json'),
targetNodeModules: paths.resolveTarget('node_modules'),
targetPackageJson: paths.resolveTarget('package.json'),
rootNodeModules: paths.resolveTargetRoot('node_modules'),
root: paths.targetRoot,
+1 -1
View File
@@ -30,7 +30,7 @@ export async function serveBundle(options: ServeOptions) {
const paths = resolveBundlingPaths(options);
const pkgPath = paths.targetPackageJson;
const pkg = await fs.readJson(pkgPath);
const config = createConfig(paths, {
const config = await createConfig(paths, {
...options,
isDev: true,
baseUrl: url,
+21
View File
@@ -26,6 +26,7 @@ type LernaPackage = {
private: boolean;
location: string;
scripts: Record<string, string>;
get(key: string): any;
};
type FileEntry =
@@ -107,6 +108,26 @@ async function moveToDistWorkspace(
strip: 1,
});
await fs.remove(archivePath);
// We remove the dependencies from package.json of packages that are marked
// as bundled, so that yarn doesn't try to install them.
if (target.get('bundled')) {
const pkgJson = await fs.readJson(
resolvePath(absoluteOutputPath, 'package.json'),
);
delete pkgJson.dependencies;
delete pkgJson.devDependencies;
delete pkgJson.peerDependencies;
delete pkgJson.optionalDependencies;
await fs.writeJson(
resolvePath(absoluteOutputPath, 'package.json'),
pkgJson,
{
spaces: 2,
},
);
}
}),
);
}
@@ -21,8 +21,8 @@
"clean": "backstage-cli clean"
},
"dependencies": {
"@backstage/core": "^{{version}}",
"@backstage/theme": "^{{version}}",
"@backstage/core": "^{{backstageVersion}}",
"@backstage/theme": "^{{backstageVersion}}",
"@material-ui/core": "^4.9.1",
"@material-ui/icons": "^4.9.1",
"@material-ui/lab": "4.0.0-alpha.45",
@@ -31,8 +31,8 @@
"react-use": "^15.3.3"
},
"devDependencies": {
"@backstage/cli": "^{{version}}",
"@backstage/dev-utils": "^{{version}}",
"@backstage/cli": "^{{backstageVersion}}",
"@backstage/dev-utils": "^{{backstageVersion}}",
"@testing-library/jest-dom": "^5.10.1",
"@testing-library/react": "^10.4.1",
"@testing-library/user-event": "^12.0.7",
@@ -2,13 +2,13 @@ import { createPlugin, createRouteRef } from '@backstage/core';
import ExampleComponent from './components/ExampleComponent';
export const rootRouteRef = createRouteRef({
path: '/{{ id }}',
title: '{{ id }}',
path: '/{{ id }}',
title: '{{ id }}',
});
export const plugin = createPlugin({
id: '{{ id }}',
register({ router }) {
router.addRoute(rootRouteRef, ExampleComponent);
},
id: '{{ id }}',
register({ router }) {
router.addRoute(rootRouteRef, ExampleComponent);
},
});