Merge remote-tracking branch 'origin/master' into ndudnik/filter-by-identity

This commit is contained in:
Nikita Nek Dudnik
2020-06-17 17:13:52 +02:00
56 changed files with 451 additions and 1029 deletions
-9
View File
@@ -14,8 +14,6 @@ jobs:
env:
CI: true
NODE_OPTIONS: --max-old-space-size=4096
BACKSTAGE_CACHE_DIR: <repoRoot>/.backstage-build-cache
BACKSTAGE_CACHE_MAX_ENTRIES: 2
steps:
- uses: actions/checkout@v2
@@ -36,13 +34,6 @@ jobs:
with:
path: node_modules
key: ${{ runner.os }}-modules-${{ hashFiles('yarn.lock') }}
- name: cache build cache
uses: actions/cache@v2
with:
path: .backstage-build-cache
key: build-cache-${{ github.sha }}
restore-keys: |
build-cache-
- name: use node.js ${{ matrix.node-version }}
uses: actions/setup-node@v1
with:
-9
View File
@@ -15,8 +15,6 @@ jobs:
env:
CI: true
NODE_OPTIONS: --max-old-space-size=4096
BACKSTAGE_CACHE_DIR: <repoRoot>/.backstage-build-cache
BACKSTAGE_CACHE_MAX_ENTRIES: 2
steps:
- uses: actions/checkout@v2
@@ -35,13 +33,6 @@ jobs:
with:
path: node_modules
key: ${{ runner.os }}-modules-${{ hashFiles('yarn.lock') }}
- name: cache build cache
uses: actions/cache@v2
with:
path: .backstage-build-cache
key: build-cache-${{ github.sha }}
restore-keys: |
build-cache-
- name: use node.js ${{ matrix.node-version }}
uses: actions/setup-node@v1
with:
+122
View File
@@ -0,0 +1,122 @@
{
"$schema": "http://json-schema.org/draft-07/schema",
"$id": "backstage.io/v1alpha1",
"type": "object",
"title": "A JSON Schema for Backstage catalog entities.",
"description": "Each descriptor file has a number of entities. This schema matches each of those.",
"examples": [
{
"apiVersion": "backstage.io/v1alpha1",
"kind": "Component",
"metadata": {
"name": "LoremService",
"description": "Creates Lorems like a pro.",
"labels": {
"product_name": "Random value Generator"
},
"annnotations": {
"docs": "https://github.com/..../tree/develop/doc"
},
"teams": [
{
"name": "Team super great",
"email": "greatTeam@geemel.com"
}
]
},
"spec": {
"type": "service",
"lifecycle": "production",
"owner": "tools@example.com"
}
}
],
"required": ["apiVersion", "kind", "metadata"],
"additionalProperties": false,
"properties": {
"apiVersion": {
"type": "string",
"description": "Version of the specification format for a particular file is written against.",
"enum": ["backstage.io/v1alpha1", "backstage.io/v1beta1"]
},
"kind": {
"type": "string",
"description": "High level entity type being described, from the Backstage system model.",
"enum": ["Component"]
},
"metadata": {
"$ref": "#/definitions/metadata"
},
"spec": {
"$ref": "#/definitions/spec"
}
},
"definitions": {
"metadata": {
"type": "object",
"description": "Metadata about the entity, i.e. things that aren't directly part of the entity specification itself.",
"required": ["name"],
"additionalProperties": true,
"properties": {
"name": {
"type": "string",
"pattern": "^[a-z0-9A-Z_.-]{1,63}$",
"description": "The name of the entity. This name is both meant for human eyes to recognize the entity, and for machines and other components to reference the entity"
},
"description": {
"type": "string",
"description": "A human readable description of the entity, to be shown in Backstage. Should be kept short and informative."
},
"namespace": {
"type": "string",
"description": "The name of a namespace that the entity belongs to."
},
"labels": {
"type": "object",
"description": "Labels are optional key/value pairs of that are attached to the entity, and their use is identical to kubernetes object labels.",
"additionalProperties": true,
"patternProperties": {
"^([a-zA-Z0-9][a-zA-Z0-9-]{1,61}[a-zA-Z0-9]\\.[a-zA-Z]{2,}/)?[a-z0-9A-Z_\\-\\.]{1,63}$": {
"type": "string",
"pattern": "^[a-z0-9A-Z_.-]{1,63}$"
}
}
},
"annnotations": {
"type": "object",
"description": "Arbitrary non-identifying metadata attached to the entity, identical in use to kubernetes object annotations.",
"additionalProperties": true,
"patternProperties": {
"^([a-zA-Z0-9][a-zA-Z0-9-]{1,61}[a-zA-Z0-9]\\.[a-zA-Z]{2,}/)?[a-z0-9A-Z_\\-\\.]{1,63}$": {
"type": "string",
"pattern": "^[a-z0-9A-Z_.-]{1,63}$"
}
}
}
}
},
"spec": {
"type": "object",
"description": "Actual specification data that describes the entity. TODO: shape depend on `kind`",
"required": ["type", "lifecycle", "owner"],
"additionalProperties": true,
"properties": {
"type": {
"type": "string",
"description": "The type of component.",
"examples": ["service"]
},
"lifecycle": {
"type": "string",
"description": "The lifecycle step that this component is in.",
"examples": ["production"]
},
"owner": {
"type": "string",
"description": "The owner of the component.",
"examples": ["tools@example.com"]
}
}
}
}
}
+1 -1
View File
@@ -2,5 +2,5 @@
"packages": ["packages/*", "plugins/*"],
"npmClient": "yarn",
"useWorkspaces": true,
"version": "0.1.1-alpha.8"
"version": "0.1.1-alpha.9"
}
+14 -14
View File
@@ -1,21 +1,21 @@
{
"name": "example-app",
"version": "0.1.1-alpha.8",
"version": "0.1.1-alpha.9",
"private": true,
"dependencies": {
"@backstage/cli": "^0.1.1-alpha.8",
"@backstage/core": "^0.1.1-alpha.8",
"@backstage/plugin-catalog": "^0.1.1-alpha.8",
"@backstage/plugin-circleci": "^0.1.1-alpha.8",
"@backstage/plugin-explore": "^0.1.1-alpha.8",
"@backstage/plugin-gitops-profiles": "^0.1.1-alpha.8",
"@backstage/plugin-lighthouse": "^0.1.1-alpha.8",
"@backstage/plugin-register-component": "^0.1.1-alpha.8",
"@backstage/plugin-scaffolder": "^0.1.1-alpha.8",
"@backstage/plugin-sentry": "^0.1.1-alpha.8",
"@backstage/plugin-tech-radar": "^0.1.1-alpha.8",
"@backstage/plugin-welcome": "^0.1.1-alpha.8",
"@backstage/theme": "^0.1.1-alpha.8",
"@backstage/cli": "^0.1.1-alpha.9",
"@backstage/core": "^0.1.1-alpha.9",
"@backstage/plugin-catalog": "^0.1.1-alpha.9",
"@backstage/plugin-circleci": "^0.1.1-alpha.9",
"@backstage/plugin-explore": "^0.1.1-alpha.9",
"@backstage/plugin-gitops-profiles": "^0.1.1-alpha.9",
"@backstage/plugin-lighthouse": "^0.1.1-alpha.9",
"@backstage/plugin-register-component": "^0.1.1-alpha.9",
"@backstage/plugin-scaffolder": "^0.1.1-alpha.9",
"@backstage/plugin-sentry": "^0.1.1-alpha.9",
"@backstage/plugin-tech-radar": "^0.1.1-alpha.9",
"@backstage/plugin-welcome": "^0.1.1-alpha.9",
"@backstage/theme": "^0.1.1-alpha.9",
"@material-ui/core": "^4.9.1",
"@material-ui/icons": "^4.9.1",
"prop-types": "^15.7.2",
+2 -2
View File
@@ -1,7 +1,7 @@
{
"name": "@backstage/backend-common",
"description": "Common functionality library for Backstage backends",
"version": "0.1.1-alpha.8",
"version": "0.1.1-alpha.9",
"main": "src/index.ts",
"types": "src/index.ts",
"private": false,
@@ -40,7 +40,7 @@
"winston": "^3.2.1"
},
"devDependencies": {
"@backstage/cli": "^0.1.1-alpha.8",
"@backstage/cli": "^0.1.1-alpha.9",
"@types/compression": "^1.7.0",
"@types/http-errors": "^1.6.3",
"@types/morgan": "^1.9.0",
+9 -9
View File
@@ -1,6 +1,6 @@
{
"name": "example-backend",
"version": "0.1.1-alpha.8",
"version": "0.1.1-alpha.9",
"main": "dist/index.cjs.js",
"types": "src/index.ts",
"private": true,
@@ -17,20 +17,20 @@
"migrate:create": "knex migrate:make -x ts"
},
"dependencies": {
"@backstage/backend-common": "^0.1.1-alpha.8",
"@backstage/catalog-model": "^0.1.1-alpha.8",
"@backstage/plugin-auth-backend": "^0.1.1-alpha.8",
"@backstage/plugin-catalog-backend": "^0.1.1-alpha.8",
"@backstage/plugin-identity-backend": "^0.1.1-alpha.8",
"@backstage/plugin-scaffolder-backend": "^0.1.1-alpha.8",
"@backstage/plugin-sentry-backend": "^0.1.1-alpha.8",
"@backstage/backend-common": "^0.1.1-alpha.9",
"@backstage/catalog-model": "^0.1.1-alpha.9",
"@backstage/plugin-auth-backend": "^0.1.1-alpha.9",
"@backstage/plugin-catalog-backend": "^0.1.1-alpha.9",
"@backstage/plugin-identity-backend": "^0.1.1-alpha.9",
"@backstage/plugin-scaffolder-backend": "^0.1.1-alpha.9",
"@backstage/plugin-sentry-backend": "^0.1.1-alpha.9",
"express": "^4.17.1",
"knex": "^0.21.1",
"sqlite3": "^4.2.0",
"winston": "^3.2.1"
},
"devDependencies": {
"@backstage/cli": "^0.1.1-alpha.8",
"@backstage/cli": "^0.1.1-alpha.9",
"@types/express": "^4.17.6",
"@types/express-serve-static-core": "^4.17.5",
"@types/helmet": "^0.0.47"
+5 -4
View File
@@ -1,12 +1,12 @@
{
"name": "@backstage/catalog-model",
"version": "0.1.1-alpha.8",
"version": "0.1.1-alpha.9",
"main": "dist/index.cjs.js",
"module": "dist/index.esm.js",
"main:src": "src/index.ts",
"types": "src/index.ts",
"license": "Apache-2.0",
"private": true,
"private": false,
"publishConfig": {
"access": "public",
"main": "dist/index.cjs.js",
@@ -22,14 +22,15 @@
"clean": "backstage-cli clean"
},
"dependencies": {
"@types/yup": "^0.28.2",
"lodash": "^4.17.15",
"yup": "^0.28.5"
},
"devDependencies": {
"@backstage/cli": "^0.1.1-alpha.8",
"@backstage/cli": "^0.1.1-alpha.9",
"@types/express": "^4.17.6",
"@types/jest": "^25.2.2",
"@types/lodash": "^4.14.151",
"@types/yup": "^0.28.2",
"yaml": "^1.9.2"
},
"files": [
+4 -4
View File
@@ -1,7 +1,7 @@
{
"name": "@backstage/cli",
"description": "CLI for developing Backstage plugins and apps",
"version": "0.1.1-alpha.8",
"version": "0.1.1-alpha.9",
"private": false,
"publishConfig": {
"access": "public"
@@ -29,8 +29,8 @@
"backstage-cli": "bin/backstage-cli"
},
"dependencies": {
"@backstage/config": "^0.1.1-alpha.7",
"@backstage/config-loader": "^0.1.1-alpha.7",
"@backstage/config": "0.1.1-alpha.9",
"@backstage/config-loader": "^0.1.1-alpha.9",
"@hot-loader/react-dom": "^16.13.0",
"@lerna/package-graph": "^3.18.5",
"@lerna/project": "^3.18.0",
@@ -40,8 +40,8 @@
"@spotify/eslint-config": "^7.0.1",
"@sucrase/webpack-loader": "^2.0.0",
"@types/start-server-webpack-plugin": "^2.2.0",
"@types/webpack-node-externals": "^1.7.1",
"@types/webpack-env": "^1.15.2",
"@types/webpack-node-externals": "^1.7.1",
"bfj": "^7.0.2",
"chalk": "^4.0.0",
"chokidar": "^3.3.1",
@@ -1,32 +0,0 @@
/*
* Copyright 2020 Spotify AB
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import { Command } from 'commander';
import { run } from '../../lib/run';
import { withCache, parseOptions } from '../../lib/buildCache';
/*
* The build-cache command is used to make builds a no-op if there are no changes to the package.
* It supports both local development where the output directory remains intact, as well as CI
* where the output directory is stored in a separate cache dir.
*/
export default async (cmd: Command, args: string[]) => {
const options = await parseOptions(cmd);
await withCache(options, async () => {
await run(args[0], args.slice(1));
});
};
+1 -12
View File
@@ -15,20 +15,9 @@
*/
import fs from 'fs-extra';
import { resolve as resolvePath, relative as relativePath } from 'path';
import { paths } from '../../lib/paths';
import { getDefaultCacheOptions } from '../../lib/buildCache';
export default async function clean() {
const cacheOptions = getDefaultCacheOptions();
const packagePath = getPackagePath(cacheOptions.cacheDir);
await fs.remove(cacheOptions.output);
await fs.remove(packagePath);
await fs.remove(paths.resolveTarget('dist'));
await fs.remove(paths.resolveTarget('coverage'));
}
function getPackagePath(cacheDir: string) {
const relativePackagePath = relativePath(paths.targetRoot, paths.targetDir);
const packagePath = resolvePath(cacheDir, relativePackagePath);
return packagePath;
}
@@ -1,49 +0,0 @@
/*
* Copyright 2020 Spotify AB
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import { Command } from 'commander';
import { run } from '../../lib/run';
import { createLogPipe } from '../../lib/logging';
import { watchDeps, Options } from '../../lib/watchDeps';
/*
* The watch-deps command is meant to improve iteration speed while working in a large monorepo
* with packages that are built independently, meaning packages depends on each other's build output.
*
* The command traverses all dependencies of the current package within the monorepo, and starts
* watching for updates in all those packages. If a change is detected, we stop listening for changes,
* and instead start up watch mode for that package. Starting watch mode means running the first
* available yarn script out of "build:watch", "watch", or "build" --watch.
*/
export default async (cmd: Command, args: string[]) => {
const options: Options = {};
if (cmd.build) {
options.build = true;
}
await watchDeps(options);
if (args?.length) {
// Use log pipe to avoid clearing the terminal
const logPipe = createLogPipe();
await run(args[0], args.slice(1), {
stdoutLogFunc: logPipe(process.stdout),
stderrLogFunc: logPipe(process.stderr),
});
}
};
-23
View File
@@ -126,29 +126,6 @@ const main = (argv: string[]) => {
.description('Restores the changes made by the prepack command')
.action(lazyAction(() => import('./commands/pack'), 'post'));
program
.command('watch-deps')
.option('--build', 'Build all dependencies on startup')
.description('Watch all dependencies while running another command')
.action(lazyAction(() => import('./commands/watch-deps'), 'default'));
program
.command('build-cache')
.description('Wrap build command with a cache')
.option(
'--input <dirs>',
'List of input directories that invalidate the cache [.]',
(value, acc) => acc.concat(value),
[],
)
.option('--output <dir>', 'Output directory to cache', 'dist')
.option(
'--cache-dir <dir>',
'Cache dir',
'<repoRoot>/node_modules/.cache/backstage-builds',
)
.action(lazyAction(() => import('./commands/build-cache'), 'default'));
program
.command('clean')
.description('Delete cache directories')
@@ -1,39 +0,0 @@
/*
* Copyright 2020 Spotify AB
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import fs from 'fs-extra';
import tar from 'tar';
import { dirname } from 'path';
// packages all files in inputDir into an archive at archivePath, deleting any existing archive
export async function createArchive(
archivePath: string,
inputDir: string,
): Promise<void> {
await fs.remove(archivePath);
await fs.ensureDir(dirname(archivePath));
await tar.create({ gzip: true, file: archivePath, cwd: inputDir }, ['.']);
}
// extracts archive at archive path into outputDir, deleting any existing files at outputDir
export async function extractArchive(
archivePath: string,
outputDir: string,
): Promise<void> {
await fs.remove(outputDir);
await fs.ensureDir(outputDir);
await tar.extract({ file: archivePath, cwd: outputDir });
}
-214
View File
@@ -1,214 +0,0 @@
/*
* Copyright 2020 Spotify AB
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import fs from 'fs-extra';
import { resolve as resolvePath, relative as relativePath } from 'path';
import { runPlain, runCheck } from '../run';
import { Options } from './options';
import { extractArchive, createArchive } from './archive';
import { paths } from '../paths';
import { version, isDev } from '../version';
const INFO_FILE = '.backstage-build-cache';
// Result from a cache query
export type CacheQueryResult = {
// True if there was a cache hit
hit: boolean;
// If there is a cache hit and this method is defined, it needs to be called to restore the
// output contents before continuing.
copy?: (outputDir: string) => Promise<void>;
// Call after a successful build to archive the output content.
// The content will be archived using the same key as was used to query the cache.
archive: (outputDir: string, maxEntries: number) => Promise<void>;
};
// Key that determines whether cached output can be reused
export type CacheKey = string[];
type CacheEntry = {
// Key for the input of this cache entry
key: CacheKey;
// Path to the archive of this cache entry
path: string;
};
// Struct containing information about cache entries on the filesystem.
// Stored inside the INFO_FILE as JSON.
type CacheInfo = {
// Optional key entry for the contents of the current directory. Used to key the
// output present in the outputs folder, where the info file resides inside the output folder.
key?: CacheKey;
// Optional list of cache archives present in the same directory. Resides in the external
// cache location inside one info file for each package.
entries?: CacheEntry[];
};
export class Cache {
// Read the current cache state form the filesystem.
static async read(options: Options) {
const relativePackagePath = relativePath(paths.targetRoot, paths.targetDir);
const location = resolvePath(options.cacheDir, relativePackagePath);
const outputInfo = await readCacheInfo(options.output);
const localKey = outputInfo?.key;
const { entries = [] } = (await readCacheInfo(location)) ?? {};
return new Cache(location, entries, localKey);
}
// Generates a key based on the contents of the input paths.
// Returns undefined if it's not possible to generate a stable key.
static async readInputKey(
inputPaths: string[],
): Promise<CacheKey | undefined> {
const allInputPaths = inputPaths.slice();
// If we're executing the cli inside the backstage repo, we add the cli src as cache key as well
if (isDev) {
allInputPaths.unshift(paths.ownDir);
}
// Make sure we don't have any uncommitted changes to the input, in that case we skip caching.
const noChanges = await runCheck(
'git',
'diff',
'--quiet',
'HEAD',
'--',
...allInputPaths,
);
if (!noChanges) {
return undefined;
}
const trees = [];
for (const inputPath of allInputPaths) {
const output = await runPlain('git', 'ls-tree', 'HEAD', inputPath);
const [, , sha] = output.split(/\s+/, 3);
// If we can't get a tree sha it means we're outside of tracked files, so treat as dirty
if (!sha) {
return undefined;
}
trees.push(sha);
}
if (isDev) {
return trees;
}
// If we're executing as a dependency, use the version as a key
return [version, ...trees];
}
constructor(
private readonly location: string,
private readonly entries: CacheEntry[] = [],
private readonly localKey?: CacheKey,
) {}
// Query for the presense of cached output for a given key
query(key: CacheKey): CacheQueryResult {
const { location } = this;
const archive = async (outputDir: string, maxEntries: number) => {
await writeCacheInfo(outputDir, { key });
const timestamp = new Date().toISOString().replace(/-|:|\..*/g, '');
const rand = Math.random().toString(36).slice(2, 6);
const archiveName = `cache-${timestamp}-${rand}.tgz`;
const archivePath = resolvePath(location, archiveName);
// Read existing entries and prepend the new one
const { entries = [] } = (await readCacheInfo(location)) ?? {};
// Check if there's already aan entry for this key, in that case we just wanna bump it
const entryIndex = entries.findIndex((e) => compareKeys(e.key, key));
if (entryIndex !== -1) {
const [existingEntry] = entries.splice(entryIndex, 1);
entries.unshift(existingEntry);
await writeCacheInfo(location, { entries });
return;
}
// Create and add new archive to entries
await createArchive(archivePath, outputDir);
entries.unshift({ key, path: archiveName });
// Remove old cache entries
const removedEntries = entries.splice(maxEntries);
for (const entry of removedEntries) {
try {
await fs.remove(resolvePath(location, entry.path));
} catch (error) {
process.stderr.write(`failed to remove old cache entry, ${error}\n`);
}
}
await writeCacheInfo(location, { entries });
};
if (compareKeys(this.localKey, key)) {
return { hit: true, archive };
}
const matchingEntry = this.entries.find((e) => compareKeys(e.key, key));
if (!matchingEntry) {
return { hit: false, archive };
}
return {
hit: true,
archive,
copy: async (outputDir: string) => {
const archivePath = resolvePath(location, matchingEntry.path);
await extractArchive(archivePath, outputDir);
},
};
}
}
// Compares to cache keys, returning true if they are both defined and equal
function compareKeys(a?: CacheKey, b?: CacheKey): boolean {
if (!a || !b) {
return false;
}
return a.join(',') === b.join(',');
}
// Read and parse a cache info file in the given directory
async function readCacheInfo(
parentDir: string,
): Promise<CacheInfo | undefined> {
const infoFile = resolvePath(parentDir, INFO_FILE);
const exists = await fs.pathExists(infoFile);
if (!exists) {
return undefined;
}
const infoData = await fs.readFile(infoFile);
const cacheInfo = JSON.parse(infoData.toString('utf8')) as CacheInfo;
return cacheInfo;
}
// Write a cache info file to the given directory
async function writeCacheInfo(
parentDir: string,
cacheInfo: CacheInfo,
): Promise<void> {
const infoData = Buffer.from(JSON.stringify(cacheInfo, null, 2), 'utf8');
await fs.writeFile(resolvePath(parentDir, INFO_FILE), infoData);
}
@@ -1,59 +0,0 @@
/*
* Copyright 2020 Spotify AB
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import { resolve as resolvePath } from 'path';
import { Command } from 'commander';
import { paths } from '../paths';
const DEFAULT_CACHE_DIR = '<repoRoot>/node_modules/.cache/backstage-builds';
const DEFAULT_MAX_ENTRIES = 10;
export type Options = {
inputs: string[];
output: string;
cacheDir: string;
maxCacheEntries: number;
};
function transformPath(path: string): string {
return resolvePath(path.replace(/<repoRoot>/g, paths.targetRoot));
}
export async function parseOptions(cmd: Command): Promise<Options> {
const inputs = cmd.input.map(transformPath) as string[];
if (inputs.length === 0) {
inputs.push(transformPath('.'));
}
const output = transformPath(cmd.output);
const cacheDir = transformPath(
process.env.BACKSTAGE_CACHE_DIR || cmd.cacheDir,
);
const maxCacheEntries =
Number(process.env.BACKSTAGE_CACHE_MAX_ENTRIES) || DEFAULT_MAX_ENTRIES;
return { inputs, output, cacheDir, maxCacheEntries };
}
export function getDefaultCacheOptions(): Options {
return {
inputs: [transformPath('.')],
output: transformPath('dist'),
cacheDir: transformPath(
process.env.BACKSTAGE_CACHE_DIR || DEFAULT_CACHE_DIR,
),
maxCacheEntries:
Number(process.env.BACKSTAGE_CACHE_MAX_ENTRIES) || DEFAULT_MAX_ENTRIES,
};
}
@@ -1,56 +0,0 @@
/*
* Copyright 2020 Spotify AB
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import fs from 'fs-extra';
import { Cache } from './cache';
import { Options } from './options';
function print(msg: string) {
process.stdout.write(`[build-cache] ${msg}\n`);
}
// Wrap a build function with a cache, which won't call the build function on cache hit
export async function withCache(
options: Options,
buildFunc: () => Promise<void>,
): Promise<void> {
const key = await Cache.readInputKey(options.inputs);
if (!key) {
print('input directory is dirty, skipping cache');
await fs.remove(options.output);
await buildFunc();
return;
}
const cache = await Cache.read(options);
const cacheResult = cache.query(key);
if (cacheResult.hit) {
if (cacheResult.copy) {
print('external cache hit, copying archive to output folder');
await cacheResult.copy(options.output);
} else {
print('cache hit, nothing to be done');
}
return;
}
print('cache miss, need to build');
await fs.remove(options.output);
await buildFunc();
await cacheResult.archive(options.output, options.maxCacheEntries);
}
@@ -1,64 +0,0 @@
/*
* Copyright 2020 Spotify AB
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import { spawn } from 'child_process';
import { LogPipe } from '../logging';
import chalk from 'chalk';
import { Package } from './packages';
export function startCompiler(pkg: Package, logPipe: LogPipe) {
// First we figure out which yarn script is a available, falling back to "build --watch"
const scriptName = ['build:watch', 'watch'].find(
(script) => script in pkg.scripts,
);
const args = scriptName ? [scriptName] : ['build', '--watch'];
// Start the watch script inside the dependency
const watch = spawn('yarn', ['run', ...args], {
cwd: pkg.location,
env: { FORCE_COLOR: 'true', ...process.env },
stdio: 'pipe',
shell: true,
});
watch.stdin.end();
watch.stdout.on('data', logPipe(process.stdout));
const logErr = logPipe(process.stderr);
watch.stderr.on('data', logErr);
const promise = new Promise<void>((resolve, reject) => {
watch.on('error', (error) => {
reject(error);
});
watch.on('close', (code: number) => {
if (code !== 0) {
const msg = `Compiler exited with code ${code}`;
logErr(chalk.red(msg));
reject(new Error(msg));
} else {
resolve();
}
});
});
return {
promise,
close() {
watch.kill('SIGINT');
},
};
}
@@ -1,62 +0,0 @@
/*
* Copyright 2020 Spotify AB
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import { paths } from '../paths';
const LernaProject = require('@lerna/project');
const PackageGraph = require('@lerna/package-graph');
export type Package = {
name: string;
location: string;
scripts: { [name in string]: string };
};
// Uses lerna to find all local deps of the root package, excluding itself or any package in the blacklist
export async function findAllDeps(
rootPackageName: string,
blacklist: string[],
): Promise<Package[]> {
const project = new LernaProject(paths.targetDir);
const packages = await project.getPackages();
const graph = new PackageGraph(packages);
const deps = new Map<string, any>();
const searchNames = [rootPackageName];
while (searchNames.length) {
const name = searchNames.pop()!;
if (deps.has(name)) {
continue;
}
const node = graph.get(name);
if (!node) {
throw new Error(`Package '${name}' not found`);
}
searchNames.push(...node.localDependencies.keys());
deps.set(name, node.pkg);
}
deps.delete(rootPackageName);
for (const name of blacklist) {
deps.delete(name);
}
return [...deps.values()];
}
@@ -1,79 +0,0 @@
/*
* Copyright 2020 Spotify AB
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import chalk from 'chalk';
import fs from 'fs-extra';
import { createLogPipeFactory } from './logger';
import { findAllDeps } from './packages';
import { startWatcher, startPackageWatcher } from './watcher';
import { startCompiler } from './compiler';
import { run } from '../run';
import { paths } from '../paths';
const PACKAGE_BLACKLIST = [
// We never want to watch for changes in the cli, but all packages will depend on it.
'@backstage/cli',
];
const WATCH_LOCATIONS = ['package.json', 'src', 'assets'];
export type Options = {
build?: boolean;
};
// Start watching for dependency changes.
// The returned promise resolves when watchers have started for all current dependencies.
export async function watchDeps(options: Options = {}) {
const localPackagePath = paths.resolveTarget('package.json');
// Rotate through different prefix colors to make it easier to differenciate between different deps
const createLogPipe = createLogPipeFactory([
chalk.yellow,
chalk.blue,
chalk.magenta,
chalk.green,
chalk.cyan,
]);
// Find all direct and transitive local dependencies of the current package.
const packageData = await fs.readFile(localPackagePath, 'utf8');
const packageJson = JSON.parse(packageData);
const packageName = packageJson.name;
const deps = await findAllDeps(packageName, PACKAGE_BLACKLIST);
if (options.build) {
await run('lerna', [
'run',
'--scope',
packageName,
'--include-dependencies',
'build',
]);
}
// We lazily watch all our deps, as in we don't start the actual watch compiler until a change is detected
const watcher = await startWatcher(deps, WATCH_LOCATIONS, (pkg) => {
startCompiler(pkg, createLogPipe(pkg.name)).promise.catch((error) => {
process.stderr.write(`${error}\n`);
});
});
await startPackageWatcher(localPackagePath, async () => {
const newDeps = await findAllDeps(packageName, PACKAGE_BLACKLIST);
await watcher.update(newDeps);
});
}
-125
View File
@@ -1,125 +0,0 @@
/*
* Copyright 2020 Spotify AB
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import { resolve as resolvePath } from 'path';
import chalk from 'chalk';
import chokidar from 'chokidar';
import { Package } from './packages';
import { createLogFunc } from '../logging';
export type Watcher = {
update(newPackages: Package[]): Promise<void>;
};
/*
* Watch for changes inside a collection of packages. When a change is detected, stop
* watching and call the callback with the package the change occured in.
*
* The returned promise is resolved once all watchers are ready.
*/
export async function startWatcher(
packages: Package[],
paths: string[],
callback: (pkg: Package) => void,
): Promise<Watcher> {
const watchedPackageLocations = new Set<string>();
const log = createLogFunc(process.stdout);
const watchPackage = async (pkg: Package) => {
let signalled = false;
watchedPackageLocations.add(pkg.location);
const watchLocations = paths.map((path) => resolvePath(pkg.location, path));
const watcher = chokidar
.watch(watchLocations, {
cwd: pkg.location,
ignoreInitial: true,
disableGlobbing: true,
})
.on('all', () => {
if (!signalled) {
signalled = true;
callback(pkg);
}
watcher.close();
});
return new Promise((resolve, reject) => {
watcher.on('ready', resolve);
watcher.on('error', reject);
});
};
const update = async (newPackages: Package[]) => {
const promises = new Array<Promise<unknown>>();
for (const pkg of newPackages) {
if (watchedPackageLocations.has(pkg.location)) {
continue;
}
log(chalk.green(`Starting watch of new dependency ${pkg.name}`));
promises.push(watchPackage(pkg));
}
await Promise.all(promises);
};
await Promise.all(packages.map(watchPackage));
return { update };
}
/**
* Watch a package.json for updates
*/
export function startPackageWatcher(packagePath: string, callback: () => void) {
let changed = false;
let working = false;
const notifyDeps = async () => {
changed = true;
if (working) {
return;
}
working = true;
changed = false;
try {
await callback();
} finally {
working = false;
// Keep going if a change was emitted while working
if (changed) {
notifyDeps();
}
}
};
const watcher = chokidar
.watch(packagePath, {
ignoreInitial: true,
disableGlobbing: true,
})
.on('all', () => {
notifyDeps();
});
return new Promise((resolve, reject) => {
watcher.on('ready', resolve);
watcher.on('error', reject);
});
}
+2 -2
View File
@@ -1,7 +1,7 @@
{
"name": "@backstage/config-loader",
"description": "Config loading functionality used by Backstage backend, and CLI",
"version": "0.1.1-alpha.7",
"version": "0.1.1-alpha.9",
"private": false,
"publishConfig": {
"access": "public",
@@ -30,7 +30,7 @@
"clean": "backstage-cli clean"
},
"dependencies": {
"@backstage/config": "^0.1.1-alpha.7",
"@backstage/config": "0.1.1-alpha.9",
"fs-extra": "^9.0.0",
"yaml": "^1.9.2",
"yup": "^0.28.5"
+1 -1
View File
@@ -1,7 +1,7 @@
{
"name": "@backstage/config",
"description": "Config API used by Backstage core, backend, and CLI",
"version": "0.1.1-alpha.7",
"version": "0.1.1-alpha.9",
"private": false,
"publishConfig": {
"access": "public",
+5 -5
View File
@@ -1,7 +1,7 @@
{
"name": "@backstage/core-api",
"description": "Internal Core API used by Backstage plugins and apps",
"version": "0.1.1-alpha.8",
"version": "0.1.1-alpha.9",
"private": false,
"publishConfig": {
"access": "public",
@@ -30,8 +30,8 @@
"clean": "backstage-cli clean"
},
"dependencies": {
"@backstage/config": "^0.1.1-alpha.7",
"@backstage/theme": "^0.1.1-alpha.8",
"@backstage/config": "0.1.1-alpha.9",
"@backstage/theme": "^0.1.1-alpha.9",
"@material-ui/core": "^4.9.1",
"@material-ui/icons": "^4.9.1",
"@types/react": "^16.9",
@@ -42,8 +42,8 @@
"zen-observable": "^0.8.15"
},
"devDependencies": {
"@backstage/cli": "^0.1.1-alpha.8",
"@backstage/test-utils-core": "^0.1.1-alpha.7",
"@backstage/cli": "^0.1.1-alpha.9",
"@backstage/test-utils-core": "0.1.1-alpha.9",
"@testing-library/jest-dom": "^5.7.0",
"@testing-library/react": "^9.3.2",
"@testing-library/user-event": "^10.2.4",
+6 -6
View File
@@ -1,7 +1,7 @@
{
"name": "@backstage/core",
"description": "Core API used by Backstage plugins and apps",
"version": "0.1.1-alpha.8",
"version": "0.1.1-alpha.9",
"private": false,
"publishConfig": {
"access": "public",
@@ -30,9 +30,9 @@
"clean": "backstage-cli clean"
},
"dependencies": {
"@backstage/config": "^0.1.1-alpha.7",
"@backstage/core-api": "^0.1.1-alpha.8",
"@backstage/theme": "^0.1.1-alpha.8",
"@backstage/config": "0.1.1-alpha.9",
"@backstage/core-api": "^0.1.1-alpha.9",
"@backstage/theme": "^0.1.1-alpha.9",
"@material-ui/core": "^4.9.1",
"@material-ui/icons": "^4.9.1",
"@material-ui/lab": "4.0.0-alpha.45",
@@ -55,8 +55,8 @@
"react-use": "^14.2.0"
},
"devDependencies": {
"@backstage/cli": "^0.1.1-alpha.8",
"@backstage/test-utils": "^0.1.1-alpha.8",
"@backstage/cli": "^0.1.1-alpha.9",
"@backstage/test-utils": "^0.1.1-alpha.9",
"@testing-library/jest-dom": "^5.7.0",
"@testing-library/react": "^9.3.2",
"@testing-library/user-event": "^10.2.4",
+5 -5
View File
@@ -1,7 +1,7 @@
{
"name": "@backstage/dev-utils",
"description": "Utilities for developing Backstage plugins.",
"version": "0.1.1-alpha.8",
"version": "0.1.1-alpha.9",
"private": false,
"publishConfig": {
"access": "public",
@@ -30,10 +30,10 @@
"clean": "backstage-cli clean"
},
"dependencies": {
"@backstage/cli": "^0.1.1-alpha.8",
"@backstage/core": "^0.1.1-alpha.8",
"@backstage/test-utils": "^0.1.1-alpha.8",
"@backstage/theme": "^0.1.1-alpha.8",
"@backstage/cli": "^0.1.1-alpha.9",
"@backstage/core": "^0.1.1-alpha.9",
"@backstage/test-utils": "^0.1.1-alpha.9",
"@backstage/theme": "^0.1.1-alpha.9",
"@material-ui/core": "^4.9.1",
"@material-ui/icons": "^4.9.1",
"@testing-library/jest-dom": "^5.7.0",
+2 -2
View File
@@ -1,6 +1,6 @@
{
"name": "storybook",
"version": "0.1.1-alpha.8",
"version": "0.1.1-alpha.9",
"description": "Storybook build for core package",
"private": true,
"scripts": {
@@ -14,7 +14,7 @@
]
},
"dependencies": {
"@backstage/theme": "^0.1.1-alpha.8"
"@backstage/theme": "^0.1.1-alpha.9"
},
"devDependencies": {
"@storybook/addon-actions": "^5.3.17",
+1 -1
View File
@@ -1,7 +1,7 @@
{
"name": "@backstage/test-utils-core",
"description": "Utilities to test Backstage core",
"version": "0.1.1-alpha.7",
"version": "0.1.1-alpha.9",
"private": false,
"publishConfig": {
"access": "public",
+5 -5
View File
@@ -1,7 +1,7 @@
{
"name": "@backstage/test-utils",
"description": "Utilities to test Backstage plugins and apps.",
"version": "0.1.1-alpha.8",
"version": "0.1.1-alpha.9",
"private": false,
"publishConfig": {
"access": "public",
@@ -30,10 +30,10 @@
"clean": "backstage-cli clean"
},
"dependencies": {
"@backstage/cli": "^0.1.1-alpha.8",
"@backstage/core-api": "^0.1.1-alpha.8",
"@backstage/test-utils-core": "^0.1.1-alpha.7",
"@backstage/theme": "^0.1.1-alpha.8",
"@backstage/cli": "^0.1.1-alpha.9",
"@backstage/core-api": "^0.1.1-alpha.9",
"@backstage/test-utils-core": "0.1.1-alpha.9",
"@backstage/theme": "^0.1.1-alpha.9",
"@material-ui/core": "^4.9.1",
"@testing-library/jest-dom": "^5.7.0",
"@testing-library/react": "^9.3.2",
+2 -2
View File
@@ -1,7 +1,7 @@
{
"name": "@backstage/theme",
"description": "material-ui theme for use with Backstage.",
"version": "0.1.1-alpha.8",
"version": "0.1.1-alpha.9",
"private": false,
"publishConfig": {
"access": "public",
@@ -32,7 +32,7 @@
"@material-ui/core": "^4.9.1"
},
"devDependencies": {
"@backstage/cli": "^0.1.1-alpha.8"
"@backstage/cli": "^0.1.1-alpha.9"
},
"files": [
"dist/**/*.{js,d.ts}"
+11 -10
View File
@@ -1,10 +1,10 @@
{
"name": "@backstage/plugin-auth-backend",
"version": "0.1.1-alpha.8",
"version": "0.1.1-alpha.9",
"main": "src/index.ts",
"types": "src/index.ts",
"license": "Apache-2.0",
"private": true,
"private": false,
"publishConfig": {
"access": "public",
"main": "dist/index.cjs.js",
@@ -20,12 +20,8 @@
"clean": "backstage-cli clean"
},
"dependencies": {
"@backstage/backend-common": "^0.1.1-alpha.8",
"@types/cookie-parser": "^1.4.2",
"@types/jwt-decode": "2.2.1",
"@types/passport": "^1.0.3",
"@types/passport-github2": "^1.2.4",
"@types/passport-google-oauth20": "^2.0.3",
"@backstage/backend-common": "^0.1.1-alpha.9",
"@types/express": "^4.17.6",
"body-parser": "^1.19.0",
"compression": "^1.7.4",
"cookie-parser": "^1.4.5",
@@ -44,12 +40,17 @@
"yn": "^4.0.0"
},
"devDependencies": {
"@backstage/cli": "^0.1.1-alpha.8",
"@backstage/cli": "^0.1.1-alpha.9",
"@types/body-parser": "^1.19.0",
"@types/cookie-parser": "^1.4.2",
"@types/jwt-decode": "2.2.1",
"@types/passport-github2": "^1.2.4",
"@types/passport-google-oauth20": "^2.0.3",
"@types/passport-saml": "^1.1.2",
"@types/passport": "^1.0.3",
"jest-fetch-mock": "^3.0.3"
},
"files": [
"dist"
"dist/**/*.{js,d.ts}"
]
}
@@ -96,6 +96,7 @@ export function createGithubProvider(
}
envProviders[env] = new OAuthProvider(new GithubAuthProvider(opts), {
disableRefresh: true,
providerId: 'github',
secure,
baseUrl,
@@ -143,6 +143,7 @@ export function createGoogleProvider(
}
envProviders[env] = new OAuthProvider(new GoogleAuthProvider(opts), {
disableRefresh: false,
providerId: 'google',
secure,
baseUrl,
+8 -7
View File
@@ -1,10 +1,10 @@
{
"name": "@backstage/plugin-catalog-backend",
"version": "0.1.1-alpha.8",
"version": "0.1.1-alpha.9",
"main": "src/index.ts",
"types": "src/index.ts",
"license": "Apache-2.0",
"private": true,
"private": false,
"publishConfig": {
"access": "public",
"main": "dist/index.cjs.js",
@@ -21,8 +21,9 @@
"mock-data": "./scripts/mock-data"
},
"dependencies": {
"@backstage/backend-common": "^0.1.1-alpha.8",
"@backstage/catalog-model": "^0.1.1-alpha.8",
"@backstage/backend-common": "^0.1.1-alpha.9",
"@backstage/catalog-model": "^0.1.1-alpha.9",
"@types/express": "^4.17.6",
"express": "^4.17.1",
"express-promise-router": "^3.0.3",
"fs-extra": "^9.0.0",
@@ -38,7 +39,7 @@
"yup": "^0.28.5"
},
"devDependencies": {
"@backstage/cli": "^0.1.1-alpha.8",
"@backstage/cli": "^0.1.1-alpha.9",
"@types/lodash": "^4.14.151",
"@types/node-fetch": "^2.5.7",
"@types/supertest": "^2.0.8",
@@ -48,7 +49,7 @@
"supertest": "^4.0.2"
},
"files": [
"dist",
"migrations"
"dist/**/*.{js,d.ts}",
"migrations/**/*.{js,d.ts}"
]
}
+10 -10
View File
@@ -1,11 +1,11 @@
{
"name": "@backstage/plugin-catalog",
"version": "0.1.1-alpha.8",
"version": "0.1.1-alpha.9",
"main": "dist/index.esm.js",
"main:src": "src/index.ts",
"types": "src/index.ts",
"license": "Apache-2.0",
"private": true,
"private": false,
"publishConfig": {
"access": "public",
"main": "dist/index.esm.js",
@@ -22,11 +22,11 @@
"clean": "backstage-cli clean"
},
"dependencies": {
"@backstage/catalog-model": "^0.1.1-alpha.8",
"@backstage/core": "^0.1.1-alpha.8",
"@backstage/plugin-scaffolder": "^0.1.1-alpha.8",
"@backstage/plugin-sentry": "^0.1.1-alpha.8",
"@backstage/theme": "^0.1.1-alpha.8",
"@backstage/catalog-model": "^0.1.1-alpha.9",
"@backstage/core": "^0.1.1-alpha.9",
"@backstage/plugin-scaffolder": "^0.1.1-alpha.9",
"@backstage/plugin-sentry": "^0.1.1-alpha.9",
"@backstage/theme": "^0.1.1-alpha.9",
"@material-ui/core": "^4.9.1",
"@material-ui/icons": "^4.9.1",
"@material-ui/lab": "4.0.0-alpha.45",
@@ -39,9 +39,9 @@
"swr": "^0.2.2"
},
"devDependencies": {
"@backstage/cli": "^0.1.1-alpha.8",
"@backstage/dev-utils": "^0.1.1-alpha.8",
"@backstage/test-utils": "^0.1.1-alpha.8",
"@backstage/cli": "^0.1.1-alpha.9",
"@backstage/dev-utils": "^0.1.1-alpha.9",
"@backstage/test-utils": "^0.1.1-alpha.9",
"@testing-library/jest-dom": "^5.7.0",
"@testing-library/react": "^10.2.1",
"@testing-library/react-hooks": "^3.3.0",
+7 -7
View File
@@ -1,11 +1,11 @@
{
"name": "@backstage/plugin-circleci",
"version": "0.1.1-alpha.8",
"version": "0.1.1-alpha.9",
"main": "dist/index.esm.js",
"main:src": "src/index.ts",
"types": "src/index.ts",
"license": "Apache-2.0",
"private": true,
"private": false,
"publishConfig": {
"access": "public",
"main": "dist/index.esm.js",
@@ -31,12 +31,11 @@
"postpack": "backstage-cli postpack"
},
"dependencies": {
"@backstage/core": "^0.1.1-alpha.8",
"@backstage/theme": "^0.1.1-alpha.8",
"@backstage/core": "^0.1.1-alpha.9",
"@backstage/theme": "^0.1.1-alpha.9",
"@material-ui/core": "^4.9.1",
"@material-ui/icons": "^4.9.1",
"@material-ui/lab": "4.0.0-alpha.45",
"@types/react-lazylog": "^4.5.0",
"circleci-api": "^4.0.0",
"moment": "^2.25.3",
"react": "^16.13.1",
@@ -47,13 +46,14 @@
"react-use": "^14.2.0"
},
"devDependencies": {
"@backstage/cli": "^0.1.1-alpha.8",
"@backstage/dev-utils": "^0.1.1-alpha.8",
"@backstage/cli": "^0.1.1-alpha.9",
"@backstage/dev-utils": "^0.1.1-alpha.9",
"@testing-library/jest-dom": "^5.7.0",
"@testing-library/react": "^9.3.2",
"@testing-library/user-event": "^10.2.4",
"@types/jest": "^25.2.2",
"@types/node": "^12.0.0",
"@types/react-lazylog": "^4.5.0",
"@types/testing-library__jest-dom": "^5.0.4",
"jest-fetch-mock": "^3.0.3"
},
+7 -7
View File
@@ -1,11 +1,11 @@
{
"name": "@backstage/plugin-explore",
"version": "0.1.1-alpha.8",
"version": "0.1.1-alpha.9",
"main": "dist/index.esm.js",
"main:src": "src/index.ts",
"types": "src/index.ts",
"license": "Apache-2.0",
"private": true,
"private": false,
"publishConfig": {
"access": "public",
"main": "dist/index.esm.js",
@@ -22,8 +22,8 @@
"start": "backstage-cli plugin:serve"
},
"dependencies": {
"@backstage/core": "^0.1.1-alpha.8",
"@backstage/theme": "^0.1.1-alpha.8",
"@backstage/core": "^0.1.1-alpha.9",
"@backstage/theme": "^0.1.1-alpha.9",
"@material-ui/core": "^4.9.1",
"@material-ui/icons": "^4.9.1",
"@material-ui/lab": "4.0.0-alpha.45",
@@ -33,9 +33,9 @@
"react-use": "^14.2.0"
},
"devDependencies": {
"@backstage/cli": "^0.1.1-alpha.8",
"@backstage/dev-utils": "^0.1.1-alpha.8",
"@backstage/test-utils": "^0.1.1-alpha.8",
"@backstage/cli": "^0.1.1-alpha.9",
"@backstage/dev-utils": "^0.1.1-alpha.9",
"@backstage/test-utils": "^0.1.1-alpha.9",
"@testing-library/jest-dom": "^5.7.0",
"@testing-library/react": "^9.3.2",
"@testing-library/user-event": "^10.2.4",
+6 -6
View File
@@ -1,11 +1,11 @@
{
"name": "@backstage/plugin-gitops-profiles",
"version": "0.1.1-alpha.8",
"version": "0.1.1-alpha.9",
"main": "dist/index.esm.js",
"main:src": "src/index.ts",
"types": "src/index.ts",
"license": "Apache-2.0",
"private": true,
"private": false,
"publishConfig": {
"access": "public",
"main": "dist/index.esm.js",
@@ -22,8 +22,8 @@
"clean": "backstage-cli clean"
},
"dependencies": {
"@backstage/core": "^0.1.1-alpha.8",
"@backstage/theme": "^0.1.1-alpha.8",
"@backstage/core": "^0.1.1-alpha.9",
"@backstage/theme": "^0.1.1-alpha.9",
"@material-ui/core": "^4.9.1",
"@material-ui/icons": "^4.9.1",
"@material-ui/lab": "4.0.0-alpha.45",
@@ -33,8 +33,8 @@
"react-use": "^14.2.0"
},
"devDependencies": {
"@backstage/cli": "^0.1.1-alpha.8",
"@backstage/dev-utils": "^0.1.1-alpha.8",
"@backstage/cli": "^0.1.1-alpha.9",
"@backstage/dev-utils": "^0.1.1-alpha.9",
"@testing-library/jest-dom": "^5.7.0",
"@testing-library/react": "^9.3.2",
"@testing-library/user-event": "^10.2.4",
+1 -1
View File
@@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import { createApiRef } from '@backstage/core-api';
import { createApiRef } from '@backstage/core';
export interface CloneFromTemplateRequest {
templateRepository: string;
@@ -20,7 +20,7 @@ import mockFetch from 'jest-fetch-mock';
import ProfileCatalog from './ProfileCatalog';
import { ThemeProvider } from '@material-ui/core';
import { lightTheme } from '@backstage/theme';
import { ApiProvider, ApiRegistry } from '@backstage/core-api';
import { ApiProvider, ApiRegistry } from '@backstage/core';
import { gitOpsApiRef, GitOpsRestApi } from '../../api';
describe('ProfileCatalog', () => {
+6 -6
View File
@@ -1,7 +1,7 @@
{
"name": "@backstage/plugin-graphiql",
"description": "Backstage plugin for browsing GraphQL APIs",
"version": "0.1.1-alpha.8",
"version": "0.1.1-alpha.9",
"private": false,
"publishConfig": {
"access": "public",
@@ -32,8 +32,8 @@
"clean": "backstage-cli clean"
},
"dependencies": {
"@backstage/core": "^0.1.1-alpha.8",
"@backstage/theme": "^0.1.1-alpha.8",
"@backstage/core": "^0.1.1-alpha.9",
"@backstage/theme": "^0.1.1-alpha.9",
"@material-ui/core": "^4.9.1",
"@material-ui/icons": "^4.9.1",
"@material-ui/lab": "4.0.0-alpha.45",
@@ -44,9 +44,9 @@
"react-use": "^14.2.0"
},
"devDependencies": {
"@backstage/cli": "^0.1.1-alpha.8",
"@backstage/dev-utils": "^0.1.1-alpha.8",
"@backstage/test-utils": "^0.1.1-alpha.8",
"@backstage/cli": "^0.1.1-alpha.9",
"@backstage/dev-utils": "^0.1.1-alpha.9",
"@backstage/test-utils": "^0.1.1-alpha.9",
"@testing-library/jest-dom": "^5.7.0",
"@testing-library/react": "^9.3.2",
"@testing-library/user-event": "^10.2.4",
+6 -5
View File
@@ -1,10 +1,10 @@
{
"name": "@backstage/plugin-identity-backend",
"version": "0.1.1-alpha.8",
"version": "0.1.1-alpha.9",
"main": "src/index.ts",
"types": "src/index.ts",
"license": "Apache-2.0",
"private": true,
"private": false,
"publishConfig": {
"access": "public",
"main": "dist/index.cjs.js",
@@ -20,7 +20,8 @@
"clean": "backstage-cli clean"
},
"dependencies": {
"@backstage/backend-common": "^0.1.1-alpha.8",
"@backstage/backend-common": "^0.1.1-alpha.9",
"@types/express": "^4.17.6",
"compression": "^1.7.4",
"cors": "^2.8.5",
"express": "^4.17.1",
@@ -32,10 +33,10 @@
"yn": "^4.0.0"
},
"devDependencies": {
"@backstage/cli": "^0.1.1-alpha.8",
"@backstage/cli": "^0.1.1-alpha.9",
"jest-fetch-mock": "^3.0.3"
},
"files": [
"dist"
"dist/**/*.{js,d.ts}"
]
}
@@ -0,0 +1,82 @@
/*
* Copyright 2020 Spotify AB
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import {
Group,
GroupsResponse,
IdentityApi,
GroupsRequest,
GroupsJson,
} from './types';
export class StaticJsonAdapter implements IdentityApi {
private readonly groups: Group[];
constructor(userGroups: GroupsJson) {
this.groups = userGroups.groups;
}
getUserGroups(req: GroupsRequest): Promise<GroupsResponse> {
return new Promise(resolve => {
const { user, type } = req;
const userGroups = this._getUserGroups(this.groups, user);
const groups = this.filterGroupsByType(userGroups, type);
resolve({ groups });
});
}
_getUserGroups(groups: Group[], user: string) {
const userGroups: Set<Group> = new Set();
groups.forEach(group => {
if (this.isUserInGroup(group, user)) {
userGroups.add(group);
}
if (group.children) {
const userSubGroups = this._getUserGroups(group.children, user) ?? [];
const isUserInSubGroup = Boolean(userSubGroups.length);
if (isUserInSubGroup) {
userGroups.add(group);
}
userSubGroups.forEach(subGroup => userGroups.add(subGroup));
}
});
return Array.from(userGroups);
}
private filterGroupsByType = (userGroups: Group[], type: string) => {
const groups = type
? userGroups
.filter((group: Group) => group.type === type)
.map(group => ({ name: group.name, type: group.type }))
: userGroups.map(group => ({
name: group.name,
type: group.type,
}));
return groups;
};
private isUserInGroup = (group: Group, user: string): boolean => {
if (group.members) {
const groupMembers = group.members;
const groupsWithUser = groupMembers.filter(
member => member.name === user,
);
return Boolean(groupsWithUser.length);
}
return false;
};
}
@@ -14,4 +14,4 @@
* limitations under the License.
*/
export * from './watchDeps';
export * from './StaticJsonAdapter';
@@ -14,20 +14,29 @@
* limitations under the License.
*/
import { createLogPipe } from '../logging';
export type User = {
name: string;
};
export type ColorFunc = (msg: string) => string;
export type Group = {
name: string;
type: string;
members?: User[];
children?: Group[];
};
// A factory for creating log pipes that rotate between different coloring functions
export function createLogPipeFactory(colorFuncs: ColorFunc[]) {
let colorIndex = 0;
export type GroupsJson = {
groups: Group[];
};
return (name: string) => {
const colorFunc = colorFuncs[colorIndex];
export type GroupsResponse = {
groups: Group[];
};
colorIndex = (colorIndex + 1) % colorFuncs.length;
const prefix = `${colorFunc(name)}: `;
return createLogPipe({ prefix });
};
export type GroupsRequest = {
user: string;
type: string;
};
export interface IdentityApi {
getUserGroups(req: GroupsRequest): Promise<GroupsResponse>;
}
@@ -13,6 +13,23 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
export * from './withCache';
export * from './options';
export const userGroups = {
groups: [
{
name: 'engineering',
type: 'org',
children: [
{
name: 'authentication',
type: 'team',
members: [{ name: 'kent' }, { name: 'dobbs' }],
},
{
name: 'checkout',
type: 'team',
members: [{ name: 'don' }, { name: 'abramev' }],
},
],
},
],
};
+18 -7
View File
@@ -17,21 +17,32 @@
import express from 'express';
import Router from 'express-promise-router';
import { Logger } from 'winston';
import { StaticJsonAdapter } from '../adapters';
import { IdentityApi } from '../adapters/types';
import { userGroups } from '../adapters/userGroups';
export interface RouterOptions {
logger: Logger;
}
const makeRouter = (adapter: IdentityApi): express.Router => {
const router = Router();
router.get('/users/:user/groups', async (req, res) => {
const user = req.params.user;
const type = req.query.type?.toString() ?? '';
const response = await adapter.getUserGroups({ user, type });
res.send(response);
});
return router;
};
export async function createRouter(
options: RouterOptions,
): Promise<express.Router> {
const router = Router();
const logger = options.logger;
router.use('/ping', (_, res) => {
logger.info('heartbeat for identity service');
res.send('pong');
});
return router;
logger.info('Initializing identity API backend');
const adapter = new StaticJsonAdapter(userGroups);
return makeRouter(adapter);
}
+6 -6
View File
@@ -1,6 +1,6 @@
{
"name": "@backstage/plugin-lighthouse",
"version": "0.1.1-alpha.8",
"version": "0.1.1-alpha.9",
"main": "dist/index.esm.js",
"main:src": "src/index.ts",
"types": "src/index.ts",
@@ -22,8 +22,8 @@
"start": "backstage-cli plugin:serve"
},
"dependencies": {
"@backstage/core": "^0.1.1-alpha.8",
"@backstage/theme": "^0.1.1-alpha.8",
"@backstage/core": "^0.1.1-alpha.9",
"@backstage/theme": "^0.1.1-alpha.9",
"@material-ui/core": "^4.9.1",
"@material-ui/icons": "^4.9.1",
"@material-ui/lab": "4.0.0-alpha.45",
@@ -34,9 +34,9 @@
"react-use": "^14.2.0"
},
"devDependencies": {
"@backstage/cli": "^0.1.1-alpha.8",
"@backstage/dev-utils": "^0.1.1-alpha.8",
"@backstage/test-utils": "^0.1.1-alpha.8",
"@backstage/cli": "^0.1.1-alpha.9",
"@backstage/dev-utils": "^0.1.1-alpha.9",
"@backstage/test-utils": "^0.1.1-alpha.9",
"@testing-library/jest-dom": "^5.7.0",
"@testing-library/react": "^9.3.2",
"@testing-library/user-event": "^10.2.4",
+8 -8
View File
@@ -1,11 +1,11 @@
{
"name": "@backstage/plugin-register-component",
"version": "0.1.1-alpha.8",
"version": "0.1.1-alpha.9",
"main": "dist/index.esm.js",
"main:src": "src/index.ts",
"types": "src/index.ts",
"license": "Apache-2.0",
"private": true,
"private": false,
"publishConfig": {
"access": "public",
"main": "dist/index.esm.js",
@@ -22,10 +22,10 @@
"clean": "backstage-cli clean"
},
"dependencies": {
"@backstage/catalog-model": "^0.1.1-alpha.8",
"@backstage/core": "^0.1.1-alpha.8",
"@backstage/plugin-catalog": "^0.1.1-alpha.8",
"@backstage/theme": "^0.1.1-alpha.8",
"@backstage/catalog-model": "^0.1.1-alpha.9",
"@backstage/core": "^0.1.1-alpha.9",
"@backstage/plugin-catalog": "^0.1.1-alpha.9",
"@backstage/theme": "^0.1.1-alpha.9",
"@material-ui/core": "^4.9.1",
"@material-ui/icons": "^4.9.1",
"@material-ui/lab": "4.0.0-alpha.45",
@@ -37,8 +37,8 @@
"react-use": "^14.2.0"
},
"devDependencies": {
"@backstage/cli": "^0.1.1-alpha.8",
"@backstage/dev-utils": "^0.1.1-alpha.8",
"@backstage/cli": "^0.1.1-alpha.9",
"@backstage/dev-utils": "^0.1.1-alpha.9",
"@testing-library/jest-dom": "^5.7.0",
"@testing-library/react": "^9.3.2",
"@testing-library/user-event": "^10.2.4",
+9 -5
View File
@@ -1,10 +1,10 @@
{
"name": "@backstage/plugin-scaffolder-backend",
"version": "0.1.1-alpha.8",
"version": "0.1.1-alpha.9",
"main": "src/index.ts",
"types": "src/index.ts",
"license": "Apache-2.0",
"private": true,
"private": false,
"publishConfig": {
"access": "public",
"main": "dist/index.cjs.js",
@@ -21,7 +21,8 @@
"mock-data": "./scripts/mock-data"
},
"dependencies": {
"@backstage/backend-common": "^0.1.1-alpha.8",
"@backstage/backend-common": "^0.1.1-alpha.9",
"@types/express": "^4.17.6",
"compression": "^1.7.4",
"cors": "^2.8.5",
"dockerode": "^3.2.0",
@@ -34,9 +35,12 @@
"winston": "^3.2.1"
},
"devDependencies": {
"@backstage/cli": "^0.1.1-alpha.8",
"@backstage/cli": "^0.1.1-alpha.9",
"@types/fs-extra": "^9.0.1",
"@types/supertest": "^2.0.8",
"supertest": "^4.0.2"
}
},
"files": [
"dist/**/*.{js,d.ts}"
]
}
+6 -6
View File
@@ -1,11 +1,11 @@
{
"name": "@backstage/plugin-scaffolder",
"version": "0.1.1-alpha.8",
"version": "0.1.1-alpha.9",
"main": "dist/index.esm.js",
"main:src": "src/index.ts",
"types": "src/index.ts",
"license": "Apache-2.0",
"private": true,
"private": false,
"publishConfig": {
"access": "public",
"main": "dist/index.esm.js",
@@ -22,8 +22,8 @@
"clean": "backstage-cli clean"
},
"dependencies": {
"@backstage/core": "^0.1.1-alpha.8",
"@backstage/theme": "^0.1.1-alpha.8",
"@backstage/core": "^0.1.1-alpha.9",
"@backstage/theme": "^0.1.1-alpha.9",
"@material-ui/core": "^4.9.1",
"@material-ui/icons": "^4.9.1",
"@material-ui/lab": "4.0.0-alpha.45",
@@ -33,8 +33,8 @@
"react-use": "^14.2.0"
},
"devDependencies": {
"@backstage/cli": "^0.1.1-alpha.8",
"@backstage/dev-utils": "^0.1.1-alpha.8",
"@backstage/cli": "^0.1.1-alpha.9",
"@backstage/dev-utils": "^0.1.1-alpha.9",
"@testing-library/jest-dom": "^5.7.0",
"@testing-library/react": "^9.3.2",
"@testing-library/user-event": "^10.2.4",
+6 -5
View File
@@ -1,10 +1,10 @@
{
"name": "@backstage/plugin-sentry-backend",
"version": "0.1.1-alpha.8",
"version": "0.1.1-alpha.9",
"main": "src/index.ts",
"types": "src/index.ts",
"license": "Apache-2.0",
"private": true,
"private": false,
"publishConfig": {
"access": "public",
"main": "dist/index.cjs.js",
@@ -20,7 +20,8 @@
"clean": "backstage-cli clean"
},
"dependencies": {
"@backstage/backend-common": "^0.1.1-alpha.8",
"@backstage/backend-common": "^0.1.1-alpha.9",
"@types/express": "^4.17.6",
"axios": "^0.19.2",
"compression": "^1.7.4",
"cors": "^2.8.5",
@@ -33,10 +34,10 @@
"yn": "^4.0.0"
},
"devDependencies": {
"@backstage/cli": "^0.1.1-alpha.8",
"@backstage/cli": "^0.1.1-alpha.9",
"jest-fetch-mock": "^3.0.3"
},
"files": [
"dist"
"dist/**/*.{js,d.ts}"
]
}
+7 -6
View File
@@ -1,11 +1,11 @@
{
"name": "@backstage/plugin-sentry",
"version": "0.1.1-alpha.8",
"version": "0.1.1-alpha.9",
"main": "dist/index.esm.js",
"main:src": "src/index.ts",
"types": "src/index.ts",
"license": "Apache-2.0",
"private": true,
"private": false,
"publishConfig": {
"access": "public",
"main": "dist/index.esm.js",
@@ -22,11 +22,12 @@
"clean": "backstage-cli clean"
},
"dependencies": {
"@backstage/core": "^0.1.1-alpha.8",
"@backstage/theme": "^0.1.1-alpha.8",
"@backstage/core": "^0.1.1-alpha.9",
"@backstage/theme": "^0.1.1-alpha.9",
"@material-ui/core": "^4.9.1",
"@material-ui/icons": "^4.9.1",
"@material-ui/lab": "4.0.0-alpha.45",
"@types/react": "^16.9",
"react": "^16.13.1",
"react-dom": "^16.13.1",
"react-sparklines": "^1.7.0",
@@ -34,8 +35,8 @@
"timeago.js": "^4.0.2"
},
"devDependencies": {
"@backstage/cli": "^0.1.1-alpha.8",
"@backstage/dev-utils": "^0.1.1-alpha.8",
"@backstage/cli": "^0.1.1-alpha.9",
"@backstage/dev-utils": "^0.1.1-alpha.9",
"@testing-library/jest-dom": "^5.7.0",
"@testing-library/react": "^9.3.2",
"@testing-library/user-event": "^10.2.4",
+6 -6
View File
@@ -1,6 +1,6 @@
{
"name": "@backstage/plugin-tech-radar",
"version": "0.1.1-alpha.8",
"version": "0.1.1-alpha.9",
"main": "dist/index.esm.js",
"main:src": "src/index.ts",
"types": "src/index.ts",
@@ -22,9 +22,9 @@
"start": "backstage-cli plugin:serve"
},
"dependencies": {
"@backstage/core": "^0.1.1-alpha.8",
"@backstage/test-utils-core": "^0.1.1-alpha.7",
"@backstage/theme": "^0.1.1-alpha.8",
"@backstage/core": "^0.1.1-alpha.9",
"@backstage/test-utils-core": "0.1.1-alpha.9",
"@backstage/theme": "^0.1.1-alpha.9",
"@material-ui/core": "^4.9.1",
"@material-ui/icons": "^4.9.1",
"@material-ui/lab": "4.0.0-alpha.45",
@@ -37,8 +37,8 @@
"react-use": "^14.2.0"
},
"devDependencies": {
"@backstage/cli": "^0.1.1-alpha.8",
"@backstage/dev-utils": "^0.1.1-alpha.8",
"@backstage/cli": "^0.1.1-alpha.9",
"@backstage/dev-utils": "^0.1.1-alpha.9",
"@testing-library/jest-dom": "^5.7.0",
"@testing-library/react": "^9.3.2",
"@testing-library/user-event": "^10.2.4",
+6 -6
View File
@@ -1,10 +1,10 @@
{
"name": "@backstage/plugin-welcome",
"version": "0.1.1-alpha.8",
"version": "0.1.1-alpha.9",
"main": "dist/index.esm.js",
"main:src": "src/index.ts",
"types": "src/index.ts",
"private": true,
"private": false,
"license": "Apache-2.0",
"publishConfig": {
"access": "public",
@@ -22,8 +22,8 @@
"start": "backstage-cli plugin:serve"
},
"dependencies": {
"@backstage/core": "^0.1.1-alpha.8",
"@backstage/theme": "^0.1.1-alpha.8",
"@backstage/core": "^0.1.1-alpha.9",
"@backstage/theme": "^0.1.1-alpha.9",
"@material-ui/core": "^4.9.1",
"@material-ui/icons": "^4.9.1",
"@material-ui/lab": "4.0.0-alpha.45",
@@ -33,8 +33,8 @@
"react-use": "^14.2.0"
},
"devDependencies": {
"@backstage/cli": "^0.1.1-alpha.8",
"@backstage/dev-utils": "^0.1.1-alpha.8",
"@backstage/cli": "^0.1.1-alpha.9",
"@backstage/dev-utils": "^0.1.1-alpha.9",
"@testing-library/jest-dom": "^5.7.0",
"@testing-library/react": "^9.3.2",
"@testing-library/user-event": "^10.2.4",
+3 -3
View File
@@ -17790,9 +17790,9 @@ svgo@^1.0.0, svgo@^1.2.2:
util.promisify "~1.0.0"
swr@^0.2.2:
version "0.2.2"
resolved "https://registry.npmjs.org/swr/-/swr-0.2.2.tgz#6e1b3e5c0e545c4fdb36ae3aa38cd94d0f9a88b7"
integrity sha512-D/z+PTUchZhoUA0tNC8TNJivf7Hc61WPxbUdXPi+VxRloddWYNP1ZicaEgyAph42ZnKl1L7twcZr4q6d0UMXcg==
version "0.2.3"
resolved "https://registry.npmjs.org/swr/-/swr-0.2.3.tgz#e0fb260d27f12fafa2388312083368f45127480d"
integrity sha512-JhuuD5ojqgjAQpZAhoPBd8Di0Mr1+ykByVKuRJdtKaxkUX/y8kMACWKkLgLQc8pcDOKEAnbIreNjU7HfqI9nHQ==
dependencies:
fast-deep-equal "2.0.1"