@sysce/estrogen 0.0.0-stage → 0.5.4

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.
Files changed (140) hide show
  1. package/LICENSE +15 -0
  2. package/README.md +207 -2
  3. package/bin/estrogen.js +38 -0
  4. package/dist/cjs/astro.d.ts +31 -0
  5. package/dist/cjs/astro.js +45 -0
  6. package/dist/cjs/cloak/astro/HolyLink.astro +36 -0
  7. package/dist/cjs/cloak/astro/HolyLink.astro.d.ts +14 -0
  8. package/dist/cjs/cloak/astro/HolyText.astro +31 -0
  9. package/dist/cjs/cloak/astro/HolyText.astro.d.ts +12 -0
  10. package/dist/cjs/cloak/astro.d.ts +2 -0
  11. package/dist/cjs/cloak/astro.js +10 -0
  12. package/dist/cjs/cloak/base64.d.ts +2 -0
  13. package/dist/cjs/cloak/base64.js +20 -0
  14. package/dist/cjs/cloak/crypto.d.ts +16 -0
  15. package/dist/cjs/cloak/crypto.js +40 -0
  16. package/dist/cjs/cloak/decrypt.d.ts +23 -0
  17. package/dist/cjs/cloak/decrypt.js +144 -0
  18. package/dist/cjs/cloak/elements.d.ts +45 -0
  19. package/dist/cjs/cloak/elements.js +195 -0
  20. package/dist/cjs/cloak/index.d.ts +10 -0
  21. package/dist/cjs/cloak/index.js +41 -0
  22. package/dist/cjs/cloak/preact.d.ts +10 -0
  23. package/dist/cjs/cloak/preact.js +19 -0
  24. package/dist/cjs/cloak/props.d.ts +18 -0
  25. package/dist/cjs/cloak/props.js +27 -0
  26. package/dist/cjs/cloak/react-extra.d.ts +327 -0
  27. package/dist/cjs/cloak/react-extra.js +169 -0
  28. package/dist/cjs/cloak/react.d.ts +28 -0
  29. package/dist/cjs/cloak/react.js +159 -0
  30. package/dist/cjs/cloak/render.d.ts +37 -0
  31. package/dist/cjs/cloak/render.js +54 -0
  32. package/dist/cjs/cloak/server.d.ts +35 -0
  33. package/dist/cjs/cloak/server.js +87 -0
  34. package/dist/cjs/cloak/server.node.d.ts +15 -0
  35. package/dist/cjs/cloak/server.node.js +36 -0
  36. package/dist/cjs/cloak/solid.d.ts +13 -0
  37. package/dist/cjs/cloak/solid.js +55 -0
  38. package/dist/cjs/cloak/span.d.ts +8 -0
  39. package/dist/cjs/cloak/span.js +123 -0
  40. package/dist/cjs/cloak/strings.d.ts +18 -0
  41. package/dist/cjs/cloak/strings.js +53 -0
  42. package/dist/cjs/cloak/svelte/HolyLink.svelte +12 -0
  43. package/dist/cjs/cloak/svelte/HolyLink.svelte.d.ts +5 -0
  44. package/dist/cjs/cloak/svelte/HolyText.svelte +13 -0
  45. package/dist/cjs/cloak/svelte/HolyText.svelte.d.ts +5 -0
  46. package/dist/cjs/cloak/svelte.d.ts +2 -0
  47. package/dist/cjs/cloak/svelte.js +10 -0
  48. package/dist/cjs/cloak/vue.d.ts +36 -0
  49. package/dist/cjs/cloak/vue.js +34 -0
  50. package/dist/cjs/esbuild.d.ts +33 -0
  51. package/dist/cjs/esbuild.js +79 -0
  52. package/dist/cjs/index.d.ts +24 -0
  53. package/dist/cjs/index.js +35 -0
  54. package/dist/cjs/node-require.js +7 -0
  55. package/dist/cjs/obfuscate.d.ts +23 -0
  56. package/dist/cjs/obfuscate.js +148 -0
  57. package/dist/cjs/options.d.ts +217 -0
  58. package/dist/cjs/options.js +89 -0
  59. package/dist/cjs/package.json +3 -0
  60. package/dist/cjs/report.d.ts +64 -0
  61. package/dist/cjs/report.js +55 -0
  62. package/dist/cjs/resolve-binary.d.ts +44 -0
  63. package/dist/cjs/resolve-binary.js +109 -0
  64. package/dist/cjs/rollup.d.ts +30 -0
  65. package/dist/cjs/rollup.js +57 -0
  66. package/dist/cjs/rsbuild.d.ts +29 -0
  67. package/dist/cjs/rsbuild.js +45 -0
  68. package/dist/cjs/vendor.d.ts +16 -0
  69. package/dist/cjs/vendor.js +95 -0
  70. package/dist/cjs/vite.d.ts +31 -0
  71. package/dist/cjs/vite.js +53 -0
  72. package/dist/esm/astro.d.ts +31 -0
  73. package/dist/esm/astro.js +42 -0
  74. package/dist/esm/cloak/astro/HolyLink.astro +36 -0
  75. package/dist/esm/cloak/astro/HolyLink.astro.d.ts +14 -0
  76. package/dist/esm/cloak/astro/HolyText.astro +31 -0
  77. package/dist/esm/cloak/astro/HolyText.astro.d.ts +12 -0
  78. package/dist/esm/cloak/astro.d.ts +2 -0
  79. package/dist/esm/cloak/astro.js +2 -0
  80. package/dist/esm/cloak/base64.d.ts +2 -0
  81. package/dist/esm/cloak/base64.js +16 -0
  82. package/dist/esm/cloak/crypto.d.ts +16 -0
  83. package/dist/esm/cloak/crypto.js +36 -0
  84. package/dist/esm/cloak/decrypt.d.ts +23 -0
  85. package/dist/esm/cloak/decrypt.js +136 -0
  86. package/dist/esm/cloak/elements.d.ts +45 -0
  87. package/dist/esm/cloak/elements.js +189 -0
  88. package/dist/esm/cloak/index.d.ts +10 -0
  89. package/dist/esm/cloak/index.js +13 -0
  90. package/dist/esm/cloak/preact.d.ts +10 -0
  91. package/dist/esm/cloak/preact.js +15 -0
  92. package/dist/esm/cloak/props.d.ts +18 -0
  93. package/dist/esm/cloak/props.js +23 -0
  94. package/dist/esm/cloak/react-extra.d.ts +327 -0
  95. package/dist/esm/cloak/react-extra.js +161 -0
  96. package/dist/esm/cloak/react.d.ts +28 -0
  97. package/dist/esm/cloak/react.js +147 -0
  98. package/dist/esm/cloak/render.d.ts +37 -0
  99. package/dist/esm/cloak/render.js +48 -0
  100. package/dist/esm/cloak/server.d.ts +35 -0
  101. package/dist/esm/cloak/server.js +75 -0
  102. package/dist/esm/cloak/server.node.d.ts +15 -0
  103. package/dist/esm/cloak/server.node.js +22 -0
  104. package/dist/esm/cloak/solid.d.ts +13 -0
  105. package/dist/esm/cloak/solid.js +51 -0
  106. package/dist/esm/cloak/span.d.ts +8 -0
  107. package/dist/esm/cloak/span.js +117 -0
  108. package/dist/esm/cloak/strings.d.ts +18 -0
  109. package/dist/esm/cloak/strings.js +47 -0
  110. package/dist/esm/cloak/svelte/HolyLink.svelte +12 -0
  111. package/dist/esm/cloak/svelte/HolyLink.svelte.d.ts +5 -0
  112. package/dist/esm/cloak/svelte/HolyText.svelte +13 -0
  113. package/dist/esm/cloak/svelte/HolyText.svelte.d.ts +5 -0
  114. package/dist/esm/cloak/svelte.d.ts +2 -0
  115. package/dist/esm/cloak/svelte.js +2 -0
  116. package/dist/esm/cloak/vue.d.ts +36 -0
  117. package/dist/esm/cloak/vue.js +31 -0
  118. package/dist/esm/esbuild.d.ts +33 -0
  119. package/dist/esm/esbuild.js +76 -0
  120. package/dist/esm/index.d.ts +24 -0
  121. package/dist/esm/index.js +22 -0
  122. package/dist/esm/node-require.js +8 -0
  123. package/dist/esm/obfuscate.d.ts +23 -0
  124. package/dist/esm/obfuscate.js +145 -0
  125. package/dist/esm/options.d.ts +217 -0
  126. package/dist/esm/options.js +85 -0
  127. package/dist/esm/package.json +3 -0
  128. package/dist/esm/report.d.ts +64 -0
  129. package/dist/esm/report.js +49 -0
  130. package/dist/esm/resolve-binary.d.ts +44 -0
  131. package/dist/esm/resolve-binary.js +101 -0
  132. package/dist/esm/rollup.d.ts +30 -0
  133. package/dist/esm/rollup.js +54 -0
  134. package/dist/esm/rsbuild.d.ts +29 -0
  135. package/dist/esm/rsbuild.js +42 -0
  136. package/dist/esm/vendor.d.ts +16 -0
  137. package/dist/esm/vendor.js +92 -0
  138. package/dist/esm/vite.d.ts +31 -0
  139. package/dist/esm/vite.js +50 -0
  140. package/package.json +282 -5
