@uni-helper/vite-plugin-uni-pages 0.1.1 → 0.1.3

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/index.cjs CHANGED
@@ -8,7 +8,7 @@ const chokidar = require('chokidar');
8
8
  const vite = require('vite');
9
9
  const unconfig = require('unconfig');
10
10
  const Debug = require('debug');
11
- const lodashEs = require('lodash-es');
11
+ const lodash = require('lodash');
12
12
  const fg = require('fast-glob');
13
13
  const fs = require('fs');
14
14
  const JSON5 = require('json5');
@@ -52,7 +52,7 @@ function isConfigFile(path) {
52
52
  return path.includes("pages.config");
53
53
  }
54
54
  function mergePageMetaDataArray(pageMetaData) {
55
- const pageMetaDataObj = lodashEs.groupBy(pageMetaData, "path");
55
+ const pageMetaDataObj = lodash.groupBy(pageMetaData, "path");
56
56
  const result = [];
57
57
  for (const path in pageMetaDataObj) {
58
58
  const _pageMetaData = pageMetaDataObj[path];
@@ -154,10 +154,15 @@ async function parseSFC(code) {
154
154
  }
155
155
  function parseCustomBlock(block, filePath, options) {
156
156
  const lang = block.lang ?? options.routeBlockLang;
157
+ const attr = {
158
+ type: "page",
159
+ ...block.attrs
160
+ };
161
+ let content;
157
162
  debug.routeBlock(`use ${lang} parser`);
158
163
  if (lang === "json5") {
159
164
  try {
160
- return JSON5.parse(block.content);
165
+ content = JSON5.parse(block.content);
161
166
  } catch (err) {
162
167
  throw new Error(
163
168
  `Invalid JSON5 format of <${block.type}> content in ${filePath}
@@ -166,7 +171,7 @@ ${err.message}`
166
171
  }
167
172
  } else if (lang === "json") {
168
173
  try {
169
- return JSON.parse(block.content);
174
+ content = JSON.parse(block.content);
170
175
  } catch (err) {
171
176
  throw new Error(
172
177
  `Invalid JSON format of <${block.type}> content in ${filePath}
@@ -175,7 +180,7 @@ ${err.message}`
175
180
  }
176
181
  } else if (lang === "yaml" || lang === "yml") {
177
182
  try {
178
- return yaml.parse(block.content);
183
+ content = yaml.parse(block.content);
179
184
  } catch (err) {
180
185
  throw new Error(
181
186
  `Invalid YAML format of <${block.type}> content in ${filePath}
@@ -183,6 +188,12 @@ ${err.message}`
183
188
  );
184
189
  }
185
190
  }
191
+ if (content) {
192
+ return {
193
+ attr,
194
+ content
195
+ };
196
+ }
186
197
  }
187
198
  async function getRouteBlock(path, options) {
188
199
  const content = fs.readFileSync(path, "utf8");
@@ -278,9 +289,9 @@ class PageContext {
278
289
  const { relativePath, absolutePath } = page;
279
290
  const routeBlock = await getRouteBlock(absolutePath, this.options);
280
291
  const relativePathWithFileName = relativePath.replace(path.extname(relativePath), "");
281
- const pageMetaDatum = { path: vite.normalizePath(relativePathWithFileName), type: "page" };
292
+ const pageMetaDatum = { path: vite.normalizePath(relativePathWithFileName), type: routeBlock?.attr.type ?? "page" };
282
293
  if (routeBlock)
283
- Object.assign(pageMetaDatum, routeBlock);
294
+ Object.assign(pageMetaDatum, routeBlock.content);
284
295
  return pageMetaDatum;
285
296
  }
286
297
  async mergePageMetaData() {
@@ -296,6 +307,7 @@ class PageContext {
296
307
  else
297
308
  this.pageMetaData = generatedPageMetaData;
298
309
  }
310
+ this.pageMetaData.sort((page) => page.type === "home" ? -1 : 0);
299
311
  debug.pages(generatedPageMetaData);
300
312
  }
301
313
  async updatePagesJSON() {
package/dist/index.d.ts CHANGED
@@ -633,7 +633,10 @@ declare class PageContext {
633
633
  resolveRoutes(): string;
634
634
  }
635
635
 
636
- type CustomBlock = Record<string, any>;
636
+ interface CustomBlock {
637
+ attr: Record<string, any>;
638
+ content: Record<string, any>;
639
+ }
637
640
  interface Options {
638
641
  /**
639
642
  * Whether to merge pages in pages.json
@@ -735,7 +738,7 @@ declare function resolveOptions(userOptions: UserOptions, viteRoot?: string): Re
735
738
  declare function resolvePageDirs(dir: string, root: string, exclude: string[]): string[];
736
739
 
737
740
  declare function parseSFC(code: string): Promise<SFCDescriptor>;
738
- declare function parseCustomBlock(block: SFCBlock, filePath: string, options: ResolvedOptions): any;
741
+ declare function parseCustomBlock(block: SFCBlock, filePath: string, options: ResolvedOptions): CustomBlock | undefined;
739
742
  declare function getRouteBlock(path: string, options: ResolvedOptions): Promise<CustomBlock | undefined>;
740
743
 
741
744
  declare const VitePluginUniPages: (userOptions?: UserOptions) => Plugin;
package/dist/index.mjs CHANGED
@@ -4,7 +4,7 @@ import chokidar from 'chokidar';
4
4
  import { normalizePath } from 'vite';
5
5
  import { loadConfig } from 'unconfig';
6
6
  import Debug from 'debug';
7
- import { groupBy } from 'lodash-es';
7
+ import { groupBy } from 'lodash';
8
8
  import fg from 'fast-glob';
9
9
  import fs from 'fs';
10
10
  import JSON5 from 'json5';
@@ -150,10 +150,15 @@ async function parseSFC(code) {
150
150
  }
151
151
  function parseCustomBlock(block, filePath, options) {
152
152
  const lang = block.lang ?? options.routeBlockLang;
153
+ const attr = {
154
+ type: "page",
155
+ ...block.attrs
156
+ };
157
+ let content;
153
158
  debug.routeBlock(`use ${lang} parser`);
154
159
  if (lang === "json5") {
155
160
  try {
156
- return JSON5.parse(block.content);
161
+ content = JSON5.parse(block.content);
157
162
  } catch (err) {
158
163
  throw new Error(
159
164
  `Invalid JSON5 format of <${block.type}> content in ${filePath}
@@ -162,7 +167,7 @@ ${err.message}`
162
167
  }
163
168
  } else if (lang === "json") {
164
169
  try {
165
- return JSON.parse(block.content);
170
+ content = JSON.parse(block.content);
166
171
  } catch (err) {
167
172
  throw new Error(
168
173
  `Invalid JSON format of <${block.type}> content in ${filePath}
@@ -171,7 +176,7 @@ ${err.message}`
171
176
  }
172
177
  } else if (lang === "yaml" || lang === "yml") {
173
178
  try {
174
- return parse$1(block.content);
179
+ content = parse$1(block.content);
175
180
  } catch (err) {
176
181
  throw new Error(
177
182
  `Invalid YAML format of <${block.type}> content in ${filePath}
@@ -179,6 +184,12 @@ ${err.message}`
179
184
  );
180
185
  }
181
186
  }
187
+ if (content) {
188
+ return {
189
+ attr,
190
+ content
191
+ };
192
+ }
182
193
  }
183
194
  async function getRouteBlock(path, options) {
184
195
  const content = fs.readFileSync(path, "utf8");
@@ -274,9 +285,9 @@ class PageContext {
274
285
  const { relativePath, absolutePath } = page;
275
286
  const routeBlock = await getRouteBlock(absolutePath, this.options);
276
287
  const relativePathWithFileName = relativePath.replace(path.extname(relativePath), "");
277
- const pageMetaDatum = { path: normalizePath(relativePathWithFileName), type: "page" };
288
+ const pageMetaDatum = { path: normalizePath(relativePathWithFileName), type: routeBlock?.attr.type ?? "page" };
278
289
  if (routeBlock)
279
- Object.assign(pageMetaDatum, routeBlock);
290
+ Object.assign(pageMetaDatum, routeBlock.content);
280
291
  return pageMetaDatum;
281
292
  }
282
293
  async mergePageMetaData() {
@@ -292,6 +303,7 @@ class PageContext {
292
303
  else
293
304
  this.pageMetaData = generatedPageMetaData;
294
305
  }
306
+ this.pageMetaData.sort((page) => page.type === "home" ? -1 : 0);
295
307
  debug.pages(generatedPageMetaData);
296
308
  }
297
309
  async updatePagesJSON() {
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@uni-helper/vite-plugin-uni-pages",
3
3
  "type": "module",
4
- "version": "0.1.1",
4
+ "version": "0.1.3",
5
5
  "packageManager": "pnpm@7.16.1",
6
6
  "description": "File system based routing for uni-app applications using Vite",
7
7
  "author": "KeJun",
@@ -18,14 +18,14 @@
18
18
  ".": {
19
19
  "types": "./dist/index.d.ts",
20
20
  "require": "./dist/index.cjs",
21
- "import": "./dist/index.js"
21
+ "import": "./dist/index.mjs"
22
22
  },
23
23
  "./client": {
24
24
  "types": "./client.d.ts"
25
25
  }
26
26
  },
27
27
  "main": "./dist/index.mjs",
28
- "module": "./dist/index.js",
28
+ "module": "./dist/index.cjs",
29
29
  "types": "./dist/index.d.ts",
30
30
  "files": [
31
31
  "dist",
@@ -37,7 +37,7 @@
37
37
  "debug": "^4.3.4",
38
38
  "fast-glob": "^3.2.12",
39
39
  "json5": "^2.2.3",
40
- "lodash-es": "^4.17.21",
40
+ "lodash": "^4.17.21",
41
41
  "magic-string": "^0.27.0",
42
42
  "unconfig": "^0.3.7",
43
43
  "yaml": "^2.2.1"
@@ -45,7 +45,7 @@
45
45
  "devDependencies": {
46
46
  "@antfu/utils": "^0.7.2",
47
47
  "@types/debug": "^4.1.7",
48
- "@types/lodash-es": "^4.17.6",
48
+ "@types/lodash": "^4.14.191",
49
49
  "@types/node": "^18.11.18",
50
50
  "vite": "^4.0.3"
51
51
  },