frosty 0.0.67 → 0.0.68

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 (49) hide show
  1. package/README.md +50 -0
  2. package/dist/_native.d.ts +3 -3
  3. package/dist/_native.mjs +2 -2
  4. package/dist/dom.d.ts +3 -3
  5. package/dist/dom.mjs +3 -3
  6. package/dist/index.d.ts +4 -4
  7. package/dist/index.mjs +3 -3
  8. package/dist/internals/{common-jmXMOod4.d.ts → common-B0Nya-9e.d.ts} +3 -3
  9. package/dist/internals/{common-jmXMOod4.d.ts.map → common-B0Nya-9e.d.ts.map} +1 -1
  10. package/dist/internals/{common-uTufm_t7.mjs → common-Ca5Ux3vo.mjs} +3 -3
  11. package/dist/internals/{common-uTufm_t7.mjs.map → common-Ca5Ux3vo.mjs.map} +1 -1
  12. package/dist/internals/{common-C5xm7xDw.d.ts → common-lfYTb1eV.d.ts} +3 -3
  13. package/dist/internals/{common-C5xm7xDw.d.ts.map → common-lfYTb1eV.d.ts.map} +1 -1
  14. package/dist/internals/{fragment-BQXp1_iv.d.ts → fragment-CApRh6Hp.d.ts} +2 -2
  15. package/dist/internals/{fragment-BQXp1_iv.d.ts.map → fragment-CApRh6Hp.d.ts.map} +1 -1
  16. package/dist/internals/{renderer-DgKjFDB-.mjs → renderer-CEj3F2CM.mjs} +2 -2
  17. package/dist/internals/{renderer-DgKjFDB-.mjs.map → renderer-CEj3F2CM.mjs.map} +1 -1
  18. package/dist/internals/{renderer-D4aiCZGU.d.ts → renderer-DBPR_8BN.d.ts} +2 -2
  19. package/dist/internals/{renderer-D4aiCZGU.d.ts.map → renderer-DBPR_8BN.d.ts.map} +1 -1
  20. package/dist/internals/{state-j1YggBhW.mjs → state-C4Wldkq7.mjs} +2 -2
  21. package/dist/internals/{state-j1YggBhW.mjs.map → state-C4Wldkq7.mjs.map} +1 -1
  22. package/dist/internals/{sync-D_pTd9lu.mjs → sync-Ciycjqeo.mjs} +3 -3
  23. package/dist/internals/{sync-D_pTd9lu.mjs.map → sync-Ciycjqeo.mjs.map} +1 -1
  24. package/dist/internals/{utils-B_4b5vas.d.ts → utils-CyrF9IfR.d.ts} +2 -2
  25. package/dist/internals/{utils-B_4b5vas.d.ts.map → utils-CyrF9IfR.d.ts.map} +1 -1
  26. package/dist/jsx-dev-runtime.d.ts +7 -0
  27. package/dist/jsx-dev-runtime.d.ts.map +1 -0
  28. package/dist/jsx-dev-runtime.js +14 -0
  29. package/dist/jsx-dev-runtime.js.map +1 -0
  30. package/dist/jsx-dev-runtime.mjs +4 -0
  31. package/dist/jsx-dev-runtime.mjs.map +1 -0
  32. package/dist/jsx-runtime.d.ts +2 -2
  33. package/dist/jsx-runtime.d.ts.map +1 -1
  34. package/dist/jsx-runtime.js +1 -1
  35. package/dist/jsx-runtime.js.map +1 -1
  36. package/dist/jsx-runtime.mjs +1 -1
  37. package/dist/jsx-runtime.mjs.map +1 -1
  38. package/dist/server-dom.d.ts +3 -3
  39. package/dist/server-dom.mjs +3 -3
  40. package/dist/web.d.ts +3 -3
  41. package/dist/web.mjs +5 -5
  42. package/package.json +3 -2
  43. package/packages/frosty-cli/package.json +0 -1
  44. package/packages/frosty-cli/scripts/bin/run.sh +81 -42
  45. package/packages/frosty-cli/src/server/env.js +26 -0
  46. package/packages/frosty-cli/src/server/index.js +7 -11
  47. package/packages/frosty-cli/src/server/render.js +9 -10
  48. package/packages/frosty-cli/src/server/route.ts +1 -7
  49. package/packages/frosty-cli/{webpack.js → webpack.mjs} +90 -48
