@dcloudio/uni-cli-shared 3.0.0-alpha-4010820240520001 → 3.0.0-alpha-4010820240529001

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.
@@ -2,3 +2,22 @@ export declare function hasThemeJson(themeLocation: string): boolean;
2
2
  export declare const parseThemeJson: (themeLocation?: string) => UniApp.ThemeJson;
3
3
  export declare const normalizeThemeConfigOnce: (manifestJsonPlatform?: Record<string, any>) => UniApp.ThemeJson;
4
4
  export declare function initTheme<T extends object>(manifestJson: Record<string, any>, pagesJson: T): T;
5
+ export declare class ThemeSassParser {
6
+ _index: number;
7
+ _input: string;
8
+ _theme: Record<string, Record<string, any>>;
9
+ constructor();
10
+ parse(input: string): Record<string, Record<string, any>>;
11
+ parseVariable(): void;
12
+ parseVariableValue(): any;
13
+ parseFunction(): void | string[];
14
+ skipOtherValue(): void;
15
+ parseString(): string;
16
+ pushThemeValue(key: string, valuePair: string[]): void;
17
+ consume(expected: string): void;
18
+ get currentChar(): string;
19
+ skipWhiteSpaceAndComments(): void;
20
+ skipComment(): void;
21
+ skipWhiteSpace(): void;
22
+ isspace(str: string): boolean;
23
+ }
@@ -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.initTheme = exports.normalizeThemeConfigOnce = exports.parseThemeJson = exports.hasThemeJson = void 0;
6
+ exports.ThemeSassParser = exports.initTheme = exports.normalizeThemeConfigOnce = exports.parseThemeJson = exports.hasThemeJson = void 0;
7
7
  const fs_1 = __importDefault(require("fs"));
8
8
  const path_1 = __importDefault(require("path"));
9
9
  const json_1 = require("./json");
@@ -35,3 +35,187 @@ function initTheme(manifestJson, pagesJson) {
35
35
  return (0, uni_shared_1.normalizeStyles)(pagesJson, themeConfig);
36
36
  }
37
37
  exports.initTheme = initTheme;
