jiek 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- package/bin/jiek-dev.js +4 -0
- package/bin/jiek.js +2 -0
- package/dist/commands/build.esm.js +68 -0
- package/dist/commands/build.esm.js.map +1 -0
- package/dist/commands/build.esm.min.js +2 -0
- package/dist/commands/build.esm.min.js.map +1 -0
- package/dist/commands/publish.esm.js +60 -0
- package/dist/commands/publish.esm.js.map +1 -0
- package/dist/commands/publish.esm.min.js +2 -0
- package/dist/commands/publish.esm.min.js.map +1 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.esm.d.ts +2 -0
- package/dist/index.esm.js +6 -0
- package/dist/index.esm.js.map +1 -0
- package/dist/index.esm.min.js +2 -0
- package/dist/index.esm.min.js.map +1 -0
- package/dist/index.iife.js +155 -0
- package/dist/index.iife.js.map +1 -0
- package/dist/index.iife.min.js +2 -0
- package/dist/index.iife.min.js.map +1 -0
- package/dist/index.umd.js +158 -0
- package/dist/index.umd.js.map +1 -0
- package/dist/index.umd.min.js +2 -0
- package/dist/index.umd.min.js.map +1 -0
- package/dist/inner.esm.js +10 -0
- package/dist/inner.esm.js.map +1 -0
- package/dist/inner.esm.min.js +2 -0
- package/dist/inner.esm.min.js.map +1 -0
- package/dist/merge-package-json.esm.js +16 -0
- package/dist/merge-package-json.esm.js.map +1 -0
- package/dist/merge-package-json.esm.min.js +2 -0
- package/dist/merge-package-json.esm.min.js.map +1 -0
- package/package.json +56 -0
- package/src/commands/build.ts +91 -0
- package/src/commands/publish.ts +79 -0
- package/src/index.ts +6 -0
- package/src/inner.ts +11 -0
- package/src/merge-package-json.ts +19 -0
- package/src/rollup/index.ts +162 -0
- package/src/rollup/plugins/globals.ts +34 -0
- package/src/rollup/plugins/skip.ts +23 -0
- package/src/rollup/utils/commonOptions.ts +9 -0
- package/src/rollup/utils/externalResolver.ts +11 -0
- package/src/rollup/utils/globalResolver.ts +24 -0
- package/src/rollup/utils/withMinify.ts +16 -0
- package/tests/build.spec.ts +28 -0
- package/tests/fixtures/node_modules/.bin/jiek +17 -0
- package/tests/fixtures/node_modules/.jiek/jiek+test-foo.rollup.config.js +31 -0
- package/tests/fixtures/node_modules/.modules.yaml +95 -0
- package/tests/fixtures/node_modules/.pnpm/@esbuild+darwin-arm64@0.20.2/node_modules/@esbuild/darwin-arm64/README.md +3 -0
- package/tests/fixtures/node_modules/.pnpm/@esbuild+darwin-arm64@0.20.2/node_modules/@esbuild/darwin-arm64/bin/esbuild +0 -0
- package/tests/fixtures/node_modules/.pnpm/@esbuild+darwin-arm64@0.20.2/node_modules/@esbuild/darwin-arm64/package.json +20 -0
- package/tests/fixtures/node_modules/.pnpm/@jiek+loader-esbuild@1.0.0_esbuild@0.20.2/node_modules/@jiek/loader-esbuild/LICENSE +21 -0
- package/tests/fixtures/node_modules/.pnpm/@jiek+loader-esbuild@1.0.0_esbuild@0.20.2/node_modules/@jiek/loader-esbuild/loader.js +3 -0
- package/tests/fixtures/node_modules/.pnpm/@jiek+loader-esbuild@1.0.0_esbuild@0.20.2/node_modules/@jiek/loader-esbuild/package.json +8 -0
- package/tests/fixtures/node_modules/.pnpm/debug@4.3.4/node_modules/debug/LICENSE +20 -0
- package/tests/fixtures/node_modules/.pnpm/debug@4.3.4/node_modules/debug/README.md +481 -0
- package/tests/fixtures/node_modules/.pnpm/debug@4.3.4/node_modules/debug/package.json +59 -0
- package/tests/fixtures/node_modules/.pnpm/debug@4.3.4/node_modules/debug/src/browser.js +269 -0
- package/tests/fixtures/node_modules/.pnpm/debug@4.3.4/node_modules/debug/src/common.js +274 -0
- package/tests/fixtures/node_modules/.pnpm/debug@4.3.4/node_modules/debug/src/index.js +10 -0
- package/tests/fixtures/node_modules/.pnpm/debug@4.3.4/node_modules/debug/src/node.js +263 -0
- package/tests/fixtures/node_modules/.pnpm/esbuild-register@3.5.0_esbuild@0.20.2/node_modules/esbuild-register/LICENSE +21 -0
- package/tests/fixtures/node_modules/.pnpm/esbuild-register@3.5.0_esbuild@0.20.2/node_modules/esbuild-register/README.md +50 -0
- package/tests/fixtures/node_modules/.pnpm/esbuild-register@3.5.0_esbuild@0.20.2/node_modules/esbuild-register/dist/loader.d.ts +3 -0
- package/tests/fixtures/node_modules/.pnpm/esbuild-register@3.5.0_esbuild@0.20.2/node_modules/esbuild-register/dist/loader.js +15 -0
- package/tests/fixtures/node_modules/.pnpm/esbuild-register@3.5.0_esbuild@0.20.2/node_modules/esbuild-register/dist/node.d.ts +23 -0
- package/tests/fixtures/node_modules/.pnpm/esbuild-register@3.5.0_esbuild@0.20.2/node_modules/esbuild-register/dist/node.js +4926 -0
- package/tests/fixtures/node_modules/.pnpm/esbuild-register@3.5.0_esbuild@0.20.2/node_modules/esbuild-register/loader.js +1 -0
- package/tests/fixtures/node_modules/.pnpm/esbuild-register@3.5.0_esbuild@0.20.2/node_modules/esbuild-register/node_modules/.bin/esbuild +14 -0
- package/tests/fixtures/node_modules/.pnpm/esbuild-register@3.5.0_esbuild@0.20.2/node_modules/esbuild-register/package.json +46 -0
- package/tests/fixtures/node_modules/.pnpm/esbuild-register@3.5.0_esbuild@0.20.2/node_modules/esbuild-register/register.js +3 -0
- package/tests/fixtures/node_modules/.pnpm/esbuild@0.20.2/node_modules/esbuild/LICENSE.md +21 -0
- package/tests/fixtures/node_modules/.pnpm/esbuild@0.20.2/node_modules/esbuild/README.md +3 -0
- package/tests/fixtures/node_modules/.pnpm/esbuild@0.20.2/node_modules/esbuild/bin/esbuild +0 -0
- package/tests/fixtures/node_modules/.pnpm/esbuild@0.20.2/node_modules/esbuild/install.js +288 -0
- package/tests/fixtures/node_modules/.pnpm/esbuild@0.20.2/node_modules/esbuild/lib/main.d.ts +703 -0
- package/tests/fixtures/node_modules/.pnpm/esbuild@0.20.2/node_modules/esbuild/lib/main.js +2436 -0
- package/tests/fixtures/node_modules/.pnpm/esbuild@0.20.2/node_modules/esbuild/node_modules/.bin/esbuild +14 -0
- package/tests/fixtures/node_modules/.pnpm/esbuild@0.20.2/node_modules/esbuild/package.json +46 -0
- package/tests/fixtures/node_modules/.pnpm/lock.yaml +291 -0
- package/tests/fixtures/node_modules/.pnpm/ms@2.1.2/node_modules/ms/index.js +162 -0
- package/tests/fixtures/node_modules/.pnpm/ms@2.1.2/node_modules/ms/license.md +21 -0
- package/tests/fixtures/node_modules/.pnpm/ms@2.1.2/node_modules/ms/package.json +37 -0
- package/tests/fixtures/node_modules/.pnpm/ms@2.1.2/node_modules/ms/readme.md +60 -0
- package/tests/fixtures/node_modules/.pnpm/node_modules/.bin/esbuild +14 -0
- package/tests/fixtures/package.json +8 -0
- package/tests/fixtures/packages/bar/package.json +4 -0
- package/tests/fixtures/packages/foo/dist/index.d.ts +3 -0
- package/tests/fixtures/packages/foo/dist/index.esm.d.ts +3 -0
- package/tests/fixtures/packages/foo/dist/index.esm.js +6 -0
- package/tests/fixtures/packages/foo/dist/index.esm.js.map +1 -0
- package/tests/fixtures/packages/foo/dist/index.esm.min.js +2 -0
- package/tests/fixtures/packages/foo/dist/index.esm.min.js.map +1 -0
- package/tests/fixtures/packages/foo/dist/index.iife.js +15 -0
- package/tests/fixtures/packages/foo/dist/index.iife.js.map +1 -0
- package/tests/fixtures/packages/foo/dist/index.iife.min.js +2 -0
- package/tests/fixtures/packages/foo/dist/index.iife.min.js.map +1 -0
- package/tests/fixtures/packages/foo/dist/index.umd.js +16 -0
- package/tests/fixtures/packages/foo/dist/index.umd.js.map +1 -0
- package/tests/fixtures/packages/foo/dist/index.umd.min.js +2 -0
- package/tests/fixtures/packages/foo/dist/index.umd.min.js.map +1 -0
- package/tests/fixtures/packages/foo/package.json +7 -0
- package/tests/fixtures/packages/foo/src/index.ts +3 -0
- package/tests/fixtures/pnpm-workspace.yaml +2 -0
- package/tests/publish.spec.ts +31 -0
@@ -0,0 +1,158 @@
|
|
1
|
+
(function (global, factory) {
|
2
|
+
typeof exports === 'object' && typeof module !== 'undefined' ? factory(require('node:fs'), require('node:path'), require('@jiek/utils/bumper'), require('@jiek/utils/getWorkspaceDir'), require('@pnpm/filter-workspace-packages'), require('child_process'), require('commander'), require('@jiek/pkger'), require('node:child_process'), require('js-yaml')) :
|
3
|
+
typeof define === 'function' && define.amd ? define(['node:fs', 'node:path', '@jiek/utils/bumper', '@jiek/utils/getWorkspaceDir', '@pnpm/filter-workspace-packages', 'child_process', 'commander', '@jiek/pkger', 'node:child_process', 'js-yaml'], factory) :
|
4
|
+
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.fs, global.path, global.bumper, global.getWorkspaceDir, global.filterWorkspacePackages, global.childProcess, global.commander, global.pkger, global.childProcess$1, global.jsYaml));
|
5
|
+
})(this, (function (fs, path, bumper, getWorkspaceDir, filterWorkspacePackages, childProcess, commander, pkger, childProcess$1, jsYaml) { 'use strict';
|
6
|
+
|
7
|
+
function _interopNamespaceDefault(e) {
|
8
|
+
var n = Object.create(null);
|
9
|
+
if (e) {
|
10
|
+
Object.keys(e).forEach(function (k) {
|
11
|
+
if (k !== 'default') {
|
12
|
+
var d = Object.getOwnPropertyDescriptor(e, k);
|
13
|
+
Object.defineProperty(n, k, d.get ? d : {
|
14
|
+
enumerable: true,
|
15
|
+
get: function () { return e[k]; }
|
16
|
+
});
|
17
|
+
}
|
18
|
+
});
|
19
|
+
}
|
20
|
+
n.default = e;
|
21
|
+
return Object.freeze(n);
|
22
|
+
}
|
23
|
+
|
24
|
+
var childProcess__namespace = /*#__PURE__*/_interopNamespaceDefault(childProcess);
|
25
|
+
var childProcess__namespace$1 = /*#__PURE__*/_interopNamespaceDefault(childProcess$1);
|
26
|
+
|
27
|
+
let resolve;
|
28
|
+
function actionDone() {
|
29
|
+
resolve();
|
30
|
+
}
|
31
|
+
function actionRestore() {
|
32
|
+
new Promise((r) => resolve = r);
|
33
|
+
}
|
34
|
+
|
35
|
+
function mergePackageJson(manifest, cwd) {
|
36
|
+
const {
|
37
|
+
jiek: { inputs: jiekInputs, cwd: _, ...jiek } = {},
|
38
|
+
exports
|
39
|
+
} = manifest;
|
40
|
+
const inputs = jiekInputs ?? (Array.isArray(exports) ? exports : void 0);
|
41
|
+
return {
|
42
|
+
...manifest,
|
43
|
+
...pkger.pkger({ inputs, cwd, ...jiek })
|
44
|
+
};
|
45
|
+
}
|
46
|
+
|
47
|
+
commander.program.command("publish").aliases(["pub", "p"]).option("--filter <filter>", "filter packages").option("--root <root>", "root path").option("--bumper <bumper>", "bump version", "patch").action(async ({ root: rootOption, filter, bumper: bumper$1, ...options }) => {
|
48
|
+
actionRestore();
|
49
|
+
const root = rootOption ? path.isAbsolute(rootOption) ? rootOption : path.resolve(process.cwd(), rootOption) : process.cwd();
|
50
|
+
const wd = getWorkspaceDir.getWorkspaceDir(root);
|
51
|
+
const { selectedProjectsGraph } = await filterWorkspacePackages.filterPackagesFromDir(wd, [{
|
52
|
+
filter: filter ?? "",
|
53
|
+
followProdDepsOnly: true
|
54
|
+
}], {
|
55
|
+
prefix: root,
|
56
|
+
workspaceDir: wd,
|
57
|
+
patterns: ["packages/*"]
|
58
|
+
});
|
59
|
+
const mainfests = [];
|
60
|
+
Object.entries(selectedProjectsGraph).forEach(([, { package: { dir, manifest } }]) => {
|
61
|
+
mainfests.push([
|
62
|
+
dir,
|
63
|
+
mergePackageJson(manifest, dir)
|
64
|
+
]);
|
65
|
+
});
|
66
|
+
const passArgs = Object.entries(options).reduce((acc, [key, value]) => {
|
67
|
+
if (value) {
|
68
|
+
acc.push(`--${key}`, value);
|
69
|
+
}
|
70
|
+
return acc;
|
71
|
+
}, []);
|
72
|
+
for (const [dir, m] of mainfests) {
|
73
|
+
const newVersion = bumper.bump(m.version, bumper$1);
|
74
|
+
const newManifest = {
|
75
|
+
...m,
|
76
|
+
version: newVersion
|
77
|
+
};
|
78
|
+
fs.renameSync(path.join(dir, "package.json"), path.join(dir, "package.json.bak"));
|
79
|
+
fs.writeFileSync(path.join(dir, "package.json"), JSON.stringify(newManifest, null, 2));
|
80
|
+
console.log(newManifest);
|
81
|
+
try {
|
82
|
+
childProcess__namespace.execSync(["pnpm", "publish", "--access", "public", "--no-git-checks", ...passArgs].join(" "), {
|
83
|
+
cwd: dir,
|
84
|
+
stdio: "inherit"
|
85
|
+
});
|
86
|
+
const oldPackageJson = JSON.parse(fs.readFileSync(path.join(dir, "package.json.bak"), "utf-8"));
|
87
|
+
oldPackageJson.version = newVersion;
|
88
|
+
fs.writeFileSync(path.join(dir, "package.json.bak"), JSON.stringify(oldPackageJson, null, 2));
|
89
|
+
} finally {
|
90
|
+
fs.unlinkSync(path.join(dir, "package.json"));
|
91
|
+
fs.renameSync(path.join(dir, "package.json.bak"), path.join(dir, "package.json"));
|
92
|
+
}
|
93
|
+
}
|
94
|
+
actionDone();
|
95
|
+
});
|
96
|
+
|
97
|
+
const FILE_TEMPLATE = (manifest) => `
|
98
|
+
module.exports = require('${process.env.NODE_ENV === "test" ? "jiek/src/rollup/index.ts" : "jiek/rollup"}').template({ }, ${JSON.stringify(manifest, null, 2)})
|
99
|
+
`.trimStart();
|
100
|
+
commander.program.command("build").option("--filter <filter>", "filter packages").option("--root <root>", "root path").action(async ({ root: rootOption, filter, ...options }) => {
|
101
|
+
actionRestore();
|
102
|
+
const root = rootOption ? path.isAbsolute(rootOption) ? rootOption : path.resolve(process.cwd(), rootOption) : process.cwd();
|
103
|
+
const wd = getWorkspaceDir.getWorkspaceDir(root);
|
104
|
+
const pnpmWorkspaceFilePath = path.resolve(wd, "pnpm-workspace.yaml");
|
105
|
+
const pnpmWorkspaceFileContent = fs.readFileSync(pnpmWorkspaceFilePath, "utf-8");
|
106
|
+
const pnpmWorkspace = jsYaml.load(pnpmWorkspaceFileContent);
|
107
|
+
if (root === wd && !filter) {
|
108
|
+
throw new Error("root path is workspace root, please provide a filter");
|
109
|
+
}
|
110
|
+
if (root !== wd && !filter) {
|
111
|
+
const packageJSONIsExist = fs.existsSync(path.resolve(root, "package.json"));
|
112
|
+
if (!packageJSONIsExist) {
|
113
|
+
throw new Error("root path is not workspace root, please provide a filter");
|
114
|
+
}
|
115
|
+
const packageJSON = JSON.parse(fs.readFileSync(path.resolve(root, "package.json"), "utf-8"));
|
116
|
+
if (!packageJSON.name) {
|
117
|
+
throw new Error("root path is not workspace root, please provide a filter");
|
118
|
+
}
|
119
|
+
filter = packageJSON.name;
|
120
|
+
}
|
121
|
+
const { selectedProjectsGraph } = await filterWorkspacePackages.filterPackagesFromDir(wd, [{
|
122
|
+
filter: filter ?? "",
|
123
|
+
followProdDepsOnly: true
|
124
|
+
}], {
|
125
|
+
prefix: root,
|
126
|
+
workspaceDir: wd,
|
127
|
+
patterns: pnpmWorkspace.packages
|
128
|
+
});
|
129
|
+
const jiekTempDir = (...paths) => path.resolve(wd, "node_modules/.jiek", ...paths);
|
130
|
+
if (!fs.existsSync(jiekTempDir()))
|
131
|
+
fs.mkdirSync(jiekTempDir());
|
132
|
+
const rollupBinaryPath = require.resolve("rollup").replace(/dist\/rollup.js$/, "dist/bin/rollup");
|
133
|
+
let i = 0;
|
134
|
+
for (const [dir, { package: { manifest } }] of Object.entries(selectedProjectsGraph)) {
|
135
|
+
const newManifest = mergePackageJson(manifest, dir);
|
136
|
+
const escapeManifestName = manifest.name?.replace(/^@/g, "").replace(/\//g, "+");
|
137
|
+
const configFile = jiekTempDir(
|
138
|
+
`${escapeManifestName ?? `anonymous-${i++}`}.rollup.config.js`
|
139
|
+
);
|
140
|
+
fs.writeFileSync(configFile, FILE_TEMPLATE(newManifest));
|
141
|
+
let prefix = "";
|
142
|
+
if (process.env.NODE_ENV === "test") {
|
143
|
+
const registerPath = require.resolve("esbuild-register");
|
144
|
+
const loaderPath = require.resolve("esbuild-register/loader");
|
145
|
+
prefix = `node --import ${registerPath} -r ${loaderPath} `;
|
146
|
+
}
|
147
|
+
childProcess__namespace$1.execSync(`${prefix}${rollupBinaryPath} -c ${configFile}`, {
|
148
|
+
cwd: dir,
|
149
|
+
stdio: "inherit"
|
150
|
+
});
|
151
|
+
}
|
152
|
+
actionDone();
|
153
|
+
});
|
154
|
+
|
155
|
+
commander.program.parse(process.argv);
|
156
|
+
|
157
|
+
}));
|
158
|
+
//# sourceMappingURL=index.umd.js.map
|
@@ -0,0 +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) => `\nmodule.exports = require('${\n process.env.NODE_ENV === 'test'\n ? 'jiek/src/rollup/index.ts'\n : 'jiek/rollup'\n}').template({ }, ${JSON.stringify(manifest, null, 2)})\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","getWorkspaceDir","filterPackagesFromDir","bump","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,EAAA;EACd,EAAM,MAAA;EAAA,IACJ,IAAA,EAAM,EAAE,MAAQ,EAAA,UAAA,EAAY,KAAK,CAAG,EAAA,GAAG,IAAK,EAAA,GAAI,EAAC;EAAA,IAAG,OAAA;EAAA,GAClD,GAAA,QAAA,CAAA;EACJ,EAAA,MAAM,SAAS,UACb,KAAA,KAAA,CAAM,OAAQ,CAAA,OAAO,IAAI,OAAU,GAAA,KAAA,CAAA,CAAA,CAAA;EAErC,EAAO,OAAA;EAAA,IACL,GAAG,QAAA;EAAA,IACH,GAAGA,WAAM,CAAA,EAAE,QAAQ,GAAK,EAAA,GAAG,MAAM,CAAA;EAAA,GACnC,CAAA;EACF;;ACLAC,mBAAA,CACG,OAAQ,CAAA,SAAS,CACjB,CAAA,OAAA,CAAQ,CAAC,KAAA,EAAO,GAAG,CAAC,CACpB,CAAA,MAAA,CAAO,mBAAqB,EAAA,iBAAiB,EAC7C,MAAO,CAAA,eAAA,EAAiB,WAAW,CAAA,CACnC,MA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,OAAA,CAAQ,yBAAyB,CAAA,CAAA;EAC5D,MAAS,MAAA,GAAA,CAAA,cAAA,EAAiB,YAAY,CAAA,IAAA,EAAO,UAAU,CAAA,CAAA,CAAA,CAAA;EAAA,KACzD;EAEA,IAAAE,yBAAA,CAAa,SAAS,CAAG,EAAA,MAAM,GAAG,gBAAgB,CAAA,IAAA,EAAO,UAAU,CAAI,CAAA,EAAA;EAAA,MACrE,GAAK,EAAA,GAAA;EAAA,MAAK,KAAO,EAAA,SAAA;EAAA,KAClB,CAAA,CAAA;EAAA,GACH;EAEA,EAAW,UAAA,EAAA,CAAA;EACb,CAAC,CAAA;;ACrFHL,mBAAQ,CAAA,KAAA,CAAM,QAAQ,IAAI,CAAA;;;;;;"}
|
@@ -0,0 +1,2 @@
|
|
1
|
+
!function(e,r){"object"==typeof exports&&"undefined"!=typeof module?r(require("node:fs"),require("node:path"),require("@jiek/utils/bumper"),require("@jiek/utils/getWorkspaceDir"),require("@pnpm/filter-workspace-packages"),require("child_process"),require("commander"),require("@jiek/pkger"),require("node:child_process"),require("js-yaml")):"function"==typeof define&&define.amd?define(["node:fs","node:path","@jiek/utils/bumper","@jiek/utils/getWorkspaceDir","@pnpm/filter-workspace-packages","child_process","commander","@jiek/pkger","node:child_process","js-yaml"],r):r((e="undefined"!=typeof globalThis?globalThis:e||self).fs,e.path,e.bumper,e.getWorkspaceDir,e.filterWorkspacePackages,e.childProcess,e.commander,e.pkger,e.childProcess$1,e.jsYaml)}(this,(function(e,r,o,i,s,t,n,c,a,p){"use strict";function l(e){var r=Object.create(null);return e&&Object.keys(e).forEach((function(o){if("default"!==o){var i=Object.getOwnPropertyDescriptor(e,o);Object.defineProperty(r,o,i.get?i:{enumerable:!0,get:function(){return e[o]}})}})),r.default=e,Object.freeze(r)}var u=l(t),f=l(a);let d;function k(){d()}function g(){new Promise((e=>d=e))}function m(e,r){const{jiek:{inputs:o,cwd:i,...s}={},exports:t}=e,n=o??(Array.isArray(t)?t:void 0);return{...e,...c.pkger({inputs:n,cwd:r,...s})}}n.program.command("publish").aliases(["pub","p"]).option("--filter <filter>","filter packages").option("--root <root>","root path").option("--bumper <bumper>","bump version","patch").action((async({root:t,filter:n,bumper:c,...a})=>{g();const p=t?r.isAbsolute(t)?t:r.resolve(process.cwd(),t):process.cwd(),l=i.getWorkspaceDir(p),{selectedProjectsGraph:f}=await s.filterPackagesFromDir(l,[{filter:n??"",followProdDepsOnly:!0}],{prefix:p,workspaceDir:l,patterns:["packages/*"]}),d=[];Object.entries(f).forEach((([,{package:{dir:e,manifest:r}}])=>{d.push([e,m(r,e)])}));const j=Object.entries(a).reduce(((e,[r,o])=>(o&&e.push(`--${r}`,o),e)),[]);for(const[i,s]of d){const t=o.bump(s.version,c),n={...s,version:t};e.renameSync(r.join(i,"package.json"),r.join(i,"package.json.bak")),e.writeFileSync(r.join(i,"package.json"),JSON.stringify(n,null,2)),console.log(n);try{u.execSync(["pnpm","publish","--access","public","--no-git-checks",...j].join(" "),{cwd:i,stdio:"inherit"});const o=JSON.parse(e.readFileSync(r.join(i,"package.json.bak"),"utf-8"));o.version=t,e.writeFileSync(r.join(i,"package.json.bak"),JSON.stringify(o,null,2))}finally{e.unlinkSync(r.join(i,"package.json")),e.renameSync(r.join(i,"package.json.bak"),r.join(i,"package.json"))}}k()}));const j=e=>`\nmodule.exports = require('${"test"===process.env.NODE_ENV?"jiek/src/rollup/index.ts":"jiek/rollup"}').template({ }, ${JSON.stringify(e,null,2)})\n`.trimStart();n.program.command("build").option("--filter <filter>","filter packages").option("--root <root>","root path").action((async({root:o,filter:t,...n})=>{g();const c=o?r.isAbsolute(o)?o:r.resolve(process.cwd(),o):process.cwd(),a=i.getWorkspaceDir(c),l=r.resolve(a,"pnpm-workspace.yaml"),u=e.readFileSync(l,"utf-8"),d=p.load(u);if(c===a&&!t)throw new Error("root path is workspace root, please provide a filter");if(c!==a&&!t){if(!e.existsSync(r.resolve(c,"package.json")))throw new Error("root path is not workspace root, please provide a filter");const o=JSON.parse(e.readFileSync(r.resolve(c,"package.json"),"utf-8"));if(!o.name)throw new Error("root path is not workspace root, please provide a filter");t=o.name}const{selectedProjectsGraph:y}=await s.filterPackagesFromDir(a,[{filter:t??"",followProdDepsOnly:!0}],{prefix:c,workspaceDir:a,patterns:d.packages}),b=(...e)=>r.resolve(a,"node_modules/.jiek",...e);e.existsSync(b())||e.mkdirSync(b());const h=require.resolve("rollup").replace(/dist\/rollup.js$/,"dist/bin/rollup");let w=0;for(const[r,{package:{manifest:o}}]of Object.entries(y)){const i=m(o,r),s=o.name?.replace(/^@/g,"").replace(/\//g,"+"),t=b(`${s??"anonymous-"+w++}.rollup.config.js`);e.writeFileSync(t,j(i));let n="";if("test"===process.env.NODE_ENV){n=`node --import ${require.resolve("esbuild-register")} -r ${require.resolve("esbuild-register/loader")} `}f.execSync(`${n}${h} -c ${t}`,{cwd:r,stdio:"inherit"})}k()})),n.program.parse(process.argv)}));
|
2
|
+
//# sourceMappingURL=index.umd.min.js.map
|
@@ -0,0 +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) => `\nmodule.exports = require('${\n process.env.NODE_ENV === 'test'\n ? 'jiek/src/rollup/index.ts'\n : 'jiek/rollup'\n}').template({ }, ${JSON.stringify(manifest, null, 2)})\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","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":"ujCAAA,IAAIA,EAIG,SAASC,IACND,GACV,CAEO,SAASE,IACC,IAAIC,SAAmBC,GAAAJ,EAAUI,GAClD,CCNgB,SAAAC,EAAiBC,EAG9BC,GACK,MACJC,MAAQC,OAAQC,EAAYH,IAAKI,KAAMH,GAAS,CAAC,EAAAI,QAAGA,GAClDN,EACEG,EAASC,IACbG,MAAMC,QAAQF,GAAWA,OAAU,GAE9B,MAAA,IACFN,KACAS,EAAMA,MAAA,CAAEN,SAAQF,SAAQC,IAE/B,CCLAQ,EAAAC,QACGC,QAAQ,WACRC,QAAQ,CAAC,MAAO,MAChBC,OAAO,oBAAqB,mBAC5BA,OAAO,gBAAiB,aACxBA,OAAO,oBAAqB,eAAgB,SAC5CC,QAAOC,OAASC,KAAMC,EAAYC,SAAQC,OAAAA,KAAWC,MAKtCzB,IACd,MAAMqB,EAAOC,EACTI,EAAKC,WAAWL,GACdA,EACAI,EAAK5B,QAAQ8B,QAAQvB,MAAOiB,GAC9BM,QAAQvB,MACNwB,EAAKC,kBAAgBT,IACrBU,sBAAEA,SAAgCC,EAAAA,sBAAsBH,EAAI,CAAC,CACjEN,OAAQA,GAAU,GAClBU,oBAAoB,IAClB,CACFC,OAAQb,EACRc,aAAcN,EACdO,SAAU,CAAC,gBAEPC,EAA0C,GAChDC,OACGC,QAAQR,GACRS,SAAQ,IAAMC,SAAWC,MAAKtC,iBAC7BiC,EAAUM,KAAK,CACbD,EAAKvC,EAAiBC,EAAUsC,IACjC,IAEC,MAAAE,EAAWN,OACdC,QAAQd,GACRoB,QAAO,CAACC,GAAMC,EAAKC,MACdA,GACFF,EAAIH,KAAK,KAAKI,IAAOC,GAEhBF,IACN,IACL,IAAA,MAAYJ,EAAKO,KAAMZ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,0 +1 @@
|
|
1
|
+
{"version":3,"file":"inner.esm.js","sources":["../src/inner.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"],"names":[],"mappings":"AAAA,IAAI,OAAA,CAAA;AAIG,SAAS,UAAa,GAAA;AAC3B,EAAQ,OAAA,EAAA,CAAA;AACV,CAAA;AAEO,SAAS,aAAgB,GAAA;AAC9B,EAAe,IAAI,OAAA,CAAc,CAAK,CAAA,KAAA,OAAA,GAAU,CAAC,CAAA,CAAA;AACnD;;;;"}
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"inner.esm.min.js","sources":["../src/inner.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"],"names":["resolve","actionDone","actionRestore","Promise","r"],"mappings":"AAAA,IAAIA,EAIG,SAASC,IACND,GACV,CAEO,SAASE,IACC,IAAIC,SAAmBC,GAAAJ,EAAUI,GAClD"}
|
@@ -0,0 +1,16 @@
|
|
1
|
+
import { pkger } from '@jiek/pkger';
|
2
|
+
|
3
|
+
function mergePackageJson(manifest, cwd) {
|
4
|
+
const {
|
5
|
+
jiek: { inputs: jiekInputs, cwd: _, ...jiek } = {},
|
6
|
+
exports
|
7
|
+
} = manifest;
|
8
|
+
const inputs = jiekInputs ?? (Array.isArray(exports) ? exports : void 0);
|
9
|
+
return {
|
10
|
+
...manifest,
|
11
|
+
...pkger({ inputs, cwd, ...jiek })
|
12
|
+
};
|
13
|
+
}
|
14
|
+
|
15
|
+
export { mergePackageJson };
|
16
|
+
//# sourceMappingURL=merge-package-json.esm.js.map
|
@@ -0,0 +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 { 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"],"names":[],"mappings":";;AAIgB,SAAA,gBAAA,CAAiB,UAG9B,GAAa,EAAA;AACd,EAAM,MAAA;AAAA,IACJ,IAAA,EAAM,EAAE,MAAQ,EAAA,UAAA,EAAY,KAAK,CAAG,EAAA,GAAG,IAAK,EAAA,GAAI,EAAC;AAAA,IAAG,OAAA;AAAA,GAClD,GAAA,QAAA,CAAA;AACJ,EAAA,MAAM,SAAS,UACb,KAAA,KAAA,CAAM,OAAQ,CAAA,OAAO,IAAI,OAAU,GAAA,KAAA,CAAA,CAAA,CAAA;AAErC,EAAO,OAAA;AAAA,IACL,GAAG,QAAA;AAAA,IACH,GAAG,KAAM,CAAA,EAAE,QAAQ,GAAK,EAAA,GAAG,MAAM,CAAA;AAAA,GACnC,CAAA;AACF;;;;"}
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"merge-package-json.esm.min.js","sources":["../src/merge-package-json.ts"],"sourcesContent":["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"],"names":["mergePackageJson","manifest","cwd","jiek","inputs","jiekInputs","_","exports","Array","isArray","pkger"],"mappings":"oCAIgB,SAAAA,EAAiBC,EAG9BC,GACK,MACJC,MAAQC,OAAQC,EAAYH,IAAKI,KAAMH,GAAS,CAAC,EAAAI,QAAGA,GAClDN,EACEG,EAASC,IACbG,MAAMC,QAAQF,GAAWA,OAAU,GAE9B,MAAA,IACFN,KACAS,EAAM,CAAEN,SAAQF,SAAQC,IAE/B"}
|
package/package.json
ADDED
@@ -0,0 +1,56 @@
|
|
1
|
+
{
|
2
|
+
"name": "jiek",
|
3
|
+
"version": "0.1.1",
|
4
|
+
"description": "YiJie's personal kits.",
|
5
|
+
"bin": {
|
6
|
+
"jiek": "bin/jiek.js",
|
7
|
+
"jiek-dev": "bin/jiek-dev.js"
|
8
|
+
},
|
9
|
+
"dependencies": {
|
10
|
+
"@pnpm/filter-workspace-packages": "^7.2.13",
|
11
|
+
"@rollup/plugin-json": "^6.0.1",
|
12
|
+
"@rollup/plugin-terser": "^0.4.4",
|
13
|
+
"autoprefixer": "^10.4.16",
|
14
|
+
"commander": "^12.0.0",
|
15
|
+
"js-yaml": "^4.1.0",
|
16
|
+
"rollup": "^4.1.5",
|
17
|
+
"rollup-plugin-copy": "^3.5.0",
|
18
|
+
"rollup-plugin-dts": "^6.1.0",
|
19
|
+
"rollup-plugin-esbuild": "^6.1.0",
|
20
|
+
"rollup-plugin-postcss": "^4.0.2",
|
21
|
+
"@jiek/pkger": "0.1.2",
|
22
|
+
"@jiek/utils": "0.1.3"
|
23
|
+
},
|
24
|
+
"devDependencies": {
|
25
|
+
"@npm/types": "^1.0.2",
|
26
|
+
"@pnpm/workspace.pkgs-graph": "^2.0.15",
|
27
|
+
"@types/js-yaml": "^4.0.9",
|
28
|
+
"esbuild-register": "^3.5.0"
|
29
|
+
},
|
30
|
+
"types": "dist/index.d.ts",
|
31
|
+
"main": "dist/index.umd.js",
|
32
|
+
"module": "dist/index.esm.js",
|
33
|
+
"unpkg": "dist/index.umd.min.js",
|
34
|
+
"jsdelivr": "dist/index.umd.min.js",
|
35
|
+
"browser": "dist/index.umd.min.js",
|
36
|
+
"typesVersions": {
|
37
|
+
"<5.0": [
|
38
|
+
"*",
|
39
|
+
"dist/*",
|
40
|
+
"dist/*/index.esm.d.ts"
|
41
|
+
]
|
42
|
+
},
|
43
|
+
"exports": {
|
44
|
+
"./package.json": "./package.json",
|
45
|
+
".": {
|
46
|
+
"types": "dist/index.d.ts",
|
47
|
+
"import": "dist/index.esm.js",
|
48
|
+
"default": "dist/index.esm.js",
|
49
|
+
"require": "dist/index.umd.js",
|
50
|
+
"inner-src": "src/index.ts"
|
51
|
+
}
|
52
|
+
},
|
53
|
+
"scripts": {
|
54
|
+
"build": "jiek-dev build"
|
55
|
+
}
|
56
|
+
}
|
@@ -0,0 +1,91 @@
|
|
1
|
+
import * as childProcess from 'node:child_process'
|
2
|
+
import fs from 'node:fs'
|
3
|
+
import path from 'node:path'
|
4
|
+
|
5
|
+
import { getWorkspaceDir } from '@jiek/utils/getWorkspaceDir'
|
6
|
+
import { filterPackagesFromDir } from '@pnpm/filter-workspace-packages'
|
7
|
+
import { program } from 'commander'
|
8
|
+
import { load } from 'js-yaml'
|
9
|
+
|
10
|
+
import { actionDone, actionRestore } from '../inner'
|
11
|
+
import { mergePackageJson } from '../merge-package-json'
|
12
|
+
|
13
|
+
const FILE_TEMPLATE = (manifest: unknown) => `
|
14
|
+
module.exports = require('${
|
15
|
+
process.env.NODE_ENV === 'test'
|
16
|
+
? 'jiek/src/rollup/index.ts'
|
17
|
+
: 'jiek/rollup'
|
18
|
+
}').template({ }, ${JSON.stringify(manifest, null, 2)})
|
19
|
+
`.trimStart()
|
20
|
+
|
21
|
+
program
|
22
|
+
.command('build')
|
23
|
+
.option('--filter <filter>', 'filter packages')
|
24
|
+
.option('--root <root>', 'root path')
|
25
|
+
.action(async ({ root: rootOption, filter, ...options }: {
|
26
|
+
root?: string
|
27
|
+
filter?: string
|
28
|
+
}) => {
|
29
|
+
actionRestore()
|
30
|
+
const root = rootOption
|
31
|
+
? path.isAbsolute(rootOption)
|
32
|
+
? rootOption
|
33
|
+
: path.resolve(process.cwd(), rootOption)
|
34
|
+
: process.cwd()
|
35
|
+
const wd = getWorkspaceDir(root)
|
36
|
+
const pnpmWorkspaceFilePath = path.resolve(wd, 'pnpm-workspace.yaml')
|
37
|
+
const pnpmWorkspaceFileContent = fs.readFileSync(pnpmWorkspaceFilePath, 'utf-8')
|
38
|
+
const pnpmWorkspace = load(pnpmWorkspaceFileContent) as {
|
39
|
+
packages: string[]
|
40
|
+
}
|
41
|
+
if (root === wd && !filter) {
|
42
|
+
throw new Error('root path is workspace root, please provide a filter')
|
43
|
+
// TODO inquirer prompt support user select packages
|
44
|
+
}
|
45
|
+
if (root !== wd && !filter) {
|
46
|
+
const packageJSONIsExist = fs.existsSync(path.resolve(root, 'package.json'))
|
47
|
+
if (!packageJSONIsExist) {
|
48
|
+
throw new Error('root path is not workspace root, please provide a filter')
|
49
|
+
}
|
50
|
+
const packageJSON = JSON.parse(fs.readFileSync(path.resolve(root, 'package.json'), 'utf-8'))
|
51
|
+
if (!packageJSON.name) {
|
52
|
+
throw new Error('root path is not workspace root, please provide a filter')
|
53
|
+
}
|
54
|
+
filter = packageJSON.name
|
55
|
+
}
|
56
|
+
const { selectedProjectsGraph } = await filterPackagesFromDir(wd, [{
|
57
|
+
filter: filter ?? '',
|
58
|
+
followProdDepsOnly: true
|
59
|
+
}], {
|
60
|
+
prefix: root,
|
61
|
+
workspaceDir: wd,
|
62
|
+
patterns: pnpmWorkspace.packages
|
63
|
+
})
|
64
|
+
const jiekTempDir = (...paths: string[]) => path.resolve(wd, 'node_modules/.jiek', ...paths)
|
65
|
+
if (!fs.existsSync(jiekTempDir())) fs.mkdirSync(jiekTempDir())
|
66
|
+
|
67
|
+
const rollupBinaryPath = require.resolve('rollup')
|
68
|
+
.replace(/dist\/rollup.js$/, 'dist/bin/rollup')
|
69
|
+
let i = 0
|
70
|
+
for (const [dir, { package: { manifest } }] of Object.entries(selectedProjectsGraph)) {
|
71
|
+
const newManifest = mergePackageJson(manifest, dir)
|
72
|
+
// TODO support auto build child packages in workspaces
|
73
|
+
const escapeManifestName = manifest.name?.replace(/^@/g, '').replace(/\//g, '+')
|
74
|
+
const configFile = jiekTempDir(
|
75
|
+
`${escapeManifestName ?? `anonymous-${i++}`}.rollup.config.js`
|
76
|
+
)
|
77
|
+
fs.writeFileSync(configFile, FILE_TEMPLATE(newManifest))
|
78
|
+
let prefix = ''
|
79
|
+
if (process.env.NODE_ENV === 'test') {
|
80
|
+
const registerPath = require.resolve('esbuild-register')
|
81
|
+
const loaderPath = require.resolve('esbuild-register/loader')
|
82
|
+
prefix = `node --import ${registerPath} -r ${loaderPath} `
|
83
|
+
}
|
84
|
+
// TODO replace with `spawn` to support watch mode
|
85
|
+
childProcess.execSync(`${prefix}${rollupBinaryPath} -c ${configFile}`, {
|
86
|
+
cwd: dir, stdio: 'inherit'
|
87
|
+
})
|
88
|
+
}
|
89
|
+
|
90
|
+
actionDone()
|
91
|
+
})
|
@@ -0,0 +1,79 @@
|
|
1
|
+
import fs from 'node:fs'
|
2
|
+
import path from 'node:path'
|
3
|
+
|
4
|
+
import { bump, type BumperType } from '@jiek/utils/bumper'
|
5
|
+
import { getWorkspaceDir } from '@jiek/utils/getWorkspaceDir'
|
6
|
+
import type { PackageJson } from '@npm/types'
|
7
|
+
import { filterPackagesFromDir } from '@pnpm/filter-workspace-packages'
|
8
|
+
import * as childProcess from 'child_process'
|
9
|
+
import { program } from 'commander'
|
10
|
+
|
11
|
+
import { actionDone, actionRestore } from '../inner'
|
12
|
+
import { mergePackageJson } from '../merge-package-json'
|
13
|
+
|
14
|
+
program
|
15
|
+
.command('publish')
|
16
|
+
.aliases(['pub', 'p'])
|
17
|
+
.option('--filter <filter>', 'filter packages')
|
18
|
+
.option('--root <root>', 'root path')
|
19
|
+
.option('--bumper <bumper>', 'bump version', 'patch')
|
20
|
+
.action(async ({ root: rootOption, filter, bumper, ...options }: {
|
21
|
+
root?: string
|
22
|
+
filter?: string
|
23
|
+
bumper: BumperType
|
24
|
+
}) => {
|
25
|
+
actionRestore()
|
26
|
+
const root = rootOption
|
27
|
+
? path.isAbsolute(rootOption)
|
28
|
+
? rootOption
|
29
|
+
: path.resolve(process.cwd(), rootOption)
|
30
|
+
: process.cwd()
|
31
|
+
const wd = getWorkspaceDir(root)
|
32
|
+
const { selectedProjectsGraph } = await filterPackagesFromDir(wd, [{
|
33
|
+
filter: filter ?? '',
|
34
|
+
followProdDepsOnly: true
|
35
|
+
}], {
|
36
|
+
prefix: root,
|
37
|
+
workspaceDir: wd,
|
38
|
+
patterns: ['packages/*']
|
39
|
+
})
|
40
|
+
const mainfests: [dir: string, PackageJson][] = []
|
41
|
+
Object
|
42
|
+
.entries(selectedProjectsGraph)
|
43
|
+
.forEach(([, { package: { dir, manifest } }]) => {
|
44
|
+
mainfests.push([
|
45
|
+
dir, mergePackageJson(manifest, dir)
|
46
|
+
])
|
47
|
+
})
|
48
|
+
const passArgs = Object
|
49
|
+
.entries(options)
|
50
|
+
.reduce((acc, [key, value]) => {
|
51
|
+
if (value) {
|
52
|
+
acc.push(`--${key}`, value as string)
|
53
|
+
}
|
54
|
+
return acc
|
55
|
+
}, [] as string[])
|
56
|
+
for (const [dir, m] of mainfests) {
|
57
|
+
const newVersion = bump(m.version, bumper)
|
58
|
+
const newManifest = {
|
59
|
+
...m,
|
60
|
+
version: newVersion
|
61
|
+
}
|
62
|
+
fs.renameSync(path.join(dir, 'package.json'), path.join(dir, 'package.json.bak'))
|
63
|
+
fs.writeFileSync(path.join(dir, 'package.json'), JSON.stringify(newManifest, null, 2))
|
64
|
+
console.log(newManifest)
|
65
|
+
try {
|
66
|
+
childProcess.execSync(['pnpm', 'publish', '--access', 'public', '--no-git-checks', ...passArgs].join(' '), {
|
67
|
+
cwd: dir,
|
68
|
+
stdio: 'inherit'
|
69
|
+
})
|
70
|
+
const oldPackageJson = JSON.parse(fs.readFileSync(path.join(dir, 'package.json.bak'), 'utf-8'))
|
71
|
+
oldPackageJson.version = newVersion
|
72
|
+
fs.writeFileSync(path.join(dir, 'package.json.bak'), JSON.stringify(oldPackageJson, null, 2))
|
73
|
+
} finally {
|
74
|
+
fs.unlinkSync(path.join(dir, 'package.json'))
|
75
|
+
fs.renameSync(path.join(dir, 'package.json.bak'), path.join(dir, 'package.json'))
|
76
|
+
}
|
77
|
+
}
|
78
|
+
actionDone()
|
79
|
+
})
|
package/src/index.ts
ADDED
package/src/inner.ts
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
import { type Options, pkger } from '@jiek/pkger'
|
2
|
+
import type { PackageJson } from '@npm/types'
|
3
|
+
import type { Manifest } from '@pnpm/workspace.pkgs-graph'
|
4
|
+
|
5
|
+
export function mergePackageJson(manifest: Manifest & {
|
6
|
+
jiek?: Options
|
7
|
+
exports?: unknown | unknown[]
|
8
|
+
}, cwd: string) {
|
9
|
+
const {
|
10
|
+
jiek: { inputs: jiekInputs, cwd: _, ...jiek } = {}, exports
|
11
|
+
} = manifest
|
12
|
+
const inputs = jiekInputs ?? (
|
13
|
+
Array.isArray(exports) ? exports : undefined
|
14
|
+
)
|
15
|
+
return {
|
16
|
+
...manifest,
|
17
|
+
...pkger({ inputs, cwd, ...jiek })
|
18
|
+
} as PackageJson
|
19
|
+
}
|