Files
next.js/bench/module-cost/scripts/prepare-bench.mjs
Arian Tron 61f56f997c
Some checks failed
Test examples / Test Examples (20) (push) Has been cancelled
Test examples / Test Examples (22) (push) Has been cancelled
Lock Threads / action (push) Has been cancelled
Trigger Release / start (push) Has been cancelled
Stale issue handler / stale (push) Has been cancelled
Update Font Data / create-pull-request (push) Has been cancelled
build-and-deploy / deploy-target (push) Has been cancelled
build-and-deploy / build (push) Has been cancelled
build-and-deploy / stable - aarch64-unknown-linux-musl - node@16 (push) Has been cancelled
build-and-deploy / stable - x86_64-unknown-linux-musl - node@16 (push) Has been cancelled
build-and-deploy / stable - aarch64-unknown-linux-gnu - node@16 (push) Has been cancelled
build-and-deploy / stable - x86_64-unknown-linux-gnu - node@16 (push) Has been cancelled
build-and-deploy / stable - aarch64-pc-windows-msvc - node@16 (push) Has been cancelled
build-and-deploy / stable - x86_64-pc-windows-msvc - node@16 (push) Has been cancelled
build-and-deploy / stable - aarch64-apple-darwin - node@16 (push) Has been cancelled
build-and-deploy / stable - x86_64-apple-darwin - node@16 (push) Has been cancelled
build-and-deploy / build-wasm (nodejs) (push) Has been cancelled
build-and-deploy / build-wasm (web) (push) Has been cancelled
build-and-deploy / Deploy preview tarball (push) Has been cancelled
build-and-deploy / Potentially publish release (push) Has been cancelled
build-and-deploy / publish-turbopack-npm-packages (push) Has been cancelled
build-and-deploy / Deploy examples (push) Has been cancelled
build-and-deploy / thank you, build (push) Has been cancelled
build-and-deploy / Upload Turbopack Bytesize metrics to Datadog (push) Has been cancelled
Rspack Next.js development integration tests / Rspack integration tests (push) Has been cancelled
Rspack Next.js production integration tests / Rspack integration tests (push) Has been cancelled
Turbopack Next.js development integration tests / Next.js integration tests (push) Has been cancelled
Turbopack Next.js production integration tests / Next.js integration tests (push) Has been cancelled
Update Rspack test manifest / Update and upload Rspack development test manifest (push) Has been cancelled
Update Rspack test manifest / Update and upload Rspack production test manifest (push) Has been cancelled
Upload bundler test manifests to areweturboyet.com / Upload test results (push) Has been cancelled
Update React / create-pull-request (push) Has been cancelled
test-e2e-project-reset-cron / reset-test-project (push) Has been cancelled
Notify about the top 15 issues/PRs/feature requests (most reacted) in the last 90 days / run (push) Has been cancelled
first commit
2026-03-10 19:37:31 +03:30

75 lines
2.1 KiB
JavaScript

import fs from 'node:fs/promises'
import path from 'node:path'
import { fileURLToPath } from 'node:url'
const __dirname = path.dirname(fileURLToPath(import.meta.url))
const commonjsDir = path.join(__dirname, '../commonjs')
const esmDir = path.join(__dirname, '../esm')
async function main() {
await fs.rm(commonjsDir, { recursive: true, force: true })
await fs.rm(esmDir, { recursive: true, force: true })
// Ensure directories exist
await fs.mkdir(commonjsDir, { recursive: true })
await fs.mkdir(esmDir, { recursive: true })
async function createFiles(dir, prefix, depth, type) {
const fileName = `${prefix}.js`
let content
if (depth === 0) {
switch (type) {
case 'commonjs':
content = `module.exports = 1;`
break
case 'esm':
content = `export default 1;`
break
default:
throw new Error(`Unknown type: ${type}`)
}
} else {
const inner = []
content = ''
for (let i = 0; i < 6; i++) {
const subPrefix = `${prefix}_${i}`
await createFiles(dir, subPrefix, depth - 1, type)
const subFileName = `${subPrefix}.js`
switch (type) {
case 'commonjs':
content += `const ${subPrefix} = require('./${subFileName}');\n`
break
case 'esm':
content += `import ${subPrefix} from './${subFileName}';\n`
break
default:
throw new Error(`Unknown type: ${type}`)
}
inner.push(subPrefix)
}
switch (type) {
case 'commonjs':
content += `\nmodule.exports = 1 + ${inner.join(' + ')};`
break
case 'esm':
content += `\nexport default 1 + ${inner.join(' + ')};`
break
default:
throw new Error(`Unknown type: ${type}`)
}
}
const filePath = path.join(dir, fileName)
await fs.writeFile(filePath, content, 'utf8')
}
await createFiles(commonjsDir, 'index', 5, 'commonjs')
await createFiles(esmDir, 'index', 5, 'esm')
}
main().catch((err) => {
console.error(err)
process.exit(1)
})