@frozzare/pkg 1.0.3 → 1.0.6
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 +3 -1
- package/dist/index.js +24 -9
- package/dist/utils.d.ts +1 -0
- package/dist/utils.js +11 -0
- package/package.json +3 -1
package/dist/index.d.ts
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
1
|
import { BuildOptions as ESBuildOptions } from 'esbuild';
|
|
2
2
|
export type BuildOptions = Omit<ESBuildOptions, 'bundle' | 'entryPoints'>;
|
|
3
|
-
export declare const build: (
|
|
3
|
+
export declare const build: (entry: string | (BuildOptions & {
|
|
4
|
+
entry: string;
|
|
5
|
+
}), options?: BuildOptions) => Promise<string | void>;
|
package/dist/index.js
CHANGED
|
@@ -7,27 +7,42 @@ exports.build = void 0;
|
|
|
7
7
|
const fs_1 = __importDefault(require("fs"));
|
|
8
8
|
const path_1 = __importDefault(require("path"));
|
|
9
9
|
const esbuild_1 = require("esbuild");
|
|
10
|
+
const utils_1 = require("./utils");
|
|
10
11
|
const defaultOptions = {
|
|
11
12
|
write: true,
|
|
12
13
|
};
|
|
13
|
-
const build = async (
|
|
14
|
-
|
|
15
|
-
const
|
|
14
|
+
const build = async (entry, options = {}) => {
|
|
15
|
+
var _a;
|
|
16
|
+
const config = (0, utils_1.omit)(['entry'], {
|
|
17
|
+
...defaultOptions,
|
|
18
|
+
...(typeof entry === 'object' ? entry : options),
|
|
19
|
+
});
|
|
20
|
+
const result = await (0, esbuild_1.build)({
|
|
16
21
|
...config,
|
|
17
|
-
entryPoints: [
|
|
22
|
+
entryPoints: [typeof entry === 'string' ? entry : entry.entry],
|
|
18
23
|
bundle: true,
|
|
19
24
|
write: false,
|
|
20
25
|
});
|
|
21
|
-
|
|
26
|
+
if (result.errors.length) {
|
|
27
|
+
throw result.errors;
|
|
28
|
+
}
|
|
29
|
+
if (result.warnings.length) {
|
|
30
|
+
result.warnings.forEach(console.warn);
|
|
31
|
+
}
|
|
32
|
+
if (!((_a = result.outputFiles) === null || _a === void 0 ? void 0 : _a.length)) {
|
|
33
|
+
throw new Error('No outfile defined');
|
|
34
|
+
}
|
|
35
|
+
const file = result.outputFiles[0];
|
|
22
36
|
let text = file.text;
|
|
23
37
|
if (config.format === 'cjs') {
|
|
24
|
-
const
|
|
25
|
-
const match = text.match(reg);
|
|
38
|
+
const match = text.match(/.*default:(?:\s+|)\(\)(?:\s+|)=>(?:\s+|)([A-Za-z0-9_]+)/);
|
|
26
39
|
if (!match) {
|
|
27
40
|
throw new Error('Failed to find export name');
|
|
28
41
|
}
|
|
29
|
-
const name = match === null || match === void 0 ? void 0 : match[1].
|
|
30
|
-
text =
|
|
42
|
+
const name = match === null || match === void 0 ? void 0 : match[1].trim();
|
|
43
|
+
text =
|
|
44
|
+
text.replace(/module.exports = __toCommonJS\(\w+\);/, '') +
|
|
45
|
+
`module.exports = ${name};`.replace((config === null || config === void 0 ? void 0 : config.minify) ? /\s/g : '', '');
|
|
31
46
|
}
|
|
32
47
|
if (!config.write) {
|
|
33
48
|
return text;
|
package/dist/utils.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const omit: (keys: string[], obj: Record<string, any>) => Record<string, any>;
|
package/dist/utils.js
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.omit = void 0;
|
|
4
|
+
const omit = (keys, obj) => {
|
|
5
|
+
if (!keys.length)
|
|
6
|
+
return obj;
|
|
7
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
8
|
+
const { [keys.pop()]: omitted, ...rest } = obj;
|
|
9
|
+
return (0, exports.omit)(keys, rest);
|
|
10
|
+
};
|
|
11
|
+
exports.omit = omit;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@frozzare/pkg",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.6",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"scripts": {
|
|
@@ -14,6 +14,8 @@
|
|
|
14
14
|
"dist"
|
|
15
15
|
],
|
|
16
16
|
"keywords": [],
|
|
17
|
+
"homepage": "https://github.com/frozzare/node-pkg",
|
|
18
|
+
"repository": "https://github.com/frozzare/node-pkg",
|
|
17
19
|
"author": "Fredrik Forsmo <fredrik.forsmo@gmail.com>",
|
|
18
20
|
"license": "MIT",
|
|
19
21
|
"dependencies": {
|