Entry point without TLA for js package (#1638)

Summary:
Follow up on https://github.com/facebook/yoga/issues/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: https://github.com/facebook/yoga/pull/1638

Reviewed By: joevilches

Differential Revision: D55614636

Pulled By: NickGerleman

fbshipit-source-id: 126a94aa68d22d32b938282cfa1a5059bb9df337
This commit is contained in:
Bela Bohlender
2024-04-08 12:04:08 -07:00
committed by Facebook GitHub Bot
parent 194f83dea5
commit bbdd1afe59
3 changed files with 38 additions and 0 deletions

View File

@@ -29,3 +29,12 @@ node.free();
## Requirements ## Requirements
`yoga-layout` requires a toolchain that supports ES Modules and top-level await. `yoga-layout` requires a toolchain that supports ES Modules and top-level await.
If top-level-await is not supported, use the `yoga-layout/load` entry point instead. This requires to load yoga manually:
```ts
import {loadYoga, Align} from 'yoga-layout/load';
const node = (await loadYoga).Node.create();
node.setAlignContent(Align.Center);
```

View File

@@ -11,6 +11,10 @@
}, },
"type": "module", "type": "module",
"main": "./src/index.ts", "main": "./src/index.ts",
"exports": {
".": "./src/index.ts",
"./load": "./src/load.ts"
},
"files": [ "files": [
"binaries/**", "binaries/**",
"src/**" "src/**"

25
javascript/src/load.ts Normal file
View File

@@ -0,0 +1,25 @@
/**
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @format
*/
// @ts-ignore untyped from Emscripten
import loadYogaImpl from '../binaries/yoga-wasm-base64-esm.js';
import wrapAssembly from './wrapAssembly.ts';
export type {
Config,
DirtiedFunction,
MeasureFunction,
Node,
Yoga,
} from './wrapAssembly.ts';
export async function loadYoga() {
return wrapAssembly(await loadYogaImpl());
}
export * from './generated/YGEnums.ts';