azot 5.0.0-alpha.11 → 5.0.0-alpha.13

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/dist/azt.cjs CHANGED
@@ -1,2 +1,196 @@
1
1
  #!/usr/bin/env node
2
- const e=require(`./chunk-350yNsax.cjs`);let t=require(`node:util`),n=require(`node:fs`),r=require(`node:path`);r=e.n(r);let i=require(`tsdown`),a=require(`node:crypto`),o=require(`javascript-obfuscator`);o=e.n(o);const s=Buffer.from(`STX`,`utf8`),c=(e,t,r)=>{let i=(0,a.randomBytes)(32),o=(0,a.randomBytes)(16),c=(0,n.readFileSync)(t),l=(0,a.createCipheriv)(`aes-256-cbc`,i,o),u=Buffer.concat([l.update(c),l.final()]),d=(0,a.publicEncrypt)(e,i),f=Buffer.concat([s,o,d,u]);return r&&(0,n.writeFileSync)(r,f),{aesIv:o,encryptedAesKey:d,encryptedCode:u}},l=(e,t,r)=>{let i=(0,n.readFileSync)(t),o=s.byteLength;if(!i.subarray(0,o).equals(s))throw Error(`Incorrect file format`);let c=o,l=c+16,u=l+512,d=i.subarray(c,l),f=i.subarray(l,u),p=i.subarray(u),m=(0,a.createDecipheriv)(`aes-256-cbc`,(0,a.privateDecrypt)(e,f),d),h=Buffer.concat([m.update(p),m.final()]).toString(`utf8`);return r&&(0,n.writeFileSync)(r,h),h},u=(e,t)=>{let r=(0,n.readFileSync)(e,`utf8`);console.log(`Obfuscating...`),console.time(`Obfuscation complete in`);let i=o.default.obfuscate(r,{target:`node`,compact:!0,controlFlowFlattening:!0,controlFlowFlatteningThreshold:1,deadCodeInjection:!0,debugProtection:!0,identifierNamesGenerator:`hexadecimal`,numbersToExpressions:!0,selfDefending:!0,simplify:!0,splitStrings:!0,splitStringsChunkLength:5,stringArray:!0,stringArrayCallsTransform:!0,stringArrayCallsTransformThreshold:1,stringArrayEncoding:[`base64`],stringArrayIndexShift:!0,stringArrayRotate:!0,stringArrayShuffle:!0,stringArrayWrappersCount:2,stringArrayWrappersChainedCalls:!0,stringArrayWrappersType:`function`,stringArrayThreshold:1,transformObjectKeys:!0,unicodeEscapeSequence:!1});console.timeEnd(`Obfuscation complete in`);let a=i.getObfuscatedCode();return(0,n.writeFileSync)(t||e,a),a},d=(0,t.parseArgs)({allowPositionals:!0,allowNegative:!0,options:{input:{type:`string`,short:`i`,description:`Path to the input file`},key:{type:`string`,short:`k`,description:`Path to the key file (public for encrypt, private for decrypt)`},output:{type:`string`,short:`o`,description:`Path to the output file`},format:{type:`string`,short:`f`,description:`Output format`},watch:{type:`boolean`,description:`Watch file changes`},minify:{type:`boolean`,description:`Minify output`},obfuscate:{type:`boolean`,description:`Obfuscate output`},encrypt:{type:`boolean`,description:`Encrypt extension source code (.js will be packed inside .stx)`},decrypt:{type:`boolean`,description:`Decrypt encrypted extension`}}}),f=()=>{let e=[process.cwd(),r.default.join(process.cwd(),`src`),r.default.join(process.cwd(),`lib`)];for(let t of e){let e=(0,n.readdirSync)(t).filter(e=>!e.endsWith(`.d.ts`)).filter(e=>new Set([`.ts`,`.js`,`.cjs`,`.mjs`]).has(r.default.extname(e))),i=e=>r.default.basename(e,r.default.extname(e)),a=e.find(e=>i(e)===`index`)||e.find(e=>i(e)===`main`)||e[0];if(a)return r.default.join(t,a)}};(async()=>{let[e,...t]=d.positionals,a=d.values.input||t[0]||f();if(!a)throw Error(`No entry file found`);if(e===`build`||e===`pack`){let t=typeof d.values.minify==`boolean`?d.values.minify:!0;await(0,i.build)({entry:a.replace(process.cwd(),`.`).replace(r.default.sep,`/`),format:d.values.format??`cjs`,platform:`node`,target:`node22`,watch:d.values.watch,minify:t});let o=d.values.format??`cjs`;d.values.input=r.default.join(process.cwd(),`dist`,r.default.basename(a).replace(/\.ts$/,`.${o}`));let s=require(r.default.join(process.cwd(),`package.json`));if((typeof d.values.obfuscate==`boolean`?d.values.obfuscate:s.private)&&u(d.values.input,d.values.input),d.values.encrypt||e===`pack`){let e=(0,n.readFileSync)(d.values.key||r.default.join(__dirname,`../public.pem`),`utf8`),t=d.values.output||d.values.input.replace(/\.js$/,`-${s.version}.stx`);c(e,d.values.input,t),(0,n.rmSync)(d.values.input)}}else if(e===`decrypt`)l((0,n.readFileSync)(d.values.key||r.default.join(__dirname,`../private.pem`),`utf8`),a,d.values.output||a.replace(/\.stx$/,`.js`)),d.values.input&&(0,n.rmSync)(d.values.input);else if(e===`dev`||e===`develop`||!e){let e=typeof d.values.minify==`boolean`?d.values.minify:!1;await(0,i.build)({entry:a,format:d.values.format??`cjs`,platform:`node`,target:`node22`,watch:!0,minify:e})}})();
2
+ const require_chunk = require('./chunk-BmvPcxpV.cjs');
3
+ let node_util = require("node:util");
4
+ let node_fs = require("node:fs");
5
+ let node_path = require("node:path");
6
+ node_path = require_chunk.__toESM(node_path);
7
+ let tsdown = require("tsdown");
8
+ let node_crypto = require("node:crypto");
9
+ let javascript_obfuscator = require("javascript-obfuscator");
10
+ javascript_obfuscator = require_chunk.__toESM(javascript_obfuscator);
11
+
12
+ //#region src/crypto.ts
13
+ const MAGIC_BYTES = Buffer.from("STX", "utf8");
14
+ const encrypt = (publicKey, inputPath, outputPath) => {
15
+ const aesKey = (0, node_crypto.randomBytes)(32);
16
+ const aesIv = (0, node_crypto.randomBytes)(16);
17
+ const code = (0, node_fs.readFileSync)(inputPath);
18
+ const cipher = (0, node_crypto.createCipheriv)("aes-256-cbc", aesKey, aesIv);
19
+ const encryptedCode = Buffer.concat([cipher.update(code), cipher.final()]);
20
+ const encryptedAesKey = (0, node_crypto.publicEncrypt)(publicKey, aesKey);
21
+ const output = Buffer.concat([
22
+ MAGIC_BYTES,
23
+ aesIv,
24
+ encryptedAesKey,
25
+ encryptedCode
26
+ ]);
27
+ if (outputPath) (0, node_fs.writeFileSync)(outputPath, output);
28
+ return {
29
+ aesIv,
30
+ encryptedAesKey,
31
+ encryptedCode
32
+ };
33
+ };
34
+ const decrypt = (privateKey, inputPath, outputPath) => {
35
+ const data = (0, node_fs.readFileSync)(inputPath);
36
+ const magicSize = MAGIC_BYTES.byteLength;
37
+ if (!data.subarray(0, magicSize).equals(MAGIC_BYTES)) throw new Error("Incorrect file format");
38
+ const aesIvStart = magicSize;
39
+ const encryptedAesKeyStart = aesIvStart + 16;
40
+ const encryptedCodeStart = encryptedAesKeyStart + 512;
41
+ const aesIv = data.subarray(aesIvStart, encryptedAesKeyStart);
42
+ const encryptedAesKey = data.subarray(encryptedAesKeyStart, encryptedCodeStart);
43
+ const encryptedCode = data.subarray(encryptedCodeStart);
44
+ const decipher = (0, node_crypto.createDecipheriv)("aes-256-cbc", (0, node_crypto.privateDecrypt)(privateKey, encryptedAesKey), aesIv);
45
+ const result = Buffer.concat([decipher.update(encryptedCode), decipher.final()]).toString("utf8");
46
+ if (outputPath) (0, node_fs.writeFileSync)(outputPath, result);
47
+ return result;
48
+ };
49
+
50
+ //#endregion
51
+ //#region src/obfuscation.ts
52
+ const obfuscate = (inputPath, outputPath) => {
53
+ const code = (0, node_fs.readFileSync)(inputPath, "utf8");
54
+ console.log("Obfuscating...");
55
+ console.time("Obfuscation complete in");
56
+ const result = javascript_obfuscator.default.obfuscate(code, {
57
+ target: "node",
58
+ compact: true,
59
+ controlFlowFlattening: true,
60
+ controlFlowFlatteningThreshold: 1,
61
+ deadCodeInjection: true,
62
+ debugProtection: true,
63
+ identifierNamesGenerator: "hexadecimal",
64
+ numbersToExpressions: true,
65
+ selfDefending: true,
66
+ simplify: true,
67
+ splitStrings: true,
68
+ splitStringsChunkLength: 5,
69
+ stringArray: true,
70
+ stringArrayCallsTransform: true,
71
+ stringArrayCallsTransformThreshold: 1,
72
+ stringArrayEncoding: ["base64"],
73
+ stringArrayIndexShift: true,
74
+ stringArrayRotate: true,
75
+ stringArrayShuffle: true,
76
+ stringArrayWrappersCount: 2,
77
+ stringArrayWrappersChainedCalls: true,
78
+ stringArrayWrappersType: "function",
79
+ stringArrayThreshold: 1,
80
+ transformObjectKeys: true,
81
+ unicodeEscapeSequence: false
82
+ });
83
+ console.timeEnd("Obfuscation complete in");
84
+ const obfuscatedCode = result.getObfuscatedCode();
85
+ (0, node_fs.writeFileSync)(outputPath || inputPath, obfuscatedCode);
86
+ return obfuscatedCode;
87
+ };
88
+
89
+ //#endregion
90
+ //#region src/cli.ts
91
+ const args = (0, node_util.parseArgs)({
92
+ allowPositionals: true,
93
+ allowNegative: true,
94
+ options: {
95
+ input: {
96
+ type: "string",
97
+ short: "i",
98
+ description: "Path to the input file"
99
+ },
100
+ key: {
101
+ type: "string",
102
+ short: "k",
103
+ description: "Path to the key file (public for encrypt, private for decrypt)"
104
+ },
105
+ output: {
106
+ type: "string",
107
+ short: "o",
108
+ description: "Path to the output file"
109
+ },
110
+ format: {
111
+ type: "string",
112
+ short: "f",
113
+ description: "Output format"
114
+ },
115
+ watch: {
116
+ type: "boolean",
117
+ description: "Watch file changes"
118
+ },
119
+ minify: {
120
+ type: "boolean",
121
+ description: "Minify output"
122
+ },
123
+ obfuscate: {
124
+ type: "boolean",
125
+ description: "Obfuscate output"
126
+ },
127
+ encrypt: {
128
+ type: "boolean",
129
+ description: "Encrypt extension source code (.js will be packed inside .stx)"
130
+ },
131
+ decrypt: {
132
+ type: "boolean",
133
+ description: "Decrypt encrypted extension"
134
+ }
135
+ }
136
+ });
137
+ const getDefaultEntryFile = () => {
138
+ const searchDirs = [
139
+ process.cwd(),
140
+ node_path.default.join(process.cwd(), "src"),
141
+ node_path.default.join(process.cwd(), "lib")
142
+ ];
143
+ for (const searchDir of searchDirs) {
144
+ const scripts = (0, node_fs.readdirSync)(searchDir).filter((file) => !file.endsWith(".d.ts")).filter((file) => new Set([
145
+ ".ts",
146
+ ".js",
147
+ ".cjs",
148
+ ".mjs"
149
+ ]).has(node_path.default.extname(file)));
150
+ const getFilename = (file) => node_path.default.basename(file, node_path.default.extname(file));
151
+ const entry = scripts.find((file) => getFilename(file) === "index") || scripts.find((file) => getFilename(file) === "main") || scripts[0];
152
+ if (entry) return node_path.default.join(searchDir, entry);
153
+ }
154
+ };
155
+ (async () => {
156
+ const [command, ...commands] = args.positionals;
157
+ const entry = args.values.input || commands[0] || getDefaultEntryFile();
158
+ if (!entry) throw new Error("No entry file found");
159
+ if (command === "build" || command === "pack") {
160
+ const shouldMinify = typeof args.values.minify === "boolean" ? args.values.minify : true;
161
+ await (0, tsdown.build)({
162
+ entry: entry.replace(process.cwd(), ".").replace(node_path.default.sep, "/"),
163
+ format: args.values.format ?? "cjs",
164
+ platform: "node",
165
+ target: "node22",
166
+ watch: args.values.watch,
167
+ minify: shouldMinify,
168
+ inlineOnly: false
169
+ });
170
+ const ext = args.values.format ?? "cjs";
171
+ args.values.input = node_path.default.join(process.cwd(), "dist", node_path.default.basename(entry).replace(/\.ts$/, `.${ext}`));
172
+ const packageJson = require(node_path.default.join(process.cwd(), "package.json"));
173
+ if (typeof args.values.obfuscate === "boolean" ? args.values.obfuscate : packageJson.private) obfuscate(args.values.input, args.values.input);
174
+ if (args.values.encrypt || command === "pack") {
175
+ const key = (0, node_fs.readFileSync)(args.values.key || node_path.default.join(__dirname, "../public.pem"), "utf8");
176
+ const output = args.values.output || args.values.input.replace(/\.js$/, `-${packageJson.version}.stx`);
177
+ encrypt(key, args.values.input, output);
178
+ (0, node_fs.rmSync)(args.values.input);
179
+ }
180
+ } else if (command === "decrypt") {
181
+ decrypt((0, node_fs.readFileSync)(args.values.key || node_path.default.join(__dirname, "../private.pem"), "utf8"), entry, args.values.output || entry.replace(/\.stx$/, ".js"));
182
+ if (args.values.input) (0, node_fs.rmSync)(args.values.input);
183
+ } else if (command === "dev" || command === "develop" || !command) {
184
+ const shouldMinify = typeof args.values.minify === "boolean" ? args.values.minify : false;
185
+ await (0, tsdown.build)({
186
+ entry,
187
+ format: args.values.format ?? "cjs",
188
+ platform: "node",
189
+ target: "node22",
190
+ watch: true,
191
+ minify: shouldMinify
192
+ });
193
+ }
194
+ })();
195
+
196
+ //#endregion
package/dist/azt.mjs CHANGED
@@ -1,2 +1,195 @@
1
1
  #!/usr/bin/env node
