Skip to content

Commit

Permalink
fix: fix spawn cmd
Browse files Browse the repository at this point in the history
  • Loading branch information
zxch3n committed May 16, 2022
1 parent 25f1dc8 commit 296f2da
Show file tree
Hide file tree
Showing 5 changed files with 153 additions and 4 deletions.
7 changes: 6 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -116,9 +116,11 @@
"@types/node": "14.x",
"@types/semver": "^7.3.9",
"@types/vscode": "^1.59.0",
"@types/ws": "^8.5.3",
"@typescript-eslint/eslint-plugin": "^5.12.1",
"@typescript-eslint/parser": "^5.12.1",
"@vscode/test-electron": "^2.1.2",
"@vueuse/core": "^8.4.2",
"eslint": "^8.9.0",
"glob": "^7.2.0",
"mocha": "^9.2.1",
Expand All @@ -131,9 +133,12 @@
"@babel/parser": "^7.17.3",
"@babel/types": "^7.17.0",
"@rauschma/stringio": "^1.4.0",
"@vitest/ws-client": "^0.12.6",
"@vue/reactivity": "^3.2.33",
"fs-extra": "^10.0.1",
"mighty-promise": "^0.0.8",
"minimatch": "^3.1.1",
"semver": "^7.3.5"
"semver": "^7.3.5",
"ws": "^8.6.0"
}
}
80 changes: 80 additions & 0 deletions src/pure/watch/client.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
import { createClient, getTasks } from "@vitest/ws-client";
import WebSocket from "ws";
import { Ref } from "@vue/reactivity";
import { computed, reactive, ref, shallowRef } from "@vue/reactivity";
import type { File, ResolvedConfig } from "vitest";

type WebSocketStatus = "OPEN" | "CONNECTING" | "CLOSED";
export type RunState = "idle" | "running";

export function buildWatchClient(url = "http://localhost:51204") {
const testRunState: Ref<RunState> = ref("idle");

const client = createClient(url, {
WebSocketConstructor: WebSocket as any,
reactive: reactive as any,
handlers: {
onTaskUpdate() {
testRunState.value = "running";
},
onFinished() {
testRunState.value = "idle";
},
},
});

const config = shallowRef<ResolvedConfig>({} as any);
const status = ref<WebSocketStatus>("CONNECTING");
const files = computed(() => client.state.getFiles());
const findById = (id: string) => {
return files.value.find((file) => file.id === id);
};

const isConnected = computed(() => status.value === "OPEN");
const isConnecting = computed(() => status.value === "CONNECTING");
const isDisconnected = computed(() => status.value === "CLOSED");

function runAll(files = client.state.getFiles()) {
return runFiles(files);
}

function runFiles(files: File[]) {
files.forEach((f) => {
delete f.result;
getTasks(f).forEach((i) => delete i.result);
});
return client.rpc.rerun(files.map((i) => i.filepath));
}

const ws = client.ws;
status.value = "CONNECTING";

ws.addEventListener("open", () => {
status.value = "OPEN";
client.state.filesMap.clear();
client.rpc.getFiles().then((files) => client.state.collectFiles(files));
client.rpc.getConfig().then((_config) => config.value = _config);
});

ws.addEventListener("close", () => {
setTimeout(() => {
if (status.value === "CONNECTING") {
status.value = "CLOSED";
}
}, 1000);
});

return {
testRunState,
client,
config,
status,
files,
isConnected,
isConnecting,
isDisconnected,
runAll,
runFiles,
findById,
};
}
2 changes: 1 addition & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"module": "commonJS",
"target": "ES2020",
"outDir": "out",
"lib": ["ES2020"],
"lib": ["ES2020", "DOM"],
"sourceMap": true,
"rootDir": "src",
"esModuleInterop": true,
Expand Down
2 changes: 1 addition & 1 deletion vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,6 @@ export default defineConfig({
test: {
/* for example, use global to avoid globals imports (describe, test, expect): */
// globals: true,
exclude: ["**/src/**", "**/node_modules/**", "**/samples/**"],
exclude: ["**/src/**", "**/node_modules/**", "**/samples/**", "out/**"],
},
});
66 changes: 65 additions & 1 deletion yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,13 @@
resolved "https://registry.npmmirror.com/@types/vscode/-/vscode-1.65.0.tgz"
integrity sha512-wQhExnh2nEzpjDMSKhUvnNmz3ucpd3E+R7wJkOhBNK3No6fG3VUdmVmMOKD0A8NDZDDDiQcLNxe3oGmX5SjJ5w==

