Skip to content

Commit

Permalink
fix: removed unsupported portfinder (#10269)
Browse files Browse the repository at this point in the history
portfinder is removed and replaced with supported get-port
  • Loading branch information
ammarkarachi authored Apr 22, 2022
1 parent eff77da commit 33d8a8f
Show file tree
Hide file tree
Showing 9 changed files with 23 additions and 35 deletions.
2 changes: 1 addition & 1 deletion packages/amplify-appsync-simulator/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
"cors": "^2.8.5",
"dataloader": "^2.0.0",
"express": "^4.17.3",
"get-port": "^5.1.1",
"graphql": "^14.5.8",
"graphql-iso-date": "^3.6.1",
"graphql-subscriptions": "^1.1.0",
Expand All @@ -48,7 +49,6 @@
"mqtt-connection": "4.0.0",
"nanoid": "^3.3.1",
"pino": "^6.13.0",
"portfinder": "^1.0.25",
"promise-toolbox": "^0.20.0",
"qlobber": "3.1.0",
"retimer": "2.0.0",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { createServer, Server } from 'http';
import { URL, URLSearchParams } from 'url';
import WS from 'ws';
import portFinder from 'portfinder';
import getPort from 'get-port';
import { PubSub } from 'graphql-subscriptions';
import { parse } from 'graphql';

Expand Down Expand Up @@ -70,9 +70,8 @@ describe('WebsocketSubscriptionServer', () => {
{ server: httpServer, path: SUBSCRIPTION_PATH },
);

serverPort = await portFinder.getPortPromise({
startPort: 20001,
stopPort: 66666,
serverPort = await getPort({
port: getPort.makeRange(20001, 65536),
});
httpServer.listen(serverPort);
server.start();
Expand Down
18 changes: 7 additions & 11 deletions packages/amplify-appsync-simulator/src/server/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ import { SubscriptionServer } from './subscription';
import { AmplifyAppSyncSimulator } from '..';
import { AppSyncSimulatorServerConfig } from '../type-definition';
import { Server, createServer } from 'http';
import portFinder from 'portfinder';
import { fromEvent } from 'promise-toolbox';
import { address as getLocalIpAddress } from 'ip';
import { AppSyncSimulatorSubscriptionServer } from './websocket-subscription';
import getPort from 'get-port';

const BASE_PORT = 8900;
const MAX_PORT = 9999;
Expand All @@ -32,18 +32,14 @@ export class AppSyncSimulatorServer {
await this._realTimeSubscriptionServer.start();

if (!port) {
port = await portFinder.getPortPromise({
startPort: BASE_PORT,
stopPort: MAX_PORT,
port: BASE_PORT,
});
port = await getPort({
port: getPort.makeRange(BASE_PORT, MAX_PORT),
})
} else {
try {
await portFinder.getPortPromise({
startPort: port,
stopPort: port,
port: port,
});
await getPort({
port,
})
} catch (e) {
throw new Error(`Port ${port} is already in use. Please kill the program using this port and restart Mock`);
}
Expand Down
15 changes: 6 additions & 9 deletions packages/amplify-appsync-simulator/src/server/subscription.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@ import { DocumentNode, ExecutableDefinitionNode, ExecutionResult, FieldNode } fr
import { createServer as createHTTPServer, Server } from 'http';
import { address as getLocalIpAddress } from 'ip';
import { AddressInfo } from 'net';
import portfinder from 'portfinder';
import { inspect } from 'util';
import { AmplifyAppSyncSimulator } from '..';
import { AppSyncSimulatorServerConfig } from '../type-definition';
import { MQTTServer } from './subscription/mqtt-server';
import { WebsocketSubscriptionServer } from './subscription/websocket-server/server';
import getPort from 'get-port';

const MINUTE = 1000 * 60;
const CONNECTION_TIMEOUT = 2 * MINUTE; // 2 mins
Expand Down Expand Up @@ -64,17 +64,14 @@ export class SubscriptionServer {

async start() {
if (!this.port) {
this.port = await portfinder.getPortPromise({
startPort: BASE_PORT,
stopPort: MAX_PORT,
});
this.port = await getPort({
port: getPort.makeRange(BASE_PORT, MAX_PORT),
})
} else {
try {
await portfinder.getPortPromise({
startPort: this.port,
stopPort: this.port,
await getPort({
port: this.port,
});
})
} catch (e) {
throw new Error(`Port ${this.port} is already in use. Please kill the program using this port and restart Mock`);
}
Expand Down
2 changes: 1 addition & 1 deletion packages/amplify-dynamodb-simulator/__test__/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ describe('emulator operations', () => {
});

it('should start on specific port', async () => {
const port = await require('portfinder').getPortPromise();
const port = await require('get-port')();
const emu = await ddbSimulator.launch({ port });
emulators.push(emu);
expect(emu.port).toBe(port);
Expand Down
2 changes: 1 addition & 1 deletion packages/amplify-dynamodb-simulator/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
},
"devDependencies": {
"download-cli": "^1.1.1",
"portfinder": "^1.0.25"
"get-port": "^5.1.1"
},
"jest": {
"testEnvironment": "node",
Expand Down
2 changes: 1 addition & 1 deletion packages/amplify-go-function-runtime-provider/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
"execa": "^5.1.1",
"fs-extra": "^8.1.0",
"glob": "^7.2.0",
"portfinder": "^1.0.25",
"get-port": "^5.1.1",
"semver": "^7.3.5",
"which": "^2.0.2"
},
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import path from 'path';
import fs from 'fs-extra';
import portfinder from 'portfinder';
import { $TSContext, pathManager } from 'amplify-cli-core';

import getPort from 'get-port';
import { InvocationRequest } from 'amplify-function-plugin-interface';
import { executeCommand } from './runtime';
import { MAIN_SOURCE, MAX_PORT, BASE_PORT, BIN_LOCAL, MAIN_BINARY, MAIN_BINARY_WIN, packageName, relativeShimSrcPath } from './constants';
Expand Down Expand Up @@ -68,10 +67,7 @@ export const localInvoke = async (request: InvocationRequest, context: $TSContex
const localInvoker = await buildLocalInvoker(context);

// Find a free tcp port for the Lambda to launch on
const portNumber = await portfinder.getPortPromise({
startPort: BASE_PORT,
stopPort: MAX_PORT,
});
const portNumber = await getPort({port: getPort.makeRange(BASE_PORT, MAX_PORT)});

const lambdaExecutableDir = path.join(request.srcRoot, BIN_LOCAL);
const lambdaExecutablePath = path.join(lambdaExecutableDir, MAIN_BINARY);
Expand Down
2 changes: 1 addition & 1 deletion yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -19906,7 +19906,7 @@ pluralize@8.0.0, pluralize@^8.0.0:
resolved "https://registry.npmjs.org/pluralize/-/pluralize-8.0.0.tgz#1a6fa16a38d12a1901e0320fa017051c539ce3b1"
integrity sha512-Nc3IT5yHzflTfbjgqWcCPpo7DaKy4FnpB0l/zCAW0Tc7jxAiuqSxHasntB3D7887LSrA93kDJ9IXovxJYxyLCA==

portfinder@^1.0.25, portfinder@^1.0.28:
portfinder@^1.0.28:
version "1.0.28"
resolved "https://registry.npmjs.org/portfinder/-/portfinder-1.0.28.tgz#67c4622852bd5374dd1dd900f779f53462fac778"
integrity sha512-Se+2isanIcEqf2XMHjyUKskczxbPH7dQnlMjXX6+dybayyHvAf/TCgyMRlzf/B6QDhAEFOGes0pzRo3by4AbMA==
Expand Down

0 comments on commit 33d8a8f

Please sign in to comment.