@savvy-web/rslib-builder 0.13.1 → 0.14.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 +1 -5
- package/index.d.ts +10 -0
- package/index.js +32 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -19,11 +19,7 @@ Build modern ESM Node.js libraries with minimal configuration. Handles TypeScrip
|
|
|
19
19
|
## Installation
|
|
20
20
|
|
|
21
21
|
```bash
|
|
22
|
-
npm install --save-dev
|
|
23
|
-
@savvy-web/rslib-builder \
|
|
24
|
-
@rslib/core \
|
|
25
|
-
@microsoft/api-extractor \
|
|
26
|
-
@typescript/native-preview
|
|
22
|
+
npm install --save-dev @savvy-web/rslib-builder @rslib/core @microsoft/api-extractor @typescript/native-preview
|
|
27
23
|
```
|
|
28
24
|
|
|
29
25
|
## Quick Start
|
package/index.d.ts
CHANGED
|
@@ -1179,6 +1179,7 @@ export declare class NodeLibraryBuilder {
|
|
|
1179
1179
|
externals: never[];
|
|
1180
1180
|
apiModel: true;
|
|
1181
1181
|
bundle: true;
|
|
1182
|
+
cjsInterop: false;
|
|
1182
1183
|
};
|
|
1183
1184
|
/**
|
|
1184
1185
|
* Merges user-provided options with default options.
|
|
@@ -1543,6 +1544,15 @@ export declare interface NodeLibraryBuilderOptions {
|
|
|
1543
1544
|
* @defaultValue true
|
|
1544
1545
|
*/
|
|
1545
1546
|
bundle?: boolean;
|
|
1547
|
+
/**
|
|
1548
|
+
* Enable CJS default export interop for CommonJS output files.
|
|
1549
|
+
* When true, CJS files are patched so `require('module')` returns
|
|
1550
|
+
* the default export directly instead of `{ default: value }`.
|
|
1551
|
+
* Named exports are preserved as properties on the default value.
|
|
1552
|
+
* Only affects CJS format output; ESM is unchanged.
|
|
1553
|
+
* @defaultValue false
|
|
1554
|
+
*/
|
|
1555
|
+
cjsInterop?: boolean;
|
|
1546
1556
|
}
|
|
1547
1557
|
|
|
1548
1558
|
/**
|
package/index.js
CHANGED
|
@@ -2688,6 +2688,20 @@ const VirtualEntryPlugin = (options)=>{
|
|
|
2688
2688
|
}
|
|
2689
2689
|
};
|
|
2690
2690
|
};
|
|
2691
|
+
const CJS_INTEROP_FOOTER = `
|
|
2692
|
+
if (module.exports && module.exports.__esModule && 'default' in module.exports) {
|
|
2693
|
+
var _def = module.exports.default;
|
|
2694
|
+
if (_def !== null && _def !== undefined && (typeof _def === 'object' || typeof _def === 'function')) {
|
|
2695
|
+
var _keys = Object.keys(module.exports);
|
|
2696
|
+
for (var _i = 0; _i < _keys.length; _i++) {
|
|
2697
|
+
var _key = _keys[_i];
|
|
2698
|
+
if (_key !== 'default' && _key !== '__esModule' && !(_key in _def)) {
|
|
2699
|
+
_def[_key] = module.exports[_key];
|
|
2700
|
+
}
|
|
2701
|
+
}
|
|
2702
|
+
}
|
|
2703
|
+
module.exports = _def;
|
|
2704
|
+
}`;
|
|
2691
2705
|
/* v8 ignore next -- @preserve */ class NodeLibraryBuilder {
|
|
2692
2706
|
static VALID_TARGETS = [
|
|
2693
2707
|
"dev",
|
|
@@ -2704,7 +2718,8 @@ const VirtualEntryPlugin = (options)=>{
|
|
|
2704
2718
|
],
|
|
2705
2719
|
externals: [],
|
|
2706
2720
|
apiModel: true,
|
|
2707
|
-
bundle: true
|
|
2721
|
+
bundle: true,
|
|
2722
|
+
cjsInterop: false
|
|
2708
2723
|
};
|
|
2709
2724
|
static mergeOptions(options = {}) {
|
|
2710
2725
|
const copyPatterns = [
|
|
@@ -2725,6 +2740,7 @@ const VirtualEntryPlugin = (options)=>{
|
|
|
2725
2740
|
externals: options.externals ?? NodeLibraryBuilder.DEFAULT_OPTIONS.externals,
|
|
2726
2741
|
apiModel: options.apiModel ?? NodeLibraryBuilder.DEFAULT_OPTIONS.apiModel,
|
|
2727
2742
|
bundle: options.bundle ?? NodeLibraryBuilder.DEFAULT_OPTIONS.bundle,
|
|
2743
|
+
cjsInterop: options.cjsInterop ?? NodeLibraryBuilder.DEFAULT_OPTIONS.cjsInterop,
|
|
2728
2744
|
...void 0 !== options.entry && {
|
|
2729
2745
|
entry: options.entry
|
|
2730
2746
|
},
|
|
@@ -2910,6 +2926,11 @@ const VirtualEntryPlugin = (options)=>{
|
|
|
2910
2926
|
entry
|
|
2911
2927
|
},
|
|
2912
2928
|
define: sourceDefine
|
|
2929
|
+
},
|
|
2930
|
+
...options.cjsInterop && "cjs" === primaryFormat && {
|
|
2931
|
+
footer: {
|
|
2932
|
+
js: CJS_INTEROP_FOOTER
|
|
2933
|
+
}
|
|
2913
2934
|
}
|
|
2914
2935
|
};
|
|
2915
2936
|
const hasRegularEntries = void 0 !== options.entry || NodeLibraryBuilder.packageHasExports();
|
|
@@ -2973,6 +2994,11 @@ const VirtualEntryPlugin = (options)=>{
|
|
|
2973
2994
|
entry
|
|
2974
2995
|
},
|
|
2975
2996
|
define: sourceDefine
|
|
2997
|
+
},
|
|
2998
|
+
...options.cjsInterop && "cjs" === secondaryFormat && {
|
|
2999
|
+
footer: {
|
|
3000
|
+
js: CJS_INTEROP_FOOTER
|
|
3001
|
+
}
|
|
2976
3002
|
}
|
|
2977
3003
|
};
|
|
2978
3004
|
libConfigs.push(secondaryLib);
|
|
@@ -3038,6 +3064,11 @@ const VirtualEntryPlugin = (options)=>{
|
|
|
3038
3064
|
tsconfigPath: options.tsconfigPath
|
|
3039
3065
|
},
|
|
3040
3066
|
define: sourceDefine
|
|
3067
|
+
},
|
|
3068
|
+
...options.cjsInterop && "cjs" === overrideFormat && {
|
|
3069
|
+
footer: {
|
|
3070
|
+
js: CJS_INTEROP_FOOTER
|
|
3071
|
+
}
|
|
3041
3072
|
}
|
|
3042
3073
|
};
|
|
3043
3074
|
libConfigs.push(overrideLib);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@savvy-web/rslib-builder",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.14.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": [
|