2022-12-28 01:27:12 -08:00
|
|
|
/**
|
|
|
|
* 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
|
|
|
|
*/
|
|
|
|
|
Consolidate JavaScript Flavors (#1433)
Summary:
Fixes https://github.com/facebook/yoga/issues/1417
This dramatically simplifies the matrix of Node vs web, ASM vs WASM, sync vs async compilation, or CommonJS vs ES Modules. We have one variant, using wasm, with ESModule top-level await to do async compilation. Web/node share the same binary, and we base64 encode the WASM into a wrapper JS file for compatibility with Node and bundlers.
This has some downsides, like requiring an environment with top level await, but also has upsides, like a consistent, sync looking API compatible with older Yoga, and mitigating TypeScript issues with package exports and typings resolution.
As part of this work I also removed `ts-node` from the toolchain (at the cost of a couple of config files needing to be vanilla JS).
Pull Request resolved: https://github.com/facebook/yoga/pull/1433
Test Plan:
1. `yarn test`
2. `yarn lint`
3. `yarn tsc`
4. `yarn benchmark`
5. `yarn build` website-next
6. `yarn lint` website-next
7. Locally test website-next
8. Examine package artifact created by GitHub
9. All Automation passes
Reviewed By: yungsters
Differential Revision: D50453324
Pulled By: NickGerleman
fbshipit-source-id: fe1192acc69e57fa69a1ff056dd7b5844d2198d5
2023-10-31 20:41:38 -07:00
|
|
|
const {
|
2022-12-28 01:27:12 -08:00
|
|
|
argv,
|
2022-12-30 14:29:42 -08:00
|
|
|
cleanTask,
|
2022-12-28 01:27:12 -08:00
|
|
|
logger,
|
|
|
|
jestTask,
|
|
|
|
option,
|
|
|
|
series,
|
|
|
|
spawn,
|
|
|
|
task,
|
2023-05-04 08:11:04 -07:00
|
|
|
tscTask,
|
2024-04-15 09:28:23 -07:00
|
|
|
copyTask,
|
Consolidate JavaScript Flavors (#1433)
Summary:
Fixes https://github.com/facebook/yoga/issues/1417
This dramatically simplifies the matrix of Node vs web, ASM vs WASM, sync vs async compilation, or CommonJS vs ES Modules. We have one variant, using wasm, with ESModule top-level await to do async compilation. Web/node share the same binary, and we base64 encode the WASM into a wrapper JS file for compatibility with Node and bundlers.
This has some downsides, like requiring an environment with top level await, but also has upsides, like a consistent, sync looking API compatible with older Yoga, and mitigating TypeScript issues with package exports and typings resolution.
As part of this work I also removed `ts-node` from the toolchain (at the cost of a couple of config files needing to be vanilla JS).
Pull Request resolved: https://github.com/facebook/yoga/pull/1433
Test Plan:
1. `yarn test`
2. `yarn lint`
3. `yarn tsc`
4. `yarn benchmark`
5. `yarn build` website-next
6. `yarn lint` website-next
7. Locally test website-next
8. Examine package artifact created by GitHub
9. All Automation passes
Reviewed By: yungsters
Differential Revision: D50453324
Pulled By: NickGerleman
fbshipit-source-id: fe1192acc69e57fa69a1ff056dd7b5844d2198d5
2023-10-31 20:41:38 -07:00
|
|
|
} = require('just-scripts');
|
2022-12-28 01:27:12 -08:00
|
|
|
|
2023-12-12 09:06:58 -08:00
|
|
|
const {existsSync} = require('fs');
|
|
|
|
const {readFile, writeFile, rm} = require('fs/promises');
|
2023-05-09 22:21:01 -07:00
|
|
|
|
2024-06-26 01:24:08 -07:00
|
|
|
const {glob} = require('glob');
|
Consolidate JavaScript Flavors (#1433)
Summary:
Fixes https://github.com/facebook/yoga/issues/1417
This dramatically simplifies the matrix of Node vs web, ASM vs WASM, sync vs async compilation, or CommonJS vs ES Modules. We have one variant, using wasm, with ESModule top-level await to do async compilation. Web/node share the same binary, and we base64 encode the WASM into a wrapper JS file for compatibility with Node and bundlers.
This has some downsides, like requiring an environment with top level await, but also has upsides, like a consistent, sync looking API compatible with older Yoga, and mitigating TypeScript issues with package exports and typings resolution.
As part of this work I also removed `ts-node` from the toolchain (at the cost of a couple of config files needing to be vanilla JS).
Pull Request resolved: https://github.com/facebook/yoga/pull/1433
Test Plan:
1. `yarn test`
2. `yarn lint`
3. `yarn tsc`
4. `yarn benchmark`
5. `yarn build` website-next
6. `yarn lint` website-next
7. Locally test website-next
8. Examine package artifact created by GitHub
9. All Automation passes
Reviewed By: yungsters
Differential Revision: D50453324
Pulled By: NickGerleman
fbshipit-source-id: fe1192acc69e57fa69a1ff056dd7b5844d2198d5
2023-10-31 20:41:38 -07:00
|
|
|
const path = require('path');
|
|
|
|
const which = require('which');
|
2022-12-28 01:27:12 -08:00
|
|
|
|
|
|
|
const node = process.execPath;
|
|
|
|
|
2023-05-09 15:35:42 -07:00
|
|
|
option('fix');
|
2022-12-28 01:27:12 -08:00
|
|
|
|
2023-12-12 09:06:58 -08:00
|
|
|
task('clean', cleanTask({paths: ['.emsdk', 'binaries', 'build']}));
|
2022-12-30 14:29:42 -08:00
|
|
|
|
2023-12-12 09:06:58 -08:00
|
|
|
task(
|
|
|
|
'build',
|
|
|
|
series(installEmsdkTask(), emcmakeGenerateTask(), cmakeBuildTask()),
|
|
|
|
);
|
|
|
|
|
|
|
|
task(
|
|
|
|
'test',
|
|
|
|
series(
|
|
|
|
'build',
|
Consolidate JavaScript Flavors (#1433)
Summary:
Fixes https://github.com/facebook/yoga/issues/1417
This dramatically simplifies the matrix of Node vs web, ASM vs WASM, sync vs async compilation, or CommonJS vs ES Modules. We have one variant, using wasm, with ESModule top-level await to do async compilation. Web/node share the same binary, and we base64 encode the WASM into a wrapper JS file for compatibility with Node and bundlers.
This has some downsides, like requiring an environment with top level await, but also has upsides, like a consistent, sync looking API compatible with older Yoga, and mitigating TypeScript issues with package exports and typings resolution.
As part of this work I also removed `ts-node` from the toolchain (at the cost of a couple of config files needing to be vanilla JS).
Pull Request resolved: https://github.com/facebook/yoga/pull/1433
Test Plan:
1. `yarn test`
2. `yarn lint`
3. `yarn tsc`
4. `yarn benchmark`
5. `yarn build` website-next
6. `yarn lint` website-next
7. Locally test website-next
8. Examine package artifact created by GitHub
9. All Automation passes
Reviewed By: yungsters
Differential Revision: D50453324
Pulled By: NickGerleman
fbshipit-source-id: fe1192acc69e57fa69a1ff056dd7b5844d2198d5
2023-10-31 20:41:38 -07:00
|
|
|
jestTask({
|
|
|
|
config: path.join(__dirname, 'jest.config.js'),
|
|
|
|
nodeArgs: ['--experimental-vm-modules'],
|
|
|
|
}),
|
2023-07-12 15:43:10 -07:00
|
|
|
),
|
2022-12-28 01:27:12 -08:00
|
|
|
);
|
|
|
|
|
2023-12-12 09:06:58 -08:00
|
|
|
task('benchmark', series('build', runBenchTask()));
|
|
|
|
|
2023-07-17 14:27:32 -07:00
|
|
|
task('clang-format', clangFormatTask({fix: argv().fix}));
|
2022-12-28 01:27:12 -08:00
|
|
|
|
2023-05-09 22:21:01 -07:00
|
|
|
task('prepack-package-json', async () => {
|
|
|
|
const packageJsonPath = path.join(__dirname, 'package.json');
|
|
|
|
const packageJsonContents = await readFile(packageJsonPath);
|
|
|
|
const packageJson = JSON.parse(packageJsonContents.toString('utf-8'));
|
|
|
|
|
2024-04-15 09:28:23 -07:00
|
|
|
packageJson.main = packageJson.main.replace(
|
|
|
|
/^.\/src\/(.*)\.ts/,
|
|
|
|
'./dist/src/$1.js',
|
|
|
|
);
|
|
|
|
packageJson.types = packageJson.main.replace(/(.*)\.js/, '$1.d.ts');
|
|
|
|
|
|
|
|
recursiveReplace(
|
|
|
|
packageJson.exports,
|
|
|
|
/^.\/src\/(.*)\.ts/,
|
|
|
|
'./dist/src/$1.js',
|
|
|
|
);
|
|
|
|
|
2023-05-09 22:21:01 -07:00
|
|
|
await writeFile(packageJsonPath, JSON.stringify(packageJson, null, 2));
|
|
|
|
});
|
|
|
|
|
2023-05-09 15:35:42 -07:00
|
|
|
task(
|
2023-05-09 22:21:01 -07:00
|
|
|
'prepack',
|
|
|
|
series(
|
2024-04-15 09:28:23 -07:00
|
|
|
'build',
|
|
|
|
copyTask({paths: ['binaries'], dest: 'dist/binaries'}),
|
|
|
|
tscTask({
|
|
|
|
emitDeclarationOnly: true,
|
|
|
|
rootDir: '.',
|
|
|
|
declarationDir: 'dist',
|
|
|
|
}),
|
|
|
|
babelTransformTask({src: 'src', dst: 'dist/src'}),
|
2023-05-09 22:21:01 -07:00
|
|
|
'prepack-package-json',
|
2023-05-09 15:35:42 -07:00
|
|
|
),
|
|
|
|
);
|
2022-12-28 01:27:12 -08:00
|
|
|
|
Consolidate JavaScript Flavors (#1433)
Summary:
Fixes https://github.com/facebook/yoga/issues/1417
This dramatically simplifies the matrix of Node vs web, ASM vs WASM, sync vs async compilation, or CommonJS vs ES Modules. We have one variant, using wasm, with ESModule top-level await to do async compilation. Web/node share the same binary, and we base64 encode the WASM into a wrapper JS file for compatibility with Node and bundlers.
This has some downsides, like requiring an environment with top level await, but also has upsides, like a consistent, sync looking API compatible with older Yoga, and mitigating TypeScript issues with package exports and typings resolution.
As part of this work I also removed `ts-node` from the toolchain (at the cost of a couple of config files needing to be vanilla JS).
Pull Request resolved: https://github.com/facebook/yoga/pull/1433
Test Plan:
1. `yarn test`
2. `yarn lint`
3. `yarn tsc`
4. `yarn benchmark`
5. `yarn build` website-next
6. `yarn lint` website-next
7. Locally test website-next
8. Examine package artifact created by GitHub
9. All Automation passes
Reviewed By: yungsters
Differential Revision: D50453324
Pulled By: NickGerleman
fbshipit-source-id: fe1192acc69e57fa69a1ff056dd7b5844d2198d5
2023-10-31 20:41:38 -07:00
|
|
|
function recursiveReplace(obj, pattern, replacement) {
|
2023-05-09 22:21:01 -07:00
|
|
|
for (const [key, value] of Object.entries(obj)) {
|
|
|
|
if (typeof value === 'string') {
|
|
|
|
obj[key] = value.replace(pattern, replacement);
|
|
|
|
} else if (typeof value === 'object' && value != null) {
|
Consolidate JavaScript Flavors (#1433)
Summary:
Fixes https://github.com/facebook/yoga/issues/1417
This dramatically simplifies the matrix of Node vs web, ASM vs WASM, sync vs async compilation, or CommonJS vs ES Modules. We have one variant, using wasm, with ESModule top-level await to do async compilation. Web/node share the same binary, and we base64 encode the WASM into a wrapper JS file for compatibility with Node and bundlers.
This has some downsides, like requiring an environment with top level await, but also has upsides, like a consistent, sync looking API compatible with older Yoga, and mitigating TypeScript issues with package exports and typings resolution.
As part of this work I also removed `ts-node` from the toolchain (at the cost of a couple of config files needing to be vanilla JS).
Pull Request resolved: https://github.com/facebook/yoga/pull/1433
Test Plan:
1. `yarn test`
2. `yarn lint`
3. `yarn tsc`
4. `yarn benchmark`
5. `yarn build` website-next
6. `yarn lint` website-next
7. Locally test website-next
8. Examine package artifact created by GitHub
9. All Automation passes
Reviewed By: yungsters
Differential Revision: D50453324
Pulled By: NickGerleman
fbshipit-source-id: fe1192acc69e57fa69a1ff056dd7b5844d2198d5
2023-10-31 20:41:38 -07:00
|
|
|
recursiveReplace(value, pattern, replacement);
|
2023-05-09 22:21:01 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
Consolidate JavaScript Flavors (#1433)
Summary:
Fixes https://github.com/facebook/yoga/issues/1417
This dramatically simplifies the matrix of Node vs web, ASM vs WASM, sync vs async compilation, or CommonJS vs ES Modules. We have one variant, using wasm, with ESModule top-level await to do async compilation. Web/node share the same binary, and we base64 encode the WASM into a wrapper JS file for compatibility with Node and bundlers.
This has some downsides, like requiring an environment with top level await, but also has upsides, like a consistent, sync looking API compatible with older Yoga, and mitigating TypeScript issues with package exports and typings resolution.
As part of this work I also removed `ts-node` from the toolchain (at the cost of a couple of config files needing to be vanilla JS).
Pull Request resolved: https://github.com/facebook/yoga/pull/1433
Test Plan:
1. `yarn test`
2. `yarn lint`
3. `yarn tsc`
4. `yarn benchmark`
5. `yarn build` website-next
6. `yarn lint` website-next
7. Locally test website-next
8. Examine package artifact created by GitHub
9. All Automation passes
Reviewed By: yungsters
Differential Revision: D50453324
Pulled By: NickGerleman
fbshipit-source-id: fe1192acc69e57fa69a1ff056dd7b5844d2198d5
2023-10-31 20:41:38 -07:00
|
|
|
function babelTransformTask(opts) {
|
2023-05-09 15:35:42 -07:00
|
|
|
return () => {
|
|
|
|
const args = [
|
2024-04-15 09:28:23 -07:00
|
|
|
opts.src,
|
2023-05-09 15:35:42 -07:00
|
|
|
'--source-maps',
|
|
|
|
'--out-dir',
|
2024-04-15 09:28:23 -07:00
|
|
|
opts.dst,
|
2023-05-09 15:35:42 -07:00
|
|
|
'--extensions',
|
Consolidate JavaScript Flavors (#1433)
Summary:
Fixes https://github.com/facebook/yoga/issues/1417
This dramatically simplifies the matrix of Node vs web, ASM vs WASM, sync vs async compilation, or CommonJS vs ES Modules. We have one variant, using wasm, with ESModule top-level await to do async compilation. Web/node share the same binary, and we base64 encode the WASM into a wrapper JS file for compatibility with Node and bundlers.
This has some downsides, like requiring an environment with top level await, but also has upsides, like a consistent, sync looking API compatible with older Yoga, and mitigating TypeScript issues with package exports and typings resolution.
As part of this work I also removed `ts-node` from the toolchain (at the cost of a couple of config files needing to be vanilla JS).
Pull Request resolved: https://github.com/facebook/yoga/pull/1433
Test Plan:
1. `yarn test`
2. `yarn lint`
3. `yarn tsc`
4. `yarn benchmark`
5. `yarn build` website-next
6. `yarn lint` website-next
7. Locally test website-next
8. Examine package artifact created by GitHub
9. All Automation passes
Reviewed By: yungsters
Differential Revision: D50453324
Pulled By: NickGerleman
fbshipit-source-id: fe1192acc69e57fa69a1ff056dd7b5844d2198d5
2023-10-31 20:41:38 -07:00
|
|
|
'.js,.cjs,.mjs,.ts,.cts,.mts',
|
2023-05-09 15:35:42 -07:00
|
|
|
];
|
2024-04-15 09:28:23 -07:00
|
|
|
logger.info(`Transforming "${path.resolve(opts.src)}"`);
|
2023-05-09 15:35:42 -07:00
|
|
|
|
|
|
|
return spawn(node, [require.resolve('@babel/cli/bin/babel'), ...args], {
|
|
|
|
cwd: __dirname,
|
Consolidate JavaScript Flavors (#1433)
Summary:
Fixes https://github.com/facebook/yoga/issues/1417
This dramatically simplifies the matrix of Node vs web, ASM vs WASM, sync vs async compilation, or CommonJS vs ES Modules. We have one variant, using wasm, with ESModule top-level await to do async compilation. Web/node share the same binary, and we base64 encode the WASM into a wrapper JS file for compatibility with Node and bundlers.
This has some downsides, like requiring an environment with top level await, but also has upsides, like a consistent, sync looking API compatible with older Yoga, and mitigating TypeScript issues with package exports and typings resolution.
As part of this work I also removed `ts-node` from the toolchain (at the cost of a couple of config files needing to be vanilla JS).
Pull Request resolved: https://github.com/facebook/yoga/pull/1433
Test Plan:
1. `yarn test`
2. `yarn lint`
3. `yarn tsc`
4. `yarn benchmark`
5. `yarn build` website-next
6. `yarn lint` website-next
7. Locally test website-next
8. Examine package artifact created by GitHub
9. All Automation passes
Reviewed By: yungsters
Differential Revision: D50453324
Pulled By: NickGerleman
fbshipit-source-id: fe1192acc69e57fa69a1ff056dd7b5844d2198d5
2023-10-31 20:41:38 -07:00
|
|
|
env: {
|
|
|
|
// Trigger distribution-specific Babel transforms
|
|
|
|
NODE_ENV: 'dist',
|
|
|
|
},
|
2023-05-09 15:35:42 -07:00
|
|
|
});
|
2022-12-28 01:27:12 -08:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
function runBenchTask() {
|
|
|
|
return () => {
|
2023-05-09 15:35:42 -07:00
|
|
|
const files = glob.sync('./tests/Benchmarks/**/*');
|
2022-12-28 01:27:12 -08:00
|
|
|
|
2023-05-10 17:12:10 -07:00
|
|
|
const args = [
|
Consolidate JavaScript Flavors (#1433)
Summary:
Fixes https://github.com/facebook/yoga/issues/1417
This dramatically simplifies the matrix of Node vs web, ASM vs WASM, sync vs async compilation, or CommonJS vs ES Modules. We have one variant, using wasm, with ESModule top-level await to do async compilation. Web/node share the same binary, and we base64 encode the WASM into a wrapper JS file for compatibility with Node and bundlers.
This has some downsides, like requiring an environment with top level await, but also has upsides, like a consistent, sync looking API compatible with older Yoga, and mitigating TypeScript issues with package exports and typings resolution.
As part of this work I also removed `ts-node` from the toolchain (at the cost of a couple of config files needing to be vanilla JS).
Pull Request resolved: https://github.com/facebook/yoga/pull/1433
Test Plan:
1. `yarn test`
2. `yarn lint`
3. `yarn tsc`
4. `yarn benchmark`
5. `yarn build` website-next
6. `yarn lint` website-next
7. Locally test website-next
8. Examine package artifact created by GitHub
9. All Automation passes
Reviewed By: yungsters
Differential Revision: D50453324
Pulled By: NickGerleman
fbshipit-source-id: fe1192acc69e57fa69a1ff056dd7b5844d2198d5
2023-10-31 20:41:38 -07:00
|
|
|
'--loader=babel-register-esm',
|
2023-05-10 17:12:10 -07:00
|
|
|
'./tests/bin/run-bench.ts',
|
|
|
|
...files,
|
|
|
|
];
|
Consolidate JavaScript Flavors (#1433)
Summary:
Fixes https://github.com/facebook/yoga/issues/1417
This dramatically simplifies the matrix of Node vs web, ASM vs WASM, sync vs async compilation, or CommonJS vs ES Modules. We have one variant, using wasm, with ESModule top-level await to do async compilation. Web/node share the same binary, and we base64 encode the WASM into a wrapper JS file for compatibility with Node and bundlers.
This has some downsides, like requiring an environment with top level await, but also has upsides, like a consistent, sync looking API compatible with older Yoga, and mitigating TypeScript issues with package exports and typings resolution.
As part of this work I also removed `ts-node` from the toolchain (at the cost of a couple of config files needing to be vanilla JS).
Pull Request resolved: https://github.com/facebook/yoga/pull/1433
Test Plan:
1. `yarn test`
2. `yarn lint`
3. `yarn tsc`
4. `yarn benchmark`
5. `yarn build` website-next
6. `yarn lint` website-next
7. Locally test website-next
8. Examine package artifact created by GitHub
9. All Automation passes
Reviewed By: yungsters
Differential Revision: D50453324
Pulled By: NickGerleman
fbshipit-source-id: fe1192acc69e57fa69a1ff056dd7b5844d2198d5
2023-10-31 20:41:38 -07:00
|
|
|
logger.info(['node', ...args].join(' '));
|
2023-05-10 17:12:10 -07:00
|
|
|
|
Consolidate JavaScript Flavors (#1433)
Summary:
Fixes https://github.com/facebook/yoga/issues/1417
This dramatically simplifies the matrix of Node vs web, ASM vs WASM, sync vs async compilation, or CommonJS vs ES Modules. We have one variant, using wasm, with ESModule top-level await to do async compilation. Web/node share the same binary, and we base64 encode the WASM into a wrapper JS file for compatibility with Node and bundlers.
This has some downsides, like requiring an environment with top level await, but also has upsides, like a consistent, sync looking API compatible with older Yoga, and mitigating TypeScript issues with package exports and typings resolution.
As part of this work I also removed `ts-node` from the toolchain (at the cost of a couple of config files needing to be vanilla JS).
Pull Request resolved: https://github.com/facebook/yoga/pull/1433
Test Plan:
1. `yarn test`
2. `yarn lint`
3. `yarn tsc`
4. `yarn benchmark`
5. `yarn build` website-next
6. `yarn lint` website-next
7. Locally test website-next
8. Examine package artifact created by GitHub
9. All Automation passes
Reviewed By: yungsters
Differential Revision: D50453324
Pulled By: NickGerleman
fbshipit-source-id: fe1192acc69e57fa69a1ff056dd7b5844d2198d5
2023-10-31 20:41:38 -07:00
|
|
|
return spawn(node, args, {
|
|
|
|
stdio: 'inherit',
|
|
|
|
});
|
2022-12-28 01:27:12 -08:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2023-12-12 09:06:58 -08:00
|
|
|
const emsdkVersion = '3.1.28';
|
|
|
|
const emsdkPath = path.join(__dirname, '.emsdk');
|
|
|
|
const emsdkBin = path.join(
|
|
|
|
emsdkPath,
|
|
|
|
process.platform === 'win32' ? 'emsdk.bat' : 'emsdk',
|
|
|
|
);
|
|
|
|
const emcmakeBin = path.join(
|
|
|
|
emsdkPath,
|
|
|
|
'upstream',
|
|
|
|
'emscripten',
|
|
|
|
process.platform === 'win32' ? 'emcmake.bat' : 'emcmake',
|
|
|
|
);
|
|
|
|
|
|
|
|
function installEmsdkTask() {
|
|
|
|
return async () => {
|
|
|
|
if (await isEmsdkReadyAndActivated()) {
|
|
|
|
logger.verbose(
|
|
|
|
`emsdk ${emsdkVersion} is already installed and activated`,
|
|
|
|
);
|
|
|
|
return false;
|
|
|
|
}
|
2023-11-03 05:23:56 -07:00
|
|
|
|
2023-12-12 09:06:58 -08:00
|
|
|
logger.info(`installing emsdk ${emsdkVersion} to ${emsdkPath}`);
|
|
|
|
await rm(emsdkPath, {recursive: true, force: true});
|
|
|
|
|
|
|
|
await spawn(
|
|
|
|
'git',
|
|
|
|
['clone', 'https://github.com/emscripten-core/emsdk.git', emsdkPath],
|
|
|
|
{stdio: 'inherit'},
|
|
|
|
);
|
|
|
|
|
2024-04-17 03:03:02 -07:00
|
|
|
await spawnShell(emsdkBin, ['install', emsdkVersion], {stdio: 'inherit'});
|
2023-12-12 09:06:58 -08:00
|
|
|
|
2024-04-17 03:03:02 -07:00
|
|
|
await spawnShell(emsdkBin, ['activate', emsdkVersion], {
|
2023-12-12 09:06:58 -08:00
|
|
|
stdio: logger.enableVerbose ? 'inherit' : 'ignore',
|
|
|
|
});
|
|
|
|
};
|
2023-11-03 05:23:56 -07:00
|
|
|
}
|
|
|
|
|
2023-12-12 09:06:58 -08:00
|
|
|
async function isEmsdkReadyAndActivated() {
|
|
|
|
if (!existsSync(emcmakeBin)) {
|
|
|
|
return false;
|
2023-11-03 05:23:56 -07:00
|
|
|
}
|
|
|
|
|
2023-12-12 09:06:58 -08:00
|
|
|
try {
|
|
|
|
const emsdkReleases = JSON.parse(
|
|
|
|
await readFile(path.join(emsdkPath, 'emscripten-releases-tags.json')),
|
|
|
|
).releases;
|
|
|
|
|
|
|
|
const versionHash = emsdkReleases[emsdkVersion];
|
|
|
|
if (!versionHash) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
const activatedVersion = await readFile(
|
|
|
|
path.join(emsdkPath, 'upstream', '.emsdk_version'),
|
|
|
|
);
|
|
|
|
|
|
|
|
return activatedVersion.toString().includes(versionHash);
|
|
|
|
} catch {
|
|
|
|
// Something is wrong. Pave and redo.
|
|
|
|
return false;
|
|
|
|
}
|
2023-11-03 05:23:56 -07:00
|
|
|
}
|
|
|
|
|
2022-12-28 01:27:12 -08:00
|
|
|
function emcmakeGenerateTask() {
|
|
|
|
return () => {
|
2023-12-12 09:06:58 -08:00
|
|
|
logger.verbose(`emcmake path: ${emcmakeBin}`);
|
2023-11-03 05:23:56 -07:00
|
|
|
|
2022-12-28 01:27:12 -08:00
|
|
|
const args = [
|
2023-05-09 15:35:42 -07:00
|
|
|
'cmake',
|
|
|
|
'-S',
|
|
|
|
'.',
|
|
|
|
'-B',
|
|
|
|
'build',
|
2023-12-12 09:06:58 -08:00
|
|
|
...(process.platform === 'win32' ? [] : ['-G', 'Ninja']),
|
2022-12-28 01:27:12 -08:00
|
|
|
];
|
2023-05-09 15:35:42 -07:00
|
|
|
logger.info(['emcmake', ...args].join(' '));
|
2022-12-28 01:27:12 -08:00
|
|
|
|
2024-04-17 03:03:02 -07:00
|
|
|
return spawnShell(emcmakeBin, args, {
|
2023-12-12 09:06:58 -08:00
|
|
|
stdio: logger.enableVerbose ? 'inherit' : 'ignore',
|
|
|
|
});
|
2022-12-28 01:27:12 -08:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
Consolidate JavaScript Flavors (#1433)
Summary:
Fixes https://github.com/facebook/yoga/issues/1417
This dramatically simplifies the matrix of Node vs web, ASM vs WASM, sync vs async compilation, or CommonJS vs ES Modules. We have one variant, using wasm, with ESModule top-level await to do async compilation. Web/node share the same binary, and we base64 encode the WASM into a wrapper JS file for compatibility with Node and bundlers.
This has some downsides, like requiring an environment with top level await, but also has upsides, like a consistent, sync looking API compatible with older Yoga, and mitigating TypeScript issues with package exports and typings resolution.
As part of this work I also removed `ts-node` from the toolchain (at the cost of a couple of config files needing to be vanilla JS).
Pull Request resolved: https://github.com/facebook/yoga/pull/1433
Test Plan:
1. `yarn test`
2. `yarn lint`
3. `yarn tsc`
4. `yarn benchmark`
5. `yarn build` website-next
6. `yarn lint` website-next
7. Locally test website-next
8. Examine package artifact created by GitHub
9. All Automation passes
Reviewed By: yungsters
Differential Revision: D50453324
Pulled By: NickGerleman
fbshipit-source-id: fe1192acc69e57fa69a1ff056dd7b5844d2198d5
2023-10-31 20:41:38 -07:00
|
|
|
function cmakeBuildTask(opts) {
|
2022-12-28 01:27:12 -08:00
|
|
|
return () => {
|
2023-12-12 09:06:58 -08:00
|
|
|
const cmake = which.sync('cmake');
|
|
|
|
logger.verbose(`cmake path: ${cmake}`);
|
|
|
|
|
2022-12-28 01:27:12 -08:00
|
|
|
const args = [
|
2023-05-09 15:35:42 -07:00
|
|
|
'--build',
|
|
|
|
'build',
|
|
|
|
...(opts?.targets ? ['--target', ...opts.targets] : []),
|
2022-12-28 01:27:12 -08:00
|
|
|
];
|
2023-05-09 15:35:42 -07:00
|
|
|
logger.info(['cmake', ...args].join(' '));
|
2022-12-28 01:27:12 -08:00
|
|
|
|
2024-04-17 03:03:02 -07:00
|
|
|
return spawnShell(cmake, args, {stdio: 'inherit'});
|
2022-12-28 01:27:12 -08:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
Consolidate JavaScript Flavors (#1433)
Summary:
Fixes https://github.com/facebook/yoga/issues/1417
This dramatically simplifies the matrix of Node vs web, ASM vs WASM, sync vs async compilation, or CommonJS vs ES Modules. We have one variant, using wasm, with ESModule top-level await to do async compilation. Web/node share the same binary, and we base64 encode the WASM into a wrapper JS file for compatibility with Node and bundlers.
This has some downsides, like requiring an environment with top level await, but also has upsides, like a consistent, sync looking API compatible with older Yoga, and mitigating TypeScript issues with package exports and typings resolution.
As part of this work I also removed `ts-node` from the toolchain (at the cost of a couple of config files needing to be vanilla JS).
Pull Request resolved: https://github.com/facebook/yoga/pull/1433
Test Plan:
1. `yarn test`
2. `yarn lint`
3. `yarn tsc`
4. `yarn benchmark`
5. `yarn build` website-next
6. `yarn lint` website-next
7. Locally test website-next
8. Examine package artifact created by GitHub
9. All Automation passes
Reviewed By: yungsters
Differential Revision: D50453324
Pulled By: NickGerleman
fbshipit-source-id: fe1192acc69e57fa69a1ff056dd7b5844d2198d5
2023-10-31 20:41:38 -07:00
|
|
|
function clangFormatTask(opts) {
|
2022-12-28 01:27:12 -08:00
|
|
|
return () => {
|
|
|
|
const args = [
|
2023-05-09 15:35:42 -07:00
|
|
|
...(opts?.fix ? ['-i'] : ['--dry-run', '--Werror']),
|
|
|
|
...glob.sync('**/*.{h,hh,hpp,c,cpp,cc,m,mm}'),
|
2022-12-28 01:27:12 -08:00
|
|
|
];
|
2023-05-09 15:35:42 -07:00
|
|
|
logger.info(['clang-format', ...args].join(' '));
|
2022-12-28 01:27:12 -08:00
|
|
|
|
2024-04-17 03:03:02 -07:00
|
|
|
return spawnShell(node, [require.resolve('clang-format'), ...args], {
|
2023-05-09 15:35:42 -07:00
|
|
|
stdio: 'inherit',
|
2022-12-28 01:27:12 -08:00
|
|
|
});
|
|
|
|
};
|
|
|
|
}
|
2024-04-17 03:03:02 -07:00
|
|
|
|
|
|
|
function spawnShell(cmd, args, opts) {
|
|
|
|
// https://github.com/nodejs/node/issues/52554
|
|
|
|
return spawn(cmd, args, {...opts, shell: true});
|
|
|
|
}
|