jiek 0.4.6 → 0.4.7-alpha.1
Sign up to get free protection for your applications and to get access to all the features.
- package/README.md +22 -1
- package/bin/jiek.js +2 -1
- package/dist/cli.d.mts +97 -0
- package/dist/cli.d.mts.map +1 -0
- package/dist/cli.d.ts +96 -1
- package/dist/cli.d.ts.map +1 -0
- package/dist/{cli.cjs → cli.js} +355 -231
- package/dist/cli.js.map +1 -0
- package/dist/cli.min.js +1 -0
- package/dist/cli.min.js.map +1 -0
- package/dist/cli.min.mjs +1 -0
- package/dist/cli.min.mjs.map +1 -0
- package/dist/cli.mjs +803 -0
- package/dist/cli.mjs.map +1 -0
- package/dist/index.d.mts +58 -0
- package/dist/index.d.mts.map +1 -0
- package/dist/index.d.ts +47 -46
- package/dist/index.d.ts.map +1 -0
- package/dist/{index.cjs → index.js} +0 -1
- package/dist/index.js.map +1 -0
- package/dist/{index.min.cjs → index.min.js} +0 -1
- package/dist/index.min.js.map +1 -0
- package/dist/index.min.mjs +1 -0
- package/dist/index.min.mjs.map +1 -0
- package/dist/{index.esm.js → index.mjs} +0 -1
- package/dist/index.mjs.map +1 -0
- package/dist/rollup/index.d.mts +53 -0
- package/dist/rollup/index.d.mts.map +1 -0
- package/dist/rollup/index.d.ts +53 -0
- package/dist/rollup/index.d.ts.map +1 -0
- package/dist/rollup/index.js +553 -0
- package/dist/rollup/index.js.map +1 -0
- package/dist/rollup/index.min.js +1 -0
- package/dist/rollup/index.min.js.map +1 -0
- package/dist/rollup/index.min.mjs +1 -0
- package/dist/rollup/index.min.mjs.map +1 -0
- package/dist/rollup/index.mjs +551 -0
- package/dist/rollup/index.mjs.map +1 -0
- package/package.json +52 -35
- package/src/cli.ts +9 -0
- package/src/commands/base.ts +9 -0
- package/src/commands/build.ts +156 -0
- package/src/commands/init.ts +373 -0
- package/src/commands/publish.ts +156 -0
- package/src/index.ts +8 -0
- package/src/inner.ts +11 -0
- package/src/merge-package-json.ts +75 -0
- package/src/pkg.ts +1 -0
- package/src/rollup/base.ts +72 -0
- package/src/rollup/index.ts +420 -0
- package/src/rollup/plugins/globals.ts +34 -0
- package/src/rollup/plugins/progress.ts +26 -0
- package/src/rollup/plugins/skip.ts +23 -0
- package/src/rollup/utils/commonOptions.ts +9 -0
- package/src/rollup/utils/externalResolver.ts +21 -0
- package/src/rollup/utils/globalResolver.ts +13 -0
- package/src/rollup/utils/withMinify.ts +18 -0
- package/src/utils/filterSupport.ts +82 -0
- package/src/utils/getExports.ts +100 -0
- package/src/utils/getRoot.ts +16 -0
- package/src/utils/getWD.ts +31 -0
- package/src/utils/loadConfig.ts +93 -0
- package/src/utils/tsRegister.ts +22 -0
- package/dist/base.esm.d.ts +0 -55
- package/dist/cli.cjs.map +0 -1
- package/dist/cli.esm.d.ts +0 -2
- package/dist/cli.esm.js +0 -9
- package/dist/cli.esm.js.map +0 -1
- package/dist/cli.esm.min.js +0 -2
- package/dist/cli.esm.min.js.map +0 -1
- package/dist/cli.min.cjs +0 -2
- package/dist/cli.min.cjs.map +0 -1
- package/dist/commands/base.esm.js +0 -5
- package/dist/commands/base.esm.js.map +0 -1
- package/dist/commands/base.esm.min.js +0 -2
- package/dist/commands/base.esm.min.js.map +0 -1
- package/dist/commands/build.esm.js +0 -58
- package/dist/commands/build.esm.js.map +0 -1
- package/dist/commands/build.esm.min.js +0 -2
- package/dist/commands/build.esm.min.js.map +0 -1
- package/dist/commands/init.esm.js +0 -271
- package/dist/commands/init.esm.js.map +0 -1
- package/dist/commands/init.esm.min.js +0 -2
- package/dist/commands/init.esm.min.js.map +0 -1
- package/dist/commands/publish.esm.js +0 -87
- package/dist/commands/publish.esm.js.map +0 -1
- package/dist/commands/publish.esm.min.js +0 -2
- package/dist/commands/publish.esm.min.js.map +0 -1
- package/dist/index.cjs.map +0 -1
- package/dist/index.esm.d.ts +0 -6
- package/dist/index.esm.js.map +0 -1
- package/dist/index.esm.min.js +0 -2
- package/dist/index.esm.min.js.map +0 -1
- package/dist/index.min.cjs.map +0 -1
- package/dist/inner.esm.js +0 -10
- package/dist/inner.esm.js.map +0 -1
- package/dist/inner.esm.min.js +0 -2
- package/dist/inner.esm.min.js.map +0 -1
- package/dist/merge-package-json.esm.js +0 -64
- package/dist/merge-package-json.esm.js.map +0 -1
- package/dist/merge-package-json.esm.min.js +0 -2
- package/dist/merge-package-json.esm.min.js.map +0 -1
- package/dist/pkg.esm.js +0 -4
- package/dist/pkg.esm.js.map +0 -1
- package/dist/pkg.esm.min.js +0 -2
- package/dist/pkg.esm.min.js.map +0 -1
- package/dist/rollup/plugins/globals.esm.js +0 -31
- package/dist/rollup/plugins/globals.esm.js.map +0 -1
- package/dist/rollup/plugins/globals.esm.min.js +0 -2
- package/dist/rollup/plugins/globals.esm.min.js.map +0 -1
- package/dist/rollup/plugins/skip.esm.js +0 -16
- package/dist/rollup/plugins/skip.esm.js.map +0 -1
- package/dist/rollup/plugins/skip.esm.min.js +0 -2
- package/dist/rollup/plugins/skip.esm.min.js.map +0 -1
- package/dist/rollup/utils/commonOptions.esm.js +0 -9
- package/dist/rollup/utils/commonOptions.esm.js.map +0 -1
- package/dist/rollup/utils/commonOptions.esm.min.js +0 -2
- package/dist/rollup/utils/commonOptions.esm.min.js.map +0 -1
- package/dist/rollup/utils/externalResolver.esm.js +0 -12
- package/dist/rollup/utils/externalResolver.esm.js.map +0 -1
- package/dist/rollup/utils/externalResolver.esm.min.js +0 -2
- package/dist/rollup/utils/externalResolver.esm.min.js.map +0 -1
- package/dist/rollup/utils/globalResolver.esm.js +0 -9
- package/dist/rollup/utils/globalResolver.esm.js.map +0 -1
- package/dist/rollup/utils/globalResolver.esm.min.js +0 -2
- package/dist/rollup/utils/globalResolver.esm.min.js.map +0 -1
- package/dist/rollup/utils/withMinify.esm.js +0 -15
- package/dist/rollup/utils/withMinify.esm.js.map +0 -1
- package/dist/rollup/utils/withMinify.esm.min.js +0 -2
- package/dist/rollup/utils/withMinify.esm.min.js.map +0 -1
- package/dist/rollup.cjs +0 -330
- package/dist/rollup.cjs.map +0 -1
- package/dist/rollup.d.ts +0 -23
- package/dist/rollup.esm.d.ts +0 -23
- package/dist/rollup.esm.js +0 -248
- package/dist/rollup.esm.js.map +0 -1
- package/dist/rollup.esm.min.js +0 -2
- package/dist/rollup.esm.min.js.map +0 -1
- package/dist/rollup.min.cjs +0 -2
- package/dist/rollup.min.cjs.map +0 -1
- package/dist/utils/commondir.esm.js +0 -25
- package/dist/utils/commondir.esm.js.map +0 -1
- package/dist/utils/commondir.esm.min.js +0 -2
- package/dist/utils/commondir.esm.min.js.map +0 -1
- package/dist/utils/filterSupport.esm.js +0 -67
- package/dist/utils/filterSupport.esm.js.map +0 -1
- package/dist/utils/filterSupport.esm.min.js +0 -2
- package/dist/utils/filterSupport.esm.min.js.map +0 -1
- package/dist/utils/getRoot.esm.js +0 -14
- package/dist/utils/getRoot.esm.js.map +0 -1
- package/dist/utils/getRoot.esm.min.js +0 -2
- package/dist/utils/getRoot.esm.min.js.map +0 -1
- package/dist/utils/getWD.esm.js +0 -31
- package/dist/utils/getWD.esm.js.map +0 -1
- package/dist/utils/getWD.esm.min.js +0 -2
- package/dist/utils/getWD.esm.min.js.map +0 -1
- package/dist/utils/loadConfig.esm.js +0 -75
- package/dist/utils/loadConfig.esm.js.map +0 -1
- package/dist/utils/loadConfig.esm.min.js +0 -2
- package/dist/utils/loadConfig.esm.min.js.map +0 -1
- package/dist/utils/tsRegister.esm.js +0 -24
- package/dist/utils/tsRegister.esm.js.map +0 -1
- package/dist/utils/tsRegister.esm.min.js +0 -2
- package/dist/utils/tsRegister.esm.min.js.map +0 -1
package/dist/{cli.cjs → cli.js}
RENAMED
@@ -6,18 +6,17 @@ var filterWorkspacePackages = require('@pnpm/filter-workspace-packages');
|
|
6
6
|
var commander = require('commander');
|
7
7
|
var jsYaml = require('js-yaml');
|
8
8
|
var getWorkspaceDir = require('@jiek/utils/getWorkspaceDir');
|
9
|
-
var
|
10
|
-
var
|
9
|
+
var cliProgress = require('cli-progress');
|
10
|
+
var execa = require('execa');
|
11
11
|
var detectIndent = require('detect-indent');
|
12
12
|
var inquirer = require('inquirer');
|
13
13
|
var jsoncParser = require('jsonc-parser');
|
14
14
|
var micromatch = require('micromatch');
|
15
|
+
var childProcess = require('node:child_process');
|
15
16
|
var bumper = require('@jiek/utils/bumper');
|
17
|
+
var entrypoints = require('@jiek/pkger/entrypoints');
|
16
18
|
|
17
|
-
function
|
18
|
-
|
19
|
-
function _interopNamespace(e) {
|
20
|
-
if (e && e.__esModule) return e;
|
19
|
+
function _interopNamespaceDefault(e) {
|
21
20
|
var n = Object.create(null);
|
22
21
|
if (e) {
|
23
22
|
Object.keys(e).forEach(function (k) {
|
@@ -34,18 +33,14 @@ function _interopNamespace(e) {
|
|
34
33
|
return Object.freeze(n);
|
35
34
|
}
|
36
35
|
|
37
|
-
var
|
38
|
-
var path__default = /*#__PURE__*/_interopDefault(path);
|
39
|
-
var childProcess__namespace = /*#__PURE__*/_interopNamespace(childProcess);
|
40
|
-
var detectIndent__default = /*#__PURE__*/_interopDefault(detectIndent);
|
41
|
-
var inquirer__default = /*#__PURE__*/_interopDefault(inquirer);
|
36
|
+
var childProcess__namespace = /*#__PURE__*/_interopNamespaceDefault(childProcess);
|
42
37
|
|
43
38
|
let root;
|
44
39
|
function getRoot() {
|
45
40
|
if (root)
|
46
41
|
return root;
|
47
42
|
const rootOption = commander.program.getOptionValue("root");
|
48
|
-
root = rootOption ?
|
43
|
+
root = rootOption ? path.isAbsolute(rootOption) ? rootOption : path.resolve(process.cwd(), rootOption) : void 0;
|
49
44
|
return root;
|
50
45
|
}
|
51
46
|
|
@@ -88,18 +83,18 @@ async function getSelectedProjectsGraph() {
|
|
88
83
|
const root = getRoot();
|
89
84
|
const { wd, notWorkspace } = getWD();
|
90
85
|
if (!notWorkspace && type === "pnpm") {
|
91
|
-
const pnpmWorkspaceFilePath =
|
92
|
-
const pnpmWorkspaceFileContent =
|
86
|
+
const pnpmWorkspaceFilePath = path.resolve(wd, "pnpm-workspace.yaml");
|
87
|
+
const pnpmWorkspaceFileContent = fs.readFileSync(pnpmWorkspaceFilePath, "utf-8");
|
93
88
|
const pnpmWorkspace = jsYaml.load(pnpmWorkspaceFileContent);
|
94
89
|
if (root === wd && !filter) {
|
95
90
|
throw new Error("root path is workspace root, please provide a filter");
|
96
91
|
}
|
97
92
|
if (root !== wd && !filter) {
|
98
|
-
const packageJSONIsExist =
|
93
|
+
const packageJSONIsExist = fs.existsSync(path.resolve(root, "package.json"));
|
99
94
|
if (!packageJSONIsExist) {
|
100
95
|
throw new Error("root path is not workspace root, please provide a filter");
|
101
96
|
}
|
102
|
-
const packageJSON = JSON.parse(
|
97
|
+
const packageJSON = JSON.parse(fs.readFileSync(path.resolve(root, "package.json"), "utf-8"));
|
103
98
|
if (!packageJSON.name) {
|
104
99
|
throw new Error("root path is not workspace root, please provide a filter");
|
105
100
|
}
|
@@ -126,7 +121,7 @@ async function getSelectedProjectsGraph() {
|
|
126
121
|
wd,
|
127
122
|
root,
|
128
123
|
value: {
|
129
|
-
[wd]: JSON.parse(
|
124
|
+
[wd]: JSON.parse(fs.readFileSync(path.resolve(wd, "package.json"), "utf-8"))
|
130
125
|
}
|
131
126
|
};
|
132
127
|
}
|
@@ -143,85 +138,6 @@ function actionRestore() {
|
|
143
138
|
new Promise((r) => resolve = r);
|
144
139
|
}
|
145
140
|
|
146
|
-
function commondir(files, cwd = process.cwd()) {
|
147
|
-
const resolvedFiles = files.map((file) => {
|
148
|
-
if (path__default.default.isAbsolute(file))
|
149
|
-
return file;
|
150
|
-
return path__default.default.resolve(cwd, file);
|
151
|
-
});
|
152
|
-
const sep = "/";
|
153
|
-
const [first = ""] = resolvedFiles;
|
154
|
-
const parts = first.split(sep);
|
155
|
-
let common = "";
|
156
|
-
for (let i = 0; i < parts.length; i++) {
|
157
|
-
const segment = parts[i];
|
158
|
-
if (resolvedFiles.every((file) => file.startsWith(common + segment))) {
|
159
|
-
common += segment + sep;
|
160
|
-
} else {
|
161
|
-
break;
|
162
|
-
}
|
163
|
-
}
|
164
|
-
return common;
|
165
|
-
}
|
166
|
-
|
167
|
-
function mergePackageJson(manifest, cwd, options = {}) {
|
168
|
-
const {
|
169
|
-
excludeDistInExports = false
|
170
|
-
} = options;
|
171
|
-
const {
|
172
|
-
jiek: { cwd: _, ...jiek } = {}
|
173
|
-
} = manifest;
|
174
|
-
const { outdir = "dist" } = jiek;
|
175
|
-
let { exports } = manifest;
|
176
|
-
let includeIndex = false;
|
177
|
-
if (typeof exports === "string") {
|
178
|
-
includeIndex = true;
|
179
|
-
exports = { ".": exports };
|
180
|
-
}
|
181
|
-
if (exports === void 0) {
|
182
|
-
exports = { ".": "./src/index.ts" };
|
183
|
-
}
|
184
|
-
if (typeof exports === "object") {
|
185
|
-
if (Array.isArray(exports) && exports.length > 0) {
|
186
|
-
includeIndex = true;
|
187
|
-
} else {
|
188
|
-
includeIndex = !!exports["."];
|
189
|
-
}
|
190
|
-
}
|
191
|
-
let inputs = Array.isArray(exports) ? exports : Object.entries(exports).reduce((acc, [key, value]) => {
|
192
|
-
if (typeof value === "string")
|
193
|
-
return key === "." ? [value, ...acc] : acc.concat(value);
|
194
|
-
if (Array.isArray(value))
|
195
|
-
return acc.concat(value);
|
196
|
-
throw new TypeError(`Unexpected value type for key "${key}" in exports, expected string, got ${typeof value}`);
|
197
|
-
}, []);
|
198
|
-
if (excludeDistInExports) {
|
199
|
-
inputs = inputs.filter((input) => !input.startsWith(`./${outdir}`) && !input.startsWith(outdir));
|
200
|
-
}
|
201
|
-
if (inputs.length === 0)
|
202
|
-
throw new Error("No inputs found");
|
203
|
-
const absoluteInputs = inputs.map(
|
204
|
-
(input) => path__default.default.isAbsolute(input) ? input : path__default.default.resolve(cwd, input)
|
205
|
-
);
|
206
|
-
let cDir = path__default.default.dirname(absoluteInputs[0]);
|
207
|
-
if (absoluteInputs.length > 1) {
|
208
|
-
cDir = commondir(absoluteInputs, cwd);
|
209
|
-
}
|
210
|
-
const resolvedInputs = absoluteInputs.map((input) => {
|
211
|
-
return path__default.default.relative(cDir, input);
|
212
|
-
});
|
213
|
-
return {
|
214
|
-
...manifest,
|
215
|
-
...pkger.pkger({
|
216
|
-
cwd,
|
217
|
-
noIndex: !includeIndex,
|
218
|
-
source: path__default.default.relative(cwd, cDir),
|
219
|
-
inputs: resolvedInputs,
|
220
|
-
...jiek
|
221
|
-
})
|
222
|
-
};
|
223
|
-
}
|
224
|
-
|
225
141
|
function packageIsExist(name) {
|
226
142
|
try {
|
227
143
|
require.resolve(name);
|
@@ -244,65 +160,24 @@ for (const register of registers) {
|
|
244
160
|
}
|
245
161
|
}
|
246
162
|
|
247
|
-
const FILE_TEMPLATE = (manifest) => `
|
248
|
-
const pkg = ${JSON.stringify(manifest, null, 2)}
|
249
|
-
const { jiek = {} } = pkg
|
250
|
-
const templateArg = jiek.templateArgFilePath
|
251
|
-
? require.resolve(jiek.templateArgFilePath)
|
252
|
-
: {
|
253
|
-
styled: jiek.styled
|
254
|
-
}
|
255
|
-
module.exports = require('jiek/rollup').template(templateArg, pkg)
|
256
|
-
`.trimStart();
|
257
|
-
commander.program.command("build").option("-t, --target <type>", "target flow: esm|umd|dts, default esm,umd,dts").option("-s, --silent", "silent mode").action(async ({ target, silent }) => {
|
258
|
-
actionRestore();
|
259
|
-
const {
|
260
|
-
wd,
|
261
|
-
value = {}
|
262
|
-
} = await getSelectedProjectsGraph() ?? {};
|
263
|
-
if (Object.keys(value).length === 0) {
|
264
|
-
throw new Error("no package found");
|
265
|
-
}
|
266
|
-
const jiekTempDir = (...paths) => path__default.default.resolve(wd, "node_modules/.jiek", ...paths);
|
267
|
-
if (!fs__default.default.existsSync(jiekTempDir()))
|
268
|
-
fs__default.default.mkdirSync(jiekTempDir());
|
269
|
-
const rollupBinaryPath = require.resolve("rollup").replace(/dist\/rollup.js$/, "dist/bin/rollup");
|
270
|
-
let i = 0;
|
271
|
-
for (const [dir, manifest] of Object.entries(value)) {
|
272
|
-
const newManifest = mergePackageJson(manifest, dir, { excludeDistInExports: true });
|
273
|
-
const escapeManifestName = manifest.name?.replace(/^@/g, "").replace(/\//g, "+");
|
274
|
-
const configFile = jiekTempDir(
|
275
|
-
`${escapeManifestName ?? `anonymous-${i++}`}.rollup.config.js`
|
276
|
-
);
|
277
|
-
fs__default.default.writeFileSync(configFile, FILE_TEMPLATE(newManifest));
|
278
|
-
let prefix = "";
|
279
|
-
if (tsRegisterName) {
|
280
|
-
prefix = `node -r ${tsRegisterName} `;
|
281
|
-
}
|
282
|
-
const command = `${prefix}${rollupBinaryPath} --silent -c ${configFile}`;
|
283
|
-
childProcess__namespace.execSync(command, {
|
284
|
-
cwd: dir,
|
285
|
-
stdio: "inherit",
|
286
|
-
env: {
|
287
|
-
JIEK_TARGET: target ?? process.env.JIEK_TARGET ?? "esm,umd,dts",
|
288
|
-
JIEK_SILENT: `${silent}` ?? process.env.JIEK_SILENT,
|
289
|
-
JIEK_ROOT: wd
|
290
|
-
}
|
291
|
-
});
|
292
|
-
}
|
293
|
-
actionDone();
|
294
|
-
});
|
295
|
-
|
296
163
|
let configName = "jiek.config";
|
297
|
-
function getConfigPath(root) {
|
164
|
+
function getConfigPath(root, dir) {
|
298
165
|
const isSupportTsLoader = !!tsRegisterName;
|
299
166
|
function configWithExtIsExist(ext) {
|
300
167
|
const filenames = [
|
301
|
-
|
302
|
-
|
168
|
+
path.resolve(process.cwd(), `${configName}.${ext}`),
|
169
|
+
path.resolve(process.cwd(), `.${configName}.${ext}`),
|
170
|
+
path.resolve(root, `${configName}.${ext}`),
|
171
|
+
path.resolve(root, `.${configName}.${ext}`)
|
303
172
|
];
|
173
|
+
if (dir) {
|
174
|
+
filenames.unshift(...[
|
175
|
+
path.resolve(dir, `${configName}.${ext}`),
|
176
|
+
path.resolve(dir, `.${configName}.${ext}`)
|
177
|
+
]);
|
178
|
+
}
|
304
179
|
for (const filename of filenames) {
|
305
|
-
if (
|
180
|
+
if (fs.existsSync(filename) && fs.lstatSync(filename).isFile()) {
|
306
181
|
return filename;
|
307
182
|
}
|
308
183
|
}
|
@@ -314,22 +189,22 @@ function getConfigPath(root) {
|
|
314
189
|
if (isSupportTsLoader) {
|
315
190
|
configName = configWithExtIsExist("ts") ?? configName;
|
316
191
|
}
|
317
|
-
return
|
192
|
+
return path.resolve(root, configName);
|
318
193
|
}
|
319
|
-
function loadConfig() {
|
320
|
-
const { wd: root
|
321
|
-
if (notWorkspace)
|
322
|
-
throw new Error("not in workspace");
|
194
|
+
function loadConfig(dir) {
|
195
|
+
const { wd: root } = getWD();
|
323
196
|
let configPath = commander.program.getOptionValue("configPath");
|
324
197
|
if (!configPath) {
|
325
|
-
configPath = getConfigPath(root);
|
198
|
+
configPath = getConfigPath(root, dir);
|
326
199
|
} else {
|
327
|
-
if (!
|
200
|
+
if (!fs.existsSync(configPath)) {
|
328
201
|
throw new Error(`config file not found: ${configPath}`);
|
329
|
-
|
330
|
-
|
202
|
+
}
|
203
|
+
if (!path.isAbsolute(configPath)) {
|
204
|
+
configPath = path.resolve(root, configPath);
|
205
|
+
}
|
331
206
|
}
|
332
|
-
const ext =
|
207
|
+
const ext = path.extname(configPath);
|
333
208
|
let module;
|
334
209
|
switch (ext) {
|
335
210
|
case ".js":
|
@@ -338,7 +213,7 @@ function loadConfig() {
|
|
338
213
|
case ".json":
|
339
214
|
return require(configPath);
|
340
215
|
case ".yaml":
|
341
|
-
return jsYaml.load(
|
216
|
+
return jsYaml.load(fs.readFileSync(configPath, "utf-8"));
|
342
217
|
case ".ts":
|
343
218
|
if (tsRegisterName) {
|
344
219
|
require(tsRegisterName);
|
@@ -359,6 +234,133 @@ function loadConfig() {
|
|
359
234
|
return module.default ?? module;
|
360
235
|
}
|
361
236
|
|
237
|
+
const FILE_TEMPLATE = (manifest) => `
|
238
|
+
const manifest = ${JSON.stringify(manifest, null, 2)}
|
239
|
+
module.exports = require('jiek/rollup').template(manifest)
|
240
|
+
`.trimStart();
|
241
|
+
commander.program.command("build").option("-s, --silent", "Don't display logs.").option("-e, --entries <ENTRIES>", "Specify the entries of the package.json's 'exports' field.(support glob)").action(async ({
|
242
|
+
silent,
|
243
|
+
entries
|
244
|
+
}) => {
|
245
|
+
actionRestore();
|
246
|
+
const { build } = loadConfig();
|
247
|
+
silent = silent ?? build?.silent ?? false;
|
248
|
+
const {
|
249
|
+
wd,
|
250
|
+
value = {}
|
251
|
+
} = await getSelectedProjectsGraph() ?? {};
|
252
|
+
if (Object.keys(value).length === 0) {
|
253
|
+
throw new Error("no package found");
|
254
|
+
}
|
255
|
+
const wdNodeModules = path.resolve(wd, "node_modules");
|
256
|
+
if (!fs.existsSync(wdNodeModules)) {
|
257
|
+
fs.mkdirSync(wdNodeModules);
|
258
|
+
}
|
259
|
+
const jiekTempDir = (...paths) => path.resolve(wdNodeModules, ".jiek", ...paths);
|
260
|
+
if (!fs.existsSync(jiekTempDir())) {
|
261
|
+
fs.mkdirSync(jiekTempDir());
|
262
|
+
}
|
263
|
+
const rollupBinaryPath = require.resolve("rollup").replace(/dist\/rollup.js$/, "dist/bin/rollup");
|
264
|
+
const multiBars = new cliProgress.MultiBar({
|
265
|
+
clearOnComplete: false,
|
266
|
+
hideCursor: true,
|
267
|
+
format: "- {bar} | {status} | {input} | {message}"
|
268
|
+
}, cliProgress.Presets.shades_classic);
|
269
|
+
let i = 0;
|
270
|
+
await Promise.all(
|
271
|
+
Object.entries(value).map(async ([dir, manifest]) => {
|
272
|
+
const escapeManifestName = manifest.name?.replace(/^@/g, "").replace(/\//g, "+");
|
273
|
+
const configFile = jiekTempDir(
|
274
|
+
`${escapeManifestName ?? `anonymous-${i++}`}.rollup.config.js`
|
275
|
+
);
|
276
|
+
fs.writeFileSync(configFile, FILE_TEMPLATE(manifest));
|
277
|
+
let prefix = "";
|
278
|
+
if (tsRegisterName) {
|
279
|
+
prefix = `node -r ${tsRegisterName} `;
|
280
|
+
}
|
281
|
+
const command = `${prefix}${rollupBinaryPath} --silent -c ${configFile}`;
|
282
|
+
const child = execa.execaCommand(command, {
|
283
|
+
ipc: true,
|
284
|
+
cwd: dir,
|
285
|
+
env: {
|
286
|
+
...process.env,
|
287
|
+
JIEK_ROOT: wd,
|
288
|
+
JIEK_ENTRIES: entries
|
289
|
+
}
|
290
|
+
});
|
291
|
+
const bars = {};
|
292
|
+
let inputMaxLen = 10;
|
293
|
+
child.on("message", (e) => {
|
294
|
+
if (e.type === "debug")
|
295
|
+
console.log(...Array.isArray(e.data) ? e.data : [e.data]);
|
296
|
+
});
|
297
|
+
!silent && child.on("message", (e) => {
|
298
|
+
if (e.type === "init") {
|
299
|
+
const { leafMap, targetsLength } = e.data;
|
300
|
+
const leafs = Array.from(leafMap.entries()).flatMap(
|
301
|
+
([input, pathAndCondiions]) => pathAndCondiions.map(([path2, ...conditions]) => ({
|
302
|
+
input,
|
303
|
+
path: path2,
|
304
|
+
conditions
|
305
|
+
}))
|
306
|
+
);
|
307
|
+
console.log(`Package '${manifest.name}' has ${targetsLength} targets to build`);
|
308
|
+
leafs.forEach(({ input }) => {
|
309
|
+
inputMaxLen = Math.max(inputMaxLen, input.length);
|
310
|
+
});
|
311
|
+
leafs.forEach(({ input, path: path2 }) => {
|
312
|
+
const key = `${input}:${path2}`;
|
313
|
+
if (bars[key])
|
314
|
+
return;
|
315
|
+
bars[key] = multiBars.create(50, 0, {
|
316
|
+
input: input.padEnd(inputMaxLen),
|
317
|
+
status: "waiting".padEnd(10)
|
318
|
+
}, {
|
319
|
+
barsize: 20,
|
320
|
+
linewrap: true
|
321
|
+
});
|
322
|
+
});
|
323
|
+
}
|
324
|
+
if (e.type === "progress") {
|
325
|
+
const {
|
326
|
+
path: path2,
|
327
|
+
tags,
|
328
|
+
input,
|
329
|
+
event,
|
330
|
+
message
|
331
|
+
} = e.data;
|
332
|
+
const bar = bars[`${input}:${path2}`];
|
333
|
+
if (!bar)
|
334
|
+
return;
|
335
|
+
bar.update(
|
336
|
+
{
|
337
|
+
start: 0,
|
338
|
+
resolve: 20,
|
339
|
+
end: 50
|
340
|
+
}[event ?? "start"] ?? 0,
|
341
|
+
{
|
342
|
+
input: input.padEnd(inputMaxLen),
|
343
|
+
status: event?.padEnd(10),
|
344
|
+
message: `${tags?.join(", ")}: ${message}`
|
345
|
+
}
|
346
|
+
);
|
347
|
+
}
|
348
|
+
});
|
349
|
+
await new Promise((resolve, reject) => {
|
350
|
+
let errorStr = "";
|
351
|
+
child.stderr?.on("data", (data) => {
|
352
|
+
errorStr += data;
|
353
|
+
});
|
354
|
+
child.once("exit", (code) => code === 0 ? resolve() : reject(new Error(`rollup build failed:
|
355
|
+
${errorStr}`)));
|
356
|
+
});
|
357
|
+
})
|
358
|
+
).finally(() => {
|
359
|
+
multiBars.stop();
|
360
|
+
});
|
361
|
+
actionDone();
|
362
|
+
});
|
363
|
+
|
362
364
|
const PACKAGE_JSON_TEMPLATE = `{
|
363
365
|
"name": "",
|
364
366
|
"version": "0.0.1",
|
@@ -404,8 +406,8 @@ function getTemplateStr(wd, template) {
|
|
404
406
|
isTemplateFile = true;
|
405
407
|
}
|
406
408
|
if (isTemplateFile) {
|
407
|
-
const templatePath =
|
408
|
-
templateString =
|
409
|
+
const templatePath = path.resolve(wd, template);
|
410
|
+
templateString = fs.readFileSync(templatePath, "utf-8");
|
409
411
|
}
|
410
412
|
return templateString;
|
411
413
|
}
|
@@ -414,8 +416,8 @@ function getWDPackageJSONFiled(wd, field) {
|
|
414
416
|
if (wdCache.has(wd)) {
|
415
417
|
return wdCache.get(wd)[field];
|
416
418
|
}
|
417
|
-
const packageJSONPath =
|
418
|
-
const packageJSON = JSON.parse(
|
419
|
+
const packageJSONPath = path.resolve(wd, "package.json");
|
420
|
+
const packageJSON = JSON.parse(fs.readFileSync(packageJSONPath, "utf-8"));
|
419
421
|
wdCache.set(wd, packageJSON);
|
420
422
|
return packageJSON[field];
|
421
423
|
}
|
@@ -425,7 +427,7 @@ async function getName(named, name, {
|
|
425
427
|
workspaceName
|
426
428
|
}) {
|
427
429
|
const relativePath = cwd.replace(`${wd}/`, "");
|
428
|
-
let basename =
|
430
|
+
let basename = path.basename(cwd);
|
429
431
|
if (typeof named === "function") {
|
430
432
|
return named(name, {
|
431
433
|
full: wd,
|
@@ -438,7 +440,7 @@ async function getName(named, name, {
|
|
438
440
|
if (typeof named === "object") {
|
439
441
|
const isWD = cwd === wd;
|
440
442
|
if (isWD) {
|
441
|
-
const { rule } = await
|
443
|
+
const { rule } = await inquirer.prompt({
|
442
444
|
type: "list",
|
443
445
|
name: "rule",
|
444
446
|
message: "choose a rule",
|
@@ -449,7 +451,7 @@ async function getName(named, name, {
|
|
449
451
|
matchedKey = rule;
|
450
452
|
matchedRule = named[rule];
|
451
453
|
}
|
452
|
-
} else
|
454
|
+
} else {
|
453
455
|
for (const [key, value] of Object.entries(named)) {
|
454
456
|
if (micromatch.isMatch(relativePath, key)) {
|
455
457
|
matchedKey = key;
|
@@ -463,15 +465,17 @@ async function getName(named, name, {
|
|
463
465
|
break;
|
464
466
|
}
|
465
467
|
}
|
468
|
+
}
|
466
469
|
}
|
467
470
|
if (!matchedRule) {
|
468
471
|
matchedKey = "packages/*";
|
469
472
|
matchedRule = `@${workspaceName}/$basename`;
|
470
473
|
}
|
471
|
-
if (!matchedRule)
|
474
|
+
if (!matchedRule) {
|
472
475
|
throw new Error("no matched rule");
|
476
|
+
}
|
473
477
|
if (!name && isParentMatched) {
|
474
|
-
basename = await
|
478
|
+
basename = await inquirer.prompt({
|
475
479
|
type: "input",
|
476
480
|
name: "name",
|
477
481
|
message: `the matched rule is \`${String(matchedRule)}\`, please input the basename
|
@@ -499,7 +503,7 @@ commander.program.command("init [name]").option("-t, --template <template>", "th
|
|
499
503
|
const cwd = process.cwd();
|
500
504
|
const { init = {} } = loadConfig() ?? {};
|
501
505
|
const { wd } = getWD();
|
502
|
-
const workspaceName =
|
506
|
+
const workspaceName = path.basename(wd);
|
503
507
|
const {
|
504
508
|
named,
|
505
509
|
template,
|
@@ -514,11 +518,11 @@ commander.program.command("init [name]").option("-t, --template <template>", "th
|
|
514
518
|
};
|
515
519
|
let readme = _readme;
|
516
520
|
if (readmeTemplate) {
|
517
|
-
const readmeTemplatePath =
|
518
|
-
readme =
|
521
|
+
const readmeTemplatePath = path.resolve(wd, readmeTemplate);
|
522
|
+
readme = fs.readFileSync(readmeTemplatePath, "utf-8");
|
519
523
|
}
|
520
524
|
const templateString = getTemplateStr(wd, template);
|
521
|
-
const { indent = " " } =
|
525
|
+
const { indent = " " } = detectIndent(templateString);
|
522
526
|
const formattingOptions = {
|
523
527
|
tabSize: indent.length,
|
524
528
|
insertSpaces: true
|
@@ -529,12 +533,15 @@ commander.program.command("init [name]").option("-t, --template <template>", "th
|
|
529
533
|
];
|
530
534
|
let newJSONString = templateString;
|
531
535
|
for (const field of passFields) {
|
532
|
-
newJSONString = jsoncParser.applyEdits(
|
536
|
+
newJSONString = jsoncParser.applyEdits(
|
533
537
|
newJSONString,
|
534
|
-
|
535
|
-
|
536
|
-
|
537
|
-
|
538
|
+
jsoncParser.modify(
|
539
|
+
newJSONString,
|
540
|
+
[field],
|
541
|
+
getWDPackageJSONFiled(wd, field),
|
542
|
+
{ formattingOptions }
|
543
|
+
)
|
544
|
+
);
|
538
545
|
}
|
539
546
|
let [pkgName, pkgDir] = await getName(named, name, {
|
540
547
|
wd,
|
@@ -542,7 +549,7 @@ commander.program.command("init [name]").option("-t, --template <template>", "th
|
|
542
549
|
workspaceName
|
543
550
|
});
|
544
551
|
if (!pkgDir) {
|
545
|
-
const { dir } = await
|
552
|
+
const { dir } = await inquirer.prompt({
|
546
553
|
type: "input",
|
547
554
|
name: "dir",
|
548
555
|
message: "package directory",
|
@@ -551,7 +558,7 @@ commander.program.command("init [name]").option("-t, --template <template>", "th
|
|
551
558
|
pkgDir = dir;
|
552
559
|
}
|
553
560
|
if (!pkgName) {
|
554
|
-
const { name: inputName } = await
|
561
|
+
const { name: inputName } = await inquirer.prompt({
|
555
562
|
type: "input",
|
556
563
|
name: "name",
|
557
564
|
message: "package name",
|
@@ -568,45 +575,55 @@ commander.program.command("init [name]").option("-t, --template <template>", "th
|
|
568
575
|
directory: pkgDir
|
569
576
|
};
|
570
577
|
}
|
571
|
-
newJSONString = jsoncParser.applyEdits(
|
578
|
+
newJSONString = jsoncParser.applyEdits(
|
572
579
|
newJSONString,
|
573
|
-
|
574
|
-
|
575
|
-
|
576
|
-
|
580
|
+
jsoncParser.modify(
|
581
|
+
newJSONString,
|
582
|
+
["repository"],
|
583
|
+
pkgRepo,
|
584
|
+
{ formattingOptions }
|
585
|
+
)
|
586
|
+
);
|
577
587
|
const homepage = `${pkgRepo?.url}/blob/master/${pkgDir}/README.md`;
|
578
|
-
newJSONString = jsoncParser.applyEdits(
|
588
|
+
newJSONString = jsoncParser.applyEdits(
|
579
589
|
newJSONString,
|
580
|
-
|
581
|
-
|
582
|
-
|
583
|
-
|
590
|
+
jsoncParser.modify(
|
591
|
+
newJSONString,
|
592
|
+
["homepage"],
|
593
|
+
homepage,
|
594
|
+
{ formattingOptions }
|
595
|
+
)
|
596
|
+
);
|
584
597
|
let labels = resolvedBug.labels;
|
585
|
-
if (typeof labels === "function")
|
598
|
+
if (typeof labels === "function") {
|
586
599
|
labels = labels({
|
587
600
|
name: pkgName,
|
588
601
|
dir: pkgDir
|
589
602
|
});
|
603
|
+
}
|
590
604
|
labels.push(`scope:${pkgName}`);
|
591
605
|
const bugs = `${pkgRepo?.url}/issues/new?template=${resolvedBug.template}&labels=${labels.join(",")}`;
|
592
|
-
newJSONString = jsoncParser.applyEdits(
|
606
|
+
newJSONString = jsoncParser.applyEdits(
|
593
607
|
newJSONString,
|
594
|
-
|
595
|
-
|
596
|
-
|
597
|
-
|
608
|
+
jsoncParser.modify(
|
609
|
+
newJSONString,
|
610
|
+
["bugs"],
|
611
|
+
bugs,
|
612
|
+
{ formattingOptions }
|
613
|
+
)
|
614
|
+
);
|
598
615
|
function pkgDirTo(to) {
|
599
616
|
if (!pkgDir)
|
600
617
|
throw new Error("pkgDir is not defined");
|
601
|
-
return
|
618
|
+
return path.resolve(pkgDir, to);
|
602
619
|
}
|
603
|
-
if (!
|
604
|
-
|
620
|
+
if (!fs.existsSync(pkgDir))
|
621
|
+
fs.mkdirSync(pkgDir);
|
605
622
|
const pkgJSONFilePath = pkgDirTo("package.json");
|
606
|
-
if (
|
623
|
+
if (fs.existsSync(pkgJSONFilePath)) {
|
607
624
|
throw new Error("package.json already exists");
|
608
625
|
}
|
609
|
-
|
626
|
+
fs.writeFileSync(pkgJSONFilePath, newJSONString);
|
610
627
|
console.log(newJSONString, "written to", pkgJSONFilePath);
|
611
628
|
const license = getWDPackageJSONFiled(wd, "license");
|
612
629
|
const readmeFilePath = pkgDirTo("README.md");
|
@@ -617,9 +634,66 @@ commander.program.command("init [name]").option("-t, --template <template>", "th
|
|
617
634
|
});
|
618
635
|
}
|
619
636
|
const readmeContent = readme.replace(/\$name/g, pkgName).replace(/\$license/g, license);
|
620
|
-
|
637
|
+
fs.writeFileSync(readmeFilePath, readmeContent);
|
621
638
|
});
|
622
639
|
|
640
|
+
const intersection = (a, b) => new Set([...a].filter((i) => b.has(i)));
|
641
|
+
function getExports({
|
642
|
+
entrypoints: entrypoints$1,
|
643
|
+
pkgIsModule,
|
644
|
+
entries,
|
645
|
+
config,
|
646
|
+
dir,
|
647
|
+
noFilter
|
648
|
+
}) {
|
649
|
+
const dirResolve = (...paths) => path.resolve(dir ?? process.cwd(), ...paths);
|
650
|
+
const dirRelative = (path$1) => path.relative(dir ?? process.cwd(), path$1);
|
651
|
+
const { build = {} } = config ?? {};
|
652
|
+
const {
|
653
|
+
crossModuleConvertor = true
|
654
|
+
} = build;
|
655
|
+
const jsOutdir = `./${dirRelative(dirResolve(
|
656
|
+
(typeof build?.output?.dir === "object" ? build.output.dir.js : build?.output?.dir) ?? "dist"
|
657
|
+
))}`;
|
658
|
+
const [, resolvedEntrypoints] = entrypoints.resolveEntrypoints(entrypoints$1);
|
659
|
+
if (entries) {
|
660
|
+
Object.entries(resolvedEntrypoints).forEach(([key]) => {
|
661
|
+
if (!entries.some((e) => micromatch.isMatch(key, e, { matchBase: true }))) {
|
662
|
+
delete resolvedEntrypoints[key];
|
663
|
+
}
|
664
|
+
});
|
665
|
+
}
|
666
|
+
const filteredResolvedEntrypoints = noFilter ? resolvedEntrypoints : entrypoints.filterLeafs(
|
667
|
+
resolvedEntrypoints,
|
668
|
+
{
|
669
|
+
skipValue: [
|
670
|
+
// ignore values that filename starts with `.jk-noentry`
|
671
|
+
/(^|\/)\.jk-noentry/,
|
672
|
+
...entrypoints.DEFAULT_SKIP_VALUES
|
673
|
+
]
|
674
|
+
}
|
675
|
+
);
|
676
|
+
const crossModuleWithConditional = crossModuleConvertor ? {
|
677
|
+
import: (opts) => !pkgIsModule && intersection(
|
678
|
+
new Set(opts.conditionals),
|
679
|
+
/* @__PURE__ */ new Set(["import", "module"])
|
680
|
+
).size === 0 ? opts.dist.replace(/\.js$/, ".mjs") : false,
|
681
|
+
require: (opts) => pkgIsModule && intersection(
|
682
|
+
new Set(opts.conditionals),
|
683
|
+
/* @__PURE__ */ new Set(["require", "node"])
|
684
|
+
).size === 0 ? opts.dist.replace(/\.js$/, ".cjs") : false
|
685
|
+
} : {};
|
686
|
+
return [
|
687
|
+
filteredResolvedEntrypoints,
|
688
|
+
entrypoints.entrypoints2Exports(filteredResolvedEntrypoints, {
|
689
|
+
outdir: jsOutdir,
|
690
|
+
withConditional: {
|
691
|
+
...crossModuleWithConditional
|
692
|
+
}
|
693
|
+
})
|
694
|
+
];
|
695
|
+
}
|
696
|
+
|
623
697
|
commander.program.command("publish").aliases(["pub", "p"]).option("-b, --bumper <bumper>", "bump version", "patch").option("-p, --preview", "preview publish").action(async ({ preview, bumper: bumper$1, ...options }) => {
|
624
698
|
actionRestore();
|
625
699
|
const { value = {} } = await getSelectedProjectsGraph() ?? {};
|
@@ -627,56 +701,107 @@ commander.program.command("publish").aliases(["pub", "p"]).option("-b, --bumper
|
|
627
701
|
if (selectedProjectsGraphEntries.length === 0) {
|
628
702
|
throw new Error("no packages selected");
|
629
703
|
}
|
630
|
-
const
|
631
|
-
|
632
|
-
|
633
|
-
|
704
|
+
const manifests = selectedProjectsGraphEntries.map(([dir, manifest]) => {
|
705
|
+
const { type, exports: entrypoints = {} } = manifest;
|
706
|
+
const pkgIsModule = type === "module";
|
707
|
+
const newManifest = { ...manifest };
|
708
|
+
const [resolvedEntrypoints, exports] = getExports({
|
709
|
+
entrypoints,
|
710
|
+
pkgIsModule,
|
711
|
+
config: loadConfig(dir),
|
712
|
+
dir,
|
713
|
+
noFilter: true
|
714
|
+
});
|
715
|
+
newManifest.exports = {
|
716
|
+
...resolvedEntrypoints,
|
717
|
+
...exports
|
718
|
+
};
|
719
|
+
return [dir, newManifest];
|
720
|
+
});
|
634
721
|
const passArgs = Object.entries(options).reduce((acc, [key, value2]) => {
|
635
722
|
if (value2) {
|
636
723
|
acc.push(`--${key}`, value2);
|
637
724
|
}
|
638
725
|
return acc;
|
639
726
|
}, []);
|
640
|
-
for (const [dir, manifest] of
|
641
|
-
const oldJSONString =
|
727
|
+
for (const [dir, manifest] of manifests) {
|
728
|
+
const oldJSONString = fs.readFileSync(path.join(dir, "package.json"), "utf-8");
|
642
729
|
const oldJSON = JSON.parse(oldJSONString) ?? "0.0.0";
|
643
730
|
const newVersion = bumper.bump(oldJSON.version, bumper$1);
|
644
|
-
const { indent = " " } =
|
731
|
+
const { indent = " " } = detectIndent(oldJSONString);
|
645
732
|
const formattingOptions = {
|
646
733
|
tabSize: indent.length,
|
647
734
|
insertSpaces: true
|
648
735
|
};
|
649
736
|
let newJSONString = oldJSONString;
|
650
|
-
newJSONString = jsoncParser.applyEdits(
|
737
|
+
newJSONString = jsoncParser.applyEdits(
|
651
738
|
newJSONString,
|
652
|
-
|
653
|
-
|
654
|
-
|
655
|
-
|
739
|
+
jsoncParser.modify(
|
740
|
+
newJSONString,
|
741
|
+
["version"],
|
742
|
+
newVersion,
|
743
|
+
{ formattingOptions }
|
744
|
+
)
|
745
|
+
);
|
656
746
|
for (const [key, value2] of Object.entries(manifest)) {
|
657
747
|
if (JSON.stringify(value2) === JSON.stringify(oldJSON[key]))
|
658
748
|
continue;
|
659
749
|
if (key !== "exports") {
|
660
|
-
newJSONString = jsoncParser.applyEdits(
|
750
|
+
newJSONString = jsoncParser.applyEdits(
|
661
751
|
newJSONString,
|
662
|
-
|
663
|
-
value2,
|
664
|
-
{ formattingOptions }
|
665
|
-
));
|
666
|
-
} else {
|
667
|
-
for (const [k, v] of Object.entries(value2)) {
|
668
|
-
newJSONString = jsoncParser.applyEdits(newJSONString, jsoncParser.modify(
|
752
|
+
jsoncParser.modify(
|
669
753
|
newJSONString,
|
670
|
-
["publishConfig",
|
671
|
-
|
754
|
+
["publishConfig", key],
|
755
|
+
value2,
|
672
756
|
{ formattingOptions }
|
673
|
-
)
|
757
|
+
)
|
758
|
+
);
|
759
|
+
} else {
|
760
|
+
const exports = value2;
|
761
|
+
for (const [k, v] of Object.entries(exports)) {
|
762
|
+
newJSONString = jsoncParser.applyEdits(
|
763
|
+
newJSONString,
|
764
|
+
jsoncParser.modify(
|
765
|
+
newJSONString,
|
766
|
+
["publishConfig", "exports", k],
|
767
|
+
v,
|
768
|
+
{ formattingOptions }
|
769
|
+
)
|
770
|
+
);
|
771
|
+
}
|
772
|
+
const index = exports?.["."];
|
773
|
+
const indexPublishConfig = {};
|
774
|
+
if (index) {
|
775
|
+
switch (typeof index) {
|
776
|
+
case "string":
|
777
|
+
indexPublishConfig[manifest?.type === "module" ? "module" : "main"] = index;
|
778
|
+
break;
|
779
|
+
case "object": {
|
780
|
+
const indexExports = index;
|
781
|
+
indexPublishConfig.main = indexExports["require"] ?? indexExports["default"];
|
782
|
+
indexPublishConfig.module = indexExports["import"] ?? indexExports["module"] ?? indexExports["default"];
|
783
|
+
break;
|
784
|
+
}
|
785
|
+
}
|
786
|
+
for (const [k, v] of Object.entries(indexPublishConfig)) {
|
787
|
+
if (v === void 0)
|
788
|
+
continue;
|
789
|
+
newJSONString = jsoncParser.applyEdits(
|
790
|
+
newJSONString,
|
791
|
+
jsoncParser.modify(
|
792
|
+
newJSONString,
|
793
|
+
["publishConfig", k],
|
794
|
+
v,
|
795
|
+
{ formattingOptions }
|
796
|
+
)
|
797
|
+
);
|
798
|
+
}
|
674
799
|
}
|
675
800
|
}
|
676
801
|
}
|
677
802
|
try {
|
678
|
-
|
679
|
-
|
803
|
+
fs.renameSync(path.join(dir, "package.json"), path.join(dir, "package.json.bak"));
|
804
|
+
fs.writeFileSync(path.join(dir, "package.json"), newJSONString);
|
680
805
|
console.log(newJSONString);
|
681
806
|
if (preview) {
|
682
807
|
console.warn("preview mode");
|
@@ -687,14 +812,13 @@ commander.program.command("publish").aliases(["pub", "p"]).option("-b, --bumper
|
|
687
812
|
stdio: "inherit"
|
688
813
|
});
|
689
814
|
const modifyVersionPackageJSON = jsoncParser.applyEdits(oldJSONString, jsoncParser.modify(oldJSONString, ["version"], newVersion, {}));
|
690
|
-
|
815
|
+
fs.writeFileSync(path.join(dir, "package.json.bak"), modifyVersionPackageJSON);
|
691
816
|
} finally {
|
692
|
-
|
693
|
-
|
817
|
+
fs.unlinkSync(path.join(dir, "package.json"));
|
818
|
+
fs.renameSync(path.join(dir, "package.json.bak"), path.join(dir, "package.json"));
|
694
819
|
}
|
695
820
|
}
|
696
821
|
actionDone();
|
697
822
|
});
|
698
823
|
|
699
824
|
commander.program.parse(process.argv);
|
700
|
-
//# sourceMappingURL=cli.cjs.map
|