screw-up 0.2.0 → 0.3.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/dist/index.cjs CHANGED
@@ -1,8 +1,7 @@
1
1
  "use strict";
2
- Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
- const fs = require("fs");
4
2
  const promises = require("fs/promises");
5
3
  const path = require("path");
4
+ const fs = require("fs");
6
5
  const flattenObject = (obj, prefix = "", map) => {
7
6
  for (const [key, value] of Object.entries(obj)) {
8
7
  if (!value)
@@ -94,7 +93,11 @@ const generateBanner = (metadata, outputKeys) => {
94
93
  */` : "";
95
94
  };
96
95
  const screwUp = (options = {}) => {
97
- const { outputKeys = ["name", "version", "description", "author", "license", "repository.url"] } = options;
96
+ const {
97
+ outputKeys = ["name", "version", "description", "author", "license", "repository.url"],
98
+ assetFilters = ["\\.d\\.ts$"]
99
+ } = options;
100
+ const assetFiltersRegex = assetFilters.map((filter) => new RegExp(filter));
98
101
  let banner;
99
102
  return {
100
103
  name: "screw-up",
@@ -108,9 +111,32 @@ const screwUp = (options = {}) => {
108
111
  const chunk = bundle[fileName];
109
112
  if (chunk.type === "chunk") {
110
113
  chunk.code = banner + "\n" + chunk.code;
114
+ } else if (chunk.type === "asset" && assetFiltersRegex.some((filter) => filter.test(fileName))) {
115
+ if (typeof chunk.source === "string") {
116
+ chunk.source = banner + "\n\n" + chunk.source;
117
+ }
111
118
  }
112
119
  }
120
+ },
121
+ async writeBundle(options2) {
122
+ if (!options2.dir) return;
123
+ try {
124
+ const files = await promises.readdir(options2.dir, { recursive: true });
125
+ for (const file of files) {
126
+ const filePath = path.join(options2.dir, file);
127
+ if (assetFiltersRegex.some((filter) => filter.test(file))) {
128
+ try {
129
+ const content = await promises.readFile(filePath, "utf-8");
130
+ if (!content.includes(banner)) {
131
+ await promises.writeFile(filePath, banner + "\n\n" + content);
132
+ }
133
+ } catch (error) {
134
+ }
135
+ }
136
+ }
137
+ } catch (error) {
138
+ }
113
139
  }
114
140
  };
115
141
  };
116
- exports.screwUp = screwUp;
142
+ module.exports = screwUp;
package/dist/index.d.ts CHANGED
@@ -6,11 +6,17 @@ export interface ScrewUpOptions {
6
6
  * @default ['name', 'version', 'description', 'author', 'license', 'repository.url']
7
7
  */
8
8
  outputKeys?: string[];
9
+ /**
10
+ * Array of asset file regex to add banner to
11
+ * @default ['\.d\.ts$']
12
+ */
13
+ assetFilters?: string[];
9
14
  }
10
15
  /**
11
16
  * Vite plugin that adds banner to the bundled code
12
17
  * @param options - Plugin options
13
18
  * @returns Vite plugin
14
19
  */
15
- export declare const screwUp: (options?: ScrewUpOptions) => Plugin;
20
+ declare const screwUp: (options?: ScrewUpOptions) => Plugin;
21
+ export default screwUp;
16
22
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,MAAM,CAAC;AAGnC,MAAM,WAAW,cAAc;IAC7B;;;OAGG;IACH,UAAU,CAAC,EAAE,MAAM,EAAE,CAAC;CACvB;AAED;;;;GAIG;AACH,eAAO,MAAM,OAAO,GAAI,UAAS,cAAmB,KAAG,MAqBtD,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,MAAM,CAAC;AAKnC,MAAM,WAAW,cAAc;IAC7B;;;OAGG;IACH,UAAU,CAAC,EAAE,MAAM,EAAE,CAAC;IACtB;;;OAGG;IACH,YAAY,CAAC,EAAE,MAAM,EAAE,CAAC;CACzB;AAED;;;;GAIG;AACH,QAAA,MAAM,OAAO,GAAI,UAAS,cAAmB,KAAG,MA2D/C,CAAC;AAEF,eAAe,OAAO,CAAC"}
package/dist/index.js CHANGED
@@ -1,6 +1,6 @@
1
- import { existsSync } from "fs";
2
- import { readFile } from "fs/promises";
1
+ import { readFile, readdir, writeFile } from "fs/promises";
3
2
  import { join, dirname } from "path";
3
+ import { existsSync } from "fs";
4
4
  const flattenObject = (obj, prefix = "", map) => {
5
5
  for (const [key, value] of Object.entries(obj)) {
6
6
  if (!value)
@@ -92,7 +92,11 @@ const generateBanner = (metadata, outputKeys) => {
92
92
  */` : "";
93
93
  };
94
94
  const screwUp = (options = {}) => {
95
- const { outputKeys = ["name", "version", "description", "author", "license", "repository.url"] } = options;
95
+ const {
96
+ outputKeys = ["name", "version", "description", "author", "license", "repository.url"],
97
+ assetFilters = ["\\.d\\.ts$"]
98
+ } = options;
99
+ const assetFiltersRegex = assetFilters.map((filter) => new RegExp(filter));
96
100
  let banner;
97
101
  return {
98
102
  name: "screw-up",
@@ -106,11 +110,34 @@ const screwUp = (options = {}) => {
106
110
  const chunk = bundle[fileName];
107
111
  if (chunk.type === "chunk") {
108
112
  chunk.code = banner + "\n" + chunk.code;
113
+ } else if (chunk.type === "asset" && assetFiltersRegex.some((filter) => filter.test(fileName))) {
114
+ if (typeof chunk.source === "string") {
115
+ chunk.source = banner + "\n\n" + chunk.source;
116
+ }
109
117
  }
110
118
  }
119
+ },
120
+ async writeBundle(options2) {
121
+ if (!options2.dir) return;
122
+ try {
123
+ const files = await readdir(options2.dir, { recursive: true });
124
+ for (const file of files) {
125
+ const filePath = join(options2.dir, file);
126
+ if (assetFiltersRegex.some((filter) => filter.test(file))) {
127
+ try {
128
+ const content = await readFile(filePath, "utf-8");
129
+ if (!content.includes(banner)) {
130
+ await writeFile(filePath, banner + "\n\n" + content);
131
+ }
132
+ } catch (error) {
133
+ }
134
+ }
135
+ }
136
+ } catch (error) {
137
+ }
111
138
  }
112
139
  };
113
140
  };
114
141
  export {
115
- screwUp
142
+ screwUp as default
116
143
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "screw-up",
3
- "version": "0.2.0",
3
+ "version": "0.3.0",
4
4
  "description": "Simply package metadata inserter on Vite plugin",
5
5
  "keywords": [
6
6
  "vite",
@@ -34,9 +34,6 @@
34
34
  "build": "rv --npm . && tsc --noEmit && vite build && tsc --emitDeclarationOnly --outDir dist",
35
35
  "test": "rv --npm . && tsc --noEmit && vitest run"
36
36
  },
37
- "dependencies": {
38
- "glob": "^11.0.3"
39
- },
40
37
  "devDependencies": {
41
38
  "@types/node": "^20.0.0",
42
39
  "typescript": "^5.0.0",