@dcloudio/uni-cli-shared 3.0.0-alpha-3090920231127001 → 3.0.0-alpha-3090920231203001

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/hbx/log.js CHANGED
@@ -43,7 +43,8 @@ if (typeof console !== 'undefined') {
43
43
  // overridedConsole('error', console.error, ZERO_WIDTH_CHAR.ERROR)
44
44
  }
45
45
  function formatAtFilename(filename, line, column) {
46
- return `at ${picocolors_1.default.cyan((0, utils_1.normalizePath)(path_1.default.relative(process.env.UNI_INPUT_DIR, filename.replace('\x00', '').split('?')[0])) +
46
+ const file = path_1.default.relative(process.env.UNI_INPUT_DIR, filename.replace('\x00', '').split('?')[0]);
47
+ return `at ${picocolors_1.default.cyan((0, utils_1.normalizePath)(file === 'pages-json-uts' ? 'pages.json' : file) +
47
48
  ':' +
48
49
  (line || 1) +
49
50
  ':' +
@@ -4,4 +4,4 @@ export * from './json';
4
4
  export * from './pages';
5
5
  export * from './manifest';
6
6
  export * from './theme';
7
- export { normalizeUniAppXAppPagesJson, normalizeUniAppXAppConfig, } from './uni-x';
7
+ export { normalizeUniAppXAppPagesJson, normalizeUniAppXAppConfig, checkPagesJson, } from './uni-x';
@@ -14,7 +14,7 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
14
  for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
15
  };
16
16
  Object.defineProperty(exports, "__esModule", { value: true });
17
- exports.normalizeUniAppXAppConfig = exports.normalizeUniAppXAppPagesJson = void 0;
17
+ exports.checkPagesJson = exports.normalizeUniAppXAppConfig = exports.normalizeUniAppXAppPagesJson = void 0;
18
18
  __exportStar(require("./mp"), exports);
19
19
  __exportStar(require("./app"), exports);
20
20
  __exportStar(require("./json"), exports);
@@ -24,3 +24,4 @@ __exportStar(require("./theme"), exports);
24
24
  var uni_x_1 = require("./uni-x");
25
25
  Object.defineProperty(exports, "normalizeUniAppXAppPagesJson", { enumerable: true, get: function () { return uni_x_1.normalizeUniAppXAppPagesJson; } });
26
26
  Object.defineProperty(exports, "normalizeUniAppXAppConfig", { enumerable: true, get: function () { return uni_x_1.normalizeUniAppXAppConfig; } });
27
+ Object.defineProperty(exports, "checkPagesJson", { enumerable: true, get: function () { return uni_x_1.checkPagesJson; } });
@@ -1,3 +1,4 @@
1
+ export declare function checkPagesJson(jsonStr: string, inputDir: string): boolean;
1
2
  export declare function normalizeUniAppXAppPagesJson(jsonStr: string): UniApp.PagesJson;
2
3
  /**
3
4
  * TODO 应该闭包,通过globalThis赋值?
@@ -3,15 +3,123 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.normalizeUniAppXAppConfig = exports.normalizeUniAppXAppPagesJson = void 0;
6
+ exports.normalizeUniAppXAppConfig = exports.normalizeUniAppXAppPagesJson = exports.checkPagesJson = void 0;
7
+ const fs_1 = __importDefault(require("fs"));
7
8
  const path_1 = __importDefault(require("path"));
8
9
  const shared_1 = require("@vue/shared");
10
+ const jsonc_parser_1 = require("jsonc-parser");
9
11
  const json_1 = require("../json");
10
12
  const pages_1 = require("../pages");
11
13
  const utils_1 = require("../../utils");
12
14
  const uniRoutes_1 = require("../app/pages/uniRoutes");
13
15
  const uniConfig_1 = require("./uniConfig");
16
+ const utils_2 = require("../../vite/plugins/vitejs/utils");
17
+ function checkPagesJson(jsonStr, inputDir) {
18
+ if (!inputDir) {
19
+ return false;
20
+ }
21
+ const errors = [];
22
+ const root = (0, jsonc_parser_1.parseTree)(jsonStr, errors);
23
+ if (!root) {
24
+ if (errors.length) {
25
+ for (const error of errors) {
26
+ const { line, column } = (0, utils_2.offsetToLineColumn)(jsonStr, error.offset);
27
+ throw {
28
+ name: 'SyntaxError',
29
+ code: error.error,
30
+ message: (0, jsonc_parser_1.printParseErrorCode)(error.error),
31
+ loc: {
32
+ start: { line, column },
33
+ },
34
+ offsetStart: error.offset,
35
+ offsetEnd: error.offset + error.length,
36
+ };
37
+ }
38
+ }
39
+ return false;
40
+ }
41
+ const pagePathNodes = walkNodes(findRootNode(root, ['pages']));
42
+ findRootNode(root, ['subPackages', 'subpackages']).forEach((node) => {
43
+ const subPackageRoot = findSubPackageRoot(node);
44
+ if (subPackageRoot) {
45
+ findRootNode(node, ['pages']).forEach((subNode) => {
46
+ walkNodes(subNode.children ?? []).forEach((node) => {
47
+ pagePathNodes.push({
48
+ ...node,
49
+ value: (0, utils_1.normalizePath)(path_1.default.join(subPackageRoot, node.value)),
50
+ });
51
+ });
52
+ });
53
+ }
54
+ });
55
+ if (pagePathNodes.length) {
56
+ for (const node of pagePathNodes) {
57
+ const pagePath = node.value ?? '';
58
+ if (fs_1.default.existsSync(path_1.default.join(inputDir, pagePath + '.uvue')) ||
59
+ fs_1.default.existsSync(path_1.default.join(inputDir, pagePath + '.vue'))) {
60
+ continue;
61
+ }
62
+ const { line, column } = (0, utils_2.offsetToLineColumn)(jsonStr, node.offset);
63
+ throw {
64
+ name: 'CompilerError',
65
+ code: 'CompilerError',
66
+ message: `The page path "${pagePath}" does not exist`,
67
+ loc: {
68
+ start: { line, column },
69
+ },
70
+ offsetStart: node.offset,
71
+ offsetEnd: node.offset + node.length,
72
+ };
73
+ }
74
+ }
75
+ return true;
76
+ }
77
+ exports.checkPagesJson = checkPagesJson;
78
+ function findSubPackageRoot(node) {
79
+ const child = node.children?.find((child) => child.type === 'property' &&
80
+ child.children &&
81
+ child.children.find((child) => child.type === 'string' && child.value === 'root'));
82
+ if (child && child.children?.length === 2) {
83
+ return child.children[1].value;
84
+ }
85
+ return '';
86
+ }
87
+ function findRootNode(node, property) {
88
+ const { type, children } = node;
89
+ if (type === 'object' && children) {
90
+ const child = children.find((child) => child.type === 'property' &&
91
+ child.children &&
92
+ child.children.find((child) => child.type === 'string' && property.includes(child.value)));
93
+ if (child) {
94
+ const node = child.children.find((child) => child.type === 'array');
95
+ return node?.children ?? [];
96
+ }
97
+ }
98
+ return [];
99
+ }
100
+ function walkNodes(node) {
101
+ const pagePathNodes = [];
102
+ node.forEach((node) => walkNode(node, pagePathNodes));
103
+ return pagePathNodes;
104
+ }
105
+ function walkNode(node, pagePathNodes) {
106
+ const { type, children } = node;
107
+ if (type === 'property' && children && children.length === 2) {
108
+ const maybePagePathNode = children[0];
109
+ const maybePagePathValueNode = children[1];
110
+ if (maybePagePathNode.type === 'string' &&
111
+ maybePagePathNode.value === 'path' &&
112
+ maybePagePathValueNode.type === 'string' &&
113
+ (0, shared_1.isString)(maybePagePathValueNode.value)) {
114
+ pagePathNodes.push(maybePagePathValueNode);
115
+ }
116
+ }
117
+ if (children) {
118
+ children.forEach((node) => walkNode(node, pagePathNodes));
119
+ }
120
+ }
14
121
  function normalizeUniAppXAppPagesJson(jsonStr) {
122
+ checkPagesJson(jsonStr, process.env.UNI_INPUT_DIR);
15
123
  const pagesJson = {
16
124
  pages: [],
17
125
  globalStyle: {},
@@ -15,6 +15,10 @@ export declare const multilineCommentsRE: RegExp;
15
15
  export declare function asyncReplace(input: string, re: RegExp, replacer: (match: RegExpExecArray) => string | Promise<string>): Promise<string>;
16
16
  export declare function isObject(value: unknown): value is Record<string, any>;
17
17
  export declare function pad(source: string, n?: number): string;
18
+ export declare function offsetToLineColumn(source: string, offset: number): {
19
+ line: number;
20
+ column: number;
21
+ };
18
22
  export declare function posToNumber(source: string, pos: number | {
19
23
  line: number;
20
24
  column: number;
@@ -30,7 +34,7 @@ export declare function locToStartAndEnd(source: string, loc: {
30
34
  };
31
35
  }): {
32
36
  start: number;
33
- end: number;
37
+ end: number | undefined;
34
38
  };
35
39
  export declare function generateCodeFrame(source: string, start?: number | {
36
40
  line: number;
@@ -3,7 +3,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.combineSourcemaps = exports.processSrcSet = exports.generateCodeFrame = exports.locToStartAndEnd = exports.posToNumber = exports.pad = exports.isObject = exports.asyncReplace = exports.multilineCommentsRE = exports.isDataUrl = exports.dataUrlRE = exports.isExternalUrl = exports.externalRE = exports.cleanUrl = exports.hashRE = exports.queryRE = exports.normalizePath = exports.isWindows = exports.deepImportRE = exports.bareImportRE = exports.slash = void 0;
6
+ exports.combineSourcemaps = exports.processSrcSet = exports.generateCodeFrame = exports.locToStartAndEnd = exports.posToNumber = exports.offsetToLineColumn = exports.pad = exports.isObject = exports.asyncReplace = exports.multilineCommentsRE = exports.isDataUrl = exports.dataUrlRE = exports.isExternalUrl = exports.externalRE = exports.cleanUrl = exports.hashRE = exports.queryRE = exports.normalizePath = exports.isWindows = exports.deepImportRE = exports.bareImportRE = exports.slash = void 0;
7
7
  /**
8
8
  * https://github.com/vitejs/vite/blob/main/packages/vite/src/node/utils.ts
9
9
  */
@@ -56,6 +56,24 @@ function pad(source, n = 2) {
56
56
  return lines.map((l) => ` `.repeat(n) + l).join(`\n`);
57
57
  }
58
58
  exports.pad = pad;
59
+ function offsetToLineColumn(source, offset) {
60
+ const lines = source.split(splitRE);
61
+ let line = 1;
62
+ let column = 0;
63
+ for (let i = 0; i < lines.length; i++) {
64
+ const lineLength = lines[i].length + 1;
65
+ if (offset <= lineLength) {
66
+ column = offset;
67
+ break;
68
+ }
69
+ else {
70
+ offset -= lineLength;
71
+ line++;
72
+ }
73
+ }
74
+ return { line, column };
75
+ }
76
+ exports.offsetToLineColumn = offsetToLineColumn;
59
77
  function posToNumber(source, pos) {
60
78
  if (typeof pos === 'number')
61
79
  return pos;
@@ -73,7 +91,9 @@ function posToNumberByLines(lines, line, column) {
73
91
  function locToStartAndEnd(source, loc) {
74
92
  const lines = source.split(splitRE);
75
93
  const start = posToNumberByLines(lines, loc.start.line, loc.start.column);
76
- const end = posToNumberByLines(lines, loc.end.line, loc.end.column);
94
+ const end = loc.end
95
+ ? posToNumberByLines(lines, loc.end.line, loc.end.column)
96
+ : undefined;
77
97
  return { start, end };
78
98
  }
79
99
  exports.locToStartAndEnd = locToStartAndEnd;
@@ -1,4 +1,7 @@
1
1
  import type { ConfigEnv, ResolvedConfig, UserConfig } from 'vite';
2
+ import { RollupError } from 'rollup';
3
+ import { CompilerError } from '@vue/compiler-sfc';
2
4
  export declare function withSourcemap(config: ResolvedConfig): boolean;
3
5
  export declare function isInHybridNVue(config: UserConfig | ResolvedConfig): boolean;
4
6
  export declare function isSsr(command: ConfigEnv['command'], config: UserConfig | ResolvedConfig): boolean;
7
+ export declare function createRollupError(plugin: string, id: string, error: CompilerError | SyntaxError, source?: string): RollupError;
@@ -1,6 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.isSsr = exports.isInHybridNVue = exports.withSourcemap = void 0;
3
+ exports.createRollupError = exports.isSsr = exports.isInHybridNVue = exports.withSourcemap = void 0;
4
+ const utils_1 = require("../plugins/vitejs/utils");
4
5
  function withSourcemap(config) {
5
6
  if (config.command === 'serve') {
6
7
  return true;
@@ -22,3 +23,31 @@ function isSsr(command, config) {
22
23
  return false;
23
24
  }
24
25
  exports.isSsr = isSsr;
26
+ function createRollupError(plugin, id, error, source) {
27
+ const { message, name, stack } = error;
28
+ const rollupError = {
29
+ id,
30
+ plugin,
31
+ message,
32
+ name,
33
+ stack,
34
+ };
35
+ if ('code' in error && error.loc) {
36
+ rollupError.loc = {
37
+ file: id,
38
+ line: error.loc.start.line,
39
+ column: error.loc.start.column,
40
+ };
41
+ if (source && source.length > 0) {
42
+ if ('offsetStart' in error && 'offsetEnd' in error) {
43
+ rollupError.frame = (0, utils_1.generateCodeFrame)(source, error.offsetStart, error.offsetEnd).replace(/\t/g, ' ');
44
+ }
45
+ else {
46
+ const { start, end } = (0, utils_1.locToStartAndEnd)(source, error.loc);
47
+ rollupError.frame = (0, utils_1.generateCodeFrame)(source, start, end).replace(/\t/g, ' ');
48
+ }
49
+ }
50
+ }
51
+ return rollupError;
52
+ }
53
+ exports.createRollupError = createRollupError;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dcloudio/uni-cli-shared",
3
- "version": "3.0.0-alpha-3090920231127001",
3
+ "version": "3.0.0-alpha-3090920231203001",
4
4
  "description": "@dcloudio/uni-cli-shared",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -25,8 +25,8 @@
25
25
  "@babel/core": "^7.21.3",
26
26
  "@babel/parser": "^7.16.4",
27
27
  "@babel/types": "^7.20.7",
28
- "@dcloudio/uni-i18n": "3.0.0-alpha-3090920231127001",
29
- "@dcloudio/uni-shared": "3.0.0-alpha-3090920231127001",
28
+ "@dcloudio/uni-i18n": "3.0.0-alpha-3090920231203001",
29
+ "@dcloudio/uni-shared": "3.0.0-alpha-3090920231203001",
30
30
  "@intlify/core-base": "9.1.9",
31
31
  "@intlify/shared": "9.1.9",
32
32
  "@intlify/vue-devtools": "9.1.9",
@@ -64,7 +64,7 @@
64
64
  },
65
65
  "gitHead": "33e807d66e1fe47e2ee08ad9c59247e37b8884da",
66
66
  "devDependencies": {
67
- "@dcloudio/uni-uts-v1": "3.0.0-alpha-3090920231127001",
67
+ "@dcloudio/uni-uts-v1": "3.0.0-alpha-3090920231203001",
68
68
  "@types/babel__core": "^7.1.19",
69
69
  "@types/debug": "^4.1.7",
70
70
  "@types/estree": "^0.0.51",