@gravity-ui/app-builder 0.2.2 → 0.4.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 (42) hide show
  1. package/CHANGELOG.md +36 -0
  2. package/README.md +295 -1
  3. package/dist/commands/build/build-lib.js +2 -5
  4. package/dist/commands/build/index.js +1 -2
  5. package/dist/commands/dev/client.js +30 -25
  6. package/dist/commands/dev/index.js +10 -8
  7. package/dist/commands/dev/server.js +3 -3
  8. package/dist/common/child-process/controllable-script.js +3 -1
  9. package/dist/common/child-process/utils.js +1 -2
  10. package/dist/common/config.d.ts +1 -1
  11. package/dist/common/config.js +34 -26
  12. package/dist/common/library/index.js +13 -13
  13. package/dist/common/links/unlink.js +2 -2
  14. package/dist/common/logger/index.js +1 -2
  15. package/dist/common/models/index.d.ts +24 -10
  16. package/dist/common/models/index.js +5 -1
  17. package/dist/common/package.js +5 -2
  18. package/dist/common/s3-upload/s3-client.d.ts +1 -0
  19. package/dist/common/s3-upload/s3-client.js +2 -14
  20. package/dist/common/s3-upload/upload.d.ts +1 -1
  21. package/dist/common/s3-upload/upload.js +1 -2
  22. package/dist/common/s3-upload/webpack-plugin.d.ts +1 -1
  23. package/dist/common/s3-upload/webpack-plugin.js +4 -2
  24. package/dist/common/tempData.js +1 -1
  25. package/dist/common/typescript/diagnostic.js +1 -1
  26. package/dist/common/typescript/transformers.js +39 -7
  27. package/dist/common/typescript/watch.js +7 -2
  28. package/dist/common/webpack/config.js +93 -65
  29. package/dist/common/webpack/public-path.js +1 -1
  30. package/dist/common/webpack/storybook.js +43 -14
  31. package/dist/common/webpack/utils.js +5 -3
  32. package/dist/common/webpack/worker/public-path.worker.d.ts +0 -0
  33. package/dist/common/webpack/worker/public-path.worker.js +3 -0
  34. package/dist/common/webpack/worker/web-worker.d.ts +4 -0
  35. package/dist/common/webpack/worker/web-worker.js +23 -0
  36. package/dist/common/webpack/worker/worker-loader.d.ts +2 -0
  37. package/dist/common/webpack/worker/worker-loader.js +123 -0
  38. package/dist/create-cli.d.ts +2 -2
  39. package/dist/create-cli.js +1 -1
  40. package/dist/index.d.ts +3 -1
  41. package/dist/index.js +18 -1
  42. package/package.json +60 -41
package/CHANGELOG.md CHANGED
@@ -1,5 +1,41 @@
1
1
  # Changelog
2
2
 
