@dcloudio/uni-cli-shared 3.0.0-3090820231124001 → 3.0.0-3090920231225001

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
  ':' +
@@ -1 +1,6 @@
1
1
  export declare function normalizeAppUniConfig(pagesJson: UniApp.PagesJson, manifestJson: Record<string, any>): string;
2
+ export declare function parseEntryPagePath(pagesJson: UniApp.PagesJson): {
3
+ entryPagePath: string;
4
+ entryPageQuery: string;
5
+ realEntryPagePath: string;
6
+ };
@@ -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.normalizeAppUniConfig = void 0;
6
+ exports.parseEntryPagePath = exports.normalizeAppUniConfig = void 0;
7
7
  const path_1 = __importDefault(require("path"));
8
8
  const i18n_1 = require("../../../i18n");
9
9
  const manifest_1 = require("../../manifest");
@@ -70,3 +70,4 @@ function parseEntryPagePath(pagesJson) {
70
70
  }
71
71
  return res;
72
72
  }
73
+ exports.parseEntryPagePath = parseEntryPagePath;
@@ -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 } from './uniAppX';
7
+ export { normalizeUniAppXAppPagesJson, normalizeUniAppXAppConfig, checkPagesJson, parseUniXFlexDirection, parseUniXSplashScreen, } from './uni-x';
@@ -14,12 +14,16 @@ 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.normalizeUniAppXAppPagesJson = void 0;
17
+ exports.parseUniXSplashScreen = exports.parseUniXFlexDirection = 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);
21
21
  __exportStar(require("./pages"), exports);
22
22
  __exportStar(require("./manifest"), exports);
23
23
  __exportStar(require("./theme"), exports);
24
- var uniAppX_1 = require("./uniAppX");
25
- Object.defineProperty(exports, "normalizeUniAppXAppPagesJson", { enumerable: true, get: function () { return uniAppX_1.normalizeUniAppXAppPagesJson; } });
24
+ var uni_x_1 = require("./uni-x");
25
+ Object.defineProperty(exports, "normalizeUniAppXAppPagesJson", { enumerable: true, get: function () { return uni_x_1.normalizeUniAppXAppPagesJson; } });
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; } });
28
+ Object.defineProperty(exports, "parseUniXFlexDirection", { enumerable: true, get: function () { return uni_x_1.parseUniXFlexDirection; } });
29
+ Object.defineProperty(exports, "parseUniXSplashScreen", { enumerable: true, get: function () { return uni_x_1.parseUniXSplashScreen; } });
@@ -24,9 +24,9 @@ const NON_APP_JSON_KEYS = [
24
24
  'usingComponents',
25
25
  'optimization',
26
26
  'scopedSlotsCompiler',
27
- 'usingComponents',
28
27
  'uniStatistics',
29
28
  'mergeVirtualHostAttributes',
29
+ 'styleIsolation',
30
30
  ];
