Skip to content

Commit 78f7639

Browse files
committed
chore(mocks): generate and publish types + setup wireit
1 parent 3fae385 commit 78f7639

25 files changed

+239
-74
lines changed

.changeset/sour-grapes-rest.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@web/mocks': patch
3+
---
4+
5+
Publish Types

.eslintignore

+1
Original file line numberDiff line numberDiff line change
@@ -17,3 +17,4 @@ demo
1717
CHANGELOG.md
1818
.changeset
1919
_site
20+
dist-types

.github/workflows/canary.yml

+3
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,9 @@ jobs:
2828
cache: 'npm'
2929
registry-url: 'https://registry.npmjs.org'
3030

31+
# Set up GitHub Actions caching for Wireit.
32+
- uses: google/wireit@setup-github-actions-caching/v1
33+
3134
- name: Install Dependencies
3235
run: npm ci
3336

.github/workflows/release.yml

+3
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,9 @@ jobs:
2727
cache: 'npm'
2828
registry-url: 'https://registry.npmjs.org'
2929

30+
# Set up GitHub Actions caching for Wireit.
31+
- uses: google/wireit@setup-github-actions-caching/v1
32+
3033
- name: Install Dependencies
3134
run: npm ci
3235

.github/workflows/verify-browserstack.yml

+4-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,10 @@ jobs:
2323
node-version: '18'
2424
cache: 'npm'
2525

26-
- name: Install dependencies
26+
# Set up GitHub Actions caching for Wireit.
27+
- uses: google/wireit@setup-github-actions-caching/v1
28+
29+
- name: Install Dependencies
2730
run: npm ci
2831

2932
- name: Build packages

.github/workflows/verify-node.yml

+4-1
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,10 @@ jobs:
2929
- name: Install Playwright dependencies
3030
run: npx playwright install-deps
3131

32-
- name: Install dependencies
32+
# Set up GitHub Actions caching for Wireit.
33+
- uses: google/wireit@setup-github-actions-caching/v1
34+
35+
- name: Install Dependencies
3336
run: npm ci
3437

3538
- name: Build packages

.github/workflows/verify-saucelabs.yml

+4-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,10 @@ jobs:
2323
node-version: '18'
2424
cache: 'npm'
2525

26-
- name: Install dependencies
26+
# Set up GitHub Actions caching for Wireit.
27+
- uses: google/wireit@setup-github-actions-caching/v1
28+
29+
- name: Install Dependencies
2730
run: npm ci
2831

2932
- name: Build packages

.github/workflows/verify-windows.yml

+4-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,10 @@ jobs:
2525
- name: Install Playwright dependencies
2626
run: npx playwright install-deps
2727

28-
- name: Install dependencies
28+
# Set up GitHub Actions caching for Wireit.
29+
- uses: google/wireit@setup-github-actions-caching/v1
30+
31+
- name: Install Dependencies
2932
run: npm ci
3033

3134
- name: Build

.gitignore

+2
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@ yarn.lock
2525
packages/*/yarn.lock
2626

2727
## build output
28+
dist-types
29+
.wireit
2830
/dist
2931
/packages/*/dist
3032
tsconfig.tsbuildinfo

package-lock.json

