[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
lauren committed
Feb 25, 2025 at 12:16 UTC
58def9f2e6ddd2ae3dfa9606711f1aea63a220c1
5 files changed
+148
-8
compiler/packages/react-forgive/.vscodeignore
new
+4
@@ -0,0 +1,4 @@
1
+**/node_modules
2
+client
3
+server
4
+scripts
compiler/packages/react-forgive/package.json
+8
-8
@@ -35,23 +35,23 @@
35
]
36
},
37
"scripts": {
38
- "compile": "yarn run esbuild-base -- --sourcemap",
38
+ "build": "yarn run compile",
39
+ "compile": "rimraf dist && concurrently -n server,client \"scripts/build.mjs -t server\" \"scripts/build.mjs -t client\"",
40
"dev": "yarn run package && yarn run install-ext",
40
- "esbuild-base": "esbuild ./src/extension.ts --bundle --outfile=dist/extension.js --external:vscode --format=cjs --platform=node",
41
- "install-ext": "code --install-extension vscode-react-compiler-0.0.1.vsix",
41
+ "install-ext": "code --install-extension react-forgive-0.0.0.vsix",
42
"lint": "echo 'no tests'",
43
- "package": "vsce package",
43
+ "package": "rm -f react-forgive-0.0.0.vsix && vsce package --yarn",
44
"postinstall": "cd client && yarn install && cd ../server && yarn install && cd ..",
45
"pretest": "yarn run compile && yarn run lint",
46
"test": "echo 'no tests'",
47
- "test-compile": "tsc -p ./",
48
- "vscode:prepublish": "yarn run esbuild-base -- --minify",
49
- "watch": "yarn run esbuild-base -- --sourcemap --watch"
47
+ "vscode:prepublish": "yarn run compile",
48
+ "watch": "scripts/build.mjs --watch"
49
},
50
"devDependencies": {
51
"@eslint/js": "^9.13.0",
52
"@types/node": "^20",
53
"eslint": "^9.13.0",
55
- "typescript-eslint": "^8.16.0"
54
+ "typescript-eslint": "^8.16.0",
55
+ "yargs": "^17.7.2"
56
}
57
}
compiler/packages/react-forgive/scripts/build.mjs
new
+58
@@ -0,0 +1,58 @@
1
+#!/usr/bin/env node
2
+
3
+/**
4
+ * Copyright (c) Meta Platforms, Inc. and affiliates.
5
+ *
6
+ * This source code is licensed under the MIT license found in the
7
+ * LICENSE file in the root directory of this source tree.
8
+ */
9
+
10
+import * as esbuild from 'esbuild';
11
+import yargs from 'yargs';
12
+import * as Server from './server.mjs';
13
+import * as Client from './client.mjs';
14
+import path from 'path';
15
+import {fileURLToPath} from 'url';
16
+
17
+const IS_DEV = process.env.NODE_ENV === 'development';
18
+const __filename = fileURLToPath(import.meta.url);
19
+const __dirname = path.dirname(__filename);
20
+
21
+const argv = yargs(process.argv.slice(2))
22
+ .choices('t', ['client', 'server'])
23
+ .options('w', {
24
+ alias: 'watch',
25
+ default: false,
26
+ type: 'boolean',
27
+ })
28
+ .parse();
29
+
30
+async function main() {
31
+ if (argv.w) {
32
+ const serverCtx = await esbuild.context(Server.config);
33
+ const clientCtx = await esbuild.context(Client.config);
34
+ await Promise.all([serverCtx.watch(), clientCtx.watch()]);
35
+ console.log('watching for changes...');
36
+ } else {
37
+ switch (argv.t) {
38
+ case 'server': {
39
+ await esbuild.build({
40
+ sourcemap: IS_DEV,
41
+ minify: IS_DEV === false,
42
+ ...Server.config,
43
+ });
44
+ break;
45
+ }
46
+ case 'client': {
47
+ await esbuild.build({
48
+ sourcemap: IS_DEV,
49
+ minify: IS_DEV === false,
50
+ ...Client.config,
51
+ });
52
+ break;
53
+ }
54
+ }
55
+ }
56
+}
57
+
58
+main();
compiler/packages/react-forgive/scripts/client.mjs
new
+39
@@ -0,0 +1,39 @@
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
+
8
+import path from 'path';
9
+import {fileURLToPath} from 'url';
10
+
11
+const __filename = fileURLToPath(import.meta.url);
12
+const __dirname = path.dirname(__filename);
13
+
14
+export const entryPoint = path.join(__dirname, '../client/src/extension.ts');
15
+export const outfile = path.join(__dirname, '../dist/extension.js');
16
+export const config = {
17
+ entryPoints: [entryPoint],
18
+ outfile,
19
+ bundle: true,
20
+ external: ['vscode'],
21
+ format: 'cjs',
22
+ platform: 'node',
23
+ banner: {
24
+ js: `/**
25
+ * Copyright (c) Meta Platforms, Inc. and affiliates.
26
+ *
27
+ * This source code is licensed under the MIT license found in the
28
+ * LICENSE file in the root directory of this source tree.
29
+ *
30
+ * @lightSyntaxTransform
31
+ * @noflow
32
+ * @nolint
33
+ * @preventMunge
34
+ * @preserve-invariant-messages
35
+ */
36
+
37
+`,
38
+ },
39
+};
compiler/packages/react-forgive/scripts/server.mjs
new
+39
@@ -0,0 +1,39 @@
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
+
8
+import path from 'path';
9
+import {fileURLToPath} from 'url';
10
+
11
+const __filename = fileURLToPath(import.meta.url);
12
+const __dirname = path.dirname(__filename);
13
+
14
+export const entryPoint = path.join(__dirname, '../server/src/index.ts');
15
+export const outfile = path.join(__dirname, '../dist/extension.js');
16
+export const config = {
17
+ entryPoints: [entryPoint],
18
+ outfile,
19
+ bundle: true,
20
+ external: ['vscode'],
21
+ format: 'cjs',
22
+ platform: 'node',
23
+ banner: {
24
+ js: `/**
25
+ * Copyright (c) Meta Platforms, Inc. and affiliates.
26
+ *
27
+ * This source code is licensed under the MIT license found in the
28
+ * LICENSE file in the root directory of this source tree.
29
+ *
30
+ * @lightSyntaxTransform
31
+ * @noflow
32
+ * @nolint
33
+ * @preventMunge
34
+ * @preserve-invariant-messages
35
+ */
36
+
37
+`,
38
+ },
39
+};