smartbundle 0.14.1 → 0.15.0-alpha.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (87) hide show
  1. package/README.md +6 -1
  2. package/__bin__/smartbundle-monorepo-link.js +2 -0
  3. package/__compiled__/cjs/src/args.d.ts +9 -1
  4. package/__compiled__/cjs/src/args.js +3 -0
  5. package/__compiled__/cjs/src/args.js.map +1 -1
  6. package/__compiled__/cjs/src/detectModules.d.ts +25 -11
  7. package/__compiled__/cjs/src/detectModules.js +165 -28
  8. package/__compiled__/cjs/src/detectModules.js.map +1 -1
  9. package/__compiled__/cjs/src/index.d.ts +1 -1
  10. package/__compiled__/cjs/src/index.js +11 -5
  11. package/__compiled__/cjs/src/index.js.map +1 -1
  12. package/__compiled__/cjs/src/monorepo/buildAll.js +62 -0
  13. package/__compiled__/cjs/src/monorepo/buildAll.js.map +1 -0
  14. package/__compiled__/cjs/src/monorepo/convertPackageJson.d.ts +31 -0
  15. package/__compiled__/cjs/src/monorepo/convertPackageJson.js +40 -0
  16. package/__compiled__/cjs/src/monorepo/convertPackageJson.js.map +1 -0
  17. package/__compiled__/cjs/src/monorepo/createLinkPackages/createLinkPackages.js +92 -0
  18. package/__compiled__/cjs/src/monorepo/createLinkPackages/createLinkPackages.js.map +1 -0
  19. package/__compiled__/cjs/src/monorepo/link.js +11 -0
  20. package/__compiled__/cjs/src/monorepo/link.js.map +1 -0
  21. package/__compiled__/cjs/src/monorepo/parseMonorepo/parseMonorepo.js +106 -0
  22. package/__compiled__/cjs/src/monorepo/parseMonorepo/parseMonorepo.js.map +1 -0
  23. package/__compiled__/cjs/src/packageJson.d.ts +5 -0
  24. package/__compiled__/cjs/src/packageJson.js +2 -0
  25. package/__compiled__/cjs/src/packageJson.js.map +1 -1
  26. package/__compiled__/cjs/src/plugins/babel/index.js +1 -1
  27. package/__compiled__/cjs/src/plugins/babel/index.js.map +1 -1
  28. package/__compiled__/cjs/src/plugins/react/index.js +3 -2
  29. package/__compiled__/cjs/src/plugins/react/index.js.map +1 -1
  30. package/__compiled__/cjs/src/run.js +47 -8
  31. package/__compiled__/cjs/src/run.js.map +1 -1
  32. package/__compiled__/cjs/src/tasks/buildTypesTask/buildTypesTask.js +1 -3
  33. package/__compiled__/cjs/src/tasks/buildTypesTask/buildTypesTask.js.map +1 -1
  34. package/__compiled__/cjs/src/tasks/buildTypesTask/callTypescript.d.ts +2 -2
  35. package/__compiled__/cjs/src/tasks/buildTypesTask/callTypescript.js.map +1 -1
  36. package/__compiled__/cjs/src/tasks/buildTypesTask/findTypingsNames.d.ts +2 -2
  37. package/__compiled__/cjs/src/tasks/buildTypesTask/findTypingsNames.js.map +1 -1
  38. package/__compiled__/cjs/src/tasks/buildTypesTask/findTypingsPackages.d.ts +2 -2
  39. package/__compiled__/cjs/src/tasks/buildTypesTask/findTypingsPackages.js.map +1 -1
  40. package/__compiled__/cjs/src/tasks/gitignoreTask.d.ts +6 -0
  41. package/__compiled__/cjs/src/tasks/gitignoreTask.js +14 -0
  42. package/__compiled__/cjs/src/tasks/gitignoreTask.js.map +1 -0
  43. package/__compiled__/cjs/src/writePackageJson.js +2 -0
  44. package/__compiled__/cjs/src/writePackageJson.js.map +1 -1
  45. package/__compiled__/esm/src/args.d.mts +9 -1
  46. package/__compiled__/esm/src/args.mjs +3 -0
  47. package/__compiled__/esm/src/args.mjs.map +1 -1
  48. package/__compiled__/esm/src/detectModules.d.mts +25 -11
  49. package/__compiled__/esm/src/detectModules.mjs +165 -28
  50. package/__compiled__/esm/src/detectModules.mjs.map +1 -1
  51. package/__compiled__/esm/src/index.d.mts +1 -1
  52. package/__compiled__/esm/src/index.mjs +11 -5
  53. package/__compiled__/esm/src/index.mjs.map +1 -1
  54. package/__compiled__/esm/src/monorepo/buildAll.mjs +62 -0
  55. package/__compiled__/esm/src/monorepo/buildAll.mjs.map +1 -0
  56. package/__compiled__/esm/src/monorepo/convertPackageJson.d.mts +31 -0
  57. package/__compiled__/esm/src/monorepo/convertPackageJson.mjs +40 -0
  58. package/__compiled__/esm/src/monorepo/convertPackageJson.mjs.map +1 -0
  59. package/__compiled__/esm/src/monorepo/createLinkPackages/createLinkPackages.mjs +92 -0
  60. package/__compiled__/esm/src/monorepo/createLinkPackages/createLinkPackages.mjs.map +1 -0
  61. package/__compiled__/esm/src/monorepo/link.mjs +10 -0
  62. package/__compiled__/esm/src/monorepo/link.mjs.map +1 -0
  63. package/__compiled__/esm/src/monorepo/parseMonorepo/parseMonorepo.mjs +106 -0
  64. package/__compiled__/esm/src/monorepo/parseMonorepo/parseMonorepo.mjs.map +1 -0
  65. package/__compiled__/esm/src/packageJson.d.mts +5 -0
  66. package/__compiled__/esm/src/packageJson.mjs +2 -0
  67. package/__compiled__/esm/src/packageJson.mjs.map +1 -1
  68. package/__compiled__/esm/src/plugins/babel/index.mjs +1 -1
  69. package/__compiled__/esm/src/plugins/babel/index.mjs.map +1 -1
  70. package/__compiled__/esm/src/plugins/react/index.mjs +3 -2
  71. package/__compiled__/esm/src/plugins/react/index.mjs.map +1 -1
  72. package/__compiled__/esm/src/run.mjs +47 -8
  73. package/__compiled__/esm/src/run.mjs.map +1 -1
  74. package/__compiled__/esm/src/tasks/buildTypesTask/buildTypesTask.mjs +1 -3
  75. package/__compiled__/esm/src/tasks/buildTypesTask/buildTypesTask.mjs.map +1 -1
  76. package/__compiled__/esm/src/tasks/buildTypesTask/callTypescript.d.mts +2 -2
  77. package/__compiled__/esm/src/tasks/buildTypesTask/callTypescript.mjs.map +1 -1
  78. package/__compiled__/esm/src/tasks/buildTypesTask/findTypingsNames.d.mts +2 -2
  79. package/__compiled__/esm/src/tasks/buildTypesTask/findTypingsNames.mjs.map +1 -1
  80. package/__compiled__/esm/src/tasks/buildTypesTask/findTypingsPackages.d.mts +2 -2
  81. package/__compiled__/esm/src/tasks/buildTypesTask/findTypingsPackages.mjs.map +1 -1
  82. package/__compiled__/esm/src/tasks/gitignoreTask.d.mts +6 -0
  83. package/__compiled__/esm/src/tasks/gitignoreTask.mjs +14 -0
  84. package/__compiled__/esm/src/tasks/gitignoreTask.mjs.map +1 -0
  85. package/__compiled__/esm/src/writePackageJson.mjs +2 -0
  86. package/__compiled__/esm/src/writePackageJson.mjs.map +1 -1
  87. package/package.json +19 -13
@@ -7,7 +7,8 @@ import { okLog } from "../../log.mjs";
7
7
  const errorJsxMessage = "SmartBundle cannot find the react dependency inside dependencies, optionalDependencies or peerDependencies. Please, install it before bundling";
