-
-
Notifications
You must be signed in to change notification settings - Fork 275
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: sink native-federation-typescript capability into dts-kit
- Loading branch information
Showing
32 changed files
with
443 additions
and
77 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
{ | ||
"parser": "@typescript-eslint/parser", | ||
"plugins": ["@typescript-eslint", "simple-import-sort"], | ||
"extends": [ | ||
"../../.eslintrc.json", | ||
"eslint:recommended", | ||
"plugin:@typescript-eslint/eslint-recommended", | ||
"plugin:@typescript-eslint/recommended" | ||
], | ||
"ignorePatterns": ["!**/*"], | ||
"rules": { | ||
"@typescript-eslint/explicit-module-boundary-types": 0, | ||
"@typescript-eslint/camelcase": 0, | ||
"@typescript-eslint/no-var-requires": 0, | ||
"@typescript-eslint/no-unused-vars": "error", | ||
"@typescript-eslint/no-non-null-assertion": 0, | ||
"@typescript-eslint/no-explicit-any": "off" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
# @module-federation/dts-kit |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
MIT License | ||
|
||
Copyright (c) 2022 Matteo Pietro Dazzi and NearForm Limited | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
SOFTWARE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
# @module-federation/dts-kit |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
{ | ||
"name": "@module-federation/dts-kit", | ||
"version": "0.3.1", | ||
"description": "Bundler federated types", | ||
"keywords": [ | ||
"module federation", | ||
"typescript", | ||
"remote types", | ||
"federated types" | ||
], | ||
"files": [ | ||
"dist/", | ||
"README.md" | ||
], | ||
"publishConfig": { | ||
"access": "public" | ||
}, | ||
"exports": { | ||
".": { | ||
"import": "./dist/index.mjs", | ||
"require": "./dist/index.js", | ||
"types": "./dist/index.d.ts" | ||
} | ||
}, | ||
"main": "./dist/index.js", | ||
"types": "./dist/index.d.ts", | ||
"author": "Matteo Pietro Dazzi <[email protected]> (https://github.com/ilteoood)", | ||
"license": "MIT", | ||
"dependencies": { | ||
"adm-zip": "^0.5.10", | ||
"ansi-colors": "^4.1.3", | ||
"axios": "^1.6.7", | ||
"rambda": "^9.1.0" | ||
}, | ||
"peerDependencies": { | ||
"typescript": "^4.9.0 || ^5.0.0", | ||
"vue-tsc": "^1.0.24" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
{ | ||
"name": "dts-kit", | ||
"$schema": "../../node_modules/nx/schemas/project-schema.json", | ||
"sourceRoot": "packages/dts-kit/src", | ||
"projectType": "library", | ||
"targets": { | ||
"build": { | ||
"executor": "nx:run-commands", | ||
"outputs": ["{workspaceRoot}/packages/dts-kit/dist"], | ||
"options": { | ||
"parallel": false, | ||
"commands": [ | ||
"tsup --config packages/dts-kit/tsup.config.ts", | ||
"cp packages/dts-kit/package.json packages/dts-kit/dist", | ||
"cp packages/dts-kit/*.md packages/dts-kit/dist" | ||
] | ||
} | ||
}, | ||
"lint": { | ||
"executor": "@nx/linter:eslint", | ||
"outputs": ["{options.outputFile}"], | ||
"options": { | ||
"lintFilePatterns": ["packages/dts-kit/**/*.ts"] | ||
} | ||
}, | ||
"test": { | ||
"executor": "@nx/vite:test", | ||
"outputs": ["{workspaceRoot}/coverage/packages/dts-kit"] | ||
}, | ||
"pre-release": { | ||
"executor": "nx:run-commands", | ||
"options": { | ||
"parallel": false, | ||
"commands": [ | ||
{ | ||
"command": "nx run dts-kit:test", | ||
"forwardAllArgs": false | ||
}, | ||
{ | ||
"command": "nx run dts-kit:build", | ||
"forwardAllArgs": false | ||
} | ||
] | ||
} | ||
}, | ||
"semantic-release": { | ||
"executor": "@goestav/nx-semantic-release:semantic-release" | ||
} | ||
}, | ||
"tags": ["package"], | ||
"implicitDependencies": [] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
export { retrieveRemoteConfig } from './configurations/remotePlugin'; | ||
export { retrieveHostConfig } from './configurations/hostPlugin'; | ||
export { getDTSManagerConstructor } from './lib/utils'; | ||
export { retrieveOriginalOutDir } from './lib/typeScriptCompiler'; | ||
export { DTSManager } from './lib/DTSManager'; | ||
|
||
export { DTSManagerOptions } from './interfaces/DTSManagerOptions'; | ||
export { HostOptions } from './interfaces/HostOptions'; | ||
export { RemoteOptions } from './interfaces/RemoteOptions'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
import { HostOptions } from './HostOptions'; | ||
import { RemoteOptions } from './RemoteOptions'; | ||
|
||
export interface DTSManagerOptions { | ||
remote?: RemoteOptions; | ||
host?: HostOptions; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
import ansiColors from 'ansi-colors'; | ||
import { rm } from 'fs/promises'; | ||
import { retrieveRemoteConfig } from '../configurations/remotePlugin'; | ||
import { createTypesArchive, downloadTypesArchive } from './archiveHandler'; | ||
import { compileTs, retrieveMfTypesPath } from './typeScriptCompiler'; | ||
import { retrieveHostConfig } from '../configurations/hostPlugin'; | ||
import { DTSManagerOptions } from '../interfaces/DTSManagerOptions'; | ||
|
||
class DTSManager { | ||
options: DTSManagerOptions; | ||
|
||
constructor(options: DTSManagerOptions) { | ||
this.options = options; | ||
} | ||
|
||
async generateTypes() { | ||
try { | ||
const { options } = this; | ||
if (!options.remote) { | ||
throw new Error( | ||
'options.remote is required if you want to generateTypes', | ||
); | ||
} | ||
const { remoteOptions, tsConfig, mapComponentsToExpose } = | ||
retrieveRemoteConfig(options.remote); | ||
compileTs(mapComponentsToExpose, tsConfig, remoteOptions); | ||
|
||
await createTypesArchive(tsConfig, remoteOptions); | ||
|
||
if (remoteOptions.deleteTypesFolder) { | ||
await rm(retrieveMfTypesPath(tsConfig, remoteOptions), { | ||
recursive: true, | ||
force: true, | ||
}); | ||
} | ||
console.log(ansiColors.green('Federated types created correctly')); | ||
} catch (error) { | ||
console.error( | ||
ansiColors.red(`Unable to compile federated types, ${error}`), | ||
); | ||
} | ||
} | ||
|
||
async consumeTypes() { | ||
const { options } = this; | ||
if (!options.host) { | ||
throw new Error('options.host is required if you want to consumeTypes'); | ||
} | ||
const { hostOptions, mapRemotesToDownload } = retrieveHostConfig( | ||
options.host, | ||
); | ||
|
||
if (hostOptions.deleteTypesFolder) { | ||
await rm(hostOptions.typesFolder, { | ||
recursive: true, | ||
force: true, | ||
}).catch((error) => | ||
console.error( | ||
ansiColors.red(`Unable to remove types folder, ${error}`), | ||
), | ||
); | ||
} | ||
|
||
const typesDownloader = downloadTypesArchive(hostOptions); | ||
const downloadPromises = | ||
Object.entries(mapRemotesToDownload).map(typesDownloader); | ||
|
||
await Promise.allSettled(downloadPromises); | ||
console.log(ansiColors.green('Federated types extraction completed')); | ||
} | ||
} | ||
|
||
export { DTSManager }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
import { DTSManager } from './DTSManager'; | ||
|
||
export function getDTSManagerConstructor( | ||
implementation?: string, | ||
): typeof DTSManager { | ||
return implementation ? require(implementation) : DTSManager; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
{ | ||
"compilerOptions": { | ||
"target": "es2017", | ||
"module": "esnext", | ||
"lib": ["esnext"], | ||
"moduleResolution": "node", | ||
"esModuleInterop": true, | ||
"strict": true, | ||
"strictNullChecks": true, | ||
"resolveJsonModule": true | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
{ | ||
"extends": "./tsconfig.json", | ||
"compilerOptions": { | ||
"outDir": "../../dist/out-tsc", | ||
"declaration": true, | ||
"skipLibCheck": true, | ||
"types": [] | ||
}, | ||
"include": ["**/*.ts"], | ||
"exclude": [ | ||
"jest.config.ts", | ||
"**/*.spec.ts", | ||
"**/*.test.ts", | ||
"tsup.config.ts" | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
{ | ||
"extends": "./tsconfig.json", | ||
"compilerOptions": { | ||
"outDir": "../../dist/out-tsc", | ||
"types": ["vitest/globals", "vitest/importMeta", "vite/client", "node"] | ||
}, | ||
"include": [ | ||
"vite.config.ts", | ||
"src/**/*.test.ts", | ||
"src/**/*.spec.ts", | ||
"src/**/*.test.tsx", | ||
"src/**/*.spec.tsx", | ||
"src/**/*.test.js", | ||
"src/**/*.spec.js", | ||
"src/**/*.test.jsx", | ||
"src/**/*.spec.jsx", | ||
"src/**/*.d.ts" | ||
] | ||
} |
Oops, something went wrong.