Skip to content

Commit

Permalink
feat(bundle): change bundling configuration
Browse files Browse the repository at this point in the history
  • Loading branch information
imjuni committed Apr 28, 2024
1 parent f9c0ed3 commit 9e969a5
Show file tree
Hide file tree
Showing 23 changed files with 835 additions and 3,054 deletions.
34 changes: 34 additions & 0 deletions .configs/esbuild.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import * as esbuild from 'esbuild';
import readPkg from 'read-pkg';

const pkg = readPkg.sync();

if (process.env.FORMAT !== 'cjs' && process.env.FORMAT !== 'esm') {
console.log(`support "cjs" or "esm"`);
console.log(`eg. FORMAT=cjs node esbuild.mjs`);

process.exit(1);
}

console.log('esbuild start bundling');
console.log(`version: ${pkg.version}`);
console.log(`FORMAT: ${process.env.FORMAT}`);
console.log(`MINIFY: ${process.env.FORMAT}`);

console.log('external: ');

await esbuild.build({
entryPoints: ['src/index.ts'],
target: 'es2021',
bundle: true,
sourcemap: true,
platform: 'node',
minify: process.env.MINIFY === 'true',
outfile: process.env.FORMAT === 'cjs' ? 'dist/cjs/index.cjs' : 'dist/esm/index.mjs',
format: process.env.FORMAT,
external: [
...Object.keys(pkg.dependencies ?? {}),
...Object.keys(pkg.devDependencies ?? {}),
...Object.keys(pkg.peerDependencies ?? {}),
],
});
1 change: 0 additions & 1 deletion .configs/jest.setup.cjs

This file was deleted.

35 changes: 0 additions & 35 deletions .configs/rollup.config.dev.ts

This file was deleted.

28 changes: 28 additions & 0 deletions .configs/rollup.config.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import { nodeResolve } from '@rollup/plugin-node-resolve';
import readPackage from 'read-pkg';
import { dts } from 'rollup-plugin-dts';

const pkg = readPackage.sync();

const resolveOnly = (module) => {
return (
pkg?.dependencies?.[module] != null &&
pkg?.devDependencies?.[module] != null &&
pkg?.peerDependencies?.[module] != null
);
};

const config = [
{
input: 'dist/types/origin/index.d.ts',
output: [{ file: 'dist/types/index.d.ts', format: 'esm' }],
plugins: [
nodeResolve({ resolveOnly }),
dts({
tsconfig: './tsconfig.dts.json',
}),
],
},
];

export default config;
79 changes: 0 additions & 79 deletions .configs/rollup.config.prod.ts

This file was deleted.

