From ea4008ea9236784a70c5a483fadf10496a2afc75 Mon Sep 17 00:00:00 2001 From: Jackie Macharia Date: Thu, 12 Jan 2023 14:05:21 +0300 Subject: [PATCH] feat: Make additional function attributes available via functions manifest (#1221) * feat: pass additional-function-attributes * chore: make attributes available to functions manifest * fix: fix linting * fix: use optional chaining * fix: add ext * fix: fix tests * fix: change internal directory name in constants.ts * feat: add test for go functions with displayName and from an internal functions folder * feat: add test for rust functions build from internal folder with displayName property * feat: add test for nodejs functions build from internal folder with displayName property * test: figure out windows breakn * fix: take windows paths into account when checking for internal functions * test: add unit test for checkIsInternalFunction * docs: add new return values * test: move tests into a better fixtures structure * fix: use unixify for checkIsInternalFunction, config, bundler, module and resolve * feat: add internalFunctionsFolder option to zipfunctionoptions * test: fix tests * test: add test for zipFunction and code to support that as well * test: change toBeTruthy to toBe(true) and isInternalFunction to internalFunction * chore: change displayName input to name * chore: change internalFunction to isInternal * chore: revert unixify, rename tests and internalFunctionsFolder to internalSrcFolder * test: revert unixify for module to see if windows test still fails * Revert "test: revert unixify for module to see if windows test still fails" This reverts commit b444d1c4828965d72d909d96fa68e531a888d221. Co-authored-by: khen <30577427+khendrikse@users.noreply.github.com> --- README.md | 25 +- src/config.ts | 1 + src/manifest.ts | 17 +- src/runtimes/go/index.ts | 18 +- src/runtimes/node/index.ts | 3 + src/runtimes/runtime.ts | 3 + src/runtimes/rust/index.ts | 8 +- src/zip.ts | 10 + .../internal-functions/go-func-1/main.go | 9 + .../internal-functions/go-func-2/go-func-2.go | 9 + .../internal-functions/go-func-2/go.mod | 3 + .../internal-functions/go-func-2/go.sum | 0 .../fixtures/node-display-name/function-1.js | 1 + .../.netlify/internal-functions/function-1.js | 1 + .../.netlify/internal-functions/function-2.js | 1 + .../internal-functions/rust-func-1/.gitignore | 1 + .../internal-functions/rust-func-1/Cargo.lock | 707 ++++++++++++++++++ .../internal-functions/rust-func-1/Cargo.toml | 14 + .../rust-func-1/src/main.rs | 29 + .../internal-functions/rust-func-2/.gitignore | 1 + .../internal-functions/rust-func-2/Cargo.lock | 707 ++++++++++++++++++ .../internal-functions/rust-func-2/Cargo.toml | 14 + .../rust-func-2/src/main.rs | 29 + tests/main.test.ts | 88 +++ tests/zip_function.test.ts | 30 + 25 files changed, 1722 insertions(+), 7 deletions(-) create mode 100644 tests/fixtures/go-internal/.netlify/internal-functions/go-func-1/main.go create mode 100644 tests/fixtures/go-internal/.netlify/internal-functions/go-func-2/go-func-2.go create mode 100644 tests/fixtures/go-internal/.netlify/internal-functions/go-func-2/go.mod create mode 100644 tests/fixtures/go-internal/.netlify/internal-functions/go-func-2/go.sum create mode 100644 tests/fixtures/node-display-name/function-1.js create mode 100644 tests/fixtures/node-internal/.netlify/internal-functions/function-1.js create mode 100644 tests/fixtures/node-internal/.netlify/internal-functions/function-2.js create mode 100644 tests/fixtures/rust-internal/.netlify/internal-functions/rust-func-1/.gitignore create mode 100644 tests/fixtures/rust-internal/.netlify/internal-functions/rust-func-1/Cargo.lock create mode 100644 tests/fixtures/rust-internal/.netlify/internal-functions/rust-func-1/Cargo.toml create mode 100644 tests/fixtures/rust-internal/.netlify/internal-functions/rust-func-1/src/main.rs create mode 100644 tests/fixtures/rust-internal/.netlify/internal-functions/rust-func-2/.gitignore create mode 100644 tests/fixtures/rust-internal/.netlify/internal-functions/rust-func-2/Cargo.lock create mode 100644 tests/fixtures/rust-internal/.netlify/internal-functions/rust-func-2/Cargo.toml create mode 100644 tests/fixtures/rust-internal/.netlify/internal-functions/rust-func-2/src/main.rs diff --git a/README.md b/README.md index 647897881..252ffb785 100644 --- a/README.md +++ b/README.md @@ -150,6 +150,10 @@ The following properties are accepted: The `[name]` placeholder will be replaced by the name of the function, allowing you to use it to construct the path to the target directory. +- `name` + + A name to use when displaying the function in the Netlify UI. Populates the `displayName` property in the functions manifest for the specified function. + #### `featureFlags` See [feature flags](#feature-flags). @@ -159,7 +163,7 @@ See [feature flags](#feature-flags). - _Type_: `string` - _Default value_: `undefined` -Defines the path for a manifest file to be created with the results of the functions bundling. This file is a +Defines the full path, including the file name, to use for the manifest file that will be created with the functions bundling results. For example, `path/to/manifest.json`. This file is a JSON-formatted string with the following properties: - `functions`: An array with the functions created, in the same format as returned by `zipFunctions` @@ -172,11 +176,18 @@ JSON-formatted string with the following properties: #### `parallelLimit` -- _Type_: `number`\ +- _Type_: `number` - _Default value_: `5` Maximum number of functions to bundle at the same time. +#### `internalSrcFolder` + +- _Type_: `string` +- _Default value_: `undefined` + +Defines the path to the folder with internal functions. Used to populate a function's `isInternal` property, if its path is within this specified internal functions folder. + ### Return value This returns a `Promise` resolving to an array of objects describing each archive. Every object has the following @@ -202,6 +213,14 @@ properties. The size of the generated archive, in bytes. +- `isInternal` `boolean` + + If the function path has a match with the `internalSrcFolder` property, this boolean will be true. + +- `displayName` `string` + + If there was a user-defined configuration object applied to the function, and it had a `name` defined. This will be returned here. + Additionally, the following properties also exist for Node.js functions: - `bundler`: `string` @@ -257,7 +276,7 @@ Additionally, the following properties also exist for Node.js functions: ```js import { zipFunction } from '@netlify/zip-it-and-ship-it' -const archive = await zipFunctions('functions/function.js', 'functions-dist') +const archive = await zipFunction('functions/function.js', 'functions-dist') ``` This is like [`zipFunctions()`](#zipfunctionssrcfolder-destfolder-options) except it bundles a single Function. diff --git a/src/config.ts b/src/config.ts index 22ba1b27e..082b9a978 100644 --- a/src/config.ts +++ b/src/config.ts @@ -24,6 +24,7 @@ interface FunctionConfig { rustTargetDirectory?: string schedule?: string zipGo?: boolean + name?: string // Temporary configuration property, only meant to be used by the deploy // configuration API. Once we start emitting ESM files for all ESM functions, diff --git a/src/manifest.ts b/src/manifest.ts index 65d8a1ff2..aa7b2ff2d 100644 --- a/src/manifest.ts +++ b/src/manifest.ts @@ -10,6 +10,9 @@ interface ManifestFunction { path: string runtime: string schedule?: string + displayName?: string + bundler?: string + isInternal?: boolean } export interface Manifest { @@ -36,10 +39,22 @@ export const createManifest = async ({ functions, path }: { functions: FunctionR await fs.writeFile(path, JSON.stringify(payload)) } -const formatFunctionForManifest = ({ mainFile, name, path, runtime, schedule }: FunctionResult): ManifestFunction => ({ +const formatFunctionForManifest = ({ + mainFile, + name, + path, + runtime, + schedule, + displayName, + bundler, + isInternal, +}: FunctionResult): ManifestFunction => ({ mainFile, name, path: resolve(path), runtime, schedule, + displayName, + bundler, + isInternal, }) diff --git a/src/runtimes/go/index.ts b/src/runtimes/go/index.ts index bcf60d9d8..4c2e86094 100644 --- a/src/runtimes/go/index.ts +++ b/src/runtimes/go/index.ts @@ -109,7 +109,16 @@ const processSource = async ({ } } -const zipFunction: ZipFunction = async function ({ config, destFolder, filename, mainFile, srcDir, srcPath, stat }) { +const zipFunction: ZipFunction = async function ({ + config, + destFolder, + filename, + mainFile, + srcDir, + srcPath, + stat, + isInternal, +}) { const destPath = join(destFolder, filename) const isSource = extname(mainFile) === '.go' @@ -151,7 +160,12 @@ const zipFunction: ZipFunction = async function ({ config, destFolder, filename, await copyFile(binary.path, destPath) } - return { config, path: destPath } + return { + config, + path: destPath, + displayName: config?.name, + isInternal, + } } const runtime: Runtime = { findFunctionsInPaths, findFunctionInPath, name: RuntimeType.GO, zipFunction } diff --git a/src/runtimes/node/index.ts b/src/runtimes/node/index.ts index c3feb3a34..3cfd93f28 100644 --- a/src/runtimes/node/index.ts +++ b/src/runtimes/node/index.ts @@ -45,6 +45,7 @@ const zipFunction: ZipFunction = async function ({ srcDir, srcPath, stat, + isInternal, }) { const pluginsModulesPath = await getPluginsModulesPath(srcDir) const bundlerName = await getBundlerName({ @@ -126,6 +127,8 @@ const zipFunction: ZipFunction = async function ({ nativeNodeModules, nodeModulesWithDynamicImports, path: zipPath, + displayName: config?.name, + isInternal, } } diff --git a/src/runtimes/runtime.ts b/src/runtimes/runtime.ts index 63ff6cdc7..f77709b49 100644 --- a/src/runtimes/runtime.ts +++ b/src/runtimes/runtime.ts @@ -45,6 +45,8 @@ export interface ZipFunctionResult { nativeNodeModules?: object nodeModulesWithDynamicImports?: string[] path: string + isInternal?: boolean + displayName?: string } export type ZipFunction = ( @@ -56,6 +58,7 @@ export type ZipFunction = ( destFolder: string featureFlags: FeatureFlags repositoryRoot?: string + isInternal?: boolean } & FunctionSource, ) => Promise diff --git a/src/runtimes/rust/index.ts b/src/runtimes/rust/index.ts index 51bfb5cf7..eb8d4786b 100644 --- a/src/runtimes/rust/index.ts +++ b/src/runtimes/rust/index.ts @@ -137,6 +137,7 @@ const zipFunction: ZipFunction = async function ({ srcDir, srcPath, stat, + isInternal, }) { const destPath = join(destFolder, `${filename}.zip`) const isSource = extname(mainFile) === '.rs' @@ -157,7 +158,12 @@ const zipFunction: ZipFunction = async function ({ await zipBinary({ ...zipOptions, srcPath, stat }) } - return { config, path: destPath } + return { + config, + path: destPath, + displayName: config?.name, + isInternal, + } } const runtime: Runtime = { findFunctionsInPaths, findFunctionInPath, name: RuntimeType.RUST, zipFunction } diff --git a/src/zip.ts b/src/zip.ts index 53a31815e..9a1cb7797 100644 --- a/src/zip.ts +++ b/src/zip.ts @@ -1,6 +1,7 @@ import { promises as fs } from 'fs' import { resolve } from 'path' +import isPathInside from 'is-path-inside' import pMap from 'p-map' import { ArchiveFormat } from './archive.js' @@ -27,12 +28,14 @@ interface ZipFunctionOptions { zipGo?: boolean systemLog?: LogFunction debug?: boolean + internalSrcFolder?: string } export type ZipFunctionsOptions = ZipFunctionOptions & { configFileDirectories?: string[] manifest?: string parallelLimit?: number + internalSrcFolder?: string } const DEFAULT_PARALLEL_LIMIT = 5 @@ -60,6 +63,7 @@ export const zipFunctions = async function ( repositoryRoot = basePath, systemLog, debug, + internalSrcFolder, }: ZipFunctionsOptions = {}, ) { validateArchiveFormat(archiveFormat) @@ -68,6 +72,8 @@ export const zipFunctions = async function ( const cache = new RuntimeCache() const featureFlags = getFlags(inputFeatureFlags) const srcFolders = resolveFunctionsDirectories(relativeSrcFolders) + const internalFunctionsPath = internalSrcFolder && resolve(internalSrcFolder) + const [paths] = await Promise.all([listFunctionsDirectories(srcFolders), fs.mkdir(destFolder, { recursive: true })]) const functions = await getFunctionsFromPaths(paths, { cache, @@ -104,6 +110,7 @@ export const zipFunctions = async function ( srcDir: func.srcDir, srcPath: func.srcPath, stat: func.stat, + isInternal: Boolean(internalFunctionsPath && isPathInside(func.srcPath, internalFunctionsPath)), }) const durationNs = endTimer(startIntervalTime) const logObject = { @@ -148,6 +155,7 @@ export const zipFunction = async function ( repositoryRoot = basePath, systemLog, debug, + internalSrcFolder, }: ZipFunctionOptions = {}, ) { validateArchiveFormat(archiveFormat) @@ -157,6 +165,7 @@ export const zipFunction = async function ( const srcPath = resolve(relativeSrcPath) const cache = new RuntimeCache() const functions = await getFunctionsFromPaths([srcPath], { cache, config: inputConfig, dedupe: true, featureFlags }) + const internalFunctionsPath = internalSrcFolder && resolve(internalSrcFolder) if (functions.size === 0) { return @@ -199,6 +208,7 @@ export const zipFunction = async function ( srcDir, srcPath, stat: stats, + isInternal: Boolean(internalFunctionsPath && isPathInside(srcPath, internalFunctionsPath)), }) const durationNs = endTimer(startIntervalTime) const logObject = { diff --git a/tests/fixtures/go-internal/.netlify/internal-functions/go-func-1/main.go b/tests/fixtures/go-internal/.netlify/internal-functions/go-func-1/main.go new file mode 100644 index 000000000..8f6188073 --- /dev/null +++ b/tests/fixtures/go-internal/.netlify/internal-functions/go-func-1/main.go @@ -0,0 +1,9 @@ +package main + +import ( + "fmt" +) + +func main() { + fmt.Println("Hello, world!") +} diff --git a/tests/fixtures/go-internal/.netlify/internal-functions/go-func-2/go-func-2.go b/tests/fixtures/go-internal/.netlify/internal-functions/go-func-2/go-func-2.go new file mode 100644 index 000000000..8f6188073 --- /dev/null +++ b/tests/fixtures/go-internal/.netlify/internal-functions/go-func-2/go-func-2.go @@ -0,0 +1,9 @@ +package main + +import ( + "fmt" +) + +func main() { + fmt.Println("Hello, world!") +} diff --git a/tests/fixtures/go-internal/.netlify/internal-functions/go-func-2/go.mod b/tests/fixtures/go-internal/.netlify/internal-functions/go-func-2/go.mod new file mode 100644 index 000000000..8d419a4b2 --- /dev/null +++ b/tests/fixtures/go-internal/.netlify/internal-functions/go-func-2/go.mod @@ -0,0 +1,3 @@ +module github.com/netlify/zip-it-and-ship-it/tests/fixtures/go-source + +go 1.15 diff --git a/tests/fixtures/go-internal/.netlify/internal-functions/go-func-2/go.sum b/tests/fixtures/go-internal/.netlify/internal-functions/go-func-2/go.sum new file mode 100644 index 000000000..e69de29bb diff --git a/tests/fixtures/node-display-name/function-1.js b/tests/fixtures/node-display-name/function-1.js new file mode 100644 index 000000000..33c1891f8 --- /dev/null +++ b/tests/fixtures/node-display-name/function-1.js @@ -0,0 +1 @@ +module.exports = true diff --git a/tests/fixtures/node-internal/.netlify/internal-functions/function-1.js b/tests/fixtures/node-internal/.netlify/internal-functions/function-1.js new file mode 100644 index 000000000..33c1891f8 --- /dev/null +++ b/tests/fixtures/node-internal/.netlify/internal-functions/function-1.js @@ -0,0 +1 @@ +module.exports = true diff --git a/tests/fixtures/node-internal/.netlify/internal-functions/function-2.js b/tests/fixtures/node-internal/.netlify/internal-functions/function-2.js new file mode 100644 index 000000000..33c1891f8 --- /dev/null +++ b/tests/fixtures/node-internal/.netlify/internal-functions/function-2.js @@ -0,0 +1 @@ +module.exports = true diff --git a/tests/fixtures/rust-internal/.netlify/internal-functions/rust-func-1/.gitignore b/tests/fixtures/rust-internal/.netlify/internal-functions/rust-func-1/.gitignore new file mode 100644 index 000000000..ea8c4bf7f --- /dev/null +++ b/tests/fixtures/rust-internal/.netlify/internal-functions/rust-func-1/.gitignore @@ -0,0 +1 @@ +/target diff --git a/tests/fixtures/rust-internal/.netlify/internal-functions/rust-func-1/Cargo.lock b/tests/fixtures/rust-internal/.netlify/internal-functions/rust-func-1/Cargo.lock new file mode 100644 index 000000000..8c080106f --- /dev/null +++ b/tests/fixtures/rust-internal/.netlify/internal-functions/rust-func-1/Cargo.lock @@ -0,0 +1,707 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +version = 3 + +[[package]] +name = "async-stream" +version = "0.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "171374e7e3b2504e0e5236e3b59260560f9fe94bfe9ac39ba5e4e929c5590625" +dependencies = [ + "async-stream-impl", + "futures-core", +] + +[[package]] +name = "async-stream-impl" +version = "0.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "648ed8c8d2ce5409ccd57453d9d1b214b342a0d69376a6feda1fd6cae3299308" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "atty" +version = "0.2.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d9b39be18770d11421cdb1b9947a45dd3f37e93092cbf377614828a319d5fee8" +dependencies = [ + "hermit-abi", + "libc", + "winapi", +] + +[[package]] +name = "autocfg" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cdb031dd78e28731d87d56cc8ffef4a8f36ca26c38fe2de700543e627f8a464a" + +[[package]] +name = "aws_lambda_events" +version = "0.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b7bfa650eb33bcc1d4a2f513dd142015d3804ab85217a643b846d1f0fe104a1e" +dependencies = [ + "base64", + "bytes", + "chrono", + "http", + "http-serde", + "serde", + "serde_derive", + "serde_json", +] + +[[package]] +name = "base64" +version = "0.13.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "904dfeac50f3cdaba28fc6f57fdcddb75f49ed61346676a78c4ffe55877802fd" + +[[package]] +name = "bytes" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c4872d67bab6358e59559027aa3b9157c53d9358c51423c17554809a8858e0f8" +dependencies = [ + "serde", +] + +[[package]] +name = "cfg-if" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" + +[[package]] +name = "chrono" +version = "0.4.19" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "670ad68c9088c2a963aaa298cb369688cf3f9465ce5e2d4ca10e6e0098a1ce73" +dependencies = [ + "libc", + "num-integer", + "num-traits", + "serde", + "time", + "winapi", +] + +[[package]] +name = "colored" +version = "1.9.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f4ffc801dacf156c5854b9df4f425a626539c3a6ef7893cc0c5084a23f0b6c59" +dependencies = [ + "atty", + "lazy_static", + "winapi", +] + +[[package]] +name = "fnv" +version = "1.0.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3f9eec918d3f24069decb9af1554cad7c880e2da24a9afd88aca000531ab82c1" + +[[package]] +name = "futures" +version = "0.3.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a12aa0eb539080d55c3f2d45a67c3b58b6b0773c1a3ca2dfec66d58c97fd66ca" +dependencies = [ + "futures-channel", + "futures-core", + "futures-executor", + "futures-io", + "futures-sink", + "futures-task", + "futures-util", +] + +[[package]] +name = "futures-channel" +version = "0.3.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5da6ba8c3bb3c165d3c7319fc1cc8304facf1fb8db99c5de877183c08a273888" +dependencies = [ + "futures-core", + "futures-sink", +] + +[[package]] +name = "futures-core" +version = "0.3.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "88d1c26957f23603395cd326b0ffe64124b818f4449552f960d815cfba83a53d" + +[[package]] +name = "futures-executor" +version = "0.3.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "45025be030969d763025784f7f355043dc6bc74093e4ecc5000ca4dc50d8745c" +dependencies = [ + "futures-core", + "futures-task", + "futures-util", +] + +[[package]] +name = "futures-io" +version = "0.3.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "522de2a0fe3e380f1bc577ba0474108faf3f6b18321dbf60b3b9c39a75073377" + +[[package]] +name = "futures-macro" +version = "0.3.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "18e4a4b95cea4b4ccbcf1c5675ca7c4ee4e9e75eb79944d07defde18068f79bb" +dependencies = [ + "autocfg", + "proc-macro-hack", + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "futures-sink" +version = "0.3.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "36ea153c13024fe480590b3e3d4cad89a0cfacecc24577b68f86c6ced9c2bc11" + +[[package]] +name = "futures-task" +version = "0.3.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1d3d00f4eddb73e498a54394f228cd55853bdf059259e8e7bc6e69d408892e99" + +[[package]] +name = "futures-util" +version = "0.3.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "36568465210a3a6ee45e1f165136d68671471a501e632e9a98d96872222b5481" +dependencies = [ + "autocfg", + "futures-channel", + "futures-core", + "futures-io", + "futures-macro", + "futures-sink", + "futures-task", + "memchr", + "pin-project-lite", + "pin-utils", + "proc-macro-hack", + "proc-macro-nested", + "slab", +] + +[[package]] +name = "hello" +version = "0.1.0" +dependencies = [ + "aws_lambda_events", + "http", + "lambda_runtime", + "log", + "simple_logger", + "tokio", +] + +[[package]] +name = "hermit-abi" +version = "0.1.19" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "62b467343b94ba476dcb2500d242dadbb39557df889310ac77c5d99100aaac33" +dependencies = [ + "libc", +] + +[[package]] +name = "http" +version = "0.2.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1323096b05d41827dadeaee54c9981958c0f94e670bc94ed80037d1a7b8b186b" +dependencies = [ + "bytes", + "fnv", + "itoa", +] + +[[package]] +name = "http-body" +version = "0.4.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1ff4f84919677303da5f147645dbea6b1881f368d03ac84e1dc09031ebd7b2c6" +dependencies = [ + "bytes", + "http", + "pin-project-lite", +] + +[[package]] +name = "http-serde" +version = "1.0.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "25698ac7002625796d5a7df8f0602400571da944c2edc1d5c268a6947dd4f692" +dependencies = [ + "http", + "serde", +] + +[[package]] +name = "httparse" +version = "1.5.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "acd94fdbe1d4ff688b67b04eee2e17bd50995534a61539e45adfefb45e5e5503" + +[[package]] +name = "httpdate" +version = "1.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c4a1e36c821dbe04574f602848a19f742f4fb3c98d40449f11bcad18d6b17421" + +[[package]] +name = "hyper" +version = "0.14.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "436ec0091e4f20e655156a30a0df3770fe2900aa301e548e08446ec794b6953c" +dependencies = [ + "bytes", + "futures-channel", + "futures-core", + "futures-util", + "http", + "http-body", + "httparse", + "httpdate", + "itoa", + "pin-project-lite", + "socket2", + "tokio", + "tower-service", + "tracing", + "want", +] + +[[package]] +name = "itoa" +version = "0.4.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b71991ff56294aa922b450139ee08b3bfc70982c6b2c7562771375cf73542dd4" + +[[package]] +name = "lambda_runtime" +version = "0.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "17ed88d8421123f9546cbd0c4235386803859c4a20b80a6eb613a652b486df8e" +dependencies = [ + "async-stream", + "bytes", + "futures", + "http", + "hyper", + "serde", + "serde_json", + "tokio", + "tokio-stream", + "tower-service", + "tracing", + "tracing-error", +] + +[[package]] +name = "lazy_static" +version = "1.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646" + +[[package]] +name = "libc" +version = "0.2.108" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8521a1b57e76b1ec69af7599e75e38e7b7fad6610f037db8c79b127201b5d119" + +[[package]] +name = "log" +version = "0.4.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "51b9bbe6c47d51fc3e1a9b945965946b4c44142ab8792c50835a980d362c2710" +dependencies = [ + "cfg-if", +] + +[[package]] +name = "memchr" +version = "2.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "308cc39be01b73d0d18f82a0e7b2a3df85245f84af96fdddc5d202d27e47b86a" + +[[package]] +name = "mio" +version = "0.7.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8067b404fe97c70829f082dec8bcf4f71225d7eaea1d8645349cb76fa06205cc" +dependencies = [ + "libc", + "log", + "miow", + "ntapi", + "winapi", +] + +[[package]] +name = "miow" +version = "0.3.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b9f1c5b025cda876f66ef43a113f91ebc9f4ccef34843000e0adf6ebbab84e21" +dependencies = [ + "winapi", +] + +[[package]] +name = "ntapi" +version = "0.3.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3f6bb902e437b6d86e03cce10a7e2af662292c5dfef23b65899ea3ac9354ad44" +dependencies = [ + "winapi", +] + +[[package]] +name = "num-integer" +version = "0.1.44" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d2cc698a63b549a70bc047073d2949cce27cd1c7b0a4a862d08a8031bc2801db" +dependencies = [ + "autocfg", + "num-traits", +] + +[[package]] +name = "num-traits" +version = "0.2.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9a64b1ec5cda2586e284722486d802acf1f7dbdc623e2bfc57e65ca1cd099290" +dependencies = [ + "autocfg", +] + +[[package]] +name = "num_cpus" +version = "1.13.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "05499f3756671c15885fee9034446956fff3f243d6077b91e5767df161f766b3" +dependencies = [ + "hermit-abi", + "libc", +] + +[[package]] +name = "once_cell" +version = "1.8.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "692fcb63b64b1758029e0a96ee63e049ce8c5948587f2f7208df04625e5f6b56" + +[[package]] +name = "pin-project-lite" +version = "0.2.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8d31d11c69a6b52a174b42bdc0c30e5e11670f90788b2c471c31c1d17d449443" + +[[package]] +name = "pin-utils" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8b870d8c151b6f2fb93e84a13146138f05d02ed11c7e7c54f8826aaaf7c9f184" + +[[package]] +name = "proc-macro-hack" +version = "0.5.19" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dbf0c48bc1d91375ae5c3cd81e3722dff1abcf81a30960240640d223f59fe0e5" + +[[package]] +name = "proc-macro-nested" +version = "0.1.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bc881b2c22681370c6a780e47af9840ef841837bc98118431d4e1868bd0c1086" + +[[package]] +name = "proc-macro2" +version = "1.0.32" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ba508cc11742c0dc5c1659771673afbab7a0efab23aa17e854cbab0837ed0b43" +dependencies = [ + "unicode-xid", +] + +[[package]] +name = "quote" +version = "1.0.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "38bc8cc6a5f2e3655e0899c1b848643b2562f853f114bfec7be120678e3ace05" +dependencies = [ + "proc-macro2", +] + +[[package]] +name = "ryu" +version = "1.0.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "71d301d4193d031abdd79ff7e3dd721168a9572ef3fe51a1517aba235bd8f86e" + +[[package]] +name = "serde" +version = "1.0.130" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f12d06de37cf59146fbdecab66aa99f9fe4f78722e3607577a5375d66bd0c913" +dependencies = [ + "serde_derive", +] + +[[package]] +name = "serde_derive" +version = "1.0.130" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d7bc1a1ab1961464eae040d96713baa5a724a8152c1222492465b54322ec508b" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "serde_json" +version = "1.0.71" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "063bf466a64011ac24040a49009724ee60a57da1b437617ceb32e53ad61bfb19" +dependencies = [ + "itoa", + "ryu", + "serde", +] + +[[package]] +name = "sharded-slab" +version = "0.1.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "900fba806f70c630b0a382d0d825e17a0f19fcd059a2ade1ff237bcddf446b31" +dependencies = [ + "lazy_static", +] + +[[package]] +name = "simple_logger" +version = "1.13.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b7de33c687404ec3045d4a0d437580455257c0436f858d702f244e7d652f9f07" +dependencies = [ + "atty", + "chrono", + "colored", + "log", + "winapi", +] + +[[package]] +name = "slab" +version = "0.4.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9def91fd1e018fe007022791f865d0ccc9b3a0d5001e01aabb8b40e46000afb5" + +[[package]] +name = "socket2" +version = "0.4.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5dc90fe6c7be1a323296982db1836d1ea9e47b6839496dde9a541bc496df3516" +dependencies = [ + "libc", + "winapi", +] + +[[package]] +name = "syn" +version = "1.0.81" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f2afee18b8beb5a596ecb4a2dce128c719b4ba399d34126b9e4396e3f9860966" +dependencies = [ + "proc-macro2", + "quote", + "unicode-xid", +] + +[[package]] +name = "thread_local" +version = "1.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8018d24e04c95ac8790716a5987d0fec4f8b27249ffa0f7d33f1369bdfb88cbd" +dependencies = [ + "once_cell", +] + +[[package]] +name = "time" +version = "0.1.44" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6db9e6914ab8b1ae1c260a4ae7a49b6c5611b40328a735b21862567685e73255" +dependencies = [ + "libc", + "wasi", + "winapi", +] + +[[package]] +name = "tokio" +version = "1.14.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "70e992e41e0d2fb9f755b37446f20900f64446ef54874f40a60c78f021ac6144" +dependencies = [ + "autocfg", + "bytes", + "libc", + "memchr", + "mio", + "num_cpus", + "pin-project-lite", + "tokio-macros", + "winapi", +] + +[[package]] +name = "tokio-macros" +version = "1.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c9efc1aba077437943f7515666aa2b882dfabfbfdf89c819ea75a8d6e9eaba5e" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "tokio-stream" +version = "0.1.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "50145484efff8818b5ccd256697f36863f587da82cf8b409c53adf1e840798e3" +dependencies = [ + "futures-core", + "pin-project-lite", + "tokio", +] + +[[package]] +name = "tower-service" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "360dfd1d6d30e05fda32ace2c8c70e9c0a9da713275777f5a4dbb8a1893930c6" + +[[package]] +name = "tracing" +version = "0.1.29" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "375a639232caf30edfc78e8d89b2d4c375515393e7af7e16f01cd96917fb2105" +dependencies = [ + "cfg-if", + "log", + "pin-project-lite", + "tracing-attributes", + "tracing-core", +] + +[[package]] +name = "tracing-attributes" +version = "0.1.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f4f480b8f81512e825f337ad51e94c1eb5d3bbdf2b363dcd01e2b19a9ffe3f8e" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "tracing-core" +version = "0.1.21" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1f4ed65637b8390770814083d20756f87bfa2c21bf2f110babdc5438351746e4" +dependencies = [ + "lazy_static", +] + +[[package]] +name = "tracing-error" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b4d7c0b83d4a500748fa5879461652b361edf5c9d51ede2a2ac03875ca185e24" +dependencies = [ + "tracing", + "tracing-subscriber", +] + +[[package]] +name = "tracing-subscriber" +version = "0.2.25" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0e0d2eaa99c3c2e41547cfa109e910a68ea03823cccad4a0525dcbc9b01e8c71" +dependencies = [ + "sharded-slab", + "thread_local", + "tracing-core", +] + +[[package]] +name = "try-lock" +version = "0.2.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "59547bce71d9c38b83d9c0e92b6066c4253371f15005def0c30d9657f50c7642" + +[[package]] +name = "unicode-xid" +version = "0.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8ccb82d61f80a663efe1f787a51b16b5a51e3314d6ac365b08639f52387b33f3" + +[[package]] +name = "want" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1ce8a968cb1cd110d136ff8b819a556d6fb6d919363c61534f6860c7eb172ba0" +dependencies = [ + "log", + "try-lock", +] + +[[package]] +name = "wasi" +version = "0.10.0+wasi-snapshot-preview1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1a143597ca7c7793eff794def352d41792a93c481eb1042423ff7ff72ba2c31f" + +[[package]] +name = "winapi" +version = "0.3.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5c839a674fcd7a98952e593242ea400abe93992746761e38641405d28b00f419" +dependencies = [ + "winapi-i686-pc-windows-gnu", + "winapi-x86_64-pc-windows-gnu", +] + +[[package]] +name = "winapi-i686-pc-windows-gnu" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6" + +[[package]] +name = "winapi-x86_64-pc-windows-gnu" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" diff --git a/tests/fixtures/rust-internal/.netlify/internal-functions/rust-func-1/Cargo.toml b/tests/fixtures/rust-internal/.netlify/internal-functions/rust-func-1/Cargo.toml new file mode 100644 index 000000000..d79be0d7b --- /dev/null +++ b/tests/fixtures/rust-internal/.netlify/internal-functions/rust-func-1/Cargo.toml @@ -0,0 +1,14 @@ +[package] +edition = "2018" +name = "hello" +version = "0.1.0" + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[dependencies] +aws_lambda_events = "0.5.0" +http = "0.2.5" +lambda_runtime = "0.4.1" +log = "0.4.14" +simple_logger = "1.13.0" +tokio = "1.14.0" diff --git a/tests/fixtures/rust-internal/.netlify/internal-functions/rust-func-1/src/main.rs b/tests/fixtures/rust-internal/.netlify/internal-functions/rust-func-1/src/main.rs new file mode 100644 index 000000000..f8987cb9c --- /dev/null +++ b/tests/fixtures/rust-internal/.netlify/internal-functions/rust-func-1/src/main.rs @@ -0,0 +1,29 @@ +use aws_lambda_events::event::apigw::{ApiGatewayProxyRequest, ApiGatewayProxyResponse}; +use aws_lambda_events::encodings::Body; +use http::header::HeaderMap; +use lambda_runtime::{handler_fn, Context, Error}; +use log::LevelFilter; +use simple_logger::SimpleLogger; + +#[tokio::main] +async fn main() -> Result<(), Error> { + SimpleLogger::new().with_level(LevelFilter::Info).init().unwrap(); + + let func = handler_fn(my_handler); + lambda_runtime::run(func).await?; + Ok(()) +} + +pub(crate) async fn my_handler(event: ApiGatewayProxyRequest, _ctx: Context) -> Result { + let path = event.path.unwrap(); + + let resp = ApiGatewayProxyResponse { + status_code: 200, + headers: HeaderMap::new(), + multi_value_headers: HeaderMap::new(), + body: Some(Body::Text(format!("Hello from '{}'", path))), + is_base64_encoded: Some(false), + }; + + Ok(resp) +} \ No newline at end of file diff --git a/tests/fixtures/rust-internal/.netlify/internal-functions/rust-func-2/.gitignore b/tests/fixtures/rust-internal/.netlify/internal-functions/rust-func-2/.gitignore new file mode 100644 index 000000000..ea8c4bf7f --- /dev/null +++ b/tests/fixtures/rust-internal/.netlify/internal-functions/rust-func-2/.gitignore @@ -0,0 +1 @@ +/target diff --git a/tests/fixtures/rust-internal/.netlify/internal-functions/rust-func-2/Cargo.lock b/tests/fixtures/rust-internal/.netlify/internal-functions/rust-func-2/Cargo.lock new file mode 100644 index 000000000..8c080106f --- /dev/null +++ b/tests/fixtures/rust-internal/.netlify/internal-functions/rust-func-2/Cargo.lock @@ -0,0 +1,707 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +version = 3 + +[[package]] +name = "async-stream" +version = "0.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "171374e7e3b2504e0e5236e3b59260560f9fe94bfe9ac39ba5e4e929c5590625" +dependencies = [ + "async-stream-impl", + "futures-core", +] + +[[package]] +name = "async-stream-impl" +version = "0.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "648ed8c8d2ce5409ccd57453d9d1b214b342a0d69376a6feda1fd6cae3299308" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "atty" +version = "0.2.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d9b39be18770d11421cdb1b9947a45dd3f37e93092cbf377614828a319d5fee8" +dependencies = [ + "hermit-abi", + "libc", + "winapi", +] + +[[package]] +name = "autocfg" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cdb031dd78e28731d87d56cc8ffef4a8f36ca26c38fe2de700543e627f8a464a" + +[[package]] +name = "aws_lambda_events" +version = "0.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b7bfa650eb33bcc1d4a2f513dd142015d3804ab85217a643b846d1f0fe104a1e" +dependencies = [ + "base64", + "bytes", + "chrono", + "http", + "http-serde", + "serde", + "serde_derive", + "serde_json", +] + +[[package]] +name = "base64" +version = "0.13.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "904dfeac50f3cdaba28fc6f57fdcddb75f49ed61346676a78c4ffe55877802fd" + +[[package]] +name = "bytes" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c4872d67bab6358e59559027aa3b9157c53d9358c51423c17554809a8858e0f8" +dependencies = [ + "serde", +] + +[[package]] +name = "cfg-if" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" + +[[package]] +name = "chrono" +version = "0.4.19" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "670ad68c9088c2a963aaa298cb369688cf3f9465ce5e2d4ca10e6e0098a1ce73" +dependencies = [ + "libc", + "num-integer", + "num-traits", + "serde", + "time", + "winapi", +] + +[[package]] +name = "colored" +version = "1.9.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f4ffc801dacf156c5854b9df4f425a626539c3a6ef7893cc0c5084a23f0b6c59" +dependencies = [ + "atty", + "lazy_static", + "winapi", +] + +[[package]] +name = "fnv" +version = "1.0.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3f9eec918d3f24069decb9af1554cad7c880e2da24a9afd88aca000531ab82c1" + +[[package]] +name = "futures" +version = "0.3.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a12aa0eb539080d55c3f2d45a67c3b58b6b0773c1a3ca2dfec66d58c97fd66ca" +dependencies = [ + "futures-channel", + "futures-core", + "futures-executor", + "futures-io", + "futures-sink", + "futures-task", + "futures-util", +] + +[[package]] +name = "futures-channel" +version = "0.3.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5da6ba8c3bb3c165d3c7319fc1cc8304facf1fb8db99c5de877183c08a273888" +dependencies = [ + "futures-core", + "futures-sink", +] + +[[package]] +name = "futures-core" +version = "0.3.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "88d1c26957f23603395cd326b0ffe64124b818f4449552f960d815cfba83a53d" + +[[package]] +name = "futures-executor" +version = "0.3.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "45025be030969d763025784f7f355043dc6bc74093e4ecc5000ca4dc50d8745c" +dependencies = [ + "futures-core", + "futures-task", + "futures-util", +] + +[[package]] +name = "futures-io" +version = "0.3.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "522de2a0fe3e380f1bc577ba0474108faf3f6b18321dbf60b3b9c39a75073377" + +[[package]] +name = "futures-macro" +version = "0.3.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "18e4a4b95cea4b4ccbcf1c5675ca7c4ee4e9e75eb79944d07defde18068f79bb" +dependencies = [ + "autocfg", + "proc-macro-hack", + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "futures-sink" +version = "0.3.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "36ea153c13024fe480590b3e3d4cad89a0cfacecc24577b68f86c6ced9c2bc11" + +[[package]] +name = "futures-task" +version = "0.3.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1d3d00f4eddb73e498a54394f228cd55853bdf059259e8e7bc6e69d408892e99" + +[[package]] +name = "futures-util" +version = "0.3.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "36568465210a3a6ee45e1f165136d68671471a501e632e9a98d96872222b5481" +dependencies = [ + "autocfg", + "futures-channel", + "futures-core", + "futures-io", + "futures-macro", + "futures-sink", + "futures-task", + "memchr", + "pin-project-lite", + "pin-utils", + "proc-macro-hack", + "proc-macro-nested", + "slab", +] + +[[package]] +name = "hello" +version = "0.1.0" +dependencies = [ + "aws_lambda_events", + "http", + "lambda_runtime", + "log", + "simple_logger", + "tokio", +] + +[[package]] +name = "hermit-abi" +version = "0.1.19" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "62b467343b94ba476dcb2500d242dadbb39557df889310ac77c5d99100aaac33" +dependencies = [ + "libc", +] + +[[package]] +name = "http" +version = "0.2.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1323096b05d41827dadeaee54c9981958c0f94e670bc94ed80037d1a7b8b186b" +dependencies = [ + "bytes", + "fnv", + "itoa", +] + +[[package]] +name = "http-body" +version = "0.4.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1ff4f84919677303da5f147645dbea6b1881f368d03ac84e1dc09031ebd7b2c6" +dependencies = [ + "bytes", + "http", + "pin-project-lite", +] + +[[package]] +name = "http-serde" +version = "1.0.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "25698ac7002625796d5a7df8f0602400571da944c2edc1d5c268a6947dd4f692" +dependencies = [ + "http", + "serde", +] + +[[package]] +name = "httparse" +version = "1.5.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "acd94fdbe1d4ff688b67b04eee2e17bd50995534a61539e45adfefb45e5e5503" + +[[package]] +name = "httpdate" +version = "1.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c4a1e36c821dbe04574f602848a19f742f4fb3c98d40449f11bcad18d6b17421" + +[[package]] +name = "hyper" +version = "0.14.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "436ec0091e4f20e655156a30a0df3770fe2900aa301e548e08446ec794b6953c" +dependencies = [ + "bytes", + "futures-channel", + "futures-core", + "futures-util", + "http", + "http-body", + "httparse", + "httpdate", + "itoa", + "pin-project-lite", + "socket2", + "tokio", + "tower-service", + "tracing", + "want", +] + +[[package]] +name = "itoa" +version = "0.4.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b71991ff56294aa922b450139ee08b3bfc70982c6b2c7562771375cf73542dd4" + +[[package]] +name = "lambda_runtime" +version = "0.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "17ed88d8421123f9546cbd0c4235386803859c4a20b80a6eb613a652b486df8e" +dependencies = [ + "async-stream", + "bytes", + "futures", + "http", + "hyper", + "serde", + "serde_json", + "tokio", + "tokio-stream", + "tower-service", + "tracing", + "tracing-error", +] + +[[package]] +name = "lazy_static" +version = "1.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646" + +[[package]] +name = "libc" +version = "0.2.108" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8521a1b57e76b1ec69af7599e75e38e7b7fad6610f037db8c79b127201b5d119" + +[[package]] +name = "log" +version = "0.4.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "51b9bbe6c47d51fc3e1a9b945965946b4c44142ab8792c50835a980d362c2710" +dependencies = [ + "cfg-if", +] + +[[package]] +name = "memchr" +version = "2.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "308cc39be01b73d0d18f82a0e7b2a3df85245f84af96fdddc5d202d27e47b86a" + +[[package]] +name = "mio" +version = "0.7.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8067b404fe97c70829f082dec8bcf4f71225d7eaea1d8645349cb76fa06205cc" +dependencies = [ + "libc", + "log", + "miow", + "ntapi", + "winapi", +] + +[[package]] +name = "miow" +version = "0.3.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b9f1c5b025cda876f66ef43a113f91ebc9f4ccef34843000e0adf6ebbab84e21" +dependencies = [ + "winapi", +] + +[[package]] +name = "ntapi" +version = "0.3.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3f6bb902e437b6d86e03cce10a7e2af662292c5dfef23b65899ea3ac9354ad44" +dependencies = [ + "winapi", +] + +[[package]] +name = "num-integer" +version = "0.1.44" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d2cc698a63b549a70bc047073d2949cce27cd1c7b0a4a862d08a8031bc2801db" +dependencies = [ + "autocfg", + "num-traits", +] + +[[package]] +name = "num-traits" +version = "0.2.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9a64b1ec5cda2586e284722486d802acf1f7dbdc623e2bfc57e65ca1cd099290" +dependencies = [ + "autocfg", +] + +[[package]] +name = "num_cpus" +version = "1.13.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "05499f3756671c15885fee9034446956fff3f243d6077b91e5767df161f766b3" +dependencies = [ + "hermit-abi", + "libc", +] + +[[package]] +name = "once_cell" +version = "1.8.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "692fcb63b64b1758029e0a96ee63e049ce8c5948587f2f7208df04625e5f6b56" + +[[package]] +name = "pin-project-lite" +version = "0.2.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8d31d11c69a6b52a174b42bdc0c30e5e11670f90788b2c471c31c1d17d449443" + +[[package]] +name = "pin-utils" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8b870d8c151b6f2fb93e84a13146138f05d02ed11c7e7c54f8826aaaf7c9f184" + +[[package]] +name = "proc-macro-hack" +version = "0.5.19" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dbf0c48bc1d91375ae5c3cd81e3722dff1abcf81a30960240640d223f59fe0e5" + +[[package]] +name = "proc-macro-nested" +version = "0.1.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bc881b2c22681370c6a780e47af9840ef841837bc98118431d4e1868bd0c1086" + +[[package]] +name = "proc-macro2" +version = "1.0.32" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ba508cc11742c0dc5c1659771673afbab7a0efab23aa17e854cbab0837ed0b43" +dependencies = [ + "unicode-xid", +] + +[[package]] +name = "quote" +version = "1.0.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "38bc8cc6a5f2e3655e0899c1b848643b2562f853f114bfec7be120678e3ace05" +dependencies = [ + "proc-macro2", +] + +[[package]] +name = "ryu" +version = "1.0.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "71d301d4193d031abdd79ff7e3dd721168a9572ef3fe51a1517aba235bd8f86e" + +[[package]] +name = "serde" +version = "1.0.130" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f12d06de37cf59146fbdecab66aa99f9fe4f78722e3607577a5375d66bd0c913" +dependencies = [ + "serde_derive", +] + +[[package]] +name = "serde_derive" +version = "1.0.130" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d7bc1a1ab1961464eae040d96713baa5a724a8152c1222492465b54322ec508b" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "serde_json" +version = "1.0.71" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "063bf466a64011ac24040a49009724ee60a57da1b437617ceb32e53ad61bfb19" +dependencies = [ + "itoa", + "ryu", + "serde", +] + +[[package]] +name = "sharded-slab" +version = "0.1.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "900fba806f70c630b0a382d0d825e17a0f19fcd059a2ade1ff237bcddf446b31" +dependencies = [ + "lazy_static", +] + +[[package]] +name = "simple_logger" +version = "1.13.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b7de33c687404ec3045d4a0d437580455257c0436f858d702f244e7d652f9f07" +dependencies = [ + "atty", + "chrono", + "colored", + "log", + "winapi", +] + +[[package]] +name = "slab" +version = "0.4.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9def91fd1e018fe007022791f865d0ccc9b3a0d5001e01aabb8b40e46000afb5" + +[[package]] +name = "socket2" +version = "0.4.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5dc90fe6c7be1a323296982db1836d1ea9e47b6839496dde9a541bc496df3516" +dependencies = [ + "libc", + "winapi", +] + +[[package]] +name = "syn" +version = "1.0.81" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f2afee18b8beb5a596ecb4a2dce128c719b4ba399d34126b9e4396e3f9860966" +dependencies = [ + "proc-macro2", + "quote", + "unicode-xid", +] + +[[package]] +name = "thread_local" +version = "1.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8018d24e04c95ac8790716a5987d0fec4f8b27249ffa0f7d33f1369bdfb88cbd" +dependencies = [ + "once_cell", +] + +[[package]] +name = "time" +version = "0.1.44" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6db9e6914ab8b1ae1c260a4ae7a49b6c5611b40328a735b21862567685e73255" +dependencies = [ + "libc", + "wasi", + "winapi", +] + +[[package]] +name = "tokio" +version = "1.14.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "70e992e41e0d2fb9f755b37446f20900f64446ef54874f40a60c78f021ac6144" +dependencies = [ + "autocfg", + "bytes", + "libc", + "memchr", + "mio", + "num_cpus", + "pin-project-lite", + "tokio-macros", + "winapi", +] + +[[package]] +name = "tokio-macros" +version = "1.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c9efc1aba077437943f7515666aa2b882dfabfbfdf89c819ea75a8d6e9eaba5e" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "tokio-stream" +version = "0.1.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "50145484efff8818b5ccd256697f36863f587da82cf8b409c53adf1e840798e3" +dependencies = [ + "futures-core", + "pin-project-lite", + "tokio", +] + +[[package]] +name = "tower-service" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "360dfd1d6d30e05fda32ace2c8c70e9c0a9da713275777f5a4dbb8a1893930c6" + +[[package]] +name = "tracing" +version = "0.1.29" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "375a639232caf30edfc78e8d89b2d4c375515393e7af7e16f01cd96917fb2105" +dependencies = [ + "cfg-if", + "log", + "pin-project-lite", + "tracing-attributes", + "tracing-core", +] + +[[package]] +name = "tracing-attributes" +version = "0.1.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f4f480b8f81512e825f337ad51e94c1eb5d3bbdf2b363dcd01e2b19a9ffe3f8e" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "tracing-core" +version = "0.1.21" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1f4ed65637b8390770814083d20756f87bfa2c21bf2f110babdc5438351746e4" +dependencies = [ + "lazy_static", +] + +[[package]] +name = "tracing-error" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b4d7c0b83d4a500748fa5879461652b361edf5c9d51ede2a2ac03875ca185e24" +dependencies = [ + "tracing", + "tracing-subscriber", +] + +[[package]] +name = "tracing-subscriber" +version = "0.2.25" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0e0d2eaa99c3c2e41547cfa109e910a68ea03823cccad4a0525dcbc9b01e8c71" +dependencies = [ + "sharded-slab", + "thread_local", + "tracing-core", +] + +[[package]] +name = "try-lock" +version = "0.2.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "59547bce71d9c38b83d9c0e92b6066c4253371f15005def0c30d9657f50c7642" + +[[package]] +name = "unicode-xid" +version = "0.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8ccb82d61f80a663efe1f787a51b16b5a51e3314d6ac365b08639f52387b33f3" + +[[package]] +name = "want" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1ce8a968cb1cd110d136ff8b819a556d6fb6d919363c61534f6860c7eb172ba0" +dependencies = [ + "log", + "try-lock", +] + +[[package]] +name = "wasi" +version = "0.10.0+wasi-snapshot-preview1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1a143597ca7c7793eff794def352d41792a93c481eb1042423ff7ff72ba2c31f" + +[[package]] +name = "winapi" +version = "0.3.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5c839a674fcd7a98952e593242ea400abe93992746761e38641405d28b00f419" +dependencies = [ + "winapi-i686-pc-windows-gnu", + "winapi-x86_64-pc-windows-gnu", +] + +[[package]] +name = "winapi-i686-pc-windows-gnu" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6" + +[[package]] +name = "winapi-x86_64-pc-windows-gnu" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" diff --git a/tests/fixtures/rust-internal/.netlify/internal-functions/rust-func-2/Cargo.toml b/tests/fixtures/rust-internal/.netlify/internal-functions/rust-func-2/Cargo.toml new file mode 100644 index 000000000..d79be0d7b --- /dev/null +++ b/tests/fixtures/rust-internal/.netlify/internal-functions/rust-func-2/Cargo.toml @@ -0,0 +1,14 @@ +[package] +edition = "2018" +name = "hello" +version = "0.1.0" + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[dependencies] +aws_lambda_events = "0.5.0" +http = "0.2.5" +lambda_runtime = "0.4.1" +log = "0.4.14" +simple_logger = "1.13.0" +tokio = "1.14.0" diff --git a/tests/fixtures/rust-internal/.netlify/internal-functions/rust-func-2/src/main.rs b/tests/fixtures/rust-internal/.netlify/internal-functions/rust-func-2/src/main.rs new file mode 100644 index 000000000..f8987cb9c --- /dev/null +++ b/tests/fixtures/rust-internal/.netlify/internal-functions/rust-func-2/src/main.rs @@ -0,0 +1,29 @@ +use aws_lambda_events::event::apigw::{ApiGatewayProxyRequest, ApiGatewayProxyResponse}; +use aws_lambda_events::encodings::Body; +use http::header::HeaderMap; +use lambda_runtime::{handler_fn, Context, Error}; +use log::LevelFilter; +use simple_logger::SimpleLogger; + +#[tokio::main] +async fn main() -> Result<(), Error> { + SimpleLogger::new().with_level(LevelFilter::Info).init().unwrap(); + + let func = handler_fn(my_handler); + lambda_runtime::run(func).await?; + Ok(()) +} + +pub(crate) async fn my_handler(event: ApiGatewayProxyRequest, _ctx: Context) -> Result { + let path = event.path.unwrap(); + + let resp = ApiGatewayProxyResponse { + status_code: 200, + headers: HeaderMap::new(), + multi_value_headers: HeaderMap::new(), + body: Some(Body::Text(format!("Hello from '{}'", path))), + is_base64_encoded: Some(false), + }; + + Ok(resp) +} \ No newline at end of file diff --git a/tests/main.test.ts b/tests/main.test.ts index 63881536a..d3564a918 100644 --- a/tests/main.test.ts +++ b/tests/main.test.ts @@ -67,8 +67,29 @@ describe('zip-it-and-ship-it', () => { expect(files).toHaveLength(1) expect(files[0].runtime).toBe('js') expect(files[0].mainFile).toBe(join(FIXTURES_DIR, fixtureName, 'function.js')) + expect(files[0].isInternal).toBeFalsy() }) + testMany( + 'Zips Node.js function files from an internal functions dir with a configured name', + [...allBundleConfigs, 'bundler_none'], + async (options) => { + const fixtureName = join('node-internal', '.netlify/internal-functions') + const { files } = await zipFixture(fixtureName, { + length: 2, + opts: { + internalSrcFolder: join(FIXTURES_DIR, fixtureName), + ...options, + config: { 'function-1': { name: 'Function One' } }, + }, + }) + expect(files).toHaveLength(2) + expect(files[0].isInternal).toBe(true) + expect(files[0].displayName).toBe('Function One') + expect(files[1].displayName).toBeUndefined() + }, + ) + testMany( 'Handles Node module with native bindings (buildtime marker module)', [...allBundleConfigs], @@ -1744,6 +1765,32 @@ describe('zip-it-and-ship-it', () => { expect(mockSource).toBe(unzippedBinaryContents) }) + test('Builds Go functions from an internal functions dir with a configured name', async () => { + vi.mocked(shellUtils.runCommand).mockImplementation(async (...args) => { + await writeFile(args[1][2], '') + + return {} as any + }) + + const fixtureName = join('go-internal', '.netlify/internal-functions') + const { files } = await zipFixture(fixtureName, { + length: 2, + opts: { + internalSrcFolder: join(FIXTURES_DIR, fixtureName), + config: { + 'go-func-1': { + name: 'Go Function One', + }, + }, + }, + }) + + expect(files).toHaveLength(2) + expect(files[0].isInternal).toBe(true) + expect(files[0].displayName).toBe('Go Function One') + expect(files[1].displayName).toBeUndefined() + }) + test('Builds Go functions from source', async () => { vi.mocked(shellUtils.runCommand).mockImplementation(async (...args) => { await writeFile(args[1][2], '') @@ -1763,6 +1810,7 @@ describe('zip-it-and-ship-it', () => { name: 'go-func-1', path: expect.anything(), runtime: 'go', + isInternal: false, }, { config: expect.anything(), @@ -1770,6 +1818,7 @@ describe('zip-it-and-ship-it', () => { name: 'go-func-2', path: expect.anything(), runtime: 'go', + isInternal: false, }, ]) @@ -1870,6 +1919,7 @@ describe('zip-it-and-ship-it', () => { path: expect.anything(), runtime: 'rs', size: 278, + isInternal: false, }, { config: expect.anything(), @@ -1878,6 +1928,7 @@ describe('zip-it-and-ship-it', () => { path: expect.anything(), runtime: 'rs', size: 278, + isInternal: false, }, ]) @@ -1899,6 +1950,43 @@ describe('zip-it-and-ship-it', () => { ) }) + test('Builds Rust functions from an internal functions dir with a configured name', async () => { + vi.mocked(shellUtils.runCommand).mockImplementation(async (...args) => { + const [rootCommand, , { env: environment }] = args + + if (rootCommand === 'cargo') { + const directory = join(environment.CARGO_TARGET_DIR, args[1][2], 'release') + const binaryPath = join(directory, 'hello') + + await mkdir(directory, { recursive: true }) + await writeFile(binaryPath, '') + + return {} as any + } + }) + + const fixtureName = join('rust-internal', '.netlify/internal-functions') + const { files } = await zipFixture(fixtureName, { + length: 2, + opts: { + internalSrcFolder: join(FIXTURES_DIR, fixtureName), + config: { + 'rust-func-1': { + name: 'Rust Function Two', + }, + }, + featureFlags: { + buildRustSource: true, + }, + }, + }) + + expect(files).toHaveLength(2) + expect(files[0].isInternal).toBe(true) + expect(files[0].displayName).toBe('Rust Function Two') + expect(files[1].displayName).toBeUndefined() + }) + test('Adds `type: "functionsBundling"` to errors resulting from compiling Rust binaries', async () => { vi.mocked(shellUtils.runCommand).mockImplementation((...args) => { if (args[0] === 'cargo') { diff --git a/tests/zip_function.test.ts b/tests/zip_function.test.ts index 3299304cc..6e2a3b69f 100644 --- a/tests/zip_function.test.ts +++ b/tests/zip_function.test.ts @@ -138,4 +138,34 @@ describe('zipFunction', () => { expect(mock2).toBe(true) }, ) + + testMany( + 'Can populate the isInternal property for functions', + ['bundler_default', 'bundler_esbuild', 'bundler_nft'], + async (options) => { + const { path: tmpDir } = await getTmpDir({ prefix: 'zip-it-test' }) + const basePath = join(FIXTURES_DIR, 'node-internal', '.netlify/internal-functions') + const opts = merge(options, { + internalSrcFolder: basePath, + }) + const result = (await zipFunction(`${basePath}/function-1.js`, tmpDir, opts))! + + expect(result.isInternal).toBe(true) + }, + ) + + testMany( + 'Can populate the displayName property for functions', + ['bundler_default', 'bundler_esbuild', 'bundler_nft'], + async (options) => { + const { path: tmpDir } = await getTmpDir({ prefix: 'zip-it-test' }) + const basePath = join(FIXTURES_DIR, 'node-display-name') + const opts = merge(options, { + config: { 'function-1': { name: 'Function One' } }, + }) + const result = (await zipFunction(`${basePath}/function-1.js`, tmpDir, opts))! + + expect(result.displayName).toBe('Function One') + }, + ) })