Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/fast-streets-learn.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@lynx-js/template-webpack-plugin": minor
---

Rename `lepus` to `mainThreadAssets` in `beforeEmit` hook.
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ export interface TemplateHooks {
debugInfo: string;
template: Buffer;
outputName: string;
lepus: Asset[];
mainThreadAssets: Asset[];
}>;
// @alpha
beforeEncode: AsyncSeriesWaterfallHook<{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ export interface TemplateHooks {
debugInfo: string;
template: Buffer;
outputName: string;
lepus: Asset[];
mainThreadAssets: Asset[];
}>;

/**
Expand Down Expand Up @@ -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()];
}),
),
Expand Down Expand Up @@ -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));
Expand Down Expand Up @@ -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
Expand All @@ -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;
}

Expand All @@ -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;
Expand All @@ -1027,9 +1026,9 @@ class LynxTemplatePluginImpl {
}

interface AssetsInformationByGroups {
js: Asset[];
backgroundThread: Asset[];
css: Asset[];
lepus: Asset[];
mainThread: Asset[];
}

export function isDebug(): boolean {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
};
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
};
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
};
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@ export default {

hooks.beforeEmit.tap(
'test',
({ debugInfo, lepus }) => {
({ debugInfo, mainThreadAssets }) => {
return {
template: Buffer.from('Hello BeforeEmit'),
lepus,
mainThreadAssets,
debugInfo,
};
},
Expand Down
Loading