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 Oct 17, 2023
1 parent 73e1d2e commit a8f09db
Show file tree
Hide file tree
Showing 38 changed files with 547 additions and 2,800 deletions.
4 changes: 4 additions & 0 deletions .bunfig.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
[install]
registry = "https://registry.npmjs.org"
[install.scopes]
"@innoai-tech" = "https://npm.pkg.github.com"
13 changes: 2 additions & 11 deletions .github/workflows/node.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,17 +20,8 @@ jobs:

- run: rustup target add wasm32-wasi

- uses: actions/setup-node@v3
with:
registry-url: 'https://npm.pkg.github.com'
node-version: "^20"

- uses: pnpm/action-setup@v2
with:
version: "^8"
- uses: oven-sh/setup-bun@v1

- run: make bootstrap
- run: make build
- run: make test
- run: make pub
env:
NODE_AUTH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
4 changes: 0 additions & 4 deletions .npmrc

This file was deleted.

22 changes: 11 additions & 11 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -9,31 +9,31 @@ tidy:
go mod tidy

update:
pnpm up -r --latest
bun update --latest

dep:
pnpm install
bun install

bootstrap: dep build.monobundle
pnpm exec monobundle
bunx monobundle

build.monobundle:
pnpm exec turbo run build --filter=monobundle --force
pnpm install

ci: lint test
bunx turbo run build --filter=monobundle --force
bun install

lint:
pnpm exec turbo run lint --force
bunx turbo run lint --force

test:
pnpm exec turbo run test --force
bunx turbo run test --force

build:
pnpm exec turbo run build --filter=!monobundle --force
bunx turbo run build --filter=!monobundle --force

ci: bootstrap lint build test

pub:
pnpm -r publish --no-git-checks
bun -r publish --no-git-checks

export BUILDKIT_HOST =
ship:
Expand Down
Binary file added bun.lockb
Binary file not shown.
2 changes: 1 addition & 1 deletion cue.mod/module.cue
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@ module: "github.com/innoai-tech/nodekit"

require: {
"github.com/innoai-tech/runtime": "v0.0.0-20230807071635-a566ade1c374"
"wagon.octohelm.tech": "v0.0.0-20200202235959-3ffa3ac0907e"
"wagon.octohelm.tech": "v0.0.0"
}
2 changes: 0 additions & 2 deletions cue.mod/module.sum

This file was deleted.

5 changes: 3 additions & 2 deletions nodedevpkg/devconfig/package.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
{
"name": "@innoai-tech/devconfig",
"version": "0.3.2",
"version": "0.4.0",
"files": [
"*.json"
],
"license": "MIT",
"scripts": {},
"type": "module"
}
}

3 changes: 3 additions & 0 deletions nodedevpkg/devconfig/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@
"dom",
"webworker"
],
"types": [
"bun-types"
],
"module": "es2022",
"target": "es2021",
"moduleResolution": "node",
Expand Down
12 changes: 6 additions & 6 deletions nodedevpkg/monobundle/package.json
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
{
"name": "@innoai-tech/monobundle",
"version": "0.10.2",
"version": "0.11.0",
"monobundle": {
"exports": {
".": "./src/index.ts",
"bin:monobundle": "./src/bin/index.ts"
},
"pipeline": {
"build": "tsx ./src/bin/index.ts"
"build": "bun ./src/bin/index.ts"
}
},
"dependencies": {
Expand Down Expand Up @@ -49,10 +49,10 @@
],
"license": "MIT",
"scripts": {
"lint": "prettier --write .",
"build": "tsx ./src/bin/index.ts",
"prepublishOnly": "pnpm run build",
"test": "vitest --run --passWithNoTests --dir ."
"lint": "bunx prettier --write .",
"build": "bun ./src/bin/index.ts",
"prepublishOnly": "bun run build",
"test": "bun test ."
},
"type": "module"
}
56 changes: 32 additions & 24 deletions nodedevpkg/monobundle/src/autoExternal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ import { minimatch } from "minimatch";
import { join } from "path";
import { globby } from "globby";
import { readFile } from "fs/promises";
import { load } from "js-yaml";
import { type InputOptions } from "rollup";
import type { Project } from "./pm";
// @ts-ignore
const builtIns = process.binding("natives");

