### Setup and Development Commands (pnpm) Source: https://github.com/afterpack-dev/afterpack/blob/main/CONTRIBUTING.md Run these pnpm commands after installing dependencies to build, test, run e2e, typecheck, lint, and check hygiene. Requires Node 18+ and pnpm (pinned via packageManager; corepack enable). Run pnpm build before pnpm typecheck because plugins resolve @afterpack/integration-utils through built declarations. ```bash pnpm install pnpm build # every package, in dependency order pnpm test # every package's unit tests, then the release scripts' (scripts/test) pnpm e2e # Playwright, packages/*/e2e (pnpm e2e:quick for the PR subset; pnpm e2e:install first) pnpm typecheck # needs a build first: plugins typecheck against built declarations pnpm lint:fix # biome, autofixing — run it after any edit pnpm hygiene # the repo hygiene guardrail described below pnpm check:comments # no explanatory comments anywhere; CI enforces it ``` -------------------------------- ### Install @afterpack/sveltekit Source: https://github.com/afterpack-dev/afterpack/blob/main/packages/sveltekit/README.md Install the package as a dev dependency for SvelteKit 2 projects. ```sh npm install --save-dev @afterpack/sveltekit ``` -------------------------------- ### afterpack.json configuration example Source: https://github.com/afterpack-dev/afterpack/blob/main/packages/cli/README.md Example configuration file showing how to set options in afterpack.json. The nearest afterpack.json at or above the working directory is used. Options can also be set via command-line flags or environment variables, with flags taking precedence over environment variables, which take precedence over the file. ```json { "preset": "hard", "seed": "git", "paths": { "exclude": ["dist/vendor/**"] }, "identifiers": { "reserved": ["Hls"] } } ``` -------------------------------- ### Run the full e2e lane as CI does Source: https://github.com/afterpack-dev/afterpack/blob/main/e2e/README.md Runs all tests in Chromium, Firefox, and WebKit after installing the Playwright browsers. Use this to replicate the CI full lane. ```bash AFTERPACK_E2E_BROWSERS=chromium,firefox,webkit pnpm e2e ``` -------------------------------- ### afterpack CLI basic usage examples Source: https://github.com/afterpack-dev/afterpack/blob/main/packages/cli/README.md Run afterpack via npx on a build directory or a single file, with options like --preset and --seed, plus verify, restore, and audit commands. Use afterpack@latest to avoid cached versions; --help lists common options and --help --all lists all. ```sh npx afterpack@latest dist # a build directory, walked recursively npx afterpack@latest dist/bundle.js # or one .js, .mjs or .cjs file npx afterpack@latest dist --preset=hard --seed=git npx afterpack@latest verify . # check a build before you deploy it npx afterpack@latest restore # undo the last run npx afterpack@latest audit example.com # scan a live site ``` -------------------------------- ### Run the e2e suite with pnpm scripts Source: https://github.com/afterpack-dev/afterpack/blob/main/e2e/README.md Commands to install fixture dependencies, run quick tests, run all tests, or build only. The build step always covers the whole selection; arguments after the script name go to playwright test. ```bash pnpm e2e:install # npm ci in each fixture; skips a fixture whose lockfile has not changed ``` ```bash pnpm e2e:quick # build the fixtures, then run the @quick tests in Chromium ``` ```bash pnpm e2e # build the fixtures, then run every test (Chromium unless told otherwise) ``` ```bash pnpm e2e:build # build only; `npx playwright test …` then reruns against those builds ``` -------------------------------- ### Afterpack package manager commands Source: https://github.com/afterpack-dev/afterpack/blob/main/AGENTS.md Core pnpm commands for installing, building, testing, linting, typechecking, and hygiene checks. The e2e command builds every e2e fixture then runs Playwright in Chromium; set AFTERPACK_E2E_BROWSERS=chromium,firefox,webkit for all three browsers as CI does. Run pnpm e2e:install first and pnpm e2e:quick for the PR subset. CI fails on pnpm hygiene and pnpm check:comments. ```bash pnpm install pnpm build # every package, in dependency order pnpm test # unit tests pnpm e2e # build every e2e fixture, then Playwright in Chromium; set # AFTERPACK_E2E_BROWSERS=chromium,firefox,webkit for all three, as CI's full lane # does (pnpm e2e:quick for the PR subset; pnpm e2e:install first; e2e/README.md) pnpm lint:fix # biome, autofixing — run after any file change pnpm typecheck # after a build: plugins typecheck against built declarations pnpm hygiene # repo hygiene guardrail; CI fails on it pnpm check:comments # no explanatory comments anywhere; CI enforces it ``` -------------------------------- ### Install @afterpack/astro with npm Source: https://github.com/afterpack-dev/afterpack/blob/main/packages/astro/README.md Install the integration as a dev dependency for Astro 4, 5, and 6 projects. ```sh npm install --save-dev @afterpack/astro ``` -------------------------------- ### Install @afterpack/esbuild with npm Source: https://github.com/afterpack-dev/afterpack/blob/main/packages/esbuild/README.md Install the plugin as a development dependency using npm. ```sh npm install --save-dev @afterpack/esbuild ``` -------------------------------- ### afterpack.json configuration example Source: https://github.com/afterpack-dev/afterpack/blob/main/packages/parcel/README.md Place configuration in afterpack.json at the project root. Environment variables prefixed with AFTERPACK_ override these file values. Unknown or misspelled keys fail the build and name the correct spelling. ```json { "preset": "medium", "seed": "git" } ``` -------------------------------- ### Install @afterpack/svelte with npm Source: https://github.com/afterpack-dev/afterpack/blob/main/packages/svelte/README.md Install the package as a development dependency for a Svelte 5 project built with Vite. ```sh npm install --save-dev @afterpack/svelte ``` -------------------------------- ### Install @afterpack/vite with npm Source: https://github.com/afterpack-dev/afterpack/blob/main/packages/vite/README.md Install the plugin as a dev dependency for use in a Vite project. ```sh npm install --save-dev @afterpack/vite ``` -------------------------------- ### afterpack.json configuration example Source: https://github.com/afterpack-dev/afterpack/blob/main/packages/cli/SKILL.md Shared by the CLI and every plugin, takes the whole schema, nested. Shows preset, seed, paths.exclude, and identifiers.reserved with a glob-based reserved entry. ```json { "preset": "hard", "seed": "git", "paths": { "exclude": ["**/*.min.js", "dist/vendor/**"] }, "identifiers": { "reserved": ["Hls", { "glob": "src/legacy/**", "names": ["jQuery"] }] } } ``` -------------------------------- ### Install @afterpack/nuxt with npm Source: https://github.com/afterpack-dev/afterpack/blob/main/packages/nuxt/README.md Install the Nuxt module as a development dependency. ```sh npm install --save-dev @afterpack/nuxt ``` -------------------------------- ### afterpackVite with preset and seed options Source: https://github.com/afterpack-dev/afterpack/blob/main/packages/vite/README.md Example of passing options to afterpackVite. The preset can be "minify", "light", "medium", "hard", or "extreme"; seed "git" uses the current commit. ```ts afterpackVite({ preset: "hard", seed: "git" }); ``` -------------------------------- ### withAfterpack options example Source: https://github.com/afterpack-dev/afterpack/blob/main/packages/electron/README.md Call withAfterpack with a preset and seed to configure AfterPack for Vite builds. The preset defaults to 'light' and the seed defaults to a new random seed per build. ```typescript withAfterpack(config, { preset: "hard", seed: "git" }); ``` -------------------------------- ### Install @afterpack/next Source: https://github.com/afterpack-dev/afterpack/blob/main/packages/next/README.md Install the package as a dev dependency. Requires Next.js 15.4 or later. ```sh npm install --save-dev @afterpack/next ``` -------------------------------- ### Install @afterpack/webpack with npm Source: https://github.com/afterpack-dev/afterpack/blob/main/packages/webpack/README.md Install the plugin as a dev dependency for webpack 5 projects. ```sh npm install --save-dev @afterpack/webpack ``` -------------------------------- ### Install @afterpack/parcel-optimizer Source: https://github.com/afterpack-dev/afterpack/blob/main/packages/parcel/README.md Install the optimizer as a dev dependency. Parcel requires optimizer packages to be named @afterpack/parcel-optimizer. ```sh npm install --save-dev @afterpack/parcel-optimizer ``` -------------------------------- ### Install @afterpack/electron Source: https://github.com/afterpack-dev/afterpack/blob/main/packages/electron/README.md Install the package as a dev dependency for use with electron-vite or Electron Forge. ```sh npm install --save-dev @afterpack/electron ``` -------------------------------- ### Install @afterpack/vue Source: https://github.com/afterpack-dev/afterpack/blob/main/packages/vue/README.md Install the plugin as a dev dependency for a Vue 3 project built with Vite. ```sh npm install --save-dev @afterpack/vue ``` -------------------------------- ### Install @afterpack/rollup with npm Source: https://github.com/afterpack-dev/afterpack/blob/main/packages/rollup/README.md Install the plugin as a development dependency for use in a Rollup 3 or 4 build. ```sh npm install --save-dev @afterpack/rollup ``` -------------------------------- ### afterpack verify command usage examples Source: https://github.com/afterpack-dev/afterpack/blob/main/packages/cli/README.md Checks a build against its protection receipt in `.afterpack/receipts/`. Run it in your deploy step. The command exits `1` when the receipt is missing, belongs to a different build, or a file changed after it was obfuscated. The success line counts JavaScript files the receipt doesn't list, such as a bundle you build without AfterPack into the same directory. ```sh npx afterpack@latest verify . # looks in ./ and ./.next/ npx afterpack@latest verify dist npx afterpack@latest verify build # SvelteKit's adapter copy; also .output/public, out/ ``` -------------------------------- ### Install @afterpack/angular as dev dependency Source: https://github.com/afterpack-dev/afterpack/blob/main/packages/angular/README.md Installs the package as a dev dependency for use in a Node script. ```sh npm install --save-dev @afterpack/angular ``` -------------------------------- ### CLI setup: add afterpack to ng build script Source: https://github.com/afterpack-dev/afterpack/blob/main/packages/angular/README.md Adds the afterpack CLI after ng build in package.json. The command obfuscates the browser bundle at dist/my-app/browser with a seed derived from the current git commit. ```jsonc // package.json { "scripts": { "build": "ng build && afterpack dist/my-app/browser --seed=git" } } ``` -------------------------------- ### Failed obfuscate run JSON output Source: https://github.com/afterpack-dev/afterpack/blob/main/packages/cli/SKILL.md A failure is also a JSON document with the same exit code and a `fix` field to act on. The example shows `exitCode: 3` and `ok: false` with error code `DIAG_SIZE_CAP_REACHED`. ```json { "schemaVersion": 1, "afterpack": "1.0.1", "command": "obfuscate", "exitCode": 3, "ok": false, "error": { "code": "DIAG_SIZE_CAP_REACHED", "message": "…", "fix": "Raise --inflation.max, or lower --complexity, …" } } ``` -------------------------------- ### package.json build script with afterpack Source: https://github.com/afterpack-dev/afterpack/blob/main/packages/cli/SKILL.md Adds an `afterpack dist` step to the `build` script so obfuscation runs after `vite build`. Run it on build output, never on source. ```jsonc // package.json { "scripts": { "build": "vite build && afterpack dist" } } ``` -------------------------------- ### Import and use add, Counter, greet from dist/esm/lib.js Source: https://github.com/afterpack-dev/afterpack/blob/main/packages/rollup/e2e/lib/index.html Imports add, Counter, and greet from the built ESM library, displays greeting and sum, and increments a counter on click, updating the text with even/odd status. ```javascript import { add, Counter, greet } from "./dist/esm/lib.js"; const result = document.querySelector('[data-testid="result"]'); result.textContent = `${greet("AfterPack")} | ${add(2, 3)}`; const counter = document.querySelector('[data-testid="counter"]'); const c = new Counter(); counter.addEventListener("click", () => { const n = c.increment(); counter.textContent = `count is ${n} (${n % 2 === 0 ? "even" : "odd"})`; }); ``` -------------------------------- ### Instantiate AfterpackWebpackPlugin with options Source: https://github.com/afterpack-dev/afterpack/blob/main/packages/webpack/README.md Pass options to the plugin constructor. The `preset` option accepts "minify", "light", "medium", "hard", or "extreme" (default "light"). The `seed` option can be a number, string, or "git" to use the current commit; default is a new random seed per build. ```js new AfterpackWebpackPlugin({ preset: "hard", seed: "git" }); ``` -------------------------------- ### afterpackEsbuild plugin configuration Source: https://github.com/afterpack-dev/afterpack/blob/main/packages/esbuild/README.md Configure the esbuild plugin with a preset and seed. The preset can be "minify", "light", "medium", "hard", or "extreme" (default "light"). The seed can be a number, string, or "git" to use the current commit; otherwise a new random seed is used per build. ```ts afterpackEsbuild({ preset: "hard", seed: "git" }); ``` -------------------------------- ### Build with reporter and verify deploy Source: https://github.com/afterpack-dev/afterpack/blob/main/packages/parcel/README.md Run the build with the reporter to write receipts to .afterpack/receipts/, then verify in the deploy step before upload. afterpack verify fails if a file changed after obfuscation or if no receipt exists. ```sh parcel build index.html --reporter @afterpack/parcel-optimizer/reporter npx afterpack@latest verify dist # in the deploy step, before the upload ``` -------------------------------- ### Run a single Firefox test repeatedly with AFTERPACK_E2E_BROWSERS Source: https://github.com/afterpack-dev/afterpack/blob/main/e2e/README.md Use this command to repeat one Firefox test in isolation. Selecting only the Firefox browser avoids running the whole dependency project, which would otherwise ignore --grep and --repeat-each. ```bash AFTERPACK_E2E_BROWSERS=firefox AFTERPACK_E2E_FIXTURES=vite-react pnpm e2e --grep @scenario --repeat-each 5 ``` -------------------------------- ### afterpack verify [dir] Source: https://github.com/afterpack-dev/afterpack/blob/main/packages/cli/README.md Checks a build against its protection receipt in `.afterpack/receipts/`. Run it in your deploy step. It verifies that every file recorded in the receipt exists and hashes to the value AfterPack wrote, and exits with code 1 if the receipt is missing, belongs to a different build, or a file changed after obfuscation. ```APIDOC ## [CLI] afterpack verify [dir] ### Description Checks a build against its protection receipt in `.afterpack/receipts/`. Run it in your deploy step. It verifies that every file recorded in the receipt exists and hashes to the value AfterPack wrote, and exits with code 1 if the receipt is missing, belongs to a different build, or a file changed after obfuscation. ### Method CLI ### Endpoint afterpack verify [dir] ### Parameters #### Positional Arguments - **dir** (string) - Optional - Directory to verify. Defaults to current directory. Examples: `.`, `dist`, `build`. ### Usage Examples ```sh npx afterpack@latest verify . # looks in ./ and ./.next/ npx afterpack@latest verify dist npx afterpack@latest verify build # SvelteKit's adapter copy; also .output/public, out/ ``` ### Behavior - Checks every file the receipt records: each must be there and hash to the value AfterPack wrote. - Other files in the tree are not checked. - The success line counts the JavaScript files the receipt doesn't list (e.g., `✓ Verified 40 files · dist/ · 27 other JS files aren't in this receipt`). - For a Next.js build the count covers `.next/static/chunks/`. ### Exit Codes - **0** - Success. - **1** - Receipt is missing, belongs to a different build, or a file changed after it was obfuscated. ### Notes - The CLI and the plugins for Vite, Next.js, webpack, Rollup, esbuild and Angular all write a receipt. ``` -------------------------------- ### Dispatch e2e-pro workflow in served mode Source: https://github.com/afterpack-dev/afterpack/blob/main/e2e/README.md Triggers the `.github/workflows/e2e-pro.yml` workflow with `engine=served` to test the candidate as the client of the Pro engine the API serves now. The run is named `E2E Pro ()`. ```bash gh api repos/afterpack-dev/afterpack/dispatches -f event_type=e2e-pro \ -f 'client_payload[version]=0.2.2-rc.202610011200' -f 'client_payload[engine]=served' \ -f 'client_payload[id]=' ``` -------------------------------- ### Pass options to afterpack() Source: https://github.com/afterpack-dev/afterpack/blob/main/packages/astro/README.md Options match @afterpack/vite except `leg` and `projectRoot`. Common options include `preset`, `complexity`, `seed`, `identifiers.reserved`, `paths.exclude`, and `build.autorun`. Options can also be set via `afterpack.json` or `AFTERPACK_*` environment variables; the options object takes precedence over environment variables, which take precedence over the file. ```js integrations: [afterpack({ preset: "medium", seed: "git" })], ``` -------------------------------- ### Render Protection Map from CLI with npx afterpack-protection-map Source: https://github.com/afterpack-dev/afterpack/blob/main/packages/protection-map/README.md Use the bundled command to render a Protection Map HTML file from JSON data. Add --no-lineage to omit per-region transform history for a smaller file. ```sh npx afterpack-protection-map report.json protection-map.html ``` -------------------------------- ### AfterPack CLI commands and options Source: https://github.com/afterpack-dev/afterpack/blob/main/packages/cli/SKILL.md Common AfterPack CLI invocations: obfuscate a directory or file, apply presets and seeds, output diagnostics as JSON, verify, restore, audit, and view help. Always use `afterpack@latest`; bare `npx afterpack` may run a stale cached copy. ```bash npx afterpack@latest dist # a directory, walked recursively npx afterpack@latest dist/bundle.js # or one .js, .mjs or .cjs file npx afterpack@latest dist --preset=hard --seed=git npx afterpack@latest dist --diagnostics.format=json npx afterpack@latest verify . # check before deploying npx afterpack@latest restore # undo the last run npx afterpack@latest audit https://example.com # scan a live site npx afterpack@latest --help # common options npx afterpack@latest --help --all # every option, its type and default ``` -------------------------------- ### Dispatch e2e-pro workflow in candidate mode Source: https://github.com/afterpack-dev/afterpack/blob/main/e2e/README.md Triggers the `.github/workflows/e2e-pro.yml` workflow with the default `engine=candidate` to test the candidate's own Pro engine. Requires `client_payload[sha]` to be the engine commit that the API must serve. The run is named `E2E Pro ()`. ```bash gh api repos/afterpack-dev/afterpack/dispatches -f event_type=e2e-pro \ -f 'client_payload[version]=0.2.2-rc.202610011200' -f 'client_payload[sha]=' \ -f 'client_payload[id]=' ``` -------------------------------- ### Call afterpackRollup with preset and seed options Source: https://github.com/afterpack-dev/afterpack/blob/main/packages/rollup/README.md Pass options to the plugin. The preset can be "minify", "light", "medium", "hard", or "extreme" (default "light"); seed "git" uses the current commit. Options can also be set via afterpack.json or AFTERPACK_* environment variables, with the options object taking precedence. ```js afterpackRollup({ preset: "hard", seed: "git" }); ``` -------------------------------- ### Run AfterPack CLI on a build output directory Source: https://github.com/afterpack-dev/afterpack/blob/main/readme.md Obfuscates the JavaScript in the specified output directory (e.g., dist/, build/, out/) or a single .js, .mjs, or .cjs file. Use `npx afterpack@latest verify .` to check a build before deployment, and `--help` to list options. ```bash npx afterpack@latest dist ``` -------------------------------- ### Configure afterpackSveltekit in vite.config.ts Source: https://github.com/afterpack-dev/afterpack/blob/main/packages/sveltekit/README.md Add afterpackSveltekit() after sveltekit() in the Vite plugins array. Every JavaScript chunk from the adapter build is obfuscated before Vite writes it, on both client and server builds. A failed run fails the build. ```ts // vite.config.ts import { sveltekit } from "@sveltejs/kit/vite"; import { afterpackSveltekit } from "@afterpack/sveltekit"; import { defineConfig } from "vite"; export default defineConfig({ plugins: [sveltekit(), afterpackSveltekit()], }); ``` -------------------------------- ### Configure @afterpack/astro in astro.config.mjs Source: https://github.com/afterpack-dev/afterpack/blob/main/packages/astro/README.md Add the integration to the Astro config. The default export and the named `afterpackAstro` export are the same function. It obfuscates browser JavaScript (islands and client scripts) and server/prerender builds for `output: "server"` or hybrid apps; a failed run fails the build. ```js // astro.config.mjs import { defineConfig } from "astro/config"; import afterpack from "@afterpack/astro"; export default defineConfig({ integrations: [afterpack()], }); ``` -------------------------------- ### Dispatch e2e-candidate workflow via gh api Source: https://github.com/afterpack-dev/afterpack/blob/main/e2e/README.md Triggers the `.github/workflows/e2e-candidate.yml` workflow manually or via `repository_dispatch` of type `e2e-candidate`. The `client_payload[version]` is the candidate release version (e.g., `0.2.2-rc.202610011200`) and `client_payload[id]` is the caller's run ID, used to name the run `E2E candidate ()`. ```bash gh api repos/afterpack-dev/afterpack/dispatches -f event_type=e2e-candidate \ -f 'client_payload[version]=0.2.2-rc.202610011200' -f 'client_payload[id]=' ``` -------------------------------- ### Configure .parcelrc to use the optimizer Source: https://github.com/afterpack-dev/afterpack/blob/main/packages/parcel/README.md Add the optimizer to the optimizers list for JavaScript bundles. Keep the "..." so Parcel's minifier runs first and AfterPack last. If obfuscation fails, the build fails. ```jsonc // .parcelrc { "extends": "@parcel/config-default", "optimizers": { "*.{js,mjs,cjs}": ["...", "@afterpack/parcel-optimizer"] } } ``` -------------------------------- ### Use afterpackEsbuild plugin in esbuild build script Source: https://github.com/afterpack-dev/afterpack/blob/main/packages/esbuild/README.md Add the plugin to the esbuild build configuration. Both outdir and outfile work. Builds with write: false or that already failed are skipped. If obfuscation fails, the build fails. ```ts // build.ts import { build } from "esbuild"; import { afterpackEsbuild } from "@afterpack/esbuild"; await build({ entryPoints: ["src/index.ts"], outdir: "dist", bundle: true, plugins: [afterpackEsbuild()], }); ``` -------------------------------- ### electron-vite config with withAfterpack Source: https://github.com/afterpack-dev/afterpack/blob/main/packages/electron/README.md Wrap the electron-vite config with withAfterpack to add AfterPack to main, preload, and renderer bundles. Obfuscation runs before Vite writes each bundle; build fails if obfuscation fails. ```ts // electron.vite.config.ts import { withAfterpack } from "@afterpack/electron"; import { defineConfig, externalizeDepsPlugin } from "electron-vite"; export default withAfterpack( defineConfig({ main: { plugins: [externalizeDepsPlugin()] }, preload: { plugins: [externalizeDepsPlugin()] }, renderer: {}, }), ); ``` -------------------------------- ### Configure afterpackVite in vite.config.ts Source: https://github.com/afterpack-dev/afterpack/blob/main/packages/vite/README.md Add the plugin to the Vite config to obfuscate all JavaScript chunks during build. If obfuscation fails, the build fails and the output directory is left untouched. ```ts // vite.config.ts import { defineConfig } from "vite"; import { afterpackVite } from "@afterpack/vite"; export default defineConfig({ plugins: [afterpackVite()], }); ``` -------------------------------- ### Pending placeholder Source: https://github.com/afterpack-dev/afterpack/blob/main/packages/rollup/e2e/lib/index.html Placeholder text shown in the fixture before the actual code is inserted. ```text pending ``` -------------------------------- ### afterpack restore [dir] Source: https://github.com/afterpack-dev/afterpack/blob/main/packages/cli/README.md Puts back the original files from `.afterpack/backups/` under their original names and undoes a run that stopped partway. It restores only when every file still holds its original bytes or the bytes the run was about to write; otherwise it names the rebuilt files and exits with code 1. ```APIDOC ## [CLI] afterpack restore [dir] ### Description Puts back the original files from `.afterpack/backups/` under their original names and undoes a run that stopped partway. It restores only when every file still holds its original bytes or the bytes the run was about to write; otherwise it names the rebuilt files and exits with code 1. ### Method CLI ### Endpoint afterpack restore [dir] ### Parameters #### Positional Arguments - **dir** (string) - Optional - Build directory to restore. Point restore at one build directory to undo only the run over it. ### Behavior - A run that stopped partway is undone only while every file still holds its original bytes or the bytes the run was about to write. - Once the output is rebuilt, the next `afterpack` run discards that backup and says so. - When only part of the output was rebuilt, nothing is discarded or restored, and the run names the rebuilt files. - A file that changed since the run is named, nothing is restored, and the command exits `1`. ### Exit Codes - **0** - Success. - **1** - A file changed since the run; nothing is restored. ### Limitations - AfterPack does not fsync what it writes, so a power loss during a run or a restore can leave files that neither the backup nor `afterpack verify` can vouch for; rebuild after one. ``` -------------------------------- ### Successful obfuscate run JSON output Source: https://github.com/afterpack-dev/afterpack/blob/main/packages/cli/SKILL.md Use this JSON document when parsing `--diagnostics.format=json` output from the `obfuscate` command. Stdout carries exactly one JSON document with no colour or progress; everything else goes to stderr. `status` is `obfuscated`, `unchanged`, or `failed`. ```json { "schemaVersion": 1, "afterpack": "1.0.1", "command": "obfuscate", "exitCode": 0, "ok": true, "files": [ { "path": "dist/app.js", "status": "obfuscated", "bytesIn": 4211, "bytesOut": 15980, "diagnostics": [] } ], "diagnostics": [{ "code": "DIAG_TARGET_REACHED", "level": "info", "message": "…", "file": "dist/app.js" }], "summary": { "files": 1, "transformed": 1, "seed": 4242, "engine": "local", "diagnostics": { "total": 1 } }, "artifacts": { "protectionMap": ".afterpack/protectionMap.html" } } ``` -------------------------------- ### Render Protection Map from Node with renderProtectionMapHtml Source: https://github.com/afterpack-dev/afterpack/blob/main/packages/protection-map/README.md Use renderProtectionMapHtml(data, { template, includeLineage }) to generate HTML from Protection Map data. It uses the bundled template unless you pass one, and includes lineage unless includeLineage is false. ```js import { writeFileSync } from "node:fs"; import { renderProtectionMapHtml } from "@afterpack/protection-map"; const { html } = renderProtectionMapHtml(data); writeFileSync("protection-map.html", html); ``` -------------------------------- ### Configure afterpackRollup in rollup.config.js Source: https://github.com/afterpack-dev/afterpack/blob/main/packages/rollup/README.md Add the plugin to your Rollup configuration. It runs last, obfuscating each JavaScript chunk before Rollup writes it; the readable bundle never reaches disk. If obfuscation fails, the build fails and the output directory is left untouched. ```js // rollup.config.js import { afterpackRollup } from "@afterpack/rollup"; export default { input: "src/index.ts", output: { dir: "dist", format: "esm" }, plugins: [afterpackRollup()], }; ``` -------------------------------- ### afterpack restore command usage Source: https://github.com/afterpack-dev/afterpack/blob/main/packages/cli/SKILL.md Restores original files from .afterpack/backups/ under their original names. Skips and names any file that changed since the run, exiting 1 if any were skipped. With no backup, exits 1. ```bash npx afterpack@latest restore # every backup under the project root's .afterpack/backups/ npx afterpack@latest restore dist ``` -------------------------------- ### electron-builder files config to exclude .afterpack Source: https://github.com/afterpack-dev/afterpack/blob/main/packages/electron/README.md Add these entries to the electron-builder 'files' array to exclude the AfterPack Protection Map and backup files from the packaged app. The plugin prints a reminder when it finds a packager config. ```jsonc "files": ["**/*", "!.afterpack/**", "!**/*.backup.*", "!**/*.map"] ``` -------------------------------- ### Electron Forge packagerConfig ignore for .afterpack Source: https://github.com/afterpack-dev/afterpack/blob/main/packages/electron/README.md Add these ignore patterns to the Electron Forge packagerConfig to exclude the AfterPack Protection Map and backup files from the packaged app. The plugin prints a reminder when it finds a packager config. ```javascript packagerConfig: { ignore: [/^\/\.afterpack/, /\.backup\./, /\.map$/] } ``` -------------------------------- ### Pin seed with AFTERPACK_SEED Source: https://github.com/afterpack-dev/afterpack/blob/main/packages/electron/README.md Set the AFTERPACK_SEED environment variable to pin the seed when build scripts run each part as a separate command, ensuring all parts share the same seed. ```sh AFTERPACK_SEED=git npm run build ``` -------------------------------- ### Electron Forge Vite config with afterpackElectron Source: https://github.com/afterpack-dev/afterpack/blob/main/packages/electron/README.md Add the afterpackElectron plugin to each Vite config in Electron Forge, specifying the leg (main, preload, or renderer). The leg is required. ```ts // vite.main.config.ts (and the same in vite.preload and vite.renderer, with their leg) import { afterpackElectron } from "@afterpack/electron"; export default { plugins: [afterpackElectron({ leg: "main" })] }; ``` -------------------------------- ### Declare a scenario test with scenario(journey) Source: https://github.com/afterpack-dev/afterpack/blob/main/e2e/README.md Declares a Playwright test tagged @scenario that runs the given journey against both the baseline and protected builds. The journey uses goto, checkpoint, and inPlace helpers instead of page.goto/page.reload so steps wait for the fixture's smoke.readySelector. ```TypeScript import { expect, test } from "@playwright/test"; import { type ScenarioSteps, scenario } from "@e2e/helpers/scenario.js"; const journey: ScenarioSteps = async ({ page, goto, checkpoint, inPlace }) => { await goto("/"); await inPlace("the Notes link", async () => { await page.getByRole("link", { name: "Notes" }).click(); await expect(page.getByRole("heading", { name: "Notes" })).toBeVisible(); }); await checkpoint("notes"); }; test("the notes journey matches the baseline", { tag: "@scenario" }, scenario(journey)); ``` -------------------------------- ### afterpack audit Source: https://github.com/afterpack-dev/afterpack/blob/main/packages/cli/SKILL.md Scans a deployed site for leaked secrets, exposed source maps, and unprotected JavaScript. Streams findings as they arrive and prints a link to the full report. ```APIDOC ## [CLI] afterpack audit ### Description Scans a deployed site for leaked secrets, exposed source maps and unprotected JavaScript, streams findings as they arrive, and prints a link to the full report. A bare host gets `https://`. It sends only the URL and writes nothing. A finished scan exits `0` however much it found; a failed scan exits `1`. Anonymous use is rate-limited per 24 hours. Docs: https://www.afterpack.dev/docs/audit ### Usage ```bash npx afterpack@latest audit ``` ### Parameters #### Positional Arguments - **url** (string) - Required - The URL of the deployed site to scan. A bare host gets `https://` prepended. ### Exit Codes - `0` - Scan completed successfully (regardless of findings). - `1` - Scan failed. ``` -------------------------------- ### Configure afterpackSvelte in vite.config.ts Source: https://github.com/afterpack-dev/afterpack/blob/main/packages/svelte/README.md Add the afterpackSvelte plugin to the Vite config. Every JavaScript chunk is obfuscated before Vite writes it, and a failed run fails the build. The plugin accepts the same options as @afterpack/vite, e.g. afterpackSvelte({ preset: "hard", seed: "git" }). ```ts // vite.config.ts import { defineConfig } from "vite"; import { svelte } from "@sveltejs/vite-plugin-svelte"; import { afterpackSvelte } from "@afterpack/svelte"; export default defineConfig({ plugins: [svelte(), afterpackSvelte()], }); ``` -------------------------------- ### Wrap Next.js config with withAfterpack Source: https://github.com/afterpack-dev/afterpack/blob/main/packages/next/README.md Wrap the Next.js config with withAfterpack to obfuscate client JavaScript during next build. Works with Turbopack or webpack, App Router or Pages Router, and static export. A function config is also supported: withAfterpack(async (phase, ctx) => ({ ... })). ```ts // next.config.ts import type { NextConfig } from "next"; import { withAfterpack } from "@afterpack/next"; const nextConfig: NextConfig = { /* your config */ }; export default withAfterpack(nextConfig); ``` -------------------------------- ### Configure @afterpack/nuxt in nuxt.config.ts Source: https://github.com/afterpack-dev/afterpack/blob/main/packages/nuxt/README.md Add the module to Nuxt's modules array and set the afterpack option with a seed. The module obfuscates all JavaScript chunks during Vite build, including client bundles and prerendered output. A failed run fails the build. ```ts // nuxt.config.ts export default defineNuxtConfig({ modules: ["@afterpack/nuxt"], afterpack: { seed: "git", }, }); ``` -------------------------------- ### Node script: afterpackAngular with seed Source: https://github.com/afterpack-dev/afterpack/blob/main/packages/angular/README.md Runs AfterPack over the Angular browser bundle from a Node script. Finds dist//browser automatically. Each JavaScript file is obfuscated in place; the promise rejects if obfuscation fails. ```ts // scripts/obfuscate.mjs, run after ng build import { afterpackAngular } from "@afterpack/angular"; await afterpackAngular({ seed: "git" }); ``` -------------------------------- ### Configure AfterpackWebpackPlugin in webpack.config.mjs Source: https://github.com/afterpack-dev/afterpack/blob/main/packages/webpack/README.md Add the plugin to the webpack plugins array. It obfuscates each JavaScript asset at the last step before writing to disk, so the readable bundle is never written. Hot-update chunks and assets copied by other plugins are left alone. If obfuscation fails, the build fails. ```js // webpack.config.mjs import { AfterpackWebpackPlugin } from "@afterpack/webpack"; export default { // ... plugins: [new AfterpackWebpackPlugin()], }; ``` -------------------------------- ### Configure afterpackVue in vite.config.ts Source: https://github.com/afterpack-dev/afterpack/blob/main/packages/vue/README.md Add the afterpackVue plugin to your Vite configuration. Every JavaScript chunk is obfuscated before Vite writes it, and a failed run fails the build. The plugin accepts the same options as @afterpack/vite, e.g., afterpackVue({ preset: "hard", seed: "git" }). ```ts // vite.config.ts import { defineConfig } from "vite"; import vue from "@vitejs/plugin-vue"; import { afterpackVue } from "@afterpack/vue"; export default defineConfig({ plugins: [vue(), afterpackVue()], }); ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.