Bladeren bron

feat: napi-rs@1

LongYinan 4 jaren geleden
bovenliggende
commit
617c1f6cd5

+ 6 - 0
.cargo/config

@@ -0,0 +1,6 @@
+[target.aarch64-unknown-linux-gnu]
+linker = "aarch64-linux-gnu-gcc"
+
+
+[target.armv7-unknown-linux-gnueabihf]
+linker = "arm-linux-gnueabihf-gcc"

+ 83 - 3
.eslintrc.yml

@@ -46,8 +46,19 @@ rules:
       },
     ]
 
+  # https://github.com/benmosher/eslint-plugin-import/pull/334
+  'import/no-duplicates': 2
   'import/first': 2
   'import/newline-after-import': 2
+  'import/order':
+    [
+      2,
+      {
+        'newlines-between': 'always',
+        'alphabetize': { 'order': 'asc' },
+        'groups': ['builtin', 'external', 'internal', 'parent', 'sibling', 'index'],
+      },
+    ]
 
   'sonarjs/cognitive-complexity': 0
   'sonarjs/no-duplicate-string': 0
@@ -68,12 +79,81 @@ overrides:
     parserOptions:
       project: ./tsconfig.json
     rules:
-      # eslint will treat TS type as undefined stuff
       'no-undef': 0
-
-      # conflict function override
+      # TypeScript declare merge
+      'no-redeclare': 0
+      'no-useless-constructor': 0
+      'no-unused-vars': 0
       'no-dupe-class-members': 0
+      'no-case-declarations': 0
+      'no-duplicate-imports': 0
+      # TypeScript Interface and Type
+      'no-use-before-define': 0
 
+      '@typescript-eslint/adjacent-overload-signatures': 2
+      '@typescript-eslint/await-thenable': 2
+      '@typescript-eslint/consistent-type-assertions': 2
+      '@typescript-eslint/ban-types':
+        [
+          'error',
+          {
+            'types':
+              {
+                'String': { 'message': 'Use string instead', 'fixWith': 'string' },
+                'Number': { 'message': 'Use number instead', 'fixWith': 'number' },
+                'Boolean': { 'message': 'Use boolean instead', 'fixWith': 'boolean' },
+                'Function': { 'message': 'Use explicit type instead' },
+              },
+          },
+        ]
+      '@typescript-eslint/explicit-member-accessibility':
+        [
+          'error',
+          {
+            accessibility: 'explicit',
+            overrides:
+              {
+                accessors: 'no-public',
+                constructors: 'no-public',
+                methods: 'no-public',
+                properties: 'no-public',
+                parameterProperties: 'explicit',
+              },
+          },
+        ]
+      '@typescript-eslint/method-signature-style': 2
+      '@typescript-eslint/no-floating-promises': 2
+      '@typescript-eslint/no-implied-eval': 2
+      '@typescript-eslint/no-for-in-array': 2
+      '@typescript-eslint/no-inferrable-types': 2
+      '@typescript-eslint/no-invalid-void-type': 2
+      '@typescript-eslint/no-misused-new': 2
+      '@typescript-eslint/no-misused-promises': 2
+      '@typescript-eslint/no-namespace': 2
+      '@typescript-eslint/no-non-null-asserted-optional-chain': 2
+      '@typescript-eslint/no-throw-literal': 2
+      '@typescript-eslint/no-unnecessary-boolean-literal-compare': 2
+      '@typescript-eslint/prefer-for-of': 2
+      '@typescript-eslint/prefer-nullish-coalescing': 2
+      '@typescript-eslint/switch-exhaustiveness-check': 2
+      '@typescript-eslint/prefer-optional-chain': 2
+      '@typescript-eslint/prefer-readonly': 2
+      '@typescript-eslint/prefer-string-starts-ends-with': 0
+      '@typescript-eslint/no-array-constructor': 2
+      '@typescript-eslint/require-await': 2
+      '@typescript-eslint/return-await': 2
+      '@typescript-eslint/ban-ts-comment':
+        [2, { 'ts-expect-error': false, 'ts-ignore': true, 'ts-nocheck': true, 'ts-check': false }]
+      '@typescript-eslint/naming-convention':
+        [
+          2,
+          {
+            selector: 'memberLike',
+            format: ['camelCase', 'PascalCase'],
+            modifiers: ['private'],
+            leadingUnderscore: 'forbid',
+          },
+        ]
       '@typescript-eslint/no-unused-vars':
         [2, { varsIgnorePattern: '^_', argsIgnorePattern: '^_', ignoreRestSiblings: true }]
       '@typescript-eslint/member-ordering':

+ 2 - 2
.github/dependabot.yml

@@ -7,7 +7,7 @@ updates:
   - package-ecosystem: 'npm'
     directory: '/'
     schedule:
-      interval: 'daily'
+      interval: 'weekly'
     # Specify labels for npm pull requests
     labels:
       - 'npm'
@@ -18,7 +18,7 @@ updates:
   - package-ecosystem: 'cargo'
     directory: '/'
     schedule:
-      interval: 'daily'
+      interval: 'weekly'
     labels:
       - 'rust'
       - 'dependencies'

+ 376 - 60
.github/workflows/CI.yaml

@@ -2,10 +2,12 @@ name: CI
 
 env:
   DEBUG: 'napi:*'
+  APP_NAME: 'package-template'
 
 on:
   push:
-    branches: [master, develop]
+    branches:
+      - main
     tags-ignore:
       - '**'
   pull_request:
@@ -19,32 +21,17 @@ jobs:
       matrix:
         os: [ubuntu-latest, macos-latest, windows-latest]
 
