@dcloudio/uni-app-uts 3.0.0-3080720230630001

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.
Files changed (70) hide show
  1. package/LICENSE +202 -0
  2. package/dist/index.d.ts +4 -0
  3. package/dist/index.js +30 -0
  4. package/dist/plugins/css.d.ts +2 -0
  5. package/dist/plugins/css.js +94 -0
  6. package/dist/plugins/index.d.ts +2 -0
  7. package/dist/plugins/index.js +203 -0
  8. package/dist/plugins/mainUTS.d.ts +2 -0
  9. package/dist/plugins/mainUTS.js +24 -0
  10. package/dist/plugins/manifestJson.d.ts +2 -0
  11. package/dist/plugins/manifestJson.js +68 -0
  12. package/dist/plugins/pagesJson.d.ts +2 -0
  13. package/dist/plugins/pagesJson.js +84 -0
  14. package/dist/plugins/pre.d.ts +7 -0
  15. package/dist/plugins/pre.js +52 -0
  16. package/dist/plugins/utils.d.ts +8 -0
  17. package/dist/plugins/utils.js +85 -0
  18. package/dist/plugins/uvue/code/script.d.ts +4 -0
  19. package/dist/plugins/uvue/code/script.js +14 -0
  20. package/dist/plugins/uvue/code/style.d.ts +12 -0
  21. package/dist/plugins/uvue/code/style.js +90 -0
  22. package/dist/plugins/uvue/code/template.d.ts +3 -0
  23. package/dist/plugins/uvue/code/template.js +16 -0
  24. package/dist/plugins/uvue/compiler/codegen.d.ts +22 -0
  25. package/dist/plugins/uvue/compiler/codegen.js +579 -0
  26. package/dist/plugins/uvue/compiler/errors.d.ts +70 -0
  27. package/dist/plugins/uvue/compiler/errors.js +82 -0
  28. package/dist/plugins/uvue/compiler/index.d.ts +9 -0
  29. package/dist/plugins/uvue/compiler/index.js +65 -0
  30. package/dist/plugins/uvue/compiler/options.d.ts +92 -0
  31. package/dist/plugins/uvue/compiler/options.js +2 -0
  32. package/dist/plugins/uvue/compiler/runtimeHelpers.d.ts +10 -0
  33. package/dist/plugins/uvue/compiler/runtimeHelpers.js +25 -0
  34. package/dist/plugins/uvue/compiler/transform.d.ts +53 -0
  35. package/dist/plugins/uvue/compiler/transform.js +294 -0
  36. package/dist/plugins/uvue/compiler/transforms/transformExpression.d.ts +5 -0
  37. package/dist/plugins/uvue/compiler/transforms/transformExpression.js +208 -0
  38. package/dist/plugins/uvue/compiler/transforms/transformInterpolation.d.ts +4 -0
  39. package/dist/plugins/uvue/compiler/transforms/transformInterpolation.js +107 -0
  40. package/dist/plugins/uvue/compiler/transforms/transformSlotOutlet.d.ts +10 -0
  41. package/dist/plugins/uvue/compiler/transforms/transformSlotOutlet.js +79 -0
  42. package/dist/plugins/uvue/compiler/transforms/transformText.d.ts +2 -0
  43. package/dist/plugins/uvue/compiler/transforms/transformText.js +99 -0
  44. package/dist/plugins/uvue/compiler/transforms/vBind.d.ts +2 -0
  45. package/dist/plugins/uvue/compiler/transforms/vBind.js +83 -0
  46. package/dist/plugins/uvue/compiler/transforms/vFor.d.ts +12 -0
  47. package/dist/plugins/uvue/compiler/transforms/vFor.js +325 -0
  48. package/dist/plugins/uvue/compiler/transforms/vIf.d.ts +4 -0
  49. package/dist/plugins/uvue/compiler/transforms/vIf.js +212 -0
  50. package/dist/plugins/uvue/compiler/transforms/vModel.d.ts +2 -0
  51. package/dist/plugins/uvue/compiler/transforms/vModel.js +51 -0
  52. package/dist/plugins/uvue/compiler/transforms/vOn.d.ts +8 -0
  53. package/dist/plugins/uvue/compiler/transforms/vOn.js +136 -0
  54. package/dist/plugins/uvue/compiler/transforms/vShow.d.ts +2 -0
  55. package/dist/plugins/uvue/compiler/transforms/vShow.js +11 -0
  56. package/dist/plugins/uvue/compiler/transforms/vText.d.ts +2 -0
  57. package/dist/plugins/uvue/compiler/transforms/vText.js +29 -0
  58. package/dist/plugins/uvue/compiler/utils.d.ts +5 -0
  59. package/dist/plugins/uvue/compiler/utils.js +37 -0
  60. package/dist/plugins/uvue/descriptorCache.d.ts +24 -0
  61. package/dist/plugins/uvue/descriptorCache.js +57 -0
  62. package/dist/plugins/uvue/error.d.ts +3 -0
  63. package/dist/plugins/uvue/error.js +22 -0
  64. package/dist/plugins/uvue/index.d.ts +13 -0
  65. package/dist/plugins/uvue/index.js +188 -0
  66. package/lib/automator/apis/App.uts +144 -0
  67. package/lib/automator/apis/Page.uts +55 -0
  68. package/lib/automator/apis/util.uts +63 -0
  69. package/lib/automator/index.uts +106 -0
  70. package/package.json +42 -0
