Skip to content

Commit d98960a

Browse files
committed
refactor: remove swcMinify version gate
1 parent b3939e4 commit d98960a

1 file changed

Lines changed: 0 additions & 52 deletions

File tree

src/utils.js

Lines changed: 0 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -658,40 +658,6 @@ async function swcMinify(input, sourceMap, minimizerOptions, extractComments) {
658658
};
659659
};
660660

661-
/**
662-
* @param {string | undefined} version swc version
663-
* @returns {boolean} true when the installed swc build supports comment extraction
664-
*/
665-
const hasExtractCommentsSupport = (version) => {
666-
if (!version) {
667-
return false;
668-
}
669-
670-
/**
671-
* @param {string} value version string
672-
* @returns {number[]} normalized semver parts
673-
*/
674-
const normalizeVersion = (value) =>
675-
value
676-
.split("-")[0]
677-
.split(".")
678-
.map((item) => Number.parseInt(item, 10) || 0);
679-
const currentVersion = normalizeVersion(version);
680-
const minimumVersion = normalizeVersion("1.15.30");
681-
682-
for (let i = 0; i < minimumVersion.length; i++) {
683-
if ((currentVersion[i] || 0) > minimumVersion[i]) {
684-
return true;
685-
}
686-
687-
if ((currentVersion[i] || 0) < minimumVersion[i]) {
688-
return false;
689-
}
690-
}
691-
692-
return true;
693-
};
694-
695661
/**
696662
* @param {PredefinedOptions<import("@swc/core").JsMinifyOptions> & import("@swc/core").JsMinifyOptions=} swcOptions swc options
697663
* @returns {SwcMinifyOptionsWithExtractComments & { sourceMap: undefined | boolean } & { compress: import("@swc/core").TerserCompressOptions }} built swc options
@@ -732,14 +698,6 @@ async function swcMinify(input, sourceMap, minimizerOptions, extractComments) {
732698
return { errors: [/** @type {Error} */ (err)] };
733699
}
734700

735-
let swcVersion;
736-
737-
try {
738-
({ version: swcVersion } = require("@swc/core/package.json"));
739-
} catch (_error) {
740-
// Ignore
741-
}
742-
743701
// Copy `swc` options
744702
const swcOptions = buildSwcOptions(minimizerOptions);
745703
const normalizedExtractComments = normalizeExtractComments(extractComments);
@@ -761,16 +719,6 @@ async function swcMinify(input, sourceMap, minimizerOptions, extractComments) {
761719
}
762720

763721
if (normalizedExtractComments.extractComments !== false) {
764-
if (!hasExtractCommentsSupport(swcVersion)) {
765-
return {
766-
errors: [
767-
new Error(
768-
`The 'extractComments' option for 'swcMinify' requires @swc/core >= 1.15.30${swcVersion ? ` (found ${swcVersion})` : ""}. Please upgrade @swc/core.`,
769-
),
770-
],
771-
};
772-
}
773-
774722
/** @type {SwcMinifyOptionsWithExtractComments} */ (
775723
swcOptions
776724
).extractComments = normalizedExtractComments.extractComments;

0 commit comments

Comments
 (0)