Skip to content

Commit

Permalink
Copy type tests on build (#259)
Browse files Browse the repository at this point in the history
  • Loading branch information
tommy-mitchell committed Feb 29, 2024
1 parent 97e8b20 commit f0c7203
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 133 deletions.
1 change: 1 addition & 0 deletions .gitignore
@@ -1,3 +1,4 @@
node_modules
build
yarn.lock
test-d/build.ts
18 changes: 16 additions & 2 deletions rollup.config.js
@@ -1,3 +1,4 @@
import fs from 'node:fs/promises';
import {nodeResolve} from '@rollup/plugin-node-resolve';
import commonjs from '@rollup/plugin-commonjs';
import json from '@rollup/plugin-json';
Expand All @@ -16,10 +17,11 @@ const stripComments = createTag(
replaceResultTransformer(emptyLineRegex, ''),
);

const sourceDirectory = 'source';
const outputDirectory = 'build';

const config = defineConfig({
input: await globby('source/**/*.js'),
input: await globby(`${sourceDirectory}/**/*.js`),
output: {
dir: outputDirectory,
interop: 'esModule',
Expand Down Expand Up @@ -58,7 +60,7 @@ const config = defineConfig({
});

const dtsConfig = defineConfig({
input: './source/index.d.ts',
input: `./${sourceDirectory}/index.d.ts`,
output: {
file: `./${outputDirectory}/index.d.ts`,
format: 'es',
Expand All @@ -67,6 +69,18 @@ const dtsConfig = defineConfig({
dts({
respectExternal: true,
}),
{
name: 'copy-tsd',
async generateBundle() {
let tsdFile = await fs.readFile('./test-d/index.ts', 'utf8');
tsdFile = tsdFile.replace(
`import meow from '../${sourceDirectory}/index.js'`,
`import meow from '../${outputDirectory}/index.js'`,
);

await fs.writeFile(`./test-d/${outputDirectory}.ts`, tsdFile);
},
},
],
});

Expand Down
131 changes: 0 additions & 131 deletions test-d/build.test-d.ts

This file was deleted.

File renamed without changes.

0 comments on commit f0c7203

Please sign in to comment.