2
- import{n as e}from"./chunk-DtROqxiw.mjs";import{parseArgs as t}from"node:util";import{readFileSync as n,readdirSync as r,rmSync as i,writeFileSync as a}from"node:fs";import o from"node:path";import{build as s}from"tsdown";import{createCipheriv as c,createDecipheriv as l,privateDecrypt as u,publicEncrypt as d,randomBytes as f}from"node:crypto";import p from"javascript-obfuscator";const m=Buffer.from(`STX`,`utf8`),h=(e,t,r)=>{let i=f(32),o=f(16),s=n(t),l=c(`aes-256-cbc`,i,o),u=Buffer.concat([l.update(s),l.final()]),p=d(e,i),h=Buffer.concat([m,o,p,u]);return r&&a(r,h),{aesIv:o,encryptedAesKey:p,encryptedCode:u}},g=(e,t,r)=>{let i=n(t),o=m.byteLength;if(!i.subarray(0,o).equals(m))throw Error(`Incorrect file format`);let s=o,c=s+16,d=c+512,f=i.subarray(s,c),p=i.subarray(c,d),h=i.subarray(d),g=l(`aes-256-cbc`,u(e,p),f),_=Buffer.concat([g.update(h),g.final()]).toString(`utf8`);return r&&a(r,_),_},_=(e,t)=>{let r=n(e,`utf8`);console.log(`Obfuscating...`),console.time(`Obfuscation complete in`);let i=p.obfuscate(r,{target:`node`,compact:!0,controlFlowFlattening:!0,controlFlowFlatteningThreshold:1,deadCodeInjection:!0,debugProtection:!0,identifierNamesGenerator:`hexadecimal`,numbersToExpressions:!0,selfDefending:!0,simplify:!0,splitStrings:!0,splitStringsChunkLength:5,stringArray:!0,stringArrayCallsTransform:!0,stringArrayCallsTransformThreshold:1,stringArrayEncoding:[`base64`],stringArrayIndexShift:!0,stringArrayRotate:!0,stringArrayShuffle:!0,stringArrayWrappersCount:2,stringArrayWrappersChainedCalls:!0,stringArrayWrappersType:`function`,stringArrayThreshold:1,transformObjectKeys:!0,unicodeEscapeSequence:!1});console.timeEnd(`Obfuscation complete in`);let o=i.getObfuscatedCode();return a(t||e,o),o},v=t({allowPositionals:!0,allowNegative:!0,options:{input:{type:`string`,short:`i`,description:`Path to the input file`},key:{type:`string`,short:`k`,description:`Path to the key file (public for encrypt, private for decrypt)`},output:{type:`string`,short:`o`,description:`Path to the output file`},format:{type:`string`,short:`f`,description:`Output format`},watch:{type:`boolean`,description:`Watch file changes`},minify:{type:`boolean`,description:`Minify output`},obfuscate:{type:`boolean`,description:`Obfuscate output`},encrypt:{type:`boolean`,description:`Encrypt extension source code (.js will be packed inside .stx)`},decrypt:{type:`boolean`,description:`Decrypt encrypted extension`}}}),y=()=>{let e=[process.cwd(),o.join(process.cwd(),`src`),o.join(process.cwd(),`lib`)];for(let t of e){let e=r(t).filter(e=>!e.endsWith(`.d.ts`)).filter(e=>new Set([`.ts`,`.js`,`.cjs`,`.mjs`]).has(o.extname(e))),n=e=>o.basename(e,o.extname(e)),i=e.find(e=>n(e)===`index`)||e.find(e=>n(e)===`main`)||e[0];if(i)return o.join(t,i)}};(async()=>{let[t,...r]=v.positionals,a=v.values.input||r[0]||y();if(!a)throw Error(`No entry file found`);if(t===`build`||t===`pack`){let r=typeof v.values.minify==`boolean`?v.values.minify:!0;await s({entry:a.replace(process.cwd(),`.`).replace(o.sep,`/`),format:v.values.format??`cjs`,platform:`node`,target:`node22`,watch:v.values.watch,minify:r});let c=v.values.format??`cjs`;v.values.input=o.join(process.cwd(),`dist`,o.basename(a).replace(/\.ts$/,`.${c}`));let l=e(o.join(process.cwd(),`package.json`));if((typeof v.values.obfuscate==`boolean`?v.values.obfuscate:l.private)&&_(v.values.input,v.values.input),v.values.encrypt||t===`pack`){let e=n(v.values.key||o.join(__dirname,`../public.pem`),`utf8`),t=v.values.output||v.values.input.replace(/\.js$/,`-${l.version}.stx`);h(e,v.values.input,t),i(v.values.input)}}else if(t===`decrypt`)g(n(v.values.key||o.join(__dirname,`../private.pem`),`utf8`),a,v.values.output||a.replace(/\.stx$/,`.js`)),v.values.input&&i(v.values.input);else if(t===`dev`||t===`develop`||!t){let e=typeof v.values.minify==`boolean`?v.values.minify:!1;await s({entry:a,format:v.values.format??`cjs`,platform:`node`,target:`node22`,watch:!0,minify:e})}})();export{};
2
+ import { n as __require } from "./chunk-DEt8GZDa.mjs";
3
+ import { parseArgs } from "node:util";
4
+ import { readFileSync, readdirSync, rmSync, writeFileSync } from "node:fs";
5
+ import path from "node:path";
6
+ import { build } from "tsdown";
7
+ import { createCipheriv, createDecipheriv, privateDecrypt, publicEncrypt, randomBytes } from "node:crypto";
8
+ import JavaScriptObfuscator from "javascript-obfuscator";
9
+
10
+ //#region src/crypto.ts
11
+ const MAGIC_BYTES = Buffer.from("STX", "utf8");
12
+ const encrypt = (publicKey, inputPath, outputPath) => {
13
+ const aesKey = randomBytes(32);
14
+ const aesIv = randomBytes(16);
15
+ const code = readFileSync(inputPath);
16
+ const cipher = createCipheriv("aes-256-cbc", aesKey, aesIv);
17
+ const encryptedCode = Buffer.concat([cipher.update(code), cipher.final()]);
18
+ const encryptedAesKey = publicEncrypt(publicKey, aesKey);
19
+ const output = Buffer.concat([
20
+ MAGIC_BYTES,
21
+ aesIv,
22
+ encryptedAesKey,
23
+ encryptedCode
24
+ ]);
25
+ if (outputPath) writeFileSync(outputPath, output);
26
+ return {
27
+ aesIv,
28
+ encryptedAesKey,
29
+ encryptedCode
30
+ };
31
+ };
32
+ const decrypt = (privateKey, inputPath, outputPath) => {
33
+ const data = readFileSync(inputPath);
34
+ const magicSize = MAGIC_BYTES.byteLength;
35
+ if (!data.subarray(0, magicSize).equals(MAGIC_BYTES)) throw new Error("Incorrect file format");
36
+ const aesIvStart = magicSize;
37
+ const encryptedAesKeyStart = aesIvStart + 16;
38
+ const encryptedCodeStart = encryptedAesKeyStart + 512;
39
+ const aesIv = data.subarray(aesIvStart, encryptedAesKeyStart);
40
+ const encryptedAesKey = data.subarray(encryptedAesKeyStart, encryptedCodeStart);
41
+ const encryptedCode = data.subarray(encryptedCodeStart);
42
+ const decipher = createDecipheriv("aes-256-cbc", privateDecrypt(privateKey, encryptedAesKey), aesIv);
43
+ const result = Buffer.concat([decipher.update(encryptedCode), decipher.final()]).toString("utf8");
44
+ if (outputPath) writeFileSync(outputPath, result);
45
+ return result;
46
+ };
47
+
48
+ //#endregion
49
+ //#region src/obfuscation.ts
50
+ const obfuscate = (inputPath, outputPath) => {
51
+ const code = readFileSync(inputPath, "utf8");
52
+ console.log("Obfuscating...");
53
+ console.time("Obfuscation complete in");
54
+ const result = JavaScriptObfuscator.obfuscate(code, {
55
+ target: "node",
56
+ compact: true,
57
+ controlFlowFlattening: true,
58
+ controlFlowFlatteningThreshold: 1,
59
+ deadCodeInjection: true,
60
+ debugProtection: true,
61
+ identifierNamesGenerator: "hexadecimal",
62
+ numbersToExpressions: true,
63
+ selfDefending: true,
64
+ simplify: true,
65
+ splitStrings: true,
66
+ splitStringsChunkLength: 5,
67
+ stringArray: true,
68
+ stringArrayCallsTransform: true,
69
+ stringArrayCallsTransformThreshold: 1,
70
+ stringArrayEncoding: ["base64"],
71
+ stringArrayIndexShift: true,
72
+ stringArrayRotate: true,
73
+ stringArrayShuffle: true,
74
+ stringArrayWrappersCount: 2,
75
+ stringArrayWrappersChainedCalls: true,
76
+ stringArrayWrappersType: "function",
77
+ stringArrayThreshold: 1,
78
+ transformObjectKeys: true,
79
+ unicodeEscapeSequence: false
80
+ });
81
+ console.timeEnd("Obfuscation complete in");
82
+ const obfuscatedCode = result.getObfuscatedCode();
83
+ writeFileSync(outputPath || inputPath, obfuscatedCode);
84
+ return obfuscatedCode;
85
+ };
86
+
87
+ //#endregion
88
+ //#region src/cli.ts
89
+ const args = parseArgs({
90
+ allowPositionals: true,
91
+ allowNegative: true,
92
+ options: {
93
+ input: {
94
+ type: "string",
95
+ short: "i",
96
+ description: "Path to the input file"
97
+ },
98
+ key: {
99
+ type: "string",
100
+ short: "k",
101
+ description: "Path to the key file (public for encrypt, private for decrypt)"
102
+ },
103
+ output: {
104
+ type: "string",
105
+ short: "o",
106
+ description: "Path to the output file"
107
+ },
108
+ format: {
109
+ type: "string",
110
+ short: "f",
111
+ description: "Output format"
112
+ },
113
+ watch: {
114
+ type: "boolean",
115
+ description: "Watch file changes"
116
+ },
117
+ minify: {
118
+ type: "boolean",
119
+ description: "Minify output"
120
+ },
121
+ obfuscate: {
122
+ type: "boolean",
123
+ description: "Obfuscate output"
124
+ },
125
+ encrypt: {
126
+ type: "boolean",
127
+ description: "Encrypt extension source code (.js will be packed inside .stx)"
128
+ },
129
+ decrypt: {
130
+ type: "boolean",
131
+ description: "Decrypt encrypted extension"
132
+ }
133
+ }
134
+ });
135
+ const getDefaultEntryFile = () => {
136
+ const searchDirs = [
137
+ process.cwd(),
138
+ path.join(process.cwd(), "src"),
139
+ path.join(process.cwd(), "lib")
140
+ ];
141
+ for (const searchDir of searchDirs) {
142
+ const scripts = readdirSync(searchDir).filter((file) => !file.endsWith(".d.ts")).filter((file) => new Set([
143
+ ".ts",
144
+ ".js",
145
+ ".cjs",
146
+ ".mjs"
147
+ ]).has(path.extname(file)));
148
+ const getFilename = (file) => path.basename(file, path.extname(file));
149
+ const entry = scripts.find((file) => getFilename(file) === "index") || scripts.find((file) => getFilename(file) === "main") || scripts[0];
150
+ if (entry) return path.join(searchDir, entry);
151
+ }
152
+ };
153
+ (async () => {
154
+ const [command, ...commands] = args.positionals;
155
+ const entry = args.values.input || commands[0] || getDefaultEntryFile();
156
+ if (!entry) throw new Error("No entry file found");
157
+ if (command === "build" || command === "pack") {
158
+ const shouldMinify = typeof args.values.minify === "boolean" ? args.values.minify : true;
159
+ await build({
160
+ entry: entry.replace(process.cwd(), ".").replace(path.sep, "/"),
161
+ format: args.values.format ?? "cjs",
162
+ platform: "node",
163
+ target: "node22",
164
+ watch: args.values.watch,
165
+ minify: shouldMinify,
166
+ inlineOnly: false
167
+ });
168
+ const ext = args.values.format ?? "cjs";
169
+ args.values.input = path.join(process.cwd(), "dist", path.basename(entry).replace(/\.ts$/, `.${ext}`));
170
+ const packageJson = __require(path.join(process.cwd(), "package.json"));
171
+ if (typeof args.values.obfuscate === "boolean" ? args.values.obfuscate : packageJson.private) obfuscate(args.values.input, args.values.input);
172
+ if (args.values.encrypt || command === "pack") {
173
+ const key = readFileSync(args.values.key || path.join(__dirname, "../public.pem"), "utf8");
174
+ const output = args.values.output || args.values.input.replace(/\.js$/, `-${packageJson.version}.stx`);
175
+ encrypt(key, args.values.input, output);
176
+ rmSync(args.values.input);
177
+ }
178
+ } else if (command === "decrypt") {
179
+ decrypt(readFileSync(args.values.key || path.join(__dirname, "../private.pem"), "utf8"), entry, args.values.output || entry.replace(/\.stx$/, ".js"));
180
+ if (args.values.input) rmSync(args.values.input);
181
+ } else if (command === "dev" || command === "develop" || !command) {
182
+ const shouldMinify = typeof args.values.minify === "boolean" ? args.values.minify : false;
183
+ await build({
184
+ entry,
185
+ format: args.values.format ?? "cjs",
186
+ platform: "node",
187
+ target: "node22",
188
+ watch: true,
189
+ minify: shouldMinify
190
+ });
191
+ }
192
+ })();
193
+
194
+ //#endregion
195
+ export { };
@@ -0,0 +1,41 @@
1
+ //#region \0rolldown/runtime.js
2
+ var __create = Object.create;
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __commonJSMin = (cb, mod) => () => (mod || cb((mod = { exports: {} }).exports, mod), mod.exports);
9
+ var __copyProps = (to, from, except, desc) => {
10
+ if (from && typeof from === "object" || typeof from === "function") {
11
+ for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
12
+ key = keys[i];
13
+ if (!__hasOwnProp.call(to, key) && key !== except) {
14
+ __defProp(to, key, {
15
+ get: ((k) => from[k]).bind(null, key),
16
+ enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
17
+ });
18
+ }
19
+ }
20
+ }
21
+ return to;
22
+ };
23
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
24
+ value: mod,
25
+ enumerable: true
26
+ }) : target, mod));
27
+
28
+ //#endregion
29
+
30
+ Object.defineProperty(exports, '__commonJSMin', {
31
+ enumerable: true,
32
+ get: function () {
33
+ return __commonJSMin;
34
+ }
35
+ });
36
+ Object.defineProperty(exports, '__toESM', {
37
+ enumerable: true,
38
+ get: function () {
39
+ return __toESM;
40
+ }
41
+ });
@@ -0,0 +1,8 @@
1
+ import { createRequire } from "node:module";
2
+
3
+ //#region \0rolldown/runtime.js
4
+ var __commonJSMin = (cb, mod) => () => (mod || cb((mod = { exports: {} }).exports, mod), mod.exports);
5
+ var __require = /* @__PURE__ */ createRequire(import.meta.url);
6
+
7
+ //#endregion
8
+ export { __require as n, __commonJSMin as t };