Skip to content
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

Do not override file.opts.filenameRelative #20

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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
3 changes: 2 additions & 1 deletion src/moduleImportHelper.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ function getImportedModuleFile(crntFile, importedModulePath) {
...crntFile,
opts: {
...crntFile.opts,
filename: (crntFile.opts.filenameRelative = importedModulePath + '.js'),
filename: importedModulePath + '.js',
filenameRelative: importedModulePath + '.js',
},
getModuleName: crntFile.getModuleName,
};
Expand Down
21 changes: 21 additions & 0 deletions test/fixtures/amd/getModuleId/.babelrc_extra
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
"moduleIds": true,
"getModuleId": {
"npmModule": "npmModuleGlobalVar",
"PATH/actual": "actualGlobalVar"
},
"plugins": [
["system-import-transformer", {
"modules": "amd"
}]
],
"presets": [
[
"@babel/preset-env",
{
"modules": "amd",
"useBuiltIns": false
}
]
]
}
3 changes: 3 additions & 0 deletions test/fixtures/amd/getModuleId/actual.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
System.import('npmModule');

// System.import('./myModule');
21 changes: 21 additions & 0 deletions test/fixtures/amd/getModuleId/expected.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
define('actualGlobalVar', [], function() {
'use strict';
var _systemImportTransformerGlobalIdentifier =
typeof window !== 'undefined'
? window
: typeof self !== 'undefined'
? self
: typeof global !== 'undefined'
? global
: {};

new Promise(function(resolve, reject) {
_systemImportTransformerGlobalIdentifier.require(
['npmModuleGlobalVar'],
resolve,
reject,
);
});
});

// System.import('./myModule');
15 changes: 12 additions & 3 deletions test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,14 +57,22 @@ function runTests() {
return result;
}

function createBabelModuleIdProvider(fileMap) {
function createBabelModuleIdProvider(fileMap, crntPath) {
return function babelModuleIdProvider(moduleName) {
// const fileMap = {
// 'myModule': 'myModuleGlobalconst'
// };

const result = fileMap[moduleName] || moduleName.replace('src/', '');
return result;
if (fileMap[moduleName]) {
return fileMap[moduleName];
}

const pathMap = moduleName.replace(crntPath, 'PATH');
if (fileMap[pathMap]) {
return fileMap[pathMap];
}

return moduleName.replace('src/', '');
};
}

Expand All @@ -83,6 +91,7 @@ function getBabelConfiguration(dir) {
if (extraConfiguration.getModuleId) {
extraConfiguration.getModuleId = createBabelModuleIdProvider(
extraConfiguration.getModuleId,
crntPath,
);
}
configurations.push(extraConfiguration);
Expand Down