@winner-fed/babel-preset-win 0.8.13-alpha.0
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/README.md +3 -0
- package/dist/index.d.ts +19 -0
- package/dist/index.js +185 -0
- package/dist/plugins/autoCSSModules.d.ts +8 -0
- package/dist/plugins/autoCSSModules.js +61 -0
- package/dist/plugins/dynamicImportNode.d.ts +3 -0
- package/dist/plugins/dynamicImportNode.js +81 -0
- package/dist/plugins/lockCoreJS.d.ts +3 -0
- package/dist/plugins/lockCoreJS.js +58 -0
- package/dist/plugins/stripExports.d.ts +3 -0
- package/dist/plugins/stripExports.js +113 -0
- package/package.json +27 -0
package/README.md
ADDED
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
interface IOpts {
|
|
2
|
+
presetEnv: any;
|
|
3
|
+
presetReact: any;
|
|
4
|
+
presetTypeScript: any;
|
|
5
|
+
pluginTransformRuntime: any;
|
|
6
|
+
pluginLockCoreJS: any;
|
|
7
|
+
pluginDynamicImportNode: any;
|
|
8
|
+
pluginAutoCSSModules: any;
|
|
9
|
+
stripExports: {
|
|
10
|
+
exports: string[];
|
|
11
|
+
};
|
|
12
|
+
classPropertiesLoose: any;
|
|
13
|
+
pluginDecorators: any;
|
|
14
|
+
}
|
|
15
|
+
declare const _default: (_context: any, opts: IOpts) => {
|
|
16
|
+
presets: (false | any[])[];
|
|
17
|
+
plugins: any[];
|
|
18
|
+
};
|
|
19
|
+
export default _default;
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,185 @@
|
|
|
1
|
+
var __create = Object.create;
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
6
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
+
var __export = (target, all) => {
|
|
8
|
+
for (var name in all)
|
|
9
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
10
|
+
};
|
|
11
|
+
var __copyProps = (to, from, except, desc) => {
|
|
12
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
13
|
+
for (let key of __getOwnPropNames(from))
|
|
14
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
15
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
16
|
+
}
|
|
17
|
+
return to;
|
|
18
|
+
};
|
|
19
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
20
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
21
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
22
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
23
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
24
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
25
|
+
mod
|
|
26
|
+
));
|
|
27
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
28
|
+
|
|
29
|
+
// src/index.ts
|
|
30
|
+
var src_exports = {};
|
|
31
|
+
__export(src_exports, {
|
|
32
|
+
default: () => src_default
|
|
33
|
+
});
|
|
34
|
+
module.exports = __toCommonJS(src_exports);
|
|
35
|
+
var import_utils = require("@winner-fed/utils");
|
|
36
|
+
var import_path = require("path");
|
|
37
|
+
var import_autoCSSModules = __toESM(require("./plugins/autoCSSModules"));
|
|
38
|
+
var import_dynamicImportNode = __toESM(require("./plugins/dynamicImportNode"));
|
|
39
|
+
var import_lockCoreJS = __toESM(require("./plugins/lockCoreJS"));
|
|
40
|
+
var import_stripExports = __toESM(require("./plugins/stripExports"));
|
|
41
|
+
var src_default = (_context, opts) => {
|
|
42
|
+
return {
|
|
43
|
+
presets: [
|
|
44
|
+
[
|
|
45
|
+
require.resolve("@winner-fed/bundler-utils/compiled/babel/preset-env"),
|
|
46
|
+
{
|
|
47
|
+
bugfixes: true,
|
|
48
|
+
// 更兼容 spec,但会变慢,所以不开
|
|
49
|
+
spec: false,
|
|
50
|
+
// 推荐用 top level 的 assumptions 配置
|
|
51
|
+
loose: false,
|
|
52
|
+
// 保留 es modules 语法,交给 webpack 处理
|
|
53
|
+
modules: false,
|
|
54
|
+
debug: false,
|
|
55
|
+
useBuiltIns: "entry",
|
|
56
|
+
corejs: (0, import_utils.getCorejsVersion)((0, import_path.join)(__dirname, "../package.json")),
|
|
57
|
+
// 没必要,遇到了应该改 targets 配置
|
|
58
|
+
forceAllTransforms: false,
|
|
59
|
+
ignoreBrowserslistConfig: true,
|
|
60
|
+
...opts.presetEnv
|
|
61
|
+
}
|
|
62
|
+
],
|
|
63
|
+
// 允许禁用 preset-react 用于支持 vue 等其他框架
|
|
64
|
+
opts.presetReact !== false && [
|
|
65
|
+
require.resolve("@winner-fed/bundler-utils/compiled/babel/preset-react"),
|
|
66
|
+
{
|
|
67
|
+
runtime: "automatic",
|
|
68
|
+
development: process.env.NODE_ENV === "development",
|
|
69
|
+
...opts.presetReact
|
|
70
|
+
}
|
|
71
|
+
],
|
|
72
|
+
[
|
|
73
|
+
require.resolve("@winner-fed/bundler-utils/compiled/babel/preset-typescript"),
|
|
74
|
+
{
|
|
75
|
+
allowNamespaces: true,
|
|
76
|
+
allowDeclareFields: true,
|
|
77
|
+
// Why false?
|
|
78
|
+
// 如果为 true,babel 只删除 import type 语句,会保留其他通过 import 引入的 type
|
|
79
|
+
// 这些 type 引用走到 webpack 之后,就会报错
|
|
80
|
+
onlyRemoveTypeImports: false,
|
|
81
|
+
optimizeConstEnums: true,
|
|
82
|
+
...opts.presetTypeScript
|
|
83
|
+
}
|
|
84
|
+
]
|
|
85
|
+
].filter(Boolean),
|
|
86
|
+
plugins: [
|
|
87
|
+
// TC39 Proposals
|
|
88
|
+
// class-static-block
|
|
89
|
+
// decorators
|
|
90
|
+
opts.pluginDecorators !== false && [
|
|
91
|
+
require.resolve("@winner-fed/bundler-utils/compiled/babel/plugin-proposal-decorators"),
|
|
92
|
+
{
|
|
93
|
+
legacy: true,
|
|
94
|
+
...opts.pluginDecorators
|
|
95
|
+
}
|
|
96
|
+
],
|
|
97
|
+
// Enable loose mode to use assignment instead of defineProperty
|
|
98
|
+
// Note:
|
|
99
|
+
// 'loose' mode configuration must be the same for
|
|
100
|
+
// * @babel/plugin-proposal-class-properties
|
|
101
|
+
// * @babel/plugin-proposal-private-methods
|
|
102
|
+
// * @babel/plugin-proposal-private-property-in-object
|
|
103
|
+
// (when they are enabled)
|
|
104
|
+
// ref: https://github.com/facebook/create-react-app/issues/4263
|
|
105
|
+
// ref: https://github.com/mobxjs/mobx/issues/1471
|
|
106
|
+
// ref: https://github.com/umijs/umi/issues/9396
|
|
107
|
+
// 不移动到 feature 里的原因是因为 decorators 有顺序要求
|
|
108
|
+
opts.classPropertiesLoose && [
|
|
109
|
+
require.resolve("@winner-fed/bundler-utils/compiled/babel/plugin-proposal-class-properties"),
|
|
110
|
+
{ loose: true }
|
|
111
|
+
],
|
|
112
|
+
opts.classPropertiesLoose && [
|
|
113
|
+
require.resolve("@winner-fed/bundler-utils/compiled/babel/plugin-proposal-private-methods"),
|
|
114
|
+
{
|
|
115
|
+
loose: true
|
|
116
|
+
}
|
|
117
|
+
],
|
|
118
|
+
opts.classPropertiesLoose && [
|
|
119
|
+
require.resolve("@winner-fed/bundler-utils/compiled/babel/plugin-proposal-private-property-in-object"),
|
|
120
|
+
{
|
|
121
|
+
loose: true
|
|
122
|
+
}
|
|
123
|
+
],
|
|
124
|
+
// do-expressions
|
|
125
|
+
[
|
|
126
|
+
require.resolve("@winner-fed/bundler-utils/compiled/babel/plugin-proposal-do-expressions")
|
|
127
|
+
],
|
|
128
|
+
// export-default-from
|
|
129
|
+
[
|
|
130
|
+
require.resolve("@winner-fed/bundler-utils/compiled/babel/plugin-proposal-export-default-from")
|
|
131
|
+
],
|
|
132
|
+
// export-namespace-from
|
|
133
|
+
[
|
|
134
|
+
require.resolve("@winner-fed/bundler-utils/compiled/babel/plugin-proposal-export-namespace-from")
|
|
135
|
+
],
|
|
136
|
+
// function-bind
|
|
137
|
+
[
|
|
138
|
+
require.resolve("@winner-fed/bundler-utils/compiled/babel/plugin-proposal-function-bind")
|
|
139
|
+
],
|
|
140
|
+
// function-sent
|
|
141
|
+
// partial-application
|
|
142
|
+
[
|
|
143
|
+
require.resolve("@winner-fed/bundler-utils/compiled/babel/plugin-proposal-partial-application")
|
|
144
|
+
],
|
|
145
|
+
// pipeline-operator
|
|
146
|
+
[
|
|
147
|
+
require.resolve("@winner-fed/bundler-utils/compiled/babel/plugin-proposal-pipeline-operator"),
|
|
148
|
+
{ proposal: "minimal" }
|
|
149
|
+
],
|
|
150
|
+
// throw-expressions
|
|
151
|
+
// record-and-tuple
|
|
152
|
+
[
|
|
153
|
+
require.resolve("@winner-fed/bundler-utils/compiled/babel/plugin-proposal-record-and-tuple"),
|
|
154
|
+
{
|
|
155
|
+
syntaxType: "hash",
|
|
156
|
+
importPolyfill: true,
|
|
157
|
+
polyfillModuleName: (0, import_path.dirname)(
|
|
158
|
+
require.resolve("@bloomberg/record-tuple-polyfill/package")
|
|
159
|
+
)
|
|
160
|
+
}
|
|
161
|
+
],
|
|
162
|
+
opts.pluginTransformRuntime && [
|
|
163
|
+
require.resolve("@winner-fed/bundler-utils/compiled/babel/plugin-transform-runtime"),
|
|
164
|
+
{
|
|
165
|
+
helpers: true,
|
|
166
|
+
regenerator: true,
|
|
167
|
+
// 7.13 之后根据 exports 自动选择 esm 和 cjs,无需此配置
|
|
168
|
+
useESModules: false,
|
|
169
|
+
// lock the version of @babel/runtime
|
|
170
|
+
// make sure we are using the correct version
|
|
171
|
+
// ref: https://github.com/babel/babel/blob/v7.16.12/packages/babel-plugin-transform-runtime/src/get-runtime-path/index.ts#L19
|
|
172
|
+
// ref: https://github.com/umijs/umi/pull/7816
|
|
173
|
+
absoluteRuntime: (0, import_path.dirname)(require.resolve("../package.json")),
|
|
174
|
+
version: `^${require("@babel/runtime/package.json").version}`,
|
|
175
|
+
...opts.pluginTransformRuntime
|
|
176
|
+
}
|
|
177
|
+
],
|
|
178
|
+
// none official plugins
|
|
179
|
+
opts.pluginLockCoreJS && [import_lockCoreJS.default],
|
|
180
|
+
opts.pluginDynamicImportNode && [import_dynamicImportNode.default],
|
|
181
|
+
opts.pluginAutoCSSModules && [import_autoCSSModules.default],
|
|
182
|
+
opts.stripExports && [import_stripExports.default]
|
|
183
|
+
].filter(Boolean)
|
|
184
|
+
};
|
|
185
|
+
};
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import * as Babel from '@winner-fed/bundler-utils/compiled/babel/core';
|
|
2
|
+
import * as t from '@winner-fed/bundler-utils/compiled/babel/types';
|
|
3
|
+
export default function (): {
|
|
4
|
+
visitor: {
|
|
5
|
+
ImportDeclaration(path: Babel.NodePath<t.ImportDeclaration>): void;
|
|
6
|
+
VariableDeclarator(path: Babel.NodePath<t.VariableDeclarator>): void;
|
|
7
|
+
};
|
|
8
|
+
};
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
var __create = Object.create;
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
6
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
+
var __export = (target, all) => {
|
|
8
|
+
for (var name in all)
|
|
9
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
10
|
+
};
|
|
11
|
+
var __copyProps = (to, from, except, desc) => {
|
|
12
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
13
|
+
for (let key of __getOwnPropNames(from))
|
|
14
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
15
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
16
|
+
}
|
|
17
|
+
return to;
|
|
18
|
+
};
|
|
19
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
20
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
21
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
22
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
23
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
24
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
25
|
+
mod
|
|
26
|
+
));
|
|
27
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
28
|
+
|
|
29
|
+
// src/plugins/autoCSSModules.ts
|
|
30
|
+
var autoCSSModules_exports = {};
|
|
31
|
+
__export(autoCSSModules_exports, {
|
|
32
|
+
default: () => autoCSSModules_default
|
|
33
|
+
});
|
|
34
|
+
module.exports = __toCommonJS(autoCSSModules_exports);
|
|
35
|
+
var t = __toESM(require("@winner-fed/bundler-utils/compiled/babel/types"));
|
|
36
|
+
var import_path = require("path");
|
|
37
|
+
var CSS_EXT_NAMES = [".css", ".less", ".sass", ".scss", ".stylus", ".styl"];
|
|
38
|
+
function autoCSSModules_default() {
|
|
39
|
+
return {
|
|
40
|
+
visitor: {
|
|
41
|
+
ImportDeclaration(path) {
|
|
42
|
+
const {
|
|
43
|
+
specifiers,
|
|
44
|
+
source,
|
|
45
|
+
source: { value }
|
|
46
|
+
} = path.node;
|
|
47
|
+
if (specifiers.length && CSS_EXT_NAMES.includes((0, import_path.extname)(value))) {
|
|
48
|
+
source.value = `${value}?modules`;
|
|
49
|
+
}
|
|
50
|
+
},
|
|
51
|
+
// e.g.
|
|
52
|
+
// const styles = await import('./index.less');
|
|
53
|
+
VariableDeclarator(path) {
|
|
54
|
+
const { node } = path;
|
|
55
|
+
if (t.isAwaitExpression(node.init) && t.isCallExpression(node.init.argument) && t.isImport(node.init.argument.callee) && node.init.argument.arguments.length === 1 && t.isStringLiteral(node.init.argument.arguments[0]) && CSS_EXT_NAMES.includes((0, import_path.extname)(node.init.argument.arguments[0].value))) {
|
|
56
|
+
node.init.argument.arguments[0].value = `${node.init.argument.arguments[0].value}?modules`;
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
};
|
|
61
|
+
}
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
var __create = Object.create;
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
6
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
+
var __export = (target, all) => {
|
|
8
|
+
for (var name in all)
|
|
9
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
10
|
+
};
|
|
11
|
+
var __copyProps = (to, from, except, desc) => {
|
|
12
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
13
|
+
for (let key of __getOwnPropNames(from))
|
|
14
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
15
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
16
|
+
}
|
|
17
|
+
return to;
|
|
18
|
+
};
|
|
19
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
20
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
21
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
22
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
23
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
24
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
25
|
+
mod
|
|
26
|
+
));
|
|
27
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
28
|
+
|
|
29
|
+
// src/plugins/dynamicImportNode.ts
|
|
30
|
+
var dynamicImportNode_exports = {};
|
|
31
|
+
__export(dynamicImportNode_exports, {
|
|
32
|
+
default: () => dynamicImportNode_default
|
|
33
|
+
});
|
|
34
|
+
module.exports = __toCommonJS(dynamicImportNode_exports);
|
|
35
|
+
var import_template = __toESM(require("@winner-fed/bundler-utils/compiled/babel/template"));
|
|
36
|
+
var t = __toESM(require("@winner-fed/bundler-utils/compiled/babel/types"));
|
|
37
|
+
function getImportSource(callNode) {
|
|
38
|
+
const importArguments = callNode.arguments;
|
|
39
|
+
const [importPath] = importArguments;
|
|
40
|
+
const isString2 = t.isStringLiteral(importPath) || t.isTemplateLiteral(importPath);
|
|
41
|
+
if (isString2) {
|
|
42
|
+
t.removeComments(importPath);
|
|
43
|
+
return importPath;
|
|
44
|
+
}
|
|
45
|
+
return t.templateLiteral(
|
|
46
|
+
[
|
|
47
|
+
t.templateElement({ raw: "", cooked: "" }),
|
|
48
|
+
t.templateElement({ raw: "", cooked: "" }, true)
|
|
49
|
+
],
|
|
50
|
+
importArguments
|
|
51
|
+
);
|
|
52
|
+
}
|
|
53
|
+
var builders = {
|
|
54
|
+
static: (0, import_template.default)("Promise.resolve().then(() => INTEROP(require(SOURCE)))"),
|
|
55
|
+
dynamic: (0, import_template.default)("Promise.resolve(SOURCE).then(s => INTEROP(require(s)))")
|
|
56
|
+
};
|
|
57
|
+
function isString(node) {
|
|
58
|
+
return t.isStringLiteral(node) || t.isTemplateLiteral(node) && node.expressions.length === 0;
|
|
59
|
+
}
|
|
60
|
+
var dynamicImportNode_default = () => {
|
|
61
|
+
const visited = /* @__PURE__ */ new WeakSet();
|
|
62
|
+
return {
|
|
63
|
+
visitor: {
|
|
64
|
+
Import(path) {
|
|
65
|
+
if (visited) {
|
|
66
|
+
if (visited.has(path)) {
|
|
67
|
+
return;
|
|
68
|
+
}
|
|
69
|
+
visited.add(path);
|
|
70
|
+
}
|
|
71
|
+
const SOURCE = getImportSource(path.parent);
|
|
72
|
+
const builder = isString(SOURCE) ? builders.static : builders.dynamic;
|
|
73
|
+
const newImport = builder({
|
|
74
|
+
SOURCE,
|
|
75
|
+
INTEROP: path.hub.addHelper("interopRequireWildcard")
|
|
76
|
+
});
|
|
77
|
+
path.parentPath.replaceWith(newImport);
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
};
|
|
81
|
+
};
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
var __create = Object.create;
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
6
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
+
var __export = (target, all) => {
|
|
8
|
+
for (var name in all)
|
|
9
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
10
|
+
};
|
|
11
|
+
var __copyProps = (to, from, except, desc) => {
|
|
12
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
13
|
+
for (let key of __getOwnPropNames(from))
|
|
14
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
15
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
16
|
+
}
|
|
17
|
+
return to;
|
|
18
|
+
};
|
|
19
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
20
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
21
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
22
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
23
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
24
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
25
|
+
mod
|
|
26
|
+
));
|
|
27
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
28
|
+
|
|
29
|
+
// src/plugins/lockCoreJS.ts
|
|
30
|
+
var lockCoreJS_exports = {};
|
|
31
|
+
__export(lockCoreJS_exports, {
|
|
32
|
+
default: () => lockCoreJS_default
|
|
33
|
+
});
|
|
34
|
+
module.exports = __toCommonJS(lockCoreJS_exports);
|
|
35
|
+
var t = __toESM(require("@winner-fed/bundler-utils/compiled/babel/types"));
|
|
36
|
+
var import_utils = require("@winner-fed/utils");
|
|
37
|
+
var import_path = require("path");
|
|
38
|
+
function addLastSlash(path) {
|
|
39
|
+
return path.endsWith("/") ? path : `${path}/`;
|
|
40
|
+
}
|
|
41
|
+
function lockCoreJS_default() {
|
|
42
|
+
return {
|
|
43
|
+
post({ path }) {
|
|
44
|
+
path.node.body.forEach((node) => {
|
|
45
|
+
if (t.isImportDeclaration(node)) {
|
|
46
|
+
if (node.source.value.startsWith("core-js/")) {
|
|
47
|
+
node.source.value = node.source.value.replace(
|
|
48
|
+
/^core-js\//,
|
|
49
|
+
addLastSlash(
|
|
50
|
+
(0, import_utils.winPath)((0, import_path.dirname)(require.resolve("core-js/package.json")))
|
|
51
|
+
)
|
|
52
|
+
);
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
});
|
|
56
|
+
}
|
|
57
|
+
};
|
|
58
|
+
}
|
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
var __create = Object.create;
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
6
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
+
var __export = (target, all) => {
|
|
8
|
+
for (var name in all)
|
|
9
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
10
|
+
};
|
|
11
|
+
var __copyProps = (to, from, except, desc) => {
|
|
12
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
13
|
+
for (let key of __getOwnPropNames(from))
|
|
14
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
15
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
16
|
+
}
|
|
17
|
+
return to;
|
|
18
|
+
};
|
|
19
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
20
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
21
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
22
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
23
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
24
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
25
|
+
mod
|
|
26
|
+
));
|
|
27
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
28
|
+
|
|
29
|
+
// src/plugins/stripExports.ts
|
|
30
|
+
var stripExports_exports = {};
|
|
31
|
+
__export(stripExports_exports, {
|
|
32
|
+
default: () => stripExports_default
|
|
33
|
+
});
|
|
34
|
+
module.exports = __toCommonJS(stripExports_exports);
|
|
35
|
+
var t = __toESM(require("@winner-fed/bundler-utils/compiled/babel/types"));
|
|
36
|
+
var stripExports_default = () => {
|
|
37
|
+
return {
|
|
38
|
+
visitor: {
|
|
39
|
+
Program: {
|
|
40
|
+
enter(path, { opts }) {
|
|
41
|
+
const expressions = path.get("body");
|
|
42
|
+
const exports = (opts == null ? void 0 : opts.exports) || [];
|
|
43
|
+
expressions.forEach((exp) => {
|
|
44
|
+
if (!(t.isExportNamedDeclaration(exp) || t.isExportDefaultDeclaration(exp)))
|
|
45
|
+
return;
|
|
46
|
+
handleExportsIndividual(exp);
|
|
47
|
+
handleExportsList(exp);
|
|
48
|
+
handleExportsDefault(exp);
|
|
49
|
+
});
|
|
50
|
+
function handleExportsIndividual(path2) {
|
|
51
|
+
if (!path2.node)
|
|
52
|
+
return;
|
|
53
|
+
if (!t.isExportNamedDeclaration(path2))
|
|
54
|
+
return;
|
|
55
|
+
if (!path2.get("declaration").node)
|
|
56
|
+
return;
|
|
57
|
+
const declaration = path2.get("declaration");
|
|
58
|
+
if (t.isVariableDeclaration(declaration)) {
|
|
59
|
+
const variables = declaration.get("declarations");
|
|
60
|
+
variables.forEach((variable) => {
|
|
61
|
+
exports.includes(variable.get("id.name").node) && variable.remove();
|
|
62
|
+
});
|
|
63
|
+
} else {
|
|
64
|
+
exports.includes(declaration.get("id.name").node) && declaration.remove();
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
function handleExportsList(path2) {
|
|
68
|
+
if (!path2.node)
|
|
69
|
+
return;
|
|
70
|
+
if (!t.isExportNamedDeclaration(path2))
|
|
71
|
+
return;
|
|
72
|
+
const specifiers = path2.get("specifiers");
|
|
73
|
+
if (!specifiers || specifiers.length === 0)
|
|
74
|
+
return;
|
|
75
|
+
specifiers.forEach((specifier) => {
|
|
76
|
+
if (exports.includes(specifier.get("exported.name").node))
|
|
77
|
+
specifier.remove();
|
|
78
|
+
});
|
|
79
|
+
if (path2.get("specifiers").length === 0)
|
|
80
|
+
path2.remove();
|
|
81
|
+
}
|
|
82
|
+
function handleExportsDefault(path2) {
|
|
83
|
+
if (!path2.node)
|
|
84
|
+
return;
|
|
85
|
+
if (!t.isExportDefaultDeclaration(path2))
|
|
86
|
+
return;
|
|
87
|
+
const declaration = path2.get("declaration");
|
|
88
|
+
if (!declaration.node)
|
|
89
|
+
return;
|
|
90
|
+
if (exports.includes(declaration.get("name").node))
|
|
91
|
+
declaration.remove();
|
|
92
|
+
}
|
|
93
|
+
},
|
|
94
|
+
exit(path) {
|
|
95
|
+
path.scope.crawl();
|
|
96
|
+
const expressions = path.get("body");
|
|
97
|
+
expressions.forEach((exp) => {
|
|
98
|
+
if (!t.isImportDeclaration(exp))
|
|
99
|
+
return;
|
|
100
|
+
const specifiers = exp.get("specifiers");
|
|
101
|
+
specifiers.forEach((s) => {
|
|
102
|
+
const name = s.get("local.name").node;
|
|
103
|
+
if (!s.scope.getBinding(name).referenced)
|
|
104
|
+
s.remove();
|
|
105
|
+
});
|
|
106
|
+
if (exp.get("specifiers").length === 0)
|
|
107
|
+
exp.remove();
|
|
108
|
+
});
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
};
|
|
113
|
+
};
|
package/package.json
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@winner-fed/babel-preset-win",
|
|
3
|
+
"version": "0.8.13-alpha.0",
|
|
4
|
+
"description": "Official babel preset for win.",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"main": "dist/index.js",
|
|
7
|
+
"types": "dist/index.d.ts",
|
|
8
|
+
"files": [
|
|
9
|
+
"dist"
|
|
10
|
+
],
|
|
11
|
+
"dependencies": {
|
|
12
|
+
"@babel/runtime": "7.23.6",
|
|
13
|
+
"@bloomberg/record-tuple-polyfill": "0.0.4",
|
|
14
|
+
"core-js": "3.34.0",
|
|
15
|
+
"@winner-fed/bundler-utils": "0.8.13-alpha.0",
|
|
16
|
+
"@winner-fed/utils": "0.8.13-alpha.0"
|
|
17
|
+
},
|
|
18
|
+
"publishConfig": {
|
|
19
|
+
"access": "public"
|
|
20
|
+
},
|
|
21
|
+
"scripts": {
|
|
22
|
+
"build": "win-scripts father build",
|
|
23
|
+
"build:deps": "win-scripts bundleDeps",
|
|
24
|
+
"dev": "win-scripts father dev",
|
|
25
|
+
"test": "win-scripts jest-turbo"
|
|
26
|
+
}
|
|
27
|
+
}
|