@esmx/rspack 3.0.0-rc.10 → 3.0.0-rc.103

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 (76) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +48 -20
  3. package/README.zh-CN.md +57 -0
  4. package/dist/index.d.ts +2 -4
  5. package/dist/index.mjs +4 -4
  6. package/dist/module-link/config.d.ts +5 -0
  7. package/dist/module-link/config.mjs +100 -0
  8. package/dist/module-link/config1.d.ts +3 -0
  9. package/dist/module-link/config1.mjs +16 -0
  10. package/dist/module-link/config2.d.ts +3 -0
  11. package/dist/module-link/config2.mjs +17 -0
  12. package/dist/module-link/index.d.ts +4 -0
  13. package/dist/module-link/index.mjs +8 -0
  14. package/dist/module-link/manifest-plugin.d.ts +14 -0
  15. package/dist/module-link/manifest-plugin.mjs +141 -0
  16. package/dist/module-link/parse.d.ts +2 -0
  17. package/dist/module-link/parse.mjs +24 -0
  18. package/dist/module-link/types.d.ts +25 -0
  19. package/dist/rspack/app.d.ts +183 -0
  20. package/dist/{app.mjs → rspack/app.mjs} +18 -46
  21. package/dist/rspack/build-target.d.ts +7 -0
  22. package/dist/rspack/build-target.mjs +0 -0
  23. package/dist/{config.d.ts → rspack/chain-config.d.ts} +3 -4
  24. package/dist/rspack/chain-config.mjs +113 -0
  25. package/dist/rspack/index.d.ts +3 -0
  26. package/dist/rspack/index.mjs +4 -0
  27. package/dist/rspack/loader.d.ts +9 -0
  28. package/dist/{loader.mjs → rspack/loader.mjs} +2 -22
  29. package/dist/rspack/pack.d.ts +9 -0
  30. package/dist/{pack.mjs → rspack/pack.mjs} +33 -25
  31. package/dist/rspack/pack.test.d.ts +1 -0
  32. package/dist/rspack/pack.test.mjs +180 -0
  33. package/dist/rspack/utils/rsbuild.d.ts +6 -0
  34. package/dist/{utils → rspack/utils}/rsbuild.mjs +7 -37
  35. package/dist/rspack-html/index.d.ts +168 -0
  36. package/dist/rspack-html/index.mjs +160 -0
  37. package/dist/rspack-html/target-setting.d.ts +17 -0
  38. package/dist/rspack-html/target-setting.mjs +31 -0
  39. package/dist/rspack-html/target-setting.test.d.ts +1 -0
  40. package/dist/rspack-html/target-setting.test.mjs +105 -0
  41. package/package.json +34 -28
  42. package/src/index.ts +7 -6
  43. package/src/module-link/config.ts +157 -0
  44. package/src/module-link/config1.ts +24 -0
  45. package/src/module-link/config2.ts +28 -0
  46. package/src/module-link/index.ts +19 -0
  47. package/src/module-link/manifest-plugin.ts +179 -0
  48. package/src/module-link/parse.ts +31 -0
  49. package/src/module-link/types.ts +31 -0
  50. package/src/{app.ts → rspack/app.ts} +104 -107
  51. package/src/rspack/build-target.ts +7 -0
  52. package/src/rspack/chain-config.ts +165 -0
  53. package/src/rspack/index.ts +8 -0
  54. package/src/{loader.ts → rspack/loader.ts} +3 -22
  55. package/src/rspack/pack.test.ts +215 -0
  56. package/src/rspack/pack.ts +101 -0
  57. package/src/{utils → rspack/utils}/rsbuild.ts +11 -40
  58. package/src/rspack-html/index.ts +495 -0
  59. package/src/rspack-html/target-setting.test.ts +123 -0
  60. package/src/rspack-html/target-setting.ts +52 -0
  61. package/dist/app.d.ts +0 -160
  62. package/dist/build-target.d.ts +0 -8
  63. package/dist/config.mjs +0 -142
  64. package/dist/html-app.d.ts +0 -299
  65. package/dist/html-app.mjs +0 -214
  66. package/dist/loader.d.ts +0 -30
  67. package/dist/pack.d.ts +0 -2
  68. package/dist/utils/rsbuild.d.ts +0 -12
  69. package/src/build-target.ts +0 -8
  70. package/src/config.ts +0 -171
  71. package/src/html-app.ts +0 -560
  72. package/src/pack.ts +0 -79
  73. /package/dist/{build-target.mjs → module-link/types.mjs} +0 -0
  74. /package/dist/{utils → rspack/utils}/index.d.ts +0 -0
  75. /package/dist/{utils → rspack/utils}/index.mjs +0 -0
  76. /package/src/{utils → rspack/utils}/index.ts +0 -0
