Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions src/finalisers/system.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import Chunk, { ModuleDeclarations } from '../Chunk';
import { Bundle as MagicStringBundle } from 'magic-string';
import { OutputOptions } from '../rollup/index';

function getStarExcludes ({ dependencies, exports } : ModuleDeclarations) {
const starExcludes = new Set(exports.map(expt => expt.exported));
Expand All @@ -24,7 +25,8 @@ export default function system (
getPath: (name: string) => string;
intro: string;
outro: string
}
},
outputOptions: OutputOptions
) {
const { dependencies, exports } = chunk.getModuleDeclarations();

Expand Down Expand Up @@ -109,8 +111,9 @@ export default function system (
`\n${t}${varOrConst} _starExcludes = { ${Array.from(starExcludes).join(': 1, ')}${starExcludes.size ? ': 1' : ''} };`;

const importBindingsSection = importBindings.length ? `\n${t}var ${importBindings.join(', ')};` : '';
const registeredName = outputOptions.name ? `'${outputOptions.name}', ` : '';

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking through rollup's documentation, I think using name here is an abuse of this option which is meant to define global variable names for IIFE/umd bundles (maybe we want to add SystemJS to our umd output at some point?). As @guybedford pointed out, the amd.id option would be more equivalent except for the amd part of the name. So I would prefer deprecating amd.id in favour of a new output option. Not sure what the best name could be; we could call it something like moduleId as it is the id of the generated module as used by the loader. Maybe @guybedford has a more elaborate opinion on this.


const wrapperStart = `System.register([${dependencyIds.join(', ')}], function (exports, module) {
const wrapperStart = `System.register(${registeredName}[${dependencyIds.join(', ')}], function (exports, module) {
${t}'use strict';${starExcludesSection}${importBindingsSection}
${t}return {${setters.length ? `\n${t}${t}setters: [${setters.map(s => `function (module) {
${t}${t}${t}${s}
Expand Down
1 change: 1 addition & 0 deletions test/form/index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
const path = require('path');
const fs = require('fs');
const assert = require('assert');
const sander = require('sander');
const rollup = require('../../dist/rollup');
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
System.register([], function (exports, module) {
System.register('bundle', [], function (exports, module) {
'use strict';
return {
execute: function () {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
System.register([], function (exports, module) {
System.register('myModule', [], function (exports, module) {
'use strict';
return {
execute: function () {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
System.register([], function (exports, module) {
System.register('bundle', [], function (exports, module) {
'use strict';
return {
execute: function () {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
System.register([], function (exports, module) {
System.register('bundle', [], function (exports, module) {
'use strict';
return {
execute: function () {
Expand Down
2 changes: 1 addition & 1 deletion test/form/samples/computed-properties/_expected/system.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
System.register([], function (exports, module) {
System.register('computedProperties', [], function (exports, module) {
'use strict';
return {
execute: function () {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
System.register(['external'], function (exports, module) {
System.register('myBundle', ['external'], function (exports, module) {
'use strict';
var Component;
return {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
System.register([], function (exports, module) {
System.register('exposedInternals', [], function (exports, module) {
'use strict';
return {
execute: function () {
Expand Down
2 changes: 1 addition & 1 deletion test/form/samples/export-all-multiple/_expected/system.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
System.register(['foo', 'bar', 'baz'], function (exports, module) {
System.register('myBundle', ['foo', 'bar', 'baz'], function (exports, module) {
'use strict';
var _starExcludes = { default: 1 };
return {
Expand Down
2 changes: 1 addition & 1 deletion test/form/samples/export-default-2/_expected/system.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
System.register([], function (exports, module) {
System.register('myBundle', [], function (exports, module) {
'use strict';
return {
execute: function () {
Expand Down
2 changes: 1 addition & 1 deletion test/form/samples/export-default-3/_expected/system.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
System.register([], function (exports, module) {
System.register('myBundle', [], function (exports, module) {
'use strict';
return {
execute: function () {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
System.register(['x'], function (exports, module) {
System.register('myBundle', ['x'], function (exports, module) {
'use strict';
var x;
return {
Expand Down
2 changes: 1 addition & 1 deletion test/form/samples/export-default/_expected/system.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
System.register([], function (exports, module) {
System.register('myBundle', [], function (exports, module) {
'use strict';
return {
execute: function () {
Expand Down
2 changes: 1 addition & 1 deletion test/form/samples/export-globals/_expected/system.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
System.register([], function (exports, module) {
System.register('myBundle', [], function (exports, module) {
'use strict';
return {
execute: function () {
Expand Down
2 changes: 1 addition & 1 deletion test/form/samples/export-live-bindings/_expected/system.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
System.register([], function (exports, module) {
System.register('iife', [], function (exports, module) {
'use strict';
return {
execute: function () {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
System.register([], function (exports, module) {
System.register('myBundle', [], function (exports, module) {
'use strict';
return {
execute: function () {
Expand Down
2 changes: 1 addition & 1 deletion test/form/samples/extend-exports/_expected/system.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
System.register([], function (exports, module) {
System.register('foo', [], function (exports, module) {
'use strict';
return {
execute: function () {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
System.register([], function (exports, module) {
System.register('foo.bar.baz', [], function (exports, module) {
'use strict';
return {
execute: function () {
Expand Down
2 changes: 1 addition & 1 deletion test/form/samples/external-deshadowing/_expected/system.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
System.register(['a', 'b'], function (exports, module) {
System.register('myBundle', ['a', 'b'], function (exports, module) {
'use strict';
var Test, Test$1;
return {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
System.register(['babel-polyfill', 'other'], function (exports, module) {
System.register('myBundle', ['babel-polyfill', 'other'], function (exports, module) {
'use strict';
var x;
return {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
System.register(['babel-polyfill'], function (exports, module) {
System.register('myBundle', ['babel-polyfill'], function (exports, module) {
'use strict';
return {
setters: [function (module) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
System.register(['external'], function (exports, module) {
System.register('myBundle', ['external'], function (exports, module) {
'use strict';
return {
setters: [function (module) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
System.register(['highcharts'], function (exports, module) {
System.register('myBundle', ['highcharts'], function (exports, module) {
'use strict';
return {
setters: [function (module) {
Expand Down
2 changes: 1 addition & 1 deletion test/form/samples/freeze/_expected/system.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
System.register([], function (exports, module) {
System.register('myBundle', [], function (exports, module) {
'use strict';
return {
execute: function () {
Expand Down
2 changes: 1 addition & 1 deletion test/form/samples/function-mutation/_expected/system.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
System.register([], function (exports, module) {
System.register('bundle', [], function (exports, module) {
'use strict';
return {
execute: function () {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
System.register([], function (exports, module) {
System.register('doc', [], function (exports, module) {
'use strict';
return {
execute: function () {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
System.register(['react-sticky'], function (exports, module) {
System.register('Sticky', ['react-sticky'], function (exports, module) {
'use strict';
var Sticky;
return {
Expand Down
2 changes: 1 addition & 1 deletion test/form/samples/indent-false/_expected/system.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
System.register([], function (exports, module) {
System.register('foo', [], function (exports, module) {
'use strict';
return {
execute: function () {
Expand Down
2 changes: 1 addition & 1 deletion test/form/samples/indent-spaces/_expected/system.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
System.register([], function (exports, module) {
System.register('foo', [], function (exports, module) {
'use strict';
return {
execute: function () {
Expand Down
2 changes: 1 addition & 1 deletion test/form/samples/indent-true-spaces/_expected/system.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
System.register([], function (exports, module) {
System.register('foo', [], function (exports, module) {
'use strict';
return {
execute: function () {
Expand Down
2 changes: 1 addition & 1 deletion test/form/samples/indent-true/_expected/system.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
System.register([], function (exports, module) {
System.register('foo', [], function (exports, module) {
'use strict';
return {
execute: function () {
Expand Down
2 changes: 1 addition & 1 deletion test/form/samples/interop-false/_expected/system.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
System.register(['core/view'], function (exports, module) {
System.register('foo', ['core/view'], function (exports, module) {
'use strict';
var View;
return {
Expand Down
2 changes: 1 addition & 1 deletion test/form/samples/intro-and-outro/_expected/system.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
System.register(['external'], function (exports, module) {
System.register('foo', ['external'], function (exports, module) {
'use strict';
var a, b;
return {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
System.register([], function (exports, module) {
System.register('myBundle', [], function (exports, module) {
'use strict';
return {
execute: function () {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
System.register([], function (exports, module) {
System.register('myBundle', [], function (exports, module) {
'use strict';
return {
execute: function () {
Expand Down
2 changes: 1 addition & 1 deletion test/form/samples/legacy-getter/_expected/system.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
System.register([], function (exports, module) {
System.register('foo', [], function (exports, module) {
'use strict';
return {
execute: function () {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
System.register([], function (exports, module) {
System.register('myBundle', [], function (exports, module) {
'use strict';
return {
execute: function () {
Expand Down
2 changes: 1 addition & 1 deletion test/form/samples/legacy/_expected/system.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
System.register([], function (exports, module) {
System.register('myBundle', [], function (exports, module) {
'use strict';
return {
execute: function () {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
System.register([], function (exports, module) {
System.register('@scoped/npm-package', [], function (exports, module) {
'use strict';
return {
execute: function () {
Expand Down
2 changes: 1 addition & 1 deletion test/form/samples/module-name-wat/_expected/system.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
System.register([], function (exports, module) {
System.register('foo.@scoped/npm-package.bar.why-would-you-do-this', [], function (exports, module) {
'use strict';
return {
execute: function () {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
System.register([], function (exports, module) {
System.register('module-name-with-dashes', [], function (exports, module) {
'use strict';
return {
execute: function () {
Expand Down
2 changes: 1 addition & 1 deletion test/form/samples/multiple-exports/_expected/system.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
System.register([], function (exports, module) {
System.register('myBundle', [], function (exports, module) {
'use strict';
return {
execute: function () {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
System.register([], function (exports, module) {
System.register('bundle', [], function (exports, module) {
'use strict';
return {
execute: function () {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
System.register([], function (exports, module) {
System.register('foo.bar.baz', [], function (exports, module) {
'use strict';
return {
execute: function () {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
System.register([], function (exports, module) {
System.register('foo.bar.baz', [], function (exports, module) {
'use strict';
return {
execute: function () {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
System.register([], function (exports, module) {
System.register('stirred', [], function (exports, module) {
'use strict';
return {
execute: function () {
Expand Down
2 changes: 1 addition & 1 deletion test/form/samples/no-treeshake/_expected/system.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
System.register(['external'], function (exports, module) {
System.register('stirred', ['external'], function (exports, module) {
'use strict';
var value, more;
return {
Expand Down
8 changes: 8 additions & 0 deletions test/form/samples/output-named-library/_config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
module.exports = {
description: 'names bundles correctly',
options: {
output: {
name: 'libraryName',

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Before this pr, this name was ignored in the outputted System.register format.

},
}
};
9 changes: 9 additions & 0 deletions test/form/samples/output-named-library/_expected/amd.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
define(['exports'], function (exports) { 'use strict';

const valueOnLib = 42;

exports.valueOnLib = valueOnLib;

Object.defineProperty(exports, '__esModule', { value: true });

});
7 changes: 7 additions & 0 deletions test/form/samples/output-named-library/_expected/cjs.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
'use strict';

Object.defineProperty(exports, '__esModule', { value: true });

const valueOnLib = 42;

exports.valueOnLib = valueOnLib;
3 changes: 3 additions & 0 deletions test/form/samples/output-named-library/_expected/es.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
const valueOnLib = 42;

export { valueOnLib };
10 changes: 10 additions & 0 deletions test/form/samples/output-named-library/_expected/iife.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
var libraryName = (function (exports) {
'use strict';

const valueOnLib = 42;

exports.valueOnLib = valueOnLib;

return exports;

}({}));
10 changes: 10 additions & 0 deletions test/form/samples/output-named-library/_expected/system.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
System.register('libraryName', [], function (exports, module) {

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Before my pr, 'libraryName', would not have appeared in this System.register call

'use strict';
return {
execute: function () {

const valueOnLib = exports('valueOnLib', 42);

}
};
});
13 changes: 13 additions & 0 deletions test/form/samples/output-named-library/_expected/umd.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
(function (global, factory) {
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports) :
typeof define === 'function' && define.amd ? define(['exports'], factory) :
(factory((global.libraryName = {})));
}(this, (function (exports) { 'use strict';

const valueOnLib = 42;

exports.valueOnLib = valueOnLib;

Object.defineProperty(exports, '__esModule', { value: true });

})));
1 change: 1 addition & 0 deletions test/form/samples/output-named-library/main.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export const valueOnLib = 42
2 changes: 1 addition & 1 deletion test/form/samples/pattern-assignments/_expected/system.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
System.register([], function (exports, module) {
System.register('bundle', [], function (exports, module) {
'use strict';
return {
execute: function () {
Expand Down
2 changes: 1 addition & 1 deletion test/form/samples/prefer-const/_expected/system.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
System.register(['other'], function (exports, module) {
System.register('myBundle', ['other'], function (exports, module) {
'use strict';
var name;
return {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
System.register([], function (exports, module) {
System.register('myBundle', [], function (exports, module) {
'use strict';
return {
execute: function () {
Expand Down
Loading