twd-js 1.3.1 → 1.3.3
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/dist/bundled.d.ts +18 -0
- package/dist/bundled.es.js +63 -60
- package/dist/bundled.umd.js +2 -2
- package/dist/index.cjs.js +28 -28
- package/dist/index.d.ts +31 -0
- package/dist/index.es.js +1910 -1906
- package/dist/mock-sw.js +1 -1
- package/dist/vite-plugin.cjs.js +1 -1
- package/dist/vite-plugin.d.ts +46 -0
- package/dist/vite-plugin.es.js +21 -5
- package/package.json +1 -1
package/dist/mock-sw.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
const h=e=>{try{return new RegExp(e),!0}catch{return!1}},u=e=>{const s=e.split("?")[0];return/\.([a-zA-Z0-9]+)$/.test(s)};function f(e,s,n){return n.find(t=>{const o=t.method.toLowerCase()===e.toLowerCase();if(t.urlRegex&&h(t.url)){const a=new RegExp(t.url);return o&&a.test(s)}if(u(t.url))return o&&s.includes(t.url);const l=t.url===s||s.includes(t.url);return o&&l&&!u(s)})}function p(e,s,n){e.forEach(t=>t.postMessage({type:"EXECUTED",alias:s.alias,request:n}))}const y=(e,s,n)=>{const o=![204,205,304].includes(s),i=o?JSON.stringify(e):null;return new Response(i,{status:s,headers:o?n||{"Content-Type":"application/json"}:n||{}})},c="1.3.
|
|
1
|
+
const h=e=>{try{return new RegExp(e),!0}catch{return!1}},u=e=>{const s=e.split("?")[0];return/\.([a-zA-Z0-9]+)$/.test(s)};function f(e,s,n){return n.find(t=>{const o=t.method.toLowerCase()===e.toLowerCase();if(t.urlRegex&&h(t.url)){const a=new RegExp(t.url);return o&&a.test(s)}if(u(t.url))return o&&s.includes(t.url);const l=t.url===s||s.includes(t.url);return o&&l&&!u(s)})}function p(e,s,n){e.forEach(t=>t.postMessage({type:"EXECUTED",alias:s.alias,request:n}))}const y=(e,s,n)=>{const o=![204,205,304].includes(s),i=o?JSON.stringify(e):null;return new Response(i,{status:s,headers:o?n||{"Content-Type":"application/json"}:n||{}})},c="1.3.3";let r=[];const g=async e=>{const{method:s}=e.request,n=e.request.url,t=f(s,n,r);t&&(console.log("[TWD] Mock hit:",t.alias,s,n),e.respondWith((async()=>{let o=null;const i=e.request.headers.get("content-type")||"application/json";if(i.includes("application/json"))try{o=await e.request.clone().json()}catch{}else if(i.includes("form"))try{const l=await e.request.clone().formData();o={},l.forEach((a,d)=>{o[d]=a})}catch{}else if(i.includes("text"))try{o=await e.request.clone().text()}catch{}else if(i.includes("octet-stream"))try{o=await e.request.clone().arrayBuffer()}catch{}else if(i.includes("image"))try{o=await e.request.clone().blob()}catch{}else try{o=await e.request.clone().text()}catch{}return self.clients.matchAll().then(l=>{p(l,t,o)}),y(t.response,t.status??200,t.responseHeaders)})()))},m=e=>{e!==c&&console.warn(`[TWD] ⚠️ Version mismatch detected:
|
|
2
2
|
Client version: ${e}
|
|
3
3
|
Service Worker version: ${c}
|
|
4
4
|
|
package/dist/vite-plugin.cjs.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const n=require("fs"),c=require("path");function l(){return{name:"remove-mock-sw",apply:"build",closeBundle(){try{n.rmSync(c.resolve("dist/mock-sw.js")),console.log("🧹 Removed mock-sw.js from build")}catch{console.log("🧹 No mock-sw.js found in build")}}}}function i(o={}){const{testFilePattern:e=".twd.test.ts"}=o,r=typeof e=="function"?e:t=>t.endsWith(e);return{name:"twd-hmr",apply:"serve",handleHotUpdate({file:t,server:s}){if(r(t))return s.ws.send({type:"full-reload",path:"*"}),[]}}}exports.removeMockServiceWorker=l;exports.twdHmr=i;
|
package/dist/vite-plugin.d.ts
CHANGED
|
@@ -18,4 +18,50 @@ import { Plugin as Plugin_2 } from 'vite';
|
|
|
18
18
|
*/
|
|
19
19
|
export declare function removeMockServiceWorker(): Plugin_2;
|
|
20
20
|
|
|
21
|
+
/**
|
|
22
|
+
* Vite plugin to handle HMR for TWD test files.
|
|
23
|
+
* When a TWD test file is updated, it forces a full page reload to prevent
|
|
24
|
+
* duplicate test entries that occur when HMR reloads test modules.
|
|
25
|
+
*
|
|
26
|
+
* This plugin only runs in development mode (serve) and does not affect Vitest test runs.
|
|
27
|
+
*
|
|
28
|
+
* @param options - Configuration options for the plugin
|
|
29
|
+
* @example
|
|
30
|
+
* ```ts
|
|
31
|
+
* import { twdHmr } from 'twd-js/vite-plugin';
|
|
32
|
+
*
|
|
33
|
+
* export default defineConfig({
|
|
34
|
+
* plugins: [
|
|
35
|
+
* // ... other plugins
|
|
36
|
+
* twdHmr() // Uses default pattern: .twd.test.ts
|
|
37
|
+
* ]
|
|
38
|
+
* });
|
|
39
|
+
* ```
|
|
40
|
+
* @example
|
|
41
|
+
* ```ts
|
|
42
|
+
* // Custom pattern
|
|
43
|
+
* twdHmr({ testFilePattern: '.twd.test.tsx' })
|
|
44
|
+
* ```
|
|
45
|
+
* @example
|
|
46
|
+
* ```ts
|
|
47
|
+
* // Custom function
|
|
48
|
+
* twdHmr({
|
|
49
|
+
* testFilePattern: (file) => file.includes('.twd.test.')
|
|
50
|
+
* })
|
|
51
|
+
* ```
|
|
52
|
+
*/
|
|
53
|
+
export declare function twdHmr(options?: TwdHmrOptions): Plugin_2;
|
|
54
|
+
|
|
55
|
+
/**
|
|
56
|
+
* Options for the TWD HMR plugin.
|
|
57
|
+
*/
|
|
58
|
+
export declare interface TwdHmrOptions {
|
|
59
|
+
/**
|
|
60
|
+
* Pattern to match test files. Defaults to `.twd.test.ts`.
|
|
61
|
+
* Can be a string (checked with `endsWith`) or a function that returns a boolean.
|
|
62
|
+
* @default ".twd.test.ts"
|
|
63
|
+
*/
|
|
64
|
+
testFilePattern?: string | ((file: string) => boolean);
|
|
65
|
+
}
|
|
66
|
+
|
|
21
67
|
export { }
|
package/dist/vite-plugin.es.js
CHANGED
|
@@ -1,18 +1,34 @@
|
|
|
1
|
-
import { rmSync as
|
|
2
|
-
import { resolve as
|
|
3
|
-
function
|
|
1
|
+
import { rmSync as s } from "fs";
|
|
2
|
+
import { resolve as l } from "path";
|
|
3
|
+
function i() {
|
|
4
4
|
return {
|
|
5
5
|
name: "remove-mock-sw",
|
|
6
6
|
apply: "build",
|
|
7
7
|
closeBundle() {
|
|
8
8
|
try {
|
|
9
|
-
|
|
9
|
+
s(l("dist/mock-sw.js")), console.log("🧹 Removed mock-sw.js from build");
|
|
10
10
|
} catch {
|
|
11
11
|
console.log("🧹 No mock-sw.js found in build");
|
|
12
12
|
}
|
|
13
13
|
}
|
|
14
14
|
};
|
|
15
15
|
}
|
|
16
|
+
function d(t = {}) {
|
|
17
|
+
const { testFilePattern: e = ".twd.test.ts" } = t, r = typeof e == "function" ? e : (o) => o.endsWith(e);
|
|
18
|
+
return {
|
|
19
|
+
name: "twd-hmr",
|
|
20
|
+
apply: "serve",
|
|
21
|
+
// Only run in dev mode, not during Vitest test runs
|
|
22
|
+
handleHotUpdate({ file: o, server: n }) {
|
|
23
|
+
if (r(o))
|
|
24
|
+
return n.ws.send({
|
|
25
|
+
type: "full-reload",
|
|
26
|
+
path: "*"
|
|
27
|
+
}), [];
|
|
28
|
+
}
|
|
29
|
+
};
|
|
30
|
+
}
|
|
16
31
|
export {
|
|
17
|
-
|
|
32
|
+
i as removeMockServiceWorker,
|
|
33
|
+
d as twdHmr
|
|
18
34
|
};
|