Skip to content
Merged
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
2 changes: 1 addition & 1 deletion .github/actions/build-test-wasm/action.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ runs:
wasm-pack build --target nodejs ./crates/${{ inputs.crate }} --out-dir ../../prebuilds/${{ inputs.crate }}
shell: bash
- name: Test WASM
run: node test_wasm.js ${{ inputs.crate }}
run: node test-wasm.js ${{ inputs.crate }}
shell: bash
- uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4.6.2
with:
Expand Down
11 changes: 11 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,17 @@ on:
- main

jobs:
lint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@34e114876b0b11c390a56381ad16ebd13914f8d5 # v4.3.1
- name: Setup Node.js
uses: actions/setup-node@49933ea5288caeca8642d1e84afbd3f7d6820020 # v4.4.0
- run: yarn install
- run: yarn install
working-directory: test/crashtracker
- run: yarn lint

build-test-wasm:
runs-on: ubuntu-latest
strategy:
Expand Down
1 change: 1 addition & 0 deletions .yarnrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
--ignore-engines true
72 changes: 72 additions & 0 deletions eslint.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
'use strict'

const eslintPluginImportX = require('eslint-plugin-import-x')
const eslintPluginJs = require('@eslint/js')
const eslintPluginN = require('eslint-plugin-n')
const eslintPluginStylistic = require('@stylistic/eslint-plugin')
const eslintPluginUnicorn = require('eslint-plugin-unicorn').default
const globals = require('globals')

module.exports = [
eslintPluginJs.configs.recommended,
eslintPluginImportX.flatConfigs.recommended,
eslintPluginN.configs['flat/recommended-script'],
eslintPluginStylistic.configs.recommended,
eslintPluginUnicorn.configs.recommended,
{
languageOptions: {
ecmaVersion: 2022,
sourceType: 'commonjs',
globals: {
...globals.es2022,
...globals.node,
},
},
settings: {
// Used by `eslint-plugin-n` to determine the minimum version of Node.js to support.
// Normally setting this in the `package.json` engines field is enough, but we can't use that as it will fail
// when running `yarn copy-artifacts` inside the prebuildify Docker container which uses Node.js 12.
node: { version: '>=18.0.0' },
},
rules: {
'@stylistic/brace-style': ['error', '1tbs'],
'@stylistic/space-before-function-paren': ['error', 'always'],
'import-x/extensions': ['error', 'never', { json: 'always' }],
'import-x/no-absolute-path': 'error',
'import-x/no-webpack-loader-syntax': 'error',
'import-x/order': ['error', {
'newlines-between': 'always',
}],
'n/no-process-exit': 'off', // Duplicate of unicorn/no-process-exit
'prefer-const': 'error',
'unicorn/prefer-module': 'off', // We use CJS
'unicorn/prevent-abbreviations': 'off',
},
},
{
files: ['load.js'],
languageOptions: {
globals: {
__webpack_require__: 'readonly',
__non_webpack_require__: 'readonly',
},
},
},
{
// This script runs inside the prebuildify Docker container which uses Node.js 12
files: ['scripts/copy-artifacts.js'],
languageOptions: {
ecmaVersion: 2019,
},
settings: {
// Used by `eslint-plugin-n` to determine the minimum version of Node.js to support.
node: { version: '>=12.0.0' },
},
rules: {
'unicorn/prefer-node-protocol': 'off',
},
},
{
ignores: ['build/', 'target/', 'prebuilds/'],
},
]
16 changes: 8 additions & 8 deletions load.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@

// TODO: Extract this file to an external library.

const { existsSync, readdirSync } = require('fs')
const os = require('os')
const path = require('path')
const { existsSync, readdirSync } = require('node:fs')
const os = require('node:os')
const path = require('node:path')

const PLATFORM = os.platform()
const ARCH = process.arch
const LIBC = PLATFORM === 'linux' ? existsSync('/etc/alpine-release') ? 'musl' : 'glibc' : ''
const LIBC = PLATFORM === 'linux' ? (existsSync('/etc/alpine-release') ? 'musl' : 'glibc') : ''
const ABI = process.versions.modules

const inWebpack = typeof __webpack_require__ === 'function'
Expand All @@ -17,7 +17,7 @@ const runtimeRequire = inWebpack ? __non_webpack_require__ : require
function maybeLoad (name) {
try {
return load(name)
} catch (e) {
} catch {
// Not found, skip.
}
}
Expand All @@ -40,7 +40,7 @@ function findWASM (name) {
const root = __dirname
const prebuilds = path.join(root, 'prebuilds')
const folders = readdirSync(prebuilds)
if (folders.find(f => f === name)) {
if (folders.includes(name)) {
return path.join(prebuilds, name, `${name.replaceAll('-', '_')}.js`)
}
}
Expand Down Expand Up @@ -76,8 +76,8 @@ function findFolder (root) {

return folders.find(f => f === `${PLATFORM}${LIBC}-${ARCH}`)
|| folders.find(f => f === `${PLATFORM}-${ARCH}`)
} catch (e) {
return null
} catch {
// Ignore
}
}

Expand Down
10 changes: 10 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
"cargo-build-release": "yarn -s cargo-build -- --release",
"cargo-build": "cargo build --message-format=json-render-diagnostics",
"copy-artifacts": "node ./scripts/copy-artifacts",
"lint": "eslint .",
"test": "bash scripts/test.sh"
},
"author": "Datadog Inc. <info@datadoghq.com>",
Expand All @@ -27,5 +28,14 @@
"homepage": "https://github.com/DataDog/libdatadog-nodejs#readme",
"publishConfig": {
"access": "public"
},
"devDependencies": {
"@eslint/js": "^10.0.1",
"@stylistic/eslint-plugin": "^5.9.0",
"eslint": "^10.0.2",
"eslint-plugin-import-x": "^4.12.2",
"eslint-plugin-n": "^17.24.0",
"eslint-plugin-unicorn": "^63.0.0",
"globals": "^17.4.0"
}
}
38 changes: 19 additions & 19 deletions scripts/build-wasm.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,42 +10,42 @@
// Our releases are built on Linux, and fortunately no special handling is required there. This
// script only allows development to happen on macOS.

const os = require('os');
const childProcess = require('child_process');
const os = require('node:os')
const childProcess = require('node:child_process')

const isMacOS = os.platform() === 'darwin';
const noWasmOpt = isMacOS ? '--no-opt' : '';
const library = process.argv[2];
const isMacOS = os.platform() === 'darwin'
const noWasmOpt = isMacOS ? '--no-opt' : ''
const library = process.argv[2]

const env = {
...process.env,
};
}

if (isMacOS) {
const homebrewDir = env.HOMEBREW_DIR ?? '/opt/homebrew';
const llvmDir = `${homebrewDir}/opt/llvm/`;
const llvmBinDir = `${llvmDir}/bin`;
const homebrewDir = env.HOMEBREW_DIR ?? '/opt/homebrew'
const llvmDir = `${homebrewDir}/opt/llvm/`
const llvmBinDir = `${llvmDir}/bin`

try {
childProcess.execSync(`${llvmBinDir}/llvm-config --version`);
} catch (error) {
console.error(`‼️ LLVM not found in ${llvmDir}.\n‼️ Please install LLVM using Homebrew:\n📝 brew install llvm`);
process.exit(1);
childProcess.execSync(`${llvmBinDir}/llvm-config --version`)
} catch {
console.error(`‼️ LLVM not found in ${llvmDir}.\n‼️ Please install LLVM using Homebrew:\n📝 brew install llvm`)
process.exit(1) // eslint-disable-line unicorn/no-process-exit
}

if (!env.PATH.includes(llvmBinDir)) {
// Add LLVM to PATH if not already included
env.PATH = `${llvmBinDir}:${env.PATH}`;
env.PATH = `${llvmBinDir}:${env.PATH}`
}

// Force C/C++ code (e.g. zstd-sys) to use Homebrew's clang for wasm32. Otherwise a global
// CC (e.g. ccache cc) can point at Apple Clang, which does not support wasm32-unknown-unknown.
env.CC_wasm32_unknown_unknown = `${llvmBinDir}/clang`;
env.CXX_wasm32_unknown_unknown = `${llvmBinDir}/clang++`;
env.CC_wasm32_unknown_unknown = `${llvmBinDir}/clang`
env.CXX_wasm32_unknown_unknown = `${llvmBinDir}/clang++`
}

