Skip to content

Commit 5de9e92

Browse files
authored
chore: don't include the shell api twice (#539)
don't include the shell api twice
1 parent 1965782 commit 5de9e92

File tree

3 files changed

+13
-9
lines changed

3 files changed

+13
-9
lines changed

packages/mongodb-ts-autocomplete/scripts/extract-types.ts

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,7 @@
11
/* eslint-disable no-console */
22
import { promises as fs } from 'fs';
33
import path from 'path';
4-
import { api as ShellApiText } from '@mongosh/shell-api/api';
5-
6-
function replaceImports(code: string) {
7-
// This just makes it possible to work on mql.ts because then the
8-
// IDE finds the import.
9-
return code.replace(/'bson'/g, "'/bson.ts'");
10-
}
4+
import { replaceImports } from '../src/utils';
115

126
async function loadSources(sources: Record<string, string>) {
137
const result: Record<string, string> = {};
@@ -25,7 +19,6 @@ async function run() {
2519
'/mql.ts': path.join(__dirname, '..', 'src', 'fixtures', 'mql.ts'),
2620
};
2721
const files = await loadSources(input);
28-
files['/shell-api.ts'] = replaceImports(ShellApiText);
2922
const code = `
3023
const files = ${JSON.stringify(files)};
3124
export default files;
@@ -38,6 +31,7 @@ export default files;
3831
'fixtures',
3932
'autocomplete-types.ts',
4033
);
34+
console.log(filepath);
4135
await fs.writeFile(filepath, code, 'utf-8');
4236
}
4337

packages/mongodb-ts-autocomplete/src/autocompleter.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
import Autocompleter from '@mongodb-js/ts-autocomplete';
22
import type { AutoCompletion } from '@mongodb-js/ts-autocomplete';
33
import autocompleteTypes from './fixtures/autocomplete-types';
4+
import { api as ShellApiText } from '@mongosh/shell-api/api';
5+
import { replaceImports } from './utils';
46

57
import type { JSONSchema } from 'mongodb-schema';
68
import { toTypescriptTypeDefinition } from 'mongodb-schema';
@@ -159,7 +161,10 @@ export class MongoDBAutocompleter {
159161

160162
this.connectionSchemas = Object.create(null);
161163

162-
this.autocompleter.updateCode(autocompleteTypes);
164+
this.autocompleter.updateCode({
165+
...autocompleteTypes,
166+
'/shell-api.ts': replaceImports(ShellApiText),
167+
});
163168
}
164169

165170
addConnection(connectionId: string): ConnectionSchema {
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
export function replaceImports(code: string) {
2+
// This just makes it possible to work on mql.ts because then the
3+
// IDE finds the import.
4+
return code.replace(/'bson'/g, "'/bson.ts'");
5+
}

0 commit comments

Comments
 (0)