Skip to content
Open
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
4 changes: 2 additions & 2 deletions packages/compile/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@
"@sdeverywhere/parse": "^0.1.4",
"byline": "^5.0.0",
"csv-parse": "^5.3.3",
"fflate": "^0.8.3",
"ramda": "^0.27.0",
"strip-bom": "^5.0.0",
"xlsx": "https://cdn.sheetjs.com/xlsx-0.20.2/xlsx-0.20.2.tgz"
"strip-bom": "^5.0.0"
},
"author": "Climate Interactive",
"license": "MIT",
Expand Down
25 changes: 7 additions & 18 deletions packages/compile/src/_shared/helpers.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import * as fs from 'node:fs'
import util from 'util'
import { parse as parseCsv } from 'csv-parse/sync'
import * as R from 'ramda'
import XLSX from 'xlsx'

import B from './bufx.js'
import { readXlsx as readXlsxFile, resetXlsxCache } from './xlsx.js'

import { canonicalId, canonicalVarId } from '@sdeverywhere/parse'

Expand All @@ -24,12 +24,6 @@ let nextLevelVarSeq = 1
let nextAuxVarSeq = 1
// parsed csv data cache
let csvData = new Map()
// parsed xlsx data cache
let xlsxData = new Map()

// Newer versions of the xlsx package require manually setting the `fs` instance
// before using the `XLSX.readFile` function
XLSX.set_fs(fs)

// XXX: This is needed for tests due to sequence numbers being in module-level storage
export function resetHelperState() {
Expand All @@ -40,7 +34,7 @@ export function resetHelperState() {
nextLevelVarSeq = 1
nextAuxVarSeq = 1
csvData.clear()
xlsxData.clear()
resetXlsxCache()
}

export let canonicalName = name => {
Expand Down Expand Up @@ -203,15 +197,10 @@ export let isIterable = obj => {
}
// Command helpers
export let readXlsx = pathname => {
// Read the XLSX file at the pathname and parse it.
// Return a `XLSX.WorkBook` object that can be used to access the data.
// Cache parsed files to support multiple reads from different equations.
let xlsx = xlsxData.get(pathname)
if (!xlsx) {
xlsx = XLSX.readFile(pathname, { cellDates: true })
xlsxData.set(pathname, xlsx)
}
return xlsx
// Read the XLSX file at the pathname and parse it. Return a workbook
// object ({ SheetNames, Sheets }) that can be used to access the data.
// The underlying reader caches parsed files by path.
return readXlsxFile(pathname)
}
export let readCsv = (pathname, delimiter = ',') => {
// Read the CSV file at the pathname and parse it with the given delimiter.
Expand Down
Loading
Loading