@@ -0,0 +1,84 @@
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.uniAppPagesPlugin = void 0;
7
+ const path_1 = __importDefault(require("path"));
8
+ const fs_extra_1 = __importDefault(require("fs-extra"));
9
+ const uni_cli_shared_1 = require("@dcloudio/uni-cli-shared");
10
+ const utils_1 = require("./utils");
11
+ function isPages(id) {
12
+ return id.endsWith(uni_cli_shared_1.PAGES_JSON_UTS);
13
+ }
14
+ function uniAppPagesPlugin() {
15
+ const pagesJsonPath = path_1.default.resolve(process.env.UNI_INPUT_DIR, 'pages.json');
16
+ const pagesJsonUTSPath = path_1.default.resolve(process.env.UNI_INPUT_DIR, uni_cli_shared_1.PAGES_JSON_UTS);
17
+ let imports = [];
18
+ let routes = [];
19
+ let globalStyle = 'new Map()';
20
+ let tabBar = 'null';
21
+ return {
22
+ name: 'uni:app-pages',
23
+ apply: 'build',
24
+ resolveId(id) {
25
+ if (isPages(id)) {
26
+ return pagesJsonUTSPath;
27
+ }
28
+ },
29
+ load(id) {
30
+ if (isPages(id)) {
31
+ return fs_extra_1.default.readFileSync(pagesJsonPath, 'utf8');
32
+ }
33
+ },
34
+ transform(code, id) {
35
+ if (isPages(id)) {
36
+ this.addWatchFile(path_1.default.resolve(process.env.UNI_INPUT_DIR, 'pages.json'));
37
+ const pagesJson = (0, uni_cli_shared_1.normalizeUniAppXAppPagesJson)(code);
38
+ imports = [];
39
+ routes = [];
40
+ pagesJson.pages.forEach((page, index) => {
41
+ const className = (0, utils_1.genClassName)(page.path);
42
+ let isQuit = index === 0;
43
+ imports.push(page.path);
44
+ routes.push(`{ path: "${page.path}", component: ${className}Class, meta: { isQuit: ${isQuit} } as PageMeta, style: ${stringifyPageStyle(page.style)} } as PageRoute`);
45
+ });
46
+ if (pagesJson.globalStyle) {
47
+ globalStyle = stringifyPageStyle(pagesJson.globalStyle);
48
+ }
49
+ if (pagesJson.tabBar) {
50
+ tabBar = (0, utils_1.stringifyMap)(pagesJson.tabBar);
51
+ }
52
+ return `${imports.map((p) => `import './${p}.uvue'`).join('\n')}
53
+ export default 'pages.json'`;
54
+ }
55
+ },
56
+ generateBundle(_, bundle) {
57
+ if (bundle[utils_1.ENTRY_FILENAME]) {
58
+ const asset = bundle[utils_1.ENTRY_FILENAME];
59
+ asset.source =
60
+ asset.source +
61
+ `
62
+ ${imports
63
+ .map((p) => {
64
+ const className = (0, utils_1.genClassName)(p);
65
+ return `import ${className}Class from './${p}.uvue?type=page'`;
66
+ })
67
+ .join('\n')}
68
+ function definePageRoutes() {
69
+ ${routes.map((route) => `__uniRoutes.push(${route})`).join('\n')}
70
+ }
71
+ function defineAppConfig(){
72
+ __uniConfig.entryPagePath = '/${imports[0]}'
73
+ __uniConfig.globalStyle = ${globalStyle}
74
+ __uniConfig.tabBar = ${tabBar}
75
+ }
76
+ `;
77
+ }
78
+ },
79
+ };
80
+ }
81
+ exports.uniAppPagesPlugin = uniAppPagesPlugin;
82
+ function stringifyPageStyle(pageStyle) {
83
+ return (0, utils_1.stringifyMap)(pageStyle);
84
+ }
@@ -0,0 +1,7 @@
1
+ import { Plugin } from 'vite';
2
+ import { FilterPattern } from '@rollup/pluginutils';
3
+ export interface UniPrePluginOptions {
4
+ include?: FilterPattern;
5
+ exclude?: FilterPattern;
6
+ }
7
+ export declare function uniPrePlugin(options?: UniPrePluginOptions): Plugin;
@@ -0,0 +1,52 @@
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.uniPrePlugin = void 0;
7
+ const path_1 = __importDefault(require("path"));
8
+ const debug_1 = __importDefault(require("debug"));
9
+ const pluginutils_1 = require("@rollup/pluginutils");
10
+ const uni_cli_shared_1 = require("@dcloudio/uni-cli-shared");
11
+ const debugPreJs = (0, debug_1.default)('uni:pre-js');
12
+ const debugPreHtml = (0, debug_1.default)('uni:pre-html');
13
+ const debugPreJsTry = (0, debug_1.default)('uni:pre-js-try');
14
+ const PRE_HTML_EXTNAME = ['.vue', '.uvue'];
15
+ const PRE_JS_EXTNAME = ['.json', '.css', '.uts'].concat(PRE_HTML_EXTNAME);
16
+ function uniPrePlugin(options = {}) {
17
+ const filter = (0, pluginutils_1.createFilter)(options.include, options.exclude);
18
+ const preJsFile = uni_cli_shared_1.preUVueJs;
19
+ const preHtmlFile = uni_cli_shared_1.preUVueHtml;
20
+ return {
21
+ name: 'uni:pre',
22
+ transform(code, id) {
23
+ if (!filter(id)) {
24
+ return;
25
+ }
26
+ const { filename } = (0, uni_cli_shared_1.parseVueRequest)(id);
27
+ const extname = path_1.default.extname(filename);
28
+ const isHtml = PRE_HTML_EXTNAME.includes(extname);
29
+ const isJs = PRE_JS_EXTNAME.includes(extname);
30
+ const isPre = isHtml || isJs;
31
+ if (isPre) {
32
+ debugPreJsTry(id);
33
+ }
34
+ const hasEndif = isPre && code.includes('#endif');
35
+ if (!hasEndif) {
36
+ return;
37
+ }
38
+ if (isHtml) {
39
+ code = preHtmlFile(code);
40
+ debugPreHtml(id);
41
+ }
42
+ if (isJs) {
43
+ code = preJsFile(code);
44
+ debugPreJs(id);
45
+ }
46
+ return {
47
+ code,
48
+ };
49
+ },
50
+ };
51
+ }
52
+ exports.uniPrePlugin = uniPrePlugin;
@@ -0,0 +1,8 @@
1
+ export declare const ENTRY_FILENAME = "index.uts";
2
+ export declare function parseImports(code: string): Promise<string>;
3
+ export declare function uvueOutDir(): string;
4
+ export declare function genClassName(fileName: string, prefix?: string): string;
5
+ export declare function isVue(filename: string): boolean;
6
+ export declare function stringifyMap(obj: unknown): string;
7
+ export declare function parseUTSRelativeFilename(filename: string): string;
8
+ export declare function parseUTSImportFilename(filename: string): string;
@@ -0,0 +1,85 @@
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.parseUTSImportFilename = exports.parseUTSRelativeFilename = exports.stringifyMap = exports.isVue = exports.genClassName = exports.uvueOutDir = exports.parseImports = exports.ENTRY_FILENAME = void 0;
7
+ const path_1 = __importDefault(require("path"));
8
+ const es_module_lexer_1 = require("es-module-lexer");
9
+ const uni_cli_shared_1 = require("@dcloudio/uni-cli-shared");
10
+ const shared_1 = require("@vue/shared");
11
+ exports.ENTRY_FILENAME = 'index.uts';
12
+ async function parseImports(code) {
13
+ await es_module_lexer_1.init;
14
+ const [imports] = (0, es_module_lexer_1.parse)(code);
15
+ return imports
16
+ .map(({ s, e }) => {
17
+ return `import "${code.slice(s, e)}"`;
18
+ })
19
+ .concat(parseUniExtApiImports(code))
20
+ .join('\n');
21
+ }
22
+ exports.parseImports = parseImports;
23
+ function parseUniExtApiImports(code) {
24
+ const extApis = (0, uni_cli_shared_1.parseUniExtApiNamespacesJsOnce)(process.env.UNI_UTS_PLATFORM, process.env.UNI_UTS_TARGET_LANGUAGE);
25
+ const pattern = /uni\.(\w+)/g;
26
+ const apis = new Set();
27
+ let match;
28
+ while ((match = pattern.exec(code)) !== null) {
29
+ apis.add(match[1]);
30
+ }
31
+ const imports = [];
32
+ apis.forEach((api) => {
33
+ const extApi = extApis[api];
34
+ if (extApi) {
35
+ imports.push(`import "${extApi[0]}"`);
36
+ }
37
+ });
38
+ return imports;
39
+ }
40
+ function uvueOutDir() {
41
+ return path_1.default.join(process.env.UNI_OUTPUT_DIR, '../.uvue');
42
+ }
43
+ exports.uvueOutDir = uvueOutDir;
44
+ function genClassName(fileName, prefix = 'Gen') {
45
+ return (prefix +
46
+ (0, shared_1.capitalize)((0, shared_1.camelize)((0, uni_cli_shared_1.removeExt)((0, uni_cli_shared_1.normalizePath)(fileName).replace(/\//g, '-')))));
47
+ }
48
+ exports.genClassName = genClassName;
49
+ function isVue(filename) {
50
+ return filename.endsWith('.vue') || filename.endsWith('.uvue');
51
+ }
52
+ exports.isVue = isVue;
53
+ function stringifyMap(obj) {
54
+ return serialize(obj, true);
55
+ }
56
+ exports.stringifyMap = stringifyMap;
57
+ function serialize(obj, ts = false) {
58
+ if ((0, shared_1.isString)(obj)) {
59
+ return `"${obj}"`;
60
+ }
61
+ else if ((0, shared_1.isPlainObject)(obj)) {
62
+ const entries = Object.entries(obj).map(([key, value]) => `[${serialize(key, ts)},${serialize(value, ts)}]`);
63
+ return `new Map${ts ? '<string, any>' : ''}([${entries.join(',')}])`;
64
+ }
65
+ else if ((0, shared_1.isArray)(obj)) {
66
+ return `[${obj.map((item) => serialize(item, ts)).join(',')}]`;
67
+ }
68
+ else {
69
+ return String(obj);
70
+ }
71
+ }
72
+ function parseUTSRelativeFilename(filename) {
73
+ if (!path_1.default.isAbsolute(filename)) {
74
+ return filename;
75
+ }
76
+ return (0, uni_cli_shared_1.normalizeNodeModules)(path_1.default.relative(process.env.UNI_INPUT_DIR, filename));
77
+ }
78
+ exports.parseUTSRelativeFilename = parseUTSRelativeFilename;
79
+ function parseUTSImportFilename(filename) {
80
+ if (!path_1.default.isAbsolute(filename)) {
81
+ return filename;
82
+ }
83
+ return (0, uni_cli_shared_1.normalizePath)(path_1.default.join(uvueOutDir(), (0, uni_cli_shared_1.normalizeNodeModules)(path_1.default.relative(process.env.UNI_INPUT_DIR, filename))));
84
+ }
85
+ exports.parseUTSImportFilename = parseUTSImportFilename;
@@ -0,0 +1,4 @@
1
+ import { SFCDescriptor } from '@vue/compiler-sfc';
2
+ export declare function genScript({ script }: SFCDescriptor, _options: {
3
+ filename: string;
4
+ }): string;
@@ -0,0 +1,14 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.genScript = void 0;
4
+ function genScript({ script }, _options) {
5
+ if (!script) {
6
+ return `
7
+ export default {}
8
+ `;
9
+ }
10
+ return ('\n'.repeat(script.loc.start.line - 1) +
11
+ `${script.content}
12
+ `);
13
+ }
14
+ exports.genScript = genScript;
@@ -0,0 +1,12 @@
1
+ import type { SFCDescriptor } from '@vue/compiler-sfc';
2
+ import type { PluginContext, TransformPluginContext } from 'rollup';
3
+ import { ResolvedOptions } from '../descriptorCache';
4
+ export declare function genStyle(_: SFCDescriptor, { className }: {
5
+ className: string;
6
+ filename: string;
7
+ }): string;
8
+ export declare function genJsStylesCode(descriptor: SFCDescriptor, pluginContext: PluginContext): Promise<string>;
9
+ export declare function transformStyle(code: string, descriptor: SFCDescriptor, index: number, options: ResolvedOptions, pluginContext: TransformPluginContext, filename: string): Promise<{
10
+ code: string;
11
+ map: null;
12
+ } | null>;
@@ -0,0 +1,90 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.transformStyle = exports.genJsStylesCode = exports.genStyle = void 0;
4
+ const descriptorCache_1 = require("../descriptorCache");
5
+ function genStyle(_, { className }) {
6
+ return `/*${className}Styles*/`;
7
+ }
8
+ exports.genStyle = genStyle;
9
+ async function genJsStylesCode(descriptor, pluginContext) {
10
+ let stylesCode = ``;
11
+ if (descriptor.styles.length) {
12
+ for (let i = 0; i < descriptor.styles.length; i++) {
13
+ const style = descriptor.styles[i];
14
+ if (style.src) {
15
+ await linkSrcToDescriptor(style.src, descriptor, pluginContext);
16
+ }
17
+ const src = style.src || descriptor.filename;
18
+ // do not include module in default query, since we use it to indicate
19
+ // that the module needs to export the modules json
20
+ const attrsQuery = attrsToQuery(style.attrs, 'css');
21
+ const srcQuery = style.src ? '&src=true' : '';
22
+ const query = `?vue&type=style&index=${i}${srcQuery}`;
23
+ const styleRequest = src + query + attrsQuery;
24
+ stylesCode += `\nimport ${JSON.stringify(styleRequest)}`;
25
+ }
26
+ }
27
+ return stylesCode;
28
+ }
29
+ exports.genJsStylesCode = genJsStylesCode;
30
+ /**
31
+ * For blocks with src imports, it is important to link the imported file
32
+ * with its owner SFC descriptor so that we can get the information about
33
+ * the owner SFC when compiling that file in the transform phase.
34
+ */
35
+ async function linkSrcToDescriptor(src, descriptor, pluginContext) {
36
+ const srcFile = (await pluginContext.resolve(src, descriptor.filename))?.id || src;
37
+ // #1812 if the src points to a dep file, the resolved id may contain a
38
+ // version query.
39
+ (0, descriptorCache_1.setSrcDescriptor)(srcFile.replace(/\?.*$/, ''), descriptor);
40
+ }
41
+ // these are built-in query parameters so should be ignored
42
+ // if the user happen to add them as attrs
43
+ const ignoreList = ['id', 'index', 'src', 'type', 'lang', 'module', 'scoped'];
44
+ function attrsToQuery(attrs, langFallback, forceLangFallback = false) {
45
+ let query = ``;
46
+ for (const name in attrs) {
47
+ const value = attrs[name];
48
+ if (!ignoreList.includes(name)) {
49
+ query += `&${encodeURIComponent(name)}${value ? `=${encodeURIComponent(value)}` : ``}`;
50
+ }
51
+ }
52
+ if (langFallback || attrs.lang) {
53
+ query +=
54
+ `lang` in attrs
55
+ ? forceLangFallback
56
+ ? `&lang.${langFallback}`
57
+ : `&lang.${attrs.lang}`
58
+ : `&lang.${langFallback}`;
59
+ }
60
+ return query;
61
+ }
62
+ async function transformStyle(code, descriptor, index, options, pluginContext, filename) {
63
+ const block = descriptor.styles[index];
64
+ // vite already handles pre-processors and CSS module so this is only
65
+ // applying SFC-specific transforms like scoped mode and CSS vars rewrite (v-bind(var))
66
+ const result = await options.compiler.compileStyleAsync({
67
+ filename: descriptor.filename,
68
+ id: `data-v-${descriptor.id}`,
69
+ isProd: true,
70
+ source: code,
71
+ });
72
+ if (result.errors.length) {
73
+ result.errors.forEach((error) => {
74
+ if (error.line && error.column) {
75
+ error.loc = {
76
+ file: descriptor.filename,
77
+ line: error.line + block.loc.start.line,
78
+ column: error.column,
79
+ };
80
+ }
81
+ pluginContext.error(error);
82
+ });
83
+ return null;
84
+ }
85
+ return {
86
+ code: result.code,
87
+ map: null,
88
+ };
89
+ }
90
+ exports.transformStyle = transformStyle;
@@ -0,0 +1,3 @@
1
+ import { SFCDescriptor } from '@vue/compiler-sfc';
2
+ import { CompilerOptions } from '../compiler/options';
3
+ export declare function genTemplate({ template }: SFCDescriptor, options: CompilerOptions): import("../compiler/options").CodegenResult;
@@ -0,0 +1,16 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.genTemplate = void 0;
4
+ const compiler_1 = require("../compiler");
5
+ const utils_1 = require("../compiler/utils");
6
+ function genTemplate({ template }, options) {
7
+ if (!template) {
8
+ return {
9
+ code: (0, utils_1.genRenderFunctionDecl)(options) + ` { return null }`,
10
+ importEasyComponents: [],
11
+ importUTSComponents: [],
12
+ };
13
+ }
14
+ return (0, compiler_1.compile)(template.content, options);
15
+ }
16
+ exports.genTemplate = genTemplate;
@@ -0,0 +1,22 @@
1
+ import { SourceMapGenerator } from 'source-map';
2
+ import { JSChildNode, RootNode, SSRCodegenNode, TemplateChildNode } from '@vue/compiler-core';
3
+ import { CodegenOptions, CodegenResult } from './options';
4
+ type CodegenNode = TemplateChildNode | JSChildNode | SSRCodegenNode;
5
+ export interface CodegenContext extends Required<CodegenOptions> {
6
+ source: string;
7
+ code: string;
8
+ importEasyComponents: string[];
9
+ importUTSComponents: string[];
10
+ line: number;
11
+ column: number;
12
+ offset: number;
13
+ indentLevel: number;
14
+ map?: SourceMapGenerator;
15
+ helper(key: symbol): string;
16
+ push(code: string, node?: CodegenNode): void;
17
+ indent(): void;
18
+ deindent(withoutNewLine?: boolean): void;
19
+ newline(): void;
20
+ }
21
+ export declare function generate(ast: RootNode, options: CodegenOptions): CodegenResult;
22
+ export {};