Allow defining the moduleIds-related option in the transform p… (#11194)
* Update "moduleIds" tests * Allow defining the moduleIds related options in the transform plugins - moduleIds - moduleId - getModuleId - moduleRoot * Sort deps
This commit is contained in:
@@ -7,6 +7,7 @@ import {
|
||||
buildNamespaceInitStatements,
|
||||
ensureStatementsHoisted,
|
||||
wrapInterop,
|
||||
getModuleName,
|
||||
} from "@babel/helper-module-transforms";
|
||||
import { template, types as t } from "@babel/core";
|
||||
import { getImportSource } from "babel-plugin-dynamic-import-node/utils";
|
||||
@@ -96,7 +97,7 @@ export default declare((api, options) => {
|
||||
importNames.push(requireId);
|
||||
}
|
||||
|
||||
let moduleName = this.getModuleName();
|
||||
let moduleName = getModuleName(this.file.opts, options);
|
||||
if (moduleName) moduleName = t.stringLiteral(moduleName);
|
||||
|
||||
const { meta, headers } = rewriteModuleStatementsAndPrepareHeader(
|
||||
|
||||
@@ -0,0 +1,5 @@
|
||||
{
|
||||
"sourceType": "module",
|
||||
"moduleIds": true,
|
||||
"moduleId": "my custom module name"
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
define("my custom module name", [], function () {
|
||||
"use strict";
|
||||
});
|
||||
@@ -1,5 +1,10 @@
|
||||
{
|
||||
"sourceType": "module",
|
||||
"moduleIds": true,
|
||||
"moduleId": "my custom module name"
|
||||
"plugins": [
|
||||
"external-helpers",
|
||||
["transform-modules-amd", {
|
||||
"moduleIds": true,
|
||||
"moduleId": "my custom module name"
|
||||
}]
|
||||
]
|
||||
}
|
||||
|
||||
1
packages/babel-plugin-transform-modules-amd/test/fixtures/amd/module-name-compat/input.js
vendored
Normal file
1
packages/babel-plugin-transform-modules-amd/test/fixtures/amd/module-name-compat/input.js
vendored
Normal file
@@ -0,0 +1 @@
|
||||
foobar();
|
||||
@@ -0,0 +1,4 @@
|
||||
{
|
||||
"sourceType": "module",
|
||||
"moduleIds": true
|
||||
}
|
||||
5
packages/babel-plugin-transform-modules-amd/test/fixtures/amd/module-name-compat/output.js
vendored
Normal file
5
packages/babel-plugin-transform-modules-amd/test/fixtures/amd/module-name-compat/output.js
vendored
Normal file
@@ -0,0 +1,5 @@
|
||||
define("amd/module-name-compat/input", [], function () {
|
||||
"use strict";
|
||||
|
||||
foobar();
|
||||
});
|
||||
@@ -1,4 +1,7 @@
|
||||
{
|
||||
"sourceType": "module",
|
||||
"moduleIds": true
|
||||
"plugins": [
|
||||
"external-helpers",
|
||||
["transform-modules-amd", { "moduleIds": true }]
|
||||
]
|
||||
}
|
||||
|
||||
@@ -0,0 +1,6 @@
|
||||
{
|
||||
"sourceType": "module",
|
||||
"moduleIds": true,
|
||||
"moduleId": "my custom module name",
|
||||
"plugins": ["external-helpers", ["transform-modules-amd", { "loose": true }]]
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
define("my custom module name", [], function () {
|
||||
"use strict";
|
||||
});
|
||||
@@ -1,6 +1,11 @@
|
||||
{
|
||||
"sourceType": "module",
|
||||
"moduleIds": true,
|
||||
"moduleId": "my custom module name",
|
||||
"plugins": ["external-helpers", ["transform-modules-amd", { "loose": true }]]
|
||||
"plugins": [
|
||||
"external-helpers",
|
||||
["transform-modules-amd", {
|
||||
"loose": true,
|
||||
"moduleIds": true,
|
||||
"moduleId": "my custom module name"
|
||||
}]
|
||||
]
|
||||
}
|
||||
|
||||
1
packages/babel-plugin-transform-modules-amd/test/fixtures/loose/module-name-compat/input.js
vendored
Normal file
1
packages/babel-plugin-transform-modules-amd/test/fixtures/loose/module-name-compat/input.js
vendored
Normal file
@@ -0,0 +1 @@
|
||||
foobar();
|
||||
@@ -0,0 +1,5 @@
|
||||
{
|
||||
"sourceType": "module",
|
||||
"moduleIds": true,
|
||||
"plugins": ["external-helpers", ["transform-modules-amd", { "loose": true }]]
|
||||
}
|
||||
5
packages/babel-plugin-transform-modules-amd/test/fixtures/loose/module-name-compat/output.js
vendored
Normal file
5
packages/babel-plugin-transform-modules-amd/test/fixtures/loose/module-name-compat/output.js
vendored
Normal file
@@ -0,0 +1,5 @@
|
||||
define("loose/module-name-compat/input", [], function () {
|
||||
"use strict";
|
||||
|
||||
foobar();
|
||||
});
|
||||
@@ -1,5 +1,10 @@
|
||||
{
|
||||
"sourceType": "module",
|
||||
"moduleIds": true,
|
||||
"plugins": ["external-helpers", ["transform-modules-amd", { "loose": true }]]
|
||||
"plugins": [
|
||||
"external-helpers",
|
||||
["transform-modules-amd", {
|
||||
"loose": true,
|
||||
"moduleIds": true
|
||||
}]
|
||||
]
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user