"@types/ws@^8.5.3":
version "8.5.3"
resolved "https://registry.npmmirror.com/@types/ws/-/ws-8.5.3.tgz#7d25a1ffbecd3c4f2d35068d0b283c037003274d"
integrity sha512-6YOoWjruKj1uLf3INHH7D3qTXwFfEsg1kf3c0uDdSBJwfa/llkwIjrAGV7j7mVgGNbzTQ3HiHKKDXl6bJPD97w==
dependencies:
"@types/node" "*"

"@typescript-eslint/eslint-plugin@^5.12.1":
version "5.14.0"
resolved "https://registry.npmmirror.com/@typescript-eslint/eslint-plugin/-/eslint-plugin-5.14.0.tgz"
Expand Down Expand Up @@ -239,6 +246,15 @@
resolved "https://registry.npmmirror.com/@ungap/promise-all-settled/-/promise-all-settled-1.1.2.tgz"
integrity sha512-sL/cEvJWAnClXw0wHk85/2L0G6Sj8UB0Ctc1TEMbKSsmpRosqhwj9gWgFRZSrBr2f9tiXISwNhCPmlfqUqyb9Q==

"@vitest/ws-client@^0.12.6":
version "0.12.6"
resolved "https://registry.npmmirror.com/@vitest/ws-client/-/ws-client-0.12.6.tgz#ba9e530f3ac6ac90eadd7b501353566182114088"
integrity sha512-pKceZ54U8O11Jb/KvZeh5Vz4H5fy9BfHk2FrRVjcR4Dk31KlS7Wxvr0+qgGFY1vHTCK39qQH4wrwCZLF9J6pYw==
dependencies:
birpc "^0.2.2"
flatted "^3.2.5"
ws "^8.6.0"

"@vscode/test-electron@^2.1.2":
version "2.1.3"
resolved "https://registry.npmmirror.com/@vscode/test-electron/-/test-electron-2.1.3.tgz#c66c4a29ede1f940c2fa204d269b660b0126dc7f"
Expand All @@ -249,6 +265,39 @@
rimraf "^3.0.2"
unzipper "^0.10.11"

"@vue/reactivity@^3.2.33":
version "3.2.33"
resolved "https://registry.npmmirror.com/@vue/reactivity/-/reactivity-3.2.33.tgz#c84eedb5225138dbfc2472864c151d3efbb4b673"
integrity sha512-62Sq0mp9/0bLmDuxuLD5CIaMG2susFAGARLuZ/5jkU1FCf9EDbwUuF+BO8Ub3Rbodx0ziIecM/NsmyjardBxfQ==
dependencies:
"@vue/shared" "3.2.33"

"@vue/shared@3.2.33":
version "3.2.33"
resolved "https://registry.npmmirror.com/@vue/shared/-/shared-3.2.33.tgz#69a8c99ceb37c1b031d5cc4aec2ff1dc77e1161e"
integrity sha512-UBc1Pg1T3yZ97vsA2ueER0F6GbJebLHYlEi4ou1H5YL4KWvMOOWwpYo9/QpWq93wxKG6Wo13IY74Hcn/f7c7Bg==

"@vueuse/core@^8.4.2":
version "8.4.2"
resolved "https://registry.npmmirror.com/@vueuse/core/-/core-8.4.2.tgz#e5be73f40394150e6a1b6abd59e5adb7c6bb6c1f"
integrity sha512-dUVU96lii1ZdWoNJXauQNt+4QrHz1DKbuW+y6pDR2N10q7rGZJMDU7pQeMcC2XeosX7kMODfaBuqsF03NozzLg==
dependencies:
"@vueuse/metadata" "8.4.2"
"@vueuse/shared" "8.4.2"
vue-demi "*"

"@vueuse/metadata@8.4.2":
version "8.4.2"
resolved "https://registry.npmmirror.com/@vueuse/metadata/-/metadata-8.4.2.tgz#b33e6b7bd5ca69e3f24ea41b149267118bcd566f"
integrity sha512-2BIj++7P0/I5dfMsEe8q7Kw0HqVAjVcyNOd9+G22/ILUC9TVLTeYOuJ1kwa1Gpr+0LWKHc6GqHiLWNL33+exoQ==

