Skip to content

Commit

Permalink
feat: update bundle-import to close https://github.com/condorheroblog…
Browse files Browse the repository at this point in the history
  • Loading branch information
condorheroblog committed Nov 7, 2024
1 parent c981a3a commit 7ae65f7
Show file tree
Hide file tree
Showing 33 changed files with 1,714 additions and 1,317 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,10 @@ export default defineConfig({
You can create a new file in the **`fake`** folder in the directory where the Vite configuration file is located, such as `user.fake.ts`:

```ts
import { faker } from "@faker-js/faker";
// fake/user.fake.ts
import Mock from "mockjs";
import { defineFakeRoute } from "vite-plugin-fake-server/client";
import { faker } from "@faker-js/faker";

export default defineFakeRoute([
{
Expand Down
20 changes: 10 additions & 10 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"type": "module",
"version": "2.1.2",
"private": true,
"packageManager": "pnpm@9.9.0",
"packageManager": "pnpm@9.12.3",
"description": "A fake server plugin for Vite.",
"author": "Condor Hero",
"license": "MIT",
Expand All @@ -28,22 +28,22 @@
"release": "bumpp -r && pnpm -r publish --access public"
},
"devDependencies": {
"@antfu/eslint-config": "^3.0.0",
"@antfu/eslint-config": "^3.8.0",
"@rollup/plugin-json": "^6.1.0",
"@types/node": "^22.5.2",
"bumpp": "^9.5.2",
"esbuild": "^0.23.1",
"eslint": "^9.9.1",
"esno": "^4.7.0",
"@types/node": "^22.9.0",
"bumpp": "^9.8.1",
"esbuild": "^0.24.0",
"eslint": "^9.14.0",
"esno": "^4.8.0",
"lint-staged": "^15.2.10",
"rimraf": "^5.0.10",
"rollup": "^4.21.2",
"rollup": "^4.24.4",
"rollup-plugin-dts": "^6.1.1",
"rollup-plugin-esbuild": "^6.1.1",
"rollup-plugin-node-externals": "^7.1.3",
"simple-git-hooks": "^2.11.1",
"typescript": "^5.5.4",
"vitest": "^2.0.5"
"typescript": "^5.6.3",
"vitest": "^2.1.4"
},
"simple-git-hooks": {
"pre-commit": "npx lint-staged"
Expand Down
10 changes: 5 additions & 5 deletions packages/playground/http2-sample/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,14 @@
"preview": "vite preview"
},
"dependencies": {
"vue": "^3.4.38"
"vue": "^3.5.12"
},
"devDependencies": {
"@vitejs/plugin-basic-ssl": "^1.1.0",
"@vitejs/plugin-vue": "^5.1.3",
"typescript": "^5.5.4",
"vite": "^5.4.2",
"@vitejs/plugin-vue": "^5.1.4",
"typescript": "^5.6.3",
"vite": "^5.4.10",
"vite-plugin-fake-server": "workspace:^",
"vue-tsc": "^2.1.4"
"vue-tsc": "^2.1.10"
}
}
2 changes: 1 addition & 1 deletion packages/playground/http2-sample/vite.config.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import basicSSL from "@vitejs/plugin-basic-ssl";
import vue from "@vitejs/plugin-vue";
import { defineConfig } from "vite";
import { vitePluginFakeServer } from "vite-plugin-fake-server";
import basicSSL from "@vitejs/plugin-basic-ssl";

// https://vitejs.dev/config/
export default defineConfig({
Expand Down
18 changes: 9 additions & 9 deletions packages/playground/react-sample/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,20 +15,20 @@
"dependencies": {
"react": "^18.3.1",
"react-dom": "^18.3.1",
"react-router-dom": "^6.26.1"
"react-router-dom": "^6.28.0"
},
"devDependencies": {
"@faker-js/faker": "^8.4.1",
"@faker-js/faker": "^9.2.0",
"@types/mockjs": "^1.0.10",
"@types/react": "^18.3.5",
"@types/react-dom": "^18.3.0",
"@vitejs/plugin-react": "^4.3.1",
"@types/react": "^18.3.12",
"@types/react-dom": "^18.3.1",
"@vitejs/plugin-react": "^4.3.3",
"autoprefixer": "^10.4.20",
"mockjs": "^ 1.1.0",
"postcss": "^8.4.44",
"tailwindcss": "^3.4.10",
"typescript": "^5.5.4",
"vite": "^5.4.2",
"postcss": "^8.4.47",
"tailwindcss": "^3.4.14",
"typescript": "^5.6.3",
"vite": "^5.4.10",
"vite-plugin-fake-server": "workspace:^"
}
}
8 changes: 4 additions & 4 deletions packages/playground/react-sample/src/components/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
export * from "./the-head";
export * from "./the-nav";
export * from "./404";
export * from "./switch-appearance";
export * from "./the-card";
export * from "./the-head";
export * from "./the-loading";
export * from "./switch-appearance";
export * from "./404";
export * from "./the-nav";
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { useEffect, useState } from "react";
import type { BUTTON_LIST } from "#src/components";

import { REQUEST_TYPE, TheLoading } from "#src/components";
import type { BUTTON_LIST } from "#src/components";
import { useEffect, useState } from "react";

function getType(value: unknown) {
return Object.prototype.toString.call(value).slice(8, -1);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { useNavigate } from "react-router-dom";

import { version } from "#/package.json";

import { SwitchAppearance } from "#src/components";
import { useNavigate } from "react-router-dom";

export function TheHead() {
const navigate = useNavigate();
Expand Down
4 changes: 2 additions & 2 deletions packages/playground/react-sample/src/hooks/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
export * from "./_configurable";
export * from "./useSupported";
export * from "./useColorMode";
export * from "./useMediaQuery";
export * from "./usePreferredDark";
export * from "./useColorMode";
export * from "./useSupported";
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { useCallback, useSyncExternalStore } from "react";
import type { ConfigurableWindow } from "../_configurable";

import { useSupported } from "../useSupported";
import { useCallback, useSyncExternalStore } from "react";
import { defaultWindow } from "../_configurable";
import type { ConfigurableWindow } from "../_configurable";
import { useSupported } from "../useSupported";

function getMediaSnapshot(query: string) {
return window.matchMedia(query).matches;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { useMediaQuery } from "../useMediaQuery";
import type { ConfigurableWindow } from "../_configurable";
import { useMediaQuery } from "../useMediaQuery";

export function usePreferredDark(options?: ConfigurableWindow) {
return useMediaQuery("(prefers-color-scheme: dark)", options);
Expand Down
2 changes: 1 addition & 1 deletion packages/playground/react-sample/src/main.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ import React from "react";
import ReactDOM from "react-dom/client";
import { RouterProvider } from "react-router-dom";

import "./styles/tailwind.css";
import { router } from "./router";
import "./styles/tailwind.css";

ReactDOM.createRoot(document.getElementById("root")!).render(
<React.StrictMode>
Expand Down
4 changes: 2 additions & 2 deletions packages/playground/react-sample/src/views/App.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { useLocation } from "react-router-dom";

import { BUTTON_LIST, TheCard, TheHead, TheNav } from "#src/components";

import { useLocation } from "react-router-dom";

function App() {
const location = useLocation();
const option = BUTTON_LIST.find(({ type, value }) => {
Expand Down
4 changes: 2 additions & 2 deletions packages/playground/vue-sample/fake/index.fake.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { defineFakeRoute } from "vite-plugin-fake-server/client";

import response from "@/response";

import { defineFakeRoute } from "vite-plugin-fake-server/client";

export default defineFakeRoute([
{
url: "/api/hello",
Expand Down
10 changes: 5 additions & 5 deletions packages/playground/vue-sample/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,13 @@
"preview": "vite preview"
},
"dependencies": {
"vue": "^3.4.38"
"vue": "^3.5.12"
},
"devDependencies": {
"@vitejs/plugin-vue": "^5.1.3",
"typescript": "^5.5.4",
"vite": "^5.4.2",
"@vitejs/plugin-vue": "^5.1.4",
"typescript": "^5.6.3",
"vite": "^5.4.10",
"vite-plugin-fake-server": "workspace:^",
"vue-tsc": "^2.1.4"
"vue-tsc": "^2.1.10"
}
}
2 changes: 1 addition & 1 deletion packages/vite-plugin-fake-server/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,10 @@ export default defineConfig({
You can create a new file in the **`fake`** folder in the directory where the Vite configuration file is located, such as `user.fake.ts`:

```ts
import { faker } from "@faker-js/faker";
// fake/user.fake.ts
import Mock from "mockjs";
import { defineFakeRoute } from "vite-plugin-fake-server/client";
import { faker } from "@faker-js/faker";

export default defineFakeRoute([
{
Expand Down
10 changes: 5 additions & 5 deletions packages/vite-plugin-fake-server/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -55,14 +55,14 @@
"typecheck": "tsc --noEmit"
},
"dependencies": {
"bundle-import": "^0.0.1",
"chokidar": "^3.6.0",
"bundle-import": "^0.0.2",
"chokidar": "^4.0.1",
"fast-glob": "^3.3.2",
"path-to-regexp": "^8.0.0",
"picocolors": "^1.0.1"
"path-to-regexp": "^8.2.0",
"picocolors": "^1.1.1"
},
"devDependencies": {
"vite": "^5.4.2"
"vite": "^5.4.10"
},
"publishConfig": {
"access": "public",
Expand Down
12 changes: 6 additions & 6 deletions packages/vite-plugin-fake-server/src/FakeFileLoader.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
import EventEmitter from "node:events";
import type { DependenciesType } from "bundle-import";
import type { FSWatcher } from "node:fs";
import type { FakeRoute } from "./node";

import type { ResolvePluginOptionsType } from "./resolvePluginOptions";
import type { Logger } from "./utils";
import EventEmitter from "node:events";
import { join, relative } from "node:path";

import { bundleImport } from "bundle-import";
import type { DependenciesType } from "bundle-import";
import chokidar from "chokidar";
import colors from "picocolors";

import { getFakeFilePath, parallelLoader } from "./node";
import type { FakeRoute } from "./node";
import type { ResolvePluginOptionsType } from "./resolvePluginOptions";
import type { Logger } from "./utils";
import { convertPathToPosix } from "./utils";

export interface FakeFileLoaderOptions extends ResolvePluginOptionsType {
Expand Down
14 changes: 7 additions & 7 deletions packages/vite-plugin-fake-server/src/build.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
/* eslint-disable no-console */
import process from "node:process";
import type { ResolvedConfig } from "vite";
import type { ResolvePluginOptionsType } from "./resolvePluginOptions";
import type { ServerBuildOptions } from "./types";
import { existsSync } from "node:fs";

import { copyFile, mkdir, readdir, stat, writeFile } from "node:fs/promises";
import { extname, join } from "node:path";

import pc from "picocolors";
import type { ResolvedConfig } from "vite";
/* eslint-disable no-console */
import process from "node:process";

import pc from "picocolors";
import { name, version } from "../package.json";

import type { ServerBuildOptions } from "./types";
import type { ResolvePluginOptionsType } from "./resolvePluginOptions";
import { FAKE_FILE_EXTENSIONS } from "./node";

export const PORT = 8888;
Expand Down
8 changes: 4 additions & 4 deletions packages/vite-plugin-fake-server/src/createFakeMiddleware.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import type { Server } from "node:http";
import type { Http2SecureServer } from "node:http2";

import { match } from "path-to-regexp";
import colors from "picocolors";
import type { Connect } from "vite";
import type { ResolvePluginOptionsType } from "./resolvePluginOptions";
import type { Logger } from "./utils";

import { match } from "path-to-regexp";
import colors from "picocolors";
import { FakeFileLoader } from "./FakeFileLoader";
import { simulateServerResponse, tryToJSON } from "./shared";
import type { ResolvePluginOptionsType } from "./resolvePluginOptions";
import type { Logger } from "./utils";
import { getRequestData, isFunction } from "./utils";

export interface CreateFakeMiddlewareOptions extends ResolvePluginOptionsType {
Expand Down
16 changes: 8 additions & 8 deletions packages/vite-plugin-fake-server/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
export * from "./types";
export { version } from "../package.json";
export * from "./build";
export * from "./client";
export * from "./createFakeMiddleware";
export * from "./FakeFileLoader";
export * from "./node";
export * from "./plugin";
export * from "./utils";
export * from "./resolvePluginOptions";
export * from "./node";
export * from "./client";
export * from "./build";
export * from "./shared";
export * from "./FakeFileLoader";
export * from "./createFakeMiddleware";
export { version } from "../package.json";
export * from "./types";
export * from "./utils";
4 changes: 2 additions & 2 deletions packages/vite-plugin-fake-server/src/node/getFakeFilePath.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import type { ResolveOptionsType } from "./resolveOptions";
import { existsSync, statSync } from "node:fs";
import { extname, join } from "node:path";

import process from "node:process";

import fg from "fast-glob";

import { convertPathToPosix } from "../utils";

import type { ResolveOptionsType } from "./resolveOptions";

export function getFakeFilePath(options: ResolveOptionsType, cwd = process.cwd()) {
const { include, exclude, extensions, infixName } = options;
if (!Array.isArray(include) || include.length === 0) {
Expand Down
4 changes: 2 additions & 2 deletions packages/vite-plugin-fake-server/src/node/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
export * from "./resolveOptions";
export * from "./constants";
export * from "./getFakeFilePath";
export * from "./parallelLoader";
export * from "./constants";
export * from "./resolveOptions";
export * from "./types";
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { FAKE_FILE_EXTENSIONS, INFIX_NAME } from "./constants";
import type { FakerSchemaServerOptions } from "./types";
import { FAKE_FILE_EXTENSIONS, INFIX_NAME } from "./constants";

export function resolveOptions(options: FakerSchemaServerOptions = {}) {
const include = options.include ?? [INFIX_NAME];
Expand Down
14 changes: 7 additions & 7 deletions packages/vite-plugin-fake-server/src/plugin.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
import process from "node:process";
import { isAbsolute, join, relative } from "node:path";
import type { HtmlTagDescriptor, Plugin, ResolvedConfig, WatchOptions } from "vite";
import type { ResolvePluginOptionsType } from "./resolvePluginOptions";
import type { VitePluginFakeServerOptions } from "./types";

import { STATUS_CODES } from "node:http";

import type { HtmlTagDescriptor, Plugin, ResolvedConfig, WatchOptions } from "vite";
import { isAbsolute, join, relative } from "node:path";

import process from "node:process";
import pkg from "../package.json";

import { generateFakeServer } from "./build";
import { createFakeMiddleware } from "./createFakeMiddleware";
import { simulateServerResponse, sleep, tryToJSON } from "./shared";
import { getFakeFilePath } from "./node";
import { resolvePluginOptions } from "./resolvePluginOptions";
import type { ResolvePluginOptionsType } from "./resolvePluginOptions";
import type { VitePluginFakeServerOptions } from "./types";
import { simulateServerResponse, sleep, tryToJSON } from "./shared";
import { buildPackage, convertPathToPosix, createLogger } from "./utils";
import { xhook } from "./xhook/index.mjs";

Expand Down
Loading

0 comments on commit 7ae65f7

Please sign in to comment.