@rspack/test-tools 0.4.4 → 0.4.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,14 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <meta charset="utf-8" />
5
+ <title>Rspack Diff Viewer</title>
6
+ <script id="$$RSPACK_DIFF_STATS_PLACEHOLDER$$"></script>
7
+ <link href="diff.bundle.css" rel="stylesheet" /><script src="diff.bundle.js" defer></script></head>
8
+
9
+ <body>
10
+
11
+ <div id="root"></div>
12
+
13
+
14
+ </body></html>
@@ -1,3 +0,0 @@
1
- export declare function createModulePlaceholderPlugin(webpackPath: any): {
2
- apply(compiler: any): void;
3
- };
@@ -1,115 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.createModulePlaceholderPlugin = void 0;
4
- // @ts-nocheck
5
- const { ConcatSource, RawSource, CachedSource, PrefixSource } = require("webpack-sources");
6
- const path = require("path");
7
- function createRenderRuntimeModulesFn(Template) {
8
- return function renderRuntimeModules(runtimeModules, renderContext) {
9
- const source = new ConcatSource();
10
- for (const module of runtimeModules) {
11
- const codeGenerationResults = renderContext.codeGenerationResults;
12
- let runtimeSource;
13
- if (codeGenerationResults) {
14
- runtimeSource = codeGenerationResults.getSource(module, renderContext.chunk.runtime, "runtime");
15
- }
16
- else {
17
- const codeGenResult = module.codeGeneration({
18
- chunkGraph: renderContext.chunkGraph,
19
- dependencyTemplates: renderContext.dependencyTemplates,
20
- moduleGraph: renderContext.moduleGraph,
21
- runtimeTemplate: renderContext.runtimeTemplate,
22
- runtime: renderContext.chunk.runtime,
23
- codeGenerationResults
24
- });
25
- if (!codeGenResult)
26
- continue;
27
- runtimeSource = codeGenResult.sources.get("runtime");
28
- }
29
- if (runtimeSource) {
30
- let identifier = module.identifier();
31
- source.add(Template.toNormalComment(`start::${identifier}`) + "\n");
32
- if (!module.shouldIsolate()) {
33
- source.add(runtimeSource);
34
- source.add("\n\n");
35
- }
36
- else if (renderContext.runtimeTemplate.supportsArrowFunction()) {
37
- source.add("(() => {\n");
38
- source.add(new PrefixSource("\t", runtimeSource));
39
- source.add("\n})();\n\n");
40
- }
41
- else {
42
- source.add("!function() {\n");
43
- source.add(new PrefixSource("\t", runtimeSource));
44
- source.add("\n}();\n\n");
45
- }
46
- source.add(Template.toNormalComment(`end::${identifier}`) + "\n");
47
- }
48
- }
49
- return source;
50
- };
51
- }
52
- const caches = new WeakMap();
53
- function createModulePlaceholderPlugin(webpackPath) {
54
- const JavascriptModulesPlugin = require(path.join(path.dirname(webpackPath), "javascript/JavascriptModulesPlugin.js"));
55
- const Template = require(path.join(path.dirname(webpackPath), "Template.js"));
56
- Template.renderRuntimeModules = createRenderRuntimeModulesFn(Template);
57
- return {
58
- apply(compiler) {
59
- compiler.hooks.compilation.tap("RuntimeDiffPlugin", compilation => {
60
- const hooks = JavascriptModulesPlugin.getCompilationHooks(compilation);
61
- hooks.inlineInRuntimeBailout.tap("RuntimeDiffPlugin", () => "not allow inline startup");
62
- hooks.renderModulePackage.tap("RuntimeDiffPlugin", (moduleSource, module, { chunk, chunkGraph, moduleGraph, runtimeTemplate }) => {
63
- const { requestShortener } = runtimeTemplate;
64
- let cacheEntry;
65
- let cache = caches.get(requestShortener);
66
- if (cache === undefined) {
67
- caches.set(requestShortener, (cache = new WeakMap()));
68
- cache.set(module, (cacheEntry = {
69
- header: undefined,
70
- footer: undefined,
71
- full: new WeakMap()
72
- }));
73
- }
74
- else {
75
- cacheEntry = cache.get(module);
76
- if (cacheEntry === undefined) {
77
- cache.set(module, (cacheEntry = {
78
- header: undefined,
79
- footer: undefined,
80
- full: new WeakMap()
81
- }));
82
- }
83
- else {
84
- const cachedSource = cacheEntry.full.get(moduleSource);
85
- if (cachedSource !== undefined)
86
- return cachedSource;
87
- }
88
- }
89
- const source = new ConcatSource();
90
- let header = cacheEntry.header;
91
- let footer = cacheEntry.footer;
92
- if (header === undefined) {
93
- const req = module.readableIdentifier(requestShortener);
94
- let reqStr = req.replace(/\*\//g, "*_/");
95
- // handle css module identifier
96
- if (reqStr.startsWith("css ")) {
97
- reqStr = reqStr.replace(/^css[\s]+/, "").trim();
98
- }
99
- header = new RawSource(`\n/* start::${reqStr} */\n`);
100
- footer = new RawSource(`\n/* end::${reqStr} */\n`);
101
- cacheEntry.header = header;
102
- cacheEntry.footer = footer;
103
- }
104
- source.add(header);
105
- source.add(moduleSource);
106
- source.add(footer);
107
- const cachedSource = new CachedSource(source);
108
- cacheEntry.full.set(moduleSource, cachedSource);
109
- return cachedSource;
110
- });
111
- });
112
- }
113
- };
114
- }
115
- exports.createModulePlaceholderPlugin = createModulePlaceholderPlugin;