jiek 0.4.6 → 0.4.7-alpha.1
Sign up to get free protection for your applications and to get access to all the features.
- package/README.md +22 -1
- package/bin/jiek.js +2 -1
- package/dist/cli.d.mts +97 -0
- package/dist/cli.d.mts.map +1 -0
- package/dist/cli.d.ts +96 -1
- package/dist/cli.d.ts.map +1 -0
- package/dist/{cli.cjs → cli.js} +355 -231
- package/dist/cli.js.map +1 -0
- package/dist/cli.min.js +1 -0
- package/dist/cli.min.js.map +1 -0
- package/dist/cli.min.mjs +1 -0
- package/dist/cli.min.mjs.map +1 -0
- package/dist/cli.mjs +803 -0
- package/dist/cli.mjs.map +1 -0
- package/dist/index.d.mts +58 -0
- package/dist/index.d.mts.map +1 -0
- package/dist/index.d.ts +47 -46
- package/dist/index.d.ts.map +1 -0
- package/dist/{index.cjs → index.js} +0 -1
- package/dist/index.js.map +1 -0
- package/dist/{index.min.cjs → index.min.js} +0 -1
- package/dist/index.min.js.map +1 -0
- package/dist/index.min.mjs +1 -0
- package/dist/index.min.mjs.map +1 -0
- package/dist/{index.esm.js → index.mjs} +0 -1
- package/dist/index.mjs.map +1 -0
- package/dist/rollup/index.d.mts +53 -0
- package/dist/rollup/index.d.mts.map +1 -0
- package/dist/rollup/index.d.ts +53 -0
- package/dist/rollup/index.d.ts.map +1 -0
- package/dist/rollup/index.js +553 -0
- package/dist/rollup/index.js.map +1 -0
- package/dist/rollup/index.min.js +1 -0
- package/dist/rollup/index.min.js.map +1 -0
- package/dist/rollup/index.min.mjs +1 -0
- package/dist/rollup/index.min.mjs.map +1 -0
- package/dist/rollup/index.mjs +551 -0
- package/dist/rollup/index.mjs.map +1 -0
- package/package.json +52 -35
- package/src/cli.ts +9 -0
- package/src/commands/base.ts +9 -0
- package/src/commands/build.ts +156 -0
- package/src/commands/init.ts +373 -0
- package/src/commands/publish.ts +156 -0
- package/src/index.ts +8 -0
- package/src/inner.ts +11 -0
- package/src/merge-package-json.ts +75 -0
- package/src/pkg.ts +1 -0
- package/src/rollup/base.ts +72 -0
- package/src/rollup/index.ts +420 -0
- package/src/rollup/plugins/globals.ts +34 -0
- package/src/rollup/plugins/progress.ts +26 -0
- package/src/rollup/plugins/skip.ts +23 -0
- package/src/rollup/utils/commonOptions.ts +9 -0
- package/src/rollup/utils/externalResolver.ts +21 -0
- package/src/rollup/utils/globalResolver.ts +13 -0
- package/src/rollup/utils/withMinify.ts +18 -0
- package/src/utils/filterSupport.ts +82 -0
- package/src/utils/getExports.ts +100 -0
- package/src/utils/getRoot.ts +16 -0
- package/src/utils/getWD.ts +31 -0
- package/src/utils/loadConfig.ts +93 -0
- package/src/utils/tsRegister.ts +22 -0
- package/dist/base.esm.d.ts +0 -55
- package/dist/cli.cjs.map +0 -1
- package/dist/cli.esm.d.ts +0 -2
- package/dist/cli.esm.js +0 -9
- package/dist/cli.esm.js.map +0 -1
- package/dist/cli.esm.min.js +0 -2
- package/dist/cli.esm.min.js.map +0 -1
- package/dist/cli.min.cjs +0 -2
- package/dist/cli.min.cjs.map +0 -1
- package/dist/commands/base.esm.js +0 -5
- package/dist/commands/base.esm.js.map +0 -1
- package/dist/commands/base.esm.min.js +0 -2
- package/dist/commands/base.esm.min.js.map +0 -1
- package/dist/commands/build.esm.js +0 -58
- package/dist/commands/build.esm.js.map +0 -1
- package/dist/commands/build.esm.min.js +0 -2
- package/dist/commands/build.esm.min.js.map +0 -1
- package/dist/commands/init.esm.js +0 -271
- package/dist/commands/init.esm.js.map +0 -1
- package/dist/commands/init.esm.min.js +0 -2
- package/dist/commands/init.esm.min.js.map +0 -1
- package/dist/commands/publish.esm.js +0 -87
- package/dist/commands/publish.esm.js.map +0 -1
- package/dist/commands/publish.esm.min.js +0 -2
- package/dist/commands/publish.esm.min.js.map +0 -1
- package/dist/index.cjs.map +0 -1
- package/dist/index.esm.d.ts +0 -6
- package/dist/index.esm.js.map +0 -1
- package/dist/index.esm.min.js +0 -2
- package/dist/index.esm.min.js.map +0 -1
- package/dist/index.min.cjs.map +0 -1
- package/dist/inner.esm.js +0 -10
- package/dist/inner.esm.js.map +0 -1
- package/dist/inner.esm.min.js +0 -2
- package/dist/inner.esm.min.js.map +0 -1
- package/dist/merge-package-json.esm.js +0 -64
- package/dist/merge-package-json.esm.js.map +0 -1
- package/dist/merge-package-json.esm.min.js +0 -2
- package/dist/merge-package-json.esm.min.js.map +0 -1
- package/dist/pkg.esm.js +0 -4
- package/dist/pkg.esm.js.map +0 -1
- package/dist/pkg.esm.min.js +0 -2
- package/dist/pkg.esm.min.js.map +0 -1
- package/dist/rollup/plugins/globals.esm.js +0 -31
- package/dist/rollup/plugins/globals.esm.js.map +0 -1
- package/dist/rollup/plugins/globals.esm.min.js +0 -2
- package/dist/rollup/plugins/globals.esm.min.js.map +0 -1
- package/dist/rollup/plugins/skip.esm.js +0 -16
- package/dist/rollup/plugins/skip.esm.js.map +0 -1
- package/dist/rollup/plugins/skip.esm.min.js +0 -2
- package/dist/rollup/plugins/skip.esm.min.js.map +0 -1
- package/dist/rollup/utils/commonOptions.esm.js +0 -9
- package/dist/rollup/utils/commonOptions.esm.js.map +0 -1
- package/dist/rollup/utils/commonOptions.esm.min.js +0 -2
- package/dist/rollup/utils/commonOptions.esm.min.js.map +0 -1
- package/dist/rollup/utils/externalResolver.esm.js +0 -12
- package/dist/rollup/utils/externalResolver.esm.js.map +0 -1
- package/dist/rollup/utils/externalResolver.esm.min.js +0 -2
- package/dist/rollup/utils/externalResolver.esm.min.js.map +0 -1
- package/dist/rollup/utils/globalResolver.esm.js +0 -9
- package/dist/rollup/utils/globalResolver.esm.js.map +0 -1
- package/dist/rollup/utils/globalResolver.esm.min.js +0 -2
- package/dist/rollup/utils/globalResolver.esm.min.js.map +0 -1
- package/dist/rollup/utils/withMinify.esm.js +0 -15
- package/dist/rollup/utils/withMinify.esm.js.map +0 -1
- package/dist/rollup/utils/withMinify.esm.min.js +0 -2
- package/dist/rollup/utils/withMinify.esm.min.js.map +0 -1
- package/dist/rollup.cjs +0 -330
- package/dist/rollup.cjs.map +0 -1
- package/dist/rollup.d.ts +0 -23
- package/dist/rollup.esm.d.ts +0 -23
- package/dist/rollup.esm.js +0 -248
- package/dist/rollup.esm.js.map +0 -1
- package/dist/rollup.esm.min.js +0 -2
- package/dist/rollup.esm.min.js.map +0 -1
- package/dist/rollup.min.cjs +0 -2
- package/dist/rollup.min.cjs.map +0 -1
- package/dist/utils/commondir.esm.js +0 -25
- package/dist/utils/commondir.esm.js.map +0 -1
- package/dist/utils/commondir.esm.min.js +0 -2
- package/dist/utils/commondir.esm.min.js.map +0 -1
- package/dist/utils/filterSupport.esm.js +0 -67
- package/dist/utils/filterSupport.esm.js.map +0 -1
- package/dist/utils/filterSupport.esm.min.js +0 -2
- package/dist/utils/filterSupport.esm.min.js.map +0 -1
- package/dist/utils/getRoot.esm.js +0 -14
- package/dist/utils/getRoot.esm.js.map +0 -1
- package/dist/utils/getRoot.esm.min.js +0 -2
- package/dist/utils/getRoot.esm.min.js.map +0 -1
- package/dist/utils/getWD.esm.js +0 -31
- package/dist/utils/getWD.esm.js.map +0 -1
- package/dist/utils/getWD.esm.min.js +0 -2
- package/dist/utils/getWD.esm.min.js.map +0 -1
- package/dist/utils/loadConfig.esm.js +0 -75
- package/dist/utils/loadConfig.esm.js.map +0 -1
- package/dist/utils/loadConfig.esm.min.js +0 -2
- package/dist/utils/loadConfig.esm.min.js.map +0 -1
- package/dist/utils/tsRegister.esm.js +0 -24
- package/dist/utils/tsRegister.esm.js.map +0 -1
- package/dist/utils/tsRegister.esm.min.js +0 -2
- package/dist/utils/tsRegister.esm.min.js.map +0 -1
@@ -0,0 +1,156 @@
|
|
1
|
+
import * as childProcess from 'node:child_process'
|
2
|
+
import fs from 'node:fs'
|
3
|
+
import path from 'node:path'
|
4
|
+
|
5
|
+
import { bump, type BumperType } from '@jiek/utils/bumper'
|
6
|
+
import { program } from 'commander'
|
7
|
+
import detectIndent from 'detect-indent'
|
8
|
+
import { applyEdits, modify } from 'jsonc-parser'
|
9
|
+
|
10
|
+
import { actionDone, actionRestore } from '../inner'
|
11
|
+
import { getSelectedProjectsGraph } from '../utils/filterSupport'
|
12
|
+
import { getExports } from '../utils/getExports'
|
13
|
+
import { loadConfig } from '../utils/loadConfig'
|
14
|
+
|
15
|
+
program
|
16
|
+
.command('publish')
|
17
|
+
.aliases(['pub', 'p'])
|
18
|
+
.option('-b, --bumper <bumper>', 'bump version', 'patch')
|
19
|
+
.option('-p, --preview', 'preview publish')
|
20
|
+
.action(async ({ preview, bumper, ...options }: {
|
21
|
+
preview?: boolean
|
22
|
+
bumper: BumperType
|
23
|
+
}) => {
|
24
|
+
actionRestore()
|
25
|
+
|
26
|
+
const { value = {} } = await getSelectedProjectsGraph() ?? {}
|
27
|
+
const selectedProjectsGraphEntries = Object.entries(value)
|
28
|
+
if (selectedProjectsGraphEntries.length === 0) {
|
29
|
+
throw new Error('no packages selected')
|
30
|
+
}
|
31
|
+
const manifests = selectedProjectsGraphEntries
|
32
|
+
.map(([dir, manifest]) => {
|
33
|
+
const { type, exports: entrypoints = {} } = manifest
|
34
|
+
const pkgIsModule = type === 'module'
|
35
|
+
const newManifest = { ...manifest }
|
36
|
+
const [resolvedEntrypoints, exports] = getExports({
|
37
|
+
entrypoints,
|
38
|
+
pkgIsModule,
|
39
|
+
config: loadConfig(dir),
|
40
|
+
dir,
|
41
|
+
noFilter: true,
|
42
|
+
withSource: true,
|
43
|
+
withSuffix: true
|
44
|
+
})
|
45
|
+
newManifest.exports = {
|
46
|
+
...resolvedEntrypoints,
|
47
|
+
...exports
|
48
|
+
}
|
49
|
+
return [dir, newManifest] as const
|
50
|
+
})
|
51
|
+
const passArgs = Object
|
52
|
+
.entries(options)
|
53
|
+
.reduce((acc, [key, value]) => {
|
54
|
+
if (value) {
|
55
|
+
acc.push(`--${key}`, value as string)
|
56
|
+
}
|
57
|
+
return acc
|
58
|
+
}, [] as string[])
|
59
|
+
for (const [dir, manifest] of manifests) {
|
60
|
+
const oldJSONString = fs.readFileSync(path.join(dir, 'package.json'), 'utf-8')
|
61
|
+
const oldJSON = JSON.parse(oldJSONString) ?? '0.0.0'
|
62
|
+
const newVersion = bump(oldJSON.version, bumper)
|
63
|
+
// TODO detectIndent by editorconfig
|
64
|
+
const { indent = ' ' } = detectIndent(oldJSONString)
|
65
|
+
const formattingOptions = {
|
66
|
+
tabSize: indent.length,
|
67
|
+
insertSpaces: true
|
68
|
+
}
|
69
|
+
let newJSONString = oldJSONString
|
70
|
+
newJSONString = applyEdits(
|
71
|
+
newJSONString,
|
72
|
+
modify(
|
73
|
+
newJSONString,
|
74
|
+
['version'],
|
75
|
+
newVersion,
|
76
|
+
{ formattingOptions }
|
77
|
+
)
|
78
|
+
)
|
79
|
+
for (const [key, value] of Object.entries(manifest)) {
|
80
|
+
if (JSON.stringify(value) === JSON.stringify(oldJSON[key])) continue
|
81
|
+
|
82
|
+
if (key !== 'exports') {
|
83
|
+
newJSONString = applyEdits(
|
84
|
+
newJSONString,
|
85
|
+
modify(
|
86
|
+
newJSONString,
|
87
|
+
['publishConfig', key],
|
88
|
+
value,
|
89
|
+
{ formattingOptions }
|
90
|
+
)
|
91
|
+
)
|
92
|
+
} else {
|
93
|
+
const exports = value as Record<string, unknown>
|
94
|
+
for (const [k, v] of Object.entries(exports)) {
|
95
|
+
newJSONString = applyEdits(
|
96
|
+
newJSONString,
|
97
|
+
modify(
|
98
|
+
newJSONString,
|
99
|
+
['publishConfig', 'exports', k],
|
100
|
+
v,
|
101
|
+
{ formattingOptions }
|
102
|
+
)
|
103
|
+
)
|
104
|
+
}
|
105
|
+
const index = exports?.['.']
|
106
|
+
const indexPublishConfig: Record<string, string> = {}
|
107
|
+
if (index) {
|
108
|
+
switch (typeof index) {
|
109
|
+
case 'string':
|
110
|
+
indexPublishConfig[
|
111
|
+
manifest?.type === 'module' ? 'module' : 'main'
|
112
|
+
] = index
|
113
|
+
break
|
114
|
+
case 'object': {
|
115
|
+
const indexExports = index as Record<string, string>
|
116
|
+
indexPublishConfig.main = indexExports['require'] ?? indexExports['default']
|
117
|
+
indexPublishConfig.module = indexExports['import'] ?? indexExports['module'] ?? indexExports['default']
|
118
|
+
break
|
119
|
+
}
|
120
|
+
}
|
121
|
+
for (const [k, v] of Object.entries(indexPublishConfig)) {
|
122
|
+
if (v === undefined) continue
|
123
|
+
newJSONString = applyEdits(
|
124
|
+
newJSONString,
|
125
|
+
modify(
|
126
|
+
newJSONString,
|
127
|
+
['publishConfig', k],
|
128
|
+
v,
|
129
|
+
{ formattingOptions }
|
130
|
+
)
|
131
|
+
)
|
132
|
+
}
|
133
|
+
}
|
134
|
+
}
|
135
|
+
}
|
136
|
+
try {
|
137
|
+
fs.renameSync(path.join(dir, 'package.json'), path.join(dir, 'package.json.bak'))
|
138
|
+
fs.writeFileSync(path.join(dir, 'package.json'), newJSONString)
|
139
|
+
console.log(newJSONString)
|
140
|
+
if (preview) {
|
141
|
+
console.warn('preview mode')
|
142
|
+
continue
|
143
|
+
}
|
144
|
+
childProcess.execSync(['pnpm', 'publish', '--access', 'public', '--no-git-checks', ...passArgs].join(' '), {
|
145
|
+
cwd: dir,
|
146
|
+
stdio: 'inherit'
|
147
|
+
})
|
148
|
+
const modifyVersionPackageJSON = applyEdits(oldJSONString, modify(oldJSONString, ['version'], newVersion, {}))
|
149
|
+
fs.writeFileSync(path.join(dir, 'package.json.bak'), modifyVersionPackageJSON)
|
150
|
+
} finally {
|
151
|
+
fs.unlinkSync(path.join(dir, 'package.json'))
|
152
|
+
fs.renameSync(path.join(dir, 'package.json.bak'), path.join(dir, 'package.json'))
|
153
|
+
}
|
154
|
+
}
|
155
|
+
actionDone()
|
156
|
+
})
|
package/src/index.ts
ADDED
package/src/inner.ts
ADDED
@@ -0,0 +1,75 @@
|
|
1
|
+
import path from 'node:path'
|
2
|
+
|
3
|
+
import { type Options, pkger } from '@jiek/pkger'
|
4
|
+
import { commondir } from '@jiek/utils/commondir'
|
5
|
+
import type { Manifest } from '@pnpm/workspace.pkgs-graph'
|
6
|
+
|
7
|
+
export function mergePackageJson(manifest: Manifest & {
|
8
|
+
jiek?: Options
|
9
|
+
exports?: unknown | unknown[]
|
10
|
+
}, cwd: string, options: {
|
11
|
+
excludeDistInExports?: boolean
|
12
|
+
} = {}) {
|
13
|
+
const {
|
14
|
+
excludeDistInExports = false
|
15
|
+
} = options
|
16
|
+
const {
|
17
|
+
jiek: { cwd: _, ...jiek } = {}
|
18
|
+
} = manifest
|
19
|
+
const { outdir = 'dist' } = jiek
|
20
|
+
let { exports } = manifest
|
21
|
+
let includeIndex = false
|
22
|
+
if (typeof exports === 'string') {
|
23
|
+
includeIndex = true
|
24
|
+
exports = { '.': exports }
|
25
|
+
}
|
26
|
+
if (exports === undefined) {
|
27
|
+
exports = { '.': './src/index.ts' }
|
28
|
+
}
|
29
|
+
if (typeof exports === 'object') {
|
30
|
+
if (Array.isArray(exports) && exports.length > 0) {
|
31
|
+
includeIndex = true
|
32
|
+
} else {
|
33
|
+
includeIndex = !!(<Record<string, unknown>>exports)['.']
|
34
|
+
}
|
35
|
+
}
|
36
|
+
let inputs = Array.isArray(exports)
|
37
|
+
? exports as string[]
|
38
|
+
: Object
|
39
|
+
.entries(<Record<string, unknown>>exports)
|
40
|
+
.reduce((acc, [key, value]) => {
|
41
|
+
if (typeof value === 'string') return key === '.'
|
42
|
+
? [value, ...acc]
|
43
|
+
: acc.concat(value)
|
44
|
+
if (Array.isArray(value)) return acc.concat(value)
|
45
|
+
|
46
|
+
throw new TypeError(`Unexpected value type for key "${key}" in exports, expected string, got ${typeof value}`)
|
47
|
+
}, [] as string[])
|
48
|
+
if (excludeDistInExports) {
|
49
|
+
inputs = inputs.filter(input => !input.startsWith(`./${outdir}`) && !input.startsWith(outdir))
|
50
|
+
}
|
51
|
+
if (inputs.length === 0)
|
52
|
+
throw new Error('No inputs found')
|
53
|
+
|
54
|
+
const absoluteInputs = inputs.map(input => path.isAbsolute(input)
|
55
|
+
? input
|
56
|
+
: path.resolve(cwd, input)
|
57
|
+
)
|
58
|
+
let cDir = path.dirname(absoluteInputs[0])
|
59
|
+
if (absoluteInputs.length > 1) {
|
60
|
+
cDir = commondir(absoluteInputs, cwd)
|
61
|
+
}
|
62
|
+
const resolvedInputs = absoluteInputs.map(input => {
|
63
|
+
return path.relative(cDir, input)
|
64
|
+
})
|
65
|
+
return {
|
66
|
+
...manifest,
|
67
|
+
...pkger({
|
68
|
+
cwd,
|
69
|
+
noIndex: !includeIndex,
|
70
|
+
source: path.relative(cwd, cDir),
|
71
|
+
inputs: resolvedInputs,
|
72
|
+
...jiek
|
73
|
+
})
|
74
|
+
}
|
75
|
+
}
|
package/src/pkg.ts
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
export default require('../package.json')
|
@@ -0,0 +1,72 @@
|
|
1
|
+
import type { OutputOptions } from 'rollup'
|
2
|
+
|
3
|
+
export type Mapping2ROO<K extends keyof OutputOptions> = OutputOptions[K] | {
|
4
|
+
js?: OutputOptions[K]
|
5
|
+
dts?: OutputOptions[K]
|
6
|
+
}
|
7
|
+
|
8
|
+
export interface TemplateOptions {
|
9
|
+
/**
|
10
|
+
* When the user configures type: module, the generated output from entry points that don't
|
11
|
+
* have cts as a suffix will automatically include the CJS version.
|
12
|
+
* if it is not configured, and the generated output from entry points that do not have mts
|
13
|
+
* as a suffix will automatically include the ESM version.
|
14
|
+
*
|
15
|
+
* @default true
|
16
|
+
*/
|
17
|
+
crossModuleConvertor?: boolean
|
18
|
+
output?: {
|
19
|
+
/**
|
20
|
+
* @default true
|
21
|
+
*
|
22
|
+
* When minify is set to true, the output will with minified files.
|
23
|
+
* When minify is set to 'only-minify', the output will direct output minified files.
|
24
|
+
*/
|
25
|
+
minify?: boolean | 'only-minify'
|
26
|
+
/**
|
27
|
+
* @default 'dist'
|
28
|
+
*/
|
29
|
+
dir?: Mapping2ROO<'dir'>
|
30
|
+
sourcemap?: Mapping2ROO<'sourcemap'>
|
31
|
+
strict?: Mapping2ROO<'strict'>
|
32
|
+
}
|
33
|
+
}
|
34
|
+
|
35
|
+
export type RollupProgressEvent =
|
36
|
+
| {
|
37
|
+
type: 'init'
|
38
|
+
data: {
|
39
|
+
leafMap: Map<string, string[][]>
|
40
|
+
targetsLength: number
|
41
|
+
}
|
42
|
+
}
|
43
|
+
| {
|
44
|
+
type: 'debug'
|
45
|
+
data: unknown
|
46
|
+
}
|
47
|
+
| {
|
48
|
+
type: 'progress'
|
49
|
+
data: {
|
50
|
+
// name, path, exportConditions, input
|
51
|
+
name: string
|
52
|
+
path: string
|
53
|
+
exportConditions: string[]
|
54
|
+
input: string
|
55
|
+
tags?: string[]
|
56
|
+
event?: string
|
57
|
+
message?: string
|
58
|
+
}
|
59
|
+
}
|
60
|
+
|
61
|
+
declare module 'jiek' {
|
62
|
+
export interface Config {
|
63
|
+
build?: TemplateOptions & {
|
64
|
+
/**
|
65
|
+
* Whether to run in silent mode, only active when configured in the workspace root or cwd.
|
66
|
+
*
|
67
|
+
* @default false
|
68
|
+
*/
|
69
|
+
silent?: boolean
|
70
|
+
}
|
71
|
+
}
|
72
|
+
}
|