@drift-agent/api-drift-engine 5.1.0 → 5.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/README.md +15 -15
- package/index.js +6 -6
- package/install.js +8 -8
- package/package.json +2 -2
- package/run.js +3 -3
package/README.md
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
API schema diff engine — detect breaking changes in **OpenAPI**, **GraphQL**, and **gRPC** schemas.
|
|
4
4
|
|
|
5
|
-
Thin npm wrapper around the [`drift-
|
|
5
|
+
Thin npm wrapper around the [`drift-agent`](https://github.com/DriftAgent/api-drift-engine) Go binary. On install, the correct pre-built binary for your platform is downloaded automatically.
|
|
6
6
|
|
|
7
7
|
## Installation
|
|
8
8
|
|
|
@@ -14,32 +14,32 @@ Requires Node.js ≥ 16. The binary is downloaded for your platform (macOS arm64
|
|
|
14
14
|
|
|
15
15
|
## CLI
|
|
16
16
|
|
|
17
|
-
After installing, the `drift-
|
|
17
|
+
After installing, the `drift-agent` binary is available as an npm bin:
|
|
18
18
|
|
|
19
19
|
```sh
|
|
20
|
-
npx drift-
|
|
20
|
+
npx drift-agent --help
|
|
21
21
|
```
|
|
22
22
|
|
|
23
23
|
### OpenAPI
|
|
24
24
|
|
|
25
25
|
```sh
|
|
26
|
-
drift-
|
|
27
|
-
drift-
|
|
28
|
-
drift-
|
|
26
|
+
drift-agent openapi --base old.yaml --head new.yaml
|
|
27
|
+
drift-agent openapi --base old.yaml --head new.yaml --format json
|
|
28
|
+
drift-agent openapi --base old.yaml --head new.yaml --fail-on-breaking
|
|
29
29
|
```
|
|
30
30
|
|
|
31
31
|
### GraphQL
|
|
32
32
|
|
|
33
33
|
```sh
|
|
34
|
-
drift-
|
|
35
|
-
drift-
|
|
34
|
+
drift-agent graphql --base old.graphql --head new.graphql
|
|
35
|
+
drift-agent graphql --base old.graphql --head new.graphql --format markdown
|
|
36
36
|
```
|
|
37
37
|
|
|
38
38
|
### gRPC / Protobuf
|
|
39
39
|
|
|
40
40
|
```sh
|
|
41
|
-
drift-
|
|
42
|
-
drift-
|
|
41
|
+
drift-agent grpc --base old.proto --head new.proto
|
|
42
|
+
drift-agent grpc --base old.proto --head new.proto --format json
|
|
43
43
|
```
|
|
44
44
|
|
|
45
45
|
### Impact analysis
|
|
@@ -48,15 +48,15 @@ Scan source code for references to each breaking change:
|
|
|
48
48
|
|
|
49
49
|
```sh
|
|
50
50
|
# From a saved diff JSON
|
|
51
|
-
drift-
|
|
52
|
-
drift-
|
|
51
|
+
drift-agent openapi --base old.yaml --head new.yaml --format json > diff.json
|
|
52
|
+
drift-agent impact --diff diff.json --scan ./src
|
|
53
53
|
|
|
54
54
|
# Pipe mode
|
|
55
|
-
drift-
|
|
56
|
-
| drift-
|
|
55
|
+
drift-agent openapi --base old.yaml --head new.yaml --format json \
|
|
56
|
+
| drift-agent impact --scan ./src
|
|
57
57
|
|
|
58
58
|
# Output as markdown
|
|
59
|
-
drift-
|
|
59
|
+
drift-agent impact --diff diff.json --scan ./src --format markdown
|
|
60
60
|
```
|
|
61
61
|
|
|
62
62
|
## Node.js / TypeScript API
|
package/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
// Programmatic API — wraps the drift-
|
|
2
|
+
// Programmatic API — wraps the drift-agent binary and returns parsed results.
|
|
3
3
|
|
|
4
4
|
const path = require("path");
|
|
5
5
|
const { spawnSync } = require("child_process");
|
|
@@ -7,22 +7,22 @@ const { spawnSync } = require("child_process");
|
|
|
7
7
|
const BIN = path.join(
|
|
8
8
|
__dirname,
|
|
9
9
|
"bin",
|
|
10
|
-
process.platform === "win32" ? "drift-
|
|
10
|
+
process.platform === "win32" ? "drift-agent.exe" : "drift-agent"
|
|
11
11
|
);
|
|
12
12
|
|
|
13
13
|
/**
|
|
14
|
-
* Run the drift-
|
|
14
|
+
* Run the drift-agent binary and return its stdout.
|
|
15
15
|
* @param {string[]} args
|
|
16
16
|
* @returns {string}
|
|
17
17
|
*/
|
|
18
18
|
function run(args) {
|
|
19
19
|
const result = spawnSync(BIN, args, { encoding: "utf8" });
|
|
20
20
|
if (result.error) {
|
|
21
|
-
throw new Error(`drift-
|
|
21
|
+
throw new Error(`drift-agent binary error: ${result.error.message}`);
|
|
22
22
|
}
|
|
23
23
|
if (result.status !== 0 && result.status !== 1) {
|
|
24
24
|
// exit 1 means breaking changes found (--fail-on-breaking), not a crash
|
|
25
|
-
throw new Error(`drift-
|
|
25
|
+
throw new Error(`drift-agent exited with code ${result.status}: ${result.stderr}`);
|
|
26
26
|
}
|
|
27
27
|
return result.stdout;
|
|
28
28
|
}
|
|
@@ -70,7 +70,7 @@ function impact(diffResult, scanDir = ".", options = {}) {
|
|
|
70
70
|
const os = require("os");
|
|
71
71
|
|
|
72
72
|
// Write the diff result to a temp file so we can pass --diff
|
|
73
|
-
const tmp = require("path").join(os.tmpdir(), `drift-
|
|
73
|
+
const tmp = require("path").join(os.tmpdir(), `drift-agent-diff-${Date.now()}.json`);
|
|
74
74
|
try {
|
|
75
75
|
fs.writeFileSync(tmp, JSON.stringify(diffResult));
|
|
76
76
|
const out = run(["impact", "--diff", tmp, "--scan", scanDir, "--format", format]);
|
package/install.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
// postinstall: downloads the drift-
|
|
2
|
+
// postinstall: downloads the drift-agent binary from GitHub Releases.
|
|
3
3
|
"use strict";
|
|
4
4
|
|
|
5
5
|
const https = require("https");
|
|
@@ -11,7 +11,7 @@ const { execSync } = require("child_process");
|
|
|
11
11
|
const VERSION = require("./package.json").version;
|
|
12
12
|
const REPO = "DriftAgent/api-drift-engine";
|
|
13
13
|
const BIN_DIR = path.join(__dirname, "bin");
|
|
14
|
-
const BIN_PATH = path.join(BIN_DIR, process.platform === "win32" ? "drift-
|
|
14
|
+
const BIN_PATH = path.join(BIN_DIR, process.platform === "win32" ? "drift-agent.exe" : "drift-agent");
|
|
15
15
|
|
|
16
16
|
// Map Node.js platform/arch → goreleaser archive naming
|
|
17
17
|
function getPlatformInfo() {
|
|
@@ -32,7 +32,7 @@ function getPlatformInfo() {
|
|
|
32
32
|
}
|
|
33
33
|
|
|
34
34
|
const ext = goos === "windows" ? "zip" : "tar.gz";
|
|
35
|
-
const archive = `drift-
|
|
35
|
+
const archive = `drift-agent_${VERSION}_${goos}_${goarch}.${ext}`;
|
|
36
36
|
const url = `https://github.com/${REPO}/releases/download/v${VERSION}/${archive}`;
|
|
37
37
|
|
|
38
38
|
return { url, archive, ext };
|
|
@@ -64,10 +64,10 @@ async function install() {
|
|
|
64
64
|
}
|
|
65
65
|
|
|
66
66
|
const { url, archive, ext } = getPlatformInfo();
|
|
67
|
-
const tmpDir = fs.mkdtempSync(path.join(os.tmpdir(), "drift-
|
|
67
|
+
const tmpDir = fs.mkdtempSync(path.join(os.tmpdir(), "drift-agent-"));
|
|
68
68
|
const archivePath = path.join(tmpDir, archive);
|
|
69
69
|
|
|
70
|
-
process.stdout.write(`Downloading drift-
|
|
70
|
+
process.stdout.write(`Downloading drift-agent v${VERSION}...\n`);
|
|
71
71
|
|
|
72
72
|
try {
|
|
73
73
|
await download(url, archivePath);
|
|
@@ -80,18 +80,18 @@ async function install() {
|
|
|
80
80
|
execSync(`unzip -o "${archivePath}" -d "${tmpDir}"`);
|
|
81
81
|
}
|
|
82
82
|
|
|
83
|
-
const extracted = path.join(tmpDir, process.platform === "win32" ? "drift-
|
|
83
|
+
const extracted = path.join(tmpDir, process.platform === "win32" ? "drift-agent.exe" : "drift-agent");
|
|
84
84
|
fs.copyFileSync(extracted, BIN_PATH);
|
|
85
85
|
fs.chmodSync(BIN_PATH, 0o755);
|
|
86
86
|
|
|
87
|
-
process.stdout.write(`drift-
|
|
87
|
+
process.stdout.write(`drift-agent installed to ${BIN_PATH}\n`);
|
|
88
88
|
} finally {
|
|
89
89
|
fs.rmSync(tmpDir, { recursive: true, force: true });
|
|
90
90
|
}
|
|
91
91
|
}
|
|
92
92
|
|
|
93
93
|
install().catch((err) => {
|
|
94
|
-
process.stderr.write(`drift-
|
|
94
|
+
process.stderr.write(`drift-agent install failed: ${err.message}\n`);
|
|
95
95
|
process.stderr.write("You can install it manually: https://github.com/DriftAgent/api-drift-engine/releases\n");
|
|
96
96
|
// Do not exit(1) — allow npm install to succeed even if binary download fails.
|
|
97
97
|
});
|
package/package.json
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@drift-agent/api-drift-engine",
|
|
3
|
-
"version": "5.
|
|
3
|
+
"version": "5.2.0",
|
|
4
4
|
"description": "API schema diff engine — detect breaking changes in OpenAPI, GraphQL, and gRPC schemas",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"types": "index.d.ts",
|
|
7
7
|
"bin": {
|
|
8
|
-
"drift-
|
|
8
|
+
"drift-agent": "run.js"
|
|
9
9
|
},
|
|
10
10
|
"scripts": {
|
|
11
11
|
"postinstall": "node install.js"
|
package/run.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
// Thin shim: passes all arguments to the drift-
|
|
2
|
+
// Thin shim: passes all arguments to the drift-agent binary.
|
|
3
3
|
"use strict";
|
|
4
4
|
|
|
5
5
|
const path = require("path");
|
|
@@ -8,14 +8,14 @@ const { spawnSync } = require("child_process");
|
|
|
8
8
|
const bin = path.join(
|
|
9
9
|
__dirname,
|
|
10
10
|
"bin",
|
|
11
|
-
process.platform === "win32" ? "drift-
|
|
11
|
+
process.platform === "win32" ? "drift-agent.exe" : "drift-agent"
|
|
12
12
|
);
|
|
13
13
|
|
|
14
14
|
const result = spawnSync(bin, process.argv.slice(2), { stdio: "inherit" });
|
|
15
15
|
|
|
16
16
|
if (result.error) {
|
|
17
17
|
process.stderr.write(
|
|
18
|
-
`drift-
|
|
18
|
+
`drift-agent: could not run binary: ${result.error.message}\n` +
|
|
19
19
|
`Make sure the package installed correctly or download manually:\n` +
|
|
20
20
|
`https://github.com/DriftAgent/api-drift-engine/releases\n`
|
|
21
21
|
);
|