jiek 2.0.1 → 2.0.2
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/cli-only-build.cjs +8 -6
- package/dist/cli-only-build.js +8 -6
- package/dist/cli.cjs +191 -469
- package/dist/cli.d.cts +0 -53
- package/dist/cli.d.ts +0 -53
- package/dist/cli.js +190 -467
- package/dist/index.d.cts +0 -53
- package/dist/index.d.ts +0 -53
- package/package.json +2 -2
- package/src/cli.ts +0 -1
- package/src/commands/build.ts +6 -4
- package/src/commands/init.ts +0 -373
package/dist/cli.cjs
CHANGED
@@ -1,20 +1,19 @@
|
|
1
1
|
'use strict';
|
2
2
|
|
3
|
+
var childProcess = require('node:child_process');
|
3
4
|
var fs = require('node:fs');
|
4
5
|
var path = require('node:path');
|
6
|
+
var bumper = require('@jiek/utils/bumper');
|
5
7
|
var commander = require('commander');
|
6
8
|
var detectIndent = require('detect-indent');
|
7
|
-
var inquirer = require('inquirer');
|
8
9
|
var jsoncParser = require('jsonc-parser');
|
9
|
-
var require$$0 = require('util');
|
10
|
-
var require$$0$1 = require('path');
|
11
|
-
var getWorkspaceDir = require('@jiek/utils/getWorkspaceDir');
|
12
10
|
var node_module = require('node:module');
|
13
11
|
var filterWorkspacePackages = require('@pnpm/filter-workspace-packages');
|
14
12
|
var jsYaml = require('js-yaml');
|
15
|
-
var
|
16
|
-
var bumper = require('@jiek/utils/bumper');
|
13
|
+
var getWorkspaceDir = require('@jiek/utils/getWorkspaceDir');
|
17
14
|
var entrypoints = require('@jiek/pkger/entrypoints');
|
15
|
+
var require$$0 = require('util');
|
16
|
+
var require$$0$1 = require('path');
|
18
17
|
require('jiek/cli-only-build');
|
19
18
|
|
20
19
|
var _documentCurrentScript = typeof document !== 'undefined' ? document.currentScript : null;
|
@@ -38,13 +37,114 @@ function _interopNamespace(e) {
|
|
38
37
|
return Object.freeze(n);
|
39
38
|
}
|
40
39
|
|
40
|
+
var childProcess__namespace = /*#__PURE__*/_interopNamespace(childProcess);
|
41
41
|
var fs__default = /*#__PURE__*/_interopDefault(fs);
|
42
42
|
var path__default = /*#__PURE__*/_interopDefault(path);
|
43
43
|
var detectIndent__default = /*#__PURE__*/_interopDefault(detectIndent);
|
44
|
-
var inquirer__default = /*#__PURE__*/_interopDefault(inquirer);
|
45
44
|
var require$$0__default = /*#__PURE__*/_interopDefault(require$$0);
|
46
45
|
var require$$0__default$1 = /*#__PURE__*/_interopDefault(require$$0$1);
|
47
|
-
|
46
|
+
|
47
|
+
let resolve;
|
48
|
+
function actionDone() {
|
49
|
+
resolve();
|
50
|
+
}
|
51
|
+
function actionRestore() {
|
52
|
+
new Promise((r) => resolve = r);
|
53
|
+
}
|
54
|
+
|
55
|
+
let root;
|
56
|
+
function getRoot() {
|
57
|
+
if (root)
|
58
|
+
return root;
|
59
|
+
const rootOption = commander.program.getOptionValue("root");
|
60
|
+
root = rootOption ? path__default.default.isAbsolute(rootOption) ? rootOption : path__default.default.resolve(process.cwd(), rootOption) : void 0;
|
61
|
+
return root;
|
62
|
+
}
|
63
|
+
|
64
|
+
let wd;
|
65
|
+
let notWorkspace = false;
|
66
|
+
function getWD() {
|
67
|
+
if (wd)
|
68
|
+
return { wd, notWorkspace };
|
69
|
+
const root = getRoot();
|
70
|
+
if (root !== void 0) {
|
71
|
+
const isWorkspace = getWorkspaceDir.isWorkspaceDir(root, type);
|
72
|
+
notWorkspace = !isWorkspace;
|
73
|
+
wd = root;
|
74
|
+
return { wd, notWorkspace };
|
75
|
+
}
|
76
|
+
try {
|
77
|
+
wd = getWorkspaceDir.getWorkspaceDir(type);
|
78
|
+
} catch (e) {
|
79
|
+
if ("message" in e && e.message === "workspace root not found") {
|
80
|
+
wd = root;
|
81
|
+
notWorkspace = true;
|
82
|
+
} else {
|
83
|
+
throw e;
|
84
|
+
}
|
85
|
+
}
|
86
|
+
return { wd, notWorkspace };
|
87
|
+
}
|
88
|
+
|
89
|
+
let type = "";
|
90
|
+
try {
|
91
|
+
const require$1 = node_module.createRequire((typeof document === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : (_documentCurrentScript && _documentCurrentScript.src || new URL('cli.cjs', document.baseURI).href)));
|
92
|
+
require$1.resolve("@pnpm/filter-workspace-packages");
|
93
|
+
type = "pnpm";
|
94
|
+
} catch {
|
95
|
+
}
|
96
|
+
async function getSelectedProjectsGraph(filter = commander.program.getOptionValue("filter")) {
|
97
|
+
let root = getRoot();
|
98
|
+
const { wd, notWorkspace } = getWD();
|
99
|
+
if (notWorkspace) {
|
100
|
+
return {
|
101
|
+
wd,
|
102
|
+
root,
|
103
|
+
value: {
|
104
|
+
[wd]: JSON.parse(fs__default.default.readFileSync(path__default.default.resolve(wd, "package.json"), "utf-8"))
|
105
|
+
}
|
106
|
+
};
|
107
|
+
}
|
108
|
+
if (type === "pnpm") {
|
109
|
+
const pnpmWorkspaceFilePath = path__default.default.resolve(wd, "pnpm-workspace.yaml");
|
110
|
+
const pnpmWorkspaceFileContent = fs__default.default.readFileSync(pnpmWorkspaceFilePath, "utf-8");
|
111
|
+
const pnpmWorkspace = jsYaml.load(pnpmWorkspaceFileContent);
|
112
|
+
if (root === wd && !filter) {
|
113
|
+
throw new Error("root path is workspace root, please provide a filter");
|
114
|
+
}
|
115
|
+
if (root === void 0) {
|
116
|
+
root = process.cwd();
|
117
|
+
}
|
118
|
+
if (root !== wd && !filter) {
|
119
|
+
const packageJSONIsExist = fs__default.default.existsSync(path__default.default.resolve(root, "package.json"));
|
120
|
+
if (!packageJSONIsExist) {
|
121
|
+
throw new Error("root path is not workspace root, please provide a filter");
|
122
|
+
}
|
123
|
+
const packageJSON = JSON.parse(fs__default.default.readFileSync(path__default.default.resolve(root, "package.json"), "utf-8"));
|
124
|
+
if (!packageJSON.name) {
|
125
|
+
throw new Error("root path is not workspace root, please provide a filter");
|
126
|
+
}
|
127
|
+
filter = packageJSON.name;
|
128
|
+
}
|
129
|
+
const { selectedProjectsGraph } = await filterWorkspacePackages.filterPackagesFromDir(wd, [{
|
130
|
+
filter: filter ?? "",
|
131
|
+
followProdDepsOnly: true
|
132
|
+
}], {
|
133
|
+
prefix: root,
|
134
|
+
workspaceDir: wd,
|
135
|
+
patterns: pnpmWorkspace.packages
|
136
|
+
});
|
137
|
+
return {
|
138
|
+
wd,
|
139
|
+
root,
|
140
|
+
value: Object.entries(selectedProjectsGraph).reduce((acc, [key, value]) => {
|
141
|
+
acc[key] = value.package.manifest;
|
142
|
+
return acc;
|
143
|
+
}, {})
|
144
|
+
};
|
145
|
+
}
|
146
|
+
throw new Error(`not supported package manager ${type}`);
|
147
|
+
}
|
48
148
|
|
49
149
|
var utils$1 = {};
|
50
150
|
|
@@ -4152,98 +4252,94 @@ function requireMicromatch () {
|
|
4152
4252
|
|
4153
4253
|
var micromatchExports = requireMicromatch();
|
4154
4254
|
|
4155
|
-
|
4156
|
-
|
4157
|
-
|
4158
|
-
|
4159
|
-
|
4160
|
-
|
4161
|
-
|
4162
|
-
|
4163
|
-
|
4164
|
-
|
4165
|
-
|
4166
|
-
const
|
4167
|
-
|
4168
|
-
type
|
4169
|
-
|
4170
|
-
|
4171
|
-
|
4172
|
-
|
4173
|
-
|
4174
|
-
if (notWorkspace) {
|
4175
|
-
return {
|
4176
|
-
wd,
|
4177
|
-
root,
|
4178
|
-
value: {
|
4179
|
-
[wd]: JSON.parse(fs__default.default.readFileSync(path__default.default.resolve(wd, "package.json"), "utf-8"))
|
4180
|
-
}
|
4181
|
-
};
|
4255
|
+
const intersection = (a, b) => new Set([...a].filter((i) => b.has(i)));
|
4256
|
+
const {
|
4257
|
+
JIEK_OUT_DIR
|
4258
|
+
} = process.env;
|
4259
|
+
const OUTDIR = JIEK_OUT_DIR ?? "dist";
|
4260
|
+
function getOutDirs({
|
4261
|
+
cwd = process.cwd(),
|
4262
|
+
defaultOutdir = OUTDIR,
|
4263
|
+
config,
|
4264
|
+
pkgName
|
4265
|
+
}) {
|
4266
|
+
const { build = {} } = config ?? {};
|
4267
|
+
const outdir = build?.output?.dir;
|
4268
|
+
function resolveOutdir(type) {
|
4269
|
+
const dir = (typeof outdir === "object" ? outdir[type] ?? outdir[{
|
4270
|
+
js: "dts",
|
4271
|
+
dts: "js"
|
4272
|
+
}[type]] : outdir) ?? defaultOutdir;
|
4273
|
+
return (path.isAbsolute(dir) ? dir : `./${path.relative(cwd, path.resolve(cwd, dir))}`).replace("{{PKG_NAME}}", pkgName);
|
4182
4274
|
}
|
4183
|
-
|
4184
|
-
|
4185
|
-
|
4186
|
-
|
4187
|
-
|
4188
|
-
|
4189
|
-
|
4190
|
-
|
4191
|
-
|
4192
|
-
|
4193
|
-
|
4194
|
-
|
4195
|
-
|
4196
|
-
|
4197
|
-
|
4198
|
-
|
4199
|
-
|
4200
|
-
|
4275
|
+
return {
|
4276
|
+
js: resolveOutdir("js"),
|
4277
|
+
dts: resolveOutdir("dts")
|
4278
|
+
};
|
4279
|
+
}
|
4280
|
+
function getExports({
|
4281
|
+
entrypoints: entrypoints$1,
|
4282
|
+
pkgName,
|
4283
|
+
pkgIsModule,
|
4284
|
+
entries,
|
4285
|
+
config,
|
4286
|
+
dir,
|
4287
|
+
defaultOutdir = OUTDIR,
|
4288
|
+
// FIXME dts support
|
4289
|
+
outdir = getOutDirs({ pkgName, defaultOutdir, config, cwd: dir }).js,
|
4290
|
+
noFilter,
|
4291
|
+
isPublish
|
4292
|
+
}) {
|
4293
|
+
const {
|
4294
|
+
build = {},
|
4295
|
+
publish: {
|
4296
|
+
withSuffix = false,
|
4297
|
+
withSource = true
|
4298
|
+
} = {}
|
4299
|
+
} = config ?? {};
|
4300
|
+
const {
|
4301
|
+
crossModuleConvertor = true
|
4302
|
+
} = build;
|
4303
|
+
const [, resolvedEntrypoints] = entrypoints.resolveEntrypoints(entrypoints$1);
|
4304
|
+
if (entries) {
|
4305
|
+
Object.entries(resolvedEntrypoints).forEach(([key]) => {
|
4306
|
+
if (!entries.some((e) => micromatchExports.isMatch(key, e, { matchBase: true }))) {
|
4307
|
+
delete resolvedEntrypoints[key];
|
4201
4308
|
}
|
4202
|
-
filter = packageJSON.name;
|
4203
|
-
}
|
4204
|
-
const { selectedProjectsGraph } = await filterWorkspacePackages.filterPackagesFromDir(wd, [{
|
4205
|
-
filter: filter ?? "",
|
4206
|
-
followProdDepsOnly: true
|
4207
|
-
}], {
|
4208
|
-
prefix: root,
|
4209
|
-
workspaceDir: wd,
|
4210
|
-
patterns: pnpmWorkspace.packages
|
4211
4309
|
});
|
4212
|
-
return {
|
4213
|
-
wd,
|
4214
|
-
root,
|
4215
|
-
value: Object.entries(selectedProjectsGraph).reduce((acc, [key, value]) => {
|
4216
|
-
acc[key] = value.package.manifest;
|
4217
|
-
return acc;
|
4218
|
-
}, {})
|
4219
|
-
};
|
4220
|
-
}
|
4221
|
-
throw new Error(`not supported package manager ${type}`);
|
4222
|
-
}
|
4223
|
-
|
4224
|
-
let wd;
|
4225
|
-
let notWorkspace = false;
|
4226
|
-
function getWD() {
|
4227
|
-
if (wd)
|
4228
|
-
return { wd, notWorkspace };
|
4229
|
-
const root = getRoot();
|
4230
|
-
if (root !== void 0) {
|
4231
|
-
const isWorkspace = getWorkspaceDir.isWorkspaceDir(root, type);
|
4232
|
-
notWorkspace = !isWorkspace;
|
4233
|
-
wd = root;
|
4234
|
-
return { wd, notWorkspace };
|
4235
4310
|
}
|
4236
|
-
|
4237
|
-
|
4238
|
-
|
4239
|
-
|
4240
|
-
|
4241
|
-
|
4242
|
-
|
4243
|
-
|
4311
|
+
const filteredResolvedEntrypoints = noFilter ? resolvedEntrypoints : entrypoints.filterLeafs(
|
4312
|
+
resolvedEntrypoints,
|
4313
|
+
{
|
4314
|
+
skipValue: [
|
4315
|
+
// ignore values that filename starts with `.jk-noentry`
|
4316
|
+
/(^|\/)\.jk-noentry/,
|
4317
|
+
...entrypoints.DEFAULT_SKIP_VALUES
|
4318
|
+
]
|
4244
4319
|
}
|
4245
|
-
|
4246
|
-
|
4320
|
+
);
|
4321
|
+
const crossModuleWithConditional = crossModuleConvertor ? {
|
4322
|
+
import: (opts) => !pkgIsModule && intersection(
|
4323
|
+
new Set(opts.conditionals),
|
4324
|
+
/* @__PURE__ */ new Set(["import", "module"])
|
4325
|
+
).size === 0 ? opts.dist.replace(/\.js$/, ".mjs") : false,
|
4326
|
+
require: (opts) => pkgIsModule && intersection(
|
4327
|
+
new Set(opts.conditionals),
|
4328
|
+
/* @__PURE__ */ new Set(["require", "node"])
|
4329
|
+
).size === 0 ? opts.dist.replace(/\.js$/, ".cjs") : false
|
4330
|
+
} : {};
|
4331
|
+
return [
|
4332
|
+
filteredResolvedEntrypoints,
|
4333
|
+
entrypoints.entrypoints2Exports(filteredResolvedEntrypoints, {
|
4334
|
+
outdir,
|
4335
|
+
withSuffix: isPublish ? withSuffix : void 0,
|
4336
|
+
withSource: isPublish ? withSource : void 0,
|
4337
|
+
withConditional: {
|
4338
|
+
...crossModuleWithConditional
|
4339
|
+
}
|
4340
|
+
}),
|
4341
|
+
outdir
|
4342
|
+
];
|
4247
4343
|
}
|
4248
4344
|
|
4249
4345
|
const require$2 = node_module.createRequire((typeof document === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : (_documentCurrentScript && _documentCurrentScript.src || new URL('cli.cjs', document.baseURI).href)));
|
@@ -4352,380 +4448,6 @@ function loadConfig(dirOrOptions) {
|
|
4352
4448
|
return module.default ?? module;
|
4353
4449
|
}
|
4354
4450
|
|
4355
|
-
const PACKAGE_JSON_TEMPLATE = `{
|
4356
|
-
"name": "",
|
4357
|
-
"version": "0.0.1",
|
4358
|
-
"description": "",
|
4359
|
-
"license": "",
|
4360
|
-
"author": "",
|
4361
|
-
"files": ["dist"],
|
4362
|
-
"exports": {
|
4363
|
-
".": "./src/index.ts"
|
4364
|
-
},
|
4365
|
-
"scripts": {
|
4366
|
-
},
|
4367
|
-
"homepage": "",
|
4368
|
-
"repository": "",
|
4369
|
-
"bugs": ""
|
4370
|
-
}`.trimStart();
|
4371
|
-
const README_TEMPLATE = `# $name
|
4372
|
-
|
4373
|
-
## Installation
|
4374
|
-
|
4375
|
-
\`\`\`bash
|
4376
|
-
npm install $name
|
4377
|
-
# or
|
4378
|
-
pnpm install $name
|
4379
|
-
# or
|
4380
|
-
yarn add $name
|
4381
|
-
\`\`\`
|
4382
|
-
|
4383
|
-
## Usage
|
4384
|
-
|
4385
|
-
|
4386
|
-
## License
|
4387
|
-
|
4388
|
-
$license
|
4389
|
-
`.trimStart();
|
4390
|
-
function getTemplateStr(wd, template) {
|
4391
|
-
let templateString = template ?? PACKAGE_JSON_TEMPLATE;
|
4392
|
-
let isTemplateFile = false;
|
4393
|
-
try {
|
4394
|
-
if (template)
|
4395
|
-
JSON.parse(template);
|
4396
|
-
} catch (e) {
|
4397
|
-
isTemplateFile = true;
|
4398
|
-
}
|
4399
|
-
if (isTemplateFile) {
|
4400
|
-
const templatePath = path__default.default.resolve(wd, template);
|
4401
|
-
templateString = fs__default.default.readFileSync(templatePath, "utf-8");
|
4402
|
-
}
|
4403
|
-
return templateString;
|
4404
|
-
}
|
4405
|
-
const wdCache = /* @__PURE__ */ new Map();
|
4406
|
-
function getWDPackageJSONFiled(wd, field) {
|
4407
|
-
if (wdCache.has(wd)) {
|
4408
|
-
return wdCache.get(wd)[field];
|
4409
|
-
}
|
4410
|
-
const packageJSONPath = path__default.default.resolve(wd, "package.json");
|
4411
|
-
const packageJSON = JSON.parse(fs__default.default.readFileSync(packageJSONPath, "utf-8"));
|
4412
|
-
wdCache.set(wd, packageJSON);
|
4413
|
-
return packageJSON[field];
|
4414
|
-
}
|
4415
|
-
async function getName(named, name, {
|
4416
|
-
wd,
|
4417
|
-
cwd,
|
4418
|
-
workspaceName
|
4419
|
-
}) {
|
4420
|
-
const relativePath = cwd.replace(`${wd}/`, "");
|
4421
|
-
let basename = path__default.default.basename(cwd);
|
4422
|
-
if (typeof named === "function") {
|
4423
|
-
return named(name, {
|
4424
|
-
full: wd,
|
4425
|
-
relative: cwd
|
4426
|
-
});
|
4427
|
-
}
|
4428
|
-
let isParentMatched = false;
|
4429
|
-
let matchedKey;
|
4430
|
-
let matchedRule;
|
4431
|
-
if (typeof named === "object") {
|
4432
|
-
const isWD = cwd === wd;
|
4433
|
-
if (isWD) {
|
4434
|
-
const { rule } = await inquirer__default.default.prompt({
|
4435
|
-
type: "list",
|
4436
|
-
name: "rule",
|
4437
|
-
message: "choose a rule",
|
4438
|
-
default: "default",
|
4439
|
-
choices: ["default"].concat(Object.keys(named))
|
4440
|
-
});
|
4441
|
-
if (rule !== "default") {
|
4442
|
-
matchedKey = rule;
|
4443
|
-
matchedRule = named[rule];
|
4444
|
-
}
|
4445
|
-
} else {
|
4446
|
-
for (const [key, value] of Object.entries(named)) {
|
4447
|
-
if (micromatchExports.isMatch(relativePath, key)) {
|
4448
|
-
matchedKey = key;
|
4449
|
-
matchedRule = value;
|
4450
|
-
break;
|
4451
|
-
}
|
4452
|
-
if (micromatchExports.isMatch(`${relativePath}/jiek_ignore_dont_use_same_file_name`, key)) {
|
4453
|
-
isParentMatched = true;
|
4454
|
-
matchedKey = key;
|
4455
|
-
matchedRule = value;
|
4456
|
-
break;
|
4457
|
-
}
|
4458
|
-
}
|
4459
|
-
}
|
4460
|
-
}
|
4461
|
-
if (!matchedRule) {
|
4462
|
-
matchedKey = "packages/*";
|
4463
|
-
matchedRule = `@${workspaceName}/$basename`;
|
4464
|
-
}
|
4465
|
-
if (!matchedRule) {
|
4466
|
-
throw new Error("no matched rule");
|
4467
|
-
}
|
4468
|
-
if (!name && isParentMatched) {
|
4469
|
-
basename = await inquirer__default.default.prompt({
|
4470
|
-
type: "input",
|
4471
|
-
name: "name",
|
4472
|
-
message: `the matched rule is \`${String(matchedRule)}\`, please input the basename
|
4473
|
-
`
|
4474
|
-
}).then(({ name: name2 }) => name2);
|
4475
|
-
}
|
4476
|
-
if (typeof matchedRule === "function") {
|
4477
|
-
return matchedRule(name, {
|
4478
|
-
full: wd,
|
4479
|
-
relative: cwd,
|
4480
|
-
basename
|
4481
|
-
});
|
4482
|
-
}
|
4483
|
-
if (typeof matchedRule === "string") {
|
4484
|
-
const dirName = name ?? basename;
|
4485
|
-
return [
|
4486
|
-
matchedRule.replace(/\$basename/g, dirName),
|
4487
|
-
matchedKey?.replace(/\/\*$/g, `/${dirName}`)
|
4488
|
-
];
|
4489
|
-
}
|
4490
|
-
throw new Error("no matched rule");
|
4491
|
-
}
|
4492
|
-
commander.program.command("init [name]").option("-t, --template <template>", "the package.json template file path or file content").action(async () => {
|
4493
|
-
const [, name] = commander.program.args;
|
4494
|
-
const cwd = process.cwd();
|
4495
|
-
const { init = {} } = loadConfig() ?? {};
|
4496
|
-
const { wd } = getWD();
|
4497
|
-
const workspaceName = path__default.default.basename(wd);
|
4498
|
-
const {
|
4499
|
-
named,
|
4500
|
-
template,
|
4501
|
-
bug = {},
|
4502
|
-
readme: _readme = README_TEMPLATE,
|
4503
|
-
readmeTemplate
|
4504
|
-
} = init;
|
4505
|
-
const resolvedBug = {
|
4506
|
-
template: "bug_report.yml",
|
4507
|
-
labels: ["bug"],
|
4508
|
-
...bug
|
4509
|
-
};
|
4510
|
-
let readme = _readme;
|
4511
|
-
if (readmeTemplate) {
|
4512
|
-
const readmeTemplatePath = path__default.default.resolve(wd, readmeTemplate);
|
4513
|
-
readme = fs__default.default.readFileSync(readmeTemplatePath, "utf-8");
|
4514
|
-
}
|
4515
|
-
const templateString = getTemplateStr(wd, template);
|
4516
|
-
const { indent = " " } = detectIndent__default.default(templateString);
|
4517
|
-
const formattingOptions = {
|
4518
|
-
tabSize: indent.length,
|
4519
|
-
insertSpaces: true
|
4520
|
-
};
|
4521
|
-
const passFields = [
|
4522
|
-
"license",
|
4523
|
-
"author"
|
4524
|
-
];
|
4525
|
-
let newJSONString = templateString;
|
4526
|
-
for (const field of passFields) {
|
4527
|
-
newJSONString = jsoncParser.applyEdits(
|
4528
|
-
newJSONString,
|
4529
|
-
jsoncParser.modify(
|
4530
|
-
newJSONString,
|
4531
|
-
[field],
|
4532
|
-
getWDPackageJSONFiled(wd, field),
|
4533
|
-
{ formattingOptions }
|
4534
|
-
)
|
4535
|
-
);
|
4536
|
-
}
|
4537
|
-
let [pkgName, pkgDir] = await getName(named, name, {
|
4538
|
-
wd,
|
4539
|
-
cwd,
|
4540
|
-
workspaceName
|
4541
|
-
});
|
4542
|
-
if (!pkgDir) {
|
4543
|
-
const { dir } = await inquirer__default.default.prompt({
|
4544
|
-
type: "input",
|
4545
|
-
name: "dir",
|
4546
|
-
message: "package directory",
|
4547
|
-
default: name
|
4548
|
-
});
|
4549
|
-
pkgDir = dir;
|
4550
|
-
}
|
4551
|
-
if (!pkgName) {
|
4552
|
-
const { name: inputName } = await inquirer__default.default.prompt({
|
4553
|
-
type: "input",
|
4554
|
-
name: "name",
|
4555
|
-
message: "package name",
|
4556
|
-
default: name
|
4557
|
-
});
|
4558
|
-
pkgName = inputName;
|
4559
|
-
}
|
4560
|
-
newJSONString = jsoncParser.applyEdits(newJSONString, jsoncParser.modify(newJSONString, ["name"], pkgName, { formattingOptions }));
|
4561
|
-
let pkgRepo = getWDPackageJSONFiled(wd, "repository");
|
4562
|
-
if (typeof pkgRepo === "string") {
|
4563
|
-
pkgRepo = {
|
4564
|
-
type: "git",
|
4565
|
-
url: pkgRepo,
|
4566
|
-
directory: pkgDir
|
4567
|
-
};
|
4568
|
-
}
|
4569
|
-
newJSONString = jsoncParser.applyEdits(
|
4570
|
-
newJSONString,
|
4571
|
-
jsoncParser.modify(
|
4572
|
-
newJSONString,
|
4573
|
-
["repository"],
|
4574
|
-
pkgRepo,
|
4575
|
-
{ formattingOptions }
|
4576
|
-
)
|
4577
|
-
);
|
4578
|
-
const homepage = `${pkgRepo?.url}/blob/master/${pkgDir}/README.md`;
|
4579
|
-
newJSONString = jsoncParser.applyEdits(
|
4580
|
-
newJSONString,
|
4581
|
-
jsoncParser.modify(
|
4582
|
-
newJSONString,
|
4583
|
-
["homepage"],
|
4584
|
-
homepage,
|
4585
|
-
{ formattingOptions }
|
4586
|
-
)
|
4587
|
-
);
|
4588
|
-
let labels = resolvedBug.labels;
|
4589
|
-
if (typeof labels === "function") {
|
4590
|
-
labels = labels({
|
4591
|
-
name: pkgName,
|
4592
|
-
dir: pkgDir
|
4593
|
-
});
|
4594
|
-
}
|
4595
|
-
labels.push(`scope:${pkgName}`);
|
4596
|
-
const bugs = `${pkgRepo?.url}/issues/new?template=${resolvedBug.template}&labels=${labels.join(",")}`;
|
4597
|
-
newJSONString = jsoncParser.applyEdits(
|
4598
|
-
newJSONString,
|
4599
|
-
jsoncParser.modify(
|
4600
|
-
newJSONString,
|
4601
|
-
["bugs"],
|
4602
|
-
bugs,
|
4603
|
-
{ formattingOptions }
|
4604
|
-
)
|
4605
|
-
);
|
4606
|
-
function pkgDirTo(to) {
|
4607
|
-
if (!pkgDir)
|
4608
|
-
throw new Error("pkgDir is not defined");
|
4609
|
-
return path__default.default.resolve(pkgDir, to);
|
4610
|
-
}
|
4611
|
-
if (!fs__default.default.existsSync(pkgDir))
|
4612
|
-
fs__default.default.mkdirSync(pkgDir);
|
4613
|
-
const pkgJSONFilePath = pkgDirTo("package.json");
|
4614
|
-
if (fs__default.default.existsSync(pkgJSONFilePath)) {
|
4615
|
-
throw new Error("package.json already exists");
|
4616
|
-
}
|
4617
|
-
fs__default.default.writeFileSync(pkgJSONFilePath, newJSONString);
|
4618
|
-
console.log(newJSONString, "written to", pkgJSONFilePath);
|
4619
|
-
const license = getWDPackageJSONFiled(wd, "license");
|
4620
|
-
const readmeFilePath = pkgDirTo("README.md");
|
4621
|
-
if (typeof readme === "function") {
|
4622
|
-
readme = readme({
|
4623
|
-
dir: pkgDir,
|
4624
|
-
packageJson: JSON.parse(newJSONString)
|
4625
|
-
});
|
4626
|
-
}
|
4627
|
-
const readmeContent = readme.replace(/\$name/g, pkgName).replace(/\$license/g, license);
|
4628
|
-
fs__default.default.writeFileSync(readmeFilePath, readmeContent);
|
4629
|
-
});
|
4630
|
-
|
4631
|
-
let resolve;
|
4632
|
-
function actionDone() {
|
4633
|
-
resolve();
|
4634
|
-
}
|
4635
|
-
function actionRestore() {
|
4636
|
-
new Promise((r) => resolve = r);
|
4637
|
-
}
|
4638
|
-
|
4639
|
-
const intersection = (a, b) => new Set([...a].filter((i) => b.has(i)));
|
4640
|
-
const {
|
4641
|
-
JIEK_OUT_DIR
|
4642
|
-
} = process.env;
|
4643
|
-
const OUTDIR = JIEK_OUT_DIR ?? "dist";
|
4644
|
-
function getOutDirs({
|
4645
|
-
cwd = process.cwd(),
|
4646
|
-
defaultOutdir = OUTDIR,
|
4647
|
-
config,
|
4648
|
-
pkgName
|
4649
|
-
}) {
|
4650
|
-
const { build = {} } = config ?? {};
|
4651
|
-
const outdir = build?.output?.dir;
|
4652
|
-
function resolveOutdir(type) {
|
4653
|
-
const dir = (typeof outdir === "object" ? outdir[type] ?? outdir[{
|
4654
|
-
js: "dts",
|
4655
|
-
dts: "js"
|
4656
|
-
}[type]] : outdir) ?? defaultOutdir;
|
4657
|
-
return (path.isAbsolute(dir) ? dir : `./${path.relative(cwd, path.resolve(cwd, dir))}`).replace("{{PKG_NAME}}", pkgName);
|
4658
|
-
}
|
4659
|
-
return {
|
4660
|
-
js: resolveOutdir("js"),
|
4661
|
-
dts: resolveOutdir("dts")
|
4662
|
-
};
|
4663
|
-
}
|
4664
|
-
function getExports({
|
4665
|
-
entrypoints: entrypoints$1,
|
4666
|
-
pkgName,
|
4667
|
-
pkgIsModule,
|
4668
|
-
entries,
|
4669
|
-
config,
|
4670
|
-
dir,
|
4671
|
-
defaultOutdir = OUTDIR,
|
4672
|
-
// FIXME dts support
|
4673
|
-
outdir = getOutDirs({ pkgName, defaultOutdir, config, cwd: dir }).js,
|
4674
|
-
noFilter,
|
4675
|
-
isPublish
|
4676
|
-
}) {
|
4677
|
-
const {
|
4678
|
-
build = {},
|
4679
|
-
publish: {
|
4680
|
-
withSuffix = false,
|
4681
|
-
withSource = true
|
4682
|
-
} = {}
|
4683
|
-
} = config ?? {};
|
4684
|
-
const {
|
4685
|
-
crossModuleConvertor = true
|
4686
|
-
} = build;
|
4687
|
-
const [, resolvedEntrypoints] = entrypoints.resolveEntrypoints(entrypoints$1);
|
4688
|
-
if (entries) {
|
4689
|
-
Object.entries(resolvedEntrypoints).forEach(([key]) => {
|
4690
|
-
if (!entries.some((e) => micromatchExports.isMatch(key, e, { matchBase: true }))) {
|
4691
|
-
delete resolvedEntrypoints[key];
|
4692
|
-
}
|
4693
|
-
});
|
4694
|
-
}
|
4695
|
-
const filteredResolvedEntrypoints = noFilter ? resolvedEntrypoints : entrypoints.filterLeafs(
|
4696
|
-
resolvedEntrypoints,
|
4697
|
-
{
|
4698
|
-
skipValue: [
|
4699
|
-
// ignore values that filename starts with `.jk-noentry`
|
4700
|
-
/(^|\/)\.jk-noentry/,
|
4701
|
-
...entrypoints.DEFAULT_SKIP_VALUES
|
4702
|
-
]
|
4703
|
-
}
|
4704
|
-
);
|
4705
|
-
const crossModuleWithConditional = crossModuleConvertor ? {
|
4706
|
-
import: (opts) => !pkgIsModule && intersection(
|
4707
|
-
new Set(opts.conditionals),
|
4708
|
-
/* @__PURE__ */ new Set(["import", "module"])
|
4709
|
-
).size === 0 ? opts.dist.replace(/\.js$/, ".mjs") : false,
|
4710
|
-
require: (opts) => pkgIsModule && intersection(
|
4711
|
-
new Set(opts.conditionals),
|
4712
|
-
/* @__PURE__ */ new Set(["require", "node"])
|
4713
|
-
).size === 0 ? opts.dist.replace(/\.js$/, ".cjs") : false
|
4714
|
-
} : {};
|
4715
|
-
return [
|
4716
|
-
filteredResolvedEntrypoints,
|
4717
|
-
entrypoints.entrypoints2Exports(filteredResolvedEntrypoints, {
|
4718
|
-
outdir,
|
4719
|
-
withSuffix: isPublish ? withSuffix : void 0,
|
4720
|
-
withSource: isPublish ? withSource : void 0,
|
4721
|
-
withConditional: {
|
4722
|
-
...crossModuleWithConditional
|
4723
|
-
}
|
4724
|
-
}),
|
4725
|
-
outdir
|
4726
|
-
];
|
4727
|
-
}
|
4728
|
-
|
4729
4451
|
const outdirDescription = `
|
4730
4452
|
The output directory of the build, which relative to the target subpackage root directory.
|
4731
4453
|
Support with variables: 'PKG_NAME',
|