rstackjs / rstackjs/rsbuild-plugin-pug

add catch code

Open
#13 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
TypeScript
Stars
2
Forks
2
Avg merge
4h 7m
Merged PRs (30d)
7

Description

  1. add catch code
import { reduceConfigs } from 'reduce-configs'
import { compile, compileClient } from 'pug'
export const PLUGIN_PUG_NAME = 'rsbuild:pug'

export const pluginPug = (options) => ({
  name: PLUGIN_PUG_NAME,

  async setup(api) {
    const VUE_SFC_REGEXP = /\.vue$/

    const pugOptions = reduceConfigs({
      initial: {
        doctype: 'html',
        compileDebug: false
      },
      config: options.pugOptions
    })

    api.transform({ test: /\.pug$/ }, ({ code, resourcePath, addDependency }) => {
      const options = {
        filename: resourcePath,
        ...pugOptions
      }

      if (VUE_SFC_REGEXP.test(resourcePath)) {
        let template
        try {
          template = compile(code, options)
          const { dependencies } = template
          if (dependencies) dependencies.forEach(addDependency)
          return template()
        } catch (e) { // ! important Add Catch Code
          addDependency(e.filename)
          return '<pre>' + e.message + '</pre>'
        }
      }

      const templateCode = compileClient(code, options)
      return `${templateCode}; export default template;`
    })
  }
})

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Locate the pluginPug setup and its api.transform handler, then compare the Vue SFC compile path with the requested catch block. Check how Pug compile errors expose filename and confirm the dependency registration and

 error output described in the issue. The change is complete when that error path behaves as shown without altering the normal compilation paths.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript, typescript
Domain
build-system, tooling
Issue type
Bug
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
42/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.