quickbundle 0.9.0 → 0.12.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/bin/bundler/bundler.d.ts +8 -4
- package/bin/bundler/bundler.js +117 -76
- package/bin/bundler/index.js +6 -1
- package/bin/bundler/package.d.ts +9 -9
- package/bin/bundler/package.js +29 -13
- package/bin/bundler/plugins.d.ts +3 -1
- package/bin/bundler/plugins.js +56 -25
- package/bin/bundler/typescript.d.ts +9 -5
- package/bin/bundler/typescript.js +144 -65
- package/bin/helpers.d.ts +4 -1
- package/bin/helpers.js +8 -9
- package/bin/program/commands/build.d.ts +3 -10
- package/bin/program/commands/build.js +106 -69
- package/bin/program/commands/watch.d.ts +3 -8
- package/bin/program/commands/watch.js +96 -61
- package/bin/program/index.js +13 -10
- package/bin/program/types.d.ts +1 -1
- package/bin/tsconfig.tsbuildinfo +1 -1
- package/package.json +18 -10
package/bin/bundler/bundler.d.ts
CHANGED
|
@@ -1,7 +1,11 @@
|
|
|
1
1
|
declare type BundleParameters = {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
2
|
+
isProduction: boolean;
|
|
3
|
+
isFast: boolean;
|
|
4
|
+
onWatch?: (error: Error | null) => void;
|
|
5
5
|
};
|
|
6
|
-
export declare const bundle: ({
|
|
6
|
+
export declare const bundle: ({
|
|
7
|
+
isProduction,
|
|
8
|
+
isFast,
|
|
9
|
+
onWatch,
|
|
10
|
+
}: BundleParameters) => Promise<(string | null)[]>;
|
|
7
11
|
export {};
|
package/bin/bundler/bundler.js
CHANGED
|
@@ -1,13 +1,39 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __awaiter =
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
};
|
|
2
|
+
var __awaiter =
|
|
3
|
+
(this && this.__awaiter) ||
|
|
4
|
+
function (thisArg, _arguments, P, generator) {
|
|
5
|
+
function adopt(value) {
|
|
6
|
+
return value instanceof P
|
|
7
|
+
? value
|
|
8
|
+
: new P(function (resolve) {
|
|
9
|
+
resolve(value);
|
|
10
|
+
});
|
|
11
|
+
}
|
|
12
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
13
|
+
function fulfilled(value) {
|
|
14
|
+
try {
|
|
15
|
+
step(generator.next(value));
|
|
16
|
+
} catch (e) {
|
|
17
|
+
reject(e);
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
function rejected(value) {
|
|
21
|
+
try {
|
|
22
|
+
step(generator["throw"](value));
|
|
23
|
+
} catch (e) {
|
|
24
|
+
reject(e);
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
function step(result) {
|
|
28
|
+
result.done
|
|
29
|
+
? resolve(result.value)
|
|
30
|
+
: adopt(result.value).then(fulfilled, rejected);
|
|
31
|
+
}
|
|
32
|
+
step(
|
|
33
|
+
(generator = generator.apply(thisArg, _arguments || [])).next()
|
|
34
|
+
);
|
|
35
|
+
});
|
|
36
|
+
};
|
|
11
37
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
38
|
exports.bundle = void 0;
|
|
13
39
|
const esbuild_1 = require("esbuild");
|
|
@@ -15,71 +41,86 @@ const constants_1 = require("../constants");
|
|
|
15
41
|
const package_1 = require("./package");
|
|
16
42
|
const plugins_1 = require("./plugins");
|
|
17
43
|
const typescript_1 = require("./typescript");
|
|
18
|
-
const bundle = ({ isProduction, isFast, onWatch
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
44
|
+
const bundle = ({ isProduction, isFast, onWatch }) =>
|
|
45
|
+
__awaiter(void 0, void 0, void 0, function* () {
|
|
46
|
+
const {
|
|
47
|
+
destination,
|
|
48
|
+
externalDependencies,
|
|
49
|
+
hasModule,
|
|
50
|
+
platform,
|
|
51
|
+
source,
|
|
52
|
+
types,
|
|
53
|
+
} = (0, package_1.getPackageMetadata)();
|
|
54
|
+
const isWatching = typeof onWatch === "function";
|
|
55
|
+
const isTypingRequested = typeof types === "string" && !isFast;
|
|
56
|
+
const tsConfig = yield (0, typescript_1.getTypeScriptConfiguration)();
|
|
57
|
+
const getType = () =>
|
|
58
|
+
__awaiter(void 0, void 0, void 0, function* () {
|
|
59
|
+
const outfile = types;
|
|
60
|
+
if (!outfile) return null;
|
|
61
|
+
yield (0, typescript_1.generateTypeScriptDeclaration)(outfile);
|
|
62
|
+
return outfile;
|
|
63
|
+
});
|
|
64
|
+
const getJavaScript = (format) =>
|
|
65
|
+
__awaiter(void 0, void 0, void 0, function* () {
|
|
66
|
+
const outfile = destination[format];
|
|
67
|
+
if (!outfile) return null;
|
|
68
|
+
yield (0, esbuild_1.build)({
|
|
69
|
+
absWorkingDir: constants_1.CWD,
|
|
70
|
+
bundle: Boolean(externalDependencies),
|
|
71
|
+
define: {
|
|
72
|
+
"process.env.NODE_ENV": isProduction
|
|
73
|
+
? '"production"'
|
|
74
|
+
: '"development"',
|
|
75
|
+
},
|
|
76
|
+
entryPoints: [source],
|
|
77
|
+
external: externalDependencies,
|
|
78
|
+
format,
|
|
79
|
+
logLevel: "silent",
|
|
80
|
+
metafile: true,
|
|
81
|
+
minify: isProduction,
|
|
82
|
+
outfile,
|
|
83
|
+
plugins: [(0, plugins_1.jsxPlugin)(tsConfig)],
|
|
84
|
+
platform,
|
|
85
|
+
sourcemap: true,
|
|
86
|
+
target:
|
|
87
|
+
(tsConfig === null || tsConfig === void 0
|
|
88
|
+
? void 0
|
|
89
|
+
: tsConfig.target) || "esnext",
|
|
90
|
+
treeShaking: true,
|
|
91
|
+
watch: isWatching && {
|
|
92
|
+
onRebuild(bundleError) {
|
|
93
|
+
return __awaiter(
|
|
94
|
+
this,
|
|
95
|
+
void 0,
|
|
96
|
+
void 0,
|
|
97
|
+
function* () {
|
|
98
|
+
let error = bundleError;
|
|
99
|
+
if (error) {
|
|
100
|
+
onWatch(error);
|
|
101
|
+
return;
|
|
102
|
+
}
|
|
103
|
+
if (isTypingRequested) {
|
|
104
|
+
try {
|
|
105
|
+
yield getType();
|
|
106
|
+
} catch (typingError) {
|
|
107
|
+
error = typingError;
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
onWatch(error);
|
|
111
|
+
}
|
|
112
|
+
);
|
|
113
|
+
},
|
|
114
|
+
},
|
|
115
|
+
});
|
|
116
|
+
return outfile;
|
|
117
|
+
});
|
|
118
|
+
const promises = [
|
|
119
|
+
...(isWatching
|
|
120
|
+
? [getJavaScript(hasModule ? "esm" : "cjs")]
|
|
121
|
+
: [getJavaScript("cjs"), getJavaScript("esm")]),
|
|
122
|
+
...(isTypingRequested ? [getType()] : []),
|
|
123
|
+
];
|
|
124
|
+
return Promise.all(promises);
|
|
125
|
+
});
|
|
85
126
|
exports.bundle = bundle;
|
package/bin/bundler/index.js
CHANGED
|
@@ -2,4 +2,9 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.bundle = void 0;
|
|
4
4
|
var bundler_1 = require("./bundler");
|
|
5
|
-
Object.defineProperty(exports, "bundle", {
|
|
5
|
+
Object.defineProperty(exports, "bundle", {
|
|
6
|
+
enumerable: true,
|
|
7
|
+
get: function () {
|
|
8
|
+
return bundler_1.bundle;
|
|
9
|
+
},
|
|
10
|
+
});
|
package/bin/bundler/package.d.ts
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
export declare const getPackageMetadata: () => {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
2
|
+
readonly destination: {
|
|
3
|
+
readonly esm?: string | undefined;
|
|
4
|
+
readonly cjs: string;
|
|
5
|
+
};
|
|
6
|
+
readonly externalDependencies: string[];
|
|
7
|
+
readonly hasModule: boolean;
|
|
8
|
+
readonly platform: "node" | "browser";
|
|
9
|
+
readonly source: string;
|
|
10
|
+
readonly types: string | undefined;
|
|
11
11
|
};
|
package/bin/bundler/package.js
CHANGED
|
@@ -5,18 +5,34 @@ const path_1 = require("path");
|
|
|
5
5
|
const constants_1 = require("../constants");
|
|
6
6
|
const helpers_1 = require("../helpers");
|
|
7
7
|
const getPackageMetadata = () => {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
8
|
+
const {
|
|
9
|
+
peerDependencies = {},
|
|
10
|
+
main,
|
|
11
|
+
module,
|
|
12
|
+
platform = "browser",
|
|
13
|
+
source,
|
|
14
|
+
types,
|
|
15
|
+
} = require((0, path_1.resolve)(constants_1.CWD, "package.json"));
|
|
16
|
+
const externalDependencies = Object.keys(peerDependencies);
|
|
17
|
+
(0, helpers_1.assert)(
|
|
18
|
+
main,
|
|
19
|
+
"A `main` field is required in `package.json`. Did you forget to add it?"
|
|
20
|
+
);
|
|
21
|
+
(0, helpers_1.assert)(
|
|
22
|
+
source,
|
|
23
|
+
"A `source` field is required in `package.json`. Did you forget to add it?"
|
|
24
|
+
);
|
|
25
|
+
(0, helpers_1.assert)(
|
|
26
|
+
["browser", "node"].includes(platform),
|
|
27
|
+
"The `platform` package field can only accept `browser` or `node` value."
|
|
28
|
+
);
|
|
29
|
+
return {
|
|
30
|
+
destination: Object.assign({ cjs: main }, module && { esm: module }),
|
|
31
|
+
externalDependencies,
|
|
32
|
+
hasModule: Boolean(module),
|
|
33
|
+
platform,
|
|
34
|
+
source,
|
|
35
|
+
types,
|
|
36
|
+
};
|
|
21
37
|
};
|
|
22
38
|
exports.getPackageMetadata = getPackageMetadata;
|
package/bin/bundler/plugins.d.ts
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
1
|
import type { Plugin } from "esbuild";
|
|
2
2
|
import type { TypeScriptConfiguration } from "./typescript";
|
|
3
|
-
export declare const jsxPlugin: (
|
|
3
|
+
export declare const jsxPlugin: (
|
|
4
|
+
tsConfig: TypeScriptConfiguration | null
|
|
5
|
+
) => Plugin;
|
package/bin/bundler/plugins.js
CHANGED
|
@@ -1,32 +1,63 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __awaiter =
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
};
|
|
2
|
+
var __awaiter =
|
|
3
|
+
(this && this.__awaiter) ||
|
|
4
|
+
function (thisArg, _arguments, P, generator) {
|
|
5
|
+
function adopt(value) {
|
|
6
|
+
return value instanceof P
|
|
7
|
+
? value
|
|
8
|
+
: new P(function (resolve) {
|
|
9
|
+
resolve(value);
|
|
10
|
+
});
|
|
11
|
+
}
|
|
12
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
13
|
+
function fulfilled(value) {
|
|
14
|
+
try {
|
|
15
|
+
step(generator.next(value));
|
|
16
|
+
} catch (e) {
|
|
17
|
+
reject(e);
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
function rejected(value) {
|
|
21
|
+
try {
|
|
22
|
+
step(generator["throw"](value));
|
|
23
|
+
} catch (e) {
|
|
24
|
+
reject(e);
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
function step(result) {
|
|
28
|
+
result.done
|
|
29
|
+
? resolve(result.value)
|
|
30
|
+
: adopt(result.value).then(fulfilled, rejected);
|
|
31
|
+
}
|
|
32
|
+
step(
|
|
33
|
+
(generator = generator.apply(thisArg, _arguments || [])).next()
|
|
34
|
+
);
|
|
35
|
+
});
|
|
36
|
+
};
|
|
11
37
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
38
|
exports.jsxPlugin = void 0;
|
|
13
39
|
const helpers_1 = require("../helpers");
|
|
14
40
|
const jsxPlugin = (tsConfig) => ({
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
41
|
+
name: "jsx-runtime",
|
|
42
|
+
setup(build) {
|
|
43
|
+
build.onLoad({ filter: /\.(j|t)sx$/ }, ({ path }) =>
|
|
44
|
+
__awaiter(this, void 0, void 0, function* () {
|
|
45
|
+
if (!tsConfig || !tsConfig.hasJsxRuntime) return;
|
|
46
|
+
const module = tsConfig.jsxImportSource || "react";
|
|
47
|
+
if (
|
|
48
|
+
!(0, helpers_1.resolveModulePath)(`${module}/jsx-runtime`)
|
|
49
|
+
) {
|
|
50
|
+
throw new Error(
|
|
51
|
+
"Unable to find the JSX runtime.\nPotential solutions:\n1. If you rely on a non React runtime, set a valid `jsxImportSource` in your tsconfig\n2. Make sure that you've installed your project dependencies"
|
|
52
|
+
);
|
|
53
|
+
}
|
|
54
|
+
const content = yield (0, helpers_1.readFile)(path, "utf8");
|
|
55
|
+
return {
|
|
56
|
+
contents: `import * as React from "${module}";${content}`,
|
|
57
|
+
loader: "tsx",
|
|
58
|
+
};
|
|
59
|
+
})
|
|
60
|
+
);
|
|
61
|
+
},
|
|
31
62
|
});
|
|
32
63
|
exports.jsxPlugin = jsxPlugin;
|
|
@@ -1,8 +1,12 @@
|
|
|
1
1
|
export declare type TypeScriptConfiguration = {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
2
|
+
target?: string;
|
|
3
|
+
jsxImportSource?: string;
|
|
4
|
+
hasJsxRuntime?: boolean;
|
|
5
5
|
};
|
|
6
6
|
export declare const getTypeScriptConfiguration: () => Promise<TypeScriptConfiguration | null>;
|
|
7
|
-
export declare const generateTypeScriptDeclaration: (
|
|
8
|
-
|
|
7
|
+
export declare const generateTypeScriptDeclaration: (
|
|
8
|
+
outfile: string
|
|
9
|
+
) => Promise<string>;
|
|
10
|
+
export declare const hasTypeScript: (
|
|
11
|
+
tsConfig: TypeScriptConfiguration | null
|
|
12
|
+
) => tsConfig is TypeScriptConfiguration;
|
|
@@ -1,75 +1,154 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __createBinding =
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
2
|
+
var __createBinding =
|
|
3
|
+
(this && this.__createBinding) ||
|
|
4
|
+
(Object.create
|
|
5
|
+
? function (o, m, k, k2) {
|
|
6
|
+
if (k2 === undefined) k2 = k;
|
|
7
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
8
|
+
if (
|
|
9
|
+
!desc ||
|
|
10
|
+
("get" in desc
|
|
11
|
+
? !m.__esModule
|
|
12
|
+
: desc.writable || desc.configurable)
|
|
13
|
+
) {
|
|
14
|
+
desc = {
|
|
15
|
+
enumerable: true,
|
|
16
|
+
get: function () {
|
|
17
|
+
return m[k];
|
|
18
|
+
},
|
|
19
|
+
};
|
|
20
|
+
}
|
|
21
|
+
Object.defineProperty(o, k2, desc);
|
|
22
|
+
}
|
|
23
|
+
: function (o, m, k, k2) {
|
|
24
|
+
if (k2 === undefined) k2 = k;
|
|
25
|
+
o[k2] = m[k];
|
|
26
|
+
});
|
|
27
|
+
var __setModuleDefault =
|
|
28
|
+
(this && this.__setModuleDefault) ||
|
|
29
|
+
(Object.create
|
|
30
|
+
? function (o, v) {
|
|
31
|
+
Object.defineProperty(o, "default", {
|
|
32
|
+
enumerable: true,
|
|
33
|
+
value: v,
|
|
34
|
+
});
|
|
35
|
+
}
|
|
36
|
+
: function (o, v) {
|
|
37
|
+
o["default"] = v;
|
|
38
|
+
});
|
|
39
|
+
var __importStar =
|
|
40
|
+
(this && this.__importStar) ||
|
|
41
|
+
function (mod) {
|
|
42
|
+
if (mod && mod.__esModule) return mod;
|
|
43
|
+
var result = {};
|
|
44
|
+
if (mod != null)
|
|
45
|
+
for (var k in mod)
|
|
46
|
+
if (
|
|
47
|
+
k !== "default" &&
|
|
48
|
+
Object.prototype.hasOwnProperty.call(mod, k)
|
|
49
|
+
)
|
|
50
|
+
__createBinding(result, mod, k);
|
|
51
|
+
__setModuleDefault(result, mod);
|
|
52
|
+
return result;
|
|
53
|
+
};
|
|
54
|
+
var __awaiter =
|
|
55
|
+
(this && this.__awaiter) ||
|
|
56
|
+
function (thisArg, _arguments, P, generator) {
|
|
57
|
+
function adopt(value) {
|
|
58
|
+
return value instanceof P
|
|
59
|
+
? value
|
|
60
|
+
: new P(function (resolve) {
|
|
61
|
+
resolve(value);
|
|
62
|
+
});
|
|
63
|
+
}
|
|
64
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
65
|
+
function fulfilled(value) {
|
|
66
|
+
try {
|
|
67
|
+
step(generator.next(value));
|
|
68
|
+
} catch (e) {
|
|
69
|
+
reject(e);
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
function rejected(value) {
|
|
73
|
+
try {
|
|
74
|
+
step(generator["throw"](value));
|
|
75
|
+
} catch (e) {
|
|
76
|
+
reject(e);
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
function step(result) {
|
|
80
|
+
result.done
|
|
81
|
+
? resolve(result.value)
|
|
82
|
+
: adopt(result.value).then(fulfilled, rejected);
|
|
83
|
+
}
|
|
84
|
+
step(
|
|
85
|
+
(generator = generator.apply(thisArg, _arguments || [])).next()
|
|
86
|
+
);
|
|
87
|
+
});
|
|
88
|
+
};
|
|
34
89
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
35
|
-
exports.hasTypeScript =
|
|
90
|
+
exports.hasTypeScript =
|
|
91
|
+
exports.generateTypeScriptDeclaration =
|
|
92
|
+
exports.getTypeScriptConfiguration =
|
|
93
|
+
void 0;
|
|
36
94
|
const path_1 = require("path");
|
|
37
95
|
const termost_1 = require("termost");
|
|
38
96
|
const constants_1 = require("../constants");
|
|
39
|
-
const getTypeScriptConfiguration = () =>
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
97
|
+
const getTypeScriptConfiguration = () =>
|
|
98
|
+
__awaiter(void 0, void 0, void 0, function* () {
|
|
99
|
+
var _a;
|
|
100
|
+
try {
|
|
101
|
+
const ts = yield Promise.resolve().then(() =>
|
|
102
|
+
__importStar(require("typescript"))
|
|
103
|
+
);
|
|
104
|
+
const { jsx, jsxImportSource, target } =
|
|
105
|
+
ts.parseJsonConfigFileContent(
|
|
106
|
+
require((0, path_1.resolve)(
|
|
107
|
+
constants_1.CWD,
|
|
108
|
+
"tsconfig.json"
|
|
109
|
+
)),
|
|
110
|
+
ts.sys,
|
|
111
|
+
constants_1.CWD
|
|
112
|
+
).options;
|
|
113
|
+
const esbuildTarget =
|
|
114
|
+
!target ||
|
|
115
|
+
[ts.ScriptTarget.ESNext, ts.ScriptTarget.Latest].includes(
|
|
116
|
+
target
|
|
117
|
+
)
|
|
118
|
+
? "esnext"
|
|
119
|
+
: (_a = ts.ScriptTarget[target]) === null || _a === void 0
|
|
120
|
+
? void 0
|
|
121
|
+
: _a.toLowerCase();
|
|
122
|
+
const hasJsxRuntime =
|
|
123
|
+
jsx !== undefined &&
|
|
124
|
+
[ts.JsxEmit["ReactJSX"], ts.JsxEmit["ReactJSXDev"]].includes(
|
|
125
|
+
jsx
|
|
126
|
+
);
|
|
127
|
+
return {
|
|
128
|
+
target: esbuildTarget,
|
|
129
|
+
jsxImportSource,
|
|
130
|
+
hasJsxRuntime,
|
|
131
|
+
};
|
|
132
|
+
} catch (error) {
|
|
133
|
+
return null;
|
|
134
|
+
}
|
|
135
|
+
});
|
|
60
136
|
exports.getTypeScriptConfiguration = getTypeScriptConfiguration;
|
|
61
|
-
const generateTypeScriptDeclaration = (outfile) =>
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
})
|
|
137
|
+
const generateTypeScriptDeclaration = (outfile) =>
|
|
138
|
+
__awaiter(void 0, void 0, void 0, function* () {
|
|
139
|
+
const outdir = (0, path_1.dirname)(outfile);
|
|
140
|
+
try {
|
|
141
|
+
yield termost_1.helpers.exec(
|
|
142
|
+
`tsc --declaration --emitDeclarationOnly --incremental --removeComments false --outDir ${outdir}`,
|
|
143
|
+
{ cwd: constants_1.CWD }
|
|
144
|
+
);
|
|
145
|
+
return outdir;
|
|
146
|
+
} catch (error) {
|
|
147
|
+
throw new Error(`Type generation failed:\n${error}`);
|
|
148
|
+
}
|
|
149
|
+
});
|
|
71
150
|
exports.generateTypeScriptDeclaration = generateTypeScriptDeclaration;
|
|
72
151
|
const hasTypeScript = (tsConfig) => {
|
|
73
|
-
|
|
152
|
+
return Boolean(tsConfig);
|
|
74
153
|
};
|
|
75
154
|
exports.hasTypeScript = hasTypeScript;
|
package/bin/helpers.d.ts
CHANGED
|
@@ -2,4 +2,7 @@
|
|
|
2
2
|
import { readFile as fsReadFile } from "fs";
|
|
3
3
|
export declare const readFile: typeof fsReadFile.__promisify__;
|
|
4
4
|
export declare const resolveModulePath: (path: string) => boolean;
|
|
5
|
-
export declare function assert(
|
|
5
|
+
export declare function assert(
|
|
6
|
+
condition: unknown,
|
|
7
|
+
message: string
|
|
8
|
+
): asserts condition;
|