weapp-vite 2.0.1 → 2.1.0

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,9 +1,10 @@
1
1
  import { R as ResolvedValue } from './types-dS68tjL6.js';
2
- import { E as Entry, S as SubPackageMetaValue, R as ResolvedAlias, P as ProjectConfig, M as MpPlatform, a as SubPackage, A as AppEntry, b as ScanWxmlOptions } from './config-BM_dhf8V.js';
2
+ import { E as Entry, S as SubPackageMetaValue, R as ResolvedAlias, P as ProjectConfig, M as MpPlatform, W as WeappViteConfig, a as SubPackage, A as AppEntry, b as ScanWxmlOptions } from './config-EPV0G671.js';
3
3
  import { PackageJson } from 'pkg-types';
4
4
  import { InlineConfig } from 'vite';
5
5
  import { RollupWatcher, RollupOutput } from 'rollup';
6
6
  import { Options } from 'tsup';
7
+ import * as ts_morph from 'ts-morph';
7
8
  import { Buffer } from 'node:buffer';
8
9
 
9
10
  interface WxmlDep {
@@ -102,6 +103,7 @@ declare class ConfigService {
102
103
  get mpDistRoot(): string;
103
104
  get outDir(): string;
104
105
  get inlineConfig(): InlineConfig;
106
+ get weappViteConfig(): WeappViteConfig | undefined;
105
107
  get packageJson(): PackageJson;
106
108
  get projectConfig(): ProjectConfig;
107
109
  get srcRoot(): string;
@@ -117,6 +119,7 @@ declare class JsonService {
117
119
  private readonly configService;
118
120
  constructor(configService: ConfigService);
119
121
  read(filepath: string): Promise<any>;
122
+ resolve(entry: Partial<Pick<Entry, 'json' | 'jsonPath' | 'type'>>): string | undefined;
120
123
  }
121
124
 
122
125
  declare class NpmService {
@@ -140,9 +143,11 @@ declare class ScanService {
140
143
  entries: Entry[];
141
144
  appEntry?: AppEntry;
142
145
  pagesSet: Set<string>;
146
+ componentEntrySet: Set<string>;
143
147
  constructor(configService: ConfigService, jsonService: JsonService, subPackageService: SubPackageService, autoImportService: AutoImportService, wxmlService: WxmlService);
144
148
  initPagesSet(): Set<string>;
145
149
  /**
150
+ * 扫描 usingComponents 字段进行解析
146
151
  * @deps [this.scanComponentEntry]
147
152
  * @param entry
148
153
  * @param relDir
@@ -150,7 +155,8 @@ declare class ScanService {
150
155
  private usingComponentsHandler;
151
156
  resetEntries(): void;
152
157
  resetAutoImport(): void;
153
- scanAppEntry(): Promise<AppEntry | undefined>;
158
+ loadAppEntry(): Promise<AppEntry | undefined>;
159
+ scanAppEntry(): Promise<void>;
154
160
  /**
155
161
  * 扫描并处理组件入口文件。
156
162
  * @param componentEntry 组件入口文件名
@@ -162,6 +168,13 @@ declare class ScanService {
162
168
  * 同时处理引入组件的情况,自动注入 usingComponents。
163
169
  */
164
170
  scanComponentEntry(componentEntry: string, dirname: string, subPackageMeta?: SubPackageMetaValue): Promise<void>;
171
+ get workersOptions(): string | {
172
+ [k: string]: unknown;
173
+ path?: string;
174
+ isSubpackage?: boolean;
175
+ } | undefined;
176
+ get workersDir(): string | undefined;
177
+ workersBuild(files: string[]): ts_morph.MemoryEmitResultFile[] | undefined;
165
178
  }
166
179
 
167
180
  declare class SubPackageService {
@@ -1,9 +1,10 @@
1
1
  import { R as ResolvedValue } from './types-dS68tjL6.cjs';
2
- import { E as Entry, S as SubPackageMetaValue, R as ResolvedAlias, P as ProjectConfig, M as MpPlatform, a as SubPackage, A as AppEntry, b as ScanWxmlOptions } from './config-DYSwq1ku.cjs';
2
+ import { E as Entry, S as SubPackageMetaValue, R as ResolvedAlias, P as ProjectConfig, M as MpPlatform, W as WeappViteConfig, a as SubPackage, A as AppEntry, b as ScanWxmlOptions } from './config-Cvwqemwg.cjs';
3
3
  import { PackageJson } from 'pkg-types';
4
4
  import { InlineConfig } from 'vite';
5
5
  import { RollupWatcher, RollupOutput } from 'rollup';
6
6
  import { Options } from 'tsup';
7
+ import * as ts_morph from 'ts-morph';
7
8
  import { Buffer } from 'node:buffer';
8
9
 
9
10
  interface WxmlDep {
@@ -102,6 +103,7 @@ declare class ConfigService {
102
103
  get mpDistRoot(): string;
103
104
  get outDir(): string;
104
105
  get inlineConfig(): InlineConfig;
106
+ get weappViteConfig(): WeappViteConfig | undefined;
105
107
  get packageJson(): PackageJson;
106
108
  get projectConfig(): ProjectConfig;
107
109
  get srcRoot(): string;
@@ -117,6 +119,7 @@ declare class JsonService {
117
119
  private readonly configService;
118
120
  constructor(configService: ConfigService);
119
121
  read(filepath: string): Promise<any>;
122
+ resolve(entry: Partial<Pick<Entry, 'json' | 'jsonPath' | 'type'>>): string | undefined;
120
123
  }
121
124
 
122
125
  declare class NpmService {
@@ -140,9 +143,11 @@ declare class ScanService {
140
143
  entries: Entry[];
141
144
  appEntry?: AppEntry;
142
145
  pagesSet: Set<string>;
146
+ componentEntrySet: Set<string>;
143
147
  constructor(configService: ConfigService, jsonService: JsonService, subPackageService: SubPackageService, autoImportService: AutoImportService, wxmlService: WxmlService);
144
148
  initPagesSet(): Set<string>;
145
149
  /**
150
+ * 扫描 usingComponents 字段进行解析
146
151
  * @deps [this.scanComponentEntry]
147
152
  * @param entry
148
153
  * @param relDir
@@ -150,7 +155,8 @@ declare class ScanService {
150
155
  private usingComponentsHandler;
151
156
  resetEntries(): void;
152
157
  resetAutoImport(): void;
153
- scanAppEntry(): Promise<AppEntry | undefined>;
158
+ loadAppEntry(): Promise<AppEntry | undefined>;
159
+ scanAppEntry(): Promise<void>;
154
160
  /**
155
161
  * 扫描并处理组件入口文件。
156
162
  * @param componentEntry 组件入口文件名
@@ -162,6 +168,13 @@ declare class ScanService {
162
168
  * 同时处理引入组件的情况,自动注入 usingComponents。
163
169
  */
164
170
  scanComponentEntry(componentEntry: string, dirname: string, subPackageMeta?: SubPackageMetaValue): Promise<void>;
171
+ get workersOptions(): string | {
172
+ [k: string]: unknown;
173
+ path?: string;
174
+ isSubpackage?: boolean;
175
+ } | undefined;
176
+ get workersDir(): string | undefined;
177
+ workersBuild(files: string[]): ts_morph.MemoryEmitResultFile[] | undefined;
165
178
  }
166
179
 
167
180
  declare class SubPackageService {
@@ -1,7 +1,7 @@
1
1
  import {
2
2
  __name,
3
3
  init_esm_shims
4
- } from "../chunk-OCZOGFU3.mjs";
4
+ } from "../chunk-PEN3BLSY.mjs";
5
5
 
6
6
  // src/auto-import-components/resolvers/index.ts
7
7
  init_esm_shims();
@@ -3,7 +3,7 @@ import {
3
3
  __name,
4
4
  __toESM,
5
5
  init_esm_shims
6
- } from "./chunk-OCZOGFU3.mjs";
6
+ } from "./chunk-PEN3BLSY.mjs";
7
7
 
8
8
  // ../../node_modules/.pnpm/reflect-metadata@0.2.2/node_modules/reflect-metadata/Reflect.js
9
9
  var require_Reflect = __commonJS({
@@ -3582,8 +3582,8 @@ var AutoImportService2 = class {
3582
3582
  }
3583
3583
  }
3584
3584
  filter(id, _meta) {
3585
- if (this.configService.inlineConfig.weapp?.enhance?.autoImportComponents?.globs) {
3586
- const isMatch = pm(this.configService.inlineConfig.weapp.enhance.autoImportComponents.globs, {
3585
+ if (this.configService.weappViteConfig?.enhance?.autoImportComponents?.globs) {
3586
+ const isMatch = pm(this.configService.weappViteConfig.enhance.autoImportComponents.globs, {
3587
3587
  cwd: this.configService.cwd,
3588
3588
  windows: true,
3589
3589
  posixSlashes: true
@@ -13987,7 +13987,7 @@ function scanWxml(wxml, options) {
13987
13987
  });
13988
13988
  const ms = wxml.toString();
13989
13989
  const deps = [];
13990
- let currentTagName = "";
13990
+ let currentTagName;
13991
13991
  let importAttrs;
13992
13992
  let attrs = {};
13993
13993
  const components2 = {};
@@ -13999,15 +13999,17 @@ function scanWxml(wxml, options) {
13999
13999
  const wxsImportNormalizeTokens = [];
14000
14000
  const removeWxsLangAttrTokens = [];
14001
14001
  const eventTokens = [];
14002
+ const tagStack = [];
14002
14003
  const parser = new Parser({
14003
14004
  onopentagname(name) {
14005
+ tagStack.push(name);
14004
14006
  currentTagName = name;
14005
14007
  importAttrs = srcImportTagsMap[currentTagName];
14006
14008
  tagStartIndex = parser.startIndex;
14007
14009
  },
14008
14010
  onattribute(name, value, quote) {
14009
14011
  attrs[name] = value;
14010
- if (importAttrs) {
14012
+ if (importAttrs && currentTagName) {
14011
14013
  for (const attrName of importAttrs) {
14012
14014
  if (attrName === name) {
14013
14015
  deps.push({
@@ -14074,6 +14076,7 @@ function scanWxml(wxml, options) {
14074
14076
  }
14075
14077
  },
14076
14078
  onclosetag() {
14079
+ currentTagName = tagStack.pop();
14077
14080
  if (currentTagName && !opts.excludeComponent(currentTagName)) {
14078
14081
  if (Array.isArray(components2[currentTagName])) {
14079
14082
  components2[currentTagName].push({
@@ -14184,7 +14187,7 @@ var debouncedLoggerSuccess = (0, import_debounce.default)((message) => {
14184
14187
  return logger_default.success(message);
14185
14188
  }, 25);
14186
14189
  function vitePluginWeapp(ctx, subPackageMeta) {
14187
- const { configService, subPackageService, autoImportService, scanService, wxmlService } = ctx;
14190
+ const { configService, subPackageService, autoImportService, scanService, wxmlService, jsonService } = ctx;
14188
14191
  let configResolved;
14189
14192
  function getInputOption(entries2) {
14190
14193
  return entries2.reduce((acc, cur) => {
@@ -14197,6 +14200,7 @@ function vitePluginWeapp(ctx, subPackageMeta) {
14197
14200
  let entries;
14198
14201
  const cachedEmittedFiles = [];
14199
14202
  const cachedWatchFiles = [];
14203
+ const cachedWorkerFiles = [];
14200
14204
  async function handleWxsDeps(deps, absPath) {
14201
14205
  for (const wxsDep of deps.filter((x4) => x4.tagName === "wxs")) {
14202
14206
  if (jsExtensions.includes(wxsDep.attrs.lang) || /\.wxs\.[jt]s$/.test(wxsDep.value)) {
@@ -14259,8 +14263,12 @@ function vitePluginWeapp(ctx, subPackageMeta) {
14259
14263
  }
14260
14264
  },
14261
14265
  async options(options) {
14266
+ if (!subPackageMeta) {
14267
+ await scanService.loadAppEntry();
14268
+ }
14262
14269
  cachedEmittedFiles.length = 0;
14263
14270
  cachedWatchFiles.length = 0;
14271
+ cachedWorkerFiles.length = 0;
14264
14272
  scanService.resetAutoImport();
14265
14273
  const { build: build4, weapp } = configResolved;
14266
14274
  const ignore = [
@@ -14278,6 +14286,9 @@ function vitePluginWeapp(ctx, subPackageMeta) {
14278
14286
  "**/*.{wxml,html,wxs}",
14279
14287
  "**/*.{png,jpg,jpeg,gif,svg,webp}"
14280
14288
  ];
14289
+ if (scanService.workersDir) {
14290
+ assetGlobs.push(path6.join(scanService.workersDir, "**/*.{js,ts}"));
14291
+ }
14281
14292
  assetGlobs.push(...resolveGlobs(weapp?.copy?.include));
14282
14293
  const patterns = assetGlobs.map((x4) => {
14283
14294
  return path6.join(targetDir, x4);
@@ -14295,6 +14306,7 @@ function vitePluginWeapp(ctx, subPackageMeta) {
14295
14306
  const absPath = path6.resolve(configService.cwd, relPath);
14296
14307
  cachedWatchFiles.push(absPath);
14297
14308
  const isWxs = relPath.endsWith(".wxs");
14309
+ const isWorker = isJsOrTs(relPath) && scanService.workersDir && relPath.startsWith(scanService.workersDir);
14298
14310
  const fileName = configService.relativeSrcRoot(relPath);
14299
14311
  if (isTemplateRequest(relPath)) {
14300
14312
  if (weapp?.enhance?.autoImportComponents && autoImportService.filter(relPath, subPackageMeta)) {
@@ -14311,6 +14323,12 @@ function vitePluginWeapp(ctx, subPackageMeta) {
14311
14323
  absPath,
14312
14324
  fileName
14313
14325
  });
14326
+ } else if (isWorker) {
14327
+ cachedWorkerFiles.push({
14328
+ relPath,
14329
+ absPath,
14330
+ fileName
14331
+ });
14314
14332
  } else {
14315
14333
  mediaFiles.push({
14316
14334
  relPath,
@@ -14349,7 +14367,7 @@ function vitePluginWeapp(ctx, subPackageMeta) {
14349
14367
  return !wxmlService.tokenMap.has(x4.absPath);
14350
14368
  });
14351
14369
  const additionalWxmlFiles = excludedWxmlFiles.filter((x4) => {
14352
- return configService.inlineConfig.weapp?.isAdditionalWxml?.(x4.absPath);
14370
+ return configService.weappViteConfig?.isAdditionalWxml?.(x4.absPath);
14353
14371
  });
14354
14372
  debug2?.(`additionalWxmlFiles:`, additionalWxmlFiles);
14355
14373
  await Promise.all([
@@ -14411,7 +14429,7 @@ function vitePluginWeapp(ctx, subPackageMeta) {
14411
14429
  this.emitFile({
14412
14430
  type: "asset",
14413
14431
  fileName,
14414
- source: resolveJson(entry, configService.aliasEntries)
14432
+ source: jsonService.resolve(entry)
14415
14433
  });
14416
14434
  }
14417
14435
  }
@@ -14425,10 +14443,10 @@ function vitePluginWeapp(ctx, subPackageMeta) {
14425
14443
  this.emitFile({
14426
14444
  type: "asset",
14427
14445
  fileName,
14428
- source: resolveJson({
14446
+ source: jsonService.resolve({
14429
14447
  json: appEntry.sitemapJson,
14430
14448
  jsonPath: appEntry.sitemapJsonPath
14431
- }, configService.aliasEntries)
14449
+ })
14432
14450
  });
14433
14451
  }
14434
14452
  }
@@ -14439,16 +14457,30 @@ function vitePluginWeapp(ctx, subPackageMeta) {
14439
14457
  this.emitFile({
14440
14458
  type: "asset",
14441
14459
  fileName,
14442
- source: resolveJson({
14460
+ source: jsonService.resolve({
14443
14461
  json: appEntry.themeJson,
14444
14462
  jsonPath: appEntry.themeJsonPath
14445
- }, configService.aliasEntries)
14463
+ })
14446
14464
  });
14447
14465
  }
14448
14466
  }
14449
14467
  }
14450
14468
  }
14451
14469
  }
14470
+ if (scanService.workersDir && cachedWorkerFiles.length) {
14471
+ const workerFiles = scanService.workersBuild(cachedWorkerFiles.map((x4) => x4.absPath));
14472
+ if (workerFiles) {
14473
+ for (let i2 = 0; i2 < workerFiles.length; i2++) {
14474
+ const workerFile = workerFiles[i2];
14475
+ const fileName = configService.relativeSrcRoot(configService.relativeCwd(cachedWorkerFiles[i2].absPath));
14476
+ this.emitFile({
14477
+ type: "prebuilt-chunk",
14478
+ fileName,
14479
+ code: workerFile.text
14480
+ });
14481
+ }
14482
+ }
14483
+ }
14452
14484
  debug2?.("buildEnd end");
14453
14485
  },
14454
14486
  resolveId(source) {
@@ -14611,6 +14643,8 @@ async function loadConfig(opts) {
14611
14643
  assetsDir: ".",
14612
14644
  commonjsOptions: {
14613
14645
  transformMixedEsModules: true,
14646
+ // include:[/(?:)/]
14647
+ // const regex = /(?:)/; // 单次匹配
14614
14648
  include: void 0
14615
14649
  }
14616
14650
  },
@@ -14701,6 +14735,9 @@ var ConfigService2 = class {
14701
14735
  get inlineConfig() {
14702
14736
  return this.options.config;
14703
14737
  }
14738
+ get weappViteConfig() {
14739
+ return this.inlineConfig.weapp;
14740
+ }
14704
14741
  get packageJson() {
14705
14742
  return this.options.packageJson;
14706
14743
  }
@@ -15256,6 +15293,9 @@ var JsonService2 = class {
15256
15293
  logger_default.error(error);
15257
15294
  }
15258
15295
  }
15296
+ resolve(entry) {
15297
+ return resolveJson(entry, this.configService.aliasEntries);
15298
+ }
15259
15299
  };
15260
15300
  JsonService2 = _ts_decorate5([
15261
15301
  Kt(),
@@ -15271,9 +15311,9 @@ init_esm_shims();
15271
15311
  import { defu as defu5, isObject as isObject4, objectHash } from "@weapp-core/shared";
15272
15312
  import fs10 from "fs-extra";
15273
15313
 
15274
- // ../../node_modules/.pnpm/local-pkg@0.5.1/node_modules/local-pkg/dist/index.mjs
15314
+ // ../../node_modules/.pnpm/local-pkg@1.0.0/node_modules/local-pkg/dist/index.mjs
15275
15315
  init_esm_shims();
15276
- import fs9, { promises as promises2 } from "node:fs";
15316
+ import fs9 from "node:fs";
15277
15317
  import { createRequire as createRequire4 } from "node:module";
15278
15318
  import path11, { dirname as dirname2, win32, join } from "node:path";
15279
15319
  import process4 from "node:process";
@@ -22299,8 +22339,7 @@ function resolvePathSync(id, options) {
22299
22339
  }
22300
22340
  __name(resolvePathSync, "resolvePathSync");
22301
22341
 
22302
- // ../../node_modules/.pnpm/local-pkg@0.5.1/node_modules/local-pkg/dist/index.mjs
22303
- var findUpStop = Symbol("findUpStop");
22342
+ // ../../node_modules/.pnpm/local-pkg@1.0.0/node_modules/local-pkg/dist/index.mjs
22304
22343
  function _resolve2(path15, options = {}) {
22305
22344
  if (options.platform === "auto" || !options.platform)
22306
22345
  options.platform = process4.platform === "win32" ? "win32" : "posix";
@@ -22508,7 +22547,7 @@ var NpmService2 = class {
22508
22547
  NODE_ENV: "production"
22509
22548
  }
22510
22549
  });
22511
- const resolvedOptions = this.configService.inlineConfig.weapp?.npm?.tsup?.(mergedOptions, {
22550
+ const resolvedOptions = this.configService.weappViteConfig?.npm?.tsup?.(mergedOptions, {
22512
22551
  entry: index,
22513
22552
  name: dep
22514
22553
  });
@@ -22544,6 +22583,7 @@ init_esm_shims();
22544
22583
  import { get as get2, isObject as isObject5, removeExtension as removeExtension4, set as set2 } from "@weapp-core/shared";
22545
22584
  import fs11 from "fs-extra";
22546
22585
  import path13 from "pathe";
22586
+ import { ModuleKind, Project, ScriptTarget } from "ts-morph";
22547
22587
  function _ts_decorate7(decorators, target, key, desc) {
22548
22588
  var c3 = arguments.length, r5 = c3 < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d3;
22549
22589
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r5 = Reflect.decorate(decorators, target, key, desc);
@@ -22574,6 +22614,8 @@ var ScanService2 = class {
22574
22614
  entries;
22575
22615
  appEntry;
22576
22616
  pagesSet;
22617
+ // 处理循环依赖
22618
+ componentEntrySet;
22577
22619
  constructor(configService, jsonService, subPackageService, autoImportService, wxmlService) {
22578
22620
  this.configService = configService;
22579
22621
  this.jsonService = jsonService;
@@ -22582,6 +22624,7 @@ var ScanService2 = class {
22582
22624
  this.wxmlService = wxmlService;
22583
22625
  this.entries = [];
22584
22626
  this.entriesSet = /* @__PURE__ */ new Set();
22627
+ this.componentEntrySet = /* @__PURE__ */ new Set();
22585
22628
  }
22586
22629
  // https://github.com/vitejs/vite/blob/192d555f88bba7576e8a40cc027e8a11e006079c/packages/vite/src/node/plugins/define.ts#L41
22587
22630
  initPagesSet() {
@@ -22603,6 +22646,7 @@ var ScanService2 = class {
22603
22646
  return set3;
22604
22647
  }
22605
22648
  /**
22649
+ * 扫描 usingComponents 字段进行解析
22606
22650
  * @deps [this.scanComponentEntry]
22607
22651
  * @param entry
22608
22652
  * @param relDir
@@ -22628,6 +22672,7 @@ var ScanService2 = class {
22628
22672
  }
22629
22673
  resetEntries() {
22630
22674
  this.entriesSet.clear();
22675
+ this.componentEntrySet.clear();
22631
22676
  this.wxmlService.clear();
22632
22677
  this.entries.length = 0;
22633
22678
  this.subPackageService.metaMap = {};
@@ -22636,9 +22681,7 @@ var ScanService2 = class {
22636
22681
  this.autoImportService.potentialComponentMap.clear();
22637
22682
  this.wxmlService.wxmlComponentsMap.clear();
22638
22683
  }
22639
- async scanAppEntry() {
22640
- debug?.("scanAppEntry start");
22641
- this.resetEntries();
22684
+ async loadAppEntry() {
22642
22685
  const appDirname = path13.resolve(this.configService.cwd, this.configService.srcRoot);
22643
22686
  const appBasename = path13.resolve(appDirname, "app");
22644
22687
  const appConfigFile = await findJsonEntry(appBasename);
@@ -22646,20 +22689,14 @@ var ScanService2 = class {
22646
22689
  if (appEntryPath && appConfigFile) {
22647
22690
  const config = await this.jsonService.read(appConfigFile);
22648
22691
  if (isObject5(config)) {
22649
- if (this.entriesSet.has(appEntryPath)) {
22650
- return;
22651
- }
22652
- this.entriesSet.add(appEntryPath);
22653
22692
  const appEntry = {
22654
22693
  path: appEntryPath,
22655
22694
  json: config,
22656
22695
  jsonPath: appConfigFile,
22657
22696
  type: "app"
22658
22697
  };
22659
- this.entries.push(appEntry);
22660
22698
  this.appEntry = appEntry;
22661
- this.pagesSet = this.initPagesSet();
22662
- const { pages, subpackages = [], subPackages = [], sitemapLocation = "sitemap.json", themeLocation = "theme.json" } = config;
22699
+ const { sitemapLocation = "sitemap.json", themeLocation = "theme.json" } = config;
22663
22700
  if (sitemapLocation) {
22664
22701
  const sitemapJsonPath = await findJsonEntry(path13.resolve(appDirname, sitemapLocation));
22665
22702
  if (sitemapJsonPath) {
@@ -22674,58 +22711,75 @@ var ScanService2 = class {
22674
22711
  appEntry.themeJson = await this.jsonService.read(themeJsonPath);
22675
22712
  }
22676
22713
  }
22677
- const subs = [
22678
- ...subpackages,
22679
- ...subPackages
22680
- ];
22681
- await this.usingComponentsHandler(appEntry, appDirname);
22682
- if (Array.isArray(pages)) {
22683
- for (const page of pages) {
22684
- await this.scanComponentEntry(page, appDirname);
22685
- }
22714
+ return appEntry;
22715
+ }
22716
+ } else {
22717
+ throw new Error(`\u5728 ${appDirname} \u76EE\u5F55\u4E0B\u6CA1\u6709\u627E\u5230 \`app.json\`, \u8BF7\u786E\u4FDD\u4F60\u521D\u59CB\u5316\u4E86\u5C0F\u7A0B\u5E8F\u9879\u76EE\uFF0C\u6216\u8005\u5728 \`vite.config.ts\` \u4E2D\u8BBE\u7F6E\u7684\u6B63\u786E\u7684 \`weapp.srcRoot\` \u914D\u7F6E\u8DEF\u5F84 `);
22718
+ }
22719
+ }
22720
+ async scanAppEntry() {
22721
+ debug?.("scanAppEntry start");
22722
+ this.resetEntries();
22723
+ const appDirname = path13.resolve(this.configService.cwd, this.configService.srcRoot);
22724
+ if (this.appEntry) {
22725
+ const { path: appEntryPath, json: config } = this.appEntry;
22726
+ if (this.entriesSet.has(appEntryPath)) {
22727
+ return;
22728
+ }
22729
+ this.entriesSet.add(appEntryPath);
22730
+ this.entries.push(this.appEntry);
22731
+ this.pagesSet = this.initPagesSet();
22732
+ const { pages, subpackages = [], subPackages = [] } = config;
22733
+ const subs = [
22734
+ ...subpackages,
22735
+ ...subPackages
22736
+ ];
22737
+ await this.usingComponentsHandler(this.appEntry, appDirname);
22738
+ if (Array.isArray(pages)) {
22739
+ for (const page of pages) {
22740
+ await this.scanComponentEntry(page, appDirname);
22686
22741
  }
22687
- for (const sub of subs) {
22688
- if (sub.independent || this.configService.inlineConfig.weapp?.subPackages?.[sub.root]?.independent) {
22689
- const meta = {
22690
- entries: [],
22691
- entriesSet: /* @__PURE__ */ new Set(),
22692
- // 合并选项
22693
- subPackage: {
22694
- ...sub,
22695
- dependencies: this.configService.inlineConfig.weapp?.subPackages?.[sub.root].dependencies
22696
- }
22697
- };
22698
- if (Array.isArray(sub.pages)) {
22699
- for (const page of sub.pages) {
22700
- await this.scanComponentEntry(path13.join(sub.root, page), appDirname, meta);
22701
- }
22702
- }
22703
- if (sub.entry) {
22704
- await this.scanComponentEntry(path13.join(sub.root, sub.entry), appDirname, meta);
22742
+ }
22743
+ for (const sub of subs) {
22744
+ if (sub.independent || this.configService.weappViteConfig?.subPackages?.[sub.root]?.independent) {
22745
+ const meta = {
22746
+ entries: [],
22747
+ entriesSet: /* @__PURE__ */ new Set(),
22748
+ // 合并选项
22749
+ subPackage: {
22750
+ ...sub,
22751
+ dependencies: this.configService.weappViteConfig?.subPackages?.[sub.root].dependencies
22705
22752
  }
22706
- this.subPackageService.metaMap[sub.root] = meta;
22707
- } else {
22708
- if (Array.isArray(sub.pages)) {
22709
- for (const page of sub.pages) {
22710
- await this.scanComponentEntry(path13.join(sub.root, page), appDirname);
22711
- }
22753
+ };
22754
+ if (Array.isArray(sub.pages)) {
22755
+ for (const page of sub.pages) {
22756
+ await this.scanComponentEntry(path13.join(sub.root, page), appDirname, meta);
22712
22757
  }
22713
- if (sub.entry) {
22714
- await this.scanComponentEntry(path13.join(sub.root, sub.entry), appDirname);
22758
+ }
22759
+ if (sub.entry) {
22760
+ await this.scanComponentEntry(path13.join(sub.root, sub.entry), appDirname, meta);
22761
+ }
22762
+ this.subPackageService.metaMap[sub.root] = meta;
22763
+ } else {
22764
+ if (Array.isArray(sub.pages)) {
22765
+ for (const page of sub.pages) {
22766
+ await this.scanComponentEntry(path13.join(sub.root, page), appDirname);
22715
22767
  }
22716
22768
  }
22769
+ if (sub.entry) {
22770
+ await this.scanComponentEntry(path13.join(sub.root, sub.entry), appDirname);
22771
+ }
22717
22772
  }
22718
- if (get2(appEntry, "json.tabBar.custom")) {
22719
- await this.scanComponentEntry("custom-tab-bar/index", appDirname);
22720
- }
22721
- if (get2(appEntry, "json.appBar")) {
22722
- await this.scanComponentEntry("app-bar/index", appDirname);
22723
- }
22724
- debug?.("scanAppEntry end");
22725
- return appEntry;
22726
22773
  }
22774
+ if (get2(this.appEntry, "json.tabBar.custom")) {
22775
+ await this.scanComponentEntry("custom-tab-bar/index", appDirname);
22776
+ }
22777
+ if (get2(this.appEntry, "json.appBar")) {
22778
+ await this.scanComponentEntry("app-bar/index", appDirname);
22779
+ }
22780
+ debug?.("scanAppEntry end");
22727
22781
  } else {
22728
- throw new Error(`\u5728 ${appDirname} \u76EE\u5F55\u4E0B\u6CA1\u6709\u627E\u5230 \`app.json\`, \u8BF7\u786E\u4FDD\u4F60\u521D\u59CB\u5316\u4E86\u5C0F\u7A0B\u5E8F\u9879\u76EE\uFF0C\u6216\u8005\u5728 \`vite.config.ts\` \u4E2D\u8BBE\u7F6E\u7684\u6B63\u786E\u7684 \`weapp.srcRoot\` \u914D\u7F6E\u8DEF\u5F84 `);
22782
+ throw new Error(`\u6CA1\u6709\u5148\u6267\u884C loadAppEntry \u65B9\u6CD5\u52A0\u8F7D\u5168\u5C40 app.json \u914D\u7F6E`);
22729
22783
  }
22730
22784
  }
22731
22785
  // usingComponents
@@ -22744,6 +22798,10 @@ var ScanService2 = class {
22744
22798
  * 同时处理引入组件的情况,自动注入 usingComponents。
22745
22799
  */
22746
22800
  async scanComponentEntry(componentEntry, dirname3, subPackageMeta) {
22801
+ if (this.componentEntrySet.has(componentEntry)) {
22802
+ debug?.(`${componentEntry} \u5DF2\u7ECF\u88AB\u626B\u63CF\u8FC7`);
22803
+ return;
22804
+ }
22747
22805
  const meta = subPackageMeta ?? {
22748
22806
  entriesSet: this.entriesSet,
22749
22807
  entries: this.entries
@@ -22811,8 +22869,8 @@ var ScanService2 = class {
22811
22869
  }
22812
22870
  set2(jsonFragment.json, `usingComponents.${value.name}`, value.from);
22813
22871
  }
22814
- } else if (Array.isArray(this.configService.inlineConfig.weapp?.enhance?.autoImportComponents?.resolvers)) {
22815
- for (const resolver of this.configService.inlineConfig.weapp.enhance.autoImportComponents.resolvers) {
22872
+ } else if (Array.isArray(this.configService.weappViteConfig?.enhance?.autoImportComponents?.resolvers)) {
22873
+ for (const resolver of this.configService.weappViteConfig.enhance.autoImportComponents.resolvers) {
22816
22874
  const value = resolver(depComponentName, baseName);
22817
22875
  if (value) {
22818
22876
  if (!(isObject5(jsonFragment.json.usingComponents) && Reflect.has(jsonFragment.json.usingComponents, value.name))) {
@@ -22823,11 +22881,44 @@ var ScanService2 = class {
22823
22881
  }
22824
22882
  }
22825
22883
  }
22884
+ this.componentEntrySet.add(componentEntry);
22826
22885
  if (isObject5(config)) {
22827
22886
  await this.usingComponentsHandler(jsonFragment, path13.dirname(baseName), subPackageMeta);
22828
22887
  }
22829
22888
  debug?.("scanComponentEntry end", componentEntry, partialEntry);
22830
22889
  }
22890
+ // https://developers.weixin.qq.com/miniprogram/dev/framework/workers.html
22891
+ get workersOptions() {
22892
+ return this.appEntry?.json?.workers;
22893
+ }
22894
+ get workersDir() {
22895
+ return typeof this.workersOptions === "object" ? this.workersOptions.path : this.workersOptions;
22896
+ }
22897
+ // https://cn.vitejs.dev/guide/build.html#library-mode
22898
+ // miniprogram_dist
22899
+ // miniprogram
22900
+ // https://developers.weixin.qq.com/miniprogram/dev/devtools/npm.html#%E8%87%AA%E5%AE%9A%E4%B9%89%E7%BB%84%E4%BB%B6%E7%9B%B8%E5%85%B3%E7%A4%BA%E4%BE%8B
22901
+ // #endregion
22902
+ workersBuild(files) {
22903
+ if (this.workersDir && files.length) {
22904
+ const project = new Project({
22905
+ compilerOptions: {
22906
+ target: ScriptTarget.ES5,
22907
+ module: ModuleKind.CommonJS,
22908
+ outDir: path13.resolve(this.configService.outDir, this.workersDir),
22909
+ strict: true,
22910
+ allowJs: true
22911
+ },
22912
+ skipAddingFilesFromTsConfig: true
22913
+ });
22914
+ for (const file of files) {
22915
+ project.addSourceFileAtPath(file);
22916
+ }
22917
+ const result = project.emitToMemory();
22918
+ const sourceFiles = result.getFiles();
22919
+ return sourceFiles;
22920
+ }
22921
+ }
22831
22922
  };
22832
22923
  ScanService2 = _ts_decorate7([
22833
22924
  Kt(),
@@ -23037,7 +23128,7 @@ var WxmlService2 = class {
23037
23128
  const wxml = await fs12.readFile(filepath, "utf8");
23038
23129
  const res = scanWxml(wxml, {
23039
23130
  platform: this.configService.platform,
23040
- ...this.configService.inlineConfig.weapp?.enhance?.wxml === true ? {} : this.configService.inlineConfig.weapp?.enhance?.wxml
23131
+ ...this.configService.weappViteConfig?.enhance?.wxml === true ? {} : this.configService.weappViteConfig?.enhance?.wxml
23041
23132
  });
23042
23133
  this.tokenMap.set(filepath, res);
23043
23134
  await this.addDeps(filepath, res.deps.filter((x4) => isImportTag(x4.tagName) && isTemplate(x4.value)).map((x4) => path14.resolve(dirname3, x4.value)));
@@ -28,9 +28,9 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
28
28
  mod
29
29
  ));
30
30
 
31
- // ../../node_modules/.pnpm/tsup@8.3.5_@swc+core@1.10.4_jiti@2.4.2_postcss@8.4.49_tsx@4.19.2_typescript@5.7.2_yaml@2.6.1/node_modules/tsup/assets/esm_shims.js
31
+ // ../../node_modules/.pnpm/tsup@8.3.5_@swc+core@1.10.7_jiti@2.4.2_postcss@8.4.49_tsx@4.19.2_typescript@5.7.3_yaml@2.7.0/node_modules/tsup/assets/esm_shims.js
32
32
  var init_esm_shims = __esm({
33
- "../../node_modules/.pnpm/tsup@8.3.5_@swc+core@1.10.4_jiti@2.4.2_postcss@8.4.49_tsx@4.19.2_typescript@5.7.2_yaml@2.6.1/node_modules/tsup/assets/esm_shims.js"() {
33
+ "../../node_modules/.pnpm/tsup@8.3.5_@swc+core@1.10.7_jiti@2.4.2_postcss@8.4.49_tsx@4.19.2_typescript@5.7.3_yaml@2.7.0/node_modules/tsup/assets/esm_shims.js"() {
34
34
  "use strict";
35
35
  }
36
36
  });
@@ -1,7 +1,7 @@
1
1
  import {
2
2
  __name,
3
3
  init_esm_shims
4
- } from "./chunk-OCZOGFU3.mjs";
4
+ } from "./chunk-PEN3BLSY.mjs";
5
5
 
6
6
  // src/config.ts
7
7
  init_esm_shims();