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.
Files changed (45) hide show
  1. package/dist/commands/build.esm.js +10 -32
  2. package/dist/commands/build.esm.js.map +1 -1
  3. package/dist/commands/build.esm.min.js +1 -1
  4. package/dist/commands/build.esm.min.js.map +1 -1
  5. package/dist/commands/publish.esm.js +50 -34
  6. package/dist/commands/publish.esm.js.map +1 -1
  7. package/dist/commands/publish.esm.min.js +1 -1
  8. package/dist/commands/publish.esm.min.js.map +1 -1
  9. package/dist/index.esm.js +3 -0
  10. package/dist/index.esm.js.map +1 -1
  11. package/dist/index.esm.min.js +1 -1
  12. package/dist/index.esm.min.js.map +1 -1
  13. package/dist/index.iife.js +194 -67
  14. package/dist/index.iife.js.map +1 -1
  15. package/dist/index.iife.min.js +1 -1
  16. package/dist/index.iife.min.js.map +1 -1
  17. package/dist/index.umd.js +196 -69
  18. package/dist/index.umd.js.map +1 -1
  19. package/dist/index.umd.min.js +1 -1
  20. package/dist/index.umd.min.js.map +1 -1
  21. package/dist/merge-package-json.esm.js +45 -4
  22. package/dist/merge-package-json.esm.js.map +1 -1
  23. package/dist/merge-package-json.esm.min.js +1 -1
  24. package/dist/merge-package-json.esm.min.js.map +1 -1
  25. package/dist/rollup.esm.js +7 -0
  26. package/dist/rollup.esm.js.map +1 -1
  27. package/dist/rollup.esm.min.js +1 -1
  28. package/dist/rollup.esm.min.js.map +1 -1
  29. package/dist/rollup.iife.js +9 -2
  30. package/dist/rollup.iife.js.map +1 -1
  31. package/dist/rollup.iife.min.js +1 -1
  32. package/dist/rollup.iife.min.js.map +1 -1
  33. package/dist/rollup.umd.js +11 -4
  34. package/dist/rollup.umd.js.map +1 -1
  35. package/dist/rollup.umd.min.js +1 -1
  36. package/dist/rollup.umd.min.js.map +1 -1
  37. package/dist/utils/commondir.esm.js +25 -0
  38. package/dist/utils/commondir.esm.js.map +1 -0
  39. package/dist/utils/commondir.esm.min.js +2 -0
  40. package/dist/utils/commondir.esm.min.js.map +1 -0
  41. package/dist/utils/filterSupport.esm.js +78 -0
  42. package/dist/utils/filterSupport.esm.js.map +1 -0
  43. package/dist/utils/filterSupport.esm.min.js +2 -0
  44. package/dist/utils/filterSupport.esm.min.js.map +1 -0
  45. package/package.json +27 -30
@@ -1,12 +1,10 @@
1
1
  import * as childProcess from 'node:child_process';
2
2
  import fs from 'node:fs';
3
3
  import path from 'node:path';
4
- import { getWorkspaceDir } from '@jiek/utils/getWorkspaceDir';
5
- import { filterPackagesFromDir } from '@pnpm/filter-workspace-packages';
6
4
  import { program } from 'commander';
7
- import { load } from 'js-yaml';
8
5
  import { actionRestore, actionDone } from '../inner.esm.js';
9
6
  import { mergePackageJson } from '../merge-package-json.esm.js';
7
+ import { getSelectedProjectsGraph } from '../utils/filterSupport.esm.js';
10
8
 
11
9
  const FILE_TEMPLATE = (manifest) => `
12
10
  const pkg = ${JSON.stringify(manifest, null, 2)}
@@ -16,43 +14,23 @@ const templateArg = jiek.templateArgFilePath
16
14
  : {
17
15
  styled: jiek.styled
18
16
  }
19
- module.exports = require('${process.env.NODE_ENV === "test" ? "jiek/src/rollup/index.ts" : "jiek/rollup"}').template(templateArg, pkg)
17
+ module.exports = require('jiek/rollup').template(templateArg, pkg)
20
18
  `.trimStart();
