npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@amplify-playground/code-from-asset-helper

v1.0.9

Published

A helper to build, bundle and copy a lambda or AppSync function to the Amplify assets directory.

Downloads

2

Readme

Code from Asset Helper

A helper to build, bundle and copy a lambda or AppSync function to the Amplify assets directory.

Installation

npm install --save-dev @amplify-playground/code-from-asset-helper

Basic Usage

Lambda Functions

The example below defines an Amplify backend and builds and bundles the function my-custom-function.lambda.ts using esbuild.


import { BuildMode, lambdaCodeFromAssetHelper } from '@amplify-playground/code-from-asset-helper';
import { defineBackend } from '@aws-amplify/backend';
import {
  Function as LambdaFunction,
  Runtime as LambdaRuntime,
} from 'aws-cdk-lib/aws-lambda';
import path from 'path';

const backend = defineBackend({
  //..
});

const stack = backend.createStack('MyCustomStack');

const buildConfig: AssetHelperConfig = { 
  buildMode: BuildMode.Esbuild
};

const myLambda = new LambdaFunction(stack, 'MyCustomFunction', {
  handler: 'index.handler',
  code: lambdaCodeFromAssetHelper(
    path.resolve('amplify/functions/my-custom-function.lambda.ts'),
    buildConfig
  ),
  runtime: LambdaRuntime.NODEJS_20_X,
});

Configuration

Disable building and copy file as is:

const buildConfig: AssetHelperConfig = { 
  buildMode: BuildMode.Off
}

Transpile using the TypeScript transpiler:

const buildConfig: AssetHelperConfig = { 
  buildMode: BuildMode.Typescript,
  tsTranspileOptions: {} // Optional
}

Build and bundle to a single file using esbuild (recommended):

const buildConfig: AssetHelperConfig = { 
  buildMode: BuildMode.Esbuild,
  esBuildOptions: {} // Optional
}

AppSync functions

The path to your tsconfig.json must be provided when building AppSync resolver functions. This allows linting against AppSync resolver functions' rules.

The following example configures a pipeline resolver for a field createTodo :

//...

const backend = defineBackend({
  data
});

const buildConfig: AppSyncAssetHelperConfigES = {
  buildMode: BuildMode.Esbuild,
  tsConfig: path.join('amplify/data', 'tsconfig.json'),
};

backend.data.addResolver('createTodo', {
    fieldName: 'createTodo',
    typeName: 'Mutation',
    runtime: FunctionRuntime.JS_1_0_0,
    code: Code.fromAsset(
            //this function is plain js
            path.join(__dirnameCommon, 'pipeline-handler.resolver.js') 
    ),
    pipelineConfig: [
      new AppsyncFunction(stack, 'TodoCreate', {
        api: backend.data.resources.graphqlApi,
        dataSource: todoDataSource,
        name: 'TodoCreate',
        code: await appSyncCodeFromAssetHelper(
          path.join(__dirname, 'todo-create.resolver.ts'), 
          buildConfig
        ),
        runtime: FunctionRuntime.JS_1_0_0,
      })
    ]
  });

License

Apache License 2.0