Skip to content

Commit

Permalink
Starting project from https://github.com/deref/uni
Browse files Browse the repository at this point in the history
  • Loading branch information
brandonbloom authored and teintinu committed Jul 24, 2021
1 parent 105d0f0 commit 9fcfa88
Show file tree
Hide file tree
Showing 101 changed files with 8,906 additions and 1 deletion.
22 changes: 22 additions & 0 deletions .github/workflows/go.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
name: Go

on:
push:
branches: [ main ]
pull_request:
branches: [ main ]

jobs:

build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2

- name: Set up Go
uses: actions/setup-go@v2
with:
go-version: 1.16

- name: Test
run: ./test.sh
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/uni
1 change: 1 addition & 0 deletions .nvmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
v14.17.3
17 changes: 17 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "Debug",
"type": "go",
"request": "launch",
"mode": "debug",
"program": "main.go",
"cwd": "example",
"args": ["run", "./reverse-args.ts", "a", "b", "c"]
}
]
}
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2021 Brandon Bloom

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
93 changes: 93 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
# Unirepo

Unirepo is an extremely opinionated TypeScript build tool.

Typical monorepo management tools in the Node.js ecosystem provide automation
around package maintenance, but still permit and require users to muck around
with poly-package configuration. Package boundaries must be manually
maintained, each with its own sub-configuration.

Unirepo is different because sub-package configuration is managed centrally and
uniformly. Package boundaries are managed automatically via bundling and code
splitting.

You will have one and only one list of dependencies. Your `package.json` files
will be generated from that source configuration. Same for `tsconfig.json`.
The source configuration file - believe it or not - allows code comments.

Unirepo is _fast_ because it is ships as a native binary and builds your code
using [esbuild][1].

Additionally, Unirepo has a `run` subcommand that acts as a substitute for
[`ts-node`][2]. The `run` subcommand also supports a `--watch` flag, and so
acts as a substitute for [`node-dev`][3] (or [`ts-node-dev`][4]) as well.
Sourcemaps are always enabled.

As mentioned, Unirepo is extremely opinionated. Those opinions will evolve into
documentation, including a growing list of
[anti-features](./doc/anti-features.md).

