Skip to content

Commit

Permalink
fix: include timestamp if version ends in -development
Browse files Browse the repository at this point in the history
BREAKING CHANGE: now adds timestamp to filename if package version ends in -development
  • Loading branch information
jedwards1211 committed Dec 5, 2021
1 parent 74bea41 commit fb767db
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 14 deletions.
15 changes: 11 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,13 @@ Doesn't currently support:
- `--workspace`
- `--workspaces`

# Filenames

The default filename is `[name]-[version].zip` where `[name]` is the package name (scoped names like `@foo/bar`
get converted to `foo-bar`) and `[version]` is the package version. If the version ends in `-development`,
a timestamp will be appened like `[name]-[version]-[timestamp].zip` so that the filename is always different
and a CloudFormation stack update will always update the Lambda code.

# Configuration

You can add the following config to `package.json`:
Expand Down Expand Up @@ -100,10 +107,10 @@ yargs
=== Zip Details ===
name: @jcoreio/pack-lambda
version: 0.0.0-development
filename: jcoreio-pack-lambda-0.0.0-development.zip
filename: jcoreio-pack-lambda-0.0.0-development-20211205184649022.zip
bundled deps: 11
total files: 922
jcoreio-pack-lambda-0.0.0-development.zip
jcoreio-pack-lambda-0.0.0-development-20211205184649022.zip
```

## `upload` - upload to S3
Expand Down Expand Up @@ -161,10 +168,10 @@ yargs
=== Zip Details ===
name: @jcoreio/pack-lambda
version: 0.0.0-development
filename: jcoreio-pack-lambda-0.0.0-development.zip
filename: jcoreio-pack-lambda-0.0.0-development-20211205184649022.zip
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
Uploading to s3://jcore-deploy/lambda/node/@jcoreio/pack-lambda/jcoreio-pack-lambda-0.0.0-development-20211205184649022.zip....done
```

# Node.js API
Expand Down
12 changes: 10 additions & 2 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,11 @@ export async function createArchive({
excludeDependencies,
})

const filename = `${manifest.name}-${manifest.version}.zip`
const filename = `${manifest.name}-${manifest.version}${
manifest.version.endsWith('-development')
? `-${new Date().toISOString().replace(/\D/g, '')}`
: ''
}.zip`
.replace(/^@/, '')
.replace(/\//, '-')

Expand Down Expand Up @@ -76,7 +80,11 @@ function printDetails({
if (!file.startsWith('node_modules/')) console.error(file)
}
if (bundled.length) {
console.error(chalk.magenta('=== Bundled Dependencies ==='))
console.error(
chalk.magenta(
'=== Bundled Dependencies (transitive deps included but not shown) ==='
)
)
for (const dep of bundled) {
console.error(dep)
}
Expand Down
22 changes: 14 additions & 8 deletions test/index.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import fs from 'fs-extra'
import packageJson from '../package.json'
import { expect } from 'chai'
import runScript from '@npmcli/run-script'
import Path from 'path'
import StreamZip from 'node-stream-zip'

describe('writeZip', function () {
Expand All @@ -17,13 +16,18 @@ describe('writeZip', function () {
path: process.cwd(),
pkg: packageJson,
})
const filename = `${packageJson.name}-${packageJson.version}.zip`
.replace(/^@/, '')
.replace(/\//, '-')

await fs.remove(filename)
const result = await writeZip()
expect(result.filename).to.equal(Path.resolve(filename))
const { filename } = result
expect(filename).to.match(
new RegExp(
`${packageJson.name
.replace(/^@/, '')
.replace(/\//, '-')}-${packageJson.version.replace(
/\./g,
'\\.'
)}-\\d{17}.zip`
)
)
expect(result.files).to.contain.members([
'index.js',
'index.d.ts',
Expand All @@ -43,7 +47,9 @@ describe('writeZip', function () {
'index.js',
'index.d.ts',
'bin/index.js',
'node_modules/npm-packlist/package.json',
'node_modules/npm-packlist',
'node_modules/@aws-sdk/lib-storage',
])
expect(entries).not.to.contain.members(['node_modules/@aws-sdk/client-ec2'])
})
})

0 comments on commit fb767db

Please sign in to comment.