minista 2.2.1 → 2.3.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/build.js CHANGED
@@ -33,10 +33,12 @@ import { slashEnd } from "./utils.js";
33
33
  const __filename = url.fileURLToPath(import.meta.url);
34
34
  const __dirname = path.dirname(__filename);
35
35
  async function buildTempPages(entryPoints, buildOptions) {
36
- const ministaPkgURL = new URL(path.resolve(__dirname + "/../package.json"), import.meta.url);
37
- const ministaPkg = JSON.parse(fs.readFileSync(ministaPkgURL, "utf8"));
38
- const userPkgURL = new URL(path.resolve("package.json"), import.meta.url);
39
- const userPkg = JSON.parse(fs.readFileSync(userPkgURL, "utf8"));
36
+ const ministaPkgUrl = path.resolve(__dirname + "/../package.json");
37
+ const ministaPkgUrlRelative = path.relative(".", ministaPkgUrl);
38
+ const ministaPkg = JSON.parse(fs.readFileSync(ministaPkgUrlRelative, "utf8"));
39
+ const userPkgPath = path.resolve("package.json");
40
+ const userPkgFilePath = path.relative(process.cwd(), userPkgPath);
41
+ const userPkg = JSON.parse(fs.readFileSync(userPkgFilePath, "utf8"));
40
42
  const esbuildExternal = [
41
43
  ...Object.keys(ministaPkg.dependencies || {}),
42
44
  ...Object.keys(ministaPkg.devDependencies || {}),
@@ -73,10 +75,11 @@ async function buildTempPages(entryPoints, buildOptions) {
73
75
  }
74
76
  async function buildStaticPages(entryPoints, tempRootFilePath, buildOptions, assetsTagStr) {
75
77
  const rootStaticContent = await buildRootEsmContent(tempRootFilePath);
78
+ const winOutBase = buildOptions.outBase.replaceAll("/", "\\");
76
79
  await Promise.all(entryPoints.map(async (entryPoint) => {
77
80
  const extname = path.extname(entryPoint);
78
81
  const basename = path.basename(entryPoint, extname);
79
- const dirname = path.dirname(entryPoint).replace(buildOptions.outBase, buildOptions.outDir);
82
+ const dirname = path.dirname(entryPoint).replace(buildOptions.outBase, buildOptions.outDir).replace(winOutBase, buildOptions.outDir);
80
83
  const filename = path.join(dirname, basename + ".html");
81
84
  await buildStaticPage(entryPoint, filename, rootStaticContent, assetsTagStr, buildOptions.outDir);
82
85
  }));
@@ -89,7 +92,8 @@ async function buildRootEsmContent(tempRootFilePath) {
89
92
  if (!tempRootFilePath) {
90
93
  return defaultRootEsmContent;
91
94
  } else {
92
- const rootEsmContent = await import(tempRootFilePath);
95
+ const targetFilePath = url.pathToFileURL(tempRootFilePath).href;
96
+ const rootEsmContent = await import(targetFilePath);
93
97
  const rootJsxContent = rootEsmContent.default ? rootEsmContent.default : Fragment;
94
98
  const staticData = rootEsmContent.getStaticData ? await buildGlobalStaticData(rootEsmContent.getStaticData) : { props: {} };
95
99
  return { component: rootJsxContent, staticData };
@@ -100,7 +104,8 @@ async function buildGlobalStaticData(getGlobalStaticData) {
100
104
  return response;
101
105
  }
102
106
  async function buildStaticPage(entryPoint, outFile, rootStaticContent, assetsTagStr, outDir) {
103
- const pageEsmContent = await import(path.resolve(entryPoint));
107
+ const targetFilePath = url.pathToFileURL(entryPoint).href;
108
+ const pageEsmContent = await import(targetFilePath);
104
109
  const pageJsxContent = pageEsmContent.default;
105
110
  const frontmatter = pageEsmContent.frontmatter ? pageEsmContent.frontmatter : void 0;
106
111
  const defaultStaticDataItem = { props: {}, paths: {} };
@@ -217,8 +222,9 @@ async function buildTempAssets(viteConfig, buildOptions) {
217
222
  }
218
223
  }
219
224
  async function buildAssetsTagStr(entryPoints, buildOptions) {
225
+ const winOutBase = buildOptions.outBase.replaceAll("/", "\\");
220
226
  const assetsTags = entryPoints.map((entryPoint) => {
221
- const assetPath = entryPoint.replace(buildOptions.outBase, buildOptions.outDir);
227
+ const assetPath = entryPoint.replace(buildOptions.outBase, buildOptions.outDir).replace(winOutBase, buildOptions.outDir).replaceAll("\\", "/");
222
228
  if (assetPath.endsWith(".css")) {
223
229
  return `<link rel="stylesheet" href="${assetPath}">`;
224
230
  } else if (assetPath.endsWith(".js")) {
package/dist/cli.js CHANGED
@@ -1,3 +1,19 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __getOwnPropSymbols = Object.getOwnPropertySymbols;
3
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
4
+ var __propIsEnum = Object.prototype.propertyIsEnumerable;
5
+ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
6
+ var __spreadValues = (a, b) => {
7
+ for (var prop in b || (b = {}))
8
+ if (__hasOwnProp.call(b, prop))
9
+ __defNormalProp(a, prop, b[prop]);
10
+ if (__getOwnPropSymbols)
11
+ for (var prop of __getOwnPropSymbols(b)) {
12
+ if (__propIsEnum.call(b, prop))
13
+ __defNormalProp(a, prop, b[prop]);
14
+ }
15
+ return a;
16
+ };
1
17
  import React from "react";
2
18
  import fs from "fs-extra";
3
19
  import { cac } from "cac";
@@ -20,19 +36,25 @@ import {
20
36
  generateDownload,
21
37
  generateBeautify
22
38
  } from "./generate.js";
39
+ const cli = cac("minista");
40
+ function cleanOptions(options) {
41
+ const ret = __spreadValues({}, options);
42
+ delete ret["--"];
43
+ return ret;
44
+ }
23
45
  function printVersion() {
24
46
  const pkgURL = new URL("../package.json", import.meta.url);
25
47
  const pkg = JSON.parse(fs.readFileSync(pkgURL, "utf8"));
26
48
  const pkgVersion = pkg.version;
27
49
  return pkgVersion;
28
50
  }
29
- const cli = cac("minista");
30
- cli.command("[root]").alias("dev").action(async () => {
51
+ cli.command("[root]", "start dev server").alias("dev").option("--host [host]", `[string] specify hostname`).option("--port <port>", `[number] specify port`).option("--strictPort", `[boolean] exit if specified port is already in use`).option("--https", `[boolean] use TLS + HTTP/2`).option("--open [path]", `[boolean | string] open browser on startup`).option("--cors", `[boolean] enable CORS`).action(async (root, options) => {
31
52
  try {
53
+ const cliOptions = cleanOptions(options);
32
54
  const userConfig = await getUserConfig();
33
55
  const config = await getConfig(userConfig);
34
56
  const mdxConfig = await getMdxConfig(config);
35
- const viteConfig = await getViteConfig(config, mdxConfig);
57
+ const viteConfig = await getViteConfig(config, mdxConfig, cliOptions);
36
58
  await Promise.all([
37
59
  emptyResolveDir(systemConfig.temp.viteImporter.outDir),
38
60
  emptyResolveDir(systemConfig.temp.icons.outDir)
@@ -44,7 +66,7 @@ cli.command("[root]").alias("dev").action(async () => {
44
66
  process.exit(1);
45
67
  }
46
68
  });
47
- cli.command("build [root]").action(async () => {
69
+ cli.command("build [root]", "build for production").action(async () => {
48
70
  try {
49
71
  const userConfig = await getUserConfig();
50
72
  const config = await getConfig(userConfig);
@@ -76,12 +98,13 @@ cli.command("build [root]").action(async () => {
76
98
  process.exit(1);
77
99
  }
78
100
  });
79
- cli.command("preview [root]").action(async () => {
101
+ cli.command("preview [root]", "locally preview production build").option("--host [host]", `[string] specify hostname`).option("--port <port>", `[number] specify port`).option("--strictPort", `[boolean] exit if specified port is already in use`).option("--https", `[boolean] use TLS + HTTP/2`).option("--open [path]", `[boolean | string] open browser on startup`).action(async (root, options) => {
80
102
  try {
103
+ const cliOptions = cleanOptions(options);
81
104
  const userConfig = await getUserConfig();
82
105
  const config = await getConfig(userConfig);
83
106
  const mdxConfig = await getMdxConfig(config);
84
- const viteConfig = await getViteConfig(config, mdxConfig);
107
+ const viteConfig = await getViteConfig(config, mdxConfig, cliOptions);
85
108
  await previewLocal(viteConfig);
86
109
  } catch (err) {
87
110
  console.log(err);
package/dist/types.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import type { ExoticComponent } from "react";
2
- import type { UserConfig as ViteUserConfig } from "vite";
2
+ import type { UserConfig as ViteUserConfig, CorsOptions as ViteCorsOptions } from "vite";
3
3
  import type { Config as SvgrOptions } from "@svgr/core";
4
4
  import type { Options as HighlightOptions } from "rehype-highlight";
5
5
  import type { Options as MdxOptions } from "@mdx-js/esbuild";
@@ -177,6 +177,21 @@ export declare type MinistaSystemConfig = {
177
177
  };
178
178
  };
179
179
  };
180
+ export declare type MinistaCliDevOptions = {
181
+ host?: string | boolean;
182
+ port?: number;
183
+ strictPort?: boolean;
184
+ https?: boolean;
185
+ open?: boolean | string;
186
+ cors?: boolean | ViteCorsOptions;
187
+ };
188
+ export declare type MinistaCliPreviewOptions = {
189
+ host?: string | boolean;
190
+ port?: number;
191
+ strictPort?: boolean;
192
+ https?: boolean;
193
+ open?: boolean | string;
194
+ };
180
195
  export declare type MinistaLocation = {
181
196
  pathname: string;
182
197
  };
package/dist/user.js CHANGED
@@ -1,5 +1,6 @@
1
1
  import React from "react";
2
2
  import path from "path";
3
+ import url from "url";
3
4
  import { build as esBuild } from "esbuild";
4
5
  import { systemConfig } from "./system.js";
5
6
  import { getSameFilePaths } from "./path.js";
@@ -22,7 +23,9 @@ async function getUserConfig(cofigPath = ".") {
22
23
  format: "esm",
23
24
  platform: "node"
24
25
  }).catch(() => process.exit(1));
25
- const { default: userConfig } = await import(path.resolve(`${systemConfig.temp.config.outDir}/minista.config.mjs`));
26
+ const userConfigPath = path.resolve(`${systemConfig.temp.config.outDir}/minista.config.mjs`);
27
+ const userConfigFilePath = url.pathToFileURL(userConfigPath).href;
28
+ const { default: userConfig } = await import(userConfigFilePath);
26
29
  return userConfig || {};
27
30
  } else {
28
31
  return {};
package/dist/vite.d.ts CHANGED
@@ -1,8 +1,8 @@
1
1
  import type { UserConfig as ViteConfig, Plugin } from "vite";
2
2
  import type { Config as SvgrOptions } from "@svgr/core";
3
3
  import type { Options as MdxOptions } from "@mdx-js/esbuild";
4
- import type { MinistaResolveConfig, MinistaSvgstoreOptions } from "./types.js";
5
- export declare function getViteConfig(config: MinistaResolveConfig, mdxConfig: MdxOptions): Promise<ViteConfig>;
4
+ import type { MinistaResolveConfig, MinistaSvgstoreOptions, MinistaCliDevOptions, MinistaCliPreviewOptions } from "./types.js";
5
+ export declare function getViteConfig(config: MinistaResolveConfig, mdxConfig: MdxOptions, cliOptions?: MinistaCliDevOptions | MinistaCliPreviewOptions): Promise<ViteConfig>;
6
6
  export declare function resolveEntry(entry: string | string[] | {}): {};
7
7
  export declare function vitePluginMinistaVirtualHtml(): Plugin;
8
8
  /*! Fork: vite-plugin-svgr | https://github.com/pd4d10/vite-plugin-svgr */
package/dist/vite.js CHANGED
@@ -18,11 +18,11 @@ import { getFilePaths } from "./path.js";
18
18
  import { getFilename, getFilenameObject } from "./utils.js";
19
19
  const __filename = url.fileURLToPath(import.meta.url);
20
20
  const __dirname = path.dirname(__filename);
21
- async function getViteConfig(config, mdxConfig) {
21
+ async function getViteConfig(config, mdxConfig, cliOptions) {
22
22
  var _a, _b, _c, _d, _e;
23
23
  const imgExt = ["jpg", "jpeg", "gif", "png", "webp", "svg"];
24
24
  const fontExt = ["woff", "woff2", "eot", "ttf", "otf"];
25
- const viteConfig = defineViteConfig({
25
+ const defaultViteConfig = defineViteConfig({
26
26
  base: config.base || "/",
27
27
  publicDir: config.public || "public",
28
28
  build: {
@@ -90,7 +90,7 @@ async function getViteConfig(config, mdxConfig) {
90
90
  },
91
91
  customLogger: createLogger("info", { prefix: "[minista]" })
92
92
  });
93
- const mergedViteConfig = mergeViteConfig(viteConfig, config.vite);
93
+ const mergedViteConfig = mergeViteConfig(defaultViteConfig, config.vite);
94
94
  const svgrPlugin = vitePluginMinistaSvgr(config.assets.svgr.svgrOptions);
95
95
  mergedViteConfig.plugins.push(svgrPlugin);
96
96
  if (config.assets.icons.useSprite) {
@@ -104,7 +104,7 @@ async function getViteConfig(config, mdxConfig) {
104
104
  }
105
105
  const mdxPlugin = mdx(mdxConfig);
106
106
  mergedViteConfig.plugins.push(mdxPlugin);
107
- return mergedViteConfig;
107
+ return cliOptions ? mergeViteConfig(mergedViteConfig, { server: cliOptions }) : mergedViteConfig;
108
108
  }
109
109
  function resolveEntry(entry) {
110
110
  const result1 = typeof entry === "object" ? entry : typeof entry === "string" ? { [getFilename(entry)]: entry } : Array.isArray(entry) ? getFilenameObject(entry) : {};
@@ -153,8 +153,9 @@ function vitePluginMinistaVirtualHtml() {
153
153
  configureServer(server) {
154
154
  return () => {
155
155
  var _a, _b;
156
- const ministaHtmlURL = new URL(path.resolve(__dirname + "/../lib/index.html"), import.meta.url);
157
- const ministaHtml = fs.readFileSync(ministaHtmlURL, "utf8");
156
+ const ministaHtmlUrl = path.resolve(__dirname + "/../lib/index.html");
157
+ const ministaHtmlUrlRelative = path.relative(".", ministaHtmlUrl);
158
+ const ministaHtml = fs.readFileSync(ministaHtmlUrlRelative, "utf8");
158
159
  const assetTagStr = getAssetsTagStr((_b = (_a = server.config.inlineConfig.build) == null ? void 0 : _a.rollupOptions) == null ? void 0 : _b.input);
159
160
  const ministaReplacedHtml = ministaHtml.replace("<!-- VIRTUAL_HTML_ASSETS_TAG -->", assetTagStr);
160
161
  server.middlewares.use((req, res, next) => {
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "minista",
3
3
  "description": "Next.js Like Development with 100% Static Generate",
4
- "version": "2.2.1",
4
+ "version": "2.3.2",
5
5
  "bin": {
6
6
  "minista": "./bin/minista.js"
7
7
  },
@@ -51,8 +51,10 @@
51
51
  "test:dev": "vitest watch",
52
52
  "user": "cd ./user && npx minista",
53
53
  "user:dev": "cd ./user && npx minista",
54
+ "user:dev-h": "cd ./user && npx minista --host",
54
55
  "user:build": "cd ./user && npx minista build",
55
56
  "user:preview": "cd ./user && npx minista preview",
57
+ "user:preview-h": "cd ./user && npx minista preview --host",
56
58
  "user:v": "cd ./user && npx minista -v",
57
59
  "user:h": "cd ./user && npx minista -h",
58
60
  "prepublishOnly": "npm run clean:dist && npm run build:all",