@strapi/typescript-utils 5.50.0 → 5.50.2
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/dist/compile.d.ts +5 -0
- package/dist/compile.d.ts.map +1 -0
- package/dist/compile.js +12 -0
- package/dist/compile.js.map +1 -0
- package/dist/compile.mjs +10 -0
- package/dist/compile.mjs.map +1 -0
- package/dist/compilers/basic.d.ts +11 -0
- package/dist/compilers/basic.d.ts.map +1 -0
- package/dist/compilers/basic.js +58 -0
- package/dist/compilers/basic.js.map +1 -0
- package/dist/compilers/basic.mjs +36 -0
- package/dist/compilers/basic.mjs.map +1 -0
- package/dist/compilers/index.d.ts +3 -0
- package/dist/compilers/index.d.ts.map +1 -0
- package/dist/compilers/index.js +8 -0
- package/dist/compilers/index.js.map +1 -0
- package/dist/compilers/index.mjs +3 -0
- package/dist/compilers/index.mjs.map +1 -0
- package/dist/generators/common/imports.d.ts +5 -0
- package/dist/generators/common/imports.d.ts.map +1 -0
- package/dist/generators/common/imports.js +42 -0
- package/dist/generators/common/imports.js.map +1 -0
- package/dist/generators/common/imports.mjs +19 -0
- package/dist/generators/common/imports.mjs.map +1 -0
- package/dist/generators/common/index.d.ts +4 -0
- package/dist/generators/common/index.d.ts.map +1 -0
- package/dist/generators/common/models/attributes.d.ts +17 -0
- package/dist/generators/common/models/attributes.d.ts.map +1 -0
- package/dist/generators/common/models/attributes.js +152 -0
- package/dist/generators/common/models/attributes.js.map +1 -0
- package/dist/generators/common/models/attributes.mjs +124 -0
- package/dist/generators/common/models/attributes.mjs.map +1 -0
- package/dist/generators/common/models/index.d.ts +7 -0
- package/dist/generators/common/models/index.d.ts.map +1 -0
- package/dist/generators/common/models/mappers.d.ts +9 -0
- package/dist/generators/common/models/mappers.d.ts.map +1 -0
- package/dist/generators/common/models/mappers.js +227 -0
- package/dist/generators/common/models/mappers.js.map +1 -0
- package/dist/generators/common/models/mappers.mjs +202 -0
- package/dist/generators/common/models/mappers.mjs.map +1 -0
- package/dist/generators/common/models/schema.d.ts +7 -0
- package/dist/generators/common/models/schema.d.ts.map +1 -0
- package/dist/generators/common/models/schema.js +79 -0
- package/dist/generators/common/models/schema.js.map +1 -0
- package/dist/generators/common/models/schema.mjs +57 -0
- package/dist/generators/common/models/schema.mjs.map +1 -0
- package/dist/generators/common/models/utils.d.ts +54 -0
- package/dist/generators/common/models/utils.d.ts.map +1 -0
- package/dist/generators/common/models/utils.js +109 -0
- package/dist/generators/common/models/utils.js.map +1 -0
- package/dist/generators/common/models/utils.mjs +81 -0
- package/dist/generators/common/models/utils.mjs.map +1 -0
- package/dist/generators/components/index.d.ts +9 -0
- package/dist/generators/components/index.d.ts.map +1 -0
- package/dist/generators/components/index.js +76 -0
- package/dist/generators/components/index.js.map +1 -0
- package/dist/generators/components/index.mjs +54 -0
- package/dist/generators/components/index.mjs.map +1 -0
- package/dist/generators/constants.d.ts +3 -0
- package/dist/generators/constants.d.ts.map +1 -0
- package/dist/generators/constants.js +8 -0
- package/dist/generators/constants.js.map +1 -0
- package/dist/generators/constants.mjs +5 -0
- package/dist/generators/constants.mjs.map +1 -0
- package/dist/generators/content-types/index.d.ts +9 -0
- package/dist/generators/content-types/index.d.ts.map +1 -0
- package/dist/generators/content-types/index.js +76 -0
- package/dist/generators/content-types/index.js.map +1 -0
- package/dist/generators/content-types/index.mjs +54 -0
- package/dist/generators/content-types/index.mjs.map +1 -0
- package/dist/generators/index.d.ts +23 -0
- package/dist/generators/index.d.ts.map +1 -0
- package/dist/generators/index.js +81 -0
- package/dist/generators/index.js.map +1 -0
- package/dist/generators/index.mjs +74 -0
- package/dist/generators/index.mjs.map +1 -0
- package/dist/generators/utils.d.ts +52 -0
- package/dist/generators/utils.d.ts.map +1 -0
- package/dist/generators/utils.js +164 -0
- package/dist/generators/utils.js.map +1 -0
- package/dist/generators/utils.mjs +131 -0
- package/dist/generators/utils.mjs.map +1 -0
- package/dist/index.d.ts +5 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +28 -0
- package/dist/index.js.map +1 -0
- package/dist/index.mjs +14 -0
- package/dist/index.mjs.map +1 -0
- package/dist/utils/format-host.d.ts +3 -0
- package/dist/utils/format-host.d.ts.map +1 -0
- package/dist/utils/format-host.js +33 -0
- package/dist/utils/format-host.js.map +1 -0
- package/dist/utils/format-host.mjs +11 -0
- package/dist/utils/format-host.mjs.map +1 -0
- package/dist/utils/get-config-path.d.ts +10 -0
- package/dist/utils/get-config-path.d.ts.map +1 -0
- package/dist/utils/get-config-path.js +43 -0
- package/dist/utils/get-config-path.js.map +1 -0
- package/dist/utils/get-config-path.mjs +18 -0
- package/dist/utils/get-config-path.mjs.map +1 -0
- package/dist/utils/index.d.ts +9 -0
- package/dist/utils/index.d.ts.map +1 -0
- package/dist/utils/is-using-typescript-sync.d.ts +5 -0
- package/dist/utils/is-using-typescript-sync.d.ts.map +1 -0
- package/dist/utils/is-using-typescript-sync.js +20 -0
- package/dist/utils/is-using-typescript-sync.js.map +1 -0
- package/dist/utils/is-using-typescript-sync.mjs +14 -0
- package/dist/utils/is-using-typescript-sync.mjs.map +1 -0
- package/dist/utils/is-using-typescript.d.ts +5 -0
- package/dist/utils/is-using-typescript.d.ts.map +1 -0
- package/dist/utils/is-using-typescript.js +20 -0
- package/dist/utils/is-using-typescript.js.map +1 -0
- package/dist/utils/is-using-typescript.mjs +14 -0
- package/dist/utils/is-using-typescript.mjs.map +1 -0
- package/dist/utils/report-diagnostics.d.ts +6 -0
- package/dist/utils/report-diagnostics.d.ts.map +1 -0
- package/dist/utils/report-diagnostics.js +37 -0
- package/dist/utils/report-diagnostics.js.map +1 -0
- package/dist/utils/report-diagnostics.mjs +15 -0
- package/dist/utils/report-diagnostics.mjs.map +1 -0
- package/dist/utils/resolve-config-options.d.ts +12 -0
- package/dist/utils/resolve-config-options.d.ts.map +1 -0
- package/dist/utils/resolve-config-options.js +39 -0
- package/dist/utils/resolve-config-options.js.map +1 -0
- package/dist/utils/resolve-config-options.mjs +17 -0
- package/dist/utils/resolve-config-options.mjs.map +1 -0
- package/dist/utils/resolve-outdir-sync.d.ts +5 -0
- package/dist/utils/resolve-outdir-sync.d.ts.map +1 -0
- package/dist/utils/resolve-outdir-sync.js +19 -0
- package/dist/utils/resolve-outdir-sync.js.map +1 -0
- package/dist/utils/resolve-outdir-sync.mjs +13 -0
- package/dist/utils/resolve-outdir-sync.mjs.map +1 -0
- package/dist/utils/resolve-outdir.d.ts +5 -0
- package/dist/utils/resolve-outdir.d.ts.map +1 -0
- package/dist/utils/resolve-outdir.js +19 -0
- package/dist/utils/resolve-outdir.js.map +1 -0
- package/dist/utils/resolve-outdir.mjs +13 -0
- package/dist/utils/resolve-outdir.mjs.map +1 -0
- package/package.json +25 -10
- package/.eslintrc.cjs +0 -16
- package/index.d.ts +0 -5
- package/jest.config.js +0 -6
- package/lib/__tests__/generators/schemas/attributes.test.js +0 -903
- package/lib/__tests__/generators/schemas/imports.test.js +0 -56
- package/lib/__tests__/generators/schemas/utils.test.js +0 -314
- package/lib/compile.js +0 -10
- package/lib/compilers/basic.js +0 -50
- package/lib/compilers/index.js +0 -7
- package/lib/generators/common/imports.js +0 -34
- package/lib/generators/common/index.js +0 -9
- package/lib/generators/common/models/attributes.js +0 -198
- package/lib/generators/common/models/index.js +0 -15
- package/lib/generators/common/models/mappers.js +0 -144
- package/lib/generators/common/models/schema.js +0 -93
- package/lib/generators/common/models/utils.js +0 -178
- package/lib/generators/components/index.js +0 -74
- package/lib/generators/constants.js +0 -6
- package/lib/generators/content-types/index.js +0 -74
- package/lib/generators/index.js +0 -122
- package/lib/generators/utils.js +0 -216
- package/lib/index.js +0 -13
- package/lib/utils/format-host.js +0 -15
- package/lib/utils/get-config-path.js +0 -29
- package/lib/utils/index.js +0 -21
- package/lib/utils/is-using-typescript-sync.js +0 -19
- package/lib/utils/is-using-typescript.js +0 -17
- package/lib/utils/report-diagnostics.js +0 -19
- package/lib/utils/resolve-config-options.js +0 -23
- package/lib/utils/resolve-outdir-sync.js +0 -18
- package/lib/utils/resolve-outdir.js +0 -18
- package/lint-staged.config.mjs +0 -1
package/lib/generators/utils.js
DELETED
|
@@ -1,216 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
const path = require('path');
|
|
4
|
-
const assert = require('assert');
|
|
5
|
-
const ts = require('typescript');
|
|
6
|
-
const fse = require('fs-extra');
|
|
7
|
-
const chalk = require('chalk');
|
|
8
|
-
|
|
9
|
-
const { factory } = ts;
|
|
10
|
-
|
|
11
|
-
const MODULE_DECLARATION = '@strapi/strapi';
|
|
12
|
-
const PUBLIC_NAMESPACE = 'Public';
|
|
13
|
-
|
|
14
|
-
/**
|
|
15
|
-
* Aggregate the given TypeScript nodes into a single string
|
|
16
|
-
*
|
|
17
|
-
* @param {ts.Node[]} definitions
|
|
18
|
-
* @return {string}
|
|
19
|
-
*/
|
|
20
|
-
const emitDefinitions = (definitions) => {
|
|
21
|
-
const nodeArray = factory.createNodeArray(definitions);
|
|
22
|
-
|
|
23
|
-
const sourceFile = ts.createSourceFile(
|
|
24
|
-
'placeholder.ts',
|
|
25
|
-
'',
|
|
26
|
-
ts.ScriptTarget.ESNext,
|
|
27
|
-
true,
|
|
28
|
-
ts.ScriptKind.TS
|
|
29
|
-
);
|
|
30
|
-
|
|
31
|
-
const printer = ts.createPrinter({ omitTrailingSemicolon: true });
|
|
32
|
-
|
|
33
|
-
return printer.printList(ts.ListFormat.MultiLine, nodeArray, sourceFile);
|
|
34
|
-
};
|
|
35
|
-
|
|
36
|
-
/**
|
|
37
|
-
* Save the given string representation of TS nodes in a file
|
|
38
|
-
* If the given directory doesn't exist, it'll be created automatically
|
|
39
|
-
*
|
|
40
|
-
* @param {string} dir
|
|
41
|
-
* @param {string} file
|
|
42
|
-
* @param {string} content
|
|
43
|
-
*
|
|
44
|
-
* @return {Promise<string>} The path of the created file
|
|
45
|
-
*/
|
|
46
|
-
const saveDefinitionToFileSystem = async (dir, file, content) => {
|
|
47
|
-
const filepath = path.join(dir, file);
|
|
48
|
-
|
|
49
|
-
fse.ensureDirSync(dir);
|
|
50
|
-
await fse.writeFile(filepath, content);
|
|
51
|
-
|
|
52
|
-
return filepath;
|
|
53
|
-
};
|
|
54
|
-
|
|
55
|
-
/**
|
|
56
|
-
* Format the given definitions.
|
|
57
|
-
* Uses the existing config if one is defined in the project.
|
|
58
|
-
*
|
|
59
|
-
* @param {string} content
|
|
60
|
-
* @returns {Promise<string>}
|
|
61
|
-
*/
|
|
62
|
-
const format = async (content) => {
|
|
63
|
-
// eslint-disable-next-line node/no-unsupported-features/es-syntax
|
|
64
|
-
const prettier = await import('prettier'); // ESM-only
|
|
65
|
-
|
|
66
|
-
const configFile = await prettier.resolveConfigFile();
|
|
67
|
-
const config = configFile
|
|
68
|
-
? await prettier.resolveConfig(configFile)
|
|
69
|
-
: // Default config
|
|
70
|
-
{
|
|
71
|
-
singleQuote: true,
|
|
72
|
-
useTabs: false,
|
|
73
|
-
tabWidth: 2,
|
|
74
|
-
};
|
|
75
|
-
|
|
76
|
-
Object.assign(config, { parser: 'typescript' });
|
|
77
|
-
|
|
78
|
-
return prettier.format(content, config);
|
|
79
|
-
};
|
|
80
|
-
|
|
81
|
-
/**
|
|
82
|
-
* Generate the extension block for a shared component from strapi/strapi
|
|
83
|
-
*
|
|
84
|
-
* @param {string} registry The registry to extend
|
|
85
|
-
* @param {Array<{ uid: string; definition: ts.TypeNode }>} definitions
|
|
86
|
-
* @returns {ts.ModuleDeclaration}
|
|
87
|
-
*/
|
|
88
|
-
const generateSharedExtensionDefinition = (registry, definitions) => {
|
|
89
|
-
const properties = definitions.map(({ uid, definition }) =>
|
|
90
|
-
factory.createPropertySignature(
|
|
91
|
-
undefined,
|
|
92
|
-
factory.createStringLiteral(uid, true),
|
|
93
|
-
undefined,
|
|
94
|
-
factory.createTypeReferenceNode(factory.createIdentifier(definition.name.escapedText))
|
|
95
|
-
)
|
|
96
|
-
);
|
|
97
|
-
|
|
98
|
-
return factory.createModuleDeclaration(
|
|
99
|
-
[factory.createModifier(ts.SyntaxKind.DeclareKeyword)],
|
|
100
|
-
factory.createStringLiteral(MODULE_DECLARATION, true),
|
|
101
|
-
factory.createModuleBlock([
|
|
102
|
-
factory.createModuleDeclaration(
|
|
103
|
-
[factory.createModifier(ts.SyntaxKind.ExportKeyword)],
|
|
104
|
-
factory.createIdentifier(PUBLIC_NAMESPACE),
|
|
105
|
-
factory.createModuleBlock(
|
|
106
|
-
properties.length > 0
|
|
107
|
-
? [
|
|
108
|
-
factory.createInterfaceDeclaration(
|
|
109
|
-
[factory.createModifier(ts.SyntaxKind.ExportKeyword)],
|
|
110
|
-
factory.createIdentifier(registry),
|
|
111
|
-
undefined,
|
|
112
|
-
undefined,
|
|
113
|
-
properties
|
|
114
|
-
),
|
|
115
|
-
]
|
|
116
|
-
: []
|
|
117
|
-
)
|
|
118
|
-
),
|
|
119
|
-
]),
|
|
120
|
-
ts.NodeFlags.ExportContext
|
|
121
|
-
);
|
|
122
|
-
};
|
|
123
|
-
|
|
124
|
-
const createLogger = (options = {}) => {
|
|
125
|
-
const { silent = false, debug = false } = options;
|
|
126
|
-
|
|
127
|
-
const state = { errors: 0, warning: 0 };
|
|
128
|
-
|
|
129
|
-
return {
|
|
130
|
-
get warnings() {
|
|
131
|
-
return state.warning;
|
|
132
|
-
},
|
|
133
|
-
|
|
134
|
-
get errors() {
|
|
135
|
-
return state.errors;
|
|
136
|
-
},
|
|
137
|
-
|
|
138
|
-
debug(...args) {
|
|
139
|
-
if (silent || !debug) {
|
|
140
|
-
return;
|
|
141
|
-
}
|
|
142
|
-
|
|
143
|
-
console.log(chalk.cyan(`[DEBUG]\t[${new Date().toISOString()}] (Typegen)`), ...args);
|
|
144
|
-
},
|
|
145
|
-
|
|
146
|
-
info(...args) {
|
|
147
|
-
if (silent) {
|
|
148
|
-
return;
|
|
149
|
-
}
|
|
150
|
-
|
|
151
|
-
console.info(chalk.blue(`[INFO]\t[${new Date().toISOString()}] (Typegen)`), ...args);
|
|
152
|
-
},
|
|
153
|
-
|
|
154
|
-
warn(...args) {
|
|
155
|
-
state.warning += 1;
|
|
156
|
-
|
|
157
|
-
if (silent) {
|
|
158
|
-
return;
|
|
159
|
-
}
|
|
160
|
-
|
|
161
|
-
console.warn(chalk.yellow(`[WARN]\t[${new Date().toISOString()}] (Typegen)`), ...args);
|
|
162
|
-
},
|
|
163
|
-
|
|
164
|
-
error(...args) {
|
|
165
|
-
state.errors += 1;
|
|
166
|
-
|
|
167
|
-
if (silent) {
|
|
168
|
-
return;
|
|
169
|
-
}
|
|
170
|
-
|
|
171
|
-
console.error(chalk.red(`[ERROR]\t[${new Date().toISOString()}] (Typegen)`), ...args);
|
|
172
|
-
},
|
|
173
|
-
};
|
|
174
|
-
};
|
|
175
|
-
|
|
176
|
-
const timer = () => {
|
|
177
|
-
const state = {
|
|
178
|
-
start: null,
|
|
179
|
-
end: null,
|
|
180
|
-
};
|
|
181
|
-
|
|
182
|
-
return {
|
|
183
|
-
start() {
|
|
184
|
-
assert(state.start === null, 'The timer has already been started');
|
|
185
|
-
assert(state.end === null, 'The timer has already been ended');
|
|
186
|
-
|
|
187
|
-
state.start = Date.now();
|
|
188
|
-
|
|
189
|
-
return this;
|
|
190
|
-
},
|
|
191
|
-
|
|
192
|
-
end() {
|
|
193
|
-
assert(state.start !== null, 'The timer needs to be started before ending it');
|
|
194
|
-
assert(state.end === null, 'The timer has already been ended');
|
|
195
|
-
|
|
196
|
-
state.end = Date.now();
|
|
197
|
-
|
|
198
|
-
return this;
|
|
199
|
-
},
|
|
200
|
-
|
|
201
|
-
get duration() {
|
|
202
|
-
assert(state.start !== null, 'The timer has not been started');
|
|
203
|
-
|
|
204
|
-
return ((state.end ?? Date.now) - state.start) / 1000;
|
|
205
|
-
},
|
|
206
|
-
};
|
|
207
|
-
};
|
|
208
|
-
|
|
209
|
-
module.exports = {
|
|
210
|
-
emitDefinitions,
|
|
211
|
-
saveDefinitionToFileSystem,
|
|
212
|
-
format,
|
|
213
|
-
generateSharedExtensionDefinition,
|
|
214
|
-
createLogger,
|
|
215
|
-
timer,
|
|
216
|
-
};
|
package/lib/index.js
DELETED
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
const compile = require('./compile');
|
|
4
|
-
const compilers = require('./compilers');
|
|
5
|
-
const utils = require('./utils');
|
|
6
|
-
const generators = require('./generators');
|
|
7
|
-
|
|
8
|
-
module.exports = {
|
|
9
|
-
compile,
|
|
10
|
-
compilers,
|
|
11
|
-
generators,
|
|
12
|
-
...utils,
|
|
13
|
-
};
|
package/lib/utils/format-host.js
DELETED
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
const ts = require('typescript');
|
|
4
|
-
const { identity } = require('lodash/fp');
|
|
5
|
-
|
|
6
|
-
/**
|
|
7
|
-
* @type {ts.FormatDiagnosticsHost}
|
|
8
|
-
*/
|
|
9
|
-
const formatHost = {
|
|
10
|
-
getCanonicalFileName: identity,
|
|
11
|
-
getCurrentDirectory: ts.sys.getCurrentDirectory,
|
|
12
|
-
getNewLine: () => ts.sys.newLine,
|
|
13
|
-
};
|
|
14
|
-
|
|
15
|
-
module.exports = formatHost;
|
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
const path = require('path');
|
|
4
|
-
const ts = require('typescript');
|
|
5
|
-
|
|
6
|
-
const DEFAULT_TS_CONFIG_FILENAME = 'tsconfig.json';
|
|
7
|
-
|
|
8
|
-
/**
|
|
9
|
-
* Get the path of the typescript config file for a given directory
|
|
10
|
-
*
|
|
11
|
-
* @param {string} dir
|
|
12
|
-
* @param {object} [options]
|
|
13
|
-
* @param {string} [options.filename]
|
|
14
|
-
* @param {boolean} [options.ancestorsLookup]
|
|
15
|
-
*
|
|
16
|
-
* @return {string | undefined}
|
|
17
|
-
*/
|
|
18
|
-
module.exports = (dir, { filename = DEFAULT_TS_CONFIG_FILENAME, ancestorsLookup = false } = {}) => {
|
|
19
|
-
const dirAbsolutePath = path.resolve(dir);
|
|
20
|
-
let configFilePath = ts.findConfigFile(dirAbsolutePath, ts.sys.fileExists, filename);
|
|
21
|
-
|
|
22
|
-
if (configFilePath) configFilePath = path.resolve(configFilePath);
|
|
23
|
-
|
|
24
|
-
if (!configFilePath || ancestorsLookup) {
|
|
25
|
-
return configFilePath;
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
return configFilePath.startsWith(dirAbsolutePath) ? configFilePath : undefined;
|
|
29
|
-
};
|
package/lib/utils/index.js
DELETED
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
const isUsingTypeScript = require('./is-using-typescript');
|
|
4
|
-
const isUsingTypeScriptSync = require('./is-using-typescript-sync');
|
|
5
|
-
const getConfigPath = require('./get-config-path');
|
|
6
|
-
const reportDiagnostics = require('./report-diagnostics');
|
|
7
|
-
const resolveConfigOptions = require('./resolve-config-options');
|
|
8
|
-
const formatHost = require('./format-host');
|
|
9
|
-
const resolveOutDir = require('./resolve-outdir');
|
|
10
|
-
const resolveOutDirSync = require('./resolve-outdir-sync');
|
|
11
|
-
|
|
12
|
-
module.exports = {
|
|
13
|
-
isUsingTypeScript,
|
|
14
|
-
isUsingTypeScriptSync,
|
|
15
|
-
getConfigPath,
|
|
16
|
-
reportDiagnostics,
|
|
17
|
-
resolveConfigOptions,
|
|
18
|
-
formatHost,
|
|
19
|
-
resolveOutDir,
|
|
20
|
-
resolveOutDirSync,
|
|
21
|
-
};
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
// @ts-check
|
|
2
|
-
|
|
3
|
-
'use strict';
|
|
4
|
-
|
|
5
|
-
const fse = require('fs-extra');
|
|
6
|
-
|
|
7
|
-
const getConfigPath = require('./get-config-path');
|
|
8
|
-
|
|
9
|
-
/**
|
|
10
|
-
* Checks if `dir` is a using TypeScript (whether there is a tsconfig file or not)
|
|
11
|
-
* @param {string} dir
|
|
12
|
-
* @param {string | undefined} filename
|
|
13
|
-
* @returns {boolean}
|
|
14
|
-
*/
|
|
15
|
-
module.exports = (dir, filename = undefined) => {
|
|
16
|
-
const filePath = getConfigPath(dir, { filename });
|
|
17
|
-
|
|
18
|
-
return filePath ? fse.pathExistsSync(filePath) : false;
|
|
19
|
-
};
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
const fse = require('fs-extra');
|
|
4
|
-
|
|
5
|
-
const getConfigPath = require('./get-config-path');
|
|
6
|
-
|
|
7
|
-
/**
|
|
8
|
-
* Checks if `dir` is a using TypeScript (whether there is a tsconfig file or not)
|
|
9
|
-
* @param {string} dir
|
|
10
|
-
* @param {string | undefined} filename
|
|
11
|
-
* @returns {Promise<boolean>}
|
|
12
|
-
*/
|
|
13
|
-
module.exports = (dir, filename = undefined) => {
|
|
14
|
-
const filePath = getConfigPath(dir, { filename });
|
|
15
|
-
|
|
16
|
-
return fse.pathExists(filePath);
|
|
17
|
-
};
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
const ts = require('typescript');
|
|
4
|
-
|
|
5
|
-
const formatHost = require('./format-host');
|
|
6
|
-
|
|
7
|
-
/**
|
|
8
|
-
* Report one or several diagnostic to the console
|
|
9
|
-
* @param {ts.Diagnostic[] | ts.Diagnostic} diagnostics
|
|
10
|
-
*/
|
|
11
|
-
module.exports = (diagnostics) => {
|
|
12
|
-
const formattedDiagnostics = ts.formatDiagnosticsWithColorAndContext(
|
|
13
|
-
Array.isArray(diagnostics) ? diagnostics : [diagnostics],
|
|
14
|
-
formatHost
|
|
15
|
-
);
|
|
16
|
-
|
|
17
|
-
console.error(formattedDiagnostics);
|
|
18
|
-
console.info(`Found ${diagnostics.length} error(s).${ts.sys.newLine}`);
|
|
19
|
-
};
|
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
const ts = require('typescript');
|
|
4
|
-
|
|
5
|
-
const logDiagnostics = require('./report-diagnostics');
|
|
6
|
-
|
|
7
|
-
module.exports = (configPath) => {
|
|
8
|
-
// Parse the tsconfig.json file and resolve every file name & compiler options
|
|
9
|
-
const { errors, ...configOptions } = ts.getParsedCommandLineOfConfigFile(
|
|
10
|
-
configPath,
|
|
11
|
-
undefined,
|
|
12
|
-
ts.sys
|
|
13
|
-
);
|
|
14
|
-
|
|
15
|
-
// If there are errors in the tsconfig.json
|
|
16
|
-
// file, report them and exit early
|
|
17
|
-
if (errors.length > 0) {
|
|
18
|
-
logDiagnostics(errors);
|
|
19
|
-
process.exit(1);
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
return configOptions;
|
|
23
|
-
};
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
const path = require('path');
|
|
4
|
-
const resolveConfigOptions = require('./resolve-config-options');
|
|
5
|
-
const isUsingTypescriptSync = require('./is-using-typescript-sync');
|
|
6
|
-
|
|
7
|
-
const DEFAULT_TS_CONFIG_FILENAME = 'tsconfig.json';
|
|
8
|
-
/**
|
|
9
|
-
* Gets the outDir value from config file (tsconfig)
|
|
10
|
-
* @param {string} dir
|
|
11
|
-
* @param {string | undefined} configFilename
|
|
12
|
-
* @returns {string | undefined}
|
|
13
|
-
*/
|
|
14
|
-
module.exports = (dir, configFilename = DEFAULT_TS_CONFIG_FILENAME) => {
|
|
15
|
-
return isUsingTypescriptSync(dir)
|
|
16
|
-
? resolveConfigOptions(path.join(dir, configFilename)).options.outDir
|
|
17
|
-
: undefined;
|
|
18
|
-
};
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
const path = require('path');
|
|
4
|
-
const resolveConfigOptions = require('./resolve-config-options');
|
|
5
|
-
const isUsingTypescript = require('./is-using-typescript');
|
|
6
|
-
|
|
7
|
-
const DEFAULT_TS_CONFIG_FILENAME = 'tsconfig.json';
|
|
8
|
-
/**
|
|
9
|
-
* Gets the outDir value from config file (tsconfig)
|
|
10
|
-
* @param {string} dir
|
|
11
|
-
* @param {string | undefined} configFilename
|
|
12
|
-
* @returns {Promise<string | undefined>}
|
|
13
|
-
*/
|
|
14
|
-
module.exports = async (dir, configFilename = DEFAULT_TS_CONFIG_FILENAME) => {
|
|
15
|
-
return (await isUsingTypescript(dir))
|
|
16
|
-
? resolveConfigOptions(path.join(dir, configFilename)).options.outDir
|
|
17
|
-
: undefined;
|
|
18
|
-
};
|
package/lint-staged.config.mjs
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export { default } from '../../../lint-staged.shared.mjs';
|