Skip to content

Commit

Permalink
Add support for relative runtime paths (#4967)
Browse files Browse the repository at this point in the history
  • Loading branch information
benbrown authored Nov 24, 2020
1 parent b3748a9 commit 0907221
Showing 1 changed file with 28 additions and 11 deletions.
39 changes: 28 additions & 11 deletions extensions/packageManager/src/node/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,15 @@ export default async (composer: IExtensionRegistration): Promise<void> => {
mergeErrors.push(msg);
};

if (currentProject.settings?.runtime?.customRuntime && currentProject.settings?.runtime?.path) {
const manifestFile = runtime.identifyManifest(currentProject.settings?.runtime?.path);


let runtimePath = currentProject.settings?.runtime?.path;
if (runtimePath && !path.isAbsolute(runtimePath)) {
runtimePath = path.resolve(currentProject.dir, runtimePath)
}

if (currentProject.settings?.runtime?.customRuntime && runtimePath) {
const manifestFile = runtime.identifyManifest(runtimePath);

const dryrun = new SchemaMerger(
[manifestFile],
Expand Down Expand Up @@ -118,16 +125,21 @@ export default async (composer: IExtensionRegistration): Promise<void> => {
mergeErrors.push(msg);
};

if (packageName && currentProject.settings?.runtime?.path) {
let runtimePath = currentProject.settings?.runtime?.path;
if (runtimePath && !path.isAbsolute(runtimePath)) {
runtimePath = path.resolve(currentProject.dir, runtimePath)
}

if (packageName && runtimePath) {
try {
// Call the runtime's component install mechanism.
const installOutput = await runtime.installComponent(
currentProject.settings?.runtime?.path || '',
runtimePath,
packageName,
version
);

const manifestFile = runtime.identifyManifest(currentProject.settings?.runtime?.path);
const manifestFile = runtime.identifyManifest(runtimePath);

// call do a dry run on the dialog merge
const dryrun = new SchemaMerger(
Expand Down Expand Up @@ -199,20 +211,20 @@ export default async (composer: IExtensionRegistration): Promise<void> => {
} catch (err) {
composer.log('Error in import', { message: err.message });
try {
await runtime.uninstallComponent(currentProject.settings.runtime.path, packageName);
await runtime.uninstallComponent(runtimePath, packageName);
} catch (err) {
composer.log('Error uninstalling', err);
}
// if packageName is in the github form <username/package> remove the first part, because otherwise the unisntall doesn't work
if (packageName.match(/.*\/.*/)) {
const [user, realPackageName] = packageName.split(/\//);
if (!user.match(/^@/)) {
await runtime.uninstallComponent(currentProject.settings.runtime.path, realPackageName);
await runtime.uninstallComponent(runtimePath, realPackageName);
}
}
res.status(500).json({ success: false, message: err.message });
}
} else if (!currentProject.settings?.runtime?.path) {
} else if (!runtimePath) {
res.status(500).json({ message: 'Please eject your runtime before installing a package.' });
} else {
res.status(500).json({ message: 'Please specify a package name or git url to import.' });
Expand All @@ -230,13 +242,18 @@ export default async (composer: IExtensionRegistration): Promise<void> => {
mergeErrors.push(msg);
};

let runtimePath = currentProject.settings?.runtime?.path;
if (runtimePath && !path.isAbsolute(runtimePath)) {
runtimePath = path.resolve(currentProject.dir, runtimePath)
}

// get URL or package name
const packageName = req.body.package;
if (packageName && currentProject.settings?.runtime?.path) {
if (packageName && runtimePath) {
try {
const output = await runtime.uninstallComponent(currentProject.settings.runtime.path, packageName);
const output = await runtime.uninstallComponent(runtimePath, packageName);

const manifestFile = runtime.identifyManifest(currentProject.settings?.runtime?.path);
const manifestFile = runtime.identifyManifest(runtimePath);

// call do a dry run on the dialog merge
const merger = new SchemaMerger(
Expand Down

0 comments on commit 0907221

Please sign in to comment.