Skip to content

Commit

Permalink
feat: bundle dependencies by default, fix cli option case
Browse files Browse the repository at this point in the history
  • Loading branch information
jedwards1211 committed Dec 1, 2021
1 parent c795939 commit 05651af
Show file tree
Hide file tree
Showing 7 changed files with 158 additions and 109 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,5 @@ node_modules
!/test/**/*.js
!/test/**/*.js.flow
!/.babelrc.js
/*.tgz
/*.zip
66 changes: 53 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ Supports:
- `--dry-run`
- `--pack-destination`
- `bundledDependencies`
- Automatically bundles all `dependencies` if `bundledDependencies` isn't present
(WARNING: this is accomplished by temporarily overwriting your `package.json`)

Doesn't currently support:

Expand All @@ -25,12 +27,6 @@ Doesn't currently support:
- `--workspace`
- `--workspaces`

# Usage

Doesn't bundle production `dependencies` by default!
Make sure to set [`bundledDependencies`](https://docs.npmjs.com/cli/v8/configuring-npm/package-json#bundleddependencies)
in your `package.json`. Put all production dependencies in there except ones provided by AWS, like `aws-sdk`.

# CLI

## `pack-lambda` - create a .zip file
Expand All @@ -41,9 +37,13 @@ npx --package @jcoreio/pack-lambda pack-lambda
pack .zip file for AWS Lambda
Options:
--version Show version number [boolean]
--help Show help [boolean]
--dryRun display contents without writing file [boolean] [default: false]
--version Show version number [boolean]
--help Show help [boolean]
--dry-run display contents without writing file
[boolean] [default: false]
--pack-destination directory in which to save .zip files [string]
--no-auto-bundled-dependencies disable bundling dependencies by default
[boolean]
```

### Example Output
Expand All @@ -70,11 +70,24 @@ bin/index.d.ts
es/bin/index.d.ts
es/index.d.ts
index.d.ts
=== Bundled Dependencies ===
@aws-sdk/client-s3
@aws-sdk/lib-storage
@babel/runtime
@npmcli/run-script
archiver
chalk
fs-extra
npm-package-arg
npm-packlist
yargs
@aws-sdk/types
=== Zip Details ===
name: @jcoreio/pack-lambda
version: 0.0.0-development
filename: jcoreio-pack-lambda-0.0.0-development.zip
total files: 15
bundled deps: 11
total files: 922
jcoreio-pack-lambda-0.0.0-development.zip
```

Expand All @@ -90,8 +103,10 @@ Positionals:
key S3 Key
Options:
--version Show version number [boolean]
--help Show help [boolean]
--version Show version number [boolean]
--help Show help [boolean]
--no-auto-bundled-dependencies disable bundling dependencies by default
[boolean]
```

### Example Output
Expand All @@ -118,11 +133,24 @@ bin/index.d.ts
es/bin/index.d.ts
es/index.d.ts
index.d.ts
=== Bundled Dependencies ===
@aws-sdk/client-s3
@aws-sdk/lib-storage
@babel/runtime
@npmcli/run-script
archiver
chalk
fs-extra
npm-package-arg
npm-packlist
yargs
@aws-sdk/types
=== Zip Details ===
name: @jcoreio/pack-lambda
version: 0.0.0-development
filename: jcoreio-pack-lambda-0.0.0-development.zip
total files: 15
bundled deps: 11
total files: 922
Uploading to s3://jcore-deploy/lambda/node/@jcoreio/pack-lambda/jcoreio-pack-lambda-0.0.0-development.zip....done
```

Expand Down Expand Up @@ -152,6 +180,10 @@ async function writeZip(options?: {
* If true, will output to stderr but not write to disk
*/
dryRun?: boolean
/**
* If false (or if package.json contains bundledDependencies), will not bundle dependencies by default
*/
autoBundledDependencies?: boolean
}): Promise<{
/**
* The files that were packed (relative to packageDir)
Expand Down Expand Up @@ -184,6 +216,10 @@ export async function uploadToS3(options: {
* The directory of the package to pack. Defaults to process.cwd()
*/
packageDir?: string
/**
* If false (or if package.json contains bundledDependencies), will not bundle dependencies by default
*/
autoBundledDependencies?: boolean
/**
* The S3 bucket to upload to
*/
Expand Down Expand Up @@ -233,6 +269,10 @@ async function createArchive(options: {
* The directory of the package to pack
*/
packageDir: string
/**
* If false (or if package.json contains bundledDependencies), will not bundle dependencies by default
*/
autoBundledDependencies?: boolean
}): Promise<{
/**
* The Archiver instance to stream to `pipe` to something else.
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,7 @@
"lint-staged": "^11.1.2",
"mocha": "^9.1.2",
"nyc": "^15.1.0",
"pacote": "^12.0.2",
"prettier": "^2.4.1",
"prettier-eslint": "^13.0.0",
"rimraf": "^3.0.2",
Expand All @@ -143,7 +144,6 @@
"fs-extra": "^10.0.0",
"npm-package-arg": "^8.1.5",
"npm-packlist": "^3.0.0",
"pacote": "^12.0.2",
"yargs": "^17.3.0"
}
}
Loading

0 comments on commit 05651af

Please sign in to comment.