Want to see it in action?
Check out the [Demo Video](https://www.youtube.com/watch?v=RJfLA7EM-Uw)!

## Status

Alpha! Don't use this yet.

See the [versioning guide](./doc/versioning.md) and the
[roadmap](./doc/roadmap.md).

Only works for targeting Node currently. Targeting Browsers is planned.

## Installation

```bash
go get -u github.com/deref/uni
```

## Usage

- [Configuration](./doc/config.md)
- [Migration Guide](./doc/migrate.md)

### Setup

1. Create a `uni.yml` file with some package entrypoints.
2. Manually add dependencies to your config file.
3. Run `uni deps`.

### Development

- Use `uni run src/program.ts` to execute programs. They must export a `main` function.
- Use `uni build some-package` to pre-compile into `out/dist`.

### Publishing

Here's the steps to do in your CI flow:

1. `uni build --version $VERSION --types` to create packages with version numbers and types definitions.
2. `uni pack` to create packed `.tgz` files.
3. `uni publish` to automate `npm publish ./path/to/package.tgz`.

## Other Features

### Patching

The [patch-package][5] utility is always available.

### Engine Checking

Functionality similar to [check-engine][6] is builtin, but much faster
and with caching.

### Executables

Any runnable script can be exposed as an executable in a package. A shim script
(with a `#!`) will be produced automatically.

[1]: https://esbuild.github.io/
[2]: https://github.com/TypeStrong/ts-node
[3]: https://github.com/fgnass/node-dev
[4]: https://github.com/wclr/ts-node-dev
[5]: https://github.com/ds300/patch-package
[6]: https://github.com/mohlsen/check-engine
57 changes: 57 additions & 0 deletions cmd/build.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
package cmd

import (
"fmt"

"github.com/deref/uni/internal"
"github.com/spf13/cobra"
)

var buildOpts internal.BuildOptions

func init() {
rootCmd.AddCommand(buildCmd)
buildCmd.Flags().StringVar(&buildOpts.Version, "version", "", "version to put in package.json")
buildCmd.Flags().BoolVar(&buildOpts.Watch, "watch", false, "rebuilds each time source files change")
buildCmd.Flags().BoolVar(&buildOpts.Types, "types", false, "also build a .d.ts file")
}

var buildCmd = &cobra.Command{
Use: "build [package]",
Short: "Builds packages targeting Node.",
Long: `Builds packages targeting Node.
Given no arguments, builds all packages. Otherwise, builds only the specified package.`,
Args: cobra.RangeArgs(0, 1),
RunE: func(cmd *cobra.Command, args []string) error {
repo := mustLoadRepository()
if err := internal.CheckEngines(repo); err != nil {
return err
}

var packages map[string]*internal.Package
switch len(args) {
case 0:
packages = repo.Packages
case 1:
pkgName := args[0]
pkg, ok := repo.Packages[pkgName]
if !ok {
return fmt.Errorf("no such package: %q", pkgName)
}
packages = map[string]*internal.Package{
pkgName: pkg,
}
default:
panic("unreachable")
}

// TODO: Parallelism.
for _, pkg := range packages {
buildOpts.Package = pkg
if err := internal.Build(repo, buildOpts); err != nil {
return err
}
}
return nil
},
}
20 changes: 20 additions & 0 deletions cmd/clean.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package cmd

import (
"github.com/deref/uni/internal"
"github.com/spf13/cobra"
)

func init() {
rootCmd.AddCommand(cleanCmd)
}

var cleanCmd = &cobra.Command{
Use: "clean",
Short: "Removes build output.",
Long: `Removes build output.`,
RunE: func(cmd *cobra.Command, args []string) error {
repo := mustLoadRepository()
return internal.Clean(repo)
},
}
26 changes: 26 additions & 0 deletions cmd/deps.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package cmd

import (
"github.com/deref/uni/internal"
"github.com/spf13/cobra"
)

var depsOpts internal.InstallDependenciesOptions

func init() {
rootCmd.AddCommand(depsCmd)
depsCmd.Flags().BoolVar(&depsOpts.Frozen, "frozen", false, "(unstable) prevents modification of dependency lock file")
}

var depsCmd = &cobra.Command{
Use: "deps",
Short: "Install dependencies",
Long: `Generates a root package.json file and runs your package manager.`,
RunE: func(cmd *cobra.Command, args []string) error {
repo := mustLoadRepository()
if err := internal.CheckEngines(repo); err != nil {
return err
}
return internal.InstallDependencies(repo, depsOpts)
},
}
35 changes: 35 additions & 0 deletions cmd/env.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package cmd

import (
"fmt"
"os"

"github.com/deref/uni/internal"
"github.com/spf13/cobra"
)

func init() {
rootCmd.AddCommand(envCmd)
}

var envCmd = &cobra.Command{
Use: "env",
Short: "Dump environment information.",
Long: `Validates and prints information about the current environment.
Returns a non-zero status code if there environment fails any checks.
The printed output of this command is intended for human consumption and
not (yet?) intended to be parsed.`,
Run: func(cmd *cobra.Command, args []string) {
repo := mustLoadRepository()
env, err := internal.AnalyzeEnvironment(repo)
if err != nil {
fmt.Fprintln(os.Stderr, err)
os.Exit(1)
}
internal.DumpEnvironment(env)
if !env.OK {
os.Exit(1)
}
},
}
51 changes: 51 additions & 0 deletions cmd/pack.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
package cmd

import (
"fmt"

"github.com/deref/uni/internal"
"github.com/spf13/cobra"
)

func init() {
rootCmd.AddCommand(packCmd)
}

var packCmd = &cobra.Command{
Use: "pack [package]",
Short: "Packs pre-built packages into a tgz files.",
Long: `Packs packages into tgz files.
Prints the absolute path of each created package.
The package must already be built. Use the build command.`,
Args: cobra.RangeArgs(0, 1),
RunE: func(cmd *cobra.Command, args []string) error {
repo := mustLoadRepository()

var packages map[string]*internal.Package
switch len(args) {
case 0:
packages = repo.Packages
case 1:
pkgName := args[0]
pkg, ok := repo.Packages[pkgName]
if !ok {
return fmt.Errorf("no such package: %q", pkgName)
}
packages = map[string]*internal.Package{
pkgName: pkg,
}
default:
panic("unreachable")
}

// TODO: Parallelism.
for _, pkg := range packages {
res, err := internal.Pack(repo, pkg)
if err != nil {
return err
}
fmt.Println(res.PackagePath)
}
return nil
},
}
Loading

0 comments on commit 9fcfa88

Please sign in to comment.