-    name: stable - ${{ matrix.os }} - node@12
+    name: stable - ${{ matrix.os }} - node@14
     runs-on: ${{ matrix.os }}
 
     steps:
       - uses: actions/checkout@v2
 
       - name: Setup node
-        uses: actions/setup-node@v1
+        uses: actions/setup-node@v2-beta
         with:
-          node-version: 12
-
-      - name: Set platform name
-        run: |
-          export NODE_PLATFORM_NAME=$(node -e "console.log(require('os').platform())")
-          echo "PLATFORM_NAME=${NODE_PLATFORM_NAME}" >> $GITHUB_ENV
-        shell: bash
-
-      - name: Install llvm
-        if: matrix.os == 'windows-latest'
-        run: choco install -y llvm
-
-      - name: Set llvm path
-        if: matrix.os == 'windows-latest'
-        run: |
-          echo "LIBCLANG_PATH=C:\\Program Files\\LLVM\\bin" >> $GITHUB_ENV
-        shell: bash
+          node-version: 14
+          check-latest: true
 
       - name: Install
         uses: actions-rs/toolchain@v1
@@ -62,23 +49,22 @@ jobs:
         uses: actions/cache@v1
         with:
           path: ~/.cargo/registry
-          key: stable-${{ matrix.os }}-node@12-cargo-registry-trimmed-${{ hashFiles('**/Cargo.lock') }}
+          key: stable-${{ matrix.os }}-node@14-cargo-registry-trimmed-${{ hashFiles('**/Cargo.lock') }}
 
       - name: Cache cargo index
         uses: actions/cache@v1
         with:
           path: ~/.cargo/git
-          key: stable-${{ matrix.os }}gnu-node@12-cargo-index-trimmed-${{ hashFiles('**/Cargo.lock') }}
+          key: stable-${{ matrix.os }}-node@14-cargo-index-trimmed-${{ hashFiles('**/Cargo.lock') }}
 
       - name: Cache NPM dependencies
         uses: actions/cache@v1
         with:
           path: node_modules
-          key: npm-cache-${{ matrix.os }}-node@12-${{ hashFiles('yarn.lock') }}
-          restore-keys: |
-            npm-cache-
+          key: npm-cache-${{ matrix.os }}-node@14-${{ hashFiles('yarn.lock') }}
+
       - name: 'Install dependencies'
-        run: yarn install --frozen-lockfile --registry https://registry.npmjs.org
+        run: yarn install --frozen-lockfile --registry https://registry.npmjs.org --network-timeout 300000
 
       - name: 'Build'
         if: matrix.os != 'macos-latest'
@@ -93,17 +79,17 @@ jobs:
       - name: Upload artifact
         uses: actions/upload-artifact@v2
         with:
-          name: bindings-${{ env.PLATFORM_NAME }}
-          path: package-template.${{ env.PLATFORM_NAME }}.node
+          name: bindings-${{ matrix.os }}
+          path: ${{ env.APP_NAME }}.*.node
 
       - name: Clear the cargo caches
         run: |
           cargo install cargo-cache --no-default-features --features ci-autoclean
           cargo-cache
 
-  build_musl:
+  build-linux-musl:
     if: "!contains(github.event.head_commit.message, 'skip ci')"
-    name: stable - linux-musl - node@12
+    name: stable - linux-musl - node@10
     runs-on: ubuntu-latest
 
     steps:
@@ -121,19 +107,283 @@ jobs:
         run: |
           docker pull docker.pkg.github.com/napi-rs/napi-rs/rust-nodejs-alpine:lts
           docker tag docker.pkg.github.com/napi-rs/napi-rs/rust-nodejs-alpine:lts builder
+
+      - name: Generate Cargo.lock
+        uses: actions-rs/cargo@v1
+        with:
+          command: generate-lockfile
+
+      - name: Cache cargo registry
+        uses: actions/cache@v1
+        with:
+          path: ~/.cargo/registry
+          key: stable-node-alpine-@10-cargo-registry-trimmed-${{ hashFiles('**/Cargo.lock') }}
+
+      - name: Cache cargo index
+        uses: actions/cache@v1
+        with:
+          path: ~/.cargo/git
+          key: stable-node-alpine-@10-cargo-index-trimmed-${{ hashFiles('**/Cargo.lock') }}
+
+      - name: Cache NPM dependencies
+        uses: actions/cache@v1
+        with:
+          path: node_modules
+          key: npm-cache-alpine-node@10-${{ hashFiles('yarn.lock') }}
+
       - name: 'Install dependencies'
-        run: yarn install --frozen-lockfile --registry https://registry.npmjs.org
+        run: yarn install --frozen-lockfile --registry https://registry.npmjs.org --network-timeout 300000
 
       - name: 'Build'
         run: |
-          docker run --rm -v $(pwd)/.cargo:/root/.cargo -v $(pwd):/fast-escape -w /fast-escape builder sh -c "yarn build --musl"
+          docker run --rm -v ~/.cargo/git:/root/.cargo/git -v ~/.cargo/registry:/root/.cargo/registry -v $(pwd):/${{ env.APP_NAME }} -e DEBUG="napi:*" -w /${{ env.APP_NAME }} builder sh -c "yarn build"
+
       - name: Upload artifact
         uses: actions/upload-artifact@v2
         with:
           name: bindings-linux-musl
