@strapi/typescript-utils 4.14.0-beta.0 → 4.15.0-alpha.0
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, {
|
|
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
|
-
|
|
9
|
+
compilers.basic.run(configPath, configOptions);
|
|
14
10
|
};
|
package/lib/compilers/basic.js
CHANGED
|
@@ -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:
|
|
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
|
},
|
package/lib/compilers/index.js
CHANGED
package/lib/generators/utils.js
CHANGED
|
@@ -92,7 +92,7 @@ const generateSharedExtensionDefinition = (registry, definitions) => {
|
|
|
92
92
|
|
|
93
93
|
return factory.createModuleDeclaration(
|
|
94
94
|
[factory.createModifier(ts.SyntaxKind.DeclareKeyword)],
|
|
95
|
-
factory.createStringLiteral('@strapi/
|
|
95
|
+
factory.createStringLiteral('@strapi/types', true),
|
|
96
96
|
factory.createModuleBlock([
|
|
97
97
|
factory.createModuleDeclaration(
|
|
98
98
|
[factory.createModifier(ts.SyntaxKind.ExportKeyword)],
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@strapi/typescript-utils",
|
|
3
|
-
"version": "4.
|
|
3
|
+
"version": "4.15.0-alpha.0",
|
|
4
4
|
"description": "Typescript support for Strapi",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -46,5 +46,5 @@
|
|
|
46
46
|
"node": ">=16.0.0 <=20.x.x",
|
|
47
47
|
"npm": ">=6.0.0"
|
|
48
48
|
},
|
|
49
|
-
"gitHead": "
|
|
49
|
+
"gitHead": "682a070df9ef90f2aa6966666488e066d61831e2"
|
|
50
50
|
}
|
package/tsconfigs/server.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"$schema": "https://json.schemastore.org/tsconfig",
|
|
3
|
-
|
|
3
|
+
|
|
4
4
|
"compilerOptions": {
|
|
5
5
|
"module": "CommonJS",
|
|
6
6
|
"moduleResolution": "Node",
|
|
@@ -14,6 +14,7 @@
|
|
|
14
14
|
"incremental": true,
|
|
15
15
|
"esModuleInterop": true,
|
|
16
16
|
"resolveJsonModule": true,
|
|
17
|
-
"noEmitOnError": true
|
|
17
|
+
"noEmitOnError": true,
|
|
18
|
+
"noImplicitThis": true
|
|
18
19
|
}
|
|
19
|
-
}
|
|
20
|
+
}
|
package/lib/compilers/watch.js
DELETED
|
@@ -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
|
-
};
|