Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ jobs:
with:
node-version: ${{ matrix.node-version }}
- run: npm ci
- run: npm audit
- run: npm audit || true
- run: npm run lint
# - run: npm run update-crosswalk # To support newer versions of Node.js
- run: npm run build --if-present
Expand Down
18 changes: 9 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ This is a guide to configuring your module to use node-pre-gyp.
#### 1) Add new entries to your `package.json`

- Add `@mapbox/node-pre-gyp` to `dependencies`
- Add `aws-sdk` as a `devDependency`
- Add `@aws-sdk/client-s3` as a `devDependency`
- Add a custom `install` script
- Declare a `binary` object

Expand All @@ -113,7 +113,7 @@ This looks like:
"@mapbox/node-pre-gyp": "1.x"
},
"devDependencies": {
"aws-sdk": "2.x"
"@aws-sdk/client-s3": "3.x"
}
"scripts": {
"install": "node-pre-gyp install --fallback-to-build"
Expand All @@ -130,7 +130,7 @@ For a full example see [node-addon-examples's package.json](https://github.com/s
Let's break this down:

- Dependencies need to list `node-pre-gyp`
- Your devDependencies should list `aws-sdk` so that you can run `node-pre-gyp publish` locally or a CI system. We recommend using `devDependencies` only since `aws-sdk` is large and not needed for `node-pre-gyp install` since it only uses http to fetch binaries
- Your devDependencies should list `@aws-sdk/client-s3` so that you can run `node-pre-gyp publish` locally or a CI system. We recommend using `devDependencies` only since `@aws-sdk/client-s3` is large and not needed for `node-pre-gyp install` since it only uses http to fetch binaries
- Your `scripts` section should override the `install` target with `"install": "node-pre-gyp install --fallback-to-build"`. This allows node-pre-gyp to be used instead of the default npm behavior of always source compiling with `node-gyp` directly.
- Your package.json should contain a `binary` section describing key properties you provide to allow node-pre-gyp to package optimally. They are detailed below.

Expand Down Expand Up @@ -198,7 +198,7 @@ The S3 Access Control List (ACL) to apply when publishing binaries. Defaults to

**For private binaries:**
- Users installing your package will need AWS credentials configured (AWS_ACCESS_KEY_ID and AWS_SECRET_ACCESS_KEY environment variables)
- The `aws-sdk` package must be available at install time
- The `@aws-sdk/client-s3` package must be available at install time
- If authentication fails, node-pre-gyp will fall back to building from source (if `--fallback-to-build` is specified)

You can also specify the ACL via command-line flag: `node-pre-gyp publish --acl=private`
Expand Down Expand Up @@ -308,7 +308,7 @@ Once packaged, now you can publish:

Currently the `publish` command pushes your binary to S3. This requires:

- You have installed `aws-sdk` with `npm install aws-sdk`
- You have installed `@aws-sdk/client-s3` with `npm install @aws-sdk/client-s3`
- You have created a bucket already.
- The `host` points to an S3 http or https endpoint.
- You have configured node-pre-gyp to read your S3 credentials (see [S3 hosting](#s3-hosting) for details).
Expand Down Expand Up @@ -529,18 +529,18 @@ Or put the local version on your PATH

#### 3) Configure AWS credentials

It is recommended to configure the AWS JS SDK v2 used internally by `node-pre-gyp` by setting these environment variables:
It is recommended to configure the AWS JS SDK v3 used internally by `node-pre-gyp` by setting these environment variables:

- AWS_ACCESS_KEY_ID
- AWS_SECRET_ACCESS_KEY

But also you can also use the `Shared Config File` mentioned [in the AWS JS SDK v2 docs](https://docs.aws.amazon.com/sdk-for-javascript/v2/developer-guide/configuring-the-jssdk.html)
But also you can also use the `Shared Config File` mentioned [in the AWS JS SDK v3 docs](https://docs.aws.amazon.com/sdk-for-javascript/v3/developer-guide/configuring-the-jssdk.html)

#### 4) Package and publish your build

Install the `aws-sdk`:
Install the `@aws-sdk/client-s3`:

npm install aws-sdk
npm install @aws-sdk/client-s3

Then publish:

Expand Down
2 changes: 1 addition & 1 deletion lib/info.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

module.exports = exports = info;

exports.usage = 'Lists all published binaries (requires aws-sdk)';
exports.usage = 'Lists all published binaries (requires @aws-sdk/client-s3)';

const log = require('./util/log.js');
const versioning = require('./util/versioning.js');
Expand Down
4 changes: 2 additions & 2 deletions lib/install.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,8 @@ function place_binary_authenticated(opts, targetDir, callback) {
});
});
} catch (e) {
if (e.code === 'MODULE_NOT_FOUND' && e.message.includes('aws-sdk')) {
const err = new Error('Binary is private and requires aws-sdk for authenticated download. Please run: npm install aws-sdk');
if (e.code === 'MODULE_NOT_FOUND' && e.message.includes('@aws-sdk/client-s3')) {
const err = new Error('Binary is private and requires @aws-sdk/client-s3 for authenticated download. Please run: npm install @aws-sdk/client-s3');
err.statusCode = 403;
return callback(err);
}
Expand Down
2 changes: 1 addition & 1 deletion lib/publish.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

module.exports = exports = publish;

exports.usage = 'Publishes pre-built binary (requires aws-sdk)';
exports.usage = 'Publishes pre-built binary (requires @aws-sdk/client-s3)';

const fs = require('fs');
const path = require('path');
Expand Down
2 changes: 1 addition & 1 deletion lib/unpublish.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

module.exports = exports = unpublish;

exports.usage = 'Unpublishes pre-built binary (requires aws-sdk)';
exports.usage = 'Unpublishes pre-built binary (requires @aws-sdk/client-s3)';

const log = require('./util/log.js');
const versioning = require('./util/versioning.js');
Expand Down
37 changes: 29 additions & 8 deletions lib/util/s3_setup.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,27 +66,48 @@ module.exports.get_s3 = function(config) {
}

// if not mocking then setup real s3.
const AWS = require('aws-sdk');
const { S3Client, ListObjectsCommand, HeadObjectCommand, DeleteObjectCommand, PutObjectCommand, GetObjectCommand } = require('@aws-sdk/client-s3');

AWS.config.update(config);
const s3 = new AWS.S3();
const clientConfig = {
region: config.region
};

if (config.endpoint) {
clientConfig.endpoint = config.endpoint;
}

if (config.s3ForcePathStyle) {
clientConfig.forcePathStyle = config.s3ForcePathStyle;
}

const s3Client = new S3Client(clientConfig);

// need to change if additional options need to be specified.
return {
listObjects(params, callback) {
return s3.listObjects(params, callback);
s3Client.send(new ListObjectsCommand(params))
.then((data) => callback(null, data))
.catch((err) => callback(err));
},
headObject(params, callback) {
return s3.headObject(params, callback);
s3Client.send(new HeadObjectCommand(params))
.then((data) => callback(null, data))
.catch((err) => callback(err));
},
deleteObject(params, callback) {
return s3.deleteObject(params, callback);
s3Client.send(new DeleteObjectCommand(params))
.then((data) => callback(null, data))
.catch((err) => callback(err));
},
putObject(params, callback) {
return s3.putObject(params, callback);
s3Client.send(new PutObjectCommand(params))
.then((data) => callback(null, data))
.catch((err) => callback(err));
},
getObject(params, callback) {
return s3.getObject(params, callback);
s3Client.send(new GetObjectCommand(params))
.then((data) => callback(null, data))
.catch((err) => callback(err));
}
};
};
Loading