38
+ // TODO
39
+ class ThemeSassParser {
40
+ constructor() {
41
+ this._index = 0;
42
+ this._input = '';
43
+ this._theme = {};
44
+ }
45
+ parse(input) {
46
+ this._index = 0;
47
+ this._input = input;
48
+ this._theme = {};
49
+ this._theme['light'] = {};
50
+ this._theme['dark'] = {};
51
+ this.parseVariable();
52
+ return this._theme;
53
+ }
54
+ parseVariable() {
55
+ this.skipWhiteSpaceAndComments();
56
+ this.consume('$');
57
+ this.skipWhiteSpaceAndComments();
58
+ let key = this.parseString();
59
+ this.skipWhiteSpaceAndComments();
60
+ this.consume(':');
61
+ this.skipWhiteSpace();
62
+ const value = this.parseVariableValue();
63
+ if (Array.isArray(value)) {
64
+ this.pushThemeValue(key, value);
65
+ }
66
+ this.consume(';');
67
+ this.skipWhiteSpaceAndComments();
68
+ if (this._index < this._input.length) {
69
+ this.parseVariable();
70
+ }
71
+ }
72
+ parseVariableValue() {
73
+ switch (this.currentChar) {
74
+ case 'l':
75
+ return this.parseFunction();
76
+ default:
77
+ return this.skipOtherValue();
78
+ }
79
+ }
80
+ parseFunction() {
81
+ let functionName = '';
82
+ while (this.currentChar != '(') {
83
+ functionName += this.currentChar;
84
+ if (this._index + 1 < this._input.length) {
85
+ ++this._index;
86
+ }
87
+ else {
88
+ break;
89
+ }
90
+ }
91
+ if (functionName != 'light-dark') {
92
+ return this.skipOtherValue();
93
+ }
94
+ let valuePair = new Array(2);
95
+ valuePair[0] = '';
96
+ valuePair[1] = '';
97
+ this.consume('(');
98
+ let index = 0;
99
+ // TODO rgb?
100
+ while (this.currentChar != ')') {
101
+ valuePair[index] += this.currentChar;
102
+ if (this.currentChar === ',') {
103
+ index++;
104
+ }
105
+ ++this._index;
106
+ }
107
+ this.consume(')');
108
+ valuePair[0] = valuePair[0].trim();
109
+ valuePair[1] = valuePair[1].trim();
110
+ return valuePair;
111
+ }
112
+ skipOtherValue() {
113
+ while (this.currentChar != ';') {
114
+ if (this._index + 1 < this._input.length) {
115
+ ++this._index;
116
+ }
117
+ else {
118
+ break;
119
+ }
120
+ }
121
+ }
122
+ parseString() {
123
+ let str = '';
124
+ while (this.currentChar != ':') {
125
+ if (this.currentChar == '\\') {
126
+ str += this.currentChar;
127
+ if (this._index + 1 < this._input.length) {
128
+ str += this._input[++this._index];
129
+ }
130
+ }
131
+ str += this.currentChar;
132
+ if (this._index + 1 < this._input.length) {
133
+ ++this._index;
134
+ }
135
+ else {
136
+ break;
137
+ }
138
+ }
139
+ return str;
140
+ }
141
+ pushThemeValue(key, valuePair) {
142
+ this._theme['light'][key] = valuePair[0];
143
+ this._theme['dark'][key] = valuePair[1];
144
+ }
145
+ consume(expected) {
146
+ if (this.currentChar != expected) {
147
+ throw new Error('Unexpected character ' +
148
+ expected +
149
+ ' index=' +
150
+ this._index +
151
+ ' ' +
152
+ this.currentChar);
153
+ }
154
+ ++this._index;
155
+ }
156
+ get currentChar() {
157
+ if (this._index >= this._input.length) {
158
+ throw new Error('Unexpected end of input');
159
+ }
160
+ return this._input[this._index];
161
+ }
162
+ skipWhiteSpaceAndComments() {
163
+ while (this._index < this._input.length) {
164
+ const c = this._input[this._index];
165
+ if (this.isspace(c)) {
166
+ ++this._index;
167
+ }
168
+ else if (c == '/') {
169
+ this.skipComment();
170
+ }
171
+ else {
172
+ break;
173
+ }
174
+ }
175
+ }
176
+ skipComment() {
177
+ if (this.currentChar != '/') {
178
+ return;
179
+ }
180
+ this.consume('/');
181
+ let nextChar = this.currentChar;
182
+ if (nextChar == '/') {
183
+ // Single line comment
184
+ while (
185
+ // @ts-expect-error
186
+ this.currentChar !== '\n' &&
187
+ this._index < this._input.length - 1) {
188
+ ++this._index;
189
+ }
190
+ this.skipWhiteSpace();
191
+ }
192
+ else if (nextChar === '*') {
193
+ // Multi-line comment
194
+ while (true) {
195
+ if (this._index + 1 >= this._input.length) {
196
+ throw new Error('Unterminated multi-line comment');
197
+ }
198
+ ++this._index;
199
+ // @ts-expect-error
200
+ if (this.currentChar === '*' && this._input[this._index + 1] === '/') {
201
+ this._index += 2;
202
+ break;
203
+ }
204
+ }
205
+ this.skipWhiteSpace();
206
+ }
207
+ else {
208
+ throw new Error('Invalid comment');
209
+ }
210
+ }
211
+ skipWhiteSpace() {
212
+ while (this._index < this._input.length &&
213
+ this.isspace(this._input[this._index])) {
214
+ ++this._index;
215
+ }
216
+ }
217
+ isspace(str) {
218
+ return str == ' ' || str == '\n' || str == '\r' || str == "'";
219
+ }
220
+ }
221
+ exports.ThemeSassParser = ThemeSassParser;
@@ -102,6 +102,7 @@ export declare function initCheckEnv(): Record<string, string>;
102
102
  export declare function resolveEncryptUniModule(id: string, platform: typeof process.env.UNI_UTS_PLATFORM, isX?: boolean): string | undefined;