+48-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+21-12
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
"node": ">=16.0.0"
1111
},
1212
"scripts": {
13-
"build": "rimraf --glob packages/*/tsconfig.tsbuildinfo && tsc --build",
13+
"build": "rimraf --glob packages/*/tsconfig.tsbuildinfo && tsc --build && npm run types",
1414
"build:production": "node scripts/workspaces-scripts-bin.mjs build:production",
1515
"build:site": "npm run build && rocket build",
1616
"build:watch": "rimraf --glob packages/*/tsconfig.tsbuildinfo && tsc --build --watch",
@@ -30,6 +30,7 @@
3030
"search": "rocket search",
3131
"start": "rocket start",
3232
"start:build": "node packages/dev-server/dist/bin.js --root-dir _site --open",
33+
"types": "wireit",
3334
"test": "npm run test:node && npm run test:browser && node scripts/workspaces-scripts-bin.mjs test:ci",
3435
"test:browser": "node packages/test-runner/dist/bin.js \"packages/*/test-browser/**/*.test.{js,ts}\"",
3536
"test:node": "mocha \"packages/!(*test-runner-selenium|*test-runner-webdriver)/test/**/*.test.{ts,js,mjs,cjs}\"",
@@ -73,17 +74,8 @@
7374
"rimraf": "^4.4.1",
7475
"rollup": "^3.15.0",
7576
"ts-node": "^10.4.0",
76-
"typescript": "~5.0.4"
77-
},
78-
"overrides": {
79-
"@lion/accordion": "^0.11.1",
80-
"@lion/combobox": "^0.11.1",
81-
"@lion/core": "^0.24.0",
82-
"@lion/form-core": "^0.18.3",
83-
"@lion/overlays": "^0.33.2",
84-
"@mdjs/core": "^0.9.0",
85-
"@mdjs/mdjs-preview": "^0.5.5",
86-
"@rocket/drawer": "^0.1.4"
77+
"typescript": "~5.0.4",
78+
"wireit": "^0.9.5"
8779
},
8880
"eslintConfig": {
8981
"parser": "@typescript-eslint/parser",
@@ -125,12 +117,29 @@
125117
"exit": true,
126118
"retries": 3
127119
},
120+
"overrides": {
121+
"@lion/accordion": "^0.11.1",
122+
"@lion/combobox": "^0.11.1",
123+
"@lion/core": "^0.24.0",
124+
"@lion/form-core": "^0.18.3",
125+
"@lion/overlays": "^0.33.2",
126+
"@mdjs/core": "^0.9.0",
127+
"@mdjs/mdjs-preview": "^0.5.5",
128+
"@rocket/drawer": "^0.1.4"
129+
},
128130
"prettier": {
129131
"singleQuote": true,
130132
"arrowParens": "avoid",
131133
"printWidth": 100,
132134
"trailingComma": "all"
133135
},
136+
"wireit": {
137+
"types": {
138+
"dependencies": [
139+
"./packages/mocks:types"
140+
]
141+
}
142+
},
134143
"workspaces": [
135144
"packages/*",
136145
"integration/*"

packages/mocks/browser.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ worker.start({
1818
/**
1919
* Mock the given mocked routes using a Service Worker.
2020
*
21-
* @param {Array<Array<Mock>|Mock>} mocks
21+
* @param {import('./types.js').Mock[]} mocks
2222
*/
2323
function registerMockRoutes(...mocks) {
2424
_registerMockRoutes(worker, bypassServiceWorker, ...mocks);

packages/mocks/http.js

+38
Original file line numberDiff line numberDiff line change
@@ -6,22 +6,60 @@ const VERSION = Symbol.for('msw-integration-layer::version');
66
* and it's import should be pure and non-sideeffectful.
77
*/
88
export const http = {
9+
/**
10+
* @param {string} endpoint
11+
* @param {import('./types.js').handler} handler
12+
* @returns {import('./types.js').Mock}
13+
*/
914
get: (endpoint, handler) => {
1015
return { [VERSION]: '1.x.x', method: 'get', endpoint, handler };
1116
},
17+
/**
18+
* @param {string} endpoint
19+
* @param {import('./types.js').handler} handler
20+
* @returns {import('./types.js').Mock}
21+
*/
1222
post: (endpoint, handler) => {
1323
return { [VERSION]: '1.x.x', method: 'post', endpoint, handler };
1424
},
25+
/**
26+
* @param {string} endpoint
27+
* @param {import('./types.js').handler} handler
28+
* @returns {import('./types.js').Mock}
29+
*/
1530
put: (endpoint, handler) => {
1631
return { [VERSION]: '1.x.x', method: 'put', endpoint, handler };
1732
},
33+
/**
34+
* @param {string} endpoint
35+
* @param {import('./types.js').handler} handler
36+
* @returns {import('./types.js').Mock}
37+
*/
1838
patch: (endpoint, handler) => {
1939
return { [VERSION]: '1.x.x', method: 'patch', endpoint, handler };
2040
},
41+
/**
42+
* @param {string} endpoint
43+
* @param {import('./types.js').handler} handler
44+
* @returns {import('./types.js').Mock}
45+
*/
2146
delete: (endpoint, handler) => {
2247
return { [VERSION]: '1.x.x', method: 'delete', endpoint, handler };
2348
},
49+
/**
50+
* @param {string} endpoint
51+
* @param {import('./types.js').handler} handler
52+
* @returns {import('./types.js').Mock}
53+
*/
2454
options: (endpoint, handler) => {
2555
return { [VERSION]: '1.x.x', method: 'options', endpoint, handler };
2656
},
57+
/**
58+
* @param {string} endpoint
59+
* @param {import('./types.js').handler} handler
60+
* @returns {import('./types.js').Mock}
61+
*/
62+
head: (endpoint, handler) => {
63+
return { [VERSION]: '1.x.x', method: 'head', endpoint, handler };
64+
},
2765
};

packages/mocks/node.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
import { setupServer } from 'msw/node';
2-
import { _registerMockRoutes } from './_registerMockRoutes.js';
2+
import { _registerMockRoutes } from './registerMockRoutes.js';
33

44
export const server = setupServer();
55
server.listen();
66

77
/**
88
* Mock the given mocked routes using a Service Worker.
99
*
10-
* @param {Array<Array<Mock>|Mock>} mocks
10+
* @param {import('./types.js').Mock[]} mocks
1111
*/
1212
export function registerMockRoutes(...mocks) {
1313
_registerMockRoutes(server, false, ...mocks);

0 commit comments

Comments
 (0)