@dimina-kit/compiler 0.0.1-dev.20260706125036 → 0.0.1-dev.20260706131625

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.
@@ -14942,23 +14942,81 @@ var init_npm_resolver = __esm({
14942
14942
  });
14943
14943
 
14944
14944
  // ../../dimina/fe/packages/compiler/src/env.js
14945
- function storeInfo(workPath) {
14945
+ function normalizeExt(raw) {
14946
+ if (typeof raw !== "string") {
14947
+ return null;
14948
+ }
14949
+ const v = raw.trim().toLowerCase().replace(/^\.+/, "");
14950
+ if (!/^[a-z0-9_-]+$/.test(v)) {
14951
+ return null;
14952
+ }
14953
+ return `.${v}`;
14954
+ }
14955
+ function normalizeTag(raw) {
14956
+ if (typeof raw !== "string") {
14957
+ return null;
14958
+ }
14959
+ const v = raw.trim().toLowerCase().replace(/^\.+/, "");
14960
+ if (!/^[a-z][a-z0-9_-]*$/.test(v)) {
14961
+ return null;
14962
+ }
14963
+ return v;
14964
+ }
14965
+ function mergeUnique(builtins, custom, normalizer, reserved) {
14966
+ const out = [...builtins];
14967
+ const seen2 = new Set(builtins);
14968
+ if (Array.isArray(custom)) {
14969
+ for (const raw of custom) {
14970
+ const n2 = normalizer(raw);
14971
+ if (n2 && !seen2.has(n2) && !reserved?.has(n2)) {
14972
+ seen2.add(n2);
14973
+ out.push(n2);
14974
+ }
14975
+ }
14976
+ }
14977
+ return out;
14978
+ }
14979
+ function normalizeFileTypes(fileTypes = {}) {
14980
+ const ft = fileTypes || {};
14981
+ return {
14982
+ templateExts: mergeUnique(DEFAULT_TEMPLATE_EXTS, ft.template, normalizeExt, RESERVED_EXTS),
14983
+ styleExts: mergeUnique(DEFAULT_STYLE_EXTS, ft.style, normalizeExt, RESERVED_EXTS),
14984
+ viewScriptExts: mergeUnique(DEFAULT_VIEW_SCRIPT_EXTS, ft.viewScript, normalizeExt, RESERVED_EXTS),
14985
+ viewScriptTags: mergeUnique(DEFAULT_VIEW_SCRIPT_TAGS, ft.viewScript, normalizeTag)
14986
+ };
14987
+ }
14988
+ function storeInfo(workPath, options = {}) {
14946
14989
  storePathInfo(workPath);
14947
14990
  storeProjectConfig();
14948
14991
  storeAppConfig();
14949
14992
  storePageConfig();
14993
+ compilerOptions = normalizeFileTypes(options.fileTypes);
14950
14994
  return {
14951
14995
  pathInfo,
14952
- configInfo
14996
+ configInfo,
14997
+ compilerOptions
14953
14998
  };
14954
14999
  }
14955
15000
  function resetStoreInfo(opts) {
14956
15001
  pathInfo = opts.pathInfo;
14957
15002
  configInfo = opts.configInfo;
15003
+ compilerOptions = opts.compilerOptions || normalizeFileTypes();
14958
15004
  if (pathInfo.workPath) {
14959
15005
  npmResolver = new NpmResolver(pathInfo.workPath);
14960
15006
  }
14961
15007
  }
15008
+ function getTemplateExts() {
15009
+ return compilerOptions.templateExts;
15010
+ }
15011
+ function getStyleExts() {
15012
+ return compilerOptions.styleExts;
15013
+ }
15014
+ function getViewScriptExts() {
15015
+ return compilerOptions.viewScriptExts;
15016
+ }
15017
+ function getViewScriptTags() {
15018
+ return compilerOptions.viewScriptTags;
15019
+ }
14962
15020
  function storePathInfo(workPath) {
14963
15021
  pathInfo.workPath = workPath;
14964
15022
  if (process_default.env.TARGET_PATH) {
@@ -15196,7 +15254,7 @@ function getPages() {
15196
15254
  subPages
15197
15255
  };
15198
15256
  }
15199
- var import_node_path4, pathInfo, configInfo, npmResolver;
15257
+ var import_node_path4, pathInfo, configInfo, npmResolver, DEFAULT_TEMPLATE_EXTS, DEFAULT_STYLE_EXTS, DEFAULT_VIEW_SCRIPT_EXTS, DEFAULT_VIEW_SCRIPT_TAGS, RESERVED_EXTS, compilerOptions;
15200
15258
  var init_env = __esm({
15201
15259
  "../../dimina/fe/packages/compiler/src/env.js"() {
15202
15260
  init_fs();
@@ -15209,6 +15267,19 @@ var init_env = __esm({
15209
15267
  pathInfo = {};
15210
15268
  configInfo = {};
15211
15269
  npmResolver = null;
15270
+ DEFAULT_TEMPLATE_EXTS = [".wxml", ".ddml"];
15271
+ DEFAULT_STYLE_EXTS = [".wxss", ".ddss", ".less", ".scss", ".sass"];
15272
+ DEFAULT_VIEW_SCRIPT_EXTS = [".wxs"];
15273
+ DEFAULT_VIEW_SCRIPT_TAGS = ["wxs", "dds"];
15274
+ RESERVED_EXTS = /* @__PURE__ */ new Set([
15275
+ ...DEFAULT_TEMPLATE_EXTS,
15276
+ ...DEFAULT_STYLE_EXTS,
15277
+ ...DEFAULT_VIEW_SCRIPT_EXTS,
15278
+ ".js",
15279
+ ".ts",
15280
+ ".json"
15281
+ ]);
15282
+ compilerOptions = normalizeFileTypes();
15212
15283
  }
15213
15284
  });
15214
15285
 
@@ -18622,7 +18693,7 @@ function warnUnsupportedWxApi(apiName, filePath, line) {
18622
18693
  }
18623
18694
  function warnUnsupportedComponent(tagName, filePath, line) {
18624
18695
  const { supportedBuiltinComponents: supportedBuiltinComponents2 } = loadReference();
18625
- if (!tagName || supportedBuiltinComponents2.has(tagName)) {
18696
+ if (!tagName || supportedBuiltinComponents2.has(tagName) || getViewScriptTags().includes(tagName)) {
18626
18697
  return;
18627
18698
  }
18628
18699
  const location = formatLocation(filePath, line);
@@ -18683,6 +18754,7 @@ var cachedReference, warnedItems;
18683
18754
  var init_compatibility = __esm({
18684
18755
  "../../dimina/fe/packages/compiler/src/common/compatibility.js"() {
18685
18756
  init_dist3();
18757
+ init_env();
18686
18758
  init_compatibility_reference();
18687
18759
  cachedReference = null;
18688
18760
  warnedItems = /* @__PURE__ */ new Set();
@@ -45049,7 +45121,7 @@ function doCompileTemplate({
45049
45121
  ssrCssVars,
45050
45122
  isProd = false,
45051
45123
  compiler,
45052
- compilerOptions = {},
45124
+ compilerOptions: compilerOptions2 = {},
45053
45125
  transformAssetUrls
45054
45126
  }) {
45055
45127
  const errors2 = [];
@@ -45083,7 +45155,7 @@ function doCompileTemplate({
45083
45155
  if (inAST == null ? void 0 : inAST.transformed) {
45084
45156
  const newAST = (ssr ? CompilerDOM : compiler).parse(inAST.source, __spreadProps$5(__spreadValues$6({
45085
45157
  prefixIdentifiers: true
45086
- }, compilerOptions), {
45158
+ }, compilerOptions2), {
45087
45159
  parseMode: "sfc",
45088
45160
  onError: (e) => errors2.push(e)
45089
45161
  }));
@@ -45101,9 +45173,9 @@ function doCompileTemplate({
45101
45173
  scopeId: scoped ? longId : void 0,
45102
45174
  slotted,
45103
45175
  sourceMap: true
45104
- }, compilerOptions), {
45176
+ }, compilerOptions2), {
45105
45177
  hmr: !isProd,
45106
- nodeTransforms: nodeTransforms.concat(compilerOptions.nodeTransforms || []),
45178
+ nodeTransforms: nodeTransforms.concat(compilerOptions2.nodeTransforms || []),
45107
45179
  filename,
45108
45180
  onError: (e) => errors2.push(e),
45109
45181
  onWarn: (w) => warnings.push(w)
@@ -76875,6 +76947,8 @@ __export(view_compiler_exports, {
76875
76947
  compileML: () => compileML,
76876
76948
  generateSlotDirective: () => generateSlotDirective,
76877
76949
  generateVModelTemplate: () => generateVModelTemplate,
76950
+ initWxsFilePathMap: () => initWxsFilePathMap,
76951
+ loadWxsModule: () => loadWxsModule,
76878
76952
  parseBraceExp: () => parseBraceExp,
76879
76953
  parseClassRules: () => parseClassRules,
76880
76954
  parseKeyExpression: () => parseKeyExpression,
@@ -76883,6 +76957,13 @@ __export(view_compiler_exports, {
76883
76957
  processWxsContent: () => processWxsContent,
76884
76958
  splitWithBraces: () => splitWithBraces
76885
76959
  });
76960
+ function buildExtStripRegex(exts) {
76961
+ const alt = exts.map((e) => e.replace(/[.*+?^${}()|[\]\\]/g, "\\$&")).join("|");
76962
+ return new RegExp(`(${alt})$`);
76963
+ }
76964
+ function stripViewScriptExt(p) {
76965
+ return p.replace(buildExtStripRegex(getViewScriptExts()), "");
76966
+ }
76886
76967
  function parseJs(code, filename = "view-compiler.js", sourceType = "module") {
76887
76968
  return parseSync(filename, code, {
76888
76969
  sourceType,
@@ -77048,8 +77129,8 @@ function scanWxsFiles(dir, workPath) {
77048
77129
  const stat2 = fs_default.statSync(fullPath);
77049
77130
  if (stat2.isDirectory()) {
77050
77131
  scanWxsFiles(fullPath, workPath);
77051
- } else if (stat2.isFile() && item.endsWith(".wxs")) {
77052
- const relativePath = fullPath.replace(workPath, "").replace(/\.wxs$/, "");
77132
+ } else if (stat2.isFile() && getViewScriptExts().some((ext) => item.endsWith(ext))) {
77133
+ const relativePath = stripViewScriptExt(fullPath.replace(workPath, ""));
77053
77134
  const moduleName = relativePath.replace(/[\/\\@\-]/g, "_").replace(/^_/, "");
77054
77135
  wxsFilePathMap.set(moduleName, fullPath);
77055
77136
  }
@@ -77279,7 +77360,7 @@ function processWxsContent(wxsContent, wxsFilePath, scriptModule, workPath, file
77279
77360
  if (filePath && filePath.includes("/miniprogram_npm/")) {
77280
77361
  const currentWxsDir = import_node_path8.default.dirname(wxsFilePath);
77281
77362
  resolvedWxsPath = import_node_path8.default.resolve(currentWxsDir, requirePath);
77282
- const relativePath = resolvedWxsPath.replace(workPath, "").replace(/\.wxs$/, "");
77363
+ const relativePath = stripViewScriptExt(resolvedWxsPath.replace(workPath, ""));
77283
77364
  const moduleName = relativePath.replace(/[\/\\@\-]/g, "_").replace(/^_/, "");
77284
77365
  processWxsDependency(resolvedWxsPath, moduleName, scriptModule, workPath, filePath);
77285
77366
  replacements.push({
@@ -77290,7 +77371,7 @@ function processWxsContent(wxsContent, wxsFilePath, scriptModule, workPath, file
77290
77371
  } else {
77291
77372
  const currentWxsDir = import_node_path8.default.dirname(wxsFilePath);
77292
77373
  resolvedWxsPath = import_node_path8.default.resolve(currentWxsDir, requirePath);
77293
- const relativePath = resolvedWxsPath.replace(workPath, "").replace(/\.wxs$/, "");
77374
+ const relativePath = stripViewScriptExt(resolvedWxsPath.replace(workPath, ""));
77294
77375
  const depModuleName = relativePath.replace(/[\/\\@\-]/g, "_").replace(/^_/, "");
77295
77376
  processWxsDependency(resolvedWxsPath, depModuleName, scriptModule, workPath, filePath);
77296
77377
  replacements.push({
@@ -77506,7 +77587,7 @@ function toCompileTemplate(isComponent2, path10, components, componentPlaceholde
77506
77587
  const src = $2(elem).attr("src");
77507
77588
  if (src) {
77508
77589
  const includeFullPath = getAbsolutePath(workPath, path10, src);
77509
- let includePath = includeFullPath.replace(workPath, "").replace(/\.(wxml|ddml)$/, "");
77590
+ let includePath = includeFullPath.replace(workPath, "").replace(buildExtStripRegex(getTemplateExts()), "");
77510
77591
  const includeDiagnosticSource = includeFullPath.startsWith(workPath) ? includeFullPath.slice(workPath.length) : includePath;
77511
77592
  if (!includePath.startsWith("/")) {
77512
77593
  includePath = "/" + includePath;
@@ -77532,8 +77613,7 @@ function toCompileTemplate(isComponent2, path10, components, componentPlaceholde
77532
77613
  );
77533
77614
  processIncludedFileWxsDependencies(includeContent, includePath, scriptModule, components, processedPaths);
77534
77615
  $includeContent("template").remove();
77535
- $includeContent("wxs").remove();
77536
- $includeContent("dds").remove();
77616
+ $includeContent(getViewScriptTags().join(",")).remove();
77537
77617
  const processedContent = processIncludeConditionalAttrs($2, elem, $includeContent.html());
77538
77618
  $2(elem).replaceWith(processedContent);
77539
77619
  } else {
@@ -77550,7 +77630,7 @@ function toCompileTemplate(isComponent2, path10, components, componentPlaceholde
77550
77630
  const src = $2(elem).attr("src");
77551
77631
  if (src) {
77552
77632
  const importFullPath = getAbsolutePath(workPath, path10, src);
77553
- let importPath = importFullPath.replace(workPath, "").replace(/\.(wxml|ddml)$/, "");
77633
+ let importPath = importFullPath.replace(workPath, "").replace(buildExtStripRegex(getTemplateExts()), "");
77554
77634
  const importDiagnosticSource = importFullPath.startsWith(workPath) ? importFullPath.slice(workPath.length) : importPath;
77555
77635
  if (!importPath.startsWith("/")) {
77556
77636
  importPath = "/" + importPath;
@@ -77597,8 +77677,7 @@ function transTagTemplate($2, templateModule, path10, components, componentPlace
77597
77677
  const templateContent = $2(elem);
77598
77678
  templateContent.find("import").remove();
77599
77679
  templateContent.find("include").remove();
77600
- templateContent.find("wxs").remove();
77601
- templateContent.find("dds").remove();
77680
+ templateContent.find(getViewScriptTags().join(",")).remove();
77602
77681
  transAsses($2, templateContent.find("image"), path10);
77603
77682
  const res = [];
77604
77683
  transHtmlTag(templateContent.html(), res, components, componentPlaceholder);
@@ -77905,7 +77984,7 @@ function parseKeyExpression(exp, itemName = "item", indexName = "index") {
77905
77984
  }
77906
77985
  function getViewPath(workPath, src) {
77907
77986
  const aSrc = src.startsWith("/") ? src : `/${src}`;
77908
- for (const mlType of fileType) {
77987
+ for (const mlType of getTemplateExts()) {
77909
77988
  const mlFullPath = `${workPath}${aSrc}${mlType}`;
77910
77989
  if (fs_default.existsSync(mlFullPath)) {
77911
77990
  return mlFullPath;
@@ -78011,10 +78090,7 @@ function parseTemplateDataExp(exp) {
78011
78090
  return `{${parseBraceExp(exp)}}`;
78012
78091
  }
78013
78092
  function transTagWxs($2, scriptModule, filePath) {
78014
- let wxsNodes = $2("wxs");
78015
- if (wxsNodes.length === 0) {
78016
- wxsNodes = $2("dds");
78017
- }
78093
+ const wxsNodes = $2(getViewScriptTags().join(","));
78018
78094
  wxsNodes.each((_, elem) => {
78019
78095
  const smName = $2(elem).attr("module");
78020
78096
  if (smName) {
@@ -78033,7 +78109,7 @@ function transTagWxs($2, scriptModule, filePath) {
78033
78109
  wxsFilePath = getAbsolutePath(workPath, filePath, src);
78034
78110
  }
78035
78111
  if (wxsFilePath) {
78036
- const relativePath = wxsFilePath.replace(workPath, "").replace(/\.wxs$/, "");
78112
+ const relativePath = stripViewScriptExt(wxsFilePath.replace(workPath, ""));
78037
78113
  uniqueModuleName = relativePath.replace(/[\/\\@\-]/g, "_").replace(/^_/, "");
78038
78114
  cacheKey = wxsFilePath;
78039
78115
  }
@@ -78106,12 +78182,8 @@ function collectAllWxsModules(scriptRes, collectedPaths = /* @__PURE__ */ new Se
78106
78182
  return allWxsModules;
78107
78183
  }
78108
78184
  function loadWxsModule(modulePath, workPath, scriptModule) {
78109
- if (!modulePath.startsWith("miniprogram_npm__") || !modulePath.includes("_wxs_")) {
78110
- return null;
78111
- }
78112
78185
  const wxsFilePath = wxsFilePathMap.get(modulePath);
78113
78186
  if (!wxsFilePath) {
78114
- console.warn(`[view] \u65E0\u6CD5\u627E\u5230 wxs \u6A21\u5757\u6587\u4EF6: ${modulePath}`);
78115
78187
  return null;
78116
78188
  }
78117
78189
  try {
@@ -78198,7 +78270,7 @@ function __resetViewState() {
78198
78270
  wxsModuleRegistry.clear();
78199
78271
  wxsFilePathMap.clear();
78200
78272
  }
78201
- var import_node_path8, fileType, compileResCache, wxsModuleRegistry, wxsFilePathMap, braceRegex, noBraceRegex, ternaryRegex;
78273
+ var import_node_path8, compileResCache, wxsModuleRegistry, wxsFilePathMap, braceRegex, noBraceRegex, ternaryRegex;
78202
78274
  var init_view_compiler = __esm({
78203
78275
  "../../dimina/fe/packages/compiler/src/core/view-compiler.js"() {
78204
78276
  init_fs();
@@ -78215,7 +78287,6 @@ var init_view_compiler = __esm({
78215
78287
  init_utils();
78216
78288
  init_env();
78217
78289
  init_expression_parser();
78218
- fileType = [".wxml", ".ddml"];
78219
78290
  compileResCache = /* @__PURE__ */ new Map();
78220
78291
  wxsModuleRegistry = /* @__PURE__ */ new Set();
78221
78292
  wxsFilePathMap = /* @__PURE__ */ new Map();
@@ -291005,7 +291076,7 @@ function normalizeCssUrlValue(value, absolutePath) {
291005
291076
  function getAbsolutePath2(modulePath) {
291006
291077
  const workPath = getWorkPath();
291007
291078
  const src = modulePath.startsWith("/") ? modulePath : `/${modulePath}`;
291008
- for (const ssType of fileType2) {
291079
+ for (const ssType of getStyleExts()) {
291009
291080
  const ssFullPath = `${workPath}${src}${ssType}`;
291010
291081
  if (fs_default.existsSync(ssFullPath)) {
291011
291082
  return ssFullPath;
@@ -291058,7 +291129,7 @@ function processHostSelector(selector2, moduleId) {
291058
291129
  function __resetStyleState() {
291059
291130
  compileRes.clear();
291060
291131
  }
291061
- var import_node_path9, import_autoprefixer, import_cssnano, import_postcss_selector_parser, fileType2, compileRes;
291132
+ var import_node_path9, import_autoprefixer, import_cssnano, import_postcss_selector_parser, compileRes;
291062
291133
  var init_style_compiler = __esm({
291063
291134
  "../../dimina/fe/packages/compiler/src/core/style-compiler.js"() {
291064
291135
  init_fs();
@@ -291073,7 +291144,6 @@ var init_style_compiler = __esm({
291073
291144
  init_sass_default();
291074
291145
  init_utils();
291075
291146
  init_env();
291076
- fileType2 = [".wxss", ".ddss", ".less", ".scss", ".sass"];
291077
291147
  compileRes = /* @__PURE__ */ new Map();
291078
291148
  if (!isMainThread) {
291079
291149
  parentPort.on("message", async ({ pages, storeInfo: storeInfo2 }) => {
@@ -291172,6 +291242,7 @@ var config_compiler_default = compileConfig;
291172
291242
  // ../../dimina/fe/packages/compiler/src/common/npm-builder.js
291173
291243
  init_fs();
291174
291244
  var import_node_path6 = __toESM(require_path_browserify(), 1);
291245
+ init_env();
291175
291246
  var NpmBuilder = class {
291176
291247
  constructor(workPath, targetPath) {
291177
291248
  this.workPath = workPath;
@@ -291279,7 +291350,7 @@ var NpmBuilder = class {
291279
291350
  * @returns {boolean} 是否为小程序文件
291280
291351
  */
291281
291352
  isMiniprogramFile(filename) {
291282
- const miniprogramExts = [".js", ".json", ".wxml", ".wxss", ".wxs", ".ts", ".less", ".scss", ".styl"];
291353
+ const miniprogramExts = [".js", ".json", ".ts", ...getTemplateExts(), ...getStyleExts(), ...getViewScriptExts()];
291283
291354
  const ext = import_node_path6.default.extname(filename).toLowerCase();
291284
291355
  return miniprogramExts.includes(ext) || filename === "package.json" || filename === "README.md" || filename.startsWith(".");
291285
291356
  }
@@ -3,12 +3,12 @@ import {
3
3
  preloadStage,
4
4
  resetCompilerState,
5
5
  runStage
6
- } from "./pool.node-chunks/chunk-MHOA4NGC.js";
6
+ } from "./pool.node-chunks/chunk-PDHO4Y56.js";
7
7
  import {
8
8
  getAppId,
9
9
  getAppName,
10
10
  resetStoreInfo
11
- } from "./pool.node-chunks/chunk-UYQ7D5I5.js";
11
+ } from "./pool.node-chunks/chunk-7FGOYOXU.js";
12
12
 
13
13
  // src/stage-worker-node.js
14
14
  import { createRequire } from "node:module";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dimina-kit/compiler",
3
- "version": "0.0.1-dev.20260706125036",
3
+ "version": "0.0.1-dev.20260706131625",
4
4
  "description": "dmcc compiler bundles (browser + node) that drive @dimina/compiler against a caller-injected node:fs replacement (no bundled fs)",
5
5
  "license": "MIT",
6
6
  "type": "module",