@afterpack/next 0.2.0-rc.20260930T1421 → 0.2.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -32,8 +32,8 @@ and if obfuscation fails, `next build` fails.
32
32
 
33
33
  AfterPack obfuscates the client chunks in `.next/static/chunks`. With `output: "export"`, the
34
34
  obfuscated chunks are what lands in `out/`. Server code in `.next/server` never reaches the browser
35
- and is left as is. The plugin also removes `.js.map` files from the client output, since a served
36
- source map gives your source away.
35
+ and is left as is. The plugin also removes the `.js.map` and `.css.map` files from `.next/static`, and
36
+ the comments that point at them, since a served source map gives your source away.
37
37
 
38
38
  ## Check a deploy
39
39
 
package/dist/index.cjs CHANGED
@@ -45,27 +45,28 @@ function detectBundler(distDir) {
45
45
  if ((0, node_fs.existsSync)((0, node_path.join)(distDir, "server", "webpack-runtime.js"))) return "webpack";
46
46
  return "unknown";
47
47
  }
48
- function stripDanglingTrailer(js) {
48
+ function stripTrailer(path, strip) {
49
49
  try {
50
- const code = (0, node_fs.readFileSync)(js, "utf8");
51
- const stripped = (0, __afterpack_integration_utils.withSourceMappingURL)(code, null);
50
+ const code = (0, node_fs.readFileSync)(path, "utf8");
51
+ const stripped = strip(code);
52
52
  if (stripped === code) return false;
53
- (0, node_fs.writeFileSync)(js, stripped);
53
+ (0, node_fs.writeFileSync)(path, stripped);
54
54
  return true;
55
55
  } catch {
56
56
  return false;
57
57
  }
58
58
  }
59
- function stripServedSourceMaps(chunks, chunksDir, log = (message) => console.log(message)) {
59
+ function stripServedSourceMaps(chunks, servedDir, log = (message) => console.log(message)) {
60
60
  let removed = 0;
61
- for (const mapPath of (0, __afterpack_integration_utils.collectSourceMaps)(chunksDir)) try {
61
+ for (const mapPath of (0, __afterpack_integration_utils.collectSourceMaps)(servedDir)) try {
62
62
  (0, node_fs.unlinkSync)(mapPath);
63
63
  removed++;
64
64
  } catch (e) {
65
65
  console.warn(`[${LABEL}] could not remove served source map ${mapPath}: ${e}`);
66
66
  }
67
67
  let trailers = 0;
68
- for (const js of chunks) if (stripDanglingTrailer(js)) trailers++;
68
+ for (const js of chunks) if (stripTrailer(js, (code) => (0, __afterpack_integration_utils.withSourceMappingURL)(code, null))) trailers++;
69
+ for (const css of (0, __afterpack_integration_utils.collectStylesheets)(servedDir)) if (stripTrailer(css, __afterpack_integration_utils.withoutCssSourceMappingURL)) trailers++;
69
70
  if (removed > 0 || trailers > 0) {
70
71
  const tail = trailers > 0 ? ` + ${trailers} sourceMappingURL trailer(s)` : "";
71
72
  log(`[${LABEL}] stripped ${removed} served source map(s)${tail} from the client tree`);
@@ -113,7 +114,7 @@ async function runAfterpackHook(input) {
113
114
  ...(0, __afterpack_integration_utils.passSettings)(resolved),
114
115
  postMinify: true,
115
116
  afterWrite: () => {
116
- stripServedSourceMaps(files, chunksDir, settings.diagnostics?.level === "none" ? () => {} : (message) => console.log(message));
117
+ stripServedSourceMaps(files, (0, node_path.join)(distDir, "static"), settings.diagnostics?.level === "none" ? () => {} : (message) => console.log(message));
117
118
  },
118
119
  receipt: {
119
120
  bundler: detectBundler(distDir),
package/dist/index.js CHANGED
@@ -1,6 +1,6 @@
1
1
  import { existsSync, readFileSync, unlinkSync, writeFileSync } from "node:fs";
2
2
  import { dirname, join, resolve } from "node:path";
3
- import { collectJsFiles, collectSourceMaps, createTelemetryReporter, passSettings, resolveClientIdentity, resolvePluginConfig, runObfuscationPass, withSourceMappingURL } from "@afterpack/integration-utils";
3
+ import { collectJsFiles, collectSourceMaps, collectStylesheets, createTelemetryReporter, passSettings, resolveClientIdentity, resolvePluginConfig, runObfuscationPass, withSourceMappingURL, withoutCssSourceMappingURL } from "@afterpack/integration-utils";
4
4
 
5
5
  //#region src/hook.ts
6
6
  const LABEL = "afterpack-next";
@@ -22,27 +22,28 @@ function detectBundler(distDir) {
22
22
  if (existsSync(join(distDir, "server", "webpack-runtime.js"))) return "webpack";
23
23
  return "unknown";
24
24
  }
25
- function stripDanglingTrailer(js) {
25
+ function stripTrailer(path, strip) {
26
26
  try {
27
- const code = readFileSync(js, "utf8");
28
- const stripped = withSourceMappingURL(code, null);
27
+ const code = readFileSync(path, "utf8");
28
+ const stripped = strip(code);
29
29
  if (stripped === code) return false;
30
- writeFileSync(js, stripped);
30
+ writeFileSync(path, stripped);
31
31
  return true;
32
32
  } catch {
33
33
  return false;
34
34
  }
35
35
  }
36
- function stripServedSourceMaps(chunks, chunksDir, log = (message) => console.log(message)) {
36
+ function stripServedSourceMaps(chunks, servedDir, log = (message) => console.log(message)) {
37
37
  let removed = 0;
38
- for (const mapPath of collectSourceMaps(chunksDir)) try {
38
+ for (const mapPath of collectSourceMaps(servedDir)) try {
39
39
  unlinkSync(mapPath);
40
40
  removed++;
41
41
  } catch (e) {
42
42
  console.warn(`[${LABEL}] could not remove served source map ${mapPath}: ${e}`);
43
43
  }
44
44
  let trailers = 0;
45
- for (const js of chunks) if (stripDanglingTrailer(js)) trailers++;
45
+ for (const js of chunks) if (stripTrailer(js, (code) => withSourceMappingURL(code, null))) trailers++;
46
+ for (const css of collectStylesheets(servedDir)) if (stripTrailer(css, withoutCssSourceMappingURL)) trailers++;
46
47
  if (removed > 0 || trailers > 0) {
47
48
  const tail = trailers > 0 ? ` + ${trailers} sourceMappingURL trailer(s)` : "";
48
49
  log(`[${LABEL}] stripped ${removed} served source map(s)${tail} from the client tree`);
@@ -90,7 +91,7 @@ async function runAfterpackHook(input) {
90
91
  ...passSettings(resolved),
91
92
  postMinify: true,
92
93
  afterWrite: () => {
93
- stripServedSourceMaps(files, chunksDir, settings.diagnostics?.level === "none" ? () => {} : (message) => console.log(message));
94
+ stripServedSourceMaps(files, join(distDir, "static"), settings.diagnostics?.level === "none" ? () => {} : (message) => console.log(message));
94
95
  },
95
96
  receipt: {
96
97
  bundler: detectBundler(distDir),
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@afterpack/next",
3
- "version": "0.2.0-rc.20260930T1421",
3
+ "version": "0.2.1",
4
4
  "description": "Next.js integration for AfterPack: obfuscate the client JavaScript of a Next.js build inside next build",
5
5
  "type": "module",
6
6
  "main": "./dist/index.cjs",
@@ -28,8 +28,8 @@
28
28
  "next": ">=15.4.0"
29
29
  },
30
30
  "dependencies": {
31
- "@afterpack/core": "~0.2.0",
32
- "@afterpack/integration-utils": "0.2.0-rc.20260930T1421"
31
+ "@afterpack/core": "~0.2.2",
32
+ "@afterpack/integration-utils": "0.2.1"
33
33
  },
34
34
  "devDependencies": {
35
35
  "@biomejs/biome": "2.4.4",