103
103
  export declare function checkEncryptUniModules(inputDir: string, params: {
104
104
  mode: 'development' | 'production';
105
+ packType: 'debug' | 'release';
105
106
  compilerVersion: string;
106
107
  appid: string;
107
108
  appname: string;
@@ -191,20 +191,9 @@ function parseInject(vite = true, platform, language, source, globalObject, defi
191
191
  const skipCheck = process.env.UNI_APP_X_UVUE_SCRIPT_ENGINE === 'js' &&
192
192
  source.includes('app-js');
193
193
  if (!skipCheck) {
194
- if (language === 'javascript') {
195
- if (appOptions.js === false) {
196
- return;
197
- }
198
- }
199
- else if (language === 'kotlin') {
200
- if (appOptions.kotlin === false) {
201
- return;
202
- }
203
- }
204
- else if (language === 'swift') {
205
- if (appOptions.swift === false) {
206
- return;
207
- }
194
+ const targetLanguage = language === 'javascript' ? 'js' : language;
195
+ if (targetLanguage && appOptions[targetLanguage] === false) {
196
+ return;
208
197
  }
209
198
  }
210
199
  }
@@ -407,6 +396,7 @@ function findEncryptUniModuleCache(uniModuleId, cacheDir, options) {
407
396
  !isEnvExpired(pkg.uni_modules?.artifacts?.env || {}, options.env)) {
408
397
  return pkg;
409
398
  }
399
+ console.log(`插件${uniModuleId} 缓存已过期,需要重新云编译。`);
410
400
  // 已过期的插件,删除缓存
411
401
  fs_extra_1.default.rmSync(uniModuleCacheDir, { recursive: true });
412
402
  }
@@ -494,10 +484,22 @@ async function checkEncryptUniModules(inputDir, params) {
494
484
  try {
495
485
  const isLogin = await C();
496
486
  console.log(`正在云编译插件${isLogin ? '' : '(请先登录)'}:${modules.join(',')}...`);
497
- const downloadUrl = await U({
498
- params,
499
- attachment: zipFile,
500
- });
487
+ let downloadUrl = '';
488
+ try {
489
+ downloadUrl = await U({
490
+ params,
491
+ attachment: zipFile,
492
+ });
493
+ }
494
+ catch (e) {
495
+ if (e.message && e.message === '{"error":"UserNotLogin"}') {
496
+ console.log('当前项目包含需要云编译的付费插件,需要您先登录HBuilderX账号。');
497
+ }
498
+ else {
499
+ console.error(e);
500
+ }
501
+ process.exit(0);
502
+ }
501
503
  await D(downloadUrl, downloadFile);
502
504
  // unzip
503
505
  const AdmZip = require('adm-zip');
@@ -4,6 +4,9 @@ exports.initAutoImportOptions = void 0;
4
4
  const uniPreset = {
5
5
  from: '@dcloudio/uni-app',
6
6
  imports: [
7
+ // ssr
8
+ 'ssrRef',
9
+ 'shallowSsrRef',
7
10
  // uni-app lifecycle
8
11
  // App and Page
9
12
  'onShow',
@@ -1,5 +1,6 @@
1
1
  import type { Plugin, ResolveFn } from 'vite';
2
2
  import type { CssUrlReplacer } from './plugins/vitejs/plugins/css';
3
3
  export declare function createEncryptCssUrlReplacer(resolve: ResolveFn): CssUrlReplacer;
4
+ export declare function uniEncryptUniModulesAssetsPlugin(): Plugin;
4
5
  export declare function uniEncryptUniModulesPlugin(): Plugin;
5
6
  export declare function addUniModulesExtApiComponents(relativeFilename: string, components: string[]): void;
@@ -3,12 +3,13 @@ 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.addUniModulesExtApiComponents = exports.uniEncryptUniModulesPlugin = exports.createEncryptCssUrlReplacer = void 0;
6
+ exports.addUniModulesExtApiComponents = exports.uniEncryptUniModulesPlugin = exports.uniEncryptUniModulesAssetsPlugin = exports.createEncryptCssUrlReplacer = void 0;
7
7
  const path_1 = __importDefault(require("path"));
8
8
  const fs_extra_1 = __importDefault(require("fs-extra"));
9
9
  const uni_modules_1 = require("../uni_modules");
10
10
  const utils_1 = require("./plugins/vitejs/utils");
11
11
  const uts_1 = require("../uts");
12
+ const utils_2 = require("../utils");
12
13
  function createEncryptCssUrlReplacer(resolve) {
13
14
  return async (url, importer) => {
14
15
  if (url.startsWith('/') && !url.startsWith('//')) {
@@ -17,12 +18,44 @@ function createEncryptCssUrlReplacer(resolve) {
17
18
  }
18
19
  const resolved = await resolve(url, importer);
19
20
  if (resolved) {
20
- return ('@/' + (0, utils_1.normalizePath)(path_1.default.relative(process.env.UNI_INPUT_DIR, resolved)));
21
+ return ('@/' + (0, utils_2.normalizePath)(path_1.default.relative(process.env.UNI_INPUT_DIR, resolved)));
21
22
  }
22
23
  return url;
23
24
  };
24
25
  }
25
26
  exports.createEncryptCssUrlReplacer = createEncryptCssUrlReplacer;
27
+ // 处理静态资源加载(目前仅限非app-android)
28
+ function uniEncryptUniModulesAssetsPlugin() {
29
+ let resolvedConfig;
30
+ return {
31
+ name: 'uni:encrypt-uni-modules-assets',
32
+ enforce: 'pre',
33
+ configResolved(config) {
34
+ resolvedConfig = config;
35
+ },
36
+ resolveId(id, importer) {
37
+ if (resolvedConfig.assetsInclude((0, utils_1.cleanUrl)(id))) {
38
+ id = (0, utils_2.normalizePath)(id);
39
+ if (importer && (id.startsWith('./') || id.startsWith('../'))) {
40
+ id = (0, utils_2.normalizePath)(path_1.default.resolve(path_1.default.dirname(importer), id));
41
+ }
42
+ if (path_1.default.isAbsolute(id)) {
43
+ id = '@/' + path_1.default.relative(process.env.UNI_INPUT_DIR, id);
44
+ }
45
+ return `\0${id}`;
46
+ }
47
+ },
48
+ load(id) {
49
+ if (resolvedConfig.assetsInclude((0, utils_1.cleanUrl)(id))) {
50
+ return {
51
+ code: `export default ${JSON.stringify(id.replace(/\0/g, ''))}`,
52
+ moduleSideEffects: false,
53
+ };
54
+ }
55
+ },
56
+ };
57
+ }
58
+ exports.uniEncryptUniModulesAssetsPlugin = uniEncryptUniModulesAssetsPlugin;
26
59
  function uniEncryptUniModulesPlugin() {
27
60
  let resolvedConfig;
28
61
  return {
@@ -42,9 +75,28 @@ function uniEncryptUniModulesPlugin() {
42
75
  config.build.rollupOptions.external = createExternal(config);
43
76
  resolvedConfig = config;
44
77
  },
45
- resolveId(id) {
46
- if (resolvedConfig.assetsInclude((0, utils_1.cleanUrl)(id))) {
47
- return `\0${id}`;
78
+ resolveId(id, importer) {
79
+ if (process.env.UNI_UTS_PLATFORM !== 'app-android') {
80
+ if (resolvedConfig.assetsInclude((0, utils_1.cleanUrl)(id))) {
81
+ id = (0, utils_2.normalizePath)(id);
82
+ if (importer && (id.startsWith('./') || id.startsWith('../'))) {
83
+ id = (0, utils_2.normalizePath)(path_1.default.resolve(path_1.default.dirname(importer), id));
84
+ }
85
+ if (path_1.default.isAbsolute(id)) {
86
+ id = '@/' + path_1.default.relative(process.env.UNI_INPUT_DIR, id);
87
+ }
88
+ return `\0${id}`;
89
+ }
90
+ }
91
+ },
92
+ load(id) {
93
+ if (process.env.UNI_UTS_PLATFORM !== 'app-android') {
94
+ if (resolvedConfig.assetsInclude((0, utils_1.cleanUrl)(id))) {
95
+ return {
96
+ code: `export default ${JSON.stringify(id.replace(/\0/g, ''))}`,
97
+ moduleSideEffects: false,
98
+ };
99
+ }
48
100
  }
49
101
  },
50
102
  generateBundle(_, bundle) {
@@ -121,12 +173,6 @@ function uvueOutDir() {
121
173
  }
122
174
  function createExternal(config) {
123
175
  return function external(source) {
124
- if (
125
- // android 平台需要编译 assets 资源
126
- process.env.UNI_UTS_PLATFORM !== 'app-android' &&
127
- config.assetsInclude((0, utils_1.cleanUrl)(source))) {
128
- return true;
129
- }
130
176
  if ([
131
177
  'vue',
132
178
  'plugin-vue:export-helper',
@@ -220,7 +266,7 @@ function genUniModulesPackageJson(uniModuleId, inputDir, artifacts) {
220
266
  }, null, 2);
221
267
  }
222
268
  function parseUniModuleId(relativeFilename) {
223
- const parts = (0, utils_1.normalizePath)(relativeFilename).split('/', 2);
269
+ const parts = (0, utils_2.normalizePath)(relativeFilename).split('/', 2);
224
270
  if (parts[0] === 'uni_modules') {
225
271
  return parts[1];
226
272
  }
@@ -171,6 +171,8 @@ function uniDecryptUniModulesPlugin() {
171
171
  mode: process.env.NODE_ENV !== 'development'
172
172
  ? 'production'
173
173
  : 'development',
174
+ packType: process.env.UNI_APP_PACK_TYPE ||
175
+ (process.env.NODE_ENV !== 'development' ? 'release' : 'debug'),
174
176
  compilerVersion: process.env.UNI_COMPILER_VERSION,
175
177
  appid: manifest.appid,
176
178
  appname: manifest.name,
@@ -1,11 +1,15 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.transformPageHead = void 0;
4
+ const compiler_core_1 = require("@vue/compiler-core");
4
5
  const utils_1 = require("../../utils");
5
6
  const transformPageHead = (node, context) => {
6
7
  // 发现是page-meta下的head,直接remove该节点
7
- (0, utils_1.checkElementNodeTag)(node, 'head') &&
8
- (0, utils_1.checkElementNodeTag)(context.parent, 'page-meta') &&
9
- context.removeNode(node);
8
+ if ((0, utils_1.checkElementNodeTag)(node, 'head') &&
9
+ (0, utils_1.checkElementNodeTag)(context.parent, 'page-meta')) {
10
+ ;
11
+ node.tag = 'page-meta-head';
12
+ node.tagType = compiler_core_1.ElementTypes.COMPONENT;
13
+ }
10
14
  };
11
15
  exports.transformPageHead = transformPageHead;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dcloudio/uni-cli-shared",
3
- "version": "3.0.0-alpha-4010820240520001",
3
+ "version": "3.0.0-alpha-4010820240529001",
4
4
  "description": "@dcloudio/uni-cli-shared",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -26,8 +26,8 @@
26
26
  "@babel/core": "^7.23.3",
27
27
  "@babel/parser": "^7.23.9",
28
28
  "@babel/types": "^7.20.7",
29
- "@dcloudio/uni-i18n": "3.0.0-alpha-4010820240520001",
30
- "@dcloudio/uni-shared": "3.0.0-alpha-4010820240520001",
29
+ "@dcloudio/uni-i18n": "3.0.0-alpha-4010820240529001",
30
+ "@dcloudio/uni-shared": "3.0.0-alpha-4010820240529001",
31
31
  "@intlify/core-base": "9.1.9",
32
32
  "@intlify/shared": "9.1.9",
33
33
  "@intlify/vue-devtools": "9.1.9",
@@ -71,7 +71,7 @@
71
71
  },
72
72
  "gitHead": "33e807d66e1fe47e2ee08ad9c59247e37b8884da",
73
73
  "devDependencies": {
74
- "@dcloudio/uni-uts-v1": "3.0.0-alpha-4010820240520001",
74
+ "@dcloudio/uni-uts-v1": "3.0.0-alpha-4010820240529001",
75
75
  "@types/adm-zip": "^0.5.5",
76
76
  "@types/babel__code-frame": "^7.0.6",
77
77
  "@types/babel__core": "^7.1.19",