-
Notifications
You must be signed in to change notification settings - Fork 617
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #10130 from vojtechszocs/rework-sdk-npm-pkg
Bug 2002362: Rework dynamic plugin SDK dist packages
- Loading branch information
Showing
26 changed files
with
650 additions
and
103 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
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
Large diffs are not rendered by default.
Oops, something went wrong.
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 |
---|---|---|
@@ -1 +1 @@ | ||
/schema | ||
/generated |
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,10 @@ | ||
#!/usr/bin/env bash | ||
|
||
set -exuo pipefail | ||
|
||
yarn build | ||
|
||
for pkgDir in 'dist/core' 'dist/internal' 'dist/webpack' | ||
do | ||
yarn publish "$pkgDir" --no-git-tag-version --new-version "$PKG_VERSION" | ||
done |
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
114 changes: 114 additions & 0 deletions
114
frontend/packages/console-dynamic-plugin-sdk/scripts/package-definitions.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,114 @@ | ||
import * as _ from 'lodash'; | ||
import * as readPkg from 'read-pkg'; | ||
import { getSharedPluginModules } from '../src/shared-modules'; | ||
|
||
type GeneratedPackage = { | ||
/** Package output directory. */ | ||
outDir: string; | ||
/** Package manifest. Note: `version` is updated via the publish script. */ | ||
manifest: readPkg.PackageJson; | ||
/** Additional files to copy to the package output directory. */ | ||
filesToCopy: Record<any, string>; | ||
}; | ||
|
||
type MissingDependencyCallback = (name: string) => void; | ||
|
||
type GetPackageDefinition = ( | ||
sdkPackage: readPkg.PackageJson, | ||
rootPackage: readPkg.PackageJson, | ||
missingDepCallback: MissingDependencyCallback, | ||
) => GeneratedPackage; | ||
|
||
const commonManifestFields: Partial<readPkg.PackageJson> = { | ||
license: 'Apache-2.0', | ||
homepage: | ||
'https://github.com/openshift/console/tree/master/frontend/packages/console-dynamic-plugin-sdk', | ||
}; | ||
|
||
const commonFiles: GeneratedPackage['filesToCopy'] = { | ||
'../../../LICENSE': 'LICENSE', | ||
}; | ||
|
||
const parseDeps = ( | ||
pkg: readPkg.PackageJson, | ||
depNames: string[], | ||
missingDepCallback: MissingDependencyCallback, | ||
) => { | ||
const srcDeps = { ...pkg.devDependencies, ...pkg.dependencies }; | ||
depNames.filter((name) => !srcDeps[name]).forEach(missingDepCallback); | ||
return _.pick(srcDeps, depNames); | ||
}; | ||
|
||
const parseDepsAs = ( | ||
pkg: readPkg.PackageJson, | ||
deps: { [depName: string]: string }, | ||
missingDepCallback: MissingDependencyCallback, | ||
) => _.mapKeys(parseDeps(pkg, Object.keys(deps), missingDepCallback), (value, key) => deps[key]); | ||
|
||
export const getCorePackage: GetPackageDefinition = ( | ||
sdkPackage, | ||
rootPackage, | ||
missingDepCallback, | ||
) => ({ | ||
outDir: 'dist/core', | ||
manifest: { | ||
name: '@openshift-console/dynamic-plugin-sdk', | ||
version: sdkPackage.version, | ||
type: 'module', | ||
main: 'lib/lib-core.js', | ||
...commonManifestFields, | ||
dependencies: parseDeps(rootPackage, getSharedPluginModules(false), missingDepCallback), | ||
}, | ||
filesToCopy: { | ||
...commonFiles, | ||
'README.md': 'README.md', | ||
'generated/doc': 'doc', | ||
}, | ||
}); | ||
|
||
export const getInternalPackage: GetPackageDefinition = ( | ||
sdkPackage, | ||
rootPackage, | ||
missingDepCallback, | ||
) => ({ | ||
outDir: 'dist/internal', | ||
manifest: { | ||
name: '@openshift-console/dynamic-plugin-sdk-internal', | ||
version: sdkPackage.version, | ||
type: 'module', | ||
main: 'lib/lib-internal.js', | ||
...commonManifestFields, | ||
dependencies: getCorePackage(sdkPackage, rootPackage, missingDepCallback).manifest.dependencies, | ||
}, | ||
filesToCopy: { | ||
...commonFiles, | ||
}, | ||
}); | ||
|
||
export const getWebpackPackage: GetPackageDefinition = ( | ||
sdkPackage, | ||
rootPackage, | ||
missingDepCallback, | ||
) => ({ | ||
outDir: 'dist/webpack', | ||
manifest: { | ||
name: '@openshift-console/dynamic-plugin-sdk-webpack', | ||
version: sdkPackage.version, | ||
type: 'commonjs', | ||
main: 'lib/lib-webpack.js', | ||
...commonManifestFields, | ||
dependencies: { | ||
...parseDeps(sdkPackage, ['webpack'], missingDepCallback), | ||
...parseDeps( | ||
rootPackage, | ||
['ajv', 'chalk', 'comment-json', 'find-up', 'read-pkg', 'semver'], | ||
missingDepCallback, | ||
), | ||
...parseDepsAs(rootPackage, { 'lodash-es': 'lodash' }, missingDepCallback), | ||
}, | ||
}, | ||
filesToCopy: { | ||
...commonFiles, | ||
'generated/schema': 'schema', | ||
}, | ||
}); |
File renamed without changes.
1 change: 1 addition & 0 deletions
1
frontend/packages/console-dynamic-plugin-sdk/src/lib-internal.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 @@ | ||
export * from './api/internal-api'; |
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
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
24 changes: 24 additions & 0 deletions
24
frontend/packages/console-dynamic-plugin-sdk/src/shared-modules-override.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,24 @@ | ||
/* eslint-disable global-require */ | ||
/* eslint-disable @typescript-eslint/no-require-imports */ | ||
|
||
import { RemoteEntryModule } from './types'; | ||
|
||
/** | ||
* At runtime, Console will override (i.e. enforce Console-bundled implementation of) shared | ||
* modules for each dynamic plugin, before loading any of the modules exposed by that plugin. | ||
* | ||
* This way, a single version of React etc. is used by Console application and its plugins. | ||
*/ | ||
export const overrideSharedModules = (entryModule: RemoteEntryModule) => { | ||
entryModule.override({ | ||
'@openshift-console/dynamic-plugin-sdk': async () => () => | ||
require('@console/dynamic-plugin-sdk/src/lib-core'), | ||
'@openshift-console/dynamic-plugin-sdk-internal': async () => () => | ||
require('@console/dynamic-plugin-sdk/src/lib-internal'), | ||
react: async () => () => require('react'), | ||
'react-helmet': async () => () => require('react-helmet'), | ||
'react-i18next': async () => () => require('react-i18next'), | ||
'react-router': async () => () => require('react-router'), | ||
'react-router-dom': async () => () => require('react-router-dom'), | ||
}); | ||
}; |
Oops, something went wrong.