@@ -0,0 +1,217 @@
1
+ /** A frontend input may be a file path or a file URL from import.meta.url. */
2
+ export type CloakInput = string | URL;
3
+ /** Optional live injector. Passing this object enables it for the build. */
4
+ export interface LiveInjectorOptions {
5
+ /** Output HTML page relative to each dist root. Defaults to index.html. */
6
+ target?: string;
7
+ /** One or more frontend build directories or HTML pages. */
8
+ cloaks: CloakInput | CloakInput[];
9
+ /** Shortcut to show or hide the frontend. Defaults to Ctrl+E. */
10
+ shortcut?: string;
11
+ /** CSS selector for the decoy region to cover; leave unset to cover the viewport. */
12
+ mount?: string;
13
+ }
14
+ /** One reference rewrite on a vendored file (`[[vendor.rewrite]]`). */
15
+ export interface VendorRewrite {
16
+ /** The text to find. */
17
+ find: string;
18
+ /** Its replacement. `{stamp}` expands to the per-build stamp. */
19
+ to: string;
20
+ /** Fail the build when `find` matches nothing across the input. Default `true`. */
21
+ required?: boolean;
22
+ /** Fail the build unless `find` matches exactly this many times. */
23
+ count?: number;
24
+ }
25
+ /** What a {@link VendorInput} hook learns about one file. */
26
+ export interface VendorFileInfo {
27
+ /** The file's path relative to `from`, with forward slashes. */
28
+ path: string;
29
+ /** The absolute source file. */
30
+ file: string;
31
+ }
32
+ /**
33
+ * One vendored input, the same as a `[[vendor]]` table in the config, plus two
34
+ * optional hooks that run in Node before estrogen sees the file. With either
35
+ * hook set, `from` must be a file or a directory, not a glob.
36
+ */
37
+ export interface VendorInput {
38
+ /** A file, a directory, or (without hooks) a glob, relative to `cwd`. */
39
+ from: string;
40
+ /** The destination under the dist root. */
41
+ to: string;
42
+ /** `'verbatim'` (the default) copies the file; `'obfuscate'` runs it through estrogen. */
43
+ mode?: 'verbatim' | 'obfuscate';
44
+ /** Insert the per-build stamp before each file's extension. Default `false`. */
45
+ stamp?: boolean;
46
+ /**
47
+ * Compile each obfuscated JS file as an ES module. Default `false`: a
48
+ * vendored file's kind comes from its own syntax, and `moduleGlobs` never
49
+ * applies to it.
50
+ */
51
+ module?: boolean;
52
+ /** Reference rewrites with required and count assertions. */
53
+ rewrite?: VendorRewrite[];
54
+ /**
55
+ * Choose each file's destination, relative to `to`. Return a path to place
56
+ * it there, `undefined` to keep its own path, or `null` to leave it out.
57
+ */
58
+ rename?: (path: string, info: VendorFileInfo) => string | null | undefined;
59
+ /**
60
+ * Change a file's contents before estrogen copies it. Return the new
61
+ * contents, or `undefined` to keep them. Runs after `rename`, only for files
62
+ * that are kept.
63
+ */
64
+ transform?: (contents: Buffer, info: VendorFileInfo) => string | Uint8Array | undefined | Promise<string | Uint8Array | undefined>;
65
+ }
66
+ export interface Options {
67
+ /**
68
+ * Directories to rewrite in place. Pass one string or a list. The CLI accepts
69
+ * `estrogen <dir>...`, so a list runs one process over every directory.
70
+ *
71
+ * The plugins fill this in from the build's output directory, so plugin
72
+ * callers leave it unset. A direct {@link obfuscate} call must set it.
73
+ */
74
+ dirs?: string | string[];
75
+ /**
76
+ * Config file for estrogen (`-c`/`--config <file>`). Per-site settings that do
77
+ * not fit a flag live here.
78
+ */
79
+ config?: string;
80
+ /**
81
+ * Canary list file (`--canary <file>`). The list of literals that must not
82
+ * survive verbatim in the output. estrogen fails nonzero if one does.
83
+ */
84
+ canary?: string;
85
+ /**
86
+ * Names file (`--names <file>`). The proxy and store names to rename for this
87
+ * site.
88
+ */
89
+ names?: string;
90
+ /**
91
+ * Source map output directory (`--sourcemap <dir>`). Off by default. When set,
92
+ * estrogen writes maps here, outside the served tree, for private debugging. A
93
+ * map traces the output back to its source, so keep this directory private
94
+ * and never ship it.
95
+ */
96
+ sourcemap?: string;
97
+ /**
98
+ * Seed for the per-file and per-build randomness (`--seed <hex>`). Fixes the
99
+ * output so two runs on one input match. Use it for tests and parity harnesses
100
+ * only. Production builds leave it unset and use real randomness.
101
+ */
102
+ seed?: string;
103
+ /**
104
+ * Worker count (`-j`/`--jobs <n>`). estrogen processes files in parallel; this
105
+ * caps the workers. Unset lets the binary pick.
106
+ */
107
+ jobs?: number;
108
+ /**
109
+ * Check mode (`--check`). Report what estrogen would do and run the canary check
110
+ * without writing changes. Useful in CI to gate a build.
111
+ */
112
+ check?: boolean;
113
+ /**
114
+ * Optimize `.svg` asset files (`--no-optimize-svg` turns it off). On by
115
+ * default: estrogen shrinks each plain image SVG with the SVGO default job set
116
+ * (drops metadata and comments, collapses whitespace, rounds path numbers,
117
+ * removes default attributes) and writes the smaller result. This replaces a
118
+ * site's separate `svgmin` step. A cloak SVG (one with an inline `<script>`)
119
+ * is left for the markup pass. Set this to `false` to keep the SVGs as the
120
+ * bundler wrote them.
121
+ */
122
+ optimizeSvg?: boolean;
123
+ /**
124
+ * Minify `.html` shells (`--no-minify-html` turns it off). On by default:
125
+ * estrogen strips comments and collapses insignificant whitespace before the
126
+ * cloak pass, leaving `<pre>`, `<textarea>`, `<script>` and `<style>` content
127
+ * intact. Set this to `false` to keep the HTML as the bundler wrote it.
128
+ */
129
+ minifyHtml?: boolean;
130
+ /**
131
+ * Minify `.css` stylesheets (`--no-minify-css` turns it off). On by default:
132
+ * estrogen minifies each stylesheet with lightningcss. CSS is not an
133
+ * obfuscation target, so this only shrinks it. Set this to `false` to keep the
134
+ * CSS as the bundler wrote it.
135
+ */
136
+ minifyCss?: boolean;
137
+ /** Inject a selected frontend in a closed shadow overlay after obfuscation. Off by default. */
138
+ injector?: LiveInjectorOptions;
139
+ /**
140
+ * Glob patterns relative to the dist root that identify ES module scripts
141
+ * without import/export syntax. Only set these for files actually loaded as
142
+ * modules. Classic scripts expose top-level var/function on globalThis.
143
+ */
144
+ moduleGlobs?: string[];
145
+ /**
146
+ * Glob patterns relative to the dist root for JS files that stay out of the
147
+ * bytecode VM (`--no-vm-glob`). They take the literal-pool and name passes.
148
+ * Use for code that rebuilds functions from `fn.toString()`, since a VM
149
+ * function's source text is the VM call wrapper.
150
+ */
151
+ noVmGlobs?: string[];
152
+ /**
153
+ * Keep the source text of a VM function the code turns into a string, such
154
+ * as `f.toString()`, `String(f)` or `f + ''`, so code that rebuilds it from
155
+ * its text still runs. On by default. `false` passes `--no-function-source`,
156
+ * and such a function reads as `[native code]`.
157
+ */
158
+ functionSource?: boolean;
159
+ /**
160
+ * Print the warning that lists functions the code turns into strings. On by
161
+ * default. `false` passes `--no-function-source-warning`.
162
+ */
163
+ functionSourceWarning?: boolean;
164
+ /**
165
+ * Files to copy into the dist before obfuscating, as `[[vendor]]` tables in
166
+ * the config are. Setting this runs `estrogen build`, which also vendors the
167
+ * config's own `[[vendor]]` inputs, and adds these after them. See
168
+ * {@link VendorInput} for the `rename` and `transform` hooks.
169
+ */
170
+ vendor?: VendorInput[];
171
+ /**
172
+ * Where `estrogen build` writes the vendor manifest (`--manifest`): relative
173
+ * to each dir, or absolute. `false` writes none (`--no-manifest`), for a
174
+ * dist served as is where the manifest would be public. The default is
175
+ * `estrogen-vendor-manifest.json` under each dir.
176
+ */
177
+ manifest?: string | false;
178
+ /**
179
+ * Emit the VM runtime once as a shared module that each ES module VM chunk
180
+ * imports (`--shared-runtime`), instead of inlining a copy in every chunk.
181
+ * A classic script and a vendored file keep the inline copy.
182
+ */
183
+ sharedRuntime?: boolean;
184
+ /** Quiet output (`--quiet`). Suppresses progress logging. */
185
+ quiet?: boolean;
186
+ /** Verbose output (`-v`/`--verbose`). Logs per-file detail. */
187
+ verbose?: boolean;
188
+ /**
189
+ * Path to the estrogen binary. Overrides the per-platform package resolution.
190
+ * Set it to run a locally built binary or a stub in tests. Normally leave it
191
+ * unset and let the matching `@sysce/estrogen-<os>-<cpu>` package provide it.
192
+ */
193
+ binaryPath?: string;
194
+ /** Working directory for the spawned process. Defaults to `process.cwd()`. */
195
+ cwd?: string;
196
+ /**
197
+ * Extra arguments appended after the flags and before the directories. An
198
+ * escape hatch for flags this type does not model yet. Prefer a typed field
199
+ * when one exists.
200
+ */
201
+ extraArgs?: string[];
202
+ }
203
+ /**
204
+ * Plugin options: {@link Options} without `dirs`, which a plugin takes from the
205
+ * build's output directory. Everything else carries through to estrogen.
206
+ */
207
+ export type PluginOptions = Omit<Options, 'dirs'>;
208
+ /**
209
+ * Normalize {@link Options.dirs} to a list. Returns an empty list when unset.
210
+ */
211
+ export declare function normalizeDirs(dirs: Options['dirs']): string[];
212
+ /**
213
+ * Turn {@link Options} into the estrogen CLI argument vector. The order is flags
214
+ * first, then `extraArgs`, then the directories, matching `estrogen [options]
215
+ * <dir>...`.
216
+ */
217
+ export declare function buildArgs(options: Options): string[];
@@ -0,0 +1,89 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.normalizeDirs = normalizeDirs;
4
+ exports.buildArgs = buildArgs;
5
+ /**
6
+ * Options shared by the programmatic API ({@link obfuscate}) and the bundler
7
+ * plugins. Each field maps to one estrogen CLI flag, so the same object configures
8
+ * a direct spawn and a plugin run.
9
+ *
10
+ * estrogen rewrites a directory that a bundler has already written. It raises the
11
+ * cost of reading that build. It is not secrecy: a decoder key ships in each
12
+ * file, and anyone with devtools can run the code.
13
+ */
14
+ const node_url_1 = require("node:url");
15
+ /**
16
+ * Normalize {@link Options.dirs} to a list. Returns an empty list when unset.
17
+ */
18
+ function normalizeDirs(dirs) {
19
+ if (dirs === undefined)
20
+ return [];
21
+ return Array.isArray(dirs) ? dirs.slice() : [dirs];
22
+ }
23
+ /**
24
+ * Turn {@link Options} into the estrogen CLI argument vector. The order is flags
25
+ * first, then `extraArgs`, then the directories, matching `estrogen [options]
26
+ * <dir>...`.
27
+ */
28
+ function buildArgs(options) {
29
+ const args = [];
30
+ if (options.config !== undefined)
31
+ args.push('--config', options.config);
32
+ if (options.canary !== undefined)
33
+ args.push('--canary', options.canary);
34
+ if (options.names !== undefined)
35
+ args.push('--names', options.names);
36
+ if (options.sourcemap !== undefined)
37
+ args.push('--sourcemap', options.sourcemap);
38
+ if (options.seed !== undefined)
39
+ args.push('--seed', options.seed);
40
+ if (options.jobs !== undefined)
41
+ args.push('--jobs', String(options.jobs));
42
+ if (options.check)
43
+ args.push('--check');
44
+ if (options.optimizeSvg === false)
45
+ args.push('--no-optimize-svg');
46
+ if (options.minifyHtml === false)
47
+ args.push('--no-minify-html');
48
+ if (options.minifyCss === false)
49
+ args.push('--no-minify-css');
50
+ if (options.moduleGlobs)
51
+ for (const pattern of options.moduleGlobs)
52
+ args.push('--module-glob', pattern);
53
+ if (options.noVmGlobs)
54
+ for (const pattern of options.noVmGlobs)
55
+ args.push('--no-vm-glob', pattern);
56
+ if (options.manifest === false)
57
+ args.push('--no-manifest');
58
+ else if (options.manifest !== undefined)
59
+ args.push('--manifest', options.manifest);
60
+ if (options.sharedRuntime)
61
+ args.push('--shared-runtime');
62
+ if (options.functionSource === false)
63
+ args.push('--no-function-source');
64
+ if (options.functionSourceWarning === false)
65
+ args.push('--no-function-source-warning');
66
+ if (options.injector) {
67
+ args.push('--cloak-target', options.injector.target ?? 'index.html');
68
+ const inputs = Array.isArray(options.injector.cloaks)
69
+ ? options.injector.cloaks
70
+ : [options.injector.cloaks];
71
+ if (inputs.length === 0)
72
+ throw new Error('estrogen: injector.cloaks must contain a frontend');
73
+ for (const input of inputs) {
74
+ args.push('--cloaks', input instanceof URL ? (0, node_url_1.fileURLToPath)(input) : input);
75
+ }
76
+ if (options.injector.shortcut)
77
+ args.push('--cloak-shortcut', options.injector.shortcut);
78
+ if (options.injector.mount)
79
+ args.push('--cloak-mount', options.injector.mount);
80
+ }
81
+ if (options.quiet)
82
+ args.push('--quiet');
83
+ if (options.verbose)
84
+ args.push('--verbose');
85
+ if (options.extraArgs)
86
+ args.push(...options.extraArgs);
87
+ args.push(...normalizeDirs(options.dirs));
88
+ return args;
89
+ }
@@ -0,0 +1,3 @@
1
+ {
2
+ "type": "commonjs"
3
+ }
@@ -0,0 +1,64 @@
1
+ /**
2
+ * The result of an estrogen run, resolved by {@link obfuscate}. estrogen exits 0 on
3
+ * success and nonzero on failure, so a resolved report always has
4
+ * `exitCode === 0`; a failed run rejects with a {@link EstrogenError} instead.
5
+ */
6
+ export interface Report {
7
+ /** True when estrogen exited 0. */
8
+ ok: boolean;
9
+ /** The process exit code. 0 on success. */
10
+ exitCode: number;
11
+ /** The directories estrogen was asked to rewrite. */
12
+ dirs: string[];
13
+ /** The binary that ran. */
14
+ binaryPath: string;
15
+ /** The argument vector passed to the binary. */
16
+ args: string[];
17
+ /** Captured standard output. */
18
+ stdout: string;
19
+ /** Captured standard error. */
20
+ stderr: string;
21
+ /** Wall-clock run time in milliseconds. */
22
+ durationMs: number;
23
+ /**
24
+ * The function source warning from stderr, when the build turns a VM
25
+ * function into a string. {@link obfuscate} also writes it to
26
+ * `process.stderr`. See {@link Options.functionSourceWarning}.
27
+ */
28
+ warning?: string;
29
+ /**
30
+ * With {@link Options.vendor} set, each dir's vendor manifest, read from
31
+ * {@link Options.manifest} (default `estrogen-vendor-manifest.json`), in
32
+ * `dirs` order: the build stamp and the map from each vendored file's public
33
+ * path to its served path. An entry is undefined when that dir has no
34
+ * manifest there. Absent when `manifest` is `false`.
35
+ */
36
+ manifests?: unknown[];
37
+ /**
38
+ * Structured detail, when the binary prints a JSON object on stdout. The
39
+ * shape is the binary's own and may grow; read it defensively.
40
+ */
41
+ details?: unknown;
42
+ }
43
+ /**
44
+ * Thrown when estrogen exits nonzero or fails to launch. Carries the partial
45
+ * {@link Report} so a caller can read the exit code, stderr, and the command
46
+ * that ran.
47
+ */
48
+ export declare class EstrogenError extends Error {
49
+ /** The report captured up to the failure. */
50
+ readonly report: Report;
51
+ constructor(message: string, report: Report);
52
+ }
53
+ /**
54
+ * Parse a structured detail object out of estrogen's stdout. estrogen may print a
55
+ * JSON object as its last non-empty line. Return it when present, otherwise
56
+ * undefined. A line that is not JSON is ignored, not an error.
57
+ */
58
+ export declare function parseDetails(stdout: string): unknown;
59
+ /**
60
+ * Pull the function source warning out of estrogen's stderr: the block from
61
+ * its `⚠ estrogen:` headline through the line that says how to hide it.
62
+ * Returns undefined when stderr has no such block.
63
+ */
64
+ export declare function functionSourceWarning(stderr: string): string | undefined;
@@ -0,0 +1,55 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.EstrogenError = void 0;
4
+ exports.parseDetails = parseDetails;
5
+ exports.functionSourceWarning = functionSourceWarning;
6
+ /**
7
+ * Thrown when estrogen exits nonzero or fails to launch. Carries the partial
8
+ * {@link Report} so a caller can read the exit code, stderr, and the command
9
+ * that ran.
10
+ */
11
+ class EstrogenError extends Error {
12
+ /** The report captured up to the failure. */
13
+ report;
14
+ constructor(message, report) {
15
+ super(message);
16
+ this.name = 'EstrogenError';
17
+ this.report = report;
18
+ }
19
+ }
20
+ exports.EstrogenError = EstrogenError;
21
+ /**
22
+ * Parse a structured detail object out of estrogen's stdout. estrogen may print a
23
+ * JSON object as its last non-empty line. Return it when present, otherwise
24
+ * undefined. A line that is not JSON is ignored, not an error.
25
+ */
26
+ function parseDetails(stdout) {
27
+ const lines = stdout.split('\n');
28
+ for (let i = lines.length - 1; i >= 0; i -= 1) {
29
+ const line = lines[i].trim();
30
+ if (line === '')
31
+ continue;
32
+ if (line[0] !== '{')
33
+ return undefined;
34
+ try {
35
+ return JSON.parse(line);
36
+ }
37
+ catch {
38
+ return undefined;
39
+ }
40
+ }
41
+ return undefined;
42
+ }
43
+ /**
44
+ * Pull the function source warning out of estrogen's stderr: the block from
45
+ * its `⚠ estrogen:` headline through the line that says how to hide it.
46
+ * Returns undefined when stderr has no such block.
47
+ */
48
+ function functionSourceWarning(stderr) {
49
+ const lines = stderr.split(/(?<=\n)/);
50
+ const start = lines.findIndex((line) => line.includes('⚠ estrogen:'));
51
+ if (start === -1)
52
+ return undefined;
53
+ const end = lines.findIndex((line, index) => index > start && line.includes('--no-function-source-warning'));
54
+ return lines.slice(start, end === -1 ? undefined : end + 1).join('');
55
+ }
@@ -0,0 +1,44 @@
1
+ /**
2
+ * The npm name of the per-platform binary package for each supported target.
3
+ * Keyed by `<os>-<cpu>` where os is `process.platform` and cpu is
4
+ * `process.arch`.
5
+ */
6
+ export declare const PLATFORM_PACKAGES: Record<string, string>;
7
+ /**
8
+ * The `<os>-<cpu>` target key for a platform and arch, or null when the pair is
9
+ * not a supported target. Defaults to the running process.
10
+ */
11
+ export declare function targetKey(platform?: string, arch?: string): string | null;
12
+ /**
13
+ * The npm package name that carries the binary for a platform and arch, or null
14
+ * when unsupported. Defaults to the running process.
15
+ */
16
+ export declare function platformPackageName(platform?: string, arch?: string): string | null;
17
+ /**
18
+ * The binary's path inside its package. Windows carries `bin/estrogen.exe`, every
19
+ * other target `bin/estrogen`.
20
+ */
21
+ export declare function binSubpath(platform?: string): string;
22
+ /**
23
+ * Thrown when no per-platform binary package resolves for the running system.
24
+ * The message names the target and the package npm would have installed.
25
+ */
26
+ export declare class MissingBinaryError extends Error {
27
+ constructor(message: string);
28
+ }
29
+ /**
30
+ * Locate the estrogen binary for the running platform.
31
+ *
32
+ * Resolution order:
33
+ * 1. `override`, when given, is returned as is (the `binaryPath` option and the
34
+ * bin launcher's own override use this).
35
+ * 2. Otherwise the matching `@sysce/estrogen-<os>-<cpu>` package is resolved
36
+ * through `req.resolve` and the binary path inside it is returned.
37
+ *
38
+ * `req` is a `require` function anchored in the launcher package, so resolution
39
+ * finds the optional dependency whether npm installed it beside the launcher or
40
+ * hoisted it to a parent `node_modules`. Throws {@link MissingBinaryError} when
41
+ * the platform is unsupported, the package is not installed, or the package
42
+ * has no binary in it.
43
+ */
44
+ export declare function resolveBinaryPath(req: NodeRequire, override?: string): string;
@@ -0,0 +1,109 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.MissingBinaryError = exports.PLATFORM_PACKAGES = void 0;
4
+ exports.targetKey = targetKey;
5
+ exports.platformPackageName = platformPackageName;
6
+ exports.binSubpath = binSubpath;
7
+ exports.resolveBinaryPath = resolveBinaryPath;
8
+ const node_fs_1 = require("node:fs");
9
+ const node_path_1 = require("node:path");
10
+ const node_process_1 = require("node:process");
11
+ /**
12
+ * The npm name of the per-platform binary package for each supported target.
13
+ * Keyed by `<os>-<cpu>` where os is `process.platform` and cpu is
14
+ * `process.arch`.
15
+ */
16
+ exports.PLATFORM_PACKAGES = {
17
+ 'linux-x64': '@sysce/estrogen-linux-x64',
18
+ 'linux-arm64': '@sysce/estrogen-linux-arm64',
19
+ 'darwin-x64': '@sysce/estrogen-darwin-x64',
20
+ 'darwin-arm64': '@sysce/estrogen-darwin-arm64',
21
+ 'win32-x64': '@sysce/estrogen-win32-x64',
22
+ };
23
+ /**
24
+ * The `<os>-<cpu>` target key for a platform and arch, or null when the pair is
25
+ * not a supported target. Defaults to the running process.
26
+ */
27
+ function targetKey(platform = node_process_1.platform, arch = node_process_1.arch) {
28
+ const key = `${platform}-${arch}`;
29
+ return key in exports.PLATFORM_PACKAGES ? key : null;
30
+ }
31
+ /**
32
+ * The npm package name that carries the binary for a platform and arch, or null
33
+ * when unsupported. Defaults to the running process.
34
+ */
35
+ function platformPackageName(platform = node_process_1.platform, arch = node_process_1.arch) {
36
+ const key = targetKey(platform, arch);
37
+ return key === null ? null : exports.PLATFORM_PACKAGES[key];
38
+ }
39
+ /**
40
+ * The binary's path inside its package. Windows carries `bin/estrogen.exe`, every
41
+ * other target `bin/estrogen`.
42
+ */
43
+ function binSubpath(platform = node_process_1.platform) {
44
+ return platform === 'win32'
45
+ ? (0, node_path_1.join)('bin', 'estrogen.exe')
46
+ : (0, node_path_1.join)('bin', 'estrogen');
47
+ }
48
+ /**
49
+ * Thrown when no per-platform binary package resolves for the running system.
50
+ * The message names the target and the package npm would have installed.
51
+ */
52
+ class MissingBinaryError extends Error {
53
+ constructor(message) {
54
+ super(message);
55
+ this.name = 'MissingBinaryError';
56
+ }
57
+ }
58
+ exports.MissingBinaryError = MissingBinaryError;
59
+ /**
60
+ * The tail of every {@link MissingBinaryError} message: the two ways to run a
61
+ * binary that did not come from a per-platform package.
62
+ */
63
+ const OVERRIDE_HINT = 'To use a binary built elsewhere, set ESTROGEN_BINARY for the estrogen ' +
64
+ 'command, or pass the binaryPath option to obfuscate() and the plugins.';
65
+ /**
66
+ * Locate the estrogen binary for the running platform.
67
+ *
68
+ * Resolution order:
69
+ * 1. `override`, when given, is returned as is (the `binaryPath` option and the
70
+ * bin launcher's own override use this).
71
+ * 2. Otherwise the matching `@sysce/estrogen-<os>-<cpu>` package is resolved
72
+ * through `req.resolve` and the binary path inside it is returned.
73
+ *
74
+ * `req` is a `require` function anchored in the launcher package, so resolution
75
+ * finds the optional dependency whether npm installed it beside the launcher or
76
+ * hoisted it to a parent `node_modules`. Throws {@link MissingBinaryError} when
77
+ * the platform is unsupported, the package is not installed, or the package
78
+ * has no binary in it.
79
+ */
80
+ function resolveBinaryPath(req, override) {
81
+ if (override !== undefined && override !== '')
82
+ return override;
83
+ const key = targetKey();
84
+ const pkg = platformPackageName();
85
+ if (key === null || pkg === null) {
86
+ const supported = Object.keys(exports.PLATFORM_PACKAGES).join(', ');
87
+ throw new MissingBinaryError(`estrogen has no prebuilt binary for ${node_process_1.platform}-${node_process_1.arch}. ` +
88
+ `Supported targets: ${supported}. ${OVERRIDE_HINT}`);
89
+ }
90
+ let pkgDir;
91
+ try {
92
+ pkgDir = (0, node_path_1.dirname)(req.resolve(`${pkg}/package.json`));
93
+ }
94
+ catch {
95
+ throw new MissingBinaryError(`estrogen could not find its binary package ${pkg} for ${key}. ` +
96
+ `npm installs it as an optional dependency of @sysce/estrogen, so ` +
97
+ `it is missing after an install with --omit=optional or ` +
98
+ `--no-optional, or when the lockfile was written on another ` +
99
+ `platform. Run "npm install ${pkg}" with the same version as ` +
100
+ `@sysce/estrogen, or reinstall without --omit=optional. ` +
101
+ OVERRIDE_HINT);
102
+ }
103
+ const binary = (0, node_path_1.join)(pkgDir, binSubpath());
104
+ if (!(0, node_fs_1.existsSync)(binary)) {
105
+ throw new MissingBinaryError(`estrogen found ${pkg} at ${pkgDir}, but it has no binary at ` +
106
+ `${binary}. Reinstall ${pkg}. ${OVERRIDE_HINT}`);
107
+ }
108
+ return binary;
109
+ }
@@ -0,0 +1,30 @@
1
+ import type { Plugin } from 'rollup';
2
+ import type { PluginOptions } from './options.js';
3
+ /**
4
+ * Rollup plugin that runs estrogen over the output directory once Rollup has
5
+ * written it.
6
+ *
7
+ * It finds the directory from the write's `output.dir`, or from the directory of
8
+ * `output.file` for a single-file build, resolved against the current working
9
+ * directory. It runs in `writeBundle`, after the files are on disk. An estrogen
10
+ * failure is thrown so the build fails.
11
+ *
12
+ * estrogen rewrites that directory in place and raises the cost of reading it.
13
+ * It is not secrecy: a decoder key ships in each file.
14
+ *
15
+ * @example
16
+ * ```ts
17
+ * import { pluginEstrogen } from '@sysce/estrogen/rollup';
18
+ *
19
+ * export default {
20
+ * input: 'src/app.js',
21
+ * output: { dir: 'dist', format: 'es' },
22
+ * plugins: [pluginEstrogen({ canary: 'canary-list.json' })],
23
+ * };
24
+ * ```
25
+ *
26
+ * @param options estrogen options. `dirs` is ignored; the output directory comes
27
+ * from the Rollup output config.
28
+ */
29
+ export declare function pluginEstrogen(options?: PluginOptions): Plugin;
30
+ export default pluginEstrogen;
@@ -0,0 +1,57 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.pluginEstrogen = pluginEstrogen;
4
+ const node_path_1 = require("node:path");
5
+ const obfuscate_js_1 = require("./obfuscate.js");
6
+ /**
7
+ * Rollup plugin that runs estrogen over the output directory once Rollup has
8
+ * written it.
9
+ *
10
+ * It finds the directory from the write's `output.dir`, or from the directory of
11
+ * `output.file` for a single-file build, resolved against the current working
12
+ * directory. It runs in `writeBundle`, after the files are on disk. An estrogen
13
+ * failure is thrown so the build fails.
14
+ *
15
+ * estrogen rewrites that directory in place and raises the cost of reading it.
16
+ * It is not secrecy: a decoder key ships in each file.
17
+ *
18
+ * @example
19
+ * ```ts
20
+ * import { pluginEstrogen } from '@sysce/estrogen/rollup';
21
+ *
22
+ * export default {
23
+ * input: 'src/app.js',
24
+ * output: { dir: 'dist', format: 'es' },
25
+ * plugins: [pluginEstrogen({ canary: 'canary-list.json' })],
26
+ * };
27
+ * ```
28
+ *
29
+ * @param options estrogen options. `dirs` is ignored; the output directory comes
30
+ * from the Rollup output config.
31
+ */
32
+ function pluginEstrogen(options = {}) {
33
+ return {
34
+ name: '@sysce/estrogen',
35
+ async writeBundle(output) {
36
+ const outDir = resolveOutputDir(output);
37
+ if (outDir === null) {
38
+ throw new Error('estrogen could not find the Rollup output directory. ' +
39
+ 'Set output.dir or output.file so estrogen knows what to rewrite.');
40
+ }
41
+ await (0, obfuscate_js_1.obfuscate)({ ...options, dirs: outDir });
42
+ },
43
+ };
44
+ }
45
+ /**
46
+ * Resolve the absolute output directory from a Rollup write. Prefers `dir`,
47
+ * falls back to the directory of `file`, and resolves relative paths against the
48
+ * working directory. Returns null when neither is set.
49
+ */
50
+ function resolveOutputDir(output) {
51
+ if (output.dir !== undefined)
52
+ return (0, node_path_1.resolve)(process.cwd(), output.dir);
53
+ if (output.file !== undefined)
54
+ return (0, node_path_1.resolve)(process.cwd(), (0, node_path_1.dirname)(output.file));
55
+ return null;
56
+ }
57
+ exports.default = pluginEstrogen;