-
Notifications
You must be signed in to change notification settings - Fork 92
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
219 additions
and
153 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,84 +1,9 @@ | ||
import { | ||
CreateDiagnostic, | ||
createScript, | ||
ServeAndBuildChecker, | ||
SharedConfig, | ||
} from 'vite-plugin-checker' | ||
import { isMainThread, parentPort } from 'worker_threads' | ||
import * as commander from 'commander' | ||
|
||
import { DiagnosticOptions, diagnostics } from './commands/diagnostics' | ||
|
||
import type { ConfigEnv } from 'vite' | ||
|
||
export const createDiagnostic: CreateDiagnostic = (userOptions = {}) => { | ||
let overlay = true // Vite defaults to true | ||
|
||
return { | ||
config: ({ hmr }) => { | ||
const viteOverlay = !(typeof hmr === 'object' && hmr.overlay === false) | ||
|
||
if (userOptions.overlay === false || !viteOverlay) { | ||
overlay = false | ||
} | ||
}, | ||
async configureServer({ root }) { | ||
const workDir: string = userOptions.root ?? root | ||
const errorCallback: DiagnosticOptions['errorCallback'] = (diagnostics, overlayErr) => { | ||
if (!overlay) return | ||
if (!overlayErr) return | ||
|
||
parentPort?.postMessage({ | ||
type: 'ERROR', | ||
payload: { | ||
type: 'error', | ||
err: overlayErr, | ||
}, | ||
}) | ||
} | ||
|
||
await diagnostics(workDir, 'WARN', { watch: true, errorCallback, verbose: false }) | ||
}, | ||
} | ||
} | ||
|
||
const { mainScript, workerScript } = createScript<{ vls: VlsConfig }>({ | ||
absFilename: __filename, | ||
buildBin: ['vite-plugin-checker-vls', ['diagnostics']], | ||
serverChecker: { createDiagnostic }, | ||
})! | ||
|
||
if (isMainThread) { | ||
const configCurryFn = (vlsConfig: VlsConfig) => { | ||
return (sharedConfig: SharedConfig, env: ConfigEnv) => { | ||
const createChecker = mainScript() | ||
return createChecker({ vls: vlsConfig, ...sharedConfig }, env) | ||
} | ||
} | ||
|
||
module.exports.VlsChecker = configCurryFn | ||
module.exports.createServeAndBuild = configCurryFn | ||
} else { | ||
workerScript() | ||
} | ||
|
||
type VlsConfig = Partial<{ | ||
// TODO: support VLS config | ||
}> | ||
|
||
declare const VlsChecker: ( | ||
options?: VlsConfig | ||
) => (config: VlsConfig & SharedConfig) => ServeAndBuildChecker | ||
|
||
export { VlsChecker } | ||
export type { VlsConfig } | ||
|
||
import commander from 'commander' | ||
|
||
export * as vscodeLanguageserverProtocol from 'vscode-languageserver-protocol' | ||
export * as vscodeUri from 'vscode-uri' | ||
export { commander } | ||
export * as chokidar from 'chokidar' | ||
export * as vls from 'vls' | ||
export { commander } | ||
|
||
export * as vscodeLanguageserverNode from 'vscode-languageserver/node' | ||
export * as vscodeLanguageserverProtocol from 'vscode-languageserver-protocol' | ||
export * as vscodeLanguageserverTextdocument from 'vscode-languageserver-textdocument' | ||
export * as vscodeUri from 'vscode-uri' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
import { | ||
CreateDiagnostic, | ||
createScript, | ||
ServeAndBuildChecker, | ||
SharedConfig, | ||
} from 'vite-plugin-checker' | ||
import { isMainThread, parentPort } from 'worker_threads' | ||
|
||
import { DiagnosticOptions, diagnostics } from './commands/diagnostics' | ||
|
||
import type { ConfigEnv } from 'vite' | ||
|
||
export const createDiagnostic: CreateDiagnostic = (userOptions = {}) => { | ||
let overlay = true // Vite defaults to true | ||
|
||
return { | ||
config: ({ hmr }) => { | ||
const viteOverlay = !(typeof hmr === 'object' && hmr.overlay === false) | ||
|
||
if (userOptions.overlay === false || !viteOverlay) { | ||
overlay = false | ||
} | ||
}, | ||
async configureServer({ root }) { | ||
const workDir: string = userOptions.root ?? root | ||
const errorCallback: DiagnosticOptions['errorCallback'] = (diagnostics, overlayErr) => { | ||
if (!overlay) return | ||
if (!overlayErr) return | ||
|
||
parentPort?.postMessage({ | ||
type: 'ERROR', | ||
payload: { | ||
type: 'error', | ||
err: overlayErr, | ||
}, | ||
}) | ||
} | ||
|
||
await diagnostics(workDir, 'WARN', { watch: true, errorCallback, verbose: false }) | ||
}, | ||
} | ||
} | ||
|
||
const { mainScript, workerScript } = createScript<{ vls: VlsConfig }>({ | ||
absFilename: __filename, | ||
buildBin: ['vite-plugin-checker-vls', ['diagnostics']], | ||
serverChecker: { createDiagnostic }, | ||
})! | ||
|
||
if (isMainThread) { | ||
const configCurryFn = (vlsConfig: VlsConfig) => { | ||
return (sharedConfig: SharedConfig, env: ConfigEnv) => { | ||
const createChecker = mainScript() | ||
return createChecker({ vls: vlsConfig, ...sharedConfig }, env) | ||
} | ||
} | ||
|
||
module.exports.VlsChecker = configCurryFn | ||
module.exports.createServeAndBuild = configCurryFn | ||
} else { | ||
workerScript() | ||
} | ||
|
||
type VlsConfig = Partial<{ | ||
// TODO: support VLS config | ||
}> | ||
|
||
declare const VlsChecker: ( | ||
options?: VlsConfig | ||
) => (config: VlsConfig & SharedConfig) => ServeAndBuildChecker | ||
|
||
export { VlsChecker } | ||
export type { VlsConfig } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,73 +1,74 @@ | ||
import { | ||
CreateDiagnostic, | ||
createScript, | ||
ServeAndBuildChecker, | ||
SharedConfig, | ||
} from 'vite-plugin-checker' | ||
import { isMainThread, parentPort } from 'worker_threads' | ||
// import { | ||
// CreateDiagnostic, | ||
// createScript, | ||
// ServeAndBuildChecker, | ||
// SharedConfig, | ||
// } from 'vite-plugin-checker' | ||
// import { isMainThread, parentPort } from 'worker_threads' | ||
|
||
import { DiagnosticOptions, diagnostics } from './commands/diagnostics' | ||
// import { DiagnosticOptions, diagnostics } from './commands/diagnostics' | ||
|
||
import type { ConfigEnv } from 'vite' | ||
// import type { ConfigEnv } from 'vite' | ||
|
||
export const createDiagnostic: CreateDiagnostic = (userOptions = {}) => { | ||
let overlay = true // Vite defaults to true | ||
// export const createDiagnostic: CreateDiagnostic = (userOptions = {}) => { | ||
// let overlay = true // Vite defaults to true | ||
|
||
return { | ||
config: ({ hmr }) => { | ||
const viteOverlay = !(typeof hmr === 'object' && hmr.overlay === false) | ||
// return { | ||
// config: ({ hmr }) => { | ||
// const viteOverlay = !(typeof hmr === 'object' && hmr.overlay === false) | ||
|
||
if (userOptions.overlay === false || !viteOverlay) { | ||
overlay = false | ||
} | ||
}, | ||
async configureServer({ root }) { | ||
const workDir: string = userOptions.root ?? root | ||
const errorCallback: DiagnosticOptions['errorCallback'] = (diagnostics, overlayErr) => { | ||
if (!overlay) return | ||
if (!overlayErr) return | ||
// if (userOptions.overlay === false || !viteOverlay) { | ||
// overlay = false | ||
// } | ||
// }, | ||
// async configureServer({ root }) { | ||
// const workDir: string = userOptions.root ?? root | ||
// const errorCallback: DiagnosticOptions['errorCallback'] = (diagnostics, overlayErr) => { | ||
// if (!overlay) return | ||
// if (!overlayErr) return | ||
|
||
parentPort?.postMessage({ | ||
type: 'ERROR', | ||
payload: { | ||
type: 'error', | ||
err: overlayErr, | ||
}, | ||
}) | ||
} | ||
// parentPort?.postMessage({ | ||
// type: 'ERROR', | ||
// payload: { | ||
// type: 'error', | ||
// err: overlayErr, | ||
// }, | ||
// }) | ||
// } | ||
|
||
await diagnostics(workDir, 'WARN', { watch: true, errorCallback, verbose: false }) | ||
}, | ||
} | ||
} | ||
// await diagnostics(workDir, 'WARN', { watch: true, errorCallback, verbose: false }) | ||
// }, | ||
// } | ||
// } | ||
|
||
const { mainScript, workerScript } = createScript<{ vls: VlsConfig }>({ | ||
absFilename: __filename, | ||
buildBin: ['vite-plugin-checker-vls', ['diagnostics']], | ||
serverChecker: { createDiagnostic }, | ||
})! | ||
// const { mainScript, workerScript } = createScript<{ vls: VlsConfig }>({ | ||
// absFilename: __filename, | ||
// buildBin: ['vite-plugin-checker-vls', ['diagnostics']], | ||
// serverChecker: { createDiagnostic }, | ||
// })! | ||
|
||
if (isMainThread) { | ||
const configCurryFn = (vlsConfig: VlsConfig) => { | ||
return (sharedConfig: SharedConfig, env: ConfigEnv) => { | ||
const createChecker = mainScript() | ||
return createChecker({ vls: vlsConfig, ...sharedConfig }, env) | ||
} | ||
} | ||
// if (isMainThread) { | ||
// const configCurryFn = (vlsConfig: VlsConfig) => { | ||
// return (sharedConfig: SharedConfig, env: ConfigEnv) => { | ||
// const createChecker = mainScript() | ||
// return createChecker({ vls: vlsConfig, ...sharedConfig }, env) | ||
// } | ||
// } | ||
|
||
module.exports.VlsChecker = configCurryFn | ||
module.exports.createServeAndBuild = configCurryFn | ||
} else { | ||
workerScript() | ||
} | ||
// module.exports.VlsChecker = configCurryFn | ||
// module.exports.createServeAndBuild = configCurryFn | ||
// } else { | ||
// workerScript() | ||
// } | ||
|
||
type VlsConfig = Partial<{ | ||
// TODO: support VLS config | ||
}> | ||
// type VlsConfig = Partial<{ | ||
// // TODO: support VLS config | ||
// }> | ||
|
||
declare const VlsChecker: ( | ||
options?: VlsConfig | ||
) => (config: VlsConfig & SharedConfig) => ServeAndBuildChecker | ||
// declare const VlsChecker: ( | ||
// options?: VlsConfig | ||
// ) => (config: VlsConfig & SharedConfig) => ServeAndBuildChecker | ||
|
||
export { VlsChecker } | ||
export type { VlsConfig } | ||
// export { VlsChecker } | ||
// export type { VlsConfig } | ||
export {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
import { parentPort } from 'worker_threads' | ||
|
||
import { Checker, CheckerAbility } from '../../Checker' | ||
import { DiagnosticOptions, diagnostics } from './commands/diagnostics' | ||
|
||
import type { CreateDiagnostic } from '../../types' | ||
|
||
export const createDiagnostic: CreateDiagnostic = (userOptions = {}) => { | ||
let overlay = true // Vite defaults to true | ||
|
||
return { | ||
config: ({ hmr }) => { | ||
const viteOverlay = !(typeof hmr === 'object' && hmr.overlay === false) | ||
|
||
if (userOptions.overlay === false || !viteOverlay) { | ||
overlay = false | ||
} | ||
}, | ||
async configureServer({ root }) { | ||
const workDir: string = userOptions.root ?? root | ||
const errorCallback: DiagnosticOptions['errorCallback'] = (diagnostics, overlayErr) => { | ||
if (!overlay) return | ||
if (!overlayErr) return | ||
|
||
parentPort?.postMessage({ | ||
type: 'ERROR', | ||
payload: { | ||
type: 'error', | ||
err: overlayErr, | ||
}, | ||
}) | ||
} | ||
|
||
await diagnostics(workDir, 'WARN', { watch: true, errorCallback, verbose: false }) | ||
}, | ||
} | ||
} | ||
|
||
export class VlsChecker extends Checker implements CheckerAbility { | ||
public constructor() { | ||
super({ | ||
name: 'vls', | ||
absFilePath: __filename, | ||
buildBin: ['vite-plugin-checker-vls', ['diagnostics']], | ||
createDiagnostic, | ||
}) | ||
} | ||
|
||
public sealConclusion() {} | ||
|
||
public init() { | ||
const createServeAndBuild = super.initMainThread() | ||
module.exports.createServeAndBuild = createServeAndBuild | ||
|
||
super.initWorkerThread() | ||
} | ||
} | ||
|
||
const vlsChecker = new VlsChecker() | ||
vlsChecker.prepare() | ||
vlsChecker.init() |
Oops, something went wrong.