@warp-drive/holodeck 0.0.0-alpha.8 → 0.0.0-alpha.83

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
@@ -40,16 +40,21 @@
40
40
 
41
41
  ## Installation
42
42
 
43
- > ⚠️ Private
44
-
45
- This package may currently only be used within EmberData. A public version is coming soon 💜
46
43
 
47
44
  ```json
48
- "devDependencies": {
49
- "@warp-drive/holodeck": "workspace:*"
50
- }
45
+ pnpm install @warp-drive/holodeck
51
46
  ```
52
47
 
48
+ **Tagged Releases**
49
+
50
+ - ![NPM Canary Version](https://img.shields.io/npm/v/%40warp-drive/holodeck/canary?label=%40canary&color=FFBF00)
51
+ - ![NPM Beta Version](https://img.shields.io/npm/v/%40warp-drive/holodeck/beta?label=%40beta&color=ff00ff)
52
+ - ![NPM Stable Version](https://img.shields.io/npm/v/%40warp-drive/holodeck/latest?label=%40latest&color=90EE90)
53
+ - ![NPM LTS Version](https://img.shields.io/npm/v/%40warp-drive/holodeck/lts?label=%40lts&color=0096FF)
54
+ - ![NPM LTS 4.12 Version](https://img.shields.io/npm/v/%40warp-drive/holodeck/lts-4-12?label=%40lts-4-12&color=bbbbbb)
55
+
56
+
57
+
53
58
  ## Usage
54
59
  #### Mocking from Within a Test
55
60
 
package/dist/index.js CHANGED
@@ -1,4 +1,10 @@
1
1
  const TEST_IDS = new WeakMap();
2
+ let HOST = 'https://localhost:1135/';
3
+ function setConfig({
4
+ host
5
+ }) {
6
+ HOST = host.endsWith('/') ? host : `${host}/`;
7
+ }
2
8
  function setTestId(context, str) {
3
9
  if (str && TEST_IDS.has(context)) {
4
10
  throw new Error(`MockServerHandler is already configured with a testId.`);
@@ -38,7 +44,9 @@ class MockServerHandler {
38
44
  request.credentials = 'omit';
39
45
  request.referrerPolicy = '';
40
46
  try {
41
- return await next(request);
47
+ const future = next(request);
48
+ context.setStream(future.getStream());
49
+ return await future;
42
50
  } catch (e) {
43
51
  if (e instanceof Error && !(e instanceof DOMException)) {
44
52
  e.message = e.message.replace(queryForTest, '');
@@ -54,7 +62,7 @@ async function mock(owner, generate, isRecording) {
54
62
  }
55
63
  const testMockNum = test.mock++;
56
64
  if (getIsRecording() || isRecording) {
57
- const url = `https://localhost:1135/__record?__xTestId=${test.id}&__xTestRequestNumber=${testMockNum}`;
65
+ const url = `${HOST}__record?__xTestId=${test.id}&__xTestRequestNumber=${testMockNum}`;
58
66
  await fetch(url, {
59
67
  method: 'POST',
60
68
  body: JSON.stringify(generate()),
@@ -65,5 +73,5 @@ async function mock(owner, generate, isRecording) {
65
73
  }
66
74
  }
67
75
 
68
- export { MockServerHandler, getIsRecording, mock, setIsRecording, setTestId };
76
+ export { MockServerHandler, getIsRecording, mock, setConfig, setIsRecording, setTestId };
69
77
  //# sourceMappingURL=index.js.map
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sources":["../client/index.ts"],"sourcesContent":["import type { Handler, NextFn, RequestContext, RequestInfo, StructuredDataDocument } from '@ember-data/request';\n\nimport type { ScaffoldGenerator } from './mock';\n\nconst TEST_IDS = new WeakMap<object, { id: string; request: number; mock: number }>();\n\nexport function setTestId(context: object, str: string | null) {\n if (str && TEST_IDS.has(context)) {\n throw new Error(`MockServerHandler is already configured with a testId.`);\n }\n if (str) {\n TEST_IDS.set(context, { id: str, request: 0, mock: 0 });\n } else {\n TEST_IDS.delete(context);\n }\n}\n\nlet IS_RECORDING = false;\nexport function setIsRecording(value: boolean) {\n IS_RECORDING = Boolean(value);\n}\nexport function getIsRecording() {\n return IS_RECORDING;\n}\n\nexport class MockServerHandler implements Handler {\n declare owner: object;\n constructor(owner: object) {\n this.owner = owner;\n }\n async request<T>(context: RequestContext, next: NextFn<T>): Promise<StructuredDataDocument<T>> {\n const test = TEST_IDS.get(this.owner);\n if (!test) {\n throw new Error(\n `MockServerHandler is not configured with a testId. Use setTestId to set the testId for each test`\n );\n }\n\n const request: RequestInfo = Object.assign({}, context.request);\n const isRecording = request.url!.endsWith('/__record');\n const firstChar = request.url!.includes('?') ? '&' : '?';\n const queryForTest = `${firstChar}__xTestId=${test.id}&__xTestRequestNumber=${\n isRecording ? test.mock++ : test.request++\n }`;\n request.url = request.url + queryForTest;\n\n request.mode = 'cors';\n request.credentials = 'omit';\n request.referrerPolicy = '';\n\n try {\n return await next(request);\n } catch (e) {\n if (e instanceof Error && !(e instanceof DOMException)) {\n e.message = e.message.replace(queryForTest, '');\n }\n throw e;\n }\n }\n}\n\nexport async function mock(owner: object, generate: ScaffoldGenerator, isRecording?: boolean) {\n const test = TEST_IDS.get(owner);\n if (!test) {\n throw new Error(`Cannot call \"mock\" before configuring a testId. Use setTestId to set the testId for each test`);\n }\n const testMockNum = test.mock++;\n if (getIsRecording() || isRecording) {\n const url = `https://localhost:1135/__record?__xTestId=${test.id}&__xTestRequestNumber=${testMockNum}`;\n await fetch(url, {\n method: 'POST',\n body: JSON.stringify(generate()),\n mode: 'cors',\n credentials: 'omit',\n referrerPolicy: '',\n });\n }\n}\n"],"names":["TEST_IDS","WeakMap","setTestId","context","str","has","Error","set","id","request","mock","delete","IS_RECORDING","setIsRecording","value","Boolean","getIsRecording","MockServerHandler","constructor","owner","next","test","get","Object","assign","isRecording","url","endsWith","firstChar","includes","queryForTest","mode","credentials","referrerPolicy","e","DOMException","message","replace","generate","testMockNum","fetch","method","body","JSON","stringify"],"mappings":"AAIA,MAAMA,QAAQ,GAAG,IAAIC,OAAO,EAAyD,CAAA;AAE9E,SAASC,SAASA,CAACC,OAAe,EAAEC,GAAkB,EAAE;EAC7D,IAAIA,GAAG,IAAIJ,QAAQ,CAACK,GAAG,CAACF,OAAO,CAAC,EAAE;AAChC,IAAA,MAAM,IAAIG,KAAK,CAAE,CAAA,sDAAA,CAAuD,CAAC,CAAA;AAC3E,GAAA;AACA,EAAA,IAAIF,GAAG,EAAE;AACPJ,IAAAA,QAAQ,CAACO,GAAG,CAACJ,OAAO,EAAE;AAAEK,MAAAA,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QAAQ,EAAE,CAAC;AAChCP,MAAAA,IAAI,EAAE,MAAM;AACZC,MAAAA,WAAW,EAAE,MAAM;AACnBC,MAAAA,cAAc,EAAE,EAAA;AAClB,KAAC,CAAC,CAAA;AACJ,GAAA;AACF;;;;"}
1
+ {"version":3,"file":"index.js","sources":["../src/index.ts"],"sourcesContent":["import type { Handler, NextFn, RequestContext, RequestInfo, StructuredDataDocument } from '@ember-data/request';\n\nimport type { ScaffoldGenerator } from './mock';\n\nconst TEST_IDS = new WeakMap<object, { id: string; request: number; mock: number }>();\n\nlet HOST = 'https://localhost:1135/';\nexport function setConfig({ host }: { host: string }) {\n HOST = host.endsWith('/') ? host : `${host}/`;\n}\n\nexport function setTestId(context: object, str: string | null) {\n if (str && TEST_IDS.has(context)) {\n throw new Error(`MockServerHandler is already configured with a testId.`);\n }\n if (str) {\n TEST_IDS.set(context, { id: str, request: 0, mock: 0 });\n } else {\n TEST_IDS.delete(context);\n }\n}\n\nlet IS_RECORDING = false;\nexport function setIsRecording(value: boolean) {\n IS_RECORDING = Boolean(value);\n}\nexport function getIsRecording() {\n return IS_RECORDING;\n}\n\nexport class MockServerHandler implements Handler {\n declare owner: object;\n constructor(owner: object) {\n this.owner = owner;\n }\n async request<T>(context: RequestContext, next: NextFn<T>): Promise<StructuredDataDocument<T>> {\n const test = TEST_IDS.get(this.owner);\n if (!test) {\n throw new Error(\n `MockServerHandler is not configured with a testId. Use setTestId to set the testId for each test`\n );\n }\n\n const request: RequestInfo = Object.assign({}, context.request);\n const isRecording = request.url!.endsWith('/__record');\n const firstChar = request.url!.includes('?') ? '&' : '?';\n const queryForTest = `${firstChar}__xTestId=${test.id}&__xTestRequestNumber=${\n isRecording ? test.mock++ : test.request++\n }`;\n request.url = request.url + queryForTest;\n\n request.mode = 'cors';\n request.credentials = 'omit';\n request.referrerPolicy = '';\n\n try {\n const future = next(request);\n context.setStream(future.getStream());\n return await future;\n } catch (e) {\n if (e instanceof Error && !(e instanceof DOMException)) {\n e.message = e.message.replace(queryForTest, '');\n }\n throw e;\n }\n }\n}\n\nexport async function mock(owner: object, generate: ScaffoldGenerator, isRecording?: boolean) {\n const test = TEST_IDS.get(owner);\n if (!test) {\n throw new Error(`Cannot call \"mock\" before configuring a testId. Use setTestId to set the testId for each test`);\n }\n const testMockNum = test.mock++;\n if (getIsRecording() || isRecording) {\n const port = window.location.port ? `:${window.location.port}` : '';\n const url = `${HOST}__record?__xTestId=${test.id}&__xTestRequestNumber=${testMockNum}`;\n await fetch(url, {\n method: 'POST',\n body: JSON.stringify(generate()),\n mode: 'cors',\n credentials: 'omit',\n referrerPolicy: '',\n });\n }\n}\n"],"names":["TEST_IDS","WeakMap","HOST","setConfig","host","endsWith","setTestId","context","str","has","Error","set","id","request","mock","delete","IS_RECORDING","setIsRecording","value","Boolean","getIsRecording","MockServerHandler","constructor","owner","next","test","get","Object","assign","isRecording","url","firstChar","includes","queryForTest","mode","credentials","referrerPolicy","future","setStream","getStream","e","DOMException","message","replace","generate","testMockNum","fetch","method","body","JSON","stringify"],"mappings":"AAIA,MAAMA,QAAQ,GAAG,IAAIC,OAAO,EAAyD,CAAA;AAErF,IAAIC,IAAI,GAAG,yBAAyB,CAAA;AAC7B,SAASC,SAASA,CAAC;AAAEC,EAAAA,IAAAA;AAAuB,CAAC,EAAE;AACpDF,EAAAA,IAAI,GAAGE,IAAI,CAACC,QAAQ,CAAC,GAAG,CAAC,GAAGD,IAAI,GAAI,CAAEA,EAAAA,IAAK,CAAE,CAAA,CAAA,CAAA;AAC/C,CAAA;AAEO,SAASE,SAASA,CAACC,OAAe,EAAEC,GAAkB,EAAE;EAC7D,IAAIA,GAAG,IAAIR,QAAQ,CAACS,GAAG,CAACF,OAAO,CAAC,EAAE;AAChC,IAAA,MAAM,IAAIG,KAAK,CAAE,CAAA,sDAAA,CAAuD,CAAC,CAAA;AAC3E,GAAA;AACA,EAAA,IAAIF,GAAG,EAAE;AACPR,IAAAA,QAAQ,CAACW,GAAG,CAACJ,OAAO,EA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AAwBiC,sBAAAA,EAAAA,WAAY,CAAC,CAAA,CAAA;IACtF,MAAMC,KAAK,CAAChB,GAAG,EAAE;AACfiB,MAAAA,MAAM,EAAE,MAAM;MACdC,IAAI,EAAEC,IAAI,CAACC,SAAS,CAACN,QAAQ,EAAE,CAAC;AAChCV,MAAAA,IAAI,EAAE,MAAM;AACZC,MAAAA,WAAW,EAAE,MAAM;AACnBC,MAAAA,cAAc,EAAE,EAAA;AAClB,KAAC,CAAC,CAAA;AACJ,GAAA;AACF;;;;"}
package/dist/mock.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"mock.js","sources":["../client/mock.ts"],"sourcesContent":["import { getIsRecording, mock } from '.';\n\nexport interface Scaffold {\n status: number;\n statusText?: string;\n headers: Record<string, string>;\n body: Record<string, string> | string | null;\n method: string;\n url: string;\n response: Record<string, unknown>;\n}\n\nexport type ScaffoldGenerator = () => Scaffold;\nexport type ResponseGenerator = () => Record<string, unknown>;\n\n/**\n * Sets up Mocking for a GET request on the mock server\n * for the supplied url.\n *\n * The response body is generated by the supplied response function.\n *\n * Available options:\n * - status: the status code to return (default: 200)\n * - headers: the headers to return (default: {})\n * - body: the body to match against for the request (default: null)\n * - RECORD: whether to record the request (default: false)\n *\n * @param url the url to mock, relative to the mock server host (e.g. `users/1`)\n * @param response a function which generates the response to return\n * @param options status, headers for the response, body to match against for the request, and whether to record the request\n * @return\n */\nexport function GET(\n owner: object,\n url: string,\n response: ResponseGenerator,\n options?: Partial<Omit<Scaffold, 'response' | 'url' | 'method'>> & { RECORD?: boolean }\n): Promise<void> {\n return mock(\n owner,\n () => ({\n status: options?.status ?? 200,\n statusText: options?.statusText ?? 'OK',\n headers: options?.headers ?? {},\n body: options?.body ?? null,\n method: 'GET',\n url,\n response: response(),\n }),\n getIsRecording() || (options?.RECORD ?? false)\n );\n}\nexport function POST() {}\nexport function PUT() {}\nexport function PATCH() {}\nexport function DELETE() {}\nexport function QUERY() {}\n"],"names":["GET","owner","url","response","options","mock","status","statusText","headers","body","method","getIsRecording","RECORD","POST","PUT","PATCH","DELETE","QUERY"],"mappings":";;AAeA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,SAASA,GAAGA,CACjBC,KAAa,EACbC,GAAW,EACXC,QAA2B,EAC3BC,OAAuF,EACxE;AACf,EAAA,OAAOC,IAAI,CACTJ,KAAK,EACL,OAAO;AACLK,IAAAA,MAAM,EAAEF,OAAO,EAAEE,MAAM,IAAI,GAAG;AAC9BC,IAAAA,UAAU,EAAEH,OAAO,EAAEG,UAAU,IAAI,IAAI;AACvCC,IAAAA,OAAO,EAAEJ,OAAO,EAAEI,OAAO,IAAI,EAAE;AAC/BC,IAAAA,IAAI,EAAEL,OAAO,EAAEK,IAAI,IAAI,IAAI;AAC3BC,IAAAA,MAAM,EAAE,KAAK;IACbR,GAAG;IACHC,QAAQ,EAAEA,QAAQ,EAAC;AACrB,GAAC,CAAC,EACFQ,cAAc,EAAE,KAAKP,OAAO,EAAEQ,MAAM,IAAI,KAAK,CAC/C,CAAC,CAAA;AACH,CAAA;AACO,SAASC,IAAIA,GAAG,EAAC;AACjB,SAASC,GAAGA,GAAG,EAAC;AAChB,SAASC,KAAKA,GAAG,EAAC;AAClB,SAASC,MAAMA,GAAG,EAAC;AACnB,SAASC,KAAKA,GAAG;;;;"}
1
+ {"version":3,"file":"mock.js","sources":["../src/mock.ts"],"sourcesContent":["import { getIsRecording, mock } from '.';\n\nexport interface Scaffold {\n status: number;\n statusText?: string;\n headers: Record<string, string>;\n body: Record<string, string> | string | null;\n method: string;\n url: string;\n response: Record<string, unknown>;\n}\n\nexport type ScaffoldGenerator = () => Scaffold;\nexport type ResponseGenerator = () => Record<string, unknown>;\n\n/**\n * Sets up Mocking for a GET request on the mock server\n * for the supplied url.\n *\n * The response body is generated by the supplied response function.\n *\n * Available options:\n * - status: the status code to return (default: 200)\n * - headers: the headers to return (default: {})\n * - body: the body to match against for the request (default: null)\n * - RECORD: whether to record the request (default: false)\n *\n * @param url the url to mock, relative to the mock server host (e.g. `users/1`)\n * @param response a function which generates the response to return\n * @param options status, headers for the response, body to match against for the request, and whether to record the request\n * @return\n */\nexport function GET(\n owner: object,\n url: string,\n response: ResponseGenerator,\n options?: Partial<Omit<Scaffold, 'response' | 'url' | 'method'>> & { RECORD?: boolean }\n): Promise<void> {\n return mock(\n owner,\n () => ({\n status: options?.status ?? 200,\n statusText: options?.statusText ?? 'OK',\n headers: options?.headers ?? {},\n body: options?.body ?? null,\n method: 'GET',\n url,\n response: response(),\n }),\n getIsRecording() || (options?.RECORD ?? false)\n );\n}\nexport function POST() {}\nexport function PUT() {}\nexport function PATCH() {}\nexport function DELETE() {}\nexport function QUERY() {}\n"],"names":["GET","owner","url","response","options","mock","status","statusText","headers","body","method","getIsRecording","RECORD","POST","PUT","PATCH","DELETE","QUERY"],"mappings":";;AAeA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,SAASA,GAAGA,CACjBC,KAAa,EACbC,GAAW,EACXC,QAA2B,EAC3BC,OAAuF,EACxE;AACf,EAAA,OAAOC,IAAI,CACTJ,KAAK,EACL,OAAO;AACLK,IAAAA,MAAM,EAAEF,OAAO,EAAEE,MAAM,IAAI,GAAG;AAC9BC,IAAAA,UAAU,EAAEH,OAAO,EAAEG,UAAU,IAAI,IAAI;AACvCC,IAAAA,OAAO,EAAEJ,OAAO,EAAEI,OAAO,IAAI,EAAE;AAC/BC,IAAAA,IAAI,EAAEL,OAAO,EAAEK,IAAI,IAAI,IAAI;AAC3BC,IAAAA,MAAM,EAAE,KAAK;IACbR,GAAG;IACHC,QAAQ,EAAEA,QAAQ,EAAC;AACrB,GAAC,CAAC,EACFQ,cAAc,EAAE,KAAKP,OAAO,EAAEQ,MAAM,IAAI,KAAK,CAC/C,CAAC,CAAA;AACH,CAAA;AACO,SAASC,IAAIA,GAAG,EAAC;AACjB,SAASC,GAAGA,GAAG,EAAC;AAChB,SAASC,KAAKA,GAAG,EAAC;AAClB,SAASC,MAAMA,GAAG,EAAC;AACnB,SAASC,KAAKA,GAAG;;;;"}
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@warp-drive/holodeck",
3
3
  "description": "⚡️ Simple, Fast HTTP Mocking for Tests",
4
- "version": "0.0.0-alpha.8",
4
+ "version": "0.0.0-alpha.83",
5
5
  "license": "MIT",
6
6
  "author": "Chris Thoburn <runspired@users.noreply.github.com>",
7
7
  "repository": {
@@ -12,7 +12,7 @@
12
12
  "homepage": "https://github.com/emberjs/data",
13
13
  "bugs": "https://github.com/emberjs/data/issues",
14
14
  "engines": {
15
- "node": ">= 20.11.0"
15
+ "node": ">= 18.20.3"
16
16
  },
17
17
  "keywords": [
18
18
  "http-mock"
@@ -21,12 +21,11 @@
21
21
  "extends": "../../package.json"
22
22
  },
23
23
  "dependencies": {
24
- "@hono/node-server": "^1.3.3",
25
- "chalk": "^4.1.2",
26
- "hono": "^3.11.3",
27
- "pm2": "^5.3.1",
28
- "pnpm-sync-dependencies-meta-injected": "0.0.10"
24
+ "@hono/node-server": "^1.11.1",
25
+ "chalk": "^5.3.0",
26
+ "hono": "^4.3.6"
29
27
  },
28
+ "type": "module",
30
29
  "files": [
31
30
  "bin",
32
31
  "dist",
@@ -37,30 +36,30 @@
37
36
  "NCC-1701-a-blue.svg"
38
37
  ],
39
38
  "bin": {
40
- "holodeck": "./bin/holodeck.js"
39
+ "ensure-cert": "./server/ensure-cert.js"
40
+ },
41
+ "scripts": {
42
+ "check:pkg-types": "tsc --noEmit",
43
+ "build:pkg": "vite build;",
44
+ "sync-hardlinks": "bun run sync-dependencies-meta-injected"
41
45
  },
42
46
  "peerDependencies": {
43
- "@ember-data/request": "5.4.0-alpha.22",
44
- "@warp-drive/core-types": "0.0.0-alpha.8"
47
+ "@ember-data/request": "5.4.0-alpha.97",
48
+ "@warp-drive/core-types": "0.0.0-alpha.83"
45
49
  },
46
50
  "devDependencies": {
47
- "@babel/cli": "^7.23.4",
48
- "@babel/core": "^7.23.7",
49
- "@babel/plugin-transform-typescript": "^7.23.6",
50
- "@babel/preset-env": "^7.23.8",
51
- "@babel/preset-typescript": "^7.23.3",
52
- "@babel/runtime": "^7.23.8",
53
- "@ember-data/request": "5.4.0-alpha.22",
54
- "@embroider/addon-dev": "^4.1.2",
55
- "@rollup/plugin-babel": "^6.0.4",
56
- "@rollup/plugin-node-resolve": "^15.2.3",
57
- "@warp-drive/core-types": "0.0.0-alpha.8",
58
- "@warp-drive/internal-config": "5.4.0-alpha.22",
59
- "rollup": "^4.9.6",
60
- "typescript": "^5.3.3",
61
- "walk-sync": "^3.0.0"
51
+ "@babel/core": "^7.24.5",
52
+ "@babel/plugin-transform-typescript": "^7.24.5",
53
+ "@babel/preset-env": "^7.24.5",
54
+ "@babel/preset-typescript": "^7.24.1",
55
+ "@babel/runtime": "^7.24.5",
56
+ "@ember-data/request": "5.4.0-alpha.97",
57
+ "@warp-drive/core-types": "0.0.0-alpha.83",
58
+ "@warp-drive/internal-config": "5.4.0-alpha.97",
59
+ "pnpm-sync-dependencies-meta-injected": "0.0.14",
60
+ "typescript": "^5.4.5",
61
+ "vite": "^5.2.11"
62
62
  },
63
- "type": "module",
64
63
  "exports": {
65
64
  ".": {
66
65
  "node": "./server/index.js",
@@ -85,12 +84,5 @@
85
84
  "@warp-drive/core-types": {
86
85
  "injected": true
87
86
  }
88
- },
89
- "scripts": {
90
- "build:types": "echo \"Types are private\" && exit 0",
91
- "build:client": "rollup --config",
92
- "_build": "bun run build:client && bun run build:types",
93
- "start": "rollup --config --watch",
94
- "_syncPnpm": "bun run sync-dependencies-meta-injected"
95
87
  }
96
- }
88
+ }
@@ -0,0 +1,55 @@
1
+ #!/usr/bin/env node
2
+ import { execSync } from 'node:child_process';
3
+ import fs from 'node:fs';
4
+ import { homedir, userInfo } from 'os';
5
+ import path from 'path';
6
+
7
+ function getShellConfigFilePath() {
8
+ const shell = userInfo().shell;
9
+ switch (shell) {
10
+ case '/bin/zsh':
11
+ return path.join(homedir(), '.zshrc');
12
+ case '/bin/bash':
13
+ return path.join(homedir(), '.bashrc');
14
+ default:
15
+ throw Error(
16
+ `Unable to determine configuration file for shell: ${shell}. Manual SSL Cert Setup Required for Holodeck.`
17
+ );
18
+ }
19
+ }
20
+
21
+ function main() {
22
+ let CERT_PATH = process.env.HOLODECK_SSL_CERT_PATH;
23
+ let KEY_PATH = process.env.HOLODECK_SSL_KEY_PATH;
24
+ const configFilePath = getShellConfigFilePath();
25
+
26
+ if (!CERT_PATH) {
27
+ CERT_PATH = path.join(homedir(), 'holodeck-localhost.pem');
28
+ process.env.HOLODECK_SSL_CERT_PATH = CERT_PATH;
29
+ execSync(`echo '\nexport HOLODECK_SSL_CERT_PATH="${CERT_PATH}"' >> ${configFilePath}`);
30
+ console.log(`Added HOLODECK_SSL_CERT_PATH to ${configFilePath}`);
31
+ }
32
+
33
+ if (!KEY_PATH) {
34
+ KEY_PATH = path.join(homedir(), 'holodeck-localhost-key.pem');
35
+ process.env.HOLODECK_SSL_KEY_PATH = KEY_PATH;
36
+ execSync(`echo '\nexport HOLODECK_SSL_KEY_PATH="${KEY_PATH}"' >> ${configFilePath}`);
37
+ console.log(`Added HOLODECK_SSL_KEY_PATH to ${configFilePath}`);
38
+ }
39
+
40
+ if (!fs.existsSync(CERT_PATH) || !fs.existsSync(KEY_PATH)) {
41
+ console.log('SSL certificate or key not found, generating new ones...');
42
+
43
+ execSync(`mkcert -install`);
44
+ execSync(`mkcert -key-file ${KEY_PATH} -cert-file ${CERT_PATH} localhost`);
45
+
46
+ console.log('SSL certificate and key generated.');
47
+ } else {
48
+ console.log('SSL certificate and key found, using existing.');
49
+ }
50
+
51
+ console.log(`Certificate path: ${CERT_PATH}`);
52
+ console.log(`Key path: ${KEY_PATH}`);
53
+ }
54
+
55
+ main();
package/server/index.js CHANGED
@@ -1,16 +1,67 @@
1
+ /* global Bun */
1
2
  import { serve } from '@hono/node-server';
3
+ import chalk from 'chalk';
2
4
  import { Hono } from 'hono';
3
5
  import { cors } from 'hono/cors';
6
+ import { HTTPException } from 'hono/http-exception';
4
7
  import { logger } from 'hono/logger';
8
+ import { execSync } from 'node:child_process';
5
9
  import crypto from 'node:crypto';
6
10
  import fs from 'node:fs';
7
11
  import http2 from 'node:http2';
8
- import { dirname } from 'node:path';
9
12
  import zlib from 'node:zlib';
10
- import { fileURLToPath } from 'url';
11
- import { HTTPException } from 'hono/http-exception';
13
+ import { homedir, userInfo } from 'os';
14
+ import path from 'path';
15
+
16
+ /** @type {import('bun-types')} */
17
+ const isBun = typeof Bun !== 'undefined';
18
+ const DEBUG = process.env.DEBUG?.includes('holodeck') || process.env.DEBUG === '*';
19
+ const CURRENT_FILE = new URL(import.meta.url).pathname;
20
+
21
+ function getShellConfigFilePath() {
22
+ const shell = userInfo().shell;
23
+ switch (shell) {
24
+ case '/bin/zsh':
25
+ return path.join(homedir(), '.zshrc');
26
+ case '/bin/bash':
27
+ return path.join(homedir(), '.bashrc');
28
+ default:
29
+ throw Error(
30
+ `Unable to determine configuration file for shell: ${shell}. Manual SSL Cert Setup Required for Holodeck.`
31
+ );
32
+ }
33
+ }
12
34
 
13
- const __dirname = dirname(fileURLToPath(import.meta.url));
35
+ function getCertInfo() {
36
+ let CERT_PATH = process.env.HOLODECK_SSL_CERT_PATH;
37
+ let KEY_PATH = process.env.HOLODECK_SSL_KEY_PATH;
38
+ const configFilePath = getShellConfigFilePath();
39
+
40
+ if (!CERT_PATH) {
41
+ CERT_PATH = path.join(homedir(), 'holodeck-localhost.pem');
42
+ process.env.HOLODECK_SSL_CERT_PATH = CERT_PATH;
43
+ execSync(`echo '\nexport HOLODECK_SSL_CERT_PATH="${CERT_PATH}"' >> ${configFilePath}`);
44
+ console.log(`Added HOLODECK_SSL_CERT_PATH to ${configFilePath}`);
45
+ }
46
+
47
+ if (!KEY_PATH) {
48
+ KEY_PATH = path.join(homedir(), 'holodeck-localhost-key.pem');
49
+ process.env.HOLODECK_SSL_KEY_PATH = KEY_PATH;
50
+ execSync(`echo '\nexport HOLODECK_SSL_KEY_PATH="${KEY_PATH}"' >> ${configFilePath}`);
51
+ console.log(`Added HOLODECK_SSL_KEY_PATH to ${configFilePath}`);
52
+ }
53
+
54
+ if (!fs.existsSync(CERT_PATH) || !fs.existsSync(KEY_PATH)) {
55
+ throw new Error('SSL certificate or key not found, you may need to run `npx -p @warp-drive/holodeck ensure-cert`');
56
+ }
57
+
58
+ return {
59
+ CERT_PATH,
60
+ KEY_PATH,
61
+ CERT: fs.readFileSync(CERT_PATH),
62
+ KEY: fs.readFileSync(KEY_PATH),
63
+ };
64
+ }
14
65
 
15
66
  const DEFAULT_PORT = 1135;
16
67
  const BROTLI_OPTIONS = {
@@ -196,7 +247,9 @@ function createTestHandler(projectRoot) {
196
247
  */
197
248
  export function createServer(options) {
198
249
  const app = new Hono();
199
- app.use('*', logger());
250
+ if (DEBUG) {
251
+ app.use('*', logger());
252
+ }
200
253
  app.use(
201
254
  '*',
202
255
  cors({
@@ -211,18 +264,112 @@ export function createServer(options) {
211
264
  );
212
265
  app.all('*', createTestHandler(options.projectRoot));
213
266
 
267
+ const { CERT, KEY } = getCertInfo();
268
+
214
269
  serve({
215
270
  fetch: app.fetch,
216
271
  createServer: (_, requestListener) => {
217
- return http2.createSecureServer(
218
- {
219
- key: fs.readFileSync(`${__dirname}/localhost-key.pem`),
220
- cert: fs.readFileSync(`${__dirname}/localhost.pem`),
221
- },
222
- requestListener
223
- );
272
+ try {
273
+ return http2.createSecureServer(
274
+ {
275
+ key: KEY,
276
+ cert: CERT,
277
+ },
278
+ requestListener
279
+ );
280
+ } catch (e) {
281
+ console.log(chalk.yellow(`Failed to create secure server, falling back to http server. Error: ${e.message}`));
282
+ return http2.createServer(requestListener);
283
+ }
224
284
  },
225
285
  port: options.port ?? DEFAULT_PORT,
226
286
  hostname: 'localhost',
287
+ // bun uses TLS options
288
+ // tls: {
289
+ // key: Bun.file(KEY_PATH),
290
+ // cert: Bun.file(CERT_PATH),
291
+ // },
227
292
  });
293
+
294
+ console.log(
295
+ `\tMock server running at ${chalk.magenta('https://localhost:') + chalk.yellow(options.port ?? DEFAULT_PORT)}`
296
+ );
228
297
  }
298
+
299
+ const servers = new Map();
300
+
301
+ export default {
302
+ async launchProgram(config = {}) {
303
+ const projectRoot = process.cwd();
304
+ const name = await import(path.join(projectRoot, 'package.json'), { with: { type: 'json' } }).then(
305
+ (pkg) => pkg.name
306
+ );
307
+ const options = { name, projectRoot, ...config };
308
+ console.log(
309
+ chalk.grey(
310
+ `\n\t@${chalk.greenBright('warp-drive')}/${chalk.magentaBright(
311
+ 'holodeck'
312
+ )} 🌅\n\t=================================\n`
313
+ ) +
314
+ chalk.grey(
315
+ `\n\tHolodeck Access Granted\n\t\tprogram: ${chalk.magenta(name)}\n\t\tsettings: ${chalk.green(JSON.stringify(config).split('\n').join(' '))}\n\t\tdirectory: ${chalk.cyan(projectRoot)}\n\t\tengine: ${chalk.cyan(
316
+ isBun ? 'bun@' + Bun.version : 'node'
317
+ )}`
318
+ )
319
+ );
320
+ console.log(chalk.grey(`\n\tStarting Subroutines (mode:${chalk.cyan(isBun ? 'bun' : 'node')})`));
321
+
322
+ if (isBun) {
323
+ const serverProcess = Bun.spawn(
324
+ ['node', '--experimental-default-type=module', CURRENT_FILE, JSON.stringify(options)],
325
+ {
326
+ env: process.env,
327
+ cwd: process.cwd(),
328
+ stdout: 'inherit',
329
+ stderr: 'inherit',
330
+ }
331
+ );
332
+ servers.set(projectRoot, serverProcess);
333
+ return;
334
+ }
335
+
336
+ if (servers.has(projectRoot)) {
337
+ throw new Error(`Holodeck is already running for project '${name}' at '${projectRoot}'`);
338
+ }
339
+
340
+ servers.set(projectRoot, createServer(options));
341
+ },
342
+ async endProgram() {
343
+ console.log(chalk.grey(`\n\tEnding Subroutines (mode:${chalk.cyan(isBun ? 'bun' : 'node')})`));
344
+ const projectRoot = process.cwd();
345
+
346
+ if (!servers.has(projectRoot)) {
347
+ const name = await import(path.join(projectRoot, 'package.json'), { with: { type: 'json' } }).then(
348
+ (pkg) => pkg.name
349
+ );
350
+ throw new Error(`Holodeck was not running for project '${name}' at '${projectRoot}'`);
351
+ }
352
+
353
+ if (isBun) {
354
+ const serverProcess = servers.get(projectRoot);
355
+ serverProcess.kill();
356
+ return;
357
+ }
358
+
359
+ servers.get(projectRoot).close();
360
+ servers.delete(projectRoot);
361
+ },
362
+ };
363
+
364
+ function main() {
365
+ const args = process.argv.slice();
366
+ if (!isBun && args.length) {
367
+ if (args[1] !== CURRENT_FILE) {
368
+ return;
369
+ }
370
+ const options = JSON.parse(args[2]);
371
+ createServer(options);
372
+ }
373
+ }
374
+
375
+ main();
package/bin/cmd/_start.js DELETED
@@ -1,3 +0,0 @@
1
- import pm2 from './pm2.js';
2
-
3
- await pm2('start', process.argv.slice(2));
package/bin/cmd/_stop.js DELETED
@@ -1,3 +0,0 @@
1
- import pm2 from './pm2.js';
2
-
3
- await pm2('stop', process.argv.slice(2));
package/bin/cmd/pm2.js DELETED
@@ -1,38 +0,0 @@
1
- /* eslint-disable no-console */
2
- /* global Bun, globalThis */
3
- const { process } = globalThis;
4
- import pm2 from 'pm2';
5
- import fs from 'fs';
6
-
7
- export default async function pm2Delegate(cmd, _args) {
8
- const pkg = JSON.parse(fs.readFileSync('./package.json'), 'utf8');
9
-
10
- return new Promise((resolve, reject) => {
11
- pm2.connect((err) => {
12
- if (err) {
13
- console.log('not able to connect to pm2');
14
- console.error(err);
15
- process.exit(2);
16
- }
17
-
18
- const options = {
19
- script: './holodeck.mjs',
20
- name: pkg.name + '::holodeck',
21
- cwd: process.cwd(),
22
- args: cmd === 'start' ? '-f' : '',
23
- };
24
-
25
- pm2[cmd](cmd === 'start' ? options : options.name, (err, apps) => {
26
- pm2.disconnect(); // Disconnects from PM2
27
- if (err) {
28
- console.log(`not able to ${cmd} pm2 for ${options.name}`);
29
- console.error(err);
30
- reject(err);
31
- } else {
32
- console.log(`pm2 ${cmd} successful for ${options.name}`);
33
- resolve();
34
- }
35
- });
36
- });
37
- });
38
- }
package/bin/cmd/run.js DELETED
@@ -1,50 +0,0 @@
1
- /* eslint-disable no-console */
2
- /* global Bun, globalThis */
3
- const isBun = typeof Bun !== 'undefined';
4
- const { process } = globalThis;
5
- import { spawn } from './spawn.js';
6
- import fs from 'fs';
7
-
8
- export default async function run(args) {
9
- const pkg = JSON.parse(fs.readFileSync('./package.json'), 'utf8');
10
- const cmd = args[0];
11
- const isPkgScript = pkg.scripts[cmd];
12
-
13
- if (isBun) {
14
- await spawn(['bun', 'run', 'holodeck:start-program']);
15
-
16
- let exitCode = 0;
17
- try {
18
- await spawn(['bun', 'run', ...args]);
19
- } catch (e) {
20
- exitCode = e;
21
- }
22
- await spawn(['bun', 'run', 'holodeck:end-program']);
23
- if (exitCode !== 0) {
24
- process.exit(exitCode);
25
- }
26
- return;
27
- } else {
28
- await spawn(['pnpm', 'run', 'holodeck:start-program']);
29
-
30
- let exitCode = 0;
31
- try {
32
- if (isPkgScript) {
33
- const cmdArgs = pkg.scripts[cmd].split(' ');
34
- if (args.length > 1) {
35
- cmdArgs.push(...args.slice(1));
36
- }
37
- console.log({ cmdArgs });
38
- await spawn(cmdArgs);
39
- } else {
40
- await spawn(['pnpm', 'exec', ...args]);
41
- }
42
- } catch (e) {
43
- exitCode = e;
44
- }
45
- await spawn(['pnpm', 'run', 'holodeck:end-program']);
46
- if (exitCode !== 0) {
47
- process.exit(exitCode);
48
- }
49
- }
50
- }
package/bin/cmd/spawn.js DELETED
@@ -1,40 +0,0 @@
1
- /* eslint-disable no-console */
2
- /* global Bun, globalThis */
3
- const isBun = typeof Bun !== 'undefined';
4
-
5
- export async function spawn(args, options) {
6
- if (isBun) {
7
- const proc = Bun.spawn(args, {
8
- env: process.env,
9
- cwd: process.cwd(),
10
- stdout: 'inherit',
11
- stderr: 'inherit',
12
- });
13
- await proc.exited;
14
- if (proc.exitCode !== 0) {
15
- throw proc.exitCode;
16
- }
17
- return;
18
- }
19
-
20
- const { spawn } = await import('node:child_process');
21
-
22
- // eslint-disable-next-line no-inner-declarations
23
- function pSpawn(cmd, args, opts) {
24
- return new Promise((resolve, reject) => {
25
- const proc = spawn(cmd, args, opts);
26
- proc.on('exit', (code) => {
27
- if (code === 0) {
28
- resolve();
29
- } else {
30
- reject(code);
31
- }
32
- });
33
- });
34
- }
35
-
36
- await pSpawn(args.shift(), args, {
37
- stdio: 'inherit',
38
- shell: true,
39
- });
40
- }
package/bin/holodeck.js DELETED
@@ -1,63 +0,0 @@
1
- #!/bin/sh -
2
- ':'; /*-
3
- test1=$(bun --version 2>&1) && exec bun "$0" "$@"
4
- test2=$(node --version 2>&1) && exec node "$0" "$@"
5
- exec printf '%s\n' "$test1" "$test2" 1>&2
6
- */
7
- /* eslint-disable no-console */
8
- /* global Bun, globalThis */
9
-
10
- import chalk from 'chalk';
11
- import { spawn } from './cmd/spawn.js';
12
-
13
- const isBun = typeof Bun !== 'undefined';
14
- const { process } = globalThis;
15
-
16
- const args = isBun ? Bun.argv.slice(2) : process.argv.slice(2);
17
- const command = args.shift();
18
-
19
- const BUN_SUPPORTS_PM2 = false;
20
- const BUN_SUPPORTS_HTTP2 = false;
21
-
22
- if (command === 'run') {
23
- console.log(
24
- chalk.grey(
25
- `\n\t@${chalk.greenBright('warp-drive')}/${chalk.magentaBright(
26
- 'holodeck'
27
- )} 🌅\n\t=================================}\n`
28
- ) +
29
- chalk.grey(
30
- `\n\tHolodeck Access Granted\n\t\tprogram: ${chalk.green(args.join(' '))}\n\t\tengine: ${chalk.cyan(
31
- isBun ? 'bun@' + Bun.version : 'node'
32
- )}`
33
- )
34
- );
35
- const run = await import('./cmd/run.js');
36
- await run.default(args);
37
- } else if (command === 'start') {
38
- console.log(chalk.grey(`\n\tStarting Subroutines (mode:${chalk.cyan(isBun ? 'bun' : 'node')})`));
39
-
40
- if (!isBun || (BUN_SUPPORTS_HTTP2 && BUN_SUPPORTS_PM2)) {
41
- const pm2 = await import('./cmd/pm2.js');
42
- await pm2.default('start', args);
43
- } else {
44
- console.log(`Downgrading to node to run pm2 due lack of http/2 or pm2 support in Bun`);
45
- const __dirname = import.meta.dir;
46
- const programPath = __dirname + '/cmd/_start.js';
47
- await spawn(['node', programPath, ...args]);
48
- }
49
- } else if (command === 'end') {
50
- console.log(chalk.grey(`\n\tEnding Subroutines (mode:${chalk.cyan(isBun ? 'bun' : 'node')})`));
51
-
52
- if (!isBun || (BUN_SUPPORTS_HTTP2 && BUN_SUPPORTS_PM2)) {
53
- const pm2 = await import('./cmd/pm2.js');
54
- await pm2.default('stop', args);
55
- } else {
56
- console.log(`Downgrading to node to run pm2 due lack of http/2 or pm2 support in Bun`);
57
- const __dirname = import.meta.dir;
58
- const programPath = __dirname + '/cmd/_stop.js';
59
- await spawn(['node', programPath, ...args]);
60
- }
61
-
62
- console.log(`\n\t${chalk.grey('The Computer has ended the program')}\n`);
63
- }
package/server/CERT.md DELETED
@@ -1,3 +0,0 @@
1
- Generated with `mkcert`
2
-
3
- It will expire on 9 January 2026 🗓
@@ -1,28 +0,0 @@
1
- -----BEGIN PRIVATE KEY-----
2
- MIIEvQIBADANBgkqhkiG9w0BAQEFAASCBKcwggSjAgEAAoIBAQCz8yulPBPYYZH+
3
- M+kBVOCSj4EmN7Texxd/DXjOJTTpDI8aophZhfaXZSnTFhLxTEuAUVboU7yGR/JJ
4
- JzL1nTVujR/gjJFrc4PVDeLzWMTJsTQcagdtku9suKC6M74/GlTI4yQC5p+IKRuv
5
- ZisQhacyjpj5s4RoBR2n2aOscIncYtuKTJ570CIt9SFxEaV/WW3PlAG5LGEuqqJR
6
- MwFTXz10IaKOVc/sxV2sYVS1tARydAx27IHKf23FilAu30nnc0ipGZNqFvHNvNed
7
- Ggye+aaCh0WtX99HXs+JKPTfvV4sCDb7KIZq3WjRk7PAaSr6e999kvHuhZpXDUJL
8
- Ynu0FYBZAgMBAAECggEBAJXcluWWAeT7ZO0x6AOe3yPPdTw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