Skip to content

Commit 17e70c4

Browse files
antfusxzzstarknt
committed
feat: poc working, thanks to
Co-authored-by: sxzz <[email protected]> Co-authored-by: starknt <[email protected]>
0 parents  commit 17e70c4

17 files changed

+5184
-0
lines changed

.github/FUNDING.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
github: [antfu]

.github/workflows/ci.yml

Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
name: CI
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
8+
pull_request:
9+
branches:
10+
- main
11+
12+
jobs:
13+
lint:
14+
runs-on: ubuntu-latest
15+
steps:
16+
- uses: actions/checkout@v3
17+
18+
- name: Install pnpm
19+
uses: pnpm/action-setup@v2
20+
21+
- name: Set node
22+
uses: actions/setup-node@v3
23+
with:
24+
node-version: lts/*
25+
26+
- name: Setup
27+
run: npm i -g @antfu/ni
28+
29+
- name: Install
30+
run: nci
31+
32+
- name: Lint
33+
run: nr lint
34+
35+
typecheck:
36+
runs-on: ubuntu-latest
37+
steps:
38+
- uses: actions/checkout@v3
39+
40+
- name: Install pnpm
41+
uses: pnpm/action-setup@v2
42+
43+
- name: Set node
44+
uses: actions/setup-node@v3
45+
with:
46+
node-version: lts/*
47+
48+
- name: Setup
49+
run: npm i -g @antfu/ni
50+
51+
- name: Install
52+
run: nci
53+
54+
- name: Typecheck
55+
run: nr typecheck
56+
57+
test:
58+
runs-on: ${{ matrix.os }}
59+
60+
strategy:
61+
matrix:
62+
node: [lts/*]
63+
os: [ubuntu-latest, windows-latest, macos-latest]
64+
fail-fast: false
65+
66+
steps:
67+
- uses: actions/checkout@v3
68+
69+
- name: Install pnpm
70+
uses: pnpm/action-setup@v2
71+
72+
- name: Set node ${{ matrix.node }}
73+
uses: actions/setup-node@v3
74+
with:
75+
node-version: ${{ matrix.node }}
76+
77+
- name: Setup
78+
run: npm i -g @antfu/ni
79+
80+
- name: Install
81+
run: nci
82+
83+
- name: Build
84+
run: nr build
85+
86+
- name: Test
87+
run: nr test

.github/workflows/release.yml

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
name: Release
2+
3+
permissions:
4+
contents: write
5+
6+
on:
7+
push:
8+
tags:
9+
- 'v*'
10+
11+
jobs:
12+
release:
13+
runs-on: ubuntu-latest
14+
steps:
15+
- uses: actions/checkout@v3
16+
with:
17+
fetch-depth: 0
18+
19+
- name: Install pnpm
20+
uses: pnpm/action-setup@v2
21+
22+
- name: Set node
23+
uses: actions/setup-node@v3
24+
with:
25+
node-version: lts/*
26+
27+
- run: npx changelogithub
28+
env:
29+
GITHUB_TOKEN: ${{secrets.GITHUB_TOKEN}}

.gitignore

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
.cache
2+
.DS_Store
3+
.idea
4+
*.log
5+
*.tgz
6+
coverage
7+
dist
8+
lib-cov
9+
logs
10+
node_modules
11+
temp

.npmrc

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
ignore-workspace-root-check=true
2+
shell-emulator=true

.vscode/settings.json

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
{
2+
// Enable the ESlint flat config support
3+
"eslint.experimental.useFlatConfig": true,
4+
5+
// Disable the default formatter, use eslint instead
6+
"prettier.enable": false,
7+
"editor.formatOnSave": false,
8+
9+
// Auto fix
10+
"editor.codeActionsOnSave": {
11+
"source.fixAll": "explicit",
12+
"source.organizeImports": "never"
13+
},
14+
15+
// Silent the stylistic rules in you IDE, but still auto fix them
16+
"eslint.rules.customizations": [
17+
{ "rule": "style/*", "severity": "off" },
18+
{ "rule": "*-indent", "severity": "off" },
19+
{ "rule": "*-spacing", "severity": "off" },
20+
{ "rule": "*-spaces", "severity": "off" },
21+
{ "rule": "*-order", "severity": "off" },
22+
{ "rule": "*-dangle", "severity": "off" },
23+
{ "rule": "*-newline", "severity": "off" },
24+
{ "rule": "*quotes", "severity": "off" },
25+
{ "rule": "*semi", "severity": "off" }
26+
],
27+
28+
// Enable eslint for all supported languages
29+
"eslint.validate": [
30+
"javascript",
31+
"javascriptreact",
32+
"typescript",
33+
"typescriptreact",
34+
"vue",
35+
"html",
36+
"markdown",
37+
"json",
38+
"jsonc",
39+
"yaml"
40+
]
41+
}

CONTRIBUTING.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Please refer to https://github.com/antfu/contribute

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) 2022 Anthony Fu <https://github.com/antfu>
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: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
# magic-string-stack
2+
3+
[![npm version][npm-version-src]][npm-version-href]
4+
[![npm downloads][npm-downloads-src]][npm-downloads-href]
5+
[![bundle][bundle-src]][bundle-href]
6+
[![JSDocs][jsdocs-src]][jsdocs-href]
7+
[![License][license-src]][license-href]
8+
9+
`magic-string` with the capability of committing changes.
10+
11+
## Usages
12+
13+
```ts
14+
import MagicStringStack from 'magic-string-stack'
15+
16+
const s = new MagicStringStack('problems = 99')
17+
18+
s.replace('problems', 'issues')
19+
.append('var ')
20+
21+
s.toString() // 'var issues = 99'
22+
s.original // 'problems = 99' (original string)
23+
24+
s.commit() // this will commit the changes
25+
26+
s.original // 'var issues = 99' (applied with previous changes)
27+
s.replace('issues', 'problems')
28+
s.toString() // 'var problems = 99'
29+
30+
s.generateMap() // generate sourcemap, if multiple commits happend, it will generate a combined sourcemap
31+
```
32+
33+
## Sponsors
34+
35+
<p align="center">
36+
<a href="https://cdn.jsdelivr.net/gh/antfu/static/sponsors.svg">
37+
<img src='https://cdn.jsdelivr.net/gh/antfu/static/sponsors.svg'/>
38+
</a>
39+
</p>
40+
41+
## License
42+
43+
[MIT](./LICENSE) License © 2023-PRESENT [Anthony Fu](https://github.com/antfu)
44+
45+
<!-- Badges -->
46+
47+
[npm-version-src]: https://img.shields.io/npm/v/magic-string-stack?style=flat&colorA=080f12&colorB=1fa669
48+
[npm-version-href]: https://npmjs.com/package/magic-string-stack
49+
[npm-downloads-src]: https://img.shields.io/npm/dm/magic-string-stack?style=flat&colorA=080f12&colorB=1fa669
50+
[npm-downloads-href]: https://npmjs.com/package/magic-string-stack
51+
[bundle-src]: https://img.shields.io/bundlephobia/minzip/magic-string-stack?style=flat&colorA=080f12&colorB=1fa669&label=minzip
52+
[bundle-href]: https://bundlephobia.com/result?p=magic-string-stack
53+
[license-src]: https://img.shields.io/github/license/antfu/magic-string-stack.svg?style=flat&colorA=080f12&colorB=1fa669
54+
[license-href]: https://github.com/antfu/magic-string-stack/blob/main/LICENSE
55+
[jsdocs-src]: https://img.shields.io/badge/jsdocs-reference-080f12?style=flat&colorA=080f12&colorB=1fa669
56+
[jsdocs-href]: https://www.jsdocs.io/package/magic-string-stack

build.config.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import { defineBuildConfig } from 'unbuild'
2+
3+
export default defineBuildConfig({
4+
entries: [
5+
'src/index',
6+
],
7+
declaration: true,
8+
clean: true,
9+
rollup: {
10+
emitCJS: true,
11+
},
12+
})

eslint.config.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
// @ts-check
2+
import antfu from '@antfu/eslint-config'
3+
4+
export default antfu(
5+
{
6+
ignores: [
7+
// eslint ignore globs here
8+
],
9+
},
10+
{
11+
rules: {
12+
// overrides
13+
},
14+
},
15+
)

package.json

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
{
2+
"name": "magic-string-stack",
3+
"type": "module",
4+
"version": "0.0.0",
5+
"packageManager": "[email protected]",
6+
"description": "magic-string with the capability of committing changes",
7+
"author": "Anthony Fu <[email protected]>",
8+
"license": "MIT",
9+
"funding": "https://github.com/sponsors/antfu",
10+
"homepage": "https://github.com/antfu/magic-string-stack#readme",
11+
"repository": {
12+
"type": "git",
13+
"url": "git+https://github.com/antfu/magic-string-stack.git"
14+
},
15+
"bugs": "https://github.com/antfu/magic-string-stack/issues",
16+
"keywords": [],
17+
"sideEffects": false,
18+
"exports": {
19+
".": {
20+
"types": "./dist/index.d.ts",
21+
"import": "./dist/index.mjs",
22+
"require": "./dist/index.cjs"
23+
}
24+
},
25+
"main": "./dist/index.mjs",
26+
"module": "./dist/index.mjs",
27+
"types": "./dist/index.d.ts",
28+
"typesVersions": {
29+
"*": {
30+
"*": [
31+
"./dist/*",
32+
"./dist/index.d.ts"
33+
]
34+
}
35+
},
36+
"files": [
37+
"dist"
38+
],
39+
"scripts": {
40+
"build": "unbuild",
41+
"dev": "unbuild --stub",
42+
"lint": "eslint .",
43+
"prepublishOnly": "nr build",
44+
"release": "bumpp && npm publish",
45+
"start": "esno src/index.ts",
46+
"test": "vitest",
47+
"typecheck": "tsc --noEmit",
48+
"prepare": "simple-git-hooks"
49+
},
50+
"dependencies": {
51+
"@ampproject/remapping": "^2.3.0",
52+
"magic-string": "^0.30.9"
53+
},
54+
"devDependencies": {
55+
"@antfu/eslint-config": "^2.6.4",
56+
"@antfu/ni": "^0.21.12",
57+
"@antfu/utils": "^0.7.7",
58+
"@types/node": "^20.11.19",
59+
"bumpp": "^9.3.0",
60+
"eslint": "^8.56.0",
61+
"esno": "^4.0.0",
62+
"lint-staged": "^15.2.2",
63+
"pnpm": "^8.15.3",
64+
"rimraf": "^5.0.5",
65+
"simple-git-hooks": "^2.9.0",
66+
"typescript": "^5.3.3",
67+
"unbuild": "^2.0.0",
68+
"vite": "^5.1.4",
69+
"vitest": "^1.3.1"
70+
},
71+
"simple-git-hooks": {
72+
"pre-commit": "pnpm lint-staged"
73+
},
74+
"lint-staged": {
75+
"*": "eslint --fix"
76+
}
77+
}

0 commit comments

Comments
 (0)