Skip to content

Commit

Permalink
feat: Allow main/module and import/require sections in copy package j…
Browse files Browse the repository at this point in the history
…son to be generated based on configuration input + add missing packages for check-packages
  • Loading branch information
tristanmenzel committed Sep 24, 2024
1 parent cb70fa3 commit 343ee1e
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 5 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@makerx/ts-toolkit",
"version": "4.0.0-beta.20",
"version": "4.0.0-beta.21",
"description": "This cli facilitates the creation of boilerplate files in a new typescript repo",
"repository": "https://github.com/MakerXStudio/ts-toolkit",
"type": "module",
Expand Down
2 changes: 2 additions & 0 deletions src/init/check-packages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ const basePackages: Record<string, string> = {
'@eslint/js': 'latest',
'@typescript-eslint/eslint-plugin': 'latest',
'@typescript-eslint/parser': 'latest',
'eslint-config-prettier': 'latest',
'eslint-plugin-prettier': 'latest',
}

const nodePackages: Record<string, string> = {
Expand Down
11 changes: 7 additions & 4 deletions src/util/copy-package-json-from-config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,13 @@ import { colorConsole } from '../color-console'
import { standardSectionWhitelist } from './copy-package-json'

export type ModuleType = 'module' | 'commonjs'
export type ExportType = 'module' | 'commonjs' | 'both'
export interface PackageConfig {
main?: string
srcDir?: string
outDir?: string
exports?: Record<string, string>
exportTypes?: ExportType
bin?: Record<string, string>
customSections?: string[]
packageJsonSource?: string
Expand All @@ -23,6 +25,7 @@ export const copyPackageJsonFromConfig = (suppliedConfig: PackageConfig) => {
outDir: 'dist',
moduleType: 'commonjs' as ModuleType,
packageJsonSource: 'package.json',
exportTypes: 'both' as ExportType,
...suppliedConfig,
}

Expand All @@ -38,8 +41,8 @@ export const copyPackageJsonFromConfig = (suppliedConfig: PackageConfig) => {
// Include all files in the package by default
files: ['**'],
...pick(packageJson, ...sectionsToUse),
main: changeExtensions(config.main, 'js'),
module: changeExtensions(config.main, 'mjs'),
main: config.exportTypes !== 'module' ? changeExtensions(config.main, 'js') : undefined,
module: config.exportTypes !== 'commonjs' ? changeExtensions(config.main, 'mjs') : undefined,
types: changeExtensions(config.main, 'd.ts'),
type: config.moduleType,
bin: config.bin && mapObject(config.bin, (key, value) => [key, changeExtensions(value, config.moduleType == 'module' ? 'mjs' : 'js')]),
Expand All @@ -49,8 +52,8 @@ export const copyPackageJsonFromConfig = (suppliedConfig: PackageConfig) => {
key,
{
types: changeExtensions(value, 'd.ts'),
import: changeExtensions(value, 'mjs'),
require: changeExtensions(value, 'js'),
import: config.exportTypes !== 'commonjs' ? changeExtensions(value, 'mjs') : undefined,
require: config.exportTypes !== 'module' ? changeExtensions(value, 'js') : undefined,
},
]),
}
Expand Down

0 comments on commit 343ee1e

Please sign in to comment.