@gravity-ui/app-builder 0.6.2 → 0.6.4

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.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,22 @@
1
1
  # Changelog
2
2
 
3
+ ## [0.6.4](https://github.com/gravity-ui/app-builder/compare/v0.6.3...v0.6.4) (2023-08-04)
4
+
5
+
6
+ ### Bug Fixes
7
+
8
+ * **build-library:** correctly write esm code to file ([#62](https://github.com/gravity-ui/app-builder/issues/62)) ([b1f1be2](https://github.com/gravity-ui/app-builder/commit/b1f1be2dfd93d79b54ee8c99e99cea945c0b6f16)), closes [#61](https://github.com/gravity-ui/app-builder/issues/61)
9
+
10
+ ## [0.6.3](https://github.com/gravity-ui/app-builder/compare/v0.6.2...v0.6.3) (2023-07-31)
11
+
12
+
13
+ ### Bug Fixes
14
+
15
+ * **build-lib:** replace style and svg paths with babel plugin ([#60](https://github.com/gravity-ui/app-builder/issues/60)) ([3b7760e](https://github.com/gravity-ui/app-builder/commit/3b7760e0af7350e60c9d3c7a704e510958d46050))
16
+ * **build:** always dedupe css modules ([#55](https://github.com/gravity-ui/app-builder/issues/55)) ([6ea483e](https://github.com/gravity-ui/app-builder/commit/6ea483eb335eb24f80f9dddc33943f0a12336281))
17
+ * **css:** disable sass loaders for pure css ([#56](https://github.com/gravity-ui/app-builder/issues/56)) ([1c23832](https://github.com/gravity-ui/app-builder/commit/1c2383299f1f4cbbc826acdd2b6231c15ab26956))
18
+ * **webworker:** correctly handle licenses and do not emit assets twice ([#58](https://github.com/gravity-ui/app-builder/issues/58)) ([e514bc6](https://github.com/gravity-ui/app-builder/commit/e514bc68ac9bed6cbbfaeddbaa95d8ea8f459acc))
19
+
3
20
  ## [0.6.2](https://github.com/gravity-ui/app-builder/compare/v0.6.1...v0.6.2) (2023-07-24)
4
21
 
5
22
 
@@ -0,0 +1,6 @@
1
+ declare const _default: (api: object, options: Record<string, any> | null | undefined, dirname: string) => {
2
+ visitor: {
3
+ ImportDeclaration(this: import("@babel/core").PluginPass, path: import("@babel/traverse").NodePath<import("@babel/types").ImportDeclaration>): void;
4
+ };
5
+ };
6
+ export default _default;
@@ -0,0 +1,15 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const helper_plugin_utils_1 = require("@babel/helper-plugin-utils");
4
+ exports.default = (0, helper_plugin_utils_1.declare)(function () {
5
+ return {
6
+ visitor: {
7
+ ImportDeclaration(path) {
8
+ const source = path.node.source.value;
9
+ if (source.endsWith('.css')) {
10
+ path.remove();
11
+ }
12
+ },
13
+ },
14
+ };
15
+ });
@@ -0,0 +1,8 @@
1
+ declare const _default: (api: object, options: Record<string, any> | null | undefined, dirname: string) => {
2
+ visitor: {
3
+ ImportDeclaration(this: import("@babel/core").PluginPass, path: import("@babel/traverse").NodePath<import("@babel/types").ImportDeclaration>): void;
4
+ ExportNamedDeclaration(this: import("@babel/core").PluginPass, path: import("@babel/traverse").NodePath<import("@babel/types").ExportNamedDeclaration>): void;
5
+ CallExpression(this: import("@babel/core").PluginPass, path: import("@babel/traverse").NodePath<import("@babel/types").CallExpression>): void;
6
+ };
7
+ };
8
+ export default _default;
@@ -0,0 +1,44 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const helper_plugin_utils_1 = require("@babel/helper-plugin-utils");
4
+ const svgPathRe = /^\.\.\/(.*)\/assets\/(.*)\.svg$/;
5
+ exports.default = (0, helper_plugin_utils_1.declare)(function (api) {
6
+ return {
7
+ visitor: {
8
+ ImportDeclaration(path) {
9
+ const source = path.node.source.value;
10
+ if (source.startsWith('.') && source.endsWith('.scss')) {
11
+ path.node.source.value = source.slice(0, -4) + 'css';
12
+ }
13
+ else {
14
+ const match = source.match(svgPathRe);
15
+ if (match) {
16
+ path.node.source.value = `${match[1]}/assets/${match[2]}`;
17
+ }
18
+ }
19
+ },
20
+ ExportNamedDeclaration(path) {
21
+ const sourceNode = path.node.source;
22
+ const specifier = path.node.specifiers[0];
23
+ if (api.types.isStringLiteral(sourceNode) &&
24
+ api.types.isExportSpecifier(specifier) &&
25
+ specifier.local.name === 'default') {
26
+ const match = sourceNode.value.match(svgPathRe);
27
+ if (match) {
28
+ sourceNode.value = `${match[1]}/assets/${match[2]}`;
29
+ }
30
+ }
31
+ },
32
+ CallExpression(path) {
33
+ const firstArgument = path.node.arguments[0];
34
+ if (path.node.callee.type === 'Import' &&
35
+ api.types.isStringLiteral(firstArgument)) {
36
+ const match = firstArgument.value.match(svgPathRe);
37
+ if (match) {
38
+ firstArgument.value = `${match[1]}/assets/${match[2]}`;
39
+ }
40
+ }
41
+ },
42
+ },
43
+ };
44
+ });
@@ -72,13 +72,13 @@ function compileToCjs(code, file, inputSourceMap, sourceDir = paths_1.default.sr
72
72
  const compiledCjsDir = path_1.default.dirname(compiledCjsFile);
73
73
  const sourcemapCjsFile = getFilePath(file, { dir: compiledDir, ext: 'js.map' });
74
74
  const sourcemapCjsUrl = `// #sourceMappingURL=${path_1.default.basename(sourcemapCjsFile)}`;
75
- const finalCode = code.replace(/import '(.*)\.css';/g, '');
76
75
  fs_1.default.mkdirSync(compiledCjsDir, { recursive: true });
77
- babel.transform(finalCode, {
76
+ babel.transform(code, {
78
77
  filename: sourceFile,
79
78
  plugins: [
80
- '@babel/plugin-transform-modules-commonjs',
81
- '@babel/plugin-proposal-dynamic-import',
79
+ require.resolve('./babel-plugin-remove-css-imports'),
80
+ require.resolve('@babel/plugin-transform-modules-commonjs'),
81
+ require.resolve('@babel/plugin-proposal-dynamic-import'),
82
82
  ],
83
83
  sourceMaps: true,
84
84
  inputSourceMap,
@@ -193,6 +193,7 @@ function buildLibrary(config) {
193
193
  },
194
194
  ],
195
195
  require.resolve('babel-plugin-lodash'),
196
+ require.resolve('./babel-plugin-replace-paths'),
196
197
  ],
197
198
  sourceMaps: true,
198
199
  }, (err, transformed) => {
@@ -202,13 +203,9 @@ function buildLibrary(config) {
202
203
  throw err;
203
204
  }
204
205
  else if (transformed) {
205
- let code = transformed.code
206
- ?.replace(/import '\.(.*)\.scss';/g, "import '.$1.css';")
207
- ?.replace(/import (\w*) from '\.\.\/(.*)\/assets\/(.*)\.svg';/g, "import $1 from '$2/assets/$3';")
208
- ?.replace(/export { *default as (\w*) *} from '\.\.\/(.*)\/assets\/(.*)\.svg';/g, "export { default as $1 } from '$2/assets/$3';")
209
- ?.replace(/import\('\.\.\/(.*)\/assets\/(.*)\.svg'\)/g, "import('$1/assets/$2')") ?? '';
210
- code += (code.length ? '\n' : '') + sourcemapUrl;
211
- fs_1.default.writeFile(compiledFile, code, errorHandlerFactory(`Source compilation has failed on writing ${compiledFile}`));
206
+ const code = transformed.code ?? '';
207
+ const esmCode = code + (code.length ? '\n' : '') + sourcemapUrl;
208
+ fs_1.default.writeFile(compiledFile, esmCode, errorHandlerFactory(`Source compilation has failed on writing ${compiledFile}`));
212
209
  if (transformed.map) {
213
210
  fs_1.default.writeFile(sourcemapFile, JSON.stringify(transformed.map), errorHandlerFactory(`Source compilation has failed on writing ${sourcemapFile}`));
214
211
  }
@@ -141,8 +141,8 @@ export interface ClientConfig {
141
141
  */
142
142
  newJsxTransform?: boolean;
143
143
  /**
144
- * @deprecated
145
- * */
144
+ * @deprecated use `forkTsChecker: false` instead
145
+ */
146
146
  disableForkTsChecker?: boolean;
147
147
  forkTsChecker?: false | ForkTsCheckerWebpackPluginOptions;
148
148
  disableSourceMapGeneration?: boolean;
@@ -102,6 +102,7 @@ function configureModuleRules(helperOptions) {
102
102
  createWorkerRule(helperOptions),
103
103
  createJavaScriptRule(helperOptions, jsLoader),
104
104
  createStylesRule(helperOptions),
105
+ createSassStylesRule(helperOptions),
105
106
  createIconsRule(helperOptions),
106
107
  createIconsRule(helperOptions, jsLoader),
107
108
  ...createAssetsRules(helperOptions),
@@ -328,7 +329,46 @@ function createWorkerRule(options) {
328
329
  ],
329
330
  };
330
331
  }
332
+ function createSassStylesRule({ isEnvDevelopment, isEnvProduction, config, }) {
333
+ const loaders = getCssLoaders({
334
+ isEnvDevelopment,
335
+ isEnvProduction,
336
+ config,
337
+ });
338
+ loaders.push({
339
+ loader: require.resolve('resolve-url-loader'),
340
+ options: {
341
+ sourceMap: !config.disableSourceMapGeneration,
342
+ },
343
+ });
344
+ loaders.push({
345
+ loader: require.resolve('sass-loader'),
346
+ options: {
347
+ sourceMap: true,
348
+ sassOptions: {
349
+ includePaths: [paths_1.default.appClient],
350
+ },
351
+ },
352
+ });
353
+ return {
354
+ test: /\.scss$/,
355
+ sideEffects: isEnvProduction ? true : undefined,
356
+ use: loaders,
357
+ };
358
+ }
331
359
  function createStylesRule({ isEnvDevelopment, isEnvProduction, config, }) {
360
+ const loaders = getCssLoaders({
361
+ isEnvDevelopment,
362
+ isEnvProduction,
363
+ config,
364
+ });
365
+ return {
366
+ test: /\.css$/,
367
+ sideEffects: isEnvProduction ? true : undefined,
368
+ use: loaders,
369
+ };
370
+ }
371
+ function getCssLoaders({ isEnvDevelopment, isEnvProduction, config }) {
332
372
  const loaders = [];
333
373
  if (isEnvProduction) {
334
374
  loaders.push(mini_css_extract_plugin_1.default.loader);
@@ -360,26 +400,7 @@ function createStylesRule({ isEnvDevelopment, isEnvProduction, config, }) {
360
400
  },
361
401
  });
362
402
  }
363
- loaders.push({
364
- loader: require.resolve('resolve-url-loader'),
365
- options: {
366
- sourceMap: !config.disableSourceMapGeneration,
367
- },
368
- });
369
- loaders.push({
370
- loader: require.resolve('sass-loader'),
371
- options: {
372
- sourceMap: true,
373
- sassOptions: {
374
- includePaths: [paths_1.default.appClient],
375
- },
376
- },
377
- });
378
- return {
379
- test: /\.s?css$/,
380
- sideEffects: isEnvProduction ? true : undefined,
381
- use: loaders,
382
- };
403
+ return loaders;
383
404
  }
384
405
  function createIconsRule({ isEnvProduction, config }, jsLoader) {
385
406
  const iconIncludes = config.icons || [];
@@ -709,6 +730,12 @@ function configureOptimization({ config }) {
709
730
  test: new RegExp(`([\\\\/])node_modules\\1(${vendorsList.join('|')})\\1`),
710
731
  priority: Infinity,
711
732
  },
733
+ css: {
734
+ test: /\.css$/,
735
+ enforce: true,
736
+ minChunks: 2,
737
+ reuseExistingChunk: true,
738
+ },
712
739
  },
713
740
  },
714
741
  runtimeChunk: 'single',
@@ -78,7 +78,7 @@ const pitch = function (request) {
78
78
  if (cacheContent) {
79
79
  return cb(null, cacheContent.content, cacheContent.map);
80
80
  }
81
- const content = compilation.assets[filename]?.source();
81
+ let content = compilation.assets[filename]?.source().toString();
82
82
  const mapFile = `${filename}.map`;
83
83
  let map = compilation.assets[mapFile]?.source();
84
84
  if (map) {
@@ -88,11 +88,24 @@ const pitch = function (request) {
88
88
  }
89
89
  map = JSON.stringify(sourceMap);
90
90
  }
91
- for (const [assetName, asset] of Object.entries(compilation.assets)) {
92
- if ([filename, mapFile].includes(assetName)) {
93
- continue;
91
+ const licenseFile = `${filename}.LICENSE.txt`;
92
+ const license = compilation.assets[licenseFile]?.source().toString();
93
+ if (license && content) {
94
+ if (content.startsWith('/*')) {
95
+ content = content.replace(/^\/\*.*?\*\//, license);
96
+ }
97
+ }
98
+ const parentCompilation = workerCompiler.parentCompilation;
99
+ if (parentCompilation) {
100
+ for (const [assetName, asset] of Object.entries(compilation.assets)) {
101
+ if ([filename, mapFile, licenseFile].includes(assetName)) {
102
+ continue;
103
+ }
104
+ if (parentCompilation.assetsInfo.has(assetName)) {
105
+ continue;
106
+ }
107
+ parentCompilation.emitAsset(assetName, asset, compilation.assetsInfo.get(assetName));
94
108
  }
95
- workerCompiler.parentCompilation?.emitAsset(assetName, asset, compilation.assetsInfo.get(assetName));
96
109
  }
97
110
  return cache.store(cacheIdent, cacheETag, { content, map: map?.toString() }, (storeCacheError) => {
98
111
  if (storeCacheError) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gravity-ui/app-builder",
3
- "version": "0.6.2",
3
+ "version": "0.6.4",
4
4
  "description": "Develop and build your React client-server projects, powered by typescript and webpack",
5
5
  "license": "MIT",
6
6
  "main": "dist/index.js",
@@ -58,6 +58,7 @@
58
58
  "dependencies": {
59
59
  "@aws-sdk/client-s3": "^3.353.0",
60
60
  "@babel/core": "^7.21.4",
61
+ "@babel/helper-plugin-utils": "^7.22.5",
61
62
  "@babel/plugin-proposal-decorators": "^7.21.0",
62
63
  "@babel/plugin-proposal-dynamic-import": "^7.18.6",
63
64
  "@babel/plugin-transform-modules-commonjs": "^7.21.2",
@@ -136,6 +137,7 @@
136
137
  "@gravity-ui/eslint-config": "^1.0.2",
137
138
  "@gravity-ui/prettier-config": "^1.0.1",
138
139
  "@gravity-ui/tsconfig": "^1.0.0",
140
+ "@types/babel__helper-plugin-utils": "^7.10.0",
139
141
  "@types/circular-dependency-plugin": "^5.0.5",
140
142
  "@types/common-tags": "^1.8.1",
141
143
  "@types/find-cache-dir": "^3.2.1",
@@ -153,6 +155,7 @@
153
155
  "@types/webpack-bundle-analyzer": "^4.6.0",
154
156
  "@types/webpack-manifest-plugin": "^3.0.5",
155
157
  "@types/yargs": "17.0.11",
158
+ "babel-plugin-tester": "^11.0.4",
156
159
  "eslint": "^8.42.0",
157
160
  "husky": "^8.0.3",
158
161
  "jest": "^29.5.0",