@trenskow/esbuild-package-json 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.vscode/settings.json +7 -0
- package/LICENSE +9 -0
- package/README.md +39 -0
- package/eslint.config.js +54 -0
- package/index.d.ts +27 -0
- package/index.js +67 -0
- package/package.json +36 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
Copyright 2026 Kristian Trenskow
|
|
2
|
+
|
|
3
|
+
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
|
|
4
|
+
|
|
5
|
+
1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
|
|
6
|
+
|
|
7
|
+
2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
|
|
8
|
+
|
|
9
|
+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS “AS IS” AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
package/README.md
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
@trenskow/esbuild-package-json
|
|
2
|
+
----
|
|
3
|
+
|
|
4
|
+
A esbuild plugin for generating `package.json` files.
|
|
5
|
+
|
|
6
|
+
# Usage
|
|
7
|
+
|
|
8
|
+
````javascript
|
|
9
|
+
|
|
10
|
+
import { build } from 'esbuild';
|
|
11
|
+
import packageJson from '@trenskow/esbuild-package-json';
|
|
12
|
+
|
|
13
|
+
(async () => {
|
|
14
|
+
const res = await build({
|
|
15
|
+
entryPoints: ['./src/main.ts'],
|
|
16
|
+
bundle: true,
|
|
17
|
+
watch: true,
|
|
18
|
+
outfile: './dist/main.js',
|
|
19
|
+
plugins: [
|
|
20
|
+
packageJson({
|
|
21
|
+
source: 'package.json',
|
|
22
|
+
destination: 'dist/package.json',
|
|
23
|
+
keyPaths: ['name', 'version', /* keys to copy to */],
|
|
24
|
+
additional: {
|
|
25
|
+
/* Additional keys to be merged into destination package.json */
|
|
26
|
+
},
|
|
27
|
+
postProcess: async ({ source, destination, packageJson }) => {
|
|
28
|
+
/* Any work that needs to be done before saving. */
|
|
29
|
+
/* `packageJson` is the object that will be saved to the destination `package.json`. */
|
|
30
|
+
}
|
|
31
|
+
})
|
|
32
|
+
],
|
|
33
|
+
});
|
|
34
|
+
})();
|
|
35
|
+
````
|
|
36
|
+
|
|
37
|
+
# License
|
|
38
|
+
|
|
39
|
+
See license in LICENSE.
|
package/eslint.config.js
ADDED
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import globals from 'globals';
|
|
2
|
+
import path from 'node:path';
|
|
3
|
+
import { fileURLToPath } from 'node:url';
|
|
4
|
+
import js from '@eslint/js';
|
|
5
|
+
import { FlatCompat } from '@eslint/eslintrc';
|
|
6
|
+
|
|
7
|
+
const __filename = fileURLToPath(import.meta.url);
|
|
8
|
+
const __dirname = path.dirname(__filename);
|
|
9
|
+
const compat = new FlatCompat({
|
|
10
|
+
baseDirectory: __dirname,
|
|
11
|
+
recommendedConfig: js.configs.recommended,
|
|
12
|
+
allConfig: js.configs.all
|
|
13
|
+
});
|
|
14
|
+
|
|
15
|
+
export default [...compat.extends('eslint:recommended'), {
|
|
16
|
+
languageOptions: {
|
|
17
|
+
globals: {
|
|
18
|
+
...globals.node,
|
|
19
|
+
...globals.mocha,
|
|
20
|
+
},
|
|
21
|
+
|
|
22
|
+
ecmaVersion: 'latest',
|
|
23
|
+
sourceType: 'module',
|
|
24
|
+
},
|
|
25
|
+
|
|
26
|
+
rules: {
|
|
27
|
+
indent: ['error', 'tab', {
|
|
28
|
+
SwitchCase: 1,
|
|
29
|
+
}],
|
|
30
|
+
|
|
31
|
+
'linebreak-style': ['error', 'unix'],
|
|
32
|
+
quotes: ['error', 'single'],
|
|
33
|
+
semi: ['error', 'always'],
|
|
34
|
+
|
|
35
|
+
'no-console': ['error', {
|
|
36
|
+
allow: ['warn', 'error', 'info'],
|
|
37
|
+
}],
|
|
38
|
+
|
|
39
|
+
'no-unused-vars': ['error', {
|
|
40
|
+
argsIgnorePattern: '^_',
|
|
41
|
+
}],
|
|
42
|
+
|
|
43
|
+
'no-empty': ['error', {
|
|
44
|
+
allowEmptyCatch: true,
|
|
45
|
+
}],
|
|
46
|
+
|
|
47
|
+
'no-trailing-spaces': ['error', {
|
|
48
|
+
ignoreComments: true,
|
|
49
|
+
}],
|
|
50
|
+
|
|
51
|
+
'require-atomic-updates': 'off',
|
|
52
|
+
'eol-last': ['error', 'always'],
|
|
53
|
+
},
|
|
54
|
+
}];
|
package/index.d.ts
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
//
|
|
2
|
+
// index.d.ts
|
|
3
|
+
// @trenskow/esbuild-package-json
|
|
4
|
+
//
|
|
5
|
+
// Created by Kristian Trenskow on 2024/12/18
|
|
6
|
+
// See license in LICENSE.
|
|
7
|
+
//
|
|
8
|
+
|
|
9
|
+
import { Plugin } from 'esbuild';
|
|
10
|
+
|
|
11
|
+
interface PostProcessOptions {
|
|
12
|
+
source: string;
|
|
13
|
+
destination: string;
|
|
14
|
+
packageJson: Record<string, any>;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
interface PackageJsonOptions {
|
|
18
|
+
source?: string = 'package.json';
|
|
19
|
+
destination: string;
|
|
20
|
+
keyPaths?: string[];
|
|
21
|
+
additional?: Record<string, any>;
|
|
22
|
+
postProcess?: (options: PostProcessOptions) => Promise<void> | void;
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
export default function packageJsonPlugin(
|
|
26
|
+
options: PackageJsonOptions
|
|
27
|
+
): Plugin;
|
package/index.js
ADDED
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
//
|
|
2
|
+
// index.js
|
|
3
|
+
// @trenskow/esbuild-package-json
|
|
4
|
+
//
|
|
5
|
+
// Created by Kristian Trenskow on 2024/12/18
|
|
6
|
+
// See license in LICENSE.
|
|
7
|
+
//
|
|
8
|
+
|
|
9
|
+
import { dirname } from 'path';
|
|
10
|
+
import { readFile, writeFile, mkdir } from 'fs/promises';
|
|
11
|
+
|
|
12
|
+
import keyd from 'keyd';
|
|
13
|
+
|
|
14
|
+
export default ({
|
|
15
|
+
source = 'package.json',
|
|
16
|
+
destination,
|
|
17
|
+
keyPaths,
|
|
18
|
+
additional = {},
|
|
19
|
+
postProcess
|
|
20
|
+
} = {}) => {
|
|
21
|
+
|
|
22
|
+
if (!source) {
|
|
23
|
+
throw new Error('[package-json] source is required');
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
return {
|
|
27
|
+
name: 'package-json',
|
|
28
|
+
|
|
29
|
+
setup(build) {
|
|
30
|
+
build.onStart(async () => {
|
|
31
|
+
|
|
32
|
+
console.info('[processing] package.json');
|
|
33
|
+
|
|
34
|
+
await mkdir(dirname(destination), { recursive: true });
|
|
35
|
+
|
|
36
|
+
const sourceContent = await readFile(source, 'utf8');
|
|
37
|
+
|
|
38
|
+
keyPaths = keyPaths || keyd(sourceContent).keyPaths();
|
|
39
|
+
|
|
40
|
+
const indentation = sourceContent.match(/^( +|\t)/m)
|
|
41
|
+
?.sort((a, b) => a.length - b.length)?.[0] || ' ';
|
|
42
|
+
|
|
43
|
+
const sourcePackageJson = JSON.parse(sourceContent);
|
|
44
|
+
|
|
45
|
+
const destinationPackageJson = Object.assign({}, keyPaths.reduce((accumulator, keyPath) => {
|
|
46
|
+
const value = keyd(sourcePackageJson).get(keyPath);
|
|
47
|
+
if (typeof value !== 'undefined') {
|
|
48
|
+
keyd(accumulator).set(keyPath, value);
|
|
49
|
+
}
|
|
50
|
+
return accumulator;
|
|
51
|
+
}, {}), additional);
|
|
52
|
+
|
|
53
|
+
if (typeof postProcess === 'function') {
|
|
54
|
+
await postProcess({
|
|
55
|
+
source,
|
|
56
|
+
destination,
|
|
57
|
+
packageJson: destinationPackageJson
|
|
58
|
+
});
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
await writeFile(destination, JSON.stringify(destinationPackageJson, null, indentation), 'utf8');
|
|
62
|
+
|
|
63
|
+
});
|
|
64
|
+
}
|
|
65
|
+
};
|
|
66
|
+
|
|
67
|
+
};
|
package/package.json
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@trenskow/esbuild-package-json",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "A esbuild plugin for generating `package.json` files.",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"esbuild",
|
|
7
|
+
"package",
|
|
8
|
+
"json"
|
|
9
|
+
],
|
|
10
|
+
"homepage": "https://github.com/trenskow/esbuild-package-json#readme",
|
|
11
|
+
"bugs": {
|
|
12
|
+
"url": "https://github.com/trenskow/esbuild-package-json/issues"
|
|
13
|
+
},
|
|
14
|
+
"repository": {
|
|
15
|
+
"type": "git",
|
|
16
|
+
"url": "git+https://github.com/trenskow/esbuild-package-json.git"
|
|
17
|
+
},
|
|
18
|
+
"license": "BSD-2-Clause",
|
|
19
|
+
"author": "Kristian Trenskow <this.is@kristians.email>",
|
|
20
|
+
"type": "module",
|
|
21
|
+
"main": "index.js",
|
|
22
|
+
"scripts": {
|
|
23
|
+
"test": "echo \"Error: no test specified\" && exit 1"
|
|
24
|
+
},
|
|
25
|
+
"dependencies": {
|
|
26
|
+
"esbuild": "^0.27.2",
|
|
27
|
+
"keyd": "^2.1.50"
|
|
28
|
+
},
|
|
29
|
+
"devDependencies": {
|
|
30
|
+
"@eslint/compat": "^2.0.2",
|
|
31
|
+
"@eslint/eslintrc": "^3.3.3",
|
|
32
|
+
"@eslint/js": "^9.39.2",
|
|
33
|
+
"eslint": "^9.39.2",
|
|
34
|
+
"globals": "^17.3.0"
|
|
35
|
+
}
|
|
36
|
+
}
|