-
-
Notifications
You must be signed in to change notification settings - Fork 624
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore(build): validate if exporting is correct in
package.json
and …
…`jsr.json` (#3638) * feat(build): for both exports to be the same * some fix * fix exclude of coverage * update * stylish error message and add comment * revert auto lint * chore: format
- Loading branch information
Showing
6 changed files
with
91 additions
and
5 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,31 @@ | ||
/// <reference types="vitest/globals" /> | ||
|
||
import { validateExports } from './validate-exports' | ||
|
||
const mockExports1 = { | ||
'./a': './a.ts', | ||
'./b': './b.ts', | ||
'./c/a': './c.ts', | ||
'./d/*': './d/*.ts', | ||
} | ||
|
||
const mockExports2 = { | ||
'./a': './a.ts', | ||
'./b': './b.ts', | ||
'./c/a': './c.ts', | ||
'./d/a': './d/a.ts', | ||
} | ||
|
||
const mockExports3 = { | ||
'./a': './a.ts', | ||
'./c/a': './c.ts', | ||
'./d/*': './d/*.ts', | ||
} | ||
|
||
describe('validateExports', () => { | ||
it('Works', async () => { | ||
expect(() => validateExports(mockExports1, mockExports1, 'package.json')).not.toThrowError() | ||
expect(() => validateExports(mockExports1, mockExports2, 'jsr.json')).not.toThrowError() | ||
expect(() => validateExports(mockExports1, mockExports3, 'package.json')).toThrowError() | ||
}) | ||
}) |
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,37 @@ | ||
export const validateExports = ( | ||
source: Record<string, unknown>, | ||
target: Record<string, unknown>, | ||
fileName: string | ||
) => { | ||
const isEntryInTarget = (entry: string): boolean => { | ||
if (entry in target) { | ||
return true | ||
} | ||
|
||
// e.g., "./utils/*" -> "./utils" | ||
const wildcardPrefix = entry.replace(/\/\*$/, '') | ||
if (entry.endsWith('/*')) { | ||
return Object.keys(target).some( | ||
(targetEntry) => | ||
targetEntry.startsWith(wildcardPrefix + '/') && targetEntry !== wildcardPrefix | ||
) | ||
} | ||
|
||
const separatedEntry = entry.split('/') | ||
while (separatedEntry.length > 0) { | ||
const pattern = `${separatedEntry.join('/')}/*` | ||
if (pattern in target) { | ||
return true | ||
} | ||
separatedEntry.pop() | ||
} | ||
|
||
return false | ||
} | ||
|
||
Object.keys(source).forEach((sourceEntry) => { | ||
if (!isEntryInTarget(sourceEntry)) { | ||
throw new Error(`Missing "${sourceEntry}" in '${fileName}'`) | ||
} | ||
}) | ||
} |
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