21
- program.command("build").option("--filter <filter>", "filter packages").option("--root <root>", "root path").action(async ({ root: rootOption, filter, ...options }) => {
19
+ program.command("build").action(async () => {
22
20
  actionRestore();
23
- const root = rootOption ? path.isAbsolute(rootOption) ? rootOption : path.resolve(process.cwd(), rootOption) : process.cwd();
24
- const wd = getWorkspaceDir(root);
25
- const pnpmWorkspaceFilePath = path.resolve(wd, "pnpm-workspace.yaml");
26
- const pnpmWorkspaceFileContent = fs.readFileSync(pnpmWorkspaceFilePath, "utf-8");
27
- const pnpmWorkspace = load(pnpmWorkspaceFileContent);
28
- if (root === wd && !filter) {
29
- throw new Error("root path is workspace root, please provide a filter");
21
+ const {
22
+ wd,
23
+ value = {}
24
+ } = await getSelectedProjectsGraph() ?? {};
25
+ if (Object.keys(value).length === 0) {
26
+ throw new Error("no package found");
30
27
  }
31
- if (root !== wd && !filter) {
32
- const packageJSONIsExist = fs.existsSync(path.resolve(root, "package.json"));
33
- if (!packageJSONIsExist) {
34
- throw new Error("root path is not workspace root, please provide a filter");
35
- }
36
- const packageJSON = JSON.parse(fs.readFileSync(path.resolve(root, "package.json"), "utf-8"));
37
- if (!packageJSON.name) {
38
- throw new Error("root path is not workspace root, please provide a filter");
39
- }
40
- filter = packageJSON.name;
41
- }
42
- const { selectedProjectsGraph } = await filterPackagesFromDir(wd, [{
43
- filter: filter ?? "",
44
- followProdDepsOnly: true
45
- }], {
46
- prefix: root,
47
- workspaceDir: wd,
48
- patterns: pnpmWorkspace.packages
49
- });
50
28
  const jiekTempDir = (...paths) => path.resolve(wd, "node_modules/.jiek", ...paths);
51
29
  if (!fs.existsSync(jiekTempDir()))
52
30
  fs.mkdirSync(jiekTempDir());
53
31
  const rollupBinaryPath = require.resolve("rollup").replace(/dist\/rollup.js$/, "dist/bin/rollup");
54
32
  let i = 0;
55
- for (const [dir, { package: { manifest } }] of Object.entries(selectedProjectsGraph)) {
33
+ for (const [dir, manifest] of Object.entries(value)) {
56
34
  const newManifest = mergePackageJson(manifest, dir);
57
35
  const escapeManifestName = manifest.name?.replace(/^@/g, "").replace(/\//g, "+");
58
36
  const configFile = jiekTempDir(
@@ -1 +1 @@
1
- {"version":3,"file":"build.esm.js","sources":["../../src/commands/build.ts"],"sourcesContent":["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"],"names":[],"mappings":";;;;;;;;;;AAYA,MAAM,aAAA,GAAgB,CAAC,QAAsB,KAAA,CAAA;AAAA,YAAA,EAC/B,IAAK,CAAA,SAAA,CAAU,QAAU,EAAA,IAAA,EAAM,CAAC,CAAC,CAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,0BAAA,EAQ7C,OAAQ,CAAA,GAAA,CAAI,QAAa,KAAA,MAAA,GACrB,6BACA,aACN,CAAA;AAAA,CAAA,CACE,SAAU,EAAA,CAAA;AAEZ,OAAA,CACG,QAAQ,OAAO,CAAA,CACf,OAAO,mBAAqB,EAAA,iBAAiB,EAC7C,MAAO,CAAA,eAAA,EAAiB,WAAW,CACnC,CAAA,MAAA,CAAO,OAAO,EAAE,IAAA,EAAM,YAAY,MAAQ,EAAA,GAAG,SAGxC,KAAA;AACJ,EAAc,aAAA,EAAA,CAAA;AACd,EAAA,MAAM,IAAO,GAAA,UAAA,GACT,IAAK,CAAA,UAAA,CAAW,UAAU,CACxB,GAAA,UAAA,GACA,IAAK,CAAA,OAAA,CAAQ,QAAQ,GAAI,EAAA,EAAG,UAAU,CAAA,GACxC,QAAQ,GAAI,EAAA,CAAA;AAChB,EAAM,MAAA,EAAA,GAAK,gBAAgB,IAAI,CAA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AAA,OAAA,CAAQ,yBAAyB,CAAA,CAAA;AAC5D,MAAS,MAAA,GAAA,CAAA,cAAA,EAAiB,YAAY,CAAA,IAAA,EAAO,UAAU,CAAA,CAAA,CAAA,CAAA;AAAA,KACzD;AAEA,IAAA,YAAA,CAAa,SAAS,CAAG,EAAA,MAAM,GAAG,gBAAgB,CAAA,IAAA,EAAO,UAAU,CAAI,CAAA,EAAA;AAAA,MACrE,GAAK,EAAA,GAAA;AAAA,MAAK,KAAO,EAAA,SAAA;AAAA,KAClB,CAAA,CAAA;AAAA,GACH;AAEA,EAAW,UAAA,EAAA,CAAA;AACb,CAAC,CAAA"}
1
+ {"version":3,"file":"build.esm.js","sources":["../../src/commands/build.ts"],"sourcesContent":["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"],"names":[],"mappings":";;;;;;;;AAUA,MAAM,aAAA,GAAgB,CAAC,QAAsB,KAAA,CAAA;AAAA,YAAA,EAC/B,IAAK,CAAA,SAAA,CAAU,QAAU,EAAA,IAAA,EAAM,CAAC,CAAC,CAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,CAAA,CAQ7C,SAAU,EAAA,CAAA;AAEZ,OAAA,CACG,OAAQ,CAAA,OAAO,CACf,CAAA,MAAA,CAAO,YAAY;AAClB,EAAc,aAAA,EAAA,CAAA;AACd,EAAM,MAAA;AAAA,IACJ,EAAA;AAAA,IAAI,QAAQ,EAAC;AAAA,GACX,GAAA,MAAM,wBAAyB,EAAA,IAAK,EAAC,CAAA;AAEzC,EAAA,IAAI,MAAO,CAAA,IAAA,CAAK,KAAK,CAAA,CAAE,WAAW,CAAG,EAAA;AACnC,IAAM,MAAA,IAAI,MAAM,kBAAkB,CAAA,CAAA;AAAA,GACpC;AACA,EAAM,MAAA,WAAA,GAAc,IAAI,KAAoB,KAAA,IAAA,CAAK,QAAQ,EAAI,EAAA,oBAAA,EAAsB,GAAG,KAAK,CAAA,CAAA;AAC3F,EAAA,IAAI,CAAC,EAAA,CAAG,UAAW,CAAA,WAAA,EAAa,CAAA;AAAG,IAAG,EAAA,CAAA,SAAA,CAAU,aAAa,CAAA,CAAA;AAE7D,EAAA,MAAM,mBA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AA,CAAA;AAAA,GACH;AAEA,EAAW,UAAA,EAAA,CAAA;AACb,CAAC,CAAA"}
@@ -1,2 +1,2 @@
1
- import*as e from"node:child_process";import r from"node:fs";import o from"node:path";import{getWorkspaceDir as t}from"@jiek/utils/getWorkspaceDir";import{filterPackagesFromDir as s}from"@pnpm/filter-workspace-packages";import{program as i}from"commander";import{load as p}from"js-yaml";import{actionRestore as n,actionDone as l}from"../inner.esm.min.js";import{mergePackageJson as a}from"../merge-package-json.esm.min.js";const c=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('${"test"===process.env.NODE_ENV?"jiek/src/rollup/index.ts":"jiek/rollup"}').template(templateArg, pkg)\n`.trimStart();i.command("build").option("--filter <filter>","filter packages").option("--root <root>","root path").action((async({root:i,filter:m,...f})=>{n();const d=i?o.isAbsolute(i)?i:o.resolve(process.cwd(),i):process.cwd(),k=t(d),g=o.resolve(k,"pnpm-workspace.yaml"),u=r.readFileSync(g,"utf-8"),j=p(u);if(d===k&&!m)throw new Error("root path is workspace root, please provide a filter");if(d!==k&&!m){if(!r.existsSync(o.resolve(d,"package.json")))throw new Error("root path is not workspace root, please provide a filter");const e=JSON.parse(r.readFileSync(o.resolve(d,"package.json"),"utf-8"));if(!e.name)throw new Error("root path is not workspace root, please provide a filter");m=e.name}const{selectedProjectsGraph:w}=await s(k,[{filter:m??"",followProdDepsOnly:!0}],{prefix:d,workspaceDir:k,patterns:j.packages}),y=(...e)=>o.resolve(k,"node_modules/.jiek",...e);r.existsSync(y())||r.mkdirSync(y());const v=require.resolve("rollup").replace(/dist\/rollup.js$/,"dist/bin/rollup");let h=0;for(const[o,{package:{manifest:t}}]of Object.entries(w)){const s=a(t,o),i=t.name?.replace(/^@/g,"").replace(/\//g,"+"),p=y(`${i??"anonymous-"+h++}.rollup.config.js`);r.writeFileSync(p,c(s));let n="";if("test"===process.env.NODE_ENV){n=`node --import ${require.resolve("esbuild-register")} -r ${require.resolve("esbuild-register/loader")} `}e.execSync(`${n}${v} -c ${p}`,{cwd:o,stdio:"inherit"})}l()}));
1
+ import*as e from"node:child_process";import r from"node:fs";import o from"node:path";import{program as t}from"commander";import{actionRestore as i,actionDone as n}from"../inner.esm.min.js";import{mergePackageJson as s}from"../merge-package-json.esm.min.js";import{getSelectedProjectsGraph as l}from"../utils/filterSupport.esm.min.js";const m=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();t.command("build").action((async()=>{i();const{wd:t,value:p={}}=await l()??{};if(0===Object.keys(p).length)throw new Error("no package found");const c=(...e)=>o.resolve(t,"node_modules/.jiek",...e);r.existsSync(c())||r.mkdirSync(c());const a=require.resolve("rollup").replace(/dist\/rollup.js$/,"dist/bin/rollup");let d=0;for(const[o,t]of Object.entries(p)){const i=s(t,o),n=t.name?.replace(/^@/g,"").replace(/\//g,"+"),l=c(`${n??"anonymous-"+d++}.rollup.config.js`);r.writeFileSync(l,m(i));let p="";if("test"===process.env.NODE_ENV){p=`node --import ${require.resolve("esbuild-register")} -r ${require.resolve("esbuild-register/loader")} `}e.execSync(`${p}${a} -c ${l}`,{cwd:o,stdio:"inherit"})}n()}));
2
2
  //# sourceMappingURL=build.esm.min.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"build.esm.min.js","sources":["../../src/commands/build.ts"],"sourcesContent":["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"],"names":["FILE_TEMPLATE","manifest","JSON","stringify","process","env","NODE_ENV","trimStart","program","command","option","action","async","root","rootOption","filter","options","actionRestore","path","isAbsolute","resolve","cwd","wd","getWorkspaceDir","pnpmWorkspaceFilePath","pnpmWorkspaceFileContent","fs","readFileSync","pnpmWorkspace","load","Error","existsSync","packageJSON","parse","name","selectedProjectsGraph","filterPackagesFromDir","followProdDepsOnly","prefix","workspaceDir","patterns","packages","jiekTempDir","paths","mkdirSync","rollupBinaryPath","require","replace","i","dir","package","Object","entries","newManifest","mergePackageJson","escapeManifestName","configFile","writeFileSync","childProcess","execSync","stdio","actionDone"],"mappings":"saAYA,MAAMA,EAAiBC,GAAsB,iBAC/BC,KAAKC,UAAUF,EAAU,KAAM,8LAQlB,SAAzBG,QAAQC,IAAIC,SACR,2BACA,+CAEJC,YAEFC,EACGC,QAAQ,SACRC,OAAO,oBAAqB,mBAC5BA,OAAO,gBAAiB,aACxBC,QAAOC,OAASC,KAAMC,EAAYC,YAAWC,MAI9BC,IACd,MAAMJ,EAAOC,EACTI,EAAKC,WAAWL,GACdA,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AQ,6BAErC,CAEAsC,EAAaC,SAAS,GAAGrB,IAASO,QAAuBW,IAAc,CACrEnC,IAAK4B,EAAKW,MAAO,WAErB,CAEWC,GAAA"}
1
+ {"version":3,"file":"build.esm.min.js","sources":["../../src/commands/build.ts"],"sourcesContent":["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"],"names":["FILE_TEMPLATE","manifest","JSON","stringify","trimStart","program","command","action","async","actionRestore","wd","value","getSelectedProjectsGraph","Object","keys","length","Error","jiekTempDir","paths","path","resolve","fs","existsSync","mkdirSync","rollupBinaryPath","require","replace","i","dir","entries","newManifest","mergePackageJson","escapeManifestName","name","configFile","writeFileSync","prefix","process","env","NODE_ENV","childProcess","execSync","cwd","stdio","actionDone"],"mappings":"8UAUA,MAAMA,EAAiBC,GAAsB,iBAC/BC,KAAKC,UAAUF,EAAU,KAAM,wOAQ3CG,YAEFC,EACGC,QAAQ,SACRC,QAAOC,UACQC,IACR,MAAAC,GACJA,EAAAC,MAAIA,EAAQ,CAAC,SACLC,KAA8B,GAExC,GAAkC,IAA9BC,OAAOC,KAAKH,GAAOI,OACf,MAAA,IAAIC,MAAM,oBAEZ,MAAAC,EAAc,IAAIC,IAAoBC,EAAKC,QAAQV,EAAI,wBAAyBQ,GACjFG,EAAGC,WAAWL,MAAmBI,EAAAE,UAAUN,KAEhD,MAAMO,EAAmBC,QAAQL,QAAQ,UACtCM,QAAQ,mBAAoB,mBAC/B,IAAIC,EAAI,EACR,IAAA,MAAYC,EAAK3B,KAAaY,OAAOgB,QAAQlB,GAAQ,CAC7C,MAAAmB,EAAcC,EAAiB9B,EAAU2B,GAEzCI,EAAqB/B,EAASgC,MAAMP,QAAQ,MAAO,IAAIA,QAAQ,MAAO,KACtEQ,EAAajB,EACjB,GAAGe,GAAsB,aAAaL,wBAExCN,EAAGc,cAAcD,EAAYlC,EAAc8B,IAC3C,IAAIM,EAAS,GACT,GAAyB,SAAzBC,QAAQC,IAAIC,SAAqB,CAG1BH,EAAA,iBAFYX,QAAQL,QAAQ,0BAClBK,QAAQL,QAAQ,6BAErC,CAEAoB,EAAaC,SAAS,GAAGL,IAASZ,QAAuBU,IAAc,CACrEQ,IAAKd,EAAKe,MAAO,WAErB,CAEWC,GAAA"}
@@ -1,55 +1,71 @@
1
1
  import fs from 'node:fs';
2
2
  import path from 'node:path';
3
3
  import { bump } from '@jiek/utils/bumper';
4
- import { getWorkspaceDir } from '@jiek/utils/getWorkspaceDir';
5
- import { filterPackagesFromDir } from '@pnpm/filter-workspace-packages';
6
4
  import * as childProcess from 'child_process';
7
5
  import { program } from 'commander';
6
+ import detectIndent from 'detect-indent';
7
+ import { applyEdits, modify } from 'jsonc-parser';
8
8
  import { actionRestore, actionDone } from '../inner.esm.js';
9
9
  import { mergePackageJson } from '../merge-package-json.esm.js';
10
+ import { getSelectedProjectsGraph } from '../utils/filterSupport.esm.js';
10
11
 
11
- 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, ...options }) => {
12
+ program.command("publish").aliases(["pub", "p"]).option("-b, --bumper <bumper>", "bump version", "patch").option("-p, --preview", "preview publish").action(async ({ preview, bumper, ...options }) => {
12
13
  actionRestore();
13
- const root = rootOption ? path.isAbsolute(rootOption) ? rootOption : path.resolve(process.cwd(), rootOption) : process.cwd();
14
- const wd = getWorkspaceDir(root);
15
- const { selectedProjectsGraph } = await filterPackagesFromDir(wd, [{
16
- filter: filter ?? "",
17
- followProdDepsOnly: true
18
- }], {
19
- prefix: root,
20
- workspaceDir: wd,
21
- patterns: ["packages/*"]
22
- });
23
- const mainfests = [];
24
- Object.entries(selectedProjectsGraph).forEach(([, { package: { dir, manifest } }]) => {
25
- mainfests.push([
26
- dir,
27
- mergePackageJson(manifest, dir)
28
- ]);
29
- });
30
- const passArgs = Object.entries(options).reduce((acc, [key, value]) => {
31
- if (value) {
32
- acc.push(`--${key}`, value);
14
+ const { value = {} } = await getSelectedProjectsGraph() ?? {};
15
+ const selectedProjectsGraphEntries = Object.entries(value);
16
+ if (selectedProjectsGraphEntries.length === 0) {
17
+ throw new Error("no packages selected");
18
+ }
19
+ const mainfests = selectedProjectsGraphEntries.map(([dir, manifest]) => [
20
+ dir,
21
+ mergePackageJson(manifest, dir)
22
+ ]);
23
+ const passArgs = Object.entries(options).reduce((acc, [key, value2]) => {
24
+ if (value2) {
25
+ acc.push(`--${key}`, value2);
33
26
  }
34
27
  return acc;
35
28
  }, []);
36
- for (const [dir, m] of mainfests) {
37
- const newVersion = bump(m.version, bumper);
38
- const newManifest = {
39
- ...m,
40
- version: newVersion
29
+ for (const [dir, manifest] of mainfests) {
30
+ const oldJSONString = fs.readFileSync(path.join(dir, "package.json"), "utf-8");
31
+ const oldJSON = JSON.parse(oldJSONString) ?? "0.0.0";
32
+ const newVersion = bump(oldJSON.version, bumper);
33
+ const { indent = " " } = detectIndent(oldJSONString);
34
+ const formattingOptions = {
35
+ tabSize: indent.length,
36
+ insertSpaces: true
41
37
  };
42
- fs.renameSync(path.join(dir, "package.json"), path.join(dir, "package.json.bak"));
43
- fs.writeFileSync(path.join(dir, "package.json"), JSON.stringify(newManifest, null, 2));
44
- console.log(newManifest);
38
+ let newJSONString = oldJSONString;
39
+ newJSONString = applyEdits(newJSONString, modify(
40
+ newJSONString,
41
+ ["version"],
42
+ newVersion,
43
+ { formattingOptions }
44
+ ));
45
+ for (const [key, value2] of Object.entries(manifest)) {
46
+ if (JSON.stringify(value2) === JSON.stringify(oldJSON[key]))
47
+ continue;
48
+ newJSONString = applyEdits(newJSONString, modify(
49
+ newJSONString,
50
+ ["publishConfig", key],
51
+ value2,
52
+ { formattingOptions }
53
+ ));
54
+ }
45
55
  try {
56
+ fs.renameSync(path.join(dir, "package.json"), path.join(dir, "package.json.bak"));
57
+ fs.writeFileSync(path.join(dir, "package.json"), newJSONString);
58
+ console.log(newJSONString);
59
+ if (preview) {
60
+ console.warn("preview mode");
61
+ continue;
62
+ }
46
63
  childProcess.execSync(["pnpm", "publish", "--access", "public", "--no-git-checks", ...passArgs].join(" "), {
47
64
  cwd: dir,
48
65
  stdio: "inherit"
49
66
  });
50
- const oldPackageJson = JSON.parse(fs.readFileSync(path.join(dir, "package.json.bak"), "utf-8"));
51
- oldPackageJson.version = newVersion;
52
- fs.writeFileSync(path.join(dir, "package.json.bak"), JSON.stringify(oldPackageJson, null, 2));
67
+ const modifyVersionPackageJSON = applyEdits(oldJSONString, modify(oldJSONString, ["version"], newVersion, {}));
68
+ fs.writeFileSync(path.join(dir, "package.json.bak"), modifyVersionPackageJSON);
53
69
  } finally {
54
70
  fs.unlinkSync(path.join(dir, "package.json"));
55
71
  fs.renameSync(path.join(dir, "package.json.bak"), path.join(dir, "package.json"));
@@ -1 +1 @@
1
- {"version":3,"file":"publish.esm.js","sources":["../../src/commands/publish.ts"],"sourcesContent":["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"],"names":[],"mappings":";;;;;;;;;;AAaA,OAAA,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,MAAO,CAAA,mBAAA,EAAqB,cAAgB,EAAA,OAAO,EACnD,MAAO,CAAA,OAAO,EAAE,IAAA,EAAM,UAAY,EAAA,MAAA,EAAQ,MAAQ,EAAA,GAAG,SAIhD,KAAA;AACJ,EAAc,aAAA,EAAA,CAAA;AACd,EAAA,MAAM,IAAO,GAAA,UAAA,GACT,IAAK,CAAA,UAAA,CAAW,UAAU,CACxB,GAAA,UAAA,GACA,IAAK,CAAA,OAAA,CAAQ,QAAQ,GAAI,EAAA,EAAG,UAAU,CAAA,GACxC,QAAQ,GAAI,EAAA,CAAA;AAChB,EAAM,MAAA,EAA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AA,CAAK,GAAK,EAAA,cAAc,CAAC,CAAA,CAAA;AAAA,KAClF;AAAA,GACF;AACA,EAAW,UAAA,EAAA,CAAA;AACb,CAAC,CAAA"}
1
+ {"version":3,"file":"publish.esm.js","sources":["../../src/commands/publish.ts"],"sourcesContent":["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"],"names":["value"],"mappings":";;;;;;;;;;;AAaA,OACG,CAAA,OAAA,CAAQ,SAAS,CAAA,CACjB,OAAQ,CAAA,CAAC,OAAO,GAAG,CAAC,CACpB,CAAA,MAAA,CAAO,uBAAyB,EAAA,cAAA,EAAgB,OAAO,CACvD,CAAA,MAAA,CAAO,eAAiB,EAAA,iBAAiB,CACzC,CAAA,MAAA,CAAO,OAAO,EAAE,OAAS,EAAA,MAAA,EAAQ,GAAG,OAAA,EAG/B,KAAA;AACJ,EAAc,aAAA,EAAA,CAAA;AAEd,EAAM,MAAA,EAAE,QAAQ,EAAC,KAAM,MAAM,wBAAA,MAA8B,EAAC,CAAA;AAC5D,EAAM,MAAA,4BAAA,GAA+B,MAAO,CAAA,OAAA,CAAQ,KAAK,CAAA,CAAA;AACzD,EAAI,IAAA,4BAAA,CAA6B,WAAW,CAAG,EAAA;AAC7C,IAAM,MAAA,IAAI,MAAM,sBAAsB,CAAA,CAAA;AAAA,GACxC;AACA,EAAA,MAAM,YAAY,4BACf,CAAA,GAAA,CAAI,CAAC,CAAC,GAAA,EAAK,QAAQ,CA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AA,IAAA,CAAK,GAAK,EAAA,kBAAkB,GAAG,wBAAwB,CAAA,CAAA;AAAA,KAC7E,SAAA;AACA,MAAA,EAAA,CAAG,UAAW,CAAA,IAAA,CAAK,IAAK,CAAA,GAAA,EAAK,cAAc,CAAC,CAAA,CAAA;AAC5C,MAAG,EAAA,CAAA,UAAA,CAAW,IAAK,CAAA,IAAA,CAAK,GAAK,EAAA,kBAAkB,GAAG,IAAK,CAAA,IAAA,CAAK,GAAK,EAAA,cAAc,CAAC,CAAA,CAAA;AAAA,KAClF;AAAA,GACF;AACA,EAAW,UAAA,EAAA,CAAA;AACb,CAAC,CAAA"}
@@ -1,2 +1,2 @@
1
- import o from"node:fs";import e from"node:path";import{bump as r}from"@jiek/utils/bumper";import{getWorkspaceDir as i}from"@jiek/utils/getWorkspaceDir";import{filterPackagesFromDir as n}from"@pnpm/filter-workspace-packages";import*as s from"child_process";import{program as a}from"commander";import{actionRestore as p,actionDone as t}from"../inner.esm.min.js";import{mergePackageJson as c}from"../merge-package-json.esm.min.js";a.command("publish").aliases(["pub","p"]).option("--filter <filter>","filter packages").option("--root <root>","root path").option("--bumper <bumper>","bump version","patch").action((async({root:a,filter:m,bumper:l,...f})=>{p();const j=a?e.isAbsolute(a)?a:e.resolve(process.cwd(),a):process.cwd(),k=i(j),{selectedProjectsGraph:g}=await n(k,[{filter:m??"",followProdDepsOnly:!0}],{prefix:j,workspaceDir:k,patterns:["packages/*"]}),u=[];Object.entries(g).forEach((([,{package:{dir:o,manifest:e}}])=>{u.push([o,c(e,o)])}));const b=Object.entries(f).reduce(((o,[e,r])=>(r&&o.push(`--${e}`,r),o)),[]);for(const[i,n]of u){const a=r(n.version,l),p={...n,version:a};o.renameSync(e.join(i,"package.json"),e.join(i,"package.json.bak")),o.writeFileSync(e.join(i,"package.json"),JSON.stringify(p,null,2)),console.log(p);try{s.execSync(["pnpm","publish","--access","public","--no-git-checks",...b].join(" "),{cwd:i,stdio:"inherit"});const r=JSON.parse(o.readFileSync(e.join(i,"package.json.bak"),"utf-8"));r.version=a,o.writeFileSync(e.join(i,"package.json.bak"),JSON.stringify(r,null,2))}finally{o.unlinkSync(e.join(i,"package.json")),o.renameSync(e.join(i,"package.json.bak"),e.join(i,"package.json"))}}t()}));
1
+ import e from"node:fs";import n from"node:path";import{bump as o}from"@jiek/utils/bumper";import*as i from"child_process";import{program as r}from"commander";import s from"detect-indent";import{applyEdits as t,modify as p}from"jsonc-parser";import{actionRestore as a,actionDone as c}from"../inner.esm.min.js";import{mergePackageJson as m}from"../merge-package-json.esm.min.js";import{getSelectedProjectsGraph as j}from"../utils/filterSupport.esm.min.js";r.command("publish").aliases(["pub","p"]).option("-b, --bumper <bumper>","bump version","patch").option("-p, --preview","preview publish").action((async({preview:r,bumper:f,...l})=>{a();const{value:g={}}=await j()??{},u=Object.entries(g);if(0===u.length)throw new Error("no packages selected");const b=u.map((([e,n])=>[e,m(n,e)])),k=Object.entries(l).reduce(((e,[n,o])=>(o&&e.push(`--${n}`,o),e)),[]);for(const[a,c]of b){const m=e.readFileSync(n.join(a,"package.json"),"utf-8"),j=JSON.parse(m)??"0.0.0",l=o(j.version,f),{indent:g=" "}=s(m),u={tabSize:g.length,insertSpaces:!0};let b=m;b=t(b,p(b,["version"],l,{formattingOptions:u}));for(const[e,n]of Object.entries(c))JSON.stringify(n)!==JSON.stringify(j[e])&&(b=t(b,p(b,["publishConfig",e],n,{formattingOptions:u})));try{if(e.renameSync(n.join(a,"package.json"),n.join(a,"package.json.bak")),e.writeFileSync(n.join(a,"package.json"),b),console.log(b),r){console.warn("preview mode");continue}i.execSync(["pnpm","publish","--access","public","--no-git-checks",...k].join(" "),{cwd:a,stdio:"inherit"});const o=t(m,p(m,["version"],l,{}));e.writeFileSync(n.join(a,"package.json.bak"),o)}finally{e.unlinkSync(n.join(a,"package.json")),e.renameSync(n.join(a,"package.json.bak"),n.join(a,"package.json"))}}c()}));
2
2
  //# sourceMappingURL=publish.esm.min.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"publish.esm.min.js","sources":["../../src/commands/publish.ts"],"sourcesContent":["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"],"names":["program","command","aliases","option","action","async","root","rootOption","filter","bumper","options","actionRestore","path","isAbsolute","resolve","process","cwd","wd","getWorkspaceDir","selectedProjectsGraph","filterPackagesFromDir","followProdDepsOnly","prefix","workspaceDir","patterns","mainfests","Object","entries","forEach","package","dir","manifest","push","mergePackageJson","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","actionDone"],"mappings":"4aAaAA,EACGC,QAAQ,WACRC,QAAQ,CAAC,MAAO,MAChBC,OAAO,oBAAqB,mBAC5BA,OAAO,gBAAiB,aACxBA,OAAO,oBAAqB,eAAgB,SAC5CC,QAAOC,OAASC,KAAMC,EAAYC,SAAQC,YAAWC,MAKtCC,IACd,MAAML,EAAOC,EACTK,EAAKC,WAAWN,GACdA,EACAK,EAAKE,QAAQC,QAAQC,MAAOT,GAC9BQ,QAAQC,MACNC,EAAKC,EAAgBZ,IACrBa,sBAAEA,SAAgCC,EAAsBH,EAAI,CAAC,CACjET,OAAQA,GAAU,GAClBa,oBAAoB,IAClB,CACFC,OAAQhB,EACRiB,aAAcN,EACdO,SAAU,CAAC,gBAEPC,EAA0C,GAChDC,OACGC,QAAQR,GACRS,SAAQ,IAAMC,SAAWC,MAAKC,iBAC7BN,EAAUO,KAAK,CACbF,EAAKG,EAAiBF,EAAUD,IACjC,IAEC,MAAAI,EAAWR,OACdC,QAAQjB,GACRyB,QAAO,CAACC,GAAMC,EAAKC,MACdA,GACFF,EAAIJ,KAAK,KAAKK,IAAOC,GAEhBF,IACN,IACL,IAAA,MAAYN,EAAKS,KAAMd,EAAW,CAChC,MAAMe,EAAaC,EAAKF,EAAEG,QAASjC,GAC7BkC,EAAc,IACfJ,EACHG,QAASF,GAERI,EAAAC,WAAWjC,EAAKkC,KAAKhB,EAAK,gBAAiBlB,EAAKkC,KAAKhB,EAAK,qBAC1Dc,EAAAG,cAAcnC,EAAKkC,KAAKhB,EAAK,gBAAiBkB,KAAKC,UAAUN,EAAa,KAAM,IACnFO,QAAQC,IAAIR,GACR,IACFS,EAAaC,SAAS,CAAC,OAAQ,UAAW,WAAY,SAAU,qBAAsBnB,GAAUY,KAAK,KAAM,CACzG9B,IAAKc,EACLwB,MAAO,YAEH,MAAAC,EAAiBP,KAAKQ,MAAMZ,EAAGa,aAAa7C,EAAKkC,KAAKhB,EAAK,oBAAqB,UACtFyB,EAAeb,QAAUF,EACtBI,EAAAG,cAAcnC,EAAKkC,KAAKhB,EAAK,oBAAqBkB,KAAKC,UAAUM,EAAgB,KAAM,GAAE,CAC5F,QACAX,EAAGc,WAAW9C,EAAKkC,KAAKhB,EAAK,iBAC1Bc,EAAAC,WAAWjC,EAAKkC,KAAKhB,EAAK,oBAAqBlB,EAAKkC,KAAKhB,EAAK,gBACnE,CACF,CACW6B,GAAA"}
1
+ {"version":3,"file":"publish.esm.min.js","sources":["../../src/commands/publish.ts"],"sourcesContent":["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"],"names":["program","command","aliases","option","action","async","preview","bumper","options","actionRestore","value","getSelectedProjectsGraph","selectedProjectsGraphEntries","Object","entries","length","Error","mainfests","map","dir","manifest","mergePackageJson","passArgs","reduce","acc","key","push","oldJSONString","fs","readFileSync","path","join","oldJSON","JSON","parse","newVersion","bump","version","indent","detectIndent","formattingOptions","tabSize","insertSpaces","newJSONString","applyEdits","modify","stringify","renameSync","writeFileSync","console","log","warn","childProcess","execSync","cwd","stdio","modifyVersionPackageJSON","unlinkSync","actionDone"],"mappings":"scAaAA,EACGC,QAAQ,WACRC,QAAQ,CAAC,MAAO,MAChBC,OAAO,wBAAyB,eAAgB,SAChDA,OAAO,gBAAiB,mBACxBC,QAAOC,OAASC,UAASC,YAAWC,MAIrBC,IAER,MAAAC,MAAEA,EAAQ,CAAC,SAAYC,KAA8B,CAAA,EACrDC,EAA+BC,OAAOC,QAAQJ,GAChD,GAAwC,IAAxCE,EAA6BG,OACzB,MAAA,IAAIC,MAAM,wBAElB,MAAMC,EAAYL,EACfM,KAAI,EAAEC,EAAKC,KAAc,CACxBD,EAAKE,EAAiBD,EAAUD,MAE9BG,EAAWT,OACdC,QAAQN,GACRe,QAAO,CAACC,GAAMC,EAAKf,MACdA,GACFc,EAAIE,KAAK,KAAKD,IAAOf,GAEhBc,IACN,IACL,IAAA,MAAYL,EAAKC,KAAaH,EAAW,CACjC,MAAAU,EAAgBC,EAAGC,aAAaC,EAAKC,KAAKZ,EAAK,gBAAiB,SAChEa,EAAUC,KAAKC,MAAMP,IAAkB,QACvCQ,EAAaC,EAAKJ,EAAQK,QAAS9B,IAEnC+B,OAAEA,EAAS,QAAWC,EAAaZ,GACnCa,EAAoB,CACxBC,QAASH,EAAOvB,OAChB2B,cAAc,GAEhB,IAAIC,EAAgBhB,EACpBgB,EAAgBC,EAAWD,EAAeE,EACxCF,EAAe,CAAC,WAAYR,EAAY,CAAEK,uBAE5C,IAAA,MAAYf,EAAKf,KAAUG,OAAOC,QAAQM,GACpCa,KAAKa,UAAUpC,KAAWuB,KAAKa,UAAUd,EAAQP,MAErDkB,EAAgBC,EAAWD,EAAeE,EACxCF,EAAe,CAAC,gBAAiBlB,GAAMf,EAAO,CAAE8B,wBAGhD,IAIF,GAHGZ,EAAAmB,WAAWjB,EAAKC,KAAKZ,EAAK,gBAAiBW,EAAKC,KAAKZ,EAAK,qBAC7DS,EAAGoB,cAAclB,EAAKC,KAAKZ,EAAK,gBAAiBwB,GACjDM,QAAQC,IAAIP,GACRrC,EAAS,CACX2C,QAAQE,KAAK,gBACb,QACF,CACAC,EAAaC,SAAS,CAAC,OAAQ,UAAW,WAAY,SAAU,qBAAsB/B,GAAUS,KAAK,KAAM,CACzGuB,IAAKnC,EACLoC,MAAO,YAEH,MAAAC,EAA2BZ,EAAWjB,EAAekB,EAAOlB,EAAe,CAAC,WAAYQ,EAAY,CAAE,IAC5GP,EAAGoB,cAAclB,EAAKC,KAAKZ,EAAK,oBAAqBqC,EAAwB,CAC7E,QACA5B,EAAG6B,WAAW3B,EAAKC,KAAKZ,EAAK,iBAC1BS,EAAAmB,WAAWjB,EAAKC,KAAKZ,EAAK,oBAAqBW,EAAKC,KAAKZ,EAAK,gBACnE,CACF,CACWuC,GAAA"}
package/dist/index.esm.js CHANGED
@@ -1,6 +1,9 @@
1
+ import './utils/filterSupport.esm.js';
1
2
  import './commands/publish.esm.js';
2
3
  import './commands/build.esm.js';
3
4
  import { program } from 'commander';
4
5
 
6
+ const pkg = require("../package.json");
7
+ program.version(pkg.version).description(pkg.description).option("--root <root>", "root path");
5
8
  program.parse(process.argv);
6
9
  //# sourceMappingURL=index.esm.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.esm.js","sources":["../src/index.ts"],"sourcesContent":["import './commands/publish'\nimport './commands/build'\n\nimport { program } from 'commander'\n\nprogram.parse(process.argv)\n"],"names":[],"mappings":";;;;AAKA,OAAQ,CAAA,KAAA,CAAM,QAAQ,IAAI,CAAA"}
1
+ {"version":3,"file":"index.esm.js","sources":["../src/index.ts"],"sourcesContent":["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":[],"mappings":";;;;;AAOA,MAAM,GAAA,GAAM,QAAQ,iBAAiB,CAAA,CAAA;AAErC,OACG,CAAA,OAAA,CAAQ,GAAI,CAAA,OAAO,CACnB,CAAA,WAAA,CAAY,IAAI,WAAW,CAAA,CAC3B,MAAO,CAAA,eAAA,EAAiB,WAAW,CAAA,CAAA;AAEtC,OAAQ,CAAA,KAAA,CAAM,QAAQ,IAAI,CAAA"}
@@ -1,2 +1,2 @@
1
- import"./commands/publish.esm.min.js";import"./commands/build.esm.min.js";import{program as m}from"commander";m.parse(process.argv);
1
+ import"./utils/filterSupport.esm.min.js";import"./commands/publish.esm.min.js";import"./commands/build.esm.min.js";import{program as o}from"commander";const r=require("../package.json");o.version(r.version).description(r.description).option("--root <root>","root path"),o.parse(process.argv);
2
2
  //# sourceMappingURL=index.esm.min.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.esm.min.js","sources":["../src/index.ts"],"sourcesContent":["import './commands/publish'\nimport './commands/build'\n\nimport { program } from 'commander'\n\nprogram.parse(process.argv)\n"],"names":["program","parse","process","argv"],"mappings":"8GAKAA,EAAQC,MAAMC,QAAQC"}
1
+ {"version":3,"file":"index.esm.min.js","sources":["../src/index.ts"],"sourcesContent":["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":["pkg","require","program","version","description","option","parse","process","argv"],"mappings":"uJAOA,MAAMA,EAAMC,QAAQ,mBAEpBC,EACGC,QAAQH,EAAIG,SACZC,YAAYJ,EAAII,aAChBC,OAAO,gBAAiB,aAE3BH,EAAQI,MAAMC,QAAQC"}