Skip to content
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

Add package.json auto version strategy #1052

Merged
merged 1 commit into from
Dec 12, 2024

Conversation

tzyl
Copy link
Contributor

@tzyl tzyl commented Dec 10, 2024

This PR adds a package-json auto version strategy to @osdk/cli as an alternative way of inferring a version from the git-describe strategy.

The vite plugin currently manually reads package.json version field to populate the widgets.config.json manifest. We will want to move this over to share the foundry.config.json parsing and auto version utils from @osdk/cli so that they can use the same git-describe strategy. Although we won't use the package-json strategy as the default it still makes sense to support this as a way of inferring versions.

const packageJsonFile = fs.readJSONSync(packageJsonPath);
const widgetConfigManifest: WidgetManifest = {
version: "1.0.0",
widgets: {},
};
const entrypointImports: { [chunkName: string]: string[] } = {};
// This is inspired by vite's native manifest plugin, but we only care about entrypoints
for (const file in bundle) {
const chunk = bundle[file];
if (chunk.type !== "chunk") {
continue;
}
if (chunk.isEntry && chunk.facadeModuleId != null) {
if (entrypointFileIdToConfigMap[chunk.facadeModuleId] == null) {
throw new Error(
`Could not find widget configuration object for entrypoint ${chunk.fileName}. Ensure that the default export of your imported *.${CONFIG_FILE_SUFFIX}.js file is a widget configuration object as returned by defineConfig()`,
);
}
if (
entrypointFileIdToConfigMap[chunk.facadeModuleId].type
!== "workshop"
) {
throw new Error(
`Unsupported widget type for entrypoint ${chunk.fileName}. Only "workshop" widgets are supported`,
);
}
const widgetConfig: WidgetManifestConfig = {
type: "workshopWidgetV1",
entrypointJs: [
{
path: chunk.fileName,
type: "module",
},
],
entrypointCss: chunk.viteMetadata?.importedCss.size
? [...chunk.viteMetadata.importedCss].map((css) => ({
path: css,
}))
: [],
rid: entrypointFileIdToConfigMap[chunk.facadeModuleId].rid,
version: packageJsonFile.version ?? "0.0.0",

@tzyl tzyl force-pushed the tl/auto-version-package-json-strategy branch from 199e7d2 to dbd5408 Compare December 11, 2024 11:17
@bulldozer-bot bulldozer-bot bot merged commit a39ef6a into main Dec 12, 2024
8 checks passed
@bulldozer-bot bulldozer-bot bot deleted the tl/auto-version-package-json-strategy branch December 12, 2024 10:13
ericanderson added a commit that referenced this pull request Jan 13, 2025
* origin/main:
  Add typed lint checks and fix promise related things (#1081)
  Version Packages (beta) (#1090)
  Export hydrateObjectSetFromRid from internal (#1087)
  Fetch by RID experimental (#1088)
  Creates new internal export for helper methods we want to hide (#1084)
  Add's more descriptive error messages for 429 errors and other errors with no body (#1082)
  Update react template per discussion (#1077)
  OSDK client internal property is hidden from output .d.ts (#1079)
  Revert `api:x-read/write` back to `api:read/write-x` (#1076)
  Move from "views" naming to "widgets" (#1075)
  Fixes attachment uploads in Browser context (#1064)
  Use foundry-config-json in widget-manifest-vite-plugin (#1055)
  Version Packages (beta) (#1072)
  Ignore unknown types (#1067)
  Correct widget template package dependency versions (#1068)
  Make interface type status configurable (#1069)
  Fix onOutOfDate handler from firing twice (#1071)
  Rename @osdk/widget-manifest-vite-plugin to @osdk/widget.vite-plugin.unstable (#1065)
  Fixing main (#1066)
  Add structs read support (#1047)
  Handle Vite plugin injections in Custom Widget Vite plugin (#1063)
  Version Packages (beta) (#1060)
  Fix unused import (#1061)
  Revive eslint-plugin-unused-imports (#1057)
  Fix URL for getBulkLinks (#1058)
  Split foundry-config-json package (#1054)
  Add package.json auto version strategy (#1052)
  Remove crypto from OSDK (#1051)
  Support site snapshot upload (#1049)
  Try catch subscription handlers (#1019)
  Experiment with no proxy for objects (#1031)
  Bump unstable widget packages to v1 to avoid undesired v0.x version behavior (#1050)
  WeakRef the as()'d objects (#1043)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants