@modern-js/babel-preset 0.0.0-nightly-20240715170628
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +26 -0
- package/dist/base.d.ts +2 -0
- package/dist/base.js +114 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +22 -0
- package/dist/node.d.ts +5 -0
- package/dist/node.js +58 -0
- package/dist/pluginLockCorejsVersion.d.ts +5 -0
- package/dist/pluginLockCorejsVersion.js +79 -0
- package/dist/types.d.ts +16 -0
- package/dist/types.js +16 -0
- package/dist/web.d.ts +5 -0
- package/dist/web.js +85 -0
- package/package.json +82 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2023-present Bytedance, Inc. and its affiliates.
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
<p align="center">
|
|
2
|
+
<a href="https://modernjs.dev" target="blank"><img src="https://lf3-static.bytednsdoc.com/obj/eden-cn/ylaelkeh7nuhfnuhf/modernjs-cover.png" width="300" alt="Modern.js Logo" /></a>
|
|
3
|
+
</p>
|
|
4
|
+
|
|
5
|
+
<h1 align="center">Modern.js</h1>
|
|
6
|
+
|
|
7
|
+
<p align="center">
|
|
8
|
+
A Progressive React Framework for modern web development.
|
|
9
|
+
</p>
|
|
10
|
+
|
|
11
|
+
## Getting Started
|
|
12
|
+
|
|
13
|
+
Please follow [Quick Start](https://modernjs.dev/en/guides/get-started/quick-start) to get started with Modern.js.
|
|
14
|
+
|
|
15
|
+
## Documentation
|
|
16
|
+
|
|
17
|
+
- [English Documentation](https://modernjs.dev/en/)
|
|
18
|
+
- [中文文档](https://modernjs.dev)
|
|
19
|
+
|
|
20
|
+
## Contributing
|
|
21
|
+
|
|
22
|
+
Please read the [Contributing Guide](https://github.com/web-infra-dev/modern.js/blob/main/CONTRIBUTING.md).
|
|
23
|
+
|
|
24
|
+
## License
|
|
25
|
+
|
|
26
|
+
Modern.js is [MIT licensed](https://github.com/web-infra-dev/modern.js/blob/main/LICENSE).
|
package/dist/base.d.ts
ADDED
package/dist/base.js
ADDED
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __export = (target, all) => {
|
|
9
|
+
for (var name in all)
|
|
10
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
|
+
};
|
|
12
|
+
var __copyProps = (to, from, except, desc) => {
|
|
13
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
|
+
for (let key of __getOwnPropNames(from))
|
|
15
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
16
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
17
|
+
}
|
|
18
|
+
return to;
|
|
19
|
+
};
|
|
20
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
+
mod
|
|
27
|
+
));
|
|
28
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
|
+
var base_exports = {};
|
|
30
|
+
__export(base_exports, {
|
|
31
|
+
generateBaseConfig: () => generateBaseConfig
|
|
32
|
+
});
|
|
33
|
+
module.exports = __toCommonJS(base_exports);
|
|
34
|
+
const generateBaseConfig = (options = {}) => {
|
|
35
|
+
var _config_plugins;
|
|
36
|
+
const config = {
|
|
37
|
+
presets: [],
|
|
38
|
+
plugins: []
|
|
39
|
+
};
|
|
40
|
+
const { presetEnv = {}, presetTypeScript = {}, pluginDecorators = false } = options;
|
|
41
|
+
if (presetEnv) {
|
|
42
|
+
var _config_presets;
|
|
43
|
+
var _presetEnv_include;
|
|
44
|
+
(_config_presets = config.presets) === null || _config_presets === void 0 ? void 0 : _config_presets.push([
|
|
45
|
+
require.resolve("@babel/preset-env"),
|
|
46
|
+
{
|
|
47
|
+
// Jest only supports commonjs
|
|
48
|
+
modules: process.env.NODE_ENV === "test" ? "commonjs" : false,
|
|
49
|
+
exclude: [
|
|
50
|
+
"transform-typeof-symbol"
|
|
51
|
+
],
|
|
52
|
+
...presetEnv,
|
|
53
|
+
// If you are using @babel/preset-env and legacy decorators, you must ensure the class elements transform is enabled regardless of your targets, because Babel only supports compiling legacy decorators when also compiling class properties:
|
|
54
|
+
// see https://babeljs.io/docs/babel-plugin-proposal-decorators#legacy
|
|
55
|
+
...pluginDecorators && pluginDecorators.version === "legacy" ? {
|
|
56
|
+
include: [
|
|
57
|
+
"@babel/plugin-transform-class-properties",
|
|
58
|
+
...(_presetEnv_include = presetEnv === null || presetEnv === void 0 ? void 0 : presetEnv.include) !== null && _presetEnv_include !== void 0 ? _presetEnv_include : []
|
|
59
|
+
]
|
|
60
|
+
} : {}
|
|
61
|
+
}
|
|
62
|
+
]);
|
|
63
|
+
}
|
|
64
|
+
if (presetTypeScript) {
|
|
65
|
+
var _config_presets1;
|
|
66
|
+
(_config_presets1 = config.presets) === null || _config_presets1 === void 0 ? void 0 : _config_presets1.push([
|
|
67
|
+
require.resolve("@babel/preset-typescript"),
|
|
68
|
+
{
|
|
69
|
+
isTSX: true,
|
|
70
|
+
allExtensions: true,
|
|
71
|
+
allowNamespaces: true,
|
|
72
|
+
allowDeclareFields: true,
|
|
73
|
+
// aligns Babel's behavior with TypeScript's default behavior.
|
|
74
|
+
// https://babeljs.io/docs/en/babel-preset-typescript#optimizeconstenums
|
|
75
|
+
optimizeConstEnums: true,
|
|
76
|
+
...presetTypeScript
|
|
77
|
+
}
|
|
78
|
+
]);
|
|
79
|
+
}
|
|
80
|
+
if (pluginDecorators) {
|
|
81
|
+
var _config_plugins1;
|
|
82
|
+
(_config_plugins1 = config.plugins) === null || _config_plugins1 === void 0 ? void 0 : _config_plugins1.push([
|
|
83
|
+
require.resolve("@babel/plugin-proposal-decorators"),
|
|
84
|
+
{
|
|
85
|
+
// decoratorsBeforeExport property is not allowed when version is legacy
|
|
86
|
+
...pluginDecorators.version === "2018-09" ? {
|
|
87
|
+
decoratorsBeforeExport: true
|
|
88
|
+
} : {},
|
|
89
|
+
...pluginDecorators
|
|
90
|
+
}
|
|
91
|
+
]);
|
|
92
|
+
}
|
|
93
|
+
(_config_plugins = config.plugins) === null || _config_plugins === void 0 ? void 0 : _config_plugins.push(
|
|
94
|
+
// Stage 1
|
|
95
|
+
// link: https://github.com/tc39/proposal-export-default-from
|
|
96
|
+
require.resolve("@babel/plugin-proposal-export-default-from"),
|
|
97
|
+
// Stage 1
|
|
98
|
+
// link: https://github.com/tc39/proposal-partial-application
|
|
99
|
+
require.resolve("@babel/plugin-proposal-partial-application"),
|
|
100
|
+
// Stage 2
|
|
101
|
+
// link: https://github.com/tc39/proposal-pipeline-operator
|
|
102
|
+
[
|
|
103
|
+
require.resolve("@babel/plugin-proposal-pipeline-operator"),
|
|
104
|
+
{
|
|
105
|
+
proposal: "minimal"
|
|
106
|
+
}
|
|
107
|
+
]
|
|
108
|
+
);
|
|
109
|
+
return config;
|
|
110
|
+
};
|
|
111
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
112
|
+
0 && (module.exports = {
|
|
113
|
+
generateBaseConfig
|
|
114
|
+
});
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './types';
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __copyProps = (to, from, except, desc) => {
|
|
7
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
8
|
+
for (let key of __getOwnPropNames(from))
|
|
9
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
10
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
11
|
+
}
|
|
12
|
+
return to;
|
|
13
|
+
};
|
|
14
|
+
var __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
|
|
15
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
16
|
+
var src_exports = {};
|
|
17
|
+
module.exports = __toCommonJS(src_exports);
|
|
18
|
+
__reExport(src_exports, require("./types"), module.exports);
|
|
19
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
20
|
+
0 && (module.exports = {
|
|
21
|
+
...require("./types")
|
|
22
|
+
});
|
package/dist/node.d.ts
ADDED
package/dist/node.js
ADDED
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __export = (target, all) => {
|
|
9
|
+
for (var name in all)
|
|
10
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
|
+
};
|
|
12
|
+
var __copyProps = (to, from, except, desc) => {
|
|
13
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
|
+
for (let key of __getOwnPropNames(from))
|
|
15
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
16
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
17
|
+
}
|
|
18
|
+
return to;
|
|
19
|
+
};
|
|
20
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
+
mod
|
|
27
|
+
));
|
|
28
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
|
+
var node_exports = {};
|
|
30
|
+
__export(node_exports, {
|
|
31
|
+
default: () => node_default,
|
|
32
|
+
getBabelConfigForNode: () => getBabelConfigForNode
|
|
33
|
+
});
|
|
34
|
+
module.exports = __toCommonJS(node_exports);
|
|
35
|
+
var import_base = require("./base");
|
|
36
|
+
const getBabelConfigForNode = (options = {}) => {
|
|
37
|
+
var _config_plugins;
|
|
38
|
+
if (options.presetEnv !== false) {
|
|
39
|
+
var _options, _options_presetEnv;
|
|
40
|
+
var _presetEnv;
|
|
41
|
+
(_presetEnv = (_options = options).presetEnv) !== null && _presetEnv !== void 0 ? _presetEnv : _options.presetEnv = {};
|
|
42
|
+
var _targets;
|
|
43
|
+
(_targets = (_options_presetEnv = options.presetEnv).targets) !== null && _targets !== void 0 ? _targets : _options_presetEnv.targets = [
|
|
44
|
+
"node >= 16"
|
|
45
|
+
];
|
|
46
|
+
}
|
|
47
|
+
const config = (0, import_base.generateBaseConfig)(options);
|
|
48
|
+
(_config_plugins = config.plugins) === null || _config_plugins === void 0 ? void 0 : _config_plugins.push(require.resolve("babel-plugin-dynamic-import-node"));
|
|
49
|
+
return config;
|
|
50
|
+
};
|
|
51
|
+
function node_default(api, options = {}) {
|
|
52
|
+
api.cache(true);
|
|
53
|
+
return getBabelConfigForNode(options);
|
|
54
|
+
}
|
|
55
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
56
|
+
0 && (module.exports = {
|
|
57
|
+
getBabelConfigForNode
|
|
58
|
+
});
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __export = (target, all) => {
|
|
9
|
+
for (var name in all)
|
|
10
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
|
+
};
|
|
12
|
+
var __copyProps = (to, from, except, desc) => {
|
|
13
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
|
+
for (let key of __getOwnPropNames(from))
|
|
15
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
16
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
17
|
+
}
|
|
18
|
+
return to;
|
|
19
|
+
};
|
|
20
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
+
mod
|
|
27
|
+
));
|
|
28
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
|
+
var pluginLockCorejsVersion_exports = {};
|
|
30
|
+
__export(pluginLockCorejsVersion_exports, {
|
|
31
|
+
default: () => pluginLockCorejsVersion_default,
|
|
32
|
+
getCoreJsVersion: () => getCoreJsVersion
|
|
33
|
+
});
|
|
34
|
+
module.exports = __toCommonJS(pluginLockCorejsVersion_exports);
|
|
35
|
+
var import_node_fs = require("node:fs");
|
|
36
|
+
var import_node_path = __toESM(require("node:path"));
|
|
37
|
+
var t = __toESM(require("@babel/types"));
|
|
38
|
+
const CORE_JS_PKG_PATH = require.resolve("core-js/package.json");
|
|
39
|
+
const REWRITE_TARGETS = {
|
|
40
|
+
"@babel/runtime": import_node_path.default.dirname(require.resolve("@babel/runtime/package.json")),
|
|
41
|
+
"core-js": import_node_path.default.dirname(CORE_JS_PKG_PATH)
|
|
42
|
+
};
|
|
43
|
+
const matchedKey = (value) => Object.keys(REWRITE_TARGETS).find((name) => value.startsWith(`${name}/`));
|
|
44
|
+
const getCoreJsVersion = () => {
|
|
45
|
+
try {
|
|
46
|
+
const { version } = JSON.parse((0, import_node_fs.readFileSync)(CORE_JS_PKG_PATH, "utf-8"));
|
|
47
|
+
const [major, minor] = version.split(".");
|
|
48
|
+
return `${major}.${minor}`;
|
|
49
|
+
} catch (err) {
|
|
50
|
+
return "3";
|
|
51
|
+
}
|
|
52
|
+
};
|
|
53
|
+
var pluginLockCorejsVersion_default = (_) => {
|
|
54
|
+
return {
|
|
55
|
+
post({ path }) {
|
|
56
|
+
for (const node of path.node.body) {
|
|
57
|
+
if (t.isImportDeclaration(node)) {
|
|
58
|
+
const key = matchedKey(node.source.value);
|
|
59
|
+
if (key) {
|
|
60
|
+
node.source.value = node.source.value.replace(new RegExp(`^${key}\\/`), `${REWRITE_TARGETS[key]}/`);
|
|
61
|
+
}
|
|
62
|
+
} else if (t.isExpressionStatement(node) && t.isCallExpression(node.expression)) {
|
|
63
|
+
const { callee } = node.expression;
|
|
64
|
+
const source = node.expression.arguments[0];
|
|
65
|
+
if (t.isIdentifier(callee) && callee.name === "require") {
|
|
66
|
+
const key = matchedKey(source.value);
|
|
67
|
+
if (key) {
|
|
68
|
+
source.value = source.value.replace(new RegExp(`^${key}\\/`), `${REWRITE_TARGETS[key]}/`);
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
};
|
|
75
|
+
};
|
|
76
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
77
|
+
0 && (module.exports = {
|
|
78
|
+
getCoreJsVersion
|
|
79
|
+
});
|
package/dist/types.d.ts
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { PresetEnvOptions } from '@rsbuild/plugin-babel';
|
|
2
|
+
export type { TransformOptions as BabelConfig } from '@babel/core';
|
|
3
|
+
type DecoratorsVersion = '2023-05' | '2023-01' | '2022-03' | '2021-12' | '2018-09' | 'legacy';
|
|
4
|
+
export type PluginDecoratorsOptions = {
|
|
5
|
+
version: DecoratorsVersion;
|
|
6
|
+
decoratorsBeforeExport?: boolean;
|
|
7
|
+
};
|
|
8
|
+
export type BasePresetOptions = {
|
|
9
|
+
presetEnv?: PresetEnvOptions | false;
|
|
10
|
+
presetTypeScript?: Record<string, unknown> | false;
|
|
11
|
+
pluginDecorators?: PluginDecoratorsOptions | false;
|
|
12
|
+
};
|
|
13
|
+
export type WebPresetOptions = BasePresetOptions & {
|
|
14
|
+
pluginTransformRuntime?: Record<string, unknown> | false;
|
|
15
|
+
};
|
|
16
|
+
export type NodePresetOptions = BasePresetOptions & {};
|
package/dist/types.js
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __copyProps = (to, from, except, desc) => {
|
|
7
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
8
|
+
for (let key of __getOwnPropNames(from))
|
|
9
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
10
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
11
|
+
}
|
|
12
|
+
return to;
|
|
13
|
+
};
|
|
14
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
15
|
+
var types_exports = {};
|
|
16
|
+
module.exports = __toCommonJS(types_exports);
|
package/dist/web.d.ts
ADDED
package/dist/web.js
ADDED
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __export = (target, all) => {
|
|
9
|
+
for (var name in all)
|
|
10
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
|
+
};
|
|
12
|
+
var __copyProps = (to, from, except, desc) => {
|
|
13
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
|
+
for (let key of __getOwnPropNames(from))
|
|
15
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
16
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
17
|
+
}
|
|
18
|
+
return to;
|
|
19
|
+
};
|
|
20
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
+
mod
|
|
27
|
+
));
|
|
28
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
|
+
var web_exports = {};
|
|
30
|
+
__export(web_exports, {
|
|
31
|
+
default: () => web_default,
|
|
32
|
+
getBabelConfigForWeb: () => getBabelConfigForWeb
|
|
33
|
+
});
|
|
34
|
+
module.exports = __toCommonJS(web_exports);
|
|
35
|
+
var import_node_path = require("node:path");
|
|
36
|
+
var import_base = require("./base");
|
|
37
|
+
var import_pluginLockCorejsVersion = require("./pluginLockCorejsVersion");
|
|
38
|
+
const getDefaultPresetEnvOption = (options) => {
|
|
39
|
+
var _options_presetEnv;
|
|
40
|
+
if (options.presetEnv === false) {
|
|
41
|
+
return false;
|
|
42
|
+
}
|
|
43
|
+
return {
|
|
44
|
+
bugfixes: true,
|
|
45
|
+
// core-js is required for web target
|
|
46
|
+
corejs: ((_options_presetEnv = options.presetEnv) === null || _options_presetEnv === void 0 ? void 0 : _options_presetEnv.useBuiltIns) ? {
|
|
47
|
+
version: (0, import_pluginLockCorejsVersion.getCoreJsVersion)(),
|
|
48
|
+
proposals: true
|
|
49
|
+
} : void 0
|
|
50
|
+
};
|
|
51
|
+
};
|
|
52
|
+
const getBabelConfigForWeb = (options) => {
|
|
53
|
+
var _config_plugins;
|
|
54
|
+
if (options.presetEnv !== false) {
|
|
55
|
+
options.presetEnv = {
|
|
56
|
+
...getDefaultPresetEnvOption(options),
|
|
57
|
+
...options.presetEnv
|
|
58
|
+
};
|
|
59
|
+
}
|
|
60
|
+
const config = (0, import_base.generateBaseConfig)(options);
|
|
61
|
+
const { pluginTransformRuntime = {} } = options;
|
|
62
|
+
if (pluginTransformRuntime) {
|
|
63
|
+
var _config_plugins1;
|
|
64
|
+
(_config_plugins1 = config.plugins) === null || _config_plugins1 === void 0 ? void 0 : _config_plugins1.push([
|
|
65
|
+
require.resolve("@babel/plugin-transform-runtime"),
|
|
66
|
+
{
|
|
67
|
+
version: require("@babel/runtime/package.json").version,
|
|
68
|
+
// this option has been deprecated
|
|
69
|
+
// but enabling it can help to reduce bundle size
|
|
70
|
+
useESModules: true,
|
|
71
|
+
...pluginTransformRuntime
|
|
72
|
+
}
|
|
73
|
+
]);
|
|
74
|
+
}
|
|
75
|
+
(_config_plugins = config.plugins) === null || _config_plugins === void 0 ? void 0 : _config_plugins.push((0, import_node_path.join)(__dirname, "./pluginLockCorejsVersion.cjs"));
|
|
76
|
+
return config;
|
|
77
|
+
};
|
|
78
|
+
function web_default(api, options) {
|
|
79
|
+
api.cache(true);
|
|
80
|
+
return getBabelConfigForWeb(options);
|
|
81
|
+
}
|
|
82
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
83
|
+
0 && (module.exports = {
|
|
84
|
+
getBabelConfigForWeb
|
|
85
|
+
});
|
package/package.json
ADDED
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@modern-js/babel-preset",
|
|
3
|
+
"version": "0.0.0-nightly-20240715170628",
|
|
4
|
+
"description": "The babel config of Modern.js.",
|
|
5
|
+
"repository": {
|
|
6
|
+
"type": "git",
|
|
7
|
+
"url": "https://github.com/web-infra-dev/modern.js",
|
|
8
|
+
"directory": "packages/builder/uni-builder"
|
|
9
|
+
},
|
|
10
|
+
"license": "MIT",
|
|
11
|
+
"type": "commonjs",
|
|
12
|
+
"exports": {
|
|
13
|
+
".": {
|
|
14
|
+
"types": "./dist/index.d.ts",
|
|
15
|
+
"jsnext:source": "./src/index.ts",
|
|
16
|
+
"default": "./dist/index.js"
|
|
17
|
+
},
|
|
18
|
+
"./web": {
|
|
19
|
+
"types": "./dist/web.d.ts",
|
|
20
|
+
"jsnext:source": "./src/web.ts",
|
|
21
|
+
"default": "./dist/web.js"
|
|
22
|
+
},
|
|
23
|
+
"./node": {
|
|
24
|
+
"types": "./dist/node.d.ts",
|
|
25
|
+
"jsnext:source": "./src/node.ts",
|
|
26
|
+
"default": "./dist/node.js"
|
|
27
|
+
}
|
|
28
|
+
},
|
|
29
|
+
"main": "./dist/index.js",
|
|
30
|
+
"types": "./dist/index.d.ts",
|
|
31
|
+
"typesVersions": {
|
|
32
|
+
"*": {
|
|
33
|
+
".": [
|
|
34
|
+
"./dist/index.d.ts"
|
|
35
|
+
],
|
|
36
|
+
"web": [
|
|
37
|
+
"./dist/web.d.ts"
|
|
38
|
+
],
|
|
39
|
+
"node": [
|
|
40
|
+
"./dist/node.d.ts"
|
|
41
|
+
]
|
|
42
|
+
}
|
|
43
|
+
},
|
|
44
|
+
"files": [
|
|
45
|
+
"dist"
|
|
46
|
+
],
|
|
47
|
+
"dependencies": {
|
|
48
|
+
"@babel/core": "^7.24.7",
|
|
49
|
+
"@babel/plugin-proposal-decorators": "^7.24.7",
|
|
50
|
+
"@babel/plugin-proposal-export-default-from": "^7.24.7",
|
|
51
|
+
"@babel/plugin-proposal-partial-application": "^7.24.7",
|
|
52
|
+
"@babel/plugin-proposal-pipeline-operator": "^7.24.7",
|
|
53
|
+
"@babel/plugin-transform-runtime": "^7.24.7",
|
|
54
|
+
"@babel/preset-env": "^7.24.7",
|
|
55
|
+
"@babel/preset-typescript": "^7.24.7",
|
|
56
|
+
"@babel/runtime": "^7.24.7",
|
|
57
|
+
"@babel/types": "^7.24.7",
|
|
58
|
+
"@rsbuild/plugin-babel": "0.7.10",
|
|
59
|
+
"@swc/helpers": "0.5.3",
|
|
60
|
+
"@types/babel__core": "^7.20.5",
|
|
61
|
+
"babel-plugin-dynamic-import-node": "2.3.3",
|
|
62
|
+
"core-js": "~3.37.1"
|
|
63
|
+
},
|
|
64
|
+
"devDependencies": {
|
|
65
|
+
"@types/node": "18.x",
|
|
66
|
+
"typescript": "^5.3.0",
|
|
67
|
+
"@modern-js/tsconfig": "0.0.0-nightly-20240715170628",
|
|
68
|
+
"@scripts/build": "0.0.0-nightly-20240715170628",
|
|
69
|
+
"@scripts/vitest-config": "0.0.0-nightly-20240715170628"
|
|
70
|
+
},
|
|
71
|
+
"publishConfig": {
|
|
72
|
+
"access": "public",
|
|
73
|
+
"provenance": true,
|
|
74
|
+
"registry": "https://registry.npmjs.org/"
|
|
75
|
+
},
|
|
76
|
+
"scripts": {
|
|
77
|
+
"build": "modern-lib build",
|
|
78
|
+
"dev": "modern-lib build --watch",
|
|
79
|
+
"test": "vitest run",
|
|
80
|
+
"test:watch": "vitest dev"
|
|
81
|
+
}
|
|
82
|
+
}
|