Skip to content
This repository was archived by the owner on May 11, 2022. It is now read-only.

Commit cd4a8bd

Browse files
authored
FUSETOOLS2-1010 - migrate to url-parse (#432)
Signed-off-by: Brian Fitzpatrick <[email protected]>
1 parent d4129f3 commit cd4a8bd

File tree

7 files changed

+284
-62
lines changed

7 files changed

+284
-62
lines changed

package-lock.json

Lines changed: 266 additions & 46 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -229,6 +229,7 @@
229229
"markdown-it-task-lists": "^2.1.1",
230230
"node-fetch": "^2.6.1",
231231
"node-html-parser": "^2.1.0",
232-
"tmp": "^0.2.1"
232+
"tmp": "^0.2.1",
233+
"url-parse": "^1.5.1"
233234
}
234235
}

src/commandHandler.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,15 +19,15 @@ import * as vscode from 'vscode';
1919
import * as path from 'path';
2020
import {getValue} from './utils';
2121
import * as extensionFunctions from './extensionFunctions';
22-
import * as url from 'url';
2322
import {isDefaultNotificationDisabled} from './utils';
23+
const url = require('url-parse');
2424

2525
// take the incoming didact link and allow a mix of a uri and text/user inputs
2626
export async function processInputs(incoming : string, extensionPath? : string) : Promise<void | undefined> {
2727
const output : any[] = [];
2828
if (incoming) {
2929
extensionFunctions.sendTextToOutputChannel(`Processing command inputs ${incoming} ${extensionPath}`);
30-
const parsedUrl = url.parse(incoming, true);
30+
const parsedUrl = new url(incoming, true);
3131
const query = parsedUrl.query;
3232

3333
let commandId: string | undefined = undefined;

src/didactUri.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,9 @@
1717

1818
'use strict';
1919

20-
import * as url from 'url';
2120
import {getValue} from './utils';
2221
import * as vscode from 'vscode';
22+
const url = require('url-parse');
2323

2424
export class DidactUri {
2525
private commandId: string | undefined;
@@ -76,7 +76,7 @@ export class DidactUri {
7676
}
7777

7878
private parseDidactUrl(incoming: string) : void {
79-
const parsedUrl = url.parse(incoming, true);
79+
const parsedUrl = new url(incoming, true);
8080
const query = parsedUrl.query;
8181

8282
if (query.commandId) {

src/extensionFunctions.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,15 +26,14 @@ import {parseADtoHTML} from './asciidocUtils';
2626
import * as scaffoldUtils from './scaffoldUtils';
2727
import { TreeNode } from './nodeProvider';
2828
import { handleExtFilePath, handleProjectFilePath } from './commandHandler';
29-
import * as url from 'url';
3029
import * as download from 'download';
3130
import { didactManager } from './didactManager';
3231
import { parse } from 'node-html-parser';
3332
import { DIDACT_DEFAULT_URL } from './utils';
3433

3534
const tmp = require('tmp');
3635
const fetch = require('node-fetch');
37-
36+
const url = require('url-parse');
3837
const EDITOR_OPENED_TIMEOUT = 3000;
3938

4039
// command IDs
@@ -653,7 +652,7 @@ export async function validateDidactCommands(commands : any[], sendToConsole = f
653652
const vsCommands : string[] = await vscode.commands.getCommands(true);
654653
for(const command of commands) {
655654
// validate all commands we found
656-
const parsedUrl = url.parse(command, true);
655+
const parsedUrl = new url(command, true);
657656
const query = parsedUrl.query;
658657
if (query.commandId) {
659658
const commandId = utils.getValue(query.commandId);
@@ -720,7 +719,7 @@ export async function placeTextOnClipboard(clipText: string): Promise<void>{
720719
export async function downloadAndUnzipFile(httpFileUrl : string, installFolder : string, dlFilename? : string, extractFlag = false, ignoreOverwrite = false): Promise<any> {
721720
let filename = '';
722721
if (!dlFilename) {
723-
const fileUrl = url.parse(httpFileUrl);
722+
const fileUrl = new url(httpFileUrl);
724723
const pathname = fileUrl.pathname;
725724
if (pathname) {
726725
filename = pathname.substring(pathname.lastIndexOf('/')+1);

src/test/suite/Utils.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,11 @@ import * as vscode from 'vscode';
2121
import * as extensionFunctions from '../../extensionFunctions';
2222
import { didactManager } from '../../didactManager';
2323
import { expect } from 'chai';
24-
import * as url from 'url';
2524
import * as utils from '../../utils';
2625
import { waitUntil } from 'async-wait-until';
2726

27+
const url = require('url-parse');
28+
2829
const extensionId = 'redhat.vscode-didact';
2930
export const ACTIVATION_TIMEOUT = 45000;
3031

@@ -71,7 +72,7 @@ export async function getFailedCommands(commands : any[]) : Promise<String[]> {
7172
if (commands && commands.length > 0) {
7273
const vsCommands : string[] = await vscode.commands.getCommands(true);
7374
for(const command of commands) {
74-
const parsedUrl = url.parse(command, true);
75+
const parsedUrl = new url(command, true);
7576
const query = parsedUrl.query;
7677
if (query.commandId) {
7778
const commandId = utils.getValue(query.commandId);

src/test/suite/didact.test.ts

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,14 +22,15 @@ import * as fs from 'fs';
2222
import * as vscode from 'vscode';
2323
import * as path from 'path';
2424
import * as extensionFunctions from '../../extensionFunctions';
25-
import * as url from 'url';
2625
import {getValue} from '../../utils';
2726
import * as commandHandler from '../../commandHandler';
2827
import { removeFilesAndFolders } from '../../utils';
2928

3029
import { waitUntil } from 'async-wait-until';
3130
import { didactManager } from '../../didactManager';
3231

32+
const url = require('url-parse');
33+
3334
const EDITOR_OPENED_TIMEOUT = 5000;
3435

3536
const testMD = vscode.Uri.parse('vscode://redhat.vscode-didact?extension=demos/markdown/didact-demo.didact.md');
@@ -132,7 +133,7 @@ suite('Didact test suite', () => {
132133

133134
test('Test the extension checking', async () => {
134135
const href = testExt;
135-
const parsedUrl = url.parse(href, true);
136+
const parsedUrl = new url(href, true);
136137
const query = parsedUrl.query;
137138
assert.notStrictEqual(query.commandId, undefined);
138139
if (query.commandId) {
@@ -153,7 +154,7 @@ suite('Didact test suite', () => {
153154

154155
test('test the command line requirements checking', async () => {
155156
const href = testReqCli;
156-
const parsedUrl = url.parse(href, true);
157+
const parsedUrl = new url(href, true);
157158
const query = parsedUrl.query;
158159
assert.notStrictEqual(query.commandId, undefined);
159160
if (query.commandId) {
@@ -181,7 +182,7 @@ suite('Didact test suite', () => {
181182
} else if (osName.startsWith(OS_MACOS)) {
182183
href = testReqMac;
183184
}
184-
const parsedUrl = url.parse(href, true);
185+
const parsedUrl = new url(href, true);
185186
const query = parsedUrl.query;
186187
assert.notStrictEqual(query.commandId, undefined);
187188
if (query.commandId) {
@@ -202,7 +203,7 @@ suite('Didact test suite', () => {
202203

203204
test('test the workspace checking', async () => {
204205
const href = testWS.toString();
205-
const parsedUrl = url.parse(href, true);
206+
const parsedUrl = new url(href, true);
206207
const query = parsedUrl.query;
207208
assert.notStrictEqual(query.commandId, undefined);
208209
if (query.commandId) {

0 commit comments

Comments
 (0)