-
Notifications
You must be signed in to change notification settings - Fork 4.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #4569 from JedWatson/gwyneplaine/replace-ert
remove ert from docs and replace with magical-types
- Loading branch information
Showing
19 changed files
with
830 additions
and
472 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 |
---|---|---|
|
@@ -41,3 +41,5 @@ package-lock.json | |
|
||
# Notes | ||
.NOTES.md | ||
|
||
magical-types |
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 |
---|---|---|
@@ -1,10 +1 @@ | ||
// import { Component } from 'react'; | ||
// | ||
// import { AsyncProps } from 'react-select/src/Async'; | ||
// import { GroupBase, OptionBase } from 'react-select'; | ||
// | ||
// export default class Select< | ||
// Option extends OptionBase, | ||
// IsMulti extends boolean, | ||
// Group extends GroupBase<Option> | ||
// > extends Component<AsyncProps<Option, IsMulti, Group>> {} | ||
export { AsyncAdditionalProps } from 'react-select/src/useAsync'; |
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 |
---|---|---|
@@ -1,10 +1 @@ | ||
// import { Component } from 'react'; | ||
// | ||
// import { CreatableProps } from 'react-select/src/Creatable'; | ||
// import { GroupBase, OptionBase } from 'react-select'; | ||
// | ||
// export default class Select< | ||
// Option extends OptionBase, | ||
// IsMulti extends boolean, | ||
// Group extends GroupBase<Option> | ||
// > extends Component<CreatableProps<Option, IsMulti, Group>> {} | ||
export { CreatableAdditionalProps } from 'react-select/src/useCreatable'; |
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 |
---|---|---|
@@ -1,12 +1,10 @@ | ||
// import { Component } from 'react'; | ||
// | ||
// import { Props, defaultProps } from 'react-select/src/Select'; | ||
// import { GroupBase, OptionBase } from 'react-select'; | ||
// | ||
// export default class Select< | ||
// Option extends OptionBase, | ||
// IsMulti extends boolean, | ||
// Group extends GroupBase<Option> | ||
// > extends Component<Props<Option, IsMulti, Group>> { | ||
// defaultProps = defaultProps; | ||
// } | ||
import { Component } from 'react'; | ||
|
||
import { Props, defaultProps } from 'react-select/src/Select'; | ||
import { GroupBase, OptionBase } from 'react-select'; | ||
|
||
export default class Select extends Component< | ||
Props<OptionBase, boolean, GroupBase<OptionBase>> | ||
> { | ||
defaultProps = defaultProps; | ||
} |
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 |
---|---|---|
@@ -1,10 +1 @@ | ||
// import { Component } from 'react'; | ||
// | ||
// import { StateManagerProps } from 'react-select/src/stateManager'; | ||
// import { GroupBase, OptionBase } from 'react-select'; | ||
// | ||
// export default class StateManager< | ||
// Option extends OptionBase, | ||
// IsMulti extends boolean, | ||
// Group extends GroupBase<Option> | ||
// > extends Component<StateManagerProps<Option, IsMulti, Group>> {} | ||
export { StateManagerAdditionalProps } from 'react-select/src/useStateManager'; |
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,6 @@ | ||
{ | ||
"main": "dist/generate-magical-types.cjs.js", | ||
"preconstruct": { | ||
"source": "../src/generate" | ||
} | ||
} |
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,19 @@ | ||
{ | ||
"name": "@react-select/generate-magical-types", | ||
"main": "dist/generate-magical-types.cjs.js", | ||
"//": "these deps aren't real, they're just to appease preconstruct", | ||
"dependencies": { | ||
"@babel/runtime": "*", | ||
"@magical-types/convert-type": "*", | ||
"@magical-types/serialization": "*", | ||
"ts-morph": "*", | ||
"fs-extra": "*", | ||
"flatted": "*" | ||
}, | ||
"preconstruct": { | ||
"entrypoints": [ | ||
"generate", | ||
"serialize" | ||
] | ||
} | ||
} |
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,6 @@ | ||
{ | ||
"main": "dist/generate-magical-types.cjs.js", | ||
"preconstruct": { | ||
"source": "../src/serialize" | ||
} | ||
} |
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,117 @@ | ||
import path from 'path'; | ||
|
||
// @ts-ignore | ||
import fs from 'fs-extra'; | ||
import * as flatted from 'flatted'; | ||
import { Project } from 'ts-morph'; | ||
import { MagicalNode } from '@magical-types/types'; | ||
import { convertType, getPropTypesType } from '@magical-types/convert-type'; | ||
|
||
type MagicalNodesForPackage = Record< | ||
string, | ||
{ type: 'component' | 'other'; node: MagicalNode } | ||
>; | ||
|
||
export type MagicalNodes = Record<string, MagicalNodesForPackage>; | ||
|
||
if (process.env.NODE_ENV === 'test') { | ||
fs.outputFileSync( | ||
path.join(__dirname, '..', 'dist', 'magical-types.json'), | ||
flatted.stringify({}) | ||
); | ||
} else { | ||
const OTHERFILES: string[] = ['stateManager', 'Async', 'Creatable']; | ||
const getOtherProps = (obj: MagicalNodes) => { | ||
OTHERFILES.forEach((name: string) => { | ||
let pkgExports: MagicalNodesForPackage = {}; | ||
obj[`${name}`] = pkgExports; | ||
let sourceFile = project.getSourceFile( | ||
path.join(__dirname, '../../Proptypes', `${name}.ts`) | ||
); | ||
if (!sourceFile) { | ||
sourceFile = project.getSourceFile( | ||
path.join(__dirname, '../../Proptypes', `${name}.tsx`) | ||
); | ||
} | ||
if (!sourceFile) { | ||
throw new Error(`source file not found for ${name}`); | ||
} | ||
resolveTypes({ sourceFile, item: name, pkgExports }); | ||
}); | ||
}; | ||
|
||
const resolveTypes = ({ | ||
sourceFile, | ||
item, | ||
pkgExports, | ||
}: { | ||
sourceFile: any; | ||
item: string; | ||
pkgExports: MagicalNodesForPackage; | ||
}) => { | ||
let exportedDeclarations = sourceFile.getExportedDeclarations(); | ||
for (const [exportName, declaration] of exportedDeclarations) { | ||
if (declaration.length) { | ||
let type = declaration[0].getType().compilerType; | ||
let typeKind: 'component' | 'other' = 'other'; | ||
console.log(`about to convert ${exportName} from ${item}`); | ||
if (exportName[0].toUpperCase() === exportName[0]) { | ||
try { | ||
type = getPropTypesType(type); | ||
typeKind = 'component'; | ||
} catch (err) {} | ||
} | ||
pkgExports[exportName] = { | ||
node: convertType(type, []), | ||
type: typeKind, | ||
}; | ||
console.log('converted'); | ||
} | ||
} | ||
}; | ||
|
||
let project = new Project({ | ||
addFilesFromTsConfig: true, | ||
tsConfigFilePath: path.resolve(__dirname, '../../../tsconfig.json'), | ||
}); | ||
console.log('done'); | ||
let pkgDir = path.resolve(__dirname, '../../../packages'); | ||
let pkgs = fs | ||
.readdirSync(pkgDir, { | ||
withFileTypes: true, | ||
}) | ||
.filter( | ||
// @ts-ignore | ||
(x) => | ||
x.isDirectory() && | ||
fs.existsSync(path.join(pkgDir, path.join(x.name), 'package.json')) | ||
) | ||
// @ts-ignore | ||
.map((x) => x.name); | ||
|
||
let obj: MagicalNodes = {}; | ||
|
||
for (const item of pkgs) { | ||
let pkgExports: MagicalNodesForPackage = {}; | ||
obj[`${item}`] = pkgExports; | ||
let sourceFile = project.getSourceFile( | ||
path.join(pkgDir, item, 'src', 'index.tsx') | ||
); | ||
if (!sourceFile) { | ||
sourceFile = project.getSourceFile( | ||
path.join(pkgDir, item, 'src', 'index.ts') | ||
); | ||
} | ||
if (!sourceFile) { | ||
throw new Error(`source file not found for ${item}`); | ||
} | ||
resolveTypes({ sourceFile, item, pkgExports }); | ||
} | ||
|
||
getOtherProps(obj); | ||
|
||
fs.outputFileSync( | ||
path.join(__dirname, '..', 'dist', 'magical-types.json'), | ||
flatted.stringify(obj) | ||
); | ||
} |
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,93 @@ | ||
import path from 'path'; | ||
|
||
// @ts-ignore | ||
import fs from 'fs-extra'; | ||
import * as flatted from 'flatted'; | ||
import { MagicalNode } from '@magical-types/types'; | ||
import { | ||
chunkNodes, | ||
serializeNodes, | ||
} from '@magical-types/serialization/serialize'; | ||
|
||
import { MagicalNodeMetadata, MagicalNodes } from './types'; | ||
|
||
const allTypes: MagicalNodes = flatted.parse( | ||
fs.readFileSync( | ||
path.join(__dirname, '..', 'dist', 'magical-types.json'), | ||
'utf8' | ||
) | ||
); | ||
|
||
const magicalTypesDir = path.resolve(__dirname, '..', '..', 'magical-types'); | ||
|
||
fs.removeSync(magicalTypesDir); | ||
|
||
fs.ensureDirSync(magicalTypesDir); | ||
|
||
let rootNodes: MagicalNode[] = []; | ||
|
||
for (const pkgName in allTypes) { | ||
for (const exportName in allTypes[pkgName]) { | ||
rootNodes.push(allTypes[pkgName][exportName].node); | ||
} | ||
} | ||
|
||
console.log('serializing nodes'); | ||
const serializationResult = serializeNodes(rootNodes); | ||
console.log('done'); | ||
|
||
console.log('chunking nodes'); | ||
const chunkedNodes = chunkNodes(serializationResult); | ||
console.log('done'); | ||
|
||
let outputPaths = chunkedNodes.map((x, index) => | ||
path.join( | ||
magicalTypesDir, | ||
`magical-types-${index}-${Math.random().toString(36)}.json` | ||
) | ||
); | ||
|
||
let outputUrlSegments = outputPaths.map( | ||
(filepath) => `/magical-types/${path.basename(filepath)}` | ||
); | ||
let manifestOutputPath = path.resolve( | ||
magicalTypesDir, | ||
'magical-types-manifest.json' | ||
); | ||
|
||
const metadataWithIndexes: MagicalNodeMetadata = {}; | ||
|
||
for (const pkgName in allTypes) { | ||
metadataWithIndexes[pkgName] = {}; | ||
for (const exportName in allTypes[pkgName]) { | ||
if (serializationResult.nodesMeta.has(allTypes[pkgName][exportName].node)) { | ||
metadataWithIndexes[pkgName][exportName] = { | ||
type: allTypes[pkgName][exportName].type, | ||
index: serializationResult.nodesMeta.get( | ||
allTypes[pkgName][exportName].node | ||
)!.index, | ||
}; | ||
} | ||
} | ||
} | ||
|
||
(async () => { | ||
console.log('writing output'); | ||
await Promise.all([ | ||
fs.writeFile( | ||
manifestOutputPath, | ||
JSON.stringify({ | ||
paths: outputUrlSegments, | ||
types: metadataWithIndexes, | ||
}) | ||
), | ||
...outputPaths.map((filepath, index) => | ||
fs.writeFile(filepath, JSON.stringify(chunkedNodes[index])) | ||
), | ||
]); | ||
|
||
console.log('done'); | ||
})().catch((err) => { | ||
console.error(err); | ||
process.exit(1); | ||
}); |
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,18 @@ | ||
import { MagicalNode, MagicalNodeIndex } from '@magical-types/types'; | ||
|
||
export type MagicalNodeMetadata = Record< | ||
string, | ||
Record<string, MagicalNodeRecord> | ||
>; | ||
|
||
export type MagicalNodeRecord = { | ||
type: 'component' | 'other'; | ||
index: MagicalNodeIndex; | ||
}; | ||
|
||
export type MagicalNodesForPackage = Record< | ||
string, | ||
{ type: 'component' | 'other'; node: MagicalNode } | ||
>; | ||
|
||
export type MagicalNodes = Record<string, MagicalNodesForPackage>; |
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
Oops, something went wrong.