minio / minio-js

MinIO Client SDK for Javascript
https://docs.min.io/docs/javascript-client-quickstart-guide.html
Apache License 2.0
928 stars 273 forks source link

feat: expose errors from entrypoint #1242

Closed aldy505 closed 9 months ago

aldy505 commented 9 months ago

Closes #1171

I originally wanted to expose it via package.json, so that we'd have something like:

  "exports": {
    ".": {
      "types": "./dist/main/minio.d.ts",
      "require": "./dist/main/minio.js",
      "default": "./dist/esm/minio.mjs"
    },
    "./errors": {
      "types": "./dist/main/errors.d.ts",
      "require": "./dist/main/errors.js",
      "default": "./dist/esm/errors.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
    },
    "./package.json": "./package.json"
  },

But that would mean two different lines on every MinIO import usage.

import * as Minio from "minio";
import { S3Error } from "minio/errors";

Instead of just

import * as Minio from "minio";

// Then use it later on as
try {
  // do stuff
} catch (error: unknown) {
  if (error instanceof Minio.S3Error) {
    // assert stuff
  }
}
aldy505 commented 9 months ago

I just realized that we're doing export * from 'notification.ts', yet it's not defined on the declaration file either. Should that be handled?

trim21 commented 9 months ago

notification.js is a js file and can't be exported in minio.d.ts, I have a working-in-progress PR for this https://github.com/minio/minio-js/pull/1226.

and it has been declared, instead of separated file but directly in minio.d.ts file.