Skip to content

Commit 8d1afc0

Browse files
authored
Revert "[go] Implement startDevServer() function (vercel#4662)" (vercel#4899)
This reverts commit 04bea1e.
1 parent 130f36a commit 8d1afc0

File tree

12 files changed

+58
-316
lines changed

12 files changed

+58
-316
lines changed

.editorconfig

-5
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,6 @@ indent_style = space
1919
[*.py]
2020
indent_size = 4
2121

22-
[*.go]
23-
indent_style = tab
24-
indent_size = 4
25-
tab_width = 4
26-
2722
[*.asm]
2823
indent_size = 8
2924

packages/now-cli/test/dev/fixtures/go/.gitignore

-1
This file was deleted.

packages/now-cli/test/dev/fixtures/go/api/[segment].go

-10
This file was deleted.

packages/now-cli/test/dev/fixtures/go/api/another.go

-10
This file was deleted.

packages/now-cli/test/dev/fixtures/go/api/index.go

-10
This file was deleted.

packages/now-cli/test/dev/integration.js

-46
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ import ms from 'ms';
22
import os from 'os';
33
import fs from 'fs-extra';
44
import test from 'ava';
5-
import { isIP } from 'net';
65
import { join, resolve, delimiter } from 'path';
76
import _execa from 'execa';
87
import fetch from 'node-fetch';
@@ -1601,48 +1600,3 @@ test(
16011600
await testPath(200, '/index.css', 'This is index.css');
16021601
})
16031602
);
1604-
1605-
test(
1606-
'[vercel dev] Should support `*.go` API serverless functions',
1607-
testFixtureStdio('go', async testPath => {
1608-
await testPath(200, `/api`, 'This is the index page');
1609-
await testPath(200, `/api/index`, 'This is the index page');
1610-
await testPath(200, `/api/index.go`, 'This is the index page');
1611-
await testPath(200, `/api/another`, 'This is another page');
1612-
await testPath(200, '/api/another.go', 'This is another page');
1613-
await testPath(200, `/api/foo`, 'Req Path: /api/foo');
1614-
await testPath(200, `/api/bar`, 'Req Path: /api/bar');
1615-
})
1616-
);
1617-
1618-
test(
1619-
'[vercel dev] Should set the `ts-node` "target" to match Node.js version',
1620-
testFixtureStdio('node-ts-node-target', async testPath => {
1621-
await testPath(200, `/api/subclass`, '{"ok":true}');
1622-
await testPath(
1623-
200,
1624-
`/api/array`,
1625-
'{"months":[1,2,3,4,5,6,7,8,9,10,11,12]}'
1626-
);
1627-
1628-
await testPath(200, `/api/dump`, (t, body, res, isDev) => {
1629-
const { host } = new URL(res.url);
1630-
const { env, headers } = JSON.parse(body);
1631-
1632-
// Test that the API endpoint receives the Vercel proxy request headers
1633-
t.is(headers['x-forwarded-host'], host);
1634-
t.is(headers['x-vercel-deployment-url'], host);
1635-
t.truthy(isIP(headers['x-real-ip']));
1636-
t.truthy(isIP(headers['x-forwarded-for']));
1637-
t.truthy(isIP(headers['x-vercel-forwarded-for']));
1638-
1639-
// Test that the API endpoint has the Vercel platform env vars defined.
1640-
t.regex(env.NOW_REGION, /^[a-z]{3}\d$/);
1641-
if (isDev) {
1642-
// Only dev is tested because in production these are opt-in.
1643-
t.is(env.VERCEL_URL, host);
1644-
t.is(env.VERCEL_REGION, 'dev1');
1645-
}
1646-
});
1647-
})
1648-
);

packages/now-go/build.sh

-9
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,4 @@
1-
#!/bin/bash
2-
set -euo pipefail
3-
4-
# Start fresh
5-
rm -rf dist
6-
7-
# Build with `ncc`
81
ncc build index.ts -e @vercel/build-utils -e @now/build-utils -o dist
92
ncc build install.ts -e @vercel/build-utils -e @now/build-utils -o dist/install
10-
11-
# Move `install.js` to dist
123
mv dist/install/index.js dist/install.js
134
rm -rf dist/install

