bunchee 5.0.0-beta.5 → 5.0.0-beta.7
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/dist/bin/cli.js +1 -1
- package/dist/index.js +46 -34
- package/package.json +13 -15
package/dist/bin/cli.js
CHANGED
package/dist/index.js
CHANGED
|
@@ -249,10 +249,10 @@ const getMainFieldExportType = (pkg)=>{
|
|
|
249
249
|
// TODO: add unit test
|
|
250
250
|
const baseNameWithoutExtension = (filename)=>path__default.default.basename(filename, path__default.default.extname(filename));
|
|
251
251
|
const isTestFile = (filename)=>/\.(test|spec)$/.test(baseNameWithoutExtension(filename));
|
|
252
|
-
const memoize = (fn,
|
|
252
|
+
const memoize = (fn, cacheKey)=>{
|
|
253
253
|
const cache = new Map();
|
|
254
254
|
return (...args)=>{
|
|
255
|
-
const key =
|
|
255
|
+
const key = cacheKey ? typeof cacheKey === 'function' ? cacheKey(...args) : cacheKey : JSON.stringify({
|
|
256
256
|
args
|
|
257
257
|
});
|
|
258
258
|
const existing = cache.get(key);
|
|
@@ -264,6 +264,7 @@ const memoize = (fn, resolver)=>{
|
|
|
264
264
|
return result;
|
|
265
265
|
};
|
|
266
266
|
};
|
|
267
|
+
const memoizeByKey = (fn)=>(cacheKey)=>memoize(fn, cacheKey);
|
|
267
268
|
function joinRelativePath(...segments) {
|
|
268
269
|
let result = path__default.default.join(...segments);
|
|
269
270
|
// If the first segment starts with '.', ensure the result does too.
|
|
@@ -1051,6 +1052,44 @@ const swcMinifyOptions = {
|
|
|
1051
1052
|
toplevel: true
|
|
1052
1053
|
}
|
|
1053
1054
|
};
|
|
1055
|
+
async function createDtsPlugin(tsCompilerOptions, tsConfigPath, cwd) {
|
|
1056
|
+
const enableIncrementalWithoutBuildInfo = tsCompilerOptions.incremental && !tsCompilerOptions.tsBuildInfoFile;
|
|
1057
|
+
const incrementalOptions = enableIncrementalWithoutBuildInfo ? {
|
|
1058
|
+
incremental: false
|
|
1059
|
+
} : undefined;
|
|
1060
|
+
const compositeOptions = tsCompilerOptions.composite ? {
|
|
1061
|
+
composite: false
|
|
1062
|
+
} : undefined;
|
|
1063
|
+
const { options: overrideResolvedTsOptions } = await convertCompilerOptions(cwd, {
|
|
1064
|
+
declaration: true,
|
|
1065
|
+
noEmit: false,
|
|
1066
|
+
noEmitOnError: true,
|
|
1067
|
+
emitDeclarationOnly: true,
|
|
1068
|
+
checkJs: false,
|
|
1069
|
+
declarationMap: false,
|
|
1070
|
+
skipLibCheck: true,
|
|
1071
|
+
// preserveSymlinks should always be set to false to avoid issues with
|
|
1072
|
+
// resolving types from <reference> from node_modules
|
|
1073
|
+
preserveSymlinks: false,
|
|
1074
|
+
target: 'ESNext',
|
|
1075
|
+
...!tsCompilerOptions.jsx ? {
|
|
1076
|
+
jsx: 'react-jsx'
|
|
1077
|
+
} : undefined,
|
|
1078
|
+
// error TS5074: Option '--incremental' can only be specified using tsconfig, emitting to single
|
|
1079
|
+
// file or when option '--tsBuildInfoFile' is specified.
|
|
1080
|
+
...incrementalOptions,
|
|
1081
|
+
// error TS6379: Composite projects may not disable incremental compilation.
|
|
1082
|
+
...compositeOptions
|
|
1083
|
+
});
|
|
1084
|
+
const dtsPlugin = require('rollup-plugin-dts').default({
|
|
1085
|
+
tsconfig: tsConfigPath,
|
|
1086
|
+
compilerOptions: overrideResolvedTsOptions
|
|
1087
|
+
});
|
|
1088
|
+
return dtsPlugin;
|
|
1089
|
+
}
|
|
1090
|
+
// Avoid create multiple dts plugins instance and parsing the same tsconfig multi times,
|
|
1091
|
+
// This will avoid memory leak and performance issue.
|
|
1092
|
+
const memoizeDtsPluginByKey = memoizeByKey(createDtsPlugin);
|
|
1054
1093
|
/**
|
|
1055
1094
|
* return {
|
|
1056
1095
|
* <absolute source path>: <pkg>/<export>
|
|
@@ -1134,38 +1173,11 @@ async function buildInputConfig(entry, bundleConfig, exportCondition, buildConte
|
|
|
1134
1173
|
})
|
|
1135
1174
|
];
|
|
1136
1175
|
if (useTypeScript) {
|
|
1137
|
-
|
|
1138
|
-
|
|
1139
|
-
|
|
1140
|
-
|
|
1141
|
-
const
|
|
1142
|
-
composite: false
|
|
1143
|
-
} : undefined;
|
|
1144
|
-
const { options: overrideResolvedTsOptions } = await convertCompilerOptions(cwd, {
|
|
1145
|
-
declaration: true,
|
|
1146
|
-
noEmit: false,
|
|
1147
|
-
noEmitOnError: true,
|
|
1148
|
-
emitDeclarationOnly: true,
|
|
1149
|
-
checkJs: false,
|
|
1150
|
-
declarationMap: false,
|
|
1151
|
-
skipLibCheck: true,
|
|
1152
|
-
// preserveSymlinks should always be set to false to avoid issues with
|
|
1153
|
-
// resolving types from <reference> from node_modules
|
|
1154
|
-
preserveSymlinks: false,
|
|
1155
|
-
target: 'ESNext',
|
|
1156
|
-
...!tsCompilerOptions.jsx ? {
|
|
1157
|
-
jsx: 'react-jsx'
|
|
1158
|
-
} : undefined,
|
|
1159
|
-
// error TS5074: Option '--incremental' can only be specified using tsconfig, emitting to single
|
|
1160
|
-
// file or when option '--tsBuildInfoFile' is specified.
|
|
1161
|
-
...incrementalOptions,
|
|
1162
|
-
// error TS6379: Composite projects may not disable incremental compilation.
|
|
1163
|
-
...compositeOptions
|
|
1164
|
-
});
|
|
1165
|
-
const dtsPlugin = require('rollup-plugin-dts').default({
|
|
1166
|
-
tsconfig: tsConfigPath,
|
|
1167
|
-
compilerOptions: overrideResolvedTsOptions
|
|
1168
|
-
});
|
|
1176
|
+
// Each process should be unique
|
|
1177
|
+
// Each package build should be unique
|
|
1178
|
+
// Composing above factors into a unique cache key to retrieve the memoized dts plugin with tsconfigs
|
|
1179
|
+
const uniqueProcessId = 'dts-plugin:' + process.pid + (buildContext.pkg.name || '');
|
|
1180
|
+
const dtsPlugin = await memoizeDtsPluginByKey(uniqueProcessId)(tsCompilerOptions, tsConfigPath, cwd);
|
|
1169
1181
|
typesPlugins.push(dtsPlugin);
|
|
1170
1182
|
}
|
|
1171
1183
|
const plugins = (dts ? typesPlugins : [
|
package/package.json
CHANGED
|
@@ -1,22 +1,10 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "bunchee",
|
|
3
|
-
"version": "5.0.0-beta.
|
|
3
|
+
"version": "5.0.0-beta.7",
|
|
4
4
|
"description": "zero config bundler for js/ts/jsx libraries",
|
|
5
5
|
"bin": "./dist/bin/cli.js",
|
|
6
6
|
"main": "./dist/index.js",
|
|
7
7
|
"types": "./dist/index.d.ts",
|
|
8
|
-
"scripts": {
|
|
9
|
-
"test": "jest --env node",
|
|
10
|
-
"test:update": "TEST_UPDATE_SNAPSHOT=1 pnpm test",
|
|
11
|
-
"test:post": "POST_BUILD=1 pnpm jest test/compile.test.ts test/integration.test.ts",
|
|
12
|
-
"clean": "rm -rf ./dist",
|
|
13
|
-
"typecheck": "tsc --noEmit && tsc -p test/tsconfig.json --noEmit",
|
|
14
|
-
"prepublishOnly": "pnpm clean && pnpm build && chmod +x ./dist/bin/cli.js && pnpm test",
|
|
15
|
-
"tsx": "node -r @swc-node/register",
|
|
16
|
-
"build": "node -r @swc-node/register ./src/bin/index.ts --runtime node",
|
|
17
|
-
"format": "prettier --write .",
|
|
18
|
-
"prepare": "husky install"
|
|
19
|
-
},
|
|
20
8
|
"type": "commonjs",
|
|
21
9
|
"keywords": [
|
|
22
10
|
"bundler",
|
|
@@ -116,5 +104,15 @@
|
|
|
116
104
|
],
|
|
117
105
|
"testTimeout": 60000
|
|
118
106
|
},
|
|
119
|
-
"packageManager": "pnpm@8.8.0"
|
|
120
|
-
|
|
107
|
+
"packageManager": "pnpm@8.8.0",
|
|
108
|
+
"scripts": {
|
|
109
|
+
"test": "jest --env node",
|
|
110
|
+
"test:update": "TEST_UPDATE_SNAPSHOT=1 pnpm test",
|
|
111
|
+
"test:post": "POST_BUILD=1 pnpm jest test/compile.test.ts test/integration.test.ts",
|
|
112
|
+
"clean": "rm -rf ./dist",
|
|
113
|
+
"typecheck": "tsc --noEmit && tsc -p test/tsconfig.json --noEmit",
|
|
114
|
+
"tsx": "node -r @swc-node/register",
|
|
115
|
+
"build": "node -r @swc-node/register ./src/bin/index.ts --runtime node",
|
|
116
|
+
"format": "prettier --write ."
|
|
117
|
+
}
|
|
118
|
+
}
|