"@vueuse/shared@8.4.2":
version "8.4.2"
resolved "https://registry.npmmirror.com/@vueuse/shared/-/shared-8.4.2.tgz#5900f06ff78bd8b6df4cbf48f8ca82dd6d9747d1"
integrity sha512-hILXMEjL8YQhj1LHN/HZ49UThyfk8irTjhele2nW+L3N55ElFUBGB/f4w0rg8EW+/suhqv7kJJPTZzvHCqxlIw==
dependencies:
vue-demi "*"

acorn-jsx@^5.3.1:
version "5.3.2"
resolved "https://registry.npmmirror.com/acorn-jsx/-/acorn-jsx-5.3.2.tgz"
Expand Down Expand Up @@ -339,6 +388,11 @@ binary@~0.3.0:
buffers "~0.1.1"
chainsaw "~0.1.0"

birpc@^0.2.2:
version "0.2.2"
resolved "https://registry.npmmirror.com/birpc/-/birpc-0.2.2.tgz#7e033234e946e2772fa01dfb897f31dd69184acd"
integrity sha512-59Tc83t28ulRZpuPz4JO+ry1EhBsoy81etx1kboBSzkx7hGExqUzIYxwDLcj1Ou8f4P/ZNacqDaat1ubBUbInw==

bluebird@~3.4.1:
version "3.4.7"
resolved "https://registry.npmmirror.com/bluebird/-/bluebird-3.4.7.tgz#f72d760be09b7f76d08ed8fae98b289a8d05fab3"
Expand Down Expand Up @@ -976,7 +1030,7 @@ flat@^5.0.2:
resolved "https://registry.npmmirror.com/flat/-/flat-5.0.2.tgz"
integrity sha512-b6suED+5/3rTpUBdG1gupIl8MPFCAMA0QXwmljLhvCUKcUvdE4gWky9zpuGCcXHOsz4J9wPGNWq6OKpmIzz3hQ==

flatted@^3.1.0:
flatted@^3.1.0, flatted@^3.2.5:
version "3.2.5"
resolved "https://registry.npmmirror.com/flatted/-/flatted-3.2.5.tgz"
integrity sha512-WIWGi2L3DyTUvUrwRKgGi9TwxQMUEqPOPQBVi71R96jZXJdFskXEmf54BoZaS1kknGODoIGASGEzBUYdyMCBJg==
Expand Down Expand Up @@ -1834,6 +1888,11 @@ vitest@latest:
tinyspy "^0.3.2"
vite "^2.9.5"

vue-demi@*:
version "0.12.5"
resolved "https://registry.npmmirror.com/vue-demi/-/vue-demi-0.12.5.tgz#8eeed566a7d86eb090209a11723f887d28aeb2d1"
integrity sha512-BREuTgTYlUr0zw0EZn3hnhC3I6gPWv+Kwh4MCih6QcAeaTlaIX0DwOVN0wHej7hSvDPecz4jygy/idsgKfW58Q==

which@2.0.2, which@^2.0.1:
version "2.0.2"
resolved "https://registry.npmmirror.com/which/-/which-2.0.2.tgz"
Expand Down Expand Up @@ -1865,6 +1924,11 @@ wrappy@1:
resolved "https://registry.npmmirror.com/wrappy/-/wrappy-1.0.2.tgz#b5243d8f3ec1aa35f1364605bc0d1036e30ab69f"
integrity sha512-l4Sp/DRseor9wL6EvV2+TuQn63dMkPjZ/sp9XkghTEbV9KlPS1xUsZ3u7/IQO4wxtcFB4bgpQPRcR3QCvezPcQ==

ws@^8.6.0:
version "8.6.0"
resolved "https://registry.npmmirror.com/ws/-/ws-8.6.0.tgz#e5e9f1d9e7ff88083d0c0dd8281ea662a42c9c23"
integrity sha512-AzmM3aH3gk0aX7/rZLYvjdvZooofDu3fFOzGqcSnQ1tOcTWwhM/o+q++E8mAyVVIyUdajrkzWUGftaVSDLn1bw==

y18n@^5.0.5:
version "5.0.8"
resolved "https://registry.npmmirror.com/y18n/-/y18n-5.0.8.tgz"
Expand Down

0 comments on commit 296f2da

Please sign in to comment.