diff --git a/.changeset/fast-streets-learn.md b/.changeset/fast-streets-learn.md new file mode 100644 index 0000000000..538aa0a81d --- /dev/null +++ b/.changeset/fast-streets-learn.md @@ -0,0 +1,5 @@ +--- +"@lynx-js/template-webpack-plugin": minor +--- + +Rename `lepus` to `mainThreadAssets` in `beforeEmit` hook. diff --git a/packages/webpack/template-webpack-plugin/etc/template-webpack-plugin.api.md b/packages/webpack/template-webpack-plugin/etc/template-webpack-plugin.api.md index 79bf979664..b98055c9dc 100644 --- a/packages/webpack/template-webpack-plugin/etc/template-webpack-plugin.api.md +++ b/packages/webpack/template-webpack-plugin/etc/template-webpack-plugin.api.md @@ -137,7 +137,7 @@ export interface TemplateHooks { debugInfo: string; template: Buffer; outputName: string; - lepus: Asset[]; + mainThreadAssets: Asset[]; }>; // @alpha beforeEncode: AsyncSeriesWaterfallHook<{ diff --git a/packages/webpack/template-webpack-plugin/src/LynxTemplatePlugin.ts b/packages/webpack/template-webpack-plugin/src/LynxTemplatePlugin.ts index 19c3385e97..f7bd9e5744 100644 --- a/packages/webpack/template-webpack-plugin/src/LynxTemplatePlugin.ts +++ b/packages/webpack/template-webpack-plugin/src/LynxTemplatePlugin.ts @@ -108,7 +108,7 @@ export interface TemplateHooks { debugInfo: string; template: Buffer; outputName: string; - lepus: Asset[]; + mainThreadAssets: Asset[]; }>; /** @@ -796,11 +796,11 @@ class LynxTemplatePluginImpl { }, lepusCode: { // TODO: support multiple lepus chunks - root: assetsInfoByGroups.lepus[0], + root: assetsInfoByGroups.mainThread[0], chunks: [], }, manifest: Object.fromEntries( - assetsInfoByGroups.js.map(asset => { + assetsInfoByGroups.backgroundThread.map(asset => { return [asset.name, asset.source.source().toString()]; }), ), @@ -896,9 +896,8 @@ class LynxTemplatePluginImpl { debugInfo, template: buffer, outputName: filename, - lepus: [lepusCode.root, ...encodeData.lepusCode.chunks].filter(i => - i !== undefined - ), + mainThreadAssets: [lepusCode.root, ...encodeData.lepusCode.chunks] + .filter(i => i !== undefined), }); compilation.emitAsset(filename, new RawSource(template, false)); @@ -980,11 +979,11 @@ class LynxTemplatePluginImpl { ): AssetsInformationByGroups { const assets: AssetsInformationByGroups = { // Will contain all js and mjs files - js: [], + backgroundThread: [], // Will contain all css files css: [], // Will contain all lepus files - lepus: [], + mainThread: [], }; // Extract paths to .js, .lepus and .css files from the current compilation @@ -1008,7 +1007,7 @@ class LynxTemplatePluginImpl { const asset = compilation.getAsset(filename)!; if (asset.info['lynx:main-thread']) { - assets.lepus.push(asset); + assets.mainThread.push(asset); return; } @@ -1017,7 +1016,7 @@ class LynxTemplatePluginImpl { // ext will contain .js or .css, because .mjs recognizes as .js const ext = (extMatch[1] === 'mjs' ? 'js' : extMatch[1]) as 'js' | 'css'; - assets[ext].push(asset); + assets[ext === 'js' ? 'backgroundThread' : 'css'].push(asset); }); return assets; @@ -1027,9 +1026,9 @@ class LynxTemplatePluginImpl { } interface AssetsInformationByGroups { - js: Asset[]; + backgroundThread: Asset[]; css: Asset[]; - lepus: Asset[]; + mainThread: Asset[]; } export function isDebug(): boolean { diff --git a/packages/webpack/template-webpack-plugin/test/cases/hooks/before-emit-filename-hash/webpack.config.js b/packages/webpack/template-webpack-plugin/test/cases/hooks/before-emit-filename-hash/webpack.config.js index 105da8226a..0405ba0a47 100644 --- a/packages/webpack/template-webpack-plugin/test/cases/hooks/before-emit-filename-hash/webpack.config.js +++ b/packages/webpack/template-webpack-plugin/test/cases/hooks/before-emit-filename-hash/webpack.config.js @@ -18,12 +18,12 @@ export default { hooks.beforeEmit.tap( 'test', - ({ debugInfo, lepus, outputName, template }) => { + ({ debugInfo, mainThreadAssets, outputName, template }) => { expect(outputName).toMatch(/main\.template\.[0-9a-fA-F]{8}\.js/); return { template, - lepus, + mainThreadAssets, debugInfo, }; }, diff --git a/packages/webpack/template-webpack-plugin/test/cases/hooks/before-emit-filename/webpack.config.js b/packages/webpack/template-webpack-plugin/test/cases/hooks/before-emit-filename/webpack.config.js index ab78034496..ae43cbc14b 100644 --- a/packages/webpack/template-webpack-plugin/test/cases/hooks/before-emit-filename/webpack.config.js +++ b/packages/webpack/template-webpack-plugin/test/cases/hooks/before-emit-filename/webpack.config.js @@ -18,12 +18,12 @@ export default { hooks.beforeEmit.tap( 'test', - ({ debugInfo, lepus, outputName, template }) => { + ({ debugInfo, mainThreadAssets, outputName, template }) => { expect(outputName).toBe('main.template.js'); return { template, - lepus, + mainThreadAssets, debugInfo, }; }, diff --git a/packages/webpack/template-webpack-plugin/test/cases/hooks/before-emit-lepus/webpack.config.js b/packages/webpack/template-webpack-plugin/test/cases/hooks/before-emit-lepus/webpack.config.js index 3b729436b8..f1664d6e02 100644 --- a/packages/webpack/template-webpack-plugin/test/cases/hooks/before-emit-lepus/webpack.config.js +++ b/packages/webpack/template-webpack-plugin/test/cases/hooks/before-emit-lepus/webpack.config.js @@ -60,12 +60,12 @@ export default { hooks.beforeEmit.tap( 'test', - ({ debugInfo, lepus, template }) => { - expect(lepus.length).toBe(2); + ({ debugInfo, mainThreadAssets, template }) => { + expect(mainThreadAssets.length).toBe(2); return { template, - lepus, + mainThreadAssets, debugInfo, }; }, diff --git a/packages/webpack/template-webpack-plugin/test/cases/hooks/before-emit/webpack.config.js b/packages/webpack/template-webpack-plugin/test/cases/hooks/before-emit/webpack.config.js index 6b430601f0..178e16d570 100644 --- a/packages/webpack/template-webpack-plugin/test/cases/hooks/before-emit/webpack.config.js +++ b/packages/webpack/template-webpack-plugin/test/cases/hooks/before-emit/webpack.config.js @@ -14,10 +14,10 @@ export default { hooks.beforeEmit.tap( 'test', - ({ debugInfo, lepus }) => { + ({ debugInfo, mainThreadAssets }) => { return { template: Buffer.from('Hello BeforeEmit'), - lepus, + mainThreadAssets, debugInfo, }; },