@pithy-sh/vite 0.10.0 → 0.12.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/dist/devOrigin.d.ts +5 -0
- package/dist/devOrigin.d.ts.map +1 -1
- package/dist/devOrigin.js +13 -2
- package/package.json +3 -3
- package/src/devOrigin.ts +13 -2
package/dist/devOrigin.d.ts
CHANGED
|
@@ -46,6 +46,11 @@ export type WorkerVarValue = string | number | boolean | null | WorkerVarValue[]
|
|
|
46
46
|
* checkout signed tokens as the first one and its own seam denied every call, 401, with every stored
|
|
47
47
|
* value agreeing (#462, `pithy-sh/dashboard#95`).
|
|
48
48
|
*
|
|
49
|
+
* **It also hands on where each service binding answers (#617).** `pithy dev` publishes the Worker's
|
|
50
|
+
* {@link SERVICE_ORIGINS_VAR} into this process's environment, for the reason it publishes the origin there:
|
|
51
|
+
* no argv. Passed on as the var of the same name, it is what core's `withLocalServices` reads to send
|
|
52
|
+
* `env.<BINDING>.fetch()` to the target's pinned port. A Worker that binds nothing is handed nothing.
|
|
53
|
+
*
|
|
49
54
|
* **Outside `pithy dev` it does nothing at all.** A plain `vite dev`, a build, or CI has no
|
|
50
55
|
* {@link WORKER_ORIGIN_VAR} in its environment, and the Worker keeps whatever `wrangler.jsonc` says —
|
|
51
56
|
* which for a deployed environment is the value `applyDomains` generated from `domains`, and is
|
package/dist/devOrigin.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"devOrigin.d.ts","sourceRoot":"","sources":["../src/devOrigin.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"devOrigin.d.ts","sourceRoot":"","sources":["../src/devOrigin.ts"],"names":[],"mappings":"AAOA;;;;;;GAMG;AACH,MAAM,WAAW,UAAU;IACzB,mFAAmF;IACnF,IAAI,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,cAAc,CAAC,CAAC;CACvC;AAED;;;;;;;;GAQG;AACH,MAAM,MAAM,cAAc,GAAG,MAAM,GAAG,MAAM,GAAG,OAAO,GAAG,IAAI,GAAG,cAAc,EAAE,GAAG;IAAE,CAAC,GAAG,EAAE,MAAM,GAAG,cAAc,CAAA;CAAE,CAAC;AAErH;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAgCG;AACH,wBAAgB,eAAe,CAAC,GAAG,GAAE,MAAM,CAAC,UAAwB,GAAG,CAAC,MAAM,EAAE,UAAU,KAAK,UAAU,CA4BxG"}
|
package/dist/devOrigin.js
CHANGED
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
// SPDX-License-Identifier: MIT
|
|
3
3
|
import { LOCAL_ENVIRONMENT } from "@pithy-sh/core/src/naming/environment";
|
|
4
4
|
import { ENVIRONMENT_VAR, WORKER_ORIGIN_VAR } from "@pithy-sh/core/src/worker/identity";
|
|
5
|
+
import { SERVICE_ORIGINS_VAR } from "@pithy-sh/core/src/worker/serviceLoopback";
|
|
5
6
|
//#region src/devOrigin.ts
|
|
6
7
|
/**
|
|
7
8
|
* Give the Worker the origin `pithy dev` allocated this checkout, as `BASE_URL`.
|
|
@@ -26,6 +27,11 @@ import { ENVIRONMENT_VAR, WORKER_ORIGIN_VAR } from "@pithy-sh/core/src/worker/id
|
|
|
26
27
|
* checkout signed tokens as the first one and its own seam denied every call, 401, with every stored
|
|
27
28
|
* value agreeing (#462, `pithy-sh/dashboard#95`).
|
|
28
29
|
*
|
|
30
|
+
* **It also hands on where each service binding answers (#617).** `pithy dev` publishes the Worker's
|
|
31
|
+
* {@link SERVICE_ORIGINS_VAR} into this process's environment, for the reason it publishes the origin there:
|
|
32
|
+
* no argv. Passed on as the var of the same name, it is what core's `withLocalServices` reads to send
|
|
33
|
+
* `env.<BINDING>.fetch()` to the target's pinned port. A Worker that binds nothing is handed nothing.
|
|
34
|
+
*
|
|
29
35
|
* **Outside `pithy dev` it does nothing at all.** A plain `vite dev`, a build, or CI has no
|
|
30
36
|
* {@link WORKER_ORIGIN_VAR} in its environment, and the Worker keeps whatever `wrangler.jsonc` says —
|
|
31
37
|
* which for a deployed environment is the value `applyDomains` generated from `domains`, and is
|
|
@@ -34,12 +40,17 @@ import { ENVIRONMENT_VAR, WORKER_ORIGIN_VAR } from "@pithy-sh/core/src/worker/id
|
|
|
34
40
|
function devWorkerConfig(env = process.env) {
|
|
35
41
|
return (config) => {
|
|
36
42
|
const origin = env[WORKER_ORIGIN_VAR];
|
|
37
|
-
|
|
43
|
+
const services = env[SERVICE_ORIGINS_VAR];
|
|
44
|
+
const given = {
|
|
45
|
+
...origin === void 0 || origin.trim() === "" ? {} : { BASE_URL: origin },
|
|
46
|
+
...services === void 0 || services.trim() === "" ? {} : { [SERVICE_ORIGINS_VAR]: services }
|
|
47
|
+
};
|
|
48
|
+
if (Object.keys(given).length === 0) return {};
|
|
38
49
|
const environment = config.vars?.[ENVIRONMENT_VAR];
|
|
39
50
|
if (typeof environment === "string" && environment !== LOCAL_ENVIRONMENT) return {};
|
|
40
51
|
return { vars: {
|
|
41
52
|
...config.vars,
|
|
42
|
-
|
|
53
|
+
...given
|
|
43
54
|
} };
|
|
44
55
|
};
|
|
45
56
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@pithy-sh/vite",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.12.0",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -26,14 +26,14 @@
|
|
|
26
26
|
"scripts": {
|
|
27
27
|
"generate": "bun scripts/generateClientEnv.ts",
|
|
28
28
|
"build": "bun run generate && tsdown && tsc -p tsconfig.build.json && bun ../../tooling/build/src/stampDeclarations.ts",
|
|
29
|
-
"typecheck": "
|
|
29
|
+
"typecheck": "bun check -p tsconfig.json",
|
|
30
30
|
"test": "vitest run",
|
|
31
31
|
"test:node": "vitest run --project=node",
|
|
32
32
|
"clean": "rm -rf dist .turbo",
|
|
33
33
|
"reset": "bun run clean && rm -rf node_modules"
|
|
34
34
|
},
|
|
35
35
|
"peerDependencies": {
|
|
36
|
-
"@pithy-sh/core": "^0.
|
|
36
|
+
"@pithy-sh/core": "^0.12.0",
|
|
37
37
|
"vite": "^6.1.0 || ^7.0.0 || ^8.0.0"
|
|
38
38
|
},
|
|
39
39
|
"devDependencies": {
|
package/src/devOrigin.ts
CHANGED
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
|
|
4
4
|
import { LOCAL_ENVIRONMENT } from "@pithy-sh/core/src/naming/environment";
|
|
5
5
|
import { ENVIRONMENT_VAR, WORKER_ORIGIN_VAR } from "@pithy-sh/core/src/worker/identity";
|
|
6
|
+
import { SERVICE_ORIGINS_VAR } from "@pithy-sh/core/src/worker/serviceLoopback";
|
|
6
7
|
|
|
7
8
|
/**
|
|
8
9
|
* The slice of `@cloudflare/vite-plugin`'s worker config this touches.
|
|
@@ -50,6 +51,11 @@ export type WorkerVarValue = string | number | boolean | null | WorkerVarValue[]
|
|
|
50
51
|
* checkout signed tokens as the first one and its own seam denied every call, 401, with every stored
|
|
51
52
|
* value agreeing (#462, `pithy-sh/dashboard#95`).
|
|
52
53
|
*
|
|
54
|
+
* **It also hands on where each service binding answers (#617).** `pithy dev` publishes the Worker's
|
|
55
|
+
* {@link SERVICE_ORIGINS_VAR} into this process's environment, for the reason it publishes the origin there:
|
|
56
|
+
* no argv. Passed on as the var of the same name, it is what core's `withLocalServices` reads to send
|
|
57
|
+
* `env.<BINDING>.fetch()` to the target's pinned port. A Worker that binds nothing is handed nothing.
|
|
58
|
+
*
|
|
53
59
|
* **Outside `pithy dev` it does nothing at all.** A plain `vite dev`, a build, or CI has no
|
|
54
60
|
* {@link WORKER_ORIGIN_VAR} in its environment, and the Worker keeps whatever `wrangler.jsonc` says —
|
|
55
61
|
* which for a deployed environment is the value `applyDomains` generated from `domains`, and is
|
|
@@ -58,10 +64,15 @@ export type WorkerVarValue = string | number | boolean | null | WorkerVarValue[]
|
|
|
58
64
|
export function devWorkerConfig(env: NodeJS.ProcessEnv = process.env): (config: WorkerVars) => WorkerVars {
|
|
59
65
|
return (config) => {
|
|
60
66
|
const origin = env[WORKER_ORIGIN_VAR];
|
|
67
|
+
const services = env[SERVICE_ORIGINS_VAR];
|
|
61
68
|
// Absent, blank, or whitespace is "nobody allocated one", never "use the empty string". An empty
|
|
62
69
|
// `BASE_URL` is worse than a wrong one: it fails a URL parse somewhere far from here rather than
|
|
63
70
|
// being denied at the seam with the origin named.
|
|
64
|
-
|
|
71
|
+
const given = {
|
|
72
|
+
...(origin === undefined || origin.trim() === "" ? {} : { BASE_URL: origin }),
|
|
73
|
+
...(services === undefined || services.trim() === "" ? {} : { [SERVICE_ORIGINS_VAR]: services }),
|
|
74
|
+
};
|
|
75
|
+
if (Object.keys(given).length === 0) return {};
|
|
65
76
|
// And never over a config that says, itself, that it is not dev.
|
|
66
77
|
//
|
|
67
78
|
// The customizer is applied on `build` as well as on `serve`, and it beats the `vars` the file
|
|
@@ -76,6 +87,6 @@ export function devWorkerConfig(env: NodeJS.ProcessEnv = process.env): (config:
|
|
|
76
87
|
// the fix from the dev run it exists for — the failure this whole issue was.
|
|
77
88
|
const environment = config.vars?.[ENVIRONMENT_VAR];
|
|
78
89
|
if (typeof environment === "string" && environment !== LOCAL_ENVIRONMENT) return {};
|
|
79
|
-
return { vars: { ...config.vars,
|
|
90
|
+
return { vars: { ...config.vars, ...given } };
|
|
80
91
|
};
|
|
81
92
|
}
|