@@ -0,0 +1,183 @@
1
+ import { type App, type Esmx } from '@esmx/core';
2
+ import type { RspackOptions } from '@rspack/core';
3
+ import type { BuildTarget } from './build-target';
4
+ /**
5
+ * Rspack application configuration context interface.
6
+ *
7
+ * This interface provides context information accessible in configuration hook functions, allowing you to:
8
+ * - Access the Esmx framework instance
9
+ * - Get the current build target (client/server/node)
10
+ * - Modify Rspack configuration
11
+ * - Access application options
12
+ *
13
+ * @example
14
+ * ```ts
15
+ * // entry.node.ts
16
+ * export default {
17
+ * async devApp(esmx) {
18
+ * return import('@esmx/rspack').then((m) =>
19
+ * m.createRspackApp(esmx, {
20
+ * // Configuration hook function
21
+ * config(context) {
22
+ * // Access build target
23
+ * }
24
+ * })
25
+ * );
26
+ * }
27
+ * };
28
+ * ```
29
+ */
30
+ export interface RspackAppConfigContext {
31
+ /**
32
+ * Esmx framework instance.
33
+ * Can be used to access framework APIs and utility functions.
34
+ */
35
+ esmx: Esmx;
36
+ /**
37
+ * Current build target.
38
+ * - 'client': Client build, generates browser-executable code
39
+ * - 'server': Server build, generates SSR rendering code
40
+ * - 'node': Node.js build, generates server entry code
41
+ */
42
+ buildTarget: BuildTarget;
43
+ /**
44
+ * Rspack compilation configuration object.
45
+ * You can modify this object in configuration hooks to customize build behavior.
46
+ */
47
+ config: RspackOptions;
48
+ /**
49
+ * Options object passed when creating the application.
50
+ */
51
+ options: RspackAppOptions;
52
+ }
53
+ /**
54
+ * Rspack chain configuration context interface.
55
+ *
56
+ * This interface provides context information accessible in chain hook functions, allowing you to:
57
+ * - Access the Esmx framework instance
58
+ * - Get the current build target (client/server/node)
59
+ * - Modify configuration using rspack-chain
60
+ * - Access application options
61
+ */
62
+ export interface RspackAppChainContext {
63
+ /**
64
+ * Esmx framework instance.
65
+ * Can be used to access framework APIs and utility functions.
66
+ */
67
+ esmx: Esmx;
68
+ /**
69
+ * Current build target.
70
+ * - 'client': Client build, generates browser-executable code
71
+ * - 'server': Server build, generates SSR rendering code
72
+ * - 'node': Node.js build, generates server entry code
73
+ */
74
+ buildTarget: BuildTarget;
75
+ /**
76
+ * rspack-chain configuration object.
77
+ * You can use the chain API in chain hooks to modify the configuration.
78
+ */
79
+ chain: import('rspack-chain').default;
80
+ /**
81
+ * Options object passed when creating the application.
82
+ */
83
+ options: RspackAppOptions;
84
+ }
85
+ /**
86
+ * Rspack application configuration options interface.
87
+ *
88
+ * This interface provides configuration options available when creating a Rspack application, including:
89
+ * - Code compression options
90
+ * - Rspack configuration hook functions
91
+ *
92
+ * @example
93
+ * ```ts
94
+ * // entry.node.ts
95
+ * export default {
96
+ * async devApp(esmx) {
97
+ * return import('@esmx/rspack').then((m) =>
98
+ * m.createRspackApp(esmx, {
99
+ * // Disable code compression
100
+ * minimize: false,
101
+ * // Custom Rspack configuration
102
+ * config(context) {
103
+ * }
104
+ * })
105
+ * );
106
+ * }
107
+ * };
108
+ * ```
109
+ */
110
+ export interface RspackAppOptions {
111
+ /**
112
+ * Whether to enable code compression.
113
+ *
114
+ * - true: Enable code compression
115
+ * - false: Disable code compression
116
+ * - undefined: Automatically determine based on environment (enabled in production, disabled in development)
117
+ *
118
+ * @default undefined
119
+ */
120
+ minimize?: boolean;
121
+ /**
122
+ * Called before the build starts, this function allows you to modify the Rspack compilation configuration.
123
+ * Supports differentiated configuration for different build targets (client/server/node).
124
+ *
125
+ * @param context - Configuration context, containing framework instance, build target, and configuration object
126
+ */
127
+ config?: (context: RspackAppConfigContext) => void;
128
+ /**
129
+ * Uses rspack-chain to provide chained configuration method, allowing more flexible modification of Rspack configuration.
130
+ * Called after the config hook, if chain hook exists, chained configuration is preferred.
131
+ *
132
+ * @param context - Configuration context, containing framework instance, build target, and chain configuration object
133
+ */
134
+ chain?: (context: RspackAppChainContext) => void;
135
+ }
136
+ /**
137
+ * Create Rspack application instance.
138
+ *
139
+ * This function creates different application instances based on the runtime environment (development/production):
140
+ * - Development environment: Configures hot update middleware and real-time rendering
141
+ * - Production environment: Configures build tasks
142
+ *
143
+ * @param esmx - Esmx framework instance
144
+ * @param options - Rspack application configuration options
145
+ * @returns Returns application instance
146
+ *
147
+ * @example
148
+ * ```ts
149
+ * // entry.node.ts
150
+ * export default {
151
+ * async devApp(esmx) {
152
+ * return import('@esmx/rspack').then((m) =>
153
+ * m.createRspackApp(esmx, {
154
+ * config(context) {
155
+ * // Configure loader to handle different file types
156
+ * context.config.module = {
157
+ * rules: [
158
+ * {
159
+ * test: /\.ts$/,
160
+ * exclude: [/node_modules/],
161
+ * loader: 'builtin:swc-loader',
162
+ * options: {
163
+ * jsc: {
164
+ * parser: {
165
+ * syntax: 'typescript'
166
+ * }
167
+ * }
168
+ * }
169
+ * },
170
+ * {
171
+ * test: /\.css$/,
172
+ * use: ['style-loader', 'css-loader']
173
+ * }
174
+ * ]
175
+ * };
176
+ * }
177
+ * })
178
+ * );
179
+ * }
180
+ * };
181
+ * ```
182
+ */
183
+ export declare function createRspackApp(esmx: Esmx, options?: RspackAppOptions): Promise<App>;
@@ -1,15 +1,12 @@
1
- import fs from "node:fs";
2
1
  import { pathToFileURL } from "node:url";
