@sysce/estrogen 0.5.6 → 0.5.8
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/README.md +24 -24
- package/bin/estrogen.js +22 -6
- package/dist/cjs/options.d.ts +2 -1
- package/dist/cjs/resolve-binary.d.ts +43 -0
- package/dist/cjs/resolve-binary.js +66 -1
- package/dist/esm/options.d.ts +2 -1
- package/dist/esm/resolve-binary.d.ts +43 -0
- package/dist/esm/resolve-binary.js +63 -1
- package/package.json +7 -7
package/README.md
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
<div align="center">
|
|
2
|
-
<img src="https://raw.githubusercontent.com/Fracital/estrogen/v0.5.
|
|
2
|
+
<img src="https://raw.githubusercontent.com/Fracital/estrogen/v0.5.8/docs/assets/estrogen.png" alt="estrogen" width="88" />
|
|
3
3
|
</div>
|
|
4
4
|
|
|
5
5
|
# @sysce/estrogen
|
|
@@ -7,7 +7,7 @@
|
|
|
7
7
|
<div align="center">
|
|
8
8
|
<a href="https://www.npmjs.com/package/@sysce/estrogen"><img src="https://img.shields.io/npm/v/@sysce/estrogen?maxAge=3600&label=npm" alt="npm" /></a>
|
|
9
9
|
<a href="https://github.com/Fracital/estrogen/actions/workflows/ci.yml"><img src="https://github.com/Fracital/estrogen/actions/workflows/ci.yml/badge.svg?branch=main" alt="CI" /></a>
|
|
10
|
-
<a href="https://github.com/Fracital/estrogen/blob/v0.5.
|
|
10
|
+
<a href="https://github.com/Fracital/estrogen/blob/v0.5.8/LICENSE"><img src="https://img.shields.io/badge/license-ISC-blue.svg" alt="license: ISC" /></a>
|
|
11
11
|
<a href="https://github.com/Fracital/estrogen/issues"><img src="https://img.shields.io/github/issues/Fracital/estrogen?style=flat&color=orange" alt="GitHub issues" /></a>
|
|
12
12
|
<a href="https://github.com/Fracital/estrogen/stargazers"><img src="https://img.shields.io/github/stars/Fracital/estrogen?style=flat&color=orange" alt="GitHub stars" /></a>
|
|
13
13
|
</div>
|
|
@@ -48,7 +48,7 @@ an optional dependency. Supported targets: linux x64 and arm64, darwin x64 and
|
|
|
48
48
|
arm64, win32 x64.
|
|
49
49
|
|
|
50
50
|
A nightly build of `main` is published under the `nightly` dist-tag, versioned
|
|
51
|
-
like `0.5.
|
|
51
|
+
like `0.5.8-nightly.202611230617.g1a2b3c4` (UTC time and commit), once a day
|
|
52
52
|
when `main` has a new commit that passed CI:
|
|
53
53
|
|
|
54
54
|
```sh
|
|
@@ -97,7 +97,7 @@ output remains safe to repeat and check; decoder-less no-header output needs a
|
|
|
97
97
|
fresh build. Changed options or canary lists need a fresh build too.
|
|
98
98
|
|
|
99
99
|
To bring packages into the build as well, run `estrogen build dist` with a
|
|
100
|
-
`[[vendor]]` config. See the [CLI reference](https://github.com/Fracital/estrogen/blob/v0.5.
|
|
100
|
+
`[[vendor]]` config. See the [CLI reference](https://github.com/Fracital/estrogen/blob/v0.5.8/docs/CLI.md).
|
|
101
101
|
|
|
102
102
|
## Benchmarks
|
|
103
103
|
|
|
@@ -110,7 +110,7 @@ file 20 times (median of 3 processes). javascript-obfuscator runs its three
|
|
|
110
110
|
shipped presets unchanged, `debugProtection` and `disableConsoleOutput`
|
|
111
111
|
included. Every build returns the same result as the original, and the VM
|
|
112
112
|
compiled every file it was given. The method and full tables are in
|
|
113
|
-
[docs/BENCHMARKS.md](https://github.com/Fracital/estrogen/blob/v0.5.
|
|
113
|
+
[docs/BENCHMARKS.md](https://github.com/Fracital/estrogen/blob/v0.5.8/docs/BENCHMARKS.md); `npm run bench` reruns it.
|
|
114
114
|
|
|
115
115
|
| | estrogen, VM | estrogen, `--no-vm` | javascript-obfuscator, default | medium | high |
|
|
116
116
|
| ---------------------------------------- | ------------ | ------------------- | ------------------------------ | -------- | --------- |
|
|
@@ -135,11 +135,11 @@ workloads the VM's size is mostly the runtime, about 9 KB gzip per file, which
|
|
|
135
135
|
`--shared-runtime` ships once for a build of ES modules. Hot code can leave the
|
|
136
136
|
VM with `--no-vm-glob`.
|
|
137
137
|
|
|
138
|
-
<img alt="Geometric mean slowdown, gzip size and build time for each tool and preset" src="https://raw.githubusercontent.com/Fracital/estrogen/v0.5.
|
|
138
|
+
<img alt="Geometric mean slowdown, gzip size and build time for each tool and preset" src="https://raw.githubusercontent.com/Fracital/estrogen/v0.5.8/docs/assets/bench/summary.png">
|
|
139
139
|
|
|
140
|
-
<img alt="Prettier format time, gzip size and build time for each tool and preset" src="https://raw.githubusercontent.com/Fracital/estrogen/v0.5.
|
|
140
|
+
<img alt="Prettier format time, gzip size and build time for each tool and preset" src="https://raw.githubusercontent.com/Fracital/estrogen/v0.5.8/docs/assets/bench/library.png">
|
|
141
141
|
|
|
142
|
-
<img alt="Steady-state slowdown against native for each workload, tool and preset" src="https://raw.githubusercontent.com/Fracital/estrogen/v0.5.
|
|
142
|
+
<img alt="Steady-state slowdown against native for each workload, tool and preset" src="https://raw.githubusercontent.com/Fracital/estrogen/v0.5.8/docs/assets/bench/slowdown.png">
|
|
143
143
|
|
|
144
144
|
## Compared with javascript-obfuscator
|
|
145
145
|
|
|
@@ -173,22 +173,22 @@ paid token, so the benchmark above runs the local package.
|
|
|
173
173
|
|
|
174
174
|
## Documentation
|
|
175
175
|
|
|
176
|
-
- [Text cloak and live injector](https://github.com/Fracital/estrogen/blob/v0.5.
|
|
176
|
+
- [Text cloak and live injector](https://github.com/Fracital/estrogen/blob/v0.5.8/docs/CLOAK.md): per-request ciphertext,
|
|
177
177
|
framework components, Ctrl+E overlays and opt-in frontend build inputs.
|
|
178
|
-
- [CLI reference](https://github.com/Fracital/estrogen/blob/v0.5.
|
|
178
|
+
- [CLI reference](https://github.com/Fracital/estrogen/blob/v0.5.8/docs/CLI.md): every flag, examples, exit codes, the
|
|
179
179
|
fail-closed rule.
|
|
180
|
-
- [Node API](https://github.com/Fracital/estrogen/blob/v0.5.
|
|
180
|
+
- [Node API](https://github.com/Fracital/estrogen/blob/v0.5.8/docs/NODE-API.md): `obfuscate()`, the esbuild, rsbuild, Vite and
|
|
181
181
|
Rollup plugins, the Astro integration, the options object, the `Report` shape.
|
|
182
|
-
- [Rust API](https://github.com/Fracital/estrogen/blob/v0.5.
|
|
183
|
-
- [Integration](https://github.com/Fracital/estrogen/blob/v0.5.
|
|
182
|
+
- [Rust API](https://github.com/Fracital/estrogen/blob/v0.5.8/docs/RUST-API.md): the `estrogen-core` public surface.
|
|
183
|
+
- [Integration](https://github.com/Fracital/estrogen/blob/v0.5.8/docs/INTEGRATION.md): esbuild, rsbuild, Vite, Rollup, Astro, and
|
|
184
184
|
a plain CLI step in `package.json`.
|
|
185
|
-
- [Benchmarks](https://github.com/Fracital/estrogen/blob/v0.5.
|
|
185
|
+
- [Benchmarks](https://github.com/Fracital/estrogen/blob/v0.5.8/docs/BENCHMARKS.md): what the VM and the literal pool cost at
|
|
186
186
|
run time and load, per workload, and the harness in `bench/`.
|
|
187
|
-
- [Project status](https://github.com/Fracital/estrogen/blob/v0.5.
|
|
187
|
+
- [Project status](https://github.com/Fracital/estrogen/blob/v0.5.8/docs/PROJECT_STATUS.md): current validation and remaining
|
|
188
188
|
compatibility work.
|
|
189
|
-
- [Proxy name rename](https://github.com/Fracital/estrogen/blob/v0.5.
|
|
189
|
+
- [Proxy name rename](https://github.com/Fracital/estrogen/blob/v0.5.8/docs/PROXY-NAMES.md): the `[proxy]` table, the vendor
|
|
190
190
|
and build scopes, `keep`, and the text a rename must not change.
|
|
191
|
-
- [Proxy integration coverage](https://github.com/Fracital/estrogen/blob/v0.5.
|
|
191
|
+
- [Proxy integration coverage](https://github.com/Fracital/estrogen/blob/v0.5.8/docs/PROXY_COVERAGE.md): per-site builds,
|
|
192
192
|
browser evidence, VM percentages and remaining gaps.
|
|
193
193
|
- [Wiki](https://github.com/Fracital/estrogen/wiki): install, configuration,
|
|
194
194
|
source maps, security and limits, contributing.
|
|
@@ -198,31 +198,31 @@ paid token, so the benchmark above runs the local package.
|
|
|
198
198
|
<table>
|
|
199
199
|
<tr><th></th><th>Site</th><th>Link</th><th>Repo</th></tr>
|
|
200
200
|
<tr>
|
|
201
|
-
<td align="center" valign="middle"><img src="https://raw.githubusercontent.com/Fracital/estrogen/v0.5.
|
|
201
|
+
<td align="center" valign="middle"><img src="https://raw.githubusercontent.com/Fracital/estrogen/v0.5.8/docs/assets/brands/abstract.png" alt="abstract v2" width="28"></td>
|
|
202
202
|
<td valign="middle">abstract v2</td>
|
|
203
203
|
<td valign="middle"><a href="https://abstracteducation.loan">abstracteducation.loan</a></td>
|
|
204
204
|
<td valign="middle"></td>
|
|
205
205
|
</tr>
|
|
206
206
|
<tr>
|
|
207
|
-
<td align="center" valign="middle"><img src="https://raw.githubusercontent.com/Fracital/estrogen/v0.5.
|
|
207
|
+
<td align="center" valign="middle"><img src="https://raw.githubusercontent.com/Fracital/estrogen/v0.5.8/docs/assets/brands/fracital.svg" alt="Fracital" width="28"></td>
|
|
208
208
|
<td valign="middle">Fracital</td>
|
|
209
209
|
<td valign="middle"><a href="https://fracit.al">fracit.al</a></td>
|
|
210
210
|
<td valign="middle"><a href="https://github.com/Fracital/Fracital"><code>Fracital/Fracital</code></a></td>
|
|
211
211
|
</tr>
|
|
212
212
|
<tr>
|
|
213
|
-
<td align="center" valign="middle"><img src="https://raw.githubusercontent.com/Fracital/estrogen/v0.5.
|
|
213
|
+
<td align="center" valign="middle"><img src="https://raw.githubusercontent.com/Fracital/estrogen/v0.5.8/docs/assets/brands/systemya.png" alt="SystemYA" width="28"></td>
|
|
214
214
|
<td valign="middle">SystemYA</td>
|
|
215
215
|
<td valign="middle"><a href="https://systemya.fracit.al">systemya.fracit.al</a></td>
|
|
216
216
|
<td valign="middle"><a href="https://github.com/Fracital/SystemYA"><code>Fracital/SystemYA</code></a></td>
|
|
217
217
|
</tr>
|
|
218
218
|
<tr>
|
|
219
|
-
<td align="center" valign="middle"><img src="https://raw.githubusercontent.com/Fracital/estrogen/v0.5.
|
|
219
|
+
<td align="center" valign="middle"><img src="https://raw.githubusercontent.com/Fracital/estrogen/v0.5.8/docs/assets/brands/stomp.png" alt="STomp" width="28"></td>
|
|
220
220
|
<td valign="middle">STomp (powerMouse)</td>
|
|
221
221
|
<td valign="middle"><a href="https://stomp.fracit.al">stomp.fracit.al</a></td>
|
|
222
222
|
<td valign="middle"><a href="https://github.com/Fracital/powerMouse"><code>Fracital/powerMouse</code></a></td>
|
|
223
223
|
</tr>
|
|
224
224
|
<tr>
|
|
225
|
-
<td align="center" valign="middle"><img src="https://raw.githubusercontent.com/Fracital/estrogen/v0.5.
|
|
225
|
+
<td align="center" valign="middle"><img src="https://raw.githubusercontent.com/Fracital/estrogen/v0.5.8/docs/assets/brands/holy-unblocker.svg" alt="Holy Unblocker" width="28"></td>
|
|
226
226
|
<td valign="middle">Holy Unblocker</td>
|
|
227
227
|
<td valign="middle"><a href="https://holyunb.locker">holyunb.locker</a></td>
|
|
228
228
|
<td valign="middle"><a href="https://github.com/holy-unblocker/website2"><code>holy-unblocker/website2</code></a></td>
|
|
@@ -233,8 +233,8 @@ paid token, so the benchmark above runs the local package.
|
|
|
233
233
|
|
|
234
234
|
| | GitHub | Name |
|
|
235
235
|
| ----------------------------------------------------------------------------- | ------------------------------ | ---------- |
|
|
236
|
-
| <img src="https://raw.githubusercontent.com/Fracital/estrogen/v0.5.
|
|
236
|
+
| <img src="https://raw.githubusercontent.com/Fracital/estrogen/v0.5.8/docs/assets/am%20i%20cool%20yet.png" width="64" alt="e9x's avatar"> | [@e9x](https://github.com/e9x) | David Reed |
|
|
237
237
|
|
|
238
238
|
## License
|
|
239
239
|
|
|
240
|
-
ISC. See [LICENSE](https://github.com/Fracital/estrogen/blob/v0.5.
|
|
240
|
+
ISC. See [LICENSE](https://github.com/Fracital/estrogen/blob/v0.5.8/LICENSE).
|
package/bin/estrogen.js
CHANGED
|
@@ -4,25 +4,41 @@
|
|
|
4
4
|
// the exit code. A missing binary is a clear error, not a stack trace.
|
|
5
5
|
import { spawn } from 'node:child_process';
|
|
6
6
|
import { createRequire } from 'node:module';
|
|
7
|
+
import { fileURLToPath } from 'node:url';
|
|
7
8
|
|
|
8
|
-
import {
|
|
9
|
+
import {
|
|
10
|
+
LauncherLoopError,
|
|
11
|
+
MissingBinaryError,
|
|
12
|
+
resolveLaunchTarget,
|
|
13
|
+
} from '../dist/esm/resolve-binary.js';
|
|
9
14
|
|
|
10
15
|
const require = createRequire(import.meta.url);
|
|
11
16
|
|
|
12
|
-
let
|
|
17
|
+
let target;
|
|
13
18
|
try {
|
|
14
19
|
// ESTROGEN_BINARY lets a local build or a test point the launcher at its own
|
|
15
|
-
// binary without installing a per-platform package.
|
|
16
|
-
|
|
20
|
+
// binary without installing a per-platform package. A value that names this
|
|
21
|
+
// launcher, or any launcher once one has run, is ignored: following it
|
|
22
|
+
// spawned the launcher again with the same environment, forever.
|
|
23
|
+
target = resolveLaunchTarget(require, fileURLToPath(import.meta.url));
|
|
17
24
|
} catch (error) {
|
|
18
|
-
if (error instanceof MissingBinaryError) {
|
|
25
|
+
if (error instanceof MissingBinaryError || error instanceof LauncherLoopError) {
|
|
19
26
|
process.stderr.write(`${error.message}\n`);
|
|
20
27
|
process.exit(1);
|
|
21
28
|
}
|
|
22
29
|
throw error;
|
|
23
30
|
}
|
|
31
|
+
if (target.ignored !== undefined) {
|
|
32
|
+
process.stderr.write(
|
|
33
|
+
`estrogen: ESTROGEN_BINARY=${target.ignored} is an estrogen launcher, ` +
|
|
34
|
+
`not the native binary; running ${target.binary}\n`,
|
|
35
|
+
);
|
|
36
|
+
}
|
|
24
37
|
|
|
25
|
-
const child = spawn(
|
|
38
|
+
const child = spawn(target.binary, process.argv.slice(2), {
|
|
39
|
+
stdio: 'inherit',
|
|
40
|
+
env: target.env,
|
|
41
|
+
});
|
|
26
42
|
|
|
27
43
|
child.on('error', (error) => {
|
|
28
44
|
process.stderr.write(`estrogen failed to start: ${error.message}\n`);
|
package/dist/cjs/options.d.ts
CHANGED
|
@@ -181,7 +181,8 @@ export interface Options {
|
|
|
181
181
|
report?: string;
|
|
182
182
|
/**
|
|
183
183
|
* Fail the run (exit 4) when any JS chunk is protected by something other
|
|
184
|
-
* than the VM (`--require-vm`).
|
|
184
|
+
* than the VM (`--require-vm`). A chunk skipped as already obfuscated fails
|
|
185
|
+
* too unless its code is VM output; through 0.5.7 it always passed.
|
|
185
186
|
*/
|
|
186
187
|
requireVm?: boolean;
|
|
187
188
|
/**
|
|
@@ -44,3 +44,46 @@ export declare class MissingBinaryError extends Error {
|
|
|
44
44
|
* has no binary in it.
|
|
45
45
|
*/
|
|
46
46
|
export declare function resolveBinaryPath(req: NodeRequire, override?: string): string;
|
|
47
|
+
/**
|
|
48
|
+
* The binary inside the installed `@sysce/estrogen-<os>-<cpu>` package, with no
|
|
49
|
+
* override and no environment lookup. Throws {@link MissingBinaryError} as
|
|
50
|
+
* {@link resolveBinaryPath} does.
|
|
51
|
+
*/
|
|
52
|
+
export declare function platformBinaryPath(req: NodeRequire): string;
|
|
53
|
+
/**
|
|
54
|
+
* The environment variable the `estrogen` launcher sets on the process it
|
|
55
|
+
* spawns: how many launchers are above that process. A launcher that starts
|
|
56
|
+
* with it set was spawned by another launcher.
|
|
57
|
+
*/
|
|
58
|
+
export declare const LAUNCHER_DEPTH_ENV = "ESTROGEN_LAUNCHER_DEPTH";
|
|
59
|
+
/**
|
|
60
|
+
* Thrown when estrogen launchers keep spawning each other instead of reaching
|
|
61
|
+
* a native binary.
|
|
62
|
+
*/
|
|
63
|
+
export declare class LauncherLoopError extends Error {
|
|
64
|
+
constructor(message: string);
|
|
65
|
+
}
|
|
66
|
+
/** What the launcher runs, and with which environment. */
|
|
67
|
+
export interface LaunchTarget {
|
|
68
|
+
/** The path to spawn. */
|
|
69
|
+
binary: string;
|
|
70
|
+
/** The environment for the spawned process, with the launcher depth set. */
|
|
71
|
+
env: NodeJS.ProcessEnv;
|
|
72
|
+
/**
|
|
73
|
+
* The `ESTROGEN_BINARY` value the launcher did not follow, when it named an
|
|
74
|
+
* estrogen launcher rather than a native binary.
|
|
75
|
+
*/
|
|
76
|
+
ignored?: string;
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
* Pick what the `estrogen` launcher at `launcher` runs.
|
|
80
|
+
*
|
|
81
|
+
* `ESTROGEN_BINARY` is followed unless it would bring the launcher back to a
|
|
82
|
+
* launcher: when it names `launcher` itself (`node_modules/.bin/estrogen` is a
|
|
83
|
+
* symlink to it), or when this launcher was itself spawned by a launcher
|
|
84
|
+
* (`ESTROGEN_LAUNCHER_DEPTH` is set), the variable is ignored and the
|
|
85
|
+
* installed platform binary runs. Following it there re-ran the launcher with
|
|
86
|
+
* the same environment, which spawned it again with no end. A third launcher
|
|
87
|
+
* in a row throws {@link LauncherLoopError}.
|
|
88
|
+
*/
|
|
89
|
+
export declare function resolveLaunchTarget(req: NodeRequire, launcher: string, env?: NodeJS.ProcessEnv): LaunchTarget;
|
|
@@ -1,10 +1,12 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.MissingBinaryError = exports.PLATFORM_PACKAGES = void 0;
|
|
3
|
+
exports.LauncherLoopError = exports.LAUNCHER_DEPTH_ENV = exports.MissingBinaryError = exports.PLATFORM_PACKAGES = void 0;
|
|
4
4
|
exports.targetKey = targetKey;
|
|
5
5
|
exports.platformPackageName = platformPackageName;
|
|
6
6
|
exports.binSubpath = binSubpath;
|
|
7
7
|
exports.resolveBinaryPath = resolveBinaryPath;
|
|
8
|
+
exports.platformBinaryPath = platformBinaryPath;
|
|
9
|
+
exports.resolveLaunchTarget = resolveLaunchTarget;
|
|
8
10
|
const node_fs_1 = require("node:fs");
|
|
9
11
|
const node_path_1 = require("node:path");
|
|
10
12
|
const node_process_1 = require("node:process");
|
|
@@ -85,6 +87,14 @@ function resolveBinaryPath(req, override) {
|
|
|
85
87
|
const fromEnv = process.env.ESTROGEN_BINARY;
|
|
86
88
|
if (fromEnv !== undefined && fromEnv !== '')
|
|
87
89
|
return fromEnv;
|
|
90
|
+
return platformBinaryPath(req);
|
|
91
|
+
}
|
|
92
|
+
/**
|
|
93
|
+
* The binary inside the installed `@sysce/estrogen-<os>-<cpu>` package, with no
|
|
94
|
+
* override and no environment lookup. Throws {@link MissingBinaryError} as
|
|
95
|
+
* {@link resolveBinaryPath} does.
|
|
96
|
+
*/
|
|
97
|
+
function platformBinaryPath(req) {
|
|
88
98
|
const key = targetKey();
|
|
89
99
|
const pkg = platformPackageName();
|
|
90
100
|
if (key === null || pkg === null) {
|
|
@@ -112,3 +122,58 @@ function resolveBinaryPath(req, override) {
|
|
|
112
122
|
}
|
|
113
123
|
return binary;
|
|
114
124
|
}
|
|
125
|
+
/**
|
|
126
|
+
* The environment variable the `estrogen` launcher sets on the process it
|
|
127
|
+
* spawns: how many launchers are above that process. A launcher that starts
|
|
128
|
+
* with it set was spawned by another launcher.
|
|
129
|
+
*/
|
|
130
|
+
exports.LAUNCHER_DEPTH_ENV = 'ESTROGEN_LAUNCHER_DEPTH';
|
|
131
|
+
/**
|
|
132
|
+
* Thrown when estrogen launchers keep spawning each other instead of reaching
|
|
133
|
+
* a native binary.
|
|
134
|
+
*/
|
|
135
|
+
class LauncherLoopError extends Error {
|
|
136
|
+
constructor(message) {
|
|
137
|
+
super(message);
|
|
138
|
+
this.name = 'LauncherLoopError';
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
exports.LauncherLoopError = LauncherLoopError;
|
|
142
|
+
/** Whether two paths name the same file once symlinks are resolved. */
|
|
143
|
+
function sameFile(a, b) {
|
|
144
|
+
try {
|
|
145
|
+
return (0, node_fs_1.realpathSync)(a) === (0, node_fs_1.realpathSync)(b);
|
|
146
|
+
}
|
|
147
|
+
catch {
|
|
148
|
+
return false;
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
/**
|
|
152
|
+
* Pick what the `estrogen` launcher at `launcher` runs.
|
|
153
|
+
*
|
|
154
|
+
* `ESTROGEN_BINARY` is followed unless it would bring the launcher back to a
|
|
155
|
+
* launcher: when it names `launcher` itself (`node_modules/.bin/estrogen` is a
|
|
156
|
+
* symlink to it), or when this launcher was itself spawned by a launcher
|
|
157
|
+
* (`ESTROGEN_LAUNCHER_DEPTH` is set), the variable is ignored and the
|
|
158
|
+
* installed platform binary runs. Following it there re-ran the launcher with
|
|
159
|
+
* the same environment, which spawned it again with no end. A third launcher
|
|
160
|
+
* in a row throws {@link LauncherLoopError}.
|
|
161
|
+
*/
|
|
162
|
+
function resolveLaunchTarget(req, launcher, env = process.env) {
|
|
163
|
+
const parsed = Number.parseInt(env[exports.LAUNCHER_DEPTH_ENV] ?? '', 10);
|
|
164
|
+
const depth = Number.isNaN(parsed) || parsed < 0 ? 0 : parsed;
|
|
165
|
+
if (depth >= 2) {
|
|
166
|
+
throw new LauncherLoopError(`estrogen: ${depth} estrogen launchers spawned each other without ` +
|
|
167
|
+
`reaching a native binary. Point ESTROGEN_BINARY at the binary ` +
|
|
168
|
+
`inside @sysce/estrogen-<os>-<cpu>, or unset it.`);
|
|
169
|
+
}
|
|
170
|
+
const childEnv = { ...env, [exports.LAUNCHER_DEPTH_ENV]: String(depth + 1) };
|
|
171
|
+
const fromEnv = env.ESTROGEN_BINARY;
|
|
172
|
+
if (fromEnv === undefined || fromEnv === '') {
|
|
173
|
+
return { binary: platformBinaryPath(req), env: childEnv };
|
|
174
|
+
}
|
|
175
|
+
if (depth === 0 && !sameFile(fromEnv, launcher)) {
|
|
176
|
+
return { binary: fromEnv, env: childEnv };
|
|
177
|
+
}
|
|
178
|
+
return { binary: platformBinaryPath(req), env: childEnv, ignored: fromEnv };
|
|
179
|
+
}
|
package/dist/esm/options.d.ts
CHANGED
|
@@ -181,7 +181,8 @@ export interface Options {
|
|
|
181
181
|
report?: string;
|
|
182
182
|
/**
|
|
183
183
|
* Fail the run (exit 4) when any JS chunk is protected by something other
|
|
184
|
-
* than the VM (`--require-vm`).
|
|
184
|
+
* than the VM (`--require-vm`). A chunk skipped as already obfuscated fails
|
|
185
|
+
* too unless its code is VM output; through 0.5.7 it always passed.
|
|
185
186
|
*/
|
|
186
187
|
requireVm?: boolean;
|
|
187
188
|
/**
|
|
@@ -44,3 +44,46 @@ export declare class MissingBinaryError extends Error {
|
|
|
44
44
|
* has no binary in it.
|
|
45
45
|
*/
|
|
46
46
|
export declare function resolveBinaryPath(req: NodeRequire, override?: string): string;
|
|
47
|
+
/**
|
|
48
|
+
* The binary inside the installed `@sysce/estrogen-<os>-<cpu>` package, with no
|
|
49
|
+
* override and no environment lookup. Throws {@link MissingBinaryError} as
|
|
50
|
+
* {@link resolveBinaryPath} does.
|
|
51
|
+
*/
|
|
52
|
+
export declare function platformBinaryPath(req: NodeRequire): string;
|
|
53
|
+
/**
|
|
54
|
+
* The environment variable the `estrogen` launcher sets on the process it
|
|
55
|
+
* spawns: how many launchers are above that process. A launcher that starts
|
|
56
|
+
* with it set was spawned by another launcher.
|
|
57
|
+
*/
|
|
58
|
+
export declare const LAUNCHER_DEPTH_ENV = "ESTROGEN_LAUNCHER_DEPTH";
|
|
59
|
+
/**
|
|
60
|
+
* Thrown when estrogen launchers keep spawning each other instead of reaching
|
|
61
|
+
* a native binary.
|
|
62
|
+
*/
|
|
63
|
+
export declare class LauncherLoopError extends Error {
|
|
64
|
+
constructor(message: string);
|
|
65
|
+
}
|
|
66
|
+
/** What the launcher runs, and with which environment. */
|
|
67
|
+
export interface LaunchTarget {
|
|
68
|
+
/** The path to spawn. */
|
|
69
|
+
binary: string;
|
|
70
|
+
/** The environment for the spawned process, with the launcher depth set. */
|
|
71
|
+
env: NodeJS.ProcessEnv;
|
|
72
|
+
/**
|
|
73
|
+
* The `ESTROGEN_BINARY` value the launcher did not follow, when it named an
|
|
74
|
+
* estrogen launcher rather than a native binary.
|
|
75
|
+
*/
|
|
76
|
+
ignored?: string;
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
* Pick what the `estrogen` launcher at `launcher` runs.
|
|
80
|
+
*
|
|
81
|
+
* `ESTROGEN_BINARY` is followed unless it would bring the launcher back to a
|
|
82
|
+
* launcher: when it names `launcher` itself (`node_modules/.bin/estrogen` is a
|
|
83
|
+
* symlink to it), or when this launcher was itself spawned by a launcher
|
|
84
|
+
* (`ESTROGEN_LAUNCHER_DEPTH` is set), the variable is ignored and the
|
|
85
|
+
* installed platform binary runs. Following it there re-ran the launcher with
|
|
86
|
+
* the same environment, which spawned it again with no end. A third launcher
|
|
87
|
+
* in a row throws {@link LauncherLoopError}.
|
|
88
|
+
*/
|
|
89
|
+
export declare function resolveLaunchTarget(req: NodeRequire, launcher: string, env?: NodeJS.ProcessEnv): LaunchTarget;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { existsSync } from 'node:fs';
|
|
1
|
+
import { existsSync, realpathSync } from 'node:fs';
|
|
2
2
|
import { dirname, join } from 'node:path';
|
|
3
3
|
import { arch as processArch, platform as processPlatform } from 'node:process';
|
|
4
4
|
/**
|
|
@@ -77,6 +77,14 @@ export function resolveBinaryPath(req, override) {
|
|
|
77
77
|
const fromEnv = process.env.ESTROGEN_BINARY;
|
|
78
78
|
if (fromEnv !== undefined && fromEnv !== '')
|
|
79
79
|
return fromEnv;
|
|
80
|
+
return platformBinaryPath(req);
|
|
81
|
+
}
|
|
82
|
+
/**
|
|
83
|
+
* The binary inside the installed `@sysce/estrogen-<os>-<cpu>` package, with no
|
|
84
|
+
* override and no environment lookup. Throws {@link MissingBinaryError} as
|
|
85
|
+
* {@link resolveBinaryPath} does.
|
|
86
|
+
*/
|
|
87
|
+
export function platformBinaryPath(req) {
|
|
80
88
|
const key = targetKey();
|
|
81
89
|
const pkg = platformPackageName();
|
|
82
90
|
if (key === null || pkg === null) {
|
|
@@ -104,3 +112,57 @@ export function resolveBinaryPath(req, override) {
|
|
|
104
112
|
}
|
|
105
113
|
return binary;
|
|
106
114
|
}
|
|
115
|
+
/**
|
|
116
|
+
* The environment variable the `estrogen` launcher sets on the process it
|
|
117
|
+
* spawns: how many launchers are above that process. A launcher that starts
|
|
118
|
+
* with it set was spawned by another launcher.
|
|
119
|
+
*/
|
|
120
|
+
export const LAUNCHER_DEPTH_ENV = 'ESTROGEN_LAUNCHER_DEPTH';
|
|
121
|
+
/**
|
|
122
|
+
* Thrown when estrogen launchers keep spawning each other instead of reaching
|
|
123
|
+
* a native binary.
|
|
124
|
+
*/
|
|
125
|
+
export class LauncherLoopError extends Error {
|
|
126
|
+
constructor(message) {
|
|
127
|
+
super(message);
|
|
128
|
+
this.name = 'LauncherLoopError';
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
/** Whether two paths name the same file once symlinks are resolved. */
|
|
132
|
+
function sameFile(a, b) {
|
|
133
|
+
try {
|
|
134
|
+
return realpathSync(a) === realpathSync(b);
|
|
135
|
+
}
|
|
136
|
+
catch {
|
|
137
|
+
return false;
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
/**
|
|
141
|
+
* Pick what the `estrogen` launcher at `launcher` runs.
|
|
142
|
+
*
|
|
143
|
+
* `ESTROGEN_BINARY` is followed unless it would bring the launcher back to a
|
|
144
|
+
* launcher: when it names `launcher` itself (`node_modules/.bin/estrogen` is a
|
|
145
|
+
* symlink to it), or when this launcher was itself spawned by a launcher
|
|
146
|
+
* (`ESTROGEN_LAUNCHER_DEPTH` is set), the variable is ignored and the
|
|
147
|
+
* installed platform binary runs. Following it there re-ran the launcher with
|
|
148
|
+
* the same environment, which spawned it again with no end. A third launcher
|
|
149
|
+
* in a row throws {@link LauncherLoopError}.
|
|
150
|
+
*/
|
|
151
|
+
export function resolveLaunchTarget(req, launcher, env = process.env) {
|
|
152
|
+
const parsed = Number.parseInt(env[LAUNCHER_DEPTH_ENV] ?? '', 10);
|
|
153
|
+
const depth = Number.isNaN(parsed) || parsed < 0 ? 0 : parsed;
|
|
154
|
+
if (depth >= 2) {
|
|
155
|
+
throw new LauncherLoopError(`estrogen: ${depth} estrogen launchers spawned each other without ` +
|
|
156
|
+
`reaching a native binary. Point ESTROGEN_BINARY at the binary ` +
|
|
157
|
+
`inside @sysce/estrogen-<os>-<cpu>, or unset it.`);
|
|
158
|
+
}
|
|
159
|
+
const childEnv = { ...env, [LAUNCHER_DEPTH_ENV]: String(depth + 1) };
|
|
160
|
+
const fromEnv = env.ESTROGEN_BINARY;
|
|
161
|
+
if (fromEnv === undefined || fromEnv === '') {
|
|
162
|
+
return { binary: platformBinaryPath(req), env: childEnv };
|
|
163
|
+
}
|
|
164
|
+
if (depth === 0 && !sameFile(fromEnv, launcher)) {
|
|
165
|
+
return { binary: fromEnv, env: childEnv };
|
|
166
|
+
}
|
|
167
|
+
return { binary: platformBinaryPath(req), env: childEnv, ignored: fromEnv };
|
|
168
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sysce/estrogen",
|
|
3
|
-
"version": "0.5.
|
|
3
|
+
"version": "0.5.8",
|
|
4
4
|
"description": "Post-build web obfuscator in Rust. Rewrites a built directory in place: JavaScript into a per-build bytecode VM, strings into an encrypted pool, and HTML, SVG and wasm names to match.",
|
|
5
5
|
"license": "ISC",
|
|
6
6
|
"author": "David Reed",
|
|
@@ -203,17 +203,17 @@
|
|
|
203
203
|
"test:cloak": "npm run build && node --test test/cloak.test.mjs test/cloak-span.test.mjs",
|
|
204
204
|
"test:function-source": "npm run build && node --test test/function-source-warning.test.mjs",
|
|
205
205
|
"test:vendor": "npm run build && node --test test/vendor.test.mjs",
|
|
206
|
-
"test:resolve": "npm run build && node --test test/resolve-binary.test.mjs",
|
|
206
|
+
"test:resolve": "npm run build && node --test test/resolve-binary.test.mjs test/launcher-loop.test.mjs",
|
|
207
207
|
"test:astro": "npm run build && astro build --root ./test/fixtures/astro && node test/cloak-astro-ssr.mjs",
|
|
208
208
|
"test:browser": "node test/cloak-browser.mjs && node test/cloak-framework-browser.mjs && node test/cloak-astro-browser.mjs && node test/injector-browser.mjs && node test/vm-browser-compat.mjs",
|
|
209
209
|
"prepack": "npm run build && node scripts/readme.mjs"
|
|
210
210
|
},
|
|
211
211
|
"optionalDependencies": {
|
|
212
|
-
"@sysce/estrogen-darwin-arm64": "0.5.
|
|
213
|
-
"@sysce/estrogen-darwin-x64": "0.5.
|
|
214
|
-
"@sysce/estrogen-linux-arm64": "0.5.
|
|
215
|
-
"@sysce/estrogen-linux-x64": "0.5.
|
|
216
|
-
"@sysce/estrogen-win32-x64": "0.5.
|
|
212
|
+
"@sysce/estrogen-darwin-arm64": "0.5.8",
|
|
213
|
+
"@sysce/estrogen-darwin-x64": "0.5.8",
|
|
214
|
+
"@sysce/estrogen-linux-arm64": "0.5.8",
|
|
215
|
+
"@sysce/estrogen-linux-x64": "0.5.8",
|
|
216
|
+
"@sysce/estrogen-win32-x64": "0.5.8"
|
|
217
217
|
},
|
|
218
218
|
"peerDependencies": {
|
|
219
219
|
"@rsbuild/core": "*",
|