@sysce/estrogen 0.0.0-stage → 0.5.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/LICENSE +15 -0
- package/README.md +235 -2
- package/bin/estrogen.js +38 -0
- package/dist/cjs/astro.d.ts +31 -0
- package/dist/cjs/astro.js +45 -0
- package/dist/cjs/cloak/astro/HolyLink.astro +36 -0
- package/dist/cjs/cloak/astro/HolyLink.astro.d.ts +14 -0
- package/dist/cjs/cloak/astro/HolyText.astro +31 -0
- package/dist/cjs/cloak/astro/HolyText.astro.d.ts +12 -0
- package/dist/cjs/cloak/astro.d.ts +2 -0
- package/dist/cjs/cloak/astro.js +10 -0
- package/dist/cjs/cloak/base64.d.ts +2 -0
- package/dist/cjs/cloak/base64.js +20 -0
- package/dist/cjs/cloak/crypto.d.ts +16 -0
- package/dist/cjs/cloak/crypto.js +40 -0
- package/dist/cjs/cloak/decrypt.d.ts +23 -0
- package/dist/cjs/cloak/decrypt.js +144 -0
- package/dist/cjs/cloak/elements.d.ts +45 -0
- package/dist/cjs/cloak/elements.js +195 -0
- package/dist/cjs/cloak/index.d.ts +10 -0
- package/dist/cjs/cloak/index.js +41 -0
- package/dist/cjs/cloak/preact.d.ts +10 -0
- package/dist/cjs/cloak/preact.js +19 -0
- package/dist/cjs/cloak/props.d.ts +18 -0
- package/dist/cjs/cloak/props.js +27 -0
- package/dist/cjs/cloak/react-extra.d.ts +327 -0
- package/dist/cjs/cloak/react-extra.js +169 -0
- package/dist/cjs/cloak/react.d.ts +28 -0
- package/dist/cjs/cloak/react.js +159 -0
- package/dist/cjs/cloak/render.d.ts +37 -0
- package/dist/cjs/cloak/render.js +54 -0
- package/dist/cjs/cloak/server.d.ts +35 -0
- package/dist/cjs/cloak/server.js +87 -0
- package/dist/cjs/cloak/server.node.d.ts +15 -0
- package/dist/cjs/cloak/server.node.js +36 -0
- package/dist/cjs/cloak/solid.d.ts +13 -0
- package/dist/cjs/cloak/solid.js +55 -0
- package/dist/cjs/cloak/span.d.ts +8 -0
- package/dist/cjs/cloak/span.js +123 -0
- package/dist/cjs/cloak/strings.d.ts +18 -0
- package/dist/cjs/cloak/strings.js +53 -0
- package/dist/cjs/cloak/svelte/HolyLink.svelte +12 -0
- package/dist/cjs/cloak/svelte/HolyLink.svelte.d.ts +5 -0
- package/dist/cjs/cloak/svelte/HolyText.svelte +13 -0
- package/dist/cjs/cloak/svelte/HolyText.svelte.d.ts +5 -0
- package/dist/cjs/cloak/svelte.d.ts +2 -0
- package/dist/cjs/cloak/svelte.js +10 -0
- package/dist/cjs/cloak/vue.d.ts +36 -0
- package/dist/cjs/cloak/vue.js +34 -0
- package/dist/cjs/esbuild.d.ts +33 -0
- package/dist/cjs/esbuild.js +79 -0
- package/dist/cjs/index.d.ts +24 -0
- package/dist/cjs/index.js +35 -0
- package/dist/cjs/node-require.js +7 -0
- package/dist/cjs/obfuscate.d.ts +23 -0
- package/dist/cjs/obfuscate.js +154 -0
- package/dist/cjs/options.d.ts +264 -0
- package/dist/cjs/options.js +105 -0
- package/dist/cjs/package.json +3 -0
- package/dist/cjs/report.d.ts +74 -0
- package/dist/cjs/report.js +55 -0
- package/dist/cjs/resolve-binary.d.ts +46 -0
- package/dist/cjs/resolve-binary.js +114 -0
- package/dist/cjs/rollup.d.ts +30 -0
- package/dist/cjs/rollup.js +57 -0
- package/dist/cjs/rsbuild.d.ts +29 -0
- package/dist/cjs/rsbuild.js +45 -0
- package/dist/cjs/vendor.d.ts +16 -0
- package/dist/cjs/vendor.js +95 -0
- package/dist/cjs/vite.d.ts +31 -0
- package/dist/cjs/vite.js +53 -0
- package/dist/esm/astro.d.ts +31 -0
- package/dist/esm/astro.js +42 -0
- package/dist/esm/cloak/astro/HolyLink.astro +36 -0
- package/dist/esm/cloak/astro/HolyLink.astro.d.ts +14 -0
- package/dist/esm/cloak/astro/HolyText.astro +31 -0
- package/dist/esm/cloak/astro/HolyText.astro.d.ts +12 -0
- package/dist/esm/cloak/astro.d.ts +2 -0
- package/dist/esm/cloak/astro.js +2 -0
- package/dist/esm/cloak/base64.d.ts +2 -0
- package/dist/esm/cloak/base64.js +16 -0
- package/dist/esm/cloak/crypto.d.ts +16 -0
- package/dist/esm/cloak/crypto.js +36 -0
- package/dist/esm/cloak/decrypt.d.ts +23 -0
- package/dist/esm/cloak/decrypt.js +136 -0
- package/dist/esm/cloak/elements.d.ts +45 -0
- package/dist/esm/cloak/elements.js +189 -0
- package/dist/esm/cloak/index.d.ts +10 -0
- package/dist/esm/cloak/index.js +13 -0
- package/dist/esm/cloak/preact.d.ts +10 -0
- package/dist/esm/cloak/preact.js +15 -0
- package/dist/esm/cloak/props.d.ts +18 -0
- package/dist/esm/cloak/props.js +23 -0
- package/dist/esm/cloak/react-extra.d.ts +327 -0
- package/dist/esm/cloak/react-extra.js +161 -0
- package/dist/esm/cloak/react.d.ts +28 -0
- package/dist/esm/cloak/react.js +147 -0
- package/dist/esm/cloak/render.d.ts +37 -0
- package/dist/esm/cloak/render.js +48 -0
- package/dist/esm/cloak/server.d.ts +35 -0
- package/dist/esm/cloak/server.js +75 -0
- package/dist/esm/cloak/server.node.d.ts +15 -0
- package/dist/esm/cloak/server.node.js +22 -0
- package/dist/esm/cloak/solid.d.ts +13 -0
- package/dist/esm/cloak/solid.js +51 -0
- package/dist/esm/cloak/span.d.ts +8 -0
- package/dist/esm/cloak/span.js +117 -0
- package/dist/esm/cloak/strings.d.ts +18 -0
- package/dist/esm/cloak/strings.js +47 -0
- package/dist/esm/cloak/svelte/HolyLink.svelte +12 -0
- package/dist/esm/cloak/svelte/HolyLink.svelte.d.ts +5 -0
- package/dist/esm/cloak/svelte/HolyText.svelte +13 -0
- package/dist/esm/cloak/svelte/HolyText.svelte.d.ts +5 -0
- package/dist/esm/cloak/svelte.d.ts +2 -0
- package/dist/esm/cloak/svelte.js +2 -0
- package/dist/esm/cloak/vue.d.ts +36 -0
- package/dist/esm/cloak/vue.js +31 -0
- package/dist/esm/esbuild.d.ts +33 -0
- package/dist/esm/esbuild.js +76 -0
- package/dist/esm/index.d.ts +24 -0
- package/dist/esm/index.js +22 -0
- package/dist/esm/node-require.js +8 -0
- package/dist/esm/obfuscate.d.ts +23 -0
- package/dist/esm/obfuscate.js +151 -0
- package/dist/esm/options.d.ts +264 -0
- package/dist/esm/options.js +101 -0
- package/dist/esm/package.json +3 -0
- package/dist/esm/report.d.ts +74 -0
- package/dist/esm/report.js +49 -0
- package/dist/esm/resolve-binary.d.ts +46 -0
- package/dist/esm/resolve-binary.js +106 -0
- package/dist/esm/rollup.d.ts +30 -0
- package/dist/esm/rollup.js +54 -0
- package/dist/esm/rsbuild.d.ts +29 -0
- package/dist/esm/rsbuild.js +42 -0
- package/dist/esm/vendor.d.ts +16 -0
- package/dist/esm/vendor.js +92 -0
- package/dist/esm/vite.d.ts +31 -0
- package/dist/esm/vite.js +50 -0
- package/package.json +283 -5
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import { dirname, resolve as resolvePath } from 'node:path';
|
|
2
|
+
import { obfuscate } from './obfuscate.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 function pluginEstrogen(options = {}) {
|
|
30
|
+
return {
|
|
31
|
+
name: '@sysce/estrogen',
|
|
32
|
+
async writeBundle(output) {
|
|
33
|
+
const outDir = resolveOutputDir(output);
|
|
34
|
+
if (outDir === null) {
|
|
35
|
+
throw new Error('estrogen could not find the Rollup output directory. ' +
|
|
36
|
+
'Set output.dir or output.file so estrogen knows what to rewrite.');
|
|
37
|
+
}
|
|
38
|
+
await obfuscate({ ...options, dirs: outDir });
|
|
39
|
+
},
|
|
40
|
+
};
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* Resolve the absolute output directory from a Rollup write. Prefers `dir`,
|
|
44
|
+
* falls back to the directory of `file`, and resolves relative paths against the
|
|
45
|
+
* working directory. Returns null when neither is set.
|
|
46
|
+
*/
|
|
47
|
+
function resolveOutputDir(output) {
|
|
48
|
+
if (output.dir !== undefined)
|
|
49
|
+
return resolvePath(process.cwd(), output.dir);
|
|
50
|
+
if (output.file !== undefined)
|
|
51
|
+
return resolvePath(process.cwd(), dirname(output.file));
|
|
52
|
+
return null;
|
|
53
|
+
}
|
|
54
|
+
export default pluginEstrogen;
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import type { RsbuildPlugin } from '@rsbuild/core';
|
|
2
|
+
import type { PluginOptions } from './options.js';
|
|
3
|
+
/**
|
|
4
|
+
* Rsbuild plugin that runs estrogen over the resolved dist directory after the
|
|
5
|
+
* build finishes.
|
|
6
|
+
*
|
|
7
|
+
* It reads the dist path from the Rsbuild context (`api.context.distPath`),
|
|
8
|
+
* which is the absolute output directory Rsbuild resolved for the build, and
|
|
9
|
+
* runs estrogen in `onAfterBuild`, once the files are written. An estrogen failure is
|
|
10
|
+
* rethrown so the build fails.
|
|
11
|
+
*
|
|
12
|
+
* estrogen rewrites that directory in place and raises the cost of reading it. It
|
|
13
|
+
* is not secrecy: a decoder key ships in each file.
|
|
14
|
+
*
|
|
15
|
+
* @example
|
|
16
|
+
* ```ts
|
|
17
|
+
* import { defineConfig } from '@rsbuild/core';
|
|
18
|
+
* import { pluginEstrogen } from '@sysce/estrogen/rsbuild';
|
|
19
|
+
*
|
|
20
|
+
* export default defineConfig({
|
|
21
|
+
* plugins: [pluginEstrogen({ canary: 'canary-list.json' })],
|
|
22
|
+
* });
|
|
23
|
+
* ```
|
|
24
|
+
*
|
|
25
|
+
* @param options estrogen options. `dirs` is ignored; the dist path comes from the
|
|
26
|
+
* Rsbuild context.
|
|
27
|
+
*/
|
|
28
|
+
export declare function pluginEstrogen(options?: PluginOptions): RsbuildPlugin;
|
|
29
|
+
export default pluginEstrogen;
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { obfuscate } from './obfuscate.js';
|
|
2
|
+
/**
|
|
3
|
+
* Rsbuild plugin that runs estrogen over the resolved dist directory after the
|
|
4
|
+
* build finishes.
|
|
5
|
+
*
|
|
6
|
+
* It reads the dist path from the Rsbuild context (`api.context.distPath`),
|
|
7
|
+
* which is the absolute output directory Rsbuild resolved for the build, and
|
|
8
|
+
* runs estrogen in `onAfterBuild`, once the files are written. An estrogen failure is
|
|
9
|
+
* rethrown so the build fails.
|
|
10
|
+
*
|
|
11
|
+
* estrogen rewrites that directory in place and raises the cost of reading it. It
|
|
12
|
+
* is not secrecy: a decoder key ships in each file.
|
|
13
|
+
*
|
|
14
|
+
* @example
|
|
15
|
+
* ```ts
|
|
16
|
+
* import { defineConfig } from '@rsbuild/core';
|
|
17
|
+
* import { pluginEstrogen } from '@sysce/estrogen/rsbuild';
|
|
18
|
+
*
|
|
19
|
+
* export default defineConfig({
|
|
20
|
+
* plugins: [pluginEstrogen({ canary: 'canary-list.json' })],
|
|
21
|
+
* });
|
|
22
|
+
* ```
|
|
23
|
+
*
|
|
24
|
+
* @param options estrogen options. `dirs` is ignored; the dist path comes from the
|
|
25
|
+
* Rsbuild context.
|
|
26
|
+
*/
|
|
27
|
+
export function pluginEstrogen(options = {}) {
|
|
28
|
+
return {
|
|
29
|
+
name: '@sysce/estrogen',
|
|
30
|
+
setup(api) {
|
|
31
|
+
api.onAfterBuild(async () => {
|
|
32
|
+
const distPath = api.context.distPath;
|
|
33
|
+
if (!distPath) {
|
|
34
|
+
throw new Error('estrogen could not find the Rsbuild dist path. ' +
|
|
35
|
+
'Set output.distPath.root so estrogen knows what to rewrite.');
|
|
36
|
+
}
|
|
37
|
+
await obfuscate({ ...options, dirs: distPath });
|
|
38
|
+
});
|
|
39
|
+
},
|
|
40
|
+
};
|
|
41
|
+
}
|
|
42
|
+
export default pluginEstrogen;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { VendorInput } from './options.js';
|
|
2
|
+
/** The vendor inputs written for `--vendor-file`, and how to remove them. */
|
|
3
|
+
export interface StagedVendor {
|
|
4
|
+
/** The JSON file to pass as `--vendor-file`. */
|
|
5
|
+
vendorFile: string;
|
|
6
|
+
/** Remove the staging directory and everything in it. */
|
|
7
|
+
cleanup: () => Promise<void>;
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* Write the vendor inputs to a JSON file for `--vendor-file`. An input with a
|
|
11
|
+
* `rename` or `transform` hook is staged first: each kept file is written,
|
|
12
|
+
* renamed and transformed, into a temporary directory, and the input points
|
|
13
|
+
* there instead. An input without hooks passes through with `from` resolved
|
|
14
|
+
* against `cwd`.
|
|
15
|
+
*/
|
|
16
|
+
export declare function stageVendor(inputs: VendorInput[], cwd: string): Promise<StagedVendor>;
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
import { mkdir, mkdtemp, readdir, readFile, rm, stat, writeFile, } from 'node:fs/promises';
|
|
2
|
+
import { tmpdir } from 'node:os';
|
|
3
|
+
import { dirname, join, relative, resolve, sep } from 'node:path';
|
|
4
|
+
/** Characters that make a `from` a glob, as the binary reads it. */
|
|
5
|
+
const GLOB = /[*?[\]{}]/;
|
|
6
|
+
/** Every file under `dir`, as forward-slash paths relative to it, sorted. */
|
|
7
|
+
async function walk(dir, base = dir) {
|
|
8
|
+
const out = [];
|
|
9
|
+
const entries = await readdir(dir, { withFileTypes: true });
|
|
10
|
+
entries.sort((a, b) => (a.name < b.name ? -1 : a.name > b.name ? 1 : 0));
|
|
11
|
+
for (const entry of entries) {
|
|
12
|
+
const full = join(dir, entry.name);
|
|
13
|
+
if (entry.isDirectory())
|
|
14
|
+
out.push(...(await walk(full, base)));
|
|
15
|
+
else if (entry.isFile())
|
|
16
|
+
out.push(relative(base, full).split(sep).join('/'));
|
|
17
|
+
}
|
|
18
|
+
return out;
|
|
19
|
+
}
|
|
20
|
+
/** A destination from `rename` must stay inside `to`. */
|
|
21
|
+
function checkDestination(input, path, dest) {
|
|
22
|
+
const parts = dest.split('/');
|
|
23
|
+
if (dest === '' || dest.startsWith('/') || parts.includes('..'))
|
|
24
|
+
throw new Error(`estrogen: vendor rename for ${input.from}: ${path} -> ${JSON.stringify(dest)} leaves \`to\``);
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Write the vendor inputs to a JSON file for `--vendor-file`. An input with a
|
|
28
|
+
* `rename` or `transform` hook is staged first: each kept file is written,
|
|
29
|
+
* renamed and transformed, into a temporary directory, and the input points
|
|
30
|
+
* there instead. An input without hooks passes through with `from` resolved
|
|
31
|
+
* against `cwd`.
|
|
32
|
+
*/
|
|
33
|
+
export async function stageVendor(inputs, cwd) {
|
|
34
|
+
const root = await mkdtemp(join(tmpdir(), 'estrogen-vendor-'));
|
|
35
|
+
const cleanup = () => rm(root, { recursive: true, force: true });
|
|
36
|
+
try {
|
|
37
|
+
const tables = [];
|
|
38
|
+
for (const [index, input] of inputs.entries()) {
|
|
39
|
+
const from = resolve(cwd, input.from);
|
|
40
|
+
const table = {
|
|
41
|
+
from,
|
|
42
|
+
to: input.to,
|
|
43
|
+
mode: input.mode ?? 'verbatim',
|
|
44
|
+
stamp: input.stamp ?? false,
|
|
45
|
+
module: input.module ?? false,
|
|
46
|
+
rewrite: input.rewrite ?? [],
|
|
47
|
+
};
|
|
48
|
+
if (input.rename || input.transform) {
|
|
49
|
+
if (GLOB.test(input.from))
|
|
50
|
+
throw new Error(`estrogen: vendor ${input.from}: rename and transform need a file or a directory, not a glob`);
|
|
51
|
+
const staged = join(root, String(index));
|
|
52
|
+
const isDir = (await stat(from)).isDirectory();
|
|
53
|
+
const files = isDir ? await walk(from) : [from.split(sep).pop()];
|
|
54
|
+
let kept = 0;
|
|
55
|
+
let last = staged;
|
|
56
|
+
for (const path of files) {
|
|
57
|
+
const info = {
|
|
58
|
+
path,
|
|
59
|
+
file: isDir ? join(from, ...path.split('/')) : from,
|
|
60
|
+
};
|
|
61
|
+
const renamed = input.rename?.(path, info);
|
|
62
|
+
if (renamed === null)
|
|
63
|
+
continue;
|
|
64
|
+
const dest = renamed ?? path;
|
|
65
|
+
checkDestination(input, path, dest);
|
|
66
|
+
const contents = await readFile(info.file);
|
|
67
|
+
const changed = await input.transform?.(contents, info);
|
|
68
|
+
const target = join(staged, ...dest.split('/'));
|
|
69
|
+
await mkdir(dirname(target), { recursive: true });
|
|
70
|
+
await writeFile(target, changed ?? contents);
|
|
71
|
+
last = target;
|
|
72
|
+
kept += 1;
|
|
73
|
+
}
|
|
74
|
+
// A hook that drops every file would hand the binary an empty
|
|
75
|
+
// input; say so here, where the cause is.
|
|
76
|
+
if (kept === 0)
|
|
77
|
+
throw new Error(`estrogen: vendor ${input.from}: rename left no files`);
|
|
78
|
+
// A single file stays a single file, so `to` means what it does
|
|
79
|
+
// without hooks: the file's name, or a directory that exists.
|
|
80
|
+
table.from = isDir ? staged : last;
|
|
81
|
+
}
|
|
82
|
+
tables.push(table);
|
|
83
|
+
}
|
|
84
|
+
const vendorFile = join(root, 'vendor.json');
|
|
85
|
+
await writeFile(vendorFile, JSON.stringify(tables));
|
|
86
|
+
return { vendorFile, cleanup };
|
|
87
|
+
}
|
|
88
|
+
catch (error) {
|
|
89
|
+
await cleanup();
|
|
90
|
+
throw error;
|
|
91
|
+
}
|
|
92
|
+
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import type { Plugin } from 'vite';
|
|
2
|
+
import type { PluginOptions } from './options.js';
|
|
3
|
+
/**
|
|
4
|
+
* Vite plugin that runs estrogen over the build output directory once Vite has
|
|
5
|
+
* written it.
|
|
6
|
+
*
|
|
7
|
+
* It reads the output directory from the resolved config (`build.outDir`,
|
|
8
|
+
* resolved against `root`) in `configResolved`, and runs estrogen in
|
|
9
|
+
* `closeBundle`, after the bundle is on disk. `apply: 'build'` with
|
|
10
|
+
* `enforce: 'post'` keeps it out of `vite serve` and after every other plugin,
|
|
11
|
+
* so it rewrites the finished build. An estrogen failure is thrown so the build
|
|
12
|
+
* fails.
|
|
13
|
+
*
|
|
14
|
+
* estrogen rewrites that directory in place and raises the cost of reading it.
|
|
15
|
+
* It is not secrecy: a decoder key ships in each file.
|
|
16
|
+
*
|
|
17
|
+
* @example
|
|
18
|
+
* ```ts
|
|
19
|
+
* import { defineConfig } from 'vite';
|
|
20
|
+
* import { pluginEstrogen } from '@sysce/estrogen/vite';
|
|
21
|
+
*
|
|
22
|
+
* export default defineConfig({
|
|
23
|
+
* plugins: [pluginEstrogen({ canary: 'canary-list.json' })],
|
|
24
|
+
* });
|
|
25
|
+
* ```
|
|
26
|
+
*
|
|
27
|
+
* @param options estrogen options. `dirs` is ignored; the output directory comes
|
|
28
|
+
* from the Vite config.
|
|
29
|
+
*/
|
|
30
|
+
export declare function pluginEstrogen(options?: PluginOptions): Plugin;
|
|
31
|
+
export default pluginEstrogen;
|
package/dist/esm/vite.js
ADDED
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import { resolve as resolvePath } from 'node:path';
|
|
2
|
+
import { obfuscate } from './obfuscate.js';
|
|
3
|
+
/**
|
|
4
|
+
* Vite plugin that runs estrogen over the build output directory once Vite has
|
|
5
|
+
* written it.
|
|
6
|
+
*
|
|
7
|
+
* It reads the output directory from the resolved config (`build.outDir`,
|
|
8
|
+
* resolved against `root`) in `configResolved`, and runs estrogen in
|
|
9
|
+
* `closeBundle`, after the bundle is on disk. `apply: 'build'` with
|
|
10
|
+
* `enforce: 'post'` keeps it out of `vite serve` and after every other plugin,
|
|
11
|
+
* so it rewrites the finished build. An estrogen failure is thrown so the build
|
|
12
|
+
* fails.
|
|
13
|
+
*
|
|
14
|
+
* estrogen rewrites that directory in place and raises the cost of reading it.
|
|
15
|
+
* It is not secrecy: a decoder key ships in each file.
|
|
16
|
+
*
|
|
17
|
+
* @example
|
|
18
|
+
* ```ts
|
|
19
|
+
* import { defineConfig } from 'vite';
|
|
20
|
+
* import { pluginEstrogen } from '@sysce/estrogen/vite';
|
|
21
|
+
*
|
|
22
|
+
* export default defineConfig({
|
|
23
|
+
* plugins: [pluginEstrogen({ canary: 'canary-list.json' })],
|
|
24
|
+
* });
|
|
25
|
+
* ```
|
|
26
|
+
*
|
|
27
|
+
* @param options estrogen options. `dirs` is ignored; the output directory comes
|
|
28
|
+
* from the Vite config.
|
|
29
|
+
*/
|
|
30
|
+
export function pluginEstrogen(options = {}) {
|
|
31
|
+
let outDir = null;
|
|
32
|
+
return {
|
|
33
|
+
name: '@sysce/estrogen',
|
|
34
|
+
apply: 'build',
|
|
35
|
+
enforce: 'post',
|
|
36
|
+
configResolved(config) {
|
|
37
|
+
outDir = resolvePath(config.root, config.build.outDir);
|
|
38
|
+
},
|
|
39
|
+
async closeBundle() {
|
|
40
|
+
if (outDir === null)
|
|
41
|
+
return;
|
|
42
|
+
await obfuscate({ ...options, dirs: outDir });
|
|
43
|
+
},
|
|
44
|
+
// Watcher seam: `estrogen --watch` and dev-server HMR land as a companion
|
|
45
|
+
// serve-mode plugin (configureServer + handleHotUpdate) that re-runs the
|
|
46
|
+
// vendor and obfuscate step on change. This build plugin stays build-only;
|
|
47
|
+
// the dev integration is tracked separately and not wired here.
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
export default pluginEstrogen;
|
package/package.json
CHANGED
|
@@ -1,6 +1,284 @@
|
|
|
1
1
|
{
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
2
|
+
"name": "@sysce/estrogen",
|
|
3
|
+
"version": "0.5.5",
|
|
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
|
+
"license": "ISC",
|
|
6
|
+
"author": "David Reed",
|
|
7
|
+
"repository": {
|
|
8
|
+
"type": "git",
|
|
9
|
+
"url": "git+https://github.com/Fracital/estrogen.git"
|
|
10
|
+
},
|
|
11
|
+
"homepage": "https://github.com/Fracital/estrogen#readme",
|
|
12
|
+
"bugs": {
|
|
13
|
+
"url": "https://github.com/Fracital/estrogen/issues"
|
|
14
|
+
},
|
|
15
|
+
"keywords": [
|
|
16
|
+
"obfuscator",
|
|
17
|
+
"obfuscation",
|
|
18
|
+
"post-build",
|
|
19
|
+
"esbuild",
|
|
20
|
+
"rsbuild",
|
|
21
|
+
"vite",
|
|
22
|
+
"rollup",
|
|
23
|
+
"astro"
|
|
24
|
+
],
|
|
25
|
+
"type": "module",
|
|
26
|
+
"bin": {
|
|
27
|
+
"estrogen": "bin/estrogen.js"
|
|
28
|
+
},
|
|
29
|
+
"main": "./dist/cjs/index.js",
|
|
30
|
+
"module": "./dist/esm/index.js",
|
|
31
|
+
"types": "./dist/esm/index.d.ts",
|
|
32
|
+
"exports": {
|
|
33
|
+
".": {
|
|
34
|
+
"import": {
|
|
35
|
+
"types": "./dist/esm/index.d.ts",
|
|
36
|
+
"default": "./dist/esm/index.js"
|
|
37
|
+
},
|
|
38
|
+
"require": {
|
|
39
|
+
"types": "./dist/cjs/index.d.ts",
|
|
40
|
+
"default": "./dist/cjs/index.js"
|
|
41
|
+
}
|
|
42
|
+
},
|
|
43
|
+
"./esbuild": {
|
|
44
|
+
"import": {
|
|
45
|
+
"types": "./dist/esm/esbuild.d.ts",
|
|
46
|
+
"default": "./dist/esm/esbuild.js"
|
|
47
|
+
},
|
|
48
|
+
"require": {
|
|
49
|
+
"types": "./dist/cjs/esbuild.d.ts",
|
|
50
|
+
"default": "./dist/cjs/esbuild.js"
|
|
51
|
+
}
|
|
52
|
+
},
|
|
53
|
+
"./rsbuild": {
|
|
54
|
+
"import": {
|
|
55
|
+
"types": "./dist/esm/rsbuild.d.ts",
|
|
56
|
+
"default": "./dist/esm/rsbuild.js"
|
|
57
|
+
},
|
|
58
|
+
"require": {
|
|
59
|
+
"types": "./dist/cjs/rsbuild.d.ts",
|
|
60
|
+
"default": "./dist/cjs/rsbuild.js"
|
|
61
|
+
}
|
|
62
|
+
},
|
|
63
|
+
"./vite": {
|
|
64
|
+
"import": {
|
|
65
|
+
"types": "./dist/esm/vite.d.ts",
|
|
66
|
+
"default": "./dist/esm/vite.js"
|
|
67
|
+
},
|
|
68
|
+
"require": {
|
|
69
|
+
"types": "./dist/cjs/vite.d.ts",
|
|
70
|
+
"default": "./dist/cjs/vite.js"
|
|
71
|
+
}
|
|
72
|
+
},
|
|
73
|
+
"./rollup": {
|
|
74
|
+
"import": {
|
|
75
|
+
"types": "./dist/esm/rollup.d.ts",
|
|
76
|
+
"default": "./dist/esm/rollup.js"
|
|
77
|
+
},
|
|
78
|
+
"require": {
|
|
79
|
+
"types": "./dist/cjs/rollup.d.ts",
|
|
80
|
+
"default": "./dist/cjs/rollup.js"
|
|
81
|
+
}
|
|
82
|
+
},
|
|
83
|
+
"./astro": {
|
|
84
|
+
"import": {
|
|
85
|
+
"types": "./dist/esm/astro.d.ts",
|
|
86
|
+
"default": "./dist/esm/astro.js"
|
|
87
|
+
},
|
|
88
|
+
"require": {
|
|
89
|
+
"types": "./dist/cjs/astro.d.ts",
|
|
90
|
+
"default": "./dist/cjs/astro.js"
|
|
91
|
+
}
|
|
92
|
+
},
|
|
93
|
+
"./cloak": {
|
|
94
|
+
"import": {
|
|
95
|
+
"types": "./dist/esm/cloak/index.d.ts",
|
|
96
|
+
"default": "./dist/esm/cloak/index.js"
|
|
97
|
+
},
|
|
98
|
+
"require": {
|
|
99
|
+
"types": "./dist/cjs/cloak/index.d.ts",
|
|
100
|
+
"default": "./dist/cjs/cloak/index.js"
|
|
101
|
+
}
|
|
102
|
+
},
|
|
103
|
+
"./cloak/span": {
|
|
104
|
+
"import": {
|
|
105
|
+
"types": "./dist/esm/cloak/span.d.ts",
|
|
106
|
+
"default": "./dist/esm/cloak/span.js"
|
|
107
|
+
},
|
|
108
|
+
"require": {
|
|
109
|
+
"types": "./dist/cjs/cloak/span.d.ts",
|
|
110
|
+
"default": "./dist/cjs/cloak/span.js"
|
|
111
|
+
}
|
|
112
|
+
},
|
|
113
|
+
"./cloak/server": {
|
|
114
|
+
"node": {
|
|
115
|
+
"import": {
|
|
116
|
+
"types": "./dist/esm/cloak/server.node.d.ts",
|
|
117
|
+
"default": "./dist/esm/cloak/server.node.js"
|
|
118
|
+
},
|
|
119
|
+
"require": {
|
|
120
|
+
"types": "./dist/cjs/cloak/server.node.d.ts",
|
|
121
|
+
"default": "./dist/cjs/cloak/server.node.js"
|
|
122
|
+
}
|
|
123
|
+
},
|
|
124
|
+
"default": {
|
|
125
|
+
"types": "./dist/esm/cloak/server.d.ts",
|
|
126
|
+
"default": "./dist/esm/cloak/server.js"
|
|
127
|
+
}
|
|
128
|
+
},
|
|
129
|
+
"./cloak/react": {
|
|
130
|
+
"import": {
|
|
131
|
+
"types": "./dist/esm/cloak/react.d.ts",
|
|
132
|
+
"default": "./dist/esm/cloak/react.js"
|
|
133
|
+
},
|
|
134
|
+
"require": {
|
|
135
|
+
"types": "./dist/cjs/cloak/react.d.ts",
|
|
136
|
+
"default": "./dist/cjs/cloak/react.js"
|
|
137
|
+
}
|
|
138
|
+
},
|
|
139
|
+
"./cloak/preact": {
|
|
140
|
+
"import": {
|
|
141
|
+
"types": "./dist/esm/cloak/preact.d.ts",
|
|
142
|
+
"default": "./dist/esm/cloak/preact.js"
|
|
143
|
+
},
|
|
144
|
+
"require": {
|
|
145
|
+
"types": "./dist/cjs/cloak/preact.d.ts",
|
|
146
|
+
"default": "./dist/cjs/cloak/preact.js"
|
|
147
|
+
}
|
|
148
|
+
},
|
|
149
|
+
"./cloak/vue": {
|
|
150
|
+
"import": {
|
|
151
|
+
"types": "./dist/esm/cloak/vue.d.ts",
|
|
152
|
+
"default": "./dist/esm/cloak/vue.js"
|
|
153
|
+
},
|
|
154
|
+
"require": {
|
|
155
|
+
"types": "./dist/cjs/cloak/vue.d.ts",
|
|
156
|
+
"default": "./dist/cjs/cloak/vue.js"
|
|
157
|
+
}
|
|
158
|
+
},
|
|
159
|
+
"./cloak/svelte": {
|
|
160
|
+
"import": {
|
|
161
|
+
"types": "./dist/esm/cloak/svelte.d.ts",
|
|
162
|
+
"default": "./dist/esm/cloak/svelte.js"
|
|
163
|
+
},
|
|
164
|
+
"require": {
|
|
165
|
+
"types": "./dist/cjs/cloak/svelte.d.ts",
|
|
166
|
+
"default": "./dist/cjs/cloak/svelte.js"
|
|
167
|
+
}
|
|
168
|
+
},
|
|
169
|
+
"./cloak/solid": {
|
|
170
|
+
"import": {
|
|
171
|
+
"types": "./dist/esm/cloak/solid.d.ts",
|
|
172
|
+
"default": "./dist/esm/cloak/solid.js"
|
|
173
|
+
},
|
|
174
|
+
"require": {
|
|
175
|
+
"types": "./dist/cjs/cloak/solid.d.ts",
|
|
176
|
+
"default": "./dist/cjs/cloak/solid.js"
|
|
177
|
+
}
|
|
178
|
+
},
|
|
179
|
+
"./cloak/astro": {
|
|
180
|
+
"import": {
|
|
181
|
+
"types": "./dist/esm/cloak/astro.d.ts",
|
|
182
|
+
"default": "./dist/esm/cloak/astro.js"
|
|
183
|
+
},
|
|
184
|
+
"require": {
|
|
185
|
+
"types": "./dist/cjs/cloak/astro.d.ts",
|
|
186
|
+
"default": "./dist/cjs/cloak/astro.js"
|
|
187
|
+
}
|
|
188
|
+
},
|
|
189
|
+
"./package.json": "./package.json"
|
|
190
|
+
},
|
|
191
|
+
"files": [
|
|
192
|
+
"bin",
|
|
193
|
+
"dist",
|
|
194
|
+
"README.md",
|
|
195
|
+
"LICENSE"
|
|
196
|
+
],
|
|
197
|
+
"scripts": {
|
|
198
|
+
"build:esm": "tsc -p tsconfig.esm.json",
|
|
199
|
+
"build:cjs": "tsc -p tsconfig.cjs.json",
|
|
200
|
+
"clean": "node -e \"import('node:fs').then((fs) => fs.rmSync('dist', { recursive: true, force: true }))\"",
|
|
201
|
+
"build": "npm run clean && npm run build:esm && npm run build:cjs && node scripts/fixup.mjs",
|
|
202
|
+
"typecheck": "tsc -p tsconfig.json",
|
|
203
|
+
"test:cloak": "npm run build && node --test test/cloak.test.mjs test/cloak-span.test.mjs",
|
|
204
|
+
"test:function-source": "npm run build && node --test test/function-source-warning.test.mjs",
|
|
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",
|
|
207
|
+
"test:astro": "npm run build && astro build --root ./test/fixtures/astro && node test/cloak-astro-ssr.mjs",
|
|
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
|
+
"prepack": "npm run build && node scripts/readme.mjs"
|
|
210
|
+
},
|
|
211
|
+
"optionalDependencies": {
|
|
212
|
+
"@sysce/estrogen-darwin-arm64": "0.5.5",
|
|
213
|
+
"@sysce/estrogen-darwin-x64": "0.5.5",
|
|
214
|
+
"@sysce/estrogen-linux-arm64": "0.5.5",
|
|
215
|
+
"@sysce/estrogen-linux-x64": "0.5.5",
|
|
216
|
+
"@sysce/estrogen-win32-x64": "0.5.5"
|
|
217
|
+
},
|
|
218
|
+
"peerDependencies": {
|
|
219
|
+
"@rsbuild/core": "*",
|
|
220
|
+
"astro": "*",
|
|
221
|
+
"esbuild": "*",
|
|
222
|
+
"preact": "^10 || ^11",
|
|
223
|
+
"react": "^18 || ^19",
|
|
224
|
+
"rollup": "*",
|
|
225
|
+
"solid-js": "^1.9",
|
|
226
|
+
"svelte": "^5",
|
|
227
|
+
"vite": "*",
|
|
228
|
+
"vue": "^3"
|
|
229
|
+
},
|
|
230
|
+
"peerDependenciesMeta": {
|
|
231
|
+
"esbuild": {
|
|
232
|
+
"optional": true
|
|
233
|
+
},
|
|
234
|
+
"@rsbuild/core": {
|
|
235
|
+
"optional": true
|
|
236
|
+
},
|
|
237
|
+
"astro": {
|
|
238
|
+
"optional": true
|
|
239
|
+
},
|
|
240
|
+
"vite": {
|
|
241
|
+
"optional": true
|
|
242
|
+
},
|
|
243
|
+
"rollup": {
|
|
244
|
+
"optional": true
|
|
245
|
+
},
|
|
246
|
+
"preact": {
|
|
247
|
+
"optional": true
|
|
248
|
+
},
|
|
249
|
+
"react": {
|
|
250
|
+
"optional": true
|
|
251
|
+
},
|
|
252
|
+
"solid-js": {
|
|
253
|
+
"optional": true
|
|
254
|
+
},
|
|
255
|
+
"svelte": {
|
|
256
|
+
"optional": true
|
|
257
|
+
},
|
|
258
|
+
"vue": {
|
|
259
|
+
"optional": true
|
|
260
|
+
}
|
|
261
|
+
},
|
|
262
|
+
"devDependencies": {
|
|
263
|
+
"@rsbuild/core": "^1.1.0",
|
|
264
|
+
"@types/node": "^22.10.0",
|
|
265
|
+
"@types/react": "^19.3.0",
|
|
266
|
+
"astro": "^5.1.0",
|
|
267
|
+
"esbuild": "^0.24.0",
|
|
268
|
+
"preact": "^11.2.0",
|
|
269
|
+
"react": "^19.3.1",
|
|
270
|
+
"react-dom": "^19.3.1",
|
|
271
|
+
"rollup": "^4.68.7",
|
|
272
|
+
"solid-js": "^1.9.20",
|
|
273
|
+
"svelte": "^5.59.1",
|
|
274
|
+
"typescript": "^5.7.0",
|
|
275
|
+
"vite": "^6.4.6",
|
|
276
|
+
"vue": "^3.5.46"
|
|
277
|
+
},
|
|
278
|
+
"engines": {
|
|
279
|
+
"node": ">=18"
|
|
280
|
+
},
|
|
281
|
+
"dependencies": {
|
|
282
|
+
"@noble/ciphers": "^1.3.0"
|
|
283
|
+
}
|
|
284
|
+
}
|