Socket
Socket
Sign inDemoInstall

vite-plugin-checker

Package Overview
Dependencies
Maintainers
1
Versions
60
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

vite-plugin-checker - npm Package Compare versions

Comparing version 0.1.0 to 0.2.0-beta.0

28

CHANGELOG.md

@@ -0,1 +1,29 @@

# 0.2.0-beta.0 (2021-06-30)
### Bug Fixes
* clean dead logic ([f88fd86](https://github.com/fi3ework/vite-plugin-checker/commit/f88fd866503ecc7fbe2ed6e16e7aaa9a14e0ce84))
* kill worker in build mode ([e7810f0](https://github.com/fi3ework/vite-plugin-checker/commit/e7810f0f76ffa6963e26cd8d51f981e6678ab841))
* make enableBuild works ([556db26](https://github.com/fi3ework/vite-plugin-checker/commit/556db26ab0ccde3a95bf7b29d1a40048829afce9))
* worker forever hang ([b5e159f](https://github.com/fi3ework/vite-plugin-checker/commit/b5e159f35bc093c66bb5724eadfede55e368d1c3))
### Features
* support arbitrary key for custom check ([#12](https://github.com/fi3ework/vite-plugin-checker/issues/12)) ([fc14b05](https://github.com/fi3ework/vite-plugin-checker/commit/fc14b05ce1c29e3ac84352397732f89e19c31a85))
# 0.1.0 (2021-06-14)
### Bug Fixes
* checker uses config right ([293f261](https://github.com/fi3ework/vite-plugin-checker/commit/293f2611b80556b7a4c2304cea7dee6a0651ba15))
* clean previous console ([fa47e77](https://github.com/fi3ework/vite-plugin-checker/commit/fa47e7707421f5a90d8bdcf871160bd5632e040c))
* support spawn in Windows ([5322714](https://github.com/fi3ework/vite-plugin-checker/commit/53227147b07284ac335123750c75ea5b6519d85a))
# Changelog

@@ -2,0 +30,0 @@

7

lib/codeFrame.d.ts
import ts from 'typescript';
export declare function createFrame({ source, start, end, }: {
import { SourceLocation } from '@babel/code-frame';
export declare function createFrame({ source, location, }: {
source: string;
start: ts.LineAndCharacter;
end: ts.LineAndCharacter;
location: SourceLocation;
}): string;
export declare function tsLocationToBabelLocation(tsLoc: Record<'start' | 'end', ts.LineAndCharacter /** 0-based */>): SourceLocation;
//# sourceMappingURL=codeFrame.d.ts.map

@@ -6,10 +6,7 @@ "use strict";

Object.defineProperty(exports, "__esModule", { value: true });
exports.createFrame = void 0;
exports.tsLocationToBabelLocation = exports.createFrame = void 0;
const os_1 = __importDefault(require("os"));
const code_frame_1 = require("@babel/code-frame");
function createFrame({ source, start, end, }) {
const frame = code_frame_1.codeFrameColumns(source, {
start: { line: start.line + 1, column: start.character + 1 },
end: { line: end.line + 1, column: end.character + 1 },
}, {
function createFrame({ source, location, }) {
const frame = code_frame_1.codeFrameColumns(source, location, {
highlightCode: true,

@@ -23,1 +20,8 @@ })

exports.createFrame = createFrame;
function tsLocationToBabelLocation(tsLoc) {
return {
start: { line: tsLoc.start.line + 1, column: tsLoc.start.character + 1 },
end: { line: tsLoc.end.line + 1, column: tsLoc.end.character + 1 },
};
}
exports.tsLocationToBabelLocation = tsLocationToBabelLocation;
import { Plugin } from 'vite';
import { UserPluginConfig } from './types';
import type { UserPluginConfig } from './types';
export * from './types';

@@ -4,0 +4,0 @@ export * from './codeFrame';

@@ -12,13 +12,2 @@ "use strict";

};
var __rest = (this && this.__rest) || function (s, e) {
var t = {};
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
t[p] = s[p];
if (s != null && typeof Object.getOwnPropertySymbols === "function")
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
t[p[i]] = s[p[i]];
}
return t;
};
var __importDefault = (this && this.__importDefault) || function (mod) {

@@ -29,4 +18,7 @@ return (mod && mod.__esModule) ? mod : { "default": mod };

const child_process_1 = require("child_process");
const lodash_omit_1 = __importDefault(require("lodash.omit"));
const lodash_pick_1 = __importDefault(require("lodash.pick"));
const npm_run_path_1 = __importDefault(require("npm-run-path"));
const os_1 = __importDefault(require("os"));
const tiny_invariant_1 = __importDefault(require("tiny-invariant"));
__exportStar(require("./types"), exports);

@@ -36,9 +28,13 @@ __exportStar(require("./codeFrame"), exports);

__exportStar(require("./worker"), exports);
function createCheckers(userConfig) {
const sharedConfigKeys = ['enableBuild', 'overlay'];
const buildInCheckerKeys = ['typescript', 'vueTsc'];
function createCheckers(userConfig, env) {
const { typescript, vueTsc } = userConfig;
const serveAndBuildCheckers = [];
const { typescript, vueTsc, vls: vlsCurry } = userConfig, sharedConfig = __rest(userConfig, ["typescript", "vueTsc", "vls"]);
const sharedConfig = lodash_pick_1.default(userConfig, sharedConfigKeys);
const customCheckers = lodash_omit_1.default(userConfig, [...sharedConfigKeys, ...buildInCheckerKeys]);
if (typescript) {
// eslint-disable-next-line @typescript-eslint/no-require-imports
const { createServeAndBuild } = require('./checkers/tsc');
serveAndBuildCheckers.push(createServeAndBuild(Object.assign({ typescript }, sharedConfig)));
serveAndBuildCheckers.push(createServeAndBuild(Object.assign({ typescript }, sharedConfig), env));
}

@@ -48,7 +44,9 @@ if (vueTsc) {

const { createServeAndBuild } = require('./checkers/vue-tsc');
serveAndBuildCheckers.push(createServeAndBuild(Object.assign({ vueTsc }, sharedConfig)));
serveAndBuildCheckers.push(createServeAndBuild(Object.assign({ vueTsc }, sharedConfig), env));
}
if (vlsCurry) {
serveAndBuildCheckers.push(vlsCurry(sharedConfig));
}
Object.keys(customCheckers).forEach((key) => {
const checkerCurryFn = customCheckers[key];
tiny_invariant_1.default(typeof checkerCurryFn === 'function', `Custom checker key should be a function, but got ${typeof checkerCurryFn}`);
serveAndBuildCheckers.push(checkerCurryFn(sharedConfig, env));
});
return serveAndBuildCheckers;

@@ -58,3 +56,4 @@ }

var _a;
const checkers = createCheckers(userConfig || {});
let checkers = [];
// const checkers = createCheckers(userConfig || {})
const enableBuild = (_a = userConfig === null || userConfig === void 0 ? void 0 : userConfig.enableBuild) !== null && _a !== void 0 ? _a : true;

@@ -68,2 +67,3 @@ let viteMode;

viteMode = env.command;
checkers = createCheckers(userConfig || {}, env);
if (viteMode !== 'serve')

@@ -82,5 +82,8 @@ return;

// for build mode
// Run a bin command in a separated process
// run a bin command in a separated process
if (viteMode !== 'build')
return;
// do not do anything when disable build mode
if (!enableBuild)
return;
const localEnv = npm_run_path_1.default.env({

@@ -99,9 +102,7 @@ env: process.env,

});
if (enableBuild) {
proc.on('exit', (code) => {
if (code !== null && code !== 0) {
process.exit(code);
}
});
}
proc.on('exit', (code) => {
if (code !== null && code !== 0) {
process.exit(code);
}
});
});

@@ -108,0 +109,0 @@ },

@@ -27,13 +27,18 @@ /// <reference types="node" />

}
export interface PluginConfig extends SharedConfig {
export declare type CustomChecker = (checkerConfig: any, env: ConfigEnv) => ServeAndBuildChecker;
export interface CustomCheckers {
[k: string]: CustomChecker | boolean;
}
export interface BuildInCheckers {
typescript: TscConfig;
vueTsc: VueTscConfig;
vls: (vlsConfig: any) => ServeAndBuildChecker;
}
export declare type PluginConfig = SharedConfig & CustomCheckers & BuildInCheckers;
/** Userland plugin configuration */
export declare type UserPluginConfig = Partial<PluginConfig>;
export declare enum ACTION_TYPES {
config = "config",
configureServer = "configureServer",
overlayError = "overlayError",
config = "config",
configureServer = "configureServer"
unref = "unref"
}

@@ -60,3 +65,6 @@ interface Action {

}
export declare type Actions = OverlayErrorAction | ConfigAction | ConfigureServerAction;
export interface UnrefAction extends Action {
type: ACTION_TYPES.unref;
}
export declare type Actions = OverlayErrorAction | ConfigAction | ConfigureServerAction | UnrefAction;
export declare type BuildCheckBin = [string, ReadonlyArray<string>];

@@ -63,0 +71,0 @@ export interface ConfigureServeChecker {

@@ -7,5 +7,6 @@ "use strict";

(function (ACTION_TYPES) {
ACTION_TYPES["overlayError"] = "overlayError";
ACTION_TYPES["config"] = "config";
ACTION_TYPES["configureServer"] = "configureServer";
ACTION_TYPES["overlayError"] = "overlayError";
ACTION_TYPES["unref"] = "unref";
})(ACTION_TYPES = exports.ACTION_TYPES || (exports.ACTION_TYPES = {}));
import ts from 'typescript';
import { ErrorPayload } from 'vite';
import { SourceLocation } from '@babel/code-frame';
import type { Range } from 'vscode-languageclient';
import type { PublishDiagnosticsParams } from 'vscode-languageclient/node';
import { SourceLocation } from '@babel/code-frame';
/**

@@ -7,0 +7,0 @@ * TypeScript utils

@@ -40,4 +40,6 @@ "use strict";

source: d.file.text,
start: (_c = d.file) === null || _c === void 0 ? void 0 : _c.getLineAndCharacterOfPosition(d.start),
end: (_d = d.file) === null || _d === void 0 ? void 0 : _d.getLineAndCharacterOfPosition(d.start + d.length),
location: codeFrame_1.tsLocationToBabelLocation({
start: (_c = d.file) === null || _c === void 0 ? void 0 : _c.getLineAndCharacterOfPosition(d.start),
end: (_d = d.file) === null || _d === void 0 ? void 0 : _d.getLineAndCharacterOfPosition(d.start + d.length),
}),
})),

@@ -44,0 +46,0 @@ stack: '',

@@ -0,1 +1,2 @@

import { ConfigEnv } from 'vite';
import type { ServeChecker, BuildCheckBin, ServeAndBuildChecker, SharedConfig } from './types';

@@ -8,3 +9,3 @@ interface WorkerScriptOptions {

interface Script<T> {
mainScript: () => (config: T & SharedConfig) => ServeAndBuildChecker;
mainScript: () => (config: T & SharedConfig, env: ConfigEnv) => ServeAndBuildChecker;
workerScript: () => void;

@@ -11,0 +12,0 @@ }

@@ -10,5 +10,6 @@ "use strict";

// initialized in main thread
const createWorker = (checkerConfig) => {
const createWorker = (checkerConfig, env) => {
const isBuild = env.command === 'build';
const worker = new worker_threads_1.Worker(absFilename, {
workerData: checkerConfig,
workerData: { env, checkerConfig },
});

@@ -19,2 +20,4 @@ // eslint-disable-next-line @typescript-eslint/consistent-type-assertions

config: (config) => {
if (isBuild)
return; // just run the command
const configAction = { type: types_1.ACTION_TYPES.config, payload: config };

@@ -32,4 +35,4 @@ worker.postMessage(configAction);

};
return (config) => ({
serve: createWorker(config),
return (config, env) => ({
serve: createWorker(config, env),
build: { buildBin },

@@ -43,15 +46,25 @@ });

throw Error('should have parentPort as file runs in worker thread');
worker_threads_1.parentPort.on('message', (action) => {
if (action.type === types_1.ACTION_TYPES.config) {
// const checker = checkerFactory()
const checkerConfig = worker_threads_1.workerData;
diagnostic = serverChecker.createDiagnostic(checkerConfig);
diagnostic.config(action.payload);
const isBuild = worker_threads_1.workerData.env.command === 'build';
// only run bin command and do not listen message in build mode
const port = worker_threads_1.parentPort.on('message', (action) => {
switch (action.type) {
case types_1.ACTION_TYPES.config: {
const checkerConfig = worker_threads_1.workerData.checkerConfig;
diagnostic = serverChecker.createDiagnostic(checkerConfig);
diagnostic.config(action.payload);
break;
}
case types_1.ACTION_TYPES.configureServer:
if (!diagnostic)
throw Error('diagnostic should be initialized in `config` hook of Vite');
diagnostic.configureServer(action.payload);
break;
case types_1.ACTION_TYPES.unref:
port.unref();
break;
}
else if (action.type === types_1.ACTION_TYPES.configureServer) {
if (!diagnostic)
throw Error('diagnostic should be initialized in `config` hook of Vite');
diagnostic.configureServer(action.payload);
}
});
if (isBuild) {
port.unref();
}
},

@@ -58,0 +71,0 @@ };

{
"name": "vite-plugin-checker",
"version": "0.1.0",
"version": "0.2.0-beta.0",
"description": "Vite plugin that runs TypeScript type checker on a separate process.",

@@ -25,2 +25,6 @@ "main": "lib/main.js",

"@babel/code-frame": "^7.12.13",
"@types/lodash.omit": "^4.5.6",
"@types/lodash.pick": "^4.4.6",
"lodash.omit": "^4.5.0",
"lodash.pick": "^4.4.0",
"log-update": "^4.0.0",

@@ -36,5 +40,8 @@ "npm-run-path": "^4.0.1",

"scripts": {
"dev": "tsc --watch",
"build": "tsc"
"dev": "tsc -p tsconfig.build.json --watch",
"build": "tsc -p tsconfig.build.json",
"build:test": "tsc -p tsconfig.test.json",
"changelog": "conventional-changelog -p angular -i CHANGELOG.md -s --commit-path . --lerna-package vite-plugin-checker",
"release": "zx ../../scripts/release.mjs"
}
}

@@ -5,2 +5,5 @@ # vite-plugin-checker

[![npm version](https://img.shields.io/npm/v/vite-plugin-checker)](https://www.npmjs.com/package/vite-plugin-checker) [![downloads/month](https://img.shields.io/npm/dm/vite-plugin-checker)](https://www.npmtrends.com/vite-plugin-checker) [![Unit Test](https://github.com/fi3ework/vite-plugin-checker/actions/workflows/ci.yml/badge.svg)](https://github.com/fi3ework/vite-plugin-checker/actions/workflows/ci.yml)
[![codecov](https://codecov.io/gh/fi3ework/vite-plugin-checker/branch/main/graph/badge.svg?token=YCU4HJ66RA)](https://codecov.io/gh/fi3ework/vite-plugin-checker)
## Features

@@ -155,5 +158,5 @@

## Examples
## Playground
Run projects in [`examples/*`](./examples) to try it out.
Run projects in [`playground/*`](./playground) to try it out.

@@ -163,3 +166,3 @@ ```bash

npm run build
cd ./examples/<ONE_EXAMPLE> # react / vls / vue-tsc
cd ./playground/<ONE_EXAMPLE> # react / vls / vue-tsc
npm run dev # for development

@@ -166,0 +169,0 @@ npm run build # for build

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc