Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions packages/dsv/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
"rollup-plugin"
],
"peerDependencies": {
"rollup": "^2.78.0||^3.0.0||^4.0.0"
"rollup": "^2.78.0||^3.0.0||^4.0.0||^5.0.0"
},
"peerDependenciesMeta": {
"rollup": {
Expand All @@ -60,7 +60,7 @@
},
"devDependencies": {
"del-cli": "^5.0.0",
"rollup": "^4.0.0-24"
"rollup": "catalog:rollup-next"

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Rollup outgrows Node 20

Switching dsv to catalog:rollup-next selects Rollup 5.0.0-2, which requires Node >=22.22.0. Both CI workflows still build or test this package on Node 20, and .nvmrc also selects Node 20. These jobs and contributors now run the build with an unsupported Node version.

Keep the Node 20 jobs on a supported Rollup version, or update the runtime setup alongside this change.

},
"types": "./types/index.d.ts"
}
12 changes: 7 additions & 5 deletions packages/dsv/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,11 @@ import { createFilter } from '@rollup/pluginutils';
import stripBom from 'strip-bom';

const parsers = { '.csv': csvParse, '.tsv': tsvParse };
// Rollup 5 appends encoded import attributes to the id as a query
const idFilter = new RegExp(
`\\.(?:${Object.keys(parsers)
.map((ext) => ext.slice(1))
.join('|')})$`
.join('|')})(?:$|\\?)`
);

export default function dsv(options = {}) {
Expand All @@ -22,16 +23,17 @@ export default function dsv(options = {}) {
filter: {
id: idFilter
},
handler(code, id) {
if (!filter(id)) return null;
handler(code, id, transformOptions) {
const rawId = (transformOptions && transformOptions.rawId) || id;
if (!filter(rawId)) return null;

const ext = extname(id);
const ext = extname(rawId);
if (!(ext in parsers)) return null;

let rows = parsers[ext](stripBom(code));

if (options.processRow) {
rows = rows.map((row) => options.processRow(row, id) || row);
rows = rows.map((row) => options.processRow(row, rawId) || row);
}

return {
Expand Down
7 changes: 7 additions & 0 deletions packages/dsv/test/fixtures/basic-csv/main-with-type.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import fruit from './fruit.csv' with { type: 'csv' };

expect(fruit).toEqual([
{ type: 'apples', count: '7' },
{ type: 'pears', count: '4' },
{ type: 'bananas', count: '5' }
]);
18 changes: 18 additions & 0 deletions packages/dsv/test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,3 +78,21 @@ test('uses a custom processor with id', async () => {
});
return testBundle(bundle);
});

test('converts csv files imported with import attributes', async () => {
let processedId;
const bundle = await rollup({
input: 'fixtures/basic-csv/main-with-type.js',
plugins: [
dsv({
include: '**/*.csv',
exclude: /attributes/,
processRow(row, rowId) {
processedId = rowId;
}
})
]
});
await testBundle(bundle);
expect(processedId).toMatch(/fruit\.csv$/);
});
Loading
Loading