@touk/federated-types 1.3.0-beta.1 → 1.3.0-beta.4
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/cli.js +39 -17
- package/package.json +6 -2
package/cli.js
CHANGED
|
@@ -4,6 +4,7 @@ const path = require('path');
|
|
|
4
4
|
const fs = require('fs');
|
|
5
5
|
const findNodeModules = require('find-node-modules');
|
|
6
6
|
const ts = require('typescript');
|
|
7
|
+
const chalk = require('chalk');
|
|
7
8
|
|
|
8
9
|
const formatHost = {
|
|
9
10
|
getCurrentDirectory: ts.sys.getCurrentDirectory,
|
|
@@ -12,8 +13,8 @@ const formatHost = {
|
|
|
12
13
|
|
|
13
14
|
function reportDiagnostic(diagnostic) {
|
|
14
15
|
console.log(
|
|
15
|
-
'TS Error',
|
|
16
|
-
diagnostic.code,
|
|
16
|
+
chalk.red('TS Error'),
|
|
17
|
+
chalk.yellow(diagnostic.code),
|
|
17
18
|
':',
|
|
18
19
|
ts.flattenDiagnosticMessageText(diagnostic.messageText, formatHost.getNewLine())
|
|
19
20
|
);
|
|
@@ -40,7 +41,7 @@ const getAllArgs = (argName) => {
|
|
|
40
41
|
results.push([process.argv[i + 1], process.argv[i + 2]]);
|
|
41
42
|
i += 3; // skip argName, key, value
|
|
42
43
|
} else {
|
|
43
|
-
console.error(
|
|
44
|
+
console.error(chalk.red('ERROR:'), '--exposes requires two arguments (key path)');
|
|
44
45
|
process.exit(1);
|
|
45
46
|
}
|
|
46
47
|
} else {
|
|
@@ -66,6 +67,10 @@ const configPath = configPathArg ? path.resolve(configPathArg) : null;
|
|
|
66
67
|
|
|
67
68
|
const nameArg = getArg('--name');
|
|
68
69
|
const exposesArgs = getAllArgs('--exposes');
|
|
70
|
+
const verboseArg = hasArg('--verbose') || process.env.npm_config_loglevel === 'verbose';
|
|
71
|
+
|
|
72
|
+
const log = (...args) => console.log(...args);
|
|
73
|
+
const logDebug = (...args) => verboseArg && console.debug(chalk.gray.dim(...args));
|
|
69
74
|
|
|
70
75
|
const findFederationConfig = (base) => {
|
|
71
76
|
let files = fs.readdirSync(base);
|
|
@@ -92,12 +97,18 @@ let federationConfig;
|
|
|
92
97
|
if (nameArg || exposesArgs.length > 0) {
|
|
93
98
|
// Inline config mode
|
|
94
99
|
if (!nameArg || exposesArgs.length === 0) {
|
|
95
|
-
console.error(
|
|
100
|
+
console.error(
|
|
101
|
+
chalk.red('ERROR:'),
|
|
102
|
+
'Both --name and --exposes are required for inline config'
|
|
103
|
+
);
|
|
96
104
|
process.exit(1);
|
|
97
105
|
}
|
|
98
106
|
|
|
99
107
|
if (configPath) {
|
|
100
|
-
console.warn(
|
|
108
|
+
console.warn(
|
|
109
|
+
chalk.yellow('WARNING:'),
|
|
110
|
+
'Both inline config and --config provided. Using inline config.'
|
|
111
|
+
);
|
|
101
112
|
}
|
|
102
113
|
|
|
103
114
|
const exposes = {};
|
|
@@ -113,22 +124,26 @@ if (nameArg || exposesArgs.length > 0) {
|
|
|
113
124
|
exposes: exposes,
|
|
114
125
|
};
|
|
115
126
|
|
|
116
|
-
|
|
127
|
+
log('Using inline config');
|
|
128
|
+
logDebug(JSON.stringify(federationConfig, null, 2));
|
|
117
129
|
} else {
|
|
118
130
|
// File-based config (current behavior)
|
|
119
131
|
if (configPath && !fs.existsSync(configPath)) {
|
|
120
|
-
console.error(
|
|
132
|
+
console.error(chalk.red('ERROR:'), `Unable to find a provided config: ${configPath}`);
|
|
121
133
|
process.exit(1);
|
|
122
134
|
}
|
|
123
135
|
|
|
124
136
|
const federationConfigPath = configPath || findFederationConfig('./');
|
|
125
137
|
|
|
126
138
|
if (federationConfigPath === undefined) {
|
|
127
|
-
console.error(
|
|
139
|
+
console.error(
|
|
140
|
+
chalk.red('ERROR:'),
|
|
141
|
+
'Unable to find a federation.config.json file in this package'
|
|
142
|
+
);
|
|
128
143
|
process.exit(1);
|
|
129
144
|
}
|
|
130
145
|
|
|
131
|
-
|
|
146
|
+
log('Using config file', chalk.blue.bold(federationConfigPath));
|
|
132
147
|
federationConfig = require(federationConfigPath);
|
|
133
148
|
}
|
|
134
149
|
|
|
@@ -141,17 +156,24 @@ function getModuleDeclareName(exposeName) {
|
|
|
141
156
|
}
|
|
142
157
|
|
|
143
158
|
try {
|
|
159
|
+
fs.mkdirSync(outputDir, { recursive: true });
|
|
144
160
|
const outFile = path.resolve(outputDir, `${federationConfig.name}.d.ts`);
|
|
145
161
|
if (fs.existsSync(outFile)) {
|
|
146
162
|
fs.unlinkSync(outFile);
|
|
147
163
|
}
|
|
148
164
|
|
|
165
|
+
const tsBuildInfoFile = path.resolve(process.cwd(), 'node_modules', '.cache', 'federated-types', `${federationConfig.name}.tsbuildinfo`);
|
|
166
|
+
fs.mkdirSync(path.dirname(tsBuildInfoFile), { recursive: true });
|
|
167
|
+
|
|
149
168
|
// write the typings file
|
|
150
169
|
const program = ts.createProgram(compileFiles, {
|
|
151
170
|
outFile,
|
|
152
171
|
declaration: true,
|
|
153
172
|
emitDeclarationOnly: true,
|
|
154
173
|
skipLibCheck: true,
|
|
174
|
+
noCheck: true,
|
|
175
|
+
incremental: true,
|
|
176
|
+
tsBuildInfoFile,
|
|
155
177
|
jsx: ts.JsxEmit.React,
|
|
156
178
|
esModuleInterop: true,
|
|
157
179
|
});
|
|
@@ -200,23 +222,23 @@ try {
|
|
|
200
222
|
outputDirs.forEach((_outputDir) => {
|
|
201
223
|
const _outFile = path.resolve(_outputDir, `${federationConfig.name}.d.ts`);
|
|
202
224
|
|
|
203
|
-
|
|
225
|
+
logDebug('writing typing file:', _outFile);
|
|
204
226
|
fs.mkdirSync(path.dirname(_outFile), { recursive: true });
|
|
205
227
|
fs.writeFileSync(_outFile, typing);
|
|
206
228
|
|
|
207
|
-
|
|
229
|
+
logDebug(`using output dir: ${_outputDir}`);
|
|
208
230
|
// if we are writing to the node_modules/@types directory, add a package.json file
|
|
209
231
|
if (_outputDir.includes(path.join('node_modules', '@types'))) {
|
|
210
232
|
const packageJsonPath = path.resolve(_outputDir, 'package.json');
|
|
211
233
|
|
|
212
234
|
if (!fs.existsSync(packageJsonPath)) {
|
|
213
|
-
|
|
235
|
+
logDebug('writing package.json:', packageJsonPath);
|
|
214
236
|
fs.copyFileSync(
|
|
215
237
|
path.resolve(__dirname, 'typings.package.tmpl.json'),
|
|
216
238
|
packageJsonPath
|
|
217
239
|
);
|
|
218
240
|
} else {
|
|
219
|
-
|
|
241
|
+
logDebug(packageJsonPath, 'already exists');
|
|
220
242
|
}
|
|
221
243
|
}
|
|
222
244
|
|
|
@@ -225,18 +247,18 @@ try {
|
|
|
225
247
|
const importStatement = `export * from './${federationConfig.name}';`;
|
|
226
248
|
|
|
227
249
|
if (!fs.existsSync(indexPath)) {
|
|
228
|
-
|
|
250
|
+
logDebug('creating index.d.ts file');
|
|
229
251
|
fs.writeFileSync(indexPath, `${importStatement}\n`);
|
|
230
252
|
} else {
|
|
231
|
-
|
|
253
|
+
logDebug('updating index.d.ts file');
|
|
232
254
|
const contents = fs.readFileSync(indexPath);
|
|
233
255
|
if (!contents.includes(importStatement)) {
|
|
234
256
|
fs.writeFileSync(indexPath, `${contents}${importStatement}\n`);
|
|
235
257
|
}
|
|
236
258
|
}
|
|
237
259
|
});
|
|
238
|
-
|
|
260
|
+
log(chalk.green('✓'), `Generated types for ${chalk.blue.bold(federationConfig.name)}`);
|
|
239
261
|
} catch (e) {
|
|
240
|
-
console.error(
|
|
262
|
+
console.error(chalk.red('ERROR:'), e);
|
|
241
263
|
process.exit(1);
|
|
242
264
|
}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@touk/federated-types",
|
|
3
3
|
"description": "share typings for your federated typescript packages around your mono-repo",
|
|
4
|
-
"version": "1.3.0-beta.
|
|
4
|
+
"version": "1.3.0-beta.4",
|
|
5
5
|
"author": "Julian Wielga <j@touk.pl>",
|
|
6
6
|
"bin": {
|
|
7
7
|
"make-federated-types": "./cli.js"
|
|
@@ -10,6 +10,7 @@
|
|
|
10
10
|
"Jonathan Greene <jgreene@pixability.com>"
|
|
11
11
|
],
|
|
12
12
|
"dependencies": {
|
|
13
|
+
"chalk": "^4.1.2",
|
|
13
14
|
"find-node-modules": "2.1.3"
|
|
14
15
|
},
|
|
15
16
|
"devDependencies": {
|
|
@@ -37,7 +38,10 @@
|
|
|
37
38
|
"peerDependencies": {
|
|
38
39
|
"typescript": ">4.0.0"
|
|
39
40
|
},
|
|
40
|
-
"repository":
|
|
41
|
+
"repository": {
|
|
42
|
+
"type": "git",
|
|
43
|
+
"url": "git+https://github.com/TouK/federated-types.git"
|
|
44
|
+
},
|
|
41
45
|
"scripts": {
|
|
42
46
|
"semantic-release": "semantic-release",
|
|
43
47
|
"test": "npm run make-types -workspaces --if-present"
|