Skip to content

Commit f58dd36

Browse files
committed
deno and node ESM tests
1 parent 46360a1 commit f58dd36

26 files changed

+5124
-58
lines changed

.github/workflows/deno.yml

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
name: 'Tests: deno 1.x'
2+
3+
on: [pull_request, push]
4+
5+
jobs:
6+
# small test
7+
misc:
8+
runs-on: ubuntu-latest
9+
env:
10+
FMTS: misc
11+
steps:
12+
- uses: actions/checkout@v2
13+
- uses: denoland/setup-deno@main
14+
with:
15+
deno-version: v1.x
16+
- run: deno test --allow-env --allow-read --allow-write test.ts
17+
# full test
18+
full:
19+
runs-on: ubuntu-latest
20+
steps:
21+
- uses: actions/checkout@v2
22+
- uses: denoland/setup-deno@main
23+
with:
24+
deno-version: v1.x
25+
- uses: ljharb/actions/node/install@main
26+
with:
27+
node-version: '16.'
28+
- run: sudo curl -Lo /usr/bin/rooster https://github.com/SheetJS/rooster/releases/download/v0.2.0/rooster-v0.2.0-linux-amd64
29+
- run: sudo chmod a+x /usr/bin/rooster
30+
- run: make init
31+
- run: 'cd test_files; make all; cd -'
32+
- run: deno test --allow-env --allow-read --allow-write test.ts

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,11 @@ This log is intended to keep track of backwards-incompatible changes, including
44
but not limited to API changes and file location changes. Minor behavioral
55
changes may not be included if they are not expected to break existing code.
66

7+
## v0.18.1
8+
9+
* Removed Node ESM build script and folded into standard ESM build
10+
* Removed undocumented aliases including `make_formulae` and `get_formulae`
11+
712
## v0.18.0
813

914
* Browser scripts only expose `XLSX` variable

Makefile

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,13 +128,31 @@ pkg: bin/xlsx.njs xlsx.js ## Build pkg standalone executable
128128
test mocha: test.js ## Run test suite
129129
mocha -R spec -t 30000
130130

131+
.PHONY: test-esm
132+
test-esm: test.mjs ## Run Node ESM test suite
133+
npx mocha -r esm -R spec -t 30000 $<
134+
135+
.PHONY: test-deno
136+
test-deno: test.ts ## Run Deno test suite
137+
deno test --allow-env --allow-read --allow-write $<
138+
131139
#* To run tests for one format, make test_<fmt>
132140
#* To run the core test suite, make test_misc
133141
TESTFMT=$(patsubst %,test_%,$(FMT))
134142
.PHONY: $(TESTFMT)
135143
$(TESTFMT): test_%:
136144
FMTS=$* make test
137145

146+
TESTESMFMT=$(patsubst %,test-esm_%,$(FMT))
147+
.PHONY: $(TESTESMFMT)
148+
$(TESTESMFMT): test-esm_%:
149+
FMTS=$* make test-esm
150+
151+
TESTDENOFMT=$(patsubst %,test-deno_%,$(FMT))
152+
.PHONY: $(TESTESMFMT)
153+
$(TESTDENOFMT): test-deno_%:
154+
FMTS=$* make test-deno
155+
138156
.PHONY: travis
139157
travis: ## Run test suite with minimal output
140158
mocha -R dot -t 30000

README.md

Lines changed: 43 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -177,10 +177,15 @@ $ bower install js-xlsx
177177

178178
**Deno**
179179

