bunchee 6.8.0 → 6.8.2
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 +0 -26
- package/dist/bin/cli.js +70 -39
- package/dist/index.d.ts +0 -1
- package/dist/index.js +26 -98
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -317,23 +317,6 @@ bunchee --no-external
|
|
|
317
317
|
|
|
318
318
|
This will include all dependencies within your output bundle.
|
|
319
319
|
|
|
320
|
-
#### TypeScript-Go Compiler
|
|
321
|
-
|
|
322
|
-
TypeScript-Go (`@typescript/native-preview`) is a high-performance, Go-based implementation of the TypeScript compiler that can significantly speed up type declaration file generation.
|
|
323
|
-
|
|
324
|
-
To use TypeScript-Go for type generation, use the `--tsgo` flag:
|
|
325
|
-
|
|
326
|
-
```sh
|
|
327
|
-
bunchee --tsgo
|
|
328
|
-
```
|
|
329
|
-
|
|
330
|
-
**Note**: This requires `@typescript/native-preview` to be installed as a dev dependency. If it's not installed, bunchee will exit with an error.
|
|
331
|
-
|
|
332
|
-
```sh
|
|
333
|
-
pnpm add -D bunchee @typescript/native-preview
|
|
334
|
-
bunchee --tsgo
|
|
335
|
-
```
|
|
336
|
-
|
|
337
320
|
#### Build Successful Command
|
|
338
321
|
|
|
339
322
|
A command to be executed after a build is successful can be specified using the `--success` option, which is useful for development watching mode:
|
|
@@ -382,14 +365,6 @@ Then use use the [exports field in package.json](https://nodejs.org/api/packages
|
|
|
382
365
|
|
|
383
366
|
If you're building a TypeScript library, separate the types from the main entry file and specify the types path in package.json. Types exports need to stay on the top of each export with `types` condition, and you can use `default` condition for the JS bundle file.
|
|
384
367
|
|
|
385
|
-
**bunchee** supports using the TypeScript-Go compiler (`@typescript/native-preview`) for faster type generation. To enable it, use the `--tsgo` flag:
|
|
386
|
-
|
|
387
|
-
```sh
|
|
388
|
-
bunchee --tsgo
|
|
389
|
-
```
|
|
390
|
-
|
|
391
|
-
Note: This requires `@typescript/native-preview` to be installed as a dev dependency. If it's not installed, bunchee will fall back to the regular TypeScript compiler with a warning.
|
|
392
|
-
|
|
393
368
|
```json5
|
|
394
369
|
{
|
|
395
370
|
"files": ["dist"],
|
|
@@ -570,7 +545,6 @@ await bundle(path.resolve('./src/index.ts'), {
|
|
|
570
545
|
cwd: process.cwd(), // string
|
|
571
546
|
clean: true, // boolean
|
|
572
547
|
tsconfig: 'tsconfig.json', // string
|
|
573
|
-
tsgo: false, // Boolean - use TypeScript-Go compiler for type generation
|
|
574
548
|
})
|
|
575
549
|
```
|
|
576
550
|
|
package/dist/bin/cli.js
CHANGED
|
@@ -146,6 +146,52 @@ const defaultColorFn = (text)=>text;
|
|
|
146
146
|
function color(prefixColor) {
|
|
147
147
|
return pc.isColorSupported ? pc[prefixColor] : defaultColorFn;
|
|
148
148
|
}
|
|
149
|
+
let activeSpinner = null;
|
|
150
|
+
// Store original console methods
|
|
151
|
+
const originalConsole = {
|
|
152
|
+
log: console.log.bind(console),
|
|
153
|
+
warn: console.warn.bind(console),
|
|
154
|
+
error: console.error.bind(console),
|
|
155
|
+
info: console.info.bind(console)
|
|
156
|
+
};
|
|
157
|
+
function isSpinnerActive() {
|
|
158
|
+
if (!activeSpinner) return false;
|
|
159
|
+
const isSpinning = activeSpinner.isSpinning;
|
|
160
|
+
return typeof isSpinning === 'function' ? isSpinning() : isSpinning;
|
|
161
|
+
}
|
|
162
|
+
/**
|
|
163
|
+
* Wrap a console method to pause spinner before logging
|
|
164
|
+
*/ function wrapConsoleMethod(original) {
|
|
165
|
+
return (...args)=>{
|
|
166
|
+
if (isSpinnerActive() && activeSpinner) {
|
|
167
|
+
activeSpinner.clear();
|
|
168
|
+
original(...args);
|
|
169
|
+
activeSpinner.start();
|
|
170
|
+
} else {
|
|
171
|
+
original(...args);
|
|
172
|
+
}
|
|
173
|
+
};
|
|
174
|
+
}
|
|
175
|
+
/**
|
|
176
|
+
* Register a spinner so that ALL console output automatically pauses it.
|
|
177
|
+
* This intercepts console.log/warn/error/info globally.
|
|
178
|
+
* Call with `null` to unregister and restore original console methods.
|
|
179
|
+
*/ function setActiveSpinner(spinner) {
|
|
180
|
+
activeSpinner = spinner;
|
|
181
|
+
if (spinner) {
|
|
182
|
+
// Patch global console methods to pause spinner
|
|
183
|
+
console.log = wrapConsoleMethod(originalConsole.log);
|
|
184
|
+
console.warn = wrapConsoleMethod(originalConsole.warn);
|
|
185
|
+
console.error = wrapConsoleMethod(originalConsole.error);
|
|
186
|
+
console.info = wrapConsoleMethod(originalConsole.info);
|
|
187
|
+
} else {
|
|
188
|
+
// Restore original console methods
|
|
189
|
+
console.log = originalConsole.log;
|
|
190
|
+
console.warn = originalConsole.warn;
|
|
191
|
+
console.error = originalConsole.error;
|
|
192
|
+
console.info = originalConsole.info;
|
|
193
|
+
}
|
|
194
|
+
}
|
|
149
195
|
const logger = {
|
|
150
196
|
log (...arg) {
|
|
151
197
|
console.log(...arg);
|
|
@@ -437,13 +483,13 @@ function validateFilesField(packageJson) {
|
|
|
437
483
|
'*'
|
|
438
484
|
];
|
|
439
485
|
const exportsField = packageJson.exports || {};
|
|
440
|
-
const resolveExportsPaths = (exports
|
|
486
|
+
const resolveExportsPaths = (exports)=>{
|
|
441
487
|
const paths = [];
|
|
442
|
-
if (typeof exports
|
|
443
|
-
paths.push(exports
|
|
444
|
-
} else if (typeof exports
|
|
445
|
-
for(const key in exports
|
|
446
|
-
paths.push(...resolveExportsPaths(exports
|
|
488
|
+
if (typeof exports === 'string') {
|
|
489
|
+
paths.push(exports);
|
|
490
|
+
} else if (typeof exports === 'object') {
|
|
491
|
+
for(const key in exports){
|
|
492
|
+
paths.push(...resolveExportsPaths(exports[key]));
|
|
447
493
|
}
|
|
448
494
|
}
|
|
449
495
|
return paths;
|
|
@@ -470,7 +516,7 @@ function validateFilesField(packageJson) {
|
|
|
470
516
|
return state;
|
|
471
517
|
}
|
|
472
518
|
function lint$1(pkg) {
|
|
473
|
-
const { name, main, exports
|
|
519
|
+
const { name, main, exports } = pkg;
|
|
474
520
|
const isESM = isESModulePackage(pkg.type);
|
|
475
521
|
const parsedExports = parseExports(pkg);
|
|
476
522
|
if (!name) {
|
|
@@ -500,12 +546,12 @@ function lint$1(pkg) {
|
|
|
500
546
|
};
|
|
501
547
|
// Validate ESM package
|
|
502
548
|
if (isESM) {
|
|
503
|
-
if (exports
|
|
504
|
-
if (typeof exports
|
|
505
|
-
if (hasCjsExtension(exports
|
|
549
|
+
if (exports) {
|
|
550
|
+
if (typeof exports === 'string') {
|
|
551
|
+
if (hasCjsExtension(exports)) {
|
|
506
552
|
exportsState.badMainExport = true;
|
|
507
553
|
}
|
|
508
|
-
} else if (typeof exports
|
|
554
|
+
} else if (typeof exports !== 'object') {
|
|
509
555
|
exportsState.invalidExportsFieldType = true;
|
|
510
556
|
} else {
|
|
511
557
|
parsedExports.forEach((outputPairs)=>{
|
|
@@ -548,12 +594,12 @@ function lint$1(pkg) {
|
|
|
548
594
|
if (main && path__default.default.extname(main) === '.mjs') {
|
|
549
595
|
exportsState.badMainExtension = true;
|
|
550
596
|
}
|
|
551
|
-
if (exports
|
|
552
|
-
if (typeof exports
|
|
553
|
-
if (path__default.default.extname(exports
|
|
597
|
+
if (exports) {
|
|
598
|
+
if (typeof exports === 'string') {
|
|
599
|
+
if (path__default.default.extname(exports) === '.mjs') {
|
|
554
600
|
exportsState.badMainExport = true;
|
|
555
601
|
}
|
|
556
|
-
} else if (typeof exports
|
|
602
|
+
} else if (typeof exports !== 'object') {
|
|
557
603
|
exportsState.invalidExportsFieldType = true;
|
|
558
604
|
} else {
|
|
559
605
|
parsedExports.forEach((outputPairs)=>{
|
|
@@ -647,12 +693,11 @@ function lint$1(pkg) {
|
|
|
647
693
|
}
|
|
648
694
|
}
|
|
649
695
|
|
|
650
|
-
var version = "6.8.
|
|
696
|
+
var version = "6.8.2";
|
|
651
697
|
|
|
652
|
-
async function writeDefaultTsconfig(tsConfigPath
|
|
698
|
+
async function writeDefaultTsconfig(tsConfigPath) {
|
|
653
699
|
await fs.promises.writeFile(tsConfigPath, JSON.stringify(DEFAULT_TS_CONFIG, null, 2), 'utf-8');
|
|
654
|
-
|
|
655
|
-
logger.log(`Detected using ${compilerName} but tsconfig.json is missing, created a ${pc.blue('tsconfig.json')} for you.`);
|
|
700
|
+
logger.log(`Detected using TypeScript but tsconfig.json is missing, created a ${pc.blue('tsconfig.json')} for you.`);
|
|
656
701
|
}
|
|
657
702
|
|
|
658
703
|
// ./index -> default
|
|
@@ -1151,7 +1196,6 @@ Options:
|
|
|
1151
1196
|
--tsconfig path to tsconfig file, default: tsconfig.json
|
|
1152
1197
|
--dts-bundle bundle type declaration files, default: false
|
|
1153
1198
|
--success <cmd> run command after build success
|
|
1154
|
-
--tsgo use TypeScript-Go compiler for type generation
|
|
1155
1199
|
`;
|
|
1156
1200
|
function help() {
|
|
1157
1201
|
logger.log(helpMessage);
|
|
@@ -1229,9 +1273,6 @@ async function parseCliArgs(argv) {
|
|
|
1229
1273
|
}).option('success', {
|
|
1230
1274
|
type: 'string',
|
|
1231
1275
|
description: 'run command after build success'
|
|
1232
|
-
}).option('tsgo', {
|
|
1233
|
-
type: 'boolean',
|
|
1234
|
-
description: 'use TypeScript-Go compiler for type generation'
|
|
1235
1276
|
}).command('prepare', 'auto configure package.json exports for building', (yargs)=>{
|
|
1236
1277
|
return yargs.option('esm', {
|
|
1237
1278
|
type: 'boolean',
|
|
@@ -1274,8 +1315,7 @@ async function parseCliArgs(argv) {
|
|
|
1274
1315
|
clean: args['clean'] !== false,
|
|
1275
1316
|
env: args['env'],
|
|
1276
1317
|
tsconfig: args['tsconfig'],
|
|
1277
|
-
onSuccess: args['success']
|
|
1278
|
-
tsgo: args['tsgo']
|
|
1318
|
+
onSuccess: args['success']
|
|
1279
1319
|
};
|
|
1280
1320
|
// When minify is enabled, sourcemap should be enabled by default, unless explicitly opted out
|
|
1281
1321
|
if (parsedArgs.minify && typeof args['sourcemap'] === 'undefined') {
|
|
@@ -1304,22 +1344,9 @@ async function run(args) {
|
|
|
1304
1344
|
env: (env == null ? void 0 : env.split(',')) || [],
|
|
1305
1345
|
clean,
|
|
1306
1346
|
tsconfig,
|
|
1307
|
-
onSuccess
|
|
1308
|
-
tsgo: args.tsgo
|
|
1347
|
+
onSuccess
|
|
1309
1348
|
};
|
|
1310
1349
|
const cliEntry = source ? path__default.default.resolve(cwd, source) : '';
|
|
1311
|
-
// Check if ts-go is available when requested (before any build operations)
|
|
1312
|
-
if (args.tsgo) {
|
|
1313
|
-
try {
|
|
1314
|
-
require.resolve('@typescript/native-preview', {
|
|
1315
|
-
paths: [
|
|
1316
|
-
cwd
|
|
1317
|
-
]
|
|
1318
|
-
});
|
|
1319
|
-
} catch {
|
|
1320
|
-
exit('--tsgo flag was specified but @typescript/native-preview is not installed. Please install it as a dev dependency: pnpm add -D @typescript/native-preview');
|
|
1321
|
-
}
|
|
1322
|
-
}
|
|
1323
1350
|
// lint package by default
|
|
1324
1351
|
await lint(cwd);
|
|
1325
1352
|
const spinnerInstance = process.stdout.isTTY ? nanospinner.createSpinner('Building...\n\n', {
|
|
@@ -1331,6 +1358,8 @@ async function run(args) {
|
|
|
1331
1358
|
success: ()=>{},
|
|
1332
1359
|
isSpinning: false
|
|
1333
1360
|
};
|
|
1361
|
+
// Register spinner with logger so logs automatically pause the spinner
|
|
1362
|
+
setActiveSpinner(spinnerInstance);
|
|
1334
1363
|
const spinner = {
|
|
1335
1364
|
start: startSpinner,
|
|
1336
1365
|
stop: stopSpinner
|
|
@@ -1410,6 +1439,8 @@ async function run(args) {
|
|
|
1410
1439
|
} else {
|
|
1411
1440
|
spinner.stop(`bunchee ${version} build completed`);
|
|
1412
1441
|
}
|
|
1442
|
+
// Unregister spinner from logger
|
|
1443
|
+
setActiveSpinner(null);
|
|
1413
1444
|
}
|
|
1414
1445
|
async function main() {
|
|
1415
1446
|
let params, error;
|
package/dist/index.d.ts
CHANGED
package/dist/index.js
CHANGED
|
@@ -4,8 +4,8 @@ var fsp = require('fs/promises');
|
|
|
4
4
|
var fs = require('fs');
|
|
5
5
|
var path = require('path');
|
|
6
6
|
require('pretty-bytes');
|
|
7
|
-
var tinyglobby = require('tinyglobby');
|
|
8
7
|
var require$$0 = require('tty');
|
|
8
|
+
var tinyglobby = require('tinyglobby');
|
|
9
9
|
var module$1 = require('module');
|
|
10
10
|
var rollup = require('rollup');
|
|
11
11
|
var pluginWasm = require('@rollup/plugin-wasm');
|
|
@@ -97,6 +97,13 @@ const defaultColorFn = (text)=>text;
|
|
|
97
97
|
function color(prefixColor) {
|
|
98
98
|
return pc.isColorSupported ? pc[prefixColor] : defaultColorFn;
|
|
99
99
|
}
|
|
100
|
+
// Store original console methods
|
|
101
|
+
({
|
|
102
|
+
log: console.log.bind(console),
|
|
103
|
+
warn: console.warn.bind(console),
|
|
104
|
+
error: console.error.bind(console),
|
|
105
|
+
info: console.info.bind(console)
|
|
106
|
+
});
|
|
100
107
|
const logger = {
|
|
101
108
|
log (...arg) {
|
|
102
109
|
console.log(...arg);
|
|
@@ -299,7 +306,7 @@ function validateEntryFiles(entryFiles) {
|
|
|
299
306
|
|
|
300
307
|
function exit(err) {
|
|
301
308
|
logger.error(err);
|
|
302
|
-
throw
|
|
309
|
+
throw new Error(err) ;
|
|
303
310
|
}
|
|
304
311
|
async function getPackageMeta(cwd) {
|
|
305
312
|
const pkgFilePath = path__default.default.resolve(cwd, 'package.json');
|
|
@@ -1034,42 +1041,7 @@ const memoizeByKey = (fn)=>{
|
|
|
1034
1041
|
const memoize = (fn)=>createMemoize(fn);
|
|
1035
1042
|
|
|
1036
1043
|
let hasLoggedTsWarning = false;
|
|
1037
|
-
|
|
1038
|
-
function resolveTsGo(cwd) {
|
|
1039
|
-
let tsgo;
|
|
1040
|
-
const m = new module$1.Module('', undefined);
|
|
1041
|
-
m.paths = module$1.Module._nodeModulePaths(cwd);
|
|
1042
|
-
try {
|
|
1043
|
-
// Bun does not yet support the `Module` class properly.
|
|
1044
|
-
if (typeof (m == null ? void 0 : m.require) === 'undefined') {
|
|
1045
|
-
const tsgoPath = require.resolve('@typescript/native-preview', {
|
|
1046
|
-
paths: [
|
|
1047
|
-
cwd
|
|
1048
|
-
]
|
|
1049
|
-
});
|
|
1050
|
-
tsgo = require(tsgoPath);
|
|
1051
|
-
} else {
|
|
1052
|
-
tsgo = m.require('@typescript/native-preview');
|
|
1053
|
-
}
|
|
1054
|
-
// ts-go exports the TypeScript API as default or named export
|
|
1055
|
-
return tsgo.default || tsgo;
|
|
1056
|
-
} catch (e) {
|
|
1057
|
-
if (!hasLoggedTsGoWarning) {
|
|
1058
|
-
hasLoggedTsGoWarning = true;
|
|
1059
|
-
logger.warn('Could not load TypeScript-Go compiler. Make sure `@typescript/native-preview` is installed as a dev dependency.');
|
|
1060
|
-
}
|
|
1061
|
-
return null;
|
|
1062
|
-
}
|
|
1063
|
-
}
|
|
1064
|
-
function resolveTypescript(cwd, useTsGo) {
|
|
1065
|
-
if (useTsGo) {
|
|
1066
|
-
const tsgo = resolveTsGo(cwd);
|
|
1067
|
-
if (tsgo) {
|
|
1068
|
-
return tsgo;
|
|
1069
|
-
}
|
|
1070
|
-
// Error if ts-go is requested but not available
|
|
1071
|
-
exit('TypeScript-Go compiler not found. Please install @typescript/native-preview as a dev dependency: pnpm add -D @typescript/native-preview');
|
|
1072
|
-
}
|
|
1044
|
+
function resolveTypescript(cwd) {
|
|
1073
1045
|
let ts;
|
|
1074
1046
|
const m = new module$1.Module('', undefined);
|
|
1075
1047
|
m.paths = module$1.Module._nodeModulePaths(cwd);
|
|
@@ -1077,9 +1049,7 @@ function resolveTypescript(cwd, useTsGo) {
|
|
|
1077
1049
|
// Bun does not yet support the `Module` class properly.
|
|
1078
1050
|
if (typeof (m == null ? void 0 : m.require) === 'undefined') {
|
|
1079
1051
|
const tsPath = require.resolve('typescript', {
|
|
1080
|
-
paths:
|
|
1081
|
-
cwd
|
|
1082
|
-
]
|
|
1052
|
+
paths: module$1.Module._nodeModulePaths(cwd)
|
|
1083
1053
|
});
|
|
1084
1054
|
ts = require(tsPath);
|
|
1085
1055
|
} else {
|
|
@@ -1099,11 +1069,11 @@ const resolveTsConfigPath = memoize((cwd, tsconfigFileName = 'tsconfig.json')=>{
|
|
|
1099
1069
|
tsConfigPath = path.resolve(cwd, tsconfigFileName);
|
|
1100
1070
|
return fileExists(tsConfigPath) ? tsConfigPath : undefined;
|
|
1101
1071
|
});
|
|
1102
|
-
function resolveTsConfigHandler(cwd, tsConfigPath
|
|
1072
|
+
function resolveTsConfigHandler(cwd, tsConfigPath) {
|
|
1103
1073
|
let tsCompilerOptions = {};
|
|
1104
1074
|
if (tsConfigPath) {
|
|
1105
1075
|
// Use the original ts handler to avoid memory leak
|
|
1106
|
-
const ts = resolveTypescript(cwd
|
|
1076
|
+
const ts = resolveTypescript(cwd);
|
|
1107
1077
|
const basePath = tsConfigPath ? path.dirname(tsConfigPath) : cwd;
|
|
1108
1078
|
const tsconfigJSON = ts.readConfigFile(tsConfigPath, ts.sys.readFile).config;
|
|
1109
1079
|
tsCompilerOptions = ts.parseJsonConfigFileContent(tsconfigJSON, ts.sys, basePath).options;
|
|
@@ -1115,28 +1085,24 @@ function resolveTsConfigHandler(cwd, tsConfigPath, useTsGo) {
|
|
|
1115
1085
|
tsConfigPath
|
|
1116
1086
|
};
|
|
1117
1087
|
}
|
|
1118
|
-
// Note: We can't memoize resolveTsConfigHandler directly with useTsGo parameter
|
|
1119
|
-
// because memoize doesn't handle optional parameters well. Instead, we'll create
|
|
1120
|
-
// a wrapper that handles the memoization per useTsGo value.
|
|
1121
1088
|
const resolveTsConfigCache = new Map();
|
|
1122
|
-
function resolveTsConfig(cwd, tsConfigPath
|
|
1123
|
-
const cacheKey = `${cwd}:${tsConfigPath || ''}
|
|
1089
|
+
function resolveTsConfig(cwd, tsConfigPath) {
|
|
1090
|
+
const cacheKey = `${cwd}:${tsConfigPath || ''}`;
|
|
1124
1091
|
if (resolveTsConfigCache.has(cacheKey)) {
|
|
1125
1092
|
return resolveTsConfigCache.get(cacheKey);
|
|
1126
1093
|
}
|
|
1127
|
-
const result = resolveTsConfigHandler(cwd, tsConfigPath
|
|
1094
|
+
const result = resolveTsConfigHandler(cwd, tsConfigPath);
|
|
1128
1095
|
resolveTsConfigCache.set(cacheKey, result);
|
|
1129
1096
|
return result;
|
|
1130
1097
|
}
|
|
1131
|
-
async function convertCompilerOptions(cwd, json
|
|
1098
|
+
async function convertCompilerOptions(cwd, json) {
|
|
1132
1099
|
// Use the original ts handler to avoid memory leak
|
|
1133
|
-
const ts = resolveTypescript(cwd
|
|
1100
|
+
const ts = resolveTypescript(cwd);
|
|
1134
1101
|
return ts.convertCompilerOptionsFromJson(json, './');
|
|
1135
1102
|
}
|
|
1136
|
-
async function writeDefaultTsconfig(tsConfigPath
|
|
1103
|
+
async function writeDefaultTsconfig(tsConfigPath) {
|
|
1137
1104
|
await fs.promises.writeFile(tsConfigPath, JSON.stringify(DEFAULT_TS_CONFIG, null, 2), 'utf-8');
|
|
1138
|
-
|
|
1139
|
-
logger.log(`Detected using ${compilerName} but tsconfig.json is missing, created a ${pc.blue('tsconfig.json')} for you.`);
|
|
1105
|
+
logger.log(`Detected using TypeScript but tsconfig.json is missing, created a ${pc.blue('tsconfig.json')} for you.`);
|
|
1140
1106
|
}
|
|
1141
1107
|
|
|
1142
1108
|
/**
|
|
@@ -1644,7 +1610,7 @@ const swcMinifyOptions = {
|
|
|
1644
1610
|
toplevel: true
|
|
1645
1611
|
}
|
|
1646
1612
|
};
|
|
1647
|
-
async function createDtsPlugin(tsCompilerOptions, tsConfigPath, respectExternal, cwd
|
|
1613
|
+
async function createDtsPlugin(tsCompilerOptions, tsConfigPath, respectExternal, cwd) {
|
|
1648
1614
|
const enableIncrementalWithoutBuildInfo = (tsCompilerOptions == null ? void 0 : tsCompilerOptions.incremental) && !(tsCompilerOptions == null ? void 0 : tsCompilerOptions.tsBuildInfoFile);
|
|
1649
1615
|
const incrementalOptions = enableIncrementalWithoutBuildInfo ? {
|
|
1650
1616
|
incremental: false
|
|
@@ -1671,33 +1637,7 @@ async function createDtsPlugin(tsCompilerOptions, tsConfigPath, respectExternal,
|
|
|
1671
1637
|
...incrementalOptions,
|
|
1672
1638
|
// error TS6379: Composite projects may not disable incremental compilation.
|
|
1673
1639
|
...compositeOptions
|
|
1674
|
-
}
|
|
1675
|
-
// If useTsGo is enabled, we need to make ts-go available to rollup-plugin-dts
|
|
1676
|
-
// rollup-plugin-dts uses require('typescript') internally, so we need to
|
|
1677
|
-
// temporarily override the module cache to use ts-go
|
|
1678
|
-
if (useTsGo) {
|
|
1679
|
-
const tsgo = resolveTsGo(cwd);
|
|
1680
|
-
if (tsgo) {
|
|
1681
|
-
try {
|
|
1682
|
-
// First, try to resolve typescript to get its path
|
|
1683
|
-
const tsPath = require.resolve('typescript', {
|
|
1684
|
-
paths: [
|
|
1685
|
-
cwd
|
|
1686
|
-
]
|
|
1687
|
-
});
|
|
1688
|
-
// Make ts-go available as 'typescript' for rollup-plugin-dts
|
|
1689
|
-
// This overrides the module cache so rollup-plugin-dts will use ts-go
|
|
1690
|
-
require.cache[tsPath] = {
|
|
1691
|
-
id: tsPath,
|
|
1692
|
-
exports: tsgo,
|
|
1693
|
-
loaded: true
|
|
1694
|
-
};
|
|
1695
|
-
} catch (e) {
|
|
1696
|
-
// If typescript cannot be resolved, we can't override it
|
|
1697
|
-
// rollup-plugin-dts will try to require it and may fail
|
|
1698
|
-
}
|
|
1699
|
-
}
|
|
1700
|
-
}
|
|
1640
|
+
});
|
|
1701
1641
|
const dtsPlugin = require('rollup-plugin-dts').default({
|
|
1702
1642
|
tsconfig: tsConfigPath,
|
|
1703
1643
|
compilerOptions: overrideResolvedTsOptions,
|
|
@@ -1791,8 +1731,8 @@ async function buildInputConfig(entry, bundleConfig, exportCondition, buildConte
|
|
|
1791
1731
|
// Each process should be unique
|
|
1792
1732
|
// Each package build should be unique
|
|
1793
1733
|
// Composing above factors into a unique cache key to retrieve the memoized dts plugin with tsconfigs
|
|
1794
|
-
const uniqueProcessId = 'dts-plugin:' + process.pid + tsConfigPath
|
|
1795
|
-
const dtsPlugin = await memoizeDtsPluginByKey(uniqueProcessId)(tsCompilerOptions, tsConfigPath, bundleConfig.dts && bundleConfig.dts.respectExternal, cwd
|
|
1734
|
+
const uniqueProcessId = 'dts-plugin:' + process.pid + tsConfigPath;
|
|
1735
|
+
const dtsPlugin = await memoizeDtsPluginByKey(uniqueProcessId)(tsCompilerOptions, tsConfigPath, bundleConfig.dts && bundleConfig.dts.respectExternal, cwd);
|
|
1796
1736
|
typesPlugins.push(dtsPlugin);
|
|
1797
1737
|
}
|
|
1798
1738
|
const plugins = (dts ? typesPlugins : [
|
|
@@ -2269,17 +2209,8 @@ async function bundle(cliEntryPath, { cwd: _cwd, onSuccess, ...options } = {}) {
|
|
|
2269
2209
|
// Original input file path, client path might change later
|
|
2270
2210
|
const inputFile = cliEntryPath;
|
|
2271
2211
|
const isFromCli = Boolean(cliEntryPath);
|
|
2272
|
-
const useTsGo = options.tsgo === true;
|
|
2273
|
-
// Check if ts-go is available when requested (before resolving tsconfig)
|
|
2274
|
-
let tsgoInstance = null;
|
|
2275
|
-
if (useTsGo) {
|
|
2276
|
-
tsgoInstance = resolveTsGo(cwd);
|
|
2277
|
-
if (!tsgoInstance) {
|
|
2278
|
-
exit('--tsgo flag was specified but @typescript/native-preview is not installed. Please install it as a dev dependency: pnpm add -D @typescript/native-preview');
|
|
2279
|
-
}
|
|
2280
|
-
}
|
|
2281
2212
|
const tsConfigPath = resolveTsConfigPath(cwd, options.tsconfig);
|
|
2282
|
-
let tsConfig = resolveTsConfig(cwd, tsConfigPath
|
|
2213
|
+
let tsConfig = resolveTsConfig(cwd, tsConfigPath);
|
|
2283
2214
|
let hasTsConfig = Boolean(tsConfig == null ? void 0 : tsConfig.tsConfigPath);
|
|
2284
2215
|
const defaultTsOptions = {
|
|
2285
2216
|
tsConfigPath: tsConfig == null ? void 0 : tsConfig.tsConfigPath,
|
|
@@ -2349,7 +2280,7 @@ async function bundle(cliEntryPath, { cwd: _cwd, onSuccess, ...options } = {}) {
|
|
|
2349
2280
|
// Otherwise, use the existing one.
|
|
2350
2281
|
const defaultTsConfigPath = path.resolve(cwd, 'tsconfig.json');
|
|
2351
2282
|
if (!fileExists(defaultTsConfigPath)) {
|
|
2352
|
-
await writeDefaultTsconfig(defaultTsConfigPath
|
|
2283
|
+
await writeDefaultTsconfig(defaultTsConfigPath);
|
|
2353
2284
|
}
|
|
2354
2285
|
defaultTsOptions.tsConfigPath = defaultTsConfigPath;
|
|
2355
2286
|
hasTsConfig = true;
|
|
@@ -2361,15 +2292,12 @@ async function bundle(cliEntryPath, { cwd: _cwd, onSuccess, ...options } = {}) {
|
|
|
2361
2292
|
const outputState = createOutputState({
|
|
2362
2293
|
entries
|
|
2363
2294
|
});
|
|
2364
|
-
// Use ts-go if it was successfully resolved earlier
|
|
2365
|
-
const useTsGoInContext = Boolean(useTsGo && hasTsConfig && tsgoInstance);
|
|
2366
2295
|
const buildContext = {
|
|
2367
2296
|
entries,
|
|
2368
2297
|
pkg,
|
|
2369
2298
|
cwd,
|
|
2370
2299
|
tsOptions: defaultTsOptions,
|
|
2371
2300
|
useTypeScript: hasTsConfig,
|
|
2372
|
-
useTsGo: useTsGoInContext,
|
|
2373
2301
|
browserslistConfig,
|
|
2374
2302
|
pluginContext: {
|
|
2375
2303
|
outputState,
|