Skip to content

Commit 8562b0b

Browse files
fix: cjs support
1 parent a253ba7 commit 8562b0b

File tree

3 files changed

+46
-28
lines changed

3 files changed

+46
-28
lines changed

scripts/release.js

+28-28
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,32 @@
1-
import fs from 'fs';
2-
import path from 'path';
3-
import chalk from 'chalk';
4-
import semver from 'semver';
5-
import { execa } from 'execa';
6-
import { cwd } from 'process';
7-
import enquirer from 'enquirer';
1+
'use strict';
82

9-
const { prompt } = enquirer;
10-
const currentVersion = JSON.parse(fs.readFileSync(path.resolve(cwd(), 'package.json'), 'utf-8')).version;
11-
const versionIncrements = ['patch', 'minor', 'major'];
3+
const fs = require('fs');
4+
const path = require('path');
5+
const semver = require('semver');
6+
const { cwd } = require('process');
7+
const enquirer = require('enquirer');
128

13-
const inc = (i) => semver.inc(currentVersion, i);
14-
const run = async (bin, args, opts = {}) => {
15-
try {
16-
await execa(bin, args, { stdio: 'inherit', ...opts });
17-
} catch (err) {
18-
console.error(chalk.red(`Error running command: ${bin} ${args.join(' ')}`));
19-
console.error(err.message);
20-
process.exit(1);
21-
}
22-
};
23-
const step = (msg) => console.log(chalk.cyan(msg));
9+
const { prompt } = enquirer;
2410

2511
async function main() {
12+
const chalk = (await import('chalk')).default; // Importação dinâmica para ESM
13+
const { execa } = await import('execa'); // Importação dinâmica para ESM
14+
15+
const currentVersion = JSON.parse(fs.readFileSync(path.resolve(cwd(), 'package.json'), 'utf-8')).version;
16+
const versionIncrements = ['patch', 'minor', 'major'];
17+
18+
const inc = (i) => semver.inc(currentVersion, i);
19+
const run = async (bin, args, opts = {}) => {
20+
try {
21+
await execa(bin, args, { stdio: 'inherit', ...opts });
22+
} catch (err) {
23+
console.error(chalk.red(`Error running command: ${bin} ${args.join(' ')}`));
24+
console.error(err.message);
25+
process.exit(1);
26+
}
27+
};
28+
const step = (msg) => console.log(chalk.cyan(msg));
29+
2630
let targetVersion;
2731

2832
try {
@@ -89,11 +93,7 @@ async function main() {
8993

9094
// Publish the package
9195
step('\nPublishing the package...');
92-
await run('npm', [
93-
'publish',
94-
'--access',
95-
'public',
96-
]);
96+
await run('pnpm', ['publish', '--access', 'public']);
9797

9898
// Push changes to GitHub
9999
step('\nPushing to GitHub...');
@@ -115,11 +115,11 @@ function updatePackage(version) {
115115
pkg.version = version;
116116

117117
fs.writeFileSync(pkgPath, JSON.stringify(pkg, null, 4) + '\n');
118-
step(`Updated package.json version to ${version}`);
118+
console.log(`Updated package.json version to ${version}`);
119119
}
120120

121121
main().catch((err) => {
122-
console.error(chalk.red(`\nUnexpected error:`));
122+
console.error(`\nUnexpected error:`);
123123
console.error(err.message);
124124
process.exit(1);
125125
});

tsconfig.cjs.json

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{
2+
"extends": "./tsconfig.json",
3+
"compilerOptions": {
4+
"module": "commonjs",
5+
"outDir": "./dist/cjs",
6+
"declaration": true,
7+
"declarationDir": "./dist/types"
8+
}
9+
}

tsconfig.esm.json

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{
2+
"extends": "./tsconfig.json",
3+
"compilerOptions": {
4+
"module": "esnext",
5+
"outDir": "./dist/esm",
6+
"declaration": true,
7+
"declarationDir": "./dist/types"
8+
}
9+
}

0 commit comments

Comments
 (0)