180-
The [`sheetjs`](https://deno.land/x/sheetjs) package is available on deno:
180+
The [`sheetjs`](https://deno.land/x/sheetjs) package is hosted by Deno:
181181

182182
```ts
183+
// @deno-types="https://deno.land/x/sheetjs/types/index.d.ts"
183184
import * as XLSX from 'https://deno.land/x/sheetjs/xlsx.mjs'
185+
186+
/* load the codepage support library for extended support with older formats */
187+
import * as cptable from 'https://deno.land/x/sheetjs/dist/cpexcel.full.mjs';
188+
XLSX.set_cptable(cptable);
184189
```
185190

186191
**NodeJS**
@@ -211,7 +216,7 @@ import * as cpexcel from 'xlsx/dist/cpexcel.full.mjs';
211216
XLSX.set_cptable(cpexcel);
212217
```
213218

214-
**PhotoShop and InDesign**
219+
**Photoshop and InDesign**
215220

216221
`dist/xlsx.extendscript.js` is an ExtendScript build for Photoshop and InDesign
217222
that is included in the `npm` package. It can be directly referenced with a
@@ -538,9 +543,11 @@ The [`demos` directory](demos/) includes sample projects for:
538543
- [`webpack 2.x`](demos/webpack/)
539544

540545
**Platforms and Integrations**
546+
- [`deno`](demos/deno/)
541547
- [`electron application`](demos/electron/)
542548
- [`nw.js application`](demos/nwjs/)
543549
- [`Chrome / Chromium extensions`](demos/chrome/)
550+
- [`Download a Google Sheet locally`](demos/google-sheet/)
544551
- [`Adobe ExtendScript`](demos/extendscript/)
545552
- [`Headless Browsers`](demos/headless/)
546553
- [`canvas-datagrid`](demos/datagrid/)
@@ -609,6 +616,23 @@ const workbook = read(buf);
609616

610617
</details>
611618

619+
<details>
620+
<summary><b>Local file in a Deno application</b> (click to show)</summary>
621+
622+
`readFile` uses `Deno.readFileSync` under the hood:
623+
624+
```js
625+
// @deno-types="https://deno.land/x/sheetjs/types/index.d.ts"
626+
import * as XLSX from 'https://deno.land/x/sheetjs/xlsx.mjs'
627+
628+
const workbook = XLSX.readFile("test.xlsx");
629+
```
630+
631+
Applications reading files must be invoked with the `--allow-read` flag. The
632+
[`deno` demo](demos/deno/) has more examples
633+
634+
</details>
635+
612636
<details>
613637
<summary><b>User-submitted file in a web page ("Drag-and-Drop")</b> (click to show)</summary>
614638

@@ -1467,6 +1491,23 @@ const workbook = writeFileSync("out.xlsb", buf);
14671491

14681492
</details>
14691493

1494+
<details>
1495+
<summary><b>Local file in a Deno application</b> (click to show)</summary>
1496+
1497+
`writeFile` uses `Deno.writeFileSync` under the hood:
1498+
1499+
```js
1500+
// @deno-types="https://deno.land/x/sheetjs/types/index.d.ts"
1501+
import * as XLSX from 'https://deno.land/x/sheetjs/xlsx.mjs'
1502+
1503+
XLSX.writeFile(workbook, "test.xlsx");
1504+
```
1505+
1506+
Applications writing files must be invoked with the `--allow-write` flag. The
1507+
[`deno` demo](demos/deno/) has more examples
1508+
1509+
</details>
1510+
14701511
<details>
14711512
<summary><b>Local file in a PhotoShop or InDesign plugin</b> (click to show)</summary>
14721513

bits/05_buf.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ function utf8decode(content/*:string*/) {
6666
o[widx++] = (128|(c&63));
6767
} else if(c >= 0xD800 && c < 0xE000) {
6868
c = (c&1023)+64;
69-
var d = str.charCodeAt(++ridx)&1023;
69+
var d = content.charCodeAt(++ridx)&1023;
7070
o[widx++] = (240|((c>>8)&7));
7171
o[widx++] = (128|((c>>2)&63));
7272
o[widx++] = (128|((d>>6)&15)|((c&3)<<4));

bits/23_binutils.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ if(has_buf/*:: && typeof Buffer !== 'undefined'*/) {
6363
}
6464

6565
/* from js-xls */
66-
if(typeof cptable !== 'undefined') {
66+
function cpdoit() {
6767
__utf16le = function(b/*:RawBytes|CFBlob*/,s/*:number*/,e/*:number*/) { return cptable.utils.decode(1200, b.slice(s,e)).replace(chr0, ''); };
6868
__utf8 = function(b/*:RawBytes|CFBlob*/,s/*:number*/,e/*:number*/) { return cptable.utils.decode(65001, b.slice(s,e)); };
6969
__lpstr = function(b/*:RawBytes|CFBlob*/,i/*:number*/) { var len = __readUInt32LE(b,i); return len > 0 ? cptable.utils.decode(current_ansi, b.slice(i+4, i+4+len-1)) : "";};
@@ -72,6 +72,7 @@ if(typeof cptable !== 'undefined') {
7272
__lpp4 = function(b/*:RawBytes|CFBlob*/,i/*:number*/) { var len = __readUInt32LE(b,i); return len > 0 ? cptable.utils.decode(1200, b.slice(i+4,i+4+len)) : "";};
7373
__8lpp4 = function(b/*:RawBytes|CFBlob*/,i/*:number*/) { var len = __readUInt32LE(b,i); return len > 0 ? cptable.utils.decode(65001, b.slice(i+4,i+4+len)) : "";};
7474
}
75+
if(typeof cptable !== 'undefined') cpdoit();
7576

7677
var __readUInt8 = function(b/*:RawBytes|CFBlob*/, idx/*:number*/)/*:number*/ { return b[idx]; };
7778
var __readUInt16LE = function(b/*:RawBytes|CFBlob*/, idx/*:number*/)/*:number*/ { return (b[idx+1]*(1<<8))+b[idx]; };

bits/75_xlml.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -585,19 +585,19 @@ function parse_xlml_xml(d, _opts)/*:Workbook*/ {
585585
break;
586586
case 'header' /*case 'Header'*/:
587587
if(!cursheet['!margins']) default_margins(cursheet['!margins']={}, 'xlml');
588-
cursheet['!margins'].header = parsexmltag(Rn[0]).Margin;
588+
if(!isNaN(+parsexmltag(Rn[0]).Margin)) cursheet['!margins'].header = +parsexmltag(Rn[0]).Margin;
589589
break;
590590
case 'footer' /*case 'Footer'*/:
591591
if(!cursheet['!margins']) default_margins(cursheet['!margins']={}, 'xlml');
592-
cursheet['!margins'].footer = parsexmltag(Rn[0]).Margin;
592+
if(!isNaN(+parsexmltag(Rn[0]).Margin)) cursheet['!margins'].footer = +parsexmltag(Rn[0]).Margin;
593593
break;
594594
case 'pagemargins' /*case 'PageMargins'*/:
595595
var pagemargins = parsexmltag(Rn[0]);
596596
if(!cursheet['!margins']) default_margins(cursheet['!margins']={},'xlml');
597-
if(pagemargins.Top) cursheet['!margins'].top = pagemargins.Top;
598-
if(pagemargins.Left) cursheet['!margins'].left = pagemargins.Left;
599-
if(pagemargins.Right) cursheet['!margins'].right = pagemargins.Right;
600-
if(pagemargins.Bottom) cursheet['!margins'].bottom = pagemargins.Bottom;
597+
if(!isNaN(+pagemargins.Top)) cursheet['!margins'].top = +pagemargins.Top;
598+
if(!isNaN(+pagemargins.Left)) cursheet['!margins'].left = +pagemargins.Left;
599+
if(!isNaN(+pagemargins.Right)) cursheet['!margins'].right = +pagemargins.Right;
600+
if(!isNaN(+pagemargins.Bottom)) cursheet['!margins'].bottom = +pagemargins.Bottom;
601601
break;
602602
case 'displayrighttoleft' /*case 'DisplayRightToLeft'*/:
603603
if(!Workbook.Views) Workbook.Views = [];

bits/87_read.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ function readSync(data/*:RawData*/, opts/*:?ParseOpts*/)/*:Workbook*/ {
6767
reset_cp();
6868
var o = opts||{};
6969
if(typeof ArrayBuffer !== 'undefined' && data instanceof ArrayBuffer) return readSync(new Uint8Array(data), (o = dup(o), o.type = "array", o));
70+
if(typeof Uint8Array !== 'undefined' && data instanceof Uint8Array && !o.type) o.type = typeof Deno !== "undefined" ? "buffer" : "array";
7071
var d = data, n = [0,0,0,0], str = false;
7172
if(o.cellStyles) { o.cellNF = true; o.sheetStubs = true; }
7273
_ssfopts = {};

bits/88_write.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,12 @@ function write_zip_type(wb/*:Workbook*/, opts/*:?WriteOpts*/)/*:any*/ {
4848
default: throw new Error("Unrecognized type " + o.type);
4949
}
5050
var out = z.FullPaths ? CFB.write(z, {fileType:"zip", type: /*::(*/{"nodebuffer": "buffer", "string": "binary"}/*:: :any)*/[oopts.type] || oopts.type, compression: !!o.compression}) : z.generate(oopts);
51-
if(typeof Deno !== "undefined" && typeof out == "string") out = new Uint8Array(s2ab(out));
51+
if(typeof Deno !== "undefined") {
52+
if(typeof out == "string") {
53+
if(o.type == "binary" || o.type == "base64") return out;
54+
out = new Uint8Array(s2ab(out));
55+
}
56+
}
5257
/*jshint -W083 */
5358
if(o.password && typeof encrypt_agile !== 'undefined') return write_cfb_ctr(encrypt_agile(out, o.password), o); // eslint-disable-line no-undef
5459
/*jshint +W083 */
@@ -72,6 +77,7 @@ function write_string_type(out/*:string*/, opts/*:WriteOpts*/, bom/*:?string*/)/
7277
case "file": return write_dl(opts.file, o, 'utf8');
7378
case "buffer": {
7479
if(has_buf) return Buffer_from(o, 'utf8');
80+
else if(typeof TextEncoder !== "undefined") return new TextEncoder().encode(o);
7581
else return write_string_type(o, {type:'binary'}).split("").map(function(c) { return c.charCodeAt(0); });
7682
}
7783
}

bits/90_utils.js

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -252,10 +252,6 @@ var utils/*:any*/ = {
252252
decode_cell: decode_cell,
253253
decode_range: decode_range,
254254
format_cell: format_cell,
255-
get_formulae: sheet_to_formulae,
256-
make_csv: sheet_to_csv,
257-
make_json: sheet_to_json,
258-
make_formulae: sheet_to_formulae,
259255
sheet_add_aoa: sheet_add_aoa,
260256
sheet_add_json: sheet_add_json,
261257
sheet_add_dom: sheet_add_dom,

0 commit comments

Comments
 (0)