Skip to content

Commit 14d583d

Browse files
authored
Update export structure, change bundler, move tests to ESM (#749)
* Put Cordova- and React Native-specific code into separate folders * First attempt at using new `exports` structure in `package.json` * Unify exported interface between browser and node variant * Disable unused imports * Rename files to better match their exported classes * Add exports for node-specific APIs * Turn node demo into ESM * Move tests to ESM and build using rollup Browserify does not support `exports` in `package.json`, so we replace it with Rollup. In addition, the tests are moved to ESM. * Let bundle be generated by rollup as well * Bundle TypeScript directly to use in sourcemaps * Explicitly change case of NoopUrlStorage file * Avoid resolving ESM types to CJS files * Add fallback methods for bundler that don't support `exports` * Add `publint` and `arethetypeswrong` as linters
1 parent 54f4a7c commit 14d583d

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

43 files changed

+881
-1168
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,4 @@ lib.esm
66
dist
77
.DS_Store
88
yarn-error.log
9+
tus-js-client-*.tgz

biome.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,8 @@
2828
"correctness": {
2929
"noNewSymbol": "error",
3030
"noUndeclaredVariables": "error",
31-
"noUnusedVariables": "error"
31+
"noUnusedVariables": "error",
32+
"noUnusedImports": "error"
3233
}
3334
}
3435
},

demos/nodejs/index.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
const fs = require('fs')
2-
const tus = require('../..')
1+
import { createReadStream } from 'fs'
2+
import { Upload } from 'tus-js-client'
33

4-
const path = `${__dirname}/../../README.md`
5-
const file = fs.createReadStream(path)
4+
const path = `${import.meta.dirname}/../../README.md`
5+
const file = createReadStream(path)
66

77
const options = {
88
endpoint: 'https://tusd.tusdemo.net/files/',
@@ -24,5 +24,5 @@ const options = {
2424
},
2525
}
2626

27-
const upload = new tus.Upload(file, options)
27+
const upload = new Upload(file, options)
2828
upload.start()
File renamed without changes.
File renamed without changes.

lib/browser/fileReader.ts renamed to lib/browser/BrowserFileReader.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import { isReactNativeFile, isReactNativePlatform } from './isReactNative.js'
2-
import { uriToBlob } from './uriToBlob.js'
1+
import { isReactNativeFile, isReactNativePlatform } from '../reactnative/isReactNative.js'
2+
import { uriToBlob } from '../reactnative/uriToBlob.js'
33

44
import type { FileReader, FileSource, UploadInput } from '../options.js'
55
import { BlobFileSource } from './sources/BlobFileSource.js'
File renamed without changes.

lib/browser/fileSignature.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import type { ReactNativeFile, UploadInput, UploadOptions } from '../options.js'
2-
import { isReactNativeFile, isReactNativePlatform } from './isReactNative.js'
2+
import { isReactNativeFile, isReactNativePlatform } from '../reactnative/isReactNative.js'
33

44
/**
55
* Generate a fingerprint for a file which will be used the store the endpoint

lib/browser/index.ts

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1-
import { DetailedError } from '../error.js'
1+
import { DetailedError } from '../DetailedError.js'
2+
import { NoopUrlStorage } from '../NoopUrlStorage.js'
23
import { enableDebugLog } from '../logger.js'
3-
import { NoopUrlStorage } from '../noopUrlStorage.js'
44
import type { UploadInput, UploadOptions } from '../options.js'
55
import { BaseUpload, defaultOptions as baseDefaultOptions, terminate } from '../upload.js'
66

7-
import { BrowserFileReader } from './fileReader.js'
7+
import { BrowserFileReader } from './BrowserFileReader.js'
8+
import { XHRHttpStack as DefaultHttpStack } from './XHRHttpStack.js'
89
import { fingerprint } from './fileSignature.js'
9-
import { XHRHttpStack as DefaultHttpStack } from './httpStack.js'
1010
import { WebStorageUrlStorage, canStoreURLs } from './urlStorage.js'
1111

1212
const defaultOptions = {
@@ -35,12 +35,6 @@ const isSupported =
3535
typeof Blob === 'function' &&
3636
typeof Blob.prototype.slice === 'function'
3737

38-
export {
39-
Upload,
40-
canStoreURLs,
41-
defaultOptions,
42-
isSupported,
43-
enableDebugLog,
44-
DefaultHttpStack,
45-
DetailedError,
46-
}
38+
// Note: The exported interface must be the same as in lib/node/index.ts.
39+
// Any changes should be reflected in both files.
40+
export { Upload, defaultOptions, isSupported, canStoreURLs, enableDebugLog, DetailedError }

lib/browser/sources/BlobFileSource.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1+
import { isCordova } from '../../cordova/isCordova.js'
2+
import { readAsByteArray } from '../../cordova/readAsByteArray.js'
13
import type { FileSource, SliceResult } from '../../options.js'
2-
import { isCordova } from './isCordova.js'
3-
import { readAsByteArray } from './readAsByteArray.js'
44

55
export class BlobFileSource implements FileSource {
66
_file: Blob

0 commit comments

Comments
 (0)