fix(packages): load bundled Pi runtime for local installs
This commit is contained in:
@@ -471,6 +471,28 @@ export async function verifyPackagedMarketplaceClientArtifact(appAsar) {
|
||||
return verifyMarketplaceClientArtifact(reachableContents, verifiedTrustSource);
|
||||
}
|
||||
|
||||
export async function verifyPackagedDevicePackageRuntime(appAsar, runtimePlatform) {
|
||||
const { reachable } = await readPackagedApplicationGraph(appAsar);
|
||||
const staleImports = reachable
|
||||
.filter(({ source }) => /\bimport\(\s*["']@earendil-works\/pi-coding-agent["']\s*\)/u.test(source))
|
||||
.map(({ entry }) => entry);
|
||||
if (staleImports.length > 0) {
|
||||
throw new Error(
|
||||
`Packaged Device Package manager still imports the incomplete app graph: ${staleImports.join(', ')}`,
|
||||
);
|
||||
}
|
||||
if (runtimePlatform.devicePackageManager?.defaultPackageManager !== 'function'
|
||||
|| runtimePlatform.devicePackageManager?.settingsManager !== 'function') {
|
||||
throw new Error('Packaged Pi runtime cannot load the Device Package manager');
|
||||
}
|
||||
return {
|
||||
authority: 'bundled-pi-runtime',
|
||||
appAsarRootImport: false,
|
||||
exports: runtimePlatform.devicePackageManager,
|
||||
result: 'pass',
|
||||
};
|
||||
}
|
||||
|
||||
async function filesContainingNeedles(root, needles) {
|
||||
const matches = [];
|
||||
const visit = async (path) => {
|
||||
@@ -496,12 +518,21 @@ async function inspectProductRuntime(executable, resourcesDirectory) {
|
||||
const resources = process.env.MAKELORE_PI_PRODUCT_RESOURCES;
|
||||
const appRequire = createRequire(path.join(resources, 'app.asar', 'package.json'));
|
||||
const packagedPackage = appRequire('./package.json');
|
||||
const piRuntime = require(path.join(resources, 'pi-runtime', 'dist', 'index.js'));
|
||||
if (typeof piRuntime.DefaultPackageManager !== 'function'
|
||||
|| typeof piRuntime.SettingsManager?.inMemory !== 'function') {
|
||||
throw new Error('Bundled Pi package manager exports are unavailable');
|
||||
}
|
||||
process.stdout.write(JSON.stringify({
|
||||
platform: process.platform,
|
||||
arch: process.arch,
|
||||
node: process.versions.node,
|
||||
electron: process.versions.electron,
|
||||
packagedPackage,
|
||||
devicePackageManager: {
|
||||
defaultPackageManager: typeof piRuntime.DefaultPackageManager,
|
||||
settingsManager: typeof piRuntime.SettingsManager.inMemory,
|
||||
},
|
||||
}));
|
||||
`;
|
||||
const { stdout } = await runCommand(executable, ['-e', script], {
|
||||
@@ -744,6 +775,7 @@ export async function verifyPiProductArtifact({ projectRoot, executable }) {
|
||||
appAsarContents,
|
||||
});
|
||||
const marketplace = await verifyPackagedMarketplaceClientArtifact(appAsar);
|
||||
const devicePackages = await verifyPackagedDevicePackageRuntime(appAsar, runtimePlatform);
|
||||
const actualSkills = bundledPluginResources.coreResources.skills;
|
||||
const missingExtensionMarkers = EXTENSION_CONTRACT_MARKERS.filter(
|
||||
(marker) => !appAsarContents.includes(Buffer.from(marker)),
|
||||
@@ -797,6 +829,7 @@ export async function verifyPiProductArtifact({ projectRoot, executable }) {
|
||||
packagedClosure,
|
||||
bundledPlugins: bundledPluginResources,
|
||||
marketplace,
|
||||
devicePackages,
|
||||
extension: {
|
||||
contractMarkers: EXTENSION_CONTRACT_MARKERS,
|
||||
packaged: true,
|
||||
|
||||
Reference in New Issue
Block a user