Skip to content

Commit

Permalink
Support CRA 3
Browse files Browse the repository at this point in the history
  • Loading branch information
Elvin Dzhavadov committed Jan 30, 2020
1 parent 7bbacf4 commit f16f0ee
Show file tree
Hide file tree
Showing 11 changed files with 10,701 additions and 8,884 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@

# Run create-react-app 2 with workspaces
# Run create-react-app 3 with workspaces

[![npm version](https://img.shields.io/npm/v/cra-workspaces.svg)](https://www.npmjs.com/package/cra-workspaces)
[![npm monthly downloads](https://img.shields.io/npm/dm/cra-workspaces.svg)](https://www.npmjs.com/package/cra-workspaces)
Expand All @@ -10,7 +10,7 @@

> By doing this you're breaking the ["guarantees"](https://github.com/facebookincubator/create-react-app/issues/99#issuecomment-234657710) that CRA provides. That is to say you now "own" the configs. **No support** will be provided. Proceed with caution.
The goal of this package is to make a monorepo using [yarn workspaces](https://yarnpkg.com/lang/en/docs/workspaces/) to share common code across a Create React App 2 (CRA).
The goal of this package is to make a monorepo using [yarn workspaces](https://yarnpkg.com/lang/en/docs/workspaces/) to share common code across a Create React App 2+ (CRA).
It runs create-react-app with yarn workspaces without config files or using 'eject'

# Getting started
Expand Down
72 changes: 35 additions & 37 deletions bin/cra-workspaces.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
#!/usr/bin/env node
// Makes the script crash on unhandled rejections instead of silently
// ignoring them. In the future, promise rejections that are not handled will
// terminate the Node.js process with a non-zero exit code.
'use strict';

// Makes the script crash on unhandled rejections instead of silently
// ignoring them. In the future, promise rejections that are not handled will
// terminate the Node.js process with a non-zero exit code.
Expand All @@ -10,47 +15,40 @@ const spawn = require('cross-spawn');
const args = process.argv.slice(2);

const scriptIndex = args.findIndex(
x => x === 'build' || x === 'eject' || x === 'start' || x === 'test'
x => x === 'build' || x === 'eject' || x === 'start' || x === 'test'
);
const script = scriptIndex === -1 ? args[0] : args[scriptIndex];
const nodeArgs = scriptIndex > 0 ? args.slice(0, scriptIndex) : [];

switch (script) {
case 'build':
case 'eject':
case 'start':
case 'test': {
const result = spawn.sync(
'node',
nodeArgs
.concat(require.resolve('../scripts/' + script))
.concat(args.slice(scriptIndex + 1)),
{ stdio: 'inherit' }
);
if (result.signal) {
if (result.signal === 'SIGKILL') {
console.log(
'The build failed because the process exited too early. ' +
'This probably means the system ran out of memory or someone called ' +
'`kill -9` on the process.'
);
} else if (result.signal === 'SIGTERM') {
console.log(
'The build failed because the process exited too early. ' +
'Someone might have called `kill` or `killall`, or the system could ' +
'be shutting down.'
);
}
process.exit(1);
if (['build', 'start'].includes(script)) {
const result = spawn.sync(
'node',
nodeArgs
.concat(require.resolve('../scripts/' + script))
.concat(args.slice(scriptIndex + 1)),
{ stdio: 'inherit' }
);
if (result.signal) {
if (result.signal === 'SIGKILL') {
console.log(
'The build failed because the process exited too early. ' +
'This probably means the system ran out of memory or someone called ' +
'`kill -9` on the process.'
);
} else if (result.signal === 'SIGTERM') {
console.log(
'The build failed because the process exited too early. ' +
'Someone might have called `kill` or `killall`, or the system could ' +
'be shutting down.'
);
}
process.exit(result.status);
break;
process.exit(1);
}
default:
console.log('Unknown script "' + script + '".');
console.log('Perhaps you need to update react-scripts?');
console.log(
'See: https://github.com/facebook/create-react-app/blob/master/packages/react-scripts/template/README.md#updating-to-new-releases'
);
break;
process.exit(result.status);
} else {
console.log('Unknown script "' + script + '".');
console.log(
'See: https://github.com/elv1n/cra-workspaces'
);
}

6 changes: 3 additions & 3 deletions example/web/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@
"main": "index.js",
"license": "MIT",
"dependencies": {
"cra-workspaces": "^1.0.0",
"cra-workspaces": "2.0.0",
"react": "^16.6.1",
"react-scripts": "^2.1.1",
"react-dom": "^16.6.1"
"react-dom": "^16.6.1",
"react-scripts": "3.3.0"
},
"scripts": {
"start": "cra-workspaces start",
Expand Down
Loading

0 comments on commit f16f0ee

Please sign in to comment.