-          path: package-template.linux-musl.node
+          path: ${{ env.APP_NAME }}.*.node
+
+  build-linux-arm7:
+    name: stable - arm7-unknown-linux-gnu - node@14
+    runs-on: ubuntu-latest
+
+    steps:
+      - run: docker run --rm --privileged multiarch/qemu-user-static:register --reset
+
+      - uses: actions/checkout@v2
+
+      - name: Setup node
+        uses: actions/setup-node@v1
+        with:
+          node-version: 14
+
+      - name: Install
+        uses: actions-rs/toolchain@v1
+        with:
+          toolchain: stable
+          profile: minimal
+          override: true
+
+      - name: Generate Cargo.lock
+        uses: actions-rs/cargo@v1
+        with:
+          command: generate-lockfile
+
+      - name: Cache cargo registry
+        uses: actions/cache@v1
+        with:
+          path: ~/.cargo/registry
+          key: stable-linux-arm7-gnu-node@14-cargo-registry-trimmed-${{ hashFiles('**/Cargo.lock') }}
+
+      - name: Cache cargo index
+        uses: actions/cache@v1
+        with:
+          path: ~/.cargo/git
+          key: stable-linux-arm7-gnu-node@14-cargo-index-trimmed-${{ hashFiles('**/Cargo.lock') }}
+
+      - name: Cache NPM dependencies
+        uses: actions/cache@v1
+        with:
+          path: node_modules
+          key: npm-cache-linux-arm7-gnu-node@14-${{ hashFiles('yarn.lock') }}
+
+      - name: Install aarch64 toolchain
+        run: rustup target add armv7-unknown-linux-gnueabihf
+
+      - name: Install cross compile toolchain
+        run: |
+          sudo apt-get update
+          sudo apt-get install gcc-arm-linux-gnueabihf -y
+
+      - name: Install dependencies
+        run: yarn install --frozen-lockfile --registry https://registry.npmjs.org --network-timeout 300000
+
+      - name: Cross build arm7
+        run: yarn build --target armv7-unknown-linux-gnueabihf
+
+      - name: Upload artifact
+        uses: actions/upload-artifact@v2
+        with:
+          name: bindings-linux-arm7
+          path: ${{ env.APP_NAME }}.*.node
+
+  build-linux-aarch64:
+    name: stable - aarch64-unknown-linux-gnu - node@14
+    runs-on: ubuntu-latest
+
+    steps:
+      - run: docker run --rm --privileged multiarch/qemu-user-static:register --reset
+
+      - uses: actions/checkout@v2
+
+      - name: Setup node
+        uses: actions/setup-node@v2-beta
+        with:
+          node-version: 14
+          check-latest: true
+
+      - name: Install
+        uses: actions-rs/toolchain@v1
+        with:
+          toolchain: stable
+          profile: minimal
+          override: true
+
+      - name: Install aarch64 toolchain
+        run: rustup target add aarch64-unknown-linux-gnu
+
+      - name: Generate Cargo.lock
+        uses: actions-rs/cargo@v1
+        with:
+          command: generate-lockfile
+
+      - name: Cache cargo registry
+        uses: actions/cache@v1
+        with:
+          path: ~/.cargo/registry
+          key: stable-linux-aarch64-gnu-node@14-cargo-registry-trimmed-${{ hashFiles('**/Cargo.lock') }}
+
+      - name: Cache cargo index
+        uses: actions/cache@v1
+        with:
+          path: ~/.cargo/git
+          key: stable-linux-aarch64-gnu-node@14-cargo-index-trimmed-${{ hashFiles('**/Cargo.lock') }}
+
+      - name: Cache NPM dependencies
+        uses: actions/cache@v1
+        with:
+          path: node_modules
+          key: npm-cache-linux-aarch64-gnu-node@14-${{ hashFiles('yarn.lock') }}
+
+      - name: Install cross compile toolchain
+        run: |
+          sudo apt-get update
+          sudo apt-get install gcc-aarch64-linux-gnu g++-aarch64-linux-gnu -y
+
+      - name: Install dependencies
+        run: yarn install --frozen-lockfile --registry https://registry.npmjs.org --network-timeout 300000
+
+      - name: Cross build aarch64
+        run: yarn build --target aarch64-unknown-linux-gnu
+
+      - name: Upload artifact
+        uses: actions/upload-artifact@v2
+        with:
+          name: bindings-linux-aarch64
+          path: ${{ env.APP_NAME }}.*.node
 
