@afterpack/webpack 0.2.0 → 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 +1 -1
- package/dist/index.cjs +12 -0
- package/dist/index.js +13 -1
- package/package.json +3 -3
package/README.md
CHANGED
|
@@ -44,7 +44,7 @@ new AfterpackWebpackPlugin({ preset: "hard", seed: "git" });
|
|
|
44
44
|
| [`seed`][seed] | a number or string; `"git"` uses the current commit | a new random seed per build |
|
|
45
45
|
| [`identifiers.reserved`][identifiers.reserved] | names never to rename | none |
|
|
46
46
|
| [`paths.exclude`][paths.exclude] | globs for files to leave untouched | none |
|
|
47
|
-
| [`sourceMap.enabled`][sourceMap.enabled] | write source maps for the obfuscated output | on in development when webpack emits a map, off in production |
|
|
47
|
+
| [`sourceMap.enabled`][sourceMap.enabled] | write source maps for the obfuscated output; off also drops the build's CSS maps | on in development when webpack emits a map, off in production |
|
|
48
48
|
| [`protectionMap.enabled`][protectionMap.enabled] | write the Protection Map | on when `devtool` emits source maps |
|
|
49
49
|
| [`build.autorun`][build.autorun] | `false` turns AfterPack off | `true` |
|
|
50
50
|
|
package/dist/index.cjs
CHANGED
|
@@ -30,6 +30,7 @@ const __afterpack_integration_utils = __toESM(require("@afterpack/integration-ut
|
|
|
30
30
|
const PLUGIN_NAME = "AfterpackWebpackPlugin";
|
|
31
31
|
const EMITTED_JS_RE = /\.(?:js|mjs|cjs)$/;
|
|
32
32
|
const SOURCE_MODULE_RE = /\.(?:m?[jt]sx?)$/;
|
|
33
|
+
const CSS_MAP_RE = /\.css\.map$/;
|
|
33
34
|
const PATHS_INCLUDE_UNSUPPORTED = "this plugin obfuscates the assets webpack's own chunks claim, in the pipeline — there is no output-directory walk for a glob to re-admit anything into. Use `npx afterpack <dir> --paths.include=...` for a disk walk, or drop the key.";
|
|
34
35
|
function isEmittedJs(name) {
|
|
35
36
|
return !name.includes(".hot-update.") && EMITTED_JS_RE.test(name);
|
|
@@ -48,6 +49,16 @@ function inputSourceMap(compilation, asset) {
|
|
|
48
49
|
const dir = asset.name.includes("/") ? `${asset.name.replace(/\/[^/]*$/, "")}/` : "";
|
|
49
50
|
return assetText(compilation, `${dir}${asset.url}`.replace(/^\.\//, ""));
|
|
50
51
|
}
|
|
52
|
+
function stripCssSourceMaps(compilation, RawSource) {
|
|
53
|
+
for (const { name } of compilation.getAssets()) if (CSS_MAP_RE.test(name)) compilation.deleteAsset(name);
|
|
54
|
+
for (const { name } of compilation.getAssets()) {
|
|
55
|
+
if (!name.endsWith(".css")) continue;
|
|
56
|
+
const css = assetText(compilation, name);
|
|
57
|
+
if (css == null) continue;
|
|
58
|
+
const stripped = (0, __afterpack_integration_utils.withoutCssSourceMappingURL)(css);
|
|
59
|
+
if (stripped !== css) compilation.updateAsset(name, new RawSource(stripped));
|
|
60
|
+
}
|
|
61
|
+
}
|
|
51
62
|
function chunkClaimedJsAssets(compilation) {
|
|
52
63
|
const names = new Set();
|
|
53
64
|
for (const chunk of compilation.chunks) for (const name of chunk.files) if (isEmittedJs(name)) names.add(name);
|
|
@@ -188,6 +199,7 @@ var AfterpackWebpackPlugin = class {
|
|
|
188
199
|
else compilation.emitAsset(mapName, map);
|
|
189
200
|
} else if (asset.mapName && compilation.getAsset(asset.mapName)) compilation.deleteAsset(asset.mapName);
|
|
190
201
|
}
|
|
202
|
+
if (!result.policy.sourceMap) stripCssSourceMaps(compilation, RawSource);
|
|
191
203
|
if (result.deferredReceipt) this.deferredReceiptByCompilation.set(compilation, result.deferredReceipt);
|
|
192
204
|
}
|
|
193
205
|
capture(resource, context) {
|
package/dist/index.js
CHANGED
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
import { readFileSync } from "node:fs";
|
|
2
2
|
import { basename, join, relative } from "node:path";
|
|
3
3
|
import { processBatch, version } from "@afterpack/core";
|
|
4
|
-
import { createTelemetryReporter, decodeDataUri, extractSourceMappingURL, passSettings, resolveClientIdentity, resolvePluginConfig, runObfuscationPass, scanDirectives, withSourceMappingURL, writeDeferredProtectionReceipt } from "@afterpack/integration-utils";
|
|
4
|
+
import { createTelemetryReporter, decodeDataUri, extractSourceMappingURL, passSettings, resolveClientIdentity, resolvePluginConfig, runObfuscationPass, scanDirectives, withSourceMappingURL, withoutCssSourceMappingURL, writeDeferredProtectionReceipt } from "@afterpack/integration-utils";
|
|
5
5
|
|
|
6
6
|
//#region src/index.ts
|
|
7
7
|
const PLUGIN_NAME = "AfterpackWebpackPlugin";
|
|
8
8
|
const EMITTED_JS_RE = /\.(?:js|mjs|cjs)$/;
|
|
9
9
|
const SOURCE_MODULE_RE = /\.(?:m?[jt]sx?)$/;
|
|
10
|
+
const CSS_MAP_RE = /\.css\.map$/;
|
|
10
11
|
const PATHS_INCLUDE_UNSUPPORTED = "this plugin obfuscates the assets webpack's own chunks claim, in the pipeline — there is no output-directory walk for a glob to re-admit anything into. Use `npx afterpack <dir> --paths.include=...` for a disk walk, or drop the key.";
|
|
11
12
|
function isEmittedJs(name) {
|
|
12
13
|
return !name.includes(".hot-update.") && EMITTED_JS_RE.test(name);
|
|
@@ -25,6 +26,16 @@ function inputSourceMap(compilation, asset) {
|
|
|
25
26
|
const dir = asset.name.includes("/") ? `${asset.name.replace(/\/[^/]*$/, "")}/` : "";
|
|
26
27
|
return assetText(compilation, `${dir}${asset.url}`.replace(/^\.\//, ""));
|
|
27
28
|
}
|
|
29
|
+
function stripCssSourceMaps(compilation, RawSource) {
|
|
30
|
+
for (const { name } of compilation.getAssets()) if (CSS_MAP_RE.test(name)) compilation.deleteAsset(name);
|
|
31
|
+
for (const { name } of compilation.getAssets()) {
|
|
32
|
+
if (!name.endsWith(".css")) continue;
|
|
33
|
+
const css = assetText(compilation, name);
|
|
34
|
+
if (css == null) continue;
|
|
35
|
+
const stripped = withoutCssSourceMappingURL(css);
|
|
36
|
+
if (stripped !== css) compilation.updateAsset(name, new RawSource(stripped));
|
|
37
|
+
}
|
|
38
|
+
}
|
|
28
39
|
function chunkClaimedJsAssets(compilation) {
|
|
29
40
|
const names = new Set();
|
|
30
41
|
for (const chunk of compilation.chunks) for (const name of chunk.files) if (isEmittedJs(name)) names.add(name);
|
|
@@ -165,6 +176,7 @@ var AfterpackWebpackPlugin = class {
|
|
|
165
176
|
else compilation.emitAsset(mapName, map);
|
|
166
177
|
} else if (asset.mapName && compilation.getAsset(asset.mapName)) compilation.deleteAsset(asset.mapName);
|
|
167
178
|
}
|
|
179
|
+
if (!result.policy.sourceMap) stripCssSourceMaps(compilation, RawSource);
|
|
168
180
|
if (result.deferredReceipt) this.deferredReceiptByCompilation.set(compilation, result.deferredReceipt);
|
|
169
181
|
}
|
|
170
182
|
capture(resource, context) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@afterpack/webpack",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.1",
|
|
4
4
|
"description": "webpack plugin for AfterPack: obfuscate your production JavaScript during the webpack build",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.cjs",
|
|
@@ -28,8 +28,8 @@
|
|
|
28
28
|
"webpack": "^5.0.0"
|
|
29
29
|
},
|
|
30
30
|
"dependencies": {
|
|
31
|
-
"@afterpack/core": "~0.2.
|
|
32
|
-
"@afterpack/integration-utils": "0.2.
|
|
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",
|