@a35hie/ts-pkg 0.1.1 → 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/README.md +3 -3
- package/dist/cli.js +313 -0
- package/dist/main.js +19 -33
- package/dist/main.js.map +4 -4
- package/package.json +7 -3
- package/.idea/copilot.data.migration.ask2agent.xml +0 -6
- package/.idea/inspectionProfiles/Project_Default.xml +0 -38
- package/.idea/misc.xml +0 -6
- package/.idea/modules.xml +0 -8
- package/.idea/vcs.xml +0 -6
- package/.prettierignore +0 -6
- package/.prettierrc +0 -9
- package/build.ts +0 -14
- package/bun.lock +0 -73
- package/package.config.ts +0 -58
- package/src/generator/createPackageJson.ts +0 -84
- package/src/main.ts +0 -68
- package/src/presets/scripts.ts +0 -59
- package/src/resolvers/dependencies.ts +0 -125
- package/src/schemas/package.ts +0 -125
- package/src/utils/conditions.ts +0 -67
- package/src/utils/merge.ts +0 -112
- package/ts-pkg-config.iml +0 -8
- package/tsconfig.json +0 -32
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.1',
|
|
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
|
-
})
|
|
@@ -1,84 +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
|
-
await Bun.write(outputPath, json + '\n')
|
|
83
|
-
console.log(`✨ Generated ${outputPath}`)
|
|
84
|
-
}
|
package/src/main.ts
DELETED
|
@@ -1,68 +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
|
-
}
|
|
64
|
-
|
|
65
|
-
// Run if main module
|
|
66
|
-
if (import.meta.main) {
|
|
67
|
-
main()
|
|
68
|
-
}
|
package/src/presets/scripts.ts
DELETED
|
@@ -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
|
-
}
|
package/src/schemas/package.ts
DELETED
|
@@ -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
|
package/src/utils/conditions.ts
DELETED
|
@@ -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
|
-
}
|