jiek 1.1.5 → 1.1.7-alpha.1
Sign up to get free protection for your applications and to get access to all the features.
- 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/bin/jiek.js
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
#!/usr/bin/env node
|
2
2
|
import { existsSync } from 'node:fs'
|
3
|
-
import { resolve, dirname } from 'node:path'
|
4
3
|
import { createRequire } from 'node:module'
|
4
|
+
import { dirname, resolve } from 'node:path'
|
5
5
|
|
6
6
|
const __dirname = dirname(import.meta.url.replace('file://', ''))
|
7
7
|
if (existsSync(resolve(__dirname, '../.jiek-dev-tag'))) {
|
package/dist/cli.cjs
CHANGED
@@ -89,19 +89,33 @@ try {
|
|
89
89
|
} catch {
|
90
90
|
}
|
91
91
|
if (type$1 !== "") {
|
92
|
-
commander.program.option("-f, --filter <filter>", "filter packages");
|
92
|
+
commander.program.option("-f, --filter <filter>", "filter packages, support fuzzy match and array. e.g. -f core,utils");
|
93
93
|
}
|
94
|
-
|
95
|
-
|
96
|
-
|
94
|
+
function filterPackagesGraph(filters) {
|
95
|
+
return Promise.all(filters.map(async (filter) => getSelectedProjectsGraph(filter)));
|
96
|
+
}
|
97
|
+
async function getSelectedProjectsGraph(filter = commander.program.getOptionValue("filter")) {
|
98
|
+
let root = getRoot();
|
97
99
|
const { wd, notWorkspace } = getWD();
|
98
|
-
if (
|
100
|
+
if (notWorkspace) {
|
101
|
+
return {
|
102
|
+
wd,
|
103
|
+
root,
|
104
|
+
value: {
|
105
|
+
[wd]: JSON.parse(fs__default.default.readFileSync(path__default.default.resolve(wd, "package.json"), "utf-8"))
|
106
|
+
}
|
107
|
+
};
|
108
|
+
}
|
109
|
+
if (type$1 === "pnpm") {
|
99
110
|
const pnpmWorkspaceFilePath = path__default.default.resolve(wd, "pnpm-workspace.yaml");
|
100
111
|
const pnpmWorkspaceFileContent = fs__default.default.readFileSync(pnpmWorkspaceFilePath, "utf-8");
|
101
112
|
const pnpmWorkspace = jsYaml.load(pnpmWorkspaceFileContent);
|
102
113
|
if (root === wd && !filter) {
|
103
114
|
throw new Error("root path is workspace root, please provide a filter");
|
104
115
|
}
|
116
|
+
if (root === void 0) {
|
117
|
+
root = process.cwd();
|
118
|
+
}
|
105
119
|
if (root !== wd && !filter) {
|
106
120
|
const packageJSONIsExist = fs__default.default.existsSync(path__default.default.resolve(root, "package.json"));
|
107
121
|
if (!packageJSONIsExist) {
|
@@ -130,18 +144,12 @@ async function getSelectedProjectsGraph() {
|
|
130
144
|
}, {})
|
131
145
|
};
|
132
146
|
}
|
133
|
-
|
134
|
-
wd,
|
135
|
-
root,
|
136
|
-
value: {
|
137
|
-
[wd]: JSON.parse(fs__default.default.readFileSync(path__default.default.resolve(wd, "package.json"), "utf-8"))
|
138
|
-
}
|
139
|
-
};
|
147
|
+
throw new Error(`not supported package manager ${type$1}`);
|
140
148
|
}
|
141
149
|
|
142
150
|
var name = "jiek";
|
143
151
|
var type = "module";
|
144
|
-
var version = "1.1.
|
152
|
+
var version = "1.1.7-alpha.1";
|
145
153
|
var description$1 = "YiJie's personal kits.";
|
146
154
|
var bin = {
|
147
155
|
jiek: "bin/jiek.js",
|
@@ -163,6 +171,9 @@ var typesVersions = {
|
|
163
171
|
]
|
164
172
|
}
|
165
173
|
};
|
174
|
+
var scripts = {
|
175
|
+
prepublish: "jk build"
|
176
|
+
};
|
166
177
|
var exports$1 = {
|
167
178
|
"./package.json": "./package.json",
|
168
179
|
".": "./src/index.ts",
|
@@ -188,7 +199,7 @@ var dependencies = {
|
|
188
199
|
inquirer: "^8.2.6",
|
189
200
|
"js-yaml": "^4.1.0",
|
190
201
|
"jsonc-parser": "^3.2.1",
|
191
|
-
rollup: "
|
202
|
+
rollup: "4.13.2",
|
192
203
|
"rollup-plugin-esbuild": "^6.1.0",
|
193
204
|
typescript: "^5.0.0"
|
194
205
|
};
|
@@ -212,6 +223,28 @@ var devDependencies = {
|
|
212
223
|
postcss: "^8.4.47",
|
213
224
|
"rollup-plugin-postcss": "^4.0.2"
|
214
225
|
};
|
226
|
+
var publishConfig = {
|
227
|
+
exports: {
|
228
|
+
"./package.json": "./package.json",
|
229
|
+
".": {
|
230
|
+
source: "./src/index.ts",
|
231
|
+
require: "./dist/index.cjs",
|
232
|
+
"default": "./dist/index.js"
|
233
|
+
},
|
234
|
+
"./cli": {
|
235
|
+
source: "./src/cli.ts",
|
236
|
+
require: "./dist/cli.cjs",
|
237
|
+
"default": "./dist/cli.js"
|
238
|
+
},
|
239
|
+
"./rollup": {
|
240
|
+
source: "./src/rollup/index.ts",
|
241
|
+
require: "./dist/rollup/index.cjs",
|
242
|
+
"default": "./dist/rollup/index.js"
|
243
|
+
}
|
244
|
+
},
|
245
|
+
main: "./dist/index.cjs",
|
246
|
+
module: "./dist/index.js"
|
247
|
+
};
|
215
248
|
var pkg = {
|
216
249
|
name: name,
|
217
250
|
type: type,
|
@@ -220,11 +253,13 @@ var pkg = {
|
|
220
253
|
bin: bin,
|
221
254
|
files: files,
|
222
255
|
typesVersions: typesVersions,
|
256
|
+
scripts: scripts,
|
223
257
|
exports: exports$1,
|
224
258
|
imports: imports,
|
225
259
|
dependencies: dependencies,
|
226
260
|
optionalDependencies: optionalDependencies,
|
227
|
-
devDependencies: devDependencies
|
261
|
+
devDependencies: devDependencies,
|
262
|
+
publishConfig: publishConfig
|
228
263
|
};
|
229
264
|
|
230
265
|
commander.program.version(pkg.version).description(pkg.description).option("--root <root>", "root path").option("-c, --config-path <configPath>", "config path");
|
@@ -360,122 +395,133 @@ commander.program.command("build").description(description).option("-s, --silent
|
|
360
395
|
actionRestore();
|
361
396
|
const { build } = loadConfig();
|
362
397
|
silent = silent ?? build?.silent ?? false;
|
363
|
-
const {
|
364
|
-
wd,
|
365
|
-
value = {}
|
366
|
-
} = await getSelectedProjectsGraph() ?? {};
|
367
|
-
if (Object.keys(value).length === 0) {
|
368
|
-
throw new Error("no package found");
|
369
|
-
}
|
370
|
-
const wdNodeModules = path__default.default.resolve(wd, "node_modules");
|
371
|
-
if (!fs__default.default.existsSync(wdNodeModules)) {
|
372
|
-
fs__default.default.mkdirSync(wdNodeModules);
|
373
|
-
}
|
374
|
-
const jiekTempDir = (...paths) => path__default.default.resolve(wdNodeModules, ".jiek", ...paths);
|
375
|
-
if (!fs__default.default.existsSync(jiekTempDir())) {
|
376
|
-
fs__default.default.mkdirSync(jiekTempDir());
|
377
|
-
}
|
378
|
-
const rollupBinaryPath = require$1.resolve("rollup").replace(/dist\/rollup.js$/, "dist/bin/rollup");
|
379
398
|
const multiBars = new cliProgress.MultiBar({
|
380
399
|
clearOnComplete: false,
|
381
400
|
hideCursor: true,
|
382
|
-
format: "- {bar} | {status} | {input} | {message}"
|
401
|
+
format: "- {bar} | {status} | {pkgName} | {input} | {message}"
|
383
402
|
}, cliProgress.Presets.shades_classic);
|
384
|
-
|
385
|
-
|
386
|
-
|
387
|
-
|
388
|
-
|
389
|
-
|
390
|
-
|
391
|
-
|
392
|
-
|
393
|
-
|
394
|
-
|
395
|
-
|
396
|
-
|
397
|
-
|
398
|
-
|
399
|
-
|
400
|
-
|
401
|
-
|
402
|
-
|
403
|
-
|
404
|
-
|
405
|
-
|
403
|
+
const buildPackage = async ({
|
404
|
+
wd,
|
405
|
+
value = {}
|
406
|
+
}) => {
|
407
|
+
if (Object.keys(value).length === 0) {
|
408
|
+
throw new Error("no package found");
|
409
|
+
}
|
410
|
+
const wdNodeModules = path__default.default.resolve(wd, "node_modules");
|
411
|
+
if (!fs__default.default.existsSync(wdNodeModules)) {
|
412
|
+
fs__default.default.mkdirSync(wdNodeModules);
|
413
|
+
}
|
414
|
+
const jiekTempDir = (...paths) => path__default.default.resolve(wdNodeModules, ".jiek", ...paths);
|
415
|
+
if (!fs__default.default.existsSync(jiekTempDir())) {
|
416
|
+
fs__default.default.mkdirSync(jiekTempDir());
|
417
|
+
}
|
418
|
+
const rollupBinaryPath = require$1.resolve("rollup").replace(/dist\/rollup.js$/, "dist/bin/rollup");
|
419
|
+
let i = 0;
|
420
|
+
await Promise.all(
|
421
|
+
Object.entries(value).map(async ([dir, manifest]) => {
|
422
|
+
const escapeManifestName = manifest.name?.replace(/^@/g, "").replace(/\//g, "+");
|
423
|
+
const configFile = jiekTempDir(
|
424
|
+
`${escapeManifestName ?? `anonymous-${i++}`}.rollup.config.js`
|
425
|
+
);
|
426
|
+
fs__default.default.writeFileSync(configFile, FILE_TEMPLATE(manifest));
|
427
|
+
let prefix = "";
|
428
|
+
if (tsRegisterName) {
|
429
|
+
prefix = `node -r ${tsRegisterName} `;
|
406
430
|
}
|
407
|
-
|
408
|
-
|
409
|
-
|
410
|
-
|
411
|
-
|
412
|
-
|
413
|
-
|
414
|
-
|
415
|
-
|
416
|
-
|
417
|
-
|
418
|
-
|
419
|
-
|
431
|
+
const command = `${prefix}${rollupBinaryPath} --silent -c ${configFile}`;
|
432
|
+
const child = execa.execaCommand(command, {
|
433
|
+
ipc: true,
|
434
|
+
cwd: dir,
|
435
|
+
env: {
|
436
|
+
...process.env,
|
437
|
+
JIEK_ROOT: wd,
|
438
|
+
JIEK_ENTRIES: entries,
|
439
|
+
JIEK_WITHOUT_JS: String(withoutJs),
|
440
|
+
JIEK_WITHOUT_DTS: String(withoutDts)
|
441
|
+
}
|
442
|
+
});
|
443
|
+
const bars = {};
|
444
|
+
let inputMaxLen = 10;
|
445
|
+
child.on("message", (e) => {
|
446
|
+
if (e.type === "debug")
|
447
|
+
console.log(...Array.isArray(e.data) ? e.data : [e.data]);
|
448
|
+
});
|
449
|
+
!silent && child.on("message", (e) => {
|
450
|
+
if (e.type === "init") {
|
451
|
+
const { leafMap, targetsLength } = e.data;
|
452
|
+
const leafs = Array.from(leafMap.entries()).flatMap(
|
453
|
+
([input, pathAndCondiions]) => pathAndCondiions.map(([path2, ...conditions]) => ({
|
454
|
+
input,
|
455
|
+
path: path2,
|
456
|
+
conditions
|
457
|
+
}))
|
458
|
+
);
|
459
|
+
console.log(`Package '${manifest.name}' has ${targetsLength} targets to build`);
|
460
|
+
leafs.forEach(({ input }) => {
|
461
|
+
inputMaxLen = Math.max(inputMaxLen, input.length);
|
462
|
+
});
|
463
|
+
leafs.forEach(({ input, path: path2 }) => {
|
464
|
+
const key = `${input}:${path2}`;
|
465
|
+
if (bars[key])
|
466
|
+
return;
|
467
|
+
bars[key] = multiBars.create(50, 0, {
|
468
|
+
pkgName: manifest.name,
|
469
|
+
input: input.padEnd(inputMaxLen),
|
470
|
+
status: "waiting".padEnd(10)
|
471
|
+
}, {
|
472
|
+
barsize: 20,
|
473
|
+
linewrap: true
|
474
|
+
});
|
475
|
+
});
|
476
|
+
}
|
477
|
+
if (e.type === "progress") {
|
478
|
+
const {
|
420
479
|
path: path2,
|
421
|
-
|
422
|
-
|
423
|
-
|
424
|
-
|
425
|
-
|
426
|
-
|
427
|
-
|
428
|
-
leafs.forEach(({ input, path: path2 }) => {
|
429
|
-
const key = `${input}:${path2}`;
|
430
|
-
if (bars[key])
|
480
|
+
tags,
|
481
|
+
input,
|
482
|
+
event,
|
483
|
+
message
|
484
|
+
} = e.data;
|
485
|
+
const bar = bars[`${input}:${path2}`];
|
486
|
+
if (!bar)
|
431
487
|
return;
|
432
|
-
|
433
|
-
|
434
|
-
|
435
|
-
|
436
|
-
|
437
|
-
|
438
|
-
|
439
|
-
|
440
|
-
|
441
|
-
|
442
|
-
|
443
|
-
|
444
|
-
|
445
|
-
input,
|
446
|
-
event,
|
447
|
-
message
|
448
|
-
} = e.data;
|
449
|
-
const bar = bars[`${input}:${path2}`];
|
450
|
-
if (!bar)
|
451
|
-
return;
|
452
|
-
bar.update(
|
453
|
-
{
|
454
|
-
start: 0,
|
455
|
-
resolve: 20,
|
456
|
-
end: 50
|
457
|
-
}[event ?? "start"] ?? 0,
|
458
|
-
{
|
459
|
-
input: input.padEnd(inputMaxLen),
|
460
|
-
status: event?.padEnd(10),
|
461
|
-
message: `${tags?.join(", ")}: ${message}`
|
462
|
-
}
|
463
|
-
);
|
464
|
-
}
|
465
|
-
});
|
466
|
-
await new Promise((resolve, reject) => {
|
467
|
-
let errorStr = "";
|
468
|
-
child.stderr?.on("data", (data) => {
|
469
|
-
errorStr += data;
|
488
|
+
bar.update(
|
489
|
+
{
|
490
|
+
start: 0,
|
491
|
+
resolve: 20,
|
492
|
+
end: 50
|
493
|
+
}[event ?? "start"] ?? 0,
|
494
|
+
{
|
495
|
+
input: input.padEnd(inputMaxLen),
|
496
|
+
status: event?.padEnd(10),
|
497
|
+
message: `${tags?.join(", ")}: ${message}`
|
498
|
+
}
|
499
|
+
);
|
500
|
+
}
|
470
501
|
});
|
471
|
-
|
502
|
+
await new Promise((resolve, reject) => {
|
503
|
+
let errorStr = "";
|
504
|
+
child.stderr?.on("data", (data) => {
|
505
|
+
errorStr += data;
|
506
|
+
});
|
507
|
+
child.once("exit", (code) => code === 0 ? resolve() : reject(new Error(`rollup build failed:
|
472
508
|
${errorStr}`)));
|
473
|
-
|
474
|
-
|
475
|
-
|
476
|
-
|
509
|
+
verbose && child.stdout?.pipe(process.stdout);
|
510
|
+
});
|
511
|
+
})
|
512
|
+
);
|
513
|
+
};
|
514
|
+
const filters = commander.program.getOptionValue("filter")?.split(",");
|
515
|
+
try {
|
516
|
+
if (filters) {
|
517
|
+
const packages = await filterPackagesGraph(filters);
|
518
|
+
await Promise.all(packages.map(buildPackage));
|
519
|
+
} else {
|
520
|
+
await buildPackage(await getSelectedProjectsGraph());
|
521
|
+
}
|
522
|
+
} finally {
|
477
523
|
multiBars.stop();
|
478
|
-
}
|
524
|
+
}
|
479
525
|
actionDone();
|
480
526
|
});
|
481
527
|
|
@@ -5041,7 +5087,11 @@ commander.program.command("publish").aliases(["pub", "p"]).option("-b, --bumper
|
|
5041
5087
|
console.warn("preview mode");
|
5042
5088
|
continue;
|
5043
5089
|
}
|
5044
|
-
|
5090
|
+
const args = ["pnpm", "publish", "--access", "public", "--no-git-checks", ...passArgs];
|
5091
|
+
if (bumper$1 && bumper.TAGS.includes(bumper$1)) {
|
5092
|
+
args.push("--tag", bumper$1);
|
5093
|
+
}
|
5094
|
+
childProcess__namespace.execSync(args.join(" "), {
|
5045
5095
|
cwd: dir,
|
5046
5096
|
stdio: "inherit"
|
5047
5097
|
});
|