drop support for src-relative imports

This commit is contained in:
Patrik Oldsberg
2020-05-06 16:38:07 +02:00
parent a8584e7cec
commit 70040b22a7
73 changed files with 153 additions and 249 deletions
-1
View File
@@ -1,7 +1,6 @@
{
"include": ["src"],
"compilerOptions": {
"baseUrl": "src",
"outDir": "dist",
"incremental": true,
"sourceMap": true,
-1
View File
@@ -1,7 +1,6 @@
{
"include": ["src"],
"compilerOptions": {
"baseUrl": "src",
"outDir": "dist",
"incremental": true,
"sourceMap": true,
-56
View File
@@ -21,68 +21,12 @@ const path = require('path');
const isLocal = require('fs').existsSync(path.resolve(__dirname, '../src'));
if (!isLocal || process.env.BACKSTAGE_E2E_CLI_TEST) {
// src-relative imports are a pain to get to work with plain tsc compilation, as the
// transpiled code will maintain the imports as they are in the source. Which means an
// import for `helpers/paths` will start like that in the output, which won't work in NodeJS.
//
// This is a solution for getting src-relative imports to work with typescript/node in
// the published package. We're using `module: "amd"` to ship the entire cli implementation
// in one file, and it also happens to generate correct module definition and import statements.
// Minimal AMD implementation
const moduleFactories = {};
const moduleCache = {};
global.define = (name, deps, moduleFunc) => {
moduleFactories[name] = () => {
const exportsObj = {};
// require() that first searches for locally defined amd modules
const requireFunc = name => {
let factory = moduleFactories[name];
if (!factory) {
// Check /index as well, to mirror nodejs resolution
const index = `${name}/index`;
if (!moduleFactories[index]) {
return require(name);
}
name = index;
factory = moduleFactories[name];
}
if (!moduleCache[name]) {
moduleCache[name] = factory();
}
return moduleCache[name];
};
const impls = deps.slice(2).map(requireFunc);
moduleFunc(requireFunc, exportsObj, ...impls);
return exportsObj;
};
};
require('../dist');
// index module is the entrypoint
moduleFactories.index();
} else {
const tsConfigPath = path.resolve(__dirname, '../tsconfig.json');
const {
baseUrl: relativeBaseUrl,
paths = {},
} = require(tsConfigPath).compilerOptions;
const baseUrl = path.resolve(__dirname, '..', relativeBaseUrl);
// Use tsconfig-paths to resolve src-relative paths during development
const cleanupPaths = require('tsconfig-paths').register({ baseUrl, paths });
require('ts-node').register({
project: path.resolve(__dirname, '../tsconfig.build.json'),
compilerOptions: {
module: 'CommonJS',
},
transpileOnly: true,
});
require('../src');
cleanupPaths();
}
-1
View File
@@ -45,7 +45,6 @@
"del": "^5.1.0",
"nodemon": "^2.0.2",
"ts-node": "^8.6.2",
"tsconfig-paths": "^3.9.0",
"zombie": "^6.1.4"
},
"dependencies": {
+1 -1
View File
@@ -14,7 +14,7 @@
* limitations under the License.
*/
import { run } from 'lib/run';
import { run } from '../../lib/run';
export default async () => {
const args = ['build'];
+3 -3
View File
@@ -14,9 +14,9 @@
* limitations under the License.
*/
import { run } from 'lib/run';
import { createLogFunc } from 'lib/logging';
import { watchDeps } from 'lib/watchDeps';
import { run } from '../../lib/run';
import { createLogFunc } from '../../lib/logging';
import { watchDeps } from '../../lib/watchDeps';
export default async () => {
// Start dynamic watch and build of dependencies, then serve the app
@@ -15,8 +15,8 @@
*/
import { Command } from 'commander';
import { run } from 'lib/run';
import { withCache, parseOptions } from 'lib/buildCache';
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.
+2 -2
View File
@@ -16,8 +16,8 @@
import fs from 'fs-extra';
import { resolve as resolvePath, relative as relativePath } from 'path';
import { paths } from 'lib/paths';
import { getDefaultCacheOptions } from 'lib/buildCache';
import { paths } from '../../lib/paths';
import { getDefaultCacheOptions } from '../../lib/buildCache';
export default async function clean() {
const cacheOptions = getDefaultCacheOptions();
@@ -21,9 +21,9 @@ import inquirer, { Answers, Question } from 'inquirer';
import { exec as execCb } from 'child_process';
import { resolve as resolvePath } from 'path';
import os from 'os';
import { Task, templatingTask } from 'lib/tasks';
import { paths } from 'lib/paths';
import { version } from 'lib/version';
import { Task, templatingTask } from '../../lib/tasks';
import { paths } from '../../lib/paths';
import { version } from '../../lib/version';
const exec = promisify(execCb);
async function checkExists(rootDir: string, name: string) {
@@ -63,7 +63,7 @@ async function buildApp(appFolder: string) {
await Task.forItem('executing', command, async () => {
process.chdir(appFolder);
await exec(command).catch(error => {
await exec(command).catch((error) => {
process.stdout.write(error.stderr);
process.stdout.write(error.stdout);
throw new Error(`Could not execute command ${chalk.cyan(command)}`);
@@ -78,7 +78,7 @@ export async function moveApp(
id: string,
) {
await Task.forItem('moving', id, async () => {
await fs.move(tempDir, destination).catch(error => {
await fs.move(tempDir, destination).catch((error) => {
throw new Error(
`Failed to move app from ${tempDir} to ${destination}: ${error.message}`,
);
@@ -101,7 +101,7 @@ async function addPackageResolutions(appDir: string) {
packageFileJson.resolutions[`@backstage/${pkg}`] = `file:${pkgPath}`;
const newContents = `${JSON.stringify(packageFileJson, null, 2)}\n`;
await fs.writeFile(pkgJsonPath, newContents, 'utf-8').catch(error => {
await fs.writeFile(pkgJsonPath, newContents, 'utf-8').catch((error) => {
throw new Error(
`Failed to add resolutions to package.json: ${error.message}`,
);
@@ -25,10 +25,10 @@ import {
parseOwnerIds,
addCodeownersEntry,
getCodeownersFilePath,
} from 'lib/codeowners';
import { paths } from 'lib/paths';
import { version } from 'lib/version';
import { Task, templatingTask } from 'lib/tasks';
} from '../../lib/codeowners';
import { paths } from '../../lib/paths';
import { version } from '../../lib/version';
import { Task, templatingTask } from '../../lib/tasks';
const exec = promisify(execCb);
async function checkExists(rootDir: string, id: string) {
@@ -107,7 +107,7 @@ export async function addPluginDependencyToApp(
packageFileJson.dependencies = sortObjectByKeys(dependencies);
const newContents = `${JSON.stringify(packageFileJson, null, 2)}\n`;
await fs.writeFile(packageFile, newContents, 'utf-8').catch(error => {
await fs.writeFile(packageFile, newContents, 'utf-8').catch((error) => {
throw new Error(
`Failed to add plugin as dependency to app: ${packageFile}: ${error.message}`,
);
@@ -119,14 +119,14 @@ export async function addPluginToApp(rootDir: string, pluginName: string) {
const pluginPackage = `@backstage/plugin-${pluginName}`;
const pluginNameCapitalized = pluginName
.split('-')
.map(name => capitalize(name))
.map((name) => capitalize(name))
.join('');
const pluginExport = `export { plugin as ${pluginNameCapitalized} } from '${pluginPackage}';`;
const pluginsFilePath = 'packages/app/src/plugins.ts';
const pluginsFile = resolvePath(rootDir, pluginsFilePath);
await Task.forItem('processing', pluginsFilePath, async () => {
await addExportStatement(pluginsFile, pluginExport).catch(error => {
await addExportStatement(pluginsFile, pluginExport).catch((error) => {
throw new Error(
`Failed to import plugin in app: ${pluginsFile}: ${error.message}`,
);
@@ -146,7 +146,7 @@ async function buildPlugin(pluginFolder: string) {
await Task.forItem('executing', command, async () => {
process.chdir(pluginFolder);
await exec(command).catch(error => {
await exec(command).catch((error) => {
process.stdout.write(error.stderr);
process.stdout.write(error.stdout);
throw new Error(`Could not execute command ${chalk.cyan(command)}`);
@@ -161,7 +161,7 @@ export async function movePlugin(
id: string,
) {
await Task.forItem('moving', id, async () => {
await fs.move(tempDir, destination).catch(error => {
await fs.move(tempDir, destination).catch((error) => {
throw new Error(
`Failed to move plugin from ${tempDir} to ${destination}: ${error.message}`,
);
+1 -1
View File
@@ -15,7 +15,7 @@
*/
import { Command } from 'commander';
import { run } from 'lib/run';
import { run } from '../lib/run';
export default async (cmd: Command) => {
const args = ['lint', '--max-warnings=0', '--format=codeframe'];
+3 -3
View File
@@ -17,8 +17,8 @@
import { rollup, watch, OutputOptions } from 'rollup';
import { Command } from 'commander';
import chalk from 'chalk';
import { withCache, getDefaultCacheOptions } from 'lib/buildCache';
import { paths } from 'lib/paths';
import { withCache, getDefaultCacheOptions } from '../../lib/buildCache';
import { paths } from '../../lib/paths';
import conf from './rollup.config';
function logError(error: any) {
@@ -62,7 +62,7 @@ export default async (cmd: Command) => {
// Instead we just wait until the user sends an interrupt signal.
await new Promise(() => {
const watcher = watch(conf);
watcher.on('event', event => {
watcher.on('event', (event) => {
// START — the watcher is (re)starting
// BUNDLE_START — building an individual bundle
// BUNDLE_END — finished building a bundle
@@ -18,7 +18,7 @@ import fs from 'fs-extra';
import chalk from 'chalk';
import { dirname } from 'path';
import { diffLines } from 'diff';
import { paths } from 'lib/paths';
import { paths } from '../../../lib/paths';
import { TemplateFile, PromptFunc, FileHandler } from './types';
export async function writeTargetFile(targetPath: string, contents: string) {
@@ -193,8 +193,8 @@ export async function handleAllFiles(
) {
for (const file of files) {
const { targetPath } = file;
const fileHandler = fileHandlers.find(handler =>
handler.patterns.some(pattern =>
const fileHandler = fileHandlers.find((handler) =>
handler.patterns.some((pattern) =>
typeof pattern === 'string'
? pattern === targetPath
: pattern.test(targetPath),
@@ -18,8 +18,8 @@ import fs from 'fs-extra';
import { relative as relativePath } from 'path';
import handlebars from 'handlebars';
import recursiveReadDir from 'recursive-readdir';
import { paths } from 'lib/paths';
import { version } from 'lib/version';
import { paths } from '../../../lib/paths';
import { version } from '../../../lib/version';
import { PluginInfo, TemplateFile } from './types';
// Reads info from the existing plugin
@@ -22,7 +22,7 @@ import postcss from 'rollup-plugin-postcss';
import imageFiles from 'rollup-plugin-image-files';
import json from '@rollup/plugin-json';
import { RollupWatchOptions } from 'rollup';
import { paths } from 'lib/paths';
import { paths } from '../../lib/paths';
export default {
input: 'src/index.ts',
@@ -15,7 +15,7 @@
*/
import { startDevServer } from './server';
import { watchDeps } from 'lib/watchDeps';
import { watchDeps } from '../../../lib/watchDeps';
export default async () => {
await watchDeps({ build: true });
@@ -15,7 +15,7 @@
*/
import { existsSync } from 'fs';
import { paths } from 'lib/paths';
import { paths } from '../../../lib/paths';
export function getPaths() {
const resolveTargetModule = (path: string) => {
@@ -15,7 +15,7 @@
*/
import { Command } from 'commander';
import { run } from 'lib/run';
import { run } from '../../lib/run';
export default async (cmd: Command) => {
const args = ['test'];
@@ -17,13 +17,13 @@
import fse from 'fs-extra';
import path from 'path';
import os from 'os';
import { paths } from 'lib/paths';
import { paths } from '../../lib/paths';
import {
addExportStatement,
capitalize,
createTemporaryPluginFolder,
} from '../create-plugin/createPlugin';
import { addCodeownersEntry } from 'lib/codeowners';
import { addCodeownersEntry } from '../../lib/codeowners';
import {
removeReferencesFromAppPackage,
removeReferencesFromPluginsFile,
@@ -39,10 +39,7 @@ const testPluginPackage = `${BACKSTAGE}/plugin-${testPluginName}`;
const tempDir = path.join(os.tmpdir(), 'remove-plugin-test');
const removeEmptyLines = (file: string): string =>
file
.split('\n')
.filter(Boolean)
.join('\n');
file.split('\n').filter(Boolean).join('\n');
const createTestPackageFile = async (
testFilePath: string,
@@ -69,7 +66,7 @@ const createTestPluginFile = async (
fse.copyFileSync(pluginsFilePath, testFilePath);
const pluginNameCapitalized = testPluginName
.split('-')
.map(name => capitalize(name))
.map((name) => capitalize(name))
.join('');
const exportStatement = `export { default as ${pluginNameCapitalized}} from @backstage/plugin-${testPluginName}`;
addExportStatement(testFilePath, exportStatement);
@@ -17,9 +17,9 @@ import fse from 'fs-extra';
import path from 'path';
import chalk from 'chalk';
import inquirer, { Answers, Question } from 'inquirer';
import { getCodeownersFilePath } from 'lib/codeowners';
import { paths } from 'lib/paths';
import { Task } from 'lib/tasks';
import { getCodeownersFilePath } from '../../lib/codeowners';
import { paths } from '../../lib/paths';
import { Task } from '../../lib/tasks';
// import os from 'os';
const BACKSTAGE = '@backstage';
@@ -85,7 +85,7 @@ const removeAllStatementsContainingID = async (file: string, ID: string) => {
const contentAfterRemoval = originalContent
.split('\n')
.filter(Boolean) // get rid of empty lines
.filter(statement => {
.filter((statement) => {
return !statement.includes(`${ID}`);
}) // get rid of lines with pluginName
.concat(['']) // newline at end of line
@@ -105,7 +105,7 @@ export const removeReferencesFromPluginsFile = async (
) => {
const pluginNameCapitalized = pluginName
.split('-')
.map(name => capitalize(name))
.map((name) => capitalize(name))
.join('');
await Task.forItem('removing', 'export references', async () => {
+2 -2
View File
@@ -15,8 +15,8 @@
*/
import { Command } from 'commander';
import { paths } from 'lib/paths';
import { runCheck } from 'lib/run';
import { paths } from '../lib/paths';
import { runCheck } from '../lib/run';
function includesAnyOf(hayStack: string[], ...needles: string[]) {
for (const needle of needles) {
@@ -15,9 +15,9 @@
*/
import { Command } from 'commander';
import { run } from 'lib/run';
import { createLogPipe } from 'lib/logging';
import { watchDeps, Options } from 'lib/watchDeps';
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
+16 -16
View File
@@ -16,8 +16,8 @@
import program from 'commander';
import chalk from 'chalk';
import { exitWithError } from 'lib/errors';
import { version } from 'lib/version';
import { exitWithError } from './lib/errors';
import { version } from './lib/version';
const main = (argv: string[]) => {
program.name('backstage-cli').version(version);
@@ -25,68 +25,68 @@ const main = (argv: string[]) => {
program
.command('create-app')
.description('Creates a new app in a new directory')
.action(actionHandler(() => require('commands/create-app/createApp')));
.action(actionHandler(() => require('./commands/create-app/createApp')));
program
.command('app:build')
.description('Build an app for a production release')
.action(actionHandler(() => require('commands/app/build')));
.action(actionHandler(() => require('./commands/app/build')));
program
.command('app:serve')
.description('Serve an app for local development')
.action(actionHandler(() => require('commands/app/serve')));
.action(actionHandler(() => require('./commands/app/serve')));
program
.command('create-plugin')
.description('Creates a new plugin in the current repository')
.action(
actionHandler(() => require('commands/create-plugin/createPlugin')),
actionHandler(() => require('./commands/create-plugin/createPlugin')),
);
program
.command('remove-plugin')
.description('Removes plugin in the current repository')
.action(
actionHandler(() => require('commands/remove-plugin/removePlugin')),
actionHandler(() => require('./commands/remove-plugin/removePlugin')),
);
program
.command('plugin:build')
.option('--watch', 'Enable watch mode')
.description('Build a plugin')
.action(actionHandler(() => require('commands/plugin/build')));
.action(actionHandler(() => require('./commands/plugin/build')));
program
.command('plugin:serve')
.description('Serves the dev/ folder of a plugin')
.action(actionHandler(() => require('commands/plugin/serve')));
.action(actionHandler(() => require('./commands/plugin/serve')));
program
.command('plugin:diff')
.option('--check', 'Fail if changes are required')
.option('--yes', 'Apply all changes')
.description('Diff an existing plugin with the creation template')
.action(actionHandler(() => require('commands/plugin/diff')));
.action(actionHandler(() => require('./commands/plugin/diff')));
program
.command('lint')
.option('--fix', 'Attempt to automatically fix violations')
.description('Lint a package')
.action(actionHandler(() => require('commands/lint')));
.action(actionHandler(() => require('./commands/lint')));
program
.command('test')
.allowUnknownOption(true) // Allows the command to run, but we still need to parse raw args
.helpOption(', --backstage-cli-help') // Let Jest handle help
.description('Run tests, forwarding args to Jest, defaulting to watch mode')
.action(actionHandler(() => require('commands/testCommand')));
.action(actionHandler(() => require('./commands/testCommand')));
program
.command('watch-deps')
.option('--build', 'Build all dependencies on startup')
.description('Watch all dependencies while running another command')
.action(actionHandler(() => require('commands/watch-deps')));
.action(actionHandler(() => require('./commands/watch-deps')));
program
.command('build-cache')
@@ -103,12 +103,12 @@ const main = (argv: string[]) => {
'Cache dir',
'<repoRoot>/node_modules/.cache/backstage-builds',
)
.action(actionHandler(() => require('commands/build-cache')));
.action(actionHandler(() => require('./commands/build-cache')));
program
.command('clean')
.description('Delete cache directories')
.action(actionHandler(() => require('commands/clean/clean')));
.action(actionHandler(() => require('./commands/clean/clean')));
program.on('command:*', () => {
console.log();
@@ -142,7 +142,7 @@ function actionHandler<T extends readonly any[]>(
};
}
process.on('unhandledRejection', rejection => {
process.on('unhandledRejection', (rejection) => {
if (rejection instanceof Error) {
exitWithError(rejection);
} else {
+6 -8
View File
@@ -16,11 +16,11 @@
import fs from 'fs-extra';
import { resolve as resolvePath, relative as relativePath } from 'path';
import { runPlain, runCheck } from 'lib/run';
import { runPlain, runCheck } from '../run';
import { Options } from './options';
import { extractArchive, createArchive } from './archive';
import { paths } from 'lib/paths';
import { version, isDev } from 'lib/version';
import { paths } from '../paths';
import { version, isDev } from '../version';
const INFO_FILE = '.backstage-build-cache';
@@ -127,9 +127,7 @@ export class Cache {
await writeCacheInfo(outputDir, { key });
const timestamp = new Date().toISOString().replace(/-|:|\..*/g, '');
const rand = Math.random()
.toString(36)
.slice(2, 6);
const rand = Math.random().toString(36).slice(2, 6);
const archiveName = `cache-${timestamp}-${rand}.tgz`;
const archivePath = resolvePath(location, archiveName);
@@ -137,7 +135,7 @@ export class Cache {
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));
const entryIndex = entries.findIndex((e) => compareKeys(e.key, key));
if (entryIndex !== -1) {
const [existingEntry] = entries.splice(entryIndex, 1);
entries.unshift(existingEntry);
@@ -167,7 +165,7 @@ export class Cache {
return { hit: true, archive };
}
const matchingEntry = this.entries.find(e => compareKeys(e.key, key));
const matchingEntry = this.entries.find((e) => compareKeys(e.key, key));
if (!matchingEntry) {
return { hit: false, archive };
}
+1 -1
View File
@@ -16,7 +16,7 @@
import { resolve as resolvePath } from 'path';
import { Command } from 'commander';
import { paths } from 'lib/paths';
import { paths } from '../paths';
const DEFAULT_CACHE_DIR = '<repoRoot>/node_modules/.cache/backstage-builds';
const DEFAULT_MAX_ENTRIES = 10;
+3 -3
View File
@@ -15,14 +15,14 @@
*/
import { spawn } from 'child_process';
import { LogPipe } from 'lib/logging';
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,
(script) => script in pkg.scripts,
);
const args = scriptName ? [scriptName] : ['build', '--watch'];
@@ -40,7 +40,7 @@ export function startCompiler(pkg: Package, logPipe: LogPipe) {
watch.stderr.on('data', logErr);
const promise = new Promise<void>((resolve, reject) => {
watch.on('error', error => {
watch.on('error', (error) => {
reject(error);
});
+1 -1
View File
@@ -14,7 +14,7 @@
* limitations under the License.
*/
import { createLogPipe } from 'lib/logging';
import { createLogPipe } from '../logging';
export type ColorFunc = (msg: string) => string;
+1 -1
View File
@@ -14,7 +14,7 @@
* limitations under the License.
*/
import { paths } from 'lib/paths';
import { paths } from '../paths';
const LernaProject = require('@lerna/project');
const PackageGraph = require('@lerna/package-graph');
+4 -4
View File
@@ -20,8 +20,8 @@ import { createLogPipeFactory } from './logger';
import { findAllDeps } from './packages';
import { startWatcher, startPackageWatcher } from './watcher';
import { startCompiler } from './compiler';
import { run } from 'lib/run';
import { paths } from 'lib/paths';
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.
@@ -66,8 +66,8 @@ export async function watchDeps(options: Options = {}) {
}
// 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 => {
const watcher = await startWatcher(deps, WATCH_LOCATIONS, (pkg) => {
startCompiler(pkg, createLogPipe(pkg.name)).promise.catch((error) => {
process.stderr.write(`${error}\n`);
});
});
+2 -2
View File
@@ -18,7 +18,7 @@ import { resolve as resolvePath } from 'path';
import chalk from 'chalk';
import chokidar from 'chokidar';
import { Package } from './packages';
import { createLogFunc } from 'lib/logging';
import { createLogFunc } from '../logging';
export type Watcher = {
update(newPackages: Package[]): Promise<void>;
@@ -42,7 +42,7 @@ export async function startWatcher(
let signalled = false;
watchedPackageLocations.add(pkg.location);
const watchLocations = paths.map(path => resolvePath(pkg.location, path));
const watchLocations = paths.map((path) => resolvePath(pkg.location, path));
const watcher = chokidar
.watch(watchLocations, {
cwd: pkg.location,
@@ -1,7 +1,5 @@
{
"extends": "../../tsconfig.json",
"include": ["src"],
"compilerOptions": {
"baseUrl": "src"
}
"compilerOptions": {}
}
@@ -1,7 +1,5 @@
{
"extends": "../../tsconfig.json",
"include": ["src"],
"compilerOptions": {
"baseUrl": "src"
}
"compilerOptions": {}
}
+2 -2
View File
@@ -2,7 +2,7 @@
"extends": "./tsconfig.json",
"exclude": ["**/*.test.*"],
"compilerOptions": {
"outFile": "dist/index.js",
"module": "amd"
"outDir": "dist",
"module": "CommonJS"
}
}
+1 -3
View File
@@ -1,7 +1,5 @@
{
"extends": "../../tsconfig.json",
"include": ["src"],
"compilerOptions": {
"baseUrl": "src"
}
"compilerOptions": {}
}
@@ -19,7 +19,7 @@ import {
UserFlags,
FeatureFlagsRegistry,
FeatureFlagsRegistryItem,
} from 'api/app/FeatureFlags';
} from '../../app/FeatureFlags';
/**
* The feature flags API is used to toggle functionality to users across plugins and Backstage.
+4 -4
View File
@@ -18,9 +18,9 @@ import React, { ComponentType } from 'react';
import { Route, Switch, Redirect } from 'react-router-dom';
import { AppContextProvider } from './AppContext';
import { App } from './types';
import BackstagePlugin from 'api/plugin/Plugin';
import BackstagePlugin from '../plugin/Plugin';
import { FeatureFlagsRegistryItem } from './FeatureFlags';
import { featureFlagsApiRef } from 'api/apis/definitions/featureFlags';
import { featureFlagsApiRef } from '../apis/definitions/featureFlags';
import ErrorPage from '../../layout/ErrorPage';
import {
@@ -28,8 +28,8 @@ import {
SystemIcons,
SystemIconKey,
defaultSystemIcons,
} from 'icons';
import { ApiHolder, ApiProvider } from 'api/apis';
} from '../../icons';
import { ApiHolder, ApiProvider } from '../apis';
import LoginPage from './LoginPage';
class AppImpl implements App {
@@ -18,7 +18,7 @@ import { FeatureFlags as FeatureFlagsImpl } from './FeatureFlags';
import {
FeatureFlagState,
FeatureFlagsApi,
} from 'api/apis/definitions/featureFlags';
} from '../apis/definitions/featureFlags';
describe('FeatureFlags', () => {
beforeEach(() => {
@@ -150,7 +150,7 @@ describe('FeatureFlags', () => {
it('should get the correct values', () => {
const getByName = (name: string) =>
featureFlags.getRegisteredFlags().find(flag => flag.name === name);
featureFlags.getRegisteredFlags().find((flag) => flag.name === name);
expect(getByName('registered-flag-0')).toBeUndefined();
expect(getByName('registered-flag-1')).toEqual({
+5 -5
View File
@@ -14,11 +14,11 @@
* limitations under the License.
*/
import { FeatureFlagName } from 'api/plugin/types';
import { FeatureFlagName } from '../plugin/types';
import {
FeatureFlagState,
FeatureFlagsApi,
} from 'api/apis/definitions/featureFlags';
} from '../apis/definitions/featureFlags';
/**
* Helper method for validating compatibility and flag name.
@@ -130,12 +130,12 @@ export interface FeatureFlagsRegistryItem {
export class FeatureFlagsRegistry extends Array<FeatureFlagsRegistryItem> {
static from(entries: FeatureFlagsRegistryItem[]) {
Array.from(entries).forEach(entry => validateFlagName(entry.name));
Array.from(entries).forEach((entry) => validateFlagName(entry.name));
return new FeatureFlagsRegistry(...entries);
}
push(...entries: FeatureFlagsRegistryItem[]): number {
Array.from(entries).forEach(entry => validateFlagName(entry.name));
Array.from(entries).forEach((entry) => validateFlagName(entry.name));
return super.push(...entries);
}
@@ -146,7 +146,7 @@ export class FeatureFlagsRegistry extends Array<FeatureFlagsRegistryItem> {
)[]
): FeatureFlagsRegistryItem[] {
const _concat = super.concat(...entries);
Array.from(_concat).forEach(entry => validateFlagName(entry.name));
Array.from(_concat).forEach((entry) => validateFlagName(entry.name));
return _concat;
}
@@ -16,10 +16,10 @@
import React, { FC, useState } from 'react';
import { GitHub as GitHubIcon } from '@material-ui/icons';
import Page from 'layout/Page';
import Header from 'layout/Header';
import Content from 'layout/Content/Content';
import ContentHeader from 'layout/ContentHeader/ContentHeader';
import Page from '../../../layout/Page';
import Header from '../../../layout/Header';
import Content from '../../../layout/Content/Content';
import ContentHeader from '../../../layout/ContentHeader/ContentHeader';
import {
Grid,
Typography,
@@ -29,7 +29,7 @@ import {
ListItem,
Link,
} from '@material-ui/core';
import InfoCard from 'layout/InfoCard/InfoCard';
import InfoCard from '../../../layout/InfoCard/InfoCard';
enum AuthType {
GitHub,
@@ -72,11 +72,11 @@ const LoginPage: FC<{}> = () => {
'Content-Type': 'application/x-www-form-urlencoded',
}),
})
.then(response => {
.then((response) => {
if (response.status === 200) return response.json();
throw Error(`${response.status} ${response.statusText}`);
})
.then(data => {
.then((data) => {
const info = {
username: username,
token: token,
+1 -1
View File
@@ -21,7 +21,7 @@ import {
RouteOptions,
FeatureFlagName,
} from './types';
import { validateBrowserCompat, validateFlagName } from 'api/app/FeatureFlags';
import { validateBrowserCompat, validateFlagName } from '../app/FeatureFlags';
export type PluginConfig = {
id: string;
@@ -16,7 +16,7 @@
import React from 'react';
import CopyTextButton from '.';
import { ApiProvider, errorApiRef, ApiRegistry, ErrorApi } from 'api';
import { ApiProvider, errorApiRef, ApiRegistry, ErrorApi } from '../../api';
export default {
title: 'CopyTextButton',
@@ -18,7 +18,7 @@ import React from 'react';
import { render } from '@testing-library/react';
import { wrapInThemedTestApp } from '@backstage/test-utils';
import CopyTextButton from './CopyTextButton';
import { ApiRegistry, errorApiRef, ApiProvider, ErrorApi } from 'api';
import { ApiRegistry, errorApiRef, ApiProvider, ErrorApi } from '../../api';
jest.mock('popper.js', () => {
const PopperJS = jest.requireActual('popper.js');
@@ -19,9 +19,9 @@ import { IconButton, makeStyles, Tooltip } from '@material-ui/core';
import PropTypes from 'prop-types';
import CopyIcon from '@material-ui/icons/FileCopy';
import { BackstageTheme } from '@backstage/theme';
import { errorApiRef, useApi } from 'api';
import { errorApiRef, useApi } from '../../api';
const useStyles = makeStyles<BackstageTheme>(theme => ({
const useStyles = makeStyles<BackstageTheme>((theme) => ({
button: {
'&:hover': {
backgroundColor: theme.palette.highlight,
@@ -56,7 +56,7 @@ const defaultProps = {
tooltipText: 'Text copied to clipboard',
};
const CopyTextButton: FC<Props> = props => {
const CopyTextButton: FC<Props> = (props) => {
const { text, tooltipDelay, tooltipText } = {
...defaultProps,
...props,
@@ -66,7 +66,7 @@ const CopyTextButton: FC<Props> = props => {
const inputRef = useRef<HTMLInputElement>(null);
const [open, setOpen] = useState(false);
const handleCopyClick: MouseEventHandler = e => {
const handleCopyClick: MouseEventHandler = (e) => {
e.stopPropagation();
setOpen(true);
@@ -16,7 +16,7 @@
import React, { FC } from 'react';
import { makeStyles } from '@material-ui/core';
import InfoCard from 'layout/InfoCard';
import InfoCard from '../../layout/InfoCard';
import { Props as BottomLinkProps } from '../../layout/BottomLink';
import CircleProgress from './CircleProgress';
@@ -36,7 +36,7 @@ const useStyles = makeStyles({
},
});
const ProgressCard: FC<Props> = props => {
const ProgressCard: FC<Props> = (props) => {
const classes = useStyles(props);
const { title, subheader, progress, deepLink, variant } = props;
@@ -24,8 +24,8 @@ import {
StatusRunning,
StatusWarning,
} from './Status';
import Table from 'components/Table';
import InfoCard from 'layout/InfoCard';
import Table from '../Table';
import InfoCard from '../../layout/InfoCard';
export default {
title: 'Status',
@@ -16,8 +16,8 @@
import React from 'react';
import TrendLine from '.';
import Table from 'components/Table';
import InfoCard from 'layout/InfoCard';
import Table from '../Table';
import InfoCard from '../../layout/InfoCard';
export default {
title: 'TrendLine',
+2 -2
View File
@@ -18,7 +18,7 @@ import { SvgIconProps } from '@material-ui/core';
import PeopleIcon from '@material-ui/icons/People';
import PersonIcon from '@material-ui/icons/Person';
import React, { FC } from 'react';
import { useApp } from 'api/app/AppContext';
import { useApp } from '../api/app/AppContext';
import { IconComponent, SystemIconKey, SystemIcons } from './types';
export const defaultSystemIcons: SystemIcons = {
@@ -27,7 +27,7 @@ export const defaultSystemIcons: SystemIcons = {
};
const overridableSystemIcon = (key: SystemIconKey): IconComponent => {
const Component: FC<SvgIconProps> = props => {
const Component: FC<SvgIconProps> = (props) => {
const app = useApp();
const Icon = app.getSystemIcon(key);
return <Icon {...props} />;
+3 -3
View File
@@ -19,11 +19,11 @@ import Helmet from 'react-helmet';
import { Typography, Tooltip, makeStyles } from '@material-ui/core';
import { BackstageTheme } from '@backstage/theme';
import { Theme } from 'layout/Page/Page';
import { Theme } from '../Page/Page';
// import { Link } from 'shared/components';
import Waves from './Waves';
const useStyles = makeStyles<BackstageTheme>(theme => ({
const useStyles = makeStyles<BackstageTheme>((theme) => ({
header: {
gridArea: 'pageHeader',
padding: theme.spacing(3),
@@ -175,7 +175,7 @@ export const Header: FC<Props> = ({
<Fragment>
<Helmet titleTemplate={titleTemplate} defaultTitle={defaultTitle} />
<Theme.Consumer>
{theme => (
{(theme) => (
<header style={style} className={classes.header}>
<Waves theme={theme} />
<div className={classes.leftItemsBox}>
@@ -16,7 +16,7 @@
import React from 'react';
import { render } from '@testing-library/react';
import { pageTheme } from 'layout/Page/PageThemeProvider';
import { pageTheme } from '../Page/PageThemeProvider';
import Waves from './Waves';
describe('<Waves/>', () => {
+1 -1
View File
@@ -16,7 +16,7 @@
import React, { FC } from 'react';
import { makeStyles } from '@material-ui/core';
import { PageTheme } from 'layout/Page';
import { PageTheme } from '../Page';
const useStyles = makeStyles<PageTheme>({
wave: {
@@ -24,7 +24,7 @@ import {
withStyles,
makeStyles,
} from '@material-ui/core';
import ErrorBoundary from 'layout/ErrorBoundary/ErrorBoundary';
import ErrorBoundary from '../ErrorBoundary';
import BottomLink, { Props as BottomLinkProps } from '../BottomLink';
const useStyles = makeStyles((theme) => ({
+1 -3
View File
@@ -1,7 +1,5 @@
{
"extends": "../../tsconfig.json",
"include": ["src"],
"compilerOptions": {
"baseUrl": "src"
}
"compilerOptions": {}
}
+1 -3
View File
@@ -1,7 +1,5 @@
{
"extends": "../../tsconfig.json",
"include": ["src"],
"compilerOptions": {
"baseUrl": "src"
}
"compilerOptions": {}
}
+1 -2
View File
@@ -22,7 +22,6 @@ module.exports = {
// Point to dist version of theme and any other packages that might be needed in the future
'@backstage/theme': path.resolve(__dirname, '../../theme'),
};
config.resolve.modules.push(coreSrc);
// Remove the default babel-loader for js files, we're using ts-loader instead
const [jsLoader] = config.module.rules.splice(0, 1);
@@ -56,7 +55,7 @@ module.exports = {
// Fail storybook build on CI if there are webpack warnings.
if (process.env.CI) {
config.plugins.push(new WebpackPluginFailBuildOnWarning())
config.plugins.push(new WebpackPluginFailBuildOnWarning());
}
return config;
+1 -3
View File
@@ -1,7 +1,5 @@
{
"extends": "../../tsconfig.json",
"include": ["src"],
"compilerOptions": {
"baseUrl": "src"
}
"compilerOptions": {}
}
+1 -3
View File
@@ -1,7 +1,5 @@
{
"extends": "../../tsconfig.json",
"include": ["src"],
"compilerOptions": {
"baseUrl": "src"
}
"compilerOptions": {}
}
+1 -1
View File
@@ -14,7 +14,7 @@
* limitations under the License.
*/
import { createTheme } from 'baseTheme';
import { createTheme } from './baseTheme';
import { blue, yellow } from '@material-ui/core/colors';
export const lightTheme = createTheme({
+1 -3
View File
@@ -1,7 +1,5 @@
{
"extends": "../../tsconfig.json",
"include": ["src"],
"compilerOptions": {
"baseUrl": "src"
}
"compilerOptions": {}
}
+1 -3
View File
@@ -1,7 +1,5 @@
{
"extends": "../../tsconfig.json",
"include": ["src"],
"compilerOptions": {
"baseUrl": "src"
}
"compilerOptions": {}
}
@@ -17,8 +17,8 @@
import React, { FC, useState, Suspense } from 'react';
import { Tabs, Tab, makeStyles, Typography, Divider } from '@material-ui/core';
import 'graphiql/graphiql.css';
import { StorageBucket } from 'lib/storage';
import { GraphQLEndpoint } from 'lib/api';
import { StorageBucket } from '../../lib/storage';
import { GraphQLEndpoint } from '../../lib/api';
import { Progress } from '@backstage/core';
import { BackstageTheme } from '@backstage/theme';
@@ -20,7 +20,7 @@ import { ThemeProvider } from '@material-ui/core';
import { lightTheme } from '@backstage/theme';
import { ApiProvider, ApiRegistry } from '@backstage/core';
import { renderWithEffects } from '@backstage/test-utils';
import { GraphQLBrowseApi, graphQlBrowseApiRef } from 'lib/api';
import { GraphQLBrowseApi, graphQlBrowseApiRef } from '../../lib/api';
jest.mock('components/GraphiQLBrowser', () => ({
GraphiQLBrowser: () => '<GraphiQLBrowser />',
@@ -26,8 +26,8 @@ import {
} from '@backstage/core';
import { useAsync } from 'react-use';
import 'graphiql/graphiql.css';
import { graphQlBrowseApiRef } from 'lib/api';
import { GraphiQLBrowser } from 'components';
import { graphQlBrowseApiRef } from '../../lib/api';
import { GraphiQLBrowser } from '../GraphiQLBrowser';
import { Typography } from '@material-ui/core';
export const GraphiQLPage: FC<{}> = () => {
+1 -3
View File
@@ -1,7 +1,5 @@
{
"extends": "../../tsconfig.json",
"include": ["src", "dev"],
"compilerOptions": {
"baseUrl": "src"
}
"compilerOptions": {}
}
@@ -16,7 +16,7 @@
import React, { FC } from 'react';
import { Typography, Link, Grid } from '@material-ui/core';
import HomePageTimer from 'components/HomepageTimer';
import HomePageTimer from '../HomepageTimer';
import { Content, InfoCard, Header, Page, pageTheme } from '@backstage/core';
import SquadTechHealth from './SquadTechHealth';
import Table from '@material-ui/core/Table';
@@ -68,7 +68,7 @@ const HomePage: FC<{}> = () => {
</TableRow>
</TableHead>
<TableBody>
{data.map(d => (
{data.map((d) => (
<TableRow key={d.id}>
<TableCell>{d.entity}</TableCell>
<TableCell>{d.kind}</TableCell>
+1 -1
View File
@@ -15,7 +15,7 @@
*/
import { createPlugin } from '@backstage/core';
import HomePage from 'components/HomePage';
import HomePage from './components/HomePage';
export const plugin = createPlugin({
id: 'home-page',
+1 -3
View File
@@ -1,7 +1,5 @@
{
"extends": "../../tsconfig.json",
"include": ["src", "dev"],
"compilerOptions": {
"baseUrl": "src"
}
"compilerOptions": {}
}
-1
View File
@@ -1,7 +1,6 @@
{
"include": ["src"],
"compilerOptions": {
"baseUrl": "src",
"outDir": "dist",
"incremental": true,
"sourceMap": true,
+1 -3
View File
@@ -1,7 +1,5 @@
{
"extends": "../../tsconfig.json",
"include": ["src"],
"compilerOptions": {
"baseUrl": "src"
}
"compilerOptions": {}
}
+1 -3
View File
@@ -1,7 +1,5 @@
{
"extends": "../../tsconfig.json",
"include": ["src"],
"compilerOptions": {
"baseUrl": "src"
}
"compilerOptions": {}
}
+1 -3
View File
@@ -1,7 +1,5 @@
{
"extends": "../../tsconfig.json",
"include": ["src"],
"compilerOptions": {
"baseUrl": "src"
}
"compilerOptions": {}
}
@@ -24,7 +24,7 @@ import {
ListItemText,
Link,
} from '@material-ui/core';
import Timer from 'components/Timer';
import Timer from '../Timer';
import {
Content,
InfoCard,
+1 -1
View File
@@ -15,7 +15,7 @@
*/
import { createPlugin } from '@backstage/core';
import WelcomePage from 'components/WelcomePage';
import WelcomePage from './components/WelcomePage';
export const plugin = createPlugin({
id: 'welcome',
+1 -3
View File
@@ -1,7 +1,5 @@
{
"extends": "../../tsconfig.json",
"include": ["src"],
"compilerOptions": {
"baseUrl": "src"
}
"compilerOptions": {}
}