-
Notifications
You must be signed in to change notification settings - Fork 12.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Expose emitted module specifiers on AMD outfile emit #35052
Comments
I’m not familiar with this behavior (don’t think I’ve ever targeted AMD before), but just to clarify a few things:
I think I would personally expect module specifiers to be relative to the rootDir, and would feel pretty safe about this not changing. I’m kind of surprised if that’s not already the case, but it seems like I might be missing something about your request? |
@andrewbranch I've created an example repo which recreates an environment which relates to this request.
I don't believe this has an impact. In my example the project root contains a
I don't believe so, I experimented in the example project and setting the
They are, as far as I can tell, and I am using the logic I detected to determine the emitted specifiers. But that means that I am coupling to a behaviour that is not really part of the contract. It feels like something that I should be able to determine from the I believe that
I was surprised too. 😁 Hopefully that adds a bit of clarity. |
Cool, thanks for the example. It looks like this comes from the
it looks like it’s intentionally finding the common source directory instead of using the rootDir.
So is it undefined right now? TypeScript/src/compiler/transformers/module/module.ts Lines 198 to 199 in 71a9176
@rbuckton thoughts? |
Correct, on |
Search Terms
amd outfile module specifier
Suggestion
Currently when utilising the compiler APIs to emit as AMD to a single outfile, the emitted module specifier in the outfile is not exposed, but does not match the source file
SourceFile.fileName
or any other attribute.It appears that there are internals of the TypeScript emitter which determine the module specifier that is included output. For example, if given
/foo/bar/baz.ts
and/foo/qat/qux.ts
being part of the same program, when emitted as AMD in a single bundle the module specifier, the outfile willdefine()
a module namedbar/baz
andqat/qux
. It appears that the algorithm used looks for the common root and removes the extension to determine the module specifier.Use Cases
When loading the bundle with an AMD loader, knowing what a module specifier is in the outfile is needed to be able to specify a module to load in a
require()
statement. So if we were automating a custom build, outputting a "bundle" and determining which module torequire()
to bootstrap the application, we have to "guess" and hope that the emitter doesn't change its algorithm of determining the module specifiers.Examples
I'm not totally sure, but a public API that would take a
SourceFile[]
and provide back astring[]
array of module specifiers. This could be used inHost.writeFile()
to determine what module specifiers are contained in the written file.Checklist
My suggestion meets these guidelines:
The text was updated successfully, but these errors were encountered: