Skip to content

Commit

Permalink
feat: support nested subpaths (#280)
Browse files Browse the repository at this point in the history
  • Loading branch information
pi0 authored Jul 18, 2023
1 parent 075b7ad commit e250f55
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 6 deletions.
10 changes: 8 additions & 2 deletions src/build.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import Module from "node:module";
import { promises as fsp } from "node:fs";
import { resolve, relative, basename } from "pathe";
import { resolve, relative, isAbsolute, normalize } from "pathe";
import type { PackageJson } from "pkg-types";
import chalk from "chalk";
import { consola } from "consola";
Expand Down Expand Up @@ -147,7 +147,13 @@ async function _build(

for (const entry of options.entries) {
if (typeof entry.name !== "string") {
entry.name = removeExtension(basename(entry.input));
let relativeInput = isAbsolute(entry.input)
? relative(rootDir, entry.input)
: normalize(entry.input);
if (relativeInput.startsWith("./")) {
relativeInput = relativeInput.slice(2);
}
entry.name = removeExtension(relativeInput.replace(/^src\//, ""));
}

if (!entry.input) {
Expand Down
8 changes: 5 additions & 3 deletions test/fixture/build.config.ts
Original file line number Diff line number Diff line change
@@ -1,20 +1,22 @@
import { defineBuildConfig } from "../../src";

export default defineBuildConfig([
// Auto preset
{},
// Custom preset
{
preset: "./build.preset",
rollup: {
emitCJS: true,
},
entries: [
"./src/index.ts",
"./src/nested/subpath.ts",
{ input: "src/runtime/", outDir: "dist/runtime" },
{ input: "src/schema", builder: "untyped" },
],
},
/**
* On top of that we run another build with a different config.
*/
// Minified
{
name: "minified",
entries: ["src/index"],
Expand Down
3 changes: 2 additions & 1 deletion test/fixture/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
"name": "fixture",
"private": "true",
"exports": {
".": "./dist/index.mjs"
".": "./dist/index.mjs",
"./nested/subpath": "./dist/nested/subpath.mjs"
}
}
1 change: 1 addition & 0 deletions test/fixture/src/nested/subpath.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export default "nested/subpath";

0 comments on commit e250f55

Please sign in to comment.