From 5f6020594bc56c71e0c5f7479a69478a4da4a5a4 Mon Sep 17 00:00:00 2001 From: Doug Parker Date: Mon, 1 Jun 2020 20:39:20 -0700 Subject: [PATCH] Renames `bxpb-runtime` to `@bxpb/runtime`. Refs #1. This updates the package name to use the new NPM scope. This improves protection against typo-squatting and clearly indicates that it is an "officially" supported package. I opted to have the directory structure as `packages/runtime/` rather than `packages/@bxpb/runtime/` as all packages should be under `@bxpb`, so it would just be extra typing and an extra directory which serves no benefit. --- README.md | 4 ++-- examples/greeter/package.json | 2 +- packages/README.md | 4 ++-- .../src/generators/clients.ts | 4 ++-- .../src/generators/clients_spec.ts | 12 ++++++------ .../src/generators/descriptors.ts | 2 +- .../src/generators/descriptors_spec.ts | 8 ++++---- .../src/generators/services.ts | 4 ++-- .../src/generators/services_spec.ts | 8 ++++---- packages/{bxpb-runtime => runtime}/README.md | 18 +++++++++--------- .../{bxpb-runtime => runtime}/karma.conf.js | 0 .../package-lock.json | 2 +- .../{bxpb-runtime => runtime}/package.json | 4 ++-- .../{bxpb-runtime => runtime}/src/client.ts | 0 .../src/client_spec.ts | 0 .../src/descriptors.ts | 0 .../{bxpb-runtime => runtime}/src/encoders.ts | 0 .../src/encoders_spec.ts | 0 .../{bxpb-runtime => runtime}/src/service.ts | 0 .../src/service_spec.ts | 0 .../src/test_data/greeter.proto | 0 .../src/testing/fake_event.ts | 0 .../src/testing/fake_event_spec.ts | 0 .../src/wire_format.d.ts | 0 .../{bxpb-runtime => runtime}/tsconfig.json | 0 .../tsconfig.lib.json | 0 .../tsconfig.spec.json | 0 27 files changed, 36 insertions(+), 36 deletions(-) rename packages/{bxpb-runtime => runtime}/README.md (76%) rename packages/{bxpb-runtime => runtime}/karma.conf.js (100%) rename packages/{bxpb-runtime => runtime}/package-lock.json (99%) rename packages/{bxpb-runtime => runtime}/package.json (94%) rename packages/{bxpb-runtime => runtime}/src/client.ts (100%) rename packages/{bxpb-runtime => runtime}/src/client_spec.ts (100%) rename packages/{bxpb-runtime => runtime}/src/descriptors.ts (100%) rename packages/{bxpb-runtime => runtime}/src/encoders.ts (100%) rename packages/{bxpb-runtime => runtime}/src/encoders_spec.ts (100%) rename packages/{bxpb-runtime => runtime}/src/service.ts (100%) rename packages/{bxpb-runtime => runtime}/src/service_spec.ts (100%) rename packages/{bxpb-runtime => runtime}/src/test_data/greeter.proto (100%) rename packages/{bxpb-runtime => runtime}/src/testing/fake_event.ts (100%) rename packages/{bxpb-runtime => runtime}/src/testing/fake_event_spec.ts (100%) rename packages/{bxpb-runtime => runtime}/src/wire_format.d.ts (100%) rename packages/{bxpb-runtime => runtime}/tsconfig.json (100%) rename packages/{bxpb-runtime => runtime}/tsconfig.lib.json (100%) rename packages/{bxpb-runtime => runtime}/tsconfig.spec.json (100%) diff --git a/README.md b/README.md index f817130..e7d73d3 100644 --- a/README.md +++ b/README.md @@ -49,7 +49,7 @@ could implemented in a Chrome extension like so: ```typescript // service.ts -import { servePort } from 'bxpb-runtime'; +import { servePort } from '@bxpb/runtime'; import { GreeterService } from './protos/greeter_bx'; // Generated service. import { HelloRequest, HelloResponse } from './protos/greeter_pb'; @@ -93,7 +93,7 @@ The architecture will consist of a few packages: * `bxpb-protoc-compiler`: A plugin for `protoc` which generates TypeScript client/service stubs for a given protobuf service. -* `bxpb-runtime`: A runtime to be included that performs the real work of communicating between +* `@bxpb/runtime`: A runtime to be included that performs the real work of communicating between the client and service in a generic fashion. * This will include client and service stubs, rather than splitting them across multiple packages. This is to keep the number of packages down as much as possible. diff --git a/examples/greeter/package.json b/examples/greeter/package.json index d6fa2f8..ec5a696 100644 --- a/examples/greeter/package.json +++ b/examples/greeter/package.json @@ -22,7 +22,7 @@ "url": "https://github.com/dgp1130/bxpb/issues" }, "dependencies": { - "bxpb-runtime": "^0.0.0", + "@bxpb/runtime": "^0.0.0", "google-protobuf": "^3.12.0", "tslib": "^2.0.0" }, diff --git a/packages/README.md b/packages/README.md index 1253f4c..744d329 100644 --- a/packages/README.md +++ b/packages/README.md @@ -1,7 +1,7 @@ # BXPB Packages -This contains all the packages for BXPB. +This contains all the packages for BXPB. All of these are under the `@bxpb` scope. * [bxpb-protoc-plugin](bxpb-protoc-plugin/) - The compiler plugin which generates BXPB TypeScript definitions for protocol buffer source files. -* [bxpb-runtime](bxpb-runtime/) - The runtime for clients and services of BXPB. \ No newline at end of file +* [@bxpb/runtime](runtime/) - The runtime for clients and services of BXPB. \ No newline at end of file diff --git a/packages/bxpb-protoc-plugin/src/generators/clients.ts b/packages/bxpb-protoc-plugin/src/generators/clients.ts index d71f12e..14ff805 100644 --- a/packages/bxpb-protoc-plugin/src/generators/clients.ts +++ b/packages/bxpb-protoc-plugin/src/generators/clients.ts @@ -36,7 +36,7 @@ export function* generateClientFiles(file: string, fileDescriptor: FileDescripto /** Returns the generated JavaScript source as a string. */ function generateClientJs(filePath: path.ParsedPath, fileDescriptor: FileDescriptorProto): string { return ` -import { ProtoClient, rpc } from 'bxpb-runtime/dist/client.js'; +import { ProtoClient, rpc } from '@bxpb/runtime/dist/client.js'; import * as descriptors from './${filePath.name}_bxdescriptors.js'; ${fileDescriptor.getServiceList().map((service) => { @@ -66,7 +66,7 @@ export class ${serviceName}Client extends ProtoClient { /** Returns the generated TypeScript definitions as a string. */ function generateClientDts(filePath: path.ParsedPath, fileDescriptor: FileDescriptorProto): string { return ` -import { ProtoClient } from 'bxpb-runtime/dist/client'; +import { ProtoClient } from '@bxpb/runtime/dist/client'; import protos from './${filePath.name}_pb'; import * as descriptors from './${filePath.name}_bxdescriptors'; diff --git a/packages/bxpb-protoc-plugin/src/generators/clients_spec.ts b/packages/bxpb-protoc-plugin/src/generators/clients_spec.ts index 2c3f62f..a380ec9 100644 --- a/packages/bxpb-protoc-plugin/src/generators/clients_spec.ts +++ b/packages/bxpb-protoc-plugin/src/generators/clients_spec.ts @@ -24,7 +24,7 @@ describe('clients', ()=> { expect(jsFile.getName()).toBe('foo_bxclients.js'); expect(jsFile.getContent()).toBe(` -import { ProtoClient, rpc } from 'bxpb-runtime/dist/client.js'; +import { ProtoClient, rpc } from '@bxpb/runtime/dist/client.js'; import * as descriptors from './foo_bxdescriptors.js'; /** Client for calling {@link descriptors.FooService}. */ @@ -38,7 +38,7 @@ export class FooClient extends ProtoClient { expect(dtsFile.getName()).toBe('foo_bxclients.d.ts'); expect(dtsFile.getContent()).toBe(` -import { ProtoClient } from 'bxpb-runtime/dist/client'; +import { ProtoClient } from '@bxpb/runtime/dist/client'; import protos from './foo_pb'; import * as descriptors from './foo_bxdescriptors'; @@ -80,7 +80,7 @@ export class FooClient extends ProtoClient { generateClientFiles('foo.proto', fileDescriptor)); expect(jsFile.getContent()).toBe(` -import { ProtoClient, rpc } from 'bxpb-runtime/dist/client.js'; +import { ProtoClient, rpc } from '@bxpb/runtime/dist/client.js'; import * as descriptors from './foo_bxdescriptors.js'; /** Client for calling {@link descriptors.FooService}. */ @@ -101,7 +101,7 @@ export class BarClient extends ProtoClient { `.trim()); expect(dtsFile.getContent()).toBe(` -import { ProtoClient } from 'bxpb-runtime/dist/client'; +import { ProtoClient } from '@bxpb/runtime/dist/client'; import protos from './foo_pb'; import * as descriptors from './foo_bxdescriptors'; @@ -144,7 +144,7 @@ export class BarClient extends ProtoClient { generateClientFiles('foo.proto', fileDescriptor)); expect(jsFile.getContent()).toBe(` -import { ProtoClient, rpc } from 'bxpb-runtime/dist/client.js'; +import { ProtoClient, rpc } from '@bxpb/runtime/dist/client.js'; import * as descriptors from './foo_bxdescriptors.js'; /** Client for calling {@link descriptors.FooService}. */ @@ -162,7 +162,7 @@ export class FooClient extends ProtoClient { `.trim()); expect(dtsFile.getContent()).toBe(` -import { ProtoClient } from 'bxpb-runtime/dist/client'; +import { ProtoClient } from '@bxpb/runtime/dist/client'; import protos from './foo_pb'; import * as descriptors from './foo_bxdescriptors'; diff --git a/packages/bxpb-protoc-plugin/src/generators/descriptors.ts b/packages/bxpb-protoc-plugin/src/generators/descriptors.ts index 557a93b..9adc7c7 100644 --- a/packages/bxpb-protoc-plugin/src/generators/descriptors.ts +++ b/packages/bxpb-protoc-plugin/src/generators/descriptors.ts @@ -78,7 +78,7 @@ export const ${serviceName}Service = Object.freeze({ function generateDescriptorDts(filePath: path.ParsedPath, descriptor: FileDescriptorProto): string { return ` import { Message } from 'google-protobuf'; -import { MethodDescriptor, ServiceDescriptor } from 'bxpb-runtime/dist/descriptors'; +import { MethodDescriptor, ServiceDescriptor } from '@bxpb/runtime/dist/descriptors'; import protos from './${filePath.name}_pb'; ${descriptor.getServiceList().map((service) => { diff --git a/packages/bxpb-protoc-plugin/src/generators/descriptors_spec.ts b/packages/bxpb-protoc-plugin/src/generators/descriptors_spec.ts index bd2fe99..ad9f1ce 100644 --- a/packages/bxpb-protoc-plugin/src/generators/descriptors_spec.ts +++ b/packages/bxpb-protoc-plugin/src/generators/descriptors_spec.ts @@ -46,7 +46,7 @@ export const FooService = Object.freeze({ expect(dtsFile.getName()).toBe('foo_bxdescriptors.d.ts'); expect(dtsFile.getContent()).toBe(` import { Message } from 'google-protobuf'; -import { MethodDescriptor, ServiceDescriptor } from 'bxpb-runtime/dist/descriptors'; +import { MethodDescriptor, ServiceDescriptor } from '@bxpb/runtime/dist/descriptors'; import protos from './foo_pb'; /** Interface of \`Foo\`'s service descriptor. */ @@ -129,7 +129,7 @@ export const BarService = Object.freeze({ expect(dtsFile.getContent()).toBe(` import { Message } from 'google-protobuf'; -import { MethodDescriptor, ServiceDescriptor } from 'bxpb-runtime/dist/descriptors'; +import { MethodDescriptor, ServiceDescriptor } from '@bxpb/runtime/dist/descriptors'; import protos from './foo_pb'; /** Interface of \`Foo\`'s service descriptor. */ @@ -213,7 +213,7 @@ export const FooService = Object.freeze({ expect(dtsFile.getContent()).toBe(` import { Message } from 'google-protobuf'; -import { MethodDescriptor, ServiceDescriptor } from 'bxpb-runtime/dist/descriptors'; +import { MethodDescriptor, ServiceDescriptor } from '@bxpb/runtime/dist/descriptors'; import protos from './foo_pb'; /** Interface of \`Foo\`'s service descriptor. */ @@ -293,7 +293,7 @@ export const FooService = Object.freeze({ expect(dtsFile.getContent()).toBe(` import { Message } from 'google-protobuf'; -import { MethodDescriptor, ServiceDescriptor } from 'bxpb-runtime/dist/descriptors'; +import { MethodDescriptor, ServiceDescriptor } from '@bxpb/runtime/dist/descriptors'; import protos from './foo_pb'; /** Interface of \`Foo\`'s service descriptor. */ diff --git a/packages/bxpb-protoc-plugin/src/generators/services.ts b/packages/bxpb-protoc-plugin/src/generators/services.ts index e32a62c..bb0038f 100644 --- a/packages/bxpb-protoc-plugin/src/generators/services.ts +++ b/packages/bxpb-protoc-plugin/src/generators/services.ts @@ -45,7 +45,7 @@ function generateServiceJs(filePath: path.ParsedPath, descriptor: FileDescriptor }); return ` -import { serve } from 'bxpb-runtime/dist/service.js'; +import { serve } from '@bxpb/runtime/dist/service.js'; import * as descriptors from './${filePath.name}_bxdescriptors.js'; ${serviceNames.map((serviceName) => ` @@ -69,7 +69,7 @@ function generateServiceDts(filePath: path.ParsedPath, descriptor: FileDescripto }); return ` -import { Transport, ServiceImplementation } from 'bxpb-runtime/dist/service'; +import { Transport, ServiceImplementation } from '@bxpb/runtime/dist/service'; import * as descriptors from './${filePath.name}_bxdescriptors'; ${serviceNames.map((serviceName) => ` diff --git a/packages/bxpb-protoc-plugin/src/generators/services_spec.ts b/packages/bxpb-protoc-plugin/src/generators/services_spec.ts index 8b03522..c8469ef 100644 --- a/packages/bxpb-protoc-plugin/src/generators/services_spec.ts +++ b/packages/bxpb-protoc-plugin/src/generators/services_spec.ts @@ -17,7 +17,7 @@ describe('services', () => { expect(jsFile.getName()).toBe('foo_bxservices.js'); expect(jsFile.getContent()).toBe(` -import { serve } from 'bxpb-runtime/dist/service.js'; +import { serve } from '@bxpb/runtime/dist/service.js'; import * as descriptors from './foo_bxdescriptors.js'; /** @@ -31,7 +31,7 @@ export function serveFoo(transport, serviceImpl) { expect(dtsFile.getName()).toBe('foo_bxservices.d.ts'); expect(dtsFile.getContent()).toBe(` -import { Transport, ServiceImplementation } from 'bxpb-runtime/dist/service'; +import { Transport, ServiceImplementation } from '@bxpb/runtime/dist/service'; import * as descriptors from './foo_bxdescriptors'; /** @@ -54,7 +54,7 @@ export function serveFoo(transport: Transport, serviceImpl: ServiceImplementatio 'foo.proto', fileDescriptor)); expect(jsFile.getContent()).toBe(` -import { serve } from 'bxpb-runtime/dist/service.js'; +import { serve } from '@bxpb/runtime/dist/service.js'; import * as descriptors from './foo_bxdescriptors.js'; /** @@ -75,7 +75,7 @@ export function serveBar(transport, serviceImpl) { `.trim()); expect(dtsFile.getContent()).toBe(` -import { Transport, ServiceImplementation } from 'bxpb-runtime/dist/service'; +import { Transport, ServiceImplementation } from '@bxpb/runtime/dist/service'; import * as descriptors from './foo_bxdescriptors'; /** diff --git a/packages/bxpb-runtime/README.md b/packages/runtime/README.md similarity index 76% rename from packages/bxpb-runtime/README.md rename to packages/runtime/README.md index 5d553d2..1257c02 100644 --- a/packages/bxpb-runtime/README.md +++ b/packages/runtime/README.md @@ -1,4 +1,4 @@ -# `bxpb-runtime` +# `@bxpb/runtime` Implements the runtime for clients and services using `bxpb`. @@ -7,7 +7,7 @@ Implements the runtime for clients and services using `bxpb`. Services should use `serve()` to listen to a message passing API and run a service on it. ```typescript -import { serve } from 'bxpb-runtime/service'; +import { serve } from '@bxpb/runtime/service'; import { GreeterService } from 'protos/greeter_bx'; import { HelloRequest, HelloResponse } from 'protos/greeter_pb'; @@ -24,7 +24,7 @@ serve(chrome.runtime.onMessage, MyProtoService, { Clients should extend `ProtoClient` for a given service they want to call. ```typescript -import { ProtoClient } from 'bxpb-runtime/client'; +import { ProtoClient } from '@bxpb/runtime/client'; import { GreeterService } from 'protos/greeter_bx'; import { HelloRequest, HelloResponse } from 'protos/greeter_pb'; @@ -54,7 +54,7 @@ Client classes are typically generated by `bxpb-protoc-plugin` and not hand-writ To build this package, run from the repository root: ```shell -npm run -- lerna run build --stream --scope bxpb-runtime --include-dependencies +npm run -- lerna run build --stream --scope @bxpb/runtime --include-dependencies ``` Output files are stored in the `dist/` directory. @@ -64,15 +64,15 @@ Output files are stored in the `dist/` directory. Build and run unit tests with this command (run from the repository root): ```shell -npm run -- lerna run build --stream --scope bxpb-runtime --include-dependencies && - npm run -- lerna run test --stream --scope bxpb-runtime +npm run -- lerna run build --stream --scope @bxpb/runtime --include-dependencies && + npm run -- lerna run test --stream --scope @bxpb/runtime ``` You can debug tests by running: ```shell -npm run -- lerna run build --stream --scope bxpb-runtime --include-dependencies && - npm run -- lerna run test:debug --stream --scope bxpb-runtime +npm run -- lerna run build --stream --scope @bxpb/runtime --include-dependencies && + npm run -- lerna run test:debug --stream --scope @bxpb/runtime ``` This will start Karma on port 9876, open a browser to http://localhost:9876/debug.html to start @@ -80,5 +80,5 @@ debugging. Sourcemaps should work out of the box and are available under the `/b DevTools. Karma will live reload and incorpate any changes from the package without requiring a restart. -However this only works for changes within `bxpb-runtime`. If any dependent packages are modified, +However this only works for changes within `@bxpb/runtime`. If any dependent packages are modified, this will likely require a full rebuild. \ No newline at end of file diff --git a/packages/bxpb-runtime/karma.conf.js b/packages/runtime/karma.conf.js similarity index 100% rename from packages/bxpb-runtime/karma.conf.js rename to packages/runtime/karma.conf.js diff --git a/packages/bxpb-runtime/package-lock.json b/packages/runtime/package-lock.json similarity index 99% rename from packages/bxpb-runtime/package-lock.json rename to packages/runtime/package-lock.json index 5212249..c963457 100644 --- a/packages/bxpb-runtime/package-lock.json +++ b/packages/runtime/package-lock.json @@ -1,5 +1,5 @@ { - "name": "bxpb-runtime", + "name": "@bxpb/runtime", "version": "0.0.0", "lockfileVersion": 1, "requires": true, diff --git a/packages/bxpb-runtime/package.json b/packages/runtime/package.json similarity index 94% rename from packages/bxpb-runtime/package.json rename to packages/runtime/package.json index 0515e63..72fad05 100644 --- a/packages/bxpb-runtime/package.json +++ b/packages/runtime/package.json @@ -1,5 +1,5 @@ { - "name": "bxpb-runtime", + "name": "@bxpb/runtime", "version": "0.0.0", "description": "Runtime library for browser extension protocol buffers.", "keywords": [ @@ -13,7 +13,7 @@ "services" ], "author": "Doug Parker ", - "homepage": "https://github.com/dgp1130/bxpb/packages/bxpb-runtime/", + "homepage": "https://github.com/dgp1130/bxpb/packages/runtime/", "license": "MIT", "repository": { "type": "git", diff --git a/packages/bxpb-runtime/src/client.ts b/packages/runtime/src/client.ts similarity index 100% rename from packages/bxpb-runtime/src/client.ts rename to packages/runtime/src/client.ts diff --git a/packages/bxpb-runtime/src/client_spec.ts b/packages/runtime/src/client_spec.ts similarity index 100% rename from packages/bxpb-runtime/src/client_spec.ts rename to packages/runtime/src/client_spec.ts diff --git a/packages/bxpb-runtime/src/descriptors.ts b/packages/runtime/src/descriptors.ts similarity index 100% rename from packages/bxpb-runtime/src/descriptors.ts rename to packages/runtime/src/descriptors.ts diff --git a/packages/bxpb-runtime/src/encoders.ts b/packages/runtime/src/encoders.ts similarity index 100% rename from packages/bxpb-runtime/src/encoders.ts rename to packages/runtime/src/encoders.ts diff --git a/packages/bxpb-runtime/src/encoders_spec.ts b/packages/runtime/src/encoders_spec.ts similarity index 100% rename from packages/bxpb-runtime/src/encoders_spec.ts rename to packages/runtime/src/encoders_spec.ts diff --git a/packages/bxpb-runtime/src/service.ts b/packages/runtime/src/service.ts similarity index 100% rename from packages/bxpb-runtime/src/service.ts rename to packages/runtime/src/service.ts diff --git a/packages/bxpb-runtime/src/service_spec.ts b/packages/runtime/src/service_spec.ts similarity index 100% rename from packages/bxpb-runtime/src/service_spec.ts rename to packages/runtime/src/service_spec.ts diff --git a/packages/bxpb-runtime/src/test_data/greeter.proto b/packages/runtime/src/test_data/greeter.proto similarity index 100% rename from packages/bxpb-runtime/src/test_data/greeter.proto rename to packages/runtime/src/test_data/greeter.proto diff --git a/packages/bxpb-runtime/src/testing/fake_event.ts b/packages/runtime/src/testing/fake_event.ts similarity index 100% rename from packages/bxpb-runtime/src/testing/fake_event.ts rename to packages/runtime/src/testing/fake_event.ts diff --git a/packages/bxpb-runtime/src/testing/fake_event_spec.ts b/packages/runtime/src/testing/fake_event_spec.ts similarity index 100% rename from packages/bxpb-runtime/src/testing/fake_event_spec.ts rename to packages/runtime/src/testing/fake_event_spec.ts diff --git a/packages/bxpb-runtime/src/wire_format.d.ts b/packages/runtime/src/wire_format.d.ts similarity index 100% rename from packages/bxpb-runtime/src/wire_format.d.ts rename to packages/runtime/src/wire_format.d.ts diff --git a/packages/bxpb-runtime/tsconfig.json b/packages/runtime/tsconfig.json similarity index 100% rename from packages/bxpb-runtime/tsconfig.json rename to packages/runtime/tsconfig.json diff --git a/packages/bxpb-runtime/tsconfig.lib.json b/packages/runtime/tsconfig.lib.json similarity index 100% rename from packages/bxpb-runtime/tsconfig.lib.json rename to packages/runtime/tsconfig.lib.json diff --git a/packages/bxpb-runtime/tsconfig.spec.json b/packages/runtime/tsconfig.spec.json similarity index 100% rename from packages/bxpb-runtime/tsconfig.spec.json rename to packages/runtime/tsconfig.spec.json