Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 7 additions & 17 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,27 +10,17 @@
"prepublishOnly": "pnpm build"
},
"type": "module",
"types": "./dist/esm/index.d.ts",
"types": "./dist/index.d.ts",
"exports": {
"./package.json": "./package.json",
".": {
"require": {
"types": "./dist/cjs/index.d.cts",
"default": "./dist/cjs/index.js"
"types": "./dist/index.d.cts",
"default": "./dist/index.cjs"
},
"import": {
"types": "./dist/esm/index.d.ts",
"default": "./dist/esm/index.js"
}
},
"./*": {
"require": {
"types": "./dist/cjs/*.d.cts",
"default": "./dist/cjs/*.js"
},
"import": {
"types": "./dist/esm/*.d.ts",
"default": "./dist/esm/*.js"
"types": "./dist/index.d.ts",
"default": "./dist/index.js"
}
}
},
Expand All @@ -43,7 +33,7 @@
"style"
],
"bin": {
"title": "./dist/esm/bin.js"
"title": "./dist/bin.js"
},
"files": [
"dist"
Expand All @@ -64,4 +54,4 @@
},
"sideEffects": false,
"packageManager": "pnpm@9.13.2"
}
}
4 changes: 2 additions & 2 deletions src/bin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import clipboardy from 'clipboardy'
const { red, grey, blue } = chalk

// Utilities
import pkg from '../package.json'
import title from './index.js'
import { help } from './help.js'

Expand All @@ -27,7 +26,8 @@ const { _, ...args } = parse({
// Output the package's version if
// the `--version was supplied
if (args['--version']) {
console.log(pkg.version)
// Injected at build time
console.log(process.env.PKG_VERSION);
process.exit(0)
}

Expand Down
2 changes: 1 addition & 1 deletion test/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import { describe, expect, test } from 'vitest'

// Source
import title from '../dist/esm/index.js'
import title from '../dist/index.js'

describe('Converting a string to title case', () => {
test('should capitalize the first letter of relevant words', () => {
Expand Down
32 changes: 11 additions & 21 deletions tsup.config.ts
Original file line number Diff line number Diff line change
@@ -1,28 +1,18 @@
import { defineConfig, Options } from 'tsup'
import fs from 'node:fs/promises'
import path from 'node:path'
import { defineConfig } from 'tsup';
import { readFileSync } from 'node:fs';

const sharedConfig: Options = {
const { version } = JSON.parse(
readFileSync(new URL('./package.json', import.meta.url), 'utf-8'),
);

export default defineConfig({
entry: ['src/**/*.ts'],
clean: true,
dts: true,
bundle: false,
splitting: true,
}

export default defineConfig([
{
format: 'esm',
outDir: 'dist/esm',
...sharedConfig
},
{
format: 'cjs',
outDir: 'dist/cjs',
outExtension: () => ({ js: '.js' }),
async onSuccess() {
await fs.writeFile(path.resolve('dist', 'cjs', 'package.json'), '{"type": "commonjs","sideEffects":false}');
},
...sharedConfig
define: {
'process.env.PKG_VERSION': JSON.stringify(version),
},
])
format: ['esm', 'cjs'],
});