-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
bug/issue 1397 handle wildcard exports for sub export condition types (…
- Loading branch information
1 parent
a1423cd
commit d92c2a7
Showing
6 changed files
with
198 additions
and
150 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 |
---|---|---|
|
@@ -115,9 +115,11 @@ function patternRoot(pattern) { | |
* "./icons/*": "./icons/*" - https://unpkg.com/browse/@spectrum-web-components/[email protected]/package.json | ||
* "./components/*": "./dist/components/*.js" - https://unpkg.com/browse/@uswds/[email protected]/package.json | ||
* "./src/components/*": "./src/components/* /index.js - https://unpkg.com/browse/@uswds/[email protected]/package.json | ||
* "./*": { "default": "./dist/*.ts.js" } - https://unpkg.com/browse/[email protected]/package.json | ||
*/ | ||
async function walkExportPatterns(dependency, sub, subValue, resolvedRoot) { | ||
// find the "deepest" segment we can start from to avoid unnecessary file scanning / crawling | ||
const rootSubOffset = patternRoot(sub); | ||
const rootSubValueOffset = patternRoot(subValue); | ||
|
||
// ideally we can use fs.glob when it comes out of experimental | ||
|
@@ -135,12 +137,13 @@ async function walkExportPatterns(dependency, sub, subValue, resolvedRoot) { | |
walkDirectoryForExportPatterns(new URL(`./${file}/`, directoryUrl)); | ||
} else if (regexPattern.test(filePathUrl.href)) { | ||
const relativePath = filePathUrl.href.replace(resolvedRoot, ''); | ||
// naive way to offset a subValue pattern to the sub pattern | ||
// ex. "./js/*": "./packages/*/src/index.js", | ||
// https://unpkg.com/browse/@uswds/[email protected]/package.json | ||
const rootSubRelativePath = relativePath.replace(rootSubValueOffset, ''); | ||
// naive way to offset a subValue pattern to the sub pattern when dealing with wildcards | ||
// ex. "./js/*": "./packages/*/src/index.js" -> /js/<package-name>/src/index.js | ||
const rootSubRelativePath = sub.endsWith('*') | ||
? `./${relativePath}`.replace(subValue.split('*')[0], '').replace(subValue.split('*')[1], '') | ||
: relativePath.replace(rootSubValueOffset, ''); | ||
|
||
updateImportMap(`${dependency}/${rootSubRelativePath}`, relativePath, resolvedRoot); | ||
updateImportMap(`${dependency}${rootSubOffset}/${rootSubRelativePath}`, relativePath, resolvedRoot); | ||
} | ||
}); | ||
} | ||
|
@@ -182,7 +185,11 @@ async function walkPackageForExports(dependency, packageJson, resolvedRoot) { | |
for (const condition of SUPPORTED_EXPORT_CONDITIONS) { | ||
if (exports[sub][condition]) { | ||
matched = true; | ||
trackExportConditions(dependency, exports, sub, condition, resolvedRoot); | ||
if (sub.indexOf('*') >= 0) { | ||
await walkExportPatterns(dependency, sub, exports[sub][condition], resolvedRoot); | ||
} else { | ||
trackExportConditions(dependency, exports, sub, condition, resolvedRoot); | ||
} | ||
break; | ||
} | ||
} | ||
|
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
Oops, something went wrong.