@rspack/core 0.5.6 → 0.5.7-canary-dcd4782-20240312094134
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.
- package/dist/ChunkGroup.d.ts +3 -1
- package/dist/ChunkGroup.js +6 -0
- package/dist/Compilation.d.ts +4 -5
- package/dist/Compilation.js +37 -52
- package/dist/Compiler.js +55 -53
- package/dist/Entrypoint.d.ts +8 -0
- package/dist/Entrypoint.js +21 -0
- package/dist/Watching.d.ts +1 -0
- package/dist/Watching.js +3 -0
- package/dist/builtin-plugin/index.d.ts +1 -0
- package/dist/builtin-plugin/index.js +1 -0
- package/dist/builtin-plugin/lazy-compilation/backend.d.ts +27 -0
- package/dist/builtin-plugin/lazy-compilation/backend.js +144 -0
- package/dist/builtin-plugin/lazy-compilation/lazyCompilation.d.ts +30 -0
- package/dist/builtin-plugin/lazy-compilation/lazyCompilation.js +6 -0
- package/dist/builtin-plugin/lazy-compilation/plugin.d.ts +10 -0
- package/dist/builtin-plugin/lazy-compilation/plugin.js +57 -0
- package/dist/config/adapter.js +10 -3
- package/dist/config/adapterRuleUse.d.ts +1 -1
- package/dist/config/normalization.d.ts +3 -2
- package/dist/config/normalization.js +3 -1
- package/dist/config/zod.d.ts +93 -10
- package/dist/config/zod.js +15 -3
- package/dist/exports.d.ts +16 -4
- package/dist/lite-tapable/index.d.ts +34 -24
- package/dist/lite-tapable/index.js +173 -75
- package/dist/loader-runner/index.js +7 -5
- package/dist/rspackOptionsApply.js +9 -0
- package/dist/stats/DefaultStatsFactoryPlugin.js +3 -0
- package/dist/stats/statsFactoryUtils.d.ts +2 -1
- package/dist/util/fake.d.ts +0 -35
- package/dist/util/fake.js +1 -95
- package/package.json +7 -6
package/dist/ChunkGroup.d.ts
CHANGED
|
@@ -2,9 +2,11 @@ import { type JsChunkGroup, type JsCompilation } from "@rspack/binding";
|
|
|
2
2
|
export declare class ChunkGroup {
|
|
3
3
|
#private;
|
|
4
4
|
static __from_binding(chunk: JsChunkGroup, compilation: JsCompilation): ChunkGroup;
|
|
5
|
-
|
|
5
|
+
protected constructor(inner: JsChunkGroup, compilation: JsCompilation);
|
|
6
6
|
getFiles(): string[];
|
|
7
7
|
getParents(): ChunkGroup[];
|
|
8
8
|
get index(): number | undefined;
|
|
9
9
|
get name(): string | undefined;
|
|
10
|
+
__internal_inner_ukey(): number;
|
|
11
|
+
__internal_inner_compilation(): JsCompilation;
|
|
10
12
|
}
|
package/dist/ChunkGroup.js
CHANGED
|
@@ -45,6 +45,12 @@ class ChunkGroup {
|
|
|
45
45
|
get name() {
|
|
46
46
|
return __classPrivateFieldGet(this, _ChunkGroup_inner, "f").name;
|
|
47
47
|
}
|
|
48
|
+
__internal_inner_ukey() {
|
|
49
|
+
return __classPrivateFieldGet(this, _ChunkGroup_inner, "f").__inner_ukey;
|
|
50
|
+
}
|
|
51
|
+
__internal_inner_compilation() {
|
|
52
|
+
return __classPrivateFieldGet(this, _ChunkGroup_inner_compilation, "f");
|
|
53
|
+
}
|
|
48
54
|
}
|
|
49
55
|
exports.ChunkGroup = ChunkGroup;
|
|
50
56
|
_ChunkGroup_inner = new WeakMap(), _ChunkGroup_inner_compilation = new WeakMap();
|
package/dist/Compilation.d.ts
CHANGED
|
@@ -12,21 +12,21 @@ import * as tapable from "tapable";
|
|
|
12
12
|
import { Source } from "webpack-sources";
|
|
13
13
|
import type { ExternalObject, JsAssetInfo, JsChunk, JsCompatSource, JsCompilation, JsModule, JsRuntimeModule, JsStatsChunk, JsStatsError, PathData } from "@rspack/binding";
|
|
14
14
|
import { RspackOptionsNormalized, StatsOptions, OutputNormalized, StatsValue, RspackPluginInstance } from "./config";
|
|
15
|
+
import * as liteTapable from "./lite-tapable";
|
|
15
16
|
import { ContextModuleFactory } from "./ContextModuleFactory";
|
|
16
17
|
import ResolverFactory from "./ResolverFactory";
|
|
17
|
-
import { ChunkGroup } from "./ChunkGroup";
|
|
18
18
|
import { Compiler } from "./Compiler";
|
|
19
19
|
import { Logger } from "./logging/Logger";
|
|
20
20
|
import { NormalModuleFactory } from "./NormalModuleFactory";
|
|
21
21
|
import { Stats } from "./Stats";
|
|
22
22
|
import { StatsFactory } from "./stats/StatsFactory";
|
|
23
23
|
import { StatsPrinter } from "./stats/StatsPrinter";
|
|
24
|
-
import { createFakeProcessAssetsHook } from "./util/fake";
|
|
25
24
|
import { NormalizedJsModule } from "./util/normalization";
|
|
26
25
|
import MergeCaller from "./util/MergeCaller";
|
|
27
26
|
import { Chunk } from "./Chunk";
|
|
28
27
|
import { CodeGenerationResult } from "./Module";
|
|
29
28
|
import { ChunkGraph } from "./ChunkGraph";
|
|
29
|
+
import { Entrypoint } from "./Entrypoint";
|
|
30
30
|
export type AssetInfo = Partial<JsAssetInfo> & Record<string, any>;
|
|
31
31
|
export type Assets = Record<string, Source>;
|
|
32
32
|
export interface Asset {
|
|
@@ -62,7 +62,7 @@ type CreateStatsOptionsContext = KnownCreateStatsOptionsContext & Record<string,
|
|
|
62
62
|
export declare class Compilation {
|
|
63
63
|
#private;
|
|
64
64
|
hooks: {
|
|
65
|
-
processAssets:
|
|
65
|
+
processAssets: liteTapable.AsyncSeriesHook<Assets>;
|
|
66
66
|
afterProcessAssets: tapable.SyncHook<Assets>;
|
|
67
67
|
childCompiler: tapable.SyncHook<[Compiler, string, number]>;
|
|
68
68
|
log: tapable.SyncBailHook<[string, LogEntry], true>;
|
|
@@ -125,7 +125,7 @@ export declare class Compilation {
|
|
|
125
125
|
/**
|
|
126
126
|
* Get a map of all entrypoints.
|
|
127
127
|
*/
|
|
128
|
-
get entrypoints(): ReadonlyMap<string,
|
|
128
|
+
get entrypoints(): ReadonlyMap<string, Entrypoint>;
|
|
129
129
|
getCache(name: string): import("./lib/CacheFacade");
|
|
130
130
|
createStatsOptions(optionsOrPreset: StatsValue | undefined, context?: CreateStatsOptionsContext): StatsOptions;
|
|
131
131
|
createStatsFactory(options: StatsOptions): StatsFactory;
|
|
@@ -328,6 +328,5 @@ export declare class Compilation {
|
|
|
328
328
|
static PROCESS_ASSETS_STAGE_OPTIMIZE_TRANSFER: number;
|
|
329
329
|
static PROCESS_ASSETS_STAGE_ANALYSE: number;
|
|
330
330
|
static PROCESS_ASSETS_STAGE_REPORT: number;
|
|
331
|
-
__internal_getProcessAssetsHookByStage(stage: number): tapable.AsyncSeriesHook<Assets, tapable.UnsetAdditionalOptions>;
|
|
332
331
|
}
|
|
333
332
|
export {};
|
package/dist/Compilation.js
CHANGED
|
@@ -49,7 +49,7 @@ exports.Compilation = void 0;
|
|
|
49
49
|
* https://github.com/webpack/webpack/blob/main/LICENSE
|
|
50
50
|
*/
|
|
51
51
|
const tapable = __importStar(require("tapable"));
|
|
52
|
-
const
|
|
52
|
+
const liteTapable = __importStar(require("./lite-tapable"));
|
|
53
53
|
const ErrorHelpers_1 = __importDefault(require("./ErrorHelpers"));
|
|
54
54
|
const Logger_1 = require("./logging/Logger");
|
|
55
55
|
const NormalModule_1 = require("./NormalModule");
|
|
@@ -64,6 +64,7 @@ const MergeCaller_1 = __importDefault(require("./util/MergeCaller"));
|
|
|
64
64
|
const memoize_1 = require("./util/memoize");
|
|
65
65
|
const Chunk_1 = require("./Chunk");
|
|
66
66
|
const ChunkGraph_1 = require("./ChunkGraph");
|
|
67
|
+
const Entrypoint_1 = require("./Entrypoint");
|
|
67
68
|
class Compilation {
|
|
68
69
|
constructor(compiler, inner) {
|
|
69
70
|
_Compilation_inner.set(this, void 0);
|
|
@@ -95,13 +96,42 @@ class Compilation {
|
|
|
95
96
|
this.name = undefined;
|
|
96
97
|
this.startTime = undefined;
|
|
97
98
|
this.endTime = undefined;
|
|
98
|
-
const
|
|
99
|
+
const processAssetsHook = new liteTapable.AsyncSeriesHook([
|
|
100
|
+
"assets"
|
|
101
|
+
]);
|
|
102
|
+
const createProcessAssetsHook = (name, stage, getArgs, code) => {
|
|
103
|
+
const errorMessage = (reason) => `Can't automatically convert plugin using Compilation.hooks.${name} to Compilation.hooks.processAssets because ${reason}.
|
|
104
|
+
BREAKING CHANGE: Asset processing hooks in Compilation has been merged into a single Compilation.hooks.processAssets hook.`;
|
|
105
|
+
const getOptions = (options) => {
|
|
106
|
+
if (typeof options === "string")
|
|
107
|
+
options = { name: options };
|
|
108
|
+
if (options.stage) {
|
|
109
|
+
throw new Error(errorMessage("it's using the 'stage' option"));
|
|
110
|
+
}
|
|
111
|
+
return { ...options, stage: stage };
|
|
112
|
+
};
|
|
113
|
+
return Object.freeze({
|
|
114
|
+
name,
|
|
115
|
+
intercept() {
|
|
116
|
+
throw new Error(errorMessage("it's using 'intercept'"));
|
|
117
|
+
},
|
|
118
|
+
tap: (options, fn) => {
|
|
119
|
+
processAssetsHook.tap(getOptions(options), () => fn(...getArgs()));
|
|
120
|
+
},
|
|
121
|
+
tapAsync: (options, fn) => {
|
|
122
|
+
processAssetsHook.tapAsync(getOptions(options), (assets, callback) => fn(...getArgs(), callback));
|
|
123
|
+
},
|
|
124
|
+
tapPromise: (options, fn) => {
|
|
125
|
+
processAssetsHook.tapPromise(getOptions(options), () => fn(...getArgs()));
|
|
126
|
+
},
|
|
127
|
+
_fakeHook: true
|
|
128
|
+
});
|
|
129
|
+
};
|
|
99
130
|
this.hooks = {
|
|
100
|
-
processAssets:
|
|
131
|
+
processAssets: processAssetsHook,
|
|
101
132
|
afterProcessAssets: new tapable.SyncHook(["assets"]),
|
|
102
|
-
// TODO: webpack 6 deprecate, keep it just for compatibility
|
|
103
133
|
/** @deprecated */
|
|
104
|
-
additionalAssets:
|
|
134
|
+
additionalAssets: createProcessAssetsHook("additionalAssets", Compilation.PROCESS_ASSETS_STAGE_ADDITIONAL, () => []),
|
|
105
135
|
childCompiler: new tapable.SyncHook([
|
|
106
136
|
"childCompiler",
|
|
107
137
|
"compilerName",
|
|
@@ -196,7 +226,7 @@ class Compilation {
|
|
|
196
226
|
get entrypoints() {
|
|
197
227
|
return new Map(Object.entries(__classPrivateFieldGet(this, _Compilation_inner, "f").entrypoints).map(([n, e]) => [
|
|
198
228
|
n,
|
|
199
|
-
|
|
229
|
+
Entrypoint_1.Entrypoint.__from_binding(e, __classPrivateFieldGet(this, _Compilation_inner, "f"))
|
|
200
230
|
]));
|
|
201
231
|
}
|
|
202
232
|
getCache(name) {
|
|
@@ -218,6 +248,7 @@ class Compilation {
|
|
|
218
248
|
options.runtimeModules = optionOrLocalFallback(options.runtimeModules, !context.forToString);
|
|
219
249
|
options.reasons = optionOrLocalFallback(options.reasons, !context.forToString);
|
|
220
250
|
options.usedExports = optionOrLocalFallback(options.usedExports, !context.forToString);
|
|
251
|
+
options.optimizationBailout = optionOrLocalFallback(options.optimizationBailout, !context.forToString);
|
|
221
252
|
options.providedExports = optionOrLocalFallback(options.providedExports, !context.forToString);
|
|
222
253
|
options.entrypoints = optionOrLocalFallback(options.entrypoints, true);
|
|
223
254
|
options.chunkGroups = optionOrLocalFallback(options.chunkGroups, !context.forToString);
|
|
@@ -674,52 +705,6 @@ class Compilation {
|
|
|
674
705
|
}
|
|
675
706
|
seal() { }
|
|
676
707
|
unseal() { }
|
|
677
|
-
__internal_getProcessAssetsHookByStage(stage) {
|
|
678
|
-
if (stage > Compilation.PROCESS_ASSETS_STAGE_REPORT) {
|
|
679
|
-
this.pushDiagnostic("warning", "not supported process_assets_stage", `custom stage for process_assets is not supported yet, so ${stage} is fallback to Compilation.PROCESS_ASSETS_STAGE_REPORT(${Compilation.PROCESS_ASSETS_STAGE_REPORT}) `);
|
|
680
|
-
stage = Compilation.PROCESS_ASSETS_STAGE_REPORT;
|
|
681
|
-
}
|
|
682
|
-
if (stage < Compilation.PROCESS_ASSETS_STAGE_ADDITIONAL) {
|
|
683
|
-
this.pushDiagnostic("warning", "not supported process_assets_stage", `custom stage for process_assets is not supported yet, so ${stage} is fallback to Compilation.PROCESS_ASSETS_STAGE_ADDITIONAL(${Compilation.PROCESS_ASSETS_STAGE_ADDITIONAL}) `);
|
|
684
|
-
stage = Compilation.PROCESS_ASSETS_STAGE_ADDITIONAL;
|
|
685
|
-
}
|
|
686
|
-
switch (stage) {
|
|
687
|
-
case Compilation.PROCESS_ASSETS_STAGE_ADDITIONAL:
|
|
688
|
-
return this.hooks.processAssets.stageAdditional;
|
|
689
|
-
case Compilation.PROCESS_ASSETS_STAGE_PRE_PROCESS:
|
|
690
|
-
return this.hooks.processAssets.stagePreProcess;
|
|
691
|
-
case Compilation.PROCESS_ASSETS_STAGE_DERIVED:
|
|
692
|
-
return this.hooks.processAssets.stageDerived;
|
|
693
|
-
case Compilation.PROCESS_ASSETS_STAGE_ADDITIONS:
|
|
694
|
-
return this.hooks.processAssets.stageAdditions;
|
|
695
|
-
case Compilation.PROCESS_ASSETS_STAGE_NONE:
|
|
696
|
-
return this.hooks.processAssets.stageNone;
|
|
697
|
-
case Compilation.PROCESS_ASSETS_STAGE_OPTIMIZE:
|
|
698
|
-
return this.hooks.processAssets.stageOptimize;
|
|
699
|
-
case Compilation.PROCESS_ASSETS_STAGE_OPTIMIZE_COUNT:
|
|
700
|
-
return this.hooks.processAssets.stageOptimizeCount;
|
|
701
|
-
case Compilation.PROCESS_ASSETS_STAGE_OPTIMIZE_COMPATIBILITY:
|
|
702
|
-
return this.hooks.processAssets.stageOptimizeCompatibility;
|
|
703
|
-
case Compilation.PROCESS_ASSETS_STAGE_OPTIMIZE_SIZE:
|
|
704
|
-
return this.hooks.processAssets.stageOptimizeSize;
|
|
705
|
-
case Compilation.PROCESS_ASSETS_STAGE_DEV_TOOLING:
|
|
706
|
-
return this.hooks.processAssets.stageDevTooling;
|
|
707
|
-
case Compilation.PROCESS_ASSETS_STAGE_OPTIMIZE_INLINE:
|
|
708
|
-
return this.hooks.processAssets.stageOptimizeInline;
|
|
709
|
-
case Compilation.PROCESS_ASSETS_STAGE_SUMMARIZE:
|
|
710
|
-
return this.hooks.processAssets.stageSummarize;
|
|
711
|
-
case Compilation.PROCESS_ASSETS_STAGE_OPTIMIZE_HASH:
|
|
712
|
-
return this.hooks.processAssets.stageOptimizeHash;
|
|
713
|
-
case Compilation.PROCESS_ASSETS_STAGE_OPTIMIZE_TRANSFER:
|
|
714
|
-
return this.hooks.processAssets.stageOptimizeTransfer;
|
|
715
|
-
case Compilation.PROCESS_ASSETS_STAGE_ANALYSE:
|
|
716
|
-
return this.hooks.processAssets.stageAnalyse;
|
|
717
|
-
case Compilation.PROCESS_ASSETS_STAGE_REPORT:
|
|
718
|
-
return this.hooks.processAssets.stageReport;
|
|
719
|
-
default:
|
|
720
|
-
throw new Error("processAssets hook uses custom stage number is not supported.");
|
|
721
|
-
}
|
|
722
|
-
}
|
|
723
708
|
}
|
|
724
709
|
_Compilation_inner = new WeakMap();
|
|
725
710
|
Compilation.PROCESS_ASSETS_STAGE_ADDITIONAL = -2000;
|
package/dist/Compiler.js
CHANGED
|
@@ -36,7 +36,7 @@ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (
|
|
|
36
36
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
37
37
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
38
38
|
};
|
|
39
|
-
var _Compiler_instances, _Compiler_instance, _Compiler_disabledHooks, _Compiler_moduleExecutionResultsMap, _Compiler_getInstance, _Compiler_updateDisabledHooks, _Compiler_beforeCompile, _Compiler_afterCompile, _Compiler_finishMake, _Compiler_buildModule,
|
|
39
|
+
var _Compiler_instances, _Compiler_instance, _Compiler_disabledHooks, _Compiler_moduleExecutionResultsMap, _Compiler_getInstance, _Compiler_updateDisabledHooks, _Compiler_beforeCompile, _Compiler_afterCompile, _Compiler_finishMake, _Compiler_buildModule, _Compiler_afterProcessAssets, _Compiler_beforeResolve, _Compiler_afterResolve, _Compiler_contextModuleFactoryBeforeResolve, _Compiler_contextModuleFactoryAfterResolve, _Compiler_normalModuleFactoryCreateModule, _Compiler_normalModuleFactoryResolveForScheme, _Compiler_optimizeChunkModules, _Compiler_optimizeTree, _Compiler_optimizeModules, _Compiler_afterOptimizeModules, _Compiler_chunkAsset, _Compiler_finishModules, _Compiler_shouldEmit, _Compiler_emit, _Compiler_assetEmitted, _Compiler_afterEmit, _Compiler_succeedModule, _Compiler_stillValidModule, _Compiler_runtimeModule, _Compiler_executeModule, _Compiler_decorateUpdateDisabledHooks, _Compiler_registerCompilerCompilationTaps, _Compiler_registerCompilerMakeTaps, _Compiler_registerCompilationProcessAssetsTaps, _Compiler_newCompilation;
|
|
40
40
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
41
41
|
exports.Compiler = void 0;
|
|
42
42
|
const index_1 = require("./index");
|
|
@@ -523,22 +523,6 @@ _Compiler_instance = new WeakMap(), _Compiler_disabledHooks = new WeakMap(), _Co
|
|
|
523
523
|
emit: __classPrivateFieldGet(this, _Compiler_instances, "m", _Compiler_emit).bind(this),
|
|
524
524
|
assetEmitted: __classPrivateFieldGet(this, _Compiler_instances, "m", _Compiler_assetEmitted).bind(this),
|
|
525
525
|
afterEmit: __classPrivateFieldGet(this, _Compiler_instances, "m", _Compiler_afterEmit).bind(this),
|
|
526
|
-
processAssetsStageAdditional: __classPrivateFieldGet(this, _Compiler_instances, "m", _Compiler_processAssets).bind(this, Compilation_1.Compilation.PROCESS_ASSETS_STAGE_ADDITIONAL),
|
|
527
|
-
processAssetsStagePreProcess: __classPrivateFieldGet(this, _Compiler_instances, "m", _Compiler_processAssets).bind(this, Compilation_1.Compilation.PROCESS_ASSETS_STAGE_PRE_PROCESS),
|
|
528
|
-
processAssetsStageDerived: __classPrivateFieldGet(this, _Compiler_instances, "m", _Compiler_processAssets).bind(this, Compilation_1.Compilation.PROCESS_ASSETS_STAGE_DERIVED),
|
|
529
|
-
processAssetsStageAdditions: __classPrivateFieldGet(this, _Compiler_instances, "m", _Compiler_processAssets).bind(this, Compilation_1.Compilation.PROCESS_ASSETS_STAGE_ADDITIONS),
|
|
530
|
-
processAssetsStageNone: __classPrivateFieldGet(this, _Compiler_instances, "m", _Compiler_processAssets).bind(this, Compilation_1.Compilation.PROCESS_ASSETS_STAGE_NONE),
|
|
531
|
-
processAssetsStageOptimize: __classPrivateFieldGet(this, _Compiler_instances, "m", _Compiler_processAssets).bind(this, Compilation_1.Compilation.PROCESS_ASSETS_STAGE_OPTIMIZE),
|
|
532
|
-
processAssetsStageOptimizeCount: __classPrivateFieldGet(this, _Compiler_instances, "m", _Compiler_processAssets).bind(this, Compilation_1.Compilation.PROCESS_ASSETS_STAGE_OPTIMIZE_COUNT),
|
|
533
|
-
processAssetsStageOptimizeCompatibility: __classPrivateFieldGet(this, _Compiler_instances, "m", _Compiler_processAssets).bind(this, Compilation_1.Compilation.PROCESS_ASSETS_STAGE_OPTIMIZE_COMPATIBILITY),
|
|
534
|
-
processAssetsStageOptimizeSize: __classPrivateFieldGet(this, _Compiler_instances, "m", _Compiler_processAssets).bind(this, Compilation_1.Compilation.PROCESS_ASSETS_STAGE_OPTIMIZE_SIZE),
|
|
535
|
-
processAssetsStageDevTooling: __classPrivateFieldGet(this, _Compiler_instances, "m", _Compiler_processAssets).bind(this, Compilation_1.Compilation.PROCESS_ASSETS_STAGE_DEV_TOOLING),
|
|
536
|
-
processAssetsStageOptimizeInline: __classPrivateFieldGet(this, _Compiler_instances, "m", _Compiler_processAssets).bind(this, Compilation_1.Compilation.PROCESS_ASSETS_STAGE_OPTIMIZE_INLINE),
|
|
537
|
-
processAssetsStageSummarize: __classPrivateFieldGet(this, _Compiler_instances, "m", _Compiler_processAssets).bind(this, Compilation_1.Compilation.PROCESS_ASSETS_STAGE_SUMMARIZE),
|
|
538
|
-
processAssetsStageOptimizeHash: __classPrivateFieldGet(this, _Compiler_instances, "m", _Compiler_processAssets).bind(this, Compilation_1.Compilation.PROCESS_ASSETS_STAGE_OPTIMIZE_HASH),
|
|
539
|
-
processAssetsStageOptimizeTransfer: __classPrivateFieldGet(this, _Compiler_instances, "m", _Compiler_processAssets).bind(this, Compilation_1.Compilation.PROCESS_ASSETS_STAGE_OPTIMIZE_TRANSFER),
|
|
540
|
-
processAssetsStageAnalyse: __classPrivateFieldGet(this, _Compiler_instances, "m", _Compiler_processAssets).bind(this, Compilation_1.Compilation.PROCESS_ASSETS_STAGE_ANALYSE),
|
|
541
|
-
processAssetsStageReport: __classPrivateFieldGet(this, _Compiler_instances, "m", _Compiler_processAssets).bind(this, Compilation_1.Compilation.PROCESS_ASSETS_STAGE_REPORT),
|
|
542
526
|
afterProcessAssets: __classPrivateFieldGet(this, _Compiler_instances, "m", _Compiler_afterProcessAssets).bind(this),
|
|
543
527
|
// `Compilation` should be created with hook `thisCompilation`, and here is the reason:
|
|
544
528
|
// We know that the hook `thisCompilation` will not be called from a child compiler(it doesn't matter whether the child compiler is created on the Rust or the Node side).
|
|
@@ -564,7 +548,8 @@ _Compiler_instance = new WeakMap(), _Compiler_disabledHooks = new WeakMap(), _Co
|
|
|
564
548
|
runtimeModule: __classPrivateFieldGet(this, _Compiler_instances, "m", _Compiler_runtimeModule).bind(this)
|
|
565
549
|
}, {
|
|
566
550
|
registerCompilerCompilationTaps: __classPrivateFieldGet(this, _Compiler_instances, "m", _Compiler_registerCompilerCompilationTaps).bind(this),
|
|
567
|
-
registerCompilerMakeTaps: __classPrivateFieldGet(this, _Compiler_instances, "m", _Compiler_registerCompilerMakeTaps).bind(this)
|
|
551
|
+
registerCompilerMakeTaps: __classPrivateFieldGet(this, _Compiler_instances, "m", _Compiler_registerCompilerMakeTaps).bind(this),
|
|
552
|
+
registerCompilationProcessAssetsTaps: __classPrivateFieldGet(this, _Compiler_instances, "m", _Compiler_registerCompilationProcessAssetsTaps).bind(this)
|
|
568
553
|
}, (0, fileSystem_1.createThreadsafeNodeFSFromRaw)(this.outputFileSystem), loader_runner_1.runLoaders.bind(undefined, this)), "f");
|
|
569
554
|
callback(null, __classPrivateFieldGet(this, _Compiler_instance, "f"));
|
|
570
555
|
}, _Compiler_updateDisabledHooks = function _Compiler_updateDisabledHooks(callback) {
|
|
@@ -578,22 +563,6 @@ _Compiler_instance = new WeakMap(), _Compiler_disabledHooks = new WeakMap(), _Co
|
|
|
578
563
|
emit: this.hooks.emit,
|
|
579
564
|
assetEmitted: this.hooks.assetEmitted,
|
|
580
565
|
afterEmit: this.hooks.afterEmit,
|
|
581
|
-
processAssetsStageAdditional: this.compilation.__internal_getProcessAssetsHookByStage(Compilation_1.Compilation.PROCESS_ASSETS_STAGE_ADDITIONAL),
|
|
582
|
-
processAssetsStagePreProcess: this.compilation.__internal_getProcessAssetsHookByStage(Compilation_1.Compilation.PROCESS_ASSETS_STAGE_PRE_PROCESS),
|
|
583
|
-
processAssetsStageDerived: this.compilation.__internal_getProcessAssetsHookByStage(Compilation_1.Compilation.PROCESS_ASSETS_STAGE_DERIVED),
|
|
584
|
-
processAssetsStageAdditions: this.compilation.__internal_getProcessAssetsHookByStage(Compilation_1.Compilation.PROCESS_ASSETS_STAGE_ADDITIONS),
|
|
585
|
-
processAssetsStageNone: this.compilation.__internal_getProcessAssetsHookByStage(Compilation_1.Compilation.PROCESS_ASSETS_STAGE_NONE),
|
|
586
|
-
processAssetsStageOptimize: this.compilation.__internal_getProcessAssetsHookByStage(Compilation_1.Compilation.PROCESS_ASSETS_STAGE_OPTIMIZE),
|
|
587
|
-
processAssetsStageOptimizeCount: this.compilation.__internal_getProcessAssetsHookByStage(Compilation_1.Compilation.PROCESS_ASSETS_STAGE_OPTIMIZE_COUNT),
|
|
588
|
-
processAssetsStageOptimizeCompatibility: this.compilation.__internal_getProcessAssetsHookByStage(Compilation_1.Compilation.PROCESS_ASSETS_STAGE_OPTIMIZE_COMPATIBILITY),
|
|
589
|
-
processAssetsStageOptimizeSize: this.compilation.__internal_getProcessAssetsHookByStage(Compilation_1.Compilation.PROCESS_ASSETS_STAGE_OPTIMIZE_SIZE),
|
|
590
|
-
processAssetsStageDevTooling: this.compilation.__internal_getProcessAssetsHookByStage(Compilation_1.Compilation.PROCESS_ASSETS_STAGE_DEV_TOOLING),
|
|
591
|
-
processAssetsStageOptimizeInline: this.compilation.__internal_getProcessAssetsHookByStage(Compilation_1.Compilation.PROCESS_ASSETS_STAGE_OPTIMIZE_INLINE),
|
|
592
|
-
processAssetsStageSummarize: this.compilation.__internal_getProcessAssetsHookByStage(Compilation_1.Compilation.PROCESS_ASSETS_STAGE_SUMMARIZE),
|
|
593
|
-
processAssetsStageOptimizeHash: this.compilation.__internal_getProcessAssetsHookByStage(Compilation_1.Compilation.PROCESS_ASSETS_STAGE_OPTIMIZE_HASH),
|
|
594
|
-
processAssetsStageOptimizeTransfer: this.compilation.__internal_getProcessAssetsHookByStage(Compilation_1.Compilation.PROCESS_ASSETS_STAGE_OPTIMIZE_TRANSFER),
|
|
595
|
-
processAssetsStageAnalyse: this.compilation.__internal_getProcessAssetsHookByStage(Compilation_1.Compilation.PROCESS_ASSETS_STAGE_ANALYSE),
|
|
596
|
-
processAssetsStageReport: this.compilation.__internal_getProcessAssetsHookByStage(Compilation_1.Compilation.PROCESS_ASSETS_STAGE_REPORT),
|
|
597
566
|
afterProcessAssets: this.compilation.hooks.afterProcessAssets,
|
|
598
567
|
optimizeTree: this.compilation.hooks.optimizeTree,
|
|
599
568
|
finishModules: this.compilation.hooks.finishModules,
|
|
@@ -650,11 +619,6 @@ _Compiler_instance = new WeakMap(), _Compiler_disabledHooks = new WeakMap(), _Co
|
|
|
650
619
|
const normalized = (0, normalization_1.normalizeJsModule)(module);
|
|
651
620
|
this.compilation.hooks.buildModule.call(normalized);
|
|
652
621
|
__classPrivateFieldGet(this, _Compiler_instances, "m", _Compiler_updateDisabledHooks).call(this);
|
|
653
|
-
}, _Compiler_processAssets = async function _Compiler_processAssets(stage) {
|
|
654
|
-
await this.compilation
|
|
655
|
-
.__internal_getProcessAssetsHookByStage(stage)
|
|
656
|
-
.promise(this.compilation.assets);
|
|
657
|
-
__classPrivateFieldGet(this, _Compiler_instances, "m", _Compiler_updateDisabledHooks).call(this);
|
|
658
622
|
}, _Compiler_afterProcessAssets = async function _Compiler_afterProcessAssets() {
|
|
659
623
|
await this.compilation.hooks.afterProcessAssets.promise(this.compilation.assets);
|
|
660
624
|
__classPrivateFieldGet(this, _Compiler_instances, "m", _Compiler_updateDisabledHooks).call(this);
|
|
@@ -810,41 +774,79 @@ _Compiler_instance = new WeakMap(), _Compiler_disabledHooks = new WeakMap(), _Co
|
|
|
810
774
|
}
|
|
811
775
|
const executeResult = __webpack_require__(entry);
|
|
812
776
|
__classPrivateFieldGet(this, _Compiler_moduleExecutionResultsMap, "f").set(id, executeResult);
|
|
777
|
+
}, _Compiler_decorateUpdateDisabledHooks = function _Compiler_decorateUpdateDisabledHooks(jsTaps) {
|
|
778
|
+
if (jsTaps.length > 0) {
|
|
779
|
+
const last = jsTaps[jsTaps.length - 1];
|
|
780
|
+
const old = last.function;
|
|
781
|
+
last.function = async () => {
|
|
782
|
+
await old();
|
|
783
|
+
__classPrivateFieldGet(this, _Compiler_instances, "m", _Compiler_updateDisabledHooks).call(this);
|
|
784
|
+
};
|
|
785
|
+
}
|
|
813
786
|
}, _Compiler_registerCompilerCompilationTaps = function _Compiler_registerCompilerCompilationTaps(stages) {
|
|
814
787
|
if (!this.hooks.compilation.isUsed())
|
|
815
788
|
return [];
|
|
816
|
-
const breakpoints = [
|
|
789
|
+
const breakpoints = [liteTapable.minStage, ...stages, liteTapable.maxStage];
|
|
817
790
|
const jsTaps = [];
|
|
818
791
|
for (let i = 0; i < breakpoints.length - 1; i++) {
|
|
819
|
-
const
|
|
792
|
+
const from = breakpoints[i];
|
|
793
|
+
const to = breakpoints[i + 1];
|
|
794
|
+
const stageRange = [from, to];
|
|
795
|
+
const queried = this.hooks.compilation.queryStageRange(stageRange);
|
|
796
|
+
if (!queried.isUsed())
|
|
797
|
+
continue;
|
|
820
798
|
jsTaps.push({
|
|
821
|
-
function: (
|
|
822
|
-
|
|
799
|
+
function: () => {
|
|
800
|
+
queried.call(this.compilation, {
|
|
823
801
|
normalModuleFactory: this.compilation.normalModuleFactory
|
|
824
802
|
});
|
|
825
|
-
if (i + 1 >= breakpoints.length - 1)
|
|
826
|
-
__classPrivateFieldGet(this, _Compiler_instances, "m", _Compiler_updateDisabledHooks).call(this);
|
|
827
803
|
},
|
|
828
|
-
stage:
|
|
804
|
+
stage: liteTapable.safeStage(from + 1)
|
|
829
805
|
});
|
|
830
806
|
}
|
|
807
|
+
__classPrivateFieldGet(this, _Compiler_instances, "m", _Compiler_decorateUpdateDisabledHooks).call(this, jsTaps);
|
|
831
808
|
return jsTaps;
|
|
832
809
|
}, _Compiler_registerCompilerMakeTaps = function _Compiler_registerCompilerMakeTaps(stages) {
|
|
833
810
|
if (!this.hooks.make.isUsed())
|
|
834
811
|
return [];
|
|
835
|
-
const breakpoints = [
|
|
812
|
+
const breakpoints = [liteTapable.minStage, ...stages, liteTapable.maxStage];
|
|
813
|
+
const jsTaps = [];
|
|
814
|
+
for (let i = 0; i < breakpoints.length - 1; i++) {
|
|
815
|
+
const from = breakpoints[i];
|
|
816
|
+
const to = breakpoints[i + 1];
|
|
817
|
+
const stageRange = [from, to];
|
|
818
|
+
const queried = this.hooks.make.queryStageRange(stageRange);
|
|
819
|
+
if (!queried.isUsed())
|
|
820
|
+
continue;
|
|
821
|
+
jsTaps.push({
|
|
822
|
+
function: async () => {
|
|
823
|
+
await queried.promise(this.compilation);
|
|
824
|
+
},
|
|
825
|
+
stage: liteTapable.safeStage(from + 1)
|
|
826
|
+
});
|
|
827
|
+
}
|
|
828
|
+
__classPrivateFieldGet(this, _Compiler_instances, "m", _Compiler_decorateUpdateDisabledHooks).call(this, jsTaps);
|
|
829
|
+
return jsTaps;
|
|
830
|
+
}, _Compiler_registerCompilationProcessAssetsTaps = function _Compiler_registerCompilationProcessAssetsTaps(stages) {
|
|
831
|
+
if (!this.compilation.hooks.processAssets.isUsed())
|
|
832
|
+
return [];
|
|
833
|
+
const breakpoints = [liteTapable.minStage, ...stages, liteTapable.maxStage];
|
|
836
834
|
const jsTaps = [];
|
|
837
835
|
for (let i = 0; i < breakpoints.length - 1; i++) {
|
|
838
|
-
const
|
|
836
|
+
const from = breakpoints[i];
|
|
837
|
+
const to = breakpoints[i + 1];
|
|
838
|
+
const stageRange = [from, to];
|
|
839
|
+
const queried = this.compilation.hooks.processAssets.queryStageRange(stageRange);
|
|
840
|
+
if (!queried.isUsed())
|
|
841
|
+
continue;
|
|
839
842
|
jsTaps.push({
|
|
840
|
-
function: async (
|
|
841
|
-
await
|
|
842
|
-
if (i + 1 >= breakpoints.length - 1)
|
|
843
|
-
__classPrivateFieldGet(this, _Compiler_instances, "m", _Compiler_updateDisabledHooks).call(this);
|
|
843
|
+
function: async () => {
|
|
844
|
+
await queried.promise(this.compilation.assets);
|
|
844
845
|
},
|
|
845
|
-
stage:
|
|
846
|
+
stage: liteTapable.safeStage(from + 1)
|
|
846
847
|
});
|
|
847
848
|
}
|
|
849
|
+
__classPrivateFieldGet(this, _Compiler_instances, "m", _Compiler_decorateUpdateDisabledHooks).call(this, jsTaps);
|
|
848
850
|
return jsTaps;
|
|
849
851
|
}, _Compiler_newCompilation = function _Compiler_newCompilation(native) {
|
|
850
852
|
const compilation = new Compilation_1.Compilation(this, native);
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { type JsChunkGroup, type JsCompilation } from "@rspack/binding";
|
|
2
|
+
import { ChunkGroup } from "./ChunkGroup";
|
|
3
|
+
import { Chunk } from "./Chunk";
|
|
4
|
+
export declare class Entrypoint extends ChunkGroup {
|
|
5
|
+
static __from_binding(chunk: JsChunkGroup, compilation: JsCompilation): Entrypoint;
|
|
6
|
+
protected constructor(inner: JsChunkGroup, compilation: JsCompilation);
|
|
7
|
+
getRuntimeChunk(): Chunk | null;
|
|
8
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Entrypoint = void 0;
|
|
4
|
+
const binding_1 = require("@rspack/binding");
|
|
5
|
+
const ChunkGroup_1 = require("./ChunkGroup");
|
|
6
|
+
const Chunk_1 = require("./Chunk");
|
|
7
|
+
class Entrypoint extends ChunkGroup_1.ChunkGroup {
|
|
8
|
+
static __from_binding(chunk, compilation) {
|
|
9
|
+
return new Entrypoint(chunk, compilation);
|
|
10
|
+
}
|
|
11
|
+
constructor(inner, compilation) {
|
|
12
|
+
super(inner, compilation);
|
|
13
|
+
}
|
|
14
|
+
getRuntimeChunk() {
|
|
15
|
+
const c = (0, binding_1.__entrypoint_inner_get_runtime_chunk)(this.__internal_inner_ukey(), this.__internal_inner_compilation());
|
|
16
|
+
if (c)
|
|
17
|
+
return Chunk_1.Chunk.__from_binding(c, this.__internal_inner_compilation());
|
|
18
|
+
return null;
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
exports.Entrypoint = Entrypoint;
|
package/dist/Watching.d.ts
CHANGED
|
@@ -33,6 +33,7 @@ export declare class Watching {
|
|
|
33
33
|
watch(files: Iterable<string>, dirs: Iterable<string>, missing: Iterable<string>): void;
|
|
34
34
|
close(callback?: () => void): void;
|
|
35
35
|
invalidate(callback?: Callback<Error, void>): void;
|
|
36
|
+
lazyCompilationInvalidate(files: Set<string>): void;
|
|
36
37
|
/**
|
|
37
38
|
* The reason why this is _done instead of #done, is that in Webpack,
|
|
38
39
|
* it will rewrite this function to another function
|
package/dist/Watching.js
CHANGED
|
@@ -150,6 +150,9 @@ class Watching {
|
|
|
150
150
|
this.onChange();
|
|
151
151
|
__classPrivateFieldGet(this, _Watching_instances, "m", _Watching_invalidate).call(this);
|
|
152
152
|
}
|
|
153
|
+
lazyCompilationInvalidate(files) {
|
|
154
|
+
__classPrivateFieldGet(this, _Watching_instances, "m", _Watching_invalidate).call(this, new Map(), new Map(), files, new Set());
|
|
155
|
+
}
|
|
153
156
|
_done(error, compilation) {
|
|
154
157
|
this.running = false;
|
|
155
158
|
let stats = undefined;
|
|
@@ -50,6 +50,7 @@ export * from "./HtmlRspackPlugin";
|
|
|
50
50
|
export * from "./CopyRspackPlugin";
|
|
51
51
|
export * from "./SwcJsMinimizerPlugin";
|
|
52
52
|
export * from "./SwcCssMinimizerPlugin";
|
|
53
|
+
export * from "./lazy-compilation/plugin";
|
|
53
54
|
import { RawBuiltins, RawCssModulesConfig } from "@rspack/binding";
|
|
54
55
|
import { RspackOptionsNormalized } from "..";
|
|
55
56
|
type BuiltinsCssConfig = {
|
|
@@ -68,6 +68,7 @@ __exportStar(require("./HtmlRspackPlugin"), exports);
|
|
|
68
68
|
__exportStar(require("./CopyRspackPlugin"), exports);
|
|
69
69
|
__exportStar(require("./SwcJsMinimizerPlugin"), exports);
|
|
70
70
|
__exportStar(require("./SwcCssMinimizerPlugin"), exports);
|
|
71
|
+
__exportStar(require("./lazy-compilation/plugin"), exports);
|
|
71
72
|
function resolveTreeShaking(treeShaking, production) {
|
|
72
73
|
return treeShaking !== undefined
|
|
73
74
|
? treeShaking.toString()
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
import type { Compiler } from "../..";
|
|
3
|
+
/**
|
|
4
|
+
* @param {Omit<LazyCompilationDefaultBackendOptions, "client"> & { client: NonNullable<LazyCompilationDefaultBackendOptions["client"]>}} options additional options for the backend
|
|
5
|
+
* @returns {BackendHandler} backend
|
|
6
|
+
*/
|
|
7
|
+
declare const getBackend: (options: any) => (compiler: Compiler, callback: (err: any, obj?: {
|
|
8
|
+
dispose: (callback: (err: any) => void) => void;
|
|
9
|
+
module: (args: {
|
|
10
|
+
module: string;
|
|
11
|
+
path: string;
|
|
12
|
+
}) => {
|
|
13
|
+
data: string;
|
|
14
|
+
client: string;
|
|
15
|
+
active: boolean;
|
|
16
|
+
};
|
|
17
|
+
} | undefined) => void) => void;
|
|
18
|
+
export default getBackend;
|
|
19
|
+
export declare function dispose(callback: any): void;
|
|
20
|
+
export declare function moduleImpl(args: {
|
|
21
|
+
module: string;
|
|
22
|
+
path: string;
|
|
23
|
+
}): {
|
|
24
|
+
active: boolean;
|
|
25
|
+
data: string;
|
|
26
|
+
client: string;
|
|
27
|
+
};
|
|
@@ -0,0 +1,144 @@
|
|
|
1
|
+
/*
|
|
2
|
+
MIT License http://www.opensource.org/licenses/mit-license.php
|
|
3
|
+
Author Tobias Koppers @sokra
|
|
4
|
+
*/
|
|
5
|
+
"use strict";
|
|
6
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
|
+
exports.moduleImpl = exports.dispose = void 0;
|
|
8
|
+
/**
|
|
9
|
+
* @param {Omit<LazyCompilationDefaultBackendOptions, "client"> & { client: NonNullable<LazyCompilationDefaultBackendOptions["client"]>}} options additional options for the backend
|
|
10
|
+
* @returns {BackendHandler} backend
|
|
11
|
+
*/
|
|
12
|
+
const getBackend = (options) => (compiler, callback) => {
|
|
13
|
+
const logger = compiler.getInfrastructureLogger("LazyCompilationBackend");
|
|
14
|
+
const activeModules = new Map();
|
|
15
|
+
const filesByKey = new Map();
|
|
16
|
+
const prefix = "/lazy-compilation-using-";
|
|
17
|
+
const isHttps = options.protocol === "https" ||
|
|
18
|
+
(typeof options.server === "object" &&
|
|
19
|
+
("key" in options.server || "pfx" in options.server));
|
|
20
|
+
const createServer = typeof options.server === "function"
|
|
21
|
+
? options.server
|
|
22
|
+
: (() => {
|
|
23
|
+
const http = isHttps ? require("https") : require("http");
|
|
24
|
+
return http.createServer.bind(http, options.server);
|
|
25
|
+
})();
|
|
26
|
+
const listen = typeof options.listen === "function"
|
|
27
|
+
? options.listen
|
|
28
|
+
: (server) => {
|
|
29
|
+
let listen = options.listen;
|
|
30
|
+
if (typeof listen === "object" && !("port" in listen))
|
|
31
|
+
listen = { ...listen, port: undefined };
|
|
32
|
+
server.listen(listen);
|
|
33
|
+
};
|
|
34
|
+
const protocol = options.protocol || (isHttps ? "https" : "http");
|
|
35
|
+
const requestListener = (req, res) => {
|
|
36
|
+
const keys = req.url.slice(prefix.length).split("@");
|
|
37
|
+
req.socket.on("close", () => {
|
|
38
|
+
setTimeout(() => {
|
|
39
|
+
for (const key of keys) {
|
|
40
|
+
const oldValue = activeModules.get(key) || 0;
|
|
41
|
+
activeModules.set(key, oldValue - 1);
|
|
42
|
+
if (oldValue === 1) {
|
|
43
|
+
logger.log(`${key} is no longer in use. Next compilation will skip this module.`);
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
}, 120000);
|
|
47
|
+
});
|
|
48
|
+
req.socket.setNoDelay(true);
|
|
49
|
+
res.writeHead(200, {
|
|
50
|
+
"content-type": "text/event-stream",
|
|
51
|
+
"Access-Control-Allow-Origin": "*",
|
|
52
|
+
"Access-Control-Allow-Methods": "*",
|
|
53
|
+
"Access-Control-Allow-Headers": "*"
|
|
54
|
+
});
|
|
55
|
+
res.write("\n");
|
|
56
|
+
const moduleActivated = [];
|
|
57
|
+
for (const key of keys) {
|
|
58
|
+
const oldValue = activeModules.get(key) || 0;
|
|
59
|
+
activeModules.set(key, oldValue + 1);
|
|
60
|
+
if (oldValue === 0) {
|
|
61
|
+
logger.log(`${key} is now in use and will be compiled.`);
|
|
62
|
+
moduleActivated.push(key);
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
if (moduleActivated.length && compiler.watching) {
|
|
66
|
+
compiler.watching.lazyCompilationInvalidate(new Set(moduleActivated.map(key => filesByKey.get(key))));
|
|
67
|
+
}
|
|
68
|
+
};
|
|
69
|
+
const server = createServer();
|
|
70
|
+
server.on("request", requestListener);
|
|
71
|
+
let isClosing = false;
|
|
72
|
+
const sockets = new Set();
|
|
73
|
+
server.on("connection", socket => {
|
|
74
|
+
sockets.add(socket);
|
|
75
|
+
socket.on("close", () => {
|
|
76
|
+
sockets.delete(socket);
|
|
77
|
+
});
|
|
78
|
+
if (isClosing)
|
|
79
|
+
socket.destroy();
|
|
80
|
+
});
|
|
81
|
+
server.on("clientError", e => {
|
|
82
|
+
if (e.message !== "Server is disposing")
|
|
83
|
+
logger.warn(e);
|
|
84
|
+
});
|
|
85
|
+
server.on("listening", (err) => {
|
|
86
|
+
if (err)
|
|
87
|
+
return callback(err);
|
|
88
|
+
const addr = server.address();
|
|
89
|
+
if (typeof addr === "string")
|
|
90
|
+
throw new Error("addr must not be a string");
|
|
91
|
+
const urlBase = addr.address === "::" || addr.address === "0.0.0.0"
|
|
92
|
+
? `${protocol}://localhost:${addr.port}`
|
|
93
|
+
: addr.family === "IPv6"
|
|
94
|
+
? `${protocol}://[${addr.address}]:${addr.port}`
|
|
95
|
+
: `${protocol}://${addr.address}:${addr.port}`;
|
|
96
|
+
logger.log(`Server-Sent-Events server for lazy compilation open at ${urlBase}.`);
|
|
97
|
+
const result = {
|
|
98
|
+
dispose(callback) {
|
|
99
|
+
isClosing = true;
|
|
100
|
+
// Removing the listener is a workaround for a memory leak in node.js
|
|
101
|
+
server.off("request", requestListener);
|
|
102
|
+
server.close(err => {
|
|
103
|
+
console.log("server shutdown");
|
|
104
|
+
callback(err);
|
|
105
|
+
});
|
|
106
|
+
for (const socket of sockets) {
|
|
107
|
+
socket.destroy(new Error("Server is disposing"));
|
|
108
|
+
}
|
|
109
|
+
},
|
|
110
|
+
module({ module: originalModule, path }) {
|
|
111
|
+
const key = `${encodeURIComponent(originalModule.replace(/\\/g, "/").replace(/@/g, "_")).replace(/%(2F|3A|24|26|2B|2C|3B|3D|3A)/g, decodeURIComponent)}`;
|
|
112
|
+
filesByKey.set(key, path);
|
|
113
|
+
const active = activeModules.get(key) > 0;
|
|
114
|
+
return {
|
|
115
|
+
client: `${options.client}?${encodeURIComponent(urlBase + prefix)}`,
|
|
116
|
+
data: key,
|
|
117
|
+
active
|
|
118
|
+
};
|
|
119
|
+
}
|
|
120
|
+
};
|
|
121
|
+
state.module = result.module;
|
|
122
|
+
state.dispose = result.dispose;
|
|
123
|
+
callback(null, result);
|
|
124
|
+
});
|
|
125
|
+
listen(server);
|
|
126
|
+
};
|
|
127
|
+
exports.default = getBackend;
|
|
128
|
+
function unimplemented() {
|
|
129
|
+
throw new Error("access before initialization");
|
|
130
|
+
}
|
|
131
|
+
const state = {
|
|
132
|
+
module: unimplemented,
|
|
133
|
+
dispose: unimplemented
|
|
134
|
+
};
|
|
135
|
+
function dispose(callback) {
|
|
136
|
+
state.dispose(callback);
|
|
137
|
+
state.dispose = unimplemented;
|
|
138
|
+
state.module = unimplemented;
|
|
139
|
+
}
|
|
140
|
+
exports.dispose = dispose;
|
|
141
|
+
function moduleImpl(args) {
|
|
142
|
+
return state.module(args);
|
|
143
|
+
}
|
|
144
|
+
exports.moduleImpl = moduleImpl;
|