Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
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
69 changes: 61 additions & 8 deletions loader/src/resolver/server/findReferencedNodeServer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,9 @@ import {
} from "@flyde/core";

import * as _Nodes from "@flyde/nodes/dist/all";
import { join } from "path";
import { join, dirname } from "path";
import { existsSync, readFileSync } from "fs";
import * as glob from "glob";
import { resolveImportablePaths } from "./resolveImportablePaths";
import { deserializeFlowByPath } from "../../serdes";
import { ReferencedNodeFinder } from "./../ReferencedNodeFinder";
Expand Down Expand Up @@ -205,16 +206,68 @@ function getLocalOrPackagePaths(fullFlowPath: string, importPath: string) {

if (existsSync(fullImportPath)) {
return [fullImportPath];
} else {
try {
return resolveImportablePaths(fullFlowPath, importPath);
} catch (e) {
if (importPath !== "@flyde/nodes") {
throw new Error(`Cannot find module ${importPath} in ${fullFlowPath}`);
}

const extensions = [".flyde", ".flyde.ts", ".ts", ".js"];
for (const ext of extensions) {
if (existsSync(fullImportPath + ext)) {
return [fullImportPath + ext];
}
}

// If a relative import is broken because the file was moved to another folder, search project tree
if (importPath.startsWith(".")) {
const flowDir = dirname(fullFlowPath);
const fileName = importPath.split("/").pop() || "";
if (fileName) {
const candidates = [fileName];
for (const ext of extensions) {
if (!fileName.endsWith(ext)) {
candidates.push(fileName + ext);
}
}

let currentDir = flowDir;
let projectRoot = flowDir;
for (let i = 0; i < 5; i++) {
if (
existsSync(join(currentDir, "package.json")) ||
existsSync(join(currentDir, ".git"))
) {
projectRoot = currentDir;
break;
}
const parent = dirname(currentDir);
if (parent === currentDir) break;
currentDir = parent;
}

for (const cand of candidates) {
const matches = glob.sync(`**/${cand}`, {
cwd: projectRoot,
ignore: [
"**/node_modules/**",
"**/dist/**",
"**/build/**",
"**/.git/**",
],
absolute: true,
});
if (matches.length > 0) {
return [matches[0]];
}
}
return [];
}
}

try {
return resolveImportablePaths(fullFlowPath, importPath);
} catch (e) {
if (importPath !== "@flyde/nodes") {
throw new Error(`Cannot find module ${importPath} in ${fullFlowPath}`);
}
return [];
}
}

// Helper function to get the source code of a node from a file
Expand Down
35 changes: 26 additions & 9 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion vscode/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,8 @@
"socket.io": "^4.5.1",
"ts-node": "^10.9.2",
"use-debounce": "^8.0.4",
"walker": "^1.0.8"
"walker": "^1.0.8",
"yaml": "^2.8.0"
},
"packageManager": "yarn@3.3.1"
}
5 changes: 5 additions & 0 deletions vscode/src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import { activateReporter, reportEvent, analytics } from "./analytics";
import { showFirstRunPrivacyNotice, showPrivacySettings } from "./privacyNotice";

import { Template, getTemplates, scaffoldTemplate } from "./templateUtils";
import { handleFileRenames } from "./fileMoveHandler";

// the application insights key (also known as instrumentation key)

Expand Down Expand Up @@ -229,6 +230,10 @@ export function activate(context: vscode.ExtensionContext) {
await showPrivacySettings();
})
);

context.subscriptions.push(
vscode.workspace.onDidRenameFiles(handleFileRenames)
);
}

// this method is called when your extension is deactivated
Expand Down
Loading