@playfast/reform-proof-vitest 1.0.2 → 1.2.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.
@@ -0,0 +1,3 @@
1
+ export declare const setProofTestHook: (hook: () => void) => void;
2
+ export declare const registerSuites: (candidates: ReadonlyArray<unknown>) => void;
3
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AASA,eAAO,MAAM,gBAAgB,GAAI,MAAM,MAAM,IAAI,KAAG,IAEnD,CAAA;AAmBD,eAAO,MAAM,cAAc,GAAI,YAAY,aAAa,CAAC,OAAO,CAAC,KAAG,IAQnE,CAAA"}
package/dist/index.js ADDED
@@ -0,0 +1,34 @@
1
+ import { isProofSuite, withProofRunner } from '@playfast/reform-proof';
2
+ import { describe, expect, test } from 'vitest';
3
+ // Identity-keyed: a suite registers once even if several modules import it.
4
+ const registered = new WeakSet();
5
+ // App setup hooks (via plugin `setup`) run only inside proof-test bodies.
6
+ const setupHooks = new Set();
7
+ export const setProofTestHook = (hook) => {
8
+ setupHooks.add(hook);
9
+ };
10
+ const runSetupHooks = () => {
11
+ setupHooks.forEach((hook) => hook());
12
+ };
13
+ const registerSuite = (suite) => {
14
+ describe(suite.product.manifest.name, () => {
15
+ suite.proofs.forEach((proof) => {
16
+ const statement = proof.requirement.manifest.statement;
17
+ test(statement, async () => {
18
+ runSetupHooks();
19
+ const outcome = await withProofRunner((runner) => runner.executeProof(proof));
20
+ expect(outcome.ok, `reform-proof: ${statement} — ${outcome.error ?? 'failed'}`).toBe(true);
21
+ });
22
+ });
23
+ });
24
+ };
25
+ export const registerSuites = (candidates) => {
26
+ candidates.forEach((candidate) => {
27
+ if (!isProofSuite(candidate) || registered.has(candidate)) {
28
+ return;
29
+ }
30
+ registered.add(candidate);
31
+ registerSuite(candidate);
32
+ });
33
+ };
34
+ //# sourceMappingURL=index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AC5F,CAAC,CAAC,CAAA;QACJ,CAAC,CAAC,CAAA;IACJ,CAAC,CAAC,CAAA;AACJ,CAAC,CAAA;AAED,MAAM,CAAC,MAAM,cAAc,GAAG,CAAC,UAAkC,EAAQ,EAAE;IACzE,UAAU,CAAC,OAAO,CAAC,CAAC,SAAS,EAAE,EAAE;QAC/B,IAAI,CAAC,YAAY,CAAC,SAAS,CAAC,IAAI,UAAU,CAAC,GAAG,CAAC,SAAS,CAAC,EAAE,CAAC;YAC1D,OAAM;QACR,CAAC;QACD,UAAU,CAAC,GAAG,CAAC,SAAS,CAAC,CAAA;QACzB,aAAa,CAAC,SAAS,CAAC,CAAA;IAC1B,CAAC,CAAC,CAAA;AACJ,CAAC,CAAA"}
@@ -0,0 +1,13 @@
1
+ export interface ReformProofPluginOptionsExternalApi {
2
+ readonly setup?: string | ReadonlyArray<string>;
3
+ }
4
+ export interface ReformProofPluginExternalApi {
5
+ readonly name: string;
6
+ readonly enforce: 'post';
7
+ transform(code: string, id: string): Promise<{
8
+ readonly code: string;
9
+ readonly map: null;
10
+ } | null>;
11
+ }
12
+ export declare const reformProofPlugin: (options?: ReformProofPluginOptionsExternalApi) => ReformProofPluginExternalApi;
13
+ //# sourceMappingURL=plugin.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"plugin.d.ts","sourceRoot":"","sources":["../src/plugin.ts"],"names":[],"mappings":"AAIA,MAAM,WAAW,mCAAmC;IAClD,QAAQ,CAAC,KAAK,CAAC,EAAE,MAAM,GAAG,aAAa,CAAC,MAAM,CAAC,CAAA;CAChD;AAED,MAAM,WAAW,4BAA4B;IAC3C,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAA;IACrB,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAA;IACxB,SAAS,CAAC,IAAI,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,GAAG,OAAO,CAAC;QAAE,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;QAAC,QAAQ,CAAC,GAAG,EAAE,IAAI,CAAA;KAAE,GAAG,IAAI,CAAC,CAAA;CACnG;AAOD,eAAO,MAAM,iBAAiB,GAC5B,UAAU,mCAAmC,KAC5C,4BA2BF,CAAA"}
package/dist/plugin.js ADDED
@@ -0,0 +1,32 @@
1
+ import { init, parse } from 'es-module-lexer';
2
+ const PROOF_RE = /\.proof\.ts$/;
3
+ const sourcePath = (id) => id.replace(/\?.*$/, '');
4
+ const setupList = (setup) => setup === undefined ? [] : typeof setup === 'string' ? [setup] : setup;
5
+ export const reformProofPlugin = (options) => {
6
+ const setupImports = setupList(options?.setup)
7
+ .map((spec) => `import '${spec}'`)
8
+ .join('\n');
9
+ return {
10
+ name: 'reform-proof-vitest',
11
+ enforce: 'post',
12
+ async transform(code, id) {
13
+ if (!PROOF_RE.test(sourcePath(id))) {
14
+ return null;
15
+ }
16
+ await init;
17
+ const [, exports] = parse(code);
18
+ // Use local binding names; re-export-from has no `ln` and is skipped.
19
+ const names = exports
20
+ .map((exportSpec) => exportSpec.ln)
21
+ .filter((local) => typeof local === 'string' && local.length > 0);
22
+ if (names.length === 0) {
23
+ return null;
24
+ }
25
+ const epilogue = `\n${setupImports}\n` +
26
+ `import { registerSuites as __registerReformProofSuites } from '@playfast/reform-proof-vitest'\n` +
27
+ `__registerReformProofSuites([${names.join(', ')}])\n`;
28
+ return { code: code + epilogue, map: null };
29
+ },
30
+ };
31
+ };
32
+ //# sourceMappingURL=plugin.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"plugin.js","sourceRoot":"","sources":["../src/plugin.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,KAAK,EAAE,MAAM,iBAAiB,CAAA;AAE7C,MAAM,QAAQ,GAAG,cAAc,CAAA;AAY/B,MAAM,UAAU,GAAG,CAAC,EAAU,EAAU,EAAE,CAAC,EAAE,CAAC,OAAO,CAAC,OAAO,EAAE,EAAE,CAAC,CAAA;AAElE,MAAM,SAAS,GAAG,CAAC,KAAmD,EAAyB,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GAAG,EAAE,IAAI,EAAE,CAAA;QAC7C,CAAC;KACF,CAAA;AACH,CAAC,CAAA"}
package/package.json CHANGED
@@ -1,55 +1,67 @@
1
1
  {
2
2
  "name": "@playfast/reform-proof-vitest",
3
- "playbook": "./playbook",
4
- "version": "1.0.2",
5
- "type": "module",
3
+ "version": "1.2.0",
6
4
  "description": "Vitest adapter for reform-proof — a vite plugin that auto-registers every *.proof.ts suite as native vitest tests, run through the proof engine.",
7
5
  "keywords": [
8
- "reform",
9
6
  "effect",
10
- "testing",
11
7
  "proof",
8
+ "reform",
9
+ "testing",
12
10
  "vitest"
13
11
  ],
12
+ "bugs": {
13
+ "url": "https://github.com/playfast/reform/issues"
14
+ },
14
15
  "license": "MIT",
15
16
  "repository": {
16
17
  "type": "git",
17
18
  "url": "https://github.com/playfast/reform.git",
18
19
  "directory": "packages/reform-proof-vitest"
19
20
  },
20
- "bugs": {
21
- "url": "https://github.com/playfast/reform/issues"
22
- },
23
- "sideEffects": false,
24
- "exports": {
25
- "./package.json": "./package.json",
26
- ".": "./src/index.ts",
27
- "./*": "./src/*.ts"
28
- },
29
21
  "files": [
22
+ "dist",
30
23
  "src",
31
24
  "README.md"
32
25
  ],
26
+ "type": "module",
27
+ "sideEffects": false,
28
+ "main": "./dist/index.js",
29
+ "types": "./dist/index.d.ts",
30
+ "exports": {
31
+ "./package.json": "./package.json",
32
+ ".": {
33
+ "playfast-src": "./src/index.ts",
34
+ "types": "./dist/index.d.ts",
35
+ "default": "./dist/index.js"
36
+ },
37
+ "./*": {
38
+ "playfast-src": "./src/*.ts",
39
+ "types": "./dist/*.d.ts",
40
+ "default": "./dist/*.js"
41
+ }
42
+ },
43
+ "publishConfig": {
44
+ "access": "public"
45
+ },
33
46
  "scripts": {
34
47
  "clean": "rm -rf dist .tsbuildinfo",
35
48
  "check": "tsc --noEmit",
36
- "build": "tsc -p tsconfig.build.json",
49
+ "build": "rm -rf dist .tsbuildinfo && tsc -p tsconfig.build.json && bun ../../scripts/fix-esm-extensions.ts dist",
37
50
  "test": "vitest run",
38
51
  "test:watch": "vitest",
39
52
  "lint": "oxlint src",
40
- "lint:fix": "oxlint --fix src"
53
+ "lint:fix": "oxlint --fix src",
54
+ "prepack": "bun run build"
41
55
  },
42
56
  "dependencies": {
43
57
  "es-module-lexer": "^1.5.4"
44
58
  },
45
- "peerDependencies": {
46
- "vitest": "*",
47
- "@playfast/reform-proof": "*"
48
- },
49
59
  "devDependencies": {
50
60
  "@playfast/reform-proof": "*"
51
61
  },
52
- "publishConfig": {
53
- "access": "public"
54
- }
62
+ "peerDependencies": {
63
+ "@playfast/reform-proof": "*",
64
+ "vitest": "*"
65
+ },
66
+ "playbook": "./playbook"
55
67
  }
package/src/plugin.ts CHANGED
@@ -9,17 +9,12 @@ export interface ReformProofPluginOptionsExternalApi {
9
9
  export interface ReformProofPluginExternalApi {
10
10
  readonly name: string
11
11
  readonly enforce: 'post'
12
- transform(
13
- code: string,
14
- id: string,
15
- ): Promise<{ readonly code: string; readonly map: null } | null>
12
+ transform(code: string, id: string): Promise<{ readonly code: string; readonly map: null } | null>
16
13
  }
17
14
 
18
15
  const sourcePath = (id: string): string => id.replace(/\?.*$/, '')
19
16
 
20
- const setupList = (
21
- setup: ReformProofPluginOptionsExternalApi['setup'],
22
- ): ReadonlyArray<string> =>
17
+ const setupList = (setup: ReformProofPluginOptionsExternalApi['setup']): ReadonlyArray<string> =>
23
18
  setup === undefined ? [] : typeof setup === 'string' ? [setup] : setup
24
19
 
25
20
  export const reformProofPlugin = (