Skip to content

Commit 922fe01

Browse files
committed
init project.
0 parents  commit 922fe01

File tree

27 files changed

+756
-0
lines changed

27 files changed

+756
-0
lines changed

.babelrc

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"presets": ["@babel/preset-env"],
3+
"plugins": []
4+
}

.github/FUNDING.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
ko_fi: jaywcjlove
2+
buy_me_a_coffee: jaywcjlove
3+
custom: ["https://www.paypal.me/kennyiseeyou", "https://jaywcjlove.github.io/#/sponsor"]

.github/workflows/ci.yml

Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
name: CI
2+
on:
3+
push:
4+
branches:
5+
- master
6+
jobs:
7+
build-deploy:
8+
runs-on: ubuntu-latest
9+
permissions:
10+
contents: write
11+
id-token: write
12+
steps:
13+
- uses: actions/checkout@v4
14+
- uses: actions/setup-node@v4
15+
with:
16+
node-version: 20
17+
registry-url: 'https://registry.npmjs.org'
18+
19+
- run: npm install
20+
- run: npm run build
21+
- run: npm run test
22+
23+
- name: Create idoc config
24+
run: |
25+
cat > idoc.yml << EOF
26+
site: "babel-plugin-add-import-extension {{version}}"
27+
menus:
28+
Home: index.html
29+
EOF
30+
31+
- run: npm install idoc@1 -g
32+
- run: idoc
33+
34+
- run: npm i coverage-badges-cli -g
35+
- run: coverage-badges --output dist/badges.svg
36+
37+
- name: Generate Contributors Images
38+
uses: jaywcjlove/github-action-contributors@main
39+
with:
40+
filter-author: (renovate\[bot\]|renovate-bot|dependabot\[bot\])
41+
output: dist/CONTRIBUTORS.svg
42+
avatarSize: 42
43+
44+
- run: cp -rp coverage/lcov-report dist
45+
46+
- name: Deploy
47+
uses: peaceiris/actions-gh-pages@v4
48+
with:
49+
github_token: ${{ secrets.GITHUB_TOKEN }}
50+
publish_dir: ./dist
51+
52+
- name: Create Tag
53+
id: create_tag
54+
uses: jaywcjlove/create-tag-action@main
55+
with:
56+
package-path: ./package.json
57+
58+
- name: Generate Changelog
59+
id: changelog
60+
uses: jaywcjlove/changelog-generator@main
61+
with:
62+
token: ${{ secrets.GITHUB_TOKEN }}
63+
head-ref: ${{steps.create_tag.outputs.version}}
64+
filter-author: (小弟调调™|Renovate Bot)
65+
filter: '[R|r]elease[d]\s+[v|V]\d(\.\d+){0,2}'
66+
67+
- name: Create Release
68+
uses: ncipollo/release-action@v1
69+
if: steps.create_tag.outputs.successful
70+
with:
71+
allowUpdates: true
72+
token: ${{ secrets.GITHUB_TOKEN }}
73+
name: ${{ steps.create_tag.outputs.version }}
74+
tag: ${{ steps.create_tag.outputs.version }}
75+
body: |
76+
[![](https://img.shields.io/badge/Open%20in-unpkg-blue)](https://uiwjs.github.io/npm-unpkg/#/pkg/@uiw/babel-plugin-add-import-extension@${{steps.create_tag.outputs.versionNumber}}/file/README.md) [![npm bundle size](https://img.shields.io/bundlephobia/minzip/babel-plugin-transform-remove-imports)](https://bundlephobia.com/result?p=babel-plugin-transform-remove-imports@${{steps.create_tag.outputs.versionNumber}})
77+
78+
```bash
79+
npm i @uiw/babel-plugin-add-import-extension@${{steps.create_tag.outputs.versionNumber}}
80+
```
81+
82+
${{ steps.changelog.outputs.compareurl }}
83+
84+
${{ steps.changelog.outputs.changelog }}
85+
86+
- run: npm publish --access public --provenance
87+
continue-on-error: true
88+
env:
89+
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}

.gitignore

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
/.idea/
2+
node_modules
3+
npm-debug.log*
4+
package-lock.json
5+
coverage
6+
dist
7+
lib
8+
.DS_Store
9+
.cache
10+
.vscode
11+
.env.local
12+
.env.development.local
13+
.env.test.local
14+
.env.production.local
15+
16+
17+
*.bak
18+
*.tem
19+
*.temp
20+
#.swp
21+
*.*~
22+
~*.*

LICENSE

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2020 uiw
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

README.md

Lines changed: 151 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,151 @@
1+
@uiw/babel-plugin-add-import-extension
2+
===
3+
<!--rehype:style=display: flex; height: 230px; align-items: center; justify-content: center; font-size: 38px;-->
4+
5+
[![NPM version](https://img.shields.io/npm/v/@uiw/babel-plugin-add-import-extension.svg?style=flat)](https://npmjs.org/package/@uiw/babel-plugin-add-import-extension)
6+
[![CI](https://github.com/uiwjs/babel-plugin-add-import-extension/actions/workflows/ci.yml/badge.svg)](https://github.com/uiwjs/babel-plugin-add-import-extension/actions/workflows/ci.yml)
7+
[![Coverage Status](https://uiwjs.github.io/babel-plugin-add-import-extension/badges.svg)](https://uiwjs.github.io/babel-plugin-add-import-extension/lcov-report)
8+
[![Downloadss](https://img.shields.io/npm/dm/babel-plugin-add-import-extension.svg?style=flat)](https://npmjs.org/package/babel-plugin-add-import-extension)
9+
[![Repo Dependents](https://badgen.net/github/dependents-repo/uiwjs/babel-plugin-add-import-extension)](https://github.com/uiwjs/babel-plugin-add-import-extension/network/dependents)
10+
11+
A plugin to add extensions to import and export declarations, is very useful when you use Typescript with Babel and don't want to explicity import or export module with extensions.
12+
13+
> [!WARNING]
14+
>
15+
> This is a fork of [babel-plugin-add-import-extension](https://www.npmjs.com/package/babel-plugin-add-import-extension), mainly used to add extensions when importing files in ESM packaging. If you are using an older webpack project, not all imported resources are `.js` files; they might be `.less`, `.css`, `.png`, or other files. Adding the `.js` extension directly would cause errors, so we need to add a parameter to ensure that resources that already have an extension won't have the `.js` extension added again.
16+
17+
## Usage
18+
19+
```bash
20+
npm install @uiw/babel-plugin-add-import-extension --save-dev
21+
```
22+
23+
Via `.babelrc` or `babel-loader`.
24+
25+
```json
26+
{
27+
"plugins": [
28+
[
29+
"@uiw/babel-plugin-add-import-extension", {
30+
// Add .js extension to all imports and exports
31+
"extension": "js",
32+
// Control with a boolean value, default to not processing files that already have an extension
33+
"skipExistingExtensions": true,
34+
}
35+
]
36+
]
37+
}
38+
```
39+
40+
```js
41+
// Input Code
42+
import './';
43+
import './main';
44+
import { Button } from 'uiw';
45+
import { Select } from '@uiw/core';
46+
47+
// Output ↓ ↓ ↓ ↓ ↓ ↓
48+
import './index.js';
49+
import './main.js';
50+
import { Button } from 'uiw';
51+
import { Select } from '@uiw/core';
52+
```
53+
54+
Output Result
55+
56+
```diff
57+
- import './';
58+
- import './main';
59+
+ import './index.js';
60+
+ import './main.js';
61+
import { Button } from 'uiw';
62+
import { Select } from '@uiw/core';
63+
```
64+
65+
## Options
66+
67+
### `replace`
68+
69+
* **Default:** `false`
70+
* **Behavior:** By default, if a declaration file already has an extension, it is preserved. Extensions are added to declaration files that do not have one.
71+
72+
### `extension`
73+
74+
* **Default:** `js`
75+
* **Behavior:** Appends the specified `.js` extension to `import` and `export` declarations.
76+
77+
### `skipUnlistedExtensions`
78+
79+
* **Default:** `false`
80+
* **Behavior:** If set to `true` and a declaration file has an extension that is *not* included in the `observedScriptExtensions` list, the file will be skipped.
81+
82+
### `observedScriptExtensions`
83+
84+
* **Default:** `['js', 'ts', 'jsx', 'tsx', 'mjs', 'cjs']`
85+
* **Behavior:** Declaration files with extensions present in this list are considered for extension replacement (based on the `replace` option). Files with extensions *not* in this list will have the `extension` option's value appended to them.
86+
87+
## Let's the transformation begin :)
88+
89+
A module import without extension:
90+
91+
```js
92+
import { add, double } from "./lib/numbers";
93+
```
94+
95+
will be converted to:
96+
97+
```js
98+
import { add, double } from "./lib/numbers.js";
99+
```
100+
101+
A module export without extension:
102+
103+
```js
104+
export { add, double } from "./lib/numbers";
105+
```
106+
107+
will be converted to:
108+
109+
```js
110+
export { add, double } from "./lib/numbers.js";
111+
```
112+
113+
If you add the `replace:true` option, extensions will be overwritten like so
114+
115+
```js
116+
import { add, double } from "./lib/numbers.ts";
117+
```
118+
119+
will be converted to:
120+
121+
```js
122+
import { add, double } from "./lib/numbers.js";
123+
```
124+
125+
and
126+
127+
```js
128+
export { add, double } from "./lib/numbers.ts";
129+
```
130+
131+
will be converted to:
132+
133+
```js
134+
export { add, double } from "./lib/numbers.js";
135+
```
136+
137+
What this plugin does is to check all imported modules and if your module is not on `node_module` it will consider that is a project/local module and add the choosed extension, so for node modules it don't add any extension.
138+
139+
## Contributors
140+
141+
As always, thanks to our amazing contributors!
142+
143+
<a href="https://github.com/uiwjs/babel-plugin-transform-remove-imports/graphs/contributors">
144+
<img src="https://uiwjs.github.io/babel-plugin-transform-remove-imports/CONTRIBUTORS.svg" />
145+
</a>
146+
147+
Made with [github-action-contributors](https://github.com/jaywcjlove/github-action-contributors).
148+
149+
## License
150+
151+
[MIT](./LICENSE) © [`Kenny Wong`](https://github.com/jaywcjlove) & [`Karl Prieb`](https://codeberg.org/karl)

index.d.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
interface Options {
2+
extension?: string;
3+
replace?: boolean;
4+
observedScriptExtensions?: [string];
5+
}
6+
7+
export default function _default(code: string, options: Options): any;

package.json

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
{
2+
"name": "@uiw/babel-plugin-add-import-extension",
3+
"version": "0.0.1",
4+
"description": "Remove the specified import declaration when you use the babel transform to build the package.",
5+
"repository": "https://github.com/uiwjs/babel-plugin-add-import-extension",
6+
"homepage": "https://uiwjs.github.io/babel-plugin-add-import-extension/",
7+
"typings": "./index.d.ts",
8+
"main": "lib/index.js",
9+
"scripts": {
10+
"prepare": "npm run build && npm run test",
11+
"test": "jest --coverage",
12+
"test:watch": "jest --watchAll --coverage",
13+
"build": "babel src --out-dir lib",
14+
"watch": "babel src --out-dir lib --verbose -w"
15+
},
16+
"keywords": [
17+
"babel-plugin",
18+
"kkt-ssr",
19+
"uiw",
20+
"ssr"
21+
],
22+
"jest": {
23+
"bail": true,
24+
"verbose": true,
25+
"coverageReporters": [
26+
"lcov",
27+
"json-summary"
28+
],
29+
"coveragePathIgnorePatterns": [
30+
"/test/cases"
31+
],
32+
"testMatch": [
33+
"**/*.(spec|test).js?(x)"
34+
]
35+
},
36+
"peerDependencies": {
37+
"@babel/core": "^7.0.0-0"
38+
},
39+
"dependencies": {},
40+
"devDependencies": {
41+
"@babel/cli": "7.24.7",
42+
"@babel/core": "7.24.7",
43+
"@babel/plugin-proposal-do-expressions": "7.24.7",
44+
"@babel/plugin-proposal-export-default-from": "7.24.7",
45+
"@babel/preset-env": "7.24.7",
46+
"@babel/preset-react": "7.24.7",
47+
"babel-core": "7.0.0-bridge.0",
48+
"jest": "29.7.0"
49+
},
50+
"files": [
51+
"lib",
52+
"index.d.ts"
53+
],
54+
"author": "Kenny Wong",
55+
"contributors": [
56+
"Slava Fomin II <[email protected]>"
57+
],
58+
"license": "MIT"
59+
}

renovate.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"extends": [
3+
"config:base"
4+
]
5+
}

0 commit comments

Comments
 (0)