* @param {string} entry entry file * @param {import("../").Configuration} options webpack options * @param {(stats: CachingStats, files: Record<string, string>, iteration: number) => void} callback done callback * @returns {{ compilerInstance: import("../").Compiler, runAgain: (options: Record
(entry, options, callback)
| 25 | * @returns {{ compilerInstance: import("../").Compiler, runAgain: (options: Record<string, unknown> | ((stats: CachingStats, files: Record<string, string>, iteration: number) => void), callback?: (stats: CachingStats, files: Record<string, string>, iteration: number) => void) => void }} helpers |
| 26 | */ |
| 27 | function compile(entry, options, callback) { |
| 28 | const webpack = require(".."); |
| 29 | |
| 30 | /** @type {import("../").WebpackOptionsNormalized} */ |
| 31 | const normalizedOptions = |
| 32 | webpack.config.getNormalizedWebpackOptions(options); |
| 33 | normalizedOptions.mode = "none"; |
| 34 | normalizedOptions.cache = |
| 35 | /** @type {import("../").WebpackOptionsNormalized["cache"]} */ ( |
| 36 | /** @type {unknown} */ (true) |
| 37 | ); |
| 38 | normalizedOptions.entry = /** @type {import("../").EntryNormalized} */ ( |
| 39 | /** @type {unknown} */ (entry) |
| 40 | ); |
| 41 | normalizedOptions.optimization.moduleIds = "natural"; |
| 42 | normalizedOptions.optimization.minimize = false; |
| 43 | normalizedOptions.context = path.join(__dirname, "fixtures"); |
| 44 | normalizedOptions.output.path = "/"; |
| 45 | normalizedOptions.output.filename = "bundle.js"; |
| 46 | normalizedOptions.output.pathinfo = true; |
| 47 | /** @type {CachingLogs} */ |
| 48 | const logs = { |
| 49 | mkdir: [], |
| 50 | writeFile: [] |
| 51 | }; |
| 52 | |
| 53 | const c = webpack( |
| 54 | /** @type {import("../").Configuration} */ ( |
| 55 | /** @type {unknown} */ (normalizedOptions) |
| 56 | ) |
| 57 | ); |
| 58 | /** @type {Record<string, string>} */ |
| 59 | const files = {}; |
| 60 | c.outputFileSystem = /** @type {import("../").OutputFileSystem} */ ( |
| 61 | /** @type {unknown} */ ({ |
| 62 | /** |
| 63 | * @param {string} dirPath directory path |
| 64 | * @param {(err: NodeJS.ErrnoException) => void} cb callback |
| 65 | */ |
| 66 | mkdir(dirPath, cb) { |
| 67 | logs.mkdir.push(dirPath); |
| 68 | const err = /** @type {NodeJS.ErrnoException} */ (new Error("error")); |
| 69 | err.code = "EEXIST"; |
| 70 | cb(err); |
| 71 | }, |
| 72 | /** |
| 73 | * @param {string} name file name |
| 74 | * @param {Buffer} content file content |
| 75 | * @param {() => void} cb callback |
| 76 | */ |
| 77 | writeFile(name, content, cb) { |
| 78 | logs.writeFile.push(name, content); |
| 79 | files[name] = content.toString("utf8"); |
| 80 | cb(); |
| 81 | }, |
| 82 | /** |
| 83 | * @param {string} _filePath file path |
| 84 | * @param {(err: Error) => void} cb callback |
no test coverage detected