@codepress/codepress-engine 0.4.0-dev.tsc.20251014034858
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/LICENSE +11 -0
- package/README.md +176 -0
- package/dist/cli.d.ts +2 -0
- package/dist/cli.js +188 -0
- package/dist/cli.js.map +1 -0
- package/dist/hash-util.d.ts +15 -0
- package/dist/hash-util.js +55 -0
- package/dist/hash-util.js.map +1 -0
- package/dist/index.d.ts +16 -0
- package/dist/index.js +175 -0
- package/dist/index.js.map +1 -0
- package/dist/server.d.ts +29 -0
- package/dist/server.js +1076 -0
- package/dist/server.js.map +1 -0
- package/dist/swc/index.d.ts +17 -0
- package/dist/swc/index.js +126 -0
- package/dist/swc/index.js.map +1 -0
- package/package.json +119 -0
- package/swc/codepress_engine.v0_82_87.wasm +0 -0
- package/swc/codepress_engine.v26.wasm +0 -0
- package/swc/codepress_engine.v42.wasm +0 -0
- package/swc/index.js +14 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
Proprietary License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 Codepress
|
|
4
|
+
|
|
5
|
+
All rights reserved.
|
|
6
|
+
|
|
7
|
+
This software and associated documentation files (the "Software") are the proprietary property of Codepress. Use of the Software is governed by the license agreement that you entered into with Codepress.
|
|
8
|
+
|
|
9
|
+
Unauthorized copying, distribution, modification, public display, public performance, or creation of derivative works of the Software or any part thereof is strictly prohibited. This includes, but is not limited to, integrating or using the Software with third-party services without explicit permission from Codepress.
|
|
10
|
+
|
|
11
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,176 @@
|
|
|
1
|
+
## CodePress Engine
|
|
2
|
+
|
|
3
|
+
TypeScript-powered instrumentation for the CodePress visual editor. The package ships a Babel plugin, SWC transform, development server, and CLI so React or Next.js projects can expose file-level context to the editor.
|
|
4
|
+
|
|
5
|
+
---
|
|
6
|
+
|
|
7
|
+
## Requirements
|
|
8
|
+
|
|
9
|
+
- Node.js **18.17.0 or newer** (Fastify v5 + diagnostics channel support)
|
|
10
|
+
- npm 8+ (or any compatible package manager)
|
|
11
|
+
- Git available on the host machine (repository & branch detection)
|
|
12
|
+
|
|
13
|
+
> Automated tests run under Node 16 and skip Fastify-specific assertions when the runtime lacks the required APIs. For production usage we strongly recommend Node 18+.
|
|
14
|
+
|
|
15
|
+
---
|
|
16
|
+
|
|
17
|
+
## Installation
|
|
18
|
+
|
|
19
|
+
```bash
|
|
20
|
+
npm install --save-dev @codepress/codepress-engine
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
Entry points exposed by the package:
|
|
24
|
+
|
|
25
|
+
| Export | Description |
|
|
26
|
+
| --------------------------------------- | --------------------------------------- |
|
|
27
|
+
| `@codepress/codepress-engine/babel` | Compiled Babel plugin (CommonJS) |
|
|
28
|
+
| `@codepress/codepress-engine/swc` | SWC transform loader & WASM helpers |
|
|
29
|
+
| `@codepress/codepress-engine/server` | Fastify development server factory |
|
|
30
|
+
| `@codepress/codepress-engine/cli` | CLI used by the `codepress` binary |
|
|
31
|
+
| `@codepress/codepress-engine/hash-util` | Browser utilities for decoding metadata |
|
|
32
|
+
|
|
33
|
+
---
|
|
34
|
+
|
|
35
|
+
## Project layout
|
|
36
|
+
|
|
37
|
+
| Path | Details |
|
|
38
|
+
| ----------------- | --------------------------------------------------------------------------- |
|
|
39
|
+
| `src/` | TypeScript sources for the Babel plugin, CLI, dev server, and utils |
|
|
40
|
+
| `dist/` | Compiled JavaScript + declaration files (`npm run build`) |
|
|
41
|
+
| `babel/` | Lightweight proxy that re-exports the compiled Babel plugin |
|
|
42
|
+
| `swc/` | WASM binaries (`wasm-v42`, `wasm-v26`, `wasm-v0_82_87`) and transform entry |
|
|
43
|
+
| `tests/`, `test/` | Jest suites covering Babel, SWC, and server helpers |
|
|
44
|
+
|
|
45
|
+
---
|
|
46
|
+
|
|
47
|
+
## Build & test workflow
|
|
48
|
+
|
|
49
|
+
```bash
|
|
50
|
+
# Install dependencies
|
|
51
|
+
npm install
|
|
52
|
+
|
|
53
|
+
# Compile TypeScript into dist/
|
|
54
|
+
npm run build
|
|
55
|
+
|
|
56
|
+
# Run Jest (ts-jest powered)
|
|
57
|
+
npm test
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
The build step must run before publishing or linking locally because Babel and CLI entry points load from `dist/`. Jest automatically performs type-checking and skips Fastify integration tests when the runtime does not support diagnostics channels.
|
|
61
|
+
|
|
62
|
+
---
|
|
63
|
+
|
|
64
|
+
## CLI & development server
|
|
65
|
+
|
|
66
|
+
```bash
|
|
67
|
+
# Show available commands
|
|
68
|
+
npx codepress help
|
|
69
|
+
|
|
70
|
+
# Launch the Fastify dev server on port 4321
|
|
71
|
+
npx codepress server
|
|
72
|
+
|
|
73
|
+
# Scaffold .env entries and install prettiers required by the dev server
|
|
74
|
+
npx codepress setup
|
|
75
|
+
|
|
76
|
+
# Run your own command with the dev server in the background
|
|
77
|
+
npx codepress npm start
|
|
78
|
+
```
|
|
79
|
+
|
|
80
|
+
Environment variables (loaded from `.env` when present):
|
|
81
|
+
|
|
82
|
+
| Variable | Default | Purpose |
|
|
83
|
+
| ------------------------ | ----------- | -------------------------------------------- |
|
|
84
|
+
| `CODEPRESS_DEV_PORT` | `4321` | Fastify listen port |
|
|
85
|
+
| `CODEPRESS_BACKEND_HOST` | `localhost` | CodePress backend hostname |
|
|
86
|
+
| `CODEPRESS_BACKEND_PORT` | `8007` | Backend REST port |
|
|
87
|
+
| `CODEPRESS_API_TOKEN` | _unset_ | API token used for authenticated proxy calls |
|
|
88
|
+
|
|
89
|
+
The server performs git-aware writes, forwards requests to the CodePress backend, and enriches responses with repository metadata. It never runs in production builds.
|
|
90
|
+
|
|
91
|
+
---
|
|
92
|
+
|
|
93
|
+
## Babel plugin usage
|
|
94
|
+
|
|
95
|
+
```js
|
|
96
|
+
// babel.config.js
|
|
97
|
+
module.exports = {
|
|
98
|
+
plugins: [
|
|
99
|
+
[
|
|
100
|
+
"@codepress/codepress-engine",
|
|
101
|
+
{
|
|
102
|
+
attributeName: "codepress-data-fp",
|
|
103
|
+
repoAttributeName: "codepress-github-repo-name",
|
|
104
|
+
branchAttributeName: "codepress-github-branch",
|
|
105
|
+
},
|
|
106
|
+
],
|
|
107
|
+
],
|
|
108
|
+
};
|
|
109
|
+
```
|
|
110
|
+
|
|
111
|
+
Each JSX element receives a `codepress-data-fp` attribute whose value encodes the relative path and start/end line numbers. Repository and branch metadata are attached to container elements (`html`, `body`, `div`) to help the visual editor route updates.
|
|
112
|
+
|
|
113
|
+
---
|
|
114
|
+
|
|
115
|
+
## SWC transform usage
|
|
116
|
+
|
|
117
|
+
```js
|
|
118
|
+
const {
|
|
119
|
+
transformWithCodePress,
|
|
120
|
+
} = require("@codepress/codepress-engine/swc-plugin");
|
|
121
|
+
|
|
122
|
+
async function transform(source, filePath) {
|
|
123
|
+
const result = await transformWithCodePress(source, filePath, {
|
|
124
|
+
attributeName: "codepress-data-fp",
|
|
125
|
+
repoAttributeName: "codepress-github-repo-name",
|
|
126
|
+
branchAttributeName: "codepress-github-branch",
|
|
127
|
+
});
|
|
128
|
+
|
|
129
|
+
return result.code;
|
|
130
|
+
}
|
|
131
|
+
```
|
|
132
|
+
|
|
133
|
+
`package.json` exports:
|
|
134
|
+
|
|
135
|
+
| Export | Target |
|
|
136
|
+
| --------------------- | -------------------------------------- |
|
|
137
|
+
| `./swc` | `./dist/swc/index.js` |
|
|
138
|
+
| `./swc/wasm` | `./swc/codepress_engine.v42.wasm` |
|
|
139
|
+
| `./swc/wasm-v42` | `./swc/codepress_engine.v42.wasm` |
|
|
140
|
+
| `./swc/wasm-v26` | `./swc/codepress_engine.v26.wasm` |
|
|
141
|
+
| `./swc/wasm-v0_82_87` | `./swc/codepress_engine.v0_82_87.wasm` |
|
|
142
|
+
|
|
143
|
+
The helper automatically selects the correct WASM binary based on detected Next.js / `@swc/core` versions. Override detection with `CODEPRESS_SWC_WASM=<package specifier>` or `CODEPRESS_SWC_ABI_BAND=<v42|v26|v0_82_87>`.
|
|
144
|
+
|
|
145
|
+
---
|
|
146
|
+
|
|
147
|
+
## Feature comparison
|
|
148
|
+
|
|
149
|
+
| Capability | Babel plugin | SWC transform |
|
|
150
|
+
| --------------------- | ------------------------ | ------------------------------- |
|
|
151
|
+
| Git-aware attributes | ✅ | ✅ |
|
|
152
|
+
| Encoded path security | XOR + base64 | XOR + base64 |
|
|
153
|
+
| Line number tracking | ✅ start–end range | ✅ (optional) |
|
|
154
|
+
| Performance | Baseline | **20–70× faster** |
|
|
155
|
+
| Output medium | String literal attribute | `[wasmSpecifier, config]` array |
|
|
156
|
+
|
|
157
|
+
---
|
|
158
|
+
|
|
159
|
+
## Additional references
|
|
160
|
+
|
|
161
|
+
- `INSTALL.md` – linking the package locally & publishing guidance
|
|
162
|
+
- `scripts/build-swc.mjs` – rebuild the WASM binaries (requires Rust toolchain)
|
|
163
|
+
- `tests/` – examples of mocking git, fetch, and file IO when validating the plugin
|
|
164
|
+
|
|
165
|
+
---
|
|
166
|
+
|
|
167
|
+
## Contributing
|
|
168
|
+
|
|
169
|
+
PRs are welcome. Please ensure:
|
|
170
|
+
|
|
171
|
+
1. `npm run build`
|
|
172
|
+
2. `npm test`
|
|
173
|
+
|
|
174
|
+
are both green before submitting. Mention in the PR description if Fastify integration tests were skipped due to running on Node < 18.
|
|
175
|
+
|
|
176
|
+
CodePress Engine is released under the MIT license (see `LICENSE`).
|
package/dist/cli.d.ts
ADDED
package/dist/cli.js
ADDED
|
@@ -0,0 +1,188 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
"use strict";
|
|
3
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
4
|
+
if (k2 === undefined) k2 = k;
|
|
5
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
6
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
7
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
8
|
+
}
|
|
9
|
+
Object.defineProperty(o, k2, desc);
|
|
10
|
+
}) : (function(o, m, k, k2) {
|
|
11
|
+
if (k2 === undefined) k2 = k;
|
|
12
|
+
o[k2] = m[k];
|
|
13
|
+
}));
|
|
14
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
15
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
16
|
+
}) : function(o, v) {
|
|
17
|
+
o["default"] = v;
|
|
18
|
+
});
|
|
19
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
20
|
+
var ownKeys = function(o) {
|
|
21
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
22
|
+
var ar = [];
|
|
23
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
24
|
+
return ar;
|
|
25
|
+
};
|
|
26
|
+
return ownKeys(o);
|
|
27
|
+
};
|
|
28
|
+
return function (mod) {
|
|
29
|
+
if (mod && mod.__esModule) return mod;
|
|
30
|
+
var result = {};
|
|
31
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
32
|
+
__setModuleDefault(result, mod);
|
|
33
|
+
return result;
|
|
34
|
+
};
|
|
35
|
+
})();
|
|
36
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
37
|
+
const child_process_1 = require("child_process");
|
|
38
|
+
const fs = __importStar(require("node:fs"));
|
|
39
|
+
const path = __importStar(require("node:path"));
|
|
40
|
+
const server_1 = require("./server");
|
|
41
|
+
const args = process.argv.slice(2);
|
|
42
|
+
let activeServer = null;
|
|
43
|
+
let signalHandlersRegistered = false;
|
|
44
|
+
let currentChildProcess;
|
|
45
|
+
async function ensureServer() {
|
|
46
|
+
if (activeServer) {
|
|
47
|
+
return activeServer;
|
|
48
|
+
}
|
|
49
|
+
const server = await (0, server_1.startServer)();
|
|
50
|
+
activeServer = server !== null && server !== void 0 ? server : null;
|
|
51
|
+
if (activeServer) {
|
|
52
|
+
console.log("\x1b[36mℹ Codepress server running. Press Ctrl+C to stop.\x1b[0m");
|
|
53
|
+
}
|
|
54
|
+
else {
|
|
55
|
+
console.log("\x1b[33mℹ Server already running\x1b[0m");
|
|
56
|
+
}
|
|
57
|
+
return activeServer;
|
|
58
|
+
}
|
|
59
|
+
async function shutdown(child) {
|
|
60
|
+
console.log("\n\x1b[33mℹ Shutting down Codepress server...\x1b[0m");
|
|
61
|
+
if (child && !child.killed) {
|
|
62
|
+
child.kill("SIGINT");
|
|
63
|
+
}
|
|
64
|
+
if (activeServer) {
|
|
65
|
+
try {
|
|
66
|
+
await activeServer.close();
|
|
67
|
+
console.log("\x1b[32m✓ Codepress server stopped\x1b[0m");
|
|
68
|
+
}
|
|
69
|
+
catch (error) {
|
|
70
|
+
console.error(`\x1b[31m✗ Failed to stop server: ${error.message}\x1b[0m`);
|
|
71
|
+
}
|
|
72
|
+
finally {
|
|
73
|
+
activeServer = null;
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
process.exit(0);
|
|
77
|
+
}
|
|
78
|
+
function registerSignalHandlers(child) {
|
|
79
|
+
currentChildProcess = child;
|
|
80
|
+
if (signalHandlersRegistered) {
|
|
81
|
+
return;
|
|
82
|
+
}
|
|
83
|
+
const handler = () => {
|
|
84
|
+
void shutdown(currentChildProcess);
|
|
85
|
+
};
|
|
86
|
+
process.on("SIGINT", handler);
|
|
87
|
+
process.on("SIGTERM", handler);
|
|
88
|
+
signalHandlersRegistered = true;
|
|
89
|
+
}
|
|
90
|
+
function setupDependencies() {
|
|
91
|
+
console.log("\x1b[36mℹ Setting up dependencies for Codepress visual editor...\x1b[0m");
|
|
92
|
+
try {
|
|
93
|
+
console.log("\x1b[36mℹ Installing dependencies...\x1b[0m");
|
|
94
|
+
(0, child_process_1.execSync)("npm install --save prettier@^3.1.0 node-fetch@^2.6.7", {
|
|
95
|
+
stdio: "inherit",
|
|
96
|
+
});
|
|
97
|
+
console.log("\n\x1b[36mℹ Setting up environment variables...\x1b[0m");
|
|
98
|
+
const envFile = path.join(process.cwd(), ".env");
|
|
99
|
+
let envContent = "";
|
|
100
|
+
if (fs.existsSync(envFile)) {
|
|
101
|
+
envContent = fs.readFileSync(envFile, "utf8");
|
|
102
|
+
}
|
|
103
|
+
let envUpdated = false;
|
|
104
|
+
if (!envContent.includes("CODEPRESS_BACKEND_HOST")) {
|
|
105
|
+
envContent += "\n# Codepress backend settings\n";
|
|
106
|
+
envContent += "CODEPRESS_BACKEND_HOST=localhost\n";
|
|
107
|
+
envContent += "CODEPRESS_BACKEND_PORT=8007\n";
|
|
108
|
+
envUpdated = true;
|
|
109
|
+
}
|
|
110
|
+
if (!envContent.includes("CODEPRESS_API_TOKEN")) {
|
|
111
|
+
envContent += "\n# Codepress authentication\n";
|
|
112
|
+
envContent += "# Get this from your organization settings in Codepress\n";
|
|
113
|
+
envContent += "CODEPRESS_API_TOKEN=\n";
|
|
114
|
+
envUpdated = true;
|
|
115
|
+
}
|
|
116
|
+
if (envUpdated) {
|
|
117
|
+
fs.writeFileSync(envFile, envContent);
|
|
118
|
+
console.log("\x1b[32m✓ Added Codepress settings to .env file\x1b[0m");
|
|
119
|
+
console.log("\x1b[33m⚠ Please set your CODEPRESS_API_TOKEN in the .env file\x1b[0m");
|
|
120
|
+
}
|
|
121
|
+
console.log("\n\x1b[32m✅ Setup completed successfully!\x1b[0m");
|
|
122
|
+
console.log("\x1b[36mℹ You can now start the server with: npx codepress server\x1b[0m");
|
|
123
|
+
}
|
|
124
|
+
catch (error) {
|
|
125
|
+
console.error(`\n\x1b[31m✗ Setup failed: ${error.message}\x1b[0m`);
|
|
126
|
+
process.exit(1);
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
function showHelp() {
|
|
130
|
+
console.log(`
|
|
131
|
+
\x1b[1mCodepress CLI\x1b[0m
|
|
132
|
+
|
|
133
|
+
\x1b[1mUsage:\x1b[0m
|
|
134
|
+
codepress [command] [args...]
|
|
135
|
+
|
|
136
|
+
\x1b[1mCommands:\x1b[0m
|
|
137
|
+
server Start the development server
|
|
138
|
+
setup Setup dependencies for the visual editor
|
|
139
|
+
<command> Run any command with the server running in background
|
|
140
|
+
help Show this help message
|
|
141
|
+
|
|
142
|
+
\x1b[1mExamples:\x1b[0m
|
|
143
|
+
codepress server Start the server only
|
|
144
|
+
codepress setup Install required dependencies
|
|
145
|
+
codepress npm start Run npm start with server in background
|
|
146
|
+
`);
|
|
147
|
+
}
|
|
148
|
+
async function main() {
|
|
149
|
+
if (args.length === 0) {
|
|
150
|
+
showHelp();
|
|
151
|
+
return;
|
|
152
|
+
}
|
|
153
|
+
const [command, ...rest] = args;
|
|
154
|
+
switch (command) {
|
|
155
|
+
case "server": {
|
|
156
|
+
const server = await ensureServer();
|
|
157
|
+
registerSignalHandlers();
|
|
158
|
+
if (!server) {
|
|
159
|
+
console.log("\x1b[33mℹ Server already running in another process\x1b[0m");
|
|
160
|
+
}
|
|
161
|
+
break;
|
|
162
|
+
}
|
|
163
|
+
case "setup":
|
|
164
|
+
setupDependencies();
|
|
165
|
+
break;
|
|
166
|
+
case "help":
|
|
167
|
+
showHelp();
|
|
168
|
+
break;
|
|
169
|
+
default: {
|
|
170
|
+
await ensureServer();
|
|
171
|
+
const childProcess = (0, child_process_1.spawn)(command, rest, {
|
|
172
|
+
stdio: "inherit",
|
|
173
|
+
shell: true,
|
|
174
|
+
});
|
|
175
|
+
childProcess.on("error", (error) => {
|
|
176
|
+
console.error(`\x1b[31m✗ Failed to start process: ${error.message}\x1b[0m`);
|
|
177
|
+
void shutdown(childProcess);
|
|
178
|
+
});
|
|
179
|
+
childProcess.on("close", (code) => {
|
|
180
|
+
console.log(`\x1b[33mℹ Child process exited with code ${code}\x1b[0m`);
|
|
181
|
+
});
|
|
182
|
+
registerSignalHandlers(childProcess);
|
|
183
|
+
break;
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
void main();
|
|
188
|
+
//# sourceMappingURL=cli.js.map
|
package/dist/cli.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cli.js","sourceRoot":"","sources":["../src/cli.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAEA,iDAAmE;AAEnE,4CAA8B;AAC9B,gDAAkC;AAElC,qCAAuC;AAEvC,MAAM,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;AACnC,IAAI,YAAY,GAA2B,IAAI,CAAC;AAChD,IAAI,wBAAwB,GAAG,KAAK,CAAC;AACrC,IAAI,mBAA6C,CAAC;AAElD,KAAK,UAAU,YAAY;IACzB,IAAI,YAAY,EAAE,CAAC;QACjB,OAAO,YAAY,CAAC;IACtB,CAAC;IAED,MAAM,MAAM,GAAG,MAAM,IAAA,oBAAW,GAAE,CAAC;IACnC,YAAY,GAAG,MAAM,aAAN,MAAM,cAAN,MAAM,GAAI,IAAI,CAAC;IAE9B,IAAI,YAAY,EAAE,CAAC;QACjB,OAAO,CAAC,GAAG,CACT,kEAAkE,CACnE,CAAC;IACJ,CAAC;SAAM,CAAC;QACN,OAAO,CAAC,GAAG,CAAC,yCAAyC,CAAC,CAAC;IACzD,CAAC;IAED,OAAO,YAAY,CAAC;AACtB,CAAC;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AC;YAEH,sBAAsB,CAAC,YAAY,CAAC,CAAC;YACrC,MAAM;QACR,CAAC;IACH,CAAC;AACH,CAAC;AAED,KAAK,IAAI,EAAE,CAAC"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Utility functions for handling CodePress hash values
|
|
3
|
+
* To be used by the browser extension for decoding repository and branch info
|
|
4
|
+
*/
|
|
5
|
+
/**
|
|
6
|
+
* Decodes a hashed value created by the plugin
|
|
7
|
+
* @param {string} hashedValue - The hashed value to decode
|
|
8
|
+
* @returns {string|null} The decoded value or null if invalid
|
|
9
|
+
*/
|
|
10
|
+
export declare function decodeHashedValue(hashedValue: string | null): string | null;
|
|
11
|
+
export interface RepositoryInfo {
|
|
12
|
+
repository: string;
|
|
13
|
+
branch: string;
|
|
14
|
+
}
|
|
15
|
+
export declare function extractRepositoryInfo(element: HTMLElement | null): RepositoryInfo | null;
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Utility functions for handling CodePress hash values
|
|
4
|
+
* To be used by the browser extension for decoding repository and branch info
|
|
5
|
+
*/
|
|
6
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
|
+
exports.decodeHashedValue = decodeHashedValue;
|
|
8
|
+
exports.extractRepositoryInfo = extractRepositoryInfo;
|
|
9
|
+
/**
|
|
10
|
+
* Decodes a hashed value created by the plugin
|
|
11
|
+
* @param {string} hashedValue - The hashed value to decode
|
|
12
|
+
* @returns {string|null} The decoded value or null if invalid
|
|
13
|
+
*/
|
|
14
|
+
function decodeHashedValue(hashedValue) {
|
|
15
|
+
if (!hashedValue) {
|
|
16
|
+
return null;
|
|
17
|
+
}
|
|
18
|
+
try {
|
|
19
|
+
const decoded = Buffer.from(hashedValue, "base64").toString();
|
|
20
|
+
const key = "codepress-identifier-key";
|
|
21
|
+
const reversedKey = key.split("").reverse().join("");
|
|
22
|
+
const pattern = new RegExp(`^${key}:(.+):${reversedKey}$`);
|
|
23
|
+
const match = decoded.match(pattern);
|
|
24
|
+
if (match && match[1]) {
|
|
25
|
+
return match[1];
|
|
26
|
+
}
|
|
27
|
+
return null;
|
|
28
|
+
}
|
|
29
|
+
catch (error) {
|
|
30
|
+
console.error("Error decoding hashed value:", error);
|
|
31
|
+
return null;
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
function extractRepositoryInfo(element) {
|
|
35
|
+
if (!element) {
|
|
36
|
+
return null;
|
|
37
|
+
}
|
|
38
|
+
let target = element;
|
|
39
|
+
while (target && !target.hasAttribute("codepress-github-repo-name")) {
|
|
40
|
+
target = target.parentElement;
|
|
41
|
+
if (!target) {
|
|
42
|
+
return null;
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
const repository = target.getAttribute("codepress-github-repo-name");
|
|
46
|
+
const branch = target.getAttribute("codepress-github-branch");
|
|
47
|
+
if (!repository) {
|
|
48
|
+
return null;
|
|
49
|
+
}
|
|
50
|
+
return {
|
|
51
|
+
repository,
|
|
52
|
+
branch: branch || "main",
|
|
53
|
+
};
|
|
54
|
+
}
|
|
55
|
+
//# sourceMappingURL=hash-util.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"hash-util.js","sourceRoot":"","sources":["../src/hash-util.ts"],"names":[],"mappings":";AAAA;;;GAGG;;AAOH,8CAqBC;AAOD,sDA2BC;AA5DD;;;;GAIG;AACH,SAAgB,iBAAiB,CAAC,WAA0B;IAC1D,IAAI,CAAC,WAAW,EAAE,CAAC;QACjB,OAAO,IAAI,CAAC;IACd,CAAC;IAED,IAAI,CAAC;QACH,MAAM,OAAO,GAAG,MAAM,CAAC,IAAI,CAAC,WAAW,EAAE,QAAQ,CAAC,CAAC,QAAQ,EAAE,CAAC;QAC9D,MAAM,GAAG,GAAG,0BAA0B,CAAC;QACvC,MAAM,WAAW,GAAG,GAAG,CAAC,KAAK,CAAC,EAAE,CAAC,CAAC,OAAO,EAAE,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;QACrD,MAAM,OAAO,GAAG,IAAI,MAAM,CAAC,IAAI,GAAG,SAAS,WAAW,GAAG,CAAC,CAAC;QAC3D,MAAM,KAAK,GAAG,OAAO,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC;QAErC,IAAI,KAAK,IAAI,KAAK,CAAC,CAAC,CAAC,EAAE,CAAC;YACtB,OAAO,KAAK,CAAC,CAAC,CAAC,CAAC;QAClB,CAAC;QAED,OAAO,IAAI,CAAC;IACd,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,OAAO,CAAC,KAAK,CAAC,8BAA8B,EAAE,KAAK,CAAC,CAAC;QACrD,OAAO,IAAI,CAAC;IACd,CAAC;AACH,CAAC;AAOD,SAAgB,qBAAqB,CACnC,OAA2B;IAE3B,IAAI,CAAC,OAAO,EAAE,CAAC;QACb,OAAO,IAAI,CAAC;IACd,CAAC;IAED,IAAI,MAAM,GAAuB,OAAO,CAAC;IACzC,OAAO,MAAM,IAAI,CAAC,MAAM,CAAC,YAAY,CAAC,4BAA4B,CAAC,EAAE,CAAC;QACpE,MAAM,GAAG,MAAM,CAAC,aAAa,CAAC;QAE9B,IAAI,CAAC,MAAM,EAAE,CAAC;YACZ,OAAO,IAAI,CAAC;QACd,CAAC;IACH,CAAC;IAED,MAAM,UAAU,GAAG,MAAM,CAAC,YAAY,CAAC,4BAA4B,CAAC,CAAC;IACrE,MAAM,MAAM,GAAG,MAAM,CAAC,YAAY,CAAC,yBAAyB,CAAC,CAAC;IAE9D,IAAI,CAAC,UAAU,EAAE,CAAC;QAChB,OAAO,IAAI,CAAC;IACd,CAAC;IAED,OAAO;QACL,UAAU;QACV,MAAM,EAAE,MAAM,IAAI,MAAM;KACzB,CAAC;AACJ,CAAC"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type * as Babel from "@babel/core";
|
|
2
|
+
export interface CodePressPluginOptions {
|
|
3
|
+
attributeName?: string;
|
|
4
|
+
repoAttributeName?: string;
|
|
5
|
+
branchAttributeName?: string;
|
|
6
|
+
repo_name?: string;
|
|
7
|
+
branch_name?: string;
|
|
8
|
+
}
|
|
9
|
+
interface CodePressPluginState extends Babel.PluginPass {
|
|
10
|
+
file: Babel.BabelFile & {
|
|
11
|
+
encodedPath?: string;
|
|
12
|
+
};
|
|
13
|
+
}
|
|
14
|
+
export declare function decode(attributeValue: string | null | undefined): string;
|
|
15
|
+
export default function codePressPlugin(babel: typeof Babel, options?: CodePressPluginOptions): Babel.PluginObj<CodePressPluginState>;
|
|
16
|
+
export {};
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,175 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.decode = decode;
|
|
7
|
+
exports.default = codePressPlugin;
|
|
8
|
+
const child_process_1 = require("child_process");
|
|
9
|
+
const path_1 = __importDefault(require("path"));
|
|
10
|
+
const SECRET = Buffer.from("codepress-file-obfuscation");
|
|
11
|
+
const BASE64_URL_SAFE_REPLACEMENTS = {
|
|
12
|
+
"+": "-",
|
|
13
|
+
"/": "_",
|
|
14
|
+
"=": "",
|
|
15
|
+
};
|
|
16
|
+
const BASE64_URL_SAFE_RESTORE = {
|
|
17
|
+
"-": "+",
|
|
18
|
+
_: "/",
|
|
19
|
+
};
|
|
20
|
+
function encode(relPath) {
|
|
21
|
+
if (!relPath)
|
|
22
|
+
return "";
|
|
23
|
+
const buffer = Buffer.from(relPath);
|
|
24
|
+
for (let index = 0; index < buffer.length; index += 1) {
|
|
25
|
+
buffer[index] = buffer[index] ^ SECRET[index % SECRET.length];
|
|
26
|
+
}
|
|
27
|
+
return buffer
|
|
28
|
+
.toString("base64")
|
|
29
|
+
.replace(/[+/=]/g, (char) => BASE64_URL_SAFE_REPLACEMENTS[char]);
|
|
30
|
+
}
|
|
31
|
+
function decode(attributeValue) {
|
|
32
|
+
if (!attributeValue)
|
|
33
|
+
return "";
|
|
34
|
+
const base64 = attributeValue.replace(/[-_]/g, (char) => BASE64_URL_SAFE_RESTORE[char]);
|
|
35
|
+
const decoded = Buffer.from(base64, "base64");
|
|
36
|
+
for (let index = 0; index < decoded.length; index += 1) {
|
|
37
|
+
decoded[index] = decoded[index] ^ SECRET[index % SECRET.length];
|
|
38
|
+
}
|
|
39
|
+
return decoded.toString();
|
|
40
|
+
}
|
|
41
|
+
function detectGitBranch() {
|
|
42
|
+
const branchFromEnv = process.env.GIT_BRANCH ||
|
|
43
|
+
process.env.VERCEL_GIT_COMMIT_REF ||
|
|
44
|
+
process.env.GITHUB_HEAD_REF ||
|
|
45
|
+
process.env.GITHUB_REF_NAME ||
|
|
46
|
+
process.env.CI_COMMIT_REF_NAME ||
|
|
47
|
+
process.env.CIRCLE_BRANCH ||
|
|
48
|
+
process.env.BITBUCKET_BRANCH ||
|
|
49
|
+
process.env.BRANCH;
|
|
50
|
+
if (branchFromEnv) {
|
|
51
|
+
return branchFromEnv;
|
|
52
|
+
}
|
|
53
|
+
try {
|
|
54
|
+
const branch = (0, child_process_1.execSync)("git rev-parse --abbrev-ref HEAD", {
|
|
55
|
+
encoding: "utf8",
|
|
56
|
+
}).trim();
|
|
57
|
+
return branch || "main";
|
|
58
|
+
}
|
|
59
|
+
catch (error) {
|
|
60
|
+
console.log("\x1b[33m⚠ Could not detect git branch, using default: main\x1b[0m", error);
|
|
61
|
+
return "main";
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
function detectGitRepoName() {
|
|
65
|
+
try {
|
|
66
|
+
const remoteUrl = (0, child_process_1.execSync)("git config --get remote.origin.url", {
|
|
67
|
+
encoding: "utf8",
|
|
68
|
+
}).trim();
|
|
69
|
+
if (!remoteUrl) {
|
|
70
|
+
return null;
|
|
71
|
+
}
|
|
72
|
+
const httpsMatch = remoteUrl.match(/https:\/\/github\.com\/([^/]+)\/([^/.]+)(?:\.git)?$/);
|
|
73
|
+
if (httpsMatch) {
|
|
74
|
+
const [, owner, repo] = httpsMatch;
|
|
75
|
+
const repoId = `${owner}/${repo}`;
|
|
76
|
+
console.log(`\x1b[32m✓ Detected GitHub repository: ${repoId}\x1b[0m`);
|
|
77
|
+
return repoId;
|
|
78
|
+
}
|
|
79
|
+
const sshMatch = remoteUrl.match(/git@github\.com:([^/]+)\/([^/.]+)(?:\.git)?$/);
|
|
80
|
+
if (sshMatch) {
|
|
81
|
+
const [, owner, repo] = sshMatch;
|
|
82
|
+
const repoId = `${owner}/${repo}`;
|
|
83
|
+
console.log(`\x1b[32m✓ Detected GitHub repository: ${repoId}\x1b[0m`);
|
|
84
|
+
return repoId;
|
|
85
|
+
}
|
|
86
|
+
console.log("\x1b[33m⚠ Could not parse GitHub repository from remote URL\x1b[0m");
|
|
87
|
+
return null;
|
|
88
|
+
}
|
|
89
|
+
catch (error) {
|
|
90
|
+
console.log("\x1b[33m⚠ Could not detect git repository\x1b[0m", error);
|
|
91
|
+
return null;
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
function codePressPlugin(babel, options = {}) {
|
|
95
|
+
var _a, _b;
|
|
96
|
+
const t = babel.types;
|
|
97
|
+
const currentBranch = detectGitBranch();
|
|
98
|
+
const currentRepoName = detectGitRepoName();
|
|
99
|
+
let globalAttributesAdded = false;
|
|
100
|
+
let processedFileCount = 0;
|
|
101
|
+
const { attributeName = "codepress-data-fp", repoAttributeName = "codepress-github-repo-name", branchAttributeName = "codepress-github-branch", } = options;
|
|
102
|
+
const repoName = (_a = options.repo_name) !== null && _a !== void 0 ? _a : currentRepoName;
|
|
103
|
+
const branch = (_b = options.branch_name) !== null && _b !== void 0 ? _b : currentBranch;
|
|
104
|
+
return {
|
|
105
|
+
name: "babel-plugin-codepress-html",
|
|
106
|
+
visitor: {
|
|
107
|
+
Program: {
|
|
108
|
+
enter(nodePath, state) {
|
|
109
|
+
var _a;
|
|
110
|
+
const filename = (_a = state.file.opts.filename) !== null && _a !== void 0 ? _a : "";
|
|
111
|
+
const relativePath = path_1.default.relative(process.cwd(), filename);
|
|
112
|
+
if (relativePath.includes("node_modules") || !relativePath) {
|
|
113
|
+
return;
|
|
114
|
+
}
|
|
115
|
+
state.file.encodedPath = encode(relativePath);
|
|
116
|
+
processedFileCount += 1;
|
|
117
|
+
},
|
|
118
|
+
},
|
|
119
|
+
JSXOpeningElement(nodePath, state) {
|
|
120
|
+
var _a, _b, _c, _d, _e;
|
|
121
|
+
const encodedPath = state.file.encodedPath;
|
|
122
|
+
if (!encodedPath) {
|
|
123
|
+
return;
|
|
124
|
+
}
|
|
125
|
+
const { node } = nodePath;
|
|
126
|
+
const startLine = (_b = (_a = node.loc) === null || _a === void 0 ? void 0 : _a.start.line) !== null && _b !== void 0 ? _b : 0;
|
|
127
|
+
const parentLoc = nodePath.parent.loc;
|
|
128
|
+
const endLine = (_c = parentLoc === null || parentLoc === void 0 ? void 0 : parentLoc.end.line) !== null && _c !== void 0 ? _c : startLine;
|
|
129
|
+
const attributeValue = `${encodedPath}:${startLine}-${endLine}`;
|
|
130
|
+
const existingAttribute = node.attributes.find((attr) => t.isJSXAttribute(attr) &&
|
|
131
|
+
t.isJSXIdentifier(attr.name, { name: attributeName }));
|
|
132
|
+
if (existingAttribute) {
|
|
133
|
+
existingAttribute.value = t.stringLiteral(attributeValue);
|
|
134
|
+
}
|
|
135
|
+
else {
|
|
136
|
+
node.attributes.push(t.jsxAttribute(t.jsxIdentifier(attributeName), t.stringLiteral(attributeValue)));
|
|
137
|
+
}
|
|
138
|
+
if (!repoName || globalAttributesAdded) {
|
|
139
|
+
return;
|
|
140
|
+
}
|
|
141
|
+
if (!t.isJSXIdentifier(node.name)) {
|
|
142
|
+
return;
|
|
143
|
+
}
|
|
144
|
+
const elementName = node.name.name;
|
|
145
|
+
const isRootElement = ["html", "body", "div"].includes(elementName);
|
|
146
|
+
if (!isRootElement) {
|
|
147
|
+
return;
|
|
148
|
+
}
|
|
149
|
+
const hasRepoAttribute = node.attributes.some((attr) => t.isJSXAttribute(attr) &&
|
|
150
|
+
t.isJSXIdentifier(attr.name, { name: repoAttributeName }));
|
|
151
|
+
if (!hasRepoAttribute) {
|
|
152
|
+
console.log(`\x1b[32m✓ Adding repo attribute globally to <${elementName}> in ${path_1.default.basename((_d = state.file.opts.filename) !== null && _d !== void 0 ? _d : "unknown")}\x1b[0m`);
|
|
153
|
+
node.attributes.push(t.jsxAttribute(t.jsxIdentifier(repoAttributeName), t.stringLiteral(repoName)));
|
|
154
|
+
}
|
|
155
|
+
const hasBranchAttribute = node.attributes.some((attr) => t.isJSXAttribute(attr) &&
|
|
156
|
+
t.isJSXIdentifier(attr.name, { name: branchAttributeName }));
|
|
157
|
+
if (!hasBranchAttribute && branch) {
|
|
158
|
+
console.log(`\x1b[32m✓ Adding branch attribute globally to <${elementName}> in ${path_1.default.basename((_e = state.file.opts.filename) !== null && _e !== void 0 ? _e : "unknown")}\x1b[0m`);
|
|
159
|
+
node.attributes.push(t.jsxAttribute(t.jsxIdentifier(branchAttributeName), t.stringLiteral(branch)));
|
|
160
|
+
}
|
|
161
|
+
globalAttributesAdded = true;
|
|
162
|
+
console.log("\x1b[36mℹ Repo/branch attributes added globally. Won't add again.\x1b[0m");
|
|
163
|
+
},
|
|
164
|
+
},
|
|
165
|
+
post() {
|
|
166
|
+
if (processedFileCount > 0) {
|
|
167
|
+
console.log(`\x1b[36mℹ Processed ${processedFileCount} files with CodePress\x1b[0m`);
|
|
168
|
+
}
|
|
169
|
+
else {
|
|
170
|
+
console.log("\x1b[33m⚠ No files were processed by CodePress\x1b[0m");
|
|
171
|
+
}
|
|
172
|
+
},
|
|
173
|
+
};
|
|
174
|
+
}
|
|
175
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;A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