-
Notifications
You must be signed in to change notification settings - Fork 12.6k
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
--outFile & --module concatenation #5090
Conversation
…itted into single out)
@mhegazy Do you want to look at this at this point? I've got js and dts concatenation in. |
@@ -1756,6 +1796,26 @@ namespace ts { | |||
}; | |||
} | |||
|
|||
export function makeModulePathSemiAbsolute(host: EmitHost, currentSourceFile: SourceFile, externalModuleName: string): string { | |||
let quotationMark = externalModuleName.charAt(0); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
my only comment here, is we can simplify this using the resolver to get the symbol and then use the symbol's declaration filename to get the semiAbsolutePath,
here is what i had in mind.
function emitExternalModuleSpecifier(moduleSpecifier: Expression) {
Debug.assert(moduleSpecifier.kind === SyntaxKind.StringLiteral);
if (compilerOptions.out) {
let moduleSymbol = resolver.getSymbolAtLocation(moduleSpecifier);
if (moduleSymbol && moduleSymbol.valueDeclaration &&
moduleSymbol.valueDeclaration.kind === SyntaxKind.SourceFile &&
!isDeclarationFile(<SourceFile>moduleSymbol.valueDeclaration)) {
let nonRelativeModuleName = getExternalModuleNameFromPath((<SourceFile>moduleSymbol.valueDeclaration).fileName);
write("\"");
write(nonRelativeModuleName);
write("\"");
return;
}
}
writeTextOfNode(currentSourceFile, moduleSpecifier);
}
function getExternalModuleNameFromPath(fileName: string) {
let sourceFilePath = getNormalizedAbsolutePath(fileName, host.getCurrentDirectory());
let commonSourceDirectory = host.getCommonSourceDirectory();
sourceFilePath = sourceFilePath.replace(commonSourceDirectory, "");
return removeFileExtension(sourceFilePath);
}
Once this goes in, please update the breaking change page: https://github.com/Microsoft/TypeScript/wiki/Breaking-Changes Add a snippit about it in What's new page: https://github.com/Microsoft/TypeScript/wiki/What%27s-new-in-TypeScript#typescript-18-upcoming And update the documentation for compiler options in: https://github.com/Microsoft/TypeScript/wiki/Compiler-Options |
--outFile & --module concatenation
Is this still only |
Is concatenating node/commonjs modules an interesting/common scenario? |
Not really. In all honesty just as interesting as |
there is definately need for this in commonjs/amd: https://github.com/TypeStrong/dts-bundle
|
@hypno2000 this is covered by #4433 |
I don't understand; can we concatenate commonjs modules into a single file now, or are they still all segmented? |
This is a year old PR, I would say open a new issue instead. And, no; common js modules can not be concatenated. |
Hey @weswigham eg.
compiled with
I want the same |
@alexeagle Per our docs, you can add a |
I don't want TypeScript authors to be aware of the module system used (this would be for karma, but for other bundlers I'd use ESM modules). Ideally I'd like the module names chosen the same way they are for |
With this we support simple concatenation of
amd
andsystemjs
modules into the specified output file. ES6, UMD, and Commonjs all can't be bundled to via simple concatenation and path correction, so they are not a part of this change and it is an error to attempt to use one of them with--outFile
.UMD was original on the list of formats to accept... but I realized that was silly when UMD contains support for commonjs (in addition to AMD), which we couldn't support - it seems silly to emit UMD when it only works in an AMD environment.Since we use
--out
with--module commonjs
internally (a lot), this changed the baselines for many tests.This is, in effect, an alternative to #4754 which works for a handful of our module emits and doesn't require the user tell us an entrypoint.
@mhegazy care to give input?