@samitouri / QOS-React-2 / commits / f01f74d9e1

Also build react-forget-runtime with rollup

This adds rollup to the runtime and adds a new plugin to add the license banner + inject the `"use no memo"` directive. We need to inject it there as rollup currently strips out unknown directives during bundling.

Lauren Tan committed Apr 2, 2024 at 12:13 UTC f01f74d9e17c259db9ea2567f49a5138f9851ce5
5 files changed +87 -2
compiler/package.json
+1
@@ -37,6 +37,7 @@
37 "@tsconfig/strictest": "^2.0.5",
38 "concurrently": "^7.4.0",
39 "rollup": "^4.13.2",
40 + "rollup-plugin-banner2": "^1.2.3",
41 "rollup-plugin-license": "^3.3.1",
42 "rollup-plugin-prettier": "^4.1.1",
43 "typescript": "^5.4.3"
compiler/packages/react-forget-runtime/package.json
+1 -1
@@ -10,7 +10,7 @@
10 "react": "^18.2.0"
11 },
12 "scripts": {
13 - "build": "tsc",
13 + "build": "rimraf dist && rollup --config --bundleConfigAsCjs",
14 "test": "echo 'no tests'"
15 }
16 }
compiler/packages/react-forget-runtime/rollup.config.js new
+64
@@ -0,0 +1,64 @@
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 typescript from "@rollup/plugin-typescript";
9 +import { nodeResolve } from "@rollup/plugin-node-resolve";
10 +import commonjs from "@rollup/plugin-commonjs";
11 +import json from "@rollup/plugin-json";
12 +import path from "path";
13 +import process from "process";
14 +import terser from "@rollup/plugin-terser";
15 +import banner2 from "rollup-plugin-banner2";
16 +
17 +const NO_INLINE = new Set(["react"]);
18 +
19 +const PROD_ROLLUP_CONFIG = {
20 + input: "src/index.ts",
21 + output: {
22 + file: "dist/index.js",
23 + format: "cjs",
24 + sourcemap: true,
25 + },
26 + plugins: [
27 + typescript({
28 + tsconfig: "./tsconfig.json",
29 + compilerOptions: {
30 + noEmit: true,
31 + },
32 + }),
33 + json(),
34 + nodeResolve({
35 + preferBuiltins: true,
36 + resolveOnly: (module) => NO_INLINE.has(module) === false,
37 + rootDir: path.join(process.cwd(), ".."),
38 + }),
39 + commonjs(),
40 + terser({
41 + format: {
42 + comments: false,
43 + },
44 + }),
45 + banner2(
46 + () => `/**
47 + * Copyright (c) Meta Platforms, Inc. and affiliates.
48 + *
49 + * This source code is licensed under the MIT license found in the
50 + * LICENSE file in the root directory of this source tree.
51 + *
52 + * @lightSyntaxTransform
53 + * @noflow
54 + * @nolint
55 + * @preventMunge
56 + * @preserve-invariant-messages
57 + */
58 +
59 +"use no memo";` // DO NOT REMOVE
60 + ),
61 + ],
62 +};
63 +
64 +export default PROD_ROLLUP_CONFIG;
compiler/packages/react-forget-runtime/tsconfig.json
+2 -1
@@ -1,7 +1,8 @@
1 {
2 "extends": "@tsconfig/strictest/tsconfig.json",
3 "compilerOptions": {
4 - "module": "CommonJS",
4 + "module": "ES2015",
5 + "moduleResolution": "Bundler",
6 "declaration": true,
7 "outDir": "dist",
8 "jsx": "react-jsxdev",
compiler/yarn.lock
+19
@@ -7536,6 +7536,13 @@ magic-string@0.30.5, magic-string@~0.30.0:
7536 dependencies:
7537 "@jridgewell/sourcemap-codec" "^1.4.15"
7538
7539 +magic-string@^0.25.7:
7540 + version "0.25.9"
7541 + resolved "https://registry.yarnpkg.com/magic-string/-/magic-string-0.25.9.tgz#de7f9faf91ef8a1c91d02c2e5314c8277dbcdd1c"
7542 + integrity sha512-RmF0AsMzgt25qzqqLc1+MbHmhdx0ojF2Fvs4XnOqz2ZOBXzzkEwc/dJQZCYHAn7v1jbVOjAZfK8msRn4BxO4VQ==
7543 + dependencies:
7544 + sourcemap-codec "^1.4.8"
7545 +
7546 magic-string@^0.30.3:
7547 version "0.30.8"
7548 resolved "https://registry.yarnpkg.com/magic-string/-/magic-string-0.30.8.tgz#14e8624246d2bedba70d5462aa99ac9681844613"
@@ -8553,6 +8560,13 @@ rimraf@^3.0.0, rimraf@^3.0.2:
8560 dependencies:
8561 glob "^7.1.3"
8562
8563 +rollup-plugin-banner2@^1.2.3:
8564 + version "1.2.3"
8565 + resolved "https://registry.yarnpkg.com/rollup-plugin-banner2/-/rollup-plugin-banner2-1.2.3.tgz#4aa454e41a80623180164625368ec0321641a0ef"
8566 + integrity sha512-lhpPoDTRZMIvSK1AppGNDIZ4fnQuW4WuENuswSUzvXhTR596zWNOmCaCYoqD15QixnjnG+wT+jauLEK5qGRPZg==
8567 + dependencies:
8568 + magic-string "^0.25.7"
8569 +
8570 rollup-plugin-license@^3.3.1:
8571 version "3.3.1"
8572 resolved "https://registry.yarnpkg.com/rollup-plugin-license/-/rollup-plugin-license-3.3.1.tgz#73b68e33477524198d6f3f9befc905f59bf37c53"
@@ -8840,6 +8854,11 @@ source-map@^0.6.0, source-map@^0.6.1, source-map@~0.6.1:
8854 resolved "https://registry.yarnpkg.com/source-map/-/source-map-0.6.1.tgz#74722af32e9614e9c287a8d0bbde48b5e2f1a263"
8855 integrity sha512-UjgapumWlbMhkBgzT7Ykc5YXUT46F0iKu8SGXq0bcwP5dz/h0Plj6enJqjz1Zbq2l5WaqYnrVbwWOWMyF3F47g==
8856
8857 +sourcemap-codec@^1.4.8:
8858 + version "1.4.8"
8859 + resolved "https://registry.yarnpkg.com/sourcemap-codec/-/sourcemap-codec-1.4.8.tgz#ea804bd94857402e6992d05a38ef1ae35a9ab4c4"
8860 + integrity sha512-9NykojV5Uih4lgo5So5dtw+f0JgJX30KCNI8gwhz2J9A15wD0Ml6tjHKwf6fTSa6fAdVBdZeNOs9eJ71qCk8vA==
8861 +
8862 spawn-command@^0.0.2-1:
8863 version "0.0.2-1"
8864 resolved "https://registry.yarnpkg.com/spawn-command/-/spawn-command-0.0.2-1.tgz#62f5e9466981c1b796dc5929937e11c9c6921bd0"