diff --git a/package-lock.json b/package-lock.json index 6c47a70..9fa8bba 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "vscode-prettier-eslint", - "version": "1.1.1", + "version": "1.1.5", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "vscode-prettier-eslint", - "version": "1.1.1", + "version": "1.1.5", "license": "MIT", "dependencies": { "find-up": "7.0.0", diff --git a/package.json b/package.json index 77f1059..132d421 100644 --- a/package.json +++ b/package.json @@ -2,7 +2,7 @@ "name": "vscode-prettier-eslint", "displayName": "VSCode Prettier ESLint", "description": "VSCode extension to format your JavaScript and TypeScript using prettier-eslint", - "version": "1.1.4", + "version": "1.1.5", "publisher": "exceptionptr", "author": "Stanislaw Schlosser ", "icon": "icon.png", diff --git a/src/extension.js b/src/extension.js index 737336f..bf23244 100644 --- a/src/extension.js +++ b/src/extension.js @@ -95,22 +95,12 @@ function fileNotInWorkspace(filePath, workspaceDirectory) { */ async function formatText(text, filePath) { try { - const name = await prettierEslint.import(filePath); - - if (!name) { - outputChannel.appendLine('No prettier-eslint found.'); - throw new Error('No prettier-eslint found.'); - } - const result = await prettierEslint .callMethod(text, filePath); return result; } catch (/** @type { any } */ err) { - prettierEslint.reload(); - outputChannel.appendLine(`Error: ${err.message} \n ${err.stack}`); - outputChannel.show(); } return text; diff --git a/src/prettier-eslint.js b/src/prettier-eslint.js index 7d3ff27..b8c4bc8 100644 --- a/src/prettier-eslint.js +++ b/src/prettier-eslint.js @@ -3,12 +3,6 @@ import * as path from 'path'; import { Worker } from "worker_threads"; export class PrettierEslintVSCode { - /** - * @private - * @type {{ resolve: (name: string) => void; reject: (err: Error) => void; } | null} - */ - _importResolver = null; - /** * @private * @type {{ id: number; resolve: (result: unknown) => void; reject: (err: Error) => void; }[]}} @@ -37,14 +31,6 @@ export class PrettierEslintVSCode { this._worker.on('message', ({ type, payload }) => { switch (type) { - case 'import': - if (payload.error) - this._importResolver?.reject(new Error(payload.error)); - else - this._importResolver?.resolve(payload.name); - - break; - case 'callMethod': const callMethodResolver = this._callMethodResolvers.find(({ id }) => id === payload.id); if (!callMethodResolver) break; @@ -62,23 +48,6 @@ export class PrettierEslintVSCode { }); } - /** - * @param {string} filePath - * @returns {Promise} - */ - async import(filePath) { - const promise = new Promise((resolve, reject) => { - this._importResolver = { resolve, reject }; - }); - - this._worker.postMessage({ - type: 'import', - payload: { filePath, modulePath: this._modulePath }, - }); - - return promise; - } - /** * @param {string} text * @param {string} filePath @@ -98,8 +67,4 @@ export class PrettierEslintVSCode { return promise; } - - reload() { - this._worker = new Worker(path.resolve(__dirname, 'worker.js')); - } } \ No newline at end of file diff --git a/src/worker.js b/src/worker.js index 4cdcb11..1867077 100644 --- a/src/worker.js +++ b/src/worker.js @@ -11,10 +11,6 @@ parentPort?.on('message', onParentPortMessage); */ function onParentPortMessage({ type, payload }) { switch (type) { - case 'import': - onImport(payload); - break; - case 'callMethod': onCallMethod(payload); break; @@ -25,8 +21,9 @@ function onParentPortMessage({ type, payload }) { * * @param {*} payload */ -function onImport(payload) { - const { filePath, modulePath } = payload; +function onCallMethod(payload) { + const { modulePath, text, filePath, id } = payload; + try { let instance = moduleCache.get(modulePath); @@ -39,32 +36,6 @@ function onImport(payload) { moduleCache.set(modulePath, instance); } - parentPort?.postMessage({ - type: 'import', - payload: { name: instance.name }, - }); - } catch (/** @type { any } */ err) { - parentPort?.postMessage({ - type: 'import', - payload: { error: err.message }, - }); - } -} - -/** - * - * @param {*} payload - */ -function onCallMethod(payload) { - const { modulePath, text, filePath, id } = payload; - - try { - const instance = moduleCache.get(modulePath); - - if (!instance) { - throw new Error(`No instance found for module path: ${modulePath}`); - } - const arg = { text, filePath }; const result = instance(arg);