Skip to content

Commit 873a62d

Browse files
authored
Merge pull request #4 from simonkovtyk/main
Release 1.0.1
2 parents e5eb21d + de4988e commit 873a62d

File tree

5 files changed

+156
-13
lines changed

5 files changed

+156
-13
lines changed

.github/workflows/deploy.yml

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,19 @@ jobs:
2121
run: tsc
2222

2323
- name: Assets
24-
run: cp package.json dist/package.json
24+
run: |
25+
cp package.json dist/package.json
26+
cp README.md dist/README.md
27+
28+
- name: Config
29+
run: |
30+
cd dist
31+
echo "//registry.npmjs.org/:_authToken=${NPM_TOKEN}" > ~/.npmrc
32+
echo "registry=https://registry.npmjs.org/" >> ~/.npmrc
2533
2634
- name: Publish
2735
env:
2836
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
2937
run: |
3038
cd dist
31-
echo "//registry.npmjs.org/:_authToken=${NPM_TOKEN}" > ~/.npmrc
32-
echo "registry=https://registry.npmjs.org/" >> ~/.npmrc
3339
pnpm publish --access public --no-git-checks

README.md

Lines changed: 128 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,128 @@
1-
# esbuild-plugin-package-json
2-
Prepares the package.json by removing all unnecessary fields and copying it to the out folder of esbuild, so the built package can be published directly.
1+
# esbuild plugin for package.json
2+
3+
![NPM Downloads](https://img.shields.io/npm/dw/esbuild-plugin-package-json) ![NPM License](https://img.shields.io/npm/l/esbuild-plugin-package-json)
4+
5+
Prepares the package.json by removing all unnecessary fields and copying it to the out-folder of esbuild, so the built package can be published directly.
6+
7+
* Supports newest esbuild version
8+
* Uses NPM's package.json discovery
9+
* Uses esbuild config to determine the out folder
10+
* Type declarations (d.ts) included
11+
12+
## Unnecessary fields
13+
14+
While a package should be published, there are a few fields, that may are considered as a security vulnerability or are just not needed in the published package.
15+
16+
Following fields will be removed:
17+
- devDependencies
18+
- scripts
19+
20+
## How It Works
21+
22+
1. Parses the package.json from the project root.
23+
2. Deletes all unnecessary fields.
24+
3. Determines the out-folder by using the existing esbuild configuration.
25+
4. Writes the new package.json to this dir.
26+
27+
This plugin prefers an ``outdir`` over an ``outfile``, but if only an ``outfile`` is provided, the plugin will choose the directory of the ``outfile`` as output directory for the package.json instead.\
28+
The ``outbase`` is used as a prefix for the ``outdir`` or ``outfile`` and it can be left as empty, if it is not needed.
29+
30+
## Options
31+
32+
### Parsing the package.json file
33+
34+
The default behavior is, that this package will use NPM's package.json resolution.\
35+
Otherwise it may be helpful, to overwrite the path to the package.json manually:
36+
37+
```typescript
38+
packageJsonPlugin(
39+
[...]
40+
pathToPackageJson?: string | undefined
41+
);
42+
```
43+
44+
The path to the custom package.json can be customized by using the ``pathToPackageJson`` key.
45+
46+
### Output directory
47+
48+
This plugin will use the esbuild configuration to determine the output directory for the package.json.\
49+
Sometimes it can be helpful to overwrite the output directory.
50+
51+
````typescript
52+
packageJsonPlugin(
53+
[...]
54+
overrideOutBase?: string | undefined,
55+
overrideOutDir?: string | undefined,
56+
overrideOutFile?: string | undefined
57+
);
58+
````
59+
60+
Each overwrite will overwrite the specific esbuild configuration.
61+
62+
[See here for more details about the out configuration of esbuild.](https://esbuild.github.io/api/#outbase)
63+
64+
### Lifecycle
65+
66+
You can configure at which lifecycle of esbuild, where the plugin will be called.
67+
68+
````typescript
69+
packageJsonPlugin(
70+
[...]
71+
lifecycle: "onStart" | "onEnd" | "onDispose" | undefined
72+
);
73+
````
74+
75+
[See here for more about the esbuild lifecycles.](https://esbuild.github.io/plugins/#concepts)
76+
77+
## Usage
78+
79+
### Installation
80+
81+
The plugin can be installed by any package manager.
82+
83+
<details><summary><b>Show instructions</b></summary>
84+
85+
> npm \
86+
> ``npm install esbuild-plugin-package-json``
87+
88+
> yarn \
89+
> ``yarn install esbuild-plugin-package-json``
90+
91+
> pnpm \
92+
> ``pnpm install esbuild-plugin-package-json``
93+
94+
</details>
95+
96+
### Integration
97+
98+
The easy way to integrate this plugin in esbuild.
99+
100+
<details><summary><b>Show instructions</b></summary>
101+
102+
````typescript
103+
await esbuild.build({
104+
[...]
105+
plugins: [
106+
packageJsonPlugin(...)
107+
]
108+
})
109+
````
110+
111+
[See here for more about the esbuild plugin integration.](https://esbuild.github.io/plugins/#using-plugins)
112+
113+
</details>
114+
115+
## License
116+
117+
The MIT License (MIT) - Please have a look at the LICENSE file for more details.
118+
119+
## Contributing
120+
121+
Feel free to contribute to this project.\
122+
You can fork this project and create a new pull request for contributing.
123+
124+
[Get to the repository at GitHub.](https://github.com/simonkovtyk/esbuild-plugin-package-json)
125+
126+
<hr>
127+
128+
GitHub [@simonkovtyk](https://github.com/simonkovtyk)

package.json

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,21 @@
1111
"esbuild tool",
1212
"build plugin",
1313
"build tool",
14-
"package.json"
14+
"package.json",
15+
"developer tools",
16+
"build process",
17+
"plugin",
18+
"esbuild dependency",
19+
"dependency management",
20+
"optimize package json",
21+
"validate package json",
22+
"esbuild copy package json",
23+
"esbuild copy",
24+
"package json plugin",
25+
"package config plugin"
1526
],
1627
"license": "MIT",
17-
"version": "1.0.0",
28+
"version": "1.0.1",
1829
"bugs": "https://github.com/simonkovtyk/esbuild-plugin-package-json/issues",
1930
"homepage": "https://github.com/simonkovtyk/esbuild-plugin-package-json",
2031
"repository": {

src/helpers/out.helper.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,19 +4,19 @@ import { ResolvePathOptions } from "../types/options.type";
44

55
// Prefer out dir before out file
66
const resolveOutDir = (options: ResolvePathOptions): string => {
7-
const explicitOutBase: string | undefined = options.overwriteOutBase ?? options.outBase;
7+
const explicitOutBase: string | undefined = options.overrideOutBase ?? options.outBase;
88

99
const outBase = explicitOutBase
1010
? path.join(process.cwd(), explicitOutBase)
1111
: process.cwd();
1212

13-
const explicitOutDir: string | undefined = options.overwriteOutDir ?? options.outDir;
13+
const explicitOutDir: string | undefined = options.overrideOutDir ?? options.outDir;
1414

1515
if (explicitOutDir !== undefined) {
1616
return path.join(outBase, explicitOutDir);
1717
}
1818

19-
const explicitOutFile: string | undefined = options.overwriteOutFile ?? options.outFile;
19+
const explicitOutFile: string | undefined = options.overrideOutFile ?? options.outFile;
2020

2121
if (explicitOutFile !== undefined) {
2222
const dirOfOutFile = path.parse(explicitOutFile).dir;

src/types/options.type.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
type Lifecycle = "onStart" | "onEnd" | "onDispose";
22

33
type PathOverwrites = {
4-
overwriteOutBase?: string | undefined,
5-
overwriteOutDir?: string | undefined,
6-
overwriteOutFile?: string | undefined
4+
overrideOutBase?: string | undefined,
5+
overrideOutDir?: string | undefined,
6+
overrideOutFile?: string | undefined
77
}
88

99
type Options = {

0 commit comments

Comments
 (0)