Skip to content

Commit

Permalink
Merge pull request #24 from aminya/update [skip ci]
Browse files Browse the repository at this point in the history
  • Loading branch information
aminya authored Sep 7, 2024
2 parents 79fc1fa + 1e54b09 commit 4eb15b5
Show file tree
Hide file tree
Showing 21 changed files with 5,839 additions and 5,404 deletions.
2 changes: 1 addition & 1 deletion .eslintrc.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{
"extends": "eslint-config-atomic",
"ignorePatterns": ["dist/", "node_modules/"]
"ignorePatterns": ["dist/", "node_modules/", "despacer/", "test/fixtures/*/*-minified.json"]
}
72 changes: 24 additions & 48 deletions .github/workflows/CI.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,37 +5,33 @@ on:

jobs:
Test:
if: "!contains(github.event.head_commit.message, '[skip ci]')"
if: ${{ !contains(github.event.head_commit.message, '[skip ci]') }}
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
os:
- windows-latest
- macos-latest
- ubuntu-latest
# - macos-11 # arm64
- macos-13 # x86
- macos-14 # arm64
d:
- "ldc-1.28.0"
- "ldc-latest"
node:
- 16
- 20
pnpm:
- 6
- 9
compiler:
- llvm-12.0.0
cmake:
- "3.22.1"
ninja:
- "1.10.2"
- llvm
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v4
with:
submodules: "true"

# Cache
- name: Cache
id: cache
uses: actions/cache@v2
uses: actions/cache@v4
with:
path: |
~/.dub
Expand All @@ -44,54 +40,33 @@ jobs:
D:\.pnpm-store
./.dub
~/llvm
key: "cache-OS:${{ matrix.os }}-D:${{ matrix.d }}-CXX:${{ matrix.compiler }}-dub:${{ hashFiles('./dub.selections.json')}}-pnpm:${{ hashFiles('./pnpm-lock.yaml') }}"
key: "cache-OS:${{ matrix.os }}-D:${{ matrix.d }}-CXX:${{ matrix.compiler }}-${{ hashFiles('./dub.selections.json', './pnpm-lock.yaml')}} }}"
restore-keys: |
"cache-OS:${{ matrix.os }}-D:${{ matrix.d }}-CXX:${{ matrix.compiler }}"
"cache-OS:${{ matrix.os }}-D:${{ matrix.d }}-CXX:${{ matrix.compiler }}-"
# Setup compilers and tools
- name: Setup Cpp
if: ${{ !contains(matrix.os, 'macos') }}
uses: aminya/setup-cpp@v1
with:
compiler: ${{ matrix.compiler }}
cmake: ${{ matrix.cmake }}
ninja: ${{ matrix.ninja }}
cmake: true
ninja: true

- name: Setup Cpp
if: ${{ contains(matrix.os, 'macos') }}
uses: aminya/setup-cpp@v1
with:
cmake: true
ninja: true

- name: Setup D
uses: dlang-community/setup-dlang@v1
with:
compiler: ${{ matrix.d }}

- name: Setup Mac Arm64
shell: bash
if: contains(matrix.os, 'macos-11')
run: |
ARCH="arm64"
echo "ARCH=$ARCH" >> $GITHUB_ENV
echo "triple=$ARCH-apple-macos" >> $GITHUB_ENV
echo "DFLAGS='-mtriple=$triple -Xcc=target -Xcc=$ARCH-apple-macos'" >> $GITHUB_ENV
echo "CPPFLAGS=$CPPFLAGS -arch $ARCH" >> $GITHUB_ENV
echo "CFLAGS=$CFLAGS -arch $ARCH" >> $GITHUB_ENV
echo "LDFLAGS=$LDFLAGS -arch $ARCH" >> $GITHUB_ENV
# Manually install ldc
# Due to https://github.com/dlang-community/setup-dlang/issues/51
curl -LJO https://github.com/ldc-developers/ldc/releases/download/v1.28.0/ldc2-1.28.0-osx-$ARCH.tar.xz
tar -xf ldc2-1.28.0-osx-$ARCH.tar.xz
rm ldc2-1.28.0-osx-$ARCH.tar.xz
LDC_PATH="~/ldc"
mkdir -p $LDC_PATH
mv ldc2-1.28.0-osx-$ARCH $LDC_PATH
# Activate ldc
echo "LIBRARY_PATH=$LDC_PATH/lib${LIBRARY_PATH:+:}${LIBRARY_PATH:-}" >> $GITHUB_ENV
echo "LD_LIBRARY_PATH=$LDC_PATH/lib${LD_LIBRARY_PATH:+:}${LD_LIBRARY_PATH:-}" >> $GITHUB_ENV
echo "PATH=$LDC_PATH/bin${PATH:+:}${PATH:-}" >> $GITHUB_ENV
echo "DMD=ldmd2" >> $GITHUB_ENV
echo "DC=ldc2" >> $GITHUB_ENV
- name: Setup Node
uses: actions/setup-node@v2
uses: actions/setup-node@v4
with:
node-version: ${{ matrix.node }}

Expand All @@ -112,6 +87,7 @@ jobs:
run: pnpm test

