bunchee 6.11.0 → 6.12.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 +7 -0
- package/dist/bin/cli.js +1 -1
- package/dist/index.js +67 -14
- package/package.json +8 -6
package/README.md
CHANGED
|
@@ -28,6 +28,13 @@ By using the standard `exports` configuration as the single source of truth, **b
|
|
|
28
28
|
npm install --save-dev bunchee typescript
|
|
29
29
|
```
|
|
30
30
|
|
|
31
|
+
> [!NOTE]
|
|
32
|
+
> TypeScript 7+ compiles natively and its `typescript` package no longer ships the JavaScript compiler API used for generating type declarations. If you're on TypeScript 7 or above, also install the official compat API package [`@typescript/typescript6`](https://www.npmjs.com/package/@typescript/typescript6) and `bunchee` will pick it up automatically:
|
|
33
|
+
>
|
|
34
|
+
> ```sh
|
|
35
|
+
> npm install --save-dev @typescript/typescript6
|
|
36
|
+
> ```
|
|
37
|
+
|
|
31
38
|
### Configuration
|
|
32
39
|
|
|
33
40
|
Create entry files of your library and `package.json`.
|
package/dist/bin/cli.js
CHANGED
|
@@ -855,7 +855,7 @@ async function lint$1(cwd) {
|
|
|
855
855
|
}
|
|
856
856
|
}
|
|
857
857
|
|
|
858
|
-
var version = "6.
|
|
858
|
+
var version = "6.12.0";
|
|
859
859
|
|
|
860
860
|
async function writeDefaultTsconfig(tsConfigPath) {
|
|
861
861
|
await fs.promises.writeFile(tsConfigPath, JSON.stringify(DEFAULT_TS_CONFIG, null, 2), 'utf-8');
|
package/dist/index.js
CHANGED
|
@@ -306,7 +306,7 @@ function validateEntryFiles(entryFiles) {
|
|
|
306
306
|
|
|
307
307
|
function exit(err) {
|
|
308
308
|
logger.error(err);
|
|
309
|
-
throw new Error(err) ;
|
|
309
|
+
throw typeof err === 'string' ? new Error(err) : err;
|
|
310
310
|
}
|
|
311
311
|
async function getPackageMeta(cwd) {
|
|
312
312
|
const pkgFilePath = path__default.default.resolve(cwd, 'package.json');
|
|
@@ -1220,27 +1220,80 @@ const memoizeByKey = (fn)=>{
|
|
|
1220
1220
|
};
|
|
1221
1221
|
const memoize = (fn)=>createMemoize(fn);
|
|
1222
1222
|
|
|
1223
|
+
// TypeScript 7+ compiles natively and its `typescript` package no longer ships
|
|
1224
|
+
// the JavaScript compiler API (the main export only contains the version).
|
|
1225
|
+
// `@typescript/typescript6` is the official package re-exporting the TS 6 API.
|
|
1226
|
+
const TS_COMPAT_PACKAGE = '@typescript/typescript6';
|
|
1223
1227
|
let hasLoggedTsWarning = false;
|
|
1224
|
-
|
|
1225
|
-
|
|
1226
|
-
|
|
1227
|
-
|
|
1228
|
+
let hasLoggedTsCompatFallback = false;
|
|
1229
|
+
let hasRedirectedTsRequire = false;
|
|
1230
|
+
// Resolve to a concrete file path (works in both Node.js and Bun); the TS 7 fallback also needs the path to redirect `require('typescript')`.
|
|
1231
|
+
function resolveModulePath(request, paths) {
|
|
1228
1232
|
try {
|
|
1229
|
-
|
|
1230
|
-
|
|
1231
|
-
|
|
1232
|
-
|
|
1233
|
-
|
|
1233
|
+
return require.resolve(request, {
|
|
1234
|
+
paths
|
|
1235
|
+
});
|
|
1236
|
+
} catch {
|
|
1237
|
+
return null;
|
|
1238
|
+
}
|
|
1239
|
+
}
|
|
1240
|
+
function hasTsCompilerApi(ts) {
|
|
1241
|
+
return typeof (ts == null ? void 0 : ts.readConfigFile) === 'function' && typeof (ts == null ? void 0 : ts.parseJsonConfigFileContent) === 'function';
|
|
1242
|
+
}
|
|
1243
|
+
// Redirect `require('typescript')` to the TS 6 compat API so dependencies
|
|
1244
|
+
// relying on the JS compiler API (e.g. rollup-plugin-dts) keep working
|
|
1245
|
+
// when the workspace TypeScript is v7+.
|
|
1246
|
+
function redirectTypescriptRequire(tsApiPath) {
|
|
1247
|
+
if (hasRedirectedTsRequire) return;
|
|
1248
|
+
hasRedirectedTsRequire = true;
|
|
1249
|
+
const moduleAny = module$1.Module;
|
|
1250
|
+
const originalResolveFilename = moduleAny._resolveFilename;
|
|
1251
|
+
moduleAny._resolveFilename = function(request, ...args) {
|
|
1252
|
+
if (request === 'typescript') {
|
|
1253
|
+
return tsApiPath;
|
|
1254
|
+
}
|
|
1255
|
+
return originalResolveFilename.apply(this, [
|
|
1256
|
+
request,
|
|
1257
|
+
...args
|
|
1258
|
+
]);
|
|
1259
|
+
};
|
|
1260
|
+
}
|
|
1261
|
+
function resolveTypescript(cwd) {
|
|
1262
|
+
const searchPaths = module$1.Module._nodeModulePaths(cwd);
|
|
1263
|
+
const tsPath = resolveModulePath('typescript', searchPaths);
|
|
1264
|
+
let ts = null;
|
|
1265
|
+
if (tsPath) {
|
|
1266
|
+
try {
|
|
1234
1267
|
ts = require(tsPath);
|
|
1235
|
-
}
|
|
1236
|
-
|
|
1268
|
+
} catch (e) {
|
|
1269
|
+
console.error(e);
|
|
1237
1270
|
}
|
|
1238
|
-
}
|
|
1239
|
-
|
|
1271
|
+
}
|
|
1272
|
+
if (!ts) {
|
|
1240
1273
|
if (!hasLoggedTsWarning) {
|
|
1241
1274
|
hasLoggedTsWarning = true;
|
|
1242
1275
|
exit('Could not load TypeScript compiler. Try to install `typescript` as dev dependency');
|
|
1243
1276
|
}
|
|
1277
|
+
return ts;
|
|
1278
|
+
}
|
|
1279
|
+
if (!hasTsCompilerApi(ts)) {
|
|
1280
|
+
var _resolveModulePath;
|
|
1281
|
+
const tsCompatPath = (_resolveModulePath = resolveModulePath(TS_COMPAT_PACKAGE, searchPaths)) != null ? _resolveModulePath : resolveModulePath(TS_COMPAT_PACKAGE, [
|
|
1282
|
+
__dirname
|
|
1283
|
+
]);
|
|
1284
|
+
if (!tsCompatPath) {
|
|
1285
|
+
if (!hasLoggedTsWarning) {
|
|
1286
|
+
hasLoggedTsWarning = true;
|
|
1287
|
+
exit(`Detected TypeScript ${ts.version || '7+'}, which no longer ships the JavaScript compiler API required for generating type declarations. Install \`${TS_COMPAT_PACKAGE}\` as dev dependency to keep building types`);
|
|
1288
|
+
}
|
|
1289
|
+
return ts;
|
|
1290
|
+
}
|
|
1291
|
+
redirectTypescriptRequire(tsCompatPath);
|
|
1292
|
+
if (!hasLoggedTsCompatFallback) {
|
|
1293
|
+
hasLoggedTsCompatFallback = true;
|
|
1294
|
+
logger.log(pc.dim(`Using ${TS_COMPAT_PACKAGE} API for TypeScript ${ts.version} type declaration generation`));
|
|
1295
|
+
}
|
|
1296
|
+
ts = require(tsCompatPath);
|
|
1244
1297
|
}
|
|
1245
1298
|
return ts;
|
|
1246
1299
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "bunchee",
|
|
3
|
-
"version": "6.
|
|
3
|
+
"version": "6.12.0",
|
|
4
4
|
"description": "zero config bundler for js/ts/jsx libraries",
|
|
5
5
|
"bin": "./dist/bin/cli.js",
|
|
6
6
|
"main": "./dist/index.js",
|
|
@@ -10,17 +10,18 @@
|
|
|
10
10
|
"test:update": "TEST_UPDATE_SNAPSHOT=1 pnpm test",
|
|
11
11
|
"test:post": "cross-env POST_BUILD=1 pnpm test test/compile.test.ts test/integration.test.ts",
|
|
12
12
|
"site": "next dev docs",
|
|
13
|
-
"docs:build": "next build docs",
|
|
13
|
+
"docs:build": "pnpm --dir docs install && next build docs",
|
|
14
14
|
"clean": "rm -rf ./dist",
|
|
15
15
|
"new-test": "node ./scripts/new-test.js",
|
|
16
16
|
"test:ts-matrix": "node ./scripts/test-ts-matrix.js all",
|
|
17
17
|
"test:ts5": "node ./scripts/test-ts-matrix.js ts5",
|
|
18
18
|
"test:ts6": "node ./scripts/test-ts-matrix.js ts6",
|
|
19
|
+
"test:ts7": "node ./scripts/test-ts-matrix.js ts7",
|
|
19
20
|
"typecheck": "tsc --noEmit && tsc -p test/tsconfig.json --noEmit",
|
|
20
21
|
"prepare-release": "pnpm clean && pnpm build",
|
|
21
22
|
"publish-local": "pnpm prepare-release && pnpm test && pnpm publish",
|
|
22
23
|
"prepublishOnly": "pnpm prepare-release && chmod +x ./dist/bin/cli.js",
|
|
23
|
-
"run-ts": "cross-env SWC_NODE_IGNORE_DYNAMIC=1 node -r @swc-node/register",
|
|
24
|
+
"run-ts": "cross-env SWC_NODE_IGNORE_DYNAMIC=1 node -r ./scripts/ts6-compat.js -r @swc-node/register",
|
|
24
25
|
"ts-bunchee": "pnpm run-ts ./src/bin/index.ts",
|
|
25
26
|
"build-dir": "pnpm ts-bunchee --cwd",
|
|
26
27
|
"build": "pnpm run-ts ./src/bin/index.ts --runtime node",
|
|
@@ -81,7 +82,7 @@
|
|
|
81
82
|
"yargs": "^17.7.2"
|
|
82
83
|
},
|
|
83
84
|
"peerDependencies": {
|
|
84
|
-
"typescript": "^4.1 || ^5.0 || ^6.0"
|
|
85
|
+
"typescript": "^4.1 || ^5.0 || ^6.0 || ^7.0"
|
|
85
86
|
},
|
|
86
87
|
"peerDependenciesMeta": {
|
|
87
88
|
"typescript": {
|
|
@@ -93,7 +94,7 @@
|
|
|
93
94
|
},
|
|
94
95
|
"devDependencies": {
|
|
95
96
|
"@huozhi/testing-package": "1.0.0",
|
|
96
|
-
"@swc-node/register": "^1.
|
|
97
|
+
"@swc-node/register": "^1.11.1",
|
|
97
98
|
"@swc/types": "^0.1.17",
|
|
98
99
|
"@tailwindcss/postcss": "^4.1.8",
|
|
99
100
|
"@types/clean-css": "^4.2.11",
|
|
@@ -102,6 +103,7 @@
|
|
|
102
103
|
"@types/react": "^19.2.14",
|
|
103
104
|
"@types/react-dom": "^19.2.3",
|
|
104
105
|
"@types/yargs": "^17.0.33",
|
|
106
|
+
"@typescript/typescript6": "^6.0.2",
|
|
105
107
|
"bunchee": "link:./",
|
|
106
108
|
"cross-env": "^7.0.3",
|
|
107
109
|
"husky": "^9.0.11",
|
|
@@ -119,5 +121,5 @@
|
|
|
119
121
|
"lint-staged": {
|
|
120
122
|
"*.{js,jsx,ts,tsx,md,json,yml,yaml}": "prettier --write"
|
|
121
123
|
},
|
|
122
|
-
"packageManager": "pnpm@
|
|
124
|
+
"packageManager": "pnpm@11.10.0"
|
|
123
125
|
}
|