@savvy-web/rslib-builder 0.9.0 → 0.10.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +4 -0
- package/index.d.ts +156 -1
- package/index.js +124 -13
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -22,6 +22,10 @@ focus on your code.
|
|
|
22
22
|
cleaner public APIs, with multi-entry support for packages with multiple exports
|
|
23
23
|
- **Multi-Target Builds** - Separate dev (source maps) and npm (optimized)
|
|
24
24
|
outputs
|
|
25
|
+
- **Virtual Entries** - Bundle additional files (like pnpmfile.cjs) with custom
|
|
26
|
+
output names, bypassing type generation and package.json exports
|
|
27
|
+
- **Flexible Format** - Configure output format (ESM or CJS) at the library level
|
|
28
|
+
with per-entry overrides for virtual entries
|
|
25
29
|
- **PNPM Integration** - Automatically resolves `catalog:` and `workspace:`
|
|
26
30
|
references
|
|
27
31
|
- **Package.json Transform** - Converts `.ts` exports to `.js`, generates files
|
package/index.d.ts
CHANGED
|
@@ -395,6 +395,13 @@ export declare interface DtsPluginOptions {
|
|
|
395
395
|
* Used to generate the correct temp tsconfig when tsconfigPath is not provided.
|
|
396
396
|
*/
|
|
397
397
|
buildTarget?: "dev" | "npm";
|
|
398
|
+
/**
|
|
399
|
+
* Output format for the library.
|
|
400
|
+
* Affects the resolved tsconfig.json module settings:
|
|
401
|
+
* - `"esm"`: Uses ESNext module and Bundler resolution (default)
|
|
402
|
+
* - `"cjs"`: Uses CommonJS module and Node10 resolution
|
|
403
|
+
*/
|
|
404
|
+
format?: "esm" | "cjs";
|
|
398
405
|
/**
|
|
399
406
|
* Options for API model generation.
|
|
400
407
|
* When enabled, generates an `<unscopedPackageName>.api.json` file in the dist directory.
|
|
@@ -1055,6 +1062,17 @@ export declare type JsonPrimitive = string | number | boolean | null;
|
|
|
1055
1062
|
*/
|
|
1056
1063
|
export declare type JsonValue = JsonPrimitive | JsonObject | JsonArray;
|
|
1057
1064
|
|
|
1065
|
+
/**
|
|
1066
|
+
* Output format for library builds.
|
|
1067
|
+
*
|
|
1068
|
+
* @remarks
|
|
1069
|
+
* - `"esm"` - ES Modules format (sets `type: "module"` in package.json)
|
|
1070
|
+
* - `"cjs"` - CommonJS format (sets `type: "commonjs"` in package.json)
|
|
1071
|
+
*
|
|
1072
|
+
* @public
|
|
1073
|
+
*/
|
|
1074
|
+
export declare type LibraryFormat = "esm" | "cjs";
|
|
1075
|
+
|
|
1058
1076
|
/**
|
|
1059
1077
|
* Allows creating a union type by combining primitive types and literal types
|
|
1060
1078
|
* without sacrificing auto-completion in IDEs for the literal type part of the union.
|
|
@@ -1137,6 +1155,7 @@ export declare class NodeLibraryBuilder {
|
|
|
1137
1155
|
* Arrays are deep-copied to prevent mutation of this object.
|
|
1138
1156
|
*/
|
|
1139
1157
|
static readonly DEFAULT_OPTIONS: {
|
|
1158
|
+
format: "esm";
|
|
1140
1159
|
plugins: never[];
|
|
1141
1160
|
define: {};
|
|
1142
1161
|
copyPatterns: never[];
|
|
@@ -1179,12 +1198,65 @@ export declare class NodeLibraryBuilder {
|
|
|
1179
1198
|
* @returns Promise resolving to the RSLib configuration
|
|
1180
1199
|
*/
|
|
1181
1200
|
static createSingleTarget(target: BuildTarget, opts: NodeLibraryBuilderOptions): Promise<RslibConfig>;
|
|
1201
|
+
/**
|
|
1202
|
+
* Checks if the current package has exports defined in package.json.
|
|
1203
|
+
* @internal
|
|
1204
|
+
*/
|
|
1205
|
+
private static packageHasExports;
|
|
1182
1206
|
}
|
|
1183
1207
|
|
|
1184
1208
|
/**
|
|
1185
1209
|
* @public
|
|
1186
1210
|
*/
|
|
1187
1211
|
export declare interface NodeLibraryBuilderOptions {
|
|
1212
|
+
/**
|
|
1213
|
+
* Output format for main entry points.
|
|
1214
|
+
* Also determines package.json `type` field:
|
|
1215
|
+
* - `"esm"` → `"type": "module"`
|
|
1216
|
+
* - `"cjs"` → `"type": "commonjs"`
|
|
1217
|
+
*
|
|
1218
|
+
* @defaultValue `"esm"`
|
|
1219
|
+
*/
|
|
1220
|
+
format?: LibraryFormat;
|
|
1221
|
+
/**
|
|
1222
|
+
* Additional entry points bundled with custom output names.
|
|
1223
|
+
* These entries bypass type generation and package.json exports
|
|
1224
|
+
* but are included in the published package.
|
|
1225
|
+
*
|
|
1226
|
+
* @remarks
|
|
1227
|
+
* Virtual entries are useful for special files like pnpm config files
|
|
1228
|
+
* that need to be bundled but don't require type declarations or
|
|
1229
|
+
* exposure as package exports.
|
|
1230
|
+
*
|
|
1231
|
+
* A module may have ONLY virtualEntries with no regular entry points.
|
|
1232
|
+
*
|
|
1233
|
+
* @example
|
|
1234
|
+
* Mixed: regular entries + virtual entries
|
|
1235
|
+
* ```typescript
|
|
1236
|
+
* NodeLibraryBuilder.create({
|
|
1237
|
+
* virtualEntries: {
|
|
1238
|
+
* "pnpmfile.cjs": {
|
|
1239
|
+
* source: "./src/pnpmfile.ts",
|
|
1240
|
+
* format: "cjs",
|
|
1241
|
+
* },
|
|
1242
|
+
* },
|
|
1243
|
+
* })
|
|
1244
|
+
* ```
|
|
1245
|
+
*
|
|
1246
|
+
* @example
|
|
1247
|
+
* Virtual-only: no regular entry points
|
|
1248
|
+
* ```typescript
|
|
1249
|
+
* NodeLibraryBuilder.create({
|
|
1250
|
+
* format: "cjs",
|
|
1251
|
+
* virtualEntries: {
|
|
1252
|
+
* "pnpmfile.cjs": {
|
|
1253
|
+
* source: "./src/pnpmfile.ts",
|
|
1254
|
+
* },
|
|
1255
|
+
* },
|
|
1256
|
+
* })
|
|
1257
|
+
* ```
|
|
1258
|
+
*/
|
|
1259
|
+
virtualEntries?: Record<string, VirtualEntryConfig>;
|
|
1188
1260
|
/** Override entry points (optional - will auto-detect from package.json) */
|
|
1189
1261
|
entry?: Record<string, string | string[]>;
|
|
1190
1262
|
/**
|
|
@@ -1848,6 +1920,15 @@ export declare const PackageJsonTransformPlugin: (options?: PackageJsonTransform
|
|
|
1848
1920
|
* @public
|
|
1849
1921
|
*/
|
|
1850
1922
|
export declare interface PackageJsonTransformPluginOptions {
|
|
1923
|
+
/**
|
|
1924
|
+
* Output format for the library.
|
|
1925
|
+
* Determines the package.json `type` field:
|
|
1926
|
+
* - `"esm"` → `"type": "module"`
|
|
1927
|
+
* - `"cjs"` → `"type": "commonjs"`
|
|
1928
|
+
*
|
|
1929
|
+
* @defaultValue `"esm"`
|
|
1930
|
+
*/
|
|
1931
|
+
format?: LibraryFormat;
|
|
1851
1932
|
/**
|
|
1852
1933
|
* Override the package name in the output package.json.
|
|
1853
1934
|
*
|
|
@@ -2332,8 +2413,14 @@ export declare class TsconfigResolver {
|
|
|
2332
2413
|
* - Excludes file selection (include, exclude, files, references)
|
|
2333
2414
|
* - Adds $schema for IDE support
|
|
2334
2415
|
*
|
|
2416
|
+
* When `format` is `"cjs"`, the resolved config uses CommonJS-compatible settings:
|
|
2417
|
+
* - `module: "commonjs"`
|
|
2418
|
+
* - `moduleResolution: "node10"`
|
|
2419
|
+
* - `esModuleInterop: true`
|
|
2420
|
+
*
|
|
2335
2421
|
* @param parsed - The parsed TypeScript configuration from `parseJsonConfigFileContent`
|
|
2336
2422
|
* @param _rootDir - Reserved for future path normalization (currently unused)
|
|
2423
|
+
* @param format - Optional output format to adjust module settings (`"esm"` or `"cjs"`)
|
|
2337
2424
|
* @returns A JSON-serializable tsconfig object
|
|
2338
2425
|
* @throws {@link TsconfigResolverError} If resolution fails for any option
|
|
2339
2426
|
*
|
|
@@ -2353,7 +2440,7 @@ export declare class TsconfigResolver {
|
|
|
2353
2440
|
*
|
|
2354
2441
|
* @public
|
|
2355
2442
|
*/
|
|
2356
|
-
resolve(parsed: ParsedCommandLine, _rootDir: string): ResolvedTsconfig;
|
|
2443
|
+
resolve(parsed: ParsedCommandLine, _rootDir: string, format?: LibraryFormat): ResolvedTsconfig;
|
|
2357
2444
|
/**
|
|
2358
2445
|
* Adds converted enum options to the compiler options object.
|
|
2359
2446
|
* @internal
|
|
@@ -2933,4 +3020,72 @@ export declare class TsconfigResolver {
|
|
|
2933
3020
|
*/
|
|
2934
3021
|
export declare type TsDocTagGroup = "core" | "extended" | "discretionary";
|
|
2935
3022
|
|
|
3023
|
+
/**
|
|
3024
|
+
* Configuration for a virtual entry point.
|
|
3025
|
+
*
|
|
3026
|
+
* @remarks
|
|
3027
|
+
* Virtual entries are bundled entry points that bypass type generation
|
|
3028
|
+
* and package.json exports while still being included in the published package.
|
|
3029
|
+
*
|
|
3030
|
+
* @example
|
|
3031
|
+
* ```typescript
|
|
3032
|
+
* const config: VirtualEntryConfig = {
|
|
3033
|
+
* source: "./src/pnpmfile.ts",
|
|
3034
|
+
* format: "cjs",
|
|
3035
|
+
* };
|
|
3036
|
+
* ```
|
|
3037
|
+
*
|
|
3038
|
+
* @public
|
|
3039
|
+
*/
|
|
3040
|
+
export declare interface VirtualEntryConfig {
|
|
3041
|
+
/**
|
|
3042
|
+
* Path to source file (relative to package root).
|
|
3043
|
+
*/
|
|
3044
|
+
source: string;
|
|
3045
|
+
/**
|
|
3046
|
+
* Output format for this entry.
|
|
3047
|
+
* If not specified, inherits from top-level `format` option.
|
|
3048
|
+
*/
|
|
3049
|
+
format?: LibraryFormat;
|
|
3050
|
+
}
|
|
3051
|
+
|
|
3052
|
+
/**
|
|
3053
|
+
* Plugin to handle virtual entry points in RSlib builds.
|
|
3054
|
+
*
|
|
3055
|
+
* @remarks
|
|
3056
|
+
* Virtual entries are special entry points that:
|
|
3057
|
+
* - Are bundled like regular entries
|
|
3058
|
+
* - Do NOT generate TypeScript declarations (.d.ts files)
|
|
3059
|
+
* - Are NOT added to package.json exports
|
|
3060
|
+
* - ARE added to package.json files array for publishing
|
|
3061
|
+
*
|
|
3062
|
+
* This plugin:
|
|
3063
|
+
* 1. Exposes the virtual entry names for DtsPlugin to skip type generation
|
|
3064
|
+
* 2. Adds virtual entry outputs to the files array in the additional stage
|
|
3065
|
+
*
|
|
3066
|
+
* @example
|
|
3067
|
+
* ```typescript
|
|
3068
|
+
* import { VirtualEntryPlugin } from '@savvy-web/rslib-builder';
|
|
3069
|
+
*
|
|
3070
|
+
* const plugin = VirtualEntryPlugin({
|
|
3071
|
+
* virtualEntryNames: new Set(['pnpmfile']),
|
|
3072
|
+
* });
|
|
3073
|
+
* ```
|
|
3074
|
+
*
|
|
3075
|
+
* @public
|
|
3076
|
+
*/
|
|
3077
|
+
export declare const VirtualEntryPlugin: (options: VirtualEntryPluginOptions) => RsbuildPlugin;
|
|
3078
|
+
|
|
3079
|
+
/**
|
|
3080
|
+
* Options for the VirtualEntryPlugin.
|
|
3081
|
+
* @public
|
|
3082
|
+
*/
|
|
3083
|
+
export declare interface VirtualEntryPluginOptions {
|
|
3084
|
+
/**
|
|
3085
|
+
* Set of virtual entry names (without extensions).
|
|
3086
|
+
* Used by DtsPlugin to skip type generation for these entries.
|
|
3087
|
+
*/
|
|
3088
|
+
virtualEntryNames: Set<string>;
|
|
3089
|
+
}
|
|
3090
|
+
|
|
2936
3091
|
export { }
|
package/index.js
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
/*! For license information please see index.js.LICENSE.txt */
|
|
2
|
-
import { constants, existsSync, writeFileSync } from "node:fs";
|
|
2
|
+
import { constants, existsSync, readFileSync, writeFileSync } from "node:fs";
|
|
3
3
|
import { dirname, isAbsolute, join, normalize, relative, resolve as external_node_path_resolve } from "node:path";
|
|
4
4
|
import { defineConfig } from "@rslib/core";
|
|
5
5
|
import { access, copyFile, mkdir, readFile, readdir, rm, stat, unlink as promises_unlink, writeFile } from "node:fs/promises";
|
|
6
6
|
import { logger as core_logger } from "@rsbuild/core";
|
|
7
7
|
import picocolors from "picocolors";
|
|
8
|
-
import {
|
|
8
|
+
import { getWorkspaceManagerRoot } from "workspace-tools";
|
|
9
9
|
import { spawn } from "node:child_process";
|
|
10
10
|
import { StandardTags, Standardization, TSDocTagSyntaxKind } from "@microsoft/tsdoc";
|
|
11
11
|
import deep_equal from "deep-equal";
|
|
@@ -169,7 +169,7 @@ function getApiExtractorPath() {
|
|
|
169
169
|
const cwd = process.cwd();
|
|
170
170
|
const localApiExtractor = join(cwd, "node_modules", "@microsoft", "api-extractor");
|
|
171
171
|
if (existsSync(localApiExtractor)) return localApiExtractor;
|
|
172
|
-
const workspaceRoot =
|
|
172
|
+
const workspaceRoot = getWorkspaceManagerRoot(cwd);
|
|
173
173
|
if (workspaceRoot) {
|
|
174
174
|
const workspaceApiExtractor = join(workspaceRoot, "node_modules", "@microsoft", "api-extractor");
|
|
175
175
|
if (existsSync(workspaceApiExtractor)) return workspaceApiExtractor;
|
|
@@ -679,7 +679,7 @@ class TsconfigResolver {
|
|
|
679
679
|
const filename = lib.includes("/") || lib.includes("\\") ? lib.split(/[\\/]/).pop() ?? lib : lib;
|
|
680
680
|
return filename.replace(/^lib\./, "").replace(/\.d\.ts$/, "");
|
|
681
681
|
}
|
|
682
|
-
resolve(parsed, _rootDir) {
|
|
682
|
+
resolve(parsed, _rootDir, format) {
|
|
683
683
|
const opts = parsed.options;
|
|
684
684
|
const compilerOptions = {};
|
|
685
685
|
this.addEnumOptions(compilerOptions, opts);
|
|
@@ -688,6 +688,11 @@ class TsconfigResolver {
|
|
|
688
688
|
compilerOptions.noEmit = true;
|
|
689
689
|
this.addPreservedBooleanOptions(compilerOptions, opts);
|
|
690
690
|
this.addPreservedStringOptions(compilerOptions, opts);
|
|
691
|
+
if ("cjs" === format) {
|
|
692
|
+
compilerOptions.module = "commonjs";
|
|
693
|
+
compilerOptions.moduleResolution = "node10";
|
|
694
|
+
compilerOptions.esModuleInterop = true;
|
|
695
|
+
}
|
|
691
696
|
return {
|
|
692
697
|
$schema: TSCONFIG_SCHEMA_URL,
|
|
693
698
|
compilerOptions
|
|
@@ -836,7 +841,7 @@ function getTsgoBinPath() {
|
|
|
836
841
|
const cwd = process.cwd();
|
|
837
842
|
const localTsgoBin = join(cwd, "node_modules", ".bin", "tsgo");
|
|
838
843
|
if (existsSync(localTsgoBin)) return localTsgoBin;
|
|
839
|
-
const workspaceRoot =
|
|
844
|
+
const workspaceRoot = getWorkspaceManagerRoot(cwd);
|
|
840
845
|
if (workspaceRoot) {
|
|
841
846
|
const workspaceTsgoBin = join(workspaceRoot, "node_modules", ".bin", "tsgo");
|
|
842
847
|
if (existsSync(workspaceTsgoBin)) return workspaceTsgoBin;
|
|
@@ -1240,8 +1245,13 @@ function runTsgo(options) {
|
|
|
1240
1245
|
const extractor = new EntryExtractor();
|
|
1241
1246
|
const { entries } = extractor.extract(packageJson);
|
|
1242
1247
|
const entryPoints = new Map();
|
|
1248
|
+
const virtualEntryNames = api.useExposed("virtual-entry-names");
|
|
1243
1249
|
for (const [entryName, sourcePath] of Object.entries(entries)){
|
|
1244
1250
|
if (entryName.startsWith("bin/")) continue;
|
|
1251
|
+
if (virtualEntryNames?.has(entryName)) {
|
|
1252
|
+
log.global.info(`Skipping type generation for virtual entry: ${entryName}`);
|
|
1253
|
+
continue;
|
|
1254
|
+
}
|
|
1245
1255
|
if (!sourcePath.match(/\.(ts|mts|cts|tsx)$/)) continue;
|
|
1246
1256
|
if (sourcePath.includes(".test.") || sourcePath.includes("__test__")) continue;
|
|
1247
1257
|
const resolvedSourcePath = sourcePath.startsWith(".") ? join(cwd, sourcePath) : sourcePath;
|
|
@@ -1332,7 +1342,7 @@ function runTsgo(options) {
|
|
|
1332
1342
|
}
|
|
1333
1343
|
if (apiModelPath && state.parsedConfig && state.tsconfigPath) {
|
|
1334
1344
|
const resolver = new TsconfigResolver();
|
|
1335
|
-
const resolvedTsconfig = resolver.resolve(state.parsedConfig, cwd);
|
|
1345
|
+
const resolvedTsconfig = resolver.resolve(state.parsedConfig, cwd, options.format);
|
|
1336
1346
|
const tsconfigContent = `${JSON.stringify(resolvedTsconfig, null, "\t")}\n`;
|
|
1337
1347
|
const tsconfigSource = new context.sources.OriginalSource(tsconfigContent, "tsconfig.json");
|
|
1338
1348
|
context.compilation.emitAsset("tsconfig.json", tsconfigSource);
|
|
@@ -1578,7 +1588,7 @@ class PnpmCatalog {
|
|
|
1578
1588
|
async getCatalog() {
|
|
1579
1589
|
try {
|
|
1580
1590
|
if (!this.cachedWorkspaceRoot) {
|
|
1581
|
-
this.cachedWorkspaceRoot =
|
|
1591
|
+
this.cachedWorkspaceRoot = getWorkspaceManagerRoot(process.cwd());
|
|
1582
1592
|
if (!this.cachedWorkspaceRoot) throw new Error("Could not find workspace root - ensure you're in a workspace");
|
|
1583
1593
|
}
|
|
1584
1594
|
const workspaceFile = external_node_path_resolve(this.cachedWorkspaceRoot, "pnpm-workspace.yaml");
|
|
@@ -1864,6 +1874,7 @@ const PackageJsonTransformPlugin = (options = {})=>{
|
|
|
1864
1874
|
const processedPackageJson = await buildPackageJson(packageJson.data, isProduction, options.processTSExports, entrypoints, exportToOutputMap, options.bundle, options.transform);
|
|
1865
1875
|
packageJson.data = processedPackageJson;
|
|
1866
1876
|
if (options.forcePrivate) packageJson.data.private = true;
|
|
1877
|
+
if (options.format) packageJson.data.type = "esm" === options.format ? "module" : "commonjs";
|
|
1867
1878
|
const useRollupTypes = api.useExposed("use-rollup-types");
|
|
1868
1879
|
if (useRollupTypes && packageJson.data.exports && "object" == typeof packageJson.data.exports) {
|
|
1869
1880
|
const exports = packageJson.data.exports;
|
|
@@ -2302,12 +2313,35 @@ const TsDocLintPlugin = (options = {})=>{
|
|
|
2302
2313
|
}
|
|
2303
2314
|
};
|
|
2304
2315
|
};
|
|
2316
|
+
const VirtualEntryPlugin = (options)=>{
|
|
2317
|
+
const { virtualEntryNames } = options;
|
|
2318
|
+
return {
|
|
2319
|
+
name: "virtual-entry-plugin",
|
|
2320
|
+
setup (api) {
|
|
2321
|
+
api.expose("virtual-entry-names", virtualEntryNames);
|
|
2322
|
+
api.processAssets({
|
|
2323
|
+
stage: "additional"
|
|
2324
|
+
}, async (context)=>{
|
|
2325
|
+
let filesArray = api.useExposed("files-array");
|
|
2326
|
+
if (!filesArray) {
|
|
2327
|
+
filesArray = new Set();
|
|
2328
|
+
api.expose("files-array", filesArray);
|
|
2329
|
+
}
|
|
2330
|
+
for (const assetName of Object.keys(context.compilation.assets)){
|
|
2331
|
+
const baseName = assetName.replace(/\.(c|m)?js$/, "");
|
|
2332
|
+
if (virtualEntryNames.has(baseName)) filesArray.add(assetName);
|
|
2333
|
+
}
|
|
2334
|
+
});
|
|
2335
|
+
}
|
|
2336
|
+
};
|
|
2337
|
+
};
|
|
2305
2338
|
/* v8 ignore next -- @preserve */ class NodeLibraryBuilder {
|
|
2306
2339
|
static VALID_TARGETS = [
|
|
2307
2340
|
"dev",
|
|
2308
2341
|
"npm"
|
|
2309
2342
|
];
|
|
2310
2343
|
static DEFAULT_OPTIONS = {
|
|
2344
|
+
format: "esm",
|
|
2311
2345
|
plugins: [],
|
|
2312
2346
|
define: {},
|
|
2313
2347
|
copyPatterns: [],
|
|
@@ -2332,6 +2366,7 @@ const TsDocLintPlugin = (options = {})=>{
|
|
|
2332
2366
|
plugins: options.plugins ?? NodeLibraryBuilder.DEFAULT_OPTIONS.plugins,
|
|
2333
2367
|
define: options.define ?? NodeLibraryBuilder.DEFAULT_OPTIONS.define,
|
|
2334
2368
|
tsconfigPath: options.tsconfigPath,
|
|
2369
|
+
format: options.format ?? NodeLibraryBuilder.DEFAULT_OPTIONS.format,
|
|
2335
2370
|
targets: options.targets ?? NodeLibraryBuilder.DEFAULT_OPTIONS.targets,
|
|
2336
2371
|
externals: options.externals ?? NodeLibraryBuilder.DEFAULT_OPTIONS.externals,
|
|
2337
2372
|
apiModel: options.apiModel ?? NodeLibraryBuilder.DEFAULT_OPTIONS.apiModel,
|
|
@@ -2349,6 +2384,9 @@ const TsDocLintPlugin = (options = {})=>{
|
|
|
2349
2384
|
},
|
|
2350
2385
|
...void 0 !== options.transform && {
|
|
2351
2386
|
transform: options.transform
|
|
2387
|
+
},
|
|
2388
|
+
...void 0 !== options.virtualEntries && {
|
|
2389
|
+
virtualEntries: options.virtualEntries
|
|
2352
2390
|
}
|
|
2353
2391
|
};
|
|
2354
2392
|
return merged;
|
|
@@ -2387,10 +2425,12 @@ const TsDocLintPlugin = (options = {})=>{
|
|
|
2387
2425
|
target,
|
|
2388
2426
|
pkg
|
|
2389
2427
|
}) : void 0;
|
|
2428
|
+
const libraryFormat = options.format ?? "esm";
|
|
2390
2429
|
plugins.push(PackageJsonTransformPlugin({
|
|
2391
2430
|
forcePrivate: "dev" === target,
|
|
2392
2431
|
bundle: true,
|
|
2393
2432
|
target,
|
|
2433
|
+
format: libraryFormat,
|
|
2394
2434
|
...transformFn && {
|
|
2395
2435
|
transform: transformFn
|
|
2396
2436
|
}
|
|
@@ -2415,6 +2455,7 @@ const TsDocLintPlugin = (options = {})=>{
|
|
|
2415
2455
|
bundledPackages: options.dtsBundledPackages
|
|
2416
2456
|
},
|
|
2417
2457
|
buildTarget: target,
|
|
2458
|
+
format: libraryFormat,
|
|
2418
2459
|
...void 0 !== apiModelForTarget && {
|
|
2419
2460
|
apiModel: apiModelForTarget
|
|
2420
2461
|
}
|
|
@@ -2437,9 +2478,9 @@ const TsDocLintPlugin = (options = {})=>{
|
|
|
2437
2478
|
externals: options.externals
|
|
2438
2479
|
}
|
|
2439
2480
|
},
|
|
2440
|
-
format:
|
|
2481
|
+
format: libraryFormat,
|
|
2441
2482
|
experiments: {
|
|
2442
|
-
advancedEsm:
|
|
2483
|
+
advancedEsm: "esm" === libraryFormat
|
|
2443
2484
|
},
|
|
2444
2485
|
bundle: true,
|
|
2445
2486
|
plugins,
|
|
@@ -2456,10 +2497,70 @@ const TsDocLintPlugin = (options = {})=>{
|
|
|
2456
2497
|
}
|
|
2457
2498
|
}
|
|
2458
2499
|
};
|
|
2500
|
+
const hasRegularEntries = void 0 !== options.entry || NodeLibraryBuilder.packageHasExports();
|
|
2501
|
+
const virtualEntries = options.virtualEntries ?? {};
|
|
2502
|
+
const hasVirtualEntries = Object.keys(virtualEntries).length > 0;
|
|
2503
|
+
if (!hasRegularEntries && !hasVirtualEntries) throw new Error("No entry points configured. Provide package.json exports, explicit entry option, or virtualEntries.");
|
|
2504
|
+
const libConfigs = [];
|
|
2505
|
+
if (hasRegularEntries) libConfigs.push(lib);
|
|
2506
|
+
if (hasVirtualEntries) {
|
|
2507
|
+
const virtualByFormat = new Map();
|
|
2508
|
+
for (const [outputName, config] of Object.entries(virtualEntries)){
|
|
2509
|
+
const entryFormat = config.format ?? libraryFormat;
|
|
2510
|
+
if (!virtualByFormat.has(entryFormat)) virtualByFormat.set(entryFormat, new Map());
|
|
2511
|
+
const entryName = outputName.replace(/\.(c|m)?js$/, "");
|
|
2512
|
+
const formatMap = virtualByFormat.get(entryFormat);
|
|
2513
|
+
if (formatMap) formatMap.set(entryName, config.source);
|
|
2514
|
+
}
|
|
2515
|
+
for (const [format, entries] of virtualByFormat){
|
|
2516
|
+
const virtualEntryNames = new Set(entries.keys());
|
|
2517
|
+
const entryMap = Object.fromEntries(entries);
|
|
2518
|
+
const virtualLib = {
|
|
2519
|
+
id: `${target}-virtual-${format}`,
|
|
2520
|
+
format,
|
|
2521
|
+
bundle: true,
|
|
2522
|
+
output: {
|
|
2523
|
+
target: "node",
|
|
2524
|
+
cleanDistPath: false,
|
|
2525
|
+
sourceMap: false,
|
|
2526
|
+
distPath: {
|
|
2527
|
+
root: outputDir
|
|
2528
|
+
},
|
|
2529
|
+
...options.externals && options.externals.length > 0 && {
|
|
2530
|
+
externals: options.externals
|
|
2531
|
+
}
|
|
2532
|
+
},
|
|
2533
|
+
source: {
|
|
2534
|
+
entry: entryMap
|
|
2535
|
+
},
|
|
2536
|
+
plugins: [
|
|
2537
|
+
VirtualEntryPlugin({
|
|
2538
|
+
virtualEntryNames
|
|
2539
|
+
}),
|
|
2540
|
+
FilesArrayPlugin({
|
|
2541
|
+
target
|
|
2542
|
+
})
|
|
2543
|
+
]
|
|
2544
|
+
};
|
|
2545
|
+
libConfigs.push(virtualLib);
|
|
2546
|
+
}
|
|
2547
|
+
if (hasRegularEntries) {
|
|
2548
|
+
const allVirtualEntryNames = new Set();
|
|
2549
|
+
for (const outputName of Object.keys(virtualEntries)){
|
|
2550
|
+
const entryName = outputName.replace(/\.(c|m)?js$/, "");
|
|
2551
|
+
allVirtualEntryNames.add(entryName);
|
|
2552
|
+
}
|
|
2553
|
+
plugins.push({
|
|
2554
|
+
name: "virtual-entry-names-exposer",
|
|
2555
|
+
setup (api) {
|
|
2556
|
+
api.expose("virtual-entry-names", allVirtualEntryNames);
|
|
2557
|
+
}
|
|
2558
|
+
});
|
|
2559
|
+
lib.plugins = plugins;
|
|
2560
|
+
}
|
|
2561
|
+
}
|
|
2459
2562
|
return defineConfig({
|
|
2460
|
-
lib:
|
|
2461
|
-
lib
|
|
2462
|
-
],
|
|
2563
|
+
lib: libConfigs,
|
|
2463
2564
|
...options.tsconfigPath && {
|
|
2464
2565
|
source: {
|
|
2465
2566
|
tsconfigPath: options.tsconfigPath
|
|
@@ -2472,5 +2573,15 @@ const TsDocLintPlugin = (options = {})=>{
|
|
|
2472
2573
|
}
|
|
2473
2574
|
});
|
|
2474
2575
|
}
|
|
2576
|
+
static packageHasExports() {
|
|
2577
|
+
try {
|
|
2578
|
+
const packageJsonPath = join(process.cwd(), "package.json");
|
|
2579
|
+
const packageJson = JSON.parse(readFileSync(packageJsonPath, "utf-8"));
|
|
2580
|
+
const { exports } = packageJson;
|
|
2581
|
+
return null != exports && "object" == typeof exports && Object.keys(exports).length > 0;
|
|
2582
|
+
} catch {
|
|
2583
|
+
return false;
|
|
2584
|
+
}
|
|
2585
|
+
}
|
|
2475
2586
|
}
|
|
2476
|
-
export { AutoEntryPlugin, DtsPlugin, EntryExtractor, FilesArrayPlugin, ImportGraph, NodeLibraryBuilder, PackageJsonTransformPlugin, TsDocConfigBuilder, TsDocLintPlugin, TsconfigResolver, TsconfigResolverError, extractEntriesFromPackageJson };
|
|
2587
|
+
export { AutoEntryPlugin, DtsPlugin, EntryExtractor, FilesArrayPlugin, ImportGraph, NodeLibraryBuilder, PackageJsonTransformPlugin, TsDocConfigBuilder, TsDocLintPlugin, TsconfigResolver, TsconfigResolverError, VirtualEntryPlugin, extractEntriesFromPackageJson };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@savvy-web/rslib-builder",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.10.0",
|
|
4
4
|
"private": false,
|
|
5
5
|
"description": "RSlib-based build system for Node.js libraries with automatic package.json transformation, TypeScript declaration bundling, and multi-target support",
|
|
6
6
|
"keywords": [
|
|
@@ -54,7 +54,7 @@
|
|
|
54
54
|
"picocolors": "^1.1.1",
|
|
55
55
|
"sort-package-json": "^3.6.1",
|
|
56
56
|
"tmp": "^0.2.5",
|
|
57
|
-
"workspace-tools": "^0.
|
|
57
|
+
"workspace-tools": "^0.41.0",
|
|
58
58
|
"yaml": "^2.8.2"
|
|
59
59
|
},
|
|
60
60
|
"peerDependencies": {
|