@dimina/compiler 1.0.14-beta.0 → 1.0.15

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
  #!/usr/bin/env node
2
- const require_env = require("../env-M-7lpbHL.cjs");
2
+ const require_env = require("../env-Dmnqp9bD.cjs");
3
3
  const require_index = require("../index.cjs");
4
4
  let node_path = require("node:path");
5
5
  node_path = require_env.__toESM(node_path, 1);
@@ -10,7 +10,7 @@ chokidar = require_env.__toESM(chokidar, 1);
10
10
  let commander = require("commander");
11
11
  var package_default = {
12
12
  name: "@dimina/compiler",
13
- version: "1.0.14-beta.0",
13
+ version: "1.0.15",
14
14
  description: "星河编译工具",
15
15
  main: "./dist/index.cjs",
16
16
  module: "./dist/index.js",
@@ -36,10 +36,14 @@ var package_default = {
36
36
  },
37
37
  bin: { "dmcc": "dist/bin/index.js" },
38
38
  scripts: {
39
+ "prebuild": "node scripts/sync-compatibility-reference.js",
39
40
  "build": "vite build",
41
+ "sync:compat": "node scripts/sync-compatibility-reference.js",
42
+ "pretest": "node scripts/sync-compatibility-reference.js",
40
43
  "test": "vitest run",
41
44
  "test:dev": "vitest",
42
45
  "coverage": "vitest run --coverage",
46
+ "prepack": "npm run build",
43
47
  "release:beta": "npm version prerelease --preid=beta && npm publish --tag beta",
44
48
  "release": "npm version patch && npm publish"
45
49
  },
@@ -53,29 +57,23 @@ var package_default = {
53
57
  "星河"
54
58
  ],
55
59
  dependencies: {
56
- "@babel/core": "^7.29.0",
57
- "@babel/generator": "^7.29.1",
58
- "@babel/plugin-transform-modules-commonjs": "^7.28.6",
59
- "@babel/traverse": "^7.29.0",
60
- "@babel/types": "^7.29.0",
61
- "@vue/compiler-sfc": "^3.5.32",
62
- "autoprefixer": "^10.4.27",
60
+ "@vue/compiler-sfc": "^3.5.34",
61
+ "autoprefixer": "^10.5.0",
63
62
  "cheerio": "^1.2.0",
64
63
  "chokidar": "^4.0.3",
65
64
  "commander": "^14.0.3",
66
- "cssnano": "^7.1.4",
67
- "esbuild": "^0.27.7",
68
- "htmlparser2": "^10.1.0",
65
+ "cssnano": "^8.0.1",
66
+ "esbuild": "^0.28.0",
67
+ "htmlparser2": "^12.0.0",
69
68
  "less": "^4.6.4",
70
69
  "listr2": "^9.0.5",
71
70
  "magic-string": "^0.30.21",
72
- "oxc-parser": "^0.123.0",
73
- "oxc-transform": "^0.124.0",
71
+ "oxc-parser": "^0.129.0",
74
72
  "oxc-walker": "^0.7.0",
75
- "postcss": "^8.5.9",
73
+ "postcss": "^8.5.14",
76
74
  "postcss-selector-parser": "^7.1.1",
77
75
  "sass": "^1.99.0",
78
- "typescript": "^6.0.2"
76
+ "source-map-js": "^1.2.1"
79
77
  },
80
78
  publishConfig: {
81
79
  "registry": "https://registry.npmjs.org/",
@@ -84,18 +82,19 @@ var package_default = {
84
82
  };
85
83
  //#endregion
86
84
  //#region src/bin/index.js
87
- commander.program.command("build").option("-c, --work-path <path>", "编译工作目录").option("-s, --target-path <path>", "编译产物存放路径").option("-w, --watch", "启用监听文件改动").option("--no-app-id-dir", "产物根目录不包含appId").action(async (options) => {
85
+ commander.program.command("build").option("-c, --work-path <path>", "编译工作目录").option("-s, --target-path <path>", "编译产物存放路径").option("-w, --watch", "启用监听文件改动").option("--no-app-id-dir", "产物根目录不包含appId").option("--sourcemap", "生成 sourcemap 文件用于调试").action(async (options) => {
88
86
  const workPath = options.workPath ? node_path.default.resolve(options.workPath) : node_process.default.cwd();
89
87
  const targetPath = options.targetPath ? node_path.default.resolve(options.targetPath) : node_process.default.cwd();
90
88
  const useAppIdDir = options.appIdDir !== false;
91
- await require_index(targetPath, workPath, useAppIdDir);
89
+ const sourcemap = !!options.sourcemap;
90
+ await require_index(targetPath, workPath, useAppIdDir, { sourcemap });
92
91
  if (options.watch) chokidar.default.watch(workPath, {
93
92
  persistent: true,
94
93
  ignoreInitial: true
95
94
  }).on("all", async (event, path) => {
96
95
  if (event === "change") {
97
96
  console.log(`${path} 改动,重新编译`);
98
- await require_index(targetPath, workPath, useAppIdDir);
97
+ await require_index(targetPath, workPath, useAppIdDir, { sourcemap });
99
98
  }
100
99
  });
101
100
  });
package/dist/bin/index.js CHANGED
@@ -6,7 +6,7 @@ import chokidar from "chokidar";
6
6
  import { program } from "commander";
7
7
  var package_default = {
8
8
  name: "@dimina/compiler",
9
- version: "1.0.14-beta.0",
9
+ version: "1.0.15",
10
10
  description: "星河编译工具",
11
11
  main: "./dist/index.cjs",
12
12
  module: "./dist/index.js",
@@ -32,10 +32,14 @@ var package_default = {
32
32
  },
33
33
  bin: { "dmcc": "dist/bin/index.js" },
34
34
  scripts: {
35
+ "prebuild": "node scripts/sync-compatibility-reference.js",
35
36
  "build": "vite build",
37
+ "sync:compat": "node scripts/sync-compatibility-reference.js",
38
+ "pretest": "node scripts/sync-compatibility-reference.js",
36
39
  "test": "vitest run",
37
40
  "test:dev": "vitest",
38
41
  "coverage": "vitest run --coverage",
42
+ "prepack": "npm run build",
39
43
  "release:beta": "npm version prerelease --preid=beta && npm publish --tag beta",
40
44
  "release": "npm version patch && npm publish"
41
45
  },
@@ -49,29 +53,23 @@ var package_default = {
49
53
  "星河"
50
54
  ],
51
55
  dependencies: {
52
- "@babel/core": "^7.29.0",
53
- "@babel/generator": "^7.29.1",
54
- "@babel/plugin-transform-modules-commonjs": "^7.28.6",
55
- "@babel/traverse": "^7.29.0",
56
- "@babel/types": "^7.29.0",
57
- "@vue/compiler-sfc": "^3.5.32",
58
- "autoprefixer": "^10.4.27",
56
+ "@vue/compiler-sfc": "^3.5.34",
57
+ "autoprefixer": "^10.5.0",
59
58
  "cheerio": "^1.2.0",
60
59
  "chokidar": "^4.0.3",
61
60
  "commander": "^14.0.3",
62
- "cssnano": "^7.1.4",
63
- "esbuild": "^0.27.7",
64
- "htmlparser2": "^10.1.0",
61
+ "cssnano": "^8.0.1",
62
+ "esbuild": "^0.28.0",
63
+ "htmlparser2": "^12.0.0",
65
64
  "less": "^4.6.4",
66
65
  "listr2": "^9.0.5",
67
66
  "magic-string": "^0.30.21",
68
- "oxc-parser": "^0.123.0",
69
- "oxc-transform": "^0.124.0",
67
+ "oxc-parser": "^0.129.0",
70
68
  "oxc-walker": "^0.7.0",
71
- "postcss": "^8.5.9",
69
+ "postcss": "^8.5.14",
72
70
  "postcss-selector-parser": "^7.1.1",
73
71
  "sass": "^1.99.0",
74
- "typescript": "^6.0.2"
72
+ "source-map-js": "^1.2.1"
75
73
  },
76
74
  publishConfig: {
77
75
  "registry": "https://registry.npmjs.org/",
@@ -80,18 +78,19 @@ var package_default = {
80
78
  };
81
79
  //#endregion
82
80
  //#region src/bin/index.js
83
- program.command("build").option("-c, --work-path <path>", "编译工作目录").option("-s, --target-path <path>", "编译产物存放路径").option("-w, --watch", "启用监听文件改动").option("--no-app-id-dir", "产物根目录不包含appId").action(async (options) => {
81
+ program.command("build").option("-c, --work-path <path>", "编译工作目录").option("-s, --target-path <path>", "编译产物存放路径").option("-w, --watch", "启用监听文件改动").option("--no-app-id-dir", "产物根目录不包含appId").option("--sourcemap", "生成 sourcemap 文件用于调试").action(async (options) => {
84
82
  const workPath = options.workPath ? path.resolve(options.workPath) : process.cwd();
85
83
  const targetPath = options.targetPath ? path.resolve(options.targetPath) : process.cwd();
86
84
  const useAppIdDir = options.appIdDir !== false;
87
- await build(targetPath, workPath, useAppIdDir);
85
+ const sourcemap = !!options.sourcemap;
86
+ await build(targetPath, workPath, useAppIdDir, { sourcemap });
88
87
  if (options.watch) chokidar.watch(workPath, {
89
88
  persistent: true,
90
89
  ignoreInitial: true
91
90
  }).on("all", async (event, path) => {
92
91
  if (event === "change") {
93
92
  console.log(`${path} 改动,重新编译`);
94
- await build(targetPath, workPath, useAppIdDir);
93
+ await build(targetPath, workPath, useAppIdDir, { sourcemap });
95
94
  }
96
95
  });
97
96
  });
@@ -0,0 +1,166 @@
1
+ import { Parser } from "htmlparser2";
2
+ //#region src/common/compatibility-reference.js
3
+ var supportedBuiltinComponents = [
4
+ "block",
5
+ "button",
6
+ "checkbox",
7
+ "checkbox-group",
8
+ "cover-image",
9
+ "cover-view",
10
+ "form",
11
+ "icon",
12
+ "image",
13
+ "input",
14
+ "label",
15
+ "movable-area",
16
+ "movable-view",
17
+ "navigation-bar",
18
+ "navigator",
19
+ "picker",
20
+ "picker-view",
21
+ "picker-view-column",
22
+ "progress",
23
+ "radio",
24
+ "radio-group",
25
+ "rich-text",
26
+ "scroll-view",
27
+ "slider",
28
+ "slot",
29
+ "swiper",
30
+ "swiper-item",
31
+ "switch",
32
+ "template",
33
+ "text",
34
+ "textarea",
35
+ "video",
36
+ "view",
37
+ "web-view",
38
+ "wxs",
39
+ "include",
40
+ "import"
41
+ ];
42
+ var supportedWxApis = [
43
+ "env",
44
+ "canIUse",
45
+ "openSystemBluetoothSetting",
46
+ "getWindowInfo",
47
+ "getSystemSetting",
48
+ "getSystemInfoSync",
49
+ "getSystemInfoAsync",
50
+ "getSystemInfo",
51
+ "reLaunch",
52
+ "redirectTo",
53
+ "navigateTo",
54
+ "navigateBack",
55
+ "showToast",
56
+ "showModal",
57
+ "showLoading",
58
+ "showActionSheet",
59
+ "hideToast",
60
+ "hideLoading",
61
+ "setNavigationBarTitle",
62
+ "setNavigationBarColor",
63
+ "pageScrollTo",
64
+ "getMenuButtonBoundingClientRect",
65
+ "createAnimation",
66
+ "createSelectorQuery",
67
+ "createIntersectionObserver",
68
+ "request",
69
+ "downloadFile",
70
+ "uploadFile",
71
+ "setStorageSync",
72
+ "getStorageSync",
73
+ "removeStorageSync",
74
+ "clearStorageSync",
75
+ "setStorage",
76
+ "getStorage",
77
+ "removeStorage",
78
+ "clearStorage",
79
+ "getStorageInfoSync",
80
+ "getStorageInfo",
81
+ "saveImageToPhotosAlbum",
82
+ "previewImage",
83
+ "compressImage",
84
+ "chooseImage",
85
+ "chooseMedia",
86
+ "chooseContact",
87
+ "addPhoneContact",
88
+ "setClipboardData",
89
+ "getClipboardData",
90
+ "vibrateShort",
91
+ "vibrateLong",
92
+ "hideKeyboard",
93
+ "getNetworkType",
94
+ "makePhoneCall",
95
+ "extBridge",
96
+ "extOnBridge",
97
+ "extOffBridge"
98
+ ];
99
+ //#endregion
100
+ //#region src/common/compatibility.js
101
+ var cachedReference = null;
102
+ var warnedItems = /* @__PURE__ */ new Set();
103
+ function loadReference() {
104
+ if (cachedReference) return cachedReference;
105
+ cachedReference = {
106
+ supportedBuiltinComponents: new Set(supportedBuiltinComponents),
107
+ supportedWxApis: new Set(supportedWxApis)
108
+ };
109
+ return cachedReference;
110
+ }
111
+ function getWxMemberName(node) {
112
+ if (node?.type !== "MemberExpression") return null;
113
+ if (node.object?.type !== "Identifier" || node.object.name !== "wx") return null;
114
+ if (!node.computed && node.property?.type === "Identifier") return node.property.name;
115
+ if (node.computed && (node.property?.type === "StringLiteral" || node.property?.type === "Literal") && typeof node.property.value === "string") return node.property.value;
116
+ return null;
117
+ }
118
+ function warnUnsupportedWxApi(apiName, filePath, line) {
119
+ const { supportedWxApis } = loadReference();
120
+ if (!apiName || supportedWxApis.has(apiName)) return;
121
+ const location = formatLocation(filePath, line);
122
+ warnOnce("api", apiName, location, `[compat] Unsupported wx API: wx.${apiName}${location}`);
123
+ }
124
+ function warnUnsupportedComponent(tagName, filePath, line) {
125
+ const { supportedBuiltinComponents } = loadReference();
126
+ if (!tagName || supportedBuiltinComponents.has(tagName)) return;
127
+ const location = formatLocation(filePath, line);
128
+ warnOnce("component", tagName, location, `[compat] Unsupported or undeclared component: <${tagName}>${location}`);
129
+ }
130
+ function checkTemplateCompatibility(content, filePath, components = {}) {
131
+ let parser;
132
+ parser = new Parser({
133
+ onopentag(tagName) {
134
+ if (components?.[tagName]) return;
135
+ warnUnsupportedComponent(tagName, filePath, getLineByIndex(content, parser.startIndex));
136
+ },
137
+ onerror(error) {
138
+ console.warn("[compat]", `Failed to parse template for compatibility diagnostics: ${filePath}`, error.message);
139
+ }
140
+ }, {
141
+ xmlMode: true,
142
+ lowerCaseTags: false,
143
+ lowerCaseAttributeNames: false,
144
+ withStartIndices: true
145
+ });
146
+ parser.write(content);
147
+ parser.end();
148
+ }
149
+ function getLineByIndex(content, index) {
150
+ if (typeof index !== "number" || index < 0) return null;
151
+ let line = 1;
152
+ for (let i = 0; i < index; i++) if (content.charCodeAt(i) === 10) line++;
153
+ return line;
154
+ }
155
+ function formatLocation(filePath, line) {
156
+ if (!filePath) return "";
157
+ return line ? ` (${filePath}:${line})` : ` (${filePath})`;
158
+ }
159
+ function warnOnce(type, name, location, message) {
160
+ const key = `${type}:${name}:${location}`;
161
+ if (warnedItems.has(key)) return;
162
+ warnedItems.add(key);
163
+ console.warn(message);
164
+ }
165
+ //#endregion
166
+ export { getWxMemberName as n, warnUnsupportedWxApi as r, checkTemplateCompatibility as t };
@@ -0,0 +1,184 @@
1
+ require("./env-Dmnqp9bD.cjs");
2
+ let htmlparser2 = require("htmlparser2");
3
+ //#region src/common/compatibility-reference.js
4
+ var supportedBuiltinComponents = [
5
+ "block",
6
+ "button",
7
+ "checkbox",
8
+ "checkbox-group",
9
+ "cover-image",
10
+ "cover-view",
11
+ "form",
12
+ "icon",
13
+ "image",
14
+ "input",
15
+ "label",
16
+ "movable-area",
17
+ "movable-view",
18
+ "navigation-bar",
19
+ "navigator",
20
+ "picker",
21
+ "picker-view",
22
+ "picker-view-column",
23
+ "progress",
24
+ "radio",
25
+ "radio-group",
26
+ "rich-text",
27
+ "scroll-view",
28
+ "slider",
29
+ "slot",
30
+ "swiper",
31
+ "swiper-item",
32
+ "switch",
33
+ "template",
34
+ "text",
35
+ "textarea",
36
+ "video",
37
+ "view",
38
+ "web-view",
39
+ "wxs",
40
+ "include",
41
+ "import"
42
+ ];
43
+ var supportedWxApis = [
44
+ "env",
45
+ "canIUse",
46
+ "openSystemBluetoothSetting",
47
+ "getWindowInfo",
48
+ "getSystemSetting",
49
+ "getSystemInfoSync",
50
+ "getSystemInfoAsync",
51
+ "getSystemInfo",
52
+ "reLaunch",
53
+ "redirectTo",
54
+ "navigateTo",
55
+ "navigateBack",
56
+ "showToast",
57
+ "showModal",
58
+ "showLoading",
59
+ "showActionSheet",
60
+ "hideToast",
61
+ "hideLoading",
62
+ "setNavigationBarTitle",
63
+ "setNavigationBarColor",
64
+ "pageScrollTo",
65
+ "getMenuButtonBoundingClientRect",
66
+ "createAnimation",
67
+ "createSelectorQuery",
68
+ "createIntersectionObserver",
69
+ "request",
70
+ "downloadFile",
71
+ "uploadFile",
72
+ "setStorageSync",
73
+ "getStorageSync",
74
+ "removeStorageSync",
75
+ "clearStorageSync",
76
+ "setStorage",
77
+ "getStorage",
78
+ "removeStorage",
79
+ "clearStorage",
80
+ "getStorageInfoSync",
81
+ "getStorageInfo",
82
+ "saveImageToPhotosAlbum",
83
+ "previewImage",
84
+ "compressImage",
85
+ "chooseImage",
86
+ "chooseMedia",
87
+ "chooseContact",
88
+ "addPhoneContact",
89
+ "setClipboardData",
90
+ "getClipboardData",
91
+ "vibrateShort",
92
+ "vibrateLong",
93
+ "hideKeyboard",
94
+ "getNetworkType",
95
+ "makePhoneCall",
96
+ "extBridge",
97
+ "extOnBridge",
98
+ "extOffBridge"
99
+ ];
100
+ //#endregion
101
+ //#region src/common/compatibility.js
102
+ var cachedReference = null;
103
+ var warnedItems = /* @__PURE__ */ new Set();
104
+ function loadReference() {
105
+ if (cachedReference) return cachedReference;
106
+ cachedReference = {
107
+ supportedBuiltinComponents: new Set(supportedBuiltinComponents),
108
+ supportedWxApis: new Set(supportedWxApis)
109
+ };
110
+ return cachedReference;
111
+ }
112
+ function getWxMemberName(node) {
113
+ if (node?.type !== "MemberExpression") return null;
114
+ if (node.object?.type !== "Identifier" || node.object.name !== "wx") return null;
115
+ if (!node.computed && node.property?.type === "Identifier") return node.property.name;
116
+ if (node.computed && (node.property?.type === "StringLiteral" || node.property?.type === "Literal") && typeof node.property.value === "string") return node.property.value;
117
+ return null;
118
+ }
119
+ function warnUnsupportedWxApi(apiName, filePath, line) {
120
+ const { supportedWxApis } = loadReference();
121
+ if (!apiName || supportedWxApis.has(apiName)) return;
122
+ const location = formatLocation(filePath, line);
123
+ warnOnce("api", apiName, location, `[compat] Unsupported wx API: wx.${apiName}${location}`);
124
+ }
125
+ function warnUnsupportedComponent(tagName, filePath, line) {
126
+ const { supportedBuiltinComponents } = loadReference();
127
+ if (!tagName || supportedBuiltinComponents.has(tagName)) return;
128
+ const location = formatLocation(filePath, line);
129
+ warnOnce("component", tagName, location, `[compat] Unsupported or undeclared component: <${tagName}>${location}`);
130
+ }
131
+ function checkTemplateCompatibility(content, filePath, components = {}) {
132
+ let parser;
133
+ parser = new htmlparser2.Parser({
134
+ onopentag(tagName) {
135
+ if (components?.[tagName]) return;
136
+ warnUnsupportedComponent(tagName, filePath, getLineByIndex(content, parser.startIndex));
137
+ },
138
+ onerror(error) {
139
+ console.warn("[compat]", `Failed to parse template for compatibility diagnostics: ${filePath}`, error.message);
140
+ }
141
+ }, {
142
+ xmlMode: true,
143
+ lowerCaseTags: false,
144
+ lowerCaseAttributeNames: false,
145
+ withStartIndices: true
146
+ });
147
+ parser.write(content);
148
+ parser.end();
149
+ }
150
+ function getLineByIndex(content, index) {
151
+ if (typeof index !== "number" || index < 0) return null;
152
+ let line = 1;
153
+ for (let i = 0; i < index; i++) if (content.charCodeAt(i) === 10) line++;
154
+ return line;
155
+ }
156
+ function formatLocation(filePath, line) {
157
+ if (!filePath) return "";
158
+ return line ? ` (${filePath}:${line})` : ` (${filePath})`;
159
+ }
160
+ function warnOnce(type, name, location, message) {
161
+ const key = `${type}:${name}:${location}`;
162
+ if (warnedItems.has(key)) return;
163
+ warnedItems.add(key);
164
+ console.warn(message);
165
+ }
166
+ //#endregion
167
+ Object.defineProperty(exports, "checkTemplateCompatibility", {
168
+ enumerable: true,
169
+ get: function() {
170
+ return checkTemplateCompatibility;
171
+ }
172
+ });
173
+ Object.defineProperty(exports, "getWxMemberName", {
174
+ enumerable: true,
175
+ get: function() {
176
+ return getWxMemberName;
177
+ }
178
+ });
179
+ Object.defineProperty(exports, "warnUnsupportedWxApi", {
180
+ enumerable: true,
181
+ get: function() {
182
+ return warnUnsupportedWxApi;
183
+ }
184
+ });