Strip shebang when present in JS files
Summary:Fixes #7034 Closes https://github.com/facebook/react-native/pull/7073 Differential Revision: D3199816 fb-gh-sync-id: 2099dd1f81b030933794be6a592a697cec3627d0 fbshipit-source-id: 2099dd1f81b030933794be6a592a697cec3627d0
This commit is contained in:
parent
7e515f8d4a
commit
91a52421d4
|
@ -69,6 +69,19 @@ describe('code transformation worker:', () => {
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('removes shebang when present', done => {
|
||||||
|
const shebang = '#!/usr/bin/env node';
|
||||||
|
const result = {
|
||||||
|
code: `${shebang} \n arbitrary(code)`,
|
||||||
|
};
|
||||||
|
transform.mockImplementation((_, callback) => callback(null, result));
|
||||||
|
transformCode(transform, 'arbitrary/file.js', 'b', {}, (_, data) => {
|
||||||
|
expect(data.code).not.toContain(shebang);
|
||||||
|
expect(data.code.split('\n').length).toEqual(result.code.split('\n').length);
|
||||||
|
done();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
it('calls back with any error yielded by the transform', done => {
|
it('calls back with any error yielded by the transform', done => {
|
||||||
const error = Error('arbitrary error');
|
const error = Error('arbitrary error');
|
||||||
transform.mockImplementation((_, callback) => callback(error));
|
transform.mockImplementation((_, callback) => callback(error));
|
||||||
|
|
|
@ -43,6 +43,9 @@ function transformCode(transform, filename, sourceCode, options, callback) {
|
||||||
|
|
||||||
if (isJson) {
|
if (isJson) {
|
||||||
code = code.replace(/^\w+\.exports=/, '');
|
code = code.replace(/^\w+\.exports=/, '');
|
||||||
|
} else {
|
||||||
|
// Remove shebang
|
||||||
|
code = code.replace(/^#!.*/, '');
|
||||||
}
|
}
|
||||||
|
|
||||||
const result = isJson || options.extern
|
const result = isJson || options.extern
|
||||||
|
|
Loading…
Reference in New Issue