jiek 0.1.12 → 0.2.0-alpha.1
Sign up to get free protection for your applications and to get access to all the features.
- package/dist/commands/build.esm.js +10 -32
- package/dist/commands/build.esm.js.map +1 -1
- package/dist/commands/build.esm.min.js +1 -1
- package/dist/commands/build.esm.min.js.map +1 -1
- package/dist/commands/publish.esm.js +50 -34
- package/dist/commands/publish.esm.js.map +1 -1
- package/dist/commands/publish.esm.min.js +1 -1
- package/dist/commands/publish.esm.min.js.map +1 -1
- package/dist/index.esm.js +3 -0
- package/dist/index.esm.js.map +1 -1
- package/dist/index.esm.min.js +1 -1
- package/dist/index.esm.min.js.map +1 -1
- package/dist/index.iife.js +194 -67
- package/dist/index.iife.js.map +1 -1
- package/dist/index.iife.min.js +1 -1
- package/dist/index.iife.min.js.map +1 -1
- package/dist/index.umd.js +196 -69
- package/dist/index.umd.js.map +1 -1
- package/dist/index.umd.min.js +1 -1
- package/dist/index.umd.min.js.map +1 -1
- package/dist/merge-package-json.esm.js +45 -4
- package/dist/merge-package-json.esm.js.map +1 -1
- package/dist/merge-package-json.esm.min.js +1 -1
- package/dist/merge-package-json.esm.min.js.map +1 -1
- package/dist/rollup.esm.js +7 -0
- package/dist/rollup.esm.js.map +1 -1
- package/dist/rollup.esm.min.js +1 -1
- package/dist/rollup.esm.min.js.map +1 -1
- package/dist/rollup.iife.js +9 -2
- package/dist/rollup.iife.js.map +1 -1
- package/dist/rollup.iife.min.js +1 -1
- package/dist/rollup.iife.min.js.map +1 -1
- package/dist/rollup.umd.js +11 -4
- package/dist/rollup.umd.js.map +1 -1
- package/dist/rollup.umd.min.js +1 -1
- package/dist/rollup.umd.min.js.map +1 -1
- package/dist/utils/commondir.esm.js +25 -0
- package/dist/utils/commondir.esm.js.map +1 -0
- package/dist/utils/commondir.esm.min.js +2 -0
- package/dist/utils/commondir.esm.min.js.map +1 -0
- package/dist/utils/filterSupport.esm.js +78 -0
- package/dist/utils/filterSupport.esm.js.map +1 -0
- package/dist/utils/filterSupport.esm.min.js +2 -0
- package/dist/utils/filterSupport.esm.min.js.map +1 -0
- package/package.json +27 -30
package/dist/index.umd.js
CHANGED
@@ -1,8 +1,8 @@
|
|
1
1
|
(function (global, factory) {
|
2
|
-
typeof exports === 'object' && typeof module !== 'undefined' ? factory(require('node:fs'), require('node:path'), require('@jiek/utils/
|
3
|
-
typeof define === 'function' && define.amd ? define(['node:fs', 'node:path', '@jiek/utils/
|
4
|
-
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.fs, global.path, global.
|
5
|
-
})(this, (function (fs, path,
|
2
|
+
typeof exports === 'object' && typeof module !== 'undefined' ? factory(require('node:fs'), require('node:path'), require('@jiek/utils/getWorkspaceDir'), require('@pnpm/filter-workspace-packages'), require('commander'), require('js-yaml'), require('@jiek/utils/bumper'), require('child_process'), require('detect-indent'), require('jsonc-parser'), require('@jiek/pkger'), require('node:child_process')) :
|
3
|
+
typeof define === 'function' && define.amd ? define(['node:fs', 'node:path', '@jiek/utils/getWorkspaceDir', '@pnpm/filter-workspace-packages', 'commander', 'js-yaml', '@jiek/utils/bumper', 'child_process', 'detect-indent', 'jsonc-parser', '@jiek/pkger', 'node:child_process'], factory) :
|
4
|
+
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.fs, global.path, global.getWorkspaceDir, global.filterWorkspacePackages, global.commander, global.jsYaml, global.bumper, global.childProcess, global.detectIndent, global.jsoncParser, global.pkger, global.childProcess$1));
|
5
|
+
})(this, (function (fs, path, getWorkspaceDir, filterWorkspacePackages, commander, jsYaml, bumper, childProcess, detectIndent, jsoncParser, pkger, childProcess$1) { 'use strict';
|
6
6
|
|
7
7
|
function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
|
8
8
|
|
@@ -27,8 +27,78 @@
|
|
27
27
|
var fs__default = /*#__PURE__*/_interopDefault(fs);
|
28
28
|
var path__default = /*#__PURE__*/_interopDefault(path);
|
29
29
|
var childProcess__namespace = /*#__PURE__*/_interopNamespace(childProcess);
|
30
|
+
var detectIndent__default = /*#__PURE__*/_interopDefault(detectIndent);
|
30
31
|
var childProcess__namespace$1 = /*#__PURE__*/_interopNamespace(childProcess$1);
|
31
32
|
|
33
|
+
let type = "";
|
34
|
+
try {
|
35
|
+
require.resolve("@pnpm/filter-workspace-packages");
|
36
|
+
type = "pnpm";
|
37
|
+
} catch {
|
38
|
+
}
|
39
|
+
if (type !== "") {
|
40
|
+
commander.program.option("-f, --filter <filter>", "filter packages");
|
41
|
+
}
|
42
|
+
async function getSelectedProjectsGraph() {
|
43
|
+
let filter = commander.program.getOptionValue("filter");
|
44
|
+
const rootOption = commander.program.getOptionValue("root");
|
45
|
+
const root = rootOption ? path__default.default.isAbsolute(rootOption) ? rootOption : path__default.default.resolve(process.cwd(), rootOption) : process.cwd();
|
46
|
+
let notWorkspace = false;
|
47
|
+
let wd;
|
48
|
+
try {
|
49
|
+
wd = getWorkspaceDir.getWorkspaceDir(root, type);
|
50
|
+
} catch (e) {
|
51
|
+
if ("message" in e && e.message === "workspace root not found") {
|
52
|
+
wd = root;
|
53
|
+
notWorkspace = true;
|
54
|
+
} else {
|
55
|
+
throw e;
|
56
|
+
}
|
57
|
+
}
|
58
|
+
if (!notWorkspace && type === "pnpm") {
|
59
|
+
const pnpmWorkspaceFilePath = path__default.default.resolve(wd, "pnpm-workspace.yaml");
|
60
|
+
const pnpmWorkspaceFileContent = fs__default.default.readFileSync(pnpmWorkspaceFilePath, "utf-8");
|
61
|
+
const pnpmWorkspace = jsYaml.load(pnpmWorkspaceFileContent);
|
62
|
+
if (root === wd && !filter) {
|
63
|
+
throw new Error("root path is workspace root, please provide a filter");
|
64
|
+
}
|
65
|
+
if (root !== wd && !filter) {
|
66
|
+
const packageJSONIsExist = fs__default.default.existsSync(path__default.default.resolve(root, "package.json"));
|
67
|
+
if (!packageJSONIsExist) {
|
68
|
+
throw new Error("root path is not workspace root, please provide a filter");
|
69
|
+
}
|
70
|
+
const packageJSON = JSON.parse(fs__default.default.readFileSync(path__default.default.resolve(root, "package.json"), "utf-8"));
|
71
|
+
if (!packageJSON.name) {
|
72
|
+
throw new Error("root path is not workspace root, please provide a filter");
|
73
|
+
}
|
74
|
+
filter = packageJSON.name;
|
75
|
+
}
|
76
|
+
const { selectedProjectsGraph } = await filterWorkspacePackages.filterPackagesFromDir(wd, [{
|
77
|
+
filter: filter ?? "",
|
78
|
+
followProdDepsOnly: true
|
79
|
+
}], {
|
80
|
+
prefix: root,
|
81
|
+
workspaceDir: wd,
|
82
|
+
patterns: pnpmWorkspace.packages
|
83
|
+
});
|
84
|
+
return {
|
85
|
+
wd,
|
86
|
+
root,
|
87
|
+
value: Object.entries(selectedProjectsGraph).reduce((acc, [key, value]) => {
|
88
|
+
acc[key] = value.package.manifest;
|
89
|
+
return acc;
|
90
|
+
}, {})
|
91
|
+
};
|
92
|
+
}
|
93
|
+
return {
|
94
|
+
wd,
|
95
|
+
root,
|
96
|
+
value: {
|
97
|
+
[wd]: JSON.parse(fs__default.default.readFileSync(path__default.default.resolve(wd, "package.json"), "utf-8"))
|
98
|
+
}
|
99
|
+
};
|
100
|
+
}
|
101
|
+
|
32
102
|
let resolve;
|
33
103
|
function actionDone() {
|
34
104
|
resolve();
|
@@ -37,60 +107,135 @@
|
|
37
107
|
new Promise((r) => resolve = r);
|
38
108
|
}
|
39
109
|
|
110
|
+
function commondir(files, cwd = process.cwd()) {
|
111
|
+
const resolvedFiles = files.map((file) => {
|
112
|
+
if (path__default.default.isAbsolute(file))
|
113
|
+
return file;
|
114
|
+
return path__default.default.resolve(cwd, file);
|
115
|
+
});
|
116
|
+
const sep = "/";
|
117
|
+
const [first = ""] = resolvedFiles;
|
118
|
+
const parts = first.split(sep);
|
119
|
+
let common = "";
|
120
|
+
for (let i = 0; i < parts.length; i++) {
|
121
|
+
const segment = parts[i];
|
122
|
+
if (resolvedFiles.every((file) => file.startsWith(common + segment))) {
|
123
|
+
common += segment + sep;
|
124
|
+
} else {
|
125
|
+
break;
|
126
|
+
}
|
127
|
+
}
|
128
|
+
return common;
|
129
|
+
}
|
130
|
+
|
40
131
|
function mergePackageJson(manifest, cwd) {
|
41
132
|
const {
|
42
|
-
jiek: {
|
43
|
-
exports
|
133
|
+
jiek: { cwd: _, ...jiek } = {}
|
44
134
|
} = manifest;
|
45
|
-
|
135
|
+
let { exports } = manifest;
|
136
|
+
let includeIndex = false;
|
137
|
+
if (typeof exports === "string") {
|
138
|
+
includeIndex = true;
|
139
|
+
exports = { ".": exports };
|
140
|
+
}
|
141
|
+
if (exports === void 0) {
|
142
|
+
exports = { ".": "./src/index.ts" };
|
143
|
+
}
|
144
|
+
if (typeof exports === "object") {
|
145
|
+
if (Array.isArray(exports) && exports.length > 0) {
|
146
|
+
includeIndex = true;
|
147
|
+
} else {
|
148
|
+
includeIndex = !!exports["."];
|
149
|
+
}
|
150
|
+
}
|
151
|
+
const inputs = Array.isArray(exports) ? exports : Object.entries(exports).reduce((acc, [key, value]) => {
|
152
|
+
if (typeof value === "string")
|
153
|
+
return key === "." ? [value, ...acc] : acc.concat(value);
|
154
|
+
if (Array.isArray(value))
|
155
|
+
return acc.concat(value);
|
156
|
+
throw new TypeError(`Unexpected value type for key "${key}" in exports, expected string, got ${typeof value}`);
|
157
|
+
}, []);
|
158
|
+
if (inputs.length === 0)
|
159
|
+
throw new Error("No inputs found");
|
160
|
+
const absoluteInputs = inputs.map(
|
161
|
+
(input) => path__default.default.isAbsolute(input) ? input : path__default.default.resolve(cwd, input)
|
162
|
+
);
|
163
|
+
let cDir = path__default.default.dirname(absoluteInputs[0]);
|
164
|
+
if (absoluteInputs.length > 1) {
|
165
|
+
cDir = commondir(absoluteInputs, cwd);
|
166
|
+
}
|
167
|
+
const resolvedInputs = absoluteInputs.map((input) => {
|
168
|
+
return path__default.default.relative(cDir, input);
|
169
|
+
});
|
46
170
|
return {
|
47
171
|
...manifest,
|
48
|
-
...pkger.pkger({
|
172
|
+
...pkger.pkger({
|
173
|
+
cwd,
|
174
|
+
noIndex: !includeIndex,
|
175
|
+
source: path__default.default.relative(cwd, cDir),
|
176
|
+
inputs: resolvedInputs,
|
177
|
+
...jiek
|
178
|
+
})
|
49
179
|
};
|
50
180
|
}
|
51
181
|
|
52
|
-
commander.program.command("publish").aliases(["pub", "p"]).option("--
|
182
|
+
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 }) => {
|
53
183
|
actionRestore();
|
54
|
-
const
|
55
|
-
const
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
mainfests.push([
|
67
|
-
dir,
|
68
|
-
mergePackageJson(manifest, dir)
|
69
|
-
]);
|
70
|
-
});
|
71
|
-
const passArgs = Object.entries(options).reduce((acc, [key, value]) => {
|
72
|
-
if (value) {
|
73
|
-
acc.push(`--${key}`, value);
|
184
|
+
const { value = {} } = await getSelectedProjectsGraph() ?? {};
|
185
|
+
const selectedProjectsGraphEntries = Object.entries(value);
|
186
|
+
if (selectedProjectsGraphEntries.length === 0) {
|
187
|
+
throw new Error("no packages selected");
|
188
|
+
}
|
189
|
+
const mainfests = selectedProjectsGraphEntries.map(([dir, manifest]) => [
|
190
|
+
dir,
|
191
|
+
mergePackageJson(manifest, dir)
|
192
|
+
]);
|
193
|
+
const passArgs = Object.entries(options).reduce((acc, [key, value2]) => {
|
194
|
+
if (value2) {
|
195
|
+
acc.push(`--${key}`, value2);
|
74
196
|
}
|
75
197
|
return acc;
|
76
198
|
}, []);
|
77
|
-
for (const [dir,
|
78
|
-
const
|
79
|
-
const
|
80
|
-
|
81
|
-
|
199
|
+
for (const [dir, manifest] of mainfests) {
|
200
|
+
const oldJSONString = fs__default.default.readFileSync(path__default.default.join(dir, "package.json"), "utf-8");
|
201
|
+
const oldJSON = JSON.parse(oldJSONString) ?? "0.0.0";
|
202
|
+
const newVersion = bumper.bump(oldJSON.version, bumper$1);
|
203
|
+
const { indent = " " } = detectIndent__default.default(oldJSONString);
|
204
|
+
const formattingOptions = {
|
205
|
+
tabSize: indent.length,
|
206
|
+
insertSpaces: true
|
82
207
|
};
|
83
|
-
|
84
|
-
|
85
|
-
|
208
|
+
let newJSONString = oldJSONString;
|
209
|
+
newJSONString = jsoncParser.applyEdits(newJSONString, jsoncParser.modify(
|
210
|
+
newJSONString,
|
211
|
+
["version"],
|
212
|
+
newVersion,
|
213
|
+
{ formattingOptions }
|
214
|
+
));
|
215
|
+
for (const [key, value2] of Object.entries(manifest)) {
|
216
|
+
if (JSON.stringify(value2) === JSON.stringify(oldJSON[key]))
|
217
|
+
continue;
|
218
|
+
newJSONString = jsoncParser.applyEdits(newJSONString, jsoncParser.modify(
|
219
|
+
newJSONString,
|
220
|
+
["publishConfig", key],
|
221
|
+
value2,
|
222
|
+
{ formattingOptions }
|
223
|
+
));
|
224
|
+
}
|
86
225
|
try {
|
226
|
+
fs__default.default.renameSync(path__default.default.join(dir, "package.json"), path__default.default.join(dir, "package.json.bak"));
|
227
|
+
fs__default.default.writeFileSync(path__default.default.join(dir, "package.json"), newJSONString);
|
228
|
+
console.log(newJSONString);
|
229
|
+
if (preview) {
|
230
|
+
console.warn("preview mode");
|
231
|
+
continue;
|
232
|
+
}
|
87
233
|
childProcess__namespace.execSync(["pnpm", "publish", "--access", "public", "--no-git-checks", ...passArgs].join(" "), {
|
88
234
|
cwd: dir,
|
89
235
|
stdio: "inherit"
|
90
236
|
});
|
91
|
-
const
|
92
|
-
|
93
|
-
fs__default.default.writeFileSync(path__default.default.join(dir, "package.json.bak"), JSON.stringify(oldPackageJson, null, 2));
|
237
|
+
const modifyVersionPackageJSON = jsoncParser.applyEdits(oldJSONString, jsoncParser.modify(oldJSONString, ["version"], newVersion, {}));
|
238
|
+
fs__default.default.writeFileSync(path__default.default.join(dir, "package.json.bak"), modifyVersionPackageJSON);
|
94
239
|
} finally {
|
95
240
|
fs__default.default.unlinkSync(path__default.default.join(dir, "package.json"));
|
96
241
|
fs__default.default.renameSync(path__default.default.join(dir, "package.json.bak"), path__default.default.join(dir, "package.json"));
|
@@ -107,43 +252,23 @@ const templateArg = jiek.templateArgFilePath
|
|
107
252
|
: {
|
108
253
|
styled: jiek.styled
|
109
254
|
}
|
110
|
-
module.exports = require('
|
255
|
+
module.exports = require('jiek/rollup').template(templateArg, pkg)
|
111
256
|
`.trimStart();
|
112
|
-
commander.program.command("build").
|
257
|
+
commander.program.command("build").action(async () => {
|
113
258
|
actionRestore();
|
114
|
-
const
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
throw new Error("root path is workspace root, please provide a filter");
|
121
|
-
}
|
122
|
-
if (root !== wd && !filter) {
|
123
|
-
const packageJSONIsExist = fs__default.default.existsSync(path__default.default.resolve(root, "package.json"));
|
124
|
-
if (!packageJSONIsExist) {
|
125
|
-
throw new Error("root path is not workspace root, please provide a filter");
|
126
|
-
}
|
127
|
-
const packageJSON = JSON.parse(fs__default.default.readFileSync(path__default.default.resolve(root, "package.json"), "utf-8"));
|
128
|
-
if (!packageJSON.name) {
|
129
|
-
throw new Error("root path is not workspace root, please provide a filter");
|
130
|
-
}
|
131
|
-
filter = packageJSON.name;
|
259
|
+
const {
|
260
|
+
wd,
|
261
|
+
value = {}
|
262
|
+
} = await getSelectedProjectsGraph() ?? {};
|
263
|
+
if (Object.keys(value).length === 0) {
|
264
|
+
throw new Error("no package found");
|
132
265
|
}
|
133
|
-
const { selectedProjectsGraph } = await filterWorkspacePackages.filterPackagesFromDir(wd, [{
|
134
|
-
filter: filter ?? "",
|
135
|
-
followProdDepsOnly: true
|
136
|
-
}], {
|
137
|
-
prefix: root,
|
138
|
-
workspaceDir: wd,
|
139
|
-
patterns: pnpmWorkspace.packages
|
140
|
-
});
|
141
266
|
const jiekTempDir = (...paths) => path__default.default.resolve(wd, "node_modules/.jiek", ...paths);
|
142
267
|
if (!fs__default.default.existsSync(jiekTempDir()))
|
143
268
|
fs__default.default.mkdirSync(jiekTempDir());
|
144
269
|
const rollupBinaryPath = require.resolve("rollup").replace(/dist\/rollup.js$/, "dist/bin/rollup");
|
145
270
|
let i = 0;
|
146
|
-
for (const [dir,
|
271
|
+
for (const [dir, manifest] of Object.entries(value)) {
|
147
272
|
const newManifest = mergePackageJson(manifest, dir);
|
148
273
|
const escapeManifestName = manifest.name?.replace(/^@/g, "").replace(/\//g, "+");
|
149
274
|
const configFile = jiekTempDir(
|
@@ -164,6 +289,8 @@ module.exports = require('${process.env.NODE_ENV === "test" ? "jiek/src/rollup/i
|
|
164
289
|
actionDone();
|
165
290
|
});
|
166
291
|
|
292
|
+
const pkg = require("../package.json");
|
293
|
+
commander.program.version(pkg.version).description(pkg.description).option("--root <root>", "root path");
|
167
294
|
commander.program.parse(process.argv);
|
168
295
|
|
169
296
|
}));
|
package/dist/index.umd.js.map
CHANGED
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"index.umd.js","sources":["../src/inner.ts","../src/merge-package-json.ts","../src/commands/publish.ts","../src/commands/build.ts","../src/index.ts"],"sourcesContent":["let resolve: () => void\n\nexport let actionFuture: Promise<void>\n\nexport function actionDone() {\n resolve()\n}\n\nexport function actionRestore() {\n actionFuture = new Promise<void>(r => resolve = r)\n}\n","import { type Options, pkger } from '@jiek/pkger'\nimport type { PackageJson } from '@npm/types'\nimport type { Manifest } from '@pnpm/workspace.pkgs-graph'\n\nexport function mergePackageJson(manifest: Manifest & {\n jiek?: Options\n exports?: unknown | unknown[]\n}, cwd: string) {\n const {\n jiek: { inputs: jiekInputs, cwd: _, ...jiek } = {}, exports\n } = manifest\n const inputs = jiekInputs ?? (\n Array.isArray(exports) ? exports : undefined\n )\n return {\n ...manifest,\n ...pkger({ inputs, cwd, ...jiek })\n } as PackageJson\n}\n","import fs from 'node:fs'\nimport path from 'node:path'\n\nimport { bump, type BumperType } from '@jiek/utils/bumper'\nimport { getWorkspaceDir } from '@jiek/utils/getWorkspaceDir'\nimport type { PackageJson } from '@npm/types'\nimport { filterPackagesFromDir } from '@pnpm/filter-workspace-packages'\nimport * as childProcess from 'child_process'\nimport { program } from 'commander'\n\nimport { actionDone, actionRestore } from '../inner'\nimport { mergePackageJson } from '../merge-package-json'\n\nprogram\n .command('publish')\n .aliases(['pub', 'p'])\n .option('--filter <filter>', 'filter packages')\n .option('--root <root>', 'root path')\n .option('--bumper <bumper>', 'bump version', 'patch')\n .action(async ({ root: rootOption, filter, bumper, ...options }: {\n root?: string\n filter?: string\n bumper: BumperType\n }) => {\n actionRestore()\n const root = rootOption\n ? path.isAbsolute(rootOption)\n ? rootOption\n : path.resolve(process.cwd(), rootOption)\n : process.cwd()\n const wd = getWorkspaceDir(root)\n const { selectedProjectsGraph } = await filterPackagesFromDir(wd, [{\n filter: filter ?? '',\n followProdDepsOnly: true\n }], {\n prefix: root,\n workspaceDir: wd,\n patterns: ['packages/*']\n })\n const mainfests: [dir: string, PackageJson][] = []\n Object\n .entries(selectedProjectsGraph)\n .forEach(([, { package: { dir, manifest } }]) => {\n mainfests.push([\n dir, mergePackageJson(manifest, dir)\n ])\n })\n const passArgs = Object\n .entries(options)\n .reduce((acc, [key, value]) => {\n if (value) {\n acc.push(`--${key}`, value as string)\n }\n return acc\n }, [] as string[])\n for (const [dir, m] of mainfests) {\n const newVersion = bump(m.version, bumper)\n const newManifest = {\n ...m,\n version: newVersion\n }\n fs.renameSync(path.join(dir, 'package.json'), path.join(dir, 'package.json.bak'))\n fs.writeFileSync(path.join(dir, 'package.json'), JSON.stringify(newManifest, null, 2))\n console.log(newManifest)\n try {\n childProcess.execSync(['pnpm', 'publish', '--access', 'public', '--no-git-checks', ...passArgs].join(' '), {\n cwd: dir,\n stdio: 'inherit'\n })\n const oldPackageJson = JSON.parse(fs.readFileSync(path.join(dir, 'package.json.bak'), 'utf-8'))\n oldPackageJson.version = newVersion\n fs.writeFileSync(path.join(dir, 'package.json.bak'), JSON.stringify(oldPackageJson, null, 2))\n } finally {\n fs.unlinkSync(path.join(dir, 'package.json'))\n fs.renameSync(path.join(dir, 'package.json.bak'), path.join(dir, 'package.json'))\n }\n }\n actionDone()\n })\n","import * as childProcess from 'node:child_process'\nimport fs from 'node:fs'\nimport path from 'node:path'\n\nimport { getWorkspaceDir } from '@jiek/utils/getWorkspaceDir'\nimport { filterPackagesFromDir } from '@pnpm/filter-workspace-packages'\nimport { program } from 'commander'\nimport { load } from 'js-yaml'\n\nimport { actionDone, actionRestore } from '../inner'\nimport { mergePackageJson } from '../merge-package-json'\n\nconst FILE_TEMPLATE = (manifest: unknown) => `\nconst pkg = ${JSON.stringify(manifest, null, 2)}\nconst { jiek = {} } = pkg\nconst templateArg = jiek.templateArgFilePath\n ? require.resolve(jiek.templateArgFilePath)\n : {\n styled: jiek.styled\n }\nmodule.exports = require('${\n process.env.NODE_ENV === 'test'\n ? 'jiek/src/rollup/index.ts'\n : 'jiek/rollup'\n}').template(templateArg, pkg)\n`.trimStart()\n\nprogram\n .command('build')\n .option('--filter <filter>', 'filter packages')\n .option('--root <root>', 'root path')\n .action(async ({ root: rootOption, filter, ...options }: {\n root?: string\n filter?: string\n }) => {\n actionRestore()\n const root = rootOption\n ? path.isAbsolute(rootOption)\n ? rootOption\n : path.resolve(process.cwd(), rootOption)\n : process.cwd()\n const wd = getWorkspaceDir(root)\n const pnpmWorkspaceFilePath = path.resolve(wd, 'pnpm-workspace.yaml')\n const pnpmWorkspaceFileContent = fs.readFileSync(pnpmWorkspaceFilePath, 'utf-8')\n const pnpmWorkspace = load(pnpmWorkspaceFileContent) as {\n packages: string[]\n }\n if (root === wd && !filter) {\n throw new Error('root path is workspace root, please provide a filter')\n // TODO inquirer prompt support user select packages\n }\n if (root !== wd && !filter) {\n const packageJSONIsExist = fs.existsSync(path.resolve(root, 'package.json'))\n if (!packageJSONIsExist) {\n throw new Error('root path is not workspace root, please provide a filter')\n }\n const packageJSON = JSON.parse(fs.readFileSync(path.resolve(root, 'package.json'), 'utf-8'))\n if (!packageJSON.name) {\n throw new Error('root path is not workspace root, please provide a filter')\n }\n filter = packageJSON.name\n }\n const { selectedProjectsGraph } = await filterPackagesFromDir(wd, [{\n filter: filter ?? '',\n followProdDepsOnly: true\n }], {\n prefix: root,\n workspaceDir: wd,\n patterns: pnpmWorkspace.packages\n })\n const jiekTempDir = (...paths: string[]) => path.resolve(wd, 'node_modules/.jiek', ...paths)\n if (!fs.existsSync(jiekTempDir())) fs.mkdirSync(jiekTempDir())\n\n const rollupBinaryPath = require.resolve('rollup')\n .replace(/dist\\/rollup.js$/, 'dist/bin/rollup')\n let i = 0\n for (const [dir, { package: { manifest } }] of Object.entries(selectedProjectsGraph)) {\n const newManifest = mergePackageJson(manifest, dir)\n // TODO support auto build child packages in workspaces\n const escapeManifestName = manifest.name?.replace(/^@/g, '').replace(/\\//g, '+')\n const configFile = jiekTempDir(\n `${escapeManifestName ?? `anonymous-${i++}`}.rollup.config.js`\n )\n fs.writeFileSync(configFile, FILE_TEMPLATE(newManifest))\n let prefix = ''\n if (process.env.NODE_ENV === 'test') {\n const registerPath = require.resolve('esbuild-register')\n const loaderPath = require.resolve('esbuild-register/loader')\n prefix = `node --import ${registerPath} -r ${loaderPath} `\n }\n // TODO replace with `spawn` to support watch mode\n childProcess.execSync(`${prefix}${rollupBinaryPath} -c ${configFile}`, {\n cwd: dir, stdio: 'inherit'\n })\n }\n\n actionDone()\n })\n","import './commands/publish'\nimport './commands/build'\n\nimport { program } from 'commander'\n\nprogram.parse(process.argv)\n"],"names":["pkger","program","bumper","path","getWorkspaceDir","filterPackagesFromDir","bump","fs","childProcess","load"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAAA,IAAI,OAAA,CAAA;EAIG,SAAS,UAAa,GAAA;EAC3B,EAAQ,OAAA,EAAA,CAAA;EACV,CAAA;EAEO,SAAS,aAAgB,GAAA;EAC9B,EAAe,IAAI,OAAA,CAAc,CAAK,CAAA,KAAA,OAAA,GAAU,CAAC,CAAA,CAAA;EACnD;;ECNgB,SAAA,gBAAA,CAAiB,UAG9B,GAAa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upport.ts","../src/inner.ts","../src/utils/commondir.ts","../src/merge-package-json.ts","../src/commands/publish.ts","../src/commands/build.ts","../src/index.ts"],"sourcesContent":["import fs from 'node:fs'\nimport path from 'node:path'\n\nimport { getWorkspaceDir } from '@jiek/utils/getWorkspaceDir'\nimport { filterPackagesFromDir } from '@pnpm/filter-workspace-packages'\nimport { program } from 'commander'\nimport { load } from 'js-yaml'\n\nexport let type = ''\n\ntry {\n require.resolve('@pnpm/filter-workspace-packages')\n type = 'pnpm'\n} catch { /* empty */ }\nif (type !== '') {\n program\n .option('-f, --filter <filter>', 'filter packages')\n}\n\ninterface ProjectsGraph {\n wd: string\n root: string\n value?: Record<string, {\n name?: string\n }>\n}\n\nexport async function getSelectedProjectsGraph(): Promise<ProjectsGraph> {\n let filter = program.getOptionValue('filter')\n const rootOption = program.getOptionValue('root')\n const root = rootOption\n ? path.isAbsolute(rootOption)\n ? rootOption\n : path.resolve(process.cwd(), rootOption)\n : process.cwd()\n let notWorkspace = false\n let wd: string\n try {\n wd = getWorkspaceDir(root, type)\n } catch (e) {\n // @ts-ignore\n if ('message' in e && e.message === 'workspace root not found') {\n wd = root\n notWorkspace = true\n } else {\n throw e\n }\n }\n if (!notWorkspace && type === 'pnpm') {\n const pnpmWorkspaceFilePath = path.resolve(wd, 'pnpm-workspace.yaml')\n const pnpmWorkspaceFileContent = fs.readFileSync(pnpmWorkspaceFilePath, 'utf-8')\n const pnpmWorkspace = load(pnpmWorkspaceFileContent) as {\n packages: string[]\n }\n if (root === wd && !filter) {\n throw new Error('root path is workspace root, please provide a filter')\n // TODO inquirer prompt support user select packages\n }\n if (root !== wd && !filter) {\n const packageJSONIsExist = fs.existsSync(path.resolve(root, 'package.json'))\n if (!packageJSONIsExist) {\n throw new Error('root path is not workspace root, please provide a filter')\n }\n const packageJSON = JSON.parse(fs.readFileSync(path.resolve(root, 'package.json'), 'utf-8'))\n if (!packageJSON.name) {\n throw new Error('root path is not workspace root, please provide a filter')\n }\n filter = packageJSON.name\n }\n const { selectedProjectsGraph } = await filterPackagesFromDir(wd, [{\n filter: filter ?? '',\n followProdDepsOnly: true\n }], {\n prefix: root,\n workspaceDir: wd,\n patterns: pnpmWorkspace.packages\n })\n return {\n wd, root,\n value: Object.entries(selectedProjectsGraph)\n .reduce((acc, [key, value]) => {\n acc[key] = value.package.manifest\n return acc\n }, {} as NonNullable<ProjectsGraph['value']>)\n }\n }\n return {\n wd, root,\n value: {\n [wd]: JSON.parse(fs.readFileSync(path.resolve(wd, 'package.json'), 'utf-8'))\n }\n }\n}\n","let resolve: () => void\n\nexport let actionFuture: Promise<void>\n\nexport function actionDone() {\n resolve()\n}\n\nexport function actionRestore() {\n actionFuture = new Promise<void>(r => resolve = r)\n}\n","import path from 'node:path'\n\nexport function commondir(files: string[], cwd = process.cwd()): string {\n const resolvedFiles = files.map(file => {\n if (path.isAbsolute(file)) return file\n return path.resolve(cwd, file)\n })\n const sep = '/'\n const [first = ''] = resolvedFiles\n const parts = first.split(sep)\n let common = ''\n for (let i = 0; i < parts.length; i++) {\n const segment = parts[i]\n if (resolvedFiles.every(file => file.startsWith(common + segment))) {\n common += segment + sep\n } else {\n break\n }\n }\n return common\n}\n","import path from 'node:path'\n\nimport { type Options, pkger } from '@jiek/pkger'\nimport type { Manifest } from '@pnpm/workspace.pkgs-graph'\n\nimport { commondir } from './utils/commondir'\n\nexport function mergePackageJson(manifest: Manifest & {\n jiek?: Options\n exports?: unknown | unknown[]\n}, cwd: string) {\n const {\n jiek: { cwd: _, ...jiek } = {}\n } = manifest\n let { exports } = manifest\n let includeIndex = false\n if (typeof exports === 'string') {\n includeIndex = true\n exports = { '.': exports }\n }\n if (exports === undefined) {\n exports = { '.': './src/index.ts' }\n }\n if (typeof exports === 'object') {\n if (Array.isArray(exports) && exports.length > 0) {\n includeIndex = true\n } else {\n includeIndex = !!(<Record<string, unknown>>exports)['.']\n }\n }\n const inputs = Array.isArray(exports)\n ? exports as string[]\n : Object\n .entries(<Record<string, unknown>>exports)\n .reduce((acc, [key, value]) => {\n if (typeof value === 'string') return key === '.'\n ? [value, ...acc]\n : acc.concat(value)\n if (Array.isArray(value)) return acc.concat(value)\n\n throw new TypeError(`Unexpected value type for key \"${key}\" in exports, expected string, got ${typeof value}`)\n }, [] as string[])\n if (inputs.length === 0)\n throw new Error('No inputs found')\n\n const absoluteInputs = inputs.map(input => path.isAbsolute(input)\n ? input\n : path.resolve(cwd, input)\n )\n let cDir = path.dirname(absoluteInputs[0])\n if (absoluteInputs.length > 1) {\n cDir = commondir(absoluteInputs, cwd)\n }\n const resolvedInputs = absoluteInputs.map(input => {\n return path.relative(cDir, input)\n })\n return {\n ...manifest,\n ...pkger({\n cwd,\n noIndex: !includeIndex,\n source: path.relative(cwd, cDir),\n inputs: resolvedInputs,\n ...jiek\n })\n }\n}\n","import fs from 'node:fs'\nimport path from 'node:path'\n\nimport { bump, type BumperType } from '@jiek/utils/bumper'\nimport * as childProcess from 'child_process'\nimport { program } from 'commander'\nimport detectIndent from 'detect-indent'\nimport { applyEdits, modify } from 'jsonc-parser'\n\nimport { actionDone, actionRestore } from '../inner'\nimport { mergePackageJson } from '../merge-package-json'\nimport { getSelectedProjectsGraph } from '../utils/filterSupport'\n\nprogram\n .command('publish')\n .aliases(['pub', 'p'])\n .option('-b, --bumper <bumper>', 'bump version', 'patch')\n .option('-p, --preview', 'preview publish')\n .action(async ({ preview, bumper, ...options }: {\n preview?: boolean\n bumper: BumperType\n }) => {\n actionRestore()\n\n const { value = {} } = await getSelectedProjectsGraph() ?? {}\n const selectedProjectsGraphEntries = Object.entries(value)\n if (selectedProjectsGraphEntries.length === 0) {\n throw new Error('no packages selected')\n }\n const mainfests = selectedProjectsGraphEntries\n .map(([dir, manifest]) => [\n dir, mergePackageJson(manifest, dir)\n ] as const)\n const passArgs = Object\n .entries(options)\n .reduce((acc, [key, value]) => {\n if (value) {\n acc.push(`--${key}`, value as string)\n }\n return acc\n }, [] as string[])\n for (const [dir, manifest] of mainfests) {\n const oldJSONString = fs.readFileSync(path.join(dir, 'package.json'), 'utf-8')\n const oldJSON = JSON.parse(oldJSONString) ?? '0.0.0'\n const newVersion = bump(oldJSON.version, bumper)\n // TODO detectIndent by editorconfig\n const { indent = ' ' } = detectIndent(oldJSONString)\n const formattingOptions = {\n tabSize: indent.length,\n insertSpaces: true\n }\n let newJSONString = oldJSONString\n newJSONString = applyEdits(newJSONString, modify(\n newJSONString, ['version'], newVersion, { formattingOptions }\n ))\n for (const [key, value] of Object.entries(manifest)) {\n if (JSON.stringify(value) === JSON.stringify(oldJSON[key])) continue\n\n newJSONString = applyEdits(newJSONString, modify(\n newJSONString, ['publishConfig', key], value, { formattingOptions }\n ))\n }\n try {\n fs.renameSync(path.join(dir, 'package.json'), path.join(dir, 'package.json.bak'))\n fs.writeFileSync(path.join(dir, 'package.json'), newJSONString)\n console.log(newJSONString)\n if (preview) {\n console.warn('preview mode')\n continue\n }\n childProcess.execSync(['pnpm', 'publish', '--access', 'public', '--no-git-checks', ...passArgs].join(' '), {\n cwd: dir,\n stdio: 'inherit'\n })\n const modifyVersionPackageJSON = applyEdits(oldJSONString, modify(oldJSONString, ['version'], newVersion, {}))\n fs.writeFileSync(path.join(dir, 'package.json.bak'), modifyVersionPackageJSON)\n } finally {\n fs.unlinkSync(path.join(dir, 'package.json'))\n fs.renameSync(path.join(dir, 'package.json.bak'), path.join(dir, 'package.json'))\n }\n }\n actionDone()\n })\n","import * as childProcess from 'node:child_process'\nimport fs from 'node:fs'\nimport path from 'node:path'\n\nimport { program } from 'commander'\n\nimport { actionDone, actionRestore } from '../inner'\nimport { mergePackageJson } from '../merge-package-json'\nimport { getSelectedProjectsGraph } from '../utils/filterSupport'\n\nconst FILE_TEMPLATE = (manifest: unknown) => `\nconst pkg = ${JSON.stringify(manifest, null, 2)}\nconst { jiek = {} } = pkg\nconst templateArg = jiek.templateArgFilePath\n ? require.resolve(jiek.templateArgFilePath)\n : {\n styled: jiek.styled\n }\nmodule.exports = require('jiek/rollup').template(templateArg, pkg)\n`.trimStart()\n\nprogram\n .command('build')\n .action(async () => {\n actionRestore()\n const {\n wd, value = {}\n } = await getSelectedProjectsGraph() ?? {}\n\n if (Object.keys(value).length === 0) {\n throw new Error('no package found')\n }\n const jiekTempDir = (...paths: string[]) => path.resolve(wd, 'node_modules/.jiek', ...paths)\n if (!fs.existsSync(jiekTempDir())) fs.mkdirSync(jiekTempDir())\n\n const rollupBinaryPath = require.resolve('rollup')\n .replace(/dist\\/rollup.js$/, 'dist/bin/rollup')\n let i = 0\n for (const [dir, manifest] of Object.entries(value)) {\n const newManifest = mergePackageJson(manifest, dir)\n // TODO support auto build child packages in workspaces\n const escapeManifestName = manifest.name?.replace(/^@/g, '').replace(/\\//g, '+')\n const configFile = jiekTempDir(\n `${escapeManifestName ?? `anonymous-${i++}`}.rollup.config.js`\n )\n fs.writeFileSync(configFile, FILE_TEMPLATE(newManifest))\n let prefix = ''\n if (process.env.NODE_ENV === 'test') {\n const registerPath = require.resolve('esbuild-register')\n const loaderPath = require.resolve('esbuild-register/loader')\n prefix = `node --import ${registerPath} -r ${loaderPath} `\n }\n // TODO replace with `spawn` to support watch mode\n childProcess.execSync(`${prefix}${rollupBinaryPath} -c ${configFile}`, {\n cwd: dir, stdio: 'inherit'\n })\n }\n\n actionDone()\n })\n","import './utils/filterSupport'\nimport './commands/publish'\nimport './commands/build'\n\nimport { program } from 'commander'\n\n// eslint-disable-next-line @typescript-eslint/no-var-requires\nconst pkg = require('../package.json')\n\nprogram\n .version(pkg.version)\n .description(pkg.description)\n .option('--root <root>', 'root path')\n\nprogram.parse(process.argv)\n"],"names":["program","path","getWorkspaceDir","fs","load","filterPackagesFromDir","pkger","bumper","value","bump","detectIndent","applyEdits","modify","childProcess"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAQO,IAAI,IAAO,GAAA,EAAA,CAAA;EAElB,IAAI;EACF,EAAA,OAAA,CAAQ,QAAQ,iCAAiC,CAAA,CAAA;EACjD,EAAO,IAAA,GA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QAAQ,IAAI,CAAA;;;;;;"}
|
package/dist/index.umd.min.js
CHANGED
@@ -1,2 +1,2 @@
|
|
1
|
-
!function(e,r){"object"==typeof exports&&"undefined"!=typeof module?r(require("node:fs"),require("node:path"),require("@jiek/utils/
|
1
|
+
!function(e,r){"object"==typeof exports&&"undefined"!=typeof module?r(require("node:fs"),require("node:path"),require("@jiek/utils/getWorkspaceDir"),require("@pnpm/filter-workspace-packages"),require("commander"),require("js-yaml"),require("@jiek/utils/bumper"),require("child_process"),require("detect-indent"),require("jsonc-parser"),require("@jiek/pkger"),require("node:child_process")):"function"==typeof define&&define.amd?define(["node:fs","node:path","@jiek/utils/getWorkspaceDir","@pnpm/filter-workspace-packages","commander","js-yaml","@jiek/utils/bumper","child_process","detect-indent","jsonc-parser","@jiek/pkger","node:child_process"],r):r((e="undefined"!=typeof globalThis?globalThis:e||self).fs,e.path,e.getWorkspaceDir,e.filterWorkspacePackages,e.commander,e.jsYaml,e.bumper,e.childProcess,e.detectIndent,e.jsoncParser,e.pkger,e.childProcess$1)}(this,(function(e,r,t,o,n,i,s,a,c,l,p,u){"use strict";function d(e){return e&&e.__esModule?e:{default:e}}function f(e){if(e&&e.__esModule)return e;var r=Object.create(null);return e&&Object.keys(e).forEach((function(t){if("default"!==t){var o=Object.getOwnPropertyDescriptor(e,t);Object.defineProperty(r,t,o.get?o:{enumerable:!0,get:function(){return e[t]}})}})),r.default=e,Object.freeze(r)}var g=d(e),m=d(r),k=f(a),y=d(c),j=f(u);let w,h="";try{require.resolve("@pnpm/filter-workspace-packages"),h="pnpm"}catch{}async function b(){let e=n.program.getOptionValue("filter");const r=n.program.getOptionValue("root"),s=r?m.default.isAbsolute(r)?r:m.default.resolve(process.cwd(),r):process.cwd();let a,c=!1;try{a=t.getWorkspaceDir(s,h)}catch(e){if(!("message"in e)||"workspace root not found"!==e.message)throw e;a=s,c=!0}if(!c&&"pnpm"===h){const r=m.default.resolve(a,"pnpm-workspace.yaml"),t=g.default.readFileSync(r,"utf-8"),n=i.load(t);if(s===a&&!e)throw new Error("root path is workspace root, please provide a filter");if(s!==a&&!e){if(!g.default.existsSync(m.default.resolve(s,"package.json")))throw new Error("root path is not workspace root, please provide a filter");const r=JSON.parse(g.default.readFileSync(m.default.resolve(s,"package.json"),"utf-8"));if(!r.name)throw new Error("root path is not workspace root, please provide a filter");e=r.name}const{selectedProjectsGraph:c}=await o.filterPackagesFromDir(a,[{filter:e??"",followProdDepsOnly:!0}],{prefix:s,workspaceDir:a,patterns:n.packages});return{wd:a,root:s,value:Object.entries(c).reduce(((e,[r,t])=>(e[r]=t.package.manifest,e)),{})}}return{wd:a,root:s,value:{[a]:JSON.parse(g.default.readFileSync(m.default.resolve(a,"package.json"),"utf-8"))}}}function v(){w()}function O(){new Promise((e=>w=e))}function S(e,r){const{jiek:{cwd:t,...o}={}}=e;let{exports:n}=e,i=!1;"string"==typeof n&&(i=!0,n={".":n}),void 0===n&&(n={".":"./src/index.ts"}),"object"==typeof n&&(i=!!(Array.isArray(n)&&n.length>0)||!!n["."]);const s=Array.isArray(n)?n:Object.entries(n).reduce(((e,[r,t])=>{if("string"==typeof t)return"."===r?[t,...e]:e.concat(t);if(Array.isArray(t))return e.concat(t);throw new TypeError(`Unexpected value type for key "${r}" in exports, expected string, got ${typeof t}`)}),[]);if(0===s.length)throw new Error("No inputs found");const a=s.map((e=>m.default.isAbsolute(e)?e:m.default.resolve(r,e)));let c=m.default.dirname(a[0]);a.length>1&&(c=function(e,r=process.cwd()){const t=e.map((e=>m.default.isAbsolute(e)?e:m.default.resolve(r,e))),[o=""]=t,n=o.split("/");let i="";for(let e=0;e<n.length;e++){const r=n[e];if(!t.every((e=>e.startsWith(i+r))))break;i+=r+"/"}return i}(a,r));const l=a.map((e=>m.default.relative(c,e)));return{...e,...p.pkger({cwd:r,noIndex:!i,source:m.default.relative(r,c),inputs:l,...o})}}""!==h&&n.program.option("-f, --filter <filter>","filter packages"),n.program.command("publish").aliases(["pub","p"]).option("-b, --bumper <bumper>","bump version","patch").option("-p, --preview","preview publish").action((async({preview:e,bumper:r,...t})=>{O();const{value:o={}}=await b()??{},n=Object.entries(o);if(0===n.length)throw new Error("no packages selected");const i=n.map((([e,r])=>[e,S(r,e)])),a=Object.entries(t).reduce(((e,[r,t])=>(t&&e.push(`--${r}`,t),e)),[]);for(const[t,o]of i){const n=g.default.readFileSync(m.default.join(t,"package.json"),"utf-8"),i=JSON.parse(n)??"0.0.0",c=s.bump(i.version,r),{indent:p=" "}=y.default(n),u={tabSize:p.length,insertSpaces:!0};let d=n;d=l.applyEdits(d,l.modify(d,["version"],c,{formattingOptions:u}));for(const[e,r]of Object.entries(o))JSON.stringify(r)!==JSON.stringify(i[e])&&(d=l.applyEdits(d,l.modify(d,["publishConfig",e],r,{formattingOptions:u})));try{if(g.default.renameSync(m.default.join(t,"package.json"),m.default.join(t,"package.json.bak")),g.default.writeFileSync(m.default.join(t,"package.json"),d),console.log(d),e){console.warn("preview mode");continue}k.execSync(["pnpm","publish","--access","public","--no-git-checks",...a].join(" "),{cwd:t,stdio:"inherit"});const r=l.applyEdits(n,l.modify(n,["version"],c,{}));g.default.writeFileSync(m.default.join(t,"package.json.bak"),r)}finally{g.default.unlinkSync(m.default.join(t,"package.json")),g.default.renameSync(m.default.join(t,"package.json.bak"),m.default.join(t,"package.json"))}}v()}));const q=e=>`\nconst pkg = ${JSON.stringify(e,null,2)}\nconst { jiek = {} } = pkg\nconst templateArg = jiek.templateArgFilePath\n ? require.resolve(jiek.templateArgFilePath)\n : {\n styled: jiek.styled\n }\nmodule.exports = require('jiek/rollup').template(templateArg, pkg)\n`.trimStart();n.program.command("build").action((async()=>{O();const{wd:e,value:r={}}=await b()??{};if(0===Object.keys(r).length)throw new Error("no package found");const t=(...r)=>m.default.resolve(e,"node_modules/.jiek",...r);g.default.existsSync(t())||g.default.mkdirSync(t());const o=require.resolve("rollup").replace(/dist\/rollup.js$/,"dist/bin/rollup");let n=0;for(const[e,i]of Object.entries(r)){const r=S(i,e),s=i.name?.replace(/^@/g,"").replace(/\//g,"+"),a=t(`${s??"anonymous-"+n++}.rollup.config.js`);g.default.writeFileSync(a,q(r));let c="";if("test"===process.env.NODE_ENV){c=`node --import ${require.resolve("esbuild-register")} -r ${require.resolve("esbuild-register/loader")} `}j.execSync(`${c}${o} -c ${a}`,{cwd:e,stdio:"inherit"})}v()}));const x=require("../package.json");n.program.version(x.version).description(x.description).option("--root <root>","root path"),n.program.parse(process.argv)}));
|
2
2
|
//# sourceMappingURL=index.umd.min.js.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"index.umd.min.js","sources":["../src/inner.ts","../src/merge-package-json.ts","../src/commands/publish.ts","../src/commands/build.ts","../src/index.ts"],"sourcesContent":["let resolve: () => void\n\nexport let actionFuture: Promise<void>\n\nexport function actionDone() {\n resolve()\n}\n\nexport function actionRestore() {\n actionFuture = new Promise<void>(r => resolve = r)\n}\n","import { type Options, pkger } from '@jiek/pkger'\nimport type { PackageJson } from '@npm/types'\nimport type { Manifest } from '@pnpm/workspace.pkgs-graph'\n\nexport function mergePackageJson(manifest: Manifest & {\n jiek?: Options\n exports?: unknown | unknown[]\n}, cwd: string) {\n const {\n jiek: { inputs: jiekInputs, cwd: _, ...jiek } = {}, exports\n } = manifest\n const inputs = jiekInputs ?? (\n Array.isArray(exports) ? exports : undefined\n )\n return {\n ...manifest,\n ...pkger({ inputs, cwd, ...jiek })\n } as PackageJson\n}\n","import fs from 'node:fs'\nimport path from 'node:path'\n\nimport { bump, type BumperType } from '@jiek/utils/bumper'\nimport { getWorkspaceDir } from '@jiek/utils/getWorkspaceDir'\nimport type { PackageJson } from '@npm/types'\nimport { filterPackagesFromDir } from '@pnpm/filter-workspace-packages'\nimport * as childProcess from 'child_process'\nimport { program } from 'commander'\n\nimport { actionDone, actionRestore } from '../inner'\nimport { mergePackageJson } from '../merge-package-json'\n\nprogram\n .command('publish')\n .aliases(['pub', 'p'])\n .option('--filter <filter>', 'filter packages')\n .option('--root <root>', 'root path')\n .option('--bumper <bumper>', 'bump version', 'patch')\n .action(async ({ root: rootOption, filter, bumper, ...options }: {\n root?: string\n filter?: string\n bumper: BumperType\n }) => {\n actionRestore()\n const root = rootOption\n ? path.isAbsolute(rootOption)\n ? rootOption\n : path.resolve(process.cwd(), rootOption)\n : process.cwd()\n const wd = getWorkspaceDir(root)\n const { selectedProjectsGraph } = await filterPackagesFromDir(wd, [{\n filter: filter ?? '',\n followProdDepsOnly: true\n }], {\n prefix: root,\n workspaceDir: wd,\n patterns: ['packages/*']\n })\n const mainfests: [dir: string, PackageJson][] = []\n Object\n .entries(selectedProjectsGraph)\n .forEach(([, { package: { dir, manifest } }]) => {\n mainfests.push([\n dir, mergePackageJson(manifest, dir)\n ])\n })\n const passArgs = Object\n .entries(options)\n .reduce((acc, [key, value]) => {\n if (value) {\n acc.push(`--${key}`, value as string)\n }\n return acc\n }, [] as string[])\n for (const [dir, m] of mainfests) {\n const newVersion = bump(m.version, bumper)\n const newManifest = {\n ...m,\n version: newVersion\n }\n fs.renameSync(path.join(dir, 'package.json'), path.join(dir, 'package.json.bak'))\n fs.writeFileSync(path.join(dir, 'package.json'), JSON.stringify(newManifest, null, 2))\n console.log(newManifest)\n try {\n childProcess.execSync(['pnpm', 'publish', '--access', 'public', '--no-git-checks', ...passArgs].join(' '), {\n cwd: dir,\n stdio: 'inherit'\n })\n const oldPackageJson = JSON.parse(fs.readFileSync(path.join(dir, 'package.json.bak'), 'utf-8'))\n oldPackageJson.version = newVersion\n fs.writeFileSync(path.join(dir, 'package.json.bak'), JSON.stringify(oldPackageJson, null, 2))\n } finally {\n fs.unlinkSync(path.join(dir, 'package.json'))\n fs.renameSync(path.join(dir, 'package.json.bak'), path.join(dir, 'package.json'))\n }\n }\n actionDone()\n })\n","import * as childProcess from 'node:child_process'\nimport fs from 'node:fs'\nimport path from 'node:path'\n\nimport { getWorkspaceDir } from '@jiek/utils/getWorkspaceDir'\nimport { filterPackagesFromDir } from '@pnpm/filter-workspace-packages'\nimport { program } from 'commander'\nimport { load } from 'js-yaml'\n\nimport { actionDone, actionRestore } from '../inner'\nimport { mergePackageJson } from '../merge-package-json'\n\nconst FILE_TEMPLATE = (manifest: unknown) => `\nconst pkg = ${JSON.stringify(manifest, null, 2)}\nconst { jiek = {} } = pkg\nconst templateArg = jiek.templateArgFilePath\n ? require.resolve(jiek.templateArgFilePath)\n : {\n styled: jiek.styled\n }\nmodule.exports = require('${\n process.env.NODE_ENV === 'test'\n ? 'jiek/src/rollup/index.ts'\n : 'jiek/rollup'\n}').template(templateArg, pkg)\n`.trimStart()\n\nprogram\n .command('build')\n .option('--filter <filter>', 'filter packages')\n .option('--root <root>', 'root path')\n .action(async ({ root: rootOption, filter, ...options }: {\n root?: string\n filter?: string\n }) => {\n actionRestore()\n const root = rootOption\n ? path.isAbsolute(rootOption)\n ? rootOption\n : path.resolve(process.cwd(), rootOption)\n : process.cwd()\n const wd = getWorkspaceDir(root)\n const pnpmWorkspaceFilePath = path.resolve(wd, 'pnpm-workspace.yaml')\n const pnpmWorkspaceFileContent = fs.readFileSync(pnpmWorkspaceFilePath, 'utf-8')\n const pnpmWorkspace = load(pnpmWorkspaceFileContent) as {\n packages: string[]\n }\n if (root === wd && !filter) {\n throw new Error('root path is workspace root, please provide a filter')\n // TODO inquirer prompt support user select packages\n }\n if (root !== wd && !filter) {\n const packageJSONIsExist = fs.existsSync(path.resolve(root, 'package.json'))\n if (!packageJSONIsExist) {\n throw new Error('root path is not workspace root, please provide a filter')\n }\n const packageJSON = JSON.parse(fs.readFileSync(path.resolve(root, 'package.json'), 'utf-8'))\n if (!packageJSON.name) {\n throw new Error('root path is not workspace root, please provide a filter')\n }\n filter = packageJSON.name\n }\n const { selectedProjectsGraph } = await filterPackagesFromDir(wd, [{\n filter: filter ?? '',\n followProdDepsOnly: true\n }], {\n prefix: root,\n workspaceDir: wd,\n patterns: pnpmWorkspace.packages\n })\n const jiekTempDir = (...paths: string[]) => path.resolve(wd, 'node_modules/.jiek', ...paths)\n if (!fs.existsSync(jiekTempDir())) fs.mkdirSync(jiekTempDir())\n\n const rollupBinaryPath = require.resolve('rollup')\n .replace(/dist\\/rollup.js$/, 'dist/bin/rollup')\n let i = 0\n for (const [dir, { package: { manifest } }] of Object.entries(selectedProjectsGraph)) {\n const newManifest = mergePackageJson(manifest, dir)\n // TODO support auto build child packages in workspaces\n const escapeManifestName = manifest.name?.replace(/^@/g, '').replace(/\\//g, '+')\n const configFile = jiekTempDir(\n `${escapeManifestName ?? `anonymous-${i++}`}.rollup.config.js`\n )\n fs.writeFileSync(configFile, FILE_TEMPLATE(newManifest))\n let prefix = ''\n if (process.env.NODE_ENV === 'test') {\n const registerPath = require.resolve('esbuild-register')\n const loaderPath = require.resolve('esbuild-register/loader')\n prefix = `node --import ${registerPath} -r ${loaderPath} `\n }\n // TODO replace with `spawn` to support watch mode\n childProcess.execSync(`${prefix}${rollupBinaryPath} -c ${configFile}`, {\n cwd: dir, stdio: 'inherit'\n })\n }\n\n actionDone()\n })\n","import './commands/publish'\nimport './commands/build'\n\nimport { program } from 'commander'\n\nprogram.parse(process.argv)\n"],"names":["resolve","actionDone","actionRestore","Promise","r","mergePackageJson","manifest","cwd","jiek","inputs","jiekInputs","_","exports","Array","isArray","pkger","commander","program","command","aliases","option","action","async","root","rootOption","filter","bumper","options","path","isAbsolute","process","wd","getWorkspaceDir","selectedProjectsGraph","filterPackagesFromDir","followProdDepsOnly","prefix","workspaceDir","patterns","mainfests","Object","entries","forEach","package","dir","push","passArgs","reduce","acc","key","value","m","newVersion","bump","version","newManifest","fs","renameSync","join","writeFileSync","JSON","stringify","console","log","childProcess","execSync","stdio","oldPackageJson","parse","default","readFileSync","unlinkSync","FILE_TEMPLATE","env","NODE_ENV","trimStart","pnpmWorkspaceFilePath","pnpmWorkspaceFileContent","pnpmWorkspace","load","Error","existsSync","packageJSON","name","packages","jiekTempDir","paths","mkdirSync","rollupBinaryPath","require","replace","i","escapeManifestName","configFile","argv"],"mappings":"opCAAA,IAAIA,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3,"file":"index.umd.min.js","sources":["../src/utils/filterSupport.ts","../src/inner.ts","../src/merge-package-json.ts","../src/utils/commondir.ts","../src/commands/publish.ts","../src/commands/build.ts","../src/index.ts"],"sourcesContent":["import fs from 'node:fs'\nimport path from 'node:path'\n\nimport { getWorkspaceDir } from '@jiek/utils/getWorkspaceDir'\nimport { filterPackagesFromDir } from '@pnpm/filter-workspace-packages'\nimport { program } from 'commander'\nimport { load } from 'js-yaml'\n\nexport let type = ''\n\ntry {\n require.resolve('@pnpm/filter-workspace-packages')\n type = 'pnpm'\n} catch { /* empty */ }\nif (type !== '') {\n program\n .option('-f, --filter <filter>', 'filter packages')\n}\n\ninterface ProjectsGraph {\n wd: string\n root: string\n value?: Record<string, {\n name?: string\n }>\n}\n\nexport async function getSelectedProjectsGraph(): Promise<ProjectsGraph> {\n let filter = program.getOptionValue('filter')\n const rootOption = program.getOptionValue('root')\n const root = rootOption\n ? path.isAbsolute(rootOption)\n ? rootOption\n : path.resolve(process.cwd(), rootOption)\n : process.cwd()\n let notWorkspace = false\n let wd: string\n try {\n wd = getWorkspaceDir(root, type)\n } catch (e) {\n // @ts-ignore\n if ('message' in e && e.message === 'workspace root not found') {\n wd = root\n notWorkspace = true\n } else {\n throw e\n }\n }\n if (!notWorkspace && type === 'pnpm') {\n const pnpmWorkspaceFilePath = path.resolve(wd, 'pnpm-workspace.yaml')\n const pnpmWorkspaceFileContent = fs.readFileSync(pnpmWorkspaceFilePath, 'utf-8')\n const pnpmWorkspace = load(pnpmWorkspaceFileContent) as {\n packages: string[]\n }\n if (root === wd && !filter) {\n throw new Error('root path is workspace root, please provide a filter')\n // TODO inquirer prompt support user select packages\n }\n if (root !== wd && !filter) {\n const packageJSONIsExist = fs.existsSync(path.resolve(root, 'package.json'))\n if (!packageJSONIsExist) {\n throw new Error('root path is not workspace root, please provide a filter')\n }\n const packageJSON = JSON.parse(fs.readFileSync(path.resolve(root, 'package.json'), 'utf-8'))\n if (!packageJSON.name) {\n throw new Error('root path is not workspace root, please provide a filter')\n }\n filter = packageJSON.name\n }\n const { selectedProjectsGraph } = await filterPackagesFromDir(wd, [{\n filter: filter ?? '',\n followProdDepsOnly: true\n }], {\n prefix: root,\n workspaceDir: wd,\n patterns: pnpmWorkspace.packages\n })\n return {\n wd, root,\n value: Object.entries(selectedProjectsGraph)\n .reduce((acc, [key, value]) => {\n acc[key] = value.package.manifest\n return acc\n }, {} as NonNullable<ProjectsGraph['value']>)\n }\n }\n return {\n wd, root,\n value: {\n [wd]: JSON.parse(fs.readFileSync(path.resolve(wd, 'package.json'), 'utf-8'))\n }\n }\n}\n","let resolve: () => void\n\nexport let actionFuture: Promise<void>\n\nexport function actionDone() {\n resolve()\n}\n\nexport function actionRestore() {\n actionFuture = new Promise<void>(r => resolve = r)\n}\n","import path from 'node:path'\n\nimport { type Options, pkger } from '@jiek/pkger'\nimport type { Manifest } from '@pnpm/workspace.pkgs-graph'\n\nimport { commondir } from './utils/commondir'\n\nexport function mergePackageJson(manifest: Manifest & {\n jiek?: Options\n exports?: unknown | unknown[]\n}, cwd: string) {\n const {\n jiek: { cwd: _, ...jiek } = {}\n } = manifest\n let { exports } = manifest\n let includeIndex = false\n if (typeof exports === 'string') {\n includeIndex = true\n exports = { '.': exports }\n }\n if (exports === undefined) {\n exports = { '.': './src/index.ts' }\n }\n if (typeof exports === 'object') {\n if (Array.isArray(exports) && exports.length > 0) {\n includeIndex = true\n } else {\n includeIndex = !!(<Record<string, unknown>>exports)['.']\n }\n }\n const inputs = Array.isArray(exports)\n ? exports as string[]\n : Object\n .entries(<Record<string, unknown>>exports)\n .reduce((acc, [key, value]) => {\n if (typeof value === 'string') return key === '.'\n ? [value, ...acc]\n : acc.concat(value)\n if (Array.isArray(value)) return acc.concat(value)\n\n throw new TypeError(`Unexpected value type for key \"${key}\" in exports, expected string, got ${typeof value}`)\n }, [] as string[])\n if (inputs.length === 0)\n throw new Error('No inputs found')\n\n const absoluteInputs = inputs.map(input => path.isAbsolute(input)\n ? input\n : path.resolve(cwd, input)\n )\n let cDir = path.dirname(absoluteInputs[0])\n if (absoluteInputs.length > 1) {\n cDir = commondir(absoluteInputs, cwd)\n }\n const resolvedInputs = absoluteInputs.map(input => {\n return path.relative(cDir, input)\n })\n return {\n ...manifest,\n ...pkger({\n cwd,\n noIndex: !includeIndex,\n source: path.relative(cwd, cDir),\n inputs: resolvedInputs,\n ...jiek\n })\n }\n}\n","import path from 'node:path'\n\nexport function commondir(files: string[], cwd = process.cwd()): string {\n const resolvedFiles = files.map(file => {\n if (path.isAbsolute(file)) return file\n return path.resolve(cwd, file)\n })\n const sep = '/'\n const [first = ''] = resolvedFiles\n const parts = first.split(sep)\n let common = ''\n for (let i = 0; i < parts.length; i++) {\n const segment = parts[i]\n if (resolvedFiles.every(file => file.startsWith(common + segment))) {\n common += segment + sep\n } else {\n break\n }\n }\n return common\n}\n","import fs from 'node:fs'\nimport path from 'node:path'\n\nimport { bump, type BumperType } from '@jiek/utils/bumper'\nimport * as childProcess from 'child_process'\nimport { program } from 'commander'\nimport detectIndent from 'detect-indent'\nimport { applyEdits, modify } from 'jsonc-parser'\n\nimport { actionDone, actionRestore } from '../inner'\nimport { mergePackageJson } from '../merge-package-json'\nimport { getSelectedProjectsGraph } from '../utils/filterSupport'\n\nprogram\n .command('publish')\n .aliases(['pub', 'p'])\n .option('-b, --bumper <bumper>', 'bump version', 'patch')\n .option('-p, --preview', 'preview publish')\n .action(async ({ preview, bumper, ...options }: {\n preview?: boolean\n bumper: BumperType\n }) => {\n actionRestore()\n\n const { value = {} } = await getSelectedProjectsGraph() ?? {}\n const selectedProjectsGraphEntries = Object.entries(value)\n if (selectedProjectsGraphEntries.length === 0) {\n throw new Error('no packages selected')\n }\n const mainfests = selectedProjectsGraphEntries\n .map(([dir, manifest]) => [\n dir, mergePackageJson(manifest, dir)\n ] as const)\n const passArgs = Object\n .entries(options)\n .reduce((acc, [key, value]) => {\n if (value) {\n acc.push(`--${key}`, value as string)\n }\n return acc\n }, [] as string[])\n for (const [dir, manifest] of mainfests) {\n const oldJSONString = fs.readFileSync(path.join(dir, 'package.json'), 'utf-8')\n const oldJSON = JSON.parse(oldJSONString) ?? '0.0.0'\n const newVersion = bump(oldJSON.version, bumper)\n // TODO detectIndent by editorconfig\n const { indent = ' ' } = detectIndent(oldJSONString)\n const formattingOptions = {\n tabSize: indent.length,\n insertSpaces: true\n }\n let newJSONString = oldJSONString\n newJSONString = applyEdits(newJSONString, modify(\n newJSONString, ['version'], newVersion, { formattingOptions }\n ))\n for (const [key, value] of Object.entries(manifest)) {\n if (JSON.stringify(value) === JSON.stringify(oldJSON[key])) continue\n\n newJSONString = applyEdits(newJSONString, modify(\n newJSONString, ['publishConfig', key], value, { formattingOptions }\n ))\n }\n try {\n fs.renameSync(path.join(dir, 'package.json'), path.join(dir, 'package.json.bak'))\n fs.writeFileSync(path.join(dir, 'package.json'), newJSONString)\n console.log(newJSONString)\n if (preview) {\n console.warn('preview mode')\n continue\n }\n childProcess.execSync(['pnpm', 'publish', '--access', 'public', '--no-git-checks', ...passArgs].join(' '), {\n cwd: dir,\n stdio: 'inherit'\n })\n const modifyVersionPackageJSON = applyEdits(oldJSONString, modify(oldJSONString, ['version'], newVersion, {}))\n fs.writeFileSync(path.join(dir, 'package.json.bak'), modifyVersionPackageJSON)\n } finally {\n fs.unlinkSync(path.join(dir, 'package.json'))\n fs.renameSync(path.join(dir, 'package.json.bak'), path.join(dir, 'package.json'))\n }\n }\n actionDone()\n })\n","import * as childProcess from 'node:child_process'\nimport fs from 'node:fs'\nimport path from 'node:path'\n\nimport { program } from 'commander'\n\nimport { actionDone, actionRestore } from '../inner'\nimport { mergePackageJson } from '../merge-package-json'\nimport { getSelectedProjectsGraph } from '../utils/filterSupport'\n\nconst FILE_TEMPLATE = (manifest: unknown) => `\nconst pkg = ${JSON.stringify(manifest, null, 2)}\nconst { jiek = {} } = pkg\nconst templateArg = jiek.templateArgFilePath\n ? require.resolve(jiek.templateArgFilePath)\n : {\n styled: jiek.styled\n }\nmodule.exports = require('jiek/rollup').template(templateArg, pkg)\n`.trimStart()\n\nprogram\n .command('build')\n .action(async () => {\n actionRestore()\n const {\n wd, value = {}\n } = await getSelectedProjectsGraph() ?? {}\n\n if (Object.keys(value).length === 0) {\n throw new Error('no package found')\n }\n const jiekTempDir = (...paths: string[]) => path.resolve(wd, 'node_modules/.jiek', ...paths)\n if (!fs.existsSync(jiekTempDir())) fs.mkdirSync(jiekTempDir())\n\n const rollupBinaryPath = require.resolve('rollup')\n .replace(/dist\\/rollup.js$/, 'dist/bin/rollup')\n let i = 0\n for (const [dir, manifest] of Object.entries(value)) {\n const newManifest = mergePackageJson(manifest, dir)\n // TODO support auto build child packages in workspaces\n const escapeManifestName = manifest.name?.replace(/^@/g, '').replace(/\\//g, '+')\n const configFile = jiekTempDir(\n `${escapeManifestName ?? `anonymous-${i++}`}.rollup.config.js`\n )\n fs.writeFileSync(configFile, FILE_TEMPLATE(newManifest))\n let prefix = ''\n if (process.env.NODE_ENV === 'test') {\n const registerPath = require.resolve('esbuild-register')\n const loaderPath = require.resolve('esbuild-register/loader')\n prefix = `node --import ${registerPath} -r ${loaderPath} `\n }\n // TODO replace with `spawn` to support watch mode\n childProcess.execSync(`${prefix}${rollupBinaryPath} -c ${configFile}`, {\n cwd: dir, stdio: 'inherit'\n })\n }\n\n actionDone()\n })\n","import './utils/filterSupport'\nimport './commands/publish'\nimport './commands/build'\n\nimport { program } from 'commander'\n\n// eslint-disable-next-line @typescript-eslint/no-var-requires\nconst pkg = require('../package.json')\n\nprogram\n .version(pkg.version)\n .description(pkg.description)\n .option('--root <root>', 'root path')\n\nprogram.parse(process.argv)\n"],"names":["resolve","type","require","async","getSelectedProjectsGraph","filter","program","getOptionValue","rootOption","root","path","isAbsolute","process","cwd","wd","notWorkspace","getWorkspaceDir","e","message","pnpmWorkspaceFilePath","default","pnpmWorkspaceFileContent","fs","readFileSync","pnpmWorkspace","load","Error","existsSync","packageJSON","JSON","parse","name","selectedProjectsGraph","filterPackagesFromDir","followProdDepsOnly","prefix","workspaceDir","patterns","packages","value","Object","entries","reduce","acc","key","package","manifest","actionDone","actionRestore","Promise","r","mergePackageJson","jiek","_","exports","includeIndex","Array","isArray","length","inputs","concat","TypeError","absoluteInputs","map","input","cDir","dirname","files","resolvedFiles","file","first","parts","split","common","i","segment","every","startsWith","commondir","resolvedInputs","relative","pkger","noIndex","source","option","command","aliases","action","preview","bumper","options","selectedProjectsGraphEntries","mainfests","dir","passArgs","push","oldJSONString","join","oldJSON","newVersion","bump","version","indent","detectIndent","formattingOptions","tabSize","insertSpaces","newJSONString","applyEdits","modify","stringify","renameSync","writeFileSync","console","log","warn","childProcess","execSync","stdio","modifyVersionPackageJSON","unlinkSync","FILE_TEMPLATE","trimStart","commander","keys","jiekTempDir","paths","mkdirSync","rollupBinaryPath","replace","newManifest","escapeManifestName","configFile","env","NODE_ENV","pkg","description","argv"],"mappings":"4wCAQO,ICRHA,EDQOC,EAAO,GAElB,IACEC,QAAQF,QAAQ,mCACTC,EAAA,MACT,CAAQ,MAAc,CActBE,eAAsBC,IAChB,IAAAC,EAASC,EAAAA,QAAQC,eAAe,UAC9B,MAAAC,EAAaF,EAAAA,QAAQC,eAAe,QACpCE,EAAOD,EACTE,EAAAA,QAAKC,WAAWH,GACdA,EACAE,EAAAA,QAAKV,QAAQY,QAAQC,MAAOL,GAC9BI,QAAQC,MACZ,IACIC,EADAC,GAAe,EAEf,IACGD,EAAAE,EAAAA,gBAAgBP,EAAMR,SACpBgB,GAEP,KAAI,YAAaA,IAAmB,6BAAdA,EAAEC,QAIhB,MAAAD,EAHDH,EAAAL,EACUM,GAAA,CAInB,CACI,IAACA,GAAyB,SAATd,EAAiB,CACpC,MAAMkB,EAAwBT,EAAAU,QAAKpB,QAAQc,EAAI,uBACzCO,EAA2BC,EAAAF,QAAGG,aAAaJ,EAAuB,SAClEK,EAAgBC,OAAKJ,GAGvB,GAAAZ,IAASK,IAAOT,EACZ,MAAA,IAAIqB,MAAM,wDAGd,G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AAzBvB,QAAQyH,IAAIC,SAAqB,CAG1BnG,EAAA,iBAFYjC,QAAQF,QAAQ,0BAClBE,QAAQF,QAAQ,6BAErC,CAEAoH,EAAaC,SAAS,GAAGlF,IAAS6F,QAAuBI,IAAc,CACrEvH,IAAKgF,EAAKyB,MAAO,WAErB,CAEWvE,GAAA,ICnDf,MAAMwF,EAAMrI,QAAQ,mBAGjByH,EAAArH,QAAA+F,QAAQkC,EAAIlC,SACZmC,YAAYD,EAAIC,aAChBpD,OAAO,gBAAiB,aAE3B9E,EAAAA,QAAQwB,MAAMlB,QAAQ6H"}
|
@@ -1,14 +1,55 @@
|
|
1
|
+
import path from 'node:path';
|
1
2
|
import { pkger } from '@jiek/pkger';
|
3
|
+
import { commondir } from './utils/commondir.esm.js';
|
2
4
|
|
3
5
|
function mergePackageJson(manifest, cwd) {
|
4
6
|
const {
|
5
|
-
jiek: {
|
6
|
-
exports
|
7
|
+
jiek: { cwd: _, ...jiek } = {}
|
7
8
|
} = manifest;
|
8
|
-
|
9
|
+
let { exports } = manifest;
|
10
|
+
let includeIndex = false;
|
11
|
+
if (typeof exports === "string") {
|
12
|
+
includeIndex = true;
|
13
|
+
exports = { ".": exports };
|
14
|
+
}
|
15
|
+
if (exports === void 0) {
|
16
|
+
exports = { ".": "./src/index.ts" };
|
17
|
+
}
|
18
|
+
if (typeof exports === "object") {
|
19
|
+
if (Array.isArray(exports) && exports.length > 0) {
|
20
|
+
includeIndex = true;
|
21
|
+
} else {
|
22
|
+
includeIndex = !!exports["."];
|
23
|
+
}
|
24
|
+
}
|
25
|
+
const inputs = Array.isArray(exports) ? exports : Object.entries(exports).reduce((acc, [key, value]) => {
|
26
|
+
if (typeof value === "string")
|
27
|
+
return key === "." ? [value, ...acc] : acc.concat(value);
|
28
|
+
if (Array.isArray(value))
|
29
|
+
return acc.concat(value);
|
30
|
+
throw new TypeError(`Unexpected value type for key "${key}" in exports, expected string, got ${typeof value}`);
|
31
|
+
}, []);
|
32
|
+
if (inputs.length === 0)
|
33
|
+
throw new Error("No inputs found");
|
34
|
+
const absoluteInputs = inputs.map(
|
35
|
+
(input) => path.isAbsolute(input) ? input : path.resolve(cwd, input)
|
36
|
+
);
|
37
|
+
let cDir = path.dirname(absoluteInputs[0]);
|
38
|
+
if (absoluteInputs.length > 1) {
|
39
|
+
cDir = commondir(absoluteInputs, cwd);
|
40
|
+
}
|
41
|
+
const resolvedInputs = absoluteInputs.map((input) => {
|
42
|
+
return path.relative(cDir, input);
|
43
|
+
});
|
9
44
|
return {
|
10
45
|
...manifest,
|
11
|
-
...pkger({
|
46
|
+
...pkger({
|
47
|
+
cwd,
|
48
|
+
noIndex: !includeIndex,
|
49
|
+
source: path.relative(cwd, cDir),
|
50
|
+
inputs: resolvedInputs,
|
51
|
+
...jiek
|
52
|
+
})
|
12
53
|
};
|
13
54
|
}
|
14
55
|
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"merge-package-json.esm.js","sources":["../src/merge-package-json.ts"],"sourcesContent":["import { type Options, pkger } from '@jiek/pkger'\nimport type {
|
1
|
+
{"version":3,"file":"merge-package-json.esm.js","sources":["../src/merge-package-json.ts"],"sourcesContent":["import path from 'node:path'\n\nimport { type Options, pkger } from '@jiek/pkger'\nimport type { Manifest } from '@pnpm/workspace.pkgs-graph'\n\nimport { commondir } from './utils/commondir'\n\nexport function mergePackageJson(manifest: Manifest & {\n jiek?: Options\n exports?: unknown | unknown[]\n}, cwd: string) {\n const {\n jiek: { cwd: _, ...jiek } = {}\n } = manifest\n let { exports } = manifest\n let includeIndex = false\n if (typeof exports === 'string') {\n includeIndex = true\n exports = { '.': exports }\n }\n if (exports === undefined) {\n exports = { '.': './src/index.ts' }\n }\n if (typeof exports === 'object') {\n if (Array.isArray(exports) && exports.length > 0) {\n includeIndex = true\n } else {\n includeIndex = !!(<Record<string, unknown>>exports)['.']\n }\n }\n const inputs = Array.isArray(exports)\n ? exports as string[]\n : Object\n .entries(<Record<string, unknown>>exports)\n .reduce((acc, [key, value]) => {\n if (typeof value === 'string') return key === '.'\n ? [value, ...acc]\n : acc.concat(value)\n if (Array.isArray(value)) return acc.concat(value)\n\n throw new TypeError(`Unexpected value type for key \"${key}\" in exports, expected string, got ${typeof value}`)\n }, [] as string[])\n if (inputs.length === 0)\n throw new Error('No inputs found')\n\n const absoluteInputs = inputs.map(input => path.isAbsolute(input)\n ? input\n : path.resolve(cwd, input)\n )\n let cDir = path.dirname(absoluteInputs[0])\n if (absoluteInputs.length > 1) {\n cDir = commondir(absoluteInputs, cwd)\n }\n const resolvedInputs = absoluteInputs.map(input => {\n return path.relative(cDir, input)\n })\n return {\n ...manifest,\n ...pkger({\n cwd,\n noIndex: !includeIndex,\n source: path.relative(cwd, cDir),\n inputs: resolvedInputs,\n ...jiek\n })\n }\n}\n"],"names":[],"mappings":";;;;AAOgB,SAAA,gBAAA,CAAiB,UAG9B,GAAa,EAAA;AACd,EAAM,MAAA;AAAA,IACJ,MAAM,EAAE,GAAA,EAAK,GAAG,GAAG,IAAA,KAAS,EAAC;AAAA,GAC3B,GAAA,QAAA,CAAA;AACJ,EAAI,IAAA,EAAE,SAAY,GAAA,QAAA,CAAA;AAClB,EAAA,IAAI,YAAe,GAAA,KAAA,CAAA;AACnB,EAAI,IAAA,OAAO,YAAY,QAAU,EAAA;AAC/B,IAAe,YAAA,GAAA,IAAA,CAAA;AACf,IAAU,OAAA,GAAA,EAAE,KAAK,OAAQ,EAAA,CAAA;AAAA,GAC3B;AACA,EAAA,IAAI,YAAY,KAAW,CAAA,EAAA;AACzB,IAAU,OAAA,GAAA,EAAE,KAAK,gBAAiB,EAAA,CAAA;AAAA,GACpC;AACA,EAAI,IAAA,OAAO,YAAY,QAAU,EAAA;AAC/B,IAAA,IAAI,MAAM,OAAQ,CAAA,OAAO,CAAK,IAAA,OAAA,CAAQ,SAAS,CAAG,EAAA;AAChD,MAAe,YAAA,GAAA,IAAA,CAAA;AAAA,KACV,MAAA;AACL,MAAe,YAAA,GAAA,CAAC,CAA2B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