@dcloudio/uni-cli-shared 3.0.0-alpha-1000920260522001 → 3.0.0-alpha-1000920260522733

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,5 @@
1
1
  export { formatAtFilename, createErrorWithBlockFlag } from './log';
2
2
  export * from './env';
3
3
  export { initModuleAlias, installHBuilderXPlugin, formatInstallHBuilderXPluginTips, } from './alias';
4
- export declare function uniHBuilderXConsolePlugin(method?: string): import("vite/dist/node").Plugin<any>;
4
+ export declare function uniHBuilderXConsolePlugin(method?: string): import("vite").Plugin<any>;
5
5
  export declare function isEnableConsole(): boolean;
package/dist/i18n.js CHANGED
@@ -47,51 +47,36 @@ function isUniAppLocaleFile(filepath) {
47
47
  return localeJsonRE.test(path_1.default.basename(filepath));
48
48
  }
49
49
  exports.isUniAppLocaleFile = isUniAppLocaleFile;
50
- const localeJsonCache = new Map();
51
50
  function parseLocaleJson(filepath) {
52
- const { mtimeMs, size } = fs_1.default.statSync(filepath);
53
- const cached = localeJsonCache.get(filepath);
54
- if (cached && cached.mtimeMs === mtimeMs && cached.size === size) {
55
- return cached.json;
56
- }
57
51
  let jsonObj = (0, json_1.parseJson)(fs_1.default.readFileSync(filepath, 'utf8'), false, filepath);
58
52
  if (isUniAppLocaleFile(filepath)) {
59
53
  jsonObj = jsonObj.common || {};
60
54
  }
61
- localeJsonCache.set(filepath, { mtimeMs, size, json: jsonObj });
62
55
  return jsonObj;
63
56
  }
64
- const localeFilesCache = new Map();
65
57
  function getLocaleFiles(cwd) {
66
- let mtimeMs;
67
- try {
68
- mtimeMs = fs_1.default.statSync(cwd).mtimeMs;
69
- }
70
- catch {
71
- return [];
72
- }
73
- const cached = localeFilesCache.get(cwd);
74
- if (cached && cached.mtimeMs === mtimeMs) {
75
- return cached.files;
76
- }
77
- const files = (0, fast_glob_1.sync)('*.json', { cwd, absolute: true });
78
- localeFilesCache.set(cwd, { mtimeMs, files });
79
- return files;
58
+ return (0, fast_glob_1.sync)('*.json', { cwd, absolute: true });
80
59
  }
81
60
  exports.getLocaleFiles = getLocaleFiles;