3
- import { styleText } from "node:util";
4
2
  import {
5
- PathType,
6
- RenderContext,
7
3
  createApp,
8
- mergeMiddlewares
4
+ mergeMiddlewares,
5
+ RenderContext
9
6
  } from "@esmx/core";
10
7
  import { createVmImport } from "@esmx/import";
11
8
  import hotMiddleware from "webpack-hot-middleware";
12
- import { createRspackConfig } from "./config.mjs";
9
+ import { createRspackConfig } from "./chain-config.mjs";
13
10
  import { pack } from "./pack.mjs";
14
11
  import { createRsBuild } from "./utils/index.mjs";
15
12
  export async function createRspackApp(esmx, options) {
@@ -50,9 +47,7 @@ async function createMiddleware(esmx, options = {}) {
50
47
  ];
51
48
  }
52
49
  function generateBuildConfig(esmx, options, buildTarget) {
53
- const config = createRspackConfig(esmx, buildTarget, options);
54
- options.config?.({ esmx, options, buildTarget, config });
55
- return config;
50
+ return createRspackConfig(esmx, buildTarget, options);
56
51
  }
57
52
  function rewriteRender(esmx) {
58
53
  return async (options) => {
@@ -63,14 +58,7 @@ function rewriteRender(esmx) {
63
58
  const module = await vmImport(
64
59
  `${esmx.name}/src/entry.server`,
65
60
  import.meta.url,
66
- {
67
- console,
68
- setTimeout,
69
- clearTimeout,
70
- process,
71
- URL,
72
- global
73
- }
61
+ global
74
62
  );
75
63
  const serverRender = module[rc.entryName];
76
64
  if (typeof serverRender === "function") {
@@ -80,40 +68,22 @@ function rewriteRender(esmx) {
80
68
  };
81
69
  }
82
70
  function rewriteBuild(esmx, options = {}) {
71
+ const targets = ["client", "server"];
72
+ if (!esmx.moduleConfig.lib) {
73
+ targets.push("node");
74
+ }
83
75
  return async () => {
84
- for (const item of esmx.moduleConfig.exports) {
85
- if (item.type === PathType.root) {
86
- const text = fs.readFileSync(
87
- esmx.resolvePath("./", item.exportPath),
88
- "utf-8"
89
- );
90
- if (/\bexport\s+\*\s+from\b/.test(text)) {
91
- console.log(
92
- styleText(
93
- "red",
94
- `The export * syntax is used in the file '${item.exportPath}', which will cause the packaging to fail.`
95
- )
96
- );
97
- console.log(
98
- styleText(
99
- "red",
100
- `Please use specific export syntax, such as export { a, b } from './a';`
101
- )
102
- );
103
- return false;
104
- }
105
- }
76
+ const ok = await createRsBuild(
77
+ targets.map((target) => generateBuildConfig(esmx, options, target))
78
+ ).build();
79
+ if (!ok) {
80
+ return false;
106
81
  }
107
- await createRsBuild([
108
- generateBuildConfig(esmx, options, "client"),
109
- generateBuildConfig(esmx, options, "server"),
110
- generateBuildConfig(esmx, options, "node")
111
- ]).build();
112
82
  esmx.writeSync(
113
- esmx.resolvePath("dist/index.js"),
83
+ esmx.resolvePath("dist/index.mjs"),
114
84
  `
115
85
  async function start() {
116
- const options = await import('./node/src/entry.node.js').then(
86
+ const options = await import('./node/src/entry.node.mjs').then(
117
87
  (mod) => mod.default
118
88
  );
119
89
  const { Esmx } = await import('@esmx/core');
@@ -125,6 +95,8 @@ async function start() {
125
95
  start();
126
96
  `.trim()
127
97
  );
98
+ console.log("\n");
99
+ console.log(esmx.generateSizeReport().text);
128
100
  return pack(esmx);
129
101
  };
130
102
  }
@@ -0,0 +1,7 @@
1
+ /**
2
+ * Build target environment type
3
+ * - node: Node.js environment build
4
+ * - client: Browser environment build
5
+ * - server: Server-side rendering build
6
+ */
7
+ export type BuildTarget = 'node' | 'client' | 'server';
File without changes
@@ -1,8 +1,7 @@
1
1
  import type { Esmx } from '@esmx/core';
2
- import { type RspackOptions } from '@rspack/core';
2
+ import type { RspackOptions } from '@rspack/core';
3
+ import RspackChain from 'rspack-chain';
3
4
  import type { RspackAppOptions } from './app';
4
5
  import type { BuildTarget } from './build-target';
5
- /**
6
- * 构建 Client、Server、Node 的基础配置
7
- */
6
+ export declare function createChainConfig(esmx: Esmx, buildTarget: BuildTarget, options: RspackAppOptions): RspackChain;
8
7
  export declare function createRspackConfig(esmx: Esmx, buildTarget: BuildTarget, options: RspackAppOptions): RspackOptions;
@@ -0,0 +1,113 @@
1
+ import { rspack } from "@rspack/core";
2
+ import RspackChain from "rspack-chain";
3
+ import nodeExternals from "webpack-node-externals";
4
+ import { initModuleLink } from "../module-link/index.mjs";
5
+ export function createChainConfig(esmx, buildTarget, options) {
6
+ const isHot = buildTarget === "client" && !esmx.isProd;
7
+ const isClient = buildTarget === "client";
8
+ const isServer = buildTarget === "server";
9
+ const isNode = buildTarget === "node";
10
+ const chain = new RspackChain();
11
+ chain.context(esmx.root);
12
+ chain.mode(esmx.isProd ? "production" : "development");
13
+ chain.target(isClient ? "web" : "node24");
14
+ chain.cache(!esmx.isProd);
15
+ chain.output.clean(esmx.isProd).filename(
16
+ !isNode && esmx.isProd ? "[name].[contenthash:8].final.mjs" : "[name].mjs"
17
+ ).chunkFilename(
18
+ esmx.isProd ? "chunks/[name].[contenthash:8].final.mjs" : "chunks/[name].mjs"
19
+ ).publicPath(
20
+ isClient ? "auto" : `${esmx.basePathPlaceholder}${esmx.basePath}`
21
+ );
22
+ chain.output.set(
23
+ "cssFilename",
24
+ esmx.isProd ? "[name].[contenthash:8].final.css" : "[name].css"
25
+ );
26
+ chain.output.set(
27
+ "cssChunkFilename",
28
+ esmx.isProd ? "chunks/[name].[contenthash:8].final.css" : "chunks/[name].css"
29
+ );
30
+ chain.output.path(esmx.resolvePath("dist", buildTarget));
31
+ chain.plugin("progress").use(rspack.ProgressPlugin, [
32
+ {
33
+ prefix: buildTarget
34
+ }
35
+ ]);
36
+ if (isHot) {
37
+ chain.plugin("hmr").use(rspack.HotModuleReplacementPlugin);
38
+ }
39
+ chain.module.parser.set("javascript", {
40
+ url: isClient ? true : "relative",
41
+ importMeta: false,
42
+ strictExportPresence: true
43
+ });
44
+ chain.module.generator.set("asset", {
45
+ emit: isClient
46
+ });
47
+ chain.module.generator.set("asset/resource", {
48
+ emit: isClient
49
+ });
50
+ chain.resolve.alias.set(esmx.name, esmx.root);
51
+ chain.optimization.minimize(options.minimize ?? esmx.isProd).emitOnErrors(true);
52
+ chain.externalsPresets({
53
+ web: isClient,
54
+ node: isServer || isNode
55
+ });
56
+ chain.externalsType("module-import");
57
+ if (isNode) {
58
+ chain.externals([
59
+ // @ts-expect-error
60
+ nodeExternals({
61
+ // @ts-expect-error
62
+ importType: "module-import"
63
+ })
64
+ ]);
65
+ }
66
+ chain.experiments({
67
+ ...chain.get("experiments") || {},
68
+ outputModule: true,
69
+ nativeWatcher: true,
70
+ rspackFuture: {
71
+ bundlerInfo: { force: false }
72
+ }
73
+ });
74
+ chain.set("lazyCompilation", false);
75
+ initModuleLink(chain, createModuleLinkConfig(esmx, buildTarget));
76
+ return chain;
77
+ }
78
+ function createModuleLinkConfig(esmx, buildTarget) {
79
+ const isClient = buildTarget === "client";
80
+ const isServer = buildTarget === "server";
81
+ const isNode = buildTarget === "node";
82
+ if (isNode) {
83
+ return {
84
+ name: esmx.name,
85
+ exports: {
86
+ "src/entry.node": {
87
+ pkg: false,
88
+ file: "./src/entry.node"
89
+ }
90
+ }
91
+ };
92
+ }
93
+ const preEntries = [];
94
+ if (isClient && !esmx.isProd) {
95
+ preEntries.push(
96
+ `${import.meta.resolve("webpack-hot-middleware/client.js")}?path=/${esmx.name}/hot-middleware`
97
+ );
98
+ }
99
+ return {
100
+ ...esmx.moduleConfig.environments[buildTarget],
101
+ name: esmx.name,
102
+ injectChunkName: isServer,
103
+ deps: Object.keys(esmx.moduleConfig.links),
104
+ preEntries
105
+ };
106
+ }
107
+ export function createRspackConfig(esmx, buildTarget, options) {
108
+ const chain = createChainConfig(esmx, buildTarget, options);
109
+ options.chain?.({ esmx, options, buildTarget, chain });
110
+ const config = chain.toConfig();
111
+ options.config?.({ esmx, options, buildTarget, config });
112
+ return config;
113
+ }
@@ -0,0 +1,3 @@
1
+ export { createRspackApp, type RspackAppChainContext, type RspackAppConfigContext, type RspackAppOptions } from './app';
2
+ export type { BuildTarget } from './build-target';
3
+ export { RSPACK_LOADER } from './loader';
@@ -0,0 +1,4 @@
1
+ export {
2
+ createRspackApp
3
+ } from "./app.mjs";
4
+ export { RSPACK_LOADER } from "./loader.mjs";
@@ -0,0 +1,9 @@
1
+ export declare const RSPACK_LOADER: {
2
+ builtinSwcLoader: string;
3
+ lightningcssLoader: string;
4
+ cssLoader: string;
5
+ styleLoader: string;
6
+ lessLoader: string;
7
+ styleResourcesLoader: string;
8
+ workerRspackLoader: string;
9
+ };
@@ -1,33 +1,13 @@
1
+ import { fileURLToPath } from "node:url";
1
2
  function resolve(name) {
2
- return new URL(import.meta.resolve(name)).pathname;
3
+ return fileURLToPath(import.meta.resolve(name));
3
4
  }
4
5
  export const RSPACK_LOADER = {
5
- /**
6
- * Rspack 内置的 builtin:swc-loader
7
- */
8
6
  builtinSwcLoader: "builtin:swc-loader",
9
- /**
10
- * Rspack 内置的 lightningcss-loader
11
- */
12
7
  lightningcssLoader: "builtin:lightningcss-loader",
13
- /**
14
- * css-loader
15
- */
16
8
  cssLoader: resolve("css-loader"),
17
- /**
18
- * style-loader
19
- */
20
9
  styleLoader: resolve("style-loader"),
21
- /**
22
- * less-loader
23
- */
24
10
  lessLoader: resolve("less-loader"),
25
- /**
26
- * style-resources-loader
27
- */
28
11
  styleResourcesLoader: resolve("style-resources-loader"),
29
- /**
30
- * worker-rspack-loader
31
- */
32
12
  workerRspackLoader: resolve("worker-rspack-loader")
33
13
  };
@@ -0,0 +1,9 @@
1
+ import type { Esmx, ManifestJson } from '@esmx/core';
2
+ export declare function pack(esmx: Esmx): Promise<boolean>;
3
+ export interface GenerateExportsOptions {
4
+ client: ManifestJson['exports'];
5
+ server: ManifestJson['exports'];
6
+ base?: Record<string, unknown>;
7
+ }
8
+ export declare function generateExports(options: GenerateExportsOptions): Record<string, unknown>;
9
+ export declare function contentHash(buffer: Buffer, algorithm?: string): string;
@@ -28,42 +28,50 @@ export async function pack(esmx) {
28
28
  await packConfig.onAfter(esmx, pkgJson, data);
29
29
  return true;
30
30
  }
31
- async function buildPackageJson(esmx) {
32
- const [clientJson, serverJson, curJson] = await Promise.all([
33
- esmx.readJson(esmx.resolvePath("dist/client/manifest.json")),
34
- esmx.readJson(esmx.resolvePath("dist/server/manifest.json")),
35
- esmx.readJson(esmx.resolvePath("package.json"))
36
- ]);
37
- const exports = {
38
- ...curJson?.exports
39
- };
40
- const set = /* @__PURE__ */ new Set([
41
- ...Object.keys(clientJson.exports),
42
- ...Object.keys(serverJson.exports)
43
- ]);
31
+ export function generateExports(options) {
32
+ const { client, server, base = {} } = options;
33
+ const exports = { ...base };
34
+ const set = /* @__PURE__ */ new Set([...Object.keys(client), ...Object.keys(server)]);
44
35
  set.forEach((name) => {
45
- const client = clientJson.exports[name];
46
- const server = serverJson.exports[name];
47
- const exportName = `./${name}`;
48
- if (client && server) {
36
+ const clientExport = client[name];
37
+ const serverExport = server[name];
38
+ const exportName = name === "index" ? "." : `./${name}`;
39
+ if (clientExport && serverExport) {
49
40
  exports[exportName] = {
50
- default: `./server/${server}`,
51
- browser: `./client/${client}`
41
+ default: `./server/${serverExport.file}`,
42
+ browser: `./client/${clientExport.file}`
52
43
  };
53
- } else if (client) {
54
- exports[exportName] = `./client/${client}`;
55
- } else if (server) {
56
- exports[exportName] = `./server/${server}`;
44
+ } else if (clientExport) {
45
+ exports[exportName] = `./client/${clientExport.file}`;
46
+ } else if (serverExport) {
47
+ exports[exportName] = `./server/${serverExport.file}`;
57
48
  }
58
49
  });
50
+ return exports;
51
+ }
52
+ async function buildPackageJson(esmx) {
53
+ const [clientJson, serverJson, curJson] = await Promise.all([
54
+ esmx.readJson(
55
+ esmx.resolvePath("dist/client/manifest.json")
56
+ ),
57
+ esmx.readJson(
58
+ esmx.resolvePath("dist/server/manifest.json")
59
+ ),
60
+ esmx.readJson(esmx.resolvePath("package.json"))
61
+ ]);
62
+ const exports = generateExports({
63
+ client: clientJson.exports,
64
+ server: serverJson.exports,
65
+ base: curJson?.exports
66
+ });
59
67
  const buildJson = {
60
68
  ...curJson,
61
69
  exports
62
70
  };
63
71
  return buildJson;
64
72
  }
65
- function contentHash(buffer, algorithm = "sha256") {
66
- const hash = crypto.createHash("sha256");
73
+ export function contentHash(buffer, algorithm = "sha256") {
74
+ const hash = crypto.createHash(algorithm);
67
75
  hash.update(buffer);
68
76
  return `${algorithm}-${hash.digest("hex")}`;
69
77
  }
@@ -0,0 +1 @@
1
+ export {};