@osdk/vite-plugin-status-reporter 0.0.1
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/build/browser/index.js +18 -0
- package/build/browser/index.js.map +1 -0
- package/build/browser/statusReporterPlugin.js +121 -0
- package/build/browser/statusReporterPlugin.js.map +1 -0
- package/build/cjs/index.cjs +92 -0
- package/build/cjs/index.cjs.map +1 -0
- package/build/cjs/index.d.cts +20 -0
- package/build/esm/index.js +18 -0
- package/build/esm/index.js.map +1 -0
- package/build/esm/statusReporterPlugin.js +121 -0
- package/build/esm/statusReporterPlugin.js.map +1 -0
- package/build/types/index.d.ts +2 -0
- package/build/types/index.d.ts.map +1 -0
- package/build/types/statusReporterPlugin.d.ts +17 -0
- package/build/types/statusReporterPlugin.d.ts.map +1 -0
- package/package.json +68 -0
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright 2025 Palantir Technologies, Inc. All rights reserved.
|
|
3
|
+
*
|
|
4
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
+
* you may not use this file except in compliance with the License.
|
|
6
|
+
* You may obtain a copy of the License at
|
|
7
|
+
*
|
|
8
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
*
|
|
10
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
11
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
+
* See the License for the specific language governing permissions and
|
|
14
|
+
* limitations under the License.
|
|
15
|
+
*/
|
|
16
|
+
|
|
17
|
+
export { statusReporterPlugin } from "./statusReporterPlugin.js";
|
|
18
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","names":["statusReporterPlugin"],"sources":["index.ts"],"sourcesContent":["/*\n * Copyright 2025 Palantir Technologies, Inc. All rights reserved.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nexport { statusReporterPlugin } from \"./statusReporterPlugin.js\";\nexport type {\n ServiceName,\n StatusReporterConfig,\n} from \"./statusReporterPlugin.js\";\n"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA,SAASA,oBAAoB,QAAQ,2BAA2B","ignoreList":[]}
|
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright 2025 Palantir Technologies, Inc. All rights reserved.
|
|
3
|
+
*
|
|
4
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
+
* you may not use this file except in compliance with the License.
|
|
6
|
+
* You may obtain a copy of the License at
|
|
7
|
+
*
|
|
8
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
*
|
|
10
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
11
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
+
* See the License for the specific language governing permissions and
|
|
14
|
+
* limitations under the License.
|
|
15
|
+
*/
|
|
16
|
+
|
|
17
|
+
import fs from "node:fs";
|
|
18
|
+
import path from "node:path";
|
|
19
|
+
/**
|
|
20
|
+
* Creates a Vite plugin that reports dev server lifecycle status to the
|
|
21
|
+
* Foundry status-server gateway. Only active during development (`apply: "serve"`).
|
|
22
|
+
*
|
|
23
|
+
* Lifecycle: PREPARING → READY (with heartbeat) → FAILED on error → STOPPED on close.
|
|
24
|
+
*/
|
|
25
|
+
export function statusReporterPlugin(config) {
|
|
26
|
+
const {
|
|
27
|
+
service,
|
|
28
|
+
gatewayAddrFile,
|
|
29
|
+
heartbeatInterval = 30_000
|
|
30
|
+
} = config;
|
|
31
|
+
let resolvedAddrFile;
|
|
32
|
+
let logger;
|
|
33
|
+
let heartbeatTimer;
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* Reads the gateway address from the port file written by the status-server.
|
|
37
|
+
* Returns undefined if the file does not exist or is empty, allowing the
|
|
38
|
+
* plugin to silently no-op when no gateway is running.
|
|
39
|
+
*/
|
|
40
|
+
function readStatusAddr() {
|
|
41
|
+
try {
|
|
42
|
+
const content = fs.readFileSync(resolvedAddrFile, "utf-8").trim();
|
|
43
|
+
return content || undefined;
|
|
44
|
+
} catch {
|
|
45
|
+
return undefined;
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* Posts a lifecycle event to the gateway's status endpoint. This is
|
|
51
|
+
* best-effort: if the gateway is unreachable the error is logged via
|
|
52
|
+
* Vite's logger and the dev server continues normally.
|
|
53
|
+
*/
|
|
54
|
+
async function publishStatus(status, level, message) {
|
|
55
|
+
const addr = readStatusAddr();
|
|
56
|
+
if (!addr) return;
|
|
57
|
+
const event = {
|
|
58
|
+
service,
|
|
59
|
+
status,
|
|
60
|
+
level,
|
|
61
|
+
timestamp: new Date().toISOString(),
|
|
62
|
+
...(message != null ? {
|
|
63
|
+
message
|
|
64
|
+
} : {})
|
|
65
|
+
};
|
|
66
|
+
try {
|
|
67
|
+
const res = await fetch(`http://${addr}/api/status`, {
|
|
68
|
+
method: "POST",
|
|
69
|
+
headers: {
|
|
70
|
+
"Content-Type": "application/json"
|
|
71
|
+
},
|
|
72
|
+
body: JSON.stringify(event)
|
|
73
|
+
});
|
|
74
|
+
await res.body?.cancel();
|
|
75
|
+
} catch (e) {
|
|
76
|
+
logger?.warn(`[status-reporter] Failed to publish status: ${e}`);
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
/**
|
|
81
|
+
* Sends an initial READY event and then re-sends it at a fixed interval
|
|
82
|
+
* so the gateway knows this service is still alive.
|
|
83
|
+
*/
|
|
84
|
+
function startHeartbeat(message) {
|
|
85
|
+
const send = () => void publishStatus("READY", "INFO", message);
|
|
86
|
+
send();
|
|
87
|
+
heartbeatTimer = setInterval(send, heartbeatInterval);
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
/** Clears the heartbeat interval so no further READY events are sent. */
|
|
91
|
+
function stopHeartbeat() {
|
|
92
|
+
if (heartbeatTimer !== undefined) {
|
|
93
|
+
clearInterval(heartbeatTimer);
|
|
94
|
+
heartbeatTimer = undefined;
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
return {
|
|
98
|
+
name: "vite-plugin-status-reporter",
|
|
99
|
+
apply: "serve",
|
|
100
|
+
configResolved(resolvedConfig) {
|
|
101
|
+
resolvedAddrFile = path.resolve(resolvedConfig.root, gatewayAddrFile);
|
|
102
|
+
logger = resolvedConfig.logger;
|
|
103
|
+
},
|
|
104
|
+
configureServer(server) {
|
|
105
|
+
void publishStatus("PREPARING", "INFO");
|
|
106
|
+
server.httpServer?.on("listening", () => {
|
|
107
|
+
const addr = server.httpServer?.address();
|
|
108
|
+
const port = typeof addr === "object" && addr ? addr.port : 8080;
|
|
109
|
+
startHeartbeat(`${service} ready at http://localhost:${port}/`);
|
|
110
|
+
});
|
|
111
|
+
server.httpServer?.on("error", err => {
|
|
112
|
+
void publishStatus("FAILED", "ERROR", err.message);
|
|
113
|
+
});
|
|
114
|
+
server.httpServer?.on("close", () => {
|
|
115
|
+
stopHeartbeat();
|
|
116
|
+
void publishStatus("STOPPED", "INFO");
|
|
117
|
+
});
|
|
118
|
+
}
|
|
119
|
+
};
|
|
120
|
+
}
|
|
121
|
+
//# sourceMappingURL=statusReporterPlugin.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"statusReporterPlugin.js","names":["fs","path","statusReporterPlugin","config","service","gatewayAddrFile","heartbeatInterval","resolvedAddrFile","logger","heartbeatTimer","readStatusAddr","content","readFileSync","trim","undefined","publishStatus","status","level","message","addr","event","timestamp","Date","toISOString","res","fetch","method","headers","body","JSON","stringify","cancel","e","warn","startHeartbeat","send","setInterval","stopHeartbeat","clearInterval","name","apply","configResolved","resolvedConfig","resolve","root","configureServer","server","httpServer","on","address","port","err"],"sources":["statusReporterPlugin.ts"],"sourcesContent":["/*\n * Copyright 2025 Palantir Technologies, Inc. All rights reserved.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport fs from \"node:fs\";\nimport path from \"node:path\";\nimport type { Logger, Plugin, ResolvedConfig } from \"vite\";\n\nexport type ServiceName =\n | \"ONTOLOGY\"\n | \"TYPESCRIPT_FUNCTIONS\"\n | \"PYTHON_FUNCTIONS\"\n | \"APP\";\ntype ServiceLifecycle =\n | \"PREPARING\"\n | \"READY\"\n | \"FAILED\"\n | \"STARTING\"\n | \"STOPPED\";\ntype StatusLevel = \"INFO\" | \"WARN\" | \"ERROR\";\ninterface ServiceEvent {\n service: ServiceName;\n status: ServiceLifecycle;\n level: StatusLevel;\n message?: string;\n timestamp: string;\n}\n\nexport interface StatusReporterConfig {\n /** Service name reported in status payloads (e.g. \"APP\") */\n service: ServiceName;\n /** Path to the gateway address file, relative to the Vite project root. */\n gatewayAddrFile: string;\n /** Heartbeat interval in milliseconds. Default: 30000 */\n heartbeatInterval?: number;\n}\n\n/**\n * Creates a Vite plugin that reports dev server lifecycle status to the\n * Foundry status-server gateway. Only active during development (`apply: \"serve\"`).\n *\n * Lifecycle: PREPARING → READY (with heartbeat) → FAILED on error → STOPPED on close.\n */\nexport function statusReporterPlugin(config: StatusReporterConfig): Plugin {\n const {\n service,\n gatewayAddrFile,\n heartbeatInterval = 30_000,\n } = config;\n\n let resolvedAddrFile: string;\n let logger: Logger | undefined;\n let heartbeatTimer: ReturnType<typeof setInterval> | undefined;\n\n /**\n * Reads the gateway address from the port file written by the status-server.\n * Returns undefined if the file does not exist or is empty, allowing the\n * plugin to silently no-op when no gateway is running.\n */\n function readStatusAddr(): string | undefined {\n try {\n const content = fs.readFileSync(resolvedAddrFile, \"utf-8\").trim();\n return content || undefined;\n } catch {\n return undefined;\n }\n }\n\n /**\n * Posts a lifecycle event to the gateway's status endpoint. This is\n * best-effort: if the gateway is unreachable the error is logged via\n * Vite's logger and the dev server continues normally.\n */\n async function publishStatus(\n status: ServiceLifecycle,\n level: StatusLevel,\n message?: string,\n ): Promise<void> {\n const addr = readStatusAddr();\n if (!addr) return;\n\n const event: ServiceEvent = {\n service,\n status,\n level,\n timestamp: new Date().toISOString(),\n ...(message != null ? { message } : {}),\n };\n\n try {\n const res = await fetch(`http://${addr}/api/status`, {\n method: \"POST\",\n headers: { \"Content-Type\": \"application/json\" },\n body: JSON.stringify(event),\n });\n await res.body?.cancel();\n } catch (e) {\n logger?.warn(`[status-reporter] Failed to publish status: ${e}`);\n }\n }\n\n /**\n * Sends an initial READY event and then re-sends it at a fixed interval\n * so the gateway knows this service is still alive.\n */\n function startHeartbeat(message: string): void {\n const send = () => void publishStatus(\"READY\", \"INFO\", message);\n send();\n heartbeatTimer = setInterval(send, heartbeatInterval);\n }\n\n /** Clears the heartbeat interval so no further READY events are sent. */\n function stopHeartbeat(): void {\n if (heartbeatTimer !== undefined) {\n clearInterval(heartbeatTimer);\n heartbeatTimer = undefined;\n }\n }\n\n return {\n name: \"vite-plugin-status-reporter\",\n apply: \"serve\",\n\n configResolved(resolvedConfig: ResolvedConfig) {\n resolvedAddrFile = path.resolve(resolvedConfig.root, gatewayAddrFile);\n logger = resolvedConfig.logger;\n },\n\n configureServer(server) {\n void publishStatus(\"PREPARING\", \"INFO\");\n\n server.httpServer?.on(\"listening\", () => {\n const addr = server.httpServer?.address();\n const port = typeof addr === \"object\" && addr ? addr.port : 8080;\n startHeartbeat(`${service} ready at http://localhost:${port}/`);\n });\n\n server.httpServer?.on(\"error\", (err) => {\n void publishStatus(\"FAILED\", \"ERROR\", err.message);\n });\n\n server.httpServer?.on(\"close\", () => {\n stopHeartbeat();\n void publishStatus(\"STOPPED\", \"INFO\");\n });\n },\n };\n}\n"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA,OAAOA,EAAE,MAAM,SAAS;AACxB,OAAOC,IAAI,MAAM,WAAW;AAgC5B;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,SAASC,oBAAoBA,CAACC,MAA4B,EAAU;EACzE,MAAM;IACJC,OAAO;IACPC,eAAe;IACfC,iBAAiB,GAAG;EACtB,CAAC,GAAGH,MAAM;EAEV,IAAII,gBAAwB;EAC5B,IAAIC,MAA0B;EAC9B,IAAIC,cAA0D;;EAE9D;AACF;AACA;AACA;AACA;EACE,SAASC,cAAcA,CAAA,EAAuB;IAC5C,IAAI;MACF,MAAMC,OAAO,GAAGX,EAAE,CAACY,YAAY,CAACL,gBAAgB,EAAE,OAAO,CAAC,CAACM,IAAI,CAAC,CAAC;MACjE,OAAOF,OAAO,IAAIG,SAAS;IAC7B,CAAC,CAAC,MAAM;MACN,OAAOA,SAAS;IAClB;EACF;;EAEA;AACF;AACA;AACA;AACA;EACE,eAAeC,aAAaA,CAC1BC,MAAwB,EACxBC,KAAkB,EAClBC,OAAgB,EACD;IACf,MAAMC,IAAI,GAAGT,cAAc,CAAC,CAAC;IAC7B,IAAI,CAACS,IAAI,EAAE;IAEX,MAAMC,KAAmB,GAAG;MAC1BhB,OAAO;MACPY,MAAM;MACNC,KAAK;MAC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tB,KAAK/B,aAAa,CAAC,WAAW,EAAE,MAAM,CAAC;MAEvC+B,MAAM,CAACC,UAAU,EAAEC,EAAE,CAAC,WAAW,EAAE,MAAM;QACvC,MAAM7B,IAAI,GAAG2B,MAAM,CAACC,UAAU,EAAEE,OAAO,CAAC,CAAC;QACzC,MAAMC,IAAI,GAAG,OAAO/B,IAAI,KAAK,QAAQ,IAAIA,IAAI,GAAGA,IAAI,CAAC+B,IAAI,GAAG,IAAI;QAChEhB,cAAc,CAAC,GAAG9B,OAAO,8BAA8B8C,IAAI,GAAG,CAAC;MACjE,CAAC,CAAC;MAEFJ,MAAM,CAACC,UAAU,EAAEC,EAAE,CAAC,OAAO,EAAGG,GAAG,IAAK;QACtC,KAAKpC,aAAa,CAAC,QAAQ,EAAE,OAAO,EAAEoC,GAAG,CAACjC,OAAO,CAAC;MACpD,CAAC,CAAC;MAEF4B,MAAM,CAACC,UAAU,EAAEC,EAAE,CAAC,OAAO,EAAE,MAAM;QACnCX,aAAa,CAAC,CAAC;QACf,KAAKtB,aAAa,CAAC,SAAS,EAAE,MAAM,CAAC;MACvC,CAAC,CAAC;IACJ;EACF,CAAC;AACH","ignoreList":[]}
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var fs = require('fs');
|
|
4
|
+
var path = require('path');
|
|
5
|
+
|
|
6
|
+
function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
|
|
7
|
+
|
|
8
|
+
var fs__default = /*#__PURE__*/_interopDefault(fs);
|
|
9
|
+
var path__default = /*#__PURE__*/_interopDefault(path);
|
|
10
|
+
|
|
11
|
+
// src/statusReporterPlugin.ts
|
|
12
|
+
function statusReporterPlugin(config) {
|
|
13
|
+
const {
|
|
14
|
+
service,
|
|
15
|
+
gatewayAddrFile,
|
|
16
|
+
heartbeatInterval = 3e4
|
|
17
|
+
} = config;
|
|
18
|
+
let resolvedAddrFile;
|
|
19
|
+
let logger;
|
|
20
|
+
let heartbeatTimer;
|
|
21
|
+
function readStatusAddr() {
|
|
22
|
+
try {
|
|
23
|
+
const content = fs__default.default.readFileSync(resolvedAddrFile, "utf-8").trim();
|
|
24
|
+
return content || void 0;
|
|
25
|
+
} catch {
|
|
26
|
+
return void 0;
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
async function publishStatus(status, level, message) {
|
|
30
|
+
const addr = readStatusAddr();
|
|
31
|
+
if (!addr) return;
|
|
32
|
+
const event = {
|
|
33
|
+
service,
|
|
34
|
+
status,
|
|
35
|
+
level,
|
|
36
|
+
timestamp: (/* @__PURE__ */ new Date()).toISOString(),
|
|
37
|
+
...message != null ? {
|
|
38
|
+
message
|
|
39
|
+
} : {}
|
|
40
|
+
};
|
|
41
|
+
try {
|
|
42
|
+
const res = await fetch(`http://${addr}/api/status`, {
|
|
43
|
+
method: "POST",
|
|
44
|
+
headers: {
|
|
45
|
+
"Content-Type": "application/json"
|
|
46
|
+
},
|
|
47
|
+
body: JSON.stringify(event)
|
|
48
|
+
});
|
|
49
|
+
await res.body?.cancel();
|
|
50
|
+
} catch (e) {
|
|
51
|
+
logger?.warn(`[status-reporter] Failed to publish status: ${e}`);
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
function startHeartbeat(message) {
|
|
55
|
+
const send = () => void publishStatus("READY", "INFO", message);
|
|
56
|
+
send();
|
|
57
|
+
heartbeatTimer = setInterval(send, heartbeatInterval);
|
|
58
|
+
}
|
|
59
|
+
function stopHeartbeat() {
|
|
60
|
+
if (heartbeatTimer !== void 0) {
|
|
61
|
+
clearInterval(heartbeatTimer);
|
|
62
|
+
heartbeatTimer = void 0;
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
return {
|
|
66
|
+
name: "vite-plugin-status-reporter",
|
|
67
|
+
apply: "serve",
|
|
68
|
+
configResolved(resolvedConfig) {
|
|
69
|
+
resolvedAddrFile = path__default.default.resolve(resolvedConfig.root, gatewayAddrFile);
|
|
70
|
+
logger = resolvedConfig.logger;
|
|
71
|
+
},
|
|
72
|
+
configureServer(server) {
|
|
73
|
+
void publishStatus("PREPARING", "INFO");
|
|
74
|
+
server.httpServer?.on("listening", () => {
|
|
75
|
+
const addr = server.httpServer?.address();
|
|
76
|
+
const port = typeof addr === "object" && addr ? addr.port : 8080;
|
|
77
|
+
startHeartbeat(`${service} ready at http://localhost:${port}/`);
|
|
78
|
+
});
|
|
79
|
+
server.httpServer?.on("error", (err) => {
|
|
80
|
+
void publishStatus("FAILED", "ERROR", err.message);
|
|
81
|
+
});
|
|
82
|
+
server.httpServer?.on("close", () => {
|
|
83
|
+
stopHeartbeat();
|
|
84
|
+
void publishStatus("STOPPED", "INFO");
|
|
85
|
+
});
|
|
86
|
+
}
|
|
87
|
+
};
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
exports.statusReporterPlugin = statusReporterPlugin;
|
|
91
|
+
//# sourceMappingURL=index.cjs.map
|
|
92
|
+
//# sourceMappingURL=index.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/statusReporterPlugin.ts"],"names":["fs","path"],"mappings":";;;;;;;;;;;AAwBO,SAAS,qBAAqB,MAAQ,EAAA;AAC3C,EAAM,MAAA;AAAA,IACJ,OAAA;AAAA,IACA,eAAA;AAAA,IACA,iBAAoB,GAAA;AAAA,GAClB,GAAA,MAAA;AACJ,EAAI,IAAA,gBAAA;AACJ,EAAI,IAAA,MAAA;AACJ,EAAI,IAAA,cAAA;AAOJ,EAAA,SAAS,cAAiB,GAAA;AACxB,IAAI,IAAA;AACF,MAAA,MAAM,UAAUA,mBAAG,CAAA,YAAA,CAAa,gBAAkB,EAAA,OAAO,EAAE,IAAK,EAAA;AAChE,MAAA,OAAO,OAAW,IAAA,KAAA,CAAA;AAAA,KACZ,CAAA,MAAA;AACN,MAAO,OAAA,MAAA;AAAA;AACT;AAQF,EAAe,eAAA,aAAA,CAAc,MAAQ,EAAA,KAAA,EAAO,OAAS,EAAA;AACnD,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,CAAQ,cAAe,CAAA,IAAA,EAAM,eAAe,CAAA;AACpE,MAAA,MAAA,GAAS,cAAe,CAAA,MAAA;AAAA,KAC1B;AAAA,IACA,gBAAgB,MAAQ,EAAA;AACtB,MAAK,KAAA,aAAA,CAAc,aAAa,MAAM,CAAA;AACtC,MAAO,MAAA,CAAA,UAAA,EAAY,EAAG,CAAA,WAAA,EAAa,MAAM;AACvC,QAAM,MAAA,IAAA,GAAO,MAAO,CAAA,UAAA,EAAY,OAAQ,EAAA;AACxC,QAAA,MAAM,OAAO,OAAO,IAAA,KAAS,QAAY,IAAA,IAAA,GAAO,KAAK,IAAO,GAAA,IAAA;AAC5D,QAAA,cAAA,CAAe,CAAG,EAAA,OAAO,CAA8B,2BAAA,EAAA,IAAI,CAAG,CAAA,CAAA,CAAA;AAAA,OAC/D,CAAA;AACD,MAAO,MAAA,CAAA,UAAA,EAAY,EAAG,CAAA,OAAA,EAAS,CAAO,GAAA,KAAA;AACpC,QAAA,KAAK,aAAc,CAAA,QAAA,EAAU,OAAS,EAAA,GAAA,CAAI,OAAO,CAAA;AAAA,OAClD,CAAA;AACD,MAAO,MAAA,CAAA,UAAA,EAAY,EAAG,CAAA,OAAA,EAAS,MAAM;AACnC,QAAc,aAAA,EAAA;AACd,QAAK,KAAA,aAAA,CAAc,WAAW,MAAM,CAAA;AAAA,OACrC,CAAA;AAAA;AACH,GACF;AACF","file":"index.cjs","sourcesContent":["/*\n * Copyright 2025 Palantir Technologies, Inc. All rights reserved.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport fs from \"node:fs\";\nimport path from \"node:path\";\n/**\n * Creates a Vite plugin that reports dev server lifecycle status to the\n * Foundry status-server gateway. Only active during development (`apply: \"serve\"`).\n *\n * Lifecycle: PREPARING → READY (with heartbeat) → FAILED on error → STOPPED on close.\n */\nexport function statusReporterPlugin(config) {\n const {\n service,\n gatewayAddrFile,\n heartbeatInterval = 30_000\n } = config;\n let resolvedAddrFile;\n let logger;\n let heartbeatTimer;\n\n /**\n * Reads the gateway address from the port file written by the status-server.\n * Returns undefined if the file does not exist or is empty, allowing the\n * plugin to silently no-op when no gateway is running.\n */\n function readStatusAddr() {\n try {\n const content = fs.readFileSync(resolvedAddrFile, \"utf-8\").trim();\n return content || undefined;\n } catch {\n return undefined;\n }\n }\n\n /**\n * Posts a lifecycle event to the gateway's status endpoint. This is\n * best-effort: if the gateway is unreachable the error is logged via\n * Vite's logger and the dev server continues normally.\n */\n async function publishStatus(status, level, message) {\n const addr = readStatusAddr();\n if (!addr) return;\n const event = {\n service,\n status,\n level,\n timestamp: new Date().toISOString(),\n ...(message != null ? {\n message\n } : {})\n };\n try {\n const res = await fetch(`http://${addr}/api/status`, {\n method: \"POST\",\n headers: {\n \"Content-Type\": \"application/json\"\n },\n body: JSON.stringify(event)\n });\n await res.body?.cancel();\n } catch (e) {\n logger?.warn(`[status-reporter] Failed to publish status: ${e}`);\n }\n }\n\n /**\n * Sends an initial READY event and then re-sends it at a fixed interval\n * so the gateway knows this service is still alive.\n */\n function startHeartbeat(message) {\n const send = () => void publishStatus(\"READY\", \"INFO\", message);\n send();\n heartbeatTimer = setInterval(send, heartbeatInterval);\n }\n\n /** Clears the heartbeat interval so no further READY events are sent. */\n function stopHeartbeat() {\n if (heartbeatTimer !== undefined) {\n clearInterval(heartbeatTimer);\n heartbeatTimer = undefined;\n }\n }\n return {\n name: \"vite-plugin-status-reporter\",\n apply: \"serve\",\n configResolved(resolvedConfig) {\n resolvedAddrFile = path.resolve(resolvedConfig.root, gatewayAddrFile);\n logger = resolvedConfig.logger;\n },\n configureServer(server) {\n void publishStatus(\"PREPARING\", \"INFO\");\n server.httpServer?.on(\"listening\", () => {\n const addr = server.httpServer?.address();\n const port = typeof addr === \"object\" && addr ? addr.port : 8080;\n startHeartbeat(`${service} ready at http://localhost:${port}/`);\n });\n server.httpServer?.on(\"error\", err => {\n void publishStatus(\"FAILED\", \"ERROR\", err.message);\n });\n server.httpServer?.on(\"close\", () => {\n stopHeartbeat();\n void publishStatus(\"STOPPED\", \"INFO\");\n });\n }\n };\n}"]}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { Plugin } from 'vite';
|
|
2
|
+
|
|
3
|
+
type ServiceName = "ONTOLOGY" | "TYPESCRIPT_FUNCTIONS" | "PYTHON_FUNCTIONS" | "APP";
|
|
4
|
+
interface StatusReporterConfig {
|
|
5
|
+
/** Service name reported in status payloads (e.g. "APP") */
|
|
6
|
+
service: ServiceName;
|
|
7
|
+
/** Path to the gateway address file, relative to the Vite project root. */
|
|
8
|
+
gatewayAddrFile: string;
|
|
9
|
+
/** Heartbeat interval in milliseconds. Default: 30000 */
|
|
10
|
+
heartbeatInterval?: number;
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* Creates a Vite plugin that reports dev server lifecycle status to the
|
|
14
|
+
* Foundry status-server gateway. Only active during development (`apply: "serve"`).
|
|
15
|
+
*
|
|
16
|
+
* Lifecycle: PREPARING → READY (with heartbeat) → FAILED on error → STOPPED on close.
|
|
17
|
+
*/
|
|
18
|
+
declare function statusReporterPlugin(config: StatusReporterConfig): Plugin;
|
|
19
|
+
|
|
20
|
+
export { type ServiceName, type StatusReporterConfig, statusReporterPlugin };
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright 2025 Palantir Technologies, Inc. All rights reserved.
|
|
3
|
+
*
|
|
4
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
+
* you may not use this file except in compliance with the License.
|
|
6
|
+
* You may obtain a copy of the License at
|
|
7
|
+
*
|
|
8
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
*
|
|
10
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
11
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
+
* See the License for the specific language governing permissions and
|
|
14
|
+
* limitations under the License.
|
|
15
|
+
*/
|
|
16
|
+
|
|
17
|
+
export { statusReporterPlugin } from "./statusReporterPlugin.js";
|
|
18
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","names":["statusReporterPlugin"],"sources":["index.ts"],"sourcesContent":["/*\n * Copyright 2025 Palantir Technologies, Inc. All rights reserved.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nexport { statusReporterPlugin } from \"./statusReporterPlugin.js\";\nexport type {\n ServiceName,\n StatusReporterConfig,\n} from \"./statusReporterPlugin.js\";\n"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA,SAASA,oBAAoB,QAAQ,2BAA2B","ignoreList":[]}
|
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright 2025 Palantir Technologies, Inc. All rights reserved.
|
|
3
|
+
*
|
|
4
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
+
* you may not use this file except in compliance with the License.
|
|
6
|
+
* You may obtain a copy of the License at
|
|
7
|
+
*
|
|
8
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
*
|
|
10
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
11
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
+
* See the License for the specific language governing permissions and
|
|
14
|
+
* limitations under the License.
|
|
15
|
+
*/
|
|
16
|
+
|
|
17
|
+
import fs from "node:fs";
|
|
18
|
+
import path from "node:path";
|
|
19
|
+
/**
|
|
20
|
+
* Creates a Vite plugin that reports dev server lifecycle status to the
|
|
21
|
+
* Foundry status-server gateway. Only active during development (`apply: "serve"`).
|
|
22
|
+
*
|
|
23
|
+
* Lifecycle: PREPARING → READY (with heartbeat) → FAILED on error → STOPPED on close.
|
|
24
|
+
*/
|
|
25
|
+
export function statusReporterPlugin(config) {
|
|
26
|
+
const {
|
|
27
|
+
service,
|
|
28
|
+
gatewayAddrFile,
|
|
29
|
+
heartbeatInterval = 30_000
|
|
30
|
+
} = config;
|
|
31
|
+
let resolvedAddrFile;
|
|
32
|
+
let logger;
|
|
33
|
+
let heartbeatTimer;
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* Reads the gateway address from the port file written by the status-server.
|
|
37
|
+
* Returns undefined if the file does not exist or is empty, allowing the
|
|
38
|
+
* plugin to silently no-op when no gateway is running.
|
|
39
|
+
*/
|
|
40
|
+
function readStatusAddr() {
|
|
41
|
+
try {
|
|
42
|
+
const content = fs.readFileSync(resolvedAddrFile, "utf-8").trim();
|
|
43
|
+
return content || undefined;
|
|
44
|
+
} catch {
|
|
45
|
+
return undefined;
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* Posts a lifecycle event to the gateway's status endpoint. This is
|
|
51
|
+
* best-effort: if the gateway is unreachable the error is logged via
|
|
52
|
+
* Vite's logger and the dev server continues normally.
|
|
53
|
+
*/
|
|
54
|
+
async function publishStatus(status, level, message) {
|
|
55
|
+
const addr = readStatusAddr();
|
|
56
|
+
if (!addr) return;
|
|
57
|
+
const event = {
|
|
58
|
+
service,
|
|
59
|
+
status,
|
|
60
|
+
level,
|
|
61
|
+
timestamp: new Date().toISOString(),
|
|
62
|
+
...(message != null ? {
|
|
63
|
+
message
|
|
64
|
+
} : {})
|
|
65
|
+
};
|
|
66
|
+
try {
|
|
67
|
+
const res = await fetch(`http://${addr}/api/status`, {
|
|
68
|
+
method: "POST",
|
|
69
|
+
headers: {
|
|
70
|
+
"Content-Type": "application/json"
|
|
71
|
+
},
|
|
72
|
+
body: JSON.stringify(event)
|
|
73
|
+
});
|
|
74
|
+
await res.body?.cancel();
|
|
75
|
+
} catch (e) {
|
|
76
|
+
logger?.warn(`[status-reporter] Failed to publish status: ${e}`);
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
/**
|
|
81
|
+
* Sends an initial READY event and then re-sends it at a fixed interval
|
|
82
|
+
* so the gateway knows this service is still alive.
|
|
83
|
+
*/
|
|
84
|
+
function startHeartbeat(message) {
|
|
85
|
+
const send = () => void publishStatus("READY", "INFO", message);
|
|
86
|
+
send();
|
|
87
|
+
heartbeatTimer = setInterval(send, heartbeatInterval);
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
/** Clears the heartbeat interval so no further READY events are sent. */
|
|
91
|
+
function stopHeartbeat() {
|
|
92
|
+
if (heartbeatTimer !== undefined) {
|
|
93
|
+
clearInterval(heartbeatTimer);
|
|
94
|
+
heartbeatTimer = undefined;
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
return {
|
|
98
|
+
name: "vite-plugin-status-reporter",
|
|
99
|
+
apply: "serve",
|
|
100
|
+
configResolved(resolvedConfig) {
|
|
101
|
+
resolvedAddrFile = path.resolve(resolvedConfig.root, gatewayAddrFile);
|
|
102
|
+
logger = resolvedConfig.logger;
|
|
103
|
+
},
|
|
104
|
+
configureServer(server) {
|
|
105
|
+
void publishStatus("PREPARING", "INFO");
|
|
106
|
+
server.httpServer?.on("listening", () => {
|
|
107
|
+
const addr = server.httpServer?.address();
|
|
108
|
+
const port = typeof addr === "object" && addr ? addr.port : 8080;
|
|
109
|
+
startHeartbeat(`${service} ready at http://localhost:${port}/`);
|
|
110
|
+
});
|
|
111
|
+
server.httpServer?.on("error", err => {
|
|
112
|
+
void publishStatus("FAILED", "ERROR", err.message);
|
|
113
|
+
});
|
|
114
|
+
server.httpServer?.on("close", () => {
|
|
115
|
+
stopHeartbeat();
|
|
116
|
+
void publishStatus("STOPPED", "INFO");
|
|
117
|
+
});
|
|
118
|
+
}
|
|
119
|
+
};
|
|
120
|
+
}
|
|
121
|
+
//# sourceMappingURL=statusReporterPlugin.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"statusReporterPlugin.js","names":["fs","path","statusReporterPlugin","config","service","gatewayAddrFile","heartbeatInterval","resolvedAddrFile","logger","heartbeatTimer","readStatusAddr","content","readFileSync","trim","undefined","publishStatus","status","level","message","addr","event","timestamp","Date","toISOString","res","fetch","method","headers","body","JSON","stringify","cancel","e","warn","startHeartbeat","send","setInterval","stopHeartbeat","clearInterval","name","apply","configResolved","resolvedConfig","resolve","root","configureServer","server","httpServer","on","address","port","err"],"sources":["statusReporterPlugin.ts"],"sourcesContent":["/*\n * Copyright 2025 Palantir Technologies, Inc. All rights reserved.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport fs from \"node:fs\";\nimport path from \"node:path\";\nimport type { Logger, Plugin, ResolvedConfig } from \"vite\";\n\nexport type ServiceName =\n | \"ONTOLOGY\"\n | \"TYPESCRIPT_FUNCTIONS\"\n | \"PYTHON_FUNCTIONS\"\n | \"APP\";\ntype ServiceLifecycle =\n | \"PREPARING\"\n | \"READY\"\n | \"FAILED\"\n | \"STARTING\"\n | \"STOPPED\";\ntype StatusLevel = \"INFO\" | \"WARN\" | \"ERROR\";\ninterface ServiceEvent {\n service: ServiceName;\n status: ServiceLifecycle;\n level: StatusLevel;\n message?: string;\n timestamp: string;\n}\n\nexport interface StatusReporterConfig {\n /** Service name reported in status payloads (e.g. \"APP\") */\n service: ServiceName;\n /** Path to the gateway address file, relative to the Vite project root. */\n gatewayAddrFile: string;\n /** Heartbeat interval in milliseconds. Default: 30000 */\n heartbeatInterval?: number;\n}\n\n/**\n * Creates a Vite plugin that reports dev server lifecycle status to the\n * Foundry status-server gateway. Only active during development (`apply: \"serve\"`).\n *\n * Lifecycle: PREPARING → READY (with heartbeat) → FAILED on error → STOPPED on close.\n */\nexport function statusReporterPlugin(config: StatusReporterConfig): Plugin {\n const {\n service,\n gatewayAddrFile,\n heartbeatInterval = 30_000,\n } = config;\n\n let resolvedAddrFile: string;\n let logger: Logger | undefined;\n let heartbeatTimer: ReturnType<typeof setInterval> | undefined;\n\n /**\n * Reads the gateway address from the port file written by the status-server.\n * Returns undefined if the file does not exist or is empty, allowing the\n * plugin to silently no-op when no gateway is running.\n */\n function readStatusAddr(): string | undefined {\n try {\n const content = fs.readFileSync(resolvedAddrFile, \"utf-8\").trim();\n return content || undefined;\n } catch {\n return undefined;\n }\n }\n\n /**\n * Posts a lifecycle event to the gateway's status endpoint. This is\n * best-effort: if the gateway is unreachable the error is logged via\n * Vite's logger and the dev server continues normally.\n */\n async function publishStatus(\n status: ServiceLifecycle,\n level: StatusLevel,\n message?: string,\n ): Promise<void> {\n const addr = readStatusAddr();\n if (!addr) return;\n\n const event: ServiceEvent = {\n service,\n status,\n level,\n timestamp: new Date().toISOString(),\n ...(message != null ? { message } : {}),\n };\n\n try {\n const res = await fetch(`http://${addr}/api/status`, {\n method: \"POST\",\n headers: { \"Content-Type\": \"application/json\" },\n body: JSON.stringify(event),\n });\n await res.body?.cancel();\n } catch (e) {\n logger?.warn(`[status-reporter] Failed to publish status: ${e}`);\n }\n }\n\n /**\n * Sends an initial READY event and then re-sends it at a fixed interval\n * so the gateway knows this service is still alive.\n */\n function startHeartbeat(message: string): void {\n const send = () => void publishStatus(\"READY\", \"INFO\", message);\n send();\n heartbeatTimer = setInterval(send, heartbeatInterval);\n }\n\n /** Clears the heartbeat interval so no further READY events are sent. */\n function stopHeartbeat(): void {\n if (heartbeatTimer !== undefined) {\n clearInterval(heartbeatTimer);\n heartbeatTimer = undefined;\n }\n }\n\n return {\n name: \"vite-plugin-status-reporter\",\n apply: \"serve\",\n\n configResolved(resolvedConfig: ResolvedConfig) {\n resolvedAddrFile = path.resolve(resolvedConfig.root, gatewayAddrFile);\n logger = resolvedConfig.logger;\n },\n\n configureServer(server) {\n void publishStatus(\"PREPARING\", \"INFO\");\n\n server.httpServer?.on(\"listening\", () => {\n const addr = server.httpServer?.address();\n const port = typeof addr === \"object\" && addr ? addr.port : 8080;\n startHeartbeat(`${service} ready at http://localhost:${port}/`);\n });\n\n server.httpServer?.on(\"error\", (err) => {\n void publishStatus(\"FAILED\", \"ERROR\", err.message);\n });\n\n server.httpServer?.on(\"close\", () => {\n stopHeartbeat();\n void publishStatus(\"STOPPED\", \"INFO\");\n });\n },\n };\n}\n"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA,OAAOA,EAAE,MAAM,SAAS;AACxB,OAAOC,IAAI,MAAM,WAAW;AAgC5B;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,SAASC,oBAAoBA,CAACC,MAA4B,EAAU;EACzE,MAAM;IACJC,OAAO;IACPC,eAAe;IACfC,iBAAiB,GAAG;EACtB,CAAC,GAAGH,MAAM;EAEV,IAAII,gBAAwB;EAC5B,IAAIC,MAA0B;EAC9B,IAAIC,cAA0D;;EAE9D;AACF;AACA;AACA;AACA;EACE,SAASC,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":"AAgBA,SAAS,4BAA4B;AACrC,cACE,aACA,4BACK","names":[],"sources":["../../src/index.ts"],"version":3,"file":"index.d.ts"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import type { Plugin } from "vite";
|
|
2
|
+
export type ServiceName = "ONTOLOGY" | "TYPESCRIPT_FUNCTIONS" | "PYTHON_FUNCTIONS" | "APP";
|
|
3
|
+
export interface StatusReporterConfig {
|
|
4
|
+
/** Service name reported in status payloads (e.g. "APP") */
|
|
5
|
+
service: ServiceName;
|
|
6
|
+
/** Path to the gateway address file, relative to the Vite project root. */
|
|
7
|
+
gatewayAddrFile: string;
|
|
8
|
+
/** Heartbeat interval in milliseconds. Default: 30000 */
|
|
9
|
+
heartbeatInterval?: number;
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* Creates a Vite plugin that reports dev server lifecycle status to the
|
|
13
|
+
* Foundry status-server gateway. Only active during development (`apply: "serve"`).
|
|
14
|
+
*
|
|
15
|
+
* Lifecycle: PREPARING → READY (with heartbeat) → FAILED on error → STOPPED on close.
|
|
16
|
+
*/
|
|
17
|
+
export declare function statusReporterPlugin(config: StatusReporterConfig): Plugin;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"mappings":"AAkBA,cAAsB,cAA8B,MAAO;AAE3D,YAAY,cACR,aACA,yBACA,qBACA;AAgBJ,iBAAiB,qBAAqB;;CAEpC,SAAS;;CAET;;CAEA;AACD;;;;;;;AAQD,OAAO,iBAAS,qBAAqBA,QAAQ,uBAAuB","names":["config: StatusReporterConfig"],"sources":["../../src/statusReporterPlugin.ts"],"version":3,"file":"statusReporterPlugin.d.ts"}
|
package/package.json
ADDED
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@osdk/vite-plugin-status-reporter",
|
|
3
|
+
"version": "0.0.1",
|
|
4
|
+
"license": "Apache-2.0",
|
|
5
|
+
"repository": {
|
|
6
|
+
"type": "git",
|
|
7
|
+
"url": "https://github.com/palantir/osdk-ts.git"
|
|
8
|
+
},
|
|
9
|
+
"exports": {
|
|
10
|
+
".": {
|
|
11
|
+
"browser": "./build/browser/index.js",
|
|
12
|
+
"import": {
|
|
13
|
+
"types": "./build/types/index.d.ts",
|
|
14
|
+
"default": "./build/esm/index.js"
|
|
15
|
+
},
|
|
16
|
+
"require": "./build/cjs/index.cjs",
|
|
17
|
+
"default": "./build/browser/index.js"
|
|
18
|
+
},
|
|
19
|
+
"./*": {
|
|
20
|
+
"browser": "./build/browser/public/*.js",
|
|
21
|
+
"import": {
|
|
22
|
+
"types": "./build/types/public/*.d.ts",
|
|
23
|
+
"default": "./build/esm/public/*.js"
|
|
24
|
+
},
|
|
25
|
+
"require": "./build/cjs/public/*.cjs",
|
|
26
|
+
"default": "./build/browser/public/*.js"
|
|
27
|
+
}
|
|
28
|
+
},
|
|
29
|
+
"peerDependencies": {
|
|
30
|
+
"vite": "*"
|
|
31
|
+
},
|
|
32
|
+
"devDependencies": {
|
|
33
|
+
"@types/node": "^20.19.13",
|
|
34
|
+
"typescript": "~5.5.4",
|
|
35
|
+
"@osdk/monorepo.api-extractor": "~0.7.0",
|
|
36
|
+
"@osdk/monorepo.tsconfig": "~0.7.0"
|
|
37
|
+
},
|
|
38
|
+
"publishConfig": {
|
|
39
|
+
"access": "public"
|
|
40
|
+
},
|
|
41
|
+
"files": [
|
|
42
|
+
"build/cjs",
|
|
43
|
+
"build/esm",
|
|
44
|
+
"build/browser",
|
|
45
|
+
"build/types",
|
|
46
|
+
"CHANGELOG.md",
|
|
47
|
+
"package.json",
|
|
48
|
+
"templates",
|
|
49
|
+
"*.d.ts"
|
|
50
|
+
],
|
|
51
|
+
"main": "./build/cjs/index.cjs",
|
|
52
|
+
"module": "./build/esm/index.js",
|
|
53
|
+
"types": "./build/cjs/index.d.cts",
|
|
54
|
+
"type": "module",
|
|
55
|
+
"scripts": {
|
|
56
|
+
"check-attw": "attw --pack .",
|
|
57
|
+
"check-spelling": "cspell --quiet .",
|
|
58
|
+
"clean": "rm -rf lib dist types build tsconfig.tsbuildinfo",
|
|
59
|
+
"fix-lint": "eslint . --fix && dprint fmt --config $(find-up dprint.json)",
|
|
60
|
+
"lint": "eslint . && dprint check --config $(find-up dprint.json)",
|
|
61
|
+
"transpileBrowser": "monorepo.tool.transpile -f esm -m normal -t browser",
|
|
62
|
+
"transpileCjs": "monorepo.tool.transpile -f cjs -m bundle -t node",
|
|
63
|
+
"transpileEsm": "monorepo.tool.transpile -f esm -m normal -t node",
|
|
64
|
+
"transpileTypes": "monorepo.tool.transpile -f esm -m types -t node",
|
|
65
|
+
"typecheck": "tsc --noEmit --emitDeclarationOnly false",
|
|
66
|
+
"watch": "tsc --watch"
|
|
67
|
+
}
|
|
68
|
+
}
|