From 342c86abfc514480f31007b0cd72ec250cfb118a Mon Sep 17 00:00:00 2001 From: Emily Xiong Date: Tue, 23 Aug 2022 16:39:08 -0400 Subject: [PATCH] feat(react-native): update react native bundle options --- docs/generated/packages/react-native.json | 47 +++++++++++++++---- e2e/react-native/src/react-native.test.ts | 22 +++++---- .../src/executors/bundle/bundle.impl.ts | 15 ++++-- .../src/executors/bundle/schema.d.ts | 14 ++++-- .../src/executors/bundle/schema.json | 47 +++++++++++++++---- .../change-searchDir-storybook.ts | 2 +- 6 files changed, 114 insertions(+), 33 deletions(-) diff --git a/docs/generated/packages/react-native.json b/docs/generated/packages/react-native.json index 708234406e417..f1a3252b85511 100644 --- a/docs/generated/packages/react-native.json +++ b/docs/generated/packages/react-native.json @@ -709,14 +709,26 @@ "description": "JS Bundle target options.", "type": "object", "properties": { + "entryFile": { + "type": "string", + "description": "The entry file relative to project root." + }, + "platform": { + "enum": ["ios", "android"], + "description": "Platform to build for." + }, + "transformer": { + "type": "string", + "description": "Specify a custom transformer to be used." + }, "dev": { "type": "boolean", "description": "Generate a development build.", "default": true }, - "entryFile": { - "type": "string", - "description": "The entry file relative to project root." + "minify": { + "type": "boolean", + "description": "Allows overriding whether bundle is minified." }, "bundleOutput": { "type": "string", @@ -726,13 +738,32 @@ "type": "number", "description": "The number of workers we should parallelize the transformer on." }, - "sourceMap": { + "sourcemapOutput": { + "type": "string", + "description": "File name where to store the sourcemap file for resulting bundle, ex. /tmp/groups.map." + }, + "sourcemapSourcesRoot": { + "type": "string", + "description": "Path to make sourcemaps sources entries relative to, ex. /root/dir." + }, + "sourcemapUseAbsolutePath": { "type": "boolean", - "description": "Whether source maps should be generated or not." + "description": "Report SourceMapURL using its full path.", + "default": false }, - "platform": { - "description": "Platform to build for (`ios`, `android`).", - "type": "string" + "assetsDest": { + "type": "string", + "description": "Directory name where to store assets referenced in the bundle." + }, + "resetCache": { + "type": "boolean", + "description": "Removes cached files.", + "default": false + }, + "readGlobalCache": { + "type": "boolean", + "description": "Removes cached files.", + "default": false } }, "required": ["platform", "entryFile", "bundleOutput"], diff --git a/e2e/react-native/src/react-native.test.ts b/e2e/react-native/src/react-native.test.ts index c6b262f76b035..ea37d423512fa 100644 --- a/e2e/react-native/src/react-native.test.ts +++ b/e2e/react-native/src/react-native.test.ts @@ -42,21 +42,27 @@ describe('react native', () => { const libLintResults = await runCLIAsync(`lint ${libName}`); expect(libLintResults.combinedOutput).toContain('All files pass linting.'); - const iosBundleResult = await runCLIAsync(`bundle-ios ${appName}`); + const iosBundleResult = await runCLIAsync( + `bundle-ios ${appName} --sourcemapOutput=../../dist/apps/${appName}/ios/main.map` + ); expect(iosBundleResult.combinedOutput).toContain( 'Done writing bundle output' ); - expect(() => - checkFilesExist(`dist/apps/${appName}/ios/main.jsbundle`) - ).not.toThrow(); + expect(() => { + checkFilesExist(`dist/apps/${appName}/ios/main.jsbundle`); + checkFilesExist(`dist/apps/${appName}/ios/main.map`); + }).not.toThrow(); - const androidBundleResult = await runCLIAsync(`bundle-android ${appName}`); + const androidBundleResult = await runCLIAsync( + `bundle-android ${appName} --sourcemapOutput=../../dist/apps/${appName}/android/main.map` + ); expect(androidBundleResult.combinedOutput).toContain( 'Done writing bundle output' ); - expect(() => - checkFilesExist(`dist/apps/${appName}/android/main.jsbundle`) - ).not.toThrow(); + expect(() => { + checkFilesExist(`dist/apps/${appName}/android/main.jsbundle`); + checkFilesExist(`dist/apps/${appName}/android/main.map`); + }).not.toThrow(); }, 1000000); it('should create storybook with application', async () => { diff --git a/packages/react-native/src/executors/bundle/bundle.impl.ts b/packages/react-native/src/executors/bundle/bundle.impl.ts index 84d544aa1ba03..e12b7d235baed 100644 --- a/packages/react-native/src/executors/bundle/bundle.impl.ts +++ b/packages/react-native/src/executors/bundle/bundle.impl.ts @@ -1,9 +1,10 @@ import { createDirectory } from '@nrwl/workspace/src/utilities/fileutils'; -import { names } from '@nrwl/devkit'; -import { dirname, join, relative, sep } from 'path'; -import { ensureNodeModulesSymlink } from '../../utils/ensure-node-modules-symlink'; +import { names, ExecutorContext } from '@nrwl/devkit'; +import { dirname, join } from 'path'; import { ChildProcess, fork } from 'child_process'; -import { ExecutorContext } from '@nrwl/devkit'; + +import { ensureNodeModulesSymlink } from '../../utils/ensure-node-modules-symlink'; + import { ReactNativeBundleOptions } from './schema'; export interface ReactNativeBundleOutput { @@ -33,7 +34,11 @@ export default async function* bundleExecutor( } } -function runCliBuild(workspaceRoot, projectRoot, options) { +function runCliBuild( + workspaceRoot: string, + projectRoot: string, + options: ReactNativeBundleOptions +) { return new Promise((resolve, reject) => { const cliOptions = createBundleOptions(options); childProcess = fork( diff --git a/packages/react-native/src/executors/bundle/schema.d.ts b/packages/react-native/src/executors/bundle/schema.d.ts index dfaa8ba589e57..133f0b98661f1 100644 --- a/packages/react-native/src/executors/bundle/schema.d.ts +++ b/packages/react-native/src/executors/bundle/schema.d.ts @@ -1,8 +1,16 @@ +// options form https://github.com/react-native-community/cli/blob/main/docs/commands.md#bundle export interface ReactNativeBundleOptions { - dev: boolean; - platform: string; entryFile: string; + platform: string; + transfrom?: string; + dev: boolean; // default is true + minify?: boolean; // default is false bundleOutput: string; maxWorkers: number; - sourceMap: boolean; + sourcemapOutput?: string; + sourcemapSourcesRoot?: string; + sourcemapUseAbsolutePath: boolean; // default is false + assetDest?: string; + resetCache: boolean; // default is false + readGlobalCache?: boolean; // default is false } diff --git a/packages/react-native/src/executors/bundle/schema.json b/packages/react-native/src/executors/bundle/schema.json index 3e42dd5d4d989..411a17edcc3c9 100644 --- a/packages/react-native/src/executors/bundle/schema.json +++ b/packages/react-native/src/executors/bundle/schema.json @@ -6,14 +6,26 @@ "description": "JS Bundle target options.", "type": "object", "properties": { + "entryFile": { + "type": "string", + "description": "The entry file relative to project root." + }, + "platform": { + "enum": ["ios", "android"], + "description": "Platform to build for." + }, + "transformer": { + "type": "string", + "description": "Specify a custom transformer to be used." + }, "dev": { "type": "boolean", "description": "Generate a development build.", "default": true }, - "entryFile": { - "type": "string", - "description": "The entry file relative to project root." + "minify": { + "type": "boolean", + "description": "Allows overriding whether bundle is minified." }, "bundleOutput": { "type": "string", @@ -23,13 +35,32 @@ "type": "number", "description": "The number of workers we should parallelize the transformer on." }, - "sourceMap": { + "sourcemapOutput": { + "type": "string", + "description": "File name where to store the sourcemap file for resulting bundle, ex. /tmp/groups.map." + }, + "sourcemapSourcesRoot": { + "type": "string", + "description": "Path to make sourcemaps sources entries relative to, ex. /root/dir." + }, + "sourcemapUseAbsolutePath": { "type": "boolean", - "description": "Whether source maps should be generated or not." + "description": "Report SourceMapURL using its full path.", + "default": false }, - "platform": { - "description": "Platform to build for (`ios`, `android`).", - "type": "string" + "assetsDest": { + "type": "string", + "description": "Directory name where to store assets referenced in the bundle." + }, + "resetCache": { + "type": "boolean", + "description": "Removes cached files.", + "default": false + }, + "readGlobalCache": { + "type": "boolean", + "description": "Removes cached files.", + "default": false } }, "required": ["platform", "entryFile", "bundleOutput"] diff --git a/packages/react-native/src/migrations/update-14-5-8/change-searchDir-storybook.ts b/packages/react-native/src/migrations/update-14-5-8/change-searchDir-storybook.ts index 659201ed28aef..0767b06b525ce 100644 --- a/packages/react-native/src/migrations/update-14-5-8/change-searchDir-storybook.ts +++ b/packages/react-native/src/migrations/update-14-5-8/change-searchDir-storybook.ts @@ -17,7 +17,7 @@ export default async function update(tree: Tree) { ) continue; const searchDir = config.targets?.['storybook']?.options?.searchDir; - if (!searchDir || !searchDir.length) { + if (!searchDir || !searchDir.length || Array.isArray(searchDir)) { continue; } config.targets['storybook'].options.searchDir = searchDir.split(',');