@undercroft/lib-tools
Version:
A CLI toolkit for building, testing, and releasing Undercroft libraries
131 lines (125 loc) • 3.4 kB
JavaScript
// src/config/rollup-config.ts
import resolve from "@rollup/plugin-node-resolve";
import commonjs from "@rollup/plugin-commonjs";
import terser from "@rollup/plugin-terser";
import { codecovRollupPlugin } from "@codecov/rollup-plugin";
function withUndercroftRollupConfig(config) {
return {
input: "dist/index.js",
output: {
file: "dist/index.umd.js",
format: "umd",
name: config.name,
sourcemap: true,
globals: {
...config?.globals || {}
}
},
plugins: [
...config?.plugins || [],
resolve({
preferBuiltins: false
}),
commonjs(),
terser(),
codecovRollupPlugin({
enableBundleAnalysis: Boolean(process.env.CODECOV_TOKEN),
bundleName: process.env.CODECOV_BUNDLE || config.bundle,
uploadToken: process.env.CODECOV_TOKEN
})
],
external: config?.external || []
};
}
// src/config/tsup-config.ts
function withUndercroftTsupConfig(userOptions) {
return {
entry: ["src/index.ts"],
format: ["esm", "cjs"],
target: "node18",
sourcemap: true,
clean: true,
dts: true,
minify: true,
...userOptions
};
}
// src/config/jest-config.ts
import { createRequire } from "node:module";
var require2 = createRequire(import.meta.url);
function withUndercroftJestConfig(options = {}) {
const transformerPath = require2.resolve("@undercroft/lib-tools/config/fileTransformer");
return {
roots: options.roots || ["<rootDir>"],
testPathIgnorePatterns: ["/node_modules/", "/dist/"],
testMatch: [
"**/__tests__/**/*.+(ts|tsx|js)",
"**/?(*.)+(spec|test).+(ts|tsx|js)"
],
transform: {
"^.+\\.(ts|tsx)$": "ts-jest",
"\\.(jpg|jpeg|png|gif|eot|otf|webp|svg|ttf|woff|woff2|mp4|webm|wav|mp3|m4a|aac|oga)$": transformerPath
},
globals: {
"ts-jest": {
tsconfig: options.tsconfig || "tsconfig.json"
}
},
coverageThreshold: options.coverageThreshold || {
global: {
branches: 100,
functions: 100,
lines: 100,
statements: 100
}
}
};
}
// src/config/size-limit-config.ts
function withUndercroftSizeLimitConfig(overrides = []) {
const base = [
{ path: "dist/index.js", limit: "5 KB" },
{ path: "dist/index.mjs", limit: "5 KB" },
{ path: "dist/index.umd.js", limit: "5 KB" },
{ path: "dist/index.d.mts", limit: "15 B" },
{ path: "dist/index.d.ts", limit: "15 B" }
];
const merged = [...base];
for (const override of overrides) {
const index = merged.findIndex((entry) => entry.path === override.path);
if (index >= 0) {
merged[index] = { ...merged[index], ...override };
} else {
merged.push(override);
}
}
return merged;
}
// src/config/prettier-config.ts
function withUndercroftPrettierConfig(config = {}) {
return {
semi: true,
singleQuote: true,
trailingComma: "all",
arrowParens: "always",
printWidth: 80,
endOfLine: "auto",
...config
};
}
// src/config/index.ts
var index_default = {
withUndercroftRollupConfig,
withUndercroftTsupConfig,
withUndercroftJestConfig,
withUndercroftSizeLimitConfig,
withUndercroftPrettierConfig
};
export {
index_default as default,
withUndercroftJestConfig,
withUndercroftPrettierConfig,
withUndercroftRollupConfig,
withUndercroftSizeLimitConfig,
withUndercroftTsupConfig
};