Cleanup entrypoints

This commit is contained in:
Nick Gerleman
2022-12-23 07:30:15 -08:00
parent b09aad433b
commit 025698132f
28 changed files with 99 additions and 63 deletions

View File

@@ -10,7 +10,7 @@ project(yoga)
file(GLOB SOURCES
../yoga/*.cpp
../yoga/**/*.cpp
sources/*.cc)
src_native/*.cc)
include_directories(..)
@@ -49,7 +49,7 @@ link_libraries(embind)
add_library(yogaObjLib OBJECT ${SOURCES})
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/dist)
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/dist/build)
add_executable(asmjs-sync $<TARGET_OBJECTS:yogaObjLib>)
target_link_options(asmjs-sync PUBLIC

View File

@@ -9,12 +9,12 @@
module.exports = async () => {
if (process.env['SYNC'] == true && process.env['WASM'] == true) {
global.Yoga = require("./dist/sync.wasm");
global.Yoga = require("./dist/variants/wasm-sync");
} else if (process.env['SYNC'] == true) {
global.Yoga = require("./dist/sync.asmjs");
global.Yoga = require("./dist/variants/asmjs-sync");
} else if (process.env['WASM'] == true) {
global.Yoga = await require("./dist/index.wasm").loadYoga();
global.Yoga = await require("./dist/variants/wasm-async").loadYoga();
} else {
global.Yoga = await require("./dist/index.asmjs").loadYoga();
global.Yoga = await require("./dist/variants/asmjs-async").loadYoga();
}
}

View File

@@ -7,35 +7,37 @@
"type": "git",
"url": "git@github.com:facebook/yoga.git"
},
"main": "./dist/index.js",
"types": "./dist/index.d.ts",
"exports": {
".": {
"browser": "./dist/index.wasm.js",
"node": "./dist/index.wasm.js",
"react-native": "./dist/index.asmjs.js",
"default": "./dist/index.asmjs.js"
"browser": "./dist/variants/wasm-async.js",
"node": "./dist/variants/wasm-async.js",
"default": "./dist/variants/asmjs-async.js"
},
"./sync": {
"browser": "./dist/sync.asmks.js",
"node": "./dist/sync.wasm.js",
"react-native": "./dist/sync.asmjs.js",
"default": "./dist/sync.asmjs.js"
"browser": "./dist/variants/asmjs-sync.js",
"node": "./dist/variants/wasm-sync.js",
"default": "./dist/variants/asmjs-sync.js"
}
},
"files": [
"dist/**",
"sources/**"
"src_js/**"
],
"scripts": {
"benchmark": "node tests/run-bench $(find tests/Benchmarks -name '*.js')",
"build": "yarn build:native && yarn build:js",
"build:native": "yarn build:native-project && cmake --build build",
"build:native-project": "which ninja && emcmake cmake -S . -B build -G Ninja || emcmake cmake -S . -B build",
"build:js": "babel sources --source-maps --out-dir dist && cp -r sources/*.d.ts dist",
"build:configure": "which ninja && emcmake cmake -S . -B build -G Ninja || emcmake cmake -S . -B build",
"build:copy-dts": "cd src_js && find . -name '*.d.ts' | cpio -pdm ../dist",
"build:js": "babel src_js --source-maps --out-dir dist && yarn build:copy-dts",
"build:native": "yarn build:configure && cmake --build build",
"postinstall": "yarn build",
"test": "yarn test:asmjs && yarn test:asmjs-sync && yarn test:wasm && yarn test:wasm-sync",
"test:asmjs": "WASM=0 SYNC=0 jest",
"test:asmjs-sync": "WASM=0 SYNC=1 jest",
"test:wasm": "WASM=1 SYNC=0 jest",
"test:wasm-sync": "WASM=1 SYNC=1 jest",
"benchmark": "node tests/run-bench $(find tests/Benchmarks -name '*.js')"
"test:wasm-sync": "WASM=1 SYNC=1 jest"
},
"devDependencies": {
"@babel/cli": "^7.20.7",

View File

@@ -1,16 +0,0 @@
/**
* 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
*/
const wrapAsm = require('./wrapAsm');
const loadAsm = require('./asmjs-async');
module.exports = {
loadYoga: () => loadAsm().then(wrapAsm),
...require('./YGEnums'),
}

View File

@@ -8,9 +8,8 @@
*/
const wrapAsm = require('./wrapAsm');
const loadAsm = require('./wasm-async');
module.exports = {
module.exports = (loadAsm) => ({
loadYoga: () => loadAsm().then(wrapAsm),
...require('./YGEnums'),
}
...require('./generated/YGEnums'),
});

View File

@@ -7,7 +7,5 @@
* @format
*/
const wrapAsm = require('./wrapAsm');
const loadAsm = require('./wasm-sync');
module.exports = wrapAsm(loadAsm());
const wrapAsm = require('./wrapAsm');
module.exports = (asm) => wrapAsm(asm());

View File

@@ -9,7 +9,7 @@
import type {Yoga} from './wrapAsm';
export * from './YGEnums';
export * from './generated/YGEnums';
export * from './wrapAsm';
export function loadYoga(): Promise<Yoga>;

View File

@@ -7,7 +7,5 @@
* @format
*/
const wrapAsm = require('./wrapAsm');
const loadAsm = require('./asmjs-sync');
module.exports = wrapAsm(loadAsm());
// Fallback for when the export map is not followed
module.exports = require('./variants/asmjs-async');

16
javascript/src_js/sync.d.ts vendored Normal file
View File

@@ -0,0 +1,16 @@
/**
* 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
*/
import type {Yoga} from './wrapAsm';
export * from './generated/YGEnums';
export * from './wrapAsm';
declare const yoga: Yoga;
export default yoga;

View File

@@ -7,10 +7,5 @@
* @format
*/
import type {Yoga} from './wrapAsm';
export * from './YGEnums';
export * from './wrapAsm';
declare const yoga: Yoga;
export default yoga;
// Fallback for when the export map is not followed
module.exports = require('./variants/asmjs-sync');

View File

@@ -0,0 +1,11 @@
/**
* 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
*/
const asm = require('../build/asmjs-async');
module.exports = require("../entryAsync")(asm);

View File

@@ -0,0 +1,11 @@
/**
* 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
*/
const asm = require('../build/asmjs-sync');
module.exports = require("../entrySync")(asm);

View File

@@ -0,0 +1,11 @@
/**
* 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
*/
const asm = require('../build/wasm-async');
module.exports = require("../entryAsync")(asm);

View File

@@ -0,0 +1,11 @@
/**
* 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
*/
const asm = require('../build/wasm-sync');
module.exports = require("../entrySync")(asm);

View File

@@ -7,7 +7,7 @@
* @format
*/
import type {
import type {
Edge,
Wrap,
Align,
@@ -19,9 +19,9 @@
Justify,
Display,
ExperimentalFeature,
} from './YGEnums';
} from './generated/YGEnums';
import type * as YGEnums from './YGEnums';
import type * as YGEnums from './generated/YGEnums';
type Layout = {
left: number;

View File

@@ -7,7 +7,7 @@
* @format
*/
const CONSTANTS = require('./YGEnums');
const CONSTANTS = require('./generated/YGEnums');
module.exports = (lib) => {
function patch(prototype, name, fn) {

View File

@@ -27,7 +27,7 @@ for (let type of ['asmjs', 'wasm']) {
vm.runInNewContext(
file,
Object.assign(Object.create(global), {
Yoga: require(type === 'asmjs' ? '../dist/sync.asmjs' : '../dist/sync.wasm'),
Yoga: require(type === 'asmjs' ? '../dist/variants/asmjs-sync' : '../dist/variants/wasm-sync'),
YGBENCHMARK: function(name, fn) {
let testEntry = testResults.get(name);