@dimina-kit/compiler 0.0.2-dev.20260718085557 → 0.0.2-dev.20260718095333

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.
@@ -12,7 +12,7 @@ import {
12
12
  getViewScriptExts,
13
13
  getWorkPath,
14
14
  storeInfo
15
- } from "./chunk-QLBB5HQB.js";
15
+ } from "./chunk-7F3E2G42.js";
16
16
 
17
17
  // ../../dimina/fe/packages/compiler/src/common/publish.js
18
18
  import path from "node:path";
@@ -318,9 +318,9 @@ var NpmBuilder = class {
318
318
 
319
319
  // src/compile-core.js
320
320
  var STAGE_IMPORTERS = {
321
- logic: () => import("./logic-compiler-PK5DY6DB.js"),
322
- view: () => import("./view-compiler-4GBP7IAT.js"),
323
- style: () => import("./style-compiler-X4EGM6MY.js")
321
+ logic: () => import("./logic-compiler-HMMTJJWY.js"),
322
+ view: () => import("./view-compiler-2VZMJ65O.js"),
323
+ style: () => import("./style-compiler-VGVCLQ7X.js")
324
324
  };
325
325
  var stageLoads = /* @__PURE__ */ new Map();
326
326
  var stageModules = /* @__PURE__ */ new Map();
@@ -1,7 +1,8 @@
1
1
  import {
2
2
  getWxMemberName,
3
+ takeCompatibilityWarnings,
3
4
  warnUnsupportedWxApi
4
- } from "./chunk-S7VHZTMY.js";
5
+ } from "./chunk-DQNLDQGT.js";
5
6
  import {
6
7
  isMainThread,
7
8
  parentPort
@@ -18,7 +19,7 @@ import {
18
19
  hasCompileInfo,
19
20
  resetStoreInfo,
20
21
  resolveAppAlias
21
- } from "./chunk-QLBB5HQB.js";
22
+ } from "./chunk-7F3E2G42.js";
22
23
 
23
24
  // ../../dimina/fe/packages/compiler/src/core/logic-compiler.js
24
25
  import fs from "node:fs";
