Skip to content

feat: support web-native streams for read/write methods #2849

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

lionel-rowe
Copy link

Fixes #1228
Fixes #2753

Summary

Add support for read(<web-native ReadableStream instance>) and write(<web-native WritableStream instance>). Both have excellent support in modern browsers and are also implemented in NodeJS, Deno, and Bun.

Test plan

See spec/unit/xlsx/write-writable-stream.spec.js and changes to spec/typescript/exceljs.spec.ts.

Related to source code (for typings update)

N/A (updated typings are reflected in diffs to runtime code + tests).

import _ExcelJS from '../../index';
import type * as ExcelJSModule from '../../exceljs';

const ExcelJS = _ExcelJS as unknown as typeof ExcelJSModule;
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Type checking wasn't currently being picked up by ts-node due to ../../index resolving to the untyped index files rather than ../../index.d.ts.

https://stackoverflow.com/questions/62490423/consume-index-d-ts-declaration-file-in-source-code

It looks like you have a collision in your module resolution.

If you have a file called index.ts, then index.d.ts won't be automatically imported.

TypeScript will automatically import .d.ts files, UNLESS their name collides with other files, where the rules for what files will collide are somewhat described here: https://www.typescriptlang.org/docs/handbook/module-resolution.html .

For that reason, I've renamed index.d.ts to exceljs.d.ts (and updated the corresponding package.json fields etc).

It still needs to be imported in this weird way for the test though. Possibly there's a better fix, but I couldn't figure one out.

@@ -24,17 +27,21 @@ describe('typescript', () => {
ws.getCell('A1').value = 7;

const wb2 = new ExcelJS.Workbook();
const stream = wb2.xlsx.createInputStream();
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This test was previously failing due to removal of createInputStream, so I've overwritten the existing test case rather than adding a new one.

],
"scripts": {
"test": "npm run test:full",
"test:es5": "export EXCEL_BUILD=es5 && npm run test:full",
"test:full": "npm run build && npm run test:unit && npm run test:integration && npm run test:end-to-end && npm run test:jasmine",
"test:full": "npm run build && npm run test:unit && npm run test:integration && npm run test:end-to-end && npm run test:jasmine && npm run test:typescript",
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added TS tests to test:full, which should now work as they no longer contain a failing test case.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Q] What's the status to support Web Stream ? Support Stream writing in browser
1 participant
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy