bunchee 6.0.2 → 6.0.4
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 +52 -28
- package/dist/bin/cli.js +26 -28
- package/dist/index.js +23 -23
- package/package.json +10 -3
package/README.md
CHANGED
|
@@ -22,28 +22,45 @@ It uses the standard exports configuration in `package.json` as the only source
|
|
|
22
22
|
### Installation
|
|
23
23
|
|
|
24
24
|
```sh
|
|
25
|
-
npm install --save-dev bunchee
|
|
25
|
+
npm install --save-dev bunchee typescript
|
|
26
26
|
```
|
|
27
27
|
|
|
28
|
-
|
|
28
|
+
### Configuration
|
|
29
|
+
|
|
30
|
+
Create entry files of your library and `package.json`.
|
|
29
31
|
|
|
30
32
|
```sh
|
|
31
|
-
|
|
33
|
+
cd ./coffee
|
|
34
|
+
mkdir src && touch ./src/index.ts && touch package.json
|
|
32
35
|
```
|
|
33
36
|
|
|
34
|
-
|
|
37
|
+
Add the exports in `package.json`.
|
|
35
38
|
|
|
36
|
-
|
|
39
|
+
```json
|
|
40
|
+
{
|
|
41
|
+
"name": "coffee",
|
|
42
|
+
"type": "module",
|
|
43
|
+
"main": "./dist/index.js",
|
|
44
|
+
"scripts": {
|
|
45
|
+
"build": "bunchee"
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
#### Build
|
|
37
51
|
|
|
38
52
|
```sh
|
|
39
|
-
|
|
40
|
-
mkdir src && touch ./src/index.ts
|
|
53
|
+
npm run build
|
|
41
54
|
```
|
|
42
55
|
|
|
43
|
-
|
|
56
|
+
Then files in `src` folders will be treated as entry files and match the export names in package.json.
|
|
57
|
+
Simply like Node.js module resolution, each export name will match the file in `src/` directory.
|
|
58
|
+
|
|
59
|
+
For example:
|
|
44
60
|
|
|
45
|
-
|
|
46
|
-
`src/
|
|
61
|
+
- `src/index.ts` will match the exports name `"."` or the only main export.
|
|
62
|
+
- `src/lite.ts` will match the exports name `"./lite"`.
|
|
63
|
+
- `src/react/index.ts` will match the exports name `"./react"`.
|
|
47
64
|
|
|
48
65
|
Now just run `npm run build` (or `pnpm build` / `yarn build`) if you're using these package managers, `bunchee` will find the entry files and build them.
|
|
49
66
|
The output format will based on the exports condition and also the file extension. Given an example:
|
|
@@ -69,16 +86,17 @@ npm exec bunchee prepare
|
|
|
69
86
|
Or you can checkout the following cases to configure your package.json.
|
|
70
87
|
|
|
71
88
|
<details>
|
|
72
|
-
<summary>
|
|
89
|
+
<summary>JavaScript ESModule</summary>
|
|
73
90
|
|
|
74
91
|
Then use use the [exports field in package.json](https://nodejs.org/api/packages.html#exports-sugar) to configure different conditions and leverage the same functionality as other bundlers, such as webpack. The exports field allows you to define multiple conditions.
|
|
75
92
|
|
|
76
93
|
```json
|
|
77
94
|
{
|
|
78
95
|
"files": ["dist"],
|
|
96
|
+
"type": "module",
|
|
79
97
|
"exports": {
|
|
80
|
-
"
|
|
81
|
-
"
|
|
98
|
+
".": "./dist/es/index.js",
|
|
99
|
+
"./react": "./dist/es/react.js"
|
|
82
100
|
},
|
|
83
101
|
"scripts": {
|
|
84
102
|
"build": "bunchee"
|
|
@@ -91,19 +109,21 @@ Then use use the [exports field in package.json](https://nodejs.org/api/packages
|
|
|
91
109
|
<details>
|
|
92
110
|
<summary>TypeScript</summary>
|
|
93
111
|
|
|
94
|
-
If you're build a TypeScript library, separate the types from the main entry file and specify the types path in package.json.
|
|
112
|
+
If you're build 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.
|
|
95
113
|
|
|
96
114
|
```json
|
|
97
115
|
{
|
|
98
116
|
"files": ["dist"],
|
|
117
|
+
"type": "module",
|
|
118
|
+
"main": "./dist/index.js",
|
|
99
119
|
"exports": {
|
|
100
|
-
"
|
|
101
|
-
"types": "./dist/
|
|
102
|
-
"default": "./dist/
|
|
120
|
+
".": {
|
|
121
|
+
"types": "./dist/index.d.ts",
|
|
122
|
+
"default": "./dist/index.js"
|
|
103
123
|
},
|
|
104
|
-
"
|
|
105
|
-
"types": "./dist/
|
|
106
|
-
"default": "./dist/
|
|
124
|
+
"./react": {
|
|
125
|
+
"types": "./dist/react/index.d.ts",
|
|
126
|
+
"default": "./dist/react/index.js"
|
|
107
127
|
}
|
|
108
128
|
},
|
|
109
129
|
"scripts": {
|
|
@@ -118,20 +138,23 @@ If you're build a TypeScript library, separate the types from the main entry fil
|
|
|
118
138
|
<summary>Hybrid (CJS & ESM) Module Resolution with TypeScript</summary>
|
|
119
139
|
If you're using TypeScript with Node 10 and Node 16 module resolution, you can use the `types` field in package.json to specify the types path. Then `bunchee` will generate the types file with the same extension as the main entry file.
|
|
120
140
|
|
|
141
|
+
_NOTE_: When you're using `.mjs` or `.cjs` extensions with TypeScript and modern module resolution (above node16), TypeScript will require specific type declaration files like `.d.mts` or `.d.cts` to match the extension. `bunchee` can automatically generate them to match the types to match the condition and extensions.
|
|
142
|
+
|
|
121
143
|
```json
|
|
122
144
|
{
|
|
123
145
|
"files": ["dist"],
|
|
124
|
-
"
|
|
125
|
-
"
|
|
126
|
-
"
|
|
146
|
+
"type": "module",
|
|
147
|
+
"main": "./dist/index.js",
|
|
148
|
+
"module": "./dist/index.js",
|
|
149
|
+
"types": "./dist/index.d.ts",
|
|
127
150
|
"exports": {
|
|
128
151
|
"import": {
|
|
129
|
-
"types": "./dist/
|
|
130
|
-
"default": "./dist/
|
|
152
|
+
"types": "./dist/index.d.ts",
|
|
153
|
+
"default": "./dist/index.js"
|
|
131
154
|
},
|
|
132
155
|
"require": {
|
|
133
|
-
"types": "./dist/
|
|
134
|
-
"default": "./dist/
|
|
156
|
+
"types": "./dist/index.d.cts",
|
|
157
|
+
"default": "./dist/index.cjs"
|
|
135
158
|
}
|
|
136
159
|
},
|
|
137
160
|
"scripts": {
|
|
@@ -176,10 +199,11 @@ Assuming you have default export package as `"."` and subpath export `"./lite"`
|
|
|
176
199
|
"scripts": {
|
|
177
200
|
"build": "bunchee"
|
|
178
201
|
},
|
|
202
|
+
"type": "module",
|
|
179
203
|
"exports": {
|
|
180
204
|
"./lite": "./dist/lite.js",
|
|
181
205
|
".": {
|
|
182
|
-
"import": "./dist/index.
|
|
206
|
+
"import": "./dist/index.js",
|
|
183
207
|
"require": "./dist/index.cjs"
|
|
184
208
|
}
|
|
185
209
|
}
|
package/dist/bin/cli.js
CHANGED
|
@@ -154,9 +154,8 @@ const logger = {
|
|
|
154
154
|
}
|
|
155
155
|
};
|
|
156
156
|
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
return path.startsWith('.') ? path : `.${sep}${path}`;
|
|
157
|
+
function posixRelativify(path) {
|
|
158
|
+
return path.startsWith('.') ? path : `./${path}`;
|
|
160
159
|
}
|
|
161
160
|
|
|
162
161
|
function exit(err) {
|
|
@@ -217,7 +216,7 @@ function isTypeFile(filename) {
|
|
|
217
216
|
function sourceFilenameToExportFullPath(filename) {
|
|
218
217
|
const ext = path__default.default.extname(filename);
|
|
219
218
|
const exportPath = filename.slice(0, -ext.length);
|
|
220
|
-
return
|
|
219
|
+
return posixRelativify(exportPath);
|
|
221
220
|
}
|
|
222
221
|
// If the file is matching the private module convention file export path.
|
|
223
222
|
// './lib/_foo' -> true
|
|
@@ -227,6 +226,9 @@ function sourceFilenameToExportFullPath(filename) {
|
|
|
227
226
|
function isPrivateExportPath(exportPath) {
|
|
228
227
|
return /\/_/.test(exportPath);
|
|
229
228
|
}
|
|
229
|
+
function normalizePath(filePath) {
|
|
230
|
+
return filePath.replace(/\\/g, '/');
|
|
231
|
+
}
|
|
230
232
|
|
|
231
233
|
function collectExportPath(exportValue, exportKey, currentPath, exportTypes, exportToDist) {
|
|
232
234
|
// End of searching, export value is file path.
|
|
@@ -376,10 +378,10 @@ function getExportTypeFromFile(filename, pkgType) {
|
|
|
376
378
|
const matchFile = (matchingPattern, filePath)=>{
|
|
377
379
|
return matchingPattern.some((pattern)=>{
|
|
378
380
|
// pattern is always posix
|
|
379
|
-
const normalizedPattern =
|
|
381
|
+
const normalizedPattern = path.posix.normalize(pattern);
|
|
380
382
|
const expandedPattern = normalizedPattern.endsWith('/') ? `${normalizedPattern}**` : `${normalizedPattern}/**`;
|
|
381
383
|
const matcher = picomatch__default.default(expandedPattern);
|
|
382
|
-
const normalizedFilePath =
|
|
384
|
+
const normalizedFilePath = path.posix.normalize(filePath);
|
|
383
385
|
return matcher(normalizedFilePath);
|
|
384
386
|
});
|
|
385
387
|
};
|
|
@@ -394,12 +396,12 @@ function validateTypesFieldCondition(pair) {
|
|
|
394
396
|
}
|
|
395
397
|
function validateFilesField(packageJson) {
|
|
396
398
|
const state = {
|
|
397
|
-
definedField: true,
|
|
398
399
|
missingFiles: []
|
|
399
400
|
};
|
|
400
|
-
const filesField = packageJson.files || [
|
|
401
|
+
const filesField = packageJson.files || [
|
|
402
|
+
'*'
|
|
403
|
+
];
|
|
401
404
|
const exportsField = packageJson.exports || {};
|
|
402
|
-
state.definedField = !!packageJson.files;
|
|
403
405
|
const resolveExportsPaths = (exports)=>{
|
|
404
406
|
const paths = [];
|
|
405
407
|
if (typeof exports === 'string') {
|
|
@@ -411,7 +413,7 @@ function validateFilesField(packageJson) {
|
|
|
411
413
|
}
|
|
412
414
|
return paths;
|
|
413
415
|
};
|
|
414
|
-
const exportedPaths = resolveExportsPaths(exportsField).map((p)=>path__default.default.normalize(p));
|
|
416
|
+
const exportedPaths = resolveExportsPaths(exportsField).map((p)=>normalizePath(path__default.default.normalize(p)));
|
|
415
417
|
const commonFields = [
|
|
416
418
|
'main',
|
|
417
419
|
'module',
|
|
@@ -559,12 +561,8 @@ function lint$1(pkg) {
|
|
|
559
561
|
const warningsCount = exportsState.badTypesExport.length + fieldState.missingFiles.length;
|
|
560
562
|
if (warningsCount) {
|
|
561
563
|
logger.warn(`Lint: ${warningsCount} issues found.`);
|
|
562
|
-
} else {
|
|
563
|
-
logger.info(`Lint: package.json is healthy.`);
|
|
564
564
|
}
|
|
565
|
-
if (
|
|
566
|
-
logger.warn('Missing files field in package.json');
|
|
567
|
-
} else if (fieldState.missingFiles.length) {
|
|
565
|
+
if (fieldState.missingFiles.length) {
|
|
568
566
|
logger.warn('Missing files in package.json');
|
|
569
567
|
fieldState.missingFiles.forEach((p)=>{
|
|
570
568
|
logger.warn(` ${p}`);
|
|
@@ -614,7 +612,7 @@ function lint$1(pkg) {
|
|
|
614
612
|
}
|
|
615
613
|
}
|
|
616
614
|
|
|
617
|
-
var version = "6.0.
|
|
615
|
+
var version = "6.0.4";
|
|
618
616
|
|
|
619
617
|
async function writeDefaultTsconfig(tsConfigPath) {
|
|
620
618
|
await fs.promises.writeFile(tsConfigPath, JSON.stringify(DEFAULT_TS_CONFIG, null, 2), 'utf-8');
|
|
@@ -673,12 +671,12 @@ function normalizeExportPath(exportPath) {
|
|
|
673
671
|
async function collectSourceEntriesByExportPath(sourceFolderPath, originalSubpath, bins, exportsEntries) {
|
|
674
672
|
const isBinaryPath = isBinExportPath(originalSubpath);
|
|
675
673
|
const subpath = originalSubpath.replace(BINARY_TAG, 'bin');
|
|
676
|
-
const absoluteDirPath =
|
|
677
|
-
const dirName =
|
|
674
|
+
const absoluteDirPath = path__default.default.join(sourceFolderPath, subpath);
|
|
675
|
+
const dirName = path__default.default.dirname(subpath) // Get directory name regardless of file/directory
|
|
678
676
|
;
|
|
679
|
-
const baseName =
|
|
677
|
+
const baseName = path__default.default.basename(subpath) // Get base name regardless of file/directory
|
|
680
678
|
;
|
|
681
|
-
const dirPath =
|
|
679
|
+
const dirPath = path__default.default.join(sourceFolderPath, dirName);
|
|
682
680
|
// Match <name>{,/index}.{<ext>,<runtime>.<ext>}
|
|
683
681
|
const globalPatterns = [
|
|
684
682
|
`${baseName}.{${[
|
|
@@ -704,14 +702,14 @@ async function collectSourceEntriesByExportPath(sourceFolderPath, originalSubpat
|
|
|
704
702
|
ignore: '**/_*'
|
|
705
703
|
});
|
|
706
704
|
for (const file of files){
|
|
707
|
-
const ext =
|
|
705
|
+
const ext = path__default.default.extname(file).slice(1);
|
|
708
706
|
if (!availableExtensions.has(ext) || isTestFile(file)) continue;
|
|
709
|
-
const sourceFileAbsolutePath =
|
|
710
|
-
const exportPath =
|
|
707
|
+
const sourceFileAbsolutePath = path__default.default.join(dirPath, file);
|
|
708
|
+
const exportPath = posixRelativify(fs.existsSync(absoluteDirPath) && (await fsp__default.default.stat(absoluteDirPath)).isDirectory() ? subpath : originalSubpath);
|
|
711
709
|
if (isBinaryPath) {
|
|
712
710
|
bins.set(normalizeExportPath(originalSubpath), sourceFileAbsolutePath);
|
|
713
711
|
} else {
|
|
714
|
-
const parts =
|
|
712
|
+
const parts = path__default.default.basename(file).split('.');
|
|
715
713
|
const exportType = parts.length > 2 ? parts[1] : getExportTypeFromExportPath(exportPath);
|
|
716
714
|
const specialExportPath = exportType !== 'index' && parts.length > 2 ? exportPath + '.' + exportType : exportPath // Adjust for direct file matches
|
|
717
715
|
;
|
|
@@ -757,12 +755,12 @@ async function collectSourceEntries(sourceFolderPath) {
|
|
|
757
755
|
});
|
|
758
756
|
for (const file of binMatches){
|
|
759
757
|
// convert relative path to export path
|
|
760
|
-
const exportPath = sourceFilenameToExportFullPath(file);
|
|
758
|
+
const exportPath = sourceFilenameToExportFullPath(normalizePath(file));
|
|
761
759
|
const binExportPath = exportPath.replace(/^\.[\//]bin/, BINARY_TAG);
|
|
762
760
|
await collectSourceEntriesByExportPath(sourceFolderPath, binExportPath, bins, exportsEntries);
|
|
763
761
|
}
|
|
764
762
|
for (const file of srcMatches){
|
|
765
|
-
const binExportPath = file.replace(/^bin/, BINARY_TAG)// Remove index.<ext> to [^index].<ext> to build the export path
|
|
763
|
+
const binExportPath = normalizePath(file).replace(/^bin/, BINARY_TAG)// Remove index.<ext> to [^index].<ext> to build the export path
|
|
766
764
|
.replace(/(\/index)?\.[^/]+$/, '');
|
|
767
765
|
await collectSourceEntriesByExportPath(sourceFolderPath, binExportPath, bins, exportsEntries);
|
|
768
766
|
}
|
|
@@ -774,7 +772,7 @@ async function collectSourceEntries(sourceFolderPath) {
|
|
|
774
772
|
|
|
775
773
|
// Output with posix style in package.json
|
|
776
774
|
function getDistPath(...subPaths) {
|
|
777
|
-
return
|
|
775
|
+
return posixRelativify(path.posix.join(DIST, ...subPaths));
|
|
778
776
|
}
|
|
779
777
|
function stripeBinaryTag(exportName) {
|
|
780
778
|
// Add \ to decode leading $
|
|
@@ -782,7 +780,7 @@ function stripeBinaryTag(exportName) {
|
|
|
782
780
|
}
|
|
783
781
|
const normalizeBaseNameToExportName = (name)=>{
|
|
784
782
|
const baseName = stripeBinaryTag(name);
|
|
785
|
-
return /^\.\/index(\.|$)/.test(baseName) ? '.' :
|
|
783
|
+
return /^\.\/index(\.|$)/.test(baseName) ? '.' : posixRelativify(baseName);
|
|
786
784
|
};
|
|
787
785
|
function createExportCondition(exportName, sourceFile, moduleType) {
|
|
788
786
|
const isTsSourceFile = isTypescriptFile(sourceFile);
|
package/dist/index.js
CHANGED
|
@@ -242,9 +242,8 @@ const DEFAULT_TS_CONFIG = {
|
|
|
242
242
|
};
|
|
243
243
|
const BINARY_TAG = '$binary';
|
|
244
244
|
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
return path.startsWith('.') ? path : `.${sep}${path}`;
|
|
245
|
+
function posixRelativify(path) {
|
|
246
|
+
return path.startsWith('.') ? path : `./${path}`;
|
|
248
247
|
}
|
|
249
248
|
|
|
250
249
|
function exit(err) {
|
|
@@ -376,7 +375,10 @@ function isBinExportPath(exportPath) {
|
|
|
376
375
|
function sourceFilenameToExportFullPath(filename) {
|
|
377
376
|
const ext = path__default.default.extname(filename);
|
|
378
377
|
const exportPath = filename.slice(0, -ext.length);
|
|
379
|
-
return
|
|
378
|
+
return posixRelativify(exportPath);
|
|
379
|
+
}
|
|
380
|
+
function normalizePath(filePath) {
|
|
381
|
+
return filePath.replace(/\\/g, '/');
|
|
380
382
|
}
|
|
381
383
|
|
|
382
384
|
function collectExportPath(exportValue, exportKey, currentPath, exportTypes, exportToDist) {
|
|
@@ -571,7 +573,7 @@ function getExportFileTypePath(absoluteJsBundlePath) {
|
|
|
571
573
|
const baseName = baseNameWithoutExtension(absoluteJsBundlePath);
|
|
572
574
|
const ext = path.extname(absoluteJsBundlePath).slice(1);
|
|
573
575
|
const typeExtension = dtsExtensionsMap[ext];
|
|
574
|
-
return path.join(dirName, baseName + '.' + typeExtension);
|
|
576
|
+
return normalizePath(path.join(dirName, baseName + '.' + typeExtension));
|
|
575
577
|
}
|
|
576
578
|
function getExportTypeFromFile(filename, pkgType) {
|
|
577
579
|
const isESModule = isESModulePackage(pkgType);
|
|
@@ -594,7 +596,7 @@ async function collectEntriesFromParsedExports(cwd, parsedExportsInfo, pkg, sour
|
|
|
594
596
|
};
|
|
595
597
|
}
|
|
596
598
|
// Find source files
|
|
597
|
-
const { bins, exportsEntries } = await collectSourceEntriesFromExportPaths(
|
|
599
|
+
const { bins, exportsEntries } = await collectSourceEntriesFromExportPaths(path__default.default.join(cwd, SRC), parsedExportsInfo, pkg);
|
|
598
600
|
// A mapping between each export path and its related special export conditions,
|
|
599
601
|
// excluding the 'default' export condition.
|
|
600
602
|
// { './index' => Set('development', 'edge-light') }
|
|
@@ -743,12 +745,12 @@ function stripSpecialCondition(exportPath) {
|
|
|
743
745
|
async function collectSourceEntriesByExportPath(sourceFolderPath, originalSubpath, bins, exportsEntries) {
|
|
744
746
|
const isBinaryPath = isBinExportPath(originalSubpath);
|
|
745
747
|
const subpath = originalSubpath.replace(BINARY_TAG, 'bin');
|
|
746
|
-
const absoluteDirPath =
|
|
747
|
-
const dirName =
|
|
748
|
+
const absoluteDirPath = path__default.default.join(sourceFolderPath, subpath);
|
|
749
|
+
const dirName = path__default.default.dirname(subpath) // Get directory name regardless of file/directory
|
|
748
750
|
;
|
|
749
|
-
const baseName =
|
|
751
|
+
const baseName = path__default.default.basename(subpath) // Get base name regardless of file/directory
|
|
750
752
|
;
|
|
751
|
-
const dirPath =
|
|
753
|
+
const dirPath = path__default.default.join(sourceFolderPath, dirName);
|
|
752
754
|
// Match <name>{,/index}.{<ext>,<runtime>.<ext>}
|
|
753
755
|
const globalPatterns = [
|
|
754
756
|
`${baseName}.{${[
|
|
@@ -774,14 +776,14 @@ async function collectSourceEntriesByExportPath(sourceFolderPath, originalSubpat
|
|
|
774
776
|
ignore: '**/_*'
|
|
775
777
|
});
|
|
776
778
|
for (const file of files){
|
|
777
|
-
const ext =
|
|
779
|
+
const ext = path__default.default.extname(file).slice(1);
|
|
778
780
|
if (!availableExtensions.has(ext) || isTestFile(file)) continue;
|
|
779
|
-
const sourceFileAbsolutePath =
|
|
780
|
-
const exportPath =
|
|
781
|
+
const sourceFileAbsolutePath = path__default.default.join(dirPath, file);
|
|
782
|
+
const exportPath = posixRelativify(fs.existsSync(absoluteDirPath) && (await fsp__default.default.stat(absoluteDirPath)).isDirectory() ? subpath : originalSubpath);
|
|
781
783
|
if (isBinaryPath) {
|
|
782
784
|
bins.set(normalizeExportPath(originalSubpath), sourceFileAbsolutePath);
|
|
783
785
|
} else {
|
|
784
|
-
const parts =
|
|
786
|
+
const parts = path__default.default.basename(file).split('.');
|
|
785
787
|
const exportType = parts.length > 2 ? parts[1] : getExportTypeFromExportPath(exportPath);
|
|
786
788
|
const specialExportPath = exportType !== 'index' && parts.length > 2 ? exportPath + '.' + exportType : exportPath // Adjust for direct file matches
|
|
787
789
|
;
|
|
@@ -841,7 +843,7 @@ async function collectSourceEntriesByExportPath(sourceFolderPath, originalSubpat
|
|
|
841
843
|
nodir: true
|
|
842
844
|
});
|
|
843
845
|
for (const file of privateFiles){
|
|
844
|
-
const sourceFileAbsolutePath =
|
|
846
|
+
const sourceFileAbsolutePath = path__default.default.join(sourceFolderPath, file);
|
|
845
847
|
const exportPath = sourceFilenameToExportFullPath(file);
|
|
846
848
|
const isEsmPkg = isESModulePackage(pkg.type);
|
|
847
849
|
// const specialItems: [string, string][] = []
|
|
@@ -855,11 +857,11 @@ async function collectSourceEntriesByExportPath(sourceFolderPath, originalSubpat
|
|
|
855
857
|
// e.g. ./_utils.ts -> ./dist/_utils.js
|
|
856
858
|
const privateExportInfo = [
|
|
857
859
|
[
|
|
858
|
-
|
|
860
|
+
posixRelativify(path.posix.join('./dist', exportPath + (isEsmPkg ? '.js' : '.mjs'))),
|
|
859
861
|
condPart + 'import'
|
|
860
862
|
],
|
|
861
863
|
[
|
|
862
|
-
|
|
864
|
+
posixRelativify(path.posix.join('./dist', exportPath + (isEsmPkg ? '.cjs' : '.js'))),
|
|
863
865
|
condPart + 'require'
|
|
864
866
|
]
|
|
865
867
|
];
|
|
@@ -930,9 +932,9 @@ function createOutputState({ entries }) {
|
|
|
930
932
|
const sourceFileName = chunk.facadeModuleId || '';
|
|
931
933
|
const exportPath = removeScope(reversedMapping.get(sourceFileName) || '.');
|
|
932
934
|
addSize({
|
|
933
|
-
fileName: path__default.default.relative(cwd, filePath)
|
|
935
|
+
fileName: normalizePath(path__default.default.relative(cwd, filePath)),
|
|
934
936
|
size,
|
|
935
|
-
sourceFileName,
|
|
937
|
+
sourceFileName: normalizePath(sourceFileName),
|
|
936
938
|
exportPath
|
|
937
939
|
});
|
|
938
940
|
});
|
|
@@ -1320,7 +1322,7 @@ function aliasEntries({ entry: sourceFilePath, conditionNames, entries, format,
|
|
|
1320
1322
|
const absoluteBundlePath = path.posix.resolve(cwd, srcBundle);
|
|
1321
1323
|
const absoluteImportBundlePath = path.posix.resolve(cwd, resolvedModuleBundle);
|
|
1322
1324
|
const filePathBase = path.posix.relative(path.posix.dirname(absoluteBundlePath), absoluteImportBundlePath);
|
|
1323
|
-
const relativePath =
|
|
1325
|
+
const relativePath = posixRelativify(normalizePath(filePathBase));
|
|
1324
1326
|
return {
|
|
1325
1327
|
id: relativePath,
|
|
1326
1328
|
external: true
|
|
@@ -1524,9 +1526,7 @@ async function buildInputConfig(entry, bundleConfig, exportCondition, buildConte
|
|
|
1524
1526
|
return externals.some((name)=>id === name || id.startsWith(name + '/'));
|
|
1525
1527
|
},
|
|
1526
1528
|
plugins,
|
|
1527
|
-
treeshake:
|
|
1528
|
-
propertyReadSideEffects: false
|
|
1529
|
-
},
|
|
1529
|
+
treeshake: 'recommended',
|
|
1530
1530
|
onwarn (warning, warn) {
|
|
1531
1531
|
const code = warning.code || '';
|
|
1532
1532
|
// Some may not have types, like CLI binary
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "bunchee",
|
|
3
|
-
"version": "6.0.
|
|
3
|
+
"version": "6.0.4",
|
|
4
4
|
"description": "zero config bundler for js/ts/jsx libraries",
|
|
5
5
|
"bin": "./dist/bin/cli.js",
|
|
6
6
|
"main": "./dist/index.js",
|
|
@@ -77,15 +77,18 @@
|
|
|
77
77
|
"@types/jest": "29.0.0",
|
|
78
78
|
"@types/node": "^22.9.3",
|
|
79
79
|
"@types/picomatch": "^3.0.1",
|
|
80
|
+
"@types/react": "19.0.1",
|
|
80
81
|
"@types/yargs": "^17.0.33",
|
|
81
82
|
"bunchee": "link:./",
|
|
82
83
|
"cross-env": "^7.0.3",
|
|
83
84
|
"husky": "^9.0.11",
|
|
84
85
|
"jest": "29.0.1",
|
|
85
86
|
"lint-staged": "^15.2.2",
|
|
87
|
+
"next": "^15.0.4",
|
|
86
88
|
"picocolors": "^1.0.0",
|
|
87
89
|
"prettier": "^3.0.0",
|
|
88
|
-
"react": "^
|
|
90
|
+
"react": "^19.0.0",
|
|
91
|
+
"react-dom": "^19.0.0",
|
|
89
92
|
"typescript": "^5.6.2"
|
|
90
93
|
},
|
|
91
94
|
"lint-staged": {
|
|
@@ -111,11 +114,15 @@
|
|
|
111
114
|
},
|
|
112
115
|
"scripts": {
|
|
113
116
|
"test": "jest --env node",
|
|
117
|
+
"test:ci": "pnpm test -- --ci",
|
|
114
118
|
"test:update": "TEST_UPDATE_SNAPSHOT=1 pnpm test",
|
|
115
119
|
"test:post": "cross-env POST_BUILD=1 pnpm jest test/compile.test.ts test/integration.test.ts",
|
|
116
|
-
"
|
|
120
|
+
"docs:dev": "next dev docs",
|
|
121
|
+
"docs:build": "next build docs",
|
|
117
122
|
"clean": "rm -rf ./dist",
|
|
118
123
|
"typecheck": "tsc --noEmit && tsc -p test/tsconfig.json --noEmit",
|
|
124
|
+
"prepare-release": "pnpm clean && pnpm build",
|
|
125
|
+
"publish-local": "pnpm prepare-release && pnpm test && pnpm publish",
|
|
119
126
|
"run-ts": "cross-env SWC_NODE_IGNORE_DYNAMIC=1 node -r @swc-node/register",
|
|
120
127
|
"ts-bunchee": "pnpm run-ts ./src/bin/index.ts",
|
|
121
128
|
"build-dir": "pnpm ts-bunchee --cwd",
|