expose-kit 0.2.0 → 0.2.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/dist/index.js CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  // index.ts
4
4
  import { Command } from "commander";
5
- import { dirname, join } from "path";
5
+ import { dirname as dirname2, join as join2 } from "path";
6
6
  import { fileURLToPath } from "url";
7
7
  import chalk4 from "chalk";
8
8
 
@@ -71,36 +71,124 @@ var showError = (message) => {
71
71
 
72
72
  // commands/parsable/index.ts
73
73
  var parsable_default = createCommand((program2) => {
74
- program2.command("parsable").description("Check if the file is parsable").argument("[file]", "The file to check").option("--file <file>", "The file to check").action(async (fileArgument, options) => {
75
- await timeout(async ({ finish }) => {
76
- const filename = fileArgument ?? options.file ?? createPrompt("Enter the file path:");
77
- if (!filename) {
78
- showError("No file provided");
79
- return finish();
80
- }
81
- try {
82
- const fileContent = readFileSync(filename, "utf8");
83
- const loader = loading("Checking if the file is parsable...").start();
84
- try {
85
- parse(fileContent, createParseOptions(filename));
86
- await sleep(500);
87
- loader.succeed("File is parsable");
88
- return finish();
89
- } catch (error) {
90
- loader.fail("File is not parsable");
91
- showError(
92
- `Error parsing file '${filename}': ${error instanceof Error ? error.message : "Unknown error"}`
93
- );
94
- return finish();
74
+ program2.command("parsable").description("Check if the file is parsable").argument("[file]", "The file to check").option("--input, --file <file>", "The file to check").option("--unlimited", "Unlimited timeout").action(
75
+ async (fileArgument, options) => {
76
+ await timeout(
77
+ async ({ finish }) => {
78
+ const filename = fileArgument ?? options.file ?? createPrompt("Enter the file path:");
79
+ if (!filename) {
80
+ showError("No file provided");
81
+ return finish();
82
+ }
83
+ try {
84
+ const fileContent = readFileSync(filename, "utf8");
85
+ const loader = loading(
86
+ "Checking if the file is parsable..."
87
+ ).start();
88
+ try {
89
+ parse(fileContent, createParseOptions(filename));
90
+ await sleep(500);
91
+ loader.succeed("File is parsable");
92
+ return finish();
93
+ } catch (error) {
94
+ loader.fail("File is not parsable");
95
+ showError(
96
+ `Error parsing file '${filename}': ${error instanceof Error ? error.message : "Unknown error"}`
97
+ );
98
+ return finish();
99
+ }
100
+ } catch (error) {
101
+ showError(
102
+ `Error reading file '${filename}': ${error instanceof Error ? error.message : "Unknown error"}`
103
+ );
104
+ return finish();
105
+ }
106
+ },
107
+ options.unlimited ? Infinity : 30 * 1e3
108
+ );
109
+ }
110
+ );
111
+ });
112
+
113
+ // commands/scope-safe/index.ts
114
+ import { readFileSync as readFileSync2, writeFileSync } from "fs";
115
+ import { basename, dirname, extname, join } from "path";
116
+ import { parse as parse2 } from "@babel/parser";
117
+ import traverse from "@babel/traverse";
118
+ import generate from "@babel/generator";
119
+ import loading2 from "loading-cli";
120
+ var createDefaultOutputPath = (inputPath) => {
121
+ const ext = extname(inputPath);
122
+ if (!ext) {
123
+ return `${inputPath}.scope-safe.js`;
124
+ }
125
+ const base = basename(inputPath, ext);
126
+ return join(dirname(inputPath), `${base}.scope-safe${ext}`);
127
+ };
128
+ var renameBindingsByScope = (code, filename) => {
129
+ const ast = parse2(code, createParseOptions(filename));
130
+ const renamedBindings = /* @__PURE__ */ new Set();
131
+ traverse(ast, {
132
+ Scopable(path) {
133
+ for (const [name, binding] of Object.entries(path.scope.bindings)) {
134
+ if (renamedBindings.has(binding)) {
135
+ continue;
95
136
  }
96
- } catch (error) {
97
- showError(
98
- `Error reading file '${filename}': ${error instanceof Error ? error.message : "Unknown error"}`
99
- );
100
- return finish();
137
+ const shouldRename = !!path.scope.parent?.hasBinding(name);
138
+ if (!shouldRename) {
139
+ renamedBindings.add(binding);
140
+ continue;
141
+ }
142
+ const newName = path.scope.generateUid(name);
143
+ if (newName !== name) {
144
+ path.scope.rename(name, newName);
145
+ }
146
+ renamedBindings.add(binding);
101
147
  }
102
- }, 30 * 1e3);
148
+ }
103
149
  });
150
+ return generate(ast).code;
151
+ };
152
+ var scope_safe_default = createCommand((program2) => {
153
+ program2.command("scope-safe").description("Rename bindings per scope for safer transforms").argument("[file]", "The file to transform").option("--input, --file <file>", "The file to transform").option("--o, --output <file>", "Output file path").option("--unlimited", "Unlimited timeout").action(
154
+ async (fileArgument, options) => {
155
+ await timeout(
156
+ async ({ finish }) => {
157
+ const filename = fileArgument ?? options.file ?? createPrompt("Enter the file path:");
158
+ if (!filename) {
159
+ showError("No file provided");
160
+ return finish();
161
+ }
162
+ try {
163
+ const fileContent = readFileSync2(filename, "utf8");
164
+ const defaultOutputPath = createDefaultOutputPath(filename);
165
+ let outputPath = options.output ?? (createPrompt(
166
+ "Enter the output file path:"
167
+ ) || "").trim() ?? defaultOutputPath;
168
+ const loader = loading2("Renaming variables by scope...").start();
169
+ try {
170
+ const output = renameBindingsByScope(fileContent, filename);
171
+ writeFileSync(outputPath, output, "utf8");
172
+ loader.succeed(`Saved scope-safe file to: ${outputPath}`);
173
+ return finish();
174
+ } catch (error) {
175
+ loader.fail("Failed to apply scope-safe transform");
176
+ showError(
177
+ `Error transforming file '${filename}': ${error instanceof Error ? error.message : "Unknown error"}`
178
+ );
179
+ return finish();
180
+ }
181
+ } catch (error) {
182
+ showError(
183
+ `Error reading file '${filename}': ${error instanceof Error ? error.message : "Unknown error"}`
184
+ );
185
+ return finish();
186
+ }
187
+ },
188
+ options.unlimited ? Infinity : 120 * 1e3
189
+ );
190
+ }
191
+ );
104
192
  });
105
193
 
106
194
  // utils/cli/showCredit.ts
@@ -117,7 +205,7 @@ var beautify = (strings, ...values) => {
117
205
  return result;
118
206
  };
119
207
  var isNoColor = () => {
120
- return process.env.NO_COLOR !== void 0 && process.argv.includes("--no-color");
208
+ return Bun.env.NO_COLOR !== void 0 && Bun.argv.includes("--no-color");
121
209
  };
122
210
  var calmGradienrain = (text) => {
123
211
  if (isNoColor()) {
@@ -154,10 +242,10 @@ ${calmGradienrain(`Expose Kit v${VERSION}`)}
154
242
  `;
155
243
 
156
244
  // index.ts
157
- import { readFileSync as readFileSync2 } from "fs";
245
+ import { readFileSync as readFileSync3 } from "fs";
158
246
  var __filename = fileURLToPath(import.meta.url);
159
- var __dirname = dirname(__filename);
160
- var pkg = JSON.parse(readFileSync2(join(__dirname, "package.json"), "utf8"));
247
+ var __dirname = dirname2(__filename);
248
+ var pkg = JSON.parse(readFileSync3(join2(__dirname, "package.json"), "utf8"));
161
249
  console.log(showCredit(pkg.version));
162
250
  console.log();
163
251
  var program = new Command();
@@ -166,7 +254,7 @@ program.name("expose").description("CLI for Deobfuscating").version(
166
254
  "-v, --version",
167
255
  "display version number"
168
256
  );
169
- var commands = [parsable_default];
257
+ var commands = [parsable_default, scope_safe_default];
170
258
  for (const command of commands) {
171
259
  command(program);
172
260
  }
package/dist/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "expose-kit",
3
- "version": "0.2.0",
3
+ "version": "0.2.1",
4
4
  "type": "module",
5
5
  "private": false,
6
6
  "author": "EdamAmex <edame8080@gmail.com> (https://github.com/EdamAme-x)",
@@ -24,7 +24,7 @@
24
24
  "build": "tsup",
25
25
  "postbuild": "publint",
26
26
  "prepublishOnly": "bun copy",
27
- "release": "np"
27
+ "release": "bun run build && np"
28
28
  },
29
29
  "devDependencies": {
30
30
  "@biomejs/biome": "2.3.11",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "expose-kit",
3
- "version": "0.2.0",
3
+ "version": "0.2.1",
4
4
  "type": "module",
5
5
  "private": false,
6
6
  "author": "EdamAmex <edame8080@gmail.com> (https://github.com/EdamAme-x)",
@@ -24,7 +24,7 @@
24
24
  "build": "tsup",
25
25
  "postbuild": "publint",
26
26
  "prepublishOnly": "bun copy",
27
- "release": "np"
27
+ "release": "bun run build && np"
28
28
  },
29
29
  "devDependencies": {
30
30
  "@biomejs/biome": "2.3.11",