@@ -1,49 +1,82 @@
1
- /* eslint no-var: 0 */
1
+ //
2
+ // webpack.mjs
3
+ //
4
+ // The MIT License
5
+ // Copyright (c) 2021 - 2025 O2ter Limited. All rights reserved.
6
+ //
7
+ // Permission is hereby granted, free of charge, to any person obtaining a copy
8
+ // of this software and associated documentation files (the "Software"), to deal
9
+ // in the Software without restriction, including without limitation the rights
10
+ // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11
+ // copies of the Software, and to permit persons to whom the Software is
12
+ // furnished to do so, subject to the following conditions:
13
+ //
14
+ // The above copyright notice and this permission notice shall be included in
15
+ // all copies or substantial portions of the Software.
16
+ //
17
+ // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18
+ // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19
+ // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20
+ // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21
+ // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22
+ // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
23
+ // THE SOFTWARE.
24
+ //
2
25
 
3
- const _ = require('lodash');
4
- const os = require('os');
5
- const fs = require('fs');
6
- const path = require('path');
7
- const crypto = require('crypto');
8
- const webpack = require('webpack');
9
- const Dotenv = require('dotenv-webpack');
10
- const TerserPlugin = require('terser-webpack-plugin');
11
- const MiniCssExtractPlugin = require('mini-css-extract-plugin');
12
- const CopyPlugin = require('copy-webpack-plugin');
26
+ import _ from 'lodash';
27
+ import os from 'os';
28
+ import fs from 'fs';
29
+ import path from 'path';
30
+ import crypto from 'crypto';
31
+ import webpack from 'webpack';
32
+ import Dotenv from 'dotenv-webpack';
33
+ import TerserPlugin from 'terser-webpack-plugin';
34
+ import MiniCssExtractPlugin from 'mini-css-extract-plugin';
13
35
 
