cli: fix module discovery race
Signed-off-by: Patrik Oldsberg <poldsberg@gmail.com>
This commit is contained in:
@@ -0,0 +1,5 @@
|
||||
---
|
||||
'@backstage/cli': patch
|
||||
---
|
||||
|
||||
Fixed an issue that would cause an invalid `__backstage-autodetected-plugins__.js` to be written when using experimental module discovery.
|
||||
@@ -112,6 +112,7 @@
|
||||
"node-libs-browser": "^2.2.1",
|
||||
"npm-packlist": "^5.0.0",
|
||||
"ora": "^5.3.0",
|
||||
"p-queue": "^6.6.2",
|
||||
"postcss": "^8.1.0",
|
||||
"process": "^0.11.10",
|
||||
"react-dev-utils": "^12.0.0-next.60",
|
||||
|
||||
@@ -18,6 +18,7 @@ import { BackstagePackageJson } from '@backstage/cli-node';
|
||||
import { Config, ConfigReader } from '@backstage/config';
|
||||
import chokidar from 'chokidar';
|
||||
import fs from 'fs-extra';
|
||||
import PQueue from 'p-queue';
|
||||
import { join as joinPath, resolve as resolvePath } from 'path';
|
||||
import { paths as cliPaths } from '../paths';
|
||||
|
||||
@@ -104,6 +105,9 @@ async function detectPackages(
|
||||
});
|
||||
}
|
||||
|
||||
// Make sure we're not issuing multiple writes at the same time, which can cause partial overwrites
|
||||
const writeQueue = new PQueue({ concurrency: 1 });
|
||||
|
||||
async function writeDetectedPackagesModule(
|
||||
pkgs: { name: string; export?: string; import: string }[],
|
||||
) {
|
||||
@@ -116,13 +120,15 @@ async function writeDetectedPackagesModule(
|
||||
)
|
||||
.join(',');
|
||||
|
||||
await fs.writeFile(
|
||||
joinPath(
|
||||
cliPaths.targetRoot,
|
||||
'node_modules',
|
||||
`${DETECTED_MODULES_MODULE_NAME}.js`,
|
||||
await writeQueue.add(() =>
|
||||
fs.writeFile(
|
||||
joinPath(
|
||||
cliPaths.targetRoot,
|
||||
'node_modules',
|
||||
`${DETECTED_MODULES_MODULE_NAME}.js`,
|
||||
),
|
||||
`window['__@backstage/discovered__'] = { modules: [${requirePackageScript}] };`,
|
||||
),
|
||||
`window['__@backstage/discovered__'] = { modules: [${requirePackageScript}] };`,
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user