Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(dsv): fix type of processRow option #1581

Merged
merged 3 commits into from
Sep 25, 2023
Merged
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
12 changes: 11 additions & 1 deletion packages/dsv/test/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,17 @@ const config: RollupOptions = {
include: 'node_modules/**',
exclude: ['node_modules/foo/**', 'node_modules/bar/**'],
processRow(row) {
return row;
return {
foo: +row.foo,
bar: new Date(row.bar),
baz: row.baz === 'true',
...row
};
}
}),
dsv({
processRow() {
// void
}
})
]
Expand Down
2 changes: 1 addition & 1 deletion packages/dsv/types/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ interface RollupDsvOptions {
* The function can either manipulate the passed row, or return an entirely new row object.
* @default undefined
*/
processRow?: null | ((row: DSVRowString, id: string) => DSVRowString | undefined);
processRow?: null | ((row: DSVRowString, id: string) => object | void);
}

/**
Expand Down
8 changes: 4 additions & 4 deletions packages/typescript/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import findTypescriptOutput, {
normalizePath,
emitFile,
isDeclarationOutputFile,
isMapOutputFile
isTypeScriptMapOutputFile
} from './outputFile';
import { preflight } from './preflight';
import createWatchProgram, { WatchProgramHelper } from './watchProgram';
Expand Down Expand Up @@ -156,11 +156,11 @@ export default function typescript(options: RollupTypescriptOptions = {}): Plugi
},

async generateBundle(outputOptions) {
const declarationAndMapFiles = [...emittedFiles.keys()].filter(
(fileName) => isDeclarationOutputFile(fileName) || isMapOutputFile(fileName)
const declarationAndTypeScriptMapFiles = [...emittedFiles.keys()].filter(
(fileName) => isDeclarationOutputFile(fileName) || isTypeScriptMapOutputFile(fileName)
);

declarationAndMapFiles.forEach((id) => {
declarationAndTypeScriptMapFiles.forEach((id) => {
const code = getEmittedFile(id, emittedFiles, tsCache);
if (!code || !parsedOptions.options.declaration) {
return;
Expand Down
7 changes: 7 additions & 0 deletions packages/typescript/src/outputFile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,13 @@ export function isCodeOutputFile(name: string): boolean {
* Checks if the given OutputFile represents some source map
*/
export function isMapOutputFile(name: string): boolean {
return name.endsWith('.map');
}

/**
* Checks if the given OutputFile represents some TypeScript source map
*/
export function isTypeScriptMapOutputFile(name: string): boolean {
return name.endsWith('ts.map');
}

Expand Down
18 changes: 18 additions & 0 deletions packages/typescript/test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -612,6 +612,24 @@ test.serial('should not emit null sourceContent', async (t) => {
t.false(sourcemap.sourcesContent.includes(undefined));
});

test.serial('should not emit sourceContent that references a non-existent file', async (t) => {
const bundle = await rollup({
input: 'fixtures/basic/main.ts',
output: {
sourcemap: true
},
plugins: [
typescript({
tsconfig: 'fixtures/basic/tsconfig.json'
})
],
onwarn
});
const output = await getCode(bundle, { format: 'es', sourcemap: true }, true);
const sourcemap = output[0].map;
t.false(sourcemap.sourcesContent.includes('//# sourceMappingURL=main.js.map'));
});

test.serial('should not fail if source maps are off', async (t) => {
await t.notThrowsAsync(
rollup({
Expand Down
Loading