@gravity-ui/app-builder 0.2.2 → 0.3.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 (35) hide show
  1. package/CHANGELOG.md +24 -0
  2. package/README.md +226 -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 +11 -9
  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 +62 -55
  29. package/dist/common/webpack/storybook.js +43 -14
  30. package/dist/common/webpack/utils.js +5 -3
  31. package/dist/create-cli.d.ts +2 -2
  32. package/dist/create-cli.js +1 -1
  33. package/dist/index.d.ts +2 -1
  34. package/dist/index.js +3 -1
  35. package/package.json +40 -41
package/CHANGELOG.md CHANGED
@@ -1,5 +1,29 @@
1
1
  # Changelog
2
2
 
3
+ ## [0.3.0](https://github.com/gravity-ui/app-builder/compare/v0.2.2...v0.3.0) (2023-05-08)
4
+
5
+
6
+ ### ⚠ BREAKING CHANGES
7
+
8
+ * **LibraryConfig:** move newJsxTransform option under lib property
9
+
10
+ ### Features
11
+
12
+ * **config:** add defineConfig helper ([31daecc](https://github.com/gravity-ui/app-builder/commit/31daecccc33fc58bc14d85c217b990c1f4302218))
13
+ * **server:** use APP_PORT env variable to pass port to server ([6b14651](https://github.com/gravity-ui/app-builder/commit/6b14651adae6cf18f0da7447636d2a8363979166))
14
+ * **storybook:** use configureServiceWebpackConfig for libraries too ([4204cf9](https://github.com/gravity-ui/app-builder/commit/4204cf9e1e5e63e16e7631477beb251e496d2690))
15
+
16
+
17
+ ### Bug Fixes
18
+
19
+ * **client:** use newJsxTransform in svgr options ([cd01f55](https://github.com/gravity-ui/app-builder/commit/cd01f552177c73b20de7e95ca65cf770e8b63dbc))
20
+ * **LibraryConfig:** move newJsxTransform option under lib property ([847a38c](https://github.com/gravity-ui/app-builder/commit/847a38cc4138741559f053ba594bcdd997c44063))
21
+
22
+
23
+ ### docs
24
+
25
+ * add documentation for services ([d78b63b](https://github.com/gravity-ui/app-builder/commit/d78b63beb03c0e446e060d977942787dc33eee2c))
26
+
3
27
  ## [0.2.2](https://github.com/gravity-ui/app-builder/compare/v0.2.1...v0.2.2) (2023-05-05)
4
28
 
5
29
 
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,226 @@ 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
+ - `disableReactRefresh` (`boolean`) — disable `react-refresh` in dev mode.
202
+ - `detectCircularDependencies` (`true | CircularDependenciesOptions`) - detect modules with circular dependencies, [more](https://github.com/aackerman/circular-dependency-plugin)
203
+
204
+ ##### Production build
205
+
206
+ - `analyzeBundle` (`true | statoscope`) — tools to analyze bundle.
207
+ - `true` — enable [webpack-bundle-analyzer](https://github.com/webpack-contrib/webpack-bundle-analyzer) plugin. Report generated to `dist/public/build/stats.html`
208
+ - `statoscope` — enable [statoscope](https://github.com/statoscope/statoscope) plugin. Reports generated to `dist/public/build/stats.json` and `dist/public/build/report.json`
209
+ - `reactProfiling` (`boolean`) — use react profiler API in production, this option also disable minimization. The API is required by React developers tools for profile.
210
+ - `cdn` (`CdnUploadConfig | CdnUploadConfig[]`) - upload bundled client files to CDN.
211
+ - `bucket` (`string`) — bucket name
212
+ - `prefix` (`string`) — path to files inside the bucket
213
+ - `region` (`string`) — AWS region or any string
214
+ - `endpoint` (`string`) - cdn host to upload files
215
+ - `compress` (`boolean`) - upload also gzip and brotli compressed versions of files
216
+ - `additionalPattern` (`string[]`) — patterns for uploading additional files. By default, only files generated by webpack are loaded.
217
+
218
+ ##### Optimization
219
+
220
+ - `vendors` (`string[]`) — additional libraries for vendor chunk
221
+ - `momentTz` — [settings](https://www.npmjs.com/package/moment-timezone-data-webpack-plugin) for moment-timezone (by default data is truncated);
222
+ - `contextReplacement` (`object`)
223
+ - `highlight.js` (`string[]`) — list of language names to include, e.g. `['javascript', 'python', 'bash']`;
224
+ - `locale`: (`string[]=['ru']`) — list of `moment.js` or `day.js` locales to include, e.g. `['de', 'es']`. Locale `En` is always present.
225
+ - `safari10` (`boolean`) — Enables `safari10` terser's option. [Terser options](https://github.com/terser/terser#minify-options)
226
+
227
+ ##### Monaco editor support
228
+
229
+ - `monaco` (`object`) — use [monaco-editor-webpack-plugin](https://github.com/microsoft/monaco-editor/tree/main/webpack-plugin#monaco-editor-webpack-loader-plugin)
230
+
231
+ - `fileName` (`string`) — custom filename template for worker scripts
232
+ - `languages` (`string[]`) - include only a subset of the languages supported.
233
+ - `features` (`string[]`) - include only a subset of the editor features.
234
+ - `customLanguages` (`IFeatureDefinition[]`) - include custom languages (outside of the ones shipped with the `monaco-editor`).
@@ -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>;
@@ -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
  };
@@ -30,8 +19,7 @@ function remapPaths(paths) {
30
19
  function omitUndefined(obj) {
31
20
  return lodash_1.default.omitBy(obj, lodash_1.default.isUndefined);
32
21
  }
33
- async function getProjectConfig(command, _a) {
34
- var { env } = _a, argv = __rest(_a, ["env"]);
22
+ async function getProjectConfig(command, { env, ...argv }) {
35
23
  function getLoader(loader) {
36
24
  return async (pathname, content) => {
37
25
  const config = loader(pathname, content);
@@ -85,13 +73,30 @@ async function getProjectConfig(command, _a) {
85
73
  inspect: argv.inspect,
86
74
  inspectBrk: argv.inspectBrk,
87
75
  };
88
- const config = Object.assign({}, (await (cfg === null || cfg === void 0 ? void 0 : cfg.config)));
89
- const projectConfig = Object.assign(Object.assign(Object.assign({}, config), omitUndefined({ target: argv.target, verbose: argv.verbose })), { client: Object.assign(Object.assign(Object.assign({}, config.client), omitUndefined(client)), (argv.cdn === 'false' ? { cdn: undefined } : undefined)), server: Object.assign(Object.assign({}, config.server), omitUndefined(server)) });
76
+ const config = { ...(await cfg?.config) };
77
+ if ((0, models_1.isLibraryConfig)(config)) {
78
+ return normalizeConfig({
79
+ ...config,
80
+ ...omitUndefined({ verbose: argv.verbose }),
81
+ });
82
+ }
83
+ const projectConfig = {
84
+ ...config,
85
+ ...omitUndefined({ target: argv.target, verbose: argv.verbose }),
86
+ client: {
87
+ ...config.client,
88
+ ...omitUndefined(client),
89
+ ...(argv.cdn === 'false' ? { cdn: undefined } : undefined),
90
+ },
91
+ server: {
92
+ ...config.server,
93
+ ...omitUndefined(server),
94
+ },
95
+ };
90
96
  return normalizeConfig(projectConfig, command);
91
97
  }
92
98
  exports.getProjectConfig = getProjectConfig;
93
99
  async function normalizeConfig(userConfig, mode) {
94
- var _a;
95
100
  if ((0, models_1.isServiceConfig)(userConfig)) {
96
101
  const config = lodash_1.default.cloneDeep(userConfig);
97
102
  const client = typeof config.client === 'object' ? config.client : (config.client = {});
@@ -108,19 +113,18 @@ async function normalizeConfig(userConfig, mode) {
108
113
  return config;
109
114
  }
110
115
  const config = lodash_1.default.cloneDeep(userConfig);
111
- config.newJsxTransform = (_a = config.newJsxTransform) !== null && _a !== void 0 ? _a : true;
116
+ config.lib.newJsxTransform = config.lib.newJsxTransform ?? true;
112
117
  return config;
113
118
  }
114
119
  exports.normalizeConfig = normalizeConfig;
115
120
  async function normalizeClientConfig(client, mode) {
116
- var _a, _b, _c, _d, _e, _f;
117
- client.newJsxTransform = (_a = client.newJsxTransform) !== null && _a !== void 0 ? _a : true;
121
+ client.newJsxTransform = client.newJsxTransform ?? true;
118
122
  client.publicPathPrefix = client.publicPathPrefix || '';
119
123
  client.modules = client.modules && remapPaths(client.modules);
120
124
  client.includes = client.includes && remapPaths(client.includes);
121
125
  client.images = client.images && remapPaths(client.images);
122
- client.hiddenSourceMap = (_b = client.hiddenSourceMap) !== null && _b !== void 0 ? _b : true;
123
- client.svgr = (_c = client.svgr) !== null && _c !== void 0 ? _c : {};
126
+ client.hiddenSourceMap = client.hiddenSourceMap ?? true;
127
+ client.svgr = client.svgr ?? {};
124
128
  client.entryFilter = client.entryFilter && splitPaths(client.entryFilter);
125
129
  if (mode === 'dev') {
126
130
  if (client.lazyCompilation) {
@@ -133,19 +137,23 @@ async function normalizeClientConfig(client, mode) {
133
137
  client.lazyCompilation.port = await (0, get_port_1.default)({ port: 6000 });
134
138
  }
135
139
  }
136
- const devServer = ((_d = client.devServer) === null || _d === void 0 ? void 0 : _d.port)
140
+ const devServer = client.devServer?.port
137
141
  ? {
138
142
  port: client.devServer.port === true
139
143
  ? await (0, get_port_1.default)({ port: 8000 })
140
144
  : client.devServer.port,
141
145
  ipc: undefined,
142
146
  }
143
- : { port: undefined, ipc: (_e = client.devServer) === null || _e === void 0 ? void 0 : _e.ipc };
144
- const _g = (_f = client.devServer) !== null && _f !== void 0 ? _f : {}, { type, options } = _g, other = __rest(_g, ["type", "options"]);
145
- client.devServer = Object.assign(Object.assign(Object.assign({}, other), devServer), { server: {
147
+ : { port: undefined, ipc: client.devServer?.ipc };
148
+ const { type, options, ...other } = client.devServer ?? {};
149
+ client.devServer = {
150
+ ...other,
151
+ ...devServer,
152
+ server: {
146
153
  type,
147
154
  options,
148
- } });
155
+ },
156
+ };
149
157
  delete client.cdn;
150
158
  }
151
159
  else {