Skip to content

Commit

Permalink
feat: add-ts-declaration-files (#6)
Browse files Browse the repository at this point in the history
* feat: add declaration file

* chore: update repo url
  • Loading branch information
2wce authored May 22, 2024
1 parent 1895ead commit a6c10b1
Show file tree
Hide file tree
Showing 8 changed files with 36 additions and 88 deletions.
5 changes: 5 additions & 0 deletions .changeset/strong-wombats-cross.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'rollup-plugin-sourcemaps2': minor
---

chore: add declaration files
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
"sideEffects": false,
"repository": {
"type": "git",
"url": "https://github.com/2wce/rollup-plugin-sourcemaps"
"url": "https://github.com/2wce/rollup-plugin-sourcemaps2"
},
"engines": {
"node": ">=18.0.0"
Expand All @@ -28,7 +28,7 @@
"prebuild": "npm run lint && npm run format && npm run typecheck",
"lint": "eslint .",
"format": "prettier --write .",
"typecheck": "tsc --noEmit",
"typecheck": "tsc",
"prepublishOnly": "npm run build",
"preversion": "npm run test"
},
Expand Down
3 changes: 2 additions & 1 deletion src/__tests__/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ import { rollup } from 'rollup';
import ts from 'typescript';
import util from 'util';

import sourcemaps, { SourcemapsPluginOptions } from '..';
import sourcemaps from '..';
import { SourcemapsPluginOptions } from '../types';

const inputPath = path.join(__dirname, '../index.ts');
const inputText = fs.readFileSync(inputPath, 'utf8');
Expand Down
64 changes: 0 additions & 64 deletions src/env.d.ts

This file was deleted.

9 changes: 2 additions & 7 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,12 @@
import pluginUtils, { CreateFilter } from '@rollup/pluginutils';
import pluginUtils from '@rollup/pluginutils';
import fs from 'fs';
import { ExistingRawSourceMap, Plugin } from 'rollup';
import { promisify } from 'util';
import { resolveSourceMap, resolveSources } from './source-map-resolve';
import { SourcemapsPluginOptions } from './types';

const { createFilter } = pluginUtils;

export interface SourcemapsPluginOptions {
include?: Parameters<CreateFilter>[0];
exclude?: Parameters<CreateFilter>[1];
readFile?(path: string, callback: (error: Error | null, data: Buffer | string) => void): void;
}

export default function sourcemaps({
include,
exclude,
Expand Down
13 changes: 1 addition & 12 deletions src/source-map-resolve.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,7 @@
import { ExistingRawSourceMap } from 'rollup';
import * as urlLib from 'url';
import decodeUriComponent from './decode-uri-component';

interface ResolvedSourceMap {
map: ExistingRawSourceMap;
url: string | null;
sourcesRelativeTo: string;
sourceMappingURL: string;
}
import { ResolvedSourceMap, ResolvedSources } from './types';

function resolveUrl(...args: string[]): string {
return args.reduce((resolved, nextUrl) => urlLib.resolve(resolved, nextUrl), '');
Expand Down Expand Up @@ -54,11 +48,6 @@ export async function resolveSourceMap(
return { sourceMappingURL, url, sourcesRelativeTo: url, map };
}

interface ResolvedSources {
sourcesResolved: string[];
sourcesContent: (string | Error)[];
}

export async function resolveSources(
map: ExistingRawSourceMap,
mapUrl: string,
Expand Down
20 changes: 20 additions & 0 deletions src/types.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import { CreateFilter } from '@rollup/pluginutils';
import { ExistingRawSourceMap } from 'rollup';

export interface ResolvedSources {
sourcesResolved: string[];
sourcesContent: (string | Error)[];
}

export interface ResolvedSourceMap {
map: ExistingRawSourceMap;
url: string | null;
sourcesRelativeTo: string;
sourceMappingURL: string;
}

export interface SourcemapsPluginOptions {
include?: Parameters<CreateFilter>[0];
exclude?: Parameters<CreateFilter>[1];
readFile?(path: string, callback: (error: Error | null, data: Buffer | string) => void): void;
}
6 changes: 4 additions & 2 deletions tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@
"compilerOptions": {
"target": "es2020",
"declarationDir": "dist",
"rootDir": "src",
"declaration": true,
"emitDeclarationOnly": true,
"rootDir": "src",
"sourceMap": true,
"inlineSources": true,
"strict": true,
Expand All @@ -12,7 +13,8 @@
"skipLibCheck": true,
"module": "ESNext",
"moduleResolution": "bundler",
"allowSyntheticDefaultImports": true
"allowSyntheticDefaultImports": true,
"types": ["node", "jest"]
},
"include": ["src"],
"exclude": ["node_modules"]
Expand Down

0 comments on commit a6c10b1

Please sign in to comment.