childProcess.execSync(
`wasm-pack build ${noWasmOpt} --target nodejs ./crates/${library} --out-dir ../../prebuilds/${library}`, {
env
}
);
env,
},
)
2 changes: 1 addition & 1 deletion scripts/copy-artifacts.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ const outPath = path.join(rootPath, 'target', 'out.ndjson')
const buildPath = path.join(rootPath, 'build', 'Release')

const lineReader = readline.createInterface({
input: fs.createReadStream(outPath)
input: fs.createReadStream(outPath),
})

lineReader.on('line', function (line) {
Expand Down
6 changes: 6 additions & 0 deletions scripts/test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,12 @@
set -e

run_test() {
local dir
dir=$(dirname "$1")
if [ -f "${dir}/package.json" ]; then
echo "Installing dependencies for $1"
yarn --cwd "$dir" install
fi
echo "Running $1"
node "$1"
}
Expand Down
10 changes: 10 additions & 0 deletions test-wasm.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
'use strict'

const fs = require('node:fs')

const crateTestsDir = `./test/wasm/${process.argv[2]}`
const files = fs.readdirSync(crateTestsDir).filter(file => file.endsWith('.js') || !file.includes('.'))

for (const file of files) {
require(`${crateTestsDir}/${file}`)
}
4 changes: 3 additions & 1 deletion test/crashtracker/app-seg-fault.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
'use strict'

const libdatadog = require('../..')

const { initTestCrashtracker } = require('./test-utils')

const crashtracker = libdatadog.load('crashtracker')
const { initTestCrashtracker } = require('./test_utils')

initTestCrashtracker()
crashtracker.beginProfilerSerializing()
Expand Down
4 changes: 3 additions & 1 deletion test/crashtracker/app-uncaught-exception-non-error.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
'use strict'

const libdatadog = require('../..')

const { initTestCrashtracker } = require('./test-utils')

const crashtracker = libdatadog.load('crashtracker')
const { initTestCrashtracker } = require('./test_utils')

initTestCrashtracker()
crashtracker.beginProfilerSerializing()
Expand Down
4 changes: 3 additions & 1 deletion test/crashtracker/app-uncaught-exception.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
'use strict'

const libdatadog = require('../..')

const { initTestCrashtracker } = require('./test-utils')

const crashtracker = libdatadog.load('crashtracker')
const { initTestCrashtracker } = require('./test_utils')

initTestCrashtracker()
crashtracker.beginProfilerSerializing()
Expand Down
4 changes: 3 additions & 1 deletion test/crashtracker/app-unhandled-rejection-non-error.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
'use strict'

const libdatadog = require('../..')

const { initTestCrashtracker } = require('./test-utils')

const crashtracker = libdatadog.load('crashtracker')
const { initTestCrashtracker } = require('./test_utils')

initTestCrashtracker()
crashtracker.beginProfilerSerializing()
Expand Down
6 changes: 4 additions & 2 deletions test/crashtracker/app-unhandled-rejection.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
'use strict'

const libdatadog = require('../..')

const { initTestCrashtracker } = require('./test-utils')

const crashtracker = libdatadog.load('crashtracker')
const { initTestCrashtracker } = require('./test_utils')

initTestCrashtracker()
crashtracker.beginProfilerSerializing()
Expand All @@ -15,4 +17,4 @@ async function myAsyncFaultyFunction () {
throw new Error('async went wrong')
}

myAsyncFaultyFunction()
myAsyncFaultyFunction() // eslint-disable-line unicorn/prefer-top-level-await
Loading