@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,53 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// The build-time string registry. A build step encrypts a fixed set of strings
|
|
3
|
+
// (brand, nav, auth copy) once and ships the plaintext -> ciphertext map on the
|
|
4
|
+
// page as window.__ESTROGEN_CLOAK_STRINGS__. Components look a string up here
|
|
5
|
+
// instead of carrying an explicit ciphertext prop.
|
|
6
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
|
+
exports.setCloakStringMapProvider = setCloakStringMapProvider;
|
|
8
|
+
exports.registerObfuscatedString = registerObfuscatedString;
|
|
9
|
+
exports.registerObfuscatedStrings = registerObfuscatedStrings;
|
|
10
|
+
exports.getObfuscatedCiphertext = getObfuscatedCiphertext;
|
|
11
|
+
const GLOBAL = '__ESTROGEN_CLOAK_STRINGS__';
|
|
12
|
+
const localRegistry = Object.create(null);
|
|
13
|
+
let stringMapProvider;
|
|
14
|
+
/** Read an existing application's registry without renaming its page global. */
|
|
15
|
+
function setCloakStringMapProvider(provider) {
|
|
16
|
+
stringMapProvider = provider;
|
|
17
|
+
}
|
|
18
|
+
/** Register one plaintext -> ciphertext pair (e.g. from a dynamic build step). */
|
|
19
|
+
function registerObfuscatedString(text, ciphertext) {
|
|
20
|
+
localRegistry[text] = ciphertext;
|
|
21
|
+
}
|
|
22
|
+
/** Register a whole plaintext -> ciphertext map at once. */
|
|
23
|
+
function registerObfuscatedStrings(map) {
|
|
24
|
+
for (const [plain, ciphertext] of Object.entries(map)) {
|
|
25
|
+
if (typeof ciphertext === 'string')
|
|
26
|
+
localRegistry[plain] = ciphertext;
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Look up the ciphertext for a plaintext string: the page-level global map
|
|
31
|
+
* wins, then the local registry. Returns undefined when the string was never
|
|
32
|
+
* registered, which tells callers to render the plaintext directly.
|
|
33
|
+
*/
|
|
34
|
+
function getObfuscatedCiphertext(text) {
|
|
35
|
+
if (typeof window !== 'undefined') {
|
|
36
|
+
const map = window[GLOBAL];
|
|
37
|
+
const fromGlobal = map && Object.hasOwn(map, text) ? map[text] : undefined;
|
|
38
|
+
if (fromGlobal)
|
|
39
|
+
return fromGlobal;
|
|
40
|
+
}
|
|
41
|
+
if (stringMapProvider) {
|
|
42
|
+
try {
|
|
43
|
+
const map = stringMapProvider();
|
|
44
|
+
const fromProvider = map && Object.hasOwn(map, text) ? map[text] : undefined;
|
|
45
|
+
if (typeof fromProvider === 'string' && fromProvider)
|
|
46
|
+
return fromProvider;
|
|
47
|
+
}
|
|
48
|
+
catch {
|
|
49
|
+
// An unavailable host registry must not break fallback rendering.
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
return localRegistry[text];
|
|
53
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
<script lang="ts">
|
|
2
|
+
import type { Snippet } from 'svelte';
|
|
3
|
+
import '../elements.js';
|
|
4
|
+
import { linkElementProps, type CloakLinkProps } from '../props.js';
|
|
5
|
+
|
|
6
|
+
let { href, hrefCipher, target, children }: CloakLinkProps & { children?: Snippet } = $props();
|
|
7
|
+
const attrs = $derived(linkElementProps({ href, hrefCipher, target }));
|
|
8
|
+
</script>
|
|
9
|
+
|
|
10
|
+
<holy-link href={attrs.href} href-cipher={attrs['href-cipher']} {target}>
|
|
11
|
+
{#if children}{@render children()}{/if}
|
|
12
|
+
</holy-link>
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
<script lang="ts">
|
|
2
|
+
import '../elements.js';
|
|
3
|
+
import { textElementProps, type CloakTextProps } from '../props.js';
|
|
4
|
+
|
|
5
|
+
let { text = '', ciphertext, ellipsis = false, revealForBots = false }: CloakTextProps = $props();
|
|
6
|
+
const result = $derived(textElementProps({ text, ciphertext, ellipsis, revealForBots }));
|
|
7
|
+
</script>
|
|
8
|
+
|
|
9
|
+
<holy-text
|
|
10
|
+
ciphertext={result.attributes.ciphertext}
|
|
11
|
+
ellipsis={result.attributes.ellipsis}
|
|
12
|
+
reveal-for-bots={result.attributes['reveal-for-bots']}
|
|
13
|
+
>{result.placeholder}</holy-text>
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.HolyLink = exports.HolyText = void 0;
|
|
7
|
+
var HolyText_svelte_1 = require("./svelte/HolyText.svelte");
|
|
8
|
+
Object.defineProperty(exports, "HolyText", { enumerable: true, get: function () { return __importDefault(HolyText_svelte_1).default; } });
|
|
9
|
+
var HolyLink_svelte_1 = require("./svelte/HolyLink.svelte");
|
|
10
|
+
Object.defineProperty(exports, "HolyLink", { enumerable: true, get: function () { return __importDefault(HolyLink_svelte_1).default; } });
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { type PropType } from 'vue';
|
|
2
|
+
import './elements.js';
|
|
3
|
+
export declare const HolyText: import("vue").DefineComponent<import("vue").ExtractPropTypes<{
|
|
4
|
+
text: {
|
|
5
|
+
type: StringConstructor;
|
|
6
|
+
default: string;
|
|
7
|
+
};
|
|
8
|
+
ciphertext: StringConstructor;
|
|
9
|
+
ellipsis: BooleanConstructor;
|
|
10
|
+
revealForBots: BooleanConstructor;
|
|
11
|
+
}>, () => import("vue").VNode<import("vue").RendererNode, import("vue").RendererElement, {
|
|
12
|
+
[key: string]: any;
|
|
13
|
+
}>, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").PublicProps, Readonly<import("vue").ExtractPropTypes<{
|
|
14
|
+
text: {
|
|
15
|
+
type: StringConstructor;
|
|
16
|
+
default: string;
|
|
17
|
+
};
|
|
18
|
+
ciphertext: StringConstructor;
|
|
19
|
+
ellipsis: BooleanConstructor;
|
|
20
|
+
revealForBots: BooleanConstructor;
|
|
21
|
+
}>> & Readonly<{}>, {
|
|
22
|
+
ellipsis: boolean;
|
|
23
|
+
text: string;
|
|
24
|
+
revealForBots: boolean;
|
|
25
|
+
}, {}, {}, {}, string, import("vue").ComponentProvideOptions, true, {}, any>;
|
|
26
|
+
export declare const HolyLink: import("vue").DefineComponent<import("vue").ExtractPropTypes<{
|
|
27
|
+
href: StringConstructor;
|
|
28
|
+
hrefCipher: StringConstructor;
|
|
29
|
+
target: PropType<string>;
|
|
30
|
+
}>, () => import("vue").VNode<import("vue").RendererNode, import("vue").RendererElement, {
|
|
31
|
+
[key: string]: any;
|
|
32
|
+
}>, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").PublicProps, Readonly<import("vue").ExtractPropTypes<{
|
|
33
|
+
href: StringConstructor;
|
|
34
|
+
hrefCipher: StringConstructor;
|
|
35
|
+
target: PropType<string>;
|
|
36
|
+
}>> & Readonly<{}>, {}, {}, {}, {}, string, import("vue").ComponentProvideOptions, true, {}, any>;
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.HolyLink = exports.HolyText = void 0;
|
|
4
|
+
const vue_1 = require("vue");
|
|
5
|
+
require("./elements.js");
|
|
6
|
+
const props_js_1 = require("./props.js");
|
|
7
|
+
exports.HolyText = (0, vue_1.defineComponent)({
|
|
8
|
+
name: 'HolyText',
|
|
9
|
+
inheritAttrs: false,
|
|
10
|
+
props: {
|
|
11
|
+
text: { type: String, default: '' },
|
|
12
|
+
ciphertext: String,
|
|
13
|
+
ellipsis: Boolean,
|
|
14
|
+
revealForBots: Boolean,
|
|
15
|
+
},
|
|
16
|
+
setup(props, { attrs }) {
|
|
17
|
+
return () => {
|
|
18
|
+
const { attributes, placeholder } = (0, props_js_1.textElementProps)(props);
|
|
19
|
+
return (0, vue_1.h)('holy-text', { ...attrs, ...attributes }, placeholder);
|
|
20
|
+
};
|
|
21
|
+
},
|
|
22
|
+
});
|
|
23
|
+
exports.HolyLink = (0, vue_1.defineComponent)({
|
|
24
|
+
name: 'HolyLink',
|
|
25
|
+
inheritAttrs: false,
|
|
26
|
+
props: {
|
|
27
|
+
href: String,
|
|
28
|
+
hrefCipher: String,
|
|
29
|
+
target: String,
|
|
30
|
+
},
|
|
31
|
+
setup(props, { attrs, slots }) {
|
|
32
|
+
return () => (0, vue_1.h)('holy-link', { ...attrs, ...(0, props_js_1.linkElementProps)(props) }, slots.default?.());
|
|
33
|
+
},
|
|
34
|
+
});
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import type { Plugin } from 'esbuild';
|
|
2
|
+
import type { PluginOptions } from './options.js';
|
|
3
|
+
/**
|
|
4
|
+
* esbuild plugin that runs estrogen over the build's output directory after esbuild
|
|
5
|
+
* writes it.
|
|
6
|
+
*
|
|
7
|
+
* It finds the directory from `initialOptions.outdir`, or from the directory of
|
|
8
|
+
* `initialOptions.outfile` when a single file is built, resolved against the
|
|
9
|
+
* build's `absWorkingDir` or the current working directory. It runs in `onEnd`,
|
|
10
|
+
* once the bundle is on disk, and skips when the build produced errors. An estrogen
|
|
11
|
+
* failure is turned into an esbuild error so the build fails.
|
|
12
|
+
*
|
|
13
|
+
* estrogen rewrites that directory in place and raises the cost of reading it. It
|
|
14
|
+
* is not secrecy: a decoder key ships in each file.
|
|
15
|
+
*
|
|
16
|
+
* @example
|
|
17
|
+
* ```ts
|
|
18
|
+
* import { build } from 'esbuild';
|
|
19
|
+
* import estrogen from '@sysce/estrogen/esbuild';
|
|
20
|
+
*
|
|
21
|
+
* await build({
|
|
22
|
+
* entryPoints: ['src/app.ts'],
|
|
23
|
+
* bundle: true,
|
|
24
|
+
* outdir: 'dist',
|
|
25
|
+
* plugins: [estrogen({ canary: 'canary-list.json' })],
|
|
26
|
+
* });
|
|
27
|
+
* ```
|
|
28
|
+
*
|
|
29
|
+
* @param options estrogen options. `dirs` is ignored; the output directory is
|
|
30
|
+
* taken from the esbuild config.
|
|
31
|
+
*/
|
|
32
|
+
export declare function estrogen(options?: PluginOptions): Plugin;
|
|
33
|
+
export default estrogen;
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.estrogen = estrogen;
|
|
4
|
+
const node_path_1 = require("node:path");
|
|
5
|
+
const obfuscate_js_1 = require("./obfuscate.js");
|
|
6
|
+
/**
|
|
7
|
+
* esbuild plugin that runs estrogen over the build's output directory after esbuild
|
|
8
|
+
* writes it.
|
|
9
|
+
*
|
|
10
|
+
* It finds the directory from `initialOptions.outdir`, or from the directory of
|
|
11
|
+
* `initialOptions.outfile` when a single file is built, resolved against the
|
|
12
|
+
* build's `absWorkingDir` or the current working directory. It runs in `onEnd`,
|
|
13
|
+
* once the bundle is on disk, and skips when the build produced errors. An estrogen
|
|
14
|
+
* failure is turned into an esbuild error so the build fails.
|
|
15
|
+
*
|
|
16
|
+
* estrogen rewrites that directory in place and raises the cost of reading it. It
|
|
17
|
+
* is not secrecy: a decoder key ships in each file.
|
|
18
|
+
*
|
|
19
|
+
* @example
|
|
20
|
+
* ```ts
|
|
21
|
+
* import { build } from 'esbuild';
|
|
22
|
+
* import estrogen from '@sysce/estrogen/esbuild';
|
|
23
|
+
*
|
|
24
|
+
* await build({
|
|
25
|
+
* entryPoints: ['src/app.ts'],
|
|
26
|
+
* bundle: true,
|
|
27
|
+
* outdir: 'dist',
|
|
28
|
+
* plugins: [estrogen({ canary: 'canary-list.json' })],
|
|
29
|
+
* });
|
|
30
|
+
* ```
|
|
31
|
+
*
|
|
32
|
+
* @param options estrogen options. `dirs` is ignored; the output directory is
|
|
33
|
+
* taken from the esbuild config.
|
|
34
|
+
*/
|
|
35
|
+
function estrogen(options = {}) {
|
|
36
|
+
return {
|
|
37
|
+
name: '@sysce/estrogen',
|
|
38
|
+
setup(build) {
|
|
39
|
+
build.onEnd(async (result) => {
|
|
40
|
+
if (result.errors.length > 0)
|
|
41
|
+
return;
|
|
42
|
+
const outDir = resolveOutputDir(build);
|
|
43
|
+
if (outDir === null) {
|
|
44
|
+
return {
|
|
45
|
+
errors: [
|
|
46
|
+
{
|
|
47
|
+
text: 'estrogen could not find the esbuild output directory. ' +
|
|
48
|
+
'Set outdir or outfile so estrogen knows what to rewrite.',
|
|
49
|
+
},
|
|
50
|
+
],
|
|
51
|
+
};
|
|
52
|
+
}
|
|
53
|
+
try {
|
|
54
|
+
await (0, obfuscate_js_1.obfuscate)({ ...options, dirs: outDir });
|
|
55
|
+
return null;
|
|
56
|
+
}
|
|
57
|
+
catch (error) {
|
|
58
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
59
|
+
return { errors: [{ text: `estrogen failed: ${message}` }] };
|
|
60
|
+
}
|
|
61
|
+
});
|
|
62
|
+
},
|
|
63
|
+
};
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* Resolve the absolute output directory from an esbuild build. Prefers `outdir`,
|
|
67
|
+
* falls back to the directory of `outfile`, and resolves relative paths against
|
|
68
|
+
* `absWorkingDir`. Returns null when neither is set.
|
|
69
|
+
*/
|
|
70
|
+
function resolveOutputDir(build) {
|
|
71
|
+
const { outdir, outfile, absWorkingDir } = build.initialOptions;
|
|
72
|
+
const base = absWorkingDir ?? process.cwd();
|
|
73
|
+
if (outdir !== undefined)
|
|
74
|
+
return (0, node_path_1.resolve)(base, outdir);
|
|
75
|
+
if (outfile !== undefined)
|
|
76
|
+
return (0, node_path_1.resolve)(base, (0, node_path_1.dirname)(outfile));
|
|
77
|
+
return null;
|
|
78
|
+
}
|
|
79
|
+
exports.default = estrogen;
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `@sysce/estrogen`: run the estrogen obfuscator from Node.
|
|
3
|
+
*
|
|
4
|
+
* estrogen rewrites an already built output directory, in place: string and
|
|
5
|
+
* template literals into an encrypted per-file pool, proxy and store names into
|
|
6
|
+
* per-build substitutes, and the embedded wasm names to match. It raises the
|
|
7
|
+
* cost of reading the build. It is not secrecy: a decoder key ships in each
|
|
8
|
+
* file, and anyone with devtools can run the code.
|
|
9
|
+
*
|
|
10
|
+
* - {@link obfuscate} spawns the binary over one or more directories.
|
|
11
|
+
* - The esbuild plugin lives at `@sysce/estrogen/esbuild`.
|
|
12
|
+
* - The Rsbuild plugin lives at `@sysce/estrogen/rsbuild`.
|
|
13
|
+
* - The Vite plugin lives at `@sysce/estrogen/vite`.
|
|
14
|
+
* - The Rollup plugin lives at `@sysce/estrogen/rollup`.
|
|
15
|
+
* - The Astro integration lives at `@sysce/estrogen/astro`.
|
|
16
|
+
*
|
|
17
|
+
* @packageDocumentation
|
|
18
|
+
*/
|
|
19
|
+
export { obfuscate } from './obfuscate.js';
|
|
20
|
+
export type { CloakInput, LiveInjectorOptions, Options, PluginOptions, VendorFileInfo, VendorInput, VendorRewrite, } from './options.js';
|
|
21
|
+
export { normalizeDirs, buildArgs } from './options.js';
|
|
22
|
+
export { EstrogenError } from './report.js';
|
|
23
|
+
export type { Report } from './report.js';
|
|
24
|
+
export { PLATFORM_PACKAGES, MissingBinaryError, platformPackageName, targetKey, binSubpath, resolveBinaryPath, } from './resolve-binary.js';
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.resolveBinaryPath = exports.binSubpath = exports.targetKey = exports.platformPackageName = exports.MissingBinaryError = exports.PLATFORM_PACKAGES = exports.EstrogenError = exports.buildArgs = exports.normalizeDirs = exports.obfuscate = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* `@sysce/estrogen`: run the estrogen obfuscator from Node.
|
|
6
|
+
*
|
|
7
|
+
* estrogen rewrites an already built output directory, in place: string and
|
|
8
|
+
* template literals into an encrypted per-file pool, proxy and store names into
|
|
9
|
+
* per-build substitutes, and the embedded wasm names to match. It raises the
|
|
10
|
+
* cost of reading the build. It is not secrecy: a decoder key ships in each
|
|
11
|
+
* file, and anyone with devtools can run the code.
|
|
12
|
+
*
|
|
13
|
+
* - {@link obfuscate} spawns the binary over one or more directories.
|
|
14
|
+
* - The esbuild plugin lives at `@sysce/estrogen/esbuild`.
|
|
15
|
+
* - The Rsbuild plugin lives at `@sysce/estrogen/rsbuild`.
|
|
16
|
+
* - The Vite plugin lives at `@sysce/estrogen/vite`.
|
|
17
|
+
* - The Rollup plugin lives at `@sysce/estrogen/rollup`.
|
|
18
|
+
* - The Astro integration lives at `@sysce/estrogen/astro`.
|
|
19
|
+
*
|
|
20
|
+
* @packageDocumentation
|
|
21
|
+
*/
|
|
22
|
+
var obfuscate_js_1 = require("./obfuscate.js");
|
|
23
|
+
Object.defineProperty(exports, "obfuscate", { enumerable: true, get: function () { return obfuscate_js_1.obfuscate; } });
|
|
24
|
+
var options_js_1 = require("./options.js");
|
|
25
|
+
Object.defineProperty(exports, "normalizeDirs", { enumerable: true, get: function () { return options_js_1.normalizeDirs; } });
|
|
26
|
+
Object.defineProperty(exports, "buildArgs", { enumerable: true, get: function () { return options_js_1.buildArgs; } });
|
|
27
|
+
var report_js_1 = require("./report.js");
|
|
28
|
+
Object.defineProperty(exports, "EstrogenError", { enumerable: true, get: function () { return report_js_1.EstrogenError; } });
|
|
29
|
+
var resolve_binary_js_1 = require("./resolve-binary.js");
|
|
30
|
+
Object.defineProperty(exports, "PLATFORM_PACKAGES", { enumerable: true, get: function () { return resolve_binary_js_1.PLATFORM_PACKAGES; } });
|
|
31
|
+
Object.defineProperty(exports, "MissingBinaryError", { enumerable: true, get: function () { return resolve_binary_js_1.MissingBinaryError; } });
|
|
32
|
+
Object.defineProperty(exports, "platformPackageName", { enumerable: true, get: function () { return resolve_binary_js_1.platformPackageName; } });
|
|
33
|
+
Object.defineProperty(exports, "targetKey", { enumerable: true, get: function () { return resolve_binary_js_1.targetKey; } });
|
|
34
|
+
Object.defineProperty(exports, "binSubpath", { enumerable: true, get: function () { return resolve_binary_js_1.binSubpath; } });
|
|
35
|
+
Object.defineProperty(exports, "resolveBinaryPath", { enumerable: true, get: function () { return resolve_binary_js_1.resolveBinaryPath; } });
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
// CommonJS runtime for getRequire. Copied to dist/cjs/node-require.js by the
|
|
2
|
+
// build. In CommonJS, require is already anchored in this file's package, so
|
|
3
|
+
// returning it resolves the optional binary packages correctly.
|
|
4
|
+
'use strict';
|
|
5
|
+
exports.getRequire = function getRequire() {
|
|
6
|
+
return require;
|
|
7
|
+
};
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { type Options } from './options.js';
|
|
2
|
+
import { type Report } from './report.js';
|
|
3
|
+
/**
|
|
4
|
+
* Run estrogen over one or more built directories.
|
|
5
|
+
*
|
|
6
|
+
* Resolves the per-platform binary (or uses {@link Options.binaryPath}), spawns
|
|
7
|
+
* it once with the flags and directories from `options`, and collects its
|
|
8
|
+
* output. Resolves with a {@link Report} when estrogen exits 0. Rejects with a
|
|
9
|
+
* {@link EstrogenError} when it exits nonzero or fails to launch; the error carries
|
|
10
|
+
* the partial report.
|
|
11
|
+
*
|
|
12
|
+
* estrogen rewrites the directories in place and raises the cost of reading the
|
|
13
|
+
* build. It is not secrecy: a decoder key ships in each file.
|
|
14
|
+
*
|
|
15
|
+
* @example
|
|
16
|
+
* ```ts
|
|
17
|
+
* import { obfuscate } from '@sysce/estrogen';
|
|
18
|
+
*
|
|
19
|
+
* const report = await obfuscate({ dirs: 'dist', canary: 'canary-list.json' });
|
|
20
|
+
* console.log(report.stdout);
|
|
21
|
+
* ```
|
|
22
|
+
*/
|
|
23
|
+
export declare function obfuscate(options: Options): Promise<Report>;
|
|
@@ -0,0 +1,154 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.obfuscate = obfuscate;
|
|
4
|
+
const node_child_process_1 = require("node:child_process");
|
|
5
|
+
const promises_1 = require("node:fs/promises");
|
|
6
|
+
const node_path_1 = require("node:path");
|
|
7
|
+
const node_require_js_1 = require("./node-require.js");
|
|
8
|
+
const options_js_1 = require("./options.js");
|
|
9
|
+
const report_js_1 = require("./report.js");
|
|
10
|
+
const resolve_binary_js_1 = require("./resolve-binary.js");
|
|
11
|
+
const vendor_js_1 = require("./vendor.js");
|
|
12
|
+
/**
|
|
13
|
+
* Run estrogen over one or more built directories.
|
|
14
|
+
*
|
|
15
|
+
* Resolves the per-platform binary (or uses {@link Options.binaryPath}), spawns
|
|
16
|
+
* it once with the flags and directories from `options`, and collects its
|
|
17
|
+
* output. Resolves with a {@link Report} when estrogen exits 0. Rejects with a
|
|
18
|
+
* {@link EstrogenError} when it exits nonzero or fails to launch; the error carries
|
|
19
|
+
* the partial report.
|
|
20
|
+
*
|
|
21
|
+
* estrogen rewrites the directories in place and raises the cost of reading the
|
|
22
|
+
* build. It is not secrecy: a decoder key ships in each file.
|
|
23
|
+
*
|
|
24
|
+
* @example
|
|
25
|
+
* ```ts
|
|
26
|
+
* import { obfuscate } from '@sysce/estrogen';
|
|
27
|
+
*
|
|
28
|
+
* const report = await obfuscate({ dirs: 'dist', canary: 'canary-list.json' });
|
|
29
|
+
* console.log(report.stdout);
|
|
30
|
+
* ```
|
|
31
|
+
*/
|
|
32
|
+
function obfuscate(options) {
|
|
33
|
+
const dirs = (0, options_js_1.normalizeDirs)(options.dirs);
|
|
34
|
+
if (dirs.length === 0) {
|
|
35
|
+
return Promise.reject(new report_js_1.EstrogenError('estrogen needs at least one directory to rewrite; set options.dirs.', {
|
|
36
|
+
ok: false,
|
|
37
|
+
exitCode: -1,
|
|
38
|
+
dirs,
|
|
39
|
+
binaryPath: options.binaryPath ?? '',
|
|
40
|
+
args: [],
|
|
41
|
+
stdout: '',
|
|
42
|
+
stderr: '',
|
|
43
|
+
durationMs: 0,
|
|
44
|
+
}));
|
|
45
|
+
}
|
|
46
|
+
let binaryPath;
|
|
47
|
+
try {
|
|
48
|
+
binaryPath = (0, resolve_binary_js_1.resolveBinaryPath)((0, node_require_js_1.getRequire)(), options.binaryPath);
|
|
49
|
+
}
|
|
50
|
+
catch (error) {
|
|
51
|
+
return Promise.reject(error);
|
|
52
|
+
}
|
|
53
|
+
if (!options.vendor?.length)
|
|
54
|
+
return run(binaryPath, (0, options_js_1.buildArgs)(options), dirs, options);
|
|
55
|
+
return vendorRun(binaryPath, dirs, options);
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* Stage the vendor inputs, run `estrogen build` with them, and read each dir's
|
|
59
|
+
* vendor manifest into the report. The staging directory is removed after the
|
|
60
|
+
* run, whether it passed or not.
|
|
61
|
+
*/
|
|
62
|
+
async function vendorRun(binaryPath, dirs, options) {
|
|
63
|
+
const cwd = options.cwd ?? process.cwd();
|
|
64
|
+
const staged = await (0, vendor_js_1.stageVendor)(options.vendor ?? [], cwd);
|
|
65
|
+
try {
|
|
66
|
+
const args = [
|
|
67
|
+
'build',
|
|
68
|
+
'--vendor-file',
|
|
69
|
+
staged.vendorFile,
|
|
70
|
+
...(0, options_js_1.buildArgs)(options),
|
|
71
|
+
];
|
|
72
|
+
const report = await run(binaryPath, args, dirs, options);
|
|
73
|
+
const manifest = options.manifest;
|
|
74
|
+
if (manifest === false)
|
|
75
|
+
return report;
|
|
76
|
+
report.manifests = await Promise.all(dirs.map((dir) => (0, promises_1.readFile)((0, node_path_1.resolve)((0, node_path_1.resolve)(cwd, dir), manifest ?? 'estrogen-vendor-manifest.json'), 'utf8')
|
|
77
|
+
.then((text) => JSON.parse(text))
|
|
78
|
+
.catch(() => undefined)));
|
|
79
|
+
return report;
|
|
80
|
+
}
|
|
81
|
+
finally {
|
|
82
|
+
await staged.cleanup();
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
/** Spawn the binary once with `args` and collect its output. */
|
|
86
|
+
function run(binaryPath, args, dirs, options) {
|
|
87
|
+
const started = Date.now();
|
|
88
|
+
return new Promise((resolve, reject) => {
|
|
89
|
+
// The binary sees a pipe, so ask it for color when this process
|
|
90
|
+
// writes its warning to a terminal.
|
|
91
|
+
const color = process.stderr.isTTY &&
|
|
92
|
+
process.env.NO_COLOR === undefined &&
|
|
93
|
+
process.env.FORCE_COLOR === undefined;
|
|
94
|
+
const child = (0, node_child_process_1.spawn)(binaryPath, args, {
|
|
95
|
+
cwd: options.cwd ?? process.cwd(),
|
|
96
|
+
stdio: ['ignore', 'pipe', 'pipe'],
|
|
97
|
+
env: color ? { ...process.env, FORCE_COLOR: '1' } : process.env,
|
|
98
|
+
});
|
|
99
|
+
let stdout = '';
|
|
100
|
+
let stderr = '';
|
|
101
|
+
child.stdout.setEncoding('utf8');
|
|
102
|
+
child.stderr.setEncoding('utf8');
|
|
103
|
+
child.stdout.on('data', (chunk) => {
|
|
104
|
+
stdout += chunk;
|
|
105
|
+
});
|
|
106
|
+
child.stderr.on('data', (chunk) => {
|
|
107
|
+
stderr += chunk;
|
|
108
|
+
});
|
|
109
|
+
child.on('error', (error) => {
|
|
110
|
+
const report = {
|
|
111
|
+
ok: false,
|
|
112
|
+
exitCode: -1,
|
|
113
|
+
dirs,
|
|
114
|
+
binaryPath,
|
|
115
|
+
args,
|
|
116
|
+
stdout,
|
|
117
|
+
stderr,
|
|
118
|
+
durationMs: Date.now() - started,
|
|
119
|
+
};
|
|
120
|
+
reject(new report_js_1.EstrogenError(`estrogen failed to start: ${error.message}`, report));
|
|
121
|
+
});
|
|
122
|
+
child.on('close', async (code, signal) => {
|
|
123
|
+
const exitCode = code ?? -1;
|
|
124
|
+
const run = options.report === undefined
|
|
125
|
+
? undefined
|
|
126
|
+
: await (0, promises_1.readFile)((0, node_path_1.resolve)(options.cwd ?? process.cwd(), options.report), 'utf8')
|
|
127
|
+
.then((text) => JSON.parse(text))
|
|
128
|
+
.catch(() => undefined);
|
|
129
|
+
// A plugin never prints stderr, so pass the warning through here.
|
|
130
|
+
const warning = (0, report_js_1.functionSourceWarning)(stderr);
|
|
131
|
+
if (warning !== undefined)
|
|
132
|
+
process.stderr.write(warning);
|
|
133
|
+
const report = {
|
|
134
|
+
ok: exitCode === 0,
|
|
135
|
+
exitCode,
|
|
136
|
+
dirs,
|
|
137
|
+
binaryPath,
|
|
138
|
+
args,
|
|
139
|
+
stdout,
|
|
140
|
+
stderr,
|
|
141
|
+
durationMs: Date.now() - started,
|
|
142
|
+
details: (0, report_js_1.parseDetails)(stdout),
|
|
143
|
+
warning,
|
|
144
|
+
run,
|
|
145
|
+
};
|
|
146
|
+
if (report.ok) {
|
|
147
|
+
resolve(report);
|
|
148
|
+
return;
|
|
149
|
+
}
|
|
150
|
+
const reason = signal ? `signal ${signal}` : `exit code ${exitCode}`;
|
|
151
|
+
reject(new report_js_1.EstrogenError(`estrogen exited with ${reason}.`, report));
|
|
152
|
+
});
|
|
153
|
+
});
|
|
154
|
+
}
|