Skip to content

Commit

Permalink
feat(react-native): update react native bundle options
Browse files Browse the repository at this point in the history
  • Loading branch information
xiongemi committed Aug 24, 2022
1 parent 36a72c7 commit c02d045
Show file tree
Hide file tree
Showing 6 changed files with 108 additions and 30 deletions.
47 changes: 39 additions & 8 deletions docs/generated/packages/react-native.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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"],
Expand Down
22 changes: 14 additions & 8 deletions e2e/react-native/src/react-native.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 () => {
Expand Down
6 changes: 4 additions & 2 deletions packages/react-native/src/executors/bundle/bundle.impl.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
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 { 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 {
Expand Down
14 changes: 11 additions & 3 deletions packages/react-native/src/executors/bundle/schema.d.ts
Original file line number Diff line number Diff line change
@@ -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
}
47 changes: 39 additions & 8 deletions packages/react-native/src/executors/bundle/schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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"]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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(',');
Expand Down

0 comments on commit c02d045

Please sign in to comment.