| 162 | .sort() |
| 163 | |
| 164 | export const check = ( |
| 165 | patterns: string[], |
| 166 | opts?: PrecompilePluginOptions |
| 167 | ): CheckReport => { |
| 168 | const cwd = realPathOf(opts?.cwd ?? process.cwd()) |
| 169 | const files = |
| 170 | patterns.length ? |
| 171 | requiredSourcesOf(patterns, cwd) |
| 172 | : sourcesOf(defaultSources, cwd) |
| 173 | // what the build's own plugin call passes, as in vite.config.ts |
| 174 | const calls = pluginCallsIn(cwd) |
| 175 | const given = opts ?? {} |
| 176 | const precompilerOptions = withEnvironment( |
| 177 | withSettingsFile({ ...withPluginCalls(calls, given), cwd }), |
| 178 | { |
| 179 | production: isProductionEnv(), |
| 180 | testing: false |
| 181 | } |
| 182 | ) |
| 183 | // one it can't find would otherwise check as though the project had none |
| 184 | if ( |
| 185 | precompilerOptions.tsconfig && |
| 186 | !existsSync(resolve(cwd, precompilerOptions.tsconfig)) |
| 187 | ) { |
| 188 | throwError( |
| 189 | writeMissingTsconfigMessage(resolve(cwd, precompilerOptions.tsconfig)) |
| 190 | ) |
| 191 | } |
| 192 | const request = createSyncPrecompiler({ precompilerOptions }) |
| 193 | const report: CheckReport = { |
| 194 | lines: pluginCallLinesOf(calls, given), |
| 195 | sites: 0, |
| 196 | accepted: 0, |
| 197 | islands: 0, |
| 198 | rate: 100, |
| 199 | errorsOutsideSites: 0, |
| 200 | errors: 0, |
| 201 | files: files.length, |
| 202 | diagnostics: [] |
| 203 | } |
| 204 | // each key of schemas that chose for a definition of some file |
| 205 | const choosing = new Set<string>() |
| 206 | // a script outside cwd the build transforms as one checked here imports it, |
| 207 | // like a workspace package's source, whose refusals fail the build too |
| 208 | const packages = optedInPackagesOf( |
| 209 | cwd, |
| 210 | precompilerOptions.dependencies, |
| 211 | () => {} |
| 212 | ) |
| 213 | const root = realPathOf(cwd) |
| 214 | const isOutside = (file: string) => { |
| 215 | const path = relative(root, file) |
| 216 | return path.startsWith("..") || isAbsolute(path) |
| 217 | } |
| 218 | const reached = new Set<string>() |
| 219 | try { |
| 220 | for (let batch = files; batch.length; ) { |
| 221 | for (const file of batch) { |