Skip to content

Commit 3c7924f

Browse files
committed
minor fixes
1 parent 1c06274 commit 3c7924f

File tree

2 files changed

+18
-9
lines changed

2 files changed

+18
-9
lines changed

packages/editor/src/runtime/editor/languages/typescript/typeAcquisition.ts

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,7 @@ const addTypecellModuleToRuntime = async (
200200
config.logger.log("adding typecell module", path);
201201
config.addLibraryToRuntime(
202202
content,
203-
`file:///node_modules/@types/${mod}/${path}`
203+
`file://node_modules/@types/${mod}/${path}`
204204
);
205205
};
206206

@@ -245,7 +245,7 @@ const addModuleToRuntime = async (
245245
} else {
246246
const typelessModule = mod.split("@types/").slice(-1);
247247
const wrapped = `declare module "${typelessModule}" { ${content} }`;
248-
config.addLibraryToRuntime(wrapped, `node_modules/${mod}/${path}`);
248+
config.addLibraryToRuntime(wrapped, `file://node_modules/${mod}/${path}`);
249249
}
250250
};
251251

@@ -316,7 +316,7 @@ const getModuleAndRootDefTypePath = async (
316316

317317
config.addLibraryToRuntime(
318318
JSON.stringify(responseJSON, null, " "),
319-
`node_modules/${packageName}/package.json`
319+
`file://node_modules/${packageName}/package.json`
320320
);
321321

322322
// Get the path of the root d.ts file
@@ -430,7 +430,7 @@ const getReferenceDependencies = async (
430430
newPath,
431431
config
432432
);
433-
const representationalPath = `node_modules/${mod}/${newPath}`;
433+
const representationalPath = `file://node_modules/${mod}/${newPath}`;
434434
config.addLibraryToRuntime(
435435
dtsReferenceResponseText,
436436
representationalPath
@@ -580,9 +580,18 @@ const getDependenciesForModule = async (
580580
// So it doesn't run twice for a package
581581
acquiredTypeDefs[moduleID] = null;
582582

583-
const resolvedFilepath = absolutePathForModule.endsWith(".ts")
584-
? absolutePathForModule
585-
: absolutePathForModule + ".d.ts";
583+
let resolvedFilepath = absolutePathForModule;
584+
585+
if (!resolvedFilepath.endsWith(".ts")) {
586+
if (resolvedFilepath.endsWith(".js")) {
587+
// case: import apache-arrow
588+
resolvedFilepath =
589+
resolvedFilepath.substring(0, resolvedFilepath.length - 3) +
590+
".d.ts";
591+
} else {
592+
resolvedFilepath += absolutePathForModule + ".d.ts";
593+
}
594+
}
586595

587596
if (
588597
moduleName?.startsWith("typecell") ||

packages/engine/src/resolvers/cdns/ESMshResolver.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,14 @@ export class ESMshResolver extends ExternalModuleResolver {
1414
if (library) {
1515
return undefined;
1616
}
17-
let matches = url.match(/^\/v\d+\/(.*)@[.\d]+\/(.*)$/);
17+
let matches = url.match(/^\/v\d+\/(.*)@[.\d]+(-[-a-z\d.]+)?\/(.*)$/);
1818
if (!matches || !matches[1]) {
1919
throw new Error("couldn't match url");
2020
}
2121
const matchedModuleName = matches[1];
2222

2323
// mode is necessary for jsx-runtime, e.g.: @yousef/use-p2
24-
mode = matches[2];
24+
mode = matches[3];
2525

2626
return {
2727
module: matchedModuleName,

0 commit comments

Comments
 (0)