Skip to content

Commit 334eebc

Browse files
bbohlenderNickGerleman
authored andcommitted
Entry point without TLA for js package (#1638)
Summary: Follow up on #1637 TLDR: tooling for TLA is not there yet; An additional entry point without top-level-await is appropriate - adds ./load entry to js package - uses .js file extensions to prevent requiring [allowImportingTsExtensions](https://www.typescriptlang.org/tsconfig#allowImportingTsExtensions) Pull Request resolved: #1638 Reviewed By: joevilches Differential Revision: D55614636 Pulled By: NickGerleman fbshipit-source-id: 126a94aa68d22d32b938282cfa1a5059bb9df337
1 parent 5b106e5 commit 334eebc

3 files changed

Lines changed: 38 additions & 0 deletions

File tree

javascript/README.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,3 +29,12 @@ node.free();
2929
## Requirements
3030

3131
`yoga-layout` requires a toolchain that supports ES Modules and top-level await.
32+
33+
If top-level-await is not supported, use the `yoga-layout/load` entry point instead. This requires to load yoga manually:
34+
35+
```ts
36+
import {loadYoga, Align} from 'yoga-layout/load';
37+
38+
const node = (await loadYoga).Node.create();
39+
node.setAlignContent(Align.Center);
40+
```

javascript/package.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,10 @@
1111
},
1212
"type": "module",
1313
"main": "./src/index.ts",
14+
"exports": {
15+
".": "./src/index.ts",
16+
"./load": "./src/load.ts"
17+
},
1418
"files": [
1519
"binaries/**",
1620
"src/**"

javascript/src/load.ts

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
/**
2+
* Copyright (c) Meta Platforms, Inc. and affiliates.
3+
*
4+
* This source code is licensed under the MIT license found in the
5+
* LICENSE file in the root directory of this source tree.
6+
*
7+
* @format
8+
*/
9+
10+
// @ts-ignore untyped from Emscripten
11+
import loadYogaImpl from '../binaries/yoga-wasm-base64-esm.js';
12+
import wrapAssembly from './wrapAssembly.ts';
13+
14+
export type {
15+
Config,
16+
DirtiedFunction,
17+
MeasureFunction,
18+
Node,
19+
Yoga,
20+
} from './wrapAssembly.ts';
21+
22+
export async function loadYoga() {
23+
return wrapAssembly(await loadYogaImpl());
24+
}
25+
export * from './generated/YGEnums.ts';

0 commit comments

Comments
 (0)