Skip to content

Commit

Permalink
feat: first commit
Browse files Browse the repository at this point in the history
  • Loading branch information
marco-ippolito committed Jul 16, 2024
1 parent 9dd5bad commit eece4ed
Show file tree
Hide file tree
Showing 13 changed files with 246 additions and 2 deletions.
10 changes: 10 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# Basic set up for three package managers

version: 2
updates:

# Maintain dependencies for GitHub Actions
- package-ecosystem: "github-actions"
directory: "/"
schedule:
interval: "weekly"
37 changes: 37 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
name: Tests

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

env:
YARN_ENABLE_GLOBAL_CACHE: false

jobs:
build-and-test:
strategy:
fail-fast: false
matrix:
node:
- 22
platform:
- ubuntu-latest
- macos-latest
- windows-latest

name: "${{matrix.platform}} w/ Node.js ${{matrix.node}}.x"
runs-on: ${{matrix.platform}}

steps:
- uses: actions/checkout@v4

- name: "Use Node.js ${{matrix.node}}.x"
uses: actions/setup-node@v4
with:
node-version: ${{matrix.node}}.x

- run: npm install
- run: npm run build
- run: npm test
43 changes: 43 additions & 0 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
name: Publish releases

on:
push:
branches: [main]

jobs:
release-please:
runs-on: ubuntu-latest
outputs:
release_created: ${{ steps.release.outputs.release_created }}
release_tag: ${{ steps.release.outputs.tag_name }}
steps:
- uses: google-github-actions/release-please-action@v3
id: release
with:
release-type: node
package-name: amaro
bump-minor-pre-major: true # TODO: remove this when releasing v1.0.0.

npm-publish:
needs: release-please
if: ${{ needs.release-please.outputs.release_created }}
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4

- uses: actions/setup-node@v4
with:
node-version: lts/*

- name: Publish to the npm registry
run: |
npm install
npm publish
env:
NPM_AUTH_TOKEN: ${{secrets.NPM_AUTH_TOKEN}}

- run: npm pack --out amaro.tgz
- name: Add Amaro package archive to GitHub release
run: gh release upload ${{ needs.release-please.outputs.release_tag }} amaro.tgz
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
.DS_Store
.vscode
node_modules
dist
package-lock.json
6 changes: 6 additions & 0 deletions CODE_OF_CONDUCT.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# Code of Conduct

Amaro is committed to upholding the Node.js Code of Conduct.

The Node.js Code of Conduct document can be found at
<https://github.com/nodejs/admin/blob/master/CODE_OF_CONDUCT.md>
File renamed without changes.
20 changes: 18 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,18 @@
# amaro
Blessed Node.js TypeScript loader
# Amaro

Amaro is a wrapper around `@swc/wasm-typescript`, a WebAssembly port of the SWC TypeScript parser.
It's currently used as an internal in Node.js for [Type Stripping](https://github.com/nodejs/loaders/issues/208), but can also be upgraded separately by users.

> Amaro means "bitter" in Italian. It's a reference to [Mount Amaro](https://en.wikipedia.org/wiki/Monte_Amaro_(Abruzzo)) on whose slopes this package was conceived.
## How to Install

To install Amaro, run:

```shell
npm install -g amaro
```

## License (MIT)

See [`LICENSE.md`](./LICENSE.md).
17 changes: 17 additions & 0 deletions biome.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"$schema": "https://biomejs.dev/schemas/1.8.3/schema.json",
"organizeImports": {
"enabled": true
},
"linter": {
"enabled": true,
"rules": {
"recommended": true
},
"ignore": ["dist/**"]
},
"formatter": {
"enabled": true,
"ignore": ["dist/**"]
}
}
47 changes: 47 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
{
"name": "amaro",
"version": "0.0.1",
"description": "Blessed Node.js TypeScript loader",
"license": "MIT",
"type": "commonjs",
"main": "dist/index.js",
"homepage": "https://github.com/marco-ippolito/amaro#readme",
"bugs": {
"url": "https://github.com/marco-ippolito/amaro/issues"
},
"repository": {
"type": "git",
"url": "https://github.com/marco-ippolito/amaro.git"
},
"scripts": {
"clean": "rimraf dist",
"lint": "biome lint --write",
"format": "biome format --write",
"prepack": "npm run build",
"postpack": "npm run clean",
"build": "rspack build",
"typecheck": "tsc --noEmit",
"test": "node --test"
},
"devDependencies": {
"@biomejs/biome": "1.8.3",
"@rspack/cli": "^0.7.5",
"@rspack/core": "^0.7.5",
"@types/node": "^20.14.11",
"rimraf": "^6.0.1",
"typescript": "^5.5.3"
},
"dependencies": {
"@swc/wasm-typescript": "^1.6.13"
},
"engines": {
"node": "^22.4.0"
},
"exports": {
"./package.json": "./package.json"
},
"files": [
"dist",
"LICENSE.md"
]
}
26 changes: 26 additions & 0 deletions rspack.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
module.exports = {
target: "node",
module: {
rules: [
{
test: /\.ts$/,
exclude: [/node_modules/],
loader: "builtin:swc-loader",
options: {
jsc: {
parser: {
syntax: "typescript",
},
},
},
type: "javascript/auto",
},
],
},
output: {
filename: "index.js",
library: {
type: "commonjs2",
},
},
};
12 changes: 12 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
const { transformSync } = require("@swc/wasm-typescript");

function stripTypes(source: string): string {
const result = transformSync(source, {
mode: "strip-only",
});
return result;
}

module.exports = {
stripTypes,
};
7 changes: 7 additions & 0 deletions test/index.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
const { test } = require("node:test");
const assert = require("node:assert");
const { stripTypes } = require("../dist/index.js");

test("should perform type stripping", () => {
assert.strictEqual(typeof stripTypes, "function");
});
18 changes: 18 additions & 0 deletions tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"compilerOptions": {
"allowSyntheticDefaultImports": true,
"baseUrl": ".",
"esModuleInterop": true,
"moduleResolution": "node",
"noEmit": true,
"forceConsistentCasingInFileNames": true,
"lib": ["ES2023"],
"module": "commonjs",
"resolveJsonModule": true,
"skipLibCheck": true,
"verbatimModuleSyntax": true,
"allowImportingTsExtensions": true,
"strict": true,
"target": "ES2022"
}
}

0 comments on commit eece4ed

Please sign in to comment.