Skip to content

Commit

Permalink
Fix packages mode outside cwd
Browse files Browse the repository at this point in the history
Resolves #2043
  • Loading branch information
Gerrit0 committed Sep 1, 2022
1 parent c265735 commit eb65e65
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 8 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
@@ -1,5 +1,9 @@
# Unreleased

### Bug Fixes

- Fixed packages mode for packages outside of cwd (again), #2043.

## v0.23.12 (2022-08-31)

### Features
Expand Down
12 changes: 6 additions & 6 deletions package-lock.json

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

2 changes: 1 addition & 1 deletion package.json
Expand Up @@ -40,7 +40,7 @@
"@types/node": "14",
"@typescript-eslint/eslint-plugin": "^5.36.1",
"@typescript-eslint/parser": "^5.36.1",
"@typestrong/fs-fixture-builder": "github:TypeStrong/fs-fixture-builder#b88cd06fe814614a0d924af9d10d04ff95a551de",
"@typestrong/fs-fixture-builder": "github:TypeStrong/fs-fixture-builder#5a9486bc66f6e36988106685768396281f6cbc10",
"c8": "^7.12.0",
"esbuild": "^0.15.6",
"eslint": "^8.23.0",
Expand Down
3 changes: 2 additions & 1 deletion src/lib/utils/entry-point.ts
Expand Up @@ -306,7 +306,8 @@ function deriveRootDir(packageGlobPaths: string[]): string {
const rootPaths = globs.flatMap((glob) =>
filterMap(glob.set, (set) => {
const stop = set.findIndex((part) => typeof part !== "string");
return stop === -1 ? set.join("/") : set.slice(0, stop).join("/");
const path = stop === -1 ? set : set.slice(0, stop);
return `/${path.join("/")}`;
})
);
return getCommonDirectory(rootPaths);
Expand Down
25 changes: 25 additions & 0 deletions src/test/slow/entry-point.test.ts
@@ -1,6 +1,7 @@
import { tempdirProject } from "@typestrong/fs-fixture-builder";
import { deepStrictEqual as equal, ok } from "assert";
import { join } from "path";
import { tmpdir } from "os";
import { Application, EntryPointStrategy, TSConfigReader } from "../..";

const fixture = tempdirProject();
Expand Down Expand Up @@ -86,4 +87,28 @@ describe("Entry Points", () => {
equal(entryPoints.length, 1);
equal(entryPoints[0].version, void 0);
});

it("Supports resolving packages outside of cwd", () => {
const fixture = tempdirProject({ rootDir: tmpdir() });
fixture.addJsonFile("tsconfig.json", {
include: ["."],
});
fixture.addJsonFile("package.json", {
main: "index.ts",
});
fixture.addFile("index.ts", "export function fromIndex() {}");
fixture.write();

app.bootstrap({
tsconfig: tsconfig,
entryPoints: [fixture.cwd],
entryPointStrategy: EntryPointStrategy.Packages,
});

const entryPoints = app.getEntryPoints();
fixture.rm();
ok(entryPoints);
equal(entryPoints.length, 1);
equal(entryPoints[0].version, void 0);
});
});

0 comments on commit eb65e65

Please sign in to comment.