Closed OmgImAlexis closed 4 years ago
TBH, I have never understood what the semantics of import foo = require("bar");
are supposed to be.
Isn’t that statement deprecated in favor of some standard import syntax?
Either way, are you explicitly allowing external modules? Usually anything from node_modules
should be excluded.
Me either but it’s how the library is using it.
I’ll have to check I’m using https://github.com/egoist/tsup
Oh nice! Your project is https://github.com/scratchdb/database right? Can you try this plugin directly? I don’t know why its even trying to load things from node_modules
.
Yes that’s the repo.
I can try. I haven’t used rollup before outside of tooling like tsup. Any pointers?
from my readme:
import dts from "rollup-plugin-dts";
const config = [
// …
{
input: "./my-input/index.d.ts",
output: [{ file: "dist/my-library.d.ts", format: "es" }],
plugins: [dts()],
},
];
export default config;
I’ll give this a go and get back to you. Thanks.
If you pull that database repo and run rollup -c
you'll see this.
➜ database git:(master) rollup -c
./lib/index.ts → dist/database.d.ts...
(!) Circular dependency: lib/index.ts -> lib/drivers/index.ts -> lib/drivers/sqlite.ts -> lib/index.ts
created dist/database.d.ts in 2.8s
If I check the output file it looks okay from a quick inspection.
import { Database } from 'better-sqlite3';
interface DriverConnection {
uri: string;
}
interface DriverOptions {
connections: DriverConnection[];
}
declare type Logger = Console;
declare class Driver {
protected log: Logger;
constructor(options: DriverOptions);
}
interface Options extends DriverOptions {
}
declare class SQLite<Tables> extends Driver {
connection: Database;
constructor(options: Options);
protected serialiseParams(params: {
[key: string]: unknown;
}): {
[k: string]: unknown;
};
insert<T extends keyof Tables>(table: T, params: DatabaseInsert<Tables[T]>): Promise<Tables[T]>;
update<T extends keyof Tables>(table: T, id: string, params: DatabaseInsert<Tables[T]>): Promise<void>;
buildSelect<T extends keyof Tables>(table: T, fields?: string[], params?: Partial<Tables[T]>): Promise<{
sqlQuery: string;
sqlParams: {
[k: string]: unknown;
};
}>;
findOne<T extends keyof Tables>(table: T, fields?: string[], params?: Partial<Tables[T]>): Promise<Tables[T]>;
find<T extends keyof Tables>(table: T, fields?: string[], params?: Partial<Tables[T]>): Promise<Tables[T][]>;
}
interface Options$1 extends DriverOptions {
}
declare class MySQL<Tables> extends Driver {
constructor(options: Options$1);
}
declare type DatabaseInsert<T> = Pick<T, Exclude<keyof T, 'id' | 'lastUpdated'>>;
interface Connection {
uri: string;
}
declare type Driver$1 = 'SQLite' | 'MySQL';
interface Options$2 {
connections: Connection[];
}
interface Drivers<Tables> {
SQLite: SQLite<Tables>;
MySQL: MySQL<Tables>;
}
declare function createDatabase<Tables>(driver: 'SQLite', options: Options$2): Drivers<Tables>['SQLite'];
declare function createDatabase<Tables>(driver: 'MySQL', options: Options$2): Drivers<Tables>['MySQL'];
export { Connection, DatabaseInsert, Driver$1 as Driver, Options$2 as Options, createDatabase };
Could this be a tsup
issue?
possible. they use a custom resolver, maybe that is not correctly flagging externals from node_modules
.
https://github.com/egoist/tsup/blob/57dfa9633c3d9fa159579d3ef32e3f15a2128b5d/src/index.ts#L65-L69
either way, this still is a real issue with my plugin that I need to fix at some point.
@Swatinem possible. they use a custom resolver, maybe that is not correctly flagging externals from
node_modules
.
Yes I should probably make it externalize types from node_modules by default, that was there because I want to bundle types for Deno.
Thanks for making this plugin btw, I use it a lot!
Thanks for making this plugin btw, I use it a lot!
glad to hear ;-)
that was there because I want to bundle types for Deno.
How does that even work in deno?
Deno supports .d.ts
for js files:
// @deno-types="https://unpkg.com/mod/types.d.ts"
import { foo } from 'https://unpkg.com/mod/index.js'
But it can't resolve types from node_modules
, so I had to bundle them in the .d.ts
.