Compare commits

..

4 Commits

Author SHA1 Message Date
Nathan Rajlich
41ce1a4291 Publish Canary
- vercel@20.1.2-canary.1
 - @vercel/node@1.8.4-canary.0
2020-09-25 10:00:24 -07:00
Nathan Rajlich
449f35cf33 [node] Only use the project's local "typescript" when it has compatible ScriptTarget (#5220)
https://app.clubhouse.io/vercel/story/8304
2020-09-24 15:18:09 -07:00
Nathan Rajlich
d683402bba Publish Canary
- vercel@20.1.2-canary.0
2020-09-23 13:23:44 -07:00
Nathan Rajlich
2051a1cd9b [cli] Ensure the devProcessPort is set during "upgrade" events (#5226)
Related to: https://twitter.com/raymondcamden/status/1308838251902521348
2020-09-23 20:16:51 +00:00
4 changed files with 50 additions and 22 deletions

View File

@@ -1,6 +1,6 @@
{
"name": "vercel",
"version": "20.1.1",
"version": "20.1.2-canary.1",
"preferGlobal": true,
"license": "Apache-2.0",
"description": "The command-line interface for Vercel",
@@ -63,7 +63,7 @@
"dependencies": {
"@vercel/build-utils": "2.5.3",
"@vercel/go": "1.1.6",
"@vercel/node": "1.8.3",
"@vercel/node": "1.8.4-canary.0",
"@vercel/python": "1.2.3",
"@vercel/ruby": "1.2.4",
"update-notifier": "4.1.0"

View File

@@ -923,9 +923,17 @@ export default class DevServer {
await once(this.watcher, 'ready');
// Configure the server to forward WebSocket "upgrade" events to the proxy.
this.server.on('upgrade', (req, socket, head) => {
this.server.on('upgrade', async (req, socket, head) => {
await this.startPromise;
if (!this.devProcessPort) {
this.output.debug(
`Detected "upgrade" event, but closing socket because no frontend dev server is running`
);
socket.destroy();
return;
}
const target = `http://localhost:${this.devProcessPort}`;
this.output.debug(`Detected upgrade event, proxying to ${target}`);
this.output.debug(`Detected "upgrade" event, proxying to ${target}`);
this.proxy.ws(req, socket, head, { target });
});

View File

@@ -1,6 +1,6 @@
{
"name": "@vercel/node",
"version": "1.8.3",
"version": "1.8.4-canary.0",
"license": "MIT",
"main": "./dist/index",
"homepage": "https://vercel.com/docs/runtimes#official-runtimes/node-js",

View File

@@ -8,33 +8,54 @@ if (!entrypoint) {
throw new Error('`VERCEL_DEV_ENTRYPOINT` must be defined');
}
import { join } from 'path';
import { register } from 'ts-node';
// Use the project's version of TypeScript if available,
// otherwise fall back to using the copy that `@vercel/node` uses.
let compiler: string;
try {
compiler = require.resolve('typescript', {
paths: [process.cwd()],
});
} catch (e) {
compiler = 'typescript';
}
type TypescriptModule = typeof import('typescript');
// Assume Node 10
let target = 'es2018';
const resolveTypescript = (p: string): string => {
try {
return require.resolve('typescript', {
paths: [p],
});
} catch (_) {
return '';
}
};
const requireTypescript = (p: string): TypescriptModule => {
// eslint-disable-next-line @typescript-eslint/no-var-requires
return require(p) as TypescriptModule;
};
let ts: TypescriptModule | null = null;
// Assume Node 10 as the lowest common denominator
let target = 'ES2018';
const nodeMajor = Number(process.versions.node.split('.')[0]);
if (nodeMajor >= 14) {
target = 'es2020';
target = 'ES2020';
} else if (nodeMajor >= 12) {
target = 'es2019';
target = 'ES2019';
}
// Use the project's version of Typescript if available and supports `target`
let compiler = resolveTypescript(process.cwd());
if (compiler) {
ts = requireTypescript(compiler);
if (!(target in ts.ScriptTarget)) {
ts = null;
}
}
// Otherwise fall back to using the copy that `@vercel/node` uses
if (!ts) {
compiler = resolveTypescript(join(__dirname, '..'));
ts = requireTypescript(compiler);
}
if (tsconfig) {
try {
// eslint-disable-next-line @typescript-eslint/no-var-requires
const ts: typeof import('typescript') = require(compiler);
const { config } = ts.readConfigFile(tsconfig, ts.sys.readFile);
if (config?.compilerOptions?.target) {
target = config.compilerOptions.target;
@@ -61,7 +82,6 @@ register({
});
import { createServer, Server, IncomingMessage, ServerResponse } from 'http';
import { join } from 'path';
import { Readable } from 'stream';
import { Bridge } from './bridge';
import { getNowLauncher } from './launcher';