smartbundle 0.7.3 → 0.8.0-alpha.0

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 (60) hide show
  1. package/README.md +62 -28
  2. package/__bin__/smartbundle.js +1 -1
  3. package/__do_not_import_directly__/args.js +23 -6
  4. package/__do_not_import_directly__/args.mjs +18 -0
  5. package/__do_not_import_directly__/buildVite.js +7 -7
  6. package/__do_not_import_directly__/buildVite.mjs +20 -0
  7. package/__do_not_import_directly__/createViteConfig.js +14 -14
  8. package/__do_not_import_directly__/{createViteConfig.cjs → createViteConfig.mjs} +14 -14
  9. package/__do_not_import_directly__/error.js +3 -3
  10. package/__do_not_import_directly__/error.mjs +9 -0
  11. package/__do_not_import_directly__/errors.js +3 -3
  12. package/__do_not_import_directly__/{errors.cjs → errors.mjs} +3 -3
  13. package/__do_not_import_directly__/packageJson.js +52 -35
  14. package/__do_not_import_directly__/packageJson.mjs +129 -0
  15. package/__do_not_import_directly__/resolveDirs.js +6 -6
  16. package/__do_not_import_directly__/{resolveDirs.cjs → resolveDirs.mjs} +6 -6
  17. package/__do_not_import_directly__/smartbundle.js +4 -3
  18. package/__do_not_import_directly__/smartbundle.mjs +3 -0
  19. package/__do_not_import_directly__/tasks/binsTask.js +16 -13
  20. package/__do_not_import_directly__/tasks/{binsTask.cjs → binsTask.mjs} +16 -13
  21. package/__do_not_import_directly__/tasks/buildTypesTask/buildTypesTask.js +34 -12
  22. package/__do_not_import_directly__/tasks/buildTypesTask/buildTypesTask.mjs +40 -0
  23. package/__do_not_import_directly__/tasks/buildTypesTask/callTypescript.js +33 -12
  24. package/__do_not_import_directly__/tasks/buildTypesTask/callTypescript.mjs +53 -0
  25. package/__do_not_import_directly__/tasks/copyStaticFilesTask.js +9 -9
  26. package/__do_not_import_directly__/tasks/{copyStaticFilesTask.cjs → copyStaticFilesTask.mjs} +9 -9
  27. package/__do_not_import_directly__/tasks/jsFilesTask.js +6 -6
  28. package/__do_not_import_directly__/tasks/{jsFilesTask.cjs → jsFilesTask.mjs} +6 -6
  29. package/__do_not_import_directly__/tasks/utils.js +3 -3
  30. package/__do_not_import_directly__/tasks/{utils.cjs → utils.mjs} +3 -3
  31. package/__do_not_import_directly__/writePackageJson.js +23 -15
  32. package/__do_not_import_directly__/{writePackageJson.cjs → writePackageJson.mjs} +23 -15
  33. package/package.json +9 -8
  34. package/src/args.d.cts +9 -0
  35. package/src/buildVite.d.cts +16 -0
  36. package/src/createViteConfig.d.cts +12 -0
  37. package/src/error.d.cts +4 -0
  38. package/src/errors.d.cts +28 -0
  39. package/src/index.d.cts +9 -0
  40. package/src/index.js +48 -43
  41. package/src/index.mjs +105 -0
  42. package/src/packageJson.d.cts +89 -0
  43. package/src/resolveDirs.d.cts +12 -0
  44. package/src/run.d.cts +1 -0
  45. package/src/tasks/binsTask.d.cts +9 -0
  46. package/src/tasks/buildTypesTask/buildTypesTask.d.cts +9 -0
  47. package/src/tasks/buildTypesTask/callTypescript.d.cts +8 -0
  48. package/src/tasks/copyStaticFilesTask.d.cts +1 -0
  49. package/src/tasks/jsFilesTask.d.cts +7 -0
  50. package/src/tasks/utils.d.cts +1 -0
  51. package/src/writePackageJson.d.cts +14 -0
  52. package/src/writePackageJson.d.ts +1 -0
  53. package/__do_not_import_directly__/args.cjs +0 -35
  54. package/__do_not_import_directly__/buildVite.cjs +0 -20
  55. package/__do_not_import_directly__/error.cjs +0 -9
  56. package/__do_not_import_directly__/packageJson.cjs +0 -146
  57. package/__do_not_import_directly__/smartbundle.cjs +0 -4
  58. package/__do_not_import_directly__/tasks/buildTypesTask/buildTypesTask.cjs +0 -62
  59. package/__do_not_import_directly__/tasks/buildTypesTask/callTypescript.cjs +0 -68
  60. package/src/index.cjs +0 -100
