@a35hie/ts-pkg 0.1.2 → 0.1.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/main.js CHANGED
File without changes
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@a35hie/ts-pkg",
3
- "version": "0.1.2",
3
+ "version": "0.1.3",
4
4
  "description": "TypeScript-based package.json with magical features",
5
5
  "license": "Apache-2.0",
6
6
  "repository": "https://github.com/a35hie/TsPkg",
@@ -9,10 +9,13 @@
9
9
  "module": "dist/main.js",
10
10
  "types": "dist/main.d.ts",
11
11
  "bin": {
12
- "ts-pkg": "./dist/main.js"
12
+ "ts-pkg": "./dist/cli.js"
13
13
  },
14
+ "files": [
15
+ "dist"
16
+ ],
14
17
  "scripts": {
15
- "build": "tsc",
18
+ "build": "bun run build.ts",
16
19
  "build:watch": "tsc --watch",
17
20
  "typecheck": "tsc --noEmit",
18
21
  "format": "prettier --write .",
@@ -25,6 +28,7 @@
25
28
  "devDependencies": {
26
29
  "typescript": "^5.9.3",
27
30
  "prettier": "^3.8.1",
31
+ "bun-plugin-dts": "^0.3.0",
28
32
  "@types/bun": "^1.3.8"
29
33
  },
30
34
  "peerDependencies": {
@@ -1,6 +0,0 @@
1
- <?xml version="1.0" encoding="UTF-8"?>
2
- <project version="4">
3
- <component name="Ask2AgentMigrationStateService">
4
- <option name="migrationStatus" value="COMPLETED" />
5
- </component>
6
- </project>
@@ -1,38 +0,0 @@
1
- <component name="InspectionProjectProfileManager">
2
- <profile version="1.0">
3
- <option name="myName" value="Project Default" />
4
- <inspection_tool class="HtmlUnknownTag" enabled="true" level="WARNING" enabled_by_default="true">
5
- <option name="myValues">
6
- <value>
7
- <list size="7">
8
- <item index="0" class="java.lang.String" itemvalue="nobr" />
9
- <item index="1" class="java.lang.String" itemvalue="noembed" />
10
- <item index="2" class="java.lang.String" itemvalue="comment" />
11
- <item index="3" class="java.lang.String" itemvalue="noscript" />
12
- <item index="4" class="java.lang.String" itemvalue="embed" />
13
- <item index="5" class="java.lang.String" itemvalue="script" />
14
- <item index="6" class="java.lang.String" itemvalue="iconify-icon" />
15
- </list>
16
- </value>
17
- </option>
18
- <option name="myCustomValuesEnabled" value="true" />
19
- </inspection_tool>
20
- <inspection_tool class="PyPep8Inspection" enabled="true" level="INFORMATION" enabled_by_default="true">
21
- <option name="ignoredErrors">
22
- <list>
23
- <option value="E302" />
24
- </list>
25
- </option>
26
- </inspection_tool>
27
- <inspection_tool class="PyPep8NamingInspection" enabled="true" level="WEAK WARNING" enabled_by_default="true">
28
- <option name="ignoredErrors">
29
- <list>
30
- <option value="N802" />
31
- <option value="N806" />
32
- <option value="N812" />
33
- <option value="N803" />
34
- </list>
35
- </option>
36
- </inspection_tool>
37
- </profile>
38
- </component>
package/.idea/misc.xml DELETED
@@ -1,6 +0,0 @@
1
- <?xml version="1.0" encoding="UTF-8"?>
2
- <project version="4">
3
- <component name="ProjectRootManager" version="2">
4
- <output url="file://$PROJECT_DIR$/out" />
5
- </component>
6
- </project>
package/.idea/modules.xml DELETED
@@ -1,8 +0,0 @@
1
- <?xml version="1.0" encoding="UTF-8"?>
2
- <project version="4">
3
- <component name="ProjectModuleManager">
4
- <modules>
5
- <module fileurl="file://$PROJECT_DIR$/ts-pkg-config.iml" filepath="$PROJECT_DIR$/ts-pkg-config.iml" />
6
- </modules>
7
- </component>
8
- </project>
package/.idea/vcs.xml DELETED
@@ -1,6 +0,0 @@
1
- <?xml version="1.0" encoding="UTF-8"?>
2
- <project version="4">
3
- <component name="VcsDirectoryMappings">
4
- <mapping directory="$PROJECT_DIR$" vcs="Git" />
5
- </component>
6
- </project>
package/.prettierignore DELETED
@@ -1,6 +0,0 @@
1
- node_modules
2
- .idea
3
- .vscode
4
- bun.lock
5
- .prettierignore
6
- dist
package/.prettierrc DELETED
@@ -1,9 +0,0 @@
1
- {
2
- "semi": false,
3
- "singleQuote": true,
4
- "trailingComma": "es5",
5
- "bracketSpacing": true,
6
- "arrowParens": "avoid",
7
- "endOfLine": "lf",
8
- "tabWidth": 2
9
- }
package/build.ts DELETED
@@ -1,26 +0,0 @@
1
- import dts from 'bun-plugin-dts'
2
-
3
- // Build library
4
- await Bun.build({
5
- entrypoints: ['./src/main.ts'],
6
- outdir: './dist',
7
- format: 'esm',
8
- target: 'node',
9
- splitting: false,
10
- sourcemap: 'external',
11
- minify: false,
12
- plugins: [dts()],
13
- })
14
-
15
- // Build CLI
16
- await Bun.build({
17
- entrypoints: ['./src/cli.ts'],
18
- outdir: './dist',
19
- format: 'esm',
20
- target: 'node',
21
- splitting: false,
22
- minify: false,
23
- banner: '#!/usr/bin/env bun',
24
- })
25
-
26
- console.log('✨ Build complete')
package/bun.lock DELETED
@@ -1,73 +0,0 @@
1
- {
2
- "lockfileVersion": 1,
3
- "configVersion": 1,
4
- "workspaces": {
5
- "": {
6
- "name": "ts-pkg-config",
7
- "devDependencies": {
8
- "@types/bun": "^1.3.8",
9
- "bun-plugin-dts": "^0.3.0",
10
- "prettier": "^3.8.1",
11
- "typescript": "^5.9.3",
12
- },
13
- "peerDependencies": {
14
- "typescript": "^5",
15
- },
16
- },
17
- },
18
- "packages": {
19
- "@types/bun": ["@types/bun@1.3.8", "", { "dependencies": { "bun-types": "1.3.8" } }, "sha512-3LvWJ2q5GerAXYxO2mffLTqOzEu5qnhEAlh48Vnu8WQfnmSwbgagjGZV6BoHKJztENYEDn6QmVd949W4uESRJA=="],
20
-
21
- "@types/node": ["@types/node@25.2.2", "", { "dependencies": { "undici-types": "~7.16.0" } }, "sha512-BkmoP5/FhRYek5izySdkOneRyXYN35I860MFAGupTdebyE66uZaR+bXLHq8k4DirE5DwQi3NuhvRU1jqTVwUrQ=="],
22
-
23
- "ansi-regex": ["ansi-regex@5.0.1", "", {}, "sha512-quJQXlTSUGL2LH9SUXo8VwsY4soanhgo6LNSm84E1LBcE8s3O0wpdiRzyR9z/ZZJMlMWv37qOOb9pdJlMUEKFQ=="],
24
-
25
- "ansi-styles": ["ansi-styles@4.3.0", "", { "dependencies": { "color-convert": "^2.0.1" } }, "sha512-zbB9rCJAT1rbjiVDb2hqKFHNYLxgtk8NURxZ3IZwD3F6NtxbXZQCnnSi1Lkx+IDohdPlFp222wVALIheZJQSEg=="],
26
-
27
- "bun-plugin-dts": ["bun-plugin-dts@0.3.0", "", { "dependencies": { "common-path-prefix": "^3.0.0", "dts-bundle-generator": "^9.5.1", "get-tsconfig": "^4.8.1" } }, "sha512-QpiAOKfPcdOToxySOqRY8FwL+brTvyXEHWzrSCRKt4Pv7Z4pnUrhK9tFtM7Ndm7ED09B/0cGXnHJKqmekr/ERw=="],
28
-
29
- "bun-types": ["bun-types@1.3.8", "", { "dependencies": { "@types/node": "*" } }, "sha512-fL99nxdOWvV4LqjmC+8Q9kW3M4QTtTR1eePs94v5ctGqU8OeceWrSUaRw3JYb7tU3FkMIAjkueehrHPPPGKi5Q=="],
30
-
31
- "cliui": ["cliui@8.0.1", "", { "dependencies": { "string-width": "^4.2.0", "strip-ansi": "^6.0.1", "wrap-ansi": "^7.0.0" } }, "sha512-BSeNnyus75C4//NQ9gQt1/csTXyo/8Sb+afLAkzAptFuMsod9HFokGNudZpi/oQV73hnVK+sR+5PVRMd+Dr7YQ=="],
32
-
33
- "color-convert": ["color-convert@2.0.1", "", { "dependencies": { "color-name": "~1.1.4" } }, "sha512-RRECPsj7iu/xb5oKYcsFHSppFNnsj/52OVTRKb4zP5onXwVF3zVmmToNcOfGC+CRDpfK/U584fMg38ZHCaElKQ=="],
34
-
35
- "color-name": ["color-name@1.1.4", "", {}, "sha512-dOy+3AuW3a2wNbZHIuMZpTcgjGuLU/uBL/ubcZF9OXbDo8ff4O8yVp5Bf0efS8uEoYo5q4Fx7dY9OgQGXgAsQA=="],
36
-
37
- "common-path-prefix": ["common-path-prefix@3.0.0", "", {}, "sha512-QE33hToZseCH3jS0qN96O/bSh3kaw/h+Tq7ngyY9eWDUnTlTNUyqfqvCXioLe5Na5jFsL78ra/wuBU4iuEgd4w=="],
38
-
39
- "dts-bundle-generator": ["dts-bundle-generator@9.5.1", "", { "dependencies": { "typescript": ">=5.0.2", "yargs": "^17.6.0" }, "bin": { "dts-bundle-generator": "dist/bin/dts-bundle-generator.js" } }, "sha512-DxpJOb2FNnEyOzMkG11sxO2dmxPjthoVWxfKqWYJ/bI/rT1rvTMktF5EKjAYrRZu6Z6t3NhOUZ0sZ5ZXevOfbA=="],
40
-
41
- "emoji-regex": ["emoji-regex@8.0.0", "", {}, "sha512-MSjYzcWNOA0ewAHpz0MxpYFvwg6yjy1NG3xteoqz644VCo/RPgnr1/GGt+ic3iJTzQ8Eu3TdM14SawnVUmGE6A=="],
42
-
43
- "escalade": ["escalade@3.2.0", "", {}, "sha512-WUj2qlxaQtO4g6Pq5c29GTcWGDyd8itL8zTlipgECz3JesAiiOKotd8JU6otB3PACgG6xkJUyVhboMS+bje/jA=="],
44
-
45
- "get-caller-file": ["get-caller-file@2.0.5", "", {}, "sha512-DyFP3BM/3YHTQOCUL/w0OZHR0lpKeGrxotcHWcqNEdnltqFwXVfhEBQ94eIo34AfQpo0rGki4cyIiftY06h2Fg=="],
46
-
47
- "get-tsconfig": ["get-tsconfig@4.13.6", "", { "dependencies": { "resolve-pkg-maps": "^1.0.0" } }, "sha512-shZT/QMiSHc/YBLxxOkMtgSid5HFoauqCE3/exfsEcwg1WkeqjG+V40yBbBrsD+jW2HDXcs28xOfcbm2jI8Ddw=="],
48
-
49
- "is-fullwidth-code-point": ["is-fullwidth-code-point@3.0.0", "", {}, "sha512-zymm5+u+sCsSWyD9qNaejV3DFvhCKclKdizYaJUuHA83RLjb7nSuGnddCHGv0hk+KY7BMAlsWeK4Ueg6EV6XQg=="],
50
-
51
- "prettier": ["prettier@3.8.1", "", { "bin": { "prettier": "bin/prettier.cjs" } }, "sha512-UOnG6LftzbdaHZcKoPFtOcCKztrQ57WkHDeRD9t/PTQtmT0NHSeWWepj6pS0z/N7+08BHFDQVUrfmfMRcZwbMg=="],
52
-
53
- "require-directory": ["require-directory@2.1.1", "", {}, "sha512-fGxEI7+wsG9xrvdjsrlmL22OMTTiHRwAMroiEeMgq8gzoLC/PQr7RsRDSTLUg/bZAZtF+TVIkHc6/4RIKrui+Q=="],
54
-
55
- "resolve-pkg-maps": ["resolve-pkg-maps@1.0.0", "", {}, "sha512-seS2Tj26TBVOC2NIc2rOe2y2ZO7efxITtLZcGSOnHHNOQ7CkiUBfw0Iw2ck6xkIhPwLhKNLS8BO+hEpngQlqzw=="],
56
-
57
- "string-width": ["string-width@4.2.3", "", { "dependencies": { "emoji-regex": "^8.0.0", "is-fullwidth-code-point": "^3.0.0", "strip-ansi": "^6.0.1" } }, "sha512-wKyQRQpjJ0sIp62ErSZdGsjMJWsap5oRNihHhu6G7JVO/9jIB6UyevL+tXuOqrng8j/cxKTWyWUwvSTriiZz/g=="],
58
-
59
- "strip-ansi": ["strip-ansi@6.0.1", "", { "dependencies": { "ansi-regex": "^5.0.1" } }, "sha512-Y38VPSHcqkFrCpFnQ9vuSXmquuv5oXOKpGeT6aGrr3o3Gc9AlVa6JBfUSOCnbxGGZF+/0ooI7KrPuUSztUdU5A=="],
60
-
61
- "typescript": ["typescript@5.9.3", "", { "bin": { "tsc": "bin/tsc", "tsserver": "bin/tsserver" } }, "sha512-jl1vZzPDinLr9eUt3J/t7V6FgNEw9QjvBPdysz9KfQDD41fQrC2Y4vKQdiaUpFT4bXlb1RHhLpp8wtm6M5TgSw=="],
62
-
63
- "undici-types": ["undici-types@7.16.0", "", {}, "sha512-Zz+aZWSj8LE6zoxD+xrjh4VfkIG8Ya6LvYkZqtUQGJPZjYl53ypCaUwWqo7eI0x66KBGeRo+mlBEkMSeSZ38Nw=="],
64
-
65
- "wrap-ansi": ["wrap-ansi@7.0.0", "", { "dependencies": { "ansi-styles": "^4.0.0", "string-width": "^4.1.0", "strip-ansi": "^6.0.0" } }, "sha512-YVGIj2kamLSTxw6NsZjoBxfSwsn0ycdesmc4p+Q21c5zPuZ1pl+NfxVdxPtdHvmNVOQ6XSYG4AUtyt/Fi7D16Q=="],
66
-
67
- "y18n": ["y18n@5.0.8", "", {}, "sha512-0pfFzegeDWJHJIAmTLRP2DwHjdF5s7jo9tuztdQxAhINCdvS+3nGINqPd00AphqJR/0LhANUS6/+7SCb98YOfA=="],
68
-
69
- "yargs": ["yargs@17.7.2", "", { "dependencies": { "cliui": "^8.0.1", "escalade": "^3.1.1", "get-caller-file": "^2.0.5", "require-directory": "^2.1.1", "string-width": "^4.2.3", "y18n": "^5.0.5", "yargs-parser": "^21.1.1" } }, "sha512-7dSzzRQ++CKnNI/krKnYRV7JKKPUXMEh61soaHKg9mrWEhzFWhFnxPxGl+69cD1Ou63C13NUPCnmIcrvqCuM6w=="],
70
-
71
- "yargs-parser": ["yargs-parser@21.1.1", "", {}, "sha512-tVpsJW7DdjecAiFpbIB1e3qxIQsE6NoPc5/eTdrbbIC4h0LVsWhnoa3g+m2HclBIujHzsxZ4VJVA+GUuc2/LBw=="],
72
- }
73
- }
package/package.config.ts DELETED
@@ -1,58 +0,0 @@
1
- import { definePackageConfig } from '@/main.ts'
2
-
3
- export default definePackageConfig({
4
- name: '@a35hie/ts-pkg',
5
- version: '0.1.2',
6
- description: 'TypeScript-based package.json with magical features',
7
- type: 'module',
8
- license: 'Apache-2.0',
9
- repository: 'https://github.com/a35hie/TsPkg',
10
-
11
- // Entry points
12
- main: 'dist/main.js',
13
- module: 'dist/main.js',
14
- types: 'dist/main.d.ts',
15
- bin: {
16
- 'ts-pkg': './dist/main.js',
17
- },
18
-
19
- // Script presets auto-generate common scripts
20
- scriptPresets: ['typescript', 'prettier', 'testing'],
21
-
22
- // Custom scripts (merged with presets, overrides if same name)
23
- scripts: {
24
- generate: 'bun run src/main.ts',
25
- },
26
-
27
- // Just list package names - versions auto-resolved!
28
- dependencies: [],
29
-
30
- devDependencies: ['typescript', 'prettier', '@types/bun'],
31
-
32
- peerDependencies: [
33
- 'typescript@^5', // Can specify version constraints
34
- ],
35
-
36
- // Conditional configuration based on environment
37
- conditions: [
38
- {
39
- when: { env: 'production' },
40
- set: {
41
- private: false,
42
- },
43
- },
44
- {
45
- when: { ci: true },
46
- set: {
47
- scripts: {
48
- test: 'vitest run --reporter=verbose',
49
- },
50
- },
51
- },
52
- ],
53
-
54
- engines: {
55
- node: '>=18',
56
- bun: '>=1.0',
57
- },
58
- })
package/src/cli.ts DELETED
@@ -1,40 +0,0 @@
1
- import type { PackageConfig } from './schemas/package'
2
- import { writePackageJson } from './generator/createPackageJson'
3
- import { resolve } from 'node:path'
4
- import { pathToFileURL } from 'node:url'
5
-
6
- async function main() {
7
- const configPath = process.argv[2] ?? 'package.config.ts'
8
- const outputPath = process.argv[3] ?? 'package.json'
9
-
10
- const absoluteConfigPath = resolve(process.cwd(), configPath)
11
-
12
- try {
13
- const configModule = await import(pathToFileURL(absoluteConfigPath).href)
14
- const config: PackageConfig = configModule.default ?? configModule
15
-
16
- await writePackageJson(config, { outputPath })
17
- } catch (error) {
18
- const err = error as NodeJS.ErrnoException
19
- if (err.code === 'ERR_MODULE_NOT_FOUND' || err.code === 'ENOENT') {
20
- console.error(`❌ Config file not found: ${configPath}`)
21
- console.error('\nCreate a package.config.ts file with:')
22
- console.error(`
23
- import { definePackageConfig } from '@a35hie/ts-pkg'
24
-
25
- export default definePackageConfig({
26
- name: 'my-package',
27
- version: '1.0.0',
28
- scriptPresets: ['typescript', 'testing'],
29
- dependencies: ['lodash', 'zod'],
30
- devDependencies: ['typescript', 'vitest'],
31
- })
32
- `)
33
- process.exit(1)
34
- }
35
- console.error('❌ Error:', err.message)
36
- process.exit(1)
37
- }
38
- }
39
-
40
- main()
@@ -1,85 +0,0 @@
1
- import type { PackageConfig, StandardPackageJson } from '../schemas/package'
2
- import { getPresetScripts, mergeScripts } from '../presets/scripts'
3
- import { resolveDependenciesCached } from '../resolvers/dependencies'
4
- import { resolveExtends } from '../utils/merge'
5
- import { applyConditions } from '../utils/conditions'
6
-
7
- export interface GenerateOptions {
8
- indent?: number
9
- outputPath?: string
10
- }
11
-
12
- export async function createPackageJson(
13
- config: PackageConfig,
14
- options: GenerateOptions = {}
15
- ): Promise<string> {
16
- const { indent = 2 } = options
17
-
18
- // Step 1: Resolve extends chain
19
- let resolved = await resolveExtends(config)
20
-
21
- // Step 2: Build scripts from presets + custom
22
- const presetScripts = resolved.scriptPresets
23
- ? getPresetScripts(resolved.scriptPresets)
24
- : {}
25
- const finalScripts = mergeScripts(presetScripts, resolved.scripts)
26
-
27
- // Step 3: Resolve dependency versions
28
- const [dependencies, devDependencies, peerDependencies] = await Promise.all([
29
- resolveDependenciesCached(resolved.dependencies),
30
- resolveDependenciesCached(resolved.devDependencies),
31
- resolveDependenciesCached(resolved.peerDependencies),
32
- ])
33
-
34
- // Step 4: Build standard package.json
35
- const packageJson: StandardPackageJson = {
36
- name: resolved.name,
37
- ...(resolved.version && { version: resolved.version }),
38
- ...(resolved.description && { description: resolved.description }),
39
- ...(resolved.keywords?.length && { keywords: resolved.keywords }),
40
- ...(resolved.homepage && { homepage: resolved.homepage }),
41
- ...(resolved.bugs && { bugs: resolved.bugs }),
42
- ...(resolved.license && { license: resolved.license }),
43
- ...(resolved.author && { author: resolved.author }),
44
- ...(resolved.contributors?.length && {
45
- contributors: resolved.contributors,
46
- }),
47
- ...(resolved.repository && { repository: resolved.repository }),
48
- ...(resolved.type && { type: resolved.type }),
49
- ...(resolved.main && { main: resolved.main }),
50
- ...(resolved.module && { module: resolved.module }),
51
- ...(resolved.types && { types: resolved.types }),
52
- ...(resolved.exports && { exports: resolved.exports }),
53
- ...(resolved.bin && { bin: resolved.bin }),
54
- ...(resolved.files?.length && { files: resolved.files }),
55
- ...(Object.keys(finalScripts).length && { scripts: finalScripts }),
56
- ...(Object.keys(dependencies).length && { dependencies }),
57
- ...(Object.keys(devDependencies).length && { devDependencies }),
58
- ...(Object.keys(peerDependencies).length && { peerDependencies }),
59
- ...(resolved.optionalDependencies && {
60
- optionalDependencies: resolved.optionalDependencies,
61
- }),
62
- ...(resolved.engines && { engines: resolved.engines }),
63
- ...(resolved.os?.length && { os: resolved.os }),
64
- ...(resolved.cpu?.length && { cpu: resolved.cpu }),
65
- ...(resolved.private !== undefined && { private: resolved.private }),
66
- ...(resolved.publishConfig && { publishConfig: resolved.publishConfig }),
67
- ...(resolved.workspaces?.length && { workspaces: resolved.workspaces }),
68
- }
69
-
70
- // Step 5: Apply conditional configs
71
- const finalPackageJson = applyConditions(packageJson, resolved.conditions)
72
-
73
- return JSON.stringify(finalPackageJson, null, indent)
74
- }
75
-
76
- export async function writePackageJson(
77
- config: PackageConfig,
78
- options: GenerateOptions = {}
79
- ): Promise<void> {
80
- const { outputPath = 'package.json' } = options
81
- const json = await createPackageJson(config, options)
82
- const { writeFile } = await import('node:fs/promises')
83
- await writeFile(outputPath, json + '\n')
84
- console.log(`✨ Generated ${outputPath}`)
85
- }
package/src/main.ts DELETED
@@ -1,63 +0,0 @@
1
- import type {
2
- PackageConfig,
3
- StandardPackageJson,
4
- ScriptPreset,
5
- DependencyInput,
6
- DependenciesInput,
7
- ConditionalConfig,
8
- License,
9
- } from './schemas/package'
10
- import {
11
- createPackageJson,
12
- writePackageJson,
13
- type GenerateOptions,
14
- } from './generator/createPackageJson'
15
-
16
- export function definePackageConfig(config: PackageConfig): PackageConfig {
17
- return config
18
- }
19
-
20
- // Run CLI if executed directly
21
- async function main() {
22
- const configPath = process.argv[2] ?? 'package.config.ts'
23
- const outputPath = process.argv[3] ?? 'package.json'
24
-
25
- try {
26
- const configModule = await import(Bun.pathToFileURL(configPath).href)
27
- const config: PackageConfig = configModule.default ?? configModule
28
-
29
- await writePackageJson(config, { outputPath })
30
- } catch (error) {
31
- if ((error as NodeJS.ErrnoException).code === 'ERR_MODULE_NOT_FOUND') {
32
- console.error(`❌ Config file not found: ${configPath}`)
33
- console.error('\nCreate a package.config.ts file with:')
34
- console.error(`
35
- import { definePackageConfig } from './src/main'
36
-
37
- export default definePackageConfig({
38
- name: 'my-package',
39
- version: '1.0.0',
40
- scriptPresets: ['typescript', 'testing'],
41
- dependencies: ['lodash', 'zod'],
42
- devDependencies: ['typescript', 'vitest'],
43
- })
44
- `)
45
- process.exit(1)
46
- }
47
- throw error
48
- }
49
- }
50
-
51
- // Export everything
52
- export {
53
- createPackageJson,
54
- writePackageJson,
55
- type PackageConfig,
56
- type StandardPackageJson,
57
- type ScriptPreset,
58
- type DependencyInput,
59
- type DependenciesInput,
60
- type ConditionalConfig,
61
- type GenerateOptions,
62
- type License,
63
- }
@@ -1,59 +0,0 @@
1
- import type { ScriptPreset } from '../schemas/package'
2
-
3
- type ScriptDefinitions = Record<string, string>
4
-
5
- const scriptPresets: Record<ScriptPreset, ScriptDefinitions> = {
6
- typescript: {
7
- build: 'tsc',
8
- 'build:watch': 'tsc --watch',
9
- typecheck: 'tsc --noEmit',
10
- },
11
-
12
- react: {
13
- dev: 'vite',
14
- build: 'vite build',
15
- preview: 'vite preview',
16
- },
17
-
18
- node: {
19
- start: 'node dist/index.js',
20
- dev: 'tsx watch src/index.ts',
21
- build: 'tsup src/index.ts --format esm,cjs --dts',
22
- },
23
-
24
- testing: {
25
- test: 'vitest',
26
- 'test:watch': 'vitest watch',
27
- 'test:coverage': 'vitest --coverage',
28
- },
29
-
30
- prettier: {
31
- format: 'prettier --write .',
32
- 'format:check': 'prettier --check .',
33
- },
34
-
35
- eslint: {
36
- lint: 'eslint .',
37
- 'lint:fix': 'eslint . --fix',
38
- },
39
- }
40
-
41
- export function getPresetScripts(presets: ScriptPreset[]): ScriptDefinitions {
42
- const merged: ScriptDefinitions = {}
43
-
44
- for (const preset of presets) {
45
- const scripts = scriptPresets[preset]
46
- if (scripts) {
47
- Object.assign(merged, scripts)
48
- }
49
- }
50
-
51
- return merged
52
- }
53
-
54
- export function mergeScripts(
55
- presetScripts: ScriptDefinitions,
56
- customScripts?: ScriptDefinitions
57
- ): ScriptDefinitions {
58
- return { ...presetScripts, ...customScripts }
59
- }
@@ -1,125 +0,0 @@
1
- import type { DependencyInput, DependenciesInput } from '../schemas/package'
2
-
3
- interface NpmPackageInfo {
4
- 'dist-tags': {
5
- latest: string
6
- [tag: string]: string
7
- }
8
- versions: Record<string, unknown>
9
- }
10
-
11
- // Parse dependency input: 'lodash' | 'lodash@^4' | { lodash: '^4.0.0' }
12
- function parseDependency(dep: DependencyInput): {
13
- name: string
14
- version?: string
15
- } {
16
- if (typeof dep === 'string') {
17
- const atIndex = dep.lastIndexOf('@')
18
- if (atIndex > 0) {
19
- return {
20
- name: dep.slice(0, atIndex),
21
- version: dep.slice(atIndex + 1),
22
- }
23
- }
24
- return { name: dep }
25
- }
26
-
27
- // Object form: { lodash: '^4.0.0' }
28
- const [name, version] = Object.entries(dep)[0]!
29
- return { name, version }
30
- }
31
-
32
- // Fetch latest version from npm registry
33
- async function fetchLatestVersion(packageName: string): Promise<string> {
34
- const url = `https://registry.npmjs.org/${encodeURIComponent(packageName)}`
35
-
36
- const response = await fetch(url, {
37
- headers: { Accept: 'application/json' },
38
- })
39
-
40
- if (!response.ok) {
41
- throw new Error(`Failed to fetch ${packageName}: ${response.statusText}`)
42
- }
43
-
44
- const data = (await response.json()) as NpmPackageInfo
45
- return data['dist-tags'].latest
46
- }
47
-
48
- // Resolve a single dependency to name: version pair
49
- async function resolveDependency(
50
- dep: DependencyInput
51
- ): Promise<[string, string]> {
52
- const { name, version } = parseDependency(dep)
53
-
54
- if (version) {
55
- return [name, version]
56
- }
57
-
58
- // Auto-resolve latest version with ^ prefix
59
- const latestVersion = await fetchLatestVersion(name)
60
- return [name, `^${latestVersion}`]
61
- }
62
-
63
- // Resolve all dependencies in parallel with batching
64
- export async function resolveDependencies(
65
- deps: DependenciesInput | undefined
66
- ): Promise<Record<string, string>> {
67
- if (!deps) {
68
- return {}
69
- }
70
-
71
- // If already an object (standard format), return as-is
72
- if (!Array.isArray(deps)) {
73
- return deps
74
- }
75
-
76
- if (deps.length === 0) {
77
- return {}
78
- }
79
-
80
- const results = await Promise.all(deps.map(resolveDependency))
81
-
82
- return Object.fromEntries(results)
83
- }
84
-
85
- // Cache for resolved versions (persists during single run)
86
- const versionCache = new Map<string, string>()
87
-
88
- export async function resolveDependenciesCached(
89
- deps: DependenciesInput | undefined
90
- ): Promise<Record<string, string>> {
91
- if (!deps) {
92
- return {}
93
- }
94
-
95
- // If already an object (standard format), return as-is
96
- if (!Array.isArray(deps)) {
97
- return deps
98
- }
99
-
100
- if (deps.length === 0) {
101
- return {}
102
- }
103
-
104
- const results: [string, string][] = []
105
-
106
- for (const dep of deps) {
107
- const { name, version } = parseDependency(dep)
108
-
109
- if (version) {
110
- results.push([name, version])
111
- continue
112
- }
113
-
114
- // Check cache first
115
- let resolvedVersion = versionCache.get(name)
116
- if (!resolvedVersion) {
117
- resolvedVersion = `^${await fetchLatestVersion(name)}`
118
- versionCache.set(name, resolvedVersion)
119
- }
120
-
121
- results.push([name, resolvedVersion])
122
- }
123
-
124
- return Object.fromEntries(results)
125
- }
@@ -1,125 +0,0 @@
1
- // Common SPDX license identifiers
2
- export type License =
3
- | 'MIT'
4
- | 'Apache-2.0'
5
- | 'GPL-2.0-only'
6
- | 'GPL-2.0-or-later'
7
- | 'GPL-3.0-only'
8
- | 'GPL-3.0-or-later'
9
- | 'LGPL-2.1-only'
10
- | 'LGPL-2.1-or-later'
11
- | 'LGPL-3.0-only'
12
- | 'LGPL-3.0-or-later'
13
- | 'BSD-2-Clause'
14
- | 'BSD-3-Clause'
15
- | 'ISC'
16
- | 'MPL-2.0'
17
- | 'AGPL-3.0-only'
18
- | 'AGPL-3.0-or-later'
19
- | 'Unlicense'
20
- | 'WTFPL'
21
- | 'CC0-1.0'
22
- | 'CC-BY-4.0'
23
- | 'CC-BY-SA-4.0'
24
- | 'Zlib'
25
- | 'BSL-1.0'
26
- | 'EPL-2.0'
27
- | 'EUPL-1.2'
28
- | 'CDDL-1.0'
29
- | 'Artistic-2.0'
30
- | 'OSL-3.0'
31
- | 'AFL-3.0'
32
- | 'LPPL-1.3c'
33
- | (string & {}) // Allow custom licenses while preserving autocomplete
34
-
35
- // Standard package.json fields
36
- export interface StandardPackageJson {
37
- name: string
38
- version?: string
39
- description?: string
40
- keywords?: string[]
41
- homepage?: string
42
- bugs?: string | { url?: string; email?: string }
43
- license?: License
44
- author?: string | { name: string; email?: string; url?: string }
45
- contributors?: (string | { name: string; email?: string; url?: string })[]
46
- repository?: string | { type: string; url: string; directory?: string }
47
- main?: string
48
- module?: string
49
- types?: string
50
- exports?: Record<
51
- string,
52
- string | { import?: string; require?: string; types?: string }
53
- >
54
- bin?: string | Record<string, string>
55
- files?: string[]
56
- scripts?: Record<string, string>
57
- dependencies?: Record<string, string>
58
- devDependencies?: Record<string, string>
59
- peerDependencies?: Record<string, string>
60
- optionalDependencies?: Record<string, string>
61
- engines?: Record<string, string>
62
- os?: string[]
63
- cpu?: string[]
64
- private?: boolean
65
- publishConfig?: Record<string, unknown>
66
- workspaces?: string[]
67
- type?: 'module' | 'commonjs'
68
- }
69
-
70
- // Script preset names
71
- export type ScriptPreset =
72
- | 'typescript'
73
- | 'react'
74
- | 'node'
75
- | 'testing'
76
- | 'prettier'
77
- | 'eslint'
78
-
79
- // Dependency can be: 'lodash' | 'lodash@^4' | { lodash: '^4.0.0' } | Record<string, string>
80
- export type DependencyInput = string | Record<string, string>
81
-
82
- // Dependencies can be array (magical) or object (standard)
83
- export type DependenciesInput = DependencyInput[] | Record<string, string>
84
-
85
- // Conditional config block
86
- export interface ConditionalConfig {
87
- when: {
88
- env?: string
89
- platform?: NodeJS.Platform
90
- nodeVersion?: string
91
- ci?: boolean
92
- }
93
- set: Partial<StandardPackageJson>
94
- }
95
-
96
- // Magical package.json config with extra features
97
- export interface PackageConfig extends Omit<
98
- StandardPackageJson,
99
- 'scripts' | 'dependencies' | 'devDependencies' | 'peerDependencies'
100
- > {
101
- // Extends another config
102
- extends?: string | PackageConfig
103
-
104
- // Script presets: auto-generate common scripts
105
- scriptPresets?: ScriptPreset[]
106
- scripts?: Record<string, string>
107
-
108
- // Magical dependency inputs (auto-resolve versions) or standard object format
109
- dependencies?: DependenciesInput
110
- devDependencies?: DependenciesInput
111
- peerDependencies?: DependenciesInput
112
-
113
- // Conditional configuration
114
- conditions?: ConditionalConfig[]
115
-
116
- // Auto-infer fields
117
- autoInfer?: {
118
- version?: boolean // from git tags
119
- repository?: boolean // from git remote
120
- author?: boolean // from git config
121
- }
122
- }
123
-
124
- // Re-export for backwards compatibility
125
- export type PackageJson = PackageConfig
@@ -1,67 +0,0 @@
1
- import type { ConditionalConfig, StandardPackageJson } from '../schemas/package'
2
- import { deepMerge } from './merge'
3
-
4
- interface ConditionContext {
5
- env: string
6
- platform: NodeJS.Platform
7
- nodeVersion: string
8
- ci: boolean
9
- }
10
-
11
- function getContext(): ConditionContext {
12
- return {
13
- env: process.env.NODE_ENV ?? 'development',
14
- platform: process.platform,
15
- nodeVersion: process.version,
16
- ci: process.env.CI === 'true' || process.env.CI === '1',
17
- }
18
- }
19
-
20
- function evaluateCondition(
21
- when: ConditionalConfig['when'],
22
- context: ConditionContext
23
- ): boolean {
24
- if (when.env !== undefined && context.env !== when.env) {
25
- return false
26
- }
27
-
28
- if (when.platform !== undefined && context.platform !== when.platform) {
29
- return false
30
- }
31
-
32
- if (when.ci !== undefined && context.ci !== when.ci) {
33
- return false
34
- }
35
-
36
- if (when.nodeVersion !== undefined) {
37
- // Simple semver check (starts with)
38
- if (!context.nodeVersion.startsWith(when.nodeVersion)) {
39
- return false
40
- }
41
- }
42
-
43
- return true
44
- }
45
-
46
- export function applyConditions(
47
- baseConfig: Partial<StandardPackageJson>,
48
- conditions: ConditionalConfig[] | undefined
49
- ): Partial<StandardPackageJson> {
50
- if (!conditions || conditions.length === 0) {
51
- return baseConfig
52
- }
53
-
54
- const context = getContext()
55
- let result = { ...baseConfig }
56
-
57
- for (const condition of conditions) {
58
- if (evaluateCondition(condition.when, context)) {
59
- result = deepMerge(
60
- result,
61
- condition.set as Record<string, unknown>
62
- ) as Partial<StandardPackageJson>
63
- }
64
- }
65
-
66
- return result
67
- }
@@ -1,112 +0,0 @@
1
- import type { PackageConfig, DependenciesInput } from '../schemas/package'
2
-
3
- // Deep merge two objects, with source overriding target
4
- export function deepMerge<T extends Record<string, unknown>>(
5
- target: T,
6
- source: Partial<T>
7
- ): T {
8
- const result = { ...target }
9
-
10
- for (const key of Object.keys(source) as (keyof T)[]) {
11
- const sourceValue = source[key]
12
- const targetValue = target[key]
13
-
14
- if (sourceValue === undefined) continue
15
-
16
- if (
17
- typeof sourceValue === 'object' &&
18
- sourceValue !== null &&
19
- !Array.isArray(sourceValue) &&
20
- typeof targetValue === 'object' &&
21
- targetValue !== null &&
22
- !Array.isArray(targetValue)
23
- ) {
24
- result[key] = deepMerge(
25
- targetValue as Record<string, unknown>,
26
- sourceValue as Record<string, unknown>
27
- ) as T[keyof T]
28
- } else {
29
- result[key] = sourceValue as T[keyof T]
30
- }
31
- }
32
-
33
- return result
34
- }
35
-
36
- // Merge dependencies (handles both array and object formats)
37
- export function mergeDependencies(
38
- target: DependenciesInput | undefined,
39
- source: DependenciesInput | undefined
40
- ): DependenciesInput | undefined {
41
- if (!target && !source) return undefined
42
- if (!target) return source
43
- if (!source) return target
44
-
45
- // If both are arrays, concat them
46
- if (Array.isArray(target) && Array.isArray(source)) {
47
- return [...target, ...source]
48
- }
49
-
50
- // If both are objects, merge them
51
- if (!Array.isArray(target) && !Array.isArray(source)) {
52
- return { ...target, ...source }
53
- }
54
-
55
- // Mixed formats: convert array to object entries and merge
56
- const targetObj = Array.isArray(target) ? {} : target
57
- const sourceObj = Array.isArray(source) ? {} : source
58
- const targetArr = Array.isArray(target) ? target : []
59
- const sourceArr = Array.isArray(source) ? source : []
60
-
61
- // Return as array with both arrays and object merged
62
- return [...targetArr, ...sourceArr, { ...targetObj, ...sourceObj }]
63
- }
64
-
65
- // Resolve extends chain
66
- export async function resolveExtends(
67
- config: PackageConfig
68
- ): Promise<PackageConfig> {
69
- if (!config.extends) {
70
- return config
71
- }
72
-
73
- let baseConfig: PackageConfig
74
-
75
- if (typeof config.extends === 'string') {
76
- // Import from file path
77
- const imported = await import(config.extends)
78
- baseConfig = imported.default ?? imported
79
- } else {
80
- baseConfig = config.extends
81
- }
82
-
83
- // Recursively resolve base config's extends
84
- baseConfig = await resolveExtends(baseConfig)
85
-
86
- // Merge base into current (current overrides base)
87
- const { extends: _, ...currentWithoutExtends } = config
88
-
89
- return {
90
- ...baseConfig,
91
- ...currentWithoutExtends,
92
- // Merge dependencies (handles both array and object formats)
93
- dependencies: mergeDependencies(
94
- baseConfig.dependencies,
95
- currentWithoutExtends.dependencies
96
- ),
97
- devDependencies: mergeDependencies(
98
- baseConfig.devDependencies,
99
- currentWithoutExtends.devDependencies
100
- ),
101
- peerDependencies: mergeDependencies(
102
- baseConfig.peerDependencies,
103
- currentWithoutExtends.peerDependencies
104
- ),
105
- // Merge objects for scripts
106
- scripts: { ...baseConfig.scripts, ...currentWithoutExtends.scripts },
107
- scriptPresets: [
108
- ...(baseConfig.scriptPresets ?? []),
109
- ...(currentWithoutExtends.scriptPresets ?? []),
110
- ],
111
- }
112
- }
package/ts-pkg-config.iml DELETED
@@ -1,8 +0,0 @@
1
- <?xml version="1.0" encoding="UTF-8"?>
2
- <module type="GENERAL_MODULE" version="4">
3
- <component name="NewModuleRootManager" inherit-compiler-output="true">
4
- <exclude-output />
5
- <content url="file://$MODULE_DIR$" />
6
- <orderEntry type="sourceFolder" forTests="false" />
7
- </component>
8
- </module>
package/tsconfig.json DELETED
@@ -1,32 +0,0 @@
1
- {
2
- "compilerOptions": {
3
- // Environment setup & latest features
4
- "lib": ["ESNext"],
5
- "target": "ESNext",
6
- "module": "Preserve",
7
- "moduleDetection": "force",
8
- "jsx": "react-jsx",
9
- "allowJs": true,
10
-
11
- // Bundler mode
12
- "moduleResolution": "bundler",
13
- "allowImportingTsExtensions": true,
14
- "verbatimModuleSyntax": true,
15
- "noEmit": true,
16
-
17
- // Best practices
18
- "strict": true,
19
- "skipLibCheck": true,
20
- "noFallthroughCasesInSwitch": true,
21
- "noUncheckedIndexedAccess": true,
22
- "noImplicitOverride": true,
23
-
24
- // Some stricter flags (disabled by default)
25
- "noUnusedLocals": false,
26
- "noUnusedParameters": false,
27
- "noPropertyAccessFromIndexSignature": false,
28
- "paths": {
29
- "@/*": ["./src/*"]
30
- }
31
- }
32
- }