From 58def9f2e6ddd2ae3dfa9606711f1aea63a220c1 Mon Sep 17 00:00:00 2001 From: lauren Date: Tue, 25 Feb 2025 12:16:10 -0500 Subject: [PATCH] [forgive] Add build scripts (#31927) Adds basic build scripts. --- [//]: # (BEGIN SAPLING FOOTER) Stack created with [Sapling](https://sapling-scm.com). Best reviewed with [ReviewStack](https://reviewstack.dev/facebook/react/pull/31927). * #31918 * __->__ #31927 --- compiler/packages/react-forgive/.vscodeignore | 4 ++ compiler/packages/react-forgive/package.json | 16 ++--- .../packages/react-forgive/scripts/build.mjs | 58 +++++++++++++++++++ .../packages/react-forgive/scripts/client.mjs | 39 +++++++++++++ .../packages/react-forgive/scripts/server.mjs | 39 +++++++++++++ 5 files changed, 148 insertions(+), 8 deletions(-) create mode 100644 compiler/packages/react-forgive/.vscodeignore create mode 100755 compiler/packages/react-forgive/scripts/build.mjs create mode 100644 compiler/packages/react-forgive/scripts/client.mjs create mode 100644 compiler/packages/react-forgive/scripts/server.mjs diff --git a/compiler/packages/react-forgive/.vscodeignore b/compiler/packages/react-forgive/.vscodeignore new file mode 100644 index 0000000000000..91f9572794cd5 --- /dev/null +++ b/compiler/packages/react-forgive/.vscodeignore @@ -0,0 +1,4 @@ +**/node_modules +client +server +scripts diff --git a/compiler/packages/react-forgive/package.json b/compiler/packages/react-forgive/package.json index 30aec4235523e..bc5f7310e98fe 100644 --- a/compiler/packages/react-forgive/package.json +++ b/compiler/packages/react-forgive/package.json @@ -35,23 +35,23 @@ ] }, "scripts": { - "compile": "yarn run esbuild-base -- --sourcemap", + "build": "yarn run compile", + "compile": "rimraf dist && concurrently -n server,client \"scripts/build.mjs -t server\" \"scripts/build.mjs -t client\"", "dev": "yarn run package && yarn run install-ext", - "esbuild-base": "esbuild ./src/extension.ts --bundle --outfile=dist/extension.js --external:vscode --format=cjs --platform=node", - "install-ext": "code --install-extension vscode-react-compiler-0.0.1.vsix", + "install-ext": "code --install-extension react-forgive-0.0.0.vsix", "lint": "echo 'no tests'", - "package": "vsce package", + "package": "rm -f react-forgive-0.0.0.vsix && vsce package --yarn", "postinstall": "cd client && yarn install && cd ../server && yarn install && cd ..", "pretest": "yarn run compile && yarn run lint", "test": "echo 'no tests'", - "test-compile": "tsc -p ./", - "vscode:prepublish": "yarn run esbuild-base -- --minify", - "watch": "yarn run esbuild-base -- --sourcemap --watch" + "vscode:prepublish": "yarn run compile", + "watch": "scripts/build.mjs --watch" }, "devDependencies": { "@eslint/js": "^9.13.0", "@types/node": "^20", "eslint": "^9.13.0", - "typescript-eslint": "^8.16.0" + "typescript-eslint": "^8.16.0", + "yargs": "^17.7.2" } } diff --git a/compiler/packages/react-forgive/scripts/build.mjs b/compiler/packages/react-forgive/scripts/build.mjs new file mode 100755 index 0000000000000..5fc8828e6e749 --- /dev/null +++ b/compiler/packages/react-forgive/scripts/build.mjs @@ -0,0 +1,58 @@ +#!/usr/bin/env node + +/** + * 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. + */ + +import * as esbuild from 'esbuild'; +import yargs from 'yargs'; +import * as Server from './server.mjs'; +import * as Client from './client.mjs'; +import path from 'path'; +import {fileURLToPath} from 'url'; + +const IS_DEV = process.env.NODE_ENV === 'development'; +const __filename = fileURLToPath(import.meta.url); +const __dirname = path.dirname(__filename); + +const argv = yargs(process.argv.slice(2)) + .choices('t', ['client', 'server']) + .options('w', { + alias: 'watch', + default: false, + type: 'boolean', + }) + .parse(); + +async function main() { + if (argv.w) { + const serverCtx = await esbuild.context(Server.config); + const clientCtx = await esbuild.context(Client.config); + await Promise.all([serverCtx.watch(), clientCtx.watch()]); + console.log('watching for changes...'); + } else { + switch (argv.t) { + case 'server': { + await esbuild.build({ + sourcemap: IS_DEV, + minify: IS_DEV === false, + ...Server.config, + }); + break; + } + case 'client': { + await esbuild.build({ + sourcemap: IS_DEV, + minify: IS_DEV === false, + ...Client.config, + }); + break; + } + } + } +} + +main(); diff --git a/compiler/packages/react-forgive/scripts/client.mjs b/compiler/packages/react-forgive/scripts/client.mjs new file mode 100644 index 0000000000000..9a8987061b391 --- /dev/null +++ b/compiler/packages/react-forgive/scripts/client.mjs @@ -0,0 +1,39 @@ +/** + * 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. + */ + +import path from 'path'; +import {fileURLToPath} from 'url'; + +const __filename = fileURLToPath(import.meta.url); +const __dirname = path.dirname(__filename); + +export const entryPoint = path.join(__dirname, '../client/src/extension.ts'); +export const outfile = path.join(__dirname, '../dist/extension.js'); +export const config = { + entryPoints: [entryPoint], + outfile, + bundle: true, + external: ['vscode'], + format: 'cjs', + platform: 'node', + banner: { + js: `/** + * 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. + * + * @lightSyntaxTransform + * @noflow + * @nolint + * @preventMunge + * @preserve-invariant-messages + */ + +`, + }, +}; diff --git a/compiler/packages/react-forgive/scripts/server.mjs b/compiler/packages/react-forgive/scripts/server.mjs new file mode 100644 index 0000000000000..95afe8770d44b --- /dev/null +++ b/compiler/packages/react-forgive/scripts/server.mjs @@ -0,0 +1,39 @@ +/** + * 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. + */ + +import path from 'path'; +import {fileURLToPath} from 'url'; + +const __filename = fileURLToPath(import.meta.url); +const __dirname = path.dirname(__filename); + +export const entryPoint = path.join(__dirname, '../server/src/index.ts'); +export const outfile = path.join(__dirname, '../dist/extension.js'); +export const config = { + entryPoints: [entryPoint], + outfile, + bundle: true, + external: ['vscode'], + format: 'cjs', + platform: 'node', + banner: { + js: `/** + * 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. + * + * @lightSyntaxTransform + * @noflow + * @nolint + * @preventMunge + * @preserve-invariant-messages + */ + +`, + }, +};