|
|
@@ -1,5 +1,5 @@
|
|
|
import { beforeEach, describe, expect, it, vi } from "vitest";
|
|
|
-import { dirname, resolve } from "node:path";
|
|
|
+import { dirname, join, resolve } from "node:path";
|
|
|
import { fileURLToPath } from "node:url";
|
|
|
|
|
|
const accessMock = vi.fn();
|
|
|
@@ -16,12 +16,31 @@ describe("studio runtime resolution", () => {
|
|
|
vi.resetModules();
|
|
|
});
|
|
|
|
|
|
+ const tsSourceEntry = join("/repo", "packages", "studio", "src", "api", "index.ts");
|
|
|
+ const tsxLoader = join("/repo", "packages", "studio", "node_modules", "tsx", "dist", "loader.mjs");
|
|
|
+ const projectBuiltEntry = join(
|
|
|
+ "/repo",
|
|
|
+ "test-project",
|
|
|
+ "node_modules",
|
|
|
+ "@actalk",
|
|
|
+ "inkos-studio",
|
|
|
+ "dist",
|
|
|
+ "api",
|
|
|
+ "index.js",
|
|
|
+ );
|
|
|
+ const cliBuiltEntry = join(
|
|
|
+ cliPackageRoot,
|
|
|
+ "node_modules",
|
|
|
+ "@actalk",
|
|
|
+ "inkos-studio",
|
|
|
+ "dist",
|
|
|
+ "api",
|
|
|
+ "index.js",
|
|
|
+ );
|
|
|
+
|
|
|
it("prefers the repository-local tsx loader for monorepo sources", async () => {
|
|
|
accessMock.mockImplementation(async (path: string) => {
|
|
|
- if (
|
|
|
- path === "/repo/packages/studio/src/api/index.ts" ||
|
|
|
- path === "/repo/packages/studio/node_modules/tsx/dist/loader.mjs"
|
|
|
- ) {
|
|
|
+ if (path === tsSourceEntry || path === tsxLoader) {
|
|
|
return;
|
|
|
}
|
|
|
throw new Error(`missing: ${path}`);
|
|
|
@@ -31,20 +50,15 @@ describe("studio runtime resolution", () => {
|
|
|
const launch = await resolveStudioLaunch("/repo/test-project");
|
|
|
|
|
|
expect(launch).toEqual({
|
|
|
- studioEntry: "/repo/packages/studio/src/api/index.ts",
|
|
|
+ studioEntry: tsSourceEntry,
|
|
|
command: "node",
|
|
|
- args: [
|
|
|
- "--import",
|
|
|
- "/repo/packages/studio/node_modules/tsx/dist/loader.mjs",
|
|
|
- "/repo/packages/studio/src/api/index.ts",
|
|
|
- "/repo/test-project",
|
|
|
- ],
|
|
|
+ args: ["--import", tsxLoader, tsSourceEntry, "/repo/test-project"],
|
|
|
});
|
|
|
});
|
|
|
|
|
|
it("finds monorepo packages/studio sources from a project directory", async () => {
|
|
|
accessMock.mockImplementation(async (path: string) => {
|
|
|
- if (path === "/repo/packages/studio/src/api/index.ts") {
|
|
|
+ if (path === tsSourceEntry) {
|
|
|
return;
|
|
|
}
|
|
|
throw new Error(`missing: ${path}`);
|
|
|
@@ -54,15 +68,15 @@ describe("studio runtime resolution", () => {
|
|
|
const launch = await resolveStudioLaunch("/repo/test-project");
|
|
|
|
|
|
expect(launch).toEqual({
|
|
|
- studioEntry: "/repo/packages/studio/src/api/index.ts",
|
|
|
+ studioEntry: tsSourceEntry,
|
|
|
command: "npx",
|
|
|
- args: ["tsx", "/repo/packages/studio/src/api/index.ts", "/repo/test-project"],
|
|
|
+ args: ["tsx", tsSourceEntry, "/repo/test-project"],
|
|
|
});
|
|
|
});
|
|
|
|
|
|
it("uses node for built JavaScript entries", async () => {
|
|
|
accessMock.mockImplementation(async (path: string) => {
|
|
|
- if (path === "/repo/test-project/node_modules/@actalk/inkos-studio/dist/api/index.js") {
|
|
|
+ if (path === projectBuiltEntry) {
|
|
|
return;
|
|
|
}
|
|
|
throw new Error(`missing: ${path}`);
|
|
|
@@ -72,15 +86,15 @@ describe("studio runtime resolution", () => {
|
|
|
const launch = await resolveStudioLaunch("/repo/test-project");
|
|
|
|
|
|
expect(launch).toEqual({
|
|
|
- studioEntry: "/repo/test-project/node_modules/@actalk/inkos-studio/dist/api/index.js",
|
|
|
+ studioEntry: projectBuiltEntry,
|
|
|
command: "node",
|
|
|
- args: ["/repo/test-project/node_modules/@actalk/inkos-studio/dist/api/index.js", "/repo/test-project"],
|
|
|
+ args: [projectBuiltEntry, "/repo/test-project"],
|
|
|
});
|
|
|
});
|
|
|
|
|
|
it("falls back to the CLI installation's bundled studio runtime", async () => {
|
|
|
accessMock.mockImplementation(async (path: string) => {
|
|
|
- if (path === `${cliPackageRoot}/node_modules/@actalk/inkos-studio/dist/api/index.js`) {
|
|
|
+ if (path === cliBuiltEntry) {
|
|
|
return;
|
|
|
}
|
|
|
throw new Error(`missing: ${path}`);
|
|
|
@@ -90,9 +104,9 @@ describe("studio runtime resolution", () => {
|
|
|
const launch = await resolveStudioLaunch("/repo/test-project");
|
|
|
|
|
|
expect(launch).toEqual({
|
|
|
- studioEntry: `${cliPackageRoot}/node_modules/@actalk/inkos-studio/dist/api/index.js`,
|
|
|
+ studioEntry: cliBuiltEntry,
|
|
|
command: "node",
|
|
|
- args: [`${cliPackageRoot}/node_modules/@actalk/inkos-studio/dist/api/index.js`, "/repo/test-project"],
|
|
|
+ args: [cliBuiltEntry, "/repo/test-project"],
|
|
|
});
|
|
|
});
|
|
|
});
|