bunchee 6.5.3 → 6.6.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 +15 -0
- package/dist/bin/cli.js +4 -2
- package/dist/index.js +48 -6
- package/package.json +6 -6
package/README.md
CHANGED
|
@@ -511,6 +511,21 @@ output
|
|
|
511
511
|
export default 'hello world'
|
|
512
512
|
```
|
|
513
513
|
|
|
514
|
+
#### Raw Imports with `?raw` Query
|
|
515
|
+
|
|
516
|
+
You can also import any file as raw text content by adding the `?raw` query parameter to the import statement. This works with any file type:
|
|
517
|
+
|
|
518
|
+
```js
|
|
519
|
+
import readme from './README.md?raw'
|
|
520
|
+
import config from './config.json?raw'
|
|
521
|
+
import styles from './styles.css?raw'
|
|
522
|
+
import content from './data.xml?raw'
|
|
523
|
+
|
|
524
|
+
export { readme, config, styles, content }
|
|
525
|
+
```
|
|
526
|
+
|
|
527
|
+
All these imports will be bundled as string content, regardless of the original file extension.
|
|
528
|
+
|
|
514
529
|
### Node.js API
|
|
515
530
|
|
|
516
531
|
```ts
|
package/dist/bin/cli.js
CHANGED
|
@@ -646,7 +646,7 @@ function lint$1(pkg) {
|
|
|
646
646
|
}
|
|
647
647
|
}
|
|
648
648
|
|
|
649
|
-
var version = "6.
|
|
649
|
+
var version = "6.6.0";
|
|
650
650
|
|
|
651
651
|
async function writeDefaultTsconfig(tsConfigPath) {
|
|
652
652
|
await fs.promises.writeFile(tsConfigPath, JSON.stringify(DEFAULT_TS_CONFIG, null, 2), 'utf-8');
|
|
@@ -1008,7 +1008,9 @@ function logOutputState(stats) {
|
|
|
1008
1008
|
const maxFilenameLength = Math.max(...allFileNameLengths);
|
|
1009
1009
|
const statsArray = [
|
|
1010
1010
|
...stats.entries()
|
|
1011
|
-
].
|
|
1011
|
+
]// filter out empty file states.
|
|
1012
|
+
// e.g. if you're building a file that does not listed in the exports, or there's no exports condition.
|
|
1013
|
+
.filter(([, fileStates])=>fileStates.length > 0).sort(([a], [b])=>{
|
|
1012
1014
|
const comp = normalizeExportPath(a).length - normalizeExportPath(b).length;
|
|
1013
1015
|
return comp === 0 ? a.localeCompare(b) : comp;
|
|
1014
1016
|
});
|
package/dist/index.js
CHANGED
|
@@ -1281,10 +1281,42 @@ function rawContent({ exclude }) {
|
|
|
1281
1281
|
], exclude);
|
|
1282
1282
|
return {
|
|
1283
1283
|
name: 'string',
|
|
1284
|
+
resolveId (id, importer) {
|
|
1285
|
+
// Handle ?raw query parameter
|
|
1286
|
+
if (id.includes('?raw')) {
|
|
1287
|
+
const cleanId = id.split('?')[0];
|
|
1288
|
+
// Resolve the actual file path
|
|
1289
|
+
if (importer) {
|
|
1290
|
+
const path = require('path');
|
|
1291
|
+
return path.resolve(path.dirname(importer), cleanId) + '?raw';
|
|
1292
|
+
}
|
|
1293
|
+
return cleanId + '?raw';
|
|
1294
|
+
}
|
|
1295
|
+
return null;
|
|
1296
|
+
},
|
|
1297
|
+
async load (id) {
|
|
1298
|
+
// Handle ?raw query parameter - read the actual file without the query
|
|
1299
|
+
if (id.includes('?raw')) {
|
|
1300
|
+
const cleanId = id.split('?')[0];
|
|
1301
|
+
try {
|
|
1302
|
+
const content = await fsp.readFile(cleanId, 'utf-8');
|
|
1303
|
+
// Normalize line endings only on Windows: convert \r\n to \n
|
|
1304
|
+
return process.platform === 'win32' ? content.replace(/\r\n/g, '\n') : content;
|
|
1305
|
+
} catch (error) {
|
|
1306
|
+
this.error(`[bunchee] failed to read file: ${cleanId}`);
|
|
1307
|
+
}
|
|
1308
|
+
}
|
|
1309
|
+
return null;
|
|
1310
|
+
},
|
|
1284
1311
|
transform (code, id) {
|
|
1285
|
-
if
|
|
1312
|
+
// Check if the file has ?raw query parameter
|
|
1313
|
+
const isRawQuery = id.includes('?raw');
|
|
1314
|
+
const cleanId = isRawQuery ? id.split('?')[0] : id;
|
|
1315
|
+
if (filter(cleanId) || isRawQuery) {
|
|
1316
|
+
// Normalize line endings only on Windows for .txt and .data files
|
|
1317
|
+
const normalizedCode = process.platform === 'win32' ? code.replace(/\r\n/g, '\n') : code;
|
|
1286
1318
|
return {
|
|
1287
|
-
code: `const data = ${JSON.stringify(
|
|
1319
|
+
code: `const data = ${JSON.stringify(normalizedCode)};\nexport default data;`,
|
|
1288
1320
|
map: null
|
|
1289
1321
|
};
|
|
1290
1322
|
}
|
|
@@ -1448,7 +1480,6 @@ async function createDtsPlugin(tsCompilerOptions, tsConfigPath, respectExternal,
|
|
|
1448
1480
|
noEmitOnError: true,
|
|
1449
1481
|
emitDeclarationOnly: true,
|
|
1450
1482
|
checkJs: false,
|
|
1451
|
-
declarationMap: false,
|
|
1452
1483
|
skipLibCheck: true,
|
|
1453
1484
|
// preserveSymlinks should always be set to false to avoid issues with
|
|
1454
1485
|
// resolving types from <reference> from node_modules
|
|
@@ -1623,8 +1654,7 @@ async function buildInputConfig(entry, bundleConfig, exportCondition, buildConte
|
|
|
1623
1654
|
const hashTo3Char = memoize((input)=>{
|
|
1624
1655
|
let hash = 0;
|
|
1625
1656
|
for(let i = 0; i < input.length; i++){
|
|
1626
|
-
hash = (hash << 5) - hash + input.charCodeAt(i) // Simple hash shift
|
|
1627
|
-
;
|
|
1657
|
+
hash = (hash << 5) - hash + input.charCodeAt(i); // Simple hash shift
|
|
1628
1658
|
}
|
|
1629
1659
|
return (hash >>> 0).toString(36).slice(0, 3) // Base36 + trim to 3 chars
|
|
1630
1660
|
;
|
|
@@ -1721,6 +1751,18 @@ async function buildOutputConfigs(bundleConfig, exportCondition, buildContext, d
|
|
|
1721
1751
|
const jsDir = path.dirname(absoluteOutputFile);
|
|
1722
1752
|
const outputFile = dts ? dtsFile : absoluteOutputFile;
|
|
1723
1753
|
const entryFiles = new Set(Object.values(entries).map((entry)=>entry.source));
|
|
1754
|
+
// By default, respect the original bunchee sourcemap option
|
|
1755
|
+
let sourcemap = !!bundleConfig.sourcemap;
|
|
1756
|
+
// If it's typescript, checking if declaration map is enabled,
|
|
1757
|
+
// otherwise we don't enable sourcemap for type files.
|
|
1758
|
+
// cases:
|
|
1759
|
+
// sourcemap (✓) + declarationMap (✓) => sourcemap for dts
|
|
1760
|
+
// sourcemap (✗) + declarationMap (✓) => sourcemap for dts
|
|
1761
|
+
// sourcemap (✓) + declarationMap (✗) => no sourcemap for dts
|
|
1762
|
+
// sourcemap (✗) + declarationMap (✗) => no sourcemap for dts
|
|
1763
|
+
if (dts) {
|
|
1764
|
+
sourcemap = !!(tsCompilerOptions == null ? void 0 : tsCompilerOptions.declarationMap);
|
|
1765
|
+
}
|
|
1724
1766
|
const outputOptions = {
|
|
1725
1767
|
name: pkg.name || name,
|
|
1726
1768
|
extend: true,
|
|
@@ -1731,7 +1773,7 @@ async function buildOutputConfigs(bundleConfig, exportCondition, buildContext, d
|
|
|
1731
1773
|
interop: 'auto',
|
|
1732
1774
|
freeze: false,
|
|
1733
1775
|
strict: false,
|
|
1734
|
-
sourcemap
|
|
1776
|
+
sourcemap,
|
|
1735
1777
|
manualChunks: createSplitChunks(pluginContext.moduleDirectiveLayerMap, entryFiles),
|
|
1736
1778
|
chunkFileNames () {
|
|
1737
1779
|
const isCjsFormat = format === 'cjs';
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "bunchee",
|
|
3
|
-
"version": "6.
|
|
3
|
+
"version": "6.6.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",
|
|
@@ -37,21 +37,21 @@
|
|
|
37
37
|
},
|
|
38
38
|
"license": "MIT",
|
|
39
39
|
"dependencies": {
|
|
40
|
-
"@rollup/plugin-commonjs": "^28.0.
|
|
40
|
+
"@rollup/plugin-commonjs": "^28.0.6",
|
|
41
41
|
"@rollup/plugin-json": "^6.1.0",
|
|
42
42
|
"@rollup/plugin-node-resolve": "^16.0.1",
|
|
43
43
|
"@rollup/plugin-replace": "^6.0.2",
|
|
44
44
|
"@rollup/plugin-wasm": "^6.2.2",
|
|
45
45
|
"@rollup/pluginutils": "^5.1.4",
|
|
46
|
-
"@swc/core": "^1.
|
|
47
|
-
"@swc/helpers": "^0.5.
|
|
46
|
+
"@swc/core": "^1.13.3",
|
|
47
|
+
"@swc/helpers": "^0.5.17",
|
|
48
48
|
"clean-css": "^5.3.3",
|
|
49
49
|
"fast-glob": "^3.3.3",
|
|
50
50
|
"magic-string": "^0.30.17",
|
|
51
51
|
"ora": "^8.0.1",
|
|
52
52
|
"picomatch": "^4.0.2",
|
|
53
53
|
"pretty-bytes": "^5.6.0",
|
|
54
|
-
"rollup": "^4.
|
|
54
|
+
"rollup": "^4.46.2",
|
|
55
55
|
"rollup-plugin-dts": "^6.2.1",
|
|
56
56
|
"rollup-plugin-swc3": "^0.11.1",
|
|
57
57
|
"rollup-preserve-directives": "^1.1.3",
|
|
@@ -90,7 +90,7 @@
|
|
|
90
90
|
"react": "^19.0.0",
|
|
91
91
|
"react-dom": "^19.0.0",
|
|
92
92
|
"tailwindcss": "^4.1.8",
|
|
93
|
-
"typescript": "^5.
|
|
93
|
+
"typescript": "^5.9.2",
|
|
94
94
|
"vitest": "^3.0.4"
|
|
95
95
|
},
|
|
96
96
|
"lint-staged": {
|