diff --git a/.github/dependabot.yml b/.github/dependabot.yml new file mode 100644 index 000000000..f800b8d9d --- /dev/null +++ b/.github/dependabot.yml @@ -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" \ No newline at end of file diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 000000000..9a1e63b26 --- /dev/null +++ b/.github/workflows/ci.yml @@ -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 \ No newline at end of file diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml new file mode 100644 index 000000000..56525ead3 --- /dev/null +++ b/.github/workflows/publish.yml @@ -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 }} \ No newline at end of file diff --git a/.gitignore b/.gitignore new file mode 100644 index 000000000..9aac17cc4 --- /dev/null +++ b/.gitignore @@ -0,0 +1,5 @@ +.DS_Store +.vscode +node_modules +dist +package-lock.json \ No newline at end of file diff --git a/CODE_OF_CONDUCT.md b/CODE_OF_CONDUCT.md new file mode 100644 index 000000000..9cab0d0cd --- /dev/null +++ b/CODE_OF_CONDUCT.md @@ -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 + diff --git a/LICENSE b/LICENSE.md similarity index 100% rename from LICENSE rename to LICENSE.md diff --git a/README.md b/README.md index 5cf680367..71f5c5935 100644 --- a/README.md +++ b/README.md @@ -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). diff --git a/biome.json b/biome.json new file mode 100644 index 000000000..4d4b1be13 --- /dev/null +++ b/biome.json @@ -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/**"] + } +} diff --git a/package.json b/package.json new file mode 100644 index 000000000..010d97009 --- /dev/null +++ b/package.json @@ -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" + ] +} \ No newline at end of file diff --git a/rspack.config.js b/rspack.config.js new file mode 100644 index 000000000..3de92cad8 --- /dev/null +++ b/rspack.config.js @@ -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", + }, + }, +}; diff --git a/src/index.ts b/src/index.ts new file mode 100644 index 000000000..31369d3b5 --- /dev/null +++ b/src/index.ts @@ -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, +}; diff --git a/test/index.test.js b/test/index.test.js new file mode 100644 index 000000000..117453f96 --- /dev/null +++ b/test/index.test.js @@ -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"); +}); diff --git a/tsconfig.json b/tsconfig.json new file mode 100644 index 000000000..c78b7e230 --- /dev/null +++ b/tsconfig.json @@ -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" + } +}