- name: Upload artifacts
uses: actions/upload-artifact@v2
uses: actions/upload-artifact@v4
with:
name: minijson-${{ runner.os }}-${{ runner.arch }}
path: ./dist
8 changes: 4 additions & 4 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
[submodule "src/native/despacer"]
path = src/native/despacer
url = https://github.com/aminya/despacer
branch = minijson
[submodule "despacer"]
path = despacer
url = https://github.com/aminya/despacer.git
branch = master
7 changes: 3 additions & 4 deletions .npmrc
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
public-hoist-pattern[]=*
package-lock=false
lockfile=true
prefer-frozen-lockfile=false
hoist-pattern[]=*eslint*
hoist-pattern[]=*babel*
hoist-pattern[]=*types*
1 change: 1 addition & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@ CHANGELOG.md
dist
test/fixtures/*-minified.json
dub.selections.json
/despacer/
36 changes: 26 additions & 10 deletions Readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,21 +32,33 @@ dub build --config=executable --build=release-nobounds --compiler=ldc2
### CLI Usage

```shell
❯ minijson --help
> minijson --help

Usage: minijson [--files FILES ...] [--comment] [--str STR ...] [--file FILE ...] [-h]

minijson: minify json files with support for comments
minijson --file file1.json --file file2.json
minijson --file file1_with_comment.json --file file2_with_comment.json --comment

minijson --string '{"some_json": "string_here"}'
minijson --string '{"some_json": "string_here"} //comment' --comment
# Minify the specified files
minijson ./dist/**/*.json ./build/a.json

# Minify the specified files (supports comments)
minijson --comment file1_with_comment.json file2_with_comment.json

# Minify the specified json string
minijson --str '{"some_json": "string_here"}'

# Minify the specified json string (supports comments)
minijson --comment --str '{"some_json": "string_here"} //comment'

More information at https://github.com/aminya/minijson

--file an array of files to minify
--string a json string to minify
--comment a flag to support comments in json
-h --help This help information.

Optional arguments:
--files FILES ...
--comment
--str STR ...
--file FILE ...
-h, --help Show this help message and exit
```

### Node API
Expand Down Expand Up @@ -111,18 +123,22 @@ Benchmark minifyFiles
### Contributing

You would need to install the ldc compiler for the D programming language

```
curl -fsS https://dlang.org/install.sh | bash -s ldc
```
After installation, it will print a message about activating it. Something like `source activate_ldc.sh`.

After installation, it will print a message about activating it. Something like `source activate_ldc.sh`.

After running the activation command, clone the repository:

```
git clone --recurse-submodules https://github.com/aminya/minijson
cd minijson
```

Then build with:

```
pnpm install
pnpm build.node
Expand Down
4 changes: 2 additions & 2 deletions benchmark/js-benchmark.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ console.log("Benchmark minifyString")
const filesContents = await Promise.all(
standardFiles.map(async (jsonFile) => {
return readFile(jsonFile, "utf8")
})
}),
)

const t11 = performance.now()
Expand All @@ -33,7 +33,7 @@ await Promise.all(
const jsonString = await readFile(jsonFile, "utf8")
const data = await jsonMinify(jsonString)
return await writeFile(jsonFile, data)
})
}),
)

const t2 = performance.now()
Expand Down
1 change: 1 addition & 0 deletions despacer
Submodule despacer added at 6e5018
13 changes: 7 additions & 6 deletions dub.sdl
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,11 @@ sourcePaths "./src/native"
importPaths "./src/native"

dependency "automem" version="0.6.7"
dependency "despacer" path="despacer"
dependency "d-glob" version="~>0.4.0"
dependency "argparse" version="~>1.3.0"

preGenerateCommands "git submodule update --init" # despacer download
dependency "despacer" path="./src/native/despacer/bindings/d"

configuration "executable" {
targetType "executable"
Expand All @@ -32,16 +35,14 @@ configuration "benchmark" {

# -------- Build Options and configurations --------

// enables all disp except =nosharedaccess
dflags "-vgc" "-preview=dip25" "-preview=dip1000" "-preview=dip1008" "-preview=fieldwise" "-preview=fixAliasThis" "-preview=intpromote" "-preview=rvaluerefparam" "-preview=in"
/* dflags "-preview=inclusiveincontracts" platform="dmd" // only on dmd */
/* dflags "-preview=dip1021" platform="posix-ldc" // "breaks the build */
// dflags "-vgc"

buildType "release-nobounds" {
buildOptions "releaseMode" "optimize" "inline" "noBoundsCheck"

# link time optimizations
dflags "--flto=full" "--ffast-math" platfrom="ldc"
dflags "--flto=full" "--ffast-math" platform="windows-ldc"
dflags "--flto=full" "--ffast-math" platform="linux-ldc"
}

buildType "debug-sanitize-address" platform="ldc" {
Expand Down
9 changes: 6 additions & 3 deletions dub.selections.json
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
{
"fileVersion": 1,
"versions": {
"argparse": "1.3.0",
"automem": "0.6.7",
"despacer": {"path":"src/native/despacer/bindings/d"},
"test_allocator": "0.3.3",
"unit-threaded": "2.0.3"
"bdd": "1.3.0",
"d-glob": "0.4.0",
"despacer": {"path":"despacer/"},
"test_allocator": "0.3.4",
"unit-threaded": "2.2.0"
}
}
Loading

0 comments on commit 4eb15b5

Please sign in to comment.