modular-library 0.0.2 → 0.0.4

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 CHANGED
@@ -163,6 +163,29 @@ To make your package consumable with subpath imports, add an `exports` map in yo
163
163
  }
164
164
  ```
165
165
 
166
+ ## CLI
167
+
168
+ You can also use `modular-library` as a CLI with `npx`.
169
+
170
+ ### Check exports
171
+
172
+ Validate that all `package.json` export targets exist and are inside your output directory:
173
+
174
+ ```bash
175
+ npx modular-library check
176
+ ```
177
+
178
+ Named options:
179
+
180
+ - `--package-json` path to package manifest (default: `./package.json`)
181
+ - `--out-dir` output directory to validate against (default: `./dist`)
182
+
183
+ Example:
184
+
185
+ ```bash
186
+ npx modular-library check --package-json ./package.json --out-dir ./dist
187
+ ```
188
+
166
189
  ## Development
167
190
 
168
191
  ```bash
@@ -0,0 +1 @@
1
+ var e=Object.create,t=Object.defineProperty,n=Object.getOwnPropertyDescriptor,r=Object.getOwnPropertyNames,i=Object.getPrototypeOf,a=Object.prototype.hasOwnProperty,o=(e,i,o,s)=>{if(i&&typeof i==`object`||typeof i==`function`)for(var c=r(i),l=0,u=c.length,d;l<u;l++)d=c[l],!a.call(e,d)&&d!==o&&t(e,d,{get:(e=>i[e]).bind(null,d),enumerable:!(s=n(i,d))||s.enumerable});return e},s=(n,r,a)=>(a=n==null?{}:e(i(n)),o(r||!n||!n.__esModule?t(a,`default`,{value:n,enumerable:!0}):a,n));Object.defineProperty(exports,`t`,{enumerable:!0,get:function(){return s}});
@@ -1 +1 @@
1
- var e=Object.create,t=Object.defineProperty,n=Object.getOwnPropertyDescriptor,r=Object.getOwnPropertyNames,i=Object.getPrototypeOf,a=Object.prototype.hasOwnProperty,o=(e,i,o,s)=>{if(i&&typeof i==`object`||typeof i==`function`)for(var c=r(i),l=0,u=c.length,d;l<u;l++)d=c[l],!a.call(e,d)&&d!==o&&t(e,d,{get:(e=>i[e]).bind(null,d),enumerable:!(s=n(i,d))||s.enumerable});return e},s=(n,r,a)=>(a=n==null?{}:e(i(n)),o(r||!n||!n.__esModule?t(a,`default`,{value:n,enumerable:!0}):a,n));let c=require(`node:fs`),l=require(`node:path`);l=s(l);var u=e=>typeof e==`string`,d=e=>e.replace(/\.[^/.]+$/,``).replace(/\\/g,`/`),f={relative:`src/`},p=(e,t)=>{let n=[e].flat(),r=n.filter(e=>u(e)),i=n.filter(e=>!u(e)),a=(0,c.globSync)(r.map(e=>e.replace(/\\/g,`/`)),{...t?.glob,withFileTypes:!1}).map(e=>{let n=l.default.relative(t?.relative??f.relative,e),r=n.startsWith(`../`)?l.default.relative(`./`,e):n;return[d(t?.transformOutputPath?t.transformOutputPath(r,e):r),e]});return Object.assign({},Object.fromEntries(a),...i)};Object.defineProperty(exports,`t`,{enumerable:!0,get:function(){return p}});
1
+ const e=require(`./chunk.js`);let t=require(`node:path`);t=e.t(t);let n=require(`node:fs`);var r=e=>typeof e==`string`,i=e=>e.replace(/\.[^/.]+$/,``).replace(/\\/g,`/`),a={relative:`src/`},o=(e,o)=>{let s=[e].flat(),c=s.filter(e=>r(e)),l=s.filter(e=>!r(e)),u=(0,n.globSync)(c.map(e=>e.replace(/\\/g,`/`)),{...o?.glob,withFileTypes:!0}).filter(e=>e.isFile()).map(e=>{let n=t.default.join(e.parentPath,e.name),r=t.default.relative(o?.relative??a.relative,n),s=r.startsWith(`../`)?t.default.relative(`./`,n):r;return[i(o?.transformOutputPath?o.transformOutputPath(s,n):s),n]});return Object.assign({},Object.fromEntries(u),...l)};Object.defineProperty(exports,`t`,{enumerable:!0,get:function(){return o}});
@@ -0,0 +1,16 @@
1
+ export type ExportValidationIssue = {
2
+ exportPath: string;
3
+ condition: string | null;
4
+ target: string;
5
+ resolvedTarget: string;
6
+ reason: "invalid-target" | "outside-out-dir" | "file-not-found";
7
+ };
8
+ export type ValidateExportsInput = {
9
+ packageJsonPath: string;
10
+ outDir: string;
11
+ };
12
+ export declare const validatePackageExports: ({ packageJsonPath, outDir, }: ValidateExportsInput) => {
13
+ valid: boolean;
14
+ issues: ExportValidationIssue[];
15
+ checked: number;
16
+ };
@@ -0,0 +1,2 @@
1
+ #!/usr/bin/env node
2
+ Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});const e=require(`./chunks/chunk.js`);let t=require(`node:path`);t=e.t(t);let n=require(`commander`),r=require(`node:fs`);var i=e=>typeof e==`object`&&!!e&&!Array.isArray(e),a=(e,t,n=[])=>typeof e==`string`?[{exportPath:t,condition:n.length>0?n.join(`.`):null,target:e}]:Object.entries(e).flatMap(([e,r])=>typeof r==`string`||i(r)?a(r,t,[...n,e]):[]),o=e=>e&&(typeof e==`string`||i(e))?typeof e==`string`||Object.values(e).every(e=>typeof e==`string`||i(e))&&Object.keys(e).every(e=>!e.startsWith(`.`))?a(e,`.`):Object.entries(e).flatMap(([e,t])=>typeof t==`string`||i(t)?a(t,e):[]):[],s=({packageJsonPath:e,outDir:n})=>{let i=(0,r.readFileSync)(e,`utf8`),a=JSON.parse(i),s=t.default.dirname(e),c=t.default.resolve(n),l=o(a.exports),u=[];return l.forEach(e=>{if(!e.target.startsWith(`./`)){u.push({...e,resolvedTarget:e.target,reason:`invalid-target`});return}let n=t.default.resolve(s,e.target),i=t.default.relative(c,n);if(i.startsWith(`..`)||t.default.isAbsolute(i)){u.push({...e,resolvedTarget:n,reason:`outside-out-dir`});return}(0,r.existsSync)(n)||u.push({...e,resolvedTarget:n,reason:`file-not-found`})}),{valid:u.length===0,issues:u,checked:l.length}},c=(e,t)=>{let n=t.condition?` (${t.condition})`:``;e.write(`- ${t.exportPath}${n}: ${t.target} -> ${t.reason} (${t.resolvedTarget})\n`)},l=({stdout:e,stderr:r,cwd:i})=>{let a=new n.Command;return a.name(`modular-library`).description(`CLI for modular-library`).showHelpAfterError().configureOutput({writeOut:t=>{e.write(t)},writeErr:e=>{r.write(e)}}).exitOverride(),a.command(`check`).description(`Validate that package.json exports exist inside out-dir`).option(`--package-json <path>`,`Path to package.json`,`./package.json`).option(`--out-dir <path>`,`Output directory to validate against`,`./dist`).action(a=>{let o=t.default.resolve(i,a.packageJson),l=t.default.resolve(i,a.outDir),u=s({packageJsonPath:o,outDir:l});if(u.valid){e.write(`All exports are valid. Checked ${u.checked} export target(s) in ${l}.\n`);return}throw r.write(`Found ${u.issues.length} invalid export target(s) out of ${u.checked}:\n`),u.issues.forEach(e=>{c(r,e)}),new n.CommanderError(1,`check.invalidExports`,``)}),a},u=(e,{stdout:t=process.stdout,stderr:r=process.stderr,cwd:i=process.cwd()}={})=>{let a=l({stdout:t,stderr:r,cwd:i});try{return e.length===0?(a.outputHelp(),0):(a.parse(e,{from:`user`}),0)}catch(e){if(e instanceof n.CommanderError)return e.code===`check.invalidExports`?1:e.exitCode;let t=e instanceof Error?e.message:String(e);return r.write(`${t}\n`),1}},d=async()=>{process.exitCode=u(process.argv.slice(2))};typeof require<`u`&&require.main===module&&d(),exports.main=d,exports.runCli=u;
package/dist/cli.d.ts ADDED
@@ -0,0 +1,11 @@
1
+ #!/usr/bin/env node
2
+ type StdoutLike = Pick<typeof process.stdout, "write">;
3
+ type StderrLike = Pick<typeof process.stderr, "write">;
4
+ type RunCliOptions = {
5
+ stdout?: StdoutLike;
6
+ stderr?: StderrLike;
7
+ cwd?: string;
8
+ };
9
+ export declare const runCli: (argv: string[], { stdout, stderr, cwd, }?: RunCliOptions) => number;
10
+ export declare const main: () => Promise<void>;
11
+ export {};
package/dist/cli.es.js ADDED
@@ -0,0 +1,86 @@
1
+ #!/usr/bin/env node
2
+ import e from "node:path";
3
+ import { Command as t, CommanderError as n } from "commander";
4
+ import { existsSync as r, readFileSync as i } from "node:fs";
5
+ //#region \0rolldown/runtime.js
6
+ var a = /* @__PURE__ */ ((e) => typeof require < "u" ? require : typeof Proxy < "u" ? new Proxy(e, { get: (e, t) => (typeof require < "u" ? require : e)[t] }) : e)(function(e) {
7
+ if (typeof require < "u") return require.apply(this, arguments);
8
+ throw Error("Calling `require` for \"" + e + "\" in an environment that doesn't expose the `require` function. See https://rolldown.rs/in-depth/bundling-cjs#require-external-modules for more details.");
9
+ }), o = (e) => typeof e == "object" && !!e && !Array.isArray(e), s = (e, t, n = []) => typeof e == "string" ? [{
10
+ exportPath: t,
11
+ condition: n.length > 0 ? n.join(".") : null,
12
+ target: e
13
+ }] : Object.entries(e).flatMap(([e, r]) => typeof r == "string" || o(r) ? s(r, t, [...n, e]) : []), c = (e) => e && (typeof e == "string" || o(e)) ? typeof e == "string" || Object.values(e).every((e) => typeof e == "string" || o(e)) && Object.keys(e).every((e) => !e.startsWith(".")) ? s(e, ".") : Object.entries(e).flatMap(([e, t]) => typeof t == "string" || o(t) ? s(t, e) : []) : [], l = ({ packageJsonPath: t, outDir: n }) => {
14
+ let a = i(t, "utf8"), o = JSON.parse(a), s = e.dirname(t), l = e.resolve(n), u = c(o.exports), d = [];
15
+ return u.forEach((t) => {
16
+ if (!t.target.startsWith("./")) {
17
+ d.push({
18
+ ...t,
19
+ resolvedTarget: t.target,
20
+ reason: "invalid-target"
21
+ });
22
+ return;
23
+ }
24
+ let n = e.resolve(s, t.target), i = e.relative(l, n);
25
+ if (i.startsWith("..") || e.isAbsolute(i)) {
26
+ d.push({
27
+ ...t,
28
+ resolvedTarget: n,
29
+ reason: "outside-out-dir"
30
+ });
31
+ return;
32
+ }
33
+ r(n) || d.push({
34
+ ...t,
35
+ resolvedTarget: n,
36
+ reason: "file-not-found"
37
+ });
38
+ }), {
39
+ valid: d.length === 0,
40
+ issues: d,
41
+ checked: u.length
42
+ };
43
+ }, u = (e, t) => {
44
+ let n = t.condition ? ` (${t.condition})` : "";
45
+ e.write(`- ${t.exportPath}${n}: ${t.target} -> ${t.reason} (${t.resolvedTarget})\n`);
46
+ }, d = ({ stdout: r, stderr: i, cwd: a }) => {
47
+ let o = new t();
48
+ return o.name("modular-library").description("CLI for modular-library").showHelpAfterError().configureOutput({
49
+ writeOut: (e) => {
50
+ r.write(e);
51
+ },
52
+ writeErr: (e) => {
53
+ i.write(e);
54
+ }
55
+ }).exitOverride(), o.command("check").description("Validate that package.json exports exist inside out-dir").option("--package-json <path>", "Path to package.json", "./package.json").option("--out-dir <path>", "Output directory to validate against", "./dist").action((t) => {
56
+ let o = e.resolve(a, t.packageJson), s = e.resolve(a, t.outDir), c = l({
57
+ packageJsonPath: o,
58
+ outDir: s
59
+ });
60
+ if (c.valid) {
61
+ r.write(`All exports are valid. Checked ${c.checked} export target(s) in ${s}.\n`);
62
+ return;
63
+ }
64
+ throw i.write(`Found ${c.issues.length} invalid export target(s) out of ${c.checked}:\n`), c.issues.forEach((e) => {
65
+ u(i, e);
66
+ }), new n(1, "check.invalidExports", "");
67
+ }), o;
68
+ }, f = (e, { stdout: t = process.stdout, stderr: r = process.stderr, cwd: i = process.cwd() } = {}) => {
69
+ let a = d({
70
+ stdout: t,
71
+ stderr: r,
72
+ cwd: i
73
+ });
74
+ try {
75
+ return e.length === 0 ? (a.outputHelp(), 0) : (a.parse(e, { from: "user" }), 0);
76
+ } catch (e) {
77
+ if (e instanceof n) return e.code === "check.invalidExports" ? 1 : e.exitCode;
78
+ let t = e instanceof Error ? e.message : String(e);
79
+ return r.write(`${t}\n`), 1;
80
+ }
81
+ }, p = async () => {
82
+ process.exitCode = f(process.argv.slice(2));
83
+ };
84
+ a !== void 0 && a.main === module && p();
85
+ //#endregion
86
+ export { p as main, f as runCli };
@@ -1,6 +1,6 @@
1
- import { GlobOptionsWithoutFileTypes } from 'node:fs';
1
+ import { GlobOptions } from 'node:fs';
2
2
  export type CreateEntryInput = string | string[] | Record<string, string>;
3
- type CreateEntriesGlobOptions = GlobOptionsWithoutFileTypes;
3
+ type CreateEntriesGlobOptions = GlobOptions;
4
4
  export type CreateEntriesOptions = {
5
5
  glob?: CreateEntriesGlobOptions;
6
6
  relative?: string;
package/package.json CHANGED
@@ -1,7 +1,10 @@
1
1
  {
2
2
  "name": "modular-library",
3
- "version": "0.0.2",
3
+ "version": "0.0.4",
4
4
  "private": false,
5
+ "bin": {
6
+ "modular-library": "./dist/cli.cjs.js"
7
+ },
5
8
  "files": [
6
9
  "dist"
7
10
  ],
@@ -53,6 +56,9 @@
53
56
  },
54
57
  "homepage": "https://github.com/alfredosalzillo/modular-library#readme",
55
58
  "description": "Plugins for Vite, Rollup, and Rolldown to build modular multi-entry TypeScript libraries.",
59
+ "dependencies": {
60
+ "commander": "^14.0.1"
61
+ },
56
62
  "devDependencies": {
57
63
  "@biomejs/biome": "^2.4.11",
58
64
  "@rollup/plugin-json": "^6.1.0",