screw-up 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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) Kouji Matsui (@kekyo@mi.kekyo.net)
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.
package/README.md ADDED
@@ -0,0 +1,174 @@
1
+ # Screw-UP
2
+
3
+ Simply package metadata inserter for Vite plugins.
4
+
5
+ [![Project Status: WIP – Initial development is in progress, but there has not yet been a stable, usable release suitable for the public.](https://www.repostatus.org/badges/latest/wip.svg)](https://www.repostatus.org/#wip)
6
+ [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
7
+ [![npm version](https://img.shields.io/npm/v/screw-up.svg)](https://www.npmjs.com/package/screw-up)
8
+
9
+ ----
10
+
11
+ ## What is this?
12
+
13
+ This is a Vite plugin that automatically inserts banner comments containing package metadata (name, version, description, author, license) into your bundled JavaScript/CSS files.
14
+
15
+ This will automatically read metadata from your `package.json`:
16
+
17
+ ```json
18
+ {
19
+ "name": "my-awesome-library",
20
+ "version": "2.1.0",
21
+ "description": "An awesome TypeScript library",
22
+ "author": "Jane Developer <jane@example.com>",
23
+ "license": "Apache-2.0"
24
+ }
25
+ ```
26
+
27
+ To insert banner header each bundled source files (`dist/index.js` and etc.):
28
+
29
+ ```javascript
30
+ /*!
31
+ * my-awesome-library 2.1.0
32
+ * An awesome TypeScript library
33
+ * Author: Jane Developer <jane@example.com>
34
+ * License: "Apache-2.0
35
+ */
36
+ // Your bundled code here...
37
+ ```
38
+
39
+ * Reads metadata from `package.json`.
40
+ * Supports both ESM and CommonJS outputs.
41
+ * Customizable banner templates.
42
+
43
+ ## Installation
44
+
45
+ ```bash
46
+ npm install --save-dev screw-up
47
+ ```
48
+
49
+ ----
50
+
51
+ ## Usage
52
+
53
+ ### Basic Usage
54
+
55
+ Add the plugin to your `vite.config.ts`:
56
+
57
+ ```typescript
58
+ import { defineConfig } from 'vite';
59
+ import { screwUp } from 'screw-up'; // Need to this
60
+
61
+ export default defineConfig({
62
+ plugins: [
63
+ screwUp() // Need to this
64
+ ],
65
+ build: {
66
+ lib: {
67
+ entry: 'src/index.ts',
68
+ name: 'MyLibrary',
69
+ fileName: 'index'
70
+ }
71
+ }
72
+ });
73
+ ```
74
+
75
+ ### Custom Banner Template
76
+
77
+ You can provide a custom banner template:
78
+
79
+ ```typescript
80
+ import { defineConfig } from 'vite';
81
+ import { screwUp } from 'screw-up';
82
+
83
+ export default defineConfig({
84
+ plugins: [
85
+ screwUp({
86
+ bannerTemplate: '/* My Custom Header - Built with ❤️ */'
87
+ })
88
+ ],
89
+ build: {
90
+ lib: {
91
+ entry: 'src/index.ts',
92
+ name: 'MyLibrary',
93
+ fileName: 'index'
94
+ }
95
+ }
96
+ });
97
+ ```
98
+
99
+ ### Custom Package Path
100
+
101
+ Specify a different path to your package.json:
102
+
103
+ ```typescript
104
+ import { defineConfig } from 'vite';
105
+ import { screwUp } from 'screw-up';
106
+
107
+ export default defineConfig({
108
+ plugins: [
109
+ screwUp({
110
+ packagePath: './packages/core/package.json'
111
+ })
112
+ ]
113
+ });
114
+ ```
115
+
116
+ ## Advanced Usage
117
+
118
+ ### Working with Monorepos
119
+
120
+ In monorepo setups, you might want to reference a specific package's metadata:
121
+
122
+ ```typescript
123
+ import { defineConfig } from 'vite';
124
+ import { screwUp } from 'screw-up';
125
+
126
+ export default defineConfig({
127
+ plugins: [
128
+ screwUp({
129
+ packagePath: '../../packages/ui/package.json'
130
+ })
131
+ ],
132
+ build: {
133
+ lib: {
134
+ entry: 'src/index.ts',
135
+ name: 'UILibrary',
136
+ fileName: 'ui'
137
+ }
138
+ }
139
+ });
140
+ ```
141
+
142
+ ### Programmatic Banner Generation
143
+
144
+ You can also use the utility functions directly:
145
+
146
+ ```typescript
147
+ import { generateBanner, readPackageMetadata } from 'screw-up';
148
+
149
+ // Read package metadata
150
+ const metadata = readPackageMetadata('./package.json');
151
+
152
+ // Generate banner
153
+ const banner = generateBanner({
154
+ name: 'my-package',
155
+ version: '1.0.0',
156
+ description: 'A great package',
157
+ author: 'Developer Name',
158
+ license: 'MIT'
159
+ });
160
+
161
+ console.log(banner);
162
+ // /*!
163
+ // * my-package v1.0.0
164
+ // * A great package
165
+ // * Author: Developer Name
166
+ // * License: MIT
167
+ // */
168
+ ```
169
+
170
+ ----
171
+
172
+ ## License
173
+
174
+ Under MIT
package/dist/index.cjs ADDED
@@ -0,0 +1,60 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
+ const fs = require("fs");
4
+ const path = require("path");
5
+ const generateBanner = (metadata) => {
6
+ const name = metadata.name || "Unknown Package";
7
+ const version = metadata.version || "0.0.0";
8
+ const description = metadata.description || "";
9
+ let author = "";
10
+ if (metadata.author) {
11
+ if (typeof metadata.author === "string") {
12
+ author = metadata.author;
13
+ } else {
14
+ author = metadata.author.email ? `${metadata.author.name} <${metadata.author.email}>` : metadata.author.name;
15
+ }
16
+ }
17
+ const license = metadata.license || "";
18
+ const parts = [
19
+ `${name} ${version}`,
20
+ description && `${description}`,
21
+ author && `Author: ${author}`,
22
+ license && `License: ${license}`
23
+ ].filter(Boolean);
24
+ return `/*!
25
+ * ${parts.join("\n * ")}
26
+ */`;
27
+ };
28
+ const readPackageMetadata = (packagePath) => {
29
+ try {
30
+ const content = fs.readFileSync(packagePath, "utf-8");
31
+ return JSON.parse(content);
32
+ } catch (error) {
33
+ console.warn(`Failed to read package.json from ${packagePath}:`, error);
34
+ return {};
35
+ }
36
+ };
37
+ const screwUp = (options = {}) => {
38
+ const { packagePath = "./package.json", bannerTemplate } = options;
39
+ let banner;
40
+ return {
41
+ name: "screw-up",
42
+ apply: "build",
43
+ configResolved(config) {
44
+ const resolvedPackagePath = path.resolve(config.root, packagePath);
45
+ const metadata = readPackageMetadata(resolvedPackagePath);
46
+ banner = bannerTemplate || generateBanner(metadata);
47
+ },
48
+ generateBundle(_options, bundle) {
49
+ for (const fileName in bundle) {
50
+ const chunk = bundle[fileName];
51
+ if (chunk.type === "chunk") {
52
+ chunk.code = banner + "\n" + chunk.code;
53
+ }
54
+ }
55
+ }
56
+ };
57
+ };
58
+ exports.generateBanner = generateBanner;
59
+ exports.readPackageMetadata = readPackageMetadata;
60
+ exports.screwUp = screwUp;
@@ -0,0 +1,44 @@
1
+ import { Plugin } from 'vite';
2
+
3
+ interface PackageMetadata {
4
+ name?: string;
5
+ version?: string;
6
+ description?: string;
7
+ author?: string | {
8
+ name: string;
9
+ email?: string;
10
+ };
11
+ license?: string;
12
+ }
13
+ /**
14
+ * Generate banner string from package.json metadata
15
+ * @param metadata - Package metadata
16
+ * @returns Banner string
17
+ */
18
+ export declare const generateBanner: (metadata: PackageMetadata) => string;
19
+ /**
20
+ * Read and parse package.json file
21
+ * @param packagePath - Path to package.json
22
+ * @returns Package metadata
23
+ */
24
+ export declare const readPackageMetadata: (packagePath: string) => PackageMetadata;
25
+ export interface ScrewUpOptions {
26
+ /**
27
+ * Path to package.json file
28
+ * @default "./package.json"
29
+ */
30
+ packagePath?: string;
31
+ /**
32
+ * Custom banner template
33
+ * @default undefined (uses built-in template)
34
+ */
35
+ bannerTemplate?: string;
36
+ }
37
+ /**
38
+ * Vite plugin that adds banner to the bundled code
39
+ * @param options - Plugin options
40
+ * @returns Vite plugin
41
+ */
42
+ export declare const screwUp: (options?: ScrewUpOptions) => Plugin;
43
+ export {};
44
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,MAAM,CAAC;AAInC,UAAU,eAAe;IACvB,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,MAAM,CAAC,EAAE,MAAM,GAAG;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,KAAK,CAAC,EAAE,MAAM,CAAA;KAAE,CAAC;IACnD,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB;AAED;;;;GAIG;AACH,eAAO,MAAM,cAAc,GAAI,UAAU,eAAe,KAAG,MA0B1D,CAAC;AAEF;;;;GAIG;AACH,eAAO,MAAM,mBAAmB,GAAI,aAAa,MAAM,KAAG,eAQzD,CAAC;AAEF,MAAM,WAAW,cAAc;IAC7B;;;OAGG;IACH,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB;;;OAGG;IACH,cAAc,CAAC,EAAE,MAAM,CAAC;CACzB;AAED;;;;GAIG;AACH,eAAO,MAAM,OAAO,GAAI,UAAS,cAAmB,KAAG,MAsBtD,CAAC"}
package/dist/index.js ADDED
@@ -0,0 +1,60 @@
1
+ import { readFileSync } from "fs";
2
+ import { resolve } from "path";
3
+ const generateBanner = (metadata) => {
4
+ const name = metadata.name || "Unknown Package";
5
+ const version = metadata.version || "0.0.0";
6
+ const description = metadata.description || "";
7
+ let author = "";
8
+ if (metadata.author) {
9
+ if (typeof metadata.author === "string") {
10
+ author = metadata.author;
11
+ } else {
12
+ author = metadata.author.email ? `${metadata.author.name} <${metadata.author.email}>` : metadata.author.name;
13
+ }
14
+ }
15
+ const license = metadata.license || "";
16
+ const parts = [
17
+ `${name} ${version}`,
18
+ description && `${description}`,
19
+ author && `Author: ${author}`,
20
+ license && `License: ${license}`
21
+ ].filter(Boolean);
22
+ return `/*!
23
+ * ${parts.join("\n * ")}
24
+ */`;
25
+ };
26
+ const readPackageMetadata = (packagePath) => {
27
+ try {
28
+ const content = readFileSync(packagePath, "utf-8");
29
+ return JSON.parse(content);
30
+ } catch (error) {
31
+ console.warn(`Failed to read package.json from ${packagePath}:`, error);
32
+ return {};
33
+ }
34
+ };
35
+ const screwUp = (options = {}) => {
36
+ const { packagePath = "./package.json", bannerTemplate } = options;
37
+ let banner;
38
+ return {
39
+ name: "screw-up",
40
+ apply: "build",
41
+ configResolved(config) {
42
+ const resolvedPackagePath = resolve(config.root, packagePath);
43
+ const metadata = readPackageMetadata(resolvedPackagePath);
44
+ banner = bannerTemplate || generateBanner(metadata);
45
+ },
46
+ generateBundle(_options, bundle) {
47
+ for (const fileName in bundle) {
48
+ const chunk = bundle[fileName];
49
+ if (chunk.type === "chunk") {
50
+ chunk.code = banner + "\n" + chunk.code;
51
+ }
52
+ }
53
+ }
54
+ };
55
+ };
56
+ export {
57
+ generateBanner,
58
+ readPackageMetadata,
59
+ screwUp
60
+ };
package/package.json ADDED
@@ -0,0 +1,44 @@
1
+ {
2
+ "name": "screw-up",
3
+ "version": "0.1.0",
4
+ "description": "Simply package metadata inserter on Vite plugin",
5
+ "keywords": [
6
+ "vite",
7
+ "plugin",
8
+ "package",
9
+ "metadata",
10
+ "inserter"
11
+ ],
12
+ "author": "Kouji Matsui (@kekyo@mi.kekyo.net)",
13
+ "license": "MIT",
14
+ "repository": {
15
+ "type": "git",
16
+ "url": "https://github.com/kekyo/screw-up.git"
17
+ },
18
+ "homepage": "https://github.com/kekyo/screw-up#readme",
19
+ "type": "module",
20
+ "main": "./dist/index.cjs",
21
+ "module": "./dist/index.js",
22
+ "types": "./dist/index.d.ts",
23
+ "exports": {
24
+ ".": {
25
+ "import": "./dist/index.js",
26
+ "require": "./dist/index.cjs",
27
+ "types": "./dist/index.d.ts"
28
+ }
29
+ },
30
+ "files": [
31
+ "dist"
32
+ ],
33
+ "scripts": {
34
+ "build": "rv --npm . && tsc --noEmit && vite build && tsc --emitDeclarationOnly --outDir dist",
35
+ "test": "rv --npm . && tsc --noEmit && vitest run"
36
+ },
37
+ "devDependencies": {
38
+ "@types/node": "^20.0.0",
39
+ "typescript": "^5.0.0",
40
+ "vite": "^5.0.0",
41
+ "vite-plugin-dts": "^3.0.0",
42
+ "vitest": "^1.0.0"
43
+ }
44
+ }