cpd 1.0.0 → 5.0.2
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/package.json +39 -6
- package/platform-map.js +84 -0
- package/run-cpd.js +61 -0
package/package.json
CHANGED
|
@@ -1,8 +1,41 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "cpd",
|
|
3
|
-
"version": "
|
|
4
|
-
"description": "Copy/
|
|
5
|
-
"
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
3
|
+
"version": "5.0.2",
|
|
4
|
+
"description": "Copy/paste detector — fast Rust-based CLI for code duplication detection",
|
|
5
|
+
"bin": {
|
|
6
|
+
"cpd": "./run-cpd.js"
|
|
7
|
+
},
|
|
8
|
+
"files": [
|
|
9
|
+
"run-cpd.js",
|
|
10
|
+
"platform-map.js"
|
|
11
|
+
],
|
|
12
|
+
"optionalDependencies": {
|
|
13
|
+
"cpd-linux-x64-gnu": "5.0.2",
|
|
14
|
+
"cpd-linux-arm64-gnu": "5.0.2",
|
|
15
|
+
"cpd-linux-x64-musl": "5.0.2",
|
|
16
|
+
"cpd-darwin-arm64": "5.0.2",
|
|
17
|
+
"cpd-darwin-x64": "5.0.2",
|
|
18
|
+
"cpd-windows-x64-msvc": "5.0.2"
|
|
19
|
+
},
|
|
20
|
+
"repository": {
|
|
21
|
+
"type": "git",
|
|
22
|
+
"url": "https://github.com/kucherenko/jscpd",
|
|
23
|
+
"directory": "rust"
|
|
24
|
+
},
|
|
25
|
+
"keywords": [
|
|
26
|
+
"cpd",
|
|
27
|
+
"copy-paste-detector",
|
|
28
|
+
"duplicate",
|
|
29
|
+
"jscpd",
|
|
30
|
+
"code-duplication",
|
|
31
|
+
"cli",
|
|
32
|
+
"rust"
|
|
33
|
+
],
|
|
34
|
+
"license": "MIT",
|
|
35
|
+
"engines": {
|
|
36
|
+
"node": ">=18"
|
|
37
|
+
},
|
|
38
|
+
"publishConfig": {
|
|
39
|
+
"access": "public"
|
|
40
|
+
}
|
|
41
|
+
}
|
package/platform-map.js
ADDED
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
const { platform, arch } = process;
|
|
4
|
+
|
|
5
|
+
const PLATFORM_MAP = {
|
|
6
|
+
"linux-x64-gnu": {
|
|
7
|
+
packageName: "cpd-linux-x64-gnu",
|
|
8
|
+
os: "linux",
|
|
9
|
+
cpu: "x64",
|
|
10
|
+
libc: "glibc",
|
|
11
|
+
rustTarget: "x86_64-unknown-linux-gnu",
|
|
12
|
+
runner: "ubuntu-latest",
|
|
13
|
+
},
|
|
14
|
+
"linux-arm64-gnu": {
|
|
15
|
+
packageName: "cpd-linux-arm64-gnu",
|
|
16
|
+
os: "linux",
|
|
17
|
+
cpu: "arm64",
|
|
18
|
+
libc: "glibc",
|
|
19
|
+
rustTarget: "aarch64-unknown-linux-gnu",
|
|
20
|
+
runner: "ubuntu-latest",
|
|
21
|
+
},
|
|
22
|
+
"linux-x64-musl": {
|
|
23
|
+
packageName: "cpd-linux-x64-musl",
|
|
24
|
+
os: "linux",
|
|
25
|
+
cpu: "x64",
|
|
26
|
+
libc: "musl",
|
|
27
|
+
rustTarget: "x86_64-unknown-linux-musl",
|
|
28
|
+
runner: "ubuntu-latest",
|
|
29
|
+
},
|
|
30
|
+
"darwin-arm64": {
|
|
31
|
+
packageName: "cpd-darwin-arm64",
|
|
32
|
+
os: "darwin",
|
|
33
|
+
cpu: "arm64",
|
|
34
|
+
rustTarget: "aarch64-apple-darwin",
|
|
35
|
+
runner: "macos-latest",
|
|
36
|
+
},
|
|
37
|
+
"darwin-x64": {
|
|
38
|
+
packageName: "cpd-darwin-x64",
|
|
39
|
+
os: "darwin",
|
|
40
|
+
cpu: "x64",
|
|
41
|
+
rustTarget: "x86_64-apple-darwin",
|
|
42
|
+
runner: "macos-13",
|
|
43
|
+
},
|
|
44
|
+
"windows-x64-msvc": {
|
|
45
|
+
packageName: "cpd-windows-x64-msvc",
|
|
46
|
+
os: "win32",
|
|
47
|
+
cpu: "x64",
|
|
48
|
+
rustTarget: "x86_64-pc-windows-msvc",
|
|
49
|
+
runner: "windows-latest",
|
|
50
|
+
},
|
|
51
|
+
};
|
|
52
|
+
|
|
53
|
+
function detectLinuxLibc() {
|
|
54
|
+
if (platform !== "linux") {
|
|
55
|
+
return undefined;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
const report =
|
|
59
|
+
process.report && typeof process.report.getReport === "function"
|
|
60
|
+
? process.report.getReport()
|
|
61
|
+
: undefined;
|
|
62
|
+
if (report && report.header && report.header.glibcVersionRuntime) {
|
|
63
|
+
return "glibc";
|
|
64
|
+
}
|
|
65
|
+
return "musl";
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
function getPlatformKey() {
|
|
69
|
+
const libc = detectLinuxLibc();
|
|
70
|
+
|
|
71
|
+
for (const [key, target] of Object.entries(PLATFORM_MAP)) {
|
|
72
|
+
if (target.os !== platform || target.cpu !== arch) {
|
|
73
|
+
continue;
|
|
74
|
+
}
|
|
75
|
+
if (target.os === "linux" && target.libc !== libc) {
|
|
76
|
+
continue;
|
|
77
|
+
}
|
|
78
|
+
return key;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
return undefined;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
module.exports = { PLATFORM_MAP, getPlatformKey };
|
package/run-cpd.js
ADDED
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
"use strict";
|
|
3
|
+
|
|
4
|
+
const path = require("path");
|
|
5
|
+
const { spawnSync } = require("child_process");
|
|
6
|
+
const { getPlatformKey, PLATFORM_MAP } = require("./platform-map");
|
|
7
|
+
|
|
8
|
+
const key = getPlatformKey();
|
|
9
|
+
if (!key) {
|
|
10
|
+
console.error(
|
|
11
|
+
`cpd: Unsupported platform ${process.platform}/${process.arch}`
|
|
12
|
+
);
|
|
13
|
+
process.exit(1);
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
const entry = PLATFORM_MAP[key];
|
|
17
|
+
const binaryName = process.platform === "win32" ? "cpd.exe" : "cpd";
|
|
18
|
+
|
|
19
|
+
let binaryPath;
|
|
20
|
+
try {
|
|
21
|
+
const pkgJson = require.resolve(`${entry.packageName}/package.json`, {
|
|
22
|
+
paths: [path.resolve(__dirname, "..")],
|
|
23
|
+
});
|
|
24
|
+
binaryPath = path.join(path.dirname(pkgJson), "cpd-bin", binaryName);
|
|
25
|
+
} catch {
|
|
26
|
+
const localBuild = path.join(
|
|
27
|
+
__dirname,
|
|
28
|
+
"target",
|
|
29
|
+
"release",
|
|
30
|
+
binaryName
|
|
31
|
+
);
|
|
32
|
+
const fs = require("fs");
|
|
33
|
+
if (fs.existsSync(localBuild)) {
|
|
34
|
+
binaryPath = localBuild;
|
|
35
|
+
} else {
|
|
36
|
+
console.error(
|
|
37
|
+
`cpd: Platform package "${entry.packageName}" not installed.` +
|
|
38
|
+
` Install it with: npm install ${entry.packageName}`
|
|
39
|
+
);
|
|
40
|
+
console.error(
|
|
41
|
+
"Alternatively, build from source: cargo build --release -p jscpd"
|
|
42
|
+
);
|
|
43
|
+
process.exit(1);
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
const result = spawnSync(binaryPath, process.argv.slice(2), {
|
|
48
|
+
stdio: "inherit",
|
|
49
|
+
});
|
|
50
|
+
|
|
51
|
+
if (result.error) {
|
|
52
|
+
if (result.error.code === "ENOENT") {
|
|
53
|
+
console.error(`cpd: binary not found: ${binaryPath}`);
|
|
54
|
+
process.exit(1);
|
|
55
|
+
}
|
|
56
|
+
throw result.error;
|
|
57
|
+
}
|
|
58
|
+
if (result.signal) {
|
|
59
|
+
process.kill(process.pid, result.signal);
|
|
60
|
+
}
|
|
61
|
+
process.exit(result.status ?? 0);
|