systemjs / builder

SystemJS build tool
MIT License
466 stars 122 forks source link

What is the correct way to replace deprecated wildcards in the paths configuration? #830

Closed jamesbrobb closed 6 years ago

jamesbrobb commented 6 years ago

Versions

systemjs: 0.19.47 systemjs-builder: 0.15.34 typescript: 2.3.0


Question

With warnings: true i get the following warning:

Paths configuration "my_module/*" -> "my_module/*.ts" uses wildcards which are being deprecated for just leaving a trailing "/" to indicate folder paths.

In order to fix this i removed the wildcards from the my_module paths config and added defaultExtension: 'ts' to packages:

So:

paths: {
    'my_module/*': 'src/my_module/*.ts' 
}

has become:

paths: {
    'my_module/': 'src/my_module/' 
},

packages: {
    my_module: {
        defaultExtension: 'ts'
    }
}

This (as far as i can understand) is what's specified as the fix for this in the warning message and now the warning message is gone. Without the defaultExtension: 'ts' it attempts to load .js files, so i'm presuming this is also required?


Problem

Using this format adds .ts onto all of the systemjs register paths and import statements once transpiled. So any other code that attempts to import MyClass from 'my_module' without the .ts will fail to find them in the register and error attempting to load my_module/MyClass

So whereas when using wildcards the output would be:

System.register("my_module/MyClass", ["./MyOtherClass"], function (exports_1, context_1) {
    ...
}

Without the wildcards and only a trailing slash and defaultExtension: 'ts' it outputs:

System.register("my_module/MyClass.ts", ["./MyOtherClass.ts"], function (exports_1, context_1) {
    ...
}


Using plugin-typescript

It has been suggested that i should be using plugin-typescript (i'm now using 7.0.6) to ensure that typescript files are handled correctly. However when using trailing slashes instead of wildcards, it ends up with only .ts on the register keys, but not the imported dependencies:

System.register("my_module/MyClass.ts", ["./MyOtherClass"], function (exports_1, context_1) {
    ...
}


Question

What's the correct way to target and transpile typescript files, so that the .ts is not added to the registry keys and imports?

aluanhaddad commented 6 years ago

Any code importing from my_module should always go through the package configuration and have the defaultExtension added to the normalized path that it requests.

There are some edge cases here but what issue are you specifically experiencing?

jamesbrobb commented 6 years ago

Got it, thanks again for your help.

I think a lot of the problems i'm experiencing stem from a misunderstanding (on my part), of what the config used for systemjs-builder should look like, and then exactly what the corresponding systemjs config used to load those bundled files should also then look like.

aluanhaddad commented 6 years ago

I'm glad I could help. It definitely gets complicated and confusing at times.