2 changes: 1 addition & 1 deletion .eslintrc.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ module.exports = {
ignorePatterns: ['__test__/*', '__tests__/*', 'examples/*', 'coverage/*', 'dist/*'],
parser: '@typescript-eslint/parser',
parserOptions: {
project: 'tsconfig.eslint.json',
project: './tsconfig.eslint.json',
tsconfigRootDir: __dirname,
},
extends: [
Expand Down
16 changes: 11 additions & 5 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,18 +16,24 @@ jobs:

strategy:
matrix:
node-version: [16.x, 18.x, 20.x]
node-version: [18.x, 20.x]
# See supported Node.js release schedule at https://nodejs.org/en/about/releases/

steps:
- uses: actions/checkout@v3
- uses: pnpm/action-setup@v2
with:
version: 8
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v3
with:
node-version: ${{ matrix.node-version }}
cache: 'npm'
- run: npm ci
- run: npm run build
- run: npm test
cache: 'pnpm'
- run: pnpm install
- run: pnpm run build
- run: pnpm run clean
- run: pnpm run test
- name: Upload coverage to Codecov
uses: codecov/codecov-action@v3
env:
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
6 changes: 3 additions & 3 deletions .husky/pre-commit
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,15 @@ yellow='\033[0;33m'
no_color='\033[0m'

echo -e "\n ${yellow}* code lint start.${no_color}"
npm run lint-staged
pnpm run lint-staged
echo -e "\n ${yellow}* code lint end.${no_color}"

echo -e "\n ${yellow}* code build start.${no_color}"
npm run build
pnpm run build
echo -e "\n ${yellow}* code build end.${no_color}"

echo -e "\n ${yellow}* code build start.${no_color}"
npm run test
pnpm run test
echo -e "\n ${yellow}* code build end.${no_color}"

echo -e "\n ${green}* pre-commit hook was SUCCESSFUL${no_color} \n"
3 changes: 2 additions & 1 deletion .prettierrc
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
{
"singleQuote": true,
"trailingComma": "all",
"printWidth": 100,
"printWidth": 120,
"arrowParens": "always",
"parser": "typescript",
"plugins": ["prettier-plugin-organize-imports"],
"endOfLine": "lf",
"overrides": [
{
Expand Down
45 changes: 39 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@
[![License](https://img.shields.io/npm/l/url-naong.svg)](https://github.com/imjuni/url-naong/blob/master/LICENSE)
[![url-naong](https://circleci.com/gh/imjuni/url-naong.svg?style=shield)](https://app.circleci.com/pipelines/github/imjuni/url-naong?branch=master)

url-naong is url builder that is inspired by [urlcat](https://github.com/balazsbotond/urlcat)
`url-naong` is a simple url builder. The [URL](https://developer.mozilla.org/en-US/docs/Web/API/URL) class is great, but it doesn't allow you to apply variables to pathnames and arrays to querystrings. This is where `url-naong` comes in handy. url-naong is url builder that is inspired by [urlcat](https://github.com/balazsbotond/urlcat)

naong is korean name of Meowth(pokemon monster)
naong is korean name of [Meowth(pokemon monster)](https://www.pokemon.com/us/pokedex/meowth)

## install

Expand All @@ -19,11 +19,44 @@ npm install url-naong --save

## Usage

```ts
const urlna = require('url-naong').default;
`urlna` function take 4 parameters.

1. (required) host
2. (required) pathname
3. (optional) path parameters and querystring
4. (optional) options of the qs library

### Variable in pathname

```js
const urlna = require('url-naong').urlna;

const url = urlna(undefined, '/hero/:hid/comic/:cid/name/:name',
{ name: 'ironman', hid: 1, cid: 13, tid: '72368bb0-a6cc-4fa1-9288-c903fd45c333', }
{
hid: 1, // evaluate in pathname
cid: 13, // evaluate in pathname
name: 'ironman', // evaluate in pathname
tid: '72368bb0-a6cc-4fa1-9288-c903fd45c333' // evaluate in querystring
}
);

console.log(url);

// created> '/hero/1/comic/13/name/ironman?tid=72368bb0-a6cc-4fa1-9288-c903fd45c333'
```

### Querystring

```js
const urlna = require('url-naong').urlna;

const url = urlna(undefined, '/hero/:hid/comic/:cid/name/:name',
{
hid: 1, // evaluate in pathname
cid: 13, // evaluate in pathname
name: 'ironman', // evaluate in pathname
tid: '72368bb0-a6cc-4fa1-9288-c903fd45c333' // evaluate in querystring
}
);

console.log(url);
Expand All @@ -34,7 +67,7 @@ console.log(url);
## TypeScript

```ts
import urlna from 'url-naong';
import { urlna } from 'url-naong';

const url = urlna(undefined, '/hero/:hid/comic/:cid/name/:name',
{ name: 'ironman', hid: 1, cid: 13, tid: '72368bb0-a6cc-4fa1-9288-c903fd45c333', }
Expand Down
10 changes: 10 additions & 0 deletions examples/cjs/path-variable.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
const urlna = require('../../dist/cjs/index.cjs').urlna;

const url = urlna('', 'hero/:hid/comic/:cid/name/:name', {
name: 'ironman',
hid: 1,
cid: 13,
tid: '72368bb0-a6cc-4fa1-9288-c903fd45c333',
});

console.log(url);
21 changes: 21 additions & 0 deletions examples/cjs/qs-array.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
const urlna = require('../../dist/cjs/index.cjs').urlna;

const url01 = urlna('', 'heros/comics', {
name: ['ironman', 'spiderman'],
tid: '72368bb0-a6cc-4fa1-9288-c903fd45c333',
});

const url02 = urlna(
'',
'heros/comics',
{
name: ['ironman', 'spiderman'],
tid: '72368bb0-a6cc-4fa1-9288-c903fd45c333',
},
{
indices: false,
},
);

console.log(url01);
console.log(url02);
10 changes: 10 additions & 0 deletions examples/esm/path-variable.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { urlna } from '../../dist/esm/index.mjs';

const url = urlna('', 'hero/:hid/comic/:cid/name/:name', {
name: 'ironman',
hid: 1,
cid: 13,
tid: '72368bb0-a6cc-4fa1-9288-c903fd45c333',
});

console.log(url);
21 changes: 21 additions & 0 deletions examples/esm/qs-array.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import { urlna } from '../../dist/esm/index.mjs';

const url01 = urlna('', 'heros/comics', {
name: ['ironman', 'spiderman'],
tid: '72368bb0-a6cc-4fa1-9288-c903fd45c333',
});

const url02 = urlna(
'',
'heros/comics',
{
name: ['ironman', 'spiderman'],
tid: '72368bb0-a6cc-4fa1-9288-c903fd45c333',
},
{
arrayFormat: 'repeat',
},
);

console.log(url01);
console.log(url02);
10 changes: 0 additions & 10 deletions jest.config.cjs

This file was deleted.

Loading

0 comments on commit 9e969a5

Please sign in to comment.