cc-prompter 0.2.1 → 0.3.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/README.md +65 -14
- package/dist/client-entry.js +17 -0
- package/dist/index.cjs +203 -27
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +53 -1
- package/dist/index.d.ts +53 -1
- package/dist/index.js +221 -25
- package/dist/index.js.map +1 -1
- package/dist/inject.js +46 -9
- package/dist/next-plugin.cjs +1148 -0
- package/dist/next-plugin.cjs.map +1 -0
- package/dist/next-plugin.d.cts +44 -0
- package/dist/next-plugin.d.ts +44 -0
- package/dist/next-plugin.js +1131 -0
- package/dist/next-plugin.js.map +1 -0
- package/dist/webpack-plugin.cjs +1078 -0
- package/dist/webpack-plugin.cjs.map +1 -0
- package/dist/webpack-plugin.d.cts +42 -0
- package/dist/webpack-plugin.d.ts +42 -0
- package/dist/webpack-plugin.js +1047 -0
- package/dist/webpack-plugin.js.map +1 -0
- package/package.json +23 -2
package/dist/index.js
CHANGED
|
@@ -1,3 +1,65 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
+
var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require : typeof Proxy !== "undefined" ? new Proxy(x, {
|
|
6
|
+
get: (a, b) => (typeof require !== "undefined" ? require : a)[b]
|
|
7
|
+
}) : x)(function(x) {
|
|
8
|
+
if (typeof require !== "undefined") return require.apply(this, arguments);
|
|
9
|
+
throw Error('Dynamic require of "' + x + '" is not supported');
|
|
10
|
+
});
|
|
11
|
+
var __esm = (fn, res) => function __init() {
|
|
12
|
+
return fn && (res = (0, fn[__getOwnPropNames(fn)[0]])(fn = 0)), res;
|
|
13
|
+
};
|
|
14
|
+
var __export = (target, all) => {
|
|
15
|
+
for (var name in all)
|
|
16
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
17
|
+
};
|
|
18
|
+
var __copyProps = (to, from, except, desc) => {
|
|
19
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
20
|
+
for (let key of __getOwnPropNames(from))
|
|
21
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
22
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
23
|
+
}
|
|
24
|
+
return to;
|
|
25
|
+
};
|
|
26
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
27
|
+
|
|
28
|
+
// src/assets.ts
|
|
29
|
+
var assets_exports = {};
|
|
30
|
+
__export(assets_exports, {
|
|
31
|
+
getInjectScript: () => getInjectScript,
|
|
32
|
+
getPanelHtml: () => getPanelHtml
|
|
33
|
+
});
|
|
34
|
+
import { readFileSync, existsSync as existsSync2 } from "fs";
|
|
35
|
+
import { join as join2, dirname as dirname2 } from "path";
|
|
36
|
+
import { fileURLToPath as fileURLToPath2 } from "url";
|
|
37
|
+
function assetPath(filename) {
|
|
38
|
+
const here = join2(_dirname, filename);
|
|
39
|
+
if (existsSync2(here)) return here;
|
|
40
|
+
const parent = join2(_dirname, "..", filename);
|
|
41
|
+
if (existsSync2(parent)) return parent;
|
|
42
|
+
throw new Error(
|
|
43
|
+
`[cc-prompter] Asset not found: ${filename}
|
|
44
|
+
Tried: ${here}
|
|
45
|
+
Tried: ${parent}
|
|
46
|
+
__dirname: ${_dirname}`
|
|
47
|
+
);
|
|
48
|
+
}
|
|
49
|
+
function getPanelHtml() {
|
|
50
|
+
return readFileSync(assetPath("panel.html"), "utf8");
|
|
51
|
+
}
|
|
52
|
+
function getInjectScript() {
|
|
53
|
+
return readFileSync(assetPath("inject.js"), "utf8");
|
|
54
|
+
}
|
|
55
|
+
var _dirname;
|
|
56
|
+
var init_assets = __esm({
|
|
57
|
+
"src/assets.ts"() {
|
|
58
|
+
"use strict";
|
|
59
|
+
_dirname = typeof __dirname !== "undefined" ? __dirname : dirname2(fileURLToPath2(import.meta.url));
|
|
60
|
+
}
|
|
61
|
+
});
|
|
62
|
+
|
|
1
63
|
// src/vite-plugin.ts
|
|
2
64
|
import { codeInspectorPlugin } from "code-inspector-plugin";
|
|
3
65
|
|
|
@@ -675,31 +737,8 @@ var PtySession = class extends EventEmitter {
|
|
|
675
737
|
}
|
|
676
738
|
};
|
|
677
739
|
|
|
678
|
-
// src/assets.ts
|
|
679
|
-
import { readFileSync, existsSync as existsSync2 } from "fs";
|
|
680
|
-
import { join as join2, dirname as dirname2 } from "path";
|
|
681
|
-
import { fileURLToPath as fileURLToPath2 } from "url";
|
|
682
|
-
var _dirname = typeof __dirname !== "undefined" ? __dirname : dirname2(fileURLToPath2(import.meta.url));
|
|
683
|
-
function assetPath(filename) {
|
|
684
|
-
const here = join2(_dirname, filename);
|
|
685
|
-
if (existsSync2(here)) return here;
|
|
686
|
-
const parent = join2(_dirname, "..", filename);
|
|
687
|
-
if (existsSync2(parent)) return parent;
|
|
688
|
-
throw new Error(
|
|
689
|
-
`[cc-prompter] Asset not found: ${filename}
|
|
690
|
-
Tried: ${here}
|
|
691
|
-
Tried: ${parent}
|
|
692
|
-
__dirname: ${_dirname}`
|
|
693
|
-
);
|
|
694
|
-
}
|
|
695
|
-
function getPanelHtml() {
|
|
696
|
-
return readFileSync(assetPath("panel.html"), "utf8");
|
|
697
|
-
}
|
|
698
|
-
function getInjectScript() {
|
|
699
|
-
return readFileSync(assetPath("inject.js"), "utf8");
|
|
700
|
-
}
|
|
701
|
-
|
|
702
740
|
// src/sidecar.ts
|
|
741
|
+
init_assets();
|
|
703
742
|
var SessionManager = class {
|
|
704
743
|
sessions = /* @__PURE__ */ new Map();
|
|
705
744
|
counter = 0;
|
|
@@ -908,10 +947,18 @@ function startSidecar(projectRoot, options) {
|
|
|
908
947
|
res.json(session.getHistory());
|
|
909
948
|
});
|
|
910
949
|
const server = createServer(app);
|
|
950
|
+
let actualPort = startPort;
|
|
951
|
+
app.get("/__cc-port", (_req, res) => {
|
|
952
|
+
const addr = server.address();
|
|
953
|
+
const port = addr && typeof addr === "object" ? addr.port : actualPort;
|
|
954
|
+
res.setHeader("Access-Control-Allow-Origin", "*");
|
|
955
|
+
res.end(String(port));
|
|
956
|
+
});
|
|
911
957
|
const MAX_PORT = startPort + 10;
|
|
912
958
|
function tryListen(port) {
|
|
913
959
|
return new Promise((resolve2, reject) => {
|
|
914
960
|
server.listen(port, () => {
|
|
961
|
+
actualPort = port;
|
|
915
962
|
console.log(`[cc-prompter] Sidecar running on http://localhost:${port}`);
|
|
916
963
|
resolve2(server);
|
|
917
964
|
});
|
|
@@ -935,6 +982,7 @@ function startSidecar(projectRoot, options) {
|
|
|
935
982
|
}
|
|
936
983
|
|
|
937
984
|
// src/vite-plugin.ts
|
|
985
|
+
init_assets();
|
|
938
986
|
function ccPromptPlugin(options) {
|
|
939
987
|
const enableInspector = options?.inspector !== false;
|
|
940
988
|
let projectRoot = process.cwd();
|
|
@@ -1007,7 +1055,155 @@ function ccPromptPlugin(options) {
|
|
|
1007
1055
|
if (inspectorPlugin) plugins.unshift(inspectorPlugin);
|
|
1008
1056
|
return plugins;
|
|
1009
1057
|
}
|
|
1058
|
+
|
|
1059
|
+
// src/webpack-plugin.ts
|
|
1060
|
+
import { join as join3, dirname as dirname3 } from "path";
|
|
1061
|
+
import { fileURLToPath as fileURLToPath3 } from "url";
|
|
1062
|
+
import { codeInspectorPlugin as codeInspectorPlugin2 } from "code-inspector-plugin";
|
|
1063
|
+
init_assets();
|
|
1064
|
+
var _dirname2 = typeof __dirname !== "undefined" ? __dirname : dirname3(fileURLToPath3(import.meta.url));
|
|
1065
|
+
var CcPromptWebpackPlugin = class {
|
|
1066
|
+
options;
|
|
1067
|
+
sidecarServer = null;
|
|
1068
|
+
sidecarStarted = false;
|
|
1069
|
+
cleanedUp = false;
|
|
1070
|
+
constructor(options) {
|
|
1071
|
+
this.options = options || {};
|
|
1072
|
+
}
|
|
1073
|
+
apply(compiler) {
|
|
1074
|
+
const isDev = this.options.dev !== void 0 ? this.options.dev : process.env.NODE_ENV !== "production";
|
|
1075
|
+
if (!isDev) return;
|
|
1076
|
+
const startPort = this.options.port || 3456;
|
|
1077
|
+
const clientEntryPath = join3(_dirname2, "client-entry.js");
|
|
1078
|
+
if (!this.sidecarStarted) {
|
|
1079
|
+
this.sidecarStarted = true;
|
|
1080
|
+
const projectRoot = this.options.root || process.cwd();
|
|
1081
|
+
this.sidecarServer = startSidecar(projectRoot, { startPort });
|
|
1082
|
+
}
|
|
1083
|
+
compiler.hooks.thisCompilation.tap("CcPromptWebpackPlugin", () => {
|
|
1084
|
+
if (!this.cleanedUp) {
|
|
1085
|
+
this.setupCleanup();
|
|
1086
|
+
}
|
|
1087
|
+
});
|
|
1088
|
+
if (this.options.inspector !== false) {
|
|
1089
|
+
const inspectorPlugin = codeInspectorPlugin2({
|
|
1090
|
+
bundler: "webpack",
|
|
1091
|
+
behavior: {
|
|
1092
|
+
locate: false,
|
|
1093
|
+
copy: false
|
|
1094
|
+
},
|
|
1095
|
+
hideDomPathAttr: true,
|
|
1096
|
+
hideConsole: true
|
|
1097
|
+
});
|
|
1098
|
+
if (inspectorPlugin && typeof inspectorPlugin.apply === "function") {
|
|
1099
|
+
inspectorPlugin.apply(compiler);
|
|
1100
|
+
} else if (Array.isArray(inspectorPlugin)) {
|
|
1101
|
+
for (const p of inspectorPlugin) {
|
|
1102
|
+
if (p && typeof p.apply === "function") p.apply(compiler);
|
|
1103
|
+
}
|
|
1104
|
+
}
|
|
1105
|
+
}
|
|
1106
|
+
const webpack = __require("webpack");
|
|
1107
|
+
const injectScript = getInjectScript();
|
|
1108
|
+
new webpack.DefinePlugin({
|
|
1109
|
+
"__CC_PROMPTER_INJECT_SCRIPT__": JSON.stringify(injectScript),
|
|
1110
|
+
"__CC_PROMPTER_PORT__": JSON.stringify(startPort)
|
|
1111
|
+
}).apply(compiler);
|
|
1112
|
+
const originalEntry = compiler.options.entry;
|
|
1113
|
+
compiler.options.entry = async () => {
|
|
1114
|
+
const entries = typeof originalEntry === "function" ? await originalEntry() : originalEntry;
|
|
1115
|
+
if (typeof entries === "string") {
|
|
1116
|
+
return { main: [clientEntryPath, entries] };
|
|
1117
|
+
}
|
|
1118
|
+
if (Array.isArray(entries)) {
|
|
1119
|
+
return { main: [clientEntryPath, ...entries] };
|
|
1120
|
+
}
|
|
1121
|
+
if (typeof entries === "object") {
|
|
1122
|
+
for (const key in entries) {
|
|
1123
|
+
if (Array.isArray(entries[key])) {
|
|
1124
|
+
entries[key].unshift(clientEntryPath);
|
|
1125
|
+
} else if (typeof entries[key] === "string") {
|
|
1126
|
+
entries[key] = [clientEntryPath, entries[key]];
|
|
1127
|
+
}
|
|
1128
|
+
}
|
|
1129
|
+
}
|
|
1130
|
+
return entries;
|
|
1131
|
+
};
|
|
1132
|
+
}
|
|
1133
|
+
setupCleanup() {
|
|
1134
|
+
const cleanup = () => {
|
|
1135
|
+
if (this.cleanedUp) return;
|
|
1136
|
+
this.cleanedUp = true;
|
|
1137
|
+
if (this.sidecarServer) {
|
|
1138
|
+
this.sidecarServer.close();
|
|
1139
|
+
this.sidecarServer = null;
|
|
1140
|
+
}
|
|
1141
|
+
};
|
|
1142
|
+
process.on("SIGTERM", () => {
|
|
1143
|
+
cleanup();
|
|
1144
|
+
process.exit(0);
|
|
1145
|
+
});
|
|
1146
|
+
process.on("SIGINT", () => {
|
|
1147
|
+
cleanup();
|
|
1148
|
+
process.exit(0);
|
|
1149
|
+
});
|
|
1150
|
+
process.on("exit", cleanup);
|
|
1151
|
+
}
|
|
1152
|
+
};
|
|
1153
|
+
|
|
1154
|
+
// src/next-plugin.ts
|
|
1155
|
+
function withCcPrompt(options) {
|
|
1156
|
+
return function(nextConfig = {}) {
|
|
1157
|
+
return Object.assign({}, nextConfig, {
|
|
1158
|
+
webpack(config, context) {
|
|
1159
|
+
if (context.dev && !context.isServer) {
|
|
1160
|
+
const plugin = new CcPromptWebpackPlugin({
|
|
1161
|
+
...options,
|
|
1162
|
+
dev: true
|
|
1163
|
+
});
|
|
1164
|
+
plugin.apply(config._compiler || { options: config, hooks: {} });
|
|
1165
|
+
const startPort = options?.port || 3456;
|
|
1166
|
+
const webpack = __require("webpack");
|
|
1167
|
+
if (options?.inspector !== false) {
|
|
1168
|
+
const { codeInspectorPlugin: codeInspectorPlugin3 } = __require("code-inspector-plugin");
|
|
1169
|
+
config.plugins = config.plugins || [];
|
|
1170
|
+
config.plugins.push(codeInspectorPlugin3({
|
|
1171
|
+
bundler: "webpack",
|
|
1172
|
+
behavior: { locate: false, copy: false },
|
|
1173
|
+
hideDomPathAttr: true,
|
|
1174
|
+
hideConsole: true
|
|
1175
|
+
}));
|
|
1176
|
+
}
|
|
1177
|
+
const { getInjectScript: getInjectScript2 } = (init_assets(), __toCommonJS(assets_exports));
|
|
1178
|
+
config.plugins.push(new webpack.DefinePlugin({
|
|
1179
|
+
"__CC_PROMPTER_INJECT_SCRIPT__": JSON.stringify(getInjectScript2()),
|
|
1180
|
+
"__CC_PROMPTER_PORT__": JSON.stringify(startPort)
|
|
1181
|
+
}));
|
|
1182
|
+
const { join: join4, dirname: dirname4 } = __require("path");
|
|
1183
|
+
const _dirname3 = typeof __dirname !== "undefined" ? __dirname : dirname4(__require("url").fileURLToPath(import.meta.url));
|
|
1184
|
+
const clientEntryPath = join4(_dirname3, "client-entry.js");
|
|
1185
|
+
const originalEntry = config.entry;
|
|
1186
|
+
config.entry = async () => {
|
|
1187
|
+
const entries = typeof originalEntry === "function" ? await originalEntry() : originalEntry;
|
|
1188
|
+
for (const key in entries) {
|
|
1189
|
+
if (Array.isArray(entries[key])) {
|
|
1190
|
+
entries[key].unshift(clientEntryPath);
|
|
1191
|
+
}
|
|
1192
|
+
}
|
|
1193
|
+
return entries;
|
|
1194
|
+
};
|
|
1195
|
+
}
|
|
1196
|
+
if (typeof nextConfig.webpack === "function") {
|
|
1197
|
+
return nextConfig.webpack(config, context);
|
|
1198
|
+
}
|
|
1199
|
+
return config;
|
|
1200
|
+
}
|
|
1201
|
+
});
|
|
1202
|
+
};
|
|
1203
|
+
}
|
|
1010
1204
|
export {
|
|
1011
|
-
|
|
1205
|
+
CcPromptWebpackPlugin,
|
|
1206
|
+
ccPromptPlugin,
|
|
1207
|
+
withCcPrompt
|
|
1012
1208
|
};
|
|
1013
1209
|
//# sourceMappingURL=index.js.map
|