@dxos/protobuf-compiler 0.8.3 → 0.8.4-main.1da679c
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/bin/main.js +8 -2
- package/dist/src/configure.d.ts.map +1 -1
- package/dist/src/configure.js +1 -1
- package/dist/src/configure.js.map +1 -1
- package/dist/src/generator/declaration-generator.d.ts.map +1 -1
- package/dist/src/generator/declaration-generator.js +1 -1
- package/dist/src/generator/declaration-generator.js.map +1 -1
- package/dist/src/generator/enum.d.ts.map +1 -1
- package/dist/src/generator/enum.js.map +1 -1
- package/dist/src/generator/field.d.ts.map +1 -1
- package/dist/src/generator/field.js.map +1 -1
- package/dist/src/generator/file-generator.d.ts.map +1 -1
- package/dist/src/generator/file-generator.js +2 -2
- package/dist/src/generator/file-generator.js.map +1 -1
- package/dist/src/generator/message.d.ts.map +1 -1
- package/dist/src/generator/message.js.map +1 -1
- package/dist/src/generator/service.d.ts.map +1 -1
- package/dist/src/generator/service.js +2 -2
- package/dist/src/generator/service.js.map +1 -1
- package/dist/src/logger.d.ts.map +1 -1
- package/dist/src/logger.js +0 -4
- package/dist/src/logger.js.map +1 -1
- package/dist/src/main.js +8 -5
- package/dist/src/main.js.map +1 -1
- package/dist/src/module-specifier.js +1 -1
- package/dist/src/module-specifier.js.map +1 -1
- package/dist/src/namespaces.test.js +1 -1
- package/dist/src/namespaces.test.js.map +1 -1
- package/dist/src/parser/resolver.d.ts.map +1 -1
- package/dist/src/parser/resolver.js +1 -1
- package/dist/src/parser/resolver.js.map +1 -1
- package/dist/src/type-generator.d.ts.map +1 -1
- package/dist/src/type-generator.js +1 -1
- package/dist/src/type-generator.js.map +1 -1
- package/dist/test/proto/gen/example/testing/another.d.ts.map +1 -1
- package/dist/test/proto/gen/example/testing/any.d.ts.map +1 -1
- package/dist/test/proto/gen/example/testing/extensions.d.ts +30 -0
- package/dist/test/proto/gen/example/testing/extensions.d.ts.map +1 -0
- package/dist/test/proto/gen/example/testing/extensions.js +1 -0
- package/dist/test/proto/gen/example/testing/extensions.js.map +1 -0
- package/dist/test/proto/gen/example/testing/service.d.ts.map +1 -1
- package/dist/test/proto/gen/example/testing/types.d.ts.map +1 -1
- package/dist/test/proto/gen/example/testing/types.js.map +1 -1
- package/dist/test/proto/gen/example/testing/util.d.ts.map +1 -1
- package/dist/test/proto/gen/google/protobuf.d.ts +9 -6
- package/dist/test/proto/gen/google/protobuf.d.ts.map +1 -1
- package/dist/test/proto/gen/google/protobuf.js.map +1 -1
- package/dist/test/proto/gen/index.d.ts +4 -0
- package/dist/test/proto/gen/index.d.ts.map +1 -1
- package/dist/test/proto/gen/index.js +2 -2
- package/dist/test/proto/gen/index.js.map +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +10 -10
- package/src/configure.ts +2 -1
- package/src/generator/declaration-generator.ts +2 -1
- package/src/generator/enum.ts +1 -0
- package/src/generator/field.ts +2 -1
- package/src/generator/file-generator.ts +5 -3
- package/src/generator/message.ts +1 -0
- package/src/generator/service.ts +5 -3
- package/src/logger.ts +2 -14
- package/src/main.ts +17 -5
- package/src/module-specifier.ts +1 -1
- package/src/namespaces.test.ts +2 -1
- package/src/parser/resolver.ts +2 -1
- package/src/type-generator.ts +3 -2
package/src/generator/field.ts
CHANGED
|
@@ -7,9 +7,10 @@ import * as ts from 'typescript';
|
|
|
7
7
|
|
|
8
8
|
import { invariant } from '@dxos/invariant';
|
|
9
9
|
|
|
10
|
-
import { types } from './types';
|
|
11
10
|
import { type SubstitutionsMap } from '../parser';
|
|
12
11
|
|
|
12
|
+
import { types } from './types';
|
|
13
|
+
|
|
13
14
|
const f = ts.factory;
|
|
14
15
|
|
|
15
16
|
export const getFieldType = (field: pb.Field, subs: SubstitutionsMap): ts.TypeNode => {
|
|
@@ -3,16 +3,18 @@
|
|
|
3
3
|
//
|
|
4
4
|
|
|
5
5
|
import { dirname, join } from 'path';
|
|
6
|
+
|
|
6
7
|
import type pb from 'protobufjs';
|
|
7
8
|
import * as ts from 'typescript';
|
|
8
9
|
|
|
10
|
+
import { CODEC_MODULE, ModuleSpecifier } from '../module-specifier';
|
|
11
|
+
import { getSafeNamespaceIdentifier, parseFullyQualifiedName } from '../namespaces';
|
|
12
|
+
import { type SubstitutionsMap } from '../parser';
|
|
13
|
+
|
|
9
14
|
import { type GeneratorContext } from './context';
|
|
10
15
|
import { createDeclarations, createTypeDictionary } from './declaration-generator';
|
|
11
16
|
import { createSerializerDefinition } from './serializer-definition-generator';
|
|
12
17
|
import { createServicesDictionary } from './service';
|
|
13
|
-
import { CODEC_MODULE, ModuleSpecifier } from '../module-specifier';
|
|
14
|
-
import { getSafeNamespaceIdentifier, parseFullyQualifiedName } from '../namespaces';
|
|
15
|
-
import { type SubstitutionsMap } from '../parser';
|
|
16
18
|
|
|
17
19
|
const f = ts.factory;
|
|
18
20
|
|
package/src/generator/message.ts
CHANGED
package/src/generator/service.ts
CHANGED
|
@@ -3,17 +3,19 @@
|
|
|
3
3
|
//
|
|
4
4
|
|
|
5
5
|
import { dirname, relative } from 'path';
|
|
6
|
+
|
|
6
7
|
import pb from 'protobufjs';
|
|
7
8
|
import * as ts from 'typescript';
|
|
8
9
|
|
|
9
10
|
import { invariant } from '@dxos/invariant';
|
|
10
11
|
|
|
11
|
-
import { type GeneratorContext } from './context';
|
|
12
|
-
import { attachDocComment } from './doc-comment';
|
|
13
|
-
import { types, getTypeReference } from './types';
|
|
14
12
|
import { normalizeFullyQualifiedName } from '../namespaces';
|
|
15
13
|
import { type SubstitutionsMap } from '../parser';
|
|
16
14
|
|
|
15
|
+
import { type GeneratorContext } from './context';
|
|
16
|
+
import { attachDocComment } from './doc-comment';
|
|
17
|
+
import { getTypeReference, types } from './types';
|
|
18
|
+
|
|
17
19
|
const f = ts.factory;
|
|
18
20
|
|
|
19
21
|
const getRpcTypes = (method: pb.Method, service: pb.Service, subs: SubstitutionsMap): [ts.TypeNode, ts.TypeNode] => {
|
package/src/logger.ts
CHANGED
|
@@ -2,8 +2,6 @@
|
|
|
2
2
|
// Copyright 2020 DXOS.org
|
|
3
3
|
//
|
|
4
4
|
|
|
5
|
-
/* eslint-disable no-console */
|
|
6
|
-
|
|
7
5
|
import chalk from 'chalk';
|
|
8
6
|
|
|
9
7
|
import { type ModuleSpecifier } from './module-specifier';
|
|
@@ -16,12 +14,7 @@ type LoggerOptions = {
|
|
|
16
14
|
export class Logger {
|
|
17
15
|
constructor(private readonly _options: LoggerOptions = {}) {}
|
|
18
16
|
|
|
19
|
-
|
|
20
|
-
logCompilationOptions(
|
|
21
|
-
protoFilePaths: string[],
|
|
22
|
-
baseDirPath: string | undefined,
|
|
23
|
-
outDirPath: string
|
|
24
|
-
): void {
|
|
17
|
+
logCompilationOptions(protoFilePaths: string[], baseDirPath: string | undefined, outDirPath: string): void {
|
|
25
18
|
if (this._options?.verbose) {
|
|
26
19
|
console.log(chalk`Output: {bold ${outDirPath}}`);
|
|
27
20
|
console.log(chalk`Sources:`);
|
|
@@ -32,12 +25,7 @@ export class Logger {
|
|
|
32
25
|
}
|
|
33
26
|
}
|
|
34
27
|
|
|
35
|
-
|
|
36
|
-
logParsedSubstitutions(
|
|
37
|
-
substitutionsModule: ModuleSpecifier,
|
|
38
|
-
substitutions: SubstitutionsMap
|
|
39
|
-
): void {
|
|
40
|
-
console.log('Processing substitutions...');
|
|
28
|
+
logParsedSubstitutions(substitutionsModule: ModuleSpecifier, substitutions: SubstitutionsMap): void {
|
|
41
29
|
if (this._options?.verbose) {
|
|
42
30
|
console.log(chalk`Definitions: {bold ${substitutionsModule.resolve()}}`);
|
|
43
31
|
if (Object.keys(substitutions).length > 0) {
|
package/src/main.ts
CHANGED
|
@@ -4,8 +4,10 @@
|
|
|
4
4
|
// Copyright 2020 DXOS.org
|
|
5
5
|
//
|
|
6
6
|
|
|
7
|
-
import { ArgumentParser } from 'argparse';
|
|
8
7
|
import { resolve } from 'node:path';
|
|
8
|
+
|
|
9
|
+
import { ArgumentParser } from 'argparse';
|
|
10
|
+
import glob from 'glob';
|
|
9
11
|
import readPkg from 'read-pkg';
|
|
10
12
|
|
|
11
13
|
import { preconfigureProtobufjs } from './configure';
|
|
@@ -21,7 +23,7 @@ const main = async () => {
|
|
|
21
23
|
});
|
|
22
24
|
|
|
23
25
|
parser.add_argument('-v', '--version', { action: 'version', version } as any);
|
|
24
|
-
parser.add_argument('
|
|
26
|
+
parser.add_argument('--src', { help: 'Protobuf input files' });
|
|
25
27
|
parser.add_argument('-s', '--substitutions', { help: 'Substitutions file' });
|
|
26
28
|
parser.add_argument('--baseDir', {
|
|
27
29
|
help: 'Base path to resolve fully qualified packages',
|
|
@@ -31,9 +33,9 @@ const main = async () => {
|
|
|
31
33
|
required: true,
|
|
32
34
|
});
|
|
33
35
|
|
|
34
|
-
const {
|
|
36
|
+
const { src, substitutions, baseDir, outDir } = parser.parse_args();
|
|
35
37
|
|
|
36
|
-
const protoFilePaths =
|
|
38
|
+
const protoFilePaths = glob.sync(src, { cwd: process.cwd() }).map((file: string) => resolve(process.cwd(), file));
|
|
37
39
|
const substitutionsModule = substitutions
|
|
38
40
|
? ModuleSpecifier.resolveFromFilePath(substitutions, process.cwd())
|
|
39
41
|
: undefined;
|
|
@@ -44,7 +46,17 @@ const main = async () => {
|
|
|
44
46
|
registerResolver(baseDirPath);
|
|
45
47
|
preconfigureProtobufjs();
|
|
46
48
|
|
|
47
|
-
await parseAndGenerateSchema(
|
|
49
|
+
await parseAndGenerateSchema(
|
|
50
|
+
substitutionsModule,
|
|
51
|
+
protoFilePaths,
|
|
52
|
+
baseDirPath,
|
|
53
|
+
outDirPath,
|
|
54
|
+
process.cwd(),
|
|
55
|
+
// TODO(wittjosiah): Expose as args.
|
|
56
|
+
undefined,
|
|
57
|
+
true,
|
|
58
|
+
false,
|
|
59
|
+
);
|
|
48
60
|
};
|
|
49
61
|
|
|
50
62
|
void main();
|
package/src/module-specifier.ts
CHANGED
package/src/namespaces.test.ts
CHANGED
|
@@ -2,9 +2,10 @@
|
|
|
2
2
|
// Copyright 2020 DXOS.org
|
|
3
3
|
//
|
|
4
4
|
|
|
5
|
+
import { join, resolve } from 'path';
|
|
6
|
+
|
|
5
7
|
import expect from 'expect';
|
|
6
8
|
import { it as test } from 'mocha';
|
|
7
|
-
import { resolve, join } from 'path';
|
|
8
9
|
import pb from 'protobufjs';
|
|
9
10
|
|
|
10
11
|
import { preconfigureProtobufjs } from './configure';
|
package/src/parser/resolver.ts
CHANGED
|
@@ -5,6 +5,7 @@
|
|
|
5
5
|
import { existsSync } from 'fs';
|
|
6
6
|
import { createRequire } from 'node:module';
|
|
7
7
|
import { basename, dirname, join } from 'path';
|
|
8
|
+
|
|
8
9
|
import pb from 'protobufjs';
|
|
9
10
|
|
|
10
11
|
const require = createRequire(import.meta.url);
|
|
@@ -25,7 +26,7 @@ export function createProtoResolver(original: ProtoResolver, baseDir?: string):
|
|
|
25
26
|
|
|
26
27
|
try {
|
|
27
28
|
// Test if referenced package.
|
|
28
|
-
// eslint-disable-next-line @typescript-eslint/no-
|
|
29
|
+
// eslint-disable-next-line @typescript-eslint/no-require-imports
|
|
29
30
|
const config = require(join(target, 'package.json'));
|
|
30
31
|
if (typeof config.protobuf !== 'string') {
|
|
31
32
|
throw new Error(`Package "${target}" does not expose "protobuf" file.`);
|
package/src/type-generator.ts
CHANGED
|
@@ -4,19 +4,20 @@
|
|
|
4
4
|
|
|
5
5
|
import { existsSync, mkdirSync, writeFileSync } from 'fs';
|
|
6
6
|
import { dirname, join } from 'path';
|
|
7
|
+
|
|
7
8
|
import pb from 'protobufjs';
|
|
8
9
|
import * as ts from 'typescript';
|
|
9
10
|
|
|
10
11
|
import {
|
|
11
12
|
createIndexSourceFile,
|
|
12
13
|
createNamespaceSourceFile,
|
|
13
|
-
getFileNameForNamespace,
|
|
14
14
|
generatePackageExports,
|
|
15
|
+
getFileNameForNamespace,
|
|
15
16
|
} from './generator';
|
|
16
17
|
import { Logger } from './logger';
|
|
17
18
|
import { type ModuleSpecifier } from './module-specifier';
|
|
18
19
|
import { splitSchemaIntoNamespaces } from './namespaces';
|
|
19
|
-
import {
|
|
20
|
+
import { type SubstitutionsMap, parseSubstitutionsFile } from './parser';
|
|
20
21
|
|
|
21
22
|
// TODO(dmaretskyi): Move all parsing into `generateSchema` and remove this function.
|
|
22
23
|
export const parseAndGenerateSchema = async (
|