Skip to content

Commit 1dd5264

Browse files
committed
feat(pdk): migrate to esm
1 parent 58ba763 commit 1dd5264

29 files changed

Lines changed: 683 additions & 563 deletions

infra/pdk.config.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { defineConfig } from 'pnpm-dev-kit';
22

33
export default defineConfig({
4-
4+
55
});

infra/pdk/package.json

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
"name": "pnpm-dev-kit",
33
"description": "PDK (pnpm dev kit), an efficient pnpm workspace development and publishing tool",
44
"version": "0.0.4",
5+
"type": "module",
56
"main": "dist/index.js",
67
"module": "dist/index.mjs",
78
"types": "dist/index.d.ts",
@@ -14,7 +15,7 @@
1415
"bin"
1516
],
1617
"bin": {
17-
"pdk": "bin/cli.js"
18+
"pdk": "bin/cli.cjs"
1819
},
1920
"scripts": {
2021
"dev": "rslib build --watch",
@@ -23,17 +24,16 @@
2324
"prepublishOnly": "pnpm run build"
2425
},
2526
"dependencies": {
26-
"@tarko/config-loader": "0.3.0",
2727
"@tarko/model-provider": "0.3.0",
2828
"boxen": "4",
29-
"cac": "^6.5.10",
30-
"chalk": "2.4.1",
29+
"cac": "6.7.14",
30+
"chalk": "5.6.2",
3131
"chokidar": "3.4.0",
32-
"execa": "9.6.0",
32+
"execa": "9.6.1",
3333
"fast-glob": "^3.3.2",
34-
"fs-extra": "^11.1.1",
35-
"inquirer": "^8.2.5",
34+
"@inquirer/prompts": "8.0.2",
3635
"js-yaml": "^4.1.0",
36+
"jiti": "2.4.2",
3737
"semver": "^7.5.4",
3838
"string-width": "^4.2.0",
3939
"text-table": "^0.2.0",
@@ -42,7 +42,6 @@
4242
"devDependencies": {
4343
"@rslib/core": "0.15.1",
4444
"@types/fs-extra": "11.0.2",
45-
"@types/inquirer": "^8.2.5",
4645
"@types/js-yaml": "^4.0.5",
4746
"@types/node": "22.15.30",
4847
"@types/semver": "^7.5.0",

infra/pdk/rslib.config.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,14 @@ import { defineConfig } from '@rslib/core';
33
export default defineConfig({
44
source: {
55
entry: {
6-
index: 'src/index.ts',
6+
index: 'src/**',
77
},
88
},
99
lib: [
1010
{
11-
format: 'cjs',
11+
format: 'esm',
1212
syntax: 'es2021',
13-
bundle: true,
13+
bundle: false,
1414
autoExternal: {
1515
dependencies: false, // Enable bundling to include tiny-conventional-commits-parser
1616
optionalDependencies: true,

infra/pdk/src/cli.ts

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,10 @@
77
* CLI entry point for PDK
88
*/
99
import { cac } from 'cac';
10-
import { dev, release, patch, changelog, githubRelease } from './commands';
11-
import { logger } from './utils/logger';
12-
import { loadPDKConfig, mergeOptions } from './utils/config';
13-
import type { DevOptions, ReleaseOptions, PatchOptions, ChangelogOptions, GitHubReleaseOptions } from './types';
10+
import { dev, release, patch, changelog, githubRelease } from './commands/index.js';
11+
import { logger } from './utils/logger.js';
12+
import { loadPDKConfig, mergeOptions } from './utils/config.js';
13+
import pkg from '../package.json' with { type: 'json' };
1414

1515
/**
1616
* Wraps a command execution with error handling and config loading
@@ -27,10 +27,10 @@ async function wrapCommand(
2727
try {
2828
// Load configuration
2929
const config = await loadPDKConfig({ cwd: options.cwd as string });
30-
30+
3131
// Merge CLI options with configuration
3232
const mergedOptions = mergeOptions(options, config, commandType);
33-
33+
3434
await command(mergedOptions);
3535
} catch (err) {
3636
console.log();
@@ -45,7 +45,6 @@ async function wrapCommand(
4545
*/
4646
export function bootstrapCli() {
4747
const cli = cac('pdk');
48-
const pkg = require('../package.json');
4948

5049
// Global options
5150
cli.option('--cwd <cwd>', 'Current working directory', {

infra/pdk/src/commands/changelog.ts

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,18 +9,17 @@
99
*/
1010
import { existsSync, readFileSync, writeFileSync } from 'fs';
1111
import { join } from 'path';
12-
import { resolveWorkspaceConfig } from '../utils/workspace';
13-
import { gitCommit, gitPush } from '../utils/git';
14-
import { logger } from '../utils/logger';
12+
import { resolveWorkspaceConfig } from '../utils/workspace.js';
13+
import { gitCommit, gitPush } from '../utils/git.js';
14+
import { logger } from '../utils/logger.js';
1515
import {
1616
getPreviousTag,
1717
generateReleaseNotes,
1818
getRepositoryInfo,
19-
} from '../utils/github';
20-
import { AIChangelogGenerator } from '../utils/ai-changelog';
19+
} from '../utils/github.js';
20+
import { AIChangelogGenerator } from '../utils/ai-changelog.js';
2121
import type { ModelProviderName } from '@tarko/model-provider';
22-
23-
import type { ChangelogOptions } from '../types';
22+
import type { ChangelogOptions } from '../types.js';
2423

2524
/**
2625
* Creates or updates CHANGELOG.md

infra/pdk/src/commands/dev.ts

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,9 @@
1111
import chokidar from 'chokidar';
1212
import * as execa from 'execa';
1313
import chalk from 'chalk';
14-
import inquirer from 'inquirer';
15-
import { loadWorkspacePackages } from '../utils/workspace';
16-
import type { DevOptions, WorkspacePackage } from '../types';
14+
import { rawlist } from '@inquirer/prompts';
15+
import { loadWorkspacePackages } from '../utils/workspace.js';
16+
import type { DevOptions, WorkspacePackage } from '../types.js';
1717

1818
// Manages running build processes
1919
const processes: Record<string, ReturnType<execa.ExecaMethod>> = {};
@@ -125,17 +125,15 @@ function enableStdinFeature(
125125
return;
126126
}
127127

128-
const { packageName } = await inquirer.prompt([
128+
const packageName = await rawlist(
129129
{
130-
type: 'list',
131-
name: 'packageName',
132130
message: 'Choose a package to build:',
133131
choices: availablePackages.map((pkg) => ({
134132
name: `${pkg.name}`,
135133
value: pkg.name,
136134
})),
137135
},
138-
]);
136+
);
139137

140138
const selectedPackage = packages.find(
141139
(pkg) => pkg.name === packageName,

infra/pdk/src/commands/github-release.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,11 @@
77
* GitHub Release command implementation
88
* Creates GitHub releases independently from npm publishing
99
*/
10-
import { resolveWorkspaceConfig } from '../utils/workspace';
11-
import { createGitHubRelease } from '../utils/github';
12-
import { logger } from '../utils/logger';
10+
import { resolveWorkspaceConfig } from '../utils/workspace.js';
11+
import { createGitHubRelease } from '../utils/github.js';
12+
import { logger } from '../utils/logger.js';
1313

14-
import type { GitHubReleaseOptions } from '../types';
14+
import type { GitHubReleaseOptions } from '../types.js';
1515

1616
/**
1717
* GitHub Release command implementation

infra/pdk/src/commands/index.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33
* SPDX-License-Identifier: Apache-2.0
44
*/
55

6-
export * from './dev';
7-
export * from './release';
8-
export * from './patch';
9-
export * from './changelog';
10-
export * from './github-release';
6+
export * from './dev.js';
7+
export * from './release.js';
8+
export * from './patch.js';
9+
export * from './changelog.js';
10+
export * from './github-release.js';

infra/pdk/src/commands/patch.ts

Lines changed: 12 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -9,22 +9,22 @@
99
* Fixes failed package publishing
1010
*/
1111
import { join } from 'path';
12-
import { readFileSync, writeFileSync } from 'fs-extra';
13-
import inquirer from 'inquirer';
12+
import { readFileSync, writeFileSync } from 'fs';
13+
import { rawlist } from '@inquirer/prompts';
1414
import textTable from 'text-table';
1515
import stringWidth from 'string-width';
1616
import chalk from 'chalk';
1717

1818
import {
1919
loadWorkspacePackages,
2020
resolveWorkspaceConfig,
21-
} from '../utils/workspace';
22-
import { fetchPackageVersion } from '../utils/npm';
23-
import { logger } from '../utils/logger';
24-
import { publishPackage } from '../utils/npm';
25-
import { removeGitHeadField } from '../utils/npm';
21+
} from '../utils/workspace.js';
22+
import { fetchPackageVersion } from '../utils/npm.js';
23+
import { logger } from '../utils/logger.js';
24+
import { publishPackage } from '../utils/npm.js';
25+
import { removeGitHeadField } from '../utils/npm.js';
2626

27-
import type { PatchOptions, PackageWithRemoteInfo } from '../types';
27+
import type { PatchOptions, PackageWithRemoteInfo } from '../types.js';
2828

2929
/**
3030
* Formats the release status table
@@ -128,14 +128,10 @@ export async function patch(options: PatchOptions = {}): Promise<void> {
128128
console.log();
129129

130130
// Confirm patch operation
131-
const { confirm } = await inquirer.prompt([
132-
{
133-
name: 'confirm',
134-
message: 'Continue to patch?',
135-
type: 'list',
136-
choices: ['No', 'Yes'],
137-
},
138-
]);
131+
const confirm = await rawlist({
132+
message: 'Continue to patch?',
133+
choices: ['No', 'Yes'],
134+
});
139135

140136
if (confirm !== 'Yes') {
141137
logger.info('Patch cancelled.');

0 commit comments

Comments
 (0)