Skip to content

Commit

Permalink
chore(bindings/nodejs): Fix generated headers (#1802)
Browse files Browse the repository at this point in the history
* chore(bindings/nodejs): Fix generated headers

Signed-off-by: Xuanwo <github@xuanwo.io>

* Add check for format

Signed-off-by: Xuanwo <github@xuanwo.io>

* Fix typo

Signed-off-by: Xuanwo <github@xuanwo.io>

---------

Signed-off-by: Xuanwo <github@xuanwo.io>
  • Loading branch information
Xuanwo authored Mar 30, 2023
1 parent 04456bf commit 3488ec3
Show file tree
Hide file tree
Showing 5 changed files with 86 additions and 14 deletions.
5 changes: 5 additions & 0 deletions .github/workflows/bindings_nodejs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -59,10 +59,15 @@ jobs:
node-version: ${{ matrix.node }}
cache: yarn
cache-dependency-path: "bindings/nodejs/yarn.lock"

- name: Corepack
run: corepack enable
- name: Install dependencies
run: yarn install

- name: Check format
run: yarn run prettier --check .

- name: Build
run: yarn build:debug
- name: Test bindings
Expand Down
6 changes: 3 additions & 3 deletions bindings/nodejs/benchmark/lib.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ const client = new S3Client({

module.exports.opendal = {
read: (path) => opendal.read(path),
write: (path, data) => opendal.write(path, data)
write: (path, data) => opendal.write(path, data),
}

module.exports.s3 = {
Expand All @@ -73,7 +73,7 @@ module.exports.s3 = {
Bucket: bucket,
})
return client.send(command)
}
},
}

module.exports.testFiles = testFiles
module.exports.testFiles = testFiles
36 changes: 27 additions & 9 deletions bindings/nodejs/generated.js
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,9 @@ switch (platform) {
case 'win32':
switch (arch) {
case 'x64':
localFileExisted = existsSync(join(__dirname, 'opendal.win32-x64-msvc.node'))
localFileExisted = existsSync(
join(__dirname, 'opendal.win32-x64-msvc.node')
)
try {
if (localFileExisted) {
nativeBinding = require('./opendal.win32-x64-msvc.node')
Expand All @@ -93,7 +95,9 @@ switch (platform) {
}
break
case 'ia32':
localFileExisted = existsSync(join(__dirname, 'opendal.win32-ia32-msvc.node'))
localFileExisted = existsSync(
join(__dirname, 'opendal.win32-ia32-msvc.node')
)
try {
if (localFileExisted) {
nativeBinding = require('./opendal.win32-ia32-msvc.node')
Expand All @@ -105,7 +109,9 @@ switch (platform) {
}
break
case 'arm64':
localFileExisted = existsSync(join(__dirname, 'opendal.win32-arm64-msvc.node'))
localFileExisted = existsSync(
join(__dirname, 'opendal.win32-arm64-msvc.node')
)
try {
if (localFileExisted) {
nativeBinding = require('./opendal.win32-arm64-msvc.node')
Expand Down Expand Up @@ -144,7 +150,9 @@ switch (platform) {
}
break
case 'arm64':
localFileExisted = existsSync(join(__dirname, 'opendal.darwin-arm64.node'))
localFileExisted = existsSync(
join(__dirname, 'opendal.darwin-arm64.node')
)
try {
if (localFileExisted) {
nativeBinding = require('./opendal.darwin-arm64.node')
Expand Down Expand Up @@ -178,7 +186,9 @@ switch (platform) {
switch (arch) {
case 'x64':
if (isMusl()) {
localFileExisted = existsSync(join(__dirname, 'opendal.linux-x64-musl.node'))
localFileExisted = existsSync(
join(__dirname, 'opendal.linux-x64-musl.node')
)
try {
if (localFileExisted) {
nativeBinding = require('./opendal.linux-x64-musl.node')
Expand All @@ -189,7 +199,9 @@ switch (platform) {
loadError = e
}
} else {
localFileExisted = existsSync(join(__dirname, 'opendal.linux-x64-gnu.node'))
localFileExisted = existsSync(
join(__dirname, 'opendal.linux-x64-gnu.node')
)
try {
if (localFileExisted) {
nativeBinding = require('./opendal.linux-x64-gnu.node')
Expand All @@ -203,7 +215,9 @@ switch (platform) {
break
case 'arm64':
if (isMusl()) {
localFileExisted = existsSync(join(__dirname, 'opendal.linux-arm64-musl.node'))
localFileExisted = existsSync(
join(__dirname, 'opendal.linux-arm64-musl.node')
)
try {
if (localFileExisted) {
nativeBinding = require('./opendal.linux-arm64-musl.node')
Expand All @@ -214,7 +228,9 @@ switch (platform) {
loadError = e
}
} else {
localFileExisted = existsSync(join(__dirname, 'opendal.linux-arm64-gnu.node'))
localFileExisted = existsSync(
join(__dirname, 'opendal.linux-arm64-gnu.node')
)
try {
if (localFileExisted) {
nativeBinding = require('./opendal.linux-arm64-gnu.node')
Expand All @@ -227,7 +243,9 @@ switch (platform) {
}
break
case 'arm':
localFileExisted = existsSync(join(__dirname, 'opendal.linux-arm-gnueabihf.node'))
localFileExisted = existsSync(
join(__dirname, 'opendal.linux-arm-gnueabihf.node')
)
try {
if (localFileExisted) {
nativeBinding = require('./opendal.linux-arm-gnueabihf.node')
Expand Down
4 changes: 2 additions & 2 deletions bindings/nodejs/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,8 @@
},
"scripts": {
"artifacts": "napi artifacts",
"build": "napi build --platform --release --js generated.js",
"build:debug": "napi build --platform --js generated.js",
"build": "napi build --platform --release --js generated.js && node ./scripts/header.js",
"build:debug": "napi build --platform --js generated.js && node ./scripts/header.js",
"docs": "typedoc",
"format": "prettier --write .",
"prepublishOnly": "napi prepublish -t npm",
Expand Down
49 changes: 49 additions & 0 deletions bindings/nodejs/scripts/header.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/

const fs = require('fs')

let files = ['generated.js', 'index.d.ts']

for (path of files) {
let data = fs.readFileSync(path, 'utf8')
fs.writeFileSync(
path,
`/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
` + data,
)
}

0 comments on commit 3488ec3

Please # to comment.