fix(turbo): keep package exports fresh in dev
This commit is contained in:
parent
a77826eab9
commit
2d779165cd
5 changed files with 68 additions and 3 deletions
|
|
@ -118,6 +118,12 @@ describe("workspace boundaries", () => {
|
||||||
const webTsconfig = JSON.parse(
|
const webTsconfig = JSON.parse(
|
||||||
readFileSync(join(root, "apps/web/tsconfig.json"), "utf8"),
|
readFileSync(join(root, "apps/web/tsconfig.json"), "utf8"),
|
||||||
) as { compilerOptions?: { paths?: Record<string, string[]> } };
|
) as { compilerOptions?: { paths?: Record<string, string[]> } };
|
||||||
|
const modelPackage = JSON.parse(
|
||||||
|
readFileSync(join(root, "packages/dashboard-model/package.json"), "utf8"),
|
||||||
|
) as { exports?: Record<string, WorkspacePackageExport> };
|
||||||
|
const uiPackage = JSON.parse(
|
||||||
|
readFileSync(join(root, "packages/ui/package.json"), "utf8"),
|
||||||
|
) as { exports?: Record<string, WorkspacePackageExport> };
|
||||||
const viteConfig = readFileSync(join(root, "apps/web/vite.config.ts"), "utf8");
|
const viteConfig = readFileSync(join(root, "apps/web/vite.config.ts"), "utf8");
|
||||||
const turboConfig = JSON.parse(
|
const turboConfig = JSON.parse(
|
||||||
readFileSync(join(root, "turbo.json"), "utf8"),
|
readFileSync(join(root, "turbo.json"), "utf8"),
|
||||||
|
|
@ -139,6 +145,29 @@ describe("workspace boundaries", () => {
|
||||||
expect(viteConfig).not.toContain("../../packages/dashboard-model/src");
|
expect(viteConfig).not.toContain("../../packages/dashboard-model/src");
|
||||||
expect(viteConfig).not.toContain("../../packages/ui/src");
|
expect(viteConfig).not.toContain("../../packages/ui/src");
|
||||||
expect(turboConfig.tasks?.dev?.dependsOn).toEqual(["^build"]);
|
expect(turboConfig.tasks?.dev?.dependsOn).toEqual(["^build"]);
|
||||||
|
expectPackageExport(modelPackage.exports?.["."], {
|
||||||
|
types: "./dist/index.d.ts",
|
||||||
|
development: "./src/index.ts",
|
||||||
|
default: "./dist/index.js",
|
||||||
|
});
|
||||||
|
expectPackageExport(modelPackage.exports?.["./fixtures"], {
|
||||||
|
types: "./dist/fixtures/index.d.ts",
|
||||||
|
development: "./src/fixtures/index.ts",
|
||||||
|
default: "./dist/fixtures/index.js",
|
||||||
|
});
|
||||||
|
expectPackageExport(uiPackage.exports?.["."], {
|
||||||
|
types: "./dist/index.d.ts",
|
||||||
|
development: "./src/index.ts",
|
||||||
|
default: "./dist/index.js",
|
||||||
|
});
|
||||||
|
expectPackageExport(uiPackage.exports?.["./styles.css"], {
|
||||||
|
development: "./src/styles.css",
|
||||||
|
default: "./dist/styles.css",
|
||||||
|
});
|
||||||
|
expectPackageExport(uiPackage.exports?.["./tokens.css"], {
|
||||||
|
development: "./src/tokens.css",
|
||||||
|
default: "./dist/tokens.css",
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
test("builds the internal container from a turbo-pruned web workspace", () => {
|
test("builds the internal container from a turbo-pruned web workspace", () => {
|
||||||
|
|
@ -210,3 +239,18 @@ describe("workspace boundaries", () => {
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
type WorkspacePackageExport =
|
||||||
|
| string
|
||||||
|
| {
|
||||||
|
types?: string;
|
||||||
|
development?: string;
|
||||||
|
default?: string;
|
||||||
|
};
|
||||||
|
|
||||||
|
function expectPackageExport(
|
||||||
|
actual: WorkspacePackageExport | undefined,
|
||||||
|
expected: Exclude<WorkspacePackageExport, string>,
|
||||||
|
): void {
|
||||||
|
expect(actual).toMatchObject(expected);
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -2,6 +2,7 @@ import { readFileSync } from "node:fs";
|
||||||
import { join } from "node:path";
|
import { join } from "node:path";
|
||||||
import { describe, expect, test } from "vitest";
|
import { describe, expect, test } from "vitest";
|
||||||
import { createDevServerConfig } from "../../vite.config";
|
import { createDevServerConfig } from "../../vite.config";
|
||||||
|
import { apiServerArgs } from "./dev";
|
||||||
|
|
||||||
describe("local development runtime", () => {
|
describe("local development runtime", () => {
|
||||||
test("starts the Bun API server together with the Vite dev server", () => {
|
test("starts the Bun API server together with the Vite dev server", () => {
|
||||||
|
|
@ -22,4 +23,11 @@ describe("local development runtime", () => {
|
||||||
changeOrigin: true,
|
changeOrigin: true,
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test("uses development package export conditions for the Bun API server", () => {
|
||||||
|
expect(apiServerArgs).toEqual([
|
||||||
|
"--conditions=development",
|
||||||
|
"src/server/index.ts",
|
||||||
|
]);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
|
||||||
|
|
@ -3,6 +3,10 @@ const webPort = process.env.PORT || "5173";
|
||||||
const apiHost = process.env.DASHBOARD_DEV_API_HOST || "127.0.0.1";
|
const apiHost = process.env.DASHBOARD_DEV_API_HOST || "127.0.0.1";
|
||||||
const apiPort = process.env.DASHBOARD_DEV_API_PORT || "5174";
|
const apiPort = process.env.DASHBOARD_DEV_API_PORT || "5174";
|
||||||
const apiTarget = `http://${apiHost}:${apiPort}`;
|
const apiTarget = `http://${apiHost}:${apiPort}`;
|
||||||
|
export const apiServerArgs = [
|
||||||
|
"--conditions=development",
|
||||||
|
"src/server/index.ts",
|
||||||
|
] as const;
|
||||||
|
|
||||||
if (import.meta.main) {
|
if (import.meta.main) {
|
||||||
runDevServers();
|
runDevServers();
|
||||||
|
|
@ -51,7 +55,7 @@ export function runDevServers(): void {
|
||||||
process.on("SIGINT", () => shutdown(0));
|
process.on("SIGINT", () => shutdown(0));
|
||||||
process.on("SIGTERM", () => shutdown(0));
|
process.on("SIGTERM", () => shutdown(0));
|
||||||
|
|
||||||
spawn("api server", [process.execPath, "src/server/index.ts"], {
|
spawn("api server", [process.execPath, ...apiServerArgs], {
|
||||||
HOST: apiHost,
|
HOST: apiHost,
|
||||||
PORT: apiPort,
|
PORT: apiPort,
|
||||||
});
|
});
|
||||||
|
|
|
||||||
|
|
@ -6,10 +6,12 @@
|
||||||
"exports": {
|
"exports": {
|
||||||
".": {
|
".": {
|
||||||
"types": "./dist/index.d.ts",
|
"types": "./dist/index.d.ts",
|
||||||
|
"development": "./src/index.ts",
|
||||||
"default": "./dist/index.js"
|
"default": "./dist/index.js"
|
||||||
},
|
},
|
||||||
"./fixtures": {
|
"./fixtures": {
|
||||||
"types": "./dist/fixtures/index.d.ts",
|
"types": "./dist/fixtures/index.d.ts",
|
||||||
|
"development": "./src/fixtures/index.ts",
|
||||||
"default": "./dist/fixtures/index.js"
|
"default": "./dist/fixtures/index.js"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
|
||||||
|
|
@ -7,10 +7,17 @@
|
||||||
"exports": {
|
"exports": {
|
||||||
".": {
|
".": {
|
||||||
"types": "./dist/index.d.ts",
|
"types": "./dist/index.d.ts",
|
||||||
|
"development": "./src/index.ts",
|
||||||
"default": "./dist/index.js"
|
"default": "./dist/index.js"
|
||||||
},
|
},
|
||||||
"./styles.css": "./dist/styles.css",
|
"./styles.css": {
|
||||||
"./tokens.css": "./dist/tokens.css"
|
"development": "./src/styles.css",
|
||||||
|
"default": "./dist/styles.css"
|
||||||
|
},
|
||||||
|
"./tokens.css": {
|
||||||
|
"development": "./src/tokens.css",
|
||||||
|
"default": "./dist/tokens.css"
|
||||||
|
}
|
||||||
},
|
},
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"build": "rm -rf dist && tsc -p tsconfig.build.json && mkdir -p dist/components && cp src/styles.css dist/styles.css && cp src/tokens.css dist/tokens.css && cp src/components/styles.css dist/components/styles.css",
|
"build": "rm -rf dist && tsc -p tsconfig.build.json && mkdir -p dist/components && cp src/styles.css dist/styles.css && cp src/tokens.css dist/tokens.css && cp src/components/styles.css dist/components/styles.css",
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue