Skip to content

Commit d1029b9

Browse files
committed
feat: support nested packages
1 parent bb4ea0b commit d1029b9

File tree

2 files changed

+20
-10
lines changed

2 files changed

+20
-10
lines changed

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "pri",
3-
"version": "4.0.5",
3+
"version": "4.0.6",
44
"types": "src/node/index.ts",
55
"main": "built/node/index.js",
66
"scripts": {

src/utils/global-state.ts

+19-9
Original file line numberDiff line numberDiff line change
@@ -72,33 +72,41 @@ function getPriConfig(rootPath: string) {
7272
return fs.readJsonSync(configFilePath, { throws: false }) || {};
7373
}
7474

75-
async function initPackages(cliCurrentPath: string, preSelectPackage: string) {
76-
const currentPackagesPath = path.join(cliCurrentPath, PACKAGES_NAME);
75+
function collectPackages(packageRootPath: string) {
76+
const currentPackagesPath = path.join(packageRootPath, PACKAGES_NAME);
7777

7878
if (fs.existsSync(currentPackagesPath)) {
79-
globalState.packages = fs
80-
.readdirSync(currentPackagesPath)
79+
fs.readdirSync(currentPackagesPath)
8180
.filter(folderName => {
8281
if (folderName === '.DS_Store') {
8382
return false;
8483
}
8584

8685
return true;
8786
})
88-
.map(folderName => {
89-
const packagePath = path.join(cliCurrentPath, PACKAGES_NAME, folderName);
87+
.forEach(folderName => {
88+
const packagePath = path.join(packageRootPath, PACKAGES_NAME, folderName);
9089
const packageJson: PackageJson = fs.readJSONSync(path.join(packagePath, 'package.json'), { throws: false });
9190

9291
const config = fs.readJsonSync(path.join(packagePath, CONFIG_FILE), { throws: false }) || {};
9392

94-
return {
93+
const eachPackage = {
9594
name: folderName,
9695
rootPath: packagePath,
9796
packageJson,
9897
config,
9998
};
99+
100+
globalState.packages.push(eachPackage);
101+
102+
// find nested packages
103+
collectPackages(eachPackage.rootPath);
100104
});
101105
}
106+
}
107+
108+
async function initPackages(projectRootPath: string, preSelectPackage: string) {
109+
collectPackages(projectRootPath);
102110

103111
if (globalState.packages.length > 0) {
104112
if (!preSelectPackage) {
@@ -137,10 +145,12 @@ async function initPackages(cliCurrentPath: string, preSelectPackage: string) {
137145

138146
switch (globalState.selectedSourceType) {
139147
case 'root':
140-
globalState.sourceRoot = cliCurrentPath;
148+
globalState.sourceRoot = projectRootPath;
141149
break;
142150
default:
143-
globalState.sourceRoot = path.join(cliCurrentPath, PACKAGES_NAME, globalState.selectedSourceType);
151+
globalState.sourceRoot = globalState.packages.find(
152+
eachPackage => eachPackage.name === globalState.selectedSourceType,
153+
).rootPath;
144154
}
145155
}
146156

0 commit comments

Comments
 (0)