@gravity-ui/app-builder 0.8.3 → 0.8.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.
@@ -1,3 +1,4 @@
1
+ /// <reference types="node" />
1
2
  import type { ExecException } from 'child_process';
2
3
  export interface BaseLogger {
3
4
  message: (msg: string) => void;
@@ -1,3 +1,4 @@
1
+ /// <reference types="node" />
1
2
  import type { EditorLanguage } from 'monaco-editor-webpack-plugin/out/languages';
2
3
  import type { EditorFeature } from 'monaco-editor-webpack-plugin/out/features';
3
4
  import type { IFeatureDefinition } from 'monaco-editor-webpack-plugin/out/types';
@@ -1,3 +1,4 @@
1
+ import type { Logger } from '../logger/index.js';
1
2
  import type { S3ClientOptions } from './s3-client.js';
2
3
  export interface UploadOptions {
3
4
  bucket: string;
@@ -10,5 +11,6 @@ export interface UploadFilesOptions {
10
11
  concurrency?: number;
11
12
  compress?: boolean;
12
13
  options: UploadOptions;
14
+ logger?: Logger;
13
15
  }
14
16
  export declare function uploadFiles(files: string[], config: UploadFilesOptions): Promise<string[]>;
@@ -29,10 +29,12 @@ Object.defineProperty(exports, "__esModule", { value: true });
29
29
  exports.uploadFiles = void 0;
30
30
  const path = __importStar(require("node:path"));
31
31
  const p_queue_1 = __importDefault(require("p-queue"));
32
+ const index_js_1 = __importDefault(require("../logger/index.js"));
32
33
  const s3_client_js_1 = require("./s3-client.js");
33
34
  const compress_js_1 = require("./compress.js");
34
35
  function uploadFiles(files, config) {
35
36
  const s3Client = (0, s3_client_js_1.getS3Client)(config.s3);
37
+ const log = config.logger ?? index_js_1.default;
36
38
  const queue = new p_queue_1.default({
37
39
  concurrency: config.concurrency ?? 512,
38
40
  });
@@ -56,32 +58,32 @@ function uploadFiles(files, config) {
56
58
  return async (relativeFilePath) => {
57
59
  const sourceFilePath = path.join(options.sourcePath, relativeFilePath);
58
60
  const targetFilePath = path.join(options.targetPath || '', relativeFilePath);
59
- console.info(`Uploading file ${relativeFilePath} ...`);
61
+ log.verbose(`Uploading file ${relativeFilePath} ...`);
60
62
  const exists = await doesExist(options.bucket, targetFilePath);
61
63
  if (exists) {
62
64
  switch (options.existsBehavior) {
63
65
  case 'overwrite': {
64
- console.info(`File ${targetFilePath} will be overwritten.`);
66
+ log.verbose(`File ${targetFilePath} will be overwritten.`);
65
67
  break;
66
68
  }
67
69
  case 'throw': {
68
70
  throw new Error(`File ${targetFilePath} already exists in ${options.bucket}`);
69
71
  }
70
72
  default: {
71
- console.info(`Nothing todo with '${relativeFilePath}'`);
73
+ log.message(`Nothing to do with '${relativeFilePath}' because '${targetFilePath}' already exists in '${options.bucket}'`);
72
74
  return Promise.resolve(relativeFilePath);
73
75
  }
74
76
  }
75
77
  }
76
78
  return uploadFile(options.bucket, sourceFilePath, targetFilePath)
77
79
  .then(() => {
78
- console.info(` ${relativeFilePath} => ${targetFilePath}`);
80
+ log.message(`Uploaded ${relativeFilePath} => ${targetFilePath}`);
79
81
  return relativeFilePath;
80
82
  })
81
83
  .catch((error) => {
82
- console.error(`Failed to upload file ${relativeFilePath}`);
84
+ log.error(`Failed to upload file ${relativeFilePath}`);
83
85
  if (error instanceof Error) {
84
- console.error(`msg: ${error.message}`);
86
+ log.error(`msg: ${error.message}`);
85
87
  }
86
88
  throw error;
87
89
  });
@@ -1,4 +1,5 @@
1
1
  import type { Compiler } from 'webpack';
2
+ import type { Logger } from '../logger/index.js';
2
3
  import type { UploadOptions } from './upload.js';
3
4
  import type { S3ClientOptions } from './s3-client.js';
4
5
  interface S3UploadPluginOptions {
@@ -8,6 +9,7 @@ interface S3UploadPluginOptions {
8
9
  s3ClientOptions: S3ClientOptions;
9
10
  s3UploadOptions: Pick<UploadOptions, 'bucket' | 'targetPath' | 'existsBehavior'>;
10
11
  additionalPattern?: string | string[];
12
+ logger?: Logger;
11
13
  }
12
14
  export declare class S3UploadPlugin {
13
15
  private options;
@@ -10,16 +10,20 @@ class S3UploadPlugin {
10
10
  this.options = options;
11
11
  }
12
12
  apply(compiler) {
13
- compiler.hooks.done.tapPromise('S3UploadPlugin', async ({ compilation }) => {
14
- let fileNames = Object.keys(compilation.assets);
13
+ compiler.hooks.done.tapPromise('s3-upload-plugin', async (stats) => {
14
+ if (stats.hasErrors()) {
15
+ stats.compilation.warnings.push(new webpack_1.WebpackError('s3-upload-plugin: skipped upload to s3 due to compilation errors'));
16
+ return;
17
+ }
18
+ let fileNames = Object.keys(stats.compilation.assets);
15
19
  if (this.options.additionalPattern) {
16
20
  const additionalFiles = (0, fast_glob_1.globSync)(this.options.additionalPattern, {
17
- cwd: compilation.outputOptions.path,
21
+ cwd: stats.compilation.outputOptions.path,
18
22
  });
19
23
  fileNames = fileNames.concat(additionalFiles);
20
24
  }
21
25
  fileNames = fileNames.filter((name) => {
22
- const fullPath = compilation.outputOptions.path + '/' + name;
26
+ const fullPath = stats.compilation.outputOptions.path + '/' + name;
23
27
  return this.isIncludeAndNotExclude(fullPath);
24
28
  });
25
29
  try {
@@ -28,13 +32,15 @@ class S3UploadPlugin {
28
32
  compress: this.options.compress,
29
33
  options: {
30
34
  ...this.options.s3UploadOptions,
31
- sourcePath: compilation.outputOptions.path ?? '',
35
+ sourcePath: stats.compilation.outputOptions.path ?? '',
32
36
  },
37
+ logger: this.options.logger,
33
38
  });
39
+ this.options.logger?.success(`Files successfully uploaded to bucket ${this.options.s3UploadOptions.bucket}`);
34
40
  }
35
41
  catch (e) {
36
- const error = new webpack_1.WebpackError(`${e instanceof Error ? e.message : e}`);
37
- compilation.errors.push(error);
42
+ const error = new webpack_1.WebpackError(`s3-upload-plugin: ${e instanceof Error ? e.message : e}`);
43
+ stats.compilation.errors.push(error);
38
44
  }
39
45
  });
40
46
  }
@@ -32,10 +32,10 @@ function compile(ts, { projectPath, configFileName = 'tsconfig.json', optionsToE
32
32
  logger.verbose("We're about to create the program");
33
33
  const compilerHost = ts.createCompilerHost(parsedConfig.options);
34
34
  compilerHost.readFile = (0, utils_1.displayFilename)(compilerHost.readFile, 'Reading', logger);
35
- // @ts-ignore
35
+ // @ts-expect-error
36
36
  compilerHost.readFile.enableDisplay();
37
37
  const program = ts.createProgram(parsedConfig.fileNames, parsedConfig.options, compilerHost);
38
- // @ts-ignore
38
+ // @ts-expect-error
39
39
  const filesCount = compilerHost.readFile.disableDisplay();
40
40
  const allDiagnostics = ts.getPreEmitDiagnostics(program).slice();
41
41
  logger.verbose(`Program created, read ${filesCount} files`);
@@ -122,7 +122,7 @@ function updateImportDeclaration(ts, node, context, resolvedPath) {
122
122
  // @ts-expect-error
123
123
  node.assertClause);
124
124
  }
125
- return context.factory.updateImportDeclaration(node, node.modifiers, node.importClause, context.factory.createStringLiteral(resolvedPath), node.assertClause);
125
+ return context.factory.updateImportDeclaration(node, node.modifiers, node.importClause, context.factory.createStringLiteral(resolvedPath), node.attributes || node.assertClause);
126
126
  }
127
127
  function updateExportDeclaration(ts, node, context, resolvedPath) {
128
128
  if (semver.lt(ts.version, '5.0.0')) {
@@ -133,7 +133,7 @@ function updateExportDeclaration(ts, node, context, resolvedPath) {
133
133
  // @ts-expect-error
134
134
  node.assertClause);
135
135
  }
136
- return context.factory.updateExportDeclaration(node, node.modifiers, node.isTypeOnly, node.exportClause, context.factory.createStringLiteral(resolvedPath), node.assertClause);
136
+ return context.factory.updateExportDeclaration(node, node.modifiers, node.isTypeOnly, node.exportClause, context.factory.createStringLiteral(resolvedPath), node.attributes || node.assertClause);
137
137
  }
138
138
  function updateImportTypeNode(ts, node, context, resolvedPath) {
139
139
  if (semver.lt(ts.version, '5.0.0')) {
@@ -142,5 +142,5 @@ function updateImportTypeNode(ts, node, context, resolvedPath) {
142
142
  // @ts-expect-error
143
143
  node.qualifier, node.typeArguments, node.isTypeOf);
144
144
  }
145
- return context.factory.updateImportTypeNode(node, context.factory.createLiteralTypeNode(context.factory.createStringLiteral(resolvedPath)), node.assertions, node.qualifier, node.typeArguments, node.isTypeOf);
145
+ return context.factory.updateImportTypeNode(node, context.factory.createLiteralTypeNode(context.factory.createStringLiteral(resolvedPath)), node.attributes || node.assertions, node.qualifier, node.typeArguments, node.isTypeOf);
146
146
  }
@@ -23,10 +23,10 @@ function watch(ts, projectPath, { logger, onAfterFilesEmitted, enableSourceMap,
23
23
  host.readFile = (0, utils_1.displayFilename)(host.readFile, 'Reading', logger);
24
24
  (0, utils_1.onHostEvent)(host, 'createProgram', () => {
25
25
  logger.verbose("We're about to create the program");
26
- // @ts-ignore
26
+ // @ts-expect-error
27
27
  host.readFile.enableDisplay();
28
28
  }, () => {
29
- // @ts-ignore
29
+ // @ts-expect-error
30
30
  const count = host.readFile.disableDisplay();
31
31
  logger.verbose(`Program created, read ${count} files`);
32
32
  });
@@ -111,7 +111,7 @@ function configureModuleRules(helperOptions) {
111
111
  createJavaScriptRule(helperOptions, jsLoader),
112
112
  createStylesRule(helperOptions),
113
113
  createSassStylesRule(helperOptions),
114
- createIconsRule(helperOptions),
114
+ createIconsRule(helperOptions), // workaround for https://github.com/webpack/webpack/issues/9309
115
115
  createIconsRule(helperOptions, jsLoader),
116
116
  ...createAssetsRules(helperOptions),
117
117
  ...createFallbackRules(helperOptions),
@@ -357,7 +357,7 @@ function createSassStylesRule(options) {
357
357
  loaders.push({
358
358
  loader: require.resolve('sass-loader'),
359
359
  options: {
360
- sourceMap: true,
360
+ sourceMap: true, // must be always true for work with resolve-url-loader
361
361
  sassOptions: {
362
362
  includePaths: [paths_1.default.appClient],
363
363
  },
@@ -711,6 +711,7 @@ function configurePlugins(options) {
711
711
  targetPath: cdn.prefix,
712
712
  },
713
713
  additionalPattern: cdn.additionalPattern,
714
+ logger: options.logger,
714
715
  }));
715
716
  }
716
717
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gravity-ui/app-builder",
3
- "version": "0.8.3",
3
+ "version": "0.8.4",
4
4
  "description": "Develop and build your React client-server projects, powered by typescript and webpack",
5
5
  "license": "MIT",
6
6
  "type": "commonjs",
@@ -125,7 +125,7 @@
125
125
  "terser-webpack-plugin": "5.3.9",
126
126
  "ts-node": "10.9.1",
127
127
  "tslib": "^2.6.2",
128
- "typescript": "^5.2.2",
128
+ "typescript": "^5.3.3",
129
129
  "webpack": "^5.88.2",
130
130
  "webpack-assets-manifest": "^5.1.0",
131
131
  "webpack-bundle-analyzer": "^4.9.1",