@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
@@ -22,17 +22,6 @@ var __importStar = (this && this.__importStar) || function (mod) {
22
22
  __setModuleDefault(result, mod);
23
23
  return result;
24
24
  };
25
- var __rest = (this && this.__rest) || function (s, e) {
26
- var t = {};
27
- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
28
- t[p] = s[p];
29
- if (s != null && typeof Object.getOwnPropertySymbols === "function")
30
- for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
31
- if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
32
- t[p[i]] = s[p[i]];
33
- }
34
- return t;
35
- };
36
25
  var __importDefault = (this && this.__importDefault) || function (mod) {
37
26
  return (mod && mod.__esModule) ? mod : { "default": mod };
38
27
  };
@@ -90,7 +79,7 @@ function webpackConfigFactory(webpackMode, config, { logger } = {}) {
90
79
  optimization: configureOptimization(helperOptions),
91
80
  externals: config.externals,
92
81
  node: config.node,
93
- watchOptions: config.watchOptions,
82
+ watchOptions: configureWatchOptions(helperOptions),
94
83
  ignoreWarnings: [/Failed to parse source map/],
95
84
  infrastructureLogging: config.verbose
96
85
  ? {
@@ -110,6 +99,9 @@ function webpackConfigFactory(webpackMode, config, { logger } = {}) {
110
99
  : undefined,
111
100
  }
112
101
  : undefined,
102
+ snapshot: {
103
+ managedPaths: config.watchOptions?.watchPackages ? [] : undefined,
104
+ },
113
105
  };
114
106
  }
115
107
  exports.webpackConfigFactory = webpackConfigFactory;
@@ -149,10 +141,10 @@ function updateIncludesFactory() {
149
141
  // eslint-disable-next-line security/detect-non-literal-regexp
150
142
  !new RegExp(linkedPackage.name).test(pathname)));
151
143
  result = [...result, ...linkedPackagesJsIncludes];
