Skip to content

Commit

Permalink
Merge pull request #1813 from dherault/arccode-sponsoring-v13
Browse files Browse the repository at this point in the history
Updates to v13
  • Loading branch information
dherault authored Aug 22, 2024
2 parents 31afde0 + 52509b2 commit bb3f724
Show file tree
Hide file tree
Showing 13 changed files with 660 additions and 693 deletions.
15 changes: 8 additions & 7 deletions .github/workflows/nodejs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,24 @@ name: node.js

on:
pull_request:
branches: [master]
branches: [master, v13]
push:
branches: [master]
branches: [master, v13]

env:
FORCE_COLOR: 1
PRINT_OFFLINE_OUTPUT: 1
SERVERLESS_ACCESS_KEY: ${{ secrets.SERVERLESS_ACCESS_KEY }}

jobs:
build:
name: "[${{ matrix.os }}] node.js v${{ matrix.node-version }}"
runs-on: ${{ matrix.os }}

timeout-minutes: 40
strategy:
fail-fast: false
matrix:
os: [macos-12, ubuntu-latest, windows-latest]
os: [macos-latest, ubuntu-latest, windows-latest]
node-version: [18, 20, 22]

steps:
Expand All @@ -33,12 +34,12 @@ jobs:
with:
go-version: "1"

- uses: actions/setup-java@v3
- uses: actions/setup-java@v4
with:
distribution: "temurin"
java-version: "8"
java-version: "11"

- uses: actions/setup-python@v4
- uses: actions/setup-python@v5
with:
python-version: "3.9"

Expand Down
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
The MIT License (MIT)

Copyright (c) 2016-present David Hérault
Copyright (c) 2016-2024 David Hérault

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
208 changes: 43 additions & 165 deletions README.md

Large diffs are not rendered by default.

970 changes: 485 additions & 485 deletions package-lock.json

Large diffs are not rendered by default.

