@moonwatch/js 0.1.8
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 +206 -0
- package/SKILL.md +320 -0
- package/dist/chunk-JKIIIVNW.mjs +11 -0
- package/dist/index.d.mts +132 -0
- package/dist/index.d.ts +132 -0
- package/dist/index.js +889 -0
- package/dist/index.mjs +860 -0
- package/dist/init.js +34 -0
- package/dist/vite.d.mts +11 -0
- package/dist/vite.d.ts +11 -0
- package/dist/vite.js +138 -0
- package/dist/vite.mjs +119 -0
- package/package.json +53 -0
package/dist/init.js
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
"use strict";
|
|
3
|
+
|
|
4
|
+
// src/init.ts
|
|
5
|
+
var import_fs = require("fs");
|
|
6
|
+
var import_path = require("path");
|
|
7
|
+
var CLAUDE_MD = "CLAUDE.md";
|
|
8
|
+
var CURSORRULES = ".cursorrules";
|
|
9
|
+
var SKILL_REF = "> See node_modules/@moonwatch/js/SKILL.md for the @moonwatch/js logging workflow.";
|
|
10
|
+
var cwd = process.cwd();
|
|
11
|
+
function appendIfMissing(filename) {
|
|
12
|
+
const filepath = (0, import_path.resolve)(cwd, filename);
|
|
13
|
+
const marker = "node_modules/@moonwatch/js/SKILL.md";
|
|
14
|
+
let content = "";
|
|
15
|
+
if ((0, import_fs.existsSync)(filepath)) {
|
|
16
|
+
content = (0, import_fs.readFileSync)(filepath, "utf-8");
|
|
17
|
+
if (content.includes(marker)) {
|
|
18
|
+
console.log(` ${filename}: already configured, skipping`);
|
|
19
|
+
return false;
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
const separator = content.length > 0 && !content.endsWith("\n") ? "\n\n" : content.length > 0 ? "\n" : "";
|
|
23
|
+
(0, import_fs.writeFileSync)(filepath, content + separator + SKILL_REF + "\n", "utf-8");
|
|
24
|
+
console.log(` ${filename}: ${content.length > 0 ? "updated" : "created"}`);
|
|
25
|
+
return true;
|
|
26
|
+
}
|
|
27
|
+
console.log("\n@moonwatch/js init\n");
|
|
28
|
+
var claudeUpdated = appendIfMissing(CLAUDE_MD);
|
|
29
|
+
var cursorUpdated = appendIfMissing(CURSORRULES);
|
|
30
|
+
if (!claudeUpdated && !cursorUpdated) {
|
|
31
|
+
console.log("\nAlready set up \u2014 nothing to do.\n");
|
|
32
|
+
} else {
|
|
33
|
+
console.log("\nDone. Your AI assistant now has access to the Moonwatch workflow guide.\n");
|
|
34
|
+
}
|
package/dist/vite.d.mts
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { Plugin } from 'vite';
|
|
2
|
+
|
|
3
|
+
interface MoonwatchPluginOptions {
|
|
4
|
+
apiKey: string;
|
|
5
|
+
logFileId: string;
|
|
6
|
+
/** @internal Override endpoint for development */
|
|
7
|
+
_endpoint?: string;
|
|
8
|
+
}
|
|
9
|
+
declare function moonwatchPlugin(options: MoonwatchPluginOptions): Plugin;
|
|
10
|
+
|
|
11
|
+
export { type MoonwatchPluginOptions, moonwatchPlugin as default };
|
package/dist/vite.d.ts
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { Plugin } from 'vite';
|
|
2
|
+
|
|
3
|
+
interface MoonwatchPluginOptions {
|
|
4
|
+
apiKey: string;
|
|
5
|
+
logFileId: string;
|
|
6
|
+
/** @internal Override endpoint for development */
|
|
7
|
+
_endpoint?: string;
|
|
8
|
+
}
|
|
9
|
+
declare function moonwatchPlugin(options: MoonwatchPluginOptions): Plugin;
|
|
10
|
+
|
|
11
|
+
export { type MoonwatchPluginOptions, moonwatchPlugin as default };
|
package/dist/vite.js
ADDED
|
@@ -0,0 +1,138 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
|
|
20
|
+
// src/vite.ts
|
|
21
|
+
var vite_exports = {};
|
|
22
|
+
__export(vite_exports, {
|
|
23
|
+
default: () => moonwatchPlugin
|
|
24
|
+
});
|
|
25
|
+
module.exports = __toCommonJS(vite_exports);
|
|
26
|
+
var import_crypto = require("crypto");
|
|
27
|
+
var import_fs = require("fs");
|
|
28
|
+
var import_path = require("path");
|
|
29
|
+
var import_os = require("os");
|
|
30
|
+
var DEFAULT_ENDPOINT = "https://log.terodato.com";
|
|
31
|
+
var RELEASE_FILE = (0, import_path.join)((0, import_os.tmpdir)(), ".moonwatch-release");
|
|
32
|
+
var RELEASE_FILE_MAX_AGE_MS = 5 * 60 * 1e3;
|
|
33
|
+
function collectMapFiles(dir) {
|
|
34
|
+
const results = [];
|
|
35
|
+
try {
|
|
36
|
+
const entries = (0, import_fs.readdirSync)(dir, { withFileTypes: true });
|
|
37
|
+
for (const entry of entries) {
|
|
38
|
+
const fullPath = (0, import_path.join)(dir, entry.name);
|
|
39
|
+
if (entry.isDirectory()) {
|
|
40
|
+
results.push(...collectMapFiles(fullPath));
|
|
41
|
+
} else if (entry.name.endsWith(".map")) {
|
|
42
|
+
results.push(fullPath);
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
} catch {
|
|
46
|
+
}
|
|
47
|
+
return results;
|
|
48
|
+
}
|
|
49
|
+
var sharedReleaseId = null;
|
|
50
|
+
var uploadedOutDirs = /* @__PURE__ */ new Set();
|
|
51
|
+
var UUID_REGEX = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;
|
|
52
|
+
function getOrCreateReleaseId() {
|
|
53
|
+
if (sharedReleaseId) return sharedReleaseId;
|
|
54
|
+
try {
|
|
55
|
+
if ((0, import_fs.existsSync)(RELEASE_FILE)) {
|
|
56
|
+
const stat = (0, import_fs.statSync)(RELEASE_FILE);
|
|
57
|
+
if (Date.now() - stat.mtimeMs < RELEASE_FILE_MAX_AGE_MS) {
|
|
58
|
+
const id2 = (0, import_fs.readFileSync)(RELEASE_FILE, "utf-8").trim();
|
|
59
|
+
if (UUID_REGEX.test(id2)) {
|
|
60
|
+
sharedReleaseId = id2;
|
|
61
|
+
return id2;
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
} catch {
|
|
66
|
+
}
|
|
67
|
+
const id = (0, import_crypto.randomUUID)();
|
|
68
|
+
sharedReleaseId = id;
|
|
69
|
+
try {
|
|
70
|
+
(0, import_fs.writeFileSync)(RELEASE_FILE, id, "utf-8");
|
|
71
|
+
} catch {
|
|
72
|
+
}
|
|
73
|
+
return id;
|
|
74
|
+
}
|
|
75
|
+
function moonwatchPlugin(options) {
|
|
76
|
+
const releaseId = getOrCreateReleaseId();
|
|
77
|
+
let resolvedConfig;
|
|
78
|
+
let skip = false;
|
|
79
|
+
return {
|
|
80
|
+
name: "moonwatch-sourcemap",
|
|
81
|
+
enforce: "post",
|
|
82
|
+
config(config, { command, mode }) {
|
|
83
|
+
if (mode === "development" || command === "serve") {
|
|
84
|
+
skip = true;
|
|
85
|
+
return;
|
|
86
|
+
}
|
|
87
|
+
return {
|
|
88
|
+
define: {
|
|
89
|
+
__MOONWATCH_RELEASE__: JSON.stringify(releaseId)
|
|
90
|
+
}
|
|
91
|
+
};
|
|
92
|
+
},
|
|
93
|
+
configResolved(config) {
|
|
94
|
+
resolvedConfig = config;
|
|
95
|
+
},
|
|
96
|
+
async closeBundle() {
|
|
97
|
+
if (skip) return;
|
|
98
|
+
const outDir = resolvedConfig.build.outDir;
|
|
99
|
+
if (uploadedOutDirs.has(outDir)) return;
|
|
100
|
+
uploadedOutDirs.add(outDir);
|
|
101
|
+
const mapFiles = collectMapFiles(outDir);
|
|
102
|
+
if (mapFiles.length === 0) {
|
|
103
|
+
console.log("[Moonwatch] No source map files found, skipping upload");
|
|
104
|
+
return;
|
|
105
|
+
}
|
|
106
|
+
const endpoint = options._endpoint || DEFAULT_ENDPOINT;
|
|
107
|
+
const url = `${endpoint}/sourcemaps/upload`;
|
|
108
|
+
const formData = new FormData();
|
|
109
|
+
formData.append("releaseId", releaseId);
|
|
110
|
+
formData.append("logFileId", options.logFileId);
|
|
111
|
+
for (const mapFile of mapFiles) {
|
|
112
|
+
const content = (0, import_fs.readFileSync)(mapFile);
|
|
113
|
+
const name = (0, import_path.relative)(outDir, mapFile).replace(/\\/g, "/").replace(/\//g, "_");
|
|
114
|
+
const blob = new Blob([content], { type: "application/json" });
|
|
115
|
+
formData.append("files", blob, name.endsWith(".map") ? name : `${name}.map`);
|
|
116
|
+
}
|
|
117
|
+
try {
|
|
118
|
+
console.log(`[Moonwatch] Uploading ${mapFiles.length} source maps (release: ${releaseId})...`);
|
|
119
|
+
const response = await fetch(url, {
|
|
120
|
+
method: "POST",
|
|
121
|
+
headers: {
|
|
122
|
+
"Authorization": `Bearer ${options.apiKey}`
|
|
123
|
+
},
|
|
124
|
+
body: formData
|
|
125
|
+
});
|
|
126
|
+
if (!response.ok) {
|
|
127
|
+
const body = await response.text();
|
|
128
|
+
console.error(`[Moonwatch] Source map upload failed (${response.status}): ${body}`);
|
|
129
|
+
return;
|
|
130
|
+
}
|
|
131
|
+
const result = await response.json();
|
|
132
|
+
console.log(`[Moonwatch] Uploaded ${result.count} source maps successfully`);
|
|
133
|
+
} catch (err) {
|
|
134
|
+
console.error("[Moonwatch] Source map upload failed:", err);
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
};
|
|
138
|
+
}
|
package/dist/vite.mjs
ADDED
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
import "./chunk-JKIIIVNW.mjs";
|
|
2
|
+
|
|
3
|
+
// src/vite.ts
|
|
4
|
+
import { randomUUID } from "crypto";
|
|
5
|
+
import { existsSync, readdirSync, readFileSync, statSync, writeFileSync } from "fs";
|
|
6
|
+
import { join, relative } from "path";
|
|
7
|
+
import { tmpdir } from "os";
|
|
8
|
+
var DEFAULT_ENDPOINT = "https://log.terodato.com";
|
|
9
|
+
var RELEASE_FILE = join(tmpdir(), ".moonwatch-release");
|
|
10
|
+
var RELEASE_FILE_MAX_AGE_MS = 5 * 60 * 1e3;
|
|
11
|
+
function collectMapFiles(dir) {
|
|
12
|
+
const results = [];
|
|
13
|
+
try {
|
|
14
|
+
const entries = readdirSync(dir, { withFileTypes: true });
|
|
15
|
+
for (const entry of entries) {
|
|
16
|
+
const fullPath = join(dir, entry.name);
|
|
17
|
+
if (entry.isDirectory()) {
|
|
18
|
+
results.push(...collectMapFiles(fullPath));
|
|
19
|
+
} else if (entry.name.endsWith(".map")) {
|
|
20
|
+
results.push(fullPath);
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
} catch {
|
|
24
|
+
}
|
|
25
|
+
return results;
|
|
26
|
+
}
|
|
27
|
+
var sharedReleaseId = null;
|
|
28
|
+
var uploadedOutDirs = /* @__PURE__ */ new Set();
|
|
29
|
+
var UUID_REGEX = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;
|
|
30
|
+
function getOrCreateReleaseId() {
|
|
31
|
+
if (sharedReleaseId) return sharedReleaseId;
|
|
32
|
+
try {
|
|
33
|
+
if (existsSync(RELEASE_FILE)) {
|
|
34
|
+
const stat = statSync(RELEASE_FILE);
|
|
35
|
+
if (Date.now() - stat.mtimeMs < RELEASE_FILE_MAX_AGE_MS) {
|
|
36
|
+
const id2 = readFileSync(RELEASE_FILE, "utf-8").trim();
|
|
37
|
+
if (UUID_REGEX.test(id2)) {
|
|
38
|
+
sharedReleaseId = id2;
|
|
39
|
+
return id2;
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
} catch {
|
|
44
|
+
}
|
|
45
|
+
const id = randomUUID();
|
|
46
|
+
sharedReleaseId = id;
|
|
47
|
+
try {
|
|
48
|
+
writeFileSync(RELEASE_FILE, id, "utf-8");
|
|
49
|
+
} catch {
|
|
50
|
+
}
|
|
51
|
+
return id;
|
|
52
|
+
}
|
|
53
|
+
function moonwatchPlugin(options) {
|
|
54
|
+
const releaseId = getOrCreateReleaseId();
|
|
55
|
+
let resolvedConfig;
|
|
56
|
+
let skip = false;
|
|
57
|
+
return {
|
|
58
|
+
name: "moonwatch-sourcemap",
|
|
59
|
+
enforce: "post",
|
|
60
|
+
config(config, { command, mode }) {
|
|
61
|
+
if (mode === "development" || command === "serve") {
|
|
62
|
+
skip = true;
|
|
63
|
+
return;
|
|
64
|
+
}
|
|
65
|
+
return {
|
|
66
|
+
define: {
|
|
67
|
+
__MOONWATCH_RELEASE__: JSON.stringify(releaseId)
|
|
68
|
+
}
|
|
69
|
+
};
|
|
70
|
+
},
|
|
71
|
+
configResolved(config) {
|
|
72
|
+
resolvedConfig = config;
|
|
73
|
+
},
|
|
74
|
+
async closeBundle() {
|
|
75
|
+
if (skip) return;
|
|
76
|
+
const outDir = resolvedConfig.build.outDir;
|
|
77
|
+
if (uploadedOutDirs.has(outDir)) return;
|
|
78
|
+
uploadedOutDirs.add(outDir);
|
|
79
|
+
const mapFiles = collectMapFiles(outDir);
|
|
80
|
+
if (mapFiles.length === 0) {
|
|
81
|
+
console.log("[Moonwatch] No source map files found, skipping upload");
|
|
82
|
+
return;
|
|
83
|
+
}
|
|
84
|
+
const endpoint = options._endpoint || DEFAULT_ENDPOINT;
|
|
85
|
+
const url = `${endpoint}/sourcemaps/upload`;
|
|
86
|
+
const formData = new FormData();
|
|
87
|
+
formData.append("releaseId", releaseId);
|
|
88
|
+
formData.append("logFileId", options.logFileId);
|
|
89
|
+
for (const mapFile of mapFiles) {
|
|
90
|
+
const content = readFileSync(mapFile);
|
|
91
|
+
const name = relative(outDir, mapFile).replace(/\\/g, "/").replace(/\//g, "_");
|
|
92
|
+
const blob = new Blob([content], { type: "application/json" });
|
|
93
|
+
formData.append("files", blob, name.endsWith(".map") ? name : `${name}.map`);
|
|
94
|
+
}
|
|
95
|
+
try {
|
|
96
|
+
console.log(`[Moonwatch] Uploading ${mapFiles.length} source maps (release: ${releaseId})...`);
|
|
97
|
+
const response = await fetch(url, {
|
|
98
|
+
method: "POST",
|
|
99
|
+
headers: {
|
|
100
|
+
"Authorization": `Bearer ${options.apiKey}`
|
|
101
|
+
},
|
|
102
|
+
body: formData
|
|
103
|
+
});
|
|
104
|
+
if (!response.ok) {
|
|
105
|
+
const body = await response.text();
|
|
106
|
+
console.error(`[Moonwatch] Source map upload failed (${response.status}): ${body}`);
|
|
107
|
+
return;
|
|
108
|
+
}
|
|
109
|
+
const result = await response.json();
|
|
110
|
+
console.log(`[Moonwatch] Uploaded ${result.count} source maps successfully`);
|
|
111
|
+
} catch (err) {
|
|
112
|
+
console.error("[Moonwatch] Source map upload failed:", err);
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
};
|
|
116
|
+
}
|
|
117
|
+
export {
|
|
118
|
+
moonwatchPlugin as default
|
|
119
|
+
};
|
package/package.json
ADDED
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@moonwatch/js",
|
|
3
|
+
"version": "0.1.8",
|
|
4
|
+
"description": "JavaScript SDK for Moonwatch",
|
|
5
|
+
"main": "dist/index.js",
|
|
6
|
+
"module": "dist/index.mjs",
|
|
7
|
+
"types": "dist/index.d.ts",
|
|
8
|
+
"exports": {
|
|
9
|
+
".": {
|
|
10
|
+
"types": "./dist/index.d.ts",
|
|
11
|
+
"require": "./dist/index.js",
|
|
12
|
+
"import": "./dist/index.mjs"
|
|
13
|
+
},
|
|
14
|
+
"./vite": {
|
|
15
|
+
"types": "./dist/vite.d.ts",
|
|
16
|
+
"require": "./dist/vite.js",
|
|
17
|
+
"import": "./dist/vite.mjs"
|
|
18
|
+
}
|
|
19
|
+
},
|
|
20
|
+
"bin": {
|
|
21
|
+
"moonwatch-init": "dist/init.js"
|
|
22
|
+
},
|
|
23
|
+
"files": [
|
|
24
|
+
"dist",
|
|
25
|
+
"SKILL.md"
|
|
26
|
+
],
|
|
27
|
+
"scripts": {
|
|
28
|
+
"build": "tsup src/index.ts src/vite.ts --format cjs,esm --dts && tsup src/init.ts --format cjs --no-dts",
|
|
29
|
+
"dev": "tsup src/index.ts --format cjs,esm --dts --watch",
|
|
30
|
+
"test": "tsx test/test.ts"
|
|
31
|
+
},
|
|
32
|
+
"devDependencies": {
|
|
33
|
+
"serialize-error": "^13.0.1",
|
|
34
|
+
"tsup": "^8.0.0",
|
|
35
|
+
"tsx": "^4.7.0",
|
|
36
|
+
"typescript": "^5.3.0",
|
|
37
|
+
"vite": "^7.3.1"
|
|
38
|
+
},
|
|
39
|
+
"peerDependencies": {
|
|
40
|
+
"vite": ">=5.0.0"
|
|
41
|
+
},
|
|
42
|
+
"peerDependenciesMeta": {
|
|
43
|
+
"vite": {
|
|
44
|
+
"optional": true
|
|
45
|
+
}
|
|
46
|
+
},
|
|
47
|
+
"keywords": [
|
|
48
|
+
"logging",
|
|
49
|
+
"moonwatch",
|
|
50
|
+
"observability"
|
|
51
|
+
],
|
|
52
|
+
"license": "MIT"
|
|
53
|
+
}
|