@dimina-kit/compiler 0.0.1-dev.20260706064107 → 0.0.1

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.
@@ -7,16 +7,13 @@ import {
7
7
  getAppName,
8
8
  getPageConfigInfo,
9
9
  getPages,
10
- getStyleExts,
11
10
  getTargetPath,
12
- getTemplateExts,
13
- getViewScriptExts,
14
11
  getWorkPath,
15
12
  resetFs,
16
13
  resetStoreInfo,
17
14
  setFs,
18
15
  storeInfo
19
- } from "./compile-core.node-chunks/chunk-QJ34C5KK.js";
16
+ } from "./compile-core.node-chunks/chunk-5ND5V2SC.js";
20
17
 
21
18
  // ../../dimina/fe/packages/compiler/src/common/publish.js
22
19
  function createDist() {
@@ -171,7 +168,7 @@ var NpmBuilder = class {
171
168
  * @returns {boolean} 是否为小程序文件
172
169
  */
173
170
  isMiniprogramFile(filename) {
174
- const miniprogramExts = [".js", ".json", ".ts", ...getTemplateExts(), ...getStyleExts(), ...getViewScriptExts()];
171
+ const miniprogramExts = [".js", ".json", ".wxml", ".wxss", ".wxs", ".ts", ".less", ".scss", ".styl"];
175
172
  const ext = path.extname(filename).toLowerCase();
176
173
  return miniprogramExts.includes(ext) || filename === "package.json" || filename === "README.md" || filename.startsWith(".");
177
174
  }
@@ -254,9 +251,9 @@ var NpmBuilder = class {
254
251
 
255
252
  // src/compile-core.js
256
253
  var STAGE_IMPORTERS = {
257
- logic: () => import("./compile-core.node-chunks/logic-compiler-2SQFOFEO.js"),
258
- view: () => import("./compile-core.node-chunks/view-compiler-WQNV7H5G.js"),
259
- style: () => import("./compile-core.node-chunks/style-compiler-ZEJ3XLTS.js")
254
+ logic: () => import("./compile-core.node-chunks/logic-compiler-RX63Y2FZ.js"),
255
+ view: () => import("./compile-core.node-chunks/view-compiler-KA2OZG44.js"),
256
+ style: () => import("./compile-core.node-chunks/style-compiler-JUY5MZSO.js")
260
257
  };
261
258
  var stageLoads = /* @__PURE__ */ new Map();
262
259
  var stageModules = /* @__PURE__ */ new Map();
@@ -1,7 +1,3 @@
1
- import {
2
- getViewScriptTags
3
- } from "./chunk-7FGOYOXU.js";
4
-
5
1
  // ../../dimina/fe/packages/compiler/src/common/compatibility.js
6
2
  import { Parser } from "htmlparser2";
7
3
 
@@ -146,7 +142,7 @@ function warnUnsupportedWxApi(apiName, filePath, line) {
146
142
  }
147
143
  function warnUnsupportedComponent(tagName, filePath, line) {
148
144
  const { supportedBuiltinComponents: supportedBuiltinComponents2 } = loadReference();
149
- if (!tagName || supportedBuiltinComponents2.has(tagName) || getViewScriptTags().includes(tagName)) {
145
+ if (!tagName || supportedBuiltinComponents2.has(tagName)) {
150
146
  return;
151
147
  }
152
148
  const location = formatLocation(filePath, line);
@@ -6,13 +6,10 @@ import {
6
6
  getAppName,
7
7
  getPageConfigInfo,
8
8
  getPages,
9
- getStyleExts,
10
9
  getTargetPath,
11
- getTemplateExts,
12
- getViewScriptExts,
13
10
  getWorkPath,
14
11
  storeInfo
15
- } from "./chunk-7FGOYOXU.js";
12
+ } from "./chunk-UYQ7D5I5.js";
16
13
 
17
14
  // ../../dimina/fe/packages/compiler/src/common/publish.js
18
15
  import path from "node:path";
@@ -235,7 +232,7 @@ var NpmBuilder = class {
235
232
  * @returns {boolean} 是否为小程序文件
236
233
  */
237
234
  isMiniprogramFile(filename) {
238
- const miniprogramExts = [".js", ".json", ".ts", ...getTemplateExts(), ...getStyleExts(), ...getViewScriptExts()];
235
+ const miniprogramExts = [".js", ".json", ".wxml", ".wxss", ".wxs", ".ts", ".less", ".scss", ".styl"];
239
236
  const ext = path2.extname(filename).toLowerCase();
240
237
  return miniprogramExts.includes(ext) || filename === "package.json" || filename === "README.md" || filename.startsWith(".");
241
238
  }
@@ -318,9 +315,9 @@ var NpmBuilder = class {
318
315
 
319
316
  // src/compile-core.js
320
317
  var STAGE_IMPORTERS = {
321
- logic: () => import("./logic-compiler-BODAINZQ.js"),
322
- view: () => import("./view-compiler-HOFFL63K.js"),
323
- style: () => import("./style-compiler-TUNDVSR5.js")
318
+ logic: () => import("./logic-compiler-3VVLN3YN.js"),
319
+ view: () => import("./view-compiler-KAYOMOXO.js"),
320
+ style: () => import("./style-compiler-QOUWS72U.js")
324
321
  };
325
322
  var stageLoads = /* @__PURE__ */ new Map();
326
323
  var stageModules = /* @__PURE__ */ new Map();
@@ -367,94 +367,23 @@ var NpmResolver = class {
367
367
  var pathInfo = {};
368
368
  var configInfo = {};
369
369
  var npmResolver = null;
370
- var DEFAULT_TEMPLATE_EXTS = [".wxml", ".ddml"];
371
- var DEFAULT_STYLE_EXTS = [".wxss", ".ddss", ".less", ".scss", ".sass"];
372
- var DEFAULT_VIEW_SCRIPT_EXTS = [".wxs"];
373
- var DEFAULT_VIEW_SCRIPT_TAGS = ["wxs", "dds"];
374
- var RESERVED_EXTS = /* @__PURE__ */ new Set([
375
- ...DEFAULT_TEMPLATE_EXTS,
376
- ...DEFAULT_STYLE_EXTS,
377
- ...DEFAULT_VIEW_SCRIPT_EXTS,
378
- ".js",
379
- ".ts",
380
- ".json"
381
- ]);
382
- var compilerOptions = normalizeFileTypes();
383
- function normalizeExt(raw) {
384
- if (typeof raw !== "string") {
385
- return null;
386
- }
387
- const v = raw.trim().toLowerCase().replace(/^\.+/, "");
388
- if (!/^[a-z0-9_-]+$/.test(v)) {
389
- return null;
390
- }
391
- return `.${v}`;
392
- }
393
- function normalizeTag(raw) {
394
- if (typeof raw !== "string") {
395
- return null;
396
- }
397
- const v = raw.trim().toLowerCase().replace(/^\.+/, "");
398
- if (!/^[a-z][a-z0-9_-]*$/.test(v)) {
399
- return null;
400
- }
401
- return v;
402
- }
403
- function mergeUnique(builtins, custom, normalizer, reserved) {
404
- const out = [...builtins];
405
- const seen = new Set(builtins);
406
- if (Array.isArray(custom)) {
407
- for (const raw of custom) {
408
- const n = normalizer(raw);
409
- if (n && !seen.has(n) && !reserved?.has(n)) {
410
- seen.add(n);
411
- out.push(n);
412
- }
413
- }
414
- }
415
- return out;
416
- }
417
- function normalizeFileTypes(fileTypes = {}) {
418
- const ft = fileTypes || {};
419
- return {
420
- templateExts: mergeUnique(DEFAULT_TEMPLATE_EXTS, ft.template, normalizeExt, RESERVED_EXTS),
421
- styleExts: mergeUnique(DEFAULT_STYLE_EXTS, ft.style, normalizeExt, RESERVED_EXTS),
422
- viewScriptExts: mergeUnique(DEFAULT_VIEW_SCRIPT_EXTS, ft.viewScript, normalizeExt, RESERVED_EXTS),
423
- viewScriptTags: mergeUnique(DEFAULT_VIEW_SCRIPT_TAGS, ft.viewScript, normalizeTag)
424
- };
425
- }
426
- function storeInfo(workPath, options = {}) {
370
+ function storeInfo(workPath) {
427
371
  storePathInfo(workPath);
428
372
  storeProjectConfig();
429
373
  storeAppConfig();
430
374
  storePageConfig();
431
- compilerOptions = normalizeFileTypes(options.fileTypes);
432
375
  return {
433
376
  pathInfo,
434
- configInfo,
435
- compilerOptions
377
+ configInfo
436
378
  };
437
379
  }
438
380
  function resetStoreInfo(opts) {
439
381
  pathInfo = opts.pathInfo;
440
382
  configInfo = opts.configInfo;
441
- compilerOptions = opts.compilerOptions || normalizeFileTypes();
442
383
  if (pathInfo.workPath) {
443
384
  npmResolver = new NpmResolver(pathInfo.workPath);
444
385
  }
445
386
  }
446
- function getTemplateExts() {
447
- return compilerOptions.templateExts;
448
- }
449
- function getStyleExts() {
450
- return compilerOptions.styleExts;
451
- }
452
- function getViewScriptExts() {
453
- return compilerOptions.viewScriptExts;
454
- }
455
- function getViewScriptTags() {
456
- return compilerOptions.viewScriptTags;
457
- }
458
387
  function storePathInfo(workPath) {
459
388
  pathInfo.workPath = workPath;
460
389
  if (process2.env.TARGET_PATH) {
@@ -702,10 +631,6 @@ export {
702
631
  __resetAssets,
703
632
  storeInfo,
704
633
  resetStoreInfo,
705
- getTemplateExts,
706
- getStyleExts,
707
- getViewScriptExts,
708
- getViewScriptTags,
709
634
  getContentByPath,
710
635
  resolveAppAlias,
711
636
  getTargetPath,
@@ -1,7 +1,7 @@
1
1
  import {
2
2
  getWxMemberName,
3
3
  warnUnsupportedWxApi
4
- } from "./chunk-C7GEIDCP.js";
4
+ } from "./chunk-FVCSERCO.js";
5
5
  import {
6
6
  isMainThread,
7
7
  parentPort
@@ -18,7 +18,7 @@ import {
18
18
  hasCompileInfo,
19
19
  resetStoreInfo,
20
20
  resolveAppAlias
21
- } from "./chunk-7FGOYOXU.js";
21
+ } from "./chunk-UYQ7D5I5.js";
22
22
 
23
23
  // ../../dimina/fe/packages/compiler/src/core/logic-compiler.js
24
24
  import fs from "node:fs";
@@ -7,13 +7,12 @@ import {
7
7
  getAppId,
8
8
  getComponent,
9
9
  getContentByPath,
10
- getStyleExts,
11
10
  getTargetPath,
12
11
  getWorkPath,
13
12
  resetStoreInfo,
14
13
  tagWhiteList,
15
14
  transformRpx
16
- } from "./chunk-7FGOYOXU.js";
15
+ } from "./chunk-UYQ7D5I5.js";
17
16
 
18
17
  // ../../dimina/fe/packages/compiler/src/core/style-compiler.js
19
18
  import fs from "node:fs";
@@ -25,6 +24,7 @@ import less from "less";
25
24
  import postcss from "postcss";
26
25
  import selectorParser from "postcss-selector-parser";
27
26
  import * as sass from "sass";
27
+ var fileType = [".wxss", ".ddss", ".less", ".scss", ".sass"];
28
28
  var compileRes = /* @__PURE__ */ new Map();
29
29
  if (!isMainThread) {
30
30
  parentPort.on("message", async ({ pages, storeInfo }) => {
@@ -212,7 +212,7 @@ function normalizeCssUrlValue(value, absolutePath) {
212
212
  function getAbsolutePath(modulePath) {
213
213
  const workPath = getWorkPath();
214
214
  const src = modulePath.startsWith("/") ? modulePath : `/${modulePath}`;
215
- for (const ssType of getStyleExts()) {
215
+ for (const ssType of fileType) {
216
216
  const ssFullPath = `${workPath}${src}${ssType}`;
217
217
  if (fs.existsSync(ssFullPath)) {
218
218
  return ssFullPath;
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  checkTemplateCompatibility
3
- } from "./chunk-C7GEIDCP.js";
3
+ } from "./chunk-FVCSERCO.js";
4
4
  import {
5
5
  isMainThread,
6
6
  parentPort
@@ -12,14 +12,11 @@ import {
12
12
  getComponent,
13
13
  getContentByPath,
14
14
  getTargetPath,
15
- getTemplateExts,
16
- getViewScriptExts,
17
- getViewScriptTags,
18
15
  getWorkPath,
19
16
  resetStoreInfo,
20
17
  tagWhiteList,
21
18
  transformRpx
22
- } from "./chunk-7FGOYOXU.js";
19
+ } from "./chunk-UYQ7D5I5.js";
23
20
 
24
21
  // ../../dimina/fe/packages/compiler/src/core/view-compiler.js
25
22
  import fs from "node:fs";
@@ -155,13 +152,7 @@ function parseBindings(bindings) {
155
152
  }
156
153
 
157
154
  // ../../dimina/fe/packages/compiler/src/core/view-compiler.js
158
- function buildExtStripRegex(exts) {
159
- const alt = exts.map((e) => e.replace(/[.*+?^${}()|[\]\\]/g, "\\$&")).join("|");
160
- return new RegExp(`(${alt})$`);
161
- }
162
- function stripViewScriptExt(p) {
163
- return p.replace(buildExtStripRegex(getViewScriptExts()), "");
164
- }
155
+ var fileType = [".wxml", ".ddml"];
165
156
  function parseJs(code, filename = "view-compiler.js", sourceType = "module") {
166
157
  return parseSync2(filename, code, {
167
158
  sourceType,
@@ -367,8 +358,8 @@ function scanWxsFiles(dir, workPath) {
367
358
  const stat = fs.statSync(fullPath);
368
359
  if (stat.isDirectory()) {
369
360
  scanWxsFiles(fullPath, workPath);
370
- } else if (stat.isFile() && getViewScriptExts().some((ext) => item.endsWith(ext))) {
371
- const relativePath = stripViewScriptExt(fullPath.replace(workPath, ""));
361
+ } else if (stat.isFile() && item.endsWith(".wxs")) {
362
+ const relativePath = fullPath.replace(workPath, "").replace(/\.wxs$/, "");
372
363
  const moduleName = relativePath.replace(/[\/\\@\-]/g, "_").replace(/^_/, "");
373
364
  wxsFilePathMap.set(moduleName, fullPath);
374
365
  }
@@ -598,7 +589,7 @@ function processWxsContent(wxsContent, wxsFilePath, scriptModule, workPath, file
598
589
  if (filePath && filePath.includes("/miniprogram_npm/")) {
599
590
  const currentWxsDir = path.dirname(wxsFilePath);
600
591
  resolvedWxsPath = path.resolve(currentWxsDir, requirePath);
601
- const relativePath = stripViewScriptExt(resolvedWxsPath.replace(workPath, ""));
592
+ const relativePath = resolvedWxsPath.replace(workPath, "").replace(/\.wxs$/, "");
602
593
  const moduleName = relativePath.replace(/[\/\\@\-]/g, "_").replace(/^_/, "");
603
594
  processWxsDependency(resolvedWxsPath, moduleName, scriptModule, workPath, filePath);
604
595
  replacements.push({
@@ -609,7 +600,7 @@ function processWxsContent(wxsContent, wxsFilePath, scriptModule, workPath, file
609
600
  } else {
610
601
  const currentWxsDir = path.dirname(wxsFilePath);
611
602
  resolvedWxsPath = path.resolve(currentWxsDir, requirePath);
612
- const relativePath = stripViewScriptExt(resolvedWxsPath.replace(workPath, ""));
603
+ const relativePath = resolvedWxsPath.replace(workPath, "").replace(/\.wxs$/, "");
613
604
  const depModuleName = relativePath.replace(/[\/\\@\-]/g, "_").replace(/^_/, "");
614
605
  processWxsDependency(resolvedWxsPath, depModuleName, scriptModule, workPath, filePath);
615
606
  replacements.push({
@@ -825,7 +816,7 @@ function toCompileTemplate(isComponent, path2, components, componentPlaceholder,
825
816
  const src = $(elem).attr("src");
826
817
  if (src) {
827
818
  const includeFullPath = getAbsolutePath(workPath, path2, src);
828
- let includePath = includeFullPath.replace(workPath, "").replace(buildExtStripRegex(getTemplateExts()), "");
819
+ let includePath = includeFullPath.replace(workPath, "").replace(/\.(wxml|ddml)$/, "");
829
820
  const includeDiagnosticSource = includeFullPath.startsWith(workPath) ? includeFullPath.slice(workPath.length) : includePath;
830
821
  if (!includePath.startsWith("/")) {
831
822
  includePath = "/" + includePath;
@@ -851,7 +842,8 @@ function toCompileTemplate(isComponent, path2, components, componentPlaceholder,
851
842
  );
852
843
  processIncludedFileWxsDependencies(includeContent, includePath, scriptModule, components, processedPaths);
853
844
  $includeContent("template").remove();
854
- $includeContent(getViewScriptTags().join(",")).remove();
845
+ $includeContent("wxs").remove();
846
+ $includeContent("dds").remove();
855
847
  const processedContent = processIncludeConditionalAttrs($, elem, $includeContent.html());
856
848
  $(elem).replaceWith(processedContent);
857
849
  } else {
@@ -868,7 +860,7 @@ function toCompileTemplate(isComponent, path2, components, componentPlaceholder,
868
860
  const src = $(elem).attr("src");
869
861
  if (src) {
870
862
  const importFullPath = getAbsolutePath(workPath, path2, src);
871
- let importPath = importFullPath.replace(workPath, "").replace(buildExtStripRegex(getTemplateExts()), "");
863
+ let importPath = importFullPath.replace(workPath, "").replace(/\.(wxml|ddml)$/, "");
872
864
  const importDiagnosticSource = importFullPath.startsWith(workPath) ? importFullPath.slice(workPath.length) : importPath;
873
865
  if (!importPath.startsWith("/")) {
874
866
  importPath = "/" + importPath;
@@ -915,7 +907,8 @@ function transTagTemplate($, templateModule, path2, components, componentPlaceho
915
907
  const templateContent = $(elem);
916
908
  templateContent.find("import").remove();
917
909
  templateContent.find("include").remove();
918
- templateContent.find(getViewScriptTags().join(",")).remove();
910
+ templateContent.find("wxs").remove();
911
+ templateContent.find("dds").remove();
919
912
  transAsses($, templateContent.find("image"), path2);
920
913
  const res = [];
921
914
  transHtmlTag(templateContent.html(), res, components, componentPlaceholder);
@@ -1222,7 +1215,7 @@ function parseKeyExpression(exp, itemName = "item", indexName = "index") {
1222
1215
  }
1223
1216
  function getViewPath(workPath, src) {
1224
1217
  const aSrc = src.startsWith("/") ? src : `/${src}`;
1225
- for (const mlType of getTemplateExts()) {
1218
+ for (const mlType of fileType) {
1226
1219
  const mlFullPath = `${workPath}${aSrc}${mlType}`;
1227
1220
  if (fs.existsSync(mlFullPath)) {
1228
1221
  return mlFullPath;
@@ -1331,7 +1324,10 @@ function parseTemplateDataExp(exp) {
1331
1324
  return `{${parseBraceExp(exp)}}`;
1332
1325
  }
1333
1326
  function transTagWxs($, scriptModule, filePath) {
1334
- const wxsNodes = $(getViewScriptTags().join(","));
1327
+ let wxsNodes = $("wxs");
1328
+ if (wxsNodes.length === 0) {
1329
+ wxsNodes = $("dds");
1330
+ }
1335
1331
  wxsNodes.each((_, elem) => {
1336
1332
  const smName = $(elem).attr("module");
1337
1333
  if (smName) {
@@ -1350,7 +1346,7 @@ function transTagWxs($, scriptModule, filePath) {
1350
1346
  wxsFilePath = getAbsolutePath(workPath, filePath, src);
1351
1347
  }
1352
1348
  if (wxsFilePath) {
1353
- const relativePath = stripViewScriptExt(wxsFilePath.replace(workPath, ""));
1349
+ const relativePath = wxsFilePath.replace(workPath, "").replace(/\.wxs$/, "");
1354
1350
  uniqueModuleName = relativePath.replace(/[\/\\@\-]/g, "_").replace(/^_/, "");
1355
1351
  cacheKey = wxsFilePath;
1356
1352
  }
@@ -1423,8 +1419,12 @@ function collectAllWxsModules(scriptRes, collectedPaths = /* @__PURE__ */ new Se
1423
1419
  return allWxsModules;
1424
1420
  }
1425
1421
  function loadWxsModule(modulePath, workPath, scriptModule) {
1422
+ if (!modulePath.startsWith("miniprogram_npm__") || !modulePath.includes("_wxs_")) {
1423
+ return null;
1424
+ }
1426
1425
  const wxsFilePath = wxsFilePathMap.get(modulePath);
1427
1426
  if (!wxsFilePath) {
1427
+ console.warn(`[view] \u65E0\u6CD5\u627E\u5230 wxs \u6A21\u5757\u6587\u4EF6: ${modulePath}`);
1428
1428
  return null;
1429
1429
  }
1430
1430
  try {
@@ -1516,8 +1516,6 @@ export {
1516
1516
  compileML,
1517
1517
  generateSlotDirective,
1518
1518
  generateVModelTemplate,
1519
- initWxsFilePathMap,
1520
- loadWxsModule,
1521
1519
  parseBraceExp,
1522
1520
  parseClassRules,
1523
1521
  parseKeyExpression,
package/dist/pool.node.js CHANGED
@@ -3,12 +3,12 @@ import {
3
3
  publishToDist,
4
4
  resetCompilerState,
5
5
  setupCompile
6
- } from "./pool.node-chunks/chunk-PDHO4Y56.js";
6
+ } from "./pool.node-chunks/chunk-MHOA4NGC.js";
7
7
  import {
8
8
  getAppConfigInfo,
9
9
  getAppId,
10
10
  getAppName
11
- } from "./pool.node-chunks/chunk-7FGOYOXU.js";
11
+ } from "./pool.node-chunks/chunk-UYQ7D5I5.js";
12
12
 
13
13
  // src/pool-node.js
14
14
  import { createRequire } from "node:module";