3
+ ## [0.4.0](https://github.com/gravity-ui/app-builder/compare/v0.3.0...v0.4.0) (2023-05-19)
4
+
5
+
6
+ ### ⚠ BREAKING CHANGES
7
+
8
+ * **Client:** change default value for setting `client.symlinks`, used default (true) from webpack.
9
+
10
+ ### Features
11
+
12
+ * **Client:** add setting to watch changes in node_modules ([#21](https://github.com/gravity-ui/app-builder/issues/21)) ([3a5dea6](https://github.com/gravity-ui/app-builder/commit/3a5dea6284f3a768650b388115a83136ba1b7a07))
13
+ * **WebWorker:** support webpack 5 web workers syntax ([#19](https://github.com/gravity-ui/app-builder/issues/19)) ([bf784bb](https://github.com/gravity-ui/app-builder/commit/bf784bb6480c60497bc79c93e70d61aaead80909))
14
+
15
+ ## [0.3.0](https://github.com/gravity-ui/app-builder/compare/v0.2.2...v0.3.0) (2023-05-08)
16
+
17
+
18
+ ### ⚠ BREAKING CHANGES
19
+
20
+ * **LibraryConfig:** move newJsxTransform option under lib property
21
+
22
+ ### Features
23
+
24
+ * **config:** add defineConfig helper ([31daecc](https://github.com/gravity-ui/app-builder/commit/31daecccc33fc58bc14d85c217b990c1f4302218))
25
+ * **server:** use APP_PORT env variable to pass port to server ([6b14651](https://github.com/gravity-ui/app-builder/commit/6b14651adae6cf18f0da7447636d2a8363979166))
26
+ * **storybook:** use configureServiceWebpackConfig for libraries too ([4204cf9](https://github.com/gravity-ui/app-builder/commit/4204cf9e1e5e63e16e7631477beb251e496d2690))
27
+
28
+
29
+ ### Bug Fixes
30
+
31
+ * **client:** use newJsxTransform in svgr options ([cd01f55](https://github.com/gravity-ui/app-builder/commit/cd01f552177c73b20de7e95ca65cf770e8b63dbc))
32
+ * **LibraryConfig:** move newJsxTransform option under lib property ([847a38c](https://github.com/gravity-ui/app-builder/commit/847a38cc4138741559f053ba594bcdd997c44063))
33
+
34
+
35
+ ### docs
36
+
37
+ * add documentation for services ([d78b63b](https://github.com/gravity-ui/app-builder/commit/d78b63beb03c0e446e060d977942787dc33eee2c))
38
+
3
39
  ## [0.2.2](https://github.com/gravity-ui/app-builder/compare/v0.2.1...v0.2.2) (2023-05-05)
4
40
 
5
41
 
package/README.md CHANGED
@@ -1,4 +1,6 @@
1
- # @gravity-ui/app-builder · [![npm package](https://img.shields.io/npm/v/@gravity-ui/app-builder)](https://www.npmjs.com/package/@gravity-ui/app-builder) [![CI](https://img.shields.io/github/workflow/status/gravity-ui/app-builder/CI/main?label=CI&logo=github)](https://github.com/gravity-ui/app-builder/actions/workflows/ci.yml?query=branch:main)
1
+ # @gravity-ui/app-builder · [![npm package](https://img.shields.io/npm/v/@gravity-ui/app-builder)](https://www.npmjs.com/package/@gravity-ui/app-builder) [![CI](https://img.shields.io/github/actions/workflow/status/gravity-ui/app-builder/.github/workflows/ci.yml?branch=main)](https://github.com/gravity-ui/app-builder/actions/workflows/ci.yml?query=branch:main)
2
+
3
+ Develop and build your client-server projects, powered by typescript and webpack.
2
4
 
3
5
  ## Install
4
6
 
@@ -7,3 +9,295 @@ npm install --save-dev @gravity-ui/app-builder
7
9
  ```
8
10
 
9
11
  ## Usage
12
+
13
+ `@gravity-ui/app-builder` provides CLI (`npx app-builder`). You can view available commands with the `--help` flag.
14
+
15
+ ### Develop your project
16
+
17
+ ```sh
18
+ npx app-builder dev # to view supported options add the --help flag.
19
+ ```
20
+
21
+ ### Build your project
22
+
23
+ ```sh
24
+ npx app-builder build # to view supported options add the --help flag.
25
+ ```
26
+
27
+ ### Configuration
28
+
29
+ You can use any of these files:
30
+
31
+ - app-builder.config.ts
32
+ - app-builder.config.js
33
+ - app-builder.config.json
34
+ - app-builder property in your package.json
35
+
36
+ You can also specify a custom filename using the `--config` flag
37
+
38
+ #### TypeScript/JavaScript
39
+
40
+ ```ts
41
+ import {defineConfig} from '@gravity-ui/app-builder';
42
+
43
+ export default defineConfig({
44
+ client: {
45
+ // client settings
46
+ },
47
+ server: {
48
+ // server settings
49
+ },
50
+ });
51
+ ```
52
+
53
+ #### Conditional config
54
+
55
+ If the config needs to be conditionally determined, it can export a function instead:
56
+
57
+ ```ts
58
+ import {defineConfig} from '@gravity-ui/app-builder';
59
+
60
+ export default defineConfig(async function (
61
+ /** @type dev | build */
62
+ command,
63
+ /**
64
+ * values specified with --env flag
65
+ *
66
+ * @type {[k in string]: string}
67
+ *
68
+ * @example
69
+ * With follow command:
70
+ * app-build dev --env=path.to.member1=value1 --env=path.to.member2=value2
71
+ * you get:
72
+ * env = {path: {to: {member1: 'value1', member2: 'value2'}}}
73
+ */
74
+ env,
75
+ ) {
76
+ return {
77
+ verbose: command === 'dev',
78
+ client: {
79
+ // client settings
80
+ },
81
+ server: {
82
+ // server settings
83
+ },
84
+ };
85
+ });
86
+
87
+ export default config;
88
+ ```
89
+
90
+ #### package.json
91
+
92
+ ```json
93
+ {
94
+ "app-builder": {
95
+ "client": {
96
+ // client settings
97
+ },
98
+ "server": {
99
+ // server settings
100
+ }
101
+ },
102
+ "scripts": {
103
+ "dev": "app-builder dev",
104
+ "build": "app-builder build"
105
+ }
106
+ }
107
+ ```
108
+
109
+ ### Common
110
+
111
+ - `target` (`client | server`) — select compilation unit.
112
+ - `verbose` (`boolean`) - turn on verbose output.
113
+
114
+ ### Server
115
+
116
+ `app-builder` compiles server with typescript.
117
+ Default folder for server code is `src/server`. There is must be file `tsconfig.json`
118
+
119
+ ```json
120
+ {
121
+ "compilerOptions": {
122
+ "outDir": "../../dist/server"
123
+ }
124
+ }
125
+ ```
126
+
127
+ and `index.ts` - server entrypoint.
128
+
129
+ `outDir` - must be configured to place compiled files to `{rootDir}/dist/server`.
130
+ The server is started with the command `node {rootDir}/dist/server/index.js`.
131
+
132
+ #### Options
133
+
134
+ All server settings are used only in dev mode:
135
+
136
+ - `port` (`number | true`) — specify port that server listens. The port will be used to
137
+ pass through requests from the client to the server. If set to `true`, the port will be selected automatically.
138
+ The server is started with the command `APP_PORT=${port} node dist/server/index.js --port ${port}`.
139
+ - `watch` (`string[]`) — by default `app-builder` monitors only `src/server` directory.
140
+ If you need to watch other directories, specify them here.
141
+ - `watchThrottle` (`number`) — use to add an extra throttle, or delay restarting.
142
+ - `inspect/inspectBrk` (`number | true`) — listen for a debugging client on specified port.
143
+ If specified `true`, try to listen on `9229`.
144
+
145
+ ### Client
146
+
147
+ `app-builder` bundles client with [webpack](https://webpack.js.org). Client code must be in `src/ui` folder.
148
+ `src/ui/entries` - each file in this folder is used as entrypoint. `dist/public/build` is output directory for bundles.
149
+
150
+ #### Options
151
+
152
+ All paths must be specified relative `rootDir` of the project.
153
+
154
+ - `modules` (`string[]`) — Tell webpack what directories should be searched when resolving modules. `modules` automatically
155
+ populates with `baseUrl` from `src/ui/tsconfig.json`.
156
+ - `alias` (`Record<string, string>`) — Create aliases to import or require certain modules more easily, [more](https://webpack.js.org/configuration/resolve/#resolvealias)
157
+
158
+ With this `{rootDir}/src/ui/tsconfig.json`:
159
+
160
+ ```json
161
+ {
162
+ "compilerOptions": {
163
+ "baseDir": ".",
164
+ "paths": {
165
+ "~units": ["units/*"]
166
+ }
167
+ }
168
+ }
169
+ ```
170
+
171
+ `modules` will contain `["{rootDir}/src"]` and aliases - `{"~units": ["{rootDir}/src/units"]}`;
172
+
173
+ - `includes` (`string[]`) — additional compilation paths. Example: `includes: ['node_modules/my-lib', 'src/shared']`
174
+ - `images` (`string[]`) — Additional paths for images. Example: `images: ['node_modules/my-lib/img']`
175
+ - `icons` (`string[]`) — Additional paths for svg icons. By default, all svgs with paths including `icons/` will be processed.
176
+ Example: `icons: [node_modules/@fortawesome/fontawesome-pro/svgs]`
177
+ - `publicPathPrefix` (`string`) — publicPath prefix, will be added to `/build/`
178
+ - `symlinks` (`boolean`) — Follow symbolic links while looking for a file. [more](https://webpack.js.org/configuration/resolve/#resolvesymlinks)
179
+ - `externals` — specify dependencies that shouldn't be resolved by webpack, but should become dependencies of the resulting bundle. [more](https://webpack.js.org/configuration/externals/)
180
+ - `node` — include polyfills or mocks for various node stuff. [more](https://webpack.js.org/configuration/node/)
181
+ - `fallback` — Redirect module requests when normal resolving fails. [more](https://webpack.js.org/configuration/resolve/#resolvefallback)
182
+ - `polyfill` — allow enable Node.js `process` object polyfill.
183
+ - `hiddenSourceMap` (`boolean=true`) - if `false` - source maps will be generated for prod builds
184
+ - `disableSourceMapGeneration` (`boolean`) — disable sourcemap generation;
185
+ - `definitions` — add additional options to DefinePlugin. [more](https://webpack.js.org/plugins/define-plugin/#usage)
186
+ - `newJsxTransform` (`boolean=true`) — use new JSX Transform.
187
+ - `svgr` (`SvgrConfig`) — svgr plugin options. [more](https://react-svgr.com/docs/options/)
188
+ - `entryFilter` (`string[]`) — filter used entrypoints.
189
+ - `excludeFromClean` (`string[]`) — do not clean provided paths before build.
190
+ - `disableForkTsChecker` (`boolean`) - do not use `ForkTsChecker`.
191
+
192
+ ##### Dev build
193
+
194
+ - `devServer` (`Object`) — webpack dev server options.
195
+ - `ipc` (`string`) — the Unix socket to listen to. If `ipc` and `port` are not defined, then the socket `{rootDir}/dist/run/client.sock` is used.
196
+ - `port` (`number | true`) — specify a port number to listen for requests on. If `true`, the free port will be selected automatically.
197
+ - `webSocketPath` (`string`) — tells clients connected to devServer to use the provided path to connect. Default is `${publicPathPrefix}/build/sockjs-node`.
198
+ - `type` (`'https'`) — allow to serve over HTTPS.
199
+ - `options` (`import('https').ServerOptions`) — allow to provide your own certificate.
200
+ - `watchOptions` — a set of options used to customize watch mode, [more](https://webpack.js.org/configuration/watch/#watchoptions)
201
+ - `watchPackages` (`boolean`) - watch all changes in `node_modules`.
202
+ - `disableReactRefresh` (`boolean`) — disable `react-refresh` in dev mode.
203
+ - `detectCircularDependencies` (`true | CircularDependenciesOptions`) - detect modules with circular dependencies, [more](https://github.com/aackerman/circular-dependency-plugin)
204
+
205
+ ##### Production build
206
+
207
+ - `analyzeBundle` (`true | statoscope`) — tools to analyze bundle.
208
+ - `true` — enable [webpack-bundle-analyzer](https://github.com/webpack-contrib/webpack-bundle-analyzer) plugin. Report generated to `dist/public/build/stats.html`
209
+ - `statoscope` — enable [statoscope](https://github.com/statoscope/statoscope) plugin. Reports generated to `dist/public/build/stats.json` and `dist/public/build/report.json`
210
+ - `reactProfiling` (`boolean`) — use react profiler API in production, this option also disable minimization. The API is required by React developers tools for profile.
211
+ - `cdn` (`CdnUploadConfig | CdnUploadConfig[]`) - upload bundled client files to CDN.
212
+ - `bucket` (`string`) — bucket name
213
+ - `prefix` (`string`) — path to files inside the bucket
214
+ - `region` (`string`) — AWS region or any string
215
+ - `endpoint` (`string`) - cdn host to upload files
216
+ - `compress` (`boolean`) - upload also gzip and brotli compressed versions of files
217
+ - `additionalPattern` (`string[]`) — patterns for uploading additional files. By default, only files generated by webpack are loaded.
218
+
219
+ ##### Optimization
220
+
221
+ - `vendors` (`string[]`) — additional libraries for vendor chunk
222
+ - `momentTz` — [settings](https://www.npmjs.com/package/moment-timezone-data-webpack-plugin) for moment-timezone (by default data is truncated);
223
+ - `contextReplacement` (`object`)
224
+ - `highlight.js` (`string[]`) — list of language names to include, e.g. `['javascript', 'python', 'bash']`;
225
+ - `locale`: (`string[]=['ru']`) — list of `moment.js` or `day.js` locales to include, e.g. `['de', 'es']`. Locale `En` is always present.
226
+ - `safari10` (`boolean`) — Enables `safari10` terser's option. [Terser options](https://github.com/terser/terser#minify-options)
227
+
228
+ ##### Monaco editor support
229
+
230
+ - `monaco` (`object`) — use [monaco-editor-webpack-plugin](https://github.com/microsoft/monaco-editor/tree/main/webpack-plugin#monaco-editor-webpack-loader-plugin)
231
+
232
+ - `fileName` (`string`) — custom filename template for worker scripts
233
+ - `languages` (`string[]`) - include only a subset of the languages supported.
234
+ - `features` (`string[]`) - include only a subset of the editor features.
235
+ - `customLanguages` (`IFeatureDefinition[]`) - include custom languages (outside of the ones shipped with the `monaco-editor`).
236
+
237
+ ##### WebWorker support
238
+
239
+ Web workers allow you to run JavaScript code in a separate thread from the main UI thread.
240
+ This can improve the performance and responsiveness of your web application by offloading
241
+ intensive tasks to the background.
242
+
243
+ To create a web worker, you need to write a script file that defines the logic of the worker. For example,
244
+ this file (my.worker.ts) implements a simple function that adds two numbers and sends the result back to the main thread:
245
+
246
+ ```ts
247
+ // my.worker.ts
248
+ self.onmessage = async (ev) => {
249
+ const {a = 0, b = 0} = ev.data || {};
250
+ const result = a + b;
251
+ self.postMessage({
252
+ result,
253
+ });
254
+ };
255
+ ```
256
+
257
+ `app-builder` provides built-in support for web workers for files with the `.worker.[jt]s` suffix. You can choose
258
+ between two variants of getting web workers by setting the `newWebWorkerSyntax` option:
259
+
260
+ - `newWebWorkerSyntax: false` (default) - use the `worker-loader` to import web workers.
261
+ Content of worker file will be included in main bundle as blob. This variant does not
262
+ support dynamic imports inside worker. For example:
263
+
264
+ ```ts
265
+ // main.ts
266
+ import MyWorker from './my.worker.ts';
267
+
268
+ const worker = new MyWorker();
269
+ ```
270
+
271
+ In this variant, you need to add some type declarations for the worker files::
272
+
273
+ ```ts
274
+ // worker.d.ts
275
+ declare module '*.worker.ts' {
276
+ class WebpackWorker extends Worker {}
277
+
278
+ export default WebpackWorker;
279
+ }
280
+ ```
281
+
282
+ - `newWebWorkerSyntax: true` - use the webpack 5 web workers [syntax](https://webpack.js.org/guides/web-workers/#syntax)
283
+ to import web workers. This variant allows to use dynamic imports inside worker and load worker bundle from CDN. For example:
284
+
285
+ ```ts
286
+ import {Worker} from '@gravity-ui/app-builder/worker';
287
+
288
+ const MyWorker = new Worker(new URL('./my.worker'), import.meta.url);
289
+ ```
290
+
291
+ To use the web worker in your main script, you need to communicate with it using the postMessage and onmessage methods. For example:
292
+
293
+ ```ts
294
+ // main.ts
295
+
296
+ const worker = '...'; // Worker creation, first or second variant
297
+
298
+ worker.onmessage = ({data: {result}}) => {
299
+ console.log(result);
300
+ };
301
+
302
+ worker.postMessage({a: 1, b: 2});
303
+ ```
@@ -9,11 +9,8 @@ function default_1(config) {
9
9
  return new Promise((resolve, reject) => {
10
10
  const build = new controllable_script_1.ControllableScript(`
11
11
  const {buildLibrary} = require(${JSON.stringify(require.resolve('../../common/library'))});
12
- buildLibrary({
13
- lib: ${JSON.stringify(config.lib)},
14
- newJsxTransform: ${JSON.stringify(config.newJsxTransform)}
15
- });
16
- `, null);
12
+ buildLibrary({lib: ${JSON.stringify(config.lib)}});
13
+ `, null);
17
14
  build.start();
18
15
  build.onExit((code) => {
19
16
  if (code) {
@@ -22,12 +22,11 @@ var __importStar = (this && this.__importStar) || function (mod) {
22
22
  __setModuleDefault(result, mod);
23
23
  return result;
24
24
  };
25
- var _a;
26
25
  Object.defineProperty(exports, "__esModule", { value: true });
27
26
  const models_1 = require("../../common/models");
28
27
  async function default_1(config) {
29
28
  process.env.NODE_ENV = 'production';
30
- const { default: build } = await (_a = (0, models_1.isLibraryConfig)(config) ? './build-lib' : './build-service', Promise.resolve().then(() => __importStar(require(_a))));
29
+ const { default: build } = await Promise.resolve(`${(0, models_1.isLibraryConfig)(config) ? './build-lib' : './build-service'}`).then(s => __importStar(require(s)));
31
30
  return build(config);
32
31
  }
33
32
  exports.default = default_1;
@@ -1,15 +1,4 @@
1
1
  "use strict";
2
- var __rest = (this && this.__rest) || function (s, e) {
3
- var t = {};
4
- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
5
- t[p] = s[p];
6
- if (s != null && typeof Object.getOwnPropertySymbols === "function")
7
- for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
8
- if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
9
- t[p[i]] = s[p[i]];
10
- }
11
- return t;
12
- };
13
2
  var __importDefault = (this && this.__importDefault) || function (mod) {
14
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
15
4
  };
@@ -32,40 +21,55 @@ async function watchClientCompilation(config, onCompilationEnd) {
32
21
  exports.watchClientCompilation = watchClientCompilation;
33
22
  async function buildWebpackServer(config) {
34
23
  const logger = new logger_1.Logger('webpack', config.verbose);
35
- const _a = config.client.devServer || {}, { webSocketPath = path_1.default.normalize(`/${config.client.publicPathPrefix}/build/sockjs-node`) } = _a, devServer = __rest(_a, ["webSocketPath"]);
36
- const normalizedConfig = Object.assign(Object.assign({}, config.client), { devServer: Object.assign(Object.assign({}, devServer), { webSocketPath }) });
24
+ const { webSocketPath = path_1.default.normalize(`/${config.client.publicPathPrefix}/build/sockjs-node`), ...devServer } = config.client.devServer || {};
25
+ const normalizedConfig = { ...config.client, devServer: { ...devServer, webSocketPath } };
37
26
  const webpackConfig = (0, config_1.webpackConfigFactory)("development" /* WebpackMode.Dev */, normalizedConfig, { logger });
38
- const options = Object.assign({ static: path_1.default.resolve(paths_1.default.appDist, 'public'), devMiddleware: {
27
+ const options = {
28
+ static: path_1.default.resolve(paths_1.default.appDist, 'public'),
29
+ devMiddleware: {
39
30
  publicPath: path_1.default.normalize(config.client.publicPathPrefix + '/build/'),
40
31
  stats: 'errors-warnings',
41
- }, liveReload: false, hot: true, client: {
32
+ },
33
+ liveReload: false,
34
+ hot: true,
35
+ client: {
42
36
  webSocketURL: { pathname: webSocketPath },
43
37
  overlay: {
44
38
  runtimeErrors: config.verbose,
45
39
  warnings: config.verbose,
46
40
  },
47
- }, webSocketServer: {
41
+ },
42
+ webSocketServer: {
48
43
  options: {
49
44
  path: webSocketPath,
50
45
  },
51
- }, host: '0.0.0.0', allowedHosts: 'all', headers: {
46
+ },
47
+ host: '0.0.0.0',
48
+ allowedHosts: 'all',
49
+ headers: {
52
50
  'Access-Control-Allow-Origin': '*',
53
51
  'Access-Control-Allow-Methods': 'GET, POST, PUT, DELETE, PATCH, OPTIONS',
54
52
  'Access-Control-Allow-Headers': 'X-Requested-With, content-type, Authorization',
55
- } }, devServer);
56
- let listenOn = options.port || options.ipc;
53
+ },
54
+ ...devServer,
55
+ };
56
+ const listenOn = options.port || options.ipc;
57
57
  if (!listenOn) {
58
- listenOn = path_1.default.resolve(paths_1.default.appDist, 'run/client.sock');
59
- options.ipc = listenOn;
58
+ options.ipc = path_1.default.resolve(paths_1.default.appDist, 'run/client.sock');
60
59
  }
61
60
  if (config.client.lazyCompilation) {
62
- options.proxy = Object.assign(Object.assign({}, options.proxy), { '/build/lazy': {
61
+ options.proxy = {
62
+ ...options.proxy,
63
+ '/build/lazy': {
63
64
  target: `http://localhost:${config.client.lazyCompilation.port}`,
64
65
  pathRewrite: { '^/build/lazy': '' },
65
- } });
66
+ },
67
+ };
66
68
  }
67
69
  if (config.server.port) {
68
- options.proxy = Object.assign(Object.assign({}, options.proxy), { '/': {
70
+ options.proxy = {
71
+ ...options.proxy,
72
+ '/': {
69
73
  target: `http://localhost:${config.server.port}`,
70
74
  bypass: (req) => {
71
75
  if (req.method !== 'GET' && req.method !== 'HEAD') {
@@ -82,7 +86,8 @@ async function buildWebpackServer(config) {
82
86
  }
83
87
  return req.path;
84
88
  },
85
- } });
89
+ },
90
+ };
86
91
  }
87
92
  const compiler = (0, webpack_1.default)(webpackConfig);
88
93
  const server = new webpack_dev_server_1.default(options, compiler);
@@ -42,15 +42,17 @@ async function default_1(config) {
42
42
  const serverPath = path_1.default.resolve(paths_1.default.appDist, 'server');
43
43
  const { inspect, inspectBrk } = config.server;
44
44
  const startNodemon = () => {
45
- var _a;
46
45
  if (needToStartNodemon && serverCompiled && clientCompiled) {
47
46
  logger_1.default.message('Starting application at', serverPath);
48
- const serverWatch = (_a = config.server.watch) !== null && _a !== void 0 ? _a : [];
47
+ const serverWatch = config.server.watch ?? [];
49
48
  const delay = config.server.watchThrottle;
50
49
  const nodemonInstance = (0, nodemon_1.default)({
51
50
  ext: 'js json',
52
51
  script: `${serverPath}/index.js`,
53
52
  args: ['--dev', config.server.port ? `--port=${config.server.port}` : ''],
53
+ env: {
54
+ ...(config.server.port ? { APP_PORT: config.server.port } : undefined),
55
+ },
54
56
  nodeArgs: inspect || inspectBrk
55
57
  ? [`--${inspect ? 'inspect' : 'inspect-brk'}=:::${inspect || inspectBrk}`]
56
58
  : undefined,
@@ -83,19 +85,19 @@ async function default_1(config) {
83
85
  }
84
86
  process.on('SIGINT', async () => {
85
87
  logger_1.default.success('\nCleaning up...');
86
- await (serverCompilation === null || serverCompilation === void 0 ? void 0 : serverCompilation.stop('SIGINT'));
87
- await (clientCompilation === null || clientCompilation === void 0 ? void 0 : clientCompilation.stop());
88
+ await serverCompilation?.stop('SIGINT');
89
+ await clientCompilation?.stop();
88
90
  process.exit(1);
89
91
  });
90
92
  process.on('SIGTERM', async () => {
91
93
  logger_1.default.success('\nCleaning up...');
92
- await (serverCompilation === null || serverCompilation === void 0 ? void 0 : serverCompilation.stop('SIGTERM'));
93
- await (clientCompilation === null || clientCompilation === void 0 ? void 0 : clientCompilation.stop());
94
+ await serverCompilation?.stop('SIGTERM');
95
+ await clientCompilation?.stop();
94
96
  process.exit(1);
95
97
  });
96
98
  (0, signal_exit_1.default)((_code, signal) => {
97
- serverCompilation === null || serverCompilation === void 0 ? void 0 : serverCompilation.stop(signal);
98
- clientCompilation === null || clientCompilation === void 0 ? void 0 : clientCompilation.stop();
99
+ serverCompilation?.stop(signal);
100
+ clientCompilation?.stop();
99
101
  });
100
102
  }
101
103
  exports.default = default_1;
@@ -5,14 +5,14 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.watchServerCompilation = void 0;
7
7
  const path_1 = __importDefault(require("path"));
8
- const rimraf_1 = __importDefault(require("rimraf"));
8
+ const rimraf_1 = require("rimraf");
9
9
  const controllable_script_1 = require("../../common/child-process/controllable-script");
10
10
  const utils_1 = require("../../common/utils");
11
11
  const paths_1 = __importDefault(require("../../common/paths"));
12
12
  function watchServerCompilation(config) {
13
13
  const serverPath = path_1.default.resolve(paths_1.default.appDist, 'server');
14
- rimraf_1.default.sync(serverPath);
15
- rimraf_1.default.sync(paths_1.default.appRun);
14
+ rimraf_1.rimraf.sync(serverPath);
15
+ rimraf_1.rimraf.sync(paths_1.default.appRun);
16
16
  (0, utils_1.createRunFolder)();
17
17
  const build = new controllable_script_1.ControllableScript(`
18
18
  const ts = require('typescript');
@@ -54,7 +54,9 @@ class ControllableScript {
54
54
  }
55
55
  }
56
56
  this.process = execa.node(this.tmpFileName, args, {
57
- env: Object.assign({}, process.env),
57
+ env: {
58
+ ...process.env,
59
+ },
58
60
  stdio: [`inherit`, `inherit`, `inherit`, `ipc`],
59
61
  nodeOptions: ['--unhandled-rejections=strict'],
60
62
  });
@@ -32,7 +32,6 @@ const path_1 = __importDefault(require("path"));
32
32
  const fs = __importStar(require("fs-extra"));
33
33
  const RANDOM_CHARS = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz';
34
34
  function randomChars(howMany) {
35
- var _a, _b;
36
35
  const value = [];
37
36
  let rnd = null;
38
37
  // make sure that we do not fail because we ran out of entropy
@@ -44,7 +43,7 @@ function randomChars(howMany) {
44
43
  rnd = crypto_1.default.pseudoRandomBytes(howMany);
45
44
  }
46
45
  for (let i = 0; i < howMany; i++) {
47
- value.push((_b = RANDOM_CHARS[((_a = rnd[i]) !== null && _a !== void 0 ? _a : 0) % RANDOM_CHARS.length]) !== null && _b !== void 0 ? _b : '0');
46
+ value.push(RANDOM_CHARS[(rnd[i] ?? 0) % RANDOM_CHARS.length] ?? '0');
48
47
  }
49
48
  return value.join('');
50
49
  }
@@ -1,5 +1,5 @@
1
1
  import type { NormalizedServiceConfig, ServiceConfig, LibraryConfig } from './models';
2
2
  import type { CliArgs } from '../create-cli';
3
- export declare function getProjectConfig(command: string, { env, ...argv }: Partial<CliArgs>): Promise<NormalizedServiceConfig>;
3
+ export declare function getProjectConfig(command: string, { env, ...argv }: Partial<CliArgs>): Promise<LibraryConfig | NormalizedServiceConfig>;
4
4
  export declare function normalizeConfig(userConfig: ServiceConfig, mode?: 'dev' | 'build' | string): Promise<NormalizedServiceConfig>;
5
5
  export declare function normalizeConfig(userConfig: LibraryConfig, mode?: 'dev' | 'build' | string): Promise<LibraryConfig>;