@touk/federated-types 1.2.1 → 1.2.2-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.
Files changed (3) hide show
  1. package/README.md +1 -4
  2. package/cli.js +27 -20
  3. package/package.json +46 -45
package/README.md CHANGED
@@ -14,7 +14,6 @@ npm install @touk/federated-types
14
14
 
15
15
  You'll also need to place a `federation.config.json` in each package being federated. It will contain the remote name and exported members. These properties are used in Webpack's `ModuleFederationPlugin` configuration object. An example:
16
16
 
17
-
18
17
  ```json
19
18
  //federation.config.json
20
19
 
@@ -28,7 +27,6 @@ You'll also need to place a `federation.config.json` in each package being feder
28
27
 
29
28
  It's recommended that you spread these properties into your ModuleFederationPlugin configuration, like so:
30
29
 
31
-
32
30
  ```javascript
33
31
  //webpack.config.js
34
32
 
@@ -55,7 +53,6 @@ module.exports = {
55
53
 
56
54
  Then you can call `make-federated-types` from your `scripts` block in your package's `package.json` file:
57
55
 
58
-
59
56
  ```javascript
60
57
  //package.json
61
58
 
@@ -68,7 +65,6 @@ This will write new package to the `node_modules/@types/__federated_types` in yo
68
65
 
69
66
  If you would rather specify a directory in which to write the typing files, you can pass an `--outputDir` parameter to the command like so:
70
67
 
71
-
72
68
  ```javascript
73
69
  //package.json
74
70
 
@@ -76,6 +72,7 @@ scripts: {
76
72
  "make-types": "make-federated-types --outputDir ../../my_types/"
77
73
  }
78
74
  ```
75
+
79
76
  You can add an `--saveToNodeModules` parameter to save in both places.
80
77
 
81
78
  If you would like to specify custom path to the config, you can pass `--config` parameter like so:
package/cli.js CHANGED
@@ -7,11 +7,16 @@ const ts = require('typescript');
7
7
 
8
8
  const formatHost = {
9
9
  getCurrentDirectory: ts.sys.getCurrentDirectory,
10
- getNewLine: () => ts.sys.newLine
10
+ getNewLine: () => ts.sys.newLine,
11
11
  };
12
12
 
13
13
  function reportDiagnostic(diagnostic) {
14
- console.log("TS Error", diagnostic.code, ":", ts.flattenDiagnosticMessageText( diagnostic.messageText, formatHost.getNewLine()));
14
+ console.log(
15
+ 'TS Error',
16
+ diagnostic.code,
17
+ ':',
18
+ ts.flattenDiagnosticMessageText(diagnostic.messageText, formatHost.getNewLine())
19
+ );
15
20
  }
16
21
 
17
22
  const [nodeModules] = findNodeModules({ cwd: process.argv[1], relative: false });
@@ -29,18 +34,15 @@ const nodeModulesOutputDir = path.resolve(nodeModules, '@types/__federated_types
29
34
  const saveToNodeMoulesArg = hasArg('--saveToNodeModules');
30
35
  const outDirArg = getArg('--outputDir');
31
36
 
32
- const outputDir = outDirArg
33
- ? path.resolve('./', outDirArg)
34
- : nodeModulesOutputDir;
37
+ const outputDir = outDirArg ? path.resolve('./', outDirArg) : nodeModulesOutputDir;
35
38
 
36
- const outputDirs = outputDir !== nodeModulesOutputDir && saveToNodeMoulesArg
37
- ? [nodeModulesOutputDir, outputDir]
38
- : [outputDir];
39
+ const outputDirs =
40
+ outputDir !== nodeModulesOutputDir && saveToNodeMoulesArg
41
+ ? [nodeModulesOutputDir, outputDir]
42
+ : [outputDir];
39
43
 
40
44
  const configPathArg = getArg('--config');
41
- const configPath = configPathArg
42
- ? path.resolve(configPathArg)
43
- : null;
45
+ const configPath = configPathArg ? path.resolve(configPathArg) : null;
44
46
 
45
47
  const findFederationConfig = (base) => {
46
48
  let files = fs.readdirSync(base);
@@ -56,7 +58,7 @@ const findFederationConfig = (base) => {
56
58
  }
57
59
  }
58
60
 
59
- for( let i = 0; i < queue.length; i++ ) {
61
+ for (let i = 0; i < queue.length; i++) {
60
62
  return findFederationConfig(queue[i]);
61
63
  }
62
64
  };
@@ -68,7 +70,6 @@ if (configPath && !fs.existsSync(configPath)) {
68
70
 
69
71
  const federationConfigPath = configPath || findFederationConfig('./');
70
72
 
71
-
72
73
  if (federationConfigPath === undefined) {
73
74
  console.error(`ERROR: Unable to find a federation.config.json file in this package`);
74
75
  process.exit(1);
@@ -97,16 +98,16 @@ try {
97
98
  declaration: true,
98
99
  emitDeclarationOnly: true,
99
100
  skipLibCheck: true,
100
- jsx: 'react',
101
+ jsx: ts.JsxEmit.React,
101
102
  esModuleInterop: true,
102
103
  });
103
104
 
104
105
  const { emitSkipped, diagnostics } = program.emit();
105
106
 
106
- diagnostics.forEach(reportDiagnostic)
107
+ diagnostics.forEach(reportDiagnostic);
107
108
 
108
109
  if (emitSkipped) {
109
- process.exit(0)
110
+ process.exit(0);
110
111
  }
111
112
 
112
113
  let typing = fs.readFileSync(outFile, { encoding: 'utf8', flag: 'r' });
@@ -114,19 +115,22 @@ try {
114
115
  const moduleRegex = RegExp(/declare module "(.*)"/, 'g');
115
116
  const moduleNames = [];
116
117
 
118
+ let execResults;
117
119
  while ((execResults = moduleRegex.exec(typing)) !== null) {
118
120
  moduleNames.push(execResults[1]);
119
121
  }
120
122
 
121
123
  moduleNames.forEach((name) => {
122
124
  // exposeName - relative name of exposed component (if not found - just take moduleName)
123
- const [exposeName = name, ...aliases] = compileKeys.filter(key => federationConfig.exposes[key].endsWith(name));
125
+ const [exposeName = name, ...aliases] = compileKeys.filter((key) =>
126
+ federationConfig.exposes[key].endsWith(name)
127
+ );
124
128
  const regex = RegExp(`"${name}"`, 'g');
125
129
 
126
130
  const moduleDeclareName = getModuleDeclareName(exposeName);
127
131
 
128
132
  // language=TypeScript
129
- const createAliasModule = name => `
133
+ const createAliasModule = (name) => `
130
134
  declare module "${getModuleDeclareName(name)}" {
131
135
  export * from "${moduleDeclareName}"
132
136
  }
@@ -138,7 +142,7 @@ try {
138
142
  ].join('\n');
139
143
  });
140
144
 
141
- outputDirs.forEach(_outputDir => {
145
+ outputDirs.forEach((_outputDir) => {
142
146
  const _outFile = path.resolve(_outputDir, `${federationConfig.name}.d.ts`);
143
147
 
144
148
  console.log('writing typing file:', _outFile);
@@ -152,7 +156,10 @@ try {
152
156
 
153
157
  if (!fs.existsSync(packageJsonPath)) {
154
158
  console.debug('writing package.json:', packageJsonPath);
155
- fs.copyFileSync(path.resolve(__dirname, 'typings.package.tmpl.json'), packageJsonPath);
159
+ fs.copyFileSync(
160
+ path.resolve(__dirname, 'typings.package.tmpl.json'),
161
+ packageJsonPath
162
+ );
156
163
  } else {
157
164
  console.debug(packageJsonPath, 'already exists');
158
165
  }
package/package.json CHANGED
@@ -1,47 +1,48 @@
1
1
  {
2
- "name": "@touk/federated-types",
3
- "description": "share typings for your federated typescript packages around your mono-repo",
4
- "version": "1.2.1",
5
- "author": "Julian Wielga <j@touk.pl>",
6
- "bin": {
7
- "make-federated-types": "./cli.js"
8
- },
9
- "contributors": [
10
- "Jonathan Greene <jgreene@pixability.com>"
11
- ],
12
- "dependencies": {
13
- "find-node-modules": "2.1.3"
14
- },
15
- "devDependencies": {
16
- "@commitlint/cli": "17.1.2",
17
- "@commitlint/config-conventional": "13.2.0",
18
- "@semantic-release/changelog": "6.0.3",
19
- "@semantic-release/git": "10.0.1",
20
- "husky": "8.0.3",
21
- "prettier": "3.6.2",
22
- "semantic-release": "19.0.5"
23
- },
24
- "files": [
25
- "cli.js",
26
- "typings.package.tmpl.json"
27
- ],
28
- "keywords": [
29
- "module-federation",
30
- "mono-repo",
31
- "typescript",
32
- "typings"
33
- ],
34
- "license": "MIT",
35
- "main": "cli.js",
36
- "peerDependencies": {
37
- "typescript": ">4.0.0"
38
- },
39
- "repository": "touk/federated-types.git",
40
- "scripts": {
41
- "semantic-release": "semantic-release",
42
- "test": "npm run make-types -workspaces --if-present"
43
- },
44
- "workspaces": [
45
- "./packages/*"
46
- ]
2
+ "name": "@touk/federated-types",
3
+ "description": "share typings for your federated typescript packages around your mono-repo",
4
+ "version": "1.2.2-beta.1",
5
+ "author": "Julian Wielga <j@touk.pl>",
6
+ "bin": {
7
+ "make-federated-types": "./cli.js"
8
+ },
9
+ "contributors": [
10
+ "Jonathan Greene <jgreene@pixability.com>"
11
+ ],
12
+ "dependencies": {
13
+ "find-node-modules": "2.1.3"
14
+ },
15
+ "devDependencies": {
16
+ "@commitlint/cli": "^20.4.2",
17
+ "@commitlint/config-conventional": "^20.4.2",
18
+ "@semantic-release/changelog": "^6.0.3",
19
+ "@semantic-release/git": "10.0.1",
20
+ "husky": "^9.1.7",
21
+ "prettier": "^3.8.1",
22
+ "semantic-release": "^25.0.3",
23
+ "typescript": "^5.9.3"
24
+ },
25
+ "files": [
26
+ "cli.js",
27
+ "typings.package.tmpl.json"
28
+ ],
29
+ "keywords": [
30
+ "module-federation",
31
+ "mono-repo",
32
+ "typescript",
33
+ "typings"
34
+ ],
35
+ "license": "MIT",
36
+ "main": "cli.js",
37
+ "peerDependencies": {
38
+ "typescript": ">4.0.0"
39
+ },
40
+ "repository": "touk/federated-types.git",
41
+ "scripts": {
42
+ "semantic-release": "semantic-release",
43
+ "test": "npm run make-types -workspaces --if-present"
44
+ },
45
+ "workspaces": [
46
+ "./packages/*"
47
+ ]
47
48
  }