Skip to content

Commit

Permalink
Merge branch 'main' into feat/ws
Browse files Browse the repository at this point in the history
  • Loading branch information
kettanaito committed May 8, 2024
2 parents 026f24f + 7cf34c1 commit a79d50a
Show file tree
Hide file tree
Showing 15 changed files with 395 additions and 188 deletions.
13 changes: 11 additions & 2 deletions config/scripts/validate-esm.js
Expand Up @@ -90,7 +90,7 @@ function validatePackageExports() {
console.log('✅ Validated package.json exports')
}

function validateExportConditions(pointer, conditions) {
function validateExportConditions(pointer, conditions, level = 0) {
if (typeof conditions === 'string') {
invariant(
fs.existsSync(conditions),
Expand All @@ -103,7 +103,7 @@ function validateExportConditions(pointer, conditions) {

const keys = Object.keys(conditions)

if (conditions[keys[0]] !== null) {
if (level == 0 && conditions[keys[0]] !== null) {
invariant(keys[0] === 'types', 'FS')
}

Expand All @@ -115,6 +115,15 @@ function validateExportConditions(pointer, conditions) {
return
}

if (typeof relativeExportPath === 'object') {
validateExportConditions(
`${pointer}.${key}`,
relativeExportPath,
level + 1,
)
return
}

const exportPath = fromRoot(relativeExportPath)
invariant(
fs.existsSync(exportPath),
Expand Down
20 changes: 16 additions & 4 deletions package.json
Expand Up @@ -14,22 +14,34 @@
"default": "./lib/core/index.js"
},
"./browser": {
"node": null,
"types": "./lib/browser/index.d.ts",
"browser": {
"require": "./lib/browser/index.js",
"import": "./lib/browser/index.mjs"
},
"node": null,
"require": "./lib/browser/index.js",
"import": "./lib/browser/index.mjs",
"default": "./lib/browser/index.js"
},
"./node": {
"browser": null,
"types": "./lib/node/index.d.ts",
"node": {
"require": "./lib/node/index.js",
"import": "./lib/node/index.mjs"
},
"browser": null,
"require": "./lib/node/index.js",
"import": "./lib/node/index.mjs",
"default": "./lib/node/index.mjs"
},
"./native": {
"browser": null,
"types": "./lib/native/index.d.ts",
"react-native": {
"require": "./lib/native/index.js",
"import": "./lib/native/index.mjs"
},
"browser": null,
"require": "./lib/native/index.js",
"import": "./lib/native/index.mjs",
"default": "./lib/native/index.js"
Expand Down Expand Up @@ -125,7 +137,7 @@
"@bundled-es-modules/statuses": "^1.0.1",
"@inquirer/confirm": "^3.0.0",
"@mswjs/cookies": "^1.1.0",
"@mswjs/interceptors": "^0.27.1",
"@mswjs/interceptors": "^0.29.0",
"@open-draft/until": "^2.1.0",
"@types/cookie": "^0.6.0",
"@types/statuses": "^2.0.4",
Expand Down
85 changes: 48 additions & 37 deletions pnpm-lock.yaml

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

9 changes: 6 additions & 3 deletions src/core/utils/internal/Disposable.ts
@@ -1,9 +1,12 @@
export type DisposableSubscription = () => Promise<void> | void
export type DisposableSubscription = () => void

export class Disposable {
protected subscriptions: Array<DisposableSubscription> = []

public async dispose() {
await Promise.all(this.subscriptions.map((subscription) => subscription()))
public dispose() {
let subscription: DisposableSubscription | undefined
while ((subscription = this.subscriptions.shift())) {
subscription()
}
}
}
21 changes: 21 additions & 0 deletions src/core/utils/internal/devUtils.test.ts
@@ -0,0 +1,21 @@
import { InternalError } from './devUtils'

describe(InternalError, () => {
it('creates an InternalError instance', () => {
const error = new InternalError('Message')

expect(error.name).toBe('InternalError')
expect(error.message).toBe('Message')
expect(error.toString()).toBe('InternalError: Message')
expect(error.stack).toMatch(/\w+/)
})

it('passes the identity check', () => {
const error = new InternalError('Message')
expect(error instanceof InternalError).toBe(true)
expect(error instanceof Error).toBe(true)

const extraneousError = new Error('Message')
expect(extraneousError).not.toBeInstanceOf(InternalError)
})
})
13 changes: 13 additions & 0 deletions src/core/utils/internal/devUtils.ts
Expand Up @@ -29,3 +29,16 @@ export const devUtils = {
warn,
error,
}

/**
* Internal error instance.
* Used to differentiate the library errors that must be forwarded
* to the user from the unhandled exceptions. Use this if you don't
* wish for the error to be coerced to a 500 fallback response.
*/
export class InternalError extends Error {
constructor(message: string) {
super(message)
this.name = 'InternalError'
}
}

0 comments on commit a79d50a

Please sign in to comment.