Back out "Use `execFileSync` over `exec` for cases with uncontrolled absolute paths" (#36780)
Summary: Pull Request resolved: https://github.com/facebook/react-native/pull/36780 Original commit changeset: 8e0ebb070768 Original Phabricator Diff: D44131032 Changelog: [Internal] all the circleCI template tests started failing after this commit, revert! Reviewed By: jacdebug, cortinico Differential Revision: D44635949 fbshipit-source-id: 429167acdbee3ebf6d81491ac65896c534c18fd0
This commit is contained in:
Родитель
12a102b926
Коммит
bece6500f7
|
@ -34,39 +34,32 @@ describe('generateCode', () => {
|
||||||
const node = 'usr/bin/node';
|
const node = 'usr/bin/node';
|
||||||
const pathToSchema = 'app/build/schema.json';
|
const pathToSchema = 'app/build/schema.json';
|
||||||
const rnRoot = path.join(__dirname, '../..');
|
const rnRoot = path.join(__dirname, '../..');
|
||||||
const libraryTypeArg = 'all';
|
const libraryType = 'all';
|
||||||
|
|
||||||
const tmpOutputDir = path.join(tmpDir, 'out');
|
const tmpOutDir = path.join(tmpDir, 'out');
|
||||||
|
|
||||||
// mock used functions
|
// mock used functions
|
||||||
jest.spyOn(fs, 'mkdirSync').mockImplementation();
|
jest.spyOn(fs, 'mkdirSync').mockImplementation();
|
||||||
jest.spyOn(child_process, 'execSync').mockImplementation();
|
jest.spyOn(child_process, 'execSync').mockImplementation();
|
||||||
jest.spyOn(child_process, 'execFileSync').mockImplementation();
|
|
||||||
|
|
||||||
underTest._generateCode(iosOutputDir, library, tmpDir, node, pathToSchema);
|
underTest._generateCode(iosOutputDir, library, tmpDir, node, pathToSchema);
|
||||||
|
|
||||||
expect(child_process.execFileSync).toHaveBeenCalledTimes(1);
|
const expectedCommand = `${node} ${path.join(
|
||||||
expect(child_process.execFileSync).toHaveBeenNthCalledWith(1, node, [
|
rnRoot,
|
||||||
`${path.join(rnRoot, 'generate-specs-cli.js')}`,
|
'generate-specs-cli.js',
|
||||||
'--platform',
|
)} --platform ios --schemaPath ${pathToSchema} --outputDir ${tmpOutDir} --libraryName ${
|
||||||
'ios',
|
library.config.name
|
||||||
'--schemaPath',
|
} --libraryType ${libraryType}`;
|
||||||
pathToSchema,
|
|
||||||
'--outputDir',
|
expect(child_process.execSync).toHaveBeenCalledTimes(2);
|
||||||
tmpOutputDir,
|
expect(child_process.execSync).toHaveBeenNthCalledWith(1, expectedCommand);
|
||||||
'--libraryName',
|
|
||||||
library.config.name,
|
|
||||||
'--libraryType',
|
|
||||||
libraryTypeArg,
|
|
||||||
]);
|
|
||||||
expect(child_process.execSync).toHaveBeenCalledTimes(1);
|
|
||||||
expect(child_process.execSync).toHaveBeenNthCalledWith(
|
expect(child_process.execSync).toHaveBeenNthCalledWith(
|
||||||
1,
|
2,
|
||||||
`cp -R ${tmpOutputDir}/* ${iosOutputDir}`,
|
`cp -R ${tmpOutDir}/* ${iosOutputDir}`,
|
||||||
);
|
);
|
||||||
|
|
||||||
expect(fs.mkdirSync).toHaveBeenCalledTimes(2);
|
expect(fs.mkdirSync).toHaveBeenCalledTimes(2);
|
||||||
expect(fs.mkdirSync).toHaveBeenNthCalledWith(1, tmpOutputDir, {
|
expect(fs.mkdirSync).toHaveBeenNthCalledWith(1, tmpOutDir, {
|
||||||
recursive: true,
|
recursive: true,
|
||||||
});
|
});
|
||||||
expect(fs.mkdirSync).toHaveBeenNthCalledWith(2, iosOutputDir, {
|
expect(fs.mkdirSync).toHaveBeenNthCalledWith(2, iosOutputDir, {
|
||||||
|
|
|
@ -16,7 +16,7 @@
|
||||||
* in a codegenConfigFilename file.
|
* in a codegenConfigFilename file.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
const {execSync, execFileSync} = require('child_process');
|
const {execSync} = require('child_process');
|
||||||
const fs = require('fs');
|
const fs = require('fs');
|
||||||
const os = require('os');
|
const os = require('os');
|
||||||
const path = require('path');
|
const path = require('path');
|
||||||
|
@ -45,8 +45,8 @@ function isReactNativeCoreLibrary(libraryName) {
|
||||||
return libraryName in CORE_LIBRARIES_WITH_OUTPUT_FOLDER;
|
return libraryName in CORE_LIBRARIES_WITH_OUTPUT_FOLDER;
|
||||||
}
|
}
|
||||||
|
|
||||||
function executeNodeScript(node, scriptArgs) {
|
function executeNodeScript(node, script) {
|
||||||
execFileSync(node, scriptArgs);
|
execSync(`${node} ${script}`);
|
||||||
}
|
}
|
||||||
|
|
||||||
function isAppRootValid(appRootDir) {
|
function isAppRootValid(appRootDir) {
|
||||||
|
@ -326,47 +326,42 @@ function generateSchema(tmpDir, library, node, codegenCliPath) {
|
||||||
|
|
||||||
console.log(`\n\n[Codegen] >>>>> Processing ${library.config.name}`);
|
console.log(`\n\n[Codegen] >>>>> Processing ${library.config.name}`);
|
||||||
// Generate one schema for the entire library...
|
// Generate one schema for the entire library...
|
||||||
executeNodeScript(node, [
|
executeNodeScript(
|
||||||
|
node,
|
||||||
`${path.join(
|
`${path.join(
|
||||||
codegenCliPath,
|
codegenCliPath,
|
||||||
'lib',
|
'lib',
|
||||||
'cli',
|
'cli',
|
||||||
'combine',
|
'combine',
|
||||||
'combine-js-to-schema-cli.js',
|
'combine-js-to-schema-cli.js',
|
||||||
)}`,
|
)} --platform ios ${pathToSchema} ${pathToJavaScriptSources}`,
|
||||||
'--platform',
|
);
|
||||||
'ios',
|
|
||||||
pathToSchema,
|
|
||||||
pathToJavaScriptSources,
|
|
||||||
]);
|
|
||||||
console.log(`[Codegen] Generated schema: ${pathToSchema}`);
|
console.log(`[Codegen] Generated schema: ${pathToSchema}`);
|
||||||
return pathToSchema;
|
return pathToSchema;
|
||||||
}
|
}
|
||||||
|
|
||||||
function generateCode(iosOutputDir, library, tmpDir, node, pathToSchema) {
|
function generateCode(iosOutputDir, library, tmpDir, node, pathToSchema) {
|
||||||
// ...then generate native code artifacts.
|
// ...then generate native code artifacts.
|
||||||
const libraryTypeArg = library.config.type ? `${library.config.type}` : '';
|
const libraryTypeArg = library.config.type
|
||||||
|
? `--libraryType ${library.config.type}`
|
||||||
|
: '';
|
||||||
|
|
||||||
const tmpOutputDir = path.join(tmpDir, 'out');
|
const tmpOutputDir = path.join(tmpDir, 'out');
|
||||||
fs.mkdirSync(tmpOutputDir, {recursive: true});
|
fs.mkdirSync(tmpOutputDir, {recursive: true});
|
||||||
|
|
||||||
executeNodeScript(node, [
|
executeNodeScript(
|
||||||
|
node,
|
||||||
`${path.join(
|
`${path.join(
|
||||||
REACT_NATIVE_PACKAGE_ROOT_FOLDER,
|
REACT_NATIVE_PACKAGE_ROOT_FOLDER,
|
||||||
'scripts',
|
'scripts',
|
||||||
'generate-specs-cli.js',
|
'generate-specs-cli.js',
|
||||||
)}`,
|
)} \
|
||||||
'--platform',
|
--platform ios \
|
||||||
'ios',
|
--schemaPath ${pathToSchema} \
|
||||||
'--schemaPath',
|
--outputDir ${tmpOutputDir} \
|
||||||
pathToSchema,
|
--libraryName ${library.config.name} \
|
||||||
'--outputDir',
|
${libraryTypeArg}`,
|
||||||
tmpOutputDir,
|
);
|
||||||
'--libraryName',
|
|
||||||
library.config.name,
|
|
||||||
'--libraryType',
|
|
||||||
libraryTypeArg,
|
|
||||||
]);
|
|
||||||
|
|
||||||
// Finally, copy artifacts to the final output directory.
|
// Finally, copy artifacts to the final output directory.
|
||||||
const outputDir =
|
const outputDir =
|
||||||
|
@ -431,19 +426,14 @@ function createComponentProvider(
|
||||||
|
|
||||||
// Generate FabricComponentProvider.
|
// Generate FabricComponentProvider.
|
||||||
// Only for iOS at this moment.
|
// Only for iOS at this moment.
|
||||||
executeNodeScript(node, [
|
executeNodeScript(
|
||||||
|
node,
|
||||||
`${path.join(
|
`${path.join(
|
||||||
REACT_NATIVE_PACKAGE_ROOT_FOLDER,
|
REACT_NATIVE_PACKAGE_ROOT_FOLDER,
|
||||||
'scripts',
|
'scripts',
|
||||||
'generate-provider-cli.js',
|
'generate-provider-cli.js',
|
||||||
)}`,
|
)} --platform ios --schemaListPath "${schemaListTmpPath}" --outputDir ${outputDir}`,
|
||||||
'--platform',
|
);
|
||||||
'ios',
|
|
||||||
'--schemaListPath',
|
|
||||||
schemaListTmpPath,
|
|
||||||
'--outputDir',
|
|
||||||
outputDir,
|
|
||||||
]);
|
|
||||||
console.log(`Generated provider in: ${outputDir}`);
|
console.log(`Generated provider in: ${outputDir}`);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -20,7 +20,7 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
const {cd, cp, echo, exec, exit, mv} = require('shelljs');
|
const {cd, cp, echo, exec, exit, mv} = require('shelljs');
|
||||||
const {execFileSync, spawn} = require('child_process');
|
const spawn = require('child_process').spawn;
|
||||||
const argv = require('yargs').argv;
|
const argv = require('yargs').argv;
|
||||||
const path = require('path');
|
const path = require('path');
|
||||||
|
|
||||||
|
@ -99,11 +99,9 @@ try {
|
||||||
);
|
);
|
||||||
|
|
||||||
describe('Scaffold a basic React Native app from template');
|
describe('Scaffold a basic React Native app from template');
|
||||||
execFileSync('rsync', [
|
exec(
|
||||||
'-a',
|
`rsync -a ${ROOT}/packages/react-native/template ${REACT_NATIVE_TEMP_DIR}`,
|
||||||
`${ROOT}/packages/react-native/template`,
|
);
|
||||||
REACT_NATIVE_TEMP_DIR,
|
|
||||||
]);
|
|
||||||
cd(REACT_NATIVE_APP_DIR);
|
cd(REACT_NATIVE_APP_DIR);
|
||||||
|
|
||||||
mv('_bundle', '.bundle');
|
mv('_bundle', '.bundle');
|
||||||
|
|
Загрузка…
Ссылка в новой задаче