@frozzare/pkg 1.0.7 → 1.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/dist/index.d.ts +2 -2
- package/dist/index.js +15 -13
- package/package.json +8 -13
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { BuildOptions as ESBuildOptions } from
|
|
2
|
-
export type BuildOptions = Omit<ESBuildOptions,
|
|
1
|
+
import { type BuildOptions as ESBuildOptions } from "esbuild";
|
|
2
|
+
export type BuildOptions = Omit<ESBuildOptions, "bundle" | "entryPoints">;
|
|
3
3
|
export declare const build: (entry: string | (BuildOptions & {
|
|
4
4
|
entry: string;
|
|
5
5
|
}), options?: BuildOptions) => Promise<string | void>;
|
package/dist/index.js
CHANGED
|
@@ -4,22 +4,24 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.build = void 0;
|
|
7
|
-
const
|
|
8
|
-
const
|
|
7
|
+
const node_fs_1 = __importDefault(require("node:fs"));
|
|
8
|
+
const node_path_1 = __importDefault(require("node:path"));
|
|
9
9
|
const esbuild_1 = require("esbuild");
|
|
10
10
|
const utils_1 = require("./utils");
|
|
11
11
|
const defaultOptions = {
|
|
12
12
|
write: true,
|
|
13
13
|
};
|
|
14
|
+
const DEFAULT_EXPORT_REGEX = /.*default:(?:\s+|)\(\)(?:\s+|)=>(?:\s+|)([A-Za-z0-9_]+)/;
|
|
15
|
+
const MODULE_EXPORTS_REGEX = /module.exports(?:\s+|)=(?:\s+|)\w+\(\w+\);/;
|
|
14
16
|
const build = async (entry, options = {}) => {
|
|
15
17
|
var _a;
|
|
16
|
-
const config = (0, utils_1.omit)([
|
|
18
|
+
const config = (0, utils_1.omit)(["entry"], {
|
|
17
19
|
...defaultOptions,
|
|
18
|
-
...(typeof entry ===
|
|
20
|
+
...(typeof entry === "object" ? entry : options),
|
|
19
21
|
});
|
|
20
22
|
const result = await (0, esbuild_1.build)({
|
|
21
23
|
...config,
|
|
22
|
-
entryPoints: [typeof entry ===
|
|
24
|
+
entryPoints: [typeof entry === "string" ? entry : entry.entry],
|
|
23
25
|
bundle: true,
|
|
24
26
|
write: false,
|
|
25
27
|
});
|
|
@@ -30,24 +32,24 @@ const build = async (entry, options = {}) => {
|
|
|
30
32
|
result.warnings.forEach(console.warn);
|
|
31
33
|
}
|
|
32
34
|
if (!((_a = result.outputFiles) === null || _a === void 0 ? void 0 : _a.length)) {
|
|
33
|
-
throw new Error(
|
|
35
|
+
throw new Error("No outfile defined");
|
|
34
36
|
}
|
|
35
37
|
const file = result.outputFiles[0];
|
|
36
38
|
let text = file.text;
|
|
37
|
-
if (config.format ===
|
|
38
|
-
const match = text.match(
|
|
39
|
+
if (config.format === "cjs") {
|
|
40
|
+
const match = text.match(DEFAULT_EXPORT_REGEX);
|
|
39
41
|
if (!match) {
|
|
40
|
-
throw new Error(
|
|
42
|
+
throw new Error("Failed to find export name");
|
|
41
43
|
}
|
|
42
44
|
const name = match === null || match === void 0 ? void 0 : match[1].trim();
|
|
43
45
|
text =
|
|
44
|
-
text.replace(
|
|
45
|
-
`${(config === null || config === void 0 ? void 0 : config.minify) ?
|
|
46
|
+
text.replace(MODULE_EXPORTS_REGEX, "").trim() +
|
|
47
|
+
`${(config === null || config === void 0 ? void 0 : config.minify) ? "" : "\n"}module.exports = ${name};`.replace((config === null || config === void 0 ? void 0 : config.minify) ? /\s/g : "", "");
|
|
46
48
|
}
|
|
47
49
|
if (!config.write) {
|
|
48
50
|
return text;
|
|
49
51
|
}
|
|
50
|
-
|
|
51
|
-
return
|
|
52
|
+
node_fs_1.default.mkdirSync(node_path_1.default.dirname(file.path));
|
|
53
|
+
return config.write ? node_fs_1.default.writeFileSync(file.path, text) : text;
|
|
52
54
|
};
|
|
53
55
|
exports.build = build;
|
package/package.json
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@frozzare/pkg",
|
|
3
|
-
"version": "1.0
|
|
3
|
+
"version": "1.1.0",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"scripts": {
|
|
7
7
|
"build": "tsc",
|
|
8
|
-
"format": "
|
|
9
|
-
"lint": "
|
|
8
|
+
"format": "biome format src --write",
|
|
9
|
+
"lint": "biome lint src",
|
|
10
10
|
"prepublishOnly": "npm run build",
|
|
11
11
|
"test": "vitest"
|
|
12
12
|
},
|
|
@@ -19,17 +19,12 @@
|
|
|
19
19
|
"author": "Fredrik Forsmo <fredrik.forsmo@gmail.com>",
|
|
20
20
|
"license": "MIT",
|
|
21
21
|
"dependencies": {
|
|
22
|
-
"esbuild": "^0.
|
|
22
|
+
"esbuild": "^0.27.2"
|
|
23
23
|
},
|
|
24
24
|
"devDependencies": {
|
|
25
|
-
"@
|
|
26
|
-
"
|
|
27
|
-
"
|
|
28
|
-
"
|
|
29
|
-
"prettier": "^2.8.4",
|
|
30
|
-
"rimraf": "^4.1.2",
|
|
31
|
-
"tsx": "^3.12.3",
|
|
32
|
-
"typescript": "^4.9.5",
|
|
33
|
-
"vitest": "^0.28.4"
|
|
25
|
+
"@biomejs/biome": "^2.3.11",
|
|
26
|
+
"typescript": "^5.9.3",
|
|
27
|
+
"ultracite": "^7.0.11",
|
|
28
|
+
"vitest": "^4.0.17"
|
|
34
29
|
}
|
|
35
30
|
}
|