(config: BuildConfig)
| 13 | * build files to npm. |
| 14 | */ |
| 15 | export async function validateBuild(config: BuildConfig) { |
| 16 | console.log('🕵️ validating build...'); |
| 17 | const pkgPath = join(config.distQwikPkgDir, 'package.json'); |
| 18 | const pkg: PackageJSON = JSON.parse(await readFile(pkgPath, 'utf-8')); |
| 19 | const errors: string[] = []; |
| 20 | const require = createRequire(import.meta.url); |
| 21 | |
| 22 | // triple checks these package files all exist and parse |
| 23 | const pkgFiles = [...pkg.files!, 'LICENSE', 'README.md', 'package.json']; |
| 24 | const expectedFiles = pkgFiles.map((f) => join(config.distQwikPkgDir, f)); |
| 25 | |
| 26 | const dependencies = ['csstype', 'vite']; |
| 27 | const pkgDependencies = Object.keys(pkg.dependencies!); |
| 28 | if (pkgDependencies.length !== dependencies.length) { |
| 29 | errors.push( |
| 30 | `Expected ${dependencies.length} dependencies, but found ${pkgDependencies.length}.` |
| 31 | ); |
| 32 | } else { |
| 33 | for (const dep of dependencies) { |
| 34 | if (!pkgDependencies.includes(dep)) { |
| 35 | errors.push(`Expected ${dep} to be a dependency.`); |
| 36 | } |
| 37 | } |
| 38 | } |
| 39 | |
| 40 | for (const filePath of expectedFiles) { |
| 41 | try { |
| 42 | // loop through each file and ensure it's built correct |
| 43 | const ext = extname(filePath); |
| 44 | |
| 45 | switch (ext) { |
| 46 | case '.cjs': |
| 47 | const f = basename(filePath); |
| 48 | if (f !== 'qwik.cjs') { |
| 49 | require(filePath); |
| 50 | console.log(`✅ ${filePath}`); |
| 51 | } |
| 52 | break; |
| 53 | case '.mjs': |
| 54 | if (config.esmNode) { |
| 55 | await import(pathToFileURL(filePath).href); |
| 56 | console.log(`✅ ${filePath}`); |
| 57 | break; |
| 58 | } |
| 59 | case '.ts': |
| 60 | validateTypeScriptFile(config, filePath); |
| 61 | console.log(`✅ ${filePath}`); |
| 62 | break; |
| 63 | case '.json': |
| 64 | JSON.parse(readFileSync(filePath, 'utf-8')); |
| 65 | console.log(`✅ ${filePath}`); |
| 66 | break; |
| 67 | case '.map': |
| 68 | JSON.parse(readFileSync(filePath, 'utf-8')); |
| 69 | console.log(`✅ ${filePath}`); |
| 70 | break; |
| 71 | default: |
| 72 | if (existsSync(filePath)) { |
no test coverage detected
searching dependent graphs…