Skip to content

Commit

Permalink
Merge pull request #313 from ryoppippi/feature/jsr-mirror-npm
Browse files Browse the repository at this point in the history
mirror jsr to npm
  • Loading branch information
ryoppippi authored Aug 30, 2024
2 parents a32c2af + abb6003 commit 419dd43
Show file tree
Hide file tree
Showing 9 changed files with 59 additions and 110 deletions.
51 changes: 51 additions & 0 deletions .github/jsr-to-npm-mirror.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
#!/usr/bin/env bun

import { $ } from 'bun';
import { join } from 'node:path';
import {tmpdir} from 'node:os';

function getTagName() {
const githubRef = Bun.env.GITHUB_REF;
if (githubRef && githubRef.startsWith("refs/tags/")) {
return githubRef.replace("refs/tags/", "");
} else {
return undefined;
}
}

const tagName = getTagName();
if (tagName == null) {
throw new Error("Could not get tag name from GITHUB_REF");
}

const versionStr = tagName.replace(/^v/, "");
const pkgName = `@jsr/ryoppippi__unplugin-typia@${versionStr}`;

/* create tmp dir */
const tmpDir = tmpdir();

$.cwd(tmpDir);

/* clone the repo */
await $`echo '@jsr:registry=https://npm.jsr.io' >> .npmrc`

await $`bun init -y && bun add ${pkgName}`;

$.cwd(join(tmpDir, 'node_modules', '@jsr', 'ryoppippi__unplugin-typia'));

const pkgJson = await $`cat ./package.json`.json();

if(pkgJson.version !== versionStr) {
throw new Error(`Version mismatch: ${pkgJson.version} !== ${versionStr}`);
}

pkgJson.name = "@ryoppippi/unplugin-typia";
pkgJson.description = "unplugin for typia";
pkgJson.repository = `https://github.com/ryoppippi/unplugin-typia.git`;
pkgJson.license = "MIT";
pkgJson.author = "ryoppippi";

await $`echo '${JSON.stringify(pkgJson, null, 2)}' > ./package.json`;

await $`npm publish --access public --provenance`;

16 changes: 0 additions & 16 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -66,28 +66,12 @@ jobs:
- run: bun run publish:jsr --dry-run
working-directory: packages/unplugin-typia

upload-pkg-pr-now:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4
- run: corepack enable
- uses: oven-sh/setup-bun@v2
with:
bun-version: ${{ env.BUN_VERSION }}
- run: bun i --frozen-lockfile
- run: |
bun run prepublishOnly
bunx pkg-pr-new publish
working-directory: packages/unplugin-typia
action-timeline:
needs:
- lint
- test
- build-examples
- jsr-publish-dry-run
- upload-pkg-pr-now
if: ${{ always() }}
runs-on: ubuntu-latest
steps:
Expand Down
7 changes: 4 additions & 3 deletions .github/workflows/release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ jobs:
working-directory: ${{env.PACKAGE_DIR}}

npm:
needs:
- jsr
runs-on: ubuntu-latest
timeout-minutes: 10
environment: Release
Expand All @@ -53,11 +55,10 @@ jobs:
- uses: oven-sh/setup-bun@v2
with:
bun-version: ${{ env.BUN_VERSION }}
- run: bun i --frozen-lockfile
- run: npm publish --provenance --access public
- run: bun run jsr-to-npm-mirror.ts
working-directory: ${{env.PACKAGE_DIR}}
env:
NODE_AUTH_TOKEN: ${{secrets.NPM_TOKEN}}
working-directory: ${{env.PACKAGE_DIR}}

release:
needs:
Expand Down
Binary file modified bun.lockb
Binary file not shown.
4 changes: 1 addition & 3 deletions packages/unplugin-typia/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -194,10 +194,8 @@ Examples:
<details>
<summary>Webpack</summary><br>

> ⚠️ Note: Currently, this plugin on JSR works only with 'esm' target.
> If you want to use 'cjs' target, please download from npm and use it.
> ⚠️ Note: Currently, this plugin works only with 'esm' target.
> If you want to download from JSR, you have following options:
> If you want to use 'cjs' target on Node < 20.17.0 , please use with [`jiti`](https://github.com/unjs/jiti).
> If you want to use 'cjs' target on Node >= 20.17.0, please use with `require` and enable [`--experimental-require-modules` flag](https://github.com/nodejs/node/pull/51977).
> If you want to use 'esm' target, don't worry! You can use this plugin without any additional setup.
Expand Down
14 changes: 1 addition & 13 deletions packages/unplugin-typia/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,6 @@
"author": "ryoppippi",
"license": "MIT",
"repository": "https://github.com/ryoppippi/unplugin-typia.git",
"keywords": [
"unplugin",
"vite",
"webpack",
"rollup",
"transform"
],
"exports": {
".": "./src/index.ts",
"./api": "./src/api.ts",
Expand All @@ -38,18 +31,14 @@
"jsrInclude": [
"jsr.json"
],
"jsrExclude": [
"dist"
],
"scripts": {
"build": "tsup",
"lint": "nr check && eslint --cache .",
"format": "eslint --cache --fix .",
"test": "vitest --typecheck --testTimeout 150000",
"check": "nr tsc --noEmit",
"release": "nr test run && nr lint && nr check && bumpp",
"publish:jsr": "nlx pkg-to-jsr && nlx jsr publish --allow-dirty",
"prepublishOnly": "nr test run && nr build && bun run ./update_package_json.ts && nlx publint"
"prepublishOnly": "nr test run && bun run ./update_package_json.ts && nlx publint"
},
"dependencies": {
"@rollup/pluginutils": "^5.1.0",
Expand Down Expand Up @@ -78,7 +67,6 @@
"eslint-plugin-format": "^0.1.2",
"rollup": "^4.20.0",
"ts-patch": "^3.2.1",
"tsup": "^8.2.4",
"vite": "^5.4.1",
"vitest": "^2.0.5"
},
Expand Down
5 changes: 2 additions & 3 deletions packages/unplugin-typia/src/webpack.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,8 @@ import unplugin from './core/index.js';
/**
* Webpack plugin
*
* Currently, this plugin on JSR works only with 'esm' target.
* If you want to use 'cjs' target, please download from npm and use it.
* If you want to download from JSR, you have following options:
* Currently, this plugin works only with 'esm' target.
*
* If you want to use 'cjs' target on Node < 20.17.0 , please use with [`jiti`](https://github.com/unjs/jiti).
* If you want to use 'cjs' target on Node >= 20.17.0, please use with `require` and enable [`--experimental-require-modules` flag](https://github.com/nodejs/node/pull/51977).
* If you want to use 'esm' target, don't worry! You can use this plugin without any additional setup.
Expand Down
11 changes: 0 additions & 11 deletions packages/unplugin-typia/tsup.config.ts

This file was deleted.

61 changes: 0 additions & 61 deletions packages/unplugin-typia/update_package_json.ts

This file was deleted.

0 comments on commit 419dd43

Please sign in to comment.