Skip to content

Commit 15dda5f

Browse files
feat: initial commit of serverless-uv-requirements plugin
- Added package.json with metadata, scripts, and dependencies. - Implemented UvRequirementsPlugin for managing Python dependencies using uv. - Created utility functions for command execution and configuration management. - Defined types for plugin configuration and serverless instance. - Added Jest tests for plugin functionality and utility methods. - Included setup file for Jest configuration and global mocks. - Configured TypeScript with strict settings and output directory. - Added example pyproject.toml and serverless.yml files for testing.
1 parent e8c364b commit 15dda5f

File tree

16 files changed

+13166
-1
lines changed

16 files changed

+13166
-1
lines changed

.eslintignore

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
node_modules/
2+
dist/
3+
coverage/
4+
*.js
5+
*.d.ts
6+
test/fixtures/

.eslintrc.js

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
module.exports = {
2+
parser: '@typescript-eslint/parser',
3+
plugins: ['@typescript-eslint'],
4+
extends: [
5+
'eslint:recommended',
6+
],
7+
root: true,
8+
env: {
9+
node: true,
10+
jest: true,
11+
es2020: true,
12+
},
13+
ignorePatterns: ['.eslintrc.js', 'dist/', 'coverage/', 'node_modules/'],
14+
rules: {
15+
'no-unused-vars': 'off',
16+
'no-undef': 'off',
17+
},
18+
};

.github/workflows/ci.yml

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
name: CI
2+
3+
on:
4+
push:
5+
branches: [main, develop]
6+
pull_request:
7+
branches: [main]
8+
9+
jobs:
10+
test:
11+
runs-on: ubuntu-latest
12+
strategy:
13+
matrix:
14+
node-version: [16.x, 18.x, 20.x]
15+
16+
steps:
17+
- uses: actions/checkout@v4
18+
19+
- name: Use Node.js ${{ matrix.node-version }}
20+
uses: actions/setup-node@v4
21+
with:
22+
node-version: ${{ matrix.node-version }}
23+
cache: "npm"
24+
25+
- name: Install dependencies
26+
run: npm ci
27+
28+
- name: Run linter
29+
run: npm run lint
30+
31+
- name: Run tests
32+
run: npm run test:coverage
33+
34+
- name: Build
35+
run: npm run build
36+
37+
- name: Upload coverage to Codecov
38+
uses: codecov/codecov-action@v3
39+
if: matrix.node-version == '18.x'
40+
with:
41+
file: ./coverage/lcov.info
42+
43+
integration-test:
44+
runs-on: ubuntu-latest
45+
steps:
46+
- uses: actions/checkout@v4
47+
48+
- name: Use Node.js 18.x
49+
uses: actions/setup-node@v4
50+
with:
51+
node-version: 18.x
52+
cache: "npm"
53+
54+
- name: Install uv
55+
run: curl -LsSf https://astral.sh/uv/install.sh | sh
56+
57+
- name: Install dependencies
58+
run: npm ci
59+
60+
- name: Build plugin
61+
run: npm run build
62+
63+
- name: Test plugin with real uv
64+
run: |
65+
cd test/fixtures
66+
npm link ../../
67+
npx serverless package

.github/workflows/release.yml

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
name: Release
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
8+
jobs:
9+
release:
10+
runs-on: ubuntu-latest
11+
steps:
12+
- uses: actions/checkout@v4
13+
with:
14+
fetch-depth: 0
15+
16+
- name: Use Node.js 18.x
17+
uses: actions/setup-node@v4
18+
with:
19+
node-version: 18.x
20+
cache: "npm"
21+
22+
- name: Install dependencies
23+
run: npm ci
24+
25+
- name: Run tests
26+
run: npm test
27+
28+
- name: Build
29+
run: npm run build
30+
31+
- name: Release
32+
env:
33+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
34+
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
35+
run: npx semantic-release

README.md

Lines changed: 66 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,67 @@
11
# serverless-uv-requirements
2-
Serverless UV Requirements – Blazing-fast dependency compile & freeze with uv during the Serverless package phase
2+
3+
[![npm version](https://badge.fury.io/js/serverless-uv-requirements.svg)](https://badge.fury.io/js/serverless-uv-requirements)
4+
[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
5+
6+
Fast Python dependency resolution using [uv](https://docs.astral.sh/uv/) for Serverless Framework.
7+
8+
Generates `requirements.txt` from `pyproject.toml` using uv's fast resolver, then works with `serverless-python-requirements` for Lambda packaging.
9+
10+
## Installation
11+
12+
```bash
13+
npm install --save-dev serverless-uv-requirements serverless-python-requirements
14+
```
15+
16+
## Setup
17+
18+
```yaml
19+
# serverless.yml
20+
plugins:
21+
- serverless-uv-requirements
22+
- serverless-python-requirements
23+
24+
custom:
25+
uv:
26+
mode: compile
27+
source: pyproject.toml
28+
output: requirements.txt
29+
30+
pythonRequirements:
31+
dockerizePip: non-linux
32+
```
33+
34+
```toml
35+
# pyproject.toml
36+
[project]
37+
dependencies = [
38+
"fastapi>=0.104.0",
39+
"pydantic>=2.0.0",
40+
]
41+
```
42+
43+
## Configuration
44+
45+
```yaml
46+
custom:
47+
uv:
48+
mode: compile # 'compile' or 'freeze'
49+
source: pyproject.toml # Input file
50+
output: requirements.txt # Output file
51+
verbose: false # Enable verbose logging
52+
skipIfMissing: false # Skip if uv not available
53+
```
54+
55+
## Requirements
56+
57+
- **uv**: `curl -LsSf https://astral.sh/uv/install.sh | sh`
58+
- **Serverless Framework**: >=3.0.0
59+
60+
## How it works
61+
62+
1. uv resolves dependencies from `pyproject.toml` to `requirements.txt` (10-100x faster than pip)
63+
2. serverless-python-requirements handles Lambda packaging
64+
65+
## License
66+
67+
MIT

jest.config.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
module.exports = {
2+
preset: "ts-jest",
3+
testEnvironment: "node",
4+
roots: ["<rootDir>/src", "<rootDir>/test"],
5+
testMatch: ["**/__tests__/**/*.ts", "**/?(*.)+(spec|test).ts"],
6+
collectCoverageFrom: ["src/**/*.ts", "!src/**/*.d.ts"],
7+
coverageDirectory: "coverage",
8+
coverageReporters: ["text", "lcov", "html"],
9+
setupFilesAfterEnv: ["<rootDir>/test/setup.ts"],
10+
};

0 commit comments

Comments
 (0)