This repository has been archived by the owner on May 22, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 35
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: restructure dependency traversal files (#708)
* refactor: remove getSrcFilesAndExternalModules * refactor: move getNewCache to util file * refactor: change signature of getDependencyNamesAndPathsForDependencies * refactor: remove intermediate exports * refactor: move getDependencyNamesAndPathsForDependencies * refactor: rename functions * refactor: remove unnecessary export * refactor: move getPluginsModulesPath to util file * refactor: rename function
- Loading branch information
1 parent
2139bea
commit 13f7579
Showing
10 changed files
with
93 additions
and
125 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
const { getPackageJson } = require('../../utils/package_json') | ||
const { getNewCache } = require('../../utils/traversal_cache') | ||
const { getDependencyPathsForDependency } = require('../zisi/traverse') | ||
|
||
const getSrcFilesForDependencies = async function ({ | ||
dependencies: dependencyNames, | ||
basedir, | ||
state = getNewCache(), | ||
pluginsModulesPath, | ||
}) { | ||
if (dependencyNames.length === 0) { | ||
return [] | ||
} | ||
|
||
const packageJson = await getPackageJson(basedir) | ||
const dependencies = await Promise.all( | ||
dependencyNames.map((dependencyName) => | ||
getSrcFilesForDependency({ | ||
dependency: dependencyName, | ||
basedir, | ||
state, | ||
packageJson, | ||
pluginsModulesPath, | ||
}), | ||
), | ||
) | ||
const paths = new Set(dependencies.flat()) | ||
|
||
return [...paths] | ||
} | ||
|
||
const getSrcFilesForDependency = async function ({ | ||
dependency, | ||
basedir, | ||
state = getNewCache(), | ||
packageJson, | ||
pluginsModulesPath, | ||
}) { | ||
try { | ||
const paths = await getDependencyPathsForDependency({ dependency, basedir, state, packageJson, pluginsModulesPath }) | ||
|
||
return paths | ||
} catch (error) { | ||
if (error.code === 'MODULE_NOT_FOUND') { | ||
return [] | ||
} | ||
|
||
throw error | ||
} | ||
} | ||
|
||
module.exports = { getSrcFilesForDependencies } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
const findUp = require('find-up') | ||
|
||
const AUTO_PLUGINS_DIR = '.netlify/plugins/' | ||
|
||
const getPluginsModulesPath = (srcDir) => findUp(`${AUTO_PLUGINS_DIR}node_modules`, { cwd: srcDir, type: 'directory' }) | ||
|
||
module.exports = { getPluginsModulesPath } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
// Local cache used for optimizing the traversal of module dependencies. | ||
const getNewCache = () => ({ localFiles: new Set(), moduleNames: new Set(), modulePaths: new Set() }) | ||
|
||
module.exports = { getNewCache } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
13f7579
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
⏱ Benchmark results
largeDepsEsbuild: 13.1s
largeDepsZisi: 1m 11.5s