Skip to content

More improvements #1190

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

Merged
merged 8 commits into from
Mar 31, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
68 changes: 68 additions & 0 deletions .github/workflows/exceljs.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
name: ExcelJS

on:
push:
branches: [ master ]
pull_request:
branches: [ '**' ]

jobs:
test:
name: Node v${{ matrix.node-version }} on ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
# https://github.com/actions/setup-node/issues/27
node-version: [8.17.0, 10.x, 12.x, 13.x]
os: [ubuntu-latest, macOS-latest, windows-latest]
runs-on: ${{ matrix.os }}

steps:
- name: Set git config
shell: bash
run: |
git config --global core.autocrlf false
git config --global core.symlinks true
if: runner.os == 'Windows'
- uses: actions/checkout@v2
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v1
with:
node-version: ${{ matrix.node-version }}
- name: Create the npm cache directory
run: mkdir npm-cache && npm config set cache ./npm-cache --global
- name: Cache node modules
uses: actions/cache@v1
with:
path: ./npm-cache
key: v1-${{ runner.os }}-node-${{ matrix.node-version }}-npm-${{ hashFiles('**/package.json') }}
restore-keys: |
v1-${{ runner.os }}-node-${{ matrix.node-version }}-npm-
- run: npm install
- run: npm test
env:
CI: true

typescript:
name: Ensure typescript compatibility
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v2
- uses: actions/setup-node@v1
with:
node-version: 12.x
- name: Create the npm cache directory
run: mkdir npm-cache && npm config set cache ./npm-cache --global
- name: Cache node modules
uses: actions/cache@v1
with:
path: ./npm-cache
key: v1-npm-${{ hashFiles('**/package.json') }}
restore-keys: |
v1-npm-
- run: npm install
- run: npm install typescript
- run: tsc index.d.ts
env:
CI: true
31 changes: 0 additions & 31 deletions .github/workflows/nodejs.yml

This file was deleted.

11 changes: 0 additions & 11 deletions .travis.yml

This file was deleted.

60 changes: 32 additions & 28 deletions benchmark.js
Original file line number Diff line number Diff line change
@@ -1,39 +1,43 @@
const fs = require('fs');
const path = require('path');
/* eslint-disable no-console */
const ExcelJS = require('./lib/exceljs.nodejs.js');

const runs = 3;

