[API reference](https://jsprismarine.dev/api/index.md) / [@jsprismarine/native-library](https://jsprismarine.dev/api/@jsprismarine/native-library/index.md) / NativeLibrary

# NativeLibrary

## Classes

- [NativeLibrary](https://jsprismarine.dev/api/@jsprismarine/native-library/NativeLibrary/classes/NativeLibrary.md)

## Interfaces

### InstallOptions

Defined in: [NativeLibrary.ts:52](https://github.com/JSPrismarine/JSPrismarine/blob/9db8dc5e83d04708d63ff9d73cae14f6c6b880f6/packages/native-library/src/NativeLibrary.ts#L52)

How [NativeLibrary.install](https://jsprismarine.dev/api/@jsprismarine/native-library/NativeLibrary/classes/NativeLibrary.md#install) finds and fetches the build; tests replace the network and the platform.

#### Properties

##### env?

> `readonly` `optional` **env?**: `ProcessEnv`

Defined in: [NativeLibrary.ts:55](https://github.com/JSPrismarine/JSPrismarine/blob/9db8dc5e83d04708d63ff9d73cae14f6c6b880f6/packages/native-library/src/NativeLibrary.ts#L55)

##### fetch?

> `readonly` `optional` **fetch?**: (`url`) => `Promise`\<`Response`\>

Defined in: [NativeLibrary.ts:56](https://github.com/JSPrismarine/JSPrismarine/blob/9db8dc5e83d04708d63ff9d73cae14f6c6b880f6/packages/native-library/src/NativeLibrary.ts#L56)

###### Parameters

###### url

`string`

###### Returns

`Promise`\<`Response`\>

##### manifest?

> `readonly` `optional` **manifest?**: [`NativeManifest`](https://jsprismarine.dev/api/@jsprismarine/native-library/manifest/index.md#nativemanifest)

Defined in: [NativeLibrary.ts:59](https://github.com/JSPrismarine/JSPrismarine/blob/9db8dc5e83d04708d63ff9d73cae14f6c6b880f6/packages/native-library/src/NativeLibrary.ts#L59)

##### packageDir

> `readonly` **packageDir**: `string`

Defined in: [NativeLibrary.ts:53](https://github.com/JSPrismarine/JSPrismarine/blob/9db8dc5e83d04708d63ff9d73cae14f6c6b880f6/packages/native-library/src/NativeLibrary.ts#L53)

##### platform?

> `readonly` `optional` **platform?**: `string`

Defined in: [NativeLibrary.ts:54](https://github.com/JSPrismarine/JSPrismarine/blob/9db8dc5e83d04708d63ff9d73cae14f6c6b880f6/packages/native-library/src/NativeLibrary.ts#L54)

##### wait?

> `readonly` `optional` **wait?**: (`milliseconds`) => `Promise`\<`void`\>

Defined in: [NativeLibrary.ts:58](https://github.com/JSPrismarine/JSPrismarine/blob/9db8dc5e83d04708d63ff9d73cae14f6c6b880f6/packages/native-library/src/NativeLibrary.ts#L58)

Waits between download attempts; tests pass one that returns at once.

###### Parameters

###### milliseconds

`number`

###### Returns

`Promise`\<`void`\>

***

### LocateOptions

Defined in: [NativeLibrary.ts:36](https://github.com/JSPrismarine/JSPrismarine/blob/9db8dc5e83d04708d63ff9d73cae14f6c6b880f6/packages/native-library/src/NativeLibrary.ts#L36)

How [NativeLibrary.locate](https://jsprismarine.dev/api/@jsprismarine/native-library/NativeLibrary/classes/NativeLibrary.md#locate) looks; tests replace each part.

#### Properties

##### env?

> `readonly` `optional` **env?**: `ProcessEnv`

Defined in: [NativeLibrary.ts:37](https://github.com/JSPrismarine/JSPrismarine/blob/9db8dc5e83d04708d63ff9d73cae14f6c6b880f6/packages/native-library/src/NativeLibrary.ts#L37)

##### manifest?

> `readonly` `optional` **manifest?**: [`NativeManifest`](https://jsprismarine.dev/api/@jsprismarine/native-library/manifest/index.md#nativemanifest)

Defined in: [NativeLibrary.ts:40](https://github.com/JSPrismarine/JSPrismarine/blob/9db8dc5e83d04708d63ff9d73cae14f6c6b880f6/packages/native-library/src/NativeLibrary.ts#L40)

##### packageDir?

> `readonly` `optional` **packageDir?**: `string`

Defined in: [NativeLibrary.ts:38](https://github.com/JSPrismarine/JSPrismarine/blob/9db8dc5e83d04708d63ff9d73cae14f6c6b880f6/packages/native-library/src/NativeLibrary.ts#L38)

##### platform?

> `readonly` `optional` **platform?**: `string`

Defined in: [NativeLibrary.ts:39](https://github.com/JSPrismarine/JSPrismarine/blob/9db8dc5e83d04708d63ff9d73cae14f6c6b880f6/packages/native-library/src/NativeLibrary.ts#L39)

***

### NativeLibraryOptions

Defined in: [NativeLibrary.ts:13](https://github.com/JSPrismarine/JSPrismarine/blob/9db8dc5e83d04708d63ff9d73cae14f6c6b880f6/packages/native-library/src/NativeLibrary.ts#L13)

What a package that ships a native library tells [NativeLibrary](https://jsprismarine.dev/api/@jsprismarine/native-library/NativeLibrary/classes/NativeLibrary.md) about it.

#### Properties

##### buildScripts

> `readonly` **buildScripts**: readonly `string`[]

Defined in: [NativeLibrary.ts:32](https://github.com/JSPrismarine/JSPrismarine/blob/9db8dc5e83d04708d63ff9d73cae14f6c6b880f6/packages/native-library/src/NativeLibrary.ts#L32)

The files outside `native/` the package's build reads, which its source hash covers.

##### envPrefix

> `readonly` **envPrefix**: `string`

Defined in: [NativeLibrary.ts:23](https://github.com/JSPrismarine/JSPrismarine/blob/9db8dc5e83d04708d63ff9d73cae14f6c6b880f6/packages/native-library/src/NativeLibrary.ts#L23)

The prefix of the package's environment variables, such as `JSP_NATIVE_NETWORK`: `_LIBRARY`
names a library to load, `_SKIP_DOWNLOAD` skips the install's download, and `_BASE_URL`
downloads from a mirror.

##### library

> `readonly` **library**: `string`

Defined in: [NativeLibrary.ts:17](https://github.com/JSPrismarine/JSPrismarine/blob/9db8dc5e83d04708d63ff9d73cae14f6c6b880f6/packages/native-library/src/NativeLibrary.ts#L17)

The library's file name without its extension, such as `libjsp_native_network`.

##### manifest

> `readonly` **manifest**: `unknown`

Defined in: [NativeLibrary.ts:30](https://github.com/JSPrismarine/JSPrismarine/blob/9db8dc5e83d04708d63ff9d73cae14f6c6b880f6/packages/native-library/src/NativeLibrary.ts#L30)

The package's `native/manifest.json`, as imported JSON. It is imported rather than read from
disk, so a bundled executable carries it.

##### packageDir

> `readonly` **packageDir**: `string`

Defined in: [NativeLibrary.ts:25](https://github.com/JSPrismarine/JSPrismarine/blob/9db8dc5e83d04708d63ff9d73cae14f6c6b880f6/packages/native-library/src/NativeLibrary.ts#L25)

The package's root, which holds `native/` in a checkout and `prebuilds/` once installed.

##### packageName

> `readonly` **packageName**: `string`

Defined in: [NativeLibrary.ts:15](https://github.com/JSPrismarine/JSPrismarine/blob/9db8dc5e83d04708d63ff9d73cae14f6c6b880f6/packages/native-library/src/NativeLibrary.ts#L15)

The npm name, as the messages tell a user to approve or build it.

## Type Aliases

### InstallOutcome

> **InstallOutcome** = \{ `bytes`: `number`; `kind`: `"installed"`; `path`: `string`; \} \| \{ `kind`: `"present"`; `path`: `string`; \} \| \{ `kind`: `"no-build"`; `platform`: `string`; \} \| \{ `kind`: `"skipped"`; \} \| \{ `kind`: `"local-sources"`; `sourceHash`: `string`; \}

Defined in: [NativeLibrary.ts:44](https://github.com/JSPrismarine/JSPrismarine/blob/9db8dc5e83d04708d63ff9d73cae14f6c6b880f6/packages/native-library/src/NativeLibrary.ts#L44)

What an install did.

## Functions

### localBuildDigest()

> **localBuildDigest**(`path`): `string` \| `undefined`

Defined in: [NativeLibrary.ts:86](https://github.com/JSPrismarine/JSPrismarine/blob/9db8dc5e83d04708d63ff9d73cae14f6c6b880f6/packages/native-library/src/NativeLibrary.ts#L86)

The digest a local build recorded in the `build.json` beside it, which `build:native` writes.

#### Parameters

##### path

`string`

The library file.

#### Returns

`string` \| `undefined`

The digest, or undefined when there is no readable record.

***

### recordLocalBuild()

> **recordLocalBuild**(`path`, `digest`): `void`

Defined in: [NativeLibrary.ts:105](https://github.com/JSPrismarine/JSPrismarine/blob/9db8dc5e83d04708d63ff9d73cae14f6c6b880f6/packages/native-library/src/NativeLibrary.ts#L105)

Records a library's digest in a `build.json` beside it, as `build:native` does, so that
[NativeLibrary.verify](https://jsprismarine.dev/api/@jsprismarine/native-library/NativeLibrary/classes/NativeLibrary.md#verify) accepts the file. Only for bytes that were checked before they were
written there, such as a library an executable embedded.

#### Parameters

##### path

`string`

The library file.

##### digest

`string`

Its SHA-256.

#### Returns

`void`