82
61
  function initLocales(dir, withMessages = true) {
83
- return getLocaleFiles(dir).reduce((res, filepath) => {
84
- const filename = path_1.default.basename(filepath);
85
- try {
86
- const locale = filename.replace(/(uni-app.)?(.*).json/, '$2');
87
- if (withMessages) {
88
- (0, shared_1.extend)(res[locale] || (res[locale] = {}), parseLocaleJson(filepath));
89
- }
90
- else {
91
- res[locale] = {};
62
+ if (!fs_1.default.existsSync(dir)) {
63
+ return {};
64
+ }
65
+ return fs_1.default.readdirSync(dir).reduce((res, filename) => {
66
+ if (path_1.default.extname(filename) === '.json') {
67
+ try {
68
+ const locale = path_1.default
69
+ .basename(filename)
70
+ .replace(/(uni-app.)?(.*).json/, '$2');
71
+ if (withMessages) {
72
+ (0, shared_1.extend)(res[locale] || (res[locale] = {}), parseLocaleJson(path_1.default.join(dir, filename)));
73
+ }
74
+ else {
75
+ res[locale] = {};
76
+ }
92
77
  }
78
+ catch (e) { }
93
79
  }
94
- catch { }
95
80
  return res;
96
81
  }, {});
97
82
  }
@@ -19,25 +19,12 @@ function rewriteConsoleExpr(method, id, filename, code, sourceMap = false) {
19
19
  if (s.hasChanged()) {
20
20
  return {
21
21
  code: s.toString(),
22
- map: sourceMap
23
- ? normalizeSourceMap(s.generateMap({ hires: true }))
24
- : { mappings: '' },
22
+ map: sourceMap ? s.generateMap({ hires: true }) : { mappings: '' },
25
23
  };
26
24
  }
27
25
  return { code, map: null };
28
26
  }
29
27
  exports.rewriteConsoleExpr = rewriteConsoleExpr;
30
- function normalizeSourceMap(map) {
31
- return {
32
- ...map,
33
- file: map.file || '',
34
- names: map.names || [],
35
- sources: map.sources || [],
36
- sourcesContent: map.sourcesContent || [],
37
- toString: () => map.toString(),
38
- toUrl: () => map.toUrl(),
39
- };
40
- }
41
28
  function restoreConsoleExpr(code) {
42
29
  return code.replace(/(?:uni\.)?__f__\('([^']+)','at ([^:]+):(\d+)',/g, 'console.$1(');
43
30
  }
@@ -1,6 +1,5 @@
1
+ import type { PluginContext } from 'rollup';
1
2
  import { type ImportSpecifier } from 'es-module-lexer';
2
- import type { Rolldown } from 'vite';
3
- type PluginContext = Rolldown.PluginContext;
4
3
  /**
5
4
  * 暂时没用
6
5
  * @param source
@@ -11,4 +10,3 @@ type PluginContext = Rolldown.PluginContext;
11
10
  export declare function findVueComponentImports(source: string, importer: string, resolve: PluginContext['resolve']): Promise<(ImportSpecifier & {
12
11
  i: string;
13
12
  })[]>;
14
- export {};
@@ -1,7 +1,6 @@
1
- import type { Rolldown } from 'vite';
1
+ import type { EmittedAsset } from 'rollup';
2
2
  import type { AttributeNode, DirectiveNode, ElementNode } from '@vue/compiler-core';
3
3
  import type { MiniProgramComponentsType } from '../json/mp/types';
4
- type EmittedAsset = Rolldown.EmittedAsset;
5
4
  type LazyElementFn = (node: ElementNode, context: {
6
5
  isMiniProgramComponent(name: string): MiniProgramComponentsType | undefined;
7
6
  }) => {
@@ -1,6 +1,5 @@
1
1
  import { type ImportDeclaration, type Program } from '@babel/types';
2
- import type { Rolldown } from 'vite';
3
- type PluginContext = Rolldown.PluginContext;
2
+ import type { PluginContext } from 'rollup';
4
3
  type BindingComponents = Record<string, {
5
4
  tag: string;
6
5
  type: 'unknown' | 'setup' | 'self';
@@ -131,13 +131,18 @@ function uniEncryptUniModulesPlugin() {
131
131
  }
132
132
  delete bundle[fileName];
133
133
  const pkg = `uni_modules/${uniModuleId}/package.json`;
134
- this.emitFile({
134
+ bundle[pkg] = {
135
135
  type: 'asset',
136
136
  fileName: pkg,
137
+ name: pkg,
138
+ names: [pkg],
139
+ originalFileName: null,
140
+ originalFileNames: [],
141
+ needsCodeReference: false,
137
142
  source: genUniModulesPackageJson(uniModuleId, process.env.UNI_INPUT_DIR, {
138
143
  env: (0, uni_modules_cloud_1.initCheckEnv)(),
139
144
  }),
140
- });
145
+ };
141
146
  }
142
147
  else if (fileName.endsWith('.js')) {
143
148
  if (isMp) {
@@ -1,4 +1,5 @@
1
- import type { Plugin, Rolldown } from 'vite';
1
+ import type { Plugin } from 'vite';
2
+ import type { EmittedAsset } from 'rollup';
2
3
  import type { ParserOptions } from '@vue/compiler-core';
3
4
  import type { CompilerOptions, SFCStyleCompileOptions, TemplateCompiler } from '@vue/compiler-sfc';
4
5
  import type { UniViteCopyPluginOptions } from './plugins/copy';
@@ -16,7 +17,7 @@ interface UniVitePluginUniOptions {
16
17
  styleOptions?: Pick<SFCStyleCompileOptions, 'postcssPlugins'>;
17
18
  compilerOptions?: {
18
19
  miniProgram?: {
19
- emitFile?: (emittedFile: Rolldown.EmittedAsset) => string;
20
+ emitFile?: (emittedFile: EmittedAsset) => string;
20
21
  };
21
22
  isNativeTag?: ParserOptions['isNativeTag'];
22
23
  isVoidTag?: ParserOptions['isVoidTag'];
@@ -29,35 +29,32 @@ function uniConsolePlugin(options) {
29
29
  }
30
30
  }
31
31
  },
32
- transform: {
33
- filter: { code: /console\.|__f__/ },
34
- handler(code, id) {
35
- if (dropConsole) {
36
- return;
37
- }
38
- if ((0, filter_1.isRenderjs)(id) || (0, filter_1.isWxs)(id)) {
39
- return {
40
- code: (0, console_1.restoreConsoleExpr)(code),
41
- map: null,
42
- };
43
- }
44
- if (!filter(id))
45
- return null;
46
- if (!(0, utils_1.isJsFile)(id))
47
- return null;
48
- let { filename } = (0, utils_1.parseVueRequest)(id);
49
- if (options.filename) {
50
- filename = options.filename(filename);
51
- }
52
- if (!filename) {
53
- return null;
54
- }
55
- if (!code.includes('console.')) {
56
- return null;
57
- }
58
- debugConsole(id);
59
- return (0, console_1.rewriteConsoleExpr)(options.method, id, filename, code, (0, utils_2.withSourcemap)(resolvedConfig));
60
- },
32
+ transform(code, id) {
33
+ if (dropConsole) {
34
+ return;
35
+ }
36
+ if ((0, filter_1.isRenderjs)(id) || (0, filter_1.isWxs)(id)) {
37
+ return {
38
+ code: (0, console_1.restoreConsoleExpr)(code),
39
+ map: null,
40
+ };
41
+ }
42
+ if (!filter(id))
43
+ return null;
44
+ if (!(0, utils_1.isJsFile)(id))
45
+ return null;
46
+ let { filename } = (0, utils_1.parseVueRequest)(id);
47
+ if (options.filename) {
48
+ filename = options.filename(filename);
49
+ }
50
+ if (!filename) {
51
+ return null;
52
+ }
53
+ if (!code.includes('console.')) {
54
+ return null;
55
+ }
56
+ debugConsole(id);
57
+ return (0, console_1.rewriteConsoleExpr)(options.method, id, filename, code, (0, utils_2.withSourcemap)(resolvedConfig));
61
58
  },
62
59
  };
63
60
  }
@@ -11,7 +11,6 @@ function uniViteCopyPlugin({ targets, }) {
11
11
  let isFirstBuild = true;
12
12
  return {
13
13
  name: 'uni:copy',
14
- enforce: 'pre',
15
14
  apply: 'build',
16
15
  configResolved(config) {
17
16
  resolvedConfig = config;
@@ -13,7 +13,6 @@ const utils_1 = require("../../utils");
13
13
  const utils_2 = require("../../vue/utils");
14
14
  const debugScoped = (0, debug_1.default)('uni:scoped');
15
15
  const SCOPED_RE = /<style\s[^>]*scoped[^>]*>/i;
16
- const VUE_SFC_ID_RE = /\.(?:vue|nvue|uvue)(?:$|\?(?!vue(?:&|=|$)))/;
17
16
  function addScoped(code) {
18
17
  return code.replace(/(<style\b[^><]*)>/gi, (str, $1) => {
19
18
  if ($1.includes('scoped')) {
@@ -33,18 +32,14 @@ function uniRemoveCssScopedPlugin(_ = { filter: () => false }) {
33
32
  return {
34
33
  name: 'uni:css-remove-scoped',
35
34
  enforce: 'pre',
36
- transform: {
37
- // 仅 SFC 主模块需要移除 scoped,跳过 script/style/template 等子模块。
38
- filter: { id: VUE_SFC_ID_RE },
39
- handler(code, id) {
40
- if (!(0, utils_2.isVueSfcFile)(id))
41
- return null;
42
- debugScoped(id);
43
- return {
44
- code: removeScoped(code),
45
- map: null,
46
- };
47
- },
35
+ transform(code, id) {
36
+ if (!(0, utils_2.isVueSfcFile)(id))
37
+ return null;
38
+ debugScoped(id);
39
+ return {
40
+ code: removeScoped(code),
41
+ map: null,
42
+ };
48
43
  },
49
44
  };
50
45
  }
@@ -54,18 +49,14 @@ function uniCssScopedPlugin({ filter } = { filter: () => false }) {
54
49
  return {
55
50
  name: 'uni:css-scoped',
56
51
  enforce: 'pre',
57
- transform: {
58
- // 仅 SFC 主模块需要补 scoped,跳过 script/style/template 等子模块。
59
- filter: { id: VUE_SFC_ID_RE },
60
- handler(code, id) {
61
- if (!filter(id))
62
- return null;
63
- debugScoped(id);
64
- return {
65
- code: addScoped(code),
66
- map: null,
67
- };
68
- },
52
+ transform(code, id) {
53
+ if (!filter(id))
54
+ return null;
55
+ debugScoped(id);
56
+ return {
57
+ code: addScoped(code),
58
+ map: null,
59
+ };
69
60
  },
70
61
  // 仅 h5
71
62
  handleHotUpdate(ctx) {
@@ -1,9 +1,2 @@
1
1
  import type { Plugin } from 'vite';
2
- interface DynamicImportPolyfillPlugin extends Plugin {
3
- renderDynamicImport(): {
4
- left: string;
5
- right: string;
6
- };
7
- }
8
- export declare function dynamicImportPolyfill(promise?: boolean): DynamicImportPolyfillPlugin;
9
- export {};
2
+ export declare function dynamicImportPolyfill(promise?: boolean): Plugin;
@@ -16,56 +16,53 @@ function uniEasycomPlugin(options) {
16
16
  const filter = (0, pluginutils_1.createFilter)(options.include, options.exclude);
17
17
  return {
18
18
  name: 'uni:app-easycom',
19
- transform: {
20
- filter: { id: /\.(vue|uvue)(\?|$)/, code: /_resolveComponent/ },
21
- handler(code, id) {
22
- if (!filter(id)) {
23
- return;
24
- }
25
- const { filename } = (0, url_1.parseVueRequest)(id);
26
- if (!constants_1.EXTNAME_VUE_TEMPLATE.includes(path_1.default.extname(filename))) {
27
- return;
28
- }
29
- if (!code.includes('_resolveComponent')) {
30
- return;
31
- }
32
- let i = 0;
33
- const importDeclarations = [];
34
- code = code.replace(/_resolveComponent\("(.+?)"(, true)?\)/g, (str, name) => {
35
- if (name && !name.startsWith('_')) {
36
- const source = (0, easycom_1.matchEasycom)(name);
37
- if (source) {
38
- // 处理easycom组件优先级
39
- return (0, easycom_1.genResolveEasycomCode)(importDeclarations, str, (0, easycom_1.addImportDeclaration)(importDeclarations, `__easycom_${i++}`, source, source.includes('uts-proxy')
40
- ? (0, shared_1.capitalize)((0, shared_1.camelize)(name)) + 'Component'
41
- : source.includes('uni_helpers')
42
- ? (0, shared_1.capitalize)((0, shared_1.camelize)(name))
43
- : ''));
44
- }
45
- else {
46
- const utsCustomElement = (0, uts_1.getUTSCustomElement)(name);
47
- if (utsCustomElement) {
48
- (0, easycom_1.addImportDeclaration)(importDeclarations, '', utsCustomElement.source, '');
49
- return `'${name}'`;
50
- }
19
+ transform(code, id) {
20
+ if (!filter(id)) {
21
+ return;
22
+ }
23
+ const { filename } = (0, url_1.parseVueRequest)(id);
24
+ if (!constants_1.EXTNAME_VUE_TEMPLATE.includes(path_1.default.extname(filename))) {
25
+ return;
26
+ }
27
+ if (!code.includes('_resolveComponent')) {
28
+ return;
29
+ }
30
+ let i = 0;
31
+ const importDeclarations = [];
32
+ code = code.replace(/_resolveComponent\("(.+?)"(, true)?\)/g, (str, name) => {
33
+ if (name && !name.startsWith('_')) {
34
+ const source = (0, easycom_1.matchEasycom)(name);
35
+ if (source) {
36
+ // 处理easycom组件优先级
37
+ return (0, easycom_1.genResolveEasycomCode)(importDeclarations, str, (0, easycom_1.addImportDeclaration)(importDeclarations, `__easycom_${i++}`, source, source.includes('uts-proxy')
38
+ ? (0, shared_1.capitalize)((0, shared_1.camelize)(name)) + 'Component'
39
+ : source.includes('uni_helpers')
40
+ ? (0, shared_1.capitalize)((0, shared_1.camelize)(name))
41
+ : ''));
42
+ }
43
+ else {
44
+ const utsCustomElement = (0, uts_1.getUTSCustomElement)(name);
45
+ if (utsCustomElement) {
46
+ (0, easycom_1.addImportDeclaration)(importDeclarations, '', utsCustomElement.source, '');
47
+ return `'${name}'`;
51
48
  }
52
- if (process.env.UNI_APP_X === 'true') {
53
- if ((0, uni_shared_1.isAppUVueBuiltInEasyComponent)(name)) {
54
- // 内置easycom组件不传入self参数
55
- return str.replace(', true)', ')');
56
- }
49
+ }
50
+ if (process.env.UNI_APP_X === 'true') {
51
+ if ((0, uni_shared_1.isAppUVueBuiltInEasyComponent)(name)) {
52
+ // 内置easycom组件不传入self参数
53
+ return str.replace(', true)', ')');
57
54
  }
58
55
  }
59
- return str;
60
- });
61
- if (importDeclarations.length) {
62
- code = importDeclarations.join('') + code;
63
56
  }
64
- return {
65
- code,
66
- map: null,
67
- };
68
- },
57
+ return str;
58
+ });
59
+ if (importDeclarations.length) {
60
+ code = importDeclarations.join('') + code;
61
+ }
62
+ return {
63
+ code,
64
+ map: null,
65
+ };
69
66
  },
70
67
  };
71
68
  }