Skip to content

Commit b3bc9e7

Browse files
authored
update_wasm
up build and os compats
2 parents 6a79b39 + 1b7c659 commit b3bc9e7

31 files changed

+1804
-4048
lines changed

.github/actions/action.yml

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
name: Setup repo
2+
description: Install dependencies and perform setup for netcdf4-wasm
3+
4+
inputs:
5+
node:
6+
default: lts/*
7+
description: Node version to use
8+
9+
runs:
10+
using: composite
11+
steps:
12+
- name: Setup Node (${{ inputs.node }})
13+
uses: actions/setup-node@v4
14+
with:
15+
node-version: ${{ inputs.node }}
16+
registry-url: "https://registry.npmjs.org"
17+
18+
- name: Install system dependencies
19+
shell: bash
20+
run: |
21+
sudo apt-get update
22+
sudo apt-get install -y cmake build-essential wget tar
23+
24+
- name: Install npm dependencies
25+
shell: bash
26+
run: npm install
27+
28+
- name: Install Emscripten
29+
shell: bash
30+
run: npm run install-emscripten

.github/workflows/ci.yml

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
name: ci
2+
3+
on:
4+
push:
5+
branches: [main]
6+
pull_request:
7+
branches: [main]
8+
9+
workflow_dispatch: # Manual trigger
10+
11+
defaults:
12+
run:
13+
shell: bash
14+
15+
jobs:
16+
core:
17+
name: Build and Test
18+
runs-on: ubuntu-latest
19+
20+
steps:
21+
- name: Checkout repo
22+
uses: actions/checkout@v4
23+
with:
24+
fetch-depth: 0
25+
26+
- name: Setup repo
27+
uses: ./.github/actions
28+
29+
- name: Check dependencies
30+
run: npm run check-deps
31+
32+
- name: Build
33+
run: npm run build
34+
35+
- name: Run tests
36+
run: npm run test:coverage

.github/workflows/release.yml

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
name: release
2+
3+
on:
4+
release:
5+
types: [created]
6+
7+
concurrency: ${{ github.workflow }}-${{ github.ref }}
8+
9+
jobs:
10+
release:
11+
name: Publish to npm
12+
runs-on: ubuntu-latest
13+
14+
steps:
15+
- name: Checkout repo
16+
uses: actions/checkout@v4
17+
with:
18+
fetch-depth: 0
19+
20+
- name: Setup repo
21+
uses: ./.github/actions
22+
23+
- name: Build
24+
run: npm run build
25+
26+
- name: Publish
27+
run: npm publish --access public
28+
env:
29+
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ node_modules/
33
npm-debug.log*
44
yarn-debug.log*
55
yarn-error.log*
6+
package-lock.json
67

78
# Build outputs
89
dist/

bindings/post.js

Lines changed: 22 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,28 @@
11
// Post-run JavaScript for NetCDF4 WASM module
22
// This file is executed after the WASM module is initialized
33

4-
// Wrap NetCDF4 functions for easier JavaScript usage
5-
if (Module && Module._malloc) {
6-
7-
// Helper functions for memory management
8-
Module.allocateString = function(str) {
9-
var len = lengthBytesUTF8(str) + 1;
10-
var ptr = Module._malloc(len);
11-
stringToUTF8(str, ptr, len);
12-
return ptr;
13-
};
4+
// Helper functions for memory management
5+
Module.allocateString = function(str) {
6+
var len = lengthBytesUTF8(str) + 1;
7+
var ptr = _malloc(len);
8+
stringToUTF8(str, ptr, len);
9+
return ptr;
10+
};
1411

15-
Module.freeString = function(ptr) {
16-
Module._free(ptr);
17-
};
12+
Module.freeString = function(ptr) {
13+
_free(ptr);
14+
};
1815

19-
// NetCDF4 wrapper functions will be added here
20-
// Example:
21-
// Module.nc_open = function(path, mode) {
22-
// var pathPtr = Module.allocateString(path);
23-
// var ncidPtr = Module._malloc(4);
24-
// var result = Module._nc_open(pathPtr, mode, ncidPtr);
25-
// var ncid = Module.getValue(ncidPtr, 'i32');
26-
// Module.freeString(pathPtr);
27-
// Module._free(ncidPtr);
28-
// return { result: result, ncid: ncid };
29-
// };
16+
// NetCDF4 wrapper functions will be added here if needed
17+
// Example:
18+
// Module.nc_open = function(path, mode) {
19+
// var pathPtr = Module.allocateString(path);
20+
// var ncidPtr = _malloc(4);
21+
// var result = Module._nc_open(pathPtr, mode, ncidPtr);
22+
// var ncid = Module.getValue(ncidPtr, 'i32');
23+
// Module.freeString(pathPtr);
24+
// _free(ncidPtr);
25+
// return { result: result, ncid: ncid };
26+
// };
3027

31-
console.log('NetCDF4 WASM: JavaScript bindings loaded');
32-
}
28+
console.log('NetCDF4 WASM: JavaScript bindings loaded');

bindings/pre.js

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11
// Pre-run JavaScript for NetCDF4 WASM module
22
// This file is executed before the WASM module is initialized
33

4-
Module = Module || {};
5-
6-
// Configure module settings
4+
// Configure module settings (Module will be provided by Emscripten)
75
Module.preRun = Module.preRun || [];
86
Module.postRun = Module.postRun || [];
97

@@ -16,7 +14,5 @@ Module.postRun.push(function() {
1614
console.log('NetCDF4 WASM: Ready');
1715
});
1816

19-
// Export for Node.js if available
20-
if (typeof module !== 'undefined' && module.exports) {
21-
module.exports = Module;
22-
}
17+
// Note: When using EXPORT_ES6=1, Emscripten handles the module export
18+
// No need to manually export - the factory function is exported by default
Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,30 @@
11
module.exports = {
2-
preset: 'ts-jest',
2+
preset: 'ts-jest/presets/default-esm',
33
testEnvironment: 'node',
4+
extensionsToTreatAsEsm: ['.ts'],
5+
moduleNameMapper: {
6+
'^(\\.{1,2}/.*)\\.js$': '$1',
7+
},
8+
transform: {
9+
'^.+\\.tsx?$': [
10+
'ts-jest',
11+
{
12+
useESM: true,
13+
},
14+
],
15+
},
416
roots: ['<rootDir>/src'],
517
testMatch: [
618
'**/__tests__/**/*.+(ts|tsx|js)',
719
'**/*.(test|spec).+(ts|tsx|js)'
820
],
9-
transform: {
10-
'^.+\\.(ts|tsx)$': 'ts-jest'
11-
},
1221
collectCoverageFrom: [
1322
'src/**/*.{ts,tsx}',
1423
'!src/**/*.d.ts',
1524
'!src/__tests__/**/*'
1625
],
1726
coverageDirectory: 'coverage',
1827
coverageReporters: ['text', 'lcov', 'html'],
19-
setupFilesAfterEnv: ['<rootDir>/jest.setup.js'],
28+
setupFilesAfterEnv: ['<rootDir>/jest.setup.cjs'], // Changed to .cjs
2029
testTimeout: 30000
2130
};
File renamed without changes.

0 commit comments

Comments
 (0)