diff --git a/lib/Compiler.js b/lib/Compiler.js index 58c30cf9911..d5f27fc0189 100644 --- a/lib/Compiler.js +++ b/lib/Compiler.js @@ -266,8 +266,8 @@ class Compiler { /** @type {LoggingFunction | undefined} */ this.infrastructureLogger = undefined; - /** @type {PlatformTargetProperties} */ - this.target = { + /** @type {Readonly} */ + this.platform = { web: null, browser: null, webworker: null, @@ -313,20 +313,6 @@ class Compiler { this._assetEmittingPreviousFiles = new Set(); } - /** - * @returns {Readonly} platform target properties - */ - getPlatformTargetInfo() { - return this.target; - } - - /** - * @param {PlatformTargetProperties} platform platform target properties - */ - setPlatformTargetInfo(platform) { - this.target = platform; - } - /** * @param {string} name cache name * @returns {CacheFacade} the cache facade instance diff --git a/lib/PlatformPlugin.js b/lib/PlatformPlugin.js index d77ce370da8..ae601ae8b45 100644 --- a/lib/PlatformPlugin.js +++ b/lib/PlatformPlugin.js @@ -28,10 +28,10 @@ class PlatformPlugin { */ apply(compiler) { compiler.hooks.environment.tap("PlatformPlugin", () => { - compiler.setPlatformTargetInfo({ - ...compiler.getPlatformTargetInfo(), + compiler.platform = { + ...compiler.platform, ...this.platform - }); + }; }); } } diff --git a/lib/webpack.js b/lib/webpack.js index e5ac2b0f1f8..faeb1624dc4 100644 --- a/lib/webpack.js +++ b/lib/webpack.js @@ -82,7 +82,7 @@ const createCompiler = rawOptions => { const platform = applyWebpackOptionsDefaultsAndResolvePlatformTargetProperties(options); if (platform) { - compiler.setPlatformTargetInfo(platform); + compiler.platform = platform; } compiler.hooks.environment.call(); compiler.hooks.afterEnvironment.call(); diff --git a/test/Compiler.test.js b/test/Compiler.test.js index c695f90b5a6..084ef30cd98 100644 --- a/test/Compiler.test.js +++ b/test/Compiler.test.js @@ -227,7 +227,7 @@ describe("Compiler", () => { } }); it("default platform info", done => { - const platform = compiler.getPlatformTargetInfo(); + const platform = compiler.platform; expect(platform.web).toBe(true); expect(platform.node).toBe(false); done(); @@ -306,7 +306,7 @@ describe("Compiler", () => { new (require("../lib/PlatformPlugin"))({ node: true }), compiler => { compiler.hooks.afterEnvironment.tap("test", () => { - const platform = compiler.getPlatformTargetInfo(); + const platform = compiler.platform; expect(platform.node).toBe(true); expect(platform.web).toBe(true); }); diff --git a/types.d.ts b/types.d.ts index 0a9eb2a478b..85a19592f34 100644 --- a/types.d.ts +++ b/types.d.ts @@ -2308,7 +2308,7 @@ declare class Compiler { fsStartTime?: number; resolverFactory: ResolverFactory; infrastructureLogger?: (arg0: string, arg1: LogTypeEnum, arg2: any[]) => void; - target: PlatformTargetProperties; + platform: Readonly; options: WebpackOptionsNormalized; context: string; requestShortener: RequestShortener; @@ -2325,8 +2325,6 @@ declare class Compiler { running: boolean; idle: boolean; watchMode: boolean; - getPlatformTargetInfo(): Readonly; - setPlatformTargetInfo(platform: PlatformTargetProperties): void; getCache(name: string): CacheFacade; getInfrastructureLogger(name: string | (() => string)): WebpackLogger; watch(watchOptions: WatchOptions, handler: RunCallback): Watching;