-  test_binding:
+  build-apple-silicon:
+    name: nightly - aarch64-apple-darwin - node@14
+    runs-on: macos-latest
+
+    steps:
+      - uses: actions/checkout@v2
+
+      - name: Setup node
+        uses: actions/setup-node@v2-beta
+        with:
+          node-version: 14
+          check-latest: true
+
+      - name: Install
+        uses: actions-rs/toolchain@v1
+        with:
+          toolchain: nightly
+          profile: minimal
+          override: true
+
+      - name: Install aarch64 toolchain
+        run: rustup target add aarch64-apple-darwin
+
+      - name: Generate Cargo.lock
+        uses: actions-rs/cargo@v1
+        with:
+          command: generate-lockfile
+
+      - name: Cache cargo registry
+        uses: actions/cache@v1
+        with:
+          path: ~/.cargo/registry
+          key: nightly-apple-aarch64-node@14-cargo-registry-trimmed-${{ hashFiles('**/Cargo.lock') }}
+
+      - name: Cache cargo index
+        uses: actions/cache@v1
+        with:
+          path: ~/.cargo/git
+          key: nightly-apple-aarch64-node@14-cargo-index-trimmed-${{ hashFiles('**/Cargo.lock') }}
+
+      - name: Cache NPM dependencies
+        uses: actions/cache@v1
+        with:
+          path: node_modules
+          key: npm-cache-apple-aarch64-node@14-${{ hashFiles('yarn.lock') }}
+
+      - name: Install dependencies
+        run: yarn install --frozen-lockfile --registry https://registry.npmjs.org --network-timeout 300000
+
+      - name: Cross build aarch64
+        run: yarn build --target aarch64-apple-darwin
+
+      - name: Upload artifact
+        uses: actions/upload-artifact@v2
+        with:
+          name: bindings-apple-aarch64
+          path: ${{ env.APP_NAME }}.*.node
+
+  build-android-aarch64:
+    name: Build - Android - aarch64
+    runs-on: macos-latest
+    steps:
+      - uses: actions/checkout@v2
+
+      - name: Setup node
+        uses: actions/setup-node@v1
+        with:
+          node-version: 14
+
+      - name: Install aarch64 toolchain
+        run: rustup target add aarch64-linux-android
+
+      - name: Generate Cargo.lock
+        uses: actions-rs/cargo@v1
+        with:
+          command: generate-lockfile
+
+      - name: Cache cargo registry
+        uses: actions/cache@v1
+        with:
+          path: ~/.cargo/registry
+          key: nightly-apple-aarch64-node@14-cargo-registry-trimmed-${{ hashFiles('**/Cargo.lock') }}
+
+      - name: Cache cargo index
+        uses: actions/cache@v1
+        with:
+          path: ~/.cargo/git
+          key: nightly-apple-aarch64-node@14-cargo-index-trimmed-${{ hashFiles('**/Cargo.lock') }}
+
+      - name: Cache NPM dependencies
+        uses: actions/cache@v1
+        with:
+          path: node_modules
+          key: npm-cache-apple-aarch64-node@14-${{ hashFiles('yarn.lock') }}
+
+      - name: Install dependencies
+        run: yarn install --frozen-lockfile --registry https://registry.npmjs.org --network-timeout 300000
+
+      - name: Build
+        shell: bash
+        run: |
+          export CARGO_TARGET_AARCH64_LINUX_ANDROID_LINKER="${ANDROID_NDK_HOME}/toolchains/llvm/prebuilt/darwin-x86_64/bin/aarch64-linux-android24-clang"
+          yarn build --target aarch64-linux-android
+
+      - name: Upload artifact
+        uses: actions/upload-artifact@v2
+        with:
+          name: bindings-android-aarch64
+          path: ${{ env.APP_NAME }}.*.node
+
+  test:
     name: Test bindings on ${{ matrix.os }} - node@${{ matrix.node }}
     needs:
       - build
@@ -141,31 +391,31 @@ jobs:
       fail-fast: false
       matrix:
         os: [ubuntu-latest, macos-latest, windows-latest]
-        node: ['10', '12', '14']
+        node: ['10', '12', '14', '15']
     runs-on: ${{ matrix.os }}
 
     steps:
       - uses: actions/checkout@v2
 
       - name: Setup node
-        uses: actions/setup-node@v1
+        uses: actions/setup-node@v2-beta
         with:
           node-version: ${{ matrix.node }}
+          check-latest: true
 
-      - name: Set platform name
-        run: |
-          export NODE_PLATFORM_NAME=$(node -e "console.log(require('os').platform())")
-          echo "PLATFORM_NAME=${NODE_PLATFORM_NAME}" >> $GITHUB_ENV
-        shell: bash
+      - name: Cache NPM dependencies
+        uses: actions/cache@v1
+        with:
+          path: node_modules
+          key: npm-cache-test-${{ matrix.os }}-node@${{ matrix.node }}-${{ hashFiles('yarn.lock') }}
 
-      # Do not cache node_modules, or yarn workspace links broken
       - name: 'Install dependencies'
-        run: yarn install --frozen-lockfile --registry https://registry.npmjs.org
+        run: yarn install --frozen-lockfile --registry https://registry.npmjs.org --network-timeout 300000
 
       - name: Download artifacts
         uses: actions/download-artifact@v2
         with:
-          name: bindings-${{ env.PLATFORM_NAME }}
+          name: bindings-${{ matrix.os }}
           path: .
 
       - name: List packages
@@ -175,19 +425,25 @@ jobs:
       - name: Test bindings
         run: yarn test
 
-  test_musl_binding:
+  test-musl:
     name: Test bindings on alpine - node@${{ matrix.node }}
     needs:
-      - build_musl
+      - build-linux-musl
     strategy:
       fail-fast: false
       matrix:
-        node: ['12', '14']
+        node: ['10', '12', '14', '15']
     runs-on: ubuntu-latest
 
     steps:
       - uses: actions/checkout@v2
 
+      - name: Cache NPM dependencies
+        uses: actions/cache@v1
+        with:
+          path: node_modules
+          key: npm-cache-alpine-node@${{ matrix.node }}-${{ hashFiles('yarn.lock') }}
+
       - name: 'Install dependencies'
         run: yarn install --frozen-lockfile --ignore-scripts --registry https://registry.npmjs.org
 
@@ -201,13 +457,69 @@ jobs:
         run: ls -R .
         shell: bash
 
