Skip to content

Commit

Permalink
Strip sharp dep from bundle (#19)
Browse files Browse the repository at this point in the history
* Remove sharp dep from build since it's provided by lambda layer

* fix deps
  • Loading branch information
revmischa authored Nov 10, 2022
1 parent d127105 commit e9cddef
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 14 deletions.
16 changes: 8 additions & 8 deletions .projen/deps.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion .projenrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,13 @@ const project = new awscdk.AwsCdkConstructLibrary({
'@types/fs-extra',
'@types/micromatch',
'@types/aws-lambda',
'esbuild',
'aws-lambda',
'serverless-http',
'jszip',
'glob',
] /* Runtime dependencies of this module. */,
devDeps: ['aws-sdk', '[email protected]'] /* Build dependencies for this module. */,
peerDeps: ['esbuild'],

// do not generate sample test files
sampleCode: false,
Expand Down
8 changes: 5 additions & 3 deletions package.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

19 changes: 19 additions & 0 deletions src/NextjsBuild.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { Token } from 'aws-cdk-lib';
import { Construct } from 'constructs';
import * as spawn from 'cross-spawn';
import * as fs from 'fs-extra';
import * as glob from 'glob';
import { listDirectory } from './NextjsAssetsDeployment';
import { CompressionLevel, NextjsBaseProps } from './NextjsBase';

Expand Down Expand Up @@ -121,6 +122,24 @@ export class NextjsBuild extends Construct {
if (buildResult.status !== 0) {
throw new Error('The app "build" script failed.');
}

// cleanup
// delete the `sharp` module since it's provided by the lambda layer
const sharpPathNpm = path.join(this._getNextStandaloneDir(), 'node_modules', 'sharp'); // npm/yarn
if (fs.existsSync(sharpPathNpm)) {
// delete the sharp folder
if (!this.props.quiet) console.debug('├ Deleting sharp module from', sharpPathNpm);
fs.removeSync(sharpPathNpm);
}
// is there a `[email protected]` folder in the `node_modules/.pnpm` folder?
const pnpmModulesDir = path.join(this._getNextStandaloneDir(), 'node_modules', '.pnpm'); // pnpm
// get glob pattern for sharp version
const matches = glob.sync(path.join(pnpmModulesDir, 'sharp@*'));
if (matches.length > 0) {
// delete the sharp folder
if (!this.props.quiet) console.debug('├ Deleting sharp module from', matches[0]);
fs.removeSync(matches[0]);
}
}

// getNextBuildId() {
Expand Down
4 changes: 2 additions & 2 deletions yarn.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit e9cddef

Please sign in to comment.