GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — --outFile & --module concatenation by weswigham · Pull Request #5090 · microsoft/TypeScript

Conversation

@weswigham

@weswigham Wesley Wigham (weswigham) commented Oct 3, 2015

Copy link
Copy Markdown
Member

With this we support simple concatenation of amd and systemjs 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.

Mohamed Hegazy (@mhegazy) care to give input?

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Wesley Wigham (weswigham) added 8 commits October 1, 2015 11:25
@weswigham
naive change
7d06789
@weswigham
Concatenated module emit fixes up all included paths
b6a57ea
@weswigham
sourcemap correctness
122753b
@weswigham
new baselines for sourcemaps tests (given that modules can now get em…
8e409f3
…itted into single out)
@weswigham
Add compiler error for incompatible module formats
4c4087c
@weswigham
Accept baselines
145fa0c
@weswigham
cusotm tests, forbid umd
03256e7
@weswigham
removed umd as allowed, accepted new baselines
3c73a66
@msftclas Microsoft Contribution License Agreements (msftclas) added the cla-already-signed label Oct 3, 2015
Wesley Wigham (weswigham) added 6 commits October 5, 2015 10:43
@weswigham
Fix jakefile rules build
613c51d
@weswigham
concatenated type emit
05dc9da
@weswigham
merge with master
d8ec703
@weswigham
Correct output, accept new baselines
d07e33d
@weswigham
m'lint
6c1f3ef
@weswigham
update comment
732ec34
@weswigham

Wesley Wigham (weswigham) commented Oct 5, 2015

Copy link
Copy Markdown
Member Author

Mohamed Hegazy (@mhegazy) Do you want to look at this at this point? I've got js and dts concatenation in.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@mhegazy Mohamed Hegazy (mhegazy) mentioned this pull request Oct 6, 2015
Using shared classes for single output client and common.js based node.js code #5094
Closed
Wesley Wigham (weswigham) added 2 commits October 12, 2015 10:21
@weswigham
Merge branch 'master' into out-module-concat
1ae7b7c
@weswigham
Merge branch 'master' into out-module-concat
a83b858
@weswigham Wesley Wigham (weswigham) mentioned this pull request Oct 20, 2015
Definition flattening #5332
Closed
Wesley Wigham (weswigham) added 3 commits October 20, 2015 15:14
@weswigham
feedback form pr
7a4e995
@weswigham
feedback form pr
79cf984
@weswigham
rename variable
d178945
mhegazy
mhegazy reviewed Oct 21, 2015
View reviewed changes
Comment thread src/compiler/utilities.ts Outdated

@mhegazy Mohamed Hegazy (mhegazy) Oct 21, 2015

Copy link
Copy Markdown
Contributor

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);
        }

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Wesley Wigham (weswigham) added 6 commits October 21, 2015 15:27
@weswigham
feedback form pr
37bc277
@weswigham
cleanup a bit, think toward the future
3f52686
@weswigham
bit more cleanup
2fcdb0f
@weswigham
fix lint
d18facb
@weswigham
remove assertion
255cde5
@weswigham
change triple-slash ref emit critaera, add a new tests and accept new…
c165be8
… baselines
@mhegazy

Mohamed Hegazy (mhegazy) commented Nov 7, 2015

Copy link
Copy Markdown
Contributor

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

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

Wesley Wigham (weswigham) added 2 commits November 9, 2015 12:38
@weswigham
Merge branch 'master' into out-module-concat
cadf543
@weswigham
fix lints
977c3ee
Wesley Wigham (weswigham) added a commit that referenced this pull request Nov 9, 2015
@weswigham
Merge pull request #5090 from weswigham/out-module-concat
f153c33
--outFile & --module concatenation
@weswigham
Wesley Wigham (weswigham) merged commit f153c33 into microsoft:master Nov 9, 2015
@weswigham Wesley Wigham (weswigham) mentioned this pull request Nov 11, 2015
No output with --out when using import statement #1544
Closed
This was referenced Dec 9, 2015
Allow relative module IDs in ambient external module declarations? #1720
Closed
Suggestion: package declaration file for commonjs packages #3089
Closed
@basarat

Basarat Ali Syed (basarat) commented Dec 10, 2015

Copy link
Copy Markdown
Contributor

Is this still only amd/systemjs? If so the statement in roadmap https://github.com/Microsoft/TypeScript/wiki/Roadmap#18 Concatenate module output with --outFile seems misleading.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@mhegazy

Mohamed Hegazy (mhegazy) commented Dec 10, 2015

Copy link
Copy Markdown
Contributor

