Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

V2 #29

Open
wants to merge 9 commits into
base: main
Choose a base branch
from
Open

V2 #29

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,4 @@ DerivedData/
.swiftpm/config/registries.json
.swiftpm/xcode/package.xcworkspace/contents.xcworkspacedata
.netrc
.vscode/
1 change: 1 addition & 0 deletions .swift-format
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
"indentation" : {
"spaces": 4
},
"lineLength": 120,
"tabWidth": 4,
"version": 1
}
69 changes: 35 additions & 34 deletions Package.resolved
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
{
"originHash" : "84f7d17fd7066cb70f9a164cb7eb38ed34d7c9c01d51ee9136540e1b8e32ba71",
"pins" : [
{
"identity" : "async-http-client",
"kind" : "remoteSourceControl",
"location" : "https://github.com/swift-server/async-http-client.git",
"state" : {
"revision" : "291438696abdd48d2a83b52465c176efbd94512b",
"version" : "1.20.1"
"revision" : "0ae99db85b2b9d1e79b362bd31fd1ffe492f7c47",
"version" : "1.21.2"
}
},
{
Expand All @@ -23,26 +24,26 @@
"kind" : "remoteSourceControl",
"location" : "https://github.com/vapor/console-kit.git",
"state" : {
"revision" : "a31f44ebfbd15a2cc0fda705279676773ac16355",
"version" : "4.14.1"
"revision" : "9f7932f22ab6f64aafadc14491e694179b7d0f6f",
"version" : "4.14.3"
}
},
{
"identity" : "multipart-kit",
"kind" : "remoteSourceControl",
"location" : "https://github.com/vapor/multipart-kit.git",
"state" : {
"revision" : "12ee56f25bd3fc4c2d09c2aa16e69de61dc786e8",
"version" : "4.6.0"
"revision" : "a31236f24bfd2ea2f520a74575881f6731d7ae68",
"version" : "4.7.0"
}
},
{
"identity" : "routing-kit",
"kind" : "remoteSourceControl",
"location" : "https://github.com/vapor/routing-kit.git",
"state" : {
"revision" : "2a92a7eac411a82fb3a03731be5e76773ebe1b3e",
"version" : "4.9.0"
"revision" : "8c9a227476555c55837e569be71944e02a056b72",
"version" : "4.9.1"
}
},
{
Expand Down Expand Up @@ -77,89 +78,89 @@
"kind" : "remoteSourceControl",
"location" : "https://github.com/apple/swift-collections.git",
"state" : {
"revision" : "94cf62b3ba8d4bed62680a282d4c25f9c63c2efb",
"version" : "1.1.0"
"revision" : "ee97538f5b81ae89698fd95938896dec5217b148",
"version" : "1.1.1"
}
},
{
"identity" : "swift-crypto",
"kind" : "remoteSourceControl",
"location" : "https://github.com/apple/swift-crypto",
"location" : "https://github.com/apple/swift-crypto.git",
"state" : {
"revision" : "f0525da24dc3c6cbb2b6b338b65042bc91cbc4bb",
"version" : "3.3.0"
"revision" : "46072478ca365fe48370993833cb22de9b41567f",
"version" : "3.5.2"
}
},
{
"identity" : "swift-http-types",
"kind" : "remoteSourceControl",
"location" : "https://github.com/apple/swift-http-types",
"state" : {
"revision" : "12358d55a3824bd5fed310b999ea8cf83a9a1a65",
"version" : "1.0.3"
"revision" : "1ddbea1ee34354a6a2532c60f98501c35ae8edfa",
"version" : "1.2.0"
}
},
{
"identity" : "swift-log",
"kind" : "remoteSourceControl",
"location" : "https://github.com/apple/swift-log.git",
"state" : {
"revision" : "e97a6fcb1ab07462881ac165fdbb37f067e205d5",
"version" : "1.5.4"
"revision" : "9cb486020ebf03bfa5b5df985387a14a98744537",
"version" : "1.6.1"
}
},
{
"identity" : "swift-metrics",
"kind" : "remoteSourceControl",
"location" : "https://github.com/apple/swift-metrics.git",
"state" : {
"revision" : "971ba26378ab69c43737ee7ba967a896cb74c0d1",
"version" : "2.4.1"
"revision" : "e0165b53d49b413dd987526b641e05e246782685",
"version" : "2.5.0"
}
},
{
"identity" : "swift-nio",
"kind" : "remoteSourceControl",
"location" : "https://github.com/apple/swift-nio.git",
"state" : {
"revision" : "fc63f0cf4e55a4597407a9fc95b16a2bc44b4982",
"version" : "2.64.0"
"revision" : "fc79798d5a150d61361a27ce0c51169b889e23de",
"version" : "2.68.0"
}
},
{
"identity" : "swift-nio-extras",
"kind" : "remoteSourceControl",
"location" : "https://github.com/apple/swift-nio-extras.git",
"state" : {
"revision" : "a3b640d7dc567225db7c94386a6e71aded1bfa63",
"version" : "1.22.0"
"revision" : "05c36b57453d23ea63785d58a7dbc7b70ba1745e",
"version" : "1.23.0"
}
},
{
"identity" : "swift-nio-http2",
"kind" : "remoteSourceControl",
"location" : "https://github.com/apple/swift-nio-http2.git",
"state" : {
"revision" : "0904bf0feb5122b7e5c3f15db7df0eabe623dd87",
"version" : "1.30.0"
"revision" : "a0224f3d20438635dd59c9fcc593520d80d131d0",
"version" : "1.33.0"
}
},
{
"identity" : "swift-nio-ssl",
"kind" : "remoteSourceControl",
"location" : "https://github.com/apple/swift-nio-ssl.git",
"state" : {
"revision" : "7c381eb6083542b124a6c18fae742f55001dc2b5",
"version" : "2.26.0"
"revision" : "2b09805797f21c380f7dc9bedaab3157c5508efb",
"version" : "2.27.0"
}
},
{
"identity" : "swift-nio-transport-services",
"kind" : "remoteSourceControl",
"location" : "https://github.com/apple/swift-nio-transport-services.git",
"state" : {
"revision" : "6cbe0ed2b394f21ab0d46b9f0c50c6be964968ce",
"version" : "1.20.1"
"revision" : "38ac8221dd20674682148d6451367f89c2652980",
"version" : "1.21.0"
}
},
{
Expand All @@ -176,17 +177,17 @@
"kind" : "remoteSourceControl",
"location" : "https://github.com/apple/swift-system.git",
"state" : {
"revision" : "025bcb1165deab2e20d4eaba79967ce73013f496",
"version" : "1.2.1"
"revision" : "6a9e38e7bd22a3b8ba80bddf395623cf68f57807",
"version" : "1.3.1"
}
},
{
"identity" : "vapor",
"kind" : "remoteSourceControl",
"location" : "https://github.com/vapor/vapor",
"state" : {
"revision" : "11cdb29614a5c7f8c5289f3c97b3398c3d89b395",
"version" : "4.92.5"
"revision" : "ebbe71c89aa1b76a0920277760b12be7a2ec7c70",
"version" : "4.102.0"
}
},
{
Expand All @@ -199,5 +200,5 @@
}
}
],
"version" : 2
"version" : 3
}
14 changes: 6 additions & 8 deletions Package.swift
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
// swift-tools-version: 5.9
// swift-tools-version: 5.10

