screw-up 0.5.1 → 0.7.1

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
@@ -2,7 +2,7 @@
2
2
  const promises = require("fs/promises");
3
3
  const path = require("path");
4
4
  const fs = require("fs");
5
- const flattenObject = (obj, prefix = "", map) => {
5
+ const flattenObject = (obj, prefix, map) => {
6
6
  for (const [key, value] of Object.entries(obj)) {
7
7
  if (!value)
8
8
  continue;
@@ -47,7 +47,7 @@ const findWorkspaceRoot = async (startPath) => {
47
47
  }
48
48
  currentPath = path.dirname(currentPath);
49
49
  }
50
- return null;
50
+ return void 0;
51
51
  };
52
52
  const mergePackageMetadata = (parentMetadata, childMetadata) => {
53
53
  const merged = {};
@@ -92,6 +92,14 @@ const generateBanner = (metadata, outputKeys) => {
92
92
  * ${parts.join("\n * ")}
93
93
  */` : "";
94
94
  };
95
+ const insertBannerHeader = (content, banner) => {
96
+ const lines = content.split("\n");
97
+ if (lines.length > 0 && lines[0].startsWith("#!")) {
98
+ return lines[0] + "\n" + banner + "\n" + lines.slice(1).join("\n");
99
+ } else {
100
+ return banner + "\n" + content;
101
+ }
102
+ };
95
103
  const screwUp = (options = {}) => {
96
104
  const {
97
105
  outputKeys = ["name", "version", "description", "author", "license", "repository.url"],
@@ -110,10 +118,10 @@ const screwUp = (options = {}) => {
110
118
  for (const fileName in bundle) {
111
119
  const chunk = bundle[fileName];
112
120
  if (chunk.type === "chunk") {
113
- chunk.code = banner + "\n" + chunk.code;
121
+ chunk.code = insertBannerHeader(chunk.code, banner);
114
122
  } else if (chunk.type === "asset" && assetFiltersRegex.some((filter) => filter.test(fileName))) {
115
123
  if (typeof chunk.source === "string") {
116
- chunk.source = banner + "\n\n" + chunk.source;
124
+ chunk.source = insertBannerHeader(chunk.source, banner + "\n");
117
125
  }
118
126
  }
119
127
  }
@@ -128,7 +136,7 @@ const screwUp = (options = {}) => {
128
136
  try {
129
137
  const content = await promises.readFile(filePath, "utf-8");
130
138
  if (!content.includes(banner)) {
131
- await promises.writeFile(filePath, banner + "\n\n" + content);
139
+ await promises.writeFile(filePath, insertBannerHeader(content, banner + "\n"));
132
140
  }
133
141
  } catch (error) {
134
142
  }
package/dist/index.js CHANGED
@@ -1,7 +1,7 @@
1
1
  import { readFile, readdir, writeFile } from "fs/promises";
2
2
  import { join, dirname } from "path";
3
3
  import { existsSync } from "fs";
4
- const flattenObject = (obj, prefix = "", map) => {
4
+ const flattenObject = (obj, prefix, map) => {
5
5
  for (const [key, value] of Object.entries(obj)) {
6
6
  if (!value)
7
7
  continue;
@@ -46,7 +46,7 @@ const findWorkspaceRoot = async (startPath) => {
46
46
  }
47
47
  currentPath = dirname(currentPath);
48
48
  }
49
- return null;
49
+ return void 0;
50
50
  };
51
51
  const mergePackageMetadata = (parentMetadata, childMetadata) => {
52
52
  const merged = {};
@@ -91,6 +91,14 @@ const generateBanner = (metadata, outputKeys) => {
91
91
  * ${parts.join("\n * ")}
92
92
  */` : "";
93
93
  };
94
+ const insertBannerHeader = (content, banner) => {
95
+ const lines = content.split("\n");
96
+ if (lines.length > 0 && lines[0].startsWith("#!")) {
97
+ return lines[0] + "\n" + banner + "\n" + lines.slice(1).join("\n");
98
+ } else {
99
+ return banner + "\n" + content;
100
+ }
101
+ };
94
102
  const screwUp = (options = {}) => {
95
103
  const {
96
104
  outputKeys = ["name", "version", "description", "author", "license", "repository.url"],
@@ -109,10 +117,10 @@ const screwUp = (options = {}) => {
109
117
  for (const fileName in bundle) {
110
118
  const chunk = bundle[fileName];
111
119
  if (chunk.type === "chunk") {
112
- chunk.code = banner + "\n" + chunk.code;
120
+ chunk.code = insertBannerHeader(chunk.code, banner);
113
121
  } else if (chunk.type === "asset" && assetFiltersRegex.some((filter) => filter.test(fileName))) {
114
122
  if (typeof chunk.source === "string") {
115
- chunk.source = banner + "\n\n" + chunk.source;
123
+ chunk.source = insertBannerHeader(chunk.source, banner + "\n");
116
124
  }
117
125
  }
118
126
  }
@@ -127,7 +135,7 @@ const screwUp = (options = {}) => {
127
135
  try {
128
136
  const content = await readFile(filePath, "utf-8");
129
137
  if (!content.includes(banner)) {
130
- await writeFile(filePath, banner + "\n\n" + content);
138
+ await writeFile(filePath, insertBannerHeader(content, banner + "\n"));
131
139
  }
132
140
  } catch (error) {
133
141
  }
@@ -8,9 +8,9 @@ export declare const readPackageMetadata: (packagePath: string) => Promise<Packa
8
8
  /**
9
9
  * Find workspace root by looking for workspace configuration files
10
10
  * @param startPath - Starting directory path
11
- * @returns Promise resolving to workspace root path or null if not found
11
+ * @returns Promise resolving to workspace root path or undefined if not found
12
12
  */
13
- export declare const findWorkspaceRoot: (startPath: string) => Promise<string | null>;
13
+ export declare const findWorkspaceRoot: (startPath: string) => Promise<string | undefined>;
14
14
  /**
15
15
  * Merge package metadata with inheritance (child overrides parent)
16
16
  * @param parentMetadata - Parent package metadata
@@ -31,4 +31,11 @@ export declare const resolvePackageMetadata: (projectRoot: string) => Promise<Pa
31
31
  * @returns Banner string
32
32
  */
33
33
  export declare const generateBanner: (metadata: PackageMetadata, outputKeys: string[]) => string;
34
+ /**
35
+ * Insert banner header at appropriate position considering shebang
36
+ * @param content - The content to insert banner into
37
+ * @param banner - The banner header to insert
38
+ * @returns Content with banner header inserted
39
+ */
40
+ export declare const insertBannerHeader: (content: string, banner: string) => string;
34
41
  //# sourceMappingURL=internal.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"internal.d.ts","sourceRoot":"","sources":["../src/internal.ts"],"names":[],"mappings":"AASA,MAAM,MAAM,eAAe,GAAG,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;AA2BrD;;;;GAIG;AACH,eAAO,MAAM,mBAAmB,GAAU,aAAa,MAAM,KAAG,OAAO,CAAC,eAAe,CAWtF,CAAC;AAEF;;;;GAIG;AACH,eAAO,MAAM,iBAAiB,GAAU,WAAW,MAAM,KAAG,OAAO,CAAC,MAAM,GAAG,IAAI,CA0BhF,CAAC;AAEF;;;;;GAKG;AACH,eAAO,MAAM,oBAAoB,GAC/B,gBAAgB,eAAe,EAC/B,eAAe,eAAe,KAC7B,eAoBF,CAAC;AAEF;;;;GAIG;AACH,eAAO,MAAM,sBAAsB,GAAU,aAAa,MAAM,KAAG,OAAO,CAAC,eAAe,CAsBzF,CAAC;AAEF;;;;;GAKG;AACH,eAAO,MAAM,cAAc,GAAI,UAAU,eAAe,EAAE,YAAY,MAAM,EAAE,KAAG,MAWhF,CAAC"}
1
+ {"version":3,"file":"internal.d.ts","sourceRoot":"","sources":["../src/internal.ts"],"names":[],"mappings":"AASA,MAAM,MAAM,eAAe,GAAG,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;AA2BrD;;;;GAIG;AACH,eAAO,MAAM,mBAAmB,GAAU,aAAa,MAAM,KAAG,OAAO,CAAC,eAAe,CAWtF,CAAC;AAEF;;;;GAIG;AACH,eAAO,MAAM,iBAAiB,GAAU,WAAW,MAAM,KAAG,OAAO,CAAC,MAAM,GAAG,SAAS,CA0BrF,CAAC;AAEF;;;;;GAKG;AACH,eAAO,MAAM,oBAAoB,GAC/B,gBAAgB,eAAe,EAC/B,eAAe,eAAe,KAC7B,eAoBF,CAAC;AAEF;;;;GAIG;AACH,eAAO,MAAM,sBAAsB,GAAU,aAAa,MAAM,KAAG,OAAO,CAAC,eAAe,CAsBzF,CAAC;AAEF;;;;;GAKG;AACH,eAAO,MAAM,cAAc,GAAI,UAAU,eAAe,EAAE,YAAY,MAAM,EAAE,KAAG,MAWhF,CAAC;AAEF;;;;;GAKG;AACH,eAAO,MAAM,kBAAkB,GAAI,SAAS,MAAM,EAAE,QAAQ,MAAM,KAAG,MAWpE,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "screw-up",
3
- "version": "0.5.1",
3
+ "version": "0.7.1",
4
4
  "description": "Simply package metadata inserter on Vite plugin",
5
5
  "keywords": [
6
6
  "vite",
@@ -35,7 +35,7 @@
35
35
  "test": "rv --npm . && tsc --noEmit && vitest run"
36
36
  },
37
37
  "peerDependencies": {
38
- "vite": "^5.0.0"
38
+ "vite": ">=5.0.0"
39
39
  },
40
40
  "devDependencies": {
41
41
  "@types/node": "^20.0.0",