152
- if (options === null || options === void 0 ? void 0 : options.includeRootAssets) {
144
+ if (options?.includeRootAssets) {
153
145
  result = [...result, ...linkedPackagesRootAssetsIncludes];
154
146
  }
155
- if (options === null || options === void 0 ? void 0 : options.includeRootStyles) {
147
+ if (options?.includeRootStyles) {
156
148
  result = [...result, ...linkedPackagesRootStylesIncludes];
157
149
  }
158
150
  return result;
@@ -167,6 +159,17 @@ function configureDevTool({ isEnvProduction, config }) {
167
159
  }
168
160
  return config.disableSourceMapGeneration ? false : format;
169
161
  }
162
+ function configureWatchOptions({ config }) {
163
+ const watchOptions = {
164
+ ...config.watchOptions,
165
+ followSymlinks: config.watchOptions?.followSymlinks ??
166
+ (!config.symlinks && config.watchOptions?.watchPackages)
167
+ ? true
168
+ : undefined,
169
+ };
170
+ delete watchOptions.watchPackages;
171
+ return watchOptions;
172
+ }
170
173
  function configureResolve({ isEnvProduction, config, tsLinkedPackages, }) {
171
174
  let alias = config.alias || {};
172
175
  alias = Object.entries(alias).reduce((result, [key, value]) => {
@@ -184,10 +187,13 @@ function configureResolve({ isEnvProduction, config, tsLinkedPackages, }) {
184
187
  }
185
188
  const { aliases, modules = [] } = (0, utils_1.resolveTsconfigPathsToAlias)(path_1.default.resolve(paths_1.default.appClient, 'tsconfig.json')) || {};
186
189
  return {
187
- alias: Object.assign(Object.assign({}, aliases), alias),
190
+ alias: {
191
+ ...aliases,
192
+ ...alias,
193
+ },
188
194
  modules: ['node_modules', ...modules, ...(config.modules || [])],
189
195
  extensions: ['.mjs', '.cjs', '.js', '.jsx', '.ts', '.tsx', '.json'],
190
- symlinks: config.symlinks || false,
196
+ symlinks: config.symlinks,
191
197
  fallback: config.fallback,
192
198
  };
193
199
  }
@@ -197,12 +203,15 @@ function createEntryArray(entry) {
197
203
  }
198
204
  function addEntry(entry, file) {
199
205
  const newEntry = path_1.default.resolve(paths_1.default.appEntry, file);
200
- return Object.assign(Object.assign({}, entry), { [path_1.default.parse(file).name]: createEntryArray(newEntry) });
206
+ return {
207
+ ...entry,
208
+ [path_1.default.parse(file).name]: createEntryArray(newEntry),
209
+ };
201
210
  }
202
211
  function configureEntry({ config }) {
203
212
  let entries = fs_1.default.readdirSync(paths_1.default.appEntry).filter((file) => /\.[jt]sx?$/.test(file));
204
213
  if (Array.isArray(config.entryFilter) && config.entryFilter.length) {
205
- entries = entries.filter((entry) => { var _a, _b; return (_a = config.entryFilter) === null || _a === void 0 ? void 0 : _a.includes((_b = entry.split('.')[0]) !== null && _b !== void 0 ? _b : ''); });
214
+ entries = entries.filter((entry) => config.entryFilter?.includes(entry.split('.')[0] ?? ''));
206
215
  }
207
216
  if (!entries.length) {
208
217
  throw new Error('No entries were found after applying UI_CORE_ENTRY_FILTER');
@@ -217,12 +226,14 @@ function getFileNames({ isEnvProduction }) {
217
226
  : 'js/[name].chunk.js',
218
227
  };
219
228
  }
220
- function configureOutput(_a) {
221
- var { isEnvDevelopment } = _a, rest = __rest(_a, ["isEnvDevelopment"]);
222
- return Object.assign(Object.assign({}, getFileNames(Object.assign({ isEnvDevelopment }, rest))), { path: paths_1.default.appBuild, pathinfo: isEnvDevelopment });
229
+ function configureOutput({ isEnvDevelopment, ...rest }) {
230
+ return {
231
+ ...getFileNames({ isEnvDevelopment, ...rest }),
232
+ path: paths_1.default.appBuild,
233
+ pathinfo: isEnvDevelopment,
234
+ };
223
235
  }
224
236
  function createJavaScriptLoader({ isEnvProduction, isEnvDevelopment, config, }) {
225
- var _a;
226
237
  return {
227
238
  loader: require.resolve('babel-loader'),
228
239
  options: {
@@ -233,7 +244,7 @@ function createJavaScriptLoader({ isEnvProduction, isEnvDevelopment, config, })
233
244
  isEnvDevelopment &&
234
245
  !config.disableReactRefresh && [
235
246
  require.resolve('react-refresh/babel'),
236
- ((_a = config.devServer) === null || _a === void 0 ? void 0 : _a.webSocketPath)
247
+ config.devServer?.webSocketPath
237
248
  ? {
238
249
  overlay: {
239
250
  sockPath: config.devServer.webSocketPath,
@@ -283,14 +294,18 @@ function createWorkerRule(options) {
283
294
  test: /\.worker\.[jt]sx?$/,
284
295
  exclude: /node_modules/,
285
296
  use: [
286
- {
287
- loader: require.resolve('worker-loader'),
288
- // currently workers located on cdn are not working properly, so we are enforcing loading workers from
289
- // service instead
290
- options: {
291
- inline: 'no-fallback',
297
+ options.config.newWebWorkerSyntax
298
+ ? {
299
+ loader: require.resolve('./worker/worker-loader'),
300
+ }
301
+ : {
302
+ loader: require.resolve('worker-loader'),
303
+ // currently workers located on cdn are not working properly, so we are enforcing loading workers from
304
+ // service instead
305
+ options: {
306
+ inline: 'no-fallback',
307
+ },
292
308
  },
293
- },
294
309
  createJavaScriptLoader(options),
295
310
  ],
296
311
  };
@@ -346,36 +361,44 @@ function createStylesRule({ isEnvDevelopment, isEnvProduction, config, }) {
346
361
  }
347
362
  function createIconsRule({ isEnvProduction, config }, jsLoader) {
348
363
  const iconIncludes = config.icons || [];
349
- return Object.assign({
364
+ return {
350
365
  // eslint-disable-next-line security/detect-unsafe-regex
351
- test: /\.svg(\?v=\d+\.\d+\.\d+)?$/,
366
+ test: /\.svg(\?v=\d+\.\d+\.\d+)?$/,
352
367
  // we can't use one rule with issuer: /\.[jt]sx?$/ cause of https://github.com/webpack/webpack/issues/9309
353
- issuer: jsLoader ? undefined : /\.s?css$/, include: [
368
+ issuer: jsLoader ? undefined : /\.s?css$/,
369
+ include: [
354
370
  /icons\/.*\.svg$/,
355
371
  // eslint-disable-next-line security/detect-non-literal-regexp
356
372
  ...iconIncludes.map((dir) => new RegExp(dir)),
357
- ] }, (jsLoader
358
- ? {
359
- use: [
360
- jsLoader,
361
- {
362
- loader: require.resolve('@svgr/webpack'),
363
- options: Object.assign({ babel: false, dimensions: false }, config.svgr),
373
+ ],
374
+ ...(jsLoader
375
+ ? {
376
+ use: [
377
+ jsLoader,
378
+ {
379
+ loader: require.resolve('@svgr/webpack'),
380
+ options: {
381
+ babel: false,
382
+ dimensions: false,
383
+ jsxRuntime: config.newJsxTransform ? 'automatic' : 'classic',
384
+ ...config.svgr,
385
+ },
386
+ },
387
+ ],
388
+ }
389
+ : {
390
+ type: 'asset',
391
+ parser: {
392
+ dataUrlCondition: {
393
+ maxSize: imagesSizeLimit,
394
+ },
364
395
  },
365
- ],
366
- }
367
- : {
368
- type: 'asset',
369
- parser: {
370
- dataUrlCondition: {
371
- maxSize: imagesSizeLimit,
396
+ generator: {
397
+ filename: 'assets/images/[name].[contenthash:8][ext]',
398
+ publicPath: isEnvProduction ? '../' : undefined,
372
399
  },
373
- },
374
- generator: {
375
- filename: 'assets/images/[name].[contenthash:8][ext]',
376
- publicPath: isEnvProduction ? '../' : undefined,
377
- },
378
- }));
400
+ }),
401
+ };
379
402
  }
380
403
  function createAssetsRules({ updateIncludes = lodash_1.default.identity, isEnvProduction, config, }) {
381
404
  const imagesRule = {
@@ -470,16 +493,14 @@ function createFallbackRules({ isEnvProduction }) {
470
493
  return rules;
471
494
  }
472
495
  function createMomentTimezoneDataPlugin(options = {}) {
473
- var _a, _b;
474
496
  const currentYear = new Date().getFullYear();
475
497
  // By default get data for current year only
476
498
  // https://momentjs.com/timezone/docs/#/use-it/webpack/
477
- const startYear = (_a = options.startYear) !== null && _a !== void 0 ? _a : currentYear;
478
- const endYear = (_b = options.endYear) !== null && _b !== void 0 ? _b : currentYear;
479
- return new moment_timezone_data_webpack_plugin_1.default(Object.assign(Object.assign({}, options), { startYear, endYear }));
499
+ const startYear = options.startYear ?? currentYear;
500
+ const endYear = options.endYear ?? currentYear;
501
+ return new moment_timezone_data_webpack_plugin_1.default({ ...options, startYear, endYear });
480
502
  }
481
503
  function configurePlugins(options) {
482
- var _a;
483
504
  const { isEnvDevelopment, isEnvProduction, config } = options;
484
505
  const excludeFromClean = config.excludeFromClean || [];
485
506
  const plugins = [
@@ -496,7 +517,10 @@ function configurePlugins(options) {
496
517
  publicPath: '',
497
518
  }),
498
519
  createMomentTimezoneDataPlugin(config.momentTz),
499
- new webpack.DefinePlugin(Object.assign({ 'process.env.NODE_ENV': JSON.stringify(process.env.NODE_ENV) }, config.definitions)),
520
+ new webpack.DefinePlugin({
521
+ 'process.env.NODE_ENV': JSON.stringify(process.env.NODE_ENV),
522
+ ...config.definitions,
523
+ }),
500
524
  ];
501
525
  if (options.logger) {
502
526
  plugins.push(new progress_plugin_1.ProgressPlugin({ logger: options.logger }));
@@ -518,14 +542,19 @@ function configurePlugins(options) {
518
542
  }
519
543
  if (config.monaco) {
520
544
  const MonacoEditorWebpackPlugin = require('monaco-editor-webpack-plugin');
521
- plugins.push(new MonacoEditorWebpackPlugin(Object.assign(Object.assign({}, config.monaco), {
545
+ plugins.push(new MonacoEditorWebpackPlugin({
546
+ ...config.monaco,
522
547
  // currently, workers located on cdn are not working properly, so we are enforcing loading workers from
523
548
  // service instead
524
- publicPath: path_1.default.normalize(config.publicPathPrefix + '/build/') })));
549
+ publicPath: path_1.default.normalize(config.publicPathPrefix + '/build/'),
550
+ }));
525
551
  }
526
552
  if (isEnvDevelopment && !config.disableReactRefresh) {
527
553
  const { webSocketPath = path_1.default.normalize(`/${config.publicPathPrefix}/build/sockjs-node`) } = config.devServer || {};
528
- plugins.push(new react_refresh_webpack_plugin_1.default({ overlay: { sockPath: webSocketPath } }));
554
+ plugins.push(new react_refresh_webpack_plugin_1.default({
555
+ overlay: { sockPath: webSocketPath },
556
+ exclude: /\.worker\.[jt]sx?$/,
557
+ }));
529
558
  }
530
559
  if (config.detectCircularDependencies) {
531
560
  let circularPluginOptions = {
@@ -549,7 +578,7 @@ function configurePlugins(options) {
549
578
  },
550
579
  }));
551
580
  }
552
- if ((_a = config.polyfill) === null || _a === void 0 ? void 0 : _a.process) {
581
+ if (config.polyfill?.process) {
553
582
  plugins.push(new webpack.ProvidePlugin({ process: 'process/browser.js' }));
554
583
  }
555
584
  if (isEnvProduction) {
@@ -639,8 +668,7 @@ function configurePlugins(options) {
639
668
  return plugins;
640
669
  }
641
670
  function configureOptimization({ isEnvProduction, config, }) {
642
- var _a;
643
- const configVendors = (_a = config.vendors) !== null && _a !== void 0 ? _a : [];
671
+ const configVendors = config.vendors ?? [];
644
672
  const vendorsList = [
645
673
  'react',
646
674
  'react-dom',
@@ -1,2 +1,2 @@
1
1
  "use strict";
2
- __webpack_public_path__ = window.__PUBLIC_PATH__;
2
+ __webpack_public_path__ = window.__PUBLIC_PATH__ ?? '/build/';
@@ -12,27 +12,52 @@ const config_1 = require("./config");
12
12
  const config_2 = require("../config");
13
13
  const models_1 = require("../models");
14
14
  async function configureServiceWebpackConfig(mode, storybookConfig) {
15
- var _a, _b, _c, _d, _e;
16
15
  const serviceConfig = await (0, config_2.getProjectConfig)(mode === "production" /* WebpackMode.Prod */ ? 'build' : 'dev', {});
17
- if (!(0, models_1.isServiceConfig)(serviceConfig)) {
18
- throw new Error('configureServiceWebpackConfig can be used only for services, but got the library config');
16
+ let options = {};
17
+ if ((0, models_1.isLibraryConfig)(serviceConfig)) {
18
+ options = {
19
+ includes: ['src'],
20
+ newJsxTransform: serviceConfig.lib?.newJsxTransform,
21
+ };
19
22
  }
20
- const webpackConfig = await configureWebpackConfigForStorybook(mode, serviceConfig.client);
21
- return Object.assign(Object.assign({}, storybookConfig), { plugins: [...((_a = storybookConfig.plugins) !== null && _a !== void 0 ? _a : []), ...webpackConfig.plugins], resolve: Object.assign(Object.assign(Object.assign({}, storybookConfig.resolve), webpackConfig.resolve), { alias: Object.assign(Object.assign({}, (_b = storybookConfig.resolve) === null || _b === void 0 ? void 0 : _b.alias), webpackConfig.resolve.alias), modules: [
22
- ...(((_c = storybookConfig.resolve) === null || _c === void 0 ? void 0 : _c.modules) || []),
23
+ else {
24
+ options = serviceConfig.client;
25
+ }
26
+ const webpackConfig = await configureWebpackConfigForStorybook(mode, options);
27
+ return {
28
+ ...storybookConfig,
29
+ plugins: [...(storybookConfig.plugins ?? []), ...webpackConfig.plugins],
30
+ resolve: {
31
+ ...storybookConfig.resolve,
32
+ ...webpackConfig.resolve,
33
+ alias: {
34
+ ...storybookConfig.resolve?.alias,
35
+ ...webpackConfig.resolve.alias,
36
+ },
37
+ modules: [
38
+ ...(storybookConfig.resolve?.modules || []),
23
39
  ...(webpackConfig.resolve.modules || []),
24
- ], extensions: [
25
- ...((_e = (_d = storybookConfig.resolve) === null || _d === void 0 ? void 0 : _d.extensions) !== null && _e !== void 0 ? _e : []),
40
+ ],
41
+ extensions: [
42
+ ...(storybookConfig.resolve?.extensions ?? []),
26
43
  ...(webpackConfig.resolve.extensions || []),
27
- ] }), module: Object.assign(Object.assign({}, storybookConfig.module), { rules: webpackConfig.module.rules }) });
44
+ ],
45
+ },
46
+ module: {
47
+ ...storybookConfig.module,
48
+ rules: webpackConfig.module.rules,
49
+ },
50
+ };
28
51
  }
29
52
  exports.configureServiceWebpackConfig = configureServiceWebpackConfig;
30
53
  async function configureWebpackConfigForStorybook(mode, userConfig = {}) {
31
- var _a;
32
54
  const isEnvDevelopment = mode === "development" /* WebpackMode.Dev */;
33
55
  const isEnvProduction = mode === "production" /* WebpackMode.Prod */;
34
56
  const config = await (0, config_2.normalizeConfig)({
35
- client: Object.assign(Object.assign({}, userConfig), { includes: ((_a = userConfig.includes) !== null && _a !== void 0 ? _a : []).concat(['.storybook']) }),
57
+ client: {
58
+ ...userConfig,
59
+ includes: (userConfig.includes ?? []).concat(['.storybook']),
60
+ },
36
61
  });
37
62
  const helperOptions = {
38
63
  isEnvDevelopment,
@@ -53,14 +78,18 @@ function configurePlugins({ isEnvDevelopment, isEnvProduction, config }) {
53
78
  if (config.definitions) {
54
79
  // eslint-disable-next-line security/detect-non-literal-require
55
80
  const webpack = require(path_1.default.resolve(process.cwd(), 'node_modules/webpack'));
56
- plugins.push(new webpack.DefinePlugin(Object.assign({}, config.definitions)));
81
+ plugins.push(new webpack.DefinePlugin({
82
+ ...config.definitions,
83
+ }));
57
84
  }
58
85
  if (config.monaco) {
59
86
  const MonacoEditorWebpackPlugin = require('monaco-editor-webpack-plugin');
60
- plugins.push(new MonacoEditorWebpackPlugin(Object.assign(Object.assign({}, config.monaco), {
87
+ plugins.push(new MonacoEditorWebpackPlugin({
88
+ ...config.monaco,
61
89
  // currently, workers located on cdn are not working properly, so we are enforcing loading workers from
62
90
  // service instead
63
- publicPath: '/' })));
91
+ publicPath: '/',
92
+ }));
64
93
  }
65
94
  if (isEnvDevelopment) {
66
95
  plugins.push(new react_refresh_webpack_plugin_1.default());
@@ -29,7 +29,7 @@ function webpackCompilerHandlerFactory(logger, onCompilationEnd) {
29
29
  if (onCompilationEnd) {
30
30
  await onCompilationEnd();
31
31
  }
32
- const time = (stats === null || stats === void 0 ? void 0 : stats.endTime) - (stats === null || stats === void 0 ? void 0 : stats.startTime);
32
+ const time = stats?.endTime - stats?.startTime;
33
33
  logger.success(`Client was successfully compiled in ${(0, pretty_time_1.prettyTime)(BigInt(time) * BigInt(1000000))}`);
34
34
  };
35
35
  }
@@ -63,9 +63,11 @@ exports.resolveTsconfigPathsToAlias = resolveTsconfigPathsToAlias;
63
63
  function readJsonConfig(pathname) {
64
64
  try {
65
65
  const json = fs_1.default.readFileSync(pathname, 'utf-8');
66
- return Object.assign({}, JSON.parse(json));
66
+ return {
67
+ ...JSON.parse(json),
68
+ };
67
69
  }
68
- catch (_a) {
70
+ catch {
69
71
  throw new Error(`Couldn't read config ${pathname}`);
70
72
  }
71
73
  }
@@ -0,0 +1,3 @@
1
+ "use strict";
2
+ // eslint-disable-next-line camelcase, no-implicit-globals
3
+ __webpack_public_path__ = self.__PUBLIC_PATH__;
@@ -0,0 +1,4 @@
1
+ declare class WebWorker extends Worker {
2
+ constructor(url: string | URL, options?: WorkerOptions);
3
+ }
4
+ export { WebWorker as Worker };
@@ -0,0 +1,23 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Worker = void 0;
4
+ class WebWorker extends Worker {
5
+ constructor(url, options) {
6
+ // eslint-disable-next-line camelcase
7
+ const publicPath = __webpack_public_path__;
8
+ const workerPublicPath = publicPath.match(/^https?:\/\//)
9
+ ? publicPath
10
+ : new URL(publicPath, window.location.href).toString();
11
+ const objectURL = URL.createObjectURL(new Blob([
12
+ [
13
+ `self.__PUBLIC_PATH__ = ${JSON.stringify(workerPublicPath)}`,
14
+ `importScripts(${JSON.stringify(url.toString())});`,
15
+ ].join('\n'),
16
+ ], {
17
+ type: 'application/javascript',
18
+ }));
19
+ super(objectURL, options);
20
+ URL.revokeObjectURL(objectURL);
21
+ }
22
+ }
23
+ exports.Worker = WebWorker;
@@ -0,0 +1,2 @@
1
+ import webpack from 'webpack';
2
+ export declare const pitch: webpack.PitchLoaderDefinitionFunction;
@@ -0,0 +1,123 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.pitch = void 0;
7
+ const node_path_1 = __importDefault(require("node:path"));
8
+ const webpack_1 = __importDefault(require("webpack"));
9
+ const NodeTargetPlugin_1 = __importDefault(require("webpack/lib/node/NodeTargetPlugin"));
10
+ const WebWorkerTemplatePlugin_1 = __importDefault(require("webpack/lib/webworker/WebWorkerTemplatePlugin"));
11
+ const FetchCompileWasmPlugin_1 = __importDefault(require("webpack/lib/web/FetchCompileWasmPlugin"));
12
+ const FetchCompileAsyncWasmPlugin_1 = __importDefault(require("webpack/lib/web/FetchCompileAsyncWasmPlugin"));
13
+ const paths_1 = __importDefault(require("../../paths"));
14
+ const publicPath = node_path_1.default.resolve(__dirname, 'public-path.worker.js');
15
+ const pitch = function (request) {
16
+ this.cacheable(false);
17
+ if (!this._compiler || !this._compilation) {
18
+ throw new Error('Something went wrong');
19
+ }
20
+ const compilerOptions = this._compiler.options;
21
+ const logger = this.getLogger('APP_BUILDER_WORKER_LOADER');
22
+ if (compilerOptions.output.globalObject === 'window') {
23
+ logger.warn('Warning (app-builder-worker-loader): output.globalObject is set to "window". It should be set to "self" or "this" to support HMR in Workers.');
24
+ }
25
+ const isEnvProduction = compilerOptions.mode === 'production';
26
+ const filename = isEnvProduction
27
+ ? 'js/[name].[contenthash:8].worker.js'
28
+ : 'js/[name].worker.js';
29
+ const workerOptions = {
30
+ filename,
31
+ chunkFilename: filename,
32
+ publicPath: compilerOptions.output.publicPath,
33
+ globalObject: 'self',
34
+ devtoolNamespace: node_path_1.default.resolve('/', node_path_1.default.relative(paths_1.default.app, this.resource)),
35
+ };
36
+ const workerCompiler = this._compilation.createChildCompiler(`worker ${request}`, workerOptions);
37
+ new WebWorkerTemplatePlugin_1.default().apply(workerCompiler);
38
+ if (this.target !== 'webworker' && this.target !== 'web') {
39
+ new NodeTargetPlugin_1.default().apply(workerCompiler);
40
+ }
41
+ new FetchCompileWasmPlugin_1.default({
42
+ mangleImports: this._compiler.options.optimization.mangleWasmImports,
43
+ }).apply(workerCompiler);
44
+ new FetchCompileAsyncWasmPlugin_1.default().apply(workerCompiler);
45
+ const bundleName = node_path_1.default.parse(this.resourcePath).name;
46
+ new webpack_1.default.EntryPlugin(this.context, `!!${publicPath}`, bundleName).apply(workerCompiler);
47
+ new webpack_1.default.EntryPlugin(this.context, `!!${request}`, bundleName).apply(workerCompiler);
48
+ configureSourceMap(workerCompiler);
49
+ const cb = this.async();
50
+ workerCompiler.compile((err, compilation) => {
51
+ if (!compilation) {
52
+ return undefined;
53
+ }
54
+ workerCompiler.parentCompilation?.children.push(compilation);
55
+ if (err) {
56
+ return cb(err);
57
+ }
58
+ if (compilation.errors && compilation.errors.length) {
59
+ const errorDetails = compilation.errors
60
+ .map((error) => {
61
+ if (error instanceof Error) {
62
+ return error.stack;
63
+ }
64
+ return error;
65
+ })
66
+ .join('\n');
67
+ return cb(new Error('Child compilation failed:\n' + errorDetails));
68
+ }
69
+ const file = Object.keys(compilation.assets)[0];
70
+ if (file) {
71
+ const contents = compilation.assets[file]?.source();
72
+ const mapFile = `${file}.map`;
73
+ let map = compilation.assets[mapFile]?.source();
74
+ if (map) {
75
+ const sourceMap = JSON.parse(map.toString());
76
+ if (Array.isArray(sourceMap.sources)) {
77
+ sourceMap.sources = sourceMap.sources.map((pathname) => pathname.replace(/webpack:\/\/[^/]+\//, 'webpack://'));
78
+ }
79
+ map = JSON.stringify(sourceMap);
80
+ }
81
+ for (const [fileName, asset] of Object.entries(compilation.assets)) {
82
+ if ([file, mapFile].includes(fileName)) {
83
+ continue;
84
+ }
85
+ workerCompiler.parentCompilation?.emitAsset(fileName, asset, compilation.assetsInfo.get(fileName));
86
+ }
87
+ return cb(null, contents, map?.toString());
88
+ }
89
+ return cb(null, undefined);
90
+ });
91
+ };
92
+ exports.pitch = pitch;
93
+ function configureSourceMap(compiler) {
94
+ const devtool = compiler.options.devtool;
95
+ if (devtool) {
96
+ if (devtool.includes('source-map')) {
97
+ // remove parent SourceMapDevToolPlugin from compilation
98
+ for (const hook of Object.values(compiler.hooks)) {
99
+ for (let i = hook.taps.length - 1; i >= 0; i--) {
100
+ const tap = hook.taps[i];
101
+ if (tap?.name === 'SourceMapDevToolPlugin') {
102
+ hook.taps.splice(i, 1);
103
+ }
104
+ }
105
+ }
106
+ const hidden = devtool.includes('hidden');
107
+ const inline = devtool.includes('inline');
108
+ const cheap = devtool.includes('cheap');
109
+ const moduleMaps = devtool.includes('module');
110
+ new webpack_1.default.SourceMapDevToolPlugin({
111
+ filename: inline ? null : compiler.options.output.sourceMapFilename,
112
+ moduleFilenameTemplate: compiler.options.output.devtoolModuleFilenameTemplate,
113
+ fallbackModuleFilenameTemplate: compiler.options.output.devtoolFallbackModuleFilenameTemplate,
114
+ append: hidden ? false : undefined,
115
+ module: moduleMaps ? true : !cheap,
116
+ columns: !cheap,
117
+ noSources: false,
118
+ namespace: (compiler.parentCompilation?.outputOptions.devtoolNamespace ?? '') +
119
+ compiler.options.output.devtoolNamespace,
120
+ }).apply(compiler);
121
+ }
122
+ }
123
+ }
@@ -2,9 +2,9 @@ export type CliArgs = Awaited<ReturnType<typeof createCli>>;
2
2
  export declare function createCli(argv: string[]): {
3
3
  [x: string]: unknown;
4
4
  verbose: boolean;
5
+ c: unknown;
5
6
  inspect: number | undefined;
6
7
  target: "client" | "server" | undefined;
7
- c: unknown;
8
8
  env: string[] | undefined;
9
9
  inspectBrk: number | undefined;
10
10
  "inspect-brk": number | undefined;
@@ -28,9 +28,9 @@ export declare function createCli(argv: string[]): {
28
28
  } | Promise<{
29
29
  [x: string]: unknown;
30
30
  verbose: boolean;
31
+ c: unknown;
31
32
  inspect: number | undefined;
32
33
  target: "client" | "server" | undefined;
33
- c: unknown;
34
34
  env: string[] | undefined;
35
35
  inspectBrk: number | undefined;
36
36
  "inspect-brk": number | undefined;
@@ -195,7 +195,7 @@ function getCommandHandler(command, handler) {
195
195
  return async (argv) => {
196
196
  logger_1.default.setVerbose(Boolean(argv.verbose));
197
197
  const config = await (0, config_1.getProjectConfig)(command, argv);
198
- const args = Object.assign(Object.assign({}, config), { logger: logger_1.default });
198
+ const args = { ...config, logger: logger_1.default };
199
199
  const localCmd = resolveLocalCommand(command);
200
200
  logger_1.default.verbose(`running command: ${command}`);
201
201
  return handler ? handler(args, localCmd) : localCmd(args);
package/dist/index.d.ts CHANGED
@@ -1,3 +1,5 @@
1
1
  export { configureWebpackConfigForStorybook, configureServiceWebpackConfig, } from './common/webpack/storybook';
2
+ export * from './common/s3-upload';
2
3
  export { createTransformPathsToLocalModules } from './common/typescript/transformers';
3
- export type { ProjectConfig, ServiceConfig, LibraryConfig } from './common/models';
4
+ export { defineConfig } from './common/models';
5
+ export type { ProjectConfig, ServiceConfig, LibraryConfig, ProjectFileConfig } from './common/models';
package/dist/index.js CHANGED
@@ -1,8 +1,25 @@
1
1
  "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
2
16
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.createTransformPathsToLocalModules = exports.configureServiceWebpackConfig = exports.configureWebpackConfigForStorybook = void 0;
17
+ exports.defineConfig = exports.createTransformPathsToLocalModules = exports.configureServiceWebpackConfig = exports.configureWebpackConfigForStorybook = void 0;
4
18
  var storybook_1 = require("./common/webpack/storybook");
5
19
  Object.defineProperty(exports, "configureWebpackConfigForStorybook", { enumerable: true, get: function () { return storybook_1.configureWebpackConfigForStorybook; } });
6
20
  Object.defineProperty(exports, "configureServiceWebpackConfig", { enumerable: true, get: function () { return storybook_1.configureServiceWebpackConfig; } });
21
+ __exportStar(require("./common/s3-upload"), exports);
7
22
  var transformers_1 = require("./common/typescript/transformers");
8
23
  Object.defineProperty(exports, "createTransformPathsToLocalModules", { enumerable: true, get: function () { return transformers_1.createTransformPathsToLocalModules; } });
24
+ var models_1 = require("./common/models");
25
+ Object.defineProperty(exports, "defineConfig", { enumerable: true, get: function () { return models_1.defineConfig; } });