Skip to content

[StimulusBundle] Exception thrown when .ts controller transpiled to .js in the same directory #2701

Open
@phasdev

Description

@phasdev

The loadCustomControllers function iterates over all .ts and .js files in the project's controllers path to build a controller map.

My project has a build step where TypeScript controllers are transpiled to JavaScript files that are saved alongside the source TypeScript files. My asset mapper config excludes TypeScript files since I'm only interested in serving JavaScript.

When loadCustomControllers iterates over all .ts and .js files in my controllers path, it tries to load mapped assets for my .ts controllers. But since these files are excluded, the returned asset is null and an exception is thrown when it tries to read the sourcePath property on the null asset.

Controller files should be a mapped asset. Not finding one indicates a problem so an exception should be thrown (e.g. see null mapped asset check in loadUxControllers function). However the loadCustomControllers function doesn't realize there are .js and .ts versions of the same controller and can skip processing the missing version.

I expected that I could exclude .ts controller files when .js versions are available.

Here's my proposed fix:

  • Skip mapping .ts controller file if a .js version is available
  • Add a null asset check and throw an exception similar to one thrown in loadUxControllers

Related: #1210

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions