@strapi/typescript-utils 4.2.0-beta.2 → 4.3.0-beta.1

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.
@@ -0,0 +1,37 @@
1
+ 'use strict';
2
+
3
+ const path = require('path');
4
+ const fs = require('fs-extra');
5
+
6
+ module.exports = async dest => {
7
+ const tsConfig = {
8
+ compilerOptions: {
9
+ lib: ['es2019', 'es2020.promise', 'es2020.bigint', 'es2020.string', 'DOM'],
10
+ noImplicitAny: false,
11
+ module: 'es2020',
12
+ target: 'es5',
13
+ jsx: 'react',
14
+ allowJs: true,
15
+ strict: true,
16
+ moduleResolution: 'node',
17
+ skipLibCheck: true,
18
+ esModuleInterop: true,
19
+ allowSyntheticDefaultImports: true,
20
+ resolveJsonModule: true,
21
+ noEmit: false,
22
+ incremental: true,
23
+ },
24
+ include: ['../../../src/admin/*', '../../../src/**/**/admin/src/*'],
25
+ exclude: ['node_modules', '**/*.test.js', '*.js'],
26
+ };
27
+
28
+ const filePath = path.join(dest, 'admin', 'src', 'tsconfig.json');
29
+
30
+ try {
31
+ await fs.ensureFile(filePath);
32
+
33
+ await fs.writeJSON(filePath, tsConfig, { spaces: 2 });
34
+ } catch (err) {
35
+ console.log(err);
36
+ }
37
+ };
@@ -0,0 +1,5 @@
1
+ 'use strict';
2
+
3
+ const createTSConfigFile = require('./create-tsconfig-file');
4
+
5
+ module.exports = { createTSConfigFile };
package/lib/compile.js CHANGED
@@ -3,12 +3,12 @@
3
3
  const compilers = require('./compilers');
4
4
  const getConfigPath = require('./utils/get-config-path');
5
5
 
6
- module.exports = async (srcDir, { watch = false } = {}) => {
6
+ module.exports = async (srcDir, { watch = false, configOptions = {} } = {}) => {
7
7
  // TODO: Use the Strapi debug logger instead or don't log at all
8
8
  console.log(`Starting the compilation for TypeScript files in ${srcDir}`);
9
9
 
10
10
  const compiler = watch ? compilers.watch : compilers.basic;
11
11
  const configPath = getConfigPath(srcDir);
12
12
 
13
- compiler.run(configPath);
13
+ compiler.run(configPath, configOptions);
14
14
  };
@@ -1,6 +1,7 @@
1
1
  'use strict';
2
2
 
3
3
  const ts = require('typescript');
4
+ const { merge } = require('lodash');
4
5
 
5
6
  const reportDiagnostics = require('../utils/report-diagnostics');
6
7
  const resolveConfigOptions = require('../utils/resolve-config-options');
@@ -9,15 +10,18 @@ module.exports = {
9
10
  /**
10
11
  * Default TS -> JS Compilation for Strapi
11
12
  * @param {string} tsConfigPath
13
+ * @param {Object} configOptions
14
+ * @param {Array.<string>} configOptions.fileNames
15
+ * @param {Object} configOptions.options
12
16
  */
13
- run(tsConfigPath) {
17
+ run(tsConfigPath, configOptions = {}) {
14
18
  // Parse the tsconfig.json file & resolve the configuration options
15
19
  const { fileNames, options, projectReferences } = resolveConfigOptions(tsConfigPath);
16
20
 
17
21
  const program = ts.createProgram({
18
- rootNames: fileNames,
22
+ rootNames: configOptions.fileNames ? configOptions.fileNames : fileNames,
19
23
  projectReferences,
20
- options,
24
+ options: merge(options, configOptions.options),
21
25
  });
22
26
 
23
27
  const emitResults = program.emit();
package/lib/index.js CHANGED
@@ -2,11 +2,13 @@
2
2
 
3
3
  const compile = require('./compile');
4
4
  const compilers = require('./compilers');
5
+ const admin = require('./admin');
5
6
  const utils = require('./utils');
6
7
 
7
8
  module.exports = {
8
9
  compile,
9
10
  compilers,
11
+ admin,
10
12
 
11
13
  ...utils,
12
14
  };
@@ -6,6 +6,7 @@ const getConfigPath = require('./get-config-path');
6
6
  const reportDiagnostics = require('./report-diagnostics');
7
7
  const resolveConfigOptions = require('./resolve-config-options');
8
8
  const formatHost = require('./format-host');
9
+ const resolveOutDir = require('./resolve-outdir');
9
10
 
10
11
  module.exports = {
11
12
  isUsingTypeScript,
@@ -14,4 +15,5 @@ module.exports = {
14
15
  reportDiagnostics,
15
16
  resolveConfigOptions,
16
17
  formatHost,
18
+ resolveOutDir,
17
19
  };
@@ -0,0 +1,17 @@
1
+ 'use strict';
2
+ const path = require('path');
3
+ const resolveConfigOptions = require('./resolve-config-options');
4
+ const isUsingTypescript = require('./is-using-typescript');
5
+
6
+ const DEFAULT_TS_CONFIG_FILENAME = 'tsconfig.json';
7
+ /**
8
+ * Gets the outDir value from config file (tsconfig)
9
+ * @param {string} dir
10
+ * @param {string | undefined} configFilename
11
+ * @returns {string | undefined}
12
+ */
13
+ module.exports = async (dir, configFilename = DEFAULT_TS_CONFIG_FILENAME) => {
14
+ return (await isUsingTypescript(dir))
15
+ ? resolveConfigOptions(path.join(dir, configFilename)).options.outDir
16
+ : undefined;
17
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@strapi/typescript-utils",
3
- "version": "4.2.0-beta.2",
3
+ "version": "4.3.0-beta.1",
4
4
  "description": "Typescript support for Strapi",
5
5
  "keywords": [
6
6
  "strapi",
@@ -32,5 +32,5 @@
32
32
  "node": ">=12.22.0 <=16.x.x",
33
33
  "npm": ">=6.0.0"
34
34
  },
35
- "gitHead": "bff73257e7695d6f361c91dda8cc810a2bb70b6e"
35
+ "gitHead": "9d6555398960c39159d66bb4eea3bcb0362e37e3"
36
36
  }
File without changes
@@ -11,6 +11,7 @@
11
11
  "skipLibCheck": true,
12
12
  "forceConsistentCasingInFileNames": true,
13
13
 
14
+ "incremental": true,
14
15
  "esModuleInterop": true,
15
16
  "resolveJsonModule": true,
16
17
  "noEmitOnError": true