jiek 2.3.2 → 2.3.4
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/.internal/.chunks/{filterSupport.4rM7f6jB.cjs → getWD.Bdo2NGCR.cjs} +30 -30
- package/dist/.internal/.chunks/{filterSupport.BXWpLBpT.js → getWD.DGvwAHMY.js} +29 -29
- package/dist/.internal/.chunks/{loadConfig.OOKddvHF.cjs → loadConfig.8xhNFEJe.cjs} +30 -12
- package/dist/.internal/.chunks/{loadConfig.CFfzkm_p.js → loadConfig.BjzxLOdC.js} +26 -9
- package/dist/.internal/bin/common.cjs +92 -97
- package/dist/.internal/bin/common.d.cts +2 -0
- package/dist/.internal/bin/common.d.ts +2 -0
- package/dist/.internal/bin/common.js +93 -98
- package/dist/.internal/bin/parseArgv.cjs +2 -2
- package/dist/.internal/bin/parseArgv.js +2 -2
- package/dist/.internal/commands/utils/createAreaManagement.cjs +108 -0
- package/dist/.internal/commands/utils/createAreaManagement.d.cts +18 -0
- package/dist/.internal/commands/utils/createAreaManagement.d.ts +18 -0
- package/dist/.internal/commands/utils/createAreaManagement.js +106 -0
- package/dist/.internal/polyfill.cjs +13 -0
- package/dist/.internal/polyfill.d.cts +1 -0
- package/dist/.internal/polyfill.d.ts +1 -0
- package/dist/.internal/polyfill.js +11 -0
- package/dist/.internal/rollup/base.d.cts +27 -4
- package/dist/.internal/rollup/base.d.ts +27 -4
- package/dist/.internal/utils/filterSupport.cjs +1 -1
- package/dist/.internal/utils/filterSupport.js +2 -2
- package/dist/.internal/utils/loadConfig.cjs +3 -3
- package/dist/.internal/utils/loadConfig.d.cts +1 -0
- package/dist/.internal/utils/loadConfig.d.ts +1 -0
- package/dist/.internal/utils/loadConfig.js +4 -4
- package/dist/.internal/utils/pascalCase.cjs +5 -0
- package/dist/.internal/utils/pascalCase.d.cts +3 -0
- package/dist/.internal/utils/pascalCase.d.ts +3 -0
- package/dist/.internal/utils/pascalCase.js +3 -0
- package/dist/.internal/utils/reveal.cjs +9 -0
- package/dist/.internal/utils/reveal.d.cts +3 -0
- package/dist/.internal/utils/reveal.d.ts +3 -0
- package/dist/.internal/utils/reveal.js +7 -0
- package/dist/bin/index.cjs +101 -43
- package/dist/index.d.cts +7 -0
- package/dist/index.d.ts +7 -0
- package/dist/rollup/index.cjs +91 -31
- package/dist/rollup/index.js +90 -30
- package/package.json +6 -2
- package/src/bin/build.cts +0 -5
- package/src/bin/common.ts +0 -3
- package/src/bin/index.cts +0 -7
- package/src/bin/parseArgv.ts +0 -26
- package/src/bridge.ts +0 -46
- package/src/commands/base.ts +0 -18
- package/src/commands/build/analyzer.ts +0 -122
- package/src/commands/build/client/analyzer.tsx +0 -121
- package/src/commands/build/client/index.ts +0 -26
- package/src/commands/build.ts +0 -544
- package/src/commands/descriptions.ts +0 -17
- package/src/commands/meta.ts +0 -5
- package/src/commands/publish.ts +0 -628
- package/src/commands/utils/optionParser.ts +0 -4
- package/src/index.ts +0 -12
- package/src/inner.ts +0 -11
- package/src/rollup/base.ts +0 -151
- package/src/rollup/bundle-analyzer.ts +0 -62
- package/src/rollup/index.ts +0 -892
- package/src/rollup/plugins/create-require.ts +0 -23
- package/src/rollup/plugins/progress.ts +0 -26
- package/src/rollup/plugins/replace.ts +0 -96
- package/src/rollup/plugins/skip.ts +0 -21
- package/src/rollup/plugins/with-external.ts +0 -23
- package/src/rollup/utils/commonOptions.ts +0 -9
- package/src/rollup/utils/externalResolver.ts +0 -47
- package/src/rollup/utils/globalResolver.ts +0 -13
- package/src/rollup/utils/withMinify.ts +0 -18
- package/src/rollup-plugin-utils.ts +0 -32
- package/src/server.ts +0 -30
- package/src/utils/checkDependency.ts +0 -26
- package/src/utils/filterSupport.ts +0 -90
- package/src/utils/getInternalModuleName.ts +0 -5
- package/src/utils/getRoot.ts +0 -14
- package/src/utils/getWD.ts +0 -31
- package/src/utils/intersection.ts +0 -1
- package/src/utils/loadConfig.ts +0 -108
- package/src/utils/recursiveListFiles.ts +0 -13
- package/src/utils/resolveExports.ts +0 -165
- package/src/utils/ts.ts +0 -94
- package/src/utils/tsRegister.ts +0 -22
package/src/commands/publish.ts
DELETED
@@ -1,628 +0,0 @@
|
|
1
|
-
/* eslint-disable ts/strict-boolean-expressions */
|
2
|
-
import * as childProcess from 'node:child_process'
|
3
|
-
import fs from 'node:fs'
|
4
|
-
import path from 'node:path'
|
5
|
-
import process from 'node:process'
|
6
|
-
|
7
|
-
import { type BumperType, TAGS, bump } from '@jiek/utils/bumper'
|
8
|
-
import { type Command, program } from 'commander'
|
9
|
-
import detectIndent from 'detect-indent'
|
10
|
-
import type { Config } from 'jiek'
|
11
|
-
import type { JSONPath } from 'jsonc-parser'
|
12
|
-
import { applyEdits, modify } from 'jsonc-parser'
|
13
|
-
|
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'
|
21
|
-
import { outdirDescription } from './descriptions'
|
22
|
-
|
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
|
-
}
|
31
|
-
export interface Config {
|
32
|
-
publish?: {
|
33
|
-
/**
|
34
|
-
* @default false
|
35
|
-
*/
|
36
|
-
withSuffix?: boolean
|
37
|
-
/**
|
38
|
-
* @default true
|
39
|
-
*/
|
40
|
-
withSource?: boolean
|
41
|
-
}
|
42
|
-
}
|
43
|
-
}
|
44
|
-
|
45
|
-
const description = `
|
46
|
-
Publish package to npm registry, and auto generate exports field and other fields in published package.json.
|
47
|
-
If you want to through the options to the \`pnpm publish\` command, you can pass the options after '--'.
|
48
|
-
`.trim()
|
49
|
-
|
50
|
-
async function forEachSelectedProjectsGraphEntries(
|
51
|
-
callback: (dir: string, manifest: NonNullable<ProjectsGraph['value']>[string]) => void
|
52
|
-
) {
|
53
|
-
const { value = {} } = await getSelectedProjectsGraph() ?? {}
|
54
|
-
const selectedProjectsGraphEntries = Object.entries(value)
|
55
|
-
if (selectedProjectsGraphEntries.length === 0) {
|
56
|
-
throw new Error('no packages selected')
|
57
|
-
}
|
58
|
-
for (const [dir, manifest] of selectedProjectsGraphEntries) {
|
59
|
-
callback(dir, manifest)
|
60
|
-
}
|
61
|
-
}
|
62
|
-
|
63
|
-
interface PublishOptions {
|
64
|
-
outdir?: string
|
65
|
-
bumper: false | BumperType
|
66
|
-
/**
|
67
|
-
* Skip entries which end with '.js'.
|
68
|
-
*/
|
69
|
-
skipJS: boolean
|
70
|
-
}
|
71
|
-
|
72
|
-
const attachPublishOptions = (command: Command) =>
|
73
|
-
command
|
74
|
-
.option('-b, --bumper <bumper>', 'bump version', 'patch')
|
75
|
-
.option('-no-b, --no-bumper', 'no bump version')
|
76
|
-
.option('-o, --outdir <OUTDIR>', outdirDescription, String, 'dist')
|
77
|
-
.option('--skipJS', 'skip entries which end with ".js"')
|
78
|
-
|
79
|
-
attachPublishOptions(
|
80
|
-
program
|
81
|
-
.command('publish')
|
82
|
-
.description(description)
|
83
|
-
.aliases(['pub', 'p'])
|
84
|
-
)
|
85
|
-
.action(async ({
|
86
|
-
outdir,
|
87
|
-
bumper,
|
88
|
-
skipJS
|
89
|
-
}: PublishOptions) => {
|
90
|
-
let shouldPassThrough = false
|
91
|
-
|
92
|
-
const passThroughOptions = process.argv
|
93
|
-
.reduce(
|
94
|
-
(acc, value) => {
|
95
|
-
if (shouldPassThrough) {
|
96
|
-
acc.push(value)
|
97
|
-
}
|
98
|
-
if (value === '--') {
|
99
|
-
shouldPassThrough = true
|
100
|
-
}
|
101
|
-
return acc
|
102
|
-
},
|
103
|
-
[] as string[]
|
104
|
-
)
|
105
|
-
|
106
|
-
await forEachSelectedProjectsGraphEntries(dir => {
|
107
|
-
const args = ['pnpm', 'publish', '--access', 'public', '--no-git-checks']
|
108
|
-
if (bumper && TAGS.includes(bumper)) {
|
109
|
-
args.push('--tag', bumper)
|
110
|
-
}
|
111
|
-
args.push(...passThroughOptions)
|
112
|
-
childProcess.execSync(args.join(' '), {
|
113
|
-
cwd: dir,
|
114
|
-
stdio: 'inherit',
|
115
|
-
env: {
|
116
|
-
...process.env,
|
117
|
-
JIEK_PUBLISH_OUTDIR: JSON.stringify(outdir),
|
118
|
-
JIEK_PUBLISH_BUMPER: JSON.stringify(bumper),
|
119
|
-
JIEK_PUBLISH_SKIP_JS: JSON.stringify(skipJS)
|
120
|
-
}
|
121
|
-
})
|
122
|
-
})
|
123
|
-
})
|
124
|
-
|
125
|
-
async function prepublish({
|
126
|
-
bumper,
|
127
|
-
skipJS
|
128
|
-
}: PublishOptions) {
|
129
|
-
const {
|
130
|
-
JIEK_PUBLISH_OUTDIR: outdirEnv,
|
131
|
-
JIEK_PUBLISH_BUMPER: bumperEnv,
|
132
|
-
JIEK_PUBLISH_SKIP_JS: skipJSEnv
|
133
|
-
} = process.env
|
134
|
-
const outdir = outdirEnv
|
135
|
-
? JSON.parse(outdirEnv) as string
|
136
|
-
: 'dist'
|
137
|
-
bumper = bumper ?? (
|
138
|
-
bumperEnv ? JSON.parse(bumperEnv) as string | boolean : false
|
139
|
-
)
|
140
|
-
skipJS = skipJS ?? (
|
141
|
-
skipJSEnv ? JSON.parse(skipJSEnv) as boolean : undefined
|
142
|
-
)
|
143
|
-
|
144
|
-
const generateNewManifest = (
|
145
|
-
dir: string,
|
146
|
-
manifest: NonNullable<ProjectsGraph['value']>[string],
|
147
|
-
config: Config
|
148
|
-
) => {
|
149
|
-
const {
|
150
|
-
name,
|
151
|
-
type,
|
152
|
-
exports: entrypoints,
|
153
|
-
imports: internalEntrypoints
|
154
|
-
} = manifest
|
155
|
-
if (!name) {
|
156
|
-
throw new Error(`package.json in ${dir} must have a name field`)
|
157
|
-
}
|
158
|
-
|
159
|
-
const pkgIsModule = type === 'module'
|
160
|
-
const newManifest = { ...manifest }
|
161
|
-
const commonOptions = {
|
162
|
-
pkgIsModule,
|
163
|
-
pkgName: name,
|
164
|
-
config,
|
165
|
-
dir,
|
166
|
-
noFilter: true,
|
167
|
-
isPublish: true,
|
168
|
-
skipJS: skipJS ?? config.skipJS
|
169
|
-
} satisfies Partial<ResolveExportsOptions>
|
170
|
-
let resolvedOutdir = outdir
|
171
|
-
if (entrypoints) {
|
172
|
-
const [resolvedEntrypoints, exports, _resolvedOutdir] = resolveExports({
|
173
|
-
entrypoints,
|
174
|
-
defaultOutdir: outdir,
|
175
|
-
...commonOptions
|
176
|
-
})
|
177
|
-
newManifest.exports = {
|
178
|
-
...resolvedEntrypoints,
|
179
|
-
...exports
|
180
|
-
}
|
181
|
-
if (resolvedOutdir === outdir) {
|
182
|
-
resolvedOutdir = _resolvedOutdir
|
183
|
-
}
|
184
|
-
}
|
185
|
-
if (internalEntrypoints) {
|
186
|
-
const [resolvedInternalEntrypoints, imports, _resolvedOutdir] = resolveExports({
|
187
|
-
entrypoints: internalEntrypoints,
|
188
|
-
defaultOutdir: `${outdir}/.internal`,
|
189
|
-
...commonOptions
|
190
|
-
})
|
191
|
-
newManifest.imports = {
|
192
|
-
...resolvedInternalEntrypoints,
|
193
|
-
...imports
|
194
|
-
}
|
195
|
-
if (resolvedOutdir === outdir) {
|
196
|
-
resolvedOutdir = _resolvedOutdir
|
197
|
-
}
|
198
|
-
}
|
199
|
-
return [newManifest, resolvedOutdir] as const
|
200
|
-
}
|
201
|
-
|
202
|
-
const generateNewPackageJSONString = ({
|
203
|
-
config,
|
204
|
-
oldJSONString,
|
205
|
-
oldJSON,
|
206
|
-
manifest,
|
207
|
-
formattingOptions
|
208
|
-
}: {
|
209
|
-
config: Config
|
210
|
-
oldJSONString: string
|
211
|
-
oldJSON: Record<string, unknown>
|
212
|
-
manifest: NonNullable<ProjectsGraph['value']>[string]
|
213
|
-
formattingOptions: {
|
214
|
-
tabSize: number
|
215
|
-
insertSpaces: boolean
|
216
|
-
}
|
217
|
-
}) => {
|
218
|
-
const internalModuleName = getInternalModuleName(manifest.name!)
|
219
|
-
|
220
|
-
let newJSONString = oldJSONString
|
221
|
-
const update = (path: JSONPath, value: unknown) => {
|
222
|
-
newJSONString = applyEdits(
|
223
|
-
newJSONString,
|
224
|
-
modify(newJSONString, path, value, { formattingOptions })
|
225
|
-
)
|
226
|
-
}
|
227
|
-
|
228
|
-
update(['publishConfig', 'typesVersions'], {
|
229
|
-
'<5.0': {
|
230
|
-
'*': [
|
231
|
-
'*',
|
232
|
-
'./*',
|
233
|
-
'./*/index.d.ts',
|
234
|
-
'./*/index.d.mts',
|
235
|
-
'./*/index.d.cts'
|
236
|
-
]
|
237
|
-
}
|
238
|
-
})
|
239
|
-
if (config.experimental?.importsDowngrade) {
|
240
|
-
update(['dependencies', internalModuleName], `file:./${outdir}/.internal`)
|
241
|
-
update(['dependenciesMeta', internalModuleName], {
|
242
|
-
'injected': true
|
243
|
-
})
|
244
|
-
update(['imports'], undefined)
|
245
|
-
}
|
246
|
-
|
247
|
-
for (const [key, value] of Object.entries(manifest)) {
|
248
|
-
if (key === 'version') continue
|
249
|
-
if (JSON.stringify(value) === JSON.stringify(oldJSON[key])) continue
|
250
|
-
|
251
|
-
if (key !== 'exports') {
|
252
|
-
newJSONString = applyEdits(
|
253
|
-
newJSONString,
|
254
|
-
modify(
|
255
|
-
newJSONString,
|
256
|
-
['publishConfig', key],
|
257
|
-
value,
|
258
|
-
{ formattingOptions }
|
259
|
-
)
|
260
|
-
)
|
261
|
-
} else {
|
262
|
-
const exports = value as Record<string, unknown>
|
263
|
-
for (const [k, v] of Object.entries(exports)) {
|
264
|
-
newJSONString = applyEdits(
|
265
|
-
newJSONString,
|
266
|
-
modify(
|
267
|
-
newJSONString,
|
268
|
-
['publishConfig', 'exports', k],
|
269
|
-
v,
|
270
|
-
{ formattingOptions }
|
271
|
-
)
|
272
|
-
)
|
273
|
-
}
|
274
|
-
const index = exports?.['.']
|
275
|
-
const indexPublishConfig: Record<string, string> = {}
|
276
|
-
if (index) {
|
277
|
-
// eslint-disable-next-line ts/switch-exhaustiveness-check
|
278
|
-
switch (typeof index) {
|
279
|
-
case 'string':
|
280
|
-
indexPublishConfig[
|
281
|
-
manifest?.type === 'module' ? 'module' : 'main'
|
282
|
-
] = index
|
283
|
-
break
|
284
|
-
case 'object': {
|
285
|
-
const indexExports = index as Record<string, string>
|
286
|
-
indexPublishConfig.main = indexExports.require ?? indexExports.default
|
287
|
-
indexPublishConfig.module = indexExports.import ?? indexExports.module ?? indexExports.default
|
288
|
-
indexPublishConfig.types = indexExports.types
|
289
|
-
break
|
290
|
-
}
|
291
|
-
}
|
292
|
-
indexPublishConfig.types = indexPublishConfig[
|
293
|
-
manifest?.type === 'module' ? 'module' : 'main'
|
294
|
-
].replace(/\.([cm]?)js$/, '.d.$1ts')
|
295
|
-
for (const [k, v] of Object.entries(indexPublishConfig)) {
|
296
|
-
if (v === undefined) continue
|
297
|
-
newJSONString = applyEdits(
|
298
|
-
newJSONString,
|
299
|
-
modify(
|
300
|
-
newJSONString,
|
301
|
-
['publishConfig', k],
|
302
|
-
v,
|
303
|
-
{ formattingOptions }
|
304
|
-
)
|
305
|
-
)
|
306
|
-
}
|
307
|
-
}
|
308
|
-
}
|
309
|
-
}
|
310
|
-
if (oldJSON.devDependencies) {
|
311
|
-
newJSONString = applyEdits(
|
312
|
-
newJSONString,
|
313
|
-
modify(
|
314
|
-
newJSONString,
|
315
|
-
['devDependencies'],
|
316
|
-
undefined,
|
317
|
-
{ formattingOptions }
|
318
|
-
)
|
319
|
-
)
|
320
|
-
}
|
321
|
-
if (oldJSON.peerDependencies) {
|
322
|
-
const peerDependenciesMeta = Object.keys(oldJSON.peerDependencies).reduce(
|
323
|
-
(acc, key) => {
|
324
|
-
acc[key] = { optional: true }
|
325
|
-
return acc
|
326
|
-
},
|
327
|
-
{} as Record<string, { optional: boolean }>
|
328
|
-
)
|
329
|
-
newJSONString = applyEdits(
|
330
|
-
newJSONString,
|
331
|
-
modify(
|
332
|
-
newJSONString,
|
333
|
-
['peerDependenciesMeta'],
|
334
|
-
peerDependenciesMeta,
|
335
|
-
{ formattingOptions }
|
336
|
-
)
|
337
|
-
)
|
338
|
-
}
|
339
|
-
if (oldJSON.files) {
|
340
|
-
newJSONString = applyEdits(
|
341
|
-
newJSONString,
|
342
|
-
modify(
|
343
|
-
newJSONString,
|
344
|
-
['files'],
|
345
|
-
undefined,
|
346
|
-
{ formattingOptions }
|
347
|
-
)
|
348
|
-
)
|
349
|
-
}
|
350
|
-
return newJSONString
|
351
|
-
}
|
352
|
-
|
353
|
-
await forEachSelectedProjectsGraphEntries((dir, originalManifest) => {
|
354
|
-
const config = loadConfig(dir)
|
355
|
-
const [manifest, resolvedOutdir] = generateNewManifest(dir, originalManifest, config)
|
356
|
-
const resolveByDir = (...paths: string[]) => path.resolve(dir, ...paths)
|
357
|
-
|
358
|
-
const oldJSONString = fs.readFileSync(resolveByDir('package.json'), 'utf-8')
|
359
|
-
const oldJSON = JSON.parse(oldJSONString) as Record<string, unknown>
|
360
|
-
if (typeof oldJSON.version !== 'string') {
|
361
|
-
throw new TypeError(`${dir}/package.json must have a version field with a string value`)
|
362
|
-
}
|
363
|
-
|
364
|
-
// TODO detectIndent by editorconfig
|
365
|
-
const { indent = ' ' } = detectIndent(oldJSONString)
|
366
|
-
const formattingOptions = {
|
367
|
-
tabSize: indent.length,
|
368
|
-
insertSpaces: true
|
369
|
-
}
|
370
|
-
|
371
|
-
const newVersion = bumper
|
372
|
-
? bump(oldJSON.version, bumper)
|
373
|
-
: oldJSON.version
|
374
|
-
const modifyVersionPackageJSON = applyEdits(
|
375
|
-
oldJSONString,
|
376
|
-
modify(oldJSONString, ['version'], newVersion, { formattingOptions })
|
377
|
-
)
|
378
|
-
|
379
|
-
const newJSONString = generateNewPackageJSONString({
|
380
|
-
config,
|
381
|
-
oldJSONString: modifyVersionPackageJSON,
|
382
|
-
oldJSON: {
|
383
|
-
...oldJSON,
|
384
|
-
version: newVersion
|
385
|
-
},
|
386
|
-
manifest,
|
387
|
-
formattingOptions
|
388
|
-
})
|
389
|
-
|
390
|
-
const withPublishConfigDirectoryOldJSONString = applyEdits(
|
391
|
-
modifyVersionPackageJSON,
|
392
|
-
modify(modifyVersionPackageJSON, ['publishConfig', 'directory'], resolvedOutdir, { formattingOptions })
|
393
|
-
)
|
394
|
-
|
395
|
-
if (!fs.existsSync(resolveByDir(resolvedOutdir))) {
|
396
|
-
fs.mkdirSync(resolveByDir(resolvedOutdir))
|
397
|
-
}
|
398
|
-
const jiekTempDir = resolveByDir('node_modules/.jiek/.tmp')
|
399
|
-
if (!fs.existsSync(resolveByDir(jiekTempDir))) {
|
400
|
-
fs.mkdirSync(resolveByDir(jiekTempDir), { recursive: true })
|
401
|
-
}
|
402
|
-
|
403
|
-
fs.writeFileSync(resolveByDir(resolvedOutdir, 'package.json'), newJSONString)
|
404
|
-
fs.writeFileSync(resolveByDir(jiekTempDir, 'package.json'), modifyVersionPackageJSON)
|
405
|
-
fs.writeFileSync(resolveByDir('package.json'), withPublishConfigDirectoryOldJSONString)
|
406
|
-
|
407
|
-
const allBuildFiles = fs
|
408
|
-
.readdirSync(resolveByDir(resolvedOutdir), { recursive: true })
|
409
|
-
.filter(file => typeof file === 'string')
|
410
|
-
.filter(file => file !== 'package.json')
|
411
|
-
const resolvedExports = manifest.exports as Record<string, unknown>
|
412
|
-
Object
|
413
|
-
.keys(resolvedExports)
|
414
|
-
.forEach(key => {
|
415
|
-
if (key === '.') return
|
416
|
-
if (/\.[cm]?js$/.test(key)) return
|
417
|
-
// resource file suffix
|
418
|
-
const resourceFileSuffixes = [
|
419
|
-
'.d.ts',
|
420
|
-
'.d.mts',
|
421
|
-
'.d.cts',
|
422
|
-
'.css',
|
423
|
-
'.scss',
|
424
|
-
'.sass',
|
425
|
-
'.less',
|
426
|
-
'.styl',
|
427
|
-
'.stylus',
|
428
|
-
'.json',
|
429
|
-
'.json5'
|
430
|
-
]
|
431
|
-
if (resourceFileSuffixes.find(suffix => key.endsWith(suffix))) return
|
432
|
-
|
433
|
-
const value = resolvedExports[key] as {
|
434
|
-
import?: string
|
435
|
-
require?: string
|
436
|
-
default?: string
|
437
|
-
}
|
438
|
-
|
439
|
-
const filepath = resolveByDir(resolvedOutdir, key)
|
440
|
-
|
441
|
-
fs.mkdirSync(filepath, { recursive: true })
|
442
|
-
const pkgJSONPath = resolveByDir(resolvedOutdir, key, 'package.json')
|
443
|
-
const relativePath = Array.from({ length: key.split('/').length - 1 }, () => '..').join('/')
|
444
|
-
const { type } = manifest
|
445
|
-
const pkgJSON: Record<string, unknown> = { type }
|
446
|
-
if ('default' in value) {
|
447
|
-
pkgJSON[
|
448
|
-
type === 'module' ? 'module' : 'main'
|
449
|
-
] = [
|
450
|
-
relativePath,
|
451
|
-
value.default?.replace(/^\.\//, '')
|
452
|
-
].join('/')
|
453
|
-
}
|
454
|
-
if ('import' in value) {
|
455
|
-
pkgJSON.module = [
|
456
|
-
relativePath,
|
457
|
-
value.import?.replace(/^\.\//, '')
|
458
|
-
].join('/')
|
459
|
-
}
|
460
|
-
if ('require' in value) {
|
461
|
-
pkgJSON.main = [
|
462
|
-
relativePath,
|
463
|
-
value.require?.replace(/^\.\//, '')
|
464
|
-
].join('/')
|
465
|
-
}
|
466
|
-
fs.writeFileSync(pkgJSONPath, JSON.stringify(pkgJSON))
|
467
|
-
})
|
468
|
-
fs.mkdirSync(resolveByDir(resolvedOutdir, resolvedOutdir))
|
469
|
-
for (const file of allBuildFiles) {
|
470
|
-
const filepath = resolveByDir(resolvedOutdir, file)
|
471
|
-
const newFilepath = resolveByDir(resolvedOutdir, resolvedOutdir, file)
|
472
|
-
const stat = fs.statSync(filepath)
|
473
|
-
if (stat.isDirectory()) {
|
474
|
-
fs.mkdirSync(newFilepath, { recursive: true })
|
475
|
-
continue
|
476
|
-
}
|
477
|
-
if (stat.isFile()) {
|
478
|
-
fs.cpSync(filepath, newFilepath)
|
479
|
-
fs.rmSync(filepath)
|
480
|
-
}
|
481
|
-
}
|
482
|
-
|
483
|
-
if (oldJSON.files) {
|
484
|
-
if (Array.isArray(oldJSON.files)) {
|
485
|
-
if (oldJSON.files.every((file: unknown) => typeof file !== 'string')) {
|
486
|
-
throw new TypeError(`${dir}/package.json files field must be an array of string`)
|
487
|
-
}
|
488
|
-
} else {
|
489
|
-
throw new TypeError(`${dir}/package.json files field must be an array`)
|
490
|
-
}
|
491
|
-
}
|
492
|
-
const resolvedOutdirAbs = resolveByDir(resolvedOutdir)
|
493
|
-
const files = (
|
494
|
-
(oldJSON.files as undefined | string[]) ?? fs.readdirSync(resolveByDir('.'))
|
495
|
-
).filter(file =>
|
496
|
-
![
|
497
|
-
'node_modules',
|
498
|
-
'package.json',
|
499
|
-
'pnpm-lock.yaml'
|
500
|
-
].includes(file) && resolveByDir(file) !== resolvedOutdirAbs
|
501
|
-
)
|
502
|
-
|
503
|
-
for (const file of files) {
|
504
|
-
const path = resolveByDir(file)
|
505
|
-
try {
|
506
|
-
const stat = fs.statSync(path)
|
507
|
-
if (stat.isDirectory()) {
|
508
|
-
fs.cpSync(path, resolveByDir(resolvedOutdir, file), { recursive: true })
|
509
|
-
continue
|
510
|
-
}
|
511
|
-
if (stat.isFile()) {
|
512
|
-
fs.cpSync(path, resolveByDir(resolvedOutdir, file))
|
513
|
-
continue
|
514
|
-
}
|
515
|
-
} catch (e) {
|
516
|
-
console.warn(String(e))
|
517
|
-
continue
|
518
|
-
}
|
519
|
-
throw new Error(`file type of ${path} is not supported`)
|
520
|
-
}
|
521
|
-
|
522
|
-
if (config.experimental?.importsDowngrade && 'imports' in manifest && manifest.imports) {
|
523
|
-
fs.writeFileSync(
|
524
|
-
resolveByDir(resolvedOutdir, resolvedOutdir, '.internal', 'package.json'),
|
525
|
-
JSON.stringify(
|
526
|
-
{
|
527
|
-
name: getInternalModuleName(manifest.name!),
|
528
|
-
exports: JSON.parse(
|
529
|
-
JSON
|
530
|
-
.stringify(manifest.imports)
|
531
|
-
.replaceAll('#', './')
|
532
|
-
.replaceAll('~', '')
|
533
|
-
) as Record<string, unknown>
|
534
|
-
},
|
535
|
-
null,
|
536
|
-
2
|
537
|
-
)
|
538
|
-
)
|
539
|
-
}
|
540
|
-
|
541
|
-
const jiekProductionTag = path.resolve(resolvedOutdir, '.jiek-production-tag')
|
542
|
-
if (!fs.existsSync(jiekProductionTag)) {
|
543
|
-
fs.writeFileSync(jiekProductionTag, '')
|
544
|
-
}
|
545
|
-
})
|
546
|
-
}
|
547
|
-
|
548
|
-
// eslint-disable-next-line no-empty-pattern
|
549
|
-
async function postpublish({}: PublishOptions) {
|
550
|
-
await forEachSelectedProjectsGraphEntries(dir => {
|
551
|
-
const jiekTempDir = path.resolve(dir, 'node_modules/.jiek/.tmp')
|
552
|
-
const packageJSONPath = path.resolve(dir, 'package.json')
|
553
|
-
const { name, version } = JSON.parse(fs.readFileSync(packageJSONPath, 'utf-8')) as {
|
554
|
-
name: string
|
555
|
-
version: string
|
556
|
-
}
|
557
|
-
const jiekTempPackageJSONPath = path.resolve(jiekTempDir, 'package.json')
|
558
|
-
if (fs.existsSync(jiekTempPackageJSONPath)) {
|
559
|
-
fs.copyFileSync(jiekTempPackageJSONPath, packageJSONPath)
|
560
|
-
fs.rmSync(jiekTempPackageJSONPath)
|
561
|
-
/* eslint-disable no-console */
|
562
|
-
console.log(`${dir}/package.json has been restored`)
|
563
|
-
console.log(
|
564
|
-
`if you want to check the compatibility of the package, you can visit: https://arethetypeswrong.github.io/?p=${name}%40${version}`
|
565
|
-
)
|
566
|
-
/* eslint-enable no-console */
|
567
|
-
} else {
|
568
|
-
throw new Error(
|
569
|
-
`jiek temp \`${dir}/package.json\` not found, please confirm the jiek pre-publish command has been executed`
|
570
|
-
)
|
571
|
-
}
|
572
|
-
})
|
573
|
-
}
|
574
|
-
|
575
|
-
const prepublishDescription = `
|
576
|
-
Prepare package.json for publish, you can add \`jk\` to the \`prepublish\` script in package.json, the command will automatically run \`jk prepublish\`.
|
577
|
-
.e.g
|
578
|
-
{
|
579
|
-
"scripts": {
|
580
|
-
"prepublish": "jk"
|
581
|
-
}
|
582
|
-
}
|
583
|
-
`.trim()
|
584
|
-
attachPublishOptions(
|
585
|
-
program
|
586
|
-
.command('prepublish')
|
587
|
-
.description(prepublishDescription)
|
588
|
-
)
|
589
|
-
.action(prepublish)
|
590
|
-
|
591
|
-
const postpublishDescription = `
|
592
|
-
Restore package.json after publish, you can add \`jk\` to the \`postpublish\` script in package.json, the command will automatically run \`jk postpublish\`.
|
593
|
-
.e.g
|
594
|
-
{
|
595
|
-
"scripts": {
|
596
|
-
"postpublish": "jk"
|
597
|
-
}
|
598
|
-
}
|
599
|
-
`.trim()
|
600
|
-
attachPublishOptions(
|
601
|
-
program
|
602
|
-
.command('postpublish')
|
603
|
-
.description(postpublishDescription)
|
604
|
-
)
|
605
|
-
.action(postpublish)
|
606
|
-
|
607
|
-
const {
|
608
|
-
npm_lifecycle_event: NPM_LIFECYCLE_EVENT
|
609
|
-
} = process.env
|
610
|
-
|
611
|
-
if (
|
612
|
-
NPM_LIFECYCLE_EVENT && [
|
613
|
-
'prepublish',
|
614
|
-
'postpublish'
|
615
|
-
].includes(NPM_LIFECYCLE_EVENT)
|
616
|
-
) {
|
617
|
-
attachPublishOptions(program)
|
618
|
-
.action(async (options: PublishOptions) => {
|
619
|
-
switch (NPM_LIFECYCLE_EVENT) {
|
620
|
-
case 'prepublish':
|
621
|
-
await prepublish(options)
|
622
|
-
break
|
623
|
-
case 'postpublish':
|
624
|
-
await postpublish(options)
|
625
|
-
break
|
626
|
-
}
|
627
|
-
})
|
628
|
-
}
|
package/src/index.ts
DELETED
@@ -1,12 +0,0 @@
|
|
1
|
-
import type {} from './commands/base'
|
2
|
-
import type {} from './commands/build'
|
3
|
-
import type {} from './commands/publish'
|
4
|
-
|
5
|
-
export interface ConfigExperimental {
|
6
|
-
}
|
7
|
-
|
8
|
-
export interface Config {
|
9
|
-
experimental?: ConfigExperimental
|
10
|
-
}
|
11
|
-
|
12
|
-
export const defineConfig = (config: Config) => config
|