-
Notifications
You must be signed in to change notification settings - Fork 123
Add Flatpak Deno generator #460
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 3 commits
Commits
Show all changes
30 commits
Select commit
Hold shift + click to select a range
705ab96
Add Flatpak Deno generator
sigmaSd 1b82dac
fix publish path
sigmaSd d72d795
better fix
sigmaSd 66b539a
document lockfile version
sigmaSd 5d3323b
Add GitHub Actions workflow for Deno CI
sigmaSd 4f207e4
Add MIT license info to README and source files
sigmaSd c714f7f
fmt
sigmaSd 1955998
dcouemnt local run
sigmaSd f9646e8
set sigmasd as deno module maintainer
sigmaSd 01b6abc
Trigger Deno workflow only on changes in deno directory
sigmaSd eae2bed
Rename Deno workflow to CI
sigmaSd 09724dc
Rename test job to deno in workflow file
sigmaSd c50fac9
Remove matrix strategy from Deno workflow
sigmaSd 91ea5cf
Remove submodules option from checkout step in CI workflow
sigmaSd 2c7713f
Add tests and refactor main function for better testability
sigmaSd e0504a3
Refactor Flatpak data types and improve README instructions
sigmaSd 07051f6
show usage when no argument is provided
sigmaSd 579fadc
Add --output option and usage examples to CLI entrypoint
sigmaSd f7ef1b2
Remove unused _urlToDenoCacheFilename function
sigmaSd c0a72ed
Clarify output file naming in usage instructions
sigmaSd 515d052
more correct typing
sigmaSd a7f234a
document technical choices
sigmaSd ff2bf48
typo
sigmaSd a04e297
Rename package to @flatpak-contrib and update version to 1.3.0
sigmaSd e6b1753
remove extra folder
sigmaSd cf1ab2a
Update deno/README.md
sigmaSd d45ba45
fmt
sigmaSd 1d23e69
Update example command to use src/main.ts path
sigmaSd eba8715
Add labeler config for deno directory
sigmaSd ca8a261
Handle peer dependencies in lockfile
sigmaSd 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,28 @@ | ||
| name: Publish | ||
| on: | ||
| push: | ||
| paths: | ||
| - deno/** | ||
| branches: | ||
| - master | ||
|
|
||
| defaults: | ||
| run: | ||
| working-directory: deno | ||
|
|
||
| jobs: | ||
| publish: | ||
| runs-on: ubuntu-latest | ||
|
|
||
| permissions: | ||
| contents: read | ||
| id-token: write | ||
|
|
||
| steps: | ||
| - uses: actions/checkout@v4 | ||
|
|
||
| - name: Setup Deno | ||
| uses: denoland/setup-deno@v2 | ||
|
|
||
| - name: Publish package | ||
| run: deno publish | ||
bbhtt marked this conversation as resolved.
Show resolved
Hide resolved
|
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,42 @@ | ||
| # Flatpak Deno Generator | ||
|
|
||
| ``` | ||
| deno -RN -W=. jsr:@flatpak/flatpak-deno-generator deno.lock | ||
| ``` | ||
|
|
||
| This will create a `deno-sources.json` that can be used in flatpak build files: | ||
|
|
||
| - it creates and populates `./deno_dir` with npm dependencies | ||
| - it creates and populates `./vendor` with jsr + http dependencies | ||
bbhtt marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| ## Usage: | ||
|
|
||
| - Use the sources file as a source, example: | ||
|
|
||
| ```yml | ||
| sources: | ||
| - deno-sources.json | ||
| ``` | ||
|
|
||
| - To use `deno_dir` point `DENO_DIR` env variable to it, like so: | ||
|
|
||
| ```yml | ||
| - name: someModule | ||
| buildsystem: simple | ||
| build-options: | ||
| env: | ||
| DENO_DIR: deno_dir | ||
| ``` | ||
|
|
||
| - To use `vendor` move it next to your `deno.json` file and make sure to compile | ||
| or run with `--vendor` flag, exmaple: | ||
|
|
||
| ```yml | ||
| - # src is where my deno project at | ||
| - mv ./vendor src/ | ||
| - DENORT_BIN=$PWD/denort ./deno compile --vendor --no-check --output virtaudio-bin --cached-only | ||
| --allow-all --include ./src/gui.slint --include ./src/client.html ./src/gui.ts | ||
| ``` | ||
|
|
||
| ## Example | ||
| - checkout https://github.com/flathub/io.github.sigmasd.VirtAudio/ | ||
bbhtt marked this conversation as resolved.
Show resolved
Hide resolved
|
||
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,6 @@ | ||
| { | ||
| "name": "@flatpak/flatpak-deno-generator", | ||
| "version": "1.2.2", | ||
| "exports": "./src/main.ts", | ||
| "license": "MIT" | ||
| } |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
bbhtt marked this conversation as resolved.
Show resolved
Hide resolved
|
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,204 @@ | ||
| import { | ||
| base64ToHex, | ||
| sha256, | ||
| shortHash, | ||
| shouldHash, | ||
| splitOnce, | ||
| urlSegments, | ||
| } from "./utils.ts"; | ||
|
|
||
| interface Pkg { | ||
| module: string; | ||
| version: string; | ||
| name: string; | ||
| cpu?: "x86_64" | "aarch64"; | ||
bbhtt marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| } | ||
|
|
||
| async function jsrPkgToFlatpakData(pkg: Pkg) { | ||
| const flatpkData = []; | ||
| const metaUrl = `https://jsr.io/${pkg.module}/meta.json`; | ||
bbhtt marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| const metaText = await fetch( | ||
| metaUrl, | ||
| ).then((r) => r.text()); | ||
|
|
||
| flatpkData.push({ | ||
| type: "file", | ||
| url: metaUrl, | ||
| sha256: await sha256(metaText), | ||
| dest: `vendor/jsr.io/${pkg.module}`, | ||
| "dest-filename": "meta.json", | ||
| }); | ||
|
|
||
| const metaVerUrl = `https://jsr.io/${pkg.module}/${pkg.version}_meta.json`; | ||
| const metaVerText = await fetch( | ||
| metaVerUrl, | ||
| ).then((r) => r.text()); | ||
|
|
||
| flatpkData.push({ | ||
| type: "file", | ||
| url: metaVerUrl, | ||
| sha256: await sha256(metaVerText), | ||
| dest: `vendor/jsr.io/${pkg.module}`, | ||
| "dest-filename": `${pkg.version}_meta.json`, | ||
| }); | ||
|
|
||
| const metaVer = JSON.parse(metaVerText); | ||
|
|
||
| for ( | ||
| const fileUrl of Object.keys(metaVer.moduleGraph2 || metaVer.moduleGraph1) | ||
| ) { | ||
| const fileMeta = metaVer.manifest[fileUrl]; | ||
| // this mean the url exists in the module graph but not in the manifest -> this url is not needed | ||
| if (!fileMeta) continue; | ||
| const [checksumType, checksumValue] = splitOnce(fileMeta.checksum, "-"); | ||
|
|
||
| const url = `https://jsr.io/${pkg.module}/${pkg.version}${fileUrl}`; | ||
| let [fileDir, fileName] = splitOnce(fileUrl, "/", "right"); | ||
| const dest = `vendor/jsr.io/${pkg.module}/${pkg.version}${fileDir}`; | ||
|
|
||
| if (shouldHash(fileName)) { | ||
| fileName = await shortHash(fileName); | ||
| } | ||
|
|
||
| flatpkData.push({ | ||
| type: "file", | ||
| url, | ||
| [checksumType]: checksumValue, | ||
| dest, | ||
| "dest-filename": fileName, | ||
| }); | ||
| } | ||
|
|
||
| // If a moule imports deno.json (import ... from "deno.json" with {type:"json"}), it won't appear in the module graph | ||
| // Worarkound: if there is a deno.json file in the manifest just add it | ||
| // Note this can be made better, by looking in the moduleGraph if deno.json is specified in the dependencies | ||
| for (const [fileUrl, fileMeta] of Object.entries(metaVer.manifest)) { | ||
| if (fileUrl.includes("deno.json")) { | ||
| const [checksumType, checksumValue] = splitOnce( | ||
| // deno-lint-ignore no-explicit-any | ||
| (fileMeta as any).checksum, | ||
| "-", | ||
| ); | ||
| const url = `https://jsr.io/${pkg.module}/${pkg.version}${fileUrl}`; | ||
| const [fileDir, fileName] = splitOnce(fileUrl, "/", "right"); | ||
| const dest = `vendor/jsr.io/${pkg.module}/${pkg.version}${fileDir}`; | ||
| flatpkData.push({ | ||
| type: "file", | ||
| url, | ||
| [checksumType]: checksumValue, | ||
| dest, | ||
| "dest-filename": fileName, | ||
| }); | ||
| } | ||
| } | ||
|
|
||
| return flatpkData; | ||
| } | ||
|
|
||
| async function npmPkgToFlatpakData(pkg: Pkg) { | ||
| //url: https://registry.npmjs.org/@napi-rs/cli/-/cli-2.18.4.tgz | ||
| //npmPkgs; | ||
| const metaUrl = `https://registry.npmjs.org/${pkg.module}`; | ||
| const metaText = await fetch(metaUrl).then( | ||
| (r) => r.text(), | ||
| ); | ||
| const meta = JSON.parse(metaText); | ||
|
|
||
| const metaData = { | ||
| type: "file", | ||
| url: metaUrl, | ||
| sha256: await sha256(metaText), | ||
| dest: `deno_dir/npm/registry.npmjs.org/${pkg.module}`, | ||
| "dest-filename": "registry.json", | ||
| }; | ||
|
|
||
| const [checksumType, checksumValue] = splitOnce( | ||
| meta.versions[pkg.version].dist.integrity, | ||
| "-", | ||
| ); | ||
| const pkgData: Record<string, unknown> = { | ||
| type: "archive", | ||
| "archive-type": "tar-gzip", | ||
| url: | ||
| `https://registry.npmjs.org/${pkg.module}/-/${pkg.name}-${pkg.version}.tgz`, | ||
| [checksumType]: base64ToHex(checksumValue), | ||
| dest: `deno_dir/npm/registry.npmjs.org/${pkg.module}/${pkg.version}`, | ||
| }; | ||
|
|
||
| if (pkg.cpu) { | ||
| pkgData["only-arches"] = [pkg.cpu]; | ||
| } | ||
|
|
||
| return [metaData, pkgData]; | ||
| } | ||
|
|
||
| if (import.meta.main) { | ||
| const arg = Deno.args[0]; | ||
| if (!arg) { | ||
| console.error("No argument provided"); | ||
| Deno.exit(1); | ||
| } | ||
|
|
||
| const lock = JSON.parse(Deno.readTextFileSync(arg)); | ||
| if (lock.version !== "5") { | ||
| throw new Error(`Unsupported deno lock version: ${lock.version}`); | ||
| } | ||
bbhtt marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| const jsrPkgs: Pkg[] = !lock.jsr ? [] : Object.keys(lock.jsr).map((pkg) => { | ||
| const r = splitOnce(pkg, "@", "right"); | ||
| const name = r[0].split("/")[1]; | ||
| return { module: r[0], version: r[1], name }; | ||
| }); | ||
| jsrPkgs; | ||
| const npmPkgs: Pkg[] = !lock.npm ? [] : Object.entries(lock.npm) | ||
| .filter(( | ||
| // deno-lint-ignore no-explicit-any | ||
| [_key, val]: any, | ||
| ) => (val.os === undefined || val.os?.at(0) === "linux")) | ||
| // deno-lint-ignore no-explicit-any | ||
| .map(([key, val]: any) => { | ||
| const r = splitOnce(key, "@", "right"); | ||
| const name = r[0].includes("/") ? r[0].split("/")[1] : r[0]; | ||
| const cpu = val.cpu?.at(0); | ||
| return { | ||
| module: r[0], | ||
| version: r[1], | ||
| name, | ||
| cpu: cpu === "x64" ? "x86_64" : cpu === "arm64" ? "aarch64" : cpu, | ||
| }; | ||
| }); | ||
| //url: https://registry.npmjs.org/@napi-rs/cli/-/cli-2.18.4.tgz | ||
| npmPkgs; | ||
| const httpPkgsData = !lock.remote | ||
| ? [] | ||
| : Object.entries(lock.remote).map(async ([urlStr, checksum]) => { | ||
| const url = new URL(urlStr); | ||
| const segments = await Promise.all( | ||
| urlSegments(url) | ||
| .map(async (part) => shouldHash(part) ? await shortHash(part) : part), | ||
| ); | ||
| const filename = segments.pop(); | ||
| return { | ||
| type: "file", | ||
| url: urlStr, | ||
| sha256: checksum, | ||
| dest: `vendor/${url.hostname}/${segments.join("/")}`, | ||
| "dest-filename": filename, | ||
| }; | ||
| }); | ||
|
|
||
| const flatpakData = [ | ||
| await Promise.all( | ||
| jsrPkgs.map((pkg) => jsrPkgToFlatpakData(pkg)), | ||
| ).then((r) => r.flat()), | ||
| await Promise.all(npmPkgs.map((pkg) => npmPkgToFlatpakData(pkg))).then( | ||
| (r) => r.flat(), | ||
| ), | ||
| await Promise.all(httpPkgsData), | ||
| ].flat(); | ||
| // console.log(flatpakData); | ||
| Deno.writeTextFileSync( | ||
| "deno-sources.json", | ||
| JSON.stringify(flatpakData, null, 2), | ||
| ); | ||
| } | ||
Oops, something went wrong.
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.