packages/now-go/go-helpers.ts

+46-27
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,14 @@ import execa from 'execa';
33
import fetch from 'node-fetch';
44
import { mkdirp, pathExists } from 'fs-extra';
55
import { dirname, join } from 'path';
6+
import { homedir } from 'os';
67
import buildUtils from './build-utils';
78
import stringArgv from 'string-argv';
89
const { debug } = buildUtils;
9-
const archMap = new Map([['x64', 'amd64'], ['x86', '386']]);
10+
const archMap = new Map([
11+
['x64', 'amd64'],
12+
['x86', '386'],
13+
]);
1014
const platformMap = new Map([['win32', 'windows']]);
1115

1216
// Location where the `go` binary will be installed after `postinstall`
@@ -126,35 +130,50 @@ export async function downloadGo(
126130
platform = process.platform,
127131
arch = process.arch
128132
) {
129-
// Check if `go` is already installed in user's `$PATH`
130-
const { failed, stdout } = await execa('go', ['version'], { reject: false });
133+
// Check default `Go` in user machine
134+
const isUserGo = await pathExists(join(homedir(), 'go'));
131135

132-
if (!failed && parseInt(stdout.split('.')[1]) >= 11) {
133-
debug('Using system installed version of `go`: %o', stdout.trim());
134-
return createGo(dir, platform, arch);
135-
}
136-
137-
// Check `go` bin in builder CWD
138-
const isGoExist = await pathExists(join(dir, 'bin'));
139-
if (!isGoExist) {
140-
debug('Installing `go` v%s to %o for %s %s', version, dir, platform, arch);
141-
const url = getGoUrl(version, platform, arch);
142-
debug('Downloading `go` URL: %o', url);
143-
const res = await fetch(url);
136+
// If we found GOPATH in ENV, or default `Go` path exists
137+
// asssume that user have `Go` installed
138+
if (isUserGo || process.env.GOPATH !== undefined) {
139+
const { stdout } = await execa('go', ['version']);
144140

145-
if (!res.ok) {
146-
throw new Error(`Failed to download: ${url} (${res.status})`);
141+
if (parseInt(stdout.split('.')[1]) >= 11) {
142+
return createGo(dir, platform, arch);
147143
}
148144

149-
// TODO: use a zip extractor when `ext === "zip"`
150-
await mkdirp(dir);
151-
await new Promise((resolve, reject) => {
152-
res.body
153-
.on('error', reject)
154-
.pipe(tar.extract({ cwd: dir, strip: 1 }))
155-
.on('error', reject)
156-
.on('finish', resolve);
157-
});
145+
throw new Error(
146+
`Your current ${stdout} doesn't support Go Modules. Please update.`
147+
);
148+
} else {
149+
// Check `Go` bin in builder CWD
150+
const isGoExist = await pathExists(join(dir, 'bin'));
151+
if (!isGoExist) {
152+
debug(
153+
'Installing `go` v%s to %o for %s %s',
154+
version,
155+
dir,
156+
platform,
157+
arch
158+
);
159+
const url = getGoUrl(version, platform, arch);
160+
debug('Downloading `go` URL: %o', url);
161+
const res = await fetch(url);
162+
163+
if (!res.ok) {
164+
throw new Error(`Failed to download: ${url} (${res.status})`);
165+
}
166+
167+
// TODO: use a zip extractor when `ext === "zip"`
168+
await mkdirp(dir);
169+
await new Promise((resolve, reject) => {
170+
res.body
171+
.on('error', reject)
172+
.pipe(tar.extract({ cwd: dir, strip: 1 }))
173+
.on('error', reject)
174+
.on('finish', resolve);
175+
});
176+
}
177+
return createGo(dir, platform, arch);
158178
}
159-
return createGo(dir, platform, arch);
160179
}

0 commit comments

Comments
 (0)