Skip to content

Commit

Permalink
Respect output.paths in dynamic imports (#3508)
Browse files Browse the repository at this point in the history
  • Loading branch information
lukastaegert committed Apr 21, 2020
1 parent 437934e commit 1916b6d
Show file tree
Hide file tree
Showing 8 changed files with 62 additions and 10 deletions.
2 changes: 1 addition & 1 deletion src/Chunk.ts
Expand Up @@ -711,7 +711,7 @@ export default class Chunk {
? `'${
resolution.renormalizeRenderPath
? this.getRelativePath(resolution.renderPath, stripKnownJsExtensions)
: resolution.id
: resolution.renderPath
}'`
: resolution;
node.renderFinalResolution(code, renderedResolution);
Expand Down
25 changes: 23 additions & 2 deletions test/form/samples/paths-function/_expected/amd.js
@@ -1,7 +1,28 @@
define(['https://unpkg.com/foo'], function (foo) { 'use strict';
define(['require', 'https://unpkg.com/foo'], function (require, foo) { 'use strict';

function _interopNamespace(e) {
if (e && e.__esModule) { return e; } else {
var n = {};
if (e) {
Object.keys(e).forEach(function (k) {
var d = Object.getOwnPropertyDescriptor(e, k);
Object.defineProperty(n, k, d.get ? d : {
enumerable: true,
get: function () {
return e[k];
}
});
});
}
n['default'] = e;
return n;
}
}

foo = foo && Object.prototype.hasOwnProperty.call(foo, 'default') ? foo['default'] : foo;

assert.equal( foo, 42 );
assert.equal(foo, 42);

new Promise(function (resolve, reject) { require(['https://unpkg.com/foo'], function (m) { resolve(_interopNamespace(m)); }, reject) }).then(({ default: foo }) => assert.equal(foo, 42));

});
23 changes: 22 additions & 1 deletion test/form/samples/paths-function/_expected/cjs.js
Expand Up @@ -2,6 +2,27 @@

function _interopDefault (ex) { return (ex && (typeof ex === 'object') && 'default' in ex) ? ex['default'] : ex; }

function _interopNamespace(e) {
if (e && e.__esModule) { return e; } else {
var n = {};
if (e) {
Object.keys(e).forEach(function (k) {
var d = Object.getOwnPropertyDescriptor(e, k);
Object.defineProperty(n, k, d.get ? d : {
enumerable: true,
get: function () {
return e[k];
}
});
});
}
n['default'] = e;
return n;
}
}

var foo = _interopDefault(require('https://unpkg.com/foo'));

assert.equal( foo, 42 );
assert.equal(foo, 42);

new Promise(function (resolve) { resolve(_interopNamespace(require('https://unpkg.com/foo'))); }).then(({ default: foo }) => assert.equal(foo, 42));
4 changes: 3 additions & 1 deletion test/form/samples/paths-function/_expected/es.js
@@ -1,3 +1,5 @@
import foo from 'https://unpkg.com/foo';

assert.equal( foo, 42 );
assert.equal(foo, 42);

import('https://unpkg.com/foo').then(({ default: foo }) => assert.equal(foo, 42));
4 changes: 3 additions & 1 deletion test/form/samples/paths-function/_expected/iife.js
Expand Up @@ -3,6 +3,8 @@

foo = foo && Object.prototype.hasOwnProperty.call(foo, 'default') ? foo['default'] : foo;

assert.equal( foo, 42 );
assert.equal(foo, 42);

import('https://unpkg.com/foo').then(({ default: foo }) => assert.equal(foo, 42));

}(foo));
6 changes: 4 additions & 2 deletions test/form/samples/paths-function/_expected/system.js
@@ -1,4 +1,4 @@
System.register(['https://unpkg.com/foo'], function () {
System.register(['https://unpkg.com/foo'], function (exports, module) {
'use strict';
var foo;
return {
Expand All @@ -7,7 +7,9 @@ System.register(['https://unpkg.com/foo'], function () {
}],
execute: function () {

assert.equal( foo, 42 );
assert.equal(foo, 42);

module.import('https://unpkg.com/foo').then(({ default: foo }) => assert.equal(foo, 42));

}
};
Expand Down
4 changes: 3 additions & 1 deletion test/form/samples/paths-function/_expected/umd.js
Expand Up @@ -6,6 +6,8 @@

foo = foo && Object.prototype.hasOwnProperty.call(foo, 'default') ? foo['default'] : foo;

assert.equal( foo, 42 );
assert.equal(foo, 42);

import('https://unpkg.com/foo').then(({ default: foo }) => assert.equal(foo, 42));

})));
4 changes: 3 additions & 1 deletion test/form/samples/paths-function/main.js
@@ -1,3 +1,5 @@
import foo from 'foo';

assert.equal( foo, 42 );
assert.equal(foo, 42);

import('foo').then(({ default: foo }) => assert.equal(foo, 42));

0 comments on commit 1916b6d

Please sign in to comment.