|
1 | 1 | import path from "path";
|
2 | 2 |
|
3 | 3 | import postcss from "postcss";
|
| 4 | +import { NormalModule } from "webpack"; |
4 | 5 |
|
5 | 6 | import {
|
6 | 7 | compile,
|
@@ -81,6 +82,54 @@ describe("loader", () => {
|
81 | 82 | expect(getErrors(stats)).toMatchSnapshot("errors");
|
82 | 83 | });
|
83 | 84 |
|
| 85 | + it('should register dependencies using the "messages" API', async () => { |
| 86 | + const plugin = () => (css, result) => { |
| 87 | + result.messages.push({ |
| 88 | + type: "build-dependency", |
| 89 | + file: "build-dep.html", |
| 90 | + content: "", |
| 91 | + plugin, |
| 92 | + }); |
| 93 | + }; |
| 94 | + |
| 95 | + let actualBuildInfo = null; |
| 96 | + |
| 97 | + const postcssPlugin = postcss.plugin("postcss-plugin", plugin); |
| 98 | + const compiler = getCompiler( |
| 99 | + "./css/index.js", |
| 100 | + { |
| 101 | + postcssOptions: { |
| 102 | + plugins: [postcssPlugin()], |
| 103 | + }, |
| 104 | + }, |
| 105 | + { |
| 106 | + plugins: [ |
| 107 | + { |
| 108 | + /** @param {import("webpack").Compiler} compiler */ |
| 109 | + apply(wpcompiler) { |
| 110 | + wpcompiler.hooks.compilation.tap("plugin", (compilation) => { |
| 111 | + NormalModule.getCompilationHooks(compilation).beforeLoaders.tap( |
| 112 | + "plugin", |
| 113 | + (_1, module) => { |
| 114 | + actualBuildInfo = module.buildInfo; |
| 115 | + } |
| 116 | + ); |
| 117 | + }); |
| 118 | + }, |
| 119 | + }, |
| 120 | + ], |
| 121 | + } |
| 122 | + ); |
| 123 | + |
| 124 | + const stats = await compile(compiler); |
| 125 | + |
| 126 | + const buildDependencies = [...actualBuildInfo.buildDependencies]; |
| 127 | + expect(buildDependencies).toContain("build-dep.html"); |
| 128 | + |
| 129 | + expect(getWarnings(stats)).toMatchSnapshot("warnings"); |
| 130 | + expect(getErrors(stats)).toMatchSnapshot("errors"); |
| 131 | + }); |
| 132 | + |
84 | 133 | it("should reuse PostCSS AST", async () => {
|
85 | 134 | const spy = jest.fn();
|
86 | 135 | const compiler = getCompiler(
|
|
0 commit comments