Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion renderers/angular/postprocess-build.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ if (!packageJson.dependencies['@a2ui/web_core']) {
);
}

packageJson.dependencies['@a2ui/web_core'] = '^' + coreVersion;
packageJson.dependencies['@a2ui/web_core'] = coreVersion;

// Remove scripts and properties that should not be in the published package
delete packageJson.scripts;
Expand Down
4 changes: 2 additions & 2 deletions renderers/lit/.npmrc
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
@a2ui:registry=https://us-npm.pkg.dev/oss-exit-gate-prod/a2ui--npm/
//us-npm.pkg.dev/oss-exit-gate-prod/a2ui--npm/:always-auth=true
@a2ui:registry=https://us-npm.pkg.dev/oss-exit-gate-prod/lit--npm/
//us-npm.pkg.dev/oss-exit-gate-prod/lit--npm/:always-auth=true
2 changes: 1 addition & 1 deletion renderers/lit/prepare-publish.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ const litPkg = JSON.parse(readFileSync(litPkgPath, 'utf8'));

// 3. Update Dependency
if (litPkg.dependencies && litPkg.dependencies['@a2ui/web_core']) {
litPkg.dependencies['@a2ui/web_core'] = '^' + coreVersion;
litPkg.dependencies['@a2ui/web_core'] = coreVersion;
} else {
console.warn('Warning: @a2ui/web_core not found in dependencies.');
}
Expand Down
3 changes: 2 additions & 1 deletion renderers/markdown/markdown-it/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions renderers/markdown/markdown-it/prepare-publish.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -41,13 +41,13 @@ const pkg = JSON.parse(readFileSync(pkgPath, 'utf8'));

// 3. Update Dependency
if (pkg.peerDependencies && pkg.peerDependencies['@a2ui/web_core']) {
pkg.peerDependencies['@a2ui/web_core'] = '^' + coreVersion;
pkg.peerDependencies['@a2ui/web_core'] = coreVersion;
} else {
console.warn('Warning: @a2ui/web_core not found in peerDependencies.');
}
if (pkg.devDependencies && pkg.devDependencies['@a2ui/web_core']) {
// We can just remove devDependencies for the published package, or update it
pkg.devDependencies['@a2ui/web_core'] = '^' + coreVersion;
pkg.devDependencies['@a2ui/web_core'] = coreVersion;
}

// 4. Adjust Paths for Dist
Expand Down
2 changes: 2 additions & 0 deletions renderers/react/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@
"*.css"
],
"scripts": {
"prepublishOnly": "node -e \"if(!process.cwd().endsWith('dist')) { console.error('Error: This package must be published from the dist/ directory. Run `npm run build` then `npm publish dist/`'); process.exit(1); }\"",
"publish:package": "npm run build && node scripts/prepare-publish.mjs && npm publish dist/ --access public",
"build": "tsup && node scripts/postbuild.mjs",
"dev": "tsup --watch",
"test": "vitest run",
Expand Down
112 changes: 112 additions & 0 deletions renderers/react/scripts/prepare-publish.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
/**
* Copyright 2026 Google LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

import { readFileSync, writeFileSync, copyFileSync, mkdirSync, existsSync } from 'fs';
import { join } from 'path';

// This script prepares the React package for publishing by:
// 1. Copying package.json to dist/
// 2. Updating @a2ui/web_core dependency from 'file:...' to the actual exact version
// 3. Adjusting paths in package.json (main, types, exports) to be relative to dist/

const dirname = import.meta.dirname;
const corePkgPath = join(dirname, '../../web_core/package.json');
const pkgPath = join(dirname, '../package.json');
const distDir = join(dirname, '../dist');

if (!existsSync(distDir)) {
mkdirSync(distDir, { recursive: true });
}

// 1. Get Core Version
const corePkg = JSON.parse(readFileSync(corePkgPath, 'utf8'));
const coreVersion = corePkg.version;
if (!coreVersion) throw new Error('Cannot determine @a2ui/web_core version');

// 2. Read Package
const pkg = JSON.parse(readFileSync(pkgPath, 'utf8'));

// 3. Update Dependency
if (pkg.dependencies && pkg.dependencies['@a2ui/web_core']) {
pkg.dependencies['@a2ui/web_core'] = coreVersion;
} else {
console.warn('Warning: @a2ui/web_core not found in dependencies.');
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The PR description states that "each renderer should be pinned to a specific version of the core library". If @a2ui/web_core is a mandatory dependency for the React renderer, then its absence should prevent publication rather than just issuing a warning. Changing this to throw new Error would ensure that incomplete or incorrectly configured packages are not published.

Suggested change
} else {
console.warn('Warning: @a2ui/web_core not found in dependencies.');
throw new Error('Error: @a2ui/web_core not found in dependencies. This is a mandatory dependency for publishing.');

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lets fix this

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed.

}

// 4. Adjust Paths for Dist
pkg.main = adjustPath(pkg.main);
pkg.module = adjustPath(pkg.module);
pkg.types = adjustPath(pkg.types);

if (pkg.exports) {
for (const key in pkg.exports) {
const exp = pkg.exports[key];
if (typeof exp === 'string') {
pkg.exports[key] = adjustPath(exp);
} else {
if (exp.import) {
if (typeof exp.import === 'string') {
exp.import = adjustPath(exp.import);
} else {
if (exp.import.types) exp.import.types = adjustPath(exp.import.types);
if (exp.import.default) exp.import.default = adjustPath(exp.import.default);
}
}
if (exp.require) {
if (typeof exp.require === 'string') {
exp.require = adjustPath(exp.require);
} else {
if (exp.require.types) exp.require.types = adjustPath(exp.require.types);
if (exp.require.default) exp.require.default = adjustPath(exp.require.default);
}
}
if (exp.types) exp.types = adjustPath(exp.types);
if (exp.default) exp.default = adjustPath(exp.default);
}
}
}

// Remove properties that should not be in the published package
delete pkg.scripts;
delete pkg.files;
delete pkg.prepublishOnly;

// 5. Write to dist/package.json
writeFileSync(join(distDir, 'package.json'), JSON.stringify(pkg, null, 2));

// 6. Copy README and LICENSE
const readmeSrc = join(dirname, '../README.md');
const licenseSrc = join(dirname, '../../../LICENSE');

if (!existsSync(readmeSrc)) {
throw new Error(`Missing required file for publishing: README.md`);
}
copyFileSync(readmeSrc, join(distDir, 'README.md'));

if (!existsSync(licenseSrc)) {
throw new Error(`Missing required file for publishing: LICENSE`);
}
copyFileSync(licenseSrc, join(distDir, 'LICENSE'));

console.log(`Prepared dist/package.json with @a2ui/web_core@${coreVersion}`);

// Utility function to adjust the paths of the built files (dist/src/*) to (src/*)
function adjustPath(p) {
if (p && p.startsWith('./dist/')) {
return './' + p.substring(7); // Remove ./dist/
}
return p;
}
Loading
Loading