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

feat: allow `templateDebugUrl` to be customized via `output.publicPath` or the `beforeEncode` hook.
Original file line number Diff line number Diff line change
Expand Up @@ -757,13 +757,31 @@ class LynxTemplatePluginImpl {
cssPlugins,
enableCSSSelector,
);

let templateDebugUrl = '';
const debugInfoPath = path.posix.format({
dir: intermediate,
base: 'debug-info.json',
});
// TODO: Support publicPath function
if (
typeof compiler.options.output.publicPath === 'string'
&& compiler.options.output.publicPath !== 'auto'
&& compiler.options.output.publicPath !== '/'
) {
templateDebugUrl = new URL(
debugInfoPath,
compiler.options.output.publicPath,
).toString();
}

const encodeRawData: EncodeRawData = {
compilerOptions: {
enableFiberArch: true,
useLepusNG: true,
enableReuseContext: true,
bundleModuleMode: 'ReturnByFunction',
templateDebugUrl: '',
templateDebugUrl,

debugInfoOutside,
defaultDisplayLinear,
Expand Down Expand Up @@ -844,23 +862,6 @@ class LynxTemplatePluginImpl {
},
};

const debugInfoPath = path.posix.format({
dir: intermediate,
base: 'debug-info.json',
});

// TODO: Support publicPath function
if (
typeof compiler.options.output.publicPath === 'string'
&& compiler.options.output.publicPath !== 'auto'
&& compiler.options.output.publicPath !== '/'
) {
resolvedEncodeOptions.compilerOptions['templateDebugUrl'] = new URL(
debugInfoPath,
compiler.options.output.publicPath,
).toString();
}

const { RawSource } = compiler.webpack.sources;

if (isDebug() || isDev) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
/// <reference types="vitest/globals" />

import fs from 'node:fs/promises';
import path from 'node:path';

it('should have debug-info.json emitted', async () => {
const content = await fs.readFile(
path.resolve(__dirname, '.rspeedy/main/debug-info.json'),
);

expect(content.length).not.toBe(0);
});

it('should have custom templateDebugUrl in tasm.json from hook', async () => {
const tasmJSON = await fs.readFile(
path.resolve(__dirname, '.rspeedy/main/tasm.json'),
'utf-8',
);

const { compilerOptions } = JSON.parse(tasmJSON);

expect(compilerOptions).toHaveProperty(
'templateDebugUrl',
'https://custom-hook-url.com/debug-info.json',
);
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import config from './webpack.config.js';

export default config;
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import { LynxEncodePlugin, LynxTemplatePlugin } from '../../../../src';

/** @type {import('webpack').Configuration} */
export default {
mode: 'development',
target: 'node',
output: {
publicPath: 'https://should-be-overridden.com/',
},
plugins: [
new LynxEncodePlugin(),
new LynxTemplatePlugin({
intermediate: '.rspeedy/main',
}),
{
apply(compiler) {
compiler.hooks.compilation.tap('TestPlugin', (compilation) => {
LynxTemplatePlugin.getLynxTemplatePluginHooks(compilation)
.beforeEncode.tap(
'TestPlugin',
(data) => {
data.encodeData.compilerOptions.templateDebugUrl =
'https://custom-hook-url.com/debug-info.json';
return data;
},
);
});
},
},
],
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
/// <reference types="vitest/globals" />

import fs from 'node:fs/promises';
import path from 'node:path';

it('should have debug-info.json emitted', async () => {
const content = await fs.readFile(
path.resolve(__dirname, '.rspeedy/main/debug-info.json'),
);

expect(content.length).not.toBe(0);
});

it('should have templateDebugUrl in tasm.json', async () => {
const tasmJSON = await fs.readFile(
path.resolve(__dirname, '.rspeedy/main/tasm.json'),
'utf-8',
);

const { compilerOptions } = JSON.parse(tasmJSON);

expect(compilerOptions).toHaveProperty(
'templateDebugUrl',
'https://example.com/.rspeedy/main/debug-info.json',
);
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import config from './webpack.config.js';

export default config;
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { LynxEncodePlugin, LynxTemplatePlugin } from '../../../../src';

/** @type {import('webpack').Configuration} */
export default {
mode: 'development',
target: 'node',
output: {
publicPath: 'https://example.com/',
},
plugins: [
new LynxEncodePlugin(),
new LynxTemplatePlugin({
intermediate: '.rspeedy/main',
}),
],
};
Loading