smartbundle 0.6.0 → 0.7.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 (52) hide show
  1. package/README.md +7 -1
  2. package/__do_not_import_directly__/createViteConfig.cjs +14 -7
  3. package/__do_not_import_directly__/createViteConfig.js +14 -7
  4. package/__do_not_import_directly__/error.cjs +9 -0
  5. package/__do_not_import_directly__/error.js +9 -0
  6. package/__do_not_import_directly__/errors.cjs +1 -1
  7. package/__do_not_import_directly__/errors.js +1 -1
  8. package/__do_not_import_directly__/packageJson.cjs +32 -1
  9. package/__do_not_import_directly__/packageJson.js +32 -1
  10. package/__do_not_import_directly__/resolveDirs.cjs +2 -1
  11. package/__do_not_import_directly__/resolveDirs.js +2 -1
  12. package/__do_not_import_directly__/smartbundle.cjs +4 -0
  13. package/__do_not_import_directly__/smartbundle.js +3 -0
  14. package/__do_not_import_directly__/tasks/binsTask.cjs +40 -0
  15. package/__do_not_import_directly__/tasks/binsTask.js +40 -0
  16. package/{src/bin.cjs → __do_not_import_directly__/tasks/buildTypesTask/buildTypesTask.cjs} +39 -2
  17. package/__do_not_import_directly__/tasks/buildTypesTask/buildTypesTask.js +40 -0
  18. package/__do_not_import_directly__/{buildTypes.cjs → tasks/buildTypesTask/callTypescript.cjs} +3 -26
  19. package/__do_not_import_directly__/{buildTypes.js → tasks/buildTypesTask/callTypescript.js} +3 -4
  20. package/__do_not_import_directly__/{copyStaticFiles.cjs → tasks/copyStaticFilesTask.cjs} +8 -1
  21. package/__do_not_import_directly__/{copyStaticFiles.js → tasks/copyStaticFilesTask.js} +8 -1
  22. package/__do_not_import_directly__/tasks/jsFilesTask.cjs +25 -0
  23. package/__do_not_import_directly__/tasks/jsFilesTask.js +25 -0
  24. package/__do_not_import_directly__/tasks/utils.cjs +12 -0
  25. package/__do_not_import_directly__/tasks/utils.js +12 -0
  26. package/__do_not_import_directly__/writePackageJson.cjs +5 -6
  27. package/__do_not_import_directly__/writePackageJson.js +5 -6
  28. package/__smartbundle__internals__/smartbundle +2 -0
  29. package/package.json +13 -11
  30. package/src/buildVite.d.ts +1 -1
  31. package/src/createViteConfig.d.ts +1 -0
  32. package/src/error.d.ts +4 -0
  33. package/src/errors.d.ts +1 -1
  34. package/src/index.cjs +102 -0
  35. package/src/index.js +102 -0
  36. package/src/packageJson.d.ts +3 -3
  37. package/src/resolveDirs.d.ts +1 -0
  38. package/src/tasks/binsTask.d.ts +9 -0
  39. package/src/tasks/buildTypesTask/buildTypesTask.d.ts +9 -0
  40. package/src/tasks/buildTypesTask/callTypescript.d.ts +8 -0
  41. package/src/tasks/copyStaticFilesTask.d.ts +1 -0
  42. package/src/tasks/jsFilesTask.d.ts +7 -0
  43. package/src/tasks/utils.d.ts +1 -0
  44. package/src/writePackageJson.d.ts +3 -2
  45. package/__do_not_import_directly__/index.cjs +0 -120
  46. package/__do_not_import_directly__/index.js +0 -98
  47. package/src/bin.d.ts +0 -2
  48. package/src/bin.js +0 -2
  49. package/src/buildTypes.d.ts +0 -7
  50. package/src/copyStaticFiles.d.ts +0 -7
  51. package/src/run.cjs +0 -4
  52. package/src/run.js +0 -3
