-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
build: bundle the exact version of sharp from the yarn.lock into the …
…lambda-tiler bundle
- Loading branch information
Showing
3 changed files
with
37 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
34 changes: 34 additions & 0 deletions
34
packages/lambda-tiler/scripts/create.deployment.package.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
#!/usr/bin/env node | ||
/** | ||
* Create a pacakge.json for the `dist` bundle based off the parent package.json | ||
* | ||
* This is needed as libsharp has to be "installed" into the dist node_modules so that lambda has access to sharp | ||
*/ | ||
const fs = require('fs'); | ||
|
||
const parentPackage = JSON.parse(fs.readFileSync('../package.json').toString()); | ||
|
||
// Find the exact version of a package in the yarn lock | ||
function getPackageVersion(packageName) { | ||
const parentLock = fs.readFileSync('../../../yarn.lock').toString().split('\n'); | ||
|
||
for (let i = 0; i < parentLock.length; i++) { | ||
if (parentLock[i].startsWith(packageName + '@')) { | ||
const versionList = parentLock[i + 1].trim(); | ||
if (!versionList.startsWith('version ')) throw new Error('Failed to find sharp version'); | ||
return JSON.parse(versionList.slice('version '.length)); | ||
} | ||
} | ||
} | ||
|
||
// the bundle is a commonjs module | ||
parentPackage.type = 'commonjs'; | ||
parentPackage.main = 'index.js'; | ||
parentPackage.dependencies = { sharp: getPackageVersion('sharp') }; | ||
|
||
// Clean up | ||
delete parentPackage.types; | ||
delete parentPackage.devDependencies; | ||
|
||
console.log('Installing dependencies', parentPackage.dependencies); | ||
fs.writeFileSync('./package.json', JSON.stringify(parentPackage, null, 2)); |