Skip to content

Commit

Permalink
merge
Browse files Browse the repository at this point in the history
  • Loading branch information
trim21 committed Jul 17, 2023
2 parents 68650a8 + f6a34ca commit 6b15bb7
Show file tree
Hide file tree
Showing 22 changed files with 1,819 additions and 1,168 deletions.
1 change: 1 addition & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ module.exports = {
},
],
'@typescript-eslint/no-explicit-any': ['warn'],
'@typescript-eslint/ban-ts-comment': 0,

'@typescript-eslint/prefer-optional-chain': 0, // ["warn"],
'no-empty-function': 0,
Expand Down
2 changes: 2 additions & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
/dist/
*.md
!docs/API.md
!README.md
/.github/workflows/
254 changes: 128 additions & 126 deletions README.md

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion README_zh_CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ mc ls play/europetrip/
* [list-objects-v2.js](https://github.com/minio/minio-js/blob/master/examples/list-objects-v2.js)
* [bucket-exists.js](https://github.com/minio/minio-js/blob/master/examples/bucket-exists.js)
* [make-bucket.js](https://github.com/minio/minio-js/blob/master/examples/make-bucket.js)
* [remove-bucket.js](https://github.com/minio/minio-js/blob/master/examples/remove-bucket.js)
* [remove-bucket.mjs](https://github.com/minio/minio-js/blob/master/examples/remove-bucket.mjs)
* [list-incomplete-uploads.js](https://github.com/minio/minio-js/blob/master/examples/list-incomplete-uploads.js)

#### 完整示例 : 操作文件对象
Expand Down
34 changes: 19 additions & 15 deletions build.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ const extMap = { cjs: '.js', esm: '.mjs' }
async function buildFiles({ files, module, outDir }) {
console.log(`building for ${module}`)
await promisify(exec)(`npx tsc --outDir ${outDir}`, { stdio: 'inherit' })
const ext = extMap[module]

const opt = options(module)
for (const file of files) {
Expand All @@ -69,7 +70,7 @@ async function buildFiles({ files, module, outDir }) {
const outDirPath = path.dirname(outFilePath)

await fsp.mkdir(outDirPath, { recursive: true })
const distCodePath = outFilePath.replace(/\.[tj]s$/g, extMap[module])
const distCodePath = outFilePath.replace(/\.[tj]s$/g, ext)

if (file.path.endsWith('.d.ts')) {
await fsp.copyFile(file.path, outFilePath)
Expand All @@ -88,19 +89,8 @@ async function buildFiles({ files, module, outDir }) {
throw e
}
}
}

async function main() {
await fsp.rm('dist', { recursive: true, force: true })

const entries = fsWalk.walkSync('src/')

await Promise.all([
buildFiles({ files: entries, module: 'cjs', outDir: './dist/main/' }),
buildFiles({ files: entries, module: 'esm', outDir: './dist/esm/' }),
])

for (const file of fsWalk.walkSync('dist/esm/')) {
for (const file of fsWalk.walkSync(outDir)) {
if (file.dirent.isDirectory()) {
continue
}
Expand All @@ -114,14 +104,28 @@ async function main() {
const mts = babel.transformSync(fileContent, {
filename: file.path,
sourceMaps: true,
plugins: [['@babel/plugin-syntax-typescript'], ['replace-import-extension', { extMapping: { '.ts': '.mjs' } }]],
plugins: [['@babel/plugin-syntax-typescript'], ['replace-import-extension', { extMapping: { '.ts': ext } }]],
})

await fsp.unlink(file.path)

const outFilePath = file.path.slice(0, file.path.length - '.d.ts'.length) + '.d.mts'
let outFilePath = file.path.slice(0, file.path.length - '.d.ts'.length) + '.d.ts'
if (module === 'esm') {
outFilePath = file.path.slice(0, file.path.length - '.d.ts'.length) + '.d.mts'
}
await fsp.writeFile(outFilePath, mts.code)
}
}

async function main() {
await fsp.rm('dist', { recursive: true, force: true })

const entries = fsWalk.walkSync('src/')

await Promise.all([
buildFiles({ files: entries, module: 'cjs', outDir: './dist/main/' }),
buildFiles({ files: entries, module: 'esm', outDir: './dist/esm/' }),
])
}

await main()
1,434 changes: 727 additions & 707 deletions docs/API.md

Large diffs are not rendered by default.

10 changes: 5 additions & 5 deletions docs/zh_CN/API.md
Original file line number Diff line number Diff line change
Expand Up @@ -631,12 +631,12 @@ __示例__


```js
minioClient.removeObject('mybucket', 'photo.jpg', function(err) {
if (err) {
return console.log('Unable to remove object', err)
}
try {
await minioClient.removeObject('mybucket', 'photo.jpg')
console.log('Removed the object')
})
} catch (err) {
console.log('Unable to remove object', err)
}
```

<a name="removeIncompleteUpload"></a>
Expand Down
15 changes: 10 additions & 5 deletions examples/list-buckets.js → examples/list-buckets.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -14,18 +14,23 @@
* limitations under the License.
*/

// Using the top-level await as we use .mjs extension
// run it like: node list-buckets.mjs

// Note: YOUR-ACCESSKEYID and YOUR-SECRETACCESSKEY are dummy values, please
// replace them with original values.

var Minio = require('minio')
import * as Minio from 'minio'

var s3Client = new Minio.Client({
endPoint: 's3.amazonaws.com',
accessKey: 'YOUR-ACCESSKEYID',
secretKey: 'YOUR-SECRETACCESSKEY',
})

s3Client.listBuckets(function (e, buckets) {
if (e) return console.log(e)
console.log('buckets :', buckets)
})
try {
const buckets = await s3Client.listBuckets()
console.log('Success', buckets)
} catch (err) {
console.log(err.message)
}
14 changes: 7 additions & 7 deletions examples/remove-bucket.js → examples/remove-bucket.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -17,19 +17,19 @@
// Note: YOUR-ACCESSKEYID, YOUR-SECRETACCESSKEY and my-bucketname
// are dummy values, please replace them with original values.

var Minio = require('minio')
import * as Minio from 'minio'

var s3Client = new Minio.Client({
const s3Client = new Minio.Client({
endPoint: 's3.amazonaws.com',
accessKey: 'YOUR-ACCESSKEYID',
secretKey: 'YOUR-SECRETACCESSKEY',
})

// Remove a bucket name my-bucketname.
// This operation will only work if your bucket is empty.
s3Client.removeBucket('my-bucketname', function (e) {
if (e) {
return console.log(e)
}
try {
await s3Client.removeBucket('my-bucketname')
console.log('Success')
})
} catch (e) {
return console.log(e)
}
10 changes: 5 additions & 5 deletions package-lock.json

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

6 changes: 1 addition & 5 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
{
"name": "minio",
"version": "7.1.1",
"version": "7.1.2",
"description": "S3 Compatible Cloud Storage client",
"main": "./dist/main/minio.js",
"module": "./dist/esm/minio.mjs",
"types": "./dist/main/minio.d.ts",
"scripts": {
"prepare": "husky install",
"tsc": "tsc",
Expand All @@ -21,19 +20,16 @@
},
"exports": {
".": {
"types": "./dist/main/minio.d.ts",
"require": "./dist/main/minio.js",
"default": "./dist/esm/minio.mjs"
},
"./dist/main/internal/*": null,
"./dist/main/*": {
"types": "./dist/main/*",
"require": "./dist/main/*",
"default": null
},
"./dist/esm/internal/*": null,
"./dist/esm/*": {
"types": "./dist/esm/*",
"import": "./dist/esm/*",
"default": null
},
Expand Down
18 changes: 18 additions & 0 deletions src/internal/callbackify.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
// wrapper an async function that support callback style API.
// It will preserve 'this'.
export function callbackify(fn) {
return function () {
const args = [...arguments]
const callback = args.pop()

// If the last argument is a function, assume it's the callback.
if (typeof callback === 'function') {
return fn.apply(this, args).then(
(result) => callback(null, result),
(err) => callback(err),
)
}

return fn.apply(this, arguments)
}
}
Loading

0 comments on commit 6b15bb7

Please sign in to comment.