Skip to content

Commit 13336d6

Browse files
Require packages to be opted in via glob, react#4570
1 parent a7066cd commit 13336d6

30 files changed

Lines changed: 276 additions & 11 deletions

File tree

packages/react-dev-utils/workspaceUtils.js

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,23 +30,29 @@ const findPkgs = (rootPath, globPatterns) => {
3030
};
3131

3232
const findMonorepo = appDir => {
33+
const appPkg = JSON.parse(
34+
fs.readFileSync(path.resolve(appDir, 'package.json'))
35+
);
3336
const monoPkgPath = findPkg.sync(path.resolve(appDir, '..'));
3437
const monoRootPath = monoPkgPath && path.dirname(monoPkgPath);
3538
const monoPkg = monoPkgPath && require(monoPkgPath);
3639
const patterns = monoPkg && monoPkg.workspaces;
3740
const isYarnWs = Boolean(patterns);
41+
const srcPatterns = appPkg && appPkg.sourceWorkspaces;
3842
const allPkgs = patterns && findPkgs(monoRootPath, patterns);
43+
const allSrcPkgs =
44+
srcPatterns && findPkgs(path.dirname(monoPkgPath), srcPatterns);
3945
const isIncluded = dir => allPkgs && allPkgs.indexOf(dir) !== -1;
4046
const isAppIncluded = isIncluded(appDir);
41-
const pkgs = allPkgs
42-
? allPkgs.filter(f => fs.realpathSync(f) !== appDir)
47+
const srcPkgPaths = allSrcPkgs
48+
? allSrcPkgs.filter(f => fs.realpathSync(f) !== appDir)
4349
: [];
4450

4551
return {
4652
isAppIncluded,
4753
isYarnWs,
48-
pkgs,
4954
rootPath: monoRootPath,
55+
srcPkgPaths,
5056
};
5157
};
5258

packages/react-scripts/config/paths.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ if (checkForMonorepo) {
128128
// the monorepo as if they are app source
129129
const mono = findMonorepo(appDirectory);
130130
if (mono.isAppIncluded) {
131-
Array.prototype.push.apply(module.exports.srcPaths, mono.pkgs);
131+
Array.prototype.push.apply(module.exports.srcPaths, mono.srcPkgPaths);
132132
module.exports.isMonorepo = true;
133133
module.exports.monorepoRoot = mono.rootPath;
134134
}

packages/react-scripts/fixtures/monorepos/packages/comp1/index.js renamed to packages/react-scripts/fixtures/monorepos/yarn-ws/packages/comp1/index.js

File renamed without changes.

packages/react-scripts/fixtures/monorepos/packages/comp1/index.test.js renamed to packages/react-scripts/fixtures/monorepos/yarn-ws/packages/comp1/index.test.js

File renamed without changes.

packages/react-scripts/fixtures/monorepos/packages/comp1/package.json renamed to packages/react-scripts/fixtures/monorepos/yarn-ws/packages/comp1/package.json

File renamed without changes.

packages/react-scripts/fixtures/monorepos/packages/comp2/index.js renamed to packages/react-scripts/fixtures/monorepos/yarn-ws/packages/comp2/index.js

File renamed without changes.

packages/react-scripts/fixtures/monorepos/packages/comp2/index.test.js renamed to packages/react-scripts/fixtures/monorepos/yarn-ws/packages/comp2/index.test.js

File renamed without changes.

packages/react-scripts/fixtures/monorepos/packages/comp2/package.json renamed to packages/react-scripts/fixtures/monorepos/yarn-ws/packages/comp2/package.json

File renamed without changes.

packages/react-scripts/fixtures/monorepos/packages/cra-app1/.gitignore renamed to packages/react-scripts/fixtures/monorepos/yarn-ws/packages/cra-app1/.gitignore

File renamed without changes.

packages/react-scripts/fixtures/monorepos/packages/cra-app1/package.json renamed to packages/react-scripts/fixtures/monorepos/yarn-ws/packages/cra-app1/package.json

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
"private": true,
55
"dependencies": {
66
"comp2": "^1.0.0",
7+
"nwbcomp": ">0.0.0",
78
"react": "^16.2.0",
89
"react-dom": "^16.2.0"
910
},
@@ -28,5 +29,8 @@
2829
"Firefox ESR",
2930
"not ie < 11"
3031
]
31-
}
32+
},
33+
"sourceWorkspaces": [
34+
"packages/comp*"
35+
]
3236
}

0 commit comments

Comments
 (0)