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/famous-dryers-play.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@lynx-js/template-webpack-plugin": patch
---

Fix source-maps (`.js.map` files) were not accessible in the `compiler.hooks.afterEmit` hook.
5 changes: 5 additions & 0 deletions .changeset/seven-cougars-look.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@lynx-js/template-webpack-plugin": patch
---

Fix incorrect hash of `background.[contenthash].js` in `.lynx.bundle` files.
Original file line number Diff line number Diff line change
Expand Up @@ -130,14 +130,13 @@ export class LynxEncodePluginImpl {
const { manifest } = encodeData;

if (!isDebug() && !isDev && !isRsdoctor()) {
templateHooks.beforeEmit.tap(this.name, (args) => {
compiler.hooks.afterEmit.tap(this.name, () => {
this.deleteDebuggingAssets(compilation, [
encodeData.lepusCode.root,
...encodeData.lepusCode.chunks,
...Object.keys(manifest).map(name => ({ name })),
...encodeData.css.chunks,
]);
return args;
});
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -522,7 +522,7 @@ class LynxTemplatePluginImpl {
* and source-map is generated
*/
compiler.webpack.Compilation
.PROCESS_ASSETS_STAGE_OPTIMIZE_INLINE,
.PROCESS_ASSETS_STAGE_OPTIMIZE_HASH,
},
() => {
return this.#generateTemplate(
Expand Down Expand Up @@ -571,9 +571,10 @@ class LynxTemplatePluginImpl {
/**
* Generate the html after minification and dev tooling is done
* and source-map is generated
* and real content hash is generated
*/
compiler.webpack.Compilation
.PROCESS_ASSETS_STAGE_OPTIMIZE_INLINE,
.PROCESS_ASSETS_STAGE_OPTIMIZE_HASH,
}, async () => {
await this.#generateAsyncTemplate(compilation);
});
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import fs from 'node:fs';

import { LynxEncodePlugin, LynxTemplatePlugin } from '../../../../src';

/** @type {import('webpack').Configuration} */
Expand Down Expand Up @@ -27,20 +29,26 @@ export default {
filename: 'template.js',
intermediate: '.rspeedy/main',
}),
(compiler) => {

compiler => {
const { DEBUG, NODE_ENV } = process.env;
compiler.hooks.beforeCompile.tap('test', () => {
process.env['DEBUG'] = '';
process.env['NODE_ENV'] = 'production';
});

// Reset
compiler.hooks.done.tap('test', () => {
process.env['DEBUG'] = DEBUG;
process.env['NODE_ENV'] = NODE_ENV;
});
},

(compiler) => {
compiler.hooks.thisCompilation.tap('test', (compilation) => {
const encodeHooks = LynxTemplatePlugin.getLynxTemplatePluginHooks(
compilation,
);
compilation.hooks.processAssets.tap(
{ stage: -1000, name: 'test' },
() => {
process.env['DEBUG'] = '';
process.env['NODE_ENV'] = 'production';
},
);

let appService;
encodeHooks.beforeEmit.tap('test', (args) => {
appService = args.finalEncodeOptions.manifest['/app-service.js'];
Expand All @@ -56,11 +64,27 @@ export default {
{ stage: 10000, name: 'test' },
() => {
expect(appService).not.toBeFalsy();
process.env['DEBUG'] = DEBUG;
process.env['NODE_ENV'] = NODE_ENV;
},
);
});
},

compiler => {
compiler.hooks.afterEmit.tap({
name: 'test',
stage: -128,
}, () => {
const files = fs.readdirSync(compiler.outputPath);
expect(files).toContain('main.bundle.js');
});

compiler.hooks.thisCompilation.tap('test', (compilation) => {
compiler.hooks.done.tap('test', () => {
expect(Object.keys(compilation.assets)).not.toContain(
'main.bundle.js',
);
});
});
},
],
};
Loading