-      - name: Run simple tests
-        run: docker run --rm -v $(pwd)/.cargo:/root/.cargo -v $(pwd):/fast-escape -w /fast-escape node:${{ matrix.node }}-alpine sh -c "node ./simple-test.js"
+      - name: Run tests
+        run: docker run --rm -v $(pwd):/${{ env.APP_NAME }} -w /${{ env.APP_NAME }} node:${{ matrix.node }}-alpine sh -c "yarn test"
+
+  test-aarch64:
+    name: stable - aarch64-unknown-linux-gnu - node@${{ matrix.node }}
+    runs-on: ubuntu-latest
+
+    needs:
+      - build-linux-aarch64
+    strategy:
+      fail-fast: false
+      matrix:
+        node: ['10', '12', '14', '15']
+
+    steps:
+      - run: docker run --rm --privileged multiarch/qemu-user-static:register --reset
+
+      - uses: actions/checkout@v2
+
+      - name: Setup node
+        uses: actions/setup-node@v2-beta
+        with:
+          node-version: ${{ matrix.node }}
+          check-latest: true
+
+      - name: Cache NPM dependencies
+        uses: actions/cache@v1
+        with:
+          path: node_modules
+          key: npm-cache-test-linux-aarch64-gnu-node@${{ matrix.node }}-${{ hashFiles('yarn.lock') }}
+
+      - name: 'Install dependencies'
+        run: yarn install --frozen-lockfile --registry https://registry.npmjs.org --network-timeout 300000
+
+      - name: Download artifacts
+        uses: actions/download-artifact@v2
+        with:
+          name: bindings-linux-aarch64
+          path: .
+
+      - name: List
+        run: ls -a
+
+      - name: Run tests
+        uses: docker://multiarch/ubuntu-core:arm64-focal
+        with:
+          args: >
+            sh -c "
+              apt-get update && \
+              apt-get install -y ca-certificates gnupg2 curl && \
+              curl -sL https://deb.nodesource.com/setup_${{ matrix.node }}.x | bash - && \
+              apt-get install -y nodejs && \
+              node ./simple-test.js
+            "
 
   dependabot:
     needs:
-      - test_binding
-      - test_musl_binding
+      - test
+      - test-musl
+      - test-aarch64
+      - build-apple-silicon
+      - build-linux-arm7
+      - build-android-aarch64
     runs-on: ubuntu-latest
     steps:
       - name: auto-merge
@@ -220,26 +532,30 @@ jobs:
     name: Publish
     runs-on: ubuntu-latest
     needs:
-      - test_binding
-      - test_musl_binding
+      - test
+      - test-musl
+      - test-aarch64
+      - build-apple-silicon
+      - build-linux-arm7
+      - build-android-aarch64
 
     steps:
       - uses: actions/checkout@v2
 
       - name: Setup node
-        uses: actions/setup-node@v1
+        uses: actions/setup-node@v2-beta
         with:
-          node-version: 12
+          node-version: 14
+          check-latest: true
 
       - name: Cache NPM dependencies
         uses: actions/cache@v1
         with:
           path: node_modules
-          key: npm-cache-ubuntu-latest-${{ hashFiles('yarn.lock') }}
-          restore-keys: |
-            npm-cache-
+          key: npm-cache-publish-ubuntu-latest-${{ hashFiles('yarn.lock') }}
+
       - name: 'Install dependencies'
-        run: yarn install --frozen-lockfile --registry https://registry.npmjs.org
+        run: yarn install --frozen-lockfile --registry https://registry.npmjs.org --network-timeout 300000
 
       - name: Download all artifacts
         uses: actions/download-artifact@v2
@@ -250,7 +566,7 @@ jobs:
         run: yarn artifacts
 
       - name: List packages
-        run: ls -R .
+        run: ls -R npm
         shell: bash
 
       - name: Publish

+ 47 - 0
.github/workflows/lint.yaml

@@ -0,0 +1,47 @@
+name: Lint
+
+on:
+  push:
+    branches:
+      - main
+    tags-ignore:
+      - '**'
+  pull_request:
+
+jobs:
+  lint:
+    name: Lint
+    runs-on: ubuntu-latest
+    steps:
+      - uses: actions/checkout@v2
+
+      - name: Setup node
+        uses: actions/setup-node@v1
+        with:
+          node-version: 14
+
+      - name: Install
+        uses: actions-rs/toolchain@v1
+        with:
+          toolchain: stable
+          profile: minimal
+          override: true
+          components: rustfmt, clippy
+
+      - name: Cache NPM dependencies
+        uses: actions/cache@v1
+        with:
+          path: node_modules
+          key: npm-cache-lint-node@14-${{ hashFiles('yarn.lock') }}
+
+      - name: 'Install dependencies'
+        run: yarn install --frozen-lockfile --registry https://registry.npmjs.org --network-timeout 300000
+
+      - name: ESLint
+        run: yarn lint
+
+      - name: Cargo fmt
+        run: cargo fmt -- --check
+
+      - name: Clippy
+        run: cargo clippy

+ 6 - 7
Cargo.toml

@@ -10,18 +10,17 @@ version = "0.1.0"
 crate-type = ["cdylib"]
 
 [dependencies]
-napi = {version = "0.5"}
-napi-derive = {version = "0.5"}
+napi = "1.0.0-alpha.1"
+napi-derive = "1.0.0-alpha.0"
 
-[target.'cfg(all(unix, not(target_env = "musl")))'.dependencies]
+[target.'cfg(all(unix, not(target_env = "musl"), not(target_arch = "aarch64")))'.dependencies]
 jemallocator = {version = "0.3", features = ["disable_initial_exec_tls"]}
 
-[target.'cfg(windows)'.dependencies]
+[target.'cfg(all(windows, target_arch = "x86_64"))'.dependencies]
 mimalloc = {version = "0.1"}
 
 [build-dependencies]
-napi-build = "0.2"
+napi-build = "1.0.0-alpha.0"
 
 [profile.release]
-lto = true
-opt-level = 3
+codegen-units = 1

+ 7 - 7
README.md

@@ -14,15 +14,15 @@ yarn add @napi-rs/package-template
 
 ### Operating Systems
 
