chore: merge branch from AnYiEE/AwesomeGadgets
这个提交包含在:
当前提交
11c2bb9fca
22
.babelrc
22
.babelrc
|
@ -1,22 +0,0 @@
|
|||
{
|
||||
"presets": [
|
||||
[
|
||||
"@babel/preset-env",
|
||||
{
|
||||
"bugfixes": true,
|
||||
"corejs": {
|
||||
"version": "3.33"
|
||||
},
|
||||
"exclude": ["es.array.push"],
|
||||
"modules": false,
|
||||
"useBuiltIns": "usage"
|
||||
}
|
||||
]
|
||||
],
|
||||
"plugins": [
|
||||
"@babel/plugin-transform-member-expression-literals",
|
||||
"@babel/plugin-transform-property-literals",
|
||||
"@babel/plugin-transform-reserved-words"
|
||||
],
|
||||
"compact": false
|
||||
}
|
|
@ -1,6 +1,5 @@
|
|||
# 注意:通常情况下不应修改此文件,如需修改,应先阅读 scripts/constant.ts 中`GLOBAL_REQUIRES_ES6`的相关说明
|
||||
# Note: Refrain from modifying this file under normal circumstances. If modification becomes necessary, refer to the instructions in scripts/constant.ts regarding `GLOBAL_REQUIRES_ES6` before proceeding
|
||||
|
||||
defaults
|
||||
# fully supports es5 and not dead
|
||||
# defaults and fully supports es6-module and not dead
|
||||
defaults
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
{
|
||||
"name": "awesome-gadgets",
|
||||
"version": "2.24.0",
|
||||
"version": "2.25.0",
|
||||
"description": "Storage, management, compilation, and automatic deployment of MediaWiki gadgets.",
|
||||
"private": true,
|
||||
"type": "module",
|
||||
|
|
|
@ -1,8 +1,9 @@
|
|||
import {BANNER, DEFAULT_DEFINITION, GLOBAL_REQUIRES_ES6, HEADER} from '../../constant';
|
||||
import type {DefaultDefinition, SourceFiles} from '../types';
|
||||
import babel, {type BabelFileResult} from '@babel/core';
|
||||
import babel, {type BabelFileResult, type PluginItem, type TransformOptions} from '@babel/core';
|
||||
import esbuild, {type OutputFile} from 'esbuild';
|
||||
import fs, {type PathOrFileDescriptor, type Stats} from 'node:fs';
|
||||
import PACKAGE from '../../../package.json' assert {type: 'json'};
|
||||
import chalk from 'chalk';
|
||||
import {esbuildOptions} from '../build-esbuild_options';
|
||||
import path from 'node:path';
|
||||
|
@ -73,8 +74,40 @@ const bundle = async (inputFilePath: string, code: string): Promise<string> => {
|
|||
return (buildResult.outputFiles as OutputFile[])[0].text;
|
||||
};
|
||||
|
||||
const generateTransformOptions = (): TransformOptions => {
|
||||
const transformOptions: TransformOptions = {
|
||||
presets: [
|
||||
[
|
||||
'@babel/preset-env',
|
||||
{
|
||||
bugfixes: true,
|
||||
corejs: {
|
||||
version: PACKAGE.devDependencies['core-js'].match(/\d+(?:.\d+){0,2}/)?.[0],
|
||||
},
|
||||
modules: false,
|
||||
useBuiltIns: 'usage',
|
||||
},
|
||||
],
|
||||
],
|
||||
compact: false,
|
||||
};
|
||||
|
||||
if (GLOBAL_REQUIRES_ES6) {
|
||||
(transformOptions.presets as NonNullable<PluginItem>)[0][1].exclude = ['es.array.push'];
|
||||
} else {
|
||||
transformOptions.plugins = [
|
||||
'@babel/plugin-transform-member-expression-literals',
|
||||
'@babel/plugin-transform-property-literals',
|
||||
'@babel/plugin-transform-reserved-words',
|
||||
];
|
||||
}
|
||||
|
||||
return transformOptions;
|
||||
};
|
||||
|
||||
const transform = async (inputFilePath: string, code: string): Promise<string> => {
|
||||
const babelFileResult: BabelFileResult = (await babel.transformAsync(code, {
|
||||
...generateTransformOptions(),
|
||||
cwd: __dirname,
|
||||
filename: inputFilePath,
|
||||
})) as BabelFileResult;
|
||||
|
|
正在加载...
在新工单中引用