Skip to content

Commit

Permalink
feat(nodejs-polars): bindings for nodejs (#1703)
Browse files Browse the repository at this point in the history
  • Loading branch information
universalmind303 committed Dec 20, 2021
1 parent d3b0f0d commit fb4dd2b
Show file tree
Hide file tree
Showing 98 changed files with 27,223 additions and 1 deletion.
164 changes: 164 additions & 0 deletions .github/workflows/create-js-release.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,164 @@
name: nodejs-polars

on:
push:
# Sequence of patterns matched against refs/tags
tags:
- 'nodejs-polars-v*' # Push events to matching nodejs-polars-v*, i.e. nodejs-polars-v1.0, nodejs-polars-v20.15.10
jobs:
build-js:
defaults:
run:
working-directory: nodejs-polars
strategy:
fail-fast: false
matrix:
settings:
# MAC
######

- host: macos-latest
target: 'x86_64-apple-darwin'
build: |
npm run build
- host: macos-latest
target: "aarch64-apple-darwin"
build: |
sudo rm -Rf /Library/Developer/CommandLineTools/SDKs/*;
export CC=$(xcrun -f clang);
export CXX=$(xcrun -f clang++);
SYSROOT=$(xcrun --sdk macosx --show-sdk-path);
export CFLAGS="-isysroot $SYSROOT -isystem $SYSROOT";
npm run build -- --target aarch64-apple-darwin
# Windows
##########

- host: windows-latest
target: "x86_64-pc-windows-msvc"
build: npm run build

- host: windows-latest
target: "i686-pc-windows-msvc"
setup: |
choco install nodejs-lts --x86 -y --force
echo "C:\\Program Files (x86)\\nodejs" >> $GITHUB_PATH
build: |
export CARGO_PROFILE_RELEASE_CODEGEN_UNITS=32;
export CARGO_PROFILE_RELEASE_LTO=false
npm run build -- --target i686-pc-windows-msvc
- host: windows-latest
target: "aarch64-pc-windows-msvc"
build: npm run build -- --target aarch64-pc-windows-msvc

# Linux
########

- host: ubuntu-latest
target: "x86_64-unknown-linux-gnu"
build: npm run build

- host: ubuntu-latest
target: "aarch64-linux-android"
build: |
export CARGO_TARGET_AARCH64_LINUX_ANDROID_LINKER="${ANDROID_NDK_HOME}/toolchains/llvm/prebuilt/linux-x86_64/bin/aarch64-linux-android24-clang"
export PATH="${ANDROID_NDK_HOME}/toolchains/llvm/prebuilt/linux-x86_64/bin:${PATH}"
npm run build -- --target aarch64-linux-android
name: ${{ matrix.settings.target }}
runs-on: ${{ matrix.settings.host }}
steps:
- uses: actions/checkout@v2
- uses: actions/setup-node@v2
with:
node-version: 16
- name: Install latest Rust nightly
uses: actions-rs/toolchain@v1
with:
toolchain: nightly-2021-12-02
override: true
target: ${{ matrix.settings.target }}

- name: Generate Cargo.lock
uses: actions-rs/cargo@v1
with:
command: generate-lockfile

- name: Cache cargo registry
uses: actions/cache@v2
with:
path: ~/.cargo/registry
key: ${{ matrix.settings.target }}-node@16-cargo-registry-trimmed-${{ hashFiles('**/Cargo.lock') }}

- name: Cache cargo index
uses: actions/cache@v2
with:
path: ~/.cargo/git
key: ${{ matrix.settings.target }}-node@16-cargo-index-trimmed-${{ hashFiles('**/Cargo.lock') }}

- name: Pull latest image
run: ${{ matrix.settings.docker }}
env:
DOCKER_REGISTRY_URL: ghcr.io
DOCKER_USERNAME: ${{ github.actor }}
DOCKER_PASSWORD: ${{ secrets.GITHUB_TOKEN }}

if: ${{ matrix.settings.docker }}

- name: "Setup toolchain"
if: ${{ matrix.settings.setup }}
run: ${{ matrix.settings.setup }}

- name: "Install dependencies"
run: npm install --ignore-scripts

- name: "Build"
run: ${{ matrix.settings.build }}
shell: bash
- name: Upload artifact
uses: actions/upload-artifact@v2
with:
path: nodejs-polars/artifacts
- name: List artifacts
run: ls -R artifacts
shell: bash

publish:
name: Publish
needs:
- build-js
defaults:
run:
working-directory: nodejs-polars
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/setup-node@v2
with:
node-version: "16"
registry-url: "https://registry.npmjs.org"

- name: "Install dependencies"
run: npm install --ignore-scripts

- name: Download all artifacts
uses: actions/download-artifact@v2
with:
path: nodejs-polars/artifacts

- name: List artifacts
run: ls -R artifacts
shell: bash

- name: Move artifacts
run: npm run artifacts

- name: Build TypeScript
run: npm run build:ts

- name: Publish to npm
run: npm publish
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,5 @@ polars/vendor
*.so
.ENV
.env
AUTO_CHANGELOG.md
AUTO_CHANGELOG.md
node_modules/
10 changes: 10 additions & 0 deletions nodejs-polars/.editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
root = true

[*]
end_of_line = lf
insert_final_newline = true

[*.{js,json,yml}]
charset = utf-8
indent_style = space
indent_size = 2
84 changes: 84 additions & 0 deletions nodejs-polars/.eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
{
"env": {
"browser": true,
"es2021": true,
"jest/globals": true
},
"globals": {
"Buffer": "readonly",
"process": "writable"
},
"extends": [
"eslint:recommended"
],
"parser": "@typescript-eslint/parser",
"parserOptions": {
"ecmaVersion": 2020,
"sourceType": "module"
},
"plugins": [
"@typescript-eslint",
"jest"
],
"rules": {
"eol-last": "error",
"no-inner-declarations": "off",
"func-call-spacing": "off",
"@typescript-eslint/func-call-spacing": [
"error"
],
"no-duplicate-imports": "off",
"@typescript-eslint/no-duplicate-imports": [
"error"
],
"comma-spacing": "off",
"@typescript-eslint/comma-spacing": [
"error"
],
"quotes": [
"error",
"double",
{
"allowTemplateLiterals": true,
"avoidEscape": true
}
],
"no-redeclare": "off",
"no-trailing-spaces": "error",
"semi": [
"error",
"always"
],
"indent": [
"error",
2,
{
"MemberExpression": 1
}
],
"no-dupe-class-members": "off",
"no-unused-vars": "off",
"newline-per-chained-call": [
"error",
{
"ignoreChainWithDepth": 2
}
],
"@typescript-eslint/member-ordering": "error",
"no-multiple-empty-lines": [
"error",
{
"max": 2,
"maxEOF": 0
}
],
"padding-line-between-statements": [
"error",
{
"blankLine": "always",
"prev": "*",
"next": "return"
}
]
}
}
14 changes: 14 additions & 0 deletions nodejs-polars/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
/target
**/*.rs.bk
Cargo.lock
node_modules/
.yarn/cache
.yarn/install-state*
.pnp.*

coverage/
bin/
.vscode
.cargo
*.node
docs/
9 changes: 9 additions & 0 deletions nodejs-polars/.npmignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
target
Cargo.lock
.cargo
.github
npm
# .eslintrc
.prettierignore
rustfmt.toml
yarn.lock
1 change: 1 addition & 0 deletions nodejs-polars/.nvmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
16
768 changes: 768 additions & 0 deletions nodejs-polars/.yarn/releases/yarn-3.1.1.cjs

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions nodejs-polars/.yarnrc.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
nodeLinker: node-modules
yarnPath: .yarn/releases/yarn-3.1.1.cjs
26 changes: 26 additions & 0 deletions nodejs-polars/@types/jest.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import {DataFrame} from "@polars/dataframe";
import {Series} from "@polars/series";

declare global {
namespace jest {
interface Matchers<R> {
toSeriesEqual(b: Series<any>): R;
toSeriesStrictEqual(b: Series<any>): R;
toFrameEqual(b: DataFrame): R;
/**
* Compares two DataFrames, including the dtypes
*
* @example
* ```
* >>> df = pl.Dataframe([pl.Series("int32": [1,2], pl.Int32)])
* >>> other = pl.Dataframe([pl.Series("int32": [1,2], pl.UInt32)])
*
* >>> expect(df).toFrameEqual(other) // passes
* >>> expect(df).toFrameStrictEqual(other) // fails
* ```
*/
toFrameStrictEqual(b: DataFrame): R;
toFrameEqualIgnoringOrder(b: DataFrame): R;
}
}
}
Loading

0 comments on commit fb4dd2b

Please sign in to comment.