Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions packages/community-cli-plugin/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ npx react-native bundle --entry-file <path> [options]
| `--minify [boolean]` | Allows overriding whether bundle is minified. Defaults to `false` if `--dev` is set. Disabling minification can be useful for speeding up production builds for testing purposes. |
| `--bundle-output <string>` | Specify the path to store the resulting bundle. |
| `--bundle-encoding <string>` | Specify the encoding for writing the bundle (<https://nodejs.org/api/buffer.html#buffer_buffer>). |
| `--resolver-option <string...>` | Custom resolver options of the form key=value. URL-encoded. May be specified multiple times. |
| `--sourcemap-output <string>` | Specify the path to store the source map file for the resulting bundle. |
| `--sourcemap-sources-root <string>` | Set the root path for source map entries. |
| `--sourcemap-use-absolute-path` | Report `SourceMapURL` using its full path. |
Expand Down
1 change: 1 addition & 0 deletions packages/community-cli-plugin/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
"metro-config": "^0.80.3",
"metro-core": "^0.80.3",
"node-fetch": "^2.2.0",
"querystring": "^0.2.1",
"readline": "^1.3.0"
},
"devDependencies": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import type {ConfigT} from 'metro-config';
import type {RequestOptions} from 'metro/src/shared/types.flow';

import loadMetroConfig from '../../utils/loadMetroConfig';
import parseKeyValueParamArray from '../../utils/parseKeyValueParamArray';
import saveAssets from './saveAssets';
import {logger} from '@react-native-community/cli-tools';
import chalk from 'chalk';
Expand Down Expand Up @@ -42,7 +43,7 @@ export type BundleCommandArgs = {
verbose: boolean,
unstableTransformProfile: string,
indexedRamBundle?: boolean,
customResolverOptions?: Record<string, string>,
resolverOption?: Array<string>,
};

async function buildBundle(
Expand All @@ -65,6 +66,10 @@ async function buildBundleWithConfig(
config: ConfigT,
bundleImpl: typeof metroBundle | typeof metroRamBundle = metroBundle,
): Promise<void> {
const customResolverOptions = parseKeyValueParamArray(
args.resolverOption ?? [],
);

if (config.resolver.platforms.indexOf(args.platform) === -1) {
logger.error(
`Invalid platform ${
Expand Down Expand Up @@ -100,7 +105,7 @@ async function buildBundleWithConfig(
minify: args.minify !== undefined ? args.minify : !args.dev,
platform: args.platform,
unstable_transformProfile: args.unstableTransformProfile,
customResolverOptions: args.customResolverOptions,
customResolverOptions,
};
const server = new Server(config);

Expand Down
15 changes: 5 additions & 10 deletions packages/community-cli-plugin/src/commands/bundle/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -115,16 +115,11 @@ const bundleCommand: Command = {
parse: (val: string): string => path.resolve(val),
},
{
name: '--custom-resolver-options <string>',
description: 'Custom resolver options, format: key=value,key2=value2.',
parse: (val: string): Record<string, string> => {
return Object.fromEntries(
val.split(',').map(option => {
const [key, value] = option.split('=');
return [key, value];
}),
);
},
name: '--resolver-option <string...>',
description:
'Custom resolver options of the form key=value. URL-encoded. May be specified multiple times.',
parse: (val: string, previous: Array<string> = []): Array<string> =>
previous.concat([val]),
},
],
};
Expand Down
30 changes: 30 additions & 0 deletions packages/community-cli-plugin/src/utils/parseKeyValueParamArray.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
/**
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @flow strict-local
* @format
* @oncall react_native
*/

import querystring from 'querystring';

export default function parseKeyValueParamArray(
keyValueArray: $ReadOnlyArray<string>,
): Record<string, string> {
const result = {};

for (const item of keyValueArray) {
if (item.indexOf('=') === -1) {
throw new Error('Expected parameter to include "=" but found: ' + item);
}
if (item.indexOf('&') !== -1) {
throw new Error('Parameter cannot include "&" but found: ' + item);
}
Object.assign(result, querystring.parse(item));
}

return result;
}
5 changes: 5 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -8073,6 +8073,11 @@ query-string@^6.12.1:
split-on-first "^1.0.0"
strict-uri-encode "^2.0.0"

querystring@^0.2.1:
version "0.2.1"
resolved "https://registry.yarnpkg.com/querystring/-/querystring-0.2.1.tgz#40d77615bb09d16902a85c3e38aa8b5ed761c2dd"
integrity sha512-wkvS7mL/JMugcup3/rMitHmd9ecIGd2lhFhK9N3UUQ450h66d1r3Y9nvXzQAW1Lq+wyx61k/1pfKS5KuKiyEbg==

queue-microtask@^1.2.2:
version "1.2.3"
resolved "https://registry.yarnpkg.com/queue-microtask/-/queue-microtask-1.2.3.tgz#4929228bbc724dfac43e0efb058caf7b6cfb6243"
Expand Down