jiek 2.2.6 → 2.2.7-alpha.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/bin/build.cjs +2 -0
- package/bin/index.cjs +2 -0
- package/bin-helper/index.cjs +31 -0
- package/bin-helper/index.d.cts +1 -0
- package/bin-helper/index.d.ts +1 -0
- package/bin-helper/package.json +5 -1
- package/dist/.internal/.chunks/getWD.D6wq8Qc2.js +95 -0
- package/dist/.internal/.chunks/getWD.ZF0avqDB.cjs +105 -0
- package/dist/{cli.js → .internal/.chunks/index.B6RQz1DZ.js} +1 -735
- package/dist/{cli.cjs → .internal/.chunks/index.DlHFuTjM.cjs} +1 -757
- package/dist/.internal/.chunks/jiek_create-require.CWFWNQHj.cjs +5 -0
- package/dist/.internal/.chunks/jiek_create-require.CxSGbkTB.js +5 -0
- package/dist/.internal/bin/parseArgv.cjs +33 -0
- package/dist/.internal/bin/parseArgv.d.cts +5 -0
- package/dist/.internal/bin/parseArgv.d.ts +5 -0
- package/dist/.internal/bin/parseArgv.js +27 -0
- package/dist/.internal/bridge.cjs +12 -0
- package/dist/.internal/bridge.d.cts +39 -0
- package/dist/.internal/bridge.d.ts +39 -0
- package/dist/.internal/bridge.js +9 -0
- package/dist/.internal/commands/build/analyzer.cjs +201 -0
- package/dist/.internal/commands/build/analyzer.d.cts +30 -0
- package/dist/.internal/commands/build/analyzer.d.ts +30 -0
- package/dist/.internal/commands/build/analyzer.js +195 -0
- package/dist/.internal/commands/descriptions.cjs +21 -0
- package/dist/.internal/commands/descriptions.d.cts +5 -0
- package/dist/.internal/commands/descriptions.d.ts +5 -0
- package/dist/.internal/commands/descriptions.js +17 -0
- package/dist/.internal/commands/meta.cjs +16 -0
- package/dist/.internal/commands/meta.d.cts +3 -0
- package/dist/.internal/commands/meta.d.ts +3 -0
- package/dist/.internal/commands/meta.js +15 -0
- package/dist/.internal/commands/utils/optionParser.cjs +8 -0
- package/dist/.internal/commands/utils/optionParser.d.cts +3 -0
- package/dist/.internal/commands/utils/optionParser.d.ts +3 -0
- package/dist/.internal/commands/utils/optionParser.js +6 -0
- package/dist/.internal/rollup/base.cjs +10 -0
- package/dist/{cli-only-build.d.cts → .internal/rollup/base.d.cts} +8 -15
- package/dist/{cli-only-build.d.ts → .internal/rollup/base.d.ts} +8 -15
- package/dist/.internal/rollup/base.js +7 -0
- package/dist/.internal/rollup/bundle-analyzer.cjs +51 -0
- package/dist/.internal/rollup/bundle-analyzer.d.cts +92 -0
- package/dist/.internal/rollup/bundle-analyzer.d.ts +92 -0
- package/dist/.internal/rollup/bundle-analyzer.js +45 -0
- package/dist/.internal/server.cjs +33 -0
- package/dist/.internal/server.d.cts +8 -0
- package/dist/.internal/server.d.ts +8 -0
- package/dist/.internal/server.js +27 -0
- package/dist/.internal/utils/checkDependency.cjs +39 -0
- package/dist/.internal/utils/checkDependency.d.cts +3 -0
- package/dist/.internal/utils/checkDependency.d.ts +3 -0
- package/dist/.internal/utils/checkDependency.js +34 -0
- package/dist/.internal/utils/filterSupport.cjs +20 -0
- package/dist/.internal/utils/filterSupport.d.cts +15 -0
- package/dist/.internal/utils/filterSupport.d.ts +15 -0
- package/dist/.internal/utils/filterSupport.js +10 -0
- package/dist/.internal/utils/getInternalModuleName.cjs +5 -0
- package/dist/.internal/utils/getInternalModuleName.d.cts +3 -0
- package/dist/.internal/utils/getInternalModuleName.d.ts +3 -0
- package/dist/.internal/utils/getInternalModuleName.js +3 -0
- package/dist/.internal/utils/getRoot.cjs +17 -0
- package/dist/.internal/utils/getRoot.d.cts +3 -0
- package/dist/.internal/utils/getRoot.d.ts +3 -0
- package/dist/.internal/utils/getRoot.js +11 -0
- package/dist/.internal/utils/getWD.cjs +15 -0
- package/dist/.internal/utils/getWD.d.cts +6 -0
- package/dist/.internal/utils/getWD.d.ts +6 -0
- package/dist/.internal/utils/getWD.js +10 -0
- package/dist/.internal/utils/intersection.cjs +5 -0
- package/dist/.internal/utils/intersection.d.cts +3 -0
- package/dist/.internal/utils/intersection.d.ts +3 -0
- package/dist/.internal/utils/intersection.js +3 -0
- package/dist/.internal/utils/loadConfig.cjs +100 -0
- package/dist/.internal/utils/loadConfig.d.cts +10 -0
- package/dist/.internal/utils/loadConfig.d.ts +10 -0
- package/dist/.internal/utils/loadConfig.js +94 -0
- package/dist/.internal/utils/recursiveListFiles.cjs +19 -0
- package/dist/.internal/utils/recursiveListFiles.d.cts +3 -0
- package/dist/.internal/utils/recursiveListFiles.d.ts +3 -0
- package/dist/.internal/utils/recursiveListFiles.js +13 -0
- package/dist/.internal/utils/resolveExports.cjs +118 -0
- package/dist/.internal/utils/resolveExports.d.cts +26 -0
- package/dist/.internal/utils/resolveExports.d.ts +26 -0
- package/dist/.internal/utils/resolveExports.js +111 -0
- package/dist/.internal/utils/ts.cjs +68 -0
- package/dist/.internal/utils/ts.d.cts +3 -0
- package/dist/.internal/utils/ts.d.ts +3 -0
- package/dist/.internal/utils/ts.js +62 -0
- package/dist/.internal/utils/tsRegister.cjs +25 -0
- package/dist/.internal/utils/tsRegister.d.cts +3 -0
- package/dist/.internal/utils/tsRegister.d.ts +3 -0
- package/dist/.internal/utils/tsRegister.js +26 -0
- package/dist/bin/build.cjs +515 -0
- package/dist/bin/index.cjs +497 -0
- package/dist/index.d.cts +12 -114
- package/dist/index.d.ts +12 -114
- package/dist/rollup/index.cjs +280 -4573
- package/dist/rollup/index.d.cts +7 -1
- package/dist/rollup/index.d.ts +7 -1
- package/dist/rollup/index.js +268 -4558
- package/package.json +20 -26
- package/src/bin/build.cts +11 -0
- package/src/bin/index.cts +6 -0
- package/src/bridge.ts +1 -1
- package/src/commands/base.ts +3 -3
- package/src/commands/build/analyzer.ts +5 -5
- package/src/commands/build/client/analyzer.tsx +1 -1
- package/src/commands/build/client/index.ts +5 -7
- package/src/commands/build.ts +226 -211
- package/src/commands/meta.ts +1 -1
- package/src/commands/publish.ts +112 -32
- package/src/index.ts +6 -1
- package/src/rollup/base.ts +2 -2
- package/src/rollup/index.ts +321 -124
- package/src/rollup/plugins/with-external.ts +23 -0
- package/src/rollup/utils/externalResolver.ts +20 -8
- package/src/utils/checkDependency.ts +1 -1
- package/src/utils/filterSupport.ts +17 -16
- package/src/utils/getInternalModuleName.ts +5 -0
- package/src/utils/intersection.ts +1 -0
- package/src/utils/{recusiveListFiles.ts → recursiveListFiles.ts} +2 -2
- package/src/utils/{getExports.ts → resolveExports.ts} +16 -14
- package/bin/jiek-build.js +0 -16
- package/bin/jiek.js +0 -13
- package/bin-helper.cjs +0 -43
- package/cli/package.json +0 -1
- package/cli-only-build/package.json +0 -1
- package/dist/cli-only-build.cjs +0 -977
- package/dist/cli-only-build.js +0 -969
- package/dist/cli.d.cts +0 -14
- package/dist/cli.d.ts +0 -14
- package/src/bin/build.ts +0 -0
- package/src/cli-only-build.ts +0 -11
- package/src/cli.ts +0 -6
- /package/{bin-helper.js → bin-helper/index.js} +0 -0
- /package/src/{parseArgv.ts → bin/parseArgv.ts} +0 -0
package/src/commands/publish.ts
CHANGED
@@ -7,15 +7,27 @@ import process from 'node:process'
|
|
7
7
|
import { type BumperType, TAGS, bump } from '@jiek/utils/bumper'
|
8
8
|
import { program } from 'commander'
|
9
9
|
import detectIndent from 'detect-indent'
|
10
|
+
import type { Config } from 'jiek'
|
11
|
+
import type { JSONPath } from 'jsonc-parser'
|
10
12
|
import { applyEdits, modify } from 'jsonc-parser'
|
11
13
|
|
12
|
-
import type { ProjectsGraph } from '
|
13
|
-
import { getSelectedProjectsGraph } from '
|
14
|
-
import {
|
15
|
-
import {
|
14
|
+
import type { ProjectsGraph } from '#~/utils/filterSupport'
|
15
|
+
import { getSelectedProjectsGraph } from '#~/utils/filterSupport'
|
16
|
+
import { loadConfig } from '#~/utils/loadConfig'
|
17
|
+
import type { ResolveExportsOptions } from '#~/utils/resolveExports'
|
18
|
+
import { resolveExports } from '#~/utils/resolveExports'
|
19
|
+
|
20
|
+
import { getInternalModuleName } from '#~/utils/getInternalModuleName'
|
16
21
|
import { outdirDescription } from './descriptions'
|
17
22
|
|
18
23
|
declare module 'jiek' {
|
24
|
+
interface ConfigExperimental {
|
25
|
+
/**
|
26
|
+
* Polyfill `imports` fields in package.json to local dependencies and exports fields.
|
27
|
+
* @default false
|
28
|
+
*/
|
29
|
+
importsDowngrade?: boolean
|
30
|
+
}
|
19
31
|
export interface Config {
|
20
32
|
publish?: {
|
21
33
|
/**
|
@@ -107,37 +119,71 @@ async function prepublish({ bumper }: {
|
|
107
119
|
bumperEnv ? JSON.parse(bumperEnv) as string | boolean : false
|
108
120
|
)
|
109
121
|
|
110
|
-
const generateNewManifest = (
|
111
|
-
|
122
|
+
const generateNewManifest = (
|
123
|
+
dir: string,
|
124
|
+
manifest: NonNullable<ProjectsGraph['value']>[string],
|
125
|
+
config: Config
|
126
|
+
) => {
|
127
|
+
const {
|
128
|
+
name,
|
129
|
+
type,
|
130
|
+
exports: entrypoints,
|
131
|
+
imports: internalEntrypoints
|
132
|
+
} = manifest
|
112
133
|
if (!name) {
|
113
134
|
throw new Error(`package.json in ${dir} must have a name field`)
|
114
135
|
}
|
115
136
|
|
116
137
|
const pkgIsModule = type === 'module'
|
117
138
|
const newManifest = { ...manifest }
|
118
|
-
const
|
119
|
-
entrypoints,
|
139
|
+
const commonOptions = {
|
120
140
|
pkgIsModule,
|
121
141
|
pkgName: name,
|
122
|
-
config
|
142
|
+
config,
|
123
143
|
dir,
|
124
|
-
defaultOutdir: outdir,
|
125
144
|
noFilter: true,
|
126
145
|
isPublish: true
|
127
|
-
}
|
128
|
-
|
129
|
-
|
130
|
-
|
146
|
+
} satisfies Partial<ResolveExportsOptions>
|
147
|
+
let resolvedOutdir = outdir
|
148
|
+
if (entrypoints) {
|
149
|
+
const [resolvedEntrypoints, exports, _resolvedOutdir] = resolveExports({
|
150
|
+
entrypoints,
|
151
|
+
defaultOutdir: outdir,
|
152
|
+
...commonOptions
|
153
|
+
})
|
154
|
+
newManifest.exports = {
|
155
|
+
...resolvedEntrypoints,
|
156
|
+
...exports
|
157
|
+
}
|
158
|
+
if (resolvedOutdir === outdir) {
|
159
|
+
resolvedOutdir = _resolvedOutdir
|
160
|
+
}
|
161
|
+
}
|
162
|
+
if (internalEntrypoints) {
|
163
|
+
const [resolvedInternalEntrypoints, imports, _resolvedOutdir] = resolveExports({
|
164
|
+
entrypoints: internalEntrypoints,
|
165
|
+
defaultOutdir: `${outdir}/.internal`,
|
166
|
+
...commonOptions
|
167
|
+
})
|
168
|
+
newManifest.imports = {
|
169
|
+
...resolvedInternalEntrypoints,
|
170
|
+
...imports
|
171
|
+
}
|
172
|
+
if (resolvedOutdir === outdir) {
|
173
|
+
resolvedOutdir = _resolvedOutdir
|
174
|
+
}
|
131
175
|
}
|
132
176
|
return [newManifest, resolvedOutdir] as const
|
133
177
|
}
|
134
178
|
|
135
179
|
const generateNewPackageJSONString = ({
|
180
|
+
config,
|
136
181
|
oldJSONString,
|
137
182
|
oldJSON,
|
138
183
|
manifest,
|
139
184
|
formattingOptions
|
140
185
|
}: {
|
186
|
+
config: Config
|
141
187
|
oldJSONString: string
|
142
188
|
oldJSON: Record<string, unknown>
|
143
189
|
manifest: NonNullable<ProjectsGraph['value']>[string]
|
@@ -146,26 +192,35 @@ async function prepublish({ bumper }: {
|
|
146
192
|
insertSpaces: boolean
|
147
193
|
}
|
148
194
|
}) => {
|
195
|
+
const internalModuleName = getInternalModuleName(manifest.name!)
|
196
|
+
|
149
197
|
let newJSONString = oldJSONString
|
150
|
-
|
151
|
-
newJSONString
|
152
|
-
modify(
|
198
|
+
const update = (path: JSONPath, value: unknown) => {
|
199
|
+
newJSONString = applyEdits(
|
153
200
|
newJSONString,
|
154
|
-
|
155
|
-
{
|
156
|
-
'<5.0': {
|
157
|
-
'*': [
|
158
|
-
'*',
|
159
|
-
`./*`,
|
160
|
-
`./*/index.d.ts`,
|
161
|
-
`./*/index.d.mts`,
|
162
|
-
`./*/index.d.cts`
|
163
|
-
]
|
164
|
-
}
|
165
|
-
},
|
166
|
-
{ formattingOptions }
|
201
|
+
modify(newJSONString, path, value, { formattingOptions })
|
167
202
|
)
|
168
|
-
|
203
|
+
}
|
204
|
+
|
205
|
+
update(['publishConfig', 'typesVersions'], {
|
206
|
+
'<5.0': {
|
207
|
+
'*': [
|
208
|
+
'*',
|
209
|
+
'./*',
|
210
|
+
'./*/index.d.ts',
|
211
|
+
'./*/index.d.mts',
|
212
|
+
'./*/index.d.cts'
|
213
|
+
]
|
214
|
+
}
|
215
|
+
})
|
216
|
+
if (config.experimental?.importsDowngrade) {
|
217
|
+
update(['dependencies', internalModuleName], `file:./${outdir}/.internal`)
|
218
|
+
update(['dependenciesMeta', internalModuleName], {
|
219
|
+
'injected': true
|
220
|
+
})
|
221
|
+
update(['imports'], undefined)
|
222
|
+
}
|
223
|
+
|
169
224
|
for (const [key, value] of Object.entries(manifest)) {
|
170
225
|
if (key === 'version') continue
|
171
226
|
if (JSON.stringify(value) === JSON.stringify(oldJSON[key])) continue
|
@@ -207,9 +262,13 @@ async function prepublish({ bumper }: {
|
|
207
262
|
const indexExports = index as Record<string, string>
|
208
263
|
indexPublishConfig.main = indexExports.require ?? indexExports.default
|
209
264
|
indexPublishConfig.module = indexExports.import ?? indexExports.module ?? indexExports.default
|
265
|
+
indexPublishConfig.types = indexExports.types
|
210
266
|
break
|
211
267
|
}
|
212
268
|
}
|
269
|
+
indexPublishConfig.types = indexPublishConfig[
|
270
|
+
manifest?.type === 'module' ? 'module' : 'main'
|
271
|
+
].replace(/\.([cm]?)js$/, '.d.$1ts')
|
213
272
|
for (const [k, v] of Object.entries(indexPublishConfig)) {
|
214
273
|
if (v === undefined) continue
|
215
274
|
newJSONString = applyEdits(
|
@@ -269,7 +328,8 @@ async function prepublish({ bumper }: {
|
|
269
328
|
}
|
270
329
|
|
271
330
|
await forEachSelectedProjectsGraphEntries((dir, originalManifest) => {
|
272
|
-
const
|
331
|
+
const config = loadConfig(dir)
|
332
|
+
const [manifest, resolvedOutdir] = generateNewManifest(dir, originalManifest, config)
|
273
333
|
const resolveByDir = (...paths: string[]) => path.resolve(dir, ...paths)
|
274
334
|
|
275
335
|
const oldJSONString = fs.readFileSync(resolveByDir('package.json'), 'utf-8')
|
@@ -294,6 +354,7 @@ async function prepublish({ bumper }: {
|
|
294
354
|
)
|
295
355
|
|
296
356
|
const newJSONString = generateNewPackageJSONString({
|
357
|
+
config,
|
297
358
|
oldJSONString: modifyVersionPackageJSON,
|
298
359
|
oldJSON: {
|
299
360
|
...oldJSON,
|
@@ -434,6 +495,25 @@ async function prepublish({ bumper }: {
|
|
434
495
|
}
|
435
496
|
throw new Error(`file type of ${path} is not supported`)
|
436
497
|
}
|
498
|
+
|
499
|
+
if (config.experimental?.importsDowngrade && 'imports' in manifest && manifest.imports) {
|
500
|
+
fs.writeFileSync(
|
501
|
+
resolveByDir(resolvedOutdir, resolvedOutdir, '.internal', 'package.json'),
|
502
|
+
JSON.stringify(
|
503
|
+
{
|
504
|
+
name: getInternalModuleName(manifest.name!),
|
505
|
+
exports: JSON.parse(
|
506
|
+
JSON
|
507
|
+
.stringify(manifest.imports)
|
508
|
+
.replaceAll('#', './')
|
509
|
+
.replaceAll('~', '')
|
510
|
+
) as Record<string, unknown>
|
511
|
+
},
|
512
|
+
null,
|
513
|
+
2
|
514
|
+
)
|
515
|
+
)
|
516
|
+
}
|
437
517
|
})
|
438
518
|
}
|
439
519
|
|
package/src/index.ts
CHANGED
@@ -2,6 +2,11 @@ import type {} from './commands/base'
|
|
2
2
|
import type {} from './commands/build'
|
3
3
|
import type {} from './commands/publish'
|
4
4
|
|
5
|
-
export interface
|
5
|
+
export interface ConfigExperimental {
|
6
|
+
}
|
7
|
+
|
8
|
+
export interface Config {
|
9
|
+
experimental?: ConfigExperimental
|
10
|
+
}
|
6
11
|
|
7
12
|
export const defineConfig = (config: Config) => config
|
package/src/rollup/base.ts
CHANGED
@@ -54,9 +54,9 @@ export interface TemplateOptions {
|
|
54
54
|
* When use esbuild type builder, it will inject `supported.import-attributes` option.
|
55
55
|
* When use swc type builder, it will inject `jsc.experimental.keepImportAttributes` option.
|
56
56
|
*
|
57
|
-
* And it will auto set the rollup output externalImportAttributes and importAttributesKey options.
|
57
|
+
* And it will auto set the rollup output `externalImportAttributes` and `importAttributesKey` options.
|
58
58
|
*
|
59
|
-
* @default
|
59
|
+
* @default false
|
60
60
|
*/
|
61
61
|
keepImportAttributes?: boolean | 'assert'
|
62
62
|
}
|