@strapi/typescript-utils 4.2.0-beta.0 → 4.2.0-beta.3
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 +2 -5
- package/lib/compilers/basic.js +7 -3
- package/lib/configs/admin.json +20 -0
- package/lib/configs/server.json +19 -0
- package/lib/utils/get-config-path.js +2 -2
- package/lib/utils/index.js +6 -6
- package/lib/utils/{is-typescript-project-sync.js → is-using-typescript-sync.js} +1 -1
- package/lib/utils/{is-typescript-project.js → is-using-typescript.js} +1 -1
- package/lib/utils/resolve-outdir.js +17 -0
- package/package.json +2 -2
- package/lib/utils/copy-resources.js +0 -12
package/lib/compile.js
CHANGED
|
@@ -2,16 +2,13 @@
|
|
|
2
2
|
|
|
3
3
|
const compilers = require('./compilers');
|
|
4
4
|
const getConfigPath = require('./utils/get-config-path');
|
|
5
|
-
const copyResources = require('./utils/copy-resources');
|
|
6
5
|
|
|
7
|
-
module.exports = async (srcDir, { watch = false } = {}) => {
|
|
6
|
+
module.exports = async (srcDir, { watch = false, configOptions = {} } = {}) => {
|
|
8
7
|
// TODO: Use the Strapi debug logger instead or don't log at all
|
|
9
8
|
console.log(`Starting the compilation for TypeScript files in ${srcDir}`);
|
|
10
9
|
|
|
11
10
|
const compiler = watch ? compilers.watch : compilers.basic;
|
|
12
11
|
const configPath = getConfigPath(srcDir);
|
|
13
12
|
|
|
14
|
-
compiler.run(configPath);
|
|
15
|
-
|
|
16
|
-
await copyResources(srcDir);
|
|
13
|
+
compiler.run(configPath, configOptions);
|
|
17
14
|
};
|
package/lib/compilers/basic.js
CHANGED
|
@@ -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();
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
{
|
|
2
|
+
"$schema": "https://json.schemastore.org/tsconfig",
|
|
3
|
+
|
|
4
|
+
"compilerOptions": {
|
|
5
|
+
"module": "ES2020",
|
|
6
|
+
"moduleResolution": "node",
|
|
7
|
+
"lib": ["ES2020", "DOM"],
|
|
8
|
+
"target": "ES5",
|
|
9
|
+
|
|
10
|
+
"jsx": "react",
|
|
11
|
+
"sourceMap": true,
|
|
12
|
+
"incremental": true,
|
|
13
|
+
|
|
14
|
+
"allowJs": true,
|
|
15
|
+
"allowSyntheticDefaultImports": true,
|
|
16
|
+
"resolveJsonModule": true,
|
|
17
|
+
"noEmit": true,
|
|
18
|
+
"skipLibCheck": true
|
|
19
|
+
}
|
|
20
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
{
|
|
2
|
+
"$schema": "https://json.schemastore.org/tsconfig",
|
|
3
|
+
|
|
4
|
+
"compilerOptions": {
|
|
5
|
+
"module": "CommonJS",
|
|
6
|
+
"moduleResolution": "Node",
|
|
7
|
+
"lib": ["ES2020"],
|
|
8
|
+
"target": "ES2019",
|
|
9
|
+
|
|
10
|
+
"strict": false,
|
|
11
|
+
"skipLibCheck": true,
|
|
12
|
+
"forceConsistentCasingInFileNames": true,
|
|
13
|
+
|
|
14
|
+
"incremental": true,
|
|
15
|
+
"esModuleInterop": true,
|
|
16
|
+
"resolveJsonModule": true,
|
|
17
|
+
"noEmitOnError": true
|
|
18
|
+
}
|
|
19
|
+
}
|
|
@@ -2,8 +2,8 @@
|
|
|
2
2
|
|
|
3
3
|
const ts = require('typescript');
|
|
4
4
|
|
|
5
|
-
const
|
|
5
|
+
const DEFAULT_TS_CONFIG_FILENAME = 'tsconfig.json';
|
|
6
6
|
|
|
7
|
-
module.exports = (dir, filename =
|
|
7
|
+
module.exports = (dir, filename = DEFAULT_TS_CONFIG_FILENAME) => {
|
|
8
8
|
return ts.findConfigFile(dir, ts.sys.fileExists, filename);
|
|
9
9
|
};
|
package/lib/utils/index.js
CHANGED
|
@@ -1,19 +1,19 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
const
|
|
4
|
-
const
|
|
3
|
+
const isUsingTypeScript = require('./is-using-typescript');
|
|
4
|
+
const isUsingTypeScriptSync = require('./is-using-typescript-sync');
|
|
5
5
|
const getConfigPath = require('./get-config-path');
|
|
6
6
|
const reportDiagnostics = require('./report-diagnostics');
|
|
7
7
|
const resolveConfigOptions = require('./resolve-config-options');
|
|
8
|
-
const copyResources = require('./copy-resources');
|
|
9
8
|
const formatHost = require('./format-host');
|
|
9
|
+
const resolveOutDir = require('./resolve-outdir');
|
|
10
10
|
|
|
11
11
|
module.exports = {
|
|
12
|
-
|
|
13
|
-
|
|
12
|
+
isUsingTypeScript,
|
|
13
|
+
isUsingTypeScriptSync,
|
|
14
14
|
getConfigPath,
|
|
15
15
|
reportDiagnostics,
|
|
16
16
|
resolveConfigOptions,
|
|
17
|
-
copyResources,
|
|
18
17
|
formatHost,
|
|
18
|
+
resolveOutDir,
|
|
19
19
|
};
|
|
@@ -5,7 +5,7 @@ const fse = require('fs-extra');
|
|
|
5
5
|
const getConfigPath = require('./get-config-path');
|
|
6
6
|
|
|
7
7
|
/**
|
|
8
|
-
* Checks if `dir` is a TypeScript
|
|
8
|
+
* Checks if `dir` is a using TypeScript (whether there is a tsconfig file or not)
|
|
9
9
|
* @param {string} dir
|
|
10
10
|
* @param {string | undefined} filename
|
|
11
11
|
* @returns {boolean}
|
|
@@ -5,7 +5,7 @@ const fse = require('fs-extra');
|
|
|
5
5
|
const getConfigPath = require('./get-config-path');
|
|
6
6
|
|
|
7
7
|
/**
|
|
8
|
-
* Checks if `dir` is a TypeScript
|
|
8
|
+
* Checks if `dir` is a using TypeScript (whether there is a tsconfig file or not)
|
|
9
9
|
* @param {string} dir
|
|
10
10
|
* @param {string | undefined} filename
|
|
11
11
|
* @returns {Promise<boolean>}
|
|
@@ -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.
|
|
3
|
+
"version": "4.2.0-beta.3",
|
|
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": "
|
|
35
|
+
"gitHead": "c4addbad6ecbc8ef7633bbba3806f3b0a2ae5f49"
|
|
36
36
|
}
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
const path = require('path');
|
|
4
|
-
const fse = require('fs-extra');
|
|
5
|
-
|
|
6
|
-
const DEFAULT_RESOURCES_PATHS = ['public', 'favicon.ico', 'package.json'];
|
|
7
|
-
|
|
8
|
-
module.exports = async (dir, resources = DEFAULT_RESOURCES_PATHS) => {
|
|
9
|
-
await Promise.all(
|
|
10
|
-
resources.map(resourceName => fse.copy(resourceName, path.join(dir, 'dist', resourceName)))
|
|
11
|
-
);
|
|
12
|
-
};
|