Skip to content

Commit

Permalink
Normalized extension root path before usage in ext:dev:upload. (#6054)
Browse files Browse the repository at this point in the history
* Normalized extension root path before usage.

* Update CHANGELOG.md

* Update publisherApi.ts

* Update extensionsHelper.ts

* Update CHANGELOG.md

* Replaced join() with normalize() and fixed regex.

* Update extensionsHelper.ts

* Update extensionsHelper.ts
  • Loading branch information
apascal07 authored Jun 28, 2023
1 parent ac28f26 commit 654e884
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 17 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
- Increased extension instance create poll timeout to 1h to match backend (#5969).
- Refactored `ext:install` to use the latest extension metadata. (#5997)
- Normalized extension root path before usage in `ext:dev:upload`. (#6054)
31 changes: 15 additions & 16 deletions src/extensions/extensionsHelper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -408,24 +408,17 @@ export async function promptForValidRepoURI(): Promise<string> {
}

/**
* Prompts for a valid extension root.
* Prompts for an extension root.
*
* @param defaultRoot the default extension root
*/
export async function promptForValidExtensionRoot(defaultRoot: string): Promise<string> {
let rootIsValid = false;
let extensionRoot = "";
while (!rootIsValid) {
extensionRoot = await promptOnce({
type: "input",
message:
"Enter this extension's root directory in the repo (defaults to previous root if set):",
default: defaultRoot,
});
// TODO: Add real directory path validation.
rootIsValid = true;
}
return extensionRoot;
export async function promptForExtensionRoot(defaultRoot: string): Promise<string> {
return await promptOnce({
type: "input",
message:
"Enter this extension's root directory in the repo (defaults to previous root if set):",
default: defaultRoot,
});
}

/**
Expand Down Expand Up @@ -817,11 +810,17 @@ export async function uploadExtensionVersionFromGitHubSource(args: {
if (!extensionRoot) {
const defaultRoot = "/";
if (!args.nonInteractive) {
extensionRoot = await promptForValidExtensionRoot(defaultRoot);
extensionRoot = await promptForExtensionRoot(defaultRoot);
} else {
extensionRoot = defaultRoot;
}
}
// Normalize root path and strip leading and trailing slashes and all `../`.
const normalizedRoot = path
.normalize(extensionRoot)
.replaceAll(/^\/|\/$/g, "")
.replaceAll(/^(\.\.\/)*/g, "");
extensionRoot = normalizedRoot || "/";

// Prompt for source ref and default to HEAD.
let sourceRef = args.sourceRef;
Expand Down
2 changes: 1 addition & 1 deletion src/extensions/publisherApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ export async function createExtensionVersionFromGitHubSource(args: {
ExtensionVersion
>(`/${refs.toExtensionName(ref)}/versions:createFromSource`, {
versionId: ref.version,
extensionRoot: args.extensionRoot ?? "/",
extensionRoot: args.extensionRoot || "/",
githubRepositorySource: {
uri: args.repoUri,
sourceRef: args.sourceRef,
Expand Down

0 comments on commit 654e884

Please sign in to comment.