@codepress/codepress-engine 0.4.0-dev.preview-bundle.20251102225420
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 +201 -0
- package/dist/cli.d.ts +2 -0
- package/dist/cli.js +320 -0
- package/dist/cli.js.map +1 -0
- package/dist/index.d.ts +10 -0
- package/dist/index.js +176 -0
- package/dist/index.js.map +1 -0
- package/dist/previewBundle.d.ts +20 -0
- package/dist/previewBundle.js +246 -0
- package/dist/previewBundle.js.map +1 -0
- package/dist/server.d.ts +29 -0
- package/dist/server.js +1140 -0
- package/dist/server.js.map +1 -0
- package/dist/swc/index.d.ts +16 -0
- package/dist/swc/index.js +126 -0
- package/dist/swc/index.js.map +1 -0
- package/dist/types.d.ts +4 -0
- package/dist/types.js +3 -0
- package/dist/types.js.map +1 -0
- package/package.json +114 -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/dist/index.js
ADDED
|
@@ -0,0 +1,176 @@
|
|
|
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
|
+
const t = babel.types;
|
|
96
|
+
const currentBranch = detectGitBranch();
|
|
97
|
+
const currentRepoName = detectGitRepoName();
|
|
98
|
+
let globalAttributesAdded = false;
|
|
99
|
+
let processedFileCount = 0;
|
|
100
|
+
const FILE_PATH_ATTRIBUTE_NAME = "codepress-data-fp";
|
|
101
|
+
const REPO_ATTRIBUTE_NAME = "codepress-github-repo-name";
|
|
102
|
+
const BRANCH_ATTRIBUTE_NAME = "codepress-github-branch";
|
|
103
|
+
const repoName = options.repo_name || currentRepoName;
|
|
104
|
+
const branch = options.branch_name || currentBranch;
|
|
105
|
+
return {
|
|
106
|
+
name: "babel-plugin-codepress-html",
|
|
107
|
+
visitor: {
|
|
108
|
+
Program: {
|
|
109
|
+
enter(nodePath, state) {
|
|
110
|
+
var _a;
|
|
111
|
+
const filename = (_a = state.file.opts.filename) !== null && _a !== void 0 ? _a : "";
|
|
112
|
+
const relativePath = path_1.default.relative(process.cwd(), filename);
|
|
113
|
+
if (relativePath.includes("node_modules") || !relativePath) {
|
|
114
|
+
return;
|
|
115
|
+
}
|
|
116
|
+
state.file.encodedPath = encode(relativePath);
|
|
117
|
+
processedFileCount += 1;
|
|
118
|
+
},
|
|
119
|
+
},
|
|
120
|
+
JSXOpeningElement(nodePath, state) {
|
|
121
|
+
var _a, _b, _c, _d, _e;
|
|
122
|
+
const encodedPath = state.file.encodedPath;
|
|
123
|
+
if (!encodedPath) {
|
|
124
|
+
return;
|
|
125
|
+
}
|
|
126
|
+
const { node } = nodePath;
|
|
127
|
+
const startLine = (_b = (_a = node.loc) === null || _a === void 0 ? void 0 : _a.start.line) !== null && _b !== void 0 ? _b : 0;
|
|
128
|
+
const parentLoc = nodePath.parent.loc;
|
|
129
|
+
const endLine = (_c = parentLoc === null || parentLoc === void 0 ? void 0 : parentLoc.end.line) !== null && _c !== void 0 ? _c : startLine;
|
|
130
|
+
const attributeValue = `${encodedPath}:${startLine}-${endLine}`;
|
|
131
|
+
const existingAttribute = node.attributes.find((attr) => t.isJSXAttribute(attr) &&
|
|
132
|
+
t.isJSXIdentifier(attr.name, { name: FILE_PATH_ATTRIBUTE_NAME }));
|
|
133
|
+
if (existingAttribute) {
|
|
134
|
+
existingAttribute.value = t.stringLiteral(attributeValue);
|
|
135
|
+
}
|
|
136
|
+
else {
|
|
137
|
+
node.attributes.push(t.jsxAttribute(t.jsxIdentifier(FILE_PATH_ATTRIBUTE_NAME), t.stringLiteral(attributeValue)));
|
|
138
|
+
}
|
|
139
|
+
if (!repoName || globalAttributesAdded) {
|
|
140
|
+
return;
|
|
141
|
+
}
|
|
142
|
+
if (!t.isJSXIdentifier(node.name)) {
|
|
143
|
+
return;
|
|
144
|
+
}
|
|
145
|
+
const elementName = node.name.name;
|
|
146
|
+
const isRootElement = ["html", "body", "div"].includes(elementName);
|
|
147
|
+
if (!isRootElement) {
|
|
148
|
+
return;
|
|
149
|
+
}
|
|
150
|
+
const hasRepoAttribute = node.attributes.some((attr) => t.isJSXAttribute(attr) &&
|
|
151
|
+
t.isJSXIdentifier(attr.name, { name: REPO_ATTRIBUTE_NAME }));
|
|
152
|
+
if (!hasRepoAttribute) {
|
|
153
|
+
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`);
|
|
154
|
+
node.attributes.push(t.jsxAttribute(t.jsxIdentifier(REPO_ATTRIBUTE_NAME), t.stringLiteral(repoName)));
|
|
155
|
+
}
|
|
156
|
+
const hasBranchAttribute = node.attributes.some((attr) => t.isJSXAttribute(attr) &&
|
|
157
|
+
t.isJSXIdentifier(attr.name, { name: BRANCH_ATTRIBUTE_NAME }));
|
|
158
|
+
if (!hasBranchAttribute && branch) {
|
|
159
|
+
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`);
|
|
160
|
+
node.attributes.push(t.jsxAttribute(t.jsxIdentifier(BRANCH_ATTRIBUTE_NAME), t.stringLiteral(branch)));
|
|
161
|
+
}
|
|
162
|
+
globalAttributesAdded = true;
|
|
163
|
+
console.log("\x1b[36mℹ Repo/branch attributes added globally. Won't add again.\x1b[0m");
|
|
164
|
+
},
|
|
165
|
+
},
|
|
166
|
+
post() {
|
|
167
|
+
if (processedFileCount > 0) {
|
|
168
|
+
console.log(`\x1b[36mℹ Processed ${processedFileCount} files with CodePress\x1b[0m`);
|
|
169
|
+
}
|
|
170
|
+
else {
|
|
171
|
+
console.log("\x1b[33m⚠ No files were processed by CodePress\x1b[0m");
|
|
172
|
+
}
|
|
173
|
+
},
|
|
174
|
+
};
|
|
175
|
+
}
|
|
176
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;AAmCA,wBAcC;AA0ED,kCAwIC;AAlQD,iDAAyC;AACzC,gDAAwB;AAIxB,MAAM,MAAM,GAAG,MAAM,CAAC,IAAI,CAAC,4BAA4B,CAAC,CAAC;AAEzD,MAAM,4BAA4B,GAA2B;IAC3D,GAAG,EAAE,GAAG;IACR,GAAG,EAAE,GAAG;IACR,GAAG,EAAE,EAAE;CACR,CAAC;AAEF,MAAM,uBAAuB,GAA2B;IACtD,GAAG,EAAE,GAAG;IACR,CAAC,EAAE,GAAG;CACP,CAAC;AAMF,SAAS,MAAM,CAAC,OAAe;IAC7B,IAAI,CAAC,OAAO;QAAE,OAAO,EAAE,CAAC;IACxB,MAAM,MAAM,GAAG,MAAM,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;IACpC,KAAK,IAAI,KAAK,GAAG,CAAC,EAAE,KAAK,GAAG,MAAM,CAAC,MAAM,EAAE,KAAK,IAAI,CAAC,EAAE,CAAC;QACtD,MAAM,CAAC,KAAK,CAAC,GAAG,MAAM,CAAC,KAAK,CAAC,GAAG,MAAM,CAAC,KAAK,GAAG,MAAM,CAAC,MAAM,CAAC,CAAC;IAChE,CAAC;IAED,OAAO,MAAM;SACV,QAAQ,CAAC,QAAQ,CAAC;SAClB,OAAO,CAAC,QAAQ,EAAE,CAAC,IAAI,EAAE,EAAE,CAAC,4BAA4B,CAAC,IAAI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aAAa,CAAC,qBAAqB,CAAC,EACtC,CAAC,CAAC,aAAa,CAAC,MAAM,CAAC,CACxB,CACF,CAAC;gBACJ,CAAC;gBAED,qBAAqB,GAAG,IAAI,CAAC;gBAC7B,OAAO,CAAC,GAAG,CACT,0EAA0E,CAC3E,CAAC;YACJ,CAAC;SACF;QACD,IAAI;YACF,IAAI,kBAAkB,GAAG,CAAC,EAAE,CAAC;gBAC3B,OAAO,CAAC,GAAG,CACT,uBAAuB,kBAAkB,8BAA8B,CACxE,CAAC;YACJ,CAAC;iBAAM,CAAC;gBACN,OAAO,CAAC,GAAG,CAAC,uDAAuD,CAAC,CAAC;YACvE,CAAC;QACH,CAAC;KACF,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
export interface PreviewBundleModule {
|
|
2
|
+
entry: string;
|
|
3
|
+
js: string;
|
|
4
|
+
warnings: string[];
|
|
5
|
+
error?: string;
|
|
6
|
+
buildError?: string;
|
|
7
|
+
usedFallback?: boolean;
|
|
8
|
+
}
|
|
9
|
+
export interface PreviewBundleResult {
|
|
10
|
+
modules: PreviewBundleModule[];
|
|
11
|
+
}
|
|
12
|
+
export interface PreviewBundleOptions {
|
|
13
|
+
entries: string[];
|
|
14
|
+
absWorkingDir: string;
|
|
15
|
+
repoName?: string;
|
|
16
|
+
branchName?: string;
|
|
17
|
+
tsconfigPath?: string;
|
|
18
|
+
quiet?: boolean;
|
|
19
|
+
}
|
|
20
|
+
export declare function previewBundle(options: PreviewBundleOptions): Promise<PreviewBundleResult>;
|
|
@@ -0,0 +1,246 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
35
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
36
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
37
|
+
};
|
|
38
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
|
+
exports.previewBundle = previewBundle;
|
|
40
|
+
const node_fs_1 = require("node:fs");
|
|
41
|
+
const fsSync = __importStar(require("node:fs"));
|
|
42
|
+
const node_path_1 = __importDefault(require("node:path"));
|
|
43
|
+
const node_module_1 = require("node:module");
|
|
44
|
+
const index_1 = __importDefault(require("./index"));
|
|
45
|
+
const SECRET = Buffer.from("codepress-file-obfuscation");
|
|
46
|
+
function xorEncodePath(input) {
|
|
47
|
+
if (!input)
|
|
48
|
+
return "";
|
|
49
|
+
const normalized = input.replace(/\\/g, "/");
|
|
50
|
+
const buffer = Buffer.from(normalized, "utf8");
|
|
51
|
+
const out = Buffer.allocUnsafe(buffer.length);
|
|
52
|
+
for (let i = 0; i < buffer.length; i += 1) {
|
|
53
|
+
out[i] = buffer[i] ^ SECRET[i % SECRET.length];
|
|
54
|
+
}
|
|
55
|
+
return out
|
|
56
|
+
.toString("base64")
|
|
57
|
+
.replace(/\+/g, "-")
|
|
58
|
+
.replace(/\//g, "_")
|
|
59
|
+
.replace(/=+$/g, "");
|
|
60
|
+
}
|
|
61
|
+
function appendRuntimeStamp(js, relPath) {
|
|
62
|
+
try {
|
|
63
|
+
const encoded = xorEncodePath(relPath || "");
|
|
64
|
+
if (!encoded)
|
|
65
|
+
return js;
|
|
66
|
+
const snippet = `\n;(function(exports){\n try {\n if (!exports) return;\n var globalObj = typeof globalThis !== 'undefined' ? globalThis : (typeof window !== 'undefined' ? window : (typeof global !== 'undefined' ? global : {}));\n var stampFn = globalObj && globalObj.__CP_stamp;\n var registerFn = globalObj && globalObj.__CP_REGISTER__;\n var encoded = ${JSON.stringify(encoded)};\n var seen = Object.create(null);\n function shouldStampName(name){\n if (!name) return false;\n var first = String(name).charAt(0);\n return first && first === first.toUpperCase();\n }\n function applyStamp(value, exportName){\n if (!value) return;\n try { if (value.__cp_id) { if (typeof registerFn === 'function') { registerFn(value.__cp_id, value); } return; } } catch (_) {}\n var id = encoded + '#' + exportName;\n if (typeof stampFn === 'function') {\n try { stampFn(value, id, encoded); } catch (_) {}\n } else {\n try { value.__cp_id = id; } catch (_) {}\n try { value.__cp_fp = encoded; } catch (_) {}\n }\n if (typeof registerFn === 'function') {\n try { registerFn(id, value); } catch (_) {}\n }\n }\n if (Object.prototype.hasOwnProperty.call(exports, 'default')) {\n applyStamp(exports.default, 'default');\n }\n for (var key in exports) {\n if (!Object.prototype.hasOwnProperty.call(exports, key)) continue;\n if (key === 'default') continue;\n if (shouldStampName(key)) {\n applyStamp(exports[key], key);\n }\n }\n } catch (_) {}\n})(typeof module !== 'undefined' ? module.exports : undefined);\n`;
|
|
67
|
+
return js + snippet;
|
|
68
|
+
}
|
|
69
|
+
catch {
|
|
70
|
+
return js;
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
function posixRelative(root, target) {
|
|
74
|
+
const rel = node_path_1.default.relative(root, target);
|
|
75
|
+
return rel.replace(/\\/g, "/");
|
|
76
|
+
}
|
|
77
|
+
function determineLoader(filePath) {
|
|
78
|
+
const ext = node_path_1.default.extname(filePath).toLowerCase();
|
|
79
|
+
if (ext === ".tsx" || ext === ".ts")
|
|
80
|
+
return "tsx";
|
|
81
|
+
return "jsx";
|
|
82
|
+
}
|
|
83
|
+
function loadFrom(specifier, primary, fallback) {
|
|
84
|
+
try {
|
|
85
|
+
return primary(specifier);
|
|
86
|
+
}
|
|
87
|
+
catch {
|
|
88
|
+
try {
|
|
89
|
+
return fallback(specifier);
|
|
90
|
+
}
|
|
91
|
+
catch {
|
|
92
|
+
return null;
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
async function previewBundle(options) {
|
|
97
|
+
var _a;
|
|
98
|
+
const absWorkingDir = node_path_1.default.resolve(options.absWorkingDir || process.cwd());
|
|
99
|
+
const createReqPath = node_path_1.default.join(absWorkingDir, "package.json");
|
|
100
|
+
let primaryRequire;
|
|
101
|
+
try {
|
|
102
|
+
primaryRequire = (0, node_module_1.createRequire)(createReqPath);
|
|
103
|
+
}
|
|
104
|
+
catch {
|
|
105
|
+
primaryRequire = (0, node_module_1.createRequire)(node_path_1.default.join(absWorkingDir, "index.js"));
|
|
106
|
+
}
|
|
107
|
+
const fallbackRequire = (0, node_module_1.createRequire)(__filename);
|
|
108
|
+
const esbuild = loadFrom("esbuild", primaryRequire, fallbackRequire);
|
|
109
|
+
if (!esbuild) {
|
|
110
|
+
throw new Error("esbuild is not available. Install it in the current repository.");
|
|
111
|
+
}
|
|
112
|
+
const babel = loadFrom("@babel/core", primaryRequire, fallbackRequire);
|
|
113
|
+
if (!babel) {
|
|
114
|
+
throw new Error("@babel/core is required for preview bundling. Install it in the current repository.");
|
|
115
|
+
}
|
|
116
|
+
const repoName = options.repoName;
|
|
117
|
+
const branchName = options.branchName;
|
|
118
|
+
const tsconfigPath = options.tsconfigPath
|
|
119
|
+
? node_path_1.default.resolve(absWorkingDir, options.tsconfigPath)
|
|
120
|
+
: (() => {
|
|
121
|
+
const candidate = node_path_1.default.join(absWorkingDir, "tsconfig.json");
|
|
122
|
+
return fsSync.existsSync(candidate) ? candidate : undefined;
|
|
123
|
+
})();
|
|
124
|
+
const instrumentationPlugin = {
|
|
125
|
+
name: "codepress-babel-instrumentation",
|
|
126
|
+
setup(build) {
|
|
127
|
+
build.onLoad({ filter: /\.[tj]sx$/ }, async (args) => {
|
|
128
|
+
const source = await node_fs_1.promises.readFile(args.path, "utf8");
|
|
129
|
+
const loader = determineLoader(args.path);
|
|
130
|
+
try {
|
|
131
|
+
const transformed = await babel.transformAsync(source, {
|
|
132
|
+
filename: args.path,
|
|
133
|
+
babelrc: false,
|
|
134
|
+
configFile: false,
|
|
135
|
+
parserOpts: {
|
|
136
|
+
sourceType: "module",
|
|
137
|
+
plugins: [
|
|
138
|
+
"jsx",
|
|
139
|
+
"typescript",
|
|
140
|
+
"classProperties",
|
|
141
|
+
"classPrivateProperties",
|
|
142
|
+
"classPrivateMethods",
|
|
143
|
+
["decorators", { decoratorsBeforeExport: true }],
|
|
144
|
+
"dynamicImport",
|
|
145
|
+
"optionalChaining",
|
|
146
|
+
"nullishCoalescingOperator",
|
|
147
|
+
],
|
|
148
|
+
},
|
|
149
|
+
assumptions: {
|
|
150
|
+
constantReexports: true,
|
|
151
|
+
},
|
|
152
|
+
generatorOpts: {
|
|
153
|
+
decoratorsBeforeExport: true,
|
|
154
|
+
},
|
|
155
|
+
plugins: [
|
|
156
|
+
[
|
|
157
|
+
index_1.default,
|
|
158
|
+
{
|
|
159
|
+
repo_name: repoName,
|
|
160
|
+
branch_name: branchName,
|
|
161
|
+
},
|
|
162
|
+
],
|
|
163
|
+
],
|
|
164
|
+
});
|
|
165
|
+
if (transformed === null || transformed === void 0 ? void 0 : transformed.code) {
|
|
166
|
+
return { contents: transformed.code, loader };
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
catch (err) {
|
|
170
|
+
if (!options.quiet) {
|
|
171
|
+
console.warn("[codepress-preview] Babel transform failed", err instanceof Error ? err.message : err);
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
return { contents: source, loader };
|
|
175
|
+
});
|
|
176
|
+
},
|
|
177
|
+
};
|
|
178
|
+
const modules = [];
|
|
179
|
+
for (const entry of options.entries) {
|
|
180
|
+
const absEntry = node_path_1.default.resolve(absWorkingDir, entry);
|
|
181
|
+
const relEntry = posixRelative(absWorkingDir, absEntry);
|
|
182
|
+
let js = "";
|
|
183
|
+
let warnings = [];
|
|
184
|
+
let error;
|
|
185
|
+
let buildError;
|
|
186
|
+
let usedFallback = false;
|
|
187
|
+
try {
|
|
188
|
+
const buildResult = await esbuild.build({
|
|
189
|
+
absWorkingDir,
|
|
190
|
+
entryPoints: [absEntry],
|
|
191
|
+
outfile: "codepress-preview.js",
|
|
192
|
+
bundle: true,
|
|
193
|
+
format: "cjs",
|
|
194
|
+
platform: "browser",
|
|
195
|
+
target: "es2019",
|
|
196
|
+
sourcemap: "inline",
|
|
197
|
+
minify: false,
|
|
198
|
+
write: false,
|
|
199
|
+
logLevel: "silent",
|
|
200
|
+
jsx: "automatic",
|
|
201
|
+
tsconfig: tsconfigPath,
|
|
202
|
+
plugins: [instrumentationPlugin],
|
|
203
|
+
});
|
|
204
|
+
const output = (_a = buildResult.outputFiles) === null || _a === void 0 ? void 0 : _a[0];
|
|
205
|
+
warnings = (buildResult.warnings || []).map((warning) => (warning === null || warning === void 0 ? void 0 : warning.text) ? String(warning.text) : JSON.stringify(warning));
|
|
206
|
+
js = appendRuntimeStamp(output ? output.text : "", relEntry);
|
|
207
|
+
}
|
|
208
|
+
catch (err) {
|
|
209
|
+
error = "build_failed";
|
|
210
|
+
buildError =
|
|
211
|
+
err instanceof Error && err.message ? err.message : String(err);
|
|
212
|
+
try {
|
|
213
|
+
const source = await node_fs_1.promises.readFile(absEntry, "utf8");
|
|
214
|
+
const loader = determineLoader(absEntry);
|
|
215
|
+
const transform = await esbuild.transform(source, {
|
|
216
|
+
loader,
|
|
217
|
+
format: "cjs",
|
|
218
|
+
jsx: "automatic",
|
|
219
|
+
target: "es2019",
|
|
220
|
+
sourcemap: "inline",
|
|
221
|
+
});
|
|
222
|
+
warnings = (transform.warnings || []).map((warning) => (warning === null || warning === void 0 ? void 0 : warning.text) ? String(warning.text) : JSON.stringify(warning));
|
|
223
|
+
js = appendRuntimeStamp(transform.code, relEntry);
|
|
224
|
+
usedFallback = true;
|
|
225
|
+
}
|
|
226
|
+
catch (fallbackErr) {
|
|
227
|
+
if (!buildError) {
|
|
228
|
+
buildError =
|
|
229
|
+
fallbackErr instanceof Error && fallbackErr.message
|
|
230
|
+
? fallbackErr.message
|
|
231
|
+
: String(fallbackErr);
|
|
232
|
+
}
|
|
233
|
+
}
|
|
234
|
+
}
|
|
235
|
+
modules.push({
|
|
236
|
+
entry: relEntry,
|
|
237
|
+
js,
|
|
238
|
+
warnings,
|
|
239
|
+
error,
|
|
240
|
+
buildError,
|
|
241
|
+
usedFallback: usedFallback || undefined,
|
|
242
|
+
});
|
|
243
|
+
}
|
|
244
|
+
return { modules };
|
|
245
|
+
}
|
|
246
|
+
//# sourceMappingURL=previewBundle.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"previewBundle.js","sourceRoot":"","sources":["../src/previewBundle.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAsFA,sCAyKC;AA/PD,qCAAyC;AACzC,gDAAkC;AAClC,0DA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,CAAC;QACH,CAAC;QAED,OAAO,CAAC,IAAI,CAAC;YACX,KAAK,EAAE,QAAQ;YACf,EAAE;YACF,QAAQ;YACR,KAAK;YACL,UAAU;YACV,YAAY,EAAE,YAAY,IAAI,SAAS;SACxC,CAAC,CAAC;IACL,CAAC;IAED,OAAO,EAAE,OAAO,EAAE,CAAC;AACrB,CAAC"}
|
package/dist/server.d.ts
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { type FastifyInstance } from "fastify";
|
|
2
|
+
interface StartServerOptions {
|
|
3
|
+
port?: number;
|
|
4
|
+
}
|
|
5
|
+
/**
|
|
6
|
+
* Create and configure the Fastify app
|
|
7
|
+
* @returns {Object} The configured Fastify instance
|
|
8
|
+
*/
|
|
9
|
+
declare function createApp(): FastifyInstance;
|
|
10
|
+
/**
|
|
11
|
+
* Starts the Codepress development server if not already running
|
|
12
|
+
* @param {Object} options Server configuration options
|
|
13
|
+
* @param {number} [options.port=4321] Port to run the server on
|
|
14
|
+
* @returns {Object|null} The Fastify instance or null if already running
|
|
15
|
+
*/
|
|
16
|
+
declare function startServer(options?: StartServerOptions): Promise<FastifyInstance | null>;
|
|
17
|
+
/**
|
|
18
|
+
* Get a list of files in the current project, respecting gitignore patterns
|
|
19
|
+
* @returns {string} List of file paths, one per line
|
|
20
|
+
*/
|
|
21
|
+
declare function getProjectStructure(): string;
|
|
22
|
+
interface ServerModule {
|
|
23
|
+
startServer: typeof startServer;
|
|
24
|
+
createApp: typeof createApp;
|
|
25
|
+
getProjectStructure: typeof getProjectStructure;
|
|
26
|
+
server?: FastifyInstance | null;
|
|
27
|
+
}
|
|
28
|
+
export { createApp, getProjectStructure, startServer };
|
|
29
|
+
export type { ServerModule };
|