@dcloudio/uni-cli-shared 3.0.0-alpha-4000020231215001 → 3.0.0-alpha-4000020231218001

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.
@@ -1,5 +1,6 @@
1
1
  import type { DecodedSourceMap, RawSourceMap } from '@ampproject/remapping';
2
- import { SourceLocation } from '@vue/compiler-core';
2
+ import { Position, SourceLocation } from '@vue/compiler-core';
3
+ import { LinesAndColumns } from 'lines-and-columns';
3
4
  export declare function slash(p: string): string;
4
5
  export declare const bareImportRE: RegExp;
5
6
  export declare const deepImportRE: RegExp;
@@ -21,6 +22,7 @@ export declare function offsetToLineColumn(source: string, offset: number): {
21
22
  line: number;
22
23
  column: number;
23
24
  };
25
+ export declare function offsetToLineColumnByLines(lines: LinesAndColumns, offset: number): Position;
24
26
  export declare function posToNumber(source: string, pos: number | {
25
27
  line: number;
26
28
  column: number;
@@ -3,13 +3,14 @@ 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.offsetToLineColumn = exports.offsetToStartAndEnd = 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.offsetToLineColumnByLines = exports.offsetToLineColumn = exports.offsetToStartAndEnd = 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
  */
10
10
  const os_1 = __importDefault(require("os"));
11
11
  const path_1 = __importDefault(require("path"));
12
12
  const remapping_1 = __importDefault(require("@ampproject/remapping"));
13
+ const lines_and_columns_1 = require("lines-and-columns");
13
14
  function slash(p) {
14
15
  return p.replace(/\\/g, '/');
15
16
  }
@@ -57,7 +58,7 @@ function pad(source, n = 2) {
57
58
  }
58
59
  exports.pad = pad;
59
60
  function offsetToStartAndEnd(source, startOffset, endOffset) {
60
- const lines = source.split(splitRE);
61
+ const lines = new lines_and_columns_1.LinesAndColumns(source);
61
62
  return {
62
63
  start: offsetToLineColumnByLines(lines, startOffset),
63
64
  end: offsetToLineColumnByLines(lines, endOffset),
@@ -65,39 +66,31 @@ function offsetToStartAndEnd(source, startOffset, endOffset) {
65
66
  };
66
67
  }
67
68
  exports.offsetToStartAndEnd = offsetToStartAndEnd;
68
- function offsetToLineColumnByLines(lines, offset) {
69
- let currentOffset = 0;
70
- for (let i = 0; i < lines.length; i++) {
71
- const lineLength = lines[i].length + 1; // Adding 1 for the newline character
72
- if (currentOffset + lineLength > offset) {
73
- const line = i + 1; // Line numbers start from 1
74
- const column = offset - currentOffset; // Column numbers start from 0
75
- return { line, column, offset };
76
- }
77
- currentOffset += lineLength;
78
- }
79
- return { line: lines.length, column: lines[lines.length - 1].length, offset };
80
- }
81
69
  function offsetToLineColumn(source, offset) {
82
- return offsetToLineColumnByLines(source.split(splitRE), offset);
70
+ return offsetToLineColumnByLines(new lines_and_columns_1.LinesAndColumns(source), offset);
83
71
  }
84
72
  exports.offsetToLineColumn = offsetToLineColumn;
73
+ function offsetToLineColumnByLines(lines, offset) {
74
+ let location = lines.locationForIndex(offset);
75
+ if (!location) {
76
+ location = lines.locationForIndex(offset);
77
+ }
78
+ // lines-and-columns is 0-indexed while positions are 1-indexed
79
+ return { line: location.line + 1, column: location.column, offset: 0 };
80
+ }
81
+ exports.offsetToLineColumnByLines = offsetToLineColumnByLines;
85
82
  function posToNumber(source, pos) {
86
83
  if (typeof pos === 'number')
87
84
  return pos;
88
- const lines = source.split(splitRE);
89
- return posToNumberByLines(lines, pos.line, pos.column);
85
+ return posToNumberByLines(new lines_and_columns_1.LinesAndColumns(source), pos.line, pos.column);
90
86
  }
91
87
  exports.posToNumber = posToNumber;
92
88
  function posToNumberByLines(lines, line, column) {
93
- let start = 0;
94
- for (let i = 0; i < line - 1; i++) {
95
- start += lines[i].length + 1;
96
- }
97
- return start + column;
89
+ // lines-and-columns is 0-indexed while positions are 1-indexed
90
+ return lines.indexForLocation({ line: line - 1, column }) || 0;
98
91
  }
99
92
  function locToStartAndEnd(source, loc) {
100
- const lines = source.split(splitRE);
93
+ const lines = new lines_and_columns_1.LinesAndColumns(source);
101
94
  const start = posToNumberByLines(lines, loc.start.line, loc.start.column);
102
95
  const end = loc.end
103
96
  ? posToNumberByLines(lines, loc.end.line, loc.end.column)
@@ -1,7 +1,9 @@
1
1
  import type { ConfigEnv, ResolvedConfig, UserConfig } from 'vite';
2
2
  import { RollupError } from 'rollup';
3
3
  import { CompilerError } from '@vue/compiler-sfc';
4
+ import { codeFrameColumns } from '@babel/code-frame';
4
5
  export declare function withSourcemap(config: ResolvedConfig): boolean;
5
6
  export declare function isInHybridNVue(config: UserConfig | ResolvedConfig): boolean;
6
7
  export declare function isSsr(command: ConfigEnv['command'], config: UserConfig | ResolvedConfig): boolean;
7
8
  export declare function createRollupError(plugin: string, id: string, error: CompilerError | SyntaxError, source?: string): RollupError;
9
+ export declare const generateCodeFrameColumns: typeof codeFrameColumns;
@@ -1,8 +1,9 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.createRollupError = exports.isSsr = exports.isInHybridNVue = exports.withSourcemap = void 0;
4
- const utils_1 = require("../plugins/vitejs/utils");
3
+ exports.generateCodeFrameColumns = exports.createRollupError = exports.isSsr = exports.isInHybridNVue = exports.withSourcemap = void 0;
5
4
  const shared_1 = require("@vue/shared");
5
+ const code_frame_1 = require("@babel/code-frame");
6
+ const utils_1 = require("../plugins/vitejs/utils");
6
7
  function withSourcemap(config) {
7
8
  if (config.command === 'serve') {
8
9
  return true;
@@ -40,11 +41,10 @@ function createRollupError(plugin, id, error, source) {
40
41
  };
41
42
  if (source && source.length > 0) {
42
43
  if ('offsetStart' in error && 'offsetEnd' in error) {
43
- rollupError.frame = (0, utils_1.generateCodeFrame)(source, error.offsetStart, error.offsetEnd).replace(/\t/g, ' ');
44
+ rollupError.frame = (0, code_frame_1.codeFrameColumns)(source, (0, utils_1.offsetToStartAndEnd)(source, error.offsetStart, error.offsetEnd));
44
45
  }
45
46
  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, ' ');
47
+ rollupError.frame = (0, code_frame_1.codeFrameColumns)(source, error.loc);
48
48
  }
49
49
  }
50
50
  }
@@ -60,3 +60,4 @@ function createRollupError(plugin, id, error, source) {
60
60
  return rollupError;
61
61
  }
62
62
  exports.createRollupError = createRollupError;
63
+ exports.generateCodeFrameColumns = code_frame_1.codeFrameColumns;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dcloudio/uni-cli-shared",
3
- "version": "3.0.0-alpha-4000020231215001",
3
+ "version": "3.0.0-alpha-4000020231218001",
4
4
  "description": "@dcloudio/uni-cli-shared",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -22,11 +22,12 @@
22
22
  },
23
23
  "dependencies": {
24
24
  "@ampproject/remapping": "^2.1.2",
25
+ "@babel/code-frame": "^7.23.5",
25
26
  "@babel/core": "^7.21.3",
26
27
  "@babel/parser": "^7.23.5",
27
28
  "@babel/types": "^7.20.7",
28
- "@dcloudio/uni-i18n": "3.0.0-alpha-4000020231215001",
29
- "@dcloudio/uni-shared": "3.0.0-alpha-4000020231215001",
29
+ "@dcloudio/uni-i18n": "3.0.0-alpha-4000020231218001",
30
+ "@dcloudio/uni-shared": "3.0.0-alpha-4000020231218001",
30
31
  "@intlify/core-base": "9.1.9",
31
32
  "@intlify/shared": "9.1.9",
32
33
  "@intlify/vue-devtools": "9.1.9",
@@ -48,6 +49,7 @@
48
49
  "fs-extra": "^10.0.0",
49
50
  "hash-sum": "^2.0.0",
50
51
  "jsonc-parser": "^3.2.0",
52
+ "lines-and-columns": "^2.0.4",
51
53
  "magic-string": "^0.30.0",
52
54
  "merge": "^2.1.1",
53
55
  "mime": "^3.0.0",
@@ -64,7 +66,8 @@
64
66
  },
65
67
  "gitHead": "33e807d66e1fe47e2ee08ad9c59247e37b8884da",
66
68
  "devDependencies": {
67
- "@dcloudio/uni-uts-v1": "3.0.0-alpha-4000020231215001",
69
+ "@dcloudio/uni-uts-v1": "3.0.0-alpha-4000020231218001",
70
+ "@types/babel__code-frame": "^7.0.6",
68
71
  "@types/babel__core": "^7.1.19",
69
72
  "@types/debug": "^4.1.7",
70
73
  "@types/estree": "^0.0.51",
@@ -76,6 +79,7 @@
76
79
  "@types/resolve": "^1.20.2",
77
80
  "@types/sass": "^1.43.1",
78
81
  "@types/stylus": "^0.48.36",
82
+ "code-frame": "link:@types/@babel/code-frame",
79
83
  "postcss": "^8.4.21",
80
84
  "unplugin-auto-import": "^0.16.7",
81
85
  "vue": "3.3.11"