@afterpack/wasm 0.2.4 → 0.2.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/api.js +29 -5
- package/dist/contract.d.ts +6 -2
- package/engine/afterpack_engine_bg.wasm +0 -0
- package/package.json +1 -1
- package/readme.md +3 -3
package/dist/api.js
CHANGED
|
@@ -21,6 +21,22 @@ function enginePath(file, index, total) {
|
|
|
21
21
|
return file.path;
|
|
22
22
|
return total === 1 ? "input.js" : `input-${index}.js`;
|
|
23
23
|
}
|
|
24
|
+
const SOURCE_TYPES = ["auto", "module", "script"];
|
|
25
|
+
function fileSourceTypes(files) {
|
|
26
|
+
return files.map((file, i) => {
|
|
27
|
+
const kind = file.sourceType;
|
|
28
|
+
if (kind === undefined || kind === null)
|
|
29
|
+
return undefined;
|
|
30
|
+
if (typeof kind === "string" && SOURCE_TYPES.includes(kind))
|
|
31
|
+
return kind;
|
|
32
|
+
const key = `files[${i}].sourceType`;
|
|
33
|
+
throw new ObfuscationError(`AfterPack refused this build: invalid engine configuration at \`${key}\` -- expected ` +
|
|
34
|
+
'"auto", "module" or "script". No output was emitted. AfterPack never falls back to ' +
|
|
35
|
+
"default settings on a bad config: a build that silently ignored your configuration " +
|
|
36
|
+
`would ship far weaker protection than you asked for. Fix or remove \`${key}\` where ` +
|
|
37
|
+
"you configure AfterPack (your plugin options or CLI flags) and rebuild.", []);
|
|
38
|
+
});
|
|
39
|
+
}
|
|
24
40
|
function blockingMessage(diagnostics) {
|
|
25
41
|
const messages = diagnostics
|
|
26
42
|
.filter((d) => d.severity === "error" || d.severity === "critical")
|
|
@@ -58,11 +74,14 @@ function engineConfigWithoutKey(config) {
|
|
|
58
74
|
const { key: _key, ...rest } = config;
|
|
59
75
|
return rest;
|
|
60
76
|
}
|
|
61
|
-
function buildCloudForm(files, paths, sources, engineConfig) {
|
|
77
|
+
function buildCloudForm(files, paths, sources, kinds, engineConfig) {
|
|
62
78
|
const manifestFiles = files.map((file, i) => {
|
|
63
79
|
const entry = { filePath: paths[i], partName: `file-${i}` };
|
|
64
80
|
if (file.sourceMap !== undefined)
|
|
65
81
|
entry.sourceMapPartName = `map-${i}`;
|
|
82
|
+
const kind = kinds[i];
|
|
83
|
+
if (kind !== undefined)
|
|
84
|
+
entry.config = { sourceType: kind };
|
|
66
85
|
return entry;
|
|
67
86
|
});
|
|
68
87
|
const form = new FormData();
|
|
@@ -310,8 +329,8 @@ function inRequestOrder(paths, results) {
|
|
|
310
329
|
return results[at];
|
|
311
330
|
});
|
|
312
331
|
}
|
|
313
|
-
async function obfuscateAllCloud(files, paths, sources, key, config) {
|
|
314
|
-
const form = buildCloudForm(files, paths, sources, engineConfigWithoutKey(config));
|
|
332
|
+
async function obfuscateAllCloud(files, paths, sources, kinds, key, config) {
|
|
333
|
+
const form = buildCloudForm(files, paths, sources, kinds, engineConfigWithoutKey(config));
|
|
315
334
|
const response = await requestCloudBatch(key, form);
|
|
316
335
|
const boundary = extractBoundary(response.headers.get("content-type"));
|
|
317
336
|
if (boundary === null) {
|
|
@@ -333,13 +352,18 @@ async function obfuscateAllCloud(files, paths, sources, key, config) {
|
|
|
333
352
|
export async function obfuscateAll(files, config) {
|
|
334
353
|
const paths = files.map((file, i) => enginePath(file, i, files.length));
|
|
335
354
|
const sources = files.map((file) => sourceToString(file.source));
|
|
355
|
+
const kinds = fileSourceTypes(files);
|
|
336
356
|
const build = config?.seed === undefined ? { ...config, seed: randomSeed() } : config;
|
|
337
357
|
if (build.key !== undefined) {
|
|
338
|
-
return obfuscateAllCloud(files, paths, sources, build.key, build);
|
|
358
|
+
return obfuscateAllCloud(files, paths, sources, kinds, build.key, build);
|
|
339
359
|
}
|
|
340
360
|
let results;
|
|
341
361
|
try {
|
|
342
|
-
results = files.map((file, i) => processFile(sources[i], file.sourceMap ?? "", JSON.stringify({
|
|
362
|
+
results = files.map((file, i) => processFile(sources[i], file.sourceMap ?? "", JSON.stringify({
|
|
363
|
+
...build,
|
|
364
|
+
filePath: paths[i],
|
|
365
|
+
...(kinds[i] === undefined ? {} : { sourceType: kinds[i] }),
|
|
366
|
+
})));
|
|
343
367
|
}
|
|
344
368
|
catch (cause) {
|
|
345
369
|
throw engineCrash(cause);
|
package/dist/contract.d.ts
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
/** A named protection level. Sets the `complexity` target; output size follows from it. */
|
|
2
2
|
export type Preset = "minify" | "light" | "medium" | "hard" | "extreme";
|
|
3
|
+
/** Whether an input is an ES module or a classic script. `auto` decides from the source, treating an `.mjs` path as a module. */
|
|
4
|
+
export type SourceType = "auto" | "module" | "script";
|
|
3
5
|
/** A kind of transformation that a region can allow or deny. */
|
|
4
6
|
export type TransformKind = ConfigurableTransform | "stringEncoding";
|
|
5
7
|
type ConfigurableTransform = "controlFlowFlatten" | "opaquePredicate" | "mixedBooleanArithmetic" | "integerBytecode" | "crossDependency" | "scopeDeepen" | "comparisonHardening" | "selfIntegrity" | "objectConstruction";
|
|
@@ -53,8 +55,8 @@ export interface AfterpackConfig {
|
|
|
53
55
|
key?: string;
|
|
54
56
|
/** A named protection level. Defaults to `light`. */
|
|
55
57
|
preset?: Preset;
|
|
56
|
-
/** Whether the input is an ES module or a classic script. `auto` (the default) decides from the source, treating an `.mjs` path as a module. Set `module` for module output that has no `import`/`export`. */
|
|
57
|
-
sourceType?:
|
|
58
|
+
/** Whether the input is an ES module or a classic script. `auto` (the default) decides from the source, treating an `.mjs` path as a module. Set `module` for module output that has no `import`/`export`. A file's own `sourceType` overrides it. */
|
|
59
|
+
sourceType?: SourceType;
|
|
58
60
|
/** How much protection to apply. `0` applies none; higher values apply more and grow the output. */
|
|
59
61
|
complexity?: number;
|
|
60
62
|
/** Runtime reflection your code relies on. A detected pattern that is not listed fails the build. */
|
|
@@ -122,6 +124,8 @@ export interface FileInput {
|
|
|
122
124
|
source: string | Uint8Array;
|
|
123
125
|
/** The file's existing source map, so the output map points back to your original source. */
|
|
124
126
|
sourceMap?: string;
|
|
127
|
+
/** This file's kind, overriding the build's `sourceType`, for a build that mixes ES modules and classic scripts. */
|
|
128
|
+
sourceType?: SourceType;
|
|
125
129
|
}
|
|
126
130
|
/** `info` never blocks a build; `error` and `critical` do. */
|
|
127
131
|
export type Severity = "info" | "error" | "critical";
|
|
Binary file
|
package/package.json
CHANGED
package/readme.md
CHANGED
|
@@ -50,7 +50,7 @@ const results = await obfuscateAll([
|
|
|
50
50
|
await version(); // "0.2.1"
|
|
51
51
|
```
|
|
52
52
|
|
|
53
|
-
`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`. The second argument is the config. See the [configuration reference](https://www.afterpack.dev/docs/config) and the [presets](https://www.afterpack.dev/docs/presets).
|
|
53
|
+
`obfuscate` accepts a string, a `Uint8Array`, or a file object `{ path, source, sourceMap, sourceType }`, where `sourceMap` is the file's existing map to chain and `sourceType` (`"auto"`, `"module"` or `"script"`) overrides the build's for that file. Each result has `code`, `bytes`, `sourceMap` and `diagnostics`. The second argument is the config. See the [configuration reference](https://www.afterpack.dev/docs/config) and the [presets](https://www.afterpack.dev/docs/presets).
|
|
54
54
|
|
|
55
55
|
## Errors
|
|
56
56
|
|
|
@@ -75,8 +75,8 @@ Without a key, all of Free runs inside your Worker or Node process, with every p
|
|
|
75
75
|
|
|
76
76
|
| Measure | Bytes | |
|
|
77
77
|
|---|---:|---|
|
|
78
|
-
| Raw `.wasm` | 4,
|
|
79
|
-
| Gzipped | 1,306,
|
|
78
|
+
| Raw `.wasm` | 4,569,613 | 4.36 MiB |
|
|
79
|
+
| Gzipped | 1,306,547 | 1.25 MiB |
|
|
80
80
|
|
|
81
81
|
This fits Cloudflare's Worker size limit on both the free and paid plans. CPU time is the tighter limit: the free plan allows 10 ms per request, and obfuscating a 185 KB bundle at `complexity: 8` takes about 263 ms on an Apple M-series laptop. Plan on Workers Paid for real bundles.
|
|
82
82
|
|