jiek 1.1.5 → 1.1.7-alpha.1
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/jiek.js +1 -1
- package/dist/cli.cjs +172 -122
- package/dist/cli.js +173 -123
- package/dist/cli.min.cjs +4 -4
- package/dist/cli.min.js +4 -4
- package/dist/rollup/index.cjs +1 -1
- package/dist/rollup/index.js +1 -1
- package/dist/rollup/index.min.cjs +4 -4
- package/dist/rollup/index.min.js +3 -3
- package/package.json +5 -2
- package/src/commands/build.ts +124 -111
- package/src/commands/publish.ts +6 -2
- package/src/utils/filterSupport.ts +24 -13
package/dist/cli.js
CHANGED
@@ -13,7 +13,7 @@ import { applyEdits, modify } from 'jsonc-parser';
|
|
13
13
|
import require$$0 from 'util';
|
14
14
|
import require$$0$1 from 'path';
|
15
15
|
import * as childProcess from 'node:child_process';
|
16
|
-
import { bump } from '@jiek/utils/bumper';
|
16
|
+
import { bump, TAGS } from '@jiek/utils/bumper';
|
17
17
|
import { resolveEntrypoints, filterLeafs, DEFAULT_SKIP_VALUES, entrypoints2Exports } from '@jiek/pkger/entrypoints';
|
18
18
|
|
19
19
|
let root;
|
@@ -58,19 +58,33 @@ try {
|
|
58
58
|
} catch {
|
59
59
|
}
|
60
60
|
if (type$1 !== "") {
|
61
|
-
program.option("-f, --filter <filter>", "filter packages");
|
61
|
+
program.option("-f, --filter <filter>", "filter packages, support fuzzy match and array. e.g. -f core,utils");
|
62
62
|
}
|
63
|
-
|
64
|
-
|
65
|
-
|
63
|
+
function filterPackagesGraph(filters) {
|
64
|
+
return Promise.all(filters.map(async (filter) => getSelectedProjectsGraph(filter)));
|
65
|
+
}
|
66
|
+
async function getSelectedProjectsGraph(filter = program.getOptionValue("filter")) {
|
67
|
+
let root = getRoot();
|
66
68
|
const { wd, notWorkspace } = getWD();
|
67
|
-
if (
|
69
|
+
if (notWorkspace) {
|
70
|
+
return {
|
71
|
+
wd,
|
72
|
+
root,
|
73
|
+
value: {
|
74
|
+
[wd]: JSON.parse(fs.readFileSync(path.resolve(wd, "package.json"), "utf-8"))
|
75
|
+
}
|
76
|
+
};
|
77
|
+
}
|
78
|
+
if (type$1 === "pnpm") {
|
68
79
|
const pnpmWorkspaceFilePath = path.resolve(wd, "pnpm-workspace.yaml");
|
69
80
|
const pnpmWorkspaceFileContent = fs.readFileSync(pnpmWorkspaceFilePath, "utf-8");
|
70
81
|
const pnpmWorkspace = load(pnpmWorkspaceFileContent);
|
71
82
|
if (root === wd && !filter) {
|
72
83
|
throw new Error("root path is workspace root, please provide a filter");
|
73
84
|
}
|
85
|
+
if (root === void 0) {
|
86
|
+
root = process.cwd();
|
87
|
+
}
|
74
88
|
if (root !== wd && !filter) {
|
75
89
|
const packageJSONIsExist = fs.existsSync(path.resolve(root, "package.json"));
|
76
90
|
if (!packageJSONIsExist) {
|
@@ -99,18 +113,12 @@ async function getSelectedProjectsGraph() {
|
|
99
113
|
}, {})
|
100
114
|
};
|
101
115
|
}
|
102
|
-
|
103
|
-
wd,
|
104
|
-
root,
|
105
|
-
value: {
|
106
|
-
[wd]: JSON.parse(fs.readFileSync(path.resolve(wd, "package.json"), "utf-8"))
|
107
|
-
}
|
108
|
-
};
|
116
|
+
throw new Error(`not supported package manager ${type$1}`);
|
109
117
|
}
|
110
118
|
|
111
119
|
var name = "jiek";
|
112
120
|
var type = "module";
|
113
|
-
var version = "1.1.
|
121
|
+
var version = "1.1.7-alpha.1";
|
114
122
|
var description$1 = "YiJie's personal kits.";
|
115
123
|
var bin = {
|
116
124
|
jiek: "bin/jiek.js",
|
@@ -132,6 +140,9 @@ var typesVersions = {
|
|
132
140
|
]
|
133
141
|
}
|
134
142
|
};
|
143
|
+
var scripts = {
|
144
|
+
prepublish: "jk build"
|
145
|
+
};
|
135
146
|
var exports = {
|
136
147
|
"./package.json": "./package.json",
|
137
148
|
".": "./src/index.ts",
|
@@ -157,7 +168,7 @@ var dependencies = {
|
|
157
168
|
inquirer: "^8.2.6",
|
158
169
|
"js-yaml": "^4.1.0",
|
159
170
|
"jsonc-parser": "^3.2.1",
|
160
|
-
rollup: "
|
171
|
+
rollup: "4.13.2",
|
161
172
|
"rollup-plugin-esbuild": "^6.1.0",
|
162
173
|
typescript: "^5.0.0"
|
163
174
|
};
|
@@ -181,6 +192,28 @@ var devDependencies = {
|
|
181
192
|
postcss: "^8.4.47",
|
182
193
|
"rollup-plugin-postcss": "^4.0.2"
|
183
194
|
};
|
195
|
+
var publishConfig = {
|
196
|
+
exports: {
|
197
|
+
"./package.json": "./package.json",
|
198
|
+
".": {
|
199
|
+
source: "./src/index.ts",
|
200
|
+
require: "./dist/index.cjs",
|
201
|
+
"default": "./dist/index.js"
|
202
|
+
},
|
203
|
+
"./cli": {
|
204
|
+
source: "./src/cli.ts",
|
205
|
+
require: "./dist/cli.cjs",
|
206
|
+
"default": "./dist/cli.js"
|
207
|
+
},
|
208
|
+
"./rollup": {
|
209
|
+
source: "./src/rollup/index.ts",
|
210
|
+
require: "./dist/rollup/index.cjs",
|
211
|
+
"default": "./dist/rollup/index.js"
|
212
|
+
}
|
213
|
+
},
|
214
|
+
main: "./dist/index.cjs",
|
215
|
+
module: "./dist/index.js"
|
216
|
+
};
|
184
217
|
var pkg = {
|
185
218
|
name: name,
|
186
219
|
type: type,
|
@@ -189,11 +222,13 @@ var pkg = {
|
|
189
222
|
bin: bin,
|
190
223
|
files: files,
|
191
224
|
typesVersions: typesVersions,
|
225
|
+
scripts: scripts,
|
192
226
|
exports: exports,
|
193
227
|
imports: imports,
|
194
228
|
dependencies: dependencies,
|
195
229
|
optionalDependencies: optionalDependencies,
|
196
|
-
devDependencies: devDependencies
|
230
|
+
devDependencies: devDependencies,
|
231
|
+
publishConfig: publishConfig
|
197
232
|
};
|
198
233
|
|
199
234
|
program.version(pkg.version).description(pkg.description).option("--root <root>", "root path").option("-c, --config-path <configPath>", "config path");
|
@@ -329,122 +364,133 @@ program.command("build").description(description).option("-s, --silent", "Don't
|
|
329
364
|
actionRestore();
|
330
365
|
const { build } = loadConfig();
|
331
366
|
silent = silent ?? build?.silent ?? false;
|
332
|
-
const {
|
333
|
-
wd,
|
334
|
-
value = {}
|
335
|
-
} = await getSelectedProjectsGraph() ?? {};
|
336
|
-
if (Object.keys(value).length === 0) {
|
337
|
-
throw new Error("no package found");
|
338
|
-
}
|
339
|
-
const wdNodeModules = path.resolve(wd, "node_modules");
|
340
|
-
if (!fs.existsSync(wdNodeModules)) {
|
341
|
-
fs.mkdirSync(wdNodeModules);
|
342
|
-
}
|
343
|
-
const jiekTempDir = (...paths) => path.resolve(wdNodeModules, ".jiek", ...paths);
|
344
|
-
if (!fs.existsSync(jiekTempDir())) {
|
345
|
-
fs.mkdirSync(jiekTempDir());
|
346
|
-
}
|
347
|
-
const rollupBinaryPath = require.resolve("rollup").replace(/dist\/rollup.js$/, "dist/bin/rollup");
|
348
367
|
const multiBars = new MultiBar({
|
349
368
|
clearOnComplete: false,
|
350
369
|
hideCursor: true,
|
351
|
-
format: "- {bar} | {status} | {input} | {message}"
|
370
|
+
format: "- {bar} | {status} | {pkgName} | {input} | {message}"
|
352
371
|
}, Presets.shades_classic);
|
353
|
-
|
354
|
-
|
355
|
-
|
356
|
-
|
357
|
-
|
358
|
-
|
359
|
-
|
360
|
-
|
361
|
-
|
362
|
-
|
363
|
-
|
364
|
-
|
365
|
-
|
366
|
-
|
367
|
-
|
368
|
-
|
369
|
-
|
370
|
-
|
371
|
-
|
372
|
-
|
373
|
-
|
374
|
-
|
372
|
+
const buildPackage = async ({
|
373
|
+
wd,
|
374
|
+
value = {}
|
375
|
+
}) => {
|
376
|
+
if (Object.keys(value).length === 0) {
|
377
|
+
throw new Error("no package found");
|
378
|
+
}
|
379
|
+
const wdNodeModules = path.resolve(wd, "node_modules");
|
380
|
+
if (!fs.existsSync(wdNodeModules)) {
|
381
|
+
fs.mkdirSync(wdNodeModules);
|
382
|
+
}
|
383
|
+
const jiekTempDir = (...paths) => path.resolve(wdNodeModules, ".jiek", ...paths);
|
384
|
+
if (!fs.existsSync(jiekTempDir())) {
|
385
|
+
fs.mkdirSync(jiekTempDir());
|
386
|
+
}
|
387
|
+
const rollupBinaryPath = require.resolve("rollup").replace(/dist\/rollup.js$/, "dist/bin/rollup");
|
388
|
+
let i = 0;
|
389
|
+
await Promise.all(
|
390
|
+
Object.entries(value).map(async ([dir, manifest]) => {
|
391
|
+
const escapeManifestName = manifest.name?.replace(/^@/g, "").replace(/\//g, "+");
|
392
|
+
const configFile = jiekTempDir(
|
393
|
+
`${escapeManifestName ?? `anonymous-${i++}`}.rollup.config.js`
|
394
|
+
);
|
395
|
+
fs.writeFileSync(configFile, FILE_TEMPLATE(manifest));
|
396
|
+
let prefix = "";
|
397
|
+
if (tsRegisterName) {
|
398
|
+
prefix = `node -r ${tsRegisterName} `;
|
375
399
|
}
|
376
|
-
|
377
|
-
|
378
|
-
|
379
|
-
|
380
|
-
|
381
|
-
|
382
|
-
|
383
|
-
|
384
|
-
|
385
|
-
|
386
|
-
|
387
|
-
|
388
|
-
|
400
|
+
const command = `${prefix}${rollupBinaryPath} --silent -c ${configFile}`;
|
401
|
+
const child = execaCommand(command, {
|
402
|
+
ipc: true,
|
403
|
+
cwd: dir,
|
404
|
+
env: {
|
405
|
+
...process.env,
|
406
|
+
JIEK_ROOT: wd,
|
407
|
+
JIEK_ENTRIES: entries,
|
408
|
+
JIEK_WITHOUT_JS: String(withoutJs),
|
409
|
+
JIEK_WITHOUT_DTS: String(withoutDts)
|
410
|
+
}
|
411
|
+
});
|
412
|
+
const bars = {};
|
413
|
+
let inputMaxLen = 10;
|
414
|
+
child.on("message", (e) => {
|
415
|
+
if (e.type === "debug")
|
416
|
+
console.log(...Array.isArray(e.data) ? e.data : [e.data]);
|
417
|
+
});
|
418
|
+
!silent && child.on("message", (e) => {
|
419
|
+
if (e.type === "init") {
|
420
|
+
const { leafMap, targetsLength } = e.data;
|
421
|
+
const leafs = Array.from(leafMap.entries()).flatMap(
|
422
|
+
([input, pathAndCondiions]) => pathAndCondiions.map(([path2, ...conditions]) => ({
|
423
|
+
input,
|
424
|
+
path: path2,
|
425
|
+
conditions
|
426
|
+
}))
|
427
|
+
);
|
428
|
+
console.log(`Package '${manifest.name}' has ${targetsLength} targets to build`);
|
429
|
+
leafs.forEach(({ input }) => {
|
430
|
+
inputMaxLen = Math.max(inputMaxLen, input.length);
|
431
|
+
});
|
432
|
+
leafs.forEach(({ input, path: path2 }) => {
|
433
|
+
const key = `${input}:${path2}`;
|
434
|
+
if (bars[key])
|
435
|
+
return;
|
436
|
+
bars[key] = multiBars.create(50, 0, {
|
437
|
+
pkgName: manifest.name,
|
438
|
+
input: input.padEnd(inputMaxLen),
|
439
|
+
status: "waiting".padEnd(10)
|
440
|
+
}, {
|
441
|
+
barsize: 20,
|
442
|
+
linewrap: true
|
443
|
+
});
|
444
|
+
});
|
445
|
+
}
|
446
|
+
if (e.type === "progress") {
|
447
|
+
const {
|
389
448
|
path: path2,
|
390
|
-
|
391
|
-
|
392
|
-
|
393
|
-
|
394
|
-
|
395
|
-
|
396
|
-
|
397
|
-
leafs.forEach(({ input, path: path2 }) => {
|
398
|
-
const key = `${input}:${path2}`;
|
399
|
-
if (bars[key])
|
449
|
+
tags,
|
450
|
+
input,
|
451
|
+
event,
|
452
|
+
message
|
453
|
+
} = e.data;
|
454
|
+
const bar = bars[`${input}:${path2}`];
|
455
|
+
if (!bar)
|
400
456
|
return;
|
401
|
-
|
402
|
-
|
403
|
-
|
404
|
-
|
405
|
-
|
406
|
-
|
407
|
-
|
408
|
-
|
409
|
-
|
410
|
-
|
411
|
-
|
412
|
-
|
413
|
-
|
414
|
-
input,
|
415
|
-
event,
|
416
|
-
message
|
417
|
-
} = e.data;
|
418
|
-
const bar = bars[`${input}:${path2}`];
|
419
|
-
if (!bar)
|
420
|
-
return;
|
421
|
-
bar.update(
|
422
|
-
{
|
423
|
-
start: 0,
|
424
|
-
resolve: 20,
|
425
|
-
end: 50
|
426
|
-
}[event ?? "start"] ?? 0,
|
427
|
-
{
|
428
|
-
input: input.padEnd(inputMaxLen),
|
429
|
-
status: event?.padEnd(10),
|
430
|
-
message: `${tags?.join(", ")}: ${message}`
|
431
|
-
}
|
432
|
-
);
|
433
|
-
}
|
434
|
-
});
|
435
|
-
await new Promise((resolve, reject) => {
|
436
|
-
let errorStr = "";
|
437
|
-
child.stderr?.on("data", (data) => {
|
438
|
-
errorStr += data;
|
457
|
+
bar.update(
|
458
|
+
{
|
459
|
+
start: 0,
|
460
|
+
resolve: 20,
|
461
|
+
end: 50
|
462
|
+
}[event ?? "start"] ?? 0,
|
463
|
+
{
|
464
|
+
input: input.padEnd(inputMaxLen),
|
465
|
+
status: event?.padEnd(10),
|
466
|
+
message: `${tags?.join(", ")}: ${message}`
|
467
|
+
}
|
468
|
+
);
|
469
|
+
}
|
439
470
|
});
|
440
|
-
|
471
|
+
await new Promise((resolve, reject) => {
|
472
|
+
let errorStr = "";
|
473
|
+
child.stderr?.on("data", (data) => {
|
474
|
+
errorStr += data;
|
475
|
+
});
|
476
|
+
child.once("exit", (code) => code === 0 ? resolve() : reject(new Error(`rollup build failed:
|
441
477
|
${errorStr}`)));
|
442
|
-
|
443
|
-
|
444
|
-
|
445
|
-
|
478
|
+
verbose && child.stdout?.pipe(process.stdout);
|
479
|
+
});
|
480
|
+
})
|
481
|
+
);
|
482
|
+
};
|
483
|
+
const filters = program.getOptionValue("filter")?.split(",");
|
484
|
+
try {
|
485
|
+
if (filters) {
|
486
|
+
const packages = await filterPackagesGraph(filters);
|
487
|
+
await Promise.all(packages.map(buildPackage));
|
488
|
+
} else {
|
489
|
+
await buildPackage(await getSelectedProjectsGraph());
|
490
|
+
}
|
491
|
+
} finally {
|
446
492
|
multiBars.stop();
|
447
|
-
}
|
493
|
+
}
|
448
494
|
actionDone();
|
449
495
|
});
|
450
496
|
|
@@ -5010,7 +5056,11 @@ program.command("publish").aliases(["pub", "p"]).option("-b, --bumper <bumper>",
|
|
5010
5056
|
console.warn("preview mode");
|
5011
5057
|
continue;
|
5012
5058
|
}
|
5013
|
-
|
5059
|
+
const args = ["pnpm", "publish", "--access", "public", "--no-git-checks", ...passArgs];
|
5060
|
+
if (bumper && TAGS.includes(bumper)) {
|
5061
|
+
args.push("--tag", bumper);
|
5062
|
+
}
|
5063
|
+
childProcess.execSync(args.join(" "), {
|
5014
5064
|
cwd: dir,
|
5015
5065
|
stdio: "inherit"
|
5016
5066
|
});
|