-
Notifications
You must be signed in to change notification settings - Fork 625
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Support custom transformer/resolver options in
metro build
and runB…
…uild API Summary: Changelog: * **[Feature]** Support custom transformer/resolver options in `metro build` and `runBuild` API 1. Adds the `--transform-option` and `--resolver-option` options to the `metro build` command. 2. Adds the `customTransformOptions` and `customResolverOptions` properties to the options object accepted by `Metro.runBuild`. Previously, Metro only supported passing these options via the bundle URL and they had no counterpart in the API or CLI. Reviewed By: huntie Differential Revision: D43775385 fbshipit-source-id: dc87b4a170883b6efe694a72b218953b85798f92
- Loading branch information
1 parent
5c5830b
commit fcfecc9
Showing
6 changed files
with
132 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
66 changes: 66 additions & 0 deletions
66
packages/metro/src/cli/__tests__/parseKeyValueParamArray-test.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
/** | ||
* 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 parseKeyValueParamArray from '../parseKeyValueParamArray'; | ||
|
||
test('empty', () => { | ||
expect(parseKeyValueParamArray([])).toEqual({}); | ||
}); | ||
|
||
test('result has nullish prototype', () => { | ||
// eslint-disable-next-line no-proto | ||
expect(parseKeyValueParamArray([]).__proto__).toBe(undefined); | ||
}); | ||
|
||
test('single prop', () => { | ||
expect(parseKeyValueParamArray(['foo=bar'])).toEqual({ | ||
foo: 'bar', | ||
}); | ||
}); | ||
|
||
test('repeated prop, last one wins', () => { | ||
expect(parseKeyValueParamArray(['foo=bar', 'foo=baz'])).toEqual({ | ||
foo: 'baz', | ||
}); | ||
}); | ||
|
||
test('multiple props', () => { | ||
expect(parseKeyValueParamArray(['foo=bar', 'baz=quux'])).toEqual({ | ||
foo: 'bar', | ||
baz: 'quux', | ||
}); | ||
}); | ||
|
||
test('"&" is not allowed', () => { | ||
expect(() => | ||
parseKeyValueParamArray(['foo=bar&baz=quux']), | ||
).toThrowErrorMatchingInlineSnapshot( | ||
`"Parameter cannot include \\"&\\" but found: foo=bar&baz=quux"`, | ||
); | ||
}); | ||
|
||
test('"=" is required', () => { | ||
expect(() => | ||
parseKeyValueParamArray(['foo', 'bar']), | ||
).toThrowErrorMatchingInlineSnapshot( | ||
`"Expected parameter to include \\"=\\" but found: foo"`, | ||
); | ||
}); | ||
|
||
test('multiple "=" characters', () => { | ||
expect(parseKeyValueParamArray(['a=b=c'])).toEqual({a: 'b=c'}); | ||
}); | ||
|
||
test('performs URL decoding', () => { | ||
expect(parseKeyValueParamArray(['a=b%20c'])).toEqual({a: 'b c'}); | ||
expect(parseKeyValueParamArray(['a=b%26c'])).toEqual({a: 'b&c'}); | ||
expect(parseKeyValueParamArray(['a%3Db=c'])).toEqual({'a=b': 'c'}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
/** | ||
* 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 coerceKeyValueArray( | ||
keyValueArray: $ReadOnlyArray<string>, | ||
): { | ||
[key: string]: string, | ||
__proto__: null, | ||
} { | ||
const result: {[key: string]: string, __proto__: null} = Object.create(null); | ||
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; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters