@afterpack/core 0.0.9 → 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/LICENSE +133 -0
- package/index.d.ts +36 -20
- package/index.js +61 -55
- package/package.json +72 -60
- package/public-api.d.ts +313 -0
- package/public-api.js +171 -0
- package/readme.md +48 -30
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
|
-
|
|
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
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
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
|
-
*
|
|
30
|
+
* Lower-level batch entry used by AfterPack's build plugins. Prefer `obfuscateAll`.
|
|
19
31
|
*
|
|
20
|
-
*
|
|
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
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
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.
|
|
81
|
-
throw new Error(`Native binding package version mismatch, expected 0.
|
|
80
|
+
if (bindingPackageVersion !== '0.2.1' && 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.2.1 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.
|
|
97
|
-
throw new Error(`Native binding package version mismatch, expected 0.
|
|
96
|
+
if (bindingPackageVersion !== '0.2.1' && 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.2.1 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.
|
|
118
|
-
throw new Error(`Native binding package version mismatch, expected 0.
|
|
117
|
+
if (bindingPackageVersion !== '0.2.1' && 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.2.1 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.
|
|
134
|
-
throw new Error(`Native binding package version mismatch, expected 0.
|
|
133
|
+
if (bindingPackageVersion !== '0.2.1' && 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.2.1 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.
|
|
151
|
-
throw new Error(`Native binding package version mismatch, expected 0.
|
|
150
|
+
if (bindingPackageVersion !== '0.2.1' && 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.2.1 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.
|
|
167
|
-
throw new Error(`Native binding package version mismatch, expected 0.
|
|
166
|
+
if (bindingPackageVersion !== '0.2.1' && 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.2.1 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.
|
|
186
|
-
throw new Error(`Native binding package version mismatch, expected 0.
|
|
185
|
+
if (bindingPackageVersion !== '0.2.1' && 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.2.1 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.
|
|
202
|
-
throw new Error(`Native binding package version mismatch, expected 0.
|
|
201
|
+
if (bindingPackageVersion !== '0.2.1' && 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.2.1 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.
|
|
218
|
-
throw new Error(`Native binding package version mismatch, expected 0.
|
|
217
|
+
if (bindingPackageVersion !== '0.2.1' && 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.2.1 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.
|
|
238
|
-
throw new Error(`Native binding package version mismatch, expected 0.
|
|
237
|
+
if (bindingPackageVersion !== '0.2.1' && 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.2.1 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.
|
|
254
|
-
throw new Error(`Native binding package version mismatch, expected 0.
|
|
253
|
+
if (bindingPackageVersion !== '0.2.1' && 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.2.1 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.
|
|
275
|
-
throw new Error(`Native binding package version mismatch, expected 0.
|
|
274
|
+
if (bindingPackageVersion !== '0.2.1' && 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.2.1 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.
|
|
291
|
-
throw new Error(`Native binding package version mismatch, expected 0.
|
|
290
|
+
if (bindingPackageVersion !== '0.2.1' && 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.2.1 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.
|
|
309
|
-
throw new Error(`Native binding package version mismatch, expected 0.
|
|
308
|
+
if (bindingPackageVersion !== '0.2.1' && 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.2.1 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.
|
|
325
|
-
throw new Error(`Native binding package version mismatch, expected 0.
|
|
324
|
+
if (bindingPackageVersion !== '0.2.1' && 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.2.1 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.
|
|
343
|
-
throw new Error(`Native binding package version mismatch, expected 0.
|
|
342
|
+
if (bindingPackageVersion !== '0.2.1' && 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.2.1 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.
|
|
359
|
-
throw new Error(`Native binding package version mismatch, expected 0.
|
|
358
|
+
if (bindingPackageVersion !== '0.2.1' && 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.2.1 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.
|
|
377
|
-
throw new Error(`Native binding package version mismatch, expected 0.
|
|
376
|
+
if (bindingPackageVersion !== '0.2.1' && 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.2.1 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.
|
|
393
|
-
throw new Error(`Native binding package version mismatch, expected 0.
|
|
392
|
+
if (bindingPackageVersion !== '0.2.1' && 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.2.1 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.
|
|
411
|
-
throw new Error(`Native binding package version mismatch, expected 0.
|
|
410
|
+
if (bindingPackageVersion !== '0.2.1' && 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.2.1 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.
|
|
427
|
-
throw new Error(`Native binding package version mismatch, expected 0.
|
|
426
|
+
if (bindingPackageVersion !== '0.2.1' && 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.2.1 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.
|
|
444
|
-
throw new Error(`Native binding package version mismatch, expected 0.
|
|
443
|
+
if (bindingPackageVersion !== '0.2.1' && 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.2.1 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.
|
|
460
|
-
throw new Error(`Native binding package version mismatch, expected 0.
|
|
459
|
+
if (bindingPackageVersion !== '0.2.1' && 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.2.1 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.
|
|
480
|
-
throw new Error(`Native binding package version mismatch, expected 0.
|
|
479
|
+
if (bindingPackageVersion !== '0.2.1' && 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.2.1 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.
|
|
496
|
-
throw new Error(`Native binding package version mismatch, expected 0.
|
|
495
|
+
if (bindingPackageVersion !== '0.2.1' && 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.2.1 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.
|
|
512
|
-
throw new Error(`Native binding package version mismatch, expected 0.
|
|
511
|
+
if (bindingPackageVersion !== '0.2.1' && 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.2.1 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.
|
|
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,74 @@
|
|
|
1
1
|
{
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
2
|
+
"name": "@afterpack/core",
|
|
3
|
+
"version": "0.2.1",
|
|
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.2.1",
|
|
63
|
+
"@afterpack/core-darwin-x64": "0.2.1",
|
|
64
|
+
"@afterpack/core-linux-arm64-gnu": "0.2.1",
|
|
65
|
+
"@afterpack/core-linux-x64-gnu": "0.2.1",
|
|
66
|
+
"@afterpack/core-linux-arm64-musl": "0.2.1",
|
|
67
|
+
"@afterpack/core-linux-x64-musl": "0.2.1",
|
|
68
|
+
"@afterpack/core-win32-x64-msvc": "0.2.1"
|
|
69
|
+
},
|
|
70
|
+
"repository": {
|
|
71
|
+
"type": "git",
|
|
72
|
+
"url": "git+https://github.com/afterpack-dev/afterpack.git"
|
|
73
|
+
}
|
|
62
74
|
}
|
package/public-api.d.ts
ADDED
|
@@ -0,0 +1,313 @@
|
|
|
1
|
+
/** A named protection level. Sets the `complexity` target; output size follows from it. */
|
|
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
|
+
/** Applies a preset inside the range, like the top-level `preset`. A `complexity` on the same range wins. */
|
|
24
|
+
preset?: Preset;
|
|
25
|
+
/** Overrides `inflation` inside the range. */
|
|
26
|
+
inflation?: {
|
|
27
|
+
/** The largest allowed output for the range, as a multiple of its input size. */
|
|
28
|
+
max?: number;
|
|
29
|
+
};
|
|
30
|
+
/** Overrides `strings` inside the range. */
|
|
31
|
+
strings?: {
|
|
32
|
+
/** Encode string literals inside the range. `false` leaves them readable. */
|
|
33
|
+
encode?: boolean;
|
|
34
|
+
};
|
|
35
|
+
/** Overrides `transforms` inside the range. */
|
|
36
|
+
transforms?: {
|
|
37
|
+
/** Only these transformations may apply inside the range. */
|
|
38
|
+
only?: TransformKind[];
|
|
39
|
+
/** These transformations never apply inside the range. */
|
|
40
|
+
deny?: TransformKind[];
|
|
41
|
+
};
|
|
42
|
+
/** A name for the range, shown in the Protection Map. */
|
|
43
|
+
label?: string;
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* Build configuration. Unknown keys are refused, so a typo fails the build instead of being
|
|
47
|
+
* ignored. Every option: https://www.afterpack.dev/docs/config
|
|
48
|
+
*/
|
|
49
|
+
export interface AfterpackConfig {
|
|
50
|
+
/** The random seed. Unset, every build produces different output; set it to reproduce a build. */
|
|
51
|
+
seed?: number | string;
|
|
52
|
+
/** Your AfterPack Pro key. With a key, the build runs in AfterPack's cloud with much stronger protection. */
|
|
53
|
+
key?: string;
|
|
54
|
+
/** A named protection level. Defaults to `light`. */
|
|
55
|
+
preset?: Preset;
|
|
56
|
+
/** How much protection to apply. `0` applies none; higher values apply more and grow the output. */
|
|
57
|
+
complexity?: number;
|
|
58
|
+
/** Runtime reflection your code relies on. A detected pattern that is not listed fails the build. */
|
|
59
|
+
reflection?: {
|
|
60
|
+
allow?: ReflectionAllow[];
|
|
61
|
+
};
|
|
62
|
+
/** Files to leave untouched, as globs. */
|
|
63
|
+
paths?: {
|
|
64
|
+
exclude?: string[];
|
|
65
|
+
};
|
|
66
|
+
/** Identifier renaming. */
|
|
67
|
+
identifiers?: {
|
|
68
|
+
/** Rename identifiers. `false` keeps every name. */
|
|
69
|
+
rename?: boolean;
|
|
70
|
+
/** Names that are never renamed. */
|
|
71
|
+
reserved?: (string | GlobReserved)[];
|
|
72
|
+
/** Also rename the top-level names of a classic script. */
|
|
73
|
+
globals?: {
|
|
74
|
+
rename?: boolean;
|
|
75
|
+
};
|
|
76
|
+
/** Rename class methods. `false` keeps them for code that reads `fn.name`. */
|
|
77
|
+
methods?: {
|
|
78
|
+
rename?: boolean;
|
|
79
|
+
};
|
|
80
|
+
};
|
|
81
|
+
/** Output size. `max` is the largest allowed output as a multiple of the input size. */
|
|
82
|
+
inflation?: {
|
|
83
|
+
max?: number | "unlimited";
|
|
84
|
+
};
|
|
85
|
+
/** String literals. */
|
|
86
|
+
strings?: {
|
|
87
|
+
/** Encode string literals so that none stays readable. */
|
|
88
|
+
encode?: boolean;
|
|
89
|
+
/** The shortest string that is encoded. */
|
|
90
|
+
minLength?: number;
|
|
91
|
+
/** Fail the build when more than `max` readable string literals remain. */
|
|
92
|
+
leaks?: {
|
|
93
|
+
max?: number;
|
|
94
|
+
};
|
|
95
|
+
/** String values kept exactly as written, for placeholders a later build step replaces. */
|
|
96
|
+
preserveLiterals?: string[];
|
|
97
|
+
};
|
|
98
|
+
/** Source map output. Never deploy a map: it reverses the obfuscation. */
|
|
99
|
+
sourceMap?: {
|
|
100
|
+
enabled?: boolean;
|
|
101
|
+
sourcesContent?: boolean;
|
|
102
|
+
};
|
|
103
|
+
/** The Protection Map, a report of what was applied where. It contains your source; never publish it. */
|
|
104
|
+
protectionMap?: {
|
|
105
|
+
enabled?: boolean;
|
|
106
|
+
detailed?: boolean;
|
|
107
|
+
};
|
|
108
|
+
/** Protection overrides for byte ranges of the source. */
|
|
109
|
+
regions?: RegionConfig[];
|
|
110
|
+
/** Switch a transformation off with `{ enabled: false }`. */
|
|
111
|
+
transforms?: Partial<Record<ConfigurableTransform, {
|
|
112
|
+
enabled?: boolean;
|
|
113
|
+
}>>;
|
|
114
|
+
}
|
|
115
|
+
/** One file to obfuscate. */
|
|
116
|
+
export interface FileInput {
|
|
117
|
+
/** The file's path, used in results and diagnostics. */
|
|
118
|
+
path?: string;
|
|
119
|
+
/** The JavaScript source. */
|
|
120
|
+
source: string | Uint8Array;
|
|
121
|
+
/** The file's existing source map, so the output map points back to your original source. */
|
|
122
|
+
sourceMap?: string;
|
|
123
|
+
}
|
|
124
|
+
/** `info` never blocks a build; `error` and `critical` do. */
|
|
125
|
+
export type Severity = "info" | "error" | "critical";
|
|
126
|
+
/** A byte range in the original source. */
|
|
127
|
+
export interface Span {
|
|
128
|
+
/** Start byte offset, inclusive. */
|
|
129
|
+
startByte: number;
|
|
130
|
+
/** End byte offset, exclusive. */
|
|
131
|
+
endByte: number;
|
|
132
|
+
}
|
|
133
|
+
/** Something AfterPack reports about a build. Codes: https://www.afterpack.dev/docs/diagnostics */
|
|
134
|
+
export interface Diagnostic {
|
|
135
|
+
/** How serious it is. */
|
|
136
|
+
severity: Severity;
|
|
137
|
+
/** A stable identifier, e.g. `DIAG_PARSE_ERROR`. */
|
|
138
|
+
code: string;
|
|
139
|
+
/** A readable explanation. */
|
|
140
|
+
message: string;
|
|
141
|
+
/** The file it refers to, or `null`. */
|
|
142
|
+
file: string | null;
|
|
143
|
+
/** The source range it refers to, or `null`. */
|
|
144
|
+
span: Span | null;
|
|
145
|
+
}
|
|
146
|
+
/** One obfuscated file. */
|
|
147
|
+
export interface Result {
|
|
148
|
+
/** The input's `path`, or `null` when none was given. */
|
|
149
|
+
path: string | null;
|
|
150
|
+
/** The output as UTF-8 bytes, ready to write. */
|
|
151
|
+
bytes: Uint8Array;
|
|
152
|
+
/** The output as a string. */
|
|
153
|
+
readonly code: string;
|
|
154
|
+
/** The output source map, or `null`. */
|
|
155
|
+
sourceMap: string | null;
|
|
156
|
+
/** Diagnostics for this file. */
|
|
157
|
+
diagnostics: Diagnostic[];
|
|
158
|
+
/** What AfterPack applied to this build, or `null` unless `protectionMap.enabled` is set. It contains your source; never publish it. */
|
|
159
|
+
protectionMap: ProtectionMap | null;
|
|
160
|
+
}
|
|
161
|
+
/** What AfterPack applied to a build, file by file. It contains your original source, so keep it private. */
|
|
162
|
+
export interface ProtectionMap {
|
|
163
|
+
/** The version of this report's format. */
|
|
164
|
+
schemaVersion: number;
|
|
165
|
+
/** The unit every span in the report is measured in. */
|
|
166
|
+
spanUnits?: "utf16";
|
|
167
|
+
/** When the report was produced, or `null` when the build did not record a time. */
|
|
168
|
+
generatedAt: string | null;
|
|
169
|
+
/** The engine settings the build ran with. */
|
|
170
|
+
engine: {
|
|
171
|
+
/** The engine version that produced the build. */
|
|
172
|
+
version: string;
|
|
173
|
+
/** Which engine path ran the build. */
|
|
174
|
+
backend: string;
|
|
175
|
+
/** The seed the build used. */
|
|
176
|
+
seed: number;
|
|
177
|
+
/** The named protection level, or `null` when none was set. */
|
|
178
|
+
preset: Preset | null;
|
|
179
|
+
/** How much protection was applied. */
|
|
180
|
+
complexity: number;
|
|
181
|
+
[key: string]: unknown;
|
|
182
|
+
};
|
|
183
|
+
/** One entry per file in the build. */
|
|
184
|
+
files: ProtectionMapFile[];
|
|
185
|
+
}
|
|
186
|
+
/** The protection report for one file in a build. */
|
|
187
|
+
export interface ProtectionMapFile {
|
|
188
|
+
/** The file and its original source. */
|
|
189
|
+
file: {
|
|
190
|
+
/** The file's path, or `null` when none was given. */
|
|
191
|
+
path: string | null;
|
|
192
|
+
/** The file's original source. */
|
|
193
|
+
originalSource: string;
|
|
194
|
+
/** The input size in bytes. */
|
|
195
|
+
inputSize: number;
|
|
196
|
+
/** The output size in bytes. */
|
|
197
|
+
outputSize: number;
|
|
198
|
+
[key: string]: unknown;
|
|
199
|
+
};
|
|
200
|
+
/** What was applied across ranges of the file. */
|
|
201
|
+
regions: Record<string, unknown>[];
|
|
202
|
+
/** Notable spots the report calls out. */
|
|
203
|
+
spotlights: Record<string, unknown>[];
|
|
204
|
+
/** Totals for the whole file. */
|
|
205
|
+
aggregate: Record<string, unknown>;
|
|
206
|
+
}
|
|
207
|
+
/**
|
|
208
|
+
* `code` on an error from a cloud build that the AfterPack service refused.
|
|
209
|
+
* `AFTERPACK_CLOUD_UPGRADE_REQUIRED`: this version is no longer accepted; `details.minVersion` names
|
|
210
|
+
* the one to install. `AFTERPACK_CLOUD_SUNSET`: the API this version speaks is retired.
|
|
211
|
+
* `AFTERPACK_CLOUD_API`: any other refusal.
|
|
212
|
+
*/
|
|
213
|
+
export type CloudErrorCode = "AFTERPACK_CLOUD_UPGRADE_REQUIRED" | "AFTERPACK_CLOUD_SUNSET" | "AFTERPACK_CLOUD_API";
|
|
214
|
+
/**
|
|
215
|
+
* A message from the AfterPack service for the person running the build. Treat every field as
|
|
216
|
+
* untrusted display text.
|
|
217
|
+
*/
|
|
218
|
+
export interface Notice {
|
|
219
|
+
/** How to present it, e.g. `info` or `warning`. */
|
|
220
|
+
severity: string;
|
|
221
|
+
/** A stable identifier for the notice. */
|
|
222
|
+
code: string;
|
|
223
|
+
/** The text to show. */
|
|
224
|
+
message: string;
|
|
225
|
+
/** A link with more detail. */
|
|
226
|
+
url?: string;
|
|
227
|
+
}
|
|
228
|
+
/** Thrown when a build cannot ship: AfterPack refused it, or a file would ship unprotected. */
|
|
229
|
+
export declare class ObfuscationError extends Error {
|
|
230
|
+
/** Diagnostics that explain the failure. */
|
|
231
|
+
readonly diagnostics: Diagnostic[];
|
|
232
|
+
/** Set when the AfterPack service refused a cloud build. */
|
|
233
|
+
readonly code?: CloudErrorCode;
|
|
234
|
+
/** Structured detail from the service, such as `minVersion`. */
|
|
235
|
+
readonly details?: Record<string, unknown> | null;
|
|
236
|
+
/** Messages from the service attached to the refusal. */
|
|
237
|
+
readonly notices?: Notice[] | null;
|
|
238
|
+
constructor(message: string, diagnostics: Diagnostic[], cloud?: {
|
|
239
|
+
code: CloudErrorCode;
|
|
240
|
+
details: Record<string, unknown> | null;
|
|
241
|
+
notices: Notice[] | null;
|
|
242
|
+
});
|
|
243
|
+
}
|
|
244
|
+
/** Where a build came from. Shown on cloud builds in your dashboard; never changes the output. */
|
|
245
|
+
export interface BuildContext {
|
|
246
|
+
/** The commit the build ran on, 7 to 40 hex characters. */
|
|
247
|
+
commitSha?: string;
|
|
248
|
+
/** The branch or tag the build ran on. */
|
|
249
|
+
ref?: string;
|
|
250
|
+
/** The version of the tool calling AfterPack. */
|
|
251
|
+
clientVersion?: string;
|
|
252
|
+
/** The name of the tool calling AfterPack, e.g. `@afterpack/vite`. */
|
|
253
|
+
client?: string;
|
|
254
|
+
}
|
|
255
|
+
/** One file for `processBatch`. */
|
|
256
|
+
export interface BatchFileInput {
|
|
257
|
+
/** The file's path, returned on its result. */
|
|
258
|
+
path: string;
|
|
259
|
+
/** The JavaScript source. */
|
|
260
|
+
source: string;
|
|
261
|
+
/** The file's existing source map, as JSON. */
|
|
262
|
+
sourceMap?: string;
|
|
263
|
+
/** Protection overrides for this file, in byte offsets of `source`. */
|
|
264
|
+
regions?: RegionConfig[];
|
|
265
|
+
}
|
|
266
|
+
/** One file's outcome from `processBatch`. */
|
|
267
|
+
export interface BatchFileResult {
|
|
268
|
+
/** The input's `path`. */
|
|
269
|
+
path: string;
|
|
270
|
+
/** The obfuscated output. Empty when `status` is `failure`. */
|
|
271
|
+
code: string;
|
|
272
|
+
/** The output source map, as JSON, when one was produced. */
|
|
273
|
+
sourceMap?: string;
|
|
274
|
+
/** This file's Protection Map data, when `protectionMap.enabled` is set. */
|
|
275
|
+
protectionMap?: ProtectionMap;
|
|
276
|
+
/** Whether the file was obfuscated. */
|
|
277
|
+
status: "success" | "failure";
|
|
278
|
+
/** Why the file failed. */
|
|
279
|
+
error?: string;
|
|
280
|
+
/** `true` when AfterPack could not protect the file and returned its original source. Do not ship it. */
|
|
281
|
+
unobfuscated: boolean;
|
|
282
|
+
/** Diagnostics for this file. Absent when they are unknown. */
|
|
283
|
+
diagnostics?: Diagnostic[];
|
|
284
|
+
}
|
|
285
|
+
/** The outcome of `processBatch`. */
|
|
286
|
+
export interface BatchResult {
|
|
287
|
+
/** One result per input file. */
|
|
288
|
+
files: BatchFileResult[];
|
|
289
|
+
/** The number of files in the build. */
|
|
290
|
+
totalFiles: number;
|
|
291
|
+
/** The number of files obfuscated. */
|
|
292
|
+
successCount: number;
|
|
293
|
+
/** The number of files that failed. */
|
|
294
|
+
failureCount: number;
|
|
295
|
+
/** `cloud` when the build ran in AfterPack's cloud, `local` otherwise. */
|
|
296
|
+
source: "local" | "cloud";
|
|
297
|
+
/** Messages from the AfterPack service. */
|
|
298
|
+
notices?: Notice[];
|
|
299
|
+
/** The engine version that ran a cloud build. */
|
|
300
|
+
engineVersion?: string;
|
|
301
|
+
}
|
|
302
|
+
/** The native `processBatch` binding, before this module wraps its rejections. */
|
|
303
|
+
export type NativeProcessBatch = (files: BatchFileInput[], config: AfterpackConfig, buildContext?: BuildContext | null) => Promise<BatchResult>;
|
|
304
|
+
/**
|
|
305
|
+
* Wrap the native `processBatch` binding so it rejects with an {@link ObfuscationError}. Wired into
|
|
306
|
+
* `index.js` by the build; the returned function is what `@afterpack/core` exports as `processBatch`.
|
|
307
|
+
*/
|
|
308
|
+
export declare function makeProcessBatch(native: NativeProcessBatch): NativeProcessBatch;
|
|
309
|
+
/** Obfuscate several files in one build. Results come back in input order. Throws an {@link ObfuscationError} when the build cannot ship. */
|
|
310
|
+
export declare function obfuscateAll(files: FileInput[], config?: AfterpackConfig): Promise<Result[]>;
|
|
311
|
+
/** Obfuscate one file. Throws an {@link ObfuscationError} when the build cannot ship. */
|
|
312
|
+
export declare function obfuscate(input: string | Uint8Array | FileInput, config?: AfterpackConfig): Promise<Result>;
|
|
313
|
+
export {};
|
package/public-api.js
ADDED
|
@@ -0,0 +1,171 @@
|
|
|
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
|
+
function randomSeed() {
|
|
66
|
+
const bytes = require("node:crypto").randomBytes(8);
|
|
67
|
+
return (bytes.readUInt32BE(0) & 0x1f_ffff) * 0x1_0000_0000 + bytes.readUInt32BE(4);
|
|
68
|
+
}
|
|
69
|
+
const decoder = new TextDecoder();
|
|
70
|
+
const encoder = new TextEncoder();
|
|
71
|
+
function sourceToString(source) {
|
|
72
|
+
return typeof source === "string" ? source : decoder.decode(source);
|
|
73
|
+
}
|
|
74
|
+
function isFileInput(input) {
|
|
75
|
+
return typeof input === "object" && input !== null && "source" in input;
|
|
76
|
+
}
|
|
77
|
+
class ObfuscatedFile {
|
|
78
|
+
path;
|
|
79
|
+
code;
|
|
80
|
+
sourceMap;
|
|
81
|
+
diagnostics;
|
|
82
|
+
protectionMap;
|
|
83
|
+
#encoded = null;
|
|
84
|
+
constructor(path, code, sourceMap, diags, protectionMap) {
|
|
85
|
+
this.path = path;
|
|
86
|
+
this.code = code;
|
|
87
|
+
this.sourceMap = sourceMap;
|
|
88
|
+
this.diagnostics = diags;
|
|
89
|
+
this.protectionMap = protectionMap;
|
|
90
|
+
}
|
|
91
|
+
get bytes() {
|
|
92
|
+
if (this.#encoded === null)
|
|
93
|
+
this.#encoded = encoder.encode(this.code);
|
|
94
|
+
return this.#encoded;
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
function enginePath(file, index, total) {
|
|
98
|
+
if (file.path !== undefined)
|
|
99
|
+
return file.path;
|
|
100
|
+
return total === 1 ? "input.js" : `input-${index}.js`;
|
|
101
|
+
}
|
|
102
|
+
function inInputOrder(results, paths) {
|
|
103
|
+
const pending = new Map();
|
|
104
|
+
results.forEach((file, i) => {
|
|
105
|
+
const bucket = pending.get(file.path);
|
|
106
|
+
if (bucket === undefined)
|
|
107
|
+
pending.set(file.path, [i]);
|
|
108
|
+
else
|
|
109
|
+
bucket.push(i);
|
|
110
|
+
});
|
|
111
|
+
return paths.map((path) => {
|
|
112
|
+
const at = pending.get(path)?.shift();
|
|
113
|
+
if (at === undefined) {
|
|
114
|
+
throw new ObfuscationError(`the engine returned no result for ${path}`, []);
|
|
115
|
+
}
|
|
116
|
+
return results[at];
|
|
117
|
+
});
|
|
118
|
+
}
|
|
119
|
+
async function callEngine(files, config) {
|
|
120
|
+
try {
|
|
121
|
+
return await binding().processBatch(files, config);
|
|
122
|
+
}
|
|
123
|
+
catch (cause) {
|
|
124
|
+
throw toObfuscationError(cause);
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
/**
|
|
128
|
+
* Wrap the native `processBatch` binding so it rejects with an {@link ObfuscationError}. Wired into
|
|
129
|
+
* `index.js` by the build; the returned function is what `@afterpack/core` exports as `processBatch`.
|
|
130
|
+
*/
|
|
131
|
+
function makeProcessBatch(native) {
|
|
132
|
+
return async function processBatch(files, config, buildContext) {
|
|
133
|
+
try {
|
|
134
|
+
return await native(files, config, buildContext);
|
|
135
|
+
}
|
|
136
|
+
catch (cause) {
|
|
137
|
+
throw toObfuscationError(cause);
|
|
138
|
+
}
|
|
139
|
+
};
|
|
140
|
+
}
|
|
141
|
+
/** Obfuscate several files in one build. Results come back in input order. Throws an {@link ObfuscationError} when the build cannot ship. */
|
|
142
|
+
async function obfuscateAll(files, config) {
|
|
143
|
+
const paths = files.map((file, i) => enginePath(file, i, files.length));
|
|
144
|
+
const sources = files.map((file) => sourceToString(file.source));
|
|
145
|
+
const batch = await callEngine(files.map((file, i) => ({
|
|
146
|
+
path: paths[i],
|
|
147
|
+
source: sources[i],
|
|
148
|
+
sourceMap: file.sourceMap,
|
|
149
|
+
})), config?.seed === undefined ? { ...config, seed: randomSeed() } : config);
|
|
150
|
+
const ordered = inInputOrder(batch.files, paths);
|
|
151
|
+
const everyDiagnostic = ordered.flatMap((file) => file.diagnostics ?? []);
|
|
152
|
+
const failed = ordered.filter((file) => file.status !== "success");
|
|
153
|
+
if (failed.length > 0) {
|
|
154
|
+
const detail = failed
|
|
155
|
+
.map((file) => `${file.path}: ${(file.error ?? "engine failure").replace(/^AfterPack refused this build: /, "")}`)
|
|
156
|
+
.join("; ");
|
|
157
|
+
throw new ObfuscationError(`AfterPack refused this build — ${detail}`, everyDiagnostic);
|
|
158
|
+
}
|
|
159
|
+
const cleartext = ordered.filter((file, i) => file.unobfuscated || (file.code === "" && sources[i].trim() !== ""));
|
|
160
|
+
if (cleartext.length > 0) {
|
|
161
|
+
const named = cleartext.map((file) => file.path).join(", ");
|
|
162
|
+
throw new ObfuscationError(`AfterPack refused this build — obfuscation was discarded and ${named} would ship as cleartext`, everyDiagnostic);
|
|
163
|
+
}
|
|
164
|
+
return ordered.map((file, i) => new ObfuscatedFile(files[i].path ?? null, file.code, file.sourceMap ?? null, file.diagnostics ?? [], file.protectionMap ?? null));
|
|
165
|
+
}
|
|
166
|
+
/** Obfuscate one file. Throws an {@link ObfuscationError} when the build cannot ship. */
|
|
167
|
+
async function obfuscate(input, config) {
|
|
168
|
+
const file = isFileInput(input) ? input : { source: input };
|
|
169
|
+
const [only] = await obfuscateAll([file], config);
|
|
170
|
+
return only;
|
|
171
|
+
}
|
package/readme.md
CHANGED
|
@@ -1,52 +1,70 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @afterpack/core
|
|
2
2
|
|
|
3
|
-
The
|
|
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
|
-
|
|
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
|
-
##
|
|
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
|
-
|
|
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 {
|
|
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
|
-
|
|
30
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
38
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
46
|
-
|
|
47
|
-
-
|
|
48
|
-
-
|
|
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
|
-
|
|
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).
|