-
Notifications
You must be signed in to change notification settings - Fork 375
feat(infrastructure): Added ability import components directly to support fed modules tree-shaking of shared packages. #8832
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
7ba8ae8
feat(infrastructure): Added ability import components directly to sup…
dlabaj 9a2c421
Updated code to take a configuration file to generate packages.
dlabaj 5d31708
Fixed issue with not using root.
dlabaj 4322717
Fixed typo
dlabaj eead8ce
Updated with changes from main.
dlabaj 1d74ec2
Updated with reveiew comments.
dlabaj bcb78b2
Fixed logic issue.
dlabaj 98bbf56
Comment updates.
dlabaj fe0fbf2
Comment updates.
dlabaj b7654c2
Updated with review comments.
dlabaj File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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,17 @@ | ||
| { | ||
| "packageName": "@patternfly/react-charts", | ||
| "modules": [ | ||
| { | ||
| "name": "dist/esm", | ||
| "type": "esm" | ||
| }, | ||
| { | ||
| "name": "dist/js", | ||
| "type": "cjs" | ||
| } | ||
| ], | ||
| "exclude": [ | ||
| "dist/esm/deprecated/index.js", | ||
| "dist/esm/next/index.js" | ||
| ] | ||
| } |
This file contains hidden or 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 hidden or 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,14 @@ | ||
| { | ||
| "packageName": "@patternfly/react-core", | ||
| "modules": [ | ||
| { | ||
| "name": "dist/esm", | ||
| "type": "esm" | ||
| }, | ||
| { | ||
| "name": "dist/js", | ||
| "type": "cjs" | ||
| } | ||
| ], | ||
| "exclude": [] | ||
| } |
This file contains hidden or 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 hidden or 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 @@ | ||
| { | ||
| "packageName": "@patternfly/react-table", | ||
| "modules": [ | ||
| { | ||
| "name": "components", | ||
| "type": "esm" | ||
| }, | ||
| { | ||
| "name": "deprecated", | ||
| "type": "esm" | ||
| }, | ||
| { | ||
| "name": "dist/js", | ||
| "type": "cjs" | ||
| } | ||
| ], | ||
| "exclude": [ | ||
| "dist/esm/deprecated/index.js", | ||
| "dist/esm/next/index.js" | ||
| ] | ||
| } |
This file contains hidden or 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,81 @@ | ||
| /* eslint-disable no-console */ | ||
| const fse = require('fs-extra'); | ||
| const glob = require('glob'); | ||
|
|
||
| const root = process.cwd(); | ||
| const packageJson = require(`${root}/package.json`); | ||
|
|
||
| if (!(process.argv.includes('--config') && process.argv.indexOf('--config') + 1 < process.argv.length)) { | ||
| console.log('--config is required followed by the config file name'); | ||
| process.exit(1); | ||
| } | ||
|
|
||
| const configJson = require(`${root}/${process.argv[process.argv.indexOf('--config') + 1]}`); | ||
|
|
||
| const foldersexclude = configJson.exclude ? configJson.exclude : [] | ||
|
|
||
| if (!configJson.modules || configJson.modules.length === 0) { | ||
| console.log('modules are required'); | ||
| process.exit(1); | ||
| } | ||
|
|
||
| const components = configJson.modules.map(module => ({ | ||
| files: glob | ||
| .sync(`${root}/${module.name}/**/**/index.js`) | ||
| .filter((item) => !foldersexclude.some((name) => item.includes(name))) | ||
| .map((name) => name.replace(/\/$/, '')), | ||
| type: module.type | ||
| })); | ||
|
|
||
| async function createPackage(component, dist) { | ||
| const cmds = []; | ||
| const destFile = component.replace(/index.js/g, 'package.json'); | ||
| const pathAsArray = component.split('/'); | ||
| const esmRelative = `.${component.split(`${root}`)[1]}`; | ||
|
|
||
| const packageName = configJson.packageName; | ||
| if (!packageName) { | ||
| console.log("packageName is required!") | ||
| process.exit(1); | ||
| } | ||
|
|
||
| let componentName = pathAsArray[pathAsArray.length - 2]; | ||
| if (pathAsArray.includes("next")) { | ||
| componentName = `${componentName.toLowerCase()}-next-${dist}`; | ||
| } else if (pathAsArray.includes("deprecated")) { | ||
| componentName = `${componentName.toLowerCase()}-deprecated-${dist}`; | ||
| } else { | ||
| componentName = `${componentName.toLowerCase()}-${dist}`; | ||
| } | ||
|
|
||
| const content = { | ||
| name: `${packageName}-${componentName}`, | ||
| main: 'index.js', | ||
| module: esmRelative, | ||
| typings: 'index.d.ts', | ||
| version: packageJson.version | ||
| }; | ||
|
|
||
| cmds.push(fse.writeJSON(destFile, content)); | ||
|
|
||
| return Promise.all(cmds); | ||
| } | ||
|
|
||
| async function generatePackages(components, dist) { | ||
| const cmds = components.map((component) => createPackage(component, dist)); | ||
| return Promise.all(cmds); | ||
| } | ||
|
|
||
| async function run(components, dist) { | ||
| try { | ||
| await generatePackages(components, dist); | ||
| } catch (error) { | ||
| console.log(error) | ||
| process.exit(1); | ||
| } | ||
| } | ||
|
|
||
| components.forEach(component => { | ||
| run(component.files, component.type); | ||
| }); | ||
|
|
||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.