@@ -157,7 +158,10 @@ ${error.stack}`);
157
158
  }
158
159
  await writeCompileRes(mainCompileRes, null);
159
160
  processedModules.clear();
160
- parentPort.postMessage({ success: true });
161
+ parentPort.postMessage({
162
+ success: true,
163
+ compatibilityWarnings: takeCompatibilityWarnings()
164
+ });
161
165
  } catch (error) {
162
166
  processedModules.clear();
163
167
  parentPort.postMessage({
@@ -210,18 +214,12 @@ async function compileJS(pages, root, mainCompileRes, progress) {
210
214
  }
211
215
  return compileRes;
212
216
  }
213
- async function buildJSByPath(packageName, module, compileRes, mainCompileRes, addExtra, depthChain = [], putMain = false) {
217
+ async function buildJSByPath(packageName, module, compileRes, mainCompileRes, addExtra, activePaths = /* @__PURE__ */ new Set(), putMain = false) {
214
218
  const currentPath = module.path;
215
- if (depthChain.includes(currentPath)) {
216
- console.warn("[logic]", `\u68C0\u6D4B\u5230\u5FAA\u73AF\u4F9D\u8D56: ${[...depthChain, currentPath].join(" -> ")}`);
217
- return;
218
- }
219
- if (depthChain.length > 20) {
220
- console.warn("[logic]", `\u68C0\u6D4B\u5230\u6DF1\u5EA6\u4F9D\u8D56: ${[...depthChain, currentPath].join(" -> ")}`);
219
+ if (!currentPath) {
221
220
  return;
222
221
  }
223
- depthChain = [...depthChain, currentPath];
224
- if (!module.path) {
222
+ if (activePaths.has(currentPath)) {
225
223
  return;
226
224
  }
227
225
  if (hasCompileInfo(module.path, compileRes, mainCompileRes)) {
@@ -258,6 +256,7 @@ async function buildJSByPath(packageName, module, compileRes, mainCompileRes, ad
258
256
  const extraInfo = {
259
257
  path: module.path
260
258
  };
259
+ activePaths.add(currentPath);
261
260
  if (module.component) {
262
261
  extraInfo.component = true;
263
262
  }
@@ -281,7 +280,7 @@ async function buildJSByPath(packageName, module, compileRes, mainCompileRes, ad
281
280
  if (!componentModule) {
282
281
  continue;
283
282
  }
284
- await buildJSByPath(packageName, componentModule, compileRes, mainCompileRes, true, depthChain, putMain || toMainSubPackage);
283
+ await buildJSByPath(packageName, componentModule, compileRes, mainCompileRes, true, activePaths, putMain || toMainSubPackage);
285
284
  componentsObj[name] = path;
286
285
  }
287
286
  extraInfo.usingComponents = componentsObj;
@@ -392,7 +391,7 @@ async function buildJSByPath(packageName, module, compileRes, mainCompileRes, ad
392
391
  }
393
392
  });
394
393
  for (const depId of dependenciesToProcess) {
395
- await buildJSByPath(packageName, { path: depId }, compileRes, mainCompileRes, false, depthChain, putMain);
394
+ await buildJSByPath(packageName, { path: depId }, compileRes, mainCompileRes, false, activePaths, putMain);
396
395
  }
397
396
  for (const replacement of pathReplacements.reverse()) {
398
397
  s.overwrite(replacement.start, replacement.end, `'${replacement.newValue}'`);
@@ -433,6 +432,7 @@ async function buildJSByPath(packageName, module, compileRes, mainCompileRes, ad
433
432
  compileInfo.code = modifiedCode;
434
433
  }
435
434
  processedModules.add(packageName + currentPath);
435
+ activePaths.delete(currentPath);
436
436
  }
437
437
  function isLocalAssetString(value) {
438
438
  return typeof value === "string" && !value.startsWith("http") && !value.startsWith("//") && (value.startsWith("/") || value.startsWith("./") || value.startsWith("../")) && /\.(?:png|jpe?g|gif|svg)(?:\?.*)?$/.test(value);
@@ -13,7 +13,7 @@ import {
13
13
  resetStoreInfo,
14
14
  tagWhiteList,
15
15
  transformRpx
16
- } from "./chunk-QLBB5HQB.js";
16
+ } from "./chunk-7F3E2G42.js";
17
17
 
18
18
  // ../../dimina/fe/packages/compiler/src/core/style-compiler.js
19
19
  import fs from "node:fs";
@@ -61,7 +61,7 @@ if (!isMainThread) {
61
61
  }
62
62
  async function compileSS(pages, root, progress) {
63
63
  for (const page of pages) {
64
- const code = await buildCompileCss(page, [], /* @__PURE__ */ new Set()) || "";
64
+ const code = await buildCompileCss(page, /* @__PURE__ */ new Set()) || "";
65
65
  const filename = `${page.path.replace(/\//g, "_")}`;
66
66
  if (root) {
67
67
  const subDir = `${getTargetPath()}/${root}`;
@@ -79,33 +79,63 @@ async function compileSS(pages, root, progress) {
79
79
  progress.completedTasks++;
80
80
  }
81
81
  }
82
- async function buildCompileCss(module, depthChain = [], compiledPaths = /* @__PURE__ */ new Set()) {
83
- const currentPath = module.path || module.absolutePath;
84
- if (depthChain.includes(currentPath)) {
85
- console.warn("[style]", `\u68C0\u6D4B\u5230\u5FAA\u73AF\u4F9D\u8D56: ${[...depthChain, currentPath].join(" -> ")}`);
86
- return "";
87
- }
88
- if (depthChain.length > 20) {
89
- console.warn("[style]", `\u68C0\u6D4B\u5230\u6DF1\u5EA6\u4F9D\u8D56: ${[...depthChain, currentPath].join(" -> ")}`);
90
- return "";
91
- }
92
- if (compiledPaths.has(currentPath)) {
93
- return "";
94
- }
95
- compiledPaths.add(currentPath);
96
- depthChain = [...depthChain, currentPath];
97
- let result = await enhanceCSS(module) || "";
98
- if (module.usingComponents) {
99
- for (const componentInfo of Object.values(module.usingComponents)) {
100
- const componentModule = getComponent(componentInfo);
101
- if (!componentModule) {
102
- continue;
82
+ async function buildCompileCss(module, compiledPaths = /* @__PURE__ */ new Set()) {
83
+ let result = "";
84
+ const pendingModules = [module];
85
+ while (pendingModules.length > 0) {
86
+ const currentModule = pendingModules.pop();
87
+ const currentPath = currentModule.path || currentModule.absolutePath;
88
+ if (compiledPaths.has(currentPath)) {
89
+ continue;
90
+ }
91
+ compiledPaths.add(currentPath);
92
+ result += await enhanceCSS(currentModule) || "";
93
+ const componentPaths = Object.values(currentModule.usingComponents || {});
94
+ for (let index = componentPaths.length - 1; index >= 0; index--) {
95
+ const componentModule = getComponent(componentPaths[index]);
96
+ if (componentModule) {
97
+ pendingModules.push(componentModule);
103
98
  }
104
- result += await buildCompileCss(componentModule, depthChain, compiledPaths) || "";
105
99
  }
106
100
  }
107
101
  return result;
108
102
  }
103
+ function boostExternalClassSelectors(cssCode, moduleId) {
104
+ if (!moduleId || !cssCode) {
105
+ return cssCode;
106
+ }
107
+ const scopeAttribute = `data-v-${moduleId}`;
108
+ const externalScopeAttribute = "data-dd-external-class-scope";
109
+ const ast = postcss.parse(cssCode);
110
+ ast.walkRules((rule) => {
111
+ if (!rule.selector.includes(`[${scopeAttribute}]`)) {
112
+ return;
113
+ }
114
+ rule.selector = selectorParser((selectors) => {
115
+ for (const selector of [...selectors.nodes]) {
116
+ const boostedSelector = selector.clone();
117
+ const scopeNodes = [];
118
+ boostedSelector.walkAttributes((attribute) => {
119
+ if (attribute.attribute === scopeAttribute) {
120
+ scopeNodes.push(attribute);
121
+ }
122
+ });
123
+ const targetScope = scopeNodes.at(-1);
124
+ if (!targetScope) {
125
+ continue;
126
+ }
127
+ targetScope.parent.insertAfter(targetScope, selectorParser.attribute({
128
+ attribute: externalScopeAttribute,
129
+ operator: "~=",
130
+ quoteMark: '"',
131
+ value: scopeAttribute
132
+ }));
133
+ selectors.append(boostedSelector);
134
+ }
135
+ }).processSync(rule.selector);
136
+ });
137
+ return ast.toResult().css;
138
+ }
109
139
  async function enhanceCSS(module) {
110
140
  const absolutePath = module.absolutePath ? module.absolutePath : getAbsolutePath(module.path);
111
141
  if (!absolutePath) {
@@ -153,7 +183,7 @@ async function enhanceCSS(module) {
153
183
  const str = node.params.replace(/^['"]|['"]$/g, "");
154
184
  const importFullPath = resolveStyleImportPath(absolutePath, str);
155
185
  node.remove();
156
- promises.push(buildCompileCss({ absolutePath: importFullPath, id: module.id }, [], /* @__PURE__ */ new Set()));
186
+ promises.push(buildCompileCss({ absolutePath: importFullPath, id: module.id }, /* @__PURE__ */ new Set()));
157
187
  } else if (node.type === "rule") {
158
188
  if (node.selector.includes("::v-deep")) {
159
189
  node.selector = node.selector.replace(/::v-deep\s+(\S[^{]*)/g, ":deep($1)");
@@ -183,11 +213,11 @@ async function enhanceCSS(module) {
183
213
  id: moduleId,
184
214
  scoped: !!moduleId
185
215
  }).code;
186
- const cleanedCode = await removeBaseComponentScope(scopedCode, moduleId);
216
+ const externalClassCode = boostExternalClassSelectors(scopedCode, moduleId);
187
217
  const res = await postcss([
188
218
  autoprefixer({ overrideBrowserslist: ["cover 99.5%"] }),
189
219
  cssnano()
190
- ]).process(cleanedCode, { from: void 0 });
220
+ ]).process(externalClassCode, { from: void 0 });
191
221
  const importCss = (await Promise.all(promises)).filter(Boolean).join("");
192
222
  const result = importCss + res.css;
193
223
  compileRes.set(cacheKey, result);
@@ -234,44 +264,25 @@ function normalizeRootStyleImports(source, workPath = getWorkPath()) {
234
264
  return `${prefix}${path.join(workPath, importPath)}${suffix}`;
235
265
  });
236
266
  }
237
- async function removeBaseComponentScope(css, moduleId) {
238
- if (!moduleId) return css;
239
- const ast = postcss.parse(css);
240
- const scopeAttrName = `data-v-${moduleId}`;
241
- ast.walkRules((rule) => {
242
- const hasBaseComponent = tagWhiteList.some(
243
- (tag) => rule.selector.includes(`.dd-${tag}`)
244
- );
245
- if (hasBaseComponent && rule.selector.includes(scopeAttrName)) {
246
- rule.selector = selectorParser((selectors) => {
247
- selectors.walkAttributes((attr) => {
248
- if (attr.attribute === scopeAttrName) {
249
- attr.remove();
250
- }
251
- });
252
- }).processSync(rule.selector);
253
- }
254
- });
255
- return ast.toResult().css;
256
- }
257
267
  function ensureImportSemicolons(css) {
258
268
  return css.replace(/@import[^;\n]*$/gm, (match) => {
259
269
  return match.endsWith(";") ? match : `${match};`;
260
270
  });
261
271
  }
262
272
  function processHostSelector(selector, moduleId) {
263
- return selector.replace(/^:host$/, `[data-v-${moduleId}]`).replace(/:host\(([^)]+)\)/g, `[data-v-${moduleId}]$1`).replace(/:host\s+/g, `[data-v-${moduleId}] `).replace(/:host(?=\.|#|:)/g, `[data-v-${moduleId}]`);
273
+ const hostSelector = `[data-dd-style-host~="${moduleId}"]`;
274
+ return selector.replace(/:host\(([^)]+)\)/g, `${hostSelector}$1`).replace(/:host(?![\w-])/g, hostSelector);
264
275
  }
265
276
  function __resetStyleState() {
266
277
  compileRes.clear();
267
278
  }
268
279
  export {
269
280
  __resetStyleState,
281
+ boostExternalClassSelectors,
270
282
  compileSS,
271
283
  ensureImportSemicolons,
272
284
  normalizeCssUrlValue,
273
285
  normalizeRootStyleImports,
274
286
  processHostSelector,
275
- removeBaseComponentScope,
276
287
  resolveStyleImportPath
277
288
  };