14
- const serverConfig = (() => {
15
- try {
16
- return require(path.resolve(process.cwd(), 'server.config.js'));
17
- } catch {
18
- return {};
19
- }
20
- })();
36
+ export default async (env, argv) => {
21
37
 
22
- const frostyDeps = (() => {
23
- try {
24
- const resolved = require.resolve('frosty');
25
- return {
26
- frosty: resolved.endsWith('/dist/index.js') ? resolved.replace('/index.js', '') : resolved,
27
- };
28
- } catch {
29
- const { rollupConfig: { input } } = require(path.resolve(__dirname, '../../rollup.config.mjs'));
30
- const resolved = {};
31
- for (const [k, v] of _.entries(input)) {
32
- if (k === 'index') continue;
33
- resolved[`frosty/${k}`] = path.resolve(__dirname, '../..', v);
34
- }
35
- return {
36
- ...resolved,
37
- frosty: path.resolve(__dirname, '../../src/index'),
38
- };
39
- }
40
- })();
38
+ const {
39
+ CONFIG_FILE = 'server.config.js',
40
+ INPUT_FILE,
41
+ PORT = 8080,
42
+ } = env;
41
43
 
42
- module.exports = (env, argv) => {
44
+ const serverConfig = await (async () => {
45
+ try {
46
+ return await import(path.resolve(process.cwd(), CONFIG_FILE));
47
+ } catch {
48
+ return {};
49
+ }
50
+ })();
43
51
 
44
52
  const config = _.isFunction(serverConfig) ? serverConfig(env, argv) : serverConfig;
45
53
  const IS_PRODUCTION = argv.mode !== 'development';
46
54
 
55
+ const {
56
+ SRCROOT = config.src,
57
+ OUTPUT_DIR = config.output || path.resolve(import.meta.dirname, 'dist'),
58
+ } = env;
59
+
60
+ const frostyDeps = await (async () => {
61
+ try {
62
+ const resolved = import.meta.resolve('frosty');
63
+ return {
64
+ frosty: resolved.endsWith('/dist/index.js') ? resolved.replace('/index.js', '') : resolved,
65
+ };
66
+ } catch {
67
+ const { rollupConfig: { input } } = await import(path.resolve(import.meta.dirname, '../../rollup.config.mjs'));
68
+ const resolved = {};
69
+ for (const [k, v] of _.entries(input)) {
70
+ if (k === 'index') continue;
71
+ resolved[`frosty/${k}`] = path.resolve(import.meta.dirname, '../..', v);
72
+ }
73
+ return {
74
+ ...resolved,
75
+ frosty: path.resolve(import.meta.dirname, '../../src/index'),
76
+ };
77
+ }
78
+ })();
79
+
47
80
  const babelLoaderConfiguration = ({ server }) => ({
48
81
  test: /\.(ts|tsx|m?js)?$/i,
49
82
  use: {
@@ -151,6 +184,9 @@ module.exports = (env, argv) => {
151
184
  resolve: {
152
185
  ...config.options?.resolve ?? {},
153
186
  alias: {
187
+ ...SRCROOT ? {
188
+ '~': path.resolve(process.cwd(), SRCROOT),
189
+ } : {},
154
190
  ...frostyDeps,
155
191
  ...config.options?.resolve?.alias ?? {},
156
192
  },
@@ -169,15 +205,16 @@ module.exports = (env, argv) => {
169
205
  ...config.options?.plugins ?? [],
170
206
  ];
171
207
 
172
- const server = config.serverEntry ? path.resolve(process.cwd(), config.serverEntry) : path.resolve(__dirname, './src/server/default.js');
208
+ const server = config.serverEntry ? path.resolve(process.cwd(), config.serverEntry) : path.resolve(import.meta.dirname, './src/server/default.js');
173
209
 
174
210
  const random = crypto.randomUUID();
175
211
  const tempDir = fs.mkdtempSync(`${os.tmpdir()}${path.sep}`);
176
212
  const applications = path.resolve(tempDir, `applications-${random}.js`);
213
+ const inputs = INPUT_FILE ? { main: { entry: path.join(process.cwd(), INPUT_FILE), uri: '/' } } : config.client;
177
214
 
178
215
  fs.writeFileSync(applications, `
179
- ${_.map(config.client, ({ entry }, name) => `import * as ${name} from '${path.resolve(process.cwd(), entry)}';`).join('\n')}
180
- export { ${_.keys(config.client).join(',')} };
216
+ ${_.map(inputs, ({ entry }, name) => `import * as ${name} from '${path.resolve(process.cwd(), entry)}';`).join('\n')}
217
+ export { ${_.keys(inputs).join(',')} };
181
218
  `);
182
219
 
183
220
  const moduleSuffixes = {
@@ -186,18 +223,18 @@ module.exports = (env, argv) => {
186
223
  };
187
224
 
188
225
  return [
189
- ..._.map(config.client, ({ entry }, name) => ({
226
+ ..._.map(inputs, ({ entry }, name) => ({
190
227
  ...webpackConfiguration,
191
228
  optimization: webpackOptimization({ server: false }),
192
229
  plugins: webpackPlugins,
193
230
  entry: {
194
231
  [`${name}_bundle`]: [
195
232
  'core-js/stable',
196
- path.resolve(__dirname, './client/index.js'),
233
+ path.resolve(import.meta.dirname, './src/client/index.js'),
197
234
  ],
198
235
  },
199
236
  output: {
200
- path: config.output ? path.join(config.output, 'public') : path.join(__dirname, 'dist/public'),
237
+ path: path.join(OUTPUT_DIR, 'public'),
201
238
  },
202
239
  resolve: {
203
240
  ...webpackConfiguration.resolve,
@@ -226,19 +263,24 @@ module.exports = (env, argv) => {
226
263
  optimization: webpackOptimization({ server: false }),
227
264
  plugins: _.compact([
228
265
  ...webpackPlugins,
266
+ new webpack.EnvironmentPlugin({ PORT }),
267
+ new webpack.DefinePlugin({
268
+ __applications__: JSON.stringify(_.mapValues(inputs, x => ({
269
+ path: x.uri,
270
+ basename: x.basename,
271
+ }))),
272
+ }),
229
273
  ...config.options?.server?.plugins ?? [],
230
- config.serverAssets && new CopyPlugin({ patterns: config.serverAssets }),
231
274
  ]),
232
275
  target: 'node',
233
- plugins: webpackPlugins,
234
276
  entry: {
235
277
  server: [
236
278
  'core-js/stable',
237
- path.resolve(__dirname, './src/server/index.js'),
279
+ path.resolve(import.meta.dirname, './src/server/index.js'),
238
280
  ],
239
281
  },
240
282
  output: {
241
- path: config.output || path.resolve(__dirname, 'dist'),
283
+ path: OUTPUT_DIR,
242
284
  },
243
285
  resolve: {
244
286
  ...webpackConfiguration.resolve,