8
8
  function reactPlugin({ modules }) {
9
9
  const pluginName = "smartbundle:react";
10
- if (modules.react == null) {
10
+ const reactModule = modules.react;
11
+ if (reactModule == null) {
11
12
  return {
12
13
  name: pluginName,
13
14
  transform(code, id) {
@@ -40,7 +41,7 @@ function reactPlugin({ modules }) {
40
41
  id,
41
42
  {
42
43
  loader: isJs || isJsx ? "jsx" : "tsx",
43
- jsx: modules.react === "legacy" ? "transform" : "automatic",
44
+ jsx: reactModule.transform === "legacy" ? "transform" : "automatic",
44
45
  sourcemap: true
45
46
  },
46
47
  this.getCombinedSourcemap()
@@ -1 +1 @@
1
- {"version":3,"file":"index.mjs","sources":["../../../../../../src/plugins/react/index.ts"],"sourcesContent":["import type { Plugin } from \"vite\";\nimport { transformWithEsbuild } from \"vite\";\nimport { type DetectedModules } from \"../../detectModules.js\";\nimport { okLog } from \"../../log.js\";\n\ntype ReactPluginArg = {\n modules: DetectedModules;\n};\n\nconst errorJsxMessage =\n \"SmartBundle cannot find the react dependency inside dependencies, optionalDependencies or peerDependencies. Please, install it before bundling\";\n\nexport function reactPlugin({ modules }: ReactPluginArg): Plugin {\n const pluginName = \"smartbundle:react\";\n\n if (modules.react == null) {\n return {\n name: pluginName,\n transform(code, id) {\n if (id.endsWith(\".jsx\") || id.endsWith(\".tsx\")) {\n this.error(new Error(errorJsxMessage));\n }\n },\n buildEnd(err) {\n if (err) {\n const isJsxError = err.message.includes(\"JSX\");\n if (isJsxError) {\n this.error(new Error(errorJsxMessage));\n }\n }\n },\n };\n }\n\n return {\n name: pluginName,\n enforce: \"pre\",\n async transform(code, id) {\n const isJs = id.endsWith(\".js\");\n const isJsx = id.endsWith(\".jsx\");\n const isTsx = id.endsWith(\".tsx\");\n if (!(isJs || isJsx || isTsx)) {\n return null;\n }\n\n return await transformWithEsbuild(\n code,\n id,\n {\n loader: isJs || isJsx ? \"jsx\" : \"tsx\",\n jsx: modules.react === \"legacy\" ? \"transform\" : \"automatic\",\n sourcemap: true,\n },\n this.getCombinedSourcemap(),\n );\n },\n buildEnd(err) {\n if (!err) {\n okLog(\"React\");\n } else {\n this.error(err);\n }\n },\n };\n}\n"],"names":[],"mappings":";;;;;;AASA,MAAM,kBACJ;AAEc,SAAA,YAAY,EAAE,WAAmC;AAC/D,QAAM,aAAa;AAEf,MAAA,QAAQ,SAAS,MAAM;AAClB,WAAA;AAAA,MACL,MAAM;AAAA,MACN,UAAU,MAAM,IAAI;AAClB,YAAI,GAAG,SAAS,MAAM,KAAK,GAAG,SAAS,MAAM,GAAG;AAC9C,eAAK,MAAM,IAAI,MAAM,eAAe,CAAC;AAAA,QAAA;AAAA,MAEzC;AAAA,MACA,SAAS,KAAK;AACZ,YAAI,KAAK;AACP,gBAAM,aAAa,IAAI,QAAQ,SAAS,KAAK;AAC7C,cAAI,YAAY;AACd,iBAAK,MAAM,IAAI,MAAM,eAAe,CAAC;AAAA,UAAA;AAAA,QACvC;AAAA,MACF;AAAA,IAEJ;AAAA,EAAA;AAGK,SAAA;AAAA,IACL,MAAM;AAAA,IACN,SAAS;AAAA,IACT,MAAM,UAAU,MAAM,IAAI;AAClB,YAAA,OAAO,GAAG,SAAS,KAAK;AACxB,YAAA,QAAQ,GAAG,SAAS,MAAM;AAC1B,YAAA,QAAQ,GAAG,SAAS,MAAM;AAC5B,UAAA,EAAE,QAAQ,SAAS,QAAQ;AACtB,eAAA;AAAA,MAAA;AAGT,aAAO,MAAM;AAAA,QACX;AAAA,QACA;AAAA,QACA;AAAA,UACE,QAAQ,QAAQ,QAAQ,QAAQ;AAAA,UAChC,KAAK,QAAQ,UAAU,WAAW,cAAc;AAAA,UAChD,WAAW;AAAA,QACb;AAAA,QACA,KAAK,qBAAqB;AAAA,MAC5B;AAAA,IACF;AAAA,IACA,SAAS,KAAK;AACZ,UAAI,CAAC,KAAK;AACR,cAAM,OAAO;AAAA,MAAA,OACR;AACL,aAAK,MAAM,GAAG;AAAA,MAAA;AAAA,IAChB;AAAA,EAEJ;AACF;"}
1
+ {"version":3,"file":"index.mjs","sources":["../../../../../../src/plugins/react/index.ts"],"sourcesContent":["import type { Plugin } from \"vite\";\nimport { transformWithEsbuild } from \"vite\";\nimport { type DetectedModules } from \"../../detectModules.js\";\nimport { okLog } from \"../../log.js\";\n\ntype ReactPluginArg = {\n modules: DetectedModules;\n};\n\nconst errorJsxMessage =\n \"SmartBundle cannot find the react dependency inside dependencies, optionalDependencies or peerDependencies. Please, install it before bundling\";\n\nexport function reactPlugin({ modules }: ReactPluginArg): Plugin {\n const pluginName = \"smartbundle:react\";\n\n const reactModule = modules.react;\n if (reactModule == null) {\n return {\n name: pluginName,\n transform(code, id) {\n if (id.endsWith(\".jsx\") || id.endsWith(\".tsx\")) {\n this.error(new Error(errorJsxMessage));\n }\n },\n buildEnd(err) {\n if (err) {\n const isJsxError = err.message.includes(\"JSX\");\n if (isJsxError) {\n this.error(new Error(errorJsxMessage));\n }\n }\n },\n };\n }\n\n return {\n name: pluginName,\n enforce: \"pre\",\n async transform(code, id) {\n const isJs = id.endsWith(\".js\");\n const isJsx = id.endsWith(\".jsx\");\n const isTsx = id.endsWith(\".tsx\");\n if (!(isJs || isJsx || isTsx)) {\n return null;\n }\n\n return await transformWithEsbuild(\n code,\n id,\n {\n loader: isJs || isJsx ? \"jsx\" : \"tsx\",\n jsx: reactModule.transform === \"legacy\" ? \"transform\" : \"automatic\",\n sourcemap: true,\n },\n this.getCombinedSourcemap(),\n );\n },\n buildEnd(err) {\n if (!err) {\n okLog(\"React\");\n } else {\n this.error(err);\n }\n },\n };\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./PrettyErrors.mjs";
4
4
  import { Youch } from "youch";
5
+ import { parseMonorepo } from "./monorepo/parseMonorepo/parseMonorepo.mjs";
6
+ import { buildMonorepo } from "./monorepo/buildAll.mjs";
5
7
  const youch = new Youch();
6
8
  (async () => {
7
- const res = await run(args);
8
- if (!res.error) {
9
- return;
10
- }
11
- for (const error of res.errors) {
12
- if (!(error instanceof PrettyError)) {
9
+ try {
10
+ const sourceDir = args.sourceDir || process.cwd();
11
+ const { monorepo, projectPaths } = await parseMonorepo({ sourceDir });
12
+ if (monorepo) {
13
+ if (projectPaths.length === 0) {
14
+ throw new PrettyError(
15
+ "No packages with -sbsources suffix found in monorepo"
16
+ );
17
+ }
18
+ const result = await buildMonorepo({
19
+ ...args,
20
+ monorepo
21
+ });
22
+ if (result.failedBuilds > 0) {
23
+ for (const { packagePath, errors } of result.errors) {
24
+ console.error(`
25
+ \x1B[31mErrors in ${packagePath}:\x1B[0m`);
26
+ for (const error of errors) {
27
+ if (!(error instanceof PrettyError)) {
28
+ console.error("\x1B[31m[ERROR]", error, "\x1B[0m");
29
+ continue;
30
+ }
31
+ console.error(await youch.toANSI(error));
32
+ }
33
+ }
34
+ process.exit(1);
35
+ }
36
+ return;
37
+ }
38
+ const res = await run(args);
39
+ if (!res.error) {
40
+ return;
41
+ }
42
+ for (const error of res.errors) {
43
+ if (!(error instanceof PrettyError)) {
44
+ console.error("\x1B[31m[ERROR]", error, "\x1B[0m");
45
+ continue;
46
+ }
47
+ console.error(await youch.toANSI(error));
48
+ }
49
+ } catch (error) {
50
+ if (error instanceof PrettyError) {
51
+ console.error(await youch.toANSI(error));
52
+ } else {
13
53
  console.error("\x1B[31m[ERROR]", error, "\x1B[0m");
14
- continue;
15
54
  }
16
- console.error(await youch.toANSI(error));
55
+ process.exit(1);
17
56
  }
18
57
  })();
19
58
  //# sourceMappingURL=run.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"run.mjs","sources":["../../../../src/run.ts"],"sourcesContent":["import { args } from \"./args.js\";\nimport { run } from \"./index.js\";\nimport { PrettyError } from \"./PrettyErrors.js\";\nimport { Youch } from \"youch\";\n\nconst youch = new Youch();\n\n(async () => {\n const res = await run(args);\n\n if (!res.error) {\n return;\n }\n\n for (const error of res.errors) {\n if (!(error instanceof PrettyError)) {\n console.error(\"\\x1b[31m[ERROR]\", error, \"\\x1b[0m\");\n continue;\n }\n\n console.error(await youch.toANSI(error));\n }\n})();\n"],"names":[],"mappings":";;;;AAKA,MAAM,QAAQ,IAAI,MAAM;AAAA,CAEvB,YAAY;AACL,QAAA,MAAM,MAAM,IAAI,IAAI;AAEtB,MAAA,CAAC,IAAI,OAAO;AACd;AAAA,EAAA;AAGS,aAAA,SAAS,IAAI,QAAQ;AAC1B,QAAA,EAAE,iBAAiB,cAAc;AAC3B,cAAA,MAAM,mBAAmB,OAAO,SAAS;AACjD;AAAA,IAAA;AAGF,YAAQ,MAAM,MAAM,MAAM,OAAO,KAAK,CAAC;AAAA,EAAA;AAE3C,GAAG;"}
1
+ {"version":3,"file":"run.mjs","sources":["../../../../src/run.ts"],"sourcesContent":["import { args } from \"./args.js\";\nimport { run } from \"./index.js\";\nimport { PrettyError } from \"./PrettyErrors.js\";\nimport { Youch } from \"youch\";\nimport { parseMonorepo } from \"./monorepo/parseMonorepo/parseMonorepo.js\";\nimport { buildMonorepo } from \"./monorepo/buildAll.js\";\n\nconst youch = new Youch();\n\n(async () => {\n try {\n const sourceDir = args.sourceDir || process.cwd();\n\n // Check if we're in a monorepo\n const { monorepo, projectPaths } = await parseMonorepo({ sourceDir });\n\n if (monorepo) {\n // Handle monorepo build\n if (projectPaths.length === 0) {\n throw new PrettyError(\n \"No packages with -sbsources suffix found in monorepo\",\n );\n }\n\n const result = await buildMonorepo({\n ...args,\n monorepo,\n });\n\n // Print errors for failed packages\n if (result.failedBuilds > 0) {\n for (const { packagePath, errors } of result.errors) {\n console.error(`\\n\\x1b[31mErrors in ${packagePath}:\\x1b[0m`);\n for (const error of errors) {\n if (!(error instanceof PrettyError)) {\n console.error(\"\\x1b[31m[ERROR]\", error, \"\\x1b[0m\");\n continue;\n }\n console.error(await youch.toANSI(error));\n }\n }\n process.exit(1);\n }\n return;\n }\n\n // Not a monorepo, run normal build\n const res = await run(args);\n\n if (!res.error) {\n return;\n }\n\n for (const error of res.errors) {\n if (!(error instanceof PrettyError)) {\n console.error(\"\\x1b[31m[ERROR]\", error, \"\\x1b[0m\");\n continue;\n }\n\n console.error(await youch.toANSI(error));\n }\n } catch (error) {\n if (error instanceof PrettyError) {\n console.error(await youch.toANSI(error));\n } else {\n console.error(\"\\x1b[31m[ERROR]\", error, \"\\x1b[0m\");\n }\n process.exit(1);\n }\n})();\n"],"names":[],"mappings":";;;;;;AAOA,MAAM,QAAQ,IAAI,MAAM;AAAA,CAEvB,YAAY;AACP,MAAA;AACF,UAAM,YAAY,KAAK,aAAa,QAAQ,IAAI;AAG1C,UAAA,EAAE,UAAU,aAAa,IAAI,MAAM,cAAc,EAAE,WAAW;AAEpE,QAAI,UAAU;AAER,UAAA,aAAa,WAAW,GAAG;AAC7B,cAAM,IAAI;AAAA,UACR;AAAA,QACF;AAAA,MAAA;AAGI,YAAA,SAAS,MAAM,cAAc;AAAA,QACjC,GAAG;AAAA,QACH;AAAA,MAAA,CACD;AAGG,UAAA,OAAO,eAAe,GAAG;AAC3B,mBAAW,EAAE,aAAa,OAAO,KAAK,OAAO,QAAQ;AACnD,kBAAQ,MAAM;AAAA,oBAAuB,WAAW,UAAU;AAC1D,qBAAW,SAAS,QAAQ;AACtB,gBAAA,EAAE,iBAAiB,cAAc;AAC3B,sBAAA,MAAM,mBAAmB,OAAO,SAAS;AACjD;AAAA,YAAA;AAEF,oBAAQ,MAAM,MAAM,MAAM,OAAO,KAAK,CAAC;AAAA,UAAA;AAAA,QACzC;AAEF,gBAAQ,KAAK,CAAC;AAAA,MAAA;AAEhB;AAAA,IAAA;AAII,UAAA,MAAM,MAAM,IAAI,IAAI;AAEtB,QAAA,CAAC,IAAI,OAAO;AACd;AAAA,IAAA;AAGS,eAAA,SAAS,IAAI,QAAQ;AAC1B,UAAA,EAAE,iBAAiB,cAAc;AAC3B,gBAAA,MAAM,mBAAmB,OAAO,SAAS;AACjD;AAAA,MAAA;AAGF,cAAQ,MAAM,MAAM,MAAM,OAAO,KAAK,CAAC;AAAA,IAAA;AAAA,WAElC,OAAO;AACd,QAAI,iBAAiB,aAAa;AAChC,cAAQ,MAAM,MAAM,MAAM,OAAO,KAAK,CAAC;AAAA,IAAA,OAClC;AACG,cAAA,MAAM,mBAAmB,OAAO,SAAS;AAAA,IAAA;AAEnD,YAAQ,KAAK,CAAC;AAAA,EAAA;AAElB,GAAG;"}
@@ -11,7 +11,6 @@ async function buildTypesTask({
11
11
  packageJson,
12
12
  modules
13
13
  }) {
14
- const { outDir } = dirs;
15
14
  const tsEntrypoints = [...entrypoints.values()].filter(
16
15
  (entry) => entry.endsWith(".ts") || entry.endsWith(".tsx")
17
16
  );
@@ -30,8 +29,7 @@ async function buildTypesTask({
30
29
  ts: modules.ts,
31
30
  dirs,
32
31
  packageJson,
33
- tsEntrypoints,
34
- outDir
32
+ tsEntrypoints
35
33
  });
36
34
  for (const [source, dts] of dtsMap.sourceToEsmDtsMap) {
37
35
  const entrypoints2 = reversedEntrypoints.get(source);
@@ -1 +1 @@
1
- {"version":3,"file":"buildTypesTask.mjs","sources":["../../../../../../src/tasks/buildTypesTask/buildTypesTask.ts"],"sourcesContent":["import { callTypescript } from \"./callTypescript.js\";\nimport { reverseMap } from \"../utils.js\";\nimport { okLog } from \"../../log.js\";\nimport type { DetectedModules } from \"../../detectModules.js\";\nimport { type PackageJson } from \"../../packageJson.js\";\nimport { type Dirs } from \"../../resolveDirs.js\";\n\ntype BuildTypesTaskOption = {\n entrypoints: Map<string, string>;\n dirs: Dirs;\n modules: DetectedModules;\n packageJson: PackageJson;\n};\n\nexport async function buildTypesTask({\n entrypoints,\n dirs,\n packageJson,\n modules,\n}: BuildTypesTaskOption) {\n const { outDir } = dirs;\n const tsEntrypoints = [...entrypoints.values()].filter((entry) =>\n entry.endsWith(\".ts\") || entry.endsWith(\".tsx\"),\n );\n const reversedEntrypoints = reverseMap(entrypoints);\n\n const entrypointToEsDtsMap = new Map<string, string>();\n const entrypointToCjsDtsMap = new Map<string, string>();\n if (tsEntrypoints.length > 0 && modules.ts == null) {\n throw new Error(\n 'smartbundle found the .ts entrypoint but required \"typescript\" to build .d.ts files. Please install the \"typescript\" dependency.',\n );\n }\n if (tsEntrypoints.length === 0 || modules.ts == null) {\n return { entrypointToEsDtsMap, entrypointToCjsDtsMap };\n }\n\n const dtsMap = await callTypescript({\n ts: modules.ts,\n dirs,\n packageJson,\n tsEntrypoints,\n outDir,\n });\n\n for (const [source, dts] of dtsMap.sourceToEsmDtsMap) {\n const entrypoints = reversedEntrypoints.get(source);\n if (entrypoints) {\n for (const entrypoint of entrypoints) {\n entrypointToEsDtsMap.set(entrypoint, dts);\n }\n }\n }\n\n for (const [source, dts] of dtsMap.sourceToCjsDtsMap) {\n const entrypoints = reversedEntrypoints.get(source);\n if (entrypoints) {\n for (const entrypoint of entrypoints) {\n entrypointToCjsDtsMap.set(entrypoint, dts);\n }\n }\n }\n\n okLog(\".d.ts\");\n\n return { entrypointToEsDtsMap, entrypointToCjsDtsMap };\n}\n"],"names":["entrypoints"],"mappings":";;;;;;;AAcA,eAAsB,eAAe;AAAA,EACnC;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF,GAAyB;AACjB,QAAA,EAAE,WAAW;AACnB,QAAM,gBAAgB,CAAC,GAAG,YAAY,OAAA,CAAQ,EAAE;AAAA,IAAO,CAAC,UACtD,MAAM,SAAS,KAAK,KAAK,MAAM,SAAS,MAAM;AAAA,EAChD;AACM,QAAA,sBAAsB,WAAW,WAAW;AAE5C,QAAA,2CAA2B,IAAoB;AAC/C,QAAA,4CAA4B,IAAoB;AACtD,MAAI,cAAc,SAAS,KAAK,QAAQ,MAAM,MAAM;AAClD,UAAM,IAAI;AAAA,MACR;AAAA,IACF;AAAA,EAAA;AAEF,MAAI,cAAc,WAAW,KAAK,QAAQ,MAAM,MAAM;AAC7C,WAAA,EAAE,sBAAsB,sBAAsB;AAAA,EAAA;AAGjD,QAAA,SAAS,MAAM,eAAe;AAAA,IAClC,IAAI,QAAQ;AAAA,IACZ;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,EAAA,CACD;AAED,aAAW,CAAC,QAAQ,GAAG,KAAK,OAAO,mBAAmB;AAC9CA,UAAAA,eAAc,oBAAoB,IAAI,MAAM;AAClD,QAAIA,cAAa;AACf,iBAAW,cAAcA,cAAa;AACf,6BAAA,IAAI,YAAY,GAAG;AAAA,MAAA;AAAA,IAC1C;AAAA,EACF;AAGF,aAAW,CAAC,QAAQ,GAAG,KAAK,OAAO,mBAAmB;AAC9CA,UAAAA,eAAc,oBAAoB,IAAI,MAAM;AAClD,QAAIA,cAAa;AACf,iBAAW,cAAcA,cAAa;AACd,8BAAA,IAAI,YAAY,GAAG;AAAA,MAAA;AAAA,IAC3C;AAAA,EACF;AAGF,QAAM,OAAO;AAEN,SAAA,EAAE,sBAAsB,sBAAsB;AACvD;"}
1
+ {"version":3,"file":"buildTypesTask.mjs","sources":["../../../../../../src/tasks/buildTypesTask/buildTypesTask.ts"],"sourcesContent":["import { callTypescript } from \"./callTypescript.js\";\nimport { reverseMap } from \"../utils.js\";\nimport { okLog } from \"../../log.js\";\nimport type { DetectedModules } from \"../../detectModules.js\";\nimport { type PackageJson } from \"../../packageJson.js\";\nimport { type Dirs } from \"../../resolveDirs.js\";\n\ntype BuildTypesTaskOption = {\n entrypoints: Map<string, string>;\n dirs: Dirs;\n modules: DetectedModules;\n packageJson: PackageJson;\n};\n\nexport async function buildTypesTask({\n entrypoints,\n dirs,\n packageJson,\n modules,\n}: BuildTypesTaskOption) {\n const { outDir } = dirs;\n const tsEntrypoints = [...entrypoints.values()].filter((entry) =>\n entry.endsWith(\".ts\") || entry.endsWith(\".tsx\"),\n );\n const reversedEntrypoints = reverseMap(entrypoints);\n\n const entrypointToEsDtsMap = new Map<string, string>();\n const entrypointToCjsDtsMap = new Map<string, string>();\n if (tsEntrypoints.length > 0 && modules.ts == null) {\n throw new Error(\n 'smartbundle found the .ts entrypoint but required \"typescript\" to build .d.ts files. Please install the \"typescript\" dependency.',\n );\n }\n if (tsEntrypoints.length === 0 || modules.ts == null) {\n return { entrypointToEsDtsMap, entrypointToCjsDtsMap };\n }\n\n const dtsMap = await callTypescript({\n ts: modules.ts,\n dirs,\n packageJson,\n tsEntrypoints,\n outDir,\n });\n\n for (const [source, dts] of dtsMap.sourceToEsmDtsMap) {\n const entrypoints = reversedEntrypoints.get(source);\n if (entrypoints) {\n for (const entrypoint of entrypoints) {\n entrypointToEsDtsMap.set(entrypoint, dts);\n }\n }\n }\n\n for (const [source, dts] of dtsMap.sourceToCjsDtsMap) {\n const entrypoints = reversedEntrypoints.get(source);\n if (entrypoints) {\n for (const entrypoint of entrypoints) {\n entrypointToCjsDtsMap.set(entrypoint, dts);\n }\n }\n }\n\n okLog(\".d.ts\");\n\n return { entrypointToEsDtsMap, entrypointToCjsDtsMap };\n}\n"],"names":["entrypoints"],"mappings":";;;;;;;AAcA,eAAsB,eAAe;AAAA,EACnC;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF,GAAyB;AAEvB,QAAM,gBAAgB,CAAC,GAAG,YAAY,OAAA,CAAQ,EAAE;AAAA,IAAO,CAAC,UACtD,MAAM,SAAS,KAAK,KAAK,MAAM,SAAS,MAAM;AAAA,EAChD;AACM,QAAA,sBAAsB,WAAW,WAAW;AAE5C,QAAA,2CAA2B,IAAoB;AAC/C,QAAA,4CAA4B,IAAoB;AACtD,MAAI,cAAc,SAAS,KAAK,QAAQ,MAAM,MAAM;AAClD,UAAM,IAAI;AAAA,MACR;AAAA,IACF;AAAA,EAAA;AAEF,MAAI,cAAc,WAAW,KAAK,QAAQ,MAAM,MAAM;AAC7C,WAAA,EAAE,sBAAsB,sBAAsB;AAAA,EAAA;AAGjD,QAAA,SAAS,MAAM,eAAe;AAAA,IAClC,IAAI,QAAQ;AAAA,IACZ;AAAA,IACA;AAAA,IACA;AAAA,EAEF,CAAC;AAED,aAAW,CAAC,QAAQ,GAAG,KAAK,OAAO,mBAAmB;AAC9CA,UAAAA,eAAc,oBAAoB,IAAI,MAAM;AAClD,QAAIA,cAAa;AACf,iBAAW,cAAcA,cAAa;AACf,6BAAA,IAAI,YAAY,GAAG;AAAA,MAAA;AAAA,IAC1C;AAAA,EACF;AAGF,aAAW,CAAC,QAAQ,GAAG,KAAK,OAAO,mBAAmB;AAC9CA,UAAAA,eAAc,oBAAoB,IAAI,MAAM;AAClD,QAAIA,cAAa;AACf,iBAAW,cAAcA,cAAa;AACd,8BAAA,IAAI,YAAY,GAAG;AAAA,MAAA;AAAA,IAC3C;AAAA,EACF;AAGF,QAAM,OAAO;AAEN,SAAA,EAAE,sBAAsB,sBAAsB;AACvD;"}
@@ -1,8 +1,8 @@
1
1
  import { type PackageJson } from "../../packageJson.js";
2
- import { type TS } from "../../detectModules.js";
2
+ import { type TSModule } from "../../detectModules.js";
3
3
  import { type Dirs } from "../../resolveDirs.js";
4
4
  type BuildTypesOptions = {
5
- ts: TS;
5
+ ts: TSModule;
6
6
  dirs: Dirs;
7
7
  packageJson: PackageJson;
8
8
  tsEntrypoints: string[];
@@ -1 +1 @@
1
- {"version":3,"file":"callTypescript.mjs","sources":["../../../../../../src/tasks/buildTypesTask/callTypescript.ts"],"sourcesContent":["import * as path from \"node:path\";\nimport * as fs from \"node:fs\";\nimport {\n inlineExtensionsMjs,\n inlineExtensionsCjs,\n} from \"./inlineExtensions.js\";\nimport { type PackageJson } from \"../../packageJson.js\";\nimport { getMinVersion, type TS } from \"../../detectModules.js\";\nimport { BuildError } from \"../../error.js\";\nimport { findTypingsPackages } from \"./findTypingsPackages.js\";\nimport { findTypingsNames } from \"./findTypingsNames.js\";\nimport { type Dirs } from \"../../resolveDirs.js\";\n\ntype BuildTypesOptions = {\n ts: TS;\n dirs: Dirs;\n packageJson: PackageJson;\n tsEntrypoints: string[];\n outDir: string;\n};\n\nfunction makeFileExists(outDir: string, filePath: string) {\n return (p: string) => {\n const dir = path.join(outDir, path.dirname(filePath));\n return fs.existsSync(path.join(dir, p));\n };\n}\n\nexport async function callTypescript({\n ts,\n dirs,\n tsEntrypoints,\n packageJson,\n}: BuildTypesOptions) {\n const { sourceDir, outDir, esmOutDir, cjsOutDir } = dirs;\n\n // <build d.ts>\n const sourceToCjsDtsMap = new Map<string, string>();\n const sourceToEsmDtsMap = new Map<string, string>();\n const program = ts.ts.createProgram(\n tsEntrypoints,\n ts.parsedConfig.options,\n ts.host,\n );\n program.emit(undefined, (fileName, data) => {\n // .d.ts for cjs because \"type\": \"commonjs\" in package.json\n // .d.mts for esm\n const relativePath = path.relative(sourceDir, fileName);\n // we create maps for ts and tsx because it can have any of these extensions\n // I don't want to detect the original ext,\n // so I've decided just create two maps and calculate the original file name outside of this function\n const sourceFileNameTS = fileName.replace(/\\.d\\.ts$/, \".ts\"); // Assuming source files have .ts extension\n const sourceFileNameTSX = fileName.replace(/\\.d\\.ts$/, \".tsx\"); // Assuming source files have .ts extension\n\n const finalEsmPath = path.join(esmOutDir, relativePath);\n const esmFinalPath = finalEsmPath.replace(/\\.d\\.ts$/, \".d.mts\");\n sourceToEsmDtsMap.set(sourceFileNameTS, esmFinalPath);\n sourceToEsmDtsMap.set(sourceFileNameTSX, esmFinalPath);\n fs.mkdirSync(path.dirname(esmFinalPath), { recursive: true });\n fs.writeFileSync(esmFinalPath, data);\n\n const finalCjsPath = path.join(cjsOutDir, relativePath);\n fs.mkdirSync(path.dirname(finalCjsPath), { recursive: true });\n const cjsFinalPath = finalCjsPath;\n fs.writeFileSync(cjsFinalPath, data);\n sourceToCjsDtsMap.set(sourceFileNameTS, cjsFinalPath);\n sourceToCjsDtsMap.set(sourceFileNameTSX, cjsFinalPath);\n });\n // </build d.ts>\n\n // <fix vscode typings>\n for (const file of [\n ...sourceToCjsDtsMap.values(),\n ...sourceToEsmDtsMap.values(),\n ]) {\n const content = fs.readFileSync(file, \"utf-8\");\n const relativePath = path.relative(outDir, file);\n if (file.endsWith(\".d.ts\")) {\n const transformedCode = inlineExtensionsCjs(\n ts.ts,\n content,\n makeFileExists(outDir, relativePath),\n );\n fs.writeFileSync(file, transformedCode);\n }\n if (file.endsWith(\".d.mts\")) {\n const transformedCode = inlineExtensionsMjs(\n ts.ts,\n content,\n makeFileExists(outDir, relativePath),\n );\n fs.writeFileSync(file, transformedCode);\n }\n }\n // </fix vscode typings>\n\n // <find all libraries names>\n const packages = new Set<string>();\n for (const sourceEntrypoint of tsEntrypoints) {\n const esmEntrypoint = sourceToEsmDtsMap.get(sourceEntrypoint);\n if (esmEntrypoint) {\n const localPackages = findTypingsNames(\n ts,\n esmEntrypoint,\n esmOutDir,\n \".d.mts\",\n );\n for (const p of localPackages) {\n packages.add(p);\n }\n }\n\n const cjsEntrypoint = sourceToCjsDtsMap.get(sourceEntrypoint);\n if (cjsEntrypoint) {\n const localPackages = findTypingsNames(\n ts,\n cjsEntrypoint,\n cjsOutDir,\n \".d.ts\",\n );\n for (const p of localPackages) {\n packages.add(p);\n }\n }\n }\n // </find all libraries names>\n\n // <check not installed typings libraries>\n const { missingTypings, existingTypingPackages } = findTypingsPackages(\n ts,\n packages,\n sourceDir,\n );\n for (const lib of existingTypingPackages) {\n if (\n getMinVersion(packageJson, lib, [\n \"optionalDependencies\",\n \"devDependencies\",\n ]) == null\n ) {\n missingTypings.add(lib);\n }\n }\n if (missingTypings.size > 0) {\n const libsList = [...missingTypings].map((x) => `\"${x}\"`).join(\", \");\n throw new BuildError(\n `The typings won't installed in bundled package: ${libsList}. Please install them into dependencies or peerDependencies.`,\n );\n }\n // </check not installed typings libraries>\n\n return {\n sourceToCjsDtsMap,\n sourceToEsmDtsMap,\n };\n}\n"],"names":[],"mappings":";;;;;;;;;;AAqBA,SAAS,eAAe,QAAgB,UAAkB;AACxD,SAAO,CAAC,MAAc;AAC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E,KAAK,IAAI;AACnE,UAAM,IAAI;AAAA,MACR,mDAAmD,QAAQ;AAAA,IAC7D;AAAA,EAAA;AAIK,SAAA;AAAA,IACL;AAAA,IACA;AAAA,EACF;AACF;"}
1
+ {"version":3,"file":"callTypescript.mjs","sources":["../../../../../../src/tasks/buildTypesTask/callTypescript.ts"],"sourcesContent":["import * as path from \"node:path\";\nimport * as fs from \"node:fs\";\nimport {\n inlineExtensionsMjs,\n inlineExtensionsCjs,\n} from \"./inlineExtensions.js\";\nimport { type PackageJson } from \"../../packageJson.js\";\nimport { getMinVersion, type TSModule } from \"../../detectModules.js\";\nimport { BuildError } from \"../../error.js\";\nimport { findTypingsPackages } from \"./findTypingsPackages.js\";\nimport { findTypingsNames } from \"./findTypingsNames.js\";\nimport { type Dirs } from \"../../resolveDirs.js\";\n\ntype BuildTypesOptions = {\n ts: TSModule;\n dirs: Dirs;\n packageJson: PackageJson;\n tsEntrypoints: string[];\n outDir: string;\n};\n\nfunction makeFileExists(outDir: string, filePath: string) {\n return (p: string) => {\n const dir = path.join(outDir, path.dirname(filePath));\n return fs.existsSync(path.join(dir, p));\n };\n}\n\nexport async function callTypescript({\n ts,\n dirs,\n tsEntrypoints,\n packageJson,\n}: BuildTypesOptions) {\n const { sourceDir, outDir, esmOutDir, cjsOutDir } = dirs;\n\n // <build d.ts>\n const sourceToCjsDtsMap = new Map<string, string>();\n const sourceToEsmDtsMap = new Map<string, string>();\n const program = ts.ts.createProgram(\n tsEntrypoints,\n ts.parsedConfig.options,\n ts.host,\n );\n program.emit(undefined, (fileName, data) => {\n // .d.ts for cjs because \"type\": \"commonjs\" in package.json\n // .d.mts for esm\n const relativePath = path.relative(sourceDir, fileName);\n // we create maps for ts and tsx because it can have any of these extensions\n // I don't want to detect the original ext,\n // so I've decided just create two maps and calculate the original file name outside of this function\n const sourceFileNameTS = fileName.replace(/\\.d\\.ts$/, \".ts\"); // Assuming source files have .ts extension\n const sourceFileNameTSX = fileName.replace(/\\.d\\.ts$/, \".tsx\"); // Assuming source files have .ts extension\n\n const finalEsmPath = path.join(esmOutDir, relativePath);\n const esmFinalPath = finalEsmPath.replace(/\\.d\\.ts$/, \".d.mts\");\n sourceToEsmDtsMap.set(sourceFileNameTS, esmFinalPath);\n sourceToEsmDtsMap.set(sourceFileNameTSX, esmFinalPath);\n fs.mkdirSync(path.dirname(esmFinalPath), { recursive: true });\n fs.writeFileSync(esmFinalPath, data);\n\n const finalCjsPath = path.join(cjsOutDir, relativePath);\n fs.mkdirSync(path.dirname(finalCjsPath), { recursive: true });\n const cjsFinalPath = finalCjsPath;\n fs.writeFileSync(cjsFinalPath, data);\n sourceToCjsDtsMap.set(sourceFileNameTS, cjsFinalPath);\n sourceToCjsDtsMap.set(sourceFileNameTSX, cjsFinalPath);\n });\n // </build d.ts>\n\n // <fix vscode typings>\n for (const file of [\n ...sourceToCjsDtsMap.values(),\n ...sourceToEsmDtsMap.values(),\n ]) {\n const content = fs.readFileSync(file, \"utf-8\");\n const relativePath = path.relative(outDir, file);\n if (file.endsWith(\".d.ts\")) {\n const transformedCode = inlineExtensionsCjs(\n ts.ts,\n content,\n makeFileExists(outDir, relativePath),\n );\n fs.writeFileSync(file, transformedCode);\n }\n if (file.endsWith(\".d.mts\")) {\n const transformedCode = inlineExtensionsMjs(\n ts.ts,\n content,\n makeFileExists(outDir, relativePath),\n );\n fs.writeFileSync(file, transformedCode);\n }\n }\n // </fix vscode typings>\n\n // <find all libraries names>\n const packages = new Set<string>();\n for (const sourceEntrypoint of tsEntrypoints) {\n const esmEntrypoint = sourceToEsmDtsMap.get(sourceEntrypoint);\n if (esmEntrypoint) {\n const localPackages = findTypingsNames(\n ts,\n esmEntrypoint,\n esmOutDir,\n \".d.mts\",\n );\n for (const p of localPackages) {\n packages.add(p);\n }\n }\n\n const cjsEntrypoint = sourceToCjsDtsMap.get(sourceEntrypoint);\n if (cjsEntrypoint) {\n const localPackages = findTypingsNames(\n ts,\n cjsEntrypoint,\n cjsOutDir,\n \".d.ts\",\n );\n for (const p of localPackages) {\n packages.add(p);\n }\n }\n }\n // </find all libraries names>\n\n // <check not installed typings libraries>\n const { missingTypings, existingTypingPackages } = findTypingsPackages(\n ts,\n packages,\n sourceDir,\n );\n for (const lib of existingTypingPackages) {\n if (\n getMinVersion(packageJson, lib, [\n \"optionalDependencies\",\n \"devDependencies\",\n ]) == null\n ) {\n missingTypings.add(lib);\n }\n }\n if (missingTypings.size > 0) {\n const libsList = [...missingTypings].map((x) => `\"${x}\"`).join(\", \");\n throw new BuildError(\n `The typings won't installed in bundled package: ${libsList}. Please install them into dependencies or peerDependencies.`,\n );\n }\n // </check not installed typings libraries>\n\n return {\n sourceToCjsDtsMap,\n sourceToEsmDtsMap,\n };\n}\n"],"names":[],"mappings":";;;;;;;;;;AAqBA,SAAS,eAAe,QAAgB,UAAkB;AACxD,SAAO,CAAC,MAAc;AACpB,UAAM,MAAM,KAAK,KAAK,QAAQ,KAAK,QAAQ,QAAQ,CAAC;AACpD,WAAO,GAAG,WAAW,KAAK,KAAK,KAAK,CAAC,CAAC;AAAA,EACxC;AACF;AAEA,eAAsB,eAAe;AAAA,EACnC;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF,GAAsB;AACpB,QAAM,EAAE,WAAW,QAAQ,WAAW,UAAc,IAAA;AAG9C,QAAA,wCAAwB,IAAoB;AAC5C,QAAA,wCAAwB,IAAoB;AAC5C,QAAA,UAAU,GAAG,GAAG;AAAA,IACpB;AAAA,IACA,GAAG,aAAa;AAAA,IAChB,GAAG;AAAA,EACL;AACA,UAAQ,KAAK,QAAW,CAAC,UAAU,SAAS;AAG1C,UAAM,eAAe,KAAK,SAAS,WAAW,QAAQ;AAItD,UAAM,mBAAmB,SAAS,QAAQ,YAAY,KAAK;AAC3D,UAAM,oBAAoB,SAAS,QAAQ,YAAY,MAAM;AAE7D,UAAM,eAAe,KAAK,KAAK,WAAW,YAAY;AACtD,UAAM,eAAe,aAAa,QAAQ,YAAY,QAAQ;AAC5C,sBAAA,I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gB;AAC5D,QAAI,eAAe;AACjB,YAAM,gBAAgB;AAAA,QACpB;AAAA,QACA;AAAA,QACA;AAAA,QACA;AAAA,MACF;AACA,iBAAW,KAAK,eAAe;AAC7B,iBAAS,IAAI,CAAC;AAAA,MAAA;AAAA,IAChB;AAAA,EACF;AAKI,QAAA,EAAE,gBAAgB,uBAAA,IAA2B;AAAA,IACjD;AAAA,IACA;AAAA,IACA;AAAA,EACF;AACA,aAAW,OAAO,wBAAwB;AAEtC,QAAA,cAAc,aAAa,KAAK;AAAA,MAC9B;AAAA,MACA;AAAA,IACD,CAAA,KAAK,MACN;AACA,qBAAe,IAAI,GAAG;AAAA,IAAA;AAAA,EACxB;AAEE,MAAA,eAAe,OAAO,GAAG;AAC3B,UAAM,WAAW,CAAC,GAAG,cAAc,EAAE,IAAI,CAAC,MAAM,IAAI,CAAC,GAAG,EAAE,KAAK,IAAI;AACnE,UAAM,IAAI;AAAA,MACR,mDAAmD,QAAQ;AAAA,IAC7D;AAAA,EAAA;AAIK,SAAA;AAAA,IACL;AAAA,IACA;AAAA,EACF;AACF;"}
@@ -1,2 +1,2 @@
1
- import type { TS } from "../../detectModules.js";
2
- export declare function findTypingsNames({ ts }: TS, entrypoint: string, sourceDir: string, ext: string): Set<string>;
1
+ import type { TSModule } from "../../detectModules.js";
2
+ export declare function findTypingsNames({ ts }: TSModule, entrypoint: string, sourceDir: string, ext: string): Set<string>;
@@ -1 +1 @@
1
- {"version":3,"file":"findTypingsNames.mjs","sources":["../../../../../../src/tasks/buildTypesTask/findTypingsNames.ts"],"sourcesContent":["import type * as ts from \"typescript\";\nimport { join, relative } from \"node:path\";\nimport { readdirSync, statSync } from \"node:fs\";\nimport type { TS } from \"../../detectModules.js\";\n\nfunction createCompilerHostWithVirtualSource(ts: TS[\"ts\"], sourceDir: string) {\n return ts.createCompilerHost({\n target: ts.ScriptTarget.ESNext,\n moduleResolution: ts.ModuleResolutionKind.NodeNext,\n baseUrl: \".\",\n sourceRoot: sourceDir,\n noEmit: true,\n emitDeclarationOnly: true,\n noEmitOnError: true,\n });\n}\n\n/*\nChatGPT told me we need to specify all files in rootNames for the program to work correctly.\n */\nfunction collectAllFilesInDir(sourceDir: string, ext: string) {\n const files = readdirSync(sourceDir);\n const ret = new Array<string>();\n for (const file of files) {\n // check if the file is a directory\n const stat = statSync(join(sourceDir, file));\n if (stat.isDirectory()) {\n ret.push(...collectAllFilesInDir(join(sourceDir, file), ext));\n } else if (file.endsWith(ext)) {\n ret.push(join(sourceDir, file));\n }\n }\n\n return ret;\n}\n\nexport function findTypingsNames(\n { ts }: TS,\n entrypoint: string,\n sourceDir: string,\n ext: string,\n) {\n const host = createCompilerHostWithVirtualSource(ts, sourceDir);\n const program = ts.createProgram({\n rootNames: collectAllFilesInDir(sourceDir, ext),\n options: {},\n host,\n });\n\n const packages = new Set<string>();\n const processedFiles = new Set<string>();\n const filesQueue = [relative(sourceDir, entrypoint)];\n\n function processModuleSpecifier(moduleSpecifier: ts.StringLiteral) {\n const moduleName = moduleSpecifier.text;\n if (moduleName.startsWith(\".\")) {\n filesQueue.push(moduleName.replace(/\\.js$/, ext));\n return;\n }\n\n packages.add(moduleName);\n }\n\n while (filesQueue.length > 0) {\n const relativeCurrentFile = filesQueue.pop()!;\n const currentFile = join(sourceDir, relativeCurrentFile);\n if (processedFiles.has(currentFile)) continue;\n\n const sourceFile = program.getSourceFile(currentFile);\n if (!sourceFile) continue;\n\n function visit(node: ts.Node) {\n // import \"moduleSpecifier\";\n if (\n ts.isImportDeclaration(node) &&\n ts.isStringLiteral(node.moduleSpecifier)\n ) {\n processModuleSpecifier(node.moduleSpecifier);\n }\n\n // Generic<import(\"node\")>;\n if (\n ts.isImportTypeNode(node) &&\n ts.isLiteralTypeNode(node.argument) &&\n ts.isStringLiteral(node.argument.literal)\n ) {\n processModuleSpecifier(node.argument.literal);\n }\n\n // export * from \"moduleSpecifier\";\n if (\n ts.isExportDeclaration(node) &&\n node.moduleSpecifier &&\n ts.isStringLiteral(node.moduleSpecifier)\n ) {\n processModuleSpecifier(node.moduleSpecifier);\n }\n\n ts.forEachChild(node, visit);\n }\n\n processedFiles.add(currentFile);\n\n ts.forEachChild(sourceFile, visit);\n }\n\n return packages;\n}\n"],"names":[],"mappings":";;AAKA,SAAS,oCAAoC,IAAc,WAAmB;AAC5E,SAAO,GAAG,mBAAmB;AAAA,IAC3B,QAAQ,GAAG,aAAa;AAAA,IACxB,kBAAkB,GAAG,qBAAqB;AAAA,IAC1C,SAAS;AAAA,IACT,YAAY;AAAA,IACZ,QAAQ;AAAA,IACR,qBAAqB;AAAA,IACrB,eAAe;AAAA,EAAA,CAChB;AACH;AAKA,SAAS,qBAAqB,WAAmB,KAAa;AACtD,QAAA,QAAQ,YAAY,SAAS;AAC7B,QAAA,MAAM,IAAI,MAAc;AAC9B,aAAW,QAAQ,OAAO;AAExB,UAAM,OAAO,SAAS,KAAK,WAAW,IAAI,CAAC;AACvC,QAAA,KAAK,eAAe;AAClB,UAAA,KAAK,GAAG,qBAAqB,KAAK,WAAW,IAAI,GAAG,GAAG,CAAC;AAAA,IACnD,WAAA,KAAK,SAAS,GAAG,GAAG;AAC7B,UAAI,KAAK,KAAK,WAAW,IAAI,CAAC;AAAA,IAAA;AAAA,EAChC;AAGK,SAAA;AACT;AAEO,SAAS,iBACd,EAAE,GAAA,GACF,YACA,WACA,KACA;AACM,QAAA,OAAO,oCAAoC,IAAI,SAAS;AACxD,QAAA,UAAU,GAAG,cAAc;AAAA,IAC/B,WAAW,qBAAqB,WAAW,GAAG;AAAA,IAC9C,SAAS,CAAC;AAAA,IACV;AAAA,EAAA,CACD;AAEK,QAAA,+BAAe,IAAY;AAC3B,QAAA,qCAAqB,IAAY;AACvC,QAAM,aAAa,CAAC,SAAS,WAAW,UAAU,CAAC;AAEnD,WAAS,uBAAuB,iBAAmC;AACjE,UAAM,aAAa,gBAAgB;AAC/B,QAAA,WAAW,WAAW,GAAG,GAAG;AAC9B,iBAAW,KAAK,WAAW,QAAQ,SAAS,GAAG,CAAC;AAChD;AAAA,IAAA;AAGF,aAAS,IAAI,UAAU;AAAA,EAAA;AAGlB,SAAA,WAAW,SAAS,GAAG;AAQnB,QAAA,QAAT,SAAe,MAAe;AAG1B,UAAA,GAAG,oBAAoB,IAAI,KAC3B,GAAG,gBAAgB,KAAK,eAAe,GACvC;AACA,+BAAuB,KAAK,eAAe;AAAA,MAAA;AAI7C,UACE,GAAG,iBAAiB,IAAI,KACxB,GAAG,kBAAkB,KAAK,QAAQ,KAClC,GAAG,gBAAgB,KAAK,SAAS,OAAO,GACxC;AACuB,+BAAA,KAAK,SAAS,OAAO;AAAA,MAAA;AAK5C,UAAA,GAAG,oBAAoB,IAAI,KAC3B,KAAK,mBACL,GAAG,gBAAgB,KAAK,eAAe,GACvC;AACA,+BAAuB,KAAK,eAAe;AAAA,MAAA;AAG1C,SAAA,aAAa,MAAM,KAAK;AAAA,IAC7B;AAnCM,UAAA,sBAAsB,WAAW,IAAI;AACrC,UAAA,cAAc,KAAK,WAAW,mBAAmB;AACnD,QAAA,eAAe,IAAI,WAAW,EAAG;AAE/B,UAAA,aAAa,QAAQ,cAAc,WAAW;AACpD,QAAI,CAAC,WAAY;AAgCjB,mBAAe,IAAI,WAAW;AAE3B,OAAA,aAAa,YAAY,KAAK;AAAA,EAAA;AAG5B,SAAA;AACT;"}
1
+ {"version":3,"file":"findTypingsNames.mjs","sources":["../../../../../../src/tasks/buildTypesTask/findTypingsNames.ts"],"sourcesContent":["import type * as ts from \"typescript\";\nimport { join, relative } from \"node:path\";\nimport { readdirSync, statSync } from \"node:fs\";\nimport type { TSModule } from \"../../detectModules.js\";\n\nfunction createCompilerHostWithVirtualSource(ts: TSModule[\"ts\"], sourceDir: string) {\n return ts.createCompilerHost({\n target: ts.ScriptTarget.ESNext,\n moduleResolution: ts.ModuleResolutionKind.NodeNext,\n baseUrl: \".\",\n sourceRoot: sourceDir,\n noEmit: true,\n emitDeclarationOnly: true,\n noEmitOnError: true,\n });\n}\n\n/*\nChatGPT told me we need to specify all files in rootNames for the program to work correctly.\n */\nfunction collectAllFilesInDir(sourceDir: string, ext: string) {\n const files = readdirSync(sourceDir);\n const ret = new Array<string>();\n for (const file of files) {\n // check if the file is a directory\n const stat = statSync(join(sourceDir, file));\n if (stat.isDirectory()) {\n ret.push(...collectAllFilesInDir(join(sourceDir, file), ext));\n } else if (file.endsWith(ext)) {\n ret.push(join(sourceDir, file));\n }\n }\n\n return ret;\n}\n\nexport function findTypingsNames(\n { ts }: TSModule,\n entrypoint: string,\n sourceDir: string,\n ext: string,\n) {\n const host = createCompilerHostWithVirtualSource(ts, sourceDir);\n const program = ts.createProgram({\n rootNames: collectAllFilesInDir(sourceDir, ext),\n options: {},\n host,\n });\n\n const packages = new Set<string>();\n const processedFiles = new Set<string>();\n const filesQueue = [relative(sourceDir, entrypoint)];\n\n function processModuleSpecifier(moduleSpecifier: ts.StringLiteral) {\n const moduleName = moduleSpecifier.text;\n if (moduleName.startsWith(\".\")) {\n filesQueue.push(moduleName.replace(/\\.js$/, ext));\n return;\n }\n\n packages.add(moduleName);\n }\n\n while (filesQueue.length > 0) {\n const relativeCurrentFile = filesQueue.pop()!;\n const currentFile = join(sourceDir, relativeCurrentFile);\n if (processedFiles.has(currentFile)) continue;\n\n const sourceFile = program.getSourceFile(currentFile);\n if (!sourceFile) continue;\n\n function visit(node: ts.Node) {\n // import \"moduleSpecifier\";\n if (\n ts.isImportDeclaration(node) &&\n ts.isStringLiteral(node.moduleSpecifier)\n ) {\n processModuleSpecifier(node.moduleSpecifier);\n }\n\n // Generic<import(\"node\")>;\n if (\n ts.isImportTypeNode(node) &&\n ts.isLiteralTypeNode(node.argument) &&\n ts.isStringLiteral(node.argument.literal)\n ) {\n processModuleSpecifier(node.argument.literal);\n }\n\n // export * from \"moduleSpecifier\";\n if (\n ts.isExportDeclaration(node) &&\n node.moduleSpecifier &&\n ts.isStringLiteral(node.moduleSpecifier)\n ) {\n processModuleSpecifier(node.moduleSpecifier);\n }\n\n ts.forEachChild(node, visit);\n }\n\n processedFiles.add(currentFile);\n\n ts.forEachChild(sourceFile, visit);\n }\n\n return packages;\n}\n"],"names":[],"mappings":";;AAKA,SAAS,oCAAoC,IAAoB,WAAmB;AAClF,SAAO,GAAG,mBAAmB;AAAA,IAC3B,QAAQ,GAAG,aAAa;AAAA,IACxB,kBAAkB,GAAG,qBAAqB;AAAA,IAC1C,SAAS;AAAA,IACT,YAAY;AAAA,IACZ,QAAQ;AAAA,IACR,qBAAqB;AAAA,IACrB,eAAe;AAAA,EAAA,CAChB;AACH;AAKA,SAAS,qBAAqB,WAAmB,KAAa;AACtD,QAAA,QAAQ,YAAY,SAAS;AAC7B,QAAA,MAAM,IAAI,MAAc;AAC9B,aAAW,QAAQ,OAAO;AAExB,UAAM,OAAO,SAAS,KAAK,WAAW,IAAI,CAAC;AACvC,QAAA,KAAK,eAAe;AAClB,UAAA,KAAK,GAAG,qBAAqB,KAAK,WAAW,IAAI,GAAG,GAAG,CAAC;AAAA,IACnD,WAAA,KAAK,SAAS,GAAG,GAAG;AAC7B,UAAI,KAAK,KAAK,WAAW,IAAI,CAAC;AAAA,IAAA;AAAA,EAChC;AAGK,SAAA;AACT;AAEO,SAAS,iBACd,EAAE,GAAA,GACF,YACA,WACA,KACA;AACM,QAAA,OAAO,oCAAoC,IAAI,SAAS;AACxD,QAAA,UAAU,GAAG,cAAc;AAAA,IAC/B,WAAW,qBAAqB,WAAW,GAAG;AAAA,IAC9C,SAAS,CAAC;AAAA,IACV;AAAA,EAAA,CACD;AAEK,QAAA,+BAAe,IAAY;AAC3B,QAAA,qCAAqB,IAAY;AACvC,QAAM,aAAa,CAAC,SAAS,WAAW,UAAU,CAAC;AAEnD,WAAS,uBAAuB,iBAAmC;AACjE,UAAM,aAAa,gBAAgB;AAC/B,QAAA,WAAW,WAAW,GAAG,GAAG;AAC9B,iBAAW,KAAK,WAAW,QAAQ,SAAS,GAAG,CAAC;AAChD;AAAA,IAAA;AAGF,aAAS,IAAI,UAAU;AAAA,EAAA;AAGlB,SAAA,WAAW,SAAS,GAAG;AAQnB,QAAA,QAAT,SAAe,MAAe;AAG1B,UAAA,GAAG,oBAAoB,IAAI,KAC3B,GAAG,gBAAgB,KAAK,eAAe,GACvC;AACA,+BAAuB,KAAK,eAAe;AAAA,MAAA;AAI7C,UACE,GAAG,iBAAiB,IAAI,KACxB,GAAG,kBAAkB,KAAK,QAAQ,KAClC,GAAG,gBAAgB,KAAK,SAAS,OAAO,GACxC;AACuB,+BAAA,KAAK,SAAS,OAAO;AAAA,MAAA;AAK5C,UAAA,GAAG,oBAAoB,IAAI,KAC3B,KAAK,mBACL,GAAG,gBAAgB,KAAK,eAAe,GACvC;AACA,+BAAuB,KAAK,eAAe;AAAA,MAAA;AAG1C,SAAA,aAAa,MAAM,KAAK;AAAA,IAC7B;AAnCM,UAAA,sBAAsB,WAAW,IAAI;AACrC,UAAA,cAAc,KAAK,WAAW,mBAAmB;AACnD,QAAA,eAAe,IAAI,WAAW,EAAG;AAE/B,UAAA,aAAa,QAAQ,cAAc,WAAW;AACpD,QAAI,CAAC,WAAY;AAgCjB,mBAAe,IAAI,WAAW;AAE3B,OAAA,aAAa,YAAY,KAAK;AAAA,EAAA;AAG5B,SAAA;AACT;"}
@@ -1,5 +1,5 @@
1
- import type { TS } from "../../detectModules.js";
2
- export declare function findTypingsPackages({ ts }: TS, packages: Set<string>, sourceDir: string): {
1
+ import type { TSModule } from "../../detectModules.js";
2
+ export declare function findTypingsPackages({ ts }: TSModule, packages: Set<string>, sourceDir: string): {
3
3
  missingTypings: Set<string>;
4
4
  existingTypingPackages: Set<string>;
5
5
  };
@@ -1 +1 @@
1
- {"version":3,"file":"findTypingsPackages.mjs","sources":["../../../../../../src/tasks/buildTypesTask/findTypingsPackages.ts"],"sourcesContent":["import type * as ts from \"typescript\";\nimport * as path from \"node:path\";\nimport type { TS } from \"../../detectModules.js\";\n\ntype HostFunctions = {\n getSourceFile: ts.CompilerHost[\"getSourceFile\"];\n fileExists: ts.CompilerHost[\"fileExists\"];\n readFile: ts.CompilerHost[\"readFile\"];\n};\n\nfunction createVirtualHostFunctions(\n ts: TS[\"ts\"],\n virtualFilePath: string,\n virtualSourceContent: string,\n originalHost: ts.CompilerHost,\n): HostFunctions {\n const getSourceFile: ts.CompilerHost[\"getSourceFile\"] = (\n fileName,\n languageVersion,\n ) => {\n if (fileName === virtualFilePath) {\n return ts.createSourceFile(\n fileName,\n virtualSourceContent,\n languageVersion,\n );\n }\n return originalHost.getSourceFile(fileName, languageVersion);\n };\n\n const fileExists: ts.CompilerHost[\"fileExists\"] = (fileName) => {\n if (fileName === virtualFilePath) {\n return true;\n }\n return originalHost.fileExists(fileName);\n };\n\n const readFile: ts.CompilerHost[\"readFile\"] = (fileName) => {\n if (fileName === virtualFilePath) {\n return virtualSourceContent;\n }\n return originalHost.readFile(fileName);\n };\n\n return {\n getSourceFile,\n fileExists,\n readFile,\n };\n}\n\nfunction createCompilerHostWithVirtualSource(\n ts: TS[\"ts\"],\n packages: Set<string>,\n sourceDir: string,\n) {\n const virtualSourceContent =\n [...packages].map((p) => `import \"${p}\";`).join(\"\\n\") +\n // for ignoring the `Generated an empty chunk: \".\"` error\n \"export const a = 1;\\n\";\n const virtualFilePath = path.join(sourceDir, \"virtual.ts\");\n\n const originalHost = ts.createCompilerHost({\n target: ts.ScriptTarget.ESNext,\n moduleResolution: ts.ModuleResolutionKind.NodeNext,\n baseUrl: \".\",\n sourceRoot: sourceDir,\n noEmit: true,\n emitDeclarationOnly: true,\n noEmitOnError: true,\n paths: {\n \"*\": [\"node_modules/*\"],\n },\n });\n const virtualFunctions = createVirtualHostFunctions(\n ts,\n virtualFilePath,\n virtualSourceContent,\n originalHost,\n );\n\n return {\n host: new Proxy(originalHost, {\n get(target, prop: keyof ts.CompilerHost) {\n return virtualFunctions[prop as keyof HostFunctions] || target[prop];\n },\n }),\n virtualFilePath,\n };\n}\n\nexport function findTypingsPackages(\n { ts }: TS,\n packages: Set<string>,\n sourceDir: string,\n) {\n const { host, virtualFilePath } = createCompilerHostWithVirtualSource(\n ts,\n packages,\n sourceDir,\n );\n\n const program = ts.createProgram({\n rootNames: [virtualFilePath],\n options: {},\n host: host,\n });\n\n const sourceFile = program.getSourceFile(virtualFilePath);\n if (!sourceFile) {\n throw new Error(\n \"[getSourceFile] Impossible error inside findMissingTypings\",\n );\n }\n\n const missingTypings = new Set<string>();\n const existingTypingPackages = new Set<string>();\n sourceFile.forEachChild((node) => {\n if (ts.isImportDeclaration(node)) {\n const moduleSpecifier = node.moduleSpecifier;\n if (ts.isStringLiteral(moduleSpecifier)) {\n const moduleResolution = ts.resolveModuleName(\n moduleSpecifier.text,\n virtualFilePath,\n {},\n host,\n );\n\n if (!moduleResolution?.resolvedModule?.packageId) {\n missingTypings.add(moduleSpecifier.text);\n } else {\n existingTypingPackages.add(\n moduleResolution.resolvedModule.packageId.name,\n );\n }\n }\n }\n });\n\n return { missingTypings, existingTypingPackages };\n}\n"],"names":[],"mappings":";AAUA,SAAS,2BACP,IACA,iBACA,sBACA,cACe;AACT,QAAA,gBAAkD,CACtD,UACA,oBACG;AACH,QAAI,aAAa,iBAAiB;AAChC,aAAO,GAAG;AAAA,QACR;AAAA,QACA;AAAA,QACA;AAAA,MACF;AAAA,IAAA;AAEK,WAAA,aAAa,cAAc,UAAU,eAAe;AAAA,EAC7D;AAEM,QAAA,aAA4C,CAAC,aAAa;AAC9D,QAAI,aAAa,iBAAiB;AACzB,aAAA;AAAA,IAAA;AAEF,WAAA,aAAa,WAAW,QAAQ;AAAA,EACzC;AAEM,QAAA,WAAwC,CAAC,aAAa;AAC1D,QAAI,aAAa,iBAAiB;AACzB,aAAA;AAAA,IAAA;AAEF,WAAA,aAAa,SAAS,QAAQ;AAAA,EACvC;AAEO,SAAA;AAAA,IACL;AAAA,IACA;AAAA,IACA;AAAA,EACF;AACF;AAEA,SAAS,oCACP,IACA,UACA,WACA;AACA,QAAM,uBACJ,CAAC,GAAG,QAAQ,EAAE,IAAI,CAAC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CAAC;AAAA,UACD;AAAA,QACF;AAEI,YAAA,GAAC,0DAAkB,mBAAlB,mBAAkC,YAAW;AACjC,yBAAA,IAAI,gBAAgB,IAAI;AAAA,QAAA,OAClC;AACkB,iCAAA;AAAA,YACrB,iBAAiB,eAAe,UAAU;AAAA,UAC5C;AAAA,QAAA;AAAA,MACF;AAAA,IACF;AAAA,EACF,CACD;AAEM,SAAA,EAAE,gBAAgB,uBAAuB;AAClD;"}
1
+ {"version":3,"file":"findTypingsPackages.mjs","sources":["../../../../../../src/tasks/buildTypesTask/findTypingsPackages.ts"],"sourcesContent":["import type * as ts from \"typescript\";\nimport * as path from \"node:path\";\nimport type { TSModule } from \"../../detectModules.js\";\n\ntype HostFunctions = {\n getSourceFile: ts.CompilerHost[\"getSourceFile\"];\n fileExists: ts.CompilerHost[\"fileExists\"];\n readFile: ts.CompilerHost[\"readFile\"];\n};\n\nfunction createVirtualHostFunctions(\n ts: TSModule[\"ts\"],\n virtualFilePath: string,\n virtualSourceContent: string,\n originalHost: ts.CompilerHost,\n): HostFunctions {\n const getSourceFile: ts.CompilerHost[\"getSourceFile\"] = (\n fileName,\n languageVersion,\n ) => {\n if (fileName === virtualFilePath) {\n return ts.createSourceFile(\n fileName,\n virtualSourceContent,\n languageVersion,\n );\n }\n return originalHost.getSourceFile(fileName, languageVersion);\n };\n\n const fileExists: ts.CompilerHost[\"fileExists\"] = (fileName) => {\n if (fileName === virtualFilePath) {\n return true;\n }\n return originalHost.fileExists(fileName);\n };\n\n const readFile: ts.CompilerHost[\"readFile\"] = (fileName) => {\n if (fileName === virtualFilePath) {\n return virtualSourceContent;\n }\n return originalHost.readFile(fileName);\n };\n\n return {\n getSourceFile,\n fileExists,\n readFile,\n };\n}\n\nfunction createCompilerHostWithVirtualSource(\n ts: TSModule[\"ts\"],\n packages: Set<string>,\n sourceDir: string,\n) {\n const virtualSourceContent =\n [...packages].map((p) => `import \"${p}\";`).join(\"\\n\") +\n // for ignoring the `Generated an empty chunk: \".\"` error\n \"export const a = 1;\\n\";\n const virtualFilePath = path.join(sourceDir, \"virtual.ts\");\n\n const originalHost = ts.createCompilerHost({\n target: ts.ScriptTarget.ESNext,\n moduleResolution: ts.ModuleResolutionKind.NodeNext,\n baseUrl: \".\",\n sourceRoot: sourceDir,\n noEmit: true,\n emitDeclarationOnly: true,\n noEmitOnError: true,\n paths: {\n \"*\": [\"node_modules/*\"],\n },\n });\n const virtualFunctions = createVirtualHostFunctions(\n ts,\n virtualFilePath,\n virtualSourceContent,\n originalHost,\n );\n\n return {\n host: new Proxy(originalHost, {\n get(target, prop: keyof ts.CompilerHost) {\n return virtualFunctions[prop as keyof HostFunctions] || target[prop];\n },\n }),\n virtualFilePath,\n };\n}\n\nexport function findTypingsPackages(\n { ts }: TSModule,\n packages: Set<string>,\n sourceDir: string,\n) {\n const { host, virtualFilePath } = createCompilerHostWithVirtualSource(\n ts,\n packages,\n sourceDir,\n );\n\n const program = ts.createProgram({\n rootNames: [virtualFilePath],\n options: {},\n host: host,\n });\n\n const sourceFile = program.getSourceFile(virtualFilePath);\n if (!sourceFile) {\n throw new Error(\n \"[getSourceFile] Impossible error inside findMissingTypings\",\n );\n }\n\n const missingTypings = new Set<string>();\n const existingTypingPackages = new Set<string>();\n sourceFile.forEachChild((node) => {\n if (ts.isImportDeclaration(node)) {\n const moduleSpecifier = node.moduleSpecifier;\n if (ts.isStringLiteral(moduleSpecifier)) {\n const moduleResolution = ts.resolveModuleName(\n moduleSpecifier.text,\n virtualFilePath,\n {},\n host,\n );\n\n if (!moduleResolution?.resolvedModule?.packageId) {\n missingTypings.add(moduleSpecifier.text);\n } else {\n existingTypingPackages.add(\n moduleResolution.resolvedModule.packageId.name,\n );\n }\n }\n }\n });\n\n return { missingTypings, existingTypingPackages };\n}\n"],"names":[],"mappings":";AAUA,SAAS,2BACP,IACA,iBACA,sBACA,cACe;AACT,QAAA,gBAAkD,CACtD,UACA,oBACG;AACH,QAAI,aAAa,iBAAiB;AAChC,aAAO,GAAG;A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,IACA;AAAA,EACF;AAEM,QAAA,UAAU,GAAG,cAAc;AAAA,IAC/B,WAAW,CAAC,eAAe;AAAA,IAC3B,SAAS,CAAC;AAAA,IACV;AAAA,EAAA,CACD;AAEK,QAAA,aAAa,QAAQ,cAAc,eAAe;AACxD,MAAI,CAAC,YAAY;AACf,UAAM,IAAI;AAAA,MACR;AAAA,IACF;AAAA,EAAA;AAGI,QAAA,qCAAqB,IAAY;AACjC,QAAA,6CAA6B,IAAY;AACpC,aAAA,aAAa,CAAC,SAAS;;AAC5B,QAAA,GAAG,oBAAoB,IAAI,GAAG;AAChC,YAAM,kBAAkB,KAAK;AACzB,UAAA,GAAG,gBAAgB,eAAe,GAAG;AACvC,cAAM,mBAAmB,GAAG;AAAA,UAC1B,gBAAgB;AAAA,UAChB;AAAA,UACA,CAAC;AAAA,UACD;AAAA,QACF;AAEI,YAAA,GAAC,0DAAkB,mBAAlB,mBAAkC,YAAW;AACjC,yBAAA,IAAI,gBAAgB,IAAI;AAAA,QAAA,OAClC;AACkB,iCAAA;AAAA,YACrB,iBAAiB,eAAe,UAAU;AAAA,UAC5C;AAAA,QAAA;AAAA,MACF;AAAA,IACF;AAAA,EACF,CACD;AAEM,SAAA,EAAE,gBAAgB,uBAAuB;AAClD;"}
@@ -0,0 +1,6 @@
1
+ import type { Dirs } from "../resolveDirs.js";
2
+ type GitignoreTaskArg = {
3
+ dirs: Dirs;
4
+ };
5
+ export declare function gitignoreTask({ dirs }: GitignoreTaskArg): Promise<void>;
6
+ export {};
@@ -0,0 +1,14 @@
1
+ import fs__default from "node:fs/promises";
2
+ import path__default from "node:path";
3
+ async function gitignoreTask({ dirs }) {
4
+ const { outDir } = dirs;
5
+ const gitignoreContent = "*\n";
6
+ const gitignorePath = path__default.join(outDir, ".gitignore");
7
+ await fs__default.writeFile(gitignorePath, gitignoreContent);
8
+ const npmignorePath = path__default.join(outDir, ".npmignore");
9
+ await fs__default.writeFile(npmignorePath, "");
10
+ }
11
+ export {
12
+ gitignoreTask
13
+ };
14
+ //# sourceMappingURL=gitignoreTask.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"gitignoreTask.mjs","sources":["../../../../../src/tasks/gitignoreTask.ts"],"sourcesContent":["import fs from \"node:fs/promises\";\nimport path from \"node:path\";\nimport type { Dirs } from \"../resolveDirs.js\";\n\ntype GitignoreTaskArg = {\n dirs: Dirs;\n};\n\nexport async function gitignoreTask({ dirs }: GitignoreTaskArg) {\n const { outDir } = dirs;\n\n // Ignore the all files to prevent commiting the dist\n const gitignoreContent = \"*\\n\";\n\n const gitignorePath = path.join(outDir, \".gitignore\");\n await fs.writeFile(gitignorePath, gitignoreContent);\n\n // We need to have empty .npmignore to avoid reading .gitignore in pnpm publishing\n const npmignorePath = path.join(outDir, \".npmignore\");\n await fs.writeFile(npmignorePath, \"\");\n}\n"],"names":["path","fs"],"mappings":";;AAQsB,eAAA,cAAc,EAAE,QAA0B;AACxD,QAAA,EAAE,WAAW;AAGnB,QAAM,mBAAmB;AAEzB,QAAM,gBAAgBA,cAAK,KAAK,QAAQ,YAAY;AAC9C,QAAAC,YAAG,UAAU,eAAe,gBAAgB;AAGlD,QAAM,gBAAgBD,cAAK,KAAK,QAAQ,YAAY;AAC9C,QAAAC,YAAG,UAAU,eAAe,EAAE;AACtC;"}
@@ -2,6 +2,7 @@ import { writeFile } from "node:fs/promises";
2
2
  import "zod";
3
3
  import "node:path";
4
4
  import { okLog } from "./log.mjs";
5
+ import { convertPackageJson } from "./monorepo/convertPackageJson.mjs";
5
6
  function extractValue(value) {
6
7
  if (!value) {
7
8
  return void 0;
@@ -36,6 +37,7 @@ async function writePackageJson(outDir, parsed, { exportsMap, binsMap }) {
36
37
  allExports["./package.json"] = "./package.json";
37
38
  const bin = binsMap.size > 0 ? Object.fromEntries(binsMap) : void 0;
38
39
  const rootExport = typeof allExports["."] === "object" ? allExports["."] : void 0;
40
+ parsed = convertPackageJson(parsed);
39
41
  const res = {
40
42
  name: parsed.name,
41
43
  type: "commonjs",
@@ -1 +1 @@
1
- {"version":3,"file":"writePackageJson.mjs","sources":["../../../../src/writePackageJson.ts"],"sourcesContent":["import { writeFile } from \"node:fs/promises\";\nimport { type PackageJson } from \"./packageJson.js\";\nimport { okLog } from \"./log.js\";\n\nexport type ExportsObject = {\n mjs?: string;\n dmts?: string;\n dcts?: string;\n cjs?: string;\n raw?: string;\n};\n\ntype BuildResult = {\n exportsMap: Map<string, ExportsObject>;\n binsMap: Map<string, string>;\n};\n\ntype ExportsPackageJsonObj =\n | {\n import?: ExportsPackageJsonObj;\n require?: ExportsPackageJsonObj;\n types?: string;\n default?: string;\n }\n | string;\n\nfunction extractValue(value?: ExportsPackageJsonObj) {\n if (!value) {\n return undefined;\n }\n if (typeof value === \"string\") {\n return value;\n }\n return value.default;\n}\n\nexport async function writePackageJson(\n outDir: string,\n parsed: PackageJson,\n { exportsMap, binsMap }: BuildResult,\n) {\n // we always want to have `exports` property in the target package.json\n // If you want to export something, please, specify them\n const allExports: Record<string, ExportsPackageJsonObj> = {};\n for (const [key, value] of exportsMap) {\n const anExport: ExportsPackageJsonObj = {};\n\n if (value.mjs) {\n anExport.import = {};\n if (value.dmts) {\n anExport.import.types = value.dmts;\n }\n anExport.import.default = value.mjs;\n }\n if (value.cjs) {\n anExport.require = {};\n if (value.dcts) {\n anExport.require.types = value.dcts;\n }\n anExport.require.default = value.cjs;\n }\n\n // should be first for correct resolving\n anExport.types = value.dcts ?? value.dmts;\n // because we need to have default and types key on the end\n // JSON.stringify will put it on the end if we put value at the last step\n anExport.default = value.cjs;\n\n allExports[key] = anExport;\n }\n allExports[\"./package.json\"] = \"./package.json\";\n\n const bin = binsMap.size > 0 ? Object.fromEntries(binsMap) : undefined;\n\n const rootExport =\n typeof allExports[\".\"] === \"object\" ? allExports[\".\"] : undefined;\n const res = {\n name: parsed.name,\n type: \"commonjs\",\n version: parsed.version,\n bin,\n types: rootExport?.types,\n module: extractValue(rootExport?.import),\n main: extractValue(rootExport?.require),\n description: parsed.description ?? \"\",\n exports: allExports,\n dependencies: parsed.dependencies ?? undefined,\n optionalDependencies: parsed.optionalDependencies ?? undefined,\n repository: parsed.repository,\n keywords: parsed.keywords,\n author: parsed.author,\n contributors: parsed.contributors,\n license: parsed.license,\n peerDependencies: parsed.peerDependencies,\n engines: parsed.engines,\n browser: parsed.browser,\n funding: parsed.funding,\n os: parsed.os,\n cpu: parsed.cpu,\n maintainers: parsed.maintainers,\n bugs: parsed.bugs,\n sideEffects: parsed.sideEffects,\n unpkg: parsed.unpkg,\n homepage: parsed.homepage,\n devDependencies: parsed.devDependencies,\n peerDependenciesMeta: parsed.peerDependenciesMeta,\n };\n\n await writeFile(`${outDir}/package.json`, JSON.stringify(res, null, 2));\n\n okLog(\"package.json\");\n}\n"],"names":[],"mappings":";;;;AA0BA,SAAS,aAAa,OAA+B;AACnD,MAAI,CAAC,OAAO;AACH,WAAA;AAAA,EAAA;AAEL,MAAA,OAAO,UAAU,UAAU;AACtB,WAAA;AAAA,EAAA;AAET,SAAO,MAAM;AACf;AAEA,eAAsB,iBACpB,QACA,QACA,EAAE,YAAY,WACd;AAGA,QAAM,aAAoD,CAAC;AAC3D,aAAW,CAAC,KAAK,KAAK,KAAK,YAAY;AACrC,UAAM,WAAkC,CAAC;AAEzC,QAAI,MAAM,KAAK;AACb,eAAS,SAAS,CAAC;AACnB,UAAI,MAAM,MAAM;AACL,iBAAA,OAAO,QAAQ,MAAM;AAAA,MAAA;AAEvB,eAAA,OAAO,UAAU,MAAM;AAAA,IAAA;AAElC,QAAI,MAAM,KAAK;AACb,eAAS,UAAU,CAAC;AACpB,UAAI,MAAM,MAAM;AACL,iBAAA,QAAQ,QAAQ,MAAM;AAAA,MAAA;AAExB,eAAA,QAAQ,UAAU,MAAM;AAAA,IAAA;AAI1B,aAAA,QAAQ,MAAM,QAAQ,MAAM;AAGrC,aAAS,UAAU,MAAM;AAEzB,eAAW,GAAG,IAAI;AAAA,EAAA;AAEpB,aAAW,gBAAgB,IAAI;AAE/B,QAAM,MAAM,QAAQ,OAAO,IAAI,OAAO,YAAY,OAAO,IAAI;AAEvD,QAAA,aACJ,OAAO,WAAW,GAAG,MAAM,WAAW,WAAW,GAAG,IAAI;AAC1D,QAAM,MAAM;AAAA,IACV,MAAM,OAAO;AAAA,IACb,MAAM;AAAA,IACN,SAAS,OAAO;AAAA,IAChB;AAAA,IACA,OAAO,yCAAY;AAAA,IACnB,QAAQ,aAAa,yCAAY,MAAM;AAAA,IACvC,MAAM,aAAa,yCAAY,OAAO;AAAA,IACtC,aAAa,OAAO,eAAe;AAAA,IACnC,SAAS;AAAA,IACT,cAAc,OAAO,gBAAgB;AAAA,IACrC,sBAAsB,OAAO,wBAAwB;AAAA,IACrD,YAAY,OAAO;AAAA,IACnB,UAAU,OAAO;AAAA,IACjB,QAAQ,OAAO;AAAA,IACf,cAAc,OAAO;AAAA,IACrB,SAAS,OAAO;AAAA,IAChB,kBAAkB,OAAO;AAAA,IACzB,SAAS,OAAO;AAAA,IAChB,SAAS,OAAO;AAAA,IAChB,SAAS,OAAO;AAAA,IAChB,IAAI,OAAO;AAAA,IACX,KAAK,OAAO;AAAA,IACZ,aAAa,OAAO;AAAA,IACpB,MAAM,OAAO;AAAA,IACb,aAAa,OAAO;AAAA,IACpB,OAAO,OAAO;AAAA,IACd,UAAU,OAAO;AAAA,IACjB,iBAAiB,OAAO;AAAA,IACxB,sBAAsB,OAAO;AAAA,EAC/B;AAEM,QAAA,UAAU,GAAG,MAAM,iBAAiB,KAAK,UAAU,KAAK,MAAM,CAAC,CAAC;AAEtE,QAAM,cAAc;AACtB;"}
1
+ {"version":3,"file":"writePackageJson.mjs","sources":["../../../../src/writePackageJson.ts"],"sourcesContent":["import { writeFile } from \"node:fs/promises\";\nimport { type PackageJson } from \"./packageJson.js\";\nimport { okLog } from \"./log.js\";\nimport { convertPackageJson } from \"./monorepo/convertPackageJson.js\";\n\nexport type ExportsObject = {\n mjs?: string;\n dmts?: string;\n dcts?: string;\n cjs?: string;\n raw?: string;\n};\n\ntype BuildResult = {\n exportsMap: Map<string, ExportsObject>;\n binsMap: Map<string, string>;\n};\n\ntype ExportsPackageJsonObj =\n | {\n import?: ExportsPackageJsonObj;\n require?: ExportsPackageJsonObj;\n types?: string;\n default?: string;\n }\n | string;\n\nfunction extractValue(value?: ExportsPackageJsonObj) {\n if (!value) {\n return undefined;\n }\n if (typeof value === \"string\") {\n return value;\n }\n return value.default;\n}\n\nexport async function writePackageJson(\n outDir: string,\n parsed: PackageJson,\n { exportsMap, binsMap }: BuildResult,\n) {\n // we always want to have `exports` property in the target package.json\n // If you want to export something, please, specify them\n const allExports: Record<string, ExportsPackageJsonObj> = {};\n for (const [key, value] of exportsMap) {\n const anExport: ExportsPackageJsonObj = {};\n\n if (value.mjs) {\n anExport.import = {};\n if (value.dmts) {\n anExport.import.types = value.dmts;\n }\n anExport.import.default = value.mjs;\n }\n if (value.cjs) {\n anExport.require = {};\n if (value.dcts) {\n anExport.require.types = value.dcts;\n }\n anExport.require.default = value.cjs;\n }\n\n // should be first for correct resolving\n anExport.types = value.dcts ?? value.dmts;\n // because we need to have default and types key on the end\n // JSON.stringify will put it on the end if we put value at the last step\n anExport.default = value.cjs;\n\n allExports[key] = anExport;\n }\n allExports[\"./package.json\"] = \"./package.json\";\n\n const bin = binsMap.size > 0 ? Object.fromEntries(binsMap) : undefined;\n\n const rootExport =\n typeof allExports[\".\"] === \"object\" ? allExports[\".\"] : undefined;\n\n parsed = convertPackageJson(parsed);\n\n const res = {\n name: parsed.name,\n type: \"commonjs\",\n version: parsed.version,\n bin,\n types: rootExport?.types,\n module: extractValue(rootExport?.import),\n main: extractValue(rootExport?.require),\n description: parsed.description ?? \"\",\n exports: allExports,\n dependencies: parsed.dependencies ?? undefined,\n optionalDependencies: parsed.optionalDependencies ?? undefined,\n repository: parsed.repository,\n keywords: parsed.keywords,\n author: parsed.author,\n contributors: parsed.contributors,\n license: parsed.license,\n peerDependencies: parsed.peerDependencies,\n engines: parsed.engines,\n browser: parsed.browser,\n funding: parsed.funding,\n os: parsed.os,\n cpu: parsed.cpu,\n maintainers: parsed.maintainers,\n bugs: parsed.bugs,\n sideEffects: parsed.sideEffects,\n unpkg: parsed.unpkg,\n homepage: parsed.homepage,\n devDependencies: parsed.devDependencies,\n peerDependenciesMeta: parsed.peerDependenciesMeta,\n };\n\n await writeFile(`${outDir}/package.json`, JSON.stringify(res, null, 2));\n\n okLog(\"package.json\");\n}\n"],"names":[],"mappings":";;;;;AA2BA,SAAS,aAAa,OAA+B;AACnD,MAAI,CAAC,OAAO;AACH,WAAA;AAAA,EAAA;AAEL,MAAA,OAAO,UAAU,UAAU;AACtB,WAAA;AAAA,EAAA;AAET,SAAO,MAAM;AACf;AAEA,eAAsB,iBACpB,QACA,QACA,EAAE,YAAY,WACd;AAGA,QAAM,aAAoD,CAAC;AAC3D,aAAW,CAAC,KAAK,KAAK,KAAK,YAAY;AACrC,UAAM,WAAkC,CAAC;AAEzC,QAAI,MAAM,KAAK;AACb,eAAS,SAAS,CAAC;AACnB,UAAI,MAAM,MAAM;AACL,iBAAA,OAAO,QAAQ,MAAM;AAAA,MAAA;AAEvB,eAAA,OAAO,UAAU,MAAM;AAAA,IAAA;AAElC,QAAI,MAAM,KAAK;AACb,eAAS,UAAU,CAAC;AACpB,UAAI,MAAM,MAAM;AACL,iBAAA,QAAQ,QAAQ,MAAM;AAAA,MAAA;AAExB,eAAA,QAAQ,UAAU,MAAM;AAAA,IAAA;AAI1B,aAAA,QAAQ,MAAM,QAAQ,MAAM;AAGrC,aAAS,UAAU,MAAM;AAEzB,eAAW,GAAG,IAAI;AAAA,EAAA;AAEpB,aAAW,gBAAgB,IAAI;AAE/B,QAAM,MAAM,QAAQ,OAAO,IAAI,OAAO,YAAY,OAAO,IAAI;AAEvD,QAAA,aACJ,OAAO,WAAW,GAAG,MAAM,WAAW,WAAW,GAAG,IAAI;AAE1D,WAAS,mBAAmB,MAAM;AAElC,QAAM,MAAM;AAAA,IACV,MAAM,OAAO;AAAA,IACb,MAAM;AAAA,IACN,SAAS,OAAO;AAAA,IAChB;AAAA,IACA,OAAO,yCAAY;AAAA,IACnB,QAAQ,aAAa,yCAAY,MAAM;AAAA,IACvC,MAAM,aAAa,yCAAY,OAAO;AAAA,IACtC,aAAa,OAAO,eAAe;AAAA,IACnC,SAAS;AAAA,IACT,cAAc,OAAO,gBAAgB;AAAA,IACrC,sBAAsB,OAAO,wBAAwB;AAAA,IACrD,YAAY,OAAO;AAAA,IACnB,UAAU,OAAO;AAAA,IACjB,QAAQ,OAAO;AAAA,IACf,cAAc,OAAO;AAAA,IACrB,SAAS,OAAO;AAAA,IAChB,kBAAkB,OAAO;AAAA,IACzB,SAAS,OAAO;AAAA,IAChB,SAAS,OAAO;AAAA,IAChB,SAAS,OAAO;AAAA,IAChB,IAAI,OAAO;AAAA,IACX,KAAK,OAAO;AAAA,IACZ,aAAa,OAAO;AAAA,IACpB,MAAM,OAAO;AAAA,IACb,aAAa,OAAO;AAAA,IACpB,OAAO,OAAO;AAAA,IACd,UAAU,OAAO;AAAA,IACjB,iBAAiB,OAAO;AAAA,IACxB,sBAAsB,OAAO;AAAA,EAC/B;AAEM,QAAA,UAAU,GAAG,MAAM,iBAAiB,KAAK,UAAU,KAAK,MAAM,CAAC,CAAC;AAEtE,QAAM,cAAc;AACtB;"}
package/package.json CHANGED
@@ -1,9 +1,10 @@
1
1
  {
2
2
  "name": "smartbundle",
3
3
  "type": "commonjs",
4
- "version": "0.14.1",
4
+ "version": "0.15.0-alpha.1",
5
5
  "bin": {
6
- "smartbundle": "__bin__/smartbundle.js"
6
+ "smartbundle": "__bin__/smartbundle.js",
7
+ "smartbundle-monorepo-link": "__bin__/smartbundle-monorepo-link.js"
7
8
  },
8
9
  "types": "./__compiled__/cjs/src/index.d.ts",
9
10
  "module": "./__compiled__/esm/src/index.mjs",
@@ -25,11 +26,13 @@
25
26
  "./package.json": "./package.json"
26
27
  },
27
28
  "dependencies": {
28
- "semver": "^7.6.3",
29
- "vite": "^6.0.7",
29
+ "glob": "^11.0.3",
30
+ "semver": "^7.7.2",
31
+ "vite": "^6.3.5",
32
+ "yaml": "^2.8.0",
30
33
  "yargs": "^17.7.2",
31
- "youch": "4.1.0-beta.5",
32
- "zod": "^3.24.1"
34
+ "youch": "4.1.0-beta.8",
35
+ "zod": "^3.25.67"
33
36
  },
34
37
  "repository": {
35
38
  "type": "git",
@@ -54,20 +57,23 @@
54
57
  "typescript": "^5.0.0",
55
58
  "vitest": "^3.0.0"
56
59
  },
60
+ "engines": {
61
+ "pnpm": "^10.11.0"
62
+ },
57
63
  "bugs": {
58
64
  "url": "https://github.com/xavescor/smartbundle/issues"
59
65
  },
60
66
  "homepage": "https://github.com/xavescor/smartbundle",
61
67
  "devDependencies": {
62
68
  "@types/babel__core": "^7.20.5",
63
- "@types/node": "^22.10.7",
64
- "@types/semver": "^7.5.8",
69
+ "@types/node": "^22.15.32",
70
+ "@types/semver": "^7.7.0",
65
71
  "@types/yargs": "^17.0.33",
66
- "prettier": "^3.4.2",
67
- "typescript": "^5.7.3",
68
- "vitest": "^3.0.2",
69
- "vitest-directory-snapshot": "^0.4.0",
70
- "zx": "^8.3.0"
72
+ "prettier": "^3.5.3",
73
+ "typescript": "^5.8.3",
74
+ "vitest": "^3.2.4",
75
+ "vitest-directory-snapshot": "^0.6.1",
76
+ "zx": "^8.5.5"
71
77
  },
72
78
  "peerDependenciesMeta": {
73
79
  "@babel/core": {