pluribuild 0.1.0 → 0.1.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +2 -0
- package/dist/index.cjs +6 -6
- package/dist/index.d.ts +8 -2
- package/dist/index.mjs +6 -6
- package/dist/run.mjs +21 -14
- package/package.json +1 -1
- package/src/BuildOptions.ts +6 -1
- package/src/build.ts +4 -5
- package/src/getDefaultEntryPoints.ts +7 -5
- package/src/run.ts +7 -2
package/README.md
CHANGED
|
@@ -6,6 +6,8 @@ Run `npx pluribuild` to build:
|
|
|
6
6
|
- `entries/<name>/src/index.ts(x)` into `dist/<name>/index.js`;
|
|
7
7
|
- `entries/<name>/x.ts(x)` into `dist/<name>/x.js` (`index` as `x` is fine, too).
|
|
8
8
|
|
|
9
|
+
Subdirectories of `entries` and entry point files whose names start with an underscore are ignored. Add `--ignore <subdir1> [<subdir2> ...]` to the command to additionally ignore the specified subdirectories of `entries`.
|
|
10
|
+
|
|
9
11
|
Run `npx pluribuild <dir>` to point to a parent directory other than `entries`.
|
|
10
12
|
|
|
11
13
|
Add `--dev` to the command to enable rebuilds on code changes. Add `--minify=off` to turn off minification.
|
package/dist/index.cjs
CHANGED
|
@@ -38,16 +38,16 @@ function toEntryPoint(toName) {
|
|
|
38
38
|
};
|
|
39
39
|
}
|
|
40
40
|
|
|
41
|
-
function getDefaultEntryPoints(dir
|
|
42
|
-
let entryPoints = new Map([...(0, node_fs.globSync)(`${dir}/[!_]*/src/index.{ts,tsx}`).map(toEntryPoint((path) => {
|
|
41
|
+
function getDefaultEntryPoints(dir, ignore) {
|
|
42
|
+
let entryPoints = new Map([...(0, node_fs.globSync)(`${dir}/[!_]*/src/index.{ts,tsx}`, { exclude: ignore?.map((subdir) => `${dir}/${subdir}/src/index.{ts,tsx}`) }).map(toEntryPoint((path) => {
|
|
43
43
|
let p = path.split(node_path.sep);
|
|
44
44
|
return `${p.at(-3)}/${p.at(-1)}`;
|
|
45
|
-
})), ...(0, node_fs.globSync)(`${dir}/[!_]*/[!_]*.{ts,tsx}`).map(toEntryPoint((path) => path.split(node_path.sep).slice(-2).join("/")))]);
|
|
45
|
+
})), ...(0, node_fs.globSync)(`${dir}/[!_]*/[!_]*.{ts,tsx}`, { exclude: ignore?.map((subdir) => `${dir}/${subdir}/[!_]*.{ts,tsx}`) }).map(toEntryPoint((path) => path.split(node_path.sep).slice(-2).join("/")))]);
|
|
46
46
|
return Array.from(entryPoints.values());
|
|
47
47
|
}
|
|
48
48
|
|
|
49
|
-
async function build({ entryPoints, dev, dir, ...options } = {}) {
|
|
50
|
-
let e = entryPoints ?? getDefaultEntryPoints(dir);
|
|
49
|
+
async function build({ entryPoints, dev, dir = "entries", ignore, ...options } = {}) {
|
|
50
|
+
let e = entryPoints ?? getDefaultEntryPoints(dir, ignore);
|
|
51
51
|
if (Object.keys(e).length === 0) {
|
|
52
52
|
console.warn("No entry points");
|
|
53
53
|
return;
|
|
@@ -69,7 +69,7 @@ async function build({ entryPoints, dev, dir, ...options } = {}) {
|
|
|
69
69
|
...options
|
|
70
70
|
};
|
|
71
71
|
if (dev) await (await esbuild.default.context(buildOptions)).watch();
|
|
72
|
-
await esbuild.default.build(buildOptions);
|
|
72
|
+
else await esbuild.default.build(buildOptions);
|
|
73
73
|
}
|
|
74
74
|
|
|
75
75
|
exports.build = build;
|
package/dist/index.d.ts
CHANGED
|
@@ -1,7 +1,12 @@
|
|
|
1
1
|
import { BuildOptions as BuildOptions$1 } from "esbuild";
|
|
2
2
|
|
|
3
3
|
type BuildOptions = BuildOptions$1 & {
|
|
4
|
-
/**
|
|
4
|
+
/**
|
|
5
|
+
* Directory containing entry points.
|
|
6
|
+
* @default "entries"
|
|
7
|
+
*/
|
|
8
|
+
dir?: string; /** List of ignored subdirectories of `dir`. */
|
|
9
|
+
ignore?: string[]; /** Development mode. Enables rebuilds on code changes. */
|
|
5
10
|
dev?: boolean;
|
|
6
11
|
};
|
|
7
12
|
|
|
@@ -9,6 +14,7 @@ declare function build({
|
|
|
9
14
|
entryPoints,
|
|
10
15
|
dev,
|
|
11
16
|
dir,
|
|
17
|
+
ignore,
|
|
12
18
|
...options
|
|
13
19
|
}?: BuildOptions): Promise<void>;
|
|
14
20
|
|
|
@@ -17,7 +23,7 @@ type EntryPoint = {
|
|
|
17
23
|
out: string;
|
|
18
24
|
};
|
|
19
25
|
|
|
20
|
-
declare function getDefaultEntryPoints(dir?: string): EntryPoint[];
|
|
26
|
+
declare function getDefaultEntryPoints(dir: string, ignore?: string[]): EntryPoint[];
|
|
21
27
|
|
|
22
28
|
declare function toEntryPoint(toName: (path: string) => string | undefined): (path: string) => [string, EntryPoint];
|
|
23
29
|
|
package/dist/index.mjs
CHANGED
|
@@ -14,16 +14,16 @@ function toEntryPoint(toName) {
|
|
|
14
14
|
};
|
|
15
15
|
}
|
|
16
16
|
|
|
17
|
-
function getDefaultEntryPoints(dir
|
|
18
|
-
let entryPoints = new Map([...globSync(`${dir}/[!_]*/src/index.{ts,tsx}`).map(toEntryPoint((path) => {
|
|
17
|
+
function getDefaultEntryPoints(dir, ignore) {
|
|
18
|
+
let entryPoints = new Map([...globSync(`${dir}/[!_]*/src/index.{ts,tsx}`, { exclude: ignore?.map((subdir) => `${dir}/${subdir}/src/index.{ts,tsx}`) }).map(toEntryPoint((path) => {
|
|
19
19
|
let p = path.split(sep);
|
|
20
20
|
return `${p.at(-3)}/${p.at(-1)}`;
|
|
21
|
-
})), ...globSync(`${dir}/[!_]*/[!_]*.{ts,tsx}`).map(toEntryPoint((path) => path.split(sep).slice(-2).join("/")))]);
|
|
21
|
+
})), ...globSync(`${dir}/[!_]*/[!_]*.{ts,tsx}`, { exclude: ignore?.map((subdir) => `${dir}/${subdir}/[!_]*.{ts,tsx}`) }).map(toEntryPoint((path) => path.split(sep).slice(-2).join("/")))]);
|
|
22
22
|
return Array.from(entryPoints.values());
|
|
23
23
|
}
|
|
24
24
|
|
|
25
|
-
async function build({ entryPoints, dev, dir, ...options } = {}) {
|
|
26
|
-
let e = entryPoints ?? getDefaultEntryPoints(dir);
|
|
25
|
+
async function build({ entryPoints, dev, dir = "entries", ignore, ...options } = {}) {
|
|
26
|
+
let e = entryPoints ?? getDefaultEntryPoints(dir, ignore);
|
|
27
27
|
if (Object.keys(e).length === 0) {
|
|
28
28
|
console.warn("No entry points");
|
|
29
29
|
return;
|
|
@@ -45,7 +45,7 @@ async function build({ entryPoints, dev, dir, ...options } = {}) {
|
|
|
45
45
|
...options
|
|
46
46
|
};
|
|
47
47
|
if (dev) await (await esbuild.context(buildOptions)).watch();
|
|
48
|
-
await esbuild.build(buildOptions);
|
|
48
|
+
else await esbuild.build(buildOptions);
|
|
49
49
|
}
|
|
50
50
|
|
|
51
51
|
export { build, getDefaultEntryPoints, toEntryPoint };
|
package/dist/run.mjs
CHANGED
|
@@ -248,10 +248,12 @@ function toEntryPoint(toName) {
|
|
|
248
248
|
}
|
|
249
249
|
|
|
250
250
|
// src/getDefaultEntryPoints.ts
|
|
251
|
-
function getDefaultEntryPoints(dir
|
|
251
|
+
function getDefaultEntryPoints(dir, ignore) {
|
|
252
252
|
let entryPoints = new Map([
|
|
253
253
|
// entries/x/src/index.ts -> dist/x/index.js
|
|
254
|
-
...globSync(`${dir}/[!_]*/src/index.{ts,tsx}
|
|
254
|
+
...globSync(`${dir}/[!_]*/src/index.{ts,tsx}`, {
|
|
255
|
+
exclude: ignore?.map((subdir) => `${dir}/${subdir}/src/index.{ts,tsx}`)
|
|
256
|
+
}).map(
|
|
255
257
|
toEntryPoint((path) => {
|
|
256
258
|
let p = path.split(sep);
|
|
257
259
|
return `${p.at(-3)}/${p.at(-1)}`;
|
|
@@ -259,9 +261,9 @@ function getDefaultEntryPoints(dir = "entries") {
|
|
|
259
261
|
),
|
|
260
262
|
// entries/x/index.ts -> dist/x/index.js (overrides entries/x/src/index.ts, if present)
|
|
261
263
|
// entries/x/y.ts -> dist/x/y.js
|
|
262
|
-
...globSync(`${dir}/[!_]*/[!_]*.{ts,tsx}
|
|
263
|
-
|
|
264
|
-
)
|
|
264
|
+
...globSync(`${dir}/[!_]*/[!_]*.{ts,tsx}`, {
|
|
265
|
+
exclude: ignore?.map((subdir) => `${dir}/${subdir}/[!_]*.{ts,tsx}`)
|
|
266
|
+
}).map(toEntryPoint((path) => path.split(sep).slice(-2).join("/")))
|
|
265
267
|
]);
|
|
266
268
|
return Array.from(entryPoints.values());
|
|
267
269
|
}
|
|
@@ -269,11 +271,12 @@ function getDefaultEntryPoints(dir = "entries") {
|
|
|
269
271
|
// src/build.ts
|
|
270
272
|
async function build({
|
|
271
273
|
entryPoints,
|
|
272
|
-
dev,
|
|
273
|
-
dir,
|
|
274
|
+
dev: dev2,
|
|
275
|
+
dir = "entries",
|
|
276
|
+
ignore,
|
|
274
277
|
...options2
|
|
275
278
|
} = {}) {
|
|
276
|
-
let e = entryPoints ?? getDefaultEntryPoints(dir);
|
|
279
|
+
let e = entryPoints ?? getDefaultEntryPoints(dir, ignore);
|
|
277
280
|
if (Object.keys(e).length === 0) {
|
|
278
281
|
console.warn("No entry points");
|
|
279
282
|
return;
|
|
@@ -294,22 +297,26 @@ async function build({
|
|
|
294
297
|
minify: true,
|
|
295
298
|
...options2
|
|
296
299
|
};
|
|
297
|
-
if (
|
|
300
|
+
if (dev2) {
|
|
298
301
|
let ctx = await esbuild.context(buildOptions);
|
|
299
302
|
await ctx.watch();
|
|
300
|
-
}
|
|
301
|
-
await esbuild.build(buildOptions);
|
|
303
|
+
} else await esbuild.build(buildOptions);
|
|
302
304
|
}
|
|
303
305
|
|
|
304
306
|
// src/run.ts
|
|
305
307
|
var args = new import_args_json.Args();
|
|
308
|
+
var dev = args.hasKey("--dev");
|
|
306
309
|
var options = {
|
|
307
|
-
dev
|
|
308
|
-
minify: !args.isExplicitlyOff("--minify")
|
|
310
|
+
dev,
|
|
311
|
+
minify: !args.isExplicitlyOff("--minify"),
|
|
312
|
+
ignore: args.getValues("--ignore")
|
|
309
313
|
};
|
|
310
314
|
var rawArgs = process.argv.slice(2);
|
|
311
315
|
if (rawArgs.length !== 0 && !(0, import_args_json.isKey)(rawArgs[0])) options.dir = rawArgs[0];
|
|
312
316
|
for (let [k, v] of Object.entries(options)) {
|
|
313
317
|
if (v === void 0) delete options[k];
|
|
314
318
|
}
|
|
315
|
-
build(options)
|
|
319
|
+
build(options).then(() => {
|
|
320
|
+
if (dev) console.log("Initial build complete");
|
|
321
|
+
else console.log("Build complete");
|
|
322
|
+
});
|
package/package.json
CHANGED
package/src/BuildOptions.ts
CHANGED
|
@@ -1,8 +1,13 @@
|
|
|
1
1
|
import type { BuildOptions as EsbuildOptions } from "esbuild";
|
|
2
2
|
|
|
3
3
|
export type BuildOptions = EsbuildOptions & {
|
|
4
|
-
/**
|
|
4
|
+
/**
|
|
5
|
+
* Directory containing entry points.
|
|
6
|
+
* @default "entries"
|
|
7
|
+
*/
|
|
5
8
|
dir?: string;
|
|
9
|
+
/** List of ignored subdirectories of `dir`. */
|
|
10
|
+
ignore?: string[];
|
|
6
11
|
/** Development mode. Enables rebuilds on code changes. */
|
|
7
12
|
dev?: boolean;
|
|
8
13
|
};
|
package/src/build.ts
CHANGED
|
@@ -5,10 +5,11 @@ import { getDefaultEntryPoints } from "./getDefaultEntryPoints.ts";
|
|
|
5
5
|
export async function build({
|
|
6
6
|
entryPoints,
|
|
7
7
|
dev,
|
|
8
|
-
dir,
|
|
8
|
+
dir = "entries",
|
|
9
|
+
ignore,
|
|
9
10
|
...options
|
|
10
11
|
}: BuildOptions = {}) {
|
|
11
|
-
let e = entryPoints ?? getDefaultEntryPoints(dir);
|
|
12
|
+
let e = entryPoints ?? getDefaultEntryPoints(dir, ignore);
|
|
12
13
|
|
|
13
14
|
if (Object.keys(e).length === 0) {
|
|
14
15
|
console.warn("No entry points");
|
|
@@ -35,7 +36,5 @@ export async function build({
|
|
|
35
36
|
if (dev) {
|
|
36
37
|
let ctx = await esbuild.context(buildOptions);
|
|
37
38
|
await ctx.watch();
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
await esbuild.build(buildOptions);
|
|
39
|
+
} else await esbuild.build(buildOptions);
|
|
41
40
|
}
|
|
@@ -2,10 +2,12 @@ import { globSync } from "node:fs";
|
|
|
2
2
|
import { sep } from "node:path";
|
|
3
3
|
import { toEntryPoint } from "./toEntryPoint.ts";
|
|
4
4
|
|
|
5
|
-
export function getDefaultEntryPoints(dir
|
|
5
|
+
export function getDefaultEntryPoints(dir: string, ignore?: string[]) {
|
|
6
6
|
let entryPoints = new Map([
|
|
7
7
|
// entries/x/src/index.ts -> dist/x/index.js
|
|
8
|
-
...globSync(`${dir}/[!_]*/src/index.{ts,tsx}
|
|
8
|
+
...globSync(`${dir}/[!_]*/src/index.{ts,tsx}`, {
|
|
9
|
+
exclude: ignore?.map((subdir) => `${dir}/${subdir}/src/index.{ts,tsx}`),
|
|
10
|
+
}).map(
|
|
9
11
|
toEntryPoint((path) => {
|
|
10
12
|
let p = path.split(sep);
|
|
11
13
|
return `${p.at(-3)}/${p.at(-1)}`;
|
|
@@ -13,9 +15,9 @@ export function getDefaultEntryPoints(dir = "entries") {
|
|
|
13
15
|
),
|
|
14
16
|
// entries/x/index.ts -> dist/x/index.js (overrides entries/x/src/index.ts, if present)
|
|
15
17
|
// entries/x/y.ts -> dist/x/y.js
|
|
16
|
-
...globSync(`${dir}/[!_]*/[!_]*.{ts,tsx}
|
|
17
|
-
|
|
18
|
-
),
|
|
18
|
+
...globSync(`${dir}/[!_]*/[!_]*.{ts,tsx}`, {
|
|
19
|
+
exclude: ignore?.map((subdir) => `${dir}/${subdir}/[!_]*.{ts,tsx}`),
|
|
20
|
+
}).map(toEntryPoint((path) => path.split(sep).slice(-2).join("/"))),
|
|
19
21
|
]);
|
|
20
22
|
|
|
21
23
|
return Array.from(entryPoints.values());
|
package/src/run.ts
CHANGED
|
@@ -4,10 +4,12 @@ import type { BuildOptions } from "./BuildOptions.ts";
|
|
|
4
4
|
import { build } from "./build.ts";
|
|
5
5
|
|
|
6
6
|
let args = new Args();
|
|
7
|
+
let dev = args.hasKey("--dev");
|
|
7
8
|
|
|
8
9
|
let options: BuildOptions = {
|
|
9
|
-
dev
|
|
10
|
+
dev,
|
|
10
11
|
minify: !args.isExplicitlyOff("--minify"),
|
|
12
|
+
ignore: args.getValues("--ignore"),
|
|
11
13
|
};
|
|
12
14
|
|
|
13
15
|
let rawArgs = process.argv.slice(2);
|
|
@@ -17,4 +19,7 @@ for (let [k, v] of Object.entries(options)) {
|
|
|
17
19
|
if (v === undefined) delete options[k as keyof BuildOptions];
|
|
18
20
|
}
|
|
19
21
|
|
|
20
|
-
build(options)
|
|
22
|
+
build(options).then(() => {
|
|
23
|
+
if (dev) console.log("Initial build complete");
|
|
24
|
+
else console.log("Build complete");
|
|
25
|
+
});
|