@modern-js/builder
Version:
Builder of modern.js.
110 lines (109 loc) • 4.57 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 tsChecker_exports = {};
__export(tsChecker_exports, {
builderPluginTsChecker: () => builderPluginTsChecker
});
module.exports = __toCommonJS(tsChecker_exports);
var import_deepmerge = __toESM(require("deepmerge"));
const builderPluginTsChecker = () => {
return {
name: "builder-plugin-ts-checker",
setup(api) {
api.modifyBundlerChain(async (chain, { target }) => {
const config = api.getNormalizedConfig();
if (config.output.disableTsChecker || !api.context.tsconfigPath) {
return;
}
if (Array.isArray(api.context.target) && target !== api.context.target[0]) {
return;
}
const { default: ForkTsCheckerWebpackPlugin } = await Promise.resolve().then(() => __toESM(require("@modern-js/builder-shared/fork-ts-checker-webpack-plugin")));
const { logger, CHAIN_ID, applyOptionsChain } = await Promise.resolve().then(() => __toESM(require("@modern-js/utils")));
let typescriptPath;
try {
typescriptPath = require.resolve("typescript", {
paths: [
api.context.rootPath
]
});
} catch (err) {
logger.warn('"typescript" is not found in current project, Type Checker will not work.');
return;
}
const { experiments } = api.getNormalizedConfig();
var _experiments_sourceBuild;
const enableSourceBuild = (_experiments_sourceBuild = experiments === null || experiments === void 0 ? void 0 : experiments.sourceBuild) !== null && _experiments_sourceBuild !== void 0 ? _experiments_sourceBuild : false;
const tsCheckerOptions = applyOptionsChain({
typescript: {
// avoid OOM issue
memoryLimit: 8192,
// use tsconfig of user project
configFile: api.context.tsconfigPath,
typescriptPath,
// In source build mode, using the project reference generates a TS2307 error,
// so additional configuration of the tsChecker is required
...enableSourceBuild ? {
build: true,
mode: "readonly"
} : {}
},
issue: {
exclude: [
{
file: "**/*.(spec|test).ts"
},
{
file: "**/node_modules/**/*"
}
]
},
logger: {
log() {
},
error(message) {
console.error(message.replace(/ERROR/g, "Type Error"));
}
}
}, config.tools.tsChecker, void 0, import_deepmerge.default);
if (api.context.bundlerType === "rspack" && chain.get("mode") === "production") {
logger.info("ts checker running...");
logger.info("ts checker is running slowly and will block builds until it is complete, please be patient and wait.");
}
chain.plugin(CHAIN_ID.PLUGIN.TS_CHECKER).use(ForkTsCheckerWebpackPlugin, [
tsCheckerOptions
]);
});
}
};
};
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
builderPluginTsChecker
});