-| Linux | macOS | Windows x64 MSVC |
-| ----- | ----- | ---------------- |
-| ✓     | ✓     | ✓                |
+| Linux x64/aarch64 | macOS x64/aarch64 | Windows x64 |
+| ----------------- | ----------------- | ----------- |
+| ✓                 | ✓                 | ✓           |
 
 ### NodeJS
 
-| Node10 | Node 12 | Node14 |
-| ------ | ------- | ------ |
-| ✓      | ✓       | ✓      |
+| Node10 | Node 12 | Node14 | Node15 |
+| ------ | ------- | ------ | ------ |
+| ✓      | ✓       | ✓      | ✓      |
 
 ## Ability
 
@@ -53,7 +53,7 @@ In this package we choose a better way to solve this problem. We release differe
 ## Develop requirements
 
 - Install latest `Rust`
-- Install `NodeJS@8.9+` which supported `N-API`
+- Install `NodeJS@10+` which fully supported `N-API`
 - Install `yarn@1.x`
 
 ## Test in local

+ 3 - 0
npm/android-arm64/README.md

@@ -0,0 +1,3 @@
+# `@napi-rs/package-template-android-arm64`
+
+This is the **aarch64-linux-android** binary for `@napi-rs/package-template`

+ 19 - 0
npm/android-arm64/package.json

@@ -0,0 +1,19 @@
+{
+  "name": "@napi-rs/package-template-android-arm64",
+  "version": "0.0.8",
+  "os": ["android"],
+  "cpu": ["arm64"],
+  "main": "package-template.android-arm64.node",
+  "files": ["package-template.android-arm64.node"],
+  "description": "Template project for writing node package with napi-rs",
+  "keywords": ["napi-rs", "NAPI", "N-API", "Rust", "node-addon", "node-addon-api"],
+  "license": "MIT",
+  "engines": {
+    "node": ">= 10"
+  },
+  "publishConfig": {
+    "registry": "https://registry.npmjs.org/",
+    "access": "public"
+  },
+  "repository": "git@github.com:napi-rs/package-template.git"
+}

+ 3 - 0
npm/darwin-arm64/README.md

@@ -0,0 +1,3 @@
+# `@napi-rs/package-template-darwin-arm64`
+
+This is the **aarch64-apple-darwin** binary for `@napi-rs/package-template`

+ 19 - 0
npm/darwin-arm64/package.json

@@ -0,0 +1,19 @@
+{
+  "name": "@napi-rs/package-template-darwin-arm64",
+  "version": "0.0.8",
+  "os": ["darwin"],
+  "cpu": ["arm64"],
+  "main": "package-template.darwin-arm64.node",
+  "files": ["package-template.darwin-arm64.node"],
+  "description": "Template project for writing node package with napi-rs",
+  "keywords": ["napi-rs", "NAPI", "N-API", "Rust", "node-addon", "node-addon-api"],
+  "license": "MIT",
+  "engines": {
+    "node": ">= 10"
+  },
+  "publishConfig": {
+    "registry": "https://registry.npmjs.org/",
+    "access": "public"
+  },
+  "repository": "git@github.com:napi-rs/package-template.git"
+}

+ 3 - 0
npm/darwin-x64/README.md

@@ -0,0 +1,3 @@
+# `@napi-rs/package-template-darwin-x64`
+
+This is the **x86_64-apple-darwin** binary for `@napi-rs/package-template`

+ 5 - 5
npm/darwin/package.json

