-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
20 changed files
with
662 additions
and
691 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,6 +4,7 @@ | |
**/config/** | ||
**/build/** | ||
**/npm/** | ||
!scripts/npm/** | ||
**/*.js.flow | ||
**/*.d.ts | ||
**/playwright*/** | ||
|
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
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,90 @@ | ||
/** | ||
* Copyright (c) Meta Platforms, Inc. and affiliates. | ||
* | ||
* This source code is licensed under the MIT license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
* | ||
*/ | ||
'use strict'; | ||
|
||
const fs = require('fs-extra'); | ||
const glob = require('glob'); | ||
const packagesManager = require('../../shared/packagesManager'); | ||
|
||
const monorepoPackageJson = require('../../shared/readMonorepoPackageJson')(); | ||
|
||
const publicNpmNames = new Set( | ||
packagesManager.getPublicPackages().map((pkg) => pkg.getNpmName()), | ||
); | ||
|
||
describe('public package.json audits (`npm run update-version` to fix most issues)', () => { | ||
packagesManager.getPublicPackages().forEach((pkg) => { | ||
const npmName = pkg.getNpmName(); | ||
const packageJson = pkg.packageJson; | ||
describe(npmName, () => { | ||
const sourceFiles = fs | ||
.readdirSync(pkg.resolve('src')) | ||
.filter((str) => /\.tsx?/.test(str)) | ||
.map((str) => str.replace(/\.tsx?$/, '', str)) | ||
.sort(); | ||
const exportedModules = pkg.getExportedNpmModuleNames().sort(); | ||
const {dependencies = {}, peerDependencies = {}} = packageJson; | ||
if (packageJson.main) { | ||
it('should only export the main module with main set', () => { | ||
expect(exportedModules).toEqual([npmName]); | ||
}); | ||
} | ||
it('has *.flow types', () => { | ||
expect(glob.sync(pkg.resolve('flow', '*.flow'))).not.toEqual([]); | ||
}); | ||
it('uses the expected directory/npm naming convention', () => { | ||
expect(npmName.replace(/^@/, '').replace('/', '-')).toBe( | ||
pkg.getDirectoryName(), | ||
); | ||
}); | ||
it('matches monorepo version', () => { | ||
expect(packageJson.version).toBe(monorepoPackageJson.version); | ||
}); | ||
it('must not have a direct dependency on react or react-dom', () => { | ||
expect(dependencies).not.toContain('react'); | ||
expect(dependencies).not.toContain('react-dom'); | ||
}); | ||
it('must not have monorepo peerDependencies', () => { | ||
expect( | ||
Object.keys(peerDependencies).filter((dep) => | ||
publicNpmNames.has(dep), | ||
), | ||
).toEqual([]); | ||
}); | ||
it('monorepo dependencies must use the exact monorepo version', () => { | ||
Object.entries(dependencies).forEach(([dep, version]) => { | ||
if (publicNpmNames.has(dep)) { | ||
expect([dep, version]).toEqual([dep, monorepoPackageJson.version]); | ||
} | ||
}); | ||
}); | ||
it('must export at least one module', () => { | ||
expect(exportedModules.length).toBeGreaterThanOrEqual(1); | ||
}); | ||
test.each(exportedModules)( | ||
`should have a source file for exported module %s`, | ||
(exportedModule) => { | ||
expect(sourceFiles).toContain( | ||
exportedModule.slice(npmName.length + 1) || 'index', | ||
); | ||
}, | ||
); | ||
if (!sourceFiles.includes('index')) { | ||
it('must not export a top-level module without an index.tsx?', () => { | ||
expect(exportedModules).not.toContain(npmName); | ||
}); | ||
test.each(sourceFiles)( | ||
`%s.tsx? must have an exported module`, | ||
(sourceFile) => { | ||
expect(exportedModules).toContain(`${npmName}/${sourceFile}`); | ||
}, | ||
); | ||
} | ||
}); | ||
}); | ||
}); |
Oops, something went wrong.