@afterpack/core 0.0.9 → 0.1.0

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 ADDED
@@ -0,0 +1,133 @@
1
+ AfterPack Engine License
2
+
3
+ Copyright 2026 AfterPack (https://www.afterpack.dev)
4
+
5
+ A plain-language summary is at https://www.afterpack.dev/license. The summary
6
+ is for convenience; these terms are the license.
7
+
8
+ ## Acceptance
9
+
10
+ By using the software, you agree to all of the terms and conditions below.
11
+
12
+ ## Copyright License
13
+
14
+ The licensor grants you a non-exclusive, royalty-free, worldwide,
15
+ non-sublicensable, non-transferable license to use and copy the software, and to
16
+ distribute unmodified copies of it as part of the dependencies of your own
17
+ projects (for example in `node_modules`, lockfiles, build caches and container
18
+ images), in each case subject to the limitations and conditions below. This
19
+ includes commercial use and use in continuous integration and build pipelines.
20
+ There are no usage limits.
21
+
22
+ ## Output
23
+
24
+ Code transformed or produced by running the software is yours, subject only
25
+ to any rights others hold in the code you gave it. The licensor claims no
26
+ rights in that output, and no notice, attribution or royalty is required to use
27
+ or distribute it.
28
+
29
+ ## Plugins and Integrations
30
+
31
+ You may write plugins, integrations and other tools that call the software's
32
+ documented public API, and license them however you choose. Such works are not
33
+ modifications of the software. They may depend on the software as a package
34
+ dependency, but any copy of the software they carry remains under these terms.
35
+
36
+ ## Limitations
37
+
38
+ You may not distribute the software on its own, or as part of a product that
39
+ offers JavaScript obfuscation or code protection and competes with the
40
+ licensor.
41
+
42
+ You may not provide JavaScript obfuscation or code protection to third parties
43
+ as a hosted or managed service that is built on the software. Using the
44
+ software inside your own product or service, where protecting code is not what
45
+ you offer to others, is allowed: for example, protecting the code your product
46
+ ships, or your own users' traffic.
47
+
48
+ You may not modify, translate or create derivative works of the software.
49
+
50
+ You may not reverse engineer, decompile or disassemble the software.
51
+
52
+ You may not use the software for any unlawful purpose, or to create,
53
+ facilitate or distribute malware, spyware or phishing.
54
+
55
+ You may not alter, remove, or obscure any licensing, copyright, or other notices
56
+ of the licensor in the software. Any use of the licensor's trademarks is subject
57
+ to applicable law.
58
+
59
+ ## Cloud Services
60
+
61
+ With an AfterPack Pro key, the software sends builds to the licensor's cloud
62
+ service. Use of that service is governed by the Terms of Service at
63
+ https://www.afterpack.dev/terms.
64
+
65
+ ## Patents
66
+
67
+ The licensor grants you a license, under any patent claims the licensor can
68
+ license, or becomes able to license, to make, have made, use, sell, offer for
69
+ sale, import and have imported the software, in each case subject to the
70
+ limitations and conditions in this license. If you or your company make any
71
+ written claim that the software infringes or contributes to infringement of any
72
+ patent, your patent license for the software granted under these terms ends
73
+ immediately. If your company makes such a claim, your patent license ends
74
+ immediately for work on behalf of your company.
75
+
76
+ ## Notices
77
+
78
+ You must ensure that anyone who gets a copy of any part of the software from you
79
+ also gets a copy of these terms.
80
+
81
+ ## No Other Rights
82
+
83
+ These terms do not imply any licenses other than those expressly granted in
84
+ these terms.
85
+
86
+ ## Termination
87
+
88
+ If you use the software in violation of these terms, such use is not licensed,
89
+ and your licenses will automatically terminate. If the licensor provides you
90
+ with a notice of your violation, and you cease all violation of this license no
91
+ later than 30 days after you receive that notice, your licenses will be
92
+ reinstated retroactively. However, if you violate these terms after such
93
+ reinstatement, any additional violation of these terms will cause your licenses
94
+ to terminate automatically and permanently. Output you created while licensed
95
+ remains yours.
96
+
97
+ ## No Liability
98
+
99
+ AS FAR AS THE LAW ALLOWS, THE SOFTWARE COMES AS IS, WITHOUT ANY WARRANTY OR
100
+ CONDITION, AND THE LICENSOR WILL NOT BE LIABLE TO YOU FOR ANY DAMAGES ARISING
101
+ OUT OF THESE TERMS OR THE USE OR NATURE OF THE SOFTWARE, UNDER ANY KIND OF
102
+ LEGAL CLAIM.
103
+
104
+ ## Definitions
105
+
106
+ The **licensor** is AfterPack, and the **software** is the AfterPack engine as
107
+ distributed in compiled form: the `@afterpack/core` and `@afterpack/wasm`
108
+ packages, the platform-specific `@afterpack/core-<platform>` packages that
109
+ carry its native binaries, and any other prebuilt AfterPack engine binary,
110
+ including any portion of them.
111
+
112
+ **you** refers to the individual or entity agreeing to these terms.
113
+
114
+ **your company** is any legal entity, sole proprietorship, or other kind of
115
+ organization that you work for, plus all organizations that have control over,
116
+ are under the control of, or are under common control with that
117
+ organization. **control** means ownership of substantially all the assets of an
118
+ entity, or the power to direct its management and policies by vote, contract, or
119
+ otherwise. Control can be direct or indirect.
120
+
121
+ **your licenses** are all the licenses granted to you for the software under
122
+ these terms.
123
+
124
+ **use** means anything you do with the software requiring one of your licenses.
125
+
126
+ **trademark** means trademarks, service marks, and similar rights.
127
+
128
+ ---
129
+
130
+ These terms are adapted from the Elastic License 2.0
131
+ (https://www.elastic.co/licensing/elastic-license), whose text is available
132
+ under the Creative Commons Attribution 4.0 International license. This license
133
+ is not the Elastic License and is not endorsed by Elastic.
package/index.d.ts CHANGED
@@ -1,25 +1,41 @@
1
- /* auto-generated by NAPI-RS */
2
- /* eslint-disable */
3
- /**
4
- * Process JavaScript code and return the transformed result.
5
- *
6
- * For MVP: Appends version comment to the end of the code.
7
- */
8
- export declare function process(code: string): string
1
+ import type { AfterpackConfig, BatchFileInput, BatchResult, BuildContext } from "./public-api";
9
2
 
10
- /**
11
- * Process a JavaScript file in place.
12
- *
13
- * Reads the file, processes it, and writes the result back.
14
- */
15
- export declare function processFile(filePath: string): void
3
+ export { ObfuscationError, obfuscate, obfuscateAll } from "./public-api";
4
+ export type {
5
+ AfterpackConfig,
6
+ BatchFileInput,
7
+ BatchFileResult,
8
+ BatchResult,
9
+ BuildContext,
10
+ CloudErrorCode,
11
+ Diagnostic,
12
+ FileInput,
13
+ GlobReserved,
14
+ Notice,
15
+ Preset,
16
+ ProtectionMap,
17
+ ProtectionMapFile,
18
+ ReflectionAllow,
19
+ RegionConfig,
20
+ Result,
21
+ Severity,
22
+ Span,
23
+ TransformKind,
24
+ } from "./public-api";
25
+
26
+ /** The AfterPack engine version, e.g. `0.1.0`. */
27
+ export declare function version(): Promise<string>;
16
28
 
17
29
  /**
18
- * Process a JavaScript file and return the result without modifying the original.
30
+ * Lower-level batch entry used by AfterPack's build plugins. Prefer `obfuscateAll`.
19
31
  *
20
- * Useful for previewing changes or writing to a different location.
32
+ * Unlike `obfuscateAll`, a failed file comes back with `status: "failure"` instead of throwing.
33
+ * It rejects with an {@link ObfuscationError} when the config is invalid or a cloud build fails.
34
+ * When the AfterPack service refused the build, `err.code` is a `CloudErrorCode` and `err.details`
35
+ * and `err.notices` carry the service's structured detail.
21
36
  */
22
- export declare function processFileToString(filePath: string): string
23
-
24
- /** Get the AfterPack version string. */
25
- export declare function version(): string
37
+ export declare function processBatch(
38
+ files: BatchFileInput[],
39
+ config: AfterpackConfig,
40
+ buildContext?: BuildContext | null,
41
+ ): Promise<BatchResult>;
package/index.js CHANGED
@@ -77,8 +77,8 @@ function requireNative() {
77
77
  try {
78
78
  const binding = require('@afterpack/core-android-arm64')
79
79
  const bindingPackageVersion = require('@afterpack/core-android-arm64/package.json').version
80
- if (bindingPackageVersion !== '0.0.4' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
81
- throw new Error(`Native binding package version mismatch, expected 0.0.4 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
80
+ if (bindingPackageVersion !== '0.1.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
81
+ throw new Error(`Native binding package version mismatch, expected 0.1.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
82
82
  }
83
83
  return binding
84
84
  } catch (e) {
@@ -93,8 +93,8 @@ function requireNative() {
93
93
  try {
94
94
  const binding = require('@afterpack/core-android-arm-eabi')
95
95
  const bindingPackageVersion = require('@afterpack/core-android-arm-eabi/package.json').version
96
- if (bindingPackageVersion !== '0.0.4' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
97
- throw new Error(`Native binding package version mismatch, expected 0.0.4 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
96
+ if (bindingPackageVersion !== '0.1.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
97
+ throw new Error(`Native binding package version mismatch, expected 0.1.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
98
98
  }
99
99
  return binding
100
100
  } catch (e) {
@@ -114,8 +114,8 @@ function requireNative() {
114
114
  try {
115
115
  const binding = require('@afterpack/core-win32-x64-gnu')
116
116
  const bindingPackageVersion = require('@afterpack/core-win32-x64-gnu/package.json').version
117
- if (bindingPackageVersion !== '0.0.4' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
118
- throw new Error(`Native binding package version mismatch, expected 0.0.4 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
117
+ if (bindingPackageVersion !== '0.1.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
118
+ throw new Error(`Native binding package version mismatch, expected 0.1.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
119
119
  }
120
120
  return binding
121
121
  } catch (e) {
@@ -130,8 +130,8 @@ function requireNative() {
130
130
  try {
131
131
  const binding = require('@afterpack/core-win32-x64-msvc')
132
132
  const bindingPackageVersion = require('@afterpack/core-win32-x64-msvc/package.json').version
133
- if (bindingPackageVersion !== '0.0.4' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
134
- throw new Error(`Native binding package version mismatch, expected 0.0.4 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
133
+ if (bindingPackageVersion !== '0.1.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
134
+ throw new Error(`Native binding package version mismatch, expected 0.1.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
135
135
  }
136
136
  return binding
137
137
  } catch (e) {
@@ -147,8 +147,8 @@ function requireNative() {
147
147
  try {
148
148
  const binding = require('@afterpack/core-win32-ia32-msvc')
149
149
  const bindingPackageVersion = require('@afterpack/core-win32-ia32-msvc/package.json').version
150
- if (bindingPackageVersion !== '0.0.4' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
151
- throw new Error(`Native binding package version mismatch, expected 0.0.4 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
150
+ if (bindingPackageVersion !== '0.1.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
151
+ throw new Error(`Native binding package version mismatch, expected 0.1.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
152
152
  }
153
153
  return binding
154
154
  } catch (e) {
@@ -163,8 +163,8 @@ function requireNative() {
163
163
  try {
164
164
  const binding = require('@afterpack/core-win32-arm64-msvc')
165
165
  const bindingPackageVersion = require('@afterpack/core-win32-arm64-msvc/package.json').version
166
- if (bindingPackageVersion !== '0.0.4' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
167
- throw new Error(`Native binding package version mismatch, expected 0.0.4 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
166
+ if (bindingPackageVersion !== '0.1.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
167
+ throw new Error(`Native binding package version mismatch, expected 0.1.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
168
168
  }
169
169
  return binding
170
170
  } catch (e) {
@@ -182,8 +182,8 @@ function requireNative() {
182
182
  try {
183
183
  const binding = require('@afterpack/core-darwin-universal')
184
184
  const bindingPackageVersion = require('@afterpack/core-darwin-universal/package.json').version
185
- if (bindingPackageVersion !== '0.0.4' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
186
- throw new Error(`Native binding package version mismatch, expected 0.0.4 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
185
+ if (bindingPackageVersion !== '0.1.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
186
+ throw new Error(`Native binding package version mismatch, expected 0.1.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
187
187
  }
188
188
  return binding
189
189
  } catch (e) {
@@ -198,8 +198,8 @@ function requireNative() {
198
198
  try {
199
199
  const binding = require('@afterpack/core-darwin-x64')
200
200
  const bindingPackageVersion = require('@afterpack/core-darwin-x64/package.json').version
201
- if (bindingPackageVersion !== '0.0.4' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
202
- throw new Error(`Native binding package version mismatch, expected 0.0.4 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
201
+ if (bindingPackageVersion !== '0.1.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
202
+ throw new Error(`Native binding package version mismatch, expected 0.1.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
203
203
  }
204
204
  return binding
205
205
  } catch (e) {
@@ -214,8 +214,8 @@ function requireNative() {
214
214
  try {
215
215
  const binding = require('@afterpack/core-darwin-arm64')
216
216
  const bindingPackageVersion = require('@afterpack/core-darwin-arm64/package.json').version
217
- if (bindingPackageVersion !== '0.0.4' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
218
- throw new Error(`Native binding package version mismatch, expected 0.0.4 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
217
+ if (bindingPackageVersion !== '0.1.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
218
+ throw new Error(`Native binding package version mismatch, expected 0.1.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
219
219
  }
220
220
  return binding
221
221
  } catch (e) {
@@ -234,8 +234,8 @@ function requireNative() {
234
234
  try {
235
235
  const binding = require('@afterpack/core-freebsd-x64')
236
236
  const bindingPackageVersion = require('@afterpack/core-freebsd-x64/package.json').version
237
- if (bindingPackageVersion !== '0.0.4' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
238
- throw new Error(`Native binding package version mismatch, expected 0.0.4 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
237
+ if (bindingPackageVersion !== '0.1.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
238
+ throw new Error(`Native binding package version mismatch, expected 0.1.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
239
239
  }
240
240
  return binding
241
241
  } catch (e) {
@@ -250,8 +250,8 @@ function requireNative() {
250
250
  try {
251
251
  const binding = require('@afterpack/core-freebsd-arm64')
252
252
  const bindingPackageVersion = require('@afterpack/core-freebsd-arm64/package.json').version
253
- if (bindingPackageVersion !== '0.0.4' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
254
- throw new Error(`Native binding package version mismatch, expected 0.0.4 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
253
+ if (bindingPackageVersion !== '0.1.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
254
+ throw new Error(`Native binding package version mismatch, expected 0.1.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
255
255
  }
256
256
  return binding
257
257
  } catch (e) {
@@ -271,8 +271,8 @@ function requireNative() {
271
271
  try {
272
272
  const binding = require('@afterpack/core-linux-x64-musl')
273
273
  const bindingPackageVersion = require('@afterpack/core-linux-x64-musl/package.json').version
274
- if (bindingPackageVersion !== '0.0.4' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
275
- throw new Error(`Native binding package version mismatch, expected 0.0.4 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
274
+ if (bindingPackageVersion !== '0.1.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
275
+ throw new Error(`Native binding package version mismatch, expected 0.1.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
276
276
  }
277
277
  return binding
278
278
  } catch (e) {
@@ -287,8 +287,8 @@ function requireNative() {
287
287
  try {
288
288
  const binding = require('@afterpack/core-linux-x64-gnu')
289
289
  const bindingPackageVersion = require('@afterpack/core-linux-x64-gnu/package.json').version
290
- if (bindingPackageVersion !== '0.0.4' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
291
- throw new Error(`Native binding package version mismatch, expected 0.0.4 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
290
+ if (bindingPackageVersion !== '0.1.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
291
+ throw new Error(`Native binding package version mismatch, expected 0.1.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
292
292
  }
293
293
  return binding
294
294
  } catch (e) {
@@ -305,8 +305,8 @@ function requireNative() {
305
305
  try {
306
306
  const binding = require('@afterpack/core-linux-arm64-musl')
307
307
  const bindingPackageVersion = require('@afterpack/core-linux-arm64-musl/package.json').version
308
- if (bindingPackageVersion !== '0.0.4' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
309
- throw new Error(`Native binding package version mismatch, expected 0.0.4 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
308
+ if (bindingPackageVersion !== '0.1.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
309
+ throw new Error(`Native binding package version mismatch, expected 0.1.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
310
310
  }
311
311
  return binding
312
312
  } catch (e) {
@@ -321,8 +321,8 @@ function requireNative() {
321
321
  try {
322
322
  const binding = require('@afterpack/core-linux-arm64-gnu')
323
323
  const bindingPackageVersion = require('@afterpack/core-linux-arm64-gnu/package.json').version
324
- if (bindingPackageVersion !== '0.0.4' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
325
- throw new Error(`Native binding package version mismatch, expected 0.0.4 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
324
+ if (bindingPackageVersion !== '0.1.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
325
+ throw new Error(`Native binding package version mismatch, expected 0.1.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
326
326
  }
327
327
  return binding
328
328
  } catch (e) {
@@ -339,8 +339,8 @@ function requireNative() {
339
339
  try {
340
340
  const binding = require('@afterpack/core-linux-arm-musleabihf')
341
341
  const bindingPackageVersion = require('@afterpack/core-linux-arm-musleabihf/package.json').version
342
- if (bindingPackageVersion !== '0.0.4' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
343
- throw new Error(`Native binding package version mismatch, expected 0.0.4 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
342
+ if (bindingPackageVersion !== '0.1.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
343
+ throw new Error(`Native binding package version mismatch, expected 0.1.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
344
344
  }
345
345
  return binding
346
346
  } catch (e) {
@@ -355,8 +355,8 @@ function requireNative() {
355
355
  try {
356
356
  const binding = require('@afterpack/core-linux-arm-gnueabihf')
357
357
  const bindingPackageVersion = require('@afterpack/core-linux-arm-gnueabihf/package.json').version
358
- if (bindingPackageVersion !== '0.0.4' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
359
- throw new Error(`Native binding package version mismatch, expected 0.0.4 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
358
+ if (bindingPackageVersion !== '0.1.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
359
+ throw new Error(`Native binding package version mismatch, expected 0.1.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
360
360
  }
361
361
  return binding
362
362
  } catch (e) {
@@ -373,8 +373,8 @@ function requireNative() {
373
373
  try {
374
374
  const binding = require('@afterpack/core-linux-loong64-musl')
375
375
  const bindingPackageVersion = require('@afterpack/core-linux-loong64-musl/package.json').version
376
- if (bindingPackageVersion !== '0.0.4' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
377
- throw new Error(`Native binding package version mismatch, expected 0.0.4 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
376
+ if (bindingPackageVersion !== '0.1.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
377
+ throw new Error(`Native binding package version mismatch, expected 0.1.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
378
378
  }
379
379
  return binding
380
380
  } catch (e) {
@@ -389,8 +389,8 @@ function requireNative() {
389
389
  try {
390
390
  const binding = require('@afterpack/core-linux-loong64-gnu')
391
391
  const bindingPackageVersion = require('@afterpack/core-linux-loong64-gnu/package.json').version
392
- if (bindingPackageVersion !== '0.0.4' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
393
- throw new Error(`Native binding package version mismatch, expected 0.0.4 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
392
+ if (bindingPackageVersion !== '0.1.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
393
+ throw new Error(`Native binding package version mismatch, expected 0.1.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
394
394
  }
395
395
  return binding
396
396
  } catch (e) {
@@ -407,8 +407,8 @@ function requireNative() {
407
407
  try {
408
408
  const binding = require('@afterpack/core-linux-riscv64-musl')
409
409
  const bindingPackageVersion = require('@afterpack/core-linux-riscv64-musl/package.json').version
410
- if (bindingPackageVersion !== '0.0.4' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
411
- throw new Error(`Native binding package version mismatch, expected 0.0.4 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
410
+ if (bindingPackageVersion !== '0.1.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
411
+ throw new Error(`Native binding package version mismatch, expected 0.1.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
412
412
  }
413
413
  return binding
414
414
  } catch (e) {
@@ -423,8 +423,8 @@ function requireNative() {
423
423
  try {
424
424
  const binding = require('@afterpack/core-linux-riscv64-gnu')
425
425
  const bindingPackageVersion = require('@afterpack/core-linux-riscv64-gnu/package.json').version
426
- if (bindingPackageVersion !== '0.0.4' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
427
- throw new Error(`Native binding package version mismatch, expected 0.0.4 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
426
+ if (bindingPackageVersion !== '0.1.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
427
+ throw new Error(`Native binding package version mismatch, expected 0.1.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
428
428
  }
429
429
  return binding
430
430
  } catch (e) {
@@ -440,8 +440,8 @@ function requireNative() {
440
440
  try {
441
441
  const binding = require('@afterpack/core-linux-ppc64-gnu')
442
442
  const bindingPackageVersion = require('@afterpack/core-linux-ppc64-gnu/package.json').version
443
- if (bindingPackageVersion !== '0.0.4' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
444
- throw new Error(`Native binding package version mismatch, expected 0.0.4 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
443
+ if (bindingPackageVersion !== '0.1.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
444
+ throw new Error(`Native binding package version mismatch, expected 0.1.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
445
445
  }
446
446
  return binding
447
447
  } catch (e) {
@@ -456,8 +456,8 @@ function requireNative() {
456
456
  try {
457
457
  const binding = require('@afterpack/core-linux-s390x-gnu')
458
458
  const bindingPackageVersion = require('@afterpack/core-linux-s390x-gnu/package.json').version
459
- if (bindingPackageVersion !== '0.0.4' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
460
- throw new Error(`Native binding package version mismatch, expected 0.0.4 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
459
+ if (bindingPackageVersion !== '0.1.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
460
+ throw new Error(`Native binding package version mismatch, expected 0.1.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
461
461
  }
462
462
  return binding
463
463
  } catch (e) {
@@ -476,8 +476,8 @@ function requireNative() {
476
476
  try {
477
477
  const binding = require('@afterpack/core-openharmony-arm64')
478
478
  const bindingPackageVersion = require('@afterpack/core-openharmony-arm64/package.json').version
479
- if (bindingPackageVersion !== '0.0.4' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
480
- throw new Error(`Native binding package version mismatch, expected 0.0.4 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
479
+ if (bindingPackageVersion !== '0.1.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
480
+ throw new Error(`Native binding package version mismatch, expected 0.1.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
481
481
  }
482
482
  return binding
483
483
  } catch (e) {
@@ -492,8 +492,8 @@ function requireNative() {
492
492
  try {
493
493
  const binding = require('@afterpack/core-openharmony-x64')
494
494
  const bindingPackageVersion = require('@afterpack/core-openharmony-x64/package.json').version
495
- if (bindingPackageVersion !== '0.0.4' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
496
- throw new Error(`Native binding package version mismatch, expected 0.0.4 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
495
+ if (bindingPackageVersion !== '0.1.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
496
+ throw new Error(`Native binding package version mismatch, expected 0.1.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
497
497
  }
498
498
  return binding
499
499
  } catch (e) {
@@ -508,8 +508,8 @@ function requireNative() {
508
508
  try {
509
509
  const binding = require('@afterpack/core-openharmony-arm')
510
510
  const bindingPackageVersion = require('@afterpack/core-openharmony-arm/package.json').version
511
- if (bindingPackageVersion !== '0.0.4' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
512
- throw new Error(`Native binding package version mismatch, expected 0.0.4 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
511
+ if (bindingPackageVersion !== '0.1.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
512
+ throw new Error(`Native binding package version mismatch, expected 0.1.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
513
513
  }
514
514
  return binding
515
515
  } catch (e) {
@@ -576,7 +576,13 @@ if (!nativeBinding) {
576
576
  }
577
577
 
578
578
  module.exports = nativeBinding
579
- module.exports.process = nativeBinding.process
580
- module.exports.processFile = nativeBinding.processFile
581
- module.exports.processFileToString = nativeBinding.processFileToString
579
+ module.exports.processBatch = nativeBinding.processBatch
582
580
  module.exports.version = nativeBinding.version
581
+
582
+ /* === AfterPack public API === */
583
+ const afterpackPublicApi = require('./public-api.js')
584
+ const afterpackNativeProcessBatch = module.exports.processBatch
585
+ module.exports.processBatch = afterpackPublicApi.makeProcessBatch(afterpackNativeProcessBatch)
586
+ module.exports.obfuscate = afterpackPublicApi.obfuscate
587
+ module.exports.obfuscateAll = afterpackPublicApi.obfuscateAll
588
+ module.exports.ObfuscationError = afterpackPublicApi.ObfuscationError
package/package.json CHANGED
@@ -1,62 +1,70 @@
1
1
  {
2
- "name": "@afterpack/core",
3
- "version": "0.0.9",
4
- "description": "AfterPack core engine - High-performance JavaScript obfuscator",
5
- "main": "index.js",
6
- "types": "index.d.ts",
7
- "napi": {
8
- "binaryName": "afterpack-napi",
9
- "targets": [
10
- "x86_64-apple-darwin",
11
- "aarch64-apple-darwin",
12
- "x86_64-unknown-linux-gnu",
13
- "aarch64-unknown-linux-gnu",
14
- "x86_64-pc-windows-msvc"
15
- ]
16
- },
17
- "files": [
18
- "index.js",
19
- "index.d.ts",
20
- "readme.md"
21
- ],
22
- "scripts": {},
23
- "engines": {
24
- "node": ">= 18"
25
- },
26
- "publishConfig": {
27
- "access": "public",
28
- "registry": "https://registry.npmjs.org/"
29
- },
30
- "devDependencies": {
31
- "@napi-rs/cli": "^3.0.0-alpha.64",
32
- "@types/node": "^22.0.0",
33
- "tsx": "^4.21.0",
34
- "typescript": "^5.7.0",
35
- "vitest": "^2.0.0"
36
- },
37
- "repository": {
38
- "type": "git",
39
- "url": "git+https://github.com/afterpack-dev/platform.git"
40
- },
41
- "homepage": "https://www.afterpack.dev",
42
- "bugs": {
43
- "url": "https://github.com/afterpack-dev/afterpack/issues"
44
- },
45
- "keywords": [
46
- "obfuscator",
47
- "javascript",
48
- "minifier",
49
- "protection",
50
- "code-protection",
51
- "afterpack"
52
- ],
53
- "author": "AfterPack <hello@afterpack.dev>",
54
- "license": "MIT",
55
- "optionalDependencies": {
56
- "@afterpack/core-darwin-arm64": "0.0.9",
57
- "@afterpack/core-darwin-x64": "0.0.9",
58
- "@afterpack/core-linux-arm64-gnu": "0.0.9",
59
- "@afterpack/core-linux-x64-gnu": "0.0.9",
60
- "@afterpack/core-win32-x64-msvc": "0.0.9"
61
- }
2
+ "name": "@afterpack/core",
3
+ "version": "0.1.0",
4
+ "description": "JavaScript obfuscator engine for Node: protect your JavaScript source code in any build, locally or with AfterPack Pro",
5
+ "main": "index.js",
6
+ "types": "index.d.ts",
7
+ "exports": {
8
+ ".": {
9
+ "types": "./index.d.ts",
10
+ "require": "./index.js",
11
+ "import": "./index.js",
12
+ "default": "./index.js"
13
+ },
14
+ "./package.json": "./package.json"
15
+ },
16
+ "napi": {
17
+ "binaryName": "afterpack-napi",
18
+ "targets": [
19
+ "x86_64-apple-darwin",
20
+ "aarch64-apple-darwin",
21
+ "x86_64-unknown-linux-gnu",
22
+ "aarch64-unknown-linux-gnu",
23
+ "x86_64-unknown-linux-musl",
24
+ "aarch64-unknown-linux-musl",
25
+ "x86_64-pc-windows-msvc"
26
+ ]
27
+ },
28
+ "files": [
29
+ "index.js",
30
+ "index.d.ts",
31
+ "public-api.js",
32
+ "public-api.d.ts",
33
+ "readme.md"
34
+ ],
35
+ "engines": {
36
+ "node": ">= 18"
37
+ },
38
+ "publishConfig": {
39
+ "access": "public",
40
+ "registry": "https://registry.npmjs.org/"
41
+ },
42
+ "homepage": "https://www.afterpack.dev/docs",
43
+ "bugs": {
44
+ "url": "https://github.com/afterpack-dev/afterpack/issues"
45
+ },
46
+ "keywords": [
47
+ "obfuscator",
48
+ "javascript-obfuscator",
49
+ "obfuscation",
50
+ "javascript",
51
+ "code-protection",
52
+ "source-code-protection",
53
+ "javascript-security",
54
+ "anti-reverse-engineering",
55
+ "obfuscate",
56
+ "source-maps",
57
+ "afterpack"
58
+ ],
59
+ "author": "AfterPack <hello@afterpack.dev>",
60
+ "license": "SEE LICENSE IN LICENSE",
61
+ "optionalDependencies": {
62
+ "@afterpack/core-darwin-arm64": "0.1.0",
63
+ "@afterpack/core-darwin-x64": "0.1.0",
64
+ "@afterpack/core-linux-arm64-gnu": "0.1.0",
65
+ "@afterpack/core-linux-x64-gnu": "0.1.0",
66
+ "@afterpack/core-linux-arm64-musl": "0.1.0",
67
+ "@afterpack/core-linux-x64-musl": "0.1.0",
68
+ "@afterpack/core-win32-x64-msvc": "0.1.0"
69
+ }
62
70
  }
@@ -0,0 +1,311 @@
1
+ /** A named protection level. Sets `complexity` and the output-size budget together. */
2
+ export type Preset = "minify" | "light" | "medium" | "hard" | "extreme";
3
+ /** A kind of transformation that a region can allow or deny. */
4
+ export type TransformKind = ConfigurableTransform | "stringEncoding";
5
+ type ConfigurableTransform = "controlFlowFlatten" | "opaquePredicate" | "mixedBooleanArithmetic" | "integerBytecode" | "crossDependency" | "scopeDeepen" | "comparisonHardening" | "selfIntegrity" | "objectConstruction";
6
+ /** A runtime reflection pattern your code relies on. `angular` and `nestjs` cover what those frameworks need. */
7
+ export type ReflectionAllow = "functionToString" | "nameIntrospection" | "argumentsCallee" | "prototypeChain" | "decoratorMetadata" | "constructorIntrospection" | "angular" | "nestjs";
8
+ /** Names kept as written, but only inside files that match `glob`. */
9
+ export interface GlobReserved {
10
+ /** Files the names are kept in, e.g. `legacy/**`. */
11
+ glob: string;
12
+ /** Identifier names never renamed in those files. */
13
+ names: string[];
14
+ }
15
+ /** A protection override for one byte range of the original source. Applied on AfterPack Pro builds. */
16
+ export interface RegionConfig {
17
+ /** Start byte offset in the original source, inclusive. */
18
+ start: number;
19
+ /** End byte offset in the original source, exclusive. */
20
+ end: number;
21
+ /** Overrides `complexity` inside the range. `0` applies no transformation there. */
22
+ complexity?: number;
23
+ /** Overrides `inflation` inside the range. */
24
+ inflation?: {
25
+ /** The largest allowed output for the range, as a multiple of its input size. */
26
+ max?: number;
27
+ };
28
+ /** Overrides `strings` inside the range. */
29
+ strings?: {
30
+ /** Encode string literals inside the range. `false` leaves them readable. */
31
+ encode?: boolean;
32
+ };
33
+ /** Overrides `transforms` inside the range. */
34
+ transforms?: {
35
+ /** Only these transformations may apply inside the range. */
36
+ only?: TransformKind[];
37
+ /** These transformations never apply inside the range. */
38
+ deny?: TransformKind[];
39
+ };
40
+ /** A name for the range, shown in the Protection Map. */
41
+ label?: string;
42
+ }
43
+ /**
44
+ * Build configuration. Unknown keys are refused, so a typo fails the build instead of being
45
+ * ignored. Every option: https://www.afterpack.dev/docs/config
46
+ */
47
+ export interface AfterpackConfig {
48
+ /** The random seed. Unset, every build produces different output; set it to reproduce a build. */
49
+ seed?: number | string;
50
+ /** Your AfterPack Pro key. With a key, the build runs in AfterPack's cloud with much stronger protection. */
51
+ key?: string;
52
+ /** A named protection level. Defaults to `light`. */
53
+ preset?: Preset;
54
+ /** How much protection to apply. `0` applies none; higher values apply more and grow the output. */
55
+ complexity?: number;
56
+ /** Runtime reflection your code relies on. A detected pattern that is not listed fails the build. */
57
+ reflection?: {
58
+ allow?: ReflectionAllow[];
59
+ };
60
+ /** Files to leave untouched, as globs. */
61
+ paths?: {
62
+ exclude?: string[];
63
+ };
64
+ /** Identifier renaming. */
65
+ identifiers?: {
66
+ /** Rename identifiers. `false` keeps every name. */
67
+ rename?: boolean;
68
+ /** Names that are never renamed. */
69
+ reserved?: (string | GlobReserved)[];
70
+ /** Also rename the top-level names of a classic script. */
71
+ globals?: {
72
+ rename?: boolean;
73
+ };
74
+ /** Rename class methods. `false` keeps them for code that reads `fn.name`. */
75
+ methods?: {
76
+ rename?: boolean;
77
+ };
78
+ };
79
+ /** Output size. `max` is the largest allowed output as a multiple of the input size. */
80
+ inflation?: {
81
+ max?: number | "unlimited";
82
+ };
83
+ /** String literals. */
84
+ strings?: {
85
+ /** Encode string literals so that none stays readable. */
86
+ encode?: boolean;
87
+ /** The shortest string that is encoded. */
88
+ minLength?: number;
89
+ /** Fail the build when more than `max` readable string literals remain. */
90
+ leaks?: {
91
+ max?: number;
92
+ };
93
+ /** String values kept exactly as written, for placeholders a later build step replaces. */
94
+ preserveLiterals?: string[];
95
+ };
96
+ /** Source map output. Never deploy a map: it reverses the obfuscation. */
97
+ sourceMap?: {
98
+ enabled?: boolean;
99
+ sourcesContent?: boolean;
100
+ };
101
+ /** The Protection Map, a report of what was applied where. It contains your source; never publish it. */
102
+ protectionMap?: {
103
+ enabled?: boolean;
104
+ detailed?: boolean;
105
+ };
106
+ /** Protection overrides for byte ranges of the source. */
107
+ regions?: RegionConfig[];
108
+ /** Switch a transformation off with `{ enabled: false }`. */
109
+ transforms?: Partial<Record<ConfigurableTransform, {
110
+ enabled?: boolean;
111
+ }>>;
112
+ }
113
+ /** One file to obfuscate. */
114
+ export interface FileInput {
115
+ /** The file's path, used in results and diagnostics. */
116
+ path?: string;
117
+ /** The JavaScript source. */
118
+ source: string | Uint8Array;
119
+ /** The file's existing source map, so the output map points back to your original source. */
120
+ sourceMap?: string;
121
+ }
122
+ /** `info` never blocks a build; `error` and `critical` do. */
123
+ export type Severity = "info" | "error" | "critical";
124
+ /** A byte range in the original source. */
125
+ export interface Span {
126
+ /** Start byte offset, inclusive. */
127
+ startByte: number;
128
+ /** End byte offset, exclusive. */
129
+ endByte: number;
130
+ }
131
+ /** Something AfterPack reports about a build. Codes: https://www.afterpack.dev/docs/diagnostics */
132
+ export interface Diagnostic {
133
+ /** How serious it is. */
134
+ severity: Severity;
135
+ /** A stable identifier, e.g. `DIAG_PARSE_ERROR`. */
136
+ code: string;
137
+ /** A readable explanation. */
138
+ message: string;
139
+ /** The file it refers to, or `null`. */
140
+ file: string | null;
141
+ /** The source range it refers to, or `null`. */
142
+ span: Span | null;
143
+ }
144
+ /** One obfuscated file. */
145
+ export interface Result {
146
+ /** The input's `path`, or `null` when none was given. */
147
+ path: string | null;
148
+ /** The output as UTF-8 bytes, ready to write. */
149
+ bytes: Uint8Array;
150
+ /** The output as a string. */
151
+ readonly code: string;
152
+ /** The output source map, or `null`. */
153
+ sourceMap: string | null;
154
+ /** Diagnostics for this file. */
155
+ diagnostics: Diagnostic[];
156
+ /** What AfterPack applied to this build, or `null` unless `protectionMap.enabled` is set. It contains your source; never publish it. */
157
+ protectionMap: ProtectionMap | null;
158
+ }
159
+ /** What AfterPack applied to a build, file by file. It contains your original source, so keep it private. */
160
+ export interface ProtectionMap {
161
+ /** The version of this report's format. */
162
+ schemaVersion: number;
163
+ /** The unit every span in the report is measured in. */
164
+ spanUnits?: "utf16";
165
+ /** When the report was produced, or `null` when the build did not record a time. */
166
+ generatedAt: string | null;
167
+ /** The engine settings the build ran with. */
168
+ engine: {
169
+ /** The engine version that produced the build. */
170
+ version: string;
171
+ /** Which engine path ran the build. */
172
+ backend: string;
173
+ /** The seed the build used. */
174
+ seed: number;
175
+ /** The named protection level, or `null` when none was set. */
176
+ preset: Preset | null;
177
+ /** How much protection was applied. */
178
+ complexity: number;
179
+ [key: string]: unknown;
180
+ };
181
+ /** One entry per file in the build. */
182
+ files: ProtectionMapFile[];
183
+ }
184
+ /** The protection report for one file in a build. */
185
+ export interface ProtectionMapFile {
186
+ /** The file and its original source. */
187
+ file: {
188
+ /** The file's path, or `null` when none was given. */
189
+ path: string | null;
190
+ /** The file's original source. */
191
+ originalSource: string;
192
+ /** The input size in bytes. */
193
+ inputSize: number;
194
+ /** The output size in bytes. */
195
+ outputSize: number;
196
+ [key: string]: unknown;
197
+ };
198
+ /** What was applied across ranges of the file. */
199
+ regions: Record<string, unknown>[];
200
+ /** Notable spots the report calls out. */
201
+ spotlights: Record<string, unknown>[];
202
+ /** Totals for the whole file. */
203
+ aggregate: Record<string, unknown>;
204
+ }
205
+ /**
206
+ * `code` on an error from a cloud build that the AfterPack service refused.
207
+ * `AFTERPACK_CLOUD_UPGRADE_REQUIRED`: this version is no longer accepted; `details.minVersion` names
208
+ * the one to install. `AFTERPACK_CLOUD_SUNSET`: the API this version speaks is retired.
209
+ * `AFTERPACK_CLOUD_API`: any other refusal.
210
+ */
211
+ export type CloudErrorCode = "AFTERPACK_CLOUD_UPGRADE_REQUIRED" | "AFTERPACK_CLOUD_SUNSET" | "AFTERPACK_CLOUD_API";
212
+ /**
213
+ * A message from the AfterPack service for the person running the build. Treat every field as
214
+ * untrusted display text.
215
+ */
216
+ export interface Notice {
217
+ /** How to present it, e.g. `info` or `warning`. */
218
+ severity: string;
219
+ /** A stable identifier for the notice. */
220
+ code: string;
221
+ /** The text to show. */
222
+ message: string;
223
+ /** A link with more detail. */
224
+ url?: string;
225
+ }
226
+ /** Thrown when a build cannot ship: AfterPack refused it, or a file would ship unprotected. */
227
+ export declare class ObfuscationError extends Error {
228
+ /** Diagnostics that explain the failure. */
229
+ readonly diagnostics: Diagnostic[];
230
+ /** Set when the AfterPack service refused a cloud build. */
231
+ readonly code?: CloudErrorCode;
232
+ /** Structured detail from the service, such as `minVersion`. */
233
+ readonly details?: Record<string, unknown> | null;
234
+ /** Messages from the service attached to the refusal. */
235
+ readonly notices?: Notice[] | null;
236
+ constructor(message: string, diagnostics: Diagnostic[], cloud?: {
237
+ code: CloudErrorCode;
238
+ details: Record<string, unknown> | null;
239
+ notices: Notice[] | null;
240
+ });
241
+ }
242
+ /** Where a build came from. Shown on cloud builds in your dashboard; never changes the output. */
243
+ export interface BuildContext {
244
+ /** The commit the build ran on, 7 to 40 hex characters. */
245
+ commitSha?: string;
246
+ /** The branch or tag the build ran on. */
247
+ ref?: string;
248
+ /** The version of the tool calling AfterPack. */
249
+ clientVersion?: string;
250
+ /** The name of the tool calling AfterPack, e.g. `@afterpack/vite`. */
251
+ client?: string;
252
+ }
253
+ /** One file for `processBatch`. */
254
+ export interface BatchFileInput {
255
+ /** The file's path, returned on its result. */
256
+ path: string;
257
+ /** The JavaScript source. */
258
+ source: string;
259
+ /** The file's existing source map, as JSON. */
260
+ sourceMap?: string;
261
+ /** Protection overrides for this file, in byte offsets of `source`. */
262
+ regions?: RegionConfig[];
263
+ }
264
+ /** One file's outcome from `processBatch`. */
265
+ export interface BatchFileResult {
266
+ /** The input's `path`. */
267
+ path: string;
268
+ /** The obfuscated output. Empty when `status` is `failure`. */
269
+ code: string;
270
+ /** The output source map, as JSON, when one was produced. */
271
+ sourceMap?: string;
272
+ /** This file's Protection Map data, when `protectionMap.enabled` is set. */
273
+ protectionMap?: ProtectionMap;
274
+ /** Whether the file was obfuscated. */
275
+ status: "success" | "failure";
276
+ /** Why the file failed. */
277
+ error?: string;
278
+ /** `true` when AfterPack could not protect the file and returned its original source. Do not ship it. */
279
+ unobfuscated: boolean;
280
+ /** Diagnostics for this file. Absent when they are unknown. */
281
+ diagnostics?: Diagnostic[];
282
+ }
283
+ /** The outcome of `processBatch`. */
284
+ export interface BatchResult {
285
+ /** One result per input file. */
286
+ files: BatchFileResult[];
287
+ /** The number of files in the build. */
288
+ totalFiles: number;
289
+ /** The number of files obfuscated. */
290
+ successCount: number;
291
+ /** The number of files that failed. */
292
+ failureCount: number;
293
+ /** `cloud` when the build ran in AfterPack's cloud, `local` otherwise. */
294
+ source: "local" | "cloud";
295
+ /** Messages from the AfterPack service. */
296
+ notices?: Notice[];
297
+ /** The engine version that ran a cloud build. */
298
+ engineVersion?: string;
299
+ }
300
+ /** The native `processBatch` binding, before this module wraps its rejections. */
301
+ export type NativeProcessBatch = (files: BatchFileInput[], config: AfterpackConfig, buildContext?: BuildContext | null) => Promise<BatchResult>;
302
+ /**
303
+ * Wrap the native `processBatch` binding so it rejects with an {@link ObfuscationError}. Wired into
304
+ * `index.js` by the build; the returned function is what `@afterpack/core` exports as `processBatch`.
305
+ */
306
+ export declare function makeProcessBatch(native: NativeProcessBatch): NativeProcessBatch;
307
+ /** Obfuscate several files in one build. Results come back in input order. Throws an {@link ObfuscationError} when the build cannot ship. */
308
+ export declare function obfuscateAll(files: FileInput[], config?: AfterpackConfig): Promise<Result[]>;
309
+ /** Obfuscate one file. Throws an {@link ObfuscationError} when the build cannot ship. */
310
+ export declare function obfuscate(input: string | Uint8Array | FileInput, config?: AfterpackConfig): Promise<Result>;
311
+ export {};
package/public-api.js ADDED
@@ -0,0 +1,167 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ObfuscationError = void 0;
4
+ exports.makeProcessBatch = makeProcessBatch;
5
+ exports.obfuscateAll = obfuscateAll;
6
+ exports.obfuscate = obfuscate;
7
+ /** Thrown when a build cannot ship: AfterPack refused it, or a file would ship unprotected. */
8
+ class ObfuscationError extends Error {
9
+ /** Diagnostics that explain the failure. */
10
+ diagnostics;
11
+ /** Set when the AfterPack service refused a cloud build. */
12
+ code;
13
+ /** Structured detail from the service, such as `minVersion`. */
14
+ details;
15
+ /** Messages from the service attached to the refusal. */
16
+ notices;
17
+ constructor(message, diagnostics, cloud) {
18
+ super(message);
19
+ this.name = "ObfuscationError";
20
+ this.diagnostics = diagnostics;
21
+ if (cloud !== undefined) {
22
+ this.code = cloud.code;
23
+ this.details = cloud.details;
24
+ this.notices = cloud.notices;
25
+ }
26
+ }
27
+ }
28
+ exports.ObfuscationError = ObfuscationError;
29
+ const CLOUD_ERROR_CODES = [
30
+ "AFTERPACK_CLOUD_UPGRADE_REQUIRED",
31
+ "AFTERPACK_CLOUD_SUNSET",
32
+ "AFTERPACK_CLOUD_API",
33
+ ];
34
+ function cloudError(cause) {
35
+ if (!(cause instanceof Error))
36
+ return null;
37
+ const code = cause.code;
38
+ if (typeof code !== "string" || !CLOUD_ERROR_CODES.includes(code))
39
+ return null;
40
+ let payload = null;
41
+ try {
42
+ payload = JSON.parse(cause.message);
43
+ }
44
+ catch { }
45
+ const apiCode = typeof payload?.code === "string" ? payload.code : code;
46
+ const message = typeof payload?.message === "string" ? payload.message : cause.message;
47
+ const details = payload?.details !== null && typeof payload?.details === "object"
48
+ ? payload.details
49
+ : null;
50
+ const notices = Array.isArray(payload?.notices) ? payload.notices : null;
51
+ return new ObfuscationError(message, [{ severity: "error", code: apiCode, message, span: null, file: null }], { code: code, details, notices });
52
+ }
53
+ function toObfuscationError(cause) {
54
+ if (cause instanceof ObfuscationError)
55
+ return cause;
56
+ const cloud = cloudError(cause);
57
+ if (cloud !== null)
58
+ return cloud;
59
+ const message = cause instanceof Error ? cause.message : String(cause);
60
+ return new ObfuscationError(message, []);
61
+ }
62
+ function binding() {
63
+ return require("./index.js");
64
+ }
65
+ const decoder = new TextDecoder();
66
+ const encoder = new TextEncoder();
67
+ function sourceToString(source) {
68
+ return typeof source === "string" ? source : decoder.decode(source);
69
+ }
70
+ function isFileInput(input) {
71
+ return typeof input === "object" && input !== null && "source" in input;
72
+ }
73
+ class ObfuscatedFile {
74
+ path;
75
+ code;
76
+ sourceMap;
77
+ diagnostics;
78
+ protectionMap;
79
+ #encoded = null;
80
+ constructor(path, code, sourceMap, diags, protectionMap) {
81
+ this.path = path;
82
+ this.code = code;
83
+ this.sourceMap = sourceMap;
84
+ this.diagnostics = diags;
85
+ this.protectionMap = protectionMap;
86
+ }
87
+ get bytes() {
88
+ if (this.#encoded === null)
89
+ this.#encoded = encoder.encode(this.code);
90
+ return this.#encoded;
91
+ }
92
+ }
93
+ function enginePath(file, index, total) {
94
+ if (file.path !== undefined)
95
+ return file.path;
96
+ return total === 1 ? "input.js" : `input-${index}.js`;
97
+ }
98
+ function inInputOrder(results, paths) {
99
+ const pending = new Map();
100
+ results.forEach((file, i) => {
101
+ const bucket = pending.get(file.path);
102
+ if (bucket === undefined)
103
+ pending.set(file.path, [i]);
104
+ else
105
+ bucket.push(i);
106
+ });
107
+ return paths.map((path) => {
108
+ const at = pending.get(path)?.shift();
109
+ if (at === undefined) {
110
+ throw new ObfuscationError(`the engine returned no result for ${path}`, []);
111
+ }
112
+ return results[at];
113
+ });
114
+ }
115
+ async function callEngine(files, config) {
116
+ try {
117
+ return await binding().processBatch(files, config);
118
+ }
119
+ catch (cause) {
120
+ throw toObfuscationError(cause);
121
+ }
122
+ }
123
+ /**
124
+ * Wrap the native `processBatch` binding so it rejects with an {@link ObfuscationError}. Wired into
125
+ * `index.js` by the build; the returned function is what `@afterpack/core` exports as `processBatch`.
126
+ */
127
+ function makeProcessBatch(native) {
128
+ return async function processBatch(files, config, buildContext) {
129
+ try {
130
+ return await native(files, config, buildContext);
131
+ }
132
+ catch (cause) {
133
+ throw toObfuscationError(cause);
134
+ }
135
+ };
136
+ }
137
+ /** Obfuscate several files in one build. Results come back in input order. Throws an {@link ObfuscationError} when the build cannot ship. */
138
+ async function obfuscateAll(files, config) {
139
+ const paths = files.map((file, i) => enginePath(file, i, files.length));
140
+ const sources = files.map((file) => sourceToString(file.source));
141
+ const batch = await callEngine(files.map((file, i) => ({
142
+ path: paths[i],
143
+ source: sources[i],
144
+ sourceMap: file.sourceMap,
145
+ })), config ?? {});
146
+ const ordered = inInputOrder(batch.files, paths);
147
+ const everyDiagnostic = ordered.flatMap((file) => file.diagnostics ?? []);
148
+ const failed = ordered.filter((file) => file.status !== "success");
149
+ if (failed.length > 0) {
150
+ const detail = failed
151
+ .map((file) => `${file.path}: ${(file.error ?? "engine failure").replace(/^AfterPack refused this build: /, "")}`)
152
+ .join("; ");
153
+ throw new ObfuscationError(`AfterPack refused this build — ${detail}`, everyDiagnostic);
154
+ }
155
+ const cleartext = ordered.filter((file, i) => file.unobfuscated || (file.code === "" && sources[i].trim() !== ""));
156
+ if (cleartext.length > 0) {
157
+ const named = cleartext.map((file) => file.path).join(", ");
158
+ throw new ObfuscationError(`AfterPack refused this build — obfuscation was discarded and ${named} would ship as cleartext`, everyDiagnostic);
159
+ }
160
+ return ordered.map((file, i) => new ObfuscatedFile(files[i].path ?? null, file.code, file.sourceMap ?? null, file.diagnostics ?? [], file.protectionMap ?? null));
161
+ }
162
+ /** Obfuscate one file. Throws an {@link ObfuscationError} when the build cannot ship. */
163
+ async function obfuscate(input, config) {
164
+ const file = isFileInput(input) ? input : { source: input };
165
+ const [only] = await obfuscateAll([file], config);
166
+ return only;
167
+ }
package/readme.md CHANGED
@@ -1,52 +1,70 @@
1
- # [@afterpack/core](https://www.afterpack.dev)
1
+ # @afterpack/core
2
2
 
3
- The high-performance JavaScript obfuscation engine that powers [AfterPack](https://www.afterpack.dev).
3
+ The engine behind [AfterPack, the JavaScript obfuscator](https://www.afterpack.dev). It runs in Node, takes JavaScript and returns obfuscated JavaScript, so you can protect your JavaScript source code in any build.
4
4
 
5
- Built with Rust for maximum speed — 20-70x faster than alternatives.
5
+ Most people want the CLI (`npx afterpack`) or a framework plugin instead. Start with the [quickstart](https://www.afterpack.dev/docs/quickstart) or the [CLI reference](https://www.afterpack.dev/docs/cli). Use this package when you are writing your own build step or tool.
6
6
 
7
- ## Features
8
-
9
- - **Free & Production-Ready** — Full obfuscation suite at no cost. Pro unlocks advanced tooling, not basic protection
10
- - **Irreversible Obfuscation** — Non-linear transforms that can't be reversed by deobfuscators or AI
11
- - **Any Complexity Level** — From minimal (`--inflate=1`) to extreme (`--inflate=1000`) protection
12
- - **Deterministic Builds** — Same input = same output. CI cache friendly, HMR compatible
13
- - **Source Maps** — Generate and chain source maps for production debugging
14
- - **Blazing Fast** — Rust-powered, 20-70x faster than alternatives
15
- - **Dual Runtime** — Native Node.js bindings + WASM for edge and browser
16
- - **Cross-Platform** — macOS, Linux, Windows (x64 & arm64)
17
-
18
- ## Installation
7
+ ## Install
19
8
 
20
9
  ```bash
21
10
  npm install @afterpack/core
22
11
  ```
23
12
 
24
- ## Quick Start
13
+ Needs Node 18 or later. The prebuilt binary for your platform installs with it.
14
+
15
+ ## Usage
25
16
 
26
17
  ```javascript
27
- import { process, version } from "@afterpack/core";
18
+ import { obfuscate, obfuscateAll, version } from "@afterpack/core";
19
+
20
+ const result = await obfuscate('console.log("hello")', { preset: "hard" });
21
+ result.code; // the obfuscated source
22
+ result.bytes; // the same output as bytes, ready to write
28
23
 
29
- const obfuscated = process('console.log("hello")');
30
- console.log(version()); // "0.0.1"
24
+ // Several files at once. Results come back in input order.
25
+ const results = await obfuscateAll([
26
+ { path: "dist/app.js", source: appSource },
27
+ { path: "dist/vendor.js", source: vendorSource, sourceMap: vendorMap },
28
+ ]);
29
+
30
+ await version(); // "0.1.0"
31
31
  ```
32
32
 
33
- ## For Most Users
33
+ `obfuscate` accepts a string, a `Uint8Array`, or a file object `{ path, source, sourceMap }`, where `sourceMap` is the file's existing map to chain. Each result has `code`, `bytes`, `sourceMap` and `diagnostics`.
34
34
 
35
- **Use the CLI instead** for a better experience:
35
+ The second argument is the config: [`preset`](https://www.afterpack.dev/docs/config#preset), [`complexity`](https://www.afterpack.dev/docs/config#complexity), [`sourceMap`](https://www.afterpack.dev/docs/config#sourceMap-enabled), [`identifiers`](https://www.afterpack.dev/docs/config#identifiers-rename), [`strings`](https://www.afterpack.dev/docs/config#strings-encode) and more. Unknown keys are rejected, so a typo fails loudly. See the [configuration reference](https://www.afterpack.dev/docs/config).
36
36
 
37
- ```bash
38
- npx afterpack dist/
37
+ ## Errors
38
+
39
+ If a build can't ship safely, the call throws. That covers an invalid config, a blocking diagnostic, or output that would go out unprotected. The error carries the engine's diagnostics:
40
+
41
+ ```javascript
42
+ import { obfuscate, ObfuscationError } from "@afterpack/core";
43
+
44
+ try {
45
+ await obfuscate(source);
46
+ } catch (err) {
47
+ if (err instanceof ObfuscationError) console.error(err.diagnostics);
48
+ throw err;
49
+ }
39
50
  ```
40
51
 
41
- This package (`@afterpack/core`) is the low-level engine.
52
+ ## Pro
53
+
54
+ Without a key, AfterPack runs on your machine and applies basic protection. Set your Pro key in the `AFTERPACK_KEY` environment variable (or pass `key` in the config) and the same call sends the build to AfterPack's cloud, which applies much stronger protection. Read more about [AfterPack Pro](https://www.afterpack.dev/docs/pro) or see [pricing](https://www.afterpack.dev/#pricing).
42
55
 
43
- ## Links
56
+ Why this matters now: [AI agents deobfuscate JavaScript](https://www.afterpack.dev/blog/ai-deobfuscates-javascript) that older tools protect. See how AfterPack [compares to javascript-obfuscator and Jscrambler](https://www.afterpack.dev/docs/comparison).
44
57
 
45
- - [Website](https://www.afterpack.dev)
46
- - [Documentation](https://www.afterpack.dev/docs)
47
- - [CLI Package](https://npmjs.com/package/afterpack)
48
- - [GitHub](https://github.com/afterpack-dev/afterpack)
58
+ ## Platforms
59
+
60
+ - macOS: arm64 (Apple Silicon), x64
61
+ - Linux (glibc): x64, arm64
62
+ - Windows: x64
63
+
64
+ Alpine and other musl-based Linux have no native binary yet: use a glibc-based image. On those hosts, and anywhere a native addon can't load (such as a Cloudflare Worker), [`@afterpack/wasm`](https://www.npmjs.com/package/@afterpack/wasm) runs the same `obfuscate` API.
49
65
 
50
66
  ## License
51
67
 
52
- MIT © [AfterPack](https://www.afterpack.dev)
68
+ Free for any use, including commercial and CI, with no limits, and the output is yours. You can't redistribute the binary on its own, build a competing obfuscation product or service on it, or reverse engineer it. See the [AfterPack Engine License](https://www.afterpack.dev/license).
69
+
70
+ Questions and feedback: [get in touch](https://www.afterpack.dev/contact). Bug reports: [GitHub](https://github.com/afterpack-dev/afterpack/issues).