Skip to content

Commit

Permalink
chore: migrate to bun
Browse files Browse the repository at this point in the history
  • Loading branch information
morlay committed Nov 9, 2023
1 parent 487ffae commit d90ff3e
Show file tree
Hide file tree
Showing 30 changed files with 255 additions and 6,301 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ jobs:
- uses: docker/setup-qemu-action@v2
- run: curl -sSLf https://raw.githubusercontent.com/octohelm/wagon/main/install.sh | sudo sh

- run: gst
- run: make build.webapp
- run: make ship
- run: make archive

Expand Down
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
MIT License

Copyright (c) 2020 cuemod
Copyright (c) 2023 octohelm

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
30 changes: 16 additions & 14 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -108,35 +108,39 @@ install.demo:
remote.debug: k.export remote.sync remote.ctr.import

remote.sync:
scp .tmp/demo.kube.tgt root@localhost:/data/demo.kube.tar
scp .tmp/demo.kube.tar root@localhost:/data/demo.kube.tar

remote.ctr.import:
@echo "if kube.pkg multi-arch supported --all-platforms is required"
ssh root@localhost "gzip --decompress --stdout /data/demo.kube.tgt | ctr image import --all-platforms -"
ssh root@localhost "gzip --decompress --stdout /data/demo.kube.tar | ctr image import --all-platforms -"

eval:
cuem eval -o components.yaml ./cuepkg/kubepkg

update.node:
pnpm up -r --latest
dep.node:
bun install

clean.node:
find . -name 'node_modules' -type d -prune -print -exec rm -rf '{}' \;
dep.node.update:
bun update --latest --save

dep.node:
pnpm install
test.node:
bun test

lint.node:
pnpm exec turbo run lint --force
bunx --bun turbo run lint --force

clean.node:
find . -name '.turbo' -type d -prune -print -exec rm -rf '{}' \;
find . -name 'node_modules' -type d -prune -print -exec rm -rf '{}' \;

build.node:
pnpm exec turbo run build --force
bunx --bun turbo run build --force

build.dashboard:
APP=dashboard pnpm exec vite build --mode production
APP=dashboard bunx --bun vite build --mode production

dev.dashboard:
pnpm exec vite
bunx --bun vite

build.webapp:
$(WAGON) do webapp build --output=cmd/kubepkg/webapp
Expand All @@ -154,5 +158,3 @@ kubetgt.dashboard:
$(WAGON) do dashboard $(ARCH)

KUBEPKGTGZ=.build/kubepkg/$(ARCH)/images/kubepkg.$(ARCH).kube.tar


Binary file added bun.lockb
Binary file not shown.
8 changes: 8 additions & 0 deletions bunfig.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
jsxImportSource = "@nodepkg/runtime"

[install]
registry = "https://registry.npmjs.org"

[install.scopes]
"@innoai-tech" = { url = "https://npm.pkg.github.com", token = "$INNOAI_TECH_REGISTRY_AUTH_TOKEN" }

2 changes: 1 addition & 1 deletion cue.mod/module.cue
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
module: "github.com/octohelm/kubepkg"

require: {
"github.com/innoai-tech/runtime": "v0.0.0-20230822100237-c611c3ecb10d"
"github.com/innoai-tech/runtime": "v0.0.0-20231019111209-7659363d4202"
"wagon.octohelm.tech": "v0.0.0"
}

Expand Down
4 changes: 2 additions & 2 deletions cue.mod/module.sum
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
github.com/innoai-tech/runtime v0.0.0-20230822100237-c611c3ecb10d h1:gKkq2oeo2Fp7dBet/OGDVEH9YhZ8nzUXkt+dK/0Of6E=
wagon.octohelm.tech v0.0.0 h1:n59rfmFf+yAAGiznpLc74rZ4jPYUsmUr8jmvHmgHpYY=
github.com/innoai-tech/runtime v0.0.0-20231019111209-7659363d4202 h1:c7VZZkMraUKZfxMnL1qxbfH/ACFqteb2Je8iubESWsA=
wagon.octohelm.tech v0.0.0 h1:MGaJBtAuLJTv0EuRtd405SA68SAvXQwkhQkwB5HvtnY=
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,9 @@ func (c *ClusterService) CreateResources(ctx context.Context) ([]manifest.Object
}

n := &corev1.Namespace{}
n.APIVersion = "v1"
n.Kind = "Namespace"
n.Name = "kube-agent"
n.Name = "kubepkg-agent"