Expand All @@ -12,22 +12,28 @@ const isPkgUsed = (pkg: string, id: string) => {
};

export type Package = {
name: string,
dependencies?: Record<string, string>,
peerDependencies?: Record<string, string>,
}
name: string;
dependencies?: Record<string, string>;
peerDependencies?: Record<string, string>;
};

export const loadWorkspace = async (project: Project, localPkg: Package) => {
const workspaces = await project.pm.workspaces(project.root);

export const loadWorkspace = async (monoRoot: string, localPkg: Package) => {
const w = load(String(await readFile(join(monoRoot, "./pnpm-workspace.yaml")))) as { packages?: string[] };
const m = new Map<string, Set<string>>;
const m = new Map<string, Set<string>>();

if (w?.packages) {
const packageJSONs = await globby(w?.packages.map((b) => `${b}/package.json`), {
cwd: monoRoot
});
if (workspaces) {
const packageJSONs = await globby(
workspaces.map((b) => `${b}/package.json`),
{
cwd: project.root,
},
);

for (const f of packageJSONs) {
let pkg = JSON.parse(String(await readFile(join(`${monoRoot}`, f)))) as Package;
let pkg = JSON.parse(
String(await readFile(join(`${project.root}`, f))),
) as Package;

// localPkg may be changed
if (localPkg.name === pkg.name) {
Expand Down Expand Up @@ -60,12 +66,12 @@ export const loadWorkspace = async (monoRoot: string, localPkg: Package) => {
};

export const createAutoExternal = async (
monoRoot: string,
project: Project,
pkg: Package,
opts: {
logger?: ReturnType<typeof import("./log").createLogger>;
sideDeps?: string[];
}
},
) => {
const logger = opts.logger;
const sideDeps = opts.sideDeps || [];
Expand All @@ -75,13 +81,13 @@ export const createAutoExternal = async (
return false;
}
return sideDeps.some(
(glob) => pkgName === glob || minimatch(pkgName, glob)
(glob) => pkgName === glob || minimatch(pkgName, glob),
);
};

const usedPkgs = new Set<string>();

const w = await loadWorkspace(monoRoot, pkg);
const w = await loadWorkspace(project, pkg);

const dep = new Set<string>();

Expand All @@ -101,15 +107,14 @@ export const createAutoExternal = async (

collect(pkg.name);


const builtins = Object.keys(builtIns);

const warningAndGetUnused = () => {
const used = [...usedPkgs.keys()];

const unused = {
deps: {} as { [k: string]: boolean },
peerDeps: {} as { [k: string]: boolean }
peerDeps: {} as { [k: string]: boolean },
};

for (const d of dep) {
Expand All @@ -129,14 +134,17 @@ export const createAutoExternal = async (
const collector = new Set<string>();

const autoExternal = (validate = true) => {

return {
name: "auto-external",

options(opts: InputOptions) {
return {
...opts,
external(id: string, importer: string | undefined, isResolved: boolean) {
external(
id: string,
importer: string | undefined,
isResolved: boolean,
) {
if (
typeof opts.external === "function" &&
opts.external(id, importer, isResolved)
Expand Down Expand Up @@ -165,7 +173,7 @@ export const createAutoExternal = async (
collector.add(id);

logger?.danger(
`"${id}" is not in dependencies or peerDependencies, and will be bundled.`
`"${id}" is not in dependencies or peerDependencies, and will be bundled.`,
);
}
}
Expand All @@ -174,9 +182,9 @@ export const createAutoExternal = async (
}

return false;
}
},
};
}
},
};
};

Expand Down
Loading

0 comments on commit a8f09db

Please sign in to comment.