forked from vercel/next.js
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Make traces in development reliable (vercel#28990)
Co-authored-by: Jiachi Liu <[email protected]>
- Loading branch information
1 parent
48b37ed
commit c1e5f5b
Showing
41 changed files
with
346 additions
and
116 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 was deleted.
Oops, something went wrong.
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 @@ | ||
components/* |
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,182 @@ | ||
#!/usr/bin/env node | ||
const path = require('path') | ||
const fs = require('fs') | ||
|
||
const getSequenceGenerator = require('random-seed') | ||
const generate = require('@babel/generator').default | ||
const t = require('@babel/types') | ||
|
||
const MIN_COMPONENT_NAME_LEN = 18 | ||
const MAX_COMPONENT_NAME_LEN = 24 | ||
const MIN_CHILDREN = 4 | ||
const MAX_CHILDREN = 80 | ||
|
||
const arrayUntil = (len) => [...Array(len)].map((_, i) => i) | ||
|
||
const generateFunctionalComponentModule = (componentName, children = []) => { | ||
const body = [ | ||
generateImport('React', 'react'), | ||
...children.map((childName) => generateImport(childName, `./${childName}`)), | ||
t.variableDeclaration('const', [ | ||
t.variableDeclarator( | ||
t.identifier(componentName), | ||
t.arrowFunctionExpression( | ||
[], | ||
t.parenthesizedExpression( | ||
generateJSXElement( | ||
'div', | ||
children.map((childName) => generateJSXElement(childName)) | ||
) | ||
) | ||
) | ||
), | ||
]), | ||
t.exportDefaultDeclaration(t.identifier(componentName)), | ||
] | ||
|
||
return t.program(body, [], 'module') | ||
} | ||
|
||
const generateJSXElement = (componentName, children = null) => | ||
t.JSXElement( | ||
t.JSXOpeningElement(t.JSXIdentifier(componentName), [], !children), | ||
children ? t.JSXClosingElement(t.JSXIdentifier(componentName)) : null, | ||
children || [], | ||
!children | ||
) | ||
|
||
const generateImport = (componentName, requireString) => | ||
t.importDeclaration( | ||
[t.importDefaultSpecifier(t.identifier(componentName))], | ||
t.stringLiteral(requireString) | ||
) | ||
|
||
const validFirstChars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' | ||
const validOtherChars = validFirstChars.toLowerCase() | ||
function generateComponentName(seqGenerator, opts) { | ||
const numOtherChars = seqGenerator.intBetween(opts.minLen, opts.maxLen) | ||
const firstChar = validFirstChars[seqGenerator.range(validFirstChars.length)] | ||
const otherChars = arrayUntil(numOtherChars).map( | ||
() => validOtherChars[seqGenerator.range(validOtherChars.length)] | ||
) | ||
return `${firstChar}${otherChars.join('')}` | ||
} | ||
|
||
function* generateModules(name, remainingDepth, seqGenerator, opts) { | ||
const filename = `${name}.${opts.extension}` | ||
let ast | ||
|
||
if (name === 'index') { | ||
name = 'RootComponent' | ||
} | ||
|
||
if (remainingDepth === 0) { | ||
ast = generateFunctionalComponentModule(name) | ||
} else { | ||
const numChildren = seqGenerator.intBetween(opts.minChild, opts.maxChild) | ||
const children = arrayUntil(numChildren).map(() => | ||
generateComponentName(seqGenerator, opts) | ||
) | ||
ast = generateFunctionalComponentModule(name, children) | ||
|
||
for (const child of children) { | ||
yield* generateModules(child, remainingDepth - 1, seqGenerator, opts) | ||
} | ||
} | ||
|
||
yield { | ||
filename, | ||
content: generate(ast).code, | ||
} | ||
} | ||
|
||
function generateFuzzponents(outdir, seed, depth, opts) { | ||
const seqGenerator = getSequenceGenerator(seed) | ||
|
||
const filenames = new Set() | ||
for (const { filename, content } of generateModules( | ||
'index', | ||
depth, | ||
seqGenerator, | ||
opts | ||
)) { | ||
if (filenames.has(filename)) { | ||
throw new Error( | ||
`Seed "${seed}" generates output with filename collisions.` | ||
) | ||
} else { | ||
filenames.add(filename) | ||
} | ||
const fpath = path.join(outdir, filename) | ||
fs.writeFileSync(fpath, `// ${filename}\n\n${content}`) | ||
} | ||
} | ||
|
||
if (require.main === module) { | ||
const { outdir, seed, depth, ...opts } = require('yargs') | ||
.option('depth', { | ||
alias: 'd', | ||
demandOption: true, | ||
describe: 'component hierarchy depth', | ||
type: 'number', | ||
}) | ||
.option('seed', { | ||
alias: 's', | ||
demandOption: true, | ||
describe: 'prng seed', | ||
type: 'number', | ||
}) | ||
.option('outdir', { | ||
alias: 'o', | ||
demandOption: false, | ||
default: process.cwd(), | ||
describe: 'the directory where components should be written', | ||
type: 'string', | ||
normalize: true, | ||
}) | ||
.option('minLen', { | ||
demandOption: false, | ||
default: MIN_COMPONENT_NAME_LEN, | ||
describe: 'the smallest acceptible component name length', | ||
type: 'number', | ||
}) | ||
.option('maxLen', { | ||
demandOption: false, | ||
default: MAX_COMPONENT_NAME_LEN, | ||
describe: 'the largest acceptible component name length', | ||
type: 'number', | ||
}) | ||
.option('minLen', { | ||
demandOption: false, | ||
default: MIN_COMPONENT_NAME_LEN, | ||
describe: 'the smallest acceptible component name length', | ||
type: 'number', | ||
}) | ||
.option('maxLen', { | ||
demandOption: false, | ||
default: MAX_COMPONENT_NAME_LEN, | ||
describe: 'the largest acceptible component name length', | ||
type: 'number', | ||
}) | ||
.option('minChild', { | ||
demandOption: false, | ||
default: MIN_CHILDREN, | ||
describe: 'the smallest number of acceptible component children', | ||
type: 'number', | ||
}) | ||
.option('maxChild', { | ||
demandOption: false, | ||
default: MAX_CHILDREN, | ||
describe: 'the largest number of acceptible component children', | ||
type: 'number', | ||
}) | ||
.option('extension', { | ||
default: 'jsx', | ||
describe: 'extension to use for generated components', | ||
type: 'string', | ||
}).argv | ||
|
||
generateFuzzponents(outdir, seed, depth, opts) | ||
} | ||
|
||
module.exports = generateFuzzponents |
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,9 @@ | ||
module.exports = { | ||
eslint: { | ||
ignoreDuringBuilds: true, | ||
}, | ||
experimental: { | ||
swcLoader: true, | ||
swcMinify: true, | ||
}, | ||
} |
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,10 @@ | ||
{ | ||
"scripts": { | ||
"prepare": "rm -rf components && node ./fuzzponent.js -d 2 -s 206 -o components", | ||
"dev": "../../node_modules/.bin/next dev", | ||
"build": "../../node_modules/.bin/next build", | ||
"start": "../../node_modules/.bin/next start", | ||
"dev-nocache": "rm -rf .next && yarn dev", | ||
"build-nocache": "rm -rf .next && yarn build" | ||
} | ||
} |
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,5 @@ | ||
import Comp from '../components/index.jsx' | ||
|
||
export default function Home() { | ||
return <Comp /> | ||
} |
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
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
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
Oops, something went wrong.