Skip to content

Commit

Permalink
Merge pull request #487 from sleistner/chore/update-dependencies
Browse files Browse the repository at this point in the history
Update dependencies
  • Loading branch information
sleistner authored Jan 1, 2023
2 parents 1058e69 + 37c5078 commit 39bce2e
Show file tree
Hide file tree
Showing 12 changed files with 1,021 additions and 894 deletions.
4 changes: 4 additions & 0 deletions .husky/pre-commit
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/usr/bin/env sh
. "$(dirname -- "$0")/_/husky.sh"

yarn run lint && yarn run test
2 changes: 1 addition & 1 deletion .node-version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
16.15.0
18
52 changes: 24 additions & 28 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -180,47 +180,43 @@
"pretest": "yarn run build:compile:dev",
"test": "node ./out/test/runTest.js",
"lint": "eslint './{src,test}/**/*.ts'",
"semantic-release": "semantic-release"
"semantic-release": "semantic-release",
"prepare": "[ ! -x ./node_modules/.bin/husky ] && exit 0; husky install"
},
"devDependencies": {
"@enter-at/eslint-config-typescript-prettier": "1.5.2",
"@semantic-release/changelog": "6.0.1",
"@enter-at/eslint-config-typescript-prettier": "1.6.0",
"@semantic-release/changelog": "6.0.2",
"@semantic-release/commit-analyzer": "9.0.2",
"@semantic-release/git": "10.0.1",
"@semantic-release/github": "8.0.4",
"@semantic-release/github": "8.0.7",
"@semantic-release/npm": "9.0.1",
"@semantic-release/release-notes-generator": "10.0.3",
"@types/bluebird": "3.5.36",
"@tsconfig/node18": "1.0.1",
"@types/bluebird": "3.5.38",
"@types/bluebird-retry": "0.11.5",
"@types/brace-expansion": "1.1.0",
"@types/chai": "4.3.1",
"@types/glob": "7.2.0",
"@types/mocha": "9.1.1",
"@types/node": "12.19.3",
"@types/sinon": "10.0.11",
"@types/sinon-chai": "3.2.8",
"@types/vscode": "1.51.0",
"@types/chai": "4.3.4",
"@types/mocha": "10.0.1",
"@types/node": "18.11.18",
"@types/sinon": "10.0.13",
"@types/sinon-chai": "3.2.9",
"@types/vscode": "1.74.0",
"bluebird": "3.7.2",
"bluebird-retry": "0.11.0",
"chai": "4.3.6",
"eslint": "7.20.0",
"glob": "7.2.3",
"husky": "4.3.8",
"mocha": "9.2.2",
"prettier": "2.2.1",
"semantic-release": "19.0.3",
"semantic-release-vsce": "5.0.12",
"sinon": "9.2.4",
"chai": "4.3.7",
"eslint": "8.31.0",
"husky": "8.0.2",
"mocha": "10.2.0",
"prettier": "2.8.1",
"semantic-release": "19.0.5",
"semantic-release-vsce": "5.5.2",
"sinon": "15.0.1",
"sinon-chai": "3.7.0",
"typescript": "4.6.4",
"typescript": "4.9.4",
"vscode-test": "1.6.1"
},
"dependencies": {
"brace-expansion": "2.0.1"
},
"husky": {
"hooks": {
"pre-commit": "yarn run lint && yarm run test"
}
"brace-expansion": "2.0.1",
"fast-glob": "3.2.12"
}
}
7 changes: 4 additions & 3 deletions src/controller/TypeAheadController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ export class TypeAheadController {
constructor(private cache: Cache, private relativeToRoot: boolean) {}

public async showDialog(sourcePath: string): Promise<string> {
const item = await this.showQuickPick(this.buildQuickPickItems(sourcePath));
const items = await this.buildQuickPickItems(sourcePath);
const item = await this.showQuickPick(items);

if (!item) {
throw new Error();
Expand Down Expand Up @@ -51,9 +52,9 @@ export class TypeAheadController {
return { description, label };
}

private async showQuickPick(items: Thenable<QuickPickItem[]>) {
private async showQuickPick(items: readonly QuickPickItem[]) {
const hint = "larger projects may take a moment to load";
const placeHolder = `First, select an existing path to create relative to (${hint})`;
return window.showQuickPick<QuickPickItem>(items, { placeHolder });
return window.showQuickPick(items, { placeHolder });
}
}
35 changes: 16 additions & 19 deletions src/lib/TreeWalker.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import glob from "fast-glob";
import * as path from "path";
import { RelativePattern, Uri, workspace } from "vscode";
import { workspace } from "vscode";

interface ExtendedProcess {
noAsar: boolean;
Expand All @@ -9,31 +10,27 @@ export class TreeWalker {
public async directories(sourcePath: string): Promise<string[]> {
try {
this.ensureFailSafeFileLookup();
const pattern = new RelativePattern(sourcePath, "**");
const files = await workspace.findFiles(pattern, undefined, Number.MAX_VALUE);
const directories = files.reduce(this.directoryReducer(sourcePath), new Set<string>());
return this.toSortedArray(directories);
const files = await glob("**", {
cwd: sourcePath,
onlyDirectories: true,
ignore: this.getExcludePatterns(),
});
return files.map((file) => path.join(path.sep, file)).sort();
} catch (err) {
const details = (err as Error).message;
throw new Error(`Unable to list subdirectories for directory "${sourcePath}". Details: (${details})`);
}
}

private ensureFailSafeFileLookup() {
((process as unknown) as ExtendedProcess).noAsar = true;
}

private directoryReducer(sourcePath: string) {
return (accumulator: Set<string>, file: Uri) => {
const directory = path.dirname(file.fsPath).replace(sourcePath, "");
if (directory) {
accumulator.add(directory);
}
return accumulator;
};
private getExcludePatterns(): string[] {
const exclude = new Set([
...Object.keys(workspace.getConfiguration("search.exclude")),
...Object.keys(workspace.getConfiguration("files.exclude")),
]);
return Array.from(exclude);
}

private toSortedArray(directories: Set<string>): string[] {
return Array.from(directories).sort();
private ensureFailSafeFileLookup() {
(process as unknown as ExtendedProcess).noAsar = true;
}
}
22 changes: 12 additions & 10 deletions test/command/NewFileCommand.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { expect } from "chai";
import * as fs from "fs";
import * as path from "path";
import sinon from "sinon";
import { Uri, window, workspace, WorkspaceFolder } from "vscode";
import { NewFileCommand } from "../../src/command";
import { NewFileController } from "../../src/controller";
Expand Down Expand Up @@ -55,14 +56,14 @@ describe(NewFileCommand.name, () => {
it("should show the quick pick dialog", async () => {
await subject.execute();
expect(window.showQuickPick).to.have.been.calledOnceWithExactly(
Promise.resolve([
sinon.match([
{ description: "- current file", label: "/" },
{ description: undefined, label: "/dir-1" },
{ description: undefined, label: "/dir-2" },
]),
{
sinon.match({
placeHolder: expectedShowQuickPickPlaceHolder,
}
})
);
});
});
Expand All @@ -74,7 +75,7 @@ describe(NewFileCommand.name, () => {

it("should show the quick pick dialog", async () => {
await subject.execute();
expect(window.showQuickPick).to.have.not.been;
expect(window.showQuickPick).to.have.not.been.called;
});
});
});
Expand Down Expand Up @@ -192,14 +193,14 @@ describe(NewFileCommand.name, () => {
it("should show the quick pick dialog", async () => {
await subject.execute();
expect(window.showQuickPick).to.have.been.calledOnceWith(
Promise.resolve([
sinon.match([
{ description: "- workspace root", label: "/" },
{ description: undefined, label: "/dir-1" },
{ description: undefined, label: "/dir-2" },
]),
{
sinon.match({
placeHolder: expectedShowQuickPickPlaceHolder,
}
})
);
});
});
Expand Down Expand Up @@ -273,15 +274,16 @@ describe(NewFileCommand.name, () => {

it("should show the quick pick dialog", async () => {
await subject.execute();

expect(window.showQuickPick).to.have.been.calledOnceWith(
Promise.resolve([
sinon.match([
{ description: "- workspace root", label: "/" },
{ description: undefined, label: "/dir-1" },
{ description: undefined, label: "/dir-2" },
]),
{
sinon.match({
placeHolder: expectedShowQuickPickPlaceHolder,
}
})
);
});
});
Expand Down
2 changes: 1 addition & 1 deletion test/helper/functions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ export function createExtensionContext(): ExtensionContext {
},
},
};
return (context as unknown) as ExtensionContext;
return context as unknown as ExtensionContext;
}

export async function openDocument(document: Uri): Promise<void> {
Expand Down
2 changes: 1 addition & 1 deletion test/helper/stubs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ type Handler = any;

export function createStubObject(handler: Handler, functionName: string): sinon.SinonStub {
const target: sinon.SinonStub | undefined = handler[functionName];
const stub: sinon.SinonStub = target && target.restore ? target : sinon.stub(handler, functionName);
const stub: sinon.SinonStub = target && "restore" in target ? target : sinon.stub(handler, functionName);

return stub;
}
Expand Down
4 changes: 2 additions & 2 deletions test/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import Mocha from "mocha";
import * as path from "path";
import * as glob from "glob";
import glob from "fast-glob";

export async function run(): Promise<void> {
const mocha = new Mocha({
Expand All @@ -10,7 +10,7 @@ export async function run(): Promise<void> {
});

const testsRoot = path.resolve(__dirname, "..");
const files = glob.sync("**/**.test.js", { cwd: testsRoot });
const files = await glob("**/**.test.js", { cwd: testsRoot });

console.log("Number of test files to run:", files.length);
// Add files to the test suite
Expand Down
6 changes: 5 additions & 1 deletion test/runTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,11 @@ async function main() {
const extensionTestsPath = path.resolve(__dirname, "./index");

// Download VS Code, unzip it and run the integration test
await runTests({ extensionDevelopmentPath, extensionTestsPath });
await runTests({
extensionDevelopmentPath,
extensionTestsPath,
launchArgs: ["--disable-extensions"],
});
} catch (err) {
// tslint:disable-next-line: no-console
console.error("Failed to run tests");
Expand Down
14 changes: 4 additions & 10 deletions tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,22 +1,16 @@
{
"extends": "@tsconfig/node18/tsconfig.json",
"compilerOptions": {
"rootDir": ".",
"outDir": "out",
"module": "commonjs",
"target": "ES2019",

"sourceMap": true,
"strict": true,
"moduleResolution": "node",

"removeComments": true,
"resolveJsonModule": true,
"esModuleInterop": true,
"experimentalDecorators": true,
"emitDecoratorMetadata": true,
"allowSyntheticDefaultImports": true
},
"exclude": [
"node_modules",
".vscode-test"
]
"exclude": ["node_modules", ".vscode-test"]
}

Loading

0 comments on commit 39bce2e

Please sign in to comment.