runProfiling('huge xlsx file', () => {
return new Promise((resolve, reject) => {
// Data taken from http://eforexcel.com/wp/downloads-18-sample-csv-files-data-sets-for-testing-sales/
const stream = fs.createReadStream(path.join(__dirname, 'spec/integration/data/huge.xlsx'));
(async () => {
try {
await runProfiling('huge xlsx file streams', () => {
return new Promise((resolve, reject) => {
// Data taken from http://eforexcel.com/wp/downloads-18-sample-csv-files-data-sets-for-testing-sales/
const wb = new ExcelJS.stream.xlsx.WorkbookReader();
const options = {
entries: 'emit',
sharedStrings: 'cache',
worksheets: 'emit',
};
wb.read('./spec/integration/data/huge.xlsx', options);

const wb = new ExcelJS.stream.xlsx.WorkbookReader();
wb.read(stream, {
entries: 'emit',
sharedStrings: 'cache',
worksheets: 'emit',
});
let worksheetCount = 0;
let rowCount = 0;
wb.on('worksheet', worksheet => {
worksheetCount += 1;
console.log(`Reading worksheet ${worksheetCount}`);
worksheet.on('row', () => {
rowCount += 1;
if (rowCount % 50000 === 0) console.log(`Reading row ${rowCount}`);
});
});

let worksheetCount = 0;
let rowCount = 0;
wb.on('worksheet', worksheet => {
worksheetCount += 1;
console.log(`Reading worksheet ${worksheetCount}`);
worksheet.on('row', () => {
rowCount += 1;
if (rowCount % 50000 === 0) console.log(`Reading row ${rowCount}`);
wb.on('end', () => {
console.log(`Processed ${worksheetCount} worksheets and ${rowCount} rows`);
resolve();
});
wb.on('error', reject);
});
});

wb.on('end', () => {
console.log(`Processed ${worksheetCount} worksheets and ${rowCount} rows`);
resolve();
});
wb.on('error', reject);
});
});
} catch (err) {
console.error(err);
}
})();

async function runProfiling(name, run) {
console.log('');
Expand Down
2 changes: 1 addition & 1 deletion lib/stream/xlsx/workbook-reader.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class WorkbookReader extends EventEmitter {
constructor(options) {
super();

this.options = options = options || {};
this.options = options || {};

this.styles = new StyleManager();
this.styles.init();
Expand Down
5 changes: 2 additions & 3 deletions lib/xlsx/xform/sheet/worksheet-xform.js
Original file line number Diff line number Diff line change
Expand Up @@ -229,9 +229,8 @@ class WorkSheetXform extends BaseXform {
},
range: medium.range,
};
let rIdHyperLink = drawingRelsHash[drawing.rels.length];
if (medium.hyperlinks && medium.hyperlinks.hyperlink) {
rIdHyperLink = nextRid(drawing.rels);
const rIdHyperLink = nextRid(drawing.rels);
drawingRelsHash[drawing.rels.length] = rIdHyperLink;
anchor.picture.hyperlinks = {
tooltip: medium.hyperlinks.tooltip,
Expand Down Expand Up @@ -316,7 +315,7 @@ class WorkSheetXform extends BaseXform {
this.map.sheetProtection.render(xmlStream, sheetProtectionModel); // Note: must be after sheetData and before autoFilter
this.map.autoFilter.render(xmlStream, model.autoFilter);
this.map.mergeCells.render(xmlStream, model.mergeCells);
this.map.conditionalFormatting.render(xmlStream, model.conditionalFormattings);// Note: must be before dataValidations
this.map.conditionalFormatting.render(xmlStream, model.conditionalFormattings); // Note: must be before dataValidations
this.map.dataValidations.render(xmlStream, model.dataValidations);

// For some reason hyperlinks have to be after the data validations
Expand Down
41 changes: 21 additions & 20 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,15 @@
],
"scripts": {
"test": "npm run test:full",
"test:full": "npm run test:unit && npm run test:integration && npm run test:end-to-end && npm run test:browser",
"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:all": "npm run test:native && npm run test:es5",
"test:native": "npm run test:full",
"test:es5": "export EXCEL_BUILD=es5 && npm run test:full",
"test:unit": "mocha --require spec/config/setup --require spec/config/setup-unit spec/unit --recursive",
"test:integration": "mocha --require spec/config/setup spec/integration --recursive",
"test:end-to-end": "mocha --require spec/config/setup spec/end-to-end --recursive",
"test:browser": "if [ ! -f .disable-test-browser ]; then npm run test:jasmine; fi",
"test:jasmine": "npm run build && grunt jasmine",
"test:browser": "if [ ! -f .disable-test-browser ]; then npm run build && npm run test:jasmine; fi",
"test:jasmine": "grunt jasmine",
"test:unit:es5": "export EXCEL_BUILD=es5 && npm run test:unit",
"test:integration:es5": "export EXCEL_BUILD=es5 && npm run test:integration",
"test:end-to-end:es5": "export EXCEL_BUILD=es5 && npm run test:end-to-end",
Expand All @@ -49,6 +49,7 @@
"clean": "rm -rf build/ && rm -rf dist",
"patch:fast-csv": "node _patch-fast-csv.js",
"benchmark": "node --expose-gc benchmark",
"benchmark:debug": "node --expose-gc --inspect-brk --trace-deopt benchmark",
"build": "npm run patch:fast-csv && grunt build",
"preversion": "npm run clean && npm run build && npm run test:all && npm run test:dist",
"postversion": "git push --no-verify && git push --tags --no-verify"
Expand Down Expand Up @@ -92,23 +93,23 @@
],
"dependencies": {
"archiver": "^3.0.0",
"dayjs": "^1.8.15",
"dayjs": "^1.8.23",
"fast-csv": "^3.4.0",
"jszip": "^3.1.5",
"proxyquire": "^2.1.3",
"readable-stream": "^3.6.0",
"saxes": "5.0.0-rc.2",
"saxes": "^5.0.0",
"tmp": "^0.1.0",
"unzipper": "^0.10.9",
"unzipper": "^0.10.10",
"uuid": "^3.3.3"
},
"devDependencies": {
"@babel/cli": "^7.6.4",
"@babel/core": "^7.1.2",
"@babel/preset-env": "^7.1.0",
"@types/chai": "^4.2.7",
"@babel/core": "^7.9.0",
"@babel/preset-env": "^7.9.0",
"@types/chai": "^4.2.11",
"@types/mocha": "^5.2.7",
"@types/node": "~12.12.27",
"@types/node": "^12.12.32",
"babelify": "^10.0.0",
"browserify": "^16.5.0",
"chai": "^4.2.0",
Expand All @@ -117,29 +118,29 @@
"core-js": "^3.2.1",
"dirty-chai": "^2.0.1",
"eslint": "^6.5.1",
"eslint-config-airbnb-base": "^14.0.0",
"eslint-config-prettier": "^6.4.0",
"eslint-config-airbnb-base": "^14.1.0",
"eslint-config-prettier": "^6.10.1",
"eslint-friendly-formatter": "^4.0.1",
"eslint-plugin-import": "^2.18.2",
"eslint-plugin-import": "^2.20.2",
"eslint-plugin-node": "^10.0.0",
"express": "^4.16.4",
"grunt": "^1.0.3",
"got": "^9.0.0",
"grunt": "^1.1.0",
"grunt-babel": "^8.0.0",
"grunt-browserify": "^5.3.0",
"grunt-contrib-copy": "^1.0.0",
"grunt-contrib-jasmine": "^2.1.0",
"grunt-terser": "^1.0.0",
"grunt-contrib-watch": "^1.1.0",
"grunt-terser": "^1.0.0",
"husky": "^2.2.0",
"lint-staged": "^8.1.5",
"memorystream": "^0.3.1",
"mocha": "^5.2.0",
"prettier-eslint": "^9.0.0",
"prettier-eslint-cli": "^5.0.0",
"regenerator-runtime": "^0.13.3",
"request": "^2.88.0",
"regenerator-runtime": "^0.13.5",
"semver": "^5.6.0",
"ts-node": "^8.6.2",
"typescript": "^3.7.5"
"ts-node": "^8.8.1",
"typescript": "^3.8.3"
}
}
39 changes: 17 additions & 22 deletions spec/end-to-end/express.spec.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
const {PassThrough} = require('readable-stream');
const express = require('express');
const request = require('request');
const got = require('got');
const testutils = require('../utils/index');

const Excel = verquire('exceljs');

// =============================================================================
// Tests

describe('Express', () => {
it('downloads a workbook', () => {
let server;
before(() => {
const app = express();
app.get('/workbook', (req, res) => {
const wb = testutils.createTestBook(new Excel.Workbook(), 'xlsx');
Expand All @@ -21,24 +20,20 @@ describe('Express', () => {
res.end();
});
});
const server = app.listen(3003);
server = app.listen(3003);
});

return new Promise((resolve, reject) => {
const r = request('http://127.0.0.1:3003/workbook');
r.on('response', res => {
const wb2 = new Excel.Workbook();
const stream = wb2.xlsx.createInputStream();
stream.on('done', () => {
try {
testutils.checkTestBook(wb2, 'xlsx');
server.close();
resolve();
} catch (ex) {
reject(ex);
}
});
res.pipe(stream);
});
after(() => {
server.close();
});

it('downloads a workbook', async () => {
const res = got.stream('http://127.0.0.1:3003/workbook', {
decompress: false,
});
const wb2 = new Excel.Workbook();
// TODO: Remove passThrough with got 10+ (requires node v10+)
await wb2.xlsx.read(res.pipe(new PassThrough()));
testutils.checkTestBook(wb2, 'xlsx');
});
});
23 changes: 12 additions & 11 deletions spec/utils/verquire.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,19 @@

const libs = {};
const basePath = (function() {
switch (process.env.EXCEL_BUILD) {
case 'es5':
require('core-js/modules/es.promise');
require('core-js/modules/es.object.assign');
require('core-js/modules/es.object.keys');
require('regenerator-runtime/runtime');
libs.exceljs = require('../../dist/es5');
return '../../dist/es5/';
default:
libs.exceljs = require('../../lib/exceljs.nodejs');
return '../../lib/';
const nodeMajorVersion = parseInt(process.versions.node.split('.')[0], 10);
if (process.env.EXCEL_BUILD === 'es5' || nodeMajorVersion < 10) {
require('core-js/modules/es.promise');
require('core-js/modules/es.object.assign');
require('core-js/modules/es.object.keys');
require('core-js/modules/es.symbol');
require('core-js/modules/es.symbol.async-iterator');
require('regenerator-runtime/runtime');
libs.exceljs = require('../../dist/es5');
return '../../dist/es5/';
}
libs.exceljs = require('../../lib/exceljs.nodejs');
return '../../lib/';
})();

module.exports = function verquire(path) {
Expand Down