Lite version (#7647)

* fix user links

* add gradio as dependency to lite

* tweak

* fiiiiix

* fix deps

* changes

* asd

* asd

* asd

* asd

* fixed

* asd

* asd

* asd

* asd

* asd

* asd

* asd

* fgh

* asd

* asd

* asd

* asd

* add changeset

* prevent duplicate dependency entries

* Update .changeset/changeset.cjs

---------

Co-authored-by: gradio-pr-bot <gradio-pr-bot@users.noreply.github.com>
Co-authored-by: Abubakar Abid <abubakar@huggingface.co>
This commit is contained in:
pngwn 2024-03-08 22:56:34 +00:00 committed by GitHub
parent d0688b3c25
commit 57510f9ce0
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 113 additions and 22 deletions

View File

@ -1,10 +1,17 @@
const { getPackagesSync } = require("@manypkg/get-packages");
const dependents_graph = require("@changesets/get-dependents-graph");
const gh = require("@changesets/get-github-info");
const { existsSync, readFileSync, writeFileSync } = require("fs");
const { join } = require("path");
const { getInfo, getInfoFromPullRequest } = gh;
const { packages, rootDir } = getPackagesSync(process.cwd());
const pkg_data = getPackagesSync(process.cwd());
const { packages, rootDir } = pkg_data;
const dependents = dependents_graph.getDependentsGraph({
packages,
root: pkg_data.rootPackage
});
/**
* @typedef {{packageJson: {name: string, python?: boolean}, dir: string}} Package
@ -34,6 +41,10 @@ function find_packages_dirs(package_name) {
return package_dirs;
}
let lines = {
_handled: []
};
const changelogFunctions = {
/**
*
@ -76,7 +87,53 @@ const changelogFunctions = {
* @param {any} dependency The dependency that has been updated
* @returns {string} The formatted dependency
*/
(dependency) => ` - ${dependency.name}@${dependency.newVersion}`
(dependency) => {
const updates = dependents.get(dependency.name);
if (updates && updates.length > 0) {
updates.forEach((update) => {
if (!lines[update]) {
lines[update] = {
dirs: find_packages_dirs(update),
current_changelog: "",
feat: [],
fix: [],
highlight: [],
previous_version: packages.find(
(p) => p.packageJson.name === update
).packageJson.version,
dependencies: []
};
const changelog_path = join(
//@ts-ignore
lines[update].dirs[1] || lines[update].dirs[0],
"CHANGELOG.md"
);
if (existsSync(changelog_path)) {
//@ts-ignore
lines[update].current_changelog = readFileSync(
changelog_path,
"utf-8"
)
.replace(`# ${update}`, "")
.trim();
}
}
lines[update].dependencies.push(
` - ${dependency.name}@${dependency.newVersion}`
);
});
}
return ` - ${dependency.name}@${dependency.newVersion}`;
}
);
writeFileSync(
join(rootDir, ".changeset", "_changelog.json"),
JSON.stringify(lines, null, 2)
);
return [changesetLink, ...updatedDepenenciesList].join("\n");
@ -151,11 +208,14 @@ const changelogFunctions = {
};
})();
const user_link = /\[(@[^]+)\]/.exec(links.user);
const users =
usersFromSummary && usersFromSummary.length
? usersFromSummary
.map((userFromSummary) => `@${userFromSummary}`)
.join(", ")
: user_link
? user_link[1]
: links.user;
const prefix = [
@ -174,16 +234,6 @@ const changelogFunctions = {
/**
* @type { ChangesetMeta & { _handled: string[] } }}
*/
let lines;
if (existsSync(join(rootDir, ".changeset", "_changelog.json"))) {
lines = JSON.parse(
readFileSync(join(rootDir, ".changeset", "_changelog.json"), "utf-8")
);
} else {
lines = {
_handled: []
};
}
if (lines._handled.includes(changeset.id)) {
return "done";
@ -191,14 +241,19 @@ const changelogFunctions = {
lines._handled.push(changeset.id);
changeset.releases.forEach((release) => {
if (!lines[release.name])
if (!lines[release.name]) {
lines[release.name] = {
dirs: find_packages_dirs(release.name),
current_changelog: "",
feat: [],
fix: [],
highlight: []
highlight: [],
previous_version: packages.find(
(p) => p.packageJson.name === release.name
).packageJson.version,
dependencies: []
};
}
const changelog_path = join(
//@ts-ignore

View File

@ -44,19 +44,46 @@ function run() {
}, /** @type {{[key:string] : PackageMeta}} */ ({}));
for (const pkg_name in packages) {
const { dirs, highlight, feat, fix, current_changelog } =
const { dirs, highlight, feat, fix, current_changelog, dependencies } =
/**@type {ChangesetMeta} */ (packages[pkg_name]);
if (pkg_name === "@gradio/lite") {
const target = all_packages.gradio.packageJson.version.split(".");
const current_version = packages[pkg_name].previous_version.split(".");
if (!packages.gradio) {
const patch = parseInt(current_version[2]) + 1;
const new_version = [target[0], target[1], patch];
all_packages[pkg_name].packageJson.version = new_version.join(".");
} else {
if (parseInt(target[1]) > parseInt(current_version[1])) {
all_packages[pkg_name].packageJson.version = target.join(".");
} else if (parseInt(target[1]) === parseInt(current_version[1])) {
const patch = parseInt(current_version[2]) + 1;
const new_version = [target[0], target[1], patch];
all_packages[pkg_name].packageJson.version = new_version.join(".");
}
}
writeFileSync(
join(all_packages[pkg_name].dir, "package.json"),
JSON.stringify(all_packages[pkg_name].packageJson, null, "\t")
);
}
const { version, python } = all_packages[pkg_name].packageJson;
const highlights = highlight.map((h) => `${h.summary}`);
const features = feat.map((f) => `- ${f.summary}`);
const fixes = fix.map((f) => `- ${f.summary}`);
const highlights = highlight?.map((h) => `${h.summary}`) || [];
const features = feat?.map((f) => `- ${f.summary}`) || [];
const fixes = fix?.map((f) => `- ${f.summary}`) || [];
const deps = Array.from(new Set(dependencies?.map((d) => d.trim()))) || [];
const release_notes = /** @type {[string[], string][]} */ ([
[highlights, "### Highlights"],
[features, "### Features"],
[fixes, "### Fixes"]
[fixes, "### Fixes"],
[deps, "### Dependency updates"]
])
.filter(([s], i) => s.length > 0)
.map(([lines, title]) => {

View File

@ -0,0 +1,5 @@
---
"@gradio/lite": patch
---
feat:Lite version

View File

@ -12,6 +12,9 @@
"scripts": {
"build": "pnpm --filter @gradio/app build:lite"
},
"dependencies": {
"gradio": "workspace:^"
},
"devDependencies": {
"@gradio/app": "workspace:^",
"@gradio/wasm": "workspace:^",

View File

@ -1109,6 +1109,10 @@ importers:
version: link:../utils
js/lite:
dependencies:
gradio:
specifier: workspace:^
version: link:../../gradio
devDependencies:
'@gradio/app':
specifier: workspace:^
@ -1116,9 +1120,6 @@ importers:
'@gradio/wasm':
specifier: workspace:^
version: link:../wasm
gradio:
specifier: workspace:^
version: link:../../gradio
js/markdown:
dependencies: