Skip to content

Commit

Permalink
docs: specify import usage with TypeScript
Browse files Browse the repository at this point in the history
  • Loading branch information
merlinnot committed May 31, 2021
1 parent 64a7dc4 commit 37bd7c8
Show file tree
Hide file tree
Showing 8 changed files with 9,403 additions and 7,411 deletions.
32 changes: 32 additions & 0 deletions README.md
Expand Up @@ -16,6 +16,38 @@ A collection of Firestore utilities.
npm install @merlinnot/firestore-extensions
```

### TypeScript

This library defines
[multiple entry points](https://nodejs.org/api/packages.html#packages_package_entry_points),
which is
[not yet supported](https://github.com/microsoft/TypeScript/issues/33079) by
TypeScript. To work around this limitation, either:

1. Manually specify import paths (choose `cjs` or `mjs` in your path depending
on which flavor you use).

```json
{
"compilerOptions": {
"paths": {
"@merlinnot/firestore-extensions/ids": [
"./node_modules/@merlinnot/firestore-extensions/lib/cjs/ids/index.js"
],
"@merlinnot/firestore-extensions/subscriptions": [
"./node_modules/@merlinnot/firestore-extensions/lib/cjs/subscriptions/index.js"
]
}
}
}
```

2. Use only the main entry point.

```typescript
import { ids, subscriptions } from '@merlinnot/firestore-extensions'`
```

### Usage

#### Firestore ID to UUID converter
Expand Down
2 changes: 1 addition & 1 deletion __mocks__/@google-cloud/firestore/index.ts
@@ -1,6 +1,6 @@
/* eslint-disable immutable/no-mutation, max-classes-per-file */

import * as firestore from '@google-cloud/firestore';
import firestore from '@google-cloud/firestore';
import { credentials } from '@grpc/grpc-js';

import {
Expand Down
6 changes: 6 additions & 0 deletions babel.config.cjs
@@ -0,0 +1,6 @@
module.exports = {
presets: [
['@babel/preset-env', { targets: { node: 'current' } }],
'@babel/preset-typescript',
],
};
9 changes: 0 additions & 9 deletions jest.config.ts
Expand Up @@ -17,20 +17,11 @@ const configuration: Config.InitialOptions = {
},
},
forceExit: true,
globals: {
'ts-jest': {
diagnostics: false,
isolatedModules: true,
tsconfig: 'tsconfig.json',
},
},
logHeapUsage: true,
preset: 'ts-jest',
restoreMocks: true,
roots: ['<rootDir>/__mocks__', '<rootDir>/src'],
setupFilesAfterEnv: ['<rootDir>/test/setup.ts'],
testEnvironment: 'node',
testRunner: 'jest-circus/runner',
};

export default configuration;

0 comments on commit 37bd7c8

Please sign in to comment.