@strapi/typescript-utils 4.13.5 → 4.13.7

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/lib/compile.js CHANGED
@@ -3,12 +3,8 @@
3
3
  const compilers = require('./compilers');
4
4
  const getConfigPath = require('./utils/get-config-path');
5
5
 
6
- module.exports = async (srcDir, { watch = false, configOptions = {} } = {}) => {
7
- // TODO: Use the Strapi debug logger instead or don't log at all
8
- console.log(`Starting the compilation for TypeScript files in ${srcDir}`);
9
-
10
- const compiler = watch ? compilers.watch : compilers.basic;
6
+ module.exports = async (srcDir, { configOptions = {} } = {}) => {
11
7
  const configPath = getConfigPath(srcDir);
12
8
 
13
- compiler.run(configPath, configOptions);
9
+ compilers.basic.run(configPath, configOptions);
14
10
  };
@@ -13,15 +13,23 @@ module.exports = {
13
13
  * @param {Object} configOptions
14
14
  * @param {Array.<string>} configOptions.fileNames
15
15
  * @param {Object} configOptions.options
16
+ * @param {boolean} configOptions.ignoreDiagnostics
16
17
  */
17
18
  run(tsConfigPath, configOptions = {}) {
19
+ const { ignoreDiagnostics = false } = configOptions;
18
20
  // Parse the tsconfig.json file & resolve the configuration options
19
21
  const { fileNames, options, projectReferences } = resolveConfigOptions(tsConfigPath);
20
22
 
23
+ const compilerOptions = merge(options, configOptions.options);
24
+
25
+ if (ignoreDiagnostics) {
26
+ Object.assign(compilerOptions, { noEmit: false, noEmitOnError: false });
27
+ }
28
+
21
29
  const program = ts.createProgram({
22
30
  rootNames: configOptions.fileNames ? configOptions.fileNames : fileNames,
23
31
  projectReferences,
24
- options: merge(options, configOptions.options),
32
+ options: compilerOptions,
25
33
  });
26
34
 
27
35
  const emitResults = program.emit();
@@ -30,12 +38,12 @@ module.exports = {
30
38
  ts.getPreEmitDiagnostics(program).concat(emitResults.diagnostics)
31
39
  );
32
40
 
33
- if (diagnostics.length > 0) {
41
+ if (!ignoreDiagnostics && diagnostics.length > 0) {
34
42
  reportDiagnostics(diagnostics);
35
43
  }
36
44
 
37
- // If the compilation failed, exit early
38
- if (emitResults.emitSkipped) {
45
+ // If the compilation failed and diagnostics are not ignored, exit early
46
+ if (!ignoreDiagnostics && emitResults.emitSkipped) {
39
47
  process.exit(1);
40
48
  }
41
49
  },
@@ -1,9 +1,7 @@
1
1
  'use strict';
2
2
 
3
3
  const basic = require('./basic');
4
- const watch = require('./watch');
5
4
 
6
5
  module.exports = {
7
6
  basic,
8
- watch,
9
7
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@strapi/typescript-utils",
3
- "version": "4.13.5",
3
+ "version": "4.13.7",
4
4
  "description": "Typescript support for Strapi",
5
5
  "repository": {
6
6
  "type": "git",
@@ -40,11 +40,11 @@
40
40
  "fs-extra": "10.0.0",
41
41
  "lodash": "4.17.21",
42
42
  "prettier": "2.8.4",
43
- "typescript": "5.1.3"
43
+ "typescript": "5.2.2"
44
44
  },
45
45
  "engines": {
46
46
  "node": ">=16.0.0 <=20.x.x",
47
47
  "npm": ">=6.0.0"
48
48
  },
49
- "gitHead": "955393fc3ebbe01ceed26eff60c17b4184950300"
49
+ "gitHead": "c11abe88239142c58d6fa4aebea8c30637237424"
50
50
  }
@@ -1,37 +0,0 @@
1
- 'use strict';
2
-
3
- const ts = require('typescript');
4
-
5
- const reportDiagnostics = require('../utils/report-diagnostics');
6
- const formatHost = require('../utils/format-host');
7
- const resolveConfigOptions = require('../utils/resolve-config-options');
8
-
9
- /**
10
- * Prints a diagnostic every time the watch status changes.
11
- * This is mainly for messages like "Starting compilation" or "Compilation completed".
12
- */
13
- const reportWatchStatusChanged = (diagnostic) => {
14
- console.info(ts.formatDiagnostic(diagnostic, formatHost));
15
- };
16
-
17
- module.exports = {
18
- run(configPath) {
19
- const createProgram = ts.createSemanticDiagnosticsBuilderProgram;
20
-
21
- const { fileNames, options, projectReferences, watchOptions } =
22
- resolveConfigOptions(configPath);
23
-
24
- const host = ts.createWatchCompilerHost(
25
- fileNames,
26
- options,
27
- ts.sys,
28
- createProgram,
29
- reportDiagnostics,
30
- reportWatchStatusChanged,
31
- projectReferences,
32
- watchOptions
33
- );
34
-
35
- ts.createWatchProgram(host);
36
- },
37
- };