Is concatenating node/commonjs modules an interesting/common scenario?

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@basarat

Basarat Ali Syed (basarat) commented Dec 10, 2015

Copy link
Copy Markdown
Contributor

Is concatenating node/commonjs modules an interesting/common scenario?

Not really. In all honesty just as interesting as amd, none of these bundlings are likely to happen in isolation i.e. module authors expect these modules to be consumed by users that will do bundling themselves, bundling the module code along with the app code. Was just curious. Thanks for the clarification 🌹

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@vladima Vladimir Matveev (vladima) mentioned this pull request Dec 27, 2015
Typescript compile to single file #6257
Closed
@vivainio Ville Vainio (vivainio) mentioned this pull request Jan 1, 2016
1.8: -m system --outFile foo.js should recognize files without exports as modules #6313
Closed
This was referenced Jan 5, 2016
Suggestion: multi-file external modules #17
Closed
Proposal: Bundling TS module type definitions #4433
Closed
@flyon René Verheij (flyon) mentioned this pull request Jan 14, 2016
Export type definitions TypeStrong/ts-loader#48
Closed
@DanielRosenwasser Daniel Rosenwasser (DanielRosenwasser) mentioned this pull request Jan 16, 2016
Show error when compiling external modules with -out or -outFile option #6514
Closed
@mhegazy Mohamed Hegazy (mhegazy) mentioned this pull request Feb 22, 2016
Is it possible to specify the AMD module (project) name during compilation? #4027
Closed
@hypno2000

Reio Piller (hypno2000) commented Apr 13, 2016

Copy link
Copy Markdown

there is definately need for this in commonjs/amd: https://github.com/TypeStrong/dts-bundle

The main use-case is generating definition for npm/bower modules written in TypeScript (commonjs/amd) so the TypeScript code should following the external-module pattern (using import/export's and --outDir).

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@mhegazy

Mohamed Hegazy (mhegazy) commented Apr 13, 2016

Copy link
Copy Markdown
Contributor

Reio Piller (@hypno2000) this is covered by #4433

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@mhegazy Mohamed Hegazy (mhegazy) mentioned this pull request May 4, 2016
Generate a single declaration file for external modules #2568
Closed
@florinn florinn mentioned this pull request Nov 29, 2016
Update README.md florinn/typemoq#35
Closed
@wbhob

Wilson Hobbs (wbhob) commented Apr 27, 2017

Copy link
Copy Markdown
Contributor

I don't understand; can we concatenate commonjs modules into a single file now, or are they still all segmented?

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@mhegazy

Mohamed Hegazy (mhegazy) commented Apr 28, 2017

Copy link
Copy Markdown
Contributor

This is a year old PR, I would say open a new issue instead.

And, no; common js modules can not be concatenated.

delagen and Kequc reacted with confused emoji
All reactions
  • 😕 2 reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@weswigham
Wesley Wigham (weswigham) deleted the out-module-concat branch August 17, 2017 23:04
@alexeagle

Alex Eagle (alexeagle) commented Sep 3, 2017

Copy link
Copy Markdown
Contributor

Hey Wesley Wigham (@weswigham)
With --outFile every AMD module is given a name. Is it possible to have the same thing when emitting to many files?

eg.
thing.ts

export function add(i: number, i2: number) {
    return i + i2;
}

compiled with --outFile
thing.js

define("thing", ["require", "exports"], function (require, exports) {
    "use strict";
    exports.__esModule = true;
    function add(i, i2) {
        return i + i2;
    }
    exports.add = add;
});

I want the same define("thing", ["require", "exports"]... without --outFile so I can concat the files together myself later in the build system. Is it possible?

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@weswigham

Wesley Wigham (weswigham) commented Sep 3, 2017

Copy link
Copy Markdown
Member Author

Alex Eagle (@alexeagle) Per our docs, you can add a ///<amd-module name="NamedModule"/> directive to the top of each file to name it.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@alexeagle

Alex Eagle (alexeagle) commented Sep 3, 2017

Copy link
Copy Markdown
Contributor

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 --outFile
I could add the amd-module directive in a BeforeTransform I suppose.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@mblandfo Mike Blandford (mblandfo) mentioned this pull request Sep 11, 2017
Combined type definitions (.d.ts) output TypeStrong/ts-loader#263
Closed
@microsoft Microsoft (microsoft) locked and limited conversation to collaborators Jun 19, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Reviewers

No reviews

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Uh oh!

There was an error while loading. Please reload this page.

8 participants

@weswigham @mhegazy @vladima @basarat @hypno2000 @wbhob @alexeagle @msftclas
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.