Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

vite-plugin-node

Package Overview
Dependencies
Maintainers
1
Versions
26
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

vite-plugin-node - npm Package Compare versions

Comparing version 0.0.19 to 1.0.0

15

dist/index.d.ts
/// <reference types="node" />
import { Options } from '@swc/core';
import http from 'http';
import { UserConfig, ViteDevServer } from 'vite';
import type http from 'http';
import type { Options } from '@swc/core';
import type { Connect, UserConfig, ViteDevServer } from 'vite';
export { RollupPluginSwc } from './rollup-plugin-swc';

@@ -9,3 +9,10 @@ export { VitePluginNode } from './vite-plugin-node';

export declare type SupportedFrameworks = 'express' | 'nest' | 'koa' | 'fastify' | 'marble';
export declare type RequestAdapter<App = any> = (app: App, req: http.IncomingMessage, res: http.ServerResponse, server: ViteDevServer) => void | Promise<void>;
export declare interface RequestAdapterParams<App> {
app: App;
server: ViteDevServer;
req: http.IncomingMessage;
res: http.ServerResponse;
next: Connect.NextFunction;
}
export declare type RequestAdapter<App = any> = (params: RequestAdapterParams<App>) => void | Promise<void>;
export declare type RequestAdapterOption = SupportedFrameworks | RequestAdapter;

@@ -12,0 +19,0 @@ export declare type SupportedTSCompiler = 'esbuild' | 'swc';

@@ -1,3 +0,3 @@

import { Options } from '@swc/core';
import { Plugin } from 'vite';
import type { Options } from '@swc/core';
import type { Plugin } from 'vite';
export declare function RollupPluginSwc(options: Options): Plugin;
"use strict";
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
var desc = Object.getOwnPropertyDescriptor(m, k);
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
desc = { enumerable: true, get: function() { return m[k]; } };
}
Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
o["default"] = v;
});
var __importStar = (this && this.__importStar) || function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
__setModuleDefault(result, mod);
return result;
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.RollupPluginSwc = void 0;
const pluginutils_1 = require("@rollup/pluginutils");
const core_1 = require("@swc/core");
const utils_1 = require("./utils");
function RollupPluginSwc(options) {
let swc;
// todo: load swc/tsconfig from config files
const config = {
// options from swc config
...options
...options,
};

@@ -18,12 +41,14 @@ const filter = (0, pluginutils_1.createFilter)(/\.(tsx?|jsx)$/, /\.js$/);

if (filter(id) || filter((0, utils_1.cleanUrl)(id))) {
const result = await (0, core_1.transform)(code, {
if (!swc)
swc = await Promise.resolve().then(() => __importStar(require('@swc/core')));
const result = await swc.transform(code, {
...config,
filename: id
filename: id,
});
return {
code: result.code,
map: result.map
map: result.map,
};
}
}
},
};

@@ -30,0 +55,0 @@ }

@@ -1,3 +0,3 @@

import { Application } from 'express';
import { RequestAdapter } from '..';
import type { Application } from 'express';
import type { RequestAdapter } from '..';
export declare const ExpressHandler: RequestAdapter<Application>;
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.ExpressHandler = void 0;
const ExpressHandler = (app, req, res) => {
const ExpressHandler = ({ app, req, res }) => {
app(req, res);

@@ -6,0 +6,0 @@ };

@@ -1,3 +0,3 @@

import { FastifyInstance } from 'fastify';
import { RequestAdapter } from '..';
import type { FastifyInstance } from 'fastify';
import type { RequestAdapter } from '..';
export declare const FastifyHandler: RequestAdapter<FastifyInstance>;
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.FastifyHandler = void 0;
const FastifyHandler = async (app, req, res) => {
const FastifyHandler = async ({ app, req, res }) => {
await app.ready();

@@ -6,0 +6,0 @@ app.routing(req, res);

/// <reference types="express" />
/// <reference types="koa" />
/// <reference types="node" />
import http from 'http';
import { Connect, ViteDevServer } from 'vite';
import { RequestAdapter, VitePluginNodeConfig } from '..';
import type http from 'http';
import type { Connect, ViteDevServer } from 'vite';
import type { RequestAdapter, VitePluginNodeConfig } from '..';
export declare const debugServer: (msg: string, ...args: any[]) => void;

@@ -8,0 +8,0 @@ export declare const SUPPORTED_FRAMEWORKS: {

@@ -7,4 +7,4 @@ "use strict";

exports.createMiddleware = exports.getPluginConfig = exports.SUPPORTED_FRAMEWORKS = exports.debugServer = void 0;
const process_1 = require("process");
const chalk_1 = __importDefault(require("chalk"));
const process_1 = require("process");
const __1 = require("..");

@@ -23,6 +23,6 @@ const utils_1 = require("../utils");

fastify: fastify_1.FastifyHandler,
marble: marble_1.MarbleHandler
marble: marble_1.MarbleHandler,
};
const getPluginConfig = (server) => {
const plugin = server.config.plugins.find((p) => p.name === __1.PLUGIN_NAME);
const plugin = server.config.plugins.find(p => p.name === __1.PLUGIN_NAME);
if (!plugin) {

@@ -52,3 +52,3 @@ console.error('Please setup VitePluginNode in your vite.config.js first');

}
return async function (req, res) {
return async function (req, res, next) {
const appModule = await server.ssrLoadModule(config.appPath);

@@ -63,3 +63,3 @@ let app = appModule[config.exportName];

app = await app;
await requestHandler(app, req, res, server);
await requestHandler({ app, server, req, res, next });
}

@@ -66,0 +66,0 @@ };

@@ -1,3 +0,3 @@

import Koa from 'koa';
import { RequestAdapter } from '..';
import type Koa from 'koa';
import type { RequestAdapter } from '..';
export declare const KoaHandler: RequestAdapter<Koa>;
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.KoaHandler = void 0;
const KoaHandler = (app, req, res) => {
const KoaHandler = ({ app, req, res }) => {
app.callback()(req, res);

@@ -6,0 +6,0 @@ };

@@ -1,5 +0,5 @@

import { RequestAdapter } from '..';
import { Context, ServerIO } from '@marblejs/core';
import { HttpListener, HttpServer } from '@marblejs/http';
import { Reader } from 'fp-ts/Reader';
import type { Context, ServerIO } from '@marblejs/core';
import type { HttpListener, HttpServer } from '@marblejs/http';
import type { Reader } from 'fp-ts/Reader';
import type { RequestAdapter } from '..';
export interface MarbleContext {

@@ -6,0 +6,0 @@ server: Promise<ServerIO<HttpServer>>;

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.MarbleHandler = void 0;
const MarbleHandler = async (app, req, res) => {
const MarbleHandler = async ({ app, req, res }) => {
const server = await app.server;

@@ -6,0 +6,0 @@ app.listener(server.context)(req, res);

import type { INestApplication } from '@nestjs/common';
import { RequestAdapter } from '..';
import type { RequestAdapter } from '..';
export declare const NestHandler: RequestAdapter<INestApplication>;
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.NestHandler = void 0;
const NestHandler = async (app, req, res) => {
const NestHandler = async ({ app, req, res }) => {
await app.init();

@@ -6,0 +6,0 @@ const instance = app.getHttpAdapter().getInstance();

@@ -27,13 +27,13 @@ "use strict";

function mergeDeep(target, source) {
let output = Object.assign({}, target);
const output = Object.assign({}, target);
if (isObject(target) && isObject(source)) {
Object.keys(source).forEach(key => {
// @ts-ignore
Object.keys(source).forEach((key) => {
// @ts-expect-error access unknow property
if (isObject(source[key])) {
if (!(key in target)) {
// @ts-ignore
// @ts-expect-error access unknow property
Object.assign(output, { [key]: source[key] });
}
else {
// @ts-ignore
// @ts-expect-error access unknow property
output[key] = mergeDeep(target[key], source[key]);

@@ -43,3 +43,3 @@ }

else {
// @ts-ignore
// @ts-expect-error access unknow property
Object.assign(output, { [key]: source[key] });

@@ -46,0 +46,0 @@ }

@@ -1,3 +0,3 @@

import { Plugin } from 'vite';
import { VitePluginNodeConfig } from '.';
import type { Plugin } from 'vite';
import type { VitePluginNodeConfig } from '.';
export declare function VitePluginNode(cfg: VitePluginNodeConfig): Plugin[];

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

exports.VitePluginNode = void 0;
const _1 = require(".");
const rollup_plugin_swc_1 = require("./rollup-plugin-swc");
const server_1 = require("./server");
const utils_1 = __importDefault(require("./utils"));
const _1 = require(".");
function VitePluginNode(cfg) {

@@ -22,9 +22,9 @@ var _a, _b, _c, _d;

syntax: 'typescript',
decorators: true
decorators: true,
},
transform: {
legacyDecorator: true,
decoratorMetadata: true
}
}
decoratorMetadata: true,
},
},
}, (_a = cfg.swcOptions) !== null && _a !== void 0 ? _a : {});

@@ -37,3 +37,3 @@ const config = {

exportName: (_d = cfg.exportName) !== null && _d !== void 0 ? _d : 'viteNodeApp',
swcOptions
swcOptions,
};

@@ -43,19 +43,30 @@ const plugins = [

name: _1.PLUGIN_NAME,
config: () => ({
build: {
ssr: config.appPath,
rollupOptions: {
input: config.appPath,
config: () => {
const plugincConfig = {
build: {
ssr: config.appPath,
rollupOptions: {
input: config.appPath,
},
},
},
server: {
hmr: false
},
esbuild: config.tsCompiler === 'esbuild' ? {} : false,
VitePluginNodeConfig: config
}),
server: {
hmr: false,
},
optimizeDeps: {
// Vite does not work well with optionnal dependencies,
// mark them as ignored for now
exclude: [
'@swc/core',
],
},
VitePluginNodeConfig: config,
};
if (config.tsCompiler === 'swc')
plugincConfig.esbuild = false;
return plugincConfig;
},
configureServer: (server) => {
server.middlewares.use((0, server_1.createMiddleware)(server));
}
}
},
},
];

@@ -62,0 +73,0 @@ if (config.tsCompiler === 'swc') {

{
"name": "vite-plugin-node",
"version": "0.0.19",
"version": "1.0.0",
"description": "Vite plugin to enable your node server HMR",

@@ -25,10 +25,2 @@ "author": "Axe",

],
"scripts": {
"build-dist": "tsc",
"build": "run-s prebuild build-dist",
"dev": "tsc -w --incremental",
"lint": "eslint --ext .ts src/**",
"format": "prettier --write .",
"prebuild": "rimraf dist && npm run lint"
},
"dependencies": {

@@ -41,3 +33,3 @@ "@rollup/pluginutils": "^4.1.1",

"@swc/core": "^1.2.153",
"vite": "^2.8.6"
"vite": "^2.9.8"
},

@@ -60,18 +52,19 @@ "peerDependenciesMeta": {

"@types/rx": "^4.1.2",
"@typescript-eslint/eslint-plugin": "^4.32.0",
"@typescript-eslint/parser": "^4.32.0",
"eslint": "^7.32.0",
"eslint-plugin-node": "^11.1.0",
"express": "^4.17.1",
"fastify": "^3.22.0",
"fp-ts": "^2.11.5",
"fp-ts": "^2.8.2",
"koa": "^2.13.3",
"npm-run-all": "^4.1.5",
"prettier": "^2.4.1",
"reflect-metadata": "^0.1.13",
"rimraf": "^3.0.2",
"rxjs": "^7.3.1",
"typescript": "^4.4.3",
"vite": "^2.8.6"
"rxjs": "^7.5.5",
"vite": "^2.9.8"
},
"scripts": {
"build-dist": "tsc",
"build": "run-s prebuild build-dist",
"dev": "tsc -w --incremental",
"lint": "eslint --ext .ts src/**",
"format": "prettier --write .",
"prebuild": "rimraf dist && npm run lint"
}
}

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

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