return append([]manifest.Object{n}, list...), nil
}
Expand Down Expand Up @@ -98,7 +99,7 @@ func createKubePkgAgent(info cluster.AgentInfo, registryEndpoint string) *v1alph
k.Spec.Containers = map[string]v1alpha1.Container{}
k.Spec.Containers["kube-agent"] = v1alpha1.Container{
Image: v1alpha1.Image{
Name: "gcr.io/octohelm/kubepkg",
Name: "ghcr.io/octohelm/kubepkg",
Tag: k.Spec.Version,
},
Args: []string{
Expand Down Expand Up @@ -131,6 +132,9 @@ func createKubePkgAgent(info cluster.AgentInfo, registryEndpoint string) *v1alph
k.Spec.Volumes["storage"] = v1alpha1.Volume{
VolumeSource: &v1alpha1.VolumePersistentVolumeClaim{
Type: "PersistentVolumeClaim",
VolumeMount: v1alpha1.VolumeMount{
MountPath: "/etc/kubepkg",
},
Opt: &corev1.PersistentVolumeClaimVolumeSource{
ClaimName: "storage-kubepkg",
},
Expand Down
5 changes: 1 addition & 4 deletions nodedevpkg/devconfig/package.json
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
{
"name": "@nodepkg/devconfig",
"version": "0.0.0",
"dependencies": {
"@innoai-tech/vuedevconfig": "^0.1.1"
},
"license": "MIT",
"private": true,
"scripts": {},
"type": "module"
}
}
37 changes: 34 additions & 3 deletions nodedevpkg/devconfig/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,39 @@
{
"extends": "@innoai-tech/vuedevconfig/tsconfig.json",
"$schema": "https://json.schemastore.org/tsconfig",
"compilerOptions": {
"baseUrl": ".",
"outDir": "./dist",
"types": [
"bun-types"
],
"module": "esnext",
"target": "esnext",
"moduleResolution": "bundler",
"allowImportingTsExtensions": true,
"moduleDetection": "force",
"strict": true,
"esModuleInterop": true,
"skipLibCheck": true,
"forceConsistentCasingInFileNames": true,
"composite": true,
"downlevelIteration": true,
"allowSyntheticDefaultImports": true,
"allowUnusedLabels": false,
"allowUnreachableCode": false,
"experimentalDecorators": true,
"noFallthroughCasesInSwitch": true,
"noImplicitOverride": true,
"noImplicitReturns": true,
"noPropertyAccessFromIndexSignature": true,
"noUncheckedIndexedAccess": true,
"noUnusedLocals": true,
"noUnusedParameters": true,
"verbatimModuleSyntax": true,
"checkJs": false,
"declaration": true,
"emitDeclarationOnly": true,
"exactOptionalPropertyTypes": false,
"jsxImportSource": "@nodepkg/runtime",
"emitDeclarationOnly": true
"jsx": "react-jsx",
"jsxImportSource": "@nodepkg/runtime"
}
}
10 changes: 5 additions & 5 deletions nodepkg/codemirror/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
"peerDependencies": {},
"exports": {
".": {
"bun": "./src/index.ts",
"import": {
"types": "./index.d.ts",
"default": "./index.mjs"
Expand All @@ -38,10 +39,9 @@
],
"license": "MIT",
"scripts": {
"lint": "prettier --write .",
"build": "monobundle",
"test": "vitest --run --passWithNoTests --dir .",
"prepublishOnly": "pnpm run build"
"lint": "bunx --bun prettier --write .",
"build": "bunx --bun monobundle",
"prepublishOnly": "bun run build"
},
"type": "module"
}
}
18 changes: 9 additions & 9 deletions nodepkg/codemirror/src/json/JSONDiff.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import {
EditorView,
gutterLineClass,
GutterMarker,
ViewUpdate
ViewUpdate,
} from "@codemirror/view";
import { useExtension } from "../EditorContextProvider";
import { isUndefined, isPlainObject, isEqual } from "@nodepkg/runtime/lodash";
Expand All @@ -13,7 +13,7 @@ import {
Range,
RangeSet,
StateEffect,
StateField
StateField,
} from "@codemirror/state";
import { walkNode } from "./util";
import { ensureSyntaxTree } from "@codemirror/language";
Expand Down Expand Up @@ -48,7 +48,7 @@ const diffedLines = StateField.define<DecorationSet>({
tr.effects.forEach((e) => {
if (e.is(addDiffLineEffect)) {
lines = lines.update({
add: [diffLine.range(e.value.from, e.value.to)]
add: [diffLine.range(e.value.from, e.value.to)],
});
} else if (e.is(removeDiffLineEffect)) {
lines = cutRange(lines, e.value);
Expand All @@ -58,10 +58,10 @@ const diffedLines = StateField.define<DecorationSet>({
return lines.update({
filterFrom: 0,
filterTo: tr.newDoc.length,
filter: () => true
filter: () => true,
});
},
provide: (f) => EditorView.decorations.from(f)
provide: (f) => EditorView.decorations.from(f),
});

function cutRange(ranges: DecorationSet, r: { from: number; to: number }) {
Expand All @@ -76,7 +76,7 @@ function cutRange(ranges: DecorationSet, r: { from: number; to: number }) {
filterFrom: r.from,
filterTo: r.to,
filter: () => false,
add: leftover
add: leftover,
});
}

Expand All @@ -96,7 +96,7 @@ const jsonDiff = (base: () => any): Extension[] => {
if (v.viewportChanged || v.docChanged) {
diffAndDispatchEffects(v, base());
}
})
}),
];
};

Expand Down Expand Up @@ -152,8 +152,8 @@ const diffAndDispatchEffects = (v: ViewUpdate, src: string) => {
addDiffLineEffect.of({
type,
from: linePos,
to: linePos
})
to: linePos,
}),
);
newLines.add(linePos);
}
Expand Down
1 change: 0 additions & 1 deletion nodepkg/codemirror/src/json/JSONPointer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ export class JSONPointer {
return "/" + keyPath.map(JSONPointer.escape).join("/");
}


