From 02891f987d82a70cdb1ffff7a0bedce7185dc797 Mon Sep 17 00:00:00 2001 From: Tommy Nguyen <4123478+tido64@users.noreply.github.com> Date: Wed, 6 Jul 2022 13:13:13 +0200 Subject: [PATCH] fix(cli): unable to enable `treeShaking` - Updates config schema to reflect breaking changes - Reverts #1706 - "Default to the new `hermes` target" --- .changeset/breezy-pillows-flash.md | 5 ++ .changeset/dull-impalas-clean.md | 5 ++ .changeset/late-drinks-hang.md | 5 ++ .changeset/short-grapes-pay.md | 5 ++ packages/cli/react-native.config.js | 1 - packages/config/schema.json | 80 +++++++++---------- .../metro-serializer-esbuild/src/index.ts | 2 +- 7 files changed, 59 insertions(+), 44 deletions(-) create mode 100644 .changeset/breezy-pillows-flash.md create mode 100644 .changeset/dull-impalas-clean.md create mode 100644 .changeset/late-drinks-hang.md create mode 100644 .changeset/short-grapes-pay.md diff --git a/.changeset/breezy-pillows-flash.md b/.changeset/breezy-pillows-flash.md new file mode 100644 index 0000000000..017650baef --- /dev/null +++ b/.changeset/breezy-pillows-flash.md @@ -0,0 +1,5 @@ +--- +"@rnx-kit/metro-serializer-esbuild": patch +--- + +Reverted "Default to the new `hermes` target" diff --git a/.changeset/dull-impalas-clean.md b/.changeset/dull-impalas-clean.md new file mode 100644 index 0000000000..27e70e0c27 --- /dev/null +++ b/.changeset/dull-impalas-clean.md @@ -0,0 +1,5 @@ +--- +"@rnx-kit/cli": patch +--- + +Fixed tree shaking not being enabled unless `--tree-shake` is specified diff --git a/.changeset/late-drinks-hang.md b/.changeset/late-drinks-hang.md new file mode 100644 index 0000000000..31130a82e9 --- /dev/null +++ b/.changeset/late-drinks-hang.md @@ -0,0 +1,5 @@ +--- +"@rnx-kit/metro-serializer-esbuild": patch +--- + +Fixed not being able to bundle react-native diff --git a/.changeset/short-grapes-pay.md b/.changeset/short-grapes-pay.md new file mode 100644 index 0000000000..0b96b91bd7 --- /dev/null +++ b/.changeset/short-grapes-pay.md @@ -0,0 +1,5 @@ +--- +"@rnx-kit/config": patch +--- + +Updated config schema to reflect breaking changes in 0.5 diff --git a/packages/cli/react-native.config.js b/packages/cli/react-native.config.js index f21a78ec3a..722a38b9d4 100644 --- a/packages/cli/react-native.config.js +++ b/packages/cli/react-native.config.js @@ -90,7 +90,6 @@ module.exports = { description: "Enable tree shaking to remove unused code and reduce the bundle size.", parse: parseBoolean, - default: false, }, { name: "--unstable-transform-profile [string]", diff --git a/packages/config/schema.json b/packages/config/schema.json index 8c51f02d91..47510b29b9 100644 --- a/packages/config/schema.json +++ b/packages/config/schema.json @@ -1,40 +1,33 @@ { - "$schema": "https://json-schema.org/draft/2020-12/schema", - "allOf": [{ "$ref": "https://json.schemastore.org/package.json" }], - "definitions": { + "$defs": { "bundleParameters": { - "allOf": [{ "$ref": "#/definitions/bundlerRuntimeParameters" }], + "allOf": [{ "$ref": "#/$defs/bundlerRuntimeParameters" }], "type": "object", "properties": { - "entryPath": { + "entryFile": { "description": "Path to the .js file which is the entry-point for building the bundle. Either absolute, or relative to the package.", "type": "string" }, - "distPath": { - "description": "Path where the bundle and source map files are written. Either absolute, or relative to the package.", - "type": "string", - "default": "dist" - }, - "assetsPath": { + "assetsDest": { "description": "Path where all bundle assets (strings, images, fonts, sounds, ...) are written. Either absolute, or relative to the package.", "type": "string", "default": "dist" }, - "bundlePrefix": { - "description": "Prefix for the bundle name, followed by the platform and either \".bundle\" (win, android) or \".jsbundle\" (mac, ios).", + "bundleOutput": { + "description": "Path to the output bundle file, either absolute or relative to the package.", "type": "string", - "default": "index" + "default": "index.[platform].bundle" }, "bundleEncoding": { "description": "Encoding scheme to use when writing the bundle file. Currently limited to UTF-8, UTF-16 (little endian), and 7-bit ASCII.", "type": "string", "enum": ["utf8", "utf16le", "ascii"] }, - "sourceMapPath": { + "sourcemapOutput": { "description": "Path to use when creating the bundle source map file. Either absolute, or relative to the package.", "type": "string" }, - "sourceMapSourceRootPath": { + "sourcemapSourcesRoot": { "description": "Path to the package's source files. Used to make source-map paths relative and therefore portable.", "type": "string" } @@ -175,41 +168,44 @@ "properties": { "rnx-kit": { "description": "Configuration for an rnx-kit package", - "allOf": [{ "$ref": "#/definitions/depCheckConfig" }], + "allOf": [{ "$ref": "#/$defs/depCheckConfig" }], "type": "object", "properties": { "bundle": { "description": "Defines how a kit is bundled. Includes shared bundling parameters with platform-specific overrides.", - "allOf": [{ "$ref": "#/definitions/bundleParameters" }], - "type": "object", - "properties": { - "id": { - "description": "Unique identifier for this bundle definition. Only used as a reference within the kit build system.", - "type": "string" - }, - "targets": { - "description": "The platform(s) for which this kit may be bundled.", - "type": "array", - "items": { - "type": "string", - "enum": ["android", "ios", "macos", "win32", "windows"] - } - }, - "platforms": { - "description": "Platform-specific overrides for bundling parameters. Any parameter not listed in an override gets its value from the shared bundle definition, or falls back to defaults.", - "type": "object", - "properties": { - "android": { "$ref": "#/definitions/bundleParameters" }, - "ios": { "$ref": "#/definitions/bundleParameters" }, - "macos": { "$ref": "#/definitions/bundleParameters" }, - "win32": { "$ref": "#/definitions/bundleParameters" }, - "windows": { "$ref": "#/definitions/bundleParameters" } + "type": "array", + "items": { + "allOf": [{ "$ref": "#/$defs/bundleParameters" }], + "type": "object", + "properties": { + "id": { + "description": "Unique identifier for this bundle definition. Only used as a reference within the kit build system.", + "type": "string" + }, + "targets": { + "description": "The platform(s) for which this kit may be bundled.", + "type": "array", + "items": { + "type": "string", + "enum": ["android", "ios", "macos", "win32", "windows"] + } + }, + "platforms": { + "description": "Platform-specific overrides for bundling parameters. Any parameter not listed in an override gets its value from the shared bundle definition, or falls back to defaults.", + "type": "object", + "properties": { + "android": { "$ref": "#/$defs/bundleParameters" }, + "ios": { "$ref": "#/$defs/bundleParameters" }, + "macos": { "$ref": "#/$defs/bundleParameters" }, + "win32": { "$ref": "#/$defs/bundleParameters" }, + "windows": { "$ref": "#/$defs/bundleParameters" } + } } } } }, "server": { - "allOf": [{ "$ref": "#/definitions/bundlerRuntimeParameters" }], + "allOf": [{ "$ref": "#/$defs/bundlerRuntimeParameters" }], "type": "object", "properties": { "projectRoot": { diff --git a/packages/metro-serializer-esbuild/src/index.ts b/packages/metro-serializer-esbuild/src/index.ts index ff0c09a4c9..ca7482a542 100644 --- a/packages/metro-serializer-esbuild/src/index.ts +++ b/packages/metro-serializer-esbuild/src/index.ts @@ -299,7 +299,7 @@ export function MetroSerializer( // To ensure that Hermes is able to consume this bundle, we must target // ES5. Hermes is missing a bunch of ES6 features, such as block scoping // (see https://github.com/facebook/hermes/issues/575). - target: buildOptions?.target ?? "hermes0", + target: buildOptions?.target ?? "es5", write: false, })