@sallyqalawi/devlink 0.0.0-stage → 0.1.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/README.md +17 -2
- package/bin/devlink.js +5 -0
- package/dist/cli.cjs +617 -0
- package/dist/cli.cjs.map +1 -0
- package/dist/cli.d.cts +1 -0
- package/dist/cli.d.ts +1 -0
- package/dist/cli.js +590 -0
- package/dist/cli.js.map +1 -0
- package/dist/client.iife.js +238 -0
- package/dist/client.iife.js.map +1 -0
- package/dist/index.cjs +592 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +44 -0
- package/dist/index.d.ts +44 -0
- package/dist/index.js +542 -0
- package/dist/index.js.map +1 -0
- package/dist/nuxt.cjs +544 -0
- package/dist/nuxt.cjs.map +1 -0
- package/dist/nuxt.d.cts +12 -0
- package/dist/nuxt.d.ts +12 -0
- package/dist/nuxt.js +511 -0
- package/dist/nuxt.js.map +1 -0
- package/dist/unplugin-CQjGqwFT.d.cts +53 -0
- package/dist/unplugin-CQjGqwFT.d.ts +53 -0
- package/dist/vite.cjs +548 -0
- package/dist/vite.cjs.map +1 -0
- package/dist/vite.d.cts +23 -0
- package/dist/vite.d.ts +23 -0
- package/dist/vite.js +511 -0
- package/dist/vite.js.map +1 -0
- package/dist/webpack.cjs +540 -0
- package/dist/webpack.cjs.map +1 -0
- package/dist/webpack.d.cts +12 -0
- package/dist/webpack.d.ts +12 -0
- package/dist/webpack.js +507 -0
- package/dist/webpack.js.map +1 -0
- package/package.json +89 -4
package/README.md
CHANGED
|
@@ -1,3 +1,18 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @sallyqalawi/devlink
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Zero-config bridge between localhost and your IDE.
|
|
4
|
+
|
|
5
|
+
```bash
|
|
6
|
+
npm i -D @sallyqalawi/devlink
|
|
7
|
+
npx @sallyqalawi/devlink init
|
|
8
|
+
```
|
|
9
|
+
|
|
10
|
+
```ts
|
|
11
|
+
import devlink from '@sallyqalawi/devlink/vite'
|
|
12
|
+
|
|
13
|
+
export default defineConfig({
|
|
14
|
+
plugins: [devlink()],
|
|
15
|
+
})
|
|
16
|
+
```
|
|
17
|
+
|
|
18
|
+
See the [root README](../../README.md) for full documentation.
|
package/bin/devlink.js
ADDED
package/dist/cli.cjs
ADDED
|
@@ -0,0 +1,617 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
"use strict";
|
|
3
|
+
var __create = Object.create;
|
|
4
|
+
var __defProp = Object.defineProperty;
|
|
5
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
6
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
7
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
8
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
9
|
+
var __copyProps = (to, from, except, desc) => {
|
|
10
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
11
|
+
for (let key of __getOwnPropNames(from))
|
|
12
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
13
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
14
|
+
}
|
|
15
|
+
return to;
|
|
16
|
+
};
|
|
17
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
18
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
19
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
20
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
21
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
22
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
23
|
+
mod
|
|
24
|
+
));
|
|
25
|
+
|
|
26
|
+
// ../../node_modules/tsup/assets/cjs_shims.js
|
|
27
|
+
var getImportMetaUrl = () => typeof document === "undefined" ? new URL(`file:${__filename}`).href : document.currentScript && document.currentScript.tagName.toUpperCase() === "SCRIPT" ? document.currentScript.src : new URL("main.js", document.baseURI).href;
|
|
28
|
+
var importMetaUrl = /* @__PURE__ */ getImportMetaUrl();
|
|
29
|
+
|
|
30
|
+
// src/cli/init.ts
|
|
31
|
+
var import_node_fs2 = __toESM(require("fs"), 1);
|
|
32
|
+
var import_node_path2 = __toESM(require("path"), 1);
|
|
33
|
+
var import_node_os = __toESM(require("os"), 1);
|
|
34
|
+
var import_node_url = require("url");
|
|
35
|
+
|
|
36
|
+
// src/cli/detect.ts
|
|
37
|
+
var import_node_fs = __toESM(require("fs"), 1);
|
|
38
|
+
var import_node_path = __toESM(require("path"), 1);
|
|
39
|
+
function readJson(file) {
|
|
40
|
+
try {
|
|
41
|
+
return JSON.parse(import_node_fs.default.readFileSync(file, "utf8"));
|
|
42
|
+
} catch {
|
|
43
|
+
return null;
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
function firstExisting(root, names) {
|
|
47
|
+
for (const name of names) {
|
|
48
|
+
const p = import_node_path.default.join(root, name);
|
|
49
|
+
if (import_node_fs.default.existsSync(p)) return name;
|
|
50
|
+
}
|
|
51
|
+
return null;
|
|
52
|
+
}
|
|
53
|
+
function detectProject(root = process.cwd()) {
|
|
54
|
+
const pkgPath = import_node_path.default.join(root, "package.json");
|
|
55
|
+
const packageJson = readJson(pkgPath);
|
|
56
|
+
const deps = {
|
|
57
|
+
...packageJson?.dependencies,
|
|
58
|
+
...packageJson?.devDependencies
|
|
59
|
+
};
|
|
60
|
+
const has = (name) => Boolean(deps[name]);
|
|
61
|
+
const hasReact = has("react");
|
|
62
|
+
const hasVue = has("vue") || has("nuxt");
|
|
63
|
+
const viteConfig = firstExisting(root, [
|
|
64
|
+
"vite.config.ts",
|
|
65
|
+
"vite.config.mts",
|
|
66
|
+
"vite.config.js",
|
|
67
|
+
"vite.config.mjs",
|
|
68
|
+
"vite.config.cjs"
|
|
69
|
+
]);
|
|
70
|
+
const nextConfig = firstExisting(root, [
|
|
71
|
+
"next.config.ts",
|
|
72
|
+
"next.config.mjs",
|
|
73
|
+
"next.config.js",
|
|
74
|
+
"next.config.cjs"
|
|
75
|
+
]);
|
|
76
|
+
const nuxtConfig = firstExisting(root, [
|
|
77
|
+
"nuxt.config.ts",
|
|
78
|
+
"nuxt.config.mts",
|
|
79
|
+
"nuxt.config.js",
|
|
80
|
+
"nuxt.config.mjs"
|
|
81
|
+
]);
|
|
82
|
+
const webpackConfig = firstExisting(root, [
|
|
83
|
+
"webpack.config.ts",
|
|
84
|
+
"webpack.config.js",
|
|
85
|
+
"webpack.config.mjs",
|
|
86
|
+
"webpack.config.cjs"
|
|
87
|
+
]);
|
|
88
|
+
if (has("nuxt") || nuxtConfig) {
|
|
89
|
+
return { framework: "nuxt", packageJson, configFile: nuxtConfig, hasReact, hasVue };
|
|
90
|
+
}
|
|
91
|
+
if (has("next") || nextConfig) {
|
|
92
|
+
return { framework: "next", packageJson, configFile: nextConfig, hasReact, hasVue };
|
|
93
|
+
}
|
|
94
|
+
if (has("vite") || viteConfig) {
|
|
95
|
+
return { framework: "vite", packageJson, configFile: viteConfig, hasReact, hasVue };
|
|
96
|
+
}
|
|
97
|
+
if (has("webpack") || has("webpack-dev-server") || webpackConfig) {
|
|
98
|
+
return { framework: "webpack", packageJson, configFile: webpackConfig, hasReact, hasVue };
|
|
99
|
+
}
|
|
100
|
+
const html = firstExisting(root, ["index.html", "public/index.html"]);
|
|
101
|
+
if (html) {
|
|
102
|
+
return { framework: "html", packageJson, configFile: html, hasReact, hasVue };
|
|
103
|
+
}
|
|
104
|
+
return { framework: "unknown", packageJson, configFile: null, hasReact, hasVue };
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
// src/cli/init.ts
|
|
108
|
+
var VSCODE_SETTINGS = {
|
|
109
|
+
"editor.multiCursorModifier": "ctrlCmd"
|
|
110
|
+
};
|
|
111
|
+
var VSCODE_KEYBINDINGS = [
|
|
112
|
+
{
|
|
113
|
+
key: "alt+btn1",
|
|
114
|
+
command: "devlink.flashLine",
|
|
115
|
+
when: "editorTextFocus"
|
|
116
|
+
},
|
|
117
|
+
{
|
|
118
|
+
key: "alt+f",
|
|
119
|
+
command: "devlink.flashLine",
|
|
120
|
+
when: "editorTextFocus"
|
|
121
|
+
}
|
|
122
|
+
];
|
|
123
|
+
var VSCODE_TASKS = {
|
|
124
|
+
version: "2.0.0",
|
|
125
|
+
tasks: [
|
|
126
|
+
{
|
|
127
|
+
label: "devlink: flash line",
|
|
128
|
+
type: "shell",
|
|
129
|
+
command: 'npx @sallyqalawi/devlink flash "${relativeFile}:${lineNumber}"',
|
|
130
|
+
problemMatcher: [],
|
|
131
|
+
presentation: {
|
|
132
|
+
reveal: "silent",
|
|
133
|
+
echo: false,
|
|
134
|
+
focus: false,
|
|
135
|
+
panel: "shared",
|
|
136
|
+
showReuseMessage: false,
|
|
137
|
+
clear: false
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
]
|
|
141
|
+
};
|
|
142
|
+
function log(msg) {
|
|
143
|
+
console.log(` ${msg}`);
|
|
144
|
+
}
|
|
145
|
+
function ensureDir(dir) {
|
|
146
|
+
import_node_fs2.default.mkdirSync(dir, { recursive: true });
|
|
147
|
+
}
|
|
148
|
+
function writeJsonMerge(file, patch) {
|
|
149
|
+
let existing = {};
|
|
150
|
+
if (import_node_fs2.default.existsSync(file)) {
|
|
151
|
+
try {
|
|
152
|
+
existing = JSON.parse(import_node_fs2.default.readFileSync(file, "utf8"));
|
|
153
|
+
} catch {
|
|
154
|
+
existing = {};
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
const merged = { ...existing, ...patch };
|
|
158
|
+
ensureDir(import_node_path2.default.dirname(file));
|
|
159
|
+
import_node_fs2.default.writeFileSync(file, JSON.stringify(merged, null, 2) + "\n", "utf8");
|
|
160
|
+
}
|
|
161
|
+
function injectViteConfig(root, configRel) {
|
|
162
|
+
const configFile = configRel ? import_node_path2.default.join(root, configRel) : import_node_path2.default.join(root, "vite.config.ts");
|
|
163
|
+
if (!import_node_fs2.default.existsSync(configFile)) {
|
|
164
|
+
const content = `import { defineConfig } from 'vite'
|
|
165
|
+
import devlink from '@sallyqalawi/devlink/vite'
|
|
166
|
+
|
|
167
|
+
export default defineConfig({
|
|
168
|
+
plugins: [devlink()],
|
|
169
|
+
})
|
|
170
|
+
`;
|
|
171
|
+
import_node_fs2.default.writeFileSync(configFile, content, "utf8");
|
|
172
|
+
return import_node_path2.default.relative(root, configFile);
|
|
173
|
+
}
|
|
174
|
+
let src = import_node_fs2.default.readFileSync(configFile, "utf8");
|
|
175
|
+
if (src.includes("devlink")) {
|
|
176
|
+
log(`Plugin already present in ${configRel}`);
|
|
177
|
+
return configRel;
|
|
178
|
+
}
|
|
179
|
+
if (!src.includes("from '@sallyqalawi/devlink/vite'") && !src.includes('from "@sallyqalawi/devlink/vite"')) {
|
|
180
|
+
const importLine = `import devlink from '@sallyqalawi/devlink/vite'
|
|
181
|
+
`;
|
|
182
|
+
if (/^import\s/m.test(src)) {
|
|
183
|
+
const lines = src.split("\n");
|
|
184
|
+
let lastImport = 0;
|
|
185
|
+
for (let i = 0; i < lines.length; i++) {
|
|
186
|
+
if (/^import\s/.test(lines[i]) || /^const\s.*=\s*require\(/.test(lines[i])) {
|
|
187
|
+
lastImport = i;
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
lines.splice(lastImport + 1, 0, importLine.trimEnd());
|
|
191
|
+
src = lines.join("\n");
|
|
192
|
+
} else {
|
|
193
|
+
src = importLine + src;
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
if (/plugins\s*:\s*\[/.test(src)) {
|
|
197
|
+
if (!/plugins\s*:\s*\[\s*devlink\s*\(/.test(src)) {
|
|
198
|
+
src = src.replace(/plugins\s*:\s*\[/, "plugins: [devlink(), ");
|
|
199
|
+
}
|
|
200
|
+
} else if (/defineConfig\s*\(\s*\{/.test(src)) {
|
|
201
|
+
src = src.replace(
|
|
202
|
+
/defineConfig\s*\(\s*\{/,
|
|
203
|
+
"defineConfig({\n plugins: [devlink()],"
|
|
204
|
+
);
|
|
205
|
+
} else if (/export\s+default\s*\{/.test(src)) {
|
|
206
|
+
src = src.replace(
|
|
207
|
+
/export\s+default\s*\{/,
|
|
208
|
+
"export default {\n plugins: [devlink()],"
|
|
209
|
+
);
|
|
210
|
+
} else {
|
|
211
|
+
log("Could not auto-inject plugins array \u2014 please add devlink() before other plugins.");
|
|
212
|
+
import_node_fs2.default.writeFileSync(configFile, src, "utf8");
|
|
213
|
+
return import_node_path2.default.relative(root, configFile);
|
|
214
|
+
}
|
|
215
|
+
import_node_fs2.default.writeFileSync(configFile, src, "utf8");
|
|
216
|
+
return import_node_path2.default.relative(root, configFile);
|
|
217
|
+
}
|
|
218
|
+
function injectNextConfig(root, configRel) {
|
|
219
|
+
const configFile = configRel ? import_node_path2.default.join(root, configRel) : import_node_path2.default.join(root, "next.config.mjs");
|
|
220
|
+
const note = `
|
|
221
|
+
/*
|
|
222
|
+
* devlink: For Next.js, install and add the webpack plugin via unplugin:
|
|
223
|
+
*
|
|
224
|
+
* // next.config.js
|
|
225
|
+
* const devlink = require('@sallyqalawi/devlink/webpack')
|
|
226
|
+
* module.exports = {
|
|
227
|
+
* webpack(config, { dev }) {
|
|
228
|
+
* if (dev) config.plugins.push(devlink())
|
|
229
|
+
* return config
|
|
230
|
+
* },
|
|
231
|
+
* }
|
|
232
|
+
*
|
|
233
|
+
* Or use the Vite-based Next experimental setup with @sallyqalawi/devlink/vite.
|
|
234
|
+
*/
|
|
235
|
+
`;
|
|
236
|
+
if (!import_node_fs2.default.existsSync(configFile)) {
|
|
237
|
+
import_node_fs2.default.writeFileSync(
|
|
238
|
+
configFile,
|
|
239
|
+
`/** @type {import('next').NextConfig} */
|
|
240
|
+
const nextConfig = {}
|
|
241
|
+
export default nextConfig
|
|
242
|
+
${note}`,
|
|
243
|
+
"utf8"
|
|
244
|
+
);
|
|
245
|
+
} else {
|
|
246
|
+
let src = import_node_fs2.default.readFileSync(configFile, "utf8");
|
|
247
|
+
if (!src.includes("devlink")) {
|
|
248
|
+
src = note + src;
|
|
249
|
+
import_node_fs2.default.writeFileSync(configFile, src, "utf8");
|
|
250
|
+
}
|
|
251
|
+
}
|
|
252
|
+
return import_node_path2.default.relative(root, configFile);
|
|
253
|
+
}
|
|
254
|
+
function injectNuxtConfig(root, configRel) {
|
|
255
|
+
const configFile = configRel ? import_node_path2.default.join(root, configRel) : import_node_path2.default.join(root, "nuxt.config.ts");
|
|
256
|
+
if (!import_node_fs2.default.existsSync(configFile)) {
|
|
257
|
+
import_node_fs2.default.writeFileSync(
|
|
258
|
+
configFile,
|
|
259
|
+
`import devlink from '@sallyqalawi/devlink/nuxt'
|
|
260
|
+
|
|
261
|
+
export default defineNuxtConfig({
|
|
262
|
+
// @ts-expect-error unplugin nuxt integration
|
|
263
|
+
modules: [devlink()],
|
|
264
|
+
})
|
|
265
|
+
`,
|
|
266
|
+
"utf8"
|
|
267
|
+
);
|
|
268
|
+
return import_node_path2.default.relative(root, configFile);
|
|
269
|
+
}
|
|
270
|
+
let src = import_node_fs2.default.readFileSync(configFile, "utf8");
|
|
271
|
+
if (src.includes("devlink")) {
|
|
272
|
+
log(`Plugin already referenced in ${configRel}`);
|
|
273
|
+
return configRel;
|
|
274
|
+
}
|
|
275
|
+
if (!src.includes("from '@sallyqalawi/devlink/nuxt'")) {
|
|
276
|
+
src = `import devlink from '@sallyqalawi/devlink/nuxt'
|
|
277
|
+
` + src;
|
|
278
|
+
}
|
|
279
|
+
if (/modules\s*:\s*\[/.test(src)) {
|
|
280
|
+
src = src.replace(/modules\s*:\s*\[/, "modules: [devlink(), ");
|
|
281
|
+
} else {
|
|
282
|
+
log("Add devlink() to your Nuxt modules array manually.");
|
|
283
|
+
}
|
|
284
|
+
import_node_fs2.default.writeFileSync(configFile, src, "utf8");
|
|
285
|
+
return import_node_path2.default.relative(root, configFile);
|
|
286
|
+
}
|
|
287
|
+
function injectHtmlFallback(root, htmlRel) {
|
|
288
|
+
const htmlFile = htmlRel ? import_node_path2.default.join(root, htmlRel) : import_node_path2.default.join(root, "index.html");
|
|
289
|
+
if (!import_node_fs2.default.existsSync(htmlFile)) {
|
|
290
|
+
ensureDir(import_node_path2.default.dirname(htmlFile));
|
|
291
|
+
import_node_fs2.default.writeFileSync(
|
|
292
|
+
htmlFile,
|
|
293
|
+
`<!DOCTYPE html>
|
|
294
|
+
<html lang="en">
|
|
295
|
+
<head>
|
|
296
|
+
<meta charset="UTF-8" />
|
|
297
|
+
<title>devlink</title>
|
|
298
|
+
</head>
|
|
299
|
+
<body>
|
|
300
|
+
<script src="/__devlink/client.js"></script>
|
|
301
|
+
</body>
|
|
302
|
+
</html>
|
|
303
|
+
`,
|
|
304
|
+
"utf8"
|
|
305
|
+
);
|
|
306
|
+
return import_node_path2.default.relative(root, htmlFile);
|
|
307
|
+
}
|
|
308
|
+
let src = import_node_fs2.default.readFileSync(htmlFile, "utf8");
|
|
309
|
+
if (!src.includes("/__devlink/client.js")) {
|
|
310
|
+
const tag = '<script src="/__devlink/client.js"></script>';
|
|
311
|
+
if (src.includes("</body>")) {
|
|
312
|
+
src = src.replace("</body>", ` ${tag}
|
|
313
|
+
</body>`);
|
|
314
|
+
} else {
|
|
315
|
+
src += `
|
|
316
|
+
${tag}
|
|
317
|
+
`;
|
|
318
|
+
}
|
|
319
|
+
import_node_fs2.default.writeFileSync(htmlFile, src, "utf8");
|
|
320
|
+
}
|
|
321
|
+
return import_node_path2.default.relative(root, htmlFile);
|
|
322
|
+
}
|
|
323
|
+
function findExtensionSource() {
|
|
324
|
+
const candidates = [
|
|
325
|
+
// Monorepo checkout
|
|
326
|
+
import_node_path2.default.resolve(process.cwd(), "packages/devlink-vscode"),
|
|
327
|
+
import_node_path2.default.resolve(process.cwd(), "../packages/devlink-vscode"),
|
|
328
|
+
import_node_path2.default.resolve(process.cwd(), "../../packages/devlink-vscode")
|
|
329
|
+
];
|
|
330
|
+
try {
|
|
331
|
+
const here = import_node_path2.default.dirname((0, import_node_url.fileURLToPath)(importMetaUrl));
|
|
332
|
+
candidates.push(import_node_path2.default.resolve(here, "../../devlink-vscode"));
|
|
333
|
+
candidates.push(import_node_path2.default.resolve(here, "../../../devlink-vscode"));
|
|
334
|
+
} catch {
|
|
335
|
+
}
|
|
336
|
+
for (const c of candidates) {
|
|
337
|
+
if (import_node_fs2.default.existsSync(import_node_path2.default.join(c, "package.json")) && import_node_fs2.default.existsSync(import_node_path2.default.join(c, "extension.js"))) {
|
|
338
|
+
return c;
|
|
339
|
+
}
|
|
340
|
+
}
|
|
341
|
+
return null;
|
|
342
|
+
}
|
|
343
|
+
function installCompanionExtension() {
|
|
344
|
+
const source = findExtensionSource();
|
|
345
|
+
if (!source) {
|
|
346
|
+
log("Companion extension source not found \u2014 Alt+Click in IDE needs packages/devlink-vscode");
|
|
347
|
+
return false;
|
|
348
|
+
}
|
|
349
|
+
const home = import_node_os.default.homedir();
|
|
350
|
+
const targets = [
|
|
351
|
+
import_node_path2.default.join(home, ".cursor", "extensions", "devlink.devlink-0.1.0"),
|
|
352
|
+
import_node_path2.default.join(home, ".vscode", "extensions", "devlink.devlink-0.1.0")
|
|
353
|
+
];
|
|
354
|
+
for (const target of targets) {
|
|
355
|
+
try {
|
|
356
|
+
ensureDir(import_node_path2.default.dirname(target));
|
|
357
|
+
import_node_fs2.default.rmSync(target, { recursive: true, force: true });
|
|
358
|
+
import_node_fs2.default.cpSync(source, target, { recursive: true });
|
|
359
|
+
log(`Installed companion extension \u2192 ${target}`);
|
|
360
|
+
} catch (err) {
|
|
361
|
+
log(`Could not install extension to ${target}: ${String(err)}`);
|
|
362
|
+
}
|
|
363
|
+
}
|
|
364
|
+
return true;
|
|
365
|
+
}
|
|
366
|
+
function setupIde(root) {
|
|
367
|
+
const vscodeDir = import_node_path2.default.join(root, ".vscode");
|
|
368
|
+
ensureDir(vscodeDir);
|
|
369
|
+
const settingsPath = import_node_path2.default.join(vscodeDir, "settings.json");
|
|
370
|
+
writeJsonMerge(settingsPath, VSCODE_SETTINGS);
|
|
371
|
+
log("Updated .vscode/settings.json (editor.multiCursorModifier \u2192 ctrlCmd)");
|
|
372
|
+
const tasksPath = import_node_path2.default.join(vscodeDir, "tasks.json");
|
|
373
|
+
if (!import_node_fs2.default.existsSync(tasksPath)) {
|
|
374
|
+
import_node_fs2.default.writeFileSync(tasksPath, JSON.stringify(VSCODE_TASKS, null, 2) + "\n", "utf8");
|
|
375
|
+
log("Created .vscode/tasks.json (devlink: flash line)");
|
|
376
|
+
} else {
|
|
377
|
+
try {
|
|
378
|
+
const tasks = JSON.parse(import_node_fs2.default.readFileSync(tasksPath, "utf8"));
|
|
379
|
+
const has = tasks.tasks?.some((t) => t.label === "devlink: flash line");
|
|
380
|
+
if (!has) {
|
|
381
|
+
tasks.tasks = [...tasks.tasks || [], ...VSCODE_TASKS.tasks];
|
|
382
|
+
import_node_fs2.default.writeFileSync(tasksPath, JSON.stringify(tasks, null, 2) + "\n", "utf8");
|
|
383
|
+
log("Added flash task to .vscode/tasks.json");
|
|
384
|
+
} else {
|
|
385
|
+
log("Flash task already in .vscode/tasks.json");
|
|
386
|
+
}
|
|
387
|
+
} catch {
|
|
388
|
+
log("Could not merge tasks.json \u2014 leaving as-is");
|
|
389
|
+
}
|
|
390
|
+
}
|
|
391
|
+
import_node_fs2.default.writeFileSync(
|
|
392
|
+
import_node_path2.default.join(vscodeDir, "extensions.json"),
|
|
393
|
+
JSON.stringify({ recommendations: ["devlink.devlink"] }, null, 2) + "\n",
|
|
394
|
+
"utf8"
|
|
395
|
+
);
|
|
396
|
+
const hintPath = import_node_path2.default.join(vscodeDir, "devlink.keybindings.json");
|
|
397
|
+
import_node_fs2.default.writeFileSync(
|
|
398
|
+
hintPath,
|
|
399
|
+
JSON.stringify(
|
|
400
|
+
{
|
|
401
|
+
_comment: "These bindings are provided by the devlink companion extension (Alt+F). Reload the window after init if the shortcut does nothing.",
|
|
402
|
+
keybindings: VSCODE_KEYBINDINGS
|
|
403
|
+
},
|
|
404
|
+
null,
|
|
405
|
+
2
|
|
406
|
+
) + "\n",
|
|
407
|
+
"utf8"
|
|
408
|
+
);
|
|
409
|
+
const installed = installCompanionExtension();
|
|
410
|
+
if (installed) {
|
|
411
|
+
log("Reload Cursor/VS Code window to activate Alt+Click \u2192 browser flash");
|
|
412
|
+
}
|
|
413
|
+
}
|
|
414
|
+
function ensureDependency(root) {
|
|
415
|
+
const pkgPath = import_node_path2.default.join(root, "package.json");
|
|
416
|
+
if (!import_node_fs2.default.existsSync(pkgPath)) return;
|
|
417
|
+
const pkg = JSON.parse(import_node_fs2.default.readFileSync(pkgPath, "utf8"));
|
|
418
|
+
const all = { ...pkg.dependencies, ...pkg.devDependencies };
|
|
419
|
+
if (all["@sallyqalawi/devlink"]) {
|
|
420
|
+
log("@sallyqalawi/devlink already in package.json");
|
|
421
|
+
return;
|
|
422
|
+
}
|
|
423
|
+
pkg.devDependencies = {
|
|
424
|
+
...pkg.devDependencies || {},
|
|
425
|
+
"@sallyqalawi/devlink": "^0.1.0"
|
|
426
|
+
};
|
|
427
|
+
import_node_fs2.default.writeFileSync(pkgPath, JSON.stringify(pkg, null, 2) + "\n", "utf8");
|
|
428
|
+
log("Added @sallyqalawi/devlink to devDependencies \u2014 run npm install");
|
|
429
|
+
}
|
|
430
|
+
async function runInit(cwd = process.cwd()) {
|
|
431
|
+
console.log("\n\u2693 devlink init\n");
|
|
432
|
+
const detected = detectProject(cwd);
|
|
433
|
+
log(`Detected: ${detected.framework}${detected.configFile ? ` (${detected.configFile})` : ""}`);
|
|
434
|
+
ensureDependency(cwd);
|
|
435
|
+
let touched;
|
|
436
|
+
const fw = detected.framework;
|
|
437
|
+
switch (fw) {
|
|
438
|
+
case "vite":
|
|
439
|
+
touched = injectViteConfig(cwd, detected.configFile);
|
|
440
|
+
log(`Injected devlink() into ${touched}`);
|
|
441
|
+
break;
|
|
442
|
+
case "next":
|
|
443
|
+
touched = injectNextConfig(cwd, detected.configFile);
|
|
444
|
+
log(`Annotated ${touched} with Next.js setup notes`);
|
|
445
|
+
break;
|
|
446
|
+
case "nuxt":
|
|
447
|
+
touched = injectNuxtConfig(cwd, detected.configFile);
|
|
448
|
+
log(`Configured ${touched}`);
|
|
449
|
+
break;
|
|
450
|
+
case "webpack":
|
|
451
|
+
log("Webpack detected \u2014 add @sallyqalawi/devlink/webpack to your plugins and wire /__devlink middleware in devServer.setupMiddlewares. See README.");
|
|
452
|
+
touched = detected.configFile || "webpack.config.js";
|
|
453
|
+
break;
|
|
454
|
+
case "html":
|
|
455
|
+
touched = injectHtmlFallback(cwd, detected.configFile);
|
|
456
|
+
log(`Injected client script into ${touched}`);
|
|
457
|
+
break;
|
|
458
|
+
default:
|
|
459
|
+
touched = injectViteConfig(cwd, null);
|
|
460
|
+
log(`Created ${touched} with devlink() (fallback)`);
|
|
461
|
+
}
|
|
462
|
+
setupIde(cwd);
|
|
463
|
+
console.log(`
|
|
464
|
+
Done. Next steps:
|
|
465
|
+
|
|
466
|
+
1. npm install # if devlink was just added
|
|
467
|
+
2. Reload the Cursor/VS Code window (Cmd/Ctrl+Shift+P \u2192 "Reload Window")
|
|
468
|
+
3. Restart your dev server
|
|
469
|
+
4. Browser: Alt+Click a UI element \u2192 jumps to code with a line flash
|
|
470
|
+
5. IDE: Alt+F on a source line \u2192 flashes the matching DOM in the browser
|
|
471
|
+
|
|
472
|
+
Multi-cursor is now Ctrl/Cmd+Click so Alt+Click is free in the browser.
|
|
473
|
+
|
|
474
|
+
`);
|
|
475
|
+
}
|
|
476
|
+
|
|
477
|
+
// src/utils.ts
|
|
478
|
+
var import_node_fs3 = __toESM(require("fs"), 1);
|
|
479
|
+
var import_node_path3 = __toESM(require("path"), 1);
|
|
480
|
+
var import_node_os2 = __toESM(require("os"), 1);
|
|
481
|
+
var PORT_FILE = ".devlink/port";
|
|
482
|
+
function getPortFilePath(root) {
|
|
483
|
+
const base = root ?? process.cwd();
|
|
484
|
+
return import_node_path3.default.join(base, PORT_FILE);
|
|
485
|
+
}
|
|
486
|
+
function readPortFile(root) {
|
|
487
|
+
const candidates = [
|
|
488
|
+
getPortFilePath(root),
|
|
489
|
+
getPortFilePath(process.cwd()),
|
|
490
|
+
import_node_path3.default.join(import_node_os2.default.tmpdir(), "devlink-port.json")
|
|
491
|
+
];
|
|
492
|
+
for (const file of candidates) {
|
|
493
|
+
try {
|
|
494
|
+
if (import_node_fs3.default.existsSync(file)) {
|
|
495
|
+
const data = JSON.parse(import_node_fs3.default.readFileSync(file, "utf8"));
|
|
496
|
+
if (data.port) return { port: data.port, host: data.host ?? "localhost" };
|
|
497
|
+
}
|
|
498
|
+
} catch {
|
|
499
|
+
}
|
|
500
|
+
}
|
|
501
|
+
return null;
|
|
502
|
+
}
|
|
503
|
+
|
|
504
|
+
// src/cli/flash.ts
|
|
505
|
+
var COMMON_PORTS = [5173, 5174, 3e3, 3001, 4173, 8080, 4200, 8e3];
|
|
506
|
+
async function tryFlash(host, port, loc) {
|
|
507
|
+
const url = `http://${host}:${port}/__devlink/flash?loc=${encodeURIComponent(loc)}`;
|
|
508
|
+
try {
|
|
509
|
+
const res = await fetch(url, { signal: AbortSignal.timeout(1500) });
|
|
510
|
+
if (!res.ok) return false;
|
|
511
|
+
const data = await res.json();
|
|
512
|
+
return Boolean(data.ok);
|
|
513
|
+
} catch {
|
|
514
|
+
return false;
|
|
515
|
+
}
|
|
516
|
+
}
|
|
517
|
+
async function runFlash(loc, opts = {}) {
|
|
518
|
+
if (!loc) {
|
|
519
|
+
console.error("Usage: npx @sallyqalawi/devlink flash <file:line>");
|
|
520
|
+
process.exitCode = 1;
|
|
521
|
+
return;
|
|
522
|
+
}
|
|
523
|
+
let normalized = loc;
|
|
524
|
+
const lineMatch = loc.match(/^(.*):(\d+)(?::(\d+))?$/);
|
|
525
|
+
if (lineMatch) {
|
|
526
|
+
normalized = `${lineMatch[1].replace(/\\/g, "/")}:${lineMatch[2]}${lineMatch[3] ? ":" + lineMatch[3] : ""}`;
|
|
527
|
+
}
|
|
528
|
+
const host = opts.host ?? "localhost";
|
|
529
|
+
if (opts.port) {
|
|
530
|
+
const ok = await tryFlash(host, opts.port, normalized);
|
|
531
|
+
if (ok) {
|
|
532
|
+
console.log(`\u26A1 Flashed ${normalized} via :${opts.port}`);
|
|
533
|
+
return;
|
|
534
|
+
}
|
|
535
|
+
console.error(`No devlink server at ${host}:${opts.port}`);
|
|
536
|
+
process.exitCode = 1;
|
|
537
|
+
return;
|
|
538
|
+
}
|
|
539
|
+
const saved = readPortFile(opts.cwd);
|
|
540
|
+
const ports = [];
|
|
541
|
+
if (saved?.port) ports.push(saved.port);
|
|
542
|
+
for (const p of COMMON_PORTS) {
|
|
543
|
+
if (!ports.includes(p)) ports.push(p);
|
|
544
|
+
}
|
|
545
|
+
for (const port of ports) {
|
|
546
|
+
const ok = await tryFlash(saved?.host ?? host, port, normalized);
|
|
547
|
+
if (ok) {
|
|
548
|
+
console.log(`\u26A1 Flashed ${normalized} via :${port}`);
|
|
549
|
+
return;
|
|
550
|
+
}
|
|
551
|
+
}
|
|
552
|
+
console.error(
|
|
553
|
+
`Could not reach a devlink server.
|
|
554
|
+
Make sure your app is running with the devlink plugin, then retry.
|
|
555
|
+
Tip: npx @sallyqalawi/devlink flash ${normalized} --port 5173`
|
|
556
|
+
);
|
|
557
|
+
process.exitCode = 1;
|
|
558
|
+
}
|
|
559
|
+
|
|
560
|
+
// src/cli/index.ts
|
|
561
|
+
function printHelp() {
|
|
562
|
+
console.log(`
|
|
563
|
+
\u2693 devlink \u2014 bridge between localhost and your IDE
|
|
564
|
+
|
|
565
|
+
Usage:
|
|
566
|
+
devlink init Inject plugin + IDE settings into the current project
|
|
567
|
+
devlink flash <file:line> Scroll & highlight matching DOM in the open localhost tab
|
|
568
|
+
devlink help Show this message
|
|
569
|
+
|
|
570
|
+
Options for flash:
|
|
571
|
+
--port <n> Dev server port (default: auto-detect)
|
|
572
|
+
--host <host> Dev server host (default: localhost)
|
|
573
|
+
|
|
574
|
+
Examples:
|
|
575
|
+
npx @sallyqalawi/devlink init
|
|
576
|
+
npx @sallyqalawi/devlink flash src/App.tsx:42
|
|
577
|
+
npx @sallyqalawi/devlink flash src/App.tsx:42 --port 5173
|
|
578
|
+
`);
|
|
579
|
+
}
|
|
580
|
+
async function main() {
|
|
581
|
+
const args = process.argv.slice(2);
|
|
582
|
+
const cmd = args[0];
|
|
583
|
+
if (!cmd || cmd === "help" || cmd === "--help" || cmd === "-h") {
|
|
584
|
+
printHelp();
|
|
585
|
+
return;
|
|
586
|
+
}
|
|
587
|
+
if (cmd === "init") {
|
|
588
|
+
await runInit(process.cwd());
|
|
589
|
+
return;
|
|
590
|
+
}
|
|
591
|
+
if (cmd === "flash") {
|
|
592
|
+
const loc = args[1];
|
|
593
|
+
let port;
|
|
594
|
+
let host;
|
|
595
|
+
for (let i = 2; i < args.length; i++) {
|
|
596
|
+
if (args[i] === "--port" && args[i + 1]) {
|
|
597
|
+
port = Number(args[++i]);
|
|
598
|
+
} else if (args[i] === "--host" && args[i + 1]) {
|
|
599
|
+
host = args[++i];
|
|
600
|
+
} else if (args[i]?.startsWith("--port=")) {
|
|
601
|
+
port = Number(args[i].slice("--port=".length));
|
|
602
|
+
} else if (args[i]?.startsWith("--host=")) {
|
|
603
|
+
host = args[i].slice("--host=".length);
|
|
604
|
+
}
|
|
605
|
+
}
|
|
606
|
+
await runFlash(loc, { port, host, cwd: process.cwd() });
|
|
607
|
+
return;
|
|
608
|
+
}
|
|
609
|
+
console.error(`Unknown command: ${cmd}`);
|
|
610
|
+
printHelp();
|
|
611
|
+
process.exitCode = 1;
|
|
612
|
+
}
|
|
613
|
+
main().catch((err) => {
|
|
614
|
+
console.error(err);
|
|
615
|
+
process.exitCode = 1;
|
|
616
|
+
});
|
|
617
|
+
//# sourceMappingURL=cli.cjs.map
|