Skip to content

Commit

Permalink
feat: Add rootDir option to PkgToJsrConfig
Browse files Browse the repository at this point in the history
This commit introduces a new option 'rootDir' to the PkgToJsrConfig. This
allows users to specify the root directory for the package.json resolution.
If not provided, it defaults to the workspace directory. The changes also
include updates to the 'bin.ts' file to accommodate this new option.
  • Loading branch information
ryoppippi committed Aug 7, 2024
1 parent d3255d1 commit 4c6d335
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 6 deletions.
14 changes: 8 additions & 6 deletions src/bin.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,19 @@
import fs from 'node:fs/promises';
import { dirname, resolve } from 'pathe';
import { readPackageJSON, resolvePackageJSON } from 'pkg-types';
import { resolve } from 'pathe';
import { findWorkspaceDir, readPackageJSON, resolvePackageJSON } from 'pkg-types';
import { consola } from 'consola';
import { genJsrFromPkg } from './utils';
import { loadConfig } from './config';

const pkgJSONPath = await resolvePackageJSON();
const options = await loadConfig();

const { rootDir: _rootDir } = options;
const rootDir = _rootDir ?? await findWorkspaceDir();

const pkgJSONPath = await resolvePackageJSON(rootDir);
const pkgJSON = await readPackageJSON(pkgJSONPath);
const rootDir = dirname(pkgJSONPath);
const jsrPath = resolve(rootDir, 'jsr.json');

const options = await loadConfig();

const jsr = genJsrFromPkg({ pkgJSON, options });

await fs.writeFile(jsrPath, JSON.stringify(jsr, null, '\t'));
Expand Down
20 changes: 20 additions & 0 deletions src/type.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,26 @@ export type JSR = {
exports: Exports;
};

/**
* The configuration object
*/
export type PkgToJsrConfig = {
/**
* The exports object
*
* @example
* ```typescript
* {
* ".": "./src/index.ts",
* "./lib": "./src/lib.ts",
* }
* ```
*/
exports: Exports;

/**
* The root directory
* @default "."
*/
rootDir?: string;
};

0 comments on commit 4c6d335

Please sign in to comment.