static unescape(str: string) {
return str.replace(/~1/g, "/").replace(/~0/g, "~");
}
Expand Down
20 changes: 11 additions & 9 deletions nodepkg/codemirror/src/json/__tests__/JSONDiff.spec.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { expect, describe, it } from "vitest";
import { expect, describe, it } from "bun:test";
import { diff } from "../JSONDiff";

describe("JSONDiff", () => {
Expand All @@ -13,20 +13,22 @@ describe("JSONDiff", () => {
{
x: {
a: {
"aliyun.com/gpu-mem": 2
}
}
"aliyun.com/gpu-mem": 2,
},
},
},
{
x: {
a: {
"aliyun.com/gpu-mem": 1
}
}
}
"aliyun.com/gpu-mem": 1,
},
},
},
);

expect([...ret.entries()]).toEqual([[`/x/a/aliyun.com~1gpu-mem`, ["m", 2, 1]]]);
expect([...ret.entries()]).toEqual([
[`/x/a/aliyun.com~1gpu-mem`, ["m", 2, 1]],
]);
});

it("should diff deletes", () => {
Expand Down
6 changes: 4 additions & 2 deletions nodepkg/codemirror/src/json/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ export const walkNode = (
editorState: EditorState,
node: SyntaxNode | null,
each: (path: string, node: SyntaxNode) => void,
path = "/"
path = "/",
) => {
if (!node) {
return;
Expand All @@ -33,7 +33,9 @@ export const walkNode = (
const propValueNode = n.lastChild;

if (propNameNode && propValueNode) {
let propName = unquote(editorState.sliceDoc(propNameNode.from, propNameNode.to));
let propName = unquote(
editorState.sliceDoc(propNameNode.from, propNameNode.to),
);

each(`${path}${JSONPointer.escape(propName)}`, propNameNode);

Expand Down
10 changes: 5 additions & 5 deletions nodepkg/jsonschema/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
"peerDependencies": {},
"exports": {
".": {
"bun": "./src/index.ts",
"import": {
"types": "./index.d.ts",
"default": "./index.mjs"
Expand All @@ -28,10 +29,9 @@
"license": "MIT",
"private": true,
"scripts": {
"build": "monobundle",
"test": "vitest --run --passWithNoTests --dir .",
"prepublishOnly": "pnpm run build",
"lint": "prettier --write ."
"build": "bunx --bun monobundle",
"prepublishOnly": "bun run build",
"lint": "bunx --bun prettier --write ."
},
"type": "module"
}
}
6 changes: 4 additions & 2 deletions nodepkg/jsonschema/src/LSP.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,10 @@ export class LSP {
return `布尔类型不匹配`;
case "enums": {
const t = this.typeAt(f.path)!;
return `值只能是: ${Object.values(t.schema)
.map((v) => JSON.stringify(v))

return `值只能是: ${t
.getSchema("enum")
.map((v: any) => JSON.stringify(v))
.join(", ")}`;
}
}
Expand Down
Loading

0 comments on commit d90ff3e

Please sign in to comment.