jso-protector 0.2.0
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/CHANGELOG.md +960 -0
- package/LICENSE +90 -0
- package/MIGRATION.md +207 -0
- package/README.md +1477 -0
- package/RELEASE.md +82 -0
- package/SECURITY.md +71 -0
- package/ai-cli.js +392 -0
- package/ai.js +176 -0
- package/bin/jso-protector.js +12066 -0
- package/browserify.d.ts +10 -0
- package/browserify.js +88 -0
- package/bun.d.ts +10 -0
- package/bun.js +41 -0
- package/ci/Jenkinsfile +82 -0
- package/ci/argo-workflows.yaml +121 -0
- package/ci/azure-pipelines.yml +56 -0
- package/ci/bitbucket-pipelines.yml +43 -0
- package/ci/buildkite.yml +50 -0
- package/ci/circleci.yml +60 -0
- package/ci/drone.yml +67 -0
- package/ci/github-actions.yml +51 -0
- package/ci/gitlab-ci.yml +39 -0
- package/ci/gocd.yaml +79 -0
- package/ci/teamcity.kts +79 -0
- package/ci/tekton.yaml +106 -0
- package/ci/verify-package.js +748 -0
- package/ci/verify-publish-metadata.js +147 -0
- package/ci/verify-templates.js +195 -0
- package/ci/woodpecker.yml +53 -0
- package/compliance/cli.js +204 -0
- package/compliance/evidence-forwarder.js +209 -0
- package/compliance/pci-dss-v4/controls.json +75 -0
- package/compliance/pci-dss-v4/index.js +2613 -0
- package/config/named-sets.js +185 -0
- package/esbuild.d.ts +16 -0
- package/esbuild.js +190 -0
- package/examples/README.md +78 -0
- package/examples/browserify/build.js +20 -0
- package/examples/bun/package.json +13 -0
- package/examples/bun/scripts/protect-release.js +28 -0
- package/examples/cli-basic/jso.config.cjs +23 -0
- package/examples/cli-basic/jso.config.json +15 -0
- package/examples/cli-basic/package.json +14 -0
- package/examples/cli-basic/scripts/build.js +10 -0
- package/examples/curl/README.md +55 -0
- package/examples/curl/protect.sh +106 -0
- package/examples/esbuild/build.js +19 -0
- package/examples/grunt/Gruntfile.js +29 -0
- package/examples/gulp/gulpfile.js +19 -0
- package/examples/helm/Chart.yaml +27 -0
- package/examples/helm/README.md +69 -0
- package/examples/helm/templates/_helpers.tpl +23 -0
- package/examples/helm/templates/_podtemplate.tpl +64 -0
- package/examples/helm/templates/job.yaml +39 -0
- package/examples/helm/templates/secret.yaml +17 -0
- package/examples/helm/values.yaml +54 -0
- package/examples/kubernetes/job.yaml +123 -0
- package/examples/metro.config.js +11 -0
- package/examples/nextjs/next.config.js +11 -0
- package/examples/node-api/protect-release.js +28 -0
- package/examples/node-api/release-summary.js +59 -0
- package/examples/parcel/package.json +13 -0
- package/examples/parcel/scripts/protect-release.js +28 -0
- package/examples/payment-page-script-inventory.json +62 -0
- package/examples/payment-page-security-headers.json +46 -0
- package/examples/pre-commit/.pre-commit-config.yaml +33 -0
- package/examples/pre-commit/README.md +45 -0
- package/examples/react-native/README.md +208 -0
- package/examples/react-native/metro.config.js +11 -0
- package/examples/rollup/rollup.config.js +20 -0
- package/examples/rspack/rspack.config.js +28 -0
- package/examples/turbopack/package.json +13 -0
- package/examples/turbopack/scripts/protect-release.js +28 -0
- package/examples/vite/vite.config.js +18 -0
- package/examples/webpack/webpack.config.js +21 -0
- package/examples/webpack-loader/webpack.config.js +22 -0
- package/governance/index.d.ts +18 -0
- package/governance/index.js +309 -0
- package/grunt.d.ts +4 -0
- package/grunt.js +111 -0
- package/gulp.d.ts +10 -0
- package/gulp.js +106 -0
- package/index.d.ts +879 -0
- package/index.js +607 -0
- package/jso.config.example.json +29 -0
- package/jso.config.schema.json +548 -0
- package/metro.d.ts +43 -0
- package/metro.js +117 -0
- package/next.d.ts +24 -0
- package/next.js +64 -0
- package/package.json +241 -0
- package/parcel.d.ts +10 -0
- package/parcel.js +40 -0
- package/react-native.d.ts +2 -0
- package/react-native.js +3 -0
- package/release-signer.js +245 -0
- package/rollup.d.ts +13 -0
- package/rollup.js +71 -0
- package/rspack-loader.d.ts +13 -0
- package/rspack-loader.js +11 -0
- package/rspack.d.ts +11 -0
- package/rspack.js +9 -0
- package/runtime/ai-script-governance.js +379 -0
- package/runtime/countermeasures.js +0 -0
- package/runtime/data-exfiltration-guard.d.ts +7 -0
- package/runtime/data-exfiltration-guard.js +161 -0
- package/runtime/environment-integrity.js +389 -0
- package/runtime/managed-integrity.d.ts +4 -0
- package/runtime/managed-integrity.js +108 -0
- package/runtime/third-party-inventory.js +437 -0
- package/turbopack.d.ts +10 -0
- package/turbopack.js +41 -0
- package/vite.d.ts +16 -0
- package/vite.js +78 -0
- package/watermark.js +126 -0
- package/webpack-loader.d.ts +15 -0
- package/webpack-loader.js +97 -0
- package/webpack.d.ts +13 -0
- package/webpack.js +143 -0
|
@@ -0,0 +1,748 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
"use strict";
|
|
4
|
+
|
|
5
|
+
const childProcess = require("node:child_process");
|
|
6
|
+
const fs = require("node:fs");
|
|
7
|
+
const os = require("node:os");
|
|
8
|
+
const path = require("node:path");
|
|
9
|
+
const vm = require("node:vm");
|
|
10
|
+
|
|
11
|
+
const root = path.resolve(__dirname, "..");
|
|
12
|
+
const npm = process.platform === "win32" ? "npm.cmd" : "npm";
|
|
13
|
+
|
|
14
|
+
const REQUIRED_PACKED_FILES = [
|
|
15
|
+
"CHANGELOG.md",
|
|
16
|
+
"MIGRATION.md",
|
|
17
|
+
"README.md",
|
|
18
|
+
"RELEASE.md",
|
|
19
|
+
"SECURITY.md",
|
|
20
|
+
"ai-cli.js",
|
|
21
|
+
"ai.js",
|
|
22
|
+
"bin/jso-protector.js",
|
|
23
|
+
"bun.d.ts",
|
|
24
|
+
"bun.js",
|
|
25
|
+
"browserify.d.ts",
|
|
26
|
+
"browserify.js",
|
|
27
|
+
"ci/azure-pipelines.yml",
|
|
28
|
+
"ci/github-actions.yml",
|
|
29
|
+
"ci/gitlab-ci.yml",
|
|
30
|
+
"ci/verify-package.js",
|
|
31
|
+
"ci/verify-publish-metadata.js",
|
|
32
|
+
"esbuild.d.ts",
|
|
33
|
+
"esbuild.js",
|
|
34
|
+
"examples/browserify/build.js",
|
|
35
|
+
"examples/cli-basic/jso.config.cjs",
|
|
36
|
+
"examples/cli-basic/jso.config.json",
|
|
37
|
+
"examples/cli-basic/package.json",
|
|
38
|
+
"examples/cli-basic/scripts/build.js",
|
|
39
|
+
"examples/bun/package.json",
|
|
40
|
+
"examples/bun/scripts/protect-release.js",
|
|
41
|
+
"examples/esbuild/build.js",
|
|
42
|
+
"examples/grunt/Gruntfile.js",
|
|
43
|
+
"examples/gulp/gulpfile.js",
|
|
44
|
+
"examples/metro.config.js",
|
|
45
|
+
"examples/node-api/protect-release.js",
|
|
46
|
+
"examples/node-api/release-summary.js",
|
|
47
|
+
"examples/nextjs/next.config.js",
|
|
48
|
+
"examples/parcel/package.json",
|
|
49
|
+
"examples/parcel/scripts/protect-release.js",
|
|
50
|
+
"examples/README.md",
|
|
51
|
+
"examples/react-native/metro.config.js",
|
|
52
|
+
"examples/rspack/rspack.config.js",
|
|
53
|
+
"examples/rollup/rollup.config.js",
|
|
54
|
+
"examples/turbopack/package.json",
|
|
55
|
+
"examples/turbopack/scripts/protect-release.js",
|
|
56
|
+
"examples/vite/vite.config.js",
|
|
57
|
+
"examples/webpack/webpack.config.js",
|
|
58
|
+
"examples/webpack-loader/webpack.config.js",
|
|
59
|
+
"grunt.d.ts",
|
|
60
|
+
"grunt.js",
|
|
61
|
+
"gulp.d.ts",
|
|
62
|
+
"gulp.js",
|
|
63
|
+
"index.d.ts",
|
|
64
|
+
"index.js",
|
|
65
|
+
"metro.d.ts",
|
|
66
|
+
"metro.js",
|
|
67
|
+
"next.d.ts",
|
|
68
|
+
"next.js",
|
|
69
|
+
"parcel.d.ts",
|
|
70
|
+
"parcel.js",
|
|
71
|
+
"react-native.d.ts",
|
|
72
|
+
"react-native.js",
|
|
73
|
+
"release-signer.js",
|
|
74
|
+
"rspack.d.ts",
|
|
75
|
+
"rspack.js",
|
|
76
|
+
"rspack-loader.d.ts",
|
|
77
|
+
"rspack-loader.js",
|
|
78
|
+
"jso.config.example.json",
|
|
79
|
+
"jso.config.schema.json",
|
|
80
|
+
"package.json",
|
|
81
|
+
"rollup.d.ts",
|
|
82
|
+
"rollup.js",
|
|
83
|
+
"turbopack.d.ts",
|
|
84
|
+
"turbopack.js",
|
|
85
|
+
"vite.d.ts",
|
|
86
|
+
"vite.js",
|
|
87
|
+
"watermark.js",
|
|
88
|
+
"webpack.d.ts",
|
|
89
|
+
"webpack.js",
|
|
90
|
+
"webpack-loader.d.ts",
|
|
91
|
+
"webpack-loader.js"
|
|
92
|
+
];
|
|
93
|
+
|
|
94
|
+
const PACKED_DIRECTORY_PREFIXES = [
|
|
95
|
+
"compliance/",
|
|
96
|
+
"config/",
|
|
97
|
+
"governance/",
|
|
98
|
+
"runtime/"
|
|
99
|
+
];
|
|
100
|
+
|
|
101
|
+
const DISALLOWED_PACKED_PATTERNS = [
|
|
102
|
+
/(^|\/)dist\//,
|
|
103
|
+
/(^|\/)dist-protected\//,
|
|
104
|
+
/(^|\/)node_modules\//,
|
|
105
|
+
/\.tgz$/,
|
|
106
|
+
/jso-manifest\.json$/
|
|
107
|
+
];
|
|
108
|
+
|
|
109
|
+
function exec(command, args, options = {}) {
|
|
110
|
+
return childProcess.execFileSync(command, args, {
|
|
111
|
+
cwd: root,
|
|
112
|
+
encoding: "utf8",
|
|
113
|
+
stdio: ["ignore", "pipe", "pipe"],
|
|
114
|
+
...options
|
|
115
|
+
});
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
function canSpawnChildren() {
|
|
119
|
+
if (process.platform === "win32") {
|
|
120
|
+
return false;
|
|
121
|
+
}
|
|
122
|
+
try {
|
|
123
|
+
const result = childProcess.spawnSync(process.execPath, ["-e", ""], { stdio: "ignore" });
|
|
124
|
+
const error = result && result.error;
|
|
125
|
+
return !(error && (error.code === "EPERM" || error.code === "EINVAL"));
|
|
126
|
+
} catch (error) {
|
|
127
|
+
return !(error && (error.code === "EPERM" || error.code === "EINVAL"));
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
function log(message) {
|
|
132
|
+
process.stdout.write(`${message}\n`);
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
if (!canSpawnChildren()) {
|
|
136
|
+
runPortableVerification();
|
|
137
|
+
process.exit(0);
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
const packOutput = exec(npm, ["pack", "--json"]);
|
|
141
|
+
const packInfo = JSON.parse(packOutput)[0];
|
|
142
|
+
const tarballPath = path.join(root, packInfo.filename);
|
|
143
|
+
const projectDir = fs.mkdtempSync(path.join(os.tmpdir(), "jso-package-verify-"));
|
|
144
|
+
|
|
145
|
+
try {
|
|
146
|
+
assertReleaseWorkflowDocs();
|
|
147
|
+
log(`Packed ${packInfo.filename} with ${packInfo.files.length} files.`);
|
|
148
|
+
assertPackedFiles(packInfo.files);
|
|
149
|
+
|
|
150
|
+
exec(npm, ["init", "-y"], { cwd: projectDir });
|
|
151
|
+
exec(npm, ["install", tarballPath, "--ignore-scripts"], { cwd: projectDir });
|
|
152
|
+
|
|
153
|
+
const smokeScript = `
|
|
154
|
+
const assert = require("node:assert/strict");
|
|
155
|
+
const api = require("jso-protector");
|
|
156
|
+
const packageJson = require("jso-protector/package.json");
|
|
157
|
+
const exportsToCheck = [
|
|
158
|
+
"bun",
|
|
159
|
+
"browserify",
|
|
160
|
+
"metro",
|
|
161
|
+
"react-native",
|
|
162
|
+
"next",
|
|
163
|
+
"parcel",
|
|
164
|
+
"rspack",
|
|
165
|
+
"rspack-loader",
|
|
166
|
+
"esbuild",
|
|
167
|
+
"gulp",
|
|
168
|
+
"grunt",
|
|
169
|
+
"rollup",
|
|
170
|
+
"turbopack",
|
|
171
|
+
"vite",
|
|
172
|
+
"webpack",
|
|
173
|
+
"webpack-loader"
|
|
174
|
+
];
|
|
175
|
+
for (const name of [
|
|
176
|
+
"obfuscate",
|
|
177
|
+
"obfuscateMultiple",
|
|
178
|
+
"buildProtectionItems",
|
|
179
|
+
"buildProtectionItemsFromInputItems",
|
|
180
|
+
"composeProtectionItemOutput",
|
|
181
|
+
"describeProtectionTransforms",
|
|
182
|
+
"getOptionsByPreset",
|
|
183
|
+
"hasConditionalMarkers",
|
|
184
|
+
"validateConditionalMarkers",
|
|
185
|
+
"findMarkedHtmlScripts",
|
|
186
|
+
"validateMarkedHtmlScripts",
|
|
187
|
+
"hasMarkedHtmlScriptAttributes",
|
|
188
|
+
"hasHtmlProtectionMarkers",
|
|
189
|
+
"formatSourceLocation",
|
|
190
|
+
"planProtection",
|
|
191
|
+
"protectCodeDetailed",
|
|
192
|
+
"protectFiles",
|
|
193
|
+
"explainCompatibilityOption",
|
|
194
|
+
"getPackageMetadata",
|
|
195
|
+
"globLikeMatch",
|
|
196
|
+
"normalizeDomainLockList",
|
|
197
|
+
"parseArgs",
|
|
198
|
+
"readStdin",
|
|
199
|
+
"translateJavascriptObfuscatorConfigOptions",
|
|
200
|
+
"translateJavascriptObfuscatorOptions"
|
|
201
|
+
]) {
|
|
202
|
+
assert.equal(typeof api[name], "function", name);
|
|
203
|
+
}
|
|
204
|
+
assert.deepEqual(api.normalizeDomainLockList("example.com, app.example.com"), ["example.com", "app.example.com"]);
|
|
205
|
+
assert.equal(api.globLikeMatch("assets/app.js", "assets/*.js"), true);
|
|
206
|
+
assert.equal(api.parseArgs(["--local-only"]).localOnly, true);
|
|
207
|
+
assert.equal(api.translateJavascriptObfuscatorConfigOptions({ domainLock: ["example.com"] }).options.LockDomain, true);
|
|
208
|
+
assert.equal(api.formatSourceLocation("first\\nsecond", 6), "2:1");
|
|
209
|
+
assert.throws(() => api.validateConditionalMarkers("app.js", "// javascript-obfuscator:disable"), /app\\.js:1:1/);
|
|
210
|
+
assert.throws(() => api.validateMarkedHtmlScripts("index.html", "<script data-javascript-obfuscator src=\\"app.js\\"></script>"), /index\\.html:1:1/);
|
|
211
|
+
for (const name of exportsToCheck) {
|
|
212
|
+
assert.equal(typeof require("jso-protector/" + name), "function", name);
|
|
213
|
+
}
|
|
214
|
+
assert.equal(api.getOptionsByPreset("balanced").DeepObfuscate, true);
|
|
215
|
+
assert.equal(packageJson.bin["jso-protector"], "./bin/jso-protector.js");
|
|
216
|
+
assert.equal(packageJson.types, "./index.d.ts");
|
|
217
|
+
assert.equal(packageJson.exports["./schema"], "./jso.config.schema.json");
|
|
218
|
+
`;
|
|
219
|
+
exec(process.execPath, ["-e", smokeScript], { cwd: projectDir });
|
|
220
|
+
|
|
221
|
+
const esmSmokeScript = `
|
|
222
|
+
import assert from "node:assert/strict";
|
|
223
|
+
import api from "jso-protector";
|
|
224
|
+
import protectBunBuild from "jso-protector/bun";
|
|
225
|
+
import browserifyProtector from "jso-protector/browserify";
|
|
226
|
+
import createMetroSerializer from "jso-protector/metro";
|
|
227
|
+
import reactNativeProtector from "jso-protector/react-native";
|
|
228
|
+
import withJsoProtector from "jso-protector/next";
|
|
229
|
+
import protectParcelBuild from "jso-protector/parcel";
|
|
230
|
+
import rspackProtector from "jso-protector/rspack";
|
|
231
|
+
import rspackLoader from "jso-protector/rspack-loader";
|
|
232
|
+
import esbuildProtector from "jso-protector/esbuild";
|
|
233
|
+
import gulpProtector from "jso-protector/gulp";
|
|
234
|
+
import registerGruntProtector from "jso-protector/grunt";
|
|
235
|
+
import rollupProtector from "jso-protector/rollup";
|
|
236
|
+
import protectTurbopackBuild from "jso-protector/turbopack";
|
|
237
|
+
import viteProtector from "jso-protector/vite";
|
|
238
|
+
import webpackProtector from "jso-protector/webpack";
|
|
239
|
+
import webpackLoader from "jso-protector/webpack-loader";
|
|
240
|
+
import schema from "jso-protector/schema" assert { type: "json" };
|
|
241
|
+
|
|
242
|
+
assert.equal(typeof api.obfuscate, "function");
|
|
243
|
+
for (const entry of [
|
|
244
|
+
protectBunBuild,
|
|
245
|
+
browserifyProtector,
|
|
246
|
+
createMetroSerializer,
|
|
247
|
+
reactNativeProtector,
|
|
248
|
+
withJsoProtector,
|
|
249
|
+
protectParcelBuild,
|
|
250
|
+
rspackProtector,
|
|
251
|
+
rspackLoader,
|
|
252
|
+
esbuildProtector,
|
|
253
|
+
gulpProtector,
|
|
254
|
+
registerGruntProtector,
|
|
255
|
+
rollupProtector,
|
|
256
|
+
protectTurbopackBuild,
|
|
257
|
+
viteProtector,
|
|
258
|
+
webpackProtector,
|
|
259
|
+
webpackLoader
|
|
260
|
+
]) {
|
|
261
|
+
assert.equal(typeof entry, "function");
|
|
262
|
+
}
|
|
263
|
+
assert.equal(schema.type, "object");
|
|
264
|
+
assert.equal(typeof schema.properties.endpoint, "object");
|
|
265
|
+
`;
|
|
266
|
+
const esmSmokePath = path.join(projectDir, "esm-smoke.mjs");
|
|
267
|
+
fs.writeFileSync(esmSmokePath, esmSmokeScript, "utf8");
|
|
268
|
+
exec(process.execPath, [esmSmokePath], { cwd: projectDir });
|
|
269
|
+
|
|
270
|
+
const packageDir = path.join(projectDir, "node_modules", "jso-protector");
|
|
271
|
+
verifyTypeDeclarations(packageDir);
|
|
272
|
+
verifyExampleFiles(path.join(packageDir, "examples"));
|
|
273
|
+
verifyExamplePackageScripts(path.join(packageDir, "examples"));
|
|
274
|
+
verifyPublishMetadataGuard(packageDir);
|
|
275
|
+
|
|
276
|
+
const binPath = path.join(packageDir, "bin", "jso-protector.js");
|
|
277
|
+
exec(process.execPath, [binPath, "--help"], { cwd: projectDir });
|
|
278
|
+
exec(npm, ["exec", "--", "jso-protector", "--help"], { cwd: projectDir });
|
|
279
|
+
const directVersion = JSON.parse(exec(process.execPath, [binPath, "--version", "--json"], { cwd: projectDir }));
|
|
280
|
+
if (directVersion.name !== "jso-protector" || directVersion.version !== packInfo.version) {
|
|
281
|
+
throw new Error(`Direct CLI version metadata is wrong: ${JSON.stringify(directVersion)}`);
|
|
282
|
+
}
|
|
283
|
+
const linkedVersion = exec(npm, ["exec", "--", "jso-protector", "--version"], { cwd: projectDir }).trim();
|
|
284
|
+
if (linkedVersion !== `jso-protector ${packInfo.version}`) {
|
|
285
|
+
throw new Error(`Linked CLI version output is wrong: ${linkedVersion}`);
|
|
286
|
+
}
|
|
287
|
+
|
|
288
|
+
const explainCompat = JSON.parse(exec(npm, ["exec", "--", "jso-protector", "--explain-compat", "self-defending", "--json"], { cwd: projectDir }));
|
|
289
|
+
if (explainCompat.option !== "selfDefending" || explainCompat.status !== "review-only" || explainCompat.confidence !== "review") {
|
|
290
|
+
throw new Error(`Compatibility explanation output is wrong: ${JSON.stringify(explainCompat)}`);
|
|
291
|
+
}
|
|
292
|
+
|
|
293
|
+
const localOnly = JSON.parse(exec(npm, ["exec", "--", "jso-protector", "--local-only", "--json"], { cwd: projectDir }));
|
|
294
|
+
if (
|
|
295
|
+
localOnly.sourceLeavesMachine !== false ||
|
|
296
|
+
!Array.isArray(localOnly.localPreflightCommands) ||
|
|
297
|
+
!localOnly.localPreflightCommands.some((command) => command.includes("--release-check --json")) ||
|
|
298
|
+
!localOnly.localPreflightCommands.some((command) => command.includes("--competitor-gap-report --json"))
|
|
299
|
+
) {
|
|
300
|
+
throw new Error(`Local-only guidance output is wrong: ${JSON.stringify(localOnly)}`);
|
|
301
|
+
}
|
|
302
|
+
if (localOnly.npmPublished !== false || localOnly.packageDistribution !== "local-only" || !localOnly.localInstallCommands.some((command) => command.includes("./packages/jso-protector"))) {
|
|
303
|
+
throw new Error(`Local package guidance output is wrong: ${JSON.stringify(localOnly)}`);
|
|
304
|
+
}
|
|
305
|
+
|
|
306
|
+
const samplePath = path.join(projectDir, "sample.js");
|
|
307
|
+
fs.writeFileSync(samplePath, "console.log('sample');\n", "utf8");
|
|
308
|
+
const resolvedConfig = JSON.parse(exec(process.execPath, [
|
|
309
|
+
binPath,
|
|
310
|
+
samplePath,
|
|
311
|
+
"--print-config",
|
|
312
|
+
"--json"
|
|
313
|
+
], { cwd: projectDir }));
|
|
314
|
+
assertOutputPath(resolvedConfig.output, path.join(projectDir, "sample-obfuscated.js"));
|
|
315
|
+
|
|
316
|
+
const linkedBinConfig = JSON.parse(exec(npm, [
|
|
317
|
+
"exec",
|
|
318
|
+
"--",
|
|
319
|
+
"jso-protector",
|
|
320
|
+
samplePath,
|
|
321
|
+
"--print-config",
|
|
322
|
+
"--json"
|
|
323
|
+
], { cwd: projectDir }));
|
|
324
|
+
assertOutputPath(linkedBinConfig.output, path.join(projectDir, "sample-obfuscated.js"));
|
|
325
|
+
|
|
326
|
+
const configPath = path.join(projectDir, "jso.config.json");
|
|
327
|
+
fs.writeFileSync(configPath, JSON.stringify({
|
|
328
|
+
endpoint: "https://example.test/HttpApi.ashx",
|
|
329
|
+
apiKey: "$JSO_VERIFY_KEY",
|
|
330
|
+
apiPassword: "$JSO_VERIFY_PASSWORD",
|
|
331
|
+
input: "dist",
|
|
332
|
+
output: "dist-protected",
|
|
333
|
+
manifest: "dist-protected/jso-manifest.json",
|
|
334
|
+
options: {
|
|
335
|
+
EncodeStrings: true
|
|
336
|
+
}
|
|
337
|
+
}, null, 2));
|
|
338
|
+
const distDir = path.join(projectDir, "dist");
|
|
339
|
+
fs.mkdirSync(distDir, { recursive: true });
|
|
340
|
+
fs.mkdirSync(path.join(projectDir, "dist-protected"), { recursive: true });
|
|
341
|
+
fs.writeFileSync(path.join(distDir, "app.js"), "console.log('dist');\n", "utf8");
|
|
342
|
+
fs.writeFileSync(path.join(distDir, "index.html"), "<script src=\"app.js\"></script>\n", "utf8");
|
|
343
|
+
|
|
344
|
+
const releaseCheckEnv = {
|
|
345
|
+
...process.env,
|
|
346
|
+
JSO_VERIFY_KEY: "verify-key",
|
|
347
|
+
JSO_VERIFY_PASSWORD: "verify-password"
|
|
348
|
+
};
|
|
349
|
+
const directReleaseCheck = JSON.parse(exec(process.execPath, [
|
|
350
|
+
binPath,
|
|
351
|
+
"--config",
|
|
352
|
+
configPath,
|
|
353
|
+
"--release-check",
|
|
354
|
+
"--strict",
|
|
355
|
+
"--json"
|
|
356
|
+
], { cwd: projectDir, env: releaseCheckEnv }));
|
|
357
|
+
assertReleaseCheck(directReleaseCheck);
|
|
358
|
+
|
|
359
|
+
const linkedReleaseCheck = JSON.parse(exec(npm, [
|
|
360
|
+
"exec",
|
|
361
|
+
"--",
|
|
362
|
+
"jso-protector",
|
|
363
|
+
"--config",
|
|
364
|
+
configPath,
|
|
365
|
+
"--release-check",
|
|
366
|
+
"--json"
|
|
367
|
+
], { cwd: projectDir, env: releaseCheckEnv }));
|
|
368
|
+
assertReleaseCheck(linkedReleaseCheck);
|
|
369
|
+
|
|
370
|
+
log("Package install verification passed.");
|
|
371
|
+
} finally {
|
|
372
|
+
try {
|
|
373
|
+
fs.rmSync(tarballPath, { force: true });
|
|
374
|
+
} catch (error) {
|
|
375
|
+
process.stderr.write(`Could not remove ${tarballPath}: ${error.message}\n`);
|
|
376
|
+
}
|
|
377
|
+
try {
|
|
378
|
+
fs.rmSync(projectDir, { recursive: true, force: true });
|
|
379
|
+
} catch (error) {
|
|
380
|
+
process.stderr.write(`Could not remove ${projectDir}: ${error.message}\n`);
|
|
381
|
+
}
|
|
382
|
+
}
|
|
383
|
+
|
|
384
|
+
function assertOutputPath(actual, expected) {
|
|
385
|
+
if (path.resolve(actual) !== path.resolve(expected)) {
|
|
386
|
+
throw new Error(`Expected output ${expected}, received ${actual}`);
|
|
387
|
+
}
|
|
388
|
+
}
|
|
389
|
+
|
|
390
|
+
function assertReleaseCheck(report) {
|
|
391
|
+
if (!report || report.format !== "jso-protector-release-check" || report.ok !== true) {
|
|
392
|
+
throw new Error(`Release check failed: ${JSON.stringify(report)}`);
|
|
393
|
+
}
|
|
394
|
+
if (!report.plan || !report.plan.files.includes("app.js") || !report.plan.assets.includes("index.html")) {
|
|
395
|
+
throw new Error(`Release check did not plan expected files/assets: ${JSON.stringify(report.plan)}`);
|
|
396
|
+
}
|
|
397
|
+
if (!report.doctor || report.doctor.ok !== true) {
|
|
398
|
+
throw new Error(`Release check doctor report failed: ${JSON.stringify(report.doctor)}`);
|
|
399
|
+
}
|
|
400
|
+
}
|
|
401
|
+
|
|
402
|
+
function assertPackedFiles(files) {
|
|
403
|
+
assertCliRuntimeDependenciesDeclared();
|
|
404
|
+
const packed = new Set(files.map((file) => file.path.replace(/\\/g, "/")));
|
|
405
|
+
const missing = REQUIRED_PACKED_FILES.filter((file) => !packed.has(file));
|
|
406
|
+
if (missing.length) {
|
|
407
|
+
throw new Error(`Packed tarball is missing required file(s): ${missing.join(", ")}`);
|
|
408
|
+
}
|
|
409
|
+
|
|
410
|
+
const disallowed = Array.from(packed).filter((file) => DISALLOWED_PACKED_PATTERNS.some((pattern) => pattern.test(file)));
|
|
411
|
+
if (disallowed.length) {
|
|
412
|
+
throw new Error(`Packed tarball includes generated or disallowed file(s): ${disallowed.join(", ")}`);
|
|
413
|
+
}
|
|
414
|
+
}
|
|
415
|
+
|
|
416
|
+
function assertReleaseWorkflowDocs() {
|
|
417
|
+
const releaseSnippets = [
|
|
418
|
+
"npm run verify:package --if-present",
|
|
419
|
+
"npm run verify:publish-metadata --if-present",
|
|
420
|
+
"--release-check --json",
|
|
421
|
+
"--competitor-gap-report --json",
|
|
422
|
+
"--script-inventory-audit",
|
|
423
|
+
"--payment-page-headers-from-har",
|
|
424
|
+
"--manifest dist-protected/jso-manifest.json"
|
|
425
|
+
];
|
|
426
|
+
const readmeOnlySnippets = [
|
|
427
|
+
"--parse-html",
|
|
428
|
+
"--honor-conditional-comments",
|
|
429
|
+
"--explain-compat",
|
|
430
|
+
"--local-only",
|
|
431
|
+
"\"jso-protector\": \"file:../packages/jso-protector\"",
|
|
432
|
+
"npm pack --json",
|
|
433
|
+
"prepublishOnly",
|
|
434
|
+
"Payment and API Access",
|
|
435
|
+
"payment-script-inventory",
|
|
436
|
+
"hosted API validates the account",
|
|
437
|
+
"API keys and passwords are redacted",
|
|
438
|
+
"Inline `apiKey`, `apiPassword`, `--api-key`, and `--api-password` values also warn",
|
|
439
|
+
"Config files can also carry mapped `javascript-obfuscator` compatibility keys"
|
|
440
|
+
,
|
|
441
|
+
"jso ai usage --pretty",
|
|
442
|
+
"usage.providerKey.status",
|
|
443
|
+
"AiProviderKeyHealth",
|
|
444
|
+
"estimate.providerKey",
|
|
445
|
+
"Parcel, Bun, and Turbopack",
|
|
446
|
+
"examples/parcel",
|
|
447
|
+
"examples/bun",
|
|
448
|
+
"examples/turbopack"
|
|
449
|
+
];
|
|
450
|
+
const securitySnippets = [
|
|
451
|
+
"Payment and Entitlements",
|
|
452
|
+
"must not contain billing rules",
|
|
453
|
+
"Unpaid, expired, disabled, or over-limit accounts",
|
|
454
|
+
"redacts API key and password values",
|
|
455
|
+
"--competitor-gap-report` reads config metadata and migration fields only",
|
|
456
|
+
"--validate-config` warns when `apiKey`, `apiPassword`, `--api-key`, or `--api-password` contain inline values"
|
|
457
|
+
];
|
|
458
|
+
const filesToCheck = [
|
|
459
|
+
"README.md",
|
|
460
|
+
"ci/github-actions.yml",
|
|
461
|
+
"ci/gitlab-ci.yml",
|
|
462
|
+
"ci/azure-pipelines.yml"
|
|
463
|
+
];
|
|
464
|
+
|
|
465
|
+
for (const fileName of filesToCheck) {
|
|
466
|
+
const text = fs.readFileSync(path.join(root, fileName), "utf8");
|
|
467
|
+
for (const snippet of releaseSnippets) {
|
|
468
|
+
if (!text.includes(snippet)) {
|
|
469
|
+
throw new Error(`${fileName} is missing release workflow snippet: ${snippet}`);
|
|
470
|
+
}
|
|
471
|
+
}
|
|
472
|
+
}
|
|
473
|
+
|
|
474
|
+
const readme = fs.readFileSync(path.join(root, "README.md"), "utf8");
|
|
475
|
+
for (const snippet of readmeOnlySnippets) {
|
|
476
|
+
if (!readme.includes(snippet)) {
|
|
477
|
+
throw new Error(`README.md is missing feature documentation snippet: ${snippet}`);
|
|
478
|
+
}
|
|
479
|
+
}
|
|
480
|
+
|
|
481
|
+
const security = fs.readFileSync(path.join(root, "SECURITY.md"), "utf8");
|
|
482
|
+
for (const snippet of securitySnippets) {
|
|
483
|
+
if (!security.includes(snippet)) {
|
|
484
|
+
throw new Error(`SECURITY.md is missing payment/security snippet: ${snippet}`);
|
|
485
|
+
}
|
|
486
|
+
}
|
|
487
|
+
|
|
488
|
+
const migration = fs.readFileSync(path.join(root, "MIGRATION.md"), "utf8");
|
|
489
|
+
if (!migration.includes("npm install --save-dev ./packages/jso-protector") || !migration.includes("\"jso-protector\": \"file:../packages/jso-protector\"")) {
|
|
490
|
+
throw new Error("MIGRATION.md must document local package install paths.");
|
|
491
|
+
}
|
|
492
|
+
if (migration.includes("npm install --save-dev jso-protector")) {
|
|
493
|
+
throw new Error("MIGRATION.md must not suggest installing jso-protector from the public npm registry.");
|
|
494
|
+
}
|
|
495
|
+
}
|
|
496
|
+
|
|
497
|
+
function verifyExampleFiles(examplesDir) {
|
|
498
|
+
for (const filePath of walkFiles(examplesDir)) {
|
|
499
|
+
if (filePath.endsWith(".js") || filePath.endsWith(".cjs")) {
|
|
500
|
+
exec(process.execPath, ["--check", filePath], { cwd: projectDir });
|
|
501
|
+
continue;
|
|
502
|
+
}
|
|
503
|
+
if (filePath.endsWith(".json")) {
|
|
504
|
+
JSON.parse(fs.readFileSync(filePath, "utf8"));
|
|
505
|
+
}
|
|
506
|
+
}
|
|
507
|
+
}
|
|
508
|
+
|
|
509
|
+
function runPortableVerification() {
|
|
510
|
+
assertReleaseWorkflowDocs();
|
|
511
|
+
assertCliRuntimeDependenciesDeclared();
|
|
512
|
+
assertLocalFiles(REQUIRED_PACKED_FILES);
|
|
513
|
+
verifyLocalExports();
|
|
514
|
+
verifyTypeDeclarations(root);
|
|
515
|
+
verifyExampleFilesPortable(path.join(root, "examples"));
|
|
516
|
+
verifyExamplePackageScripts(path.join(root, "examples"));
|
|
517
|
+
verifyPublishMetadataGuardPortable();
|
|
518
|
+
log("Portable package verification passed (child processes unavailable in this environment).");
|
|
519
|
+
}
|
|
520
|
+
|
|
521
|
+
function assertCliRuntimeDependenciesDeclared() {
|
|
522
|
+
const entrypoint = path.join(root, "bin", "jso-protector.js");
|
|
523
|
+
const source = fs.readFileSync(entrypoint, "utf8");
|
|
524
|
+
const dependencyPattern = /require\(\s*["'](\.\.\/[A-Za-z0-9_./-]+)["']\s*\)/g;
|
|
525
|
+
const missing = [];
|
|
526
|
+
let match;
|
|
527
|
+
|
|
528
|
+
while ((match = dependencyPattern.exec(source))) {
|
|
529
|
+
let resolved = path.relative(root, path.resolve(path.dirname(entrypoint), match[1])).replace(/\\/g, "/");
|
|
530
|
+
if (!path.extname(resolved))
|
|
531
|
+
resolved += ".js";
|
|
532
|
+
const explicitlyIncluded = REQUIRED_PACKED_FILES.includes(resolved);
|
|
533
|
+
const includedByDirectory = PACKED_DIRECTORY_PREFIXES.some((entry) => resolved.startsWith(entry));
|
|
534
|
+
if (!explicitlyIncluded && !includedByDirectory)
|
|
535
|
+
missing.push(resolved);
|
|
536
|
+
}
|
|
537
|
+
|
|
538
|
+
if (missing.length) {
|
|
539
|
+
throw new Error(`CLI runtime dependency is not required in the packed artifact: ${Array.from(new Set(missing)).join(", ")}`);
|
|
540
|
+
}
|
|
541
|
+
}
|
|
542
|
+
|
|
543
|
+
function assertLocalFiles(files) {
|
|
544
|
+
const missing = files.filter((file) => !fs.existsSync(path.join(root, file)));
|
|
545
|
+
if (missing.length) {
|
|
546
|
+
throw new Error(`Workspace is missing required file(s): ${missing.join(", ")}`);
|
|
547
|
+
}
|
|
548
|
+
}
|
|
549
|
+
|
|
550
|
+
function verifyLocalExports() {
|
|
551
|
+
const api = require(path.join(root, "index.js"));
|
|
552
|
+
const packageJson = require(path.join(root, "package.json"));
|
|
553
|
+
const exportsToCheck = [
|
|
554
|
+
"bun",
|
|
555
|
+
"browserify",
|
|
556
|
+
"metro",
|
|
557
|
+
"react-native",
|
|
558
|
+
"next",
|
|
559
|
+
"parcel",
|
|
560
|
+
"rspack",
|
|
561
|
+
"rspack-loader",
|
|
562
|
+
"esbuild",
|
|
563
|
+
"gulp",
|
|
564
|
+
"grunt",
|
|
565
|
+
"rollup",
|
|
566
|
+
"turbopack",
|
|
567
|
+
"vite",
|
|
568
|
+
"webpack",
|
|
569
|
+
"webpack-loader"
|
|
570
|
+
];
|
|
571
|
+
const exportTargets = {
|
|
572
|
+
bun: "./bun.js",
|
|
573
|
+
browserify: "./browserify.js",
|
|
574
|
+
metro: "./metro.js",
|
|
575
|
+
"react-native": "./react-native.js",
|
|
576
|
+
next: "./next.js",
|
|
577
|
+
parcel: "./parcel.js",
|
|
578
|
+
rspack: "./rspack.js",
|
|
579
|
+
"rspack-loader": "./rspack-loader.js",
|
|
580
|
+
esbuild: "./esbuild.js",
|
|
581
|
+
gulp: "./gulp.js",
|
|
582
|
+
grunt: "./grunt.js",
|
|
583
|
+
rollup: "./rollup.js",
|
|
584
|
+
turbopack: "./turbopack.js",
|
|
585
|
+
vite: "./vite.js",
|
|
586
|
+
webpack: "./webpack.js",
|
|
587
|
+
"webpack-loader": "./webpack-loader.js"
|
|
588
|
+
};
|
|
589
|
+
|
|
590
|
+
for (const name of [
|
|
591
|
+
"obfuscate",
|
|
592
|
+
"obfuscateMultiple",
|
|
593
|
+
"buildProtectionItems",
|
|
594
|
+
"buildProtectionItemsFromInputItems",
|
|
595
|
+
"composeProtectionItemOutput",
|
|
596
|
+
"describeProtectionTransforms",
|
|
597
|
+
"getOptionsByPreset",
|
|
598
|
+
"hasConditionalMarkers",
|
|
599
|
+
"validateConditionalMarkers",
|
|
600
|
+
"findMarkedHtmlScripts",
|
|
601
|
+
"validateMarkedHtmlScripts",
|
|
602
|
+
"hasMarkedHtmlScriptAttributes",
|
|
603
|
+
"hasHtmlProtectionMarkers",
|
|
604
|
+
"formatSourceLocation",
|
|
605
|
+
"planProtection",
|
|
606
|
+
"protectCodeDetailed",
|
|
607
|
+
"protectFiles",
|
|
608
|
+
"explainCompatibilityOption",
|
|
609
|
+
"getPackageMetadata",
|
|
610
|
+
"globLikeMatch",
|
|
611
|
+
"normalizeDomainLockList",
|
|
612
|
+
"parseArgs",
|
|
613
|
+
"readStdin",
|
|
614
|
+
"translateJavascriptObfuscatorConfigOptions",
|
|
615
|
+
"translateJavascriptObfuscatorOptions"
|
|
616
|
+
]) {
|
|
617
|
+
if (typeof api[name] !== "function") {
|
|
618
|
+
throw new Error(`Expected root export ${name} to be a function.`);
|
|
619
|
+
}
|
|
620
|
+
}
|
|
621
|
+
|
|
622
|
+
for (const name of exportsToCheck) {
|
|
623
|
+
if (typeof require(path.join(root, `${name}.js`)) !== "function") {
|
|
624
|
+
throw new Error(`Expected subpath export ${name} to be callable.`);
|
|
625
|
+
}
|
|
626
|
+
const exportConfig = packageJson.exports[`./${name}`];
|
|
627
|
+
if (!exportConfig || exportConfig.require !== exportTargets[name] || exportConfig.default !== exportTargets[name]) {
|
|
628
|
+
throw new Error(`package.json must export ./${name} to ${exportTargets[name]}.`);
|
|
629
|
+
}
|
|
630
|
+
}
|
|
631
|
+
|
|
632
|
+
if (packageJson.exports["./schema"] !== "./jso.config.schema.json") {
|
|
633
|
+
throw new Error("package.json must export ./schema.");
|
|
634
|
+
}
|
|
635
|
+
}
|
|
636
|
+
|
|
637
|
+
function verifyExampleFilesPortable(examplesDir) {
|
|
638
|
+
for (const filePath of walkFiles(examplesDir)) {
|
|
639
|
+
if (filePath.endsWith(".js") || filePath.endsWith(".cjs")) {
|
|
640
|
+
new vm.Script(fs.readFileSync(filePath, "utf8"), { filename: filePath });
|
|
641
|
+
continue;
|
|
642
|
+
}
|
|
643
|
+
if (filePath.endsWith(".json")) {
|
|
644
|
+
JSON.parse(fs.readFileSync(filePath, "utf8"));
|
|
645
|
+
}
|
|
646
|
+
}
|
|
647
|
+
}
|
|
648
|
+
|
|
649
|
+
function verifyPublishMetadataGuardPortable() {
|
|
650
|
+
const packageJson = JSON.parse(fs.readFileSync(path.join(root, "package.json"), "utf8"));
|
|
651
|
+
|
|
652
|
+
// Mirrors ci/verify-publish-metadata.js: exactly two states are approved, and
|
|
653
|
+
// a half-migrated package must fail rather than publish. Kept in sync
|
|
654
|
+
// deliberately -- this is the second of two independent guards, so weakening
|
|
655
|
+
// one alone should not be enough to let a bad state through.
|
|
656
|
+
const localOnly = packageJson.private === true && packageJson.license === "UNLICENSED";
|
|
657
|
+
const proprietaryPublic =
|
|
658
|
+
packageJson.private !== true && packageJson.license === "SEE LICENSE IN LICENSE";
|
|
659
|
+
|
|
660
|
+
if (!localOnly && !proprietaryPublic) {
|
|
661
|
+
throw new Error(
|
|
662
|
+
"Publish metadata guard: package is in neither approved state. Expected either " +
|
|
663
|
+
"private:true + \"UNLICENSED\" (local-only) or private removed + " +
|
|
664
|
+
"\"SEE LICENSE IN LICENSE\" (proprietary release). Found " +
|
|
665
|
+
`private:${JSON.stringify(packageJson.private)} license:${JSON.stringify(packageJson.license)}.`
|
|
666
|
+
);
|
|
667
|
+
}
|
|
668
|
+
if (proprietaryPublic && !fs.existsSync(path.join(root, "LICENSE"))) {
|
|
669
|
+
throw new Error(
|
|
670
|
+
"Publish metadata guard: license is \"SEE LICENSE IN LICENSE\" but no LICENSE file exists."
|
|
671
|
+
);
|
|
672
|
+
}
|
|
673
|
+
if (!packageJson.bin || packageJson.bin["jso-protector"] !== "./bin/jso-protector.js") {
|
|
674
|
+
throw new Error("Publish metadata guard expects the jso-protector bin export.");
|
|
675
|
+
}
|
|
676
|
+
}
|
|
677
|
+
|
|
678
|
+
function verifyTypeDeclarations(packageDir) {
|
|
679
|
+
const declarations = fs.readFileSync(path.join(packageDir, "index.d.ts"), "utf8");
|
|
680
|
+
const requiredSnippets = [
|
|
681
|
+
"export type InitTemplateName = \"browser-app\" | \"html-app\" | \"node-app\" | \"electron-app\" | \"nextjs-app\" | \"vite-app\" | \"parcel-app\" | \"bun-app\" | \"browserify-app\" | \"webpack-app\" | \"rspack-app\" | \"turbopack-app\" | \"react-native-app\";",
|
|
682
|
+
"export interface PackageMetadata",
|
|
683
|
+
"export interface ParsedCliArgs",
|
|
684
|
+
"export interface CompetitorGapReport",
|
|
685
|
+
"export interface AiProviderKeyHealth",
|
|
686
|
+
"providerKey?: AiProviderKeyHealth;",
|
|
687
|
+
"export function buildCompetitorGapReport",
|
|
688
|
+
"label: \"validate\" | \"preview\" | \"doctor\" | \"release-check\" | \"competitor-gap\" | \"protect\";",
|
|
689
|
+
"export function getPackageMetadata",
|
|
690
|
+
"export function globLikeMatch",
|
|
691
|
+
"export function normalizeDomainLockList",
|
|
692
|
+
"export function parseArgs",
|
|
693
|
+
"export function readStdin",
|
|
694
|
+
"export function translateJavascriptObfuscatorConfigOptions",
|
|
695
|
+
"export function writeLocalOnlyGuidance"
|
|
696
|
+
];
|
|
697
|
+
|
|
698
|
+
for (const snippet of requiredSnippets) {
|
|
699
|
+
if (!declarations.includes(snippet)) {
|
|
700
|
+
throw new Error(`index.d.ts is missing declaration snippet: ${snippet}`);
|
|
701
|
+
}
|
|
702
|
+
}
|
|
703
|
+
|
|
704
|
+
const parseHtmlMatches = declarations.match(/parseHtml\?: boolean/g) || [];
|
|
705
|
+
if (parseHtmlMatches.length !== 1) {
|
|
706
|
+
throw new Error(`index.d.ts should declare ProtectionOptions.parseHtml once, found ${parseHtmlMatches.length}.`);
|
|
707
|
+
}
|
|
708
|
+
}
|
|
709
|
+
|
|
710
|
+
function verifyExamplePackageScripts(examplesDir) {
|
|
711
|
+
const cliPackagePath = path.join(examplesDir, "cli-basic", "package.json");
|
|
712
|
+
const cliPackage = JSON.parse(fs.readFileSync(cliPackagePath, "utf8"));
|
|
713
|
+
if (!cliPackage.scripts || !String(cliPackage.scripts.preflight || "").includes("--release-check --json")) {
|
|
714
|
+
throw new Error("examples/cli-basic/package.json must include a release-check preflight script.");
|
|
715
|
+
}
|
|
716
|
+
if (!String(cliPackage.scripts.release || "").includes("npm run preflight")) {
|
|
717
|
+
throw new Error("examples/cli-basic/package.json release script must run preflight before protection.");
|
|
718
|
+
}
|
|
719
|
+
|
|
720
|
+
const packageJson = JSON.parse(fs.readFileSync(path.join(root, "package.json"), "utf8"));
|
|
721
|
+
if (!packageJson.scripts || !String(packageJson.scripts.prepublishOnly || "").includes("verify-publish-metadata.js")) {
|
|
722
|
+
throw new Error("package.json must block npm publish with ci/verify-publish-metadata.js until metadata is final.");
|
|
723
|
+
}
|
|
724
|
+
}
|
|
725
|
+
|
|
726
|
+
function verifyPublishMetadataGuard(packageDir) {
|
|
727
|
+
const guardPath = path.join(packageDir, "ci", "verify-publish-metadata.js");
|
|
728
|
+
const report = JSON.parse(exec(process.execPath, [guardPath, "--allow-local", "--json"], { cwd: packageDir }));
|
|
729
|
+
if (report.format !== "jso-protector-publish-metadata") {
|
|
730
|
+
throw new Error(`Publish metadata guard reported wrong format: ${JSON.stringify(report)}`);
|
|
731
|
+
}
|
|
732
|
+
if (report.ok !== true || report.localOnly !== true || report.localAllowed !== true || report.publishReady !== false) {
|
|
733
|
+
throw new Error(`Publish metadata guard should confirm the local-only package policy: ${JSON.stringify(report)}`);
|
|
734
|
+
}
|
|
735
|
+
if ((report.issues || []).length) {
|
|
736
|
+
throw new Error(`Publish metadata guard reported unexpected local-only issues: ${JSON.stringify(report)}`);
|
|
737
|
+
}
|
|
738
|
+
}
|
|
739
|
+
|
|
740
|
+
function walkFiles(dir) {
|
|
741
|
+
const files = [];
|
|
742
|
+
for (const entry of fs.readdirSync(dir, { withFileTypes: true })) {
|
|
743
|
+
const entryPath = path.join(dir, entry.name);
|
|
744
|
+
if (entry.isDirectory()) files.push(...walkFiles(entryPath));
|
|
745
|
+
else if (entry.isFile()) files.push(entryPath);
|
|
746
|
+
}
|
|
747
|
+
return files;
|
|
748
|
+
}
|