Skip to content
Closed
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
32 changes: 31 additions & 1 deletion packages/react-scripts/bin/react-scripts.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,12 @@ switch (script) {
case 'eject':
case 'start':
case 'test': {
const nodeOptions = getNodeOptionsIfPresent(script);
const result = spawn.sync(
'node',
[require.resolve('../scripts/' + script)].concat(args),
nodeOptions
.concat([require.resolve('../scripts/' + script)])
.concat(args),
{ stdio: 'inherit' }
);
if (result.signal) {
Expand Down Expand Up @@ -51,3 +54,30 @@ switch (script) {
);
break;
}

function getNodeOptionsIfPresent(script) {
const nameOne = 'NODE_COMMAND_LINE';
const nameTwo = `${nameOne}_${script.toUpperCase()}`;
const { readFileSync } = require('fs');
const { parse } = require('dotenv');
const path = '.env';
const encoding = 'utf8';
const getArgList = val => {
return val.split('--').filter(v => v !== '').map(v => `--${v}`);
};
let nodeOptions = [];
try {
const parsedObj = parse(readFileSync(path, { encoding: encoding }));
nodeOptions = Object.entries(parsedObj).reduce((lst, [key, val]) => {
if (key === nameTwo) {
lst = getArgList(val);
} else if (key === nameOne && lst.length === 0) {
lst = getArgList(val);
}
return lst;
}, []);
} catch (e) {
// File does not exit or could not be read
}
return nodeOptions;
}