import PackageDescription

let package = Package(
name: "Vercel",
name: "swift-vercel",
platforms: [
.macOS(.v12)
],
Expand All @@ -13,19 +13,17 @@ let package = Package(
.plugin(name: "VercelPackager", targets: ["VercelPackager"]),
],
dependencies: [
.package(url: "https://github.com/apple/swift-crypto", from: "3.0.0"),
.package(
url: "https://github.com/swift-server/swift-aws-lambda-runtime", from: "1.0.0-alpha.2"),
.package(url: "https://github.com/swift-server/async-http-client", from: "1.20.1"),
.package(url: "https://github.com/swift-server/swift-aws-lambda-runtime", from: "1.0.0-alpha.2"),
.package(url: "https://github.com/apple/swift-http-types.git", from: "1.0.0"),
.package(url: "https://github.com/vapor/vapor", from: "4.0.0"),
],
targets: [
.target(
name: "Vercel",
dependencies: [
.product(name: "AWSLambdaRuntime", package: "swift-aws-lambda-runtime"),
.product(name: "AsyncHTTPClient", package: "async-http-client"),
.product(name: "Crypto", package: "swift-crypto"),
.product(name: "HTTPTypes", package: "swift-http-types"),
.product(name: "HTTPTypesFoundation", package: "swift-http-types"),
],
swiftSettings: [
.enableExperimentalFeature("StrictConcurrency")
Expand Down
35 changes: 24 additions & 11 deletions Plugins/VercelPackager/VercelOutput.swift
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//
// VercelOutput.swift
//
//
//
// Created by Andrew Barba on 1/21/23.
//
Expand All @@ -26,7 +26,8 @@ public struct VercelOutput {
return encoder
}

public init(packageManager: PackagePlugin.PackageManager, context: PackagePlugin.PluginContext, arguments: [String]) {
public init(packageManager: PackagePlugin.PackageManager, context: PackagePlugin.PluginContext, arguments: [String])
{
self.packageManager = packageManager
self.context = context
self.arguments = arguments
Expand Down Expand Up @@ -55,7 +56,7 @@ public struct VercelOutput {

var deployArguments = [
"deploy",
"--prebuilt"
"--prebuilt",
]

if arguments.contains("--prod") {
Expand Down Expand Up @@ -148,6 +149,10 @@ extension VercelOutput {
arguments.contains("--prod")
}

public var nightly: Bool {
arguments.contains("--nightly")
}

public var functionMemory: String {
argument("memory") ?? "512"
}
Expand Down Expand Up @@ -190,7 +195,8 @@ extension VercelOutput {
}

// Split file into lines
let lines = text
let lines =
text
.split(separator: "\n")
.map { $0.trimmingCharacters(in: .whitespacesAndNewlines) }

Expand All @@ -199,7 +205,8 @@ extension VercelOutput {
guard !line.starts(with: "#") else { return }

// Split the line into key value parts
let keyValue = line
let keyValue =
line
.split(separator: "=", maxSplits: 1)
.map { $0.trimmingCharacters(in: .whitespacesAndNewlines) }

Expand Down Expand Up @@ -383,7 +390,7 @@ extension VercelOutput {
// Handle filesystem
.init(handle: "filesystem"),
// Proxy all other routes
.init(src: "^.*$", dest: product.name, check: true)
.init(src: "^.*$", dest: product.name, check: true),
]
let config = OutputConfiguration(
routes: routes,
Expand Down Expand Up @@ -442,7 +449,9 @@ extension VercelOutput {
architecture: architecture,
memory: .init(functionMemory),
maxDuration: .init(functionDuration),
regions: functionRegions?.components(separatedBy: ",").map { $0.trimmingCharacters(in: .whitespacesAndNewlines) }
regions: functionRegions?.components(separatedBy: ",").map {
$0.trimmingCharacters(in: .whitespacesAndNewlines)
}
)
let data = try encoder.encode(config)
fs.createFile(atPath: vercelFunctionConfigurationPath(product).string, contents: data)
Expand Down Expand Up @@ -491,8 +500,10 @@ extension VercelOutput {
try Shell.execute(
executable: context.tool(named: "node").path,
arguments: [
projectDirectory.appending([".build", "checkouts", "Vercel", "Plugins", "VercelPackager", "Server", "server.cjs"]).string,
port
projectDirectory.appending([
".build", "checkouts", "Vercel", "Plugins", "VercelPackager", "Server", "server.cjs",
]).string,
port,
],
environment: ["SWIFT_PROJECT_DIRECTORY": projectDirectory.string],
printCommand: false
Expand Down Expand Up @@ -551,7 +562,9 @@ extension VercelOutput {

private func buildDockerProduct(_ product: Product) async throws -> Path {
let dockerToolPath = try context.tool(named: "docker").path
let baseImage = "swift:\(context.package.toolsVersion.major).\(context.package.toolsVersion.minor)-amazonlinux2"
let baseImage = nightly
? "swiftlang/swift:nightly-\(context.package.toolsVersion.major).\(context.package.toolsVersion.minor)-amazonlinux2"
: "swift:\(context.package.toolsVersion.major).\(context.package.toolsVersion.minor)-amazonlinux2"

// build the product
try Shell.execute(
Expand All @@ -563,7 +576,7 @@ extension VercelOutput {
"-v", "\(context.package.directory.string):/workspace",
"-w", "/workspace",
baseImage,
"bash", "-cl", "swift build -c release --static-swift-stdlib"
"bash", "-cl", "swift build -c release -Xswiftc -Osize --static-swift-stdlib",
]
)

Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ import Vercel
@main
struct App: RequestHandler {

func onRequest(_ req: Request) async throws -> Response {
func onRequest(_ req: IncomingRequest) async throws -> OutgoingResponse {
let greeting = EdgeConfig.default.get("greeting").string!
return .status(.ok).send("Hello, \(greeting)")
}
Expand Down
Loading