@berish/yarn-workspaces
Advanced tools
Comparing version 1.0.0 to 1.1.0
@@ -11,2 +11,7 @@ "use strict"; | ||
paths: [], | ||
pathsDependencies: [], | ||
pathsDevDependencies: [], | ||
workspacesPackages: [], | ||
workspacesPackagesDependencies: [], | ||
workspacesPackagesDevDependencies: [], | ||
packageEntry: 'main:src', | ||
@@ -40,7 +45,19 @@ development: true, | ||
const appDependencies = helpers_1.getDependenciesByPath(paths.appPackageJson); | ||
const applicableSrcPaths = workspace_1.searchInDependenciesTable(dependenciesTable, packageEntries, appDependencies); | ||
const searchResultDependenciesTable = workspace_1.searchInDependenciesTable(appDependencies, dependenciesTable, packageEntries); | ||
console.log(`Found ${packageEntries.length} path(s) with "${config.packageEntry}" entry.`); | ||
console.log(`Found ${applicableSrcPaths.length} path(s) as tree of dependencies`); | ||
if (applicableSrcPaths.length > 0) | ||
config.paths = applicableSrcPaths; | ||
console.log(`Found ${searchResultDependenciesTable.pathsDependencies.length} path(s) as tree of dependencies`); | ||
console.log(`Found ${searchResultDependenciesTable.pathsDevDependencies.length} path(s) as tree of devDependencies`); | ||
const { paths: allPaths, pathsDependencies, pathsDevDependencies, workspacesPackages, workspacesPackagesDependencies, workspacesPackagesDevDependencies, } = searchResultDependenciesTable; | ||
if (allPaths.length > 0) | ||
config.paths = allPaths; | ||
if (pathsDependencies.length > 0) | ||
config.paths = pathsDependencies; | ||
if (pathsDevDependencies.length > 0) | ||
config.paths = pathsDevDependencies; | ||
if (workspacesPackages.length > 0) | ||
config.paths = workspacesPackages; | ||
if (workspacesPackagesDependencies.length > 0) | ||
config.paths = workspacesPackagesDependencies; | ||
if (workspacesPackagesDevDependencies.length > 0) | ||
config.paths = workspacesPackagesDevDependencies; | ||
console.log('Exporting Workspaces config to Webpack.'); | ||
@@ -47,0 +64,0 @@ return config; |
@@ -1,2 +0,2 @@ | ||
import { DependenciesType, PackageJsonType } from '../types'; | ||
export declare const getDependencies: (packageJson: PackageJsonType) => DependenciesType; | ||
import { PackageJsonType, DependenciesAllType } from '../types'; | ||
export declare const getDependencies: (packageJson: PackageJsonType) => DependenciesAllType; |
@@ -6,13 +6,16 @@ "use strict"; | ||
exports.getDependencies = (packageJson) => { | ||
const allDependencies = { | ||
dependencies: {}, | ||
devDependencies: {}, | ||
}; | ||
if (!packageJson) | ||
return {}; | ||
return allDependencies; | ||
const deps = getByKeyChain_1.getByKeyChain(packageJson, ['dependencies']); | ||
const devDeps = getByKeyChain_1.getByKeyChain(packageJson, ['devDependencies']); | ||
let dependencies = {}; | ||
if (deps) | ||
dependencies = Object.assign(dependencies, deps); | ||
allDependencies.dependencies = deps; | ||
if (devDeps) | ||
dependencies = Object.assign(dependencies, devDeps); | ||
return dependencies; | ||
allDependencies.devDependencies = devDeps; | ||
return allDependencies; | ||
}; | ||
//# sourceMappingURL=getDependencies.js.map |
@@ -1,2 +0,1 @@ | ||
import { DependenciesType } from '../types'; | ||
export declare const getDependenciesByPath: (appPackageJson: string) => DependenciesType; | ||
export declare const getDependenciesByPath: (appPackageJson: string) => import("../types").DependenciesAllType; |
@@ -12,2 +12,6 @@ export declare type WorkspacesStringType = string[]; | ||
}; | ||
export declare type DependenciesAllType = { | ||
dependencies: DependenciesType; | ||
devDependencies: DependenciesType; | ||
}; | ||
export declare type PackageJsonType = { | ||
@@ -29,5 +33,14 @@ name: string; | ||
}; | ||
export declare type ConfigType = { | ||
export declare type SearchResultDependenciesTableMini = { | ||
pathsDependencies: string[]; | ||
pathsDevDependencies: string[]; | ||
workspacesPackagesDependencies: string[]; | ||
workspacesPackagesDevDependencies: string[]; | ||
}; | ||
export declare type SearchResultDependenciesTable = SearchResultDependenciesTableMini & { | ||
paths: string[]; | ||
workspacesPackages: string[]; | ||
}; | ||
export declare type ConfigType = SearchResultDependenciesTable & { | ||
root: string; | ||
paths: string[]; | ||
packageEntry: string; | ||
@@ -44,4 +57,4 @@ development: boolean; | ||
path: string; | ||
dependencies: DependenciesType; | ||
dependencies: DependenciesAllType; | ||
}; | ||
}; |
@@ -1,5 +0,5 @@ | ||
import { DependenciesTableType, DependenciesType } from '../types'; | ||
import { DependenciesTableType, DependenciesAllType, SearchResultDependenciesTable } from '../types'; | ||
/** | ||
* Получаем все вложенные зависимости | ||
*/ | ||
export declare const searchInDependenciesTable: (depsTable: DependenciesTableType, packageEntries: string[], appDependencies: DependenciesType) => string[]; | ||
export declare const searchInDependenciesTable: (appDependencies: DependenciesAllType, depsTable: DependenciesTableType, packageEntries: string[]) => SearchResultDependenciesTable; |
@@ -8,17 +8,58 @@ "use strict"; | ||
*/ | ||
exports.searchInDependenciesTable = (depsTable, packageEntries, appDependencies) => { | ||
exports.searchInDependenciesTable = (appDependencies, depsTable, packageEntries) => { | ||
const _searchInDependenciesTable = (appDependencies) => { | ||
return packageEntries.reduce((out, path) => { | ||
const packageJson = helpers_1.readFindUpPackageJson(path); | ||
if (appDependencies && Reflect.has(appDependencies, packageJson.name)) { | ||
out.push(path); | ||
const subDependencies = depsTable[packageJson.name].dependencies; | ||
const subPaths = _searchInDependenciesTable(subDependencies); | ||
out.push(...subPaths); | ||
const result = { | ||
pathsDependencies: [], | ||
pathsDevDependencies: [], | ||
workspacesPackagesDependencies: [], | ||
workspacesPackagesDevDependencies: [], | ||
}; | ||
for (const packageEntryDir of packageEntries) { | ||
const packageJson = helpers_1.readFindUpPackageJson(packageEntryDir); | ||
const packageName = packageJson.name; | ||
if (!appDependencies) | ||
continue; | ||
const { dependencies, devDependencies } = appDependencies; | ||
const hasPackageNameInDependencies = dependencies && Reflect.has(dependencies, packageName); | ||
const hasPackageNameInDevDependencies = devDependencies && Reflect.has(devDependencies, packageName); | ||
if (hasPackageNameInDependencies) { | ||
result.pathsDependencies.push(packageEntryDir); | ||
result.workspacesPackagesDependencies.push(packageName); | ||
const packageAllDependencies = depsTable[packageJson.name].dependencies; | ||
const { pathsDependencies: subPathsDependencies, pathsDevDependencies: subPathsDevDependencies, workspacesPackagesDependencies: subWorkspacesPackagesDependencies, workspacesPackagesDevDependencies: subWorkspacesPackagesDevDependencies, } = _searchInDependenciesTable(packageAllDependencies); | ||
result.pathsDependencies.push(...subPathsDependencies); | ||
result.pathsDevDependencies.push(...subPathsDevDependencies); | ||
result.workspacesPackagesDependencies.push(...subWorkspacesPackagesDependencies); | ||
result.workspacesPackagesDevDependencies.push(...subWorkspacesPackagesDevDependencies); | ||
} | ||
return out; | ||
}, []); | ||
if (hasPackageNameInDevDependencies) { | ||
result.pathsDevDependencies.push(packageEntryDir); | ||
result.workspacesPackagesDevDependencies.push(packageName); | ||
const packageAllDependencies = depsTable[packageJson.name].dependencies; | ||
const { pathsDependencies: subPathsDependencies, pathsDevDependencies: subPathsDevDependencies, workspacesPackagesDependencies: subWorkspacesPackagesDependencies, workspacesPackagesDevDependencies: subWorkspacesPackagesDevDependencies, } = _searchInDependenciesTable(packageAllDependencies); | ||
result.pathsDevDependencies.push(...subPathsDependencies, ...subPathsDevDependencies); | ||
result.workspacesPackagesDevDependencies.push(...subWorkspacesPackagesDependencies, ...subWorkspacesPackagesDevDependencies); | ||
} | ||
} | ||
return result; | ||
}; | ||
return [...new Set(_searchInDependenciesTable(appDependencies))]; | ||
const { pathsDependencies, pathsDevDependencies, workspacesPackagesDependencies, workspacesPackagesDevDependencies, } = _searchInDependenciesTable(appDependencies); | ||
const pathsDependenciesSet = new Set(pathsDependencies); | ||
const pathsDevDependenciesSet = new Set(pathsDevDependencies); | ||
const workspacesPackagesDependenciesSet = new Set(workspacesPackagesDependencies); | ||
const workspacesPackagesDevDependenciesSet = new Set(workspacesPackagesDevDependencies); | ||
const pathsSet = new Set([...pathsDependenciesSet, ...pathsDevDependenciesSet]); | ||
const workspacesPackagesSet = new Set([ | ||
...workspacesPackagesDependenciesSet, | ||
...workspacesPackagesDevDependenciesSet, | ||
]); | ||
return { | ||
paths: [...pathsSet], | ||
pathsDependencies: [...pathsDependenciesSet], | ||
pathsDevDependencies: [...pathsDevDependenciesSet], | ||
workspacesPackages: [...workspacesPackagesSet], | ||
workspacesPackagesDependencies: [...workspacesPackagesDependenciesSet], | ||
workspacesPackagesDevDependencies: [...workspacesPackagesDevDependenciesSet], | ||
}; | ||
}; | ||
//# sourceMappingURL=searchInDependenciesTable.js.map |
{ | ||
"name": "@berish/yarn-workspaces", | ||
"version": "1.0.0", | ||
"version": "1.1.0", | ||
"description": "Get config by yarn workspaces", | ||
@@ -5,0 +5,0 @@ "main": "build/index.js", |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
2
33375
50
429