cli: switch to keeping track of outputs for each package role

Signed-off-by: Patrik Oldsberg <poldsberg@gmail.com>
This commit is contained in:
Patrik Oldsberg
2022-01-25 21:35:39 +01:00
parent f2c5b74617
commit 323562efc9
6 changed files with 66 additions and 23 deletions
+3 -6
View File
@@ -20,9 +20,6 @@ import { PackageRole, findRoleFromCommand, getRoleInfo } from '../../lib/role';
const bundledRoles: PackageRole[] = ['app', 'backend'];
const esmPlatforms = ['web', 'common'];
const cjsPlatforms = ['node', 'common'];
export async function command(cmd: Command): Promise<void> {
const role = await findRoleFromCommand(cmd);
const roleInfo = getRoleInfo(role);
@@ -35,13 +32,13 @@ export async function command(cmd: Command): Promise<void> {
const outputs = new Set<Output>();
if (cjsPlatforms.includes(roleInfo.platform)) {
if (roleInfo.output.includes('cjs')) {
outputs.add(Output.cjs);
}
if (esmPlatforms.includes(roleInfo.platform)) {
if (roleInfo.output.includes('esm')) {
outputs.add(Output.esm);
}
if (role !== 'cli') {
if (roleInfo.output.includes('types')) {
outputs.add(Output.types);
}
@@ -17,9 +17,8 @@
import fs from 'fs-extra';
import { resolve as resolvePath } from 'path';
import { PackageGraph } from '../../lib/monorepo';
import { getRoleFromPackage, PackageRole } from '../../lib/role';
import { getRoleFromPackage, getRoleInfo, PackageRole } from '../../lib/role';
const bundledRoles: PackageRole[] = ['app', 'backend'];
const noStartRoles: PackageRole[] = ['cli', 'common-library'];
export async function command() {
@@ -32,8 +31,9 @@ export async function command() {
return;
}
const roleInfo = getRoleInfo(role);
const hasStart = !noStartRoles.includes(role);
const isBundled = bundledRoles.includes(role);
const isBundled = roleInfo.output.includes('bundle');
const expectedScripts = {
...(hasStart && { start: 'backstage-cli script start' }),
+6 -1
View File
@@ -14,7 +14,12 @@
* limitations under the License.
*/
export type { PackageRoleInfo, PackagePlatform, PackageRole } from './types';
export type {
PackageRoleInfo,
PackagePlatform,
PackageOutputType,
PackageRole,
} from './types';
export {
getRoleInfo,
getRoleFromPackage,
@@ -28,13 +28,13 @@ describe('getRoleInfo', () => {
expect(getRoleInfo('web-library')).toEqual({
role: 'web-library',
platform: 'web',
bundled: false,
output: ['types', 'esm'],
});
expect(getRoleInfo('app')).toEqual({
role: 'app',
platform: 'web',
bundled: true,
output: ['bundle'],
});
expect(() => getRoleInfo('invalid')).toThrow(
+50 -10
View File
@@ -21,16 +21,56 @@ import { paths } from '../paths';
import { PackageRole, PackageRoleInfo } from './types';
const packageRoleInfos: PackageRoleInfo[] = [
{ role: 'app', bundled: true, platform: 'web' },
{ role: 'backend', bundled: true, platform: 'node' },
{ role: 'cli', bundled: false, platform: 'node' },
{ role: 'web-library', bundled: false, platform: 'web' },
{ role: 'node-library', bundled: false, platform: 'node' },
{ role: 'common-library', bundled: false, platform: 'common' },
{ role: 'plugin-frontend', bundled: false, platform: 'web' },
{ role: 'plugin-frontend-module', bundled: false, platform: 'web' },
{ role: 'plugin-backend', bundled: false, platform: 'node' },
{ role: 'plugin-backend-module', bundled: false, platform: 'node' },
{
role: 'app',
platform: 'web',
output: ['bundle'],
},
{
role: 'backend',
platform: 'node',
output: ['bundle'],
},
{
role: 'cli',
platform: 'node',
output: ['cjs'],
},
{
role: 'web-library',
platform: 'web',
output: ['types', 'esm'],
},
{
role: 'node-library',
platform: 'node',
output: ['types', 'cjs'],
},
{
role: 'common-library',
platform: 'common',
output: ['types', 'esm', 'cjs'],
},
{
role: 'plugin-frontend',
platform: 'web',
output: ['types', 'esm'],
},
{
role: 'plugin-frontend-module',
platform: 'web',
output: ['types', 'esm'],
},
{
role: 'plugin-backend',
platform: 'node',
output: ['types', 'cjs'],
},
{
role: 'plugin-backend-module',
platform: 'node',
output: ['types', 'cjs'],
},
];
export function getRoleInfo(role: string): PackageRoleInfo {
+2 -1
View File
@@ -27,9 +27,10 @@ export type PackageRole =
| 'plugin-backend-module';
export type PackagePlatform = 'node' | 'web' | 'common';
export type PackageOutputType = 'bundle' | 'types' | 'esm' | 'cjs';
export interface PackageRoleInfo {
role: PackageRole;
bundled: boolean;
platform: PackagePlatform;
output: PackageOutputType[];
}