@modern-js/builder
Version:
Builder of modern.js.
74 lines (73 loc) • 3.21 kB
JavaScript
;
var __create = Object.create;
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __getProtoOf = Object.getPrototypeOf;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
for (var name in all)
__defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
if (from && typeof from === "object" || typeof from === "function") {
for (let key of __getOwnPropNames(from))
if (!__hasOwnProp.call(to, key) && key !== except)
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
}
return to;
};
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
// If the importer is in node compatibility mode or this is not an ESM
// file that has been converted to a CommonJS file using a Babel-
// compatible transform (i.e. "__esModule" has not been set), then set
// "default" to the CommonJS "module.exports" for node compatibility.
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
mod
));
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
var checkSyntax_exports = {};
__export(checkSyntax_exports, {
builderPluginCheckSyntax: () => builderPluginCheckSyntax
});
module.exports = __toCommonJS(checkSyntax_exports);
var import_builder_shared = require("@modern-js/builder-shared");
function builderPluginCheckSyntax() {
return {
name: "builder-plugin-check-syntax",
setup(api) {
api.modifyBundlerChain(async (chain, { isProd, target }) => {
const config = api.getNormalizedConfig();
const { checkSyntax } = config.security;
if (!isProd || [
"node",
"web-worker"
].includes(target) || !checkSyntax) {
return;
}
const targets = await getCheckTargets(api.context, config, target, checkSyntax);
const { CheckSyntaxPlugin } = await Promise.resolve().then(() => __toESM(require("@modern-js/builder-shared")));
chain.plugin(CheckSyntaxPlugin.name).use(CheckSyntaxPlugin, [
{
targets,
rootPath: api.context.rootPath,
...typeof checkSyntax === "object" ? checkSyntax : {}
}
]);
});
}
};
}
async function getCheckTargets(builderContext, builderConfig, builderTarget, checkSyntax) {
var _ref;
const browserslist = (_ref = await (0, import_builder_shared.getBrowserslistWithDefault)(builderContext.rootPath, builderConfig, builderTarget)) !== null && _ref !== void 0 ? _ref : import_builder_shared.DEFAULT_BROWSERSLIST[builderTarget];
if (checkSyntax === true) {
return browserslist;
}
var _checkSyntax_targets;
return (_checkSyntax_targets = checkSyntax.targets) !== null && _checkSyntax_targets !== void 0 ? _checkSyntax_targets : browserslist;
}
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
builderPluginCheckSyntax
});