@@ -0,0 +1,129 @@
1
+ import * as fs from "node:fs/promises";
2
+ import z from "zod";
3
+ import { errors } from "./errors.mjs";
4
+ import { join } from "node:path";
5
+ async function fileExists(filePath) {
6
+ try {
7
+ const stats = await fs.stat(filePath);
8
+ return stats.isFile();
9
+ } catch (error) {
10
+ return false;
11
+ }
12
+ }
13
+ function dependencies(errorText) {
14
+ return z.record(z.string({ message: errorText }), { message: errorText }).optional();
15
+ }
16
+ function createPathValidator(sourceDir) {
17
+ return (path) => {
18
+ const finalPath = join(sourceDir, path);
19
+ return fileExists(finalPath);
20
+ };
21
+ }
22
+ const PackageJsonNameField = "___NAME___";
23
+ function fillPackageJson(packageJson) {
24
+ if (packageJson.bin) {
25
+ const binName = packageJson.bin.get(PackageJsonNameField);
26
+ if (binName) {
27
+ packageJson.bin.set(packageJson.name, binName);
28
+ packageJson.bin.delete(PackageJsonNameField);
29
+ }
30
+ }
31
+ }
32
+ function createPackageJsonSchema(sourceDir) {
33
+ const pathValidator = createPathValidator(sourceDir);
34
+ return z.object({
35
+ exports: z.union(
36
+ [
37
+ z.string().transform((path) => /* @__PURE__ */ new Map([[".", path]])),
38
+ z.record(z.string()).transform((obj) => new Map(Object.entries(obj)))
39
+ ],
40
+ {
41
+ errorMap() {
42
+ return { message: errors.exportsRequired };
43
+ }
44
+ }
45
+ ).refine(async (obj) => {
46
+ for (const [key, value] of obj.entries()) {
47
+ if (!await pathValidator(value)) {
48
+ return false;
49
+ }
50
+ }
51
+ return true;
52
+ }, errors.exportsInvalid).optional(),
53
+ name: z.string({ message: errors.nameRequired }).min(1, errors.nameMinLength).max(214, errors.nameMaxLength).refine(
54
+ (name) => ["_", "."].every((start) => !name.startsWith(start)),
55
+ errors.nameStartsIllegalChars
56
+ ),
57
+ version: z.string({ message: errors.versionRequired }),
58
+ private: z.boolean({ message: errors.privateIsTrue }).refine((value) => value, errors.privateIsTrue),
59
+ description: z.string({ message: errors.descriptionString }).optional(),
60
+ dependencies: dependencies(errors.dependenciesInvalid),
61
+ optionalDependencies: dependencies(errors.optionalDependenciesInvalid),
62
+ bin: z.union(
63
+ [
64
+ z.string().transform((value) => /* @__PURE__ */ new Map([[PackageJsonNameField, value]])),
65
+ z.record(z.string()).transform((record) => new Map(Object.entries(record)))
66
+ ],
67
+ {
68
+ errorMap() {
69
+ return { message: errors.binFiled };
70
+ }
71
+ }
72
+ ).refine(
73
+ async (map) => {
74
+ for (const [key, value] of map.entries()) {
75
+ if (!await pathValidator(value)) {
76
+ return false;
77
+ }
78
+ }
79
+ return true;
80
+ },
81
+ { message: errors.binFiled }
82
+ ).optional(),
83
+ repository: z.any().optional(),
84
+ keywords: z.array(z.string(), { message: errors.keywordsInvalid }).optional(),
85
+ author: z.any().optional(),
86
+ maintainers: z.any().optional(),
87
+ contributors: z.array(
88
+ z.union([
89
+ z.string({ message: errors.contributorsInvalid }),
90
+ z.object({}, { message: errors.contributorsInvalid })
91
+ ])
92
+ ).optional(),
93
+ license: z.any().optional(),
94
+ devDependencies: dependencies(errors.devDependenciesInvalid),
95
+ peerDependencies: dependencies(errors.peerDependenciesInvalid),
96
+ engines: z.record(z.string(), { message: errors.enginesInvalid }).optional(),
97
+ browser: z.union([
98
+ z.string({ message: errors.browserInvalid }),
99
+ z.record(z.string(), { message: errors.browserInvalid })
100
+ ]).optional(),
101
+ bugs: z.any().optional(),
102
+ funding: z.union([
103
+ z.string({ message: errors.fundingInvalid }),
104
+ z.object({}, { message: errors.fundingInvalid })
105
+ ]).optional(),
106
+ os: z.array(z.string(), { message: errors.osInvalid }).optional(),
107
+ cpu: z.array(z.string(), { message: errors.cpuInvalid }).optional(),
108
+ sideEffects: z.any().optional(),
109
+ unpkg: z.any().optional(),
110
+ homepage: z.any().optional()
111
+ });
112
+ }
113
+ async function parsePackageJson({
114
+ sourceDir,
115
+ packagePath
116
+ }) {
117
+ const packageString = await fs.readFile(packagePath, "utf-8");
118
+ const rawJson = JSON.parse(packageString);
119
+ const packageJsonSchema = createPackageJsonSchema(sourceDir);
120
+ const packageJson = await packageJsonSchema.safeParseAsync(rawJson);
121
+ if (!packageJson.success) {
122
+ return packageJson.error.errors.map((error) => error.message);
123
+ }
124
+ fillPackageJson(packageJson.data);
125
+ return packageJson.data;
126
+ }
127
+ export {
128
+ parsePackageJson
129
+ };
@@ -1,9 +1,11 @@
1
- import { isAbsolute, join } from "node:path";
1
+ "use strict";
2
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
+ const path = require("node:path");
2
4
  function myResolve(path1, path2) {
3
- if (isAbsolute(path2)) {
5
+ if (path.isAbsolute(path2)) {
4
6
  return path2;
5
7
  }
6
- return join(path1, path2);
8
+ return path.join(path1, path2);
7
9
  }
8
10
  function resolveDirs(args) {
9
11
  const sourceDir = myResolve(process.cwd(), args.sourceDir ?? ".");
@@ -15,6 +17,4 @@ function resolveDirs(args) {
15
17
  const outBinsDir = myResolve(outDir, "__bin__");
16
18
  return { sourceDir, packagePath, outDir, outBinsDir };
17
19
  }
18
- export {
19
- resolveDirs
20
- };
20
+ exports.resolveDirs = resolveDirs;
@@ -1,11 +1,9 @@
1
- "use strict";
2
- Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
- const path = require("node:path");
1
+ import { isAbsolute, join } from "node:path";
4
2
  function myResolve(path1, path2) {
5
- if (path.isAbsolute(path2)) {
3
+ if (isAbsolute(path2)) {
6
4
  return path2;
7
5
  }
8
- return path.join(path1, path2);
6
+ return join(path1, path2);
9
7
  }
10
8
  function resolveDirs(args) {
11
9
  const sourceDir = myResolve(process.cwd(), args.sourceDir ?? ".");
@@ -17,4 +15,6 @@ function resolveDirs(args) {
17
15
  const outBinsDir = myResolve(outDir, "__bin__");
18
16
  return { sourceDir, packagePath, outDir, outBinsDir };
19
17
  }
20
- exports.resolveDirs = resolveDirs;
18
+ export {
19
+ resolveDirs
20
+ };
@@ -1,3 +1,4 @@
1
- import { args } from "./args.js";
2
- import { run } from "../src/index.js";
3
- run(args);
1
+ "use strict";
2
+ const args = require("./args.js");
3
+ const _ = require("../src/index.js");
4
+ _.run(args.args);
@@ -0,0 +1,3 @@
1
+ import { args } from "./args.mjs";
2
+ import { run } from "../src/index.mjs";
3
+ run(args);
@@ -1,7 +1,9 @@
1
- import { mkdir, writeFile } from "node:fs/promises";
2
- import { relative, join } from "node:path";
3
- import "vite";
4
- import { reverseMap } from "./utils.js";
1
+ "use strict";
2
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
+ const fs = require("node:fs/promises");
4
+ const path = require("node:path");
5
+ require("vite");
6
+ const utils = require("./utils.js");
5
7
  async function binsTask({
6
8
  buildOutput,
7
9
  bins,
@@ -11,8 +13,8 @@ async function binsTask({
11
13
  if (bins.size === 0) {
12
14
  return /* @__PURE__ */ new Map();
13
15
  }
14
- await mkdir(outBinsDir, { recursive: true });
15
- const reversedEntrypoints = reverseMap(bins);
16
+ await fs.mkdir(outBinsDir, { recursive: true });
17
+ const reversedEntrypoints = utils.reverseMap(bins);
16
18
  const res = /* @__PURE__ */ new Map();
17
19
  for (const el of buildOutput) {
18
20
  if (el.facadeModuleId == null) {
@@ -26,19 +28,20 @@ async function binsTask({
26
28
  continue;
27
29
  }
28
30
  for (const binName of binsNames) {
29
- const totalPath = relative(outBinsDir, join(outDir, el.fileName));
30
- const execPath = join(outBinsDir, `${binName}.js`);
31
- await writeFile(
31
+ const totalPath = path.relative(
32
+ outBinsDir,
33
+ path.join(outDir, el.fileName.replace(/js$/, "mjs"))
34
+ );
35
+ const execPath = path.join(outBinsDir, `${binName}.js`);
36
+ await fs.writeFile(
32
37
  execPath,
33
38
  `#!/usr/bin/env node
34
39
  import("${totalPath}");
35
40
  `
36
41
  );
37
- res.set(relative(outDir, execPath), binName);
42
+ res.set(path.relative(outDir, execPath), binName);
38
43
  }
39
44
  }
40
45
  return res;
41
46
  }
42
- export {
43
- binsTask
44
- };
47
+ exports.binsTask = binsTask;
@@ -1,9 +1,7 @@
1
- "use strict";
2
- Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
- const fs = require("node:fs/promises");
4
- const path = require("node:path");
5
- require("vite");
6
- const utils = require("./utils.cjs");
1
+ import { mkdir, writeFile } from "node:fs/promises";
2
+ import { relative, join } from "node:path";
3
+ import "vite";
4
+ import { reverseMap } from "./utils.mjs";
7
5
  async function binsTask({
8
6
  buildOutput,
9
7
  bins,
@@ -13,8 +11,8 @@ async function binsTask({
13
11
  if (bins.size === 0) {
14
12
  return /* @__PURE__ */ new Map();
15
13
  }
16
- await fs.mkdir(outBinsDir, { recursive: true });
17
- const reversedEntrypoints = utils.reverseMap(bins);
14
+ await mkdir(outBinsDir, { recursive: true });
15
+ const reversedEntrypoints = reverseMap(bins);
18
16
  const res = /* @__PURE__ */ new Map();
19
17
  for (const el of buildOutput) {
20
18
  if (el.facadeModuleId == null) {
@@ -28,17 +26,22 @@ async function binsTask({
28
26
  continue;
29
27
  }
30
28
  for (const binName of binsNames) {
31
- const totalPath = path.relative(outBinsDir, path.join(outDir, el.fileName));
32
- const execPath = path.join(outBinsDir, `${binName}.js`);
33
- await fs.writeFile(
29
+ const totalPath = relative(
30
+ outBinsDir,
31
+ join(outDir, el.fileName.replace(/js$/, "mjs"))
32
+ );
33
+ const execPath = join(outBinsDir, `${binName}.js`);
34
+ await writeFile(
34
35
  execPath,
35
36
  `#!/usr/bin/env node
36
37
  import("${totalPath}");
37
38
  `
38
39
  );
39
- res.set(path.relative(outDir, execPath), binName);
40
+ res.set(relative(outDir, execPath), binName);
40
41
  }
41
42
  }
42
43
  return res;
43
44
  }
44
- exports.binsTask = binsTask;
45
+ export {
46
+ binsTask
47
+ };
@@ -1,14 +1,38 @@
1
- import "vite";
2
- import { errors } from "../../errors.js";
3
- import { callTypescript } from "./callTypescript.js";
4
- import { reverseMap } from "../utils.js";
1
+ "use strict";
2
+ var __create = Object.create;
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __copyProps = (to, from, except, desc) => {
9
+ if (from && typeof from === "object" || typeof from === "function") {
10
+ for (let key of __getOwnPropNames(from))
11
+ if (!__hasOwnProp.call(to, key) && key !== except)
12
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
13
+ }
14
+ return to;
15
+ };
16
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
17
+ // If the importer is in node compatibility mode or this is not an ESM
18
+ // file that has been converted to a CommonJS file using a Babel-
19
+ // compatible transform (i.e. "__esModule" has not been set), then set
20
+ // "default" to the CommonJS "module.exports" for node compatibility.
21
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
22
+ mod
23
+ ));
24
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
25
+ require("vite");
26
+ const errors = require("../../errors.js");
27
+ const callTypescript = require("./callTypescript.js");
28
+ const utils = require("../utils.js");
5
29
  async function buildTypesTask({
6
30
  buildOutput,
7
31
  entrypoints,
8
32
  sourceDir,
9
33
  outDir
10
34
  }) {
11
- const reversedEntrypoints = reverseMap(entrypoints);
35
+ const reversedEntrypoints = utils.reverseMap(entrypoints);
12
36
  const tsEntrypoints = [...entrypoints.values()].filter(
13
37
  (entry) => entry.endsWith(".ts")
14
38
  );
@@ -19,22 +43,20 @@ async function buildTypesTask({
19
43
  try {
20
44
  ts = await import("typescript");
21
45
  } catch {
22
- throw errors.typescriptNotFound;
46
+ throw errors.errors.typescriptNotFound;
23
47
  }
24
48
  const files = buildOutput.map((el) => el.facadeModuleId ?? "");
25
- const dtsMap = await callTypescript({ ts, sourceDir, files, outDir });
49
+ const dtsMap = await callTypescript.callTypescript({ ts, sourceDir, files, outDir });
26
50
  const result = /* @__PURE__ */ new Map();
27
- for (const [source, dts] of dtsMap) {
51
+ for (const [types, source] of dtsMap) {
28
52
  const exportPath = reversedEntrypoints.get(source);
29
53
  if (!exportPath) {
30
54
  continue;
31
55
  }
32
56
  for (const path of exportPath) {
33
- result.set(dts, path);
57
+ result.set(types, path);
34
58
  }
35
59
  }
36
60
  return result;
37
61
  }
38
- export {
39
- buildTypesTask
40
- };
62
+ exports.buildTypesTask = buildTypesTask;
@@ -0,0 +1,40 @@
1
+ import "vite";
2
+ import { errors } from "../../errors.mjs";
3
+ import { callTypescript } from "./callTypescript.mjs";
4
+ import { reverseMap } from "../utils.mjs";
5
+ async function buildTypesTask({
6
+ buildOutput,
7
+ entrypoints,
8
+ sourceDir,
9
+ outDir
10
+ }) {
11
+ const reversedEntrypoints = reverseMap(entrypoints);
12
+ const tsEntrypoints = [...entrypoints.values()].filter(
13
+ (entry) => entry.endsWith(".ts")
14
+ );
15
+ if (tsEntrypoints.length === 0) {
16
+ return /* @__PURE__ */ new Map();
17
+ }
18
+ let ts;
19
+ try {
20
+ ts = await import("typescript");
21
+ } catch {
22
+ throw errors.typescriptNotFound;
23
+ }
24
+ const files = buildOutput.map((el) => el.facadeModuleId ?? "");
25
+ const dtsMap = await callTypescript({ ts, sourceDir, files, outDir });
26
+ const result = /* @__PURE__ */ new Map();
27
+ for (const [types, source] of dtsMap) {
28
+ const exportPath = reversedEntrypoints.get(source);
29
+ if (!exportPath) {
30
+ continue;
31
+ }
32
+ for (const path of exportPath) {
33
+ result.set(types, path);
34
+ }
35
+ }
36
+ return result;
37
+ }
38
+ export {
39
+ buildTypesTask
40
+ };
@@ -1,17 +1,37 @@
1
- import * as path from "node:path";
2
- import * as fs from "node:fs";
1
+ "use strict";
2
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
+ const path = require("node:path");
4
+ const fs = require("node:fs");
5
+ function _interopNamespaceDefault(e) {
6
+ const n = Object.create(null, { [Symbol.toStringTag]: { value: "Module" } });
7
+ if (e) {
8
+ for (const k in e) {
9
+ if (k !== "default") {
10
+ const d = Object.getOwnPropertyDescriptor(e, k);
11
+ Object.defineProperty(n, k, d.get ? d : {
12
+ enumerable: true,
13
+ get: () => e[k]
14
+ });
15
+ }
16
+ }
17
+ }
18
+ n.default = e;
19
+ return Object.freeze(n);
20
+ }
21
+ const path__namespace = /* @__PURE__ */ _interopNamespaceDefault(path);
22
+ const fs__namespace = /* @__PURE__ */ _interopNamespaceDefault(fs);
3
23
  async function callTypescript({
4
24
  ts,
5
25
  sourceDir,
6
26
  files,
7
27
  outDir
8
28
  }) {
9
- const configPath = path.join(sourceDir, "tsconfig.json");
29
+ const configPath = path__namespace.join(sourceDir, "tsconfig.json");
10
30
  const configFile = ts.readConfigFile(
11
31
  configPath,
12
32
  (path2) => (
13
33
  // https://github.com/XaveScor/bobrik/issues/22
14
- fs.readFileSync(path2, "utf-8")
34
+ fs__namespace.readFileSync(path2, "utf-8")
15
35
  )
16
36
  );
17
37
  const parsedCommandLine = ts.parseJsonConfigFileContent(
@@ -36,15 +56,16 @@ async function callTypescript({
36
56
  const sourceToDtsMap = /* @__PURE__ */ new Map();
37
57
  const program = ts.createProgram(files, parsedCommandLine.options, host);
38
58
  program.emit(void 0, (fileName, data) => {
39
- const relativePath = path.relative(sourceDir, fileName);
40
- const finalPath = path.join(outDir, relativePath);
59
+ const relativePath = path__namespace.relative(sourceDir, fileName);
60
+ const esmFinalPath = path__namespace.join(outDir, relativePath);
41
61
  const sourceFileName = fileName.replace(/\.d\.ts$/, ".ts");
42
- sourceToDtsMap.set(sourceFileName, finalPath);
43
- fs.mkdirSync(path.dirname(finalPath), { recursive: true });
44
- fs.writeFileSync(finalPath, data);
62
+ sourceToDtsMap.set(esmFinalPath, sourceFileName);
63
+ fs__namespace.mkdirSync(path__namespace.dirname(esmFinalPath), { recursive: true });
64
+ fs__namespace.writeFileSync(esmFinalPath, data);
65
+ const cjsFinalPath = esmFinalPath.replace(/\.d\.ts$/, ".d.cts");
66
+ fs__namespace.writeFileSync(cjsFinalPath, data);
67
+ sourceToDtsMap.set(cjsFinalPath, sourceFileName);
45
68
  });
46
69
  return sourceToDtsMap;
47
70
  }
48
- export {
49
- callTypescript
50
- };
71
+ exports.callTypescript = callTypescript;
@@ -0,0 +1,53 @@
1
+ import * as path from "node:path";
2
+ import * as fs from "node:fs";
3
+ async function callTypescript({
4
+ ts,
5
+ sourceDir,
6
+ files,
7
+ outDir
8
+ }) {
9
+ const configPath = path.join(sourceDir, "tsconfig.json");
10
+ const configFile = ts.readConfigFile(
11
+ configPath,
12
+ (path2) => (
13
+ // https://github.com/XaveScor/bobrik/issues/22
14
+ fs.readFileSync(path2, "utf-8")
15
+ )
16
+ );
17
+ const parsedCommandLine = ts.parseJsonConfigFileContent(
18
+ configFile.config,
19
+ ts.sys,
20
+ sourceDir,
21
+ {
22
+ declaration: true,
23
+ emitDeclarationOnly: true,
24
+ strict: false,
25
+ strictNullChecks: false,
26
+ strictFunctionTypes: false,
27
+ strictPropertyInitialization: false,
28
+ skipLibCheck: true,
29
+ skipDefaultLibCheck: true,
30
+ // https://github.com/XaveScor/bobrik/issues/22#issuecomment-2308552352
31
+ noEmit: false
32
+ },
33
+ configPath
34
+ );
35
+ const host = ts.createCompilerHost(parsedCommandLine.options);
36
+ const sourceToDtsMap = /* @__PURE__ */ new Map();
37
+ const program = ts.createProgram(files, parsedCommandLine.options, host);
38
+ program.emit(void 0, (fileName, data) => {
39
+ const relativePath = path.relative(sourceDir, fileName);
40
+ const esmFinalPath = path.join(outDir, relativePath);
41
+ const sourceFileName = fileName.replace(/\.d\.ts$/, ".ts");
42
+ sourceToDtsMap.set(esmFinalPath, sourceFileName);
43
+ fs.mkdirSync(path.dirname(esmFinalPath), { recursive: true });
44
+ fs.writeFileSync(esmFinalPath, data);
45
+ const cjsFinalPath = esmFinalPath.replace(/\.d\.ts$/, ".d.cts");
46
+ fs.writeFileSync(cjsFinalPath, data);
47
+ sourceToDtsMap.set(cjsFinalPath, sourceFileName);
48
+ });
49
+ return sourceToDtsMap;
50
+ }
51
+ export {
52
+ callTypescript
53
+ };
@@ -1,5 +1,7 @@
1
- import { join } from "node:path";
2
- import { readdir, copyFile } from "node:fs/promises";
1
+ "use strict";
2
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
+ const path = require("node:path");
4
+ const fs = require("node:fs/promises");
3
5
  async function copyStaticFilesTask(sourceDir, outDir) {
4
6
  return copyStaticFiles({
5
7
  relativeFiles: /* @__PURE__ */ new Set(["readme.md"]),
@@ -13,7 +15,7 @@ async function copyStaticFiles({
13
15
  relativeFiles
14
16
  }) {
15
17
  const dirFiles = new Map(
16
- (await readdir(sourceDir, { recursive: true })).map(
18
+ (await fs.readdir(sourceDir, { recursive: true })).map(
17
19
  (f) => [f.toLowerCase(), f]
18
20
  )
19
21
  );
@@ -21,14 +23,12 @@ async function copyStaticFiles({
21
23
  try {
22
24
  const matchingFile = dirFiles.get(file.toLowerCase());
23
25
  if (matchingFile) {
24
- const outFilePath = join(outDir, matchingFile);
25
- const filePath = join(sourceDir, matchingFile);
26
- await copyFile(filePath, outFilePath);
26
+ const outFilePath = path.join(outDir, matchingFile);
27
+ const filePath = path.join(sourceDir, matchingFile);
28
+ await fs.copyFile(filePath, outFilePath);
27
29
  }
28
30
  } catch {
29
31
  }
30
32
  }
31
33
  }
32
- export {
33
- copyStaticFilesTask
34
- };
34
+ exports.copyStaticFilesTask = copyStaticFilesTask;
@@ -1,7 +1,5 @@
1
- "use strict";
2
- Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
- const path = require("node:path");
4
- const fs = require("node:fs/promises");
1
+ import { join } from "node:path";
2
+ import { readdir, copyFile } from "node:fs/promises";
5
3
  async function copyStaticFilesTask(sourceDir, outDir) {
6
4
  return copyStaticFiles({
7
5
  relativeFiles: /* @__PURE__ */ new Set(["readme.md"]),
@@ -15,7 +13,7 @@ async function copyStaticFiles({
15
13
  relativeFiles
16
14
  }) {
17
15
  const dirFiles = new Map(
18
- (await fs.readdir(sourceDir, { recursive: true })).map(
16
+ (await readdir(sourceDir, { recursive: true })).map(
19
17
  (f) => [f.toLowerCase(), f]
20
18
  )
21
19
  );
@@ -23,12 +21,14 @@ async function copyStaticFiles({
23
21
  try {
24
22
  const matchingFile = dirFiles.get(file.toLowerCase());
25
23
  if (matchingFile) {
26
- const outFilePath = path.join(outDir, matchingFile);
27
- const filePath = path.join(sourceDir, matchingFile);
28
- await fs.copyFile(filePath, outFilePath);
24
+ const outFilePath = join(outDir, matchingFile);
25
+ const filePath = join(sourceDir, matchingFile);
26
+ await copyFile(filePath, outFilePath);
29
27
  }
30
28
  } catch {
31
29
  }
32
30
  }
33
31
  }
34
- exports.copyStaticFilesTask = copyStaticFilesTask;
32
+ export {
33
+ copyStaticFilesTask
34
+ };
@@ -1,10 +1,12 @@
1
- import "vite";
2
- import { reverseMap } from "./utils.js";
1
+ "use strict";
2
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
+ require("vite");
4
+ const utils = require("./utils.js");
3
5
  async function jsFilesTask({
4
6
  buildOutput,
5
7
  entrypoints
6
8
  }) {
7
- const reversedEntrypoints = reverseMap(entrypoints);
9
+ const reversedEntrypoints = utils.reverseMap(entrypoints);
8
10
  const res = /* @__PURE__ */ new Map();
9
11
  for (const el of buildOutput) {
10
12
  if (el.facadeModuleId == null) {
@@ -20,6 +22,4 @@ async function jsFilesTask({
20
22
  }
21
23
  return res;
22
24
  }
23
- export {
24
- jsFilesTask
25
- };
25
+ exports.jsFilesTask = jsFilesTask;
@@ -1,12 +1,10 @@
1
- "use strict";
2
- Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
- require("vite");
4
- const utils = require("./utils.cjs");
1
+ import "vite";
2
+ import { reverseMap } from "./utils.mjs";
5
3
  async function jsFilesTask({
6
4
  buildOutput,
7
5
  entrypoints
8
6
  }) {
9
- const reversedEntrypoints = utils.reverseMap(entrypoints);
7
+ const reversedEntrypoints = reverseMap(entrypoints);
10
8
  const res = /* @__PURE__ */ new Map();
11
9
  for (const el of buildOutput) {
12
10
  if (el.facadeModuleId == null) {
@@ -22,4 +20,6 @@ async function jsFilesTask({
22
20
  }
23
21
  return res;
24
22
  }
25
- exports.jsFilesTask = jsFilesTask;
23
+ export {
24
+ jsFilesTask
25
+ };
@@ -1,3 +1,5 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
1
3
  function reverseMap(map) {
2
4
  const reversed = /* @__PURE__ */ new Map();
3
5
  for (const [key, value] of map) {
@@ -7,6 +9,4 @@ function reverseMap(map) {
7
9
  }
8
10
  return reversed;
9
11
  }
10
- export {
11
- reverseMap
12
- };
12
+ exports.reverseMap = reverseMap;