bunchee 6.5.4 → 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 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.5.4";
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
- ].sort(([a], [b])=>{
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 (filter(id)) {
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(code)};\nexport default data;`,
1319
+ code: `const data = ${JSON.stringify(normalizedCode)};\nexport default data;`,
1288
1320
  map: null
1289
1321
  };
1290
1322
  }
@@ -1622,8 +1654,7 @@ async function buildInputConfig(entry, bundleConfig, exportCondition, buildConte
1622
1654
  const hashTo3Char = memoize((input)=>{
1623
1655
  let hash = 0;
1624
1656
  for(let i = 0; i < input.length; i++){
1625
- hash = (hash << 5) - hash + input.charCodeAt(i) // Simple hash shift
1626
- ;
1657
+ hash = (hash << 5) - hash + input.charCodeAt(i); // Simple hash shift
1627
1658
  }
1628
1659
  return (hash >>> 0).toString(36).slice(0, 3) // Base36 + trim to 3 chars
1629
1660
  ;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "bunchee",
3
- "version": "6.5.4",
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.3",
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.11.21",
47
- "@swc/helpers": "^0.5.15",
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.40.0",
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.7.2",
93
+ "typescript": "^5.9.2",
94
94
  "vitest": "^3.0.4"
95
95
  },
96
96
  "lint-staged": {