@mpcore/weapp-vite 0.1.29 → 1.0.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.
package/README.md CHANGED
@@ -9,4 +9,6 @@ const project = await createWeappViteTestProject({ cwd: process.cwd() })
9
9
  const result = await project.renderPage('/pages/index/index')
10
10
  ```
11
11
 
12
- Cold builds emit to `.weapp-vite/test-artifacts/`. Repeated calls reuse a valid artifact, while watch mode performs a complete bundler-owned rebuild after source changes.
12
+ Cold builds emit immutable generations under `.weapp-vite/test-artifacts/`, isolated by process and build configuration. Repeated calls validate source, configuration, compiler dependencies and output contents before reusing an artifact. Rebuilding never overwrites a generation still used by a test. An explicit `outDir` opts into a caller-owned output directory; do not share that directory between concurrent builds or running tests.
13
+
14
+ Watch mode follows source files, configuration dependencies and the compiler module graph, then publishes a complete bundler-owned generation before calling `onRebuilt`. Changes during a build coalesce into a follow-up build. `close()` waits for any active build and callback, prevents late notifications, and releases only its own watcher. Generated generations remain available until the caller cleans the project’s `.weapp-vite/test-artifacts/` directory after all tests have closed.
package/dist/index.d.mts CHANGED
@@ -1,33 +1,12 @@
1
1
  import { CreateTestProjectOptions, MiniProgramTestProject } from "@mpcore/test";
2
+ import { BuildTestArtifactOptions, BuildTestArtifactOptions as BuildTestArtifactOptions$1, WatchTestArtifactOptions, WatchTestArtifactOptions as WatchTestArtifactOptions$1, WeappViteTestArtifact, WeappViteTestArtifact as WeappViteTestArtifact$1, WeappViteTestArtifactWatcher, WeappViteTestArtifactWatcher as WeappViteTestArtifactWatcher$1 } from "weapp-vite/test";
2
3
  //#region src/index.d.ts
3
- export interface BuildTestArtifactOptions {
4
- configFile?: string;
5
- cwd?: string;
6
- mode?: string;
7
- outDir?: string;
8
- projectConfigPath?: string;
9
- skipNpm?: boolean;
10
- }
11
- export interface WeappViteTestArtifact {
12
- appConfigPath: string;
13
- miniprogramRootPath: string;
14
- projectPath: string;
15
- sourceRootPath: string;
16
- }
17
- export interface WatchTestArtifactOptions extends BuildTestArtifactOptions {
18
- onError?: (error: unknown) => void;
19
- onRebuilt?: (artifact: WeappViteTestArtifact) => void | Promise<void>;
20
- }
21
- export interface WeappViteTestArtifactWatcher {
22
- artifact: WeappViteTestArtifact;
23
- close: () => Promise<void>;
24
- rebuild: () => Promise<WeappViteTestArtifact>;
25
- }
26
- export interface CreateWeappViteTestProjectOptions extends BuildTestArtifactOptions {
4
+ export interface CreateWeappViteTestProjectOptions extends BuildTestArtifactOptions$1 {
27
5
  test?: Omit<CreateTestProjectOptions, 'artifact'>;
28
6
  }
29
- export declare function buildWeappViteTestArtifact(options?: BuildTestArtifactOptions): Promise<WeappViteTestArtifact>;
30
- export declare function clearWeappViteTestArtifactCache(options?: BuildTestArtifactOptions): void;
7
+ export declare function buildWeappViteTestArtifact(options?: BuildTestArtifactOptions$1): Promise<WeappViteTestArtifact$1>;
8
+ export declare function clearWeappViteTestArtifactCache(options?: BuildTestArtifactOptions$1): void;
31
9
  export declare function createWeappViteTestProject(options?: CreateWeappViteTestProjectOptions): Promise<MiniProgramTestProject>;
32
- export declare function watchWeappViteTestArtifact(options?: WatchTestArtifactOptions): Promise<WeappViteTestArtifactWatcher>;
33
- //#endregion
10
+ export declare function watchWeappViteTestArtifact(options?: WatchTestArtifactOptions$1): Promise<WeappViteTestArtifactWatcher$1>;
11
+ //#endregion
12
+ export type { BuildTestArtifactOptions, WatchTestArtifactOptions, WeappViteTestArtifact, WeappViteTestArtifactWatcher };
package/dist/index.mjs CHANGED
@@ -1,42 +1,35 @@
1
- import fs from "node:fs/promises";
2
1
  import path from "node:path";
3
2
  import process from "node:process";
4
3
  import { createTestProject } from "@mpcore/test";
5
- import { buildTestArtifact, watchTestArtifact } from "weapp-vite/test";
4
+ import { buildTestArtifact, isTestArtifactCurrent, watchTestArtifact } from "weapp-vite/test";
6
5
  //#region src/index.ts
7
6
  const artifactCache = /* @__PURE__ */ new Map();
8
7
  function cacheKey(options) {
8
+ const cwd = path.resolve(options.cwd ?? process.cwd());
9
9
  return JSON.stringify({
10
- configFile: options.configFile,
11
- cwd: path.resolve(options.cwd ?? process.cwd()),
10
+ configFile: options.configFile && path.resolve(cwd, options.configFile),
11
+ cwd,
12
12
  mode: options.mode ?? "test",
13
- outDir: options.outDir,
14
- projectConfigPath: options.projectConfigPath,
15
- skipNpm: options.skipNpm
13
+ outDir: options.outDir && path.resolve(cwd, options.outDir),
14
+ projectConfigPath: options.projectConfigPath && path.resolve(cwd, options.projectConfigPath),
15
+ skipNpm: options.skipNpm ?? false
16
16
  });
17
17
  }
18
- async function artifactExists(artifact) {
19
- try {
20
- await fs.access(artifact.appConfigPath);
21
- return true;
22
- } catch {
23
- return false;
24
- }
25
- }
26
18
  async function buildWeappViteTestArtifact(options = {}) {
27
19
  const key = cacheKey(options);
28
20
  const cached = artifactCache.get(key);
29
- if (cached) {
30
- const artifact = await cached;
31
- if (await artifactExists(artifact)) return artifact;
32
- artifactCache.delete(key);
33
- }
34
- const pending = buildTestArtifact(options);
21
+ const pending = (async () => {
22
+ if (cached) {
23
+ const artifact = await cached.catch(() => void 0);
24
+ if (artifact && await isTestArtifactCurrent(artifact)) return artifact;
25
+ }
26
+ return await buildTestArtifact(options);
27
+ })();
35
28
  artifactCache.set(key, pending);
36
29
  try {
37
30
  return await pending;
38
31
  } catch (error) {
39
- artifactCache.delete(key);
32
+ if (artifactCache.get(key) === pending) artifactCache.delete(key);
40
33
  throw error;
41
34
  }
42
35
  }
@@ -57,13 +50,15 @@ async function createWeappViteTestProject(options = {}) {
57
50
  }
58
51
  async function watchWeappViteTestArtifact(options = {}) {
59
52
  clearWeappViteTestArtifactCache(options);
60
- return await watchTestArtifact({
53
+ const watcher = await watchTestArtifact({
61
54
  ...options,
62
55
  async onRebuilt(artifact) {
63
56
  artifactCache.set(cacheKey(options), Promise.resolve(artifact));
64
57
  await options.onRebuilt?.(artifact);
65
58
  }
66
59
  });
60
+ artifactCache.set(cacheKey(options), Promise.resolve(watcher.artifact));
61
+ return watcher;
67
62
  }
68
63
  //#endregion
69
64
  export { buildWeappViteTestArtifact, clearWeappViteTestArtifactCache, createWeappViteTestProject, watchWeappViteTestArtifact };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@mpcore/weapp-vite",
3
3
  "type": "module",
4
- "version": "0.1.29",
4
+ "version": "1.0.0",
5
5
  "description": "weapp-vite artifact adapter for @mpcore/test",
6
6
  "author": "ice breaker <1324318532@qq.com>",
7
7
  "license": "MIT",
@@ -37,11 +37,11 @@
37
37
  "dist"
38
38
  ],
39
39
  "engines": {
40
- "node": "^20.19.0 || >=22.12.0"
40
+ "node": "^22.18.0 || ^24.11.0 || >=26.0.0"
41
41
  },
42
42
  "dependencies": {
43
- "@mpcore/test": "0.1.15",
44
- "weapp-vite": "7.4.0"
43
+ "@mpcore/test": "1.0.0",
44
+ "weapp-vite": "7.5.0"
45
45
  },
46
46
  "publishConfig": {
47
47
  "access": "public",
@@ -49,15 +49,16 @@
49
49
  },
50
50
  "tsd": {
51
51
  "compilerOptions": {
52
- "module": "ESNext",
53
- "moduleResolution": "Bundler"
52
+ "module": "NodeNext",
53
+ "moduleResolution": "NodeNext"
54
54
  }
55
55
  },
56
56
  "scripts": {
57
57
  "build": "tsdown",
58
58
  "dev": "tsdown -w",
59
59
  "test": "vitest run",
60
- "test:types": "pnpm build && tsd",
60
+ "test:types": "pnpm build && pnpm run test:types:check",
61
+ "test:types:check": "tsd --files \"test-d/**/*.test-d.ts\"",
61
62
  "typecheck": "tsc --noEmit"
62
63
  }
63
64
  }