Link local packages in package.json if in e2e-test
This commit is contained in:
@@ -86,6 +86,34 @@ export async function moveApp(
|
||||
});
|
||||
}
|
||||
|
||||
async function addPackageResolutions(rootDir: string, appDir: string) {
|
||||
process.chdir(appDir);
|
||||
|
||||
const packageFileContent = await fs.readFile('package.json', 'utf-8');
|
||||
const packageFileJson = JSON.parse(packageFileContent);
|
||||
|
||||
if (packageFileJson.resolutions) {
|
||||
throw new Error('package.json already contains resolutions');
|
||||
}
|
||||
packageFileJson.resolutions = {};
|
||||
|
||||
const packages = ['cli', 'core', 'test-utils', 'test-utils-core', 'theme'];
|
||||
|
||||
for (const pkg of packages) {
|
||||
await Task.forItem('adding', `${pkg} link to package.json`, async () => {
|
||||
const pkgPath = require('path').join(rootDir, 'packages', pkg);
|
||||
packageFileJson.resolutions[`@backstage/${pkg}`] = `file:${pkgPath}`;
|
||||
const newContents = `${JSON.stringify(packageFileJson, null, 2)}\n`;
|
||||
|
||||
await fs.writeFile('package.json', newContents, 'utf-8').catch(error => {
|
||||
throw new Error(
|
||||
`Failed to add resolutions to package.json: ${error.message}`,
|
||||
);
|
||||
});
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
export default async () => {
|
||||
const questions: Question[] = [
|
||||
{
|
||||
@@ -126,6 +154,15 @@ export default async () => {
|
||||
Task.section('Moving to final location');
|
||||
await moveApp(tempDir, appDir, answers.name);
|
||||
|
||||
// e2e testing needs special treatment
|
||||
if (process.env.E2E) {
|
||||
Task.section('Linking packages locally for e2e tests');
|
||||
const rootDir = process.env.CI
|
||||
? resolvePath(process.env.GITHUB_WORKSPACE!)
|
||||
: resolvePath(__dirname, '..', '..', '..');
|
||||
await addPackageResolutions(rootDir, appDir);
|
||||
}
|
||||
|
||||
Task.section('Building the app');
|
||||
await buildApp(appDir);
|
||||
|
||||
|
||||
@@ -53,7 +53,7 @@ export function findRootPath(topPath: string): string {
|
||||
try {
|
||||
const contents = fs.readFileSync(packagePath, 'utf8');
|
||||
const data = JSON.parse(contents);
|
||||
if (data.name === 'root') {
|
||||
if (data.name === 'root' || data.name.includes('backstage-e2e')) {
|
||||
return path;
|
||||
}
|
||||
} catch (error) {
|
||||
|
||||
@@ -25,8 +25,5 @@
|
||||
"@backstage/cli": "^{{version}}",
|
||||
"lerna": "^3.20.2",
|
||||
"prettier": "^1.19.1"
|
||||
},
|
||||
"resolutions": {
|
||||
"@backstage/cli": "file:/home/runner/work/backstage/backstage/packages/cli"
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user