Skip to content

Commit fc441af

Browse files
committed
editor: fix type tracking issue
1 parent 3ae97aa commit fc441af

File tree

3 files changed

+20
-8
lines changed

3 files changed

+20
-8
lines changed

assets/js/editor/Editor.tsx

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -158,11 +158,12 @@ async function loadDTS(specifier: string): Promise<Lib[]> {
158158
if (!filePath.startsWith('node_modules')) {
159159
// Load every common typedef into the common module
160160
let content = await fetchFile(`${commonSpecifier}${filePath}`);
161-
content = content.replace(/\* +@(.+?)\*\//gs, '*/');
162-
console.log(content);
163-
results.push({
164-
content: `declare module '@openfn/language-common' { ${content} }`,
165-
});
161+
if (!content.startsWith('<!DOCTYPE html>')) {
162+
content = content.replace(/\* +@(.+?)\*\//gs, '*/');
163+
results.push({
164+
content: `declare module '@openfn/language-common' { ${content} }`,
165+
});
166+
}
166167
}
167168
}
168169
}
@@ -176,6 +177,13 @@ async function loadDTS(specifier: string): Promise<Lib[]> {
176177
for await (const filePath of fetchDTSListing(specifier)) {
177178
if (!filePath.startsWith('node_modules')) {
178179
let content = await fetchFile(`${specifier}${filePath}`);
180+
if (content.match(/<!doctype html>/i)) {
181+
continue;
182+
}
183+
// Convert relative paths
184+
content = content
185+
.replace(/from '\.\//g, `from '${name}/`)
186+
.replace(/import '\.\//g, `import '${name}/`);
179187

180188
// Remove js doc annotations
181189
// this regex means: find a * then an @ (with 1+ space in between), then match everything up to a closing comment */
@@ -186,9 +194,6 @@ async function loadDTS(specifier: string): Promise<Lib[]> {
186194

187195
// Import the index as the global namespace - but take care to convert all paths to absolute
188196
if (fileName === 'index' || fileName === 'Adaptor') {
189-
content = content.replace(/from '\.\//g, `from '${name}/`);
190-
content = content.replace(/import '\.\//g, `import '${name}/`);
191-
192197
// It turns out that "export * as " seems to straight up not work in Monaco
193198
// So this little hack will refactor import statements in a way that works
194199
content = content.replace(
@@ -218,6 +223,7 @@ async function loadDTS(specifier: string): Promise<Lib[]> {
218223
// This is basically a hack to work around https://github.com/OpenFn/lightning/issues/2641
219224
// If we find a types.d.ts, append it to every other file
220225
adaptorDefs = adaptorDefs.map(def => def.replace('{{$TYPES}}', types));
226+
console.log(adaptorDefs);
221227

222228
results.push(
223229
...adaptorDefs.map(content => ({

assets/js/editor/lib/es5.dts.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
// https://github.com/microsoft/TypeScript/blob/main/lib/lib.es5.d.ts
22
export default `
3+
4+
35
interface Array<T> {
46
/**
57
* Gets or sets the length of the array. This is a number one higher than the highest index in the array.
@@ -178,6 +180,9 @@ interface Array<T> {
178180
*/
179181
reduceRight<U>(callbackfn: (previousValue: U, currentValue: T, currentIndex: number, array: T[]) => U, initialValue: U): U;
180182
183+
// JC copied out of VSC core. Needed to support union types apparently
184+
copyWithin(target: number, start: number, end?: number): this;
185+
181186
// JC note that this is the only thing we actually need to get the types to track
182187
// we could ditch the rest of the definition (if no-one wants to code-complete array.length)
183188
[n: number]: T;

assets/js/editor/lib/es5.min.dts.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
// Super minimal array definition to support typings
22
export default `
33
interface Array<T> {
4+
copyWithin(target: number, start: number, end?: number): this;
45
[n: number]: T;
56
}
67

0 commit comments

Comments
 (0)