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

generate index.d.ts in build #338

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
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
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"version": "3.4.7",
"main": "./dist/pretender.js",
"module": "./dist/pretender.es.js",
"types": "index.d.ts",
"types": "./dist/index.d.ts",
"description": "Pretender is a mock server library for XMLHttpRequest and Fetch, that comes with an express/sinatra style syntax for defining routes and their handlers.",
"license": "MIT",
"scripts": {
Expand Down Expand Up @@ -42,6 +42,7 @@
"release-it-lerna-changelog": "^2.3.0",
"rollup": "^2.10.2",
"rollup-plugin-typescript": "^1.0.0",
Copy link
Member

Choose a reason for hiding this comment

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

I think you need to remove this then rerun yarn.

error Your lockfile needs to be updated

"rollup-plugin-typescript2": "^0.30.0",
"sinon": "^9.0.2",
"tslib": "^1.9.3",
"typescript": "~3.1.1",
Expand Down
6 changes: 3 additions & 3 deletions rollup.config.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import commonjs from "@rollup/plugin-commonjs";
import resolve from "@rollup/plugin-node-resolve";
import typescript from "rollup-plugin-typescript";
import typescript from "rollup-plugin-typescript2";
import { readFileSync } from "fs";
import pkg from "./package.json";

Expand Down Expand Up @@ -31,7 +31,7 @@ module.exports = [
format: "es",
},
],
plugins: [commonjs(), resolve(), typescript()],
plugins: [commonjs(), resolve(), typescript({ useTsconfigDeclarationDir: true })],
},
{
input: "src/index.ts",
Expand All @@ -42,6 +42,6 @@ module.exports = [
format: "iife",
}
],
plugins: [commonjs(), resolve(), typescript()],
plugins: [commonjs(), resolve(), typescript({ useTsconfigDeclarationDir: true })],
},
];
2 changes: 1 addition & 1 deletion src/create-passthrough.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ export function createPassthrough(fakeXHR, nativeXMLHttpRequest) {
var evts = ['error', 'timeout', 'abort', 'readystatechange'];

// event types to handle on the xhr.upload
var uploadEvents = [];
var uploadEvents: string[] = [];

// properties to copy from the native xhr to fake xhr
var lifecycleProps = [
Expand Down
2 changes: 1 addition & 1 deletion src/interceptor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import FakeXMLHttpRequest from 'fake-xml-http-request';
import { createPassthrough } from './create-passthrough';

export function interceptor(ctx) {
function FakeRequest() {
function FakeRequest(this: any) {
Copy link
Author

@katehedgpeth katehedgpeth Oct 26, 2021

Choose a reason for hiding this comment

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

I really hate using any, but I wasn't totally sure what this should be. Is it Pretender?

Copy link
Member

Choose a reason for hiding this comment

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

This should really be rewritten into class :) Seems the generated type is fine, maybe just leave it there for now

// super()
FakeXMLHttpRequest.call(this);
}
Expand Down
4 changes: 2 additions & 2 deletions src/pretender.ts
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ export default class Pretender {
}

handleRequest(request: FakeRequest) {
let verb = request.method.toUpperCase();
let verb = request.method.toUpperCase() as Verb;
let path = request.url;

let handler = this._handlerFor(verb, path, request);
Expand Down Expand Up @@ -289,7 +289,7 @@ export default class Pretender {
}

requiresManualResolution(verb: string, path: string) {
let handler = this._handlerFor(verb.toUpperCase(), path, {});
let handler = this._handlerFor(verb.toUpperCase() as Verb, path, {} as FakeRequest);
if (!handler) {
return false;
}
Expand Down
5 changes: 3 additions & 2 deletions tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,12 @@
"compilerOptions": {
/* Basic Options */
"target": "es5", /* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017','ES2018' or 'ESNEXT'. */
"module": "commonjs", /* Specify module code generation: 'none', 'commonjs', 'amd', 'system', 'umd', 'es2015', or 'ESNext'. */
"module": "ESNext", /* Specify module code generation: 'none', 'commonjs', 'amd', 'system', 'umd', 'es2015', or 'ESNext'. */
// "lib": [], /* Specify library files to be included in the compilation. */
// "allowJs": true, /* Allow javascript files to be compiled. */
// "checkJs": true, /* Report errors in .js files. */
"declaration": false, /* Generates corresponding '.d.ts' file. */
"declaration": true, /* Generates corresponding '.d.ts' file. */
"declarationDir": "dist",
// "declarationMap": true, /* Generates a sourcemap for each corresponding '.d.ts' file. */
// "sourceMap": true, /* Generates corresponding '.map' file. */
// "outFile": "./", /* Concatenate and emit output to single file. */
Expand Down