package/README.md CHANGED
@@ -19,6 +19,12 @@ npx smartbundle
19
19
  ```
20
20
  3) Go to the `dist` folder and publish your package to the npm registry. The total package.json will be generated automatically.
21
21
 
22
+ ## Supported targets
23
+ - Bun 1+
24
+ - Node ^18.0.0, ^20.0.0, ^22.0.0, ^23.0.0
25
+ - Webpack ^4.47.0, ^5.95.0
26
+ - Rspack ^1.0.0
27
+
22
28
  ## Features
23
29
  - generate the most compatible package.json for any bundlers(webpack, rollup, esbuild, vite, etc) or runtimes(node, bun, deno, etc)
24
30
  - validate package.json for common errors
@@ -38,4 +44,4 @@ Almost every npm package have the same build pipeline: build code, generate type
38
44
 
39
45
  I really like the [microbundle](https://github.com/developit/microbundle) project, but it requires a lot of extra configuration and is not zero-config. And more, the project is not maintained and does not support a lot of modern js features.
40
46
 
41
- So I decided to create my own project to automate the build pipeline and save the developer's time for building packages.
47
+ So I decided to create my own project to automate the build pipeline and save the developer's time for building packages.
@@ -1,12 +1,17 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
3
  const path = require("node:path");
4
+ require("node:fs/promises");
5
+ require("zod");
4
6
  const vite = require("vite");
5
- function mapToObject(map) {
7
+ function mapToObject(map, bins) {
6
8
  const obj = {};
7
9
  for (const [key, value] of map) {
8
10
  obj[key] = value;
9
11
  }
12
+ for (const [key, value] of bins) {
13
+ obj[key] = value;
14
+ }
10
15
  return obj;
11
16
  }
12
17
  function createExternalDepValidator(packageJson) {
@@ -41,14 +46,16 @@ function createViteConfig({ dirs, packageJson }) {
41
46
  const { sourceDir, outDir } = dirs;
42
47
  const entrypoints = /* @__PURE__ */ new Map();
43
48
  if (packageJson.exports) {
44
- for (const [key, value] of packageJson.exports.entries()) {
49
+ for (const [key, value] of packageJson.exports) {
45
50
  const entry = path.join(sourceDir, value);
46
51
  entrypoints.set(key, entry);
47
52
  }
48
53
  }
54
+ const bins = /* @__PURE__ */ new Map();
49
55
  if (packageJson.bin) {
50
- const binEntry = path.join(sourceDir, packageJson.bin);
51
- entrypoints.set("__bin__", binEntry);
56
+ for (const [key, value] of packageJson.bin) {
57
+ bins.set(key, path.join(sourceDir, value));
58
+ }
52
59
  }
53
60
  const depsValidator = createExternalDepValidator(packageJson);
54
61
  const viteConfig = vite.defineConfig({
@@ -57,14 +64,14 @@ function createViteConfig({ dirs, packageJson }) {
57
64
  outDir,
58
65
  write: true,
59
66
  minify: false,
60
- emptyOutDir: true,
67
+ emptyOutDir: false,
61
68
  assetsInlineLimit: 0,
62
69
  terserOptions: {
63
70
  compress: false,
64
71
  mangle: false
65
72
  },
66
73
  lib: {
67
- entry: mapToObject(entrypoints),
74
+ entry: mapToObject(entrypoints, bins),
68
75
  formats: ["es", "cjs"],
69
76
  fileName: (format, entryName) => {
70
77
  const entrypoint = entrypoints.get(entryName);
@@ -92,6 +99,6 @@ function createViteConfig({ dirs, packageJson }) {
92
99
  }
93
100
  }
94
101
  });
95
- return { viteConfig, entrypoints };
102
+ return { viteConfig, entrypoints, bins };
96
103
  }
97
104
  exports.createViteConfig = createViteConfig;
@@ -1,10 +1,15 @@
1
1
  import { join, relative } from "node:path";
2
+ import "node:fs/promises";
3
+ import "zod";
2
4
  import { defineConfig } from "vite";
3
- function mapToObject(map) {
5
+ function mapToObject(map, bins) {
4
6
  const obj = {};
5
7
  for (const [key, value] of map) {
6
8
  obj[key] = value;
7
9
  }
10
+ for (const [key, value] of bins) {
11
+ obj[key] = value;
12
+ }
8
13
  return obj;
9
14
  }
10
15
  function createExternalDepValidator(packageJson) {
@@ -39,14 +44,16 @@ function createViteConfig({ dirs, packageJson }) {
39
44
  const { sourceDir, outDir } = dirs;
40
45
  const entrypoints = /* @__PURE__ */ new Map();
41
46
  if (packageJson.exports) {
42
- for (const [key, value] of packageJson.exports.entries()) {
47
+ for (const [key, value] of packageJson.exports) {
43
48
  const entry = join(sourceDir, value);
44
49
  entrypoints.set(key, entry);
45
50
  }
46
51
  }
52
+ const bins = /* @__PURE__ */ new Map();
47
53
  if (packageJson.bin) {
48
- const binEntry = join(sourceDir, packageJson.bin);
49
- entrypoints.set("__bin__", binEntry);
54
+ for (const [key, value] of packageJson.bin) {
55
+ bins.set(key, join(sourceDir, value));
56
+ }
50
57
  }
51
58
  const depsValidator = createExternalDepValidator(packageJson);
52
59
  const viteConfig = defineConfig({
@@ -55,14 +62,14 @@ function createViteConfig({ dirs, packageJson }) {
55
62
  outDir,
56
63
  write: true,
57
64
  minify: false,
58
- emptyOutDir: true,
65
+ emptyOutDir: false,
59
66
  assetsInlineLimit: 0,
60
67
  terserOptions: {
61
68
  compress: false,
62
69
  mangle: false
63
70
  },
64
71
  lib: {
65
- entry: mapToObject(entrypoints),
72
+ entry: mapToObject(entrypoints, bins),
66
73
  formats: ["es", "cjs"],
67
74
  fileName: (format, entryName) => {
68
75
  const entrypoint = entrypoints.get(entryName);
@@ -90,7 +97,7 @@ function createViteConfig({ dirs, packageJson }) {
90
97
  }
91
98
  }
92
99
  });
93
- return { viteConfig, entrypoints };
100
+ return { viteConfig, entrypoints, bins };
94
101
  }
95
102
  export {
96
103
  createViteConfig
@@ -0,0 +1,9 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
+ class BuildError extends Error {
4
+ constructor(error) {
5
+ super(error);
6
+ this.error = error;
7
+ }
8
+ }
9
+ exports.BuildError = BuildError;
@@ -0,0 +1,9 @@
1
+ class BuildError extends Error {
2
+ constructor(error) {
3
+ super(error);
4
+ this.error = error;
5
+ }
6
+ }
7
+ export {
8
+ BuildError
9
+ };
@@ -11,7 +11,7 @@ const errors = {
11
11
  privateIsTrue: "The `private` field must be `true` for avoiding accidental publish. More info: https://docs.npmjs.com/cli/v10/configuring-npm/package-json#private",
12
12
  descriptionString: "The `description` field must be a string. Please, verify the value. More info: https://docs.npmjs.com/cli/v10/configuring-npm/package-json#description",
13
13
  dependenciesInvalid: "The `dependencies` field must be an Object<string, string>. Please, verify the value. More info: https://docs.npmjs.com/cli/v10/configuring-npm/package-json#dependencies",
14
- binString: "The `bin` field must be a string. Please, verify the value. More info: https://docs.npmjs.com/cli/v10/configuring-npm/package-json#bin",
14
+ binFiled: "The `bin` field must be a path or Record<string, FilePath>. Please, verify the value. More info: https://docs.npmjs.com/cli/v10/configuring-npm/package-json#bin",
15
15
  rollupError: "An error occurred while building the package. Please, report it to the issues on GitHub",
16
16
  typescriptNotFound: "The package.json contains typescript entrypoints, but the typescript package is not found. Please, install typescript@^5.0.0",
17
17
  optionalDependenciesInvalid: "The `optionalDependencies` field must be an Object<string, string>. Please, verify the value. More info: https://docs.npmjs.com/cli/v10/configuring-npm/package-json#optionaldependencies",
@@ -9,7 +9,7 @@ const errors = {
9
9
  privateIsTrue: "The `private` field must be `true` for avoiding accidental publish. More info: https://docs.npmjs.com/cli/v10/configuring-npm/package-json#private",
10
10
  descriptionString: "The `description` field must be a string. Please, verify the value. More info: https://docs.npmjs.com/cli/v10/configuring-npm/package-json#description",
11
11
  dependenciesInvalid: "The `dependencies` field must be an Object<string, string>. Please, verify the value. More info: https://docs.npmjs.com/cli/v10/configuring-npm/package-json#dependencies",
12
- binString: "The `bin` field must be a string. Please, verify the value. More info: https://docs.npmjs.com/cli/v10/configuring-npm/package-json#bin",
12
+ binFiled: "The `bin` field must be a path or Record<string, FilePath>. Please, verify the value. More info: https://docs.npmjs.com/cli/v10/configuring-npm/package-json#bin",
13
13
  rollupError: "An error occurred while building the package. Please, report it to the issues on GitHub",
14
14
  typescriptNotFound: "The package.json contains typescript entrypoints, but the typescript package is not found. Please, install typescript@^5.0.0",
15
15
  optionalDependenciesInvalid: "The `optionalDependencies` field must be an Object<string, string>. Please, verify the value. More info: https://docs.npmjs.com/cli/v10/configuring-npm/package-json#optionaldependencies",
@@ -38,6 +38,16 @@ function createPathValidator(sourceDir) {
38
38
  return fileExists(finalPath);
39
39
  };
40
40
  }
41
+ const PackageJsonNameField = "___NAME___";
42
+ function fillPackageJson(packageJson) {
43
+ if (packageJson.bin) {
44
+ const binName = packageJson.bin.get(PackageJsonNameField);
45
+ if (binName) {
46
+ packageJson.bin.set(packageJson.name, binName);
47
+ packageJson.bin.delete(PackageJsonNameField);
48
+ }
49
+ }
50
+ }
41
51
  function createPackageJsonSchema(sourceDir) {
42
52
  const pathValidator = createPathValidator(sourceDir);
43
53
  return z.object({
@@ -68,7 +78,27 @@ function createPackageJsonSchema(sourceDir) {
68
78
  description: z.string({ message: errors.errors.descriptionString }).optional(),
69
79
  dependencies: dependencies(errors.errors.dependenciesInvalid),
70
80
  optionalDependencies: dependencies(errors.errors.optionalDependenciesInvalid),
71
- bin: z.string({ message: errors.errors.binString }).optional(),
81
+ bin: z.union(
82
+ [
83
+ z.string().transform((value) => /* @__PURE__ */ new Map([[PackageJsonNameField, value]])),
84
+ z.record(z.string()).transform((record) => new Map(Object.entries(record)))
85
+ ],
86
+ {
87
+ errorMap() {
88
+ return { message: errors.errors.binFiled };
89
+ }
90
+ }
91
+ ).refine(
92
+ async (map) => {
93
+ for (const [key, value] of map.entries()) {
94
+ if (!await pathValidator(value)) {
95
+ return false;
96
+ }
97
+ }
98
+ return true;
99
+ },
100
+ { message: errors.errors.binFiled }
101
+ ).optional(),
72
102
  repository: z.any().optional(),
73
103
  keywords: z.array(z.string(), { message: errors.errors.keywordsInvalid }).optional(),
74
104
  author: z.any().optional(),
@@ -110,6 +140,7 @@ async function parsePackageJson({
110
140
  if (!packageJson.success) {
111
141
  return packageJson.error.errors.map((error) => error.message);
112
142
  }
143
+ fillPackageJson(packageJson.data);
113
144
  return packageJson.data;
114
145
  }
115
146
  exports.parsePackageJson = parsePackageJson;
@@ -19,6 +19,16 @@ function createPathValidator(sourceDir) {
19
19
  return fileExists(finalPath);
20
20
  };
21
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
+ }
22
32
  function createPackageJsonSchema(sourceDir) {
23
33
  const pathValidator = createPathValidator(sourceDir);
24
34
  return z.object({
@@ -49,7 +59,27 @@ function createPackageJsonSchema(sourceDir) {
49
59
  description: z.string({ message: errors.descriptionString }).optional(),
50
60
  dependencies: dependencies(errors.dependenciesInvalid),
51
61
  optionalDependencies: dependencies(errors.optionalDependenciesInvalid),
52
- bin: z.string({ message: errors.binString }).optional(),
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(),
53
83
  repository: z.any().optional(),
54
84
  keywords: z.array(z.string(), { message: errors.keywordsInvalid }).optional(),
55
85
  author: z.any().optional(),
@@ -91,6 +121,7 @@ async function parsePackageJson({
91
121
  if (!packageJson.success) {
92
122
  return packageJson.error.errors.map((error) => error.message);
93
123
  }
124
+ fillPackageJson(packageJson.data);
94
125
  return packageJson.data;
95
126
  }
96
127
  export {
@@ -14,6 +14,7 @@ function resolveDirs(args) {
14
14
  args.packagePath ?? "./package.json"
15
15
  );
16
16
  const outDir = myResolve(process.cwd(), args.outputDir ?? "./dist");
17
- return { sourceDir, packagePath, outDir };
17
+ const outInternalsDir = myResolve(outDir, "__smartbundle__internals__");
18
+ return { sourceDir, packagePath, outDir, outInternalsDir };
18
19
  }
19
20
  exports.resolveDirs = resolveDirs;
@@ -12,7 +12,8 @@ function resolveDirs(args) {
12
12
  args.packagePath ?? "./package.json"
13
13
  );
14
14
  const outDir = myResolve(process.cwd(), args.outputDir ?? "./dist");
15
- return { sourceDir, packagePath, outDir };
15
+ const outInternalsDir = myResolve(outDir, "__smartbundle__internals__");
16
+ return { sourceDir, packagePath, outDir, outInternalsDir };
16
17
  }
17
18
  export {
18
19
  resolveDirs
@@ -0,0 +1,4 @@
1
+ "use strict";
2
+ const args = require("./args.cjs");
3
+ const _ = require("../src/index.cjs");
4
+ _.run(args.args);
@@ -0,0 +1,3 @@
1
+ import { args } from "./args.js";
2
+ import { run } from "../src/index.js";
3
+ run(args);
@@ -0,0 +1,40 @@
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");
7
+ async function binsTask({
8
+ buildOutput,
9
+ bins,
10
+ outInternalsDir,
11
+ outDir
12
+ }) {
13
+ const reversedEntrypoints = utils.reverseMap(bins);
14
+ const res = /* @__PURE__ */ new Map();
15
+ for (const el of buildOutput) {
16
+ if (el.facadeModuleId == null) {
17
+ continue;
18
+ }
19
+ if (el.fileName.endsWith(".cjs")) {
20
+ continue;
21
+ }
22
+ const binsPath = reversedEntrypoints.get(el.facadeModuleId);
23
+ if (!binsPath) {
24
+ continue;
25
+ }
26
+ for (const path$1 of binsPath) {
27
+ const totalPath = path.relative(outInternalsDir, path.join(outDir, el.fileName));
28
+ const execPath = path.join(outInternalsDir, path$1);
29
+ await fs.writeFile(
30
+ execPath,
31
+ `#!/usr/bin/env node
32
+ import("${totalPath}");
33
+ `
34
+ );
35
+ res.set(path.relative(outDir, execPath), path$1);
36
+ }
37
+ }
38
+ return res;
39
+ }
40
+ exports.binsTask = binsTask;
@@ -0,0 +1,40 @@
1
+ import { writeFile } from "node:fs/promises";
2
+ import { relative, join } from "node:path";
3
+ import "vite";
4
+ import { reverseMap } from "./utils.js";
5
+ async function binsTask({
6
+ buildOutput,
7
+ bins,
8
+ outInternalsDir,
9
+ outDir
10
+ }) {
11
+ const reversedEntrypoints = reverseMap(bins);
12
+ const res = /* @__PURE__ */ new Map();
13
+ for (const el of buildOutput) {
14
+ if (el.facadeModuleId == null) {
15
+ continue;
16
+ }
17
+ if (el.fileName.endsWith(".cjs")) {
18
+ continue;
19
+ }
20
+ const binsPath = reversedEntrypoints.get(el.facadeModuleId);
21
+ if (!binsPath) {
22
+ continue;
23
+ }
24
+ for (const path of binsPath) {
25
+ const totalPath = relative(outInternalsDir, join(outDir, el.fileName));
26
+ const execPath = join(outInternalsDir, path);
27
+ await writeFile(
28
+ execPath,
29
+ `#!/usr/bin/env node
30
+ import("${totalPath}");
31
+ `
32
+ );
33
+ res.set(relative(outDir, execPath), path);
34
+ }
35
+ }
36
+ return res;
37
+ }
38
+ export {
39
+ binsTask
40
+ };
@@ -1,4 +1,3 @@
1
- #!/usr/bin/env node
2
1
  "use strict";
3
2
  var __create = Object.create;
4
3
  var __defProp = Object.defineProperty;
@@ -22,4 +21,42 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
22
21
  isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
23
22
  mod
24
23
  ));
25
- import("smartbundle");
24
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
25
+ require("vite");
26
+ const errors = require("../../errors.cjs");
27
+ const callTypescript = require("./callTypescript.cjs");
28
+ const utils = require("../utils.cjs");
29
+ async function buildTypesTask({
30
+ buildOutput,
31
+ entrypoints,
32
+ sourceDir,
33
+ outDir
34
+ }) {
35
+ const reversedEntrypoints = utils.reverseMap(entrypoints);
36
+ const tsEntrypoints = [...entrypoints.values()].filter(
37
+ (entry) => entry.endsWith(".ts")
38
+ );
39
+ if (tsEntrypoints.length === 0) {
40
+ return /* @__PURE__ */ new Map();
41
+ }
42
+ let ts;
43
+ try {
44
+ ts = await import("typescript");
45
+ } catch {
46
+ throw errors.errors.typescriptNotFound;
47
+ }
48
+ const files = buildOutput.map((el) => el.facadeModuleId ?? "");
49
+ const dtsMap = await callTypescript.callTypescript({ ts, sourceDir, files, outDir });
50
+ const result = /* @__PURE__ */ new Map();
51
+ for (const [source, dts] of dtsMap) {
52
+ const exportPath = reversedEntrypoints.get(source);
53
+ if (!exportPath) {
54
+ continue;
55
+ }
56
+ for (const path of exportPath) {
57
+ result.set(dts, path);
58
+ }
59
+ }
60
+ return result;
61
+ }
62
+ exports.buildTypesTask = buildTypesTask;
@@ -0,0 +1,40 @@
1
+ import "vite";
2
+ import { errors } from "../../errors.js";
3
+ import { callTypescript } from "./callTypescript.js";
4
+ import { reverseMap } from "../utils.js";
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 [source, dts] of dtsMap) {
28
+ const exportPath = reversedEntrypoints.get(source);
29
+ if (!exportPath) {
30
+ continue;
31
+ }
32
+ for (const path of exportPath) {
33
+ result.set(dts, path);
34
+ }
35
+ }
36
+ return result;
37
+ }
38
+ export {
39
+ buildTypesTask
40
+ };
@@ -1,26 +1,4 @@
1
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
2
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
25
3
  const path = require("node:path");
26
4
  const fs = require("node:fs");
@@ -42,13 +20,12 @@ function _interopNamespaceDefault(e) {
42
20
  }
43
21
  const path__namespace = /* @__PURE__ */ _interopNamespaceDefault(path);
44
22
  const fs__namespace = /* @__PURE__ */ _interopNamespaceDefault(fs);
45
- async function buildTypes({
23
+ async function callTypescript({
24
+ ts,
46
25
  sourceDir,
47
26
  files,
48
27
  outDir
49
28
  }) {
50
- const importedTs = await import("typescript");
51
- const ts = importedTs.default ?? importedTs;
52
29
  const configPath = path__namespace.join(sourceDir, "tsconfig.json");
53
30
  const configFile = ts.readConfigFile(
54
31
  configPath,
@@ -88,4 +65,4 @@ async function buildTypes({
88
65
  });
89
66
  return sourceToDtsMap;
90
67
  }
91
- exports.buildTypes = buildTypes;
68
+ exports.callTypescript = callTypescript;
@@ -1,12 +1,11 @@
1
1
  import * as path from "node:path";
2
2
  import * as fs from "node:fs";
3
- async function buildTypes({
3
+ async function callTypescript({
4
+ ts,
4
5
  sourceDir,
5
6
  files,
6
7
  outDir
7
8
  }) {
8
- const importedTs = await import("typescript");
9
- const ts = importedTs.default ?? importedTs;
10
9
  const configPath = path.join(sourceDir, "tsconfig.json");
11
10
  const configFile = ts.readConfigFile(
12
11
  configPath,
@@ -47,5 +46,5 @@ async function buildTypes({
47
46
  return sourceToDtsMap;
48
47
  }
49
48
  export {
50
- buildTypes
49
+ callTypescript
51
50
  };
@@ -2,6 +2,13 @@
2
2
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
3
  const path = require("node:path");
4
4
  const fs = require("node:fs/promises");
5
+ async function copyStaticFilesTask(sourceDir, outDir) {
6
+ return copyStaticFiles({
7
+ relativeFiles: /* @__PURE__ */ new Set(["readme.md"]),
8
+ sourceDir,
9
+ outDir
10
+ });
11
+ }
5
12
  async function copyStaticFiles({
6
13
  sourceDir,
7
14
  outDir,
@@ -24,4 +31,4 @@ async function copyStaticFiles({
24
31
  }
25
32
  }
26
33
  }
27
- exports.copyStaticFiles = copyStaticFiles;
34
+ exports.copyStaticFilesTask = copyStaticFilesTask;
@@ -1,5 +1,12 @@
1
1
  import { join } from "node:path";
2
2
  import { readdir, copyFile } from "node:fs/promises";
3
+ async function copyStaticFilesTask(sourceDir, outDir) {
4
+ return copyStaticFiles({
5
+ relativeFiles: /* @__PURE__ */ new Set(["readme.md"]),
6
+ sourceDir,
7
+ outDir
8
+ });
9
+ }
3
10
  async function copyStaticFiles({
4
11
  sourceDir,
5
12
  outDir,
@@ -23,5 +30,5 @@ async function copyStaticFiles({
23
30
  }
24
31
  }
25
32
  export {
26
- copyStaticFiles
33
+ copyStaticFilesTask
27
34
  };
@@ -0,0 +1,25 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
+ require("vite");
4
+ const utils = require("./utils.cjs");
5
+ async function jsFilesTask({
6
+ buildOutput,
7
+ entrypoints
8
+ }) {
9
+ const reversedEntrypoints = utils.reverseMap(entrypoints);
10
+ const res = /* @__PURE__ */ new Map();
11
+ for (const el of buildOutput) {
12
+ if (el.facadeModuleId == null) {
13
+ continue;
14
+ }
15
+ const exportPath = reversedEntrypoints.get(el.facadeModuleId);
16
+ if (!exportPath) {
17
+ continue;
18
+ }
19
+ for (const path of exportPath) {
20
+ res.set(el.fileName, path);
21
+ }
22
+ }
23
+ return res;
24
+ }
25
+ exports.jsFilesTask = jsFilesTask;
@@ -0,0 +1,25 @@
1
+ import "vite";
2
+ import { reverseMap } from "./utils.js";
3
+ async function jsFilesTask({
4
+ buildOutput,
5
+ entrypoints
6
+ }) {
7
+ const reversedEntrypoints = reverseMap(entrypoints);
8
+ const res = /* @__PURE__ */ new Map();
9
+ for (const el of buildOutput) {
10
+ if (el.facadeModuleId == null) {
11
+ continue;
12
+ }
13
+ const exportPath = reversedEntrypoints.get(el.facadeModuleId);
14
+ if (!exportPath) {
15
+ continue;
16
+ }
17
+ for (const path of exportPath) {
18
+ res.set(el.fileName, path);
19
+ }
20
+ }
21
+ return res;
22
+ }
23
+ export {
24
+ jsFilesTask
25
+ };