cli: disable feature detection for backend builds
Signed-off-by: Patrik Oldsberg <poldsberg@gmail.com>
This commit is contained in:
@@ -0,0 +1,5 @@
|
||||
---
|
||||
'@backstage/cli': patch
|
||||
---
|
||||
|
||||
Tweaked the new package feature detection to not be active when building backend packages.
|
||||
@@ -29,5 +29,6 @@ export default async (dir: string, packages: string[], options: Options) => {
|
||||
await createDistWorkspace(packages, {
|
||||
targetDir: dir,
|
||||
alwaysYarnPack: options.alwaysYarnPack,
|
||||
enableFeatureDetection: true,
|
||||
});
|
||||
};
|
||||
|
||||
@@ -21,6 +21,7 @@ import {
|
||||
import { paths } from '../lib/paths';
|
||||
import fs from 'fs-extra';
|
||||
import { publishPreflightCheck } from '../lib/publishing';
|
||||
import { createTypeDistProject } from '../lib/typeDistProject';
|
||||
|
||||
export const pre = async () => {
|
||||
publishPreflightCheck({
|
||||
@@ -28,7 +29,10 @@ export const pre = async () => {
|
||||
packageJson: await fs.readJson(paths.resolveTarget('package.json')),
|
||||
});
|
||||
|
||||
await productionPack({ packageDir: paths.targetDir });
|
||||
await productionPack({
|
||||
packageDir: paths.targetDir,
|
||||
featureDetectionProject: await createTypeDistProject(),
|
||||
});
|
||||
};
|
||||
|
||||
export const post = async () => {
|
||||
|
||||
@@ -105,6 +105,12 @@ type Options = {
|
||||
*/
|
||||
alwaysYarnPack?: boolean;
|
||||
|
||||
/**
|
||||
* If set to true, the TypeScript feature detection will be enabled, which
|
||||
* annotates the package exports field with the `backstage` export type.
|
||||
*/
|
||||
enableFeatureDetection?: boolean;
|
||||
|
||||
/**
|
||||
* If set to true, the generated code will be minified.
|
||||
*/
|
||||
@@ -237,6 +243,7 @@ export async function createDistWorkspace(
|
||||
targetDir,
|
||||
targets,
|
||||
Boolean(options.alwaysYarnPack),
|
||||
Boolean(options.enableFeatureDetection),
|
||||
);
|
||||
|
||||
const files: FileEntry[] = options.files ?? ['yarn.lock', 'package.json'];
|
||||
@@ -280,6 +287,7 @@ async function moveToDistWorkspace(
|
||||
workspaceDir: string,
|
||||
localPackages: PackageGraphNode[],
|
||||
alwaysYarnPack: boolean,
|
||||
enableFeatureDetection: boolean,
|
||||
): Promise<void> {
|
||||
const [fastPackPackages, slowPackPackages] = partition(
|
||||
localPackages,
|
||||
@@ -288,8 +296,10 @@ async function moveToDistWorkspace(
|
||||
FAST_PACK_SCRIPTS.includes(pkg.packageJson.scripts?.prepack),
|
||||
);
|
||||
|
||||
const tsMorphProject =
|
||||
fastPackPackages.length > 0 ? await createTypeDistProject() : undefined;
|
||||
const featureDetectionProject =
|
||||
fastPackPackages.length > 0 && enableFeatureDetection
|
||||
? await createTypeDistProject()
|
||||
: undefined;
|
||||
|
||||
// New an improved flow where we avoid calling `yarn pack`
|
||||
await Promise.all(
|
||||
@@ -301,7 +311,7 @@ async function moveToDistWorkspace(
|
||||
await productionPack({
|
||||
packageDir: target.dir,
|
||||
targetDir: absoluteOutputPath,
|
||||
project: tsMorphProject,
|
||||
featureDetectionProject,
|
||||
});
|
||||
}),
|
||||
);
|
||||
|
||||
@@ -19,10 +19,7 @@ import npmPackList from 'npm-packlist';
|
||||
import { resolve as resolvePath, posix as posixPath } from 'path';
|
||||
import { BackstagePackageJson } from '@backstage/cli-node';
|
||||
import { readEntryPoints } from '../entryPoints';
|
||||
import {
|
||||
createTypeDistProject,
|
||||
getEntryPointDefaultFeatureType,
|
||||
} from '../typeDistProject';
|
||||
import { getEntryPointDefaultFeatureType } from '../typeDistProject';
|
||||
import { Project } from 'ts-morph';
|
||||
|
||||
const PKG_PATH = 'package.json';
|
||||
@@ -35,9 +32,9 @@ interface ProductionPackOptions {
|
||||
packageDir: string;
|
||||
targetDir?: string;
|
||||
/**
|
||||
* A ts-morph project to share across packages
|
||||
* Enables package feature detection using this TS-morph project.
|
||||
*/
|
||||
project?: Project;
|
||||
featureDetectionProject?: Project;
|
||||
}
|
||||
|
||||
export async function productionPack(options: ProductionPackOptions) {
|
||||
@@ -55,7 +52,7 @@ export async function productionPack(options: ProductionPackOptions) {
|
||||
const writeCompatibilityEntryPoints = await prepareExportsEntryPoints(
|
||||
pkg,
|
||||
packageDir,
|
||||
options.project,
|
||||
options.featureDetectionProject,
|
||||
);
|
||||
|
||||
// TODO(Rugvip): Once exports are rolled out more broadly we should deprecate and remove this behavior
|
||||
@@ -144,7 +141,7 @@ const EXPORT_MAP = {
|
||||
async function prepareExportsEntryPoints(
|
||||
pkg: BackstagePackageJson,
|
||||
packageDir: string,
|
||||
commonProject?: Project,
|
||||
featureDetectionProject?: Project,
|
||||
) {
|
||||
const distPath = resolvePath(packageDir, 'dist');
|
||||
if (!(await fs.pathExists(distPath))) {
|
||||
@@ -158,7 +155,6 @@ async function prepareExportsEntryPoints(
|
||||
>();
|
||||
|
||||
const entryPoints = readEntryPoints(pkg);
|
||||
const project = commonProject || (await createTypeDistProject());
|
||||
|
||||
for (const entryPoint of entryPoints) {
|
||||
if (!SCRIPT_EXTS.includes(entryPoint.ext)) {
|
||||
@@ -177,14 +173,14 @@ async function prepareExportsEntryPoints(
|
||||
|
||||
exp.default = exp.require ?? exp.import;
|
||||
|
||||
// Find the default export type for the entry point
|
||||
if (exp.types) {
|
||||
// Find the default export type for the entry point, if feature detection is active
|
||||
if (exp.types && featureDetectionProject) {
|
||||
const defaultFeatureType =
|
||||
pkg.backstage?.role &&
|
||||
getEntryPointDefaultFeatureType(
|
||||
pkg.backstage?.role,
|
||||
packageDir,
|
||||
project,
|
||||
featureDetectionProject,
|
||||
exp.types,
|
||||
);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user