Skip to content

Commit 0f6a365

Browse files
committed
add loader for component app prop check
When a component imported a package with pinned version, the "Check component app prop" PR check failed because Node.js was unable to resolve the package version correctly. This commit adds a custom loader that strips the version from the imported package, allowing the check to pass. For example, if the component imports `[email protected]`, the loader will transform the import to `got`.
1 parent 7a9e1aa commit 0f6a365

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed

.github/workflows/pull-request-checks.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,6 @@ jobs:
101101
- name: Check component keys
102102
run: node scripts/findBadKeys.js ${{ steps.changed_files.outputs.added_modified }} ${{ steps.changed_files.outputs.renamed }}
103103
- name: Check component app prop
104-
run: node scripts/checkComponentAppProp.js ${{ steps.changed_files.outputs.added_modified }} ${{ steps.changed_files.outputs.renamed }}
104+
run: node --experimental-loader ./scripts/version-strip-loader.mjs scripts/checkComponentAppProp.js ${{ steps.changed_files.outputs.added_modified }} ${{ steps.changed_files.outputs.renamed }}
105105
- name: Check for duplicate component keys
106106
run: node scripts/findDuplicateKeys.js

scripts/version-strip-loader.mjs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
export async function resolve(specifier, context, nextResolve) {
2+
// Strip version from imports like "[email protected]" -> "got"
3+
const versionedImportMatch = specifier.match(/^(.+)@[\d\.\-\w]+$/);
4+
if (versionedImportMatch) {
5+
specifier = versionedImportMatch[1];
6+
}
7+
8+
return nextResolve(specifier, context);
9+
}

0 commit comments

Comments
 (0)