[API reference](https://jsprismarine.dev/api/index.md) / [@jsprismarine/script-host](https://jsprismarine.dev/api/@jsprismarine/script-host/index.md) / host/pack

# host/pack

## Interfaces

### ScriptConfig

Defined in: [script-host/src/host/pack.ts:185](https://github.com/JSPrismarine/JSPrismarine/blob/e928b08f56694af6821b757ce6b196faebd3199c/packages/script-host/src/host/pack.ts#L185)

The configuration of every script module, read from a BDS `config/` folder.

#### Methods

##### module()

> **module**(`moduleUuid`): [`ScriptModuleConfig`](#scriptmoduleconfig)

Defined in: [script-host/src/host/pack.ts:187](https://github.com/JSPrismarine/JSPrismarine/blob/e928b08f56694af6821b757ce6b196faebd3199c/packages/script-host/src/host/pack.ts#L187)

What applies to the script module with this UUID.

###### Parameters

###### moduleUuid

`string`

###### Returns

[`ScriptModuleConfig`](#scriptmoduleconfig)

##### reload()?

> `optional` **reload**(): [`ScriptConfig`](#scriptconfig)

Defined in: [script-host/src/host/pack.ts:192](https://github.com/JSPrismarine/JSPrismarine/blob/e928b08f56694af6821b757ce6b196faebd3199c/packages/script-host/src/host/pack.ts#L192)

Reads the folder again, as `@minecraft/server-admin`'s `reloadScriptingConfig` asks. Left
out, a reload keeps what was read.

###### Returns

[`ScriptConfig`](#scriptconfig)

***

### ScriptModuleConfig

Defined in: [script-host/src/host/pack.ts:175](https://github.com/JSPrismarine/JSPrismarine/blob/e928b08f56694af6821b757ce6b196faebd3199c/packages/script-host/src/host/pack.ts#L175)

What `config/` says about one script module.

#### Properties

##### allowedModules

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

Defined in: [script-host/src/host/pack.ts:177](https://github.com/JSPrismarine/JSPrismarine/blob/e928b08f56694af6821b757ce6b196faebd3199c/packages/script-host/src/host/pack.ts#L177)

`allowed_modules` from `permissions.json`.

##### secrets

> `readonly` **secrets**: `Readonly`\<`Record`\<`string`, `string`\>\>

Defined in: [script-host/src/host/pack.ts:181](https://github.com/JSPrismarine/JSPrismarine/blob/e928b08f56694af6821b757ce6b196faebd3199c/packages/script-host/src/host/pack.ts#L181)

`secrets.json`, which `@minecraft/server-admin`'s `secrets` reads.

##### variables

> `readonly` **variables**: `Readonly`\<`Record`\<`string`, `unknown`\>\>

Defined in: [script-host/src/host/pack.ts:179](https://github.com/JSPrismarine/JSPrismarine/blob/e928b08f56694af6821b757ce6b196faebd3199c/packages/script-host/src/host/pack.ts#L179)

`variables.json`, which `@minecraft/server-admin`'s `variables` reads.

***

### ScriptPack

Defined in: [script-host/src/host/pack.ts:15](https://github.com/JSPrismarine/JSPrismarine/blob/e928b08f56694af6821b757ce6b196faebd3199c/packages/script-host/src/host/pack.ts#L15)

A behavior pack whose manifest has a `script` module.

#### Properties

##### dependencies

> `readonly` **dependencies**: readonly [`ModuleDependency`](https://jsprismarine.dev/api/@jsprismarine/script-host/shape/resolve/index.md#moduledependency)[]

Defined in: [script-host/src/host/pack.ts:29](https://github.com/JSPrismarine/JSPrismarine/blob/e928b08f56694af6821b757ce6b196faebd3199c/packages/script-host/src/host/pack.ts#L29)

The native modules the manifest declares, such as `@minecraft/server`.

##### directory

> `readonly` **directory**: `string`

Defined in: [script-host/src/host/pack.ts:17](https://github.com/JSPrismarine/JSPrismarine/blob/e928b08f56694af6821b757ce6b196faebd3199c/packages/script-host/src/host/pack.ts#L17)

The pack's directory.

##### entry

> `readonly` **entry**: `string`

Defined in: [script-host/src/host/pack.ts:27](https://github.com/JSPrismarine/JSPrismarine/blob/e928b08f56694af6821b757ce6b196faebd3199c/packages/script-host/src/host/pack.ts#L27)

The script module's entry, relative to the pack, such as `scripts/main.js`.

##### moduleUuid

> `readonly` **moduleUuid**: `string`

Defined in: [script-host/src/host/pack.ts:25](https://github.com/JSPrismarine/JSPrismarine/blob/e928b08f56694af6821b757ce6b196faebd3199c/packages/script-host/src/host/pack.ts#L25)

The script module's UUID, which names its folder under `config/`.

##### name

> `readonly` **name**: `string`

Defined in: [script-host/src/host/pack.ts:19](https://github.com/JSPrismarine/JSPrismarine/blob/e928b08f56694af6821b757ce6b196faebd3199c/packages/script-host/src/host/pack.ts#L19)

The header name, which BDS's content log names the pack by.

##### uuid

> `readonly` **uuid**: `string`

Defined in: [script-host/src/host/pack.ts:23](https://github.com/JSPrismarine/JSPrismarine/blob/e928b08f56694af6821b757ce6b196faebd3199c/packages/script-host/src/host/pack.ts#L23)

The header UUID.

##### version

> `readonly` **version**: `string`

Defined in: [script-host/src/host/pack.ts:21](https://github.com/JSPrismarine/JSPrismarine/blob/e928b08f56694af6821b757ce6b196faebd3199c/packages/script-host/src/host/pack.ts#L21)

The header version, such as `1.0.0`.

## Variables

### DEFAULT\_ALLOWED\_MODULES

> `const` **DEFAULT\_ALLOWED\_MODULES**: readonly `string`[]

Defined in: [script-host/src/host/pack.ts:165](https://github.com/JSPrismarine/JSPrismarine/blob/e928b08f56694af6821b757ce6b196faebd3199c/packages/script-host/src/host/pack.ts#L165)

The modules a world may use when its `config/default/permissions.json` is missing: the list
that file holds in the pinned BDS archive.

## Functions

### packLabel()

> **packLabel**(`pack`): `string`

Defined in: [script-host/src/host/pack.ts:33](https://github.com/JSPrismarine/JSPrismarine/blob/e928b08f56694af6821b757ce6b196faebd3199c/packages/script-host/src/host/pack.ts#L33)

How BDS's resolution messages name a pack: its header name and version, such as `my pack - 1.0.0`.

#### Parameters

##### pack

[`ScriptPack`](#scriptpack)

#### Returns

`string`

***

### packModulePath()

> **packModulePath**(`pack`, `base`, `specifier`): `string`

Defined in: [script-host/src/host/pack.ts:137](https://github.com/JSPrismarine/JSPrismarine/blob/e928b08f56694af6821b757ce6b196faebd3199c/packages/script-host/src/host/pack.ts#L137)

The path of a pack's file that a script's import reaches, as BDS resolves it, with `/` between
folders. A specifier that starts with `.` is read from the importing module's folder, and any
other from the pack's `scripts` folder, so `items/item.handler` imported anywhere is
`scripts/items/item.handler.js`. A path that names no file gains `.js` when that names one, as
`./close_open_vent` reaches `close_open_vent.js`. Every spelling of a file gives the same path,
so the file is one module however it is imported.

#### Parameters

##### pack

[`ScriptPack`](#scriptpack)

The pack the importing module belongs to.

##### base

`string`

The importing module's path in the pack.

##### specifier

`string`

The specifier as the import wrote it, which does not start with `@`.

#### Returns

`string`

The path, which names no file when the import reaches none.

***

### packScripts()

> **packScripts**(`pack`): `Map`\<`string`, `string`\>

Defined in: [script-host/src/host/pack.ts:149](https://github.com/JSPrismarine/JSPrismarine/blob/e928b08f56694af6821b757ce6b196faebd3199c/packages/script-host/src/host/pack.ts#L149)

Every JavaScript file of a pack's `scripts` folder, by its path relative to the pack.

#### Parameters

##### pack

[`ScriptPack`](#scriptpack)

#### Returns

`Map`\<`string`, `string`\>

***

### readPackBytes()

> **readPackBytes**(`pack`, `path`): `Uint8Array`\<`ArrayBufferLike`\> \| `undefined`

Defined in: [script-host/src/host/pack.ts:108](https://github.com/JSPrismarine/JSPrismarine/blob/e928b08f56694af6821b757ce6b196faebd3199c/packages/script-host/src/host/pack.ts#L108)

Reads a binary file of a pack, such as a GameTest's `.mcstructure`, under the same rule as
[readPackFile](#readpackfile).

#### Parameters

##### pack

[`ScriptPack`](#scriptpack)

##### path

`string`

#### Returns

`Uint8Array`\<`ArrayBufferLike`\> \| `undefined`

Undefined when the file is missing or outside the pack.

***

### readPackFile()

> **readPackFile**(`pack`, `path`): `string` \| `undefined`

Defined in: [script-host/src/host/pack.ts:98](https://github.com/JSPrismarine/JSPrismarine/blob/e928b08f56694af6821b757ce6b196faebd3199c/packages/script-host/src/host/pack.ts#L98)

Reads a file of a pack, by its path relative to the pack. A symbolic link counts by where it
points, so a link to a file outside the pack reads nothing.

#### Parameters

##### pack

[`ScriptPack`](#scriptpack)

##### path

`string`

#### Returns

`string` \| `undefined`

Its text, or undefined when it does not exist or the path leaves the pack.

***

### readScriptConfig()

> **readScriptConfig**(`directory`, `warn?`): [`ScriptConfig`](#scriptconfig)

Defined in: [script-host/src/host/pack.ts:232](https://github.com/JSPrismarine/JSPrismarine/blob/e928b08f56694af6821b757ce6b196faebd3199c/packages/script-host/src/host/pack.ts#L232)

Reads a BDS `config/` folder: `default/` for every pack, and a folder named after a script
module's UUID for that module. A file in a module's folder replaces the same file in
`default/`, as the `config-permissions` scenario of the parity suite records BDS doing for
`permissions.json`; BDS documents no merge for the other two files either.

#### Parameters

##### directory

`string` \| `undefined`

The `config/` folder, or undefined for a server without one.

##### warn?

(`message`) => `void`

Where BDS's warnings about the files go, such as a secret that is not a string.

#### Returns

[`ScriptConfig`](#scriptconfig)

#### Throws

When a file there is not a JSON object.

***

### readScriptPack()

> **readScriptPack**(`directory`): [`ScriptPack`](#scriptpack) \| `undefined`

Defined in: [script-host/src/host/pack.ts:47](https://github.com/JSPrismarine/JSPrismarine/blob/e928b08f56694af6821b757ce6b196faebd3199c/packages/script-host/src/host/pack.ts#L47)

Reads a behavior pack's manifest.

#### Parameters

##### directory

`string`

The pack's directory, holding `manifest.json`.

#### Returns

[`ScriptPack`](#scriptpack) \| `undefined`

The pack, or undefined when it has no manifest or no `script` module with an entry.

#### Throws

When the manifest is not JSON, or its header lacks a name, a UUID or a version.
