mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-03-24 16:18:39 +08:00
fix #14592 ### Description > 🤖 **Note:** The code in this Pull Request were developed with the assistance of AI, but have been thoroughly reviewed and manually tested. > I noticed there's a check when opening an issue that asks _"Is your content generated by AI?"_, so I mention it here in case it's a deal breaker. If so I understand, you can close the PR, just wanted to share this in case it's useful anyways. This PR introduces **Obsidian Vault Import Support** to AFFiNE. Previously, users migrating from Obsidian had to rely on the generic Markdown importer, which often resulted in broken cross-links, missing directory structures, and metadata conflicts because Obsidian relies heavily on proprietary structures not supported by standard Markdown. This completely new feature makes migrating to AFFiNE easy. **Key Features & Implementations:** 1. **Vault (Directory) Selection** - Utilizes the `openDirectory` blocksuite utility in the import modal to allow users to select an entire folder directly from their filesystem, maintaining file context rather than forcing `.zip` uploads. 2. **Wikilink Resolution (Two-Pass Import)** - Restructured the `importObsidianVault` process into a two-pass architecture. - **Pass 1:** Discovers all files, assigns new AFFiNE document IDs, and maps them efficiently (by title, alias, and filename) into a high-performance hash map. - **Pass 2:** Processes the generic markdown AST and correctly maps custom `[[wikilinks]]` to the actual pre-registered AFFiNE blocksuite document IDs via `obsidianWikilinkToDeltaMatcher`. - Safely strips leading emojis from wikilink aliases to prevent duplicated page icons rendering mid-sentence. 3. **Emoji Metadata & State Fixes** - Implemented an aggressive, single-pass RegExp to extract multiple leading/combining emojis (`Emoji_Presentation` / `\ufe0f`) from H1 headers and Frontmatter. Emojis are assigned specifically to the page icon metadata property and cleanly stripped from the visual document title. - Fixed a core mutation bug where the loop iterating over existing `docMetas` was aggressively overwriting newly minted IDs for the current import batch. This fully resolves the issue where imported pages (especially re-imports) were incorrectly flagged as `trashed`. - Enforces explicit `trash: false` patch instructions. 4. **Syntax Conversion** - Implemented conversion of Obsidian-style Callouts (`> [!NOTE] Title`) into native AFFiNE block formats (`> 💡 **Title**`). - Hardened the `blockquote` parser so that nested structures (like `> - list items`) are fully preserved instead of discarded. ### UI Changes - Updated the Import Modal to include the "Import Obsidian Vault" flow utilizing the native filesystem directory picker. - Regenerated and synced `i18n-completenesses.json` correctly up to 100% across all supported locales for the new modal string additions. ### Testing Instructions 1. Navigate to the Workspace sidebar and click "Import". 2. Select "Obsidian" and use the directory picker to define a comprehensive Vault folder. 3. Validate that cross-links between documents automatically resolve to their specific AFFiNE instances. 4. Validate documents containing leading Emojis display exactly one Emoji (in the page icon area), and none duplicated in the actual title header. 5. Validate Callouts are rendered cleanly and correctly, and no documents are incorrectly marked as "Trash". <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit * **New Features** * Import Obsidian vaults with wikilink resolution, emoji/title preservation, asset handling, and automatic document creation. * Folder-based imports via a Directory Picker (with hidden-input fallback) integrated into the import dialog. * **Localization** * Added Obsidian import label and tooltip translations. * **Tests** * Added end-to-end tests validating Obsidian vault import and asset handling. <!-- end of auto-generated comment: release notes by coderabbit.ai --> --------- Co-authored-by: DarkSky <25152247+darkskygit@users.noreply.github.com> Co-authored-by: DarkSky <darksky2048@gmail.com>
588 lines
24 KiB
JavaScript
588 lines
24 KiB
JavaScript
// prettier-ignore
|
|
/* eslint-disable */
|
|
// @ts-nocheck
|
|
/* auto-generated by NAPI-RS */
|
|
|
|
const { readFileSync } = require('node:fs')
|
|
let nativeBinding = null
|
|
const loadErrors = []
|
|
|
|
const isMusl = () => {
|
|
let musl = false
|
|
if (process.platform === 'linux') {
|
|
musl = isMuslFromFilesystem()
|
|
if (musl === null) {
|
|
musl = isMuslFromReport()
|
|
}
|
|
if (musl === null) {
|
|
musl = isMuslFromChildProcess()
|
|
}
|
|
}
|
|
return musl
|
|
}
|
|
|
|
const isFileMusl = (f) => f.includes('libc.musl-') || f.includes('ld-musl-')
|
|
|
|
const isMuslFromFilesystem = () => {
|
|
try {
|
|
return readFileSync('/usr/bin/ldd', 'utf-8').includes('musl')
|
|
} catch {
|
|
return null
|
|
}
|
|
}
|
|
|
|
const isMuslFromReport = () => {
|
|
let report = null
|
|
if (typeof process.report?.getReport === 'function') {
|
|
process.report.excludeNetwork = true
|
|
report = process.report.getReport()
|
|
}
|
|
if (!report) {
|
|
return null
|
|
}
|
|
if (report.header && report.header.glibcVersionRuntime) {
|
|
return false
|
|
}
|
|
if (Array.isArray(report.sharedObjects)) {
|
|
if (report.sharedObjects.some(isFileMusl)) {
|
|
return true
|
|
}
|
|
}
|
|
return false
|
|
}
|
|
|
|
const isMuslFromChildProcess = () => {
|
|
try {
|
|
return require('child_process').execSync('ldd --version', { encoding: 'utf8' }).includes('musl')
|
|
} catch (e) {
|
|
// If we reach this case, we don't know if the system is musl or not, so is better to just fallback to false
|
|
return false
|
|
}
|
|
}
|
|
|
|
function requireNative() {
|
|
if (process.env.NAPI_RS_NATIVE_LIBRARY_PATH) {
|
|
try {
|
|
return require(process.env.NAPI_RS_NATIVE_LIBRARY_PATH);
|
|
} catch (err) {
|
|
loadErrors.push(err)
|
|
}
|
|
} else if (process.platform === 'android') {
|
|
if (process.arch === 'arm64') {
|
|
try {
|
|
return require('./affine.android-arm64.node')
|
|
} catch (e) {
|
|
loadErrors.push(e)
|
|
}
|
|
try {
|
|
const binding = require('@affine/native-android-arm64')
|
|
const bindingPackageVersion = require('@affine/native-android-arm64/package.json').version
|
|
if (bindingPackageVersion !== '0.26.3' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
|
throw new Error(`Native binding package version mismatch, expected 0.26.3 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
}
|
|
return binding
|
|
} catch (e) {
|
|
loadErrors.push(e)
|
|
}
|
|
} else if (process.arch === 'arm') {
|
|
try {
|
|
return require('./affine.android-arm-eabi.node')
|
|
} catch (e) {
|
|
loadErrors.push(e)
|
|
}
|
|
try {
|
|
const binding = require('@affine/native-android-arm-eabi')
|
|
const bindingPackageVersion = require('@affine/native-android-arm-eabi/package.json').version
|
|
if (bindingPackageVersion !== '0.26.3' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
|
throw new Error(`Native binding package version mismatch, expected 0.26.3 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
}
|
|
return binding
|
|
} catch (e) {
|
|
loadErrors.push(e)
|
|
}
|
|
} else {
|
|
loadErrors.push(new Error(`Unsupported architecture on Android ${process.arch}`))
|
|
}
|
|
} else if (process.platform === 'win32') {
|
|
if (process.arch === 'x64') {
|
|
if (process.config?.variables?.shlib_suffix === 'dll.a' || process.config?.variables?.node_target_type === 'shared_library') {
|
|
try {
|
|
return require('./affine.win32-x64-gnu.node')
|
|
} catch (e) {
|
|
loadErrors.push(e)
|
|
}
|
|
try {
|
|
const binding = require('@affine/native-win32-x64-gnu')
|
|
const bindingPackageVersion = require('@affine/native-win32-x64-gnu/package.json').version
|
|
if (bindingPackageVersion !== '0.26.3' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
|
throw new Error(`Native binding package version mismatch, expected 0.26.3 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
}
|
|
return binding
|
|
} catch (e) {
|
|
loadErrors.push(e)
|
|
}
|
|
} else {
|
|
try {
|
|
return require('./affine.win32-x64-msvc.node')
|
|
} catch (e) {
|
|
loadErrors.push(e)
|
|
}
|
|
try {
|
|
const binding = require('@affine/native-win32-x64-msvc')
|
|
const bindingPackageVersion = require('@affine/native-win32-x64-msvc/package.json').version
|
|
if (bindingPackageVersion !== '0.26.3' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
|
throw new Error(`Native binding package version mismatch, expected 0.26.3 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
}
|
|
return binding
|
|
} catch (e) {
|
|
loadErrors.push(e)
|
|
}
|
|
}
|
|
} else if (process.arch === 'ia32') {
|
|
try {
|
|
return require('./affine.win32-ia32-msvc.node')
|
|
} catch (e) {
|
|
loadErrors.push(e)
|
|
}
|
|
try {
|
|
const binding = require('@affine/native-win32-ia32-msvc')
|
|
const bindingPackageVersion = require('@affine/native-win32-ia32-msvc/package.json').version
|
|
if (bindingPackageVersion !== '0.26.3' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
|
throw new Error(`Native binding package version mismatch, expected 0.26.3 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
}
|
|
return binding
|
|
} catch (e) {
|
|
loadErrors.push(e)
|
|
}
|
|
} else if (process.arch === 'arm64') {
|
|
try {
|
|
return require('./affine.win32-arm64-msvc.node')
|
|
} catch (e) {
|
|
loadErrors.push(e)
|
|
}
|
|
try {
|
|
const binding = require('@affine/native-win32-arm64-msvc')
|
|
const bindingPackageVersion = require('@affine/native-win32-arm64-msvc/package.json').version
|
|
if (bindingPackageVersion !== '0.26.3' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
|
throw new Error(`Native binding package version mismatch, expected 0.26.3 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
}
|
|
return binding
|
|
} catch (e) {
|
|
loadErrors.push(e)
|
|
}
|
|
} else {
|
|
loadErrors.push(new Error(`Unsupported architecture on Windows: ${process.arch}`))
|
|
}
|
|
} else if (process.platform === 'darwin') {
|
|
try {
|
|
return require('./affine.darwin-universal.node')
|
|
} catch (e) {
|
|
loadErrors.push(e)
|
|
}
|
|
try {
|
|
const binding = require('@affine/native-darwin-universal')
|
|
const bindingPackageVersion = require('@affine/native-darwin-universal/package.json').version
|
|
if (bindingPackageVersion !== '0.26.3' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
|
throw new Error(`Native binding package version mismatch, expected 0.26.3 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
}
|
|
return binding
|
|
} catch (e) {
|
|
loadErrors.push(e)
|
|
}
|
|
if (process.arch === 'x64') {
|
|
try {
|
|
return require('./affine.darwin-x64.node')
|
|
} catch (e) {
|
|
loadErrors.push(e)
|
|
}
|
|
try {
|
|
const binding = require('@affine/native-darwin-x64')
|
|
const bindingPackageVersion = require('@affine/native-darwin-x64/package.json').version
|
|
if (bindingPackageVersion !== '0.26.3' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
|
throw new Error(`Native binding package version mismatch, expected 0.26.3 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
}
|
|
return binding
|
|
} catch (e) {
|
|
loadErrors.push(e)
|
|
}
|
|
} else if (process.arch === 'arm64') {
|
|
try {
|
|
return require('./affine.darwin-arm64.node')
|
|
} catch (e) {
|
|
loadErrors.push(e)
|
|
}
|
|
try {
|
|
const binding = require('@affine/native-darwin-arm64')
|
|
const bindingPackageVersion = require('@affine/native-darwin-arm64/package.json').version
|
|
if (bindingPackageVersion !== '0.26.3' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
|
throw new Error(`Native binding package version mismatch, expected 0.26.3 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
}
|
|
return binding
|
|
} catch (e) {
|
|
loadErrors.push(e)
|
|
}
|
|
} else {
|
|
loadErrors.push(new Error(`Unsupported architecture on macOS: ${process.arch}`))
|
|
}
|
|
} else if (process.platform === 'freebsd') {
|
|
if (process.arch === 'x64') {
|
|
try {
|
|
return require('./affine.freebsd-x64.node')
|
|
} catch (e) {
|
|
loadErrors.push(e)
|
|
}
|
|
try {
|
|
const binding = require('@affine/native-freebsd-x64')
|
|
const bindingPackageVersion = require('@affine/native-freebsd-x64/package.json').version
|
|
if (bindingPackageVersion !== '0.26.3' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
|
throw new Error(`Native binding package version mismatch, expected 0.26.3 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
}
|
|
return binding
|
|
} catch (e) {
|
|
loadErrors.push(e)
|
|
}
|
|
} else if (process.arch === 'arm64') {
|
|
try {
|
|
return require('./affine.freebsd-arm64.node')
|
|
} catch (e) {
|
|
loadErrors.push(e)
|
|
}
|
|
try {
|
|
const binding = require('@affine/native-freebsd-arm64')
|
|
const bindingPackageVersion = require('@affine/native-freebsd-arm64/package.json').version
|
|
if (bindingPackageVersion !== '0.26.3' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
|
throw new Error(`Native binding package version mismatch, expected 0.26.3 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
}
|
|
return binding
|
|
} catch (e) {
|
|
loadErrors.push(e)
|
|
}
|
|
} else {
|
|
loadErrors.push(new Error(`Unsupported architecture on FreeBSD: ${process.arch}`))
|
|
}
|
|
} else if (process.platform === 'linux') {
|
|
if (process.arch === 'x64') {
|
|
if (isMusl()) {
|
|
try {
|
|
return require('./affine.linux-x64-musl.node')
|
|
} catch (e) {
|
|
loadErrors.push(e)
|
|
}
|
|
try {
|
|
const binding = require('@affine/native-linux-x64-musl')
|
|
const bindingPackageVersion = require('@affine/native-linux-x64-musl/package.json').version
|
|
if (bindingPackageVersion !== '0.26.3' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
|
throw new Error(`Native binding package version mismatch, expected 0.26.3 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
}
|
|
return binding
|
|
} catch (e) {
|
|
loadErrors.push(e)
|
|
}
|
|
} else {
|
|
try {
|
|
return require('./affine.linux-x64-gnu.node')
|
|
} catch (e) {
|
|
loadErrors.push(e)
|
|
}
|
|
try {
|
|
const binding = require('@affine/native-linux-x64-gnu')
|
|
const bindingPackageVersion = require('@affine/native-linux-x64-gnu/package.json').version
|
|
if (bindingPackageVersion !== '0.26.3' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
|
throw new Error(`Native binding package version mismatch, expected 0.26.3 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
}
|
|
return binding
|
|
} catch (e) {
|
|
loadErrors.push(e)
|
|
}
|
|
}
|
|
} else if (process.arch === 'arm64') {
|
|
if (isMusl()) {
|
|
try {
|
|
return require('./affine.linux-arm64-musl.node')
|
|
} catch (e) {
|
|
loadErrors.push(e)
|
|
}
|
|
try {
|
|
const binding = require('@affine/native-linux-arm64-musl')
|
|
const bindingPackageVersion = require('@affine/native-linux-arm64-musl/package.json').version
|
|
if (bindingPackageVersion !== '0.26.3' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
|
throw new Error(`Native binding package version mismatch, expected 0.26.3 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
}
|
|
return binding
|
|
} catch (e) {
|
|
loadErrors.push(e)
|
|
}
|
|
} else {
|
|
try {
|
|
return require('./affine.linux-arm64-gnu.node')
|
|
} catch (e) {
|
|
loadErrors.push(e)
|
|
}
|
|
try {
|
|
const binding = require('@affine/native-linux-arm64-gnu')
|
|
const bindingPackageVersion = require('@affine/native-linux-arm64-gnu/package.json').version
|
|
if (bindingPackageVersion !== '0.26.3' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
|
throw new Error(`Native binding package version mismatch, expected 0.26.3 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
}
|
|
return binding
|
|
} catch (e) {
|
|
loadErrors.push(e)
|
|
}
|
|
}
|
|
} else if (process.arch === 'arm') {
|
|
if (isMusl()) {
|
|
try {
|
|
return require('./affine.linux-arm-musleabihf.node')
|
|
} catch (e) {
|
|
loadErrors.push(e)
|
|
}
|
|
try {
|
|
const binding = require('@affine/native-linux-arm-musleabihf')
|
|
const bindingPackageVersion = require('@affine/native-linux-arm-musleabihf/package.json').version
|
|
if (bindingPackageVersion !== '0.26.3' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
|
throw new Error(`Native binding package version mismatch, expected 0.26.3 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
}
|
|
return binding
|
|
} catch (e) {
|
|
loadErrors.push(e)
|
|
}
|
|
} else {
|
|
try {
|
|
return require('./affine.linux-arm-gnueabihf.node')
|
|
} catch (e) {
|
|
loadErrors.push(e)
|
|
}
|
|
try {
|
|
const binding = require('@affine/native-linux-arm-gnueabihf')
|
|
const bindingPackageVersion = require('@affine/native-linux-arm-gnueabihf/package.json').version
|
|
if (bindingPackageVersion !== '0.26.3' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
|
throw new Error(`Native binding package version mismatch, expected 0.26.3 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
}
|
|
return binding
|
|
} catch (e) {
|
|
loadErrors.push(e)
|
|
}
|
|
}
|
|
} else if (process.arch === 'loong64') {
|
|
if (isMusl()) {
|
|
try {
|
|
return require('./affine.linux-loong64-musl.node')
|
|
} catch (e) {
|
|
loadErrors.push(e)
|
|
}
|
|
try {
|
|
const binding = require('@affine/native-linux-loong64-musl')
|
|
const bindingPackageVersion = require('@affine/native-linux-loong64-musl/package.json').version
|
|
if (bindingPackageVersion !== '0.26.3' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
|
throw new Error(`Native binding package version mismatch, expected 0.26.3 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
}
|
|
return binding
|
|
} catch (e) {
|
|
loadErrors.push(e)
|
|
}
|
|
} else {
|
|
try {
|
|
return require('./affine.linux-loong64-gnu.node')
|
|
} catch (e) {
|
|
loadErrors.push(e)
|
|
}
|
|
try {
|
|
const binding = require('@affine/native-linux-loong64-gnu')
|
|
const bindingPackageVersion = require('@affine/native-linux-loong64-gnu/package.json').version
|
|
if (bindingPackageVersion !== '0.26.3' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
|
throw new Error(`Native binding package version mismatch, expected 0.26.3 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
}
|
|
return binding
|
|
} catch (e) {
|
|
loadErrors.push(e)
|
|
}
|
|
}
|
|
} else if (process.arch === 'riscv64') {
|
|
if (isMusl()) {
|
|
try {
|
|
return require('./affine.linux-riscv64-musl.node')
|
|
} catch (e) {
|
|
loadErrors.push(e)
|
|
}
|
|
try {
|
|
const binding = require('@affine/native-linux-riscv64-musl')
|
|
const bindingPackageVersion = require('@affine/native-linux-riscv64-musl/package.json').version
|
|
if (bindingPackageVersion !== '0.26.3' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
|
throw new Error(`Native binding package version mismatch, expected 0.26.3 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
}
|
|
return binding
|
|
} catch (e) {
|
|
loadErrors.push(e)
|
|
}
|
|
} else {
|
|
try {
|
|
return require('./affine.linux-riscv64-gnu.node')
|
|
} catch (e) {
|
|
loadErrors.push(e)
|
|
}
|
|
try {
|
|
const binding = require('@affine/native-linux-riscv64-gnu')
|
|
const bindingPackageVersion = require('@affine/native-linux-riscv64-gnu/package.json').version
|
|
if (bindingPackageVersion !== '0.26.3' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
|
throw new Error(`Native binding package version mismatch, expected 0.26.3 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
}
|
|
return binding
|
|
} catch (e) {
|
|
loadErrors.push(e)
|
|
}
|
|
}
|
|
} else if (process.arch === 'ppc64') {
|
|
try {
|
|
return require('./affine.linux-ppc64-gnu.node')
|
|
} catch (e) {
|
|
loadErrors.push(e)
|
|
}
|
|
try {
|
|
const binding = require('@affine/native-linux-ppc64-gnu')
|
|
const bindingPackageVersion = require('@affine/native-linux-ppc64-gnu/package.json').version
|
|
if (bindingPackageVersion !== '0.26.3' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
|
throw new Error(`Native binding package version mismatch, expected 0.26.3 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
}
|
|
return binding
|
|
} catch (e) {
|
|
loadErrors.push(e)
|
|
}
|
|
} else if (process.arch === 's390x') {
|
|
try {
|
|
return require('./affine.linux-s390x-gnu.node')
|
|
} catch (e) {
|
|
loadErrors.push(e)
|
|
}
|
|
try {
|
|
const binding = require('@affine/native-linux-s390x-gnu')
|
|
const bindingPackageVersion = require('@affine/native-linux-s390x-gnu/package.json').version
|
|
if (bindingPackageVersion !== '0.26.3' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
|
throw new Error(`Native binding package version mismatch, expected 0.26.3 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
}
|
|
return binding
|
|
} catch (e) {
|
|
loadErrors.push(e)
|
|
}
|
|
} else {
|
|
loadErrors.push(new Error(`Unsupported architecture on Linux: ${process.arch}`))
|
|
}
|
|
} else if (process.platform === 'openharmony') {
|
|
if (process.arch === 'arm64') {
|
|
try {
|
|
return require('./affine.openharmony-arm64.node')
|
|
} catch (e) {
|
|
loadErrors.push(e)
|
|
}
|
|
try {
|
|
const binding = require('@affine/native-openharmony-arm64')
|
|
const bindingPackageVersion = require('@affine/native-openharmony-arm64/package.json').version
|
|
if (bindingPackageVersion !== '0.26.3' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
|
throw new Error(`Native binding package version mismatch, expected 0.26.3 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
}
|
|
return binding
|
|
} catch (e) {
|
|
loadErrors.push(e)
|
|
}
|
|
} else if (process.arch === 'x64') {
|
|
try {
|
|
return require('./affine.openharmony-x64.node')
|
|
} catch (e) {
|
|
loadErrors.push(e)
|
|
}
|
|
try {
|
|
const binding = require('@affine/native-openharmony-x64')
|
|
const bindingPackageVersion = require('@affine/native-openharmony-x64/package.json').version
|
|
if (bindingPackageVersion !== '0.26.3' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
|
throw new Error(`Native binding package version mismatch, expected 0.26.3 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
}
|
|
return binding
|
|
} catch (e) {
|
|
loadErrors.push(e)
|
|
}
|
|
} else if (process.arch === 'arm') {
|
|
try {
|
|
return require('./affine.openharmony-arm.node')
|
|
} catch (e) {
|
|
loadErrors.push(e)
|
|
}
|
|
try {
|
|
const binding = require('@affine/native-openharmony-arm')
|
|
const bindingPackageVersion = require('@affine/native-openharmony-arm/package.json').version
|
|
if (bindingPackageVersion !== '0.26.3' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
|
|
throw new Error(`Native binding package version mismatch, expected 0.26.3 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
|
|
}
|
|
return binding
|
|
} catch (e) {
|
|
loadErrors.push(e)
|
|
}
|
|
} else {
|
|
loadErrors.push(new Error(`Unsupported architecture on OpenHarmony: ${process.arch}`))
|
|
}
|
|
} else {
|
|
loadErrors.push(new Error(`Unsupported OS: ${process.platform}, architecture: ${process.arch}`))
|
|
}
|
|
}
|
|
|
|
nativeBinding = requireNative()
|
|
|
|
if (!nativeBinding || process.env.NAPI_RS_FORCE_WASI) {
|
|
let wasiBinding = null
|
|
let wasiBindingError = null
|
|
try {
|
|
wasiBinding = require('./affine.wasi.cjs')
|
|
nativeBinding = wasiBinding
|
|
} catch (err) {
|
|
if (process.env.NAPI_RS_FORCE_WASI) {
|
|
wasiBindingError = err
|
|
}
|
|
}
|
|
if (!nativeBinding) {
|
|
try {
|
|
wasiBinding = require('@affine/native-wasm32-wasi')
|
|
nativeBinding = wasiBinding
|
|
} catch (err) {
|
|
if (process.env.NAPI_RS_FORCE_WASI) {
|
|
wasiBindingError.cause = err
|
|
loadErrors.push(err)
|
|
}
|
|
}
|
|
}
|
|
if (process.env.NAPI_RS_FORCE_WASI === 'error' && !wasiBinding) {
|
|
const error = new Error('WASI binding not found and NAPI_RS_FORCE_WASI is set to error')
|
|
error.cause = wasiBindingError
|
|
throw error
|
|
}
|
|
}
|
|
|
|
if (!nativeBinding) {
|
|
if (loadErrors.length > 0) {
|
|
throw new Error(
|
|
`Cannot find native binding. ` +
|
|
`npm has a bug related to optional dependencies (https://github.com/npm/cli/issues/4828). ` +
|
|
'Please try `npm i` again after removing both package-lock.json and node_modules directory.',
|
|
{
|
|
cause: loadErrors.reduce((err, cur) => {
|
|
cur.cause = err
|
|
return cur
|
|
}),
|
|
},
|
|
)
|
|
}
|
|
throw new Error(`Failed to load native binding`)
|
|
}
|
|
|
|
module.exports = nativeBinding
|
|
module.exports.ApplicationInfo = nativeBinding.ApplicationInfo
|
|
module.exports.ApplicationListChangedSubscriber = nativeBinding.ApplicationListChangedSubscriber
|
|
module.exports.ApplicationStateChangedSubscriber = nativeBinding.ApplicationStateChangedSubscriber
|
|
module.exports.AudioCaptureSession = nativeBinding.AudioCaptureSession
|
|
module.exports.ShareableContent = nativeBinding.ShareableContent
|
|
module.exports.decodeAudio = nativeBinding.decodeAudio
|
|
module.exports.decodeAudioSync = nativeBinding.decodeAudioSync
|
|
module.exports.mintChallengeResponse = nativeBinding.mintChallengeResponse
|
|
module.exports.verifyChallengeResponse = nativeBinding.verifyChallengeResponse
|
|
module.exports.DocStorage = nativeBinding.DocStorage
|
|
module.exports.DocStoragePool = nativeBinding.DocStoragePool
|
|
module.exports.SqliteConnection = nativeBinding.SqliteConnection
|
|
module.exports.ValidationResult = nativeBinding.ValidationResult
|