Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fixes #44 #46

Closed
wants to merge 2 commits into from
Closed
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
16 changes: 8 additions & 8 deletions src/s3_plugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -102,22 +102,22 @@ module.exports = class S3Plugin {
let dPath = addSeperatorToPath(this.options.directory)

this.getAllFilesRecursive(dPath)
.then((files) => this.handleFiles(files, cb))
.then((files) => this.handleFiles(files, compilation))
.then(() => cb())
.catch(e => this.handleErrors(e, compilation, cb))
} else {
this.getAssetFiles(compilation)
.then((files) => this.handleFiles(files))
.then((files) => this.handleFiles(files, compilation))
.then(() => cb())
.catch(e => this.handleErrors(e, compilation, cb))
}
})
}

handleFiles(files) {
handleFiles(files, compilation) {
return this.changeUrls(files)
.then((files) => this.filterAllowedFiles(files))
.then((files) => this.uploadFiles(files))
.then((files) => this.uploadFiles(files, compilation))
.then(() => this.invalidateCloudfront())
}

Expand Down Expand Up @@ -229,8 +229,8 @@ module.exports = class S3Plugin {
this.isConnected = true
}

transformBasePath() {
return Promise.resolve(this.basePathTransform(this.options.basePath))
transformBasePath(compilation) {
return Promise.resolve(this.basePathTransform(this.options.basePath, compilation))
.then(addTrailingS3Sep)
.then(nPath => this.options.basePath = nPath)
}
Expand Down Expand Up @@ -268,8 +268,8 @@ module.exports = class S3Plugin {
})
}

uploadFiles(files = []) {
return this.transformBasePath()
uploadFiles(files = [], compilation) {
return this.transformBasePath(compilation)
.then(() => {
var uploadFiles = files.map(file => this.uploadFile(file.name, file.path))

Expand Down
10 changes: 8 additions & 2 deletions test/upload_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,10 @@ describe('S3 Webpack Upload', function() {
BASE_PATH = 'test'
var s3Config = {
basePath: BASE_PATH,
basePathTransform(basePath) {
basePathTransform(basePath, compilation) {
assert.isString(basePath);
assert.isObject(compilation);

return Promise.resolve(basePath + NAME_PREFIX)
}
}
Expand All @@ -117,7 +120,10 @@ describe('S3 Webpack Upload', function() {
BASE_PATH = 'test'
var s3Config = {
basePath: BASE_PATH,
basePathTransform(basePath) {
basePathTransform(basePath, compilation) {
assert.isString(basePath);
assert.isObject(compilation);

return basePath + NAME_PREFIX
}
}
Expand Down