17 changes: 8 additions & 9 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
{
"dedicatedTo": "Blue, a great migrating bird.",
"name": "serverless-offline",
"version": "13.6.0",
"version": "13.7.0",
"description": "Emulate AWS λ and API Gateway locally when developing your Serverless project",
"license": "MIT",
"exports": {
Expand Down Expand Up @@ -77,7 +76,7 @@
]
},
"dependencies": {
"@aws-sdk/client-lambda": "^3.509.0",
"@aws-sdk/client-lambda": "^3.636.0",
"@hapi/boom": "^10.0.1",
"@hapi/h2o2": "^10.0.4",
"@hapi/hapi": "^21.3.10",
Expand All @@ -89,12 +88,12 @@
"fs-extra": "^11.2.0",
"is-wsl": "^3.1.0",
"java-invoke-local": "0.0.6",
"jose": "^5.6.3",
"jose": "^5.7.0",
"js-string-escape": "^1.0.1",
"jsonpath-plus": "^9.0.0",
"jsonschema": "^1.4.1",
"jszip": "^3.10.1",
"luxon": "^3.4.4",
"luxon": "^3.5.0",
"node-schedule": "^2.1.1",
"p-memoize": "^7.1.1",
"velocityjs": "^2.0.6",
Expand All @@ -108,12 +107,12 @@
"eslint-config-airbnb-base": "^15.0.0",
"eslint-config-prettier": "^9.1.0",
"eslint-plugin-import": "^2.29.1",
"eslint-plugin-prettier": "^5.1.3",
"eslint-plugin-prettier": "^5.2.1",
"eslint-plugin-unicorn": "^54.0.0",
"mocha": "^10.6.0",
"mocha": "^10.7.3",
"nyc": "^17.0.0",
"prettier": "^3.3.2",
"serverless": "^3.39.0"
"prettier": "^3.3.3",
"serverless": "^3.2.0"
},
"peerDependencies": {
"serverless": "^3.2.0"
Expand Down
9 changes: 7 additions & 2 deletions src/ServerlessOffline.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import process, { exit } from "node:process"
import { log, setLogUtils } from "./utils/log.js"
import logSponsor from "./utils/logSponsor.js"
import {
commandOptions,
CUSTOM_OPTION,
Expand Down Expand Up @@ -64,6 +65,12 @@ export default class ServerlessOffline {
async start() {
this.#mergeOptions()

if (this.#cliOptions.noSponsor) {
log.notice()
} else {
logSponsor()
}

const {
albEvents,
httpEvents,
Expand Down Expand Up @@ -278,13 +285,11 @@ export default class ServerlessOffline {
origin: this.#options.corsAllowOrigin,
}

log.notice()
log.notice(
`Starting Offline at stage ${
this.#options.stage || provider.stage
} ${gray(`(${this.#options.region || provider.region})`)}`,
)
log.notice()
log.debug("options:", this.#options)
}

Expand Down
4 changes: 4 additions & 0 deletions src/config/commandOptions.js
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,10 @@ export default {
type: "boolean",
usage: "Don't prepend http routes with the stage.",
},
noSponsor: {
type: "boolean",
usage: "Remove sponsor message from the output.",
},
noTimeout: {
shortcut: "t",
type: "boolean",
Expand Down
2 changes: 2 additions & 0 deletions src/events/http/createAuthScheme.js
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,8 @@ export default function createAuthScheme(authorizerOptions, provider, lambda) {
event = {
...event,
identitySource: [finalAuthorization],
pathParameters: nullIfEmpty(pathParams),
queryStringParameters: parseQueryStringParameters(url),
rawPath: request.path,
rawQueryString: getRawQueryParams(url),
requestContext: {
Expand Down
8 changes: 3 additions & 5 deletions src/lambda/HttpServer.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ export default class HttpServer {
.listFunctionNames()
.map(
(functionName) =>
` * ${funcNamePairs[functionName]}: ${functionName}`,
` * ${funcNamePairs[functionName]}: ${functionName}`,
),
].join("\n"),
)
Expand All @@ -73,9 +73,7 @@ export default class HttpServer {
.listFunctionNames()
.map(
(functionName) =>
` * ${
invRoute.method
} ${basePath}${invRoute.path.replace(
` * ${invRoute.method} ${basePath}${invRoute.path.replace(
"{functionName}",
functionName,
)}`,
Expand All @@ -90,7 +88,7 @@ export default class HttpServer {
.listFunctionNames()
.map(
(functionName) =>
` * ${
` * ${
invAsyncRoute.method
} ${basePath}${invAsyncRoute.path.replace(
"{functionName}",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
/* eslint-disable unicorn/no-abusive-eslint-disable */
/* eslint-disable */

"use strict"

const { pathToFileURL } = require("node:url")
Expand All @@ -20,7 +23,7 @@ const { pathToFileURL } = require("node:url")
"Errors.js": function (exports2, module2) {
"use strict"

const util = require("util")
const util = require("node:util")
function _isError(obj) {
return (
obj &&
Expand Down Expand Up @@ -53,7 +56,7 @@ const { pathToFileURL } = require("node:url")
errorMessage: error.toString(),
trace: [],
}
} catch (_err) {
} catch {
return {
errorType: "handled",
errorMessage:
Expand All @@ -67,7 +70,7 @@ const { pathToFileURL } = require("node:url")
return ` ${JSON.stringify(error, (_k, v) =>
_withEnumerableProperties(v),
)}`
} catch (err) {
} catch {
return ` ${JSON.stringify(toRapidResponse(error))}`
}
}
Expand Down Expand Up @@ -118,27 +121,27 @@ const { pathToFileURL } = require("node:url")
return 0
}
try {
const verbosity = parseInt(process.env[EnvVarName])
const verbosity = Number.parseInt(process.env[EnvVarName])
return verbosity < 0 ? 0 : verbosity > 3 ? 3 : verbosity
} catch (_) {
} catch {
return 0
}
})()
exports2.logger = function (category) {
return {
verbose() {
if (Verbosity >= 1) {
console.log.apply(null, [Tag, category, ...arguments])
Reflect.apply(console.log, null, [Tag, category, ...arguments])
}
},
vverbose() {
if (Verbosity >= 2) {
console.log.apply(null, [Tag, category, ...arguments])
Reflect.apply(console.log, null, [Tag, category, ...arguments])
}
},
vvverbose() {
if (Verbosity >= 3) {
console.log.apply(null, [Tag, category, ...arguments])
Reflect.apply(console.log, null, [Tag, category, ...arguments])
}
},
}
Expand Down Expand Up @@ -166,8 +169,8 @@ const { pathToFileURL } = require("node:url")
module2.exports.HttpResponseStream = HttpResponseStream2
},
})
const path = require("path")
const fs = require("fs")
const path = require("node:path")
const fs = require("node:fs")
const {
HandlerNotFound,
MalformedHandlerName,
Expand Down Expand Up @@ -306,7 +309,10 @@ const { pathToFileURL } = require("node:url")
if (e instanceof SyntaxError) {
throw new UserCodeSyntaxError(e)
} else if (e.code !== void 0 && e.code === "MODULE_NOT_FOUND") {
verbose("globalPaths", JSON.stringify(require("module").globalPaths))
verbose(
"globalPaths",
JSON.stringify(require("node:module").globalPaths),
)
throw new ImportModuleError(e)
} else {
throw e
Expand All @@ -322,7 +328,7 @@ const { pathToFileURL } = require("node:url")
}
function _isHandlerStreaming(handler) {
if (
typeof handler[HANDLER_STREAMING] === "undefined" ||
handler[HANDLER_STREAMING] === undefined ||
handler[HANDLER_STREAMING] === null ||
handler[HANDLER_STREAMING] === false
) {
Expand Down
6 changes: 6 additions & 0 deletions src/lambda/handler-runner/python-runner/invoke.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# copy/pasted entirely as is from:
# https://github.com/serverless/serverless/blob/v1.50.0/lib/plugins/aws/invokeLocal/invoke.py

import base64
import subprocess
import argparse
import json
Expand All @@ -10,6 +11,7 @@
from time import strftime, time
from importlib import import_module


class FakeLambdaContext(object):
def __init__(self, name='Fake', version='LATEST', timeout=6, **kwargs):
self.name = name
Expand Down Expand Up @@ -102,5 +104,9 @@ def log(self):
'__offline_payload__': result
}

if isinstance(result['body'], bytes):
data['__offline_payload__']['body'] = base64.b64encode(result['body']).decode('utf-8')
data['isBase64Encoded'] = True

sys.stdout.write(json.dumps(data))
sys.stdout.write('\n')
13 changes: 6 additions & 7 deletions src/utils/logRoutes.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,7 @@ import {
yellow,
} from "../config/colors.js"

const { max } = Math

const post = "POST"
const colorMethodMapping = new Map([
["DELETE", red],
["GET", dodgerblue],
Expand All @@ -28,13 +27,13 @@ function logRoute(method, server, path, maxLength, dimPath = false) {
const methodColor = colorMethodMapping.get(method) ?? peachpuff
const methodFormatted = method.padEnd(maxLength, " ")

return `${methodColor(methodFormatted)} ${yellow.dim("|")} ${gray.dim(
server,
)}${dimPath ? gray.dim(path) : lime(path)}`
return `${methodColor(methodFormatted)} ${yellow.dim("|")} ${gray.dim(server)}${dimPath ? gray.dim(path) : lime(path)}`
}

function getMaxHttpMethodNameLength(routeInfo) {
return max(...routeInfo.map(({ method }) => method.length))
return Math.max(
...routeInfo.map(({ method }) => Math.max(method.length, post.length)),
)
}

export default function logRoutes(routeInfo) {
Expand All @@ -55,7 +54,7 @@ export default function logRoutes(routeInfo) {
// eslint-disable-next-line prefer-template
logRoute(method, server, path, maxLength) +
"\n" +
logRoute("POST", server, invokePath, maxLength, true),
logRoute(post, server, invokePath, maxLength, true),
)
.join("\n"),
boxenOptions,
Expand Down
Loading

0 comments on commit bb3f724

Please sign in to comment.