Skip to content

Commit

Permalink
feat: add outputDir for searching source map
Browse files Browse the repository at this point in the history
  • Loading branch information
nyqykk committed Dec 18, 2024
1 parent 2c00182 commit 3ea9aec
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 8 deletions.
16 changes: 15 additions & 1 deletion e2e/cases/doctor-rspack/plugin.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,18 @@ async function rspackCompile(tapName: string, compile: typeof compileByRspack) {
},
plugins: [
// @ts-ignore
createRsdoctorPlugin({}),
createRsdoctorPlugin({
linter: {
rules: {
'ecma-version-check': [
'Error',
{
ecmaVersion: 3,
},
],
},
},
}),
{
name: 'Foo',
apply(compiler: Compiler) {
Expand Down Expand Up @@ -108,6 +119,7 @@ async function rspackCompile(tapName: string, compile: typeof compileByRspack) {
},
},
],
devtool: 'cheap-module-source-map',
});

return res;
Expand Down Expand Up @@ -140,6 +152,8 @@ test('rspack data store', async () => {
const graphData = datas.moduleGraph;
const configs = datas.configs;

const ecmaCheckError = datas.errors.some((e) => e.code === 'E1004');
expect(ecmaCheckError).toBeTruthy();
os.EOL === '\n'
? expect(
graphData.modules[0].webpackId.indexOf('/fixtures/a.js'),
Expand Down
6 changes: 4 additions & 2 deletions packages/core/src/rules/rules/ecma-version-check/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@ export const rule = defineRule<typeof title, Config>(() => {
path: root,
env: 'production',
});
const { exclude, excludeOutput, targets, ecmaVersion } = ruleConfig;
const { exclude, excludeOutput, targets, ecmaVersion, outputDir } =
ruleConfig;
const finalTargets = targets || browserslistConfig || [];
// disable check syntax
if (!finalTargets.length && !ecmaVersion) {
Expand All @@ -45,7 +46,8 @@ export const rule = defineRule<typeof title, Config>(() => {
rootPath: root,
targets: finalTargets,
});
await checkSyntax.check(asset.path, asset.content);
const assetPath = path.resolve(root, outputDir || 'dist', asset.path);
await checkSyntax.check(assetPath, asset.content);
checkSyntax.errors.forEach((err) => {
report({
message: `Find some syntax that does not match "ecmaVersion <= ${checkSyntax.ecmaVersion}"`,
Expand Down
4 changes: 3 additions & 1 deletion packages/core/src/rules/rules/ecma-version-check/types.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import type { PluginCheckSyntaxOptions } from '@rsbuild/plugin-check-syntax';

export interface Config extends PluginCheckSyntaxOptions {}
export interface Config extends PluginCheckSyntaxOptions {
outputDir?: string;
}
4 changes: 0 additions & 4 deletions scripts/test-helper/src/rspack.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,6 @@ export function compileByRspack(
const compiler = rspack({
entry: absPath,
mode: 'none',
output: {
path: path.resolve(__dirname),
filename: 'bundle.js',
},
stats: 'normal',
cache: false,
...options,
Expand Down

0 comments on commit 3ea9aec

Please sign in to comment.