31
31
  function mergeMiniProgramAppJson(appJson, platformJson = {}) {
32
32
  Object.keys(platformJson).forEach((name) => {
@@ -0,0 +1,10 @@
1
+ export { parseUniXFlexDirection, parseUniXSplashScreen } from './manifest';
2
+ export declare function checkPagesJson(jsonStr: string, inputDir: string): boolean;
3
+ export declare function normalizeUniAppXAppPagesJson(jsonStr: string): UniApp.PagesJson;
4
+ /**
5
+ * TODO 应该闭包,通过globalThis赋值?
6
+ * @param pagesJson
7
+ * @param manifestJson
8
+ * @returns
9
+ */
10
+ export declare function normalizeUniAppXAppConfig(pagesJson: UniApp.PagesJson, manifestJson: Record<string, any>): string;
@@ -0,0 +1,209 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.normalizeUniAppXAppConfig = exports.normalizeUniAppXAppPagesJson = exports.checkPagesJson = exports.parseUniXSplashScreen = exports.parseUniXFlexDirection = void 0;
7
+ const fs_1 = __importDefault(require("fs"));
8
+ const path_1 = __importDefault(require("path"));
9
+ const shared_1 = require("@vue/shared");
10
+ const jsonc_parser_1 = require("jsonc-parser");
11
+ const json_1 = require("../json");
12
+ const pages_1 = require("../pages");
13
+ const utils_1 = require("../../utils");
14
+ const uniRoutes_1 = require("../app/pages/uniRoutes");
15
+ const uniConfig_1 = require("./uniConfig");
16
+ const utils_2 = require("../../vite/plugins/vitejs/utils");
17
+ var manifest_1 = require("./manifest");
18
+ Object.defineProperty(exports, "parseUniXFlexDirection", { enumerable: true, get: function () { return manifest_1.parseUniXFlexDirection; } });
19
+ Object.defineProperty(exports, "parseUniXSplashScreen", { enumerable: true, get: function () { return manifest_1.parseUniXSplashScreen; } });
20
+ function checkPagesJson(jsonStr, inputDir) {
21
+ if (!inputDir) {
22
+ return false;
23
+ }
24
+ const errors = [];
25
+ const root = (0, jsonc_parser_1.parseTree)(jsonStr, errors);
26
+ if (!root) {
27
+ if (errors.length) {
28
+ for (const error of errors) {
29
+ const { line, column } = (0, utils_2.offsetToLineColumn)(jsonStr, error.offset);
30
+ throw {
31
+ name: 'SyntaxError',
32
+ code: error.error,
33
+ message: (0, jsonc_parser_1.printParseErrorCode)(error.error),
34
+ loc: {
35
+ start: { line, column },
36
+ },
37
+ offsetStart: error.offset,
38
+ offsetEnd: error.offset + error.length,
39
+ };
40
+ }
41
+ }
42
+ return false;
43
+ }
44
+ const pagePathNodes = walkNodes(findRootNode(root, ['pages']));
45
+ findRootNode(root, ['subPackages', 'subpackages']).forEach((node) => {
46
+ const subPackageRoot = findSubPackageRoot(node);
47
+ if (subPackageRoot) {
48
+ findRootNode(node, ['pages']).forEach((subNode) => {
49
+ walkNodes(subNode.children ?? []).forEach((node) => {
50
+ pagePathNodes.push({
51
+ ...node,
52
+ value: (0, utils_1.normalizePath)(path_1.default.join(subPackageRoot, node.value)),
53
+ });
54
+ });
55
+ });
56
+ }
57
+ });
58
+ if (pagePathNodes.length) {
59
+ for (const node of pagePathNodes) {
60
+ const pagePath = node.value ?? '';
61
+ if (fs_1.default.existsSync(path_1.default.join(inputDir, pagePath + '.uvue')) ||
62
+ fs_1.default.existsSync(path_1.default.join(inputDir, pagePath + '.vue'))) {
63
+ continue;
64
+ }
65
+ const { line, column } = (0, utils_2.offsetToLineColumn)(jsonStr, node.offset);
66
+ throw {
67
+ name: 'CompilerError',
68
+ code: 'CompilerError',
69
+ message: `The page path "${pagePath}" does not exist`,
70
+ loc: {
71
+ start: { line, column },
72
+ },
73
+ offsetStart: node.offset,
74
+ offsetEnd: node.offset + node.length,
75
+ };
76
+ }
77
+ }
78
+ return true;
79
+ }
80
+ exports.checkPagesJson = checkPagesJson;
81
+ function findSubPackageRoot(node) {
82
+ const child = node.children?.find((child) => child.type === 'property' &&
83
+ child.children &&
84
+ child.children.find((child) => child.type === 'string' && child.value === 'root'));
85
+ if (child && child.children?.length === 2) {
86
+ return child.children[1].value;
87
+ }
88
+ return '';
89
+ }
90
+ function findRootNode(node, property) {
91
+ const { type, children } = node;
92
+ if (type === 'object' && children) {
93
+ const child = children.find((child) => child.type === 'property' &&
94
+ child.children &&
95
+ child.children.find((child) => child.type === 'string' && property.includes(child.value)));
96
+ if (child) {
97
+ const node = child.children.find((child) => child.type === 'array');
98
+ return node?.children ?? [];
99
+ }
100
+ }
101
+ return [];
102
+ }
103
+ function walkNodes(node) {
104
+ const pagePathNodes = [];
105
+ node.forEach((node) => walkNode(node, pagePathNodes));
106
+ return pagePathNodes;
107
+ }
108
+ function walkNode(node, pagePathNodes) {
109
+ const { type, children } = node;
110
+ if (type === 'property' && children && children.length === 2) {
111
+ const maybePagePathNode = children[0];
112
+ const maybePagePathValueNode = children[1];
113
+ if (maybePagePathNode.type === 'string' &&
114
+ maybePagePathNode.value === 'path' &&
115
+ maybePagePathValueNode.type === 'string' &&
116
+ (0, shared_1.isString)(maybePagePathValueNode.value)) {
117
+ pagePathNodes.push(maybePagePathValueNode);
118
+ }
119
+ }
120
+ if (children) {
121
+ children.forEach((node) => walkNode(node, pagePathNodes));
122
+ }
123
+ }
124
+ function normalizeUniAppXAppPagesJson(jsonStr) {
125
+ checkPagesJson(jsonStr, process.env.UNI_INPUT_DIR);
126
+ const pagesJson = {
127
+ pages: [],
128
+ globalStyle: {},
129
+ };
130
+ let userPagesJson = {
131
+ pages: [],
132
+ globalStyle: {},
133
+ };
134
+ // preprocess
135
+ try {
136
+ userPagesJson = (0, json_1.parseJson)(jsonStr, true);
137
+ }
138
+ catch (e) {
139
+ console.error(`[vite] Error: pages.json parse failed.\n`, jsonStr, e);
140
+ }
141
+ // pages
142
+ (0, pages_1.validatePages)(userPagesJson, jsonStr);
143
+ userPagesJson.subPackages =
144
+ userPagesJson.subPackages || userPagesJson.subpackages;
145
+ // subPackages
146
+ if (userPagesJson.subPackages) {
147
+ userPagesJson.pages.push(...normalizeSubPackages(userPagesJson.subPackages));
148
+ }
149
+ pagesJson.pages = userPagesJson.pages;
150
+ // pageStyle
151
+ normalizePages(pagesJson.pages);
152
+ // globalStyle
153
+ pagesJson.globalStyle = normalizePageStyle(userPagesJson.globalStyle);
154
+ // tabBar
155
+ if (userPagesJson.tabBar) {
156
+ pagesJson.tabBar = userPagesJson.tabBar;
157
+ }
158
+ // condition
159
+ if (userPagesJson.condition) {
160
+ pagesJson.condition = userPagesJson.condition;
161
+ }
162
+ // uniIdRouter
163
+ if (userPagesJson.uniIdRouter) {
164
+ pagesJson.uniIdRouter = userPagesJson.uniIdRouter;
165
+ }
166
+ return pagesJson;
167
+ }
168
+ exports.normalizeUniAppXAppPagesJson = normalizeUniAppXAppPagesJson;
169
+ function normalizeSubPackages(subPackages) {
170
+ const pages = [];
171
+ if ((0, shared_1.isArray)(subPackages)) {
172
+ subPackages.forEach(({ root, pages: subPages }) => {
173
+ if (root && subPages.length) {
174
+ subPages.forEach((subPage) => {
175
+ subPage.path = (0, utils_1.normalizePath)(path_1.default.join(root, subPage.path));
176
+ subPage.style = subPage.style;
177
+ pages.push(subPage);
178
+ });
179
+ }
180
+ });
181
+ }
182
+ return pages;
183
+ }
184
+ function normalizePages(pages) {
185
+ pages.forEach((page) => {
186
+ page.style = normalizePageStyle(page.style);
187
+ });
188
+ }
189
+ function normalizePageStyle(pageStyle) {
190
+ if (pageStyle) {
191
+ (0, shared_1.extend)(pageStyle, pageStyle['app']);
192
+ (0, pages_1.removePlatformStyle)(pageStyle);
193
+ return pageStyle;
194
+ }
195
+ return {};
196
+ }
197
+ /**
198
+ * TODO 应该闭包,通过globalThis赋值?
199
+ * @param pagesJson
200
+ * @param manifestJson
201
+ * @returns
202
+ */
203
+ function normalizeUniAppXAppConfig(pagesJson, manifestJson) {
204
+ return `const __uniConfig = ${(0, uniConfig_1.normalizeAppXUniConfig)(pagesJson, manifestJson)};
205
+ const __uniRoutes = ${(0, uniRoutes_1.normalizeAppUniRoutes)(pagesJson)}.map(uniRoute=>(uniRoute.meta.route=uniRoute.path,__uniConfig.pages.push(uniRoute.path),uniRoute.path='/'+uniRoute.path,uniRoute));
206
+
207
+ `;
208
+ }
209
+ exports.normalizeUniAppXAppConfig = normalizeUniAppXAppConfig;
@@ -0,0 +1,2 @@
1
+ export declare function parseUniXFlexDirection(manifestJson: Record<string, any>): any;
2
+ export declare function parseUniXSplashScreen(manifestJson: Record<string, any>): false | object;
@@ -0,0 +1,21 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.parseUniXSplashScreen = exports.parseUniXFlexDirection = void 0;
4
+ const shared_1 = require("@vue/shared");
5
+ const flexDirs = ['row', 'row-reverse', 'column', 'column-reverse'];
6
+ function parseUniXFlexDirection(manifestJson) {
7
+ const flexDir = manifestJson?.['uni-app-x']?.['flex-direction'];
8
+ if (flexDir && flexDirs.includes(flexDir)) {
9
+ return flexDir;
10
+ }
11
+ return 'column';
12
+ }
13
+ exports.parseUniXFlexDirection = parseUniXFlexDirection;
14
+ function parseUniXSplashScreen(manifestJson) {
15
+ const splashScreen = manifestJson?.['app']?.['splashScreen'];
16
+ if ((0, shared_1.isPlainObject)(splashScreen)) {
17
+ return splashScreen;
18
+ }
19
+ return false;
20
+ }
21
+ exports.parseUniXSplashScreen = parseUniXSplashScreen;
@@ -0,0 +1 @@
1
+ export declare function normalizeAppXUniConfig(pagesJson: UniApp.PagesJson, manifestJson: Record<string, any>): string;
@@ -0,0 +1,18 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.normalizeAppXUniConfig = void 0;
4
+ const uniConfig_1 = require("../app/pages/uniConfig");
5
+ function normalizeAppXUniConfig(pagesJson, manifestJson) {
6
+ const config = {
7
+ pages: [],
8
+ globalStyle: pagesJson.globalStyle,
9
+ appname: manifestJson.name || '',
10
+ compilerVersion: process.env.UNI_COMPILER_VERSION,
11
+ ...(0, uniConfig_1.parseEntryPagePath)(pagesJson),
12
+ tabBar: pagesJson.tabBar,
13
+ fallbackLocale: manifestJson.fallbackLocale,
14
+ };
15
+ // TODO 待支持分包
16
+ return JSON.stringify(config);
17
+ }
18
+ exports.normalizeAppXUniConfig = normalizeAppXUniConfig;
package/dist/utils.d.ts CHANGED
@@ -21,3 +21,5 @@ export declare function resolveSourceMapPath(outputDir?: string, platform?: UniA
21
21
  export declare function installDepTips(type: 'dependencies' | 'devDependencies', module: string, version?: string): string;
22
22
  export declare function isAppVue(filename: string): boolean;
23
23
  export declare function resolveAppVue(inputDir: string): string;
24
+ export declare function parseImporter(importer: string): string;
25
+ export declare function createResolveErrorMsg(source: string, importer: string): string;
package/dist/utils.js CHANGED
@@ -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.resolveAppVue = exports.isAppVue = exports.installDepTips = exports.resolveSourceMapPath = exports.pathToGlob = exports.normalizeParsePlugins = exports.normalizeMiniProgramFilename = exports.normalizeNodeModules = exports.removeExt = exports.normalizePagePath = exports.normalizeIdentifier = exports.checkElementNodeTag = exports.normalizePath = exports.isWindows = exports.isRunningWithYarnPnp = exports.isArray = exports.capitalize = exports.camelize = exports.version = exports.hash = void 0;
6
+ exports.createResolveErrorMsg = exports.parseImporter = exports.resolveAppVue = exports.isAppVue = exports.installDepTips = exports.resolveSourceMapPath = exports.pathToGlob = exports.normalizeParsePlugins = exports.normalizeMiniProgramFilename = exports.normalizeNodeModules = exports.removeExt = exports.normalizePagePath = exports.normalizeIdentifier = exports.checkElementNodeTag = exports.normalizePath = exports.isWindows = exports.isRunningWithYarnPnp = exports.isArray = exports.capitalize = exports.camelize = exports.version = exports.hash = void 0;
7
7
  const fs_1 = __importDefault(require("fs"));
8
8
  const os_1 = __importDefault(require("os"));
9
9
  const path_1 = __importDefault(require("path"));
@@ -129,3 +129,15 @@ function resolveAppVue(inputDir) {
129
129
  return normalizePath(path_1.default.resolve(inputDir, 'App.vue'));
130
130
  }
131
131
  exports.resolveAppVue = resolveAppVue;
132
+ function parseImporter(importer) {
133
+ importer = importer.split('?')[0];
134
+ if (path_1.default.isAbsolute(importer)) {
135
+ return normalizePath(path_1.default.relative(process.env.UNI_INPUT_DIR, importer));
136
+ }
137
+ return importer;
138
+ }
139
+ exports.parseImporter = parseImporter;
140
+ function createResolveErrorMsg(source, importer) {
141
+ return `Could not resolve "${source}" from "${parseImporter(importer)}"`;
142
+ }
143
+ exports.createResolveErrorMsg = createResolveErrorMsg;
@@ -9,4 +9,4 @@ export * from './uts/uni_modules';
9
9
  export * from './uts/uvue';
10
10
  export { assetPlugin, parseAssets, getAssetHash } from './vitejs/plugins/asset';
11
11
  export { isCSSRequest, cssPlugin, cssPostPlugin, minifyCSS, cssLangRE, commonjsProxyRE, } from './vitejs/plugins/css';
12
- export { generateCodeFrame, locToStartAndEnd } from './vitejs/utils';
12
+ export { generateCodeFrame, locToStartAndEnd, offsetToStartAndEnd, } from './vitejs/utils';
@@ -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.locToStartAndEnd = exports.generateCodeFrame = exports.commonjsProxyRE = exports.cssLangRE = exports.minifyCSS = exports.cssPostPlugin = exports.cssPlugin = exports.isCSSRequest = exports.getAssetHash = exports.parseAssets = exports.assetPlugin = void 0;
17
+ exports.offsetToStartAndEnd = exports.locToStartAndEnd = exports.generateCodeFrame = exports.commonjsProxyRE = exports.cssLangRE = exports.minifyCSS = exports.cssPostPlugin = exports.cssPlugin = exports.isCSSRequest = exports.getAssetHash = exports.parseAssets = exports.assetPlugin = void 0;
18
18
  __exportStar(require("./cssScoped"), exports);
19
19
  __exportStar(require("./copy"), exports);
20
20
  __exportStar(require("./inject"), exports);
@@ -38,3 +38,4 @@ Object.defineProperty(exports, "commonjsProxyRE", { enumerable: true, get: funct
38
38
  var utils_1 = require("./vitejs/utils");
39
39
  Object.defineProperty(exports, "generateCodeFrame", { enumerable: true, get: function () { return utils_1.generateCodeFrame; } });
40
40
  Object.defineProperty(exports, "locToStartAndEnd", { enumerable: true, get: function () { return utils_1.locToStartAndEnd; } });
41
+ Object.defineProperty(exports, "offsetToStartAndEnd", { enumerable: true, get: function () { return utils_1.offsetToStartAndEnd; } });
@@ -2,6 +2,7 @@ import { ExistingRawSourceMap, RollupError } from 'rollup';
2
2
  import { Plugin } from '../plugin';
3
3
  import { ResolvedConfig } from '../config';
4
4
  import * as Postcss from 'postcss';
5
+ import { SFCDescriptor } from '@vue/compiler-sfc';
5
6
  export interface CSSOptions {
6
7
  /**
7
8
  * https://github.com/css-modules/postcss-modules
@@ -32,6 +33,7 @@ export declare const isDirectCSSRequest: (request: string) => boolean;
32
33
  */
33
34
  export declare function cssPlugin(config: ResolvedConfig, options?: {
34
35
  isAppX: boolean;
36
+ getDescriptor?(filename: string): SFCDescriptor | undefined;
35
37
  }): Plugin;
36
38
  /**
37
39
  * Plugin applied after user plugins
@@ -37,11 +37,15 @@ const utils_1 = require("../utils");
37
37
  const asset_1 = require("./asset");
38
38
  const magic_string_1 = __importDefault(require("magic-string"));
39
39
  const Postcss = __importStar(require("postcss"));
40
+ const shared_1 = require("@vue/shared");
40
41
  const preprocess_1 = require("../../../../preprocess");
41
42
  const uniapp_1 = require("../../../../postcss/plugins/uniapp");
42
43
  const cleanString_1 = require("../cleanString");
43
- const shared_1 = require("@vue/shared");
44
44
  const constants_1 = require("../../../../constants");
45
+ const utils_2 = require("../../../utils/utils");
46
+ const compiler_core_1 = require("@vue/compiler-core");
47
+ const utils_3 = require("../../../../utils");
48
+ const utils_4 = require("../../../utils");
45
49
  const cssLangs = `\\.(css|less|sass|scss|styl|stylus|pcss|postcss)($|\\?)`;
46
50
  exports.cssLangRE = new RegExp(cssLangs);
47
51
  const cssModuleRE = new RegExp(`\\.module${cssLangs}`);
@@ -54,10 +58,46 @@ const isDirectCSSRequest = (request) => exports.cssLangRE.test(request) && direc
54
58
  exports.isDirectCSSRequest = isDirectCSSRequest;
55
59
  const cssModulesCache = new WeakMap();
56
60
  const postcssConfigCache = new WeakMap();
61
+ function wrapResolve(resolve, code, source, getDescriptor) {
62
+ if (!source) {
63
+ return resolve;
64
+ }
65
+ return async (id, importer, aliasOnly, ssr) => {
66
+ try {
67
+ return await resolve(id, importer, aliasOnly, ssr);
68
+ }
69
+ catch (e) {
70
+ if (importer && getDescriptor) {
71
+ const { filename, query } = (0, utils_4.parseVueRequest)(importer);
72
+ // 仅处理 vue | uvue
73
+ if (query.vue &&
74
+ query.type === 'style' &&
75
+ 'index' in query &&
76
+ /\.[u]vue/.test(filename)) {
77
+ const descriptor = getDescriptor(importer.split('?')[0]);
78
+ if (descriptor) {
79
+ const styleBlock = descriptor.styles[query.index];
80
+ if (styleBlock) {
81
+ code = descriptor.source;
82
+ const offsetLine = styleBlock.loc.start.line - 1;
83
+ source.start.line = source.start.line + offsetLine;
84
+ source.end.line = source.end.line + offsetLine;
85
+ }
86
+ }
87
+ }
88
+ }
89
+ const error = (0, utils_2.createRollupError)('', importer || '', (0, compiler_core_1.createCompilerError)(0, { start: source.start, end: source.end, source: '' }, { 0: (0, utils_3.createResolveErrorMsg)(id, importer) }), code);
90
+ error.line = source.start.line;
91
+ error.column = source.start.column;
92
+ throw error;
93
+ }
94
+ return;
95
+ };
96
+ }
57
97
  /**
58
98
  * Plugin applied before user plugins
59
99
  */
60
- function cssPlugin(config, options) {
100
+ function cssPlugin(config, options = { isAppX: false }) {
61
101
  let server;
62
102
  let moduleCache;
63
103
  const resolveUrl = config.createResolver({
@@ -80,12 +120,12 @@ function cssPlugin(config, options) {
80
120
  if (!exports.cssLangRE.test(id) || exports.commonjsProxyRE.test(id)) {
81
121
  return;
82
122
  }
83
- const urlReplacer = async (url, importer) => {
123
+ const urlReplacer = async (url, importer, source) => {
84
124
  if (url.startsWith('/') && !url.startsWith('//')) {
85
125
  // /static/logo.png => @/static/logo.png
86
126
  url = '@' + url;
87
127
  }
88
- const resolved = await resolveUrl(url, importer);
128
+ const resolved = await wrapResolve(resolveUrl, source?.input.css || raw, source, options.getDescriptor)(url, importer);
89
129
  if (resolved) {
90
130
  return (0, asset_1.fileToUrl)(resolved, config, options?.isAppX
91
131
  ? {
@@ -602,7 +642,7 @@ const UrlRewritePostcssPlugin = (opts) => {
602
642
  if (isCssUrl || isCssImageSet) {
603
643
  const replacerForDeclaration = (rawUrl) => {
604
644
  const importer = declaration.source?.input.file;
605
- return opts.replacer(rawUrl, importer);
645
+ return opts.replacer(rawUrl, importer, declaration.source);
606
646
  };
607
647
  const rewriterToUse = isCssImageSet
608
648
  ? rewriteCssImageSet
@@ -1,4 +1,5 @@
1
1
  import type { DecodedSourceMap, RawSourceMap } from '@ampproject/remapping';
2
+ import { SourceLocation } from '@vue/compiler-core';
2
3
  export declare function slash(p: string): string;
3
4
  export declare const bareImportRE: RegExp;
4
5
  export declare const deepImportRE: RegExp;
@@ -15,6 +16,11 @@ export declare const multilineCommentsRE: RegExp;
15
16
  export declare function asyncReplace(input: string, re: RegExp, replacer: (match: RegExpExecArray) => string | Promise<string>): Promise<string>;
16
17
  export declare function isObject(value: unknown): value is Record<string, any>;
17
18
  export declare function pad(source: string, n?: number): string;
19
+ export declare function offsetToStartAndEnd(source: string, startOffset: number, endOffset: number): SourceLocation;
20
+ export declare function offsetToLineColumn(source: string, offset: number): {
21
+ line: number;
22
+ column: number;
23
+ };
18
24
  export declare function posToNumber(source: string, pos: number | {
19
25
  line: number;
20
26
  column: number;
@@ -30,7 +36,7 @@ export declare function locToStartAndEnd(source: string, loc: {
30
36
  };
31
37
  }): {
32
38
  start: number;
33
- end: number;
39
+ end: number | undefined;
34
40
  };
35
41
  export declare function generateCodeFrame(source: string, start?: number | {
36
42
  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.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
  */
@@ -56,6 +56,32 @@ 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 offsetToStartAndEnd(source, startOffset, endOffset) {
60
+ const lines = source.split(splitRE);
61
+ return {
62
+ start: offsetToLineColumnByLines(lines, startOffset),
63
+ end: offsetToLineColumnByLines(lines, endOffset),
64
+ source: '',
65
+ };
66
+ }
67
+ 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
+ function offsetToLineColumn(source, offset) {
82
+ return offsetToLineColumnByLines(source.split(splitRE), offset);
83
+ }
84
+ exports.offsetToLineColumn = offsetToLineColumn;
59
85
  function posToNumber(source, pos) {
60
86
  if (typeof pos === 'number')
61
87
  return pos;
@@ -73,18 +99,29 @@ function posToNumberByLines(lines, line, column) {
73
99
  function locToStartAndEnd(source, loc) {
74
100
  const lines = source.split(splitRE);
75
101
  const start = posToNumberByLines(lines, loc.start.line, loc.start.column);
76
- const end = posToNumberByLines(lines, loc.end.line, loc.end.column);
102
+ const end = loc.end
103
+ ? posToNumberByLines(lines, loc.end.line, loc.end.column)
104
+ : undefined;
77
105
  return { start, end };
78
106
  }
79
107
  exports.locToStartAndEnd = locToStartAndEnd;
80
108
  function generateCodeFrame(source, start = 0, end) {
81
109
  start = posToNumber(source, start);
82
110
  end = end || start;
83
- const lines = source.split(splitRE);
111
+ // Split the content into individual lines but capture the newline sequence
112
+ // that separated each line. This is important because the actual sequence is
113
+ // needed to properly take into account the full line length for offset
114
+ // comparison
115
+ let lines = source.split(/(\r?\n)/);
116
+ // Separate the lines and newline sequences into separate arrays for easier referencing
117
+ const newlineSequences = lines.filter((_, idx) => idx % 2 === 1);
118
+ lines = lines.filter((_, idx) => idx % 2 === 0);
84
119
  let count = 0;
85
120
  const res = [];
86
121
  for (let i = 0; i < lines.length; i++) {
87
- count += lines[i].length + 1;
122
+ count +=
123
+ lines[i].length +
124
+ ((newlineSequences[i] && newlineSequences[i].length) || 0);
88
125
  if (count >= start) {
89
126
  for (let j = i - range; j <= i + range || end > count; j++) {
90
127
  if (j < 0 || j >= lines.length)
@@ -92,9 +129,10 @@ function generateCodeFrame(source, start = 0, end) {
92
129
  const line = j + 1;
93
130
  res.push(`${line}${' '.repeat(Math.max(3 - String(line).length, 0))}| ${lines[j]}`);
94
131
  const lineLength = lines[j].length;
132
+ const newLineSeqLength = (newlineSequences[j] && newlineSequences[j].length) || 0;
95
133
  if (j === i) {
96
134
  // push underline
97
- const pad = start - (count - lineLength) + 1;
135
+ const pad = start - (count - (lineLength + newLineSeqLength));
98
136
  const length = Math.max(1, end > count ? lineLength - pad : end - start);
99
137
  res.push(` | ` + ' '.repeat(pad) + '^'.repeat(length));
100
138
  }
@@ -103,7 +141,7 @@ function generateCodeFrame(source, start = 0, end) {
103
141
  const length = Math.max(Math.min(end - count, lineLength), 1);
104
142
  res.push(` | ` + '^'.repeat(length));
105
143
  }
106
- count += lineLength + 1;
144
+ count += lineLength + newLineSeqLength;
107
145
  }
108
146
  }
109
147
  break;
@@ -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,8 @@
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");
5
+ const shared_1 = require("@vue/shared");
4
6
  function withSourcemap(config) {
5
7
  if (config.command === 'serve') {
6
8
  return true;
@@ -22,3 +24,39 @@ function isSsr(command, config) {
22
24
  return false;
23
25
  }
24
26
  exports.isSsr = isSsr;
27
+ function createRollupError(plugin, id, error, source) {
28
+ const { message, name, stack } = error;
29
+ const rollupError = (0, shared_1.extend)(new Error(message), {
30
+ id,
31
+ plugin,
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
+ if (id) {
52
+ // 指定了id后,不让后续的rollup重写
53
+ Object.defineProperty(rollupError, 'id', {
54
+ get() {
55
+ return id;
56
+ },
57
+ set(_v) { },
58
+ });
59
+ }
60
+ return rollupError;
61
+ }
62
+ 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-3090820231124001",
3
+ "version": "3.0.0-3090920231225001",
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-3090820231124001",
29
- "@dcloudio/uni-shared": "3.0.0-3090820231124001",
28
+ "@dcloudio/uni-i18n": "3.0.0-3090920231225001",
29
+ "@dcloudio/uni-shared": "3.0.0-3090920231225001",
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-3090820231124001",
67
+ "@dcloudio/uni-uts-v1": "3.0.0-3090920231225001",
68
68
  "@types/babel__core": "^7.1.19",
69
69
  "@types/debug": "^4.1.7",
70
70
  "@types/estree": "^0.0.51",
@@ -1 +0,0 @@
1
- export declare function normalizeUniAppXAppPagesJson(jsonStr: string): UniApp.PagesJson;
@@ -1,79 +0,0 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.normalizeUniAppXAppPagesJson = void 0;
7
- const path_1 = __importDefault(require("path"));
8
- const shared_1 = require("@vue/shared");
9
- const json_1 = require("./json");
10
- const pages_1 = require("./pages");
11
- const utils_1 = require("../utils");
12
- function normalizeUniAppXAppPagesJson(jsonStr) {
13
- const pagesJson = {
14
- pages: [],
15
- globalStyle: {},
16
- };
17
- let userPagesJson = {
18
- pages: [],
19
- globalStyle: {},
20
- };
21
- // preprocess
22
- try {
23
- userPagesJson = (0, json_1.parseJson)(jsonStr, true);
24
- }
25
- catch (e) {
26
- console.error(`[vite] Error: pages.json parse failed.\n`, jsonStr, e);
27
- }
28
- // pages
29
- (0, pages_1.validatePages)(userPagesJson, jsonStr);
30
- userPagesJson.subPackages =
31
- userPagesJson.subPackages || userPagesJson.subpackages;
32
- // subPackages
33
- if (userPagesJson.subPackages) {
34
- userPagesJson.pages.push(...normalizeSubPackages(userPagesJson.subPackages));
35
- }
36
- pagesJson.pages = userPagesJson.pages;
37
- // pageStyle
38
- normalizePages(pagesJson.pages);
39
- // globalStyle
40
- pagesJson.globalStyle = normalizePageStyle(userPagesJson.globalStyle);
41
- // tabBar
42
- if (userPagesJson.tabBar) {
43
- pagesJson.tabBar = userPagesJson.tabBar;
44
- }
45
- // condition
46
- if (userPagesJson.condition) {
47
- pagesJson.condition = userPagesJson.condition;
48
- }
49
- return pagesJson;
50
- }
51
- exports.normalizeUniAppXAppPagesJson = normalizeUniAppXAppPagesJson;
52
- function normalizeSubPackages(subPackages) {
53
- const pages = [];
54
- if ((0, shared_1.isArray)(subPackages)) {
55
- subPackages.forEach(({ root, pages: subPages }) => {
56
- if (root && subPages.length) {
57
- subPages.forEach((subPage) => {
58
- subPage.path = (0, utils_1.normalizePath)(path_1.default.join(root, subPage.path));
59
- subPage.style = subPage.style;
60
- pages.push(subPage);
61
- });
62
- }
63
- });
64
- }
65
- return pages;
66
- }
67
- function normalizePages(pages) {
68
- pages.forEach((page) => {
69
- page.style = normalizePageStyle(page.style);
70
- });
71
- }
72
- function normalizePageStyle(pageStyle) {
73
- if (pageStyle) {
74
- (0, shared_1.extend)(pageStyle, pageStyle['app']);
75
- (0, pages_1.removePlatformStyle)(pageStyle);
76
- return pageStyle;
77
- }
78
- return {};
79
- }