@@ -1,15 +1,15 @@
 {
-  "name": "@napi-rs/package-template-darwin",
+  "name": "@napi-rs/package-template-darwin-x64",
   "version": "0.0.8",
   "os": ["darwin"],
-  "main": "package-template.darwin.node",
-  "files": ["package-template.darwin.node"],
+  "cpu": ["x64"],
+  "main": "package-template.darwin-x64.node",
+  "files": ["package-template.darwin-x64.node"],
   "description": "Template project for writing node package with napi-rs",
   "keywords": ["napi-rs", "NAPI", "N-API", "Rust", "node-addon", "node-addon-api"],
   "license": "MIT",
-  "cpu": ["x64"],
   "engines": {
-    "node": ">= 8.9"
+    "node": ">= 10"
   },
   "publishConfig": {
     "registry": "https://registry.npmjs.org/",

+ 0 - 3
npm/darwin/README.md

@@ -1,3 +0,0 @@
-# `@napi-rs/package-template-darwin`
-
-This is the **darwin** 64-bit binary for `@napi-rs/package-template`

+ 3 - 0
npm/linux-arm-gnueabihf/README.md

@@ -0,0 +1,3 @@
+# `@napi-rs/package-template-linux-arm-gnueabihf`
+
+This is the **armv7-unknown-linux-gnueabihf** binary for `@napi-rs/package-template`

+ 19 - 0
npm/linux-arm-gnueabihf/package.json

@@ -0,0 +1,19 @@
+{
+  "name": "@napi-rs/package-template-linux-arm-gnueabihf",
+  "version": "0.0.8",
+  "os": ["linux"],
+  "cpu": ["arm"],
+  "main": "package-template.linux-arm-gnueabihf.node",
+  "files": ["package-template.linux-arm-gnueabihf.node"],
+  "description": "Template project for writing node package with napi-rs",
+  "keywords": ["napi-rs", "NAPI", "N-API", "Rust", "node-addon", "node-addon-api"],
+  "license": "MIT",
+  "engines": {
+    "node": ">= 10"
+  },
+  "publishConfig": {
+    "registry": "https://registry.npmjs.org/",
+    "access": "public"
+  },
+  "repository": "git@github.com:napi-rs/package-template.git"
+}

+ 3 - 0
npm/linux-arm64-gnu/README.md

@@ -0,0 +1,3 @@
+# `@napi-rs/package-template-linux-arm64-gnu`
+
+This is the **aarch64-unknown-linux-gnu** binary for `@napi-rs/package-template`

+ 19 - 0
npm/linux-arm64-gnu/package.json

@@ -0,0 +1,19 @@
+{
+  "name": "@napi-rs/package-template-linux-arm64-gnu",
+  "version": "0.0.8",
+  "os": ["linux"],
+  "cpu": ["arm64"],
+  "main": "package-template.linux-arm64-gnu.node",
+  "files": ["package-template.linux-arm64-gnu.node"],
+  "description": "Template project for writing node package with napi-rs",
+  "keywords": ["napi-rs", "NAPI", "N-API", "Rust", "node-addon", "node-addon-api"],
+  "license": "MIT",
+  "engines": {
+    "node": ">= 10"
+  },
+  "publishConfig": {
+    "registry": "https://registry.npmjs.org/",
+    "access": "public"
+  },
+  "repository": "git@github.com:napi-rs/package-template.git"
+}

+ 0 - 3
npm/linux-musl/README.md

@@ -1,3 +0,0 @@
-# `@napi-rs/package-template-linux-musl`
-
-This is the **linux-musl** 64-bit binary for `@napi-rs/package-template`

+ 3 - 0
npm/linux-x64-gnu/README.md

@@ -0,0 +1,3 @@
+# `@napi-rs/package-template-linux-x64-gnu`
+
+This is the **x86_64-unknown-linux-gnu** binary for `@napi-rs/package-template`

+ 5 - 5
npm/linux/package.json

@@ -1,15 +1,15 @@
 {
-  "name": "@napi-rs/package-template-linux",
+  "name": "@napi-rs/package-template-linux-x64-gnu",
   "version": "0.0.8",
   "os": ["linux"],
-  "main": "package-template.linux.node",
-  "files": ["package-template.linux.node"],
+  "cpu": ["x64"],
+  "main": "package-template.linux-x64-gnu.node",
+  "files": ["package-template.linux-x64-gnu.node"],
   "description": "Template project for writing node package with napi-rs",
   "keywords": ["napi-rs", "NAPI", "N-API", "Rust", "node-addon", "node-addon-api"],
   "license": "MIT",
-  "cpu": ["x64"],
   "engines": {
-    "node": ">= 8.9"
+    "node": ">= 10"
   },
   "publishConfig": {
     "registry": "https://registry.npmjs.org/",

+ 3 - 0
npm/linux-x64-musl/README.md

@@ -0,0 +1,3 @@
+# `@napi-rs/package-template-linux-x64-musl`
+
+This is the **x86_64-unknown-linux-musl** binary for `@napi-rs/package-template`

+ 5 - 5
npm/linux-musl/package.json

@@ -1,15 +1,15 @@
 {
-  "name": "@napi-rs/package-template-linux-musl",
+  "name": "@napi-rs/package-template-linux-x64-musl",
   "version": "0.0.8",
   "os": ["linux"],
-  "main": "package-template.linux-musl.node",
-  "files": ["package-template.linux-musl.node"],
+  "cpu": ["x64"],
+  "main": "package-template.linux-x64-musl.node",
+  "files": ["package-template.linux-x64-musl.node"],
   "description": "Template project for writing node package with napi-rs",
   "keywords": ["napi-rs", "NAPI", "N-API", "Rust", "node-addon", "node-addon-api"],
   "license": "MIT",
-  "cpu": ["x64"],
   "engines": {
-    "node": ">= 8.9"
+    "node": ">= 10"
   },
   "publishConfig": {
     "registry": "https://registry.npmjs.org/",

+ 0 - 3
npm/linux/README.md

@@ -1,3 +0,0 @@
-# `@napi-rs/package-template-linux`
-
-This is the **linux** 64-bit binary for `@napi-rs/package-template`

+ 3 - 0
npm/win32-x64-msvc/README.md

@@ -0,0 +1,3 @@
+# `@napi-rs/package-template-win32-x64-msvc`
+
+This is the **x86_64-pc-windows-msvc** binary for `@napi-rs/package-template`

+ 5 - 5
npm/win32/package.json

@@ -1,15 +1,15 @@
 {
-  "name": "@napi-rs/package-template-win32",
+  "name": "@napi-rs/package-template-win32-x64-msvc",
   "version": "0.0.8",
   "os": ["win32"],
-  "main": "package-template.win32.node",
-  "files": ["package-template.win32.node"],
+  "cpu": ["x64"],
+  "main": "package-template.win32-x64-msvc.node",
+  "files": ["package-template.win32-x64-msvc.node"],
   "description": "Template project for writing node package with napi-rs",
   "keywords": ["napi-rs", "NAPI", "N-API", "Rust", "node-addon", "node-addon-api"],
   "license": "MIT",
-  "cpu": ["x64"],
   "engines": {
-    "node": ">= 8.9"
+    "node": ">= 10"
   },
   "publishConfig": {
     "registry": "https://registry.npmjs.org/",

+ 0 - 3
npm/win32/README.md

@@ -1,3 +0,0 @@
-# `@napi-rs/package-template-win32`
-
-This is the **win32** 64-bit binary for `@napi-rs/package-template`

+ 20 - 15
package.json

@@ -7,14 +7,21 @@
   "license": "MIT",
   "keywords": ["napi-rs", "NAPI", "N-API", "Rust", "node-addon", "node-addon-api"],
   "files": ["index.d.ts", "index.js"],
-  "os": ["darwin", "linux", "win32"],
-  "cpu": ["x64"],
   "napi": {
     "name": "package-template",
-    "musl": ["linux"]
+    "triples": {
+      "defaults": true,
+      "additional": [
+        "x86_64-unknown-linux-musl",
+        "aarch64-unknown-linux-gnu",
+        "armv7-unknown-linux-gnueabihf",
+        "aarch64-apple-darwin",
+        "aarch64-linux-android"
+      ]
+    }
   },
   "engines": {
-    "node": ">= 8.9"
+    "node": ">= 10"
   },
   "publishConfig": {
     "registry": "https://registry.npmjs.org/",
@@ -22,9 +29,9 @@
   },
   "scripts": {
     "artifacts": "napi artifacts",
-    "bench": "node -r @swc-node/register benchmark/bench.ts",
-    "build": "cargo build --release && napi build --platform --release",
-    "build:debug": "cargo build && napi build --platform",
+    "bench": "node -r ts-node/register/transpile-only benchmark/bench.ts",
+    "build": "napi build --platform --release",
+    "build:debug": "napi build --platform",
     "format": "run-p format:md format:json format:yaml format:source format:rs",
     "format:md": "prettier --parser markdown --write './**/*.md'",
     "format:json": "prettier --parser json --write './**/*.json'",
@@ -37,7 +44,7 @@
     "version": "napi version"
   },
   "devDependencies": {
-    "@swc-node/register": "^1.0.2",
+    "@napi-rs/cli": "^1.0.0-alpha.10",
     "@typescript-eslint/eslint-plugin": "^4.10.0",
     "@typescript-eslint/parser": "^4.10.0",
     "ava": "^3.14.0",
@@ -46,19 +53,17 @@
     "eslint": "^7.15.0",
     "eslint-config-prettier": "^7.0.0",
     "eslint-plugin-import": "^2.22.1",
-    "eslint-plugin-prettier": "^3.2.0",
-    "eslint-plugin-react": "^7.21.5",
-    "eslint-plugin-react-hooks": "^4.2.0",
+    "eslint-plugin-prettier": "^3.3.0",
     "eslint-plugin-sonarjs": "^0.5.0",
     "husky": "^4.3.6",
     "lint-staged": "^10.5.3",
-    "napi-rs": "^0.3.10",
     "npm-run-all": "^4.1.5",
     "prettier": "^2.2.1",
+    "ts-node": "^9.1.1",
     "typescript": "^4.1.3"
   },
   "dependencies": {
-    "@node-rs/helper": "^0.4.0"
+    "@node-rs/helper": "^1.0.0-alpha.3"
   },
   "lint-staged": {
     "*.@(js|ts|tsx)": ["prettier --write", "eslint -c .eslintrc.yml --fix"],
@@ -67,10 +72,10 @@
     "*.json": ["prettier --parser json --write"]
   },
   "ava": {
-    "require": ["@swc-node/register"],
+    "require": ["ts-node/register/transpile-only"],
     "extensions": ["ts"],
     "environmentVariables": {
-      "SWC_NODE_PROJECT": "./tsconfig.json"
+      "TS_NODE_PROJECT": "./tsconfig.json"
     }
   },
   "prettier": {

+ 12 - 12
src/lib.rs

@@ -1,22 +1,20 @@
-#[macro_use]
-extern crate napi;
+#![deny(clippy::all)]
+
 #[macro_use]
 extern crate napi_derive;
 
 use std::convert::TryInto;
 
-use napi::{CallContext, Env, JsNumber, JsObject, Module, Result, Task};
+use napi::{CallContext, Env, JsNumber, JsObject, Result, Task};
 
-#[cfg(all(unix, not(target_env = "musl")))]
+#[cfg(all(unix, not(target_env = "musl"), not(target_arch = "aarch64")))]
 #[global_allocator]
 static ALLOC: jemallocator::Jemalloc = jemallocator::Jemalloc;
 
-#[cfg(windows)]
+#[cfg(all(windows, target_arch = "x86_64"))]
 #[global_allocator]
 static ALLOC: mimalloc::MiMalloc = mimalloc::MiMalloc;
 
-register_module!(example, init);
-
 struct AsyncTask(u32);
 
 impl Task for AsyncTask {
@@ -30,15 +28,16 @@ impl Task for AsyncTask {
     Ok(self.0 * 2)
   }
 
-  fn resolve(&self, env: &mut Env, output: Self::Output) -> Result<Self::JsValue> {
+  fn resolve(self, env: Env, output: Self::Output) -> Result<Self::JsValue> {
     env.create_uint32(output)
   }
 }
 
-fn init(module: &mut Module) -> Result<()> {
-  module.create_named_method("sync", sync_fn)?;
+#[module_exports]
+fn init(mut exports: JsObject) -> Result<()> {
+  exports.create_named_method("sync", sync_fn)?;
 
-  module.create_named_method("sleep", sleep)?;
+  exports.create_named_method("sleep", sleep)?;
   Ok(())
 }
 
@@ -53,5 +52,6 @@ fn sync_fn(ctx: CallContext) -> Result<JsNumber> {
 fn sleep(ctx: CallContext) -> Result<JsObject> {
   let argument: u32 = ctx.get::<JsNumber>(0)?.try_into()?;
   let task = AsyncTask(argument);
-  ctx.env.spawn(task)
+  let async_task = ctx.env.spawn(task)?;
+  Ok(async_task.promise_object())
 }

File diff suppressed because it is too large
+ 348 - 461
yarn.lock