@dcloudio/uni-cli-shared 3.0.0-alpha-3040520220408002 → 3.0.0-alpha-3040620220415001

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/easycom.js CHANGED
@@ -88,7 +88,7 @@ function initEasycom({ dirs, rootDir, custom, extensions = ['.vue', '.jsx', '.ts
88
88
  Object.keys(custom).forEach((name) => {
89
89
  const componentPath = custom[name];
90
90
  easycomsObj[name] = componentPath.startsWith('@/')
91
- ? (0, utils_1.normalizePath)(path_1.default.join(rootDir, componentPath.substr(2)))
91
+ ? (0, utils_1.normalizePath)(path_1.default.join(rootDir, componentPath.slice(2)))
92
92
  : componentPath;
93
93
  });
94
94
  }
package/dist/hbx/log.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { LogErrorOptions } from 'vite';
1
+ import type { LogErrorOptions } from 'vite';
2
2
  import { Formatter } from '../logs/format';
3
3
  export declare function formatAtFilename(filename: string, line?: number, column?: number): string;
4
4
  export declare const h5ServeFormatter: Formatter;
package/dist/hbx/log.js CHANGED
@@ -4,9 +4,13 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.errorFormatter = exports.removeWarnFormatter = exports.removeInfoFormatter = exports.h5ServeFormatter = exports.formatAtFilename = void 0;
7
+ const fs_1 = __importDefault(require("fs"));
7
8
  const path_1 = __importDefault(require("path"));
8
9
  const picocolors_1 = __importDefault(require("picocolors"));
9
10
  const utils_1 = require("../utils");
11
+ const constants_1 = require("../constants");
12
+ const ast_1 = require("../vite/utils/ast");
13
+ const utils_2 = require("../vite/plugins/vitejs/utils");
10
14
  const SIGNAL_H5_LOCAL = ' > Local:';
11
15
  const SIGNAL_H5_NETWORK = ' > Network:';
12
16
  const networkLogs = [];
@@ -75,6 +79,23 @@ function buildErrorMessage(err, args = [], includeStack = true) {
75
79
  var _a, _b;
76
80
  if (err.plugin) {
77
81
  args.push(`${picocolors_1.default.magenta('[plugin:' + err.plugin + ']')} ${picocolors_1.default.red(err.message)}`);
82
+ if (err.loc &&
83
+ err.hook === 'transform' &&
84
+ err.plugin === 'rollup-plugin-dynamic-import-variables' &&
85
+ err.id &&
86
+ constants_1.EXTNAME_VUE_RE.test(err.id)) {
87
+ try {
88
+ const ast = (0, ast_1.parseVue)(fs_1.default.readFileSync(err.id, 'utf8'), []);
89
+ const scriptNode = ast.children.find((node) => node.type === 1 /* ELEMENT */ && node.tag === 'script');
90
+ if (scriptNode) {
91
+ const scriptLoc = scriptNode.loc;
92
+ args.push(picocolors_1.default.yellow(pad((0, utils_2.generateCodeFrame)(scriptLoc.source, err.loc))));
93
+ // correct error location
94
+ err.loc.line = scriptLoc.start.line + err.loc.line - 1;
95
+ }
96
+ }
97
+ catch (e) { }
98
+ }
78
99
  }
79
100
  else {
80
101
  args.push(picocolors_1.default.red(err.message));
package/dist/resolve.d.ts CHANGED
@@ -3,4 +3,5 @@ export declare function relativeFile(from: string, to: string): string;
3
3
  export declare const resolveMainPathOnce: (inputDir: string) => string;
4
4
  export declare function getBuiltInPaths(): string[];
5
5
  export declare function resolveBuiltIn(path: string): string;
6
+ export declare function resolveVueI18nRuntime(): string;
6
7
  export declare function resolveComponentsLibPath(): string;
package/dist/resolve.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.resolveComponentsLibPath = exports.resolveBuiltIn = exports.getBuiltInPaths = exports.resolveMainPathOnce = exports.relativeFile = exports.requireResolve = void 0;
6
+ exports.resolveComponentsLibPath = exports.resolveVueI18nRuntime = exports.resolveBuiltIn = exports.getBuiltInPaths = exports.resolveMainPathOnce = exports.relativeFile = exports.requireResolve = void 0;
7
7
  const fs_1 = __importDefault(require("fs"));
8
8
  const path_1 = __importDefault(require("path"));
9
9
  const debug_1 = __importDefault(require("debug"));
@@ -46,7 +46,7 @@ function resolveNodeModulePath(modulePath) {
46
46
  }
47
47
  const index = modulePath.lastIndexOf('node_modules');
48
48
  if (index > -1) {
49
- nodeModulesPaths.push(path_1.default.join(modulePath.substr(0, index), 'node_modules'));
49
+ nodeModulesPaths.push(path_1.default.join(modulePath.slice(0, index), 'node_modules'));
50
50
  }
51
51
  return nodeModulesPaths;
52
52
  }
@@ -87,6 +87,10 @@ function resolveBuiltIn(path) {
87
87
  return require.resolve(path, { paths: getBuiltInPaths() });
88
88
  }
89
89
  exports.resolveBuiltIn = resolveBuiltIn;
90
+ function resolveVueI18nRuntime() {
91
+ return path_1.default.resolve(__dirname, '../lib/vue-i18n/dist/vue-i18n.runtime.esm-bundler.js');
92
+ }
93
+ exports.resolveVueI18nRuntime = resolveVueI18nRuntime;
90
94
  let componentsLibPath = '';
91
95
  function resolveComponentsLibPath() {
92
96
  if (!componentsLibPath) {
@@ -40,6 +40,7 @@ export declare function cssPostPlugin(config: ResolvedConfig, { chunkCssFilename
40
40
  }): Plugin;
41
41
  export declare const cssUrlRE: RegExp;
42
42
  export declare function minifyCSS(css: string, config: ResolvedConfig): Promise<string>;
43
+ export declare function hoistAtRules(css: string): Promise<string>;
43
44
  export interface StylePreprocessorResults {
44
45
  code: string;
45
46
  map?: object;
@@ -26,7 +26,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
26
26
  return (mod && mod.__esModule) ? mod : { "default": mod };
27
27
  };
28
28
  Object.defineProperty(exports, "__esModule", { value: true });
29
- exports.minifyCSS = exports.cssUrlRE = exports.cssPostPlugin = exports.cssPlugin = exports.isDirectCSSRequest = exports.isCSSRequest = exports.commonjsProxyRE = exports.cssLangRE = void 0;
29
+ exports.hoistAtRules = exports.minifyCSS = exports.cssUrlRE = exports.cssPostPlugin = exports.cssPlugin = exports.isDirectCSSRequest = exports.isCSSRequest = exports.commonjsProxyRE = exports.cssLangRE = void 0;
30
30
  const fs_1 = __importDefault(require("fs"));
31
31
  const path_1 = __importDefault(require("path"));
32
32
  const fast_glob_1 = __importDefault(require("fast-glob"));
@@ -35,6 +35,7 @@ const postcss_load_config_1 = __importDefault(require("postcss-load-config"));
35
35
  const pluginutils_1 = require("@rollup/pluginutils");
36
36
  const utils_1 = require("../utils");
37
37
  const asset_1 = require("./asset");
38
+ const magic_string_1 = __importDefault(require("magic-string"));
38
39
  const esbuild_1 = require("esbuild");
39
40
  const preprocess_1 = require("../../../../preprocess");
40
41
  const constants_1 = require("../../../../constants");
@@ -179,6 +180,11 @@ function cssPostPlugin(config, { chunkCssFilename, chunkCssCode, }) {
179
180
  css = css.replace(asset_1.assetUrlRE, (_, fileHash, postfix = '') => {
180
181
  return (0, utils_1.normalizePath)(path_1.default.relative(path_1.default.dirname(filename), (0, asset_1.getAssetFilename)(fileHash, config) + postfix));
181
182
  });
183
+ // only external @imports and @charset should exist at this point
184
+ // hoist them to the top of the CSS chunk per spec (#1845 and #6333)
185
+ if (css.includes('@import') || css.includes('@charset')) {
186
+ css = await hoistAtRules(css);
187
+ }
182
188
  if (minify && config.build.minify) {
183
189
  css = await minifyCSS(css, config);
184
190
  }
@@ -503,34 +509,51 @@ async function doUrlReplace(rawUrl, matched, replacer) {
503
509
  return `url(${wrap}${await replacer(rawUrl)}${wrap})`;
504
510
  }
505
511
  async function minifyCSS(css, config) {
506
- const { code, warnings } = await (0, esbuild_1.transform)(css, {
507
- loader: 'css',
508
- minify: true,
509
- target: config.build.cssTarget || undefined,
510
- });
511
- if (warnings.length) {
512
- const msgs = await (0, esbuild_1.formatMessages)(warnings, { kind: 'warning' });
513
- config.logger.warn(picocolors_1.default.yellow(`warnings when minifying css:\n${msgs.join('\n')}`));
512
+ try {
513
+ const { code, warnings } = await (0, esbuild_1.transform)(css, {
514
+ loader: 'css',
515
+ minify: true,
516
+ target: config.build.cssTarget || undefined,
517
+ });
518
+ if (warnings.length) {
519
+ const msgs = await (0, esbuild_1.formatMessages)(warnings, { kind: 'warning' });
520
+ config.logger.warn(picocolors_1.default.yellow(`warnings when minifying css:\n${msgs.join('\n')}`));
521
+ }
522
+ return code;
523
+ }
524
+ catch (e) {
525
+ if (e.errors) {
526
+ const msgs = await (0, esbuild_1.formatMessages)(e.errors, { kind: 'error' });
527
+ e.frame = '\n' + msgs.join('\n');
528
+ e.loc = e.errors[0].location;
529
+ }
530
+ throw e;
514
531
  }
515
- return code;
516
532
  }
517
533
  exports.minifyCSS = minifyCSS;
518
- const AtImportHoistPlugin = () => {
519
- return {
520
- postcssPlugin: 'vite-hoist-at-imports',
521
- Once(root) {
522
- const imports = [];
523
- root.walkAtRules((rule) => {
524
- if (rule.name === 'import') {
525
- // record in reverse so that can simply prepend to preserve order
526
- imports.unshift(rule);
527
- }
528
- });
529
- imports.forEach((i) => root.prepend(i));
530
- },
531
- };
532
- };
533
- AtImportHoistPlugin.postcss = true;
534
+ async function hoistAtRules(css) {
535
+ const s = new magic_string_1.default(css);
536
+ // #1845
537
+ // CSS @import can only appear at top of the file. We need to hoist all @import
538
+ // to top when multiple files are concatenated.
539
+ // match until semicolon that's not in quotes
540
+ s.replace(/@import\s*(?:url\([^\)]*\)|"[^"]*"|'[^']*'|[^;]*).*?;/gm, (match) => {
541
+ s.appendLeft(0, match);
542
+ return '';
543
+ });
544
+ // #6333
545
+ // CSS @charset must be the top-first in the file, hoist the first to top
546
+ let foundCharset = false;
547
+ s.replace(/@charset\s*(?:"[^"]*"|'[^']*'|[^;]*).*?;/gm, (match) => {
548
+ if (!foundCharset) {
549
+ s.prepend(match);
550
+ foundCharset = true;
551
+ }
552
+ return '';
553
+ });
554
+ return s.toString();
555
+ }
556
+ exports.hoistAtRules = hoistAtRules;
534
557
  const loadedPreprocessors = {};
535
558
  function loadPreprocessor(lang, root) {
536
559
  var _a, _b;